return TRUE;
}
-typedef union
-{
- ULONG ul;
- struct
- {
- UCHAR red;
- UCHAR green;
- UCHAR blue;
- UCHAR alpha;
- } col;
-} NICEPIXEL32;
-
-typedef union
-{
- USHORT us;
- struct
- {
- USHORT red:5,
- green:6,
- blue:5;
- } col;
-} NICEPIXEL16;
-
-static __inline UCHAR
-Clamp5(ULONG val)
-{
- return (val > 31) ? 31 : val;
-}
-
-static __inline UCHAR
-Clamp8(ULONG val)
-{
- return (val > 255) ? 255 : val;
-}
-
-static __inline UCHAR
-Clamp6(ULONG val)
-{
- return (val > 63) ? 63 : val;
-}
-
-BOOLEAN
-DIB_16BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
- RECTL* SourceRect, CLIPOBJ* ClipRegion,
- XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
-{
- INT Rows, Cols, SrcX, SrcY;
- register PUSHORT Dst;
- ULONG DstDelta;
- BLENDFUNCTION BlendFunc;
- register NICEPIXEL16 SrcPixel16;
- register NICEPIXEL16 DstPixel16;
- register NICEPIXEL32 SrcPixel32;
- register NICEPIXEL32 DstPixel32;
- UCHAR Alpha, SrcBpp;
- EXLATEOBJ *pexlo;
- EXLATEOBJ exloDst2Src;
-
- DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
- SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
- DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
-
- ASSERT(DestRect->bottom - DestRect->top == SourceRect->bottom - SourceRect->top &&
- DestRect->right - DestRect->left == SourceRect->right - SourceRect->left);
-
- BlendFunc = BlendObj->BlendFunction;
- if (BlendFunc.BlendOp != AC_SRC_OVER)
- {
- DPRINT1("BlendOp != AC_SRC_OVER\n");
- return FALSE;
- }
- if (BlendFunc.BlendFlags != 0)
- {
- DPRINT1("BlendFlags != 0\n");
- return FALSE;
- }
- if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0)
- {
- DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat);
- return FALSE;
- }
- if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 &&
- BitsPerFormat(Source->iBitmapFormat) != 32)
- {
- DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
- return FALSE;
- }
-
- if (!ColorTranslation)
- {
- DPRINT1("ColorTranslation must not be NULL!\n");
- return FALSE;
- }
-
- pexlo = CONTAINING_RECORD(ColorTranslation, EXLATEOBJ, xlo);
- EXLATEOBJ_vInitialize(&exloDst2Src, pexlo->ppalDst, pexlo->ppalSrc, 0, 0, 0);
-
- Dst = (PUSHORT)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
- (DestRect->left << 1));
- DstDelta = Dest->lDelta - ((DestRect->right - DestRect->left) << 1);
- SrcBpp = BitsPerFormat(Source->iBitmapFormat);
-
- Rows = DestRect->bottom - DestRect->top;
- SrcY = SourceRect->top;
- while (--Rows >= 0)
- {
- Cols = DestRect->right - DestRect->left;
- SrcX = SourceRect->left;
- while (--Cols >= 0)
- {
- if (SrcBpp <= 16)
- {
- SrcPixel16.us = DIB_GetSource(Source, SrcX++, SrcY, ColorTranslation);
- SrcPixel32.col.red = (SrcPixel16.col.red << 3);
- SrcPixel32.col.green = (SrcPixel16.col.green << 2);
- SrcPixel32.col.blue = (SrcPixel16.col.blue << 3);
-
- SrcPixel32.col.red = SrcPixel32.col.red * BlendFunc.SourceConstantAlpha / 255;
- SrcPixel32.col.green = SrcPixel32.col.green * BlendFunc.SourceConstantAlpha / 255;
- SrcPixel32.col.blue = SrcPixel32.col.blue * BlendFunc.SourceConstantAlpha / 255;
- SrcPixel32.col.alpha = (SrcBpp == 32) ?
- (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha / 255) :
- BlendFunc.SourceConstantAlpha;
-
- Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
- SrcPixel32.col.alpha : BlendFunc.SourceConstantAlpha;
-
- DstPixel16.us = *Dst;
- DstPixel16.col.red = Clamp5(DstPixel16.col.red * (255 - Alpha) / 255 +
- (SrcPixel32.col.red >> 3));
-
- DstPixel16.col.green = Clamp6(DstPixel16.col.green * (255 - Alpha) / 255 +
- (SrcPixel32.col.green >> 2));
-
- DstPixel16.col.blue = Clamp5(DstPixel16.col.blue * (255 - Alpha) / 255 +
- (SrcPixel32.col.blue >> 3));
-
- *Dst++ = DstPixel16.us;
- }
- else
- {
- SrcPixel32.ul = DIB_GetSourceIndex(Source, SrcX++, SrcY);
-
- SrcPixel32.col.red = SrcPixel32.col.red * BlendFunc.SourceConstantAlpha / 255;
- SrcPixel32.col.green = SrcPixel32.col.green * BlendFunc.SourceConstantAlpha / 255;
- SrcPixel32.col.blue = SrcPixel32.col.blue * BlendFunc.SourceConstantAlpha / 255;
- SrcPixel32.col.alpha = (SrcBpp == 32) ?
- (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha / 255) :
- BlendFunc.SourceConstantAlpha;
-
- Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
- SrcPixel32.col.alpha : BlendFunc.SourceConstantAlpha;
-
- DstPixel32.ul = XLATEOBJ_iXlate(&exloDst2Src.xlo, *Dst);
- SrcPixel32.col.red = Clamp8(DstPixel32.col.red * (255 - Alpha) / 255 + SrcPixel32.col.red);
- SrcPixel32.col.green = Clamp8(DstPixel32.col.green * (255 - Alpha) / 255 + SrcPixel32.col.green);
- SrcPixel32.col.blue = Clamp8(DstPixel32.col.blue * (255 - Alpha) / 255 + SrcPixel32.col.blue);
- *Dst++ = XLATEOBJ_iXlate(ColorTranslation, SrcPixel32.ul);
- }
- }
-
- Dst = (PUSHORT)((ULONG_PTR)Dst + DstDelta);
- SrcY++;
- }
-
- EXLATEOBJ_vCleanup(&exloDst2Src);
-
- return TRUE;
-}
-
/* EOF */