2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 static const RGBQUAD EGAColorsQuads
[16] = {
26 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
27 { 0x00, 0x00, 0x00, 0x00 },
28 { 0x00, 0x00, 0x80, 0x00 },
29 { 0x00, 0x80, 0x00, 0x00 },
30 { 0x00, 0x80, 0x80, 0x00 },
31 { 0x80, 0x00, 0x00, 0x00 },
32 { 0x80, 0x00, 0x80, 0x00 },
33 { 0x80, 0x80, 0x00, 0x00 },
34 { 0x80, 0x80, 0x80, 0x00 },
35 { 0xc0, 0xc0, 0xc0, 0x00 },
36 { 0x00, 0x00, 0xff, 0x00 },
37 { 0x00, 0xff, 0x00, 0x00 },
38 { 0x00, 0xff, 0xff, 0x00 },
39 { 0xff, 0x00, 0x00, 0x00 },
40 { 0xff, 0x00, 0xff, 0x00 },
41 { 0xff, 0xff, 0x00, 0x00 },
42 { 0xff, 0xff, 0xff, 0x00 }
45 static const RGBTRIPLE EGAColorsTriples
[16] = {
46 /* rgbBlue, rgbGreen, rgbRed */
65 static const RGBQUAD DefLogPaletteQuads
[20] = { /* Copy of Default Logical Palette */
66 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
67 { 0x00, 0x00, 0x00, 0x00 },
68 { 0x00, 0x00, 0x80, 0x00 },
69 { 0x00, 0x80, 0x00, 0x00 },
70 { 0x00, 0x80, 0x80, 0x00 },
71 { 0x80, 0x00, 0x00, 0x00 },
72 { 0x80, 0x00, 0x80, 0x00 },
73 { 0x80, 0x80, 0x00, 0x00 },
74 { 0xc0, 0xc0, 0xc0, 0x00 },
75 { 0xc0, 0xdc, 0xc0, 0x00 },
76 { 0xf0, 0xca, 0xa6, 0x00 },
77 { 0xf0, 0xfb, 0xff, 0x00 },
78 { 0xa4, 0xa0, 0xa0, 0x00 },
79 { 0x80, 0x80, 0x80, 0x00 },
80 { 0x00, 0x00, 0xf0, 0x00 },
81 { 0x00, 0xff, 0x00, 0x00 },
82 { 0x00, 0xff, 0xff, 0x00 },
83 { 0xff, 0x00, 0x00, 0x00 },
84 { 0xff, 0x00, 0xff, 0x00 },
85 { 0xff, 0xff, 0x00, 0x00 },
86 { 0xff, 0xff, 0xff, 0x00 }
89 static const RGBQUAD DefLogPaletteTriples
[20] = { /* Copy of Default Logical Palette */
90 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
100 { 0xf0, 0xca, 0xa6 },
101 { 0xf0, 0xfb, 0xff },
102 { 0xa4, 0xa0, 0xa0 },
103 { 0x80, 0x80, 0x80 },
104 { 0x00, 0x00, 0xf0 },
105 { 0x00, 0xff, 0x00 },
106 { 0x00, 0xff, 0xff },
107 { 0xff, 0x00, 0x00 },
108 { 0xff, 0x00, 0xff },
109 { 0xff, 0xff, 0x00 },
120 CONST RGBQUAD
*Colors
)
128 if (!(dc
= DC_LockDc(hDC
))) return 0;
129 if (dc
->dctype
== DC_TYPE_INFO
)
135 psurf
= dc
->dclevel
.pSurface
;
139 EngSetLastError(ERROR_INVALID_PARAMETER
);
143 if (psurf
->hSecure
== NULL
)
146 EngSetLastError(ERROR_INVALID_PARAMETER
);
150 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
151 if (biBitCount
<= 8 && StartIndex
< (1 << biBitCount
))
153 if (StartIndex
+ Entries
> (1 << biBitCount
))
154 Entries
= (1 << biBitCount
) - StartIndex
;
156 if (psurf
->ppal
== NULL
)
159 EngSetLastError(ERROR_INVALID_HANDLE
);
163 PalGDI
= PALETTE_LockPalette(psurf
->ppal
->BaseObject
.hHmgr
);
165 for (Index
= StartIndex
;
166 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
169 PalGDI
->IndexedColors
[Index
].peRed
= Colors
[Index
- StartIndex
].rgbRed
;
170 PalGDI
->IndexedColors
[Index
].peGreen
= Colors
[Index
- StartIndex
].rgbGreen
;
171 PalGDI
->IndexedColors
[Index
].peBlue
= Colors
[Index
- StartIndex
].rgbBlue
;
173 PALETTE_UnlockPalette(PalGDI
);
178 /* Mark the brushes invalid */
179 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
|DIRTY_LINE
|DIRTY_BACKGROUND
|DIRTY_TEXT
;
197 UINT Index
, Count
= 0;
200 if (!(dc
= DC_LockDc(hDC
))) return 0;
201 if (dc
->dctype
== DC_TYPE_INFO
)
207 psurf
= dc
->dclevel
.pSurface
;
211 EngSetLastError(ERROR_INVALID_PARAMETER
);
215 if (psurf
->hSecure
== NULL
)
218 EngSetLastError(ERROR_INVALID_PARAMETER
);
222 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
223 if (biBitCount
<= 8 &&
224 StartIndex
< (1 << biBitCount
))
226 if (StartIndex
+ Entries
> (1 << biBitCount
))
227 Entries
= (1 << biBitCount
) - StartIndex
;
229 if (psurf
->ppal
== NULL
)
232 EngSetLastError(ERROR_INVALID_HANDLE
);
236 PalGDI
= PALETTE_LockPalette(psurf
->ppal
->BaseObject
.hHmgr
);
238 for (Index
= StartIndex
;
239 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
242 Colors
[Index
- StartIndex
].rgbRed
= PalGDI
->IndexedColors
[Index
].peRed
;
243 Colors
[Index
- StartIndex
].rgbGreen
= PalGDI
->IndexedColors
[Index
].peGreen
;
244 Colors
[Index
- StartIndex
].rgbBlue
= PalGDI
->IndexedColors
[Index
].peBlue
;
245 Colors
[Index
- StartIndex
].rgbReserved
= 0;
248 PALETTE_UnlockPalette(PalGDI
);
256 // Converts a DIB to a device-dependent bitmap
265 CONST BITMAPINFO
*bmi
,
268 HBITMAP SourceBitmap
;
269 PSURFACE psurfDst
, psurfSrc
;
276 SourceBitmap
= DIB_CreateDIBSection(DC
, bmi
, ColorUse
, &pvBits
, NULL
, 0, 0);
277 if (0 == SourceBitmap
)
279 DPRINT1("Error : Could not create a DIBSection.\n");
280 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
284 RtlCopyMemory(pvBits
, Bits
, DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
,
285 bmi
->bmiHeader
.biHeight
,
286 bmi
->bmiHeader
.biBitCount
));
288 psurfDst
= SURFACE_LockSurface(hBitmap
);
289 psurfSrc
= SURFACE_LockSurface(SourceBitmap
);
291 if(!(psurfSrc
&& psurfDst
))
293 DPRINT1("Error, could not lock surfaces\n");
297 rcDst
.top
= bmi
->bmiHeader
.biHeight
< 0 ?
298 abs(bmi
->bmiHeader
.biHeight
) - (ScanLines
+ StartScan
) : StartScan
;
300 rcDst
.bottom
= rcDst
.top
+ ScanLines
;
301 rcDst
.right
= psurfDst
->SurfObj
.sizlBitmap
.cx
;
306 EXLATEOBJ_vInitialize(&exlo
, psurfSrc
->ppal
, psurfDst
->ppal
, 0, 0, 0);
308 result
= IntEngCopyBits(&psurfDst
->SurfObj
,
317 EXLATEOBJ_vCleanup(&exlo
);
322 SURFACE_UnlockSurface(psurfSrc
);
326 SURFACE_UnlockSurface(psurfDst
);
328 GreDeleteObject(SourceBitmap
);
333 // FIXME by Removing NtGdiSetDIBits!!!
334 // This is a victim of the Win32k Initialization BUG!!!!!
335 // Converts a DIB to a device-dependent bitmap
344 CONST BITMAPINFO
*bmi
,
349 NTSTATUS Status
= STATUS_SUCCESS
;
355 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
356 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
357 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, ColorUse
), 1);
359 DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
,
361 bmi
->bmiHeader
.biBitCount
),
364 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
366 Status
= _SEH2_GetExceptionCode();
370 if (!NT_SUCCESS(Status
))
378 EngSetLastError(ERROR_INVALID_HANDLE
);
381 if (Dc
->dctype
== DC_TYPE_INFO
)
387 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
397 NtGdiSetDIBitsToDeviceInternal(
412 IN BOOL bTransformCoordinates
,
413 IN OPTIONAL HANDLE hcmXform
)
416 NTSTATUS Status
= STATUS_SUCCESS
;
418 HBITMAP hSourceBitmap
= NULL
;
419 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
426 PPALETTE ppalDIB
= NULL
;
427 HPALETTE hpalDIB
= NULL
;
433 ProbeForRead(bmi
, cjMaxInfo
, 1);
434 ProbeForRead(Bits
, cjMaxBits
, 1);
436 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
438 Status
= _SEH2_GetExceptionCode();
442 if (!NT_SUCCESS(Status
))
447 pDC
= DC_LockDc(hDC
);
450 EngSetLastError(ERROR_INVALID_HANDLE
);
453 if (pDC
->dctype
== DC_TYPE_INFO
)
459 pSurf
= pDC
->dclevel
.pSurface
;
461 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
463 ScanLines
= min(ScanLines
, abs(bmi
->bmiHeader
.biHeight
) - StartScan
);
467 if (bTransformCoordinates
)
469 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
471 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
472 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
473 rcDest
.right
= rcDest
.left
+ Width
;
474 rcDest
.bottom
= rcDest
.top
+ Height
;
475 rcDest
.top
+= StartScan
;
480 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
481 SourceSize
.cy
= ScanLines
;
483 DIBWidth
= WIDTH_BYTES_ALIGN32(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
485 hSourceBitmap
= EngCreateBitmap(SourceSize
,
487 BitmapFormat(bmi
->bmiHeader
.biBitCount
,
488 bmi
->bmiHeader
.biCompression
),
489 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
493 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
494 Status
= STATUS_NO_MEMORY
;
498 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
501 Status
= STATUS_UNSUCCESSFUL
;
507 /* Create a palette for the DIB */
508 hpalDIB
= BuildDIBPalette(bmi
);
511 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
512 Status
= STATUS_NO_MEMORY
;
516 /* Lock the DIB palette */
517 ppalDIB
= PALETTE_LockPalette(hpalDIB
);
520 EngSetLastError(ERROR_INVALID_HANDLE
);
521 Status
= STATUS_UNSUCCESSFUL
;
525 /* Initialize EXLATEOBJ */
526 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, pSurf
->ppal
, 0, 0, 0);
529 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
530 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
531 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
532 Status
= IntEngBitBlt(pDestSurf
,
535 pDC
->rosdc
.CombinedClip
,
542 ROP3_TO_ROP4(SRCCOPY
));
544 /* Cleanup EXLATEOBJ */
545 EXLATEOBJ_vCleanup(&exlo
);
548 if (NT_SUCCESS(Status
))
553 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
555 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
556 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
557 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
564 /* Converts a device-dependent bitmap to a DIB */
567 NtGdiGetDIBitsInternal(
578 BITMAPCOREINFO
* pbmci
= NULL
;
579 PSURFACE psurf
= NULL
;
585 RGBTRIPLE
* rgbTriples
;
588 NTSTATUS Status
= STATUS_SUCCESS
;
590 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
592 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
597 /* Probe for read and write */
598 ProbeForRead(Info
, MaxInfo
, 1);
599 ProbeForWrite(Info
, MaxInfo
, 1);
600 if (Bits
) ProbeForWrite(Bits
, MaxBits
, 1);
602 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
604 Status
= _SEH2_GetExceptionCode();
608 if (!NT_SUCCESS(Status
))
613 colorPtr
= (LPBYTE
)Info
+ Info
->bmiHeader
.biSize
;
614 rgbTriples
= colorPtr
;
617 bitmap_type
= DIB_GetBitmapInfo(&Info
->bmiHeader
,
624 if(bitmap_type
== -1)
626 DPRINT("Wrong bitmap format\n");
627 EngSetLastError(ERROR_INVALID_PARAMETER
);
630 else if(bitmap_type
== 0)
632 /* We need a BITMAPINFO to create a DIB, but we have to fill
633 * the BITMAPCOREINFO we're provided */
634 pbmci
= (BITMAPCOREINFO
*)Info
;
635 Info
= DIB_ConvertBitmapInfo((BITMAPINFO
*)pbmci
, Usage
);
638 DPRINT1("Error, could not convert the BITMAPCOREINFO!\n");
641 rgbQuads
= Info
->bmiColors
;
644 pDC
= DC_LockDc(hDC
);
645 if (pDC
== NULL
|| pDC
->dctype
== DC_TYPE_INFO
)
651 /* Get a pointer to the source bitmap object */
652 psurf
= SURFACE_ShareLockSurface(hBitmap
);
659 /* Fill in the structure */
662 case 0: /* Only info */
665 pbmci
->bmciHeader
.bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
666 pbmci
->bmciHeader
.bcHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
667 -psurf
->SurfObj
.sizlBitmap
.cy
:
668 psurf
->SurfObj
.sizlBitmap
.cy
;
669 pbmci
->bmciHeader
.bcPlanes
= 1;
670 pbmci
->bmciHeader
.bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
672 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
673 Info
->bmiHeader
.biHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
674 -psurf
->SurfObj
.sizlBitmap
.cy
:
675 psurf
->SurfObj
.sizlBitmap
.cy
;;
676 Info
->bmiHeader
.biPlanes
= 1;
677 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
678 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes( Info
->bmiHeader
.biWidth
,
679 Info
->bmiHeader
.biHeight
,
680 Info
->bmiHeader
.biBitCount
);
683 switch(Info
->bmiHeader
.biBitCount
)
687 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
690 Info
->bmiHeader
.biCompression
= BI_RGB
;
694 else if(Info
->bmiHeader
.biBitCount
> 8)
696 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
700 Info
->bmiHeader
.biCompression
= BI_RGB
;
702 Info
->bmiHeader
.biXPelsPerMeter
= 0;
703 Info
->bmiHeader
.biYPelsPerMeter
= 0;
704 Info
->bmiHeader
.biClrUsed
= 0;
705 Info
->bmiHeader
.biClrImportant
= 0;
706 ScanLines
= abs(Info
->bmiHeader
.biHeight
);
712 Info
->bmiHeader
.biClrUsed
= 0;
714 /* If the bitmap if a DIB section and has the same format than what
715 * we're asked, go ahead! */
716 if((psurf
->hSecure
) &&
717 (BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == bpp
))
719 if(Usage
== DIB_RGB_COLORS
)
721 unsigned int colors
= min(psurf
->ppal
->NumColors
, 1 << bpp
);
725 for(i
=0; i
< colors
; i
++)
727 rgbTriples
[i
].rgbtRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
728 rgbTriples
[i
].rgbtGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
729 rgbTriples
[i
].rgbtBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
732 if(colors
!= 1 << bpp
) Info
->bmiHeader
.biClrUsed
= colors
;
733 for(i
=0; i
< colors
; i
++)
735 rgbQuads
[i
].rgbRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
736 rgbQuads
[i
].rgbGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
737 rgbQuads
[i
].rgbBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
742 for(i
=0; i
< 1 << bpp
; i
++)
744 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
745 ((WORD
*)rgbQuads
)[i
] = i
;
751 if(Usage
== DIB_PAL_COLORS
)
753 for(i
=0; i
< 1 << bpp
; i
++)
755 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
756 ((WORD
*)rgbQuads
)[i
] = i
;
759 else if(bpp
> 1 && bpp
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
)) {
760 /* For color DDBs in native depth (mono DDBs always have
761 a black/white palette):
762 Generate the color map from the selected palette */
763 PPALETTE pDcPal
= PALETTE_LockPalette(pDC
->dclevel
.hpal
);
769 for (i
= 0; i
< pDcPal
->NumColors
; i
++) {
772 rgbTriples
[i
].rgbtRed
= pDcPal
->IndexedColors
[i
].peRed
;
773 rgbTriples
[i
].rgbtGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
774 rgbTriples
[i
].rgbtBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
777 rgbQuads
[i
].rgbRed
= pDcPal
->IndexedColors
[i
].peRed
;
778 rgbQuads
[i
].rgbGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
779 rgbQuads
[i
].rgbBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
780 rgbQuads
[i
].rgbReserved
= 0;
782 PALETTE_UnlockPalette(pDcPal
);
788 rgbTriples
[0].rgbtRed
= rgbTriples
[0].rgbtGreen
=
789 rgbTriples
[0].rgbtBlue
= 0;
790 rgbTriples
[1].rgbtRed
= rgbTriples
[1].rgbtGreen
=
791 rgbTriples
[1].rgbtBlue
= 0xff;
793 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
=
794 rgbQuads
[0].rgbBlue
= 0;
795 rgbQuads
[0].rgbReserved
= 0;
796 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
=
797 rgbQuads
[1].rgbBlue
= 0xff;
798 rgbQuads
[1].rgbReserved
= 0;
803 RtlCopyMemory(rgbTriples
, EGAColorsTriples
, sizeof(EGAColorsTriples
));
804 RtlCopyMemory(rgbQuads
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
814 RGBTRIPLE
*colorTriple
;
816 RtlCopyMemory(rgbTriples
, DefLogPaletteTriples
,
817 10 * sizeof(RGBTRIPLE
));
818 RtlCopyMemory(rgbTriples
+ 246, DefLogPaletteTriples
+ 10,
819 10 * sizeof(RGBTRIPLE
));
820 colorTriple
= rgbTriples
+ 10;
821 for(r
= 0; r
<= 5; r
++) /* FIXME */
823 for(g
= 0; g
<= 5; g
++)
825 for(b
= 0; b
<= 5; b
++)
827 colorTriple
->rgbtRed
= (r
* 0xff) / 5;
828 colorTriple
->rgbtGreen
= (g
* 0xff) / 5;
829 colorTriple
->rgbtBlue
= (b
* 0xff) / 5;
835 memcpy(rgbQuads
, DefLogPaletteQuads
,
836 10 * sizeof(RGBQUAD
));
837 memcpy(rgbQuads
+ 246, DefLogPaletteQuads
+ 10,
838 10 * sizeof(RGBQUAD
));
839 color
= rgbQuads
+ 10;
840 for(r
= 0; r
<= 5; r
++) /* FIXME */
842 for(g
= 0; g
<= 5; g
++)
844 for(b
= 0; b
<= 5; b
++)
846 color
->rgbRed
= (r
* 0xff) / 5;
847 color
->rgbGreen
= (g
* 0xff) / 5;
848 color
->rgbBlue
= (b
* 0xff) / 5;
849 color
->rgbReserved
= 0;
861 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
863 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
864 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
865 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
870 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
874 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
875 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
876 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
880 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
881 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
882 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
889 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
893 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
894 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
895 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
899 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
900 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
901 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
906 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(width
, height
, bpp
);
908 if(Bits
&& ScanLines
)
910 /* Create a DIBSECTION, blt it, profit */
919 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
926 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
930 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
931 Info
->bmiHeader
.biHeight
= height
< 0 ?
932 -ScanLines
: ScanLines
;
934 hBmpDest
= DIB_CreateDIBSection(pDC
, Info
, Usage
, &pDIBits
, NULL
, 0, 0);
936 Info
->bmiHeader
.biWidth
= width
;
937 Info
->bmiHeader
.biHeight
= height
;
941 DPRINT1("Unable to create a DIB Section!\n");
942 EngSetLastError(ERROR_INVALID_PARAMETER
);
947 psurfDest
= SURFACE_ShareLockSurface(hBmpDest
);
951 rcDest
.bottom
= ScanLines
;
952 rcDest
.right
= psurf
->SurfObj
.sizlBitmap
.cx
;
955 srcPoint
.y
= height
< 0 ?
956 psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
) : StartScan
;
958 EXLATEOBJ_vInitialize(&exlo
, psurf
->ppal
, psurfDest
->ppal
, 0xffffff, 0xffffff, 0);
960 ret
= IntEngCopyBits(&psurfDest
->SurfObj
,
967 SURFACE_ShareUnlockSurface(psurfDest
);
973 Status
= STATUS_SUCCESS
;
976 RtlCopyMemory(Bits
, pDIBits
, DIB_GetDIBImageBytes (width
, ScanLines
, bpp
));
978 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
980 Status
= _SEH2_GetExceptionCode();
984 if(!NT_SUCCESS(Status
))
986 DPRINT1("Unable to copy bits to the user provided pointer\n");
991 GreDeleteObject(hBmpDest
);
992 EXLATEOBJ_vCleanup(&exlo
);
994 else ScanLines
= abs(height
);
998 if(pDC
) DC_UnlockDc(pDC
);
999 if(psurf
) SURFACE_ShareUnlockSurface(psurf
);
1000 if(pbmci
) DIB_FreeConvertedBitmapInfo(Info
, (BITMAPINFO
*)pbmci
);
1008 NtGdiStretchDIBitsInternal(
1019 LPBITMAPINFO BitsInfo
,
1038 if (!Bits
|| !BitsInfo
)
1041 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1044 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1050 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1051 ProbeForRead(Bits
, cjMaxBits
, 1);
1052 if (DIB_GetBitmapInfo(&BitsInfo
->bmiHeader
, &width
, &height
, &planes
, &bpp
, &compr
, &size
) == -1)
1054 DPRINT1("Invalid bitmap\n");
1055 _SEH2_YIELD(goto cleanup
;)
1057 RtlCopyMemory(safeBits
, Bits
, cjMaxBits
);
1059 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1061 DPRINT1("Error, failed to read the DIB bits\n");
1062 _SEH2_YIELD(goto cleanup
;)
1068 DPRINT1("Bitmap has a negative width\n");
1072 hBitmap
= NtGdiGetDCObject(hDC
, OBJ_BITMAP
);
1074 if (!(pdc
= DC_LockDc(hDC
)))
1076 ExFreePoolWithTag(safeBits
, TAG_DIB
);
1077 EngSetLastError(ERROR_INVALID_HANDLE
);
1081 if (XDest
== 0 && YDest
== 0 && XSrc
== 0 && XSrc
== 0 &&
1082 DestWidth
== SrcWidth
&& DestHeight
== SrcHeight
&&
1087 ret
= IntGdiGetObject(hBitmap
, sizeof(bmp
), &bmp
) == sizeof(bmp
);
1089 bmp
.bmBitsPixel
== bpp
&&
1090 bmp
.bmWidth
== SrcWidth
&&
1091 bmp
.bmHeight
== SrcHeight
&&
1092 bmp
.bmPlanes
== planes
)
1095 ret
= IntSetDIBits(pdc
, hBitmap
, 0, height
, safeBits
, BitsInfo
, Usage
);
1101 /* slow path - need to use StretchBlt */
1103 hBitmap
= DIB_CreateDIBSection(pdc
, BitsInfo
, Usage
, &pvBits
, NULL
, 0, 0);
1108 DPRINT1("Error, failed to create a DIB section\n");
1112 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1114 RtlCopyMemory(pvBits
, safeBits
, cjMaxBits
);
1115 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1117 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1118 left (negative biHeight) */
1119 ret
= NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1120 hdcMem
, XSrc
, abs(height
) - SrcHeight
- YSrc
,
1121 SrcWidth
, SrcHeight
, ROP
, 0);
1125 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1126 NtGdiDeleteObjectApp(hdcMem
);
1127 GreDeleteObject(hBitmap
);
1130 ExFreePoolWithTag(safeBits
, TAG_DIB
);
1150 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1151 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1153 if (bpp
!= 1) fColor
= TRUE
;
1154 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1157 const RGBQUAD
*rgb
= (RGBQUAD
*)((PBYTE
)data
+ data
->bmiHeader
.biSize
);
1158 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1160 // Check if the first color of the colormap is black
1161 if ((col
== RGB(0, 0, 0)))
1164 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1166 // If the second color is white, create a monochrome bitmap
1167 fColor
= (col
!= RGB(0xff,0xff,0xff));
1172 // Now create the bitmap
1175 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1179 handle
= GreCreateBitmap(width
,
1189 if (NULL
!= handle
&& CBM_INIT
== init
)
1191 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1197 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1198 // The DDB that is created will be whatever bit depth your reference DC is
1201 NtGdiCreateDIBitmapInternal(
1206 IN OPTIONAL LPBYTE pjInit
,
1207 IN OPTIONAL LPBITMAPINFO pbmi
,
1209 IN UINT cjMaxInitInfo
,
1214 NTSTATUS Status
= STATUS_SUCCESS
;
1215 PBYTE safeBits
= NULL
;
1216 HBITMAP hbmResult
= NULL
;
1218 if(pjInit
&& (fInit
== CBM_INIT
))
1220 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1223 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1230 if(pbmi
) ProbeForRead(pbmi
, cjMaxInitInfo
, 1);
1231 if(pjInit
&& (fInit
== CBM_INIT
))
1233 ProbeForRead(pjInit
, cjMaxBits
, 1);
1234 RtlCopyMemory(safeBits
, pjInit
, cjMaxBits
);
1237 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1239 Status
= _SEH2_GetExceptionCode();
1243 if(!NT_SUCCESS(Status
))
1245 SetLastNtError(Status
);
1249 hbmResult
= GreCreateDIBitmapInternal(hDc
,
1260 if (safeBits
) ExFreePoolWithTag(safeBits
, TAG_DIB
);
1266 GreCreateDIBitmapInternal(
1271 IN OPTIONAL LPBYTE pjInit
,
1272 IN OPTIONAL PBITMAPINFO pbmi
,
1282 if (!hDc
) /* 1bpp monochrome bitmap */
1283 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1284 hdcDest
= NtGdiCreateCompatibleDC(0);
1295 Dc
= DC_LockDc(hdcDest
);
1298 EngSetLastError(ERROR_INVALID_HANDLE
);
1301 /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
1302 * if bpp != 1 and ignore the real value that was passed */
1304 bpp
= pbmi
->bmiHeader
.biBitCount
;
1307 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1312 NtGdiDeleteObjectApp(hdcDest
);
1320 NtGdiCreateDIBSection(
1322 IN OPTIONAL HANDLE hSection
,
1328 IN ULONG_PTR dwColorSpace
,
1331 HBITMAP hbitmap
= 0;
1333 BOOL bDesktopDC
= FALSE
;
1334 NTSTATUS Status
= STATUS_SUCCESS
;
1336 if (!bmi
) return hbitmap
; // Make sure.
1340 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
1341 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
1342 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, Usage
), 1);
1344 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1346 Status
= _SEH2_GetExceptionCode();
1350 if(!NT_SUCCESS(Status
))
1352 SetLastNtError(Status
);
1356 // If the reference hdc is null, take the desktop dc
1359 hDC
= NtGdiCreateCompatibleDC(0);
1363 if ((dc
= DC_LockDc(hDC
)))
1365 hbitmap
= DIB_CreateDIBSection(dc
,
1376 EngSetLastError(ERROR_INVALID_HANDLE
);
1380 NtGdiDeleteObjectApp(hDC
);
1387 DIB_CreateDIBSection(
1389 CONST BITMAPINFO
*bmi
,
1397 SURFACE
*bmp
= NULL
;
1398 void *mapBits
= NULL
;
1401 // Fill BITMAP32 structure with DIB data
1402 CONST BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1409 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1410 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1411 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1413 /* CreateDIBSection should fail for compressed formats */
1414 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1416 return (HBITMAP
)NULL
;
1419 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1421 bm
.bmWidth
= bi
->biWidth
;
1422 bm
.bmHeight
= effHeight
;
1423 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: WIDTH_BYTES_ALIGN32(bm
.bmWidth
, bi
->biBitCount
);
1425 bm
.bmPlanes
= bi
->biPlanes
;
1426 bm
.bmBitsPixel
= bi
->biBitCount
;
1429 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1430 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1431 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
&& bi
->biCompression
!= BI_BITFIELDS
1432 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1436 SYSTEM_BASIC_INFORMATION Sbi
;
1439 LARGE_INTEGER SectionOffset
;
1442 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1446 if (!NT_SUCCESS(Status
))
1451 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1452 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1454 SectionOffset
.LowPart
= mapOffset
;
1455 SectionOffset
.HighPart
= 0;
1457 Status
= ZwMapViewOfSection(section
,
1467 if (!NT_SUCCESS(Status
))
1469 EngSetLastError(ERROR_INVALID_PARAMETER
);
1473 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1475 else if (ovr_pitch
&& offset
)
1476 bm
.bmBits
= (LPVOID
) offset
;
1480 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1481 if(!bm
.bmBits
) goto cleanup
;
1484 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1485 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1487 if (usage
== DIB_PAL_COLORS
)
1492 pdcPal
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1493 hpal
= DIB_MapPaletteColors(pdcPal
, bmi
);
1494 PALETTE_UnlockPalette(pdcPal
);
1498 /* For DIB Brushes */
1499 DPRINT1("FIXME : Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
1501 hpal
= (HPALETTE
) 0xFFFFFFFF;
1506 hpal
= BuildDIBPalette(bmi
);
1511 DPRINT1("Error : Could not create a palette for the DIB.\n");
1515 // Create Device Dependent Bitmap and add DIB pointer
1516 Size
.cx
= bm
.bmWidth
;
1517 Size
.cy
= abs(bm
.bmHeight
);
1518 res
= GreCreateBitmapEx(bm
.bmWidth
,
1521 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1522 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1523 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1529 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1532 bmp
= SURFACE_LockSurface(res
);
1535 EngSetLastError(ERROR_INVALID_HANDLE
);
1539 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1540 table between the DIB and the X physical device. Obviously,
1541 this is left out of the ReactOS implementation. Instead,
1542 we call NtGdiSetDIBColorTable. */
1543 bmp
->hDIBSection
= section
;
1544 bmp
->hSecure
= hSecure
;
1545 bmp
->dwOffset
= offset
;
1546 bmp
->flags
= API_BITMAP
;
1547 bmp
->biClrImportant
= bi
->biClrImportant
;
1548 bmp
->SurfObj
.fjBitmap
&= ~BMF_DONT_FREE
;
1551 if(hpal
!= (HPALETTE
)0xFFFFFFFF)
1553 bmp
->ppal
= PALETTE_ShareLockPalette(hpal
);
1554 /* Lazy delete hpal, it will be freed at surface release */
1555 GreDeleteObject(hpal
);
1558 // Clean up in case of errors
1560 if (!res
|| !bmp
|| !bm
.bmBits
)
1562 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1565 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1568 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1573 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1581 SURFACE_FreeSurfaceByHandle(res
);
1588 SURFACE_UnlockSurface(bmp
);
1591 // Return BITMAP handle and storage location
1592 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1600 /***********************************************************************
1603 * Get the info from a bitmap header.
1604 * Return 0 for COREHEADER, 1 for INFOHEADER, -1 for error.
1608 DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
1609 LONG
*height
, WORD
*planes
, WORD
*bpp
, DWORD
*compr
, DWORD
*size
)
1611 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
1613 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
1614 *width
= core
->bcWidth
;
1615 *height
= core
->bcHeight
;
1616 *planes
= core
->bcPlanes
;
1617 *bpp
= core
->bcBitCount
;
1622 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
)) /* assume BITMAPINFOHEADER */
1624 *width
= header
->biWidth
;
1625 *height
= header
->biHeight
;
1626 *planes
= header
->biPlanes
;
1627 *bpp
= header
->biBitCount
;
1628 *compr
= header
->biCompression
;
1629 *size
= header
->biSizeImage
;
1632 DPRINT1("(%d): unknown/wrong size for header\n", header
->biSize
);
1636 /***********************************************************************
1637 * DIB_GetDIBImageBytes
1639 * Return the number of bytes used to hold the image in a DIB bitmap.
1640 * 11/16/1999 (RJJ) lifted from wine
1643 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1645 return WIDTH_BYTES_ALIGN32(width
, depth
) * (height
< 0 ? -height
: height
);
1648 /***********************************************************************
1649 * DIB_BitmapInfoSize
1651 * Return the size of the bitmap info structure including color table.
1652 * 11/16/1999 (RJJ) lifted from wine
1655 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1657 unsigned int colors
, size
, masks
= 0;
1659 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1661 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
1662 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1663 return sizeof(BITMAPCOREHEADER
) + colors
*
1664 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1666 else /* assume BITMAPINFOHEADER */
1668 colors
= info
->bmiHeader
.biClrUsed
;
1669 if (colors
> 256) colors
= 256;
1670 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
1671 colors
= 1 << info
->bmiHeader
.biBitCount
;
1672 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
1673 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
1674 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1680 DIB_MapPaletteColors(PPALETTE ppal
, CONST BITMAPINFO
* lpbmi
)
1682 PALETTEENTRY
* ppalEntries
;
1687 if (!(ppal
->flFlags
& PAL_INDEXED
))
1692 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1693 if (lpbmi
->bmiHeader
.biClrUsed
)
1695 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1698 /* Don't have more colors than we need */
1699 nNumColors
= min(ppal
->NumColors
, nNumColors
);
1701 ppalEntries
= ExAllocatePoolWithTag(PagedPool
, sizeof(PALETTEENTRY
) * nNumColors
, TAG_COLORMAP
);
1702 if (ppalEntries
== NULL
)
1704 DPRINT1("Could not allocate palette entries\n");
1708 lpIndex
= (USHORT
*)((PBYTE
)lpbmi
+ lpbmi
->bmiHeader
.biSize
);
1710 for (i
= 0; i
< nNumColors
; i
++)
1712 if (*lpIndex
< ppal
->NumColors
)
1714 ppalEntries
[i
] = ppal
->IndexedColors
[*lpIndex
];
1718 ppalEntries
[i
].peRed
= 0;
1719 ppalEntries
[i
].peGreen
= 0;
1720 ppalEntries
[i
].peBlue
= 0;
1721 ppalEntries
[i
].peFlags
= 0;
1727 hpal
= PALETTE_AllocPalette(PAL_INDEXED
, nNumColors
, (ULONG
*)ppalEntries
, 0, 0, 0);
1729 ExFreePoolWithTag(ppalEntries
, TAG_COLORMAP
);
1736 BuildDIBPalette(CONST BITMAPINFO
*bmi
)
1741 ULONG RedMask
= 0, GreenMask
= 0, BlueMask
= 0;
1742 PDWORD pdwColors
= (PDWORD
)((PBYTE
)bmi
+ bmi
->bmiHeader
.biSize
);
1745 // Determine Bits Per Pixel
1746 bits
= bmi
->bmiHeader
.biBitCount
;
1748 // Determine paletteType from Bits Per Pixel
1751 paletteType
= PAL_INDEXED
;
1752 RedMask
= GreenMask
= BlueMask
= 0;
1754 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1756 paletteType
= PAL_BITFIELDS
;
1757 if (bmi
->bmiHeader
.biSize
>= sizeof(BITMAPV4HEADER
))
1759 PBITMAPV4HEADER pV4Header
= (PBITMAPV4HEADER
)&bmi
->bmiHeader
;
1760 RedMask
= pV4Header
->bV4RedMask
;
1761 GreenMask
= pV4Header
->bV4GreenMask
;
1762 BlueMask
= pV4Header
->bV4BlueMask
;
1766 RedMask
= pdwColors
[0];
1767 GreenMask
= pdwColors
[1];
1768 BlueMask
= pdwColors
[2];
1773 paletteType
= PAL_BITFIELDS
;
1777 paletteType
|= PAL_RGB16_555
;
1785 paletteType
|= PAL_BGR
;
1787 GreenMask
= 0x00FF00;
1788 BlueMask
= 0x0000FF;
1793 if (bmi
->bmiHeader
.biClrUsed
== 0)
1795 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1799 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1802 if (PAL_INDEXED
== paletteType
)
1804 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)pdwColors
);
1808 hPal
= PALETTE_AllocPalette(paletteType
, 0,
1810 RedMask
, GreenMask
, BlueMask
);
1816 /* Converts a BITMAPCOREINFO to a BITMAPINFO structure,
1817 * or does nothing if it's already a BITMAPINFO (or V4 or V5) */
1820 DIB_ConvertBitmapInfo (CONST BITMAPINFO
* pbmi
, DWORD Usage
)
1822 CONST BITMAPCOREINFO
* pbmci
= (BITMAPCOREINFO
*)pbmi
;
1823 BITMAPINFO
* pNewBmi
;
1824 UINT numColors
= 0, ColorsSize
= 0;
1826 if(pbmi
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
)) return (BITMAPINFO
*)pbmi
;
1827 if(pbmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) return NULL
;
1829 if(pbmci
->bmciHeader
.bcBitCount
<= 8)
1831 numColors
= 1 << pbmci
->bmciHeader
.bcBitCount
;
1832 if(Usage
== DIB_PAL_COLORS
)
1834 ColorsSize
= numColors
* sizeof(WORD
);
1838 ColorsSize
= numColors
* sizeof(RGBQUAD
);
1841 else if (Usage
== DIB_PAL_COLORS
)
1843 /* Invalid at high Res */
1847 pNewBmi
= ExAllocatePoolWithTag(PagedPool
, sizeof(BITMAPINFOHEADER
) + ColorsSize
, TAG_DIB
);
1848 if(!pNewBmi
) return NULL
;
1850 RtlZeroMemory(pNewBmi
, sizeof(BITMAPINFOHEADER
) + ColorsSize
);
1852 pNewBmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1853 pNewBmi
->bmiHeader
.biBitCount
= pbmci
->bmciHeader
.bcBitCount
;
1854 pNewBmi
->bmiHeader
.biWidth
= pbmci
->bmciHeader
.bcWidth
;
1855 pNewBmi
->bmiHeader
.biHeight
= pbmci
->bmciHeader
.bcHeight
;
1856 pNewBmi
->bmiHeader
.biPlanes
= pbmci
->bmciHeader
.bcPlanes
;
1857 pNewBmi
->bmiHeader
.biCompression
= BI_RGB
;
1858 pNewBmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(pNewBmi
->bmiHeader
.biWidth
,
1859 pNewBmi
->bmiHeader
.biHeight
,
1860 pNewBmi
->bmiHeader
.biBitCount
);
1862 if(Usage
== DIB_PAL_COLORS
)
1864 RtlCopyMemory(pNewBmi
->bmiColors
, pbmci
->bmciColors
, ColorsSize
);
1869 for(i
=0; i
<numColors
; i
++)
1871 pNewBmi
->bmiColors
[i
].rgbRed
= pbmci
->bmciColors
[i
].rgbtRed
;
1872 pNewBmi
->bmiColors
[i
].rgbGreen
= pbmci
->bmciColors
[i
].rgbtGreen
;
1873 pNewBmi
->bmiColors
[i
].rgbBlue
= pbmci
->bmciColors
[i
].rgbtBlue
;
1880 /* Frees a BITMAPINFO created with DIB_ConvertBitmapInfo */
1883 DIB_FreeConvertedBitmapInfo(BITMAPINFO
* converted
, BITMAPINFO
* orig
)
1885 if(converted
!= orig
)
1886 ExFreePoolWithTag(converted
, TAG_DIB
);