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
->dctype
== DC_TYPE_INFO
)
88 psurf
= SURFACE_LockSurface(dc
->rosdc
.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
->dctype
== DC_TYPE_INFO
)
154 psurf
= SURFACE_LockSurface(dc
->rosdc
.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 // Use hDIBPalette if it exists
275 if (bitmap
->hDIBPalette
)
277 DDB_Palette
= bitmap
->hDIBPalette
;
281 // Destination palette obtained from the hDC
282 DDB_Palette
= ((GDIDEVICE
*)DC
->ppdev
)->DevInfo
.hpalDefault
;
284 hDCPalette
= PALETTE_LockPalette(DDB_Palette
);
285 if (NULL
== hDCPalette
)
287 EngUnlockSurface(SourceSurf
);
288 EngDeleteSurface((HSURF
)SourceBitmap
);
289 SURFACE_UnlockSurface(bitmap
);
290 SetLastWin32Error(ERROR_INVALID_HANDLE
);
293 DDB_Palette_Type
= hDCPalette
->Mode
;
294 PALETTE_UnlockPalette(hDCPalette
);
296 // Source palette obtained from the BITMAPINFO
297 DIB_Palette
= BuildDIBPalette ( (PBITMAPINFO
)bmi
, (PINT
)&DIB_Palette_Type
);
298 if (NULL
== DIB_Palette
)
300 EngUnlockSurface(SourceSurf
);
301 EngDeleteSurface((HSURF
)SourceBitmap
);
302 SURFACE_UnlockSurface(bitmap
);
303 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
307 // Determine XLATEOBJ for color translation
308 XlateObj
= IntEngCreateXlate(DDB_Palette_Type
, DIB_Palette_Type
, DDB_Palette
, DIB_Palette
);
309 if (NULL
== XlateObj
)
311 PALETTE_FreePaletteByHandle(DIB_Palette
);
312 EngUnlockSurface(SourceSurf
);
313 EngDeleteSurface((HSURF
)SourceBitmap
);
314 SURFACE_UnlockSurface(bitmap
);
315 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
323 // Determine destination rectangle
325 DestRect
.top
= abs(bmi
->bmiHeader
.biHeight
) - StartScan
- ScanLines
;
326 DestRect
.right
= SourceSize
.cx
;
327 DestRect
.bottom
= DestRect
.top
+ ScanLines
;
329 copyBitsResult
= EngCopyBits(DestSurf
, SourceSurf
, NULL
, XlateObj
, &DestRect
, &ZeroPoint
);
331 // If it succeeded, return number of scanlines copies
332 if(copyBitsResult
== TRUE
)
334 result
= SourceSize
.cy
;
336 // result = abs(bmi->bmiHeader.biHeight) - StartScan;
340 EngDeleteXlate(XlateObj
);
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
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
);
416 NtGdiSetDIBitsToDeviceInternal(
431 IN BOOL bTransformCoordinates
,
432 IN OPTIONAL HANDLE hcmXform
436 NTSTATUS Status
= STATUS_SUCCESS
;
438 HBITMAP hSourceBitmap
= NULL
;
439 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
444 XLATEOBJ
*XlateObj
= NULL
;
446 HPALETTE DDBPalette
, DIBPalette
= NULL
;
447 ULONG DDBPaletteType
, DIBPaletteType
;
453 ProbeForRead(bmi
, cjMaxInfo
, 1);
454 ProbeForRead(Bits
, cjMaxBits
, 1);
456 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
458 Status
= _SEH2_GetExceptionCode();
462 if (!NT_SUCCESS(Status
))
467 pDC
= DC_LockDc(hDC
);
470 SetLastWin32Error(ERROR_INVALID_HANDLE
);
473 if (pDC
->dctype
== DC_TYPE_INFO
)
479 pDestSurf
= EngLockSurface((HSURF
)pDC
->rosdc
.hBitmap
);
482 /* FIXME: SetLastError ? */
489 if (bTransformCoordinates
)
491 CoordLPtoDP(pDC
, (LPPOINT
)&rcDest
);
493 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
494 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
495 rcDest
.right
= rcDest
.left
+ Width
;
496 rcDest
.bottom
= rcDest
.top
+ Height
;
501 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
502 SourceSize
.cy
= ScanLines
; // this one --> abs(bmi->bmiHeader.biHeight) - StartScan
503 DIBWidth
= DIB_GetDIBWidthBytes(SourceSize
.cx
, bmi
->bmiHeader
.biBitCount
);
505 hSourceBitmap
= EngCreateBitmap(SourceSize
,
507 BitmapFormat(bmi
->bmiHeader
.biBitCount
, bmi
->bmiHeader
.biCompression
),
508 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
512 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
513 Status
= STATUS_NO_MEMORY
;
517 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
520 Status
= STATUS_UNSUCCESSFUL
;
524 /* Obtain destination palette from the DC */
525 pDCPalette
= PALETTE_LockPalette(((GDIDEVICE
*)pDC
->ppdev
)->DevInfo
.hpalDefault
);
528 SetLastWin32Error(ERROR_INVALID_HANDLE
);
529 Status
= STATUS_UNSUCCESSFUL
;
533 DDBPaletteType
= pDCPalette
->Mode
;
534 DDBPalette
= ((GDIDEVICE
*)pDC
->ppdev
)->DevInfo
.hpalDefault
;
535 PALETTE_UnlockPalette(pDCPalette
);
537 DIBPalette
= BuildDIBPalette(bmi
, (PINT
)&DIBPaletteType
);
540 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
541 Status
= STATUS_NO_MEMORY
;
545 /* Determine XlateObj */
546 XlateObj
= IntEngCreateXlate(DDBPaletteType
, DIBPaletteType
, DDBPalette
, DIBPalette
);
549 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
550 Status
= STATUS_NO_MEMORY
;
555 Status
= IntEngBitBlt(pDestSurf
,
558 pDC
->rosdc
.CombinedClip
,
565 ROP3_TO_ROP4(SRCCOPY
));
567 if (NT_SUCCESS(Status
))
569 /* FIXME: Should probably be only the number of lines actually copied */
570 ret
= ScanLines
; // this one --> abs(Info->bmiHeader.biHeight) - StartScan;
573 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
574 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
575 if (XlateObj
) EngDeleteXlate(XlateObj
);
576 if (DIBPalette
) PALETTE_FreePaletteByHandle(DIBPalette
);
577 EngUnlockSurface(pDestSurf
);
584 /* Converts a device-dependent bitmap to a DIB */
586 NtGdiGetDIBitsInternal(HDC hDC
,
597 SURFACE
*psurf
= NULL
;
598 HBITMAP hDestBitmap
= NULL
;
599 HPALETTE hSourcePalette
= NULL
;
600 HPALETTE hDestPalette
= NULL
;
601 PPALGDI SourcePalette
= NULL
;
602 PPALGDI DestPalette
= NULL
;
603 NTSTATUS Status
= STATUS_SUCCESS
;
605 BOOL bPaletteMatch
= FALSE
;
606 PBYTE ChkBits
= Bits
;
610 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
612 if ( (Usage
&& Usage
!= DIB_PAL_COLORS
) ||
617 // if ScanLines == 0, no need to copy Bits.
618 if (!ScanLines
) ChkBits
= NULL
;
622 ProbeForWrite(Info
, Info
->bmiHeader
.biSize
, 1); // Comp for Core.
623 if (ChkBits
) ProbeForWrite(ChkBits
, MaxBits
, 1);
625 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
627 Status
= _SEH2_GetExceptionCode();
631 if (!NT_SUCCESS(Status
))
637 if (Dc
== NULL
) return 0;
638 if (Dc
->dctype
== DC_TYPE_INFO
)
645 /* Get a pointer to the source bitmap object */
646 psurf
= SURFACE_LockSurface(hBitmap
);
650 hSourcePalette
= psurf
->hDIBPalette
;
653 hSourcePalette
= pPrimarySurface
->DevInfo
.hpalDefault
;
656 ColorPtr
= ((PBYTE
)Info
+ Info
->bmiHeader
.biSize
);
657 rgbQuads
= (RGBQUAD
*)ColorPtr
;
659 /* fill out the BITMAPINFO struct */
661 { // Core or not to Core? We have converted from Core in Gdi~ so?
662 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
664 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
665 coreheader
->bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
666 coreheader
->bcPlanes
= 1;
667 coreheader
->bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
668 coreheader
->bcHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
669 if (psurf
->SurfObj
.lDelta
> 0)
670 coreheader
->bcHeight
= -coreheader
->bcHeight
;
673 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
675 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
676 Info
->bmiHeader
.biHeight
= psurf
->SurfObj
.sizlBitmap
.cy
;
677 Info
->bmiHeader
.biPlanes
= 1;
678 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
679 switch (psurf
->SurfObj
.iBitmapFormat
)
687 Info
->bmiHeader
.biCompression
= BI_RGB
;
690 Info
->bmiHeader
.biCompression
= BI_RLE4
;
693 Info
->bmiHeader
.biCompression
= BI_RLE8
;
696 Info
->bmiHeader
.biCompression
= BI_JPEG
;
699 Info
->bmiHeader
.biCompression
= BI_PNG
;
702 /* Image size has to be calculated */
703 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(Info
->bmiHeader
.biWidth
,
704 Info
->bmiHeader
.biBitCount
) * Info
->bmiHeader
.biHeight
;
705 Info
->bmiHeader
.biXPelsPerMeter
= 0; /* FIXME */
706 Info
->bmiHeader
.biYPelsPerMeter
= 0; /* FIXME */
707 Info
->bmiHeader
.biClrUsed
= 0;
708 Info
->bmiHeader
.biClrImportant
= 1 << Info
->bmiHeader
.biBitCount
; /* FIXME */
709 /* Report negtive height for top-down bitmaps. */
710 if (psurf
->SurfObj
.lDelta
> 0)
711 Info
->bmiHeader
.biHeight
= -Info
->bmiHeader
.biHeight
;
713 Result
= psurf
->SurfObj
.sizlBitmap
.cy
;
718 ULONG SourcePaletteType
= 0;
719 ULONG DestPaletteType
;
723 if (Info
->bmiHeader
.biBitCount
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
))
725 hDestPalette
= hSourcePalette
;
726 bPaletteMatch
= TRUE
;
729 hDestPalette
= BuildDIBPalette(Info
, (PINT
)&DestPaletteType
); //hDestPalette = Dc->DevInfo->hpalDefault;
731 SourcePalette
= PALETTE_LockPalette(hSourcePalette
);
732 /* FIXME - SourcePalette can be NULL!!! Don't assert here! */
733 ASSERT(SourcePalette
);
734 SourcePaletteType
= SourcePalette
->Mode
;
735 PALETTE_UnlockPalette(SourcePalette
);
739 DestPalette
= PALETTE_LockPalette(hDestPalette
);
740 /* FIXME - DestPalette can be NULL!!!! Don't assert here!!! */
741 DPRINT("DestPalette : %p\n", DestPalette
);
743 DestPaletteType
= DestPalette
->Mode
;
747 DestPalette
= SourcePalette
;
751 /* FIXME: This is largely incomplete. ATM no Core!*/
752 switch(Info
->bmiHeader
.biBitCount
)
757 Info
->bmiHeader
.biClrUsed
= 0;
758 if ( psurf
->hSecure
&&
759 BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == Info
->bmiHeader
.biBitCount
)
761 if (Usage
== DIB_RGB_COLORS
)
763 if (DestPalette
->NumColors
!= 1 << Info
->bmiHeader
.biBitCount
)
764 Info
->bmiHeader
.biClrUsed
= DestPalette
->NumColors
;
766 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< DestPalette
->NumColors
;
769 rgbQuads
[Index
].rgbRed
= DestPalette
->IndexedColors
[Index
].peRed
;
770 rgbQuads
[Index
].rgbGreen
= DestPalette
->IndexedColors
[Index
].peGreen
;
771 rgbQuads
[Index
].rgbBlue
= DestPalette
->IndexedColors
[Index
].peBlue
;
772 rgbQuads
[Index
].rgbReserved
= 0;
777 PWORD Ptr
= ColorPtr
;
779 Index
< (1 << Info
->bmiHeader
.biBitCount
);
782 Ptr
[Index
] = (WORD
)Index
;
788 if (Usage
== DIB_PAL_COLORS
)
790 PWORD Ptr
= ColorPtr
;
792 Index
< (1 << Info
->bmiHeader
.biBitCount
);
795 Ptr
[Index
] = (WORD
)Index
;
798 else if (Info
->bmiHeader
.biBitCount
> 1 && bPaletteMatch
)
801 Index
< (1 << Info
->bmiHeader
.biBitCount
) && Index
< DestPalette
->NumColors
;
804 Info
->bmiColors
[Index
].rgbRed
= DestPalette
->IndexedColors
[Index
].peRed
;
805 Info
->bmiColors
[Index
].rgbGreen
= DestPalette
->IndexedColors
[Index
].peGreen
;
806 Info
->bmiColors
[Index
].rgbBlue
= DestPalette
->IndexedColors
[Index
].peBlue
;
807 Info
->bmiColors
[Index
].rgbReserved
= 0;
812 switch(Info
->bmiHeader
.biBitCount
)
815 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
= rgbQuads
[0].rgbBlue
= 0;
816 rgbQuads
[0].rgbReserved
= 0;
817 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
= rgbQuads
[1].rgbBlue
= 0xff;
818 rgbQuads
[1].rgbReserved
= 0;
821 RtlCopyMemory(ColorPtr
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
828 RtlCopyMemory(rgbQuads
, DefLogPaletteQuads
, 10 * sizeof(RGBQUAD
));
829 RtlCopyMemory(rgbQuads
+ 246, DefLogPaletteQuads
+ 10, 10 * sizeof(RGBQUAD
));
830 color
= rgbQuads
+ 10;
831 for(r
= 0; r
<= 5; r
++) /* FIXME */
832 for(g
= 0; g
<= 5; g
++)
833 for(b
= 0; b
<= 5; b
++)
835 color
->rgbRed
= (r
* 0xff) / 5;
836 color
->rgbGreen
= (g
* 0xff) / 5;
837 color
->rgbBlue
= (b
* 0xff) / 5;
838 color
->rgbReserved
= 0;
848 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
850 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
851 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
852 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
857 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
859 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
860 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
861 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
867 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
869 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
870 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
871 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
877 PALETTE_UnlockPalette(DestPalette
);
879 // If we have a good dib pointer, why not just copy bits from there w/o XLATE'ing them.
881 /* Create the destination bitmap too for the copy operation */
882 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
888 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
889 DestSize
.cx
= psurf
->SurfObj
.sizlBitmap
.cx
;
890 DestSize
.cy
= ScanLines
;
894 if (Info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
896 BITMAPCOREHEADER
* coreheader
= (BITMAPCOREHEADER
*) Info
;
897 hDestBitmap
= EngCreateBitmap(DestSize
,
898 DIB_GetDIBWidthBytes(DestSize
.cx
, coreheader
->bcBitCount
),
899 BitmapFormat(coreheader
->bcBitCount
, BI_RGB
),
900 0 < coreheader
->bcHeight
? 0 : BMF_TOPDOWN
,
904 if (Info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
))
906 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBWidthBytes(DestSize
.cx
,
907 Info
->bmiHeader
.biBitCount
) * DestSize
.cy
;
909 hDestBitmap
= EngCreateBitmap(DestSize
,
910 DIB_GetDIBWidthBytes(DestSize
.cx
, Info
->bmiHeader
.biBitCount
),
911 BitmapFormat(Info
->bmiHeader
.biBitCount
, Info
->bmiHeader
.biCompression
),
912 0 < Info
->bmiHeader
.biHeight
? 0 : BMF_TOPDOWN
,
916 if (hDestBitmap
== NULL
)
920 if (NT_SUCCESS(Status
))
923 SURFOBJ
*DestSurfObj
;
926 XlateObj
= IntEngCreateXlate(DestPaletteType
,
932 SourcePoint
.y
= psurf
->SurfObj
.sizlBitmap
.cy
- (StartScan
+ ScanLines
);
934 /* Determine destination rectangle */
937 DestRect
.right
= DestSize
.cx
;
938 DestRect
.bottom
= DestSize
.cy
;
940 DestSurfObj
= EngLockSurface((HSURF
)hDestBitmap
);
942 if (EngCopyBits( DestSurfObj
,
949 DPRINT("GetDIBits %d \n",abs(Info
->bmiHeader
.biHeight
) - StartScan
);
953 EngDeleteXlate(XlateObj
);
954 EngUnlockSurface(DestSurfObj
);
958 if (hDestBitmap
!= NULL
)
959 EngDeleteSurface((HSURF
)hDestBitmap
);
961 if (hDestPalette
!= NULL
&& bPaletteMatch
== FALSE
)
962 PALETTE_FreePaletteByHandle(hDestPalette
);
964 SURFACE_UnlockSurface(psurf
);
966 DPRINT("leaving NtGdiGetDIBitsInternal\n");
973 NtGdiStretchDIBitsInternal(
984 LPBITMAPINFO BitsInfo
,
991 HBITMAP hBitmap
, hOldBitmap
= NULL
;
993 HPALETTE hPal
= NULL
;
997 if (!Bits
|| !BitsInfo
)
999 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1005 ProbeForRead(BitsInfo
, cjMaxInfo
, 1);
1006 ProbeForRead(Bits
, cjMaxBits
, 1);
1008 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1016 DPRINT1("NtGdiStretchDIBitsInternal fail to read BitMapInfo: %x or Bits: %x\n",BitsInfo
,Bits
);
1020 hdcMem
= NtGdiCreateCompatibleDC(hDC
);
1023 DPRINT1("NtGdiCreateCompatibleDC fail create hdc\n");
1027 hBitmap
= NtGdiCreateCompatibleBitmap( hDC
,
1028 abs(BitsInfo
->bmiHeader
.biWidth
),
1029 abs(BitsInfo
->bmiHeader
.biHeight
));
1030 if (hBitmap
== NULL
)
1032 DPRINT1("NtGdiCreateCompatibleBitmap fail create bitmap\n");
1033 DPRINT1("hDC : 0x%08x \n", hDC
);
1034 DPRINT1("BitsInfo->bmiHeader.biWidth : 0x%08x \n", BitsInfo
->bmiHeader
.biWidth
);
1035 DPRINT1("BitsInfo->bmiHeader.biHeight : 0x%08x \n", BitsInfo
->bmiHeader
.biHeight
);
1039 /* Select the bitmap into hdcMem, and save a handle to the old bitmap */
1040 hOldBitmap
= NtGdiSelectBitmap(hdcMem
, hBitmap
);
1042 if(Usage
== DIB_PAL_COLORS
)
1044 hPal
= NtGdiGetDCObject(hDC
, GDI_OBJECT_TYPE_PALETTE
);
1045 hPal
= GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1048 if (BitsInfo
->bmiHeader
.biCompression
== BI_RLE4
||
1049 BitsInfo
->bmiHeader
.biCompression
== BI_RLE8
)
1051 /* copy existing bitmap from destination dc */
1052 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1053 NtGdiBitBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1054 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, ROP
, 0, 0);
1056 NtGdiStretchBlt(hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1057 SrcWidth
, SrcHeight
, hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1061 pDC
= DC_LockDc(hdcMem
);
1064 /* Note BitsInfo->bmiHeader.biHeight is the number of scanline,
1065 * if it negitve we getting to many scanline for scanline is UINT not
1066 * a INT, so we need make the negtive value to positve and that make the
1067 * count correct for negtive bitmap, TODO : we need testcase for this api */
1068 IntSetDIBits(pDC
, hBitmap
, 0, abs(BitsInfo
->bmiHeader
.biHeight
), Bits
,
1075 /* Origin for DIBitmap may be bottom left (positive biHeight) or top
1076 left (negative biHeight) */
1077 if (SrcWidth
== DestWidth
&& SrcHeight
== DestHeight
)
1078 NtGdiBitBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1079 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1082 NtGdiStretchBlt(hDC
, XDest
, YDest
, DestWidth
, DestHeight
,
1083 hdcMem
, XSrc
, abs(BitsInfo
->bmiHeader
.biHeight
) - SrcHeight
- YSrc
,
1084 SrcWidth
, SrcHeight
, ROP
, 0);
1088 GdiSelectPalette(hdcMem
, hPal
, FALSE
);
1091 NtGdiSelectBitmap(hdcMem
, hOldBitmap
);
1093 NtGdiDeleteObjectApp(hdcMem
);
1095 NtGdiDeleteObject(hBitmap
);
1103 IntCreateDIBitmap(PDC Dc
,
1115 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1116 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1118 if (bpp
!= 1) fColor
= TRUE
;
1119 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1122 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
1124 const RGBQUAD
*rgb
= data
->bmiColors
;
1125 DWORD col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1127 // Check if the first color of the colormap is black
1128 if ((col
== RGB(0, 0, 0)))
1131 col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1133 // If the second color is white, create a monochrome bitmap
1134 fColor
= (col
!= RGB(0xff,0xff,0xff));
1138 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1140 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
1141 DWORD col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1143 if ((col
== RGB(0,0,0)))
1146 col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1147 fColor
= (col
!= RGB(0xff,0xff,0xff));
1153 DPRINT("(%ld): wrong size for data\n", data
->bmiHeader
.biSize
);
1158 // Now create the bitmap
1161 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1165 handle
= IntGdiCreateBitmap(width
,
1175 if (NULL
!= handle
&& CBM_INIT
== init
)
1177 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1183 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1184 // The DDB that is created will be whatever bit depth your reference DC is
1187 NtGdiCreateDIBitmapInternal(IN HDC hDc
,
1191 IN OPTIONAL LPBYTE pjInit
,
1192 IN OPTIONAL LPBITMAPINFO pbmi
,
1194 IN UINT cjMaxInitInfo
,
1203 if (!hDc
) // CreateBitmap
1204 { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1205 hDc
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
,FALSE
);
1208 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1212 Dc
= DC_LockDc(hDc
);
1215 NtGdiDeleteObjectApp(hDc
);
1216 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1220 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1223 NtGdiDeleteObjectApp(hDc
);
1225 else // CreateCompatibleBitmap
1227 Dc
= DC_LockDc(hDc
);
1230 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1234 First create an un-initialised bitmap. The depth of the bitmap
1235 should match that of the hdc and not that supplied in bmih.
1238 bpp
= pbmi
->bmiHeader
.biBitCount
;
1241 if (Dc
->dctype
!= DC_TYPE_MEMORY
)
1242 bpp
= IntGdiGetDeviceCaps(Dc
, BITSPIXEL
);
1247 SURFACE
*psurf
= SURFACE_LockSurface(Dc
->rosdc
.hBitmap
);
1248 Count
= BITMAP_GetObject(psurf
, sizeof(dibs
), &dibs
);
1253 if (Count
== sizeof(BITMAP
))
1254 /* A device-dependent bitmap is selected in the DC */
1255 bpp
= dibs
.dsBm
.bmBitsPixel
;
1257 /* A DIB section is selected in the DC */
1258 bpp
= dibs
.dsBmih
.biBitCount
;
1260 SURFACE_UnlockSurface(psurf
);
1263 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1270 HBITMAP APIENTRY
NtGdiCreateDIBSection(HDC hDC
,
1271 IN OPTIONAL HANDLE hSection
,
1273 IN LPBITMAPINFO bmi
,
1277 IN ULONG_PTR dwColorSpace
,
1280 HBITMAP hbitmap
= 0;
1282 BOOL bDesktopDC
= FALSE
;
1284 if (!bmi
) return hbitmap
; // Make sure.
1286 // If the reference hdc is null, take the desktop dc
1289 hDC
= NtGdiCreateCompatibleDC(0);
1293 if ((dc
= DC_LockDc(hDC
)))
1295 hbitmap
= DIB_CreateDIBSection ( dc
, (BITMAPINFO
*)bmi
, Usage
, Bits
,
1296 hSection
, dwOffset
, 0);
1301 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1305 NtGdiDeleteObjectApp(hDC
);
1311 DIB_CreateDIBSection(
1321 SURFACE
*bmp
= NULL
;
1322 void *mapBits
= NULL
;
1325 // Fill BITMAP32 structure with DIB data
1326 BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1333 DWORD dsBitfields
[3] = {0};
1335 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1336 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1337 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1339 /* CreateDIBSection should fail for compressed formats */
1340 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1342 return (HBITMAP
)NULL
;
1345 pDc_Attr
= dc
->pDc_Attr
;
1346 if ( !pDc_Attr
) pDc_Attr
= &dc
->Dc_Attr
;
1348 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1350 bm
.bmWidth
= bi
->biWidth
;
1351 bm
.bmHeight
= effHeight
;
1352 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: (ULONG
) DIB_GetDIBWidthBytes(bm
.bmWidth
, bi
->biBitCount
);
1354 bm
.bmPlanes
= bi
->biPlanes
;
1355 bm
.bmBitsPixel
= bi
->biBitCount
;
1358 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1359 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1360 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
1361 ? bi
->biSizeImage
: (ULONG
) (bm
.bmWidthBytes
* effHeight
);
1365 SYSTEM_BASIC_INFORMATION Sbi
;
1368 LARGE_INTEGER SectionOffset
;
1371 Status
= ZwQuerySystemInformation ( SystemBasicInformation
,
1375 if (!NT_SUCCESS(Status
))
1380 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1381 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1383 SectionOffset
.LowPart
= mapOffset
;
1384 SectionOffset
.HighPart
= 0;
1386 Status
= ZwMapViewOfSection ( section
,
1396 if (!NT_SUCCESS(Status
))
1398 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1402 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1404 else if (ovr_pitch
&& offset
)
1405 bm
.bmBits
= (LPVOID
) offset
;
1409 bm
.bmBits
= EngAllocUserMem( totalSize
, 0 );
1412 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1413 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1415 if(usage
== DIB_PAL_COLORS
)
1416 lpRGB
= DIB_MapPaletteColors(dc
, bmi
);
1418 lpRGB
= bmi
->bmiColors
;
1420 /* Set dsBitfields values */
1421 if ( usage
== DIB_PAL_COLORS
|| bi
->biBitCount
<= 8)
1423 dsBitfields
[0] = dsBitfields
[1] = dsBitfields
[2] = 0;
1425 else if (bi
->biCompression
== BI_RGB
)
1427 switch(bi
->biBitCount
)
1431 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0x7c00;
1432 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x03e0;
1433 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x001f;
1438 dsBitfields
[0] = (bi
->biCompression
== BI_BITFIELDS
) ? *(DWORD
*)lpRGB
: 0xff0000;
1439 dsBitfields
[1] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 1) : 0x00ff00;
1440 dsBitfields
[2] = (bi
->biCompression
== BI_BITFIELDS
) ? *((DWORD
*)lpRGB
+ 2) : 0x0000ff;
1446 dsBitfields
[0] = ((DWORD
*)bmi
->bmiColors
)[0];
1447 dsBitfields
[1] = ((DWORD
*)bmi
->bmiColors
)[1];
1448 dsBitfields
[2] = ((DWORD
*)bmi
->bmiColors
)[2];
1451 // Create Device Dependent Bitmap and add DIB pointer
1452 Size
.cx
= bm
.bmWidth
;
1453 Size
.cy
= abs(bm
.bmHeight
);
1454 res
= IntCreateBitmap( Size
,
1456 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1457 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1458 (bi
->biHeight
< 0 ? BMF_TOPDOWN
: 0),
1462 if (lpRGB
!= bmi
->bmiColors
)
1464 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1466 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1469 bmp
= SURFACE_LockSurface(res
);
1472 if (lpRGB
!= bmi
->bmiColors
)
1474 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1476 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1477 NtGdiDeleteObject(bmp
);
1481 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1482 table between the DIB and the X physical device. Obviously,
1483 this is left out of the ReactOS implementation. Instead,
1484 we call NtGdiSetDIBColorTable. */
1486 /* set number of entries in bmi.bmiColors table */
1487 if(bi
->biBitCount
== 1) { bi
->biClrUsed
= 2; } else
1488 if(bi
->biBitCount
== 4) { bi
->biClrUsed
= 16; } else
1489 if(bi
->biBitCount
== 8) { bi
->biClrUsed
= 256; }
1491 bmp
->hDIBSection
= section
;
1492 bmp
->hSecure
= hSecure
;
1493 bmp
->dwOffset
= offset
;
1494 bmp
->flFlags
= BITMAPOBJ_IS_APIBITMAP
;
1495 bmp
->dsBitfields
[0] = dsBitfields
[0];
1496 bmp
->dsBitfields
[1] = dsBitfields
[1];
1497 bmp
->dsBitfields
[2] = dsBitfields
[2];
1498 bmp
->biClrUsed
= bi
->biClrUsed
;
1499 bmp
->biClrImportant
= bi
->biClrImportant
;
1501 if (bi
->biClrUsed
!= 0)
1502 bmp
->hDIBPalette
= PALETTE_AllocPaletteIndexedRGB(bi
->biClrUsed
, lpRGB
);
1504 bmp
->hDIBPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1509 // Clean up in case of errors
1510 if (!res
|| !bmp
|| !bm
.bmBits
)
1512 DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1515 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1518 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1523 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1526 if (bmp
) { bmp
= NULL
; }
1527 if (res
) { SURFACE_FreeSurfaceByHandle(res
); res
= 0; }
1530 if (lpRGB
!= bmi
->bmiColors
)
1532 ExFreePoolWithTag(lpRGB
, TAG_COLORMAP
);
1537 SURFACE_UnlockSurface(bmp
);
1540 // Return BITMAP handle and storage location
1541 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1546 // if (res) pDc_Attr->ulDirty_ |= DC_DIBSECTION;
1551 /***********************************************************************
1552 * DIB_GetDIBWidthBytes
1554 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1555 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
1556 * 11/16/1999 (RJJ) lifted from wine
1558 INT FASTCALL
DIB_GetDIBWidthBytes (INT width
, INT depth
)
1560 return ((width
* depth
+ 31) & ~31) >> 3;
1563 /***********************************************************************
1564 * DIB_GetDIBImageBytes
1566 * Return the number of bytes used to hold the image in a DIB bitmap.
1567 * 11/16/1999 (RJJ) lifted from wine
1570 INT APIENTRY
DIB_GetDIBImageBytes (INT width
, INT height
, INT depth
)
1572 return DIB_GetDIBWidthBytes( width
, depth
) * (height
< 0 ? -height
: height
);
1575 /***********************************************************************
1576 * DIB_BitmapInfoSize
1578 * Return the size of the bitmap info structure including color table.
1579 * 11/16/1999 (RJJ) lifted from wine
1582 INT FASTCALL
DIB_BitmapInfoSize (const BITMAPINFO
* info
, WORD coloruse
)
1586 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1588 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
1589 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1590 return sizeof(BITMAPCOREHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1592 else /* assume BITMAPINFOHEADER */
1594 colors
= info
->bmiHeader
.biClrUsed
;
1595 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8)) colors
= 1 << info
->bmiHeader
.biBitCount
;
1596 return sizeof(BITMAPINFOHEADER
) + colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1601 DIB_MapPaletteColors(PDC dc
, CONST BITMAPINFO
* lpbmi
)
1608 palGDI
= PALETTE_LockPalette(dc
->DcLevel
.hpal
);
1615 if (palGDI
->Mode
!= PAL_INDEXED
)
1617 PALETTE_UnlockPalette(palGDI
);
1621 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1622 if (lpbmi
->bmiHeader
.biClrUsed
)
1624 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1627 lpRGB
= (RGBQUAD
*)ExAllocatePoolWithTag(PagedPool
, sizeof(RGBQUAD
) * nNumColors
, TAG_COLORMAP
);
1630 PALETTE_UnlockPalette(palGDI
);
1634 lpIndex
= (USHORT
*)&lpbmi
->bmiColors
[0];
1636 for (i
= 0; i
< nNumColors
; i
++)
1638 lpRGB
[i
].rgbRed
= palGDI
->IndexedColors
[*lpIndex
].peRed
;
1639 lpRGB
[i
].rgbGreen
= palGDI
->IndexedColors
[*lpIndex
].peGreen
;
1640 lpRGB
[i
].rgbBlue
= palGDI
->IndexedColors
[*lpIndex
].peBlue
;
1641 lpRGB
[i
].rgbReserved
= 0;
1644 PALETTE_UnlockPalette(palGDI
);
1650 BuildDIBPalette (CONST BITMAPINFO
*bmi
, PINT paletteType
)
1654 PALETTEENTRY
*palEntries
= NULL
;
1656 ULONG RedMask
, GreenMask
, BlueMask
;
1658 // Determine Bits Per Pixel
1659 bits
= bmi
->bmiHeader
.biBitCount
;
1661 // Determine paletteType from Bits Per Pixel
1664 *paletteType
= PAL_INDEXED
;
1665 RedMask
= GreenMask
= BlueMask
= 0;
1667 else if(bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1669 *paletteType
= PAL_BITFIELDS
;
1670 RedMask
= ((ULONG
*)bmi
->bmiColors
)[0];
1671 GreenMask
= ((ULONG
*)bmi
->bmiColors
)[1];
1672 BlueMask
= ((ULONG
*)bmi
->bmiColors
)[2];
1676 *paletteType
= PAL_BITFIELDS
;
1683 *paletteType
= PAL_BGR
;
1685 GreenMask
= 0x00ff00;
1686 BlueMask
= 0x0000ff;
1689 if (bmi
->bmiHeader
.biClrUsed
== 0)
1691 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1695 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1698 if (PAL_INDEXED
== *paletteType
)
1700 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)bmi
->bmiColors
);
1704 hPal
= PALETTE_AllocPalette(*paletteType
, ColorCount
,
1705 (ULONG
*) palEntries
,
1706 RedMask
, GreenMask
, BlueMask
);