📄 adjust.c
字号:
UserPrefMonitorOnTime++ ;
//BacklightOnTime
if ((PowerUpFlag.SoftPowerOnState) || (PowerUpFlag.SyncPowerOnState))
{
if (UserPrefBacklightOnTime <= 0xFFFE)
UserPrefBacklightOnTime++ ;
}
SaveFactoryDependentSettings();
}
#endif
}
#if defined(Action_AdjustColor_WB_Used) | defined(Action_AdjustContrast_WB_Used)
// Look-up table for sin cos functions
//This table is using enhanced coefficient.
short code sincos_lut[65] = {
0x0000, 0x0064, 0x00C8, 0x012D, 0x0191, 0x01F5, 0x0259, 0x02BC,
0x031F, 0x0381, 0x03E3, 0x0444, 0x04A5, 0x0504, 0x0563, 0x05C2,
0x061F, 0x067B, 0x06D7, 0x0731, 0x078A, 0x07E2, 0x0839, 0x088F,
0x08E3, 0x0936, 0x0987, 0x09D7, 0x0A26, 0x0A73, 0x0ABE, 0x0B08,
0x0B50, 0x0B96, 0x0BDA, 0x0C1D, 0x0C5E, 0x0C9D, 0x0CD9, 0x0D14,
0x0D4D, 0x0D84, 0x0DB9, 0x0DEB, 0x0E1C, 0x0E4A, 0x0E76, 0x0EA0,
0x0EC8, 0x0EED, 0x0F10, 0x0F31, 0x0F4F, 0x0F6B, 0x0F85, 0x0F9C,
0x0FB1, 0x0FC3, 0x0FD3, 0x0FE1, 0x0FEC, 0x0FF4, 0x0FFB, 0x0FFE,
0x0FFF
};
//******************************************************************
// DESCRIPTION : Matrix multiply. Multiplies 3x3 matrix A with
// 3x3 matrix B, storing the results back in A.
// PARAMETERS :
// RETURN : result stored in matrix A.
//******************************************************************
static void __near matrix_MxM(SDWORD *A, SDWORD *B)
{
BYTE row,col;
SDWORD M[3][3];
SDWORD a,b,c;
for(row=0;row<3;row++)
{
for(col=0;col<3;col++)
{
a = A[row * 3 + 0] * B[0 * 3 + col];
b = A[row * 3 + 1] * B[1 * 3 + col];
c = A[row * 3 + 2] * B[2 * 3 + col];
M[row][col] = (a + b + c) >> 8;
}
}
memcpy(A,M,sizeof(M));
}
//******************************************************************
// FUNCTION : matrix_MxA
// USAGE : Adjusts contrast, saturation
// in YUV space.
// INPUT : A[]
//
//
// OUTPUT : A[]
// A[] = Adjust[]
//
// GLOBALS : UserPrefContrast, UserPrefUVSaturation, UserPrefUVFleshTone
// - contrast is a one byte unsigned word that can
// take values between 0x00 and 0xFF in 0x01
// steps.
// - saturation is a one byte unsigned word that can
// take values between 0x00 and 0xFF in 0x01
// steps.
// - fleshtone is a one byte unsigned word that can
// take values between 0x00 and 0xFF in 0x01
// steps.
//******************************************************************
static void __near matrix_MxA(SDWORD *A, SWORD constrast)
{
BYTE hue;
SDWORD Adjust[3][3];
SDWORD cos;
SDWORD sin;
SDWORD sat;
#ifdef Action_AdjustVideoWindowHue_WB_Used
hue = UserPrefHue - 128;
#else
hue = 0;
#endif
cos = ( SDWORD)cosinus(hue);
sin = ( SDWORD) sinus(hue);
#ifdef Action_AdjustVideoWindowSaturation_WB_Used
sat = ((SDWORD)UserPrefSaturation << 1);
#else
sat = 256;
#endif
Adjust[0][0] = constrast;
Adjust[0][1] = 0;
Adjust[0][2] = 0;
Adjust[1][0] = 0;
Adjust[1][1] = ((sat * cos) >> 8);
Adjust[1][2] = ((sat * sin) >> 8);
Adjust[2][0] = 0;
Adjust[2][1] = (-(sin * sat) >> 8);
Adjust[2][2] = (( cos * sat) >> 8);
memcpy(A,Adjust,sizeof(Adjust));
}
//******************************************************************
// DESCRIPTION : Matrix multiply Constant. Multiplies 3x3 matrix A with
// contstant C, storing the result back in matrix A.
// PARAMETERS :
// RETURN : result stored in matrix A.
//******************************************************************
static void __near matrix_MxC(SDWORD *A, SWORD C)
{
BYTE i;
for(i=0;i<9;i++)
{
A[i] = (A[i] * C) >> 8;
}
}
//******************************************************************
// FUNCTION : sinus
// USAGE : Calculates sinus
// DESCRIPTION : The function uses a look up table in which are
// stored samples for the first quadrant 0 to 90
// degrees.
//
// INPUT : angle value in steps of 360/256 degrees
// (the angle range is 0x00 to 0xFF, granularity
// is 1.4 degrees).
// OUTPUT : sinus value
// GLOBALS : sincos_lut
// USED_REGS : None
//******************************************************************
static short sinus(BYTE alpha)
{
switch (alpha & 0xC0)
{
case 0x00:
return( sincos_lut[alpha & 0x3F] >> 4);
case 0x40:
return( sincos_lut[64-(alpha & 0x3F)] >> 4);
case 0x80:
return(-(sincos_lut[alpha & 0x3F] >> 4));
case 0xC0:
return(-(sincos_lut[64-(alpha & 0x3F)] >> 4));
default:
break;
}
return 0;
}
//******************************************************************
// FUNCTION : cosinus
// USAGE : calculates cosinus
// DESCRIPTION : The function calculates cosinus by using sinus
// function based on the formula:
// cos(a) = sin(a + 90)
//
// INPUT : angle value in steps of 360/256 degrees
// (the angle range is 0x00 to 0xFF, granularity
// is 1.4 degrees).
// OUTPUT : cosinus value
// GLOBALS : sincos_lut
// USED_REGS : None
//******************************************************************
static short cosinus(BYTE alpha)
{
return (sinus(alpha + 64));
}
//******************************************************************
// DESCRIPTION : Color adjuster function using RGB
// SYNTEX : void AdjustColor(void)
// PARAMETERS : none
// RETURN : none
//******************************************************************
#define sRGB2rgb { \
{0x0100L, 0x0000L, 0x0000L}, \
{0x0000L, 0x0100L, 0x0000L}, \
{0x0000L, 0x0000L, 0x0100L} \
}
#define yuv2rgb { \
{0x12AL, 0x000L, 0x198L}, \
{0x12AL, -0x064L, -0x0D0L}, \
{0x12AL, 0x204L, 0x0000L} \
}
#define rgb2yuv { \
{ 0x041L, 0x081L, 0x019L }, \
{ -0x025L, -0x04AL, 0x070L }, \
{ 0x070L, -0x05EL, -0x012L } \
}
void far AdjustColor()
{
BYTE i,accacm;
WORD contrast;
SDWORD rgbGain[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
SDWORD sRGB[3][3] = sRGB2rgb;
SDWORD sYUVRGB[3][3] = yuv2rgb;
//SDWORD sRGBYUV[3][3] = rgb2yuv;
SDWORD *ccMatrix;
ColorTempType S_ColorTemp;
DWORD startTime;
{
if (UserPrefColor == CTEMP_USER )
{
msg("CTEMP_USER %d", (WORD)UserPrefColor);
rgbGain[0][0] = (DWORD)UserPrefRedColor;
rgbGain[1][1] = (DWORD)UserPrefGreenColor;
rgbGain[2][2] = (DWORD)UserPrefBlueColor;
}
else
{
//get the rgb values from nvram
#ifdef NVRAM_BLOCK_ColorTemp_WB_Used
LoadColorTemp(UserPrefColor, (BYTE *) &S_ColorTemp);
rgbGain[0][0] = S_ColorTemp.R;
rgbGain[1][1] = S_ColorTemp.G;
rgbGain[2][2] = S_ColorTemp.B;
#else
// if Color temp not stored in NVRAM, use sRGB settings.
rgbGain[0][0] = ColorTempConst[UserPrefColor][0];
rgbGain[1][1] = ColorTempConst[UserPrefColor][1];
rgbGain[2][2] = ColorTempConst[UserPrefColor][2];
#endif //NVRAM_BLOCK_ColorTemp_WB_Used
}
}
msgx("***************************************", 0);
msgx("UserPrefColor %d", (WORD)UserPrefColor);
msgx("rgbGain[0][0] = %d", (WORD) rgbGain[0][0]);
msgx("rgbGain[1][1] = %d", (WORD) rgbGain[1][1]);
msgx("rgbGain[2][2] = %d", (WORD) rgbGain[2][2]);
//only reset contrast for SRGB color space
if(UserPrefColor == CTEMP_SRGB)
#ifdef UserPrefFactorysRGBContrastValue
UserPrefContrast = UserPrefFactorysRGBContrastValue;
#else
UserPrefContrast = 128;
#endif
else
{
B_PreUserPrefColor = UserPrefColor; //Implementation 2 of AdjustContrast ()
}
contrast = UserPrefContrast * 2; //allow contrast to go from 0->2.00 instead of 0->1.00
// if input is YUV, or RGB2YUV enabled in the front end, then the
// input to the multiplier is YUV.
accacm = gmd_FALSE;
#ifdef UserPrefW_OsdAccAcmFlag
if((InputPortArray[gmvb_CurrentPortMain].ACC_En) &&
((UserPrefW_OsdAccAcmFlag & AccEnableBit) == AccEnableBit))
accacm |= gmd_TRUE;
if((InputPortArray[gmvb_CurrentPortMain].ACM_En) &&
((UserPrefW_OsdAccAcmFlag & AcmEnableBit) == AcmEnableBit))
accacm |= gmd_TRUE;
#endif
if( accacm || InputPortArray[gmvb_CurrentPortMain].YUV)
{
ccMatrix = &sRGB[0][0];
//[sRGB] = [Adjust]
matrix_MxA(ccMatrix, contrast);
//now covert YUV back to RGB for dipslay.
matrix_MxM(&sYUVRGB[0][0],ccMatrix);
//swap red, blue and blue (don' know why)
sRGB[0][0] = sYUVRGB[0][2];
sRGB[0][1] = sYUVRGB[0][0];
sRGB[0][2] = sYUVRGB[0][1];
sRGB[1][0] = sYUVRGB[1][2];
sRGB[1][1] = sYUVRGB[1][0];
sRGB[1][2] = sYUVRGB[1][1];
sRGB[2][0] = sYUVRGB[2][2];
sRGB[2][1] = sYUVRGB[2][0];
sRGB[2][2] = sYUVRGB[2][1];
//[Gain]*[sRGB]
matrix_MxM(&rgbGain[0][0],ccMatrix);
}
else
{// Input to the multiplier is RGB.
ccMatrix = &sRGB[0][0];
matrix_MxM(&rgbGain[0][0],ccMatrix);
matrix_MxM(&rgbGain[0][0],&sRGB[0][0]);
matrix_MxC(&rgbGain[0][0],contrast);
}
msgx("_",0);
msgx("_",0);
msgx("R %d",(WORD)rgbGain[0][0]);
msgx("G %d",(WORD)rgbGain[1][1]);
msgx("B %d",(WORD)rgbGain[2][2]);
#ifdef Action_AdjustVideoWindowHue_WB_Used
msgx("H %d",UserPrefHue);
#endif
#ifdef Action_AdjustVideoWindowSaturation_WB_Used
msgx("S %d",UserPrefSaturation);
#endif
msgx("contrast %d",(WORD)contrast);
// wait for blanking period
startTime = gm_ReadSystemTime();
while(1)
{
WORD LineNumber;
LineNumber = gm_ReadRegWord(DV_POSITION_0);
if(LineNumber == (gmc_PanelVActiveEnd + 1))
break;
if(labs(gm_ReadSystemTime() - startTime) > 40)// wait for 40ms.
{
msgx("blanking timer expired",0);
break;
}
}
if( accacm || InputPortArray[gmvb_CurrentPortMain].YUV)
gm_WriteRegByte(MULT_CTRL, MULT_WIN_CTRL | WIN_INSIDE_FORMAT | WIN_OUTSIDE_FORMAT);
else
gm_WriteRegByte(MULT_CTRL, MULT_WIN_CTRL);
for(i=0; i < 9; i++)
{
gm_WriteRegWord(MULT_COEFF_11_A_0 + (i * 2),(WORD)(((DWORD *)rgbGain)[i]));
gm_WriteRegWord(MULT_COEFF_11_B_0 + (i * 2),(WORD)(((DWORD *)rgbGain)[i]));
msgx("matrix ----- %x",(WORD)(((DWORD *)rgbGain)[i]));
}
#ifdef UserPrefW_OsdAccAcmFlag
#if USE_ACC_ACM
if((InputPortArray[gmvb_CurrentPortMain].ACC_En) &&
((UserPrefW_OsdAccAcmFlag & AccEnableBit) == AccEnableBit))
gm_EnableACC();
else
gm_DisableACC();
if((InputPortArray[gmvb_CurrentPortMain].ACM_En) &&
((UserPrefW_OsdAccAcmFlag & AcmEnableBit) == AcmEnableBit))
gm_EnableACM();
else
gm_DisableACM();
#endif // USE_ACC_ACM
#endif
gm_WriteRegByte(HOST_CONTROL, SYNC_UPDATE);
}
#endif // Action_AdjustColor_WB_Used
#ifdef Action_AdjustVideoWindowHue_WB_Used
void far AdjustVideoWindowHue(void)
{
//gm_CallDriver(DEV_VPC3230,VID_SET_HUE,(void*)((BYTE)UserPrefSaturation),NULL_PTR);
AdjustColor();
}
#endif // Action_AdjustVideoWindowHue_WB_Used
#ifdef Action_AdjustVideoWindowSaturation_WB_Used
void far AdjustVideoWindowSaturation(void)
{
//gm_CallDriver(DEV_VPC3230,VID_SET_SATURATION,(void*)((BYTE)UserPrefSaturation),NULL_PTR);
AdjustColor();
}
#endif // Action_AdjustVideoWindowSaturation_WB_Used
void far AdjustFactoryColorTempAction(void)
{
#ifdef Action_AdjustFactoryColorTemp_WB_Used
AdjustFactoryColorTemp();
#endif
}
void far AdjustFactoryColorTemp(void)
{
#ifdef Action_AdjustFactoryColorTemp_WB_Used
BYTE saveUPC = UserPrefColor;
UserPrefRedColor = UserPrefFactoryColorTempAdjRed;
UserPrefGreenColor = UserPrefFactoryColorTempAdjGreen;
UserPrefBlueColor = UserPrefFactoryColorTempAdjBlue;
//adjust color according to pre-defined red/green/blue
//Set UserPrefColor to CTEMP_USER so AdjustColor() will use UserPrefXColor
//instead of reading value from NVRAM.
UserPrefColor = CTEMP_USER;
AdjustColor();
UserPrefColor = saveUPC;
#endif
}
//******************************************************************
// FUNCTION : EnterFactoryMenu
// DESCRIPTION : Copies UserPref values with UserPrefFactory
// values to be used in the factory menu.
//******************************************************************
void EnterFactoryMenu(void)
{
msgx("*** enter factory menu ***",0);
}
//******************************************************************
// FUNCTION : ExitFactoryMenu
// DESCRIPTION : Restores the UserPref values back to normal
//******************************************************************
void ExitFactoryMenu(void)
{
msgx("*** exit factory menu ***",0);
#ifdef Action_RestoreModeIndepSettings_WB_Used
RestoreModeIndepSettings();
#endif
}
void EnterDefaultState(void)
{
msg("** OSD: EnterDefaultState",0);
}
void EnterValidModeState(void)
{
msg("** OSD: EnterValidModeState",0);
}
void EnterNoSignalState(void)
{
msg("** OSD: EnterNoSignalState",0);
}
void EnterNoCableState(void)
{
msg("** OSD: EnterNoCableState",0);
}
void EnterOutOfRangeState(void)
{
msg("** OSD: EnterOutOfRangeState",0);
}
void EnterSleepState(void)
{
msg("** OSD: EnterSleepState",0);
}
//******************************************************************
// FUNCTION : StartFloating/StopFloating
// DESCRIPTION : Functions set up an interrupt and chain it to
// the system timer which already gives us a 1ms tick. Upon the
// FLOATING_TIME_MS time in the ISR, OsdFloating() is called to
// position the OSD dialog.
//******************************************************************
#include "system\mcu186.h"
#ifdef Action_StartFloating_WB_Used
void far interrupt (*TimerIsr)(void);
#define FLOATING_TIME_MS 50
void far interrupt FloatingISR(void)
{
static WORD i=0;
if(i++ > FLOATING_TIME_MS)
{
OsdFloating();
i = 0;
}
TimerIsr();
}
void StartFloating(void)
{
msg("** start floating **",0);
gm_DisableInterrupts();
TimerIsr = (void far interrupt (*)(void))GET_VECTOR(TIMER2_VECTOR);
SET_VECTOR(TIMER2_VECTOR, FloatingISR);
asm{ STI };
}
void StopFloating(void)
{
msg("** stop floating **",0);
gm_DisableInterrupts();
SET_VECTOR(TIMER2_VECTOR,TimerIsr);
asm{ STI };
}
#endif //Action_StartFloating_WB_Used
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -