-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrgb_ycbcr.vhd
165 lines (152 loc) · 5.21 KB
/
rgb_ycbcr.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_textio.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
-- tested on fpga (+- 2 accuracy)
entity rgb_ycbcr is
port (
clock : in std_logic;
-- r,g,b : in unsigned(7 downto 0);
-- y,cb,cr : out sfixed(7 downto 0)
-- i : in std_logic_vector(1 downto 0);
-- hex_1,hex_2 : out std_logic_vector(6 downto 0)
hex_1,hex_2,hex_3,hex_4,hex_5 : out std_logic_vector(6 downto 0);
data_out: out std_logic_vector(7 downto 0)
) ;
end rgb_ycbcr;
architecture arch of rgb_ycbcr is
-- signal r,g,b : unsigned(7 downto 0);
signal y,cb,cr : sfixed(7 downto 0);
signal y_temp2 : unsigned(7 downto 0);
begin
-- r <= "11111111";
-- b <= "11111111";
-- g <= "11111111";
rgb_ycbcr_conversion_pr :process(clock)
variable rs,gs,bs,y_temp,cb_temp,cr_temp: unsigned(23 downto 0);
variable cb_temp2,cr_temp2,y_temp3 : unsigned(7 downto 0);
begin
if rising_edge(clock) then
rs := x"0000"&x"ff";
gs := x"0000"&x"00";
bs := x"0000"&x"00";
y_temp := (((rs sll 14)+(rs sll 11)+(rs sll 10)+(rs sll 7)+(rs sll 3)+(rs sll 2)+(rs sll 1)+(gs sll 15)+(gs sll 12)+(gs sll 10)+(gs sll 9)+(gs sll 6)+(gs sll 2)+(bs sll 12)+(bs sll 11)+(bs sll 10)+(bs sll 8)+(bs sll 5)+(bs sll 3)+(bs sll 2)+(bs sll 1)) srl 16) - "10000000" ;
y_temp2 <= y_temp(7 downto 0);
y <= to_sfixed(std_logic_vector(y_temp2 ),7,0);
data_out <= std_logic_vector(y);
end if;
end process;
with y_temp2(3 downto 0) select hex_2 <=
"1000000" when "0000",
"1111001" when "0001",
"0100100" when "0010",
"0110000" when "0011",
"0011001" when "0100",
"0010010" when "0101",
"0000010" when "0110",
"1111000" when "0111",
"0000000" when "1000",
"0011000" when "1001",
"0001000" when "1010",
"0000011" when "1011",
"1000110" when "1100",
"0100001" when "1101",
"0000110" when "1110",
"0001110" when "1111",
"1111111" when others;
--with hex_out(to_integer(v))(to_integer(u))(7 downto 4) select hex_2 <=
with y_temp2(7 downto 4) select hex_3<=
"1000000" when "0000",
"1111001" when "0001",
"0100100" when "0010",
"0110000" when "0011",
"0011001" when "0100",
"0010010" when "0101",
"0000010" when "0110",
"1111000" when "0111",
"0000000" when "1000",
"0011000" when "1001",
"0001000" when "1010",
"0000011" when "1011",
"1000110" when "1100",
"0100001" when "1101",
"0000110" when "1110",
"0001110" when "1111",
"1111111" when others;
with y(3 downto 0) select hex_4 <=
"1000000" when "0000",
"1111001" when "0001",
"0100100" when "0010",
"0110000" when "0011",
"0011001" when "0100",
"0010010" when "0101",
"0000010" when "0110",
"1111000" when "0111",
"0000000" when "1000",
"0011000" when "1001",
"0001000" when "1010",
"0000011" when "1011",
"1000110" when "1100",
"0100001" when "1101",
"0000110" when "1110",
"0001110" when "1111",
"1111111" when others;
--with hex_out(to_integer(v))(to_integer(u))(7 downto 4) select hex_2 <=
with y(7 downto 4) select hex_5 <=
"1000000" when "0000",
"1111001" when "0001",
"0100100" when "0010",
"0110000" when "0011",
"0011001" when "0100",
"0010010" when "0101",
"0000010" when "0110",
"1111000" when "0111",
"0000000" when "1000",
"0011000" when "1001",
"0001000" when "1010",
"0000011" when "1011",
"1000110" when "1100",
"0100001" when "1101",
"0000110" when "1110",
"0001110" when "1111",
"1111111" when others;
-- dct_coeff <= y when i = "00" else cb when i = "01" else cr when i = "10" else y;
-- with dct_coeff(3 downto 0) select hex_1 <=
-- "1000000" when "0000",
-- "1111001" when "0001",
-- "0100100" when "0010",
-- "0110000" when "0011",
-- "0011001" when "0100",
-- "0010010" when "0101",
-- "0000010" when "0110",
-- "1111000" when "0111",
-- "0000000" when "1000",
-- "0011000" when "1001",
-- "0001000" when "1010",
-- "0000011" when "1011",
-- "1000110" when "1100",
-- "0100001" when "1101",
-- "0000110" when "1110",
-- "0001110" when "1111",
-- "1111111" when others;
-- with dct_coeff(7 downto 4) select hex_2 <=
-- "1000000" when "0000",
-- "1111001" when "0001",
-- "0100100" when "0010",
-- "0110000" when "0011",
-- "0011001" when "0100",
-- "0010010" when "0101",
-- "0000010" when "0110",
-- "1111000" when "0111",
-- "0000000" when "1000",
-- "0011000" when "1001",
-- "0001000" when "1010",
-- "0000011" when "1011",
-- "1000110" when "1100",
-- "0100001" when "1101",
-- "0000110" when "1110",
-- "0001110" when "1111",
-- "1111111" when others;
end arch ; -- arch