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;
199 if (!(dc
= DC_LockDc(hDC
))) return 0;
200 if (dc
->dctype
== DC_TYPE_INFO
)
206 psurf
= dc
->dclevel
.pSurface
;
210 EngSetLastError(ERROR_INVALID_PARAMETER
);
214 if (psurf
->hSecure
== NULL
)
217 EngSetLastError(ERROR_INVALID_PARAMETER
);
224 if (ppal
->flFlags
& PAL_INDEXED
)
227 for (Index
= StartIndex
;
228 Index
< StartIndex
+ Entries
&& Index
< ppal
->NumColors
;
231 Colors
[Index
- StartIndex
].rgbRed
= ppal
->IndexedColors
[Index
].peRed
;
232 Colors
[Index
- StartIndex
].rgbGreen
= ppal
->IndexedColors
[Index
].peGreen
;
233 Colors
[Index
- StartIndex
].rgbBlue
= ppal
->IndexedColors
[Index
].peBlue
;
234 Colors
[Index
- StartIndex
].rgbReserved
= 0;
244 // Converts a DIB to a device-dependent bitmap
253 CONST BITMAPINFO
*bmi
,
256 HBITMAP SourceBitmap
;
257 PSURFACE psurfDst
, psurfSrc
;
264 SourceBitmap
= DIB_CreateDIBSection(DC
, bmi
, ColorUse
, &pvBits
, NULL
, 0, 0);
265 if (0 == SourceBitmap
)
267 DPRINT1("Error : Could not create a DIBSection.\n");
268 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
272 RtlCopyMemory(pvBits
, Bits
, DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
,
273 bmi
->bmiHeader
.biHeight
,
274 bmi
->bmiHeader
.biBitCount
));
276 psurfDst
= SURFACE_LockSurface(hBitmap
);
277 psurfSrc
= SURFACE_LockSurface(SourceBitmap
);
279 if(!(psurfSrc
&& psurfDst
))
281 DPRINT1("Error, could not lock surfaces\n");
285 rcDst
.top
= bmi
->bmiHeader
.biHeight
< 0 ?
286 abs(bmi
->bmiHeader
.biHeight
) - (ScanLines
+ StartScan
) : StartScan
;
288 rcDst
.bottom
= rcDst
.top
+ ScanLines
;
289 rcDst
.right
= psurfDst
->SurfObj
.sizlBitmap
.cx
;
294 EXLATEOBJ_vInitialize(&exlo
, psurfSrc
->ppal
, psurfDst
->ppal
, 0, 0, 0);
296 result
= IntEngCopyBits(&psurfDst
->SurfObj
,
305 EXLATEOBJ_vCleanup(&exlo
);
310 SURFACE_UnlockSurface(psurfSrc
);
314 SURFACE_UnlockSurface(psurfDst
);
316 GreDeleteObject(SourceBitmap
);
321 // FIXME by Removing NtGdiSetDIBits!!!
322 // This is a victim of the Win32k Initialization BUG!!!!!
323 // Converts a DIB to a device-dependent bitmap
332 CONST BITMAPINFO
*bmi
,
337 NTSTATUS Status
= STATUS_SUCCESS
;
343 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
344 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
345 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, ColorUse
), 1);
347 DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
,
349 bmi
->bmiHeader
.biBitCount
),
352 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
354 Status
= _SEH2_GetExceptionCode();
358 if (!NT_SUCCESS(Status
))
366 EngSetLastError(ERROR_INVALID_HANDLE
);
369 if (Dc
->dctype
== DC_TYPE_INFO
)
375 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
385 NtGdiSetDIBitsToDeviceInternal(
400 IN BOOL bTransformCoordinates
,
401 IN OPTIONAL HANDLE hcmXform
)
404 NTSTATUS Status
= STATUS_SUCCESS
;
406 HBITMAP hSourceBitmap
= NULL
;
407 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
414 PPALETTE ppalDIB
= NULL
;
415 HPALETTE hpalDIB
= NULL
;
421 ProbeForRead(bmi
, cjMaxInfo
, 1);
422 ProbeForRead(Bits
, cjMaxBits
, 1);
424 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
426 Status
= _SEH2_GetExceptionCode();
430 if (!NT_SUCCESS(Status
))
435 pDC
= DC_LockDc(hDC
);
438 EngSetLastError(ERROR_INVALID_HANDLE
);
441 if (pDC
->dctype
== DC_TYPE_INFO
)
447 pSurf
= pDC
->dclevel
.pSurface
;
449 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
451 ScanLines
= min(ScanLines
, abs(bmi
->bmiHeader
.biHeight
) - StartScan
);
455 if (bTransformCoordinates
)
457 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
459 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
460 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
461 rcDest
.right
= rcDest
.left
+ Width
;
462 rcDest
.bottom
= rcDest
.top
+ Height
;
463 rcDest
.top
+= StartScan
;
468 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
469 SourceSize
.cy
= ScanLines
;
471 DIBWidth
= WIDTH_BYTES_ALIGN32(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
473 hSourceBitmap
= EngCreateBitmap(SourceSize
,
475 BitmapFormat(bmi
->bmiHeader
.biBitCount
,
476 bmi
->bmiHeader
.biCompression
),
477 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
481 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
482 Status
= STATUS_NO_MEMORY
;
486 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
489 Status
= STATUS_UNSUCCESSFUL
;
495 /* Create a palette for the DIB */
496 hpalDIB
= BuildDIBPalette(bmi
);
499 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
500 Status
= STATUS_NO_MEMORY
;
504 /* Lock the DIB palette */
505 ppalDIB
= PALETTE_LockPalette(hpalDIB
);
508 EngSetLastError(ERROR_INVALID_HANDLE
);
509 Status
= STATUS_UNSUCCESSFUL
;
513 /* Initialize EXLATEOBJ */
514 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, pSurf
->ppal
, 0, 0, 0);
517 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
518 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
519 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
520 Status
= IntEngBitBlt(pDestSurf
,
523 pDC
->rosdc
.CombinedClip
,
530 ROP3_TO_ROP4(SRCCOPY
));
532 /* Cleanup EXLATEOBJ */
533 EXLATEOBJ_vCleanup(&exlo
);
536 if (NT_SUCCESS(Status
))
541 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
543 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
544 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
545 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
552 /* Converts a device-dependent bitmap to a DIB */
555 NtGdiGetDIBitsInternal(
566 BITMAPCOREINFO
* pbmci
= NULL
;
567 PSURFACE psurf
= NULL
;
573 RGBTRIPLE
* rgbTriples
;
576 NTSTATUS Status
= STATUS_SUCCESS
;
578 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
580 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
585 /* Probe for read and write */
586 ProbeForRead(Info
, MaxInfo
, 1);
587 ProbeForWrite(Info
, MaxInfo
, 1);
588 if (Bits
) ProbeForWrite(Bits
, MaxBits
, 1);
590 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
592 Status
= _SEH2_GetExceptionCode();
596 if (!NT_SUCCESS(Status
))
601 colorPtr
= (LPBYTE
)Info
+ Info
->bmiHeader
.biSize
;
602 rgbTriples
= colorPtr
;
605 bitmap_type
= DIB_GetBitmapInfo(&Info
->bmiHeader
,
612 if(bitmap_type
== -1)
614 DPRINT("Wrong bitmap format\n");
615 EngSetLastError(ERROR_INVALID_PARAMETER
);
618 else if(bitmap_type
== 0)
620 /* We need a BITMAPINFO to create a DIB, but we have to fill
621 * the BITMAPCOREINFO we're provided */
622 pbmci
= (BITMAPCOREINFO
*)Info
;
623 Info
= DIB_ConvertBitmapInfo((BITMAPINFO
*)pbmci
, Usage
);
626 DPRINT1("Error, could not convert the BITMAPCOREINFO!\n");
629 rgbQuads
= Info
->bmiColors
;
632 pDC
= DC_LockDc(hDC
);
633 if (pDC
== NULL
|| pDC
->dctype
== DC_TYPE_INFO
)
639 /* Get a pointer to the source bitmap object */
640 psurf
= SURFACE_ShareLockSurface(hBitmap
);
647 /* Fill in the structure */
650 case 0: /* Only info */
653 pbmci
->bmciHeader
.bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
654 pbmci
->bmciHeader
.bcHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
655 -psurf
->SurfObj
.sizlBitmap
.cy
:
656 psurf
->SurfObj
.sizlBitmap
.cy
;
657 pbmci
->bmciHeader
.bcPlanes
= 1;
658 pbmci
->bmciHeader
.bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
660 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
661 Info
->bmiHeader
.biHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
662 -psurf
->SurfObj
.sizlBitmap
.cy
:
663 psurf
->SurfObj
.sizlBitmap
.cy
;;
664 Info
->bmiHeader
.biPlanes
= 1;
665 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
666 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes( Info
->bmiHeader
.biWidth
,
667 Info
->bmiHeader
.biHeight
,
668 Info
->bmiHeader
.biBitCount
);
671 switch(Info
->bmiHeader
.biBitCount
)
675 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
678 Info
->bmiHeader
.biCompression
= BI_RGB
;
682 else if(Info
->bmiHeader
.biBitCount
> 8)
684 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
688 Info
->bmiHeader
.biCompression
= BI_RGB
;
690 Info
->bmiHeader
.biXPelsPerMeter
= 0;
691 Info
->bmiHeader
.biYPelsPerMeter
= 0;
692 Info
->bmiHeader
.biClrUsed
= 0;
693 Info
->bmiHeader
.biClrImportant
= 0;
694 ScanLines
= abs(Info
->bmiHeader
.biHeight
);
700 Info
->bmiHeader
.biClrUsed
= 0;
702 /* If the bitmap if a DIB section and has the same format than what
703 * we're asked, go ahead! */
704 if((psurf
->hSecure
) &&
705 (BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == bpp
))
707 if(Usage
== DIB_RGB_COLORS
)
709 unsigned int colors
= min(psurf
->ppal
->NumColors
, 1 << bpp
);
713 for(i
=0; i
< colors
; i
++)
715 rgbTriples
[i
].rgbtRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
716 rgbTriples
[i
].rgbtGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
717 rgbTriples
[i
].rgbtBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
720 if(colors
!= 1 << bpp
) Info
->bmiHeader
.biClrUsed
= colors
;
721 for(i
=0; i
< colors
; i
++)
723 rgbQuads
[i
].rgbRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
724 rgbQuads
[i
].rgbGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
725 rgbQuads
[i
].rgbBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
730 for(i
=0; i
< 1 << bpp
; i
++)
732 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
733 ((WORD
*)rgbQuads
)[i
] = i
;
739 if(Usage
== DIB_PAL_COLORS
)
741 for(i
=0; i
< 1 << bpp
; i
++)
743 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
744 ((WORD
*)rgbQuads
)[i
] = i
;
747 else if(bpp
> 1 && bpp
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
)) {
748 /* For color DDBs in native depth (mono DDBs always have
749 a black/white palette):
750 Generate the color map from the selected palette */
751 PPALETTE pDcPal
= PALETTE_LockPalette(pDC
->dclevel
.hpal
);
757 for (i
= 0; i
< pDcPal
->NumColors
; i
++) {
760 rgbTriples
[i
].rgbtRed
= pDcPal
->IndexedColors
[i
].peRed
;
761 rgbTriples
[i
].rgbtGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
762 rgbTriples
[i
].rgbtBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
765 rgbQuads
[i
].rgbRed
= pDcPal
->IndexedColors
[i
].peRed
;
766 rgbQuads
[i
].rgbGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
767 rgbQuads
[i
].rgbBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
768 rgbQuads
[i
].rgbReserved
= 0;
770 PALETTE_UnlockPalette(pDcPal
);
776 rgbTriples
[0].rgbtRed
= rgbTriples
[0].rgbtGreen
=
777 rgbTriples
[0].rgbtBlue
= 0;
778 rgbTriples
[1].rgbtRed
= rgbTriples
[1].rgbtGreen
=
779 rgbTriples
[1].rgbtBlue
= 0xff;
781 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
=
782 rgbQuads
[0].rgbBlue
= 0;
783 rgbQuads
[0].rgbReserved
= 0;
784 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
=
785 rgbQuads
[1].rgbBlue
= 0xff;
786 rgbQuads
[1].rgbReserved
= 0;
791 RtlCopyMemory(rgbTriples
, EGAColorsTriples
, sizeof(EGAColorsTriples
));
792 RtlCopyMemory(rgbQuads
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
802 RGBTRIPLE
*colorTriple
;
804 RtlCopyMemory(rgbTriples
, DefLogPaletteTriples
,
805 10 * sizeof(RGBTRIPLE
));
806 RtlCopyMemory(rgbTriples
+ 246, DefLogPaletteTriples
+ 10,
807 10 * sizeof(RGBTRIPLE
));
808 colorTriple
= rgbTriples
+ 10;
809 for(r
= 0; r
<= 5; r
++) /* FIXME */
811 for(g
= 0; g
<= 5; g
++)
813 for(b
= 0; b
<= 5; b
++)
815 colorTriple
->rgbtRed
= (r
* 0xff) / 5;
816 colorTriple
->rgbtGreen
= (g
* 0xff) / 5;
817 colorTriple
->rgbtBlue
= (b
* 0xff) / 5;
823 memcpy(rgbQuads
, DefLogPaletteQuads
,
824 10 * sizeof(RGBQUAD
));
825 memcpy(rgbQuads
+ 246, DefLogPaletteQuads
+ 10,
826 10 * sizeof(RGBQUAD
));
827 color
= rgbQuads
+ 10;
828 for(r
= 0; r
<= 5; r
++) /* FIXME */
830 for(g
= 0; g
<= 5; g
++)
832 for(b
= 0; b
<= 5; b
++)
834 color
->rgbRed
= (r
* 0xff) / 5;
835 color
->rgbGreen
= (g
* 0xff) / 5;
836 color
->rgbBlue
= (b
* 0xff) / 5;
837 color
->rgbReserved
= 0;
849 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
851 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
852 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
853 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
858 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
862 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
863 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
864 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
868 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
869 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
870 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
877 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
881 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
882 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
883 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
887 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
888 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
889 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
894 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(width
, height
, bpp
);
896 if(Bits
&& ScanLines
)
898 /* Create a DIBSECTION, blt it, profit */
907 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
914 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
918 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
919 Info
->bmiHeader
.biHeight
= height
< 0 ?
920 -ScanLines
: ScanLines
;
922 hBmpDest
= DIB_CreateDIBSection(pDC
, Info
, Usage
, &pDIBits
, NULL
, 0, 0);
924 Info
->bmiHeader
.biWidth
= width
;
925 Info
->bmiHeader
.biHeight
= height
;
929 DPRINT1("Unable to create a DIB Section!\n");
930 EngSetLastError(ERROR_INVALID_PARAMETER
);
935 psurfDest
= SURFACE_ShareLockSurface(hBmpDest
);
939 rcDest
.bottom
= ScanLines
;
940 rcDest
.right
= psurf
->SurfObj
.sizlBitmap
.cx
;
943 srcPoint
.y
= height
< 0 ?
944 psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
) : StartScan
;
946 EXLATEOBJ_vInitialize(&exlo
, psurf
->ppal
, psurfDest
->ppal
, 0xffffff, 0xffffff, 0);
948 ret
= IntEngCopyBits(&psurfDest
->SurfObj
,
955 SURFACE_ShareUnlockSurface(psurfDest
);
961 Status
= STATUS_SUCCESS
;
964 RtlCopyMemory(Bits
, pDIBits
, DIB_GetDIBImageBytes (width
, ScanLines
, bpp
));
966 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
968 Status
= _SEH2_GetExceptionCode();
972 if(!NT_SUCCESS(Status
))
974 DPRINT1("Unable to copy bits to the user provided pointer\n");
979 GreDeleteObject(hBmpDest
);
980 EXLATEOBJ_vCleanup(&exlo
);
982 else ScanLines
= abs(height
);
986 if(pDC
) DC_UnlockDc(pDC
);
987 if(psurf
) SURFACE_ShareUnlockSurface(psurf
);
988 if(pbmci
) DIB_FreeConvertedBitmapInfo(Info
, (BITMAPINFO
*)pbmci
);
996 NtGdiStretchDIBitsInternal(
1007 LPBITMAPINFO BitsInfo
,
1026 if (!Bits
|| !BitsInfo
)
1029 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1032 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1038 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1039 ProbeForRead(Bits
, cjMaxBits
, 1);
1040 if (DIB_GetBitmapInfo(&BitsInfo
->bmiHeader
, &width
, &height
, &planes
, &bpp
, &compr
, &size
) == -1)
1042 DPRINT1("Invalid bitmap\n");
1043 _SEH2_YIELD(goto cleanup
;)
1045 RtlCopyMemory(safeBits
, Bits
, cjMaxBits
);
1047 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1049 DPRINT1("Error, failed to read the DIB bits\n");
1050 _SEH2_YIELD(goto cleanup
;)
1056 DPRINT1("Bitmap has a negative width\n");
1060 hBitmap
= NtGdiGetDCObject(hDC
, OBJ_BITMAP
);
1062 if (!(pdc
= DC_LockDc(hDC
)))
1064 ExFreePoolWithTag(safeBits
, TAG_DIB
);
1065 EngSetLastError(ERROR_INVALID_HANDLE
);
1069 if (XDest
== 0 && YDest
== 0 && XSrc
== 0 && XSrc
== 0 &&
1070 DestWidth
== SrcWidth
&& DestHeight
== SrcHeight
&&
1075 ret
= IntGdiGetObject(hBitmap
, sizeof(bmp
), &bmp
) == sizeof(bmp
);
1077 bmp
.bmBitsPixel
== bpp
&&
1078 bmp
.bmWidth
== SrcWidth
&&
1079 bmp
.bmHeight
== SrcHeight
&&
1080 bmp
.bmPlanes
== planes
)
1083 ret
= IntSetDIBits(pdc
, hBitmap
, 0, height
, safeBits
, BitsInfo
, Usage
);
1089 /* slow path - need to use StretchBlt */
1091 hBitmap
= DIB_CreateDIBSection(pdc
, BitsInfo
, Usage
, &pvBits
, NULL
, 0, 0);
1096 DPRINT1("Error, failed to create a DIB section\n");
1100 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1102 RtlCopyMemory(pvBits
, safeBits
, cjMaxBits
);
1103 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1105 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1106 left (negative biHeight) */
1107 ret
= NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1108 hdcMem
, XSrc
, abs(height
) - SrcHeight
- YSrc
,
1109 SrcWidth
, SrcHeight
, ROP
, 0);
1113 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1114 NtGdiDeleteObjectApp(hdcMem
);
1115 GreDeleteObject(hBitmap
);
1118 ExFreePoolWithTag(safeBits
, TAG_DIB
);
1138 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1139 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1141 if (bpp
!= 1) fColor
= TRUE
;
1142 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1145 const RGBQUAD
*rgb
= (RGBQUAD
*)((PBYTE
)data
+ data
->bmiHeader
.biSize
);
1146 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1148 // Check if the first color of the colormap is black
1149 if ((col
== RGB(0, 0, 0)))
1152 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1154 // If the second color is white, create a monochrome bitmap
1155 fColor
= (col
!= RGB(0xff,0xff,0xff));
1160 // Now create the bitmap
1163 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1167 handle
= GreCreateBitmap(width
,
1177 if (NULL
!= handle
&& CBM_INIT
== init
)
1179 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1185 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1186 // The DDB that is created will be whatever bit depth your reference DC is
1189 NtGdiCreateDIBitmapInternal(
1194 IN OPTIONAL LPBYTE pjInit
,
1195 IN OPTIONAL LPBITMAPINFO pbmi
,
1197 IN UINT cjMaxInitInfo
,
1202 NTSTATUS Status
= STATUS_SUCCESS
;
1203 PBYTE safeBits
= NULL
;
1204 HBITMAP hbmResult
= NULL
;
1206 if(pjInit
&& (fInit
== CBM_INIT
))
1208 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1211 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1218 if(pbmi
) ProbeForRead(pbmi
, cjMaxInitInfo
, 1);
1219 if(pjInit
&& (fInit
== CBM_INIT
))
1221 ProbeForRead(pjInit
, cjMaxBits
, 1);
1222 RtlCopyMemory(safeBits
, pjInit
, cjMaxBits
);
1225 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1227 Status
= _SEH2_GetExceptionCode();
1231 if(!NT_SUCCESS(Status
))
1233 SetLastNtError(Status
);
1237 hbmResult
= GreCreateDIBitmapInternal(hDc
,
1248 if (safeBits
) ExFreePoolWithTag(safeBits
, TAG_DIB
);
1254 GreCreateDIBitmapInternal(
1259 IN OPTIONAL LPBYTE pjInit
,
1260 IN OPTIONAL PBITMAPINFO pbmi
,
1270 if (!hDc
) /* 1bpp monochrome bitmap */
1271 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1272 hdcDest
= NtGdiCreateCompatibleDC(0);
1283 Dc
= DC_LockDc(hdcDest
);
1286 EngSetLastError(ERROR_INVALID_HANDLE
);
1289 /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
1290 * if bpp != 1 and ignore the real value that was passed */
1292 bpp
= pbmi
->bmiHeader
.biBitCount
;
1295 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1300 NtGdiDeleteObjectApp(hdcDest
);
1308 NtGdiCreateDIBSection(
1310 IN OPTIONAL HANDLE hSection
,
1316 IN ULONG_PTR dwColorSpace
,
1319 HBITMAP hbitmap
= 0;
1321 BOOL bDesktopDC
= FALSE
;
1322 NTSTATUS Status
= STATUS_SUCCESS
;
1324 if (!bmi
) return hbitmap
; // Make sure.
1328 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
1329 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
1330 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, Usage
), 1);
1332 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1334 Status
= _SEH2_GetExceptionCode();
1338 if(!NT_SUCCESS(Status
))
1340 SetLastNtError(Status
);
1344 // If the reference hdc is null, take the desktop dc
1347 hDC
= NtGdiCreateCompatibleDC(0);
1351 if ((dc
= DC_LockDc(hDC
)))
1353 hbitmap
= DIB_CreateDIBSection(dc
,
1364 EngSetLastError(ERROR_INVALID_HANDLE
);
1368 NtGdiDeleteObjectApp(hDC
);
1375 DIB_CreateDIBSection(
1377 CONST BITMAPINFO
*bmi
,
1385 SURFACE
*bmp
= NULL
;
1386 void *mapBits
= NULL
;
1389 // Fill BITMAP32 structure with DIB data
1390 CONST BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1397 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1398 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1399 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1401 /* CreateDIBSection should fail for compressed formats */
1402 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1404 return (HBITMAP
)NULL
;
1407 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1409 bm
.bmWidth
= bi
->biWidth
;
1410 bm
.bmHeight
= effHeight
;
1411 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: WIDTH_BYTES_ALIGN32(bm
.bmWidth
, bi
->biBitCount
);
1413 bm
.bmPlanes
= bi
->biPlanes
;
1414 bm
.bmBitsPixel
= bi
->biBitCount
;
1417 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1418 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1419 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
&& bi
->biCompression
!= BI_BITFIELDS
1420 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1424 SYSTEM_BASIC_INFORMATION Sbi
;
1427 LARGE_INTEGER SectionOffset
;
1430 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1434 if (!NT_SUCCESS(Status
))
1439 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1440 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1442 SectionOffset
.LowPart
= mapOffset
;
1443 SectionOffset
.HighPart
= 0;
1445 Status
= ZwMapViewOfSection(section
,
1455 if (!NT_SUCCESS(Status
))
1457 EngSetLastError(ERROR_INVALID_PARAMETER
);
1461 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1463 else if (ovr_pitch
&& offset
)
1464 bm
.bmBits
= (LPVOID
) offset
;
1468 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1469 if(!bm
.bmBits
) goto cleanup
;
1472 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1473 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1475 if (usage
== DIB_PAL_COLORS
)
1480 pdcPal
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1481 hpal
= DIB_MapPaletteColors(pdcPal
, bmi
);
1482 PALETTE_UnlockPalette(pdcPal
);
1486 /* For DIB Brushes */
1487 DPRINT1("FIXME : Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
1489 hpal
= (HPALETTE
) 0xFFFFFFFF;
1494 hpal
= BuildDIBPalette(bmi
);
1499 DPRINT1("Error : Could not create a palette for the DIB.\n");
1503 // Create Device Dependent Bitmap and add DIB pointer
1504 Size
.cx
= bm
.bmWidth
;
1505 Size
.cy
= abs(bm
.bmHeight
);
1506 res
= GreCreateBitmapEx(bm
.bmWidth
,
1509 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1510 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1511 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1517 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1520 bmp
= SURFACE_LockSurface(res
);
1523 EngSetLastError(ERROR_INVALID_HANDLE
);
1527 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1528 table between the DIB and the X physical device. Obviously,
1529 this is left out of the ReactOS implementation. Instead,
1530 we call NtGdiSetDIBColorTable. */
1531 bmp
->hDIBSection
= section
;
1532 bmp
->hSecure
= hSecure
;
1533 bmp
->dwOffset
= offset
;
1534 bmp
->flags
= API_BITMAP
;
1535 bmp
->biClrImportant
= bi
->biClrImportant
;
1536 bmp
->SurfObj
.fjBitmap
&= ~BMF_DONT_FREE
;
1539 if(hpal
!= (HPALETTE
)0xFFFFFFFF)
1541 bmp
->ppal
= PALETTE_ShareLockPalette(hpal
);
1542 /* Lazy delete hpal, it will be freed at surface release */
1543 GreDeleteObject(hpal
);
1546 // Clean up in case of errors
1548 if (!res
|| !bmp
|| !bm
.bmBits
)
1550 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1553 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1556 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1561 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1569 SURFACE_FreeSurfaceByHandle(res
);
1576 SURFACE_UnlockSurface(bmp
);
1579 // Return BITMAP handle and storage location
1580 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1588 /***********************************************************************
1591 * Get the info from a bitmap header.
1592 * Return 0 for COREHEADER, 1 for INFOHEADER, -1 for error.
1596 DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
1597 LONG
*height
, WORD
*planes
, WORD
*bpp
, DWORD
*compr
, DWORD
*size
)
1599 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
1601 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
1602 *width
= core
->bcWidth
;
1603 *height
= core
->bcHeight
;
1604 *planes
= core
->bcPlanes
;
1605 *bpp
= core
->bcBitCount
;
1610 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
)) /* assume BITMAPINFOHEADER */
1612 *width
= header
->biWidth
;
1613 *height
= header
->biHeight
;
1614 *planes
= header
->biPlanes
;
1615 *bpp
= header
->biBitCount
;
1616 *compr
= header
->biCompression
;
1617 *size
= header
->biSizeImage
;
1620 DPRINT1("(%d): unknown/wrong size for header\n", header
->biSize
);
1624 /***********************************************************************
1625 * DIB_GetDIBImageBytes
1627 * Return the number of bytes used to hold the image in a DIB bitmap.
1628 * 11/16/1999 (RJJ) lifted from wine
1631 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1633 return WIDTH_BYTES_ALIGN32(width
, depth
) * (height
< 0 ? -height
: height
);
1636 /***********************************************************************
1637 * DIB_BitmapInfoSize
1639 * Return the size of the bitmap info structure including color table.
1640 * 11/16/1999 (RJJ) lifted from wine
1643 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1645 unsigned int colors
, size
, masks
= 0;
1647 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1649 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
1650 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1651 return sizeof(BITMAPCOREHEADER
) + colors
*
1652 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1654 else /* assume BITMAPINFOHEADER */
1656 colors
= info
->bmiHeader
.biClrUsed
;
1657 if (colors
> 256) colors
= 256;
1658 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
1659 colors
= 1 << info
->bmiHeader
.biBitCount
;
1660 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
1661 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
1662 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1668 DIB_MapPaletteColors(PPALETTE ppal
, CONST BITMAPINFO
* lpbmi
)
1670 PALETTEENTRY
* ppalEntries
;
1675 if (!(ppal
->flFlags
& PAL_INDEXED
))
1680 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1681 if (lpbmi
->bmiHeader
.biClrUsed
)
1683 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1686 /* Don't have more colors than we need */
1687 nNumColors
= min(ppal
->NumColors
, nNumColors
);
1689 ppalEntries
= ExAllocatePoolWithTag(PagedPool
, sizeof(PALETTEENTRY
) * nNumColors
, TAG_COLORMAP
);
1690 if (ppalEntries
== NULL
)
1692 DPRINT1("Could not allocate palette entries\n");
1696 lpIndex
= (USHORT
*)((PBYTE
)lpbmi
+ lpbmi
->bmiHeader
.biSize
);
1698 for (i
= 0; i
< nNumColors
; i
++)
1700 if (*lpIndex
< ppal
->NumColors
)
1702 ppalEntries
[i
] = ppal
->IndexedColors
[*lpIndex
];
1706 ppalEntries
[i
].peRed
= 0;
1707 ppalEntries
[i
].peGreen
= 0;
1708 ppalEntries
[i
].peBlue
= 0;
1709 ppalEntries
[i
].peFlags
= 0;
1715 hpal
= PALETTE_AllocPalette(PAL_INDEXED
, nNumColors
, (ULONG
*)ppalEntries
, 0, 0, 0);
1717 ExFreePoolWithTag(ppalEntries
, TAG_COLORMAP
);
1724 BuildDIBPalette(CONST BITMAPINFO
*bmi
)
1729 ULONG RedMask
= 0, GreenMask
= 0, BlueMask
= 0;
1730 PDWORD pdwColors
= (PDWORD
)((PBYTE
)bmi
+ bmi
->bmiHeader
.biSize
);
1733 // Determine Bits Per Pixel
1734 bits
= bmi
->bmiHeader
.biBitCount
;
1736 // Determine paletteType from Bits Per Pixel
1739 paletteType
= PAL_INDEXED
;
1740 RedMask
= GreenMask
= BlueMask
= 0;
1742 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1744 paletteType
= PAL_BITFIELDS
;
1745 if (bmi
->bmiHeader
.biSize
>= sizeof(BITMAPV4HEADER
))
1747 PBITMAPV4HEADER pV4Header
= (PBITMAPV4HEADER
)&bmi
->bmiHeader
;
1748 RedMask
= pV4Header
->bV4RedMask
;
1749 GreenMask
= pV4Header
->bV4GreenMask
;
1750 BlueMask
= pV4Header
->bV4BlueMask
;
1754 RedMask
= pdwColors
[0];
1755 GreenMask
= pdwColors
[1];
1756 BlueMask
= pdwColors
[2];
1761 paletteType
= PAL_BITFIELDS
;
1765 paletteType
|= PAL_RGB16_555
;
1773 paletteType
|= PAL_BGR
;
1775 GreenMask
= 0x00FF00;
1776 BlueMask
= 0x0000FF;
1781 if (bmi
->bmiHeader
.biClrUsed
== 0)
1783 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1787 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1790 if (PAL_INDEXED
== paletteType
)
1792 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)pdwColors
);
1796 hPal
= PALETTE_AllocPalette(paletteType
, 0,
1798 RedMask
, GreenMask
, BlueMask
);
1804 /* Converts a BITMAPCOREINFO to a BITMAPINFO structure,
1805 * or does nothing if it's already a BITMAPINFO (or V4 or V5) */
1808 DIB_ConvertBitmapInfo (CONST BITMAPINFO
* pbmi
, DWORD Usage
)
1810 CONST BITMAPCOREINFO
* pbmci
= (BITMAPCOREINFO
*)pbmi
;
1811 BITMAPINFO
* pNewBmi
;
1812 UINT numColors
= 0, ColorsSize
= 0;
1814 if(pbmi
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
)) return (BITMAPINFO
*)pbmi
;
1815 if(pbmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) return NULL
;
1817 if(pbmci
->bmciHeader
.bcBitCount
<= 8)
1819 numColors
= 1 << pbmci
->bmciHeader
.bcBitCount
;
1820 if(Usage
== DIB_PAL_COLORS
)
1822 ColorsSize
= numColors
* sizeof(WORD
);
1826 ColorsSize
= numColors
* sizeof(RGBQUAD
);
1829 else if (Usage
== DIB_PAL_COLORS
)
1831 /* Invalid at high Res */
1835 pNewBmi
= ExAllocatePoolWithTag(PagedPool
, sizeof(BITMAPINFOHEADER
) + ColorsSize
, TAG_DIB
);
1836 if(!pNewBmi
) return NULL
;
1838 RtlZeroMemory(pNewBmi
, sizeof(BITMAPINFOHEADER
) + ColorsSize
);
1840 pNewBmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1841 pNewBmi
->bmiHeader
.biBitCount
= pbmci
->bmciHeader
.bcBitCount
;
1842 pNewBmi
->bmiHeader
.biWidth
= pbmci
->bmciHeader
.bcWidth
;
1843 pNewBmi
->bmiHeader
.biHeight
= pbmci
->bmciHeader
.bcHeight
;
1844 pNewBmi
->bmiHeader
.biPlanes
= pbmci
->bmciHeader
.bcPlanes
;
1845 pNewBmi
->bmiHeader
.biCompression
= BI_RGB
;
1846 pNewBmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(pNewBmi
->bmiHeader
.biWidth
,
1847 pNewBmi
->bmiHeader
.biHeight
,
1848 pNewBmi
->bmiHeader
.biBitCount
);
1850 if(Usage
== DIB_PAL_COLORS
)
1852 RtlCopyMemory(pNewBmi
->bmiColors
, pbmci
->bmciColors
, ColorsSize
);
1857 for(i
=0; i
<numColors
; i
++)
1859 pNewBmi
->bmiColors
[i
].rgbRed
= pbmci
->bmciColors
[i
].rgbtRed
;
1860 pNewBmi
->bmiColors
[i
].rgbGreen
= pbmci
->bmciColors
[i
].rgbtGreen
;
1861 pNewBmi
->bmiColors
[i
].rgbBlue
= pbmci
->bmciColors
[i
].rgbtBlue
;
1868 /* Frees a BITMAPINFO created with DIB_ConvertBitmapInfo */
1871 DIB_FreeConvertedBitmapInfo(BITMAPINFO
* converted
, BITMAPINFO
* orig
)
1873 if(converted
!= orig
)
1874 ExFreePoolWithTag(converted
, TAG_DIB
);