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
;
88 enum x11drv_shm_mode shm_mode
;
91 X_PHYSBITMAP
*physBitmap
;
92 } X11DRV_DIB_IMAGEBITS_DESCR
;
97 RLE_EOL
= 0, /* End of line */
98 RLE_END
= 1, /* End of bitmap */
99 RLE_DELTA
= 2 /* Delta */
103 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*,INT
);
106 Some of the following helper functions are duplicated in
110 /***********************************************************************
111 * DIB_DoProtectDIBSection
113 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP
*physBitmap
, DWORD new_prot
)
117 VirtualProtect(physBitmap
->base
, physBitmap
->size
, new_prot
, &old_prot
);
118 TRACE("Changed protection from %d to %d\n", old_prot
, new_prot
);
121 /***********************************************************************
122 * X11DRV_DIB_GetXImageWidthBytes
124 * Return the width of an X image in bytes
126 static inline int X11DRV_DIB_GetXImageWidthBytes( int width
, int depth
)
128 if (!depth
|| depth
> 32) goto error
;
130 if (!ximageDepthTable
[depth
-1])
132 XImage
*testimage
= XCreateImage( gdi_display
, visual
, depth
,
133 ZPixmap
, 0, NULL
, 1, 1, 32, 20 );
136 ximageDepthTable
[depth
-1] = testimage
->bits_per_pixel
;
137 XDestroyImage( testimage
);
139 else ximageDepthTable
[depth
-1] = -1;
141 if (ximageDepthTable
[depth
-1] != -1)
142 return (4 * ((width
* ximageDepthTable
[depth
-1] + 31) / 32));
145 WARN( "(%d): Unsupported depth\n", depth
);
150 /***********************************************************************
151 * X11DRV_DIB_GetDIBWidthBytes
153 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
155 static int X11DRV_DIB_GetDIBWidthBytes( int width
, int depth
)
157 return ((width
* depth
+ 31) / 8) & ~3;
161 /***********************************************************************
164 * Return the size of the bitmap info structure including color table.
166 int bitmap_info_size( const BITMAPINFO
* info
, WORD coloruse
)
168 unsigned int colors
, size
, masks
= 0;
170 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
172 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
173 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
174 return sizeof(BITMAPCOREHEADER
) + colors
*
175 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
177 else /* assume BITMAPINFOHEADER */
179 colors
= info
->bmiHeader
.biClrUsed
;
180 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
181 colors
= 1 << info
->bmiHeader
.biBitCount
;
182 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
183 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
184 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
189 /***********************************************************************
190 * X11DRV_DIB_CreateXImage
194 XImage
*X11DRV_DIB_CreateXImage( int width
, int height
, int depth
)
197 XImage
*image
= NULL
;
201 width_bytes
= X11DRV_DIB_GetXImageWidthBytes( width
, depth
);
202 data
= HeapAlloc( GetProcessHeap(), 0, height
* width_bytes
);
203 if (data
) image
= XCreateImage( gdi_display
, visual
, depth
, ZPixmap
, 0,
204 data
, width
, height
, 32, width_bytes
);
205 if (!image
) HeapFree( GetProcessHeap(), 0, data
);
211 /***********************************************************************
212 * X11DRV_DIB_DestroyXImage
214 * Destroy an X image created with X11DRV_DIB_CreateXImage.
216 void X11DRV_DIB_DestroyXImage( XImage
*image
)
218 HeapFree( GetProcessHeap(), 0, image
->data
);
221 XDestroyImage( image
);
226 /***********************************************************************
227 * X11DRV_DIB_GetColorCount
229 * Computes the number of colors for the bitmap palette.
230 * Should not be called for a >8-bit deep bitmap.
232 static unsigned int X11DRV_DIB_GetColorCount(const BITMAPINFO
*info
)
234 unsigned int colors
= min( info
->bmiHeader
.biClrUsed
, 256 );
235 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
240 static inline BOOL
colour_is_brighter(RGBQUAD c1
, RGBQUAD c2
)
242 return (c1
.rgbRed
* c1
.rgbRed
+ c1
.rgbGreen
* c1
.rgbGreen
+ c1
.rgbBlue
* c1
.rgbBlue
) >
243 (c2
.rgbRed
* c2
.rgbRed
+ c2
.rgbGreen
* c2
.rgbGreen
+ c2
.rgbBlue
* c2
.rgbBlue
);
246 /***********************************************************************
247 * X11DRV_DIB_GenColorMap
249 * Fills the color map of a bitmap palette. Should not be called
250 * for a >8-bit deep bitmap.
252 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE
*physDev
, int *colorMapping
,
253 WORD coloruse
, WORD depth
, const void *colorPtr
, int start
, int end
)
257 if (coloruse
== DIB_RGB_COLORS
)
259 const RGBQUAD
* rgb
= colorPtr
;
261 if (depth
== 1) /* Monochrome */
266 if (GetDIBColorTable( physDev
->dev
.hdc
, 0, 2, table
) == 2)
267 invert
= !colour_is_brighter(table
[1], table
[0]);
269 for (i
= start
; i
< end
; i
++, rgb
++)
270 colorMapping
[i
] = ((rgb
->rgbRed
+ rgb
->rgbGreen
+
271 rgb
->rgbBlue
> 255*3/2 && !invert
) ||
272 (rgb
->rgbRed
+ rgb
->rgbGreen
+
273 rgb
->rgbBlue
<= 255*3/2 && invert
));
276 for (i
= start
; i
< end
; i
++, rgb
++)
277 colorMapping
[i
] = X11DRV_PALETTE_LookupPixel(physDev
->color_shifts
, RGB(rgb
->rgbRed
,
281 else /* DIB_PAL_COLORS */
283 const WORD
* index
= colorPtr
;
285 for (i
= start
; i
< end
; i
++, index
++)
286 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(*index
) );
292 /***********************************************************************
293 * X11DRV_DIB_BuildColorMap
295 * Build the color map from the bitmap palette. Should not be called
296 * for a >8-bit deep bitmap.
298 static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
299 const BITMAPINFO
*info
, int *nColors
)
301 const void *colorPtr
;
305 *nColors
= X11DRV_DIB_GetColorCount(info
);
306 if (!*nColors
) return NULL
;
308 colorPtr
= (const BYTE
*)info
+ (WORD
)info
->bmiHeader
.biSize
;
309 if (!(colorMapping
= HeapAlloc(GetProcessHeap(), 0, *nColors
* sizeof(int) )))
312 return X11DRV_DIB_GenColorMap( physDev
, colorMapping
, coloruse
, depth
,
313 colorPtr
, 0, *nColors
);
316 /***********************************************************************
317 * X11DRV_DIB_MapColor
319 static int X11DRV_DIB_MapColor( int *physMap
, int nPhysMap
, int phys
, int oldcol
)
323 if ((oldcol
< nPhysMap
) && (physMap
[oldcol
] == phys
))
326 for (color
= 0; color
< nPhysMap
; color
++)
327 if (physMap
[color
] == phys
)
330 WARN("Strange color %08x\n", phys
);
335 /*********************************************************************
336 * X11DRV_DIB_GetNearestIndex
338 * Helper for X11DRV_DIB_GetDIBits.
339 * Returns the nearest colour table index for a given RGB.
340 * Nearest is defined by minimizing the sum of the squares.
342 static INT
X11DRV_DIB_GetNearestIndex(RGBQUAD
*colormap
, int numColors
, BYTE r
, BYTE g
, BYTE b
)
344 INT i
, best
= -1, diff
, bestdiff
= -1;
347 for(color
= colormap
, i
= 0; i
< numColors
; color
++, i
++) {
348 diff
= (r
- color
->rgbRed
) * (r
- color
->rgbRed
) +
349 (g
- color
->rgbGreen
) * (g
- color
->rgbGreen
) +
350 (b
- color
->rgbBlue
) * (b
- color
->rgbBlue
);
353 if(best
== -1 || diff
< bestdiff
) {
360 /*********************************************************************
361 * X11DRV_DIB_MaskToShift
363 * Helper for X11DRV_DIB_GetDIBits.
364 * Returns the by how many bits to shift a given color so that it is
365 * in the proper position.
367 INT
X11DRV_DIB_MaskToShift(DWORD mask
)
375 while ((mask
&1)==0) {
382 /***********************************************************************
383 * X11DRV_DIB_CheckMask
385 * Check RGB mask if it is either 0 or matches visual's mask.
387 static inline int X11DRV_DIB_CheckMask(int red_mask
, int green_mask
, int blue_mask
)
389 return ( red_mask
== 0 && green_mask
== 0 && blue_mask
== 0 ) ||
390 ( red_mask
== visual
->red_mask
&& green_mask
== visual
->green_mask
&&
391 blue_mask
== visual
->blue_mask
);
394 /***********************************************************************
395 * X11DRV_DIB_SetImageBits_1
397 * SetDIBits for a 1-bit deep DIB.
399 static void X11DRV_DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
400 DWORD srcwidth
, DWORD dstwidth
, int left
,
401 int *colors
, XImage
*bmpImage
, int linebytes
)
410 srcbits
= srcbits
+ linebytes
* (lines
- 1);
411 linebytes
= -linebytes
;
414 if ((extra
= (left
& 7)) != 0) {
418 srcbits
+= left
>> 3;
419 width
= min(srcwidth
, dstwidth
);
421 /* ==== pal 1 dib -> any bmp format ==== */
422 for (h
= lines
-1; h
>=0; h
--) {
424 for (i
= width
/8, x
= left
; i
> 0; i
--) {
426 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
427 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
428 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
429 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
430 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
431 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
432 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
433 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
439 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
441 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
443 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
445 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
447 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
449 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
451 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
454 srcbits
+= linebytes
;
458 /***********************************************************************
459 * X11DRV_DIB_GetImageBits_1
461 * GetDIBits for a 1-bit deep DIB.
463 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
464 DWORD dstwidth
, DWORD srcwidth
,
465 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
466 XImage
*bmpImage
, int linebytes
)
469 int h
, width
= min(dstwidth
, srcwidth
);
473 dstbits
= dstbits
+ linebytes
* (lines
- 1);
474 linebytes
= -linebytes
;
477 switch (bmpImage
->depth
)
481 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
483 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
486 for (h
=lines
-1; h
>=0; h
--) {
490 for (x
=0; x
<width
; x
++) {
492 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
493 dstval
|=(X11DRV_DIB_GetNearestIndex
497 srcval
.peBlue
) << (7 - (x
& 7)));
506 /* pad with 0 to DWORD alignment */
507 for (x
= (x
+7)&~7; x
< ((width
+ 31) & ~31); x
+=8)
509 dstbits
+= linebytes
;
517 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
, bmpImage
->green_mask
, bmpImage
->blue_mask
)
519 /* ==== pal 8 bmp -> pal 1 dib ==== */
521 const BYTE
* srcpixel
;
524 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
526 for (h
=0; h
<lines
; h
++) {
531 for (x
=0; x
<width
; x
++) {
533 srcval
=srccolors
[*srcpixel
++];
534 dstval
|=(X11DRV_DIB_GetNearestIndex
538 srcval
.peBlue
) << (7-(x
&7)) );
547 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
548 dstbits
+= linebytes
;
559 const WORD
* srcpixel
;
562 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
564 if (bmpImage
->green_mask
==0x03e0) {
565 if (bmpImage
->red_mask
==0x7c00) {
566 /* ==== rgb 555 bmp -> pal 1 dib ==== */
567 for (h
=0; h
<lines
; h
++) {
572 for (x
=0; x
<width
; x
++) {
575 dstval
|=(X11DRV_DIB_GetNearestIndex
577 ((srcval
>> 7) & 0xf8) | /* r */
578 ((srcval
>> 12) & 0x07),
579 ((srcval
>> 2) & 0xf8) | /* g */
580 ((srcval
>> 7) & 0x07),
581 ((srcval
<< 3) & 0xf8) | /* b */
582 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
591 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
592 dstbits
+= linebytes
;
594 } else if (bmpImage
->blue_mask
==0x7c00) {
595 /* ==== bgr 555 bmp -> pal 1 dib ==== */
596 for (h
=0; h
<lines
; h
++) {
601 for (x
=0; x
<width
; x
++) {
605 dstval
|=(X11DRV_DIB_GetNearestIndex
607 ((srcval
<< 3) & 0xf8) | /* r */
608 ((srcval
>> 2) & 0x07),
609 ((srcval
>> 2) & 0xf8) | /* g */
610 ((srcval
>> 7) & 0x07),
611 ((srcval
>> 7) & 0xf8) | /* b */
612 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
621 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
622 dstbits
+= linebytes
;
627 } else if (bmpImage
->green_mask
==0x07e0) {
628 if (bmpImage
->red_mask
==0xf800) {
629 /* ==== rgb 565 bmp -> pal 1 dib ==== */
630 for (h
=0; h
<lines
; h
++) {
635 for (x
=0; x
<width
; x
++) {
638 dstval
|=(X11DRV_DIB_GetNearestIndex
640 ((srcval
>> 8) & 0xf8) | /* r */
641 ((srcval
>> 13) & 0x07),
642 ((srcval
>> 3) & 0xfc) | /* g */
643 ((srcval
>> 9) & 0x03),
644 ((srcval
<< 3) & 0xf8) | /* b */
645 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
654 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
655 dstbits
+= linebytes
;
657 } else if (bmpImage
->blue_mask
==0xf800) {
658 /* ==== bgr 565 bmp -> pal 1 dib ==== */
659 for (h
=0; h
<lines
; h
++) {
664 for (x
=0; x
<width
; x
++) {
667 dstval
|=(X11DRV_DIB_GetNearestIndex
669 ((srcval
<< 3) & 0xf8) | /* r */
670 ((srcval
>> 2) & 0x07),
671 ((srcval
>> 3) & 0xfc) | /* g */
672 ((srcval
>> 9) & 0x03),
673 ((srcval
>> 8) & 0xf8) | /* b */
674 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
683 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
684 dstbits
+= linebytes
;
703 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
704 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
706 if (bmpImage
->green_mask
!=0x00ff00 ||
707 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
709 } else if (bmpImage
->blue_mask
==0xff) {
710 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
711 for (h
=0; h
<lines
; h
++) {
716 for (x
=0; x
<width
; x
++) {
717 dstval
|=(X11DRV_DIB_GetNearestIndex
721 srcbyte
[0]) << (7-(x
&7)) );
722 srcbyte
+=bytes_per_pixel
;
731 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
732 dstbits
+= linebytes
;
735 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
736 for (h
=0; h
<lines
; h
++) {
741 for (x
=0; x
<width
; x
++) {
742 dstval
|=(X11DRV_DIB_GetNearestIndex
746 srcbyte
[2]) << (7-(x
&7)) );
747 srcbyte
+=bytes_per_pixel
;
756 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
757 dstbits
+= linebytes
;
768 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
770 /* ==== any bmp format -> pal 1 dib ==== */
771 if ((unsigned)colors
[0].rgbRed
+colors
[0].rgbGreen
+colors
[0].rgbBlue
>=
772 (unsigned)colors
[1].rgbRed
+colors
[1].rgbGreen
+colors
[1].rgbBlue
)
775 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
776 "%s color mapping\n",
777 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
778 bmpImage
->green_mask
, bmpImage
->blue_mask
,
779 neg
?"negative":"direct" );
781 for (h
=lines
-1; h
>=0; h
--) {
785 for (x
=0; x
<width
; x
++) {
786 dstval
|=((XGetPixel( bmpImage
, x
, h
) >= white
) ^ neg
) << (7 - (x
&7));
795 dstbits
+= linebytes
;
802 /***********************************************************************
803 * X11DRV_DIB_SetImageBits_4
805 * SetDIBits for a 4-bit deep DIB.
807 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
808 DWORD srcwidth
, DWORD dstwidth
, int left
,
809 int *colors
, XImage
*bmpImage
, int linebytes
)
817 srcbits
= srcbits
+ linebytes
* (lines
- 1);
818 linebytes
= -linebytes
;
825 srcbits
+= left
>> 1;
826 width
= min(srcwidth
, dstwidth
);
828 /* ==== pal 4 dib -> any bmp format ==== */
829 for (h
= lines
-1; h
>= 0; h
--) {
831 for (i
= width
/2, x
= left
; i
> 0; i
--) {
832 BYTE srcval
=*srcbyte
++;
833 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
834 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
837 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
838 srcbits
+= linebytes
;
844 /***********************************************************************
845 * X11DRV_DIB_GetImageBits_4
847 * GetDIBits for a 4-bit deep DIB.
849 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
850 DWORD srcwidth
, DWORD dstwidth
,
851 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
852 XImage
*bmpImage
, int linebytes
)
855 int h
, width
= min(srcwidth
, dstwidth
);
860 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
861 linebytes
= -linebytes
;
864 switch (bmpImage
->depth
) {
867 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
869 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
872 for (h
= lines
-1; h
>= 0; h
--) {
876 for (x
= 0; x
< width
; x
++) {
878 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
879 dstval
|=(X11DRV_DIB_GetNearestIndex
883 srcval
.peBlue
) << (4-((x
&1)<<2)));
892 dstbits
+= linebytes
;
900 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
902 /* ==== pal 8 bmp -> pal 4 dib ==== */
904 const BYTE
*srcpixel
;
907 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
908 for (h
=0; h
<lines
; h
++) {
913 for (x
=0; x
<width
; x
++) {
915 srcval
= srccolors
[*srcpixel
++];
916 dstval
|=(X11DRV_DIB_GetNearestIndex
920 srcval
.peBlue
) << (4*(1-(x
&1))) );
929 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
930 dstbits
+= linebytes
;
941 const WORD
* srcpixel
;
944 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
946 if (bmpImage
->green_mask
==0x03e0) {
947 if (bmpImage
->red_mask
==0x7c00) {
948 /* ==== rgb 555 bmp -> pal 4 dib ==== */
949 for (h
=0; h
<lines
; h
++) {
954 for (x
=0; x
<width
; x
++) {
957 dstval
|=(X11DRV_DIB_GetNearestIndex
959 ((srcval
>> 7) & 0xf8) | /* r */
960 ((srcval
>> 12) & 0x07),
961 ((srcval
>> 2) & 0xf8) | /* g */
962 ((srcval
>> 7) & 0x07),
963 ((srcval
<< 3) & 0xf8) | /* b */
964 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
973 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
974 dstbits
+= linebytes
;
976 } else if (bmpImage
->blue_mask
==0x7c00) {
977 /* ==== bgr 555 bmp -> pal 4 dib ==== */
978 for (h
=0; h
<lines
; h
++) {
983 for (x
=0; x
<width
; x
++) {
986 dstval
|=(X11DRV_DIB_GetNearestIndex
988 ((srcval
<< 3) & 0xf8) | /* r */
989 ((srcval
>> 2) & 0x07),
990 ((srcval
>> 2) & 0xf8) | /* g */
991 ((srcval
>> 7) & 0x07),
992 ((srcval
>> 7) & 0xf8) | /* b */
993 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1002 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1003 dstbits
+= linebytes
;
1008 } else if (bmpImage
->green_mask
==0x07e0) {
1009 if (bmpImage
->red_mask
==0xf800) {
1010 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1011 for (h
=0; h
<lines
; h
++) {
1016 for (x
=0; x
<width
; x
++) {
1019 dstval
|=(X11DRV_DIB_GetNearestIndex
1021 ((srcval
>> 8) & 0xf8) | /* r */
1022 ((srcval
>> 13) & 0x07),
1023 ((srcval
>> 3) & 0xfc) | /* g */
1024 ((srcval
>> 9) & 0x03),
1025 ((srcval
<< 3) & 0xf8) | /* b */
1026 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1035 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1036 dstbits
+= linebytes
;
1038 } else if (bmpImage
->blue_mask
==0xf800) {
1039 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1040 for (h
=0; h
<lines
; h
++) {
1045 for (x
=0; x
<width
; x
++) {
1048 dstval
|=(X11DRV_DIB_GetNearestIndex
1050 ((srcval
<< 3) & 0xf8) | /* r */
1051 ((srcval
>> 2) & 0x07),
1052 ((srcval
>> 3) & 0xfc) | /* g */
1053 ((srcval
>> 9) & 0x03),
1054 ((srcval
>> 8) & 0xf8) | /* b */
1055 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1064 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1065 dstbits
+= linebytes
;
1077 if (bmpImage
->bits_per_pixel
==24) {
1078 const void* srcbits
;
1079 const BYTE
*srcbyte
;
1082 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1084 if (bmpImage
->green_mask
!=0x00ff00 ||
1085 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1087 } else if (bmpImage
->blue_mask
==0xff) {
1088 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1089 for (h
=0; h
<lines
; h
++) {
1092 for (x
=0; x
<width
/2; x
++) {
1093 /* Do 2 pixels at a time */
1094 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1099 X11DRV_DIB_GetNearestIndex
1107 /* And then the odd pixel */
1108 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1114 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1115 dstbits
+= linebytes
;
1118 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1119 for (h
=0; h
<lines
; h
++) {
1122 for (x
=0; x
<width
/2; x
++) {
1123 /* Do 2 pixels at a time */
1124 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1129 X11DRV_DIB_GetNearestIndex
1137 /* And then the odd pixel */
1138 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1144 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1145 dstbits
+= linebytes
;
1154 const void* srcbits
;
1155 const BYTE
*srcbyte
;
1158 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1160 if (bmpImage
->green_mask
!=0x00ff00 ||
1161 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1163 } else if (bmpImage
->blue_mask
==0xff) {
1164 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1165 for (h
=0; h
<lines
; h
++) {
1168 for (x
=0; x
<width
/2; x
++) {
1169 /* Do 2 pixels at a time */
1170 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1175 X11DRV_DIB_GetNearestIndex
1183 /* And then the odd pixel */
1184 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1190 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1191 dstbits
+= linebytes
;
1194 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1195 for (h
=0; h
<lines
; h
++) {
1198 for (x
=0; x
<width
/2; x
++) {
1199 /* Do 2 pixels at a time */
1200 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1205 X11DRV_DIB_GetNearestIndex
1213 /* And then the odd pixel */
1214 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1220 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1221 dstbits
+= linebytes
;
1232 /* ==== any bmp format -> pal 4 dib ==== */
1233 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1234 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1235 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1236 for (h
=lines
-1; h
>=0; h
--) {
1238 for (x
=0; x
<(width
& ~1); x
+=2) {
1239 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1240 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1243 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1245 dstbits
+= linebytes
;
1252 /***********************************************************************
1253 * X11DRV_DIB_SetImageBits_8
1255 * SetDIBits for an 8-bit deep DIB.
1257 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1258 DWORD srcwidth
, DWORD dstwidth
, int left
,
1259 const int *colors
, XImage
*bmpImage
,
1263 int h
, width
= min(srcwidth
, dstwidth
);
1264 const BYTE
* srcbyte
;
1270 srcbits
= srcbits
+ linebytes
* (lines
-1);
1271 linebytes
= -linebytes
;
1276 switch (bmpImage
->depth
) {
1279 /* Some X servers might have 32 bit/ 16bit deep pixel */
1280 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1281 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1283 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1284 dstbits
=(BYTE
*)bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1285 for (h
= lines
; h
--; ) {
1286 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1287 for (x
=0; x
<width
/2; x
++) {
1288 /* Do 2 pixels at a time */
1289 *dstpixel
++=(colors
[srcbyte
[1]] << 16) | colors
[srcbyte
[0]];
1293 /* And then the odd pixel */
1294 *((WORD
*)dstpixel
)=colors
[srcbyte
[0]];
1296 srcbyte
= (srcbits
+= linebytes
);
1297 dstbits
-= bmpImage
->bytes_per_line
;
1304 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1305 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1307 dstbits
=(BYTE
*)bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1308 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1309 for (h
= lines
; h
--; ) {
1310 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1311 for (x
=0; x
<width
; x
++) {
1312 *dstpixel
++=colors
[*srcbyte
++];
1314 srcbyte
= (srcbits
+= linebytes
);
1315 dstbits
-= bmpImage
->bytes_per_line
;
1321 break; /* use slow generic case below */
1324 /* ==== pal 8 dib -> any bmp format ==== */
1325 for (h
=lines
-1; h
>=0; h
--) {
1326 for (x
=left
; x
<width
+left
; x
++) {
1327 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1329 srcbyte
= (srcbits
+= linebytes
);
1333 /***********************************************************************
1334 * X11DRV_DIB_GetImageBits_8
1336 * GetDIBits for an 8-bit deep DIB.
1338 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1339 DWORD srcwidth
, DWORD dstwidth
,
1340 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1341 XImage
*bmpImage
, int linebytes
)
1344 int h
, width
= min(srcwidth
, dstwidth
);
1350 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1351 linebytes
= -linebytes
;
1356 * This condition is true when GetImageBits has been called by
1357 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1358 * 256 colormaps, so we'll just use it for GetDIBits calls.
1359 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1361 if (!srccolors
) goto updatesection
;
1363 switch (bmpImage
->depth
) {
1366 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1369 /* ==== pal 1 bmp -> pal 8 dib ==== */
1370 /* ==== pal 4 bmp -> pal 8 dib ==== */
1371 for (h
=lines
-1; h
>=0; h
--) {
1373 for (x
=0; x
<width
; x
++) {
1374 PALETTEENTRY srcval
;
1375 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1376 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1381 dstbits
+= linebytes
;
1389 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1391 /* ==== pal 8 bmp -> pal 8 dib ==== */
1392 const void* srcbits
;
1393 const BYTE
* srcpixel
;
1395 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1396 for (h
=0; h
<lines
; h
++) {
1399 for (x
= 0; x
< width
; x
++) {
1400 PALETTEENTRY srcval
;
1401 srcval
=srccolors
[*srcpixel
++];
1402 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1407 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1408 dstbits
+= linebytes
;
1418 const void* srcbits
;
1419 const WORD
* srcpixel
;
1422 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1424 if (bmpImage
->green_mask
==0x03e0) {
1425 if (bmpImage
->red_mask
==0x7c00) {
1426 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1427 for (h
=0; h
<lines
; h
++) {
1430 for (x
=0; x
<width
; x
++) {
1433 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1435 ((srcval
>> 7) & 0xf8) | /* r */
1436 ((srcval
>> 12) & 0x07),
1437 ((srcval
>> 2) & 0xf8) | /* g */
1438 ((srcval
>> 7) & 0x07),
1439 ((srcval
<< 3) & 0xf8) | /* b */
1440 ((srcval
>> 2) & 0x07) );
1442 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1443 dstbits
+= linebytes
;
1445 } else if (bmpImage
->blue_mask
==0x7c00) {
1446 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1447 for (h
=0; h
<lines
; h
++) {
1450 for (x
=0; x
<width
; x
++) {
1453 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1455 ((srcval
<< 3) & 0xf8) | /* r */
1456 ((srcval
>> 2) & 0x07),
1457 ((srcval
>> 2) & 0xf8) | /* g */
1458 ((srcval
>> 7) & 0x07),
1459 ((srcval
>> 7) & 0xf8) | /* b */
1460 ((srcval
>> 12) & 0x07) );
1462 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1463 dstbits
+= linebytes
;
1468 } else if (bmpImage
->green_mask
==0x07e0) {
1469 if (bmpImage
->red_mask
==0xf800) {
1470 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1471 for (h
=0; h
<lines
; h
++) {
1474 for (x
=0; x
<width
; x
++) {
1477 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1479 ((srcval
>> 8) & 0xf8) | /* r */
1480 ((srcval
>> 13) & 0x07),
1481 ((srcval
>> 3) & 0xfc) | /* g */
1482 ((srcval
>> 9) & 0x03),
1483 ((srcval
<< 3) & 0xf8) | /* b */
1484 ((srcval
>> 2) & 0x07) );
1486 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1487 dstbits
+= linebytes
;
1489 } else if (bmpImage
->blue_mask
==0xf800) {
1490 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1491 for (h
=0; h
<lines
; h
++) {
1494 for (x
=0; x
<width
; x
++) {
1497 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1499 ((srcval
<< 3) & 0xf8) | /* r */
1500 ((srcval
>> 2) & 0x07),
1501 ((srcval
>> 3) & 0xfc) | /* g */
1502 ((srcval
>> 9) & 0x03),
1503 ((srcval
>> 8) & 0xf8) | /* b */
1504 ((srcval
>> 13) & 0x07) );
1506 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1507 dstbits
+= linebytes
;
1521 const void* srcbits
;
1522 const BYTE
*srcbyte
;
1524 int bytes_per_pixel
;
1526 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1527 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1529 if (bmpImage
->green_mask
!=0x00ff00 ||
1530 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1532 } else if (bmpImage
->blue_mask
==0xff) {
1533 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1534 for (h
=0; h
<lines
; h
++) {
1537 for (x
=0; x
<width
; x
++) {
1538 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1543 srcbyte
+=bytes_per_pixel
;
1545 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1546 dstbits
+= linebytes
;
1549 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1550 for (h
=0; h
<lines
; h
++) {
1553 for (x
=0; x
<width
; x
++) {
1554 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1559 srcbyte
+=bytes_per_pixel
;
1561 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1562 dstbits
+= linebytes
;
1570 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1571 bmpImage
->depth
, bmpImage
->red_mask
,
1572 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1574 /* ==== any bmp format -> pal 8 dib ==== */
1575 for (h
=lines
-1; h
>=0; h
--) {
1577 for (x
=0; x
<width
; x
++) {
1578 *dstbyte
=X11DRV_DIB_MapColor
1580 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1583 dstbits
+= linebytes
;
1589 /***********************************************************************
1590 * X11DRV_DIB_SetImageBits_16
1592 * SetDIBits for a 16-bit deep DIB.
1594 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1595 DWORD srcwidth
, DWORD dstwidth
, int left
,
1596 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1597 XImage
*bmpImage
, int linebytes
)
1600 int h
, width
= min(srcwidth
, dstwidth
);
1601 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1606 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1607 linebytes
= -linebytes
;
1610 switch (bmpImage
->depth
)
1617 srcbits
=srcbits
+left
*2;
1618 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1620 if (bmpImage
->green_mask
==0x03e0) {
1621 if (gSrc
==bmpImage
->green_mask
) {
1622 if (rSrc
==bmpImage
->red_mask
) {
1623 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1624 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1625 convs
->Convert_5x5_asis
1628 dstbits
,-bmpImage
->bytes_per_line
);
1629 } else if (rSrc
==bmpImage
->blue_mask
) {
1630 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1631 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1632 convs
->Convert_555_reverse
1635 dstbits
,-bmpImage
->bytes_per_line
);
1638 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1639 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1640 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1641 convs
->Convert_565_to_555_asis
1644 dstbits
,-bmpImage
->bytes_per_line
);
1646 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1647 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1648 convs
->Convert_565_to_555_reverse
1651 dstbits
,-bmpImage
->bytes_per_line
);
1654 } else if (bmpImage
->green_mask
==0x07e0) {
1655 if (gSrc
==bmpImage
->green_mask
) {
1656 if (rSrc
==bmpImage
->red_mask
) {
1657 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
1658 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
1659 convs
->Convert_5x5_asis
1662 dstbits
,-bmpImage
->bytes_per_line
);
1664 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
1665 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
1666 convs
->Convert_565_reverse
1669 dstbits
,-bmpImage
->bytes_per_line
);
1672 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1673 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
1674 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
1675 convs
->Convert_555_to_565_asis
1678 dstbits
,-bmpImage
->bytes_per_line
);
1680 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
1681 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
1682 convs
->Convert_555_to_565_reverse
1685 dstbits
,-bmpImage
->bytes_per_line
);
1695 if (bmpImage
->bits_per_pixel
==24) {
1698 srcbits
=srcbits
+left
*2;
1699 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
1701 if (bmpImage
->green_mask
!=0x00ff00 ||
1702 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1704 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
1705 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
1707 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
1708 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
1709 convs
->Convert_555_to_888_asis
1712 dstbits
,-bmpImage
->bytes_per_line
);
1714 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
1715 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
1716 convs
->Convert_565_to_888_asis
1719 dstbits
,-bmpImage
->bytes_per_line
);
1723 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
1724 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
1725 convs
->Convert_555_to_888_reverse
1728 dstbits
,-bmpImage
->bytes_per_line
);
1730 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
1731 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
1732 convs
->Convert_565_to_888_reverse
1735 dstbits
,-bmpImage
->bytes_per_line
);
1746 srcbits
=srcbits
+left
*2;
1747 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1749 if (bmpImage
->green_mask
!=0x00ff00 ||
1750 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1752 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
1753 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
1755 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
1756 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
1757 convs
->Convert_555_to_0888_asis
1760 dstbits
,-bmpImage
->bytes_per_line
);
1762 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
1763 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
1764 convs
->Convert_565_to_0888_asis
1767 dstbits
,-bmpImage
->bytes_per_line
);
1771 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
1772 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
1773 convs
->Convert_555_to_0888_reverse
1776 dstbits
,-bmpImage
->bytes_per_line
);
1778 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
1779 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
1780 convs
->Convert_565_to_0888_reverse
1783 dstbits
,-bmpImage
->bytes_per_line
);
1791 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
1792 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1793 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1799 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
1800 const WORD
* srcpixel
;
1801 int rShift1
,gShift1
,bShift1
;
1802 int rShift2
,gShift2
,bShift2
;
1805 /* Set color scaling values */
1806 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
1807 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
1808 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
1813 /* Green has 5 bits, like the others */
1817 /* Green has 6 bits, not 5. Compensate. */
1826 /* We could split it into four separate cases to optimize
1827 * but it is probably not worth it.
1829 for (h
=lines
-1; h
>=0; h
--) {
1830 srcpixel
=(const WORD
*)srcbits
;
1831 for (x
=left
; x
<width
+left
; x
++) {
1833 BYTE red
,green
,blue
;
1834 srcval
=*srcpixel
++ << 16;
1835 red
= ((srcval
>> rShift1
) & 0xf8) |
1836 ((srcval
>> rShift2
) & 0x07);
1837 green
=((srcval
>> gShift1
) & gMask1
) |
1838 ((srcval
>> gShift2
) & gMask2
);
1839 blue
= ((srcval
>> bShift1
) & 0xf8) |
1840 ((srcval
>> bShift2
) & 0x07);
1841 XPutPixel(bmpImage
, x
, h
,
1842 X11DRV_PALETTE_ToPhysical
1843 (physDev
, RGB(red
,green
,blue
)));
1845 srcbits
+= linebytes
;
1853 /***********************************************************************
1854 * X11DRV_DIB_GetImageBits_16
1856 * GetDIBits for an 16-bit deep DIB.
1858 static void X11DRV_DIB_GetImageBits_16( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
1859 DWORD dstwidth
, DWORD srcwidth
,
1860 PALETTEENTRY
*srccolors
,
1861 DWORD rDst
, DWORD gDst
, DWORD bDst
,
1862 XImage
*bmpImage
, int linebytes
)
1865 int h
, width
= min(srcwidth
, dstwidth
);
1866 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
1871 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
1872 linebytes
= -linebytes
;
1875 switch (bmpImage
->depth
)
1880 const char* srcbits
;
1882 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1884 if (bmpImage
->green_mask
==0x03e0) {
1885 if (gDst
==bmpImage
->green_mask
) {
1886 if (rDst
==bmpImage
->red_mask
) {
1887 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
1888 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
1889 convs
->Convert_5x5_asis
1891 srcbits
,-bmpImage
->bytes_per_line
,
1894 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
1895 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
1896 convs
->Convert_555_reverse
1898 srcbits
,-bmpImage
->bytes_per_line
,
1902 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
1903 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
1904 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
1905 convs
->Convert_555_to_565_asis
1907 srcbits
,-bmpImage
->bytes_per_line
,
1910 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
1911 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
1912 convs
->Convert_555_to_565_reverse
1914 srcbits
,-bmpImage
->bytes_per_line
,
1918 } else if (bmpImage
->green_mask
==0x07e0) {
1919 if (gDst
==bmpImage
->green_mask
) {
1920 if (rDst
== bmpImage
->red_mask
) {
1921 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
1922 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
1923 convs
->Convert_5x5_asis
1925 srcbits
,-bmpImage
->bytes_per_line
,
1928 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
1929 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
1930 convs
->Convert_565_reverse
1932 srcbits
,-bmpImage
->bytes_per_line
,
1936 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
1937 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
1938 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
1939 convs
->Convert_565_to_555_asis
1941 srcbits
,-bmpImage
->bytes_per_line
,
1944 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
1945 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
1946 convs
->Convert_565_to_555_reverse
1948 srcbits
,-bmpImage
->bytes_per_line
,
1959 if (bmpImage
->bits_per_pixel
== 24) {
1960 const char* srcbits
;
1962 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1964 if (bmpImage
->green_mask
!=0x00ff00 ||
1965 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1967 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
1968 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
1970 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
1971 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
1972 convs
->Convert_888_to_555_asis
1974 srcbits
,-bmpImage
->bytes_per_line
,
1977 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
1978 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
1979 convs
->Convert_888_to_565_asis
1981 srcbits
,-bmpImage
->bytes_per_line
,
1986 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
1987 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
1988 convs
->Convert_888_to_555_reverse
1990 srcbits
,-bmpImage
->bytes_per_line
,
1993 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
1994 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
1995 convs
->Convert_888_to_565_reverse
1997 srcbits
,-bmpImage
->bytes_per_line
,
2007 const char* srcbits
;
2009 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2011 if (bmpImage
->green_mask
!=0x00ff00 ||
2012 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2014 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2015 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2017 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2018 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2019 convs
->Convert_0888_to_555_asis
2021 srcbits
,-bmpImage
->bytes_per_line
,
2024 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2025 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2026 convs
->Convert_0888_to_565_asis
2028 srcbits
,-bmpImage
->bytes_per_line
,
2033 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2034 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2035 convs
->Convert_0888_to_555_reverse
2037 srcbits
,-bmpImage
->bytes_per_line
,
2040 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2041 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2042 convs
->Convert_0888_to_565_reverse
2044 srcbits
,-bmpImage
->bytes_per_line
,
2053 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2055 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2056 int rShift
,gShift
,bShift
;
2059 /* Shift everything 16 bits left so that all shifts are >0,
2060 * even for BGR DIBs. Then a single >> 16 will bring everything
2063 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2064 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2065 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2067 /* 6 bits for the green */
2073 for (h
= lines
- 1; h
>= 0; h
--) {
2074 dstpixel
=(LPWORD
)dstbits
;
2075 for (x
= 0; x
< width
; x
++) {
2076 PALETTEENTRY srcval
;
2078 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2079 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2080 ((srcval
.peGreen
<< gShift
) & gDst
) |
2081 ((srcval
.peBlue
<< bShift
) & bDst
);
2082 *dstpixel
++=dstval
>> 16;
2084 dstbits
+= linebytes
;
2092 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2094 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2095 int rShift
,gShift
,bShift
;
2096 const BYTE
* srcbits
;
2097 const BYTE
* srcpixel
;
2100 /* Shift everything 16 bits left so that all shifts are >0,
2101 * even for BGR DIBs. Then a single >> 16 will bring everything
2104 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2105 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2106 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2108 /* 6 bits for the green */
2114 srcbits
=(BYTE
*)bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2115 for (h
=0; h
<lines
; h
++) {
2117 dstpixel
=(LPWORD
)dstbits
;
2118 for (x
= 0; x
< width
; x
++) {
2119 PALETTEENTRY srcval
;
2121 srcval
=srccolors
[*srcpixel
++];
2122 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2123 ((srcval
.peGreen
<< gShift
) & gDst
) |
2124 ((srcval
.peBlue
<< bShift
) & bDst
);
2125 *dstpixel
++=dstval
>> 16;
2127 srcbits
-= bmpImage
->bytes_per_line
;
2128 dstbits
+= linebytes
;
2138 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2139 int rShift
,gShift
,bShift
;
2142 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2143 bmpImage
->depth
, bmpImage
->red_mask
,
2144 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2147 /* Shift everything 16 bits left so that all shifts are >0,
2148 * even for BGR DIBs. Then a single >> 16 will bring everything
2151 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2152 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2153 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2155 /* 6 bits for the green */
2161 for (h
= lines
- 1; h
>= 0; h
--) {
2162 dstpixel
=(LPWORD
)dstbits
;
2163 for (x
= 0; x
< width
; x
++) {
2166 srcval
=X11DRV_PALETTE_ToLogical(physDev
, XGetPixel(bmpImage
, x
, h
));
2167 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2168 ((GetGValue(srcval
) << gShift
) & gDst
) |
2169 ((GetBValue(srcval
) << bShift
) & bDst
);
2170 *dstpixel
++=dstval
>> 16;
2172 dstbits
+= linebytes
;
2180 /***********************************************************************
2181 * X11DRV_DIB_SetImageBits_24
2183 * SetDIBits for a 24-bit deep DIB.
2185 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2186 DWORD srcwidth
, DWORD dstwidth
, int left
,
2187 X11DRV_PDEVICE
*physDev
,
2188 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2189 XImage
*bmpImage
, DWORD linebytes
)
2192 int h
, width
= min(srcwidth
, dstwidth
);
2193 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2198 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2199 linebytes
= -linebytes
;
2202 switch (bmpImage
->depth
)
2205 if (bmpImage
->bits_per_pixel
==24) {
2208 srcbits
=srcbits
+left
*3;
2209 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2211 if (bmpImage
->green_mask
!=0x00ff00 ||
2212 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2214 } else if (rSrc
==bmpImage
->red_mask
) {
2215 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2216 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2217 convs
->Convert_888_asis
2220 dstbits
,-bmpImage
->bytes_per_line
);
2222 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2223 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2224 convs
->Convert_888_reverse
2227 dstbits
,-bmpImage
->bytes_per_line
);
2237 srcbits
=srcbits
+left
*3;
2238 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2240 if (bmpImage
->green_mask
!=0x00ff00 ||
2241 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2243 } else if (rSrc
==bmpImage
->red_mask
) {
2244 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2245 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2246 convs
->Convert_888_to_0888_asis
2249 dstbits
,-bmpImage
->bytes_per_line
);
2251 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2252 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2253 convs
->Convert_888_to_0888_reverse
2256 dstbits
,-bmpImage
->bytes_per_line
);
2266 srcbits
=srcbits
+left
*3;
2267 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2269 if (bmpImage
->green_mask
==0x03e0) {
2270 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2271 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2272 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2273 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2274 convs
->Convert_888_to_555_asis
2277 dstbits
,-bmpImage
->bytes_per_line
);
2278 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2279 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2280 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2281 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2282 convs
->Convert_888_to_555_reverse
2285 dstbits
,-bmpImage
->bytes_per_line
);
2289 } else if (bmpImage
->green_mask
==0x07e0) {
2290 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2291 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2292 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2293 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2294 convs
->Convert_888_to_565_asis
2297 dstbits
,-bmpImage
->bytes_per_line
);
2298 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2299 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2300 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2301 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2302 convs
->Convert_888_to_565_reverse
2305 dstbits
,-bmpImage
->bytes_per_line
);
2317 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2318 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2319 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2325 /* ==== rgb 888 dib -> any bmp format ==== */
2326 const BYTE
* srcbyte
;
2328 /* Windows only supports one 24bpp DIB format: RGB888 */
2330 for (h
= lines
- 1; h
>= 0; h
--) {
2332 for (x
= left
; x
< width
+left
; x
++) {
2333 XPutPixel(bmpImage
, x
, h
,
2334 X11DRV_PALETTE_ToPhysical
2335 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2338 srcbits
+= linebytes
;
2346 /***********************************************************************
2347 * X11DRV_DIB_GetImageBits_24
2349 * GetDIBits for an 24-bit deep DIB.
2351 static void X11DRV_DIB_GetImageBits_24( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
2352 DWORD dstwidth
, DWORD srcwidth
,
2353 PALETTEENTRY
*srccolors
,
2354 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2355 XImage
*bmpImage
, DWORD linebytes
)
2358 int h
, width
= min(srcwidth
, dstwidth
);
2359 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2364 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2365 linebytes
= -linebytes
;
2368 switch (bmpImage
->depth
)
2371 if (bmpImage
->bits_per_pixel
==24) {
2372 const char* srcbits
;
2374 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2376 if (bmpImage
->green_mask
!=0x00ff00 ||
2377 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2379 } else if (rDst
==bmpImage
->red_mask
) {
2380 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2381 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2382 convs
->Convert_888_asis
2384 srcbits
,-bmpImage
->bytes_per_line
,
2387 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2388 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2389 convs
->Convert_888_reverse
2391 srcbits
,-bmpImage
->bytes_per_line
,
2400 const char* srcbits
;
2402 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2404 if (bmpImage
->green_mask
!=0x00ff00 ||
2405 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2407 } else if (rDst
==bmpImage
->red_mask
) {
2408 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2409 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2410 convs
->Convert_0888_to_888_asis
2412 srcbits
,-bmpImage
->bytes_per_line
,
2415 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2416 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2417 convs
->Convert_0888_to_888_reverse
2419 srcbits
,-bmpImage
->bytes_per_line
,
2428 const char* srcbits
;
2430 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2432 if (bmpImage
->green_mask
==0x03e0) {
2433 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2434 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2435 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2436 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2437 convs
->Convert_555_to_888_asis
2439 srcbits
,-bmpImage
->bytes_per_line
,
2441 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2442 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2443 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2444 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2445 convs
->Convert_555_to_888_reverse
2447 srcbits
,-bmpImage
->bytes_per_line
,
2452 } else if (bmpImage
->green_mask
==0x07e0) {
2453 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2454 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2455 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2456 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2457 convs
->Convert_565_to_888_asis
2459 srcbits
,-bmpImage
->bytes_per_line
,
2461 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2462 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2463 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2464 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2465 convs
->Convert_565_to_888_reverse
2467 srcbits
,-bmpImage
->bytes_per_line
,
2480 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2482 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2485 /* Windows only supports one 24bpp DIB format: rgb 888 */
2486 for (h
= lines
- 1; h
>= 0; h
--) {
2488 for (x
= 0; x
< width
; x
++) {
2489 PALETTEENTRY srcval
;
2490 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2491 dstbyte
[0]=srcval
.peBlue
;
2492 dstbyte
[1]=srcval
.peGreen
;
2493 dstbyte
[2]=srcval
.peRed
;
2496 dstbits
+= linebytes
;
2504 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2506 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2507 const void* srcbits
;
2508 const BYTE
* srcpixel
;
2511 /* Windows only supports one 24bpp DIB format: rgb 888 */
2512 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2513 for (h
= lines
- 1; h
>= 0; h
--) {
2516 for (x
= 0; x
< width
; x
++ ) {
2517 PALETTEENTRY srcval
;
2518 srcval
=srccolors
[*srcpixel
++];
2519 dstbyte
[0]=srcval
.peBlue
;
2520 dstbyte
[1]=srcval
.peGreen
;
2521 dstbyte
[2]=srcval
.peRed
;
2524 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2525 dstbits
+= linebytes
;
2535 /* ==== any bmp format -> 888 dib ==== */
2538 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2539 bmpImage
->depth
, bmpImage
->red_mask
,
2540 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2543 /* Windows only supports one 24bpp DIB format: rgb 888 */
2544 for (h
= lines
- 1; h
>= 0; h
--) {
2546 for (x
= 0; x
< width
; x
++) {
2547 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2548 (physDev
, XGetPixel( bmpImage
, x
, h
));
2549 dstbyte
[0]=GetBValue(srcval
);
2550 dstbyte
[1]=GetGValue(srcval
);
2551 dstbyte
[2]=GetRValue(srcval
);
2554 dstbits
+= linebytes
;
2562 /***********************************************************************
2563 * X11DRV_DIB_SetImageBits_32
2565 * SetDIBits for a 32-bit deep DIB.
2567 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2568 DWORD srcwidth
, DWORD dstwidth
, int left
,
2569 X11DRV_PDEVICE
*physDev
,
2570 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2575 int h
, width
= min(srcwidth
, dstwidth
);
2576 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2581 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2582 linebytes
= -linebytes
;
2585 switch (bmpImage
->depth
)
2588 if (bmpImage
->bits_per_pixel
==24) {
2591 srcbits
=srcbits
+left
*4;
2592 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2594 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2595 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2596 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2597 convs
->Convert_0888_to_888_asis
2600 dstbits
,-bmpImage
->bytes_per_line
);
2601 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2602 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2604 /* the tests below assume sane bmpImage masks */
2605 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2606 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2607 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2608 convs
->Convert_0888_to_888_reverse
2611 dstbits
,-bmpImage
->bytes_per_line
);
2612 } else if (bmpImage
->blue_mask
==0xff) {
2613 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2614 convs
->Convert_any0888_to_rgb888
2618 dstbits
,-bmpImage
->bytes_per_line
);
2620 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2621 convs
->Convert_any0888_to_bgr888
2625 dstbits
,-bmpImage
->bytes_per_line
);
2635 srcbits
=srcbits
+left
*4;
2636 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2638 if (gSrc
==bmpImage
->green_mask
) {
2639 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2640 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2641 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2642 convs
->Convert_0888_asis
2645 dstbits
,-bmpImage
->bytes_per_line
);
2646 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2647 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2649 /* the tests below assume sane bmpImage masks */
2650 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
2651 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2652 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2653 convs
->Convert_0888_reverse
2656 dstbits
,-bmpImage
->bytes_per_line
);
2658 /* ==== any 0888 dib -> any 0888 bmp ==== */
2659 convs
->Convert_0888_any
2663 dstbits
,-bmpImage
->bytes_per_line
,
2664 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2666 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2667 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2669 /* the tests below assume sane bmpImage masks */
2671 /* ==== any 0888 dib -> any 0888 bmp ==== */
2672 convs
->Convert_0888_any
2676 dstbits
,-bmpImage
->bytes_per_line
,
2677 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2687 srcbits
=srcbits
+left
*4;
2688 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2690 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
2691 if (bmpImage
->green_mask
==0x03e0) {
2692 if (bmpImage
->red_mask
==0x7f00) {
2693 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
2694 convs
->Convert_0888_to_555_asis
2697 dstbits
,-bmpImage
->bytes_per_line
);
2698 } else if (bmpImage
->blue_mask
==0x7f00) {
2699 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
2700 convs
->Convert_0888_to_555_reverse
2703 dstbits
,-bmpImage
->bytes_per_line
);
2707 } else if (bmpImage
->green_mask
==0x07e0) {
2708 if (bmpImage
->red_mask
==0xf800) {
2709 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
2710 convs
->Convert_0888_to_565_asis
2713 dstbits
,-bmpImage
->bytes_per_line
);
2714 } else if (bmpImage
->blue_mask
==0xf800) {
2715 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
2716 convs
->Convert_0888_to_565_reverse
2719 dstbits
,-bmpImage
->bytes_per_line
);
2726 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
2727 if (bmpImage
->green_mask
==0x03e0) {
2728 if (bmpImage
->blue_mask
==0x7f00) {
2729 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
2730 convs
->Convert_0888_to_555_asis
2733 dstbits
,-bmpImage
->bytes_per_line
);
2734 } else if (bmpImage
->red_mask
==0x7f00) {
2735 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
2736 convs
->Convert_0888_to_555_reverse
2739 dstbits
,-bmpImage
->bytes_per_line
);
2743 } else if (bmpImage
->green_mask
==0x07e0) {
2744 if (bmpImage
->blue_mask
==0xf800) {
2745 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
2746 convs
->Convert_0888_to_565_asis
2749 dstbits
,-bmpImage
->bytes_per_line
);
2750 } else if (bmpImage
->red_mask
==0xf800) {
2751 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
2752 convs
->Convert_0888_to_565_reverse
2755 dstbits
,-bmpImage
->bytes_per_line
);
2763 if (bmpImage
->green_mask
==0x03e0 &&
2764 (bmpImage
->red_mask
==0x7f00 ||
2765 bmpImage
->blue_mask
==0x7f00)) {
2766 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
2767 convs
->Convert_any0888_to_5x5
2771 dstbits
,-bmpImage
->bytes_per_line
,
2772 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2773 } else if (bmpImage
->green_mask
==0x07e0 &&
2774 (bmpImage
->red_mask
==0xf800 ||
2775 bmpImage
->blue_mask
==0xf800)) {
2776 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
2777 convs
->Convert_any0888_to_5x5
2781 dstbits
,-bmpImage
->bytes_per_line
,
2782 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2792 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2793 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2794 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2800 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
2801 const DWORD
* srcpixel
;
2802 int rShift
,gShift
,bShift
;
2804 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
2805 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
2806 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
2808 for (h
= lines
- 1; h
>= 0; h
--) {
2809 srcpixel
=(const DWORD
*)srcbits
;
2810 for (x
= left
; x
< width
+left
; x
++) {
2812 BYTE red
,green
,blue
;
2813 srcvalue
=*srcpixel
++;
2814 red
= (srcvalue
>> rShift
) & 0xff;
2815 green
=(srcvalue
>> gShift
) & 0xff;
2816 blue
= (srcvalue
>> bShift
) & 0xff;
2817 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
2818 (physDev
, RGB(red
,green
,blue
)));
2820 srcbits
+= linebytes
;
2828 /***********************************************************************
2829 * X11DRV_DIB_GetImageBits_32
2831 * GetDIBits for an 32-bit deep DIB.
2833 static void X11DRV_DIB_GetImageBits_32( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
2834 DWORD dstwidth
, DWORD srcwidth
,
2835 PALETTEENTRY
*srccolors
,
2836 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2837 XImage
*bmpImage
, int linebytes
)
2840 int h
, width
= min(srcwidth
, dstwidth
);
2841 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2846 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2847 linebytes
= -linebytes
;
2850 switch (bmpImage
->depth
)
2853 if (bmpImage
->bits_per_pixel
==24) {
2854 const void* srcbits
;
2856 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2858 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
2859 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2860 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2861 convs
->Convert_888_to_0888_asis
2863 srcbits
,-bmpImage
->bytes_per_line
,
2865 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2866 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2868 /* the tests below assume sane bmpImage masks */
2869 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
2870 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2871 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2872 convs
->Convert_888_to_0888_reverse
2874 srcbits
,-bmpImage
->bytes_per_line
,
2876 } else if (bmpImage
->blue_mask
==0xff) {
2877 /* ==== rgb 888 bmp -> any 0888 dib ==== */
2878 convs
->Convert_rgb888_to_any0888
2880 srcbits
,-bmpImage
->bytes_per_line
,
2884 /* ==== bgr 888 bmp -> any 0888 dib ==== */
2885 convs
->Convert_bgr888_to_any0888
2887 srcbits
,-bmpImage
->bytes_per_line
,
2897 const char* srcbits
;
2899 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2901 if (gDst
==bmpImage
->green_mask
) {
2902 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
2903 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
2904 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
2905 convs
->Convert_0888_asis
2907 srcbits
,-bmpImage
->bytes_per_line
,
2909 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2910 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2912 /* the tests below assume sane bmpImage masks */
2913 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
2914 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
2915 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
2916 convs
->Convert_0888_reverse
2918 srcbits
,-bmpImage
->bytes_per_line
,
2921 /* ==== any 0888 bmp -> any 0888 dib ==== */
2922 convs
->Convert_0888_any
2924 srcbits
,-bmpImage
->bytes_per_line
,
2925 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
2929 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2930 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2932 /* the tests below assume sane bmpImage masks */
2934 /* ==== any 0888 bmp -> any 0888 dib ==== */
2935 convs
->Convert_0888_any
2937 srcbits
,-bmpImage
->bytes_per_line
,
2938 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
2948 const char* srcbits
;
2950 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2952 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
2953 if (bmpImage
->green_mask
==0x03e0) {
2954 if (bmpImage
->red_mask
==0x7f00) {
2955 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
2956 convs
->Convert_555_to_0888_asis
2958 srcbits
,-bmpImage
->bytes_per_line
,
2960 } else if (bmpImage
->blue_mask
==0x7f00) {
2961 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
2962 convs
->Convert_555_to_0888_reverse
2964 srcbits
,-bmpImage
->bytes_per_line
,
2969 } else if (bmpImage
->green_mask
==0x07e0) {
2970 if (bmpImage
->red_mask
==0xf800) {
2971 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
2972 convs
->Convert_565_to_0888_asis
2974 srcbits
,-bmpImage
->bytes_per_line
,
2976 } else if (bmpImage
->blue_mask
==0xf800) {
2977 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
2978 convs
->Convert_565_to_0888_reverse
2980 srcbits
,-bmpImage
->bytes_per_line
,
2988 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
2989 if (bmpImage
->green_mask
==0x03e0) {
2990 if (bmpImage
->blue_mask
==0x7f00) {
2991 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
2992 convs
->Convert_555_to_0888_asis
2994 srcbits
,-bmpImage
->bytes_per_line
,
2996 } else if (bmpImage
->red_mask
==0x7f00) {
2997 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
2998 convs
->Convert_555_to_0888_reverse
3000 srcbits
,-bmpImage
->bytes_per_line
,
3005 } else if (bmpImage
->green_mask
==0x07e0) {
3006 if (bmpImage
->blue_mask
==0xf800) {
3007 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3008 convs
->Convert_565_to_0888_asis
3010 srcbits
,-bmpImage
->bytes_per_line
,
3012 } else if (bmpImage
->red_mask
==0xf800) {
3013 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3014 convs
->Convert_565_to_0888_reverse
3016 srcbits
,-bmpImage
->bytes_per_line
,
3025 if (bmpImage
->green_mask
==0x03e0 &&
3026 (bmpImage
->red_mask
==0x7f00 ||
3027 bmpImage
->blue_mask
==0x7f00)) {
3028 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3029 convs
->Convert_5x5_to_any0888
3031 srcbits
,-bmpImage
->bytes_per_line
,
3032 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3035 } else if (bmpImage
->green_mask
==0x07e0 &&
3036 (bmpImage
->red_mask
==0xf800 ||
3037 bmpImage
->blue_mask
==0xf800)) {
3038 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3039 convs
->Convert_5x5_to_any0888
3041 srcbits
,-bmpImage
->bytes_per_line
,
3042 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3054 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3056 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3057 int rShift
,gShift
,bShift
;
3060 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3061 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3062 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3063 for (h
= lines
- 1; h
>= 0; h
--) {
3064 dstpixel
=(DWORD
*)dstbits
;
3065 for (x
= 0; x
< width
; x
++) {
3066 PALETTEENTRY srcval
;
3067 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3068 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3069 (srcval
.peGreen
<< gShift
) |
3070 (srcval
.peBlue
<< bShift
);
3072 dstbits
+= linebytes
;
3080 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3082 /* ==== pal 8 bmp -> any 0888 dib ==== */
3083 int rShift
,gShift
,bShift
;
3084 const void* srcbits
;
3085 const BYTE
* srcpixel
;
3088 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3089 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3090 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3091 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3092 for (h
= lines
- 1; h
>= 0; h
--) {
3094 dstpixel
=(DWORD
*)dstbits
;
3095 for (x
= 0; x
< width
; x
++) {
3096 PALETTEENTRY srcval
;
3097 srcval
=srccolors
[*srcpixel
++];
3098 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3099 (srcval
.peGreen
<< gShift
) |
3100 (srcval
.peBlue
<< bShift
);
3102 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3103 dstbits
+= linebytes
;
3113 /* ==== any bmp format -> any 0888 dib ==== */
3114 int rShift
,gShift
,bShift
;
3117 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3118 bmpImage
->depth
, bmpImage
->red_mask
,
3119 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3122 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3123 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3124 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3125 for (h
= lines
- 1; h
>= 0; h
--) {
3126 dstpixel
=(DWORD
*)dstbits
;
3127 for (x
= 0; x
< width
; x
++) {
3129 srcval
=X11DRV_PALETTE_ToLogical(physDev
, XGetPixel(bmpImage
, x
, h
));
3130 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3131 (GetGValue(srcval
) << gShift
) |
3132 (GetBValue(srcval
) << bShift
);
3134 dstbits
+= linebytes
;
3141 /***********************************************************************
3142 * X11DRV_DIB_SetImageBits
3144 * Transfer the bits to an X image.
3145 * Helper function for SetDIBits() and SetDIBitsToDevice().
3147 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3149 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3150 void *old_data
= NULL
;
3155 bmpImage
= descr
->image
;
3157 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3158 descr
->infoWidth
, lines
, 32, 0 );
3159 bmpImage
->data
= HeapAlloc( GetProcessHeap(), 0, lines
* bmpImage
->bytes_per_line
);
3160 if(bmpImage
->data
== NULL
) {
3161 ERR("Out of memory!\n");
3162 XDestroyImage( bmpImage
);
3163 wine_tsx11_unlock();
3168 bmpImage
->red_mask
= descr
->shifts
->physicalRed
.max
<< descr
->shifts
->physicalRed
.shift
;
3169 bmpImage
->green_mask
= descr
->shifts
->physicalGreen
.max
<< descr
->shifts
->physicalGreen
.shift
;
3170 bmpImage
->blue_mask
= descr
->shifts
->physicalBlue
.max
<< descr
->shifts
->physicalBlue
.shift
;
3173 wine_tsx11_unlock();
3175 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3176 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3177 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3178 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3179 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3181 #ifdef HAVE_LIBXXSHM
3182 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
3183 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3184 && descr
->xDest
== 0 && descr
->yDest
== 0)
3186 TRACE("Using the shared pixmap data.\n");
3189 XSync( gdi_display
, False
);
3190 wine_tsx11_unlock();
3192 old_data
= descr
->image
->data
;
3193 descr
->image
->data
= descr
->physBitmap
->shminfo
.shmaddr
;
3197 /* Transfer the pixels */
3200 switch(descr
->infoBpp
)
3203 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3204 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3205 bmpImage
, descr
->dibpitch
);
3208 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3209 descr
->infoWidth
, descr
->width
,
3210 descr
->xSrc
, (int*)(descr
->colorMap
),
3211 bmpImage
, descr
->dibpitch
);
3214 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3215 descr
->infoWidth
, descr
->width
,
3216 descr
->xSrc
, (int *)(descr
->colorMap
),
3217 bmpImage
, descr
->dibpitch
);
3220 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3221 descr
->infoWidth
, descr
->width
,
3222 descr
->xSrc
, descr
->physDev
,
3223 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3224 bmpImage
, descr
->dibpitch
);
3227 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3228 descr
->infoWidth
, descr
->width
,
3229 descr
->xSrc
, descr
->physDev
,
3230 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3231 bmpImage
, descr
->dibpitch
);
3234 X11DRV_DIB_SetImageBits_32( descr
->lines
, descr
->bits
,
3235 descr
->infoWidth
, descr
->width
,
3236 descr
->xSrc
, descr
->physDev
,
3237 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3238 bmpImage
, descr
->dibpitch
);
3241 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3247 WARN( "invalid bits pointer %p\n", descr
->bits
);
3252 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3253 descr
->drawable
, descr
->gc
, bmpImage
,
3254 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3255 descr
->width
, descr
->height
);
3260 #ifdef HAVE_LIBXXSHM
3261 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
3262 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3263 && descr
->xDest
== 0 && descr
->yDest
== 0)
3265 XSync( gdi_display
, False
);
3267 else if (descr
->shm_mode
== X11DRV_SHM_IMAGE
&& descr
->image
)
3269 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3270 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3271 descr
->width
, descr
->height
, FALSE
);
3272 XSync( gdi_display
, 0 );
3277 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3278 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3279 descr
->width
, descr
->height
);
3283 if (old_data
) descr
->image
->data
= old_data
;
3285 if (!descr
->image
) X11DRV_DIB_DestroyXImage( bmpImage
);
3286 wine_tsx11_unlock();
3290 /***********************************************************************
3291 * X11DRV_DIB_GetImageBits
3293 * Transfer the bits from an X image.
3295 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3297 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3298 void *old_data
= NULL
;
3303 bmpImage
= descr
->image
;
3305 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3306 descr
->infoWidth
, lines
, 32, 0 );
3307 bmpImage
->data
= HeapAlloc( GetProcessHeap(), 0, lines
* bmpImage
->bytes_per_line
);
3308 if(bmpImage
->data
== NULL
) {
3309 ERR("Out of memory!\n");
3310 XDestroyImage( bmpImage
);
3311 wine_tsx11_unlock();
3316 bmpImage
->red_mask
= descr
->shifts
->physicalRed
.max
<< descr
->shifts
->physicalRed
.shift
;
3317 bmpImage
->green_mask
= descr
->shifts
->physicalGreen
.max
<< descr
->shifts
->physicalGreen
.shift
;
3318 bmpImage
->blue_mask
= descr
->shifts
->physicalBlue
.max
<< descr
->shifts
->physicalBlue
.shift
;
3322 #ifdef HAVE_LIBXXSHM
3324 /* We must not call XShmGetImage() with a bitmap which is bigger than the available area.
3325 If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */
3326 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
&& descr
->image
3327 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3328 && descr
->xDest
== 0 && descr
->yDest
== 0
3329 && bmpImage
->width
<= (descr
->width
- descr
->xSrc
)
3330 && bmpImage
->height
<= (descr
->height
- descr
->ySrc
))
3332 XSync( gdi_display
, False
);
3333 old_data
= bmpImage
->data
;
3334 bmpImage
->data
= descr
->physBitmap
->shminfo
.shmaddr
;
3335 TRACE("Using shared pixmap data.\n");
3337 else if (descr
->shm_mode
== X11DRV_SHM_IMAGE
&& descr
->image
3338 && bmpImage
->width
<= (descr
->width
- descr
->xSrc
)
3339 && bmpImage
->height
<= (descr
->height
- descr
->ySrc
))
3341 int saveRed
, saveGreen
, saveBlue
;
3343 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3344 gdi_display
, descr
->drawable
, bmpImage
,
3345 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3347 /* We must save and restore the bmpImage's masks in order
3348 * to preserve them across the call to XShmGetImage, which
3349 * decides to eliminate them since it doesn't happen to know
3350 * what the format of the image is supposed to be, even though
3352 saveRed
= bmpImage
->red_mask
;
3353 saveBlue
= bmpImage
->blue_mask
;
3354 saveGreen
= bmpImage
->green_mask
;
3356 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3357 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3359 bmpImage
->red_mask
= saveRed
;
3360 bmpImage
->blue_mask
= saveBlue
;
3361 bmpImage
->green_mask
= saveGreen
;
3364 #endif /* HAVE_LIBXXSHM */
3366 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3367 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3368 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3369 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3370 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3371 bmpImage
, descr
->xDest
, descr
->yDest
);
3373 wine_tsx11_unlock();
3375 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3376 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3377 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3378 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3379 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3380 /* Transfer the pixels */
3381 switch(descr
->infoBpp
)
3384 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3385 descr
->infoWidth
, descr
->width
,
3386 descr
->colorMap
, descr
->palentry
,
3387 bmpImage
, descr
->dibpitch
);
3391 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3392 descr
->infoWidth
, descr
->width
,
3393 descr
->colorMap
, descr
->palentry
,
3394 bmpImage
, descr
->dibpitch
);
3397 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3398 descr
->infoWidth
, descr
->width
,
3399 descr
->colorMap
, descr
->palentry
,
3400 bmpImage
, descr
->dibpitch
);
3403 X11DRV_DIB_GetImageBits_16( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3404 descr
->infoWidth
,descr
->width
,
3406 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3407 bmpImage
, descr
->dibpitch
);
3411 X11DRV_DIB_GetImageBits_24( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3412 descr
->infoWidth
,descr
->width
,
3414 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3415 bmpImage
, descr
->dibpitch
);
3419 X11DRV_DIB_GetImageBits_32( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3420 descr
->infoWidth
, descr
->width
,
3422 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3423 bmpImage
, descr
->dibpitch
);
3427 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3431 if (old_data
) bmpImage
->data
= old_data
;
3432 if (!descr
->image
) X11DRV_DIB_DestroyXImage( bmpImage
);
3436 /***********************************************************************
3437 * X11DRV_DIB_DoCopyDIBSection
3439 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
3440 void *colorMap
, int nColorMap
,
3441 Drawable dest
, GC gc
,
3442 DWORD xSrc
, DWORD ySrc
,
3443 DWORD xDest
, DWORD yDest
,
3444 DWORD width
, DWORD height
)
3446 DIBSECTION dibSection
;
3447 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3448 int identity
[2] = {0,1};
3450 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
3452 descr
.physDev
= NULL
;
3453 descr
.palentry
= NULL
;
3454 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
3455 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
3456 descr
.lines
= physBitmap
->topdown
? -dibSection
.dsBmih
.biHeight
: dibSection
.dsBmih
.biHeight
;
3457 descr
.image
= physBitmap
->image
;
3458 descr
.colorMap
= colorMap
;
3459 descr
.nColorMap
= nColorMap
;
3460 descr
.bits
= dibSection
.dsBm
.bmBits
;
3461 descr
.depth
= physBitmap
->depth
;
3462 descr
.shifts
= physBitmap
->trueColor
? &physBitmap
->color_shifts
: NULL
;
3463 descr
.compression
= dibSection
.dsBmih
.biCompression
;
3464 descr
.physBitmap
= physBitmap
;
3466 if(descr
.infoBpp
== 1)
3467 descr
.colorMap
= (void*)identity
;
3469 switch (descr
.infoBpp
)
3474 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3478 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
3479 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
3480 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
3485 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
3486 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
3487 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
3492 descr
.drawable
= dest
;
3496 descr
.xDest
= xDest
;
3497 descr
.yDest
= yDest
;
3498 descr
.width
= width
;
3499 descr
.height
= height
;
3500 descr
.sizeImage
= 0;
3502 descr
.shm_mode
= physBitmap
->shm_mode
;
3503 #ifdef HAVE_LIBXXSHM
3504 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
&& physBitmap
->pixmap
!= dest
)
3506 descr
.shm_mode
= X11DRV_SHM_NONE
;
3509 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
3513 TRACE("Copying from Pixmap to DIB bits\n");
3514 X11DRV_DIB_GetImageBits( &descr
);
3518 TRACE("Copying from DIB bits to Pixmap\n");
3519 X11DRV_DIB_SetImageBits( &descr
);
3523 /***********************************************************************
3524 * X11DRV_DIB_DoUpdateDIBSection
3526 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
3530 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
3531 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
3532 physBitmap
->colorMap
, physBitmap
->nColorMap
,
3533 physBitmap
->pixmap
, get_bitmap_gc(physBitmap
->depth
),
3534 0, 0, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
);
3537 /***********************************************************************
3538 * X11DRV_DIB_FaultHandler
3540 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
3542 X_PHYSBITMAP
*physBitmap
= NULL
;
3546 const size_t pagemask
= getpagesize() - 1;
3548 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
3549 return EXCEPTION_CONTINUE_SEARCH
;
3551 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
3553 EnterCriticalSection(&dibs_cs
);
3554 LIST_FOR_EACH( ptr
, &dibs_list
)
3556 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
3557 if ((physBitmap
->base
<= addr
) &&
3558 (addr
< physBitmap
->base
+ ((physBitmap
->size
+ pagemask
) & ~pagemask
)))
3564 LeaveCriticalSection(&dibs_cs
);
3566 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
3568 if (addr
>= physBitmap
->base
+ physBitmap
->size
)
3569 WARN( "%p: access to %p beyond the end of the DIB\n", physBitmap
->hbitmap
, addr
);
3571 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
);
3572 if (ep
->ExceptionRecord
->ExceptionInformation
[0] == EXCEPTION_WRITE_FAULT
) {
3573 /* the app tried to write the DIB bits */
3574 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
);
3576 /* the app tried to read the DIB bits */
3577 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
);
3579 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
3581 return EXCEPTION_CONTINUE_EXECUTION
;
3584 /***********************************************************************
3587 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
)
3589 INT ret
= DIB_Status_None
;
3591 if (!physBitmap
->image
) return ret
; /* not a DIB section */
3592 EnterCriticalSection(&physBitmap
->lock
);
3593 ret
= physBitmap
->status
;
3595 case DIB_Status_GdiMod
:
3596 /* GDI access - request to draw on pixmap */
3597 switch (physBitmap
->status
)
3600 case DIB_Status_None
:
3601 physBitmap
->p_status
= DIB_Status_GdiMod
;
3602 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
3605 case DIB_Status_GdiMod
:
3606 TRACE("GdiMod requested in status GdiMod\n" );
3607 physBitmap
->p_status
= DIB_Status_GdiMod
;
3610 case DIB_Status_InSync
:
3611 TRACE("GdiMod requested in status InSync\n" );
3612 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
3613 physBitmap
->status
= DIB_Status_GdiMod
;
3614 physBitmap
->p_status
= DIB_Status_InSync
;
3617 case DIB_Status_AppMod
:
3618 TRACE("GdiMod requested in status AppMod\n" );
3619 /* make it readonly to avoid app changing data while we copy */
3620 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
3621 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
3622 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
3623 physBitmap
->p_status
= DIB_Status_AppMod
;
3624 physBitmap
->status
= DIB_Status_GdiMod
;
3629 case DIB_Status_InSync
:
3630 /* App access - request access to read DIB surface */
3631 /* (typically called from signal handler) */
3632 switch (physBitmap
->status
)
3635 case DIB_Status_None
:
3636 /* shouldn't happen from signal handler */
3639 case DIB_Status_GdiMod
:
3640 TRACE("InSync requested in status GdiMod\n" );
3641 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
3642 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
3643 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
3644 physBitmap
->status
= DIB_Status_InSync
;
3647 case DIB_Status_InSync
:
3648 TRACE("InSync requested in status InSync\n" );
3649 /* shouldn't happen from signal handler */
3652 case DIB_Status_AppMod
:
3653 TRACE("InSync requested in status AppMod\n" );
3654 /* no reason to do anything here, and this
3655 * shouldn't happen from signal handler */
3660 case DIB_Status_AppMod
:
3661 /* App access - request access to write DIB surface */
3662 /* (typically called from signal handler) */
3663 switch (physBitmap
->status
)
3666 case DIB_Status_None
:
3667 /* shouldn't happen from signal handler */
3670 case DIB_Status_GdiMod
:
3671 TRACE("AppMod requested in status GdiMod\n" );
3672 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
3673 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
3674 physBitmap
->status
= DIB_Status_AppMod
;
3677 case DIB_Status_InSync
:
3678 TRACE("AppMod requested in status InSync\n" );
3679 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
3680 physBitmap
->status
= DIB_Status_AppMod
;
3683 case DIB_Status_AppMod
:
3684 TRACE("AppMod requested in status AppMod\n" );
3685 /* shouldn't happen from signal handler */
3690 /* it is up to the caller to do the copy/conversion, probably
3691 * using the return value to decide where to copy from */
3693 LeaveCriticalSection(&physBitmap
->lock
);
3697 /***********************************************************************
3700 INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
)
3702 INT ret
= DIB_Status_None
;
3704 if (!physBitmap
->image
) return ret
; /* not a DIB section */
3705 TRACE("Locking %p from thread %04x\n", physBitmap
->hbitmap
, GetCurrentThreadId());
3706 EnterCriticalSection(&physBitmap
->lock
);
3707 ret
= physBitmap
->status
;
3708 if (req
!= DIB_Status_None
)
3709 X11DRV_DIB_Coerce(physBitmap
, req
);
3713 /***********************************************************************
3716 void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
3718 if (!physBitmap
->image
) return; /* not a DIB section */
3719 switch (physBitmap
->status
)
3722 case DIB_Status_None
:
3723 /* in case anyone is wondering, this is the "signal handler doesn't
3724 * work" case, where we always have to be ready for app access */
3726 switch (physBitmap
->p_status
)
3728 case DIB_Status_GdiMod
:
3729 TRACE("Unlocking and syncing from GdiMod\n" );
3730 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
3734 TRACE("Unlocking without needing to sync\n" );
3738 else TRACE("Unlocking with no changes\n");
3739 physBitmap
->p_status
= DIB_Status_None
;
3742 case DIB_Status_GdiMod
:
3743 TRACE("Unlocking in status GdiMod\n" );
3744 /* DIB was protected in Coerce */
3746 /* no commit, revert to InSync if applicable */
3747 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
3748 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
3749 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
3750 physBitmap
->status
= DIB_Status_InSync
;
3755 case DIB_Status_InSync
:
3756 TRACE("Unlocking in status InSync\n" );
3757 /* DIB was already protected in Coerce */
3760 case DIB_Status_AppMod
:
3761 TRACE("Unlocking in status AppMod\n" );
3762 /* DIB was already protected in Coerce */
3763 /* this case is ordinary only called from the signal handler,
3764 * so we don't bother to check for !commit */
3767 LeaveCriticalSection(&physBitmap
->lock
);
3768 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
3771 /***********************************************************************
3772 * X11DRV_CoerceDIBSection
3774 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
3776 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
3777 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
);
3780 /***********************************************************************
3781 * X11DRV_LockDIBSection
3783 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
3785 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
3786 return X11DRV_DIB_Lock(physDev
->bitmap
, req
);
3789 /***********************************************************************
3790 * X11DRV_UnlockDIBSection
3792 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
3794 if (!physDev
|| !physDev
->bitmap
) return;
3795 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
3799 #ifdef HAVE_LIBXXSHM
3800 /***********************************************************************
3801 * X11DRV_XShmErrorHandler
3804 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
3806 return 1; /* FIXME: should check event contents */
3809 /***********************************************************************
3810 * X11DRV_XShmCreateImage
3813 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
3814 XShmSegmentInfo
* shminfo
)
3818 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
3821 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
3823 if( shminfo
->shmid
!= -1 )
3825 shminfo
->shmaddr
= shmat( shminfo
->shmid
, 0, 0 );
3826 if( shminfo
->shmaddr
!= (char*)-1 )
3830 shminfo
->readOnly
= FALSE
;
3831 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
3832 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
3833 XSync( gdi_display
, False
);
3834 if (X11DRV_check_error()) ok
= FALSE
;
3837 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
3838 return image
; /* Success! */
3840 /* An error occurred */
3841 shmdt(shminfo
->shmaddr
);
3843 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
3844 shminfo
->shmid
= -1;
3846 XFlush(gdi_display
);
3847 XDestroyImage(image
);
3853 static Bool
X11DRV_DIB_QueryXShm( Bool
*pixmaps
)
3855 static Bool have_xshm
, have_xshm_pixmaps
;
3856 static BOOL initialized
;
3862 have_xshm
= XShmQueryVersion( gdi_display
, &major
, &minor
, &have_xshm_pixmaps
);
3866 *pixmaps
= have_xshm_pixmaps
;
3869 #endif /* HAVE_LIBXXSHM */
3871 /***********************************************************************
3872 * X11DRV_CreateDIBSection (X11DRV.@)
3874 HBITMAP
X11DRV_CreateDIBSection( PHYSDEV dev
, HBITMAP hbitmap
, BITMAPINFO
*bmi
, UINT usage
)
3876 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3877 X_PHYSBITMAP
*physBitmap
;
3879 #ifdef HAVE_LIBXXSHM
3883 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
3884 physBitmap
->topdown
= bmi
->bmiHeader
.biHeight
< 0;
3885 physBitmap
->status
= DIB_Status_None
;
3887 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
3889 /* create color map */
3890 if (dib
.dsBm
.bmBitsPixel
<= 8)
3892 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( physDev
,
3893 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
3894 &physBitmap
->nColorMap
);
3897 if (!X11DRV_XRender_SetPhysBitmapDepth( physBitmap
, dib
.dsBm
.bmBitsPixel
, &dib
))
3899 if (dib
.dsBm
.bmBitsPixel
== 1)
3901 physBitmap
->depth
= 1;
3902 physBitmap
->trueColor
= FALSE
;
3906 physBitmap
->depth
= screen_depth
;
3907 physBitmap
->color_shifts
= X11DRV_PALETTE_default_shifts
;
3908 physBitmap
->trueColor
= (visual
->class == TrueColor
|| visual
->class == DirectColor
);
3912 /* create pixmap and X image */
3914 #ifdef HAVE_LIBXXSHM
3915 physBitmap
->shminfo
.shmid
= -1;
3917 if (X11DRV_DIB_QueryXShm( &pixmaps
)
3918 && (physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
3919 physBitmap
->depth
, &physBitmap
->shminfo
)))
3923 physBitmap
->shm_mode
= X11DRV_SHM_PIXMAP
;
3924 physBitmap
->image
->data
= HeapAlloc( GetProcessHeap(), 0,
3925 dib
.dsBm
.bmHeight
* physBitmap
->image
->bytes_per_line
);
3929 physBitmap
->shm_mode
= X11DRV_SHM_IMAGE
;
3930 physBitmap
->image
->data
= physBitmap
->shminfo
.shmaddr
;
3936 physBitmap
->shm_mode
= X11DRV_SHM_NONE
;
3937 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
3938 physBitmap
->depth
);
3941 #ifdef HAVE_LIBXXSHM
3942 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
)
3944 TRACE("Creating shared pixmap for bmp %p.\n", physBitmap
->hbitmap
);
3945 physBitmap
->pixmap
= XShmCreatePixmap( gdi_display
, root_window
,
3946 physBitmap
->shminfo
.shmaddr
, &physBitmap
->shminfo
,
3947 dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
3948 physBitmap
->depth
);
3953 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
3954 dib
.dsBm
.bmHeight
, physBitmap
->depth
);
3957 wine_tsx11_unlock();
3958 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
3960 if (physBitmap
->trueColor
)
3962 ColorShifts
*shifts
= &physBitmap
->color_shifts
;
3964 /* When XRender is around and used, we also support dibsections in other formats like 16-bit. In these
3965 * cases we need to override the mask of XImages. The reason is that during XImage creation the masks are
3966 * derived from a 24-bit visual (no 16-bit ones are around when X runs at 24-bit). SetImageBits and other
3967 * functions rely on the color masks for proper color conversion, so we need to override the masks here. */
3968 physBitmap
->image
->red_mask
= shifts
->physicalRed
.max
<< shifts
->physicalRed
.shift
;
3969 physBitmap
->image
->green_mask
= shifts
->physicalGreen
.max
<< shifts
->physicalGreen
.shift
;
3970 physBitmap
->image
->blue_mask
= shifts
->physicalBlue
.max
<< shifts
->physicalBlue
.shift
;
3973 /* install fault handler */
3974 InitializeCriticalSection( &physBitmap
->lock
);
3975 physBitmap
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": X_PHYSBITMAP.lock");
3977 physBitmap
->base
= dib
.dsBm
.bmBits
;
3978 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
3979 physBitmap
->status
= DIB_Status_AppMod
;
3982 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
3983 EnterCriticalSection( &dibs_cs
);
3984 list_add_head( &dibs_list
, &physBitmap
->entry
);
3985 LeaveCriticalSection( &dibs_cs
);
3987 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
3992 /***********************************************************************
3993 * X11DRV_DIB_DeleteDIBSection
3995 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
3999 EnterCriticalSection( &dibs_cs
);
4000 list_remove( &physBitmap
->entry
);
4001 last
= list_empty( &dibs_list
);
4002 LeaveCriticalSection( &dibs_cs
);
4006 RemoveVectoredExceptionHandler( dibs_handler
);
4007 dibs_handler
= NULL
;
4010 if (dib
->dshSection
)
4011 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
);
4013 if (physBitmap
->image
)
4016 #ifdef HAVE_LIBXXSHM
4017 if (physBitmap
->shminfo
.shmid
!= -1)
4019 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4020 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
) X11DRV_DIB_DestroyXImage( physBitmap
->image
);
4021 else XDestroyImage( physBitmap
->image
);
4022 shmdt( physBitmap
->shminfo
.shmaddr
);
4023 physBitmap
->shminfo
.shmid
= -1;
4024 physBitmap
->shm_mode
= X11DRV_SHM_NONE
;
4028 X11DRV_DIB_DestroyXImage( physBitmap
->image
);
4029 wine_tsx11_unlock();
4032 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4033 physBitmap
->lock
.DebugInfo
->Spare
[0] = 0;
4034 DeleteCriticalSection(&physBitmap
->lock
);
4037 /***********************************************************************
4038 * SetDIBColorTable (X11DRV.@)
4040 UINT
X11DRV_SetDIBColorTable( PHYSDEV dev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4042 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
4045 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4047 if (!physBitmap
) return 0;
4048 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4050 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4051 UINT end
= count
+ start
;
4052 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4054 * Changing color table might change the mapping between
4055 * DIB colors and X11 colors and thus alter the visible state
4056 * of the bitmap object.
4059 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4060 * at least for a 1 bpp dibsection
4062 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
);
4063 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4064 dib
.dsBm
.bmBitsPixel
, colors
, start
, end
);
4065 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4072 /***********************************************************************
4073 * X11DRV_DIB_CreateDIBFromBitmap
4075 * Allocates a packed DIB and copies the bitmap data into it.
4077 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4082 LPBITMAPINFOHEADER pbmiHeader
;
4083 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4086 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4089 * A packed DIB contains a BITMAPINFO structure followed immediately by
4090 * an optional color palette and the pixel data.
4093 /* Calculate the size of the packed DIB */
4094 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4095 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4096 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4098 /* Get the offset to the bits */
4099 OffsetBits
= cPackedSize
- cDataSize
;
4101 /* Allocate the packed DIB */
4102 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4103 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4107 WARN("Could not allocate packed DIB!\n");
4111 /* A packed DIB starts with a BITMAPINFOHEADER */
4112 pPackedDIB
= GlobalLock(hPackedDIB
);
4113 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4115 /* Init the BITMAPINFOHEADER */
4116 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
4117 pbmiHeader
->biWidth
= bmp
.bmWidth
;
4118 pbmiHeader
->biHeight
= bmp
.bmHeight
;
4119 pbmiHeader
->biPlanes
= 1;
4120 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
4121 pbmiHeader
->biCompression
= BI_RGB
;
4122 pbmiHeader
->biSizeImage
= 0;
4123 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
4124 pbmiHeader
->biClrUsed
= 0;
4125 pbmiHeader
->biClrImportant
= 0;
4127 /* Retrieve the DIB bits from the bitmap and fill in the
4128 * DIB color table if present */
4130 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
4131 hBmp
, /* Handle to bitmap */
4132 0, /* First scan line to set in dest bitmap */
4133 bmp
.bmHeight
, /* Number of scan lines to copy */
4134 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
4135 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
4136 0); /* RGB or palette index */
4137 GlobalUnlock(hPackedDIB
);
4139 /* Cleanup if GetDIBits failed */
4140 if (nLinesCopied
!= bmp
.bmHeight
)
4142 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
4143 GlobalFree(hPackedDIB
);
4150 /**************************************************************************
4151 * X11DRV_DIB_CreateDIBFromPixmap
4153 * Allocates a packed DIB and copies the Pixmap data into it.
4154 * The Pixmap passed in is deleted after the conversion.
4156 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
4159 X_PHYSBITMAP
*physBitmap
;
4162 HGLOBAL hPackedDIB
= 0;
4164 int x
,y
; /* Unused */
4165 unsigned border_width
; /* Unused */
4166 unsigned int depth
, width
, height
;
4168 /* Get the Pixmap dimensions and bit depth */
4170 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
4171 &border_width
, &depth
)) depth
= 0;
4172 wine_tsx11_unlock();
4173 if (!pixmap_formats
[depth
]) return 0;
4175 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4176 width
, height
, depth
);
4179 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4180 * and make it a container for the pixmap passed.
4182 if (!(hBmp
= CreateBitmap( width
, height
, 1, pixmap_formats
[depth
]->bits_per_pixel
, NULL
))) return 0;
4184 /* force bitmap to be owned by a screen DC */
4185 hdcMem
= CreateCompatibleDC( hdc
);
4186 SelectObject( hdcMem
, SelectObject( hdcMem
, hBmp
));
4189 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4191 /* swap the new pixmap in */
4192 orig_pixmap
= physBitmap
->pixmap
;
4193 physBitmap
->pixmap
= pixmap
;
4196 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4197 * A packed DIB contains a BITMAPINFO structure followed immediately by
4198 * an optional color palette and the pixel data.
4200 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
4202 /* we can now get rid of the HBITMAP and its original pixmap */
4203 physBitmap
->pixmap
= orig_pixmap
;
4206 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
4211 /**************************************************************************
4212 * X11DRV_DIB_CreatePixmapFromDIB
4214 * Creates a Pixmap from a packed DIB
4216 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
4219 X_PHYSBITMAP
*physBitmap
;
4224 /* Create a DDB from the DIB */
4226 pbmi
= GlobalLock(hPackedDIB
);
4227 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
4228 (LPBYTE
)pbmi
+ bitmap_info_size( pbmi
, DIB_RGB_COLORS
),
4229 pbmi
, DIB_RGB_COLORS
);
4230 GlobalUnlock(hPackedDIB
);
4232 /* make sure it's owned by x11drv */
4233 memdc
= CreateCompatibleDC( hdc
);
4234 SelectObject( memdc
, hBmp
);
4237 /* clear the physBitmap so that we can steal its pixmap */
4238 if ((physBitmap
= X11DRV_get_phys_bitmap( hBmp
)))
4240 pixmap
= physBitmap
->pixmap
;
4241 physBitmap
->pixmap
= 0;
4244 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4247 TRACE("Returning Pixmap %lx\n", pixmap
);