2 * GDI device-independent bitmaps
4 * Copyright 1993,1994 Alexandre Julliard
18 extern void CLIPPING_UpdateGCRegion(DC
* );
20 static int bitmapDepthTable
[] = { 8, 1, 32, 16, 24, 15, 4, 0 };
21 static int ximageDepthTable
[] = { 0, 0, 0, 0, 0, 0, 0 };
24 /* This structure holds the arguments for DIB_SetImageBits() */
33 const BITMAPINFO
*info
;
43 } DIB_SETIMAGEBITS_DESCR
;
46 /***********************************************************************
54 for( i
= 0; bitmapDepthTable
[i
]; i
++ )
56 testimage
= TSXCreateImage(display
, DefaultVisualOfScreen(screen
),
57 bitmapDepthTable
[i
], ZPixmap
, 0, NULL
, 1, 1, 32, 20 );
58 if( testimage
) ximageDepthTable
[i
] = testimage
->bits_per_pixel
;
60 TSXDestroyImage(testimage
);
65 /***********************************************************************
66 * DIB_GetXImageWidthBytes
68 * Return the width of an X image in bytes
70 int DIB_GetXImageWidthBytes( int width
, int depth
)
74 if (!ximageDepthTable
[0]) {
77 for( i
= 0; bitmapDepthTable
[i
] ; i
++ )
78 if( bitmapDepthTable
[i
] == depth
)
79 return (4 * ((width
* ximageDepthTable
[i
] + 31)/32));
81 WARN(bitmap
, "(%d): Unsupported depth\n", depth
);
85 /***********************************************************************
86 * DIB_GetDIBWidthBytes
88 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
89 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
91 int DIB_GetDIBWidthBytes( int width
, int depth
)
97 case 1: words
= (width
+ 31) / 32; break;
98 case 4: words
= (width
+ 7) / 8; break;
99 case 8: words
= (width
+ 3) / 4; break;
101 case 16: words
= (width
+ 1) / 2; break;
102 case 24: words
= (width
* 3 + 3)/4; break;
105 WARN(bitmap
, "(%d): Unsupported depth\n", depth
);
114 /***********************************************************************
117 * Return the size of the bitmap info structure including color table.
119 int DIB_BitmapInfoSize( BITMAPINFO
* info
, WORD coloruse
)
123 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
125 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)info
;
126 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
127 return sizeof(BITMAPCOREHEADER
) + colors
*
128 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
130 else /* assume BITMAPINFOHEADER */
132 colors
= info
->bmiHeader
.biClrUsed
;
133 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
134 colors
= 1 << info
->bmiHeader
.biBitCount
;
135 return sizeof(BITMAPINFOHEADER
) + colors
*
136 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
141 /***********************************************************************
144 * Get the info from a bitmap header.
145 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
147 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, DWORD
*width
,
148 int *height
, WORD
*bpp
)
150 if (header
->biSize
== sizeof(BITMAPINFOHEADER
))
152 *width
= header
->biWidth
;
153 *height
= header
->biHeight
;
154 *bpp
= header
->biBitCount
;
157 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
159 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)header
;
160 *width
= core
->bcWidth
;
161 *height
= core
->bcHeight
;
162 *bpp
= core
->bcBitCount
;
165 WARN(bitmap
, "(%ld): wrong size for header\n", header
->biSize
);
170 /***********************************************************************
173 * Build the color map from the bitmap palette. Should not be called
174 * for a 24-bit deep bitmap.
176 static int *DIB_BuildColorMap( DC
*dc
, WORD coloruse
, WORD depth
,
177 const BITMAPINFO
*info
)
184 if ((isInfo
= (info
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))))
186 colors
= info
->bmiHeader
.biClrUsed
;
187 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
188 colorPtr
= (WORD
*)info
->bmiColors
;
190 else /* assume BITMAPCOREINFO */
192 colors
= 1 << ((BITMAPCOREHEADER
*)&info
->bmiHeader
)->bcBitCount
;
193 colorPtr
= (WORD
*)((BITMAPCOREINFO
*)info
)->bmciColors
;
195 if (!(colorMapping
= (int *)HeapAlloc(GetProcessHeap(), 0,
196 colors
* sizeof(int) ))) return NULL
;
198 if (coloruse
== DIB_RGB_COLORS
)
202 RGBQUAD
* rgb
= (RGBQUAD
*)colorPtr
;
204 if (depth
== 1) /* Monochrome */
205 for (i
= 0; i
< colors
; i
++, rgb
++)
206 colorMapping
[i
] = (rgb
->rgbRed
+ rgb
->rgbGreen
+
207 rgb
->rgbBlue
> 255*3/2);
209 for (i
= 0; i
< colors
; i
++, rgb
++)
210 colorMapping
[i
] = COLOR_ToPhysical( dc
, RGB(rgb
->rgbRed
,
216 RGBTRIPLE
* rgb
= (RGBTRIPLE
*)colorPtr
;
218 if (depth
== 1) /* Monochrome */
219 for (i
= 0; i
< colors
; i
++, rgb
++)
220 colorMapping
[i
] = (rgb
->rgbtRed
+ rgb
->rgbtGreen
+
221 rgb
->rgbtBlue
> 255*3/2);
223 for (i
= 0; i
< colors
; i
++, rgb
++)
224 colorMapping
[i
] = COLOR_ToPhysical( dc
, RGB(rgb
->rgbtRed
,
229 else /* DIB_PAL_COLORS */
231 for (i
= 0; i
< colors
; i
++, colorPtr
++)
232 colorMapping
[i
] = COLOR_ToPhysical( dc
, PALETTEINDEX(*colorPtr
) );
237 /***********************************************************************
238 * DIB_SetImageBits_1_Line
240 * Handles a single line of 1 bit data.
242 static void DIB_SetImageBits_1_Line(DWORD dstwidth
, int left
, int *colors
,
243 XImage
*bmpImage
, int h
, const BYTE
*bits
)
248 dstwidth
+= left
; bits
+= left
>> 3;
250 /* FIXME: should avoid putting x<left pixels (minor speed issue) */
251 for (i
= dstwidth
/8, x
= left
&~7; (i
> 0); i
--)
254 XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 7] );
255 XPutPixel( bmpImage
, x
++, h
, colors
[(pix
>> 6) & 1] );
256 XPutPixel( bmpImage
, x
++, h
, colors
[(pix
>> 5) & 1] );
257 XPutPixel( bmpImage
, x
++, h
, colors
[(pix
>> 4) & 1] );
258 XPutPixel( bmpImage
, x
++, h
, colors
[(pix
>> 3) & 1] );
259 XPutPixel( bmpImage
, x
++, h
, colors
[(pix
>> 2) & 1] );
260 XPutPixel( bmpImage
, x
++, h
, colors
[(pix
>> 1) & 1] );
261 XPutPixel( bmpImage
, x
++, h
, colors
[pix
& 1] );
266 case 7: XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 7] ); pix
<<= 1;
267 case 6: XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 7] ); pix
<<= 1;
268 case 5: XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 7] ); pix
<<= 1;
269 case 4: XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 7] ); pix
<<= 1;
270 case 3: XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 7] ); pix
<<= 1;
271 case 2: XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 7] ); pix
<<= 1;
272 case 1: XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 7] );
276 /***********************************************************************
279 * SetDIBits for a 1-bit deep DIB.
281 static void DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
282 DWORD srcwidth
, DWORD dstwidth
, int left
,
283 int *colors
, XImage
*bmpImage
)
288 DWORD linebytes
= ((srcwidth
+ 31) & ~31) / 8;
291 for (h
= lines
-1; h
>=0; h
--) {
292 DIB_SetImageBits_1_Line(dstwidth
, left
, colors
, bmpImage
, h
, srcbits
);
293 srcbits
+= linebytes
;
297 for (h
= 0; h
< lines
; h
++) {
298 DIB_SetImageBits_1_Line(dstwidth
, left
, colors
, bmpImage
, h
, srcbits
);
299 srcbits
+= linebytes
;
305 /***********************************************************************
308 * SetDIBits for a 4-bit deep DIB.
310 static void DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
311 DWORD srcwidth
, DWORD dstwidth
, int left
,
312 int *colors
, XImage
*bmpImage
)
316 const BYTE
*bits
= srcbits
+ (left
>> 1);
319 DWORD linebytes
= ((srcwidth
+7)&~7)/2;
323 /* FIXME: should avoid putting x<left pixels (minor speed issue) */
325 for (h
= lines
-1; h
>= 0; h
--) {
326 for (i
= dstwidth
/2, x
= left
&~1; i
> 0; i
--) {
328 XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 4] );
329 XPutPixel( bmpImage
, x
++, h
, colors
[pix
& 0x0f] );
331 if (dstwidth
& 1) XPutPixel( bmpImage
, x
, h
, colors
[*bits
>> 4] );
332 srcbits
+= linebytes
;
333 bits
= srcbits
+ (left
>> 1);
337 for (h
= 0; h
< lines
; h
++) {
338 for (i
= dstwidth
/2, x
= left
&~1; i
> 0; i
--) {
340 XPutPixel( bmpImage
, x
++, h
, colors
[pix
>> 4] );
341 XPutPixel( bmpImage
, x
++, h
, colors
[pix
& 0x0f] );
343 if (dstwidth
& 1) XPutPixel( bmpImage
, x
, h
, colors
[*bits
>> 4] );
344 srcbits
+= linebytes
;
345 bits
= srcbits
+ (left
>> 1);
350 #define check_xy(x,y) \
357 /***********************************************************************
358 * DIB_SetImageBits_RLE4
360 * SetDIBits for a 4-bit deep compressed DIB.
362 static void DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
, DWORD width
,
363 DWORD dstwidth
, int left
, int *colors
, XImage
*bmpImage
)
365 int x
= 0, c
, length
;
366 const BYTE
*begin
= bits
;
368 dstwidth
+= left
; /* FIXME: avoid putting x<left pixels */
371 while ((int)lines
>= 0)
374 if (length
) { /* encoded */
377 XPutPixel(bmpImage
, x
++, lines
, colors
[c
>> 4]);
381 XPutPixel(bmpImage
, x
++, lines
, colors
[c
& 0xf]);
393 case 1: /* eopicture */
401 default: /* absolute */
404 XPutPixel(bmpImage
, x
++, lines
, colors
[c
>> 4]);
408 XPutPixel(bmpImage
, x
++, lines
, colors
[c
& 0xf]);
412 if ((bits
- begin
) & 1)
419 /***********************************************************************
422 * SetDIBits for an 8-bit deep DIB.
424 static void DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
425 DWORD srcwidth
, DWORD dstwidth
, int left
,
426 int *colors
, XImage
*bmpImage
)
430 const BYTE
*bits
= srcbits
+ left
;
432 /* align to 32 bit */
433 DWORD linebytes
= (srcwidth
+ 3) & ~3;
438 for (h
= lines
- 1; h
>= 0; h
--) {
439 for (x
= left
; x
< dstwidth
; x
++, bits
++) {
440 XPutPixel( bmpImage
, x
, h
, colors
[*bits
] );
442 bits
= (srcbits
+= linebytes
) + left
;
446 for (h
= 0; h
< lines
; h
++) {
447 for (x
= left
; x
< dstwidth
; x
++, bits
++) {
448 XPutPixel( bmpImage
, x
, h
, colors
[*bits
] );
450 bits
= (srcbits
+= linebytes
) + left
;
455 /***********************************************************************
456 * DIB_SetImageBits_RLE8
458 * SetDIBits for an 8-bit deep compressed DIB.
460 * This function rewritten 941113 by James Youngman. WINE blew out when I
461 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
463 * This was because the algorithm assumed that all RLE8 bitmaps end with the
464 * 'End of bitmap' escape code. This code is very much laxer in what it
465 * allows to end the expansion. Possibly too lax. See the note by
466 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
467 * bitmap should end with RleEnd, but on the other hand, software exists
468 * that produces ones that don't and Windows 3.1 doesn't complain a bit
471 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
472 * James A. Youngman <mbcstjy@afs.man.ac.uk>
476 enum Rle8_EscapeCodes
479 * Apologies for polluting your file's namespace...
481 RleEol
= 0, /* End of line */
482 RleEnd
= 1, /* End of bitmap */
483 RleDelta
= 2 /* Delta */
486 static void DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
, DWORD width
,
487 DWORD dstwidth
, int left
, int *colors
, XImage
*bmpImage
)
489 int x
; /* X-positon on each line. Increases. */
490 int line
; /* Line #. Starts at lines-1, decreases */
491 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
492 BYTE length
; /* The length pf a run */
493 BYTE color_index
; /* index into colors[] as read from bits */
494 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
495 WORD color
; /* value of colour[color_index] */
497 if (lines
== 0) /* Let's hope this doesn't happen. */
500 dstwidth
+= left
; /* FIXME: avoid putting x<left pixels */
503 * Note that the bitmap data is stored by Windows starting at the
504 * bottom line of the bitmap and going upwards. Within each line,
505 * the data is stored left-to-right. That's the reason why line
506 * goes from lines-1 to 0. [JAY]
516 * If the length byte is not zero (which is the escape value),
517 * We have a run of length pixels all the same colour. The colour
518 * index is stored next.
520 * If the length byte is zero, we need to read the next byte to
521 * know what to do. [JAY]
526 * [Run-Length] Encoded mode
528 color_index
= (*pIn
++); /* Get the colour index. */
529 color
= colors
[color_index
];
532 XPutPixel(bmpImage
, x
++, line
, color
);
537 * Escape codes (may be an absolute sequence though)
539 escape_code
= (*pIn
++);
542 case RleEol
: /* =0, end of line */
549 case RleEnd
: /* =1, end of bitmap */
552 * Not all RLE8 bitmaps end with this
553 * code. For example, Paint Shop Pro
554 * produces some that don't. That's (I think)
555 * what caused the previous implementation to
558 line
=-1; /* Cause exit from do loop. */
562 case RleDelta
: /* =2, a delta */
565 * Note that deltaing to line 0
566 * will cause an exit from the loop,
567 * which may not be what is intended.
568 * The fact that there is a delta in the bits
569 * almost certainly implies that there is data
570 * to follow. You may feel that we should
571 * jump to the top of the loop to avoid exiting
574 * TODO: Decide what to do here in that case. [JAY]
580 TRACE(bitmap
, "Delta to last line of bitmap "
581 "(wrongly?) causes loop exit\n");
586 default: /* >2, switch to absolute mode */
591 length
= escape_code
;
594 color_index
= (*pIn
++);
595 XPutPixel(bmpImage
, x
++, line
,
596 colors
[color_index
]);
600 * If you think for a moment you'll realise that the
601 * only time we could ever possibly read an odd
602 * number of bytes is when there is a 0x00 (escape),
603 * a value >0x02 (absolute mode) and then an odd-
604 * length run. Therefore this is the only place we
605 * need to worry about it. Everywhere else the
606 * bytes are always read in pairs. [JAY]
609 pIn
++; /* Throw away the pad byte. */
612 } /* switch (escape_code) : Escape sequence */
613 } /* process either an encoded sequence or an escape sequence */
615 /* We expect to come here more than once per line. */
616 } while (line
>= 0); /* Do this until the bitmap is filled */
619 * Everybody comes here at the end.
620 * Check how we exited the loop and print a message if it's a bit odd.
623 if ( (*(pIn
-2) != 0/*escape*/) || (*(pIn
-1)!= RleEnd
) )
625 TRACE(bitmap
, "End-of-bitmap "
626 "without (strictly) proper escape code. Last two "
627 "bytes were: %02X %02X.\n",
634 /***********************************************************************
635 * DIB_SetImageBits_16
637 * SetDIBits for a 16-bit deep DIB.
639 static void DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
640 DWORD srcwidth
, DWORD dstwidth
, int left
,
641 DC
*dc
, XImage
*bmpImage
)
649 /* align to 32 bit */
650 DWORD linebytes
= (srcwidth
* 2 + 3) & ~3;
654 ptr
= (LPWORD
) srcbits
+ left
;
656 for (h
= lines
- 1; h
>= 0; h
--) {
657 for (x
= left
; x
< dstwidth
; x
++, ptr
++) {
659 r
= (BYTE
) ((val
& 0x7c00) >> 7);
660 g
= (BYTE
) ((val
& 0x03e0) >> 2);
661 b
= (BYTE
) ((val
& 0x001f) << 3);
662 XPutPixel( bmpImage
, x
, h
,
663 COLOR_ToPhysical(dc
, RGB(r
,g
,b
)) );
665 ptr
= (LPWORD
) (srcbits
+= linebytes
) + left
;
669 for (h
= 0; h
< lines
; h
++) {
670 for (x
= left
; x
< dstwidth
; x
++, ptr
++) {
672 r
= (BYTE
) ((val
& 0x7c00) >> 7);
673 g
= (BYTE
) ((val
& 0x03e0) >> 2);
674 b
= (BYTE
) ((val
& 0x001f) << 3);
675 XPutPixel( bmpImage
, x
, h
,
676 COLOR_ToPhysical(dc
, RGB(r
,g
,b
)) );
678 ptr
= (LPWORD
) (srcbits
+= linebytes
) + left
;
684 /***********************************************************************
685 * DIB_SetImageBits_24
687 * SetDIBits for a 24-bit deep DIB.
689 static void DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
690 DWORD srcwidth
, DWORD dstwidth
, int left
,
691 DC
*dc
, XImage
*bmpImage
)
694 const BYTE
*bits
= srcbits
+ left
* 3;
697 /* align to 32 bit */
698 DWORD linebytes
= (srcwidth
* 3 + 3) & ~3;
702 /* "bits" order is reversed for some reason */
705 for (h
= lines
- 1; h
>= 0; h
--) {
706 for (x
= left
; x
< dstwidth
; x
++, bits
+= 3) {
707 XPutPixel( bmpImage
, x
, h
,
708 COLOR_ToPhysical(dc
, RGB(bits
[2],bits
[1],bits
[0])));
710 bits
= (srcbits
+= linebytes
) + left
* 3;
714 for (h
= 0; h
< lines
; h
++) {
715 for (x
= left
; x
< dstwidth
; x
++, bits
+= 3) {
716 XPutPixel( bmpImage
, x
, h
,
717 COLOR_ToPhysical(dc
, RGB(bits
[2],bits
[1],bits
[0])));
719 bits
= (srcbits
+= linebytes
) + left
* 3;
725 /***********************************************************************
726 * DIB_SetImageBits_32
728 * SetDIBits for a 32-bit deep DIB.
730 static void DIB_SetImageBits_32( int lines
, const BYTE
*srcbits
,
731 DWORD srcwidth
, DWORD dstwidth
, int left
,
732 DC
*dc
, XImage
*bmpImage
)
735 const BYTE
*bits
= srcbits
+ left
* 4;
738 DWORD linebytes
= (srcwidth
* 4);
743 for (h
= lines
- 1; h
>= 0; h
--) {
744 for (x
= left
; x
< dstwidth
; x
++, bits
+= 4) {
745 XPutPixel( bmpImage
, x
, h
,
746 COLOR_ToPhysical(dc
, RGB(bits
[2],bits
[1],bits
[0])));
748 bits
= (srcbits
+= linebytes
) + left
* 4;
752 for (h
= 0; h
< lines
; h
++) {
753 for (x
= left
; x
< dstwidth
; x
++, bits
+= 4) {
754 XPutPixel( bmpImage
, x
, h
,
755 COLOR_ToPhysical(dc
, RGB(bits
[2],bits
[1],bits
[0])));
757 bits
= (srcbits
+= linebytes
) + left
* 4;
763 /***********************************************************************
766 * Transfer the bits to an X image.
767 * Helper function for SetDIBits() and SetDIBitsToDevice().
768 * The Xlib critical section must be entered before calling this function.
770 static int DIB_SetImageBits( const DIB_SETIMAGEBITS_DESCR
*descr
)
774 DWORD compression
= 0;
777 if (descr
->info
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
778 compression
= descr
->info
->bmiHeader
.biCompression
;
780 /* Build the color mapping table */
782 if (descr
->infoBpp
> 8) colorMapping
= NULL
;
783 else if (!(colorMapping
= DIB_BuildColorMap( descr
->dc
, descr
->coloruse
,
784 descr
->depth
, descr
->info
)))
787 if( descr
->dc
->w
.flags
& DC_DIRTY
) CLIPPING_UpdateGCRegion(descr
->dc
);
789 /* Transfer the pixels */
790 lines
= descr
->lines
;
791 if (lines
< 0) lines
= -lines
;
792 XCREATEIMAGE(bmpImage
, descr
->infoWidth
, lines
, descr
->depth
);
794 switch(descr
->infoBpp
)
797 DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
798 descr
->width
, descr
->xSrc
, colorMapping
, bmpImage
);
801 if (compression
) DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
802 descr
->infoWidth
, descr
->width
, descr
->xSrc
,
803 colorMapping
, bmpImage
);
804 else DIB_SetImageBits_4( descr
->lines
, descr
->bits
, descr
->infoWidth
,
805 descr
->width
, descr
->xSrc
, colorMapping
, bmpImage
);
808 if (compression
) DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
809 descr
->infoWidth
, descr
->width
, descr
->xSrc
,
810 colorMapping
, bmpImage
);
811 else DIB_SetImageBits_8( descr
->lines
, descr
->bits
, descr
->infoWidth
,
812 descr
->width
, descr
->xSrc
, colorMapping
, bmpImage
);
816 DIB_SetImageBits_16( descr
->lines
, descr
->bits
, descr
->infoWidth
,
817 descr
->width
, descr
->xSrc
, descr
->dc
, bmpImage
);
820 DIB_SetImageBits_24( descr
->lines
, descr
->bits
, descr
->infoWidth
,
821 descr
->width
, descr
->xSrc
, descr
->dc
, bmpImage
);
824 DIB_SetImageBits_32( descr
->lines
, descr
->bits
, descr
->infoWidth
,
825 descr
->width
, descr
->xSrc
, descr
->dc
, bmpImage
);
828 WARN(bitmap
, "(%d): Invalid depth\n", descr
->infoBpp
);
831 if (colorMapping
) HeapFree( GetProcessHeap(), 0, colorMapping
);
832 XPutImage( display
, descr
->drawable
, descr
->gc
, bmpImage
,
833 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
834 descr
->width
, descr
->height
);
835 XDestroyImage( bmpImage
);
840 /***********************************************************************
841 * StretchDIBits16 (GDI.439)
843 INT16 WINAPI
StretchDIBits16(HDC16 hdc
, INT16 xDst
, INT16 yDst
, INT16 widthDst
,
844 INT16 heightDst
, INT16 xSrc
, INT16 ySrc
, INT16 widthSrc
,
845 INT16 heightSrc
, const VOID
*bits
,
846 const BITMAPINFO
*info
, UINT16 wUsage
, DWORD dwRop
)
848 return (INT16
)StretchDIBits32( hdc
, xDst
, yDst
, widthDst
, heightDst
,
849 xSrc
, ySrc
, widthSrc
, heightSrc
, bits
,
850 info
, wUsage
, dwRop
);
854 /***********************************************************************
855 * StretchDIBits32 (GDI32.351)
857 INT32 WINAPI
StretchDIBits32(HDC32 hdc
, INT32 xDst
, INT32 yDst
, INT32 widthDst
,
858 INT32 heightDst
, INT32 xSrc
, INT32 ySrc
, INT32 widthSrc
,
859 INT32 heightSrc
, const void *bits
,
860 const BITMAPINFO
*info
, UINT32 wUsage
, DWORD dwRop
)
862 HBITMAP32 hBitmap
, hOldBitmap
;
865 hBitmap
= CreateDIBitmap32( hdc
, &info
->bmiHeader
, CBM_INIT
,
866 bits
, info
, wUsage
);
867 hdcMem
= CreateCompatibleDC32( hdc
);
868 hOldBitmap
= SelectObject32( hdcMem
, hBitmap
);
869 StretchBlt32( hdc
, xDst
, yDst
, widthDst
, heightDst
,
870 hdcMem
, xSrc
, ySrc
, widthSrc
, heightSrc
, dwRop
);
871 SelectObject32( hdcMem
, hOldBitmap
);
872 DeleteDC32( hdcMem
);
873 DeleteObject32( hBitmap
);
878 /***********************************************************************
879 * SetDIBits16 (GDI.440)
881 INT16 WINAPI
SetDIBits16( HDC16 hdc
, HBITMAP16 hbitmap
, UINT16 startscan
,
882 UINT16 lines
, LPCVOID bits
, const BITMAPINFO
*info
,
885 return SetDIBits32( hdc
, hbitmap
, startscan
, lines
, bits
, info
, coloruse
);
889 /******************************************************************************
890 * SetDIBits32 [GDI32.312] Sets pixels in a bitmap using colors from DIB
893 * hdc [I] Handle to device context
894 * hbitmap [I] Handle to bitmap
895 * startscan [I] Starting scan line
896 * lines [I] Number of scan lines
897 * bits [I] Array of bitmap bits
898 * info [I] Address of structure with data
899 * coloruse [I] Type of color indexes to use
902 * Success: Number of scan lines copied
905 INT32 WINAPI
SetDIBits32( HDC32 hdc
, HBITMAP32 hbitmap
, UINT32 startscan
,
906 UINT32 lines
, LPCVOID bits
, const BITMAPINFO
*info
,
909 DIB_SETIMAGEBITS_DESCR descr
;
911 int height
, tmpheight
;
914 /* Check parameters */
916 descr
.dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
919 descr
.dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
920 if (!descr
.dc
) return 0;
922 if (!(bmp
= (BITMAPOBJ
*)GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
)))
924 GDI_HEAP_UNLOCK( hdc
);
927 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &descr
.infoWidth
, &height
,
928 &descr
.infoBpp
) == -1)
930 GDI_HEAP_UNLOCK( hbitmap
);
931 GDI_HEAP_UNLOCK( hdc
);
935 if (height
< 0) height
= -height
;
936 if (!lines
|| (startscan
>= height
))
938 GDI_HEAP_UNLOCK( hbitmap
);
939 GDI_HEAP_UNLOCK( hdc
);
942 if (startscan
+ lines
> height
) lines
= height
- startscan
;
945 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
946 descr
.depth
= bmp
->bitmap
.bmBitsPixel
;
948 descr
.coloruse
= coloruse
;
949 descr
.drawable
= bmp
->pixmap
;
950 descr
.gc
= BITMAP_GC(bmp
);
954 descr
.yDest
= height
- startscan
- lines
;
955 descr
.width
= bmp
->bitmap
.bmWidth
;
956 descr
.height
= lines
;
958 EnterCriticalSection( &X11DRV_CritSection
);
959 result
= CALL_LARGE_STACK( DIB_SetImageBits
, &descr
);
960 LeaveCriticalSection( &X11DRV_CritSection
);
962 GDI_HEAP_UNLOCK( hdc
);
963 GDI_HEAP_UNLOCK( hbitmap
);
968 /***********************************************************************
969 * SetDIBitsToDevice16 (GDI.443)
971 INT16 WINAPI
SetDIBitsToDevice16(HDC16 hdc
, INT16 xDest
, INT16 yDest
, INT16 cx
,
972 INT16 cy
, INT16 xSrc
, INT16 ySrc
, UINT16 startscan
,
973 UINT16 lines
, LPCVOID bits
, const BITMAPINFO
*info
,
976 return SetDIBitsToDevice32( hdc
, xDest
, yDest
, cx
, cy
, xSrc
, ySrc
,
977 startscan
, lines
, bits
, info
, coloruse
);
981 /***********************************************************************
982 * SetDIBitsToDevice32 (GDI32.313)
984 INT32 WINAPI
SetDIBitsToDevice32(HDC32 hdc
, INT32 xDest
, INT32 yDest
, DWORD cx
,
985 DWORD cy
, INT32 xSrc
, INT32 ySrc
, UINT32 startscan
,
986 UINT32 lines
, LPCVOID bits
, const BITMAPINFO
*info
,
989 DIB_SETIMAGEBITS_DESCR descr
;
991 DWORD width
, oldcy
= cy
;
993 int height
, tmpheight
;
995 /* Check parameters */
997 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1000 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
1003 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
,
1004 &height
, &descr
.infoBpp
) == -1)
1007 if (height
< 0) height
= -height
;
1008 if (!lines
|| (startscan
>= height
)) return 0;
1009 if (startscan
+ lines
> height
) lines
= height
- startscan
;
1010 if (ySrc
< startscan
) ySrc
= startscan
;
1011 else if (ySrc
>= startscan
+ lines
) return 0;
1012 if (xSrc
>= width
) return 0;
1013 if (ySrc
+ cy
>= startscan
+ lines
) cy
= startscan
+ lines
- ySrc
;
1014 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
1015 if (!cx
|| !cy
) return 0;
1017 DC_SetupGCForText( dc
); /* To have the correct colors */
1018 TSXSetFunction( display
, dc
->u
.x
.gc
, DC_XROPfunction
[dc
->w
.ROPmode
-1] );
1022 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
1023 descr
.infoWidth
= width
;
1024 descr
.depth
= dc
->w
.bitsPerPixel
;
1026 descr
.coloruse
= coloruse
;
1027 descr
.drawable
= dc
->u
.x
.drawable
;
1028 descr
.gc
= dc
->u
.x
.gc
;
1030 descr
.ySrc
= tmpheight
>= 0 ? lines
-(ySrc
-startscan
)-cy
+(oldcy
-cy
) : ySrc
- startscan
;
1031 descr
.xDest
= dc
->w
.DCOrgX
+ XLPTODP( dc
, xDest
);
1032 descr
.yDest
= dc
->w
.DCOrgY
+ YLPTODP( dc
, yDest
) + (tmpheight
>= 0 ? oldcy
-cy
: 0);
1036 EnterCriticalSection( &X11DRV_CritSection
);
1037 result
= CALL_LARGE_STACK( DIB_SetImageBits
, &descr
);
1038 LeaveCriticalSection( &X11DRV_CritSection
);
1042 /***********************************************************************
1043 * SetDIBColorTable32 (GDI32.311)
1045 UINT32 WINAPI
SetDIBColorTable32( HDC32 hdc
, UINT32 startpos
, UINT32 entries
,
1049 PALETTEENTRY
* palEntry
;
1050 PALETTEOBJ
* palette
;
1053 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1056 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
1060 if (!(palette
= (PALETTEOBJ
*)GDI_GetObjPtr( dc
->w
.hPalette
, PALETTE_MAGIC
)))
1065 /* Transfer color info */
1067 if (dc
->w
.bitsPerPixel
<= 8) {
1068 palEntry
= palette
->logpalette
.palPalEntry
+ startpos
;
1069 if (startpos
+ entries
> (1 << dc
->w
.bitsPerPixel
)) {
1070 entries
= (1 << dc
->w
.bitsPerPixel
) - startpos
;
1072 for (end
= colors
+ entries
; colors
< end
; palEntry
++, colors
++)
1074 palEntry
->peRed
= colors
->rgbRed
;
1075 palEntry
->peGreen
= colors
->rgbGreen
;
1076 palEntry
->peBlue
= colors
->rgbBlue
;
1081 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
1085 /***********************************************************************
1086 * GetDIBColorTable32 (GDI32.169)
1088 UINT32 WINAPI
GetDIBColorTable32( HDC32 hdc
, UINT32 startpos
, UINT32 entries
,
1092 PALETTEENTRY
* palEntry
;
1093 PALETTEOBJ
* palette
;
1096 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1099 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
1103 if (!(palette
= (PALETTEOBJ
*)GDI_GetObjPtr( dc
->w
.hPalette
, PALETTE_MAGIC
)))
1108 /* Transfer color info */
1110 if (dc
->w
.bitsPerPixel
<= 8) {
1111 palEntry
= palette
->logpalette
.palPalEntry
+ startpos
;
1112 if (startpos
+ entries
> (1 << dc
->w
.bitsPerPixel
)) {
1113 entries
= (1 << dc
->w
.bitsPerPixel
) - startpos
;
1115 for (end
= colors
+ entries
; colors
< end
; palEntry
++, colors
++)
1117 colors
->rgbRed
= palEntry
->peRed
;
1118 colors
->rgbGreen
= palEntry
->peGreen
;
1119 colors
->rgbBlue
= palEntry
->peBlue
;
1120 colors
->rgbReserved
= 0;
1125 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
1129 /***********************************************************************
1130 * GetDIBits16 (GDI.441)
1132 INT16 WINAPI
GetDIBits16( HDC16 hdc
, HBITMAP16 hbitmap
, UINT16 startscan
,
1133 UINT16 lines
, LPSTR bits
, BITMAPINFO
* info
,
1136 return GetDIBits32( hdc
, hbitmap
, startscan
, lines
, bits
, info
, coloruse
);
1140 /******************************************************************************
1141 * GetDIBits32 [GDI32.170] Retrieves bits of bitmap and copies to buffer
1144 * Success: Number of scan lines copied from bitmap
1147 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/func/src/f30_14.htm
1149 INT32 WINAPI
GetDIBits32(
1150 HDC32 hdc
, /* [in] Handle to device context */
1151 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
1152 UINT32 startscan
, /* [in] First scan line to set in dest bitmap */
1153 UINT32 lines
, /* [in] Number of scan lines to copy */
1154 LPSTR bits
, /* [out] Address of array for bitmap bits */
1155 BITMAPINFO
* info
, /* [out] Address of structure with bitmap data */
1156 UINT32 coloruse
) /* [in] RGB or palette index */
1160 PALETTEENTRY
* palEntry
;
1161 PALETTEOBJ
* palette
;
1165 if (!lines
) return 0;
1166 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1169 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
1172 if (!(bmp
= (BITMAPOBJ
*)GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
)))
1174 if (!(palette
= (PALETTEOBJ
*)GDI_GetObjPtr( dc
->w
.hPalette
, PALETTE_MAGIC
)))
1176 GDI_HEAP_UNLOCK( hbitmap
);
1180 /* Transfer color info */
1182 if (info
->bmiHeader
.biBitCount
<=8) {
1183 palEntry
= palette
->logpalette
.palPalEntry
;
1184 for (i
= 0; i
< info
->bmiHeader
.biClrUsed
; i
++, palEntry
++)
1186 if (coloruse
== DIB_RGB_COLORS
)
1188 info
->bmiColors
[i
].rgbRed
= palEntry
->peRed
;
1189 info
->bmiColors
[i
].rgbGreen
= palEntry
->peGreen
;
1190 info
->bmiColors
[i
].rgbBlue
= palEntry
->peBlue
;
1191 info
->bmiColors
[i
].rgbReserved
= 0;
1193 else ((WORD
*)info
->bmiColors
)[i
] = (WORD
)i
;
1200 int pad
, yend
, xend
= bmp
->bitmap
.bmWidth
;
1202 TRACE(bitmap
, "%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
1203 lines
, bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
1204 (int)info
->bmiHeader
.biWidth
, (int)info
->bmiHeader
.biHeight
, startscan
);
1206 /* adjust number of scanlines to copy */
1208 if( lines
> info
->bmiHeader
.biHeight
) lines
= info
->bmiHeader
.biHeight
;
1209 yend
= startscan
+ lines
;
1210 if( startscan
>= bmp
->bitmap
.bmHeight
)
1212 GDI_HEAP_UNLOCK( hbitmap
);
1213 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
1216 if( yend
> bmp
->bitmap
.bmHeight
) yend
= bmp
->bitmap
.bmHeight
;
1218 /* adjust scanline width */
1220 pad
= info
->bmiHeader
.biWidth
- bmp
->bitmap
.bmWidth
;
1223 /* bitmap is wider than DIB, copy only a part */
1226 xend
= info
->bmiHeader
.biWidth
;
1229 EnterCriticalSection( &X11DRV_CritSection
);
1230 bmpImage
= (XImage
*)CALL_LARGE_STACK( BITMAP_GetXImage
, bmp
);
1232 switch( info
->bmiHeader
.biBitCount
)
1235 /* pad up to 32 bit */
1236 pad
+= (4 - (info
->bmiHeader
.biWidth
& 3)) & 3;
1237 for( y
= yend
- 1; (int)y
>= (int)startscan
; y
-- )
1239 for( x
= 0; x
< xend
; x
++ )
1240 *bbits
++ = XGetPixel( bmpImage
, x
, y
);
1245 pad
+= ((32 - (info
->bmiHeader
.biWidth
& 31)) / 8) & 3;
1246 for( y
= yend
- 1; (int)y
>= (int)startscan
; y
-- )
1249 for( x
= 0; x
< xend
; x
++ ) {
1251 *bbits
|= XGetPixel( bmpImage
, x
, y
)<<(7-(x
&7));
1261 pad
+= ((8 - (info
->bmiHeader
.biWidth
& 7)) / 2) & 3;
1262 for( y
= yend
- 1; (int)y
>= (int)startscan
; y
-- )
1265 for( x
= 0; x
< xend
; x
++ ) {
1267 *bbits
|= XGetPixel( bmpImage
, x
, y
)<<(4*(1-(x
&1)));
1278 pad
+= (4 - ((info
->bmiHeader
.biWidth
*2) & 3)) & 3;
1279 for( y
= yend
- 1; (int)y
>= (int)startscan
; y
-- )
1282 for( x
= 0; x
< xend
; x
++ ) {
1283 unsigned long pixel
=XGetPixel( bmpImage
, x
, y
);
1284 *bbits
++ = pixel
& 0xff;
1285 *bbits
++ = (pixel
>> 8) & 0xff;
1291 pad
+= (4 - ((info
->bmiHeader
.biWidth
*3) & 3)) & 3;
1292 for( y
= yend
- 1; (int)y
>= (int)startscan
; y
-- )
1295 for( x
= 0; x
< xend
; x
++ ) {
1296 unsigned long pixel
=XGetPixel( bmpImage
, x
, y
);
1297 *bbits
++ = (pixel
>>16) & 0xff;
1298 *bbits
++ = (pixel
>> 8) & 0xff;
1299 *bbits
++ = pixel
& 0xff;
1305 for( y
= yend
- 1; (int)y
>= (int)startscan
; y
-- )
1308 for( x
= 0; x
< xend
; x
++ ) {
1309 unsigned long pixel
=XGetPixel( bmpImage
, x
, y
);
1310 *bbits
++ = (pixel
>>16) & 0xff;
1311 *bbits
++ = (pixel
>> 8) & 0xff;
1312 *bbits
++ = pixel
& 0xff;
1317 WARN(bitmap
,"Unsupported depth %d\n",
1318 info
->bmiHeader
.biBitCount
);
1322 XDestroyImage( bmpImage
);
1323 LeaveCriticalSection( &X11DRV_CritSection
);
1325 info
->bmiHeader
.biCompression
= 0;
1327 else if( info
->bmiHeader
.biSize
>= sizeof(BITMAPINFOHEADER
) )
1329 /* fill in struct members */
1331 info
->bmiHeader
.biWidth
= bmp
->bitmap
.bmWidth
;
1332 info
->bmiHeader
.biHeight
= bmp
->bitmap
.bmHeight
;
1333 info
->bmiHeader
.biPlanes
= 1;
1334 info
->bmiHeader
.biBitCount
= bmp
->bitmap
.bmBitsPixel
;
1335 info
->bmiHeader
.biSizeImage
= bmp
->bitmap
.bmHeight
*
1336 DIB_GetDIBWidthBytes( bmp
->bitmap
.bmWidth
,
1337 bmp
->bitmap
.bmBitsPixel
);
1338 info
->bmiHeader
.biCompression
= 0;
1341 GDI_HEAP_UNLOCK( hbitmap
);
1342 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
1347 /***********************************************************************
1348 * CreateDIBitmap16 (GDI.442)
1350 HBITMAP16 WINAPI
CreateDIBitmap16( HDC16 hdc
, const BITMAPINFOHEADER
* header
,
1351 DWORD init
, LPCVOID bits
, const BITMAPINFO
* data
,
1354 return CreateDIBitmap32( hdc
, header
, init
, bits
, data
, coloruse
);
1358 /***********************************************************************
1359 * CreateDIBitmap32 (GDI32.37)
1361 HBITMAP32 WINAPI
CreateDIBitmap32( HDC32 hdc
, const BITMAPINFOHEADER
*header
,
1362 DWORD init
, LPCVOID bits
, const BITMAPINFO
*data
,
1371 if (DIB_GetBitmapInfo( header
, &width
, &height
, &bpp
) == -1) return 0;
1372 if (height
< 0) height
= -height
;
1374 /* Check if we should create a monochrome or color bitmap. */
1375 /* We create a monochrome bitmap only if it has exactly 2 */
1376 /* colors, which are either black or white, nothing else. */
1377 /* In all other cases, we create a color bitmap. */
1379 if (bpp
!= 1) fColor
= TRUE
;
1380 else if ((coloruse
!= DIB_RGB_COLORS
) ||
1381 (init
!= CBM_INIT
) || !data
) fColor
= FALSE
;
1384 if (data
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
1386 RGBQUAD
*rgb
= data
->bmiColors
;
1387 DWORD col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1388 if ((col
== RGB(0,0,0)) || (col
== RGB(0xff,0xff,0xff)))
1391 col
= RGB( rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
);
1392 fColor
= ((col
!= RGB(0,0,0)) && (col
!= RGB(0xff,0xff,0xff)));
1396 else if (data
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
1398 RGBTRIPLE
*rgb
= ((BITMAPCOREINFO
*)data
)->bmciColors
;
1399 DWORD col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1400 if ((col
== RGB(0,0,0)) || (col
== RGB(0xff,0xff,0xff)))
1403 col
= RGB( rgb
->rgbtRed
, rgb
->rgbtGreen
, rgb
->rgbtBlue
);
1404 fColor
= ((col
!= RGB(0,0,0)) && (col
!= RGB(0xff,0xff,0xff)));
1410 WARN(bitmap
, "(%ld): wrong size for data\n",
1411 data
->bmiHeader
.biSize
);
1416 /* Now create the bitmap */
1418 handle
= fColor
? CreateCompatibleBitmap32( hdc
, width
, height
) :
1419 CreateBitmap32( width
, height
, 1, 1, NULL
);
1420 if (!handle
) return 0;
1422 if (init
== CBM_INIT
)
1423 SetDIBits32( hdc
, handle
, 0, height
, bits
, data
, coloruse
);
1427 /***********************************************************************
1428 * CreateDIBSection16 (GDI.489)
1430 HBITMAP16 WINAPI
CreateDIBSection16 (HDC16 hdc
, BITMAPINFO
*bmi
, UINT16 usage
,
1431 LPVOID
**bits
, HANDLE16 section
,
1434 return CreateDIBSection32 (hdc
, bmi
, usage
, bits
, section
, offset
);
1437 /***********************************************************************
1438 * CreateDIBSection32 (GDI32.36)
1440 HBITMAP32 WINAPI
CreateDIBSection32 (HDC32 hdc
, BITMAPINFO
*bmi
, UINT32 usage
,
1441 LPVOID
**bits
,HANDLE32 section
,
1447 "(%d,[w=%ld,h=%ld],%d,%p,0x%08x,%ld),semistub\n",
1448 hdc
,bmi
->bmiHeader
.biWidth
,bmi
->bmiHeader
.biHeight
,
1449 usage
,bits
,section
,offset
);
1451 if (bmi
->bmiHeader
.biHeight
< 0 ) bmi
->bmiHeader
.biHeight
= -bmi
->bmiHeader
.biHeight
;
1452 if (bmi
->bmiHeader
.biWidth
< 0 ) bmi
->bmiHeader
.biWidth
= -bmi
->bmiHeader
.biWidth
;
1453 /* FIXME. The following line isn't quite right. */
1454 res
= CreateDIBitmap32 (hdc
, &bmi
->bmiHeader
, 0, NULL
, bmi
, 0);
1458 if (GetObject32A (res
, sizeof (bmp
), &bmp
))
1460 /* FIXME: this is wrong! (bmBits is always NULL) */
1461 if (bits
) *bits
= bmp
.bmBits
;
1463 TRACE(bitmap
,"allocating %ld bytes of memory\n",
1464 bmi
->bmiHeader
.biWidth
*bmi
->bmiHeader
.biHeight
*4);
1465 if (bits
) *bits
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,
1466 bmi
->bmiHeader
.biWidth
*bmi
->bmiHeader
.biHeight
*4);
1472 if (res
) DeleteObject32 (res
);
1473 if (bits
) *bits
= NULL
;