From c5f484597f4660b5b71c3a84122d9baf69236127 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Fri, 5 Aug 2011 13:20:32 +0100 Subject: [PATCH] gdi32: Simplify dibdrv_GetImage by merging the stand-alone and selected bitmap cases. --- dlls/gdi32/dibdrv/dc.c | 74 ++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/dlls/gdi32/dibdrv/dc.c b/dlls/gdi32/dibdrv/dc.c index b0fe47f4b04..6ffb5540d01 100644 --- a/dlls/gdi32/dibdrv/dc.c +++ b/dlls/gdi32/dibdrv/dc.c @@ -380,6 +380,9 @@ static void set_color_info( const dib_info *dib, BITMAPINFO *info ) static DWORD dibdrv_GetImage( PHYSDEV dev, HBITMAP hbitmap, BITMAPINFO *info, struct gdi_image_bits *bits, struct bitblt_coords *src ) { + DWORD ret = ERROR_SUCCESS; + dib_info *dib, stand_alone; + TRACE( "%p %p %p\n", dev, hbitmap, info ); info->bmiHeader.biSize = sizeof(info->bmiHeader); @@ -397,64 +400,39 @@ static DWORD dibdrv_GetImage( PHYSDEV dev, HBITMAP hbitmap, BITMAPINFO *info, if (!bmp) return ERROR_INVALID_HANDLE; assert(bmp->dib); - info->bmiHeader.biWidth = bmp->dib->dsBmih.biWidth; - info->bmiHeader.biHeight = bmp->dib->dsBmih.biHeight; - info->bmiHeader.biBitCount = bmp->dib->dsBmih.biBitCount; - info->bmiHeader.biSizeImage = get_dib_image_size( (BITMAPINFO *)&bmp->dib->dsBmih ); - - switch (info->bmiHeader.biBitCount) - { - case 1: - case 4: - case 8: - if (bmp->color_table) - { - info->bmiHeader.biClrUsed = min( bmp->nb_colors, 1 << info->bmiHeader.biBitCount ); - memcpy( info->bmiColors, bmp->color_table, info->bmiHeader.biClrUsed * sizeof(RGBQUAD) ); - } - break; - case 16: - info->bmiHeader.biCompression = BI_BITFIELDS; - memcpy( info->bmiColors, bmp->dib->dsBitfields, sizeof(bmp->dib->dsBitfields) ); - break; - case 32: - if (bmp->dib->dsBmih.biCompression == BI_BITFIELDS && - memcmp( bmp->dib->dsBitfields, bit_fields_888, sizeof(bmp->dib->dsBitfields) )) - { - info->bmiHeader.biCompression = BI_BITFIELDS; - memcpy( info->bmiColors, bmp->dib->dsBitfields, sizeof(bmp->dib->dsBitfields) ); - } - break; - } - if (bits) + if (!init_dib_info( &stand_alone, &bmp->dib->dsBmih, bmp->dib->dsBitfields, + bmp->color_table, bmp->nb_colors, bmp->dib->dsBm.bmBits, 0 )) { - bits->ptr = bmp->dib->dsBm.bmBits; - bits->is_copy = FALSE; - bits->free = NULL; + ret = ERROR_BAD_FORMAT; + goto done; } - GDI_ReleaseObj( hbitmap ); + dib = &stand_alone; } else { dibdrv_physdev *pdev = get_dibdrv_pdev(dev); + dib = &pdev->dib; + } - info->bmiHeader.biWidth = pdev->dib.width; - info->bmiHeader.biHeight = pdev->dib.stride > 0 ? -pdev->dib.height : pdev->dib.height; - info->bmiHeader.biBitCount = pdev->dib.bit_count; - info->bmiHeader.biSizeImage = pdev->dib.height * abs(pdev->dib.stride); + info->bmiHeader.biWidth = dib->width; + info->bmiHeader.biHeight = dib->stride > 0 ? -dib->height : dib->height; + info->bmiHeader.biBitCount = dib->bit_count; + info->bmiHeader.biSizeImage = dib->height * abs( dib->stride ); - set_color_info( &pdev->dib, info ); + set_color_info( dib, info ); - if (bits) - { - bits->ptr = pdev->dib.bits; - if (pdev->dib.stride < 0) - bits->ptr = (char *)bits->ptr + (pdev->dib.height - 1) * pdev->dib.stride; - bits->is_copy = FALSE; - bits->free = NULL; - } + if (bits) + { + bits->ptr = dib->bits; + if (dib->stride < 0) + bits->ptr = (char *)bits->ptr + (dib->height - 1) * dib->stride; + bits->is_copy = FALSE; + bits->free = NULL; } - return ERROR_SUCCESS; + +done: + if (hbitmap) GDI_ReleaseObj( hbitmap ); + return ret; } static BOOL matching_color_info( const dib_info *dib, const BITMAPINFO *info ) -- 2.11.4.GIT