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 }
73 IntSetDIBColorTable(HDC hDC
, UINT StartIndex
, UINT Entries
, CONST RGBQUAD
*Colors
)
81 if (!(dc
= DC_LockDc(hDC
))) return 0;
82 if (dc
->DC_Type
== DC_TYPE_INFO
)
88 psurf
= SURFACE_LockSurface(dc
->w
.hBitmap
);
92 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
96 if (psurf
->hSecure
== NULL
)
98 SURFACE_UnlockSurface(psurf
);
100 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
104 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
105 if (biBitCount
<= 8 && StartIndex
< (1 << biBitCount
))
107 if (StartIndex
+ Entries
> (1 << biBitCount
))
108 Entries
= (1 << biBitCount
) - StartIndex
;
110 PalGDI
= PALETTE_LockPalette(psurf
->hDIBPalette
);
113 SURFACE_UnlockSurface(psurf
);
115 SetLastWin32Error(ERROR_INVALID_HANDLE
);
119 for (Index
= StartIndex
;
120 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
123 PalGDI
->IndexedColors
[Index
].peRed
= Colors
[Index
- StartIndex
].rgbRed
;
124 PalGDI
->IndexedColors
[Index
].peGreen
= Colors
[Index
- StartIndex
].rgbGreen
;
125 PalGDI
->IndexedColors
[Index
].peBlue
= Colors
[Index
- StartIndex
].rgbBlue
;
127 PALETTE_UnlockPalette(PalGDI
);
132 SURFACE_UnlockSurface(psurf
);
139 IntGetDIBColorTable(HDC hDC
, UINT StartIndex
, UINT Entries
, RGBQUAD
*Colors
)
147 if (!(dc
= DC_LockDc(hDC
))) return 0;
148 if (dc
->DC_Type
== DC_TYPE_INFO
)
154 psurf
= SURFACE_LockSurface(dc
->w
.hBitmap
);
158 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
162 if (psurf
->hSecure
== NULL
)
164 SURFACE_UnlockSurface(psurf
);
166 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
170 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
171 if (biBitCount
<= 8 &&
172 StartIndex
< (1 << biBitCount
))
174 if (StartIndex
+ Entries
> (1 << biBitCount
))
175 Entries
= (1 << biBitCount
) - StartIndex
;
177 PalGDI
= PALETTE_LockPalette(psurf
->hDIBPalette
);
180 SURFACE_UnlockSurface(psurf
);
182 SetLastWin32Error(ERROR_INVALID_HANDLE
);
186 for (Index
= StartIndex
;
187 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
190 Colors
[Index
- StartIndex
].rgbRed
= PalGDI
->IndexedColors
[Index
].peRed
;
191 Colors
[Index
- StartIndex
].rgbGreen
= PalGDI
->IndexedColors
[Index
].peGreen
;
192 Colors
[Index
- StartIndex
].rgbBlue
= PalGDI
->IndexedColors
[Index
].peBlue
;
193 Colors
[Index
- StartIndex
].rgbReserved
= 0;
195 PALETTE_UnlockPalette(PalGDI
);
200 SURFACE_UnlockSurface(psurf
);
206 // Converts a DIB to a device-dependent bitmap
214 CONST BITMAPINFO
*bmi
,
218 HBITMAP SourceBitmap
;
221 SURFOBJ
*DestSurf
, *SourceSurf
;
228 HPALETTE DDB_Palette
, DIB_Palette
;
229 ULONG DDB_Palette_Type
, DIB_Palette_Type
;
233 if (!(bitmap
= SURFACE_LockSurface(hBitmap
)))
239 //if (ColorUse == DIB_PAL_COLORS)
240 // lpRGB = DIB_MapPaletteColors(hDC, bmi);
242 // lpRGB = &bmi->bmiColors;
244 DestSurf
= &bitmap
->SurfObj
;
246 // Create source surface
247 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
248 SourceSize
.cy
= ScanLines
;
250 // Determine width of DIB
251 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
253 SourceBitmap
= EngCreateBitmap(SourceSize
,
255 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
256 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
258 if (0 == SourceBitmap
)
260 SURFACE_UnlockSurface(bitmap
);
261 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
265 SourceSurf
= EngLockSurface((HSURF
)SourceBitmap
);
266 if (NULL
== SourceSurf
)
268 EngDeleteSurface((HSURF
)SourceBitmap
);
269 SURFACE_UnlockSurface(bitmap
);
270 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
274 // Destination palette obtained from the hDC
275 hDCPalette
= PALETTE_LockPalette(((GDIDEVICE
*)DC
->pPDev
)->DevInfo
.hpalDefault
);
276 if (NULL
== hDCPalette
)
278 EngUnlockSurface(SourceSurf
);
279 EngDeleteSurface((HSURF
)SourceBitmap
);
280 SURFACE_UnlockSurface(bitmap
);
281 SetLastWin32Error(ERROR_INVALID_HANDLE
);
284 DDB_Palette_Type
= hDCPalette
->Mode
;
285 DDB_Palette
= ((GDIDEVICE
*)DC
->pPDev
)->DevInfo
.hpalDefault
;
286 PALETTE_UnlockPalette(hDCPalette
);
288 // Source palette obtained from the BITMAPINFO
289 DIB_Palette
= BuildDIBPalette ( (PBITMAPINFO
)bmi
, (PINT
)&DIB_Palette_Type
);
290 if (NULL
== DIB_Palette
)
292 EngUnlockSurface(SourceSurf
);
293 EngDeleteSurface((HSURF
)SourceBitmap
);
294 SURFACE_UnlockSurface(bitmap
);
295 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
299 // Determine XLATEOBJ for color translation
300 XlateObj
= IntEngCreateXlate(DDB_Palette_Type
, DIB_Palette_Type
, DDB_Palette
, DIB_Palette
);
301 if (NULL
== XlateObj
)
303 PALETTE_FreePaletteByHandle(DIB_Palette
);
304 EngUnlockSurface(SourceSurf
);
305 EngDeleteSurface((HSURF
)SourceBitmap
);
306 SURFACE_UnlockSurface(bitmap
);
307 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
315 // Determine destination rectangle
317 DestRect
.top
= abs(bmi
->bmiHeader
.biHeight
) - StartScan
- ScanLines
;
318 DestRect
.right
= SourceSize
.cx
;
319 DestRect
.bottom
= DestRect
.top
+ ScanLines
;
321 copyBitsResult
= EngCopyBits(DestSurf
, SourceSurf
, NULL
, XlateObj
, &DestRect
, &ZeroPoint
);
323 // If it succeeded, return number of scanlines copies
324 if(copyBitsResult
== TRUE
)
326 result
= SourceSize
.cy
;
328 // result = abs(bmi->bmiHeader.biHeight) - StartScan;
332 EngDeleteXlate(XlateObj
);
333 PALETTE_FreePaletteByHandle(DIB_Palette
);
334 EngUnlockSurface(SourceSurf
);
335 EngDeleteSurface((HSURF
)SourceBitmap
);
337 // if (ColorUse == DIB_PAL_COLORS)
338 // WinFree((LPSTR)lpRGB);
340 SURFACE_UnlockSurface(bitmap
);
345 // FIXME by Removing NtGdiSetDIBits!!!
346 // This is a victim of the Win32k Initialization BUG!!!!!
347 // Converts a DIB to a device-dependent bitmap
355 CONST BITMAPINFO
*bmi
,
360 NTSTATUS Status
= STATUS_SUCCESS
;
366 { // FYI: We converted from CORE in gdi.
367 ProbeForRead(bmi
, sizeof(BITMAPINFO
), 1);
368 cjBits
= bmi
->bmiHeader
.biBitCount
* bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biWidth
;
369 cjBits
= ((cjBits
+ 31) & ~31 ) / 8;
371 ProbeForRead(Bits
, cjBits
, 1);
373 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
375 Status
= _SEH2_GetExceptionCode();
379 if (!NT_SUCCESS(Status
))
387 SetLastWin32Error(ERROR_INVALID_HANDLE
);
390 if (Dc
->DC_Type
== DC_TYPE_INFO
)
396 Ret
= IntSetDIBits(Dc
, hBitmap
, StartScan
, ScanLines
, Bits
, bmi
, ColorUse
);
408 NtGdiSetDIBitsToDeviceInternal(
423 IN BOOL bTransformCoordinates
,
424 IN OPTIONAL HANDLE hcmXform
428 NTSTATUS Status
= STATUS_SUCCESS
;
430 HBITMAP hSourceBitmap
= NULL
;
431 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
436 XLATEOBJ
*XlateObj
= NULL
;
438 HPALETTE DDBPalette
, DIBPalette
= NULL
;
439 ULONG DDBPaletteType
, DIBPaletteType
;
445 ProbeForRead(bmi
, cjMaxInfo
, 1);
446 ProbeForRead(Bits
, cjMaxBits
, 1);
448 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
450 Status
= _SEH2_GetExceptionCode();
454 if (!NT_SUCCESS(Status
))
459 pDC
= DC_LockDc(hDC
);
462 SetLastWin32Error(ERROR_INVALID_HANDLE
);
465 if (pDC
->DC_Type
== DC_TYPE_INFO
)
471 pDestSurf
= EngLockSurface((HSURF
)pDC
->w
.hBitmap
);
474 /* FIXME: SetLastError ? */
481 if (bTransformCoordinates
)
483 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
485 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
486 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
487 rcDest
.right
= rcDest
.left
+ Width
;
488 rcDest
.bottom
= rcDest
.top
+ Height
;
493 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
494 SourceSize
.cy
= ScanLines
; // this one --> abs(bmi->bmiHeader.biHeight) - StartScan
495 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
497 hSourceBitmap
= EngCreateBitmap(SourceSize
,
499 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
500 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
504 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
505 Status
= STATUS_NO_MEMORY
;
509 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
512 Status
= STATUS_UNSUCCESSFUL
;
516 /* Obtain destination palette from the DC */
517 pDCPalette
= PALETTE_LockPalette(((GDIDEVICE
*)pDC
->pPDev
)->DevInfo
.hpalDefault
);
520 SetLastWin32Error(ERROR_INVALID_HANDLE
);
521 Status
= STATUS_UNSUCCESSFUL
;
525 DDBPaletteType
= pDCPalette
->Mode
;
526 DDBPalette
= ((GDIDEVICE
*)pDC
->pPDev
)->DevInfo
.hpalDefault
;
527 PALETTE_UnlockPalette(pDCPalette
);
529 DIBPalette
= BuildDIBPalette(bmi
, (PINT
)&DIBPaletteType
);
532 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
533 Status
= STATUS_NO_MEMORY
;
537 /* Determine XlateObj */
538 XlateObj
= IntEngCreateXlate(DDBPaletteType
, DIBPaletteType
, DDBPalette
, DIBPalette
);
541 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
542 Status
= STATUS_NO_MEMORY
;
547 Status
= IntEngBitBlt(pDestSurf
,
557 ROP3_TO_ROP4(SRCCOPY
));
559 if (NT_SUCCESS(Status
))
561 /* FIXME: Should probably be only the number of lines actually copied */
562 ret
= ScanLines
; // this one --> abs(Info->bmiHeader.biHeight) - StartScan;
565 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
566 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
567 if (XlateObj
) EngDeleteXlate(XlateObj
);
568 if (DIBPalette
) PALETTE_FreePaletteByHandle(DIBPalette
);
569 EngUnlockSurface(pDestSurf
);
576 /* Converts a device-dependent bitmap to a DIB */
578 NtGdiGetDIBitsInternal(HDC hDC
,
589 SURFACE
*psurf
= NULL
;
590 HBITMAP hDestBitmap
= NULL
;
591 HPALETTE hSourcePalette
= NULL
;
592 HPALETTE hDestPalette
= NULL
;
593 PPALGDI SourcePalette
= NULL
;
594 PPALGDI DestPalette
= NULL
;
595 NTSTATUS Status
= STATUS_SUCCESS
;
597 BOOL bPaletteMatch
= FALSE
;
598 PBYTE ChkBits
= Bits
;
602 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
604 if ( (Usage
&& Usage
!= DIB_PAL_COLORS
) ||
609 // if ScanLines == 0, no need to copy Bits.
610 if (!ScanLines
) ChkBits
= NULL
;
614 ProbeForWrite(Info
, Info
->bmiHeader
.biSize
, 1); // Comp for Core.
615 if (ChkBits
) ProbeForWrite(ChkBits
, MaxBits
, 1);
617 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
619 Status
= _SEH2_GetExceptionCode();
623 if (!NT_SUCCESS(Status
))
629 if (Dc
== NULL
) return 0;
630 if (Dc
->DC_Type
== DC_TYPE_INFO
)
637 /* Get a pointer to the source bitmap object */
638 psurf
= SURFACE_LockSurface(hBitmap
);
642 hSourcePalette
= psurf
->hDIBPalette
;
645 hSourcePalette
= pPrimarySurface
->DevInfo
.hpalDefault
;
648 ColorPtr
= ((PBYTE
)Info
+ Info
->bmiHeader
.biSize
);
649 rgbQuads
= (RGBQUAD
*)ColorPtr
;
651 /* fill out the BITMAPINFO struct */
653 { // Core or not to Core? We have converted from Core in Gdi~ so?
654 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
656 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
657 coreheader
->bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
658 coreheader
->bcPlanes
= 1;
659 coreheader
->bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
660 coreheader
->bcHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
661 if (psurf
->SurfObj
.lDelta
> 0)
662 coreheader
->bcHeight
= -coreheader
->bcHeight
;
665 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
667 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
668 Info
->bmiHeader
.biHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
669 Info
->bmiHeader
.biPlanes
= 1;
670 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
671 switch (psurf
->SurfObj
.iBitmapFormat
)
679 Info
->bmiHeader
.biCompression
= BI_RGB
;
682 Info
->bmiHeader
.biCompression
= BI_RLE4
;
685 Info
->bmiHeader
.biCompression
= BI_RLE8
;
688 Info
->bmiHeader
.biCompression
= BI_JPEG
;
691 Info
->bmiHeader
.biCompression
= BI_PNG
;
694 /* Image size has to be calculated */
695 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(Info
->bmiHeader
.biWidth
,
696 Info
->bmiHeader
.biBitCount
) * Info
->bmiHeader
.biHeight
;
697 Info
->bmiHeader
.biXPelsPerMeter
= 0; /* FIXME */
698 Info
->bmiHeader
.biYPelsPerMeter
= 0; /* FIXME */
699 Info
->bmiHeader
.biClrUsed
= 0;
700 Info
->bmiHeader
.biClrImportant
= 1 << Info
->bmiHeader
.biBitCount
; /* FIXME */
701 /* Report negtive height for top-down bitmaps. */
702 if (psurf
->SurfObj
.lDelta
> 0)
703 Info
->bmiHeader
.biHeight
= -Info
->bmiHeader
.biHeight
;
705 Result
= psurf
->SurfObj
.sizlBitmap
.cy
;
710 ULONG SourcePaletteType
= 0;
711 ULONG DestPaletteType
;
715 if (Info
->bmiHeader
.biBitCount
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
))
717 hDestPalette
= hSourcePalette
;
718 bPaletteMatch
= TRUE
;
721 hDestPalette
= BuildDIBPalette(Info
, (PINT
)&DestPaletteType
); //hDestPalette = Dc->DevInfo->hpalDefault;
723 SourcePalette
= PALETTE_LockPalette(hSourcePalette
);
724 /* FIXME - SourcePalette can be NULL!!! Don't assert here! */
725 ASSERT(SourcePalette
);
726 SourcePaletteType
= SourcePalette
->Mode
;
727 PALETTE_UnlockPalette(SourcePalette
);
731 DestPalette
= PALETTE_LockPalette(hDestPalette
);
732 /* FIXME - DestPalette can be NULL!!!! Don't assert here!!! */
733 DPRINT("DestPalette : %p\n", DestPalette
);
735 DestPaletteType
= DestPalette
->Mode
;
739 DestPalette
= SourcePalette
;
743 /* FIXME: This is largely incomplete. ATM no Core!*/
744 switch(Info
->bmiHeader
.biBitCount
)
749 Info
->bmiHeader
.biClrUsed
= 0;
750 if ( psurf
->hSecure
&&
751 BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == Info
->bmiHeader
.biBitCount
)
753 if (Usage
== DIB_RGB_COLORS
)
755 if (DestPalette
->NumColors
!= 1 << Info
->bmiHeader
.biBitCount
)
756 Info
->bmiHeader
.biClrUsed
= DestPalette
->NumColors
;
758 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< DestPalette
->NumColors
;
761 rgbQuads
[Index
].rgbRed
= DestPalette
->IndexedColors
[Index
].peRed
;
762 rgbQuads
[Index
].rgbGreen
= DestPalette
->IndexedColors
[Index
].peGreen
;
763 rgbQuads
[Index
].rgbBlue
= DestPalette
->IndexedColors
[Index
].peBlue
;
764 rgbQuads
[Index
].rgbReserved
= 0;
769 PWORD Ptr
= ColorPtr
;
771 Index
< (1 << Info
->bmiHeader
.biBitCount
);
774 Ptr
[Index
] = (WORD
)Index
;
780 if (Usage
== DIB_PAL_COLORS
)
782 PWORD Ptr
= ColorPtr
;
784 Index
< (1 << Info
->bmiHeader
.biBitCount
);
787 Ptr
[Index
] = (WORD
)Index
;
790 else if (Info
->bmiHeader
.biBitCount
> 1 && bPaletteMatch
)
793 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< DestPalette
->NumColors
;
796 Info
->bmiColors
[Index
].rgbRed
= DestPalette
->IndexedColors
[Index
].peRed
;
797 Info
->bmiColors
[Index
].rgbGreen
= DestPalette
->IndexedColors
[Index
].peGreen
;
798 Info
->bmiColors
[Index
].rgbBlue
= DestPalette
->IndexedColors
[Index
].peBlue
;
799 Info
->bmiColors
[Index
].rgbReserved
= 0;
804 switch(Info
->bmiHeader
.biBitCount
)
807 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
= rgbQuads
[0].rgbBlue
= 0;
808 rgbQuads
[0].rgbReserved
= 0;
809 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
= rgbQuads
[1].rgbBlue
= 0xff;
810 rgbQuads
[1].rgbReserved
= 0;
813 RtlCopyMemory(ColorPtr
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
820 RtlCopyMemory(rgbQuads
, DefLogPaletteQuads
, 10 * sizeof(RGBQUAD
));
821 RtlCopyMemory(rgbQuads
+ 246, DefLogPaletteQuads
+ 10, 10 * sizeof(RGBQUAD
));
822 color
= rgbQuads
+ 10;
823 for(r
= 0; r
<= 5; r
++) /* FIXME */
824 for(g
= 0; g
<= 5; g
++)
825 for(b
= 0; b
<= 5; b
++)
827 color
->rgbRed
= (r
* 0xff) / 5;
828 color
->rgbGreen
= (g
* 0xff) / 5;
829 color
->rgbBlue
= (b
* 0xff) / 5;
830 color
->rgbReserved
= 0;
840 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
842 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
843 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
844 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
849 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
851 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
852 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
853 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
859 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
861 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
862 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
863 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
869 PALETTE_UnlockPalette(DestPalette
);
871 // If we have a good dib pointer, why not just copy bits from there w/o XLATE'ing them.
873 /* Create the destination bitmap too for the copy operation */
874 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
880 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
881 DestSize
.cx
= psurf
->SurfObj
.sizlBitmap
.cx
;
882 DestSize
.cy
= ScanLines
;
886 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
888 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
889 hDestBitmap
= EngCreateBitmap(DestSize
,
890 DIB_GetDIBWidthBytes(DestSize
.cx
, coreheader
->bcBitCount
),
891 BitmapFormat(coreheader
->bcBitCount
, BI_RGB
),
892 0 < coreheader
->bcHeight
? 0 : BMF_TOPDOWN
,
896 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
898 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(DestSize
.cx
,
899 Info
->bmiHeader
.biBitCount
) * DestSize
.cy
;
901 hDestBitmap
= EngCreateBitmap(DestSize
,
902 DIB_GetDIBWidthBytes(DestSize
.cx
, Info
->bmiHeader
.biBitCount
),
903 BitmapFormat(Info
->bmiHeader
.biBitCount
, Info
->bmiHeader
.biCompression
),
904 0 < Info
->bmiHeader
.biHeight
? 0 : BMF_TOPDOWN
,
908 if (hDestBitmap
== NULL
)
912 if (NT_SUCCESS(Status
))
915 SURFOBJ
*DestSurfObj
;
918 XlateObj
= IntEngCreateXlate(DestPaletteType
,
924 SourcePoint
.y
= psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
);
926 /* Determine destination rectangle */
929 DestRect
.right
= DestSize
.cx
;
930 DestRect
.bottom
= DestSize
.cy
;
932 DestSurfObj
= EngLockSurface((HSURF
)hDestBitmap
);
934 if (EngCopyBits( DestSurfObj
,
941 DPRINT("GetDIBits %d \n",abs(Info
->bmiHeader
.biHeight
) - StartScan
);
945 EngDeleteXlate(XlateObj
);
946 EngUnlockSurface(DestSurfObj
);
950 if (hDestBitmap
!= NULL
)
951 EngDeleteSurface((HSURF
)hDestBitmap
);
953 if (hDestPalette
!= NULL
&& bPaletteMatch
== FALSE
)
954 PALETTE_FreePaletteByHandle(hDestPalette
);
956 SURFACE_UnlockSurface(psurf
);
958 DPRINT("leaving NtGdiGetDIBitsInternal\n");
965 NtGdiStretchDIBitsInternal(
976 LPBITMAPINFO BitsInfo
,
983 HBITMAP hBitmap
, hOldBitmap
= NULL
;
985 HPALETTE hPal
= NULL
;
989 if (!Bits
|| !BitsInfo
)
991 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
997 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
998 ProbeForRead(Bits
, cjMaxBits
, 1);
1000 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1008 DPRINT1("NtGdiStretchDIBitsInternal fail to read BitMapInfo: %x or Bits: %x\n",BitsInfo
,Bits
);
1012 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1015 DPRINT1("NtGdiCreateCompatibleDC fail create hdc\n");
1019 hBitmap
= NtGdiCreateCompatibleBitmap( hDC
,
1020 abs(BitsInfo
->bmiHeader
.biWidth
),
1021 abs(BitsInfo
->bmiHeader
.biHeight
));
1022 if (hBitmap
== NULL
)
1024 DPRINT1("NtGdiCreateCompatibleBitmap fail create bitmap\n");
1025 DPRINT1("hDC : 0x%08x \n", hDC
);
1026 DPRINT1("BitsInfo->bmiHeader.biWidth : 0x%08x \n", BitsInfo
->bmiHeader
.biWidth
);
1027 DPRINT1("BitsInfo->bmiHeader.biHeight : 0x%08x \n", BitsInfo
->bmiHeader
.biHeight
);
1031 /* Select the bitmap into hdcMem, and save a handle to the old bitmap */
1032 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1034 if(Usage
== DIB_PAL_COLORS
)
1036 hPal
= NtGdiGetDCObject(hDC
, GDI_OBJECT_TYPE_PALETTE
);
1037 hPal
= GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1040 if (BitsInfo
->bmiHeader
.biCompression
== BI_RLE4
||
1041 BitsInfo
->bmiHeader
.biCompression
== BI_RLE8
)
1043 /* copy existing bitmap from destination dc */
1044 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1045 NtGdiBitBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1046 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, ROP
, 0, 0);
1048 NtGdiStretchBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1049 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1053 pDC
= DC_LockDc(hdcMem
);
1056 /* Note BitsInfo->bmiHeader.biHeight is the number of scanline,
1057 * if it negitve we getting to many scanline for scanline is UINT not
1058 * a INT, so we need make the negtive value to positve and that make the
1059 * count correct for negtive bitmap, TODO : we need testcase for this api */
1060 IntSetDIBits(pDC
, hBitmap
, 0, abs(BitsInfo
->bmiHeader
.biHeight
), Bits
,
1067 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1068 left (negative biHeight) */
1069 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1070 NtGdiBitBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1071 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1074 NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1075 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1076 SrcWidth
, SrcHeight
, ROP
, 0);
1080 GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1083 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1085 NtGdiDeleteObjectApp(hdcMem
);
1087 NtGdiDeleteObject(hBitmap
);
1095 IntCreateDIBitmap(PDC Dc
,
1107 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1108 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1110 if (bpp
!= 1) fColor
= TRUE
;
1111 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1114 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
1116 const RGBQUAD
*rgb
= data
->bmiColors
;
1117 DWORD col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1119 // Check if the first color of the colormap is black
1120 if ((col
== RGB(0, 0, 0)))
1123 col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1125 // If the second color is white, create a monochrome bitmap
1126 fColor
= (col
!= RGB(0xff,0xff,0xff));
1130 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1132 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
1133 DWORD col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1135 if ((col
== RGB(0,0,0)))
1138 col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1139 fColor
= (col
!= RGB(0xff,0xff,0xff));
1145 DPRINT("(%ld): wrong size for data\n", data
->bmiHeader
.biSize
);
1150 // Now create the bitmap
1153 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1157 handle
= IntGdiCreateBitmap(width
,
1167 if (NULL
!= handle
&& CBM_INIT
== init
)
1169 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1175 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1176 // The DDB that is created will be whatever bit depth your reference DC is
1179 NtGdiCreateDIBitmapInternal(IN HDC hDc
,
1183 IN OPTIONAL LPBYTE pjInit
,
1184 IN OPTIONAL LPBITMAPINFO pbmi
,
1186 IN UINT cjMaxInitInfo
,
1195 if (!hDc
) // CreateBitmap
1196 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1197 hDc
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
,FALSE
);
1200 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1204 Dc
= DC_LockDc(hDc
);
1207 NtGdiDeleteObjectApp(hDc
);
1208 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1212 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1215 NtGdiDeleteObjectApp(hDc
);
1217 else // CreateCompatibleBitmap
1219 Dc
= DC_LockDc(hDc
);
1222 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1226 First create an un-initialised bitmap. The depth of the bitmap
1227 should match that of the hdc and not that supplied in bmih.
1230 bpp
= pbmi
->bmiHeader
.biBitCount
;
1233 if (Dc
->DC_Type
!= DC_TYPE_MEMORY
)
1234 bpp
= IntGdiGetDeviceCaps(Dc
, BITSPIXEL
);
1239 SURFACE
*psurf
= SURFACE_LockSurface(Dc
->w
.hBitmap
);
1240 Count
= BITMAP_GetObject(psurf
, sizeof(dibs
), &dibs
);
1245 if (Count
== sizeof(BITMAP
))
1246 /* A device-dependent bitmap is selected in the DC */
1247 bpp
= dibs
.dsBm
.bmBitsPixel
;
1249 /* A DIB section is selected in the DC */
1250 bpp
= dibs
.dsBmih
.biBitCount
;
1252 SURFACE_UnlockSurface(psurf
);
1255 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1262 HBITMAP APIENTRY
NtGdiCreateDIBSection(HDC hDC
,
1263 IN OPTIONAL HANDLE hSection
,
1265 IN LPBITMAPINFO bmi
,
1269 IN ULONG_PTR dwColorSpace
,
1272 HBITMAP hbitmap
= 0;
1274 BOOL bDesktopDC
= FALSE
;
1276 if (!bmi
) return hbitmap
; // Make sure.
1278 // If the reference hdc is null, take the desktop dc
1281 hDC
= NtGdiCreateCompatibleDC(0);
1285 if ((dc
= DC_LockDc(hDC
)))
1287 hbitmap
= DIB_CreateDIBSection ( dc
, (BITMAPINFO
*)bmi
, Usage
, Bits
,
1288 hSection
, dwOffset
, 0);
1293 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1297 NtGdiDeleteObjectApp(hDC
);
1303 DIB_CreateDIBSection(
1313 SURFACE
*bmp
= NULL
;
1314 void *mapBits
= NULL
;
1317 // Fill BITMAP32 structure with DIB data
1318 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1325 DWORD dsBitfields
[3] = {0};
1327 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1328 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1329 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1331 /* CreateDIBSection should fail for compressed formats */
1332 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1334 return (HBITMAP
)NULL
;
1337 pDc_Attr
= dc
->pDc_Attr
;
1338 if ( !pDc_Attr
) pDc_Attr
= &dc
->Dc_Attr
;
1340 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1342 bm
.bmWidth
= bi
->biWidth
;
1343 bm
.bmHeight
= effHeight
;
1344 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1346 bm
.bmPlanes
= bi
->biPlanes
;
1347 bm
.bmBitsPixel
= bi
->biBitCount
;
1350 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1351 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1352 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1353 ? bi
->biSizeImage
: (ULONG
) (bm
.bmWidthBytes
* effHeight
);
1357 SYSTEM_BASIC_INFORMATION Sbi
;
1360 LARGE_INTEGER SectionOffset
;
1363 Status
= ZwQuerySystemInformation ( SystemBasicInformation
,
1367 if (!NT_SUCCESS(Status
))
1372 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1373 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1375 SectionOffset
.LowPart
= mapOffset
;
1376 SectionOffset
.HighPart
= 0;
1378 Status
= ZwMapViewOfSection ( section
,
1388 if (!NT_SUCCESS(Status
))
1390 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1394 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1396 else if (ovr_pitch
&& offset
)
1397 bm
.bmBits
= (LPVOID
) offset
;
1401 bm
.bmBits
= EngAllocUserMem( totalSize
, 0 );
1404 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1405 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1407 if(usage
== DIB_PAL_COLORS
)
1408 lpRGB
= DIB_MapPaletteColors(dc
, bmi
);
1410 lpRGB
= bmi
->bmiColors
;
1412 /* Set dsBitfields values */
1413 if ( usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1415 dsBitfields
[0] = dsBitfields
[1] = dsBitfields
[2] = 0;
1417 else if (bi
->biCompression
== BI_RGB
)
1419 switch(bi
->biBitCount
)
1423 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0x7c00;
1424 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x03e0;
1425 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x001f;
1430 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0xff0000;
1431 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x00ff00;
1432 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x0000ff;
1438 dsBitfields
[0] = ((DWORD
*)bmi
->bmiColors
)[0];
1439 dsBitfields
[1] = ((DWORD
*)bmi
->bmiColors
)[1];
1440 dsBitfields
[2] = ((DWORD
*)bmi
->bmiColors
)[2];
1443 // Create Device Dependent Bitmap and add DIB pointer
1444 Size
.cx
= bm
.bmWidth
;
1445 Size
.cy
= abs(bm
.bmHeight
);
1446 res
= IntCreateBitmap( Size
,
1448 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1449 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1450 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1454 if (lpRGB
!= bmi
->bmiColors
)
1456 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1458 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1461 bmp
= SURFACE_LockSurface(res
);
1464 if (lpRGB
!= bmi
->bmiColors
)
1466 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1468 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1469 NtGdiDeleteObject(bmp
);
1473 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1474 table between the DIB and the X physical device. Obviously,
1475 this is left out of the ReactOS implementation. Instead,
1476 we call NtGdiSetDIBColorTable. */
1478 /* set number of entries in bmi.bmiColors table */
1479 if(bi
->biBitCount
== 1) { bi
->biClrUsed
= 2; } else
1480 if(bi
->biBitCount
== 4) { bi
->biClrUsed
= 16; } else
1481 if(bi
->biBitCount
== 8) { bi
->biClrUsed
= 256; }
1483 bmp
->hDIBSection
= section
;
1484 bmp
->hSecure
= hSecure
;
1485 bmp
->dwOffset
= offset
;
1486 bmp
->flFlags
= BITMAPOBJ_IS_APIBITMAP
;
1487 bmp
->dsBitfields
[0] = dsBitfields
[0];
1488 bmp
->dsBitfields
[1] = dsBitfields
[1];
1489 bmp
->dsBitfields
[2] = dsBitfields
[2];
1490 bmp
->biClrUsed
= bi
->biClrUsed
;
1491 bmp
->biClrImportant
= bi
->biClrImportant
;
1493 if (bi
->biClrUsed
!= 0)
1494 bmp
->hDIBPalette
= PALETTE_AllocPaletteIndexedRGB(bi
->biClrUsed
, lpRGB
);
1496 bmp
->hDIBPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1501 // Clean up in case of errors
1502 if (!res
|| !bmp
|| !bm
.bmBits
)
1504 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1507 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1510 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1515 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1518 if (bmp
) { bmp
= NULL
; }
1519 if (res
) { SURFACE_FreeSurfaceByHandle(res
); res
= 0; }
1522 if (lpRGB
!= bmi
->bmiColors
)
1524 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1529 SURFACE_UnlockSurface(bmp
);
1532 // Return BITMAP handle and storage location
1533 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1538 // if (res) pDc_Attr->ulDirty_ |= DC_DIBSECTION;
1543 /***********************************************************************
1544 * DIB_GetDIBWidthBytes
1546 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1547 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1548 * 11/16/1999 (RJJ) lifted from wine
1550 INT FASTCALL
DIB_GetDIBWidthBytes (INT width
, INT depth
)
1552 return ((width
* depth
+ 31) & ~31) >> 3;
1555 /***********************************************************************
1556 * DIB_GetDIBImageBytes
1558 * Return the number of bytes used to hold the image in a DIB bitmap.
1559 * 11/16/1999 (RJJ) lifted from wine
1562 INT APIENTRY
DIB_GetDIBImageBytes (INT width
, INT height
, INT depth
)
1564 return DIB_GetDIBWidthBytes( width
, depth
) * (height
< 0 ? -height
: height
);
1567 /***********************************************************************
1568 * DIB_BitmapInfoSize
1570 * Return the size of the bitmap info structure including color table.
1571 * 11/16/1999 (RJJ) lifted from wine
1574 INT FASTCALL
DIB_BitmapInfoSize (const BITMAPINFO
* info
, WORD coloruse
)
1578 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1580 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1581 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1582 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1584 else /* assume BITMAPINFOHEADER */
1586 colors
= info
->bmiHeader
.biClrUsed
;
1587 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1588 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1593 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1600 palGDI
= PALETTE_LockPalette(dc
->DcLevel
.hpal
);
1607 if (palGDI
->Mode
!= PAL_INDEXED
)
1609 PALETTE_UnlockPalette(palGDI
);
1613 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1614 if (lpbmi
->bmiHeader
.biClrUsed
)
1616 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1619 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1622 PALETTE_UnlockPalette(palGDI
);
1626 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1628 for (i
= 0; i
< nNumColors
; i
++)
1630 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1631 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1632 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1633 lpRGB
[i
].rgbReserved
= 0;
1636 PALETTE_UnlockPalette(palGDI
);
1642 BuildDIBPalette (CONST BITMAPINFO
*bmi
, PINT paletteType
)
1646 PALETTEENTRY
*palEntries
= NULL
;
1648 ULONG RedMask
, GreenMask
, BlueMask
;
1650 // Determine Bits Per Pixel
1651 bits
= bmi
->bmiHeader
.biBitCount
;
1653 // Determine paletteType from Bits Per Pixel
1656 *paletteType
= PAL_INDEXED
;
1657 RedMask
= GreenMask
= BlueMask
= 0;
1659 else if(bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1661 *paletteType
= PAL_BITFIELDS
;
1662 RedMask
= ((ULONG
*)bmi
->bmiColors
)[0];
1663 GreenMask
= ((ULONG
*)bmi
->bmiColors
)[1];
1664 BlueMask
= ((ULONG
*)bmi
->bmiColors
)[2];
1668 *paletteType
= PAL_BITFIELDS
;
1675 *paletteType
= PAL_BGR
;
1677 GreenMask
= 0x00ff00;
1678 BlueMask
= 0x0000ff;
1681 if (bmi
->bmiHeader
.biClrUsed
== 0)
1683 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1687 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1690 if (PAL_INDEXED
== *paletteType
)
1692 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)bmi
->bmiColors
);
1696 hPal
= PALETTE_AllocPalette(*paletteType
, ColorCount
,
1697 (ULONG
*) palEntries
,
1698 RedMask
, GreenMask
, BlueMask
);