3 #undef WIN32_LEAN_AND_MEAN
6 #include <win32k/bitmaps.h>
7 //#include <win32k/debug.h>
12 BOOL STDCALL
W32kBitBlt(HDC hDCDest
,
22 PDC DCDest
= DC_HandleToPtr(hDCDest
);
23 PDC DCSrc
= DC_HandleToPtr(hDCSrc
);
28 PBITMAPOBJ DestBitmapObj
;
29 PBITMAPOBJ SrcBitmapObj
;
30 BOOL Status
, SurfDestAlloc
, SurfSrcAlloc
;
32 DestRect
.left
= XDest
;
34 DestRect
.right
= XDest
+Width
;
35 DestRect
.bottom
= YDest
+Height
;
40 SurfDestAlloc
= FALSE
;
43 DPRINT("Get surfdest.. ");
46 if(DCDest
->Surface
!= NULL
)
48 // Use the DC's surface if it has one
49 SurfDest
= AccessUserObject(DCDest
->Surface
);
53 DPRINT("Get surfsrc.. ");
56 if(DCSrc
->Surface
!= NULL
)
58 DPRINT("from DC's surface\n");
60 // Use the DC's surface if it has one
61 SurfSrc
= AccessUserObject(DCSrc
->Surface
);
66 DPRINT("Go to EngBitBlt\n");
67 Status
= EngBitBlt(SurfDest
, SurfSrc
, NULL
, NULL
, NULL
,
68 &DestRect
, &SourcePoint
, NULL
, NULL
, NULL
, NULL
); // FIXME: Color translation (xlateobj)
70 if(SurfDestAlloc
== TRUE
) ExFreePool(SurfDest
);
71 if(SurfSrcAlloc
== TRUE
) ExFreePool(SurfSrc
);
76 HBITMAP STDCALL
W32kCreateBitmap(INT Width
,
85 Planes
= (BYTE
) Planes
;
86 BitsPerPel
= (BYTE
) BitsPerPel
;
88 /* Check parameters */
89 if (!Height
|| !Width
)
107 /* Create the BITMAPOBJ */
108 bmp
= BITMAPOBJ_AllocBitmap ();
114 DPRINT("W32kCreateBitmap:%dx%d, %d (%d BPP) colors returning %08x\n", Width
, Height
,
115 1 << (Planes
* BitsPerPel
), BitsPerPel
, bmp
);
119 bmp
->bitmap
.bmType
= 0;
120 bmp
->bitmap
.bmWidth
= Width
;
121 bmp
->bitmap
.bmHeight
= Height
;
122 bmp
->bitmap
.bmPlanes
= Planes
;
123 bmp
->bitmap
.bmBitsPixel
= BitsPerPel
;
124 bmp
->bitmap
.bmWidthBytes
= BITMAPOBJ_GetWidthBytes (Width
, BitsPerPel
);
125 bmp
->bitmap
.bmBits
= NULL
;
126 bmp
->DDBitmap
= NULL
;
128 hBitmap
= BITMAPOBJ_PtrToHandle (bmp
);
130 // Allocate memory for bitmap bits
131 bmp
->bitmap
.bmBits
= ExAllocatePool(PagedPool
, bmp
->bitmap
.bmWidthBytes
* bmp
->bitmap
.bmHeight
);
133 if (Bits
) /* Set bitmap bits */
135 W32kSetBitmapBits(hBitmap
,
136 Height
* bmp
->bitmap
.bmWidthBytes
,
144 HBITMAP STDCALL
W32kCreateCompatibleBitmap(HDC hDC
,
152 dc
= DC_HandleToPtr (hDC
);
154 DPRINT("W32kCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n", hDC
, Width
, Height
, dc
->w
.bitsPerPixel
);
160 if ((Width
>= 0x10000) || (Height
>= 0x10000))
162 DPRINT("got bad width %d or height %d, please look for reason\n",
167 /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
168 if (!Width
|| !Height
)
170 hbmpRet
= W32kCreateBitmap (1, 1, 1, 1, NULL
);
174 hbmpRet
= W32kCreateBitmap (Width
,
181 DPRINT ("\t\t%04x\n", hbmpRet
);
187 HBITMAP STDCALL
W32kCreateBitmapIndirect(CONST BITMAP
*BM
)
189 return W32kCreateBitmap (BM
->bmWidth
,
196 HBITMAP STDCALL
W32kCreateDIBitmap(HDC hDC
,
197 CONST BITMAPINFOHEADER
*bmih
,
200 CONST BITMAPINFO
*bmi
,
206 HBITMAP STDCALL
W32kCreateDIBSection(HDC hDC
,
207 CONST BITMAPINFO
*bmi
,
216 HBITMAP STDCALL
W32kCreateDiscardableBitmap(HDC hDC
,
220 /* FIXME: this probably should do something else */
221 return W32kCreateCompatibleBitmap(hDC
, Width
, Height
);
224 BOOL STDCALL
W32kExtFloodFill(HDC hDC
,
233 BOOL STDCALL
W32kFloodFill(HDC hDC
,
241 LONG STDCALL
W32kGetBitmapBits(HBITMAP hBitmap
,
248 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
254 /* If the bits vector is null, the function should return the read size */
257 return bmp
->bitmap
.bmWidthBytes
* bmp
->bitmap
.bmHeight
;
262 DPRINT ("(%ld): Negative number of bytes passed???\n", Count
);
266 /* Only get entire lines */
267 height
= Count
/ bmp
->bitmap
.bmWidthBytes
;
268 if (height
> bmp
->bitmap
.bmHeight
)
270 height
= bmp
->bitmap
.bmHeight
;
272 Count
= height
* bmp
->bitmap
.bmWidthBytes
;
275 DPRINT("Less then one entire line requested\n");
276 BITMAPOBJ_UnlockBitmap (hBitmap
);
280 DPRINT("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
281 hBitmap
, Count
, Bits
, bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
282 1 << bmp
->bitmap
.bmBitsPixel
, height
);
284 /* FIXME: Call DDI CopyBits here if available */
287 DPRINT("Calling device specific BitmapBits\n");
288 if(bmp
->DDBitmap
->funcs
->pBitmapBits
)
290 ret
= bmp
->DDBitmap
->funcs
->pBitmapBits(hbitmap
, bits
, count
,
295 ERR_(bitmap
)("BitmapBits == NULL??\n");
302 if(!bmp
->bitmap
.bmBits
)
304 DPRINT ("Bitmap is empty\n");
309 memcpy(Bits
, bmp
->bitmap
.bmBits
, Count
);
313 BITMAPOBJ_UnlockBitmap (hBitmap
);
318 BOOL STDCALL
W32kGetBitmapDimensionEx(HBITMAP hBitmap
,
323 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
329 *Dimension
= bmp
->size
;
330 BITMAPOBJ_UnlockBitmap (hBitmap
);
335 UINT STDCALL
W32kGetDIBColorTable(HDC hDC
,
343 INT STDCALL
W32kGetDIBits(HDC hDC
,
354 COLORREF STDCALL
W32kGetPixel(HDC hDC
,
361 BOOL STDCALL
W32kMaskBlt(HDC hDCDest
,
377 BOOL STDCALL
W32kPlgBlt(HDC hDCDest
,
391 LONG STDCALL
W32kSetBitmapBits(HBITMAP hBitmap
,
398 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
399 if (bmp
== NULL
|| Bits
== NULL
)
406 DPRINT ("(%ld): Negative number of bytes passed???\n", Bytes
);
410 /* Only get entire lines */
411 height
= Bytes
/ bmp
->bitmap
.bmWidthBytes
;
412 if (height
> bmp
->bitmap
.bmHeight
)
414 height
= bmp
->bitmap
.bmHeight
;
416 Bytes
= height
* bmp
->bitmap
.bmWidthBytes
;
417 DPRINT ("(%08x, bytes:%ld, bits:%p) %dx%d %d colors fetched height: %ld\n",
422 bmp
->bitmap
.bmHeight
,
423 1 << bmp
->bitmap
.bmBitsPixel
,
427 /* FIXME: call DDI specific function here if available */
430 DPRINT ("Calling device specific BitmapBits\n");
431 if (bmp
->DDBitmap
->funcs
->pBitmapBits
)
433 ret
= bmp
->DDBitmap
->funcs
->pBitmapBits(hBitmap
,
440 DPRINT ("BitmapBits == NULL??\n");
447 /* FIXME: Alloc enough for entire bitmap */
448 if (bmp
->bitmap
.bmBits
== NULL
)
450 bmp
->bitmap
.bmBits
= ExAllocatePool (PagedPool
, Bytes
);
452 if(!bmp
->bitmap
.bmBits
)
454 DPRINT ("Unable to allocate bit buffer\n");
459 memcpy(bmp
->bitmap
.bmBits
, Bits
, Bytes
);
463 BITMAPOBJ_UnlockBitmap (hBitmap
);
468 BOOL STDCALL
W32kSetBitmapDimensionEx(HBITMAP hBitmap
,
475 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
485 bmp
->size
.cx
= Width
;
486 bmp
->size
.cy
= Height
;
487 BITMAPOBJ_UnlockBitmap (hBitmap
);
492 UINT STDCALL
W32kSetDIBColorTable(HDC hDC
,
495 CONST RGBQUAD
*Colors
)
500 INT STDCALL
W32kSetDIBits(HDC hDC
,
505 CONST BITMAPINFO
*bmi
,
511 INT STDCALL
W32kSetDIBitsToDevice(HDC hDC
,
521 CONST BITMAPINFO
*bmi
,
527 COLORREF STDCALL
W32kSetPixel(HDC hDC
,
535 BOOL STDCALL
W32kSetPixelV(HDC hDC
,
543 BOOL STDCALL
W32kStretchBlt(HDC hDCDest
,
558 INT STDCALL
W32kStretchDIBits(HDC hDC
,
568 CONST BITMAPINFO
*BitsInfo
,
575 /* Internal Functions */
578 BITMAPOBJ_GetWidthBytes (INT bmWidth
, INT bpp
)
583 return 2 * ((bmWidth
+15) >> 4);
586 bmWidth
*= 3; /* fall through */
588 return bmWidth
+ (bmWidth
& 1);
598 return 2 * ((bmWidth
+3) >> 2);
607 HBITMAP
BITMAPOBJ_CopyBitmap(HBITMAP hBitmap
)
613 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
622 res
= W32kCreateBitmapIndirect(&bm
);
627 buf
= ExAllocatePool (NonPagedPool
, bm
.bmWidthBytes
* bm
.bmHeight
);
628 W32kGetBitmapBits (hBitmap
, bm
.bmWidthBytes
* bm
.bmHeight
, buf
);
629 W32kSetBitmapBits (res
, bm
.bmWidthBytes
* bm
.bmHeight
, buf
);
632 BITMAPOBJ_UnlockBitmap (hBitmap
);
637 /***********************************************************************
638 * DIB_GetDIBWidthBytes
640 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
641 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
642 * 11/16/1999 (RJJ) lifted from wine
644 int DIB_GetDIBWidthBytes(int width
, int depth
)
650 case 1: words
= (width
+ 31) / 32; break;
651 case 4: words
= (width
+ 7) / 8; break;
652 case 8: words
= (width
+ 3) / 4; break;
654 case 16: words
= (width
+ 1) / 2; break;
655 case 24: words
= (width
* 3 + 3)/4; break;
658 DPRINT("(%d): Unsupported depth\n", depth
);
666 /***********************************************************************
667 * DIB_GetDIBImageBytes
669 * Return the number of bytes used to hold the image in a DIB bitmap.
670 * 11/16/1999 (RJJ) lifted from wine
673 int DIB_GetDIBImageBytes (int width
, int height
, int depth
)
675 return DIB_GetDIBWidthBytes( width
, depth
) * (height
< 0 ? -height
: height
);
678 /***********************************************************************
681 * Return the size of the bitmap info structure including color table.
682 * 11/16/1999 (RJJ) lifted from wine
685 int DIB_BitmapInfoSize (const BITMAPINFO
* info
, WORD coloruse
)
689 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
691 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
692 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
693 return sizeof(BITMAPCOREHEADER
) + colors
*
694 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
696 else /* assume BITMAPINFOHEADER */
698 colors
= info
->bmiHeader
.biClrUsed
;
699 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
700 colors
= 1 << info
->bmiHeader
.biBitCount
;
701 return sizeof(BITMAPINFOHEADER
) + colors
*
702 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));