- DDB are 16 bits aligned.
- Reset hdc field of the unselected bitmap.
- Lock it too, so it's not messed with when we unselect it.
- Move Pattern creation of IntGdiCreateDIBBrush to DIB_CreateDIBSection.
svn path=/branches/reactos-yarotows/; revision=48406
cBitsPixel = gajBitsPerFormat[pso->iBitmapFormat];
/* Is a width in bytes given? */
- if (ulWidth)
+ if (!ulWidth)
{
- /* Align the width (Windows compatibility) */
- ulWidth = ((((ulWidth << 3) / cBitsPixel) * cBitsPixel + 31) & ~31) >> 3;
- }
- else
- {
- /* Calculate width from the bitmap width in pixels */
- ulWidth = ((pso->sizlBitmap.cx * cBitsPixel + 31) & ~31) >> 3;
- }
+ /* Align the width (windows compatibility) */
+ if(psurf->flags & DDB_SURFACE)
+ {
+ /* DDB are 16 bits aligned */
+ ulWidth = BITMAP_GetWidthBytes(pso->sizlBitmap.cx, cBitsPixel);
+ }
+ else
+ {
+ /* Others are 32 bits aligned */
+ ulWidth = DIB_GetDIBWidthBytes(pso->sizlBitmap.cx, cBitsPixel);
+ }
+ }
+
/* Calculate the bitmap size in bytes */
pso->cjBits = ulWidth * pso->sizlBitmap.cy;
IN ULONG iFormat,
IN USHORT fjBitmap,
IN ULONG cjBits,
- IN OPTIONAL PVOID pvBits);
+ IN OPTIONAL PVOID pvBits,
+ IN FLONG flags);
HBITMAP
FASTCALL
IN ULONG iFormat,
IN USHORT fjBitmap,
IN ULONG cjSizeImage,
- IN OPTIONAL PVOID pvBits)
+ IN OPTIONAL PVOID pvBits,
+ IN FLONG flags)
{
PSURFACE psurf;
SURFOBJ *pso;
HBITMAP hbmp;
PVOID pvCompressedBits;
SIZEL sizl;
- FLONG fl = 0;
/* Verify format */
if (iFormat < BMF_1BPP || iFormat > BMF_PNG) return NULL;
pvCompressedBits = pvBits;
pvBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
Decompress4bpp(sizl, pvCompressedBits, pvBits, pso->lDelta);
- fl |= BMF_RLE_HACK;
+ fjBitmap |= BMF_RLE_HACK;
}
else if (iFormat == BMF_8RLE)
{
pvCompressedBits = pvBits;
pvBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
Decompress8bpp(sizl, pvCompressedBits, pvBits, pso->lDelta);
- fl |= BMF_RLE_HACK;
+ fjBitmap |= BMF_RLE_HACK;
}
+ /* Mark as API bitmap */
+ psurf->flags |= (flags | API_BITMAP);
+
/* Set the bitmap bits */
if (!SURFACE_bSetBitmapBits(psurf, fjBitmap, cjWidthBytes, pvBits))
{
return NULL;
}
- /* Mark as API bitmap */
- psurf->flags |= API_BITMAP;
-
/* Unlock the surface and return */
SURFACE_UnlockSurface(psurf);
return hbmp;
}
+/* Creates a DDB surface,
+ * as in CreateCompatibleBitmap or CreateBitmap.
+ */
HBITMAP
APIENTRY
GreCreateBitmap(
BitmapFormat(cBitsPixel * cPlanes, BI_RGB),
0, /* no bitmap flags */
0, /* auto size */
- pvBits);
+ pvBits,
+ DDB_SURFACE /* DDB */);
}
HBITMAP
IN UINT cBitsPixel,
IN OPTIONAL LPBYTE pUnsafeBits)
{
- PSURFACE psurf;
- SURFOBJ *pso;
HBITMAP hbmp;
- FLONG fl = 0;
ULONG cjWidthBytes, iFormat;
/* NOTE: Windows also doesn't store nr. of planes separately! */
}
/* Make sure that cjBits will not overflow */
- cjWidthBytes = DIB_GetDIBWidthBytes(nWidth, cBitsPixel);
+ cjWidthBytes = BITMAP_GetWidthBytes(nWidth, cBitsPixel);
if ((ULONGLONG)cjWidthBytes * nHeight >= 0x100000000ULL)
{
DPRINT1("Width = %d, Height = %d BitsPixel = %d\n",
return NULL;
}
- /* Allocate a surface */
- psurf = SURFACE_AllocSurface(STYPE_BITMAP, nWidth, nHeight, iFormat);
- if (!psurf)
- {
- DPRINT1("SURFACE_AllocSurface failed.\n");
- EngSetLastError(ERROR_OUTOFMEMORY);
- return NULL;
- }
-
- /* Get the handle for the bitmap and the surfobj */
- hbmp = (HBITMAP)psurf->SurfObj.hsurf;
- pso = &psurf->SurfObj;
+ /* cBitsPixel = cBitsPixel * cPlanes now! */
+ hbmp = GreCreateBitmap(nWidth, nHeight, 1, cBitsPixel, NULL);
- /* Allocate the bitmap bits */
- if (!SURFACE_bSetBitmapBits(psurf, fl, 0, NULL))
- {
- /* Bail out if that failed */
- DPRINT1("SURFACE_bSetBitmapBits failed.\n");
- SURFACE_FreeSurfaceByHandle(hbmp);
- return NULL;
- }
-
if (pUnsafeBits)
{
+ PSURFACE psurf = SURFACE_LockSurface(hbmp);
_SEH2_TRY
{
ProbeForRead(pUnsafeBits, cjWidthBytes * nHeight, 1);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
+ SURFACE_UnlockSurface(psurf);
SURFACE_FreeSurfaceByHandle(hbmp);
_SEH2_YIELD(return NULL;)
}
_SEH2_END
- }
- /* Mark as API bitmap */
- psurf->flags |= API_BITMAP;
+ SURFACE_UnlockSurface(psurf);
+ }
- /* Unlock the surface and return */
- SURFACE_UnlockSurface(psurf);
return hbmp;
}
Bitmap->SurfObj.iBitmapFormat,
Bitmap->SurfObj.fjBitmap,
Bitmap->SurfObj.cjBits,
- NULL);
+ NULL,
+ Bitmap->flags);
if (res)
return hdc;
}
+
/* EOF */
RGN_ATTR Attr[GDIOBJATTRFREE];
} GDI_OBJ_ATTR_ENTRY, *PGDI_OBJ_ATTR_ENTRY;
-static const ULONG HatchBrushes[NB_HATCH_STYLES][8] =
+static const USHORT HatchBrushes[NB_HATCH_STYLES][8] =
{
{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF}, /* HS_HORIZONTAL */
{0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7}, /* HS_VERTICAL */
PBRUSH pbrush;
HBITMAP hPattern;
ULONG_PTR DataPtr;
- PSURFACE psurfPattern;
- HPALETTE hpal ;
+ PVOID pvDIBits;
if (BitmapInfo->bmiHeader.biSize < sizeof(BITMAPINFOHEADER))
{
DataPtr = (ULONG_PTR)BitmapInfo + DIB_BitmapInfoSize(BitmapInfo, ColorSpec);
- hPattern = GreCreateBitmap(BitmapInfo->bmiHeader.biWidth,
- BitmapInfo->bmiHeader.biHeight,
- BitmapInfo->bmiHeader.biPlanes,
- BitmapInfo->bmiHeader.biBitCount,
- (PVOID)DataPtr);
+ hPattern = DIB_CreateDIBSection(NULL, BitmapInfo, ColorSpec, &pvDIBits, NULL, 0, 0);
if (hPattern == NULL)
{
SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
-
- psurfPattern = SURFACE_LockSurface(hPattern);
- ASSERT(psurfPattern != NULL);
- if(ColorSpec == DIB_PAL_COLORS) DPRINT1("FIXME, unsupported color spec!\n");
- hpal = BuildDIBPalette(BitmapInfo);
- psurfPattern->ppal = PALETTE_ShareLockPalette(hpal);
- /* Lazy delete palette, it will be freed when its shared reference is zeroed */
- GreDeleteObject(hpal);
- SURFACE_UnlockSurface(psurfPattern);
+ RtlCopyMemory(pvDIBits,
+ (PVOID)DataPtr,
+ DIB_GetDIBImageBytes(BitmapInfo->bmiHeader.biWidth,
+ BitmapInfo->bmiHeader.biHeight,
+ BitmapInfo->bmiHeader.biBitCount * BitmapInfo->bmiHeader.biPlanes));
pbrush = BRUSH_AllocBrushWithHandle();
if (pbrush == NULL)
}
/* Get the handle for the old bitmap */
- psurfOld = pDC->dclevel.pSurface;
- hOrgBmp = psurfOld ? psurfOld->BaseObject.hHmgr : NULL;
+ ASSERT(pDC->dclevel.pSurface);
+ hOrgBmp = pDC->dclevel.pSurface->BaseObject.hHmgr;
+
+ /* Lock it, to be sure while we mess with it*/
+ psurfOld = SURFACE_LockSurface(hOrgBmp);
+
+ /* Reset hdc, this surface isn't selected anymore */
+ psurfOld->hdc = NULL;
/* Release the old bitmap, reference the new */
DC_vSelectSurface(pDC, psurfBmp);
+ /* And unlock it, now we're done */
+ SURFACE_UnlockSurface(psurfOld);
+
// If Info DC this is zero and pSurface is moved to DC->pSurfInfo.
psurfBmp->hdc = hDC;
+
/* FIXME; improve by using a region without a handle and selecting it */
hVisRgn = IntSysCreateRectRgn( 0,
0,
if (usage == DIB_PAL_COLORS)
{
- PPALETTE pdcPal ;
- pdcPal = PALETTE_LockPalette(dc->dclevel.hpal);
- hpal = DIB_MapPaletteColors(pdcPal, bmi);
- PALETTE_UnlockPalette(pdcPal);
+ if(dc)
+ {
+ PPALETTE pdcPal ;
+ pdcPal = PALETTE_LockPalette(dc->dclevel.hpal);
+ hpal = DIB_MapPaletteColors(pdcPal, bmi);
+ PALETTE_UnlockPalette(pdcPal);
+ }
+ else
+ {
+ /* For DIB Brushes */
+ DPRINT1("FIXME : Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
+ /* HACK */
+ hpal = (HPALETTE) 0xFFFFFFFF;
+ }
}
else
{
if(!hpal)
{
- DPRINT1("Error : Could not create a aplette for the DIB.\n");
+ DPRINT1("Error : Could not create a palette for the DIB.\n");
goto cleanup;
}
BMF_DONTCACHE | BMF_USERMEM | BMF_NOZEROINIT |
(bi->biHeight < 0 ? BMF_TOPDOWN : 0),
bi->biSizeImage,
- bm.bmBits);
+ bm.bmBits,
+ 0);
if (!res)
{
SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
bmp->flags = API_BITMAP;
bmp->biClrImportant = bi->biClrImportant;
- bmp->ppal = PALETTE_ShareLockPalette(hpal);
- /* Lazy delete hpal, it will be freed at surface release */
- GreDeleteObject(hpal);
+ /* HACK */
+ if(hpal != (HPALETTE)0xFFFFFFFF)
+ {
+ bmp->ppal = PALETTE_ShareLockPalette(hpal);
+ /* Lazy delete hpal, it will be freed at surface release */
+ GreDeleteObject(hpal);
+ }
// Clean up in case of errors
cleanup: