1 #undef WIN32_LEAN_AND_MEAN
4 #include <win32k/bitmaps.h>
5 //#include <win32k/debug.h>
6 #include "../eng/handle.h"
9 #include <win32k/debug1.h>
11 BOOL STDCALL
W32kBitBlt(HDC hDCDest
,
21 PDC DCDest
= DC_HandleToPtr(hDCDest
);
22 PDC DCSrc
= DC_HandleToPtr(hDCSrc
);
23 PSURFOBJ SurfDest
, SurfSrc
;
24 PSURFGDI SurfGDIDest
, SurfGDISrc
;
27 PBITMAPOBJ DestBitmapObj
;
28 PBITMAPOBJ SrcBitmapObj
;
29 BOOL Status
, SurfDestAlloc
, SurfSrcAlloc
;
31 PPALGDI PalDestGDI
, PalSourceGDI
;
32 PXLATEOBJ XlateObj
= NULL
;
33 HPALETTE SourcePalette
, DestPalette
;
35 /* Offset the destination and source by the origin of their DCs. */
36 XDest
+= DCDest
->w
.DCOrgX
;
37 YDest
+= DCDest
->w
.DCOrgY
;
38 XSrc
+= DCSrc
->w
.DCOrgX
;
39 YSrc
+= DCSrc
->w
.DCOrgY
;
41 DestRect
.left
= XDest
;
43 DestRect
.right
= XDest
+Width
;
44 DestRect
.bottom
= YDest
+Height
;
49 SurfDestAlloc
= FALSE
;
52 // Determine surfaces to be used in the bitblt
53 SurfDest
= (PSURFOBJ
)AccessUserObject(DCDest
->Surface
);
54 SurfSrc
= (PSURFOBJ
)AccessUserObject(DCSrc
->Surface
);
56 SurfGDIDest
= (PSURFGDI
)AccessInternalObjectFromUserObject(SurfDest
);
57 SurfGDISrc
= (PSURFGDI
)AccessInternalObjectFromUserObject(SurfSrc
);
59 // Retrieve the logical palette of the destination DC
60 DCLogPal
= (PPALOBJ
)AccessUserObject(DCDest
->w
.hPalette
);
63 if(DCLogPal
->logicalToSystem
)
64 XlateObj
= DCLogPal
->logicalToSystem
;
66 // If the source and destination formats differ, create an XlateObj [what if we already have one??]
67 if((BitsPerFormat(SurfDest
->iBitmapFormat
) != BitsPerFormat(SurfSrc
->iBitmapFormat
)) && (XlateObj
== NULL
))
69 if(DCDest
->w
.hPalette
!= 0)
71 DestPalette
= DCDest
->w
.hPalette
;
73 DestPalette
= W32kGetStockObject(DEFAULT_PALETTE
);
75 if(DCSrc
->w
.hPalette
!= 0)
77 SourcePalette
= DCSrc
->w
.hPalette
;
79 SourcePalette
= W32kGetStockObject(DEFAULT_PALETTE
);
81 PalDestGDI
= (PPALGDI
)AccessInternalObject(DestPalette
);
82 PalSourceGDI
= (PPALGDI
)AccessInternalObject(SourcePalette
);
84 XlateObj
= (PXLATEOBJ
)EngCreateXlate(PalDestGDI
->Mode
, PalSourceGDI
->Mode
, DestPalette
, SourcePalette
);
87 // Perform the bitblt operation
89 Status
= EngBitBlt(SurfDest
, SurfSrc
, NULL
, NULL
, XlateObj
, &DestRect
, &SourcePoint
, NULL
, NULL
, NULL
, NULL
);
91 if(SurfDestAlloc
== TRUE
) ExFreePool(SurfDest
);
92 if(SurfSrcAlloc
== TRUE
) ExFreePool(SurfSrc
);
94 DC_ReleasePtr(hDCDest
);
95 DC_ReleasePtr(hDCSrc
);
100 HBITMAP STDCALL
W32kCreateBitmap(INT Width
,
109 Planes
= (BYTE
) Planes
;
110 BitsPerPel
= (BYTE
) BitsPerPel
;
112 /* Check parameters */
113 if (!Height
|| !Width
)
131 /* Create the BITMAPOBJ */
132 hBitmap
= BITMAPOBJ_AllocBitmap ();
135 DPRINT("W32kCreateBitmap: BITMAPOBJ_AllocBitmap returned 0\n");
139 bmp
= BITMAPOBJ_HandleToPtr( hBitmap
);
141 DPRINT("W32kCreateBitmap:%dx%d, %d (%d BPP) colors returning %08x\n", Width
, Height
,
142 1 << (Planes
* BitsPerPel
), BitsPerPel
, bmp
);
144 bmp
->size
.cx
= Width
;
145 bmp
->size
.cy
= Height
;
146 bmp
->bitmap
.bmType
= 0;
147 bmp
->bitmap
.bmWidth
= Width
;
148 bmp
->bitmap
.bmHeight
= Height
;
149 bmp
->bitmap
.bmPlanes
= Planes
;
150 bmp
->bitmap
.bmBitsPixel
= BitsPerPel
;
151 bmp
->bitmap
.bmWidthBytes
= BITMAPOBJ_GetWidthBytes (Width
, BitsPerPel
);
152 bmp
->bitmap
.bmBits
= NULL
;
153 bmp
->DDBitmap
= NULL
;
156 // Allocate memory for bitmap bits
157 bmp
->bitmap
.bmBits
= ExAllocatePool(PagedPool
, bmp
->bitmap
.bmWidthBytes
* bmp
->bitmap
.bmHeight
);
159 if (Bits
) /* Set bitmap bits */
161 W32kSetBitmapBits(hBitmap
, Height
* bmp
->bitmap
.bmWidthBytes
, Bits
);
164 BITMAPOBJ_ReleasePtr( hBitmap
);
169 BOOL
Bitmap_InternalDelete( PBITMAPOBJ pBmp
)
172 ExFreePool(pBmp
->bitmap
.bmBits
);
177 HBITMAP STDCALL
W32kCreateCompatibleBitmap(HDC hDC
,
185 dc
= DC_HandleToPtr (hDC
);
187 DbgPrint("W32kCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n", hDC
, Width
, Height
, dc
->w
.bitsPerPixel
);
193 if ((Width
>= 0x10000) || (Height
>= 0x10000))
195 DPRINT("got bad width %d or height %d, please look for reason\n", Width
, Height
);
199 /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
200 if (!Width
|| !Height
)
202 hbmpRet
= W32kCreateBitmap (1, 1, 1, 1, NULL
);
206 hbmpRet
= W32kCreateBitmap(Width
, Height
, 1, dc
->w
.bitsPerPixel
, NULL
);
209 DPRINT ("\t\t%04x\n", hbmpRet
);
210 DC_ReleasePtr( hDC
);
214 HBITMAP STDCALL
W32kCreateBitmapIndirect(CONST BITMAP
*BM
)
216 return W32kCreateBitmap (BM
->bmWidth
,
223 HBITMAP STDCALL
W32kCreateDiscardableBitmap(HDC hDC
,
227 /* FIXME: this probably should do something else */
228 return W32kCreateCompatibleBitmap(hDC
, Width
, Height
);
231 BOOL STDCALL
W32kExtFloodFill(HDC hDC
,
240 BOOL STDCALL
W32kFloodFill(HDC hDC
,
248 BOOL STDCALL
W32kGetBitmapDimensionEx(HBITMAP hBitmap
,
253 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
259 *Dimension
= bmp
->size
;
264 COLORREF STDCALL
W32kGetPixel(HDC hDC
,
271 BOOL STDCALL
W32kMaskBlt(HDC hDCDest
,
287 BOOL STDCALL
W32kPlgBlt(HDC hDCDest
,
301 LONG STDCALL
W32kSetBitmapBits(HBITMAP hBitmap
,
308 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
309 if (bmp
== NULL
|| Bits
== NULL
)
316 DPRINT ("(%ld): Negative number of bytes passed???\n", Bytes
);
320 /* Only get entire lines */
321 height
= Bytes
/ bmp
->bitmap
.bmWidthBytes
;
322 if (height
> bmp
->bitmap
.bmHeight
)
324 height
= bmp
->bitmap
.bmHeight
;
326 Bytes
= height
* bmp
->bitmap
.bmWidthBytes
;
327 DPRINT ("(%08x, bytes:%ld, bits:%p) %dx%d %d colors fetched height: %ld\n",
332 bmp
->bitmap
.bmHeight
,
333 1 << bmp
->bitmap
.bmBitsPixel
,
337 /* FIXME: call DDI specific function here if available */
340 DPRINT ("Calling device specific BitmapBits\n");
341 if (bmp
->DDBitmap
->funcs
->pBitmapBits
)
343 ret
= bmp
->DDBitmap
->funcs
->pBitmapBits(hBitmap
, (void *) Bits
, Bytes
, DDB_SET
);
347 DPRINT ("BitmapBits == NULL??\n");
354 /* FIXME: Alloc enough for entire bitmap */
355 if (bmp
->bitmap
.bmBits
== NULL
)
357 bmp
->bitmap
.bmBits
= ExAllocatePool (PagedPool
, Bytes
);
359 if(!bmp
->bitmap
.bmBits
)
361 DPRINT ("Unable to allocate bit buffer\n");
366 memcpy(bmp
->bitmap
.bmBits
, Bits
, Bytes
);
374 BOOL STDCALL
W32kSetBitmapDimensionEx(HBITMAP hBitmap
,
381 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
391 bmp
->size
.cx
= Width
;
392 bmp
->size
.cy
= Height
;
397 COLORREF STDCALL
W32kSetPixel(HDC hDC
,
405 BOOL STDCALL
W32kSetPixelV(HDC hDC
,
413 BOOL STDCALL
W32kStretchBlt(HDC hDCDest
,
428 /* Internal Functions */
431 BITMAPOBJ_GetWidthBytes (INT bmWidth
, INT bpp
)
436 return 2 * ((bmWidth
+15) >> 4);
439 bmWidth
*= 3; /* fall through */
441 return bmWidth
+ (bmWidth
& 1);
451 return 2 * ((bmWidth
+3) >> 2);
460 HBITMAP
BITMAPOBJ_CopyBitmap(HBITMAP hBitmap
)
466 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
475 res
= W32kCreateBitmapIndirect(&bm
);
480 buf
= ExAllocatePool (NonPagedPool
, bm
.bmWidthBytes
* bm
.bmHeight
);
481 W32kGetBitmapBits (hBitmap
, bm
.bmWidthBytes
* bm
.bmHeight
, buf
);
482 W32kSetBitmapBits (res
, bm
.bmWidthBytes
* bm
.bmHeight
, buf
);
489 INT
BITMAP_GetObject(BITMAPOBJ
* bmp
, INT count
, LPVOID buffer
)
493 if(count
< sizeof(DIBSECTION
))
495 if (count
> sizeof(BITMAP
)) count
= sizeof(BITMAP
);
499 if (count
> sizeof(DIBSECTION
)) count
= sizeof(DIBSECTION
);
501 memcpy(buffer
, bmp
->dib
, count
);
506 if (count
> sizeof(BITMAP
)) count
= sizeof(BITMAP
);
507 memcpy(buffer
, &bmp
->bitmap
, count
);