⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auto.c

📁 RTD2662板卡源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
	if((stAdcData.AdcGain[_RED] == 0x00) || (stAdcData.AdcGain[_GREEN] == 0x00) || (stAdcData.AdcGain[_BLUE] == 0x00))
		return _ERROR_ABORT;
	else
		return _ERROR_SUCCESS;
}

//--------------------------------------------------
// Description  : Get max or min color value
// Input Value  : Measure information
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoMeasureColor(BYTE ucColor, BYTE ucPar, BYTE *pMargin)
{
    CScalerSetBit(_AUTO_ADJ_CTRL0_7A, ~(_BIT2 | _BIT1 | _BIT0) , (ucColor == 3) ? ucColor : ( 2 - ucColor));

	if(bSourceVideo())
	{
		CScalerSetBit(_VGIP_HV_DELAY_1E, 0x0f, 0x00);
		
		pData[0] = ((HIBYTE(stModeInfo.IHStartPos) << 2) & 0x0C) |(HIBYTE(stModeInfo.IHStartPos + stModeInfo.IHWidth )  & 0x03);   
		pData[1] = LOBYTE(stModeInfo.IHStartPos);
		pData[2] = LOBYTE(stModeInfo.IHStartPos + stModeInfo.IHWidth);
		pData[3] = ((HIBYTE(stModeInfo.IVStartPos) << 2) & 0x0C) |(HIBYTE(stModeInfo.IVStartPos + stModeInfo.IVHeight )  & 0x03);   
		pData[4] = LOBYTE(stModeInfo.IVStartPos);
		pData[5] = LOBYTE(stModeInfo.IVStartPos + stModeInfo.IVHeight);

	}
	else
	{	// VGA or YPBPR
    if(ucPar == _MEASURE_COLORS_MIN)
    {
        pData[0] = 0x12;
        pData[1] = 0x80;
        pData[2] = 0x00;
        pData[3] = 0x00;
        pData[4] = (usVStartPos > 9) ? 9 : (usVStartPos - 1);
        pData[5] = pData[4] + 1;
    }
    else
    {
        pData[0] = ((usHStartPos >> 4) & 0x70) | (HIBYTE(usHEndPos) & 0x0f);
        pData[1] = (LOBYTE(usHStartPos));
        pData[2] = (LOBYTE(usHEndPos));
        pData[3] = ((usVStartPos >> 4) & 0x70) | (HIBYTE(usVEndPos) & 0x0f);
        pData[4] = (LOBYTE(usVStartPos));
        pData[5] = (LOBYTE(usVEndPos));
    }
	}	
    CScalerWrite(_H_BOUNDARY_H_70, 6, pData, _AUTOINC);

    CScalerSetByte(_AUTO_ADJ_CTRL1_7D, 0x01 | ((ucPar & 0x01) << 5));

    pData[0] = CAutoWaitFinish();

    if(pData[0] != _ERROR_SUCCESS)       return pData[0];

    CScalerRead(_AUTO_PHASE_0_87, 1, pMargin, _AUTOINC);

    if(ucPar == _MEASURE_COLORS_MIN)
        *pMargin ^= 0xff;		// measure color min need 1's complement

    return _ERROR_SUCCESS;
}


UINT8 Change_Device_Gain(UINT8 color, UINT8 delta, UINT8 inc)
{
       
#if(_VIDEO_AUTO_WHITE_BLANCE == _ENABLE)
       if(bSourceVideo())
    	   	return(Change_VDC_Gain(color, delta, inc));
       else   
#endif
              return(CAutoChangeAdcGain(color, delta, inc));			   	
          
       
}

UINT8 Change_Device_Offset(UINT8 color, UINT8 delta, UINT8 inc)
{
#if(_VIDEO_AUTO_WHITE_BLANCE == _ENABLE)
       if(bSourceVideo())
	   	   return(Change_VDC_Offset(color, delta, inc));
       else   
#endif
                 return(CAutoChangeAdcOffset(color, delta, inc));       
}

