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
;
152 UINT Index
, Count
= 0;
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;
202 PALETTE_UnlockPalette(PalGDI
);
210 // Converts a DIB to a device-dependent bitmap
219 CONST BITMAPINFO
*bmi
,
223 HBITMAP SourceBitmap
;
226 SURFOBJ
*DestSurf
, *SourceSurf
;
231 PPALETTE ppalDDB
, ppalDIB
;
233 HPALETTE DDB_Palette
, DIB_Palette
;
234 ULONG DIB_Palette_Type
;
238 if (!(bitmap
= SURFACE_LockSurface(hBitmap
)))
244 //if (ColorUse == DIB_PAL_COLORS)
245 // lpRGB = DIB_MapPaletteColors(hDC, bmi);
247 // lpRGB = &bmi->bmiColors;
249 DestSurf
= &bitmap
->SurfObj
;
251 // Create source surface
252 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
253 SourceSize
.cy
= ScanLines
;
255 // Determine width of DIB
256 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
258 SourceBitmap
= EngCreateBitmap(SourceSize
,
260 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
261 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
263 if (0 == SourceBitmap
)
265 SURFACE_UnlockSurface(bitmap
);
266 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
270 SourceSurf
= EngLockSurface((HSURF
)SourceBitmap
);
271 if (NULL
== SourceSurf
)
273 EngDeleteSurface((HSURF
)SourceBitmap
);
274 SURFACE_UnlockSurface(bitmap
);
275 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
279 // Use hDIBPalette if it exists
280 if (bitmap
->hDIBPalette
)
282 DDB_Palette
= bitmap
->hDIBPalette
;
286 // Destination palette obtained from the hDC
287 DDB_Palette
= DC
->ppdev
->devinfo
.hpalDefault
;
290 ppalDDB
= PALETTE_LockPalette(DDB_Palette
);
293 EngUnlockSurface(SourceSurf
);
294 EngDeleteSurface((HSURF
)SourceBitmap
);
295 SURFACE_UnlockSurface(bitmap
);
296 SetLastWin32Error(ERROR_INVALID_HANDLE
);
300 // Source palette obtained from the BITMAPINFO
301 DIB_Palette
= BuildDIBPalette((PBITMAPINFO
)bmi
, (PINT
)&DIB_Palette_Type
);
302 if (NULL
== DIB_Palette
)
304 EngUnlockSurface(SourceSurf
);
305 EngDeleteSurface((HSURF
)SourceBitmap
);
306 SURFACE_UnlockSurface(bitmap
);
307 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
311 ppalDIB
= PALETTE_LockPalette(DIB_Palette
);
313 /* Initialize XLATEOBJ for color translation */
314 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
320 // Determine destination rectangle
322 DestRect
.top
= abs(bmi
->bmiHeader
.biHeight
) - StartScan
- ScanLines
;
323 DestRect
.right
= SourceSize
.cx
;
324 DestRect
.bottom
= DestRect
.top
+ ScanLines
;
326 copyBitsResult
= IntEngCopyBits(DestSurf
, SourceSurf
, NULL
, &exlo
.xlo
, &DestRect
, &ZeroPoint
);
328 // If it succeeded, return number of scanlines copies
329 if (copyBitsResult
== TRUE
)
331 result
= SourceSize
.cy
;
333 // result = abs(bmi->bmiHeader.biHeight) - StartScan;
337 EXLATEOBJ_vCleanup(&exlo
);
338 PALETTE_UnlockPalette(ppalDIB
);
339 PALETTE_UnlockPalette(ppalDDB
);
340 PALETTE_FreePaletteByHandle(DIB_Palette
);
341 EngUnlockSurface(SourceSurf
);
342 EngDeleteSurface((HSURF
)SourceBitmap
);
344 // if (ColorUse == DIB_PAL_COLORS)
345 // WinFree((LPSTR)lpRGB);
347 SURFACE_UnlockSurface(bitmap
);
352 // FIXME by Removing NtGdiSetDIBits!!!
353 // This is a victim of the Win32k Initialization BUG!!!!!
354 // Converts a DIB to a device-dependent bitmap
363 CONST BITMAPINFO
*bmi
,
368 NTSTATUS Status
= STATUS_SUCCESS
;
374 { // FYI: We converted from CORE in gdi.
375 ProbeForRead(bmi
, sizeof(BITMAPINFO
), 1);
376 cjBits
= bmi
->bmiHeader
.biBitCount
* bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biWidth
;
377 cjBits
= ((cjBits
+ 31) & ~31) / 8;
379 ProbeForRead(Bits
, cjBits
, 1);
381 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
383 Status
= _SEH2_GetExceptionCode();
387 if (!NT_SUCCESS(Status
))
395 SetLastWin32Error(ERROR_INVALID_HANDLE
);
398 if (Dc
->dctype
== DC_TYPE_INFO
)
404 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
414 NtGdiSetDIBitsToDeviceInternal(
429 IN BOOL bTransformCoordinates
,
430 IN OPTIONAL HANDLE hcmXform
)
433 NTSTATUS Status
= STATUS_SUCCESS
;
435 HBITMAP hSourceBitmap
= NULL
;
436 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
443 PPALETTE ppalDDB
= NULL
, ppalDIB
= NULL
;
444 HPALETTE hpalDDB
, hpalDIB
= NULL
;
445 ULONG DIBPaletteType
;
451 ProbeForRead(bmi
, cjMaxInfo
, 1);
452 ProbeForRead(Bits
, cjMaxBits
, 1);
454 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
456 Status
= _SEH2_GetExceptionCode();
460 if (!NT_SUCCESS(Status
))
465 pDC
= DC_LockDc(hDC
);
468 SetLastWin32Error(ERROR_INVALID_HANDLE
);
471 if (pDC
->dctype
== DC_TYPE_INFO
)
477 /* Use destination palette obtained from the DC by default */
478 hpalDDB
= pDC
->ppdev
->devinfo
.hpalDefault
;
480 /* Try to use hDIBPalette if it exists */
481 pSurf
= pDC
->dclevel
.pSurface
;
482 if (pSurf
&& pSurf
->hDIBPalette
)
484 hpalDDB
= pSurf
->hDIBPalette
;
487 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
489 ScanLines
= min(ScanLines
, abs(bmi
->bmiHeader
.biHeight
) - StartScan
);
493 if (bTransformCoordinates
)
495 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
497 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
498 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
499 rcDest
.right
= rcDest
.left
+ Width
;
500 rcDest
.bottom
= rcDest
.top
+ Height
;
501 rcDest
.top
+= StartScan
;
506 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
507 SourceSize
.cy
= ScanLines
;
509 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
511 hSourceBitmap
= EngCreateBitmap(SourceSize
,
513 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
514 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
518 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
519 Status
= STATUS_NO_MEMORY
;
523 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
526 Status
= STATUS_UNSUCCESSFUL
;
530 /* Obtain destination palette */
531 ppalDDB
= PALETTE_LockPalette(hpalDDB
);
534 SetLastWin32Error(ERROR_INVALID_HANDLE
);
535 Status
= STATUS_UNSUCCESSFUL
;
539 /* Create a palette for the DIB */
540 hpalDIB
= BuildDIBPalette(bmi
, (PINT
)&DIBPaletteType
);
543 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
544 Status
= STATUS_NO_MEMORY
;
548 /* Lock the DIB palette */
549 ppalDIB
= PALETTE_LockPalette(hpalDIB
);
552 SetLastWin32Error(ERROR_INVALID_HANDLE
);
553 Status
= STATUS_UNSUCCESSFUL
;
557 /* Initialize EXLATEOBJ */
558 EXLATEOBJ_vInitialize(&exlo
, ppalDIB
, ppalDDB
, 0, 0, 0);
561 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
562 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
563 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
564 Status
= IntEngBitBlt(pDestSurf
,
567 pDC
->rosdc
.CombinedClip
,
574 ROP3_TO_ROP4(SRCCOPY
));
576 /* Cleanup EXLATEOBJ */
577 EXLATEOBJ_vCleanup(&exlo
);
580 if (NT_SUCCESS(Status
))
585 if (ppalDIB
) PALETTE_UnlockPalette(ppalDIB
);
586 if (ppalDDB
) PALETTE_UnlockPalette(ppalDDB
);
588 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
589 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
590 if (hpalDIB
) PALETTE_FreePaletteByHandle(hpalDIB
);
597 /* Converts a device-dependent bitmap to a DIB */
600 NtGdiGetDIBitsInternal(
612 SURFACE
*psurf
= NULL
;
613 HBITMAP hDestBitmap
= NULL
;
614 HPALETTE hSourcePalette
= NULL
;
615 HPALETTE hDestPalette
= NULL
;
616 PPALETTE ppalSrc
= NULL
;
617 PPALETTE ppalDst
= NULL
;
618 NTSTATUS Status
= STATUS_SUCCESS
;
620 BOOL bPaletteMatch
= FALSE
;
621 PBYTE ChkBits
= Bits
;
624 ULONG DestPaletteType
;
627 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
629 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
632 // if ScanLines == 0, no need to copy Bits.
638 ProbeForRead(&Info
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
640 ProbeForWrite(Info
, Info
->bmiHeader
.biSize
, 1); // Comp for Core.
641 if (ChkBits
) ProbeForWrite(ChkBits
, MaxBits
, 1);
643 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
645 Status
= _SEH2_GetExceptionCode();
649 if (!NT_SUCCESS(Status
))
655 if (Dc
== NULL
) return 0;
656 if (Dc
->dctype
== DC_TYPE_INFO
)
663 /* Get a pointer to the source bitmap object */
664 psurf
= SURFACE_LockSurface(hBitmap
);
668 hSourcePalette
= psurf
->hDIBPalette
;
671 hSourcePalette
= pPrimarySurface
->devinfo
.hpalDefault
;
674 ColorPtr
= ((PBYTE
)Info
+ Info
->bmiHeader
.biSize
);
675 rgbQuads
= (RGBQUAD
*)ColorPtr
;
677 /* Copy palette information
678 * Always create a palette for 15 & 16 bit. */
679 if ((Info
->bmiHeader
.biBitCount
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) &&
680 Info
->bmiHeader
.biBitCount
!= 15 && Info
->bmiHeader
.biBitCount
!= 16) ||
683 hDestPalette
= hSourcePalette
;
684 bPaletteMatch
= TRUE
;
687 hDestPalette
= BuildDIBPalette(Info
, (PINT
)&DestPaletteType
); //hDestPalette = Dc->DevInfo->hpalDefault;
689 ppalSrc
= PALETTE_LockPalette(hSourcePalette
);
690 /* FIXME - ppalSrc can be NULL!!! Don't assert here! */
695 ppalDst
= PALETTE_LockPalette(hDestPalette
);
696 /* FIXME - ppalDst can be NULL!!!! Don't assert here!!! */
697 DPRINT("ppalDst : %p\n", ppalDst
);
706 /* FIXME: This is largely incomplete. ATM no Core!*/
707 switch (Info
->bmiHeader
.biBitCount
)
712 Info
->bmiHeader
.biClrUsed
= 0;
713 if (psurf
->hSecure
&&
714 BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == Info
->bmiHeader
.biBitCount
)
716 if (Usage
== DIB_RGB_COLORS
)
718 if (ppalDst
->NumColors
!= 1 << Info
->bmiHeader
.biBitCount
)
719 Info
->bmiHeader
.biClrUsed
= ppalDst
->NumColors
;
721 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
724 rgbQuads
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
725 rgbQuads
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
726 rgbQuads
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
727 rgbQuads
[Index
].rgbReserved
= 0;
732 PWORD Ptr
= ColorPtr
;
734 Index
< (1 << Info
->bmiHeader
.biBitCount
);
737 Ptr
[Index
] = (WORD
)Index
;
743 if (Usage
== DIB_PAL_COLORS
)
745 PWORD Ptr
= ColorPtr
;
747 Index
< (1 << Info
->bmiHeader
.biBitCount
);
750 Ptr
[Index
] = (WORD
)Index
;
753 else if (Info
->bmiHeader
.biBitCount
> 1 && bPaletteMatch
)
756 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< ppalDst
->NumColors
;
759 Info
->bmiColors
[Index
].rgbRed
= ppalDst
->IndexedColors
[Index
].peRed
;
760 Info
->bmiColors
[Index
].rgbGreen
= ppalDst
->IndexedColors
[Index
].peGreen
;
761 Info
->bmiColors
[Index
].rgbBlue
= ppalDst
->IndexedColors
[Index
].peBlue
;
762 Info
->bmiColors
[Index
].rgbReserved
= 0;
767 switch (Info
->bmiHeader
.biBitCount
)
770 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
= rgbQuads
[0].rgbBlue
= 0;
771 rgbQuads
[0].rgbReserved
= 0;
772 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
= rgbQuads
[1].rgbBlue
= 0xff;
773 rgbQuads
[1].rgbReserved
= 0;
776 RtlCopyMemory(ColorPtr
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
783 RtlCopyMemory(rgbQuads
, DefLogPaletteQuads
, 10 * sizeof(RGBQUAD
));
784 RtlCopyMemory(rgbQuads
+ 246, DefLogPaletteQuads
+ 10, 10 * sizeof(RGBQUAD
));
785 color
= rgbQuads
+ 10;
786 for (r
= 0; r
<= 5; r
++) /* FIXME */
787 for (g
= 0; g
<= 5; g
++)
788 for (b
= 0; b
<= 5; b
++)
790 color
->rgbRed
= (r
* 0xff) / 5;
791 color
->rgbGreen
= (g
* 0xff) / 5;
792 color
->rgbBlue
= (b
* 0xff) / 5;
793 color
->rgbReserved
= 0;
803 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
805 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
806 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
807 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
812 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
814 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
815 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
816 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
822 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
824 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
825 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
826 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
832 PALETTE_UnlockPalette(ppalDst
);
834 /* fill out the BITMAPINFO struct */
836 { // Core or not to Core? We have converted from Core in Gdi~ so?
837 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
839 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
840 coreheader
->bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
841 coreheader
->bcPlanes
= 1;
842 coreheader
->bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
843 coreheader
->bcHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
844 if (psurf
->SurfObj
.lDelta
> 0)
845 coreheader
->bcHeight
= -coreheader
->bcHeight
;
848 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
850 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
851 Info
->bmiHeader
.biHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
852 Info
->bmiHeader
.biPlanes
= 1;
853 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
854 switch (psurf
->SurfObj
.iBitmapFormat
)
856 /* FIXME: What about BI_BITFIELDS? */
863 Info
->bmiHeader
.biCompression
= BI_RGB
;
866 Info
->bmiHeader
.biCompression
= BI_RLE4
;
869 Info
->bmiHeader
.biCompression
= BI_RLE8
;
872 Info
->bmiHeader
.biCompression
= BI_JPEG
;
875 Info
->bmiHeader
.biCompression
= BI_PNG
;
878 /* Image size has to be calculated */
879 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(Info
->bmiHeader
.biWidth
,
880 Info
->bmiHeader
.biBitCount
) * Info
->bmiHeader
.biHeight
;
881 Info
->bmiHeader
.biXPelsPerMeter
= 0; /* FIXME */
882 Info
->bmiHeader
.biYPelsPerMeter
= 0; /* FIXME */
883 Info
->bmiHeader
.biClrUsed
= 0;
884 Info
->bmiHeader
.biClrImportant
= 1 << Info
->bmiHeader
.biBitCount
; /* FIXME */
885 /* Report negtive height for top-down bitmaps. */
886 if (psurf
->SurfObj
.lDelta
> 0)
887 Info
->bmiHeader
.biHeight
= -Info
->bmiHeader
.biHeight
;
889 Result
= psurf
->SurfObj
.sizlBitmap
.cy
;
897 // If we have a good dib pointer, why not just copy bits from there w/o XLATE'ing them.
899 /* Create the destination bitmap too for the copy operation */
900 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
906 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
907 DestSize
.cx
= psurf
->SurfObj
.sizlBitmap
.cx
;
908 DestSize
.cy
= ScanLines
;
912 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
914 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
915 hDestBitmap
= EngCreateBitmap(DestSize
,
916 DIB_GetDIBWidthBytes(DestSize
.cx
, coreheader
->bcBitCount
),
917 BitmapFormat(coreheader
->bcBitCount
, BI_RGB
),
918 0 < coreheader
->bcHeight
? 0 : BMF_TOPDOWN
,
922 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
924 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(DestSize
.cx
,
925 Info
->bmiHeader
.biBitCount
) * DestSize
.cy
;
927 hDestBitmap
= EngCreateBitmap(DestSize
,
928 DIB_GetDIBWidthBytes(DestSize
.cx
, Info
->bmiHeader
.biBitCount
),
929 BitmapFormat(Info
->bmiHeader
.biBitCount
, Info
->bmiHeader
.biCompression
),
930 0 < Info
->bmiHeader
.biHeight
? 0 : BMF_TOPDOWN
,
934 if (hDestBitmap
== NULL
)
938 if (NT_SUCCESS(Status
))
941 SURFOBJ
*DestSurfObj
;
944 EXLATEOBJ_vInitialize(&exlo
, ppalSrc
, ppalDst
, 0, 0, 0);
947 SourcePoint
.y
= psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
);
949 /* Determine destination rectangle */
952 DestRect
.right
= DestSize
.cx
;
953 DestRect
.bottom
= DestSize
.cy
;
955 DestSurfObj
= EngLockSurface((HSURF
)hDestBitmap
);
957 if (IntEngCopyBits(DestSurfObj
,
964 DPRINT("GetDIBits %d \n",abs(Info
->bmiHeader
.biHeight
) - StartScan
);
968 EXLATEOBJ_vCleanup(&exlo
);
969 EngUnlockSurface(DestSurfObj
);
973 PALETTE_UnlockPalette(ppalSrc
);
975 if (hDestBitmap
!= NULL
)
976 EngDeleteSurface((HSURF
)hDestBitmap
);
978 if (hDestPalette
!= NULL
&& bPaletteMatch
== FALSE
)
979 PALETTE_FreePaletteByHandle(hDestPalette
);
981 SURFACE_UnlockSurface(psurf
);
983 DPRINT("leaving NtGdiGetDIBitsInternal\n");
990 NtGdiStretchDIBitsInternal(
1001 LPBITMAPINFO BitsInfo
,
1008 HBITMAP hBitmap
, hOldBitmap
= NULL
;
1010 HPALETTE hPal
= NULL
;
1014 if (!Bits
|| !BitsInfo
)
1016 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1022 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1023 ProbeForRead(Bits
, cjMaxBits
, 1);
1025 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1033 DPRINT1("NtGdiStretchDIBitsInternal fail to read BitMapInfo: %x or Bits: %x\n",BitsInfo
,Bits
);
1037 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1040 DPRINT1("NtGdiCreateCompatibleDC fail create hdc\n");
1044 hBitmap
= NtGdiCreateCompatibleBitmap(hDC
,
1045 abs(BitsInfo
->bmiHeader
.biWidth
),
1046 abs(BitsInfo
->bmiHeader
.biHeight
));
1047 if (hBitmap
== NULL
)
1049 DPRINT1("NtGdiCreateCompatibleBitmap fail create bitmap\n");
1050 DPRINT1("hDC : 0x%08x \n", hDC
);
1051 DPRINT1("BitsInfo->bmiHeader.biWidth : 0x%08x \n", BitsInfo
->bmiHeader
.biWidth
);
1052 DPRINT1("BitsInfo->bmiHeader.biHeight : 0x%08x \n", BitsInfo
->bmiHeader
.biHeight
);
1056 /* Select the bitmap into hdcMem, and save a handle to the old bitmap */
1057 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1059 if (Usage
== DIB_PAL_COLORS
)
1061 hPal
= NtGdiGetDCObject(hDC
, GDI_OBJECT_TYPE_PALETTE
);
1062 hPal
= GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1065 if (BitsInfo
->bmiHeader
.biCompression
== BI_RLE4
||
1066 BitsInfo
->bmiHeader
.biCompression
== BI_RLE8
)
1068 /* copy existing bitmap from destination dc */
1069 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1070 NtGdiBitBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1071 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, ROP
, 0, 0);
1073 NtGdiStretchBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1074 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1078 pDC
= DC_LockDc(hdcMem
);
1081 /* Note BitsInfo->bmiHeader.biHeight is the number of scanline,
1082 * if it negitve we getting to many scanline for scanline is UINT not
1083 * a INT, so we need make the negtive value to positve and that make the
1084 * count correct for negtive bitmap, TODO : we need testcase for this api */
1085 IntSetDIBits(pDC
, hBitmap
, 0, abs(BitsInfo
->bmiHeader
.biHeight
), Bits
,
1092 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1093 left (negative biHeight) */
1094 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1095 NtGdiBitBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1096 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1099 NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1100 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1101 SrcWidth
, SrcHeight
, ROP
, 0);
1105 GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1108 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1110 NtGdiDeleteObjectApp(hdcMem
);
1112 GreDeleteObject(hBitmap
);
1133 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1134 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1136 if (bpp
!= 1) fColor
= TRUE
;
1137 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1140 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
1142 const RGBQUAD
*rgb
= data
->bmiColors
;
1143 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1145 // Check if the first color of the colormap is black
1146 if ((col
== RGB(0, 0, 0)))
1149 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1151 // If the second color is white, create a monochrome bitmap
1152 fColor
= (col
!= RGB(0xff,0xff,0xff));
1156 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1158 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
1159 DWORD col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1161 if ((col
== RGB(0,0,0)))
1164 col
= RGB(rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1165 fColor
= (col
!= RGB(0xff,0xff,0xff));
1171 DPRINT("(%ld): wrong size for data\n", data
->bmiHeader
.biSize
);
1176 // Now create the bitmap
1179 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1183 handle
= IntGdiCreateBitmap(width
,
1193 if (NULL
!= handle
&& CBM_INIT
== init
)
1195 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1201 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1202 // The DDB that is created will be whatever bit depth your reference DC is
1205 NtGdiCreateDIBitmapInternal(
1210 IN OPTIONAL LPBYTE pjInit
,
1211 IN OPTIONAL LPBITMAPINFO pbmi
,
1213 IN UINT cjMaxInitInfo
,
1222 if (!hDc
) // CreateBitmap
1223 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1224 hDc
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
,FALSE
);
1227 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1231 Dc
= DC_LockDc(hDc
);
1234 NtGdiDeleteObjectApp(hDc
);
1235 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1239 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1242 NtGdiDeleteObjectApp(hDc
);
1244 else // CreateCompatibleBitmap
1246 Dc
= DC_LockDc(hDc
);
1249 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1253 First create an un-initialised bitmap. The depth of the bitmap
1254 should match that of the hdc and not that supplied in bmih.
1257 bpp
= pbmi
->bmiHeader
.biBitCount
;
1260 if (Dc
->dctype
!= DC_TYPE_MEMORY
)
1261 bpp
= IntGdiGetDeviceCaps(Dc
, BITSPIXEL
);
1266 SURFACE
*psurf
= Dc
->dclevel
.pSurface
;
1267 Count
= BITMAP_GetObject(psurf
, sizeof(dibs
), &dibs
);
1272 if (Count
== sizeof(BITMAP
))
1273 /* A device-dependent bitmap is selected in the DC */
1274 bpp
= dibs
.dsBm
.bmBitsPixel
;
1276 /* A DIB section is selected in the DC */
1277 bpp
= dibs
.dsBmih
.biBitCount
;
1281 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1290 NtGdiCreateDIBSection(
1292 IN OPTIONAL HANDLE hSection
,
1294 IN LPBITMAPINFO bmi
,
1298 IN ULONG_PTR dwColorSpace
,
1301 HBITMAP hbitmap
= 0;
1303 BOOL bDesktopDC
= FALSE
;
1305 if (!bmi
) return hbitmap
; // Make sure.
1307 // If the reference hdc is null, take the desktop dc
1310 hDC
= NtGdiCreateCompatibleDC(0);
1314 if ((dc
= DC_LockDc(hDC
)))
1316 hbitmap
= DIB_CreateDIBSection(dc
,
1327 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1331 NtGdiDeleteObjectApp(hDC
);
1338 DIB_CreateDIBSection(
1348 SURFACE
*bmp
= NULL
;
1349 void *mapBits
= NULL
;
1352 // Fill BITMAP32 structure with DIB data
1353 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1360 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
)
1444 lpRGB
= DIB_MapPaletteColors(dc
, bmi
);
1445 ColorCount
= bi
->biClrUsed
;
1446 if (ColorCount
== 0)
1448 ColorCount
= 1 << bi
->biBitCount
;
1453 lpRGB
= bmi
->bmiColors
;
1454 ColorCount
= 1 << bi
->biBitCount
;
1457 /* Set dsBitfields values */
1458 if (usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1460 dsBitfields
[0] = dsBitfields
[1] = dsBitfields
[2] = 0;
1462 else if (bi
->biCompression
== BI_RGB
)
1464 switch (bi
->biBitCount
)
1468 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0x7c00;
1469 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x03e0;
1470 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x001f;
1475 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0xff0000;
1476 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x00ff00;
1477 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x0000ff;
1483 dsBitfields
[0] = ((DWORD
*)bmi
->bmiColors
)[0];
1484 dsBitfields
[1] = ((DWORD
*)bmi
->bmiColors
)[1];
1485 dsBitfields
[2] = ((DWORD
*)bmi
->bmiColors
)[2];
1488 // Create Device Dependent Bitmap and add DIB pointer
1489 Size
.cx
= bm
.bmWidth
;
1490 Size
.cy
= abs(bm
.bmHeight
);
1491 res
= IntCreateBitmap(Size
,
1493 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1494 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1495 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1499 if (lpRGB
!= bmi
->bmiColors
)
1501 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1503 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1506 bmp
= SURFACE_LockSurface(res
);
1509 if (lpRGB
!= bmi
->bmiColors
)
1511 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1513 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1514 GreDeleteObject(bmp
);
1518 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1519 table between the DIB and the X physical device. Obviously,
1520 this is left out of the ReactOS implementation. Instead,
1521 we call NtGdiSetDIBColorTable. */
1522 if (bi
->biBitCount
<= 8)
1524 bi
->biClrUsed
= 1 << bi
->biBitCount
;
1531 bmp
->hDIBSection
= section
;
1532 bmp
->hSecure
= hSecure
;
1533 bmp
->dwOffset
= offset
;
1534 bmp
->flFlags
= BITMAPOBJ_IS_APIBITMAP
;
1535 bmp
->dsBitfields
[0] = dsBitfields
[0];
1536 bmp
->dsBitfields
[1] = dsBitfields
[1];
1537 bmp
->dsBitfields
[2] = dsBitfields
[2];
1538 bmp
->biClrUsed
= bi
->biClrUsed
;
1539 bmp
->biClrImportant
= bi
->biClrImportant
;
1541 if (bi
->biClrUsed
!= 0)
1543 bmp
->hDIBPalette
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, lpRGB
);
1547 bmp
->hDIBPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1553 // Clean up in case of errors
1554 if (!res
|| !bmp
|| !bm
.bmBits
)
1556 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1559 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1562 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1567 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1575 SURFACE_FreeSurfaceByHandle(res
);
1580 if (lpRGB
!= bmi
->bmiColors
)
1582 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1587 SURFACE_UnlockSurface(bmp
);
1590 // Return BITMAP handle and storage location
1591 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1596 if (res
) pdcattr
->ulDirty_
|= DC_DIBSECTION
;
1601 /***********************************************************************
1602 * DIB_GetDIBWidthBytes
1604 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1605 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1606 * 11/16/1999 (RJJ) lifted from wine
1608 INT FASTCALL
DIB_GetDIBWidthBytes(INT width
, INT depth
)
1610 return ((width
* depth
+ 31) & ~31) >> 3;
1613 /***********************************************************************
1614 * DIB_GetDIBImageBytes
1616 * Return the number of bytes used to hold the image in a DIB bitmap.
1617 * 11/16/1999 (RJJ) lifted from wine
1620 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1622 return DIB_GetDIBWidthBytes(width
, depth
) * (height
< 0 ? -height
: height
);
1625 /***********************************************************************
1626 * DIB_BitmapInfoSize
1628 * Return the size of the bitmap info structure including color table.
1629 * 11/16/1999 (RJJ) lifted from wine
1632 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1636 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1638 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1639 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1640 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1642 else /* assume BITMAPINFOHEADER */
1644 colors
= info
->bmiHeader
.biClrUsed
;
1645 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1646 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1652 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1659 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
1666 if (palGDI
->Mode
!= PAL_INDEXED
)
1668 PALETTE_UnlockPalette(palGDI
);
1672 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1673 if (lpbmi
->bmiHeader
.biClrUsed
)
1675 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1678 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1681 PALETTE_UnlockPalette(palGDI
);
1685 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1687 for (i
= 0; i
< nNumColors
; i
++)
1689 if (*lpIndex
< palGDI
->NumColors
)
1691 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1692 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1693 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1697 lpRGB
[i
].rgbRed
= 0;
1698 lpRGB
[i
].rgbGreen
= 0;
1699 lpRGB
[i
].rgbBlue
= 0;
1701 lpRGB
[i
].rgbReserved
= 0;
1704 PALETTE_UnlockPalette(palGDI
);
1711 BuildDIBPalette(CONST BITMAPINFO
*bmi
, PINT paletteType
)
1715 PALETTEENTRY
*palEntries
= NULL
;
1717 ULONG RedMask
, GreenMask
, BlueMask
;
1719 // Determine Bits Per Pixel
1720 bits
= bmi
->bmiHeader
.biBitCount
;
1722 // Determine paletteType from Bits Per Pixel
1725 *paletteType
= PAL_INDEXED
;
1726 RedMask
= GreenMask
= BlueMask
= 0;
1728 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1730 *paletteType
= PAL_BITFIELDS
;
1731 RedMask
= ((ULONG
*)bmi
->bmiColors
)[0];
1732 GreenMask
= ((ULONG
*)bmi
->bmiColors
)[1];
1733 BlueMask
= ((ULONG
*)bmi
->bmiColors
)[2];
1737 *paletteType
= PAL_BITFIELDS
;
1744 *paletteType
= PAL_BGR
;
1746 GreenMask
= 0x00ff00;
1747 BlueMask
= 0x0000ff;
1750 if (bmi
->bmiHeader
.biClrUsed
== 0)
1752 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1756 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1759 if (PAL_INDEXED
== *paletteType
)
1761 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)bmi
->bmiColors
);
1765 hPal
= PALETTE_AllocPalette(*paletteType
, ColorCount
,
1766 (ULONG
*) palEntries
,
1767 RedMask
, GreenMask
, BlueMask
);