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
;
90 } X11DRV_DIB_IMAGEBITS_DESCR
;
95 RLE_EOL
= 0, /* End of line */
96 RLE_END
= 1, /* End of bitmap */
97 RLE_DELTA
= 2 /* Delta */
101 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*,INT
);
102 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*,INT
);
103 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*,BOOL
);
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
)
161 case 1: words
= (width
+ 31) / 32; break;
162 case 4: words
= (width
+ 7) / 8; break;
163 case 8: words
= (width
+ 3) / 4; break;
165 case 16: words
= (width
+ 1) / 2; break;
166 case 24: words
= (width
* 3 + 3) / 4; break;
168 WARN("(%d): Unsupported depth\n", depth
);
177 /***********************************************************************
178 * X11DRV_DIB_GetDIBImageBytes
180 * Return the number of bytes used to hold the image in a DIB bitmap.
182 static int X11DRV_DIB_GetDIBImageBytes( int width
, int height
, int depth
)
184 return X11DRV_DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
188 /***********************************************************************
191 * Return the size of the bitmap info structure including color table.
193 int bitmap_info_size( const BITMAPINFO
* info
, WORD coloruse
)
195 unsigned int colors
, masks
= 0;
197 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
199 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
200 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
201 return sizeof(BITMAPCOREHEADER
) + colors
*
202 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
204 else /* assume BITMAPINFOHEADER */
206 colors
= info
->bmiHeader
.biClrUsed
;
207 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
208 colors
= 1 << info
->bmiHeader
.biBitCount
;
209 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
210 return sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) + colors
*
211 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
216 /***********************************************************************
217 * X11DRV_DIB_CreateXImage
221 XImage
*X11DRV_DIB_CreateXImage( int width
, int height
, int depth
)
224 XImage
*image
= NULL
;
228 width_bytes
= X11DRV_DIB_GetXImageWidthBytes( width
, depth
);
229 data
= HeapAlloc( GetProcessHeap(), 0, height
* width_bytes
);
230 if (data
) image
= XCreateImage( gdi_display
, visual
, depth
, ZPixmap
, 0,
231 data
, width
, height
, 32, width_bytes
);
232 if (!image
) HeapFree( GetProcessHeap(), 0, data
);
238 /***********************************************************************
239 * X11DRV_DIB_DestroyXImage
241 * Destroy an X image created with X11DRV_DIB_CreateXImage.
243 void X11DRV_DIB_DestroyXImage( XImage
*image
)
245 HeapFree( GetProcessHeap(), 0, image
->data
);
248 XDestroyImage( image
);
253 /***********************************************************************
254 * DIB_GetBitmapInfoEx
256 * Get the info from a bitmap header.
257 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
259 static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER
*header
, LONG
*width
,
260 LONG
*height
, WORD
*planes
, WORD
*bpp
,
261 WORD
*compr
, DWORD
*size
)
263 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
265 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
266 *width
= core
->bcWidth
;
267 *height
= core
->bcHeight
;
268 *planes
= core
->bcPlanes
;
269 *bpp
= core
->bcBitCount
;
274 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
))
276 *width
= header
->biWidth
;
277 *height
= header
->biHeight
;
278 *planes
= header
->biPlanes
;
279 *bpp
= header
->biBitCount
;
280 *compr
= header
->biCompression
;
281 *size
= header
->biSizeImage
;
284 ERR("(%d): unknown/wrong size for header\n", header
->biSize
);
289 /***********************************************************************
290 * X11DRV_DIB_GetColorCount
292 * Computes the number of colors for the bitmap palette.
293 * Should not be called for a >8-bit deep bitmap.
295 static unsigned int X11DRV_DIB_GetColorCount(const BITMAPINFO
*info
)
298 BOOL core_info
= info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
);
302 colors
= 1 << ((const BITMAPCOREINFO
*)info
)->bmciHeader
.bcBitCount
;
306 colors
= info
->bmiHeader
.biClrUsed
;
307 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
311 ERR("called with >256 colors!\n");
317 /***********************************************************************
320 * Get the info from a bitmap header.
321 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
323 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
324 LONG
*height
, WORD
*bpp
, WORD
*compr
)
329 return DIB_GetBitmapInfoEx( header
, width
, height
, &planes
, bpp
, compr
, &size
);
333 static inline BOOL
colour_is_brighter(RGBQUAD c1
, RGBQUAD c2
)
335 return (c1
.rgbRed
* c1
.rgbRed
+ c1
.rgbGreen
* c1
.rgbGreen
+ c1
.rgbBlue
* c1
.rgbBlue
) >
336 (c2
.rgbRed
* c2
.rgbRed
+ c2
.rgbGreen
* c2
.rgbGreen
+ c2
.rgbBlue
* c2
.rgbBlue
);
339 /***********************************************************************
340 * X11DRV_DIB_GenColorMap
342 * Fills the color map of a bitmap palette. Should not be called
343 * for a >8-bit deep bitmap.
345 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE
*physDev
, int *colorMapping
,
346 WORD coloruse
, WORD depth
, BOOL quads
,
347 const void *colorPtr
, int start
, int end
)
351 if (coloruse
== DIB_RGB_COLORS
)
355 const RGBQUAD
* rgb
= (const RGBQUAD
*)colorPtr
;
357 if (depth
== 1) /* Monochrome */
362 if (GetDIBColorTable( physDev
->hdc
, 0, 2, table
) == 2)
363 invert
= !colour_is_brighter(table
[1], table
[0]);
365 for (i
= start
; i
< end
; i
++, rgb
++)
366 colorMapping
[i
] = ((rgb
->rgbRed
+ rgb
->rgbGreen
+
367 rgb
->rgbBlue
> 255*3/2 && !invert
) ||
368 (rgb
->rgbRed
+ rgb
->rgbGreen
+
369 rgb
->rgbBlue
<= 255*3/2 && invert
));
372 for (i
= start
; i
< end
; i
++, rgb
++)
373 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( NULL
, RGB(rgb
->rgbRed
,
379 const RGBTRIPLE
* rgb
= (const RGBTRIPLE
*)colorPtr
;
381 if (depth
== 1) /* Monochrome */
386 if (GetDIBColorTable( physDev
->hdc
, 0, 2, table
) == 2)
387 invert
= !colour_is_brighter(table
[1], table
[0]);
389 for (i
= start
; i
< end
; i
++, rgb
++)
390 colorMapping
[i
] = ((rgb
->rgbtRed
+ rgb
->rgbtGreen
+
391 rgb
->rgbtBlue
> 255*3/2 && !invert
) ||
392 (rgb
->rgbtRed
+ rgb
->rgbtGreen
+
393 rgb
->rgbtBlue
<= 255*3/2 && invert
));
396 for (i
= start
; i
< end
; i
++, rgb
++)
397 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( NULL
, RGB(rgb
->rgbtRed
,
402 else /* DIB_PAL_COLORS */
404 const WORD
* index
= (const WORD
*)colorPtr
;
406 for (i
= start
; i
< end
; i
++, index
++)
407 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(*index
) );
413 /***********************************************************************
414 * X11DRV_DIB_BuildColorMap
416 * Build the color map from the bitmap palette. Should not be called
417 * for a >8-bit deep bitmap.
419 static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
420 const BITMAPINFO
*info
, int *nColors
)
423 const void *colorPtr
;
427 *nColors
= X11DRV_DIB_GetColorCount(info
);
428 if (!*nColors
) return NULL
;
430 isInfo
= info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
);
431 colorPtr
= (const BYTE
*)info
+ (WORD
)info
->bmiHeader
.biSize
;
432 if (!(colorMapping
= HeapAlloc(GetProcessHeap(), 0, *nColors
* sizeof(int) )))
435 return X11DRV_DIB_GenColorMap( physDev
, colorMapping
, coloruse
, depth
,
436 isInfo
, colorPtr
, 0, *nColors
);
439 /***********************************************************************
440 * X11DRV_DIB_MapColor
442 static int X11DRV_DIB_MapColor( int *physMap
, int nPhysMap
, int phys
, int oldcol
)
446 if ((oldcol
< nPhysMap
) && (physMap
[oldcol
] == phys
))
449 for (color
= 0; color
< nPhysMap
; color
++)
450 if (physMap
[color
] == phys
)
453 WARN("Strange color %08x\n", phys
);
458 /*********************************************************************
459 * X11DRV_DIB_GetNearestIndex
461 * Helper for X11DRV_DIB_GetDIBits.
462 * Returns the nearest colour table index for a given RGB.
463 * Nearest is defined by minimizing the sum of the squares.
465 static INT
X11DRV_DIB_GetNearestIndex(RGBQUAD
*colormap
, int numColors
, BYTE r
, BYTE g
, BYTE b
)
467 INT i
, best
= -1, diff
, bestdiff
= -1;
470 for(color
= colormap
, i
= 0; i
< numColors
; color
++, i
++) {
471 diff
= (r
- color
->rgbRed
) * (r
- color
->rgbRed
) +
472 (g
- color
->rgbGreen
) * (g
- color
->rgbGreen
) +
473 (b
- color
->rgbBlue
) * (b
- color
->rgbBlue
);
476 if(best
== -1 || diff
< bestdiff
) {
483 /*********************************************************************
484 * X11DRV_DIB_MaskToShift
486 * Helper for X11DRV_DIB_GetDIBits.
487 * Returns the by how many bits to shift a given color so that it is
488 * in the proper position.
490 INT
X11DRV_DIB_MaskToShift(DWORD mask
)
498 while ((mask
&1)==0) {
505 /***********************************************************************
506 * X11DRV_DIB_CheckMask
508 * Check RGB mask if it is either 0 or matches visual's mask.
510 static inline int X11DRV_DIB_CheckMask(int red_mask
, int green_mask
, int blue_mask
)
512 return ( red_mask
== 0 && green_mask
== 0 && blue_mask
== 0 ) ||
513 ( red_mask
== visual
->red_mask
&& green_mask
== visual
->green_mask
&&
514 blue_mask
== visual
->blue_mask
);
517 /***********************************************************************
518 * X11DRV_DIB_SetImageBits_1
520 * SetDIBits for a 1-bit deep DIB.
522 static void X11DRV_DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
523 DWORD srcwidth
, DWORD dstwidth
, int left
,
524 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
533 srcbits
= srcbits
+ linebytes
* (lines
- 1);
534 linebytes
= -linebytes
;
537 if ((extra
= (left
& 7)) != 0) {
541 srcbits
+= left
>> 3;
542 width
= min(srcwidth
, dstwidth
);
544 /* ==== pal 1 dib -> any bmp format ==== */
545 for (h
= lines
-1; h
>=0; h
--) {
547 for (i
= width
/8, x
= left
; i
> 0; i
--) {
549 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
550 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
551 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
552 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
553 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
554 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
555 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
556 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
562 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
563 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
564 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
565 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
566 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
567 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
568 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
571 srcbits
+= linebytes
;
575 /***********************************************************************
576 * X11DRV_DIB_GetImageBits_1
578 * GetDIBits for a 1-bit deep DIB.
580 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
581 DWORD dstwidth
, DWORD srcwidth
,
582 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
583 XImage
*bmpImage
, DWORD linebytes
)
586 int h
, width
= min(dstwidth
, srcwidth
);
590 dstbits
= dstbits
+ linebytes
* (lines
- 1);
591 linebytes
= -linebytes
;
594 switch (bmpImage
->depth
)
598 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
600 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
603 for (h
=lines
-1; h
>=0; h
--) {
607 for (x
=0; x
<width
; x
++) {
609 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
610 dstval
|=(X11DRV_DIB_GetNearestIndex
614 srcval
.peBlue
) << (7 - (x
& 7)));
623 dstbits
+= linebytes
;
631 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
, bmpImage
->green_mask
, bmpImage
->blue_mask
)
633 /* ==== pal 8 bmp -> pal 1 dib ==== */
635 const BYTE
* srcpixel
;
638 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
640 for (h
=0; h
<lines
; h
++) {
645 for (x
=0; x
<width
; x
++) {
647 srcval
=srccolors
[*srcpixel
++];
648 dstval
|=(X11DRV_DIB_GetNearestIndex
652 srcval
.peBlue
) << (7-(x
&7)) );
661 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
662 dstbits
+= linebytes
;
673 const WORD
* srcpixel
;
676 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
678 if (bmpImage
->green_mask
==0x03e0) {
679 if (bmpImage
->red_mask
==0x7c00) {
680 /* ==== rgb 555 bmp -> pal 1 dib ==== */
681 for (h
=0; h
<lines
; h
++) {
686 for (x
=0; x
<width
; x
++) {
689 dstval
|=(X11DRV_DIB_GetNearestIndex
691 ((srcval
>> 7) & 0xf8) | /* r */
692 ((srcval
>> 12) & 0x07),
693 ((srcval
>> 2) & 0xf8) | /* g */
694 ((srcval
>> 7) & 0x07),
695 ((srcval
<< 3) & 0xf8) | /* b */
696 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
705 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
706 dstbits
+= linebytes
;
708 } else if (bmpImage
->blue_mask
==0x7c00) {
709 /* ==== bgr 555 bmp -> pal 1 dib ==== */
710 for (h
=0; h
<lines
; h
++) {
715 for (x
=0; x
<width
; x
++) {
718 dstval
|=(X11DRV_DIB_GetNearestIndex
720 ((srcval
<< 3) & 0xf8) | /* r */
721 ((srcval
>> 2) & 0x07),
722 ((srcval
>> 2) & 0xf8) | /* g */
723 ((srcval
>> 7) & 0x07),
724 ((srcval
>> 7) & 0xf8) | /* b */
725 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
734 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
735 dstbits
+= linebytes
;
740 } else if (bmpImage
->green_mask
==0x07e0) {
741 if (bmpImage
->red_mask
==0xf800) {
742 /* ==== rgb 565 bmp -> pal 1 dib ==== */
743 for (h
=0; h
<lines
; h
++) {
748 for (x
=0; x
<width
; x
++) {
751 dstval
|=(X11DRV_DIB_GetNearestIndex
753 ((srcval
>> 8) & 0xf8) | /* r */
754 ((srcval
>> 13) & 0x07),
755 ((srcval
>> 3) & 0xfc) | /* g */
756 ((srcval
>> 9) & 0x03),
757 ((srcval
<< 3) & 0xf8) | /* b */
758 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
767 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
768 dstbits
+= linebytes
;
770 } else if (bmpImage
->blue_mask
==0xf800) {
771 /* ==== bgr 565 bmp -> pal 1 dib ==== */
772 for (h
=0; h
<lines
; h
++) {
777 for (x
=0; x
<width
; x
++) {
780 dstval
|=(X11DRV_DIB_GetNearestIndex
782 ((srcval
<< 3) & 0xf8) | /* r */
783 ((srcval
>> 2) & 0x07),
784 ((srcval
>> 3) & 0xfc) | /* g */
785 ((srcval
>> 9) & 0x03),
786 ((srcval
>> 8) & 0xf8) | /* b */
787 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
796 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
797 dstbits
+= linebytes
;
816 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
817 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
819 if (bmpImage
->green_mask
!=0x00ff00 ||
820 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
822 } else if (bmpImage
->blue_mask
==0xff) {
823 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
824 for (h
=0; h
<lines
; h
++) {
829 for (x
=0; x
<width
; x
++) {
830 dstval
|=(X11DRV_DIB_GetNearestIndex
834 srcbyte
[0]) << (7-(x
&7)) );
835 srcbyte
+=bytes_per_pixel
;
844 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
845 dstbits
+= linebytes
;
848 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
849 for (h
=0; h
<lines
; h
++) {
854 for (x
=0; x
<width
; x
++) {
855 dstval
|=(X11DRV_DIB_GetNearestIndex
859 srcbyte
[2]) << (7-(x
&7)) );
860 srcbyte
+=bytes_per_pixel
;
869 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
870 dstbits
+= linebytes
;
881 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
883 /* ==== any bmp format -> pal 1 dib ==== */
884 if ((unsigned)colors
[0].rgbRed
+colors
[0].rgbGreen
+colors
[0].rgbBlue
>=
885 (unsigned)colors
[1].rgbRed
+colors
[1].rgbGreen
+colors
[1].rgbBlue
)
888 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
889 "%s color mapping\n",
890 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
891 bmpImage
->green_mask
, bmpImage
->blue_mask
,
892 neg
?"negative":"direct" );
894 for (h
=lines
-1; h
>=0; h
--) {
898 for (x
=0; x
<width
; x
++) {
899 dstval
|=((XGetPixel( bmpImage
, x
, h
) >= white
) ^ neg
) << (7 - (x
&7));
908 dstbits
+= linebytes
;
915 /***********************************************************************
916 * X11DRV_DIB_SetImageBits_4
918 * SetDIBits for a 4-bit deep DIB.
920 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
921 DWORD srcwidth
, DWORD dstwidth
, int left
,
922 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
930 srcbits
= srcbits
+ linebytes
* (lines
- 1);
931 linebytes
= -linebytes
;
938 srcbits
+= left
>> 1;
939 width
= min(srcwidth
, dstwidth
);
941 /* ==== pal 4 dib -> any bmp format ==== */
942 for (h
= lines
-1; h
>= 0; h
--) {
944 for (i
= width
/2, x
= left
; i
> 0; i
--) {
945 BYTE srcval
=*srcbyte
++;
946 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
947 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
950 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
951 srcbits
+= linebytes
;
957 /***********************************************************************
958 * X11DRV_DIB_GetImageBits_4
960 * GetDIBits for a 4-bit deep DIB.
962 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
963 DWORD srcwidth
, DWORD dstwidth
,
964 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
965 XImage
*bmpImage
, DWORD linebytes
)
968 int h
, width
= min(srcwidth
, dstwidth
);
974 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
975 linebytes
= -linebytes
;
980 switch (bmpImage
->depth
) {
983 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
985 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
988 for (h
= lines
-1; h
>= 0; h
--) {
992 for (x
= 0; x
< width
; x
++) {
994 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
995 dstval
|=(X11DRV_DIB_GetNearestIndex
999 srcval
.peBlue
) << (4-((x
&1)<<2)));
1008 dstbits
+= linebytes
;
1016 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1018 /* ==== pal 8 bmp -> pal 4 dib ==== */
1019 const void* srcbits
;
1020 const BYTE
*srcpixel
;
1023 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1024 for (h
=0; h
<lines
; h
++) {
1029 for (x
=0; x
<width
; x
++) {
1030 PALETTEENTRY srcval
;
1031 srcval
= srccolors
[*srcpixel
++];
1032 dstval
|=(X11DRV_DIB_GetNearestIndex
1036 srcval
.peBlue
) << (4*(1-(x
&1))) );
1045 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1046 dstbits
+= linebytes
;
1056 const void* srcbits
;
1057 const WORD
* srcpixel
;
1060 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1062 if (bmpImage
->green_mask
==0x03e0) {
1063 if (bmpImage
->red_mask
==0x7c00) {
1064 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1065 for (h
=0; h
<lines
; h
++) {
1070 for (x
=0; x
<width
; x
++) {
1073 dstval
|=(X11DRV_DIB_GetNearestIndex
1075 ((srcval
>> 7) & 0xf8) | /* r */
1076 ((srcval
>> 12) & 0x07),
1077 ((srcval
>> 2) & 0xf8) | /* g */
1078 ((srcval
>> 7) & 0x07),
1079 ((srcval
<< 3) & 0xf8) | /* b */
1080 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1089 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1090 dstbits
+= linebytes
;
1092 } else if (bmpImage
->blue_mask
==0x7c00) {
1093 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1094 for (h
=0; h
<lines
; h
++) {
1099 for (x
=0; x
<width
; x
++) {
1102 dstval
|=(X11DRV_DIB_GetNearestIndex
1104 ((srcval
<< 3) & 0xf8) | /* r */
1105 ((srcval
>> 2) & 0x07),
1106 ((srcval
>> 2) & 0xf8) | /* g */
1107 ((srcval
>> 7) & 0x07),
1108 ((srcval
>> 7) & 0xf8) | /* b */
1109 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1118 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1119 dstbits
+= linebytes
;
1124 } else if (bmpImage
->green_mask
==0x07e0) {
1125 if (bmpImage
->red_mask
==0xf800) {
1126 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1127 for (h
=0; h
<lines
; h
++) {
1132 for (x
=0; x
<width
; x
++) {
1135 dstval
|=(X11DRV_DIB_GetNearestIndex
1137 ((srcval
>> 8) & 0xf8) | /* r */
1138 ((srcval
>> 13) & 0x07),
1139 ((srcval
>> 3) & 0xfc) | /* g */
1140 ((srcval
>> 9) & 0x03),
1141 ((srcval
<< 3) & 0xf8) | /* b */
1142 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1151 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1152 dstbits
+= linebytes
;
1154 } else if (bmpImage
->blue_mask
==0xf800) {
1155 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1156 for (h
=0; h
<lines
; h
++) {
1161 for (x
=0; x
<width
; x
++) {
1164 dstval
|=(X11DRV_DIB_GetNearestIndex
1166 ((srcval
<< 3) & 0xf8) | /* r */
1167 ((srcval
>> 2) & 0x07),
1168 ((srcval
>> 3) & 0xfc) | /* g */
1169 ((srcval
>> 9) & 0x03),
1170 ((srcval
>> 8) & 0xf8) | /* b */
1171 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1180 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1181 dstbits
+= linebytes
;
1193 if (bmpImage
->bits_per_pixel
==24) {
1194 const void* srcbits
;
1195 const BYTE
*srcbyte
;
1198 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1200 if (bmpImage
->green_mask
!=0x00ff00 ||
1201 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1203 } else if (bmpImage
->blue_mask
==0xff) {
1204 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1205 for (h
=0; h
<lines
; h
++) {
1208 for (x
=0; x
<width
/2; x
++) {
1209 /* Do 2 pixels at a time */
1210 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1215 X11DRV_DIB_GetNearestIndex
1223 /* And then the odd pixel */
1224 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1230 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1231 dstbits
+= linebytes
;
1234 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1235 for (h
=0; h
<lines
; h
++) {
1238 for (x
=0; x
<width
/2; x
++) {
1239 /* Do 2 pixels at a time */
1240 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1245 X11DRV_DIB_GetNearestIndex
1253 /* And then the odd pixel */
1254 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1260 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1261 dstbits
+= linebytes
;
1270 const void* srcbits
;
1271 const BYTE
*srcbyte
;
1274 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1276 if (bmpImage
->green_mask
!=0x00ff00 ||
1277 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1279 } else if (bmpImage
->blue_mask
==0xff) {
1280 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1281 for (h
=0; h
<lines
; h
++) {
1284 for (x
=0; x
<width
/2; x
++) {
1285 /* Do 2 pixels at a time */
1286 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1291 X11DRV_DIB_GetNearestIndex
1299 /* And then the odd pixel */
1300 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1306 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1307 dstbits
+= linebytes
;
1310 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1311 for (h
=0; h
<lines
; h
++) {
1314 for (x
=0; x
<width
/2; x
++) {
1315 /* Do 2 pixels at a time */
1316 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1321 X11DRV_DIB_GetNearestIndex
1329 /* And then the odd pixel */
1330 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1336 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1337 dstbits
+= linebytes
;
1348 /* ==== any bmp format -> pal 4 dib ==== */
1349 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1350 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1351 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1352 for (h
=lines
-1; h
>=0; h
--) {
1354 for (x
=0; x
<(width
& ~1); x
+=2) {
1355 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1356 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1359 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1361 dstbits
+= linebytes
;
1368 /***********************************************************************
1369 * X11DRV_DIB_SetImageBits_RLE4
1371 * SetDIBits for a 4-bit deep compressed DIB.
1373 static void X11DRV_DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
,
1374 DWORD srcwidth
, DWORD dstwidth
,
1375 int left
, int *colors
,
1378 unsigned int x
= 0, width
= min(srcwidth
, dstwidth
);
1379 int y
= lines
- 1, c
, length
;
1380 const BYTE
*begin
= bits
;
1385 if (length
) { /* encoded */
1388 if (x
>= (left
+ width
)) break;
1389 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1391 if (!length
--) break;
1392 if (x
>= (left
+ width
)) break;
1393 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1413 default: /* absolute */
1416 if (x
>= left
&& x
< (left
+ width
))
1417 XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1419 if (!length
--) break;
1420 if (x
>= left
&& x
< (left
+ width
))
1421 XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1424 if ((bits
- begin
) & 1)
1433 /***********************************************************************
1434 * X11DRV_DIB_SetImageBits_8
1436 * SetDIBits for an 8-bit deep DIB.
1438 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1439 DWORD srcwidth
, DWORD dstwidth
, int left
,
1440 const int *colors
, XImage
*bmpImage
,
1444 int h
, width
= min(srcwidth
, dstwidth
);
1445 const BYTE
* srcbyte
;
1451 srcbits
= srcbits
+ linebytes
* (lines
-1);
1452 linebytes
= -linebytes
;
1457 switch (bmpImage
->depth
) {
1460 /* Some X servers might have 32 bit/ 16bit deep pixel */
1461 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1462 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1464 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1465 dstbits
=(BYTE
*)bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1466 for (h
= lines
; h
--; ) {
1467 #if defined(__i386__) && defined(__GNUC__)
1468 int _cl1
,_cl2
; /* temp outputs for asm below */
1469 /* Borrowed from DirectDraw */
1470 __asm__
__volatile__(
1475 " movw (%%edx,%%eax,4),%%ax\n"
1477 " xor %%eax,%%eax\n"
1479 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1484 :"eax", "cc", "memory"
1487 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1488 for (x
=0; x
<width
/2; x
++) {
1489 /* Do 2 pixels at a time */
1490 *dstpixel
++=(colors
[srcbyte
[1]] << 16) | colors
[srcbyte
[0]];
1494 /* And then the odd pixel */
1495 *((WORD
*)dstpixel
)=colors
[srcbyte
[0]];
1498 srcbyte
= (srcbits
+= linebytes
);
1499 dstbits
-= bmpImage
->bytes_per_line
;
1506 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1507 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1509 dstbits
=(BYTE
*)bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1510 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1511 for (h
= lines
; h
--; ) {
1512 #if defined(__i386__) && defined(__GNUC__)
1513 int _cl1
,_cl2
; /* temp outputs for asm below */
1514 /* Borrowed from DirectDraw */
1515 __asm__
__volatile__(
1520 " movl (%%edx,%%eax,4),%%eax\n"
1522 " xor %%eax,%%eax\n"
1524 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1529 :"eax", "cc", "memory"
1532 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1533 for (x
=0; x
<width
; x
++) {
1534 *dstpixel
++=colors
[*srcbyte
++];
1537 srcbyte
= (srcbits
+= linebytes
);
1538 dstbits
-= bmpImage
->bytes_per_line
;
1544 break; /* use slow generic case below */
1547 /* ==== pal 8 dib -> any bmp format ==== */
1548 for (h
=lines
-1; h
>=0; h
--) {
1549 for (x
=left
; x
<width
+left
; x
++) {
1550 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1552 srcbyte
= (srcbits
+= linebytes
);
1556 /***********************************************************************
1557 * X11DRV_DIB_GetImageBits_8
1559 * GetDIBits for an 8-bit deep DIB.
1561 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1562 DWORD srcwidth
, DWORD dstwidth
,
1563 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1564 XImage
*bmpImage
, DWORD linebytes
)
1567 int h
, width
= min(srcwidth
, dstwidth
);
1573 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1574 linebytes
= -linebytes
;
1579 * This condition is true when GetImageBits has been called by
1580 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1581 * 256 colormaps, so we'll just use it for GetDIBits calls.
1582 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1584 if (!srccolors
) goto updatesection
;
1586 switch (bmpImage
->depth
) {
1589 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1592 /* ==== pal 1 bmp -> pal 8 dib ==== */
1593 /* ==== pal 4 bmp -> pal 8 dib ==== */
1594 for (h
=lines
-1; h
>=0; h
--) {
1596 for (x
=0; x
<width
; x
++) {
1597 PALETTEENTRY srcval
;
1598 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1599 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1604 dstbits
+= linebytes
;
1612 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1614 /* ==== pal 8 bmp -> pal 8 dib ==== */
1615 const void* srcbits
;
1616 const BYTE
* srcpixel
;
1618 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1619 for (h
=0; h
<lines
; h
++) {
1622 for (x
= 0; x
< width
; x
++) {
1623 PALETTEENTRY srcval
;
1624 srcval
=srccolors
[*srcpixel
++];
1625 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1630 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1631 dstbits
+= linebytes
;
1641 const void* srcbits
;
1642 const WORD
* srcpixel
;
1645 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1647 if (bmpImage
->green_mask
==0x03e0) {
1648 if (bmpImage
->red_mask
==0x7c00) {
1649 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1650 for (h
=0; h
<lines
; h
++) {
1653 for (x
=0; x
<width
; x
++) {
1656 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1658 ((srcval
>> 7) & 0xf8) | /* r */
1659 ((srcval
>> 12) & 0x07),
1660 ((srcval
>> 2) & 0xf8) | /* g */
1661 ((srcval
>> 7) & 0x07),
1662 ((srcval
<< 3) & 0xf8) | /* b */
1663 ((srcval
>> 2) & 0x07) );
1665 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1666 dstbits
+= linebytes
;
1668 } else if (bmpImage
->blue_mask
==0x7c00) {
1669 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1670 for (h
=0; h
<lines
; h
++) {
1673 for (x
=0; x
<width
; x
++) {
1676 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1678 ((srcval
<< 3) & 0xf8) | /* r */
1679 ((srcval
>> 2) & 0x07),
1680 ((srcval
>> 2) & 0xf8) | /* g */
1681 ((srcval
>> 7) & 0x07),
1682 ((srcval
>> 7) & 0xf8) | /* b */
1683 ((srcval
>> 12) & 0x07) );
1685 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1686 dstbits
+= linebytes
;
1691 } else if (bmpImage
->green_mask
==0x07e0) {
1692 if (bmpImage
->red_mask
==0xf800) {
1693 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1694 for (h
=0; h
<lines
; h
++) {
1697 for (x
=0; x
<width
; x
++) {
1700 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1702 ((srcval
>> 8) & 0xf8) | /* r */
1703 ((srcval
>> 13) & 0x07),
1704 ((srcval
>> 3) & 0xfc) | /* g */
1705 ((srcval
>> 9) & 0x03),
1706 ((srcval
<< 3) & 0xf8) | /* b */
1707 ((srcval
>> 2) & 0x07) );
1709 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1710 dstbits
+= linebytes
;
1712 } else if (bmpImage
->blue_mask
==0xf800) {
1713 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1714 for (h
=0; h
<lines
; h
++) {
1717 for (x
=0; x
<width
; x
++) {
1720 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1722 ((srcval
<< 3) & 0xf8) | /* r */
1723 ((srcval
>> 2) & 0x07),
1724 ((srcval
>> 3) & 0xfc) | /* g */
1725 ((srcval
>> 9) & 0x03),
1726 ((srcval
>> 8) & 0xf8) | /* b */
1727 ((srcval
>> 13) & 0x07) );
1729 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1730 dstbits
+= linebytes
;
1744 const void* srcbits
;
1745 const BYTE
*srcbyte
;
1747 int bytes_per_pixel
;
1749 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1750 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1752 if (bmpImage
->green_mask
!=0x00ff00 ||
1753 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1755 } else if (bmpImage
->blue_mask
==0xff) {
1756 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1757 for (h
=0; h
<lines
; h
++) {
1760 for (x
=0; x
<width
; x
++) {
1761 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1766 srcbyte
+=bytes_per_pixel
;
1768 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1769 dstbits
+= linebytes
;
1772 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1773 for (h
=0; h
<lines
; h
++) {
1776 for (x
=0; x
<width
; x
++) {
1777 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1782 srcbyte
+=bytes_per_pixel
;
1784 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1785 dstbits
+= linebytes
;
1793 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1794 bmpImage
->depth
, bmpImage
->red_mask
,
1795 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1797 /* ==== any bmp format -> pal 8 dib ==== */
1798 for (h
=lines
-1; h
>=0; h
--) {
1800 for (x
=0; x
<width
; x
++) {
1801 *dstbyte
=X11DRV_DIB_MapColor
1803 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1806 dstbits
+= linebytes
;
1812 /***********************************************************************
1813 * X11DRV_DIB_SetImageBits_RLE8
1815 * SetDIBits for an 8-bit deep compressed DIB.
1817 * This function rewritten 941113 by James Youngman. WINE blew out when I
1818 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1820 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1821 * 'End of bitmap' escape code. This code is very much laxer in what it
1822 * allows to end the expansion. Possibly too lax. See the note by
1823 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1824 * bitmap should end with RleEnd, but on the other hand, software exists
1825 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1828 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1829 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1832 static void X11DRV_DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
,
1833 DWORD srcwidth
, DWORD dstwidth
,
1834 int left
, int *colors
,
1837 unsigned int x
; /* X-position on each line. Increases. */
1838 int y
; /* Line #. Starts at lines-1, decreases */
1839 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
1840 BYTE length
; /* The length pf a run */
1841 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
1844 * Note that the bitmap data is stored by Windows starting at the
1845 * bottom line of the bitmap and going upwards. Within each line,
1846 * the data is stored left-to-right. That's the reason why line
1847 * goes from lines-1 to 0. [JAY]
1857 * If the length byte is not zero (which is the escape value),
1858 * We have a run of length pixels all the same colour. The colour
1859 * index is stored next.
1861 * If the length byte is zero, we need to read the next byte to
1862 * know what to do. [JAY]
1867 * [Run-Length] Encoded mode
1869 int color
= colors
[*pIn
++];
1870 while (length
-- && x
< (left
+ dstwidth
)) {
1871 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1878 * Escape codes (may be an absolute sequence though)
1880 escape_code
= (*pIn
++);
1889 /* Not all RLE8 bitmaps end with this code. For
1890 * example, Paint Shop Pro produces some that don't.
1891 * That's (I think) what caused the previous
1892 * implementation to fail. [JAY]
1901 default: /* switch to absolute mode */
1902 length
= escape_code
;
1905 int color
= colors
[*pIn
++];
1906 if (x
>= (left
+ dstwidth
))
1911 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1915 * If you think for a moment you'll realise that the
1916 * only time we could ever possibly read an odd
1917 * number of bytes is when there is a 0x00 (escape),
1918 * a value >0x02 (absolute mode) and then an odd-
1919 * length run. Therefore this is the only place we
1920 * need to worry about it. Everywhere else the
1921 * bytes are always read in pairs. [JAY]
1923 if (escape_code
& 1) pIn
++; /* Throw away the pad byte. */
1925 } /* switch (escape_code) : Escape sequence */
1931 /***********************************************************************
1932 * X11DRV_DIB_SetImageBits_16
1934 * SetDIBits for a 16-bit deep DIB.
1936 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1937 DWORD srcwidth
, DWORD dstwidth
, int left
,
1938 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1939 XImage
*bmpImage
, DWORD linebytes
)
1942 int h
, width
= min(srcwidth
, dstwidth
);
1943 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1948 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1949 linebytes
= -linebytes
;
1952 switch (bmpImage
->depth
)
1959 srcbits
=srcbits
+left
*2;
1960 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1962 if (bmpImage
->green_mask
==0x03e0) {
1963 if (gSrc
==bmpImage
->green_mask
) {
1964 if (rSrc
==bmpImage
->red_mask
) {
1965 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1966 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1967 convs
->Convert_5x5_asis
1970 dstbits
,-bmpImage
->bytes_per_line
);
1971 } else if (rSrc
==bmpImage
->blue_mask
) {
1972 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1973 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1974 convs
->Convert_555_reverse
1977 dstbits
,-bmpImage
->bytes_per_line
);
1980 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1981 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1982 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1983 convs
->Convert_565_to_555_asis
1986 dstbits
,-bmpImage
->bytes_per_line
);
1988 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1989 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1990 convs
->Convert_565_to_555_reverse
1993 dstbits
,-bmpImage
->bytes_per_line
);
1996 } else if (bmpImage
->green_mask
==0x07e0) {
1997 if (gSrc
==bmpImage
->green_mask
) {
1998 if (rSrc
==bmpImage
->red_mask
) {
1999 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
2000 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
2001 convs
->Convert_5x5_asis
2004 dstbits
,-bmpImage
->bytes_per_line
);
2006 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
2007 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
2008 convs
->Convert_565_reverse
2011 dstbits
,-bmpImage
->bytes_per_line
);
2014 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
2015 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
2016 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
2017 convs
->Convert_555_to_565_asis
2020 dstbits
,-bmpImage
->bytes_per_line
);
2022 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
2023 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
2024 convs
->Convert_555_to_565_reverse
2027 dstbits
,-bmpImage
->bytes_per_line
);
2037 if (bmpImage
->bits_per_pixel
==24) {
2040 srcbits
=srcbits
+left
*2;
2041 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2043 if (bmpImage
->green_mask
!=0x00ff00 ||
2044 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2046 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2047 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2049 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2050 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2051 convs
->Convert_555_to_888_asis
2054 dstbits
,-bmpImage
->bytes_per_line
);
2056 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2057 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2058 convs
->Convert_565_to_888_asis
2061 dstbits
,-bmpImage
->bytes_per_line
);
2065 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2066 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2067 convs
->Convert_555_to_888_reverse
2070 dstbits
,-bmpImage
->bytes_per_line
);
2072 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2073 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2074 convs
->Convert_565_to_888_reverse
2077 dstbits
,-bmpImage
->bytes_per_line
);
2088 srcbits
=srcbits
+left
*2;
2089 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2091 if (bmpImage
->green_mask
!=0x00ff00 ||
2092 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2094 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2095 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2097 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2098 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2099 convs
->Convert_555_to_0888_asis
2102 dstbits
,-bmpImage
->bytes_per_line
);
2104 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2105 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2106 convs
->Convert_565_to_0888_asis
2109 dstbits
,-bmpImage
->bytes_per_line
);
2113 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2114 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2115 convs
->Convert_555_to_0888_reverse
2118 dstbits
,-bmpImage
->bytes_per_line
);
2120 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2121 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2122 convs
->Convert_565_to_0888_reverse
2125 dstbits
,-bmpImage
->bytes_per_line
);
2133 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2134 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2135 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2141 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2142 const WORD
* srcpixel
;
2143 int rShift1
,gShift1
,bShift1
;
2144 int rShift2
,gShift2
,bShift2
;
2147 /* Set color scaling values */
2148 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
2149 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
2150 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
2155 /* Green has 5 bits, like the others */
2159 /* Green has 6 bits, not 5. Compensate. */
2168 /* We could split it into four separate cases to optimize
2169 * but it is probably not worth it.
2171 for (h
=lines
-1; h
>=0; h
--) {
2172 srcpixel
=(const WORD
*)srcbits
;
2173 for (x
=left
; x
<width
+left
; x
++) {
2175 BYTE red
,green
,blue
;
2176 srcval
=*srcpixel
++ << 16;
2177 red
= ((srcval
>> rShift1
) & 0xf8) |
2178 ((srcval
>> rShift2
) & 0x07);
2179 green
=((srcval
>> gShift1
) & gMask1
) |
2180 ((srcval
>> gShift2
) & gMask2
);
2181 blue
= ((srcval
>> bShift1
) & 0xf8) |
2182 ((srcval
>> bShift2
) & 0x07);
2183 XPutPixel(bmpImage
, x
, h
,
2184 X11DRV_PALETTE_ToPhysical
2185 (physDev
, RGB(red
,green
,blue
)));
2187 srcbits
+= linebytes
;
2195 /***********************************************************************
2196 * X11DRV_DIB_GetImageBits_16
2198 * GetDIBits for an 16-bit deep DIB.
2200 static void X11DRV_DIB_GetImageBits_16( int lines
, BYTE
*dstbits
,
2201 DWORD dstwidth
, DWORD srcwidth
,
2202 PALETTEENTRY
*srccolors
,
2203 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2204 XImage
*bmpImage
, DWORD dibpitch
)
2207 int h
, width
= min(srcwidth
, dstwidth
);
2208 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2210 DWORD linebytes
= dibpitch
;
2215 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
2216 linebytes
= -linebytes
;
2219 switch (bmpImage
->depth
)
2224 const char* srcbits
;
2226 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2228 if (bmpImage
->green_mask
==0x03e0) {
2229 if (gDst
==bmpImage
->green_mask
) {
2230 if (rDst
==bmpImage
->red_mask
) {
2231 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2232 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2233 convs
->Convert_5x5_asis
2235 srcbits
,-bmpImage
->bytes_per_line
,
2238 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2239 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2240 convs
->Convert_555_reverse
2242 srcbits
,-bmpImage
->bytes_per_line
,
2246 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2247 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2248 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2249 convs
->Convert_555_to_565_asis
2251 srcbits
,-bmpImage
->bytes_per_line
,
2254 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2255 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2256 convs
->Convert_555_to_565_reverse
2258 srcbits
,-bmpImage
->bytes_per_line
,
2262 } else if (bmpImage
->green_mask
==0x07e0) {
2263 if (gDst
==bmpImage
->green_mask
) {
2264 if (rDst
== bmpImage
->red_mask
) {
2265 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2266 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2267 convs
->Convert_5x5_asis
2269 srcbits
,-bmpImage
->bytes_per_line
,
2272 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2273 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2274 convs
->Convert_565_reverse
2276 srcbits
,-bmpImage
->bytes_per_line
,
2280 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2281 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2282 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2283 convs
->Convert_565_to_555_asis
2285 srcbits
,-bmpImage
->bytes_per_line
,
2288 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2289 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2290 convs
->Convert_565_to_555_reverse
2292 srcbits
,-bmpImage
->bytes_per_line
,
2303 if (bmpImage
->bits_per_pixel
== 24) {
2304 const char* srcbits
;
2306 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2308 if (bmpImage
->green_mask
!=0x00ff00 ||
2309 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2311 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2312 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2314 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2315 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2316 convs
->Convert_888_to_555_asis
2318 srcbits
,-bmpImage
->bytes_per_line
,
2321 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2322 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2323 convs
->Convert_888_to_565_asis
2325 srcbits
,-bmpImage
->bytes_per_line
,
2330 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2331 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2332 convs
->Convert_888_to_555_reverse
2334 srcbits
,-bmpImage
->bytes_per_line
,
2337 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2338 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2339 convs
->Convert_888_to_565_reverse
2341 srcbits
,-bmpImage
->bytes_per_line
,
2351 const char* srcbits
;
2353 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2355 if (bmpImage
->green_mask
!=0x00ff00 ||
2356 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2358 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2359 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2361 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2362 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2363 convs
->Convert_0888_to_555_asis
2365 srcbits
,-bmpImage
->bytes_per_line
,
2368 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2369 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2370 convs
->Convert_0888_to_565_asis
2372 srcbits
,-bmpImage
->bytes_per_line
,
2377 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2378 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2379 convs
->Convert_0888_to_555_reverse
2381 srcbits
,-bmpImage
->bytes_per_line
,
2384 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2385 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2386 convs
->Convert_0888_to_565_reverse
2388 srcbits
,-bmpImage
->bytes_per_line
,
2397 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2399 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2400 int rShift
,gShift
,bShift
;
2403 /* Shift everything 16 bits left so that all shifts are >0,
2404 * even for BGR DIBs. Then a single >> 16 will bring everything
2407 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2408 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2409 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2411 /* 6 bits for the green */
2417 for (h
= lines
- 1; h
>= 0; h
--) {
2418 dstpixel
=(LPWORD
)dstbits
;
2419 for (x
= 0; x
< width
; x
++) {
2420 PALETTEENTRY srcval
;
2422 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2423 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2424 ((srcval
.peGreen
<< gShift
) & gDst
) |
2425 ((srcval
.peBlue
<< bShift
) & bDst
);
2426 *dstpixel
++=dstval
>> 16;
2428 dstbits
+= linebytes
;
2436 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2438 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2439 int rShift
,gShift
,bShift
;
2440 const BYTE
* srcbits
;
2441 const BYTE
* srcpixel
;
2444 /* Shift everything 16 bits left so that all shifts are >0,
2445 * even for BGR DIBs. Then a single >> 16 will bring everything
2448 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2449 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2450 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2452 /* 6 bits for the green */
2458 srcbits
=(BYTE
*)bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2459 for (h
=0; h
<lines
; h
++) {
2461 dstpixel
=(LPWORD
)dstbits
;
2462 for (x
= 0; x
< width
; x
++) {
2463 PALETTEENTRY srcval
;
2465 srcval
=srccolors
[*srcpixel
++];
2466 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2467 ((srcval
.peGreen
<< gShift
) & gDst
) |
2468 ((srcval
.peBlue
<< bShift
) & bDst
);
2469 *dstpixel
++=dstval
>> 16;
2471 srcbits
-= bmpImage
->bytes_per_line
;
2472 dstbits
+= linebytes
;
2482 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2483 int rShift
,gShift
,bShift
;
2486 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2487 bmpImage
->depth
, bmpImage
->red_mask
,
2488 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2491 /* Shift everything 16 bits left so that all shifts are >0,
2492 * even for BGR DIBs. Then a single >> 16 will bring everything
2495 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2496 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2497 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2499 /* 6 bits for the green */
2505 for (h
= lines
- 1; h
>= 0; h
--) {
2506 dstpixel
=(LPWORD
)dstbits
;
2507 for (x
= 0; x
< width
; x
++) {
2510 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
2511 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2512 ((GetGValue(srcval
) << gShift
) & gDst
) |
2513 ((GetBValue(srcval
) << bShift
) & bDst
);
2514 *dstpixel
++=dstval
>> 16;
2516 dstbits
+= linebytes
;
2524 /***********************************************************************
2525 * X11DRV_DIB_SetImageBits_24
2527 * SetDIBits for a 24-bit deep DIB.
2529 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2530 DWORD srcwidth
, DWORD dstwidth
, int left
,
2531 X11DRV_PDEVICE
*physDev
,
2532 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2533 XImage
*bmpImage
, DWORD linebytes
)
2536 int h
, width
= min(srcwidth
, dstwidth
);
2537 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2542 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2543 linebytes
= -linebytes
;
2546 switch (bmpImage
->depth
)
2549 if (bmpImage
->bits_per_pixel
==24) {
2552 srcbits
=srcbits
+left
*3;
2553 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2555 if (bmpImage
->green_mask
!=0x00ff00 ||
2556 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2558 } else if (rSrc
==bmpImage
->red_mask
) {
2559 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2560 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2561 convs
->Convert_888_asis
2564 dstbits
,-bmpImage
->bytes_per_line
);
2566 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2567 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2568 convs
->Convert_888_reverse
2571 dstbits
,-bmpImage
->bytes_per_line
);
2581 srcbits
=srcbits
+left
*3;
2582 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2584 if (bmpImage
->green_mask
!=0x00ff00 ||
2585 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2587 } else if (rSrc
==bmpImage
->red_mask
) {
2588 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2589 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2590 convs
->Convert_888_to_0888_asis
2593 dstbits
,-bmpImage
->bytes_per_line
);
2595 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2596 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2597 convs
->Convert_888_to_0888_reverse
2600 dstbits
,-bmpImage
->bytes_per_line
);
2610 srcbits
=srcbits
+left
*3;
2611 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2613 if (bmpImage
->green_mask
==0x03e0) {
2614 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2615 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2616 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2617 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2618 convs
->Convert_888_to_555_asis
2621 dstbits
,-bmpImage
->bytes_per_line
);
2622 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2623 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2624 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2625 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2626 convs
->Convert_888_to_555_reverse
2629 dstbits
,-bmpImage
->bytes_per_line
);
2633 } else if (bmpImage
->green_mask
==0x07e0) {
2634 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2635 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2636 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2637 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2638 convs
->Convert_888_to_565_asis
2641 dstbits
,-bmpImage
->bytes_per_line
);
2642 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2643 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2644 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2645 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2646 convs
->Convert_888_to_565_reverse
2649 dstbits
,-bmpImage
->bytes_per_line
);
2661 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2662 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2663 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2669 /* ==== rgb 888 dib -> any bmp format ==== */
2670 const BYTE
* srcbyte
;
2672 /* Windows only supports one 24bpp DIB format: RGB888 */
2674 for (h
= lines
- 1; h
>= 0; h
--) {
2676 for (x
= left
; x
< width
+left
; x
++) {
2677 XPutPixel(bmpImage
, x
, h
,
2678 X11DRV_PALETTE_ToPhysical
2679 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2682 srcbits
+= linebytes
;
2690 /***********************************************************************
2691 * X11DRV_DIB_GetImageBits_24
2693 * GetDIBits for an 24-bit deep DIB.
2695 static void X11DRV_DIB_GetImageBits_24( int lines
, BYTE
*dstbits
,
2696 DWORD dstwidth
, DWORD srcwidth
,
2697 PALETTEENTRY
*srccolors
,
2698 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2699 XImage
*bmpImage
, DWORD linebytes
)
2702 int h
, width
= min(srcwidth
, dstwidth
);
2703 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2708 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2709 linebytes
= -linebytes
;
2712 switch (bmpImage
->depth
)
2715 if (bmpImage
->bits_per_pixel
==24) {
2716 const char* srcbits
;
2718 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2720 if (bmpImage
->green_mask
!=0x00ff00 ||
2721 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2723 } else if (rDst
==bmpImage
->red_mask
) {
2724 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2725 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2726 convs
->Convert_888_asis
2728 srcbits
,-bmpImage
->bytes_per_line
,
2731 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2732 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2733 convs
->Convert_888_reverse
2735 srcbits
,-bmpImage
->bytes_per_line
,
2744 const char* srcbits
;
2746 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2748 if (bmpImage
->green_mask
!=0x00ff00 ||
2749 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2751 } else if (rDst
==bmpImage
->red_mask
) {
2752 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2753 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2754 convs
->Convert_0888_to_888_asis
2756 srcbits
,-bmpImage
->bytes_per_line
,
2759 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2760 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2761 convs
->Convert_0888_to_888_reverse
2763 srcbits
,-bmpImage
->bytes_per_line
,
2772 const char* srcbits
;
2774 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2776 if (bmpImage
->green_mask
==0x03e0) {
2777 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2778 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2779 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2780 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2781 convs
->Convert_555_to_888_asis
2783 srcbits
,-bmpImage
->bytes_per_line
,
2785 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2786 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2787 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2788 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2789 convs
->Convert_555_to_888_reverse
2791 srcbits
,-bmpImage
->bytes_per_line
,
2796 } else if (bmpImage
->green_mask
==0x07e0) {
2797 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2798 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2799 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2800 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2801 convs
->Convert_565_to_888_asis
2803 srcbits
,-bmpImage
->bytes_per_line
,
2805 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2806 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2807 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2808 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2809 convs
->Convert_565_to_888_reverse
2811 srcbits
,-bmpImage
->bytes_per_line
,
2824 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2826 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2829 /* Windows only supports one 24bpp DIB format: rgb 888 */
2830 for (h
= lines
- 1; h
>= 0; h
--) {
2832 for (x
= 0; x
< width
; x
++) {
2833 PALETTEENTRY srcval
;
2834 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2835 dstbyte
[0]=srcval
.peBlue
;
2836 dstbyte
[1]=srcval
.peGreen
;
2837 dstbyte
[2]=srcval
.peRed
;
2840 dstbits
+= linebytes
;
2848 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2850 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2851 const void* srcbits
;
2852 const BYTE
* srcpixel
;
2855 /* Windows only supports one 24bpp DIB format: rgb 888 */
2856 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2857 for (h
= lines
- 1; h
>= 0; h
--) {
2860 for (x
= 0; x
< width
; x
++ ) {
2861 PALETTEENTRY srcval
;
2862 srcval
=srccolors
[*srcpixel
++];
2863 dstbyte
[0]=srcval
.peBlue
;
2864 dstbyte
[1]=srcval
.peGreen
;
2865 dstbyte
[2]=srcval
.peRed
;
2868 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2869 dstbits
+= linebytes
;
2879 /* ==== any bmp format -> 888 dib ==== */
2882 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2883 bmpImage
->depth
, bmpImage
->red_mask
,
2884 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2887 /* Windows only supports one 24bpp DIB format: rgb 888 */
2888 for (h
= lines
- 1; h
>= 0; h
--) {
2890 for (x
= 0; x
< width
; x
++) {
2891 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2892 (XGetPixel( bmpImage
, x
, h
));
2893 dstbyte
[0]=GetBValue(srcval
);
2894 dstbyte
[1]=GetGValue(srcval
);
2895 dstbyte
[2]=GetRValue(srcval
);
2898 dstbits
+= linebytes
;
2906 /***********************************************************************
2907 * X11DRV_DIB_SetImageBits_32
2909 * SetDIBits for a 32-bit deep DIB.
2911 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2912 DWORD srcwidth
, DWORD dstwidth
, int left
,
2913 X11DRV_PDEVICE
*physDev
,
2914 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2919 int h
, width
= min(srcwidth
, dstwidth
);
2920 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2925 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2926 linebytes
= -linebytes
;
2929 switch (bmpImage
->depth
)
2932 if (bmpImage
->bits_per_pixel
==24) {
2935 srcbits
=srcbits
+left
*4;
2936 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2938 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2939 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2940 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2941 convs
->Convert_0888_to_888_asis
2944 dstbits
,-bmpImage
->bytes_per_line
);
2945 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2946 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2948 /* the tests below assume sane bmpImage masks */
2949 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2950 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2951 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2952 convs
->Convert_0888_to_888_reverse
2955 dstbits
,-bmpImage
->bytes_per_line
);
2956 } else if (bmpImage
->blue_mask
==0xff) {
2957 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2958 convs
->Convert_any0888_to_rgb888
2962 dstbits
,-bmpImage
->bytes_per_line
);
2964 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2965 convs
->Convert_any0888_to_bgr888
2969 dstbits
,-bmpImage
->bytes_per_line
);
2979 srcbits
=srcbits
+left
*4;
2980 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2982 if (gSrc
==bmpImage
->green_mask
) {
2983 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2984 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2985 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2986 convs
->Convert_0888_asis
2989 dstbits
,-bmpImage
->bytes_per_line
);
2990 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2991 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2993 /* the tests below assume sane bmpImage masks */
2994 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
2995 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2996 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2997 convs
->Convert_0888_reverse
3000 dstbits
,-bmpImage
->bytes_per_line
);
3002 /* ==== any 0888 dib -> any 0888 bmp ==== */
3003 convs
->Convert_0888_any
3007 dstbits
,-bmpImage
->bytes_per_line
,
3008 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3010 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3011 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3013 /* the tests below assume sane bmpImage masks */
3015 /* ==== any 0888 dib -> any 0888 bmp ==== */
3016 convs
->Convert_0888_any
3020 dstbits
,-bmpImage
->bytes_per_line
,
3021 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3031 srcbits
=srcbits
+left
*4;
3032 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
3034 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
3035 if (bmpImage
->green_mask
==0x03e0) {
3036 if (bmpImage
->red_mask
==0x7f00) {
3037 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
3038 convs
->Convert_0888_to_555_asis
3041 dstbits
,-bmpImage
->bytes_per_line
);
3042 } else if (bmpImage
->blue_mask
==0x7f00) {
3043 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
3044 convs
->Convert_0888_to_555_reverse
3047 dstbits
,-bmpImage
->bytes_per_line
);
3051 } else if (bmpImage
->green_mask
==0x07e0) {
3052 if (bmpImage
->red_mask
==0xf800) {
3053 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3054 convs
->Convert_0888_to_565_asis
3057 dstbits
,-bmpImage
->bytes_per_line
);
3058 } else if (bmpImage
->blue_mask
==0xf800) {
3059 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3060 convs
->Convert_0888_to_565_reverse
3063 dstbits
,-bmpImage
->bytes_per_line
);
3070 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
3071 if (bmpImage
->green_mask
==0x03e0) {
3072 if (bmpImage
->blue_mask
==0x7f00) {
3073 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3074 convs
->Convert_0888_to_555_asis
3077 dstbits
,-bmpImage
->bytes_per_line
);
3078 } else if (bmpImage
->red_mask
==0x7f00) {
3079 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3080 convs
->Convert_0888_to_555_reverse
3083 dstbits
,-bmpImage
->bytes_per_line
);
3087 } else if (bmpImage
->green_mask
==0x07e0) {
3088 if (bmpImage
->blue_mask
==0xf800) {
3089 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3090 convs
->Convert_0888_to_565_asis
3093 dstbits
,-bmpImage
->bytes_per_line
);
3094 } else if (bmpImage
->red_mask
==0xf800) {
3095 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3096 convs
->Convert_0888_to_565_reverse
3099 dstbits
,-bmpImage
->bytes_per_line
);
3107 if (bmpImage
->green_mask
==0x03e0 &&
3108 (bmpImage
->red_mask
==0x7f00 ||
3109 bmpImage
->blue_mask
==0x7f00)) {
3110 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3111 convs
->Convert_any0888_to_5x5
3115 dstbits
,-bmpImage
->bytes_per_line
,
3116 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3117 } else if (bmpImage
->green_mask
==0x07e0 &&
3118 (bmpImage
->red_mask
==0xf800 ||
3119 bmpImage
->blue_mask
==0xf800)) {
3120 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3121 convs
->Convert_any0888_to_5x5
3125 dstbits
,-bmpImage
->bytes_per_line
,
3126 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3136 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3137 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
3138 bmpImage
->green_mask
, bmpImage
->blue_mask
);
3144 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3145 const DWORD
* srcpixel
;
3146 int rShift
,gShift
,bShift
;
3148 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
3149 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
3150 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
3152 for (h
= lines
- 1; h
>= 0; h
--) {
3153 srcpixel
=(const DWORD
*)srcbits
;
3154 for (x
= left
; x
< width
+left
; x
++) {
3156 BYTE red
,green
,blue
;
3157 srcvalue
=*srcpixel
++;
3158 red
= (srcvalue
>> rShift
) & 0xff;
3159 green
=(srcvalue
>> gShift
) & 0xff;
3160 blue
= (srcvalue
>> bShift
) & 0xff;
3161 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
3162 (physDev
, RGB(red
,green
,blue
)));
3164 srcbits
+= linebytes
;
3172 /***********************************************************************
3173 * X11DRV_DIB_GetImageBits_32
3175 * GetDIBits for an 32-bit deep DIB.
3177 static void X11DRV_DIB_GetImageBits_32( int lines
, BYTE
*dstbits
,
3178 DWORD dstwidth
, DWORD srcwidth
,
3179 PALETTEENTRY
*srccolors
,
3180 DWORD rDst
, DWORD gDst
, DWORD bDst
,
3181 XImage
*bmpImage
, DWORD linebytes
)
3184 int h
, width
= min(srcwidth
, dstwidth
);
3186 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
3191 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
3192 linebytes
= -linebytes
;
3197 switch (bmpImage
->depth
)
3200 if (bmpImage
->bits_per_pixel
==24) {
3201 const void* srcbits
;
3203 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3205 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
3206 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3207 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3208 convs
->Convert_888_to_0888_asis
3210 srcbits
,-bmpImage
->bytes_per_line
,
3212 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3213 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3215 /* the tests below assume sane bmpImage masks */
3216 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
3217 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3218 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3219 convs
->Convert_888_to_0888_reverse
3221 srcbits
,-bmpImage
->bytes_per_line
,
3223 } else if (bmpImage
->blue_mask
==0xff) {
3224 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3225 convs
->Convert_rgb888_to_any0888
3227 srcbits
,-bmpImage
->bytes_per_line
,
3231 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3232 convs
->Convert_bgr888_to_any0888
3234 srcbits
,-bmpImage
->bytes_per_line
,
3244 const char* srcbits
;
3246 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3248 if (gDst
==bmpImage
->green_mask
) {
3249 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
3250 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3251 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3252 convs
->Convert_0888_asis
3254 srcbits
,-bmpImage
->bytes_per_line
,
3256 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3257 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3259 /* the tests below assume sane bmpImage masks */
3260 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
3261 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3262 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3263 convs
->Convert_0888_reverse
3265 srcbits
,-bmpImage
->bytes_per_line
,
3268 /* ==== any 0888 bmp -> any 0888 dib ==== */
3269 convs
->Convert_0888_any
3271 srcbits
,-bmpImage
->bytes_per_line
,
3272 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3276 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3277 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3279 /* the tests below assume sane bmpImage masks */
3281 /* ==== any 0888 bmp -> any 0888 dib ==== */
3282 convs
->Convert_0888_any
3284 srcbits
,-bmpImage
->bytes_per_line
,
3285 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3295 const char* srcbits
;
3297 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3299 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
3300 if (bmpImage
->green_mask
==0x03e0) {
3301 if (bmpImage
->red_mask
==0x7f00) {
3302 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3303 convs
->Convert_555_to_0888_asis
3305 srcbits
,-bmpImage
->bytes_per_line
,
3307 } else if (bmpImage
->blue_mask
==0x7f00) {
3308 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3309 convs
->Convert_555_to_0888_reverse
3311 srcbits
,-bmpImage
->bytes_per_line
,
3316 } else if (bmpImage
->green_mask
==0x07e0) {
3317 if (bmpImage
->red_mask
==0xf800) {
3318 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3319 convs
->Convert_565_to_0888_asis
3321 srcbits
,-bmpImage
->bytes_per_line
,
3323 } else if (bmpImage
->blue_mask
==0xf800) {
3324 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3325 convs
->Convert_565_to_0888_reverse
3327 srcbits
,-bmpImage
->bytes_per_line
,
3335 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
3336 if (bmpImage
->green_mask
==0x03e0) {
3337 if (bmpImage
->blue_mask
==0x7f00) {
3338 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3339 convs
->Convert_555_to_0888_asis
3341 srcbits
,-bmpImage
->bytes_per_line
,
3343 } else if (bmpImage
->red_mask
==0x7f00) {
3344 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3345 convs
->Convert_555_to_0888_reverse
3347 srcbits
,-bmpImage
->bytes_per_line
,
3352 } else if (bmpImage
->green_mask
==0x07e0) {
3353 if (bmpImage
->blue_mask
==0xf800) {
3354 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3355 convs
->Convert_565_to_0888_asis
3357 srcbits
,-bmpImage
->bytes_per_line
,
3359 } else if (bmpImage
->red_mask
==0xf800) {
3360 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3361 convs
->Convert_565_to_0888_reverse
3363 srcbits
,-bmpImage
->bytes_per_line
,
3372 if (bmpImage
->green_mask
==0x03e0 &&
3373 (bmpImage
->red_mask
==0x7f00 ||
3374 bmpImage
->blue_mask
==0x7f00)) {
3375 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3376 convs
->Convert_5x5_to_any0888
3378 srcbits
,-bmpImage
->bytes_per_line
,
3379 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3382 } else if (bmpImage
->green_mask
==0x07e0 &&
3383 (bmpImage
->red_mask
==0xf800 ||
3384 bmpImage
->blue_mask
==0xf800)) {
3385 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3386 convs
->Convert_5x5_to_any0888
3388 srcbits
,-bmpImage
->bytes_per_line
,
3389 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3401 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3403 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3404 int rShift
,gShift
,bShift
;
3407 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3408 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3409 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3410 for (h
= lines
- 1; h
>= 0; h
--) {
3411 dstpixel
=(DWORD
*)dstbits
;
3412 for (x
= 0; x
< width
; x
++) {
3413 PALETTEENTRY srcval
;
3414 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3415 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3416 (srcval
.peGreen
<< gShift
) |
3417 (srcval
.peBlue
<< bShift
);
3419 dstbits
+= linebytes
;
3427 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3429 /* ==== pal 8 bmp -> any 0888 dib ==== */
3430 int rShift
,gShift
,bShift
;
3431 const void* srcbits
;
3432 const BYTE
* srcpixel
;
3435 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3436 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3437 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3438 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3439 for (h
= lines
- 1; h
>= 0; h
--) {
3441 dstpixel
=(DWORD
*)dstbits
;
3442 for (x
= 0; x
< width
; x
++) {
3443 PALETTEENTRY srcval
;
3444 srcval
=srccolors
[*srcpixel
++];
3445 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3446 (srcval
.peGreen
<< gShift
) |
3447 (srcval
.peBlue
<< bShift
);
3449 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3450 dstbits
+= linebytes
;
3460 /* ==== any bmp format -> any 0888 dib ==== */
3461 int rShift
,gShift
,bShift
;
3464 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3465 bmpImage
->depth
, bmpImage
->red_mask
,
3466 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3469 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3470 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3471 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3472 for (h
= lines
- 1; h
>= 0; h
--) {
3473 dstpixel
=(DWORD
*)dstbits
;
3474 for (x
= 0; x
< width
; x
++) {
3476 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
3477 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3478 (GetGValue(srcval
) << gShift
) |
3479 (GetBValue(srcval
) << bShift
);
3481 dstbits
+= linebytes
;
3488 static int XGetSubImageErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
3490 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
3493 /***********************************************************************
3494 * X11DRV_DIB_SetImageBits_GetSubImage
3496 * Helper for X11DRV_DIB_SetImageBits
3498 static void X11DRV_DIB_SetImageBits_GetSubImage(
3499 const X11DRV_DIB_IMAGEBITS_DESCR
*descr
, XImage
*bmpImage
)
3501 /* compressed bitmaps may contain gaps in them. So make a copy
3502 * of the existing pixels first */
3505 SetRect( &bmprc
, descr
->xDest
, descr
->yDest
,
3506 descr
->xDest
+ descr
->width
, descr
->yDest
+ descr
->height
);
3507 GetRgnBox( descr
->physDev
->region
, &rc
);
3508 /* convert from dc to drawable origin */
3509 OffsetRect( &rc
, descr
->physDev
->dc_rect
.left
, descr
->physDev
->dc_rect
.top
);
3510 /* clip visible rect with bitmap */
3511 if( IntersectRect( &rc
, &rc
, &bmprc
))
3513 X11DRV_expect_error( gdi_display
, XGetSubImageErrorHandler
, NULL
);
3514 XGetSubImage( gdi_display
, descr
->drawable
, rc
.left
, rc
.top
,
3515 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, AllPlanes
,
3517 descr
->xSrc
+ rc
.left
- bmprc
.left
,
3518 descr
->ySrc
+ rc
.top
- bmprc
.top
);
3519 X11DRV_check_error();
3523 /***********************************************************************
3524 * X11DRV_DIB_SetImageBits
3526 * Transfer the bits to an X image.
3527 * Helper function for SetDIBits() and SetDIBitsToDevice().
3529 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3531 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3536 bmpImage
= descr
->image
;
3538 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3539 descr
->infoWidth
, lines
, 32, 0 );
3540 bmpImage
->data
= HeapAlloc( GetProcessHeap(), 0, lines
* bmpImage
->bytes_per_line
);
3541 if(bmpImage
->data
== NULL
) {
3542 ERR("Out of memory!\n");
3543 XDestroyImage( bmpImage
);
3544 wine_tsx11_unlock();
3548 wine_tsx11_unlock();
3550 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3551 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3552 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3553 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3554 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3556 /* Transfer the pixels */
3559 switch(descr
->infoBpp
)
3562 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3563 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3564 bmpImage
, descr
->dibpitch
);
3567 if (descr
->compression
) {
3568 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3569 X11DRV_DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
3570 descr
->infoWidth
, descr
->width
,
3571 descr
->xSrc
, (int *)(descr
->colorMap
),
3574 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3575 descr
->infoWidth
, descr
->width
,
3576 descr
->xSrc
, (int*)(descr
->colorMap
),
3577 bmpImage
, descr
->dibpitch
);
3580 if (descr
->compression
) {
3581 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3582 X11DRV_DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
3583 descr
->infoWidth
, descr
->width
,
3584 descr
->xSrc
, (int *)(descr
->colorMap
),
3587 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3588 descr
->infoWidth
, descr
->width
,
3589 descr
->xSrc
, (int *)(descr
->colorMap
),
3590 bmpImage
, descr
->dibpitch
);
3594 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3595 descr
->infoWidth
, descr
->width
,
3596 descr
->xSrc
, descr
->physDev
,
3597 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3598 bmpImage
, descr
->dibpitch
);
3601 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3602 descr
->infoWidth
, descr
->width
,
3603 descr
->xSrc
, descr
->physDev
,
3604 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3605 bmpImage
, descr
->dibpitch
);
3608 X11DRV_DIB_SetImageBits_32( descr
->lines
, descr
->bits
,
3609 descr
->infoWidth
, descr
->width
,
3610 descr
->xSrc
, descr
->physDev
,
3611 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3612 bmpImage
, descr
->dibpitch
);
3615 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3621 WARN( "invalid bits pointer %p\n", descr
->bits
);
3626 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3627 descr
->drawable
, descr
->gc
, bmpImage
,
3628 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3629 descr
->width
, descr
->height
);
3634 #ifdef HAVE_LIBXXSHM
3635 if (descr
->image
&& descr
->useShm
)
3637 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3638 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3639 descr
->width
, descr
->height
, FALSE
);
3640 XSync( gdi_display
, 0 );
3644 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3645 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3646 descr
->width
, descr
->height
);
3648 if (!descr
->image
) X11DRV_DIB_DestroyXImage( bmpImage
);
3649 wine_tsx11_unlock();
3653 /***********************************************************************
3654 * X11DRV_DIB_GetImageBits
3656 * Transfer the bits from an X image.
3658 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3660 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3665 bmpImage
= descr
->image
;
3667 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3668 descr
->infoWidth
, lines
, 32, 0 );
3669 bmpImage
->data
= HeapAlloc( GetProcessHeap(), 0, lines
* bmpImage
->bytes_per_line
);
3670 if(bmpImage
->data
== NULL
) {
3671 ERR("Out of memory!\n");
3672 XDestroyImage( bmpImage
);
3673 wine_tsx11_unlock();
3678 #ifdef HAVE_LIBXXSHM
3680 /* We must not call XShmGetImage() with a bitmap which is bigger than the available area.
3681 If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */
3682 if((descr
->image
&& descr
->useShm
) && (bmpImage
->width
<= (descr
->width
- descr
->xSrc
))
3683 && (bmpImage
->height
<= (descr
->height
- descr
->ySrc
)))
3685 int saveRed
, saveGreen
, saveBlue
;
3687 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3688 gdi_display
, descr
->drawable
, bmpImage
,
3689 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3691 /* We must save and restore the bmpImage's masks in order
3692 * to preserve them across the call to XShmGetImage, which
3693 * decides to eliminate them since it doesn't happen to know
3694 * what the format of the image is supposed to be, even though
3696 saveRed
= bmpImage
->red_mask
;
3697 saveBlue
= bmpImage
->blue_mask
;
3698 saveGreen
= bmpImage
->green_mask
;
3700 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3701 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3703 bmpImage
->red_mask
= saveRed
;
3704 bmpImage
->blue_mask
= saveBlue
;
3705 bmpImage
->green_mask
= saveGreen
;
3708 #endif /* HAVE_LIBXXSHM */
3710 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3711 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3712 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3713 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3714 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3715 bmpImage
, descr
->xDest
, descr
->yDest
);
3717 wine_tsx11_unlock();
3719 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3720 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3721 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3722 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3723 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3724 /* Transfer the pixels */
3725 switch(descr
->infoBpp
)
3728 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3729 descr
->infoWidth
, descr
->width
,
3730 descr
->colorMap
, descr
->palentry
,
3731 bmpImage
, descr
->dibpitch
);
3735 if (descr
->compression
) {
3736 FIXME("Compression not yet supported!\n");
3737 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 4 ) * abs(descr
->lines
))
3740 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3741 descr
->infoWidth
, descr
->width
,
3742 descr
->colorMap
, descr
->palentry
,
3743 bmpImage
, descr
->dibpitch
);
3746 if (descr
->compression
) {
3747 FIXME("Compression not yet supported!\n");
3748 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 8 ) * abs(descr
->lines
))
3751 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3752 descr
->infoWidth
, descr
->width
,
3753 descr
->colorMap
, descr
->palentry
,
3754 bmpImage
, descr
->dibpitch
);
3758 X11DRV_DIB_GetImageBits_16( descr
->lines
, (LPVOID
)descr
->bits
,
3759 descr
->infoWidth
,descr
->width
,
3761 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3762 bmpImage
, descr
->dibpitch
);
3766 X11DRV_DIB_GetImageBits_24( descr
->lines
, (LPVOID
)descr
->bits
,
3767 descr
->infoWidth
,descr
->width
,
3769 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3770 bmpImage
, descr
->dibpitch
);
3774 X11DRV_DIB_GetImageBits_32( descr
->lines
, (LPVOID
)descr
->bits
,
3775 descr
->infoWidth
, descr
->width
,
3777 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3778 bmpImage
, descr
->dibpitch
);
3782 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3786 if (!descr
->image
) X11DRV_DIB_DestroyXImage( bmpImage
);
3790 /*************************************************************************
3791 * X11DRV_SetDIBitsToDevice
3794 INT
X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE
*physDev
, INT xDest
, INT yDest
, DWORD cx
,
3795 DWORD cy
, INT xSrc
, INT ySrc
,
3796 UINT startscan
, UINT lines
, LPCVOID bits
,
3797 const BITMAPINFO
*info
, UINT coloruse
)
3799 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3804 int rop
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
) - 1];
3806 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3807 &descr
.infoBpp
, &descr
.compression
) == -1)
3810 top_down
= (height
< 0);
3811 if (top_down
) height
= -height
;
3815 LPtoDP(physDev
->hdc
, &pt
, 1);
3817 if (!lines
|| (startscan
>= height
)) return 0;
3818 if (!top_down
&& startscan
+ lines
> height
) lines
= height
- startscan
;
3820 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3821 * and clamp all values to fit inside [startscan,startscan+lines]
3823 if (ySrc
+ cy
<= startscan
+ lines
)
3825 UINT y
= startscan
+ lines
- (ySrc
+ cy
);
3826 if (ySrc
< startscan
) cy
-= (startscan
- ySrc
);
3829 /* avoid getting unnecessary lines */
3831 if (y
>= lines
) return 0;
3836 if (y
>= lines
) return lines
;
3837 ySrc
= y
; /* need to get all lines in top down mode */
3842 if (ySrc
>= startscan
+ lines
) return lines
;
3843 pt
.y
+= ySrc
+ cy
- (startscan
+ lines
);
3844 cy
= startscan
+ lines
- ySrc
;
3846 if (cy
> lines
) cy
= lines
;
3848 if (xSrc
>= width
) return lines
;
3849 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
3850 if (!cx
|| !cy
) return lines
;
3852 /* Update the pixmap from the DIB section */
3853 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
3855 X11DRV_SetupGCForText( physDev
); /* To have the correct colors */
3857 XSetFunction(gdi_display
, physDev
->gc
, rop
);
3858 wine_tsx11_unlock();
3860 switch (descr
.infoBpp
)
3865 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3867 physDev
->depth
, info
, &descr
.nColorMap
);
3868 if (!descr
.colorMap
) return 0;
3869 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3873 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3874 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3875 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3881 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3882 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3883 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3888 descr
.physDev
= physDev
;
3891 descr
.palentry
= NULL
;
3892 descr
.lines
= top_down
? -lines
: lines
;
3893 descr
.infoWidth
= width
;
3894 descr
.depth
= physDev
->depth
;
3895 descr
.drawable
= physDev
->drawable
;
3896 descr
.gc
= physDev
->gc
;
3899 descr
.xDest
= physDev
->dc_rect
.left
+ pt
.x
;
3900 descr
.yDest
= physDev
->dc_rect
.top
+ pt
.y
;
3903 descr
.useShm
= FALSE
;
3904 descr
.dibpitch
= ((width
* descr
.infoBpp
+ 31) &~31) / 8;
3906 result
= X11DRV_DIB_SetImageBits( &descr
);
3908 if (descr
.infoBpp
<= 8)
3909 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3911 /* Update the DIBSection of the pixmap */
3912 X11DRV_UnlockDIBSection(physDev
, TRUE
);
3917 /***********************************************************************
3918 * SetDIBits (X11DRV.@)
3920 INT
X11DRV_SetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
,
3921 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
, UINT coloruse
)
3923 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3924 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3926 LONG width
, height
, tmpheight
;
3929 descr
.physDev
= physDev
;
3931 if (!physBitmap
) return 0;
3933 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3934 &descr
.infoBpp
, &descr
.compression
) == -1)
3938 if (height
< 0) height
= -height
;
3939 if (!lines
|| (startscan
>= height
))
3942 if (!GetObjectW( hbitmap
, sizeof(bitmap
), &bitmap
)) return 0;
3944 if (startscan
+ lines
> height
) lines
= height
- startscan
;
3946 switch (descr
.infoBpp
)
3951 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3952 descr
.physDev
, coloruse
,
3953 physBitmap
->pixmap_depth
,
3954 info
, &descr
.nColorMap
);
3955 if (!descr
.colorMap
) return 0;
3956 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3960 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3961 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3962 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3968 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3969 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3970 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3979 descr
.palentry
= NULL
;
3980 descr
.infoWidth
= width
;
3981 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
3982 descr
.depth
= physBitmap
->pixmap_depth
;
3983 descr
.drawable
= physBitmap
->pixmap
;
3984 descr
.gc
= BITMAP_GC(physBitmap
);
3988 descr
.yDest
= height
- startscan
- lines
;
3989 descr
.width
= bitmap
.bmWidth
;
3990 descr
.height
= lines
;
3991 descr
.useShm
= FALSE
;
3992 descr
.dibpitch
= ((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8;
3993 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
3994 result
= X11DRV_DIB_SetImageBits( &descr
);
3996 /* optimisation for the case where the input bits are in exactly the same
3997 * format as the internal representation and copying to the app bits is
3998 * cheap - saves a round trip to the X server */
3999 if (descr
.compression
== BI_RGB
&&
4000 coloruse
== DIB_RGB_COLORS
&&
4001 descr
.infoBpp
== bitmap
.bmBitsPixel
&&
4002 physBitmap
->base
&& physBitmap
->size
< 65536)
4004 unsigned int srcwidthb
= bitmap
.bmWidthBytes
;
4005 int dstwidthb
= X11DRV_DIB_GetDIBWidthBytes( width
, descr
.infoBpp
);
4006 LPBYTE dbits
= physBitmap
->base
, sbits
= (LPBYTE
)bits
+ (startscan
* srcwidthb
);
4010 TRACE("syncing compatible set bits to app bits\n");
4011 if ((tmpheight
< 0) ^ (bitmap
.bmHeight
< 0))
4013 dbits
+= dstwidthb
* (lines
-1);
4014 dstwidthb
= -dstwidthb
;
4016 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4017 widthb
= min(srcwidthb
, abs(dstwidthb
));
4018 for (y
= 0; y
< lines
; y
++, dbits
+= dstwidthb
, sbits
+= srcwidthb
)
4019 memcpy(dbits
, sbits
, widthb
);
4020 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4021 physBitmap
->status
= DIB_Status_InSync
;
4023 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4025 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4030 /***********************************************************************
4031 * GetDIBits (X11DRV.@)
4033 INT
X11DRV_GetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
, UINT lines
,
4034 LPVOID bits
, BITMAPINFO
*info
, UINT coloruse
)
4036 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
4038 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4039 PALETTEENTRY palette
[256];
4042 LONG width
, tempHeight
;
4046 static const PALETTEENTRY peBlack
= {0,0,0,0};
4047 static const PALETTEENTRY peWhite
= {255,255,255,0};
4049 if (!physBitmap
) return 0;
4050 if (!(obj_size
= GetObjectW( hbitmap
, sizeof(dib
), &dib
))) return 0;
4052 bitmap_type
= DIB_GetBitmapInfo( (BITMAPINFOHEADER
*)info
, &width
, &tempHeight
, &descr
.infoBpp
, &descr
.compression
);
4054 if (physBitmap
->pixmap_depth
> 1)
4056 GetPaletteEntries( GetCurrentObject( physDev
->hdc
, OBJ_PAL
), 0, 256, palette
);
4060 palette
[0] = peBlack
;
4061 palette
[1] = peWhite
;
4064 if (bitmap_type
== -1)
4066 ERR("Invalid bitmap\n");
4069 descr
.lines
= tempHeight
;
4070 core_header
= (bitmap_type
== 0);
4071 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
4073 TRACE("%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
4074 lines
, dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
, width
, descr
.lines
, startscan
);
4076 if( lines
> dib
.dsBm
.bmHeight
) lines
= dib
.dsBm
.bmHeight
;
4078 height
= descr
.lines
;
4079 if (height
< 0) height
= -height
;
4080 if( lines
> height
) lines
= height
;
4081 /* Top-down images have a negative biHeight, the scanlines of these images
4082 * were inverted in X11DRV_DIB_GetImageBits_xx
4083 * To prevent this we simply change the sign of lines
4084 * (the number of scan lines to copy).
4085 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
4087 if( descr
.lines
< 0 && lines
> 0) lines
= -lines
;
4089 if( startscan
>= dib
.dsBm
.bmHeight
) return 0;
4091 descr
.colorMap
= NULL
;
4093 switch (descr
.infoBpp
)
4098 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4099 if(coloruse
== DIB_RGB_COLORS
)
4100 descr
.colorMap
= colorPtr
;
4102 int num_colors
= 1 << descr
.infoBpp
, i
;
4105 WORD
*index
= (WORD
*)colorPtr
;
4106 descr
.colorMap
= rgb
= HeapAlloc(GetProcessHeap(), 0, num_colors
* sizeof(RGBQUAD
));
4107 for(i
= 0; i
< num_colors
; i
++, rgb
++, index
++) {
4108 colref
= X11DRV_PALETTE_ToLogical(X11DRV_PALETTE_ToPhysical(physDev
, PALETTEINDEX(*index
)));
4109 rgb
->rgbRed
= GetRValue(colref
);
4110 rgb
->rgbGreen
= GetGValue(colref
);
4111 rgb
->rgbBlue
= GetBValue(colref
);
4112 rgb
->rgbReserved
= 0;
4118 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4119 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4120 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4124 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4125 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4126 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4130 descr
.physDev
= physDev
;
4131 descr
.palentry
= palette
;
4133 descr
.image
= physBitmap
->image
;
4134 descr
.infoWidth
= width
;
4135 descr
.lines
= lines
;
4136 descr
.depth
= physBitmap
->pixmap_depth
;
4137 descr
.drawable
= physBitmap
->pixmap
;
4138 descr
.gc
= BITMAP_GC(physBitmap
);
4139 descr
.width
= dib
.dsBm
.bmWidth
;
4140 descr
.height
= dib
.dsBm
.bmHeight
;
4144 descr
.sizeImage
= core_header
? 0 : info
->bmiHeader
.biSizeImage
;
4146 if (descr
.lines
> 0)
4148 descr
.ySrc
= (descr
.height
-1) - (startscan
+ (lines
-1));
4152 descr
.ySrc
= startscan
;
4154 #ifdef HAVE_LIBXXSHM
4155 descr
.useShm
= (obj_size
== sizeof(DIBSECTION
)) && (physBitmap
->shminfo
.shmid
!= -1);
4157 descr
.useShm
= FALSE
;
4159 descr
.dibpitch
= (obj_size
== sizeof(DIBSECTION
)) ? dib
.dsBm
.bmWidthBytes
4160 : (((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8);
4162 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
4163 X11DRV_DIB_GetImageBits( &descr
);
4164 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4166 if(!core_header
&& info
->bmiHeader
.biSizeImage
== 0) /* Fill in biSizeImage */
4167 info
->bmiHeader
.biSizeImage
= X11DRV_DIB_GetDIBImageBytes( descr
.infoWidth
,
4171 if (descr
.compression
== BI_BITFIELDS
)
4173 *(DWORD
*)info
->bmiColors
= descr
.rMask
;
4174 *((DWORD
*)info
->bmiColors
+ 1) = descr
.gMask
;
4175 *((DWORD
*)info
->bmiColors
+ 2) = descr
.bMask
;
4177 else if (!core_header
)
4179 /* if RLE or JPEG compression were supported,
4180 * this line would be invalid. */
4181 info
->bmiHeader
.biCompression
= 0;
4184 if(descr
.colorMap
!= colorPtr
)
4185 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4189 /***********************************************************************
4190 * X11DRV_DIB_DoCopyDIBSection
4192 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
4193 void *colorMap
, int nColorMap
,
4194 Drawable dest
, GC gc
,
4195 DWORD xSrc
, DWORD ySrc
,
4196 DWORD xDest
, DWORD yDest
,
4197 DWORD width
, DWORD height
)
4199 DIBSECTION dibSection
;
4200 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4201 int identity
[2] = {0,1};
4203 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
4205 descr
.physDev
= NULL
;
4206 descr
.palentry
= NULL
;
4207 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
4208 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
4209 descr
.lines
= dibSection
.dsBmih
.biHeight
;
4210 descr
.image
= physBitmap
->image
;
4211 descr
.colorMap
= colorMap
;
4212 descr
.nColorMap
= nColorMap
;
4213 descr
.bits
= dibSection
.dsBm
.bmBits
;
4214 descr
.depth
= physBitmap
->pixmap_depth
;
4215 descr
.compression
= dibSection
.dsBmih
.biCompression
;
4217 if(descr
.infoBpp
== 1)
4218 descr
.colorMap
= (void*)identity
;
4220 switch (descr
.infoBpp
)
4225 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4229 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
4230 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
4231 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
4236 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
4237 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
4238 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
4243 descr
.drawable
= dest
;
4247 descr
.xDest
= xDest
;
4248 descr
.yDest
= yDest
;
4249 descr
.width
= width
;
4250 descr
.height
= height
;
4251 descr
.sizeImage
= 0;
4253 #ifdef HAVE_LIBXXSHM
4254 descr
.useShm
= (physBitmap
->shminfo
.shmid
!= -1);
4256 descr
.useShm
= FALSE
;
4258 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
4262 TRACE("Copying from Pixmap to DIB bits\n");
4263 X11DRV_DIB_GetImageBits( &descr
);
4267 TRACE("Copying from DIB bits to Pixmap\n");
4268 X11DRV_DIB_SetImageBits( &descr
);
4272 /***********************************************************************
4273 * X11DRV_DIB_CopyDIBSection
4275 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE
*physDevSrc
, X11DRV_PDEVICE
*physDevDst
,
4276 DWORD xSrc
, DWORD ySrc
, DWORD xDest
, DWORD yDest
,
4277 DWORD width
, DWORD height
)
4280 X_PHYSBITMAP
*physBitmap
;
4281 unsigned int nColorMap
;
4285 TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc
->hdc
, physDevDst
->hdc
,
4286 xSrc
, ySrc
, xDest
, yDest
, width
, height
);
4287 /* this function is meant as an optimization for BitBlt,
4288 * not to be called otherwise */
4289 physBitmap
= physDevSrc
->bitmap
;
4290 if (!physBitmap
|| GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
4292 ERR("called for non-DIBSection!?\n");
4295 /* while BitBlt should already have made sure we only get
4296 * positive values, we should check for oversize values */
4297 if ((xSrc
< dib
.dsBm
.bmWidth
) &&
4298 (ySrc
< dib
.dsBm
.bmHeight
)) {
4299 if (xSrc
+ width
> dib
.dsBm
.bmWidth
)
4300 width
= dib
.dsBm
.bmWidth
- xSrc
;
4301 if (ySrc
+ height
> dib
.dsBm
.bmHeight
)
4302 height
= dib
.dsBm
.bmHeight
- ySrc
;
4303 /* if the source bitmap is 8bpp or less, we're supposed to use the
4304 * DC's palette for color conversion (not the DIB color table) */
4305 if (dib
.dsBm
.bmBitsPixel
<= 8) {
4306 HPALETTE hPalette
= GetCurrentObject( physDevSrc
->hdc
, OBJ_PAL
);
4307 if (!hPalette
|| (hPalette
== GetStockObject(DEFAULT_PALETTE
))) {
4308 /* HACK: no palette has been set in the source DC,
4309 * use the DIB colormap instead - this is necessary in some
4310 * cases since we need to do depth conversion in some places
4311 * where real Windows can just copy data straight over */
4312 x11ColorMap
= physBitmap
->colorMap
;
4313 nColorMap
= physBitmap
->nColorMap
;
4314 freeColorMap
= FALSE
;
4316 const BITMAPINFO
* info
= (BITMAPINFO
*)&dib
.dsBmih
;
4319 nColorMap
= X11DRV_DIB_GetColorCount(info
);
4320 x11ColorMap
= HeapAlloc(GetProcessHeap(), 0, nColorMap
* sizeof(int));
4321 for (i
= 0; i
< nColorMap
; i
++)
4322 x11ColorMap
[i
] = X11DRV_PALETTE_ToPhysical(physDevSrc
, PALETTEINDEX(i
));
4323 freeColorMap
= TRUE
;
4330 freeColorMap
= FALSE
;
4332 /* perform the copy */
4333 X11DRV_DIB_DoCopyDIBSection(physBitmap
, FALSE
, x11ColorMap
, nColorMap
,
4334 physDevDst
->drawable
, physDevDst
->gc
, xSrc
, ySrc
,
4335 physDevDst
->dc_rect
.left
+ xDest
, physDevDst
->dc_rect
.top
+ yDest
,
4337 /* free color mapping */
4339 HeapFree(GetProcessHeap(), 0, x11ColorMap
);
4343 /***********************************************************************
4344 * X11DRV_DIB_DoUpdateDIBSection
4346 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
4350 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
4351 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
4352 physBitmap
->colorMap
, physBitmap
->nColorMap
,
4353 physBitmap
->pixmap
, BITMAP_GC(physBitmap
),
4354 0, 0, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
);
4357 /***********************************************************************
4358 * X11DRV_DIB_FaultHandler
4360 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
4362 X_PHYSBITMAP
*physBitmap
= NULL
;
4366 const size_t pagemask
= getpagesize() - 1;
4368 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
4369 return EXCEPTION_CONTINUE_SEARCH
;
4371 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
4373 EnterCriticalSection(&dibs_cs
);
4374 LIST_FOR_EACH( ptr
, &dibs_list
)
4376 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
4377 if ((physBitmap
->base
<= addr
) &&
4378 (addr
< physBitmap
->base
+ ((physBitmap
->size
+ pagemask
) & ~pagemask
)))
4384 LeaveCriticalSection(&dibs_cs
);
4386 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
4388 if (addr
>= physBitmap
->base
+ physBitmap
->size
)
4389 WARN( "%p: access to %p beyond the end of the DIB\n", physBitmap
->hbitmap
, addr
);
4391 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
);
4392 if (ep
->ExceptionRecord
->ExceptionInformation
[0] == EXCEPTION_WRITE_FAULT
) {
4393 /* the app tried to write the DIB bits */
4394 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
);
4396 /* the app tried to read the DIB bits */
4397 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
);
4399 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4401 return EXCEPTION_CONTINUE_EXECUTION
;
4404 /***********************************************************************
4407 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
)
4409 INT ret
= DIB_Status_None
;
4411 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4412 EnterCriticalSection(&physBitmap
->lock
);
4413 ret
= physBitmap
->status
;
4415 case DIB_Status_GdiMod
:
4416 /* GDI access - request to draw on pixmap */
4417 switch (physBitmap
->status
)
4420 case DIB_Status_None
:
4421 physBitmap
->p_status
= DIB_Status_GdiMod
;
4422 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4425 case DIB_Status_GdiMod
:
4426 TRACE("GdiMod requested in status GdiMod\n" );
4427 physBitmap
->p_status
= DIB_Status_GdiMod
;
4430 case DIB_Status_InSync
:
4431 TRACE("GdiMod requested in status InSync\n" );
4432 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4433 physBitmap
->status
= DIB_Status_GdiMod
;
4434 physBitmap
->p_status
= DIB_Status_InSync
;
4437 case DIB_Status_AppMod
:
4438 TRACE("GdiMod requested in status AppMod\n" );
4439 /* make it readonly to avoid app changing data while we copy */
4440 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4441 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4442 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4443 physBitmap
->p_status
= DIB_Status_AppMod
;
4444 physBitmap
->status
= DIB_Status_GdiMod
;
4449 case DIB_Status_InSync
:
4450 /* App access - request access to read DIB surface */
4451 /* (typically called from signal handler) */
4452 switch (physBitmap
->status
)
4455 case DIB_Status_None
:
4456 /* shouldn't happen from signal handler */
4459 case DIB_Status_GdiMod
:
4460 TRACE("InSync requested in status GdiMod\n" );
4461 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4462 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4463 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4464 physBitmap
->status
= DIB_Status_InSync
;
4467 case DIB_Status_InSync
:
4468 TRACE("InSync requested in status InSync\n" );
4469 /* shouldn't happen from signal handler */
4472 case DIB_Status_AppMod
:
4473 TRACE("InSync requested in status AppMod\n" );
4474 /* no reason to do anything here, and this
4475 * shouldn't happen from signal handler */
4480 case DIB_Status_AppMod
:
4481 /* App access - request access to write DIB surface */
4482 /* (typically called from signal handler) */
4483 switch (physBitmap
->status
)
4486 case DIB_Status_None
:
4487 /* shouldn't happen from signal handler */
4490 case DIB_Status_GdiMod
:
4491 TRACE("AppMod requested in status GdiMod\n" );
4492 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4493 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4494 physBitmap
->status
= DIB_Status_AppMod
;
4497 case DIB_Status_InSync
:
4498 TRACE("AppMod requested in status InSync\n" );
4499 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4500 physBitmap
->status
= DIB_Status_AppMod
;
4503 case DIB_Status_AppMod
:
4504 TRACE("AppMod requested in status AppMod\n" );
4505 /* shouldn't happen from signal handler */
4510 /* it is up to the caller to do the copy/conversion, probably
4511 * using the return value to decide where to copy from */
4513 LeaveCriticalSection(&physBitmap
->lock
);
4517 /***********************************************************************
4520 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
)
4522 INT ret
= DIB_Status_None
;
4524 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4525 TRACE("Locking %p from thread %04x\n", physBitmap
->hbitmap
, GetCurrentThreadId());
4526 EnterCriticalSection(&physBitmap
->lock
);
4527 ret
= physBitmap
->status
;
4528 if (req
!= DIB_Status_None
)
4529 X11DRV_DIB_Coerce(physBitmap
, req
);
4533 /***********************************************************************
4536 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
4538 if (!physBitmap
->image
) return; /* not a DIB section */
4539 switch (physBitmap
->status
)
4542 case DIB_Status_None
:
4543 /* in case anyone is wondering, this is the "signal handler doesn't
4544 * work" case, where we always have to be ready for app access */
4546 switch (physBitmap
->p_status
)
4548 case DIB_Status_GdiMod
:
4549 TRACE("Unlocking and syncing from GdiMod\n" );
4550 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4554 TRACE("Unlocking without needing to sync\n" );
4558 else TRACE("Unlocking with no changes\n");
4559 physBitmap
->p_status
= DIB_Status_None
;
4562 case DIB_Status_GdiMod
:
4563 TRACE("Unlocking in status GdiMod\n" );
4564 /* DIB was protected in Coerce */
4566 /* no commit, revert to InSync if applicable */
4567 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
4568 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
4569 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4570 physBitmap
->status
= DIB_Status_InSync
;
4575 case DIB_Status_InSync
:
4576 TRACE("Unlocking in status InSync\n" );
4577 /* DIB was already protected in Coerce */
4580 case DIB_Status_AppMod
:
4581 TRACE("Unlocking in status AppMod\n" );
4582 /* DIB was already protected in Coerce */
4583 /* this case is ordinary only called from the signal handler,
4584 * so we don't bother to check for !commit */
4587 LeaveCriticalSection(&physBitmap
->lock
);
4588 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
4591 /***********************************************************************
4592 * X11DRV_CoerceDIBSection
4594 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4596 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4597 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
);
4600 /***********************************************************************
4601 * X11DRV_LockDIBSection
4603 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4605 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4606 return X11DRV_DIB_Lock(physDev
->bitmap
, req
);
4609 /***********************************************************************
4610 * X11DRV_UnlockDIBSection
4612 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
4614 if (!physDev
|| !physDev
->bitmap
) return;
4615 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
4619 #ifdef HAVE_LIBXXSHM
4620 /***********************************************************************
4621 * X11DRV_XShmErrorHandler
4624 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
4626 return 1; /* FIXME: should check event contents */
4629 /***********************************************************************
4630 * X11DRV_XShmCreateImage
4633 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
4634 XShmSegmentInfo
* shminfo
)
4638 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
4641 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
4643 if( shminfo
->shmid
!= -1 )
4645 shminfo
->shmaddr
= image
->data
= shmat(shminfo
->shmid
, 0, 0);
4646 if( shminfo
->shmaddr
!= (char*)-1 )
4650 shminfo
->readOnly
= FALSE
;
4651 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
4652 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
4653 XSync( gdi_display
, False
);
4654 if (X11DRV_check_error()) ok
= FALSE
;
4657 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4658 return image
; /* Success! */
4660 /* An error occurred */
4661 shmdt(shminfo
->shmaddr
);
4663 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4664 shminfo
->shmid
= -1;
4666 XFlush(gdi_display
);
4667 XDestroyImage(image
);
4672 #endif /* HAVE_LIBXXSHM */
4675 /***********************************************************************
4676 * X11DRV_CreateDIBSection (X11DRV.@)
4678 HBITMAP
X11DRV_CreateDIBSection( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
,
4679 const BITMAPINFO
*bmi
, UINT usage
)
4681 X_PHYSBITMAP
*physBitmap
;
4684 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
4685 physBitmap
->status
= DIB_Status_None
;
4687 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
4689 /* create color map */
4690 if (dib
.dsBm
.bmBitsPixel
<= 8)
4692 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( physDev
,
4693 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
4694 &physBitmap
->nColorMap
);
4697 /* create pixmap and X image */
4699 physBitmap
->pixmap_depth
= (dib
.dsBm
.bmBitsPixel
== 1) ? 1 : screen_depth
;
4700 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
4701 dib
.dsBm
.bmHeight
, physBitmap
->pixmap_depth
);
4702 #ifdef HAVE_LIBXXSHM
4703 physBitmap
->shminfo
.shmid
= -1;
4704 if (!XShmQueryExtension(gdi_display
) ||
4705 !(physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4706 physBitmap
->pixmap_depth
, &physBitmap
->shminfo
)) )
4708 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4709 physBitmap
->pixmap_depth
);
4710 wine_tsx11_unlock();
4711 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
4713 /* install fault handler */
4714 InitializeCriticalSection( &physBitmap
->lock
);
4715 physBitmap
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": X_PHYSBITMAP.lock");
4717 physBitmap
->base
= dib
.dsBm
.bmBits
;
4718 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
4719 physBitmap
->status
= DIB_Status_AppMod
;
4722 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
4723 EnterCriticalSection( &dibs_cs
);
4724 list_add_head( &dibs_list
, &physBitmap
->entry
);
4725 LeaveCriticalSection( &dibs_cs
);
4727 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4732 /***********************************************************************
4733 * X11DRV_DIB_DeleteDIBSection
4735 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
4739 EnterCriticalSection( &dibs_cs
);
4740 list_remove( &physBitmap
->entry
);
4741 last
= list_empty( &dibs_list
);
4742 LeaveCriticalSection( &dibs_cs
);
4746 RemoveVectoredExceptionHandler( dibs_handler
);
4747 dibs_handler
= NULL
;
4750 if (dib
->dshSection
)
4751 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
);
4753 if (physBitmap
->image
)
4756 #ifdef HAVE_LIBXXSHM
4757 if (physBitmap
->shminfo
.shmid
!= -1)
4759 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4760 XDestroyImage( physBitmap
->image
);
4761 shmdt( physBitmap
->shminfo
.shmaddr
);
4762 physBitmap
->shminfo
.shmid
= -1;
4766 X11DRV_DIB_DestroyXImage( physBitmap
->image
);
4767 wine_tsx11_unlock();
4770 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4771 physBitmap
->lock
.DebugInfo
->Spare
[0] = 0;
4772 DeleteCriticalSection(&physBitmap
->lock
);
4775 /***********************************************************************
4776 * SetDIBColorTable (X11DRV.@)
4778 UINT
X11DRV_SetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4782 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4784 if (!physBitmap
) return 0;
4785 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4787 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4788 UINT end
= count
+ start
;
4789 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4791 * Changing color table might change the mapping between
4792 * DIB colors and X11 colors and thus alter the visible state
4793 * of the bitmap object.
4796 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4797 * at least for a 1 bpp dibsection
4799 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
);
4800 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4801 dib
.dsBm
.bmBitsPixel
,
4802 TRUE
, colors
, start
, end
);
4803 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4810 /***********************************************************************
4811 * X11DRV_DIB_CreateDIBFromBitmap
4813 * Allocates a packed DIB and copies the bitmap data into it.
4815 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4820 LPBITMAPINFOHEADER pbmiHeader
;
4821 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4824 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4827 * A packed DIB contains a BITMAPINFO structure followed immediately by
4828 * an optional color palette and the pixel data.
4831 /* Calculate the size of the packed DIB */
4832 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4833 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4834 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4836 /* Get the offset to the bits */
4837 OffsetBits
= cPackedSize
- cDataSize
;
4839 /* Allocate the packed DIB */
4840 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4841 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4845 WARN("Could not allocate packed DIB!\n");
4849 /* A packed DIB starts with a BITMAPINFOHEADER */
4850 pPackedDIB
= GlobalLock(hPackedDIB
);
4851 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4853 /* Init the BITMAPINFOHEADER */
4854 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
4855 pbmiHeader
->biWidth
= bmp
.bmWidth
;
4856 pbmiHeader
->biHeight
= bmp
.bmHeight
;
4857 pbmiHeader
->biPlanes
= 1;
4858 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
4859 pbmiHeader
->biCompression
= BI_RGB
;
4860 pbmiHeader
->biSizeImage
= 0;
4861 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
4862 pbmiHeader
->biClrUsed
= 0;
4863 pbmiHeader
->biClrImportant
= 0;
4865 /* Retrieve the DIB bits from the bitmap and fill in the
4866 * DIB color table if present */
4868 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
4869 hBmp
, /* Handle to bitmap */
4870 0, /* First scan line to set in dest bitmap */
4871 bmp
.bmHeight
, /* Number of scan lines to copy */
4872 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
4873 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
4874 0); /* RGB or palette index */
4875 GlobalUnlock(hPackedDIB
);
4877 /* Cleanup if GetDIBits failed */
4878 if (nLinesCopied
!= bmp
.bmHeight
)
4880 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
4881 GlobalFree(hPackedDIB
);
4888 /**************************************************************************
4889 * X11DRV_DIB_CreateDIBFromPixmap
4891 * Allocates a packed DIB and copies the Pixmap data into it.
4892 * The Pixmap passed in is deleted after the conversion.
4894 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
4897 X_PHYSBITMAP
*physBitmap
;
4900 HGLOBAL hPackedDIB
= 0;
4902 int x
,y
; /* Unused */
4903 unsigned border_width
; /* Unused */
4904 unsigned int depth
, width
, height
;
4906 /* Get the Pixmap dimensions and bit depth */
4908 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
4909 &border_width
, &depth
)) depth
= 0;
4910 wine_tsx11_unlock();
4911 if (!depth
) return 0;
4913 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4914 width
, height
, depth
);
4917 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4918 * and make it a container for the pixmap passed.
4920 if (!(hBmp
= CreateBitmap( width
, height
, 1, depth_to_bpp(depth
), NULL
))) return 0;
4922 /* force bitmap to be owned by a screen DC */
4923 hdcMem
= CreateCompatibleDC( hdc
);
4924 SelectObject( hdcMem
, SelectObject( hdcMem
, hBmp
));
4927 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4929 /* swap the new pixmap in */
4930 orig_pixmap
= physBitmap
->pixmap
;
4931 physBitmap
->pixmap
= pixmap
;
4934 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4935 * A packed DIB contains a BITMAPINFO structure followed immediately by
4936 * an optional color palette and the pixel data.
4938 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
4940 /* we can now get rid of the HBITMAP and its original pixmap */
4941 physBitmap
->pixmap
= orig_pixmap
;
4944 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
4949 /**************************************************************************
4950 * X11DRV_DIB_CreatePixmapFromDIB
4952 * Creates a Pixmap from a packed DIB
4954 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
4957 X_PHYSBITMAP
*physBitmap
;
4961 /* Create a DDB from the DIB */
4963 pbmi
= GlobalLock(hPackedDIB
);
4964 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
4965 (LPBYTE
)pbmi
+ bitmap_info_size( pbmi
, DIB_RGB_COLORS
),
4966 pbmi
, DIB_RGB_COLORS
);
4967 GlobalUnlock(hPackedDIB
);
4969 /* clear the physBitmap so that we can steal its pixmap */
4970 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4971 pixmap
= physBitmap
->pixmap
;
4972 physBitmap
->pixmap
= 0;
4974 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4977 TRACE("Returning Pixmap %lx\n", pixmap
);