OpenCores
URL https://opencores.org/ocsvn/video_systems/video_systems/trunk

Subversion Repositories video_systems

[/] [video_systems/] [trunk/] [common/] [color_space converters/] [ycrcb2rgb/] [rtl/] [verilog/] [ycrcb2rgb.v] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  YCrCb to RGB Color Space converter                         ////
4
////                                                             ////
5
////  Converts YCrCb (YUV) values to RGB values                  ////
6
////  R = Y + 1.403Cr                                            ////
7
////  G = Y - 0.344Cb - 0.714Cr                                  ////
8
////  B = Y + 1.770Cb                                            ////
9
////                                                             ////
10
////  Author: Richard Herveille                                  ////
11
////          richard@asics.ws                                   ////
12
////          www.asics.ws                                       ////
13
////                                                             ////
14
////                                                             ////
15
/////////////////////////////////////////////////////////////////////
16
////                                                             ////
17
//// Copyright (C) 2001 Richard Herveille                        ////
18
////                    richard@asics.ws                         ////
19
////                                                             ////
20
//// This source file may be used and distributed without        ////
21
//// restriction provided that this copyright statement is not   ////
22
//// removed from the file and that any derivative work contains ////
23
//// the original copyright notice and the associated disclaimer.////
24
////                                                             ////
25
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
26
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
27
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
28
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
29
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
30
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
31
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
32
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
33
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
34
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
35
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
36
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
37
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
38
////                                                             ////
39
/////////////////////////////////////////////////////////////////////
40
 
41
//  CVS Log
42
//
43
//  $Id: ycrcb2rgb.v,v 1.1.1.1 2002-03-26 07:25:09 rherveille Exp $
44
//
45
//  $Date: 2002-03-26 07:25:09 $
46
//  $Revision: 1.1.1.1 $
47
//  $Author: rherveille $
48
//  $Locker:  $
49
//  $State: Exp $
50
//
51
// Change History:
52
//               $Log: not supported by cvs2svn $
53
 
54
 
55
`timescale 1ns/10ps
56
 
57
module ycrcb2rgb(clk, ena, y, cr, cb, r, g, b);
58
        //
59
        // inputs & outputs
60
        //
61
        input        clk;
62
        input        ena;
63
        input  [9:0] y, cr, cb;
64
 
65
        output [9:0] r, g, b;
66
        reg [9:0] r, g, b;
67
 
68
 
69
        reg [9:0] dy, dcr, dcb;
70
 
71
        //
72
        // variables
73
        //
74
        reg [22:0] ir, ig, ib;
75
 
76
        //
77
        // module body
78
        //
79
 
80
 
81
        // step 1: Calculate R, G, B
82
        //
83
        // Use N.M format for multiplication:
84
        // R = Y + 1.403Cr = Y + Cr + 0.403Cr
85
        // R = Y + Cr + 0x19C*Cr
86
        //
87
        // G = Y - 0.344Cb - 0.714Cr
88
        // G = Y - 0x160*Cb - 0x2DB*Cr
89
        //
90
        // B = Y + 1.770Cb = Y + Cb + 0.770Cb
91
        // B = Y + Cb + 0x314*Cb
92
 
93
 
94
        // delay y, cr and cb
95
        always@(posedge clk)
96
                if (ena)
97
                begin
98
                        dy  <= #1 y;
99
                        dcr <= #1 cr;
100
                        dcb <= #1 cb;
101
                end
102
 
103
        // calculate R
104
        reg [19:0] rm;
105
 
106
        always@(posedge clk)
107
                if (ena)
108
                begin
109
                        rm <= #1 10'h19C * cr;
110
 
111
                        ir <= #1 ( (dy + dcr) << 10) + rm;
112
                end
113
 
114
        // calculate G
115
        reg [19:0] gm1, gm2;
116
 
117
        always@(posedge clk)
118
                if (ena)
119
                begin
120
                        gm1 <= #1 10'h160 * cb;
121
                        gm2 <= #1 10'h2DB * cr;
122
 
123
                        ig  <= #1 (dy << 10) - (gm1 + gm2);
124
                end
125
 
126
        // calculate B
127
        reg [19:0] bm;
128
 
129
        always@(posedge clk)
130
                if (ena)
131
                begin
132
                        bm <= #1 10'h314 * cb;
133
 
134
                        ib <= #1 ( (dy + dcb) << 10) + bm;
135
                end
136
 
137
        //
138
        // step2: check boundaries
139
        //
140
        always@(posedge clk)
141
                if (ena)
142
                begin
143
                        // check R
144
                        r <= #1 (ir[19:10] & {10{!ir[22]}}) | {10{(!ir[22] && (ir[21] || ir[20]))}};
145
 
146
                        // check G
147
                        g <= #1 (ig[19:10] & {10{!ig[22]}}) | {10{(!ig[22] && (ig[21] || ig[20]))}};
148
 
149
                        // check B
150
                        b <= #1 (ib[19:10] & {10{!ib[22]}}) | {10{(!ib[22] && (ib[21] || ib[20]))}};
151
                end
152
endmodule
153
 
154
 
155
 
156
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.