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 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
143 if (psurf
->hSecure
== NULL
)
146 SetLastWin32Error(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 SetLastWin32Error(ERROR_INVALID_HANDLE
);
163 PalGDI
= PALETTE_LockPalette(psurf
->ppal
->BaseObject
.hHmgr
);
165 for (Index
= StartIndex
;
166 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
169 PalGDI
->IndexedColors
[Index
].peRed
= Colors
[Index
- StartIndex
].rgbRed
;
170 PalGDI
->IndexedColors
[Index
].peGreen
= Colors
[Index
- StartIndex
].rgbGreen
;
171 PalGDI
->IndexedColors
[Index
].peBlue
= Colors
[Index
- StartIndex
].rgbBlue
;
173 PALETTE_UnlockPalette(PalGDI
);
178 /* Mark the brushes invalid */
179 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
|DIRTY_LINE
|DIRTY_BACKGROUND
|DIRTY_TEXT
;
197 UINT Index
, Count
= 0;
200 if (!(dc
= DC_LockDc(hDC
))) return 0;
201 if (dc
->dctype
== DC_TYPE_INFO
)
207 psurf
= dc
->dclevel
.pSurface
;
211 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
215 if (psurf
->hSecure
== NULL
)
218 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
222 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
223 if (biBitCount
<= 8 &&
224 StartIndex
< (1 << biBitCount
))
226 if (StartIndex
+ Entries
> (1 << biBitCount
))
227 Entries
= (1 << biBitCount
) - StartIndex
;
229 if (psurf
->ppal
== NULL
)
232 SetLastWin32Error(ERROR_INVALID_HANDLE
);
236 PalGDI
= PALETTE_LockPalette(psurf
->ppal
->BaseObject
.hHmgr
);
238 for (Index
= StartIndex
;
239 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
242 Colors
[Index
- StartIndex
].rgbRed
= PalGDI
->IndexedColors
[Index
].peRed
;
243 Colors
[Index
- StartIndex
].rgbGreen
= PalGDI
->IndexedColors
[Index
].peGreen
;
244 Colors
[Index
- StartIndex
].rgbBlue
= PalGDI
->IndexedColors
[Index
].peBlue
;
245 Colors
[Index
- StartIndex
].rgbReserved
= 0;
248 PALETTE_UnlockPalette(PalGDI
);
256 // Converts a DIB to a device-dependent bitmap
265 CONST BITMAPINFO
*bmi
,
268 HBITMAP SourceBitmap
, hOldSrcBmp
= NULL
, hOldDstBmp
= NULL
;
273 SourceBitmap
= DIB_CreateDIBSection(DC
, bmi
, ColorUse
, &pvBits
, NULL
, 0, 0);
274 if (0 == SourceBitmap
)
276 DPRINT1("Error : Could not create a DIBSection.\n");
277 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
281 RtlCopyMemory(pvBits
, Bits
, DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
,
282 bmi
->bmiHeader
.biHeight
,
283 bmi
->bmiHeader
.biBitCount
));
285 hdcSrc
= NtGdiCreateCompatibleDC(0);
286 hdcDst
= NtGdiCreateCompatibleDC(0);
288 if(!(hdcSrc
&& hdcDst
))
290 DPRINT1("Error, could not create memory DCs.\n");
294 hOldSrcBmp
= NtGdiSelectBitmap(hdcSrc
, SourceBitmap
);
295 hOldDstBmp
= NtGdiSelectBitmap(hdcDst
, hBitmap
);
297 if(!(hOldSrcBmp
&& hOldDstBmp
))
299 DPRINT1("Error : Could not select bitmaps into DCs\n");
303 result
= NtGdiBitBlt(hdcDst
, 0, 0, bmi
->bmiHeader
.biWidth
, ScanLines
, hdcSrc
, 0, StartScan
,
312 if(hOldSrcBmp
) NtGdiSelectBitmap(hdcSrc
, hOldSrcBmp
);
313 NtGdiDeleteObjectApp(hdcSrc
);
317 if(hOldDstBmp
) NtGdiSelectBitmap(hdcDst
, hOldDstBmp
);
318 NtGdiDeleteObjectApp(hdcDst
);
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
))
370 SetLastWin32Error(ERROR_INVALID_HANDLE
);
373 if (Dc
->dctype
== DC_TYPE_INFO
)
379 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
389 NtGdiSetDIBitsToDeviceInternal(
404 IN BOOL bTransformCoordinates
,
405 IN OPTIONAL HANDLE hcmXform
)
408 NTSTATUS Status
= STATUS_SUCCESS
;
410 HBITMAP hSourceBitmap
= NULL
;
411 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
418 PPALETTE ppalDIB
= NULL
;
419 HPALETTE hpalDIB
= NULL
;
425 ProbeForRead(bmi
, cjMaxInfo
, 1);
426 ProbeForRead(Bits
, cjMaxBits
, 1);
428 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
430 Status
= _SEH2_GetExceptionCode();
434 if (!NT_SUCCESS(Status
))
439 pDC
= DC_LockDc(hDC
);
442 SetLastWin32Error(ERROR_INVALID_HANDLE
);
445 if (pDC
->dctype
== DC_TYPE_INFO
)
451 pSurf
= pDC
->dclevel
.pSurface
;
453 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
455 ScanLines
= min(ScanLines
, abs(bmi
->bmiHeader
.biHeight
) - StartScan
);
459 if (bTransformCoordinates
)
461 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
463 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
464 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
465 rcDest
.right
= rcDest
.left
+ Width
;
466 rcDest
.bottom
= rcDest
.top
+ Height
;
467 rcDest
.top
+= StartScan
;
472 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
473 SourceSize
.cy
= ScanLines
;
475 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
477 hSourceBitmap
= EngCreateBitmap(SourceSize
,
479 BitmapFormat(bmi
->bmiHeader
.biBitCount
,
480 bmi
->bmiHeader
.biCompression
),
481 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
485 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
486 Status
= STATUS_NO_MEMORY
;
490 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
493 Status
= STATUS_UNSUCCESSFUL
;
499 /* Create a palette for the DIB */
500 hpalDIB
= BuildDIBPalette(bmi
);
503 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
504 Status
= STATUS_NO_MEMORY
;
508 /* Lock the DIB palette */
509 ppalDIB
= PALETTE_LockPalette(hpalDIB
);
512 SetLastWin32Error(ERROR_INVALID_HANDLE
);
513 Status
= STATUS_UNSUCCESSFUL
;
517 /* Initialize EXLATEOBJ */
518 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, pSurf
->ppal
, 0, 0, 0);
521 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
522 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
523 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
524 Status
= IntEngBitBlt(pDestSurf
,
527 pDC
->rosdc
.CombinedClip
,
534 ROP3_TO_ROP4(SRCCOPY
));
536 /* Cleanup EXLATEOBJ */
537 EXLATEOBJ_vCleanup(&exlo
);
540 if (NT_SUCCESS(Status
))
545 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
547 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
548 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
549 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
556 /* Converts a device-dependent bitmap to a DIB */
559 NtGdiGetDIBitsInternal(
570 BITMAPCOREINFO
* pbmci
= NULL
;
571 PSURFACE psurf
= NULL
;
577 RGBTRIPLE
* rgbTriples
;
580 NTSTATUS Status
= STATUS_SUCCESS
;
582 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
584 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
589 /* Probe for read and write */
590 ProbeForRead(Info
, MaxInfo
, 1);
591 ProbeForWrite(Info
, MaxInfo
, 1);
592 if (Bits
) ProbeForWrite(Bits
, MaxBits
, 1);
594 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
596 Status
= _SEH2_GetExceptionCode();
600 if (!NT_SUCCESS(Status
))
605 colorPtr
= (LPBYTE
)Info
+ Info
->bmiHeader
.biSize
;
606 rgbTriples
= colorPtr
;
609 bitmap_type
= DIB_GetBitmapInfo(&Info
->bmiHeader
,
616 if(bitmap_type
== -1)
618 DPRINT("Wrong bitmap format\n");
619 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
622 else if(bitmap_type
== 0)
624 /* We need a BITMAPINFO to create a DIB, but we have to fill
625 * the BITMAPCOREINFO we're provided */
626 pbmci
= (BITMAPCOREINFO
*)Info
;
627 Info
= DIB_ConvertBitmapInfo((BITMAPINFO
*)pbmci
, Usage
);
630 DPRINT1("Error, could not convert the BITMAPCOREINFO!\n");
633 rgbQuads
= Info
->bmiColors
;
636 pDC
= DC_LockDc(hDC
);
637 if (pDC
== NULL
|| pDC
->dctype
== DC_TYPE_INFO
)
643 /* Get a pointer to the source bitmap object */
644 psurf
= SURFACE_LockSurface(hBitmap
);
651 /* Fill in the structure */
654 case 0: /* Only info */
657 pbmci
->bmciHeader
.bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
658 pbmci
->bmciHeader
.bcHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
659 -psurf
->SurfObj
.sizlBitmap
.cy
:
660 psurf
->SurfObj
.sizlBitmap
.cy
;
661 pbmci
->bmciHeader
.bcPlanes
= 1;
662 pbmci
->bmciHeader
.bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
664 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
665 Info
->bmiHeader
.biHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
666 -psurf
->SurfObj
.sizlBitmap
.cy
:
667 psurf
->SurfObj
.sizlBitmap
.cy
;;
668 Info
->bmiHeader
.biPlanes
= 1;
669 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
670 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes( Info
->bmiHeader
.biWidth
,
671 Info
->bmiHeader
.biHeight
,
672 Info
->bmiHeader
.biBitCount
);
675 switch(Info
->bmiHeader
.biBitCount
)
679 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
682 Info
->bmiHeader
.biCompression
= BI_RGB
;
686 else if(Info
->bmiHeader
.biBitCount
> 8)
688 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
692 Info
->bmiHeader
.biCompression
= BI_RGB
;
694 Info
->bmiHeader
.biXPelsPerMeter
= 0;
695 Info
->bmiHeader
.biYPelsPerMeter
= 0;
696 Info
->bmiHeader
.biClrUsed
= 0;
697 Info
->bmiHeader
.biClrImportant
= 0;
699 /* Get Complete info now */
705 Info
->bmiHeader
.biClrUsed
= 0;
707 /* If the bitmap if a DIB section and has the same format than what
708 * we're asked, go ahead! */
709 if((psurf
->hSecure
) &&
710 (BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == bpp
))
712 if(Usage
== DIB_RGB_COLORS
)
714 unsigned int colors
= min(psurf
->ppal
->NumColors
, 1 << bpp
);
718 for(i
=0; i
< colors
; i
++)
720 rgbTriples
[i
].rgbtRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
721 rgbTriples
[i
].rgbtGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
722 rgbTriples
[i
].rgbtBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
725 if(colors
!= 1 << bpp
) Info
->bmiHeader
.biClrUsed
= colors
;
726 RtlCopyMemory(rgbQuads
, psurf
->ppal
->IndexedColors
, colors
* sizeof(RGBQUAD
));
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 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
935 psurfDest
= SURFACE_LockSurface(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
, 0, 0, 0);
948 ret
= IntEngCopyBits(&psurfDest
->SurfObj
,
959 Status
= STATUS_SUCCESS
;
962 RtlCopyMemory(Bits
, pDIBits
, DIB_GetDIBImageBytes (width
, height
, bpp
));
964 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
966 Status
= _SEH2_GetExceptionCode();
970 if(!NT_SUCCESS(Status
))
972 DPRINT1("Unable to copy bits to the user provided pointer\n");
977 GreDeleteObject(hBmpDest
);
978 EXLATEOBJ_vCleanup(&exlo
);
983 if(pDC
) DC_UnlockDc(pDC
);
984 if(psurf
) SURFACE_UnlockSurface(psurf
);
985 if(pbmci
) DIB_FreeConvertedBitmapInfo(Info
, (BITMAPINFO
*)pbmci
);
993 NtGdiStretchDIBitsInternal(
1004 LPBITMAPINFO BitsInfo
,
1011 HBITMAP hBitmap
, hOldBitmap
= NULL
;
1013 NTSTATUS Status
= STATUS_SUCCESS
;
1017 if (!Bits
|| !BitsInfo
)
1019 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1023 /* Create a DIB Section, data will be probed there */
1024 hBitmap
= NtGdiCreateDIBSection(hDC
,
1036 DPRINT1("Failed to create a DIB.\n");
1042 ProbeForRead(Bits
, cjMaxBits
, 1);
1043 RtlCopyMemory(pvDIBits
, Bits
, DIB_GetDIBImageBytes(BitsInfo
->bmiHeader
.biWidth
,
1044 BitsInfo
->bmiHeader
.biHeight
,
1045 BitsInfo
->bmiHeader
.biBitCount
));
1047 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1049 Status
= _SEH2_GetExceptionCode();
1053 if(!NT_SUCCESS(Status
))
1055 DPRINT1("Error : Could not read DIB bits\n");
1056 SetLastNtError(Status
);
1060 hdcMem
= NtGdiCreateCompatibleDC(0);
1063 DPRINT1("Failed to create a memory DC!");
1067 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1070 DPRINT1("Could not select the DIB into the memory DC\n");
1074 /* Do we want to stretch ? */
1075 if((SrcWidth
== DestWidth
) && (SrcHeight
== DestHeight
))
1077 Ret
= NtGdiBitBlt(hDC
, XDest
, YDest
, XDest
+ DestWidth
, YDest
+ DestHeight
,
1078 hdcMem
, XSrc
, YSrc
, ROP
, 0, 0);
1082 Ret
= NtGdiStretchBlt(hDC
, XDest
, YDest
, XDest
+ DestWidth
, YDest
+ DestHeight
,
1083 hdcMem
, XSrc
, YSrc
, XSrc
+ SrcWidth
, YSrc
+ SrcHeight
,
1093 if(hOldBitmap
) NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1094 NtGdiDeleteObjectApp(hdcMem
);
1096 GreDeleteObject(hBitmap
);
1117 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1118 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1120 if (bpp
!= 1) fColor
= TRUE
;
1121 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1124 const RGBQUAD
*rgb
= (RGBQUAD
*)((PBYTE
)data
+ data
->bmiHeader
.biSize
);
1125 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1127 // Check if the first color of the colormap is black
1128 if ((col
== RGB(0, 0, 0)))
1131 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1133 // If the second color is white, create a monochrome bitmap
1134 fColor
= (col
!= RGB(0xff,0xff,0xff));
1139 // Now create the bitmap
1142 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1146 handle
= GreCreateBitmap(width
,
1156 if (NULL
!= handle
&& CBM_INIT
== init
)
1158 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1164 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1165 // The DDB that is created will be whatever bit depth your reference DC is
1168 NtGdiCreateDIBitmapInternal(
1173 IN OPTIONAL LPBYTE pjInit
,
1174 IN OPTIONAL LPBITMAPINFO pbmi
,
1176 IN UINT cjMaxInitInfo
,
1181 NTSTATUS Status
= STATUS_SUCCESS
;
1185 if(pbmi
) ProbeForRead(pbmi
, cjMaxInitInfo
, 1);
1186 if(pjInit
&& (fInit
== CBM_INIT
)) ProbeForRead(pjInit
, cjMaxBits
, 1);
1188 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1190 Status
= _SEH2_GetExceptionCode();
1194 if(!NT_SUCCESS(Status
))
1196 SetLastNtError(Status
);
1200 return GreCreateDIBitmapInternal(hDc
,
1213 GreCreateDIBitmapInternal(
1218 IN OPTIONAL LPBYTE pjInit
,
1219 IN OPTIONAL PBITMAPINFO pbmi
,
1229 if (!hDc
) /* 1bpp monochrome bitmap */
1230 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1231 hdcDest
= NtGdiCreateCompatibleDC(0);
1242 Dc
= DC_LockDc(hdcDest
);
1245 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1248 /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
1249 * if bpp != 1 and ignore the real value that was passed */
1251 bpp
= pbmi
->bmiHeader
.biBitCount
;
1254 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1259 NtGdiDeleteObjectApp(hdcDest
);
1267 NtGdiCreateDIBSection(
1269 IN OPTIONAL HANDLE hSection
,
1275 IN ULONG_PTR dwColorSpace
,
1278 HBITMAP hbitmap
= 0;
1280 BOOL bDesktopDC
= FALSE
;
1281 NTSTATUS Status
= STATUS_SUCCESS
;
1283 if (!bmi
) return hbitmap
; // Make sure.
1287 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
1288 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
1289 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, Usage
), 1);
1291 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1293 Status
= _SEH2_GetExceptionCode();
1297 if(!NT_SUCCESS(Status
))
1299 SetLastNtError(Status
);
1303 // If the reference hdc is null, take the desktop dc
1306 hDC
= NtGdiCreateCompatibleDC(0);
1310 if ((dc
= DC_LockDc(hDC
)))
1312 hbitmap
= DIB_CreateDIBSection(dc
,
1323 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1327 NtGdiDeleteObjectApp(hDC
);
1334 DIB_CreateDIBSection(
1336 CONST BITMAPINFO
*bmi
,
1344 SURFACE
*bmp
= NULL
;
1345 void *mapBits
= NULL
;
1348 // Fill BITMAP32 structure with DIB data
1349 CONST BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1356 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1357 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1358 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1360 /* CreateDIBSection should fail for compressed formats */
1361 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1363 return (HBITMAP
)NULL
;
1366 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1368 bm
.bmWidth
= bi
->biWidth
;
1369 bm
.bmHeight
= effHeight
;
1370 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1372 bm
.bmPlanes
= bi
->biPlanes
;
1373 bm
.bmBitsPixel
= bi
->biBitCount
;
1376 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1377 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1378 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1379 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1383 SYSTEM_BASIC_INFORMATION Sbi
;
1386 LARGE_INTEGER SectionOffset
;
1389 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1393 if (!NT_SUCCESS(Status
))
1398 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1399 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1401 SectionOffset
.LowPart
= mapOffset
;
1402 SectionOffset
.HighPart
= 0;
1404 Status
= ZwMapViewOfSection(section
,
1414 if (!NT_SUCCESS(Status
))
1416 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1420 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1422 else if (ovr_pitch
&& offset
)
1423 bm
.bmBits
= (LPVOID
) offset
;
1427 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1428 if(!bm
.bmBits
) goto cleanup
;
1431 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1432 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1434 if (usage
== DIB_PAL_COLORS
)
1439 pdcPal
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1440 hpal
= DIB_MapPaletteColors(pdcPal
, bmi
);
1441 PALETTE_UnlockPalette(pdcPal
);
1445 /* For DIB Brushes */
1446 DPRINT1("FIXME : Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
1448 hpal
= (HPALETTE
) 0xFFFFFFFF;
1453 hpal
= BuildDIBPalette(bmi
);
1458 DPRINT1("Error : Could not create a palette for the DIB.\n");
1462 // Create Device Dependent Bitmap and add DIB pointer
1463 Size
.cx
= bm
.bmWidth
;
1464 Size
.cy
= abs(bm
.bmHeight
);
1465 res
= GreCreateBitmapEx(bm
.bmWidth
,
1468 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1469 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1470 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1476 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1479 bmp
= SURFACE_LockSurface(res
);
1482 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1486 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1487 table between the DIB and the X physical device. Obviously,
1488 this is left out of the ReactOS implementation. Instead,
1489 we call NtGdiSetDIBColorTable. */
1490 bmp
->hDIBSection
= section
;
1491 bmp
->hSecure
= hSecure
;
1492 bmp
->dwOffset
= offset
;
1493 bmp
->flags
= API_BITMAP
;
1494 bmp
->biClrImportant
= bi
->biClrImportant
;
1497 if(hpal
!= (HPALETTE
)0xFFFFFFFF)
1499 bmp
->ppal
= PALETTE_ShareLockPalette(hpal
);
1500 /* Lazy delete hpal, it will be freed at surface release */
1501 GreDeleteObject(hpal
);
1504 // Clean up in case of errors
1506 if (!res
|| !bmp
|| !bm
.bmBits
)
1508 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1511 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1514 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1519 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1527 SURFACE_FreeSurfaceByHandle(res
);
1534 SURFACE_UnlockSurface(bmp
);
1537 // Return BITMAP handle and storage location
1538 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1546 /***********************************************************************
1549 * Get the info from a bitmap header.
1550 * Return 0 for COREHEADER, 1 for INFOHEADER, -1 for error.
1554 DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
1555 LONG
*height
, WORD
*planes
, WORD
*bpp
, DWORD
*compr
, DWORD
*size
)
1557 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
1559 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
1560 *width
= core
->bcWidth
;
1561 *height
= core
->bcHeight
;
1562 *planes
= core
->bcPlanes
;
1563 *bpp
= core
->bcBitCount
;
1568 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
)) /* assume BITMAPINFOHEADER */
1570 *width
= header
->biWidth
;
1571 *height
= header
->biHeight
;
1572 *planes
= header
->biPlanes
;
1573 *bpp
= header
->biBitCount
;
1574 *compr
= header
->biCompression
;
1575 *size
= header
->biSizeImage
;
1578 DPRINT1("(%d): unknown/wrong size for header\n", header
->biSize
);
1582 /***********************************************************************
1583 * DIB_GetDIBWidthBytes
1585 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1586 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1587 * 11/16/1999 (RJJ) lifted from wine
1589 INT FASTCALL
DIB_GetDIBWidthBytes(INT width
, INT depth
)
1591 return ((width
* depth
+ 31) & ~31) >> 3;
1594 /***********************************************************************
1595 * DIB_GetDIBImageBytes
1597 * Return the number of bytes used to hold the image in a DIB bitmap.
1598 * 11/16/1999 (RJJ) lifted from wine
1601 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1603 return DIB_GetDIBWidthBytes(width
, depth
) * (height
< 0 ? -height
: height
);
1606 /***********************************************************************
1607 * DIB_BitmapInfoSize
1609 * Return the size of the bitmap info structure including color table.
1610 * 11/16/1999 (RJJ) lifted from wine
1613 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1615 unsigned int colors
, size
, masks
= 0;
1617 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1619 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
1620 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1621 return sizeof(BITMAPCOREHEADER
) + colors
*
1622 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1624 else /* assume BITMAPINFOHEADER */
1626 colors
= info
->bmiHeader
.biClrUsed
;
1627 if (colors
> 256) colors
= 256;
1628 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
1629 colors
= 1 << info
->bmiHeader
.biBitCount
;
1630 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
1631 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
1632 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1638 DIB_MapPaletteColors(PPALETTE ppal
, CONST BITMAPINFO
* lpbmi
)
1640 PALETTEENTRY
* ppalEntries
;
1645 if (ppal
->Mode
!= PAL_INDEXED
)
1650 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1651 if (lpbmi
->bmiHeader
.biClrUsed
)
1653 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1656 /* Don't have more colors than we need */
1657 nNumColors
= min(ppal
->NumColors
, nNumColors
);
1659 ppalEntries
= ExAllocatePoolWithTag(PagedPool
, sizeof(PALETTEENTRY
) * nNumColors
, TAG_COLORMAP
);
1660 if (ppalEntries
== NULL
)
1662 DPRINT1("Could not allocate palette entries\n");
1666 lpIndex
= (USHORT
*)((PBYTE
)lpbmi
+ lpbmi
->bmiHeader
.biSize
);
1668 for (i
= 0; i
< nNumColors
; i
++)
1670 if (*lpIndex
< ppal
->NumColors
)
1672 ppalEntries
[i
] = ppal
->IndexedColors
[*lpIndex
];
1676 ppalEntries
[i
].peRed
= 0;
1677 ppalEntries
[i
].peGreen
= 0;
1678 ppalEntries
[i
].peBlue
= 0;
1679 ppalEntries
[i
].peFlags
= 0;
1685 hpal
= PALETTE_AllocPalette(PAL_INDEXED
, nNumColors
, (ULONG
*)ppalEntries
, 0, 0, 0);
1687 ExFreePoolWithTag(ppalEntries
, TAG_COLORMAP
);
1694 BuildDIBPalette(CONST BITMAPINFO
*bmi
)
1699 ULONG RedMask
= 0, GreenMask
= 0, BlueMask
= 0;
1700 PDWORD pdwColors
= (PDWORD
)((PBYTE
)bmi
+ bmi
->bmiHeader
.biSize
);
1703 // Determine Bits Per Pixel
1704 bits
= bmi
->bmiHeader
.biBitCount
;
1706 // Determine paletteType from Bits Per Pixel
1709 paletteType
= PAL_INDEXED
;
1710 RedMask
= GreenMask
= BlueMask
= 0;
1712 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1714 paletteType
= PAL_BITFIELDS
;
1715 RedMask
= pdwColors
[0];
1716 GreenMask
= pdwColors
[1];
1717 BlueMask
= pdwColors
[2];
1719 else if (bits
== 15)
1721 paletteType
= PAL_RGB16_555
;
1723 else if (bits
== 16)
1725 paletteType
= PAL_RGB16_565
;
1729 paletteType
= PAL_BGR
;
1732 if (bmi
->bmiHeader
.biClrUsed
== 0)
1734 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1738 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1741 if (PAL_INDEXED
== paletteType
)
1743 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)pdwColors
);
1747 hPal
= PALETTE_AllocPalette(paletteType
, 0,
1749 RedMask
, GreenMask
, BlueMask
);
1755 /* Converts a BITMAPCOREINFO to a BITMAPINFO structure,
1756 * or does nothing if it's already a BITMAPINFO (or V4 or V5) */
1759 DIB_ConvertBitmapInfo (CONST BITMAPINFO
* pbmi
, DWORD Usage
)
1761 CONST BITMAPCOREINFO
* pbmci
= (BITMAPCOREINFO
*)pbmi
;
1762 BITMAPINFO
* pNewBmi
;
1763 UINT numColors
= 0, ColorsSize
= 0;
1765 if(pbmi
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
)) return (BITMAPINFO
*)pbmi
;
1766 if(pbmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) return NULL
;
1768 if(pbmci
->bmciHeader
.bcBitCount
<= 8)
1770 numColors
= 1 << pbmci
->bmciHeader
.bcBitCount
;
1771 if(Usage
== DIB_PAL_COLORS
)
1773 ColorsSize
= numColors
* sizeof(WORD
);
1777 ColorsSize
= numColors
* sizeof(RGBQUAD
);
1780 else if (Usage
== DIB_PAL_COLORS
)
1782 /* Invalid at high Res */
1786 pNewBmi
= ExAllocatePoolWithTag(PagedPool
, sizeof(BITMAPINFOHEADER
) + ColorsSize
, TAG_DIB
);
1787 if(!pNewBmi
) return NULL
;
1789 RtlZeroMemory(pNewBmi
, sizeof(BITMAPINFOHEADER
) + ColorsSize
);
1791 pNewBmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1792 pNewBmi
->bmiHeader
.biBitCount
= pbmci
->bmciHeader
.bcBitCount
;
1793 pNewBmi
->bmiHeader
.biWidth
= pbmci
->bmciHeader
.bcWidth
;
1794 pNewBmi
->bmiHeader
.biHeight
= pbmci
->bmciHeader
.bcHeight
;
1795 pNewBmi
->bmiHeader
.biPlanes
= pbmci
->bmciHeader
.bcPlanes
;
1796 pNewBmi
->bmiHeader
.biCompression
= BI_RGB
;
1797 pNewBmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(pNewBmi
->bmiHeader
.biWidth
,
1798 pNewBmi
->bmiHeader
.biHeight
,
1799 pNewBmi
->bmiHeader
.biBitCount
);
1801 if(Usage
== DIB_PAL_COLORS
)
1803 RtlCopyMemory(pNewBmi
->bmiColors
, pbmci
->bmciColors
, ColorsSize
);
1808 for(i
=0; i
<numColors
; i
++)
1810 pNewBmi
->bmiColors
[i
].rgbRed
= pbmci
->bmciColors
[i
].rgbtRed
;
1811 pNewBmi
->bmiColors
[i
].rgbGreen
= pbmci
->bmciColors
[i
].rgbtGreen
;
1812 pNewBmi
->bmiColors
[i
].rgbBlue
= pbmci
->bmciColors
[i
].rgbtBlue
;
1819 /* Frees a BITMAPINFO created with DIB_ConvertBitmapInfo */
1822 DIB_FreeConvertedBitmapInfo(BITMAPINFO
* converted
, BITMAPINFO
* orig
)
1824 if(converted
!= orig
)
1825 ExFreePoolWithTag(converted
, TAG_DIB
);