--/************************************************************************* -- -- Filename: YCbCr_RGB_conv.vhd -- -- Author: Rejean Lau, Maziyar Khorasani, Yongie Liu, Ram Swamy -- Description: This is the YCbCr to RGB converter model which implements -- the conversion formulas for 8 bit Y,Cb,Cr inputs -- R = 1.164(Y' - 16) + 1.596(Cr - 128) -- G = 1.164(Y' - 16) - (0.813)(Cr - 128) - 0.392(Cb - 128) -- B = 1.165(Y' - 16) + 2.017(Cb - 128) -- ***************************************************************************/ library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; --use IEEE.std_logic_unsigned.all; use IEEE.std_logic_signed.all; use IEEE.Numeric_STD.all; --library virtex; --use virtex.components.all; --library synplify; --use synplify.attributes.all; entity ycrcb2rgb is port (Y,Cr,Cb : in std_logic_vector(7 downto 0); clk,rst : in std_logic; R,G,B : out std_logic_vector(7 downto 0)); end ycrcb2rgb; architecture logic of ycrcb2rgb is signal Y_reg,CR_reg,CB_reg: std_logic_vector(7 downto 0); signal X_int,A_int,B1_int,B2_int,C_int: std_logic_vector(19 downto 0); signal Y_int1,CR_int1,CB_int1: std_logic_vector (8 downto 0); signal R_int,G_int,B_int: std_logic_vector(19 downto 0); begin P1:process (clk,rst) begin if (rst = '1') then Y_reg <= "00000000"; CR_reg <= "00000000";CB_reg <= "00000000"; elsif (rising_edge (clk)) then Y_reg <= Y; CR_reg <= Cr;CB_reg <= Cb; end if; end process P1; Y_int1 <= (('0' & Y_reg) - "000010000"); --16 for 8 bit CR_int1 <= (('0' & CR_reg) - "010000000"); --128 for 8 bit CB_int1 <= (('0' & CB_reg) - "010000000"); --128 for 8 bit P2:process (clk,rst) begin if (rst = '1') then X_int <= (others => '0'); A_int <= (others => '0'); B1_int <= (others => '0'); B2_int <= (others => '0'); C_int <= (others => '0'); elsif (rising_edge (clk)) then X_int <= ("00100101010" * (Y_int1));--(Y_reg - "10000"));-- Y_reg - 16 A_int <= ("00110011000" * ( CR_int1));--(CR_reg - "10000000")); -- Cr_reg - 128 B1_int <= ("00011010000" * ( CR_int1));--(CR_reg - "10000000")); B2_int <= ("00001100100" * (CB_int1));--(CB_reg - "10000000")); -- Cb_reg - 128 C_int <= ("01000000100" * (CB_int1));--(CB_reg - "10000000")); end if; end process P2; P3:process (clk,rst) begin if (rst = '1') then R_int <= (others => '0'); G_int <= (others => '0'); B_int <= (others => '0'); elsif (rising_edge (clk)) then R_int <= X_int + A_int; G_int <= X_int - B1_int - B2_int; B_int <= X_int + C_int; end if; end process P3; P4:process (R_int) begin if (R_int(19) = '1') then R <= "00000000"; elsif (R_int(18 downto 16) = "000") then R <= R_int(15 downto 8); elsif (R_int(16) = '1') then R <= "11111111"; end if; end process P4; P5:process (G_int) begin if (G_int(19) = '1') then G <= "00000000"; elsif (G_int(18 downto 16) = "000") then G <= G_int(15 downto 8); elsif (G_int(16) = '1') then G <= "11111111"; end if; end process P5; P6:process (B_int) begin if (B_int(19) = '1') then B <= "00000000"; elsif (B_int(18 downto 16) = "000") then B <= B_int(15 downto 8); elsif (B_int(16) = '1') then B <= "11111111"; end if; end process P6; end logic ;