//--------------------------------------------------
// Description  : Adjust ADC gain
// Input Value  : Adjusting setting
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoTuneDeviceGain(BYTE ucColor, BYTE *pMargin, BYTE ucMax_Target)
{
    BYTE temp;

    if(CAutoMeasureColor(ucColor, _MEASURE_COLORS_MAX, pMargin) != _ERROR_SUCCESS)
        return _ERROR_ABORT;

	if(*pMargin > ucMax_Target)
	{
        temp  = *pMargin - ucMax_Target;
       	// Non-zero return value of Change_ADC_Gain() means ADC gain reaches maximum.
	if(Change_Device_Gain(ucColor, temp, 0))                  // Decrease Gain; Decrease Contrast
		    {
               if(bSourceVideo())
               {
	           if(Change_Device_Offset(ucColor, 2, 0))               // Increase Offset; Decrease Brightness	           
		        	return _ERROR_FINISH;

               }
               else
               {
	           if(Change_Device_Offset(ucColor, 4, 0))               // Increase Offset; Decrease Brightness	           
		        	return _ERROR_FINISH;
               }
		   	}
	}
	else if(*pMargin < ucMax_Target)
	{
        temp  = ucMax_Target - *pMargin;
        	// Non-zero return value of Change_ADC_Gain() means ADC gain reaches minimum.
        if(Change_Device_Gain(ucColor, temp, 1))                  // Increase Gain; Increase Contrast
       		{
               if(bSourceVideo())
               {
	           if(Change_Device_Offset(ucColor, 2, 1))               // Increase Offset; Decrease Brightness	           
		        	return _ERROR_FINISH;

               }
               else
               {
	           if(Change_Device_Offset(ucColor, 4, 1))               // Increase Offset; Decrease Brightness	           
		        	return _ERROR_FINISH;
               }
        	}
		}
    return _ERROR_SUCCESS;
}

//--------------------------------------------------
// Description  : Adjust ADC offset
// Input Value  : Adjusting setting
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoTuneDeviceOffset(BYTE ucColor, BYTE *pMargin, BYTE ucMin_Target)
{
	BYTE temp;

	if(CAutoMeasureColor(ucColor, _MEASURE_COLORS_MIN, pMargin) != _ERROR_SUCCESS)
		return _ERROR_ABORT;

	 if((_GET_INPUT_SOURCE() == _SOURCE_VGA)||
	 	((_GET_INPUT_SOURCE() == _SOURCE_YPBPR )&&(ucColor == _SY)) ||
	 	((bSourceVideo())&&(ucColor == _GREEN)))
	 {

               //forster modified 061002
		 if(*pMargin > ucMin_Target)
		 {
                      temp = *pMargin - ucMin_Target;
			 Change_Device_Offset(ucColor, ((temp > 8) ? 8 : temp), 0);
		}
		else if(*pMargin < ucMin_Target)
		{

        temp = ucMin_Target - *pMargin;

        		if(*pMargin == 0)
                          Change_Device_Offset(ucColor, temp + 4, 1);       // Increase Offset; Increase Brightness
        		else
                          Change_Device_Offset(ucColor, temp, 1);           // Increase Offset; Increase Brightness
		}		
	}
	else
	{
		if(*pMargin > _CHROMA_BLACK_LEVEL)
		{
			temp = *pMargin - _CHROMA_BLACK_LEVEL;
			Change_Device_Offset(ucColor, ((temp > 8) ? 8 : temp), 0);
		}
		else if(*pMargin < _CHROMA_BLACK_LEVEL)
		{		
			temp = _CHROMA_BLACK_LEVEL - *pMargin;
        		if(*pMargin == 0)
			{
                      	Change_Device_Offset(ucColor, temp + 4, 1);
		        }
			else
			{
				Change_Device_Offset(ucColor, temp, 1);
			}
   		}
	}
    return _ERROR_SUCCESS;
}

//--------------------------------------------------
// Description  : Change ADC gain
// Input Value  : Input information
// Output Value : Return 1 if overrange
//--------------------------------------------------
BYTE CAutoChangeAdcGain(BYTE ucColor, BYTE ucDelta, BYTE ucInc)
{
    BYTE overrange = 0;
    BYTE Gain;

  	if(_GET_INPUT_SOURCE() == _SOURCE_VGA)
		Gain = 	stAdcData.AdcGain[ucColor] ;
    else if(_GET_INPUT_SOURCE() == _SOURCE_YPBPR)
		Gain = stYPbPrData.YPbPrGain[ucColor];

   		if(ucInc)
    	{
        if(Gain >= ucDelta)
            Gain -= ucDelta;
        	else
        	{
            Gain = 0;
        	    overrange = 1;
       		}
    	}
    	else
    	{
        if ((0xff - ucDelta) >= Gain)
            Gain += ucDelta;
        	else
        	{
            Gain = 0xff;
            	overrange = 1;
        	}
    	}

   if(_GET_INPUT_SOURCE() == _SOURCE_VGA)
		stAdcData.AdcGain[ucColor] = Gain;
    else if(_GET_INPUT_SOURCE() == _SOURCE_YPBPR)
		stYPbPrData.YPbPrGain[ucColor] = Gain;

    	CAdjustAdcGain();
    	return overrange;
}

//--------------------------------------------------
// Description  : Change ADC offset
// Input Value  : Input information
// Output Value : Return 1 if overrange
//--------------------------------------------------
BYTE CAutoChangeAdcOffset(BYTE ucColor, BYTE ucDelta, BYTE ucInc)
{
	BYTE overrange = 0;
	BYTE Offset;	

	if(_GET_INPUT_SOURCE() == _SOURCE_VGA)
		Offset = 	stAdcData.AdcOffset[ucColor];
	else if(_GET_INPUT_SOURCE() == _SOURCE_YPBPR)
		Offset = stYPbPrData.YPbPrOffset[ucColor];
	if(ucInc)
    	{
		if(Offset >= ucDelta)
			Offset -= ucDelta;
        	else
        	{
			Offset = 0;
			overrange = 1;
        	}
    	}
    	else
    	{
		if ((0xff - ucDelta) >= Offset)
			Offset += ucDelta;
		else
        	{
			Offset = 0xff;
			overrange = 1;
        	}
    	}

	if(_GET_INPUT_SOURCE() == _SOURCE_VGA)
		stAdcData.AdcOffset[ucColor] = Offset;
	else if(_GET_INPUT_SOURCE() == _SOURCE_YPBPR)
		stYPbPrData.YPbPrOffset[ucColor] = Offset;	

    	CAdjustAdcOffset();
    	return overrange;
}

#if(_VIDEO_AUTO_WHITE_BLANCE == _ENABLE)
#define _CHROMA   	0x00
#define _LUMA		0x01

UINT8 Change_VDC_Gain(UINT8 color, UINT8 delta,UINT8 inc)
{
    if(color == _LUMA)//VDC Y gain is more sensitive than other source
	{
	    if(delta < 0x08)
           delta = delta >> 1;
	}
	
    pData[2] = 0;
    pData[0] = color == _LUMA ? GET_VDC_GAIN() : GET_VDC_CHROMA();
    pData[1] = inc ? (0xff - pData[0]) : pData[0];
    if(inc){
    	if(pData[1] > delta)
        	pData[0] += delta;
	else{
			 pData[0] = 0xff;
			 pData[2] |= color;//saturate
		}
  	}
	else{
		if(pData[1] > delta)
       	    	pData[0] -= delta;
		else{
			pData[0] = 0;
			pData[2] |= color; //saturate
		}
   	}
	if(color == _LUMA){
		SET_VDC_GAIN(pData[0]);
		CVideoSetVDCContrast(pData[0]);
    }
	else{
		SET_VDC_CHROMA(pData[0]);
		CVideoSetVDCSaturation(pData[0]);
    }
	return pData[2];
}

UINT8 Change_VDC_Offset(UINT8 color, UINT8 delta,UINT8 inc)
{
	//Chroma can't adjust the offset
    if(color == _CHROMA)
	 	return 0;
    pData[2] = 0;
    pData[0] = GET_VDC_OFFSET();
   pData[1] = inc ? (0xff - pData[0]) : pData[0];
    if(inc){
    	if(pData[1] > delta)
        	pData[0] += delta;
	else{
                  pData[0] = 0xff;
		    pData[2] |= color;  //saturate
		}
	}
    else{
    	if(pData[1] > delta)
        	pData[0] -= delta;
	else{
			pData[0] = 0;
			pData[2] |= color;  //saturate
	}
}
	SET_VDC_OFFSET(pData[0]);
	CVideoSetVDCBrightness(pData[0]);
	return pData[2];
}
#endif

#if(_YPBPR_AUTO_TYPE==_NEW_TYPE)
#define Channel_Y 		0
#define Channel_U 		1
#define Channel_V 		2

BYTE YPbPr_ABS(UINT8 data_1, UINT8 data_2)
{
	UINT8 result;

	if(data_1 >= data_2)
		result = data_1 - data_2;
	else
		result = data_2 - data_1;
	return result;
}

BYTE ActiveRegion_2547D(UINT16 *Region)
{
	//CScalerPageSelect(_PAGE0);
	CScalerSetByte(_IPH_ACT_STA_H_14, 0x00);
	CScalerSetByte(_IPV_ACT_STA_H_18, 0x00);

	CScalerRead(_IPH_ACT_STA_H_14, 10, pData, _AUTOINC);			// 14(0),15(1),16(2),17(3),18(4),19(5),1A(6),1B(7),1C(8),1D(9)
	Region[0] = ((pData[0]  & (0x07)) << 8) + pData[1] + pData[9];	//Active_HStart
	Region[1] = ((pData[2]  & (0x07)) << 8) + pData[3];						//Active_HWidth
	Region[2] = ((pData[4]  & (0x07)) << 8) + pData[5] + pData[8];	//Active_VStart
	Region[3] = ((pData[6]  & (0x07)) << 8) + pData[7];						//Active_VLines
	
	return(1);
}

