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 RGBQUAD DefLogPaletteQuads
[20] = { /* Copy of Default Logical Palette */
46 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
47 { 0x00, 0x00, 0x00, 0x00 },
48 { 0x00, 0x00, 0x80, 0x00 },
49 { 0x00, 0x80, 0x00, 0x00 },
50 { 0x00, 0x80, 0x80, 0x00 },
51 { 0x80, 0x00, 0x00, 0x00 },
52 { 0x80, 0x00, 0x80, 0x00 },
53 { 0x80, 0x80, 0x00, 0x00 },
54 { 0xc0, 0xc0, 0xc0, 0x00 },
55 { 0xc0, 0xdc, 0xc0, 0x00 },
56 { 0xf0, 0xca, 0xa6, 0x00 },
57 { 0xf0, 0xfb, 0xff, 0x00 },
58 { 0xa4, 0xa0, 0xa0, 0x00 },
59 { 0x80, 0x80, 0x80, 0x00 },
60 { 0x00, 0x00, 0xf0, 0x00 },
61 { 0x00, 0xff, 0x00, 0x00 },
62 { 0x00, 0xff, 0xff, 0x00 },
63 { 0xff, 0x00, 0x00, 0x00 },
64 { 0xff, 0x00, 0xff, 0x00 },
65 { 0xff, 0xff, 0x00, 0x00 },
66 { 0xff, 0xff, 0xff, 0x00 }
76 CONST RGBQUAD
*Colors
)
84 if (!(dc
= DC_LockDc(hDC
))) return 0;
85 if (dc
->dctype
== DC_TYPE_INFO
)
91 psurf
= dc
->dclevel
.pSurface
;
95 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
99 if (psurf
->hSecure
== NULL
)
102 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
106 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
107 if (biBitCount
<= 8 && StartIndex
< (1 << biBitCount
))
109 if (StartIndex
+ Entries
> (1 << biBitCount
))
110 Entries
= (1 << biBitCount
) - StartIndex
;
112 if (psurf
->ppal
== NULL
)
115 SetLastWin32Error(ERROR_INVALID_HANDLE
);
119 PalGDI
= PALETTE_LockPalette(psurf
->ppal
->BaseObject
.hHmgr
);
121 for (Index
= StartIndex
;
122 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
125 PalGDI
->IndexedColors
[Index
].peRed
= Colors
[Index
- StartIndex
].rgbRed
;
126 PalGDI
->IndexedColors
[Index
].peGreen
= Colors
[Index
- StartIndex
].rgbGreen
;
127 PalGDI
->IndexedColors
[Index
].peBlue
= Colors
[Index
- StartIndex
].rgbBlue
;
129 PALETTE_UnlockPalette(PalGDI
);
134 /* Mark the brushes invalid */
135 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
|DIRTY_LINE
|DIRTY_BACKGROUND
|DIRTY_TEXT
;
153 UINT Index
, Count
= 0;
156 if (!(dc
= DC_LockDc(hDC
))) return 0;
157 if (dc
->dctype
== DC_TYPE_INFO
)
163 psurf
= dc
->dclevel
.pSurface
;
167 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
171 if (psurf
->hSecure
== NULL
)
174 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
178 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
179 if (biBitCount
<= 8 &&
180 StartIndex
< (1 << biBitCount
))
182 if (StartIndex
+ Entries
> (1 << biBitCount
))
183 Entries
= (1 << biBitCount
) - StartIndex
;
185 if (psurf
->ppal
== NULL
)
188 SetLastWin32Error(ERROR_INVALID_HANDLE
);
192 PalGDI
= PALETTE_LockPalette(psurf
->ppal
->BaseObject
.hHmgr
);
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;
204 PALETTE_UnlockPalette(PalGDI
);
212 // Converts a DIB to a device-dependent bitmap
221 CONST BITMAPINFO
*bmi
,
225 HBITMAP SourceBitmap
;
228 SURFOBJ
*DestSurf
, *SourceSurf
;
233 PPALETTE ppalDDB
, ppalDIB
;
235 HPALETTE DIB_Palette
;
236 ULONG DIB_Palette_Type
;
240 if (!(bitmap
= SURFACE_LockSurface(hBitmap
)))
246 //if (ColorUse == DIB_PAL_COLORS)
247 // lpRGB = DIB_MapPaletteColors(hDC, bmi);
249 // lpRGB = &bmi->bmiColors;
251 DestSurf
= &bitmap
->SurfObj
;
253 // Create source surface
254 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
255 SourceSize
.cy
= ScanLines
;
257 // Determine width of DIB
258 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
260 SourceBitmap
= EngCreateBitmap(SourceSize
,
262 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
263 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
265 if (0 == SourceBitmap
)
267 SURFACE_UnlockSurface(bitmap
);
268 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
272 SourceSurf
= EngLockSurface((HSURF
)SourceBitmap
);
273 if (NULL
== SourceSurf
)
275 EngDeleteSurface((HSURF
)SourceBitmap
);
276 SURFACE_UnlockSurface(bitmap
);
277 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
283 ppalDDB
= bitmap
->ppal
;
284 GDIOBJ_IncrementShareCount(&ppalDDB
->BaseObject
);
287 // Destination palette obtained from the hDC
288 ppalDDB
= PALETTE_ShareLockPalette(DC
->ppdev
->devinfo
.hpalDefault
);
292 EngUnlockSurface(SourceSurf
);
293 EngDeleteSurface((HSURF
)SourceBitmap
);
294 SURFACE_UnlockSurface(bitmap
);
295 SetLastWin32Error(ERROR_INVALID_HANDLE
);
299 // Source palette obtained from the BITMAPINFO
300 DIB_Palette
= BuildDIBPalette((PBITMAPINFO
)bmi
, (PINT
)&DIB_Palette_Type
);
301 if (NULL
== DIB_Palette
)
303 EngUnlockSurface(SourceSurf
);
304 EngDeleteSurface((HSURF
)SourceBitmap
);
305 SURFACE_UnlockSurface(bitmap
);
306 PALETTE_ShareUnlockPalette(ppalDDB
);
307 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
311 ppalDIB
= PALETTE_LockPalette(DIB_Palette
);
313 /* Initialize XLATEOBJ for color translation */
314 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
320 // Determine destination rectangle
322 DestRect
.top
= abs(bmi
->bmiHeader
.biHeight
) - StartScan
- ScanLines
;
323 DestRect
.right
= SourceSize
.cx
;
324 DestRect
.bottom
= DestRect
.top
+ ScanLines
;
326 copyBitsResult
= IntEngCopyBits(DestSurf
, SourceSurf
, NULL
, &exlo
.xlo
, &DestRect
, &ZeroPoint
);
328 // If it succeeded, return number of scanlines copies
329 if (copyBitsResult
== TRUE
)
331 result
= SourceSize
.cy
;
333 // result = abs(bmi->bmiHeader.biHeight) - StartScan;
337 EXLATEOBJ_vCleanup(&exlo
);
338 PALETTE_UnlockPalette(ppalDIB
);
339 PALETTE_ShareUnlockPalette(ppalDDB
);
340 PALETTE_FreePaletteByHandle(DIB_Palette
);
341 EngUnlockSurface(SourceSurf
);
342 EngDeleteSurface((HSURF
)SourceBitmap
);
344 // if (ColorUse == DIB_PAL_COLORS)
345 // WinFree((LPSTR)lpRGB);
347 SURFACE_UnlockSurface(bitmap
);
352 // FIXME by Removing NtGdiSetDIBits!!!
353 // This is a victim of the Win32k Initialization BUG!!!!!
354 // Converts a DIB to a device-dependent bitmap
363 CONST BITMAPINFO
*bmi
,
368 NTSTATUS Status
= STATUS_SUCCESS
;
374 { // FYI: We converted from CORE in gdi.
375 ProbeForRead(bmi
, sizeof(BITMAPINFO
), 1);
376 cjBits
= bmi
->bmiHeader
.biBitCount
* bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biWidth
;
377 cjBits
= ((cjBits
+ 31) & ~31) / 8;
379 ProbeForRead(Bits
, cjBits
, 1);
381 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
383 Status
= _SEH2_GetExceptionCode();
387 if (!NT_SUCCESS(Status
))
395 SetLastWin32Error(ERROR_INVALID_HANDLE
);
398 if (Dc
->dctype
== DC_TYPE_INFO
)
404 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
414 NtGdiSetDIBitsToDeviceInternal(
429 IN BOOL bTransformCoordinates
,
430 IN OPTIONAL HANDLE hcmXform
)
433 NTSTATUS Status
= STATUS_SUCCESS
;
435 HBITMAP hSourceBitmap
= NULL
;
436 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
443 PPALETTE ppalDDB
= NULL
, ppalDIB
= NULL
;
444 HPALETTE hpalDIB
= NULL
;
445 ULONG DIBPaletteType
;
451 ProbeForRead(bmi
, cjMaxInfo
, 1);
452 ProbeForRead(Bits
, cjMaxBits
, 1);
454 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
456 Status
= _SEH2_GetExceptionCode();
460 if (!NT_SUCCESS(Status
))
465 pDC
= DC_LockDc(hDC
);
468 SetLastWin32Error(ERROR_INVALID_HANDLE
);
471 if (pDC
->dctype
== DC_TYPE_INFO
)
477 pSurf
= pDC
->dclevel
.pSurface
;
479 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
481 ScanLines
= min(ScanLines
, abs(bmi
->bmiHeader
.biHeight
) - StartScan
);
485 if (bTransformCoordinates
)
487 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
489 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
490 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
491 rcDest
.right
= rcDest
.left
+ Width
;
492 rcDest
.bottom
= rcDest
.top
+ Height
;
493 rcDest
.top
+= StartScan
;
498 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
499 SourceSize
.cy
= ScanLines
;
501 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
503 hSourceBitmap
= EngCreateBitmap(SourceSize
,
505 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
506 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
510 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
511 Status
= STATUS_NO_MEMORY
;
515 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
518 Status
= STATUS_UNSUCCESSFUL
;
522 /* Obtain destination palette */
523 if (pSurf
&& pSurf
->ppal
)
525 ppalDDB
= pSurf
->ppal
;
526 GDIOBJ_IncrementShareCount(&ppalDDB
->BaseObject
);
529 ppalDDB
= PALETTE_ShareLockPalette(pDC
->ppdev
->devinfo
.hpalDefault
);
533 SetLastWin32Error(ERROR_INVALID_HANDLE
);
534 Status
= STATUS_UNSUCCESSFUL
;
538 /* Create a palette for the DIB */
539 hpalDIB
= BuildDIBPalette(bmi
, (PINT
)&DIBPaletteType
);
542 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
543 Status
= STATUS_NO_MEMORY
;
547 /* Lock the DIB palette */
548 ppalDIB
= PALETTE_LockPalette(hpalDIB
);
551 SetLastWin32Error(ERROR_INVALID_HANDLE
);
552 Status
= STATUS_UNSUCCESSFUL
;
556 /* Initialize EXLATEOBJ */
557 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
560 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
561 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
562 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
563 Status
= IntEngBitBlt(pDestSurf
,
566 pDC
->rosdc
.CombinedClip
,
573 ROP3_TO_ROP4(SRCCOPY
));
575 /* Cleanup EXLATEOBJ */
576 EXLATEOBJ_vCleanup(&exlo
);
579 if (NT_SUCCESS(Status
))
584 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
585 if (ppalDDB
) PALETTE_ShareUnlockPalette(ppalDDB
);
587 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
588 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
589 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
596 /* Converts a device-dependent bitmap to a DIB */
599 NtGdiGetDIBitsInternal(
611 SURFACE
*psurf
= NULL
;
612 HBITMAP hDestBitmap
= NULL
;
613 HPALETTE hDestPalette
= NULL
;
614 PPALETTE ppalSrc
= NULL
;
615 PPALETTE ppalDst
= NULL
;
616 NTSTATUS Status
= STATUS_SUCCESS
;
618 BOOL bPaletteMatch
= FALSE
;
619 PBYTE ChkBits
= Bits
;
622 ULONG DestPaletteType
;
625 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
627 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
630 // if ScanLines == 0, no need to copy Bits.
636 ProbeForRead(&Info
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
638 ProbeForWrite(Info
, Info
->bmiHeader
.biSize
, 1); // Comp for Core.
639 if (ChkBits
) ProbeForWrite(ChkBits
, MaxBits
, 1);
641 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
643 Status
= _SEH2_GetExceptionCode();
647 if (!NT_SUCCESS(Status
))
653 if (Dc
== NULL
) return 0;
654 if (Dc
->dctype
== DC_TYPE_INFO
)
660 /* Get a pointer to the source bitmap object */
661 psurf
= SURFACE_LockSurface(hBitmap
);
670 ppalSrc
= psurf
->ppal
;
671 GDIOBJ_IncrementShareCount(&ppalSrc
->BaseObject
);
674 ppalSrc
= PALETTE_ShareLockPalette(Dc
->ppdev
->devinfo
.hpalDefault
);
678 ASSERT(ppalSrc
!= NULL
);
680 ColorPtr
= ((PBYTE
)Info
+ Info
->bmiHeader
.biSize
);
681 rgbQuads
= (RGBQUAD
*)ColorPtr
;
683 /* Copy palette information
684 * Always create a palette for 15 & 16 bit. */
685 if ((Info
->bmiHeader
.biBitCount
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) &&
686 Info
->bmiHeader
.biBitCount
!= 15 && Info
->bmiHeader
.biBitCount
!= 16) ||
690 bPaletteMatch
= TRUE
;
693 hDestPalette
= BuildDIBPalette(Info
, (PINT
)&DestPaletteType
); //hDestPalette = Dc->DevInfo->hpalDefault;
697 ppalDst
= PALETTE_LockPalette(hDestPalette
);
698 /* FIXME - ppalDst can be NULL!!!! Don't assert here!!! */
699 DPRINT("ppalDst : %p\n", ppalDst
);
704 /* FIXME: This is largely incomplete. ATM no Core!*/
705 switch (Info
->bmiHeader
.biBitCount
)
710 Info
->bmiHeader
.biClrUsed
= 0;
711 if (psurf
->hSecure
&&
712 BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == Info
->bmiHeader
.biBitCount
)
714 if (Usage
== DIB_RGB_COLORS
)
716 if (ppalDst
->NumColors
!= 1 << Info
->bmiHeader
.biBitCount
)
717 Info
->bmiHeader
.biClrUsed
= ppalDst
->NumColors
;
719 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
722 rgbQuads
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
723 rgbQuads
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
724 rgbQuads
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
725 rgbQuads
[Index
].rgbReserved
= 0;
730 PWORD Ptr
= ColorPtr
;
732 Index
< (1 << Info
->bmiHeader
.biBitCount
);
735 Ptr
[Index
] = (WORD
)Index
;
741 if (Usage
== DIB_PAL_COLORS
)
743 PWORD Ptr
= ColorPtr
;
745 Index
< (1 << Info
->bmiHeader
.biBitCount
);
748 Ptr
[Index
] = (WORD
)Index
;
751 else if (Info
->bmiHeader
.biBitCount
> 1 && bPaletteMatch
)
754 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
757 Info
->bmiColors
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
758 Info
->bmiColors
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
759 Info
->bmiColors
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
760 Info
->bmiColors
[Index
].rgbReserved
= 0;
765 switch (Info
->bmiHeader
.biBitCount
)
768 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
= rgbQuads
[0].rgbBlue
= 0;
769 rgbQuads
[0].rgbReserved
= 0;
770 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
= rgbQuads
[1].rgbBlue
= 0xff;
771 rgbQuads
[1].rgbReserved
= 0;
774 RtlCopyMemory(ColorPtr
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
781 RtlCopyMemory(rgbQuads
, DefLogPaletteQuads
, 10 * sizeof(RGBQUAD
));
782 RtlCopyMemory(rgbQuads
+ 246, DefLogPaletteQuads
+ 10, 10 * sizeof(RGBQUAD
));
783 color
= rgbQuads
+ 10;
784 for (r
= 0; r
<= 5; r
++) /* FIXME */
785 for (g
= 0; g
<= 5; g
++)
786 for (b
= 0; b
<= 5; b
++)
788 color
->rgbRed
= (r
* 0xff) / 5;
789 color
->rgbGreen
= (g
* 0xff) / 5;
790 color
->rgbBlue
= (b
* 0xff) / 5;
791 color
->rgbReserved
= 0;
801 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
803 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
804 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
805 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
810 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
812 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
813 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
814 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
820 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
822 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
823 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
824 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
830 PALETTE_UnlockPalette(ppalDst
);
832 /* fill out the BITMAPINFO struct */
834 { // Core or not to Core? We have converted from Core in Gdi~ so?
835 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
837 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
838 coreheader
->bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
839 coreheader
->bcPlanes
= 1;
840 coreheader
->bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
841 coreheader
->bcHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
842 if (psurf
->SurfObj
.lDelta
> 0)
843 coreheader
->bcHeight
= -coreheader
->bcHeight
;
846 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
848 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
849 Info
->bmiHeader
.biHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
850 Info
->bmiHeader
.biPlanes
= 1;
851 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
852 switch (psurf
->SurfObj
.iBitmapFormat
)
854 /* FIXME: What about BI_BITFIELDS? */
861 Info
->bmiHeader
.biCompression
= BI_RGB
;
864 Info
->bmiHeader
.biCompression
= BI_RLE4
;
867 Info
->bmiHeader
.biCompression
= BI_RLE8
;
870 Info
->bmiHeader
.biCompression
= BI_JPEG
;
873 Info
->bmiHeader
.biCompression
= BI_PNG
;
876 /* Image size has to be calculated */
877 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(Info
->bmiHeader
.biWidth
,
878 Info
->bmiHeader
.biBitCount
) * Info
->bmiHeader
.biHeight
;
879 Info
->bmiHeader
.biXPelsPerMeter
= 0; /* FIXME */
880 Info
->bmiHeader
.biYPelsPerMeter
= 0; /* FIXME */
881 Info
->bmiHeader
.biClrUsed
= 0;
882 Info
->bmiHeader
.biClrImportant
= 1 << Info
->bmiHeader
.biBitCount
; /* FIXME */
883 /* Report negtive height for top-down bitmaps. */
884 if (psurf
->SurfObj
.lDelta
> 0)
885 Info
->bmiHeader
.biHeight
= -Info
->bmiHeader
.biHeight
;
887 Result
= psurf
->SurfObj
.sizlBitmap
.cy
;
895 // If we have a good dib pointer, why not just copy bits from there w/o XLATE'ing them.
897 /* Create the destination bitmap too for the copy operation */
898 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
904 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
905 DestSize
.cx
= psurf
->SurfObj
.sizlBitmap
.cx
;
906 DestSize
.cy
= ScanLines
;
910 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
912 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
913 hDestBitmap
= EngCreateBitmap(DestSize
,
914 DIB_GetDIBWidthBytes(DestSize
.cx
, coreheader
->bcBitCount
),
915 BitmapFormat(coreheader
->bcBitCount
, BI_RGB
),
916 0 < coreheader
->bcHeight
? 0 : BMF_TOPDOWN
,
920 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
922 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(DestSize
.cx
,
923 Info
->bmiHeader
.biBitCount
) * DestSize
.cy
;
925 hDestBitmap
= EngCreateBitmap(DestSize
,
926 DIB_GetDIBWidthBytes(DestSize
.cx
, Info
->bmiHeader
.biBitCount
),
927 BitmapFormat(Info
->bmiHeader
.biBitCount
, Info
->bmiHeader
.biCompression
),
928 0 < Info
->bmiHeader
.biHeight
? 0 : BMF_TOPDOWN
,
932 if (hDestBitmap
== NULL
)
936 if (NT_SUCCESS(Status
))
939 SURFOBJ
*DestSurfObj
;
942 EXLATEOBJ_vInitialize(&exlo
, ppalSrc
, ppalDst
, 0, 0, 0);
945 SourcePoint
.y
= psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
);
947 /* Determine destination rectangle */
950 DestRect
.right
= DestSize
.cx
;
951 DestRect
.bottom
= DestSize
.cy
;
953 DestSurfObj
= EngLockSurface((HSURF
)hDestBitmap
);
955 if (IntEngCopyBits(DestSurfObj
,
962 DPRINT("GetDIBits %d \n",abs(Info
->bmiHeader
.biHeight
) - StartScan
);
966 EXLATEOBJ_vCleanup(&exlo
);
967 EngUnlockSurface(DestSurfObj
);
971 PALETTE_ShareUnlockPalette(ppalSrc
);
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
= Dc
->ppdev
->gdiinfo
.cBitsPixel
;
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
;
1351 // Fill BITMAP32 structure with DIB data
1352 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1359 DWORD dsBitfields
[3] = {0};
1362 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1363 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1364 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1366 /* CreateDIBSection should fail for compressed formats */
1367 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1369 return (HBITMAP
)NULL
;
1372 pdcattr
= dc
->pdcattr
;
1374 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1376 bm
.bmWidth
= bi
->biWidth
;
1377 bm
.bmHeight
= effHeight
;
1378 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1380 bm
.bmPlanes
= bi
->biPlanes
;
1381 bm
.bmBitsPixel
= bi
->biBitCount
;
1384 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1385 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1386 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1387 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1391 SYSTEM_BASIC_INFORMATION Sbi
;
1394 LARGE_INTEGER SectionOffset
;
1397 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1401 if (!NT_SUCCESS(Status
))
1406 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1407 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1409 SectionOffset
.LowPart
= mapOffset
;
1410 SectionOffset
.HighPart
= 0;
1412 Status
= ZwMapViewOfSection(section
,
1422 if (!NT_SUCCESS(Status
))
1424 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1428 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1430 else if (ovr_pitch
&& offset
)
1431 bm
.bmBits
= (LPVOID
) offset
;
1435 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1438 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1439 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1441 if (usage
== DIB_PAL_COLORS
)
1443 lpRGB
= DIB_MapPaletteColors(dc
, bmi
);
1444 ColorCount
= bi
->biClrUsed
;
1445 if (ColorCount
== 0)
1447 ColorCount
= 1 << bi
->biBitCount
;
1452 lpRGB
= bmi
->bmiColors
;
1453 ColorCount
= 1 << bi
->biBitCount
;
1456 /* Set dsBitfields values */
1457 if (usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1459 dsBitfields
[0] = dsBitfields
[1] = dsBitfields
[2] = 0;
1461 else if (bi
->biCompression
== BI_RGB
)
1463 switch (bi
->biBitCount
)
1466 dsBitfields
[0] = 0x7c00;
1467 dsBitfields
[1] = 0x03e0;
1468 dsBitfields
[2] = 0x001f;
1472 dsBitfields
[0] = 0xF800;
1473 dsBitfields
[1] = 0x07e0;
1474 dsBitfields
[2] = 0x001f;
1479 dsBitfields
[0] = 0xff0000;
1480 dsBitfields
[1] = 0x00ff00;
1481 dsBitfields
[2] = 0x0000ff;
1487 dsBitfields
[0] = ((DWORD
*)bmi
->bmiColors
)[0];
1488 dsBitfields
[1] = ((DWORD
*)bmi
->bmiColors
)[1];
1489 dsBitfields
[2] = ((DWORD
*)bmi
->bmiColors
)[2];
1492 // Create Device Dependent Bitmap and add DIB pointer
1493 Size
.cx
= bm
.bmWidth
;
1494 Size
.cy
= abs(bm
.bmHeight
);
1495 res
= IntCreateBitmap(Size
,
1497 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1498 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1499 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1503 if (lpRGB
!= bmi
->bmiColors
)
1505 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1507 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1510 bmp
= SURFACE_LockSurface(res
);
1513 if (lpRGB
!= bmi
->bmiColors
)
1515 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1517 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1518 GreDeleteObject(res
);
1522 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1523 table between the DIB and the X physical device. Obviously,
1524 this is left out of the ReactOS implementation. Instead,
1525 we call NtGdiSetDIBColorTable. */
1526 if (bi
->biBitCount
<= 8)
1528 bi
->biClrUsed
= 1 << bi
->biBitCount
;
1535 bmp
->hDIBSection
= section
;
1536 bmp
->hSecure
= hSecure
;
1537 bmp
->dwOffset
= offset
;
1538 bmp
->flags
= API_BITMAP
;
1539 bmp
->dsBitfields
[0] = dsBitfields
[0];
1540 bmp
->dsBitfields
[1] = dsBitfields
[1];
1541 bmp
->dsBitfields
[2] = dsBitfields
[2];
1542 bmp
->biClrUsed
= bi
->biClrUsed
;
1543 bmp
->biClrImportant
= bi
->biClrImportant
;
1545 if (bi
->biClrUsed
!= 0)
1547 hpal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, lpRGB
);
1551 hpal
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1557 bmp
->ppal
= PALETTE_ShareLockPalette(hpal
);
1558 /* Lazy delete hpal, it will be freed at surface release */
1559 GreDeleteObject(hpal
);
1561 // Clean up in case of errors
1562 if (!res
|| !bmp
|| !bm
.bmBits
)
1564 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1567 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1570 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1575 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1583 SURFACE_FreeSurfaceByHandle(res
);
1588 if (lpRGB
!= bmi
->bmiColors
)
1590 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1595 SURFACE_UnlockSurface(bmp
);
1598 // Return BITMAP handle and storage location
1599 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1604 if (res
) pdcattr
->ulDirty_
|= DC_DIBSECTION
;
1609 /***********************************************************************
1610 * DIB_GetDIBWidthBytes
1612 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1613 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1614 * 11/16/1999 (RJJ) lifted from wine
1616 INT FASTCALL
DIB_GetDIBWidthBytes(INT width
, INT depth
)
1618 return ((width
* depth
+ 31) & ~31) >> 3;
1621 /***********************************************************************
1622 * DIB_GetDIBImageBytes
1624 * Return the number of bytes used to hold the image in a DIB bitmap.
1625 * 11/16/1999 (RJJ) lifted from wine
1628 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1630 return DIB_GetDIBWidthBytes(width
, depth
) * (height
< 0 ? -height
: height
);
1633 /***********************************************************************
1634 * DIB_BitmapInfoSize
1636 * Return the size of the bitmap info structure including color table.
1637 * 11/16/1999 (RJJ) lifted from wine
1640 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1644 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1646 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1647 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1648 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1650 else /* assume BITMAPINFOHEADER */
1652 colors
= info
->bmiHeader
.biClrUsed
;
1653 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1654 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1660 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1667 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1674 if (palGDI
->Mode
!= PAL_INDEXED
)
1676 PALETTE_UnlockPalette(palGDI
);
1680 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1681 if (lpbmi
->bmiHeader
.biClrUsed
)
1683 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1686 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1689 PALETTE_UnlockPalette(palGDI
);
1693 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1695 for (i
= 0; i
< nNumColors
; i
++)
1697 if (*lpIndex
< palGDI
->NumColors
)
1699 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1700 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1701 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1705 lpRGB
[i
].rgbRed
= 0;
1706 lpRGB
[i
].rgbGreen
= 0;
1707 lpRGB
[i
].rgbBlue
= 0;
1709 lpRGB
[i
].rgbReserved
= 0;
1712 PALETTE_UnlockPalette(palGDI
);
1719 BuildDIBPalette(CONST BITMAPINFO
*bmi
, PINT paletteType
)
1723 PALETTEENTRY
*palEntries
= NULL
;
1725 ULONG RedMask
, GreenMask
, BlueMask
;
1727 // Determine Bits Per Pixel
1728 bits
= bmi
->bmiHeader
.biBitCount
;
1730 // Determine paletteType from Bits Per Pixel
1733 *paletteType
= PAL_INDEXED
;
1734 RedMask
= GreenMask
= BlueMask
= 0;
1736 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1738 *paletteType
= PAL_BITFIELDS
;
1739 RedMask
= ((ULONG
*)bmi
->bmiColors
)[0];
1740 GreenMask
= ((ULONG
*)bmi
->bmiColors
)[1];
1741 BlueMask
= ((ULONG
*)bmi
->bmiColors
)[2];
1743 else if (bits
== 15)
1745 *paletteType
= PAL_BITFIELDS
;
1750 else if (bits
== 16)
1752 *paletteType
= PAL_BITFIELDS
;
1759 *paletteType
= PAL_BGR
;
1761 GreenMask
= 0x00ff00;
1762 BlueMask
= 0x0000ff;
1765 if (bmi
->bmiHeader
.biClrUsed
== 0)
1767 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1771 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1774 if (PAL_INDEXED
== *paletteType
)
1776 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)bmi
->bmiColors
);
1780 hPal
= PALETTE_AllocPalette(*paletteType
, ColorCount
,
1781 (ULONG
*) palEntries
,
1782 RedMask
, GreenMask
, BlueMask
);