Author: jgardou Date: Fri Oct 24 17:31:37 2014 New Revision: 64965
URL: http://svn.reactos.org/svn/reactos?rev=64965&view=rev Log: [WIN32K] - Differenciate 16bpp 565 from 16bpp 555 in alphablending code. - Fix RGB vs BGR mismatch CORE-8695
Modified: trunk/reactos/win32ss/gdi/dib/dib16bpp.c
Modified: trunk/reactos/win32ss/gdi/dib/dib16bpp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/dib/dib16bpp.c?... ============================================================================== --- trunk/reactos/win32ss/gdi/dib/dib16bpp.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/dib/dib16bpp.c [iso-8859-1] Fri Oct 24 17:31:37 2014 @@ -542,11 +542,23 @@ USHORT us; struct { + USHORT blue :5; + USHORT green :6; USHORT red :5; - USHORT green :6; + } col; +} NICEPIXEL16_565; + +typedef union +{ + USHORT us; + struct + { USHORT blue :5; + USHORT green :5; + USHORT red :5; + USHORT xxxx :1; } col; -} NICEPIXEL16; +} NICEPIXEL16_555;
static __inline UCHAR Clamp6(ULONG val) @@ -568,8 +580,7 @@ INT DstX, DstY, SrcX, SrcY; BLENDFUNCTION BlendFunc; NICEPIXEL32 SrcPixel32; - NICEPIXEL16 DstPixel16; - UCHAR Alpha, Alpha6, Alpha5; + UCHAR Alpha; EXLATEOBJ* pexlo; EXLATEOBJ exloSrcRGB;
@@ -609,46 +620,97 @@ pexlo = CONTAINING_RECORD(ColorTranslation, EXLATEOBJ, xlo); EXLATEOBJ_vInitialize(&exloSrcRGB, pexlo->ppalSrc, &gpalRGB, 0, 0, 0);
- SrcY = SourceRect->top; - DstY = DestRect->top; - while ( DstY < DestRect->bottom ) - { - SrcX = SourceRect->left; - DstX = DestRect->left; - while(DstX < DestRect->right) - { - SrcPixel32.ul = DIB_GetSource(Source, SrcX, SrcY, &exloSrcRGB.xlo); - 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; - - Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ? - (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha) / 255 : - BlendFunc.SourceConstantAlpha; - - Alpha6 = Alpha >> 2; - Alpha5 = Alpha >> 3; - - DstPixel16.us = DIB_16BPP_GetPixel(Dest, DstX, DstY) & 0xFFFF; - /* Perform bit loss */ - SrcPixel32.col.red >>= 3; - SrcPixel32.col.green >>= 2; - SrcPixel32.col.blue >>= 3; - - /* Do the blend in the right bit depth */ - DstPixel16.col.red = Clamp5((DstPixel16.col.red * (31 - Alpha5)) / 31 + SrcPixel32.col.red); - DstPixel16.col.green = Clamp6((DstPixel16.col.green * (63 - Alpha6)) / 63 + SrcPixel32.col.green); - DstPixel16.col.blue = Clamp5((DstPixel16.col.blue * (31 - Alpha5)) / 31 + SrcPixel32.col.blue); - - DIB_16BPP_PutPixel(Dest, DstX, DstY, DstPixel16.us); - - DstX++; - SrcX = SourceRect->left + ((DstX-DestRect->left)*(SourceRect->right - SourceRect->left)) - /(DestRect->right-DestRect->left); - } - DstY++; - SrcY = SourceRect->top + ((DstY-DestRect->top)*(SourceRect->bottom - SourceRect->top)) - /(DestRect->bottom-DestRect->top); + if (pexlo->ppalDst->flFlags & PAL_RGB16_555) + { + NICEPIXEL16_555 DstPixel16; + + SrcY = SourceRect->top; + DstY = DestRect->top; + while ( DstY < DestRect->bottom ) + { + SrcX = SourceRect->left; + DstX = DestRect->left; + while(DstX < DestRect->right) + { + SrcPixel32.ul = DIB_GetSource(Source, SrcX, SrcY, &exloSrcRGB.xlo); + 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; + + Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ? + (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha) / 255 : + BlendFunc.SourceConstantAlpha; + + Alpha >>= 3; + + DstPixel16.us = DIB_16BPP_GetPixel(Dest, DstX, DstY) & 0xFFFF; + /* Perform bit loss */ + SrcPixel32.col.red >>= 3; + SrcPixel32.col.green >>= 3; + SrcPixel32.col.blue >>= 3; + + /* Do the blend in the right bit depth */ + DstPixel16.col.red = Clamp5((DstPixel16.col.red * (31 - Alpha)) / 31 + SrcPixel32.col.red); + DstPixel16.col.green = Clamp5((DstPixel16.col.green * (31 - Alpha)) / 31 + SrcPixel32.col.green); + DstPixel16.col.blue = Clamp5((DstPixel16.col.blue * (31 - Alpha)) / 31 + SrcPixel32.col.blue); + + DIB_16BPP_PutPixel(Dest, DstX, DstY, DstPixel16.us); + + DstX++; + SrcX = SourceRect->left + ((DstX-DestRect->left)*(SourceRect->right - SourceRect->left)) + /(DestRect->right-DestRect->left); + } + DstY++; + SrcY = SourceRect->top + ((DstY-DestRect->top)*(SourceRect->bottom - SourceRect->top)) + /(DestRect->bottom-DestRect->top); + } + } + else + { + NICEPIXEL16_565 DstPixel16; + UCHAR Alpha6, Alpha5; + + SrcY = SourceRect->top; + DstY = DestRect->top; + while ( DstY < DestRect->bottom ) + { + SrcX = SourceRect->left; + DstX = DestRect->left; + while(DstX < DestRect->right) + { + SrcPixel32.ul = DIB_GetSource(Source, SrcX, SrcY, &exloSrcRGB.xlo); + 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; + + Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ? + (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha) / 255 : + BlendFunc.SourceConstantAlpha; + + Alpha6 = Alpha >> 2; + Alpha5 = Alpha >> 3; + + DstPixel16.us = DIB_16BPP_GetPixel(Dest, DstX, DstY) & 0xFFFF; + /* Perform bit loss */ + SrcPixel32.col.red >>= 3; + SrcPixel32.col.green >>= 2; + SrcPixel32.col.blue >>= 3; + + /* Do the blend in the right bit depth */ + DstPixel16.col.red = Clamp5((DstPixel16.col.red * (31 - Alpha5)) / 31 + SrcPixel32.col.red); + DstPixel16.col.green = Clamp6((DstPixel16.col.green * (63 - Alpha6)) / 63 + SrcPixel32.col.green); + DstPixel16.col.blue = Clamp5((DstPixel16.col.blue * (31 - Alpha5)) / 31 + SrcPixel32.col.blue); + + DIB_16BPP_PutPixel(Dest, DstX, DstY, DstPixel16.us); + + DstX++; + SrcX = SourceRect->left + ((DstX-DestRect->left)*(SourceRect->right - SourceRect->left)) + /(DestRect->right-DestRect->left); + } + DstY++; + SrcY = SourceRect->top + ((DstY-DestRect->top)*(SourceRect->bottom - SourceRect->top)) + /(DestRect->bottom-DestRect->top); + } }
EXLATEOBJ_vCleanup(&exloSrcRGB);