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
)
227 width_bytes
= X11DRV_DIB_GetXImageWidthBytes( width
, depth
);
228 image
= XCreateImage( gdi_display
, visual
, depth
, ZPixmap
, 0,
229 calloc( height
, width_bytes
),
230 width
, height
, 32, width_bytes
);
236 /***********************************************************************
237 * DIB_GetBitmapInfoEx
239 * Get the info from a bitmap header.
240 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
242 static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER
*header
, LONG
*width
,
243 LONG
*height
, WORD
*planes
, WORD
*bpp
,
244 WORD
*compr
, DWORD
*size
)
246 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
248 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
249 *width
= core
->bcWidth
;
250 *height
= core
->bcHeight
;
251 *planes
= core
->bcPlanes
;
252 *bpp
= core
->bcBitCount
;
257 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
))
259 *width
= header
->biWidth
;
260 *height
= header
->biHeight
;
261 *planes
= header
->biPlanes
;
262 *bpp
= header
->biBitCount
;
263 *compr
= header
->biCompression
;
264 *size
= header
->biSizeImage
;
267 ERR("(%d): unknown/wrong size for header\n", header
->biSize
);
272 /***********************************************************************
273 * X11DRV_DIB_GetColorCount
275 * Computes the number of colors for the bitmap palette.
276 * Should not be called for a >8-bit deep bitmap.
278 static unsigned int X11DRV_DIB_GetColorCount(const BITMAPINFO
*info
)
281 BOOL core_info
= info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
);
285 colors
= 1 << ((const BITMAPCOREINFO
*)info
)->bmciHeader
.bcBitCount
;
289 colors
= info
->bmiHeader
.biClrUsed
;
290 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
294 ERR("called with >256 colors!\n");
300 /***********************************************************************
303 * Get the info from a bitmap header.
304 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
306 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
307 LONG
*height
, WORD
*bpp
, WORD
*compr
)
312 return DIB_GetBitmapInfoEx( header
, width
, height
, &planes
, bpp
, compr
, &size
);
316 static inline BOOL
colour_is_brighter(RGBQUAD c1
, RGBQUAD c2
)
318 return (c1
.rgbRed
* c1
.rgbRed
+ c1
.rgbGreen
* c1
.rgbGreen
+ c1
.rgbBlue
* c1
.rgbBlue
) >
319 (c2
.rgbRed
* c2
.rgbRed
+ c2
.rgbGreen
* c2
.rgbGreen
+ c2
.rgbBlue
* c2
.rgbBlue
);
322 /***********************************************************************
323 * X11DRV_DIB_GenColorMap
325 * Fills the color map of a bitmap palette. Should not be called
326 * for a >8-bit deep bitmap.
328 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE
*physDev
, int *colorMapping
,
329 WORD coloruse
, WORD depth
, BOOL quads
,
330 const void *colorPtr
, int start
, int end
)
334 if (coloruse
== DIB_RGB_COLORS
)
338 const RGBQUAD
* rgb
= (const RGBQUAD
*)colorPtr
;
340 if (depth
== 1) /* Monochrome */
345 if (GetDIBColorTable( physDev
->hdc
, 0, 2, table
) == 2)
346 invert
= !colour_is_brighter(table
[1], table
[0]);
348 for (i
= start
; i
< end
; i
++, rgb
++)
349 colorMapping
[i
] = ((rgb
->rgbRed
+ rgb
->rgbGreen
+
350 rgb
->rgbBlue
> 255*3/2 && !invert
) ||
351 (rgb
->rgbRed
+ rgb
->rgbGreen
+
352 rgb
->rgbBlue
<= 255*3/2 && invert
));
355 for (i
= start
; i
< end
; i
++, rgb
++)
356 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( NULL
, RGB(rgb
->rgbRed
,
362 const RGBTRIPLE
* rgb
= (const RGBTRIPLE
*)colorPtr
;
364 if (depth
== 1) /* Monochrome */
369 if (GetDIBColorTable( physDev
->hdc
, 0, 2, table
) == 2)
370 invert
= !colour_is_brighter(table
[1], table
[0]);
372 for (i
= start
; i
< end
; i
++, rgb
++)
373 colorMapping
[i
] = ((rgb
->rgbtRed
+ rgb
->rgbtGreen
+
374 rgb
->rgbtBlue
> 255*3/2 && !invert
) ||
375 (rgb
->rgbtRed
+ rgb
->rgbtGreen
+
376 rgb
->rgbtBlue
<= 255*3/2 && invert
));
379 for (i
= start
; i
< end
; i
++, rgb
++)
380 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( NULL
, RGB(rgb
->rgbtRed
,
385 else /* DIB_PAL_COLORS */
387 const WORD
* index
= (const WORD
*)colorPtr
;
389 for (i
= start
; i
< end
; i
++, index
++)
390 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(*index
) );
396 /***********************************************************************
397 * X11DRV_DIB_BuildColorMap
399 * Build the color map from the bitmap palette. Should not be called
400 * for a >8-bit deep bitmap.
402 static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
403 const BITMAPINFO
*info
, int *nColors
)
406 const void *colorPtr
;
410 *nColors
= X11DRV_DIB_GetColorCount(info
);
411 if (!*nColors
) return NULL
;
413 isInfo
= info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
);
414 colorPtr
= (const BYTE
*)info
+ (WORD
)info
->bmiHeader
.biSize
;
415 if (!(colorMapping
= HeapAlloc(GetProcessHeap(), 0, *nColors
* sizeof(int) )))
418 return X11DRV_DIB_GenColorMap( physDev
, colorMapping
, coloruse
, depth
,
419 isInfo
, colorPtr
, 0, *nColors
);
422 /***********************************************************************
423 * X11DRV_DIB_MapColor
425 static int X11DRV_DIB_MapColor( int *physMap
, int nPhysMap
, int phys
, int oldcol
)
429 if ((oldcol
< nPhysMap
) && (physMap
[oldcol
] == phys
))
432 for (color
= 0; color
< nPhysMap
; color
++)
433 if (physMap
[color
] == phys
)
436 WARN("Strange color %08x\n", phys
);
441 /*********************************************************************
442 * X11DRV_DIB_GetNearestIndex
444 * Helper for X11DRV_DIB_GetDIBits.
445 * Returns the nearest colour table index for a given RGB.
446 * Nearest is defined by minimizing the sum of the squares.
448 static INT
X11DRV_DIB_GetNearestIndex(RGBQUAD
*colormap
, int numColors
, BYTE r
, BYTE g
, BYTE b
)
450 INT i
, best
= -1, diff
, bestdiff
= -1;
453 for(color
= colormap
, i
= 0; i
< numColors
; color
++, i
++) {
454 diff
= (r
- color
->rgbRed
) * (r
- color
->rgbRed
) +
455 (g
- color
->rgbGreen
) * (g
- color
->rgbGreen
) +
456 (b
- color
->rgbBlue
) * (b
- color
->rgbBlue
);
459 if(best
== -1 || diff
< bestdiff
) {
466 /*********************************************************************
467 * X11DRV_DIB_MaskToShift
469 * Helper for X11DRV_DIB_GetDIBits.
470 * Returns the by how many bits to shift a given color so that it is
471 * in the proper position.
473 INT
X11DRV_DIB_MaskToShift(DWORD mask
)
481 while ((mask
&1)==0) {
488 /***********************************************************************
489 * X11DRV_DIB_CheckMask
491 * Check RGB mask if it is either 0 or matches visual's mask.
493 static inline int X11DRV_DIB_CheckMask(int red_mask
, int green_mask
, int blue_mask
)
495 return ( red_mask
== 0 && green_mask
== 0 && blue_mask
== 0 ) ||
496 ( red_mask
== visual
->red_mask
&& green_mask
== visual
->green_mask
&&
497 blue_mask
== visual
->blue_mask
);
500 /***********************************************************************
501 * X11DRV_DIB_SetImageBits_1
503 * SetDIBits for a 1-bit deep DIB.
505 static void X11DRV_DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
506 DWORD srcwidth
, DWORD dstwidth
, int left
,
507 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
516 srcbits
= srcbits
+ linebytes
* (lines
- 1);
517 linebytes
= -linebytes
;
520 if ((extra
= (left
& 7)) != 0) {
524 srcbits
+= left
>> 3;
525 width
= min(srcwidth
, dstwidth
);
527 /* ==== pal 1 dib -> any bmp format ==== */
528 for (h
= lines
-1; h
>=0; h
--) {
530 for (i
= width
/8, x
= left
; i
> 0; i
--) {
532 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
533 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
534 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
535 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
536 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
537 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
538 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
539 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
545 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
546 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
547 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
548 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
549 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
550 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
551 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
554 srcbits
+= linebytes
;
558 /***********************************************************************
559 * X11DRV_DIB_GetImageBits_1
561 * GetDIBits for a 1-bit deep DIB.
563 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
564 DWORD dstwidth
, DWORD srcwidth
,
565 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
566 XImage
*bmpImage
, DWORD linebytes
)
569 int h
, width
= min(dstwidth
, srcwidth
);
573 dstbits
= dstbits
+ linebytes
* (lines
- 1);
574 linebytes
= -linebytes
;
577 switch (bmpImage
->depth
)
581 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
583 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
586 for (h
=lines
-1; h
>=0; h
--) {
590 for (x
=0; x
<width
; x
++) {
592 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
593 dstval
|=(X11DRV_DIB_GetNearestIndex
597 srcval
.peBlue
) << (7 - (x
& 7)));
606 dstbits
+= linebytes
;
614 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
, bmpImage
->green_mask
, bmpImage
->blue_mask
)
616 /* ==== pal 8 bmp -> pal 1 dib ==== */
618 const BYTE
* srcpixel
;
621 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
623 for (h
=0; h
<lines
; h
++) {
628 for (x
=0; x
<width
; x
++) {
630 srcval
=srccolors
[*srcpixel
++];
631 dstval
|=(X11DRV_DIB_GetNearestIndex
635 srcval
.peBlue
) << (7-(x
&7)) );
644 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
645 dstbits
+= linebytes
;
656 const WORD
* srcpixel
;
659 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
661 if (bmpImage
->green_mask
==0x03e0) {
662 if (bmpImage
->red_mask
==0x7c00) {
663 /* ==== rgb 555 bmp -> pal 1 dib ==== */
664 for (h
=0; h
<lines
; h
++) {
669 for (x
=0; x
<width
; x
++) {
672 dstval
|=(X11DRV_DIB_GetNearestIndex
674 ((srcval
>> 7) & 0xf8) | /* r */
675 ((srcval
>> 12) & 0x07),
676 ((srcval
>> 2) & 0xf8) | /* g */
677 ((srcval
>> 7) & 0x07),
678 ((srcval
<< 3) & 0xf8) | /* b */
679 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
688 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
689 dstbits
+= linebytes
;
691 } else if (bmpImage
->blue_mask
==0x7c00) {
692 /* ==== bgr 555 bmp -> pal 1 dib ==== */
693 for (h
=0; h
<lines
; h
++) {
698 for (x
=0; x
<width
; x
++) {
701 dstval
|=(X11DRV_DIB_GetNearestIndex
703 ((srcval
<< 3) & 0xf8) | /* r */
704 ((srcval
>> 2) & 0x07),
705 ((srcval
>> 2) & 0xf8) | /* g */
706 ((srcval
>> 7) & 0x07),
707 ((srcval
>> 7) & 0xf8) | /* b */
708 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
717 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
718 dstbits
+= linebytes
;
723 } else if (bmpImage
->green_mask
==0x07e0) {
724 if (bmpImage
->red_mask
==0xf800) {
725 /* ==== rgb 565 bmp -> pal 1 dib ==== */
726 for (h
=0; h
<lines
; h
++) {
731 for (x
=0; x
<width
; x
++) {
734 dstval
|=(X11DRV_DIB_GetNearestIndex
736 ((srcval
>> 8) & 0xf8) | /* r */
737 ((srcval
>> 13) & 0x07),
738 ((srcval
>> 3) & 0xfc) | /* g */
739 ((srcval
>> 9) & 0x03),
740 ((srcval
<< 3) & 0xf8) | /* b */
741 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
750 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
751 dstbits
+= linebytes
;
753 } else if (bmpImage
->blue_mask
==0xf800) {
754 /* ==== bgr 565 bmp -> pal 1 dib ==== */
755 for (h
=0; h
<lines
; h
++) {
760 for (x
=0; x
<width
; x
++) {
763 dstval
|=(X11DRV_DIB_GetNearestIndex
765 ((srcval
<< 3) & 0xf8) | /* r */
766 ((srcval
>> 2) & 0x07),
767 ((srcval
>> 3) & 0xfc) | /* g */
768 ((srcval
>> 9) & 0x03),
769 ((srcval
>> 8) & 0xf8) | /* b */
770 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
779 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
780 dstbits
+= linebytes
;
799 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
800 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
802 if (bmpImage
->green_mask
!=0x00ff00 ||
803 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
805 } else if (bmpImage
->blue_mask
==0xff) {
806 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
807 for (h
=0; h
<lines
; h
++) {
812 for (x
=0; x
<width
; x
++) {
813 dstval
|=(X11DRV_DIB_GetNearestIndex
817 srcbyte
[0]) << (7-(x
&7)) );
818 srcbyte
+=bytes_per_pixel
;
827 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
828 dstbits
+= linebytes
;
831 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
832 for (h
=0; h
<lines
; h
++) {
837 for (x
=0; x
<width
; x
++) {
838 dstval
|=(X11DRV_DIB_GetNearestIndex
842 srcbyte
[2]) << (7-(x
&7)) );
843 srcbyte
+=bytes_per_pixel
;
852 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
853 dstbits
+= linebytes
;
864 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
866 /* ==== any bmp format -> pal 1 dib ==== */
867 if ((unsigned)colors
[0].rgbRed
+colors
[0].rgbGreen
+colors
[0].rgbBlue
>=
868 (unsigned)colors
[1].rgbRed
+colors
[1].rgbGreen
+colors
[1].rgbBlue
)
871 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
872 "%s color mapping\n",
873 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
874 bmpImage
->green_mask
, bmpImage
->blue_mask
,
875 neg
?"negative":"direct" );
877 for (h
=lines
-1; h
>=0; h
--) {
881 for (x
=0; x
<width
; x
++) {
882 dstval
|=((XGetPixel( bmpImage
, x
, h
) >= white
) ^ neg
) << (7 - (x
&7));
891 dstbits
+= linebytes
;
898 /***********************************************************************
899 * X11DRV_DIB_SetImageBits_4
901 * SetDIBits for a 4-bit deep DIB.
903 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
904 DWORD srcwidth
, DWORD dstwidth
, int left
,
905 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
913 srcbits
= srcbits
+ linebytes
* (lines
- 1);
914 linebytes
= -linebytes
;
921 srcbits
+= left
>> 1;
922 width
= min(srcwidth
, dstwidth
);
924 /* ==== pal 4 dib -> any bmp format ==== */
925 for (h
= lines
-1; h
>= 0; h
--) {
927 for (i
= width
/2, x
= left
; i
> 0; i
--) {
928 BYTE srcval
=*srcbyte
++;
929 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
930 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
933 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
934 srcbits
+= linebytes
;
940 /***********************************************************************
941 * X11DRV_DIB_GetImageBits_4
943 * GetDIBits for a 4-bit deep DIB.
945 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
946 DWORD srcwidth
, DWORD dstwidth
,
947 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
948 XImage
*bmpImage
, DWORD linebytes
)
951 int h
, width
= min(srcwidth
, dstwidth
);
957 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
958 linebytes
= -linebytes
;
963 switch (bmpImage
->depth
) {
966 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
968 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
971 for (h
= lines
-1; h
>= 0; h
--) {
975 for (x
= 0; x
< width
; x
++) {
977 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
978 dstval
|=(X11DRV_DIB_GetNearestIndex
982 srcval
.peBlue
) << (4-((x
&1)<<2)));
991 dstbits
+= linebytes
;
999 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1001 /* ==== pal 8 bmp -> pal 4 dib ==== */
1002 const void* srcbits
;
1003 const BYTE
*srcpixel
;
1006 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1007 for (h
=0; h
<lines
; h
++) {
1012 for (x
=0; x
<width
; x
++) {
1013 PALETTEENTRY srcval
;
1014 srcval
= srccolors
[*srcpixel
++];
1015 dstval
|=(X11DRV_DIB_GetNearestIndex
1019 srcval
.peBlue
) << (4*(1-(x
&1))) );
1028 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1029 dstbits
+= linebytes
;
1039 const void* srcbits
;
1040 const WORD
* srcpixel
;
1043 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1045 if (bmpImage
->green_mask
==0x03e0) {
1046 if (bmpImage
->red_mask
==0x7c00) {
1047 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1048 for (h
=0; h
<lines
; h
++) {
1053 for (x
=0; x
<width
; x
++) {
1056 dstval
|=(X11DRV_DIB_GetNearestIndex
1058 ((srcval
>> 7) & 0xf8) | /* r */
1059 ((srcval
>> 12) & 0x07),
1060 ((srcval
>> 2) & 0xf8) | /* g */
1061 ((srcval
>> 7) & 0x07),
1062 ((srcval
<< 3) & 0xf8) | /* b */
1063 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1072 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1073 dstbits
+= linebytes
;
1075 } else if (bmpImage
->blue_mask
==0x7c00) {
1076 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1077 for (h
=0; h
<lines
; h
++) {
1082 for (x
=0; x
<width
; x
++) {
1085 dstval
|=(X11DRV_DIB_GetNearestIndex
1087 ((srcval
<< 3) & 0xf8) | /* r */
1088 ((srcval
>> 2) & 0x07),
1089 ((srcval
>> 2) & 0xf8) | /* g */
1090 ((srcval
>> 7) & 0x07),
1091 ((srcval
>> 7) & 0xf8) | /* b */
1092 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1101 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1102 dstbits
+= linebytes
;
1107 } else if (bmpImage
->green_mask
==0x07e0) {
1108 if (bmpImage
->red_mask
==0xf800) {
1109 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1110 for (h
=0; h
<lines
; h
++) {
1115 for (x
=0; x
<width
; x
++) {
1118 dstval
|=(X11DRV_DIB_GetNearestIndex
1120 ((srcval
>> 8) & 0xf8) | /* r */
1121 ((srcval
>> 13) & 0x07),
1122 ((srcval
>> 3) & 0xfc) | /* g */
1123 ((srcval
>> 9) & 0x03),
1124 ((srcval
<< 3) & 0xf8) | /* b */
1125 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1134 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1135 dstbits
+= linebytes
;
1137 } else if (bmpImage
->blue_mask
==0xf800) {
1138 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1139 for (h
=0; h
<lines
; h
++) {
1144 for (x
=0; x
<width
; x
++) {
1147 dstval
|=(X11DRV_DIB_GetNearestIndex
1149 ((srcval
<< 3) & 0xf8) | /* r */
1150 ((srcval
>> 2) & 0x07),
1151 ((srcval
>> 3) & 0xfc) | /* g */
1152 ((srcval
>> 9) & 0x03),
1153 ((srcval
>> 8) & 0xf8) | /* b */
1154 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1163 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1164 dstbits
+= linebytes
;
1176 if (bmpImage
->bits_per_pixel
==24) {
1177 const void* srcbits
;
1178 const BYTE
*srcbyte
;
1181 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1183 if (bmpImage
->green_mask
!=0x00ff00 ||
1184 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1186 } else if (bmpImage
->blue_mask
==0xff) {
1187 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1188 for (h
=0; h
<lines
; h
++) {
1191 for (x
=0; x
<width
/2; x
++) {
1192 /* Do 2 pixels at a time */
1193 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1198 X11DRV_DIB_GetNearestIndex
1206 /* And then the odd pixel */
1207 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1213 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1214 dstbits
+= linebytes
;
1217 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1218 for (h
=0; h
<lines
; h
++) {
1221 for (x
=0; x
<width
/2; x
++) {
1222 /* Do 2 pixels at a time */
1223 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1228 X11DRV_DIB_GetNearestIndex
1236 /* And then the odd pixel */
1237 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1243 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1244 dstbits
+= linebytes
;
1253 const void* srcbits
;
1254 const BYTE
*srcbyte
;
1257 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1259 if (bmpImage
->green_mask
!=0x00ff00 ||
1260 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1262 } else if (bmpImage
->blue_mask
==0xff) {
1263 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1264 for (h
=0; h
<lines
; h
++) {
1267 for (x
=0; x
<width
/2; x
++) {
1268 /* Do 2 pixels at a time */
1269 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1274 X11DRV_DIB_GetNearestIndex
1282 /* And then the odd pixel */
1283 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1289 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1290 dstbits
+= linebytes
;
1293 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1294 for (h
=0; h
<lines
; h
++) {
1297 for (x
=0; x
<width
/2; x
++) {
1298 /* Do 2 pixels at a time */
1299 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1304 X11DRV_DIB_GetNearestIndex
1312 /* And then the odd pixel */
1313 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1319 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1320 dstbits
+= linebytes
;
1331 /* ==== any bmp format -> pal 4 dib ==== */
1332 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1333 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1334 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1335 for (h
=lines
-1; h
>=0; h
--) {
1337 for (x
=0; x
<(width
& ~1); x
+=2) {
1338 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1339 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1342 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1344 dstbits
+= linebytes
;
1351 /***********************************************************************
1352 * X11DRV_DIB_SetImageBits_RLE4
1354 * SetDIBits for a 4-bit deep compressed DIB.
1356 static void X11DRV_DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
,
1357 DWORD srcwidth
, DWORD dstwidth
,
1358 int left
, int *colors
,
1361 unsigned int x
= 0, width
= min(srcwidth
, dstwidth
);
1362 int y
= lines
- 1, c
, length
;
1363 const BYTE
*begin
= bits
;
1368 if (length
) { /* encoded */
1371 if (x
>= (left
+ width
)) break;
1372 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1374 if (!length
--) break;
1375 if (x
>= (left
+ width
)) break;
1376 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1396 default: /* absolute */
1399 if (x
>= left
&& x
< (left
+ width
))
1400 XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1402 if (!length
--) break;
1403 if (x
>= left
&& x
< (left
+ width
))
1404 XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1407 if ((bits
- begin
) & 1)
1416 /***********************************************************************
1417 * X11DRV_DIB_SetImageBits_8
1419 * SetDIBits for an 8-bit deep DIB.
1421 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1422 DWORD srcwidth
, DWORD dstwidth
, int left
,
1423 const int *colors
, XImage
*bmpImage
,
1427 int h
, width
= min(srcwidth
, dstwidth
);
1428 const BYTE
* srcbyte
;
1434 srcbits
= srcbits
+ linebytes
* (lines
-1);
1435 linebytes
= -linebytes
;
1440 switch (bmpImage
->depth
) {
1443 /* Some X servers might have 32 bit/ 16bit deep pixel */
1444 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1445 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1447 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1448 dstbits
=(BYTE
*)bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1449 for (h
= lines
; h
--; ) {
1450 #if defined(__i386__) && defined(__GNUC__)
1451 int _cl1
,_cl2
; /* temp outputs for asm below */
1452 /* Borrowed from DirectDraw */
1453 __asm__
__volatile__(
1458 " movw (%%edx,%%eax,4),%%ax\n"
1460 " xor %%eax,%%eax\n"
1462 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1467 :"eax", "cc", "memory"
1470 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1471 for (x
=0; x
<width
/2; x
++) {
1472 /* Do 2 pixels at a time */
1473 *dstpixel
++=(colors
[srcbyte
[1]] << 16) | colors
[srcbyte
[0]];
1477 /* And then the odd pixel */
1478 *((WORD
*)dstpixel
)=colors
[srcbyte
[0]];
1481 srcbyte
= (srcbits
+= linebytes
);
1482 dstbits
-= bmpImage
->bytes_per_line
;
1489 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1490 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1492 dstbits
=(BYTE
*)bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1493 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1494 for (h
= lines
; h
--; ) {
1495 #if defined(__i386__) && defined(__GNUC__)
1496 int _cl1
,_cl2
; /* temp outputs for asm below */
1497 /* Borrowed from DirectDraw */
1498 __asm__
__volatile__(
1503 " movl (%%edx,%%eax,4),%%eax\n"
1505 " xor %%eax,%%eax\n"
1507 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1512 :"eax", "cc", "memory"
1515 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1516 for (x
=0; x
<width
; x
++) {
1517 *dstpixel
++=colors
[*srcbyte
++];
1520 srcbyte
= (srcbits
+= linebytes
);
1521 dstbits
-= bmpImage
->bytes_per_line
;
1527 break; /* use slow generic case below */
1530 /* ==== pal 8 dib -> any bmp format ==== */
1531 for (h
=lines
-1; h
>=0; h
--) {
1532 for (x
=left
; x
<width
+left
; x
++) {
1533 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1535 srcbyte
= (srcbits
+= linebytes
);
1539 /***********************************************************************
1540 * X11DRV_DIB_GetImageBits_8
1542 * GetDIBits for an 8-bit deep DIB.
1544 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1545 DWORD srcwidth
, DWORD dstwidth
,
1546 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1547 XImage
*bmpImage
, DWORD linebytes
)
1550 int h
, width
= min(srcwidth
, dstwidth
);
1556 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1557 linebytes
= -linebytes
;
1562 * This condition is true when GetImageBits has been called by
1563 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1564 * 256 colormaps, so we'll just use it for GetDIBits calls.
1565 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1567 if (!srccolors
) goto updatesection
;
1569 switch (bmpImage
->depth
) {
1572 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1575 /* ==== pal 1 bmp -> pal 8 dib ==== */
1576 /* ==== pal 4 bmp -> pal 8 dib ==== */
1577 for (h
=lines
-1; h
>=0; h
--) {
1579 for (x
=0; x
<width
; x
++) {
1580 PALETTEENTRY srcval
;
1581 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1582 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1587 dstbits
+= linebytes
;
1595 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1597 /* ==== pal 8 bmp -> pal 8 dib ==== */
1598 const void* srcbits
;
1599 const BYTE
* srcpixel
;
1601 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1602 for (h
=0; h
<lines
; h
++) {
1605 for (x
= 0; x
< width
; x
++) {
1606 PALETTEENTRY srcval
;
1607 srcval
=srccolors
[*srcpixel
++];
1608 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1613 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1614 dstbits
+= linebytes
;
1624 const void* srcbits
;
1625 const WORD
* srcpixel
;
1628 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1630 if (bmpImage
->green_mask
==0x03e0) {
1631 if (bmpImage
->red_mask
==0x7c00) {
1632 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1633 for (h
=0; h
<lines
; h
++) {
1636 for (x
=0; x
<width
; x
++) {
1639 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1641 ((srcval
>> 7) & 0xf8) | /* r */
1642 ((srcval
>> 12) & 0x07),
1643 ((srcval
>> 2) & 0xf8) | /* g */
1644 ((srcval
>> 7) & 0x07),
1645 ((srcval
<< 3) & 0xf8) | /* b */
1646 ((srcval
>> 2) & 0x07) );
1648 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1649 dstbits
+= linebytes
;
1651 } else if (bmpImage
->blue_mask
==0x7c00) {
1652 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1653 for (h
=0; h
<lines
; h
++) {
1656 for (x
=0; x
<width
; x
++) {
1659 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1661 ((srcval
<< 3) & 0xf8) | /* r */
1662 ((srcval
>> 2) & 0x07),
1663 ((srcval
>> 2) & 0xf8) | /* g */
1664 ((srcval
>> 7) & 0x07),
1665 ((srcval
>> 7) & 0xf8) | /* b */
1666 ((srcval
>> 12) & 0x07) );
1668 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1669 dstbits
+= linebytes
;
1674 } else if (bmpImage
->green_mask
==0x07e0) {
1675 if (bmpImage
->red_mask
==0xf800) {
1676 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1677 for (h
=0; h
<lines
; h
++) {
1680 for (x
=0; x
<width
; x
++) {
1683 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1685 ((srcval
>> 8) & 0xf8) | /* r */
1686 ((srcval
>> 13) & 0x07),
1687 ((srcval
>> 3) & 0xfc) | /* g */
1688 ((srcval
>> 9) & 0x03),
1689 ((srcval
<< 3) & 0xf8) | /* b */
1690 ((srcval
>> 2) & 0x07) );
1692 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1693 dstbits
+= linebytes
;
1695 } else if (bmpImage
->blue_mask
==0xf800) {
1696 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1697 for (h
=0; h
<lines
; h
++) {
1700 for (x
=0; x
<width
; x
++) {
1703 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1705 ((srcval
<< 3) & 0xf8) | /* r */
1706 ((srcval
>> 2) & 0x07),
1707 ((srcval
>> 3) & 0xfc) | /* g */
1708 ((srcval
>> 9) & 0x03),
1709 ((srcval
>> 8) & 0xf8) | /* b */
1710 ((srcval
>> 13) & 0x07) );
1712 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1713 dstbits
+= linebytes
;
1727 const void* srcbits
;
1728 const BYTE
*srcbyte
;
1730 int bytes_per_pixel
;
1732 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1733 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1735 if (bmpImage
->green_mask
!=0x00ff00 ||
1736 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1738 } else if (bmpImage
->blue_mask
==0xff) {
1739 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1740 for (h
=0; h
<lines
; h
++) {
1743 for (x
=0; x
<width
; x
++) {
1744 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1749 srcbyte
+=bytes_per_pixel
;
1751 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1752 dstbits
+= linebytes
;
1755 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1756 for (h
=0; h
<lines
; h
++) {
1759 for (x
=0; x
<width
; x
++) {
1760 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1765 srcbyte
+=bytes_per_pixel
;
1767 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1768 dstbits
+= linebytes
;
1776 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1777 bmpImage
->depth
, bmpImage
->red_mask
,
1778 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1780 /* ==== any bmp format -> pal 8 dib ==== */
1781 for (h
=lines
-1; h
>=0; h
--) {
1783 for (x
=0; x
<width
; x
++) {
1784 *dstbyte
=X11DRV_DIB_MapColor
1786 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1789 dstbits
+= linebytes
;
1795 /***********************************************************************
1796 * X11DRV_DIB_SetImageBits_RLE8
1798 * SetDIBits for an 8-bit deep compressed DIB.
1800 * This function rewritten 941113 by James Youngman. WINE blew out when I
1801 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1803 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1804 * 'End of bitmap' escape code. This code is very much laxer in what it
1805 * allows to end the expansion. Possibly too lax. See the note by
1806 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1807 * bitmap should end with RleEnd, but on the other hand, software exists
1808 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1811 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1812 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1815 static void X11DRV_DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
,
1816 DWORD srcwidth
, DWORD dstwidth
,
1817 int left
, int *colors
,
1820 unsigned int x
; /* X-position on each line. Increases. */
1821 int y
; /* Line #. Starts at lines-1, decreases */
1822 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
1823 BYTE length
; /* The length pf a run */
1824 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
1827 * Note that the bitmap data is stored by Windows starting at the
1828 * bottom line of the bitmap and going upwards. Within each line,
1829 * the data is stored left-to-right. That's the reason why line
1830 * goes from lines-1 to 0. [JAY]
1840 * If the length byte is not zero (which is the escape value),
1841 * We have a run of length pixels all the same colour. The colour
1842 * index is stored next.
1844 * If the length byte is zero, we need to read the next byte to
1845 * know what to do. [JAY]
1850 * [Run-Length] Encoded mode
1852 int color
= colors
[*pIn
++];
1853 while (length
-- && x
< (left
+ dstwidth
)) {
1854 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1861 * Escape codes (may be an absolute sequence though)
1863 escape_code
= (*pIn
++);
1872 /* Not all RLE8 bitmaps end with this code. For
1873 * example, Paint Shop Pro produces some that don't.
1874 * That's (I think) what caused the previous
1875 * implementation to fail. [JAY]
1884 default: /* switch to absolute mode */
1885 length
= escape_code
;
1888 int color
= colors
[*pIn
++];
1889 if (x
>= (left
+ dstwidth
))
1894 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1898 * If you think for a moment you'll realise that the
1899 * only time we could ever possibly read an odd
1900 * number of bytes is when there is a 0x00 (escape),
1901 * a value >0x02 (absolute mode) and then an odd-
1902 * length run. Therefore this is the only place we
1903 * need to worry about it. Everywhere else the
1904 * bytes are always read in pairs. [JAY]
1906 if (escape_code
& 1) pIn
++; /* Throw away the pad byte. */
1908 } /* switch (escape_code) : Escape sequence */
1914 /***********************************************************************
1915 * X11DRV_DIB_SetImageBits_16
1917 * SetDIBits for a 16-bit deep DIB.
1919 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1920 DWORD srcwidth
, DWORD dstwidth
, int left
,
1921 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1922 XImage
*bmpImage
, DWORD linebytes
)
1925 int h
, width
= min(srcwidth
, dstwidth
);
1926 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1931 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1932 linebytes
= -linebytes
;
1935 switch (bmpImage
->depth
)
1942 srcbits
=srcbits
+left
*2;
1943 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1945 if (bmpImage
->green_mask
==0x03e0) {
1946 if (gSrc
==bmpImage
->green_mask
) {
1947 if (rSrc
==bmpImage
->red_mask
) {
1948 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1949 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1950 convs
->Convert_5x5_asis
1953 dstbits
,-bmpImage
->bytes_per_line
);
1954 } else if (rSrc
==bmpImage
->blue_mask
) {
1955 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1956 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1957 convs
->Convert_555_reverse
1960 dstbits
,-bmpImage
->bytes_per_line
);
1963 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1964 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1965 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1966 convs
->Convert_565_to_555_asis
1969 dstbits
,-bmpImage
->bytes_per_line
);
1971 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1972 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1973 convs
->Convert_565_to_555_reverse
1976 dstbits
,-bmpImage
->bytes_per_line
);
1979 } else if (bmpImage
->green_mask
==0x07e0) {
1980 if (gSrc
==bmpImage
->green_mask
) {
1981 if (rSrc
==bmpImage
->red_mask
) {
1982 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
1983 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
1984 convs
->Convert_5x5_asis
1987 dstbits
,-bmpImage
->bytes_per_line
);
1989 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
1990 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
1991 convs
->Convert_565_reverse
1994 dstbits
,-bmpImage
->bytes_per_line
);
1997 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1998 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
1999 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
2000 convs
->Convert_555_to_565_asis
2003 dstbits
,-bmpImage
->bytes_per_line
);
2005 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
2006 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
2007 convs
->Convert_555_to_565_reverse
2010 dstbits
,-bmpImage
->bytes_per_line
);
2020 if (bmpImage
->bits_per_pixel
==24) {
2023 srcbits
=srcbits
+left
*2;
2024 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2026 if (bmpImage
->green_mask
!=0x00ff00 ||
2027 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2029 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2030 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2032 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2033 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2034 convs
->Convert_555_to_888_asis
2037 dstbits
,-bmpImage
->bytes_per_line
);
2039 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2040 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2041 convs
->Convert_565_to_888_asis
2044 dstbits
,-bmpImage
->bytes_per_line
);
2048 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2049 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2050 convs
->Convert_555_to_888_reverse
2053 dstbits
,-bmpImage
->bytes_per_line
);
2055 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2056 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2057 convs
->Convert_565_to_888_reverse
2060 dstbits
,-bmpImage
->bytes_per_line
);
2071 srcbits
=srcbits
+left
*2;
2072 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2074 if (bmpImage
->green_mask
!=0x00ff00 ||
2075 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2077 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2078 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2080 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2081 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2082 convs
->Convert_555_to_0888_asis
2085 dstbits
,-bmpImage
->bytes_per_line
);
2087 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2088 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2089 convs
->Convert_565_to_0888_asis
2092 dstbits
,-bmpImage
->bytes_per_line
);
2096 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2097 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2098 convs
->Convert_555_to_0888_reverse
2101 dstbits
,-bmpImage
->bytes_per_line
);
2103 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2104 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2105 convs
->Convert_565_to_0888_reverse
2108 dstbits
,-bmpImage
->bytes_per_line
);
2116 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2117 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2118 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2124 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2125 const WORD
* srcpixel
;
2126 int rShift1
,gShift1
,bShift1
;
2127 int rShift2
,gShift2
,bShift2
;
2130 /* Set color scaling values */
2131 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
2132 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
2133 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
2138 /* Green has 5 bits, like the others */
2142 /* Green has 6 bits, not 5. Compensate. */
2151 /* We could split it into four separate cases to optimize
2152 * but it is probably not worth it.
2154 for (h
=lines
-1; h
>=0; h
--) {
2155 srcpixel
=(const WORD
*)srcbits
;
2156 for (x
=left
; x
<width
+left
; x
++) {
2158 BYTE red
,green
,blue
;
2159 srcval
=*srcpixel
++ << 16;
2160 red
= ((srcval
>> rShift1
) & 0xf8) |
2161 ((srcval
>> rShift2
) & 0x07);
2162 green
=((srcval
>> gShift1
) & gMask1
) |
2163 ((srcval
>> gShift2
) & gMask2
);
2164 blue
= ((srcval
>> bShift1
) & 0xf8) |
2165 ((srcval
>> bShift2
) & 0x07);
2166 XPutPixel(bmpImage
, x
, h
,
2167 X11DRV_PALETTE_ToPhysical
2168 (physDev
, RGB(red
,green
,blue
)));
2170 srcbits
+= linebytes
;
2178 /***********************************************************************
2179 * X11DRV_DIB_GetImageBits_16
2181 * GetDIBits for an 16-bit deep DIB.
2183 static void X11DRV_DIB_GetImageBits_16( int lines
, BYTE
*dstbits
,
2184 DWORD dstwidth
, DWORD srcwidth
,
2185 PALETTEENTRY
*srccolors
,
2186 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2187 XImage
*bmpImage
, DWORD dibpitch
)
2190 int h
, width
= min(srcwidth
, dstwidth
);
2191 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2193 DWORD linebytes
= dibpitch
;
2198 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
2199 linebytes
= -linebytes
;
2202 switch (bmpImage
->depth
)
2207 const char* srcbits
;
2209 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2211 if (bmpImage
->green_mask
==0x03e0) {
2212 if (gDst
==bmpImage
->green_mask
) {
2213 if (rDst
==bmpImage
->red_mask
) {
2214 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2215 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2216 convs
->Convert_5x5_asis
2218 srcbits
,-bmpImage
->bytes_per_line
,
2221 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2222 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2223 convs
->Convert_555_reverse
2225 srcbits
,-bmpImage
->bytes_per_line
,
2229 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2230 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2231 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2232 convs
->Convert_555_to_565_asis
2234 srcbits
,-bmpImage
->bytes_per_line
,
2237 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2238 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2239 convs
->Convert_555_to_565_reverse
2241 srcbits
,-bmpImage
->bytes_per_line
,
2245 } else if (bmpImage
->green_mask
==0x07e0) {
2246 if (gDst
==bmpImage
->green_mask
) {
2247 if (rDst
== bmpImage
->red_mask
) {
2248 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2249 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2250 convs
->Convert_5x5_asis
2252 srcbits
,-bmpImage
->bytes_per_line
,
2255 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2256 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2257 convs
->Convert_565_reverse
2259 srcbits
,-bmpImage
->bytes_per_line
,
2263 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2264 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2265 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2266 convs
->Convert_565_to_555_asis
2268 srcbits
,-bmpImage
->bytes_per_line
,
2271 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2272 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2273 convs
->Convert_565_to_555_reverse
2275 srcbits
,-bmpImage
->bytes_per_line
,
2286 if (bmpImage
->bits_per_pixel
== 24) {
2287 const char* srcbits
;
2289 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2291 if (bmpImage
->green_mask
!=0x00ff00 ||
2292 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2294 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2295 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2297 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2298 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2299 convs
->Convert_888_to_555_asis
2301 srcbits
,-bmpImage
->bytes_per_line
,
2304 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2305 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2306 convs
->Convert_888_to_565_asis
2308 srcbits
,-bmpImage
->bytes_per_line
,
2313 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2314 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2315 convs
->Convert_888_to_555_reverse
2317 srcbits
,-bmpImage
->bytes_per_line
,
2320 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2321 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2322 convs
->Convert_888_to_565_reverse
2324 srcbits
,-bmpImage
->bytes_per_line
,
2334 const char* srcbits
;
2336 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2338 if (bmpImage
->green_mask
!=0x00ff00 ||
2339 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2341 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2342 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2344 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2345 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2346 convs
->Convert_0888_to_555_asis
2348 srcbits
,-bmpImage
->bytes_per_line
,
2351 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2352 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2353 convs
->Convert_0888_to_565_asis
2355 srcbits
,-bmpImage
->bytes_per_line
,
2360 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2361 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2362 convs
->Convert_0888_to_555_reverse
2364 srcbits
,-bmpImage
->bytes_per_line
,
2367 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2368 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2369 convs
->Convert_0888_to_565_reverse
2371 srcbits
,-bmpImage
->bytes_per_line
,
2380 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2382 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2383 int rShift
,gShift
,bShift
;
2386 /* Shift everything 16 bits left so that all shifts are >0,
2387 * even for BGR DIBs. Then a single >> 16 will bring everything
2390 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2391 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2392 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2394 /* 6 bits for the green */
2400 for (h
= lines
- 1; h
>= 0; h
--) {
2401 dstpixel
=(LPWORD
)dstbits
;
2402 for (x
= 0; x
< width
; x
++) {
2403 PALETTEENTRY srcval
;
2405 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2406 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2407 ((srcval
.peGreen
<< gShift
) & gDst
) |
2408 ((srcval
.peBlue
<< bShift
) & bDst
);
2409 *dstpixel
++=dstval
>> 16;
2411 dstbits
+= linebytes
;
2419 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2421 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2422 int rShift
,gShift
,bShift
;
2423 const BYTE
* srcbits
;
2424 const BYTE
* srcpixel
;
2427 /* Shift everything 16 bits left so that all shifts are >0,
2428 * even for BGR DIBs. Then a single >> 16 will bring everything
2431 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2432 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2433 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2435 /* 6 bits for the green */
2441 srcbits
=(BYTE
*)bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2442 for (h
=0; h
<lines
; h
++) {
2444 dstpixel
=(LPWORD
)dstbits
;
2445 for (x
= 0; x
< width
; x
++) {
2446 PALETTEENTRY srcval
;
2448 srcval
=srccolors
[*srcpixel
++];
2449 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2450 ((srcval
.peGreen
<< gShift
) & gDst
) |
2451 ((srcval
.peBlue
<< bShift
) & bDst
);
2452 *dstpixel
++=dstval
>> 16;
2454 srcbits
-= bmpImage
->bytes_per_line
;
2455 dstbits
+= linebytes
;
2465 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2466 int rShift
,gShift
,bShift
;
2469 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2470 bmpImage
->depth
, bmpImage
->red_mask
,
2471 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2474 /* Shift everything 16 bits left so that all shifts are >0,
2475 * even for BGR DIBs. Then a single >> 16 will bring everything
2478 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2479 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2480 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2482 /* 6 bits for the green */
2488 for (h
= lines
- 1; h
>= 0; h
--) {
2489 dstpixel
=(LPWORD
)dstbits
;
2490 for (x
= 0; x
< width
; x
++) {
2493 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
2494 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2495 ((GetGValue(srcval
) << gShift
) & gDst
) |
2496 ((GetBValue(srcval
) << bShift
) & bDst
);
2497 *dstpixel
++=dstval
>> 16;
2499 dstbits
+= linebytes
;
2507 /***********************************************************************
2508 * X11DRV_DIB_SetImageBits_24
2510 * SetDIBits for a 24-bit deep DIB.
2512 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2513 DWORD srcwidth
, DWORD dstwidth
, int left
,
2514 X11DRV_PDEVICE
*physDev
,
2515 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2516 XImage
*bmpImage
, DWORD linebytes
)
2519 int h
, width
= min(srcwidth
, dstwidth
);
2520 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2525 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2526 linebytes
= -linebytes
;
2529 switch (bmpImage
->depth
)
2532 if (bmpImage
->bits_per_pixel
==24) {
2535 srcbits
=srcbits
+left
*3;
2536 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2538 if (bmpImage
->green_mask
!=0x00ff00 ||
2539 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2541 } else if (rSrc
==bmpImage
->red_mask
) {
2542 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2543 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2544 convs
->Convert_888_asis
2547 dstbits
,-bmpImage
->bytes_per_line
);
2549 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2550 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2551 convs
->Convert_888_reverse
2554 dstbits
,-bmpImage
->bytes_per_line
);
2564 srcbits
=srcbits
+left
*3;
2565 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2567 if (bmpImage
->green_mask
!=0x00ff00 ||
2568 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2570 } else if (rSrc
==bmpImage
->red_mask
) {
2571 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2572 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2573 convs
->Convert_888_to_0888_asis
2576 dstbits
,-bmpImage
->bytes_per_line
);
2578 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2579 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2580 convs
->Convert_888_to_0888_reverse
2583 dstbits
,-bmpImage
->bytes_per_line
);
2593 srcbits
=srcbits
+left
*3;
2594 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2596 if (bmpImage
->green_mask
==0x03e0) {
2597 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2598 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2599 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2600 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2601 convs
->Convert_888_to_555_asis
2604 dstbits
,-bmpImage
->bytes_per_line
);
2605 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2606 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2607 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2608 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2609 convs
->Convert_888_to_555_reverse
2612 dstbits
,-bmpImage
->bytes_per_line
);
2616 } else if (bmpImage
->green_mask
==0x07e0) {
2617 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2618 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2619 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2620 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2621 convs
->Convert_888_to_565_asis
2624 dstbits
,-bmpImage
->bytes_per_line
);
2625 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2626 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2627 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2628 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2629 convs
->Convert_888_to_565_reverse
2632 dstbits
,-bmpImage
->bytes_per_line
);
2644 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2645 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2646 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2652 /* ==== rgb 888 dib -> any bmp format ==== */
2653 const BYTE
* srcbyte
;
2655 /* Windows only supports one 24bpp DIB format: RGB888 */
2657 for (h
= lines
- 1; h
>= 0; h
--) {
2659 for (x
= left
; x
< width
+left
; x
++) {
2660 XPutPixel(bmpImage
, x
, h
,
2661 X11DRV_PALETTE_ToPhysical
2662 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2665 srcbits
+= linebytes
;
2673 /***********************************************************************
2674 * X11DRV_DIB_GetImageBits_24
2676 * GetDIBits for an 24-bit deep DIB.
2678 static void X11DRV_DIB_GetImageBits_24( int lines
, BYTE
*dstbits
,
2679 DWORD dstwidth
, DWORD srcwidth
,
2680 PALETTEENTRY
*srccolors
,
2681 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2682 XImage
*bmpImage
, DWORD linebytes
)
2685 int h
, width
= min(srcwidth
, dstwidth
);
2686 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2691 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2692 linebytes
= -linebytes
;
2695 switch (bmpImage
->depth
)
2698 if (bmpImage
->bits_per_pixel
==24) {
2699 const char* srcbits
;
2701 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2703 if (bmpImage
->green_mask
!=0x00ff00 ||
2704 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2706 } else if (rDst
==bmpImage
->red_mask
) {
2707 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2708 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2709 convs
->Convert_888_asis
2711 srcbits
,-bmpImage
->bytes_per_line
,
2714 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2715 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2716 convs
->Convert_888_reverse
2718 srcbits
,-bmpImage
->bytes_per_line
,
2727 const char* srcbits
;
2729 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2731 if (bmpImage
->green_mask
!=0x00ff00 ||
2732 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2734 } else if (rDst
==bmpImage
->red_mask
) {
2735 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2736 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2737 convs
->Convert_0888_to_888_asis
2739 srcbits
,-bmpImage
->bytes_per_line
,
2742 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2743 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2744 convs
->Convert_0888_to_888_reverse
2746 srcbits
,-bmpImage
->bytes_per_line
,
2755 const char* srcbits
;
2757 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2759 if (bmpImage
->green_mask
==0x03e0) {
2760 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2761 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2762 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2763 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2764 convs
->Convert_555_to_888_asis
2766 srcbits
,-bmpImage
->bytes_per_line
,
2768 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2769 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2770 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2771 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2772 convs
->Convert_555_to_888_reverse
2774 srcbits
,-bmpImage
->bytes_per_line
,
2779 } else if (bmpImage
->green_mask
==0x07e0) {
2780 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2781 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2782 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2783 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2784 convs
->Convert_565_to_888_asis
2786 srcbits
,-bmpImage
->bytes_per_line
,
2788 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2789 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2790 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2791 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2792 convs
->Convert_565_to_888_reverse
2794 srcbits
,-bmpImage
->bytes_per_line
,
2807 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2809 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2812 /* Windows only supports one 24bpp DIB format: rgb 888 */
2813 for (h
= lines
- 1; h
>= 0; h
--) {
2815 for (x
= 0; x
< width
; x
++) {
2816 PALETTEENTRY srcval
;
2817 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2818 dstbyte
[0]=srcval
.peBlue
;
2819 dstbyte
[1]=srcval
.peGreen
;
2820 dstbyte
[2]=srcval
.peRed
;
2823 dstbits
+= linebytes
;
2831 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2833 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2834 const void* srcbits
;
2835 const BYTE
* srcpixel
;
2838 /* Windows only supports one 24bpp DIB format: rgb 888 */
2839 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2840 for (h
= lines
- 1; h
>= 0; h
--) {
2843 for (x
= 0; x
< width
; x
++ ) {
2844 PALETTEENTRY srcval
;
2845 srcval
=srccolors
[*srcpixel
++];
2846 dstbyte
[0]=srcval
.peBlue
;
2847 dstbyte
[1]=srcval
.peGreen
;
2848 dstbyte
[2]=srcval
.peRed
;
2851 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2852 dstbits
+= linebytes
;
2862 /* ==== any bmp format -> 888 dib ==== */
2865 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2866 bmpImage
->depth
, bmpImage
->red_mask
,
2867 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2870 /* Windows only supports one 24bpp DIB format: rgb 888 */
2871 for (h
= lines
- 1; h
>= 0; h
--) {
2873 for (x
= 0; x
< width
; x
++) {
2874 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2875 (XGetPixel( bmpImage
, x
, h
));
2876 dstbyte
[0]=GetBValue(srcval
);
2877 dstbyte
[1]=GetGValue(srcval
);
2878 dstbyte
[2]=GetRValue(srcval
);
2881 dstbits
+= linebytes
;
2889 /***********************************************************************
2890 * X11DRV_DIB_SetImageBits_32
2892 * SetDIBits for a 32-bit deep DIB.
2894 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2895 DWORD srcwidth
, DWORD dstwidth
, int left
,
2896 X11DRV_PDEVICE
*physDev
,
2897 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2903 int h
, width
= min(srcwidth
, dstwidth
);
2904 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2909 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2910 linebytes
= -linebytes
;
2913 ptr
= (const DWORD
*) srcbits
+ left
;
2915 switch (bmpImage
->depth
)
2918 if (bmpImage
->bits_per_pixel
==24) {
2921 srcbits
=srcbits
+left
*4;
2922 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2924 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2925 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2926 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2927 convs
->Convert_0888_to_888_asis
2930 dstbits
,-bmpImage
->bytes_per_line
);
2931 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2932 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2934 /* the tests below assume sane bmpImage masks */
2935 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2936 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2937 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2938 convs
->Convert_0888_to_888_reverse
2941 dstbits
,-bmpImage
->bytes_per_line
);
2942 } else if (bmpImage
->blue_mask
==0xff) {
2943 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2944 convs
->Convert_any0888_to_rgb888
2948 dstbits
,-bmpImage
->bytes_per_line
);
2950 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2951 convs
->Convert_any0888_to_bgr888
2955 dstbits
,-bmpImage
->bytes_per_line
);
2965 srcbits
=srcbits
+left
*4;
2966 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2968 if (gSrc
==bmpImage
->green_mask
) {
2969 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2970 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2971 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2972 convs
->Convert_0888_asis
2975 dstbits
,-bmpImage
->bytes_per_line
);
2976 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2977 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2979 /* the tests below assume sane bmpImage masks */
2980 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
2981 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2982 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2983 convs
->Convert_0888_reverse
2986 dstbits
,-bmpImage
->bytes_per_line
);
2988 /* ==== any 0888 dib -> any 0888 bmp ==== */
2989 convs
->Convert_0888_any
2993 dstbits
,-bmpImage
->bytes_per_line
,
2994 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2996 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2997 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2999 /* the tests below assume sane bmpImage masks */
3001 /* ==== any 0888 dib -> any 0888 bmp ==== */
3002 convs
->Convert_0888_any
3006 dstbits
,-bmpImage
->bytes_per_line
,
3007 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3017 srcbits
=srcbits
+left
*4;
3018 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
3020 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
3021 if (bmpImage
->green_mask
==0x03e0) {
3022 if (bmpImage
->red_mask
==0x7f00) {
3023 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
3024 convs
->Convert_0888_to_555_asis
3027 dstbits
,-bmpImage
->bytes_per_line
);
3028 } else if (bmpImage
->blue_mask
==0x7f00) {
3029 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
3030 convs
->Convert_0888_to_555_reverse
3033 dstbits
,-bmpImage
->bytes_per_line
);
3037 } else if (bmpImage
->green_mask
==0x07e0) {
3038 if (bmpImage
->red_mask
==0xf800) {
3039 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3040 convs
->Convert_0888_to_565_asis
3043 dstbits
,-bmpImage
->bytes_per_line
);
3044 } else if (bmpImage
->blue_mask
==0xf800) {
3045 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3046 convs
->Convert_0888_to_565_reverse
3049 dstbits
,-bmpImage
->bytes_per_line
);
3056 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
3057 if (bmpImage
->green_mask
==0x03e0) {
3058 if (bmpImage
->blue_mask
==0x7f00) {
3059 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3060 convs
->Convert_0888_to_555_asis
3063 dstbits
,-bmpImage
->bytes_per_line
);
3064 } else if (bmpImage
->red_mask
==0x7f00) {
3065 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3066 convs
->Convert_0888_to_555_reverse
3069 dstbits
,-bmpImage
->bytes_per_line
);
3073 } else if (bmpImage
->green_mask
==0x07e0) {
3074 if (bmpImage
->blue_mask
==0xf800) {
3075 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3076 convs
->Convert_0888_to_565_asis
3079 dstbits
,-bmpImage
->bytes_per_line
);
3080 } else if (bmpImage
->red_mask
==0xf800) {
3081 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3082 convs
->Convert_0888_to_565_reverse
3085 dstbits
,-bmpImage
->bytes_per_line
);
3093 if (bmpImage
->green_mask
==0x03e0 &&
3094 (bmpImage
->red_mask
==0x7f00 ||
3095 bmpImage
->blue_mask
==0x7f00)) {
3096 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3097 convs
->Convert_any0888_to_5x5
3101 dstbits
,-bmpImage
->bytes_per_line
,
3102 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3103 } else if (bmpImage
->green_mask
==0x07e0 &&
3104 (bmpImage
->red_mask
==0xf800 ||
3105 bmpImage
->blue_mask
==0xf800)) {
3106 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3107 convs
->Convert_any0888_to_5x5
3111 dstbits
,-bmpImage
->bytes_per_line
,
3112 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3122 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3123 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
3124 bmpImage
->green_mask
, bmpImage
->blue_mask
);
3130 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3131 const DWORD
* srcpixel
;
3132 int rShift
,gShift
,bShift
;
3134 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
3135 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
3136 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
3138 for (h
= lines
- 1; h
>= 0; h
--) {
3139 srcpixel
=(const DWORD
*)srcbits
;
3140 for (x
= left
; x
< width
+left
; x
++) {
3142 BYTE red
,green
,blue
;
3143 srcvalue
=*srcpixel
++;
3144 red
= (srcvalue
>> rShift
) & 0xff;
3145 green
=(srcvalue
>> gShift
) & 0xff;
3146 blue
= (srcvalue
>> bShift
) & 0xff;
3147 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
3148 (physDev
, RGB(red
,green
,blue
)));
3150 srcbits
+= linebytes
;
3158 /***********************************************************************
3159 * X11DRV_DIB_GetImageBits_32
3161 * GetDIBits for an 32-bit deep DIB.
3163 static void X11DRV_DIB_GetImageBits_32( int lines
, BYTE
*dstbits
,
3164 DWORD dstwidth
, DWORD srcwidth
,
3165 PALETTEENTRY
*srccolors
,
3166 DWORD rDst
, DWORD gDst
, DWORD bDst
,
3167 XImage
*bmpImage
, DWORD linebytes
)
3170 int h
, width
= min(srcwidth
, dstwidth
);
3172 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
3177 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
3178 linebytes
= -linebytes
;
3183 switch (bmpImage
->depth
)
3186 if (bmpImage
->bits_per_pixel
==24) {
3187 const void* srcbits
;
3189 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3191 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
3192 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3193 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3194 convs
->Convert_888_to_0888_asis
3196 srcbits
,-bmpImage
->bytes_per_line
,
3198 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3199 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3201 /* the tests below assume sane bmpImage masks */
3202 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
3203 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3204 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3205 convs
->Convert_888_to_0888_reverse
3207 srcbits
,-bmpImage
->bytes_per_line
,
3209 } else if (bmpImage
->blue_mask
==0xff) {
3210 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3211 convs
->Convert_rgb888_to_any0888
3213 srcbits
,-bmpImage
->bytes_per_line
,
3217 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3218 convs
->Convert_bgr888_to_any0888
3220 srcbits
,-bmpImage
->bytes_per_line
,
3230 const char* srcbits
;
3232 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3234 if (gDst
==bmpImage
->green_mask
) {
3235 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
3236 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3237 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3238 convs
->Convert_0888_asis
3240 srcbits
,-bmpImage
->bytes_per_line
,
3242 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3243 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3245 /* the tests below assume sane bmpImage masks */
3246 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
3247 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3248 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3249 convs
->Convert_0888_reverse
3251 srcbits
,-bmpImage
->bytes_per_line
,
3254 /* ==== any 0888 bmp -> any 0888 dib ==== */
3255 convs
->Convert_0888_any
3257 srcbits
,-bmpImage
->bytes_per_line
,
3258 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3262 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3263 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3265 /* the tests below assume sane bmpImage masks */
3267 /* ==== any 0888 bmp -> any 0888 dib ==== */
3268 convs
->Convert_0888_any
3270 srcbits
,-bmpImage
->bytes_per_line
,
3271 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3281 const char* srcbits
;
3283 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3285 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
3286 if (bmpImage
->green_mask
==0x03e0) {
3287 if (bmpImage
->red_mask
==0x7f00) {
3288 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3289 convs
->Convert_555_to_0888_asis
3291 srcbits
,-bmpImage
->bytes_per_line
,
3293 } else if (bmpImage
->blue_mask
==0x7f00) {
3294 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3295 convs
->Convert_555_to_0888_reverse
3297 srcbits
,-bmpImage
->bytes_per_line
,
3302 } else if (bmpImage
->green_mask
==0x07e0) {
3303 if (bmpImage
->red_mask
==0xf800) {
3304 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3305 convs
->Convert_565_to_0888_asis
3307 srcbits
,-bmpImage
->bytes_per_line
,
3309 } else if (bmpImage
->blue_mask
==0xf800) {
3310 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3311 convs
->Convert_565_to_0888_reverse
3313 srcbits
,-bmpImage
->bytes_per_line
,
3321 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
3322 if (bmpImage
->green_mask
==0x03e0) {
3323 if (bmpImage
->blue_mask
==0x7f00) {
3324 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3325 convs
->Convert_555_to_0888_asis
3327 srcbits
,-bmpImage
->bytes_per_line
,
3329 } else if (bmpImage
->red_mask
==0x7f00) {
3330 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3331 convs
->Convert_555_to_0888_reverse
3333 srcbits
,-bmpImage
->bytes_per_line
,
3338 } else if (bmpImage
->green_mask
==0x07e0) {
3339 if (bmpImage
->blue_mask
==0xf800) {
3340 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3341 convs
->Convert_565_to_0888_asis
3343 srcbits
,-bmpImage
->bytes_per_line
,
3345 } else if (bmpImage
->red_mask
==0xf800) {
3346 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3347 convs
->Convert_565_to_0888_reverse
3349 srcbits
,-bmpImage
->bytes_per_line
,
3358 if (bmpImage
->green_mask
==0x03e0 &&
3359 (bmpImage
->red_mask
==0x7f00 ||
3360 bmpImage
->blue_mask
==0x7f00)) {
3361 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3362 convs
->Convert_5x5_to_any0888
3364 srcbits
,-bmpImage
->bytes_per_line
,
3365 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3368 } else if (bmpImage
->green_mask
==0x07e0 &&
3369 (bmpImage
->red_mask
==0xf800 ||
3370 bmpImage
->blue_mask
==0xf800)) {
3371 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3372 convs
->Convert_5x5_to_any0888
3374 srcbits
,-bmpImage
->bytes_per_line
,
3375 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3387 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3389 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3390 int rShift
,gShift
,bShift
;
3393 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3394 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3395 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3396 for (h
= lines
- 1; h
>= 0; h
--) {
3397 dstpixel
=(DWORD
*)dstbits
;
3398 for (x
= 0; x
< width
; x
++) {
3399 PALETTEENTRY srcval
;
3400 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3401 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3402 (srcval
.peGreen
<< gShift
) |
3403 (srcval
.peBlue
<< bShift
);
3405 dstbits
+= linebytes
;
3413 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3415 /* ==== pal 8 bmp -> any 0888 dib ==== */
3416 int rShift
,gShift
,bShift
;
3417 const void* srcbits
;
3418 const BYTE
* srcpixel
;
3421 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3422 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3423 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3424 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3425 for (h
= lines
- 1; h
>= 0; h
--) {
3427 dstpixel
=(DWORD
*)dstbits
;
3428 for (x
= 0; x
< width
; x
++) {
3429 PALETTEENTRY srcval
;
3430 srcval
=srccolors
[*srcpixel
++];
3431 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3432 (srcval
.peGreen
<< gShift
) |
3433 (srcval
.peBlue
<< bShift
);
3435 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3436 dstbits
+= linebytes
;
3446 /* ==== any bmp format -> any 0888 dib ==== */
3447 int rShift
,gShift
,bShift
;
3450 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3451 bmpImage
->depth
, bmpImage
->red_mask
,
3452 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3455 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3456 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3457 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3458 for (h
= lines
- 1; h
>= 0; h
--) {
3459 dstpixel
=(DWORD
*)dstbits
;
3460 for (x
= 0; x
< width
; x
++) {
3462 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
3463 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3464 (GetGValue(srcval
) << gShift
) |
3465 (GetBValue(srcval
) << bShift
);
3467 dstbits
+= linebytes
;
3474 static int XGetSubImageErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
3476 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
3479 /***********************************************************************
3480 * X11DRV_DIB_SetImageBits_GetSubImage
3482 * Helper for X11DRV_DIB_SetImageBits
3484 static void X11DRV_DIB_SetImageBits_GetSubImage(
3485 const X11DRV_DIB_IMAGEBITS_DESCR
*descr
, XImage
*bmpImage
)
3487 /* compressed bitmaps may contain gaps in them. So make a copy
3488 * of the existing pixels first */
3491 SetRect( &bmprc
, descr
->xDest
, descr
->yDest
,
3492 descr
->xDest
+ descr
->width
, descr
->yDest
+ descr
->height
);
3493 GetRgnBox( descr
->physDev
->region
, &rc
);
3494 /* convert from dc to drawable origin */
3495 OffsetRect( &rc
, descr
->physDev
->dc_rect
.left
, descr
->physDev
->dc_rect
.top
);
3496 /* clip visible rect with bitmap */
3497 if( IntersectRect( &rc
, &rc
, &bmprc
))
3499 X11DRV_expect_error( gdi_display
, XGetSubImageErrorHandler
, NULL
);
3500 XGetSubImage( gdi_display
, descr
->drawable
, rc
.left
, rc
.top
,
3501 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, AllPlanes
,
3503 descr
->xSrc
+ rc
.left
- bmprc
.left
,
3504 descr
->ySrc
+ rc
.top
- bmprc
.top
);
3505 X11DRV_check_error();
3509 /***********************************************************************
3510 * X11DRV_DIB_SetImageBits
3512 * Transfer the bits to an X image.
3513 * Helper function for SetDIBits() and SetDIBitsToDevice().
3515 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3517 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3522 bmpImage
= descr
->image
;
3524 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3525 descr
->infoWidth
, lines
, 32, 0 );
3526 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3527 if(bmpImage
->data
== NULL
) {
3528 ERR("Out of memory!\n");
3529 XDestroyImage( bmpImage
);
3530 wine_tsx11_unlock();
3534 wine_tsx11_unlock();
3536 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3537 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3538 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3539 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3540 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3542 /* Transfer the pixels */
3545 switch(descr
->infoBpp
)
3548 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3549 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3550 bmpImage
, descr
->dibpitch
);
3553 if (descr
->compression
) {
3554 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3555 X11DRV_DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
3556 descr
->infoWidth
, descr
->width
,
3557 descr
->xSrc
, (int *)(descr
->colorMap
),
3560 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3561 descr
->infoWidth
, descr
->width
,
3562 descr
->xSrc
, (int*)(descr
->colorMap
),
3563 bmpImage
, descr
->dibpitch
);
3566 if (descr
->compression
) {
3567 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3568 X11DRV_DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
3569 descr
->infoWidth
, descr
->width
,
3570 descr
->xSrc
, (int *)(descr
->colorMap
),
3573 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3574 descr
->infoWidth
, descr
->width
,
3575 descr
->xSrc
, (int *)(descr
->colorMap
),
3576 bmpImage
, descr
->dibpitch
);
3580 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3581 descr
->infoWidth
, descr
->width
,
3582 descr
->xSrc
, descr
->physDev
,
3583 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3584 bmpImage
, descr
->dibpitch
);
3587 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3588 descr
->infoWidth
, descr
->width
,
3589 descr
->xSrc
, descr
->physDev
,
3590 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3591 bmpImage
, descr
->dibpitch
);
3594 X11DRV_DIB_SetImageBits_32( 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 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3607 WARN( "invalid bits pointer %p\n", descr
->bits
);
3612 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3613 descr
->drawable
, descr
->gc
, bmpImage
,
3614 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3615 descr
->width
, descr
->height
);
3620 #ifdef HAVE_LIBXXSHM
3621 if (descr
->image
&& descr
->useShm
)
3623 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3624 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3625 descr
->width
, descr
->height
, FALSE
);
3626 XSync( gdi_display
, 0 );
3630 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3631 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3632 descr
->width
, descr
->height
);
3634 if (!descr
->image
) XDestroyImage( bmpImage
);
3635 wine_tsx11_unlock();
3639 /***********************************************************************
3640 * X11DRV_DIB_GetImageBits
3642 * Transfer the bits from an X image.
3644 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3646 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3651 bmpImage
= descr
->image
;
3653 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3654 descr
->infoWidth
, lines
, 32, 0 );
3655 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3656 if(bmpImage
->data
== NULL
) {
3657 ERR("Out of memory!\n");
3658 XDestroyImage( bmpImage
);
3659 wine_tsx11_unlock();
3664 #ifdef HAVE_LIBXXSHM
3666 /* We must not call XShmGetImage() with a bitmap which is bigger than the available area.
3667 If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */
3668 if((descr
->image
&& descr
->useShm
) && (bmpImage
->width
<= (descr
->width
- descr
->xSrc
))
3669 && (bmpImage
->height
<= (descr
->height
- descr
->ySrc
)))
3671 int saveRed
, saveGreen
, saveBlue
;
3673 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3674 gdi_display
, descr
->drawable
, bmpImage
,
3675 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3677 /* We must save and restore the bmpImage's masks in order
3678 * to preserve them across the call to XShmGetImage, which
3679 * decides to eliminate them since it doesn't happen to know
3680 * what the format of the image is supposed to be, even though
3682 saveRed
= bmpImage
->red_mask
;
3683 saveBlue
= bmpImage
->blue_mask
;
3684 saveGreen
= bmpImage
->green_mask
;
3686 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3687 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3689 bmpImage
->red_mask
= saveRed
;
3690 bmpImage
->blue_mask
= saveBlue
;
3691 bmpImage
->green_mask
= saveGreen
;
3694 #endif /* HAVE_LIBXXSHM */
3696 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3697 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3698 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3699 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3700 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3701 bmpImage
, descr
->xDest
, descr
->yDest
);
3703 wine_tsx11_unlock();
3705 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3706 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3707 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3708 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3709 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3710 /* Transfer the pixels */
3711 switch(descr
->infoBpp
)
3714 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3715 descr
->infoWidth
, descr
->width
,
3716 descr
->colorMap
, descr
->palentry
,
3717 bmpImage
, descr
->dibpitch
);
3721 if (descr
->compression
) {
3722 FIXME("Compression not yet supported!\n");
3723 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 4 ) * abs(descr
->lines
))
3726 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3727 descr
->infoWidth
, descr
->width
,
3728 descr
->colorMap
, descr
->palentry
,
3729 bmpImage
, descr
->dibpitch
);
3732 if (descr
->compression
) {
3733 FIXME("Compression not yet supported!\n");
3734 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 8 ) * abs(descr
->lines
))
3737 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3738 descr
->infoWidth
, descr
->width
,
3739 descr
->colorMap
, descr
->palentry
,
3740 bmpImage
, descr
->dibpitch
);
3744 X11DRV_DIB_GetImageBits_16( descr
->lines
, (LPVOID
)descr
->bits
,
3745 descr
->infoWidth
,descr
->width
,
3747 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3748 bmpImage
, descr
->dibpitch
);
3752 X11DRV_DIB_GetImageBits_24( descr
->lines
, (LPVOID
)descr
->bits
,
3753 descr
->infoWidth
,descr
->width
,
3755 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3756 bmpImage
, descr
->dibpitch
);
3760 X11DRV_DIB_GetImageBits_32( descr
->lines
, (LPVOID
)descr
->bits
,
3761 descr
->infoWidth
, descr
->width
,
3763 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3764 bmpImage
, descr
->dibpitch
);
3768 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3775 XDestroyImage( bmpImage
);
3776 wine_tsx11_unlock();
3781 /*************************************************************************
3782 * X11DRV_SetDIBitsToDevice
3785 INT
X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE
*physDev
, INT xDest
, INT yDest
, DWORD cx
,
3786 DWORD cy
, INT xSrc
, INT ySrc
,
3787 UINT startscan
, UINT lines
, LPCVOID bits
,
3788 const BITMAPINFO
*info
, UINT coloruse
)
3790 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3795 int rop
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
) - 1];
3797 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3798 &descr
.infoBpp
, &descr
.compression
) == -1)
3801 top_down
= (height
< 0);
3802 if (top_down
) height
= -height
;
3806 LPtoDP(physDev
->hdc
, &pt
, 1);
3808 if (!lines
|| (startscan
>= height
)) return 0;
3809 if (!top_down
&& startscan
+ lines
> height
) lines
= height
- startscan
;
3811 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3812 * and clamp all values to fit inside [startscan,startscan+lines]
3814 if (ySrc
+ cy
<= startscan
+ lines
)
3816 UINT y
= startscan
+ lines
- (ySrc
+ cy
);
3817 if (ySrc
< startscan
) cy
-= (startscan
- ySrc
);
3820 /* avoid getting unnecessary lines */
3822 if (y
>= lines
) return 0;
3827 if (y
>= lines
) return lines
;
3828 ySrc
= y
; /* need to get all lines in top down mode */
3833 if (ySrc
>= startscan
+ lines
) return lines
;
3834 pt
.y
+= ySrc
+ cy
- (startscan
+ lines
);
3835 cy
= startscan
+ lines
- ySrc
;
3837 if (cy
> lines
) cy
= lines
;
3839 if (xSrc
>= width
) return lines
;
3840 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
3841 if (!cx
|| !cy
) return lines
;
3843 /* Update the pixmap from the DIB section */
3844 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
3846 X11DRV_SetupGCForText( physDev
); /* To have the correct colors */
3848 XSetFunction(gdi_display
, physDev
->gc
, rop
);
3849 wine_tsx11_unlock();
3851 switch (descr
.infoBpp
)
3856 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3858 physDev
->depth
, info
, &descr
.nColorMap
);
3859 if (!descr
.colorMap
) return 0;
3860 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3864 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3865 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3866 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3872 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3873 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3874 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3879 descr
.physDev
= physDev
;
3882 descr
.palentry
= NULL
;
3883 descr
.lines
= top_down
? -lines
: lines
;
3884 descr
.infoWidth
= width
;
3885 descr
.depth
= physDev
->depth
;
3886 descr
.drawable
= physDev
->drawable
;
3887 descr
.gc
= physDev
->gc
;
3890 descr
.xDest
= physDev
->dc_rect
.left
+ pt
.x
;
3891 descr
.yDest
= physDev
->dc_rect
.top
+ pt
.y
;
3894 descr
.useShm
= FALSE
;
3895 descr
.dibpitch
= ((width
* descr
.infoBpp
+ 31) &~31) / 8;
3897 result
= X11DRV_DIB_SetImageBits( &descr
);
3899 if (descr
.infoBpp
<= 8)
3900 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3902 /* Update the DIBSection of the pixmap */
3903 X11DRV_UnlockDIBSection(physDev
, TRUE
);
3908 /***********************************************************************
3909 * SetDIBits (X11DRV.@)
3911 INT
X11DRV_SetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
,
3912 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
, UINT coloruse
)
3914 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3915 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3917 LONG width
, height
, tmpheight
;
3920 descr
.physDev
= physDev
;
3922 if (!physBitmap
) return 0;
3924 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3925 &descr
.infoBpp
, &descr
.compression
) == -1)
3929 if (height
< 0) height
= -height
;
3930 if (!lines
|| (startscan
>= height
))
3933 if (!GetObjectW( hbitmap
, sizeof(bitmap
), &bitmap
)) return 0;
3935 if (startscan
+ lines
> height
) lines
= height
- startscan
;
3937 switch (descr
.infoBpp
)
3942 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3943 descr
.physDev
, coloruse
,
3944 physBitmap
->pixmap_depth
,
3945 info
, &descr
.nColorMap
);
3946 if (!descr
.colorMap
) return 0;
3947 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3951 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3952 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3953 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3959 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3960 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3961 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3970 descr
.palentry
= NULL
;
3971 descr
.infoWidth
= width
;
3972 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
3973 descr
.depth
= physBitmap
->pixmap_depth
;
3974 descr
.drawable
= physBitmap
->pixmap
;
3975 descr
.gc
= BITMAP_GC(physBitmap
);
3979 descr
.yDest
= height
- startscan
- lines
;
3980 descr
.width
= bitmap
.bmWidth
;
3981 descr
.height
= lines
;
3982 descr
.useShm
= FALSE
;
3983 descr
.dibpitch
= ((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8;
3984 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
3985 result
= X11DRV_DIB_SetImageBits( &descr
);
3987 /* optimisation for the case where the input bits are in exactly the same
3988 * format as the internal representation and copying to the app bits is
3989 * cheap - saves a round trip to the X server */
3990 if (descr
.compression
== BI_RGB
&&
3991 coloruse
== DIB_RGB_COLORS
&&
3992 descr
.infoBpp
== bitmap
.bmBitsPixel
&&
3993 physBitmap
->base
&& physBitmap
->size
< 65536)
3995 unsigned int srcwidthb
= bitmap
.bmWidthBytes
;
3996 int dstwidthb
= X11DRV_DIB_GetDIBWidthBytes( width
, descr
.infoBpp
);
3997 LPBYTE dbits
= physBitmap
->base
, sbits
= (LPBYTE
)bits
+ (startscan
* srcwidthb
);
4001 TRACE("syncing compatible set bits to app bits\n");
4002 if ((tmpheight
< 0) ^ (bitmap
.bmHeight
< 0))
4004 dbits
= (LPBYTE
)bits
+ (dstwidthb
* (lines
-1));
4005 dstwidthb
= -dstwidthb
;
4007 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4008 widthb
= min(srcwidthb
, abs(dstwidthb
));
4009 for (y
= 0; y
< lines
; y
++, dbits
+= dstwidthb
, sbits
+= srcwidthb
)
4010 memcpy(dbits
, sbits
, widthb
);
4011 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4012 physBitmap
->status
= DIB_Status_InSync
;
4014 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4016 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4021 /***********************************************************************
4022 * GetDIBits (X11DRV.@)
4024 INT
X11DRV_GetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
, UINT lines
,
4025 LPVOID bits
, BITMAPINFO
*info
, UINT coloruse
)
4027 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
4029 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4030 PALETTEENTRY palette
[256];
4033 LONG width
, tempHeight
;
4038 GetPaletteEntries( GetCurrentObject( physDev
->hdc
, OBJ_PAL
), 0, 256, palette
);
4040 if (!physBitmap
) return 0;
4041 if (!(obj_size
= GetObjectW( hbitmap
, sizeof(dib
), &dib
))) return 0;
4043 bitmap_type
= DIB_GetBitmapInfo( (BITMAPINFOHEADER
*)info
, &width
, &tempHeight
, &descr
.infoBpp
, &descr
.compression
);
4044 if (bitmap_type
== -1)
4046 ERR("Invalid bitmap\n");
4049 descr
.lines
= tempHeight
;
4050 core_header
= (bitmap_type
== 0);
4051 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
4053 TRACE("%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
4054 lines
, dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
, width
, descr
.lines
, startscan
);
4056 if( lines
> dib
.dsBm
.bmHeight
) lines
= dib
.dsBm
.bmHeight
;
4058 height
= descr
.lines
;
4059 if (height
< 0) height
= -height
;
4060 if( lines
> height
) lines
= height
;
4061 /* Top-down images have a negative biHeight, the scanlines of these images
4062 * were inverted in X11DRV_DIB_GetImageBits_xx
4063 * To prevent this we simply change the sign of lines
4064 * (the number of scan lines to copy).
4065 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
4067 if( descr
.lines
< 0 && lines
> 0) lines
= -lines
;
4069 if( startscan
>= dib
.dsBm
.bmHeight
) return 0;
4071 descr
.colorMap
= NULL
;
4073 switch (descr
.infoBpp
)
4078 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4079 if(coloruse
== DIB_RGB_COLORS
)
4080 descr
.colorMap
= colorPtr
;
4082 int num_colors
= 1 << descr
.infoBpp
, i
;
4085 WORD
*index
= (WORD
*)colorPtr
;
4086 descr
.colorMap
= rgb
= HeapAlloc(GetProcessHeap(), 0, num_colors
* sizeof(RGBQUAD
));
4087 for(i
= 0; i
< num_colors
; i
++, rgb
++, index
++) {
4088 colref
= X11DRV_PALETTE_ToLogical(X11DRV_PALETTE_ToPhysical(physDev
, PALETTEINDEX(*index
)));
4089 rgb
->rgbRed
= GetRValue(colref
);
4090 rgb
->rgbGreen
= GetGValue(colref
);
4091 rgb
->rgbBlue
= GetBValue(colref
);
4092 rgb
->rgbReserved
= 0;
4098 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4099 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4100 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4104 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4105 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4106 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4110 descr
.physDev
= physDev
;
4111 descr
.palentry
= palette
;
4113 descr
.image
= physBitmap
->image
;
4114 descr
.infoWidth
= width
;
4115 descr
.lines
= lines
;
4116 descr
.depth
= physBitmap
->pixmap_depth
;
4117 descr
.drawable
= physBitmap
->pixmap
;
4118 descr
.gc
= BITMAP_GC(physBitmap
);
4119 descr
.width
= dib
.dsBm
.bmWidth
;
4120 descr
.height
= dib
.dsBm
.bmHeight
;
4124 descr
.sizeImage
= core_header
? 0 : info
->bmiHeader
.biSizeImage
;
4126 if (descr
.lines
> 0)
4128 descr
.ySrc
= (descr
.height
-1) - (startscan
+ (lines
-1));
4132 descr
.ySrc
= startscan
;
4134 #ifdef HAVE_LIBXXSHM
4135 descr
.useShm
= (obj_size
== sizeof(DIBSECTION
)) && (physBitmap
->shminfo
.shmid
!= -1);
4137 descr
.useShm
= FALSE
;
4139 descr
.dibpitch
= (obj_size
== sizeof(DIBSECTION
)) ? dib
.dsBm
.bmWidthBytes
4140 : (((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8);
4142 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
4143 X11DRV_DIB_GetImageBits( &descr
);
4144 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4146 if(!core_header
&& info
->bmiHeader
.biSizeImage
== 0) /* Fill in biSizeImage */
4147 info
->bmiHeader
.biSizeImage
= X11DRV_DIB_GetDIBImageBytes( descr
.infoWidth
,
4151 if (descr
.compression
== BI_BITFIELDS
)
4153 *(DWORD
*)info
->bmiColors
= descr
.rMask
;
4154 *((DWORD
*)info
->bmiColors
+ 1) = descr
.gMask
;
4155 *((DWORD
*)info
->bmiColors
+ 2) = descr
.bMask
;
4157 else if (!core_header
)
4159 /* if RLE or JPEG compression were supported,
4160 * this line would be invalid. */
4161 info
->bmiHeader
.biCompression
= 0;
4164 if(descr
.colorMap
!= colorPtr
)
4165 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4169 /***********************************************************************
4170 * X11DRV_DIB_DoCopyDIBSection
4172 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
4173 void *colorMap
, int nColorMap
,
4174 Drawable dest
, GC gc
,
4175 DWORD xSrc
, DWORD ySrc
,
4176 DWORD xDest
, DWORD yDest
,
4177 DWORD width
, DWORD height
)
4179 DIBSECTION dibSection
;
4180 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4181 int identity
[2] = {0,1};
4183 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
4185 descr
.physDev
= NULL
;
4186 descr
.palentry
= NULL
;
4187 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
4188 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
4189 descr
.lines
= dibSection
.dsBmih
.biHeight
;
4190 descr
.image
= physBitmap
->image
;
4191 descr
.colorMap
= colorMap
;
4192 descr
.nColorMap
= nColorMap
;
4193 descr
.bits
= dibSection
.dsBm
.bmBits
;
4194 descr
.depth
= physBitmap
->pixmap_depth
;
4195 descr
.compression
= dibSection
.dsBmih
.biCompression
;
4197 if(descr
.infoBpp
== 1)
4198 descr
.colorMap
= (void*)identity
;
4200 switch (descr
.infoBpp
)
4205 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4209 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
4210 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
4211 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
4216 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
4217 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
4218 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
4223 descr
.drawable
= dest
;
4227 descr
.xDest
= xDest
;
4228 descr
.yDest
= yDest
;
4229 descr
.width
= width
;
4230 descr
.height
= height
;
4231 descr
.sizeImage
= 0;
4233 #ifdef HAVE_LIBXXSHM
4234 descr
.useShm
= (physBitmap
->shminfo
.shmid
!= -1);
4236 descr
.useShm
= FALSE
;
4238 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
4242 TRACE("Copying from Pixmap to DIB bits\n");
4243 X11DRV_DIB_GetImageBits( &descr
);
4247 TRACE("Copying from DIB bits to Pixmap\n");
4248 X11DRV_DIB_SetImageBits( &descr
);
4252 /***********************************************************************
4253 * X11DRV_DIB_CopyDIBSection
4255 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE
*physDevSrc
, X11DRV_PDEVICE
*physDevDst
,
4256 DWORD xSrc
, DWORD ySrc
, DWORD xDest
, DWORD yDest
,
4257 DWORD width
, DWORD height
)
4260 X_PHYSBITMAP
*physBitmap
;
4261 unsigned int nColorMap
;
4265 TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc
->hdc
, physDevDst
->hdc
,
4266 xSrc
, ySrc
, xDest
, yDest
, width
, height
);
4267 /* this function is meant as an optimization for BitBlt,
4268 * not to be called otherwise */
4269 physBitmap
= physDevSrc
->bitmap
;
4270 if (!physBitmap
|| GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
4272 ERR("called for non-DIBSection!?\n");
4275 /* while BitBlt should already have made sure we only get
4276 * positive values, we should check for oversize values */
4277 if ((xSrc
< dib
.dsBm
.bmWidth
) &&
4278 (ySrc
< dib
.dsBm
.bmHeight
)) {
4279 if (xSrc
+ width
> dib
.dsBm
.bmWidth
)
4280 width
= dib
.dsBm
.bmWidth
- xSrc
;
4281 if (ySrc
+ height
> dib
.dsBm
.bmHeight
)
4282 height
= dib
.dsBm
.bmHeight
- ySrc
;
4283 /* if the source bitmap is 8bpp or less, we're supposed to use the
4284 * DC's palette for color conversion (not the DIB color table) */
4285 if (dib
.dsBm
.bmBitsPixel
<= 8) {
4286 HPALETTE hPalette
= GetCurrentObject( physDevSrc
->hdc
, OBJ_PAL
);
4287 if (!hPalette
|| (hPalette
== GetStockObject(DEFAULT_PALETTE
))) {
4288 /* HACK: no palette has been set in the source DC,
4289 * use the DIB colormap instead - this is necessary in some
4290 * cases since we need to do depth conversion in some places
4291 * where real Windows can just copy data straight over */
4292 x11ColorMap
= physBitmap
->colorMap
;
4293 nColorMap
= physBitmap
->nColorMap
;
4294 freeColorMap
= FALSE
;
4296 const BITMAPINFO
* info
= (BITMAPINFO
*)&dib
.dsBmih
;
4299 nColorMap
= X11DRV_DIB_GetColorCount(info
);
4300 x11ColorMap
= HeapAlloc(GetProcessHeap(), 0, nColorMap
* sizeof(int));
4301 for (i
= 0; i
< nColorMap
; i
++)
4302 x11ColorMap
[i
] = X11DRV_PALETTE_ToPhysical(physDevSrc
, PALETTEINDEX(i
));
4303 freeColorMap
= TRUE
;
4310 freeColorMap
= FALSE
;
4312 /* perform the copy */
4313 X11DRV_DIB_DoCopyDIBSection(physBitmap
, FALSE
, x11ColorMap
, nColorMap
,
4314 physDevDst
->drawable
, physDevDst
->gc
, xSrc
, ySrc
,
4315 physDevDst
->dc_rect
.left
+ xDest
, physDevDst
->dc_rect
.top
+ yDest
,
4317 /* free color mapping */
4319 HeapFree(GetProcessHeap(), 0, x11ColorMap
);
4323 /***********************************************************************
4324 * X11DRV_DIB_DoUpdateDIBSection
4326 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
4330 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
4331 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
4332 physBitmap
->colorMap
, physBitmap
->nColorMap
,
4333 physBitmap
->pixmap
, BITMAP_GC(physBitmap
),
4334 0, 0, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
);
4337 /***********************************************************************
4338 * X11DRV_DIB_FaultHandler
4340 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
4342 X_PHYSBITMAP
*physBitmap
= NULL
;
4346 const size_t pagemask
= getpagesize() - 1;
4348 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
4349 return EXCEPTION_CONTINUE_SEARCH
;
4351 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
4353 EnterCriticalSection(&dibs_cs
);
4354 LIST_FOR_EACH( ptr
, &dibs_list
)
4356 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
4357 if ((physBitmap
->base
<= addr
) &&
4358 (addr
< physBitmap
->base
+ ((physBitmap
->size
+ pagemask
) & ~pagemask
)))
4364 LeaveCriticalSection(&dibs_cs
);
4366 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
4368 if (addr
>= physBitmap
->base
+ physBitmap
->size
)
4369 WARN( "%p: access to %p beyond the end of the DIB\n", physBitmap
->hbitmap
, addr
);
4371 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
);
4372 if (ep
->ExceptionRecord
->ExceptionInformation
[0] == EXCEPTION_WRITE_FAULT
) {
4373 /* the app tried to write the DIB bits */
4374 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
);
4376 /* the app tried to read the DIB bits */
4377 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
);
4379 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4381 return EXCEPTION_CONTINUE_EXECUTION
;
4384 /***********************************************************************
4387 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
)
4389 INT ret
= DIB_Status_None
;
4391 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4392 EnterCriticalSection(&physBitmap
->lock
);
4393 ret
= physBitmap
->status
;
4395 case DIB_Status_GdiMod
:
4396 /* GDI access - request to draw on pixmap */
4397 switch (physBitmap
->status
)
4400 case DIB_Status_None
:
4401 physBitmap
->p_status
= DIB_Status_GdiMod
;
4402 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4405 case DIB_Status_GdiMod
:
4406 TRACE("GdiMod requested in status GdiMod\n" );
4407 physBitmap
->p_status
= DIB_Status_GdiMod
;
4410 case DIB_Status_InSync
:
4411 TRACE("GdiMod requested in status InSync\n" );
4412 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4413 physBitmap
->status
= DIB_Status_GdiMod
;
4414 physBitmap
->p_status
= DIB_Status_InSync
;
4417 case DIB_Status_AppMod
:
4418 TRACE("GdiMod requested in status AppMod\n" );
4419 /* make it readonly to avoid app changing data while we copy */
4420 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4421 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4422 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4423 physBitmap
->p_status
= DIB_Status_AppMod
;
4424 physBitmap
->status
= DIB_Status_GdiMod
;
4429 case DIB_Status_InSync
:
4430 /* App access - request access to read DIB surface */
4431 /* (typically called from signal handler) */
4432 switch (physBitmap
->status
)
4435 case DIB_Status_None
:
4436 /* shouldn't happen from signal handler */
4439 case DIB_Status_GdiMod
:
4440 TRACE("InSync requested in status GdiMod\n" );
4441 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4442 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4443 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4444 physBitmap
->status
= DIB_Status_InSync
;
4447 case DIB_Status_InSync
:
4448 TRACE("InSync requested in status InSync\n" );
4449 /* shouldn't happen from signal handler */
4452 case DIB_Status_AppMod
:
4453 TRACE("InSync requested in status AppMod\n" );
4454 /* no reason to do anything here, and this
4455 * shouldn't happen from signal handler */
4460 case DIB_Status_AppMod
:
4461 /* App access - request access to write DIB surface */
4462 /* (typically called from signal handler) */
4463 switch (physBitmap
->status
)
4466 case DIB_Status_None
:
4467 /* shouldn't happen from signal handler */
4470 case DIB_Status_GdiMod
:
4471 TRACE("AppMod requested in status GdiMod\n" );
4472 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4473 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4474 physBitmap
->status
= DIB_Status_AppMod
;
4477 case DIB_Status_InSync
:
4478 TRACE("AppMod requested in status InSync\n" );
4479 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4480 physBitmap
->status
= DIB_Status_AppMod
;
4483 case DIB_Status_AppMod
:
4484 TRACE("AppMod requested in status AppMod\n" );
4485 /* shouldn't happen from signal handler */
4490 /* it is up to the caller to do the copy/conversion, probably
4491 * using the return value to decide where to copy from */
4493 LeaveCriticalSection(&physBitmap
->lock
);
4497 /***********************************************************************
4500 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
)
4502 INT ret
= DIB_Status_None
;
4504 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4505 TRACE("Locking %p from thread %04x\n", physBitmap
->hbitmap
, GetCurrentThreadId());
4506 EnterCriticalSection(&physBitmap
->lock
);
4507 ret
= physBitmap
->status
;
4508 if (req
!= DIB_Status_None
)
4509 X11DRV_DIB_Coerce(physBitmap
, req
);
4513 /***********************************************************************
4516 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
4518 if (!physBitmap
->image
) return; /* not a DIB section */
4519 switch (physBitmap
->status
)
4522 case DIB_Status_None
:
4523 /* in case anyone is wondering, this is the "signal handler doesn't
4524 * work" case, where we always have to be ready for app access */
4526 switch (physBitmap
->p_status
)
4528 case DIB_Status_GdiMod
:
4529 TRACE("Unlocking and syncing from GdiMod\n" );
4530 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4534 TRACE("Unlocking without needing to sync\n" );
4538 else TRACE("Unlocking with no changes\n");
4539 physBitmap
->p_status
= DIB_Status_None
;
4542 case DIB_Status_GdiMod
:
4543 TRACE("Unlocking in status GdiMod\n" );
4544 /* DIB was protected in Coerce */
4546 /* no commit, revert to InSync if applicable */
4547 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
4548 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
4549 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4550 physBitmap
->status
= DIB_Status_InSync
;
4555 case DIB_Status_InSync
:
4556 TRACE("Unlocking in status InSync\n" );
4557 /* DIB was already protected in Coerce */
4560 case DIB_Status_AppMod
:
4561 TRACE("Unlocking in status AppMod\n" );
4562 /* DIB was already protected in Coerce */
4563 /* this case is ordinary only called from the signal handler,
4564 * so we don't bother to check for !commit */
4567 LeaveCriticalSection(&physBitmap
->lock
);
4568 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
4571 /***********************************************************************
4572 * X11DRV_CoerceDIBSection
4574 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4576 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4577 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
);
4580 /***********************************************************************
4581 * X11DRV_LockDIBSection
4583 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4585 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4586 return X11DRV_DIB_Lock(physDev
->bitmap
, req
);
4589 /***********************************************************************
4590 * X11DRV_UnlockDIBSection
4592 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
4594 if (!physDev
|| !physDev
->bitmap
) return;
4595 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
4599 #ifdef HAVE_LIBXXSHM
4600 /***********************************************************************
4601 * X11DRV_XShmErrorHandler
4604 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
4606 return 1; /* FIXME: should check event contents */
4609 /***********************************************************************
4610 * X11DRV_XShmCreateImage
4613 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
4614 XShmSegmentInfo
* shminfo
)
4618 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
4621 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
4623 if( shminfo
->shmid
!= -1 )
4625 shminfo
->shmaddr
= image
->data
= shmat(shminfo
->shmid
, 0, 0);
4626 if( shminfo
->shmaddr
!= (char*)-1 )
4630 shminfo
->readOnly
= FALSE
;
4631 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
4632 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
4633 XSync( gdi_display
, False
);
4634 if (X11DRV_check_error()) ok
= FALSE
;
4637 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4638 return image
; /* Success! */
4640 /* An error occurred */
4641 shmdt(shminfo
->shmaddr
);
4643 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4644 shminfo
->shmid
= -1;
4646 XFlush(gdi_display
);
4647 XDestroyImage(image
);
4652 #endif /* HAVE_LIBXXSHM */
4655 /***********************************************************************
4656 * X11DRV_CreateDIBSection (X11DRV.@)
4658 HBITMAP
X11DRV_CreateDIBSection( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
,
4659 const BITMAPINFO
*bmi
, UINT usage
)
4661 X_PHYSBITMAP
*physBitmap
;
4664 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
4665 physBitmap
->status
= DIB_Status_None
;
4667 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
4669 /* create color map */
4670 if (dib
.dsBm
.bmBitsPixel
<= 8)
4672 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( physDev
,
4673 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
4674 &physBitmap
->nColorMap
);
4677 /* create pixmap and X image */
4679 physBitmap
->pixmap_depth
= (dib
.dsBm
.bmBitsPixel
== 1) ? 1 : screen_depth
;
4680 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
4681 dib
.dsBm
.bmHeight
, physBitmap
->pixmap_depth
);
4682 #ifdef HAVE_LIBXXSHM
4683 physBitmap
->shminfo
.shmid
= -1;
4684 if (!XShmQueryExtension(gdi_display
) ||
4685 !(physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4686 physBitmap
->pixmap_depth
, &physBitmap
->shminfo
)) )
4688 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4689 physBitmap
->pixmap_depth
);
4690 wine_tsx11_unlock();
4691 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
4693 /* install fault handler */
4694 InitializeCriticalSection( &physBitmap
->lock
);
4695 physBitmap
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": X_PHYSBITMAP.lock");
4697 physBitmap
->base
= dib
.dsBm
.bmBits
;
4698 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
4699 physBitmap
->status
= DIB_Status_AppMod
;
4702 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
4703 EnterCriticalSection( &dibs_cs
);
4704 list_add_head( &dibs_list
, &physBitmap
->entry
);
4705 LeaveCriticalSection( &dibs_cs
);
4707 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4712 /***********************************************************************
4713 * X11DRV_DIB_DeleteDIBSection
4715 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
4719 EnterCriticalSection( &dibs_cs
);
4720 list_remove( &physBitmap
->entry
);
4721 last
= list_empty( &dibs_list
);
4722 LeaveCriticalSection( &dibs_cs
);
4726 RemoveVectoredExceptionHandler( dibs_handler
);
4727 dibs_handler
= NULL
;
4730 if (dib
->dshSection
)
4731 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
);
4733 if (physBitmap
->image
)
4736 #ifdef HAVE_LIBXXSHM
4737 if (physBitmap
->shminfo
.shmid
!= -1)
4739 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4740 XDestroyImage( physBitmap
->image
);
4741 shmdt( physBitmap
->shminfo
.shmaddr
);
4742 physBitmap
->shminfo
.shmid
= -1;
4746 XDestroyImage( physBitmap
->image
);
4747 wine_tsx11_unlock();
4750 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4751 physBitmap
->lock
.DebugInfo
->Spare
[0] = 0;
4752 DeleteCriticalSection(&physBitmap
->lock
);
4755 /***********************************************************************
4756 * SetDIBColorTable (X11DRV.@)
4758 UINT
X11DRV_SetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4762 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4764 if (!physBitmap
) return 0;
4765 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4767 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4768 UINT end
= count
+ start
;
4769 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4771 * Changing color table might change the mapping between
4772 * DIB colors and X11 colors and thus alter the visible state
4773 * of the bitmap object.
4776 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4777 * at least for a 1 bpp dibsection
4779 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
);
4780 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4781 dib
.dsBm
.bmBitsPixel
,
4782 TRUE
, colors
, start
, end
);
4783 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4790 /***********************************************************************
4791 * X11DRV_DIB_CreateDIBFromBitmap
4793 * Allocates a packed DIB and copies the bitmap data into it.
4795 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4800 LPBITMAPINFOHEADER pbmiHeader
;
4801 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4804 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4807 * A packed DIB contains a BITMAPINFO structure followed immediately by
4808 * an optional color palette and the pixel data.
4811 /* Calculate the size of the packed DIB */
4812 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4813 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4814 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4816 /* Get the offset to the bits */
4817 OffsetBits
= cPackedSize
- cDataSize
;
4819 /* Allocate the packed DIB */
4820 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4821 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4825 WARN("Could not allocate packed DIB!\n");
4829 /* A packed DIB starts with a BITMAPINFOHEADER */
4830 pPackedDIB
= GlobalLock(hPackedDIB
);
4831 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4833 /* Init the BITMAPINFOHEADER */
4834 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
4835 pbmiHeader
->biWidth
= bmp
.bmWidth
;
4836 pbmiHeader
->biHeight
= bmp
.bmHeight
;
4837 pbmiHeader
->biPlanes
= 1;
4838 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
4839 pbmiHeader
->biCompression
= BI_RGB
;
4840 pbmiHeader
->biSizeImage
= 0;
4841 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
4842 pbmiHeader
->biClrUsed
= 0;
4843 pbmiHeader
->biClrImportant
= 0;
4845 /* Retrieve the DIB bits from the bitmap and fill in the
4846 * DIB color table if present */
4848 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
4849 hBmp
, /* Handle to bitmap */
4850 0, /* First scan line to set in dest bitmap */
4851 bmp
.bmHeight
, /* Number of scan lines to copy */
4852 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
4853 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
4854 0); /* RGB or palette index */
4855 GlobalUnlock(hPackedDIB
);
4857 /* Cleanup if GetDIBits failed */
4858 if (nLinesCopied
!= bmp
.bmHeight
)
4860 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
4861 GlobalFree(hPackedDIB
);
4868 /**************************************************************************
4869 * X11DRV_DIB_CreateDIBFromPixmap
4871 * Allocates a packed DIB and copies the Pixmap data into it.
4872 * The Pixmap passed in is deleted after the conversion.
4874 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
4877 X_PHYSBITMAP
*physBitmap
;
4880 HGLOBAL hPackedDIB
= 0;
4882 int x
,y
; /* Unused */
4883 unsigned border_width
; /* Unused */
4884 unsigned int depth
, width
, height
;
4886 /* Get the Pixmap dimensions and bit depth */
4888 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
4889 &border_width
, &depth
)) depth
= 0;
4890 wine_tsx11_unlock();
4891 if (!depth
) return 0;
4893 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4894 width
, height
, depth
);
4897 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4898 * and make it a container for the pixmap passed.
4900 if (!(hBmp
= CreateBitmap( width
, height
, 1, depth_to_bpp(depth
), NULL
))) return 0;
4902 /* force bitmap to be owned by a screen DC */
4903 hdcMem
= CreateCompatibleDC( hdc
);
4904 SelectObject( hdcMem
, SelectObject( hdcMem
, hBmp
));
4907 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4909 /* swap the new pixmap in */
4910 orig_pixmap
= physBitmap
->pixmap
;
4911 physBitmap
->pixmap
= pixmap
;
4914 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4915 * A packed DIB contains a BITMAPINFO structure followed immediately by
4916 * an optional color palette and the pixel data.
4918 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
4920 /* we can now get rid of the HBITMAP and its original pixmap */
4921 physBitmap
->pixmap
= orig_pixmap
;
4924 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
4929 /**************************************************************************
4930 * X11DRV_DIB_CreatePixmapFromDIB
4932 * Creates a Pixmap from a packed DIB
4934 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
4937 X_PHYSBITMAP
*physBitmap
;
4941 /* Create a DDB from the DIB */
4943 pbmi
= GlobalLock(hPackedDIB
);
4944 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
4945 (LPBYTE
)pbmi
+ bitmap_info_size( pbmi
, DIB_RGB_COLORS
),
4946 pbmi
, DIB_RGB_COLORS
);
4947 GlobalUnlock(hPackedDIB
);
4949 /* clear the physBitmap so that we can steal its pixmap */
4950 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4951 pixmap
= physBitmap
->pixmap
;
4952 physBitmap
->pixmap
= 0;
4954 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4957 TRACE("Returning Pixmap %lx\n", pixmap
);