4 * ReactOS W32 Subsystem
5 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 static const RGBQUAD EGAColorsQuads
[16] = {
28 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
29 { 0x00, 0x00, 0x00, 0x00 },
30 { 0x00, 0x00, 0x80, 0x00 },
31 { 0x00, 0x80, 0x00, 0x00 },
32 { 0x00, 0x80, 0x80, 0x00 },
33 { 0x80, 0x00, 0x00, 0x00 },
34 { 0x80, 0x00, 0x80, 0x00 },
35 { 0x80, 0x80, 0x00, 0x00 },
36 { 0x80, 0x80, 0x80, 0x00 },
37 { 0xc0, 0xc0, 0xc0, 0x00 },
38 { 0x00, 0x00, 0xff, 0x00 },
39 { 0x00, 0xff, 0x00, 0x00 },
40 { 0x00, 0xff, 0xff, 0x00 },
41 { 0xff, 0x00, 0x00, 0x00 },
42 { 0xff, 0x00, 0xff, 0x00 },
43 { 0xff, 0xff, 0x00, 0x00 },
44 { 0xff, 0xff, 0xff, 0x00 }
47 static const RGBQUAD DefLogPaletteQuads
[20] = { /* Copy of Default Logical Palette */
48 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
49 { 0x00, 0x00, 0x00, 0x00 },
50 { 0x00, 0x00, 0x80, 0x00 },
51 { 0x00, 0x80, 0x00, 0x00 },
52 { 0x00, 0x80, 0x80, 0x00 },
53 { 0x80, 0x00, 0x00, 0x00 },
54 { 0x80, 0x00, 0x80, 0x00 },
55 { 0x80, 0x80, 0x00, 0x00 },
56 { 0xc0, 0xc0, 0xc0, 0x00 },
57 { 0xc0, 0xdc, 0xc0, 0x00 },
58 { 0xf0, 0xca, 0xa6, 0x00 },
59 { 0xf0, 0xfb, 0xff, 0x00 },
60 { 0xa4, 0xa0, 0xa0, 0x00 },
61 { 0x80, 0x80, 0x80, 0x00 },
62 { 0x00, 0x00, 0xf0, 0x00 },
63 { 0x00, 0xff, 0x00, 0x00 },
64 { 0x00, 0xff, 0xff, 0x00 },
65 { 0xff, 0x00, 0x00, 0x00 },
66 { 0xff, 0x00, 0xff, 0x00 },
67 { 0xff, 0xff, 0x00, 0x00 },
68 { 0xff, 0xff, 0xff, 0x00 }
78 CONST RGBQUAD
*Colors
)
86 if (!(dc
= DC_LockDc(hDC
))) return 0;
87 if (dc
->dctype
== DC_TYPE_INFO
)
93 psurf
= dc
->dclevel
.pSurface
;
97 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
101 if (psurf
->hSecure
== NULL
)
104 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
108 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
109 if (biBitCount
<= 8 && StartIndex
< (1 << biBitCount
))
111 if (StartIndex
+ Entries
> (1 << biBitCount
))
112 Entries
= (1 << biBitCount
) - StartIndex
;
114 PalGDI
= PALETTE_LockPalette(psurf
->hDIBPalette
);
118 SetLastWin32Error(ERROR_INVALID_HANDLE
);
122 for (Index
= StartIndex
;
123 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
126 PalGDI
->IndexedColors
[Index
].peRed
= Colors
[Index
- StartIndex
].rgbRed
;
127 PalGDI
->IndexedColors
[Index
].peGreen
= Colors
[Index
- StartIndex
].rgbGreen
;
128 PalGDI
->IndexedColors
[Index
].peBlue
= Colors
[Index
- StartIndex
].rgbBlue
;
130 PALETTE_UnlockPalette(PalGDI
);
135 /* Mark the brushes invalid */
136 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
|DIRTY_LINE
|DIRTY_BACKGROUND
|DIRTY_TEXT
;
157 if (!(dc
= DC_LockDc(hDC
))) return 0;
158 if (dc
->dctype
== DC_TYPE_INFO
)
164 psurf
= dc
->dclevel
.pSurface
;
168 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
172 if (psurf
->hSecure
== NULL
)
175 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
179 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
180 if (biBitCount
<= 8 &&
181 StartIndex
< (1 << biBitCount
))
183 if (StartIndex
+ Entries
> (1 << biBitCount
))
184 Entries
= (1 << biBitCount
) - StartIndex
;
186 PalGDI
= PALETTE_LockPalette(psurf
->hDIBPalette
);
190 SetLastWin32Error(ERROR_INVALID_HANDLE
);
194 for (Index
= StartIndex
;
195 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
198 Colors
[Index
- StartIndex
].rgbRed
= PalGDI
->IndexedColors
[Index
].peRed
;
199 Colors
[Index
- StartIndex
].rgbGreen
= PalGDI
->IndexedColors
[Index
].peGreen
;
200 Colors
[Index
- StartIndex
].rgbBlue
= PalGDI
->IndexedColors
[Index
].peBlue
;
201 Colors
[Index
- StartIndex
].rgbReserved
= 0;
203 PALETTE_UnlockPalette(PalGDI
);
213 // Converts a DIB to a device-dependent bitmap
222 CONST BITMAPINFO
*bmi
,
226 HBITMAP SourceBitmap
;
229 SURFOBJ
*DestSurf
, *SourceSurf
;
236 HPALETTE DDB_Palette
, DIB_Palette
;
237 ULONG DDB_Palette_Type
, DIB_Palette_Type
;
241 if (!(bitmap
= SURFACE_LockSurface(hBitmap
)))
247 //if (ColorUse == DIB_PAL_COLORS)
248 // lpRGB = DIB_MapPaletteColors(hDC, bmi);
250 // lpRGB = &bmi->bmiColors;
252 DestSurf
= &bitmap
->SurfObj
;
254 // Create source surface
255 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
256 SourceSize
.cy
= ScanLines
;
258 // Determine width of DIB
259 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
261 SourceBitmap
= EngCreateBitmap(SourceSize
,
263 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
264 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
266 if (0 == SourceBitmap
)
268 SURFACE_UnlockSurface(bitmap
);
269 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
273 SourceSurf
= EngLockSurface((HSURF
)SourceBitmap
);
274 if (NULL
== SourceSurf
)
276 EngDeleteSurface((HSURF
)SourceBitmap
);
277 SURFACE_UnlockSurface(bitmap
);
278 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
282 // Use hDIBPalette if it exists
283 if (bitmap
->hDIBPalette
)
285 DDB_Palette
= bitmap
->hDIBPalette
;
289 // Destination palette obtained from the hDC
290 DDB_Palette
= DC
->ppdev
->DevInfo
.hpalDefault
;
293 hDCPalette
= PALETTE_LockPalette(DDB_Palette
);
294 if (NULL
== hDCPalette
)
296 EngUnlockSurface(SourceSurf
);
297 EngDeleteSurface((HSURF
)SourceBitmap
);
298 SURFACE_UnlockSurface(bitmap
);
299 SetLastWin32Error(ERROR_INVALID_HANDLE
);
302 DDB_Palette_Type
= hDCPalette
->Mode
;
303 PALETTE_UnlockPalette(hDCPalette
);
305 // Source palette obtained from the BITMAPINFO
306 DIB_Palette
= BuildDIBPalette((PBITMAPINFO
)bmi
, (PINT
)&DIB_Palette_Type
);
307 if (NULL
== DIB_Palette
)
309 EngUnlockSurface(SourceSurf
);
310 EngDeleteSurface((HSURF
)SourceBitmap
);
311 SURFACE_UnlockSurface(bitmap
);
312 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
316 // Determine XLATEOBJ for color translation
317 XlateObj
= IntEngCreateXlate(0, 0, DDB_Palette
, DIB_Palette
);
318 if (NULL
== XlateObj
)
320 PALETTE_FreePaletteByHandle(DIB_Palette
);
321 EngUnlockSurface(SourceSurf
);
322 EngDeleteSurface((HSURF
)SourceBitmap
);
323 SURFACE_UnlockSurface(bitmap
);
324 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
332 // Determine destination rectangle
334 DestRect
.top
= abs(bmi
->bmiHeader
.biHeight
) - StartScan
- ScanLines
;
335 DestRect
.right
= SourceSize
.cx
;
336 DestRect
.bottom
= DestRect
.top
+ ScanLines
;
338 copyBitsResult
= IntEngCopyBits(DestSurf
, SourceSurf
, NULL
, XlateObj
, &DestRect
, &ZeroPoint
);
340 // If it succeeded, return number of scanlines copies
341 if (copyBitsResult
== TRUE
)
343 result
= SourceSize
.cy
;
345 // result = abs(bmi->bmiHeader.biHeight) - StartScan;
349 EngDeleteXlate(XlateObj
);
350 PALETTE_FreePaletteByHandle(DIB_Palette
);
351 EngUnlockSurface(SourceSurf
);
352 EngDeleteSurface((HSURF
)SourceBitmap
);
354 // if (ColorUse == DIB_PAL_COLORS)
355 // WinFree((LPSTR)lpRGB);
357 SURFACE_UnlockSurface(bitmap
);
362 // FIXME by Removing NtGdiSetDIBits!!!
363 // This is a victim of the Win32k Initialization BUG!!!!!
364 // Converts a DIB to a device-dependent bitmap
373 CONST BITMAPINFO
*bmi
,
378 NTSTATUS Status
= STATUS_SUCCESS
;
384 { // FYI: We converted from CORE in gdi.
385 ProbeForRead(bmi
, sizeof(BITMAPINFO
), 1);
386 cjBits
= bmi
->bmiHeader
.biBitCount
* bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biWidth
;
387 cjBits
= ((cjBits
+ 31) & ~31) / 8;
389 ProbeForRead(Bits
, cjBits
, 1);
391 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
393 Status
= _SEH2_GetExceptionCode();
397 if (!NT_SUCCESS(Status
))
405 SetLastWin32Error(ERROR_INVALID_HANDLE
);
408 if (Dc
->dctype
== DC_TYPE_INFO
)
414 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
424 NtGdiSetDIBitsToDeviceInternal(
439 IN BOOL bTransformCoordinates
,
440 IN OPTIONAL HANDLE hcmXform
)
443 NTSTATUS Status
= STATUS_SUCCESS
;
445 HBITMAP hSourceBitmap
= NULL
;
446 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
452 XLATEOBJ
*XlateObj
= NULL
;
454 HPALETTE DDBPalette
, DIBPalette
= NULL
;
455 ULONG DDBPaletteType
, DIBPaletteType
;
461 ProbeForRead(bmi
, cjMaxInfo
, 1);
462 ProbeForRead(Bits
, cjMaxBits
, 1);
464 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
466 Status
= _SEH2_GetExceptionCode();
470 if (!NT_SUCCESS(Status
))
475 pDC
= DC_LockDc(hDC
);
478 SetLastWin32Error(ERROR_INVALID_HANDLE
);
481 if (pDC
->dctype
== DC_TYPE_INFO
)
487 /* Use destination palette obtained from the DC by default */
488 DDBPalette
= pDC
->ppdev
->DevInfo
.hpalDefault
;
490 /* Try to use hDIBPalette if it exists */
491 pSurf
= pDC
->dclevel
.pSurface
;
492 if (pSurf
&& pSurf
->hDIBPalette
)
494 DDBPalette
= pSurf
->hDIBPalette
;
497 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
501 if (bTransformCoordinates
)
503 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
505 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
506 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
507 rcDest
.right
= rcDest
.left
+ Width
;
508 rcDest
.bottom
= rcDest
.top
+ Height
;
512 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
513 SourceSize
.cy
= ScanLines
; // this one --> abs(bmi->bmiHeader.biHeight) - StartScan
514 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
516 hSourceBitmap
= EngCreateBitmap(SourceSize
,
518 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
519 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
523 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
524 Status
= STATUS_NO_MEMORY
;
528 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
531 Status
= STATUS_UNSUCCESSFUL
;
535 /* Obtain destination palette */
536 pDCPalette
= PALETTE_LockPalette(DDBPalette
);
539 SetLastWin32Error(ERROR_INVALID_HANDLE
);
540 Status
= STATUS_UNSUCCESSFUL
;
544 DDBPaletteType
= pDCPalette
->Mode
;
545 PALETTE_UnlockPalette(pDCPalette
);
547 DIBPalette
= BuildDIBPalette(bmi
, (PINT
)&DIBPaletteType
);
550 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
551 Status
= STATUS_NO_MEMORY
;
555 /* Determine XlateObj */
556 XlateObj
= IntEngCreateXlate(DDBPaletteType
, DIBPaletteType
, DDBPalette
, DIBPalette
);
559 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
560 Status
= STATUS_NO_MEMORY
;
565 Status
= IntEngBitBlt(pDestSurf
,
568 pDC
->rosdc
.CombinedClip
,
575 ROP3_TO_ROP4(SRCCOPY
));
577 if (NT_SUCCESS(Status
))
579 /* FIXME: Should probably be only the number of lines actually copied */
580 ret
= ScanLines
; // this one --> abs(Info->bmiHeader.biHeight) - StartScan;
583 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
584 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
585 if (XlateObj
) EngDeleteXlate(XlateObj
);
586 if (DIBPalette
) PALETTE_FreePaletteByHandle(DIBPalette
);
593 /* Converts a device-dependent bitmap to a DIB */
596 NtGdiGetDIBitsInternal(
608 SURFACE
*psurf
= NULL
;
609 HBITMAP hDestBitmap
= NULL
;
610 HPALETTE hSourcePalette
= NULL
;
611 HPALETTE hDestPalette
= NULL
;
612 PPALETTE SourcePalette
= NULL
;
613 PPALETTE DestPalette
= NULL
;
614 NTSTATUS Status
= STATUS_SUCCESS
;
616 BOOL bPaletteMatch
= FALSE
;
617 PBYTE ChkBits
= Bits
;
620 ULONG SourcePaletteType
= 0;
621 ULONG DestPaletteType
;
624 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
626 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
629 // if ScanLines == 0, no need to copy Bits.
635 ProbeForWrite(Info
, Info
->bmiHeader
.biSize
, 1); // Comp for Core.
636 if (ChkBits
) ProbeForWrite(ChkBits
, MaxBits
, 1);
638 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
640 Status
= _SEH2_GetExceptionCode();
644 if (!NT_SUCCESS(Status
))
650 if (Dc
== NULL
) return 0;
651 if (Dc
->dctype
== DC_TYPE_INFO
)
658 /* Get a pointer to the source bitmap object */
659 psurf
= SURFACE_LockSurface(hBitmap
);
663 hSourcePalette
= psurf
->hDIBPalette
;
666 hSourcePalette
= pPrimarySurface
->DevInfo
.hpalDefault
;
669 ColorPtr
= ((PBYTE
)Info
+ Info
->bmiHeader
.biSize
);
670 rgbQuads
= (RGBQUAD
*)ColorPtr
;
672 /* Copy palette information
673 * Always create a palette for 15 & 16 bit. */
674 if (Info
->bmiHeader
.biBitCount
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) &&
675 Info
->bmiHeader
.biBitCount
!= 15 && Info
->bmiHeader
.biBitCount
!= 16)
677 hDestPalette
= hSourcePalette
;
678 bPaletteMatch
= TRUE
;
681 hDestPalette
= BuildDIBPalette(Info
, (PINT
)&DestPaletteType
); //hDestPalette = Dc->DevInfo->hpalDefault;
683 SourcePalette
= PALETTE_LockPalette(hSourcePalette
);
684 /* FIXME - SourcePalette can be NULL!!! Don't assert here! */
685 ASSERT(SourcePalette
);
686 SourcePaletteType
= SourcePalette
->Mode
;
687 PALETTE_UnlockPalette(SourcePalette
);
691 DestPalette
= PALETTE_LockPalette(hDestPalette
);
692 /* FIXME - DestPalette can be NULL!!!! Don't assert here!!! */
693 DPRINT("DestPalette : %p\n", DestPalette
);
695 DestPaletteType
= DestPalette
->Mode
;
699 DestPalette
= SourcePalette
;
703 /* FIXME: This is largely incomplete. ATM no Core!*/
704 switch (Info
->bmiHeader
.biBitCount
)
709 Info
->bmiHeader
.biClrUsed
= 0;
710 if (psurf
->hSecure
&&
711 BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == Info
->bmiHeader
.biBitCount
)
713 if (Usage
== DIB_RGB_COLORS
)
715 if (DestPalette
->NumColors
!= 1 << Info
->bmiHeader
.biBitCount
)
716 Info
->bmiHeader
.biClrUsed
= DestPalette
->NumColors
;
718 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< DestPalette
->NumColors
;
721 rgbQuads
[Index
].rgbRed
= DestPalette
->IndexedColors
[Index
].peRed
;
722 rgbQuads
[Index
].rgbGreen
= DestPalette
->IndexedColors
[Index
].peGreen
;
723 rgbQuads
[Index
].rgbBlue
= DestPalette
->IndexedColors
[Index
].peBlue
;
724 rgbQuads
[Index
].rgbReserved
= 0;
729 PWORD Ptr
= ColorPtr
;
731 Index
< (1 << Info
->bmiHeader
.biBitCount
);
734 Ptr
[Index
] = (WORD
)Index
;
740 if (Usage
== DIB_PAL_COLORS
)
742 PWORD Ptr
= ColorPtr
;
744 Index
< (1 << Info
->bmiHeader
.biBitCount
);
747 Ptr
[Index
] = (WORD
)Index
;
750 else if (Info
->bmiHeader
.biBitCount
> 1 && bPaletteMatch
)
753 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< DestPalette
->NumColors
;
756 Info
->bmiColors
[Index
].rgbRed
= DestPalette
->IndexedColors
[Index
].peRed
;
757 Info
->bmiColors
[Index
].rgbGreen
= DestPalette
->IndexedColors
[Index
].peGreen
;
758 Info
->bmiColors
[Index
].rgbBlue
= DestPalette
->IndexedColors
[Index
].peBlue
;
759 Info
->bmiColors
[Index
].rgbReserved
= 0;
764 switch (Info
->bmiHeader
.biBitCount
)
767 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
= rgbQuads
[0].rgbBlue
= 0;
768 rgbQuads
[0].rgbReserved
= 0;
769 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
= rgbQuads
[1].rgbBlue
= 0xff;
770 rgbQuads
[1].rgbReserved
= 0;
773 RtlCopyMemory(ColorPtr
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
780 RtlCopyMemory(rgbQuads
, DefLogPaletteQuads
, 10 * sizeof(RGBQUAD
));
781 RtlCopyMemory(rgbQuads
+ 246, DefLogPaletteQuads
+ 10, 10 * sizeof(RGBQUAD
));
782 color
= rgbQuads
+ 10;
783 for (r
= 0; r
<= 5; r
++) /* FIXME */
784 for (g
= 0; g
<= 5; g
++)
785 for (b
= 0; b
<= 5; b
++)
787 color
->rgbRed
= (r
* 0xff) / 5;
788 color
->rgbGreen
= (g
* 0xff) / 5;
789 color
->rgbBlue
= (b
* 0xff) / 5;
790 color
->rgbReserved
= 0;
800 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
802 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
803 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
804 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
809 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
811 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
812 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
813 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
819 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
821 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
822 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
823 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
829 PALETTE_UnlockPalette(DestPalette
);
831 /* fill out the BITMAPINFO struct */
833 { // Core or not to Core? We have converted from Core in Gdi~ so?
834 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
836 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
837 coreheader
->bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
838 coreheader
->bcPlanes
= 1;
839 coreheader
->bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
840 coreheader
->bcHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
841 if (psurf
->SurfObj
.lDelta
> 0)
842 coreheader
->bcHeight
= -coreheader
->bcHeight
;
845 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
847 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
848 Info
->bmiHeader
.biHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
849 Info
->bmiHeader
.biPlanes
= 1;
850 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
851 switch (psurf
->SurfObj
.iBitmapFormat
)
853 /* FIXME: What about BI_BITFIELDS? */
860 Info
->bmiHeader
.biCompression
= BI_RGB
;
863 Info
->bmiHeader
.biCompression
= BI_RLE4
;
866 Info
->bmiHeader
.biCompression
= BI_RLE8
;
869 Info
->bmiHeader
.biCompression
= BI_JPEG
;
872 Info
->bmiHeader
.biCompression
= BI_PNG
;
875 /* Image size has to be calculated */
876 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(Info
->bmiHeader
.biWidth
,
877 Info
->bmiHeader
.biBitCount
) * Info
->bmiHeader
.biHeight
;
878 Info
->bmiHeader
.biXPelsPerMeter
= 0; /* FIXME */
879 Info
->bmiHeader
.biYPelsPerMeter
= 0; /* FIXME */
880 Info
->bmiHeader
.biClrUsed
= 0;
881 Info
->bmiHeader
.biClrImportant
= 1 << Info
->bmiHeader
.biBitCount
; /* FIXME */
882 /* Report negtive height for top-down bitmaps. */
883 if (psurf
->SurfObj
.lDelta
> 0)
884 Info
->bmiHeader
.biHeight
= -Info
->bmiHeader
.biHeight
;
886 Result
= psurf
->SurfObj
.sizlBitmap
.cy
;
894 // If we have a good dib pointer, why not just copy bits from there w/o XLATE'ing them.
896 /* Create the destination bitmap too for the copy operation */
897 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
903 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
904 DestSize
.cx
= psurf
->SurfObj
.sizlBitmap
.cx
;
905 DestSize
.cy
= ScanLines
;
909 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
911 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
912 hDestBitmap
= EngCreateBitmap(DestSize
,
913 DIB_GetDIBWidthBytes(DestSize
.cx
, coreheader
->bcBitCount
),
914 BitmapFormat(coreheader
->bcBitCount
, BI_RGB
),
915 0 < coreheader
->bcHeight
? 0 : BMF_TOPDOWN
,
919 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
921 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(DestSize
.cx
,
922 Info
->bmiHeader
.biBitCount
) * DestSize
.cy
;
924 hDestBitmap
= EngCreateBitmap(DestSize
,
925 DIB_GetDIBWidthBytes(DestSize
.cx
, Info
->bmiHeader
.biBitCount
),
926 BitmapFormat(Info
->bmiHeader
.biBitCount
, Info
->bmiHeader
.biCompression
),
927 0 < Info
->bmiHeader
.biHeight
? 0 : BMF_TOPDOWN
,
931 if (hDestBitmap
== NULL
)
935 if (NT_SUCCESS(Status
))
938 SURFOBJ
*DestSurfObj
;
941 XlateObj
= IntEngCreateXlate(DestPaletteType
,
947 SourcePoint
.y
= psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
);
949 /* Determine destination rectangle */
952 DestRect
.right
= DestSize
.cx
;
953 DestRect
.bottom
= DestSize
.cy
;
955 DestSurfObj
= EngLockSurface((HSURF
)hDestBitmap
);
957 if (IntEngCopyBits(DestSurfObj
,
964 DPRINT("GetDIBits %d \n",abs(Info
->bmiHeader
.biHeight
) - StartScan
);
968 EngDeleteXlate(XlateObj
);
969 EngUnlockSurface(DestSurfObj
);
973 if (hDestBitmap
!= NULL
)
974 EngDeleteSurface((HSURF
)hDestBitmap
);
976 if (hDestPalette
!= NULL
&& bPaletteMatch
== FALSE
)
977 PALETTE_FreePaletteByHandle(hDestPalette
);
979 SURFACE_UnlockSurface(psurf
);
981 DPRINT("leaving NtGdiGetDIBitsInternal\n");
988 NtGdiStretchDIBitsInternal(
999 LPBITMAPINFO BitsInfo
,
1006 HBITMAP hBitmap
, hOldBitmap
= NULL
;
1008 HPALETTE hPal
= NULL
;
1012 if (!Bits
|| !BitsInfo
)
1014 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1020 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1021 ProbeForRead(Bits
, cjMaxBits
, 1);
1023 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1031 DPRINT1("NtGdiStretchDIBitsInternal fail to read BitMapInfo: %x or Bits: %x\n",BitsInfo
,Bits
);
1035 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1038 DPRINT1("NtGdiCreateCompatibleDC fail create hdc\n");
1042 hBitmap
= NtGdiCreateCompatibleBitmap(hDC
,
1043 abs(BitsInfo
->bmiHeader
.biWidth
),
1044 abs(BitsInfo
->bmiHeader
.biHeight
));
1045 if (hBitmap
== NULL
)
1047 DPRINT1("NtGdiCreateCompatibleBitmap fail create bitmap\n");
1048 DPRINT1("hDC : 0x%08x \n", hDC
);
1049 DPRINT1("BitsInfo->bmiHeader.biWidth : 0x%08x \n", BitsInfo
->bmiHeader
.biWidth
);
1050 DPRINT1("BitsInfo->bmiHeader.biHeight : 0x%08x \n", BitsInfo
->bmiHeader
.biHeight
);
1054 /* Select the bitmap into hdcMem, and save a handle to the old bitmap */
1055 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1057 if (Usage
== DIB_PAL_COLORS
)
1059 hPal
= NtGdiGetDCObject(hDC
, GDI_OBJECT_TYPE_PALETTE
);
1060 hPal
= GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1063 if (BitsInfo
->bmiHeader
.biCompression
== BI_RLE4
||
1064 BitsInfo
->bmiHeader
.biCompression
== BI_RLE8
)
1066 /* copy existing bitmap from destination dc */
1067 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1068 NtGdiBitBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1069 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, ROP
, 0, 0);
1071 NtGdiStretchBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1072 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1076 pDC
= DC_LockDc(hdcMem
);
1079 /* Note BitsInfo->bmiHeader.biHeight is the number of scanline,
1080 * if it negitve we getting to many scanline for scanline is UINT not
1081 * a INT, so we need make the negtive value to positve and that make the
1082 * count correct for negtive bitmap, TODO : we need testcase for this api */
1083 IntSetDIBits(pDC
, hBitmap
, 0, abs(BitsInfo
->bmiHeader
.biHeight
), Bits
,
1090 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1091 left (negative biHeight) */
1092 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1093 NtGdiBitBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1094 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1097 NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1098 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1099 SrcWidth
, SrcHeight
, ROP
, 0);
1103 GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1106 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1108 NtGdiDeleteObjectApp(hdcMem
);
1110 GreDeleteObject(hBitmap
);
1131 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1132 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1134 if (bpp
!= 1) fColor
= TRUE
;
1135 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1138 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
1140 const RGBQUAD
*rgb
= data
->bmiColors
;
1141 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1143 // Check if the first color of the colormap is black
1144 if ((col
== RGB(0, 0, 0)))
1147 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1149 // If the second color is white, create a monochrome bitmap
1150 fColor
= (col
!= RGB(0xff,0xff,0xff));
1154 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1156 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
1157 DWORD col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1159 if ((col
== RGB(0,0,0)))
1162 col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1163 fColor
= (col
!= RGB(0xff,0xff,0xff));
1169 DPRINT("(%ld): wrong size for data\n", data
->bmiHeader
.biSize
);
1174 // Now create the bitmap
1177 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1181 handle
= IntGdiCreateBitmap(width
,
1191 if (NULL
!= handle
&& CBM_INIT
== init
)
1193 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1199 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1200 // The DDB that is created will be whatever bit depth your reference DC is
1203 NtGdiCreateDIBitmapInternal(
1208 IN OPTIONAL LPBYTE pjInit
,
1209 IN OPTIONAL LPBITMAPINFO pbmi
,
1211 IN UINT cjMaxInitInfo
,
1220 if (!hDc
) // CreateBitmap
1221 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1222 hDc
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
,FALSE
);
1225 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1229 Dc
= DC_LockDc(hDc
);
1232 NtGdiDeleteObjectApp(hDc
);
1233 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1237 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1240 NtGdiDeleteObjectApp(hDc
);
1242 else // CreateCompatibleBitmap
1244 Dc
= DC_LockDc(hDc
);
1247 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1251 First create an un-initialised bitmap. The depth of the bitmap
1252 should match that of the hdc and not that supplied in bmih.
1255 bpp
= pbmi
->bmiHeader
.biBitCount
;
1258 if (Dc
->dctype
!= DC_TYPE_MEMORY
)
1259 bpp
= IntGdiGetDeviceCaps(Dc
, BITSPIXEL
);
1264 SURFACE
*psurf
= Dc
->dclevel
.pSurface
;
1265 Count
= BITMAP_GetObject(psurf
, sizeof(dibs
), &dibs
);
1270 if (Count
== sizeof(BITMAP
))
1271 /* A device-dependent bitmap is selected in the DC */
1272 bpp
= dibs
.dsBm
.bmBitsPixel
;
1274 /* A DIB section is selected in the DC */
1275 bpp
= dibs
.dsBmih
.biBitCount
;
1279 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1288 NtGdiCreateDIBSection(
1290 IN OPTIONAL HANDLE hSection
,
1292 IN LPBITMAPINFO bmi
,
1296 IN ULONG_PTR dwColorSpace
,
1299 HBITMAP hbitmap
= 0;
1301 BOOL bDesktopDC
= FALSE
;
1303 if (!bmi
) return hbitmap
; // Make sure.
1305 // If the reference hdc is null, take the desktop dc
1308 hDC
= NtGdiCreateCompatibleDC(0);
1312 if ((dc
= DC_LockDc(hDC
)))
1314 hbitmap
= DIB_CreateDIBSection(dc
,
1325 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1329 NtGdiDeleteObjectApp(hDC
);
1336 DIB_CreateDIBSection(
1346 SURFACE
*bmp
= NULL
;
1347 void *mapBits
= NULL
;
1350 // Fill BITMAP32 structure with DIB data
1351 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1358 DWORD dsBitfields
[3] = {0};
1360 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1361 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1362 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1364 /* CreateDIBSection should fail for compressed formats */
1365 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1367 return (HBITMAP
)NULL
;
1370 pdcattr
= dc
->pdcattr
;
1372 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1374 bm
.bmWidth
= bi
->biWidth
;
1375 bm
.bmHeight
= effHeight
;
1376 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1378 bm
.bmPlanes
= bi
->biPlanes
;
1379 bm
.bmBitsPixel
= bi
->biBitCount
;
1382 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1383 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1384 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1385 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1389 SYSTEM_BASIC_INFORMATION Sbi
;
1392 LARGE_INTEGER SectionOffset
;
1395 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1399 if (!NT_SUCCESS(Status
))
1404 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1405 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1407 SectionOffset
.LowPart
= mapOffset
;
1408 SectionOffset
.HighPart
= 0;
1410 Status
= ZwMapViewOfSection(section
,
1420 if (!NT_SUCCESS(Status
))
1422 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1426 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1428 else if (ovr_pitch
&& offset
)
1429 bm
.bmBits
= (LPVOID
) offset
;
1433 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1436 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1437 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1439 if (usage
== DIB_PAL_COLORS
)
1440 lpRGB
= DIB_MapPaletteColors(dc
, bmi
);
1442 lpRGB
= bmi
->bmiColors
;
1444 /* Set dsBitfields values */
1445 if (usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1447 dsBitfields
[0] = dsBitfields
[1] = dsBitfields
[2] = 0;
1449 else if (bi
->biCompression
== BI_RGB
)
1451 switch (bi
->biBitCount
)
1455 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0x7c00;
1456 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x03e0;
1457 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x001f;
1462 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0xff0000;
1463 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x00ff00;
1464 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x0000ff;
1470 dsBitfields
[0] = ((DWORD
*)bmi
->bmiColors
)[0];
1471 dsBitfields
[1] = ((DWORD
*)bmi
->bmiColors
)[1];
1472 dsBitfields
[2] = ((DWORD
*)bmi
->bmiColors
)[2];
1475 // Create Device Dependent Bitmap and add DIB pointer
1476 Size
.cx
= bm
.bmWidth
;
1477 Size
.cy
= abs(bm
.bmHeight
);
1478 res
= IntCreateBitmap(Size
,
1480 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1481 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1482 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1486 if (lpRGB
!= bmi
->bmiColors
)
1488 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1490 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1493 bmp
= SURFACE_LockSurface(res
);
1496 if (lpRGB
!= bmi
->bmiColors
)
1498 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1500 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1501 GreDeleteObject(bmp
);
1505 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1506 table between the DIB and the X physical device. Obviously,
1507 this is left out of the ReactOS implementation. Instead,
1508 we call NtGdiSetDIBColorTable. */
1510 /* set number of entries in bmi.bmiColors table */
1511 if (bi
->biBitCount
== 1) {
1514 if (bi
->biBitCount
== 4) {
1517 if (bi
->biBitCount
== 8) {
1518 bi
->biClrUsed
= 256;
1521 bmp
->hDIBSection
= section
;
1522 bmp
->hSecure
= hSecure
;
1523 bmp
->dwOffset
= offset
;
1524 bmp
->flFlags
= BITMAPOBJ_IS_APIBITMAP
;
1525 bmp
->dsBitfields
[0] = dsBitfields
[0];
1526 bmp
->dsBitfields
[1] = dsBitfields
[1];
1527 bmp
->dsBitfields
[2] = dsBitfields
[2];
1528 bmp
->biClrUsed
= bi
->biClrUsed
;
1529 bmp
->biClrImportant
= bi
->biClrImportant
;
1531 if (bi
->biClrUsed
!= 0)
1532 bmp
->hDIBPalette
= PALETTE_AllocPaletteIndexedRGB(bi
->biClrUsed
, lpRGB
);
1534 bmp
->hDIBPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1539 // Clean up in case of errors
1540 if (!res
|| !bmp
|| !bm
.bmBits
)
1542 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1545 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1548 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1553 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1561 SURFACE_FreeSurfaceByHandle(res
);
1566 if (lpRGB
!= bmi
->bmiColors
)
1568 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1573 SURFACE_UnlockSurface(bmp
);
1576 // Return BITMAP handle and storage location
1577 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1582 if (res
) pdcattr
->ulDirty_
|= DC_DIBSECTION
;
1587 /***********************************************************************
1588 * DIB_GetDIBWidthBytes
1590 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1591 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1592 * 11/16/1999 (RJJ) lifted from wine
1594 INT FASTCALL
DIB_GetDIBWidthBytes(INT width
, INT depth
)
1596 return ((width
* depth
+ 31) & ~31) >> 3;
1599 /***********************************************************************
1600 * DIB_GetDIBImageBytes
1602 * Return the number of bytes used to hold the image in a DIB bitmap.
1603 * 11/16/1999 (RJJ) lifted from wine
1606 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1608 return DIB_GetDIBWidthBytes(width
, depth
) * (height
< 0 ? -height
: height
);
1611 /***********************************************************************
1612 * DIB_BitmapInfoSize
1614 * Return the size of the bitmap info structure including color table.
1615 * 11/16/1999 (RJJ) lifted from wine
1618 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1622 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1624 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1625 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1626 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1628 else /* assume BITMAPINFOHEADER */
1630 colors
= info
->bmiHeader
.biClrUsed
;
1631 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1632 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1638 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1645 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1652 if (palGDI
->Mode
!= PAL_INDEXED
)
1654 PALETTE_UnlockPalette(palGDI
);
1658 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1659 if (lpbmi
->bmiHeader
.biClrUsed
)
1661 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1664 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1667 PALETTE_UnlockPalette(palGDI
);
1671 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1673 for (i
= 0; i
< nNumColors
; i
++)
1675 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1676 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1677 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1678 lpRGB
[i
].rgbReserved
= 0;
1681 PALETTE_UnlockPalette(palGDI
);
1688 BuildDIBPalette(CONST BITMAPINFO
*bmi
, PINT paletteType
)
1692 PALETTEENTRY
*palEntries
= NULL
;
1694 ULONG RedMask
, GreenMask
, BlueMask
;
1696 // Determine Bits Per Pixel
1697 bits
= bmi
->bmiHeader
.biBitCount
;
1699 // Determine paletteType from Bits Per Pixel
1702 *paletteType
= PAL_INDEXED
;
1703 RedMask
= GreenMask
= BlueMask
= 0;
1705 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1707 *paletteType
= PAL_BITFIELDS
;
1708 RedMask
= ((ULONG
*)bmi
->bmiColors
)[0];
1709 GreenMask
= ((ULONG
*)bmi
->bmiColors
)[1];
1710 BlueMask
= ((ULONG
*)bmi
->bmiColors
)[2];
1714 *paletteType
= PAL_BITFIELDS
;
1721 *paletteType
= PAL_BGR
;
1723 GreenMask
= 0x00ff00;
1724 BlueMask
= 0x0000ff;
1727 if (bmi
->bmiHeader
.biClrUsed
== 0)
1729 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1733 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1736 if (PAL_INDEXED
== *paletteType
)
1738 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)bmi
->bmiColors
);
1742 hPal
= PALETTE_AllocPalette(*paletteType
, ColorCount
,
1743 (ULONG
*) palEntries
,
1744 RedMask
, GreenMask
, BlueMask
);