Commit cf85fb14 authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Add a helper function that implements GetImage on a bitmap.

parent b6f25e52
......@@ -265,7 +265,7 @@ LONG WINAPI GetBitmapBits(
src.width = src.visrect.right - src.visrect.left;
src.height = src.visrect.bottom - src.visrect.top;
if (!bmp->funcs->pGetImage( NULL, hbitmap, info, &src_bits, &src ))
if (!get_image_from_bitmap( bmp, info, &src_bits, &src ))
{
const char *src_ptr = src_bits.ptr;
int src_stride = get_dib_stride( info->bmiHeader.biWidth, info->bmiHeader.biBitCount );
......
......@@ -69,7 +69,7 @@ static BOOL copy_bitmap( struct brush_pattern *brush, HBITMAP bitmap )
src.visrect.top = src.y = 0;
src.visrect.right = src.width = bmp->dib.dsBm.bmWidth;
src.visrect.bottom = src.height = bmp->dib.dsBm.bmHeight;
if (bmp->funcs->pGetImage( NULL, bitmap, info, &bits, &src )) goto done;
if (get_image_from_bitmap( bmp, info, &bits, &src )) goto done;
brush->bits = bits;
if (!bits.free)
......
......@@ -1334,7 +1334,7 @@ INT WINAPI GetDIBits(
lines = src.height;
}
err = bmp->funcs->pGetImage( NULL, hbitmap, src_info, bits ? &src_bits : NULL, bits ? &src : NULL );
err = get_image_from_bitmap( bmp, src_info, bits ? &src_bits : NULL, bits ? &src : NULL );
if (err) goto done;
......
......@@ -808,46 +808,19 @@ static void set_color_info( const dib_info *dib, BITMAPINFO *info )
}
}
/***********************************************************************
* dibdrv_GetImage
*/
DWORD dibdrv_GetImage( PHYSDEV dev, HBITMAP hbitmap, BITMAPINFO *info,
struct gdi_image_bits *bits, struct bitblt_coords *src )
static DWORD get_image_dib_info( dib_info *dib, BITMAPINFO *info,
struct gdi_image_bits *bits, struct bitblt_coords *src )
{
DWORD ret = ERROR_SUCCESS;
dib_info *dib = NULL, stand_alone;
TRACE( "%p %p %p\n", dev, hbitmap, info );
info->bmiHeader.biSize = sizeof(info->bmiHeader);
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biCompression = BI_RGB;
info->bmiHeader.biXPelsPerMeter = 0;
info->bmiHeader.biYPelsPerMeter = 0;
info->bmiHeader.biClrImportant = 0;
if (hbitmap)
{
BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, OBJ_BITMAP );
if (!bmp) return ERROR_INVALID_HANDLE;
if (!init_dib_info_from_bitmapobj( &stand_alone, bmp ))
{
ret = ERROR_OUTOFMEMORY;
goto done;
}
dib = &stand_alone;
}
else
{
dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
dib = &pdev->dib;
}
info->bmiHeader.biWidth = dib->width;
info->bmiHeader.biHeight = dib->rect.bottom - dib->rect.top;
info->bmiHeader.biBitCount = dib->bit_count;
info->bmiHeader.biSizeImage = info->bmiHeader.biHeight * abs( dib->stride );
info->bmiHeader.biWidth = dib->width;
info->bmiHeader.biHeight = dib->rect.bottom - dib->rect.top;
info->bmiHeader.biBitCount = dib->bit_count;
info->bmiHeader.biSizeImage = info->bmiHeader.biHeight * abs( dib->stride );
if (dib->stride > 0) info->bmiHeader.biHeight = -info->bmiHeader.biHeight;
set_color_info( dib, info );
......@@ -863,10 +836,39 @@ DWORD dibdrv_GetImage( PHYSDEV dev, HBITMAP hbitmap, BITMAPINFO *info,
src->x += dib->rect.left;
offset_rect( &src->visrect, dib->rect.left, 0 );
}
return ERROR_SUCCESS;
}
done:
if (hbitmap) GDI_ReleaseObj( hbitmap );
return ret;
DWORD get_image_from_bitmap( BITMAPOBJ *bmp, BITMAPINFO *info,
struct gdi_image_bits *bits, struct bitblt_coords *src )
{
dib_info dib;
if (!init_dib_info_from_bitmapobj( &dib, bmp )) return ERROR_OUTOFMEMORY;
return get_image_dib_info( &dib, info, bits, src );
}
/***********************************************************************
* dibdrv_GetImage
*/
DWORD dibdrv_GetImage( PHYSDEV dev, HBITMAP hbitmap, BITMAPINFO *info,
struct gdi_image_bits *bits, struct bitblt_coords *src )
{
dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
TRACE( "%p %p %p\n", dev, hbitmap, info );
if (hbitmap)
{
DWORD ret;
BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, OBJ_BITMAP );
if (!bmp) return ERROR_INVALID_HANDLE;
ret = get_image_from_bitmap( bmp, info, bits, src );
GDI_ReleaseObj( hbitmap );
return ret;
}
return get_image_dib_info( &pdev->dib, info, bits, src );
}
static BOOL matching_color_info( const dib_info *dib, const BITMAPINFO *info )
......
......@@ -269,6 +269,8 @@ extern COLORREF get_pixel_bitmapinfo( const BITMAPINFO *info, void *bits, struct
extern BOOL render_aa_text_bitmapinfo( HDC hdc, BITMAPINFO *info, struct gdi_image_bits *bits,
struct bitblt_coords *src, INT x, INT y, UINT flags,
UINT aa_flags, LPCWSTR str, UINT count, const INT *dx ) DECLSPEC_HIDDEN;
extern DWORD get_image_from_bitmap( BITMAPOBJ *bmp, BITMAPINFO *info,
struct gdi_image_bits *bits, struct bitblt_coords *src ) DECLSPEC_HIDDEN;
/* driver.c */
extern const struct gdi_dc_funcs null_driver DECLSPEC_HIDDEN;
......
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