void HistPos( UINT16 Active_HStart, UINT16 Active_HWidth, UINT16 Active_VStart, UINT16 Active_VWidth, UINT16 *Offset_Pos, UINT16 *Y_Gain_Pos, UINT16 *PbPr_Gain_Pos)
{
/*
//chroma2330#36(Default)//remember to modify fractional number.!!!!!
	//OffsetYPbPr Position
	Offset_Pos[0]	= (Active_HStart+Active_HWidth) - Active_HWidth/7;
	Offset_Pos[1]	= Offset_Pos[0] + Active_HWidth/100;
	Offset_Pos[2]	= (Active_VStart+Active_VWidth) - 2*Active_VWidth/20;
	Offset_Pos[3]	= Offset_Pos[2] + Active_VWidth/20;

	//GainY Position
	Y_Gain_Pos[0]=  (Active_HStart + Active_HWidth)/2;
	Y_Gain_Pos[1]=  Y_Gain_Pos[0] + Active_HWidth/100;
	Y_Gain_Pos[2]	= (Active_VStart+Active_VWidth) - 2*Active_VWidth/20;
	Y_Gain_Pos[3]	= Y_Gain_Pos[2] + Active_VWidth/20;

	//GainPbPr Position
	PbPr_Gain_Pos[0]	= (Active_HStart+Active_HWidth) - (2.5)*Active_HWidth/7;
	PbPr_Gain_Pos[1]	= PbPr_Gain_Pos[0]+ Active_HWidth/100;
	PbPr_Gain_Pos[2]	= Active_VStart + Active_VWidth/20;
	PbPr_Gain_Pos[3]	= PbPr_Gain_Pos[2] + Active_VWidth/20;
*/

//chroma2330#27
/*
	//OffsetYPbPr(Black)
	Offset_Pos[0] 	= Active_HStart + Active_HWidth*(0.03125);
	Offset_Pos[1]       = Offset_Pos[0]  + Active_HWidth*(0.03125);

	Offset_Pos[2] 	= Active_VStart + Active_VWidth*(0.05);
	Offset_Pos[3]	= Offset_Pos[2]  + Active_VWidth*(0.05);

	//GainY(White)
	Y_Gain_Pos[1] 	= (Active_HStart + Active_HWidth) - Active_HWidth*(0.0625);
	Y_Gain_Pos[0] 	= Y_Gain_Pos[1] - Active_HWidth*(0.03125);

	Y_Gain_Pos[3]	= (Active_VStart + Active_VWidth) - Active_VWidth*(0.05);
	Y_Gain_Pos[2]	= Y_Gain_Pos[3] - Active_VWidth*(0.05);
	
	//GainPbPr(Magenta)
	PbPr_Gain_Pos[1] = Active_HStart + Active_HWidth*(0.5) - Active_HWidth*(0.0625);
	PbPr_Gain_Pos[0] = PbPr_Gain_Pos[1]  - Active_HWidth*(0.03125);

	PbPr_Gain_Pos[3] = Y_Gain_Pos[3];
	PbPr_Gain_Pos[2] = Y_Gain_Pos[2];
*/
//VideoBook-Chapter#2_colorbar
	Offset_Pos[0]	= (Active_HStart+Active_HWidth) - Active_HWidth*(0.0625);//over 16
	Offset_Pos[1]	= Offset_Pos[0] + Active_HWidth*(0.015625);//over 64

	//GainY(White)
	Y_Gain_Pos[0]	= Active_HStart + Active_HWidth*(0.03125);//over 32
	Y_Gain_Pos[1]	= Y_Gain_Pos[0] + Active_HWidth*(0.015625);//over 64
		
	//GainPbPr(Magenta)
	PbPr_Gain_Pos[0] = (Active_HStart+Active_HWidth) - (3.5)*(Active_HWidth*(0.125));//over 8
	PbPr_Gain_Pos[1] = PbPr_Gain_Pos[0] + Active_HWidth*(0.015625); //over 64
		
	Offset_Pos[2]	= Active_VStart + Active_VWidth*(0.03125);//over 32
	Offset_Pos[3]	= Offset_Pos[2] + Active_VWidth*(0.03125);//over 32
	Y_Gain_Pos[2]  = Offset_Pos[2];
	Y_Gain_Pos[3]  = Offset_Pos[3];
	PbPr_Gain_Pos[2]  = Offset_Pos[2];
	PbPr_Gain_Pos[3]  = Offset_Pos[3];

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -