-
Notifications
You must be signed in to change notification settings - Fork 0
/
YCbCr2RGB.v
167 lines (161 loc) · 4.11 KB
/
YCbCr2RGB.v
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
166
167
// --------------------------------------------------------------------
// Copyright (c) 2005 by Terasic Technologies Inc.
// --------------------------------------------------------------------
//
// Permission:
//
// Terasic grants permission to use and modify this code for use
// in synthesis for all Terasic Development Boards and Altera Development
// Kits made by Terasic. Other use of this code, including the selling
// ,duplication, or modification of any portion is strictly prohibited.
//
// Disclaimer:
//
// This VHDL/Verilog or C/C++ source code is intended as a design reference
// which illustrates how these types of functions can be implemented.
// It is the user's responsibility to verify their design for
// consistency and functionality through the use of formal
// verification methods. Terasic provides no warranty regarding the use
// or functionality of this code.
//
// --------------------------------------------------------------------
//
// Terasic Technologies Inc
// 356 Fu-Shin E. Rd Sec. 1. JhuBei City,
// HsinChu County, Taiwan
// 302
//
// web: http://www.terasic.com/
// email: [email protected]
//
// --------------------------------------------------------------------
//
// Major Functions: YCbCr to RGB Color Doamin Converter.
// ( 10 Bits Resolution )
//
// --------------------------------------------------------------------
//
// Revision History :
// --------------------------------------------------------------------
// Ver :| Author :| Mod. Date :| Changes Made:
// V1.0 :| Johnny Chen :| 05/09/05 :| Initial Revision
// V2.0 :| Peli Li :| 04/19/2010 :| revised the megacore instance
// --------------------------------------------------------------------
module YCbCr2RGB ( Red,Green,Blue,oDVAL,
iY,iCb,iCr,iDVAL,
iRESET,iCLK);
// Input
input [7:0] iY,iCb,iCr;
input iDVAL,iRESET,iCLK;
wire iCLK;
// Output
output [9:0] Red,Green,Blue;
output reg oDVAL;
// Internal Registers/Wires
reg [9:0] oRed,oGreen,oBlue;
reg [3:0] oDVAL_d;
reg [19:0] X_OUT,Y_OUT,Z_OUT;
wire [26:0] X,Y,Z;
assign Red = oRed;
assign Green= oGreen;
assign Blue = oBlue;
always@(posedge iCLK)
begin
if(iRESET)
begin
oDVAL<=0;
oDVAL_d<=0;
oRed<=0;
oGreen<=0;
oBlue<=0;
end
else
begin
// Red
if(X_OUT[19])
oRed<=0;
else if(X_OUT[18:0]>1023)
oRed<=1023;
else
oRed<=X_OUT[9:0];
// Green
if(Y_OUT[19])
oGreen<=0;
else if(Y_OUT[18:0]>1023)
oGreen<=1023;
else
oGreen<=Y_OUT[9:0];
// Blue
if(Z_OUT[19])
oBlue<=0;
else if(Z_OUT[18:0]>1023)
oBlue<=1023;
else
oBlue<=Z_OUT[9:0];
// Control
{oDVAL,oDVAL_d}<={oDVAL_d,iDVAL};
end
end
always@(posedge iCLK)
begin
if(iRESET)
begin
X_OUT<=0;
Y_OUT<=0;
Z_OUT<=0;
end
else
begin
X_OUT<=( X - 20'd114131 ) >>7;
Y_OUT<=( Y + 20'd69370 ) >>7;
Z_OUT<=( Z - 20'd141787 ) >>7;
end
end
// Y 596, 0, 817
MAC_3 u0(
.aclr0(iRESET),
.clock0(iCLK),
.dataa_0(iY),
.dataa_1(iCb),
.dataa_2(iCr),
.datab_0(17'h00254),
.datab_1(17'h00000),
.datab_2(17'h00331),
.result(X)
);
//MAC_3 u0( iRESET, iCLK,iY, iCb, iCr,
// 17'h00254, 17'h00000, 17'h00331,
// X);
// Cb 596, -200, -416
MAC_3 u1(
.aclr0(iRESET),
.clock0(iCLK),
.dataa_0(iY),
.dataa_1(iCb),
.dataa_2(iCr),
.datab_0(17'h00254),
// .datab_1(17'h3FF38),
.datab_1(17'h1FF38),
// .datab_2(17'h3FE60),
.datab_2(17'h1FE60),
.result(Y)
);
//MAC_3 u1( iRESET, iCLK,iY, iCb, iCr,
// 17'h00254, 17'h3FF38, 17'h3FE60,
// Y );
// Cr 596, 1033, 0
MAC_3 u2(
.aclr0(iRESET),
.clock0(iCLK),
.dataa_0(iY),
.dataa_1(iCb),
.dataa_2(iCr),
.datab_0(17'h00254),
.datab_1(17'h00409),
.datab_2(17'h00000),
.result(Z)
);
//MAC_3 u2( iRESET, iCLK,iY, iCb, iCr,
// 17'h00254, 17'h00409, 17'h00000,
// Z );
endmodule