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] =
27 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
28 { 0x00, 0x00, 0x00, 0x00 },
29 { 0x00, 0x00, 0x80, 0x00 },
30 { 0x00, 0x80, 0x00, 0x00 },
31 { 0x00, 0x80, 0x80, 0x00 },
32 { 0x80, 0x00, 0x00, 0x00 },
33 { 0x80, 0x00, 0x80, 0x00 },
34 { 0x80, 0x80, 0x00, 0x00 },
35 { 0x80, 0x80, 0x80, 0x00 },
36 { 0xc0, 0xc0, 0xc0, 0x00 },
37 { 0x00, 0x00, 0xff, 0x00 },
38 { 0x00, 0xff, 0x00, 0x00 },
39 { 0x00, 0xff, 0xff, 0x00 },
40 { 0xff, 0x00, 0x00, 0x00 },
41 { 0xff, 0x00, 0xff, 0x00 },
42 { 0xff, 0xff, 0x00, 0x00 },
43 { 0xff, 0xff, 0xff, 0x00 }
46 static const RGBTRIPLE EGAColorsTriples
[16] =
48 /* rgbBlue, rgbGreen, rgbRed */
67 static const RGBQUAD DefLogPaletteQuads
[20] = /* Copy of Default Logical Palette */
69 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
70 { 0x00, 0x00, 0x00, 0x00 },
71 { 0x00, 0x00, 0x80, 0x00 },
72 { 0x00, 0x80, 0x00, 0x00 },
73 { 0x00, 0x80, 0x80, 0x00 },
74 { 0x80, 0x00, 0x00, 0x00 },
75 { 0x80, 0x00, 0x80, 0x00 },
76 { 0x80, 0x80, 0x00, 0x00 },
77 { 0xc0, 0xc0, 0xc0, 0x00 },
78 { 0xc0, 0xdc, 0xc0, 0x00 },
79 { 0xf0, 0xca, 0xa6, 0x00 },
80 { 0xf0, 0xfb, 0xff, 0x00 },
81 { 0xa4, 0xa0, 0xa0, 0x00 },
82 { 0x80, 0x80, 0x80, 0x00 },
83 { 0x00, 0x00, 0xf0, 0x00 },
84 { 0x00, 0xff, 0x00, 0x00 },
85 { 0x00, 0xff, 0xff, 0x00 },
86 { 0xff, 0x00, 0x00, 0x00 },
87 { 0xff, 0x00, 0xff, 0x00 },
88 { 0xff, 0xff, 0x00, 0x00 },
89 { 0xff, 0xff, 0xff, 0x00 }
92 static const RGBQUAD DefLogPaletteTriples
[20] = /* Copy of Default Logical Palette */
94 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
100 { 0x80, 0x00, 0x80 },
101 { 0x80, 0x80, 0x00 },
102 { 0xc0, 0xc0, 0xc0 },
103 { 0xc0, 0xdc, 0xc0 },
104 { 0xf0, 0xca, 0xa6 },
105 { 0xf0, 0xfb, 0xff },
106 { 0xa4, 0xa0, 0xa0 },
107 { 0x80, 0x80, 0x80 },
108 { 0x00, 0x00, 0xf0 },
109 { 0x00, 0xff, 0x00 },
110 { 0x00, 0xff, 0xff },
111 { 0xff, 0x00, 0x00 },
112 { 0xff, 0x00, 0xff },
113 { 0xff, 0xff, 0x00 },
124 CONST RGBQUAD
*Colors
)
132 if (!(dc
= DC_LockDc(hDC
))) return 0;
133 if (dc
->dctype
== DC_TYPE_INFO
)
139 psurf
= dc
->dclevel
.pSurface
;
143 EngSetLastError(ERROR_INVALID_PARAMETER
);
147 if (psurf
->hSecure
== NULL
)
150 EngSetLastError(ERROR_INVALID_PARAMETER
);
154 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
155 if (biBitCount
<= 8 && StartIndex
< (1 << biBitCount
))
157 if (StartIndex
+ Entries
> (1 << biBitCount
))
158 Entries
= (1 << biBitCount
) - StartIndex
;
160 if (psurf
->ppal
== NULL
)
163 EngSetLastError(ERROR_INVALID_HANDLE
);
167 PalGDI
= PALETTE_LockPalette(psurf
->ppal
->BaseObject
.hHmgr
);
169 for (Index
= StartIndex
;
170 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
173 PalGDI
->IndexedColors
[Index
].peRed
= Colors
[Index
- StartIndex
].rgbRed
;
174 PalGDI
->IndexedColors
[Index
].peGreen
= Colors
[Index
- StartIndex
].rgbGreen
;
175 PalGDI
->IndexedColors
[Index
].peBlue
= Colors
[Index
- StartIndex
].rgbBlue
;
177 PALETTE_UnlockPalette(PalGDI
);
182 /* Mark the brushes invalid */
183 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
|DIRTY_LINE
|DIRTY_BACKGROUND
|DIRTY_TEXT
;
201 UINT Index
, Count
= 0;
203 if (!(dc
= DC_LockDc(hDC
))) return 0;
204 if (dc
->dctype
== DC_TYPE_INFO
)
210 psurf
= dc
->dclevel
.pSurface
;
214 EngSetLastError(ERROR_INVALID_PARAMETER
);
218 if (psurf
->hSecure
== NULL
)
221 EngSetLastError(ERROR_INVALID_PARAMETER
);
228 if (ppal
->flFlags
& PAL_INDEXED
)
231 for (Index
= StartIndex
;
232 Index
< StartIndex
+ Entries
&& Index
< ppal
->NumColors
;
235 Colors
[Index
- StartIndex
].rgbRed
= ppal
->IndexedColors
[Index
].peRed
;
236 Colors
[Index
- StartIndex
].rgbGreen
= ppal
->IndexedColors
[Index
].peGreen
;
237 Colors
[Index
- StartIndex
].rgbBlue
= ppal
->IndexedColors
[Index
].peBlue
;
238 Colors
[Index
- StartIndex
].rgbReserved
= 0;
248 // Converts a DIB to a device-dependent bitmap
257 CONST BITMAPINFO
*bmi
,
260 HBITMAP SourceBitmap
;
261 PSURFACE psurfDst
, psurfSrc
;
268 SourceBitmap
= DIB_CreateDIBSection(DC
, bmi
, ColorUse
, &pvBits
, NULL
, 0, 0);
269 if (0 == SourceBitmap
)
271 DPRINT1("Error : Could not create a DIBSection.\n");
272 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
276 RtlCopyMemory(pvBits
, Bits
, DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
,
277 bmi
->bmiHeader
.biHeight
,
278 bmi
->bmiHeader
.biBitCount
));
280 psurfDst
= SURFACE_LockSurface(hBitmap
);
281 psurfSrc
= SURFACE_LockSurface(SourceBitmap
);
283 if(!(psurfSrc
&& psurfDst
))
285 DPRINT1("Error, could not lock surfaces\n");
289 rcDst
.top
= bmi
->bmiHeader
.biHeight
< 0 ?
290 abs(bmi
->bmiHeader
.biHeight
) - (ScanLines
+ StartScan
) : StartScan
;
292 rcDst
.bottom
= rcDst
.top
+ ScanLines
;
293 rcDst
.right
= psurfDst
->SurfObj
.sizlBitmap
.cx
;
298 EXLATEOBJ_vInitialize(&exlo
, psurfSrc
->ppal
, psurfDst
->ppal
, 0, 0, 0);
300 result
= IntEngCopyBits(&psurfDst
->SurfObj
,
309 EXLATEOBJ_vCleanup(&exlo
);
314 SURFACE_UnlockSurface(psurfSrc
);
318 SURFACE_UnlockSurface(psurfDst
);
320 GreDeleteObject(SourceBitmap
);
325 // FIXME by Removing NtGdiSetDIBits!!!
326 // This is a victim of the Win32k Initialization BUG!!!!!
327 // Converts a DIB to a device-dependent bitmap
336 CONST BITMAPINFO
*bmi
,
341 NTSTATUS Status
= STATUS_SUCCESS
;
347 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
348 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
349 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, ColorUse
), 1);
351 DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
,
353 bmi
->bmiHeader
.biBitCount
),
356 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
358 Status
= _SEH2_GetExceptionCode();
362 if (!NT_SUCCESS(Status
))
367 /* Lock DC if asked to */
368 if(ColorUse
== DIB_PAL_COLORS
)
373 EngSetLastError(ERROR_INVALID_HANDLE
);
376 if (Dc
->dctype
== DC_TYPE_INFO
)
383 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
385 if(Dc
) DC_UnlockDc(Dc
);
393 NtGdiSetDIBitsToDeviceInternal(
408 IN BOOL bTransformCoordinates
,
409 IN OPTIONAL HANDLE hcmXform
)
412 NTSTATUS Status
= STATUS_SUCCESS
;
414 HBITMAP hSourceBitmap
= NULL
;
415 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
422 PPALETTE ppalDIB
= NULL
;
423 HPALETTE hpalDIB
= NULL
;
429 ProbeForRead(bmi
, cjMaxInfo
, 1);
430 ProbeForRead(Bits
, cjMaxBits
, 1);
432 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
434 Status
= _SEH2_GetExceptionCode();
438 if (!NT_SUCCESS(Status
))
443 pDC
= DC_LockDc(hDC
);
446 EngSetLastError(ERROR_INVALID_HANDLE
);
449 if (pDC
->dctype
== DC_TYPE_INFO
)
455 pSurf
= pDC
->dclevel
.pSurface
;
457 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
459 ScanLines
= min(ScanLines
, abs(bmi
->bmiHeader
.biHeight
) - StartScan
);
463 if (bTransformCoordinates
)
465 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
467 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
468 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
469 rcDest
.right
= rcDest
.left
+ Width
;
470 rcDest
.bottom
= rcDest
.top
+ Height
;
471 rcDest
.top
+= StartScan
;
476 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
477 SourceSize
.cy
= ScanLines
;
479 DIBWidth
= WIDTH_BYTES_ALIGN32(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
481 hSourceBitmap
= EngCreateBitmap(SourceSize
,
483 BitmapFormat(bmi
->bmiHeader
.biBitCount
,
484 bmi
->bmiHeader
.biCompression
),
485 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
489 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
490 Status
= STATUS_NO_MEMORY
;
494 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
497 Status
= STATUS_UNSUCCESSFUL
;
503 /* Create a palette for the DIB */
504 hpalDIB
= BuildDIBPalette(bmi
);
507 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
508 Status
= STATUS_NO_MEMORY
;
512 /* Lock the DIB palette */
513 ppalDIB
= PALETTE_LockPalette(hpalDIB
);
516 EngSetLastError(ERROR_INVALID_HANDLE
);
517 Status
= STATUS_UNSUCCESSFUL
;
521 /* Initialize EXLATEOBJ */
522 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, pSurf
->ppal
, 0, 0, 0);
525 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
526 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
527 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
528 Status
= IntEngBitBlt(pDestSurf
,
531 pDC
->rosdc
.CombinedClip
,
538 ROP4_FROM_INDEX(R3_OPINDEX_SRCCOPY
));
540 /* Cleanup EXLATEOBJ */
541 EXLATEOBJ_vCleanup(&exlo
);
544 if (NT_SUCCESS(Status
))
549 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
551 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
552 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
553 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
560 /* Converts a device-dependent bitmap to a DIB */
563 NtGdiGetDIBitsInternal(
574 BITMAPCOREINFO
* pbmci
= NULL
;
575 PSURFACE psurf
= NULL
;
581 RGBTRIPLE
* rgbTriples
;
584 NTSTATUS Status
= STATUS_SUCCESS
;
586 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
588 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
593 /* Probe for read and write */
594 ProbeForRead(Info
, MaxInfo
, 1);
595 ProbeForWrite(Info
, MaxInfo
, 1);
596 if (Bits
) ProbeForWrite(Bits
, MaxBits
, 1);
598 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
600 Status
= _SEH2_GetExceptionCode();
604 if (!NT_SUCCESS(Status
))
609 colorPtr
= (LPBYTE
)Info
+ Info
->bmiHeader
.biSize
;
610 rgbTriples
= colorPtr
;
613 bitmap_type
= DIB_GetBitmapInfo(&Info
->bmiHeader
,
620 if(bitmap_type
== -1)
622 DPRINT("Wrong bitmap format\n");
623 EngSetLastError(ERROR_INVALID_PARAMETER
);
626 else if(bitmap_type
== 0)
628 /* We need a BITMAPINFO to create a DIB, but we have to fill
629 * the BITMAPCOREINFO we're provided */
630 pbmci
= (BITMAPCOREINFO
*)Info
;
631 Info
= DIB_ConvertBitmapInfo((BITMAPINFO
*)pbmci
, Usage
);
634 DPRINT1("Error, could not convert the BITMAPCOREINFO!\n");
637 rgbQuads
= Info
->bmiColors
;
640 pDC
= DC_LockDc(hDC
);
641 if (pDC
== NULL
|| pDC
->dctype
== DC_TYPE_INFO
)
647 /* Get a pointer to the source bitmap object */
648 psurf
= SURFACE_ShareLockSurface(hBitmap
);
655 /* Fill in the structure */
658 case 0: /* Only info */
661 pbmci
->bmciHeader
.bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
662 pbmci
->bmciHeader
.bcHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
663 -psurf
->SurfObj
.sizlBitmap
.cy
:
664 psurf
->SurfObj
.sizlBitmap
.cy
;
665 pbmci
->bmciHeader
.bcPlanes
= 1;
666 pbmci
->bmciHeader
.bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
668 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
669 Info
->bmiHeader
.biHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
670 -psurf
->SurfObj
.sizlBitmap
.cy
:
671 psurf
->SurfObj
.sizlBitmap
.cy
;;
672 Info
->bmiHeader
.biPlanes
= 1;
673 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
674 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes( Info
->bmiHeader
.biWidth
,
675 Info
->bmiHeader
.biHeight
,
676 Info
->bmiHeader
.biBitCount
);
679 switch(Info
->bmiHeader
.biBitCount
)
683 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
686 Info
->bmiHeader
.biCompression
= BI_RGB
;
690 else if(Info
->bmiHeader
.biBitCount
> 8)
692 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
696 Info
->bmiHeader
.biCompression
= BI_RGB
;
698 Info
->bmiHeader
.biXPelsPerMeter
= 0;
699 Info
->bmiHeader
.biYPelsPerMeter
= 0;
700 Info
->bmiHeader
.biClrUsed
= 0;
701 Info
->bmiHeader
.biClrImportant
= 0;
702 ScanLines
= abs(Info
->bmiHeader
.biHeight
);
708 Info
->bmiHeader
.biClrUsed
= 0;
710 /* If the bitmap if a DIB section and has the same format than what
711 * we're asked, go ahead! */
712 if((psurf
->hSecure
) &&
713 (BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == bpp
))
715 if(Usage
== DIB_RGB_COLORS
)
717 unsigned int colors
= min(psurf
->ppal
->NumColors
, 1 << bpp
);
721 for(i
=0; i
< colors
; i
++)
723 rgbTriples
[i
].rgbtRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
724 rgbTriples
[i
].rgbtGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
725 rgbTriples
[i
].rgbtBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
728 if(colors
!= 1 << bpp
) Info
->bmiHeader
.biClrUsed
= colors
;
729 for(i
=0; i
< colors
; i
++)
731 rgbQuads
[i
].rgbRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
732 rgbQuads
[i
].rgbGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
733 rgbQuads
[i
].rgbBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
738 for(i
=0; i
< 1 << bpp
; i
++)
740 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
741 ((WORD
*)rgbQuads
)[i
] = i
;
747 if(Usage
== DIB_PAL_COLORS
)
749 for(i
=0; i
< 1 << bpp
; i
++)
751 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
752 ((WORD
*)rgbQuads
)[i
] = i
;
755 else if(bpp
> 1 && bpp
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
))
757 /* For color DDBs in native depth (mono DDBs always have
758 a black/white palette):
759 Generate the color map from the selected palette */
760 PPALETTE pDcPal
= PALETTE_LockPalette(pDC
->dclevel
.hpal
);
766 for (i
= 0; i
< pDcPal
->NumColors
; i
++)
770 rgbTriples
[i
].rgbtRed
= pDcPal
->IndexedColors
[i
].peRed
;
771 rgbTriples
[i
].rgbtGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
772 rgbTriples
[i
].rgbtBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
775 rgbQuads
[i
].rgbRed
= pDcPal
->IndexedColors
[i
].peRed
;
776 rgbQuads
[i
].rgbGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
777 rgbQuads
[i
].rgbBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
778 rgbQuads
[i
].rgbReserved
= 0;
780 PALETTE_UnlockPalette(pDcPal
);
789 rgbTriples
[0].rgbtRed
= rgbTriples
[0].rgbtGreen
=
790 rgbTriples
[0].rgbtBlue
= 0;
791 rgbTriples
[1].rgbtRed
= rgbTriples
[1].rgbtGreen
=
792 rgbTriples
[1].rgbtBlue
= 0xff;
794 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
=
795 rgbQuads
[0].rgbBlue
= 0;
796 rgbQuads
[0].rgbReserved
= 0;
797 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
=
798 rgbQuads
[1].rgbBlue
= 0xff;
799 rgbQuads
[1].rgbReserved
= 0;
804 RtlCopyMemory(rgbTriples
, EGAColorsTriples
, sizeof(EGAColorsTriples
));
805 RtlCopyMemory(rgbQuads
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
815 RGBTRIPLE
*colorTriple
;
817 RtlCopyMemory(rgbTriples
, DefLogPaletteTriples
,
818 10 * sizeof(RGBTRIPLE
));
819 RtlCopyMemory(rgbTriples
+ 246, DefLogPaletteTriples
+ 10,
820 10 * sizeof(RGBTRIPLE
));
821 colorTriple
= rgbTriples
+ 10;
822 for(r
= 0; r
<= 5; r
++) /* FIXME */
824 for(g
= 0; g
<= 5; g
++)
826 for(b
= 0; b
<= 5; b
++)
828 colorTriple
->rgbtRed
= (r
* 0xff) / 5;
829 colorTriple
->rgbtGreen
= (g
* 0xff) / 5;
830 colorTriple
->rgbtBlue
= (b
* 0xff) / 5;
836 memcpy(rgbQuads
, DefLogPaletteQuads
,
837 10 * sizeof(RGBQUAD
));
838 memcpy(rgbQuads
+ 246, DefLogPaletteQuads
+ 10,
839 10 * sizeof(RGBQUAD
));
840 color
= rgbQuads
+ 10;
841 for(r
= 0; r
<= 5; r
++) /* FIXME */
843 for(g
= 0; g
<= 5; g
++)
845 for(b
= 0; b
<= 5; b
++)
847 color
->rgbRed
= (r
* 0xff) / 5;
848 color
->rgbGreen
= (g
* 0xff) / 5;
849 color
->rgbBlue
= (b
* 0xff) / 5;
850 color
->rgbReserved
= 0;
862 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
864 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
865 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
866 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
871 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
875 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
876 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
877 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
881 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
882 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
883 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
890 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
894 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
895 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
896 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
900 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
901 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
902 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
907 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(width
, height
, bpp
);
909 if(Bits
&& ScanLines
)
911 /* Create a DIBSECTION, blt it, profit */
920 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
927 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
931 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
932 Info
->bmiHeader
.biHeight
= height
< 0 ?
933 -ScanLines
: ScanLines
;
935 hBmpDest
= DIB_CreateDIBSection(pDC
, Info
, Usage
, &pDIBits
, NULL
, 0, 0);
937 Info
->bmiHeader
.biWidth
= width
;
938 Info
->bmiHeader
.biHeight
= height
;
942 DPRINT1("Unable to create a DIB Section!\n");
943 EngSetLastError(ERROR_INVALID_PARAMETER
);
948 psurfDest
= SURFACE_ShareLockSurface(hBmpDest
);
952 rcDest
.bottom
= ScanLines
;
953 rcDest
.right
= psurf
->SurfObj
.sizlBitmap
.cx
;
961 if(ScanLines
<= StartScan
)
964 SURFACE_ShareUnlockSurface(psurfDest
);
965 GreDeleteObject(hBmpDest
);
969 ScanLines
-= StartScan
;
973 srcPoint
.y
= StartScan
;
976 EXLATEOBJ_vInitialize(&exlo
, psurf
->ppal
, psurfDest
->ppal
, 0xffffff, 0xffffff, 0);
978 ret
= IntEngCopyBits(&psurfDest
->SurfObj
,
985 SURFACE_ShareUnlockSurface(psurfDest
);
991 Status
= STATUS_SUCCESS
;
994 RtlCopyMemory(Bits
, pDIBits
, DIB_GetDIBImageBytes (width
, ScanLines
, bpp
));
996 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
998 Status
= _SEH2_GetExceptionCode();
1002 if(!NT_SUCCESS(Status
))
1004 DPRINT1("Unable to copy bits to the user provided pointer\n");
1009 GreDeleteObject(hBmpDest
);
1010 EXLATEOBJ_vCleanup(&exlo
);
1012 else ScanLines
= abs(height
);
1016 if(pDC
) DC_UnlockDc(pDC
);
1017 if(psurf
) SURFACE_ShareUnlockSurface(psurf
);
1018 if(pbmci
) DIB_FreeConvertedBitmapInfo(Info
, (BITMAPINFO
*)pbmci
);
1026 NtGdiStretchDIBitsInternal(
1037 LPBITMAPINFO BitsInfo
,
1056 if (!Bits
|| !BitsInfo
)
1059 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1062 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1068 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1069 ProbeForRead(Bits
, cjMaxBits
, 1);
1070 if (DIB_GetBitmapInfo(&BitsInfo
->bmiHeader
, &width
, &height
, &planes
, &bpp
, &compr
, &size
) == -1)
1072 DPRINT1("Invalid bitmap\n");
1073 _SEH2_YIELD(goto cleanup
;)
1075 RtlCopyMemory(safeBits
, Bits
, cjMaxBits
);
1077 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1079 DPRINT1("Error, failed to read the DIB bits\n");
1080 _SEH2_YIELD(goto cleanup
;)
1086 DPRINT1("Bitmap has a negative width\n");
1090 hBitmap
= NtGdiGetDCObject(hDC
, OBJ_BITMAP
);
1092 if (!(pdc
= DC_LockDc(hDC
)))
1094 ExFreePoolWithTag(safeBits
, TAG_DIB
);
1095 EngSetLastError(ERROR_INVALID_HANDLE
);
1099 if (XDest
== 0 && YDest
== 0 && XSrc
== 0 && XSrc
== 0 &&
1100 DestWidth
== SrcWidth
&& DestHeight
== SrcHeight
&&
1105 ret
= IntGdiGetObject(hBitmap
, sizeof(bmp
), &bmp
) == sizeof(bmp
);
1107 bmp
.bmBitsPixel
== bpp
&&
1108 bmp
.bmWidth
== SrcWidth
&&
1109 bmp
.bmHeight
== SrcHeight
&&
1110 bmp
.bmPlanes
== planes
)
1113 ret
= IntSetDIBits(pdc
, hBitmap
, 0, height
, safeBits
, BitsInfo
, Usage
);
1119 /* slow path - need to use StretchBlt */
1121 hBitmap
= DIB_CreateDIBSection(pdc
, BitsInfo
, Usage
, &pvBits
, NULL
, 0, 0);
1126 DPRINT1("Error, failed to create a DIB section\n");
1130 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1132 RtlCopyMemory(pvBits
, safeBits
, cjMaxBits
);
1133 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1135 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1136 left (negative biHeight) */
1137 ret
= NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1138 hdcMem
, XSrc
, abs(height
) - SrcHeight
- YSrc
,
1139 SrcWidth
, SrcHeight
, ROP
, 0);
1143 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1144 NtGdiDeleteObjectApp(hdcMem
);
1145 GreDeleteObject(hBitmap
);
1148 ExFreePoolWithTag(safeBits
, TAG_DIB
);
1168 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1169 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1171 if (bpp
!= 1) fColor
= TRUE
;
1172 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1175 const RGBQUAD
*rgb
= (RGBQUAD
*)((PBYTE
)data
+ data
->bmiHeader
.biSize
);
1176 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1178 // Check if the first color of the colormap is black
1179 if ((col
== RGB(0, 0, 0)))
1182 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1184 // If the second color is white, create a monochrome bitmap
1185 fColor
= (col
!= RGB(0xff,0xff,0xff));
1190 // Now create the bitmap
1193 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1197 handle
= GreCreateBitmap(width
,
1207 if (NULL
!= handle
&& CBM_INIT
== init
)
1209 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1215 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1216 // The DDB that is created will be whatever bit depth your reference DC is
1219 NtGdiCreateDIBitmapInternal(
1224 IN OPTIONAL LPBYTE pjInit
,
1225 IN OPTIONAL LPBITMAPINFO pbmi
,
1227 IN UINT cjMaxInitInfo
,
1232 NTSTATUS Status
= STATUS_SUCCESS
;
1233 PBYTE safeBits
= NULL
;
1234 HBITMAP hbmResult
= NULL
;
1236 if(pjInit
&& (fInit
== CBM_INIT
))
1238 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1241 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1248 if(pbmi
) ProbeForRead(pbmi
, cjMaxInitInfo
, 1);
1249 if(pjInit
&& (fInit
== CBM_INIT
))
1251 ProbeForRead(pjInit
, cjMaxBits
, 1);
1252 RtlCopyMemory(safeBits
, pjInit
, cjMaxBits
);
1255 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1257 Status
= _SEH2_GetExceptionCode();
1261 if(!NT_SUCCESS(Status
))
1263 SetLastNtError(Status
);
1267 hbmResult
= GreCreateDIBitmapInternal(hDc
,
1278 if (safeBits
) ExFreePoolWithTag(safeBits
, TAG_DIB
);
1284 GreCreateDIBitmapInternal(
1289 IN OPTIONAL LPBYTE pjInit
,
1290 IN OPTIONAL PBITMAPINFO pbmi
,
1300 if (!hDc
) /* 1bpp monochrome bitmap */
1302 // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1303 hdcDest
= NtGdiCreateCompatibleDC(0);
1314 Dc
= DC_LockDc(hdcDest
);
1317 EngSetLastError(ERROR_INVALID_HANDLE
);
1320 /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
1321 * if bpp != 1 and ignore the real value that was passed */
1323 bpp
= pbmi
->bmiHeader
.biBitCount
;
1326 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1331 NtGdiDeleteObjectApp(hdcDest
);
1339 NtGdiCreateDIBSection(
1341 IN OPTIONAL HANDLE hSection
,
1347 IN ULONG_PTR dwColorSpace
,
1350 HBITMAP hbitmap
= 0;
1352 BOOL bDesktopDC
= FALSE
;
1353 NTSTATUS Status
= STATUS_SUCCESS
;
1355 if (!bmi
) return hbitmap
; // Make sure.
1359 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
1360 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
1361 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, Usage
), 1);
1363 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1365 Status
= _SEH2_GetExceptionCode();
1369 if(!NT_SUCCESS(Status
))
1371 SetLastNtError(Status
);
1375 // If the reference hdc is null, take the desktop dc
1378 hDC
= NtGdiCreateCompatibleDC(0);
1382 if ((dc
= DC_LockDc(hDC
)))
1384 hbitmap
= DIB_CreateDIBSection(dc
,
1395 EngSetLastError(ERROR_INVALID_HANDLE
);
1399 NtGdiDeleteObjectApp(hDC
);
1406 DIB_CreateDIBSection(
1408 CONST BITMAPINFO
*bmi
,
1416 SURFACE
*bmp
= NULL
;
1417 void *mapBits
= NULL
;
1420 // Fill BITMAP32 structure with DIB data
1421 CONST BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1428 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1429 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1430 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1432 /* CreateDIBSection should fail for compressed formats */
1433 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1435 return (HBITMAP
)NULL
;
1438 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1440 bm
.bmWidth
= bi
->biWidth
;
1441 bm
.bmHeight
= effHeight
;
1442 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: WIDTH_BYTES_ALIGN32(bm
.bmWidth
, bi
->biBitCount
);
1444 bm
.bmPlanes
= bi
->biPlanes
;
1445 bm
.bmBitsPixel
= bi
->biBitCount
;
1448 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1449 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1450 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
&& bi
->biCompression
!= BI_BITFIELDS
1451 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1455 SYSTEM_BASIC_INFORMATION Sbi
;
1458 LARGE_INTEGER SectionOffset
;
1461 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1465 if (!NT_SUCCESS(Status
))
1470 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1471 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1473 SectionOffset
.LowPart
= mapOffset
;
1474 SectionOffset
.HighPart
= 0;
1476 Status
= ZwMapViewOfSection(section
,
1486 if (!NT_SUCCESS(Status
))
1488 EngSetLastError(ERROR_INVALID_PARAMETER
);
1492 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1494 else if (ovr_pitch
&& offset
)
1495 bm
.bmBits
= (LPVOID
) offset
;
1499 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1500 if(!bm
.bmBits
) goto cleanup
;
1503 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1504 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1506 if (usage
== DIB_PAL_COLORS
)
1511 pdcPal
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1512 hpal
= DIB_MapPaletteColors(pdcPal
, bmi
);
1513 PALETTE_UnlockPalette(pdcPal
);
1517 /* For DIB Brushes */
1518 DPRINT1("FIXME : Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
1520 hpal
= (HPALETTE
) 0xFFFFFFFF;
1525 hpal
= BuildDIBPalette(bmi
);
1530 DPRINT1("Error : Could not create a palette for the DIB.\n");
1534 // Create Device Dependent Bitmap and add DIB pointer
1535 Size
.cx
= bm
.bmWidth
;
1536 Size
.cy
= abs(bm
.bmHeight
);
1537 res
= GreCreateBitmapEx(bm
.bmWidth
,
1540 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1541 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1542 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1548 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1551 bmp
= SURFACE_LockSurface(res
);
1554 EngSetLastError(ERROR_INVALID_HANDLE
);
1558 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1559 table between the DIB and the X physical device. Obviously,
1560 this is left out of the ReactOS implementation. Instead,
1561 we call NtGdiSetDIBColorTable. */
1562 bmp
->hDIBSection
= section
;
1563 bmp
->hSecure
= hSecure
;
1564 bmp
->dwOffset
= offset
;
1565 bmp
->flags
= API_BITMAP
;
1566 bmp
->biClrImportant
= bi
->biClrImportant
;
1567 bmp
->SurfObj
.fjBitmap
&= ~BMF_DONT_FREE
;
1570 if(hpal
!= (HPALETTE
)0xFFFFFFFF)
1572 bmp
->ppal
= PALETTE_ShareLockPalette(hpal
);
1573 /* Lazy delete hpal, it will be freed at surface release */
1574 GreDeleteObject(hpal
);
1577 // Clean up in case of errors
1579 if (!res
|| !bmp
|| !bm
.bmBits
)
1581 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1584 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1587 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1591 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1599 SURFACE_FreeSurfaceByHandle(res
);
1606 SURFACE_UnlockSurface(bmp
);
1609 // Return BITMAP handle and storage location
1610 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1618 /***********************************************************************
1621 * Get the info from a bitmap header.
1622 * Return 0 for COREHEADER, 1 for INFOHEADER, -1 for error.
1626 DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
1627 LONG
*height
, WORD
*planes
, WORD
*bpp
, DWORD
*compr
, DWORD
*size
)
1629 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
1631 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
1632 *width
= core
->bcWidth
;
1633 *height
= core
->bcHeight
;
1634 *planes
= core
->bcPlanes
;
1635 *bpp
= core
->bcBitCount
;
1640 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
)) /* assume BITMAPINFOHEADER */
1642 *width
= header
->biWidth
;
1643 *height
= header
->biHeight
;
1644 *planes
= header
->biPlanes
;
1645 *bpp
= header
->biBitCount
;
1646 *compr
= header
->biCompression
;
1647 *size
= header
->biSizeImage
;
1650 DPRINT1("(%d): unknown/wrong size for header\n", header
->biSize
);
1654 /***********************************************************************
1655 * DIB_GetDIBImageBytes
1657 * Return the number of bytes used to hold the image in a DIB bitmap.
1658 * 11/16/1999 (RJJ) lifted from wine
1661 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1663 return WIDTH_BYTES_ALIGN32(width
, depth
) * (height
< 0 ? -height
: height
);
1666 /***********************************************************************
1667 * DIB_BitmapInfoSize
1669 * Return the size of the bitmap info structure including color table.
1670 * 11/16/1999 (RJJ) lifted from wine
1673 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1675 unsigned int colors
, size
, masks
= 0;
1677 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1679 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
1680 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1681 return sizeof(BITMAPCOREHEADER
) + colors
*
1682 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1684 else /* assume BITMAPINFOHEADER */
1686 colors
= info
->bmiHeader
.biClrUsed
;
1687 if (colors
> 256) colors
= 256;
1688 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
1689 colors
= 1 << info
->bmiHeader
.biBitCount
;
1690 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
1691 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
1692 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1698 DIB_MapPaletteColors(PPALETTE ppal
, CONST BITMAPINFO
* lpbmi
)
1700 PALETTEENTRY
* ppalEntries
;
1705 if (!(ppal
->flFlags
& PAL_INDEXED
))
1710 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1711 if (lpbmi
->bmiHeader
.biClrUsed
)
1713 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1716 /* Don't have more colors than we need */
1717 nNumColors
= min(ppal
->NumColors
, nNumColors
);
1719 ppalEntries
= ExAllocatePoolWithTag(PagedPool
, sizeof(PALETTEENTRY
) * nNumColors
, TAG_COLORMAP
);
1720 if (ppalEntries
== NULL
)
1722 DPRINT1("Could not allocate palette entries\n");
1726 lpIndex
= (USHORT
*)((PBYTE
)lpbmi
+ lpbmi
->bmiHeader
.biSize
);
1728 for (i
= 0; i
< nNumColors
; i
++)
1730 if (*lpIndex
< ppal
->NumColors
)
1732 ppalEntries
[i
] = ppal
->IndexedColors
[*lpIndex
];
1736 ppalEntries
[i
].peRed
= 0;
1737 ppalEntries
[i
].peGreen
= 0;
1738 ppalEntries
[i
].peBlue
= 0;
1739 ppalEntries
[i
].peFlags
= 0;
1745 hpal
= PALETTE_AllocPalette(PAL_INDEXED
, nNumColors
, (ULONG
*)ppalEntries
, 0, 0, 0);
1747 ExFreePoolWithTag(ppalEntries
, TAG_COLORMAP
);
1754 BuildDIBPalette(CONST BITMAPINFO
*bmi
)
1759 ULONG RedMask
= 0, GreenMask
= 0, BlueMask
= 0;
1760 PDWORD pdwColors
= (PDWORD
)((PBYTE
)bmi
+ bmi
->bmiHeader
.biSize
);
1763 // Determine Bits Per Pixel
1764 bits
= bmi
->bmiHeader
.biBitCount
;
1766 // Determine paletteType from Bits Per Pixel
1769 paletteType
= PAL_INDEXED
;
1770 RedMask
= GreenMask
= BlueMask
= 0;
1772 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1774 paletteType
= PAL_BITFIELDS
;
1775 if (bmi
->bmiHeader
.biSize
>= sizeof(BITMAPV4HEADER
))
1777 PBITMAPV4HEADER pV4Header
= (PBITMAPV4HEADER
)&bmi
->bmiHeader
;
1778 RedMask
= pV4Header
->bV4RedMask
;
1779 GreenMask
= pV4Header
->bV4GreenMask
;
1780 BlueMask
= pV4Header
->bV4BlueMask
;
1784 RedMask
= pdwColors
[0];
1785 GreenMask
= pdwColors
[1];
1786 BlueMask
= pdwColors
[2];
1791 paletteType
= PAL_BITFIELDS
;
1795 paletteType
|= PAL_RGB16_555
;
1803 paletteType
|= PAL_BGR
;
1805 GreenMask
= 0x00FF00;
1806 BlueMask
= 0x0000FF;
1811 if (bmi
->bmiHeader
.biClrUsed
== 0)
1813 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1817 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1820 if (PAL_INDEXED
== paletteType
)
1822 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)pdwColors
);
1826 hPal
= PALETTE_AllocPalette(paletteType
, 0,
1828 RedMask
, GreenMask
, BlueMask
);
1834 /* Converts a BITMAPCOREINFO to a BITMAPINFO structure,
1835 * or does nothing if it's already a BITMAPINFO (or V4 or V5) */
1838 DIB_ConvertBitmapInfo (CONST BITMAPINFO
* pbmi
, DWORD Usage
)
1840 CONST BITMAPCOREINFO
* pbmci
= (BITMAPCOREINFO
*)pbmi
;
1841 BITMAPINFO
* pNewBmi
;
1842 UINT numColors
= 0, ColorsSize
= 0;
1844 if(pbmi
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
)) return (BITMAPINFO
*)pbmi
;
1845 if(pbmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) return NULL
;
1847 if(pbmci
->bmciHeader
.bcBitCount
<= 8)
1849 numColors
= 1 << pbmci
->bmciHeader
.bcBitCount
;
1850 if(Usage
== DIB_PAL_COLORS
)
1852 ColorsSize
= numColors
* sizeof(WORD
);
1856 ColorsSize
= numColors
* sizeof(RGBQUAD
);
1859 else if (Usage
== DIB_PAL_COLORS
)
1861 /* Invalid at high Res */
1865 pNewBmi
= ExAllocatePoolWithTag(PagedPool
, sizeof(BITMAPINFOHEADER
) + ColorsSize
, TAG_DIB
);
1866 if(!pNewBmi
) return NULL
;
1868 RtlZeroMemory(pNewBmi
, sizeof(BITMAPINFOHEADER
) + ColorsSize
);
1870 pNewBmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1871 pNewBmi
->bmiHeader
.biBitCount
= pbmci
->bmciHeader
.bcBitCount
;
1872 pNewBmi
->bmiHeader
.biWidth
= pbmci
->bmciHeader
.bcWidth
;
1873 pNewBmi
->bmiHeader
.biHeight
= pbmci
->bmciHeader
.bcHeight
;
1874 pNewBmi
->bmiHeader
.biPlanes
= pbmci
->bmciHeader
.bcPlanes
;
1875 pNewBmi
->bmiHeader
.biCompression
= BI_RGB
;
1876 pNewBmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(pNewBmi
->bmiHeader
.biWidth
,
1877 pNewBmi
->bmiHeader
.biHeight
,
1878 pNewBmi
->bmiHeader
.biBitCount
);
1880 if(Usage
== DIB_PAL_COLORS
)
1882 RtlCopyMemory(pNewBmi
->bmiColors
, pbmci
->bmciColors
, ColorsSize
);
1887 for(i
=0; i
<numColors
; i
++)
1889 pNewBmi
->bmiColors
[i
].rgbRed
= pbmci
->bmciColors
[i
].rgbtRed
;
1890 pNewBmi
->bmiColors
[i
].rgbGreen
= pbmci
->bmciColors
[i
].rgbtGreen
;
1891 pNewBmi
->bmiColors
[i
].rgbBlue
= pbmci
->bmciColors
[i
].rgbtBlue
;
1898 /* Frees a BITMAPINFO created with DIB_ConvertBitmapInfo */
1901 DIB_FreeConvertedBitmapInfo(BITMAPINFO
* converted
, BITMAPINFO
* orig
)
1903 if(converted
!= orig
)
1904 ExFreePoolWithTag(converted
, TAG_DIB
);