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
;
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 DDBPalette
, DIBPalette
= 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 DDBPalette
= pDC
->ppdev
->devinfo
.hpalDefault
;
483 /* Try to use hDIBPalette if it exists */
484 pSurf
= pDC
->dclevel
.pSurface
;
485 if (pSurf
&& pSurf
->hDIBPalette
)
487 DDBPalette
= 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(DDBPalette
);
532 SetLastWin32Error(ERROR_INVALID_HANDLE
);
533 Status
= STATUS_UNSUCCESSFUL
;
537 DIBPalette
= BuildDIBPalette(bmi
, (PINT
)&DIBPaletteType
);
540 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
541 Status
= STATUS_NO_MEMORY
;
545 /* Initialize EXLATEOBJ */
546 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
549 Status
= IntEngBitBlt(pDestSurf
,
552 pDC
->rosdc
.CombinedClip
,
559 ROP3_TO_ROP4(SRCCOPY
));
561 /* Cleanup EXLATEOBJ */
562 EXLATEOBJ_vCleanup(&exlo
);
565 if (NT_SUCCESS(Status
))
567 /* FIXME: Should probably be only the number of lines actually copied */
568 ret
= ScanLines
; // this one --> abs(Info->bmiHeader.biHeight) - StartScan;
571 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
572 if (ppalDDB
) PALETTE_UnlockPalette(ppalDDB
);
574 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
575 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
576 if (DIBPalette
) PALETTE_FreePaletteByHandle(DIBPalette
);
583 /* Converts a device-dependent bitmap to a DIB */
586 NtGdiGetDIBitsInternal(
598 SURFACE
*psurf
= NULL
;
599 HBITMAP hDestBitmap
= NULL
;
600 HPALETTE hSourcePalette
= NULL
;
601 HPALETTE hDestPalette
= NULL
;
602 PPALETTE ppalSrc
= NULL
;
603 PPALETTE ppalDst
= NULL
;
604 NTSTATUS Status
= STATUS_SUCCESS
;
606 BOOL bPaletteMatch
= FALSE
;
607 PBYTE ChkBits
= Bits
;
610 ULONG DestPaletteType
;
613 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
615 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
618 // if ScanLines == 0, no need to copy Bits.
624 ProbeForRead(&Info
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
626 ProbeForWrite(Info
, Info
->bmiHeader
.biSize
, 1); // Comp for Core.
627 if (ChkBits
) ProbeForWrite(ChkBits
, MaxBits
, 1);
629 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
631 Status
= _SEH2_GetExceptionCode();
635 if (!NT_SUCCESS(Status
))
641 if (Dc
== NULL
) return 0;
642 if (Dc
->dctype
== DC_TYPE_INFO
)
649 /* Get a pointer to the source bitmap object */
650 psurf
= SURFACE_LockSurface(hBitmap
);
654 hSourcePalette
= psurf
->hDIBPalette
;
657 hSourcePalette
= pPrimarySurface
->devinfo
.hpalDefault
;
660 ColorPtr
= ((PBYTE
)Info
+ Info
->bmiHeader
.biSize
);
661 rgbQuads
= (RGBQUAD
*)ColorPtr
;
663 /* Copy palette information
664 * Always create a palette for 15 & 16 bit. */
665 if ((Info
->bmiHeader
.biBitCount
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) &&
666 Info
->bmiHeader
.biBitCount
!= 15 && Info
->bmiHeader
.biBitCount
!= 16) ||
669 hDestPalette
= hSourcePalette
;
670 bPaletteMatch
= TRUE
;
673 hDestPalette
= BuildDIBPalette(Info
, (PINT
)&DestPaletteType
); //hDestPalette = Dc->DevInfo->hpalDefault;
675 ppalSrc
= PALETTE_LockPalette(hSourcePalette
);
676 /* FIXME - ppalSrc can be NULL!!! Don't assert here! */
681 ppalDst
= PALETTE_LockPalette(hDestPalette
);
682 /* FIXME - ppalDst can be NULL!!!! Don't assert here!!! */
683 DPRINT("ppalDst : %p\n", ppalDst
);
692 /* FIXME: This is largely incomplete. ATM no Core!*/
693 switch (Info
->bmiHeader
.biBitCount
)
698 Info
->bmiHeader
.biClrUsed
= 0;
699 if (psurf
->hSecure
&&
700 BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == Info
->bmiHeader
.biBitCount
)
702 if (Usage
== DIB_RGB_COLORS
)
704 if (ppalDst
->NumColors
!= 1 << Info
->bmiHeader
.biBitCount
)
705 Info
->bmiHeader
.biClrUsed
= ppalDst
->NumColors
;
707 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
710 rgbQuads
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
711 rgbQuads
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
712 rgbQuads
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
713 rgbQuads
[Index
].rgbReserved
= 0;
718 PWORD Ptr
= ColorPtr
;
720 Index
< (1 << Info
->bmiHeader
.biBitCount
);
723 Ptr
[Index
] = (WORD
)Index
;
729 if (Usage
== DIB_PAL_COLORS
)
731 PWORD Ptr
= ColorPtr
;
733 Index
< (1 << Info
->bmiHeader
.biBitCount
);
736 Ptr
[Index
] = (WORD
)Index
;
739 else if (Info
->bmiHeader
.biBitCount
> 1 && bPaletteMatch
)
742 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
745 Info
->bmiColors
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
746 Info
->bmiColors
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
747 Info
->bmiColors
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
748 Info
->bmiColors
[Index
].rgbReserved
= 0;
753 switch (Info
->bmiHeader
.biBitCount
)
756 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
= rgbQuads
[0].rgbBlue
= 0;
757 rgbQuads
[0].rgbReserved
= 0;
758 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
= rgbQuads
[1].rgbBlue
= 0xff;
759 rgbQuads
[1].rgbReserved
= 0;
762 RtlCopyMemory(ColorPtr
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
769 RtlCopyMemory(rgbQuads
, DefLogPaletteQuads
, 10 * sizeof(RGBQUAD
));
770 RtlCopyMemory(rgbQuads
+ 246, DefLogPaletteQuads
+ 10, 10 * sizeof(RGBQUAD
));
771 color
= rgbQuads
+ 10;
772 for (r
= 0; r
<= 5; r
++) /* FIXME */
773 for (g
= 0; g
<= 5; g
++)
774 for (b
= 0; b
<= 5; b
++)
776 color
->rgbRed
= (r
* 0xff) / 5;
777 color
->rgbGreen
= (g
* 0xff) / 5;
778 color
->rgbBlue
= (b
* 0xff) / 5;
779 color
->rgbReserved
= 0;
789 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
791 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
792 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
793 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
798 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
800 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
801 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
802 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
808 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
810 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
811 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
812 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
818 PALETTE_UnlockPalette(ppalDst
);
820 /* fill out the BITMAPINFO struct */
822 { // Core or not to Core? We have converted from Core in Gdi~ so?
823 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
825 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
826 coreheader
->bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
827 coreheader
->bcPlanes
= 1;
828 coreheader
->bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
829 coreheader
->bcHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
830 if (psurf
->SurfObj
.lDelta
> 0)
831 coreheader
->bcHeight
= -coreheader
->bcHeight
;
834 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
836 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
837 Info
->bmiHeader
.biHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
838 Info
->bmiHeader
.biPlanes
= 1;
839 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
840 switch (psurf
->SurfObj
.iBitmapFormat
)
842 /* FIXME: What about BI_BITFIELDS? */
849 Info
->bmiHeader
.biCompression
= BI_RGB
;
852 Info
->bmiHeader
.biCompression
= BI_RLE4
;
855 Info
->bmiHeader
.biCompression
= BI_RLE8
;
858 Info
->bmiHeader
.biCompression
= BI_JPEG
;
861 Info
->bmiHeader
.biCompression
= BI_PNG
;
864 /* Image size has to be calculated */
865 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(Info
->bmiHeader
.biWidth
,
866 Info
->bmiHeader
.biBitCount
) * Info
->bmiHeader
.biHeight
;
867 Info
->bmiHeader
.biXPelsPerMeter
= 0; /* FIXME */
868 Info
->bmiHeader
.biYPelsPerMeter
= 0; /* FIXME */
869 Info
->bmiHeader
.biClrUsed
= 0;
870 Info
->bmiHeader
.biClrImportant
= 1 << Info
->bmiHeader
.biBitCount
; /* FIXME */
871 /* Report negtive height for top-down bitmaps. */
872 if (psurf
->SurfObj
.lDelta
> 0)
873 Info
->bmiHeader
.biHeight
= -Info
->bmiHeader
.biHeight
;
875 Result
= psurf
->SurfObj
.sizlBitmap
.cy
;
883 // If we have a good dib pointer, why not just copy bits from there w/o XLATE'ing them.
885 /* Create the destination bitmap too for the copy operation */
886 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
892 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
893 DestSize
.cx
= psurf
->SurfObj
.sizlBitmap
.cx
;
894 DestSize
.cy
= ScanLines
;
898 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
900 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
901 hDestBitmap
= EngCreateBitmap(DestSize
,
902 DIB_GetDIBWidthBytes(DestSize
.cx
, coreheader
->bcBitCount
),
903 BitmapFormat(coreheader
->bcBitCount
, BI_RGB
),
904 0 < coreheader
->bcHeight
? 0 : BMF_TOPDOWN
,
908 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
910 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(DestSize
.cx
,
911 Info
->bmiHeader
.biBitCount
) * DestSize
.cy
;
913 hDestBitmap
= EngCreateBitmap(DestSize
,
914 DIB_GetDIBWidthBytes(DestSize
.cx
, Info
->bmiHeader
.biBitCount
),
915 BitmapFormat(Info
->bmiHeader
.biBitCount
, Info
->bmiHeader
.biCompression
),
916 0 < Info
->bmiHeader
.biHeight
? 0 : BMF_TOPDOWN
,
920 if (hDestBitmap
== NULL
)
924 if (NT_SUCCESS(Status
))
927 SURFOBJ
*DestSurfObj
;
930 EXLATEOBJ_vInitialize(&exlo
, ppalSrc
, ppalDst
, 0, 0, 0);
933 SourcePoint
.y
= psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
);
935 /* Determine destination rectangle */
938 DestRect
.right
= DestSize
.cx
;
939 DestRect
.bottom
= DestSize
.cy
;
941 DestSurfObj
= EngLockSurface((HSURF
)hDestBitmap
);
943 if (IntEngCopyBits(DestSurfObj
,
950 DPRINT("GetDIBits %d \n",abs(Info
->bmiHeader
.biHeight
) - StartScan
);
954 EXLATEOBJ_vCleanup(&exlo
);
955 EngUnlockSurface(DestSurfObj
);
959 PALETTE_UnlockPalette(ppalSrc
);
961 if (hDestBitmap
!= NULL
)
962 EngDeleteSurface((HSURF
)hDestBitmap
);
964 if (hDestPalette
!= NULL
&& bPaletteMatch
== FALSE
)
965 PALETTE_FreePaletteByHandle(hDestPalette
);
967 SURFACE_UnlockSurface(psurf
);
969 DPRINT("leaving NtGdiGetDIBitsInternal\n");
976 NtGdiStretchDIBitsInternal(
987 LPBITMAPINFO BitsInfo
,
994 HBITMAP hBitmap
, hOldBitmap
= NULL
;
996 HPALETTE hPal
= NULL
;
1000 if (!Bits
|| !BitsInfo
)
1002 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1008 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1009 ProbeForRead(Bits
, cjMaxBits
, 1);
1011 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1019 DPRINT1("NtGdiStretchDIBitsInternal fail to read BitMapInfo: %x or Bits: %x\n",BitsInfo
,Bits
);
1023 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1026 DPRINT1("NtGdiCreateCompatibleDC fail create hdc\n");
1030 hBitmap
= NtGdiCreateCompatibleBitmap(hDC
,
1031 abs(BitsInfo
->bmiHeader
.biWidth
),
1032 abs(BitsInfo
->bmiHeader
.biHeight
));
1033 if (hBitmap
== NULL
)
1035 DPRINT1("NtGdiCreateCompatibleBitmap fail create bitmap\n");
1036 DPRINT1("hDC : 0x%08x \n", hDC
);
1037 DPRINT1("BitsInfo->bmiHeader.biWidth : 0x%08x \n", BitsInfo
->bmiHeader
.biWidth
);
1038 DPRINT1("BitsInfo->bmiHeader.biHeight : 0x%08x \n", BitsInfo
->bmiHeader
.biHeight
);
1042 /* Select the bitmap into hdcMem, and save a handle to the old bitmap */
1043 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1045 if (Usage
== DIB_PAL_COLORS
)
1047 hPal
= NtGdiGetDCObject(hDC
, GDI_OBJECT_TYPE_PALETTE
);
1048 hPal
= GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1051 if (BitsInfo
->bmiHeader
.biCompression
== BI_RLE4
||
1052 BitsInfo
->bmiHeader
.biCompression
== BI_RLE8
)
1054 /* copy existing bitmap from destination dc */
1055 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1056 NtGdiBitBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1057 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, ROP
, 0, 0);
1059 NtGdiStretchBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1060 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1064 pDC
= DC_LockDc(hdcMem
);
1067 /* Note BitsInfo->bmiHeader.biHeight is the number of scanline,
1068 * if it negitve we getting to many scanline for scanline is UINT not
1069 * a INT, so we need make the negtive value to positve and that make the
1070 * count correct for negtive bitmap, TODO : we need testcase for this api */
1071 IntSetDIBits(pDC
, hBitmap
, 0, abs(BitsInfo
->bmiHeader
.biHeight
), Bits
,
1078 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1079 left (negative biHeight) */
1080 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1081 NtGdiBitBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1082 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1085 NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1086 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1087 SrcWidth
, SrcHeight
, ROP
, 0);
1091 GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1094 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1096 NtGdiDeleteObjectApp(hdcMem
);
1098 GreDeleteObject(hBitmap
);
1119 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1120 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1122 if (bpp
!= 1) fColor
= TRUE
;
1123 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1126 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
1128 const RGBQUAD
*rgb
= data
->bmiColors
;
1129 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1131 // Check if the first color of the colormap is black
1132 if ((col
== RGB(0, 0, 0)))
1135 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1137 // If the second color is white, create a monochrome bitmap
1138 fColor
= (col
!= RGB(0xff,0xff,0xff));
1142 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1144 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
1145 DWORD col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1147 if ((col
== RGB(0,0,0)))
1150 col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1151 fColor
= (col
!= RGB(0xff,0xff,0xff));
1157 DPRINT("(%ld): wrong size for data\n", data
->bmiHeader
.biSize
);
1162 // Now create the bitmap
1165 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1169 handle
= IntGdiCreateBitmap(width
,
1179 if (NULL
!= handle
&& CBM_INIT
== init
)
1181 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1187 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1188 // The DDB that is created will be whatever bit depth your reference DC is
1191 NtGdiCreateDIBitmapInternal(
1196 IN OPTIONAL LPBYTE pjInit
,
1197 IN OPTIONAL LPBITMAPINFO pbmi
,
1199 IN UINT cjMaxInitInfo
,
1208 if (!hDc
) // CreateBitmap
1209 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1210 hDc
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
,FALSE
);
1213 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1217 Dc
= DC_LockDc(hDc
);
1220 NtGdiDeleteObjectApp(hDc
);
1221 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1225 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1228 NtGdiDeleteObjectApp(hDc
);
1230 else // CreateCompatibleBitmap
1232 Dc
= DC_LockDc(hDc
);
1235 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1239 First create an un-initialised bitmap. The depth of the bitmap
1240 should match that of the hdc and not that supplied in bmih.
1243 bpp
= pbmi
->bmiHeader
.biBitCount
;
1246 if (Dc
->dctype
!= DC_TYPE_MEMORY
)
1247 bpp
= IntGdiGetDeviceCaps(Dc
, BITSPIXEL
);
1252 SURFACE
*psurf
= Dc
->dclevel
.pSurface
;
1253 Count
= BITMAP_GetObject(psurf
, sizeof(dibs
), &dibs
);
1258 if (Count
== sizeof(BITMAP
))
1259 /* A device-dependent bitmap is selected in the DC */
1260 bpp
= dibs
.dsBm
.bmBitsPixel
;
1262 /* A DIB section is selected in the DC */
1263 bpp
= dibs
.dsBmih
.biBitCount
;
1267 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1276 NtGdiCreateDIBSection(
1278 IN OPTIONAL HANDLE hSection
,
1280 IN LPBITMAPINFO bmi
,
1284 IN ULONG_PTR dwColorSpace
,
1287 HBITMAP hbitmap
= 0;
1289 BOOL bDesktopDC
= FALSE
;
1291 if (!bmi
) return hbitmap
; // Make sure.
1293 // If the reference hdc is null, take the desktop dc
1296 hDC
= NtGdiCreateCompatibleDC(0);
1300 if ((dc
= DC_LockDc(hDC
)))
1302 hbitmap
= DIB_CreateDIBSection(dc
,
1313 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1317 NtGdiDeleteObjectApp(hDC
);
1324 DIB_CreateDIBSection(
1334 SURFACE
*bmp
= NULL
;
1335 void *mapBits
= NULL
;
1338 // Fill BITMAP32 structure with DIB data
1339 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1346 DWORD dsBitfields
[3] = {0};
1348 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1349 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1350 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1352 /* CreateDIBSection should fail for compressed formats */
1353 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1355 return (HBITMAP
)NULL
;
1358 pdcattr
= dc
->pdcattr
;
1360 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1362 bm
.bmWidth
= bi
->biWidth
;
1363 bm
.bmHeight
= effHeight
;
1364 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1366 bm
.bmPlanes
= bi
->biPlanes
;
1367 bm
.bmBitsPixel
= bi
->biBitCount
;
1370 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1371 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1372 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1373 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1377 SYSTEM_BASIC_INFORMATION Sbi
;
1380 LARGE_INTEGER SectionOffset
;
1383 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1387 if (!NT_SUCCESS(Status
))
1392 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1393 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1395 SectionOffset
.LowPart
= mapOffset
;
1396 SectionOffset
.HighPart
= 0;
1398 Status
= ZwMapViewOfSection(section
,
1408 if (!NT_SUCCESS(Status
))
1410 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1414 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1416 else if (ovr_pitch
&& offset
)
1417 bm
.bmBits
= (LPVOID
) offset
;
1421 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1424 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1425 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1427 if (usage
== DIB_PAL_COLORS
)
1428 lpRGB
= DIB_MapPaletteColors(dc
, bmi
);
1430 lpRGB
= bmi
->bmiColors
;
1432 /* Set dsBitfields values */
1433 if (usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1435 dsBitfields
[0] = dsBitfields
[1] = dsBitfields
[2] = 0;
1437 else if (bi
->biCompression
== BI_RGB
)
1439 switch (bi
->biBitCount
)
1443 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0x7c00;
1444 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x03e0;
1445 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x001f;
1450 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0xff0000;
1451 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x00ff00;
1452 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x0000ff;
1458 dsBitfields
[0] = ((DWORD
*)bmi
->bmiColors
)[0];
1459 dsBitfields
[1] = ((DWORD
*)bmi
->bmiColors
)[1];
1460 dsBitfields
[2] = ((DWORD
*)bmi
->bmiColors
)[2];
1463 // Create Device Dependent Bitmap and add DIB pointer
1464 Size
.cx
= bm
.bmWidth
;
1465 Size
.cy
= abs(bm
.bmHeight
);
1466 res
= IntCreateBitmap(Size
,
1468 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1469 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1470 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1474 if (lpRGB
!= bmi
->bmiColors
)
1476 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1478 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1481 bmp
= SURFACE_LockSurface(res
);
1484 if (lpRGB
!= bmi
->bmiColors
)
1486 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1488 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1489 GreDeleteObject(bmp
);
1493 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1494 table between the DIB and the X physical device. Obviously,
1495 this is left out of the ReactOS implementation. Instead,
1496 we call NtGdiSetDIBColorTable. */
1498 /* set number of entries in bmi.bmiColors table */
1499 if (bi
->biBitCount
== 1) {
1502 if (bi
->biBitCount
== 4) {
1505 if (bi
->biBitCount
== 8) {
1506 bi
->biClrUsed
= 256;
1509 bmp
->hDIBSection
= section
;
1510 bmp
->hSecure
= hSecure
;
1511 bmp
->dwOffset
= offset
;
1512 bmp
->flFlags
= BITMAPOBJ_IS_APIBITMAP
;
1513 bmp
->dsBitfields
[0] = dsBitfields
[0];
1514 bmp
->dsBitfields
[1] = dsBitfields
[1];
1515 bmp
->dsBitfields
[2] = dsBitfields
[2];
1516 bmp
->biClrUsed
= bi
->biClrUsed
;
1517 bmp
->biClrImportant
= bi
->biClrImportant
;
1519 if (bi
->biClrUsed
!= 0)
1520 bmp
->hDIBPalette
= PALETTE_AllocPaletteIndexedRGB(bi
->biClrUsed
, lpRGB
);
1522 bmp
->hDIBPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1527 // Clean up in case of errors
1528 if (!res
|| !bmp
|| !bm
.bmBits
)
1530 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1533 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1536 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1541 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1549 SURFACE_FreeSurfaceByHandle(res
);
1554 if (lpRGB
!= bmi
->bmiColors
)
1556 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1561 SURFACE_UnlockSurface(bmp
);
1564 // Return BITMAP handle and storage location
1565 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1570 if (res
) pdcattr
->ulDirty_
|= DC_DIBSECTION
;
1575 /***********************************************************************
1576 * DIB_GetDIBWidthBytes
1578 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1579 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1580 * 11/16/1999 (RJJ) lifted from wine
1582 INT FASTCALL
DIB_GetDIBWidthBytes(INT width
, INT depth
)
1584 return ((width
* depth
+ 31) & ~31) >> 3;
1587 /***********************************************************************
1588 * DIB_GetDIBImageBytes
1590 * Return the number of bytes used to hold the image in a DIB bitmap.
1591 * 11/16/1999 (RJJ) lifted from wine
1594 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1596 return DIB_GetDIBWidthBytes(width
, depth
) * (height
< 0 ? -height
: height
);
1599 /***********************************************************************
1600 * DIB_BitmapInfoSize
1602 * Return the size of the bitmap info structure including color table.
1603 * 11/16/1999 (RJJ) lifted from wine
1606 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1610 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1612 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1613 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1614 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1616 else /* assume BITMAPINFOHEADER */
1618 colors
= info
->bmiHeader
.biClrUsed
;
1619 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1620 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1626 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1633 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1640 if (palGDI
->Mode
!= PAL_INDEXED
)
1642 PALETTE_UnlockPalette(palGDI
);
1646 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1647 if (lpbmi
->bmiHeader
.biClrUsed
)
1649 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1652 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1655 PALETTE_UnlockPalette(palGDI
);
1659 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1661 for (i
= 0; i
< nNumColors
; i
++)
1663 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1664 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1665 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1666 lpRGB
[i
].rgbReserved
= 0;
1669 PALETTE_UnlockPalette(palGDI
);
1676 BuildDIBPalette(CONST BITMAPINFO
*bmi
, PINT paletteType
)
1680 PALETTEENTRY
*palEntries
= NULL
;
1682 ULONG RedMask
, GreenMask
, BlueMask
;
1684 // Determine Bits Per Pixel
1685 bits
= bmi
->bmiHeader
.biBitCount
;
1687 // Determine paletteType from Bits Per Pixel
1690 *paletteType
= PAL_INDEXED
;
1691 RedMask
= GreenMask
= BlueMask
= 0;
1693 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1695 *paletteType
= PAL_BITFIELDS
;
1696 RedMask
= ((ULONG
*)bmi
->bmiColors
)[0];
1697 GreenMask
= ((ULONG
*)bmi
->bmiColors
)[1];
1698 BlueMask
= ((ULONG
*)bmi
->bmiColors
)[2];
1702 *paletteType
= PAL_BITFIELDS
;
1709 *paletteType
= PAL_BGR
;
1711 GreenMask
= 0x00ff00;
1712 BlueMask
= 0x0000ff;
1715 if (bmi
->bmiHeader
.biClrUsed
== 0)
1717 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1721 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1724 if (PAL_INDEXED
== *paletteType
)
1726 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)bmi
->bmiColors
);
1730 hPal
= PALETTE_AllocPalette(*paletteType
, ColorCount
,
1731 (ULONG
*) palEntries
,
1732 RedMask
, GreenMask
, BlueMask
);