};
-ULONG FASTCALL BitmapFormat(WORD Bits, DWORD Compression)
+ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression)
{
- switch (Compression)
+ switch (iCompression)
{
case BI_RGB:
/* Fall through */
case BI_BITFIELDS:
- switch (Bits)
- {
- case 1:
- return BMF_1BPP;
- case 4:
- return BMF_4BPP;
- case 8:
- return BMF_8BPP;
- case 16:
- return BMF_16BPP;
- case 24:
- return BMF_24BPP;
- case 32:
- return BMF_32BPP;
- }
+ if (cBits <= 1) return BMF_1BPP;
+ if (cBits <= 4) return BMF_4BPP;
+ if (cBits <= 8) return BMF_8BPP;
+ if (cBits <= 16) return BMF_16BPP;
+ if (cBits <= 24) return BMF_24BPP;
+ if (cBits <= 32) return BMF_32BPP;
return 0;
case BI_RLE4:
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);
+ psurf = (PSURFACE)GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_BITMAP, sizeof(SURFACE));
if (psurf)
{
pso->iType = iType;
pso->iUniq = InterlockedIncrement((PLONG)&giUniqueSurface);
- SURFACE_vSetDefaultPalette(psurf);
+ /* Assign a default palette and increment its reference count */
+ psurf->ppal = appalSurfaceDefault[iFormat];
+ GDIOBJ_vReferenceObjectByPointer(&psurf->ppal->BaseObject);
}
return psurf;
{
SURFOBJ *pso = &psurf->SurfObj;
PVOID pvSection;
+ UCHAR cBitsPixel;
/* Only bitmaps can have bits */
ASSERT(psurf->SurfObj.iType == STYPE_BITMAP);
- /* If no width is given, calculate it */
- if (!ulWidth)
- ulWidth = DIB_GetDIBWidthBytes(pso->sizlBitmap.cx,
- BitsPerFormat(pso->iBitmapFormat));
+ /* Get bits per pixel from the format */
+ cBitsPixel = gajBitsPerFormat[pso->iBitmapFormat];
+
+ /* Is a width in bytes given? */
+ if (ulWidth)
+ {
+ /* Align the width (Windows compatibility, drivers expect that) */
+ ulWidth = WIDTH_BYTES_ALIGN32((ulWidth << 3) / cBitsPixel, cBitsPixel);
+ }
+ else
+ {
+ /* Calculate width from the bitmap width in pixels */
+ ulWidth = WIDTH_BYTES_ALIGN32(pso->sizlBitmap.cx, cBitsPixel);
+ }
/* 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);
}
{
/* Bail out if that failed */
DPRINT1("SURFACE_bSetBitmapBits failed.\n");
- SURFACE_FreeSurfaceByHandle(hbmp);
+ GDIOBJ_vDeleteObject(&psurf->BaseObject);
return NULL;
}
/* Set public ownership */
- GDIOBJ_SetOwnership(hbmp, NULL);
+ GDIOBJ_vSetObjectOwner(&psurf->BaseObject, GDI_OBJ_HMGR_PUBLIC);
/* Unlock the surface and return */
SURFACE_UnlockSurface(psurf);
hbmp = (HBITMAP)psurf->SurfObj.hsurf;
/* Set public ownership */
- GDIOBJ_SetOwnership(hbmp, NULL);
+ GDIOBJ_vSetObjectOwner(&psurf->BaseObject, GDI_OBJ_HMGR_PUBLIC);
/* Unlock the surface and return */
SURFACE_UnlockSurface(psurf);
hsurf = psurf->SurfObj.hsurf;
/* Set public ownership */
- GDIOBJ_SetOwnership(hsurf, NULL);
+ GDIOBJ_vSetObjectOwner(&psurf->BaseObject, GDI_OBJ_HMGR_PUBLIC);
/* Unlock the surface and return */
SURFACE_UnlockSurface(psurf);
ppdev = (PDEVOBJ*)hdev;
/* Lock the surface */
- psurf = SURFACE_LockSurface(hsurf);
+ psurf = SURFACE_ShareLockSurface(hsurf);
if (!psurf)
{
return FALSE;
/* Get palette */
psurf->ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
- SURFACE_UnlockSurface(psurf);
+ SURFACE_ShareUnlockSurface(psurf);
return TRUE;
}
PSURFACE psurf;
PDEVOBJ* ppdev;
- psurf = SURFACE_LockSurface(hsurf);
+ psurf = SURFACE_ShareLockSurface(hsurf);
if (psurf == NULL)
{
return FALSE;
/* Get palette */
psurf->ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
- SURFACE_UnlockSurface(psurf);
+ SURFACE_ShareUnlockSurface(psurf);
return TRUE;
}
APIENTRY
EngDeleteSurface(IN HSURF hsurf)
{
- GDIOBJ_SetOwnership(hsurf, PsGetCurrentProcess());
- SURFACE_FreeSurfaceByHandle(hsurf);
+ PSURFACE psurf;
+
+ psurf = SURFACE_ShareLockSurface(hsurf);
+ if (!psurf)
+ {
+ DPRINT1("Could not reference surface to delete\n");
+ return FALSE;
+ }
+
+ GDIOBJ_vDeleteObject(&psurf->BaseObject);
return TRUE;
}
APIENTRY
EngLockSurface(IN HSURF hsurf)
{
- SURFACE *psurf = GDIOBJ_ShareLockObj(hsurf, GDI_OBJECT_TYPE_BITMAP);
+ SURFACE *psurf = SURFACE_ShareLockSurface(hsurf);
- if (psurf != NULL)
- return &psurf->SurfObj;
-
- return NULL;
+ return psurf ? &psurf->SurfObj : NULL;
}
VOID
APIENTRY
NtGdiEngUnlockSurface(IN SURFOBJ *pso)
{
- EngUnlockSurface(pso);
+ UNIMPLEMENTED;
+ ASSERT(FALSE);
}
VOID
if (pso != NULL)
{
SURFACE *psurf = CONTAINING_RECORD(pso, SURFACE, SurfObj);
- GDIOBJ_ShareUnlockObjByPtr((POBJ)psurf);
- }
-}
-
-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)
- {
- pso->lDelta = DIB_GetDIBWidthBytes(Size.cx, BitsPerFormat(BMF_4BPP));
- pso->cjBits = pso->lDelta * Size.cy;
- UncompressedFormat = BMF_4BPP;
- UncompressedBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
- Decompress4bpp(Size, (BYTE *)Bits, (BYTE *)UncompressedBits, pso->lDelta);
- Flags |= BMF_RLE_HACK;
+ SURFACE_ShareUnlockSurface(psurf);
}
- else if (Format == BMF_8RLE)
- {
- pso->lDelta = DIB_GetDIBWidthBytes(Size.cx, BitsPerFormat(BMF_8BPP));
- pso->cjBits = pso->lDelta * Size.cy;
- 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
- {
- pso->lDelta = abs(Width);
- pso->cjBits = pso->lDelta * Size.cy;
- 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 */