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_ShareLockPalette(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_ShareUnlockPalette(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_ShareLockSurface(hBitmap
);
281 psurfSrc
= SURFACE_ShareLockSurface(SourceBitmap
);
283 if(!(psurfSrc
&& psurfDst
))
285 DPRINT1("Error, could not lock surfaces\n");
289 rcDst
.top
= StartScan
;
291 rcDst
.bottom
= rcDst
.top
+ ScanLines
;
292 rcDst
.right
= psurfDst
->SurfObj
.sizlBitmap
.cx
;
297 /* 1bpp bitmaps have 0 for white, 1 for black */
298 EXLATEOBJ_vInitialize(&exlo
, psurfSrc
->ppal
, psurfDst
->ppal
, 0xFFFFFF, 0xFFFFFF, 0);
300 result
= IntEngCopyBits(&psurfDst
->SurfObj
,
309 EXLATEOBJ_vCleanup(&exlo
);
314 SURFACE_ShareUnlockSurface(psurfSrc
);
318 SURFACE_ShareUnlockSurface(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 IntLPtoDP(pDC
, (LPPOINT
)&rcDest
, 2);
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
= GreCreateBitmapEx(bmi
->bmiHeader
.biWidth
,
484 BitmapFormat(bmi
->bmiHeader
.biBitCount
,
485 bmi
->bmiHeader
.biCompression
),
486 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
487 bmi
->bmiHeader
.biSizeImage
,
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_ShareLockPalette(hpalDIB
);
520 EngSetLastError(ERROR_INVALID_HANDLE
);
521 Status
= STATUS_UNSUCCESSFUL
;
525 /* Initialize EXLATEOBJ */
526 EXLATEOBJ_vInitialize(&exlo
,
529 RGB(0xff, 0xff, 0xff),
530 pDC
->pdcattr
->crBackgroundClr
,
531 pDC
->pdcattr
->crForegroundClr
);
534 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
535 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
536 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
537 Status
= IntEngBitBlt(pDestSurf
,
540 pDC
->rosdc
.CombinedClip
,
547 ROP4_FROM_INDEX(R3_OPINDEX_SRCCOPY
));
549 /* Cleanup EXLATEOBJ */
550 EXLATEOBJ_vCleanup(&exlo
);
553 if (NT_SUCCESS(Status
))
558 if (ppalDIB
) PALETTE_ShareUnlockPalette(ppalDIB
);
560 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
561 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
562 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
569 /* Converts a device-dependent bitmap to a DIB */
572 NtGdiGetDIBitsInternal(
583 BITMAPCOREINFO
* pbmci
= NULL
;
584 PSURFACE psurf
= NULL
;
590 RGBTRIPLE
* rgbTriples
;
593 NTSTATUS Status
= STATUS_SUCCESS
;
595 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
597 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
602 /* Probe for read and write */
603 ProbeForRead(Info
, MaxInfo
, 1);
604 ProbeForWrite(Info
, MaxInfo
, 1);
605 if (Bits
) ProbeForWrite(Bits
, MaxBits
, 1);
607 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
609 Status
= _SEH2_GetExceptionCode();
613 if (!NT_SUCCESS(Status
))
618 colorPtr
= (LPBYTE
)Info
+ Info
->bmiHeader
.biSize
;
619 rgbTriples
= colorPtr
;
622 bitmap_type
= DIB_GetBitmapInfo(&Info
->bmiHeader
,
629 if(bitmap_type
== -1)
631 DPRINT("Wrong bitmap format\n");
632 EngSetLastError(ERROR_INVALID_PARAMETER
);
635 else if(bitmap_type
== 0)
637 /* We need a BITMAPINFO to create a DIB, but we have to fill
638 * the BITMAPCOREINFO we're provided */
639 pbmci
= (BITMAPCOREINFO
*)Info
;
640 Info
= DIB_ConvertBitmapInfo((BITMAPINFO
*)pbmci
, Usage
);
643 DPRINT1("Error, could not convert the BITMAPCOREINFO!\n");
646 rgbQuads
= Info
->bmiColors
;
649 pDC
= DC_LockDc(hDC
);
650 if (pDC
== NULL
|| pDC
->dctype
== DC_TYPE_INFO
)
656 /* Get a pointer to the source bitmap object */
657 psurf
= SURFACE_ShareLockSurface(hBitmap
);
664 /* Fill in the structure */
667 case 0: /* Only info */
670 pbmci
->bmciHeader
.bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
671 pbmci
->bmciHeader
.bcHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
672 -psurf
->SurfObj
.sizlBitmap
.cy
:
673 psurf
->SurfObj
.sizlBitmap
.cy
;
674 pbmci
->bmciHeader
.bcPlanes
= 1;
675 pbmci
->bmciHeader
.bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
677 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
678 Info
->bmiHeader
.biHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
679 -psurf
->SurfObj
.sizlBitmap
.cy
:
680 psurf
->SurfObj
.sizlBitmap
.cy
;;
681 Info
->bmiHeader
.biPlanes
= 1;
682 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
683 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes( Info
->bmiHeader
.biWidth
,
684 Info
->bmiHeader
.biHeight
,
685 Info
->bmiHeader
.biBitCount
);
688 switch(Info
->bmiHeader
.biBitCount
)
692 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
695 Info
->bmiHeader
.biCompression
= BI_RGB
;
699 else if(Info
->bmiHeader
.biBitCount
> 8)
701 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
705 Info
->bmiHeader
.biCompression
= BI_RGB
;
707 Info
->bmiHeader
.biXPelsPerMeter
= 0;
708 Info
->bmiHeader
.biYPelsPerMeter
= 0;
709 Info
->bmiHeader
.biClrUsed
= 0;
710 Info
->bmiHeader
.biClrImportant
= 0;
711 ScanLines
= abs(Info
->bmiHeader
.biHeight
);
717 Info
->bmiHeader
.biClrUsed
= 0;
719 /* If the bitmap if a DIB section and has the same format than what
720 * we're asked, go ahead! */
721 if((psurf
->hSecure
) &&
722 (BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == bpp
))
724 if(Usage
== DIB_RGB_COLORS
)
726 unsigned int colors
= min(psurf
->ppal
->NumColors
, 1 << bpp
);
730 for(i
=0; i
< colors
; i
++)
732 rgbTriples
[i
].rgbtRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
733 rgbTriples
[i
].rgbtGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
734 rgbTriples
[i
].rgbtBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
737 if(colors
!= 1 << bpp
) Info
->bmiHeader
.biClrUsed
= colors
;
738 for(i
=0; i
< colors
; i
++)
740 rgbQuads
[i
].rgbRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
741 rgbQuads
[i
].rgbGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
742 rgbQuads
[i
].rgbBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
747 for(i
=0; i
< 1 << bpp
; i
++)
749 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
750 ((WORD
*)rgbQuads
)[i
] = i
;
756 if(Usage
== DIB_PAL_COLORS
)
758 for(i
=0; i
< 1 << bpp
; i
++)
760 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
761 ((WORD
*)rgbQuads
)[i
] = i
;
764 else if(bpp
> 1 && bpp
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
))
766 /* For color DDBs in native depth (mono DDBs always have
767 a black/white palette):
768 Generate the color map from the selected palette */
769 PPALETTE pDcPal
= PALETTE_ShareLockPalette(pDC
->dclevel
.hpal
);
775 for (i
= 0; i
< pDcPal
->NumColors
; i
++)
779 rgbTriples
[i
].rgbtRed
= pDcPal
->IndexedColors
[i
].peRed
;
780 rgbTriples
[i
].rgbtGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
781 rgbTriples
[i
].rgbtBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
784 rgbQuads
[i
].rgbRed
= pDcPal
->IndexedColors
[i
].peRed
;
785 rgbQuads
[i
].rgbGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
786 rgbQuads
[i
].rgbBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
787 rgbQuads
[i
].rgbReserved
= 0;
789 PALETTE_ShareUnlockPalette(pDcPal
);
798 rgbTriples
[0].rgbtRed
= rgbTriples
[0].rgbtGreen
=
799 rgbTriples
[0].rgbtBlue
= 0;
800 rgbTriples
[1].rgbtRed
= rgbTriples
[1].rgbtGreen
=
801 rgbTriples
[1].rgbtBlue
= 0xff;
803 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
=
804 rgbQuads
[0].rgbBlue
= 0;
805 rgbQuads
[0].rgbReserved
= 0;
806 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
=
807 rgbQuads
[1].rgbBlue
= 0xff;
808 rgbQuads
[1].rgbReserved
= 0;
813 RtlCopyMemory(rgbTriples
, EGAColorsTriples
, sizeof(EGAColorsTriples
));
814 RtlCopyMemory(rgbQuads
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
824 RGBTRIPLE
*colorTriple
;
826 RtlCopyMemory(rgbTriples
, DefLogPaletteTriples
,
827 10 * sizeof(RGBTRIPLE
));
828 RtlCopyMemory(rgbTriples
+ 246, DefLogPaletteTriples
+ 10,
829 10 * sizeof(RGBTRIPLE
));
830 colorTriple
= rgbTriples
+ 10;
831 for(r
= 0; r
<= 5; r
++) /* FIXME */
833 for(g
= 0; g
<= 5; g
++)
835 for(b
= 0; b
<= 5; b
++)
837 colorTriple
->rgbtRed
= (r
* 0xff) / 5;
838 colorTriple
->rgbtGreen
= (g
* 0xff) / 5;
839 colorTriple
->rgbtBlue
= (b
* 0xff) / 5;
845 memcpy(rgbQuads
, DefLogPaletteQuads
,
846 10 * sizeof(RGBQUAD
));
847 memcpy(rgbQuads
+ 246, DefLogPaletteQuads
+ 10,
848 10 * sizeof(RGBQUAD
));
849 color
= rgbQuads
+ 10;
850 for(r
= 0; r
<= 5; r
++) /* FIXME */
852 for(g
= 0; g
<= 5; g
++)
854 for(b
= 0; b
<= 5; b
++)
856 color
->rgbRed
= (r
* 0xff) / 5;
857 color
->rgbGreen
= (g
* 0xff) / 5;
858 color
->rgbBlue
= (b
* 0xff) / 5;
859 color
->rgbReserved
= 0;
871 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
873 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
874 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
875 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
880 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
884 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
885 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
886 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
890 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
891 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
892 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
899 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
903 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
904 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
905 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
909 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
910 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
911 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
916 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(width
, height
, bpp
);
918 if(Bits
&& ScanLines
)
920 /* Create a DIBSECTION, blt it, profit */
929 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
936 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
940 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
941 Info
->bmiHeader
.biHeight
= height
< 0 ?
942 -ScanLines
: ScanLines
;
944 hBmpDest
= DIB_CreateDIBSection(pDC
, Info
, Usage
, &pDIBits
, NULL
, 0, 0);
946 Info
->bmiHeader
.biWidth
= width
;
947 Info
->bmiHeader
.biHeight
= height
;
951 DPRINT1("Unable to create a DIB Section!\n");
952 EngSetLastError(ERROR_INVALID_PARAMETER
);
957 psurfDest
= SURFACE_ShareLockSurface(hBmpDest
);
961 rcDest
.bottom
= ScanLines
;
962 rcDest
.right
= psurf
->SurfObj
.sizlBitmap
.cx
;
970 if(ScanLines
<= StartScan
)
973 SURFACE_ShareUnlockSurface(psurfDest
);
974 GreDeleteObject(hBmpDest
);
978 ScanLines
-= StartScan
;
982 srcPoint
.y
= StartScan
;
985 EXLATEOBJ_vInitialize(&exlo
, psurf
->ppal
, psurfDest
->ppal
, 0xffffff, 0xffffff, 0);
987 ret
= IntEngCopyBits(&psurfDest
->SurfObj
,
994 SURFACE_ShareUnlockSurface(psurfDest
);
1000 Status
= STATUS_SUCCESS
;
1003 RtlCopyMemory(Bits
, pDIBits
, DIB_GetDIBImageBytes (width
, ScanLines
, bpp
));
1005 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1007 Status
= _SEH2_GetExceptionCode();
1011 if(!NT_SUCCESS(Status
))
1013 DPRINT1("Unable to copy bits to the user provided pointer\n");
1018 GreDeleteObject(hBmpDest
);
1019 EXLATEOBJ_vCleanup(&exlo
);
1021 else ScanLines
= abs(height
);
1025 if(pDC
) DC_UnlockDc(pDC
);
1026 if(psurf
) SURFACE_ShareUnlockSurface(psurf
);
1027 if(pbmci
) DIB_FreeConvertedBitmapInfo(Info
, (BITMAPINFO
*)pbmci
);
1032 #define ROP_TO_ROP4(Rop) ((Rop) >> 16)
1037 NtGdiStretchDIBitsInternal(
1047 IN OPTIONAL LPBYTE pjInit
,
1048 IN LPBITMAPINFO pbmi
,
1050 IN DWORD dwRop
, // ms ntgdi.h says dwRop4(?)
1055 BOOL bResult
= FALSE
;
1060 PSURFACE psurfTmp
, psurfDst
;
1063 if (!(pdc
= DC_LockDc(hdc
)))
1065 EngSetLastError(ERROR_INVALID_HANDLE
);
1069 /* Transform dest size */
1072 IntLPtoDP(pdc
, (POINTL
*)&sizel
, 1);
1075 /* Check if we can use NtGdiSetDIBitsToDeviceInternal */
1076 if (sizel
.cx
== cxSrc
&& sizel
.cy
== cySrc
&& dwRop
== SRCCOPY
)
1079 return NtGdiSetDIBitsToDeviceInternal(hdc
,
1097 /* Create an intermediate bitmap from the DIB */
1098 hbmTmp
= NtGdiCreateDIBitmapInternal(hdc
,
1111 DPRINT1("NtGdiCreateDIBitmapInternal failed\n");
1115 /* FIXME: locking twice is cheesy, coord tranlation in UM will fix it */
1116 if (!(pdc
= DC_LockDc(hdc
)))
1118 DPRINT1("Could not lock dc\n");
1119 EngSetLastError(ERROR_INVALID_HANDLE
);
1120 GreDeleteObject(hbmTmp
);
1124 psurfTmp
= SURFACE_ShareLockSurface(hbmTmp
);
1127 DPRINT1("Could not lock bitmap :-(\n");
1131 psurfDst
= pdc
->dclevel
.pSurface
;
1139 /* Calculate source and destination rect */
1142 rcSrc
.right
= xSrc
+ abs(cxSrc
);
1143 rcSrc
.bottom
= ySrc
+ abs(cySrc
);
1146 rcDst
.right
= rcDst
.left
+ cxDst
;
1147 rcDst
.bottom
= rcDst
.top
+ cyDst
;
1148 IntLPtoDP(pdc
, (POINTL
*)&rcDst
, 2);
1149 RECTL_vOffsetRect(&rcDst
, pdc
->ptlDCOrig
.x
, pdc
->ptlDCOrig
.y
);
1151 /* Initialize XLATEOBJ */
1152 EXLATEOBJ_vInitialize(&exlo
,
1155 RGB(0xff, 0xff, 0xff),
1156 pdc
->pdcattr
->crBackgroundClr
,
1157 pdc
->pdcattr
->crForegroundClr
);
1159 /* Prepare DC for blit */
1160 DC_vPrepareDCsForBlit(pdc
, rcDst
, NULL
, rcSrc
);
1162 /* Perform the stretch operation */
1163 bResult
= IntEngStretchBlt(&psurfDst
->SurfObj
,
1166 pdc
->rosdc
.CombinedClip
,
1171 &pdc
->eboFill
.BrushObject
,
1173 ROP_TO_ROP4(dwRop
));
1176 DC_vFinishBlit(pdc
, NULL
);
1177 EXLATEOBJ_vCleanup(&exlo
);
1179 if (psurfTmp
) SURFACE_ShareUnlockSurface(psurfTmp
);
1180 if (hbmTmp
) GreDeleteObject(hbmTmp
);
1181 if (pdc
) DC_UnlockDc(pdc
);
1202 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1203 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1205 if (bpp
!= 1) fColor
= TRUE
;
1206 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1209 const RGBQUAD
*rgb
= (RGBQUAD
*)((PBYTE
)data
+ data
->bmiHeader
.biSize
);
1210 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1212 // Check if the first color of the colormap is black
1213 if ((col
== RGB(0, 0, 0)))
1216 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1218 // If the second color is white, create a monochrome bitmap
1219 fColor
= (col
!= RGB(0xff,0xff,0xff));
1224 // Now create the bitmap
1227 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1231 handle
= GreCreateBitmap(width
,
1241 if (NULL
!= handle
&& CBM_INIT
== init
)
1243 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1249 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1250 // The DDB that is created will be whatever bit depth your reference DC is
1253 NtGdiCreateDIBitmapInternal(
1258 IN OPTIONAL LPBYTE pjInit
,
1259 IN OPTIONAL LPBITMAPINFO pbmi
,
1261 IN UINT cjMaxInitInfo
,
1266 NTSTATUS Status
= STATUS_SUCCESS
;
1267 PBYTE safeBits
= NULL
;
1268 HBITMAP hbmResult
= NULL
;
1270 if(pjInit
&& (fInit
== CBM_INIT
))
1272 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1275 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1282 if(pbmi
) ProbeForRead(pbmi
, cjMaxInitInfo
, 1);
1283 if(pjInit
&& (fInit
== CBM_INIT
))
1285 ProbeForRead(pjInit
, cjMaxBits
, 1);
1286 RtlCopyMemory(safeBits
, pjInit
, cjMaxBits
);
1289 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1291 Status
= _SEH2_GetExceptionCode();
1295 if(!NT_SUCCESS(Status
))
1297 SetLastNtError(Status
);
1301 hbmResult
= GreCreateDIBitmapInternal(hDc
,
1312 if (safeBits
) ExFreePoolWithTag(safeBits
, TAG_DIB
);
1318 GreCreateDIBitmapInternal(
1323 IN OPTIONAL LPBYTE pjInit
,
1324 IN OPTIONAL PBITMAPINFO pbmi
,
1334 if (!hDc
) /* 1bpp monochrome bitmap */
1336 // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1337 hdcDest
= NtGdiCreateCompatibleDC(0);
1348 Dc
= DC_LockDc(hdcDest
);
1351 EngSetLastError(ERROR_INVALID_HANDLE
);
1354 /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
1355 * if bpp != 1 and ignore the real value that was passed */
1357 bpp
= pbmi
->bmiHeader
.biBitCount
;
1360 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1365 NtGdiDeleteObjectApp(hdcDest
);
1373 NtGdiCreateDIBSection(
1375 IN OPTIONAL HANDLE hSection
,
1381 IN ULONG_PTR dwColorSpace
,
1384 HBITMAP hbitmap
= 0;
1386 BOOL bDesktopDC
= FALSE
;
1387 NTSTATUS Status
= STATUS_SUCCESS
;
1389 if (!bmi
) return hbitmap
; // Make sure.
1393 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
1394 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
1395 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, Usage
), 1);
1397 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1399 Status
= _SEH2_GetExceptionCode();
1403 if(!NT_SUCCESS(Status
))
1405 SetLastNtError(Status
);
1409 // If the reference hdc is null, take the desktop dc
1412 hDC
= NtGdiCreateCompatibleDC(0);
1416 if ((dc
= DC_LockDc(hDC
)))
1418 hbitmap
= DIB_CreateDIBSection(dc
,
1429 EngSetLastError(ERROR_INVALID_HANDLE
);
1433 NtGdiDeleteObjectApp(hDC
);
1440 DIB_CreateDIBSection(
1442 CONST BITMAPINFO
*bmi
,
1450 SURFACE
*bmp
= NULL
;
1451 void *mapBits
= NULL
;
1454 // Fill BITMAP32 structure with DIB data
1455 CONST BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1462 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1463 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1464 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1466 /* CreateDIBSection should fail for compressed formats */
1467 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1469 DPRINT1("no compressed format allowed\n");
1470 return (HBITMAP
)NULL
;
1473 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1475 bm
.bmWidth
= bi
->biWidth
;
1476 bm
.bmHeight
= effHeight
;
1477 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: WIDTH_BYTES_ALIGN32(bm
.bmWidth
, bi
->biBitCount
);
1479 bm
.bmPlanes
= bi
->biPlanes
;
1480 bm
.bmBitsPixel
= bi
->biBitCount
;
1483 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1484 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1485 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
&& bi
->biCompression
!= BI_BITFIELDS
1486 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1490 SYSTEM_BASIC_INFORMATION Sbi
;
1493 LARGE_INTEGER SectionOffset
;
1496 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1500 if (!NT_SUCCESS(Status
))
1502 DPRINT1("ZwQuerySystemInformation failed (0x%lx)\n", Status
);
1506 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1507 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1509 SectionOffset
.LowPart
= mapOffset
;
1510 SectionOffset
.HighPart
= 0;
1512 Status
= ZwMapViewOfSection(section
,
1522 if (!NT_SUCCESS(Status
))
1524 DPRINT1("ZwMapViewOfSection failed (0x%lx)\n", Status
);
1525 EngSetLastError(ERROR_INVALID_PARAMETER
);
1529 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1531 else if (ovr_pitch
&& offset
)
1532 bm
.bmBits
= (LPVOID
) offset
;
1536 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1539 DPRINT1("Failed to allocate memory\n");
1544 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1545 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1547 if (usage
== DIB_PAL_COLORS
)
1552 ppalDc
= PALETTE_ShareLockPalette(dc
->dclevel
.hpal
);
1553 hpal
= DIB_MapPaletteColors(ppalDc
, bmi
);
1554 PALETTE_ShareUnlockPalette(ppalDc
);
1558 /* For DIB Brushes */
1559 DPRINT1("FIXME : Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
1561 hpal
= (HPALETTE
) 0xFFFFFFFF;
1566 hpal
= BuildDIBPalette(bmi
);
1571 DPRINT1("Error : Could not create a palette for the DIB.\n");
1575 // Create Device Dependent Bitmap and add DIB pointer
1576 Size
.cx
= bm
.bmWidth
;
1577 Size
.cy
= abs(bm
.bmHeight
);
1578 res
= GreCreateBitmapEx(bm
.bmWidth
,
1581 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1582 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1583 ((bi
->biHeight
< 0) ? BMF_TOPDOWN
: 0),
1589 DPRINT1("GreCreateBitmapEx failed\n");
1590 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1593 bmp
= SURFACE_ShareLockSurface(res
); // HACK
1596 DPRINT1("SURFACE_LockSurface failed\n");
1597 EngSetLastError(ERROR_INVALID_HANDLE
);
1601 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1602 table between the DIB and the X physical device. Obviously,
1603 this is left out of the ReactOS implementation. Instead,
1604 we call NtGdiSetDIBColorTable. */
1605 bmp
->hDIBSection
= section
;
1606 bmp
->hSecure
= hSecure
;
1607 bmp
->dwOffset
= offset
;
1608 bmp
->flags
= API_BITMAP
;
1609 bmp
->biClrImportant
= bi
->biClrImportant
;
1610 bmp
->SurfObj
.fjBitmap
&= ~BMF_DONT_FREE
;
1613 if(hpal
!= (HPALETTE
)0xFFFFFFFF)
1615 bmp
->ppal
= PALETTE_ShareLockPalette(hpal
);
1616 /* Lazy delete hpal, it will be freed at surface release */
1617 GreDeleteObject(hpal
);
1620 // Clean up in case of errors
1622 if (!res
|| !bmp
|| !bm
.bmBits
)
1624 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1627 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1630 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1634 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1642 SURFACE_FreeSurfaceByHandle(res
);
1649 SURFACE_ShareUnlockSurface(bmp
);
1652 // Return BITMAP handle and storage location
1653 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1661 /***********************************************************************
1664 * Get the info from a bitmap header.
1665 * Return 0 for COREHEADER, 1 for INFOHEADER, -1 for error.
1669 DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
1670 LONG
*height
, WORD
*planes
, WORD
*bpp
, DWORD
*compr
, DWORD
*size
)
1672 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
1674 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
1675 *width
= core
->bcWidth
;
1676 *height
= core
->bcHeight
;
1677 *planes
= core
->bcPlanes
;
1678 *bpp
= core
->bcBitCount
;
1683 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
)) /* assume BITMAPINFOHEADER */
1685 *width
= header
->biWidth
;
1686 *height
= header
->biHeight
;
1687 *planes
= header
->biPlanes
;
1688 *bpp
= header
->biBitCount
;
1689 *compr
= header
->biCompression
;
1690 *size
= header
->biSizeImage
;
1693 DPRINT1("(%d): unknown/wrong size for header\n", header
->biSize
);
1697 /***********************************************************************
1698 * DIB_GetDIBImageBytes
1700 * Return the number of bytes used to hold the image in a DIB bitmap.
1701 * 11/16/1999 (RJJ) lifted from wine
1704 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1706 return WIDTH_BYTES_ALIGN32(width
, depth
) * (height
< 0 ? -height
: height
);
1709 /***********************************************************************
1710 * DIB_BitmapInfoSize
1712 * Return the size of the bitmap info structure including color table.
1713 * 11/16/1999 (RJJ) lifted from wine
1716 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1718 unsigned int colors
, size
, masks
= 0;
1720 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1722 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
1723 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1724 return sizeof(BITMAPCOREHEADER
) + colors
*
1725 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1727 else /* assume BITMAPINFOHEADER */
1729 colors
= info
->bmiHeader
.biClrUsed
;
1730 if (colors
> 256) colors
= 256;
1731 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
1732 colors
= 1 << info
->bmiHeader
.biBitCount
;
1733 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
1734 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
1735 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1741 DIB_MapPaletteColors(PPALETTE ppal
, CONST BITMAPINFO
* lpbmi
)
1743 PALETTEENTRY
* ppalEntries
;
1748 if (!(ppal
->flFlags
& PAL_INDEXED
))
1753 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1754 if (lpbmi
->bmiHeader
.biClrUsed
)
1756 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1759 /* Don't have more colors than we need */
1760 nNumColors
= min(ppal
->NumColors
, nNumColors
);
1762 ppalEntries
= ExAllocatePoolWithTag(PagedPool
, sizeof(PALETTEENTRY
) * nNumColors
, TAG_COLORMAP
);
1763 if (ppalEntries
== NULL
)
1765 DPRINT1("Could not allocate palette entries\n");
1769 lpIndex
= (USHORT
*)((PBYTE
)lpbmi
+ lpbmi
->bmiHeader
.biSize
);
1771 for (i
= 0; i
< nNumColors
; i
++)
1773 if (*lpIndex
< ppal
->NumColors
)
1775 ppalEntries
[i
] = ppal
->IndexedColors
[*lpIndex
];
1779 ppalEntries
[i
].peRed
= 0;
1780 ppalEntries
[i
].peGreen
= 0;
1781 ppalEntries
[i
].peBlue
= 0;
1782 ppalEntries
[i
].peFlags
= 0;
1788 hpal
= PALETTE_AllocPalette(PAL_INDEXED
, nNumColors
, (ULONG
*)ppalEntries
, 0, 0, 0);
1790 ExFreePoolWithTag(ppalEntries
, TAG_COLORMAP
);
1797 BuildDIBPalette(CONST BITMAPINFO
*bmi
)
1802 ULONG RedMask
= 0, GreenMask
= 0, BlueMask
= 0;
1803 PDWORD pdwColors
= (PDWORD
)((PBYTE
)bmi
+ bmi
->bmiHeader
.biSize
);
1806 // Determine Bits Per Pixel
1807 bits
= bmi
->bmiHeader
.biBitCount
;
1809 // Determine paletteType from Bits Per Pixel
1812 paletteType
= PAL_INDEXED
;
1813 RedMask
= GreenMask
= BlueMask
= 0;
1815 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1817 paletteType
= PAL_BITFIELDS
;
1818 if (bmi
->bmiHeader
.biSize
>= sizeof(BITMAPV4HEADER
))
1820 PBITMAPV4HEADER pV4Header
= (PBITMAPV4HEADER
)&bmi
->bmiHeader
;
1821 RedMask
= pV4Header
->bV4RedMask
;
1822 GreenMask
= pV4Header
->bV4GreenMask
;
1823 BlueMask
= pV4Header
->bV4BlueMask
;
1827 RedMask
= pdwColors
[0];
1828 GreenMask
= pdwColors
[1];
1829 BlueMask
= pdwColors
[2];
1834 paletteType
= PAL_BITFIELDS
;
1838 paletteType
|= PAL_RGB16_555
;
1846 paletteType
|= PAL_BGR
;
1848 GreenMask
= 0x00FF00;
1849 BlueMask
= 0x0000FF;
1854 if (bmi
->bmiHeader
.biClrUsed
== 0)
1856 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1860 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1863 if (PAL_INDEXED
== paletteType
)
1865 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)pdwColors
);
1869 hPal
= PALETTE_AllocPalette(paletteType
, 0,
1871 RedMask
, GreenMask
, BlueMask
);
1877 /* Converts a BITMAPCOREINFO to a BITMAPINFO structure,
1878 * or does nothing if it's already a BITMAPINFO (or V4 or V5) */
1881 DIB_ConvertBitmapInfo (CONST BITMAPINFO
* pbmi
, DWORD Usage
)
1883 CONST BITMAPCOREINFO
* pbmci
= (BITMAPCOREINFO
*)pbmi
;
1884 BITMAPINFO
* pNewBmi
;
1885 UINT numColors
= 0, ColorsSize
= 0;
1887 if(pbmi
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
)) return (BITMAPINFO
*)pbmi
;
1888 if(pbmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) return NULL
;
1890 if(pbmci
->bmciHeader
.bcBitCount
<= 8)
1892 numColors
= 1 << pbmci
->bmciHeader
.bcBitCount
;
1893 if(Usage
== DIB_PAL_COLORS
)
1895 ColorsSize
= numColors
* sizeof(WORD
);
1899 ColorsSize
= numColors
* sizeof(RGBQUAD
);
1902 else if (Usage
== DIB_PAL_COLORS
)
1904 /* Invalid at high Res */
1908 pNewBmi
= ExAllocatePoolWithTag(PagedPool
, sizeof(BITMAPINFOHEADER
) + ColorsSize
, TAG_DIB
);
1909 if(!pNewBmi
) return NULL
;
1911 RtlZeroMemory(pNewBmi
, sizeof(BITMAPINFOHEADER
) + ColorsSize
);
1913 pNewBmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1914 pNewBmi
->bmiHeader
.biBitCount
= pbmci
->bmciHeader
.bcBitCount
;
1915 pNewBmi
->bmiHeader
.biWidth
= pbmci
->bmciHeader
.bcWidth
;
1916 pNewBmi
->bmiHeader
.biHeight
= pbmci
->bmciHeader
.bcHeight
;
1917 pNewBmi
->bmiHeader
.biPlanes
= pbmci
->bmciHeader
.bcPlanes
;
1918 pNewBmi
->bmiHeader
.biCompression
= BI_RGB
;
1919 pNewBmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(pNewBmi
->bmiHeader
.biWidth
,
1920 pNewBmi
->bmiHeader
.biHeight
,
1921 pNewBmi
->bmiHeader
.biBitCount
);
1923 if(Usage
== DIB_PAL_COLORS
)
1925 RtlCopyMemory(pNewBmi
->bmiColors
, pbmci
->bmciColors
, ColorsSize
);
1930 for(i
=0; i
<numColors
; i
++)
1932 pNewBmi
->bmiColors
[i
].rgbRed
= pbmci
->bmciColors
[i
].rgbtRed
;
1933 pNewBmi
->bmiColors
[i
].rgbGreen
= pbmci
->bmciColors
[i
].rgbtGreen
;
1934 pNewBmi
->bmiColors
[i
].rgbBlue
= pbmci
->bmciColors
[i
].rgbtBlue
;
1941 /* Frees a BITMAPINFO created with DIB_ConvertBitmapInfo */
1944 DIB_FreeConvertedBitmapInfo(BITMAPINFO
* converted
, BITMAPINFO
* orig
)
1946 if(converted
!= orig
)
1947 ExFreePoolWithTag(converted
, TAG_DIB
);