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
25 #include <X11/extensions/XShm.h>
26 # ifdef HAVE_SYS_SHM_H
29 # ifdef HAVE_SYS_IPC_H
32 #endif /* defined(HAVE_LIBXXSHM) */
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(bitmap
);
46 static struct list dibs_list
= LIST_INIT(dibs_list
);
48 static CRITICAL_SECTION dibs_cs
;
49 static CRITICAL_SECTION_DEBUG dibs_cs_debug
=
52 { &dibs_cs_debug
.ProcessLocksList
, &dibs_cs_debug
.ProcessLocksList
},
53 0, 0, { (DWORD_PTR
)(__FILE__
": dibs_cs") }
55 static CRITICAL_SECTION dibs_cs
= { &dibs_cs_debug
, -1, 0, 0, 0, 0 };
57 static PVOID dibs_handler
;
59 static int ximageDepthTable
[32];
61 /* This structure holds the arguments for DIB_SetImageBits() */
64 X11DRV_PDEVICE
*physDev
;
67 PALETTEENTRY
*palentry
;
89 } X11DRV_DIB_IMAGEBITS_DESCR
;
94 RLE_EOL
= 0, /* End of line */
95 RLE_END
= 1, /* End of bitmap */
96 RLE_DELTA
= 2 /* Delta */
100 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*,INT
,BOOL
);
101 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*,INT
,BOOL
);
102 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*,BOOL
);
105 Some of the following helper functions are duplicated in
109 /***********************************************************************
110 * X11DRV_DIB_GetXImageWidthBytes
112 * Return the width of an X image in bytes
114 static inline int X11DRV_DIB_GetXImageWidthBytes( int width
, int depth
)
116 if (!depth
|| depth
> 32) goto error
;
118 if (!ximageDepthTable
[depth
-1])
120 XImage
*testimage
= XCreateImage( gdi_display
, visual
, depth
,
121 ZPixmap
, 0, NULL
, 1, 1, 32, 20 );
124 ximageDepthTable
[depth
-1] = testimage
->bits_per_pixel
;
125 XDestroyImage( testimage
);
127 else ximageDepthTable
[depth
-1] = -1;
129 if (ximageDepthTable
[depth
-1] != -1)
130 return (4 * ((width
* ximageDepthTable
[depth
-1] + 31) / 32));
133 WARN( "(%d): Unsupported depth\n", depth
);
138 /***********************************************************************
139 * X11DRV_DIB_GetDIBWidthBytes
141 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
143 static int X11DRV_DIB_GetDIBWidthBytes( int width
, int depth
)
149 case 1: words
= (width
+ 31) / 32; break;
150 case 4: words
= (width
+ 7) / 8; break;
151 case 8: words
= (width
+ 3) / 4; break;
153 case 16: words
= (width
+ 1) / 2; break;
154 case 24: words
= (width
* 3 + 3) / 4; break;
156 WARN("(%d): Unsupported depth\n", depth
);
165 /***********************************************************************
166 * X11DRV_DIB_GetDIBImageBytes
168 * Return the number of bytes used to hold the image in a DIB bitmap.
170 static int X11DRV_DIB_GetDIBImageBytes( int width
, int height
, int depth
)
172 return X11DRV_DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
176 /***********************************************************************
177 * X11DRV_DIB_BitmapInfoSize
179 * Return the size of the bitmap info structure including color table.
181 int X11DRV_DIB_BitmapInfoSize( const BITMAPINFO
* info
, WORD coloruse
)
185 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
187 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
188 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
189 return sizeof(BITMAPCOREHEADER
) + colors
*
190 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
192 else /* assume BITMAPINFOHEADER */
194 colors
= info
->bmiHeader
.biClrUsed
;
195 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
196 colors
= 1 << info
->bmiHeader
.biBitCount
;
197 return sizeof(BITMAPINFOHEADER
) + colors
*
198 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
203 /***********************************************************************
204 * X11DRV_DIB_CreateXImage
208 XImage
*X11DRV_DIB_CreateXImage( int width
, int height
, int depth
)
214 width_bytes
= X11DRV_DIB_GetXImageWidthBytes( width
, depth
);
215 image
= XCreateImage( gdi_display
, visual
, depth
, ZPixmap
, 0,
216 calloc( height
, width_bytes
),
217 width
, height
, 32, width_bytes
);
223 /***********************************************************************
224 * DIB_GetBitmapInfoEx
226 * Get the info from a bitmap header.
227 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
229 static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER
*header
, LONG
*width
,
230 LONG
*height
, WORD
*planes
, WORD
*bpp
,
231 WORD
*compr
, DWORD
*size
)
233 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
235 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
236 *width
= core
->bcWidth
;
237 *height
= core
->bcHeight
;
238 *planes
= core
->bcPlanes
;
239 *bpp
= core
->bcBitCount
;
244 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
))
246 *width
= header
->biWidth
;
247 *height
= header
->biHeight
;
248 *planes
= header
->biPlanes
;
249 *bpp
= header
->biBitCount
;
250 *compr
= header
->biCompression
;
251 *size
= header
->biSizeImage
;
254 ERR("(%d): unknown/wrong size for header\n", header
->biSize
);
259 /***********************************************************************
262 * Get the info from a bitmap header.
263 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
265 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
266 LONG
*height
, WORD
*bpp
, WORD
*compr
)
271 return DIB_GetBitmapInfoEx( header
, width
, height
, &planes
, bpp
, compr
, &size
);
275 static inline BOOL
colour_is_brighter(RGBQUAD c1
, RGBQUAD c2
)
277 return (c1
.rgbRed
* c1
.rgbRed
+ c1
.rgbGreen
* c1
.rgbGreen
+ c1
.rgbBlue
* c1
.rgbBlue
) >
278 (c2
.rgbRed
* c2
.rgbRed
+ c2
.rgbGreen
* c2
.rgbGreen
+ c2
.rgbBlue
* c2
.rgbBlue
);
281 /***********************************************************************
282 * X11DRV_DIB_GenColorMap
284 * Fills the color map of a bitmap palette. Should not be called
285 * for a >8-bit deep bitmap.
287 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE
*physDev
, int *colorMapping
,
288 WORD coloruse
, WORD depth
, BOOL quads
,
289 const void *colorPtr
, int start
, int end
)
293 if (coloruse
== DIB_RGB_COLORS
)
297 const RGBQUAD
* rgb
= (const RGBQUAD
*)colorPtr
;
299 if (depth
== 1) /* Monochrome */
304 if (GetDIBColorTable( physDev
->hdc
, 0, 2, table
) == 2)
305 invert
= !colour_is_brighter(table
[1], table
[0]);
307 for (i
= start
; i
< end
; i
++, rgb
++)
308 colorMapping
[i
] = ((rgb
->rgbRed
+ rgb
->rgbGreen
+
309 rgb
->rgbBlue
> 255*3/2 && !invert
) ||
310 (rgb
->rgbRed
+ rgb
->rgbGreen
+
311 rgb
->rgbBlue
<= 255*3/2 && invert
));
314 for (i
= start
; i
< end
; i
++, rgb
++)
315 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( NULL
, RGB(rgb
->rgbRed
,
321 const RGBTRIPLE
* rgb
= (const RGBTRIPLE
*)colorPtr
;
323 if (depth
== 1) /* Monochrome */
328 if (GetDIBColorTable( physDev
->hdc
, 0, 2, table
) == 2)
329 invert
= !colour_is_brighter(table
[1], table
[0]);
331 for (i
= start
; i
< end
; i
++, rgb
++)
332 colorMapping
[i
] = ((rgb
->rgbtRed
+ rgb
->rgbtGreen
+
333 rgb
->rgbtBlue
> 255*3/2 && !invert
) ||
334 (rgb
->rgbtRed
+ rgb
->rgbtGreen
+
335 rgb
->rgbtBlue
<= 255*3/2 && invert
));
338 for (i
= start
; i
< end
; i
++, rgb
++)
339 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( NULL
, RGB(rgb
->rgbtRed
,
344 else /* DIB_PAL_COLORS */
347 const WORD
* index
= (const WORD
*)colorPtr
;
349 for (i
= start
; i
< end
; i
++, index
++)
350 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(*index
) );
352 for (i
= start
; i
< end
; i
++)
353 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(i
) );
360 /***********************************************************************
361 * X11DRV_DIB_BuildColorMap
363 * Build the color map from the bitmap palette. Should not be called
364 * for a >8-bit deep bitmap.
366 static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
367 const BITMAPINFO
*info
, int *nColors
)
371 const void *colorPtr
;
374 isInfo
= info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
);
378 colors
= info
->bmiHeader
.biClrUsed
;
379 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
383 colors
= 1 << ((const BITMAPCOREHEADER
*)info
)->bcBitCount
;
386 colorPtr
= (const BYTE
*) info
+ (WORD
) info
->bmiHeader
.biSize
;
390 ERR("called with >256 colors!\n");
394 /* just so CopyDIBSection doesn't have to create an identity palette */
395 if (coloruse
== (WORD
)-1) colorPtr
= NULL
;
397 if (!(colorMapping
= HeapAlloc(GetProcessHeap(), 0, colors
* sizeof(int) )))
401 return X11DRV_DIB_GenColorMap( physDev
, colorMapping
, coloruse
, depth
,
402 isInfo
, colorPtr
, 0, colors
);
405 /***********************************************************************
406 * X11DRV_DIB_MapColor
408 static int X11DRV_DIB_MapColor( int *physMap
, int nPhysMap
, int phys
, int oldcol
)
412 if ((oldcol
< nPhysMap
) && (physMap
[oldcol
] == phys
))
415 for (color
= 0; color
< nPhysMap
; color
++)
416 if (physMap
[color
] == phys
)
419 WARN("Strange color %08x\n", phys
);
424 /*********************************************************************
425 * X11DRV_DIB_GetNearestIndex
427 * Helper for X11DRV_DIB_GetDIBits.
428 * Returns the nearest colour table index for a given RGB.
429 * Nearest is defined by minimizing the sum of the squares.
431 static INT
X11DRV_DIB_GetNearestIndex(RGBQUAD
*colormap
, int numColors
, BYTE r
, BYTE g
, BYTE b
)
433 INT i
, best
= -1, diff
, bestdiff
= -1;
436 for(color
= colormap
, i
= 0; i
< numColors
; color
++, i
++) {
437 diff
= (r
- color
->rgbRed
) * (r
- color
->rgbRed
) +
438 (g
- color
->rgbGreen
) * (g
- color
->rgbGreen
) +
439 (b
- color
->rgbBlue
) * (b
- color
->rgbBlue
);
442 if(best
== -1 || diff
< bestdiff
) {
449 /*********************************************************************
450 * X11DRV_DIB_MaskToShift
452 * Helper for X11DRV_DIB_GetDIBits.
453 * Returns the by how many bits to shift a given color so that it is
454 * in the proper position.
456 INT
X11DRV_DIB_MaskToShift(DWORD mask
)
464 while ((mask
&1)==0) {
471 /***********************************************************************
472 * X11DRV_DIB_CheckMask
474 * Check RGB mask if it is either 0 or matches visual's mask.
476 static inline int X11DRV_DIB_CheckMask(int red_mask
, int green_mask
, int blue_mask
)
478 return ( red_mask
== 0 && green_mask
== 0 && blue_mask
== 0 ) ||
479 ( red_mask
== visual
->red_mask
&& green_mask
== visual
->green_mask
&&
480 blue_mask
== visual
->blue_mask
);
483 /***********************************************************************
484 * X11DRV_DIB_SetImageBits_1
486 * SetDIBits for a 1-bit deep DIB.
488 static void X11DRV_DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
489 DWORD srcwidth
, DWORD dstwidth
, int left
,
490 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
499 srcbits
= srcbits
+ linebytes
* (lines
- 1);
500 linebytes
= -linebytes
;
503 if ((extra
= (left
& 7)) != 0) {
507 srcbits
+= left
>> 3;
508 width
= min(srcwidth
, dstwidth
);
510 /* ==== pal 1 dib -> any bmp format ==== */
511 for (h
= lines
-1; h
>=0; h
--) {
513 /* FIXME: should avoid putting x<left pixels (minor speed issue) */
514 for (i
= width
/8, x
= left
; i
> 0; i
--) {
516 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
517 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
518 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
519 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
520 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
521 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
522 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
523 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
529 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
530 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
531 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
532 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
533 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
534 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
535 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
538 srcbits
+= linebytes
;
542 /***********************************************************************
543 * X11DRV_DIB_GetImageBits_1
545 * GetDIBits for a 1-bit deep DIB.
547 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
548 DWORD dstwidth
, DWORD srcwidth
,
549 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
550 XImage
*bmpImage
, DWORD linebytes
)
553 int h
, width
= min(dstwidth
, srcwidth
);
557 dstbits
= dstbits
+ linebytes
* (lines
- 1);
558 linebytes
= -linebytes
;
561 switch (bmpImage
->depth
)
565 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
567 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
570 for (h
=lines
-1; h
>=0; h
--) {
574 for (x
=0; x
<width
; x
++) {
576 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
577 dstval
|=(X11DRV_DIB_GetNearestIndex
581 srcval
.peBlue
) << (7 - (x
& 7)));
590 dstbits
+= linebytes
;
598 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
, bmpImage
->green_mask
, bmpImage
->blue_mask
)
600 /* ==== pal 8 bmp -> pal 1 dib ==== */
602 const BYTE
* srcpixel
;
605 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
607 for (h
=0; h
<lines
; h
++) {
612 for (x
=0; x
<width
; x
++) {
614 srcval
=srccolors
[(int)*srcpixel
++];
615 dstval
|=(X11DRV_DIB_GetNearestIndex
619 srcval
.peBlue
) << (7-(x
&7)) );
628 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
629 dstbits
+= linebytes
;
640 const WORD
* srcpixel
;
643 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
645 if (bmpImage
->green_mask
==0x03e0) {
646 if (bmpImage
->red_mask
==0x7c00) {
647 /* ==== rgb 555 bmp -> pal 1 dib ==== */
648 for (h
=0; h
<lines
; h
++) {
653 for (x
=0; x
<width
; x
++) {
656 dstval
|=(X11DRV_DIB_GetNearestIndex
658 ((srcval
>> 7) & 0xf8) | /* r */
659 ((srcval
>> 12) & 0x07),
660 ((srcval
>> 2) & 0xf8) | /* g */
661 ((srcval
>> 7) & 0x07),
662 ((srcval
<< 3) & 0xf8) | /* b */
663 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
672 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
673 dstbits
+= linebytes
;
675 } else if (bmpImage
->blue_mask
==0x7c00) {
676 /* ==== bgr 555 bmp -> pal 1 dib ==== */
677 for (h
=0; h
<lines
; h
++) {
682 for (x
=0; x
<width
; x
++) {
685 dstval
|=(X11DRV_DIB_GetNearestIndex
687 ((srcval
<< 3) & 0xf8) | /* r */
688 ((srcval
>> 2) & 0x07),
689 ((srcval
>> 2) & 0xf8) | /* g */
690 ((srcval
>> 7) & 0x07),
691 ((srcval
>> 7) & 0xf8) | /* b */
692 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
701 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
702 dstbits
+= linebytes
;
707 } else if (bmpImage
->green_mask
==0x07e0) {
708 if (bmpImage
->red_mask
==0xf800) {
709 /* ==== rgb 565 bmp -> pal 1 dib ==== */
710 for (h
=0; h
<lines
; h
++) {
715 for (x
=0; x
<width
; x
++) {
718 dstval
|=(X11DRV_DIB_GetNearestIndex
720 ((srcval
>> 8) & 0xf8) | /* r */
721 ((srcval
>> 13) & 0x07),
722 ((srcval
>> 3) & 0xfc) | /* g */
723 ((srcval
>> 9) & 0x03),
724 ((srcval
<< 3) & 0xf8) | /* b */
725 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
734 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
735 dstbits
+= linebytes
;
737 } else if (bmpImage
->blue_mask
==0xf800) {
738 /* ==== bgr 565 bmp -> pal 1 dib ==== */
739 for (h
=0; h
<lines
; h
++) {
744 for (x
=0; x
<width
; x
++) {
747 dstval
|=(X11DRV_DIB_GetNearestIndex
749 ((srcval
<< 3) & 0xf8) | /* r */
750 ((srcval
>> 2) & 0x07),
751 ((srcval
>> 3) & 0xfc) | /* g */
752 ((srcval
>> 9) & 0x03),
753 ((srcval
>> 8) & 0xf8) | /* b */
754 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
763 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
764 dstbits
+= linebytes
;
783 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
784 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
786 if (bmpImage
->green_mask
!=0x00ff00 ||
787 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
789 } else if (bmpImage
->blue_mask
==0xff) {
790 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
791 for (h
=0; h
<lines
; h
++) {
796 for (x
=0; x
<width
; x
++) {
797 dstval
|=(X11DRV_DIB_GetNearestIndex
801 srcbyte
[0]) << (7-(x
&7)) );
802 srcbyte
+=bytes_per_pixel
;
811 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
812 dstbits
+= linebytes
;
815 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
816 for (h
=0; h
<lines
; h
++) {
821 for (x
=0; x
<width
; x
++) {
822 dstval
|=(X11DRV_DIB_GetNearestIndex
826 srcbyte
[2]) << (7-(x
&7)) );
827 srcbyte
+=bytes_per_pixel
;
836 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
837 dstbits
+= linebytes
;
848 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
850 /* ==== any bmp format -> pal 1 dib ==== */
851 if ((unsigned)colors
[0].rgbRed
+colors
[0].rgbGreen
+colors
[0].rgbBlue
>=
852 (unsigned)colors
[1].rgbRed
+colors
[1].rgbGreen
+colors
[1].rgbBlue
)
855 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
856 "%s color mapping\n",
857 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
858 bmpImage
->green_mask
, bmpImage
->blue_mask
,
859 neg
?"negative":"direct" );
861 for (h
=lines
-1; h
>=0; h
--) {
865 for (x
=0; x
<width
; x
++) {
866 dstval
|=((XGetPixel( bmpImage
, x
, h
) >= white
) ^ neg
) << (7 - (x
&7));
875 dstbits
+= linebytes
;
882 /***********************************************************************
883 * X11DRV_DIB_SetImageBits_4
885 * SetDIBits for a 4-bit deep DIB.
887 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
888 DWORD srcwidth
, DWORD dstwidth
, int left
,
889 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
897 srcbits
= srcbits
+ linebytes
* (lines
- 1);
898 linebytes
= -linebytes
;
905 srcbits
+= left
>> 1;
906 width
= min(srcwidth
, dstwidth
);
908 /* ==== pal 4 dib -> any bmp format ==== */
909 for (h
= lines
-1; h
>= 0; h
--) {
911 for (i
= width
/2, x
= left
; i
> 0; i
--) {
912 BYTE srcval
=*srcbyte
++;
913 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
914 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
917 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
918 srcbits
+= linebytes
;
924 /***********************************************************************
925 * X11DRV_DIB_GetImageBits_4
927 * GetDIBits for a 4-bit deep DIB.
929 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
930 DWORD srcwidth
, DWORD dstwidth
,
931 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
932 XImage
*bmpImage
, DWORD linebytes
)
935 int h
, width
= min(srcwidth
, dstwidth
);
941 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
942 linebytes
= -linebytes
;
947 switch (bmpImage
->depth
) {
950 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
952 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
955 for (h
= lines
-1; h
>= 0; h
--) {
959 for (x
= 0; x
< width
; x
++) {
961 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
962 dstval
|=(X11DRV_DIB_GetNearestIndex
966 srcval
.peBlue
) << (4-((x
&1)<<2)));
975 dstbits
+= linebytes
;
983 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
985 /* ==== pal 8 bmp -> pal 4 dib ==== */
987 const BYTE
*srcpixel
;
990 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
991 for (h
=0; h
<lines
; h
++) {
996 for (x
=0; x
<width
; x
++) {
998 srcval
= srccolors
[(int)*srcpixel
++];
999 dstval
|=(X11DRV_DIB_GetNearestIndex
1003 srcval
.peBlue
) << (4*(1-(x
&1))) );
1012 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1013 dstbits
+= linebytes
;
1023 const void* srcbits
;
1024 const WORD
* srcpixel
;
1027 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1029 if (bmpImage
->green_mask
==0x03e0) {
1030 if (bmpImage
->red_mask
==0x7c00) {
1031 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1032 for (h
=0; h
<lines
; h
++) {
1037 for (x
=0; x
<width
; x
++) {
1040 dstval
|=(X11DRV_DIB_GetNearestIndex
1042 ((srcval
>> 7) & 0xf8) | /* r */
1043 ((srcval
>> 12) & 0x07),
1044 ((srcval
>> 2) & 0xf8) | /* g */
1045 ((srcval
>> 7) & 0x07),
1046 ((srcval
<< 3) & 0xf8) | /* b */
1047 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1056 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1057 dstbits
+= linebytes
;
1059 } else if (bmpImage
->blue_mask
==0x7c00) {
1060 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1061 for (h
=0; h
<lines
; h
++) {
1066 for (x
=0; x
<width
; x
++) {
1069 dstval
|=(X11DRV_DIB_GetNearestIndex
1071 ((srcval
<< 3) & 0xf8) | /* r */
1072 ((srcval
>> 2) & 0x07),
1073 ((srcval
>> 2) & 0xf8) | /* g */
1074 ((srcval
>> 7) & 0x07),
1075 ((srcval
>> 7) & 0xf8) | /* b */
1076 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1085 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1086 dstbits
+= linebytes
;
1091 } else if (bmpImage
->green_mask
==0x07e0) {
1092 if (bmpImage
->red_mask
==0xf800) {
1093 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1094 for (h
=0; h
<lines
; h
++) {
1099 for (x
=0; x
<width
; x
++) {
1102 dstval
|=(X11DRV_DIB_GetNearestIndex
1104 ((srcval
>> 8) & 0xf8) | /* r */
1105 ((srcval
>> 13) & 0x07),
1106 ((srcval
>> 3) & 0xfc) | /* g */
1107 ((srcval
>> 9) & 0x03),
1108 ((srcval
<< 3) & 0xf8) | /* b */
1109 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1118 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1119 dstbits
+= linebytes
;
1121 } else if (bmpImage
->blue_mask
==0xf800) {
1122 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1123 for (h
=0; h
<lines
; h
++) {
1128 for (x
=0; x
<width
; x
++) {
1131 dstval
|=(X11DRV_DIB_GetNearestIndex
1133 ((srcval
<< 3) & 0xf8) | /* r */
1134 ((srcval
>> 2) & 0x07),
1135 ((srcval
>> 3) & 0xfc) | /* g */
1136 ((srcval
>> 9) & 0x03),
1137 ((srcval
>> 8) & 0xf8) | /* b */
1138 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1147 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1148 dstbits
+= linebytes
;
1160 if (bmpImage
->bits_per_pixel
==24) {
1161 const void* srcbits
;
1162 const BYTE
*srcbyte
;
1165 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1167 if (bmpImage
->green_mask
!=0x00ff00 ||
1168 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1170 } else if (bmpImage
->blue_mask
==0xff) {
1171 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1172 for (h
=0; h
<lines
; h
++) {
1175 for (x
=0; x
<width
/2; x
++) {
1176 /* Do 2 pixels at a time */
1177 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1182 X11DRV_DIB_GetNearestIndex
1190 /* And the the odd pixel */
1191 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1197 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1198 dstbits
+= linebytes
;
1201 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1202 for (h
=0; h
<lines
; h
++) {
1205 for (x
=0; x
<width
/2; x
++) {
1206 /* Do 2 pixels at a time */
1207 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1212 X11DRV_DIB_GetNearestIndex
1220 /* And the the odd pixel */
1221 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1227 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1228 dstbits
+= linebytes
;
1237 const void* srcbits
;
1238 const BYTE
*srcbyte
;
1241 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1243 if (bmpImage
->green_mask
!=0x00ff00 ||
1244 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1246 } else if (bmpImage
->blue_mask
==0xff) {
1247 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1248 for (h
=0; h
<lines
; h
++) {
1251 for (x
=0; x
<width
/2; x
++) {
1252 /* Do 2 pixels at a time */
1253 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1258 X11DRV_DIB_GetNearestIndex
1266 /* And the the odd pixel */
1267 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1273 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1274 dstbits
+= linebytes
;
1277 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1278 for (h
=0; h
<lines
; h
++) {
1281 for (x
=0; x
<width
/2; x
++) {
1282 /* Do 2 pixels at a time */
1283 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1288 X11DRV_DIB_GetNearestIndex
1296 /* And the the odd pixel */
1297 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1303 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1304 dstbits
+= linebytes
;
1315 /* ==== any bmp format -> pal 4 dib ==== */
1316 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1317 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1318 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1319 for (h
=lines
-1; h
>=0; h
--) {
1321 for (x
=0; x
<(width
& ~1); x
+=2) {
1322 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1323 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1326 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1328 dstbits
+= linebytes
;
1335 /***********************************************************************
1336 * X11DRV_DIB_SetImageBits_RLE4
1338 * SetDIBits for a 4-bit deep compressed DIB.
1340 static void X11DRV_DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
,
1341 DWORD srcwidth
, DWORD dstwidth
,
1342 int left
, int *colors
,
1345 unsigned int x
= 0, width
= min(srcwidth
, dstwidth
);
1346 int y
= lines
- 1, c
, length
;
1347 const BYTE
*begin
= bits
;
1352 if (length
) { /* encoded */
1355 if (x
>= (left
+ width
)) break;
1356 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1358 if (!length
--) break;
1359 if (x
>= (left
+ width
)) break;
1360 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1380 default: /* absolute */
1383 if (x
>= left
&& x
< (left
+ width
))
1384 XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1386 if (!length
--) break;
1387 if (x
>= left
&& x
< (left
+ width
))
1388 XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1391 if ((bits
- begin
) & 1)
1400 /***********************************************************************
1401 * X11DRV_DIB_SetImageBits_8
1403 * SetDIBits for an 8-bit deep DIB.
1405 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1406 DWORD srcwidth
, DWORD dstwidth
, int left
,
1407 const int *colors
, XImage
*bmpImage
,
1411 int h
, width
= min(srcwidth
, dstwidth
);
1412 const BYTE
* srcbyte
;
1418 srcbits
= srcbits
+ linebytes
* (lines
-1);
1419 linebytes
= -linebytes
;
1424 switch (bmpImage
->depth
) {
1427 #if defined(__i386__) && defined(__GNUC__)
1428 /* Some X servers might have 32 bit/ 16bit deep pixel */
1429 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1430 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1432 dstbits
=(BYTE
*)bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1433 /* FIXME: Does this really handle all these cases correctly? */
1434 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1435 for (h
= lines
; h
--; ) {
1436 int _cl1
,_cl2
; /* temp outputs for asm below */
1437 /* Borrowed from DirectDraw */
1438 __asm__
__volatile__(
1443 " movw (%%edx,%%eax,4),%%ax\n"
1445 " xor %%eax,%%eax\n"
1447 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1452 :"eax", "cc", "memory"
1454 srcbyte
= (srcbits
+= linebytes
);
1455 dstbits
-= bmpImage
->bytes_per_line
;
1463 #if defined(__i386__) && defined(__GNUC__)
1464 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1465 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1467 dstbits
=(BYTE
*)bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1468 /* FIXME: Does this really handle both cases correctly? */
1469 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1470 for (h
= lines
; h
--; ) {
1471 int _cl1
,_cl2
; /* temp outputs for asm below */
1472 /* Borrowed from DirectDraw */
1473 __asm__
__volatile__(
1478 " movl (%%edx,%%eax,4),%%eax\n"
1480 " xor %%eax,%%eax\n"
1482 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1487 :"eax", "cc", "memory"
1489 srcbyte
= (srcbits
+= linebytes
);
1490 dstbits
-= bmpImage
->bytes_per_line
;
1497 break; /* use slow generic case below */
1500 /* ==== pal 8 dib -> any bmp format ==== */
1501 for (h
=lines
-1; h
>=0; h
--) {
1502 for (x
=left
; x
<width
+left
; x
++) {
1503 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1505 srcbyte
= (srcbits
+= linebytes
);
1509 /***********************************************************************
1510 * X11DRV_DIB_GetImageBits_8
1512 * GetDIBits for an 8-bit deep DIB.
1514 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1515 DWORD srcwidth
, DWORD dstwidth
,
1516 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1517 XImage
*bmpImage
, DWORD linebytes
)
1520 int h
, width
= min(srcwidth
, dstwidth
);
1526 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1527 linebytes
= -linebytes
;
1532 * This condition is true when GetImageBits has been called by
1533 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1534 * 256 colormaps, so we'll just use it for GetDIBits calls.
1535 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1537 if (!srccolors
) goto updatesection
;
1539 switch (bmpImage
->depth
) {
1542 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1545 /* ==== pal 1 bmp -> pal 8 dib ==== */
1546 /* ==== pal 4 bmp -> pal 8 dib ==== */
1547 for (h
=lines
-1; h
>=0; h
--) {
1549 for (x
=0; x
<width
; x
++) {
1550 PALETTEENTRY srcval
;
1551 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1552 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1557 dstbits
+= linebytes
;
1565 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1567 /* ==== pal 8 bmp -> pal 8 dib ==== */
1568 const void* srcbits
;
1569 const BYTE
* srcpixel
;
1571 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1572 for (h
=0; h
<lines
; h
++) {
1575 for (x
= 0; x
< width
; x
++) {
1576 PALETTEENTRY srcval
;
1577 srcval
=srccolors
[(int)*srcpixel
++];
1578 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1583 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1584 dstbits
+= linebytes
;
1594 const void* srcbits
;
1595 const WORD
* srcpixel
;
1598 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1600 if (bmpImage
->green_mask
==0x03e0) {
1601 if (bmpImage
->red_mask
==0x7c00) {
1602 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1603 for (h
=0; h
<lines
; h
++) {
1606 for (x
=0; x
<width
; x
++) {
1609 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1611 ((srcval
>> 7) & 0xf8) | /* r */
1612 ((srcval
>> 12) & 0x07),
1613 ((srcval
>> 2) & 0xf8) | /* g */
1614 ((srcval
>> 7) & 0x07),
1615 ((srcval
<< 3) & 0xf8) | /* b */
1616 ((srcval
>> 2) & 0x07) );
1618 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1619 dstbits
+= linebytes
;
1621 } else if (bmpImage
->blue_mask
==0x7c00) {
1622 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1623 for (h
=0; h
<lines
; h
++) {
1626 for (x
=0; x
<width
; x
++) {
1629 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1631 ((srcval
<< 3) & 0xf8) | /* r */
1632 ((srcval
>> 2) & 0x07),
1633 ((srcval
>> 2) & 0xf8) | /* g */
1634 ((srcval
>> 7) & 0x07),
1635 ((srcval
>> 7) & 0xf8) | /* b */
1636 ((srcval
>> 12) & 0x07) );
1638 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1639 dstbits
+= linebytes
;
1644 } else if (bmpImage
->green_mask
==0x07e0) {
1645 if (bmpImage
->red_mask
==0xf800) {
1646 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1647 for (h
=0; h
<lines
; h
++) {
1650 for (x
=0; x
<width
; x
++) {
1653 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1655 ((srcval
>> 8) & 0xf8) | /* r */
1656 ((srcval
>> 13) & 0x07),
1657 ((srcval
>> 3) & 0xfc) | /* g */
1658 ((srcval
>> 9) & 0x03),
1659 ((srcval
<< 3) & 0xf8) | /* b */
1660 ((srcval
>> 2) & 0x07) );
1662 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1663 dstbits
+= linebytes
;
1665 } else if (bmpImage
->blue_mask
==0xf800) {
1666 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1667 for (h
=0; h
<lines
; h
++) {
1670 for (x
=0; x
<width
; x
++) {
1673 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1675 ((srcval
<< 3) & 0xf8) | /* r */
1676 ((srcval
>> 2) & 0x07),
1677 ((srcval
>> 3) & 0xfc) | /* g */
1678 ((srcval
>> 9) & 0x03),
1679 ((srcval
>> 8) & 0xf8) | /* b */
1680 ((srcval
>> 13) & 0x07) );
1682 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1683 dstbits
+= linebytes
;
1697 const void* srcbits
;
1698 const BYTE
*srcbyte
;
1700 int bytes_per_pixel
;
1702 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1703 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1705 if (bmpImage
->green_mask
!=0x00ff00 ||
1706 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1708 } else if (bmpImage
->blue_mask
==0xff) {
1709 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1710 for (h
=0; h
<lines
; h
++) {
1713 for (x
=0; x
<width
; x
++) {
1714 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1719 srcbyte
+=bytes_per_pixel
;
1721 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1722 dstbits
+= linebytes
;
1725 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1726 for (h
=0; h
<lines
; h
++) {
1729 for (x
=0; x
<width
; x
++) {
1730 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1735 srcbyte
+=bytes_per_pixel
;
1737 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1738 dstbits
+= linebytes
;
1746 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1747 bmpImage
->depth
, bmpImage
->red_mask
,
1748 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1750 /* ==== any bmp format -> pal 8 dib ==== */
1751 for (h
=lines
-1; h
>=0; h
--) {
1753 for (x
=0; x
<width
; x
++) {
1754 *dstbyte
=X11DRV_DIB_MapColor
1756 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1759 dstbits
+= linebytes
;
1765 /***********************************************************************
1766 * X11DRV_DIB_SetImageBits_RLE8
1768 * SetDIBits for an 8-bit deep compressed DIB.
1770 * This function rewritten 941113 by James Youngman. WINE blew out when I
1771 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1773 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1774 * 'End of bitmap' escape code. This code is very much laxer in what it
1775 * allows to end the expansion. Possibly too lax. See the note by
1776 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1777 * bitmap should end with RleEnd, but on the other hand, software exists
1778 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1781 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1782 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1785 static void X11DRV_DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
,
1786 DWORD srcwidth
, DWORD dstwidth
,
1787 int left
, int *colors
,
1790 unsigned int x
; /* X-position on each line. Increases. */
1791 int y
; /* Line #. Starts at lines-1, decreases */
1792 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
1793 BYTE length
; /* The length pf a run */
1794 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
1797 * Note that the bitmap data is stored by Windows starting at the
1798 * bottom line of the bitmap and going upwards. Within each line,
1799 * the data is stored left-to-right. That's the reason why line
1800 * goes from lines-1 to 0. [JAY]
1810 * If the length byte is not zero (which is the escape value),
1811 * We have a run of length pixels all the same colour. The colour
1812 * index is stored next.
1814 * If the length byte is zero, we need to read the next byte to
1815 * know what to do. [JAY]
1820 * [Run-Length] Encoded mode
1822 int color
= colors
[*pIn
++];
1823 while (length
-- && x
< (left
+ dstwidth
)) {
1824 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1831 * Escape codes (may be an absolute sequence though)
1833 escape_code
= (*pIn
++);
1842 /* Not all RLE8 bitmaps end with this code. For
1843 * example, Paint Shop Pro produces some that don't.
1844 * That's (I think) what caused the previous
1845 * implementation to fail. [JAY]
1854 default: /* switch to absolute mode */
1855 length
= escape_code
;
1858 int color
= colors
[*pIn
++];
1859 if (x
>= (left
+ dstwidth
))
1864 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1868 * If you think for a moment you'll realise that the
1869 * only time we could ever possibly read an odd
1870 * number of bytes is when there is a 0x00 (escape),
1871 * a value >0x02 (absolute mode) and then an odd-
1872 * length run. Therefore this is the only place we
1873 * need to worry about it. Everywhere else the
1874 * bytes are always read in pairs. [JAY]
1876 if (escape_code
& 1) pIn
++; /* Throw away the pad byte. */
1878 } /* switch (escape_code) : Escape sequence */
1884 /***********************************************************************
1885 * X11DRV_DIB_SetImageBits_16
1887 * SetDIBits for a 16-bit deep DIB.
1889 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1890 DWORD srcwidth
, DWORD dstwidth
, int left
,
1891 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1892 XImage
*bmpImage
, DWORD linebytes
)
1895 int h
, width
= min(srcwidth
, dstwidth
);
1896 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1901 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1902 linebytes
= -linebytes
;
1905 switch (bmpImage
->depth
)
1912 srcbits
=srcbits
+left
*2;
1913 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1915 if (bmpImage
->green_mask
==0x03e0) {
1916 if (gSrc
==bmpImage
->green_mask
) {
1917 if (rSrc
==bmpImage
->red_mask
) {
1918 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1919 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1920 convs
->Convert_5x5_asis
1923 dstbits
,-bmpImage
->bytes_per_line
);
1924 } else if (rSrc
==bmpImage
->blue_mask
) {
1925 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1926 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1927 convs
->Convert_555_reverse
1930 dstbits
,-bmpImage
->bytes_per_line
);
1933 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1934 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1935 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1936 convs
->Convert_565_to_555_asis
1939 dstbits
,-bmpImage
->bytes_per_line
);
1941 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1942 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1943 convs
->Convert_565_to_555_reverse
1946 dstbits
,-bmpImage
->bytes_per_line
);
1949 } else if (bmpImage
->green_mask
==0x07e0) {
1950 if (gSrc
==bmpImage
->green_mask
) {
1951 if (rSrc
==bmpImage
->red_mask
) {
1952 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
1953 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
1954 convs
->Convert_5x5_asis
1957 dstbits
,-bmpImage
->bytes_per_line
);
1959 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
1960 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
1961 convs
->Convert_565_reverse
1964 dstbits
,-bmpImage
->bytes_per_line
);
1967 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1968 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
1969 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
1970 convs
->Convert_555_to_565_asis
1973 dstbits
,-bmpImage
->bytes_per_line
);
1975 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
1976 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
1977 convs
->Convert_555_to_565_reverse
1980 dstbits
,-bmpImage
->bytes_per_line
);
1990 if (bmpImage
->bits_per_pixel
==24) {
1993 srcbits
=srcbits
+left
*2;
1994 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
1996 if (bmpImage
->green_mask
!=0x00ff00 ||
1997 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1999 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2000 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2002 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2003 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2004 convs
->Convert_555_to_888_asis
2007 dstbits
,-bmpImage
->bytes_per_line
);
2009 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2010 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2011 convs
->Convert_565_to_888_asis
2014 dstbits
,-bmpImage
->bytes_per_line
);
2018 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2019 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2020 convs
->Convert_555_to_888_reverse
2023 dstbits
,-bmpImage
->bytes_per_line
);
2025 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2026 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2027 convs
->Convert_565_to_888_reverse
2030 dstbits
,-bmpImage
->bytes_per_line
);
2041 srcbits
=srcbits
+left
*2;
2042 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2044 if (bmpImage
->green_mask
!=0x00ff00 ||
2045 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2047 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2048 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2050 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2051 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2052 convs
->Convert_555_to_0888_asis
2055 dstbits
,-bmpImage
->bytes_per_line
);
2057 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2058 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2059 convs
->Convert_565_to_0888_asis
2062 dstbits
,-bmpImage
->bytes_per_line
);
2066 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2067 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2068 convs
->Convert_555_to_0888_reverse
2071 dstbits
,-bmpImage
->bytes_per_line
);
2073 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2074 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2075 convs
->Convert_565_to_0888_reverse
2078 dstbits
,-bmpImage
->bytes_per_line
);
2086 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2087 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2088 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2094 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2095 const WORD
* srcpixel
;
2096 int rShift1
,gShift1
,bShift1
;
2097 int rShift2
,gShift2
,bShift2
;
2100 /* Set color scaling values */
2101 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
2102 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
2103 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
2108 /* Green has 5 bits, like the others */
2112 /* Green has 6 bits, not 5. Compensate. */
2121 /* We could split it into four separate cases to optimize
2122 * but it is probably not worth it.
2124 for (h
=lines
-1; h
>=0; h
--) {
2125 srcpixel
=(const WORD
*)srcbits
;
2126 for (x
=left
; x
<width
+left
; x
++) {
2128 BYTE red
,green
,blue
;
2129 srcval
=*srcpixel
++ << 16;
2130 red
= ((srcval
>> rShift1
) & 0xf8) |
2131 ((srcval
>> rShift2
) & 0x07);
2132 green
=((srcval
>> gShift1
) & gMask1
) |
2133 ((srcval
>> gShift2
) & gMask2
);
2134 blue
= ((srcval
>> bShift1
) & 0xf8) |
2135 ((srcval
>> bShift2
) & 0x07);
2136 XPutPixel(bmpImage
, x
, h
,
2137 X11DRV_PALETTE_ToPhysical
2138 (physDev
, RGB(red
,green
,blue
)));
2140 srcbits
+= linebytes
;
2148 /***********************************************************************
2149 * X11DRV_DIB_GetImageBits_16
2151 * GetDIBits for an 16-bit deep DIB.
2153 static void X11DRV_DIB_GetImageBits_16( int lines
, BYTE
*dstbits
,
2154 DWORD dstwidth
, DWORD srcwidth
,
2155 PALETTEENTRY
*srccolors
,
2156 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2157 XImage
*bmpImage
, DWORD dibpitch
)
2160 int h
, width
= min(srcwidth
, dstwidth
);
2161 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2163 DWORD linebytes
= dibpitch
;
2168 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
2169 linebytes
= -linebytes
;
2172 switch (bmpImage
->depth
)
2177 const char* srcbits
;
2179 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2181 if (bmpImage
->green_mask
==0x03e0) {
2182 if (gDst
==bmpImage
->green_mask
) {
2183 if (rDst
==bmpImage
->red_mask
) {
2184 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2185 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2186 convs
->Convert_5x5_asis
2188 srcbits
,-bmpImage
->bytes_per_line
,
2191 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2192 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2193 convs
->Convert_555_reverse
2195 srcbits
,-bmpImage
->bytes_per_line
,
2199 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2200 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2201 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2202 convs
->Convert_555_to_565_asis
2204 srcbits
,-bmpImage
->bytes_per_line
,
2207 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2208 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2209 convs
->Convert_555_to_565_reverse
2211 srcbits
,-bmpImage
->bytes_per_line
,
2215 } else if (bmpImage
->green_mask
==0x07e0) {
2216 if (gDst
==bmpImage
->green_mask
) {
2217 if (rDst
== bmpImage
->red_mask
) {
2218 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2219 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2220 convs
->Convert_5x5_asis
2222 srcbits
,-bmpImage
->bytes_per_line
,
2225 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2226 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2227 convs
->Convert_565_reverse
2229 srcbits
,-bmpImage
->bytes_per_line
,
2233 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2234 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2235 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2236 convs
->Convert_565_to_555_asis
2238 srcbits
,-bmpImage
->bytes_per_line
,
2241 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2242 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2243 convs
->Convert_565_to_555_reverse
2245 srcbits
,-bmpImage
->bytes_per_line
,
2256 if (bmpImage
->bits_per_pixel
== 24) {
2257 const char* srcbits
;
2259 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2261 if (bmpImage
->green_mask
!=0x00ff00 ||
2262 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2264 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2265 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2267 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2268 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2269 convs
->Convert_888_to_555_asis
2271 srcbits
,-bmpImage
->bytes_per_line
,
2274 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2275 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2276 convs
->Convert_888_to_565_asis
2278 srcbits
,-bmpImage
->bytes_per_line
,
2283 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2284 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2285 convs
->Convert_888_to_555_reverse
2287 srcbits
,-bmpImage
->bytes_per_line
,
2290 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2291 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2292 convs
->Convert_888_to_565_reverse
2294 srcbits
,-bmpImage
->bytes_per_line
,
2304 const char* srcbits
;
2306 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2308 if (bmpImage
->green_mask
!=0x00ff00 ||
2309 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2311 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2312 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2314 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2315 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2316 convs
->Convert_0888_to_555_asis
2318 srcbits
,-bmpImage
->bytes_per_line
,
2321 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2322 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2323 convs
->Convert_0888_to_565_asis
2325 srcbits
,-bmpImage
->bytes_per_line
,
2330 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2331 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2332 convs
->Convert_0888_to_555_reverse
2334 srcbits
,-bmpImage
->bytes_per_line
,
2337 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2338 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2339 convs
->Convert_0888_to_565_reverse
2341 srcbits
,-bmpImage
->bytes_per_line
,
2350 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2352 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2353 int rShift
,gShift
,bShift
;
2356 /* Shift everything 16 bits left so that all shifts are >0,
2357 * even for BGR DIBs. Then a single >> 16 will bring everything
2360 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2361 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2362 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2364 /* 6 bits for the green */
2370 for (h
= lines
- 1; h
>= 0; h
--) {
2371 dstpixel
=(LPWORD
)dstbits
;
2372 for (x
= 0; x
< width
; x
++) {
2373 PALETTEENTRY srcval
;
2375 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2376 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2377 ((srcval
.peGreen
<< gShift
) & gDst
) |
2378 ((srcval
.peBlue
<< bShift
) & bDst
);
2379 *dstpixel
++=dstval
>> 16;
2381 dstbits
+= linebytes
;
2389 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2391 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2392 int rShift
,gShift
,bShift
;
2393 const BYTE
* srcbits
;
2394 const BYTE
* srcpixel
;
2397 /* Shift everything 16 bits left so that all shifts are >0,
2398 * even for BGR DIBs. Then a single >> 16 will bring everything
2401 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2402 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2403 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2405 /* 6 bits for the green */
2411 srcbits
=(BYTE
*)bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2412 for (h
=0; h
<lines
; h
++) {
2414 dstpixel
=(LPWORD
)dstbits
;
2415 for (x
= 0; x
< width
; x
++) {
2416 PALETTEENTRY srcval
;
2418 srcval
=srccolors
[(int)*srcpixel
++];
2419 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2420 ((srcval
.peGreen
<< gShift
) & gDst
) |
2421 ((srcval
.peBlue
<< bShift
) & bDst
);
2422 *dstpixel
++=dstval
>> 16;
2424 srcbits
-= bmpImage
->bytes_per_line
;
2425 dstbits
+= linebytes
;
2435 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2436 int rShift
,gShift
,bShift
;
2439 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2440 bmpImage
->depth
, bmpImage
->red_mask
,
2441 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2444 /* Shift everything 16 bits left so that all shifts are >0,
2445 * even for BGR DIBs. Then a single >> 16 will bring everything
2448 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2449 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2450 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2452 /* 6 bits for the green */
2458 for (h
= lines
- 1; h
>= 0; h
--) {
2459 dstpixel
=(LPWORD
)dstbits
;
2460 for (x
= 0; x
< width
; x
++) {
2463 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
2464 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2465 ((GetGValue(srcval
) << gShift
) & gDst
) |
2466 ((GetBValue(srcval
) << bShift
) & bDst
);
2467 *dstpixel
++=dstval
>> 16;
2469 dstbits
+= linebytes
;
2477 /***********************************************************************
2478 * X11DRV_DIB_SetImageBits_24
2480 * SetDIBits for a 24-bit deep DIB.
2482 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2483 DWORD srcwidth
, DWORD dstwidth
, int left
,
2484 X11DRV_PDEVICE
*physDev
,
2485 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2486 XImage
*bmpImage
, DWORD linebytes
)
2489 int h
, width
= min(srcwidth
, dstwidth
);
2490 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2495 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2496 linebytes
= -linebytes
;
2499 switch (bmpImage
->depth
)
2502 if (bmpImage
->bits_per_pixel
==24) {
2505 srcbits
=srcbits
+left
*3;
2506 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2508 if (bmpImage
->green_mask
!=0x00ff00 ||
2509 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2511 } else if (rSrc
==bmpImage
->red_mask
) {
2512 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2513 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2514 convs
->Convert_888_asis
2517 dstbits
,-bmpImage
->bytes_per_line
);
2519 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2520 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2521 convs
->Convert_888_reverse
2524 dstbits
,-bmpImage
->bytes_per_line
);
2534 srcbits
=srcbits
+left
*3;
2535 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2537 if (bmpImage
->green_mask
!=0x00ff00 ||
2538 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2540 } else if (rSrc
==bmpImage
->red_mask
) {
2541 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2542 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2543 convs
->Convert_888_to_0888_asis
2546 dstbits
,-bmpImage
->bytes_per_line
);
2548 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2549 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2550 convs
->Convert_888_to_0888_reverse
2553 dstbits
,-bmpImage
->bytes_per_line
);
2563 srcbits
=srcbits
+left
*3;
2564 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2566 if (bmpImage
->green_mask
==0x03e0) {
2567 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2568 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2569 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2570 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2571 convs
->Convert_888_to_555_asis
2574 dstbits
,-bmpImage
->bytes_per_line
);
2575 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2576 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2577 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2578 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2579 convs
->Convert_888_to_555_reverse
2582 dstbits
,-bmpImage
->bytes_per_line
);
2586 } else if (bmpImage
->green_mask
==0x07e0) {
2587 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2588 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2589 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2590 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2591 convs
->Convert_888_to_565_asis
2594 dstbits
,-bmpImage
->bytes_per_line
);
2595 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2596 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2597 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2598 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2599 convs
->Convert_888_to_565_reverse
2602 dstbits
,-bmpImage
->bytes_per_line
);
2614 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2615 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2616 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2622 /* ==== rgb 888 dib -> any bmp bormat ==== */
2623 const BYTE
* srcbyte
;
2625 /* Windows only supports one 24bpp DIB format: RGB888 */
2627 for (h
= lines
- 1; h
>= 0; h
--) {
2628 srcbyte
=(const BYTE
*)srcbits
;
2629 for (x
= left
; x
< width
+left
; x
++) {
2630 XPutPixel(bmpImage
, x
, h
,
2631 X11DRV_PALETTE_ToPhysical
2632 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2635 srcbits
+= linebytes
;
2643 /***********************************************************************
2644 * X11DRV_DIB_GetImageBits_24
2646 * GetDIBits for an 24-bit deep DIB.
2648 static void X11DRV_DIB_GetImageBits_24( int lines
, BYTE
*dstbits
,
2649 DWORD dstwidth
, DWORD srcwidth
,
2650 PALETTEENTRY
*srccolors
,
2651 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2652 XImage
*bmpImage
, DWORD linebytes
)
2655 int h
, width
= min(srcwidth
, dstwidth
);
2656 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2661 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2662 linebytes
= -linebytes
;
2665 switch (bmpImage
->depth
)
2668 if (bmpImage
->bits_per_pixel
==24) {
2669 const char* srcbits
;
2671 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2673 if (bmpImage
->green_mask
!=0x00ff00 ||
2674 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2676 } else if (rDst
==bmpImage
->red_mask
) {
2677 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2678 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2679 convs
->Convert_888_asis
2681 srcbits
,-bmpImage
->bytes_per_line
,
2684 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2685 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2686 convs
->Convert_888_reverse
2688 srcbits
,-bmpImage
->bytes_per_line
,
2697 const char* srcbits
;
2699 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2701 if (bmpImage
->green_mask
!=0x00ff00 ||
2702 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2704 } else if (rDst
==bmpImage
->red_mask
) {
2705 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2706 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2707 convs
->Convert_0888_to_888_asis
2709 srcbits
,-bmpImage
->bytes_per_line
,
2712 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2713 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2714 convs
->Convert_0888_to_888_reverse
2716 srcbits
,-bmpImage
->bytes_per_line
,
2725 const char* srcbits
;
2727 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2729 if (bmpImage
->green_mask
==0x03e0) {
2730 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2731 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2732 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2733 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2734 convs
->Convert_555_to_888_asis
2736 srcbits
,-bmpImage
->bytes_per_line
,
2738 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2739 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2740 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2741 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2742 convs
->Convert_555_to_888_reverse
2744 srcbits
,-bmpImage
->bytes_per_line
,
2749 } else if (bmpImage
->green_mask
==0x07e0) {
2750 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2751 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2752 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2753 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2754 convs
->Convert_565_to_888_asis
2756 srcbits
,-bmpImage
->bytes_per_line
,
2758 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2759 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2760 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2761 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2762 convs
->Convert_565_to_888_reverse
2764 srcbits
,-bmpImage
->bytes_per_line
,
2777 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2779 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2782 /* Windows only supports one 24bpp DIB format: rgb 888 */
2783 for (h
= lines
- 1; h
>= 0; h
--) {
2785 for (x
= 0; x
< width
; x
++) {
2786 PALETTEENTRY srcval
;
2787 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2788 dstbyte
[0]=srcval
.peBlue
;
2789 dstbyte
[1]=srcval
.peGreen
;
2790 dstbyte
[2]=srcval
.peRed
;
2793 dstbits
+= linebytes
;
2801 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2803 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2804 const void* srcbits
;
2805 const BYTE
* srcpixel
;
2808 /* Windows only supports one 24bpp DIB format: rgb 888 */
2809 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2810 for (h
= lines
- 1; h
>= 0; h
--) {
2813 for (x
= 0; x
< width
; x
++ ) {
2814 PALETTEENTRY srcval
;
2815 srcval
=srccolors
[(int)*srcpixel
++];
2816 dstbyte
[0]=srcval
.peBlue
;
2817 dstbyte
[1]=srcval
.peGreen
;
2818 dstbyte
[2]=srcval
.peRed
;
2821 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2822 dstbits
+= linebytes
;
2832 /* ==== any bmp format -> 888 dib ==== */
2835 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2836 bmpImage
->depth
, bmpImage
->red_mask
,
2837 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2840 /* Windows only supports one 24bpp DIB format: rgb 888 */
2841 for (h
= lines
- 1; h
>= 0; h
--) {
2843 for (x
= 0; x
< width
; x
++) {
2844 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2845 (XGetPixel( bmpImage
, x
, h
));
2846 dstbyte
[0]=GetBValue(srcval
);
2847 dstbyte
[1]=GetGValue(srcval
);
2848 dstbyte
[2]=GetRValue(srcval
);
2851 dstbits
+= linebytes
;
2859 /***********************************************************************
2860 * X11DRV_DIB_SetImageBits_32
2862 * SetDIBits for a 32-bit deep DIB.
2864 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2865 DWORD srcwidth
, DWORD dstwidth
, int left
,
2866 X11DRV_PDEVICE
*physDev
,
2867 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2873 int h
, width
= min(srcwidth
, dstwidth
);
2874 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2879 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2880 linebytes
= -linebytes
;
2883 ptr
= (const DWORD
*) srcbits
+ left
;
2885 switch (bmpImage
->depth
)
2888 if (bmpImage
->bits_per_pixel
==24) {
2891 srcbits
=srcbits
+left
*4;
2892 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2894 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2895 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2896 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2897 convs
->Convert_0888_to_888_asis
2900 dstbits
,-bmpImage
->bytes_per_line
);
2901 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2902 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2904 /* the tests below assume sane bmpImage masks */
2905 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2906 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2907 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2908 convs
->Convert_0888_to_888_reverse
2911 dstbits
,-bmpImage
->bytes_per_line
);
2912 } else if (bmpImage
->blue_mask
==0xff) {
2913 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2914 convs
->Convert_any0888_to_rgb888
2918 dstbits
,-bmpImage
->bytes_per_line
);
2920 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2921 convs
->Convert_any0888_to_bgr888
2925 dstbits
,-bmpImage
->bytes_per_line
);
2935 srcbits
=srcbits
+left
*4;
2936 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2938 if (gSrc
==bmpImage
->green_mask
) {
2939 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2940 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2941 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2942 convs
->Convert_0888_asis
2945 dstbits
,-bmpImage
->bytes_per_line
);
2946 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2947 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2949 /* the tests below assume sane bmpImage masks */
2950 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
2951 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2952 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2953 convs
->Convert_0888_reverse
2956 dstbits
,-bmpImage
->bytes_per_line
);
2958 /* ==== any 0888 dib -> any 0888 bmp ==== */
2959 convs
->Convert_0888_any
2963 dstbits
,-bmpImage
->bytes_per_line
,
2964 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2966 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2967 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2969 /* the tests below assume sane bmpImage masks */
2971 /* ==== any 0888 dib -> any 0888 bmp ==== */
2972 convs
->Convert_0888_any
2976 dstbits
,-bmpImage
->bytes_per_line
,
2977 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2987 srcbits
=srcbits
+left
*4;
2988 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2990 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
2991 if (bmpImage
->green_mask
==0x03e0) {
2992 if (bmpImage
->red_mask
==0x7f00) {
2993 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
2994 convs
->Convert_0888_to_555_asis
2997 dstbits
,-bmpImage
->bytes_per_line
);
2998 } else if (bmpImage
->blue_mask
==0x7f00) {
2999 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
3000 convs
->Convert_0888_to_555_reverse
3003 dstbits
,-bmpImage
->bytes_per_line
);
3007 } else if (bmpImage
->green_mask
==0x07e0) {
3008 if (bmpImage
->red_mask
==0xf800) {
3009 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3010 convs
->Convert_0888_to_565_asis
3013 dstbits
,-bmpImage
->bytes_per_line
);
3014 } else if (bmpImage
->blue_mask
==0xf800) {
3015 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3016 convs
->Convert_0888_to_565_reverse
3019 dstbits
,-bmpImage
->bytes_per_line
);
3026 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
3027 if (bmpImage
->green_mask
==0x03e0) {
3028 if (bmpImage
->blue_mask
==0x7f00) {
3029 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3030 convs
->Convert_0888_to_555_asis
3033 dstbits
,-bmpImage
->bytes_per_line
);
3034 } else if (bmpImage
->red_mask
==0x7f00) {
3035 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3036 convs
->Convert_0888_to_555_reverse
3039 dstbits
,-bmpImage
->bytes_per_line
);
3043 } else if (bmpImage
->green_mask
==0x07e0) {
3044 if (bmpImage
->blue_mask
==0xf800) {
3045 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3046 convs
->Convert_0888_to_565_asis
3049 dstbits
,-bmpImage
->bytes_per_line
);
3050 } else if (bmpImage
->red_mask
==0xf800) {
3051 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3052 convs
->Convert_0888_to_565_reverse
3055 dstbits
,-bmpImage
->bytes_per_line
);
3063 if (bmpImage
->green_mask
==0x03e0 &&
3064 (bmpImage
->red_mask
==0x7f00 ||
3065 bmpImage
->blue_mask
==0x7f00)) {
3066 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3067 convs
->Convert_any0888_to_5x5
3071 dstbits
,-bmpImage
->bytes_per_line
,
3072 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3073 } else if (bmpImage
->green_mask
==0x07e0 &&
3074 (bmpImage
->red_mask
==0xf800 ||
3075 bmpImage
->blue_mask
==0xf800)) {
3076 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3077 convs
->Convert_any0888_to_5x5
3081 dstbits
,-bmpImage
->bytes_per_line
,
3082 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3092 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3093 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
3094 bmpImage
->green_mask
, bmpImage
->blue_mask
);
3100 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3101 const DWORD
* srcpixel
;
3102 int rShift
,gShift
,bShift
;
3104 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
3105 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
3106 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
3108 for (h
= lines
- 1; h
>= 0; h
--) {
3109 srcpixel
=(const DWORD
*)srcbits
;
3110 for (x
= left
; x
< width
+left
; x
++) {
3112 BYTE red
,green
,blue
;
3113 srcvalue
=*srcpixel
++;
3114 red
= (srcvalue
>> rShift
) & 0xff;
3115 green
=(srcvalue
>> gShift
) & 0xff;
3116 blue
= (srcvalue
>> bShift
) & 0xff;
3117 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
3118 (physDev
, RGB(red
,green
,blue
)));
3120 srcbits
+= linebytes
;
3128 /***********************************************************************
3129 * X11DRV_DIB_GetImageBits_32
3131 * GetDIBits for an 32-bit deep DIB.
3133 static void X11DRV_DIB_GetImageBits_32( int lines
, BYTE
*dstbits
,
3134 DWORD dstwidth
, DWORD srcwidth
,
3135 PALETTEENTRY
*srccolors
,
3136 DWORD rDst
, DWORD gDst
, DWORD bDst
,
3137 XImage
*bmpImage
, DWORD linebytes
)
3140 int h
, width
= min(srcwidth
, dstwidth
);
3142 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
3147 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
3148 linebytes
= -linebytes
;
3153 switch (bmpImage
->depth
)
3156 if (bmpImage
->bits_per_pixel
==24) {
3157 const void* srcbits
;
3159 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3161 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
3162 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3163 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3164 convs
->Convert_888_to_0888_asis
3166 srcbits
,-bmpImage
->bytes_per_line
,
3168 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3169 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3171 /* the tests below assume sane bmpImage masks */
3172 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
3173 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3174 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3175 convs
->Convert_888_to_0888_reverse
3177 srcbits
,-bmpImage
->bytes_per_line
,
3179 } else if (bmpImage
->blue_mask
==0xff) {
3180 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3181 convs
->Convert_rgb888_to_any0888
3183 srcbits
,-bmpImage
->bytes_per_line
,
3187 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3188 convs
->Convert_bgr888_to_any0888
3190 srcbits
,-bmpImage
->bytes_per_line
,
3200 const char* srcbits
;
3202 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3204 if (gDst
==bmpImage
->green_mask
) {
3205 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
3206 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3207 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3208 convs
->Convert_0888_asis
3210 srcbits
,-bmpImage
->bytes_per_line
,
3212 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3213 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3215 /* the tests below assume sane bmpImage masks */
3216 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
3217 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3218 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3219 convs
->Convert_0888_reverse
3221 srcbits
,-bmpImage
->bytes_per_line
,
3224 /* ==== any 0888 bmp -> any 0888 dib ==== */
3225 convs
->Convert_0888_any
3227 srcbits
,-bmpImage
->bytes_per_line
,
3228 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3232 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3233 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3235 /* the tests below assume sane bmpImage masks */
3237 /* ==== any 0888 bmp -> any 0888 dib ==== */
3238 convs
->Convert_0888_any
3240 srcbits
,-bmpImage
->bytes_per_line
,
3241 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3251 const char* srcbits
;
3253 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3255 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
3256 if (bmpImage
->green_mask
==0x03e0) {
3257 if (bmpImage
->red_mask
==0x7f00) {
3258 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3259 convs
->Convert_555_to_0888_asis
3261 srcbits
,-bmpImage
->bytes_per_line
,
3263 } else if (bmpImage
->blue_mask
==0x7f00) {
3264 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3265 convs
->Convert_555_to_0888_reverse
3267 srcbits
,-bmpImage
->bytes_per_line
,
3272 } else if (bmpImage
->green_mask
==0x07e0) {
3273 if (bmpImage
->red_mask
==0xf800) {
3274 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3275 convs
->Convert_565_to_0888_asis
3277 srcbits
,-bmpImage
->bytes_per_line
,
3279 } else if (bmpImage
->blue_mask
==0xf800) {
3280 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3281 convs
->Convert_565_to_0888_reverse
3283 srcbits
,-bmpImage
->bytes_per_line
,
3291 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
3292 if (bmpImage
->green_mask
==0x03e0) {
3293 if (bmpImage
->blue_mask
==0x7f00) {
3294 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3295 convs
->Convert_555_to_0888_asis
3297 srcbits
,-bmpImage
->bytes_per_line
,
3299 } else if (bmpImage
->red_mask
==0x7f00) {
3300 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3301 convs
->Convert_555_to_0888_reverse
3303 srcbits
,-bmpImage
->bytes_per_line
,
3308 } else if (bmpImage
->green_mask
==0x07e0) {
3309 if (bmpImage
->blue_mask
==0xf800) {
3310 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3311 convs
->Convert_565_to_0888_asis
3313 srcbits
,-bmpImage
->bytes_per_line
,
3315 } else if (bmpImage
->red_mask
==0xf800) {
3316 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3317 convs
->Convert_565_to_0888_reverse
3319 srcbits
,-bmpImage
->bytes_per_line
,
3328 if (bmpImage
->green_mask
==0x03e0 &&
3329 (bmpImage
->red_mask
==0x7f00 ||
3330 bmpImage
->blue_mask
==0x7f00)) {
3331 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3332 convs
->Convert_5x5_to_any0888
3334 srcbits
,-bmpImage
->bytes_per_line
,
3335 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3338 } else if (bmpImage
->green_mask
==0x07e0 &&
3339 (bmpImage
->red_mask
==0xf800 ||
3340 bmpImage
->blue_mask
==0xf800)) {
3341 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3342 convs
->Convert_5x5_to_any0888
3344 srcbits
,-bmpImage
->bytes_per_line
,
3345 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3357 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3359 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3360 int rShift
,gShift
,bShift
;
3363 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3364 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3365 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3366 for (h
= lines
- 1; h
>= 0; h
--) {
3367 dstpixel
=(DWORD
*)dstbits
;
3368 for (x
= 0; x
< width
; x
++) {
3369 PALETTEENTRY srcval
;
3370 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3371 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3372 (srcval
.peGreen
<< gShift
) |
3373 (srcval
.peBlue
<< bShift
);
3375 dstbits
+= linebytes
;
3383 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3385 /* ==== pal 8 bmp -> any 0888 dib ==== */
3386 int rShift
,gShift
,bShift
;
3387 const void* srcbits
;
3388 const BYTE
* srcpixel
;
3391 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3392 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3393 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3394 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3395 for (h
= lines
- 1; h
>= 0; h
--) {
3397 dstpixel
=(DWORD
*)dstbits
;
3398 for (x
= 0; x
< width
; x
++) {
3399 PALETTEENTRY srcval
;
3400 srcval
=srccolors
[(int)*srcpixel
++];
3401 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3402 (srcval
.peGreen
<< gShift
) |
3403 (srcval
.peBlue
<< bShift
);
3405 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3406 dstbits
+= linebytes
;
3416 /* ==== any bmp format -> any 0888 dib ==== */
3417 int rShift
,gShift
,bShift
;
3420 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3421 bmpImage
->depth
, bmpImage
->red_mask
,
3422 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3425 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3426 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3427 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3428 for (h
= lines
- 1; h
>= 0; h
--) {
3429 dstpixel
=(DWORD
*)dstbits
;
3430 for (x
= 0; x
< width
; x
++) {
3432 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
3433 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3434 (GetGValue(srcval
) << gShift
) |
3435 (GetBValue(srcval
) << bShift
);
3437 dstbits
+= linebytes
;
3444 static int XGetSubImageErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
3446 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
3449 /***********************************************************************
3450 * X11DRV_DIB_SetImageBits_GetSubImage
3452 * Helper for X11DRV_DIB_SetImageBits
3454 static void X11DRV_DIB_SetImageBits_GetSubImage(
3455 const X11DRV_DIB_IMAGEBITS_DESCR
*descr
, XImage
*bmpImage
)
3457 /* compressed bitmaps may contain gaps in them. So make a copy
3458 * of the existing pixels first */
3461 SetRect( &bmprc
, descr
->xDest
, descr
->yDest
,
3462 descr
->xDest
+ descr
->width
, descr
->yDest
+ descr
->height
);
3463 GetRgnBox( descr
->physDev
->region
, &rc
);
3464 /* convert from dc to drawable origin */
3465 OffsetRect( &rc
, descr
->physDev
->dc_rect
.left
, descr
->physDev
->dc_rect
.top
);
3466 /* clip visible rect with bitmap */
3467 if( IntersectRect( &rc
, &rc
, &bmprc
))
3469 X11DRV_expect_error( gdi_display
, XGetSubImageErrorHandler
, NULL
);
3470 XGetSubImage( gdi_display
, descr
->drawable
, rc
.left
, rc
.top
,
3471 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, AllPlanes
,
3473 descr
->xSrc
+ rc
.left
- bmprc
.left
,
3474 descr
->ySrc
+ rc
.top
- bmprc
.top
);
3475 X11DRV_check_error();
3479 /***********************************************************************
3480 * X11DRV_DIB_SetImageBits
3482 * Transfer the bits to an X image.
3483 * Helper function for SetDIBits() and SetDIBitsToDevice().
3485 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3487 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3492 bmpImage
= descr
->image
;
3494 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3495 descr
->infoWidth
, lines
, 32, 0 );
3496 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3497 if(bmpImage
->data
== NULL
) {
3498 ERR("Out of memory!\n");
3499 XDestroyImage( bmpImage
);
3500 wine_tsx11_unlock();
3504 wine_tsx11_unlock();
3506 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3507 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3508 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3509 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3510 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3512 /* Transfer the pixels */
3513 switch(descr
->infoBpp
)
3516 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3517 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3518 bmpImage
, descr
->dibpitch
);
3521 if (descr
->compression
) {
3522 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3523 X11DRV_DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
3524 descr
->infoWidth
, descr
->width
,
3525 descr
->xSrc
, (int *)(descr
->colorMap
),
3528 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3529 descr
->infoWidth
, descr
->width
,
3530 descr
->xSrc
, (int*)(descr
->colorMap
),
3531 bmpImage
, descr
->dibpitch
);
3534 if (descr
->compression
) {
3535 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3536 X11DRV_DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
3537 descr
->infoWidth
, descr
->width
,
3538 descr
->xSrc
, (int *)(descr
->colorMap
),
3541 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3542 descr
->infoWidth
, descr
->width
,
3543 descr
->xSrc
, (int *)(descr
->colorMap
),
3544 bmpImage
, descr
->dibpitch
);
3548 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3549 descr
->infoWidth
, descr
->width
,
3550 descr
->xSrc
, descr
->physDev
,
3551 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3552 bmpImage
, descr
->dibpitch
);
3555 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3556 descr
->infoWidth
, descr
->width
,
3557 descr
->xSrc
, descr
->physDev
,
3558 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3559 bmpImage
, descr
->dibpitch
);
3562 X11DRV_DIB_SetImageBits_32( descr
->lines
, descr
->bits
,
3563 descr
->infoWidth
, descr
->width
,
3564 descr
->xSrc
, descr
->physDev
,
3565 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3566 bmpImage
, descr
->dibpitch
);
3569 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3573 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3574 descr
->drawable
, descr
->gc
, bmpImage
,
3575 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3576 descr
->width
, descr
->height
);
3579 #ifdef HAVE_LIBXXSHM
3580 if (descr
->image
&& descr
->useShm
)
3582 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3583 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3584 descr
->width
, descr
->height
, FALSE
);
3585 XSync( gdi_display
, 0 );
3589 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3590 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3591 descr
->width
, descr
->height
);
3593 if (!descr
->image
) XDestroyImage( bmpImage
);
3594 wine_tsx11_unlock();
3598 /***********************************************************************
3599 * X11DRV_DIB_GetImageBits
3601 * Transfer the bits from an X image.
3603 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3605 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3610 bmpImage
= descr
->image
;
3612 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3613 descr
->infoWidth
, lines
, 32, 0 );
3614 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3615 if(bmpImage
->data
== NULL
) {
3616 ERR("Out of memory!\n");
3617 XDestroyImage( bmpImage
);
3618 wine_tsx11_unlock();
3623 #ifdef HAVE_LIBXXSHM
3625 /* We must not call XShmGetImage() with a bitmap which is bigger than the avilable area.
3626 If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */
3627 if((descr
->image
&& descr
->useShm
) && (bmpImage
->width
<= (descr
->width
- descr
->xSrc
))
3628 && (bmpImage
->height
<= (descr
->height
- descr
->ySrc
)))
3630 int saveRed
, saveGreen
, saveBlue
;
3632 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3633 gdi_display
, descr
->drawable
, bmpImage
,
3634 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3636 /* We must save and restore the bmpImage's masks in order
3637 * to preserve them across the call to XShmGetImage, which
3638 * decides to eleminate them since it doesn't happen to know
3639 * what the format of the image is supposed to be, even though
3641 saveRed
= bmpImage
->red_mask
;
3642 saveBlue
= bmpImage
->blue_mask
;
3643 saveGreen
= bmpImage
->green_mask
;
3645 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3646 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3648 bmpImage
->red_mask
= saveRed
;
3649 bmpImage
->blue_mask
= saveBlue
;
3650 bmpImage
->green_mask
= saveGreen
;
3653 #endif /* HAVE_LIBXXSHM */
3655 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3656 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3657 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3658 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3659 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3660 bmpImage
, descr
->xDest
, descr
->yDest
);
3662 wine_tsx11_unlock();
3664 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3665 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3666 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3667 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3668 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3669 /* Transfer the pixels */
3670 switch(descr
->infoBpp
)
3673 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3674 descr
->infoWidth
, descr
->width
,
3675 descr
->colorMap
, descr
->palentry
,
3676 bmpImage
, descr
->dibpitch
);
3680 if (descr
->compression
) {
3681 FIXME("Compression not yet supported!\n");
3682 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 4 ) * abs(descr
->lines
))
3685 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3686 descr
->infoWidth
, descr
->width
,
3687 descr
->colorMap
, descr
->palentry
,
3688 bmpImage
, descr
->dibpitch
);
3691 if (descr
->compression
) {
3692 FIXME("Compression not yet supported!\n");
3693 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 8 ) * abs(descr
->lines
))
3696 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3697 descr
->infoWidth
, descr
->width
,
3698 descr
->colorMap
, descr
->palentry
,
3699 bmpImage
, descr
->dibpitch
);
3703 X11DRV_DIB_GetImageBits_16( descr
->lines
, (LPVOID
)descr
->bits
,
3704 descr
->infoWidth
,descr
->width
,
3706 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3707 bmpImage
, descr
->dibpitch
);
3711 X11DRV_DIB_GetImageBits_24( descr
->lines
, (LPVOID
)descr
->bits
,
3712 descr
->infoWidth
,descr
->width
,
3714 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3715 bmpImage
, descr
->dibpitch
);
3719 X11DRV_DIB_GetImageBits_32( descr
->lines
, (LPVOID
)descr
->bits
,
3720 descr
->infoWidth
, descr
->width
,
3722 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3723 bmpImage
, descr
->dibpitch
);
3727 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3734 XDestroyImage( bmpImage
);
3735 wine_tsx11_unlock();
3740 /*************************************************************************
3741 * X11DRV_SetDIBitsToDevice
3744 INT
X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE
*physDev
, INT xDest
, INT yDest
, DWORD cx
,
3745 DWORD cy
, INT xSrc
, INT ySrc
,
3746 UINT startscan
, UINT lines
, LPCVOID bits
,
3747 const BITMAPINFO
*info
, UINT coloruse
)
3749 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3754 int rop
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
) - 1];
3756 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3757 &descr
.infoBpp
, &descr
.compression
) == -1)
3760 top_down
= (height
< 0);
3761 if (top_down
) height
= -height
;
3765 LPtoDP(physDev
->hdc
, &pt
, 1);
3767 if (!lines
|| (startscan
>= height
)) return 0;
3768 if (!top_down
&& startscan
+ lines
> height
) lines
= height
- startscan
;
3770 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3771 * and clamp all values to fit inside [startscan,startscan+lines]
3773 if (ySrc
+ cy
<= startscan
+ lines
)
3775 UINT y
= startscan
+ lines
- (ySrc
+ cy
);
3776 if (ySrc
< startscan
) cy
-= (startscan
- ySrc
);
3779 /* avoid getting unnecessary lines */
3781 if (y
>= lines
) return 0;
3786 if (y
>= lines
) return lines
;
3787 ySrc
= y
; /* need to get all lines in top down mode */
3792 if (ySrc
>= startscan
+ lines
) return lines
;
3793 pt
.y
+= ySrc
+ cy
- (startscan
+ lines
);
3794 cy
= startscan
+ lines
- ySrc
;
3796 if (cy
> lines
) cy
= lines
;
3798 if (xSrc
>= width
) return lines
;
3799 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
3800 if (!cx
|| !cy
) return lines
;
3802 /* Update the pixmap from the DIB section */
3803 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
, FALSE
);
3805 X11DRV_SetupGCForText( physDev
); /* To have the correct colors */
3807 XSetFunction(gdi_display
, physDev
->gc
, rop
);
3808 wine_tsx11_unlock();
3810 switch (descr
.infoBpp
)
3815 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3817 physDev
->depth
, info
, &descr
.nColorMap
);
3818 if (!descr
.colorMap
) return 0;
3819 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3823 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3824 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3825 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3831 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3832 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3833 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3838 descr
.physDev
= physDev
;
3841 descr
.palentry
= NULL
;
3842 descr
.lines
= top_down
? -lines
: lines
;
3843 descr
.infoWidth
= width
;
3844 descr
.depth
= physDev
->depth
;
3845 descr
.drawable
= physDev
->drawable
;
3846 descr
.gc
= physDev
->gc
;
3849 descr
.xDest
= physDev
->dc_rect
.left
+ pt
.x
;
3850 descr
.yDest
= physDev
->dc_rect
.top
+ pt
.y
;
3853 descr
.useShm
= FALSE
;
3854 descr
.dibpitch
= ((width
* descr
.infoBpp
+ 31) &~31) / 8;
3856 result
= X11DRV_DIB_SetImageBits( &descr
);
3858 if (descr
.infoBpp
<= 8)
3859 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3861 /* Update the DIBSection of the pixmap */
3862 X11DRV_UnlockDIBSection(physDev
, TRUE
);
3867 /***********************************************************************
3868 * SetDIBits (X11DRV.@)
3870 INT
X11DRV_SetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
,
3871 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
, UINT coloruse
)
3873 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3874 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3876 LONG width
, height
, tmpheight
;
3879 descr
.physDev
= physDev
;
3881 if (!physBitmap
) return 0;
3883 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3884 &descr
.infoBpp
, &descr
.compression
) == -1)
3888 if (height
< 0) height
= -height
;
3889 if (!lines
|| (startscan
>= height
))
3892 if (!GetObjectW( hbitmap
, sizeof(bitmap
), &bitmap
)) return 0;
3894 if (startscan
+ lines
> height
) lines
= height
- startscan
;
3896 switch (descr
.infoBpp
)
3901 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3902 descr
.physDev
, coloruse
,
3903 physBitmap
->pixmap_depth
,
3904 info
, &descr
.nColorMap
);
3905 if (!descr
.colorMap
) return 0;
3906 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3910 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3911 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3912 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3918 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3919 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3920 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3929 descr
.palentry
= NULL
;
3930 descr
.infoWidth
= width
;
3931 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
3932 descr
.depth
= physBitmap
->pixmap_depth
;
3933 descr
.drawable
= physBitmap
->pixmap
;
3934 descr
.gc
= BITMAP_GC(physBitmap
);
3938 descr
.yDest
= height
- startscan
- lines
;
3939 descr
.width
= bitmap
.bmWidth
;
3940 descr
.height
= lines
;
3941 descr
.useShm
= FALSE
;
3942 descr
.dibpitch
= ((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8;
3943 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
, FALSE
);
3944 result
= X11DRV_DIB_SetImageBits( &descr
);
3945 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
3947 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3952 /***********************************************************************
3953 * GetDIBits (X11DRV.@)
3955 INT
X11DRV_GetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
, UINT lines
,
3956 LPVOID bits
, BITMAPINFO
*info
, UINT coloruse
)
3958 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3960 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3961 PALETTEENTRY palette
[256];
3964 LONG width
, tempHeight
;
3969 GetPaletteEntries( GetCurrentObject( physDev
->hdc
, OBJ_PAL
), 0, 256, palette
);
3971 if (!physBitmap
) return 0;
3972 if (!(obj_size
= GetObjectW( hbitmap
, sizeof(dib
), &dib
))) return 0;
3974 bitmap_type
= DIB_GetBitmapInfo( (BITMAPINFOHEADER
*)info
, &width
, &tempHeight
, &descr
.infoBpp
, &descr
.compression
);
3975 descr
.lines
= tempHeight
;
3976 if (bitmap_type
== -1)
3978 ERR("Invalid bitmap\n");
3981 core_header
= (bitmap_type
== 0);
3982 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
3984 TRACE("%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
3985 lines
, dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
, width
, descr
.lines
, startscan
);
3987 if( lines
> dib
.dsBm
.bmHeight
) lines
= dib
.dsBm
.bmHeight
;
3989 height
= descr
.lines
;
3990 if (height
< 0) height
= -height
;
3991 if( lines
> height
) lines
= height
;
3992 /* Top-down images have a negative biHeight, the scanlines of theses images
3993 * were inverted in X11DRV_DIB_GetImageBits_xx
3994 * To prevent this we simply change the sign of lines
3995 * (the number of scan lines to copy).
3996 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
3998 if( descr
.lines
< 0 && lines
> 0) lines
= -lines
;
4000 if( startscan
>= dib
.dsBm
.bmHeight
) return 0;
4002 descr
.colorMap
= NULL
;
4004 switch (descr
.infoBpp
)
4009 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4010 if(coloruse
== DIB_RGB_COLORS
)
4011 descr
.colorMap
= colorPtr
;
4013 int num_colors
= 1 << descr
.infoBpp
, i
;
4016 WORD
*index
= (WORD
*)colorPtr
;
4017 descr
.colorMap
= rgb
= HeapAlloc(GetProcessHeap(), 0, num_colors
* sizeof(RGBQUAD
));
4018 for(i
= 0; i
< num_colors
; i
++, rgb
++, index
++) {
4019 colref
= X11DRV_PALETTE_ToLogical(X11DRV_PALETTE_ToPhysical(physDev
, PALETTEINDEX(*index
)));
4020 rgb
->rgbRed
= GetRValue(colref
);
4021 rgb
->rgbGreen
= GetGValue(colref
);
4022 rgb
->rgbBlue
= GetBValue(colref
);
4023 rgb
->rgbReserved
= 0;
4029 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4030 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4031 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4035 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4036 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4037 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4041 descr
.physDev
= physDev
;
4042 descr
.palentry
= palette
;
4044 descr
.image
= physBitmap
->image
;
4045 descr
.infoWidth
= width
;
4046 descr
.lines
= lines
;
4047 descr
.depth
= physBitmap
->pixmap_depth
;
4048 descr
.drawable
= physBitmap
->pixmap
;
4049 descr
.gc
= BITMAP_GC(physBitmap
);
4050 descr
.width
= dib
.dsBm
.bmWidth
;
4051 descr
.height
= dib
.dsBm
.bmHeight
;
4055 descr
.sizeImage
= core_header
? 0 : info
->bmiHeader
.biSizeImage
;
4057 if (descr
.lines
> 0)
4059 descr
.ySrc
= (descr
.height
-1) - (startscan
+ (lines
-1));
4063 descr
.ySrc
= startscan
;
4065 #ifdef HAVE_LIBXXSHM
4066 descr
.useShm
= (obj_size
== sizeof(DIBSECTION
)) && (physBitmap
->shminfo
.shmid
!= -1);
4068 descr
.useShm
= FALSE
;
4070 descr
.dibpitch
= (obj_size
== sizeof(DIBSECTION
)) ? dib
.dsBm
.bmWidthBytes
4071 : (((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8);
4073 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
, FALSE
);
4074 X11DRV_DIB_GetImageBits( &descr
);
4075 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4077 if(!core_header
&& info
->bmiHeader
.biSizeImage
== 0) /* Fill in biSizeImage */
4078 info
->bmiHeader
.biSizeImage
= X11DRV_DIB_GetDIBImageBytes( descr
.infoWidth
,
4082 if (descr
.compression
== BI_BITFIELDS
)
4084 *(DWORD
*)info
->bmiColors
= descr
.rMask
;
4085 *((DWORD
*)info
->bmiColors
+ 1) = descr
.gMask
;
4086 *((DWORD
*)info
->bmiColors
+ 2) = descr
.bMask
;
4088 else if (!core_header
)
4090 /* if RLE or JPEG compression were supported,
4091 * this line would be invalid. */
4092 info
->bmiHeader
.biCompression
= 0;
4095 if(descr
.colorMap
!= colorPtr
)
4096 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4100 /***********************************************************************
4101 * DIB_DoProtectDIBSection
4103 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP
*physBitmap
, DWORD new_prot
)
4107 VirtualProtect(physBitmap
->base
, physBitmap
->size
, new_prot
, &old_prot
);
4108 TRACE("Changed protection from %d to %d\n", old_prot
, new_prot
);
4111 /***********************************************************************
4112 * X11DRV_DIB_DoCopyDIBSection
4114 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
4115 void *colorMap
, int nColorMap
,
4116 Drawable dest
, GC gc
,
4117 DWORD xSrc
, DWORD ySrc
,
4118 DWORD xDest
, DWORD yDest
,
4119 DWORD width
, DWORD height
)
4121 DIBSECTION dibSection
;
4122 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4123 int identity
[2] = {0,1};
4125 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
4127 descr
.physDev
= NULL
;
4128 descr
.palentry
= NULL
;
4129 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
4130 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
4131 descr
.lines
= dibSection
.dsBmih
.biHeight
;
4132 descr
.image
= physBitmap
->image
;
4133 descr
.colorMap
= colorMap
;
4134 descr
.nColorMap
= nColorMap
;
4135 descr
.bits
= dibSection
.dsBm
.bmBits
;
4136 descr
.depth
= physBitmap
->pixmap_depth
;
4137 descr
.compression
= dibSection
.dsBmih
.biCompression
;
4139 if(descr
.infoBpp
== 1)
4140 descr
.colorMap
= (void*)identity
;
4142 switch (descr
.infoBpp
)
4147 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4151 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
4152 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
4153 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
4158 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
4159 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
4160 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
4165 descr
.drawable
= dest
;
4169 descr
.xDest
= xDest
;
4170 descr
.yDest
= yDest
;
4171 descr
.width
= width
;
4172 descr
.height
= height
;
4173 descr
.sizeImage
= 0;
4175 #ifdef HAVE_LIBXXSHM
4176 descr
.useShm
= (physBitmap
->shminfo
.shmid
!= -1);
4178 descr
.useShm
= FALSE
;
4180 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
4184 TRACE("Copying from Pixmap to DIB bits\n");
4185 X11DRV_DIB_GetImageBits( &descr
);
4189 TRACE("Copying from DIB bits to Pixmap\n");
4190 X11DRV_DIB_SetImageBits( &descr
);
4194 /***********************************************************************
4195 * X11DRV_DIB_CopyDIBSection
4197 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE
*physDevSrc
, X11DRV_PDEVICE
*physDevDst
,
4198 DWORD xSrc
, DWORD ySrc
, DWORD xDest
, DWORD yDest
,
4199 DWORD width
, DWORD height
)
4202 X_PHYSBITMAP
*physBitmap
;
4203 int nColorMap
= 0, *colorMap
= NULL
, aColorMap
= FALSE
;
4205 TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc
->hdc
, physDevDst
->hdc
,
4206 xSrc
, ySrc
, xDest
, yDest
, width
, height
);
4207 /* this function is meant as an optimization for BitBlt,
4208 * not to be called otherwise */
4209 physBitmap
= physDevSrc
->bitmap
;
4210 if (!physBitmap
|| GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
4212 ERR("called for non-DIBSection!?\n");
4215 /* while BitBlt should already have made sure we only get
4216 * positive values, we should check for oversize values */
4217 if ((xSrc
< dib
.dsBm
.bmWidth
) &&
4218 (ySrc
< dib
.dsBm
.bmHeight
)) {
4219 if (xSrc
+ width
> dib
.dsBm
.bmWidth
)
4220 width
= dib
.dsBm
.bmWidth
- xSrc
;
4221 if (ySrc
+ height
> dib
.dsBm
.bmHeight
)
4222 height
= dib
.dsBm
.bmHeight
- ySrc
;
4223 /* if the source bitmap is 8bpp or less, we're supposed to use the
4224 * DC's palette for color conversion (not the DIB color table) */
4225 if (dib
.dsBm
.bmBitsPixel
<= 8) {
4226 HPALETTE hPalette
= GetCurrentObject( physDevSrc
->hdc
, OBJ_PAL
);
4227 if (!hPalette
|| (hPalette
== GetStockObject(DEFAULT_PALETTE
))) {
4228 /* HACK: no palette has been set in the source DC,
4229 * use the DIB colormap instead - this is necessary in some
4230 * cases since we need to do depth conversion in some places
4231 * where real Windows can just copy data straight over */
4232 colorMap
= physBitmap
->colorMap
;
4233 nColorMap
= physBitmap
->nColorMap
;
4235 colorMap
= X11DRV_DIB_BuildColorMap( physDevSrc
, (WORD
)-1,
4236 dib
.dsBm
.bmBitsPixel
,
4237 (BITMAPINFO
*)&dib
.dsBmih
,
4239 if (colorMap
) aColorMap
= TRUE
;
4242 /* perform the copy */
4243 X11DRV_DIB_DoCopyDIBSection(physBitmap
, FALSE
, colorMap
, nColorMap
,
4244 physDevDst
->drawable
, physDevDst
->gc
, xSrc
, ySrc
,
4245 physDevDst
->dc_rect
.left
+ xDest
, physDevDst
->dc_rect
.top
+ yDest
,
4247 /* free color mapping */
4249 HeapFree(GetProcessHeap(), 0, colorMap
);
4253 /***********************************************************************
4254 * X11DRV_DIB_DoUpdateDIBSection
4256 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
4260 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
4261 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
4262 physBitmap
->colorMap
, physBitmap
->nColorMap
,
4263 physBitmap
->pixmap
, BITMAP_GC(physBitmap
),
4264 0, 0, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
);
4267 /***********************************************************************
4268 * X11DRV_DIB_FaultHandler
4270 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
4272 X_PHYSBITMAP
*physBitmap
= NULL
;
4277 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
4278 return EXCEPTION_CONTINUE_SEARCH
;
4280 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
4282 EnterCriticalSection(&dibs_cs
);
4283 LIST_FOR_EACH( ptr
, &dibs_list
)
4285 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
4286 if ((physBitmap
->base
<= addr
) && (addr
< physBitmap
->base
+ physBitmap
->size
))
4292 LeaveCriticalSection(&dibs_cs
);
4294 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
4296 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
, FALSE
);
4297 if (ep
->ExceptionRecord
->ExceptionInformation
[0] == EXCEPTION_WRITE_FAULT
) {
4298 /* the app tried to write the DIB bits */
4299 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
, FALSE
);
4301 /* the app tried to read the DIB bits */
4302 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
, FALSE
);
4304 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4306 return EXCEPTION_CONTINUE_EXECUTION
;
4309 /***********************************************************************
4312 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
, BOOL lossy
)
4314 INT ret
= DIB_Status_None
;
4316 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4317 EnterCriticalSection(&physBitmap
->lock
);
4318 ret
= physBitmap
->status
;
4320 case DIB_Status_GdiMod
:
4321 /* GDI access - request to draw on pixmap */
4322 switch (physBitmap
->status
)
4325 case DIB_Status_None
:
4326 physBitmap
->p_status
= DIB_Status_GdiMod
;
4327 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4330 case DIB_Status_GdiMod
:
4331 TRACE("GdiMod requested in status GdiMod\n" );
4332 physBitmap
->p_status
= DIB_Status_GdiMod
;
4335 case DIB_Status_InSync
:
4336 TRACE("GdiMod requested in status InSync\n" );
4337 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4338 physBitmap
->status
= DIB_Status_GdiMod
;
4339 physBitmap
->p_status
= DIB_Status_InSync
;
4342 case DIB_Status_AppMod
:
4343 TRACE("GdiMod requested in status AppMod\n" );
4345 /* make it readonly to avoid app changing data while we copy */
4346 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4347 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4349 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4350 physBitmap
->p_status
= DIB_Status_AppMod
;
4351 physBitmap
->status
= DIB_Status_GdiMod
;
4356 case DIB_Status_InSync
:
4357 /* App access - request access to read DIB surface */
4358 /* (typically called from signal handler) */
4359 switch (physBitmap
->status
)
4362 case DIB_Status_None
:
4363 /* shouldn't happen from signal handler */
4366 case DIB_Status_GdiMod
:
4367 TRACE("InSync requested in status GdiMod\n" );
4369 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4370 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4372 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4373 physBitmap
->status
= DIB_Status_InSync
;
4376 case DIB_Status_InSync
:
4377 TRACE("InSync requested in status InSync\n" );
4378 /* shouldn't happen from signal handler */
4381 case DIB_Status_AppMod
:
4382 TRACE("InSync requested in status AppMod\n" );
4383 /* no reason to do anything here, and this
4384 * shouldn't happen from signal handler */
4389 case DIB_Status_AppMod
:
4390 /* App access - request access to write DIB surface */
4391 /* (typically called from signal handler) */
4392 switch (physBitmap
->status
)
4395 case DIB_Status_None
:
4396 /* shouldn't happen from signal handler */
4399 case DIB_Status_GdiMod
:
4400 TRACE("AppMod requested in status GdiMod\n" );
4401 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4402 if (!lossy
) X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4403 physBitmap
->status
= DIB_Status_AppMod
;
4406 case DIB_Status_InSync
:
4407 TRACE("AppMod requested in status InSync\n" );
4408 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4409 physBitmap
->status
= DIB_Status_AppMod
;
4412 case DIB_Status_AppMod
:
4413 TRACE("AppMod requested in status AppMod\n" );
4414 /* shouldn't happen from signal handler */
4419 /* it is up to the caller to do the copy/conversion, probably
4420 * using the return value to decide where to copy from */
4422 LeaveCriticalSection(&physBitmap
->lock
);
4426 /***********************************************************************
4429 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
, BOOL lossy
)
4431 INT ret
= DIB_Status_None
;
4433 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4434 TRACE("Locking %p from thread %04x\n", physBitmap
->hbitmap
, GetCurrentThreadId());
4435 EnterCriticalSection(&physBitmap
->lock
);
4436 ret
= physBitmap
->status
;
4437 if (req
!= DIB_Status_None
)
4438 X11DRV_DIB_Coerce(physBitmap
, req
, lossy
);
4442 /***********************************************************************
4445 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
4447 if (!physBitmap
->image
) return; /* not a DIB section */
4448 switch (physBitmap
->status
)
4451 case DIB_Status_None
:
4452 /* in case anyone is wondering, this is the "signal handler doesn't
4453 * work" case, where we always have to be ready for app access */
4455 switch (physBitmap
->p_status
)
4457 case DIB_Status_GdiMod
:
4458 TRACE("Unlocking and syncing from GdiMod\n" );
4459 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4463 TRACE("Unlocking without needing to sync\n" );
4467 else TRACE("Unlocking with no changes\n");
4468 physBitmap
->p_status
= DIB_Status_None
;
4471 case DIB_Status_GdiMod
:
4472 TRACE("Unlocking in status GdiMod\n" );
4473 /* DIB was protected in Coerce */
4475 /* no commit, revert to InSync if applicable */
4476 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
4477 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
4478 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4479 physBitmap
->status
= DIB_Status_InSync
;
4484 case DIB_Status_InSync
:
4485 TRACE("Unlocking in status InSync\n" );
4486 /* DIB was already protected in Coerce */
4489 case DIB_Status_AppMod
:
4490 TRACE("Unlocking in status AppMod\n" );
4491 /* DIB was already protected in Coerce */
4492 /* this case is ordinary only called from the signal handler,
4493 * so we don't bother to check for !commit */
4496 LeaveCriticalSection(&physBitmap
->lock
);
4497 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
4500 /***********************************************************************
4501 * X11DRV_CoerceDIBSection
4503 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
, BOOL lossy
)
4505 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4506 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
, lossy
);
4509 /***********************************************************************
4510 * X11DRV_LockDIBSection
4512 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
, BOOL lossy
)
4514 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4515 return X11DRV_DIB_Lock(physDev
->bitmap
, req
, lossy
);
4518 /***********************************************************************
4519 * X11DRV_UnlockDIBSection
4521 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
4523 if (!physDev
|| !physDev
->bitmap
) return;
4524 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
4528 #ifdef HAVE_LIBXXSHM
4529 /***********************************************************************
4530 * X11DRV_XShmErrorHandler
4533 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
4535 return 1; /* FIXME: should check event contents */
4538 /***********************************************************************
4539 * X11DRV_XShmCreateImage
4542 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
4543 XShmSegmentInfo
* shminfo
)
4547 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
4550 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
4552 if( shminfo
->shmid
!= -1 )
4554 shminfo
->shmaddr
= image
->data
= shmat(shminfo
->shmid
, 0, 0);
4555 if( shminfo
->shmaddr
!= (char*)-1 )
4559 shminfo
->readOnly
= FALSE
;
4560 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
4561 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
4562 XSync( gdi_display
, False
);
4563 if (X11DRV_check_error()) ok
= FALSE
;
4566 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4567 return image
; /* Success! */
4569 /* An error occurred */
4570 shmdt(shminfo
->shmaddr
);
4572 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4573 shminfo
->shmid
= -1;
4575 XFlush(gdi_display
);
4576 XDestroyImage(image
);
4581 #endif /* HAVE_LIBXXSHM */
4584 /***********************************************************************
4585 * X11DRV_CreateDIBSection (X11DRV.@)
4587 HBITMAP
X11DRV_CreateDIBSection( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
,
4588 const BITMAPINFO
*bmi
, UINT usage
)
4590 X_PHYSBITMAP
*physBitmap
;
4593 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
4594 physBitmap
->status
= DIB_Status_None
;
4596 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
4598 /* create color map */
4599 if (dib
.dsBm
.bmBitsPixel
<= 8)
4601 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( physDev
,
4602 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
4603 &physBitmap
->nColorMap
);
4606 /* create pixmap and X image */
4608 physBitmap
->pixmap_depth
= (dib
.dsBm
.bmBitsPixel
== 1) ? 1 : screen_depth
;
4609 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
4610 dib
.dsBm
.bmHeight
, physBitmap
->pixmap_depth
);
4611 #ifdef HAVE_LIBXXSHM
4612 physBitmap
->shminfo
.shmid
= -1;
4613 if (!XShmQueryExtension(gdi_display
) ||
4614 !(physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4615 physBitmap
->pixmap_depth
, &physBitmap
->shminfo
)) )
4617 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4618 physBitmap
->pixmap_depth
);
4619 wine_tsx11_unlock();
4620 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
4622 /* install fault handler */
4623 InitializeCriticalSection( &physBitmap
->lock
);
4624 physBitmap
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": X_PHYSBITMAP.lock");
4626 physBitmap
->base
= dib
.dsBm
.bmBits
;
4627 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
4628 physBitmap
->status
= DIB_Status_AppMod
;
4631 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
4632 EnterCriticalSection( &dibs_cs
);
4633 list_add_head( &dibs_list
, &physBitmap
->entry
);
4634 LeaveCriticalSection( &dibs_cs
);
4636 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4641 /***********************************************************************
4642 * X11DRV_DIB_DeleteDIBSection
4644 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
4648 EnterCriticalSection( &dibs_cs
);
4649 list_remove( &physBitmap
->entry
);
4650 last
= list_empty( &dibs_list
);
4651 LeaveCriticalSection( &dibs_cs
);
4655 RemoveVectoredExceptionHandler( dibs_handler
);
4656 dibs_handler
= NULL
;
4659 if (dib
->dshSection
)
4660 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
, FALSE
);
4662 if (physBitmap
->image
)
4665 #ifdef HAVE_LIBXXSHM
4666 if (physBitmap
->shminfo
.shmid
!= -1)
4668 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4669 XDestroyImage( physBitmap
->image
);
4670 shmdt( physBitmap
->shminfo
.shmaddr
);
4671 physBitmap
->shminfo
.shmid
= -1;
4675 XDestroyImage( physBitmap
->image
);
4676 wine_tsx11_unlock();
4679 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4680 physBitmap
->lock
.DebugInfo
->Spare
[0] = 0;
4681 DeleteCriticalSection(&physBitmap
->lock
);
4684 /***********************************************************************
4685 * SetDIBColorTable (X11DRV.@)
4687 UINT
X11DRV_SetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4691 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4693 if (!physBitmap
) return 0;
4694 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4696 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4697 UINT end
= count
+ start
;
4698 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4700 * Changing color table might change the mapping between
4701 * DIB colors and X11 colors and thus alter the visible state
4702 * of the bitmap object.
4705 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4706 * at least for a 1 bpp dibsection
4708 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
, FALSE
);
4709 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4710 dib
.dsBm
.bmBitsPixel
,
4711 TRUE
, colors
, start
, end
);
4712 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4719 /***********************************************************************
4720 * X11DRV_DIB_CreateDIBFromBitmap
4722 * Allocates a packed DIB and copies the bitmap data into it.
4724 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4729 LPBITMAPINFOHEADER pbmiHeader
;
4730 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4733 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4736 * A packed DIB contains a BITMAPINFO structure followed immediately by
4737 * an optional color palette and the pixel data.
4740 /* Calculate the size of the packed DIB */
4741 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4742 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4743 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4745 /* Get the offset to the bits */
4746 OffsetBits
= cPackedSize
- cDataSize
;
4748 /* Allocate the packed DIB */
4749 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4750 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4754 WARN("Could not allocate packed DIB!\n");
4758 /* A packed DIB starts with a BITMAPINFOHEADER */
4759 pPackedDIB
= GlobalLock(hPackedDIB
);
4760 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4762 /* Init the BITMAPINFOHEADER */
4763 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
4764 pbmiHeader
->biWidth
= bmp
.bmWidth
;
4765 pbmiHeader
->biHeight
= bmp
.bmHeight
;
4766 pbmiHeader
->biPlanes
= 1;
4767 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
4768 pbmiHeader
->biCompression
= BI_RGB
;
4769 pbmiHeader
->biSizeImage
= 0;
4770 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
4771 pbmiHeader
->biClrUsed
= 0;
4772 pbmiHeader
->biClrImportant
= 0;
4774 /* Retrieve the DIB bits from the bitmap and fill in the
4775 * DIB color table if present */
4777 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
4778 hBmp
, /* Handle to bitmap */
4779 0, /* First scan line to set in dest bitmap */
4780 bmp
.bmHeight
, /* Number of scan lines to copy */
4781 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
4782 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
4783 0); /* RGB or palette index */
4784 GlobalUnlock(hPackedDIB
);
4786 /* Cleanup if GetDIBits failed */
4787 if (nLinesCopied
!= bmp
.bmHeight
)
4789 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
4790 GlobalFree(hPackedDIB
);
4797 /**************************************************************************
4798 * X11DRV_DIB_CreateDIBFromPixmap
4800 * Allocates a packed DIB and copies the Pixmap data into it.
4801 * The Pixmap passed in is deleted after the conversion.
4803 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
4806 X_PHYSBITMAP
*physBitmap
;
4807 HBITMAP hBmp
= 0, old
;
4808 HGLOBAL hPackedDIB
= 0;
4810 int x
,y
; /* Unused */
4811 unsigned border_width
; /* Unused */
4812 unsigned int depth
, width
, height
;
4814 /* Get the Pixmap dimensions and bit depth */
4816 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
4817 &border_width
, &depth
)) depth
= 0;
4818 wine_tsx11_unlock();
4819 if (!depth
) return 0;
4821 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4822 width
, height
, depth
);
4825 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4826 * and make it a container for the pixmap passed.
4828 hBmp
= CreateBitmap( width
, height
, 1, depth
, NULL
);
4830 /* force bitmap to be owned by a screen DC */
4831 hdcMem
= CreateCompatibleDC( hdc
);
4832 old
= SelectObject( hdcMem
, hBmp
);
4834 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4837 if (physBitmap
->pixmap
) XFreePixmap( gdi_display
, physBitmap
->pixmap
);
4838 physBitmap
->pixmap
= pixmap
;
4839 wine_tsx11_unlock();
4841 SelectObject( hdcMem
, old
);
4845 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4846 * A packed DIB contains a BITMAPINFO structure followed immediately by
4847 * an optional color palette and the pixel data.
4849 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
4851 /* We can now get rid of the HBITMAP wrapper we created earlier.
4852 * Note: Simply calling DeleteObject will free the embedded Pixmap as well.
4856 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
4861 /**************************************************************************
4862 * X11DRV_DIB_CreatePixmapFromDIB
4864 * Creates a Pixmap from a packed DIB
4866 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
4869 X_PHYSBITMAP
*physBitmap
;
4873 /* Create a DDB from the DIB */
4875 pbmi
= GlobalLock(hPackedDIB
);
4876 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
4877 (LPBYTE
)pbmi
+ X11DRV_DIB_BitmapInfoSize( pbmi
, DIB_RGB_COLORS
),
4878 pbmi
, DIB_RGB_COLORS
);
4879 GlobalUnlock(hPackedDIB
);
4881 /* clear the physBitmap so that we can steal its pixmap */
4882 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4883 pixmap
= physBitmap
->pixmap
;
4884 physBitmap
->pixmap
= 0;
4886 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4889 TRACE("Returning Pixmap %ld\n", pixmap
);