2 * X11DRV device-independent bitmaps
4 * Copyright 1993,1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
26 #include <X11/extensions/XShm.h>
27 # ifdef HAVE_SYS_SHM_H
30 # ifdef HAVE_SYS_IPC_H
33 #endif /* defined(HAVE_LIBXXSHM) */
42 #include "wine/exception.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(bitmap
);
47 static struct list dibs_list
= LIST_INIT(dibs_list
);
49 static CRITICAL_SECTION dibs_cs
;
50 static CRITICAL_SECTION_DEBUG dibs_cs_debug
=
53 { &dibs_cs_debug
.ProcessLocksList
, &dibs_cs_debug
.ProcessLocksList
},
54 0, 0, { (DWORD_PTR
)(__FILE__
": dibs_cs") }
56 static CRITICAL_SECTION dibs_cs
= { &dibs_cs_debug
, -1, 0, 0, 0, 0 };
58 static PVOID dibs_handler
;
60 static int ximageDepthTable
[32];
62 /* This structure holds the arguments for DIB_SetImageBits() */
65 X11DRV_PDEVICE
*physDev
;
68 PALETTEENTRY
*palentry
;
87 enum x11drv_shm_mode shm_mode
;
90 X_PHYSBITMAP
*physBitmap
;
91 } X11DRV_DIB_IMAGEBITS_DESCR
;
96 RLE_EOL
= 0, /* End of line */
97 RLE_END
= 1, /* End of bitmap */
98 RLE_DELTA
= 2 /* Delta */
102 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*,INT
);
103 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*,INT
);
104 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*,BOOL
);
107 Some of the following helper functions are duplicated in
111 /***********************************************************************
112 * DIB_DoProtectDIBSection
114 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP
*physBitmap
, DWORD new_prot
)
118 VirtualProtect(physBitmap
->base
, physBitmap
->size
, new_prot
, &old_prot
);
119 TRACE("Changed protection from %d to %d\n", old_prot
, new_prot
);
122 /***********************************************************************
123 * X11DRV_DIB_GetXImageWidthBytes
125 * Return the width of an X image in bytes
127 static inline int X11DRV_DIB_GetXImageWidthBytes( int width
, int depth
)
129 if (!depth
|| depth
> 32) goto error
;
131 if (!ximageDepthTable
[depth
-1])
133 XImage
*testimage
= XCreateImage( gdi_display
, visual
, depth
,
134 ZPixmap
, 0, NULL
, 1, 1, 32, 20 );
137 ximageDepthTable
[depth
-1] = testimage
->bits_per_pixel
;
138 XDestroyImage( testimage
);
140 else ximageDepthTable
[depth
-1] = -1;
142 if (ximageDepthTable
[depth
-1] != -1)
143 return (4 * ((width
* ximageDepthTable
[depth
-1] + 31) / 32));
146 WARN( "(%d): Unsupported depth\n", depth
);
151 /***********************************************************************
152 * X11DRV_DIB_GetDIBWidthBytes
154 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
156 static int X11DRV_DIB_GetDIBWidthBytes( int width
, int depth
)
162 case 1: words
= (width
+ 31) / 32; break;
163 case 4: words
= (width
+ 7) / 8; break;
164 case 8: words
= (width
+ 3) / 4; break;
166 case 16: words
= (width
+ 1) / 2; break;
167 case 24: words
= (width
* 3 + 3) / 4; break;
169 WARN("(%d): Unsupported depth\n", depth
);
178 /***********************************************************************
179 * X11DRV_DIB_GetDIBImageBytes
181 * Return the number of bytes used to hold the image in a DIB bitmap.
183 static int X11DRV_DIB_GetDIBImageBytes( int width
, int height
, int depth
)
185 return X11DRV_DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
189 /***********************************************************************
192 * Return the size of the bitmap info structure including color table.
194 int bitmap_info_size( const BITMAPINFO
* info
, WORD coloruse
)
196 unsigned int colors
, size
, masks
= 0;
198 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
200 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
201 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
202 return sizeof(BITMAPCOREHEADER
) + colors
*
203 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
205 else /* assume BITMAPINFOHEADER */
207 colors
= info
->bmiHeader
.biClrUsed
;
208 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
209 colors
= 1 << info
->bmiHeader
.biBitCount
;
210 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
211 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
212 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
217 /***********************************************************************
218 * X11DRV_DIB_CreateXImage
222 XImage
*X11DRV_DIB_CreateXImage( int width
, int height
, int depth
)
225 XImage
*image
= NULL
;
229 width_bytes
= X11DRV_DIB_GetXImageWidthBytes( width
, depth
);
230 data
= HeapAlloc( GetProcessHeap(), 0, height
* width_bytes
);
231 if (data
) image
= XCreateImage( gdi_display
, visual
, depth
, ZPixmap
, 0,
232 data
, width
, height
, 32, width_bytes
);
233 if (!image
) HeapFree( GetProcessHeap(), 0, data
);
239 /***********************************************************************
240 * X11DRV_DIB_DestroyXImage
242 * Destroy an X image created with X11DRV_DIB_CreateXImage.
244 void X11DRV_DIB_DestroyXImage( XImage
*image
)
246 HeapFree( GetProcessHeap(), 0, image
->data
);
249 XDestroyImage( image
);
254 /***********************************************************************
255 * DIB_GetBitmapInfoEx
257 * Get the info from a bitmap header.
258 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
260 static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER
*header
, LONG
*width
,
261 LONG
*height
, WORD
*planes
, WORD
*bpp
,
262 WORD
*compr
, DWORD
*size
)
264 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
266 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
267 *width
= core
->bcWidth
;
268 *height
= core
->bcHeight
;
269 *planes
= core
->bcPlanes
;
270 *bpp
= core
->bcBitCount
;
275 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
))
277 *width
= header
->biWidth
;
278 *height
= header
->biHeight
;
279 *planes
= header
->biPlanes
;
280 *bpp
= header
->biBitCount
;
281 *compr
= header
->biCompression
;
282 *size
= header
->biSizeImage
;
285 ERR("(%d): unknown/wrong size for header\n", header
->biSize
);
290 /***********************************************************************
291 * X11DRV_DIB_GetColorCount
293 * Computes the number of colors for the bitmap palette.
294 * Should not be called for a >8-bit deep bitmap.
296 static unsigned int X11DRV_DIB_GetColorCount(const BITMAPINFO
*info
)
299 BOOL core_info
= info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
);
303 colors
= 1 << ((const BITMAPCOREINFO
*)info
)->bmciHeader
.bcBitCount
;
307 colors
= info
->bmiHeader
.biClrUsed
;
308 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
312 ERR("called with >256 colors!\n");
318 /***********************************************************************
321 * Get the info from a bitmap header.
322 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
324 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
325 LONG
*height
, WORD
*bpp
, WORD
*compr
)
330 return DIB_GetBitmapInfoEx( header
, width
, height
, &planes
, bpp
, compr
, &size
);
334 static inline BOOL
colour_is_brighter(RGBQUAD c1
, RGBQUAD c2
)
336 return (c1
.rgbRed
* c1
.rgbRed
+ c1
.rgbGreen
* c1
.rgbGreen
+ c1
.rgbBlue
* c1
.rgbBlue
) >
337 (c2
.rgbRed
* c2
.rgbRed
+ c2
.rgbGreen
* c2
.rgbGreen
+ c2
.rgbBlue
* c2
.rgbBlue
);
340 /***********************************************************************
341 * X11DRV_DIB_GenColorMap
343 * Fills the color map of a bitmap palette. Should not be called
344 * for a >8-bit deep bitmap.
346 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE
*physDev
, int *colorMapping
,
347 WORD coloruse
, WORD depth
, BOOL quads
,
348 const void *colorPtr
, int start
, int end
)
352 if (coloruse
== DIB_RGB_COLORS
)
356 const RGBQUAD
* rgb
= colorPtr
;
358 if (depth
== 1) /* Monochrome */
363 if (GetDIBColorTable( physDev
->hdc
, 0, 2, table
) == 2)
364 invert
= !colour_is_brighter(table
[1], table
[0]);
366 for (i
= start
; i
< end
; i
++, rgb
++)
367 colorMapping
[i
] = ((rgb
->rgbRed
+ rgb
->rgbGreen
+
368 rgb
->rgbBlue
> 255*3/2 && !invert
) ||
369 (rgb
->rgbRed
+ rgb
->rgbGreen
+
370 rgb
->rgbBlue
<= 255*3/2 && invert
));
373 for (i
= start
; i
< end
; i
++, rgb
++)
374 colorMapping
[i
] = X11DRV_PALETTE_LookupPixel(physDev
->color_shifts
, RGB(rgb
->rgbRed
,
380 const RGBTRIPLE
* rgb
= colorPtr
;
382 if (depth
== 1) /* Monochrome */
387 if (GetDIBColorTable( physDev
->hdc
, 0, 2, table
) == 2)
388 invert
= !colour_is_brighter(table
[1], table
[0]);
390 for (i
= start
; i
< end
; i
++, rgb
++)
391 colorMapping
[i
] = ((rgb
->rgbtRed
+ rgb
->rgbtGreen
+
392 rgb
->rgbtBlue
> 255*3/2 && !invert
) ||
393 (rgb
->rgbtRed
+ rgb
->rgbtGreen
+
394 rgb
->rgbtBlue
<= 255*3/2 && invert
));
397 for (i
= start
; i
< end
; i
++, rgb
++)
398 colorMapping
[i
] = X11DRV_PALETTE_LookupPixel(physDev
->color_shifts
, RGB(rgb
->rgbtRed
,
403 else /* DIB_PAL_COLORS */
405 const WORD
* index
= colorPtr
;
407 for (i
= start
; i
< end
; i
++, index
++)
408 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(*index
) );
414 /***********************************************************************
415 * X11DRV_DIB_BuildColorMap
417 * Build the color map from the bitmap palette. Should not be called
418 * for a >8-bit deep bitmap.
420 static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
421 const BITMAPINFO
*info
, int *nColors
)
424 const void *colorPtr
;
428 *nColors
= X11DRV_DIB_GetColorCount(info
);
429 if (!*nColors
) return NULL
;
431 isInfo
= info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
);
432 colorPtr
= (const BYTE
*)info
+ (WORD
)info
->bmiHeader
.biSize
;
433 if (!(colorMapping
= HeapAlloc(GetProcessHeap(), 0, *nColors
* sizeof(int) )))
436 return X11DRV_DIB_GenColorMap( physDev
, colorMapping
, coloruse
, depth
,
437 isInfo
, colorPtr
, 0, *nColors
);
440 /***********************************************************************
441 * X11DRV_DIB_MapColor
443 static int X11DRV_DIB_MapColor( int *physMap
, int nPhysMap
, int phys
, int oldcol
)
447 if ((oldcol
< nPhysMap
) && (physMap
[oldcol
] == phys
))
450 for (color
= 0; color
< nPhysMap
; color
++)
451 if (physMap
[color
] == phys
)
454 WARN("Strange color %08x\n", phys
);
459 /*********************************************************************
460 * X11DRV_DIB_GetNearestIndex
462 * Helper for X11DRV_DIB_GetDIBits.
463 * Returns the nearest colour table index for a given RGB.
464 * Nearest is defined by minimizing the sum of the squares.
466 static INT
X11DRV_DIB_GetNearestIndex(RGBQUAD
*colormap
, int numColors
, BYTE r
, BYTE g
, BYTE b
)
468 INT i
, best
= -1, diff
, bestdiff
= -1;
471 for(color
= colormap
, i
= 0; i
< numColors
; color
++, i
++) {
472 diff
= (r
- color
->rgbRed
) * (r
- color
->rgbRed
) +
473 (g
- color
->rgbGreen
) * (g
- color
->rgbGreen
) +
474 (b
- color
->rgbBlue
) * (b
- color
->rgbBlue
);
477 if(best
== -1 || diff
< bestdiff
) {
484 /*********************************************************************
485 * X11DRV_DIB_MaskToShift
487 * Helper for X11DRV_DIB_GetDIBits.
488 * Returns the by how many bits to shift a given color so that it is
489 * in the proper position.
491 INT
X11DRV_DIB_MaskToShift(DWORD mask
)
499 while ((mask
&1)==0) {
506 /***********************************************************************
507 * X11DRV_DIB_CheckMask
509 * Check RGB mask if it is either 0 or matches visual's mask.
511 static inline int X11DRV_DIB_CheckMask(int red_mask
, int green_mask
, int blue_mask
)
513 return ( red_mask
== 0 && green_mask
== 0 && blue_mask
== 0 ) ||
514 ( red_mask
== visual
->red_mask
&& green_mask
== visual
->green_mask
&&
515 blue_mask
== visual
->blue_mask
);
518 /***********************************************************************
519 * X11DRV_DIB_SetImageBits_1
521 * SetDIBits for a 1-bit deep DIB.
523 static void X11DRV_DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
524 DWORD srcwidth
, DWORD dstwidth
, int left
,
525 int *colors
, XImage
*bmpImage
, int linebytes
)
534 srcbits
= srcbits
+ linebytes
* (lines
- 1);
535 linebytes
= -linebytes
;
538 if ((extra
= (left
& 7)) != 0) {
542 srcbits
+= left
>> 3;
543 width
= min(srcwidth
, dstwidth
);
545 /* ==== pal 1 dib -> any bmp format ==== */
546 for (h
= lines
-1; h
>=0; h
--) {
548 for (i
= width
/8, x
= left
; i
> 0; i
--) {
550 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
551 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
552 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
553 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
554 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
555 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
556 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
557 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
563 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
564 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
565 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
566 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
567 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
568 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
569 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
572 srcbits
+= linebytes
;
576 /***********************************************************************
577 * X11DRV_DIB_GetImageBits_1
579 * GetDIBits for a 1-bit deep DIB.
581 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
582 DWORD dstwidth
, DWORD srcwidth
,
583 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
584 XImage
*bmpImage
, int linebytes
)
587 int h
, width
= min(dstwidth
, srcwidth
);
591 dstbits
= dstbits
+ linebytes
* (lines
- 1);
592 linebytes
= -linebytes
;
595 switch (bmpImage
->depth
)
599 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
601 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
604 for (h
=lines
-1; h
>=0; h
--) {
608 for (x
=0; x
<width
; x
++) {
610 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
611 dstval
|=(X11DRV_DIB_GetNearestIndex
615 srcval
.peBlue
) << (7 - (x
& 7)));
624 /* pad with 0 to DWORD alignment */
625 for (x
= (x
+7)&~7; x
< ((width
+ 31) & ~31); x
+=8)
627 dstbits
+= linebytes
;
635 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
, bmpImage
->green_mask
, bmpImage
->blue_mask
)
637 /* ==== pal 8 bmp -> pal 1 dib ==== */
639 const BYTE
* srcpixel
;
642 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
644 for (h
=0; h
<lines
; h
++) {
649 for (x
=0; x
<width
; x
++) {
651 srcval
=srccolors
[*srcpixel
++];
652 dstval
|=(X11DRV_DIB_GetNearestIndex
656 srcval
.peBlue
) << (7-(x
&7)) );
665 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
666 dstbits
+= linebytes
;
677 const WORD
* srcpixel
;
680 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
682 if (bmpImage
->green_mask
==0x03e0) {
683 if (bmpImage
->red_mask
==0x7c00) {
684 /* ==== rgb 555 bmp -> pal 1 dib ==== */
685 for (h
=0; h
<lines
; h
++) {
690 for (x
=0; x
<width
; x
++) {
693 dstval
|=(X11DRV_DIB_GetNearestIndex
695 ((srcval
>> 7) & 0xf8) | /* r */
696 ((srcval
>> 12) & 0x07),
697 ((srcval
>> 2) & 0xf8) | /* g */
698 ((srcval
>> 7) & 0x07),
699 ((srcval
<< 3) & 0xf8) | /* b */
700 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
709 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
710 dstbits
+= linebytes
;
712 } else if (bmpImage
->blue_mask
==0x7c00) {
713 /* ==== bgr 555 bmp -> pal 1 dib ==== */
714 for (h
=0; h
<lines
; h
++) {
719 for (x
=0; x
<width
; x
++) {
722 dstval
|=(X11DRV_DIB_GetNearestIndex
724 ((srcval
<< 3) & 0xf8) | /* r */
725 ((srcval
>> 2) & 0x07),
726 ((srcval
>> 2) & 0xf8) | /* g */
727 ((srcval
>> 7) & 0x07),
728 ((srcval
>> 7) & 0xf8) | /* b */
729 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
738 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
739 dstbits
+= linebytes
;
744 } else if (bmpImage
->green_mask
==0x07e0) {
745 if (bmpImage
->red_mask
==0xf800) {
746 /* ==== rgb 565 bmp -> pal 1 dib ==== */
747 for (h
=0; h
<lines
; h
++) {
752 for (x
=0; x
<width
; x
++) {
755 dstval
|=(X11DRV_DIB_GetNearestIndex
757 ((srcval
>> 8) & 0xf8) | /* r */
758 ((srcval
>> 13) & 0x07),
759 ((srcval
>> 3) & 0xfc) | /* g */
760 ((srcval
>> 9) & 0x03),
761 ((srcval
<< 3) & 0xf8) | /* b */
762 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
771 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
772 dstbits
+= linebytes
;
774 } else if (bmpImage
->blue_mask
==0xf800) {
775 /* ==== bgr 565 bmp -> pal 1 dib ==== */
776 for (h
=0; h
<lines
; h
++) {
781 for (x
=0; x
<width
; x
++) {
784 dstval
|=(X11DRV_DIB_GetNearestIndex
786 ((srcval
<< 3) & 0xf8) | /* r */
787 ((srcval
>> 2) & 0x07),
788 ((srcval
>> 3) & 0xfc) | /* g */
789 ((srcval
>> 9) & 0x03),
790 ((srcval
>> 8) & 0xf8) | /* b */
791 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
800 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
801 dstbits
+= linebytes
;
820 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
821 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
823 if (bmpImage
->green_mask
!=0x00ff00 ||
824 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
826 } else if (bmpImage
->blue_mask
==0xff) {
827 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
828 for (h
=0; h
<lines
; h
++) {
833 for (x
=0; x
<width
; x
++) {
834 dstval
|=(X11DRV_DIB_GetNearestIndex
838 srcbyte
[0]) << (7-(x
&7)) );
839 srcbyte
+=bytes_per_pixel
;
848 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
849 dstbits
+= linebytes
;
852 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
853 for (h
=0; h
<lines
; h
++) {
858 for (x
=0; x
<width
; x
++) {
859 dstval
|=(X11DRV_DIB_GetNearestIndex
863 srcbyte
[2]) << (7-(x
&7)) );
864 srcbyte
+=bytes_per_pixel
;
873 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
874 dstbits
+= linebytes
;
885 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
887 /* ==== any bmp format -> pal 1 dib ==== */
888 if ((unsigned)colors
[0].rgbRed
+colors
[0].rgbGreen
+colors
[0].rgbBlue
>=
889 (unsigned)colors
[1].rgbRed
+colors
[1].rgbGreen
+colors
[1].rgbBlue
)
892 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
893 "%s color mapping\n",
894 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
895 bmpImage
->green_mask
, bmpImage
->blue_mask
,
896 neg
?"negative":"direct" );
898 for (h
=lines
-1; h
>=0; h
--) {
902 for (x
=0; x
<width
; x
++) {
903 dstval
|=((XGetPixel( bmpImage
, x
, h
) >= white
) ^ neg
) << (7 - (x
&7));
912 dstbits
+= linebytes
;
919 /***********************************************************************
920 * X11DRV_DIB_SetImageBits_4
922 * SetDIBits for a 4-bit deep DIB.
924 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
925 DWORD srcwidth
, DWORD dstwidth
, int left
,
926 int *colors
, XImage
*bmpImage
, int linebytes
)
934 srcbits
= srcbits
+ linebytes
* (lines
- 1);
935 linebytes
= -linebytes
;
942 srcbits
+= left
>> 1;
943 width
= min(srcwidth
, dstwidth
);
945 /* ==== pal 4 dib -> any bmp format ==== */
946 for (h
= lines
-1; h
>= 0; h
--) {
948 for (i
= width
/2, x
= left
; i
> 0; i
--) {
949 BYTE srcval
=*srcbyte
++;
950 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
951 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
954 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
955 srcbits
+= linebytes
;
961 /***********************************************************************
962 * X11DRV_DIB_GetImageBits_4
964 * GetDIBits for a 4-bit deep DIB.
966 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
967 DWORD srcwidth
, DWORD dstwidth
,
968 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
969 XImage
*bmpImage
, int linebytes
)
972 int h
, width
= min(srcwidth
, dstwidth
);
977 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
978 linebytes
= -linebytes
;
981 switch (bmpImage
->depth
) {
984 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
986 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
989 for (h
= lines
-1; h
>= 0; h
--) {
993 for (x
= 0; x
< width
; x
++) {
995 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
996 dstval
|=(X11DRV_DIB_GetNearestIndex
1000 srcval
.peBlue
) << (4-((x
&1)<<2)));
1009 dstbits
+= linebytes
;
1017 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1019 /* ==== pal 8 bmp -> pal 4 dib ==== */
1020 const void* srcbits
;
1021 const BYTE
*srcpixel
;
1024 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1025 for (h
=0; h
<lines
; h
++) {
1030 for (x
=0; x
<width
; x
++) {
1031 PALETTEENTRY srcval
;
1032 srcval
= srccolors
[*srcpixel
++];
1033 dstval
|=(X11DRV_DIB_GetNearestIndex
1037 srcval
.peBlue
) << (4*(1-(x
&1))) );
1046 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1047 dstbits
+= linebytes
;
1057 const void* srcbits
;
1058 const WORD
* srcpixel
;
1061 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1063 if (bmpImage
->green_mask
==0x03e0) {
1064 if (bmpImage
->red_mask
==0x7c00) {
1065 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1066 for (h
=0; h
<lines
; h
++) {
1071 for (x
=0; x
<width
; x
++) {
1074 dstval
|=(X11DRV_DIB_GetNearestIndex
1076 ((srcval
>> 7) & 0xf8) | /* r */
1077 ((srcval
>> 12) & 0x07),
1078 ((srcval
>> 2) & 0xf8) | /* g */
1079 ((srcval
>> 7) & 0x07),
1080 ((srcval
<< 3) & 0xf8) | /* b */
1081 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1090 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1091 dstbits
+= linebytes
;
1093 } else if (bmpImage
->blue_mask
==0x7c00) {
1094 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1095 for (h
=0; h
<lines
; h
++) {
1100 for (x
=0; x
<width
; x
++) {
1103 dstval
|=(X11DRV_DIB_GetNearestIndex
1105 ((srcval
<< 3) & 0xf8) | /* r */
1106 ((srcval
>> 2) & 0x07),
1107 ((srcval
>> 2) & 0xf8) | /* g */
1108 ((srcval
>> 7) & 0x07),
1109 ((srcval
>> 7) & 0xf8) | /* b */
1110 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1119 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1120 dstbits
+= linebytes
;
1125 } else if (bmpImage
->green_mask
==0x07e0) {
1126 if (bmpImage
->red_mask
==0xf800) {
1127 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1128 for (h
=0; h
<lines
; h
++) {
1133 for (x
=0; x
<width
; x
++) {
1136 dstval
|=(X11DRV_DIB_GetNearestIndex
1138 ((srcval
>> 8) & 0xf8) | /* r */
1139 ((srcval
>> 13) & 0x07),
1140 ((srcval
>> 3) & 0xfc) | /* g */
1141 ((srcval
>> 9) & 0x03),
1142 ((srcval
<< 3) & 0xf8) | /* b */
1143 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1152 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1153 dstbits
+= linebytes
;
1155 } else if (bmpImage
->blue_mask
==0xf800) {
1156 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1157 for (h
=0; h
<lines
; h
++) {
1162 for (x
=0; x
<width
; x
++) {
1165 dstval
|=(X11DRV_DIB_GetNearestIndex
1167 ((srcval
<< 3) & 0xf8) | /* r */
1168 ((srcval
>> 2) & 0x07),
1169 ((srcval
>> 3) & 0xfc) | /* g */
1170 ((srcval
>> 9) & 0x03),
1171 ((srcval
>> 8) & 0xf8) | /* b */
1172 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1181 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1182 dstbits
+= linebytes
;
1194 if (bmpImage
->bits_per_pixel
==24) {
1195 const void* srcbits
;
1196 const BYTE
*srcbyte
;
1199 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1201 if (bmpImage
->green_mask
!=0x00ff00 ||
1202 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1204 } else if (bmpImage
->blue_mask
==0xff) {
1205 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1206 for (h
=0; h
<lines
; h
++) {
1209 for (x
=0; x
<width
/2; x
++) {
1210 /* Do 2 pixels at a time */
1211 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1216 X11DRV_DIB_GetNearestIndex
1224 /* And then the odd pixel */
1225 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1231 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1232 dstbits
+= linebytes
;
1235 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1236 for (h
=0; h
<lines
; h
++) {
1239 for (x
=0; x
<width
/2; x
++) {
1240 /* Do 2 pixels at a time */
1241 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1246 X11DRV_DIB_GetNearestIndex
1254 /* And then the odd pixel */
1255 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1261 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1262 dstbits
+= linebytes
;
1271 const void* srcbits
;
1272 const BYTE
*srcbyte
;
1275 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1277 if (bmpImage
->green_mask
!=0x00ff00 ||
1278 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1280 } else if (bmpImage
->blue_mask
==0xff) {
1281 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1282 for (h
=0; h
<lines
; h
++) {
1285 for (x
=0; x
<width
/2; x
++) {
1286 /* Do 2 pixels at a time */
1287 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1292 X11DRV_DIB_GetNearestIndex
1300 /* And then the odd pixel */
1301 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1307 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1308 dstbits
+= linebytes
;
1311 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1312 for (h
=0; h
<lines
; h
++) {
1315 for (x
=0; x
<width
/2; x
++) {
1316 /* Do 2 pixels at a time */
1317 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1322 X11DRV_DIB_GetNearestIndex
1330 /* And then the odd pixel */
1331 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1337 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1338 dstbits
+= linebytes
;
1349 /* ==== any bmp format -> pal 4 dib ==== */
1350 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1351 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1352 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1353 for (h
=lines
-1; h
>=0; h
--) {
1355 for (x
=0; x
<(width
& ~1); x
+=2) {
1356 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1357 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1360 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1362 dstbits
+= linebytes
;
1369 /***********************************************************************
1370 * X11DRV_DIB_SetImageBits_RLE4
1372 * SetDIBits for a 4-bit deep compressed DIB.
1374 static void X11DRV_DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
,
1375 DWORD srcwidth
, DWORD dstwidth
,
1376 int left
, int *colors
,
1379 unsigned int x
= 0, width
= min(srcwidth
, dstwidth
);
1380 int y
= lines
- 1, c
, length
;
1381 const BYTE
*begin
= bits
;
1386 if (length
) { /* encoded */
1389 if (x
>= (left
+ width
)) break;
1390 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1392 if (!length
--) break;
1393 if (x
>= (left
+ width
)) break;
1394 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1414 default: /* absolute */
1417 if (x
>= left
&& x
< (left
+ width
))
1418 XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1420 if (!length
--) break;
1421 if (x
>= left
&& x
< (left
+ width
))
1422 XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1425 if ((bits
- begin
) & 1)
1434 /***********************************************************************
1435 * X11DRV_DIB_SetImageBits_8
1437 * SetDIBits for an 8-bit deep DIB.
1439 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1440 DWORD srcwidth
, DWORD dstwidth
, int left
,
1441 const int *colors
, XImage
*bmpImage
,
1445 int h
, width
= min(srcwidth
, dstwidth
);
1446 const BYTE
* srcbyte
;
1452 srcbits
= srcbits
+ linebytes
* (lines
-1);
1453 linebytes
= -linebytes
;
1458 switch (bmpImage
->depth
) {
1461 /* Some X servers might have 32 bit/ 16bit deep pixel */
1462 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1463 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1465 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1466 dstbits
=(BYTE
*)bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1467 for (h
= lines
; h
--; ) {
1468 #if defined(__i386__) && defined(__GNUC__)
1469 int _cl1
,_cl2
; /* temp outputs for asm below */
1470 /* Borrowed from DirectDraw */
1471 __asm__
__volatile__(
1476 " movw (%%edx,%%eax,4),%%ax\n"
1478 " xor %%eax,%%eax\n"
1480 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1485 :"eax", "cc", "memory"
1488 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1489 for (x
=0; x
<width
/2; x
++) {
1490 /* Do 2 pixels at a time */
1491 *dstpixel
++=(colors
[srcbyte
[1]] << 16) | colors
[srcbyte
[0]];
1495 /* And then the odd pixel */
1496 *((WORD
*)dstpixel
)=colors
[srcbyte
[0]];
1499 srcbyte
= (srcbits
+= linebytes
);
1500 dstbits
-= bmpImage
->bytes_per_line
;
1507 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1508 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1510 dstbits
=(BYTE
*)bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1511 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1512 for (h
= lines
; h
--; ) {
1513 #if defined(__i386__) && defined(__GNUC__)
1514 int _cl1
,_cl2
; /* temp outputs for asm below */
1515 /* Borrowed from DirectDraw */
1516 __asm__
__volatile__(
1521 " movl (%%edx,%%eax,4),%%eax\n"
1523 " xor %%eax,%%eax\n"
1525 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1530 :"eax", "cc", "memory"
1533 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1534 for (x
=0; x
<width
; x
++) {
1535 *dstpixel
++=colors
[*srcbyte
++];
1538 srcbyte
= (srcbits
+= linebytes
);
1539 dstbits
-= bmpImage
->bytes_per_line
;
1545 break; /* use slow generic case below */
1548 /* ==== pal 8 dib -> any bmp format ==== */
1549 for (h
=lines
-1; h
>=0; h
--) {
1550 for (x
=left
; x
<width
+left
; x
++) {
1551 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1553 srcbyte
= (srcbits
+= linebytes
);
1557 /***********************************************************************
1558 * X11DRV_DIB_GetImageBits_8
1560 * GetDIBits for an 8-bit deep DIB.
1562 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1563 DWORD srcwidth
, DWORD dstwidth
,
1564 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1565 XImage
*bmpImage
, int linebytes
)
1568 int h
, width
= min(srcwidth
, dstwidth
);
1574 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1575 linebytes
= -linebytes
;
1580 * This condition is true when GetImageBits has been called by
1581 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1582 * 256 colormaps, so we'll just use it for GetDIBits calls.
1583 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1585 if (!srccolors
) goto updatesection
;
1587 switch (bmpImage
->depth
) {
1590 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1593 /* ==== pal 1 bmp -> pal 8 dib ==== */
1594 /* ==== pal 4 bmp -> pal 8 dib ==== */
1595 for (h
=lines
-1; h
>=0; h
--) {
1597 for (x
=0; x
<width
; x
++) {
1598 PALETTEENTRY srcval
;
1599 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1600 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1605 dstbits
+= linebytes
;
1613 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1615 /* ==== pal 8 bmp -> pal 8 dib ==== */
1616 const void* srcbits
;
1617 const BYTE
* srcpixel
;
1619 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1620 for (h
=0; h
<lines
; h
++) {
1623 for (x
= 0; x
< width
; x
++) {
1624 PALETTEENTRY srcval
;
1625 srcval
=srccolors
[*srcpixel
++];
1626 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1631 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1632 dstbits
+= linebytes
;
1642 const void* srcbits
;
1643 const WORD
* srcpixel
;
1646 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1648 if (bmpImage
->green_mask
==0x03e0) {
1649 if (bmpImage
->red_mask
==0x7c00) {
1650 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1651 for (h
=0; h
<lines
; h
++) {
1654 for (x
=0; x
<width
; x
++) {
1657 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1659 ((srcval
>> 7) & 0xf8) | /* r */
1660 ((srcval
>> 12) & 0x07),
1661 ((srcval
>> 2) & 0xf8) | /* g */
1662 ((srcval
>> 7) & 0x07),
1663 ((srcval
<< 3) & 0xf8) | /* b */
1664 ((srcval
>> 2) & 0x07) );
1666 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1667 dstbits
+= linebytes
;
1669 } else if (bmpImage
->blue_mask
==0x7c00) {
1670 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1671 for (h
=0; h
<lines
; h
++) {
1674 for (x
=0; x
<width
; x
++) {
1677 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1679 ((srcval
<< 3) & 0xf8) | /* r */
1680 ((srcval
>> 2) & 0x07),
1681 ((srcval
>> 2) & 0xf8) | /* g */
1682 ((srcval
>> 7) & 0x07),
1683 ((srcval
>> 7) & 0xf8) | /* b */
1684 ((srcval
>> 12) & 0x07) );
1686 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1687 dstbits
+= linebytes
;
1692 } else if (bmpImage
->green_mask
==0x07e0) {
1693 if (bmpImage
->red_mask
==0xf800) {
1694 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1695 for (h
=0; h
<lines
; h
++) {
1698 for (x
=0; x
<width
; x
++) {
1701 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1703 ((srcval
>> 8) & 0xf8) | /* r */
1704 ((srcval
>> 13) & 0x07),
1705 ((srcval
>> 3) & 0xfc) | /* g */
1706 ((srcval
>> 9) & 0x03),
1707 ((srcval
<< 3) & 0xf8) | /* b */
1708 ((srcval
>> 2) & 0x07) );
1710 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1711 dstbits
+= linebytes
;
1713 } else if (bmpImage
->blue_mask
==0xf800) {
1714 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1715 for (h
=0; h
<lines
; h
++) {
1718 for (x
=0; x
<width
; x
++) {
1721 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1723 ((srcval
<< 3) & 0xf8) | /* r */
1724 ((srcval
>> 2) & 0x07),
1725 ((srcval
>> 3) & 0xfc) | /* g */
1726 ((srcval
>> 9) & 0x03),
1727 ((srcval
>> 8) & 0xf8) | /* b */
1728 ((srcval
>> 13) & 0x07) );
1730 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1731 dstbits
+= linebytes
;
1745 const void* srcbits
;
1746 const BYTE
*srcbyte
;
1748 int bytes_per_pixel
;
1750 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1751 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1753 if (bmpImage
->green_mask
!=0x00ff00 ||
1754 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1756 } else if (bmpImage
->blue_mask
==0xff) {
1757 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1758 for (h
=0; h
<lines
; h
++) {
1761 for (x
=0; x
<width
; x
++) {
1762 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1767 srcbyte
+=bytes_per_pixel
;
1769 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1770 dstbits
+= linebytes
;
1773 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1774 for (h
=0; h
<lines
; h
++) {
1777 for (x
=0; x
<width
; x
++) {
1778 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1783 srcbyte
+=bytes_per_pixel
;
1785 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1786 dstbits
+= linebytes
;
1794 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1795 bmpImage
->depth
, bmpImage
->red_mask
,
1796 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1798 /* ==== any bmp format -> pal 8 dib ==== */
1799 for (h
=lines
-1; h
>=0; h
--) {
1801 for (x
=0; x
<width
; x
++) {
1802 *dstbyte
=X11DRV_DIB_MapColor
1804 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1807 dstbits
+= linebytes
;
1813 /***********************************************************************
1814 * X11DRV_DIB_SetImageBits_RLE8
1816 * SetDIBits for an 8-bit deep compressed DIB.
1818 * This function rewritten 941113 by James Youngman. WINE blew out when I
1819 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1821 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1822 * 'End of bitmap' escape code. This code is very much laxer in what it
1823 * allows to end the expansion. Possibly too lax. See the note by
1824 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1825 * bitmap should end with RleEnd, but on the other hand, software exists
1826 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1829 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1830 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1833 static void X11DRV_DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
,
1834 DWORD srcwidth
, DWORD dstwidth
,
1835 int left
, int *colors
,
1838 unsigned int x
; /* X-position on each line. Increases. */
1839 int y
; /* Line #. Starts at lines-1, decreases */
1840 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
1841 BYTE length
; /* The length pf a run */
1842 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
1845 * Note that the bitmap data is stored by Windows starting at the
1846 * bottom line of the bitmap and going upwards. Within each line,
1847 * the data is stored left-to-right. That's the reason why line
1848 * goes from lines-1 to 0. [JAY]
1858 * If the length byte is not zero (which is the escape value),
1859 * We have a run of length pixels all the same colour. The colour
1860 * index is stored next.
1862 * If the length byte is zero, we need to read the next byte to
1863 * know what to do. [JAY]
1868 * [Run-Length] Encoded mode
1870 int color
= colors
[*pIn
++];
1871 while (length
-- && x
< (left
+ dstwidth
)) {
1872 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1879 * Escape codes (may be an absolute sequence though)
1881 escape_code
= (*pIn
++);
1890 /* Not all RLE8 bitmaps end with this code. For
1891 * example, Paint Shop Pro produces some that don't.
1892 * That's (I think) what caused the previous
1893 * implementation to fail. [JAY]
1902 default: /* switch to absolute mode */
1903 length
= escape_code
;
1906 int color
= colors
[*pIn
++];
1907 if (x
>= (left
+ dstwidth
))
1912 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1916 * If you think for a moment you'll realise that the
1917 * only time we could ever possibly read an odd
1918 * number of bytes is when there is a 0x00 (escape),
1919 * a value >0x02 (absolute mode) and then an odd-
1920 * length run. Therefore this is the only place we
1921 * need to worry about it. Everywhere else the
1922 * bytes are always read in pairs. [JAY]
1924 if (escape_code
& 1) pIn
++; /* Throw away the pad byte. */
1926 } /* switch (escape_code) : Escape sequence */
1932 /***********************************************************************
1933 * X11DRV_DIB_SetImageBits_16
1935 * SetDIBits for a 16-bit deep DIB.
1937 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1938 DWORD srcwidth
, DWORD dstwidth
, int left
,
1939 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1940 XImage
*bmpImage
, int linebytes
)
1943 int h
, width
= min(srcwidth
, dstwidth
);
1944 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1949 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1950 linebytes
= -linebytes
;
1953 switch (bmpImage
->depth
)
1960 srcbits
=srcbits
+left
*2;
1961 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1963 if (bmpImage
->green_mask
==0x03e0) {
1964 if (gSrc
==bmpImage
->green_mask
) {
1965 if (rSrc
==bmpImage
->red_mask
) {
1966 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1967 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1968 convs
->Convert_5x5_asis
1971 dstbits
,-bmpImage
->bytes_per_line
);
1972 } else if (rSrc
==bmpImage
->blue_mask
) {
1973 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1974 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1975 convs
->Convert_555_reverse
1978 dstbits
,-bmpImage
->bytes_per_line
);
1981 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1982 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1983 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1984 convs
->Convert_565_to_555_asis
1987 dstbits
,-bmpImage
->bytes_per_line
);
1989 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1990 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1991 convs
->Convert_565_to_555_reverse
1994 dstbits
,-bmpImage
->bytes_per_line
);
1997 } else if (bmpImage
->green_mask
==0x07e0) {
1998 if (gSrc
==bmpImage
->green_mask
) {
1999 if (rSrc
==bmpImage
->red_mask
) {
2000 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
2001 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
2002 convs
->Convert_5x5_asis
2005 dstbits
,-bmpImage
->bytes_per_line
);
2007 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
2008 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
2009 convs
->Convert_565_reverse
2012 dstbits
,-bmpImage
->bytes_per_line
);
2015 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
2016 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
2017 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
2018 convs
->Convert_555_to_565_asis
2021 dstbits
,-bmpImage
->bytes_per_line
);
2023 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
2024 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
2025 convs
->Convert_555_to_565_reverse
2028 dstbits
,-bmpImage
->bytes_per_line
);
2038 if (bmpImage
->bits_per_pixel
==24) {
2041 srcbits
=srcbits
+left
*2;
2042 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2044 if (bmpImage
->green_mask
!=0x00ff00 ||
2045 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2047 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2048 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2050 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2051 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2052 convs
->Convert_555_to_888_asis
2055 dstbits
,-bmpImage
->bytes_per_line
);
2057 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2058 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2059 convs
->Convert_565_to_888_asis
2062 dstbits
,-bmpImage
->bytes_per_line
);
2066 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2067 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2068 convs
->Convert_555_to_888_reverse
2071 dstbits
,-bmpImage
->bytes_per_line
);
2073 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2074 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2075 convs
->Convert_565_to_888_reverse
2078 dstbits
,-bmpImage
->bytes_per_line
);
2089 srcbits
=srcbits
+left
*2;
2090 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2092 if (bmpImage
->green_mask
!=0x00ff00 ||
2093 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2095 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2096 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2098 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2099 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2100 convs
->Convert_555_to_0888_asis
2103 dstbits
,-bmpImage
->bytes_per_line
);
2105 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2106 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2107 convs
->Convert_565_to_0888_asis
2110 dstbits
,-bmpImage
->bytes_per_line
);
2114 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2115 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2116 convs
->Convert_555_to_0888_reverse
2119 dstbits
,-bmpImage
->bytes_per_line
);
2121 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2122 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2123 convs
->Convert_565_to_0888_reverse
2126 dstbits
,-bmpImage
->bytes_per_line
);
2134 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2135 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2136 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2142 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2143 const WORD
* srcpixel
;
2144 int rShift1
,gShift1
,bShift1
;
2145 int rShift2
,gShift2
,bShift2
;
2148 /* Set color scaling values */
2149 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
2150 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
2151 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
2156 /* Green has 5 bits, like the others */
2160 /* Green has 6 bits, not 5. Compensate. */
2169 /* We could split it into four separate cases to optimize
2170 * but it is probably not worth it.
2172 for (h
=lines
-1; h
>=0; h
--) {
2173 srcpixel
=(const WORD
*)srcbits
;
2174 for (x
=left
; x
<width
+left
; x
++) {
2176 BYTE red
,green
,blue
;
2177 srcval
=*srcpixel
++ << 16;
2178 red
= ((srcval
>> rShift1
) & 0xf8) |
2179 ((srcval
>> rShift2
) & 0x07);
2180 green
=((srcval
>> gShift1
) & gMask1
) |
2181 ((srcval
>> gShift2
) & gMask2
);
2182 blue
= ((srcval
>> bShift1
) & 0xf8) |
2183 ((srcval
>> bShift2
) & 0x07);
2184 XPutPixel(bmpImage
, x
, h
,
2185 X11DRV_PALETTE_ToPhysical
2186 (physDev
, RGB(red
,green
,blue
)));
2188 srcbits
+= linebytes
;
2196 /***********************************************************************
2197 * X11DRV_DIB_GetImageBits_16
2199 * GetDIBits for an 16-bit deep DIB.
2201 static void X11DRV_DIB_GetImageBits_16( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
2202 DWORD dstwidth
, DWORD srcwidth
,
2203 PALETTEENTRY
*srccolors
,
2204 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2205 XImage
*bmpImage
, int linebytes
)
2208 int h
, width
= min(srcwidth
, dstwidth
);
2209 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2214 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
2215 linebytes
= -linebytes
;
2218 switch (bmpImage
->depth
)
2223 const char* srcbits
;
2225 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2227 if (bmpImage
->green_mask
==0x03e0) {
2228 if (gDst
==bmpImage
->green_mask
) {
2229 if (rDst
==bmpImage
->red_mask
) {
2230 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2231 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2232 convs
->Convert_5x5_asis
2234 srcbits
,-bmpImage
->bytes_per_line
,
2237 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2238 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2239 convs
->Convert_555_reverse
2241 srcbits
,-bmpImage
->bytes_per_line
,
2245 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2246 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2247 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2248 convs
->Convert_555_to_565_asis
2250 srcbits
,-bmpImage
->bytes_per_line
,
2253 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2254 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2255 convs
->Convert_555_to_565_reverse
2257 srcbits
,-bmpImage
->bytes_per_line
,
2261 } else if (bmpImage
->green_mask
==0x07e0) {
2262 if (gDst
==bmpImage
->green_mask
) {
2263 if (rDst
== bmpImage
->red_mask
) {
2264 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2265 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2266 convs
->Convert_5x5_asis
2268 srcbits
,-bmpImage
->bytes_per_line
,
2271 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2272 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2273 convs
->Convert_565_reverse
2275 srcbits
,-bmpImage
->bytes_per_line
,
2279 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2280 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2281 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2282 convs
->Convert_565_to_555_asis
2284 srcbits
,-bmpImage
->bytes_per_line
,
2287 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2288 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2289 convs
->Convert_565_to_555_reverse
2291 srcbits
,-bmpImage
->bytes_per_line
,
2302 if (bmpImage
->bits_per_pixel
== 24) {
2303 const char* srcbits
;
2305 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2307 if (bmpImage
->green_mask
!=0x00ff00 ||
2308 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2310 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2311 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2313 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2314 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2315 convs
->Convert_888_to_555_asis
2317 srcbits
,-bmpImage
->bytes_per_line
,
2320 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2321 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2322 convs
->Convert_888_to_565_asis
2324 srcbits
,-bmpImage
->bytes_per_line
,
2329 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2330 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2331 convs
->Convert_888_to_555_reverse
2333 srcbits
,-bmpImage
->bytes_per_line
,
2336 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2337 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2338 convs
->Convert_888_to_565_reverse
2340 srcbits
,-bmpImage
->bytes_per_line
,
2350 const char* srcbits
;
2352 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2354 if (bmpImage
->green_mask
!=0x00ff00 ||
2355 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2357 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2358 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2360 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2361 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2362 convs
->Convert_0888_to_555_asis
2364 srcbits
,-bmpImage
->bytes_per_line
,
2367 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2368 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2369 convs
->Convert_0888_to_565_asis
2371 srcbits
,-bmpImage
->bytes_per_line
,
2376 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2377 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2378 convs
->Convert_0888_to_555_reverse
2380 srcbits
,-bmpImage
->bytes_per_line
,
2383 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2384 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2385 convs
->Convert_0888_to_565_reverse
2387 srcbits
,-bmpImage
->bytes_per_line
,
2396 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2398 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2399 int rShift
,gShift
,bShift
;
2402 /* Shift everything 16 bits left so that all shifts are >0,
2403 * even for BGR DIBs. Then a single >> 16 will bring everything
2406 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2407 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2408 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2410 /* 6 bits for the green */
2416 for (h
= lines
- 1; h
>= 0; h
--) {
2417 dstpixel
=(LPWORD
)dstbits
;
2418 for (x
= 0; x
< width
; x
++) {
2419 PALETTEENTRY srcval
;
2421 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2422 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2423 ((srcval
.peGreen
<< gShift
) & gDst
) |
2424 ((srcval
.peBlue
<< bShift
) & bDst
);
2425 *dstpixel
++=dstval
>> 16;
2427 dstbits
+= linebytes
;
2435 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2437 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2438 int rShift
,gShift
,bShift
;
2439 const BYTE
* srcbits
;
2440 const BYTE
* srcpixel
;
2443 /* Shift everything 16 bits left so that all shifts are >0,
2444 * even for BGR DIBs. Then a single >> 16 will bring everything
2447 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2448 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2449 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2451 /* 6 bits for the green */
2457 srcbits
=(BYTE
*)bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2458 for (h
=0; h
<lines
; h
++) {
2460 dstpixel
=(LPWORD
)dstbits
;
2461 for (x
= 0; x
< width
; x
++) {
2462 PALETTEENTRY srcval
;
2464 srcval
=srccolors
[*srcpixel
++];
2465 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2466 ((srcval
.peGreen
<< gShift
) & gDst
) |
2467 ((srcval
.peBlue
<< bShift
) & bDst
);
2468 *dstpixel
++=dstval
>> 16;
2470 srcbits
-= bmpImage
->bytes_per_line
;
2471 dstbits
+= linebytes
;
2481 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2482 int rShift
,gShift
,bShift
;
2485 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2486 bmpImage
->depth
, bmpImage
->red_mask
,
2487 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2490 /* Shift everything 16 bits left so that all shifts are >0,
2491 * even for BGR DIBs. Then a single >> 16 will bring everything
2494 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2495 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2496 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2498 /* 6 bits for the green */
2504 for (h
= lines
- 1; h
>= 0; h
--) {
2505 dstpixel
=(LPWORD
)dstbits
;
2506 for (x
= 0; x
< width
; x
++) {
2509 srcval
=X11DRV_PALETTE_ToLogical(physDev
, XGetPixel(bmpImage
, x
, h
));
2510 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2511 ((GetGValue(srcval
) << gShift
) & gDst
) |
2512 ((GetBValue(srcval
) << bShift
) & bDst
);
2513 *dstpixel
++=dstval
>> 16;
2515 dstbits
+= linebytes
;
2523 /***********************************************************************
2524 * X11DRV_DIB_SetImageBits_24
2526 * SetDIBits for a 24-bit deep DIB.
2528 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2529 DWORD srcwidth
, DWORD dstwidth
, int left
,
2530 X11DRV_PDEVICE
*physDev
,
2531 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2532 XImage
*bmpImage
, DWORD linebytes
)
2535 int h
, width
= min(srcwidth
, dstwidth
);
2536 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2541 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2542 linebytes
= -linebytes
;
2545 switch (bmpImage
->depth
)
2548 if (bmpImage
->bits_per_pixel
==24) {
2551 srcbits
=srcbits
+left
*3;
2552 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2554 if (bmpImage
->green_mask
!=0x00ff00 ||
2555 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2557 } else if (rSrc
==bmpImage
->red_mask
) {
2558 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2559 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2560 convs
->Convert_888_asis
2563 dstbits
,-bmpImage
->bytes_per_line
);
2565 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2566 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2567 convs
->Convert_888_reverse
2570 dstbits
,-bmpImage
->bytes_per_line
);
2580 srcbits
=srcbits
+left
*3;
2581 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2583 if (bmpImage
->green_mask
!=0x00ff00 ||
2584 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2586 } else if (rSrc
==bmpImage
->red_mask
) {
2587 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2588 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2589 convs
->Convert_888_to_0888_asis
2592 dstbits
,-bmpImage
->bytes_per_line
);
2594 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2595 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2596 convs
->Convert_888_to_0888_reverse
2599 dstbits
,-bmpImage
->bytes_per_line
);
2609 srcbits
=srcbits
+left
*3;
2610 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2612 if (bmpImage
->green_mask
==0x03e0) {
2613 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2614 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2615 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2616 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2617 convs
->Convert_888_to_555_asis
2620 dstbits
,-bmpImage
->bytes_per_line
);
2621 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2622 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2623 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2624 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2625 convs
->Convert_888_to_555_reverse
2628 dstbits
,-bmpImage
->bytes_per_line
);
2632 } else if (bmpImage
->green_mask
==0x07e0) {
2633 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2634 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2635 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2636 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2637 convs
->Convert_888_to_565_asis
2640 dstbits
,-bmpImage
->bytes_per_line
);
2641 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2642 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2643 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2644 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2645 convs
->Convert_888_to_565_reverse
2648 dstbits
,-bmpImage
->bytes_per_line
);
2660 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2661 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2662 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2668 /* ==== rgb 888 dib -> any bmp format ==== */
2669 const BYTE
* srcbyte
;
2671 /* Windows only supports one 24bpp DIB format: RGB888 */
2673 for (h
= lines
- 1; h
>= 0; h
--) {
2675 for (x
= left
; x
< width
+left
; x
++) {
2676 XPutPixel(bmpImage
, x
, h
,
2677 X11DRV_PALETTE_ToPhysical
2678 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2681 srcbits
+= linebytes
;
2689 /***********************************************************************
2690 * X11DRV_DIB_GetImageBits_24
2692 * GetDIBits for an 24-bit deep DIB.
2694 static void X11DRV_DIB_GetImageBits_24( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
2695 DWORD dstwidth
, DWORD srcwidth
,
2696 PALETTEENTRY
*srccolors
,
2697 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2698 XImage
*bmpImage
, DWORD linebytes
)
2701 int h
, width
= min(srcwidth
, dstwidth
);
2702 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2707 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2708 linebytes
= -linebytes
;
2711 switch (bmpImage
->depth
)
2714 if (bmpImage
->bits_per_pixel
==24) {
2715 const char* srcbits
;
2717 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2719 if (bmpImage
->green_mask
!=0x00ff00 ||
2720 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2722 } else if (rDst
==bmpImage
->red_mask
) {
2723 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2724 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2725 convs
->Convert_888_asis
2727 srcbits
,-bmpImage
->bytes_per_line
,
2730 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2731 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2732 convs
->Convert_888_reverse
2734 srcbits
,-bmpImage
->bytes_per_line
,
2743 const char* srcbits
;
2745 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2747 if (bmpImage
->green_mask
!=0x00ff00 ||
2748 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2750 } else if (rDst
==bmpImage
->red_mask
) {
2751 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2752 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2753 convs
->Convert_0888_to_888_asis
2755 srcbits
,-bmpImage
->bytes_per_line
,
2758 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2759 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2760 convs
->Convert_0888_to_888_reverse
2762 srcbits
,-bmpImage
->bytes_per_line
,
2771 const char* srcbits
;
2773 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2775 if (bmpImage
->green_mask
==0x03e0) {
2776 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2777 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2778 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2779 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2780 convs
->Convert_555_to_888_asis
2782 srcbits
,-bmpImage
->bytes_per_line
,
2784 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2785 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2786 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2787 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2788 convs
->Convert_555_to_888_reverse
2790 srcbits
,-bmpImage
->bytes_per_line
,
2795 } else if (bmpImage
->green_mask
==0x07e0) {
2796 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2797 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2798 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2799 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2800 convs
->Convert_565_to_888_asis
2802 srcbits
,-bmpImage
->bytes_per_line
,
2804 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2805 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2806 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2807 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2808 convs
->Convert_565_to_888_reverse
2810 srcbits
,-bmpImage
->bytes_per_line
,
2823 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2825 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2828 /* Windows only supports one 24bpp DIB format: rgb 888 */
2829 for (h
= lines
- 1; h
>= 0; h
--) {
2831 for (x
= 0; x
< width
; x
++) {
2832 PALETTEENTRY srcval
;
2833 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2834 dstbyte
[0]=srcval
.peBlue
;
2835 dstbyte
[1]=srcval
.peGreen
;
2836 dstbyte
[2]=srcval
.peRed
;
2839 dstbits
+= linebytes
;
2847 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2849 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2850 const void* srcbits
;
2851 const BYTE
* srcpixel
;
2854 /* Windows only supports one 24bpp DIB format: rgb 888 */
2855 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2856 for (h
= lines
- 1; h
>= 0; h
--) {
2859 for (x
= 0; x
< width
; x
++ ) {
2860 PALETTEENTRY srcval
;
2861 srcval
=srccolors
[*srcpixel
++];
2862 dstbyte
[0]=srcval
.peBlue
;
2863 dstbyte
[1]=srcval
.peGreen
;
2864 dstbyte
[2]=srcval
.peRed
;
2867 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2868 dstbits
+= linebytes
;
2878 /* ==== any bmp format -> 888 dib ==== */
2881 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2882 bmpImage
->depth
, bmpImage
->red_mask
,
2883 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2886 /* Windows only supports one 24bpp DIB format: rgb 888 */
2887 for (h
= lines
- 1; h
>= 0; h
--) {
2889 for (x
= 0; x
< width
; x
++) {
2890 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2891 (physDev
, XGetPixel( bmpImage
, x
, h
));
2892 dstbyte
[0]=GetBValue(srcval
);
2893 dstbyte
[1]=GetGValue(srcval
);
2894 dstbyte
[2]=GetRValue(srcval
);
2897 dstbits
+= linebytes
;
2905 /***********************************************************************
2906 * X11DRV_DIB_SetImageBits_32
2908 * SetDIBits for a 32-bit deep DIB.
2910 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2911 DWORD srcwidth
, DWORD dstwidth
, int left
,
2912 X11DRV_PDEVICE
*physDev
,
2913 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2918 int h
, width
= min(srcwidth
, dstwidth
);
2919 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2924 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2925 linebytes
= -linebytes
;
2928 switch (bmpImage
->depth
)
2931 if (bmpImage
->bits_per_pixel
==24) {
2934 srcbits
=srcbits
+left
*4;
2935 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2937 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2938 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2939 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2940 convs
->Convert_0888_to_888_asis
2943 dstbits
,-bmpImage
->bytes_per_line
);
2944 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2945 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2947 /* the tests below assume sane bmpImage masks */
2948 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2949 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2950 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2951 convs
->Convert_0888_to_888_reverse
2954 dstbits
,-bmpImage
->bytes_per_line
);
2955 } else if (bmpImage
->blue_mask
==0xff) {
2956 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2957 convs
->Convert_any0888_to_rgb888
2961 dstbits
,-bmpImage
->bytes_per_line
);
2963 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2964 convs
->Convert_any0888_to_bgr888
2968 dstbits
,-bmpImage
->bytes_per_line
);
2978 srcbits
=srcbits
+left
*4;
2979 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2981 if (gSrc
==bmpImage
->green_mask
) {
2982 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2983 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2984 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2985 convs
->Convert_0888_asis
2988 dstbits
,-bmpImage
->bytes_per_line
);
2989 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2990 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2992 /* the tests below assume sane bmpImage masks */
2993 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
2994 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2995 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2996 convs
->Convert_0888_reverse
2999 dstbits
,-bmpImage
->bytes_per_line
);
3001 /* ==== any 0888 dib -> any 0888 bmp ==== */
3002 convs
->Convert_0888_any
3006 dstbits
,-bmpImage
->bytes_per_line
,
3007 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3009 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3010 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3012 /* the tests below assume sane bmpImage masks */
3014 /* ==== any 0888 dib -> any 0888 bmp ==== */
3015 convs
->Convert_0888_any
3019 dstbits
,-bmpImage
->bytes_per_line
,
3020 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3030 srcbits
=srcbits
+left
*4;
3031 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
3033 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
3034 if (bmpImage
->green_mask
==0x03e0) {
3035 if (bmpImage
->red_mask
==0x7f00) {
3036 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
3037 convs
->Convert_0888_to_555_asis
3040 dstbits
,-bmpImage
->bytes_per_line
);
3041 } else if (bmpImage
->blue_mask
==0x7f00) {
3042 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
3043 convs
->Convert_0888_to_555_reverse
3046 dstbits
,-bmpImage
->bytes_per_line
);
3050 } else if (bmpImage
->green_mask
==0x07e0) {
3051 if (bmpImage
->red_mask
==0xf800) {
3052 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3053 convs
->Convert_0888_to_565_asis
3056 dstbits
,-bmpImage
->bytes_per_line
);
3057 } else if (bmpImage
->blue_mask
==0xf800) {
3058 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3059 convs
->Convert_0888_to_565_reverse
3062 dstbits
,-bmpImage
->bytes_per_line
);
3069 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
3070 if (bmpImage
->green_mask
==0x03e0) {
3071 if (bmpImage
->blue_mask
==0x7f00) {
3072 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3073 convs
->Convert_0888_to_555_asis
3076 dstbits
,-bmpImage
->bytes_per_line
);
3077 } else if (bmpImage
->red_mask
==0x7f00) {
3078 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3079 convs
->Convert_0888_to_555_reverse
3082 dstbits
,-bmpImage
->bytes_per_line
);
3086 } else if (bmpImage
->green_mask
==0x07e0) {
3087 if (bmpImage
->blue_mask
==0xf800) {
3088 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3089 convs
->Convert_0888_to_565_asis
3092 dstbits
,-bmpImage
->bytes_per_line
);
3093 } else if (bmpImage
->red_mask
==0xf800) {
3094 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3095 convs
->Convert_0888_to_565_reverse
3098 dstbits
,-bmpImage
->bytes_per_line
);
3106 if (bmpImage
->green_mask
==0x03e0 &&
3107 (bmpImage
->red_mask
==0x7f00 ||
3108 bmpImage
->blue_mask
==0x7f00)) {
3109 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3110 convs
->Convert_any0888_to_5x5
3114 dstbits
,-bmpImage
->bytes_per_line
,
3115 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3116 } else if (bmpImage
->green_mask
==0x07e0 &&
3117 (bmpImage
->red_mask
==0xf800 ||
3118 bmpImage
->blue_mask
==0xf800)) {
3119 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3120 convs
->Convert_any0888_to_5x5
3124 dstbits
,-bmpImage
->bytes_per_line
,
3125 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3135 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3136 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
3137 bmpImage
->green_mask
, bmpImage
->blue_mask
);
3143 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3144 const DWORD
* srcpixel
;
3145 int rShift
,gShift
,bShift
;
3147 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
3148 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
3149 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
3151 for (h
= lines
- 1; h
>= 0; h
--) {
3152 srcpixel
=(const DWORD
*)srcbits
;
3153 for (x
= left
; x
< width
+left
; x
++) {
3155 BYTE red
,green
,blue
;
3156 srcvalue
=*srcpixel
++;
3157 red
= (srcvalue
>> rShift
) & 0xff;
3158 green
=(srcvalue
>> gShift
) & 0xff;
3159 blue
= (srcvalue
>> bShift
) & 0xff;
3160 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
3161 (physDev
, RGB(red
,green
,blue
)));
3163 srcbits
+= linebytes
;
3171 /***********************************************************************
3172 * X11DRV_DIB_GetImageBits_32
3174 * GetDIBits for an 32-bit deep DIB.
3176 static void X11DRV_DIB_GetImageBits_32( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
3177 DWORD dstwidth
, DWORD srcwidth
,
3178 PALETTEENTRY
*srccolors
,
3179 DWORD rDst
, DWORD gDst
, DWORD bDst
,
3180 XImage
*bmpImage
, int linebytes
)
3183 int h
, width
= min(srcwidth
, dstwidth
);
3184 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
3189 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
3190 linebytes
= -linebytes
;
3193 switch (bmpImage
->depth
)
3196 if (bmpImage
->bits_per_pixel
==24) {
3197 const void* srcbits
;
3199 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3201 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
3202 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3203 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3204 convs
->Convert_888_to_0888_asis
3206 srcbits
,-bmpImage
->bytes_per_line
,
3208 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3209 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3211 /* the tests below assume sane bmpImage masks */
3212 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
3213 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3214 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3215 convs
->Convert_888_to_0888_reverse
3217 srcbits
,-bmpImage
->bytes_per_line
,
3219 } else if (bmpImage
->blue_mask
==0xff) {
3220 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3221 convs
->Convert_rgb888_to_any0888
3223 srcbits
,-bmpImage
->bytes_per_line
,
3227 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3228 convs
->Convert_bgr888_to_any0888
3230 srcbits
,-bmpImage
->bytes_per_line
,
3240 const char* srcbits
;
3242 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3244 if (gDst
==bmpImage
->green_mask
) {
3245 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
3246 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3247 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3248 convs
->Convert_0888_asis
3250 srcbits
,-bmpImage
->bytes_per_line
,
3252 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3253 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3255 /* the tests below assume sane bmpImage masks */
3256 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
3257 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3258 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3259 convs
->Convert_0888_reverse
3261 srcbits
,-bmpImage
->bytes_per_line
,
3264 /* ==== any 0888 bmp -> any 0888 dib ==== */
3265 convs
->Convert_0888_any
3267 srcbits
,-bmpImage
->bytes_per_line
,
3268 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3272 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3273 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3275 /* the tests below assume sane bmpImage masks */
3277 /* ==== any 0888 bmp -> any 0888 dib ==== */
3278 convs
->Convert_0888_any
3280 srcbits
,-bmpImage
->bytes_per_line
,
3281 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3291 const char* srcbits
;
3293 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3295 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
3296 if (bmpImage
->green_mask
==0x03e0) {
3297 if (bmpImage
->red_mask
==0x7f00) {
3298 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3299 convs
->Convert_555_to_0888_asis
3301 srcbits
,-bmpImage
->bytes_per_line
,
3303 } else if (bmpImage
->blue_mask
==0x7f00) {
3304 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3305 convs
->Convert_555_to_0888_reverse
3307 srcbits
,-bmpImage
->bytes_per_line
,
3312 } else if (bmpImage
->green_mask
==0x07e0) {
3313 if (bmpImage
->red_mask
==0xf800) {
3314 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3315 convs
->Convert_565_to_0888_asis
3317 srcbits
,-bmpImage
->bytes_per_line
,
3319 } else if (bmpImage
->blue_mask
==0xf800) {
3320 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3321 convs
->Convert_565_to_0888_reverse
3323 srcbits
,-bmpImage
->bytes_per_line
,
3331 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
3332 if (bmpImage
->green_mask
==0x03e0) {
3333 if (bmpImage
->blue_mask
==0x7f00) {
3334 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3335 convs
->Convert_555_to_0888_asis
3337 srcbits
,-bmpImage
->bytes_per_line
,
3339 } else if (bmpImage
->red_mask
==0x7f00) {
3340 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3341 convs
->Convert_555_to_0888_reverse
3343 srcbits
,-bmpImage
->bytes_per_line
,
3348 } else if (bmpImage
->green_mask
==0x07e0) {
3349 if (bmpImage
->blue_mask
==0xf800) {
3350 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3351 convs
->Convert_565_to_0888_asis
3353 srcbits
,-bmpImage
->bytes_per_line
,
3355 } else if (bmpImage
->red_mask
==0xf800) {
3356 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3357 convs
->Convert_565_to_0888_reverse
3359 srcbits
,-bmpImage
->bytes_per_line
,
3368 if (bmpImage
->green_mask
==0x03e0 &&
3369 (bmpImage
->red_mask
==0x7f00 ||
3370 bmpImage
->blue_mask
==0x7f00)) {
3371 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3372 convs
->Convert_5x5_to_any0888
3374 srcbits
,-bmpImage
->bytes_per_line
,
3375 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3378 } else if (bmpImage
->green_mask
==0x07e0 &&
3379 (bmpImage
->red_mask
==0xf800 ||
3380 bmpImage
->blue_mask
==0xf800)) {
3381 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3382 convs
->Convert_5x5_to_any0888
3384 srcbits
,-bmpImage
->bytes_per_line
,
3385 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3397 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3399 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3400 int rShift
,gShift
,bShift
;
3403 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3404 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3405 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3406 for (h
= lines
- 1; h
>= 0; h
--) {
3407 dstpixel
=(DWORD
*)dstbits
;
3408 for (x
= 0; x
< width
; x
++) {
3409 PALETTEENTRY srcval
;
3410 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3411 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3412 (srcval
.peGreen
<< gShift
) |
3413 (srcval
.peBlue
<< bShift
);
3415 dstbits
+= linebytes
;
3423 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3425 /* ==== pal 8 bmp -> any 0888 dib ==== */
3426 int rShift
,gShift
,bShift
;
3427 const void* srcbits
;
3428 const BYTE
* srcpixel
;
3431 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3432 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3433 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3434 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3435 for (h
= lines
- 1; h
>= 0; h
--) {
3437 dstpixel
=(DWORD
*)dstbits
;
3438 for (x
= 0; x
< width
; x
++) {
3439 PALETTEENTRY srcval
;
3440 srcval
=srccolors
[*srcpixel
++];
3441 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3442 (srcval
.peGreen
<< gShift
) |
3443 (srcval
.peBlue
<< bShift
);
3445 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3446 dstbits
+= linebytes
;
3456 /* ==== any bmp format -> any 0888 dib ==== */
3457 int rShift
,gShift
,bShift
;
3460 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3461 bmpImage
->depth
, bmpImage
->red_mask
,
3462 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3465 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3466 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3467 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3468 for (h
= lines
- 1; h
>= 0; h
--) {
3469 dstpixel
=(DWORD
*)dstbits
;
3470 for (x
= 0; x
< width
; x
++) {
3472 srcval
=X11DRV_PALETTE_ToLogical(physDev
, XGetPixel(bmpImage
, x
, h
));
3473 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3474 (GetGValue(srcval
) << gShift
) |
3475 (GetBValue(srcval
) << bShift
);
3477 dstbits
+= linebytes
;
3484 static int XGetSubImageErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
3486 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
3489 /***********************************************************************
3490 * X11DRV_DIB_SetImageBits_GetSubImage
3492 * Helper for X11DRV_DIB_SetImageBits
3494 static void X11DRV_DIB_SetImageBits_GetSubImage(
3495 const X11DRV_DIB_IMAGEBITS_DESCR
*descr
, XImage
*bmpImage
)
3497 /* compressed bitmaps may contain gaps in them. So make a copy
3498 * of the existing pixels first */
3501 SetRect( &bmprc
, descr
->xDest
, descr
->yDest
,
3502 descr
->xDest
+ descr
->width
, descr
->yDest
+ descr
->height
);
3503 GetRgnBox( descr
->physDev
->region
, &rc
);
3504 /* convert from dc to drawable origin */
3505 OffsetRect( &rc
, descr
->physDev
->dc_rect
.left
, descr
->physDev
->dc_rect
.top
);
3506 /* clip visible rect with bitmap */
3507 if( IntersectRect( &rc
, &rc
, &bmprc
))
3509 X11DRV_expect_error( gdi_display
, XGetSubImageErrorHandler
, NULL
);
3510 XGetSubImage( gdi_display
, descr
->drawable
, rc
.left
, rc
.top
,
3511 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, AllPlanes
,
3513 descr
->xSrc
+ rc
.left
- bmprc
.left
,
3514 descr
->ySrc
+ rc
.top
- bmprc
.top
);
3515 X11DRV_check_error();
3519 /***********************************************************************
3520 * X11DRV_DIB_SetImageBits
3522 * Transfer the bits to an X image.
3523 * Helper function for SetDIBits() and SetDIBitsToDevice().
3525 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3527 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3528 void *old_data
= NULL
;
3533 bmpImage
= descr
->image
;
3535 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3536 descr
->infoWidth
, lines
, 32, 0 );
3537 bmpImage
->data
= HeapAlloc( GetProcessHeap(), 0, lines
* bmpImage
->bytes_per_line
);
3538 if(bmpImage
->data
== NULL
) {
3539 ERR("Out of memory!\n");
3540 XDestroyImage( bmpImage
);
3541 wine_tsx11_unlock();
3545 wine_tsx11_unlock();
3547 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3548 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3549 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3550 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3551 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3553 #ifdef HAVE_LIBXXSHM
3554 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
3555 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3556 && descr
->xDest
== 0 && descr
->yDest
== 0)
3558 TRACE("Using the shared pixmap data.\n");
3561 XSync( gdi_display
, False
);
3562 wine_tsx11_unlock();
3564 old_data
= descr
->image
->data
;
3565 descr
->image
->data
= descr
->physBitmap
->shminfo
.shmaddr
;
3569 /* Transfer the pixels */
3572 switch(descr
->infoBpp
)
3575 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3576 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3577 bmpImage
, descr
->dibpitch
);
3580 if (descr
->compression
) {
3581 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3582 X11DRV_DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
3583 descr
->infoWidth
, descr
->width
,
3584 descr
->xSrc
, (int *)(descr
->colorMap
),
3587 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3588 descr
->infoWidth
, descr
->width
,
3589 descr
->xSrc
, (int*)(descr
->colorMap
),
3590 bmpImage
, descr
->dibpitch
);
3593 if (descr
->compression
) {
3594 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3595 X11DRV_DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
3596 descr
->infoWidth
, descr
->width
,
3597 descr
->xSrc
, (int *)(descr
->colorMap
),
3600 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3601 descr
->infoWidth
, descr
->width
,
3602 descr
->xSrc
, (int *)(descr
->colorMap
),
3603 bmpImage
, descr
->dibpitch
);
3607 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3608 descr
->infoWidth
, descr
->width
,
3609 descr
->xSrc
, descr
->physDev
,
3610 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3611 bmpImage
, descr
->dibpitch
);
3614 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3615 descr
->infoWidth
, descr
->width
,
3616 descr
->xSrc
, descr
->physDev
,
3617 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3618 bmpImage
, descr
->dibpitch
);
3621 X11DRV_DIB_SetImageBits_32( descr
->lines
, descr
->bits
,
3622 descr
->infoWidth
, descr
->width
,
3623 descr
->xSrc
, descr
->physDev
,
3624 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3625 bmpImage
, descr
->dibpitch
);
3628 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3634 WARN( "invalid bits pointer %p\n", descr
->bits
);
3639 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3640 descr
->drawable
, descr
->gc
, bmpImage
,
3641 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3642 descr
->width
, descr
->height
);
3647 #ifdef HAVE_LIBXXSHM
3648 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
3649 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3650 && descr
->xDest
== 0 && descr
->yDest
== 0)
3652 XSync( gdi_display
, False
);
3654 else if (descr
->shm_mode
== X11DRV_SHM_IMAGE
&& descr
->image
)
3656 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3657 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3658 descr
->width
, descr
->height
, FALSE
);
3659 XSync( gdi_display
, 0 );
3664 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3665 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3666 descr
->width
, descr
->height
);
3670 if (old_data
) descr
->image
->data
= old_data
;
3672 if (!descr
->image
) X11DRV_DIB_DestroyXImage( bmpImage
);
3673 wine_tsx11_unlock();
3677 /***********************************************************************
3678 * X11DRV_DIB_GetImageBits
3680 * Transfer the bits from an X image.
3682 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3684 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3685 void *old_data
= NULL
;
3690 bmpImage
= descr
->image
;
3692 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3693 descr
->infoWidth
, lines
, 32, 0 );
3694 bmpImage
->data
= HeapAlloc( GetProcessHeap(), 0, lines
* bmpImage
->bytes_per_line
);
3695 if(bmpImage
->data
== NULL
) {
3696 ERR("Out of memory!\n");
3697 XDestroyImage( bmpImage
);
3698 wine_tsx11_unlock();
3703 #ifdef HAVE_LIBXXSHM
3705 /* We must not call XShmGetImage() with a bitmap which is bigger than the available area.
3706 If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */
3707 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
&& descr
->image
3708 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3709 && descr
->xDest
== 0 && descr
->yDest
== 0
3710 && bmpImage
->width
<= (descr
->width
- descr
->xSrc
)
3711 && bmpImage
->height
<= (descr
->height
- descr
->ySrc
))
3713 XSync( gdi_display
, False
);
3714 old_data
= bmpImage
->data
;
3715 bmpImage
->data
= descr
->physBitmap
->shminfo
.shmaddr
;
3716 TRACE("Using shared pixmap data.\n");
3718 else if (descr
->shm_mode
== X11DRV_SHM_IMAGE
&& descr
->image
3719 && bmpImage
->width
<= (descr
->width
- descr
->xSrc
)
3720 && bmpImage
->height
<= (descr
->height
- descr
->ySrc
))
3722 int saveRed
, saveGreen
, saveBlue
;
3724 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3725 gdi_display
, descr
->drawable
, bmpImage
,
3726 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3728 /* We must save and restore the bmpImage's masks in order
3729 * to preserve them across the call to XShmGetImage, which
3730 * decides to eliminate them since it doesn't happen to know
3731 * what the format of the image is supposed to be, even though
3733 saveRed
= bmpImage
->red_mask
;
3734 saveBlue
= bmpImage
->blue_mask
;
3735 saveGreen
= bmpImage
->green_mask
;
3737 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3738 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3740 bmpImage
->red_mask
= saveRed
;
3741 bmpImage
->blue_mask
= saveBlue
;
3742 bmpImage
->green_mask
= saveGreen
;
3745 #endif /* HAVE_LIBXXSHM */
3747 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3748 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3749 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3750 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3751 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3752 bmpImage
, descr
->xDest
, descr
->yDest
);
3754 wine_tsx11_unlock();
3756 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3757 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3758 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3759 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3760 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3761 /* Transfer the pixels */
3762 switch(descr
->infoBpp
)
3765 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3766 descr
->infoWidth
, descr
->width
,
3767 descr
->colorMap
, descr
->palentry
,
3768 bmpImage
, descr
->dibpitch
);
3772 if (descr
->compression
) {
3773 FIXME("Compression not yet supported!\n");
3774 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 4 ) * abs(descr
->lines
))
3777 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3778 descr
->infoWidth
, descr
->width
,
3779 descr
->colorMap
, descr
->palentry
,
3780 bmpImage
, descr
->dibpitch
);
3783 if (descr
->compression
) {
3784 FIXME("Compression not yet supported!\n");
3785 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 8 ) * abs(descr
->lines
))
3788 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3789 descr
->infoWidth
, descr
->width
,
3790 descr
->colorMap
, descr
->palentry
,
3791 bmpImage
, descr
->dibpitch
);
3795 X11DRV_DIB_GetImageBits_16( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3796 descr
->infoWidth
,descr
->width
,
3798 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3799 bmpImage
, descr
->dibpitch
);
3803 X11DRV_DIB_GetImageBits_24( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3804 descr
->infoWidth
,descr
->width
,
3806 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3807 bmpImage
, descr
->dibpitch
);
3811 X11DRV_DIB_GetImageBits_32( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3812 descr
->infoWidth
, descr
->width
,
3814 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3815 bmpImage
, descr
->dibpitch
);
3819 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3823 if (old_data
) bmpImage
->data
= old_data
;
3824 if (!descr
->image
) X11DRV_DIB_DestroyXImage( bmpImage
);
3828 /*************************************************************************
3829 * X11DRV_SetDIBitsToDevice
3832 INT CDECL
X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE
*physDev
, INT xDest
, INT yDest
, DWORD cx
,
3833 DWORD cy
, INT xSrc
, INT ySrc
,
3834 UINT startscan
, UINT lines
, LPCVOID bits
,
3835 const BITMAPINFO
*info
, UINT coloruse
)
3837 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3842 int rop
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
) - 1];
3844 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3845 &descr
.infoBpp
, &descr
.compression
) == -1)
3848 top_down
= (height
< 0);
3849 if (top_down
) height
= -height
;
3853 LPtoDP(physDev
->hdc
, &pt
, 1);
3855 if (!lines
|| (startscan
>= height
)) return 0;
3856 if (!top_down
&& startscan
+ lines
> height
) lines
= height
- startscan
;
3858 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3859 * and clamp all values to fit inside [startscan,startscan+lines]
3861 if (ySrc
+ cy
<= startscan
+ lines
)
3863 UINT y
= startscan
+ lines
- (ySrc
+ cy
);
3864 if (ySrc
< startscan
) cy
-= (startscan
- ySrc
);
3867 /* avoid getting unnecessary lines */
3869 if (y
>= lines
) return 0;
3874 if (y
>= lines
) return lines
;
3875 ySrc
= y
; /* need to get all lines in top down mode */
3880 if (ySrc
>= startscan
+ lines
) return lines
;
3881 pt
.y
+= ySrc
+ cy
- (startscan
+ lines
);
3882 cy
= startscan
+ lines
- ySrc
;
3884 if (cy
> lines
) cy
= lines
;
3886 if (xSrc
>= width
) return lines
;
3887 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
3888 if (!cx
|| !cy
) return lines
;
3890 /* Update the pixmap from the DIB section */
3891 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
3893 X11DRV_SetupGCForText( physDev
); /* To have the correct colors */
3895 XSetFunction(gdi_display
, physDev
->gc
, rop
);
3896 wine_tsx11_unlock();
3898 switch (descr
.infoBpp
)
3903 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3905 physDev
->depth
, info
, &descr
.nColorMap
);
3906 if (!descr
.colorMap
) return 0;
3907 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3911 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3912 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3913 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3919 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3920 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3921 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3926 descr
.physDev
= physDev
;
3929 descr
.palentry
= NULL
;
3930 descr
.lines
= top_down
? -lines
: lines
;
3931 descr
.infoWidth
= width
;
3932 descr
.depth
= physDev
->depth
;
3933 descr
.drawable
= physDev
->drawable
;
3934 descr
.gc
= physDev
->gc
;
3937 descr
.xDest
= physDev
->dc_rect
.left
+ pt
.x
;
3938 descr
.yDest
= physDev
->dc_rect
.top
+ pt
.y
;
3941 descr
.shm_mode
= X11DRV_SHM_NONE
;
3942 descr
.dibpitch
= ((width
* descr
.infoBpp
+ 31) &~31) / 8;
3943 descr
.physBitmap
= NULL
;
3945 result
= X11DRV_DIB_SetImageBits( &descr
);
3947 if (descr
.infoBpp
<= 8)
3948 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3950 /* Update the DIBSection of the pixmap */
3951 X11DRV_UnlockDIBSection(physDev
, TRUE
);
3956 /***********************************************************************
3957 * SetDIBits (X11DRV.@)
3959 INT CDECL
X11DRV_SetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
,
3960 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
, UINT coloruse
)
3962 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3963 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3965 LONG width
, height
, tmpheight
;
3968 descr
.physDev
= physDev
;
3970 if (!physBitmap
) return 0;
3972 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3973 &descr
.infoBpp
, &descr
.compression
) == -1)
3977 if (height
< 0) height
= -height
;
3978 if (!lines
|| (startscan
>= height
))
3981 if (!GetObjectW( hbitmap
, sizeof(ds
), &ds
)) return 0;
3983 if (startscan
+ lines
> height
) lines
= height
- startscan
;
3985 switch (descr
.infoBpp
)
3990 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3991 descr
.physDev
, coloruse
,
3992 physBitmap
->pixmap_depth
,
3993 info
, &descr
.nColorMap
);
3994 if (!descr
.colorMap
) return 0;
3995 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3999 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4000 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4001 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4007 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4008 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4009 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4018 descr
.palentry
= NULL
;
4019 descr
.infoWidth
= width
;
4020 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
4021 descr
.depth
= physBitmap
->pixmap_depth
;
4022 descr
.drawable
= physBitmap
->pixmap
;
4023 descr
.gc
= get_bitmap_gc(physBitmap
->pixmap_depth
);
4027 descr
.yDest
= height
- startscan
- lines
;
4028 descr
.width
= ds
.dsBm
.bmWidth
;
4029 descr
.height
= lines
;
4030 descr
.shm_mode
= X11DRV_SHM_NONE
;
4031 descr
.dibpitch
= ((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8;
4032 descr
.physBitmap
= NULL
;
4033 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
4034 result
= X11DRV_DIB_SetImageBits( &descr
);
4036 /* optimisation for the case where the input bits are in exactly the same
4037 * format as the internal representation and copying to the app bits is
4038 * cheap - saves a round trip to the X server */
4039 if (descr
.compression
== BI_RGB
&&
4040 coloruse
== DIB_RGB_COLORS
&&
4041 descr
.infoBpp
== ds
.dsBm
.bmBitsPixel
&&
4042 physBitmap
->base
&& physBitmap
->size
< 65536)
4044 unsigned int srcwidthb
= X11DRV_DIB_GetDIBWidthBytes( width
, descr
.infoBpp
);
4045 int dstwidthb
= ds
.dsBm
.bmWidthBytes
;
4046 LPBYTE dbits
= physBitmap
->base
+ startscan
* dstwidthb
;
4047 const BYTE
*sbits
= bits
;
4051 TRACE("syncing compatible set bits to app bits\n");
4052 if ((tmpheight
< 0) ^ physBitmap
->topdown
)
4054 dbits
+= dstwidthb
* (lines
-1);
4055 dstwidthb
= -dstwidthb
;
4057 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4058 widthb
= min(srcwidthb
, abs(dstwidthb
));
4059 for (y
= 0; y
< lines
; y
++, dbits
+= dstwidthb
, sbits
+= srcwidthb
)
4060 memcpy(dbits
, sbits
, widthb
);
4061 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4062 physBitmap
->status
= DIB_Status_InSync
;
4064 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4066 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4071 /***********************************************************************
4072 * GetDIBits (X11DRV.@)
4074 INT CDECL
X11DRV_GetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
, UINT lines
,
4075 LPVOID bits
, BITMAPINFO
*info
, UINT coloruse
)
4077 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
4079 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4080 PALETTEENTRY palette
[256];
4083 LONG width
, tempHeight
;
4087 static const PALETTEENTRY peBlack
= {0,0,0,0};
4088 static const PALETTEENTRY peWhite
= {255,255,255,0};
4090 if (!physBitmap
) return 0;
4091 if (!(obj_size
= GetObjectW( hbitmap
, sizeof(dib
), &dib
))) return 0;
4093 bitmap_type
= DIB_GetBitmapInfo( (BITMAPINFOHEADER
*)info
, &width
, &tempHeight
, &descr
.infoBpp
, &descr
.compression
);
4094 if (bitmap_type
== -1)
4096 ERR("Invalid bitmap\n");
4100 if (physBitmap
->pixmap_depth
> 1)
4102 GetPaletteEntries( GetCurrentObject( physDev
->hdc
, OBJ_PAL
), 0, 256, palette
);
4106 palette
[0] = peBlack
;
4107 palette
[1] = peWhite
;
4110 descr
.lines
= tempHeight
;
4111 core_header
= (bitmap_type
== 0);
4112 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
4114 TRACE("%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
4115 lines
, dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
, width
, descr
.lines
, startscan
);
4117 if( lines
> dib
.dsBm
.bmHeight
) lines
= dib
.dsBm
.bmHeight
;
4119 height
= descr
.lines
;
4120 if (height
< 0) height
= -height
;
4121 if( lines
> height
) lines
= height
;
4122 /* Top-down images have a negative biHeight, the scanlines of these images
4123 * were inverted in X11DRV_DIB_GetImageBits_xx
4124 * To prevent this we simply change the sign of lines
4125 * (the number of scan lines to copy).
4126 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
4128 if( descr
.lines
< 0 && lines
> 0) lines
= -lines
;
4130 if( startscan
>= dib
.dsBm
.bmHeight
) return 0;
4132 descr
.colorMap
= NULL
;
4134 switch (descr
.infoBpp
)
4139 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4140 if(coloruse
== DIB_RGB_COLORS
)
4141 descr
.colorMap
= colorPtr
;
4143 int num_colors
= 1 << descr
.infoBpp
, i
;
4146 WORD
*index
= colorPtr
;
4147 descr
.colorMap
= rgb
= HeapAlloc(GetProcessHeap(), 0, num_colors
* sizeof(RGBQUAD
));
4148 for(i
= 0; i
< num_colors
; i
++, rgb
++, index
++) {
4149 colref
= X11DRV_PALETTE_ToLogical(physDev
, X11DRV_PALETTE_ToPhysical(physDev
, PALETTEINDEX(*index
)));
4150 rgb
->rgbRed
= GetRValue(colref
);
4151 rgb
->rgbGreen
= GetGValue(colref
);
4152 rgb
->rgbBlue
= GetBValue(colref
);
4153 rgb
->rgbReserved
= 0;
4159 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4160 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4161 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4165 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4166 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4167 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4171 descr
.physDev
= physDev
;
4172 descr
.palentry
= palette
;
4174 descr
.image
= physBitmap
->image
;
4175 descr
.infoWidth
= width
;
4176 descr
.lines
= lines
;
4177 descr
.depth
= physBitmap
->pixmap_depth
;
4178 descr
.drawable
= physBitmap
->pixmap
;
4179 descr
.gc
= get_bitmap_gc(physBitmap
->pixmap_depth
);
4180 descr
.width
= dib
.dsBm
.bmWidth
;
4181 descr
.height
= dib
.dsBm
.bmHeight
;
4185 descr
.sizeImage
= core_header
? 0 : info
->bmiHeader
.biSizeImage
;
4186 descr
.physBitmap
= physBitmap
;
4188 if (descr
.lines
> 0)
4190 descr
.ySrc
= (descr
.height
-1) - (startscan
+ (lines
-1));
4194 descr
.ySrc
= startscan
;
4196 descr
.shm_mode
= physBitmap
->shm_mode
;
4197 descr
.dibpitch
= (obj_size
== sizeof(DIBSECTION
)) ? dib
.dsBm
.bmWidthBytes
4198 : (((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8);
4200 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
4201 X11DRV_DIB_GetImageBits( &descr
);
4202 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4204 if(!core_header
&& info
->bmiHeader
.biSizeImage
== 0) /* Fill in biSizeImage */
4205 info
->bmiHeader
.biSizeImage
= X11DRV_DIB_GetDIBImageBytes( descr
.infoWidth
,
4209 if (descr
.compression
== BI_BITFIELDS
)
4211 *(DWORD
*)info
->bmiColors
= descr
.rMask
;
4212 *((DWORD
*)info
->bmiColors
+ 1) = descr
.gMask
;
4213 *((DWORD
*)info
->bmiColors
+ 2) = descr
.bMask
;
4215 else if (!core_header
)
4217 /* if RLE or JPEG compression were supported,
4218 * this line would be invalid. */
4219 info
->bmiHeader
.biCompression
= 0;
4222 if(descr
.colorMap
!= colorPtr
)
4223 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4227 /***********************************************************************
4228 * X11DRV_DIB_DoCopyDIBSection
4230 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
4231 void *colorMap
, int nColorMap
,
4232 Drawable dest
, GC gc
,
4233 DWORD xSrc
, DWORD ySrc
,
4234 DWORD xDest
, DWORD yDest
,
4235 DWORD width
, DWORD height
)
4237 DIBSECTION dibSection
;
4238 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4239 int identity
[2] = {0,1};
4241 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
4243 descr
.physDev
= NULL
;
4244 descr
.palentry
= NULL
;
4245 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
4246 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
4247 descr
.lines
= physBitmap
->topdown
? -dibSection
.dsBmih
.biHeight
: dibSection
.dsBmih
.biHeight
;
4248 descr
.image
= physBitmap
->image
;
4249 descr
.colorMap
= colorMap
;
4250 descr
.nColorMap
= nColorMap
;
4251 descr
.bits
= dibSection
.dsBm
.bmBits
;
4252 descr
.depth
= physBitmap
->pixmap_depth
;
4253 descr
.compression
= dibSection
.dsBmih
.biCompression
;
4254 descr
.physBitmap
= physBitmap
;
4256 if(descr
.infoBpp
== 1)
4257 descr
.colorMap
= (void*)identity
;
4259 switch (descr
.infoBpp
)
4264 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4268 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
4269 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
4270 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
4275 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
4276 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
4277 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
4282 descr
.drawable
= dest
;
4286 descr
.xDest
= xDest
;
4287 descr
.yDest
= yDest
;
4288 descr
.width
= width
;
4289 descr
.height
= height
;
4290 descr
.sizeImage
= 0;
4292 descr
.shm_mode
= physBitmap
->shm_mode
;
4293 #ifdef HAVE_LIBXXSHM
4294 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
&& physBitmap
->pixmap
!= dest
)
4296 descr
.shm_mode
= X11DRV_SHM_NONE
;
4299 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
4303 TRACE("Copying from Pixmap to DIB bits\n");
4304 X11DRV_DIB_GetImageBits( &descr
);
4308 TRACE("Copying from DIB bits to Pixmap\n");
4309 X11DRV_DIB_SetImageBits( &descr
);
4313 /***********************************************************************
4314 * X11DRV_DIB_CopyDIBSection
4316 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE
*physDevSrc
, X11DRV_PDEVICE
*physDevDst
,
4317 DWORD xSrc
, DWORD ySrc
, DWORD xDest
, DWORD yDest
,
4318 DWORD width
, DWORD height
)
4321 X_PHYSBITMAP
*physBitmap
;
4322 unsigned int nColorMap
;
4326 TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc
->hdc
, physDevDst
->hdc
,
4327 xSrc
, ySrc
, xDest
, yDest
, width
, height
);
4328 /* this function is meant as an optimization for BitBlt,
4329 * not to be called otherwise */
4330 physBitmap
= physDevSrc
->bitmap
;
4331 if (!physBitmap
|| GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
4333 ERR("called for non-DIBSection!?\n");
4336 /* while BitBlt should already have made sure we only get
4337 * positive values, we should check for oversize values */
4338 if ((xSrc
< dib
.dsBm
.bmWidth
) &&
4339 (ySrc
< dib
.dsBm
.bmHeight
)) {
4340 if (xSrc
+ width
> dib
.dsBm
.bmWidth
)
4341 width
= dib
.dsBm
.bmWidth
- xSrc
;
4342 if (ySrc
+ height
> dib
.dsBm
.bmHeight
)
4343 height
= dib
.dsBm
.bmHeight
- ySrc
;
4344 /* if the source bitmap is 8bpp or less, we're supposed to use the
4345 * DC's palette for color conversion (not the DIB color table) */
4346 if (dib
.dsBm
.bmBitsPixel
<= 8) {
4347 HPALETTE hPalette
= GetCurrentObject( physDevSrc
->hdc
, OBJ_PAL
);
4348 if (!hPalette
|| (hPalette
== GetStockObject(DEFAULT_PALETTE
))) {
4349 /* HACK: no palette has been set in the source DC,
4350 * use the DIB colormap instead - this is necessary in some
4351 * cases since we need to do depth conversion in some places
4352 * where real Windows can just copy data straight over */
4353 x11ColorMap
= physBitmap
->colorMap
;
4354 nColorMap
= physBitmap
->nColorMap
;
4355 freeColorMap
= FALSE
;
4357 const BITMAPINFO
* info
= (BITMAPINFO
*)&dib
.dsBmih
;
4360 nColorMap
= X11DRV_DIB_GetColorCount(info
);
4361 x11ColorMap
= HeapAlloc(GetProcessHeap(), 0, nColorMap
* sizeof(int));
4362 for (i
= 0; i
< nColorMap
; i
++)
4363 x11ColorMap
[i
] = X11DRV_PALETTE_ToPhysical(physDevSrc
, PALETTEINDEX(i
));
4364 freeColorMap
= TRUE
;
4371 freeColorMap
= FALSE
;
4373 /* perform the copy */
4374 X11DRV_DIB_DoCopyDIBSection(physBitmap
, FALSE
, x11ColorMap
, nColorMap
,
4375 physDevDst
->drawable
, physDevDst
->gc
, xSrc
, ySrc
,
4376 physDevDst
->dc_rect
.left
+ xDest
, physDevDst
->dc_rect
.top
+ yDest
,
4378 /* free color mapping */
4380 HeapFree(GetProcessHeap(), 0, x11ColorMap
);
4384 /***********************************************************************
4385 * X11DRV_DIB_DoUpdateDIBSection
4387 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
4391 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
4392 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
4393 physBitmap
->colorMap
, physBitmap
->nColorMap
,
4394 physBitmap
->pixmap
, get_bitmap_gc(physBitmap
->pixmap_depth
),
4395 0, 0, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
);
4398 /***********************************************************************
4399 * X11DRV_DIB_FaultHandler
4401 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
4403 X_PHYSBITMAP
*physBitmap
= NULL
;
4407 const size_t pagemask
= getpagesize() - 1;
4409 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
4410 return EXCEPTION_CONTINUE_SEARCH
;
4412 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
4414 EnterCriticalSection(&dibs_cs
);
4415 LIST_FOR_EACH( ptr
, &dibs_list
)
4417 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
4418 if ((physBitmap
->base
<= addr
) &&
4419 (addr
< physBitmap
->base
+ ((physBitmap
->size
+ pagemask
) & ~pagemask
)))
4425 LeaveCriticalSection(&dibs_cs
);
4427 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
4429 if (addr
>= physBitmap
->base
+ physBitmap
->size
)
4430 WARN( "%p: access to %p beyond the end of the DIB\n", physBitmap
->hbitmap
, addr
);
4432 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
);
4433 if (ep
->ExceptionRecord
->ExceptionInformation
[0] == EXCEPTION_WRITE_FAULT
) {
4434 /* the app tried to write the DIB bits */
4435 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
);
4437 /* the app tried to read the DIB bits */
4438 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
);
4440 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4442 return EXCEPTION_CONTINUE_EXECUTION
;
4445 /***********************************************************************
4448 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
)
4450 INT ret
= DIB_Status_None
;
4452 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4453 EnterCriticalSection(&physBitmap
->lock
);
4454 ret
= physBitmap
->status
;
4456 case DIB_Status_GdiMod
:
4457 /* GDI access - request to draw on pixmap */
4458 switch (physBitmap
->status
)
4461 case DIB_Status_None
:
4462 physBitmap
->p_status
= DIB_Status_GdiMod
;
4463 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4466 case DIB_Status_GdiMod
:
4467 TRACE("GdiMod requested in status GdiMod\n" );
4468 physBitmap
->p_status
= DIB_Status_GdiMod
;
4471 case DIB_Status_InSync
:
4472 TRACE("GdiMod requested in status InSync\n" );
4473 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4474 physBitmap
->status
= DIB_Status_GdiMod
;
4475 physBitmap
->p_status
= DIB_Status_InSync
;
4478 case DIB_Status_AppMod
:
4479 TRACE("GdiMod requested in status AppMod\n" );
4480 /* make it readonly to avoid app changing data while we copy */
4481 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4482 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4483 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4484 physBitmap
->p_status
= DIB_Status_AppMod
;
4485 physBitmap
->status
= DIB_Status_GdiMod
;
4490 case DIB_Status_InSync
:
4491 /* App access - request access to read DIB surface */
4492 /* (typically called from signal handler) */
4493 switch (physBitmap
->status
)
4496 case DIB_Status_None
:
4497 /* shouldn't happen from signal handler */
4500 case DIB_Status_GdiMod
:
4501 TRACE("InSync requested in status GdiMod\n" );
4502 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4503 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4504 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4505 physBitmap
->status
= DIB_Status_InSync
;
4508 case DIB_Status_InSync
:
4509 TRACE("InSync requested in status InSync\n" );
4510 /* shouldn't happen from signal handler */
4513 case DIB_Status_AppMod
:
4514 TRACE("InSync requested in status AppMod\n" );
4515 /* no reason to do anything here, and this
4516 * shouldn't happen from signal handler */
4521 case DIB_Status_AppMod
:
4522 /* App access - request access to write DIB surface */
4523 /* (typically called from signal handler) */
4524 switch (physBitmap
->status
)
4527 case DIB_Status_None
:
4528 /* shouldn't happen from signal handler */
4531 case DIB_Status_GdiMod
:
4532 TRACE("AppMod requested in status GdiMod\n" );
4533 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4534 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4535 physBitmap
->status
= DIB_Status_AppMod
;
4538 case DIB_Status_InSync
:
4539 TRACE("AppMod requested in status InSync\n" );
4540 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4541 physBitmap
->status
= DIB_Status_AppMod
;
4544 case DIB_Status_AppMod
:
4545 TRACE("AppMod requested in status AppMod\n" );
4546 /* shouldn't happen from signal handler */
4551 /* it is up to the caller to do the copy/conversion, probably
4552 * using the return value to decide where to copy from */
4554 LeaveCriticalSection(&physBitmap
->lock
);
4558 /***********************************************************************
4561 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
)
4563 INT ret
= DIB_Status_None
;
4565 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4566 TRACE("Locking %p from thread %04x\n", physBitmap
->hbitmap
, GetCurrentThreadId());
4567 EnterCriticalSection(&physBitmap
->lock
);
4568 ret
= physBitmap
->status
;
4569 if (req
!= DIB_Status_None
)
4570 X11DRV_DIB_Coerce(physBitmap
, req
);
4574 /***********************************************************************
4577 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
4579 if (!physBitmap
->image
) return; /* not a DIB section */
4580 switch (physBitmap
->status
)
4583 case DIB_Status_None
:
4584 /* in case anyone is wondering, this is the "signal handler doesn't
4585 * work" case, where we always have to be ready for app access */
4587 switch (physBitmap
->p_status
)
4589 case DIB_Status_GdiMod
:
4590 TRACE("Unlocking and syncing from GdiMod\n" );
4591 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4595 TRACE("Unlocking without needing to sync\n" );
4599 else TRACE("Unlocking with no changes\n");
4600 physBitmap
->p_status
= DIB_Status_None
;
4603 case DIB_Status_GdiMod
:
4604 TRACE("Unlocking in status GdiMod\n" );
4605 /* DIB was protected in Coerce */
4607 /* no commit, revert to InSync if applicable */
4608 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
4609 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
4610 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4611 physBitmap
->status
= DIB_Status_InSync
;
4616 case DIB_Status_InSync
:
4617 TRACE("Unlocking in status InSync\n" );
4618 /* DIB was already protected in Coerce */
4621 case DIB_Status_AppMod
:
4622 TRACE("Unlocking in status AppMod\n" );
4623 /* DIB was already protected in Coerce */
4624 /* this case is ordinary only called from the signal handler,
4625 * so we don't bother to check for !commit */
4628 LeaveCriticalSection(&physBitmap
->lock
);
4629 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
4632 /***********************************************************************
4633 * X11DRV_CoerceDIBSection
4635 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4637 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4638 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
);
4641 /***********************************************************************
4642 * X11DRV_LockDIBSection
4644 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4646 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4647 return X11DRV_DIB_Lock(physDev
->bitmap
, req
);
4650 /***********************************************************************
4651 * X11DRV_UnlockDIBSection
4653 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
4655 if (!physDev
|| !physDev
->bitmap
) return;
4656 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
4660 #ifdef HAVE_LIBXXSHM
4661 /***********************************************************************
4662 * X11DRV_XShmErrorHandler
4665 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
4667 return 1; /* FIXME: should check event contents */
4670 /***********************************************************************
4671 * X11DRV_XShmCreateImage
4674 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
4675 XShmSegmentInfo
* shminfo
)
4679 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
4682 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
4684 if( shminfo
->shmid
!= -1 )
4686 shminfo
->shmaddr
= shmat( shminfo
->shmid
, 0, 0 );
4687 if( shminfo
->shmaddr
!= (char*)-1 )
4691 shminfo
->readOnly
= FALSE
;
4692 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
4693 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
4694 XSync( gdi_display
, False
);
4695 if (X11DRV_check_error()) ok
= FALSE
;
4698 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4699 return image
; /* Success! */
4701 /* An error occurred */
4702 shmdt(shminfo
->shmaddr
);
4704 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4705 shminfo
->shmid
= -1;
4707 XFlush(gdi_display
);
4708 XDestroyImage(image
);
4713 #endif /* HAVE_LIBXXSHM */
4716 /***********************************************************************
4717 * X11DRV_CreateDIBSection (X11DRV.@)
4719 HBITMAP CDECL
X11DRV_CreateDIBSection( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
,
4720 const BITMAPINFO
*bmi
, UINT usage
)
4722 X_PHYSBITMAP
*physBitmap
;
4726 #ifdef HAVE_LIBXXSHM
4731 DIB_GetBitmapInfo( &bmi
->bmiHeader
, &w
, &h
, &bpp
, &compr
);
4733 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
4734 if (h
< 0) physBitmap
->topdown
= TRUE
;
4735 physBitmap
->status
= DIB_Status_None
;
4737 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
4739 /* create color map */
4740 if (dib
.dsBm
.bmBitsPixel
<= 8)
4742 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( physDev
,
4743 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
4744 &physBitmap
->nColorMap
);
4747 if (!X11DRV_XRender_SetPhysBitmapDepth( physBitmap
, dib
.dsBm
.bmBitsPixel
, &dib
))
4749 if (dib
.dsBm
.bmBitsPixel
== 1)
4751 physBitmap
->pixmap_depth
= 1;
4752 physBitmap
->trueColor
= FALSE
;
4756 physBitmap
->pixmap_depth
= screen_depth
;
4757 physBitmap
->pixmap_color_shifts
= X11DRV_PALETTE_default_shifts
;
4758 physBitmap
->trueColor
= (visual
->class == TrueColor
|| visual
->class == DirectColor
);
4762 /* create pixmap and X image */
4764 #ifdef HAVE_LIBXXSHM
4765 physBitmap
->shminfo
.shmid
= -1;
4767 if (XShmQueryVersion( gdi_display
, &major
, &minor
, &pixmaps
)
4768 && (physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4769 physBitmap
->pixmap_depth
, &physBitmap
->shminfo
)))
4773 physBitmap
->shm_mode
= X11DRV_SHM_PIXMAP
;
4774 physBitmap
->image
->data
= HeapAlloc( GetProcessHeap(), 0,
4775 dib
.dsBm
.bmHeight
* physBitmap
->image
->bytes_per_line
);
4779 physBitmap
->shm_mode
= X11DRV_SHM_IMAGE
;
4780 physBitmap
->image
->data
= physBitmap
->shminfo
.shmaddr
;
4786 physBitmap
->shm_mode
= X11DRV_SHM_NONE
;
4787 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4788 physBitmap
->pixmap_depth
);
4791 #ifdef HAVE_LIBXXSHM
4792 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
)
4794 TRACE("Creating shared pixmap for bmp %p.\n", physBitmap
->hbitmap
);
4795 physBitmap
->pixmap
= XShmCreatePixmap( gdi_display
, root_window
,
4796 physBitmap
->shminfo
.shmaddr
, &physBitmap
->shminfo
,
4797 dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4798 physBitmap
->pixmap_depth
);
4803 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
4804 dib
.dsBm
.bmHeight
, physBitmap
->pixmap_depth
);
4807 wine_tsx11_unlock();
4808 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
4810 if (physBitmap
->trueColor
)
4812 ColorShifts
*shifts
= &physBitmap
->pixmap_color_shifts
;
4814 /* When XRender is around and used, we also support dibsections in other formats like 16-bit. In these
4815 * cases we need to override the mask of XImages. The reason is that during XImage creation the masks are
4816 * derived from a 24-bit visual (no 16-bit ones are around when X runs at 24-bit). SetImageBits and other
4817 * functions rely on the color masks for proper color conversion, so we need to override the masks here. */
4818 physBitmap
->image
->red_mask
= shifts
->physicalRed
.max
<< shifts
->physicalRed
.shift
;
4819 physBitmap
->image
->green_mask
= shifts
->physicalGreen
.max
<< shifts
->physicalGreen
.shift
;
4820 physBitmap
->image
->blue_mask
= shifts
->physicalBlue
.max
<< shifts
->physicalBlue
.shift
;
4823 /* install fault handler */
4824 InitializeCriticalSection( &physBitmap
->lock
);
4825 physBitmap
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": X_PHYSBITMAP.lock");
4827 physBitmap
->base
= dib
.dsBm
.bmBits
;
4828 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
4829 physBitmap
->status
= DIB_Status_AppMod
;
4832 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
4833 EnterCriticalSection( &dibs_cs
);
4834 list_add_head( &dibs_list
, &physBitmap
->entry
);
4835 LeaveCriticalSection( &dibs_cs
);
4837 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4842 /***********************************************************************
4843 * X11DRV_DIB_DeleteDIBSection
4845 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
4849 EnterCriticalSection( &dibs_cs
);
4850 list_remove( &physBitmap
->entry
);
4851 last
= list_empty( &dibs_list
);
4852 LeaveCriticalSection( &dibs_cs
);
4856 RemoveVectoredExceptionHandler( dibs_handler
);
4857 dibs_handler
= NULL
;
4860 if (dib
->dshSection
)
4861 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
);
4863 if (physBitmap
->image
)
4866 #ifdef HAVE_LIBXXSHM
4867 if (physBitmap
->shminfo
.shmid
!= -1)
4869 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4870 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
) X11DRV_DIB_DestroyXImage( physBitmap
->image
);
4871 else XDestroyImage( physBitmap
->image
);
4872 shmdt( physBitmap
->shminfo
.shmaddr
);
4873 physBitmap
->shminfo
.shmid
= -1;
4874 physBitmap
->shm_mode
= X11DRV_SHM_NONE
;
4878 X11DRV_DIB_DestroyXImage( physBitmap
->image
);
4879 wine_tsx11_unlock();
4882 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4883 physBitmap
->lock
.DebugInfo
->Spare
[0] = 0;
4884 DeleteCriticalSection(&physBitmap
->lock
);
4887 /***********************************************************************
4888 * SetDIBColorTable (X11DRV.@)
4890 UINT CDECL
X11DRV_SetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4894 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4896 if (!physBitmap
) return 0;
4897 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4899 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4900 UINT end
= count
+ start
;
4901 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4903 * Changing color table might change the mapping between
4904 * DIB colors and X11 colors and thus alter the visible state
4905 * of the bitmap object.
4908 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4909 * at least for a 1 bpp dibsection
4911 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
);
4912 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4913 dib
.dsBm
.bmBitsPixel
,
4914 TRUE
, colors
, start
, end
);
4915 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4922 /***********************************************************************
4923 * X11DRV_DIB_CreateDIBFromBitmap
4925 * Allocates a packed DIB and copies the bitmap data into it.
4927 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4932 LPBITMAPINFOHEADER pbmiHeader
;
4933 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4936 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4939 * A packed DIB contains a BITMAPINFO structure followed immediately by
4940 * an optional color palette and the pixel data.
4943 /* Calculate the size of the packed DIB */
4944 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4945 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4946 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4948 /* Get the offset to the bits */
4949 OffsetBits
= cPackedSize
- cDataSize
;
4951 /* Allocate the packed DIB */
4952 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4953 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4957 WARN("Could not allocate packed DIB!\n");
4961 /* A packed DIB starts with a BITMAPINFOHEADER */
4962 pPackedDIB
= GlobalLock(hPackedDIB
);
4963 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4965 /* Init the BITMAPINFOHEADER */
4966 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
4967 pbmiHeader
->biWidth
= bmp
.bmWidth
;
4968 pbmiHeader
->biHeight
= bmp
.bmHeight
;
4969 pbmiHeader
->biPlanes
= 1;
4970 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
4971 pbmiHeader
->biCompression
= BI_RGB
;
4972 pbmiHeader
->biSizeImage
= 0;
4973 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
4974 pbmiHeader
->biClrUsed
= 0;
4975 pbmiHeader
->biClrImportant
= 0;
4977 /* Retrieve the DIB bits from the bitmap and fill in the
4978 * DIB color table if present */
4980 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
4981 hBmp
, /* Handle to bitmap */
4982 0, /* First scan line to set in dest bitmap */
4983 bmp
.bmHeight
, /* Number of scan lines to copy */
4984 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
4985 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
4986 0); /* RGB or palette index */
4987 GlobalUnlock(hPackedDIB
);
4989 /* Cleanup if GetDIBits failed */
4990 if (nLinesCopied
!= bmp
.bmHeight
)
4992 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
4993 GlobalFree(hPackedDIB
);
5000 /**************************************************************************
5001 * X11DRV_DIB_CreateDIBFromPixmap
5003 * Allocates a packed DIB and copies the Pixmap data into it.
5004 * The Pixmap passed in is deleted after the conversion.
5006 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
5009 X_PHYSBITMAP
*physBitmap
;
5012 HGLOBAL hPackedDIB
= 0;
5014 int x
,y
; /* Unused */
5015 unsigned border_width
; /* Unused */
5016 unsigned int depth
, width
, height
;
5018 /* Get the Pixmap dimensions and bit depth */
5020 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
5021 &border_width
, &depth
)) depth
= 0;
5022 wine_tsx11_unlock();
5023 if (!depth
) return 0;
5025 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
5026 width
, height
, depth
);
5029 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
5030 * and make it a container for the pixmap passed.
5032 if (!(hBmp
= CreateBitmap( width
, height
, 1, depth_to_bpp(depth
), NULL
))) return 0;
5034 /* force bitmap to be owned by a screen DC */
5035 hdcMem
= CreateCompatibleDC( hdc
);
5036 SelectObject( hdcMem
, SelectObject( hdcMem
, hBmp
));
5039 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
5041 /* swap the new pixmap in */
5042 orig_pixmap
= physBitmap
->pixmap
;
5043 physBitmap
->pixmap
= pixmap
;
5046 * Create a packed DIB from the Pixmap wrapper bitmap created above.
5047 * A packed DIB contains a BITMAPINFO structure followed immediately by
5048 * an optional color palette and the pixel data.
5050 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
5052 /* we can now get rid of the HBITMAP and its original pixmap */
5053 physBitmap
->pixmap
= orig_pixmap
;
5056 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
5061 /**************************************************************************
5062 * X11DRV_DIB_CreatePixmapFromDIB
5064 * Creates a Pixmap from a packed DIB
5066 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
5069 X_PHYSBITMAP
*physBitmap
;
5073 /* Create a DDB from the DIB */
5075 pbmi
= GlobalLock(hPackedDIB
);
5076 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
5077 (LPBYTE
)pbmi
+ bitmap_info_size( pbmi
, DIB_RGB_COLORS
),
5078 pbmi
, DIB_RGB_COLORS
);
5079 GlobalUnlock(hPackedDIB
);
5081 /* clear the physBitmap so that we can steal its pixmap */
5082 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
5083 pixmap
= physBitmap
->pixmap
;
5084 physBitmap
->pixmap
= 0;
5086 /* Delete the DDB we created earlier now that we have stolen its pixmap */
5089 TRACE("Returning Pixmap %lx\n", pixmap
);