gdi32: Add an inline helper to retrieve a DDB byte width.

This commit is contained in:
Alexandre Julliard 2011-07-25 15:24:12 +02:00
parent dcfe0c48ea
commit d33e0d2c86
4 changed files with 10 additions and 41 deletions

View File

@ -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)

View File

@ -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 */

View File

@ -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;

View File

@ -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 */