📄 decoder.cpp
字号:
// Method: ErrorCode Decoder::SetVideoInput(Connector source)
// Purpose: Select which connector as input
// Input: Connector source - SVideo, Tuner, Composite
// Output: None
// Return: Fail if error in parameter, else Success
/////////////////////////////////////////////////////////////////////////////
ErrorCode Decoder::SetVideoInput(Connector source)
{
if ((source != ConSVideo) &&
(source != ConTuner) &&
(source != ConComposite))
return Fail;
decFieldMUXSEL = (ULONG)source + 1;
// set to composite or Y/C component video depends on video source
SetCompositeVideo((source == ConSVideo) ? FALSE : TRUE);
return Success;
}
/////////////////////////////////////////////////////////////////////////////
// Method: Connector Decoder::GetVideoInput()
// Purpose: Get which connector is input
// Input: None
// Output: None
// Return: Video source - SVideo, Tuner, Composite
/////////////////////////////////////////////////////////////////////////////
Connector Decoder::GetVideoInput()
{
return ((Connector)(decFieldMUXSEL-1));
}
/////////////////////////////////////////////////////////////////////////////
// Method: ErrorCode Decoder::SetCrystal(Crystal crystalNo)
// Purpose: Select which crystal as input
// Input: Crystal crystalNo:
// XT0 - Crystal_XT0
// XT1 - Crystal_XT1
// Auto select - Crystal_AutoSelect
// Output: None
// Return: Fail if error in parameter, else Success
/////////////////////////////////////////////////////////////////////////////
ErrorCode Decoder::SetCrystal(Crystal crystalNo)
{
if ((crystalNo < Crystal_XT0) || (crystalNo > Crystal_AutoSelect))
return Fail;
decFieldXTSEL = crystalNo;
return Success;
}
/////////////////////////////////////////////////////////////////////////////
// Method: int Decoder::GetCrystal()
// Purpose: Get which crystal is input
// Input: None
// Output: None
// Return: Crystal Number:
// XT0 - Crystal_XT0
// XT1 - Crystal_XT1
// Auto select - Crystal_AutoSelect
/////////////////////////////////////////////////////////////////////////////
int Decoder::GetCrystal()
{
return ((int)decFieldXTSEL);
}
/////////////////////////////////////////////////////////////////////////////
// Method: ErrorCode Decoder::SetVideoFormat(VideoFormat format)
// Purpose: Set video format
// Input: Video format -
// Auto format: VFormat_AutoDetect
// NTSC (M): VFormat_NTSC
// NTSC Japan: VFormat_NTSC_J
// PAL (B, D, G, H, I): VFormat_PAL_BDGHI
// PAL (M): VFormat_PAL_M
// PAL(N): VFormat_PAL_N
// SECAM: VFormat_SECAM
// PAN(N Combo) VFormat_PAL_N_COMB
// Output: None
// Return: Fail if error in parameter, else Success
// Notes: Available video formats are: NTSC, PAL(B, D, G, H, I), PAL(M),
// PAL(N), SECAM
// This function also sets the AGCDelay (ADELAY) and BrustDelay
// (BDELAY) registers
/////////////////////////////////////////////////////////////////////////////
ErrorCode Decoder::SetVideoFormat(VideoFormat format)
{
if ((format < VFormat_AutoDetect) ||
(format > VFormat_PAL_N_COMB))
return Fail;
switch (format)
{
case VFormat_PAL_M:
case VFormat_NTSC:
case VFormat_NTSC_J:
decFieldFORMAT = format;
decRegADELAY = 0x68;
decRegBDELAY = 0x5D;
SetChromaComb(TRUE); // enable chroma comb
SelectCrystal('N'); // select NTSC crystal
break;
case VFormat_PAL_BDGHI:
case VFormat_PAL_N:
decFieldFORMAT = format;
decRegADELAY = 0x7F;
decRegBDELAY = 0x72;
SetChromaComb(TRUE); // enable chroma comb
SelectCrystal('P'); // select PAL crystal
break;
case VFormat_PAL_N_COMB:
decFieldFORMAT = format;
decRegADELAY = 0x7F;
decRegBDELAY = 0x72;
SetChromaComb(TRUE); // enable chroma comb
SelectCrystal('N'); // select NTSC crystal
break;
case VFormat_SECAM:
decFieldFORMAT = format;
decRegADELAY = 0x7F;
decRegBDELAY = 0xA0;
SetChromaComb(FALSE); // disable chroma comb
SelectCrystal('P'); // select PAL crystal
break;
default: // VFormat_AutoDetect
// auto format detect by examining the number of lines
if (Decoder::Is525LinesVideo()) // lines == 525 -> NTSC
Decoder::SetVideoFormat(VFormat_NTSC);
else // lines == 625 -> PAL/SECAM
Decoder::SetVideoFormat(VFormat_PAL_BDGHI); // PAL_BDGHI covers most areas
}
SetSaturation(m_satParam);
return Success;
}
/////////////////////////////////////////////////////////////////////////////
// Method: int Decoder::GetVideoFormat()
// Purpose: Obtain video format
// Input: None
// Output: None
// Return: Video format
// Auto format: VFormat_AutoDetect
// NTSC (M): VFormat_NTSC
// PAL (B, D, G, H, I): VFormat_PAL_BDGHI
// PAL (M): VFormat_PAL_M
// PAL(N): VFormat_PAL_N
// SECAM: VFormat_SECAM
// PAN(N Combo) VFormat_PAL_N_COMB
/////////////////////////////////////////////////////////////////////////////
int Decoder::GetVideoFormat()
{
BYTE bFormat = (BYTE)decFieldFORMAT;
if (!bFormat) // autodetection enabled
return Is525LinesVideo() ? VFormat_NTSC : VFormat_SECAM;
else
return bFormat;
}
//===== Temporal Decimation register ========================================
/////////////////////////////////////////////////////////////////////////////
// Method: ErrorCode Decoder::SetRate(BOOL fields, VidField even, int rate)
// Purpose: Set frames or fields rate
// Input: BOOL fields - TRUE for fields, FALSE for frames
// VidField even - TRUE to start decimation with even field, FALSE odd
// int rate - decimation rate: frames (1-50/60); fields(1-25/30)
// Output: None
// Return: Fail if error in parameter, else Success
/////////////////////////////////////////////////////////////////////////////
ErrorCode Decoder::SetRate(BOOL fields, VidField vf, int rate)
{
int nMax;
if (Is525LinesVideo() == TRUE)
nMax = 30; // NTSC
else
nMax = 25; // PAL/SECAM
// if setting frame rate, double the max value
if (fields == FALSE)
nMax *= 2;
if (rate < 0 || rate > nMax)
return Fail;
decFieldDEC_FIELD = (fields == FALSE) ? Off : On;
decFieldDEC_FIELDALIGN = (vf == VF_Even) ? On : Off;
int nDrop = (BYTE) nMax - rate;
decFieldDEC_RAT = (BYTE) (fields == FALSE) ? nDrop : nDrop * 2;
return Success;
}
//===== Brightness Control register =========================================
/////////////////////////////////////////////////////////////////////////////
// Method: ErrorCode Decoder::SetBrightness(int param)
// Purpose: Set video brightness
// Input: int param - parameter value (0-255; default 128)
// Output: None
// Return: Fail if error in parameter, else Success
// Note: See IsAdjustContrast() for detailed description of the contrast
// adjustment calculation
/////////////////////////////////////////////////////////////////////////////
ErrorCode Decoder::SetBrightness(int param)
{
if(m_param.OutOfRange(param))
return Fail;
// perform mapping to our range
int mapped;
if (Mapping(param, m_param, &mapped, m_regBrightness) == Fail)
return Fail;
m_briParam = (WORD)param;
// calculate brightness value
int value = (128 * mapped) / m_regBrightness.Max() ;
// need to limit the value to 0x7F (+50%) because 0x80 is -50%!
if ((mapped > 0) && (value == 0x80))
value = 0x7F;
// perform adjustment of brightness register if adjustment is needed
if (IsAdjustContrast())
{
regBright = value; // brightness value before adjustment
long A = (long)regBright * (long)0xD8;
long B = 64 * ((long)0xD8 - (long)regContrast);
long temp = 0x00;
if (regContrast != 0) // already limit contrast > zero; just in case here
temp = ((A + B) / (long)regContrast);
temp = (temp < -128) ? -128 : ((temp > 127) ? 127 : temp);
value = (BYTE)temp;
}
decRegBRIGHT = (BYTE)value;
return Success;
}
/////////////////////////////////////////////////////////////////////////////
// Method: int Decoder::GetBrightness()
// Purpose: Obtain brightness value
// Input: None
// Output: None
// Return: Brightness parameter (0-255)
/////////////////////////////////////////////////////////////////////////////
int Decoder::GetBrightness()
{
return m_briParam;
}
//===== Miscellaneous Control register (E_CONTROL, O_CONTROL) ===============
/////////////////////////////////////////////////////////////////////////////
// Method: void Decoder::SetLumaNotchFilter(BOOL mode)
// Purpose: Enable/Disable luma notch filter
// Input: BOOL mode - TRUE = Enable; FALSE = Disable
// Output: None
// Return: None
/////////////////////////////////////////////////////////////////////////////
void Decoder::SetLumaNotchFilter(BOOL mode)
{
decFieldLNOTCH = (mode == FALSE) ? On : Off; // reverse
}
/////////////////////////////////////////////////////////////////////////////
// Method: BOOL Decoder::IsLumaNotchFilter()
// Purpose: Check if luma notch filter is enable or disable
// Input: None
// Output: None
// Return: TRUE = Enable; FALSE = Disable
/////////////////////////////////////////////////////////////////////////////
BOOL Decoder::IsLumaNotchFilter()
{
return (decFieldLNOTCH == Off) ? TRUE : FALSE; // reverse
}
/////////////////////////////////////////////////////////////////////////////
// Method: void Decoder::SetCompositeVideo(BOOL mode)
// Purpose: Select composite or Y/C component video
// Input: BOOL mode - TRUE = Composite; FALSE = Y/C Component
// Output: None
// Return: None
/////////////////////////////////////////////////////////////////////////////
void Decoder::SetCompositeVideo(BOOL mode)
{
if (mode == TRUE)
{
// composite video
decFieldCOMP = Off;
Decoder::SetChromaADC(FALSE); // disable chroma ADC
Decoder::SetLumaNotchFilter(TRUE); // enable luma notch filter
}
else
{
// Y/C Component video
decFieldCOMP = On;
Decoder::SetChromaADC(TRUE); // enable chroma ADC
Decoder::SetLumaNotchFilter(FALSE); // disable luma notch filter
}
}
/////////////////////////////////////////////////////////////////////////////
// Method: void Decoder::SetLumaDecimation(BOOL mode)
// Purpose: Enable/Disable luma decimation filter
// Input: BOOL mode - TRUE = Enable; FALSE = Disable
// Output: None
// Return: None
/////////////////////////////////////////////////////////////////////////////
void Decoder::SetLumaDecimation(BOOL mode)
{
// value of 0 turns the decimation on
decFieldLDEC = (mode == TRUE) ? 0 : 1;
}
//===== Luma Gain register (CON_MSB, CONTRAST_LO) ===========================
/////////////////////////////////////////////////////////////////////////////
// Method: ErrorCode Decoder::SetContrast(int param)
// Purpose: Set video contrast
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -