[WIN32K]
[reactos.git] / subsystems / win32 / win32k / objects / bitmaps.c
index 17194c7..e604957 100644 (file)
@@ -69,11 +69,13 @@ UnsafeSetBitmapBits(
 
 HBITMAP
 APIENTRY
-GreCreateBitmap(
+GreCreateBitmapEx(
     IN INT nWidth,
     IN INT nHeight,
-    IN UINT cPlanes,
-    IN UINT cBitsPixel,
+    IN ULONG cjWidthBytes,
+    IN ULONG iFormat,
+    IN USHORT fjBitmap,
+    IN ULONG cjSizeImage,
     IN OPTIONAL PVOID pvBits)
 {
     PSURFACE psurf;
@@ -82,10 +84,6 @@ GreCreateBitmap(
     PVOID pvCompressedBits;
     SIZEL sizl;
     FLONG fl = 0;
-    ULONG iFormat;
-
-    /* Calculate bitmap format */
-    iFormat = BitmapFormat(cBitsPixel * cPlanes, BI_RGB);
 
     /* Verify format */
     if (iFormat < BMF_1BPP || iFormat > BMF_PNG) return NULL;
@@ -121,7 +119,7 @@ GreCreateBitmap(
     }
 
     /* Set the bitmap bits */
-    if (!SURFACE_bSetBitmapBits(psurf, fl, 0, pvBits))
+    if (!SURFACE_bSetBitmapBits(psurf, fjBitmap, cjWidthBytes, pvBits))
     {
         /* Bail out if that failed */
         DPRINT1("SURFACE_bSetBitmapBits failed.\n");
@@ -137,6 +135,25 @@ GreCreateBitmap(
     return hbmp;
 }
 
+HBITMAP
+APIENTRY
+GreCreateBitmap(
+    IN INT nWidth,
+    IN INT nHeight,
+    IN UINT cPlanes,
+    IN UINT cBitsPixel,
+    IN OPTIONAL PVOID pvBits)
+{
+    /* Call the extended function */
+    return GreCreateBitmapEx(nWidth,
+                             nHeight,
+                             0, /* auto width */
+                             BitmapFormat(cBitsPixel * cPlanes, BI_RGB),
+                             0, /* no bitmap flags */
+                             0, /* auto size */
+                             pvBits);
+}
+
 HBITMAP
 APIENTRY
 NtGdiCreateBitmap(
@@ -274,7 +291,7 @@ IntCreateCompatibleBitmap(
                     PSURFACE psurfBmp;
                     size.cx = abs(Width);
                     size.cy = abs(Height);
-            Bmp = GreCreateBitmap(abs(Width),
+                                       Bmp = GreCreateBitmap(abs(Width),
                                   abs(Height),
                                   1,
                                   dibs.dsBm.bmBitsPixel,
@@ -292,63 +309,51 @@ IntCreateCompatibleBitmap(
                 else
                 {
                     /* A DIB section is selected in the DC */
-                    BITMAPINFO *bi;
+                                       BYTE buf[sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD)] = {0};
                     PVOID Bits;
-
-                    /* Allocate memory for a BITMAPINFOHEADER structure and a
-                       color table. The maximum number of colors in a color table
-                       is 256 which corresponds to a bitmap with depth 8.
-                       Bitmaps with higher depths don't have color tables. */
-                    bi = ExAllocatePoolWithTag(PagedPool,
-                                               sizeof(BITMAPINFOHEADER) +
-                                                   256 * sizeof(RGBQUAD),
-                                               TAG_TEMP);
-
-                    if (bi)
+                                       BITMAPINFO* bi = (BITMAPINFO*)buf;
+
+                    bi->bmiHeader.biSize          = sizeof(bi->bmiHeader);
+                    bi->bmiHeader.biWidth         = Width;
+                    bi->bmiHeader.biHeight        = Height;
+                    bi->bmiHeader.biPlanes        = dibs.dsBmih.biPlanes;
+                    bi->bmiHeader.biBitCount      = dibs.dsBmih.biBitCount;
+                    bi->bmiHeader.biCompression   = dibs.dsBmih.biCompression;
+                    bi->bmiHeader.biSizeImage     = 0;
+                    bi->bmiHeader.biXPelsPerMeter = dibs.dsBmih.biXPelsPerMeter;
+                    bi->bmiHeader.biYPelsPerMeter = dibs.dsBmih.biYPelsPerMeter;
+                    bi->bmiHeader.biClrUsed       = dibs.dsBmih.biClrUsed;
+                    bi->bmiHeader.biClrImportant  = dibs.dsBmih.biClrImportant;
+
+                    if (bi->bmiHeader.biCompression == BI_BITFIELDS)
                     {
-                        bi->bmiHeader.biSize          = sizeof(bi->bmiHeader);
-                        bi->bmiHeader.biWidth         = Width;
-                        bi->bmiHeader.biHeight        = Height;
-                        bi->bmiHeader.biPlanes        = dibs.dsBmih.biPlanes;
-                        bi->bmiHeader.biBitCount      = dibs.dsBmih.biBitCount;
-                        bi->bmiHeader.biCompression   = dibs.dsBmih.biCompression;
-                        bi->bmiHeader.biSizeImage     = 0;
-                        bi->bmiHeader.biXPelsPerMeter = dibs.dsBmih.biXPelsPerMeter;
-                        bi->bmiHeader.biYPelsPerMeter = dibs.dsBmih.biYPelsPerMeter;
-                        bi->bmiHeader.biClrUsed       = dibs.dsBmih.biClrUsed;
-                        bi->bmiHeader.biClrImportant  = dibs.dsBmih.biClrImportant;
-
-                        if (bi->bmiHeader.biCompression == BI_BITFIELDS)
+                        /* Copy the color masks */
+                        RtlCopyMemory(bi->bmiColors, dibs.dsBitfields, 3*sizeof(RGBQUAD));
+                    }
+                    else if (bi->bmiHeader.biBitCount <= 8)
+                    {
+                        /* Copy the color table */
+                        UINT Index;
+                        PPALETTE PalGDI;
+
+                        if (!psurf->ppal)
                         {
-                            /* Copy the color masks */
-                            RtlCopyMemory(bi->bmiColors, dibs.dsBitfields, 3 * sizeof(DWORD));
+                            SetLastWin32Error(ERROR_INVALID_HANDLE);
+                            return 0;
                         }
-                        else if (bi->bmiHeader.biBitCount <= 8)
+
+                        PalGDI = PALETTE_LockPalette(psurf->ppal->BaseObject.hHmgr);
+
+                        for (Index = 0;
+                                Index < 256 && Index < PalGDI->NumColors;
+                                Index++)
                         {
-                            /* Copy the color table */
-                            UINT Index;
-                            PPALETTE PalGDI;
-
-                            if (!psurf->ppal)
-                            {
-                                ExFreePoolWithTag(bi, TAG_TEMP);
-                                SetLastWin32Error(ERROR_INVALID_HANDLE);
-                                return 0;
-                            }
-
-                            PalGDI = PALETTE_LockPalette(psurf->ppal->BaseObject.hHmgr);
-
-                            for (Index = 0;
-                                    Index < 256 && Index < PalGDI->NumColors;
-                                    Index++)
-                            {
-                                bi->bmiColors[Index].rgbRed   = PalGDI->IndexedColors[Index].peRed;
-                                bi->bmiColors[Index].rgbGreen = PalGDI->IndexedColors[Index].peGreen;
-                                bi->bmiColors[Index].rgbBlue  = PalGDI->IndexedColors[Index].peBlue;
-                                bi->bmiColors[Index].rgbReserved = 0;
-                            }
-                            PALETTE_UnlockPalette(PalGDI);
+                            bi->bmiColors[Index].rgbRed   = PalGDI->IndexedColors[Index].peRed;
+                            bi->bmiColors[Index].rgbGreen = PalGDI->IndexedColors[Index].peGreen;
+                            bi->bmiColors[Index].rgbBlue  = PalGDI->IndexedColors[Index].peBlue;
+                            bi->bmiColors[Index].rgbReserved = 0;
                         }
+                        PALETTE_UnlockPalette(PalGDI);
 
                         Bmp = DIB_CreateDIBSection(Dc,
                                                    bi,
@@ -357,8 +362,6 @@ IntCreateCompatibleBitmap(
                                                    NULL,
                                                    0,
                                                    0);
-
-                        ExFreePoolWithTag(bi, TAG_TEMP);
                         return Bmp;
                     }
                 }