2 * $Id: dib.c,v 1.52 2004/06/22 20:08:17 gvg Exp $
4 * ReactOS W32 Subsystem
5 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 NtGdiSetDIBColorTable(HDC hDC
, UINT StartIndex
, UINT Entries
, CONST RGBQUAD
*Colors
)
29 if (!(dc
= DC_LockDc(hDC
))) return 0;
31 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
32 if (BitmapObj
== NULL
)
35 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
39 if (BitmapObj
->dib
== NULL
)
41 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
43 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
47 if (BitmapObj
->dib
->dsBmih
.biBitCount
<= 8 &&
48 StartIndex
< (1 << BitmapObj
->dib
->dsBmih
.biBitCount
))
50 if (StartIndex
+ Entries
> (1 << BitmapObj
->dib
->dsBmih
.biBitCount
))
51 Entries
= (1 << BitmapObj
->dib
->dsBmih
.biBitCount
) - StartIndex
;
53 MmCopyFromCaller(BitmapObj
->ColorMap
+ StartIndex
, Colors
, Entries
* sizeof(RGBQUAD
));
55 /* Rebuild the palette. */
56 NtGdiDeleteObject(dc
->w
.hPalette
);
57 dc
->w
.hPalette
= PALETTE_AllocPaletteIndexedRGB(1 << BitmapObj
->dib
->dsBmih
.biBitCount
,
63 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
70 NtGdiGetDIBColorTable(HDC hDC
, UINT StartIndex
, UINT Entries
, RGBQUAD
*Colors
)
75 if (!(dc
= DC_LockDc(hDC
))) return 0;
77 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
78 if (BitmapObj
== NULL
)
81 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
85 if (BitmapObj
->dib
== NULL
)
87 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
89 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
93 if (BitmapObj
->dib
->dsBmih
.biBitCount
<= 8 &&
94 StartIndex
< (1 << BitmapObj
->dib
->dsBmih
.biBitCount
))
96 if (StartIndex
+ Entries
> (1 << BitmapObj
->dib
->dsBmih
.biBitCount
))
97 Entries
= (1 << BitmapObj
->dib
->dsBmih
.biBitCount
) - StartIndex
;
99 MmCopyToCaller(Colors
, BitmapObj
->ColorMap
+ StartIndex
, Entries
* sizeof(RGBQUAD
));
104 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
110 // Converts a DIB to a device-dependent bitmap
118 CONST BITMAPINFO
*bmi
,
122 HBITMAP SourceBitmap
, DestBitmap
;
125 SURFOBJ
*DestSurf
, *SourceSurf
;
133 HPALETTE DDB_Palette
, DIB_Palette
;
134 ULONG DDB_Palette_Type
, DIB_Palette_Type
;
135 const BYTE
*vBits
= (const BYTE
*)Bits
;
136 INT scanDirection
= 1, DIBWidth
;
139 if (!(bitmap
= BITMAPOBJ_LockBitmap(hBitmap
)))
145 //if (ColorUse == DIB_PAL_COLORS)
146 // lpRGB = DIB_MapPaletteColors(hDC, bmi);
148 // lpRGB = &bmi->bmiColors[0];
150 // Create a temporary surface for the destination bitmap
151 DestBitmap
= BitmapToSurf(bitmap
, DC
->GDIDevice
);
153 DestSurf
= (SURFOBJ
*) AccessUserObject( (ULONG
)DestBitmap
);
154 DestGDI
= (PSURFGDI
) AccessInternalObjectFromUserObject( DestSurf
);
156 // Create source surface
157 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
158 SourceSize
.cy
= abs(bmi
->bmiHeader
.biHeight
);
160 // Determine width of DIB
161 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
163 // Determine DIB Vertical Orientation
164 if(bmi
->bmiHeader
.biHeight
> 0)
167 vBits
+= DIBWidth
* bmi
->bmiHeader
.biHeight
- DIBWidth
;
170 SourceBitmap
= EngCreateBitmap(SourceSize
,
171 DIBWidth
* scanDirection
,
172 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
175 SourceSurf
= (SURFOBJ
*)AccessUserObject((ULONG
)SourceBitmap
);
177 // Destination palette obtained from the hDC
178 hDCPalette
= PALETTE_LockPalette(DC
->DevInfo
->hpalDefault
);
179 if (NULL
== hDCPalette
)
181 EngDeleteSurface((HSURF
)SourceBitmap
);
182 EngDeleteSurface((HSURF
)DestBitmap
);
183 BITMAPOBJ_UnlockBitmap(hBitmap
);
184 SetLastWin32Error(ERROR_INVALID_HANDLE
);
187 DDB_Palette_Type
= hDCPalette
->Mode
;
188 DDB_Palette
= DC
->DevInfo
->hpalDefault
;
189 PALETTE_UnlockPalette(DC
->DevInfo
->hpalDefault
);
191 // Source palette obtained from the BITMAPINFO
192 DIB_Palette
= BuildDIBPalette ( (PBITMAPINFO
)bmi
, (PINT
)&DIB_Palette_Type
);
193 if (NULL
== DIB_Palette
)
195 EngDeleteSurface((HSURF
)SourceBitmap
);
196 EngDeleteSurface((HSURF
)DestBitmap
);
197 BITMAPOBJ_UnlockBitmap(hBitmap
);
198 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
202 // Determine XLATEOBJ for color translation
203 XlateObj
= IntEngCreateXlate(DDB_Palette_Type
, DIB_Palette_Type
, DDB_Palette
, DIB_Palette
);
204 if (NULL
== XlateObj
)
206 PALETTE_FreePalette(DIB_Palette
);
207 EngDeleteSurface((HSURF
)SourceBitmap
);
208 EngDeleteSurface((HSURF
)DestBitmap
);
209 BITMAPOBJ_UnlockBitmap(hBitmap
);
210 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
218 // Determine destination rectangle
221 DestRect
.right
= SourceSize
.cx
;
222 DestRect
.bottom
= SourceSize
.cy
;
224 copyBitsResult
= EngCopyBits(DestSurf
, SourceSurf
, NULL
, XlateObj
, &DestRect
, &ZeroPoint
);
226 // If it succeeded, return number of scanlines copies
227 if(copyBitsResult
== TRUE
)
229 result
= SourceSize
.cy
- 1;
233 EngDeleteXlate(XlateObj
);
234 PALETTE_FreePalette(DIB_Palette
);
235 EngDeleteSurface((HSURF
)SourceBitmap
);
236 EngDeleteSurface((HSURF
)DestBitmap
);
238 // if (ColorUse == DIB_PAL_COLORS)
239 // WinFree((LPSTR)lpRGB);
241 BITMAPOBJ_UnlockBitmap(hBitmap
);
246 // Converts a DIB to a device-dependent bitmap
254 CONST BITMAPINFO
*bmi
,
263 SetLastWin32Error(ERROR_INVALID_HANDLE
);
267 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
275 NtGdiSetDIBitsToDevice(
286 CONST BITMAPINFO
*bmi
,
293 // Converts a device-dependent bitmap to a DIB
295 INT STDCALL
NtGdiGetDIBits(HDC hDC
,
300 LPBITMAPINFO UnsafeInfo
,
303 INT STDCALL
NtGdiGetDIBits(
304 HDC hdc
, /* [in] Handle to device context */
305 HBITMAP hbitmap
, /* [in] Handle to bitmap */
306 UINT startscan
, /* [in] First scan line to set in dest bitmap */
307 UINT lines
, /* [in] Number of scan lines to copy */
308 LPVOID bits
, /* [out] Address of array for bitmap bits */
309 BITMAPINFO
* info
, /* [out] Address of structure with bitmap data */
310 UINT coloruse
) /* [in] RGB or palette index */
315 BITMAPCOREHEADER
*Core
;
316 PBITMAPOBJ BitmapObj
;
329 BitmapObj
= BITMAPOBJ_LockBitmap(hBitmap
);
330 if (NULL
== BitmapObj
)
332 SetLastWin32Error(ERROR_INVALID_HANDLE
);
336 RtlZeroMemory(&Info
, sizeof(BITMAPINFO
));
337 Status
= MmCopyFromCaller(&(Info
.bmiHeader
.biSize
),
338 &(UnsafeInfo
->bmiHeader
.biSize
),
340 if (! NT_SUCCESS(Status
))
342 SetLastNtError(Status
);
343 BITMAPOBJ_UnlockBitmap(hBitmap
);
347 /* If the bits are not requested, UnsafeInfo can point to either a
348 BITMAPINFOHEADER or a BITMAPCOREHEADER */
349 if (sizeof(BITMAPINFOHEADER
) != Info
.bmiHeader
.biSize
&&
350 (sizeof(BITMAPCOREHEADER
) != Info
.bmiHeader
.biSize
||
353 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
354 BITMAPOBJ_UnlockBitmap(hBitmap
);
358 Status
= MmCopyFromCaller(&(Info
.bmiHeader
),
359 &(UnsafeInfo
->bmiHeader
),
360 Info
.bmiHeader
.biSize
);
361 if (! NT_SUCCESS(Status
))
363 SetLastNtError(Status
);
364 BITMAPOBJ_UnlockBitmap(hBitmap
);
370 if (sizeof(BITMAPINFOHEADER
) == Info
.bmiHeader
.biSize
)
372 if (0 != Info
.bmiHeader
.biBitCount
)
374 DPRINT("NtGdiGetDIBits(): This operation isn't fully implemented yet.");
378 Info
.bmiHeader
.biWidth
= BitmapObj
->bitmap
.bmWidth
;
379 Info
.bmiHeader
.biHeight
= BitmapObj
->bitmap
.bmHeight
;
380 Info
.bmiHeader
.biPlanes
= BitmapObj
->bitmap
.bmPlanes
;
381 Info
.bmiHeader
.biBitCount
= BitmapObj
->bitmap
.bmBitsPixel
;
382 Info
.bmiHeader
.biCompression
= BI_RGB
;
383 Info
.bmiHeader
.biSizeImage
= BitmapObj
->bitmap
.bmHeight
* BitmapObj
->bitmap
.bmWidthBytes
;
387 Core
= (BITMAPCOREHEADER
*)(&Info
.bmiHeader
);
388 if (0 != Core
->bcBitCount
)
393 Core
->bcWidth
= BitmapObj
->bitmap
.bmWidth
;
394 Core
->bcHeight
= BitmapObj
->bitmap
.bmHeight
;
395 Core
->bcPlanes
= BitmapObj
->bitmap
.bmPlanes
;
396 Core
->bcBitCount
= BitmapObj
->bitmap
.bmBitsPixel
;
399 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, Info
.bmiHeader
.biSize
);
400 if (! NT_SUCCESS(Status
))
402 SetLastNtError(Status
);
403 BITMAPOBJ_UnlockBitmap(hBitmap
);
408 else if (0 == StartScan
&& Info
.bmiHeader
.biHeight
== (LONG
) (StartScan
+ ScanLines
) &&
409 Info
.bmiHeader
.biWidth
== BitmapObj
->bitmap
.bmWidth
&&
410 Info
.bmiHeader
.biHeight
== BitmapObj
->bitmap
.bmHeight
&&
411 Info
.bmiHeader
.biPlanes
== BitmapObj
->bitmap
.bmPlanes
&&
412 Info
.bmiHeader
.biBitCount
== BitmapObj
->bitmap
.bmBitsPixel
&&
413 8 < Info
.bmiHeader
.biBitCount
)
415 Info
.bmiHeader
.biSizeImage
= BitmapObj
->bitmap
.bmHeight
* BitmapObj
->bitmap
.bmWidthBytes
;
416 Status
= MmCopyToCaller(Bits
, BitmapObj
->bitmap
.bmBits
, Info
.bmiHeader
.biSizeImage
);
417 if (! NT_SUCCESS(Status
))
419 SetLastNtError(Status
);
420 BITMAPOBJ_UnlockBitmap(hBitmap
);
423 RtlZeroMemory(&InfoWithBitFields
, sizeof(InfoWithBitFields
));
424 RtlCopyMemory(&(InfoWithBitFields
.Info
), &Info
, sizeof(BITMAPINFO
));
425 if (BI_BITFIELDS
== Info
.bmiHeader
.biCompression
)
427 DCObj
= DC_LockDc(hDC
);
430 SetLastWin32Error(ERROR_INVALID_HANDLE
);
431 BITMAPOBJ_UnlockBitmap(hBitmap
);
434 PalGdi
= PALETTE_LockPalette(DCObj
->w
.hPalette
);
435 BitField
= (DWORD
*) ((char *) &InfoWithBitFields
+ InfoWithBitFields
.Info
.bmiHeader
.biSize
);
436 BitField
[0] = PalGdi
->RedMask
;
437 BitField
[1] = PalGdi
->GreenMask
;
438 BitField
[2] = PalGdi
->BlueMask
;
439 PALETTE_UnlockPalette(DCObj
->w
.hPalette
);
440 InfoSize
= InfoWithBitFields
.Info
.bmiHeader
.biSize
+ 3 * sizeof(DWORD
);
445 InfoSize
= Info
.bmiHeader
.biSize
;
447 Status
= MmCopyToCaller(UnsafeInfo
, &InfoWithBitFields
, InfoSize
);
448 if (! NT_SUCCESS(Status
))
450 SetLastNtError(Status
);
451 BITMAPOBJ_UnlockBitmap(hBitmap
);
460 BITMAPOBJ_UnlockBitmap(hBitmap
);
469 if (!(dc
= DC_LockDc( hdc
))) return 0;
470 if (!(bmp
= BITMAPOBJ_LockBitmap(hbitmap
)))
476 /* Transfer color info */
478 if (info
->bmiHeader
.biBitCount
<= 8 && info
->bmiHeader
.biBitCount
> 0 ) {
480 info
->bmiHeader
.biClrUsed
= 0;
482 /* If the bitmap object already has a dib section at the
483 same color depth then get the color map from it */
484 if (bmp
->dib
&& bmp
->dib
->dsBm
.bmBitsPixel
== info
->bmiHeader
.biBitCount
) {
485 NtGdiGetDIBColorTable(hdc
, 0, 1 << info
->bmiHeader
.biBitCount
, info
->bmiColors
);
488 if(info
->bmiHeader
.biBitCount
>= bmp
->bitmap
.bmBitsPixel
) {
489 /* Generate the color map from the selected palette */
490 PALETTEENTRY
* palEntry
;
492 if (!(palette
= PALETTE_LockPalette(dc
->w
.hPalette
))) {
494 BITMAPOBJ_UnlockBitmap( hbitmap
);
497 palEntry
= palette
->IndexedColors
;
498 for (i
= 0; i
< (1 << bmp
->bitmap
.bmBitsPixel
); i
++, palEntry
++) {
499 if (coloruse
== DIB_RGB_COLORS
) {
500 info
->bmiColors
[i
].rgbRed
= palEntry
->peRed
;
501 info
->bmiColors
[i
].rgbGreen
= palEntry
->peGreen
;
502 info
->bmiColors
[i
].rgbBlue
= palEntry
->peBlue
;
503 info
->bmiColors
[i
].rgbReserved
= 0;
505 else ((WORD
*)info
->bmiColors
)[i
] = (WORD
)i
;
507 PALETTE_UnlockPalette( dc
->w
.hPalette
);
509 switch (info
->bmiHeader
.biBitCount
) {
511 info
->bmiColors
[0].rgbRed
= info
->bmiColors
[0].rgbGreen
=
512 info
->bmiColors
[0].rgbBlue
= 0;
513 info
->bmiColors
[0].rgbReserved
= 0;
514 info
->bmiColors
[1].rgbRed
= info
->bmiColors
[1].rgbGreen
=
515 info
->bmiColors
[1].rgbBlue
= 0xff;
516 info
->bmiColors
[1].rgbReserved
= 0;
520 memcpy(info
->bmiColors
, COLOR_GetSystemPaletteTemplate(), NB_RESERVED_COLORS
* sizeof(PALETTEENTRY
));
528 memcpy(info
->bmiColors
, COLOR_GetSystemPaletteTemplate(),
529 10 * sizeof(RGBQUAD
));
530 memcpy(info
->bmiColors
+ 246, COLOR_GetSystemPaletteTemplate() + 10,
531 10 * sizeof(RGBQUAD
));
532 color
= info
->bmiColors
+ 10;
533 for(r
= 0; r
<= 5; r
++) /* FIXME */
534 for(g
= 0; g
<= 5; g
++)
535 for(b
= 0; b
<= 5; b
++) {
536 color
->rgbRed
= (r
* 0xff) / 5;
537 color
->rgbGreen
= (g
* 0xff) / 5;
538 color
->rgbBlue
= (b
* 0xff) / 5;
539 color
->rgbReserved
= 0;
550 /* If the bitmap object already have a dib section that contains image data, get the bits from it */
551 if(bmp
->dib
&& bmp
->dib
->dsBm
.bmBitsPixel
>= 15 && info
->bmiHeader
.biBitCount
>= 15)
553 /*FIXME: Only RGB dibs supported for now */
554 unsigned int srcwidth
= bmp
->dib
->dsBm
.bmWidth
, srcwidthb
= bmp
->dib
->dsBm
.bmWidthBytes
;
555 int dstwidthb
= DIB_GetDIBWidthBytes( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
);
556 LPBYTE dbits
= bits
, sbits
= (LPBYTE
) bmp
->dib
->dsBm
.bmBits
+ (startscan
* srcwidthb
);
559 if ((info
->bmiHeader
.biHeight
< 0) ^ (bmp
->dib
->dsBmih
.biHeight
< 0))
561 dbits
= (LPBYTE
)bits
+ (dstwidthb
* (lines
-1));
562 dstwidthb
= -dstwidthb
;
565 switch( info
->bmiHeader
.biBitCount
) {
568 case 16: /* 16 bpp dstDIB */
570 LPWORD dstbits
= (LPWORD
)dbits
;
571 WORD rmask
= 0x7c00, gmask
= 0x03e0, bmask
= 0x001f;
573 /* FIXME: BI_BITFIELDS not supported yet */
575 switch(bmp
->dib
->dsBm
.bmBitsPixel
) {
577 case 16: /* 16 bpp srcDIB -> 16 bpp dstDIB */
579 /* FIXME: BI_BITFIELDS not supported yet */
580 for (y
= 0; y
< lines
; y
++, dbits
+=dstwidthb
, sbits
+=srcwidthb
)
581 memcpy(dbits
, sbits
, srcwidthb
);
585 case 24: /* 24 bpp srcDIB -> 16 bpp dstDIB */
587 LPBYTE srcbits
= sbits
;
589 for( y
= 0; y
< lines
; y
++) {
590 for( x
= 0; x
< srcwidth
; x
++, srcbits
+= 3)
591 *dstbits
++ = ((srcbits
[0] >> 3) & bmask
) |
592 (((WORD
)srcbits
[1] << 2) & gmask
) |
593 (((WORD
)srcbits
[2] << 7) & rmask
);
595 dstbits
= (LPWORD
)(dbits
+=dstwidthb
);
596 srcbits
= (sbits
+= srcwidthb
);
601 case 32: /* 32 bpp srcDIB -> 16 bpp dstDIB */
603 LPDWORD srcbits
= (LPDWORD
)sbits
;
606 for( y
= 0; y
< lines
; y
++) {
607 for( x
= 0; x
< srcwidth
; x
++ ) {
609 *dstbits
++ = (WORD
)(((val
>> 3) & bmask
) | ((val
>> 6) & gmask
) |
610 ((val
>> 9) & rmask
));
612 dstbits
= (LPWORD
)(dbits
+=dstwidthb
);
613 srcbits
= (LPDWORD
)(sbits
+=srcwidthb
);
618 default: /* ? bit bmp -> 16 bit DIB */
619 DPRINT1("FIXME: 15/16 bit DIB %d bit bitmap\n",
620 bmp
->bitmap
.bmBitsPixel
);
626 case 24: /* 24 bpp dstDIB */
628 LPBYTE dstbits
= dbits
;
630 switch(bmp
->dib
->dsBm
.bmBitsPixel
) {
632 case 16: /* 16 bpp srcDIB -> 24 bpp dstDIB */
634 LPWORD srcbits
= (LPWORD
)sbits
;
637 /* FIXME: BI_BITFIELDS not supported yet */
638 for( y
= 0; y
< lines
; y
++) {
639 for( x
= 0; x
< srcwidth
; x
++ ) {
641 *dstbits
++ = (BYTE
)(((val
<< 3) & 0xf8) | ((val
>> 2) & 0x07));
642 *dstbits
++ = (BYTE
)(((val
>> 2) & 0xf8) | ((val
>> 7) & 0x07));
643 *dstbits
++ = (BYTE
)(((val
>> 7) & 0xf8) | ((val
>> 12) & 0x07));
645 dstbits
= (LPBYTE
)(dbits
+=dstwidthb
);
646 srcbits
= (LPWORD
)(sbits
+=srcwidthb
);
651 case 24: /* 24 bpp srcDIB -> 24 bpp dstDIB */
653 for (y
= 0; y
< lines
; y
++, dbits
+=dstwidthb
, sbits
+=srcwidthb
)
654 memcpy(dbits
, sbits
, srcwidthb
);
658 case 32: /* 32 bpp srcDIB -> 24 bpp dstDIB */
660 LPBYTE srcbits
= (LPBYTE
)sbits
;
662 for( y
= 0; y
< lines
; y
++) {
663 for( x
= 0; x
< srcwidth
; x
++, srcbits
++ ) {
664 *dstbits
++ = *srcbits
++;
665 *dstbits
++ = *srcbits
++;
666 *dstbits
++ = *srcbits
++;
668 dstbits
=(LPBYTE
)(dbits
+=dstwidthb
);
669 srcbits
= (LPBYTE
)(sbits
+=srcwidthb
);
674 default: /* ? bit bmp -> 24 bit DIB */
675 DPRINT1("FIXME: 24 bit DIB %d bit bitmap\n",
676 bmp
->bitmap
.bmBitsPixel
);
682 case 32: /* 32 bpp dstDIB */
684 LPDWORD dstbits
= (LPDWORD
)dbits
;
686 /* FIXME: BI_BITFIELDS not supported yet */
688 switch(bmp
->dib
->dsBm
.bmBitsPixel
) {
689 case 16: /* 16 bpp srcDIB -> 32 bpp dstDIB */
691 LPWORD srcbits
= (LPWORD
)sbits
;
694 /* FIXME: BI_BITFIELDS not supported yet */
695 for( y
= 0; y
< lines
; y
++) {
696 for( x
= 0; x
< srcwidth
; x
++ ) {
697 val
= (DWORD
)*srcbits
++;
698 *dstbits
++ = ((val
<< 3) & 0xf8) | ((val
>> 2) & 0x07) |
699 ((val
<< 6) & 0xf800) | ((val
<< 1) & 0x0700) |
700 ((val
<< 9) & 0xf80000) | ((val
<< 4) & 0x070000);
702 dstbits
=(LPDWORD
)(dbits
+=dstwidthb
);
703 srcbits
=(LPWORD
)(sbits
+=srcwidthb
);
708 case 24: /* 24 bpp srcDIB -> 32 bpp dstDIB */
710 LPBYTE srcbits
= sbits
;
712 for( y
= 0; y
< lines
; y
++) {
713 for( x
= 0; x
< srcwidth
; x
++, srcbits
+=3 )
714 *dstbits
++ = ((DWORD
)*srcbits
) & 0x00ffffff;
715 dstbits
=(LPDWORD
)(dbits
+=dstwidthb
);
716 srcbits
=(sbits
+=srcwidthb
);
721 case 32: /* 32 bpp srcDIB -> 16 bpp dstDIB */
723 /* FIXME: BI_BITFIELDS not supported yet */
724 for (y
= 0; y
< lines
; y
++, dbits
+=dstwidthb
, sbits
+=srcwidthb
)
725 memcpy(dbits
, sbits
, srcwidthb
);
729 default: /* ? bit bmp -> 32 bit DIB */
730 DPRINT1("FIXME: 32 bit DIB %d bit bitmap\n",
731 bmp
->bitmap
.bmBitsPixel
);
737 default: /* ? bit DIB */
738 DPRINT1("FIXME: Unsupported DIB depth %d\n", info
->bmiHeader
.biBitCount
);
742 /* Otherwise, get bits from the XImage */
748 else if( info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
) )
750 /* fill in struct members */
752 if( info
->bmiHeader
.biBitCount
== 0)
754 info
->bmiHeader
.biWidth
= bmp
->bitmap
.bmWidth
;
755 info
->bmiHeader
.biHeight
= bmp
->bitmap
.bmHeight
;
756 info
->bmiHeader
.biPlanes
= 1;
757 info
->bmiHeader
.biBitCount
= bmp
->bitmap
.bmBitsPixel
;
758 info
->bmiHeader
.biSizeImage
=
759 DIB_GetDIBImageBytes( bmp
->bitmap
.bmWidth
,
760 bmp
->bitmap
.bmHeight
,
761 bmp
->bitmap
.bmBitsPixel
);
762 info
->bmiHeader
.biCompression
= 0;
766 info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(
767 info
->bmiHeader
.biWidth
,
768 info
->bmiHeader
.biHeight
,
769 info
->bmiHeader
.biBitCount
);
774 BITMAPOBJ_UnlockBitmap( hbitmap
);
780 INT STDCALL
NtGdiStretchDIBits(HDC hDC
,
790 CONST BITMAPINFO
*BitsInfo
,
794 HBITMAP hBitmap
, hOldBitmap
;
797 if (!Bits
|| !BitsInfo
)
799 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
803 hdcMem
= NtGdiCreateCompatableDC(hDC
);
804 hBitmap
= NtGdiCreateCompatibleBitmap(hDC
, BitsInfo
->bmiHeader
.biWidth
,
805 BitsInfo
->bmiHeader
.biHeight
);
806 hOldBitmap
= NtGdiSelectObject(hdcMem
, hBitmap
);
808 if (BitsInfo
->bmiHeader
.biCompression
== BI_RLE4
||
809 BitsInfo
->bmiHeader
.biCompression
== BI_RLE8
)
811 /* copy existing bitmap from destination dc */
812 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
813 NtGdiBitBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
814 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, ROP
);
816 NtGdiStretchBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
817 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
821 NtGdiSetDIBits(hdcMem
, hBitmap
, 0, BitsInfo
->bmiHeader
.biHeight
, Bits
,
824 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
825 left (negative biHeight) */
826 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
827 NtGdiBitBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
828 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
831 NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
832 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
833 SrcWidth
, SrcHeight
, ROP
);
835 NtGdiSelectObject(hdcMem
, hOldBitmap
);
836 NtGdiDeleteDC(hdcMem
);
837 NtGdiDeleteObject(hBitmap
);
842 LONG STDCALL
NtGdiGetBitmapBits(HBITMAP hBitmap
,
849 bmp
= BITMAPOBJ_LockBitmap (hBitmap
);
855 /* If the bits vector is null, the function should return the read size */
858 return bmp
->bitmap
.bmWidthBytes
* bmp
->bitmap
.bmHeight
;
863 DPRINT ("(%ld): Negative number of bytes passed???\n", Count
);
867 /* Only get entire lines */
868 height
= Count
/ bmp
->bitmap
.bmWidthBytes
;
869 if (height
> bmp
->bitmap
.bmHeight
)
871 height
= bmp
->bitmap
.bmHeight
;
873 Count
= height
* bmp
->bitmap
.bmWidthBytes
;
876 DPRINT("Less then one entire line requested\n");
880 DPRINT("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
881 hBitmap
, Count
, Bits
, bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
882 1 << bmp
->bitmap
.bmBitsPixel
, height
);
884 /* FIXME: Call DDI CopyBits here if available */
887 DPRINT("Calling device specific BitmapBits\n");
888 if(bmp
->DDBitmap
->funcs
->pBitmapBits
)
890 ret
= bmp
->DDBitmap
->funcs
->pBitmapBits(hbitmap
, bits
, count
,
895 ERR_(bitmap
)("BitmapBits == NULL??\n");
902 if(!bmp
->bitmap
.bmBits
)
904 DPRINT ("Bitmap is empty\n");
909 memcpy(Bits
, bmp
->bitmap
.bmBits
, Count
);
917 static HBITMAP FASTCALL
918 IntCreateDIBitmap(PDC Dc
, const BITMAPINFOHEADER
*header
,
919 DWORD init
, LPCVOID bits
, const BITMAPINFO
*data
,
929 if (DIB_GetBitmapInfo( header
, &width
, &height
, &bpp
, &compr
) == -1) return 0;
930 if (height
< 0) height
= -height
;
932 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
933 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
935 if (bpp
!= 1) fColor
= TRUE
;
936 else if ((coloruse
!= DIB_RGB_COLORS
) ||
937 (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
940 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
942 RGBQUAD
*rgb
= data
->bmiColors
;
943 DWORD col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
945 // Check if the first color of the colormap is black
946 if ((col
== RGB(0, 0, 0)))
949 col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
951 // If the second color is white, create a monochrome bitmap
952 fColor
= (col
!= RGB(0xff,0xff,0xff));
956 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
958 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
959 DWORD col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
961 if ((col
== RGB(0,0,0)))
964 col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
965 fColor
= (col
!= RGB(0xff,0xff,0xff));
971 DPRINT("(%ld): wrong size for data\n", data
->bmiHeader
.biSize
);
976 // Now create the bitmap
979 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
983 handle
= NtGdiCreateBitmap( width
, height
, 1, 1, NULL
);
986 if (NULL
!= handle
&& CBM_INIT
== init
)
988 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
994 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
995 // The DDB that is created will be whatever bit depth your reference DC is
996 HBITMAP STDCALL
NtGdiCreateDIBitmap(HDC hDc
, const BITMAPINFOHEADER
*Header
,
997 DWORD Init
, LPCVOID Bits
, const BITMAPINFO
*Data
,
1003 Dc
= DC_LockDc(hDc
);
1006 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1010 Bmp
= IntCreateDIBitmap(Dc
, Header
, Init
, Bits
, Data
, ColorUse
);
1017 HBITMAP STDCALL
NtGdiCreateDIBSection(HDC hDC
,
1018 CONST BITMAPINFO
*bmi
,
1024 HBITMAP hbitmap
= 0;
1026 BOOL bDesktopDC
= FALSE
;
1028 // If the reference hdc is null, take the desktop dc
1031 hDC
= NtGdiCreateCompatableDC(0);
1035 if ((dc
= DC_LockDc(hDC
)))
1037 hbitmap
= DIB_CreateDIBSection ( dc
, (BITMAPINFO
*)bmi
, Usage
, Bits
,
1038 hSection
, dwOffset
, 0);
1049 DIB_CreateDIBSection(
1050 PDC dc
, BITMAPINFO
*bmi
, UINT usage
,
1051 LPVOID
*bits
, HANDLE section
,
1052 DWORD offset
, DWORD ovr_pitch
)
1055 BITMAPOBJ
*bmp
= NULL
;
1056 DIBSECTION
*dib
= NULL
;
1058 // Fill BITMAP32 structure with DIB data
1059 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1065 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1066 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1067 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1069 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1071 bm
.bmWidth
= bi
->biWidth
;
1072 bm
.bmHeight
= effHeight
;
1073 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1075 bm
.bmPlanes
= bi
->biPlanes
;
1076 bm
.bmBitsPixel
= bi
->biBitCount
;
1079 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1080 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1081 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1082 ? bi
->biSizeImage
: (ULONG
) (bm
.bmWidthBytes
* effHeight
);
1085 /* bm.bmBits = MapViewOfFile(section, FILE_MAP_ALL_ACCESS,
1086 0L, offset, totalSize); */
1087 DbgPrint("DIB_CreateDIBSection: Cannot yet handle section DIBs\n");
1088 else if (ovr_pitch
&& offset
)
1089 bm
.bmBits
= (LPVOID
) offset
;
1092 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1095 /* bm.bmBits = ExAllocatePool(PagedPool, totalSize); */
1097 if(usage
== DIB_PAL_COLORS
)
1098 memcpy(bmi
->bmiColors
, (UINT
*)DIB_MapPaletteColors(dc
, bmi
), sizeof(UINT
*));
1100 // Allocate Memory for DIB and fill structure
1103 dib
= ExAllocatePoolWithTag(PagedPool
, sizeof(DIBSECTION
), TAG_DIB
);
1104 RtlZeroMemory(dib
, sizeof(DIBSECTION
));
1111 dib
->dsBmih
.biSizeImage
= totalSize
;
1113 /* Set dsBitfields values */
1114 if ( usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1116 dib
->dsBitfields
[0] = dib
->dsBitfields
[1] = dib
->dsBitfields
[2] = 0;
1118 else switch(bi
->biBitCount
)
1121 dib
->dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)bmi
->bmiColors
: 0x7c00;
1122 dib
->dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)bmi
->bmiColors
+ 1) : 0x03e0;
1123 dib
->dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)bmi
->bmiColors
+ 2) : 0x001f; break;
1126 dib
->dsBitfields
[0] = 0xff;
1127 dib
->dsBitfields
[1] = 0xff00;
1128 dib
->dsBitfields
[2] = 0xff0000;
1132 dib
->dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)bmi
->bmiColors
: 0xff;
1133 dib
->dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)bmi
->bmiColors
+ 1) : 0xff00;
1134 dib
->dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)bmi
->bmiColors
+ 2) : 0xff0000;
1137 dib
->dshSection
= section
;
1138 dib
->dsOffset
= offset
;
1141 // Create Device Dependent Bitmap and add DIB pointer
1144 res
= IntCreateDIBitmap(dc
, bi
, 0, NULL
, bmi
, usage
);
1149 bmp
= BITMAPOBJ_LockBitmap(res
);
1152 NtGdiDeleteObject(bmp
);
1155 bmp
->dib
= (DIBSECTION
*) dib
;
1156 /* Install user-mode bits instead of kernel-mode bits */
1157 ExFreePool(bmp
->bitmap
.bmBits
);
1158 bmp
->bitmap
.bmBits
= bm
.bmBits
;
1160 /* WINE NOTE: WINE makes use of a colormap, which is a color translation table between the DIB and the X physical
1161 device. Obviously, this is left out of the ReactOS implementation. Instead, we call
1162 NtGdiSetDIBColorTable. */
1163 if(bi
->biBitCount
== 1) { Entries
= 2; } else
1164 if(bi
->biBitCount
== 4) { Entries
= 16; } else
1165 if(bi
->biBitCount
== 8) { Entries
= 256; }
1167 bmp
->ColorMap
= ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
)*Entries
, TAG_COLORMAP
);
1168 RtlCopyMemory(bmp
->ColorMap
, bmi
->bmiColors
, sizeof(RGBQUAD
)*Entries
);
1171 // Clean up in case of errors
1172 if (!res
|| !bmp
|| !dib
|| !bm
.bmBits
)
1174 DPRINT("got an error res=%08x, bmp=%p, dib=%p, bm.bmBits=%p\n", res
, bmp
, dib
, bm
.bmBits
);
1178 UnmapViewOfFile(bm.bmBits), bm.bmBits = NULL;
1180 VirtualFree(bm.bmBits, 0L, MEM_RELEASE), bm.bmBits = NULL;
1183 if (dib
) { ExFreePool(dib
); dib
= NULL
; }
1184 if (bmp
) { bmp
= NULL
; }
1185 if (res
) { BITMAPOBJ_FreeBitmap(res
); res
= 0; }
1190 BITMAPOBJ_UnlockBitmap(res
);
1193 // Return BITMAP handle and storage location
1194 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1202 /***********************************************************************
1203 * DIB_GetDIBWidthBytes
1205 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1206 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1207 * 11/16/1999 (RJJ) lifted from wine
1209 INT FASTCALL
DIB_GetDIBWidthBytes (INT width
, INT depth
)
1215 case 1: words
= (width
+ 31) >> 5; break;
1216 case 4: words
= (width
+ 7) >> 3; break;
1217 case 8: words
= (width
+ 3) >> 2; break;
1219 case 16: words
= (width
+ 1) >> 1; break;
1220 case 24: words
= (width
* 3 + 3) >> 2; break;
1223 DPRINT("(%d): Unsupported depth\n", depth
);
1231 /***********************************************************************
1232 * DIB_GetDIBImageBytes
1234 * Return the number of bytes used to hold the image in a DIB bitmap.
1235 * 11/16/1999 (RJJ) lifted from wine
1238 INT STDCALL
DIB_GetDIBImageBytes (INT width
, INT height
, INT depth
)
1240 return DIB_GetDIBWidthBytes( width
, depth
) * (height
< 0 ? -height
: height
);
1243 /***********************************************************************
1244 * DIB_BitmapInfoSize
1246 * Return the size of the bitmap info structure including color table.
1247 * 11/16/1999 (RJJ) lifted from wine
1250 INT FASTCALL
DIB_BitmapInfoSize (const BITMAPINFO
* info
, WORD coloruse
)
1254 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1256 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1257 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1258 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1260 else /* assume BITMAPINFOHEADER */
1262 colors
= info
->bmiHeader
.biClrUsed
;
1263 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1264 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1268 INT STDCALL
DIB_GetBitmapInfo (const BITMAPINFOHEADER
*header
,
1274 if (header
->biSize
== sizeof(BITMAPINFOHEADER
))
1276 *width
= header
->biWidth
;
1277 *height
= header
->biHeight
;
1278 *bpp
= header
->biBitCount
;
1279 *compr
= header
->biCompression
;
1282 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
1284 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)header
;
1285 *width
= core
->bcWidth
;
1286 *height
= core
->bcHeight
;
1287 *bpp
= core
->bcBitCount
;
1291 DPRINT("(%ld): wrong size for header\n", header
->biSize
);
1295 // Converts a Device Independent Bitmap (DIB) to a Device Dependant Bitmap (DDB)
1296 // The specified Device Context (DC) defines what the DIB should be converted to
1297 PBITMAPOBJ FASTCALL
DIBtoDDB(HGLOBAL hPackedDIB
, HDC hdc
) // FIXME: This should be removed. All references to this function should
1298 // change to NtGdiSetDIBits
1301 PBITMAPOBJ pBmp
= NULL
;
1303 LPBYTE pbits
= NULL
;
1305 // Get a pointer to the packed DIB's data
1306 // pPackedDIB = (LPBYTE)GlobalLock(hPackedDIB);
1309 pbits
= (LPBYTE
)(dib
+ DIB_BitmapInfoSize((BITMAPINFO
*)&dib
->dsBmih
, DIB_RGB_COLORS
));
1311 // Create a DDB from the DIB
1312 hBmp
= NtGdiCreateDIBitmap ( hdc
, &dib
->dsBmih
, CBM_INIT
,
1313 (LPVOID
)pbits
, (BITMAPINFO
*)&dib
->dsBmih
, DIB_RGB_COLORS
);
1315 // GlobalUnlock(hPackedDIB);
1317 // Retrieve the internal Pixmap from the DDB
1318 pBmp
= BITMAPOBJ_LockBitmap(hBmp
);
1324 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1331 palGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1335 // RELEASEDCINFO(hDC);
1339 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1340 if (lpbmi
->bmiHeader
.biClrUsed
)
1342 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1345 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1346 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1348 for (i
= 0; i
< nNumColors
; i
++)
1350 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1351 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1352 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1355 // RELEASEDCINFO(hDC);
1356 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1361 PPALETTEENTRY STDCALL
1362 DIBColorTableToPaletteEntries (
1363 PPALETTEENTRY palEntries
,
1364 const RGBQUAD
*DIBColorTable
,
1370 for (i
= 0; i
< ColorCount
; i
++)
1372 palEntries
->peRed
= DIBColorTable
->rgbRed
;
1373 palEntries
->peGreen
= DIBColorTable
->rgbGreen
;
1374 palEntries
->peBlue
= DIBColorTable
->rgbBlue
;
1383 BuildDIBPalette (PBITMAPINFO bmi
, PINT paletteType
)
1387 PALETTEENTRY
*palEntries
= NULL
;
1390 // Determine Bits Per Pixel
1391 bits
= bmi
->bmiHeader
.biBitCount
;
1393 // Determine paletteType from Bits Per Pixel
1396 *paletteType
= PAL_INDEXED
;
1400 *paletteType
= PAL_BITFIELDS
;
1404 *paletteType
= PAL_BGR
;
1407 if (bmi
->bmiHeader
.biClrUsed
== 0)
1409 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1413 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1416 if (PAL_INDEXED
== *paletteType
)
1418 palEntries
= ExAllocatePoolWithTag(PagedPool
, sizeof(PALETTEENTRY
)*ColorCount
, TAG_COLORMAP
);
1419 DIBColorTableToPaletteEntries(palEntries
, bmi
->bmiColors
, ColorCount
);
1421 hPal
= PALETTE_AllocPalette( *paletteType
, ColorCount
, (ULONG
*)palEntries
, 0, 0, 0 );
1422 if (NULL
!= palEntries
)
1424 ExFreePool(palEntries
);