pxtransp.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:5k
源码类别:

Symbian

开发平台:

Visual C++

  1. // include
  2. #include "hxtypes.h"
  3. #include "hxwintyp.h"
  4. #include "hxcom.h"
  5. #include "ihxpckts.h"
  6. // pnmisc
  7. #include "hxparse.h"
  8. // pxcomlib
  9. #include "pxtransp.h"
  10. HX_RESULT ParseTransparencyParameters(IHXValues* pValues,
  11.                                       REF(UINT32) rulBgOpacity,
  12.                                       REF(BOOL)   rbBgOpacitySpecified,
  13.                                       REF(UINT32) rulMediaOpacity,
  14.                                       REF(BOOL)   rbMediaOpacitySpecified,
  15.                                       REF(UINT32) rulChromaKey,
  16.                                       REF(BOOL)   rbChromaKeySpecified,
  17.                                       REF(UINT32) rulChromaKeyTolerance,
  18.                                       REF(UINT32) rulChromaKeyOpacity,
  19.                                       REF(BOOL)   rbAlphaChannelNeeded)
  20. {
  21.     HX_RESULT retVal = HXR_OK;
  22.     if (pValues)
  23.     {
  24.         // Get the background opacity
  25.         IHXBuffer* pStr = NULL;
  26.         HX_RESULT   rv   = pValues->GetPropertyCString("backgroundOpacity", pStr);
  27.         if (SUCCEEDED(rv))
  28.         {
  29.             UINT32 ulTmp = 0;
  30.             retVal = HXParseOpacity((const char*) pStr->GetBuffer(), ulTmp);
  31.             if (SUCCEEDED(retVal))
  32.             {
  33.                 rulBgOpacity         = ulTmp;
  34.                 rbBgOpacitySpecified = TRUE;
  35.                 if (rulBgOpacity < 255)
  36.                 {
  37.                     rbAlphaChannelNeeded = TRUE;
  38.                 }
  39.             }
  40.         }
  41.         if (SUCCEEDED(retVal))
  42.         {
  43.             // Get the media opacity
  44.             HX_RELEASE(pStr);
  45.             rv = pValues->GetPropertyCString("mediaOpacity", pStr);
  46.             if (SUCCEEDED(rv))
  47.             {
  48.                 UINT32 ulTmp = 0;
  49.                 retVal = HXParseOpacity((const char*) pStr->GetBuffer(), ulTmp);
  50.                 if (SUCCEEDED(retVal))
  51.                 {
  52.                     rulMediaOpacity         = ulTmp;
  53.                     rbMediaOpacitySpecified = TRUE;
  54.                     if (rulMediaOpacity < 255)
  55.                     {
  56.                         rbAlphaChannelNeeded = TRUE;
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.         if (SUCCEEDED(retVal))
  62.         {
  63.             // Get the media chromakey
  64.             HX_RELEASE(pStr);
  65.             rv = pValues->GetPropertyCString("chromaKey", pStr);
  66.             if (SUCCEEDED(rv))
  67.             {
  68.                 UINT32 ulTmp = 0;
  69.                 retVal = HXParseColorUINT32((const char*) pStr->GetBuffer(), ulTmp);
  70.                 if (SUCCEEDED(retVal))
  71.                 {
  72.                     rulChromaKey         = ulTmp;
  73.                     rbChromaKeySpecified = TRUE;
  74.                     rbAlphaChannelNeeded = TRUE;
  75.                 }
  76.             }
  77.         }
  78.         if (SUCCEEDED(retVal))
  79.         {
  80.             // Get the media chromakey tolerance
  81.             HX_RELEASE(pStr);
  82.             rv = pValues->GetPropertyCString("chromaKeyTolerance", pStr);
  83.             if (SUCCEEDED(rv))
  84.             {
  85.                 UINT32 ulTmp = 0;
  86.                 retVal = HXParseColorUINT32((const char*) pStr->GetBuffer(), ulTmp);
  87.                 if (SUCCEEDED(retVal))
  88.                 {
  89.                     rulChromaKeyTolerance = ulTmp;
  90.                 }
  91.             }
  92.         }
  93.         if (SUCCEEDED(retVal))
  94.         {
  95.             // Get the chroma key opacity
  96.             HX_RELEASE(pStr);
  97.             rv = pValues->GetPropertyCString("chromaKeyOpacity", pStr);
  98.             if (SUCCEEDED(rv))
  99.             {
  100.                 UINT32 ulTmp = 0;
  101.                 retVal = HXParseOpacity((const char*) pStr->GetBuffer(), ulTmp);
  102.                 if (SUCCEEDED(rv))
  103.                 {
  104.                     rulChromaKeyOpacity = ulTmp;
  105.                 }
  106.             }
  107.         }
  108.         HX_RELEASE(pStr);
  109.     }
  110.     else
  111.     {
  112.         retVal = HXR_FAIL;
  113.     }
  114.     return retVal;
  115. }
  116. BOOL DoesChromaKeyChannelMatch(UINT32 ulColor,
  117.                                UINT32 ulChromaKey,
  118.                                UINT32 ulChromaKeyTol)
  119. {
  120.     BOOL bRet = FALSE;
  121.     INT32 lDiff = ((INT32) ulColor) - ((INT32) ulChromaKey);
  122.     if (lDiff < 0)
  123.     {
  124.         lDiff = -lDiff;
  125.     }
  126.     if (lDiff <= (INT32) ulChromaKeyTol)
  127.     {
  128.         bRet = TRUE;
  129.     }
  130.     return bRet;
  131. }
  132. BOOL DoesChromaKeyMatch(UINT32 ulColor,
  133.                         UINT32 ulChromaKey,
  134.                         UINT32 ulChromaKeyTol)
  135. {
  136.     BOOL bRet = FALSE;
  137.     if (DoesChromaKeyChannelMatch(ARGB32_RED(ulColor),
  138.                                   ARGB32_RED(ulChromaKey),
  139.                                   ARGB32_RED(ulChromaKeyTol)) &&
  140.         DoesChromaKeyChannelMatch(ARGB32_GREEN(ulColor),
  141.                                   ARGB32_GREEN(ulChromaKey),
  142.                                   ARGB32_GREEN(ulChromaKeyTol)) &&
  143.         DoesChromaKeyChannelMatch(ARGB32_BLUE(ulColor),
  144.                                   ARGB32_BLUE(ulChromaKey),
  145.                                   ARGB32_BLUE(ulChromaKeyTol)))
  146.     {
  147.         bRet = TRUE;
  148.     }
  149.     return bRet;
  150. }