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 PalGDI
= PALETTE_LockPalette(psurf
->hDIBPalette
);
116 SetLastWin32Error(ERROR_INVALID_HANDLE
);
120 for (Index
= StartIndex
;
121 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
124 PalGDI
->IndexedColors
[Index
].peRed
= Colors
[Index
- StartIndex
].rgbRed
;
125 PalGDI
->IndexedColors
[Index
].peGreen
= Colors
[Index
- StartIndex
].rgbGreen
;
126 PalGDI
->IndexedColors
[Index
].peBlue
= Colors
[Index
- StartIndex
].rgbBlue
;
128 PALETTE_UnlockPalette(PalGDI
);
133 /* Mark the brushes invalid */
134 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
|DIRTY_LINE
|DIRTY_BACKGROUND
|DIRTY_TEXT
;
155 if (!(dc
= DC_LockDc(hDC
))) return 0;
156 if (dc
->dctype
== DC_TYPE_INFO
)
162 psurf
= dc
->dclevel
.pSurface
;
166 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
170 if (psurf
->hSecure
== NULL
)
173 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
177 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
178 if (biBitCount
<= 8 &&
179 StartIndex
< (1 << biBitCount
))
181 if (StartIndex
+ Entries
> (1 << biBitCount
))
182 Entries
= (1 << biBitCount
) - StartIndex
;
184 PalGDI
= PALETTE_LockPalette(psurf
->hDIBPalette
);
188 SetLastWin32Error(ERROR_INVALID_HANDLE
);
192 for (Index
= StartIndex
;
193 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
196 Colors
[Index
- StartIndex
].rgbRed
= PalGDI
->IndexedColors
[Index
].peRed
;
197 Colors
[Index
- StartIndex
].rgbGreen
= PalGDI
->IndexedColors
[Index
].peGreen
;
198 Colors
[Index
- StartIndex
].rgbBlue
= PalGDI
->IndexedColors
[Index
].peBlue
;
199 Colors
[Index
- StartIndex
].rgbReserved
= 0;
201 PALETTE_UnlockPalette(PalGDI
);
211 // Converts a DIB to a device-dependent bitmap
220 CONST BITMAPINFO
*bmi
,
224 HBITMAP SourceBitmap
;
227 SURFOBJ
*DestSurf
, *SourceSurf
;
232 PPALETTE ppalDDB
, ppalDIB
;
234 HPALETTE DDB_Palette
, DIB_Palette
;
235 ULONG DIB_Palette_Type
;
239 if (!(bitmap
= SURFACE_LockSurface(hBitmap
)))
245 //if (ColorUse == DIB_PAL_COLORS)
246 // lpRGB = DIB_MapPaletteColors(hDC, bmi);
248 // lpRGB = &bmi->bmiColors;
250 DestSurf
= &bitmap
->SurfObj
;
252 // Create source surface
253 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
254 SourceSize
.cy
= ScanLines
;
256 // Determine width of DIB
257 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
259 SourceBitmap
= EngCreateBitmap(SourceSize
,
261 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
262 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
264 if (0 == SourceBitmap
)
266 SURFACE_UnlockSurface(bitmap
);
267 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
271 SourceSurf
= EngLockSurface((HSURF
)SourceBitmap
);
272 if (NULL
== SourceSurf
)
274 EngDeleteSurface((HSURF
)SourceBitmap
);
275 SURFACE_UnlockSurface(bitmap
);
276 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
280 // Use hDIBPalette if it exists
281 if (bitmap
->hDIBPalette
)
283 DDB_Palette
= bitmap
->hDIBPalette
;
287 // Destination palette obtained from the hDC
288 DDB_Palette
= DC
->ppdev
->devinfo
.hpalDefault
;
291 ppalDDB
= PALETTE_LockPalette(DDB_Palette
);
294 EngUnlockSurface(SourceSurf
);
295 EngDeleteSurface((HSURF
)SourceBitmap
);
296 SURFACE_UnlockSurface(bitmap
);
297 SetLastWin32Error(ERROR_INVALID_HANDLE
);
301 // Source palette obtained from the BITMAPINFO
302 DIB_Palette
= BuildDIBPalette((PBITMAPINFO
)bmi
, (PINT
)&DIB_Palette_Type
);
303 if (NULL
== DIB_Palette
)
305 EngUnlockSurface(SourceSurf
);
306 EngDeleteSurface((HSURF
)SourceBitmap
);
307 SURFACE_UnlockSurface(bitmap
);
308 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
312 ppalDIB
= PALETTE_LockPalette(DIB_Palette
);
314 /* Initialize XLATEOBJ for color translation */
315 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
321 // Determine destination rectangle
323 DestRect
.top
= abs(bmi
->bmiHeader
.biHeight
) - StartScan
- ScanLines
;
324 DestRect
.right
= SourceSize
.cx
;
325 DestRect
.bottom
= DestRect
.top
+ ScanLines
;
327 copyBitsResult
= IntEngCopyBits(DestSurf
, SourceSurf
, NULL
, &exlo
.xlo
, &DestRect
, &ZeroPoint
);
329 // If it succeeded, return number of scanlines copies
330 if (copyBitsResult
== TRUE
)
332 result
= SourceSize
.cy
;
334 // result = abs(bmi->bmiHeader.biHeight) - StartScan;
338 EXLATEOBJ_vCleanup(&exlo
);
339 PALETTE_UnlockPalette(ppalDIB
);
340 PALETTE_UnlockPalette(ppalDDB
);
341 PALETTE_FreePaletteByHandle(DIB_Palette
);
342 EngUnlockSurface(SourceSurf
);
343 EngDeleteSurface((HSURF
)SourceBitmap
);
345 // if (ColorUse == DIB_PAL_COLORS)
346 // WinFree((LPSTR)lpRGB);
348 SURFACE_UnlockSurface(bitmap
);
353 // FIXME by Removing NtGdiSetDIBits!!!
354 // This is a victim of the Win32k Initialization BUG!!!!!
355 // Converts a DIB to a device-dependent bitmap
364 CONST BITMAPINFO
*bmi
,
369 NTSTATUS Status
= STATUS_SUCCESS
;
375 { // FYI: We converted from CORE in gdi.
376 ProbeForRead(bmi
, sizeof(BITMAPINFO
), 1);
377 cjBits
= bmi
->bmiHeader
.biBitCount
* bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biWidth
;
378 cjBits
= ((cjBits
+ 31) & ~31) / 8;
380 ProbeForRead(Bits
, cjBits
, 1);
382 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
384 Status
= _SEH2_GetExceptionCode();
388 if (!NT_SUCCESS(Status
))
396 SetLastWin32Error(ERROR_INVALID_HANDLE
);
399 if (Dc
->dctype
== DC_TYPE_INFO
)
405 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
415 NtGdiSetDIBitsToDeviceInternal(
430 IN BOOL bTransformCoordinates
,
431 IN OPTIONAL HANDLE hcmXform
)
434 NTSTATUS Status
= STATUS_SUCCESS
;
436 HBITMAP hSourceBitmap
= NULL
;
437 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
444 PPALETTE ppalDDB
= NULL
, ppalDIB
= NULL
;
445 HPALETTE hpalDDB
, hpalDIB
= NULL
;
446 ULONG DIBPaletteType
;
452 ProbeForRead(bmi
, cjMaxInfo
, 1);
453 ProbeForRead(Bits
, cjMaxBits
, 1);
455 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
457 Status
= _SEH2_GetExceptionCode();
461 if (!NT_SUCCESS(Status
))
466 pDC
= DC_LockDc(hDC
);
469 SetLastWin32Error(ERROR_INVALID_HANDLE
);
472 if (pDC
->dctype
== DC_TYPE_INFO
)
478 /* Use destination palette obtained from the DC by default */
479 hpalDDB
= pDC
->ppdev
->devinfo
.hpalDefault
;
481 /* Try to use hDIBPalette if it exists */
482 pSurf
= pDC
->dclevel
.pSurface
;
483 if (pSurf
&& pSurf
->hDIBPalette
)
485 hpalDDB
= pSurf
->hDIBPalette
;
488 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
490 ScanLines
= min(ScanLines
, abs(bmi
->bmiHeader
.biHeight
) - StartScan
);
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
;
502 rcDest
.top
+= StartScan
;
507 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
508 SourceSize
.cy
= ScanLines
;
510 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
512 hSourceBitmap
= EngCreateBitmap(SourceSize
,
514 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
515 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
519 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
520 Status
= STATUS_NO_MEMORY
;
524 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
527 Status
= STATUS_UNSUCCESSFUL
;
531 /* Obtain destination palette */
532 ppalDDB
= PALETTE_LockPalette(hpalDDB
);
535 SetLastWin32Error(ERROR_INVALID_HANDLE
);
536 Status
= STATUS_UNSUCCESSFUL
;
540 /* Create a palette for the DIB */
541 hpalDIB
= BuildDIBPalette(bmi
, (PINT
)&DIBPaletteType
);
544 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
545 Status
= STATUS_NO_MEMORY
;
549 /* Lock the DIB palette */
550 ppalDIB
= PALETTE_LockPalette(hpalDIB
);
553 SetLastWin32Error(ERROR_INVALID_HANDLE
);
554 Status
= STATUS_UNSUCCESSFUL
;
558 /* Initialize EXLATEOBJ */
559 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
562 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
563 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
564 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
565 Status
= IntEngBitBlt(pDestSurf
,
568 pDC
->rosdc
.CombinedClip
,
575 ROP3_TO_ROP4(SRCCOPY
));
577 /* Cleanup EXLATEOBJ */
578 EXLATEOBJ_vCleanup(&exlo
);
581 if (NT_SUCCESS(Status
))
586 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
587 if (ppalDDB
) PALETTE_UnlockPalette(ppalDDB
);
589 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
590 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
591 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
598 /* Converts a device-dependent bitmap to a DIB */
601 NtGdiGetDIBitsInternal(
613 SURFACE
*psurf
= NULL
;
614 HBITMAP hDestBitmap
= NULL
;
615 HPALETTE hSourcePalette
= NULL
;
616 HPALETTE hDestPalette
= NULL
;
617 PPALETTE ppalSrc
= NULL
;
618 PPALETTE ppalDst
= NULL
;
619 NTSTATUS Status
= STATUS_SUCCESS
;
621 BOOL bPaletteMatch
= FALSE
;
622 PBYTE ChkBits
= Bits
;
625 ULONG DestPaletteType
;
628 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
630 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
633 // if ScanLines == 0, no need to copy Bits.
639 ProbeForRead(&Info
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
641 ProbeForWrite(Info
, Info
->bmiHeader
.biSize
, 1); // Comp for Core.
642 if (ChkBits
) ProbeForWrite(ChkBits
, MaxBits
, 1);
644 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
646 Status
= _SEH2_GetExceptionCode();
650 if (!NT_SUCCESS(Status
))
656 if (Dc
== NULL
) return 0;
657 if (Dc
->dctype
== DC_TYPE_INFO
)
664 /* Get a pointer to the source bitmap object */
665 psurf
= SURFACE_LockSurface(hBitmap
);
669 hSourcePalette
= psurf
->hDIBPalette
;
672 hSourcePalette
= pPrimarySurface
->devinfo
.hpalDefault
;
675 ColorPtr
= ((PBYTE
)Info
+ Info
->bmiHeader
.biSize
);
676 rgbQuads
= (RGBQUAD
*)ColorPtr
;
678 /* Copy palette information
679 * Always create a palette for 15 & 16 bit. */
680 if ((Info
->bmiHeader
.biBitCount
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) &&
681 Info
->bmiHeader
.biBitCount
!= 15 && Info
->bmiHeader
.biBitCount
!= 16) ||
684 hDestPalette
= hSourcePalette
;
685 bPaletteMatch
= TRUE
;
688 hDestPalette
= BuildDIBPalette(Info
, (PINT
)&DestPaletteType
); //hDestPalette = Dc->DevInfo->hpalDefault;
690 ppalSrc
= PALETTE_LockPalette(hSourcePalette
);
691 /* FIXME - ppalSrc can be NULL!!! Don't assert here! */
696 ppalDst
= PALETTE_LockPalette(hDestPalette
);
697 /* FIXME - ppalDst can be NULL!!!! Don't assert here!!! */
698 DPRINT("ppalDst : %p\n", ppalDst
);
707 /* FIXME: This is largely incomplete. ATM no Core!*/
708 switch (Info
->bmiHeader
.biBitCount
)
713 Info
->bmiHeader
.biClrUsed
= 0;
714 if (psurf
->hSecure
&&
715 BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == Info
->bmiHeader
.biBitCount
)
717 if (Usage
== DIB_RGB_COLORS
)
719 if (ppalDst
->NumColors
!= 1 << Info
->bmiHeader
.biBitCount
)
720 Info
->bmiHeader
.biClrUsed
= ppalDst
->NumColors
;
722 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
725 rgbQuads
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
726 rgbQuads
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
727 rgbQuads
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
728 rgbQuads
[Index
].rgbReserved
= 0;
733 PWORD Ptr
= ColorPtr
;
735 Index
< (1 << Info
->bmiHeader
.biBitCount
);
738 Ptr
[Index
] = (WORD
)Index
;
744 if (Usage
== DIB_PAL_COLORS
)
746 PWORD Ptr
= ColorPtr
;
748 Index
< (1 << Info
->bmiHeader
.biBitCount
);
751 Ptr
[Index
] = (WORD
)Index
;
754 else if (Info
->bmiHeader
.biBitCount
> 1 && bPaletteMatch
)
757 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
760 Info
->bmiColors
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
761 Info
->bmiColors
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
762 Info
->bmiColors
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
763 Info
->bmiColors
[Index
].rgbReserved
= 0;
768 switch (Info
->bmiHeader
.biBitCount
)
771 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
= rgbQuads
[0].rgbBlue
= 0;
772 rgbQuads
[0].rgbReserved
= 0;
773 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
= rgbQuads
[1].rgbBlue
= 0xff;
774 rgbQuads
[1].rgbReserved
= 0;
777 RtlCopyMemory(ColorPtr
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
784 RtlCopyMemory(rgbQuads
, DefLogPaletteQuads
, 10 * sizeof(RGBQUAD
));
785 RtlCopyMemory(rgbQuads
+ 246, DefLogPaletteQuads
+ 10, 10 * sizeof(RGBQUAD
));
786 color
= rgbQuads
+ 10;
787 for (r
= 0; r
<= 5; r
++) /* FIXME */
788 for (g
= 0; g
<= 5; g
++)
789 for (b
= 0; b
<= 5; b
++)
791 color
->rgbRed
= (r
* 0xff) / 5;
792 color
->rgbGreen
= (g
* 0xff) / 5;
793 color
->rgbBlue
= (b
* 0xff) / 5;
794 color
->rgbReserved
= 0;
804 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
806 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
807 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
808 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
813 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
815 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
816 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
817 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
823 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
825 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
826 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
827 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
833 PALETTE_UnlockPalette(ppalDst
);
835 /* fill out the BITMAPINFO struct */
837 { // Core or not to Core? We have converted from Core in Gdi~ so?
838 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
840 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
841 coreheader
->bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
842 coreheader
->bcPlanes
= 1;
843 coreheader
->bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
844 coreheader
->bcHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
845 if (psurf
->SurfObj
.lDelta
> 0)
846 coreheader
->bcHeight
= -coreheader
->bcHeight
;
849 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
851 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
852 Info
->bmiHeader
.biHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
853 Info
->bmiHeader
.biPlanes
= 1;
854 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
855 switch (psurf
->SurfObj
.iBitmapFormat
)
857 /* FIXME: What about BI_BITFIELDS? */
864 Info
->bmiHeader
.biCompression
= BI_RGB
;
867 Info
->bmiHeader
.biCompression
= BI_RLE4
;
870 Info
->bmiHeader
.biCompression
= BI_RLE8
;
873 Info
->bmiHeader
.biCompression
= BI_JPEG
;
876 Info
->bmiHeader
.biCompression
= BI_PNG
;
879 /* Image size has to be calculated */
880 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(Info
->bmiHeader
.biWidth
,
881 Info
->bmiHeader
.biBitCount
) * Info
->bmiHeader
.biHeight
;
882 Info
->bmiHeader
.biXPelsPerMeter
= 0; /* FIXME */
883 Info
->bmiHeader
.biYPelsPerMeter
= 0; /* FIXME */
884 Info
->bmiHeader
.biClrUsed
= 0;
885 Info
->bmiHeader
.biClrImportant
= 1 << Info
->bmiHeader
.biBitCount
; /* FIXME */
886 /* Report negtive height for top-down bitmaps. */
887 if (psurf
->SurfObj
.lDelta
> 0)
888 Info
->bmiHeader
.biHeight
= -Info
->bmiHeader
.biHeight
;
890 Result
= psurf
->SurfObj
.sizlBitmap
.cy
;
898 // If we have a good dib pointer, why not just copy bits from there w/o XLATE'ing them.
900 /* Create the destination bitmap too for the copy operation */
901 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
907 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
908 DestSize
.cx
= psurf
->SurfObj
.sizlBitmap
.cx
;
909 DestSize
.cy
= ScanLines
;
913 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
915 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
916 hDestBitmap
= EngCreateBitmap(DestSize
,
917 DIB_GetDIBWidthBytes(DestSize
.cx
, coreheader
->bcBitCount
),
918 BitmapFormat(coreheader
->bcBitCount
, BI_RGB
),
919 0 < coreheader
->bcHeight
? 0 : BMF_TOPDOWN
,
923 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
925 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(DestSize
.cx
,
926 Info
->bmiHeader
.biBitCount
) * DestSize
.cy
;
928 hDestBitmap
= EngCreateBitmap(DestSize
,
929 DIB_GetDIBWidthBytes(DestSize
.cx
, Info
->bmiHeader
.biBitCount
),
930 BitmapFormat(Info
->bmiHeader
.biBitCount
, Info
->bmiHeader
.biCompression
),
931 0 < Info
->bmiHeader
.biHeight
? 0 : BMF_TOPDOWN
,
935 if (hDestBitmap
== NULL
)
939 if (NT_SUCCESS(Status
))
942 SURFOBJ
*DestSurfObj
;
945 EXLATEOBJ_vInitialize(&exlo
, ppalSrc
, ppalDst
, 0, 0, 0);
948 SourcePoint
.y
= psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
);
950 /* Determine destination rectangle */
953 DestRect
.right
= DestSize
.cx
;
954 DestRect
.bottom
= DestSize
.cy
;
956 DestSurfObj
= EngLockSurface((HSURF
)hDestBitmap
);
958 if (IntEngCopyBits(DestSurfObj
,
965 DPRINT("GetDIBits %d \n",abs(Info
->bmiHeader
.biHeight
) - StartScan
);
969 EXLATEOBJ_vCleanup(&exlo
);
970 EngUnlockSurface(DestSurfObj
);
974 PALETTE_UnlockPalette(ppalSrc
);
976 if (hDestBitmap
!= NULL
)
977 EngDeleteSurface((HSURF
)hDestBitmap
);
979 if (hDestPalette
!= NULL
&& bPaletteMatch
== FALSE
)
980 PALETTE_FreePaletteByHandle(hDestPalette
);
982 SURFACE_UnlockSurface(psurf
);
984 DPRINT("leaving NtGdiGetDIBitsInternal\n");
991 NtGdiStretchDIBitsInternal(
1002 LPBITMAPINFO BitsInfo
,
1009 HBITMAP hBitmap
, hOldBitmap
= NULL
;
1011 HPALETTE hPal
= NULL
;
1015 if (!Bits
|| !BitsInfo
)
1017 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1023 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1024 ProbeForRead(Bits
, cjMaxBits
, 1);
1026 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1034 DPRINT1("NtGdiStretchDIBitsInternal fail to read BitMapInfo: %x or Bits: %x\n",BitsInfo
,Bits
);
1038 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1041 DPRINT1("NtGdiCreateCompatibleDC fail create hdc\n");
1045 hBitmap
= NtGdiCreateCompatibleBitmap(hDC
,
1046 abs(BitsInfo
->bmiHeader
.biWidth
),
1047 abs(BitsInfo
->bmiHeader
.biHeight
));
1048 if (hBitmap
== NULL
)
1050 DPRINT1("NtGdiCreateCompatibleBitmap fail create bitmap\n");
1051 DPRINT1("hDC : 0x%08x \n", hDC
);
1052 DPRINT1("BitsInfo->bmiHeader.biWidth : 0x%08x \n", BitsInfo
->bmiHeader
.biWidth
);
1053 DPRINT1("BitsInfo->bmiHeader.biHeight : 0x%08x \n", BitsInfo
->bmiHeader
.biHeight
);
1057 /* Select the bitmap into hdcMem, and save a handle to the old bitmap */
1058 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1060 if (Usage
== DIB_PAL_COLORS
)
1062 hPal
= NtGdiGetDCObject(hDC
, GDI_OBJECT_TYPE_PALETTE
);
1063 hPal
= GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1066 if (BitsInfo
->bmiHeader
.biCompression
== BI_RLE4
||
1067 BitsInfo
->bmiHeader
.biCompression
== BI_RLE8
)
1069 /* copy existing bitmap from destination dc */
1070 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1071 NtGdiBitBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1072 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, ROP
, 0, 0);
1074 NtGdiStretchBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1075 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1079 pDC
= DC_LockDc(hdcMem
);
1082 /* Note BitsInfo->bmiHeader.biHeight is the number of scanline,
1083 * if it negitve we getting to many scanline for scanline is UINT not
1084 * a INT, so we need make the negtive value to positve and that make the
1085 * count correct for negtive bitmap, TODO : we need testcase for this api */
1086 IntSetDIBits(pDC
, hBitmap
, 0, abs(BitsInfo
->bmiHeader
.biHeight
), Bits
,
1093 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1094 left (negative biHeight) */
1095 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1096 NtGdiBitBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1097 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1100 NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1101 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1102 SrcWidth
, SrcHeight
, ROP
, 0);
1106 GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1109 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1111 NtGdiDeleteObjectApp(hdcMem
);
1113 GreDeleteObject(hBitmap
);
1134 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1135 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1137 if (bpp
!= 1) fColor
= TRUE
;
1138 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1141 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
1143 const RGBQUAD
*rgb
= data
->bmiColors
;
1144 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1146 // Check if the first color of the colormap is black
1147 if ((col
== RGB(0, 0, 0)))
1150 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1152 // If the second color is white, create a monochrome bitmap
1153 fColor
= (col
!= RGB(0xff,0xff,0xff));
1157 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1159 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
1160 DWORD col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1162 if ((col
== RGB(0,0,0)))
1165 col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1166 fColor
= (col
!= RGB(0xff,0xff,0xff));
1172 DPRINT("(%ld): wrong size for data\n", data
->bmiHeader
.biSize
);
1177 // Now create the bitmap
1180 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1184 handle
= IntGdiCreateBitmap(width
,
1194 if (NULL
!= handle
&& CBM_INIT
== init
)
1196 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1202 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1203 // The DDB that is created will be whatever bit depth your reference DC is
1206 NtGdiCreateDIBitmapInternal(
1211 IN OPTIONAL LPBYTE pjInit
,
1212 IN OPTIONAL LPBITMAPINFO pbmi
,
1214 IN UINT cjMaxInitInfo
,
1223 if (!hDc
) // CreateBitmap
1224 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1225 hDc
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
,FALSE
);
1228 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1232 Dc
= DC_LockDc(hDc
);
1235 NtGdiDeleteObjectApp(hDc
);
1236 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1240 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1243 NtGdiDeleteObjectApp(hDc
);
1245 else // CreateCompatibleBitmap
1247 Dc
= DC_LockDc(hDc
);
1250 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1254 First create an un-initialised bitmap. The depth of the bitmap
1255 should match that of the hdc and not that supplied in bmih.
1258 bpp
= pbmi
->bmiHeader
.biBitCount
;
1261 if (Dc
->dctype
!= DC_TYPE_MEMORY
)
1262 bpp
= IntGdiGetDeviceCaps(Dc
, BITSPIXEL
);
1267 SURFACE
*psurf
= Dc
->dclevel
.pSurface
;
1268 Count
= BITMAP_GetObject(psurf
, sizeof(dibs
), &dibs
);
1273 if (Count
== sizeof(BITMAP
))
1274 /* A device-dependent bitmap is selected in the DC */
1275 bpp
= dibs
.dsBm
.bmBitsPixel
;
1277 /* A DIB section is selected in the DC */
1278 bpp
= dibs
.dsBmih
.biBitCount
;
1282 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1291 NtGdiCreateDIBSection(
1293 IN OPTIONAL HANDLE hSection
,
1295 IN LPBITMAPINFO bmi
,
1299 IN ULONG_PTR dwColorSpace
,
1302 HBITMAP hbitmap
= 0;
1304 BOOL bDesktopDC
= FALSE
;
1306 if (!bmi
) return hbitmap
; // Make sure.
1308 // If the reference hdc is null, take the desktop dc
1311 hDC
= NtGdiCreateCompatibleDC(0);
1315 if ((dc
= DC_LockDc(hDC
)))
1317 hbitmap
= DIB_CreateDIBSection(dc
,
1328 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1332 NtGdiDeleteObjectApp(hDC
);
1339 DIB_CreateDIBSection(
1349 SURFACE
*bmp
= NULL
;
1350 void *mapBits
= NULL
;
1353 // Fill BITMAP32 structure with DIB data
1354 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1361 DWORD dsBitfields
[3] = {0};
1363 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1364 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1365 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1367 /* CreateDIBSection should fail for compressed formats */
1368 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1370 return (HBITMAP
)NULL
;
1373 pdcattr
= dc
->pdcattr
;
1375 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1377 bm
.bmWidth
= bi
->biWidth
;
1378 bm
.bmHeight
= effHeight
;
1379 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1381 bm
.bmPlanes
= bi
->biPlanes
;
1382 bm
.bmBitsPixel
= bi
->biBitCount
;
1385 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1386 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1387 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1388 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1392 SYSTEM_BASIC_INFORMATION Sbi
;
1395 LARGE_INTEGER SectionOffset
;
1398 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1402 if (!NT_SUCCESS(Status
))
1407 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1408 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1410 SectionOffset
.LowPart
= mapOffset
;
1411 SectionOffset
.HighPart
= 0;
1413 Status
= ZwMapViewOfSection(section
,
1423 if (!NT_SUCCESS(Status
))
1425 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1429 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1431 else if (ovr_pitch
&& offset
)
1432 bm
.bmBits
= (LPVOID
) offset
;
1436 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1439 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1440 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1442 if (usage
== DIB_PAL_COLORS
)
1443 lpRGB
= DIB_MapPaletteColors(dc
, bmi
);
1445 lpRGB
= bmi
->bmiColors
;
1447 /* Set dsBitfields values */
1448 if (usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1450 dsBitfields
[0] = dsBitfields
[1] = dsBitfields
[2] = 0;
1452 else if (bi
->biCompression
== BI_RGB
)
1454 switch (bi
->biBitCount
)
1458 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0x7c00;
1459 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x03e0;
1460 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x001f;
1465 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0xff0000;
1466 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x00ff00;
1467 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x0000ff;
1473 dsBitfields
[0] = ((DWORD
*)bmi
->bmiColors
)[0];
1474 dsBitfields
[1] = ((DWORD
*)bmi
->bmiColors
)[1];
1475 dsBitfields
[2] = ((DWORD
*)bmi
->bmiColors
)[2];
1478 // Create Device Dependent Bitmap and add DIB pointer
1479 Size
.cx
= bm
.bmWidth
;
1480 Size
.cy
= abs(bm
.bmHeight
);
1481 res
= IntCreateBitmap(Size
,
1483 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1484 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1485 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1489 if (lpRGB
!= bmi
->bmiColors
)
1491 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1493 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1496 bmp
= SURFACE_LockSurface(res
);
1499 if (lpRGB
!= bmi
->bmiColors
)
1501 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1503 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1504 GreDeleteObject(bmp
);
1508 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1509 table between the DIB and the X physical device. Obviously,
1510 this is left out of the ReactOS implementation. Instead,
1511 we call NtGdiSetDIBColorTable. */
1513 /* set number of entries in bmi.bmiColors table */
1514 if (bi
->biBitCount
== 1) {
1517 if (bi
->biBitCount
== 4) {
1520 if (bi
->biBitCount
== 8) {
1521 bi
->biClrUsed
= 256;
1524 bmp
->hDIBSection
= section
;
1525 bmp
->hSecure
= hSecure
;
1526 bmp
->dwOffset
= offset
;
1527 bmp
->flFlags
= BITMAPOBJ_IS_APIBITMAP
;
1528 bmp
->dsBitfields
[0] = dsBitfields
[0];
1529 bmp
->dsBitfields
[1] = dsBitfields
[1];
1530 bmp
->dsBitfields
[2] = dsBitfields
[2];
1531 bmp
->biClrUsed
= bi
->biClrUsed
;
1532 bmp
->biClrImportant
= bi
->biClrImportant
;
1534 if (bi
->biClrUsed
!= 0)
1535 bmp
->hDIBPalette
= PALETTE_AllocPaletteIndexedRGB(bi
->biClrUsed
, lpRGB
);
1537 bmp
->hDIBPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1542 // Clean up in case of errors
1543 if (!res
|| !bmp
|| !bm
.bmBits
)
1545 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1548 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1551 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1556 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1564 SURFACE_FreeSurfaceByHandle(res
);
1569 if (lpRGB
!= bmi
->bmiColors
)
1571 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1576 SURFACE_UnlockSurface(bmp
);
1579 // Return BITMAP handle and storage location
1580 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1585 if (res
) pdcattr
->ulDirty_
|= DC_DIBSECTION
;
1590 /***********************************************************************
1591 * DIB_GetDIBWidthBytes
1593 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1594 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1595 * 11/16/1999 (RJJ) lifted from wine
1597 INT FASTCALL
DIB_GetDIBWidthBytes(INT width
, INT depth
)
1599 return ((width
* depth
+ 31) & ~31) >> 3;
1602 /***********************************************************************
1603 * DIB_GetDIBImageBytes
1605 * Return the number of bytes used to hold the image in a DIB bitmap.
1606 * 11/16/1999 (RJJ) lifted from wine
1609 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1611 return DIB_GetDIBWidthBytes(width
, depth
) * (height
< 0 ? -height
: height
);
1614 /***********************************************************************
1615 * DIB_BitmapInfoSize
1617 * Return the size of the bitmap info structure including color table.
1618 * 11/16/1999 (RJJ) lifted from wine
1621 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1625 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1627 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1628 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1629 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1631 else /* assume BITMAPINFOHEADER */
1633 colors
= info
->bmiHeader
.biClrUsed
;
1634 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1635 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1641 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1648 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1655 if (palGDI
->Mode
!= PAL_INDEXED
)
1657 PALETTE_UnlockPalette(palGDI
);
1661 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1662 if (lpbmi
->bmiHeader
.biClrUsed
)
1664 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1667 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1670 PALETTE_UnlockPalette(palGDI
);
1674 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1676 for (i
= 0; i
< nNumColors
; i
++)
1678 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1679 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1680 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1681 lpRGB
[i
].rgbReserved
= 0;
1684 PALETTE_UnlockPalette(palGDI
);
1691 BuildDIBPalette(CONST BITMAPINFO
*bmi
, PINT paletteType
)
1695 PALETTEENTRY
*palEntries
= NULL
;
1697 ULONG RedMask
, GreenMask
, BlueMask
;
1699 // Determine Bits Per Pixel
1700 bits
= bmi
->bmiHeader
.biBitCount
;
1702 // Determine paletteType from Bits Per Pixel
1705 *paletteType
= PAL_INDEXED
;
1706 RedMask
= GreenMask
= BlueMask
= 0;
1708 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1710 *paletteType
= PAL_BITFIELDS
;
1711 RedMask
= ((ULONG
*)bmi
->bmiColors
)[0];
1712 GreenMask
= ((ULONG
*)bmi
->bmiColors
)[1];
1713 BlueMask
= ((ULONG
*)bmi
->bmiColors
)[2];
1717 *paletteType
= PAL_BITFIELDS
;
1724 *paletteType
= PAL_BGR
;
1726 GreenMask
= 0x00ff00;
1727 BlueMask
= 0x0000ff;
1730 if (bmi
->bmiHeader
.biClrUsed
== 0)
1732 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1736 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1739 if (PAL_INDEXED
== *paletteType
)
1741 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)bmi
->bmiColors
);
1745 hPal
= PALETTE_AllocPalette(*paletteType
, ColorCount
,
1746 (ULONG
*) palEntries
,
1747 RedMask
, GreenMask
, BlueMask
);