/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// YCrCb to RGB Color Space converter ////
|
//// YCrCb to RGB Color Space converter ////
|
//// ////
|
//// ////
|
//// Converts YCrCb (YUV) values to RGB values ////
|
//// Converts YCrCb (YUV) values to RGB values ////
|
//// R = Y + 1.403Cr ////
|
//// R = Y + 1.403Cr ////
|
//// G = Y - 0.344Cb - 0.714Cr ////
|
//// G = Y - 0.344Cb - 0.714Cr ////
|
//// B = Y + 1.770Cb ////
|
//// B = Y + 1.770Cb ////
|
//// ////
|
//// ////
|
//// Author: Richard Herveille ////
|
//// Author: Richard Herveille ////
|
//// richard@asics.ws ////
|
//// richard@asics.ws ////
|
//// www.asics.ws ////
|
//// www.asics.ws ////
|
//// ////
|
//// ////
|
//// ////
|
//// ////
|
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2001 Richard Herveille ////
|
//// Copyright (C) 2001 Richard Herveille ////
|
//// richard@asics.ws ////
|
//// richard@asics.ws ////
|
//// ////
|
//// ////
|
//// This source file may be used and distributed without ////
|
//// This source file may be used and distributed without ////
|
//// restriction provided that this copyright statement is not ////
|
//// restriction provided that this copyright statement is not ////
|
//// removed from the file and that any derivative work contains ////
|
//// removed from the file and that any derivative work contains ////
|
//// the original copyright notice and the associated disclaimer.////
|
//// the original copyright notice and the associated disclaimer.////
|
//// ////
|
//// ////
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
//// POSSIBILITY OF SUCH DAMAGE. ////
|
//// POSSIBILITY OF SUCH DAMAGE. ////
|
//// ////
|
//// ////
|
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
|
|
// CVS Log
|
// CVS Log
|
//
|
//
|
// $Id: ycrcb2rgb.v,v 1.1.1.1 2002-03-26 07:25:09 rherveille Exp $
|
// $Id: ycrcb2rgb.v,v 1.1.1.1 2002-03-26 07:25:09 rherveille Exp $
|
//
|
//
|
// $Date: 2002-03-26 07:25:09 $
|
// $Date: 2002-03-26 07:25:09 $
|
// $Revision: 1.1.1.1 $
|
// $Revision: 1.1.1.1 $
|
// $Author: rherveille $
|
// $Author: rherveille $
|
// $Locker: $
|
// $Locker: $
|
// $State: Exp $
|
// $State: Exp $
|
//
|
//
|
// Change History:
|
// Change History:
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
|
|
|
`timescale 1ns/10ps
|
`timescale 1ns/10ps
|
|
|
module ycrcb2rgb(clk, ena, y, cr, cb, r, g, b);
|
module ycrcb2rgb(clk, ena, y, cr, cb, r, g, b);
|
//
|
//
|
// inputs & outputs
|
// inputs & outputs
|
//
|
//
|
input clk;
|
input clk;
|
input ena;
|
input ena;
|
input [9:0] y, cr, cb;
|
input [9:0] y, cr, cb;
|
|
|
output [9:0] r, g, b;
|
output [9:0] r, g, b;
|
reg [9:0] r, g, b;
|
reg [9:0] r, g, b;
|
|
|
|
|
reg [9:0] dy, dcr, dcb;
|
reg [9:0] dy, dcr, dcb;
|
|
|
//
|
//
|
// variables
|
// variables
|
//
|
//
|
reg [22:0] ir, ig, ib;
|
reg [22:0] ir, ig, ib;
|
|
|
//
|
//
|
// module body
|
// module body
|
//
|
//
|
|
|
|
|
// step 1: Calculate R, G, B
|
// step 1: Calculate R, G, B
|
//
|
//
|
// Use N.M format for multiplication:
|
// Use N.M format for multiplication:
|
// R = Y + 1.403Cr = Y + Cr + 0.403Cr
|
// R = Y + 1.403Cr = Y + Cr + 0.403Cr
|
// R = Y + Cr + 0x19C*Cr
|
// R = Y + Cr + 0x19C*Cr
|
//
|
//
|
// G = Y - 0.344Cb - 0.714Cr
|
// G = Y - 0.344Cb - 0.714Cr
|
// G = Y - 0x160*Cb - 0x2DB*Cr
|
// G = Y - 0x160*Cb - 0x2DB*Cr
|
//
|
//
|
// B = Y + 1.770Cb = Y + Cb + 0.770Cb
|
// B = Y + 1.770Cb = Y + Cb + 0.770Cb
|
// B = Y + Cb + 0x314*Cb
|
// B = Y + Cb + 0x314*Cb
|
|
|
|
|
// delay y, cr and cb
|
// delay y, cr and cb
|
always@(posedge clk)
|
always@(posedge clk)
|
if (ena)
|
if (ena)
|
begin
|
begin
|
dy <= #1 y;
|
dy <= #1 y;
|
dcr <= #1 cr;
|
dcr <= #1 cr;
|
dcb <= #1 cb;
|
dcb <= #1 cb;
|
end
|
end
|
|
|
// calculate R
|
// calculate R
|
reg [19:0] rm;
|
reg [19:0] rm;
|
|
|
always@(posedge clk)
|
always@(posedge clk)
|
if (ena)
|
if (ena)
|
begin
|
begin
|
rm <= #1 10'h19C * cr;
|
rm <= #1 10'h19C * cr;
|
|
|
ir <= #1 ( (dy + dcr) << 10) + rm;
|
ir <= #1 ( (dy + dcr) << 10) + rm;
|
end
|
end
|
|
|
// calculate G
|
// calculate G
|
reg [19:0] gm1, gm2;
|
reg [19:0] gm1, gm2;
|
|
|
always@(posedge clk)
|
always@(posedge clk)
|
if (ena)
|
if (ena)
|
begin
|
begin
|
gm1 <= #1 10'h160 * cb;
|
gm1 <= #1 10'h160 * cb;
|
gm2 <= #1 10'h2DB * cr;
|
gm2 <= #1 10'h2DB * cr;
|
|
|
ig <= #1 (dy << 10) - (gm1 + gm2);
|
ig <= #1 (dy << 10) - (gm1 + gm2);
|
end
|
end
|
|
|
// calculate B
|
// calculate B
|
reg [19:0] bm;
|
reg [19:0] bm;
|
|
|
always@(posedge clk)
|
always@(posedge clk)
|
if (ena)
|
if (ena)
|
begin
|
begin
|
bm <= #1 10'h314 * cb;
|
bm <= #1 10'h314 * cb;
|
|
|
ib <= #1 ( (dy + dcb) << 10) + bm;
|
ib <= #1 ( (dy + dcb) << 10) + bm;
|
end
|
end
|
|
|
//
|
//
|
// step2: check boundaries
|
// step2: check boundaries
|
//
|
//
|
always@(posedge clk)
|
always@(posedge clk)
|
if (ena)
|
if (ena)
|
begin
|
begin
|
// check R
|
// check R
|
r <= #1 (ir[19:10] & {10{!ir[22]}}) | {10{(!ir[22] && (ir[21] || ir[20]))}};
|
r <= #1 (ir[19:10] & {10{!ir[22]}}) | {10{(!ir[22] && (ir[21] || ir[20]))}};
|
|
|
// check G
|
// check G
|
g <= #1 (ig[19:10] & {10{!ig[22]}}) | {10{(!ig[22] && (ig[21] || ig[20]))}};
|
g <= #1 (ig[19:10] & {10{!ig[22]}}) | {10{(!ig[22] && (ig[21] || ig[20]))}};
|
|
|
// check B
|
// check B
|
b <= #1 (ib[19:10] & {10{!ib[22]}}) | {10{(!ib[22] && (ib[21] || ib[20]))}};
|
b <= #1 (ib[19:10] & {10{!ib[22]}}) | {10{(!ib[22] && (ib[21] || ib[20]))}};
|
end
|
end
|
endmodule
|
endmodule
|
|
|
|
|
|
|
|
|
|
|