Author: dchapyshev
Date: Fri Sep 2 15:40:32 2016
New Revision: 72534
URL:
http://svn.reactos.org/svn/reactos?rev=72534&view=rev
Log:
[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
Modified:
trunk/reactos/win32ss/gdi/gdi32/objects/bitmap.c
Modified: trunk/reactos/win32ss/gdi/gdi32/objects/bitmap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/gdi32/objects/…
==============================================================================
--- trunk/reactos/win32ss/gdi/gdi32/objects/bitmap.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/gdi32/objects/bitmap.c [iso-8859-1] Fri Sep 2 15:40:32
2016
@@ -403,13 +403,11 @@
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 @@
/* 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 @@
/* 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 @@
}
/* 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 @@
}
/* Check if the Compr is incompatible */
- if ((compr == BI_JPEG) || (compr == BI_PNG) || (compr == BI_BITFIELDS))
- {
- DPRINT1("invalid compr: %lu!\n", compr);
+ if ((Compression == BI_JPEG) || (Compression == BI_PNG) || (Compression ==
BI_BITFIELDS))
+ {
+ 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 @@
}
/* Negative width is not allowed */
- if (width < 0)
- {
- DPRINT1("Negative width: %li\n", width);
+ if (Width < 0)
+ {
+ 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)
- {
- _SEH2_TRY
- {
- 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);
+ cjBmpScanSize = GdiGetBitmapBitsSize(pbmiConverted);
+
+ DPRINT("pBMI %p, Size bpp %u, dibsize %d, Conv %u, BSS %u\n",
+ Data, BitsPerPixel, DibSize, cjInfoSize, cjBmpScanSize);
+
+ if (!Width || !Height)
+ {
+ hBitmap = 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;
}
/*