vi_gamma.v 1.95 KB
/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1994, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 *************************************************************************/

// $Id: vi_gamma.v,v 1.1.1.1 2002/05/17 06:07:49 blythe Exp $

////////////////////////////////////////////////////////////////////////
//
// Project Reality
//
// module:	vi_gamma
// description:	Gamma correction for video interface.
//
// designer:	Phil Gossett
// date:	10/30/94
//
////////////////////////////////////////////////////////////////////////

module vi_gamma (vclk, gamma_dither_enable, gamma_enable, rgb, rand, sync,
		gamma_rgb, gamma_sync);

input vclk;
input gamma_enable;
input gamma_dither_enable;
input [7:0] rgb;
input [5:0] rand;
input sync;

output [6:0] gamma_rgb;
output gamma_sync;

wire [6:0] sqrt_rgb;
wire [7:0] dither_rgb;
wire blank;

reg blank_reg;
reg [6:0] gamma_rgb;
reg gamma_sync;

vi_gamma_sqrt viga (.a({rgb,(rand & {6{gamma_dither_enable}})}), .q(sqrt_rgb));
assign dither_rgb = (rgb == 8'hFF) ?
			8'hFF :
			(rgb + {7'b0,(rand[5] & gamma_dither_enable)});
assign blank = sync ? rgb[7] : blank_reg;

always @(posedge vclk)
begin
	blank_reg <= blank;
	gamma_rgb <= sync ?
		{3'b0,rgb[4:1]} :
		({7{~blank}} & (gamma_enable ?
					sqrt_rgb :
					dither_rgb[7:1]));
	gamma_sync <= sync;
end

endmodule // vi_gamma