Commit 505a6b9c authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

gdi32: Implement CreateBitmapIndirect on top of CreateBitmap.

Instead of the other way around. Signed-off-by: 's avatarJacek Caban <jacek@codeweavers.com> Signed-off-by: 's avatarHuw Davies <huw@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent f5c117fb
...@@ -44,38 +44,6 @@ static const struct gdi_obj_funcs bitmap_funcs = ...@@ -44,38 +44,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.@] * CreateCompatibleBitmap [GDI32.@]
* *
* Creates a bitmap compatible with the DC. * Creates a bitmap compatible with the DC.
...@@ -123,81 +91,57 @@ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height) ...@@ -123,81 +91,57 @@ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
/****************************************************************************** /******************************************************************************
* CreateBitmapIndirect [GDI32.@] * CreateBitmap [GDI32.@]
* *
* Creates a bitmap with the specified info. * 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; BITMAPOBJ *bmpobj;
HBITMAP hbitmap; HBITMAP hbitmap;
INT dib_stride; INT dib_stride;
SIZE_T size; SIZE_T size;
if (!bmp || bmp->bmType) if (width > 0x7ffffff || height > 0x7ffffff)
{
SetLastError( ERROR_INVALID_PARAMETER );
return NULL;
}
if (bmp->bmWidth > 0x7ffffff || bmp->bmHeight > 0x7ffffff)
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return 0; return 0;
} }
bm = *bmp; if (!width || !height)
if (!bm.bmWidth || !bm.bmHeight)
{
return GetStockObject( DEFAULT_BITMAP ); 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 ); SetLastError( ERROR_INVALID_PARAMETER );
return NULL; return NULL;
} }
/* Windows only uses 1, 4, 8, 16, 24 and 32 bpp */ /* Windows only uses 1, 4, 8, 16, 24 and 32 bpp */
if(bm.bmBitsPixel == 1) bm.bmBitsPixel = 1; if(bpp == 1) bpp = 1;
else if(bm.bmBitsPixel <= 4) bm.bmBitsPixel = 4; else if(bpp <= 4) bpp = 4;
else if(bm.bmBitsPixel <= 8) bm.bmBitsPixel = 8; else if(bpp <= 8) bpp = 8;
else if(bm.bmBitsPixel <= 16) bm.bmBitsPixel = 16; else if(bpp <= 16) bpp = 16;
else if(bm.bmBitsPixel <= 24) bm.bmBitsPixel = 24; else if(bpp <= 24) bpp = 24;
else if(bm.bmBitsPixel <= 32) bm.bmBitsPixel = 32; else if(bpp <= 32) bpp = 32;
else { else
WARN("Invalid bmBitsPixel %d, returning ERROR_INVALID_PARAMETER\n", bm.bmBitsPixel); {
WARN("Invalid bmBitsPixel %d, returning ERROR_INVALID_PARAMETER\n", bpp);
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return NULL; return NULL;
} }
/* Windows ignores the provided bm.bmWidthBytes */ dib_stride = get_dib_stride( width, bpp );
bm.bmWidthBytes = get_bitmap_stride( bm.bmWidth, bm.bmBitsPixel ); size = dib_stride * height;
dib_stride = get_dib_stride( bm.bmWidth, bm.bmBitsPixel );
size = dib_stride * bm.bmHeight;
/* Check for overflow (dib_stride itself must be ok because of the constraint on bm.bmWidth above). */ /* 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 ); SetLastError( ERROR_INVALID_PARAMETER );
return 0; return 0;
...@@ -210,8 +154,13 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp ) ...@@ -210,8 +154,13 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp )
return 0; return 0;
} }
bmpobj->dib.dsBm = bm; bmpobj->dib.dsBm.bmType = 0;
bmpobj->dib.dsBm.bmBits = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ); 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) if (!bmpobj->dib.dsBm.bmBits)
{ {
HeapFree( GetProcessHeap(), 0, bmpobj ); HeapFree( GetProcessHeap(), 0, bmpobj );
...@@ -226,12 +175,10 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp ) ...@@ -226,12 +175,10 @@ HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp )
return 0; return 0;
} }
if (bm.bmBits) if (bits)
SetBitmapBits( hbitmap, bm.bmHeight * bm.bmWidthBytes, bm.bmBits ); SetBitmapBits( hbitmap, height * bmpobj->dib.dsBm.bmWidthBytes, bits );
TRACE("%dx%d, bpp %d planes %d: returning %p\n", bm.bmWidth, bm.bmHeight,
bm.bmBitsPixel, bm.bmPlanes, hbitmap);
TRACE("%dx%d, bpp %d planes %d: returning %p\n", width, height, bpp, planes, hbitmap);
return hbitmap; return hbitmap;
} }
......
...@@ -186,3 +186,18 @@ HPEN WINAPI CreatePen( INT style, INT width, COLORREF color ) ...@@ -186,3 +186,18 @@ HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
if (style < 0 || style > PS_INSIDEFRAME) style = PS_SOLID; if (style < 0 || style > PS_INSIDEFRAME) style = PS_SOLID;
return NtGdiCreatePen( style, width, color, NULL ); 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 );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment