📄 surface.cpp
字号:
m_pSite->SetOptimizedFormat(NULL);
return HXR_OK;
}
STDMETHODIMP
CHXSurface::GetOptimizedFormat(REF(HX_COMPRESSION_TYPE) ulType)
{
HXBitmapInfoHeader* pOptimizedFormat = m_pSite->GetOptimizedFormat();
if (!pOptimizedFormat)
{
return HXR_FAIL;
}
ulType = pOptimizedFormat->biCompression;
return HXR_OK;
}
STDMETHODIMP
CHXSurface::GetPreferredFormat(REF(HX_COMPRESSION_TYPE) ulType)
{
ulType = m_PreferredFormat;
return HXR_OK;
}
/*
* IHXVideoControls methods
*/
STDMETHODIMP_(float)
CHXSurface::GetBrightness(void)
{
return m_Brightness;
}
STDMETHODIMP
CHXSurface::SetBrightness(float Brightness)
{
if (Brightness > MAX_BRIGHTNESS)
{
m_Brightness = (float) MAX_BRIGHTNESS;
}
else if (Brightness < MIN_BRIGHTNESS)
{
m_Brightness = (float) MIN_BRIGHTNESS;
}
else
{
m_Brightness = Brightness;
}
return HXR_OK;
}
STDMETHODIMP_(float)
CHXSurface::GetContrast(void)
{
return m_Contrast;
}
STDMETHODIMP
CHXSurface::SetContrast(float Contrast)
{
if (Contrast > MAX_CONTRAST)
{
m_Contrast = (float) MAX_CONTRAST;
}
else if (Contrast < MIN_CONTRAST)
{
m_Contrast = (float) MIN_CONTRAST;
}
else
{
m_Contrast = Contrast;
}
return HXR_OK;
}
STDMETHODIMP_(float)
CHXSurface::GetSaturation(void)
{
return m_Saturation;
}
STDMETHODIMP
CHXSurface::SetSaturation(float Saturation)
{
if (Saturation > MAX_SATURATION)
{
m_Saturation = (float) MAX_SATURATION;
}
else if (Saturation < MIN_SATURATION)
{
m_Saturation = (float) MIN_SATURATION;
}
else
{
m_Saturation = Saturation;
}
return HXR_OK;
}
STDMETHODIMP_(float)
CHXSurface::GetHue(void)
{
return m_Hue;
}
STDMETHODIMP
CHXSurface::SetHue(float Hue)
{
if (Hue > MAX_HUE)
{
m_Hue = (float) MAX_HUE;
}
else if (Hue < MIN_HUE)
{
m_Hue = (float) MIN_HUE;
}
else
{
m_Hue = Hue;
}
return HXR_OK;
}
STDMETHODIMP_(float)
CHXSurface::GetSharpness(void)
{
return m_Sharpness;
}
STDMETHODIMP
CHXSurface::SetSharpness(float Sharpness)
{
if (Sharpness > MAX_SHARPNESS)
{
m_Sharpness = (float) MAX_SHARPNESS;
}
else if (Sharpness < MIN_SHARPNESS)
{
m_Sharpness = (float) MIN_SHARPNESS;
}
else
{
m_Sharpness = Sharpness;
}
return HXR_OK;
}
STDMETHODIMP
CHXSurface::SetModeSharpness(UINT16 dFlag)
{
//set m_ModeSharpness =1 when deblocking filter is on
//set m_ModeSharpness =0 when deblocking filter is off
//find the deblocking filter on/off by getstreampreoperty
m_ModeSharpness=dFlag;
return HXR_OK;
}
void
CHXSurface::PerformYUVConversion(UCHAR* ySrc,
UCHAR* uSrc,
UCHAR* vSrc,
INT32 nPitchSrc,
UCHAR* Dst,
INT32 nWidth,
INT32 nHeight,
INT32 nPitchDst,
HX_MOFTAG Format,
INT16 nExpand)
{
INT16 nNewFormat = 0;
if (Format == HXCOLOR_RGB3_ID)
{
nNewFormat = T_RGB888;
}
else if (Format == HXCOLOR_RGB565_ID)
{
nNewFormat = T_RGB565;
}
else if (Format == HXCOLOR_RGB555_ID)
{
nNewFormat = T_RGB555;
}
else
{
HX_ASSERT(0); // Invalid format
}
// We only need to Set the Color Adjustments if they've changed
if (CheckColorSettings())
{
// Adjust colors according to video control settings
m_pConverter->SetColorAdjustments(m_Brightness, m_Contrast, m_Saturation, m_Hue);
// Reset Previous values so next time we'll know if they've changed
m_PrevBrightness = m_Brightness;
m_PrevContrast = m_Contrast;
m_PrevSaturation = m_Saturation;
m_PrevHue = m_Hue;
}
// We only need to Set the Color Adjustments if they've changed
if (CheckSharpness())
{
// Adjust colors according to video control settings
m_pConverter->SetSharpnessAdjustments(m_Sharpness,nExpand);
// Reset Previous values so next time we'll know if they've changed
m_PrevSharpness = m_Sharpness;
}
if (ySrc[0] != 1)
{
//if Sharpness is -1.0 (or close) do not do any edge enhancement
//check necessary because intel mmx edge enhacement does not check this
if( (m_Sharpness+1.0)>0.1 )
{
if(m_ModeSharpness)
{
//Deblocking filter is ON
m_pConverter->EnhanceUniform(ySrc,nHeight,nWidth,nPitchSrc,m_Sharpness);
}
else
{
//Deblocking filter is OFF
m_pConverter->Enhance(ySrc,nHeight,nWidth,nPitchSrc,m_Sharpness);
}
}
}
else
{
ySrc[0] = ySrc[1];
}
// Execute the conversion
m_pConverter->ConvertYUVtoRGB(ySrc, uSrc, vSrc, nPitchSrc, Dst, nWidth,
nHeight, nPitchDst, nNewFormat, nExpand);
//change one corner pixel to put a digital watermark
ySrc[0] = 1;
}
UINT16
CHXSurface::CheckColorSettings()
{
// NOTE 40 steps of granularity for color control parameters (based on
// below float to int precision; proper rounding is not essential)
if( (int)(m_PrevBrightness * 20.f) != (int)(m_Brightness * 20.f) ||
(int)(m_PrevContrast * 20.f) != (int)(m_Contrast * 20.f) ||
(int)(m_PrevSaturation * 20.f) != (int)(m_Saturation * 20.f) ||
(int)(m_PrevHue * 20.f) != (int)(m_Hue * 20.f) )
{
return 1; // reinitializationing of color table required
}
else
{
return 0; // no change in color controls
}
}
UINT16
CHXSurface::CheckSharpness()
{
// NOTE 40 steps of granularity for sharpness control parameters (based on
// below float to int precision; proper rounding is not essential)
if( (int)(m_PrevSharpness * 20.f) != (int)(m_Sharpness * 20.f) )
{
return 1; // reinitializationing of sharpness table required
}
else
{
return 0; // no change in sharpness table
}
}
UINT16
CHXSurface::CalculateNewBitDepth(HX_COMPRESSION_TYPE nNewFormat)
{
UINT16 nNewBitDepth = 0;
switch (nNewFormat)
{
case HXCOLOR_RGB3_ID:
{
#ifdef _MACINTOSH
nNewBitDepth = 32;
#else
nNewBitDepth = 24;
#endif
}
break;
case HXCOLOR_RGB24_ID:
{
nNewBitDepth = 24;
}
break;
#ifdef _WINDOWS
case HXCOLOR_RGB555_ID:
{
nNewBitDepth = 16;
}
break;
case HXCOLOR_RGB565_ID:
{
nNewBitDepth = 16;
}
break;
#endif
default:
HX_ASSERT(0); // Invalid format
break;
}
return nNewBitDepth;
}
void
CHXSurface::AdjustBitmapHeader(HXBitmapInfoHeader* pBitmapInfo,
HX_MOFTAG NewFormat)
{
switch (NewFormat)
{
case HXCOLOR_RGB3_ID:
{
#ifdef _MACINTOSH
pBitmapInfo->biCompression = HX_RGB;
pBitmapInfo->biBitCount = 32;
#else
pBitmapInfo->biCompression = HX_RGB;
pBitmapInfo->biBitCount = 24;
#endif
}
break;
case HXCOLOR_RGB24_ID:
{
pBitmapInfo->biCompression = HX_RGB;
pBitmapInfo->biBitCount = 24;
}
break;
#ifdef _WINDOWS
case HXCOLOR_RGB555_ID:
{
pBitmapInfo->biCompression = HX_BITFIELDS;
pBitmapInfo->biBitCount = 16;
pBitmapInfo->rcolor = 0x00007C00; // red
pBitmapInfo->gcolor = 0x000003E0; // green
pBitmapInfo->bcolor = 0x0000001F; // blue
}
break;
case HXCOLOR_RGB565_ID:
{
pBitmapInfo->biCompression = HX_BITFIELDS;
pBitmapInfo->biBitCount = 16;
pBitmapInfo->rcolor = 0x0000F800; // red
pBitmapInfo->gcolor = 0x000007E0; // green
pBitmapInfo->bcolor = 0x0000001F; // blue
}
break;
#endif
default:
HX_ASSERT(0); // Invalid format
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -