Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Copyright (C) 1991-2004 Altera Corporation
  2. //Any megafunction design, and related net list (encrypted or decrypted),
  3. //support information, device programming or simulation file, and any other
  4. //associated documentation or information provided by Altera or a partner
  5. //under Altera's Megafunction Partnership Program may be used only to
  6. //program PLD devices (but not masked PLD devices) from Altera.  Any other
  7. //use of such megafunction design, net list, support information, device
  8. //programming or simulation file, or any other related documentation or
  9. //information is prohibited for any other purpose, including, but not
  10. //limited to modification, reverse engineering, de-compiling, or use with
  11. //any other silicon devices, unless such use is explicitly licensed under
  12. //a separate agreement with Altera or a megafunction partner.  Title to
  13. //the intellectual property, including patents, copyrights, trademarks,
  14. //trade secrets, or maskworks, embodied in any such megafunction design,
  15. //net list, support information, device programming or simulation file, or
  16. //any other related documentation or information provided by Altera or a
  17. //megafunction partner, remains with Altera, the megafunction partner, or
  18. //their respective licensors.  No other licenses, including any licenses
  19. //needed under any third party's intellectual property, are provided herein.
  20. //Copying or modifying any file, or portion thereof, to which this notice
  21. //is attached violates this copyright.
  22.  
  23.  
  24. // VHDL Custom Instruction Template File for Combinatorial Logic
  25.  
  26. module ycbcr_to_rgb (
  27. dataa,  // Operand A (always required)
  28.         // dataa(7 downto 0) contains Y
  29. datab,  // Operand B (optional)
  30.         //datab(7 downto 0) contains Cb
  31.         // datab(15 downto 8) contains Cr
  32. result, // result (always required)
  33. );
  34.  
  35. input dataa[31:0];
  36. input datab[31:0];
  37.  
  38. output result[31:0];
  39.  
  40. // Intermediate signals
  41. reg signed [7:0] Cbb;
  42. reg signed [7:0] Crr;
  43. reg [23:0] YYstd;
  44. reg signed [23:0] YY;
  45.  
  46. reg signed [23:0] Cr1402;
  47. reg signed [22:0] Cr071414;
  48. reg signed [21:0] Cb034414;
  49. reg signed [23:0] Cb1722;
  50.  
  51. reg signed [23:0] red24;
  52. reg signed [23:0] blue24;
  53. reg signed [23:0] green24;
  54.  
  55. parameter c22970 = 16'b0101100110111010;
  56. parameter c11700 = 15'b010110110110100;
  57. parameter c5638  = 14'b01011000000110;
  58. parameter c29032 = 16'b0111000101101000;
  59.  
  60. always @(*) begin
  61.     YYstd = {2'b0, dataa, 14'b0};
  62.     YY = YYstd;
  63.     Cbb = {~datab[7], datab[6:0]}; // --subtract 128
  64.     Crr = {~datab[15], datab[14:0]};
  65.    
  66.     Cr1402 = Crr * c22970;
  67.     Cr071414 = Crr * c11700;
  68.     Cb034414 = Cbb * c5638;
  69.     Cb1722 = Cbb * c29032;
  70.  
  71.     red24 = YY + Cr1402;
  72.     blue24 = YY + Cb1722;
  73.     green24 = YY - Cb034414 - Cr071414;
  74.    
  75.     result[31:24] = '0;
  76.    
  77.     if (blue24[23]) begin
  78.         result[7:0] = '0;
  79.     end else if (blue24[22]) begin
  80.         result[7:0] = '1;
  81.     end else begin
  82.         result[7:0] = blue24[21:14];
  83.     end;
  84.    
  85.     if (green24[23]) begin
  86.         result[15:8] = '0;
  87.     end else if (green24[22]) begin
  88.         result[15:8] = '1;
  89.     end else begin
  90.         result[15:8] = green24[21:14];
  91.     end;
  92.    
  93.     if (red24[23]) begin
  94.         result[23:16] = '0;
  95.     end else if (red24[22]) begin
  96.         result[23:16] = '1;
  97.     end else begin
  98.         result[23:16] = red24[21:14];
  99.     end;
  100. end
  101.  
  102. // custom instruction logic (note:  external interfaces can be used as well)
  103. // use the n[7..0] port as a select signal on a multiplexer to select the value to feed result[31..0]
  104. endmodule;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement