From dff1c73022991d34c019f9f30e31d41961222dc7 Mon Sep 17 00:00:00 2001 From: Dmitry Chapyshev Date: Fri, 2 Sep 2016 15:40:32 +0000 Subject: [PATCH] [GDI32] - ConvertBitmapInfo returns value of the cjInfoSize variable. We should not ignore this value. Checks are added - The call of CalculateColorTableSize is not necessary, its value was already returned by ConvertBitmapInfo. * Fixes 9 tests for gdi32_apitest CreateDIBitmap svn path=/trunk/; revision=72534 --- reactos/win32ss/gdi/gdi32/objects/bitmap.c | 102 ++++++++++++--------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/reactos/win32ss/gdi/gdi32/objects/bitmap.c b/reactos/win32ss/gdi/gdi32/objects/bitmap.c index a2d6c2b20f4..1bbe3924a0f 100644 --- a/reactos/win32ss/gdi/gdi32/objects/bitmap.c +++ b/reactos/win32ss/gdi/gdi32/objects/bitmap.c @@ -403,13 +403,11 @@ CreateDIBitmap( const BITMAPINFO *Data, UINT ColorUse) { - LONG width, height, compr, dibsize; - WORD planes, bpp; + LONG Width, Height, Compression, DibSize; + WORD Planes, BitsPerPixel; // PDC_ATTR pDc_Attr; - UINT InfoSize = 0; UINT cjBmpScanSize = 0; - HBITMAP hBmp = NULL; - NTSTATUS Status = STATUS_SUCCESS; + HBITMAP hBitmap = NULL; PBITMAPINFO pbmiConverted; UINT cjInfoSize; @@ -419,6 +417,22 @@ CreateDIBitmap( /* Check for CBM_CREATDIB */ if (Init & CBM_CREATDIB) { + if (cjInfoSize == 0) + { + goto Exit; + } + else if (Init & CBM_INIT) + { + if (Bits == NULL) + { + goto Exit; + } + } + else + { + Bits = NULL; + } + /* CBM_CREATDIB needs Data. */ if (pbmiConverted == NULL) { @@ -437,6 +451,23 @@ CreateDIBitmap( /* Use the header from the data */ Header = &Data->bmiHeader; } + else + { + if (Init & CBM_INIT) + { + if (Bits != NULL) + { + if (cjInfoSize == 0) + { + goto Exit; + } + } + else + { + Init &= ~CBM_INIT; + } + } + } /* Header is required */ if (!Header) @@ -447,7 +478,7 @@ CreateDIBitmap( } /* Get the bitmap format and dimensions */ - if (DIB_GetBitmapInfo(Header, &width, &height, &planes, &bpp, &compr, &dibsize) == -1) + if (DIB_GetBitmapInfo(Header, &Width, &Height, &Planes, &BitsPerPixel, &Compression, &DibSize) == -1) { DPRINT1("DIB_GetBitmapInfo failed!\n"); GdiSetLastError(ERROR_INVALID_PARAMETER); @@ -455,16 +486,16 @@ CreateDIBitmap( } /* Check if the Compr is incompatible */ - if ((compr == BI_JPEG) || (compr == BI_PNG) || (compr == BI_BITFIELDS)) + if ((Compression == BI_JPEG) || (Compression == BI_PNG) || (Compression == BI_BITFIELDS)) { - DPRINT1("invalid compr: %lu!\n", compr); + DPRINT1("Invalid compression: %lu!\n", Compression); goto Exit; } /* Only DIB_RGB_COLORS (0), DIB_PAL_COLORS (1) and 2 are valid. */ if (ColorUse > DIB_PAL_COLORS + 1) { - DPRINT1("invalid compr: %lu!\n", compr); + DPRINT1("Invalid compression: %lu!\n", Compression); GdiSetLastError(ERROR_INVALID_PARAMETER); goto Exit; } @@ -478,60 +509,49 @@ CreateDIBitmap( } /* Negative width is not allowed */ - if (width < 0) + if (Width < 0) { - DPRINT1("Negative width: %li\n", width); + DPRINT1("Negative width: %li\n", Width); goto Exit; } /* Top-down DIBs have a negative height. */ - height = abs(height); + Height = abs(Height); // For Icm support. // GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID)&pDc_Attr)) - if (pbmiConverted) + cjBmpScanSize = GdiGetBitmapBitsSize(pbmiConverted); + + DPRINT("pBMI %p, Size bpp %u, dibsize %d, Conv %u, BSS %u\n", + Data, BitsPerPixel, DibSize, cjInfoSize, cjBmpScanSize); + + if (!Width || !Height) { - _SEH2_TRY - { - cjBmpScanSize = GdiGetBitmapBitsSize(pbmiConverted); - CalculateColorTableSize(&pbmiConverted->bmiHeader, &ColorUse, &InfoSize); - InfoSize += pbmiConverted->bmiHeader.biSize; - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - Status = _SEH2_GetExceptionCode(); - } - _SEH2_END + hBitmap = GetStockObject(DEFAULT_BITMAP); } - - if (!NT_SUCCESS(Status)) - { - DPRINT1("Got an exception!\n"); - GdiSetLastError(ERROR_INVALID_PARAMETER); - goto Exit; - } - - DPRINT("pBMI %p, Size bpp %u, dibsize %d, Conv %u, BSS %u\n", Data, bpp, dibsize, InfoSize, - cjBmpScanSize); - - if (!width || !height) - hBmp = GetStockObject(DEFAULT_BITMAP); else { - hBmp = NtGdiCreateDIBitmapInternal(hDC, width, height, Init, (LPBYTE)Bits, - (LPBITMAPINFO)pbmiConverted, ColorUse, InfoSize, cjBmpScanSize, 0, 0); + hBitmap = NtGdiCreateDIBitmapInternal(hDC, + Width, + Height, + Init, + (LPBYTE)Bits, + (LPBITMAPINFO)pbmiConverted, + ColorUse, + cjInfoSize, + cjBmpScanSize, + 0, 0); } Exit: - /* Cleanup converted BITMAPINFO */ if ((pbmiConverted != NULL) && (pbmiConverted != Data)) { RtlFreeHeap(RtlGetProcessHeap(), 0, pbmiConverted); } - return hBmp; + return hBitmap; } /*