- 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
This commit is contained in:
Dmitry Chapyshev 2016-09-02 15:40:32 +00:00
parent 9598f87c7c
commit dff1c73022

View file

@ -403,13 +403,11 @@ CreateDIBitmap(
const BITMAPINFO *Data, const BITMAPINFO *Data,
UINT ColorUse) UINT ColorUse)
{ {
LONG width, height, compr, dibsize; LONG Width, Height, Compression, DibSize;
WORD planes, bpp; WORD Planes, BitsPerPixel;
// PDC_ATTR pDc_Attr; // PDC_ATTR pDc_Attr;
UINT InfoSize = 0;
UINT cjBmpScanSize = 0; UINT cjBmpScanSize = 0;
HBITMAP hBmp = NULL; HBITMAP hBitmap = NULL;
NTSTATUS Status = STATUS_SUCCESS;
PBITMAPINFO pbmiConverted; PBITMAPINFO pbmiConverted;
UINT cjInfoSize; UINT cjInfoSize;
@ -419,6 +417,22 @@ CreateDIBitmap(
/* Check for CBM_CREATDIB */ /* Check for CBM_CREATDIB */
if (Init & 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. */ /* CBM_CREATDIB needs Data. */
if (pbmiConverted == NULL) if (pbmiConverted == NULL)
{ {
@ -437,6 +451,23 @@ CreateDIBitmap(
/* Use the header from the data */ /* Use the header from the data */
Header = &Data->bmiHeader; Header = &Data->bmiHeader;
} }
else
{
if (Init & CBM_INIT)
{
if (Bits != NULL)
{
if (cjInfoSize == 0)
{
goto Exit;
}
}
else
{
Init &= ~CBM_INIT;
}
}
}
/* Header is required */ /* Header is required */
if (!Header) if (!Header)
@ -447,7 +478,7 @@ CreateDIBitmap(
} }
/* Get the bitmap format and dimensions */ /* 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"); DPRINT1("DIB_GetBitmapInfo failed!\n");
GdiSetLastError(ERROR_INVALID_PARAMETER); GdiSetLastError(ERROR_INVALID_PARAMETER);
@ -455,16 +486,16 @@ CreateDIBitmap(
} }
/* Check if the Compr is incompatible */ /* 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; goto Exit;
} }
/* Only DIB_RGB_COLORS (0), DIB_PAL_COLORS (1) and 2 are valid. */ /* Only DIB_RGB_COLORS (0), DIB_PAL_COLORS (1) and 2 are valid. */
if (ColorUse > DIB_PAL_COLORS + 1) if (ColorUse > DIB_PAL_COLORS + 1)
{ {
DPRINT1("invalid compr: %lu!\n", compr); DPRINT1("Invalid compression: %lu!\n", Compression);
GdiSetLastError(ERROR_INVALID_PARAMETER); GdiSetLastError(ERROR_INVALID_PARAMETER);
goto Exit; goto Exit;
} }
@ -478,60 +509,49 @@ CreateDIBitmap(
} }
/* Negative width is not allowed */ /* 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; goto Exit;
} }
/* Top-down DIBs have a negative height. */ /* Top-down DIBs have a negative height. */
height = abs(height); Height = abs(Height);
// For Icm support. // For Icm support.
// GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID)&pDc_Attr)) // 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 hBitmap = GetStockObject(DEFAULT_BITMAP);
{
cjBmpScanSize = GdiGetBitmapBitsSize(pbmiConverted);
CalculateColorTableSize(&pbmiConverted->bmiHeader, &ColorUse, &InfoSize);
InfoSize += pbmiConverted->bmiHeader.biSize;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Status = _SEH2_GetExceptionCode();
}
_SEH2_END
} }
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 else
{ {
hBmp = NtGdiCreateDIBitmapInternal(hDC, width, height, Init, (LPBYTE)Bits, hBitmap = NtGdiCreateDIBitmapInternal(hDC,
(LPBITMAPINFO)pbmiConverted, ColorUse, InfoSize, cjBmpScanSize, 0, 0); Width,
Height,
Init,
(LPBYTE)Bits,
(LPBITMAPINFO)pbmiConverted,
ColorUse,
cjInfoSize,
cjBmpScanSize,
0, 0);
} }
Exit: Exit:
/* Cleanup converted BITMAPINFO */ /* Cleanup converted BITMAPINFO */
if ((pbmiConverted != NULL) && (pbmiConverted != Data)) if ((pbmiConverted != NULL) && (pbmiConverted != Data))
{ {
RtlFreeHeap(RtlGetProcessHeap(), 0, pbmiConverted); RtlFreeHeap(RtlGetProcessHeap(), 0, pbmiConverted);
} }
return hBmp; return hBitmap;
} }
/* /*