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
);
101 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*,INT
);
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 for (i
= width
/8, x
= left
; i
> 0; i
--) {
515 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
516 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
517 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
518 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
519 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
520 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
521 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
522 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
528 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
529 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
530 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
531 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
532 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
533 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
534 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
537 srcbits
+= linebytes
;
541 /***********************************************************************
542 * X11DRV_DIB_GetImageBits_1
544 * GetDIBits for a 1-bit deep DIB.
546 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
547 DWORD dstwidth
, DWORD srcwidth
,
548 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
549 XImage
*bmpImage
, DWORD linebytes
)
552 int h
, width
= min(dstwidth
, srcwidth
);
556 dstbits
= dstbits
+ linebytes
* (lines
- 1);
557 linebytes
= -linebytes
;
560 switch (bmpImage
->depth
)
564 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
566 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
569 for (h
=lines
-1; h
>=0; h
--) {
573 for (x
=0; x
<width
; x
++) {
575 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
576 dstval
|=(X11DRV_DIB_GetNearestIndex
580 srcval
.peBlue
) << (7 - (x
& 7)));
589 dstbits
+= linebytes
;
597 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
, bmpImage
->green_mask
, bmpImage
->blue_mask
)
599 /* ==== pal 8 bmp -> pal 1 dib ==== */
601 const BYTE
* srcpixel
;
604 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
606 for (h
=0; h
<lines
; h
++) {
611 for (x
=0; x
<width
; x
++) {
613 srcval
=srccolors
[(int)*srcpixel
++];
614 dstval
|=(X11DRV_DIB_GetNearestIndex
618 srcval
.peBlue
) << (7-(x
&7)) );
627 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
628 dstbits
+= linebytes
;
639 const WORD
* srcpixel
;
642 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
644 if (bmpImage
->green_mask
==0x03e0) {
645 if (bmpImage
->red_mask
==0x7c00) {
646 /* ==== rgb 555 bmp -> pal 1 dib ==== */
647 for (h
=0; h
<lines
; h
++) {
652 for (x
=0; x
<width
; x
++) {
655 dstval
|=(X11DRV_DIB_GetNearestIndex
657 ((srcval
>> 7) & 0xf8) | /* r */
658 ((srcval
>> 12) & 0x07),
659 ((srcval
>> 2) & 0xf8) | /* g */
660 ((srcval
>> 7) & 0x07),
661 ((srcval
<< 3) & 0xf8) | /* b */
662 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
671 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
672 dstbits
+= linebytes
;
674 } else if (bmpImage
->blue_mask
==0x7c00) {
675 /* ==== bgr 555 bmp -> pal 1 dib ==== */
676 for (h
=0; h
<lines
; h
++) {
681 for (x
=0; x
<width
; x
++) {
684 dstval
|=(X11DRV_DIB_GetNearestIndex
686 ((srcval
<< 3) & 0xf8) | /* r */
687 ((srcval
>> 2) & 0x07),
688 ((srcval
>> 2) & 0xf8) | /* g */
689 ((srcval
>> 7) & 0x07),
690 ((srcval
>> 7) & 0xf8) | /* b */
691 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
700 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
701 dstbits
+= linebytes
;
706 } else if (bmpImage
->green_mask
==0x07e0) {
707 if (bmpImage
->red_mask
==0xf800) {
708 /* ==== rgb 565 bmp -> pal 1 dib ==== */
709 for (h
=0; h
<lines
; h
++) {
714 for (x
=0; x
<width
; x
++) {
717 dstval
|=(X11DRV_DIB_GetNearestIndex
719 ((srcval
>> 8) & 0xf8) | /* r */
720 ((srcval
>> 13) & 0x07),
721 ((srcval
>> 3) & 0xfc) | /* g */
722 ((srcval
>> 9) & 0x03),
723 ((srcval
<< 3) & 0xf8) | /* b */
724 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
733 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
734 dstbits
+= linebytes
;
736 } else if (bmpImage
->blue_mask
==0xf800) {
737 /* ==== bgr 565 bmp -> pal 1 dib ==== */
738 for (h
=0; h
<lines
; h
++) {
743 for (x
=0; x
<width
; x
++) {
746 dstval
|=(X11DRV_DIB_GetNearestIndex
748 ((srcval
<< 3) & 0xf8) | /* r */
749 ((srcval
>> 2) & 0x07),
750 ((srcval
>> 3) & 0xfc) | /* g */
751 ((srcval
>> 9) & 0x03),
752 ((srcval
>> 8) & 0xf8) | /* b */
753 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
762 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
763 dstbits
+= linebytes
;
782 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
783 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
785 if (bmpImage
->green_mask
!=0x00ff00 ||
786 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
788 } else if (bmpImage
->blue_mask
==0xff) {
789 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
790 for (h
=0; h
<lines
; h
++) {
795 for (x
=0; x
<width
; x
++) {
796 dstval
|=(X11DRV_DIB_GetNearestIndex
800 srcbyte
[0]) << (7-(x
&7)) );
801 srcbyte
+=bytes_per_pixel
;
810 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
811 dstbits
+= linebytes
;
814 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
815 for (h
=0; h
<lines
; h
++) {
820 for (x
=0; x
<width
; x
++) {
821 dstval
|=(X11DRV_DIB_GetNearestIndex
825 srcbyte
[2]) << (7-(x
&7)) );
826 srcbyte
+=bytes_per_pixel
;
835 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
836 dstbits
+= linebytes
;
847 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
849 /* ==== any bmp format -> pal 1 dib ==== */
850 if ((unsigned)colors
[0].rgbRed
+colors
[0].rgbGreen
+colors
[0].rgbBlue
>=
851 (unsigned)colors
[1].rgbRed
+colors
[1].rgbGreen
+colors
[1].rgbBlue
)
854 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
855 "%s color mapping\n",
856 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
857 bmpImage
->green_mask
, bmpImage
->blue_mask
,
858 neg
?"negative":"direct" );
860 for (h
=lines
-1; h
>=0; h
--) {
864 for (x
=0; x
<width
; x
++) {
865 dstval
|=((XGetPixel( bmpImage
, x
, h
) >= white
) ^ neg
) << (7 - (x
&7));
874 dstbits
+= linebytes
;
881 /***********************************************************************
882 * X11DRV_DIB_SetImageBits_4
884 * SetDIBits for a 4-bit deep DIB.
886 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
887 DWORD srcwidth
, DWORD dstwidth
, int left
,
888 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
896 srcbits
= srcbits
+ linebytes
* (lines
- 1);
897 linebytes
= -linebytes
;
904 srcbits
+= left
>> 1;
905 width
= min(srcwidth
, dstwidth
);
907 /* ==== pal 4 dib -> any bmp format ==== */
908 for (h
= lines
-1; h
>= 0; h
--) {
910 for (i
= width
/2, x
= left
; i
> 0; i
--) {
911 BYTE srcval
=*srcbyte
++;
912 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
913 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
916 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
917 srcbits
+= linebytes
;
923 /***********************************************************************
924 * X11DRV_DIB_GetImageBits_4
926 * GetDIBits for a 4-bit deep DIB.
928 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
929 DWORD srcwidth
, DWORD dstwidth
,
930 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
931 XImage
*bmpImage
, DWORD linebytes
)
934 int h
, width
= min(srcwidth
, dstwidth
);
940 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
941 linebytes
= -linebytes
;
946 switch (bmpImage
->depth
) {
949 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
951 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
954 for (h
= lines
-1; h
>= 0; h
--) {
958 for (x
= 0; x
< width
; x
++) {
960 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
961 dstval
|=(X11DRV_DIB_GetNearestIndex
965 srcval
.peBlue
) << (4-((x
&1)<<2)));
974 dstbits
+= linebytes
;
982 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
984 /* ==== pal 8 bmp -> pal 4 dib ==== */
986 const BYTE
*srcpixel
;
989 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
990 for (h
=0; h
<lines
; h
++) {
995 for (x
=0; x
<width
; x
++) {
997 srcval
= srccolors
[(int)*srcpixel
++];
998 dstval
|=(X11DRV_DIB_GetNearestIndex
1002 srcval
.peBlue
) << (4*(1-(x
&1))) );
1011 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1012 dstbits
+= linebytes
;
1022 const void* srcbits
;
1023 const WORD
* srcpixel
;
1026 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1028 if (bmpImage
->green_mask
==0x03e0) {
1029 if (bmpImage
->red_mask
==0x7c00) {
1030 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1031 for (h
=0; h
<lines
; h
++) {
1036 for (x
=0; x
<width
; x
++) {
1039 dstval
|=(X11DRV_DIB_GetNearestIndex
1041 ((srcval
>> 7) & 0xf8) | /* r */
1042 ((srcval
>> 12) & 0x07),
1043 ((srcval
>> 2) & 0xf8) | /* g */
1044 ((srcval
>> 7) & 0x07),
1045 ((srcval
<< 3) & 0xf8) | /* b */
1046 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1055 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1056 dstbits
+= linebytes
;
1058 } else if (bmpImage
->blue_mask
==0x7c00) {
1059 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1060 for (h
=0; h
<lines
; h
++) {
1065 for (x
=0; x
<width
; x
++) {
1068 dstval
|=(X11DRV_DIB_GetNearestIndex
1070 ((srcval
<< 3) & 0xf8) | /* r */
1071 ((srcval
>> 2) & 0x07),
1072 ((srcval
>> 2) & 0xf8) | /* g */
1073 ((srcval
>> 7) & 0x07),
1074 ((srcval
>> 7) & 0xf8) | /* b */
1075 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1084 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1085 dstbits
+= linebytes
;
1090 } else if (bmpImage
->green_mask
==0x07e0) {
1091 if (bmpImage
->red_mask
==0xf800) {
1092 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1093 for (h
=0; h
<lines
; h
++) {
1098 for (x
=0; x
<width
; x
++) {
1101 dstval
|=(X11DRV_DIB_GetNearestIndex
1103 ((srcval
>> 8) & 0xf8) | /* r */
1104 ((srcval
>> 13) & 0x07),
1105 ((srcval
>> 3) & 0xfc) | /* g */
1106 ((srcval
>> 9) & 0x03),
1107 ((srcval
<< 3) & 0xf8) | /* b */
1108 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1117 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1118 dstbits
+= linebytes
;
1120 } else if (bmpImage
->blue_mask
==0xf800) {
1121 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1122 for (h
=0; h
<lines
; h
++) {
1127 for (x
=0; x
<width
; x
++) {
1130 dstval
|=(X11DRV_DIB_GetNearestIndex
1132 ((srcval
<< 3) & 0xf8) | /* r */
1133 ((srcval
>> 2) & 0x07),
1134 ((srcval
>> 3) & 0xfc) | /* g */
1135 ((srcval
>> 9) & 0x03),
1136 ((srcval
>> 8) & 0xf8) | /* b */
1137 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1146 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1147 dstbits
+= linebytes
;
1159 if (bmpImage
->bits_per_pixel
==24) {
1160 const void* srcbits
;
1161 const BYTE
*srcbyte
;
1164 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1166 if (bmpImage
->green_mask
!=0x00ff00 ||
1167 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1169 } else if (bmpImage
->blue_mask
==0xff) {
1170 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1171 for (h
=0; h
<lines
; h
++) {
1174 for (x
=0; x
<width
/2; x
++) {
1175 /* Do 2 pixels at a time */
1176 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1181 X11DRV_DIB_GetNearestIndex
1189 /* And the the odd pixel */
1190 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1196 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1197 dstbits
+= linebytes
;
1200 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1201 for (h
=0; h
<lines
; h
++) {
1204 for (x
=0; x
<width
/2; x
++) {
1205 /* Do 2 pixels at a time */
1206 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1211 X11DRV_DIB_GetNearestIndex
1219 /* And the the odd pixel */
1220 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1226 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1227 dstbits
+= linebytes
;
1236 const void* srcbits
;
1237 const BYTE
*srcbyte
;
1240 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1242 if (bmpImage
->green_mask
!=0x00ff00 ||
1243 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1245 } else if (bmpImage
->blue_mask
==0xff) {
1246 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1247 for (h
=0; h
<lines
; h
++) {
1250 for (x
=0; x
<width
/2; x
++) {
1251 /* Do 2 pixels at a time */
1252 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1257 X11DRV_DIB_GetNearestIndex
1265 /* And the the odd pixel */
1266 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1272 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1273 dstbits
+= linebytes
;
1276 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1277 for (h
=0; h
<lines
; h
++) {
1280 for (x
=0; x
<width
/2; x
++) {
1281 /* Do 2 pixels at a time */
1282 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1287 X11DRV_DIB_GetNearestIndex
1295 /* And the the odd pixel */
1296 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1302 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1303 dstbits
+= linebytes
;
1314 /* ==== any bmp format -> pal 4 dib ==== */
1315 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1316 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1317 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1318 for (h
=lines
-1; h
>=0; h
--) {
1320 for (x
=0; x
<(width
& ~1); x
+=2) {
1321 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1322 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1325 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1327 dstbits
+= linebytes
;
1334 /***********************************************************************
1335 * X11DRV_DIB_SetImageBits_RLE4
1337 * SetDIBits for a 4-bit deep compressed DIB.
1339 static void X11DRV_DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
,
1340 DWORD srcwidth
, DWORD dstwidth
,
1341 int left
, int *colors
,
1344 unsigned int x
= 0, width
= min(srcwidth
, dstwidth
);
1345 int y
= lines
- 1, c
, length
;
1346 const BYTE
*begin
= bits
;
1351 if (length
) { /* encoded */
1354 if (x
>= (left
+ width
)) break;
1355 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1357 if (!length
--) break;
1358 if (x
>= (left
+ width
)) break;
1359 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1379 default: /* absolute */
1382 if (x
>= left
&& x
< (left
+ width
))
1383 XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1385 if (!length
--) break;
1386 if (x
>= left
&& x
< (left
+ width
))
1387 XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1390 if ((bits
- begin
) & 1)
1399 /***********************************************************************
1400 * X11DRV_DIB_SetImageBits_8
1402 * SetDIBits for an 8-bit deep DIB.
1404 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1405 DWORD srcwidth
, DWORD dstwidth
, int left
,
1406 const int *colors
, XImage
*bmpImage
,
1410 int h
, width
= min(srcwidth
, dstwidth
);
1411 const BYTE
* srcbyte
;
1417 srcbits
= srcbits
+ linebytes
* (lines
-1);
1418 linebytes
= -linebytes
;
1423 switch (bmpImage
->depth
) {
1426 #if defined(__i386__) && defined(__GNUC__)
1427 /* Some X servers might have 32 bit/ 16bit deep pixel */
1428 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1429 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1431 dstbits
=(BYTE
*)bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1432 /* FIXME: Does this really handle all these cases correctly? */
1433 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1434 for (h
= lines
; h
--; ) {
1435 int _cl1
,_cl2
; /* temp outputs for asm below */
1436 /* Borrowed from DirectDraw */
1437 __asm__
__volatile__(
1442 " movw (%%edx,%%eax,4),%%ax\n"
1444 " xor %%eax,%%eax\n"
1446 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1451 :"eax", "cc", "memory"
1453 srcbyte
= (srcbits
+= linebytes
);
1454 dstbits
-= bmpImage
->bytes_per_line
;
1462 #if defined(__i386__) && defined(__GNUC__)
1463 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1464 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1466 dstbits
=(BYTE
*)bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1467 /* FIXME: Does this really handle both cases correctly? */
1468 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1469 for (h
= lines
; h
--; ) {
1470 int _cl1
,_cl2
; /* temp outputs for asm below */
1471 /* Borrowed from DirectDraw */
1472 __asm__
__volatile__(
1477 " movl (%%edx,%%eax,4),%%eax\n"
1479 " xor %%eax,%%eax\n"
1481 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1486 :"eax", "cc", "memory"
1488 srcbyte
= (srcbits
+= linebytes
);
1489 dstbits
-= bmpImage
->bytes_per_line
;
1496 break; /* use slow generic case below */
1499 /* ==== pal 8 dib -> any bmp format ==== */
1500 for (h
=lines
-1; h
>=0; h
--) {
1501 for (x
=left
; x
<width
+left
; x
++) {
1502 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1504 srcbyte
= (srcbits
+= linebytes
);
1508 /***********************************************************************
1509 * X11DRV_DIB_GetImageBits_8
1511 * GetDIBits for an 8-bit deep DIB.
1513 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1514 DWORD srcwidth
, DWORD dstwidth
,
1515 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1516 XImage
*bmpImage
, DWORD linebytes
)
1519 int h
, width
= min(srcwidth
, dstwidth
);
1525 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1526 linebytes
= -linebytes
;
1531 * This condition is true when GetImageBits has been called by
1532 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1533 * 256 colormaps, so we'll just use it for GetDIBits calls.
1534 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1536 if (!srccolors
) goto updatesection
;
1538 switch (bmpImage
->depth
) {
1541 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1544 /* ==== pal 1 bmp -> pal 8 dib ==== */
1545 /* ==== pal 4 bmp -> pal 8 dib ==== */
1546 for (h
=lines
-1; h
>=0; h
--) {
1548 for (x
=0; x
<width
; x
++) {
1549 PALETTEENTRY srcval
;
1550 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1551 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1556 dstbits
+= linebytes
;
1564 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1566 /* ==== pal 8 bmp -> pal 8 dib ==== */
1567 const void* srcbits
;
1568 const BYTE
* srcpixel
;
1570 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1571 for (h
=0; h
<lines
; h
++) {
1574 for (x
= 0; x
< width
; x
++) {
1575 PALETTEENTRY srcval
;
1576 srcval
=srccolors
[(int)*srcpixel
++];
1577 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1582 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1583 dstbits
+= linebytes
;
1593 const void* srcbits
;
1594 const WORD
* srcpixel
;
1597 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1599 if (bmpImage
->green_mask
==0x03e0) {
1600 if (bmpImage
->red_mask
==0x7c00) {
1601 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1602 for (h
=0; h
<lines
; h
++) {
1605 for (x
=0; x
<width
; x
++) {
1608 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1610 ((srcval
>> 7) & 0xf8) | /* r */
1611 ((srcval
>> 12) & 0x07),
1612 ((srcval
>> 2) & 0xf8) | /* g */
1613 ((srcval
>> 7) & 0x07),
1614 ((srcval
<< 3) & 0xf8) | /* b */
1615 ((srcval
>> 2) & 0x07) );
1617 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1618 dstbits
+= linebytes
;
1620 } else if (bmpImage
->blue_mask
==0x7c00) {
1621 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1622 for (h
=0; h
<lines
; h
++) {
1625 for (x
=0; x
<width
; x
++) {
1628 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1630 ((srcval
<< 3) & 0xf8) | /* r */
1631 ((srcval
>> 2) & 0x07),
1632 ((srcval
>> 2) & 0xf8) | /* g */
1633 ((srcval
>> 7) & 0x07),
1634 ((srcval
>> 7) & 0xf8) | /* b */
1635 ((srcval
>> 12) & 0x07) );
1637 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1638 dstbits
+= linebytes
;
1643 } else if (bmpImage
->green_mask
==0x07e0) {
1644 if (bmpImage
->red_mask
==0xf800) {
1645 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1646 for (h
=0; h
<lines
; h
++) {
1649 for (x
=0; x
<width
; x
++) {
1652 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1654 ((srcval
>> 8) & 0xf8) | /* r */
1655 ((srcval
>> 13) & 0x07),
1656 ((srcval
>> 3) & 0xfc) | /* g */
1657 ((srcval
>> 9) & 0x03),
1658 ((srcval
<< 3) & 0xf8) | /* b */
1659 ((srcval
>> 2) & 0x07) );
1661 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1662 dstbits
+= linebytes
;
1664 } else if (bmpImage
->blue_mask
==0xf800) {
1665 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1666 for (h
=0; h
<lines
; h
++) {
1669 for (x
=0; x
<width
; x
++) {
1672 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1674 ((srcval
<< 3) & 0xf8) | /* r */
1675 ((srcval
>> 2) & 0x07),
1676 ((srcval
>> 3) & 0xfc) | /* g */
1677 ((srcval
>> 9) & 0x03),
1678 ((srcval
>> 8) & 0xf8) | /* b */
1679 ((srcval
>> 13) & 0x07) );
1681 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1682 dstbits
+= linebytes
;
1696 const void* srcbits
;
1697 const BYTE
*srcbyte
;
1699 int bytes_per_pixel
;
1701 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1702 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1704 if (bmpImage
->green_mask
!=0x00ff00 ||
1705 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1707 } else if (bmpImage
->blue_mask
==0xff) {
1708 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1709 for (h
=0; h
<lines
; h
++) {
1712 for (x
=0; x
<width
; x
++) {
1713 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1718 srcbyte
+=bytes_per_pixel
;
1720 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1721 dstbits
+= linebytes
;
1724 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1725 for (h
=0; h
<lines
; h
++) {
1728 for (x
=0; x
<width
; x
++) {
1729 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1734 srcbyte
+=bytes_per_pixel
;
1736 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1737 dstbits
+= linebytes
;
1745 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1746 bmpImage
->depth
, bmpImage
->red_mask
,
1747 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1749 /* ==== any bmp format -> pal 8 dib ==== */
1750 for (h
=lines
-1; h
>=0; h
--) {
1752 for (x
=0; x
<width
; x
++) {
1753 *dstbyte
=X11DRV_DIB_MapColor
1755 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1758 dstbits
+= linebytes
;
1764 /***********************************************************************
1765 * X11DRV_DIB_SetImageBits_RLE8
1767 * SetDIBits for an 8-bit deep compressed DIB.
1769 * This function rewritten 941113 by James Youngman. WINE blew out when I
1770 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1772 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1773 * 'End of bitmap' escape code. This code is very much laxer in what it
1774 * allows to end the expansion. Possibly too lax. See the note by
1775 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1776 * bitmap should end with RleEnd, but on the other hand, software exists
1777 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1780 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1781 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1784 static void X11DRV_DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
,
1785 DWORD srcwidth
, DWORD dstwidth
,
1786 int left
, int *colors
,
1789 unsigned int x
; /* X-position on each line. Increases. */
1790 int y
; /* Line #. Starts at lines-1, decreases */
1791 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
1792 BYTE length
; /* The length pf a run */
1793 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
1796 * Note that the bitmap data is stored by Windows starting at the
1797 * bottom line of the bitmap and going upwards. Within each line,
1798 * the data is stored left-to-right. That's the reason why line
1799 * goes from lines-1 to 0. [JAY]
1809 * If the length byte is not zero (which is the escape value),
1810 * We have a run of length pixels all the same colour. The colour
1811 * index is stored next.
1813 * If the length byte is zero, we need to read the next byte to
1814 * know what to do. [JAY]
1819 * [Run-Length] Encoded mode
1821 int color
= colors
[*pIn
++];
1822 while (length
-- && x
< (left
+ dstwidth
)) {
1823 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1830 * Escape codes (may be an absolute sequence though)
1832 escape_code
= (*pIn
++);
1841 /* Not all RLE8 bitmaps end with this code. For
1842 * example, Paint Shop Pro produces some that don't.
1843 * That's (I think) what caused the previous
1844 * implementation to fail. [JAY]
1853 default: /* switch to absolute mode */
1854 length
= escape_code
;
1857 int color
= colors
[*pIn
++];
1858 if (x
>= (left
+ dstwidth
))
1863 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1867 * If you think for a moment you'll realise that the
1868 * only time we could ever possibly read an odd
1869 * number of bytes is when there is a 0x00 (escape),
1870 * a value >0x02 (absolute mode) and then an odd-
1871 * length run. Therefore this is the only place we
1872 * need to worry about it. Everywhere else the
1873 * bytes are always read in pairs. [JAY]
1875 if (escape_code
& 1) pIn
++; /* Throw away the pad byte. */
1877 } /* switch (escape_code) : Escape sequence */
1883 /***********************************************************************
1884 * X11DRV_DIB_SetImageBits_16
1886 * SetDIBits for a 16-bit deep DIB.
1888 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1889 DWORD srcwidth
, DWORD dstwidth
, int left
,
1890 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1891 XImage
*bmpImage
, DWORD linebytes
)
1894 int h
, width
= min(srcwidth
, dstwidth
);
1895 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1900 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1901 linebytes
= -linebytes
;
1904 switch (bmpImage
->depth
)
1911 srcbits
=srcbits
+left
*2;
1912 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1914 if (bmpImage
->green_mask
==0x03e0) {
1915 if (gSrc
==bmpImage
->green_mask
) {
1916 if (rSrc
==bmpImage
->red_mask
) {
1917 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1918 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1919 convs
->Convert_5x5_asis
1922 dstbits
,-bmpImage
->bytes_per_line
);
1923 } else if (rSrc
==bmpImage
->blue_mask
) {
1924 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1925 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1926 convs
->Convert_555_reverse
1929 dstbits
,-bmpImage
->bytes_per_line
);
1932 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1933 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1934 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1935 convs
->Convert_565_to_555_asis
1938 dstbits
,-bmpImage
->bytes_per_line
);
1940 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1941 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1942 convs
->Convert_565_to_555_reverse
1945 dstbits
,-bmpImage
->bytes_per_line
);
1948 } else if (bmpImage
->green_mask
==0x07e0) {
1949 if (gSrc
==bmpImage
->green_mask
) {
1950 if (rSrc
==bmpImage
->red_mask
) {
1951 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
1952 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
1953 convs
->Convert_5x5_asis
1956 dstbits
,-bmpImage
->bytes_per_line
);
1958 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
1959 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
1960 convs
->Convert_565_reverse
1963 dstbits
,-bmpImage
->bytes_per_line
);
1966 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1967 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
1968 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
1969 convs
->Convert_555_to_565_asis
1972 dstbits
,-bmpImage
->bytes_per_line
);
1974 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
1975 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
1976 convs
->Convert_555_to_565_reverse
1979 dstbits
,-bmpImage
->bytes_per_line
);
1989 if (bmpImage
->bits_per_pixel
==24) {
1992 srcbits
=srcbits
+left
*2;
1993 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
1995 if (bmpImage
->green_mask
!=0x00ff00 ||
1996 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1998 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
1999 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2001 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2002 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2003 convs
->Convert_555_to_888_asis
2006 dstbits
,-bmpImage
->bytes_per_line
);
2008 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2009 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2010 convs
->Convert_565_to_888_asis
2013 dstbits
,-bmpImage
->bytes_per_line
);
2017 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2018 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2019 convs
->Convert_555_to_888_reverse
2022 dstbits
,-bmpImage
->bytes_per_line
);
2024 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2025 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2026 convs
->Convert_565_to_888_reverse
2029 dstbits
,-bmpImage
->bytes_per_line
);
2040 srcbits
=srcbits
+left
*2;
2041 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2043 if (bmpImage
->green_mask
!=0x00ff00 ||
2044 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2046 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2047 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2049 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2050 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2051 convs
->Convert_555_to_0888_asis
2054 dstbits
,-bmpImage
->bytes_per_line
);
2056 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2057 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2058 convs
->Convert_565_to_0888_asis
2061 dstbits
,-bmpImage
->bytes_per_line
);
2065 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2066 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2067 convs
->Convert_555_to_0888_reverse
2070 dstbits
,-bmpImage
->bytes_per_line
);
2072 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2073 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2074 convs
->Convert_565_to_0888_reverse
2077 dstbits
,-bmpImage
->bytes_per_line
);
2085 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2086 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2087 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2093 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2094 const WORD
* srcpixel
;
2095 int rShift1
,gShift1
,bShift1
;
2096 int rShift2
,gShift2
,bShift2
;
2099 /* Set color scaling values */
2100 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
2101 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
2102 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
2107 /* Green has 5 bits, like the others */
2111 /* Green has 6 bits, not 5. Compensate. */
2120 /* We could split it into four separate cases to optimize
2121 * but it is probably not worth it.
2123 for (h
=lines
-1; h
>=0; h
--) {
2124 srcpixel
=(const WORD
*)srcbits
;
2125 for (x
=left
; x
<width
+left
; x
++) {
2127 BYTE red
,green
,blue
;
2128 srcval
=*srcpixel
++ << 16;
2129 red
= ((srcval
>> rShift1
) & 0xf8) |
2130 ((srcval
>> rShift2
) & 0x07);
2131 green
=((srcval
>> gShift1
) & gMask1
) |
2132 ((srcval
>> gShift2
) & gMask2
);
2133 blue
= ((srcval
>> bShift1
) & 0xf8) |
2134 ((srcval
>> bShift2
) & 0x07);
2135 XPutPixel(bmpImage
, x
, h
,
2136 X11DRV_PALETTE_ToPhysical
2137 (physDev
, RGB(red
,green
,blue
)));
2139 srcbits
+= linebytes
;
2147 /***********************************************************************
2148 * X11DRV_DIB_GetImageBits_16
2150 * GetDIBits for an 16-bit deep DIB.
2152 static void X11DRV_DIB_GetImageBits_16( int lines
, BYTE
*dstbits
,
2153 DWORD dstwidth
, DWORD srcwidth
,
2154 PALETTEENTRY
*srccolors
,
2155 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2156 XImage
*bmpImage
, DWORD dibpitch
)
2159 int h
, width
= min(srcwidth
, dstwidth
);
2160 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2162 DWORD linebytes
= dibpitch
;
2167 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
2168 linebytes
= -linebytes
;
2171 switch (bmpImage
->depth
)
2176 const char* srcbits
;
2178 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2180 if (bmpImage
->green_mask
==0x03e0) {
2181 if (gDst
==bmpImage
->green_mask
) {
2182 if (rDst
==bmpImage
->red_mask
) {
2183 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2184 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2185 convs
->Convert_5x5_asis
2187 srcbits
,-bmpImage
->bytes_per_line
,
2190 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2191 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2192 convs
->Convert_555_reverse
2194 srcbits
,-bmpImage
->bytes_per_line
,
2198 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2199 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2200 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2201 convs
->Convert_555_to_565_asis
2203 srcbits
,-bmpImage
->bytes_per_line
,
2206 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2207 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2208 convs
->Convert_555_to_565_reverse
2210 srcbits
,-bmpImage
->bytes_per_line
,
2214 } else if (bmpImage
->green_mask
==0x07e0) {
2215 if (gDst
==bmpImage
->green_mask
) {
2216 if (rDst
== bmpImage
->red_mask
) {
2217 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2218 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2219 convs
->Convert_5x5_asis
2221 srcbits
,-bmpImage
->bytes_per_line
,
2224 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2225 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2226 convs
->Convert_565_reverse
2228 srcbits
,-bmpImage
->bytes_per_line
,
2232 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2233 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2234 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2235 convs
->Convert_565_to_555_asis
2237 srcbits
,-bmpImage
->bytes_per_line
,
2240 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2241 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2242 convs
->Convert_565_to_555_reverse
2244 srcbits
,-bmpImage
->bytes_per_line
,
2255 if (bmpImage
->bits_per_pixel
== 24) {
2256 const char* srcbits
;
2258 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2260 if (bmpImage
->green_mask
!=0x00ff00 ||
2261 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2263 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2264 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2266 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2267 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2268 convs
->Convert_888_to_555_asis
2270 srcbits
,-bmpImage
->bytes_per_line
,
2273 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2274 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2275 convs
->Convert_888_to_565_asis
2277 srcbits
,-bmpImage
->bytes_per_line
,
2282 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2283 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2284 convs
->Convert_888_to_555_reverse
2286 srcbits
,-bmpImage
->bytes_per_line
,
2289 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2290 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2291 convs
->Convert_888_to_565_reverse
2293 srcbits
,-bmpImage
->bytes_per_line
,
2303 const char* srcbits
;
2305 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2307 if (bmpImage
->green_mask
!=0x00ff00 ||
2308 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2310 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2311 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2313 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2314 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2315 convs
->Convert_0888_to_555_asis
2317 srcbits
,-bmpImage
->bytes_per_line
,
2320 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2321 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2322 convs
->Convert_0888_to_565_asis
2324 srcbits
,-bmpImage
->bytes_per_line
,
2329 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2330 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2331 convs
->Convert_0888_to_555_reverse
2333 srcbits
,-bmpImage
->bytes_per_line
,
2336 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2337 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2338 convs
->Convert_0888_to_565_reverse
2340 srcbits
,-bmpImage
->bytes_per_line
,
2349 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2351 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2352 int rShift
,gShift
,bShift
;
2355 /* Shift everything 16 bits left so that all shifts are >0,
2356 * even for BGR DIBs. Then a single >> 16 will bring everything
2359 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2360 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2361 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2363 /* 6 bits for the green */
2369 for (h
= lines
- 1; h
>= 0; h
--) {
2370 dstpixel
=(LPWORD
)dstbits
;
2371 for (x
= 0; x
< width
; x
++) {
2372 PALETTEENTRY srcval
;
2374 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2375 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2376 ((srcval
.peGreen
<< gShift
) & gDst
) |
2377 ((srcval
.peBlue
<< bShift
) & bDst
);
2378 *dstpixel
++=dstval
>> 16;
2380 dstbits
+= linebytes
;
2388 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2390 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2391 int rShift
,gShift
,bShift
;
2392 const BYTE
* srcbits
;
2393 const BYTE
* srcpixel
;
2396 /* Shift everything 16 bits left so that all shifts are >0,
2397 * even for BGR DIBs. Then a single >> 16 will bring everything
2400 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2401 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2402 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2404 /* 6 bits for the green */
2410 srcbits
=(BYTE
*)bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2411 for (h
=0; h
<lines
; h
++) {
2413 dstpixel
=(LPWORD
)dstbits
;
2414 for (x
= 0; x
< width
; x
++) {
2415 PALETTEENTRY srcval
;
2417 srcval
=srccolors
[(int)*srcpixel
++];
2418 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2419 ((srcval
.peGreen
<< gShift
) & gDst
) |
2420 ((srcval
.peBlue
<< bShift
) & bDst
);
2421 *dstpixel
++=dstval
>> 16;
2423 srcbits
-= bmpImage
->bytes_per_line
;
2424 dstbits
+= linebytes
;
2434 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2435 int rShift
,gShift
,bShift
;
2438 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2439 bmpImage
->depth
, bmpImage
->red_mask
,
2440 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2443 /* Shift everything 16 bits left so that all shifts are >0,
2444 * even for BGR DIBs. Then a single >> 16 will bring everything
2447 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2448 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2449 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2451 /* 6 bits for the green */
2457 for (h
= lines
- 1; h
>= 0; h
--) {
2458 dstpixel
=(LPWORD
)dstbits
;
2459 for (x
= 0; x
< width
; x
++) {
2462 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
2463 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2464 ((GetGValue(srcval
) << gShift
) & gDst
) |
2465 ((GetBValue(srcval
) << bShift
) & bDst
);
2466 *dstpixel
++=dstval
>> 16;
2468 dstbits
+= linebytes
;
2476 /***********************************************************************
2477 * X11DRV_DIB_SetImageBits_24
2479 * SetDIBits for a 24-bit deep DIB.
2481 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2482 DWORD srcwidth
, DWORD dstwidth
, int left
,
2483 X11DRV_PDEVICE
*physDev
,
2484 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2485 XImage
*bmpImage
, DWORD linebytes
)
2488 int h
, width
= min(srcwidth
, dstwidth
);
2489 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2494 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2495 linebytes
= -linebytes
;
2498 switch (bmpImage
->depth
)
2501 if (bmpImage
->bits_per_pixel
==24) {
2504 srcbits
=srcbits
+left
*3;
2505 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2507 if (bmpImage
->green_mask
!=0x00ff00 ||
2508 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2510 } else if (rSrc
==bmpImage
->red_mask
) {
2511 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2512 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2513 convs
->Convert_888_asis
2516 dstbits
,-bmpImage
->bytes_per_line
);
2518 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2519 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2520 convs
->Convert_888_reverse
2523 dstbits
,-bmpImage
->bytes_per_line
);
2533 srcbits
=srcbits
+left
*3;
2534 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2536 if (bmpImage
->green_mask
!=0x00ff00 ||
2537 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2539 } else if (rSrc
==bmpImage
->red_mask
) {
2540 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2541 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2542 convs
->Convert_888_to_0888_asis
2545 dstbits
,-bmpImage
->bytes_per_line
);
2547 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2548 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2549 convs
->Convert_888_to_0888_reverse
2552 dstbits
,-bmpImage
->bytes_per_line
);
2562 srcbits
=srcbits
+left
*3;
2563 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2565 if (bmpImage
->green_mask
==0x03e0) {
2566 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2567 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2568 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2569 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2570 convs
->Convert_888_to_555_asis
2573 dstbits
,-bmpImage
->bytes_per_line
);
2574 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2575 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2576 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2577 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2578 convs
->Convert_888_to_555_reverse
2581 dstbits
,-bmpImage
->bytes_per_line
);
2585 } else if (bmpImage
->green_mask
==0x07e0) {
2586 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2587 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2588 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2589 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2590 convs
->Convert_888_to_565_asis
2593 dstbits
,-bmpImage
->bytes_per_line
);
2594 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2595 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2596 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2597 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2598 convs
->Convert_888_to_565_reverse
2601 dstbits
,-bmpImage
->bytes_per_line
);
2613 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2614 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2615 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2621 /* ==== rgb 888 dib -> any bmp bormat ==== */
2622 const BYTE
* srcbyte
;
2624 /* Windows only supports one 24bpp DIB format: RGB888 */
2626 for (h
= lines
- 1; h
>= 0; h
--) {
2627 srcbyte
=(const BYTE
*)srcbits
;
2628 for (x
= left
; x
< width
+left
; x
++) {
2629 XPutPixel(bmpImage
, x
, h
,
2630 X11DRV_PALETTE_ToPhysical
2631 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2634 srcbits
+= linebytes
;
2642 /***********************************************************************
2643 * X11DRV_DIB_GetImageBits_24
2645 * GetDIBits for an 24-bit deep DIB.
2647 static void X11DRV_DIB_GetImageBits_24( int lines
, BYTE
*dstbits
,
2648 DWORD dstwidth
, DWORD srcwidth
,
2649 PALETTEENTRY
*srccolors
,
2650 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2651 XImage
*bmpImage
, DWORD linebytes
)
2654 int h
, width
= min(srcwidth
, dstwidth
);
2655 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2660 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2661 linebytes
= -linebytes
;
2664 switch (bmpImage
->depth
)
2667 if (bmpImage
->bits_per_pixel
==24) {
2668 const char* srcbits
;
2670 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2672 if (bmpImage
->green_mask
!=0x00ff00 ||
2673 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2675 } else if (rDst
==bmpImage
->red_mask
) {
2676 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2677 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2678 convs
->Convert_888_asis
2680 srcbits
,-bmpImage
->bytes_per_line
,
2683 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2684 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2685 convs
->Convert_888_reverse
2687 srcbits
,-bmpImage
->bytes_per_line
,
2696 const char* srcbits
;
2698 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2700 if (bmpImage
->green_mask
!=0x00ff00 ||
2701 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2703 } else if (rDst
==bmpImage
->red_mask
) {
2704 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2705 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2706 convs
->Convert_0888_to_888_asis
2708 srcbits
,-bmpImage
->bytes_per_line
,
2711 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2712 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2713 convs
->Convert_0888_to_888_reverse
2715 srcbits
,-bmpImage
->bytes_per_line
,
2724 const char* srcbits
;
2726 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2728 if (bmpImage
->green_mask
==0x03e0) {
2729 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2730 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2731 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2732 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2733 convs
->Convert_555_to_888_asis
2735 srcbits
,-bmpImage
->bytes_per_line
,
2737 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2738 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2739 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2740 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2741 convs
->Convert_555_to_888_reverse
2743 srcbits
,-bmpImage
->bytes_per_line
,
2748 } else if (bmpImage
->green_mask
==0x07e0) {
2749 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2750 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2751 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2752 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2753 convs
->Convert_565_to_888_asis
2755 srcbits
,-bmpImage
->bytes_per_line
,
2757 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2758 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2759 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2760 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2761 convs
->Convert_565_to_888_reverse
2763 srcbits
,-bmpImage
->bytes_per_line
,
2776 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2778 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2781 /* Windows only supports one 24bpp DIB format: rgb 888 */
2782 for (h
= lines
- 1; h
>= 0; h
--) {
2784 for (x
= 0; x
< width
; x
++) {
2785 PALETTEENTRY srcval
;
2786 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2787 dstbyte
[0]=srcval
.peBlue
;
2788 dstbyte
[1]=srcval
.peGreen
;
2789 dstbyte
[2]=srcval
.peRed
;
2792 dstbits
+= linebytes
;
2800 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2802 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2803 const void* srcbits
;
2804 const BYTE
* srcpixel
;
2807 /* Windows only supports one 24bpp DIB format: rgb 888 */
2808 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2809 for (h
= lines
- 1; h
>= 0; h
--) {
2812 for (x
= 0; x
< width
; x
++ ) {
2813 PALETTEENTRY srcval
;
2814 srcval
=srccolors
[(int)*srcpixel
++];
2815 dstbyte
[0]=srcval
.peBlue
;
2816 dstbyte
[1]=srcval
.peGreen
;
2817 dstbyte
[2]=srcval
.peRed
;
2820 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2821 dstbits
+= linebytes
;
2831 /* ==== any bmp format -> 888 dib ==== */
2834 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2835 bmpImage
->depth
, bmpImage
->red_mask
,
2836 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2839 /* Windows only supports one 24bpp DIB format: rgb 888 */
2840 for (h
= lines
- 1; h
>= 0; h
--) {
2842 for (x
= 0; x
< width
; x
++) {
2843 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2844 (XGetPixel( bmpImage
, x
, h
));
2845 dstbyte
[0]=GetBValue(srcval
);
2846 dstbyte
[1]=GetGValue(srcval
);
2847 dstbyte
[2]=GetRValue(srcval
);
2850 dstbits
+= linebytes
;
2858 /***********************************************************************
2859 * X11DRV_DIB_SetImageBits_32
2861 * SetDIBits for a 32-bit deep DIB.
2863 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2864 DWORD srcwidth
, DWORD dstwidth
, int left
,
2865 X11DRV_PDEVICE
*physDev
,
2866 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2872 int h
, width
= min(srcwidth
, dstwidth
);
2873 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2878 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2879 linebytes
= -linebytes
;
2882 ptr
= (const DWORD
*) srcbits
+ left
;
2884 switch (bmpImage
->depth
)
2887 if (bmpImage
->bits_per_pixel
==24) {
2890 srcbits
=srcbits
+left
*4;
2891 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2893 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2894 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2895 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2896 convs
->Convert_0888_to_888_asis
2899 dstbits
,-bmpImage
->bytes_per_line
);
2900 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2901 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2903 /* the tests below assume sane bmpImage masks */
2904 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2905 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2906 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2907 convs
->Convert_0888_to_888_reverse
2910 dstbits
,-bmpImage
->bytes_per_line
);
2911 } else if (bmpImage
->blue_mask
==0xff) {
2912 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2913 convs
->Convert_any0888_to_rgb888
2917 dstbits
,-bmpImage
->bytes_per_line
);
2919 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2920 convs
->Convert_any0888_to_bgr888
2924 dstbits
,-bmpImage
->bytes_per_line
);
2934 srcbits
=srcbits
+left
*4;
2935 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2937 if (gSrc
==bmpImage
->green_mask
) {
2938 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2939 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2940 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2941 convs
->Convert_0888_asis
2944 dstbits
,-bmpImage
->bytes_per_line
);
2945 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2946 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2948 /* the tests below assume sane bmpImage masks */
2949 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
2950 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2951 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2952 convs
->Convert_0888_reverse
2955 dstbits
,-bmpImage
->bytes_per_line
);
2957 /* ==== any 0888 dib -> any 0888 bmp ==== */
2958 convs
->Convert_0888_any
2962 dstbits
,-bmpImage
->bytes_per_line
,
2963 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2965 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2966 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2968 /* the tests below assume sane bmpImage masks */
2970 /* ==== any 0888 dib -> any 0888 bmp ==== */
2971 convs
->Convert_0888_any
2975 dstbits
,-bmpImage
->bytes_per_line
,
2976 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2986 srcbits
=srcbits
+left
*4;
2987 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2989 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
2990 if (bmpImage
->green_mask
==0x03e0) {
2991 if (bmpImage
->red_mask
==0x7f00) {
2992 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
2993 convs
->Convert_0888_to_555_asis
2996 dstbits
,-bmpImage
->bytes_per_line
);
2997 } else if (bmpImage
->blue_mask
==0x7f00) {
2998 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
2999 convs
->Convert_0888_to_555_reverse
3002 dstbits
,-bmpImage
->bytes_per_line
);
3006 } else if (bmpImage
->green_mask
==0x07e0) {
3007 if (bmpImage
->red_mask
==0xf800) {
3008 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3009 convs
->Convert_0888_to_565_asis
3012 dstbits
,-bmpImage
->bytes_per_line
);
3013 } else if (bmpImage
->blue_mask
==0xf800) {
3014 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3015 convs
->Convert_0888_to_565_reverse
3018 dstbits
,-bmpImage
->bytes_per_line
);
3025 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
3026 if (bmpImage
->green_mask
==0x03e0) {
3027 if (bmpImage
->blue_mask
==0x7f00) {
3028 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3029 convs
->Convert_0888_to_555_asis
3032 dstbits
,-bmpImage
->bytes_per_line
);
3033 } else if (bmpImage
->red_mask
==0x7f00) {
3034 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3035 convs
->Convert_0888_to_555_reverse
3038 dstbits
,-bmpImage
->bytes_per_line
);
3042 } else if (bmpImage
->green_mask
==0x07e0) {
3043 if (bmpImage
->blue_mask
==0xf800) {
3044 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3045 convs
->Convert_0888_to_565_asis
3048 dstbits
,-bmpImage
->bytes_per_line
);
3049 } else if (bmpImage
->red_mask
==0xf800) {
3050 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3051 convs
->Convert_0888_to_565_reverse
3054 dstbits
,-bmpImage
->bytes_per_line
);
3062 if (bmpImage
->green_mask
==0x03e0 &&
3063 (bmpImage
->red_mask
==0x7f00 ||
3064 bmpImage
->blue_mask
==0x7f00)) {
3065 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3066 convs
->Convert_any0888_to_5x5
3070 dstbits
,-bmpImage
->bytes_per_line
,
3071 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3072 } else if (bmpImage
->green_mask
==0x07e0 &&
3073 (bmpImage
->red_mask
==0xf800 ||
3074 bmpImage
->blue_mask
==0xf800)) {
3075 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3076 convs
->Convert_any0888_to_5x5
3080 dstbits
,-bmpImage
->bytes_per_line
,
3081 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3091 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3092 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
3093 bmpImage
->green_mask
, bmpImage
->blue_mask
);
3099 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3100 const DWORD
* srcpixel
;
3101 int rShift
,gShift
,bShift
;
3103 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
3104 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
3105 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
3107 for (h
= lines
- 1; h
>= 0; h
--) {
3108 srcpixel
=(const DWORD
*)srcbits
;
3109 for (x
= left
; x
< width
+left
; x
++) {
3111 BYTE red
,green
,blue
;
3112 srcvalue
=*srcpixel
++;
3113 red
= (srcvalue
>> rShift
) & 0xff;
3114 green
=(srcvalue
>> gShift
) & 0xff;
3115 blue
= (srcvalue
>> bShift
) & 0xff;
3116 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
3117 (physDev
, RGB(red
,green
,blue
)));
3119 srcbits
+= linebytes
;
3127 /***********************************************************************
3128 * X11DRV_DIB_GetImageBits_32
3130 * GetDIBits for an 32-bit deep DIB.
3132 static void X11DRV_DIB_GetImageBits_32( int lines
, BYTE
*dstbits
,
3133 DWORD dstwidth
, DWORD srcwidth
,
3134 PALETTEENTRY
*srccolors
,
3135 DWORD rDst
, DWORD gDst
, DWORD bDst
,
3136 XImage
*bmpImage
, DWORD linebytes
)
3139 int h
, width
= min(srcwidth
, dstwidth
);
3141 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
3146 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
3147 linebytes
= -linebytes
;
3152 switch (bmpImage
->depth
)
3155 if (bmpImage
->bits_per_pixel
==24) {
3156 const void* srcbits
;
3158 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3160 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
3161 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3162 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3163 convs
->Convert_888_to_0888_asis
3165 srcbits
,-bmpImage
->bytes_per_line
,
3167 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3168 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3170 /* the tests below assume sane bmpImage masks */
3171 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
3172 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3173 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3174 convs
->Convert_888_to_0888_reverse
3176 srcbits
,-bmpImage
->bytes_per_line
,
3178 } else if (bmpImage
->blue_mask
==0xff) {
3179 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3180 convs
->Convert_rgb888_to_any0888
3182 srcbits
,-bmpImage
->bytes_per_line
,
3186 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3187 convs
->Convert_bgr888_to_any0888
3189 srcbits
,-bmpImage
->bytes_per_line
,
3199 const char* srcbits
;
3201 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3203 if (gDst
==bmpImage
->green_mask
) {
3204 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
3205 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3206 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3207 convs
->Convert_0888_asis
3209 srcbits
,-bmpImage
->bytes_per_line
,
3211 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3212 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3214 /* the tests below assume sane bmpImage masks */
3215 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
3216 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3217 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3218 convs
->Convert_0888_reverse
3220 srcbits
,-bmpImage
->bytes_per_line
,
3223 /* ==== any 0888 bmp -> any 0888 dib ==== */
3224 convs
->Convert_0888_any
3226 srcbits
,-bmpImage
->bytes_per_line
,
3227 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3231 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3232 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3234 /* the tests below assume sane bmpImage masks */
3236 /* ==== any 0888 bmp -> any 0888 dib ==== */
3237 convs
->Convert_0888_any
3239 srcbits
,-bmpImage
->bytes_per_line
,
3240 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3250 const char* srcbits
;
3252 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3254 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
3255 if (bmpImage
->green_mask
==0x03e0) {
3256 if (bmpImage
->red_mask
==0x7f00) {
3257 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3258 convs
->Convert_555_to_0888_asis
3260 srcbits
,-bmpImage
->bytes_per_line
,
3262 } else if (bmpImage
->blue_mask
==0x7f00) {
3263 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3264 convs
->Convert_555_to_0888_reverse
3266 srcbits
,-bmpImage
->bytes_per_line
,
3271 } else if (bmpImage
->green_mask
==0x07e0) {
3272 if (bmpImage
->red_mask
==0xf800) {
3273 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3274 convs
->Convert_565_to_0888_asis
3276 srcbits
,-bmpImage
->bytes_per_line
,
3278 } else if (bmpImage
->blue_mask
==0xf800) {
3279 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3280 convs
->Convert_565_to_0888_reverse
3282 srcbits
,-bmpImage
->bytes_per_line
,
3290 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
3291 if (bmpImage
->green_mask
==0x03e0) {
3292 if (bmpImage
->blue_mask
==0x7f00) {
3293 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3294 convs
->Convert_555_to_0888_asis
3296 srcbits
,-bmpImage
->bytes_per_line
,
3298 } else if (bmpImage
->red_mask
==0x7f00) {
3299 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3300 convs
->Convert_555_to_0888_reverse
3302 srcbits
,-bmpImage
->bytes_per_line
,
3307 } else if (bmpImage
->green_mask
==0x07e0) {
3308 if (bmpImage
->blue_mask
==0xf800) {
3309 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3310 convs
->Convert_565_to_0888_asis
3312 srcbits
,-bmpImage
->bytes_per_line
,
3314 } else if (bmpImage
->red_mask
==0xf800) {
3315 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3316 convs
->Convert_565_to_0888_reverse
3318 srcbits
,-bmpImage
->bytes_per_line
,
3327 if (bmpImage
->green_mask
==0x03e0 &&
3328 (bmpImage
->red_mask
==0x7f00 ||
3329 bmpImage
->blue_mask
==0x7f00)) {
3330 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3331 convs
->Convert_5x5_to_any0888
3333 srcbits
,-bmpImage
->bytes_per_line
,
3334 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3337 } else if (bmpImage
->green_mask
==0x07e0 &&
3338 (bmpImage
->red_mask
==0xf800 ||
3339 bmpImage
->blue_mask
==0xf800)) {
3340 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3341 convs
->Convert_5x5_to_any0888
3343 srcbits
,-bmpImage
->bytes_per_line
,
3344 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3356 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3358 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3359 int rShift
,gShift
,bShift
;
3362 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3363 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3364 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3365 for (h
= lines
- 1; h
>= 0; h
--) {
3366 dstpixel
=(DWORD
*)dstbits
;
3367 for (x
= 0; x
< width
; x
++) {
3368 PALETTEENTRY srcval
;
3369 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3370 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3371 (srcval
.peGreen
<< gShift
) |
3372 (srcval
.peBlue
<< bShift
);
3374 dstbits
+= linebytes
;
3382 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3384 /* ==== pal 8 bmp -> any 0888 dib ==== */
3385 int rShift
,gShift
,bShift
;
3386 const void* srcbits
;
3387 const BYTE
* srcpixel
;
3390 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3391 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3392 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3393 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3394 for (h
= lines
- 1; h
>= 0; h
--) {
3396 dstpixel
=(DWORD
*)dstbits
;
3397 for (x
= 0; x
< width
; x
++) {
3398 PALETTEENTRY srcval
;
3399 srcval
=srccolors
[(int)*srcpixel
++];
3400 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3401 (srcval
.peGreen
<< gShift
) |
3402 (srcval
.peBlue
<< bShift
);
3404 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3405 dstbits
+= linebytes
;
3415 /* ==== any bmp format -> any 0888 dib ==== */
3416 int rShift
,gShift
,bShift
;
3419 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3420 bmpImage
->depth
, bmpImage
->red_mask
,
3421 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3424 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3425 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3426 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3427 for (h
= lines
- 1; h
>= 0; h
--) {
3428 dstpixel
=(DWORD
*)dstbits
;
3429 for (x
= 0; x
< width
; x
++) {
3431 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
3432 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3433 (GetGValue(srcval
) << gShift
) |
3434 (GetBValue(srcval
) << bShift
);
3436 dstbits
+= linebytes
;
3443 static int XGetSubImageErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
3445 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
3448 /***********************************************************************
3449 * X11DRV_DIB_SetImageBits_GetSubImage
3451 * Helper for X11DRV_DIB_SetImageBits
3453 static void X11DRV_DIB_SetImageBits_GetSubImage(
3454 const X11DRV_DIB_IMAGEBITS_DESCR
*descr
, XImage
*bmpImage
)
3456 /* compressed bitmaps may contain gaps in them. So make a copy
3457 * of the existing pixels first */
3460 SetRect( &bmprc
, descr
->xDest
, descr
->yDest
,
3461 descr
->xDest
+ descr
->width
, descr
->yDest
+ descr
->height
);
3462 GetRgnBox( descr
->physDev
->region
, &rc
);
3463 /* convert from dc to drawable origin */
3464 OffsetRect( &rc
, descr
->physDev
->dc_rect
.left
, descr
->physDev
->dc_rect
.top
);
3465 /* clip visible rect with bitmap */
3466 if( IntersectRect( &rc
, &rc
, &bmprc
))
3468 X11DRV_expect_error( gdi_display
, XGetSubImageErrorHandler
, NULL
);
3469 XGetSubImage( gdi_display
, descr
->drawable
, rc
.left
, rc
.top
,
3470 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, AllPlanes
,
3472 descr
->xSrc
+ rc
.left
- bmprc
.left
,
3473 descr
->ySrc
+ rc
.top
- bmprc
.top
);
3474 X11DRV_check_error();
3478 /***********************************************************************
3479 * X11DRV_DIB_SetImageBits
3481 * Transfer the bits to an X image.
3482 * Helper function for SetDIBits() and SetDIBitsToDevice().
3484 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3486 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3491 bmpImage
= descr
->image
;
3493 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3494 descr
->infoWidth
, lines
, 32, 0 );
3495 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3496 if(bmpImage
->data
== NULL
) {
3497 ERR("Out of memory!\n");
3498 XDestroyImage( bmpImage
);
3499 wine_tsx11_unlock();
3503 wine_tsx11_unlock();
3505 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3506 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3507 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3508 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3509 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3511 /* Transfer the pixels */
3512 switch(descr
->infoBpp
)
3515 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3516 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3517 bmpImage
, descr
->dibpitch
);
3520 if (descr
->compression
) {
3521 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3522 X11DRV_DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
3523 descr
->infoWidth
, descr
->width
,
3524 descr
->xSrc
, (int *)(descr
->colorMap
),
3527 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3528 descr
->infoWidth
, descr
->width
,
3529 descr
->xSrc
, (int*)(descr
->colorMap
),
3530 bmpImage
, descr
->dibpitch
);
3533 if (descr
->compression
) {
3534 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3535 X11DRV_DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
3536 descr
->infoWidth
, descr
->width
,
3537 descr
->xSrc
, (int *)(descr
->colorMap
),
3540 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3541 descr
->infoWidth
, descr
->width
,
3542 descr
->xSrc
, (int *)(descr
->colorMap
),
3543 bmpImage
, descr
->dibpitch
);
3547 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3548 descr
->infoWidth
, descr
->width
,
3549 descr
->xSrc
, descr
->physDev
,
3550 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3551 bmpImage
, descr
->dibpitch
);
3554 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3555 descr
->infoWidth
, descr
->width
,
3556 descr
->xSrc
, descr
->physDev
,
3557 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3558 bmpImage
, descr
->dibpitch
);
3561 X11DRV_DIB_SetImageBits_32( descr
->lines
, descr
->bits
,
3562 descr
->infoWidth
, descr
->width
,
3563 descr
->xSrc
, descr
->physDev
,
3564 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3565 bmpImage
, descr
->dibpitch
);
3568 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3572 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3573 descr
->drawable
, descr
->gc
, bmpImage
,
3574 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3575 descr
->width
, descr
->height
);
3578 #ifdef HAVE_LIBXXSHM
3579 if (descr
->image
&& descr
->useShm
)
3581 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3582 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3583 descr
->width
, descr
->height
, FALSE
);
3584 XSync( gdi_display
, 0 );
3588 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3589 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3590 descr
->width
, descr
->height
);
3592 if (!descr
->image
) XDestroyImage( bmpImage
);
3593 wine_tsx11_unlock();
3597 /***********************************************************************
3598 * X11DRV_DIB_GetImageBits
3600 * Transfer the bits from an X image.
3602 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3604 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3609 bmpImage
= descr
->image
;
3611 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3612 descr
->infoWidth
, lines
, 32, 0 );
3613 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3614 if(bmpImage
->data
== NULL
) {
3615 ERR("Out of memory!\n");
3616 XDestroyImage( bmpImage
);
3617 wine_tsx11_unlock();
3622 #ifdef HAVE_LIBXXSHM
3624 /* We must not call XShmGetImage() with a bitmap which is bigger than the available area.
3625 If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */
3626 if((descr
->image
&& descr
->useShm
) && (bmpImage
->width
<= (descr
->width
- descr
->xSrc
))
3627 && (bmpImage
->height
<= (descr
->height
- descr
->ySrc
)))
3629 int saveRed
, saveGreen
, saveBlue
;
3631 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3632 gdi_display
, descr
->drawable
, bmpImage
,
3633 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3635 /* We must save and restore the bmpImage's masks in order
3636 * to preserve them across the call to XShmGetImage, which
3637 * decides to eleminate them since it doesn't happen to know
3638 * what the format of the image is supposed to be, even though
3640 saveRed
= bmpImage
->red_mask
;
3641 saveBlue
= bmpImage
->blue_mask
;
3642 saveGreen
= bmpImage
->green_mask
;
3644 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3645 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3647 bmpImage
->red_mask
= saveRed
;
3648 bmpImage
->blue_mask
= saveBlue
;
3649 bmpImage
->green_mask
= saveGreen
;
3652 #endif /* HAVE_LIBXXSHM */
3654 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3655 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3656 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3657 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3658 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3659 bmpImage
, descr
->xDest
, descr
->yDest
);
3661 wine_tsx11_unlock();
3663 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3664 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3665 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3666 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3667 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3668 /* Transfer the pixels */
3669 switch(descr
->infoBpp
)
3672 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3673 descr
->infoWidth
, descr
->width
,
3674 descr
->colorMap
, descr
->palentry
,
3675 bmpImage
, descr
->dibpitch
);
3679 if (descr
->compression
) {
3680 FIXME("Compression not yet supported!\n");
3681 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 4 ) * abs(descr
->lines
))
3684 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3685 descr
->infoWidth
, descr
->width
,
3686 descr
->colorMap
, descr
->palentry
,
3687 bmpImage
, descr
->dibpitch
);
3690 if (descr
->compression
) {
3691 FIXME("Compression not yet supported!\n");
3692 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 8 ) * abs(descr
->lines
))
3695 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3696 descr
->infoWidth
, descr
->width
,
3697 descr
->colorMap
, descr
->palentry
,
3698 bmpImage
, descr
->dibpitch
);
3702 X11DRV_DIB_GetImageBits_16( descr
->lines
, (LPVOID
)descr
->bits
,
3703 descr
->infoWidth
,descr
->width
,
3705 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3706 bmpImage
, descr
->dibpitch
);
3710 X11DRV_DIB_GetImageBits_24( descr
->lines
, (LPVOID
)descr
->bits
,
3711 descr
->infoWidth
,descr
->width
,
3713 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3714 bmpImage
, descr
->dibpitch
);
3718 X11DRV_DIB_GetImageBits_32( descr
->lines
, (LPVOID
)descr
->bits
,
3719 descr
->infoWidth
, descr
->width
,
3721 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3722 bmpImage
, descr
->dibpitch
);
3726 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3733 XDestroyImage( bmpImage
);
3734 wine_tsx11_unlock();
3739 /*************************************************************************
3740 * X11DRV_SetDIBitsToDevice
3743 INT
X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE
*physDev
, INT xDest
, INT yDest
, DWORD cx
,
3744 DWORD cy
, INT xSrc
, INT ySrc
,
3745 UINT startscan
, UINT lines
, LPCVOID bits
,
3746 const BITMAPINFO
*info
, UINT coloruse
)
3748 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3753 int rop
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
) - 1];
3755 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3756 &descr
.infoBpp
, &descr
.compression
) == -1)
3759 top_down
= (height
< 0);
3760 if (top_down
) height
= -height
;
3764 LPtoDP(physDev
->hdc
, &pt
, 1);
3766 if (!lines
|| (startscan
>= height
)) return 0;
3767 if (!top_down
&& startscan
+ lines
> height
) lines
= height
- startscan
;
3769 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3770 * and clamp all values to fit inside [startscan,startscan+lines]
3772 if (ySrc
+ cy
<= startscan
+ lines
)
3774 UINT y
= startscan
+ lines
- (ySrc
+ cy
);
3775 if (ySrc
< startscan
) cy
-= (startscan
- ySrc
);
3778 /* avoid getting unnecessary lines */
3780 if (y
>= lines
) return 0;
3785 if (y
>= lines
) return lines
;
3786 ySrc
= y
; /* need to get all lines in top down mode */
3791 if (ySrc
>= startscan
+ lines
) return lines
;
3792 pt
.y
+= ySrc
+ cy
- (startscan
+ lines
);
3793 cy
= startscan
+ lines
- ySrc
;
3795 if (cy
> lines
) cy
= lines
;
3797 if (xSrc
>= width
) return lines
;
3798 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
3799 if (!cx
|| !cy
) return lines
;
3801 /* Update the pixmap from the DIB section */
3802 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
3804 X11DRV_SetupGCForText( physDev
); /* To have the correct colors */
3806 XSetFunction(gdi_display
, physDev
->gc
, rop
);
3807 wine_tsx11_unlock();
3809 switch (descr
.infoBpp
)
3814 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3816 physDev
->depth
, info
, &descr
.nColorMap
);
3817 if (!descr
.colorMap
) return 0;
3818 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3822 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3823 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3824 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3830 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3831 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3832 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3837 descr
.physDev
= physDev
;
3840 descr
.palentry
= NULL
;
3841 descr
.lines
= top_down
? -lines
: lines
;
3842 descr
.infoWidth
= width
;
3843 descr
.depth
= physDev
->depth
;
3844 descr
.drawable
= physDev
->drawable
;
3845 descr
.gc
= physDev
->gc
;
3848 descr
.xDest
= physDev
->dc_rect
.left
+ pt
.x
;
3849 descr
.yDest
= physDev
->dc_rect
.top
+ pt
.y
;
3852 descr
.useShm
= FALSE
;
3853 descr
.dibpitch
= ((width
* descr
.infoBpp
+ 31) &~31) / 8;
3855 result
= X11DRV_DIB_SetImageBits( &descr
);
3857 if (descr
.infoBpp
<= 8)
3858 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3860 /* Update the DIBSection of the pixmap */
3861 X11DRV_UnlockDIBSection(physDev
, TRUE
);
3866 /***********************************************************************
3867 * SetDIBits (X11DRV.@)
3869 INT
X11DRV_SetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
,
3870 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
, UINT coloruse
)
3872 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3873 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3875 LONG width
, height
, tmpheight
;
3878 descr
.physDev
= physDev
;
3880 if (!physBitmap
) return 0;
3882 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3883 &descr
.infoBpp
, &descr
.compression
) == -1)
3887 if (height
< 0) height
= -height
;
3888 if (!lines
|| (startscan
>= height
))
3891 if (!GetObjectW( hbitmap
, sizeof(bitmap
), &bitmap
)) return 0;
3893 if (startscan
+ lines
> height
) lines
= height
- startscan
;
3895 switch (descr
.infoBpp
)
3900 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3901 descr
.physDev
, coloruse
,
3902 physBitmap
->pixmap_depth
,
3903 info
, &descr
.nColorMap
);
3904 if (!descr
.colorMap
) return 0;
3905 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3909 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3910 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3911 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3917 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3918 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3919 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3928 descr
.palentry
= NULL
;
3929 descr
.infoWidth
= width
;
3930 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
3931 descr
.depth
= physBitmap
->pixmap_depth
;
3932 descr
.drawable
= physBitmap
->pixmap
;
3933 descr
.gc
= BITMAP_GC(physBitmap
);
3937 descr
.yDest
= height
- startscan
- lines
;
3938 descr
.width
= bitmap
.bmWidth
;
3939 descr
.height
= lines
;
3940 descr
.useShm
= FALSE
;
3941 descr
.dibpitch
= ((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8;
3942 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
3943 result
= X11DRV_DIB_SetImageBits( &descr
);
3944 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
3946 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3951 /***********************************************************************
3952 * GetDIBits (X11DRV.@)
3954 INT
X11DRV_GetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
, UINT lines
,
3955 LPVOID bits
, BITMAPINFO
*info
, UINT coloruse
)
3957 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3959 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3960 PALETTEENTRY palette
[256];
3963 LONG width
, tempHeight
;
3968 GetPaletteEntries( GetCurrentObject( physDev
->hdc
, OBJ_PAL
), 0, 256, palette
);
3970 if (!physBitmap
) return 0;
3971 if (!(obj_size
= GetObjectW( hbitmap
, sizeof(dib
), &dib
))) return 0;
3973 bitmap_type
= DIB_GetBitmapInfo( (BITMAPINFOHEADER
*)info
, &width
, &tempHeight
, &descr
.infoBpp
, &descr
.compression
);
3974 descr
.lines
= tempHeight
;
3975 if (bitmap_type
== -1)
3977 ERR("Invalid bitmap\n");
3980 core_header
= (bitmap_type
== 0);
3981 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
3983 TRACE("%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
3984 lines
, dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
, width
, descr
.lines
, startscan
);
3986 if( lines
> dib
.dsBm
.bmHeight
) lines
= dib
.dsBm
.bmHeight
;
3988 height
= descr
.lines
;
3989 if (height
< 0) height
= -height
;
3990 if( lines
> height
) lines
= height
;
3991 /* Top-down images have a negative biHeight, the scanlines of these images
3992 * were inverted in X11DRV_DIB_GetImageBits_xx
3993 * To prevent this we simply change the sign of lines
3994 * (the number of scan lines to copy).
3995 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
3997 if( descr
.lines
< 0 && lines
> 0) lines
= -lines
;
3999 if( startscan
>= dib
.dsBm
.bmHeight
) return 0;
4001 descr
.colorMap
= NULL
;
4003 switch (descr
.infoBpp
)
4008 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4009 if(coloruse
== DIB_RGB_COLORS
)
4010 descr
.colorMap
= colorPtr
;
4012 int num_colors
= 1 << descr
.infoBpp
, i
;
4015 WORD
*index
= (WORD
*)colorPtr
;
4016 descr
.colorMap
= rgb
= HeapAlloc(GetProcessHeap(), 0, num_colors
* sizeof(RGBQUAD
));
4017 for(i
= 0; i
< num_colors
; i
++, rgb
++, index
++) {
4018 colref
= X11DRV_PALETTE_ToLogical(X11DRV_PALETTE_ToPhysical(physDev
, PALETTEINDEX(*index
)));
4019 rgb
->rgbRed
= GetRValue(colref
);
4020 rgb
->rgbGreen
= GetGValue(colref
);
4021 rgb
->rgbBlue
= GetBValue(colref
);
4022 rgb
->rgbReserved
= 0;
4028 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4029 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4030 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4034 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4035 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4036 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4040 descr
.physDev
= physDev
;
4041 descr
.palentry
= palette
;
4043 descr
.image
= physBitmap
->image
;
4044 descr
.infoWidth
= width
;
4045 descr
.lines
= lines
;
4046 descr
.depth
= physBitmap
->pixmap_depth
;
4047 descr
.drawable
= physBitmap
->pixmap
;
4048 descr
.gc
= BITMAP_GC(physBitmap
);
4049 descr
.width
= dib
.dsBm
.bmWidth
;
4050 descr
.height
= dib
.dsBm
.bmHeight
;
4054 descr
.sizeImage
= core_header
? 0 : info
->bmiHeader
.biSizeImage
;
4056 if (descr
.lines
> 0)
4058 descr
.ySrc
= (descr
.height
-1) - (startscan
+ (lines
-1));
4062 descr
.ySrc
= startscan
;
4064 #ifdef HAVE_LIBXXSHM
4065 descr
.useShm
= (obj_size
== sizeof(DIBSECTION
)) && (physBitmap
->shminfo
.shmid
!= -1);
4067 descr
.useShm
= FALSE
;
4069 descr
.dibpitch
= (obj_size
== sizeof(DIBSECTION
)) ? dib
.dsBm
.bmWidthBytes
4070 : (((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8);
4072 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
4073 X11DRV_DIB_GetImageBits( &descr
);
4074 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4076 if(!core_header
&& info
->bmiHeader
.biSizeImage
== 0) /* Fill in biSizeImage */
4077 info
->bmiHeader
.biSizeImage
= X11DRV_DIB_GetDIBImageBytes( descr
.infoWidth
,
4081 if (descr
.compression
== BI_BITFIELDS
)
4083 *(DWORD
*)info
->bmiColors
= descr
.rMask
;
4084 *((DWORD
*)info
->bmiColors
+ 1) = descr
.gMask
;
4085 *((DWORD
*)info
->bmiColors
+ 2) = descr
.bMask
;
4087 else if (!core_header
)
4089 /* if RLE or JPEG compression were supported,
4090 * this line would be invalid. */
4091 info
->bmiHeader
.biCompression
= 0;
4094 if(descr
.colorMap
!= colorPtr
)
4095 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4099 /***********************************************************************
4100 * DIB_DoProtectDIBSection
4102 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP
*physBitmap
, DWORD new_prot
)
4106 VirtualProtect(physBitmap
->base
, physBitmap
->size
, new_prot
, &old_prot
);
4107 TRACE("Changed protection from %d to %d\n", old_prot
, new_prot
);
4110 /***********************************************************************
4111 * X11DRV_DIB_DoCopyDIBSection
4113 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
4114 void *colorMap
, int nColorMap
,
4115 Drawable dest
, GC gc
,
4116 DWORD xSrc
, DWORD ySrc
,
4117 DWORD xDest
, DWORD yDest
,
4118 DWORD width
, DWORD height
)
4120 DIBSECTION dibSection
;
4121 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4122 int identity
[2] = {0,1};
4124 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
4126 descr
.physDev
= NULL
;
4127 descr
.palentry
= NULL
;
4128 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
4129 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
4130 descr
.lines
= dibSection
.dsBmih
.biHeight
;
4131 descr
.image
= physBitmap
->image
;
4132 descr
.colorMap
= colorMap
;
4133 descr
.nColorMap
= nColorMap
;
4134 descr
.bits
= dibSection
.dsBm
.bmBits
;
4135 descr
.depth
= physBitmap
->pixmap_depth
;
4136 descr
.compression
= dibSection
.dsBmih
.biCompression
;
4138 if(descr
.infoBpp
== 1)
4139 descr
.colorMap
= (void*)identity
;
4141 switch (descr
.infoBpp
)
4146 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4150 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
4151 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
4152 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
4157 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
4158 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
4159 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
4164 descr
.drawable
= dest
;
4168 descr
.xDest
= xDest
;
4169 descr
.yDest
= yDest
;
4170 descr
.width
= width
;
4171 descr
.height
= height
;
4172 descr
.sizeImage
= 0;
4174 #ifdef HAVE_LIBXXSHM
4175 descr
.useShm
= (physBitmap
->shminfo
.shmid
!= -1);
4177 descr
.useShm
= FALSE
;
4179 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
4183 TRACE("Copying from Pixmap to DIB bits\n");
4184 X11DRV_DIB_GetImageBits( &descr
);
4188 TRACE("Copying from DIB bits to Pixmap\n");
4189 X11DRV_DIB_SetImageBits( &descr
);
4193 /***********************************************************************
4194 * X11DRV_DIB_CopyDIBSection
4196 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE
*physDevSrc
, X11DRV_PDEVICE
*physDevDst
,
4197 DWORD xSrc
, DWORD ySrc
, DWORD xDest
, DWORD yDest
,
4198 DWORD width
, DWORD height
)
4201 X_PHYSBITMAP
*physBitmap
;
4202 int nColorMap
= 0, *colorMap
= NULL
, aColorMap
= FALSE
;
4204 TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc
->hdc
, physDevDst
->hdc
,
4205 xSrc
, ySrc
, xDest
, yDest
, width
, height
);
4206 /* this function is meant as an optimization for BitBlt,
4207 * not to be called otherwise */
4208 physBitmap
= physDevSrc
->bitmap
;
4209 if (!physBitmap
|| GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
4211 ERR("called for non-DIBSection!?\n");
4214 /* while BitBlt should already have made sure we only get
4215 * positive values, we should check for oversize values */
4216 if ((xSrc
< dib
.dsBm
.bmWidth
) &&
4217 (ySrc
< dib
.dsBm
.bmHeight
)) {
4218 if (xSrc
+ width
> dib
.dsBm
.bmWidth
)
4219 width
= dib
.dsBm
.bmWidth
- xSrc
;
4220 if (ySrc
+ height
> dib
.dsBm
.bmHeight
)
4221 height
= dib
.dsBm
.bmHeight
- ySrc
;
4222 /* if the source bitmap is 8bpp or less, we're supposed to use the
4223 * DC's palette for color conversion (not the DIB color table) */
4224 if (dib
.dsBm
.bmBitsPixel
<= 8) {
4225 HPALETTE hPalette
= GetCurrentObject( physDevSrc
->hdc
, OBJ_PAL
);
4226 if (!hPalette
|| (hPalette
== GetStockObject(DEFAULT_PALETTE
))) {
4227 /* HACK: no palette has been set in the source DC,
4228 * use the DIB colormap instead - this is necessary in some
4229 * cases since we need to do depth conversion in some places
4230 * where real Windows can just copy data straight over */
4231 colorMap
= physBitmap
->colorMap
;
4232 nColorMap
= physBitmap
->nColorMap
;
4234 colorMap
= X11DRV_DIB_BuildColorMap( physDevSrc
, (WORD
)-1,
4235 dib
.dsBm
.bmBitsPixel
,
4236 (BITMAPINFO
*)&dib
.dsBmih
,
4238 if (colorMap
) aColorMap
= TRUE
;
4241 /* perform the copy */
4242 X11DRV_DIB_DoCopyDIBSection(physBitmap
, FALSE
, colorMap
, nColorMap
,
4243 physDevDst
->drawable
, physDevDst
->gc
, xSrc
, ySrc
,
4244 physDevDst
->dc_rect
.left
+ xDest
, physDevDst
->dc_rect
.top
+ yDest
,
4246 /* free color mapping */
4248 HeapFree(GetProcessHeap(), 0, colorMap
);
4252 /***********************************************************************
4253 * X11DRV_DIB_DoUpdateDIBSection
4255 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
4259 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
4260 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
4261 physBitmap
->colorMap
, physBitmap
->nColorMap
,
4262 physBitmap
->pixmap
, BITMAP_GC(physBitmap
),
4263 0, 0, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
);
4266 /***********************************************************************
4267 * X11DRV_DIB_FaultHandler
4269 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
4271 X_PHYSBITMAP
*physBitmap
= NULL
;
4276 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
4277 return EXCEPTION_CONTINUE_SEARCH
;
4279 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
4281 EnterCriticalSection(&dibs_cs
);
4282 LIST_FOR_EACH( ptr
, &dibs_list
)
4284 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
4285 if ((physBitmap
->base
<= addr
) && (addr
< physBitmap
->base
+ physBitmap
->size
))
4291 LeaveCriticalSection(&dibs_cs
);
4293 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
4295 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
);
4296 if (ep
->ExceptionRecord
->ExceptionInformation
[0] == EXCEPTION_WRITE_FAULT
) {
4297 /* the app tried to write the DIB bits */
4298 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
);
4300 /* the app tried to read the DIB bits */
4301 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
);
4303 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4305 return EXCEPTION_CONTINUE_EXECUTION
;
4308 /***********************************************************************
4311 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
)
4313 INT ret
= DIB_Status_None
;
4315 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4316 EnterCriticalSection(&physBitmap
->lock
);
4317 ret
= physBitmap
->status
;
4319 case DIB_Status_GdiMod
:
4320 /* GDI access - request to draw on pixmap */
4321 switch (physBitmap
->status
)
4324 case DIB_Status_None
:
4325 physBitmap
->p_status
= DIB_Status_GdiMod
;
4326 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4329 case DIB_Status_GdiMod
:
4330 TRACE("GdiMod requested in status GdiMod\n" );
4331 physBitmap
->p_status
= DIB_Status_GdiMod
;
4334 case DIB_Status_InSync
:
4335 TRACE("GdiMod requested in status InSync\n" );
4336 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4337 physBitmap
->status
= DIB_Status_GdiMod
;
4338 physBitmap
->p_status
= DIB_Status_InSync
;
4341 case DIB_Status_AppMod
:
4342 TRACE("GdiMod requested in status AppMod\n" );
4343 /* make it readonly to avoid app changing data while we copy */
4344 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4345 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4346 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4347 physBitmap
->p_status
= DIB_Status_AppMod
;
4348 physBitmap
->status
= DIB_Status_GdiMod
;
4353 case DIB_Status_InSync
:
4354 /* App access - request access to read DIB surface */
4355 /* (typically called from signal handler) */
4356 switch (physBitmap
->status
)
4359 case DIB_Status_None
:
4360 /* shouldn't happen from signal handler */
4363 case DIB_Status_GdiMod
:
4364 TRACE("InSync requested in status GdiMod\n" );
4365 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4366 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4367 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4368 physBitmap
->status
= DIB_Status_InSync
;
4371 case DIB_Status_InSync
:
4372 TRACE("InSync requested in status InSync\n" );
4373 /* shouldn't happen from signal handler */
4376 case DIB_Status_AppMod
:
4377 TRACE("InSync requested in status AppMod\n" );
4378 /* no reason to do anything here, and this
4379 * shouldn't happen from signal handler */
4384 case DIB_Status_AppMod
:
4385 /* App access - request access to write DIB surface */
4386 /* (typically called from signal handler) */
4387 switch (physBitmap
->status
)
4390 case DIB_Status_None
:
4391 /* shouldn't happen from signal handler */
4394 case DIB_Status_GdiMod
:
4395 TRACE("AppMod requested in status GdiMod\n" );
4396 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4397 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4398 physBitmap
->status
= DIB_Status_AppMod
;
4401 case DIB_Status_InSync
:
4402 TRACE("AppMod requested in status InSync\n" );
4403 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4404 physBitmap
->status
= DIB_Status_AppMod
;
4407 case DIB_Status_AppMod
:
4408 TRACE("AppMod requested in status AppMod\n" );
4409 /* shouldn't happen from signal handler */
4414 /* it is up to the caller to do the copy/conversion, probably
4415 * using the return value to decide where to copy from */
4417 LeaveCriticalSection(&physBitmap
->lock
);
4421 /***********************************************************************
4424 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
)
4426 INT ret
= DIB_Status_None
;
4428 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4429 TRACE("Locking %p from thread %04x\n", physBitmap
->hbitmap
, GetCurrentThreadId());
4430 EnterCriticalSection(&physBitmap
->lock
);
4431 ret
= physBitmap
->status
;
4432 if (req
!= DIB_Status_None
)
4433 X11DRV_DIB_Coerce(physBitmap
, req
);
4437 /***********************************************************************
4440 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
4442 if (!physBitmap
->image
) return; /* not a DIB section */
4443 switch (physBitmap
->status
)
4446 case DIB_Status_None
:
4447 /* in case anyone is wondering, this is the "signal handler doesn't
4448 * work" case, where we always have to be ready for app access */
4450 switch (physBitmap
->p_status
)
4452 case DIB_Status_GdiMod
:
4453 TRACE("Unlocking and syncing from GdiMod\n" );
4454 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4458 TRACE("Unlocking without needing to sync\n" );
4462 else TRACE("Unlocking with no changes\n");
4463 physBitmap
->p_status
= DIB_Status_None
;
4466 case DIB_Status_GdiMod
:
4467 TRACE("Unlocking in status GdiMod\n" );
4468 /* DIB was protected in Coerce */
4470 /* no commit, revert to InSync if applicable */
4471 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
4472 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
4473 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4474 physBitmap
->status
= DIB_Status_InSync
;
4479 case DIB_Status_InSync
:
4480 TRACE("Unlocking in status InSync\n" );
4481 /* DIB was already protected in Coerce */
4484 case DIB_Status_AppMod
:
4485 TRACE("Unlocking in status AppMod\n" );
4486 /* DIB was already protected in Coerce */
4487 /* this case is ordinary only called from the signal handler,
4488 * so we don't bother to check for !commit */
4491 LeaveCriticalSection(&physBitmap
->lock
);
4492 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
4495 /***********************************************************************
4496 * X11DRV_CoerceDIBSection
4498 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4500 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4501 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
);
4504 /***********************************************************************
4505 * X11DRV_LockDIBSection
4507 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4509 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4510 return X11DRV_DIB_Lock(physDev
->bitmap
, req
);
4513 /***********************************************************************
4514 * X11DRV_UnlockDIBSection
4516 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
4518 if (!physDev
|| !physDev
->bitmap
) return;
4519 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
4523 #ifdef HAVE_LIBXXSHM
4524 /***********************************************************************
4525 * X11DRV_XShmErrorHandler
4528 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
4530 return 1; /* FIXME: should check event contents */
4533 /***********************************************************************
4534 * X11DRV_XShmCreateImage
4537 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
4538 XShmSegmentInfo
* shminfo
)
4542 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
4545 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
4547 if( shminfo
->shmid
!= -1 )
4549 shminfo
->shmaddr
= image
->data
= shmat(shminfo
->shmid
, 0, 0);
4550 if( shminfo
->shmaddr
!= (char*)-1 )
4554 shminfo
->readOnly
= FALSE
;
4555 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
4556 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
4557 XSync( gdi_display
, False
);
4558 if (X11DRV_check_error()) ok
= FALSE
;
4561 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4562 return image
; /* Success! */
4564 /* An error occurred */
4565 shmdt(shminfo
->shmaddr
);
4567 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4568 shminfo
->shmid
= -1;
4570 XFlush(gdi_display
);
4571 XDestroyImage(image
);
4576 #endif /* HAVE_LIBXXSHM */
4579 /***********************************************************************
4580 * X11DRV_CreateDIBSection (X11DRV.@)
4582 HBITMAP
X11DRV_CreateDIBSection( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
,
4583 const BITMAPINFO
*bmi
, UINT usage
)
4585 X_PHYSBITMAP
*physBitmap
;
4588 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
4589 physBitmap
->status
= DIB_Status_None
;
4591 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
4593 /* create color map */
4594 if (dib
.dsBm
.bmBitsPixel
<= 8)
4596 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( physDev
,
4597 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
4598 &physBitmap
->nColorMap
);
4601 /* create pixmap and X image */
4603 physBitmap
->pixmap_depth
= (dib
.dsBm
.bmBitsPixel
== 1) ? 1 : screen_depth
;
4604 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
4605 dib
.dsBm
.bmHeight
, physBitmap
->pixmap_depth
);
4606 #ifdef HAVE_LIBXXSHM
4607 physBitmap
->shminfo
.shmid
= -1;
4608 if (!XShmQueryExtension(gdi_display
) ||
4609 !(physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4610 physBitmap
->pixmap_depth
, &physBitmap
->shminfo
)) )
4612 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4613 physBitmap
->pixmap_depth
);
4614 wine_tsx11_unlock();
4615 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
4617 /* install fault handler */
4618 InitializeCriticalSection( &physBitmap
->lock
);
4619 physBitmap
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": X_PHYSBITMAP.lock");
4621 physBitmap
->base
= dib
.dsBm
.bmBits
;
4622 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
4623 physBitmap
->status
= DIB_Status_AppMod
;
4626 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
4627 EnterCriticalSection( &dibs_cs
);
4628 list_add_head( &dibs_list
, &physBitmap
->entry
);
4629 LeaveCriticalSection( &dibs_cs
);
4631 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4636 /***********************************************************************
4637 * X11DRV_DIB_DeleteDIBSection
4639 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
4643 EnterCriticalSection( &dibs_cs
);
4644 list_remove( &physBitmap
->entry
);
4645 last
= list_empty( &dibs_list
);
4646 LeaveCriticalSection( &dibs_cs
);
4650 RemoveVectoredExceptionHandler( dibs_handler
);
4651 dibs_handler
= NULL
;
4654 if (dib
->dshSection
)
4655 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
);
4657 if (physBitmap
->image
)
4660 #ifdef HAVE_LIBXXSHM
4661 if (physBitmap
->shminfo
.shmid
!= -1)
4663 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4664 XDestroyImage( physBitmap
->image
);
4665 shmdt( physBitmap
->shminfo
.shmaddr
);
4666 physBitmap
->shminfo
.shmid
= -1;
4670 XDestroyImage( physBitmap
->image
);
4671 wine_tsx11_unlock();
4674 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4675 physBitmap
->lock
.DebugInfo
->Spare
[0] = 0;
4676 DeleteCriticalSection(&physBitmap
->lock
);
4679 /***********************************************************************
4680 * SetDIBColorTable (X11DRV.@)
4682 UINT
X11DRV_SetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4686 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4688 if (!physBitmap
) return 0;
4689 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4691 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4692 UINT end
= count
+ start
;
4693 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4695 * Changing color table might change the mapping between
4696 * DIB colors and X11 colors and thus alter the visible state
4697 * of the bitmap object.
4700 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4701 * at least for a 1 bpp dibsection
4703 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
);
4704 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4705 dib
.dsBm
.bmBitsPixel
,
4706 TRUE
, colors
, start
, end
);
4707 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4714 /***********************************************************************
4715 * X11DRV_DIB_CreateDIBFromBitmap
4717 * Allocates a packed DIB and copies the bitmap data into it.
4719 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4724 LPBITMAPINFOHEADER pbmiHeader
;
4725 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4728 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4731 * A packed DIB contains a BITMAPINFO structure followed immediately by
4732 * an optional color palette and the pixel data.
4735 /* Calculate the size of the packed DIB */
4736 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4737 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4738 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4740 /* Get the offset to the bits */
4741 OffsetBits
= cPackedSize
- cDataSize
;
4743 /* Allocate the packed DIB */
4744 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4745 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4749 WARN("Could not allocate packed DIB!\n");
4753 /* A packed DIB starts with a BITMAPINFOHEADER */
4754 pPackedDIB
= GlobalLock(hPackedDIB
);
4755 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4757 /* Init the BITMAPINFOHEADER */
4758 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
4759 pbmiHeader
->biWidth
= bmp
.bmWidth
;
4760 pbmiHeader
->biHeight
= bmp
.bmHeight
;
4761 pbmiHeader
->biPlanes
= 1;
4762 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
4763 pbmiHeader
->biCompression
= BI_RGB
;
4764 pbmiHeader
->biSizeImage
= 0;
4765 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
4766 pbmiHeader
->biClrUsed
= 0;
4767 pbmiHeader
->biClrImportant
= 0;
4769 /* Retrieve the DIB bits from the bitmap and fill in the
4770 * DIB color table if present */
4772 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
4773 hBmp
, /* Handle to bitmap */
4774 0, /* First scan line to set in dest bitmap */
4775 bmp
.bmHeight
, /* Number of scan lines to copy */
4776 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
4777 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
4778 0); /* RGB or palette index */
4779 GlobalUnlock(hPackedDIB
);
4781 /* Cleanup if GetDIBits failed */
4782 if (nLinesCopied
!= bmp
.bmHeight
)
4784 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
4785 GlobalFree(hPackedDIB
);
4792 /**************************************************************************
4793 * X11DRV_DIB_CreateDIBFromPixmap
4795 * Allocates a packed DIB and copies the Pixmap data into it.
4796 * The Pixmap passed in is deleted after the conversion.
4798 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
4801 X_PHYSBITMAP
*physBitmap
;
4802 HBITMAP hBmp
= 0, old
;
4803 HGLOBAL hPackedDIB
= 0;
4805 int x
,y
; /* Unused */
4806 unsigned border_width
; /* Unused */
4807 unsigned int depth
, width
, height
;
4809 /* Get the Pixmap dimensions and bit depth */
4811 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
4812 &border_width
, &depth
)) depth
= 0;
4813 wine_tsx11_unlock();
4814 if (!depth
) return 0;
4816 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4817 width
, height
, depth
);
4820 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4821 * and make it a container for the pixmap passed.
4823 hBmp
= CreateBitmap( width
, height
, 1, depth
, NULL
);
4825 /* force bitmap to be owned by a screen DC */
4826 hdcMem
= CreateCompatibleDC( hdc
);
4827 old
= SelectObject( hdcMem
, hBmp
);
4829 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4832 if (physBitmap
->pixmap
) XFreePixmap( gdi_display
, physBitmap
->pixmap
);
4833 physBitmap
->pixmap
= pixmap
;
4834 wine_tsx11_unlock();
4836 SelectObject( hdcMem
, old
);
4840 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4841 * A packed DIB contains a BITMAPINFO structure followed immediately by
4842 * an optional color palette and the pixel data.
4844 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
4846 /* We can now get rid of the HBITMAP wrapper we created earlier.
4847 * Note: Simply calling DeleteObject will free the embedded Pixmap as well.
4851 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
4856 /**************************************************************************
4857 * X11DRV_DIB_CreatePixmapFromDIB
4859 * Creates a Pixmap from a packed DIB
4861 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
4864 X_PHYSBITMAP
*physBitmap
;
4868 /* Create a DDB from the DIB */
4870 pbmi
= GlobalLock(hPackedDIB
);
4871 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
4872 (LPBYTE
)pbmi
+ X11DRV_DIB_BitmapInfoSize( pbmi
, DIB_RGB_COLORS
),
4873 pbmi
, DIB_RGB_COLORS
);
4874 GlobalUnlock(hPackedDIB
);
4876 /* clear the physBitmap so that we can steal its pixmap */
4877 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4878 pixmap
= physBitmap
->pixmap
;
4879 physBitmap
->pixmap
= 0;
4881 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4884 TRACE("Returning Pixmap %ld\n", pixmap
);