diff --git a/subsystems/win32/win32k/eng/surface.c b/subsystems/win32/win32k/eng/surface.c index 46f96d81c3e..815f67063ca 100644 --- a/subsystems/win32/win32k/eng/surface.c +++ b/subsystems/win32/win32k/eng/surface.c @@ -200,18 +200,17 @@ SURFACE_bSetBitmapBits( cBitsPixel = gajBitsPerFormat[pso->iBitmapFormat]; /* Is a width in bytes given? */ - if (!ulWidth) + if (ulWidth) { - /* Calculate width from the bitmap width in pixels */ - ulWidth = DIB_GetDIBWidthBytes(psurf->SurfObj.sizlBitmap.cx, cBitsPixel); + /* Align the width (Windows compatibility, drivers expect that) */ + ulWidth = WIDTH_BYTES_ALIGN32((ulWidth << 3) / cBitsPixel, cBitsPixel); } else { - /* Align the width (windows compatibility, drivers expect that) */ - ulWidth = ((((ulWidth << 3) / cBitsPixel) * cBitsPixel + 31) & ~31) >> 3; + /* Calculate width from the bitmap width in pixels */ + ulWidth = WIDTH_BYTES_ALIGN32(pso->sizlBitmap.cx, cBitsPixel); } - /* Calculate the bitmap size in bytes */ pso->cjBits = ulWidth * pso->sizlBitmap.cy; diff --git a/subsystems/win32/win32k/include/surface.h b/subsystems/win32/win32k/include/surface.h index e19a1986425..485f3dc72b3 100644 --- a/subsystems/win32/win32k/include/surface.h +++ b/subsystems/win32/win32k/include/surface.h @@ -128,3 +128,7 @@ SURFACE_bSetBitmapBits( ULONG FASTCALL BitmapFormat (WORD Bits, DWORD Compression); extern UCHAR gajBitsPerFormat[]; #define BitsPerFormat(Format) gajBitsPerFormat[Format] + +#define WIDTH_BYTES_ALIGN32(cx, bpp) ((((cx) * (bpp) + 31) & ~31) >> 3) +#define WIDTH_BYTES_ALIGN16(cx, bpp) ((((cx) * (bpp) + 15) & ~15) >> 3) +