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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
;
234 PPALETTE ppalDDB
, ppalDIB
;
236 HPALETTE DDB_Palette
, DIB_Palette
;
237 ULONG 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 ppalDDB
= PALETTE_LockPalette(DDB_Palette
);
296 EngUnlockSurface(SourceSurf
);
297 EngDeleteSurface((HSURF
)SourceBitmap
);
298 SURFACE_UnlockSurface(bitmap
);
299 SetLastWin32Error(ERROR_INVALID_HANDLE
);
303 // Source palette obtained from the BITMAPINFO
304 DIB_Palette
= BuildDIBPalette((PBITMAPINFO
)bmi
, (PINT
)&DIB_Palette_Type
);
305 if (NULL
== DIB_Palette
)
307 EngUnlockSurface(SourceSurf
);
308 EngDeleteSurface((HSURF
)SourceBitmap
);
309 SURFACE_UnlockSurface(bitmap
);
310 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
314 ppalDIB
= PALETTE_LockPalette(DIB_Palette
);
316 /* Initialize XLATEOBJ for color translation */
317 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
323 // Determine destination rectangle
325 DestRect
.top
= abs(bmi
->bmiHeader
.biHeight
) - StartScan
- ScanLines
;
326 DestRect
.right
= SourceSize
.cx
;
327 DestRect
.bottom
= DestRect
.top
+ ScanLines
;
329 copyBitsResult
= IntEngCopyBits(DestSurf
, SourceSurf
, NULL
, &exlo
.xlo
, &DestRect
, &ZeroPoint
);
331 // If it succeeded, return number of scanlines copies
332 if (copyBitsResult
== TRUE
)
334 result
= SourceSize
.cy
;
336 // result = abs(bmi->bmiHeader.biHeight) - StartScan;
340 EXLATEOBJ_vCleanup(&exlo
);
341 PALETTE_UnlockPalette(ppalDIB
);
342 PALETTE_UnlockPalette(ppalDDB
);
343 PALETTE_FreePaletteByHandle(DIB_Palette
);
344 EngUnlockSurface(SourceSurf
);
345 EngDeleteSurface((HSURF
)SourceBitmap
);
347 // if (ColorUse == DIB_PAL_COLORS)
348 // WinFree((LPSTR)lpRGB);
350 SURFACE_UnlockSurface(bitmap
);
355 // FIXME by Removing NtGdiSetDIBits!!!
356 // This is a victim of the Win32k Initialization BUG!!!!!
357 // Converts a DIB to a device-dependent bitmap
366 CONST BITMAPINFO
*bmi
,
371 NTSTATUS Status
= STATUS_SUCCESS
;
377 { // FYI: We converted from CORE in gdi.
378 ProbeForRead(bmi
, sizeof(BITMAPINFO
), 1);
379 cjBits
= bmi
->bmiHeader
.biBitCount
* bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biWidth
;
380 cjBits
= ((cjBits
+ 31) & ~31) / 8;
382 ProbeForRead(Bits
, cjBits
, 1);
384 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
386 Status
= _SEH2_GetExceptionCode();
390 if (!NT_SUCCESS(Status
))
398 SetLastWin32Error(ERROR_INVALID_HANDLE
);
401 if (Dc
->dctype
== DC_TYPE_INFO
)
407 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
417 NtGdiSetDIBitsToDeviceInternal(
432 IN BOOL bTransformCoordinates
,
433 IN OPTIONAL HANDLE hcmXform
)
436 NTSTATUS Status
= STATUS_SUCCESS
;
438 HBITMAP hSourceBitmap
= NULL
;
439 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
446 PPALETTE ppalDDB
= NULL
, ppalDIB
= NULL
;
447 HPALETTE hpalDDB
, hpalDIB
= NULL
;
448 ULONG DIBPaletteType
;
454 ProbeForRead(bmi
, cjMaxInfo
, 1);
455 ProbeForRead(Bits
, cjMaxBits
, 1);
457 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
459 Status
= _SEH2_GetExceptionCode();
463 if (!NT_SUCCESS(Status
))
468 pDC
= DC_LockDc(hDC
);
471 SetLastWin32Error(ERROR_INVALID_HANDLE
);
474 if (pDC
->dctype
== DC_TYPE_INFO
)
480 /* Use destination palette obtained from the DC by default */
481 hpalDDB
= pDC
->ppdev
->devinfo
.hpalDefault
;
483 /* Try to use hDIBPalette if it exists */
484 pSurf
= pDC
->dclevel
.pSurface
;
485 if (pSurf
&& pSurf
->hDIBPalette
)
487 hpalDDB
= pSurf
->hDIBPalette
;
490 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
494 if (bTransformCoordinates
)
496 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
498 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
499 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
500 rcDest
.right
= rcDest
.left
+ Width
;
501 rcDest
.bottom
= rcDest
.top
+ Height
;
505 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
506 SourceSize
.cy
= ScanLines
; // this one --> abs(bmi->bmiHeader.biHeight) - StartScan
507 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
509 hSourceBitmap
= EngCreateBitmap(SourceSize
,
511 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
512 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
516 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
517 Status
= STATUS_NO_MEMORY
;
521 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
524 Status
= STATUS_UNSUCCESSFUL
;
528 /* Obtain destination palette */
529 ppalDDB
= PALETTE_LockPalette(hpalDDB
);
532 SetLastWin32Error(ERROR_INVALID_HANDLE
);
533 Status
= STATUS_UNSUCCESSFUL
;
537 /* Create a palette for the DIB */
538 hpalDIB
= BuildDIBPalette(bmi
, (PINT
)&DIBPaletteType
);
541 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
542 Status
= STATUS_NO_MEMORY
;
546 /* Lock the DIB palette */
547 ppalDIB
= PALETTE_LockPalette(hpalDIB
);
550 SetLastWin32Error(ERROR_INVALID_HANDLE
);
551 Status
= STATUS_UNSUCCESSFUL
;
555 /* Initialize EXLATEOBJ */
556 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
559 Status
= IntEngBitBlt(pDestSurf
,
562 pDC
->rosdc
.CombinedClip
,
569 ROP3_TO_ROP4(SRCCOPY
));
571 /* Cleanup EXLATEOBJ */
572 EXLATEOBJ_vCleanup(&exlo
);
575 if (NT_SUCCESS(Status
))
577 /* FIXME: Should probably be only the number of lines actually copied */
578 ret
= ScanLines
; // this one --> abs(Info->bmiHeader.biHeight) - StartScan;
581 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
582 if (ppalDDB
) PALETTE_UnlockPalette(ppalDDB
);
584 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
585 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
586 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
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 ppalSrc
= NULL
;
613 PPALETTE ppalDst
= NULL
;
614 NTSTATUS Status
= STATUS_SUCCESS
;
616 BOOL bPaletteMatch
= FALSE
;
617 PBYTE ChkBits
= Bits
;
620 ULONG DestPaletteType
;
623 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
625 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
628 // if ScanLines == 0, no need to copy Bits.
634 ProbeForRead(&Info
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
636 ProbeForWrite(Info
, Info
->bmiHeader
.biSize
, 1); // Comp for Core.
637 if (ChkBits
) ProbeForWrite(ChkBits
, MaxBits
, 1);
639 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
641 Status
= _SEH2_GetExceptionCode();
645 if (!NT_SUCCESS(Status
))
651 if (Dc
== NULL
) return 0;
652 if (Dc
->dctype
== DC_TYPE_INFO
)
659 /* Get a pointer to the source bitmap object */
660 psurf
= SURFACE_LockSurface(hBitmap
);
664 hSourcePalette
= psurf
->hDIBPalette
;
667 hSourcePalette
= pPrimarySurface
->devinfo
.hpalDefault
;
670 ColorPtr
= ((PBYTE
)Info
+ Info
->bmiHeader
.biSize
);
671 rgbQuads
= (RGBQUAD
*)ColorPtr
;
673 /* Copy palette information
674 * Always create a palette for 15 & 16 bit. */
675 if ((Info
->bmiHeader
.biBitCount
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) &&
676 Info
->bmiHeader
.biBitCount
!= 15 && Info
->bmiHeader
.biBitCount
!= 16) ||
679 hDestPalette
= hSourcePalette
;
680 bPaletteMatch
= TRUE
;
683 hDestPalette
= BuildDIBPalette(Info
, (PINT
)&DestPaletteType
); //hDestPalette = Dc->DevInfo->hpalDefault;
685 ppalSrc
= PALETTE_LockPalette(hSourcePalette
);
686 /* FIXME - ppalSrc can be NULL!!! Don't assert here! */
691 ppalDst
= PALETTE_LockPalette(hDestPalette
);
692 /* FIXME - ppalDst can be NULL!!!! Don't assert here!!! */
693 DPRINT("ppalDst : %p\n", ppalDst
);
702 /* FIXME: This is largely incomplete. ATM no Core!*/
703 switch (Info
->bmiHeader
.biBitCount
)
708 Info
->bmiHeader
.biClrUsed
= 0;
709 if (psurf
->hSecure
&&
710 BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == Info
->bmiHeader
.biBitCount
)
712 if (Usage
== DIB_RGB_COLORS
)
714 if (ppalDst
->NumColors
!= 1 << Info
->bmiHeader
.biBitCount
)
715 Info
->bmiHeader
.biClrUsed
= ppalDst
->NumColors
;
717 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
720 rgbQuads
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
721 rgbQuads
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
722 rgbQuads
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
723 rgbQuads
[Index
].rgbReserved
= 0;
728 PWORD Ptr
= ColorPtr
;
730 Index
< (1 << Info
->bmiHeader
.biBitCount
);
733 Ptr
[Index
] = (WORD
)Index
;
739 if (Usage
== DIB_PAL_COLORS
)
741 PWORD Ptr
= ColorPtr
;
743 Index
< (1 << Info
->bmiHeader
.biBitCount
);
746 Ptr
[Index
] = (WORD
)Index
;
749 else if (Info
->bmiHeader
.biBitCount
> 1 && bPaletteMatch
)
752 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
755 Info
->bmiColors
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
756 Info
->bmiColors
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
757 Info
->bmiColors
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
758 Info
->bmiColors
[Index
].rgbReserved
= 0;
763 switch (Info
->bmiHeader
.biBitCount
)
766 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
= rgbQuads
[0].rgbBlue
= 0;
767 rgbQuads
[0].rgbReserved
= 0;
768 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
= rgbQuads
[1].rgbBlue
= 0xff;
769 rgbQuads
[1].rgbReserved
= 0;
772 RtlCopyMemory(ColorPtr
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
779 RtlCopyMemory(rgbQuads
, DefLogPaletteQuads
, 10 * sizeof(RGBQUAD
));
780 RtlCopyMemory(rgbQuads
+ 246, DefLogPaletteQuads
+ 10, 10 * sizeof(RGBQUAD
));
781 color
= rgbQuads
+ 10;
782 for (r
= 0; r
<= 5; r
++) /* FIXME */
783 for (g
= 0; g
<= 5; g
++)
784 for (b
= 0; b
<= 5; b
++)
786 color
->rgbRed
= (r
* 0xff) / 5;
787 color
->rgbGreen
= (g
* 0xff) / 5;
788 color
->rgbBlue
= (b
* 0xff) / 5;
789 color
->rgbReserved
= 0;
799 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
801 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
802 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
803 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
808 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
810 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
811 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
812 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
818 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
820 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
821 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
822 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
828 PALETTE_UnlockPalette(ppalDst
);
830 /* fill out the BITMAPINFO struct */
832 { // Core or not to Core? We have converted from Core in Gdi~ so?
833 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
835 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
836 coreheader
->bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
837 coreheader
->bcPlanes
= 1;
838 coreheader
->bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
839 coreheader
->bcHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
840 if (psurf
->SurfObj
.lDelta
> 0)
841 coreheader
->bcHeight
= -coreheader
->bcHeight
;
844 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
846 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
847 Info
->bmiHeader
.biHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
848 Info
->bmiHeader
.biPlanes
= 1;
849 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
850 switch (psurf
->SurfObj
.iBitmapFormat
)
852 /* FIXME: What about BI_BITFIELDS? */
859 Info
->bmiHeader
.biCompression
= BI_RGB
;
862 Info
->bmiHeader
.biCompression
= BI_RLE4
;
865 Info
->bmiHeader
.biCompression
= BI_RLE8
;
868 Info
->bmiHeader
.biCompression
= BI_JPEG
;
871 Info
->bmiHeader
.biCompression
= BI_PNG
;
874 /* Image size has to be calculated */
875 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(Info
->bmiHeader
.biWidth
,
876 Info
->bmiHeader
.biBitCount
) * Info
->bmiHeader
.biHeight
;
877 Info
->bmiHeader
.biXPelsPerMeter
= 0; /* FIXME */
878 Info
->bmiHeader
.biYPelsPerMeter
= 0; /* FIXME */
879 Info
->bmiHeader
.biClrUsed
= 0;
880 Info
->bmiHeader
.biClrImportant
= 1 << Info
->bmiHeader
.biBitCount
; /* FIXME */
881 /* Report negtive height for top-down bitmaps. */
882 if (psurf
->SurfObj
.lDelta
> 0)
883 Info
->bmiHeader
.biHeight
= -Info
->bmiHeader
.biHeight
;
885 Result
= psurf
->SurfObj
.sizlBitmap
.cy
;
893 // If we have a good dib pointer, why not just copy bits from there w/o XLATE'ing them.
895 /* Create the destination bitmap too for the copy operation */
896 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
902 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
903 DestSize
.cx
= psurf
->SurfObj
.sizlBitmap
.cx
;
904 DestSize
.cy
= ScanLines
;
908 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
910 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
911 hDestBitmap
= EngCreateBitmap(DestSize
,
912 DIB_GetDIBWidthBytes(DestSize
.cx
, coreheader
->bcBitCount
),
913 BitmapFormat(coreheader
->bcBitCount
, BI_RGB
),
914 0 < coreheader
->bcHeight
? 0 : BMF_TOPDOWN
,
918 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
920 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(DestSize
.cx
,
921 Info
->bmiHeader
.biBitCount
) * DestSize
.cy
;
923 hDestBitmap
= EngCreateBitmap(DestSize
,
924 DIB_GetDIBWidthBytes(DestSize
.cx
, Info
->bmiHeader
.biBitCount
),
925 BitmapFormat(Info
->bmiHeader
.biBitCount
, Info
->bmiHeader
.biCompression
),
926 0 < Info
->bmiHeader
.biHeight
? 0 : BMF_TOPDOWN
,
930 if (hDestBitmap
== NULL
)
934 if (NT_SUCCESS(Status
))
937 SURFOBJ
*DestSurfObj
;
940 EXLATEOBJ_vInitialize(&exlo
, ppalSrc
, ppalDst
, 0, 0, 0);
943 SourcePoint
.y
= psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
);
945 /* Determine destination rectangle */
948 DestRect
.right
= DestSize
.cx
;
949 DestRect
.bottom
= DestSize
.cy
;
951 DestSurfObj
= EngLockSurface((HSURF
)hDestBitmap
);
953 if (IntEngCopyBits(DestSurfObj
,
960 DPRINT("GetDIBits %d \n",abs(Info
->bmiHeader
.biHeight
) - StartScan
);
964 EXLATEOBJ_vCleanup(&exlo
);
965 EngUnlockSurface(DestSurfObj
);
969 PALETTE_UnlockPalette(ppalSrc
);
971 if (hDestBitmap
!= NULL
)
972 EngDeleteSurface((HSURF
)hDestBitmap
);
974 if (hDestPalette
!= NULL
&& bPaletteMatch
== FALSE
)
975 PALETTE_FreePaletteByHandle(hDestPalette
);
977 SURFACE_UnlockSurface(psurf
);
979 DPRINT("leaving NtGdiGetDIBitsInternal\n");
986 NtGdiStretchDIBitsInternal(
997 LPBITMAPINFO BitsInfo
,
1004 HBITMAP hBitmap
, hOldBitmap
= NULL
;
1006 HPALETTE hPal
= NULL
;
1010 if (!Bits
|| !BitsInfo
)
1012 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1018 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1019 ProbeForRead(Bits
, cjMaxBits
, 1);
1021 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1029 DPRINT1("NtGdiStretchDIBitsInternal fail to read BitMapInfo: %x or Bits: %x\n",BitsInfo
,Bits
);
1033 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1036 DPRINT1("NtGdiCreateCompatibleDC fail create hdc\n");
1040 hBitmap
= NtGdiCreateCompatibleBitmap(hDC
,
1041 abs(BitsInfo
->bmiHeader
.biWidth
),
1042 abs(BitsInfo
->bmiHeader
.biHeight
));
1043 if (hBitmap
== NULL
)
1045 DPRINT1("NtGdiCreateCompatibleBitmap fail create bitmap\n");
1046 DPRINT1("hDC : 0x%08x \n", hDC
);
1047 DPRINT1("BitsInfo->bmiHeader.biWidth : 0x%08x \n", BitsInfo
->bmiHeader
.biWidth
);
1048 DPRINT1("BitsInfo->bmiHeader.biHeight : 0x%08x \n", BitsInfo
->bmiHeader
.biHeight
);
1052 /* Select the bitmap into hdcMem, and save a handle to the old bitmap */
1053 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1055 if (Usage
== DIB_PAL_COLORS
)
1057 hPal
= NtGdiGetDCObject(hDC
, GDI_OBJECT_TYPE_PALETTE
);
1058 hPal
= GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1061 if (BitsInfo
->bmiHeader
.biCompression
== BI_RLE4
||
1062 BitsInfo
->bmiHeader
.biCompression
== BI_RLE8
)
1064 /* copy existing bitmap from destination dc */
1065 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1066 NtGdiBitBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1067 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, ROP
, 0, 0);
1069 NtGdiStretchBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1070 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1074 pDC
= DC_LockDc(hdcMem
);
1077 /* Note BitsInfo->bmiHeader.biHeight is the number of scanline,
1078 * if it negitve we getting to many scanline for scanline is UINT not
1079 * a INT, so we need make the negtive value to positve and that make the
1080 * count correct for negtive bitmap, TODO : we need testcase for this api */
1081 IntSetDIBits(pDC
, hBitmap
, 0, abs(BitsInfo
->bmiHeader
.biHeight
), Bits
,
1088 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1089 left (negative biHeight) */
1090 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1091 NtGdiBitBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1092 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1095 NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1096 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1097 SrcWidth
, SrcHeight
, ROP
, 0);
1101 GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1104 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1106 NtGdiDeleteObjectApp(hdcMem
);
1108 GreDeleteObject(hBitmap
);
1129 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1130 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1132 if (bpp
!= 1) fColor
= TRUE
;
1133 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1136 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
1138 const RGBQUAD
*rgb
= data
->bmiColors
;
1139 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1141 // Check if the first color of the colormap is black
1142 if ((col
== RGB(0, 0, 0)))
1145 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1147 // If the second color is white, create a monochrome bitmap
1148 fColor
= (col
!= RGB(0xff,0xff,0xff));
1152 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1154 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
1155 DWORD col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1157 if ((col
== RGB(0,0,0)))
1160 col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1161 fColor
= (col
!= RGB(0xff,0xff,0xff));
1167 DPRINT("(%ld): wrong size for data\n", data
->bmiHeader
.biSize
);
1172 // Now create the bitmap
1175 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1179 handle
= IntGdiCreateBitmap(width
,
1189 if (NULL
!= handle
&& CBM_INIT
== init
)
1191 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1197 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1198 // The DDB that is created will be whatever bit depth your reference DC is
1201 NtGdiCreateDIBitmapInternal(
1206 IN OPTIONAL LPBYTE pjInit
,
1207 IN OPTIONAL LPBITMAPINFO pbmi
,
1209 IN UINT cjMaxInitInfo
,
1218 if (!hDc
) // CreateBitmap
1219 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1220 hDc
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
,FALSE
);
1223 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1227 Dc
= DC_LockDc(hDc
);
1230 NtGdiDeleteObjectApp(hDc
);
1231 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1235 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1238 NtGdiDeleteObjectApp(hDc
);
1240 else // CreateCompatibleBitmap
1242 Dc
= DC_LockDc(hDc
);
1245 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1249 First create an un-initialised bitmap. The depth of the bitmap
1250 should match that of the hdc and not that supplied in bmih.
1253 bpp
= pbmi
->bmiHeader
.biBitCount
;
1256 if (Dc
->dctype
!= DC_TYPE_MEMORY
)
1257 bpp
= IntGdiGetDeviceCaps(Dc
, BITSPIXEL
);
1262 SURFACE
*psurf
= Dc
->dclevel
.pSurface
;
1263 Count
= BITMAP_GetObject(psurf
, sizeof(dibs
), &dibs
);
1268 if (Count
== sizeof(BITMAP
))
1269 /* A device-dependent bitmap is selected in the DC */
1270 bpp
= dibs
.dsBm
.bmBitsPixel
;
1272 /* A DIB section is selected in the DC */
1273 bpp
= dibs
.dsBmih
.biBitCount
;
1277 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1286 NtGdiCreateDIBSection(
1288 IN OPTIONAL HANDLE hSection
,
1290 IN LPBITMAPINFO bmi
,
1294 IN ULONG_PTR dwColorSpace
,
1297 HBITMAP hbitmap
= 0;
1299 BOOL bDesktopDC
= FALSE
;
1301 if (!bmi
) return hbitmap
; // Make sure.
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(
1344 SURFACE
*bmp
= NULL
;
1345 void *mapBits
= NULL
;
1348 // Fill BITMAP32 structure with DIB data
1349 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1356 DWORD dsBitfields
[3] = {0};
1358 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1359 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1360 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1362 /* CreateDIBSection should fail for compressed formats */
1363 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1365 return (HBITMAP
)NULL
;
1368 pdcattr
= dc
->pdcattr
;
1370 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1372 bm
.bmWidth
= bi
->biWidth
;
1373 bm
.bmHeight
= effHeight
;
1374 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1376 bm
.bmPlanes
= bi
->biPlanes
;
1377 bm
.bmBitsPixel
= bi
->biBitCount
;
1380 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1381 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1382 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1383 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1387 SYSTEM_BASIC_INFORMATION Sbi
;
1390 LARGE_INTEGER SectionOffset
;
1393 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1397 if (!NT_SUCCESS(Status
))
1402 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1403 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1405 SectionOffset
.LowPart
= mapOffset
;
1406 SectionOffset
.HighPart
= 0;
1408 Status
= ZwMapViewOfSection(section
,
1418 if (!NT_SUCCESS(Status
))
1420 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1424 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1426 else if (ovr_pitch
&& offset
)
1427 bm
.bmBits
= (LPVOID
) offset
;
1431 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1434 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1435 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1437 if (usage
== DIB_PAL_COLORS
)
1438 lpRGB
= DIB_MapPaletteColors(dc
, bmi
);
1440 lpRGB
= bmi
->bmiColors
;
1442 /* Set dsBitfields values */
1443 if (usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1445 dsBitfields
[0] = dsBitfields
[1] = dsBitfields
[2] = 0;
1447 else if (bi
->biCompression
== BI_RGB
)
1449 switch (bi
->biBitCount
)
1453 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0x7c00;
1454 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x03e0;
1455 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x001f;
1460 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0xff0000;
1461 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x00ff00;
1462 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x0000ff;
1468 dsBitfields
[0] = ((DWORD
*)bmi
->bmiColors
)[0];
1469 dsBitfields
[1] = ((DWORD
*)bmi
->bmiColors
)[1];
1470 dsBitfields
[2] = ((DWORD
*)bmi
->bmiColors
)[2];
1473 // Create Device Dependent Bitmap and add DIB pointer
1474 Size
.cx
= bm
.bmWidth
;
1475 Size
.cy
= abs(bm
.bmHeight
);
1476 res
= IntCreateBitmap(Size
,
1478 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1479 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1480 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1484 if (lpRGB
!= bmi
->bmiColors
)
1486 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1488 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1491 bmp
= SURFACE_LockSurface(res
);
1494 if (lpRGB
!= bmi
->bmiColors
)
1496 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1498 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1499 GreDeleteObject(bmp
);
1503 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1504 table between the DIB and the X physical device. Obviously,
1505 this is left out of the ReactOS implementation. Instead,
1506 we call NtGdiSetDIBColorTable. */
1508 /* set number of entries in bmi.bmiColors table */
1509 if (bi
->biBitCount
== 1) {
1512 if (bi
->biBitCount
== 4) {
1515 if (bi
->biBitCount
== 8) {
1516 bi
->biClrUsed
= 256;
1519 bmp
->hDIBSection
= section
;
1520 bmp
->hSecure
= hSecure
;
1521 bmp
->dwOffset
= offset
;
1522 bmp
->flFlags
= BITMAPOBJ_IS_APIBITMAP
;
1523 bmp
->dsBitfields
[0] = dsBitfields
[0];
1524 bmp
->dsBitfields
[1] = dsBitfields
[1];
1525 bmp
->dsBitfields
[2] = dsBitfields
[2];
1526 bmp
->biClrUsed
= bi
->biClrUsed
;
1527 bmp
->biClrImportant
= bi
->biClrImportant
;
1529 if (bi
->biClrUsed
!= 0)
1530 bmp
->hDIBPalette
= PALETTE_AllocPaletteIndexedRGB(bi
->biClrUsed
, lpRGB
);
1532 bmp
->hDIBPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1537 // Clean up in case of errors
1538 if (!res
|| !bmp
|| !bm
.bmBits
)
1540 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1543 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1546 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1551 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1559 SURFACE_FreeSurfaceByHandle(res
);
1564 if (lpRGB
!= bmi
->bmiColors
)
1566 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1571 SURFACE_UnlockSurface(bmp
);
1574 // Return BITMAP handle and storage location
1575 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1580 if (res
) pdcattr
->ulDirty_
|= DC_DIBSECTION
;
1585 /***********************************************************************
1586 * DIB_GetDIBWidthBytes
1588 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1589 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1590 * 11/16/1999 (RJJ) lifted from wine
1592 INT FASTCALL
DIB_GetDIBWidthBytes(INT width
, INT depth
)
1594 return ((width
* depth
+ 31) & ~31) >> 3;
1597 /***********************************************************************
1598 * DIB_GetDIBImageBytes
1600 * Return the number of bytes used to hold the image in a DIB bitmap.
1601 * 11/16/1999 (RJJ) lifted from wine
1604 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1606 return DIB_GetDIBWidthBytes(width
, depth
) * (height
< 0 ? -height
: height
);
1609 /***********************************************************************
1610 * DIB_BitmapInfoSize
1612 * Return the size of the bitmap info structure including color table.
1613 * 11/16/1999 (RJJ) lifted from wine
1616 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1620 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1622 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1623 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1624 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1626 else /* assume BITMAPINFOHEADER */
1628 colors
= info
->bmiHeader
.biClrUsed
;
1629 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1630 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1636 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1643 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1650 if (palGDI
->Mode
!= PAL_INDEXED
)
1652 PALETTE_UnlockPalette(palGDI
);
1656 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1657 if (lpbmi
->bmiHeader
.biClrUsed
)
1659 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1662 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1665 PALETTE_UnlockPalette(palGDI
);
1669 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1671 for (i
= 0; i
< nNumColors
; i
++)
1673 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1674 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1675 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1676 lpRGB
[i
].rgbReserved
= 0;
1679 PALETTE_UnlockPalette(palGDI
);
1686 BuildDIBPalette(CONST BITMAPINFO
*bmi
, PINT paletteType
)
1690 PALETTEENTRY
*palEntries
= NULL
;
1692 ULONG RedMask
, GreenMask
, BlueMask
;
1694 // Determine Bits Per Pixel
1695 bits
= bmi
->bmiHeader
.biBitCount
;
1697 // Determine paletteType from Bits Per Pixel
1700 *paletteType
= PAL_INDEXED
;
1701 RedMask
= GreenMask
= BlueMask
= 0;
1703 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1705 *paletteType
= PAL_BITFIELDS
;
1706 RedMask
= ((ULONG
*)bmi
->bmiColors
)[0];
1707 GreenMask
= ((ULONG
*)bmi
->bmiColors
)[1];
1708 BlueMask
= ((ULONG
*)bmi
->bmiColors
)[2];
1712 *paletteType
= PAL_BITFIELDS
;
1719 *paletteType
= PAL_BGR
;
1721 GreenMask
= 0x00ff00;
1722 BlueMask
= 0x0000ff;
1725 if (bmi
->bmiHeader
.biClrUsed
== 0)
1727 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1731 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1734 if (PAL_INDEXED
== *paletteType
)
1736 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)bmi
->bmiColors
);
1740 hPal
= PALETTE_AllocPalette(*paletteType
, ColorCount
,
1741 (ULONG
*) palEntries
,
1742 RedMask
, GreenMask
, BlueMask
);