return TRUE;
}
-static
-void
-SURFACE_vSetDefaultPalette(
- PSURFACE psurfBmp)
-{
- ULONG cBitsPixel = BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat);
-
- /* Find a suitable palette for this bitmap
- * Increment internal objects share count
- * so we can call PALETTE_ShareUnlockPalette
- * or GDIOBJ_IncrementShareCount safely */
- switch(cBitsPixel)
- {
- case 1:
- psurfBmp->ppal = &gpalMono;
- GDIOBJ_IncrementShareCount(&gpalMono.BaseObject);
- break;
- case 4:
- case 8:
- psurfBmp->ppal = PALETTE_ShareLockPalette(StockObjects[DEFAULT_PALETTE]);
- break;
- case 15:
- psurfBmp->ppal = &gpalRGB555;
- GDIOBJ_IncrementShareCount(&gpalRGB555.BaseObject);
- break;
- case 16:
- psurfBmp->ppal = &gpalRGB565;
- GDIOBJ_IncrementShareCount(&gpalRGB565.BaseObject);
- break;
- case 24:
- case 32:
- psurfBmp->ppal = &gpalRGB;
- GDIOBJ_IncrementShareCount((POBJ)&gpalRGB);
- break;
- default:
- DPRINT1("Could not determine palette for bit depth %u.\n", cBitsPixel);
- break;
- }
-}
PSURFACE
NTAPI
{
PSURFACE psurf;
SURFOBJ *pso;
-
+
+ /* Verify format */
+ if (iFormat < BMF_1BPP || iFormat > BMF_PNG)
+ {
+ DPRINT1("Invalid bitmap format: %ld\n", iFormat);
+ return NULL;
+ }
+
/* Allocate a SURFACE object */
psurf = (PSURFACE)GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_BITMAP);
pso->iType = iType;
pso->iUniq = InterlockedIncrement((PLONG)&giUniqueSurface);
- SURFACE_vSetDefaultPalette(psurf);
+ /* Assign a default palette amd increment its reference count */
+ psurf->ppal = appalSurfaceDefault[iFormat];
+ GDIOBJ_IncrementShareCount(&psurf->ppal->BaseObject);
}
return psurf;
cBitsPixel = gajBitsPerFormat[pso->iBitmapFormat];
/* Is a width in bytes given? */
- if (ulWidth)
- {
- /* Align the width (Windows compatibility) */
- //ulWidth = ((((ulWidth << 3) / cBitsPixel) * cBitsPixel + 31) & ~31) >> 3;
- }
- else
+ if (!ulWidth)
{
/* Calculate width from the bitmap width in pixels */
- ulWidth = ((pso->sizlBitmap.cx * cBitsPixel + 31) & ~31) >> 3;
+ ulWidth = DIB_GetDIBWidthBytes(psurf->SurfObj.sizlBitmap.cx, cBitsPixel);
}
+ else
+ {
+ /* Align the width (windows compatibility, drivers expect that) */
+ ulWidth = ((((ulWidth << 3) / cBitsPixel) * cBitsPixel + 31) & ~31) >> 3;
+ }
+
/* Calculate the bitmap size in bytes */
pso->cjBits = ulWidth * pso->sizlBitmap.cy;
(fjBitmap & BMF_NOZEROINIT) ?
0 : FL_ZERO_MEMORY,
pso->cjBits, TAG_DIB);
-
+
/* Free the section already, but keep the mapping */
if (pvBits) EngFreeSectionMem(pvSection, NULL);
}
}
}
-HBITMAP
-FASTCALL
-IntCreateBitmap(
- IN SIZEL Size,
- IN LONG Width,
- IN ULONG Format,
- IN ULONG Flags,
- IN PVOID Bits)
-{
- HBITMAP hbmp;
- SURFOBJ *pso;
- PSURFACE psurf;
- PVOID UncompressedBits;
- ULONG UncompressedFormat;
-
- if (Format == 0)
- return 0;
-
- /* Allocate a surface */
- psurf = SURFACE_AllocSurface(STYPE_BITMAP, Size.cx, Size.cy, Format);
- if (!psurf)
- {
- DPRINT1("SURFACE_AllocSurface failed.\n");
- return NULL;
- }
-
- /* Get the handle for the bitmap and the surfobj */
- hbmp = (HBITMAP)psurf->SurfObj.hsurf;
- pso = &psurf->SurfObj;
-
- if (Format == BMF_4RLE)
- {
- UncompressedFormat = BMF_4BPP;
- UncompressedBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
- Decompress4bpp(Size, (BYTE *)Bits, (BYTE *)UncompressedBits, pso->lDelta);
- Flags |= BMF_RLE_HACK;
- }
- else if (Format == BMF_8RLE)
- {
- UncompressedFormat = BMF_8BPP;
- UncompressedBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
- Decompress8bpp(Size, (BYTE *)Bits, (BYTE *)UncompressedBits, pso->lDelta);
- Flags |= BMF_RLE_HACK;
- }
- else
- {
- UncompressedBits = Bits;
- UncompressedFormat = Format;
- }
-
- /* Set the bitmap bits */
- if (!SURFACE_bSetBitmapBits(psurf, Flags, Width, UncompressedBits))
- {
- /* Bail out if that failed */
- DPRINT1("SURFACE_bSetBitmapBits failed.\n");
- SURFACE_FreeSurfaceByHandle(hbmp);
- return NULL;
- }
-
- /* Unlock the surface and return */
- SURFACE_UnlockSurface(psurf);
- return hbmp;
-}
-
/* EOF */