1 #undef WIN32_LEAN_AND_MEAN
4 #include <win32k/bitmaps.h>
5 //#include <win32k/debug.h>
6 #include "../eng/handle.h"
7 #include <include/inteng.h>
10 #include <win32k/debug1.h>
12 BOOL STDCALL W32kBitBlt(HDC hDCDest,
22 PDC DCDest = DC_HandleToPtr(hDCDest);
23 PDC DCSrc = DC_HandleToPtr(hDCSrc);
24 PSURFOBJ SurfDest, SurfSrc;
25 PSURFGDI SurfGDIDest, SurfGDISrc;
28 PBITMAPOBJ DestBitmapObj;
29 PBITMAPOBJ SrcBitmapObj;
30 BOOL Status, SurfDestAlloc, SurfSrcAlloc, XlateAlloc;
32 PPALGDI PalDestGDI, PalSourceGDI;
33 PXLATEOBJ XlateObj = NULL;
34 HPALETTE SourcePalette, DestPalette;
36 /* Offset the destination and source by the origin of their DCs. */
37 XDest += DCDest->w.DCOrgX;
38 YDest += DCDest->w.DCOrgY;
39 XSrc += DCSrc->w.DCOrgX;
40 YSrc += DCSrc->w.DCOrgY;
42 DestRect.left = XDest;
44 DestRect.right = XDest+Width;
45 DestRect.bottom = YDest+Height;
50 SurfDestAlloc = FALSE;
54 // Determine surfaces to be used in the bitblt
55 SurfDest = (PSURFOBJ)AccessUserObject(DCDest->Surface);
56 SurfSrc = (PSURFOBJ)AccessUserObject(DCSrc->Surface);
58 SurfGDIDest = (PSURFGDI)AccessInternalObjectFromUserObject(SurfDest);
59 SurfGDISrc = (PSURFGDI)AccessInternalObjectFromUserObject(SurfSrc);
61 // Retrieve the logical palette of the destination DC
62 DCLogPal = (PPALOBJ)AccessUserObject(DCDest->w.hPalette);
65 if(DCLogPal->logicalToSystem)
66 XlateObj = DCLogPal->logicalToSystem;
68 // If the source and destination formats differ, create an XlateObj [what if we already have one??]
69 if((BitsPerFormat(SurfDest->iBitmapFormat) != BitsPerFormat(SurfSrc->iBitmapFormat)) && (XlateObj == NULL))
71 if(DCDest->w.hPalette != 0)
73 DestPalette = DCDest->w.hPalette;
75 DestPalette = W32kGetStockObject(DEFAULT_PALETTE);
77 if(DCSrc->w.hPalette != 0)
79 SourcePalette = DCSrc->w.hPalette;
81 SourcePalette = W32kGetStockObject(DEFAULT_PALETTE);
83 PalDestGDI = (PPALGDI)AccessInternalObject(DestPalette);
84 PalSourceGDI = (PPALGDI)AccessInternalObject(SourcePalette);
86 XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalDestGDI->Mode, PalSourceGDI->Mode, DestPalette, SourcePalette);
90 // Perform the bitblt operation
92 Status = IntEngBitBlt(SurfDest, SurfSrc, NULL, NULL, XlateObj, &DestRect, &SourcePoint, NULL, NULL, NULL, ROP);
94 if (XlateAlloc) EngDeleteXlate(XlateObj);
95 if (SurfDestAlloc) ExFreePool(SurfDest);
96 if (SurfSrcAlloc) ExFreePool(SurfSrc);
98 DC_ReleasePtr(hDCDest);
99 DC_ReleasePtr(hDCSrc);
104 HBITMAP STDCALL W32kCreateBitmap(INT Width,
113 Planes = (BYTE) Planes;
114 BitsPerPel = (BYTE) BitsPerPel;
116 /* Check parameters */
117 if (!Height || !Width)
135 /* Create the BITMAPOBJ */
136 hBitmap = BITMAPOBJ_AllocBitmap ();
139 DPRINT("W32kCreateBitmap: BITMAPOBJ_AllocBitmap returned 0\n");
143 bmp = BITMAPOBJ_HandleToPtr( hBitmap );
145 DPRINT("W32kCreateBitmap:%dx%d, %d (%d BPP) colors returning %08x\n", Width, Height,
146 1 << (Planes * BitsPerPel), BitsPerPel, bmp);
148 bmp->size.cx = Width;
149 bmp->size.cy = Height;
150 bmp->bitmap.bmType = 0;
151 bmp->bitmap.bmWidth = Width;
152 bmp->bitmap.bmHeight = Height;
153 bmp->bitmap.bmPlanes = Planes;
154 bmp->bitmap.bmBitsPixel = BitsPerPel;
155 bmp->bitmap.bmWidthBytes = BITMAPOBJ_GetWidthBytes (Width, BitsPerPel);
156 bmp->bitmap.bmBits = NULL;
157 bmp->DDBitmap = NULL;
160 // Allocate memory for bitmap bits
161 bmp->bitmap.bmBits = ExAllocatePool(PagedPool, bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight);
163 if (Bits) /* Set bitmap bits */
165 W32kSetBitmapBits(hBitmap, Height * bmp->bitmap.bmWidthBytes, Bits);
168 BITMAPOBJ_ReleasePtr( hBitmap );
173 BOOL Bitmap_InternalDelete( PBITMAPOBJ pBmp )
176 if( pBmp->bitmap.bmBits )
177 ExFreePool(pBmp->bitmap.bmBits);
182 HBITMAP STDCALL W32kCreateCompatibleBitmap(HDC hDC,
190 dc = DC_HandleToPtr (hDC);
192 DPRINT("W32kCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n", hDC, Width, Height, dc->w.bitsPerPixel);
198 if ((Width >= 0x10000) || (Height >= 0x10000))
200 DPRINT("got bad width %d or height %d, please look for reason\n", Width, Height);
204 /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
205 if (!Width || !Height)
207 hbmpRet = W32kCreateBitmap (1, 1, 1, 1, NULL);
211 hbmpRet = W32kCreateBitmap(Width, Height, 1, dc->w.bitsPerPixel, NULL);
214 DPRINT ("\t\t%04x\n", hbmpRet);
215 DC_ReleasePtr( hDC );
219 HBITMAP STDCALL W32kCreateBitmapIndirect(CONST BITMAP *BM)
221 return W32kCreateBitmap (BM->bmWidth,
228 HBITMAP STDCALL W32kCreateDiscardableBitmap(HDC hDC,
232 /* FIXME: this probably should do something else */
233 return W32kCreateCompatibleBitmap(hDC, Width, Height);
236 BOOL STDCALL W32kExtFloodFill(HDC hDC,
245 BOOL STDCALL W32kFloodFill(HDC hDC,
253 BOOL STDCALL W32kGetBitmapDimensionEx(HBITMAP hBitmap,
258 bmp = BITMAPOBJ_HandleToPtr (hBitmap);
264 *Dimension = bmp->size;
269 COLORREF STDCALL W32kGetPixel(HDC hDC,
276 BOOL STDCALL W32kMaskBlt(HDC hDCDest,
292 BOOL STDCALL W32kPlgBlt(HDC hDCDest,
306 LONG STDCALL W32kSetBitmapBits(HBITMAP hBitmap,
313 bmp = BITMAPOBJ_HandleToPtr (hBitmap);
314 if (bmp == NULL || Bits == NULL)
321 DPRINT ("(%ld): Negative number of bytes passed???\n", Bytes );
325 /* Only get entire lines */
326 height = Bytes / bmp->bitmap.bmWidthBytes;
327 if (height > bmp->bitmap.bmHeight)
329 height = bmp->bitmap.bmHeight;
331 Bytes = height * bmp->bitmap.bmWidthBytes;
332 DPRINT ("(%08x, bytes:%ld, bits:%p) %dx%d %d colors fetched height: %ld\n",
337 bmp->bitmap.bmHeight,
338 1 << bmp->bitmap.bmBitsPixel,
342 /* FIXME: call DDI specific function here if available */
345 DPRINT ("Calling device specific BitmapBits\n");
346 if (bmp->DDBitmap->funcs->pBitmapBits)
348 ret = bmp->DDBitmap->funcs->pBitmapBits(hBitmap, (void *) Bits, Bytes, DDB_SET);
352 DPRINT ("BitmapBits == NULL??\n");
359 /* FIXME: Alloc enough for entire bitmap */
360 if (bmp->bitmap.bmBits == NULL)
362 bmp->bitmap.bmBits = ExAllocatePool (PagedPool, Bytes);
364 if(!bmp->bitmap.bmBits)
366 DPRINT ("Unable to allocate bit buffer\n");
371 memcpy(bmp->bitmap.bmBits, Bits, Bytes);
379 BOOL STDCALL W32kSetBitmapDimensionEx(HBITMAP hBitmap,
386 bmp = BITMAPOBJ_HandleToPtr (hBitmap);
396 bmp->size.cx = Width;
397 bmp->size.cy = Height;
402 COLORREF STDCALL W32kSetPixel(HDC hDC,
410 BOOL STDCALL W32kSetPixelV(HDC hDC,
418 BOOL STDCALL W32kStretchBlt(HDC hDCDest,
433 /* Internal Functions */
436 BITMAPOBJ_GetWidthBytes (INT bmWidth, INT bpp)
441 return 2 * ((bmWidth+15) >> 4);
444 bmWidth *= 3; /* fall through */
446 return bmWidth + (bmWidth & 1);
456 return 2 * ((bmWidth+3) >> 2);
465 HBITMAP BITMAPOBJ_CopyBitmap(HBITMAP hBitmap)
471 bmp = BITMAPOBJ_HandleToPtr (hBitmap);
480 res = W32kCreateBitmapIndirect(&bm);
485 buf = ExAllocatePool (NonPagedPool, bm.bmWidthBytes * bm.bmHeight);
486 W32kGetBitmapBits (hBitmap, bm.bmWidthBytes * bm.bmHeight, buf);
487 W32kSetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
494 INT BITMAP_GetObject(BITMAPOBJ * bmp, INT count, LPVOID buffer)
498 if(count < sizeof(DIBSECTION))
500 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
504 if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
506 memcpy(buffer, bmp->dib, count);
511 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
512 memcpy(buffer, &bmp->bitmap, count);