2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/objects/dibobj.c
5 * PURPOSE: Dib object functions
14 static const RGBQUAD EGAColorsQuads
[16] =
16 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
17 { 0x00, 0x00, 0x00, 0x00 },
18 { 0x00, 0x00, 0x80, 0x00 },
19 { 0x00, 0x80, 0x00, 0x00 },
20 { 0x00, 0x80, 0x80, 0x00 },
21 { 0x80, 0x00, 0x00, 0x00 },
22 { 0x80, 0x00, 0x80, 0x00 },
23 { 0x80, 0x80, 0x00, 0x00 },
24 { 0x80, 0x80, 0x80, 0x00 },
25 { 0xc0, 0xc0, 0xc0, 0x00 },
26 { 0x00, 0x00, 0xff, 0x00 },
27 { 0x00, 0xff, 0x00, 0x00 },
28 { 0x00, 0xff, 0xff, 0x00 },
29 { 0xff, 0x00, 0x00, 0x00 },
30 { 0xff, 0x00, 0xff, 0x00 },
31 { 0xff, 0xff, 0x00, 0x00 },
32 { 0xff, 0xff, 0xff, 0x00 }
35 static const RGBTRIPLE EGAColorsTriples
[16] =
37 /* rgbBlue, rgbGreen, rgbRed */
56 static const RGBQUAD DefLogPaletteQuads
[20] = /* Copy of Default Logical Palette */
58 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
59 { 0x00, 0x00, 0x00, 0x00 },
60 { 0x00, 0x00, 0x80, 0x00 },
61 { 0x00, 0x80, 0x00, 0x00 },
62 { 0x00, 0x80, 0x80, 0x00 },
63 { 0x80, 0x00, 0x00, 0x00 },
64 { 0x80, 0x00, 0x80, 0x00 },
65 { 0x80, 0x80, 0x00, 0x00 },
66 { 0xc0, 0xc0, 0xc0, 0x00 },
67 { 0xc0, 0xdc, 0xc0, 0x00 },
68 { 0xf0, 0xca, 0xa6, 0x00 },
69 { 0xf0, 0xfb, 0xff, 0x00 },
70 { 0xa4, 0xa0, 0xa0, 0x00 },
71 { 0x80, 0x80, 0x80, 0x00 },
72 { 0x00, 0x00, 0xf0, 0x00 },
73 { 0x00, 0xff, 0x00, 0x00 },
74 { 0x00, 0xff, 0xff, 0x00 },
75 { 0xff, 0x00, 0x00, 0x00 },
76 { 0xff, 0x00, 0xff, 0x00 },
77 { 0xff, 0xff, 0x00, 0x00 },
78 { 0xff, 0xff, 0xff, 0x00 }
81 static const RGBQUAD DefLogPaletteTriples
[20] = /* Copy of Default Logical Palette */
83 /* rgbBlue, rgbGreen, rgbRed, rgbReserved */
100 { 0xff, 0x00, 0x00 },
101 { 0xff, 0x00, 0xff },
102 { 0xff, 0xff, 0x00 },
113 CONST RGBQUAD
*Colors
)
121 if (!(dc
= DC_LockDc(hDC
))) return 0;
122 if (dc
->dctype
== DC_TYPE_INFO
)
128 psurf
= dc
->dclevel
.pSurface
;
132 EngSetLastError(ERROR_INVALID_PARAMETER
);
136 if (psurf
->hSecure
== NULL
)
139 EngSetLastError(ERROR_INVALID_PARAMETER
);
143 biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
144 if (biBitCount
<= 8 && StartIndex
< (1 << biBitCount
))
146 if (StartIndex
+ Entries
> (1 << biBitCount
))
147 Entries
= (1 << biBitCount
) - StartIndex
;
149 if (psurf
->ppal
== NULL
)
152 EngSetLastError(ERROR_INVALID_HANDLE
);
156 PalGDI
= psurf
->ppal
;
158 for (Index
= StartIndex
;
159 Index
< StartIndex
+ Entries
&& Index
< PalGDI
->NumColors
;
162 PalGDI
->IndexedColors
[Index
].peRed
= Colors
[Index
- StartIndex
].rgbRed
;
163 PalGDI
->IndexedColors
[Index
].peGreen
= Colors
[Index
- StartIndex
].rgbGreen
;
164 PalGDI
->IndexedColors
[Index
].peBlue
= Colors
[Index
- StartIndex
].rgbBlue
;
170 /* Mark the brushes invalid */
171 dc
->pdcattr
->ulDirty_
|= DIRTY_FILL
|DIRTY_LINE
|DIRTY_BACKGROUND
|DIRTY_TEXT
;
189 UINT Index
, Count
= 0;
191 if (!(dc
= DC_LockDc(hDC
))) return 0;
192 if (dc
->dctype
== DC_TYPE_INFO
)
198 psurf
= dc
->dclevel
.pSurface
;
202 EngSetLastError(ERROR_INVALID_PARAMETER
);
206 if (psurf
->hSecure
== NULL
)
209 EngSetLastError(ERROR_INVALID_PARAMETER
);
216 if (ppal
->flFlags
& PAL_INDEXED
)
219 for (Index
= StartIndex
;
220 Index
< StartIndex
+ Entries
&& Index
< ppal
->NumColors
;
223 Colors
[Index
- StartIndex
].rgbRed
= ppal
->IndexedColors
[Index
].peRed
;
224 Colors
[Index
- StartIndex
].rgbGreen
= ppal
->IndexedColors
[Index
].peGreen
;
225 Colors
[Index
- StartIndex
].rgbBlue
= ppal
->IndexedColors
[Index
].peBlue
;
226 Colors
[Index
- StartIndex
].rgbReserved
= 0;
236 // Converts a DIB to a device-dependent bitmap
245 CONST BITMAPINFO
*bmi
,
248 HBITMAP SourceBitmap
;
249 PSURFACE psurfDst
, psurfSrc
;
254 HPALETTE hpalDIB
= 0;
255 PPALETTE ppalDIB
= 0;
257 SourceBitmap
= GreCreateBitmapEx(bmi
->bmiHeader
.biWidth
,
260 BitmapFormat(bmi
->bmiHeader
.biBitCount
,
261 bmi
->bmiHeader
.biCompression
),
262 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
263 bmi
->bmiHeader
.biSizeImage
,
268 DPRINT1("Error: Could not create a bitmap.\n");
269 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
273 psurfDst
= SURFACE_ShareLockSurface(hBitmap
);
274 psurfSrc
= SURFACE_ShareLockSurface(SourceBitmap
);
276 if(!(psurfSrc
&& psurfDst
))
278 DPRINT1("Error: Could not lock surfaces\n");
282 /* Create a palette for the DIB */
283 hpalDIB
= BuildDIBPalette(bmi
);
286 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
290 /* Lock the DIB palette */
291 ppalDIB
= PALETTE_ShareLockPalette(hpalDIB
);
294 EngSetLastError(ERROR_INVALID_HANDLE
);
298 /* Initialize EXLATEOBJ */
299 EXLATEOBJ_vInitialize(&exlo
,
302 RGB(0xff, 0xff, 0xff),
303 RGB(0xff, 0xff, 0xff), //DC->pdcattr->crBackgroundClr,
304 0); // DC->pdcattr->crForegroundClr);
306 rcDst
.top
= StartScan
;
308 rcDst
.bottom
= rcDst
.top
+ ScanLines
;
309 rcDst
.right
= psurfDst
->SurfObj
.sizlBitmap
.cx
;
313 result
= IntEngCopyBits(&psurfDst
->SurfObj
,
322 EXLATEOBJ_vCleanup(&exlo
);
325 if (ppalDIB
) PALETTE_ShareUnlockPalette(ppalDIB
);
326 if (hpalDIB
) GreDeleteObject(hpalDIB
);
327 if(psurfSrc
) SURFACE_ShareUnlockSurface(psurfSrc
);
328 if(psurfDst
) SURFACE_ShareUnlockSurface(psurfDst
);
329 GreDeleteObject(SourceBitmap
);
337 NtGdiSetDIBitsToDeviceInternal(
352 IN BOOL bTransformCoordinates
,
353 IN OPTIONAL HANDLE hcmXform
)
356 NTSTATUS Status
= STATUS_SUCCESS
;
358 HBITMAP hSourceBitmap
= NULL
;
359 SURFOBJ
*pDestSurf
, *pSourceSurf
= NULL
;
366 PPALETTE ppalDIB
= NULL
;
367 HPALETTE hpalDIB
= NULL
;
368 LPBITMAPINFO pbmiSafe
;
372 pbmiSafe
= ExAllocatePoolWithTag(PagedPool
, cjMaxInfo
, 'pmTG');
373 if (!pbmiSafe
) return 0;
377 ProbeForRead(bmi
, cjMaxInfo
, 1);
378 ProbeForRead(Bits
, cjMaxBits
, 1);
379 RtlCopyMemory(pbmiSafe
, bmi
, cjMaxInfo
);
382 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
384 Status
= _SEH2_GetExceptionCode();
388 if (!NT_SUCCESS(Status
))
393 pDC
= DC_LockDc(hDC
);
396 EngSetLastError(ERROR_INVALID_HANDLE
);
399 if (pDC
->dctype
== DC_TYPE_INFO
)
405 pSurf
= pDC
->dclevel
.pSurface
;
407 pDestSurf
= pSurf
? &pSurf
->SurfObj
: NULL
;
409 ScanLines
= min(ScanLines
, abs(bmi
->bmiHeader
.biHeight
) - StartScan
);
413 if (bTransformCoordinates
)
415 IntLPtoDP(pDC
, (LPPOINT
)&rcDest
, 2);
417 rcDest
.left
+= pDC
->ptlDCOrig
.x
;
418 rcDest
.top
+= pDC
->ptlDCOrig
.y
;
419 rcDest
.right
= rcDest
.left
+ Width
;
420 rcDest
.bottom
= rcDest
.top
+ Height
;
421 rcDest
.top
+= StartScan
;
426 SourceSize
.cx
= bmi
->bmiHeader
.biWidth
;
427 SourceSize
.cy
= ScanLines
;
429 //DIBWidth = WIDTH_BYTES_ALIGN32(SourceSize.cx, bmi->bmiHeader.biBitCount);
431 hSourceBitmap
= GreCreateBitmapEx(bmi
->bmiHeader
.biWidth
,
434 BitmapFormat(bmi
->bmiHeader
.biBitCount
,
435 bmi
->bmiHeader
.biCompression
),
436 bmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
437 bmi
->bmiHeader
.biSizeImage
,
443 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
444 Status
= STATUS_NO_MEMORY
;
448 pSourceSurf
= EngLockSurface((HSURF
)hSourceBitmap
);
451 Status
= STATUS_UNSUCCESSFUL
;
457 /* Create a palette for the DIB */
458 hpalDIB
= BuildDIBPalette(bmi
);
461 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
462 Status
= STATUS_NO_MEMORY
;
466 /* Lock the DIB palette */
467 ppalDIB
= PALETTE_ShareLockPalette(hpalDIB
);
470 EngSetLastError(ERROR_INVALID_HANDLE
);
471 Status
= STATUS_UNSUCCESSFUL
;
475 /* Initialize EXLATEOBJ */
476 EXLATEOBJ_vInitialize(&exlo
,
479 RGB(0xff, 0xff, 0xff),
480 pDC
->pdcattr
->crBackgroundClr
,
481 pDC
->pdcattr
->crForegroundClr
);
484 DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
485 rcDest
.left
, rcDest
.top
, rcDest
.right
, rcDest
.bottom
,
486 ptSource
.x
, ptSource
.y
, SourceSize
.cx
, SourceSize
.cy
);
487 Status
= IntEngBitBlt(pDestSurf
,
490 pDC
->rosdc
.CombinedClip
,
497 ROP4_FROM_INDEX(R3_OPINDEX_SRCCOPY
));
499 /* Cleanup EXLATEOBJ */
500 EXLATEOBJ_vCleanup(&exlo
);
503 if (NT_SUCCESS(Status
))
508 if (ppalDIB
) PALETTE_ShareUnlockPalette(ppalDIB
);
510 if (pSourceSurf
) EngUnlockSurface(pSourceSurf
);
511 if (hSourceBitmap
) EngDeleteSurface((HSURF
)hSourceBitmap
);
512 if (hpalDIB
) GreDeleteObject(hpalDIB
);
515 ExFreePool(pbmiSafe
);
520 /* Converts a device-dependent bitmap to a DIB */
523 NtGdiGetDIBitsInternal(
534 BITMAPCOREINFO
* pbmci
= NULL
;
535 PSURFACE psurf
= NULL
;
541 RGBTRIPLE
* rgbTriples
;
544 NTSTATUS Status
= STATUS_SUCCESS
;
546 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
548 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
553 /* Probe for read and write */
554 ProbeForRead(Info
, MaxInfo
, 1);
555 ProbeForWrite(Info
, MaxInfo
, 1);
556 if (Bits
) ProbeForWrite(Bits
, MaxBits
, 1);
558 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
560 Status
= _SEH2_GetExceptionCode();
564 if (!NT_SUCCESS(Status
))
569 colorPtr
= (LPBYTE
)Info
+ Info
->bmiHeader
.biSize
;
570 rgbTriples
= colorPtr
;
573 bitmap_type
= DIB_GetBitmapInfo(&Info
->bmiHeader
,
580 if(bitmap_type
== -1)
582 DPRINT("Wrong bitmap format\n");
583 EngSetLastError(ERROR_INVALID_PARAMETER
);
586 else if(bitmap_type
== 0)
588 /* We need a BITMAPINFO to create a DIB, but we have to fill
589 * the BITMAPCOREINFO we're provided */
590 pbmci
= (BITMAPCOREINFO
*)Info
;
591 Info
= DIB_ConvertBitmapInfo((BITMAPINFO
*)pbmci
, Usage
);
594 DPRINT1("Error, could not convert the BITMAPCOREINFO!\n");
597 rgbQuads
= Info
->bmiColors
;
600 pDC
= DC_LockDc(hDC
);
601 if (pDC
== NULL
|| pDC
->dctype
== DC_TYPE_INFO
)
607 /* Get a pointer to the source bitmap object */
608 psurf
= SURFACE_ShareLockSurface(hBitmap
);
615 /* Fill in the structure */
618 case 0: /* Only info */
621 pbmci
->bmciHeader
.bcWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
622 pbmci
->bmciHeader
.bcHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
623 -psurf
->SurfObj
.sizlBitmap
.cy
:
624 psurf
->SurfObj
.sizlBitmap
.cy
;
625 pbmci
->bmciHeader
.bcPlanes
= 1;
626 pbmci
->bmciHeader
.bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
628 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
629 Info
->bmiHeader
.biHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
630 -psurf
->SurfObj
.sizlBitmap
.cy
:
631 psurf
->SurfObj
.sizlBitmap
.cy
;;
632 Info
->bmiHeader
.biPlanes
= 1;
633 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
634 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes( Info
->bmiHeader
.biWidth
,
635 Info
->bmiHeader
.biHeight
,
636 Info
->bmiHeader
.biBitCount
);
639 switch(Info
->bmiHeader
.biBitCount
)
643 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
646 Info
->bmiHeader
.biCompression
= BI_RGB
;
650 else if(Info
->bmiHeader
.biBitCount
> 8)
652 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
656 Info
->bmiHeader
.biCompression
= BI_RGB
;
658 Info
->bmiHeader
.biXPelsPerMeter
= 0;
659 Info
->bmiHeader
.biYPelsPerMeter
= 0;
660 Info
->bmiHeader
.biClrUsed
= 0;
661 Info
->bmiHeader
.biClrImportant
= 0;
662 ScanLines
= abs(Info
->bmiHeader
.biHeight
);
668 Info
->bmiHeader
.biClrUsed
= 0;
670 /* If the bitmap if a DIB section and has the same format than what
671 * we're asked, go ahead! */
672 if((psurf
->hSecure
) &&
673 (BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == bpp
))
675 if(Usage
== DIB_RGB_COLORS
)
677 unsigned int colors
= min(psurf
->ppal
->NumColors
, 1 << bpp
);
681 for(i
=0; i
< colors
; i
++)
683 rgbTriples
[i
].rgbtRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
684 rgbTriples
[i
].rgbtGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
685 rgbTriples
[i
].rgbtBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
688 if(colors
!= 1 << bpp
) Info
->bmiHeader
.biClrUsed
= colors
;
689 for(i
=0; i
< colors
; i
++)
691 rgbQuads
[i
].rgbRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
692 rgbQuads
[i
].rgbGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
693 rgbQuads
[i
].rgbBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
698 for(i
=0; i
< 1 << bpp
; i
++)
700 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
701 ((WORD
*)rgbQuads
)[i
] = i
;
707 if(Usage
== DIB_PAL_COLORS
)
709 for(i
=0; i
< 1 << bpp
; i
++)
711 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
712 ((WORD
*)rgbQuads
)[i
] = i
;
715 else if(bpp
> 1 && bpp
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
))
717 /* For color DDBs in native depth (mono DDBs always have
718 a black/white palette):
719 Generate the color map from the selected palette */
720 PPALETTE pDcPal
= PALETTE_ShareLockPalette(pDC
->dclevel
.hpal
);
726 for (i
= 0; i
< pDcPal
->NumColors
; i
++)
730 rgbTriples
[i
].rgbtRed
= pDcPal
->IndexedColors
[i
].peRed
;
731 rgbTriples
[i
].rgbtGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
732 rgbTriples
[i
].rgbtBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
735 rgbQuads
[i
].rgbRed
= pDcPal
->IndexedColors
[i
].peRed
;
736 rgbQuads
[i
].rgbGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
737 rgbQuads
[i
].rgbBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
738 rgbQuads
[i
].rgbReserved
= 0;
740 PALETTE_ShareUnlockPalette(pDcPal
);
749 rgbTriples
[0].rgbtRed
= rgbTriples
[0].rgbtGreen
=
750 rgbTriples
[0].rgbtBlue
= 0;
751 rgbTriples
[1].rgbtRed
= rgbTriples
[1].rgbtGreen
=
752 rgbTriples
[1].rgbtBlue
= 0xff;
754 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
=
755 rgbQuads
[0].rgbBlue
= 0;
756 rgbQuads
[0].rgbReserved
= 0;
757 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
=
758 rgbQuads
[1].rgbBlue
= 0xff;
759 rgbQuads
[1].rgbReserved
= 0;
764 RtlCopyMemory(rgbTriples
, EGAColorsTriples
, sizeof(EGAColorsTriples
));
765 RtlCopyMemory(rgbQuads
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
775 RGBTRIPLE
*colorTriple
;
777 RtlCopyMemory(rgbTriples
, DefLogPaletteTriples
,
778 10 * sizeof(RGBTRIPLE
));
779 RtlCopyMemory(rgbTriples
+ 246, DefLogPaletteTriples
+ 10,
780 10 * sizeof(RGBTRIPLE
));
781 colorTriple
= rgbTriples
+ 10;
782 for(r
= 0; r
<= 5; r
++) /* FIXME */
784 for(g
= 0; g
<= 5; g
++)
786 for(b
= 0; b
<= 5; b
++)
788 colorTriple
->rgbtRed
= (r
* 0xff) / 5;
789 colorTriple
->rgbtGreen
= (g
* 0xff) / 5;
790 colorTriple
->rgbtBlue
= (b
* 0xff) / 5;
796 memcpy(rgbQuads
, DefLogPaletteQuads
,
797 10 * sizeof(RGBQUAD
));
798 memcpy(rgbQuads
+ 246, DefLogPaletteQuads
+ 10,
799 10 * sizeof(RGBQUAD
));
800 color
= rgbQuads
+ 10;
801 for(r
= 0; r
<= 5; r
++) /* FIXME */
803 for(g
= 0; g
<= 5; g
++)
805 for(b
= 0; b
<= 5; b
++)
807 color
->rgbRed
= (r
* 0xff) / 5;
808 color
->rgbGreen
= (g
* 0xff) / 5;
809 color
->rgbBlue
= (b
* 0xff) / 5;
810 color
->rgbReserved
= 0;
822 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
824 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
825 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
826 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
831 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
835 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
836 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
837 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
841 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
842 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
843 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
850 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
854 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
855 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
856 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
860 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
861 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
862 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
867 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(width
, height
, bpp
);
869 if(Bits
&& ScanLines
)
871 /* Create a DIBSECTION, blt it, profit */
880 if (StartScan
> psurf
->SurfObj
.sizlBitmap
.cy
)
887 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
891 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
892 Info
->bmiHeader
.biHeight
= height
< 0 ?
893 -ScanLines
: ScanLines
;
895 hBmpDest
= DIB_CreateDIBSection(pDC
, Info
, Usage
, &pDIBits
, NULL
, 0, 0);
897 Info
->bmiHeader
.biWidth
= width
;
898 Info
->bmiHeader
.biHeight
= height
;
902 DPRINT1("Unable to create a DIB Section!\n");
903 EngSetLastError(ERROR_INVALID_PARAMETER
);
908 psurfDest
= SURFACE_ShareLockSurface(hBmpDest
);
912 rcDest
.bottom
= ScanLines
;
913 rcDest
.right
= psurf
->SurfObj
.sizlBitmap
.cx
;
921 if(ScanLines
<= StartScan
)
924 SURFACE_ShareUnlockSurface(psurfDest
);
925 GreDeleteObject(hBmpDest
);
929 ScanLines
-= StartScan
;
933 srcPoint
.y
= StartScan
;
936 EXLATEOBJ_vInitialize(&exlo
, psurf
->ppal
, psurfDest
->ppal
, 0xffffff, 0xffffff, 0);
938 ret
= IntEngCopyBits(&psurfDest
->SurfObj
,
945 SURFACE_ShareUnlockSurface(psurfDest
);
951 Status
= STATUS_SUCCESS
;
954 RtlCopyMemory(Bits
, pDIBits
, DIB_GetDIBImageBytes (width
, ScanLines
, bpp
));
956 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
958 Status
= _SEH2_GetExceptionCode();
962 if(!NT_SUCCESS(Status
))
964 DPRINT1("Unable to copy bits to the user provided pointer\n");
969 GreDeleteObject(hBmpDest
);
970 EXLATEOBJ_vCleanup(&exlo
);
972 else ScanLines
= abs(height
);
976 if(pDC
) DC_UnlockDc(pDC
);
977 if(psurf
) SURFACE_ShareUnlockSurface(psurf
);
978 if(pbmci
) DIB_FreeConvertedBitmapInfo(Info
, (BITMAPINFO
*)pbmci
);
983 #define ROP_TO_ROP4(Rop) ((Rop) >> 16)
988 NtGdiStretchDIBitsInternal(
998 IN OPTIONAL LPBYTE pjInit
,
999 IN LPBITMAPINFO pbmi
,
1001 IN DWORD dwRop
, // MS ntgdi.h says dwRop4(?)
1006 BOOL bResult
= FALSE
;
1011 PSURFACE psurfTmp
= 0, psurfDst
= 0;
1012 HPALETTE hpalDIB
= 0;
1013 PPALETTE ppalDIB
= 0;
1017 if (!(pdc
= DC_LockDc(hdc
)))
1019 EngSetLastError(ERROR_INVALID_HANDLE
);
1023 /* Transform dest size */
1026 IntLPtoDP(pdc
, (POINTL
*)&sizel
, 1);
1029 /* Check if we can use NtGdiSetDIBitsToDeviceInternal */
1030 if (sizel
.cx
== cxSrc
&& sizel
.cy
== cySrc
&& dwRop
== SRCCOPY
)
1033 return NtGdiSetDIBitsToDeviceInternal(hdc
,
1051 pvBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, 'pmeT');
1059 ProbeForRead(pjInit
, cjMaxBits
, 1);
1060 RtlCopyMemory(pvBits
, pjInit
, cjMaxBits
);
1062 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1064 _SEH2_YIELD(return 0);
1068 /* FIXME: Locking twice is cheesy, coord tranlation in UM will fix it */
1069 if (!(pdc
= DC_LockDc(hdc
)))
1071 DPRINT1("Could not lock dc\n");
1072 EngSetLastError(ERROR_INVALID_HANDLE
);
1076 psurfDst
= pdc
->dclevel
.pSurface
;
1084 /* Calculate source and destination rect */
1087 rcSrc
.right
= xSrc
+ abs(cxSrc
);
1088 rcSrc
.bottom
= ySrc
+ abs(cySrc
);
1091 rcDst
.right
= rcDst
.left
+ cxDst
;
1092 rcDst
.bottom
= rcDst
.top
+ cyDst
;
1093 IntLPtoDP(pdc
, (POINTL
*)&rcDst
, 2);
1094 RECTL_vOffsetRect(&rcDst
, pdc
->ptlDCOrig
.x
, pdc
->ptlDCOrig
.y
);
1096 hbmTmp
= GreCreateBitmapEx(pbmi
->bmiHeader
.biWidth
,
1097 pbmi
->bmiHeader
.biHeight
,
1099 BitmapFormat(pbmi
->bmiHeader
.biBitCount
,
1100 pbmi
->bmiHeader
.biCompression
),
1101 pbmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
1102 pbmi
->bmiHeader
.biSizeImage
,
1112 psurfTmp
= SURFACE_ShareLockSurface(hbmTmp
);
1119 /* Create a palette for the DIB */
1120 hpalDIB
= BuildDIBPalette(pbmi
);
1127 /* Lock the DIB palette */
1128 ppalDIB
= PALETTE_ShareLockPalette(hpalDIB
);
1135 /* Initialize XLATEOBJ */
1136 EXLATEOBJ_vInitialize(&exlo
,
1139 RGB(0xff, 0xff, 0xff),
1140 pdc
->pdcattr
->crBackgroundClr
,
1141 pdc
->pdcattr
->crForegroundClr
);
1143 /* Prepare DC for blit */
1144 DC_vPrepareDCsForBlit(pdc
, rcDst
, NULL
, rcSrc
);
1146 /* Perform the stretch operation */
1147 bResult
= IntEngStretchBlt(&psurfDst
->SurfObj
,
1150 pdc
->rosdc
.CombinedClip
,
1155 &pdc
->eboFill
.BrushObject
,
1157 ROP_TO_ROP4(dwRop
));
1160 DC_vFinishBlit(pdc
, NULL
);
1161 EXLATEOBJ_vCleanup(&exlo
);
1163 if (ppalDIB
) PALETTE_ShareUnlockPalette(ppalDIB
);
1164 if (hpalDIB
) GreDeleteObject(hpalDIB
);
1165 if (psurfTmp
) SURFACE_ShareUnlockSurface(psurfTmp
);
1166 if (hbmTmp
) GreDeleteObject(hbmTmp
);
1167 if (pdc
) DC_UnlockDc(pdc
);
1168 ExFreePoolWithTag(pvBits
, 'pmeT');
1189 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1190 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1192 if (bpp
!= 1) fColor
= TRUE
;
1193 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1196 const RGBQUAD
*rgb
= (RGBQUAD
*)((PBYTE
)data
+ data
->bmiHeader
.biSize
);
1197 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1199 // Check if the first color of the colormap is black
1200 if ((col
== RGB(0, 0, 0)))
1203 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1205 // If the second color is white, create a monochrome bitmap
1206 fColor
= (col
!= RGB(0xff,0xff,0xff));
1211 // Now create the bitmap
1214 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1218 handle
= GreCreateBitmap(width
,
1228 if (NULL
!= handle
&& CBM_INIT
== init
)
1230 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1236 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1237 // The DDB that is created will be whatever bit depth your reference DC is
1240 NtGdiCreateDIBitmapInternal(
1245 IN OPTIONAL LPBYTE pjInit
,
1246 IN OPTIONAL LPBITMAPINFO pbmi
,
1248 IN UINT cjMaxInitInfo
,
1253 NTSTATUS Status
= STATUS_SUCCESS
;
1254 PBYTE safeBits
= NULL
;
1255 HBITMAP hbmResult
= NULL
;
1257 if(pjInit
&& (fInit
== CBM_INIT
))
1259 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1262 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1269 if(pbmi
) ProbeForRead(pbmi
, cjMaxInitInfo
, 1);
1270 if(pjInit
&& (fInit
== CBM_INIT
))
1272 ProbeForRead(pjInit
, cjMaxBits
, 1);
1273 RtlCopyMemory(safeBits
, pjInit
, cjMaxBits
);
1276 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1278 Status
= _SEH2_GetExceptionCode();
1282 if(!NT_SUCCESS(Status
))
1284 SetLastNtError(Status
);
1288 hbmResult
= GreCreateDIBitmapInternal(hDc
,
1299 if (safeBits
) ExFreePoolWithTag(safeBits
, TAG_DIB
);
1305 GreCreateDIBitmapInternal(
1310 IN OPTIONAL LPBYTE pjInit
,
1311 IN OPTIONAL PBITMAPINFO pbmi
,
1321 if (!hDc
) /* 1bpp monochrome bitmap */
1323 // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1324 hdcDest
= NtGdiCreateCompatibleDC(0);
1335 Dc
= DC_LockDc(hdcDest
);
1338 EngSetLastError(ERROR_INVALID_HANDLE
);
1341 /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
1342 * if bpp != 1 and ignore the real value that was passed */
1344 bpp
= pbmi
->bmiHeader
.biBitCount
;
1347 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1352 NtGdiDeleteObjectApp(hdcDest
);
1360 NtGdiCreateDIBSection(
1362 IN OPTIONAL HANDLE hSection
,
1368 IN ULONG_PTR dwColorSpace
,
1371 HBITMAP hbitmap
= 0;
1373 BOOL bDesktopDC
= FALSE
;
1374 NTSTATUS Status
= STATUS_SUCCESS
;
1376 if (!bmi
) return hbitmap
; // Make sure.
1380 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
1381 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
1382 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, Usage
), 1);
1384 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1386 Status
= _SEH2_GetExceptionCode();
1390 if(!NT_SUCCESS(Status
))
1392 SetLastNtError(Status
);
1396 // If the reference hdc is null, take the desktop dc
1399 hDC
= NtGdiCreateCompatibleDC(0);
1403 if ((dc
= DC_LockDc(hDC
)))
1405 hbitmap
= DIB_CreateDIBSection(dc
,
1416 EngSetLastError(ERROR_INVALID_HANDLE
);
1420 NtGdiDeleteObjectApp(hDC
);
1427 DIB_CreateDIBSection(
1429 CONST BITMAPINFO
*bmi
,
1437 SURFACE
*bmp
= NULL
;
1438 void *mapBits
= NULL
;
1441 // Fill BITMAP32 structure with DIB data
1442 CONST BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1449 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1450 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1451 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1453 /* CreateDIBSection should fail for compressed formats */
1454 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1456 DPRINT1("no compressed format allowed\n");
1457 return (HBITMAP
)NULL
;
1460 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1462 bm
.bmWidth
= bi
->biWidth
;
1463 bm
.bmHeight
= effHeight
;
1464 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: WIDTH_BYTES_ALIGN32(bm
.bmWidth
, bi
->biBitCount
);
1466 bm
.bmPlanes
= bi
->biPlanes
;
1467 bm
.bmBitsPixel
= bi
->biBitCount
;
1470 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1471 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1472 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
&& bi
->biCompression
!= BI_BITFIELDS
1473 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1477 SYSTEM_BASIC_INFORMATION Sbi
;
1480 LARGE_INTEGER SectionOffset
;
1483 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1487 if (!NT_SUCCESS(Status
))
1489 DPRINT1("ZwQuerySystemInformation failed (0x%lx)\n", Status
);
1493 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1494 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1496 SectionOffset
.LowPart
= mapOffset
;
1497 SectionOffset
.HighPart
= 0;
1499 Status
= ZwMapViewOfSection(section
,
1509 if (!NT_SUCCESS(Status
))
1511 DPRINT1("ZwMapViewOfSection failed (0x%lx)\n", Status
);
1512 EngSetLastError(ERROR_INVALID_PARAMETER
);
1516 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1518 else if (ovr_pitch
&& offset
)
1519 bm
.bmBits
= (LPVOID
) offset
;
1523 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1526 DPRINT1("Failed to allocate memory\n");
1531 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1532 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1534 if (usage
== DIB_PAL_COLORS
)
1539 ppalDc
= PALETTE_ShareLockPalette(dc
->dclevel
.hpal
);
1540 hpal
= DIB_MapPaletteColors(ppalDc
, bmi
);
1541 PALETTE_ShareUnlockPalette(ppalDc
);
1545 /* For DIB Brushes */
1546 DPRINT1("FIXME: Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
1548 hpal
= (HPALETTE
) 0xFFFFFFFF;
1553 hpal
= BuildDIBPalette(bmi
);
1558 DPRINT1("Error: Could not create a palette for the DIB.\n");
1562 // Create Device Dependent Bitmap and add DIB pointer
1563 //Size.cx = bm.bmWidth;
1564 //Size.cy = abs(bm.bmHeight);
1565 res
= GreCreateBitmapEx(bm
.bmWidth
,
1568 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1569 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1570 ((bi
->biHeight
< 0) ? BMF_TOPDOWN
: 0),
1576 DPRINT1("GreCreateBitmapEx failed\n");
1577 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1580 bmp
= SURFACE_ShareLockSurface(res
); // HACK
1583 DPRINT1("SURFACE_LockSurface failed\n");
1584 EngSetLastError(ERROR_INVALID_HANDLE
);
1588 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1589 table between the DIB and the X physical device. Obviously,
1590 this is left out of the ReactOS implementation. Instead,
1591 we call NtGdiSetDIBColorTable. */
1592 bmp
->hDIBSection
= section
;
1593 bmp
->hSecure
= hSecure
;
1594 bmp
->dwOffset
= offset
;
1595 bmp
->flags
= API_BITMAP
;
1596 bmp
->biClrImportant
= bi
->biClrImportant
;
1597 bmp
->SurfObj
.fjBitmap
&= ~BMF_DONT_FREE
;
1600 if(hpal
!= (HPALETTE
)0xFFFFFFFF)
1602 bmp
->ppal
= PALETTE_ShareLockPalette(hpal
);
1603 /* Lazy delete hpal, it will be freed at surface release */
1604 GreDeleteObject(hpal
);
1607 // Clean up in case of errors
1609 if (!res
|| !bmp
|| !bm
.bmBits
)
1611 DPRINT("Got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1614 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1617 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1621 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1629 GreDeleteObject(res
);
1636 SURFACE_ShareUnlockSurface(bmp
);
1639 // Return BITMAP handle and storage location
1640 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1648 /***********************************************************************
1651 * Get the info from a bitmap header.
1652 * Return 0 for COREHEADER, 1 for INFOHEADER, -1 for error.
1656 DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
1657 LONG
*height
, WORD
*planes
, WORD
*bpp
, DWORD
*compr
, DWORD
*size
)
1659 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
1661 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
1662 *width
= core
->bcWidth
;
1663 *height
= core
->bcHeight
;
1664 *planes
= core
->bcPlanes
;
1665 *bpp
= core
->bcBitCount
;
1670 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
)) /* Assume BITMAPINFOHEADER */
1672 *width
= header
->biWidth
;
1673 *height
= header
->biHeight
;
1674 *planes
= header
->biPlanes
;
1675 *bpp
= header
->biBitCount
;
1676 *compr
= header
->biCompression
;
1677 *size
= header
->biSizeImage
;
1680 DPRINT1("(%d): unknown/wrong size for header\n", header
->biSize
);
1684 /***********************************************************************
1685 * DIB_GetDIBImageBytes
1687 * Return the number of bytes used to hold the image in a DIB bitmap.
1688 * 11/16/1999 (RJJ) lifted from wine
1691 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1693 return WIDTH_BYTES_ALIGN32(width
, depth
) * (height
< 0 ? -height
: height
);
1696 /***********************************************************************
1697 * DIB_BitmapInfoSize
1699 * Return the size of the bitmap info structure including color table.
1700 * 11/16/1999 (RJJ) lifted from wine
1703 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1705 unsigned int colors
, size
, masks
= 0;
1707 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1709 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
1710 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1711 return sizeof(BITMAPCOREHEADER
) + colors
*
1712 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1714 else /* Assume BITMAPINFOHEADER */
1716 colors
= info
->bmiHeader
.biClrUsed
;
1717 if (colors
> 256) colors
= 256;
1718 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
1719 colors
= 1 << info
->bmiHeader
.biBitCount
;
1720 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
1721 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
1722 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1728 DIB_MapPaletteColors(PPALETTE ppal
, CONST BITMAPINFO
* lpbmi
)
1730 PALETTEENTRY
* ppalEntries
;
1735 if (!(ppal
->flFlags
& PAL_INDEXED
))
1740 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1741 if (lpbmi
->bmiHeader
.biClrUsed
)
1743 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1746 /* Don't have more colors than we need */
1747 nNumColors
= min(ppal
->NumColors
, nNumColors
);
1749 ppalEntries
= ExAllocatePoolWithTag(PagedPool
, sizeof(PALETTEENTRY
) * nNumColors
, TAG_COLORMAP
);
1750 if (ppalEntries
== NULL
)
1752 DPRINT1("Could not allocate palette entries\n");
1756 lpIndex
= (USHORT
*)((PBYTE
)lpbmi
+ lpbmi
->bmiHeader
.biSize
);
1758 for (i
= 0; i
< nNumColors
; i
++)
1760 if (*lpIndex
< ppal
->NumColors
)
1762 ppalEntries
[i
] = ppal
->IndexedColors
[*lpIndex
];
1766 ppalEntries
[i
].peRed
= 0;
1767 ppalEntries
[i
].peGreen
= 0;
1768 ppalEntries
[i
].peBlue
= 0;
1769 ppalEntries
[i
].peFlags
= 0;
1775 hpal
= PALETTE_AllocPalette(PAL_INDEXED
, nNumColors
, (ULONG
*)ppalEntries
, 0, 0, 0);
1777 ExFreePoolWithTag(ppalEntries
, TAG_COLORMAP
);
1784 BuildDIBPalette(CONST BITMAPINFO
*bmi
)
1789 ULONG RedMask
= 0, GreenMask
= 0, BlueMask
= 0;
1790 PDWORD pdwColors
= (PDWORD
)((PBYTE
)bmi
+ bmi
->bmiHeader
.biSize
);
1793 // Determine Bits Per Pixel
1794 bits
= bmi
->bmiHeader
.biBitCount
;
1796 // Determine paletteType from Bits Per Pixel
1799 paletteType
= PAL_INDEXED
;
1800 RedMask
= GreenMask
= BlueMask
= 0;
1802 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1804 paletteType
= PAL_BITFIELDS
;
1805 if (bmi
->bmiHeader
.biSize
>= sizeof(BITMAPV4HEADER
))
1807 PBITMAPV4HEADER pV4Header
= (PBITMAPV4HEADER
)&bmi
->bmiHeader
;
1808 RedMask
= pV4Header
->bV4RedMask
;
1809 GreenMask
= pV4Header
->bV4GreenMask
;
1810 BlueMask
= pV4Header
->bV4BlueMask
;
1814 RedMask
= pdwColors
[0];
1815 GreenMask
= pdwColors
[1];
1816 BlueMask
= pdwColors
[2];
1821 paletteType
= PAL_BITFIELDS
;
1825 paletteType
|= PAL_RGB16_555
;
1833 paletteType
|= PAL_BGR
;
1835 GreenMask
= 0x00FF00;
1836 BlueMask
= 0x0000FF;
1841 if (bmi
->bmiHeader
.biClrUsed
== 0)
1843 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1847 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1850 if (PAL_INDEXED
== paletteType
)
1852 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)pdwColors
);
1856 hPal
= PALETTE_AllocPalette(paletteType
, 0,
1858 RedMask
, GreenMask
, BlueMask
);
1864 /* Converts a BITMAPCOREINFO to a BITMAPINFO structure,
1865 * or does nothing if it's already a BITMAPINFO (or V4 or V5) */
1868 DIB_ConvertBitmapInfo (CONST BITMAPINFO
* pbmi
, DWORD Usage
)
1870 CONST BITMAPCOREINFO
* pbmci
= (BITMAPCOREINFO
*)pbmi
;
1871 BITMAPINFO
* pNewBmi
;
1872 UINT numColors
= 0, ColorsSize
= 0;
1874 if(pbmi
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
)) return (BITMAPINFO
*)pbmi
;
1875 if(pbmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) return NULL
;
1877 if(pbmci
->bmciHeader
.bcBitCount
<= 8)
1879 numColors
= 1 << pbmci
->bmciHeader
.bcBitCount
;
1880 if(Usage
== DIB_PAL_COLORS
)
1882 ColorsSize
= numColors
* sizeof(WORD
);
1886 ColorsSize
= numColors
* sizeof(RGBQUAD
);
1889 else if (Usage
== DIB_PAL_COLORS
)
1891 /* Invalid at high-res */
1895 pNewBmi
= ExAllocatePoolWithTag(PagedPool
, sizeof(BITMAPINFOHEADER
) + ColorsSize
, TAG_DIB
);
1896 if(!pNewBmi
) return NULL
;
1898 RtlZeroMemory(pNewBmi
, sizeof(BITMAPINFOHEADER
) + ColorsSize
);
1900 pNewBmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1901 pNewBmi
->bmiHeader
.biBitCount
= pbmci
->bmciHeader
.bcBitCount
;
1902 pNewBmi
->bmiHeader
.biWidth
= pbmci
->bmciHeader
.bcWidth
;
1903 pNewBmi
->bmiHeader
.biHeight
= pbmci
->bmciHeader
.bcHeight
;
1904 pNewBmi
->bmiHeader
.biPlanes
= pbmci
->bmciHeader
.bcPlanes
;
1905 pNewBmi
->bmiHeader
.biCompression
= BI_RGB
;
1906 pNewBmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(pNewBmi
->bmiHeader
.biWidth
,
1907 pNewBmi
->bmiHeader
.biHeight
,
1908 pNewBmi
->bmiHeader
.biBitCount
);
1910 if(Usage
== DIB_PAL_COLORS
)
1912 RtlCopyMemory(pNewBmi
->bmiColors
, pbmci
->bmciColors
, ColorsSize
);
1917 for(i
=0; i
<numColors
; i
++)
1919 pNewBmi
->bmiColors
[i
].rgbRed
= pbmci
->bmciColors
[i
].rgbtRed
;
1920 pNewBmi
->bmiColors
[i
].rgbGreen
= pbmci
->bmciColors
[i
].rgbtGreen
;
1921 pNewBmi
->bmiColors
[i
].rgbBlue
= pbmci
->bmciColors
[i
].rgbtBlue
;
1928 /* Frees a BITMAPINFO created with DIB_ConvertBitmapInfo */
1931 DIB_FreeConvertedBitmapInfo(BITMAPINFO
* converted
, BITMAPINFO
* orig
)
1933 if(converted
!= orig
)
1934 ExFreePoolWithTag(converted
, TAG_DIB
);