Module: wine Branch: master Commit: d33e0d2c866f14f195fa72ad82ef1649a7f18303 URL: http://source.winehq.org/git/wine.git/?a=commit;h=d33e0d2c866f14f195fa72ad82...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Jul 25 15:24:12 2011 +0200
gdi32: Add an inline helper to retrieve a DDB byte width.
---
dlls/gdi32/bitmap.c | 41 +++-------------------------------------- dlls/gdi32/enhmfdrv/objects.c | 2 +- dlls/gdi32/gdi_private.h | 6 +++++- dlls/gdi32/mfdrv/objects.c | 2 +- 4 files changed, 10 insertions(+), 41 deletions(-)
diff --git a/dlls/gdi32/bitmap.c b/dlls/gdi32/bitmap.c index 620e75c..2e23f6e 100644 --- a/dlls/gdi32/bitmap.c +++ b/dlls/gdi32/bitmap.c @@ -137,41 +137,6 @@ done: }
-/*********************************************************************** - * BITMAP_GetWidthBytes - * - * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB - * data. - */ -INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp ) -{ - switch(bpp) - { - case 1: - return 2 * ((bmWidth+15) >> 4); - - case 24: - bmWidth *= 3; /* fall through */ - case 8: - return bmWidth + (bmWidth & 1); - - case 32: - return bmWidth * 4; - - case 16: - case 15: - return bmWidth * 2; - - case 4: - return 2 * ((bmWidth+3) >> 2); - - default: - WARN("Unknown depth %d, please report.\n", bpp ); - } - return -1; -} - - /****************************************************************************** * CreateBitmap [GDI32.@] * @@ -196,7 +161,7 @@ HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes, bm.bmType = 0; bm.bmWidth = width; bm.bmHeight = height; - bm.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp ); + bm.bmWidthBytes = get_bitmap_stride( width, bpp ); bm.bmPlanes = planes; bm.bmBitsPixel = bpp; bm.bmBits = (LPVOID)bits; @@ -363,7 +328,7 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp ) }
/* Windows ignores the provided bm.bmWidthBytes */ - bm.bmWidthBytes = BITMAP_GetWidthBytes( bm.bmWidth, bm.bmBitsPixel ); + bm.bmWidthBytes = get_bitmap_stride( bm.bmWidth, bm.bmBitsPixel ); /* XP doesn't allow to create bitmaps larger than 128 Mb */ if (bm.bmHeight > 128 * 1024 * 1024 / bm.bmWidthBytes) { @@ -426,7 +391,7 @@ LONG WINAPI GetBitmapBits( { DIBSECTION *dib = bmp->dib; const char *src = dib->dsBm.bmBits; - INT width_bytes = BITMAP_GetWidthBytes(dib->dsBm.bmWidth, dib->dsBm.bmBitsPixel); + INT width_bytes = get_bitmap_stride(dib->dsBm.bmWidth, dib->dsBm.bmBitsPixel); LONG max = width_bytes * bmp->bitmap.bmHeight;
if (!bits) diff --git a/dlls/gdi32/enhmfdrv/objects.c b/dlls/gdi32/enhmfdrv/objects.c index a3d976e..fca6f63 100644 --- a/dlls/gdi32/enhmfdrv/objects.c +++ b/dlls/gdi32/enhmfdrv/objects.c @@ -231,7 +231,7 @@ DWORD EMFDRV_CreateBrushIndirect( PHYSDEV dev, HBRUSH hBrush ) info->biBitCount = bm.bmBitsPixel; info->biSizeImage = bmSize; GetBitmapBits((HANDLE)logbrush.lbHatch, - bm.bmHeight * BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), + bm.bmHeight * get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel), (LPBYTE)info + sizeof(BITMAPINFOHEADER));
/* Change the padding to be DIB compatible if needed */ diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h index bdd9606..b825df9 100644 --- a/dlls/gdi32/gdi_private.h +++ b/dlls/gdi32/gdi_private.h @@ -311,7 +311,6 @@ extern BOOL BIDI_Reorder( HDC hDC, LPCWSTR lpString, INT uCount, DWORD dwFlags, /* bitmap.c */ extern HBITMAP BITMAP_CopyBitmap( HBITMAP hbitmap ) DECLSPEC_HIDDEN; extern BOOL BITMAP_SetOwnerDC( HBITMAP hbitmap, PHYSDEV physdev ) DECLSPEC_HIDDEN; -extern INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp ) DECLSPEC_HIDDEN;
/* clipping.c */ extern int get_clip_box( DC *dc, RECT *rect ) DECLSPEC_HIDDEN; @@ -549,6 +548,11 @@ static inline void offset_rect( RECT *rect, int offset_x, int offset_y ) rect->bottom += offset_y; }
+static inline int get_bitmap_stride( int width, int bpp ) +{ + return ((width * bpp + 15) >> 3) & ~1; +} + static inline int get_dib_stride( int width, int bpp ) { return ((width * bpp + 31) >> 3) & ~3; diff --git a/dlls/gdi32/mfdrv/objects.c b/dlls/gdi32/mfdrv/objects.c index 3054950..d9c9f95 100644 --- a/dlls/gdi32/mfdrv/objects.c +++ b/dlls/gdi32/mfdrv/objects.c @@ -270,7 +270,7 @@ INT16 MFDRV_CreateBrushIndirect(PHYSDEV dev, HBRUSH hBrush ) info->bmiHeader.biSizeImage = bmSize;
GetBitmapBits((HANDLE)logbrush.lbHatch, - bm.bmHeight * BITMAP_GetWidthBytes (bm.bmWidth, bm.bmBitsPixel), + bm.bmHeight * get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel), (LPBYTE)info + sizeof(BITMAPINFO) + sizeof(RGBQUAD));
/* Change the padding to be DIB compatible if needed */