PSURFACE psurf;
SURFOBJ *pso;
HBITMAP hbmp;
- PVOID pvCompressedBits;
- SIZEL sizl;
/* Verify format */
if (iFormat < BMF_1BPP || iFormat > BMF_PNG) return NULL;
/* The infamous RLE hack */
if (iFormat == BMF_4RLE || iFormat == BMF_8RLE)
{
+ PVOID pvCompressedBits;
+ SIZEL sizl;
+ LONG lDelta;
+
sizl.cx = nWidth;
sizl.cy = nHeight;
+ lDelta = WIDTH_BYTES_ALIGN32(nWidth, gajBitsPerFormat[iFormat]);
+
pvCompressedBits = pvBits;
- pvBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
+ pvBits = EngAllocMem(FL_ZERO_MEMORY, lDelta * nHeight, TAG_DIB);
if (!pvBits)
{
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
SURFACE_FreeSurfaceByHandle(hbmp);
return NULL;
}
- DecompressBitmap(sizl, pvCompressedBits, pvBits, pso->lDelta, iFormat);
+ DecompressBitmap(sizl, pvCompressedBits, pvBits, lDelta, iFormat);
fjBitmap |= BMF_RLE_HACK;
+
+ iFormat = iFormat == BMF_4RLE ? BMF_4BPP : BMF_8BPP;
+ psurf->SurfObj.iBitmapFormat = iFormat;
}
- /* Mark as API bitmap */
- psurf->flags |= (flags | API_BITMAP);
+ /* Mark as API bitmap */
+ psurf->flags |= (flags | API_BITMAP);
/* Set the bitmap bits */
if (!SURFACE_bSetBitmapBits(psurf, fjBitmap, cjWidthBytes, pvBits))
return 0;
}
- Bitmap = SURFACE_LockSurface(hBitmap);
+ Bitmap = SURFACE_ShareLockSurface(hBitmap);
if (Bitmap == NULL)
{
return 0;
if (res)
{
- resBitmap = SURFACE_LockSurface(res);
+ resBitmap = SURFACE_ShareLockSurface(res);
if (resBitmap)
{
IntSetBitmapBits(resBitmap, Bitmap->SurfObj.cjBits, Bitmap->SurfObj.pvBits);
- SURFACE_UnlockSurface(resBitmap);
+ GDIOBJ_IncrementShareCount(&Bitmap->ppal->BaseObject);
+ GDIOBJ_ShareUnlockObjByPtr(&resBitmap->ppal->BaseObject);
+ resBitmap->ppal = Bitmap->ppal;
+ SURFACE_ShareUnlockSurface(resBitmap);
}
else
{
}
}
- SURFACE_UnlockSurface(Bitmap);
+ SURFACE_ShareUnlockSurface(Bitmap);
return res;
}
case BMF_1BPP:
case BMF_4BPP:
case BMF_8BPP:
- case BMF_24BPP:
pds->dsBmih.biCompression = BI_RGB;
break;
pds->dsBmih.biCompression = BI_BITFIELDS;
break;
+ case BMF_24BPP:
case BMF_32BPP:
- if (psurf->ppal->flFlags & PAL_RGB)
+ /* 24/32bpp BI_RGB is actually BGR format */
+ if (psurf->ppal->flFlags & PAL_BGR)
pds->dsBmih.biCompression = BI_RGB;
else
pds->dsBmih.biCompression = BI_BITFIELDS;