3 #undef WIN32_LEAN_AND_MEAN
6 #include <win32k/bitmaps.h>
7 #include <win32k/debug.h>
10 #include <internal/debug.h>
12 BOOL
W32kBitBlt(HDC hDCDest
,
25 HBITMAP
W32kCreateBitmap(INT Width
,
34 Planes
= (BYTE
) Planes
;
35 BitsPerPel
= (BYTE
) BitsPerPel
;
37 /* Check parameters */
38 if (!Height
|| !Width
)
56 /* Create the BITMAPOBJ */
57 bmp
= BITMAPOBJ_AllocBitmap ();
63 DPRINT("%dx%d, %d colors returning %08x\n", Width
, Height
,
64 1 << (Planes
* BitsPerPel
), bmp
);
68 bmp
->bitmap
.bmType
= 0;
69 bmp
->bitmap
.bmWidth
= Width
;
70 bmp
->bitmap
.bmHeight
= Height
;
71 bmp
->bitmap
.bmPlanes
= Planes
;
72 bmp
->bitmap
.bmBitsPixel
= BitsPerPel
;
73 bmp
->bitmap
.bmWidthBytes
= BITMAPOBJ_GetWidthBytes (Width
, BitsPerPel
);
74 bmp
->bitmap
.bmBits
= NULL
;
77 hBitmap
= BITMAPOBJ_PtrToHandle (bmp
);
78 if (Bits
) /* Set bitmap bits */
80 W32kSetBitmapBits(hBitmap
,
81 Height
* bmp
->bitmap
.bmWidthBytes
,
84 BITMAPOBJ_UnlockBitmap (hBitmap
);
89 HBITMAP
W32kCreateCompatibleBitmap(HDC hDC
,
97 DPRINT("(%04x,%d,%d) = \n", hDC
, Width
, Height
);
98 dc
= DC_PtrToHandle (hDC
);
103 if ((Width
>= 0x10000) || (Height
>= 0x10000))
105 DPRINT("got bad width %d or height %d, please look for reason\n",
110 /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
111 if (!Width
|| !Height
)
113 hbmpRet
= W32kCreateBitmap (1, 1, 1, 1, NULL
);
117 hbmpRet
= W32kCreateBitmap (Width
,
124 DPRINT ("\t\t%04x\n", hbmpRet
);
130 HBITMAP
W32kCreateBitmapIndirect(CONST BITMAP
*BM
)
132 return W32kCreateBitmap (BM
->bmWidth
,
139 HBITMAP
W32kCreateDIBitmap(HDC hDC
,
140 CONST BITMAPINFOHEADER
*bmih
,
143 CONST BITMAPINFO
*bmi
,
149 HBITMAP
W32kCreateDIBSection(HDC hDC
,
150 CONST BITMAPINFO
*bmi
,
159 HBITMAP
W32kCreateDiscardableBitmap(HDC hDC
,
163 /* FIXME: this probably should do something else */
164 return W32kCreateCompatibleBitmap(hDC
, Width
, Height
);
167 BOOL
W32kExtFloodFill(HDC hDC
,
176 BOOL
W32kFloodFill(HDC hDC
,
184 LONG
W32kGetBitmapBits(HBITMAP hBitmap
,
191 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
197 /* If the bits vector is null, the function should return the read size */
200 return bmp
->bitmap
.bmWidthBytes
* bmp
->bitmap
.bmHeight
;
205 DPRINT ("(%ld): Negative number of bytes passed???\n", Count
);
209 /* Only get entire lines */
210 height
= Count
/ bmp
->bitmap
.bmWidthBytes
;
211 if (height
> bmp
->bitmap
.bmHeight
)
213 height
= bmp
->bitmap
.bmHeight
;
215 Count
= height
* bmp
->bitmap
.bmWidthBytes
;
218 DPRINT("Less then one entire line requested\n");
219 BITMAPOBJ_UnlockBitmap (hBitmap
);
223 DPRINT("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
224 hBitmap
, Count
, Bits
, bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
225 1 << bmp
->bitmap
.bmBitsPixel
, height
);
227 /* FIXME: Call DDI CopyBits here if available */
230 DPRINT("Calling device specific BitmapBits\n");
231 if(bmp
->DDBitmap
->funcs
->pBitmapBits
)
233 ret
= bmp
->DDBitmap
->funcs
->pBitmapBits(hbitmap
, bits
, count
,
238 ERR_(bitmap
)("BitmapBits == NULL??\n");
245 if(!bmp
->bitmap
.bmBits
)
247 DPRINT ("Bitmap is empty\n");
252 memcpy(Bits
, bmp
->bitmap
.bmBits
, Count
);
256 BITMAPOBJ_UnlockBitmap (hBitmap
);
261 BOOL
W32kGetBitmapDimensionEx(HBITMAP hBitmap
,
266 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
272 *Dimension
= bmp
->size
;
273 BITMAPOBJ_UnlockBitmap (hBitmap
);
278 UINT
W32kGetDIBColorTable(HDC hDC
,
286 INT
W32kGetDIBits(HDC hDC
,
297 COLORREF
W32kGetPixel(HDC hDC
,
304 BOOL
W32kMaskBlt(HDC hDCDest
,
320 BOOL
W32kPlgBlt(HDC hDCDest
,
334 LONG
W32kSetBitmapBits(HBITMAP hBitmap
,
341 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
342 if (bmp
== NULL
|| Bits
== NULL
)
349 DPRINT ("(%ld): Negative number of bytes passed???\n", Bytes
);
353 /* Only get entire lines */
354 height
= Bytes
/ bmp
->bitmap
.bmWidthBytes
;
355 if (height
> bmp
->bitmap
.bmHeight
)
357 height
= bmp
->bitmap
.bmHeight
;
359 Bytes
= height
* bmp
->bitmap
.bmWidthBytes
;
360 DPRINT ("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
365 bmp
->bitmap
.bmHeight
,
366 1 << bmp
->bitmap
.bmBitsPixel
,
370 /* FIXME: call DDI specific function here if available */
373 DPRINT ("Calling device specific BitmapBits\n");
374 if (bmp
->DDBitmap
->funcs
->pBitmapBits
)
376 ret
= bmp
->DDBitmap
->funcs
->pBitmapBits(hBitmap
,
383 DPRINT ("BitmapBits == NULL??\n");
390 /* FIXME: Alloc enough for entire bitmap */
391 if (bmp
->bitmap
.bmBits
== NULL
)
393 bmp
->bitmap
.bmBits
= ExAllocatePool (NonPagedPool
, Bytes
);
395 if(!bmp
->bitmap
.bmBits
)
397 DPRINT ("Unable to allocate bit buffer\n");
402 memcpy(bmp
->bitmap
.bmBits
, Bits
, Bytes
);
406 BITMAPOBJ_UnlockBitmap (hBitmap
);
411 BOOL
W32kSetBitmapDimensionEx(HBITMAP hBitmap
,
418 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
428 bmp
->size
.cx
= Width
;
429 bmp
->size
.cy
= Height
;
430 BITMAPOBJ_UnlockBitmap (hBitmap
);
435 UINT
W32kSetDIBColorTable(HDC hDC
,
438 CONST RGBQUAD
*Colors
)
443 INT
W32kSetDIBits(HDC hDC
,
448 CONST BITMAPINFO
*bmi
,
454 INT
W32kSetDIBitsToDevice(HDC hDC
,
464 CONST BITMAPINFO
*bmi
,
470 COLORREF
W32kSetPixel(HDC hDC
,
478 BOOL
W32kSetPixelV(HDC hDC
,
486 BOOL
W32kStretchBlt(HDC hDCDest
,
501 INT
W32kStretchDIBits(HDC hDC
,
511 CONST BITMAPINFO
*BitsInfo
,
518 /* Internal Functions */
521 BITMAPOBJ_GetWidthBytes (INT bmWidth
, INT bpp
)
526 return 2 * ((bmWidth
+15) >> 4);
529 bmWidth
*= 3; /* fall through */
531 return bmWidth
+ (bmWidth
& 1);
541 return 2 * ((bmWidth
+3) >> 2);
550 HBITMAP
BITMAPOBJ_CopyBitmap(HBITMAP hBitmap
)
556 bmp
= BITMAPOBJ_HandleToPtr (hBitmap
);
565 res
= W32kCreateBitmapIndirect(&bm
);
570 buf
= ExAllocatePool (NonPagedPool
, bm
.bmWidthBytes
* bm
.bmHeight
);
571 W32kGetBitmapBits (hBitmap
, bm
.bmWidthBytes
* bm
.bmHeight
, buf
);
572 W32kSetBitmapBits (res
, bm
.bmWidthBytes
* bm
.bmHeight
, buf
);
575 BITMAPOBJ_UnlockBitmap (hBitmap
);
580 /***********************************************************************
581 * DIB_GetDIBWidthBytes
583 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
584 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
585 * 11/16/1999 (RJJ) lifted from wine
587 int DIB_GetDIBWidthBytes(int width
, int depth
)
593 case 1: words
= (width
+ 31) / 32; break;
594 case 4: words
= (width
+ 7) / 8; break;
595 case 8: words
= (width
+ 3) / 4; break;
597 case 16: words
= (width
+ 1) / 2; break;
598 case 24: words
= (width
* 3 + 3)/4; break;
601 DPRINT("(%d): Unsupported depth\n", depth
);
609 /***********************************************************************
610 * DIB_GetDIBImageBytes
612 * Return the number of bytes used to hold the image in a DIB bitmap.
613 * 11/16/1999 (RJJ) lifted from wine
616 int DIB_GetDIBImageBytes (int width
, int height
, int depth
)
618 return DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
621 /***********************************************************************
624 * Return the size of the bitmap info structure including color table.
625 * 11/16/1999 (RJJ) lifted from wine
628 int DIB_BitmapInfoSize (const BITMAPINFO
* info
, WORD coloruse
)
632 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
634 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
635 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
636 return sizeof(BITMAPCOREHEADER
) + colors
*
637 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
639 else /* assume BITMAPINFOHEADER */
641 colors
= info
->bmiHeader
.biClrUsed
;
642 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
643 colors
= 1 << info
->bmiHeader
.biBitCount
;
644 return sizeof(BITMAPINFOHEADER
) + colors
*
645 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));