Beispiel #1
0
// performs AlphaBlend
//static 
void MapWindow::DoAlphaBlend(HDC dstHdc, const RECT dstRect, HDC srcHdc, const RECT srcRect, BYTE globalOpacity) {
  if (AlphaBlendF == NULL)
    return;
  
  //BLENDFUNCTION bf = { AC_SRC_OVER, 0, globalOpacity, AC_SRC_ALPHA };
  // we are not using per-pixel alpha, so do not use AC_SRC_ALPHA flag
  BLENDFUNCTION bf = { AC_SRC_OVER, 0, globalOpacity, 0 };
  
  AlphaBlendF(
    dstHdc, dstRect.left, dstRect.top, dstRect.right - dstRect.left, dstRect.bottom - dstRect.top,
    srcHdc, srcRect.left, srcRect.top, srcRect.right - srcRect.left, srcRect.bottom - srcRect.top, bf);
} // DoAlphaBlend()
Beispiel #2
0
bool LKSurface::AlphaBlend(const RECT& dstRect, const LKSurface& Surface, const RECT& srcRect, uint8_t globalOpacity) {
    if(!AlphaBlendSupported()) {
        return false;
    }

#ifdef USE_GDI
#ifdef UNDER_CE

    extern BOOL DoAlphaBlend_internal(HDC,int,int,int,int,HDC,int,int,int,int, DWORD);

    static unsigned failedCount = 0;
    static bool Success = false;

    bool bOK = false;
    if (AlphaBlendF) {
        //BLENDFUNCTION bf = { AC_SRC_OVER, 0, globalOpacity, AC_SRC_ALPHA };
        // we are not using per-pixel alpha, so do not use AC_SRC_ALPHA flag
        BLENDFUNCTION bf = {AC_SRC_OVER, 0, globalOpacity, 0};
        bOK = AlphaBlendF(
                *this, dstRect.left, dstRect.top, dstRect.right - dstRect.left, dstRect.bottom - dstRect.top,
                Surface, srcRect.left, srcRect.top, srcRect.right - srcRect.left, srcRect.bottom - srcRect.top, bf);

        if (!Success) {
            if (!bOK && dstRect.right - dstRect.left > 0 &&
                    dstRect.bottom - dstRect.top > 0 &&
                    srcRect.right - srcRect.left > 0 &&
                    srcRect.bottom - srcRect.top > 0) {

                // after more 10 consecutive failed, we assume AlphaBlend is not supported, don't use it anymore
                ++failedCount;
                if (failedCount > 10) {
                    AlphaBlendF = NULL;
                }
            }
            Success = bOK;
        }
    }

    if (!bOK) {
        bOK = DoAlphaBlend_internal(
                *this, dstRect.left, dstRect.top, dstRect.right - dstRect.left, dstRect.bottom - dstRect.top,
                Surface, srcRect.left, srcRect.top, srcRect.right - srcRect.left, srcRect.bottom - srcRect.top, globalOpacity);
    }

    return bOK;

#else
    //BLENDFUNCTION bf = { AC_SRC_OVER, 0, globalOpacity, AC_SRC_ALPHA };
    // we are not using per-pixel alpha, so do not use AC_SRC_ALPHA flag
    BLENDFUNCTION bf = {AC_SRC_OVER, 0, globalOpacity, 0};
    ::AlphaBlend(*this, dstRect.left, dstRect.top, dstRect.right - dstRect.left, dstRect.bottom - dstRect.top,
            Surface, srcRect.left, srcRect.top, srcRect.right - srcRect.left, srcRect.bottom - srcRect.top, bf);

    return true; // always return true because always implemented on Windows PC
#endif
#else
    if(_pCanvas) {
        _pCanvas->AlphaBlend(dstRect.left, dstRect.top, dstRect.right - dstRect.left, dstRect.bottom - dstRect.top,
                        Surface, srcRect.left, srcRect.top, srcRect.right - srcRect.left, srcRect.bottom - srcRect.top, globalOpacity);
        return true;
    }
    return false;
#endif    
}