2 * GDI device-independent bitmaps
4 * Copyright 1993,1994 Alexandre Julliard
12 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(bitmap
)
18 /***********************************************************************
19 * DIB_GetDIBWidthBytes
21 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
22 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
24 int DIB_GetDIBWidthBytes( int width
, int depth
)
30 case 1: words
= (width
+ 31) / 32; break;
31 case 4: words
= (width
+ 7) / 8; break;
32 case 8: words
= (width
+ 3) / 4; break;
34 case 16: words
= (width
+ 1) / 2; break;
35 case 24: words
= (width
* 3 + 3)/4; break;
38 WARN("(%d): Unsupported depth\n", depth
);
46 /***********************************************************************
47 * DIB_GetDIBImageBytes
49 * Return the number of bytes used to hold the image in a DIB bitmap.
51 int DIB_GetDIBImageBytes( int width
, int height
, int depth
)
53 return DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
57 /***********************************************************************
60 * Return the size of the bitmap info structure including color table.
62 int DIB_BitmapInfoSize( const BITMAPINFO
* info
, WORD coloruse
)
66 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
68 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
69 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
70 return sizeof(BITMAPCOREHEADER
) + colors
*
71 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
73 else /* assume BITMAPINFOHEADER */
75 colors
= info
->bmiHeader
.biClrUsed
;
76 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
77 colors
= 1 << info
->bmiHeader
.biBitCount
;
78 return sizeof(BITMAPINFOHEADER
) + colors
*
79 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
84 /***********************************************************************
87 * Get the info from a bitmap header.
88 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
90 int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, DWORD
*width
,
91 int *height
, WORD
*bpp
, WORD
*compr
)
93 if (header
->biSize
== sizeof(BITMAPINFOHEADER
))
95 *width
= header
->biWidth
;
96 *height
= header
->biHeight
;
97 *bpp
= header
->biBitCount
;
98 *compr
= header
->biCompression
;
101 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
103 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)header
;
104 *width
= core
->bcWidth
;
105 *height
= core
->bcHeight
;
106 *bpp
= core
->bcBitCount
;
110 WARN("(%ld): wrong size for header\n", header
->biSize
);
115 /***********************************************************************
116 * StretchDIBits16 (GDI.439)
118 INT16 WINAPI
StretchDIBits16(HDC16 hdc
, INT16 xDst
, INT16 yDst
, INT16 widthDst
,
119 INT16 heightDst
, INT16 xSrc
, INT16 ySrc
, INT16 widthSrc
,
120 INT16 heightSrc
, const VOID
*bits
,
121 const BITMAPINFO
*info
, UINT16 wUsage
, DWORD dwRop
)
123 return (INT16
)StretchDIBits( hdc
, xDst
, yDst
, widthDst
, heightDst
,
124 xSrc
, ySrc
, widthSrc
, heightSrc
, bits
,
125 info
, wUsage
, dwRop
);
129 /***********************************************************************
130 * StretchDIBits32 (GDI32.351)
132 INT WINAPI
StretchDIBits(HDC hdc
, INT xDst
, INT yDst
, INT widthDst
,
133 INT heightDst
, INT xSrc
, INT ySrc
, INT widthSrc
,
134 INT heightSrc
, const void *bits
,
135 const BITMAPINFO
*info
, UINT wUsage
, DWORD dwRop
)
137 DC
*dc
= DC_GetDCPtr( hdc
);
138 if(!dc
) return FALSE
;
140 if(dc
->funcs
->pStretchDIBits
)
141 return dc
->funcs
->pStretchDIBits(dc
, xDst
, yDst
, widthDst
,
142 heightDst
, xSrc
, ySrc
, widthSrc
,
143 heightSrc
, bits
, info
, wUsage
,
145 else { /* use StretchBlt32 */
146 HBITMAP hBitmap
, hOldBitmap
;
149 hBitmap
= CreateDIBitmap( hdc
, &info
->bmiHeader
, CBM_INIT
,
150 bits
, info
, wUsage
);
151 hdcMem
= CreateCompatibleDC( hdc
);
152 hOldBitmap
= SelectObject( hdcMem
, hBitmap
);
153 /* Origin for DIBitmap is bottom left ! */
154 StretchBlt( hdc
, xDst
, yDst
, widthDst
, heightDst
,
155 hdcMem
, xSrc
, info
->bmiHeader
.biHeight
- heightSrc
- ySrc
,
156 widthSrc
, heightSrc
, dwRop
);
157 SelectObject( hdcMem
, hOldBitmap
);
159 DeleteObject( hBitmap
);
165 /***********************************************************************
166 * SetDIBits16 (GDI.440)
168 INT16 WINAPI
SetDIBits16( HDC16 hdc
, HBITMAP16 hbitmap
, UINT16 startscan
,
169 UINT16 lines
, LPCVOID bits
, const BITMAPINFO
*info
,
172 return SetDIBits( hdc
, hbitmap
, startscan
, lines
, bits
, info
, coloruse
);
176 /******************************************************************************
177 * SetDIBits32 [GDI32.312] Sets pixels in a bitmap using colors from DIB
180 * hdc [I] Handle to device context
181 * hbitmap [I] Handle to bitmap
182 * startscan [I] Starting scan line
183 * lines [I] Number of scan lines
184 * bits [I] Array of bitmap bits
185 * info [I] Address of structure with data
186 * coloruse [I] Type of color indexes to use
189 * Success: Number of scan lines copied
192 INT WINAPI
SetDIBits( HDC hdc
, HBITMAP hbitmap
, UINT startscan
,
193 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
,
200 /* Check parameters */
201 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
204 dc
= (DC
*) GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
208 if (!(bitmap
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
)))
210 GDI_HEAP_UNLOCK( hdc
);
214 result
= BITMAP_Driver
->pSetDIBits(bitmap
, dc
, startscan
,
218 GDI_HEAP_UNLOCK( hdc
);
219 GDI_HEAP_UNLOCK( hbitmap
);
225 /***********************************************************************
226 * SetDIBitsToDevice16 (GDI.443)
228 INT16 WINAPI
SetDIBitsToDevice16(HDC16 hdc
, INT16 xDest
, INT16 yDest
, INT16 cx
,
229 INT16 cy
, INT16 xSrc
, INT16 ySrc
, UINT16 startscan
,
230 UINT16 lines
, LPCVOID bits
, const BITMAPINFO
*info
,
233 return SetDIBitsToDevice( hdc
, xDest
, yDest
, cx
, cy
, xSrc
, ySrc
,
234 startscan
, lines
, bits
, info
, coloruse
);
238 /***********************************************************************
239 * SetDIBitsToDevice32 (GDI32.313)
241 INT WINAPI
SetDIBitsToDevice(HDC hdc
, INT xDest
, INT yDest
, DWORD cx
,
242 DWORD cy
, INT xSrc
, INT ySrc
, UINT startscan
,
243 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
,
249 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
251 if(dc
->funcs
->pSetDIBitsToDevice
)
252 ret
= dc
->funcs
->pSetDIBitsToDevice( dc
, xDest
, yDest
, cx
, cy
, xSrc
,
253 ySrc
, startscan
, lines
, bits
,
256 FIXME("unimplemented on hdc %08x\n", hdc
);
260 GDI_HEAP_UNLOCK( hdc
);
264 /***********************************************************************
265 * SetDIBColorTable16 (GDI.602)
267 UINT16 WINAPI
SetDIBColorTable16( HDC16 hdc
, UINT16 startpos
, UINT16 entries
,
270 return SetDIBColorTable( hdc
, startpos
, entries
, colors
);
273 /***********************************************************************
274 * SetDIBColorTable32 (GDI32.311)
276 UINT WINAPI
SetDIBColorTable( HDC hdc
, UINT startpos
, UINT entries
,
280 PALETTEENTRY
* palEntry
;
281 PALETTEOBJ
* palette
;
284 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
287 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
291 if (!(palette
= (PALETTEOBJ
*)GDI_GetObjPtr( dc
->w
.hPalette
, PALETTE_MAGIC
)))
296 /* Transfer color info */
298 if (dc
->w
.bitsPerPixel
<= 8) {
299 palEntry
= palette
->logpalette
.palPalEntry
+ startpos
;
300 if (startpos
+ entries
> (1 << dc
->w
.bitsPerPixel
)) {
301 entries
= (1 << dc
->w
.bitsPerPixel
) - startpos
;
303 for (end
= colors
+ entries
; colors
< end
; palEntry
++, colors
++)
305 palEntry
->peRed
= colors
->rgbRed
;
306 palEntry
->peGreen
= colors
->rgbGreen
;
307 palEntry
->peBlue
= colors
->rgbBlue
;
312 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
316 /***********************************************************************
317 * GetDIBColorTable16 (GDI.603)
319 UINT16 WINAPI
GetDIBColorTable16( HDC16 hdc
, UINT16 startpos
, UINT16 entries
,
322 return GetDIBColorTable( hdc
, startpos
, entries
, colors
);
325 /***********************************************************************
326 * GetDIBColorTable32 (GDI32.169)
328 UINT WINAPI
GetDIBColorTable( HDC hdc
, UINT startpos
, UINT entries
,
332 PALETTEENTRY
* palEntry
;
333 PALETTEOBJ
* palette
;
336 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
339 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
343 if (!(palette
= (PALETTEOBJ
*)GDI_GetObjPtr( dc
->w
.hPalette
, PALETTE_MAGIC
)))
348 /* Transfer color info */
350 if (dc
->w
.bitsPerPixel
<= 8) {
351 palEntry
= palette
->logpalette
.palPalEntry
+ startpos
;
352 if (startpos
+ entries
> (1 << dc
->w
.bitsPerPixel
)) {
353 entries
= (1 << dc
->w
.bitsPerPixel
) - startpos
;
355 for (end
= colors
+ entries
; colors
< end
; palEntry
++, colors
++)
357 colors
->rgbRed
= palEntry
->peRed
;
358 colors
->rgbGreen
= palEntry
->peGreen
;
359 colors
->rgbBlue
= palEntry
->peBlue
;
360 colors
->rgbReserved
= 0;
365 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
369 /* FIXME the following two structs should be combined with __sysPalTemplate in
370 objects/color.c - this should happen after de-X11-ing both of these
372 NB. RGBQUAD and PALETTENTRY have different orderings of red, green
375 static RGBQUAD EGAColors
[16] = {
376 /* rgbBlue, rgbGreen, rgbRed, rgbReserverd */
377 { 0x00, 0x00, 0x00, 0x00 },
378 { 0x00, 0x00, 0x80, 0x00 },
379 { 0x00, 0x80, 0x00, 0x00 },
380 { 0x00, 0x80, 0x80, 0x00 },
381 { 0x80, 0x00, 0x00, 0x00 },
382 { 0x80, 0x00, 0x80, 0x00 },
383 { 0x80, 0x80, 0x00, 0x00 },
384 { 0x80, 0x80, 0x80, 0x00 },
385 { 0xc0, 0xc0, 0xc0, 0x00 },
386 { 0x00, 0x00, 0xff, 0x00 },
387 { 0x00, 0xff, 0x00, 0x00 },
388 { 0x00, 0xff, 0xff, 0x00 },
389 { 0xff, 0x00, 0x00, 0x00 },
390 { 0xff, 0x00, 0xff, 0x00 },
391 { 0xff, 0xff, 0x00, 0x00 },
392 { 0xff, 0xff, 0xff, 0x00 }
396 static RGBQUAD DefLogPalette
[20] = { /* Copy of Default Logical Palette */
397 /* rgbBlue, rgbGreen, rgbRed, rgbReserverd */
398 { 0x00, 0x00, 0x00, 0x00 },
399 { 0x00, 0x00, 0x80, 0x00 },
400 { 0x00, 0x80, 0x00, 0x00 },
401 { 0x00, 0x80, 0x80, 0x00 },
402 { 0x80, 0x00, 0x00, 0x00 },
403 { 0x80, 0x00, 0x80, 0x00 },
404 { 0x80, 0x80, 0x00, 0x00 },
405 { 0xc0, 0xc0, 0xc0, 0x00 },
406 { 0xc0, 0xdc, 0xc0, 0x00 },
407 { 0xf0, 0xca, 0xa6, 0x00 },
408 { 0xf0, 0xfb, 0xff, 0x00 },
409 { 0xa4, 0xa0, 0xa0, 0x00 },
410 { 0x80, 0x80, 0x80, 0x00 },
411 { 0x00, 0x00, 0xf0, 0x00 },
412 { 0x00, 0xff, 0x00, 0x00 },
413 { 0x00, 0xff, 0xff, 0x00 },
414 { 0xff, 0x00, 0x00, 0x00 },
415 { 0xff, 0x00, 0xff, 0x00 },
416 { 0xff, 0xff, 0x00, 0x00 },
417 { 0xff, 0xff, 0xff, 0x00 }
420 /***********************************************************************
421 * GetDIBits16 (GDI.441)
423 INT16 WINAPI
GetDIBits16( HDC16 hdc
, HBITMAP16 hbitmap
, UINT16 startscan
,
424 UINT16 lines
, LPVOID bits
, BITMAPINFO
* info
,
427 return GetDIBits( hdc
, hbitmap
, startscan
, lines
, bits
, info
, coloruse
);
431 /******************************************************************************
432 * GetDIBits32 [GDI32.170] Retrieves bits of bitmap and copies to buffer
435 * Success: Number of scan lines copied from bitmap
438 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/func/src/f30_14.htm
440 INT WINAPI
GetDIBits(
441 HDC hdc
, /* [in] Handle to device context */
442 HBITMAP hbitmap
, /* [in] Handle to bitmap */
443 UINT startscan
, /* [in] First scan line to set in dest bitmap */
444 UINT lines
, /* [in] Number of scan lines to copy */
445 LPVOID bits
, /* [out] Address of array for bitmap bits */
446 BITMAPINFO
* info
, /* [out] Address of structure with bitmap data */
447 UINT coloruse
) /* [in] RGB or palette index */
451 PALETTEENTRY
* palEntry
;
452 PALETTEOBJ
* palette
;
455 if (!lines
) return 0;
457 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
460 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
463 if (!(bmp
= (BITMAPOBJ
*)GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
)))
465 GDI_HEAP_UNLOCK( hdc
);
468 if (!(palette
= (PALETTEOBJ
*)GDI_GetObjPtr( dc
->w
.hPalette
, PALETTE_MAGIC
)))
470 GDI_HEAP_UNLOCK( hdc
);
471 GDI_HEAP_UNLOCK( hbitmap
);
475 /* Transfer color info */
477 if (info
->bmiHeader
.biBitCount
<= 8 && info
->bmiHeader
.biBitCount
> 0 ) {
479 info
->bmiHeader
.biClrUsed
= 0;
481 if(info
->bmiHeader
.biBitCount
>= bmp
->bitmap
.bmBitsPixel
) {
482 palEntry
= palette
->logpalette
.palPalEntry
;
483 for (i
= 0; i
< (1 << bmp
->bitmap
.bmBitsPixel
); i
++, palEntry
++) {
484 if (coloruse
== DIB_RGB_COLORS
) {
485 info
->bmiColors
[i
].rgbRed
= palEntry
->peRed
;
486 info
->bmiColors
[i
].rgbGreen
= palEntry
->peGreen
;
487 info
->bmiColors
[i
].rgbBlue
= palEntry
->peBlue
;
488 info
->bmiColors
[i
].rgbReserved
= 0;
490 else ((WORD
*)info
->bmiColors
)[i
] = (WORD
)i
;
493 switch (info
->bmiHeader
.biBitCount
) {
495 info
->bmiColors
[0].rgbRed
= info
->bmiColors
[0].rgbGreen
=
496 info
->bmiColors
[0].rgbBlue
= 0;
497 info
->bmiColors
[0].rgbReserved
= 0;
498 info
->bmiColors
[1].rgbRed
= info
->bmiColors
[1].rgbGreen
=
499 info
->bmiColors
[1].rgbBlue
= 0xff;
500 info
->bmiColors
[1].rgbReserved
= 0;
504 memcpy(info
->bmiColors
, EGAColors
, sizeof(EGAColors
));
512 memcpy(info
->bmiColors
, DefLogPalette
,
513 10 * sizeof(RGBQUAD
));
514 memcpy(info
->bmiColors
+ 246, DefLogPalette
+ 10,
515 10 * sizeof(RGBQUAD
));
516 color
= info
->bmiColors
+ 10;
517 for(r
= 0; r
<= 5; r
++) /* FIXME */
518 for(g
= 0; g
<= 5; g
++)
519 for(b
= 0; b
<= 5; b
++) {
520 color
->rgbRed
= (r
* 0xff) / 5;
521 color
->rgbGreen
= (g
* 0xff) / 5;
522 color
->rgbBlue
= (b
* 0xff) / 5;
523 color
->rgbReserved
= 0;
531 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
535 if(!BITMAP_Driver
->pGetDIBits(bmp
, dc
, startscan
, lines
, bits
, info
, coloruse
, hbitmap
))
537 GDI_HEAP_UNLOCK( hdc
);
538 GDI_HEAP_UNLOCK( hbitmap
);
543 else if( info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
) )
545 /* fill in struct members */
547 if( info
->bmiHeader
.biBitCount
== 0)
549 info
->bmiHeader
.biWidth
= bmp
->bitmap
.bmWidth
;
550 info
->bmiHeader
.biHeight
= bmp
->bitmap
.bmHeight
;
551 info
->bmiHeader
.biPlanes
= 1;
552 info
->bmiHeader
.biBitCount
= bmp
->bitmap
.bmBitsPixel
;
553 info
->bmiHeader
.biSizeImage
=
554 DIB_GetDIBImageBytes( bmp
->bitmap
.bmWidth
,
555 bmp
->bitmap
.bmHeight
,
556 bmp
->bitmap
.bmBitsPixel
);
557 info
->bmiHeader
.biCompression
= 0;
561 info
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(
562 info
->bmiHeader
.biWidth
,
563 info
->bmiHeader
.biHeight
,
564 info
->bmiHeader
.biBitCount
);
568 TRACE("biSizeImage = %ld, biWidth = %ld, biHeight = %ld\n",
569 info
->bmiHeader
.biSizeImage
, info
->bmiHeader
.biWidth
,
570 info
->bmiHeader
.biHeight
);
572 GDI_HEAP_UNLOCK( hdc
);
573 GDI_HEAP_UNLOCK( hbitmap
);
579 /***********************************************************************
580 * CreateDIBitmap16 (GDI.442)
582 HBITMAP16 WINAPI
CreateDIBitmap16( HDC16 hdc
, const BITMAPINFOHEADER
* header
,
583 DWORD init
, LPCVOID bits
, const BITMAPINFO
* data
,
586 return CreateDIBitmap( hdc
, header
, init
, bits
, data
, coloruse
);
590 /***********************************************************************
591 * CreateDIBitmap32 (GDI32.37)
593 HBITMAP WINAPI
CreateDIBitmap( HDC hdc
, const BITMAPINFOHEADER
*header
,
594 DWORD init
, LPCVOID bits
, const BITMAPINFO
*data
,
604 if (DIB_GetBitmapInfo( header
, &width
, &height
, &bpp
, &compr
) == -1) return 0;
605 if (height
< 0) height
= -height
;
607 /* Check if we should create a monochrome or color bitmap. */
608 /* We create a monochrome bitmap only if it has exactly 2 */
609 /* colors, which are either black or white, nothing else. */
610 /* In all other cases, we create a color bitmap. */
612 if (bpp
!= 1) fColor
= TRUE
;
613 else if ((coloruse
!= DIB_RGB_COLORS
) ||
614 (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
617 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
619 RGBQUAD
*rgb
= data
->bmiColors
;
620 DWORD col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
621 if ((col
== RGB(0,0,0)) || (col
== RGB(0xff,0xff,0xff)))
624 col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
625 fColor
= ((col
!= RGB(0,0,0)) && (col
!= RGB(0xff,0xff,0xff)));
629 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
631 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
632 DWORD col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
633 if ((col
== RGB(0,0,0)) || (col
== RGB(0xff,0xff,0xff)))
636 col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
637 fColor
= ((col
!= RGB(0,0,0)) && (col
!= RGB(0xff,0xff,0xff)));
643 WARN("(%ld): wrong size for data\n",
644 data
->bmiHeader
.biSize
);
649 /* Now create the bitmap */
651 handle
= fColor
? CreateBitmap( width
, height
, 1, MONITOR_GetDepth(&MONITOR_PrimaryMonitor
), NULL
) :
652 CreateBitmap( width
, height
, 1, 1, NULL
);
653 if (!handle
) return 0;
655 if (init
== CBM_INIT
)
656 SetDIBits( hdc
, handle
, 0, height
, bits
, data
, coloruse
);
660 /***********************************************************************
661 * CreateDIBSection16 (GDI.489)
663 HBITMAP16 WINAPI
CreateDIBSection16 (HDC16 hdc
, BITMAPINFO
*bmi
, UINT16 usage
,
664 SEGPTR
*bits
, HANDLE section
,
668 DC
*dc
= (DC
*) GDI_GetObjPtr(hdc
, DC_MAGIC
);
669 if(!dc
) dc
= (DC
*) GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
670 if(!dc
) return (HBITMAP16
) NULL
;
672 hbitmap
= dc
->funcs
->pCreateDIBSection16(dc
, bmi
, usage
, bits
, section
, offset
);
674 GDI_HEAP_UNLOCK(hdc
);
679 /***********************************************************************
680 * CreateDIBSection32 (GDI32.36)
682 HBITMAP WINAPI
CreateDIBSection(HDC hdc
, BITMAPINFO
*bmi
, UINT usage
,
683 LPVOID
*bits
, HANDLE section
,
687 DC
*dc
= (DC
*) GDI_GetObjPtr(hdc
, DC_MAGIC
);
688 if(!dc
) dc
= (DC
*) GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
689 if(!dc
) return (HBITMAP
) NULL
;
691 hbitmap
= dc
->funcs
->pCreateDIBSection(dc
, bmi
, usage
, bits
, section
, offset
);
693 GDI_HEAP_UNLOCK(hdc
);
698 /***********************************************************************
699 * DIB_DeleteDIBSection
701 void DIB_DeleteDIBSection( BITMAPOBJ
*bmp
)
705 DIBSECTION
*dib
= bmp
->dib
;
707 if (dib
->dsBm
.bmBits
)
710 UnmapViewOfFile(dib
->dsBm
.bmBits
);
712 VirtualFree(dib
->dsBm
.bmBits
, MEM_RELEASE
, 0L);
715 BITMAP_Driver
->pDeleteDIBSection(bmp
);
717 HeapFree(GetProcessHeap(), 0, dib
);
722 /***********************************************************************
723 * DIB_FixColorsToLoadflags
725 * Change color table entries when LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
728 void DIB_FixColorsToLoadflags(BITMAPINFO
* bmi
, UINT loadflags
, BYTE pix
)
731 COLORREF c_W
, c_S
, c_F
, c_L
, c_C
;
735 if (bmi
->bmiHeader
.biBitCount
> 8) return;
736 if (bmi
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
)) incr
= 4;
737 else if (bmi
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
)) incr
= 3;
739 WARN("Wrong bitmap header size!\n");
742 colors
= bmi
->bmiHeader
.biClrUsed
;
743 if (!colors
&& (bmi
->bmiHeader
.biBitCount
<= 8))
744 colors
= 1 << bmi
->bmiHeader
.biBitCount
;
745 c_W
= GetSysColor(COLOR_WINDOW
);
746 c_S
= GetSysColor(COLOR_3DSHADOW
);
747 c_F
= GetSysColor(COLOR_3DFACE
);
748 c_L
= GetSysColor(COLOR_3DLIGHT
);
749 if (loadflags
& LR_LOADTRANSPARENT
) {
750 switch (bmi
->bmiHeader
.biBitCount
) {
751 case 1: pix
= pix
>> 7; break;
752 case 4: pix
= pix
>> 4; break;
755 WARN("(%d): Unsupported depth\n", bmi
->bmiHeader
.biBitCount
);
759 WARN("pixel has color index greater than biClrUsed!\n");
762 if (loadflags
& LR_LOADMAP3DCOLORS
) c_W
= c_F
;
763 ptr
= (RGBQUAD
*)((char*)bmi
->bmiColors
+pix
*incr
);
764 ptr
->rgbBlue
= GetBValue(c_W
);
765 ptr
->rgbGreen
= GetGValue(c_W
);
766 ptr
->rgbRed
= GetRValue(c_W
);
768 if (loadflags
& LR_LOADMAP3DCOLORS
)
769 for (i
=0; i
<colors
; i
++) {
770 ptr
= (RGBQUAD
*)((char*)bmi
->bmiColors
+i
*incr
);
771 c_C
= RGB(ptr
->rgbRed
, ptr
->rgbGreen
, ptr
->rgbBlue
);
772 if (c_C
== RGB(128, 128, 128)) {
773 ptr
->rgbRed
= GetRValue(c_S
);
774 ptr
->rgbGreen
= GetGValue(c_S
);
775 ptr
->rgbBlue
= GetBValue(c_S
);
776 } else if (c_C
== RGB(192, 192, 192)) {
777 ptr
->rgbRed
= GetRValue(c_F
);
778 ptr
->rgbGreen
= GetGValue(c_F
);
779 ptr
->rgbBlue
= GetBValue(c_F
);
780 } else if (c_C
== RGB(223, 223, 223)) {
781 ptr
->rgbRed
= GetRValue(c_L
);
782 ptr
->rgbGreen
= GetGValue(c_L
);
783 ptr
->rgbBlue
= GetBValue(c_L
);