surface.cpp
Upload User: zhongxx05
Upload Date: 2007-06-06
Package Size: 33641k
Code Size: 19k
Category:

Symbian

Development Platform:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: RCSL 1.0/RPSL 1.0
  3.  *
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
  5.  *
  6.  * The contents of this file, and the files included with this file, are
  7.  * subject to the current version of the RealNetworks Public Source License
  8.  * Version 1.0 (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the RealNetworks Community Source License Version 1.0
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
  12.  * in which case the RCSL will apply. You may also obtain the license terms
  13.  * directly from RealNetworks.  You may not use this file except in
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or
  16.  * RCSL for the rights, obligations and limitations governing use of the
  17.  * contents of the file.
  18.  *
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the
  20.  * developer of the Original Code and owns the copyrights in the portions
  21.  * it created.
  22.  *
  23.  * This file, and the files included with this file, is distributed and made
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  28.  *
  29.  * Technology Compatibility Kit Test Suite(s) Location:
  30.  *    http://www.helixcommunity.org/content/tck
  31.  *
  32.  * Contributor(s):
  33.  *
  34.  * ***** END LICENSE BLOCK ***** */
  35. #include "hxcom.h"
  36. #include "hxtypes.h"
  37. #include "hxmtypes.h"
  38. #include "hxwintyp.h"
  39. #include "chxxtype.h"
  40. #include "hxwin.h"
  41. #include "hxengin.h"
  42. #include "hxcodec.h"
  43. #include "hxalloc.h"
  44. #ifdef _WINDOWS
  45. #include "diballoc.h"
  46. #ifdef _WIN32
  47. #include <vfw.h>
  48. #else
  49. #include <drawdib.h>
  50. #endif // _WIN32
  51. #endif // _WINDOWS
  52. //#include "color.h"
  53. #include "coloracc.h"
  54. #include "hxcolor.h"
  55. #include "hxvctrl.h"
  56. #include "hxvsurf.h"
  57. #include "hxsite2.h"
  58. #include "ihxpckts.h"
  59. #include "surface.h"
  60. #include "vidosurf.h"
  61. #ifdef _WIN32
  62. #include "fullsurf.h"
  63. #endif // _WIN32
  64. #include "sitewnd.h"
  65. #include "mmx_util.h"
  66. #ifndef WIDTHBYTES
  67. #define WIDTHBYTES(i)           ((unsigned long)((i+31)&(~31))/8)
  68. #endif
  69. #include "dbgtimer.h" // for blit time debugging
  70. #include "hxheap.h"
  71. #ifdef _DEBUG
  72. #undef HX_THIS_FILE
  73. static const char HX_THIS_FILE[] = __FILE__;
  74. #endif
  75. CHXSurface::CHXSurface(IUnknown* pContext, CHXSiteWindowed* pSite)
  76.     : m_lRefCount(0)
  77.     , m_pContext(pContext)
  78.     , m_pConverter(NULL)
  79.     , m_Brightness((float) DEF_BRIGHTNESS)
  80.     , m_Contrast((float) DEF_CONTRAST)
  81.     , m_Saturation((float) DEF_SATURATION)
  82.     , m_Hue((float) DEF_HUE)
  83.     , m_Sharpness((float) DEF_SHARPNESS)
  84.     , m_PrevBrightness((float) MAX_BRIGHTNESS)
  85.     , m_PrevContrast((float) MAX_CONTRAST)
  86.     , m_PrevSaturation((float) MAX_SATURATION)
  87.     , m_PrevSharpness((float) MAX_SHARPNESS)
  88.     , m_PrevHue((float) MAX_HUE)
  89.     , m_pSite(pSite)
  90.     , m_PreferredFormat(HXCOLOR_RGB3_ID)
  91.     , m_nBitDepth(32)
  92. {
  93.     if (pContext)
  94.     {
  95. pContext->AddRef();
  96.     }
  97. #ifndef _WIN16
  98.     // Load color conversion library
  99.     m_pConverter = new ColorFuncAccess(m_pContext);
  100.     HX_ASSERT(m_pConverter);
  101.     if (!m_pConverter)
  102.     {
  103.        return;
  104.     }
  105.     m_pConverter->InitColorConverter();
  106. #endif /* _WIN16 */
  107. }
  108. CHXSurface::~CHXSurface()
  109. {
  110. #ifndef _WIN16
  111.     if (m_pConverter)
  112.     {
  113. delete m_pConverter;
  114. m_pConverter = NULL;
  115.     }
  116. #endif /* _WIN16 */
  117.     HX_RELEASE(m_pContext);
  118. }
  119. // *** IUnknown methods ***
  120. /////////////////////////////////////////////////////////////////////////
  121. //  Method:
  122. //      IUnknown::QueryInterface
  123. //  Purpose:
  124. //      Implement this to export the interfaces supported by your
  125. //      object.
  126. //
  127. STDMETHODIMP
  128. CHXSurface::QueryInterface(REFIID riid, void** ppvObj)
  129. {
  130.     QInterfaceList qiList[] =
  131.     {
  132. { GET_IIDHANDLE(IID_IUnknown), this },
  133. { GET_IIDHANDLE(IID_IHXVideoSurface), (IHXVideoSurface*) this },
  134. { GET_IIDHANDLE(IID_IHXVideoControl), (IHXVideoControl*) this },
  135.     };
  136.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  137. }
  138. /////////////////////////////////////////////////////////////////////////
  139. //  Method:
  140. //      IUnknown::AddRef
  141. //  Purpose:
  142. //      Everyone usually implements this the same... feel free to use
  143. //      this implementation.
  144. //
  145. STDMETHODIMP_(ULONG32)
  146. CHXSurface::AddRef()
  147. {
  148.     return InterlockedIncrement(&m_lRefCount);
  149. }
  150. /////////////////////////////////////////////////////////////////////////
  151. //  Method:
  152. //      IUnknown::Release
  153. //  Purpose:
  154. //      Everyone usually implements this the same... feel free to use
  155. //      this implementation.
  156. //
  157. STDMETHODIMP_(ULONG32)
  158. CHXSurface::Release()
  159. {
  160.     if (InterlockedDecrement(&m_lRefCount) > 0)
  161.     {
  162. return m_lRefCount;
  163.     }
  164.     delete this;
  165.     return 0;
  166. }
  167. STDMETHODIMP
  168. CHXSurface::Blt(UCHAR* pImageData,
  169.  HXBitmapInfoHeader* pBitmapInfo,
  170.  REF(HXxRect) inDestRect,
  171.  REF(HXxRect) inSrcRect)
  172. {
  173.     //DebugTimer timer("CHXSurface::Blt");
  174.     #ifdef XXXBHG_TRACE_CODE
  175.     char szOut[256]; /* Flawfinder: ignore */
  176.     sprintf(szOut,"CHXSurface::Blt(%lx Dest[%d,%d,%d,%d] Src[%d,%d,%d,%d])rn",this, /* Flawfinder: ignore */
  177.     inDestRect.left,inDestRect.top,inDestRect.right,inDestRect.bottom,
  178.     inSrcRect.left,inSrcRect.top,inSrcRect.right,inSrcRect.bottom
  179.     );
  180.     OutputDebugString(szOut);
  181.     #endif
  182.     HX_RESULT hr = HXR_OK;
  183.     UCHAR* pNewImageData = NULL;
  184.     HXBitmapInfoHeader* pNewBitmapInfo = NULL;
  185.     BOOL bInterpolate = FALSE;
  186.     CHXxRect rDestRect = inDestRect;
  187.     CHXxRect rSrcRect = inSrcRect;
  188.     INT32 ulOldWidth = rSrcRect.Width();
  189.     INT32 ulOldHeight = rSrcRect.Height();
  190.     INT32 ulNewWidth = ulOldWidth;
  191.     INT32 ulNewHeight = ulOldHeight;
  192. // This whole segment of code will be removed once we implement Yuriy's
  193. // color converters for all Windows builds.
  194. #ifndef _MACINTOSH
  195.     // Convert the data from YUV if necessary
  196.     if (pBitmapInfo->biCompression == HXCOLOR_YUV420_ID)
  197.     {
  198. UCHAR*   uBase = pImageData + (pBitmapInfo->biWidth * pBitmapInfo->biHeight);
  199. UCHAR*   vBase = uBase + ((pBitmapInfo->biWidth * pBitmapInfo->biHeight) / 4);
  200. INT32   ulYOffset = (rSrcRect.top * pBitmapInfo->biWidth) + rSrcRect.left;
  201. INT32   ulUVOffset = ((pBitmapInfo->biWidth * rSrcRect.top) / 4) + (rSrcRect.left / 2);
  202. UCHAR*   ySrc = pImageData + ulYOffset;
  203. UCHAR*   uSrc = uBase + ulUVOffset;
  204. UCHAR*   vSrc = vBase + ulUVOffset;
  205. INT32   ulSrcPitch = pBitmapInfo->biWidth;
  206. #ifdef _MACINTOSH
  207. INT32   ulDstPitch = rSrcRect.Width();
  208. #else
  209. INT32   ulDstPitch = -rSrcRect.Width();
  210. #endif
  211. UINT16   nNewBitDepth = CalculateNewBitDepth(m_PreferredFormat);
  212. INT32   ulSizeImage = WIDTHBYTES((rSrcRect.Width() * nNewBitDepth) * rSrcRect.Height());
  213. bInterpolate = ((rSrcRect.Width()*2 == rDestRect.Width()) &&
  214.   (rSrcRect.Height()*2 == rDestRect.Height()));
  215. if (bInterpolate)
  216. {
  217.     #ifdef XXXBHG_TRACE_CODE
  218.     OutputDebugString("let's interpolate!rn");
  219.     #endif
  220.     ulNewWidth  = rDestRect.Width();
  221.     ulNewHeight = rDestRect.Height();
  222.     ulSizeImage = WIDTHBYTES((rDestRect.Width() * nNewBitDepth) * rDestRect.Height());
  223. #ifdef _MACINTOSH
  224.     ulDstPitch = rDestRect.Width();
  225. #else
  226.     ulDstPitch = -rDestRect.Width();
  227. #endif
  228. }
  229. pNewBitmapInfo = new HXBitmapInfoHeader();
  230. pNewImageData  = new UCHAR[ulSizeImage];
  231. memcpy(pNewBitmapInfo, pBitmapInfo, sizeof(HXBitmapInfoHeader)); /* Flawfinder: ignore */
  232. #ifdef XXXBHG_TRACE_CODE
  233. OutputDebugString("color conversion!rn");
  234. #endif
  235. // Actually convert the data to RGB format
  236. PerformYUVConversion(ySrc, uSrc, vSrc, ulSrcPitch, pNewImageData,
  237.      rSrcRect.Width(), rSrcRect.Height(),
  238.      ulDstPitch, m_PreferredFormat, bInterpolate);
  239. // Adjust bitmap info header to account for conversion
  240. pNewBitmapInfo->biWidth  = ulNewWidth;
  241. pNewBitmapInfo->biHeight = ulNewHeight;
  242. pNewBitmapInfo->biSizeImage = ulSizeImage;
  243. AdjustBitmapHeader(pNewBitmapInfo, m_PreferredFormat);
  244. //Reset the src rect's origin so BltImageToDC() can go ahead and
  245. // honor the source rect passed to it when calling DrawDibDraw(),
  246. // SetDIBitsToDevice(), and StretchDIBits():
  247. rSrcRect.left = 0;
  248. rSrcRect.top = 0;
  249. rSrcRect.right = ulNewWidth;
  250. rSrcRect.bottom = ulNewHeight;
  251. // Use the new data instead of that which was passed in
  252. pBitmapInfo = pNewBitmapInfo;
  253. pImageData  = pNewImageData;
  254.     }
  255.     else if (pBitmapInfo->biCompression == HXCOLOR_RGB3_ID   ||
  256.      pBitmapInfo->biCompression == HXCOLOR_RGB555_ID ||
  257.      pBitmapInfo->biCompression == HXCOLOR_RGB565_ID ||
  258.      pBitmapInfo->biCompression == HXCOLOR_RGB24_ID)
  259.     {
  260. pNewBitmapInfo = new HXBitmapInfoHeader();
  261. memcpy(pNewBitmapInfo, pBitmapInfo, sizeof(HXBitmapInfoHeader)); /* Flawfinder: ignore */
  262. AdjustBitmapHeader(pNewBitmapInfo, pNewBitmapInfo->biCompression);
  263. // Use the new data instead of that which was passed in
  264. pBitmapInfo = pNewBitmapInfo;
  265.     }
  266.     if (bInterpolate)
  267.     {
  268. // we also need to fake out the source size so things don't stretch
  269. // further down the road.
  270. rSrcRect.right  = rSrcRect.left + ulNewWidth;
  271. rSrcRect.bottom = rSrcRect.top  + ulNewHeight;
  272.     }
  273. #endif
  274.     // Call the platform dependent blitter
  275.     hr = BltImage(pImageData, pBitmapInfo, rDestRect, rSrcRect);
  276.     if (bInterpolate)
  277.     {
  278. // we need to adjust back from our previous fake out
  279. // so things don't freak out even more further down the road.
  280. rSrcRect.right  = rSrcRect.left + ulOldWidth;
  281. rSrcRect.bottom = rSrcRect.top  + ulOldHeight;
  282.     }
  283.     if (pNewImageData)
  284.     {
  285. delete []pNewImageData;
  286. pNewImageData = NULL;
  287.     }
  288.     if (pNewBitmapInfo)
  289.     {
  290. delete pNewBitmapInfo;
  291. pNewBitmapInfo = NULL;
  292.     }
  293.     return hr;
  294. }
  295. STDMETHODIMP
  296. CHXSurface::BeginOptimizedBlt(HXBitmapInfoHeader* pBitmapInfo)
  297. {
  298.     // Check for a bad header
  299.     HX_ASSERT(pBitmapInfo);
  300.     HX_ASSERT(pBitmapInfo->biSizeImage >= (pBitmapInfo->biWidth *
  301. pBitmapInfo->biBitCount * pBitmapInfo->biHeight)/8);
  302.     if (!pBitmapInfo)
  303.     {
  304. return HXR_FAIL;
  305.     }
  306.     if (pBitmapInfo->biCompression == HX_RGB     ||
  307. pBitmapInfo->biCompression == HX_BITFIELDS ||
  308. pBitmapInfo->biCompression == HXCOLOR_RGB3_ID   ||
  309. pBitmapInfo->biCompression == HXCOLOR_RGB555_ID ||
  310. pBitmapInfo->biCompression == HXCOLOR_RGB565_ID ||
  311. pBitmapInfo->biCompression == HXCOLOR_RGB24_ID  ||
  312. pBitmapInfo->biCompression == HXCOLOR_8BIT_ID   ||
  313. pBitmapInfo->biCompression == HXCOLOR_YUV420_ID)
  314.     {
  315. m_pSite->SetOptimizedFormat(pBitmapInfo);
  316. return HXR_OK;
  317.     }
  318.     return HXR_FAIL;
  319. }
  320. STDMETHODIMP
  321. CHXSurface::OptimizedBlt(UCHAR* pImageBits,
  322.   REF(HXxRect) rDestRect,
  323.   REF(HXxRect) rSrcRect)
  324. {
  325.     //DebugTimer timer("CHXSurface::OptimizedBlt");
  326.     HXBitmapInfoHeader* pOptimizedFormat = m_pSite->GetOptimizedFormat();
  327.     HX_ASSERT(pOptimizedFormat);
  328.     if (!pOptimizedFormat)
  329.     {
  330. return HXR_UNEXPECTED;
  331.     }
  332.     return Blt(pImageBits, pOptimizedFormat, rDestRect, rSrcRect);
  333. }
  334. STDMETHODIMP
  335. CHXSurface::EndOptimizedBlt(void)
  336. {
  337.     HXBitmapInfoHeader* pOptimizedFormat = m_pSite->GetOptimizedFormat();
  338.     HX_ASSERT(pOptimizedFormat);
  339.     if (!pOptimizedFormat)
  340.     {
  341. return HXR_UNEXPECTED;
  342.     }
  343.     m_pSite->SetOptimizedFormat(NULL);
  344.     return HXR_OK;
  345. }
  346. STDMETHODIMP
  347. CHXSurface::GetOptimizedFormat(REF(HX_COMPRESSION_TYPE) ulType)
  348. {
  349.     HXBitmapInfoHeader* pOptimizedFormat = m_pSite->GetOptimizedFormat();
  350.     if (!pOptimizedFormat)
  351.     {
  352. return HXR_FAIL;
  353.     }
  354.     ulType = pOptimizedFormat->biCompression;
  355.     return HXR_OK;
  356. }
  357. STDMETHODIMP
  358. CHXSurface::GetPreferredFormat(REF(HX_COMPRESSION_TYPE) ulType)
  359. {
  360.     ulType = m_PreferredFormat;
  361.     return HXR_OK;
  362. }
  363. /*
  364.  * IHXVideoControls methods
  365.  */
  366. STDMETHODIMP_(float)
  367. CHXSurface::GetBrightness(void)
  368. {
  369.     return m_Brightness;
  370. }
  371. STDMETHODIMP
  372. CHXSurface::SetBrightness(float Brightness)
  373. {
  374.     if (Brightness > MAX_BRIGHTNESS)
  375.     {
  376. m_Brightness = (float) MAX_BRIGHTNESS;
  377.     }
  378.     else if (Brightness < MIN_BRIGHTNESS)
  379.     {
  380. m_Brightness = (float) MIN_BRIGHTNESS;
  381.     }
  382.     else
  383.     {
  384. m_Brightness = Brightness;
  385.     }
  386.     return HXR_OK;
  387. }
  388. STDMETHODIMP_(float)
  389. CHXSurface::GetContrast(void)
  390. {
  391.     return m_Contrast;
  392. }
  393. STDMETHODIMP
  394. CHXSurface::SetContrast(float Contrast)
  395. {
  396.     if (Contrast > MAX_CONTRAST)
  397.     {
  398. m_Contrast = (float) MAX_CONTRAST;
  399.     }
  400.     else if (Contrast < MIN_CONTRAST)
  401.     {
  402. m_Contrast = (float) MIN_CONTRAST;
  403.     }
  404.     else
  405.     {
  406. m_Contrast = Contrast;
  407.     }
  408.     return HXR_OK;
  409. }
  410. STDMETHODIMP_(float)
  411. CHXSurface::GetSaturation(void)
  412. {
  413.     return m_Saturation;
  414. }
  415. STDMETHODIMP
  416. CHXSurface::SetSaturation(float Saturation)
  417. {
  418.     if (Saturation > MAX_SATURATION)
  419.     {
  420. m_Saturation = (float) MAX_SATURATION;
  421.     }
  422.     else if (Saturation < MIN_SATURATION)
  423.     {
  424. m_Saturation = (float) MIN_SATURATION;
  425.     }
  426.     else
  427.     {
  428. m_Saturation = Saturation;
  429.     }
  430.     return HXR_OK;
  431. }
  432. STDMETHODIMP_(float)
  433. CHXSurface::GetHue(void)
  434. {
  435.     return m_Hue;
  436. }
  437. STDMETHODIMP
  438. CHXSurface::SetHue(float Hue)
  439. {
  440.     if (Hue > MAX_HUE)
  441.     {
  442. m_Hue = (float) MAX_HUE;
  443.     }
  444.     else if (Hue < MIN_HUE)
  445.     {
  446. m_Hue = (float) MIN_HUE;
  447.     }
  448.     else
  449.     {
  450. m_Hue = Hue;
  451.     }
  452.     return HXR_OK;
  453. }
  454. STDMETHODIMP_(float)
  455. CHXSurface::GetSharpness(void)
  456. {
  457.     return m_Sharpness;
  458. }
  459. STDMETHODIMP
  460. CHXSurface::SetSharpness(float Sharpness)
  461. {
  462.     if (Sharpness > MAX_SHARPNESS)
  463.     {
  464. m_Sharpness = (float) MAX_SHARPNESS;
  465.     }
  466.     else if (Sharpness < MIN_SHARPNESS)
  467.     {
  468. m_Sharpness = (float) MIN_SHARPNESS;
  469.     }
  470.     else
  471.     {
  472. m_Sharpness = Sharpness;
  473.     }
  474.     return HXR_OK;
  475. }
  476. STDMETHODIMP
  477. CHXSurface::SetModeSharpness(UINT16 dFlag)
  478. {
  479.     //set m_ModeSharpness =1 when deblocking filter is on
  480.     //set m_ModeSharpness =0 when deblocking filter is off
  481.     //find the deblocking filter on/off by getstreampreoperty
  482.     m_ModeSharpness=dFlag;
  483.     return HXR_OK;
  484. }
  485. void
  486. CHXSurface::PerformYUVConversion(UCHAR* ySrc,
  487.   UCHAR* uSrc,
  488.   UCHAR* vSrc,
  489.   INT32  nPitchSrc,
  490.   UCHAR* Dst,
  491.   INT32  nWidth,
  492.   INT32  nHeight,
  493.   INT32  nPitchDst,
  494.   HX_MOFTAG Format,
  495.   INT16  nExpand)
  496. {
  497.     INT16 nNewFormat = 0;
  498.     if (Format == HXCOLOR_RGB3_ID)
  499.     {
  500. nNewFormat = T_RGB888;
  501.     }
  502.     else if (Format == HXCOLOR_RGB565_ID)
  503.     {
  504. nNewFormat = T_RGB565;
  505.     }
  506.     else if (Format == HXCOLOR_RGB555_ID)
  507.     {
  508. nNewFormat = T_RGB555;
  509.     }
  510.     else
  511.     {
  512. HX_ASSERT(0); // Invalid format
  513.     }
  514.     // We only need to Set the Color Adjustments if they've changed
  515.     if (CheckColorSettings())
  516.     {
  517. // Adjust colors according to video control settings
  518. m_pConverter->SetColorAdjustments(m_Brightness, m_Contrast, m_Saturation, m_Hue);
  519. // Reset Previous values so next time we'll know if they've changed
  520. m_PrevBrightness = m_Brightness;
  521. m_PrevContrast  = m_Contrast;
  522. m_PrevSaturation = m_Saturation;
  523. m_PrevHue  = m_Hue;
  524.     }
  525.     // We only need to Set the Color Adjustments if they've changed
  526.     if (CheckSharpness())
  527.     {
  528. // Adjust colors according to video control settings
  529. m_pConverter->SetSharpnessAdjustments(m_Sharpness,nExpand);
  530. // Reset Previous values so next time we'll know if they've changed
  531. m_PrevSharpness = m_Sharpness;
  532.    }
  533.     if (ySrc[0] != 1)
  534.     {
  535. //if Sharpness is -1.0 (or close) do not do any edge enhancement
  536. //check necessary because intel mmx edge enhacement does not check this
  537. if( (m_Sharpness+1.0)>0.1 )
  538. {
  539. if(m_ModeSharpness)
  540. {
  541.     //Deblocking filter is ON
  542.     m_pConverter->EnhanceUniform(ySrc,nHeight,nWidth,nPitchSrc,m_Sharpness);
  543. }
  544. else
  545. {
  546.     //Deblocking filter is OFF
  547.     m_pConverter->Enhance(ySrc,nHeight,nWidth,nPitchSrc,m_Sharpness);
  548. }
  549. }
  550.     }
  551.     else
  552.     {
  553. ySrc[0] = ySrc[1];
  554.     }
  555.     // Execute the conversion
  556.     m_pConverter->ConvertYUVtoRGB(ySrc, uSrc, vSrc, nPitchSrc, Dst, nWidth,
  557. nHeight, nPitchDst, nNewFormat, nExpand);
  558.     //change one corner pixel to put a digital watermark
  559.     ySrc[0] = 1;
  560. }
  561. UINT16
  562. CHXSurface::CheckColorSettings()
  563. {
  564. // NOTE 40 steps of granularity for color control parameters (based on
  565. // below float to int precision; proper rounding is not essential)
  566.     if( (int)(m_PrevBrightness * 20.f) != (int)(m_Brightness * 20.f) ||
  567. (int)(m_PrevContrast * 20.f) != (int)(m_Contrast * 20.f) ||
  568. (int)(m_PrevSaturation * 20.f) != (int)(m_Saturation * 20.f) ||
  569. (int)(m_PrevHue * 20.f) != (int)(m_Hue * 20.f) )
  570.     {
  571. return 1; // reinitializationing of color table required
  572.     }
  573.     else
  574.     {
  575. return 0; // no change in color controls
  576.     }
  577. }
  578. UINT16
  579. CHXSurface::CheckSharpness()
  580. {
  581. // NOTE 40 steps of granularity for sharpness control parameters (based on
  582. // below float to int precision; proper rounding is not essential)
  583.     if( (int)(m_PrevSharpness * 20.f) != (int)(m_Sharpness * 20.f)  )
  584.     {
  585. return 1; // reinitializationing of sharpness table required
  586.     }
  587.     else
  588.     {
  589. return 0; // no change in sharpness table
  590.     }
  591. }
  592. UINT16
  593. CHXSurface::CalculateNewBitDepth(HX_COMPRESSION_TYPE nNewFormat)
  594. {
  595.     UINT16 nNewBitDepth = 0;
  596.     switch (nNewFormat)
  597.     {
  598. case HXCOLOR_RGB3_ID:
  599. {
  600. #ifdef _MACINTOSH
  601.     nNewBitDepth = 32;
  602. #else
  603.     nNewBitDepth = 24;
  604. #endif
  605. }
  606. break;
  607. case HXCOLOR_RGB24_ID:
  608. {
  609.     nNewBitDepth = 24;
  610. }
  611. break;
  612. #ifdef _WINDOWS
  613. case HXCOLOR_RGB555_ID:
  614. {
  615.     nNewBitDepth = 16;
  616. }
  617. break;
  618. case HXCOLOR_RGB565_ID:
  619. {
  620.     nNewBitDepth = 16;
  621. }
  622. break;
  623. #endif
  624. default:
  625.     HX_ASSERT(0);   // Invalid format
  626.     break;
  627.     }
  628.     return nNewBitDepth;
  629. }
  630. void
  631. CHXSurface::AdjustBitmapHeader(HXBitmapInfoHeader* pBitmapInfo,
  632. HX_MOFTAG NewFormat)
  633. {
  634.     switch (NewFormat)
  635.     {
  636. case HXCOLOR_RGB3_ID:
  637. {
  638. #ifdef _MACINTOSH
  639.     pBitmapInfo->biCompression = HX_RGB;
  640.     pBitmapInfo->biBitCount  = 32;
  641. #else
  642.     pBitmapInfo->biCompression = HX_RGB;
  643.     pBitmapInfo->biBitCount  = 24;
  644. #endif
  645. }
  646. break;
  647. case HXCOLOR_RGB24_ID:
  648. {
  649.     pBitmapInfo->biCompression = HX_RGB;
  650.     pBitmapInfo->biBitCount  = 24;
  651. }
  652. break;
  653. #ifdef _WINDOWS
  654. case HXCOLOR_RGB555_ID:
  655. {
  656.     pBitmapInfo->biCompression = HX_BITFIELDS;
  657.     pBitmapInfo->biBitCount    = 16;
  658.     pBitmapInfo->rcolor =   0x00007C00; // red
  659.     pBitmapInfo->gcolor =   0x000003E0; // green
  660.     pBitmapInfo->bcolor =   0x0000001F; // blue
  661. }
  662. break;
  663. case HXCOLOR_RGB565_ID:
  664. {
  665.     pBitmapInfo->biCompression = HX_BITFIELDS;
  666.     pBitmapInfo->biBitCount    = 16;
  667.     pBitmapInfo->rcolor =    0x0000F800; // red
  668.     pBitmapInfo->gcolor =    0x000007E0; // green
  669.     pBitmapInfo->bcolor =    0x0000001F; // blue
  670. }
  671. break;
  672. #endif
  673. default:
  674.     HX_ASSERT(0);   // Invalid format
  675.     break;
  676.     }
  677. }