engine/wii/video.c
/**
 * Sets brightness and _gamma correction.  Both are implemented using the
 * Flipper/Hollywood's texture environment (TEV) unit.
 *
 * @param br the desired brightness
 * @param gm the desired _gamma
 */
Sets brightness and _gamma correction.  Both are implemented using the
Flipper/Hollywood's texture environment (TEV) unit.

@param br the desired brightness
@param gm the desired _gamma
Sets brightness and _gamma correction . Both are implemented using the Flipper / Hollywood ' s texture environment ( TEV ) unit . @param br the desired brightness @param gm the desired _gamma
void video_set_color_correction(int gm, int br)
{
	if(br < -255) br = -255;
	if(br > 255) br = 255;
	if(gm < -255) gm = -255;
	if(gm > 255) gm = 255;
	if(br != brightness)
	{
		brightness = br;
		brightness_update = 1;
	}
	if(gm != _gamma)
	{
		_gamma = gm;
		_gamma_update = 1;
	}
	if(brightness_update)
	{
		GXColor correction_color = {abs(brightness),abs(brightness),abs(brightness),abs(brightness)};
		brightness_update = 0;
		if(brightness == 0) GX_SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_TEXC);
		else
		{
			GX_SetTevColor(GX_TEVREG0, correction_color);
			GX_SetTevColorIn(GX_TEVSTAGE0, GX_CC_TEXC, GX_CC_ZERO, GX_CC_C0, brightness > 0 ? GX_CC_C0 : GX_CC_ZERO);
		}
		GX_SetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
	}
	if(_gamma_update)
	{
		GXColor correction_color = {abs(_gamma),abs(_gamma),abs(_gamma),abs(_gamma)};
		_gamma_update = 0;
		if(_gamma == 0) GX_SetNumTevStages(1);
		else
		{
			GX_SetNumTevStages(3);
			GX_SetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA);
			GX_SetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
			GX_SetTevAlphaIn(GX_TEVSTAGE2, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA);
			GX_SetTevAlphaOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
			GX_SetTevColor(GX_TEVREG1, correction_color);
			if(_gamma > 0)
			{
				GX_SetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_C1, GX_CC_CPREV, GX_CC_ONE);
				GX_SetTevColorOp(GX_TEVSTAGE1, GX_TEV_SUB, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVREG2);
				GX_SetTevColorIn(GX_TEVSTAGE2, GX_CC_C2, GX_CC_ZERO, GX_CC_CPREV, GX_CC_ONE);
				GX_SetTevColorOp(GX_TEVSTAGE2, GX_TEV_SUB, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
			}
			else
			{
				GX_SetTevColorIn(GX_TEVSTAGE1, GX_CC_C1, GX_CC_ZERO, GX_CC_CPREV, GX_CC_ONE);
				GX_SetTevColorOp(GX_TEVSTAGE1, GX_TEV_SUB, GX_TB_ZERO, GX_CS_SCALE_1, GX_FALSE, GX_TEVREG2);
				GX_SetTevColorIn(GX_TEVSTAGE2, GX_CC_ZERO, GX_CC_C2, GX_CC_CPREV, GX_CC_ZERO);
				GX_SetTevColorOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
			}
		}
	}
}
void video_set_color_correction ( int gm , int br ) { if ( br < -255 ) br = -255 ; if ( br > 255 ) br = 255 ; if ( gm < -255 ) gm = -255 ; if ( gm > 255 ) gm = 255 ; if ( br != brightness ) { brightness = br ; brightness_update = 1 ; } if ( gm != _gamma ) { _gamma = gm ; _gamma_update = 1 ; } if ( brightness_update ) { GXColor correction_color = { abs ( brightness ) , abs ( brightness ) , abs ( brightness ) , abs ( brightness ) } ; brightness_update = 0 ; if ( brightness == 0 ) GX_SetTevColorIn ( GX_TEVSTAGE0 , GX_CC_ZERO , GX_CC_ZERO , GX_CC_ZERO , GX_CC_TEXC ) ; else { GX_SetTevColor ( GX_TEVREG0 , correction_color ) ; GX_SetTevColorIn ( GX_TEVSTAGE0 , GX_CC_TEXC , GX_CC_ZERO , GX_CC_C0 , brightness > 0 ? GX_CC_C0 : GX_CC_ZERO ) ; } GX_SetTevColorOp ( GX_TEVSTAGE0 , GX_TEV_ADD , GX_TB_ZERO , GX_CS_SCALE_1 , GX_TRUE , GX_TEVPREV ) ; } if ( _gamma_update ) { GXColor correction_color = { abs ( _gamma ) , abs ( _gamma ) , abs ( _gamma ) , abs ( _gamma ) } ; _gamma_update = 0 ; if ( _gamma == 0 ) GX_SetNumTevStages ( 1 ) ; else { GX_SetNumTevStages ( 3 ) ; GX_SetTevAlphaIn ( GX_TEVSTAGE1 , GX_CA_ZERO , GX_CA_ZERO , GX_CA_ZERO , GX_CA_TEXA ) ; GX_SetTevAlphaOp ( GX_TEVSTAGE1 , GX_TEV_ADD , GX_TB_ZERO , GX_CS_SCALE_1 , GX_TRUE , GX_TEVPREV ) ; GX_SetTevAlphaIn ( GX_TEVSTAGE2 , GX_CA_ZERO , GX_CA_ZERO , GX_CA_ZERO , GX_CA_TEXA ) ; GX_SetTevAlphaOp ( GX_TEVSTAGE2 , GX_TEV_ADD , GX_TB_ZERO , GX_CS_SCALE_1 , GX_TRUE , GX_TEVPREV ) ; GX_SetTevColor ( GX_TEVREG1 , correction_color ) ; if ( _gamma > 0 ) { GX_SetTevColorIn ( GX_TEVSTAGE1 , GX_CC_ZERO , GX_CC_C1 , GX_CC_CPREV , GX_CC_ONE ) ; GX_SetTevColorOp ( GX_TEVSTAGE1 , GX_TEV_SUB , GX_TB_ZERO , GX_CS_SCALE_1 , GX_TRUE , GX_TEVREG2 ) ; GX_SetTevColorIn ( GX_TEVSTAGE2 , GX_CC_C2 , GX_CC_ZERO , GX_CC_CPREV , GX_CC_ONE ) ; GX_SetTevColorOp ( GX_TEVSTAGE2 , GX_TEV_SUB , GX_TB_ZERO , GX_CS_SCALE_1 , GX_TRUE , GX_TEVPREV ) ; } else { GX_SetTevColorIn ( GX_TEVSTAGE1 , GX_CC_C1 , GX_CC_ZERO , GX_CC_CPREV , GX_CC_ONE ) ; GX_SetTevColorOp ( GX_TEVSTAGE1 , GX_TEV_SUB , GX_TB_ZERO , GX_CS_SCALE_1 , GX_FALSE , GX_TEVREG2 ) ; GX_SetTevColorIn ( GX_TEVSTAGE2 , GX_CC_ZERO , GX_CC_C2 , GX_CC_CPREV , GX_CC_ZERO ) ; GX_SetTevColorOp ( GX_TEVSTAGE2 , GX_TEV_ADD , GX_TB_ZERO , GX_CS_SCALE_1 , GX_TRUE , GX_TEVPREV ) ; } } } }
Sets brightness and _gamma correction.
Sets brightness and _gamma correction .
// update brightness correction if changed since last frame // for brightness > 0, brightnesscorrect(c,b) = b+(c*(1.0-b)) // for brightness < 0, brightnesscorrect(c,b) = c*(1.0+b) // update _gamma correction if changed since last frame // for _gamma > 0, _gammacorrect(c,g) = 1.0-((1.0-c)*(1.0-(c*g))) // Stage 1: (1.0 - ((1.0-c)*0.0 + g*c))  = 1.0-(c*g) // Stage 2: (1.0 - ((1.0-c)*prev + 0*c)) = 1.0-((1.0-c)*(1.0-(c*g))) // for _gamma < 0, _gammacorrect(c,g) = c*(1.0-((1.0-c)*g)) // Stage 1: (1.0 - ((1.0-c)*g + 0.0*c))  =    1.0-((1.0-c)*g) // Stage 2: (0.0 + ((1.0-c)*0 + prev*c)) = c*(1.0-((1.0-c)*g))