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
< (1UL << biBitCount
)))
146 if (StartIndex
+ Entries
> (1UL << 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
;
542 RGBTRIPLE
* rgbTriples
;
545 NTSTATUS Status
= STATUS_SUCCESS
;
547 DPRINT("Entered NtGdiGetDIBitsInternal()\n");
549 if ((Usage
&& Usage
!= DIB_PAL_COLORS
) || !Info
|| !hBitmap
)
554 /* Probe for read and write */
555 ProbeForRead(Info
, MaxInfo
, 1);
556 ProbeForWrite(Info
, MaxInfo
, 1);
557 if (Bits
) ProbeForWrite(Bits
, MaxBits
, 1);
559 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
561 Status
= _SEH2_GetExceptionCode();
565 if (!NT_SUCCESS(Status
))
570 colorPtr
= (LPBYTE
)Info
+ Info
->bmiHeader
.biSize
;
571 rgbTriples
= colorPtr
;
574 bitmap_type
= DIB_GetBitmapInfo(&Info
->bmiHeader
,
581 if(bitmap_type
== -1)
583 DPRINT("Wrong bitmap format\n");
584 EngSetLastError(ERROR_INVALID_PARAMETER
);
587 else if(bitmap_type
== 0)
589 /* We need a BITMAPINFO to create a DIB, but we have to fill
590 * the BITMAPCOREINFO we're provided */
591 pbmci
= (BITMAPCOREINFO
*)Info
;
592 Info
= DIB_ConvertBitmapInfo((BITMAPINFO
*)pbmci
, Usage
);
595 DPRINT1("Error, could not convert the BITMAPCOREINFO!\n");
598 rgbQuads
= Info
->bmiColors
;
601 pDC
= DC_LockDc(hDC
);
602 if (pDC
== NULL
|| pDC
->dctype
== DC_TYPE_INFO
)
608 /* Get a pointer to the source bitmap object */
609 psurf
= SURFACE_ShareLockSurface(hBitmap
);
616 /* Fill in the structure */
619 case 0: /* Only info */
622 pbmci
->bmciHeader
.bcWidth
= (WORD
)psurf
->SurfObj
.sizlBitmap
.cx
;
623 pbmci
->bmciHeader
.bcHeight
= (WORD
)((psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
624 -psurf
->SurfObj
.sizlBitmap
.cy
:
625 psurf
->SurfObj
.sizlBitmap
.cy
);
626 pbmci
->bmciHeader
.bcPlanes
= 1;
627 pbmci
->bmciHeader
.bcBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
629 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
630 Info
->bmiHeader
.biHeight
= (psurf
->SurfObj
.fjBitmap
& BMF_TOPDOWN
) ?
631 -psurf
->SurfObj
.sizlBitmap
.cy
:
632 psurf
->SurfObj
.sizlBitmap
.cy
;;
633 Info
->bmiHeader
.biPlanes
= 1;
634 Info
->bmiHeader
.biBitCount
= BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
);
635 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes( Info
->bmiHeader
.biWidth
,
636 Info
->bmiHeader
.biHeight
,
637 Info
->bmiHeader
.biBitCount
);
640 switch(Info
->bmiHeader
.biBitCount
)
644 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
647 Info
->bmiHeader
.biCompression
= BI_RGB
;
651 else if(Info
->bmiHeader
.biBitCount
> 8)
653 Info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
657 Info
->bmiHeader
.biCompression
= BI_RGB
;
659 Info
->bmiHeader
.biXPelsPerMeter
= 0;
660 Info
->bmiHeader
.biYPelsPerMeter
= 0;
661 Info
->bmiHeader
.biClrUsed
= 0;
662 Info
->bmiHeader
.biClrImportant
= 0;
663 ScanLines
= abs(Info
->bmiHeader
.biHeight
);
669 Info
->bmiHeader
.biClrUsed
= 0;
671 /* If the bitmap if a DIB section and has the same format than what
672 * we're asked, go ahead! */
673 if((psurf
->hSecure
) &&
674 (BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
) == bpp
))
676 if(Usage
== DIB_RGB_COLORS
)
678 ULONG colors
= min(psurf
->ppal
->NumColors
, 256);
682 for(i
= 0; i
< colors
; i
++)
684 rgbTriples
[i
].rgbtRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
685 rgbTriples
[i
].rgbtGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
686 rgbTriples
[i
].rgbtBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
689 if(colors
!= 256) Info
->bmiHeader
.biClrUsed
= colors
;
690 for(i
= 0; i
< colors
; i
++)
692 rgbQuads
[i
].rgbRed
= psurf
->ppal
->IndexedColors
[i
].peRed
;
693 rgbQuads
[i
].rgbGreen
= psurf
->ppal
->IndexedColors
[i
].peGreen
;
694 rgbQuads
[i
].rgbBlue
= psurf
->ppal
->IndexedColors
[i
].peBlue
;
699 for(i
= 0; i
< 256; i
++)
701 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
702 ((WORD
*)rgbQuads
)[i
] = i
;
708 if(Usage
== DIB_PAL_COLORS
)
710 for(i
= 0; i
< 256; i
++)
712 if(pbmci
) ((WORD
*)rgbTriples
)[i
] = i
;
713 ((WORD
*)rgbQuads
)[i
] = i
;
716 else if(bpp
> 1 && bpp
== BitsPerFormat(psurf
->SurfObj
.iBitmapFormat
))
718 /* For color DDBs in native depth (mono DDBs always have
719 a black/white palette):
720 Generate the color map from the selected palette */
721 PPALETTE pDcPal
= PALETTE_ShareLockPalette(pDC
->dclevel
.hpal
);
727 for (i
= 0; i
< pDcPal
->NumColors
; i
++)
731 rgbTriples
[i
].rgbtRed
= pDcPal
->IndexedColors
[i
].peRed
;
732 rgbTriples
[i
].rgbtGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
733 rgbTriples
[i
].rgbtBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
736 rgbQuads
[i
].rgbRed
= pDcPal
->IndexedColors
[i
].peRed
;
737 rgbQuads
[i
].rgbGreen
= pDcPal
->IndexedColors
[i
].peGreen
;
738 rgbQuads
[i
].rgbBlue
= pDcPal
->IndexedColors
[i
].peBlue
;
739 rgbQuads
[i
].rgbReserved
= 0;
741 PALETTE_ShareUnlockPalette(pDcPal
);
750 rgbTriples
[0].rgbtRed
= rgbTriples
[0].rgbtGreen
=
751 rgbTriples
[0].rgbtBlue
= 0;
752 rgbTriples
[1].rgbtRed
= rgbTriples
[1].rgbtGreen
=
753 rgbTriples
[1].rgbtBlue
= 0xff;
755 rgbQuads
[0].rgbRed
= rgbQuads
[0].rgbGreen
=
756 rgbQuads
[0].rgbBlue
= 0;
757 rgbQuads
[0].rgbReserved
= 0;
758 rgbQuads
[1].rgbRed
= rgbQuads
[1].rgbGreen
=
759 rgbQuads
[1].rgbBlue
= 0xff;
760 rgbQuads
[1].rgbReserved
= 0;
765 RtlCopyMemory(rgbTriples
, EGAColorsTriples
, sizeof(EGAColorsTriples
));
766 RtlCopyMemory(rgbQuads
, EGAColorsQuads
, sizeof(EGAColorsQuads
));
776 RGBTRIPLE
*colorTriple
;
778 RtlCopyMemory(rgbTriples
, DefLogPaletteTriples
,
779 10 * sizeof(RGBTRIPLE
));
780 RtlCopyMemory(rgbTriples
+ 246, DefLogPaletteTriples
+ 10,
781 10 * sizeof(RGBTRIPLE
));
782 colorTriple
= rgbTriples
+ 10;
783 for(r
= 0; r
<= 5; r
++) /* FIXME */
785 for(g
= 0; g
<= 5; g
++)
787 for(b
= 0; b
<= 5; b
++)
789 colorTriple
->rgbtRed
= (r
* 0xff) / 5;
790 colorTriple
->rgbtGreen
= (g
* 0xff) / 5;
791 colorTriple
->rgbtBlue
= (b
* 0xff) / 5;
797 memcpy(rgbQuads
, DefLogPaletteQuads
,
798 10 * sizeof(RGBQUAD
));
799 memcpy(rgbQuads
+ 246, DefLogPaletteQuads
+ 10,
800 10 * sizeof(RGBQUAD
));
801 color
= rgbQuads
+ 10;
802 for(r
= 0; r
<= 5; r
++) /* FIXME */
804 for(g
= 0; g
<= 5; g
++)
806 for(b
= 0; b
<= 5; b
++)
808 color
->rgbRed
= (r
* 0xff) / 5;
809 color
->rgbGreen
= (g
* 0xff) / 5;
810 color
->rgbBlue
= (b
* 0xff) / 5;
811 color
->rgbReserved
= 0;
823 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
825 ((PDWORD
)Info
->bmiColors
)[0] = 0x7c00;
826 ((PDWORD
)Info
->bmiColors
)[1] = 0x03e0;
827 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
832 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
836 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
837 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
838 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
842 ((PDWORD
)Info
->bmiColors
)[0] = 0xf800;
843 ((PDWORD
)Info
->bmiColors
)[1] = 0x07e0;
844 ((PDWORD
)Info
->bmiColors
)[2] = 0x001f;
851 if (Info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
855 ((PDWORD
)Info
->bmiColors
)[0] = psurf
->ppal
->RedMask
;
856 ((PDWORD
)Info
->bmiColors
)[1] = psurf
->ppal
->GreenMask
;
857 ((PDWORD
)Info
->bmiColors
)[2] = psurf
->ppal
->BlueMask
;
861 ((PDWORD
)Info
->bmiColors
)[0] = 0xff0000;
862 ((PDWORD
)Info
->bmiColors
)[1] = 0x00ff00;
863 ((PDWORD
)Info
->bmiColors
)[2] = 0x0000ff;
868 Info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(width
, height
, bpp
);
870 if(Bits
&& ScanLines
)
872 /* Create a DIBSECTION, blt it, profit */
881 if (StartScan
> (ULONG
)psurf
->SurfObj
.sizlBitmap
.cy
)
888 ScanLines
= min(ScanLines
, psurf
->SurfObj
.sizlBitmap
.cy
- StartScan
);
892 Info
->bmiHeader
.biWidth
= psurf
->SurfObj
.sizlBitmap
.cx
;
893 Info
->bmiHeader
.biHeight
= (height
< 0) ?
894 -(LONG
)ScanLines
: ScanLines
;
896 hBmpDest
= DIB_CreateDIBSection(pDC
, Info
, Usage
, &pDIBits
, NULL
, 0, 0);
898 Info
->bmiHeader
.biWidth
= width
;
899 Info
->bmiHeader
.biHeight
= height
;
903 DPRINT1("Unable to create a DIB Section!\n");
904 EngSetLastError(ERROR_INVALID_PARAMETER
);
909 psurfDest
= SURFACE_ShareLockSurface(hBmpDest
);
913 rcDest
.bottom
= ScanLines
;
914 rcDest
.right
= psurf
->SurfObj
.sizlBitmap
.cx
;
922 if(ScanLines
<= StartScan
)
925 SURFACE_ShareUnlockSurface(psurfDest
);
926 GreDeleteObject(hBmpDest
);
930 ScanLines
-= StartScan
;
934 srcPoint
.y
= StartScan
;
937 EXLATEOBJ_vInitialize(&exlo
, psurf
->ppal
, psurfDest
->ppal
, 0xffffff, 0xffffff, 0);
939 ret
= IntEngCopyBits(&psurfDest
->SurfObj
,
946 SURFACE_ShareUnlockSurface(psurfDest
);
952 Status
= STATUS_SUCCESS
;
955 RtlCopyMemory(Bits
, pDIBits
, DIB_GetDIBImageBytes (width
, ScanLines
, bpp
));
957 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
959 Status
= _SEH2_GetExceptionCode();
963 if(!NT_SUCCESS(Status
))
965 DPRINT1("Unable to copy bits to the user provided pointer\n");
970 GreDeleteObject(hBmpDest
);
971 EXLATEOBJ_vCleanup(&exlo
);
973 else ScanLines
= abs(height
);
977 if(pDC
) DC_UnlockDc(pDC
);
978 if(psurf
) SURFACE_ShareUnlockSurface(psurf
);
979 if(pbmci
) DIB_FreeConvertedBitmapInfo(Info
, (BITMAPINFO
*)pbmci
);
984 #define ROP_TO_ROP4(Rop) ((Rop) >> 16)
989 NtGdiStretchDIBitsInternal(
999 IN OPTIONAL LPBYTE pjInit
,
1000 IN LPBITMAPINFO pbmi
,
1002 IN DWORD dwRop
, // MS ntgdi.h says dwRop4(?)
1007 BOOL bResult
= FALSE
;
1012 PSURFACE psurfTmp
= 0, psurfDst
= 0;
1013 HPALETTE hpalDIB
= 0;
1014 PPALETTE ppalDIB
= 0;
1018 if (!(pdc
= DC_LockDc(hdc
)))
1020 EngSetLastError(ERROR_INVALID_HANDLE
);
1024 /* Transform dest size */
1027 IntLPtoDP(pdc
, (POINTL
*)&sizel
, 1);
1030 /* Check if we can use NtGdiSetDIBitsToDeviceInternal */
1031 if (sizel
.cx
== cxSrc
&& sizel
.cy
== cySrc
&& dwRop
== SRCCOPY
)
1034 return NtGdiSetDIBitsToDeviceInternal(hdc
,
1052 pvBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, 'pmeT');
1060 ProbeForRead(pjInit
, cjMaxBits
, 1);
1061 RtlCopyMemory(pvBits
, pjInit
, cjMaxBits
);
1063 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1065 _SEH2_YIELD(return 0);
1069 /* FIXME: Locking twice is cheesy, coord tranlation in UM will fix it */
1070 if (!(pdc
= DC_LockDc(hdc
)))
1072 DPRINT1("Could not lock dc\n");
1073 EngSetLastError(ERROR_INVALID_HANDLE
);
1077 psurfDst
= pdc
->dclevel
.pSurface
;
1085 /* Calculate source and destination rect */
1088 rcSrc
.right
= xSrc
+ abs(cxSrc
);
1089 rcSrc
.bottom
= ySrc
+ abs(cySrc
);
1092 rcDst
.right
= rcDst
.left
+ cxDst
;
1093 rcDst
.bottom
= rcDst
.top
+ cyDst
;
1094 IntLPtoDP(pdc
, (POINTL
*)&rcDst
, 2);
1095 RECTL_vOffsetRect(&rcDst
, pdc
->ptlDCOrig
.x
, pdc
->ptlDCOrig
.y
);
1097 hbmTmp
= GreCreateBitmapEx(pbmi
->bmiHeader
.biWidth
,
1098 pbmi
->bmiHeader
.biHeight
,
1100 BitmapFormat(pbmi
->bmiHeader
.biBitCount
,
1101 pbmi
->bmiHeader
.biCompression
),
1102 pbmi
->bmiHeader
.biHeight
< 0 ? BMF_TOPDOWN
: 0,
1103 pbmi
->bmiHeader
.biSizeImage
,
1113 psurfTmp
= SURFACE_ShareLockSurface(hbmTmp
);
1120 /* Create a palette for the DIB */
1121 hpalDIB
= BuildDIBPalette(pbmi
);
1128 /* Lock the DIB palette */
1129 ppalDIB
= PALETTE_ShareLockPalette(hpalDIB
);
1136 /* Initialize XLATEOBJ */
1137 EXLATEOBJ_vInitialize(&exlo
,
1140 RGB(0xff, 0xff, 0xff),
1141 pdc
->pdcattr
->crBackgroundClr
,
1142 pdc
->pdcattr
->crForegroundClr
);
1144 /* Prepare DC for blit */
1145 DC_vPrepareDCsForBlit(pdc
, rcDst
, NULL
, rcSrc
);
1147 /* Perform the stretch operation */
1148 bResult
= IntEngStretchBlt(&psurfDst
->SurfObj
,
1151 pdc
->rosdc
.CombinedClip
,
1156 &pdc
->eboFill
.BrushObject
,
1158 ROP_TO_ROP4(dwRop
));
1161 DC_vFinishBlit(pdc
, NULL
);
1162 EXLATEOBJ_vCleanup(&exlo
);
1164 if (ppalDIB
) PALETTE_ShareUnlockPalette(ppalDIB
);
1165 if (hpalDIB
) GreDeleteObject(hpalDIB
);
1166 if (psurfTmp
) SURFACE_ShareUnlockSurface(psurfTmp
);
1167 if (hbmTmp
) GreDeleteObject(hbmTmp
);
1168 if (pdc
) DC_UnlockDc(pdc
);
1169 ExFreePoolWithTag(pvBits
, 'pmeT');
1190 // Check if we should create a monochrome or color bitmap. We create a monochrome bitmap only if it has exactly 2
1191 // colors, which are black followed by white, nothing else. In all other cases, we create a color bitmap.
1193 if (bpp
!= 1) fColor
= TRUE
;
1194 else if ((coloruse
!= DIB_RGB_COLORS
) || (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1197 const RGBQUAD
*rgb
= (RGBQUAD
*)((PBYTE
)data
+ data
->bmiHeader
.biSize
);
1198 DWORD col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1200 // Check if the first color of the colormap is black
1201 if ((col
== RGB(0, 0, 0)))
1204 col
= RGB(rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1206 // If the second color is white, create a monochrome bitmap
1207 fColor
= (col
!= RGB(0xff,0xff,0xff));
1212 // Now create the bitmap
1215 handle
= IntCreateCompatibleBitmap(Dc
, width
, height
);
1219 handle
= GreCreateBitmap(width
,
1229 if (NULL
!= handle
&& CBM_INIT
== init
)
1231 IntSetDIBits(Dc
, handle
, 0, height
, bits
, data
, coloruse
);
1237 // The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a DIB and, optionally, sets the bitmap bits
1238 // The DDB that is created will be whatever bit depth your reference DC is
1241 NtGdiCreateDIBitmapInternal(
1246 IN OPTIONAL LPBYTE pjInit
,
1247 IN OPTIONAL LPBITMAPINFO pbmi
,
1249 IN UINT cjMaxInitInfo
,
1254 NTSTATUS Status
= STATUS_SUCCESS
;
1255 PBYTE safeBits
= NULL
;
1256 HBITMAP hbmResult
= NULL
;
1258 if(pjInit
&& (fInit
== CBM_INIT
))
1260 safeBits
= ExAllocatePoolWithTag(PagedPool
, cjMaxBits
, TAG_DIB
);
1263 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1270 if(pbmi
) ProbeForRead(pbmi
, cjMaxInitInfo
, 1);
1271 if(pjInit
&& (fInit
== CBM_INIT
))
1273 ProbeForRead(pjInit
, cjMaxBits
, 1);
1274 RtlCopyMemory(safeBits
, pjInit
, cjMaxBits
);
1277 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1279 Status
= _SEH2_GetExceptionCode();
1283 if(!NT_SUCCESS(Status
))
1285 SetLastNtError(Status
);
1289 hbmResult
= GreCreateDIBitmapInternal(hDc
,
1300 if (safeBits
) ExFreePoolWithTag(safeBits
, TAG_DIB
);
1306 GreCreateDIBitmapInternal(
1311 IN OPTIONAL LPBYTE pjInit
,
1312 IN OPTIONAL PBITMAPINFO pbmi
,
1322 if (!hDc
) /* 1bpp monochrome bitmap */
1324 // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1325 hdcDest
= NtGdiCreateCompatibleDC(0);
1336 Dc
= DC_LockDc(hdcDest
);
1339 EngSetLastError(ERROR_INVALID_HANDLE
);
1342 /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
1343 * if bpp != 1 and ignore the real value that was passed */
1345 bpp
= pbmi
->bmiHeader
.biBitCount
;
1348 Bmp
= IntCreateDIBitmap(Dc
, cx
, cy
, bpp
, fInit
, pjInit
, pbmi
, iUsage
);
1353 NtGdiDeleteObjectApp(hdcDest
);
1361 NtGdiCreateDIBSection(
1363 IN OPTIONAL HANDLE hSection
,
1369 IN ULONG_PTR dwColorSpace
,
1372 HBITMAP hbitmap
= 0;
1374 BOOL bDesktopDC
= FALSE
;
1375 NTSTATUS Status
= STATUS_SUCCESS
;
1377 if (!bmi
) return hbitmap
; // Make sure.
1381 ProbeForRead(&bmi
->bmiHeader
.biSize
, sizeof(DWORD
), 1);
1382 ProbeForRead(bmi
, bmi
->bmiHeader
.biSize
, 1);
1383 ProbeForRead(bmi
, DIB_BitmapInfoSize(bmi
, (WORD
)Usage
), 1);
1385 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1387 Status
= _SEH2_GetExceptionCode();
1391 if(!NT_SUCCESS(Status
))
1393 SetLastNtError(Status
);
1397 // If the reference hdc is null, take the desktop dc
1400 hDC
= NtGdiCreateCompatibleDC(0);
1404 if ((dc
= DC_LockDc(hDC
)))
1406 hbitmap
= DIB_CreateDIBSection(dc
,
1417 EngSetLastError(ERROR_INVALID_HANDLE
);
1421 NtGdiDeleteObjectApp(hDC
);
1428 DIB_CreateDIBSection(
1430 CONST BITMAPINFO
*bmi
,
1438 SURFACE
*bmp
= NULL
;
1439 void *mapBits
= NULL
;
1442 // Fill BITMAP32 structure with DIB data
1443 CONST BITMAPINFOHEADER
*bi
= &bmi
->bmiHeader
;
1450 DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
1451 bi
->biWidth
, bi
->biHeight
, bi
->biPlanes
, bi
->biBitCount
,
1452 bi
->biSizeImage
, bi
->biClrUsed
, usage
== DIB_PAL_COLORS
? "PAL" : "RGB");
1454 /* CreateDIBSection should fail for compressed formats */
1455 if (bi
->biCompression
== BI_RLE4
|| bi
->biCompression
== BI_RLE8
)
1457 DPRINT1("no compressed format allowed\n");
1458 return (HBITMAP
)NULL
;
1461 effHeight
= bi
->biHeight
>= 0 ? bi
->biHeight
: -bi
->biHeight
;
1463 bm
.bmWidth
= bi
->biWidth
;
1464 bm
.bmHeight
= effHeight
;
1465 bm
.bmWidthBytes
= ovr_pitch
? ovr_pitch
: WIDTH_BYTES_ALIGN32(bm
.bmWidth
, bi
->biBitCount
);
1467 bm
.bmPlanes
= bi
->biPlanes
;
1468 bm
.bmBitsPixel
= bi
->biBitCount
;
1471 // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1472 // we're dealing with a compressed bitmap. Otherwise, use width * height.
1473 totalSize
= bi
->biSizeImage
&& bi
->biCompression
!= BI_RGB
&& bi
->biCompression
!= BI_BITFIELDS
1474 ? bi
->biSizeImage
: (ULONG
)(bm
.bmWidthBytes
* effHeight
);
1478 SYSTEM_BASIC_INFORMATION Sbi
;
1481 LARGE_INTEGER SectionOffset
;
1484 Status
= ZwQuerySystemInformation(SystemBasicInformation
,
1488 if (!NT_SUCCESS(Status
))
1490 DPRINT1("ZwQuerySystemInformation failed (0x%lx)\n", Status
);
1494 mapOffset
= offset
- (offset
% Sbi
.AllocationGranularity
);
1495 mapSize
= bi
->biSizeImage
+ (offset
- mapOffset
);
1497 SectionOffset
.LowPart
= mapOffset
;
1498 SectionOffset
.HighPart
= 0;
1500 Status
= ZwMapViewOfSection(section
,
1510 if (!NT_SUCCESS(Status
))
1512 DPRINT1("ZwMapViewOfSection failed (0x%lx)\n", Status
);
1513 EngSetLastError(ERROR_INVALID_PARAMETER
);
1517 if (mapBits
) bm
.bmBits
= (char *)mapBits
+ (offset
- mapOffset
);
1519 else if (ovr_pitch
&& offset
)
1520 bm
.bmBits
= (LPVOID
) offset
;
1524 bm
.bmBits
= EngAllocUserMem(totalSize
, 0);
1527 DPRINT1("Failed to allocate memory\n");
1532 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1533 hSecure
= (HANDLE
)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1535 if (usage
== DIB_PAL_COLORS
)
1540 ppalDc
= PALETTE_ShareLockPalette(dc
->dclevel
.hpal
);
1541 hpal
= DIB_MapPaletteColors(ppalDc
, bmi
);
1542 PALETTE_ShareUnlockPalette(ppalDc
);
1546 /* For DIB Brushes */
1547 DPRINT1("FIXME: Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
1549 hpal
= (HPALETTE
) 0xFFFFFFFF;
1554 hpal
= BuildDIBPalette(bmi
);
1559 DPRINT1("Error: Could not create a palette for the DIB.\n");
1563 // Create Device Dependent Bitmap and add DIB pointer
1564 //Size.cx = bm.bmWidth;
1565 //Size.cy = abs(bm.bmHeight);
1566 res
= GreCreateBitmapEx(bm
.bmWidth
,
1569 BitmapFormat(bi
->biBitCount
* bi
->biPlanes
, bi
->biCompression
),
1570 BMF_DONTCACHE
| BMF_USERMEM
| BMF_NOZEROINIT
|
1571 ((bi
->biHeight
< 0) ? BMF_TOPDOWN
: 0),
1577 DPRINT1("GreCreateBitmapEx failed\n");
1578 EngSetLastError(ERROR_NO_SYSTEM_RESOURCES
);
1581 bmp
= SURFACE_ShareLockSurface(res
); // HACK
1584 DPRINT1("SURFACE_LockSurface failed\n");
1585 EngSetLastError(ERROR_INVALID_HANDLE
);
1589 /* WINE NOTE: WINE makes use of a colormap, which is a color translation
1590 table between the DIB and the X physical device. Obviously,
1591 this is left out of the ReactOS implementation. Instead,
1592 we call NtGdiSetDIBColorTable. */
1593 bmp
->hDIBSection
= section
;
1594 bmp
->hSecure
= hSecure
;
1595 bmp
->dwOffset
= offset
;
1596 bmp
->flags
= API_BITMAP
;
1597 bmp
->biClrImportant
= bi
->biClrImportant
;
1598 bmp
->SurfObj
.fjBitmap
&= ~BMF_DONT_FREE
;
1601 if(hpal
!= (HPALETTE
)0xFFFFFFFF)
1603 bmp
->ppal
= PALETTE_ShareLockPalette(hpal
);
1604 /* Lazy delete hpal, it will be freed at surface release */
1605 GreDeleteObject(hpal
);
1608 // Clean up in case of errors
1610 if (!res
|| !bmp
|| !bm
.bmBits
)
1612 DPRINT("Got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res
, bmp
, bm
.bmBits
);
1615 // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
1618 ZwUnmapViewOfSection(NtCurrentProcess(), mapBits
);
1622 EngFreeUserMem(bm
.bmBits
), bm
.bmBits
= NULL
;
1630 GreDeleteObject(res
);
1637 SURFACE_ShareUnlockSurface(bmp
);
1640 // Return BITMAP handle and storage location
1641 if (NULL
!= bm
.bmBits
&& NULL
!= bits
)
1649 /***********************************************************************
1652 * Get the info from a bitmap header.
1653 * Return 0 for COREHEADER, 1 for INFOHEADER, -1 for error.
1657 DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
1658 LONG
*height
, WORD
*planes
, WORD
*bpp
, DWORD
*compr
, DWORD
*size
)
1660 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
1662 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
1663 *width
= core
->bcWidth
;
1664 *height
= core
->bcHeight
;
1665 *planes
= core
->bcPlanes
;
1666 *bpp
= core
->bcBitCount
;
1671 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
)) /* Assume BITMAPINFOHEADER */
1673 *width
= header
->biWidth
;
1674 *height
= header
->biHeight
;
1675 *planes
= header
->biPlanes
;
1676 *bpp
= header
->biBitCount
;
1677 *compr
= header
->biCompression
;
1678 *size
= header
->biSizeImage
;
1681 DPRINT1("(%d): unknown/wrong size for header\n", header
->biSize
);
1685 /***********************************************************************
1686 * DIB_GetDIBImageBytes
1688 * Return the number of bytes used to hold the image in a DIB bitmap.
1689 * 11/16/1999 (RJJ) lifted from wine
1692 INT APIENTRY
DIB_GetDIBImageBytes(INT width
, INT height
, INT depth
)
1694 return WIDTH_BYTES_ALIGN32(width
, depth
) * (height
< 0 ? -height
: height
);
1697 /***********************************************************************
1698 * DIB_BitmapInfoSize
1700 * Return the size of the bitmap info structure including color table.
1701 * 11/16/1999 (RJJ) lifted from wine
1704 INT FASTCALL
DIB_BitmapInfoSize(const BITMAPINFO
* info
, WORD coloruse
)
1706 unsigned int colors
, size
, masks
= 0;
1708 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1710 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
1711 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
1712 return sizeof(BITMAPCOREHEADER
) + colors
*
1713 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
1715 else /* Assume BITMAPINFOHEADER */
1717 colors
= info
->bmiHeader
.biClrUsed
;
1718 if (colors
> 256) colors
= 256;
1719 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
1720 colors
= 1 << info
->bmiHeader
.biBitCount
;
1721 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
1722 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
1723 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
1729 DIB_MapPaletteColors(PPALETTE ppal
, CONST BITMAPINFO
* lpbmi
)
1731 PALETTEENTRY
* ppalEntries
;
1736 if (!(ppal
->flFlags
& PAL_INDEXED
))
1741 nNumColors
= 1 << lpbmi
->bmiHeader
.biBitCount
;
1742 if (lpbmi
->bmiHeader
.biClrUsed
)
1744 nNumColors
= min(nNumColors
, lpbmi
->bmiHeader
.biClrUsed
);
1747 /* Don't have more colors than we need */
1748 nNumColors
= min(ppal
->NumColors
, nNumColors
);
1750 ppalEntries
= ExAllocatePoolWithTag(PagedPool
, sizeof(PALETTEENTRY
) * nNumColors
, TAG_COLORMAP
);
1751 if (ppalEntries
== NULL
)
1753 DPRINT1("Could not allocate palette entries\n");
1757 lpIndex
= (USHORT
*)((PBYTE
)lpbmi
+ lpbmi
->bmiHeader
.biSize
);
1759 for (i
= 0; i
< nNumColors
; i
++)
1761 if (*lpIndex
< ppal
->NumColors
)
1763 ppalEntries
[i
] = ppal
->IndexedColors
[*lpIndex
];
1767 ppalEntries
[i
].peRed
= 0;
1768 ppalEntries
[i
].peGreen
= 0;
1769 ppalEntries
[i
].peBlue
= 0;
1770 ppalEntries
[i
].peFlags
= 0;
1776 hpal
= PALETTE_AllocPalette(PAL_INDEXED
, nNumColors
, (ULONG
*)ppalEntries
, 0, 0, 0);
1778 ExFreePoolWithTag(ppalEntries
, TAG_COLORMAP
);
1785 BuildDIBPalette(CONST BITMAPINFO
*bmi
)
1790 ULONG RedMask
= 0, GreenMask
= 0, BlueMask
= 0;
1791 PDWORD pdwColors
= (PDWORD
)((PBYTE
)bmi
+ bmi
->bmiHeader
.biSize
);
1794 // Determine Bits Per Pixel
1795 bits
= bmi
->bmiHeader
.biBitCount
;
1797 // Determine paletteType from Bits Per Pixel
1800 paletteType
= PAL_INDEXED
;
1801 RedMask
= GreenMask
= BlueMask
= 0;
1803 else if (bmi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1805 paletteType
= PAL_BITFIELDS
;
1806 if (bmi
->bmiHeader
.biSize
>= sizeof(BITMAPV4HEADER
))
1808 PBITMAPV4HEADER pV4Header
= (PBITMAPV4HEADER
)&bmi
->bmiHeader
;
1809 RedMask
= pV4Header
->bV4RedMask
;
1810 GreenMask
= pV4Header
->bV4GreenMask
;
1811 BlueMask
= pV4Header
->bV4BlueMask
;
1815 RedMask
= pdwColors
[0];
1816 GreenMask
= pdwColors
[1];
1817 BlueMask
= pdwColors
[2];
1822 paletteType
= PAL_BITFIELDS
;
1826 paletteType
|= PAL_RGB16_555
;
1834 paletteType
|= PAL_BGR
;
1836 GreenMask
= 0x00FF00;
1837 BlueMask
= 0x0000FF;
1842 if (bmi
->bmiHeader
.biClrUsed
== 0)
1844 ColorCount
= 1 << bmi
->bmiHeader
.biBitCount
;
1848 ColorCount
= bmi
->bmiHeader
.biClrUsed
;
1851 if (PAL_INDEXED
== paletteType
)
1853 hPal
= PALETTE_AllocPaletteIndexedRGB(ColorCount
, (RGBQUAD
*)pdwColors
);
1857 hPal
= PALETTE_AllocPalette(paletteType
, 0,
1859 RedMask
, GreenMask
, BlueMask
);
1865 /* Converts a BITMAPCOREINFO to a BITMAPINFO structure,
1866 * or does nothing if it's already a BITMAPINFO (or V4 or V5) */
1869 DIB_ConvertBitmapInfo (CONST BITMAPINFO
* pbmi
, DWORD Usage
)
1871 CONST BITMAPCOREINFO
* pbmci
= (BITMAPCOREINFO
*)pbmi
;
1872 BITMAPINFO
* pNewBmi
;
1873 UINT numColors
= 0, ColorsSize
= 0;
1875 if(pbmi
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
)) return (BITMAPINFO
*)pbmi
;
1876 if(pbmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) return NULL
;
1878 if(pbmci
->bmciHeader
.bcBitCount
<= 8)
1880 numColors
= 1 << pbmci
->bmciHeader
.bcBitCount
;
1881 if(Usage
== DIB_PAL_COLORS
)
1883 ColorsSize
= numColors
* sizeof(WORD
);
1887 ColorsSize
= numColors
* sizeof(RGBQUAD
);
1890 else if (Usage
== DIB_PAL_COLORS
)
1892 /* Invalid at high-res */
1896 pNewBmi
= ExAllocatePoolWithTag(PagedPool
, sizeof(BITMAPINFOHEADER
) + ColorsSize
, TAG_DIB
);
1897 if(!pNewBmi
) return NULL
;
1899 RtlZeroMemory(pNewBmi
, sizeof(BITMAPINFOHEADER
) + ColorsSize
);
1901 pNewBmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1902 pNewBmi
->bmiHeader
.biBitCount
= pbmci
->bmciHeader
.bcBitCount
;
1903 pNewBmi
->bmiHeader
.biWidth
= pbmci
->bmciHeader
.bcWidth
;
1904 pNewBmi
->bmiHeader
.biHeight
= pbmci
->bmciHeader
.bcHeight
;
1905 pNewBmi
->bmiHeader
.biPlanes
= pbmci
->bmciHeader
.bcPlanes
;
1906 pNewBmi
->bmiHeader
.biCompression
= BI_RGB
;
1907 pNewBmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(pNewBmi
->bmiHeader
.biWidth
,
1908 pNewBmi
->bmiHeader
.biHeight
,
1909 pNewBmi
->bmiHeader
.biBitCount
);
1911 if(Usage
== DIB_PAL_COLORS
)
1913 RtlCopyMemory(pNewBmi
->bmiColors
, pbmci
->bmciColors
, ColorsSize
);
1918 for(i
=0; i
<numColors
; i
++)
1920 pNewBmi
->bmiColors
[i
].rgbRed
= pbmci
->bmciColors
[i
].rgbtRed
;
1921 pNewBmi
->bmiColors
[i
].rgbGreen
= pbmci
->bmciColors
[i
].rgbtGreen
;
1922 pNewBmi
->bmiColors
[i
].rgbBlue
= pbmci
->bmciColors
[i
].rgbtBlue
;
1929 /* Frees a BITMAPINFO created with DIB_ConvertBitmapInfo */
1932 DIB_FreeConvertedBitmapInfo(BITMAPINFO
* converted
, BITMAPINFO
* orig
)
1934 if(converted
!= orig
)
1935 ExFreePoolWithTag(converted
, TAG_DIB
);