Module: wine Branch: master Commit: 505a6b9cffa5e7081bce4326c15f4f960601760f URL: https://source.winehq.org/git/wine.git/?a=commit;h=505a6b9cffa5e7081bce4326c...
Author: Jacek Caban jacek@codeweavers.com Date: Mon Jul 5 13:40:45 2021 +0200
gdi32: Implement CreateBitmapIndirect on top of CreateBitmap.
Instead of the other way around.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Huw Davies huw@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/gdi32/bitmap.c | 121 +++++++++++++++------------------------------------ dlls/gdi32/objects.c | 15 +++++++ 2 files changed, 49 insertions(+), 87 deletions(-)
diff --git a/dlls/gdi32/bitmap.c b/dlls/gdi32/bitmap.c index aaad76dce36..cebe2dea644 100644 --- a/dlls/gdi32/bitmap.c +++ b/dlls/gdi32/bitmap.c @@ -43,38 +43,6 @@ static const struct gdi_obj_funcs bitmap_funcs = };
-/****************************************************************************** - * CreateBitmap [GDI32.@] - * - * Creates a bitmap with the specified info. - * - * PARAMS - * width [I] bitmap width - * height [I] bitmap height - * planes [I] Number of color planes - * bpp [I] Number of bits to identify a color - * bits [I] Pointer to array containing color data - * - * RETURNS - * Success: Handle to bitmap - * Failure: 0 - */ -HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes, - UINT bpp, LPCVOID bits ) -{ - BITMAP bm; - - bm.bmType = 0; - bm.bmWidth = width; - bm.bmHeight = height; - bm.bmWidthBytes = get_bitmap_stride( width, bpp ); - bm.bmPlanes = planes; - bm.bmBitsPixel = bpp; - bm.bmBits = (LPVOID)bits; - - return CreateBitmapIndirect( &bm ); -} - /****************************************************************************** * CreateCompatibleBitmap [GDI32.@] * @@ -123,81 +91,57 @@ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
/****************************************************************************** - * CreateBitmapIndirect [GDI32.@] + * CreateBitmap [GDI32.@] * * Creates a bitmap with the specified info. - * - * PARAMS - * bmp [I] Pointer to the bitmap info describing the bitmap - * - * RETURNS - * Success: Handle to bitmap - * Failure: NULL. Use GetLastError() to determine the cause. - * - * NOTES - * If a width or height of 0 is given, a 1x1 monochrome bitmap is returned. */ -HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp ) +HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes, + UINT bpp, const void *bits ) { - BITMAP bm; BITMAPOBJ *bmpobj; HBITMAP hbitmap; INT dib_stride; SIZE_T size;
- if (!bmp || bmp->bmType) - { - SetLastError( ERROR_INVALID_PARAMETER ); - return NULL; - } - - if (bmp->bmWidth > 0x7ffffff || bmp->bmHeight > 0x7ffffff) + if (width > 0x7ffffff || height > 0x7ffffff) { SetLastError( ERROR_INVALID_PARAMETER ); return 0; }
- bm = *bmp; - - if (!bm.bmWidth || !bm.bmHeight) - { + if (!width || !height) return GetStockObject( DEFAULT_BITMAP ); - } - else - { - if (bm.bmHeight < 0) - bm.bmHeight = -bm.bmHeight; - if (bm.bmWidth < 0) - bm.bmWidth = -bm.bmWidth; - }
- if (bm.bmPlanes != 1) + if (height < 0) + height = -height; + if (width < 0) + width = -width; + + if (planes != 1) { - FIXME("planes = %d\n", bm.bmPlanes); + FIXME("planes = %d\n", planes); SetLastError( ERROR_INVALID_PARAMETER ); return NULL; }
/* Windows only uses 1, 4, 8, 16, 24 and 32 bpp */ - if(bm.bmBitsPixel == 1) bm.bmBitsPixel = 1; - else if(bm.bmBitsPixel <= 4) bm.bmBitsPixel = 4; - else if(bm.bmBitsPixel <= 8) bm.bmBitsPixel = 8; - else if(bm.bmBitsPixel <= 16) bm.bmBitsPixel = 16; - else if(bm.bmBitsPixel <= 24) bm.bmBitsPixel = 24; - else if(bm.bmBitsPixel <= 32) bm.bmBitsPixel = 32; - else { - WARN("Invalid bmBitsPixel %d, returning ERROR_INVALID_PARAMETER\n", bm.bmBitsPixel); + if(bpp == 1) bpp = 1; + else if(bpp <= 4) bpp = 4; + else if(bpp <= 8) bpp = 8; + else if(bpp <= 16) bpp = 16; + else if(bpp <= 24) bpp = 24; + else if(bpp <= 32) bpp = 32; + else + { + WARN("Invalid bmBitsPixel %d, returning ERROR_INVALID_PARAMETER\n", bpp); SetLastError(ERROR_INVALID_PARAMETER); return NULL; }
- /* Windows ignores the provided bm.bmWidthBytes */ - bm.bmWidthBytes = get_bitmap_stride( bm.bmWidth, bm.bmBitsPixel ); - - dib_stride = get_dib_stride( bm.bmWidth, bm.bmBitsPixel ); - size = dib_stride * bm.bmHeight; + dib_stride = get_dib_stride( width, bpp ); + size = dib_stride * height; /* Check for overflow (dib_stride itself must be ok because of the constraint on bm.bmWidth above). */ - if (dib_stride != size / bm.bmHeight) + if (dib_stride != size / height) { SetLastError( ERROR_INVALID_PARAMETER ); return 0; @@ -210,8 +154,13 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp ) return 0; }
- bmpobj->dib.dsBm = bm; - bmpobj->dib.dsBm.bmBits = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ); + bmpobj->dib.dsBm.bmType = 0; + bmpobj->dib.dsBm.bmWidth = width; + bmpobj->dib.dsBm.bmHeight = height; + bmpobj->dib.dsBm.bmWidthBytes = get_bitmap_stride( width, bpp ); + bmpobj->dib.dsBm.bmPlanes = planes; + bmpobj->dib.dsBm.bmBitsPixel = bpp; + bmpobj->dib.dsBm.bmBits = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ); if (!bmpobj->dib.dsBm.bmBits) { HeapFree( GetProcessHeap(), 0, bmpobj ); @@ -226,12 +175,10 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp ) return 0; }
- if (bm.bmBits) - SetBitmapBits( hbitmap, bm.bmHeight * bm.bmWidthBytes, bm.bmBits ); - - TRACE("%dx%d, bpp %d planes %d: returning %p\n", bm.bmWidth, bm.bmHeight, - bm.bmBitsPixel, bm.bmPlanes, hbitmap); + if (bits) + SetBitmapBits( hbitmap, height * bmpobj->dib.dsBm.bmWidthBytes, bits );
+ TRACE("%dx%d, bpp %d planes %d: returning %p\n", width, height, bpp, planes, hbitmap); return hbitmap; }
diff --git a/dlls/gdi32/objects.c b/dlls/gdi32/objects.c index 0e8453f4af2..1567a02b128 100644 --- a/dlls/gdi32/objects.c +++ b/dlls/gdi32/objects.c @@ -186,3 +186,18 @@ HPEN WINAPI CreatePen( INT style, INT width, COLORREF color ) if (style < 0 || style > PS_INSIDEFRAME) style = PS_SOLID; return NtGdiCreatePen( style, width, color, NULL ); } + +/*********************************************************************** + * CreateBitmapIndirect (GDI32.@) + */ +HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp ) +{ + if (!bmp || bmp->bmType) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return NULL; + } + + return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes, + bmp->bmBitsPixel, bmp->bmBits ); +}