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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
);
45 WINE_DECLARE_DEBUG_CHANNEL(x11drv
);
47 static struct list dibs_list
= LIST_INIT(dibs_list
);
49 static CRITICAL_SECTION dibs_cs
;
50 static CRITICAL_SECTION_DEBUG dibs_cs_debug
=
53 { &dibs_cs_debug
.ProcessLocksList
, &dibs_cs_debug
.ProcessLocksList
},
54 0, 0, { 0, (DWORD
)(__FILE__
": dibs_cs") }
56 static CRITICAL_SECTION dibs_cs
= { &dibs_cs_debug
, -1, 0, 0, 0, 0 };
58 static PVOID dibs_handler
;
60 static int ximageDepthTable
[32];
62 /* This structure holds the arguments for DIB_SetImageBits() */
65 X11DRV_PDEVICE
*physDev
;
68 PALETTEENTRY
*palentry
;
90 } X11DRV_DIB_IMAGEBITS_DESCR
;
95 RLE_EOL
= 0, /* End of line */
96 RLE_END
= 1, /* End of bitmap */
97 RLE_DELTA
= 2 /* Delta */
101 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*,INT
,BOOL
);
102 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*,INT
,BOOL
);
103 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*,BOOL
);
106 Some of the following helper functions are duplicated in
110 /***********************************************************************
111 * X11DRV_DIB_GetXImageWidthBytes
113 * Return the width of an X image in bytes
115 inline static int X11DRV_DIB_GetXImageWidthBytes( int width
, int depth
)
117 if (!depth
|| depth
> 32) goto error
;
119 if (!ximageDepthTable
[depth
-1])
121 XImage
*testimage
= XCreateImage( gdi_display
, visual
, depth
,
122 ZPixmap
, 0, NULL
, 1, 1, 32, 20 );
125 ximageDepthTable
[depth
-1] = testimage
->bits_per_pixel
;
126 XDestroyImage( testimage
);
128 else ximageDepthTable
[depth
-1] = -1;
130 if (ximageDepthTable
[depth
-1] != -1)
131 return (4 * ((width
* ximageDepthTable
[depth
-1] + 31) / 32));
134 WARN( "(%d): Unsupported depth\n", depth
);
139 /***********************************************************************
140 * X11DRV_DIB_GetDIBWidthBytes
142 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
144 static int X11DRV_DIB_GetDIBWidthBytes( int width
, int depth
)
150 case 1: words
= (width
+ 31) / 32; break;
151 case 4: words
= (width
+ 7) / 8; break;
152 case 8: words
= (width
+ 3) / 4; break;
154 case 16: words
= (width
+ 1) / 2; break;
155 case 24: words
= (width
* 3 + 3) / 4; break;
157 WARN("(%d): Unsupported depth\n", depth
);
166 /***********************************************************************
167 * X11DRV_DIB_GetDIBImageBytes
169 * Return the number of bytes used to hold the image in a DIB bitmap.
171 static int X11DRV_DIB_GetDIBImageBytes( int width
, int height
, int depth
)
173 return X11DRV_DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
177 /***********************************************************************
178 * X11DRV_DIB_BitmapInfoSize
180 * Return the size of the bitmap info structure including color table.
182 int X11DRV_DIB_BitmapInfoSize( const BITMAPINFO
* info
, WORD coloruse
)
186 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
188 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
189 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
190 return sizeof(BITMAPCOREHEADER
) + colors
*
191 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
193 else /* assume BITMAPINFOHEADER */
195 colors
= info
->bmiHeader
.biClrUsed
;
196 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
197 colors
= 1 << info
->bmiHeader
.biBitCount
;
198 return sizeof(BITMAPINFOHEADER
) + colors
*
199 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
204 /***********************************************************************
205 * X11DRV_DIB_CreateXImage
209 XImage
*X11DRV_DIB_CreateXImage( int width
, int height
, int depth
)
215 width_bytes
= X11DRV_DIB_GetXImageWidthBytes( width
, depth
);
216 image
= XCreateImage( gdi_display
, visual
, depth
, ZPixmap
, 0,
217 calloc( height
, width_bytes
),
218 width
, height
, 32, width_bytes
);
224 /***********************************************************************
225 * DIB_GetBitmapInfoEx
227 * Get the info from a bitmap header.
228 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
230 static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER
*header
, LONG
*width
,
231 LONG
*height
, WORD
*planes
, WORD
*bpp
,
232 WORD
*compr
, DWORD
*size
)
234 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
236 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
237 *width
= core
->bcWidth
;
238 *height
= core
->bcHeight
;
239 *planes
= core
->bcPlanes
;
240 *bpp
= core
->bcBitCount
;
245 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
))
247 *width
= header
->biWidth
;
248 *height
= header
->biHeight
;
249 *planes
= header
->biPlanes
;
250 *bpp
= header
->biBitCount
;
251 *compr
= header
->biCompression
;
252 *size
= header
->biSizeImage
;
255 ERR("(%ld): unknown/wrong size for header\n", header
->biSize
);
260 /***********************************************************************
263 * Get the info from a bitmap header.
264 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
266 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
267 LONG
*height
, WORD
*bpp
, WORD
*compr
)
272 return DIB_GetBitmapInfoEx( header
, width
, height
, &planes
, bpp
, compr
, &size
);
276 /***********************************************************************
277 * X11DRV_DIB_GenColorMap
279 * Fills the color map of a bitmap palette. Should not be called
280 * for a >8-bit deep bitmap.
282 int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE
*physDev
, int *colorMapping
,
283 WORD coloruse
, WORD depth
, BOOL quads
,
284 const void *colorPtr
, int start
, int end
)
288 if (coloruse
== DIB_RGB_COLORS
)
292 const RGBQUAD
* rgb
= (const RGBQUAD
*)colorPtr
;
294 if (depth
== 1) /* Monochrome */
295 for (i
= start
; i
< end
; i
++, rgb
++)
296 colorMapping
[i
] = (rgb
->rgbRed
+ rgb
->rgbGreen
+
297 rgb
->rgbBlue
> 255*3/2);
299 for (i
= start
; i
< end
; i
++, rgb
++)
300 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, RGB(rgb
->rgbRed
,
306 const RGBTRIPLE
* rgb
= (const RGBTRIPLE
*)colorPtr
;
308 if (depth
== 1) /* Monochrome */
309 for (i
= start
; i
< end
; i
++, rgb
++)
310 colorMapping
[i
] = (rgb
->rgbtRed
+ rgb
->rgbtGreen
+
311 rgb
->rgbtBlue
> 255*3/2);
313 for (i
= start
; i
< end
; i
++, rgb
++)
314 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, RGB(rgb
->rgbtRed
,
319 else /* DIB_PAL_COLORS */
322 const WORD
* index
= (const WORD
*)colorPtr
;
324 for (i
= start
; i
< end
; i
++, index
++)
325 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(*index
) );
327 for (i
= start
; i
< end
; i
++)
328 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(i
) );
335 /***********************************************************************
336 * X11DRV_DIB_BuildColorMap
338 * Build the color map from the bitmap palette. Should not be called
339 * for a >8-bit deep bitmap.
341 int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
342 const BITMAPINFO
*info
, int *nColors
)
346 const void *colorPtr
;
349 isInfo
= info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
);
353 colors
= info
->bmiHeader
.biClrUsed
;
354 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
358 colors
= 1 << ((const BITMAPCOREHEADER
*)info
)->bcBitCount
;
361 colorPtr
= (const BYTE
*) info
+ (WORD
) info
->bmiHeader
.biSize
;
365 ERR("called with >256 colors!\n");
369 /* just so CopyDIBSection doesn't have to create an identity palette */
370 if (coloruse
== (WORD
)-1) colorPtr
= NULL
;
372 if (!(colorMapping
= HeapAlloc(GetProcessHeap(), 0, colors
* sizeof(int) )))
376 return X11DRV_DIB_GenColorMap( physDev
, colorMapping
, coloruse
, depth
,
377 isInfo
, colorPtr
, 0, colors
);
380 /***********************************************************************
381 * X11DRV_DIB_BuildColorTable
383 * Build the dib color table. This either keeps a copy of the bmiColors array if
384 * usage is DIB_RGB_COLORS, or looks up the palette indicies if usage is
386 * Should not be called for a >8-bit deep bitmap.
388 static RGBQUAD
*X11DRV_DIB_BuildColorTable( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
389 const BITMAPINFO
*info
)
394 BOOL core_info
= info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
);
398 colors
= 1 << ((BITMAPCOREINFO
*) info
)->bmciHeader
.bcBitCount
;
402 colors
= info
->bmiHeader
.biClrUsed
;
403 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
407 ERR("called with >256 colors!\n");
411 if (!(colorTable
= HeapAlloc(GetProcessHeap(), 0, colors
* sizeof(RGBQUAD
) )))
414 if(coloruse
== DIB_RGB_COLORS
)
418 /* Convert RGBTRIPLEs to RGBQUADs */
419 for (i
=0; i
< colors
; i
++)
421 colorTable
[i
].rgbRed
= ((BITMAPCOREINFO
*) info
)->bmciColors
[i
].rgbtRed
;
422 colorTable
[i
].rgbGreen
= ((BITMAPCOREINFO
*) info
)->bmciColors
[i
].rgbtGreen
;
423 colorTable
[i
].rgbBlue
= ((BITMAPCOREINFO
*) info
)->bmciColors
[i
].rgbtBlue
;
424 colorTable
[i
].rgbReserved
= 0;
429 memcpy(colorTable
, (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
, colors
* sizeof(RGBQUAD
));
434 HPALETTE hpal
= GetCurrentObject(physDev
->hdc
, OBJ_PAL
);
435 PALETTEENTRY
* pal_ents
;
436 WORD
*index
= (WORD
*) ((LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
);
437 int logcolors
, entry
;
439 logcolors
= GetPaletteEntries( hpal
, 0, 0, NULL
);
440 pal_ents
= HeapAlloc(GetProcessHeap(), 0, logcolors
* sizeof(*pal_ents
));
441 logcolors
= GetPaletteEntries( hpal
, 0, logcolors
, pal_ents
);
443 for(i
= 0; i
< colors
; i
++, index
++)
445 entry
= *index
% logcolors
;
446 colorTable
[i
].rgbRed
= pal_ents
[entry
].peRed
;
447 colorTable
[i
].rgbGreen
= pal_ents
[entry
].peGreen
;
448 colorTable
[i
].rgbBlue
= pal_ents
[entry
].peBlue
;
449 colorTable
[i
].rgbReserved
= 0;
452 HeapFree(GetProcessHeap(), 0, pal_ents
);
458 /***********************************************************************
459 * X11DRV_DIB_MapColor
461 int X11DRV_DIB_MapColor( int *physMap
, int nPhysMap
, int phys
, int oldcol
)
465 if ((oldcol
< nPhysMap
) && (physMap
[oldcol
] == phys
))
468 for (color
= 0; color
< nPhysMap
; color
++)
469 if (physMap
[color
] == phys
)
472 WARN("Strange color %08x\n", phys
);
477 /*********************************************************************
478 * X11DRV_DIB_GetNearestIndex
480 * Helper for X11DRV_DIB_GetDIBits.
481 * Returns the nearest colour table index for a given RGB.
482 * Nearest is defined by minimizing the sum of the squares.
484 static INT
X11DRV_DIB_GetNearestIndex(RGBQUAD
*colormap
, int numColors
, BYTE r
, BYTE g
, BYTE b
)
486 INT i
, best
= -1, diff
, bestdiff
= -1;
489 for(color
= colormap
, i
= 0; i
< numColors
; color
++, i
++) {
490 diff
= (r
- color
->rgbRed
) * (r
- color
->rgbRed
) +
491 (g
- color
->rgbGreen
) * (g
- color
->rgbGreen
) +
492 (b
- color
->rgbBlue
) * (b
- color
->rgbBlue
);
495 if(best
== -1 || diff
< bestdiff
) {
502 /*********************************************************************
503 * X11DRV_DIB_MaskToShift
505 * Helper for X11DRV_DIB_GetDIBits.
506 * Returns the by how many bits to shift a given color so that it is
507 * in the proper position.
509 INT
X11DRV_DIB_MaskToShift(DWORD mask
)
517 while ((mask
&1)==0) {
524 /***********************************************************************
525 * X11DRV_DIB_SetImageBits_1
527 * SetDIBits for a 1-bit deep DIB.
529 static void X11DRV_DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
530 DWORD srcwidth
, DWORD dstwidth
, int left
,
531 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
540 srcbits
= srcbits
+ linebytes
* (lines
- 1);
541 linebytes
= -linebytes
;
544 if ((extra
= (left
& 7)) != 0) {
548 srcbits
+= left
>> 3;
549 width
= min(srcwidth
, dstwidth
);
551 /* ==== pal 1 dib -> any bmp format ==== */
552 for (h
= lines
-1; h
>=0; h
--) {
554 /* FIXME: should avoid putting x<left pixels (minor speed issue) */
555 for (i
= width
/8, x
= left
; i
> 0; i
--) {
557 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
558 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
559 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
560 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
561 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
562 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
563 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
564 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
570 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
571 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
572 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
573 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
574 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
575 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
576 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
579 srcbits
+= linebytes
;
583 /***********************************************************************
584 * X11DRV_DIB_GetImageBits_1
586 * GetDIBits for a 1-bit deep DIB.
588 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
589 DWORD dstwidth
, DWORD srcwidth
,
590 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
591 XImage
*bmpImage
, DWORD linebytes
)
594 int h
, width
= min(dstwidth
, srcwidth
);
598 dstbits
= dstbits
+ linebytes
* (lines
- 1);
599 linebytes
= -linebytes
;
602 switch (bmpImage
->depth
)
606 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
607 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
610 for (h
=lines
-1; h
>=0; h
--) {
614 for (x
=0; x
<width
; x
++) {
616 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
617 dstval
|=(X11DRV_DIB_GetNearestIndex
621 srcval
.peBlue
) << (7 - (x
& 7)));
630 dstbits
+= linebytes
;
638 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
639 /* ==== pal 8 bmp -> pal 1 dib ==== */
641 const BYTE
* srcpixel
;
644 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
646 for (h
=0; h
<lines
; h
++) {
651 for (x
=0; x
<width
; x
++) {
653 srcval
=srccolors
[(int)*srcpixel
++];
654 dstval
|=(X11DRV_DIB_GetNearestIndex
658 srcval
.peBlue
) << (7-(x
&7)) );
667 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
668 dstbits
+= linebytes
;
679 const WORD
* srcpixel
;
682 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
684 if (bmpImage
->green_mask
==0x03e0) {
685 if (bmpImage
->red_mask
==0x7c00) {
686 /* ==== rgb 555 bmp -> pal 1 dib ==== */
687 for (h
=0; h
<lines
; h
++) {
692 for (x
=0; x
<width
; x
++) {
695 dstval
|=(X11DRV_DIB_GetNearestIndex
697 ((srcval
>> 7) & 0xf8) | /* r */
698 ((srcval
>> 12) & 0x07),
699 ((srcval
>> 2) & 0xf8) | /* g */
700 ((srcval
>> 7) & 0x07),
701 ((srcval
<< 3) & 0xf8) | /* b */
702 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
711 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
712 dstbits
+= linebytes
;
714 } else if (bmpImage
->blue_mask
==0x7c00) {
715 /* ==== bgr 555 bmp -> pal 1 dib ==== */
716 for (h
=0; h
<lines
; h
++) {
721 for (x
=0; x
<width
; x
++) {
724 dstval
|=(X11DRV_DIB_GetNearestIndex
726 ((srcval
<< 3) & 0xf8) | /* r */
727 ((srcval
>> 2) & 0x07),
728 ((srcval
>> 2) & 0xf8) | /* g */
729 ((srcval
>> 7) & 0x07),
730 ((srcval
>> 7) & 0xf8) | /* b */
731 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
740 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
741 dstbits
+= linebytes
;
746 } else if (bmpImage
->green_mask
==0x07e0) {
747 if (bmpImage
->red_mask
==0xf800) {
748 /* ==== rgb 565 bmp -> pal 1 dib ==== */
749 for (h
=0; h
<lines
; h
++) {
754 for (x
=0; x
<width
; x
++) {
757 dstval
|=(X11DRV_DIB_GetNearestIndex
759 ((srcval
>> 8) & 0xf8) | /* r */
760 ((srcval
>> 13) & 0x07),
761 ((srcval
>> 3) & 0xfc) | /* g */
762 ((srcval
>> 9) & 0x03),
763 ((srcval
<< 3) & 0xf8) | /* b */
764 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
773 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
774 dstbits
+= linebytes
;
776 } else if (bmpImage
->blue_mask
==0xf800) {
777 /* ==== bgr 565 bmp -> pal 1 dib ==== */
778 for (h
=0; h
<lines
; h
++) {
783 for (x
=0; x
<width
; x
++) {
786 dstval
|=(X11DRV_DIB_GetNearestIndex
788 ((srcval
<< 3) & 0xf8) | /* r */
789 ((srcval
>> 2) & 0x07),
790 ((srcval
>> 3) & 0xfc) | /* g */
791 ((srcval
>> 9) & 0x03),
792 ((srcval
>> 8) & 0xf8) | /* b */
793 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
802 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
803 dstbits
+= linebytes
;
822 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
823 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
825 if (bmpImage
->green_mask
!=0x00ff00 ||
826 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
828 } else if (bmpImage
->blue_mask
==0xff) {
829 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
830 for (h
=0; h
<lines
; h
++) {
835 for (x
=0; x
<width
; x
++) {
836 dstval
|=(X11DRV_DIB_GetNearestIndex
840 srcbyte
[0]) << (7-(x
&7)) );
841 srcbyte
+=bytes_per_pixel
;
850 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
851 dstbits
+= linebytes
;
854 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
855 for (h
=0; h
<lines
; h
++) {
860 for (x
=0; x
<width
; x
++) {
861 dstval
|=(X11DRV_DIB_GetNearestIndex
865 srcbyte
[2]) << (7-(x
&7)) );
866 srcbyte
+=bytes_per_pixel
;
875 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
876 dstbits
+= linebytes
;
886 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
888 /* ==== any bmp format -> pal 1 dib ==== */
889 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB\n",
890 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
891 bmpImage
->green_mask
, bmpImage
->blue_mask
);
893 for (h
=lines
-1; h
>=0; h
--) {
897 for (x
=0; x
<width
; x
++) {
898 dstval
|=(XGetPixel( bmpImage
, x
, h
) >= white
) << (7 - (x
&7));
907 dstbits
+= linebytes
;
914 /***********************************************************************
915 * X11DRV_DIB_SetImageBits_4
917 * SetDIBits for a 4-bit deep DIB.
919 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
920 DWORD srcwidth
, DWORD dstwidth
, int left
,
921 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
929 srcbits
= srcbits
+ linebytes
* (lines
- 1);
930 linebytes
= -linebytes
;
937 srcbits
+= left
>> 1;
938 width
= min(srcwidth
, dstwidth
);
940 /* ==== pal 4 dib -> any bmp format ==== */
941 for (h
= lines
-1; h
>= 0; h
--) {
943 for (i
= width
/2, x
= left
; i
> 0; i
--) {
944 BYTE srcval
=*srcbyte
++;
945 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
946 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
949 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
950 srcbits
+= linebytes
;
956 /***********************************************************************
957 * X11DRV_DIB_GetImageBits_4
959 * GetDIBits for a 4-bit deep DIB.
961 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
962 DWORD srcwidth
, DWORD dstwidth
,
963 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
964 XImage
*bmpImage
, DWORD linebytes
)
967 int h
, width
= min(srcwidth
, dstwidth
);
973 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
974 linebytes
= -linebytes
;
979 switch (bmpImage
->depth
) {
982 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
983 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
986 for (h
= lines
-1; h
>= 0; h
--) {
990 for (x
= 0; x
< width
; x
++) {
992 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
993 dstval
|=(X11DRV_DIB_GetNearestIndex
997 srcval
.peBlue
) << (4-((x
&1)<<2)));
1006 dstbits
+= linebytes
;
1014 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
1015 /* ==== pal 8 bmp -> pal 4 dib ==== */
1016 const void* srcbits
;
1017 const BYTE
*srcpixel
;
1020 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1021 for (h
=0; h
<lines
; h
++) {
1026 for (x
=0; x
<width
; x
++) {
1027 PALETTEENTRY srcval
;
1028 srcval
= srccolors
[(int)*srcpixel
++];
1029 dstval
|=(X11DRV_DIB_GetNearestIndex
1033 srcval
.peBlue
) << (4*(1-(x
&1))) );
1042 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1043 dstbits
+= linebytes
;
1053 const void* srcbits
;
1054 const WORD
* srcpixel
;
1057 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1059 if (bmpImage
->green_mask
==0x03e0) {
1060 if (bmpImage
->red_mask
==0x7c00) {
1061 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1062 for (h
=0; h
<lines
; h
++) {
1067 for (x
=0; x
<width
; x
++) {
1070 dstval
|=(X11DRV_DIB_GetNearestIndex
1072 ((srcval
>> 7) & 0xf8) | /* r */
1073 ((srcval
>> 12) & 0x07),
1074 ((srcval
>> 2) & 0xf8) | /* g */
1075 ((srcval
>> 7) & 0x07),
1076 ((srcval
<< 3) & 0xf8) | /* b */
1077 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1086 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1087 dstbits
+= linebytes
;
1089 } else if (bmpImage
->blue_mask
==0x7c00) {
1090 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1091 for (h
=0; h
<lines
; h
++) {
1096 for (x
=0; x
<width
; x
++) {
1099 dstval
|=(X11DRV_DIB_GetNearestIndex
1101 ((srcval
<< 3) & 0xf8) | /* r */
1102 ((srcval
>> 2) & 0x07),
1103 ((srcval
>> 2) & 0xf8) | /* g */
1104 ((srcval
>> 7) & 0x07),
1105 ((srcval
>> 7) & 0xf8) | /* b */
1106 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1115 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1116 dstbits
+= linebytes
;
1121 } else if (bmpImage
->green_mask
==0x07e0) {
1122 if (bmpImage
->red_mask
==0xf800) {
1123 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1124 for (h
=0; h
<lines
; h
++) {
1129 for (x
=0; x
<width
; x
++) {
1132 dstval
|=(X11DRV_DIB_GetNearestIndex
1134 ((srcval
>> 8) & 0xf8) | /* r */
1135 ((srcval
>> 13) & 0x07),
1136 ((srcval
>> 3) & 0xfc) | /* g */
1137 ((srcval
>> 9) & 0x03),
1138 ((srcval
<< 3) & 0xf8) | /* b */
1139 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1148 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1149 dstbits
+= linebytes
;
1151 } else if (bmpImage
->blue_mask
==0xf800) {
1152 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1153 for (h
=0; h
<lines
; h
++) {
1158 for (x
=0; x
<width
; x
++) {
1161 dstval
|=(X11DRV_DIB_GetNearestIndex
1163 ((srcval
<< 3) & 0xf8) | /* r */
1164 ((srcval
>> 2) & 0x07),
1165 ((srcval
>> 3) & 0xfc) | /* g */
1166 ((srcval
>> 9) & 0x03),
1167 ((srcval
>> 8) & 0xf8) | /* b */
1168 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1177 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1178 dstbits
+= linebytes
;
1190 if (bmpImage
->bits_per_pixel
==24) {
1191 const void* srcbits
;
1192 const BYTE
*srcbyte
;
1195 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1197 if (bmpImage
->green_mask
!=0x00ff00 ||
1198 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1200 } else if (bmpImage
->blue_mask
==0xff) {
1201 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1202 for (h
=0; h
<lines
; h
++) {
1205 for (x
=0; x
<width
/2; x
++) {
1206 /* Do 2 pixels at a time */
1207 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1212 X11DRV_DIB_GetNearestIndex
1220 /* And the the odd pixel */
1221 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1227 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1228 dstbits
+= linebytes
;
1231 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1232 for (h
=0; h
<lines
; h
++) {
1235 for (x
=0; x
<width
/2; x
++) {
1236 /* Do 2 pixels at a time */
1237 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1242 X11DRV_DIB_GetNearestIndex
1250 /* And the the odd pixel */
1251 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1257 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1258 dstbits
+= linebytes
;
1267 const void* srcbits
;
1268 const BYTE
*srcbyte
;
1271 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1273 if (bmpImage
->green_mask
!=0x00ff00 ||
1274 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1276 } else if (bmpImage
->blue_mask
==0xff) {
1277 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1278 for (h
=0; h
<lines
; h
++) {
1281 for (x
=0; x
<width
/2; x
++) {
1282 /* Do 2 pixels at a time */
1283 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1288 X11DRV_DIB_GetNearestIndex
1296 /* And the the odd pixel */
1297 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1303 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1304 dstbits
+= linebytes
;
1307 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1308 for (h
=0; h
<lines
; h
++) {
1311 for (x
=0; x
<width
/2; x
++) {
1312 /* Do 2 pixels at a time */
1313 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1318 X11DRV_DIB_GetNearestIndex
1326 /* And the the odd pixel */
1327 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1333 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1334 dstbits
+= linebytes
;
1345 /* ==== any bmp format -> pal 4 dib ==== */
1346 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1347 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1348 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1349 for (h
=lines
-1; h
>=0; h
--) {
1351 for (x
=0; x
<(width
& ~1); x
+=2) {
1352 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1353 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1356 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1358 dstbits
+= linebytes
;
1365 /***********************************************************************
1366 * X11DRV_DIB_SetImageBits_RLE4
1368 * SetDIBits for a 4-bit deep compressed DIB.
1370 static void X11DRV_DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
,
1371 DWORD srcwidth
, DWORD dstwidth
,
1372 int left
, int *colors
,
1375 unsigned int x
= 0, width
= min(srcwidth
, dstwidth
);
1376 int y
= lines
- 1, c
, length
;
1377 const BYTE
*begin
= bits
;
1382 if (length
) { /* encoded */
1385 if (x
>= (left
+ width
)) break;
1386 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1388 if (!length
--) break;
1389 if (x
>= (left
+ width
)) break;
1390 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1410 default: /* absolute */
1413 if (x
>= left
&& x
< (left
+ width
))
1414 XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1416 if (!length
--) break;
1417 if (x
>= left
&& x
< (left
+ width
))
1418 XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1421 if ((bits
- begin
) & 1)
1430 /***********************************************************************
1431 * X11DRV_DIB_SetImageBits_8
1433 * SetDIBits for an 8-bit deep DIB.
1435 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1436 DWORD srcwidth
, DWORD dstwidth
, int left
,
1437 const int *colors
, XImage
*bmpImage
,
1441 int h
, width
= min(srcwidth
, dstwidth
);
1442 const BYTE
* srcbyte
;
1448 srcbits
= srcbits
+ linebytes
* (lines
-1);
1449 linebytes
= -linebytes
;
1454 switch (bmpImage
->depth
) {
1457 #if defined(__i386__) && defined(__GNUC__)
1458 /* Some X servers might have 32 bit/ 16bit deep pixel */
1459 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1460 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1462 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1463 /* FIXME: Does this really handle all these cases correctly? */
1464 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1465 for (h
= lines
; h
--; ) {
1466 int _cl1
,_cl2
; /* temp outputs for asm below */
1467 /* Borrowed from DirectDraw */
1468 __asm__
__volatile__(
1473 " movw (%%edx,%%eax,4),%%ax\n"
1475 " xor %%eax,%%eax\n"
1477 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1482 :"eax", "cc", "memory"
1484 srcbyte
= (srcbits
+= linebytes
);
1485 dstbits
-= bmpImage
->bytes_per_line
;
1493 #if defined(__i386__) && defined(__GNUC__)
1494 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1495 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1497 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1498 /* FIXME: Does this really handle both cases correctly? */
1499 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1500 for (h
= lines
; h
--; ) {
1501 int _cl1
,_cl2
; /* temp outputs for asm below */
1502 /* Borrowed from DirectDraw */
1503 __asm__
__volatile__(
1508 " movl (%%edx,%%eax,4),%%eax\n"
1510 " xor %%eax,%%eax\n"
1512 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1517 :"eax", "cc", "memory"
1519 srcbyte
= (srcbits
+= linebytes
);
1520 dstbits
-= bmpImage
->bytes_per_line
;
1527 break; /* use slow generic case below */
1530 /* ==== pal 8 dib -> any bmp format ==== */
1531 for (h
=lines
-1; h
>=0; h
--) {
1532 for (x
=left
; x
<width
+left
; x
++) {
1533 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1535 srcbyte
= (srcbits
+= linebytes
);
1539 /***********************************************************************
1540 * X11DRV_DIB_GetImageBits_8
1542 * GetDIBits for an 8-bit deep DIB.
1544 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1545 DWORD srcwidth
, DWORD dstwidth
,
1546 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1547 XImage
*bmpImage
, DWORD linebytes
)
1550 int h
, width
= min(srcwidth
, dstwidth
);
1556 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1557 linebytes
= -linebytes
;
1562 * This condition is true when GetImageBits has been called by
1563 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1564 * 256 colormaps, so we'll just use for for GetDIBits calls.
1565 * (In somes cases, in a updateDIBSection, the returned colors are bad too)
1567 if (!srccolors
) goto updatesection
;
1569 switch (bmpImage
->depth
) {
1572 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
1574 /* ==== pal 1 bmp -> pal 8 dib ==== */
1575 /* ==== pal 4 bmp -> pal 8 dib ==== */
1576 for (h
=lines
-1; h
>=0; h
--) {
1578 for (x
=0; x
<width
; x
++) {
1579 PALETTEENTRY srcval
;
1580 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1581 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1586 dstbits
+= linebytes
;
1594 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
1595 /* ==== pal 8 bmp -> pal 8 dib ==== */
1596 const void* srcbits
;
1597 const BYTE
* srcpixel
;
1599 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1600 for (h
=0; h
<lines
; h
++) {
1603 for (x
= 0; x
< width
; x
++) {
1604 PALETTEENTRY srcval
;
1605 srcval
=srccolors
[(int)*srcpixel
++];
1606 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1611 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1612 dstbits
+= linebytes
;
1622 const void* srcbits
;
1623 const WORD
* srcpixel
;
1626 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1628 if (bmpImage
->green_mask
==0x03e0) {
1629 if (bmpImage
->red_mask
==0x7c00) {
1630 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1631 for (h
=0; h
<lines
; h
++) {
1634 for (x
=0; x
<width
; x
++) {
1637 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1639 ((srcval
>> 7) & 0xf8) | /* r */
1640 ((srcval
>> 12) & 0x07),
1641 ((srcval
>> 2) & 0xf8) | /* g */
1642 ((srcval
>> 7) & 0x07),
1643 ((srcval
<< 3) & 0xf8) | /* b */
1644 ((srcval
>> 2) & 0x07) );
1646 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1647 dstbits
+= linebytes
;
1649 } else if (bmpImage
->blue_mask
==0x7c00) {
1650 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1651 for (h
=0; h
<lines
; h
++) {
1654 for (x
=0; x
<width
; x
++) {
1657 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1659 ((srcval
<< 3) & 0xf8) | /* r */
1660 ((srcval
>> 2) & 0x07),
1661 ((srcval
>> 2) & 0xf8) | /* g */
1662 ((srcval
>> 7) & 0x07),
1663 ((srcval
>> 7) & 0xf8) | /* b */
1664 ((srcval
>> 12) & 0x07) );
1666 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1667 dstbits
+= linebytes
;
1672 } else if (bmpImage
->green_mask
==0x07e0) {
1673 if (bmpImage
->red_mask
==0xf800) {
1674 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1675 for (h
=0; h
<lines
; h
++) {
1678 for (x
=0; x
<width
; x
++) {
1681 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1683 ((srcval
>> 8) & 0xf8) | /* r */
1684 ((srcval
>> 13) & 0x07),
1685 ((srcval
>> 3) & 0xfc) | /* g */
1686 ((srcval
>> 9) & 0x03),
1687 ((srcval
<< 3) & 0xf8) | /* b */
1688 ((srcval
>> 2) & 0x07) );
1690 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1691 dstbits
+= linebytes
;
1693 } else if (bmpImage
->blue_mask
==0xf800) {
1694 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1695 for (h
=0; h
<lines
; h
++) {
1698 for (x
=0; x
<width
; x
++) {
1701 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1703 ((srcval
<< 3) & 0xf8) | /* r */
1704 ((srcval
>> 2) & 0x07),
1705 ((srcval
>> 3) & 0xfc) | /* g */
1706 ((srcval
>> 9) & 0x03),
1707 ((srcval
>> 8) & 0xf8) | /* b */
1708 ((srcval
>> 13) & 0x07) );
1710 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1711 dstbits
+= linebytes
;
1725 const void* srcbits
;
1726 const BYTE
*srcbyte
;
1728 int bytes_per_pixel
;
1730 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1731 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1733 if (bmpImage
->green_mask
!=0x00ff00 ||
1734 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1736 } else if (bmpImage
->blue_mask
==0xff) {
1737 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1738 for (h
=0; h
<lines
; h
++) {
1741 for (x
=0; x
<width
; x
++) {
1742 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1747 srcbyte
+=bytes_per_pixel
;
1749 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1750 dstbits
+= linebytes
;
1753 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1754 for (h
=0; h
<lines
; h
++) {
1757 for (x
=0; x
<width
; x
++) {
1758 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1763 srcbyte
+=bytes_per_pixel
;
1765 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1766 dstbits
+= linebytes
;
1774 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1775 bmpImage
->depth
, bmpImage
->red_mask
,
1776 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1778 /* ==== any bmp format -> pal 8 dib ==== */
1779 for (h
=lines
-1; h
>=0; h
--) {
1781 for (x
=0; x
<width
; x
++) {
1782 *dstbyte
=X11DRV_DIB_MapColor
1784 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1787 dstbits
+= linebytes
;
1793 /***********************************************************************
1794 * X11DRV_DIB_SetImageBits_RLE8
1796 * SetDIBits for an 8-bit deep compressed DIB.
1798 * This function rewritten 941113 by James Youngman. WINE blew out when I
1799 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1801 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1802 * 'End of bitmap' escape code. This code is very much laxer in what it
1803 * allows to end the expansion. Possibly too lax. See the note by
1804 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1805 * bitmap should end with RleEnd, but on the other hand, software exists
1806 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1809 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1810 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1813 static void X11DRV_DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
,
1814 DWORD srcwidth
, DWORD dstwidth
,
1815 int left
, int *colors
,
1818 unsigned int x
; /* X-position on each line. Increases. */
1819 int y
; /* Line #. Starts at lines-1, decreases */
1820 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
1821 BYTE length
; /* The length pf a run */
1822 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
1825 * Note that the bitmap data is stored by Windows starting at the
1826 * bottom line of the bitmap and going upwards. Within each line,
1827 * the data is stored left-to-right. That's the reason why line
1828 * goes from lines-1 to 0. [JAY]
1838 * If the length byte is not zero (which is the escape value),
1839 * We have a run of length pixels all the same colour. The colour
1840 * index is stored next.
1842 * If the length byte is zero, we need to read the next byte to
1843 * know what to do. [JAY]
1848 * [Run-Length] Encoded mode
1850 int color
= colors
[*pIn
++];
1851 while (length
-- && x
< (left
+ dstwidth
)) {
1852 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1859 * Escape codes (may be an absolute sequence though)
1861 escape_code
= (*pIn
++);
1870 /* Not all RLE8 bitmaps end with this code. For
1871 * example, Paint Shop Pro produces some that don't.
1872 * That's (I think) what caused the previous
1873 * implementation to fail. [JAY]
1882 default: /* switch to absolute mode */
1883 length
= escape_code
;
1886 int color
= colors
[*pIn
++];
1887 if (x
>= (left
+ dstwidth
))
1892 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1896 * If you think for a moment you'll realise that the
1897 * only time we could ever possibly read an odd
1898 * number of bytes is when there is a 0x00 (escape),
1899 * a value >0x02 (absolute mode) and then an odd-
1900 * length run. Therefore this is the only place we
1901 * need to worry about it. Everywhere else the
1902 * bytes are always read in pairs. [JAY]
1904 if (escape_code
& 1) pIn
++; /* Throw away the pad byte. */
1906 } /* switch (escape_code) : Escape sequence */
1912 /***********************************************************************
1913 * X11DRV_DIB_SetImageBits_16
1915 * SetDIBits for a 16-bit deep DIB.
1917 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1918 DWORD srcwidth
, DWORD dstwidth
, int left
,
1919 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1920 XImage
*bmpImage
, DWORD linebytes
)
1923 int h
, width
= min(srcwidth
, dstwidth
);
1924 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1929 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1930 linebytes
= -linebytes
;
1933 switch (bmpImage
->depth
)
1940 srcbits
=srcbits
+left
*2;
1941 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1943 if (bmpImage
->green_mask
==0x03e0) {
1944 if (gSrc
==bmpImage
->green_mask
) {
1945 if (rSrc
==bmpImage
->red_mask
) {
1946 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1947 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1948 convs
->Convert_5x5_asis
1951 dstbits
,-bmpImage
->bytes_per_line
);
1952 } else if (rSrc
==bmpImage
->blue_mask
) {
1953 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1954 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1955 convs
->Convert_555_reverse
1958 dstbits
,-bmpImage
->bytes_per_line
);
1961 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1962 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1963 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1964 convs
->Convert_565_to_555_asis
1967 dstbits
,-bmpImage
->bytes_per_line
);
1969 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1970 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1971 convs
->Convert_565_to_555_reverse
1974 dstbits
,-bmpImage
->bytes_per_line
);
1977 } else if (bmpImage
->green_mask
==0x07e0) {
1978 if (gSrc
==bmpImage
->green_mask
) {
1979 if (rSrc
==bmpImage
->red_mask
) {
1980 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
1981 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
1982 convs
->Convert_5x5_asis
1985 dstbits
,-bmpImage
->bytes_per_line
);
1987 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
1988 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
1989 convs
->Convert_565_reverse
1992 dstbits
,-bmpImage
->bytes_per_line
);
1995 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1996 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
1997 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
1998 convs
->Convert_555_to_565_asis
2001 dstbits
,-bmpImage
->bytes_per_line
);
2003 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
2004 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
2005 convs
->Convert_555_to_565_reverse
2008 dstbits
,-bmpImage
->bytes_per_line
);
2018 if (bmpImage
->bits_per_pixel
==24) {
2021 srcbits
=srcbits
+left
*2;
2022 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2024 if (bmpImage
->green_mask
!=0x00ff00 ||
2025 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2027 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2028 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2030 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2031 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2032 convs
->Convert_555_to_888_asis
2035 dstbits
,-bmpImage
->bytes_per_line
);
2037 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2038 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2039 convs
->Convert_565_to_888_asis
2042 dstbits
,-bmpImage
->bytes_per_line
);
2046 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2047 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2048 convs
->Convert_555_to_888_reverse
2051 dstbits
,-bmpImage
->bytes_per_line
);
2053 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2054 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2055 convs
->Convert_565_to_888_reverse
2058 dstbits
,-bmpImage
->bytes_per_line
);
2069 srcbits
=srcbits
+left
*2;
2070 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2072 if (bmpImage
->green_mask
!=0x00ff00 ||
2073 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2075 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2076 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2078 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2079 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2080 convs
->Convert_555_to_0888_asis
2083 dstbits
,-bmpImage
->bytes_per_line
);
2085 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2086 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2087 convs
->Convert_565_to_0888_asis
2090 dstbits
,-bmpImage
->bytes_per_line
);
2094 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2095 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2096 convs
->Convert_555_to_0888_reverse
2099 dstbits
,-bmpImage
->bytes_per_line
);
2101 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2102 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2103 convs
->Convert_565_to_0888_reverse
2106 dstbits
,-bmpImage
->bytes_per_line
);
2114 WARN("from 16 bit DIB (%lx,%lx,%lx) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2115 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2116 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2122 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2123 const WORD
* srcpixel
;
2124 int rShift1
,gShift1
,bShift1
;
2125 int rShift2
,gShift2
,bShift2
;
2128 /* Set color scaling values */
2129 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
2130 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
2131 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
2136 /* Green has 5 bits, like the others */
2140 /* Green has 6 bits, not 5. Compensate. */
2149 /* We could split it into four separate cases to optimize
2150 * but it is probably not worth it.
2152 for (h
=lines
-1; h
>=0; h
--) {
2153 srcpixel
=(const WORD
*)srcbits
;
2154 for (x
=left
; x
<width
+left
; x
++) {
2156 BYTE red
,green
,blue
;
2157 srcval
=*srcpixel
++ << 16;
2158 red
= ((srcval
>> rShift1
) & 0xf8) |
2159 ((srcval
>> rShift2
) & 0x07);
2160 green
=((srcval
>> gShift1
) & gMask1
) |
2161 ((srcval
>> gShift2
) & gMask2
);
2162 blue
= ((srcval
>> bShift1
) & 0xf8) |
2163 ((srcval
>> bShift2
) & 0x07);
2164 XPutPixel(bmpImage
, x
, h
,
2165 X11DRV_PALETTE_ToPhysical
2166 (physDev
, RGB(red
,green
,blue
)));
2168 srcbits
+= linebytes
;
2176 /***********************************************************************
2177 * X11DRV_DIB_GetImageBits_16
2179 * GetDIBits for an 16-bit deep DIB.
2181 static void X11DRV_DIB_GetImageBits_16( int lines
, BYTE
*dstbits
,
2182 DWORD dstwidth
, DWORD srcwidth
,
2183 PALETTEENTRY
*srccolors
,
2184 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2185 XImage
*bmpImage
, DWORD dibpitch
)
2188 int h
, width
= min(srcwidth
, dstwidth
);
2189 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2191 DWORD linebytes
= dibpitch
;
2196 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
2197 linebytes
= -linebytes
;
2200 switch (bmpImage
->depth
)
2205 const char* srcbits
;
2207 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2209 if (bmpImage
->green_mask
==0x03e0) {
2210 if (gDst
==bmpImage
->green_mask
) {
2211 if (rDst
==bmpImage
->red_mask
) {
2212 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2213 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2214 convs
->Convert_5x5_asis
2216 srcbits
,-bmpImage
->bytes_per_line
,
2219 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2220 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2221 convs
->Convert_555_reverse
2223 srcbits
,-bmpImage
->bytes_per_line
,
2227 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2228 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2229 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2230 convs
->Convert_555_to_565_asis
2232 srcbits
,-bmpImage
->bytes_per_line
,
2235 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2236 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2237 convs
->Convert_555_to_565_reverse
2239 srcbits
,-bmpImage
->bytes_per_line
,
2243 } else if (bmpImage
->green_mask
==0x07e0) {
2244 if (gDst
==bmpImage
->green_mask
) {
2245 if (rDst
== bmpImage
->red_mask
) {
2246 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2247 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2248 convs
->Convert_5x5_asis
2250 srcbits
,-bmpImage
->bytes_per_line
,
2253 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2254 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2255 convs
->Convert_565_reverse
2257 srcbits
,-bmpImage
->bytes_per_line
,
2261 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2262 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2263 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2264 convs
->Convert_565_to_555_asis
2266 srcbits
,-bmpImage
->bytes_per_line
,
2269 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2270 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2271 convs
->Convert_565_to_555_reverse
2273 srcbits
,-bmpImage
->bytes_per_line
,
2284 if (bmpImage
->bits_per_pixel
== 24) {
2285 const char* srcbits
;
2287 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2289 if (bmpImage
->green_mask
!=0x00ff00 ||
2290 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2292 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2293 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2295 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2296 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2297 convs
->Convert_888_to_555_asis
2299 srcbits
,-bmpImage
->bytes_per_line
,
2302 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2303 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2304 convs
->Convert_888_to_565_asis
2306 srcbits
,-bmpImage
->bytes_per_line
,
2311 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2312 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2313 convs
->Convert_888_to_555_reverse
2315 srcbits
,-bmpImage
->bytes_per_line
,
2318 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2319 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2320 convs
->Convert_888_to_565_reverse
2322 srcbits
,-bmpImage
->bytes_per_line
,
2332 const char* srcbits
;
2334 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2336 if (bmpImage
->green_mask
!=0x00ff00 ||
2337 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2339 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2340 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2342 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2343 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2344 convs
->Convert_0888_to_555_asis
2346 srcbits
,-bmpImage
->bytes_per_line
,
2349 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2350 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2351 convs
->Convert_0888_to_565_asis
2353 srcbits
,-bmpImage
->bytes_per_line
,
2358 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2359 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2360 convs
->Convert_0888_to_555_reverse
2362 srcbits
,-bmpImage
->bytes_per_line
,
2365 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2366 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2367 convs
->Convert_0888_to_565_reverse
2369 srcbits
,-bmpImage
->bytes_per_line
,
2378 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
2379 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2380 int rShift
,gShift
,bShift
;
2383 /* Shift everything 16 bits left so that all shifts are >0,
2384 * even for BGR DIBs. Then a single >> 16 will bring everything
2387 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2388 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2389 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2391 /* 6 bits for the green */
2397 for (h
= lines
- 1; h
>= 0; h
--) {
2398 dstpixel
=(LPWORD
)dstbits
;
2399 for (x
= 0; x
< width
; x
++) {
2400 PALETTEENTRY srcval
;
2402 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2403 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2404 ((srcval
.peGreen
<< gShift
) & gDst
) |
2405 ((srcval
.peBlue
<< bShift
) & bDst
);
2406 *dstpixel
++=dstval
>> 16;
2408 dstbits
+= linebytes
;
2416 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
2417 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2418 int rShift
,gShift
,bShift
;
2419 const BYTE
* srcbits
;
2420 const BYTE
* srcpixel
;
2423 /* Shift everything 16 bits left so that all shifts are >0,
2424 * even for BGR DIBs. Then a single >> 16 will bring everything
2427 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2428 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2429 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2431 /* 6 bits for the green */
2437 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2438 for (h
=0; h
<lines
; h
++) {
2440 dstpixel
=(LPWORD
)dstbits
;
2441 for (x
= 0; x
< width
; x
++) {
2442 PALETTEENTRY srcval
;
2444 srcval
=srccolors
[(int)*srcpixel
++];
2445 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2446 ((srcval
.peGreen
<< gShift
) & gDst
) |
2447 ((srcval
.peBlue
<< bShift
) & bDst
);
2448 *dstpixel
++=dstval
>> 16;
2450 srcbits
-= bmpImage
->bytes_per_line
;
2451 dstbits
+= linebytes
;
2461 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2462 int rShift
,gShift
,bShift
;
2465 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%lx,%lx,%lx)\n",
2466 bmpImage
->depth
, bmpImage
->red_mask
,
2467 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2470 /* Shift everything 16 bits left so that all shifts are >0,
2471 * even for BGR DIBs. Then a single >> 16 will bring everything
2474 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2475 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2476 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2478 /* 6 bits for the green */
2484 for (h
= lines
- 1; h
>= 0; h
--) {
2485 dstpixel
=(LPWORD
)dstbits
;
2486 for (x
= 0; x
< width
; x
++) {
2489 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
2490 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2491 ((GetGValue(srcval
) << gShift
) & gDst
) |
2492 ((GetBValue(srcval
) << bShift
) & bDst
);
2493 *dstpixel
++=dstval
>> 16;
2495 dstbits
+= linebytes
;
2503 /***********************************************************************
2504 * X11DRV_DIB_SetImageBits_24
2506 * SetDIBits for a 24-bit deep DIB.
2508 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2509 DWORD srcwidth
, DWORD dstwidth
, int left
,
2510 X11DRV_PDEVICE
*physDev
,
2511 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2512 XImage
*bmpImage
, DWORD linebytes
)
2515 int h
, width
= min(srcwidth
, dstwidth
);
2516 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2521 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2522 linebytes
= -linebytes
;
2525 switch (bmpImage
->depth
)
2528 if (bmpImage
->bits_per_pixel
==24) {
2531 srcbits
=srcbits
+left
*3;
2532 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2534 if (bmpImage
->green_mask
!=0x00ff00 ||
2535 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2537 } else if (rSrc
==bmpImage
->red_mask
) {
2538 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2539 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2540 convs
->Convert_888_asis
2543 dstbits
,-bmpImage
->bytes_per_line
);
2545 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2546 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2547 convs
->Convert_888_reverse
2550 dstbits
,-bmpImage
->bytes_per_line
);
2560 srcbits
=srcbits
+left
*3;
2561 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2563 if (bmpImage
->green_mask
!=0x00ff00 ||
2564 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2566 } else if (rSrc
==bmpImage
->red_mask
) {
2567 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2568 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2569 convs
->Convert_888_to_0888_asis
2572 dstbits
,-bmpImage
->bytes_per_line
);
2574 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2575 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2576 convs
->Convert_888_to_0888_reverse
2579 dstbits
,-bmpImage
->bytes_per_line
);
2589 srcbits
=srcbits
+left
*3;
2590 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2592 if (bmpImage
->green_mask
==0x03e0) {
2593 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2594 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2595 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2596 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2597 convs
->Convert_888_to_555_asis
2600 dstbits
,-bmpImage
->bytes_per_line
);
2601 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2602 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2603 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2604 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2605 convs
->Convert_888_to_555_reverse
2608 dstbits
,-bmpImage
->bytes_per_line
);
2612 } else if (bmpImage
->green_mask
==0x07e0) {
2613 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2614 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2615 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2616 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2617 convs
->Convert_888_to_565_asis
2620 dstbits
,-bmpImage
->bytes_per_line
);
2621 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2622 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2623 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2624 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2625 convs
->Convert_888_to_565_reverse
2628 dstbits
,-bmpImage
->bytes_per_line
);
2640 WARN("from 24 bit DIB (%lx,%lx,%lx) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2641 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2642 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2648 /* ==== rgb 888 dib -> any bmp bormat ==== */
2649 const BYTE
* srcbyte
;
2651 /* Windows only supports one 24bpp DIB format: RGB888 */
2653 for (h
= lines
- 1; h
>= 0; h
--) {
2654 srcbyte
=(const BYTE
*)srcbits
;
2655 for (x
= left
; x
< width
+left
; x
++) {
2656 XPutPixel(bmpImage
, x
, h
,
2657 X11DRV_PALETTE_ToPhysical
2658 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2661 srcbits
+= linebytes
;
2669 /***********************************************************************
2670 * X11DRV_DIB_GetImageBits_24
2672 * GetDIBits for an 24-bit deep DIB.
2674 static void X11DRV_DIB_GetImageBits_24( int lines
, BYTE
*dstbits
,
2675 DWORD dstwidth
, DWORD srcwidth
,
2676 PALETTEENTRY
*srccolors
,
2677 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2678 XImage
*bmpImage
, DWORD linebytes
)
2681 int h
, width
= min(srcwidth
, dstwidth
);
2682 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2687 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2688 linebytes
= -linebytes
;
2691 switch (bmpImage
->depth
)
2694 if (bmpImage
->bits_per_pixel
==24) {
2695 const char* srcbits
;
2697 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2699 if (bmpImage
->green_mask
!=0x00ff00 ||
2700 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2702 } else if (rDst
==bmpImage
->red_mask
) {
2703 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2704 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2705 convs
->Convert_888_asis
2707 srcbits
,-bmpImage
->bytes_per_line
,
2710 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2711 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2712 convs
->Convert_888_reverse
2714 srcbits
,-bmpImage
->bytes_per_line
,
2723 const char* srcbits
;
2725 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2727 if (bmpImage
->green_mask
!=0x00ff00 ||
2728 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2730 } else if (rDst
==bmpImage
->red_mask
) {
2731 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2732 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2733 convs
->Convert_0888_to_888_asis
2735 srcbits
,-bmpImage
->bytes_per_line
,
2738 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2739 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2740 convs
->Convert_0888_to_888_reverse
2742 srcbits
,-bmpImage
->bytes_per_line
,
2751 const char* srcbits
;
2753 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2755 if (bmpImage
->green_mask
==0x03e0) {
2756 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2757 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2758 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2759 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2760 convs
->Convert_555_to_888_asis
2762 srcbits
,-bmpImage
->bytes_per_line
,
2764 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2765 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2766 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2767 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2768 convs
->Convert_555_to_888_reverse
2770 srcbits
,-bmpImage
->bytes_per_line
,
2775 } else if (bmpImage
->green_mask
==0x07e0) {
2776 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2777 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2778 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2779 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2780 convs
->Convert_565_to_888_asis
2782 srcbits
,-bmpImage
->bytes_per_line
,
2784 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2785 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2786 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2787 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2788 convs
->Convert_565_to_888_reverse
2790 srcbits
,-bmpImage
->bytes_per_line
,
2803 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
2804 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2807 /* Windows only supports one 24bpp DIB format: rgb 888 */
2808 for (h
= lines
- 1; h
>= 0; h
--) {
2810 for (x
= 0; x
< width
; x
++) {
2811 PALETTEENTRY srcval
;
2812 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2813 dstbyte
[0]=srcval
.peBlue
;
2814 dstbyte
[1]=srcval
.peGreen
;
2815 dstbyte
[2]=srcval
.peRed
;
2818 dstbits
+= linebytes
;
2826 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
== 0 && srccolors
) {
2827 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2828 const void* srcbits
;
2829 const BYTE
* srcpixel
;
2832 /* Windows only supports one 24bpp DIB format: rgb 888 */
2833 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2834 for (h
= lines
- 1; h
>= 0; h
--) {
2837 for (x
= 0; x
< width
; x
++ ) {
2838 PALETTEENTRY srcval
;
2839 srcval
=srccolors
[(int)*srcpixel
++];
2840 dstbyte
[0]=srcval
.peBlue
;
2841 dstbyte
[1]=srcval
.peGreen
;
2842 dstbyte
[2]=srcval
.peRed
;
2845 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2846 dstbits
+= linebytes
;
2856 /* ==== any bmp format -> 888 dib ==== */
2859 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%lx,%lx,%lx)\n",
2860 bmpImage
->depth
, bmpImage
->red_mask
,
2861 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2864 /* Windows only supports one 24bpp DIB format: rgb 888 */
2865 for (h
= lines
- 1; h
>= 0; h
--) {
2867 for (x
= 0; x
< width
; x
++) {
2868 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2869 (XGetPixel( bmpImage
, x
, h
));
2870 dstbyte
[0]=GetBValue(srcval
);
2871 dstbyte
[1]=GetGValue(srcval
);
2872 dstbyte
[2]=GetRValue(srcval
);
2875 dstbits
+= linebytes
;
2883 /***********************************************************************
2884 * X11DRV_DIB_SetImageBits_32
2886 * SetDIBits for a 32-bit deep DIB.
2888 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2889 DWORD srcwidth
, DWORD dstwidth
, int left
,
2890 X11DRV_PDEVICE
*physDev
,
2891 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2897 int h
, width
= min(srcwidth
, dstwidth
);
2898 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2903 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2904 linebytes
= -linebytes
;
2907 ptr
= (const DWORD
*) srcbits
+ left
;
2909 switch (bmpImage
->depth
)
2912 if (bmpImage
->bits_per_pixel
==24) {
2915 srcbits
=srcbits
+left
*4;
2916 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2918 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2919 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2920 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2921 convs
->Convert_0888_to_888_asis
2924 dstbits
,-bmpImage
->bytes_per_line
);
2925 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2926 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2928 /* the tests below assume sane bmpImage masks */
2929 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2930 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2931 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2932 convs
->Convert_0888_to_888_reverse
2935 dstbits
,-bmpImage
->bytes_per_line
);
2936 } else if (bmpImage
->blue_mask
==0xff) {
2937 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2938 convs
->Convert_any0888_to_rgb888
2942 dstbits
,-bmpImage
->bytes_per_line
);
2944 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2945 convs
->Convert_any0888_to_bgr888
2949 dstbits
,-bmpImage
->bytes_per_line
);
2959 srcbits
=srcbits
+left
*4;
2960 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2962 if (gSrc
==bmpImage
->green_mask
) {
2963 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2964 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2965 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2966 convs
->Convert_0888_asis
2969 dstbits
,-bmpImage
->bytes_per_line
);
2970 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2971 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2973 /* the tests below assume sane bmpImage masks */
2974 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
2975 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2976 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2977 convs
->Convert_0888_reverse
2980 dstbits
,-bmpImage
->bytes_per_line
);
2982 /* ==== any 0888 dib -> any 0888 bmp ==== */
2983 convs
->Convert_0888_any
2987 dstbits
,-bmpImage
->bytes_per_line
,
2988 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
2990 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2991 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2993 /* the tests below assume sane bmpImage masks */
2995 /* ==== any 0888 dib -> any 0888 bmp ==== */
2996 convs
->Convert_0888_any
3000 dstbits
,-bmpImage
->bytes_per_line
,
3001 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3011 srcbits
=srcbits
+left
*4;
3012 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
3014 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
3015 if (bmpImage
->green_mask
==0x03e0) {
3016 if (bmpImage
->red_mask
==0x7f00) {
3017 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
3018 convs
->Convert_0888_to_555_asis
3021 dstbits
,-bmpImage
->bytes_per_line
);
3022 } else if (bmpImage
->blue_mask
==0x7f00) {
3023 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
3024 convs
->Convert_0888_to_555_reverse
3027 dstbits
,-bmpImage
->bytes_per_line
);
3031 } else if (bmpImage
->green_mask
==0x07e0) {
3032 if (bmpImage
->red_mask
==0xf800) {
3033 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3034 convs
->Convert_0888_to_565_asis
3037 dstbits
,-bmpImage
->bytes_per_line
);
3038 } else if (bmpImage
->blue_mask
==0xf800) {
3039 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3040 convs
->Convert_0888_to_565_reverse
3043 dstbits
,-bmpImage
->bytes_per_line
);
3050 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
3051 if (bmpImage
->green_mask
==0x03e0) {
3052 if (bmpImage
->blue_mask
==0x7f00) {
3053 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3054 convs
->Convert_0888_to_555_asis
3057 dstbits
,-bmpImage
->bytes_per_line
);
3058 } else if (bmpImage
->red_mask
==0x7f00) {
3059 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3060 convs
->Convert_0888_to_555_reverse
3063 dstbits
,-bmpImage
->bytes_per_line
);
3067 } else if (bmpImage
->green_mask
==0x07e0) {
3068 if (bmpImage
->blue_mask
==0xf800) {
3069 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3070 convs
->Convert_0888_to_565_asis
3073 dstbits
,-bmpImage
->bytes_per_line
);
3074 } else if (bmpImage
->red_mask
==0xf800) {
3075 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3076 convs
->Convert_0888_to_565_reverse
3079 dstbits
,-bmpImage
->bytes_per_line
);
3087 if (bmpImage
->green_mask
==0x03e0 &&
3088 (bmpImage
->red_mask
==0x7f00 ||
3089 bmpImage
->blue_mask
==0x7f00)) {
3090 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3091 convs
->Convert_any0888_to_5x5
3095 dstbits
,-bmpImage
->bytes_per_line
,
3096 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3097 } else if (bmpImage
->green_mask
==0x07e0 &&
3098 (bmpImage
->red_mask
==0xf800 ||
3099 bmpImage
->blue_mask
==0xf800)) {
3100 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3101 convs
->Convert_any0888_to_5x5
3105 dstbits
,-bmpImage
->bytes_per_line
,
3106 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3116 WARN("from 32 bit DIB (%lx,%lx,%lx) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3117 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
3118 bmpImage
->green_mask
, bmpImage
->blue_mask
);
3124 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3125 const DWORD
* srcpixel
;
3126 int rShift
,gShift
,bShift
;
3128 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
3129 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
3130 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
3132 for (h
= lines
- 1; h
>= 0; h
--) {
3133 srcpixel
=(const DWORD
*)srcbits
;
3134 for (x
= left
; x
< width
+left
; x
++) {
3136 BYTE red
,green
,blue
;
3137 srcvalue
=*srcpixel
++;
3138 red
= (srcvalue
>> rShift
) & 0xff;
3139 green
=(srcvalue
>> gShift
) & 0xff;
3140 blue
= (srcvalue
>> bShift
) & 0xff;
3141 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
3142 (physDev
, RGB(red
,green
,blue
)));
3144 srcbits
+= linebytes
;
3152 /***********************************************************************
3153 * X11DRV_DIB_GetImageBits_32
3155 * GetDIBits for an 32-bit deep DIB.
3157 static void X11DRV_DIB_GetImageBits_32( int lines
, BYTE
*dstbits
,
3158 DWORD dstwidth
, DWORD srcwidth
,
3159 PALETTEENTRY
*srccolors
,
3160 DWORD rDst
, DWORD gDst
, DWORD bDst
,
3161 XImage
*bmpImage
, DWORD linebytes
)
3164 int h
, width
= min(srcwidth
, dstwidth
);
3166 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
3171 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
3172 linebytes
= -linebytes
;
3177 switch (bmpImage
->depth
)
3180 if (bmpImage
->bits_per_pixel
==24) {
3181 const void* srcbits
;
3183 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3185 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
3186 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3187 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3188 convs
->Convert_888_to_0888_asis
3190 srcbits
,-bmpImage
->bytes_per_line
,
3192 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3193 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3195 /* the tests below assume sane bmpImage masks */
3196 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
3197 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3198 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3199 convs
->Convert_888_to_0888_reverse
3201 srcbits
,-bmpImage
->bytes_per_line
,
3203 } else if (bmpImage
->blue_mask
==0xff) {
3204 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3205 convs
->Convert_rgb888_to_any0888
3207 srcbits
,-bmpImage
->bytes_per_line
,
3211 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3212 convs
->Convert_bgr888_to_any0888
3214 srcbits
,-bmpImage
->bytes_per_line
,
3224 const char* srcbits
;
3226 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3228 if (gDst
==bmpImage
->green_mask
) {
3229 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
3230 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3231 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3232 convs
->Convert_0888_asis
3234 srcbits
,-bmpImage
->bytes_per_line
,
3236 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3237 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3239 /* the tests below assume sane bmpImage masks */
3240 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
3241 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3242 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3243 convs
->Convert_0888_reverse
3245 srcbits
,-bmpImage
->bytes_per_line
,
3248 /* ==== any 0888 bmp -> any 0888 dib ==== */
3249 convs
->Convert_0888_any
3251 srcbits
,-bmpImage
->bytes_per_line
,
3252 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3256 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3257 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3259 /* the tests below assume sane bmpImage masks */
3261 /* ==== any 0888 bmp -> any 0888 dib ==== */
3262 convs
->Convert_0888_any
3264 srcbits
,-bmpImage
->bytes_per_line
,
3265 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3275 const char* srcbits
;
3277 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3279 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
3280 if (bmpImage
->green_mask
==0x03e0) {
3281 if (bmpImage
->red_mask
==0x7f00) {
3282 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3283 convs
->Convert_555_to_0888_asis
3285 srcbits
,-bmpImage
->bytes_per_line
,
3287 } else if (bmpImage
->blue_mask
==0x7f00) {
3288 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3289 convs
->Convert_555_to_0888_reverse
3291 srcbits
,-bmpImage
->bytes_per_line
,
3296 } else if (bmpImage
->green_mask
==0x07e0) {
3297 if (bmpImage
->red_mask
==0xf800) {
3298 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3299 convs
->Convert_565_to_0888_asis
3301 srcbits
,-bmpImage
->bytes_per_line
,
3303 } else if (bmpImage
->blue_mask
==0xf800) {
3304 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3305 convs
->Convert_565_to_0888_reverse
3307 srcbits
,-bmpImage
->bytes_per_line
,
3315 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
3316 if (bmpImage
->green_mask
==0x03e0) {
3317 if (bmpImage
->blue_mask
==0x7f00) {
3318 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3319 convs
->Convert_555_to_0888_asis
3321 srcbits
,-bmpImage
->bytes_per_line
,
3323 } else if (bmpImage
->red_mask
==0x7f00) {
3324 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3325 convs
->Convert_555_to_0888_reverse
3327 srcbits
,-bmpImage
->bytes_per_line
,
3332 } else if (bmpImage
->green_mask
==0x07e0) {
3333 if (bmpImage
->blue_mask
==0xf800) {
3334 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3335 convs
->Convert_565_to_0888_asis
3337 srcbits
,-bmpImage
->bytes_per_line
,
3339 } else if (bmpImage
->red_mask
==0xf800) {
3340 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3341 convs
->Convert_565_to_0888_reverse
3343 srcbits
,-bmpImage
->bytes_per_line
,
3352 if (bmpImage
->green_mask
==0x03e0 &&
3353 (bmpImage
->red_mask
==0x7f00 ||
3354 bmpImage
->blue_mask
==0x7f00)) {
3355 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3356 convs
->Convert_5x5_to_any0888
3358 srcbits
,-bmpImage
->bytes_per_line
,
3359 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3362 } else if (bmpImage
->green_mask
==0x07e0 &&
3363 (bmpImage
->red_mask
==0xf800 ||
3364 bmpImage
->blue_mask
==0xf800)) {
3365 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3366 convs
->Convert_5x5_to_any0888
3368 srcbits
,-bmpImage
->bytes_per_line
,
3369 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3381 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
3382 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3383 int rShift
,gShift
,bShift
;
3386 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3387 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3388 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3389 for (h
= lines
- 1; h
>= 0; h
--) {
3390 dstpixel
=(DWORD
*)dstbits
;
3391 for (x
= 0; x
< width
; x
++) {
3392 PALETTEENTRY srcval
;
3393 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3394 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3395 (srcval
.peGreen
<< gShift
) |
3396 (srcval
.peBlue
<< bShift
);
3398 dstbits
+= linebytes
;
3406 if (bmpImage
->red_mask
==0 && bmpImage
->green_mask
==0 && bmpImage
->blue_mask
==0 && srccolors
) {
3407 /* ==== pal 8 bmp -> any 0888 dib ==== */
3408 int rShift
,gShift
,bShift
;
3409 const void* srcbits
;
3410 const BYTE
* srcpixel
;
3413 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3414 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3415 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3416 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3417 for (h
= lines
- 1; h
>= 0; h
--) {
3419 dstpixel
=(DWORD
*)dstbits
;
3420 for (x
= 0; x
< width
; x
++) {
3421 PALETTEENTRY srcval
;
3422 srcval
=srccolors
[(int)*srcpixel
++];
3423 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3424 (srcval
.peGreen
<< gShift
) |
3425 (srcval
.peBlue
<< bShift
);
3427 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3428 dstbits
+= linebytes
;
3438 /* ==== any bmp format -> any 0888 dib ==== */
3439 int rShift
,gShift
,bShift
;
3442 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%lx,%lx,%lx)\n",
3443 bmpImage
->depth
, bmpImage
->red_mask
,
3444 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3447 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3448 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3449 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3450 for (h
= lines
- 1; h
>= 0; h
--) {
3451 dstpixel
=(DWORD
*)dstbits
;
3452 for (x
= 0; x
< width
; x
++) {
3454 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
3455 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3456 (GetGValue(srcval
) << gShift
) |
3457 (GetBValue(srcval
) << bShift
);
3459 dstbits
+= linebytes
;
3466 static int XGetSubImageErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
3468 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
3471 /***********************************************************************
3472 * X11DRV_DIB_SetImageBits_GetSubImage
3474 * Helper for X11DRV_DIB_SetImageBits
3476 static void X11DRV_DIB_SetImageBits_GetSubImage(
3477 const X11DRV_DIB_IMAGEBITS_DESCR
*descr
, XImage
*bmpImage
)
3479 /* compressed bitmaps may contain gaps in them. So make a copy
3480 * of the existing pixels first */
3483 SetRect( &bmprc
, descr
->xDest
, descr
->yDest
,
3484 descr
->xDest
+ descr
->width
, descr
->yDest
+ descr
->height
);
3485 GetRgnBox( descr
->physDev
->region
, &rc
);
3486 /* convert from dc to drawable origin */
3487 OffsetRect( &rc
, descr
->physDev
->org
.x
, descr
->physDev
->org
.y
);
3488 /* clip visible rect with bitmap */
3489 if( IntersectRect( &rc
, &rc
, &bmprc
))
3491 X11DRV_expect_error( gdi_display
, XGetSubImageErrorHandler
, NULL
);
3492 XGetSubImage( gdi_display
, descr
->drawable
, rc
.left
, rc
.top
,
3493 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, AllPlanes
,
3495 descr
->xSrc
+ rc
.left
- bmprc
.left
,
3496 descr
->ySrc
+ rc
.top
- bmprc
.top
);
3497 X11DRV_check_error();
3501 /***********************************************************************
3502 * X11DRV_DIB_SetImageBits
3504 * Transfer the bits to an X image.
3505 * Helper function for SetDIBits() and SetDIBitsToDevice().
3507 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3509 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3514 bmpImage
= descr
->image
;
3516 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3517 descr
->infoWidth
, lines
, 32, 0 );
3518 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3519 if(bmpImage
->data
== NULL
) {
3520 ERR("Out of memory!\n");
3521 XDestroyImage( bmpImage
);
3522 wine_tsx11_unlock();
3527 TRACE("Dib: depth=%d r=%lx g=%lx b=%lx\n",
3528 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3529 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3530 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3531 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3533 /* Transfer the pixels */
3534 switch(descr
->infoBpp
)
3537 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3538 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3539 bmpImage
, descr
->dibpitch
);
3542 if (descr
->compression
) {
3543 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3544 X11DRV_DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
3545 descr
->infoWidth
, descr
->width
,
3546 descr
->xSrc
, (int *)(descr
->colorMap
),
3549 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3550 descr
->infoWidth
, descr
->width
,
3551 descr
->xSrc
, (int*)(descr
->colorMap
),
3552 bmpImage
, descr
->dibpitch
);
3555 if (descr
->compression
) {
3556 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3557 X11DRV_DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
3558 descr
->infoWidth
, descr
->width
,
3559 descr
->xSrc
, (int *)(descr
->colorMap
),
3562 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3563 descr
->infoWidth
, descr
->width
,
3564 descr
->xSrc
, (int *)(descr
->colorMap
),
3565 bmpImage
, descr
->dibpitch
);
3569 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3570 descr
->infoWidth
, descr
->width
,
3571 descr
->xSrc
, descr
->physDev
,
3572 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3573 bmpImage
, descr
->dibpitch
);
3576 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3577 descr
->infoWidth
, descr
->width
,
3578 descr
->xSrc
, descr
->physDev
,
3579 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3580 bmpImage
, descr
->dibpitch
);
3583 X11DRV_DIB_SetImageBits_32( descr
->lines
, descr
->bits
,
3584 descr
->infoWidth
, descr
->width
,
3585 descr
->xSrc
, descr
->physDev
,
3586 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3587 bmpImage
, descr
->dibpitch
);
3590 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3594 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3595 descr
->drawable
, descr
->gc
, bmpImage
,
3596 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3597 descr
->width
, descr
->height
);
3598 #ifdef HAVE_LIBXXSHM
3601 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3602 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3603 descr
->width
, descr
->height
, FALSE
);
3604 XSync( gdi_display
, 0 );
3608 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3609 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3610 descr
->width
, descr
->height
);
3612 if (!descr
->image
) XDestroyImage( bmpImage
);
3613 wine_tsx11_unlock();
3617 /***********************************************************************
3618 * X11DRV_DIB_GetImageBits
3620 * Transfer the bits from an X image.
3622 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3624 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3629 bmpImage
= descr
->image
;
3631 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3632 descr
->infoWidth
, lines
, 32, 0 );
3633 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3634 if(bmpImage
->data
== NULL
) {
3635 ERR("Out of memory!\n");
3636 XDestroyImage( bmpImage
);
3637 wine_tsx11_unlock();
3642 #ifdef HAVE_LIBXXSHM
3645 int saveRed
, saveGreen
, saveBlue
;
3647 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3648 gdi_display
, descr
->drawable
, bmpImage
,
3649 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3651 /* We must save and restore the bmpImage's masks in order
3652 * to preserve them across the call to XShmGetImage, which
3653 * decides to eleminate them since it doesn't happen to know
3654 * what the format of the image is supposed to be, even though
3656 saveRed
= bmpImage
->red_mask
;
3657 saveBlue
= bmpImage
->blue_mask
;
3658 saveGreen
= bmpImage
->green_mask
;
3660 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3661 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3663 bmpImage
->red_mask
= saveRed
;
3664 bmpImage
->blue_mask
= saveBlue
;
3665 bmpImage
->green_mask
= saveGreen
;
3668 #endif /* HAVE_LIBXXSHM */
3670 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3671 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3672 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3673 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3674 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3675 bmpImage
, descr
->xDest
, descr
->yDest
);
3678 TRACE("Dib: depth=%2d r=%lx g=%lx b=%lx\n",
3679 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3680 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3681 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3682 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3683 /* Transfer the pixels */
3684 switch(descr
->infoBpp
)
3687 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3688 descr
->infoWidth
, descr
->width
,
3689 descr
->colorMap
, descr
->palentry
,
3690 bmpImage
, descr
->dibpitch
);
3694 if (descr
->compression
) {
3695 FIXME("Compression not yet supported!\n");
3696 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 4 ) * abs(descr
->lines
))
3699 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3700 descr
->infoWidth
, descr
->width
,
3701 descr
->colorMap
, descr
->palentry
,
3702 bmpImage
, descr
->dibpitch
);
3705 if (descr
->compression
) {
3706 FIXME("Compression not yet supported!\n");
3707 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 8 ) * abs(descr
->lines
))
3710 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3711 descr
->infoWidth
, descr
->width
,
3712 descr
->colorMap
, descr
->palentry
,
3713 bmpImage
, descr
->dibpitch
);
3717 X11DRV_DIB_GetImageBits_16( descr
->lines
, (LPVOID
)descr
->bits
,
3718 descr
->infoWidth
,descr
->width
,
3720 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3721 bmpImage
, descr
->dibpitch
);
3725 X11DRV_DIB_GetImageBits_24( descr
->lines
, (LPVOID
)descr
->bits
,
3726 descr
->infoWidth
,descr
->width
,
3728 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3729 bmpImage
, descr
->dibpitch
);
3733 X11DRV_DIB_GetImageBits_32( descr
->lines
, (LPVOID
)descr
->bits
,
3734 descr
->infoWidth
, descr
->width
,
3736 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3737 bmpImage
, descr
->dibpitch
);
3741 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3745 if (!descr
->image
) XDestroyImage( bmpImage
);
3746 wine_tsx11_unlock();
3750 /*************************************************************************
3751 * X11DRV_SetDIBitsToDevice
3754 INT
X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE
*physDev
, INT xDest
, INT yDest
, DWORD cx
,
3755 DWORD cy
, INT xSrc
, INT ySrc
,
3756 UINT startscan
, UINT lines
, LPCVOID bits
,
3757 const BITMAPINFO
*info
, UINT coloruse
)
3759 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3766 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3767 &descr
.infoBpp
, &descr
.compression
) == -1)
3770 top_down
= (height
< 0);
3771 if (top_down
) height
= -height
;
3775 LPtoDP(physDev
->hdc
, &pt
, 1);
3777 if (!lines
|| (startscan
>= height
)) return 0;
3778 if (!top_down
&& startscan
+ lines
> height
) lines
= height
- startscan
;
3780 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3781 * and clamp all values to fit inside [startscan,startscan+lines]
3783 if (ySrc
+ cy
<= startscan
+ lines
)
3785 UINT y
= startscan
+ lines
- (ySrc
+ cy
);
3786 if (ySrc
< startscan
) cy
-= (startscan
- ySrc
);
3789 /* avoid getting unnecessary lines */
3791 if (y
>= lines
) return 0;
3796 if (y
>= lines
) return lines
;
3797 ySrc
= y
; /* need to get all lines in top down mode */
3802 if (ySrc
>= startscan
+ lines
) return lines
;
3803 pt
.y
+= ySrc
+ cy
- (startscan
+ lines
);
3804 cy
= startscan
+ lines
- ySrc
;
3806 if (cy
> lines
) cy
= lines
;
3808 if (xSrc
>= width
) return lines
;
3809 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
3810 if (!cx
|| !cy
) return lines
;
3812 /* Update the pixmap from the DIB section */
3813 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
, FALSE
);
3815 X11DRV_SetupGCForText( physDev
); /* To have the correct colors */
3817 XSetFunction(gdi_display
, physDev
->gc
, X11DRV_XROPfunction
[GetROP2(physDev
->hdc
) - 1]);
3818 wine_tsx11_unlock();
3820 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
3822 switch (descr
.infoBpp
)
3827 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3828 coloruse
== DIB_PAL_COLORS
? physDev
: NULL
, coloruse
,
3829 physDev
->depth
, info
, &descr
.nColorMap
);
3830 if (!descr
.colorMap
) return 0;
3831 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3835 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
) : 0x7c00;
3836 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
+ 1) : 0x03e0;
3837 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
+ 2) : 0x001f;
3843 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
) : 0xff0000;
3844 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
+ 1) : 0x00ff00;
3845 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
+ 2) : 0x0000ff;
3850 descr
.physDev
= physDev
;
3853 descr
.palentry
= NULL
;
3854 descr
.lines
= top_down
? -lines
: lines
;
3855 descr
.infoWidth
= width
;
3856 descr
.depth
= physDev
->depth
;
3857 descr
.drawable
= physDev
->drawable
;
3858 descr
.gc
= physDev
->gc
;
3861 descr
.xDest
= physDev
->org
.x
+ pt
.x
;
3862 descr
.yDest
= physDev
->org
.y
+ pt
.y
;
3865 descr
.useShm
= FALSE
;
3866 descr
.dibpitch
= ((width
* descr
.infoBpp
+ 31) &~31) / 8;
3868 result
= X11DRV_DIB_SetImageBits( &descr
);
3870 if (descr
.infoBpp
<= 8)
3871 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3873 /* Update the DIBSection of the pixmap */
3874 X11DRV_UnlockDIBSection(physDev
, TRUE
);
3879 /***********************************************************************
3880 * SetDIBits (X11DRV.@)
3882 INT
X11DRV_SetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
,
3883 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
, UINT coloruse
)
3885 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3886 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3888 LONG height
, tmpheight
;
3892 descr
.physDev
= physDev
;
3894 if (!physBitmap
) return 0;
3896 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &descr
.infoWidth
, &height
,
3897 &descr
.infoBpp
, &descr
.compression
) == -1)
3901 if (height
< 0) height
= -height
;
3902 if (!lines
|| (startscan
>= height
))
3905 if (!GetObjectW( hbitmap
, sizeof(bitmap
), &bitmap
)) return 0;
3907 if (startscan
+ lines
> height
) lines
= height
- startscan
;
3909 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
3911 switch (descr
.infoBpp
)
3916 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3917 coloruse
== DIB_PAL_COLORS
? descr
.physDev
: NULL
, coloruse
,
3918 physBitmap
->pixmap_depth
,
3919 info
, &descr
.nColorMap
);
3920 if (!descr
.colorMap
) return 0;
3921 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3925 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
) : 0x7c00;
3926 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
+ 1) : 0x03e0;
3927 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
+ 2) : 0x001f;
3933 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
) : 0xff0000;
3934 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
+ 1) : 0x00ff00;
3935 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)colorPtr
+ 2) : 0x0000ff;
3944 descr
.palentry
= NULL
;
3945 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
3946 descr
.depth
= physBitmap
->pixmap_depth
;
3947 descr
.drawable
= physBitmap
->pixmap
;
3948 descr
.gc
= BITMAP_GC(physBitmap
);
3952 descr
.yDest
= height
- startscan
- lines
;
3953 descr
.width
= bitmap
.bmWidth
;
3954 descr
.height
= lines
;
3955 descr
.useShm
= FALSE
;
3956 descr
.dibpitch
= ((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8;
3957 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
, FALSE
);
3958 result
= X11DRV_DIB_SetImageBits( &descr
);
3959 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
3961 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3966 /***********************************************************************
3967 * GetDIBits (X11DRV.@)
3969 INT
X11DRV_GetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
, UINT lines
,
3970 LPVOID bits
, BITMAPINFO
*info
, UINT coloruse
)
3972 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3974 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3975 PALETTEENTRY palette
[256];
3983 GetPaletteEntries( GetCurrentObject( physDev
->hdc
, OBJ_PAL
), 0, 256, palette
);
3985 if (!physBitmap
) return 0;
3986 if (!(obj_size
= GetObjectW( hbitmap
, sizeof(dib
), &dib
))) return 0;
3988 bitmap_type
= DIB_GetBitmapInfo( (BITMAPINFOHEADER
*) info
, &descr
.infoWidth
, &tempHeight
, &descr
.infoBpp
, &descr
.compression
);
3989 descr
.lines
= tempHeight
;
3990 if (bitmap_type
== -1)
3992 ERR("Invalid bitmap\n");
3995 core_header
= (bitmap_type
== 0);
3996 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
3998 TRACE("%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
3999 lines
, dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
, (int)descr
.infoWidth
, descr
.lines
, startscan
);
4001 if( lines
> dib
.dsBm
.bmHeight
) lines
= dib
.dsBm
.bmHeight
;
4003 height
= descr
.lines
;
4004 if (height
< 0) height
= -height
;
4005 if( lines
> height
) lines
= height
;
4006 /* Top-down images have a negative biHeight, the scanlines of theses images
4007 * were inverted in X11DRV_DIB_GetImageBits_xx
4008 * To prevent this we simply change the sign of lines
4009 * (the number of scan lines to copy).
4010 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
4012 if( descr
.lines
< 0 && lines
> 0) lines
= -lines
;
4014 if( startscan
>= dib
.dsBm
.bmHeight
) return 0;
4016 descr
.colorMap
= NULL
;
4018 switch (descr
.infoBpp
)
4023 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4024 if(coloruse
== DIB_RGB_COLORS
)
4025 descr
.colorMap
= colorPtr
;
4027 int num_colors
= 1 << descr
.infoBpp
, i
;
4030 WORD
*index
= (WORD
*)colorPtr
;
4031 descr
.colorMap
= rgb
= HeapAlloc(GetProcessHeap(), 0, num_colors
* sizeof(RGBQUAD
));
4032 for(i
= 0; i
< num_colors
; i
++, rgb
++, index
++) {
4033 colref
= X11DRV_PALETTE_ToLogical(X11DRV_PALETTE_ToPhysical(physDev
, PALETTEINDEX(*index
)));
4034 rgb
->rgbRed
= GetRValue(colref
);
4035 rgb
->rgbGreen
= GetGValue(colref
);
4036 rgb
->rgbBlue
= GetBValue(colref
);
4037 rgb
->rgbReserved
= 0;
4043 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *((DWORD
*)colorPtr
) : 0x7c00;
4044 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((DWORD
*)colorPtr
+ 1) : 0x03e0;
4045 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((DWORD
*)colorPtr
+ 2) : 0x001f;
4049 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *((DWORD
*)colorPtr
) : 0xff0000;
4050 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((DWORD
*)colorPtr
+ 1) : 0x00ff00;
4051 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((DWORD
*)colorPtr
+ 2) : 0x0000ff;
4055 descr
.physDev
= physDev
;
4056 descr
.palentry
= palette
;
4059 descr
.lines
= lines
;
4060 descr
.depth
= physBitmap
->pixmap_depth
;
4061 descr
.drawable
= physBitmap
->pixmap
;
4062 descr
.gc
= BITMAP_GC(physBitmap
);
4063 descr
.width
= dib
.dsBm
.bmWidth
;
4064 descr
.height
= dib
.dsBm
.bmHeight
;
4068 descr
.sizeImage
= core_header
? 0 : info
->bmiHeader
.biSizeImage
;
4070 if (descr
.lines
> 0)
4072 descr
.ySrc
= (descr
.height
-1) - (startscan
+ (lines
-1));
4076 descr
.ySrc
= startscan
;
4078 #ifdef HAVE_LIBXXSHM
4079 descr
.useShm
= (obj_size
== sizeof(DIBSECTION
)) && (physBitmap
->shminfo
.shmid
!= -1);
4081 descr
.useShm
= FALSE
;
4083 descr
.dibpitch
= (obj_size
== sizeof(DIBSECTION
)) ? dib
.dsBm
.bmWidthBytes
4084 : (((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8);
4086 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
, FALSE
);
4087 X11DRV_DIB_GetImageBits( &descr
);
4088 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4090 if(!core_header
&& info
->bmiHeader
.biSizeImage
== 0) /* Fill in biSizeImage */
4091 info
->bmiHeader
.biSizeImage
= X11DRV_DIB_GetDIBImageBytes( descr
.infoWidth
,
4095 if (descr
.compression
== BI_BITFIELDS
)
4097 *(DWORD
*) colorPtr
= descr
.rMask
;
4098 *((DWORD
*)colorPtr
+ 1) = descr
.gMask
;
4099 *((DWORD
*)colorPtr
+ 2) = descr
.bMask
;
4101 else if (!core_header
)
4103 /* if RLE or JPEG compression were supported,
4104 * this line would be invalid. */
4105 info
->bmiHeader
.biCompression
= 0;
4108 if(descr
.colorMap
&& descr
.colorMap
!= colorPtr
)
4109 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4113 /***********************************************************************
4114 * DIB_DoProtectDIBSection
4116 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP
*physBitmap
, DWORD new_prot
)
4120 VirtualProtect(physBitmap
->base
, physBitmap
->size
, new_prot
, &old_prot
);
4121 TRACE("Changed protection from %ld to %ld\n", old_prot
, new_prot
);
4124 /***********************************************************************
4125 * X11DRV_DIB_DoCopyDIBSection
4127 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
4128 void *colorMap
, int nColorMap
,
4130 DWORD xSrc
, DWORD ySrc
,
4131 DWORD xDest
, DWORD yDest
,
4132 DWORD width
, DWORD height
)
4134 DIBSECTION dibSection
;
4135 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4136 int identity
[2] = {0,1};
4138 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
4140 descr
.physDev
= NULL
;
4141 descr
.palentry
= NULL
;
4142 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
4143 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
4144 descr
.lines
= dibSection
.dsBmih
.biHeight
;
4145 descr
.image
= physBitmap
->image
;
4146 descr
.colorMap
= colorMap
;
4147 descr
.nColorMap
= nColorMap
;
4148 descr
.bits
= dibSection
.dsBm
.bmBits
;
4149 descr
.depth
= physBitmap
->pixmap_depth
;
4150 descr
.compression
= dibSection
.dsBmih
.biCompression
;
4152 if(descr
.infoBpp
== 1)
4153 descr
.colorMap
= (void*)identity
;
4155 switch (descr
.infoBpp
)
4160 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4164 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
4165 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
4166 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
4171 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
4172 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
4173 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
4178 descr
.drawable
= dest
;
4179 descr
.gc
= BITMAP_GC(physBitmap
);
4182 descr
.xDest
= xDest
;
4183 descr
.yDest
= yDest
;
4184 descr
.width
= width
;
4185 descr
.height
= height
;
4186 descr
.sizeImage
= 0;
4188 #ifdef HAVE_LIBXXSHM
4189 descr
.useShm
= (physBitmap
->shminfo
.shmid
!= -1);
4191 descr
.useShm
= FALSE
;
4193 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
4197 TRACE("Copying from Pixmap to DIB bits\n");
4198 X11DRV_DIB_GetImageBits( &descr
);
4202 TRACE("Copying from DIB bits to Pixmap\n");
4203 X11DRV_DIB_SetImageBits( &descr
);
4207 /***********************************************************************
4208 * X11DRV_DIB_CopyDIBSection
4210 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE
*physDevSrc
, X11DRV_PDEVICE
*physDevDst
,
4211 DWORD xSrc
, DWORD ySrc
, DWORD xDest
, DWORD yDest
,
4212 DWORD width
, DWORD height
)
4215 X_PHYSBITMAP
*physBitmap
;
4216 int nColorMap
= 0, *colorMap
= NULL
, aColorMap
= FALSE
;
4218 TRACE("(%p,%p,%ld,%ld,%ld,%ld,%ld,%ld)\n", physDevSrc
->hdc
, physDevDst
->hdc
,
4219 xSrc
, ySrc
, xDest
, yDest
, width
, height
);
4220 /* this function is meant as an optimization for BitBlt,
4221 * not to be called otherwise */
4222 physBitmap
= physDevSrc
->bitmap
;
4223 if (!physBitmap
|| GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
4225 ERR("called for non-DIBSection!?\n");
4228 /* while BitBlt should already have made sure we only get
4229 * positive values, we should check for oversize values */
4230 if ((xSrc
< dib
.dsBm
.bmWidth
) &&
4231 (ySrc
< dib
.dsBm
.bmHeight
)) {
4232 if (xSrc
+ width
> dib
.dsBm
.bmWidth
)
4233 width
= dib
.dsBm
.bmWidth
- xSrc
;
4234 if (ySrc
+ height
> dib
.dsBm
.bmHeight
)
4235 height
= dib
.dsBm
.bmHeight
- ySrc
;
4236 /* if the source bitmap is 8bpp or less, we're supposed to use the
4237 * DC's palette for color conversion (not the DIB color table) */
4238 if (dib
.dsBm
.bmBitsPixel
<= 8) {
4239 HPALETTE hPalette
= GetCurrentObject( physDevSrc
->hdc
, OBJ_PAL
);
4240 if (!hPalette
|| (hPalette
== GetStockObject(DEFAULT_PALETTE
))) {
4241 /* HACK: no palette has been set in the source DC,
4242 * use the DIB colormap instead - this is necessary in some
4243 * cases since we need to do depth conversion in some places
4244 * where real Windows can just copy data straight over */
4245 colorMap
= physBitmap
->colorMap
;
4246 nColorMap
= physBitmap
->nColorMap
;
4248 colorMap
= X11DRV_DIB_BuildColorMap( physDevSrc
, (WORD
)-1,
4249 dib
.dsBm
.bmBitsPixel
,
4250 (BITMAPINFO
*)&dib
.dsBmih
,
4252 if (colorMap
) aColorMap
= TRUE
;
4255 /* perform the copy */
4256 X11DRV_DIB_DoCopyDIBSection(physBitmap
, FALSE
, colorMap
, nColorMap
,
4257 physDevDst
->drawable
, xSrc
, ySrc
,
4258 physDevDst
->org
.x
+ xDest
, physDevDst
->org
.y
+ yDest
,
4260 /* free color mapping */
4262 HeapFree(GetProcessHeap(), 0, colorMap
);
4266 /***********************************************************************
4267 * X11DRV_DIB_DoUpdateDIBSection
4269 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
4273 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
4274 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
4275 physBitmap
->colorMap
, physBitmap
->nColorMap
,
4276 physBitmap
->pixmap
, 0, 0, 0, 0,
4277 bitmap
.bmWidth
, bitmap
.bmHeight
);
4280 /***********************************************************************
4281 * X11DRV_DIB_FaultHandler
4283 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
4285 X_PHYSBITMAP
*physBitmap
= NULL
;
4290 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
4291 return EXCEPTION_CONTINUE_SEARCH
;
4293 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
4295 EnterCriticalSection(&dibs_cs
);
4296 LIST_FOR_EACH( ptr
, &dibs_list
)
4298 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
4299 if ((physBitmap
->base
<= addr
) && (addr
< physBitmap
->base
+ physBitmap
->size
))
4305 LeaveCriticalSection(&dibs_cs
);
4307 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
4309 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
, FALSE
);
4310 if (ep
->ExceptionRecord
->ExceptionInformation
[0]) {
4311 /* the app tried to write the DIB bits */
4312 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
, FALSE
);
4314 /* the app tried to read the DIB bits */
4315 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
, FALSE
);
4317 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4319 return EXCEPTION_CONTINUE_EXECUTION
;
4322 /***********************************************************************
4325 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
, BOOL lossy
)
4327 INT ret
= DIB_Status_None
;
4329 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4330 EnterCriticalSection(&physBitmap
->lock
);
4331 ret
= physBitmap
->status
;
4333 case DIB_Status_GdiMod
:
4334 /* GDI access - request to draw on pixmap */
4335 switch (physBitmap
->status
)
4338 case DIB_Status_None
:
4339 physBitmap
->p_status
= DIB_Status_GdiMod
;
4340 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4343 case DIB_Status_GdiMod
:
4344 TRACE("GdiMod requested in status GdiMod\n" );
4345 physBitmap
->p_status
= DIB_Status_GdiMod
;
4348 case DIB_Status_InSync
:
4349 TRACE("GdiMod requested in status InSync\n" );
4350 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4351 physBitmap
->status
= DIB_Status_GdiMod
;
4352 physBitmap
->p_status
= DIB_Status_InSync
;
4355 case DIB_Status_AppMod
:
4356 TRACE("GdiMod requested in status AppMod\n" );
4358 /* make it readonly to avoid app changing data while we copy */
4359 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4360 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4362 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4363 physBitmap
->p_status
= DIB_Status_AppMod
;
4364 physBitmap
->status
= DIB_Status_GdiMod
;
4369 case DIB_Status_InSync
:
4370 /* App access - request access to read DIB surface */
4371 /* (typically called from signal handler) */
4372 switch (physBitmap
->status
)
4375 case DIB_Status_None
:
4376 /* shouldn't happen from signal handler */
4379 case DIB_Status_GdiMod
:
4380 TRACE("InSync requested in status GdiMod\n" );
4382 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4383 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4385 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4386 physBitmap
->status
= DIB_Status_InSync
;
4389 case DIB_Status_InSync
:
4390 TRACE("InSync requested in status InSync\n" );
4391 /* shouldn't happen from signal handler */
4394 case DIB_Status_AppMod
:
4395 TRACE("InSync requested in status AppMod\n" );
4396 /* no reason to do anything here, and this
4397 * shouldn't happen from signal handler */
4402 case DIB_Status_AppMod
:
4403 /* App access - request access to write DIB surface */
4404 /* (typically called from signal handler) */
4405 switch (physBitmap
->status
)
4408 case DIB_Status_None
:
4409 /* shouldn't happen from signal handler */
4412 case DIB_Status_GdiMod
:
4413 TRACE("AppMod requested in status GdiMod\n" );
4414 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4415 if (!lossy
) X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4416 physBitmap
->status
= DIB_Status_AppMod
;
4419 case DIB_Status_InSync
:
4420 TRACE("AppMod requested in status InSync\n" );
4421 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4422 physBitmap
->status
= DIB_Status_AppMod
;
4425 case DIB_Status_AppMod
:
4426 TRACE("AppMod requested in status AppMod\n" );
4427 /* shouldn't happen from signal handler */
4432 /* it is up to the caller to do the copy/conversion, probably
4433 * using the return value to decide where to copy from */
4435 LeaveCriticalSection(&physBitmap
->lock
);
4439 /***********************************************************************
4442 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
, BOOL lossy
)
4444 INT ret
= DIB_Status_None
;
4446 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4447 TRACE("Locking %p from thread %04lx\n", physBitmap
->hbitmap
, GetCurrentThreadId());
4448 EnterCriticalSection(&physBitmap
->lock
);
4449 ret
= physBitmap
->status
;
4450 if (req
!= DIB_Status_None
)
4451 X11DRV_DIB_Coerce(physBitmap
, req
, lossy
);
4455 /***********************************************************************
4458 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
4460 if (!physBitmap
->image
) return; /* not a DIB section */
4461 switch (physBitmap
->status
)
4464 case DIB_Status_None
:
4465 /* in case anyone is wondering, this is the "signal handler doesn't
4466 * work" case, where we always have to be ready for app access */
4468 switch (physBitmap
->p_status
)
4470 case DIB_Status_GdiMod
:
4471 TRACE("Unlocking and syncing from GdiMod\n" );
4472 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4476 TRACE("Unlocking without needing to sync\n" );
4480 else TRACE("Unlocking with no changes\n");
4481 physBitmap
->p_status
= DIB_Status_None
;
4484 case DIB_Status_GdiMod
:
4485 TRACE("Unlocking in status GdiMod\n" );
4486 /* DIB was protected in Coerce */
4488 /* no commit, revert to InSync if applicable */
4489 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
4490 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
4491 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4492 physBitmap
->status
= DIB_Status_InSync
;
4497 case DIB_Status_InSync
:
4498 TRACE("Unlocking in status InSync\n" );
4499 /* DIB was already protected in Coerce */
4502 case DIB_Status_AppMod
:
4503 TRACE("Unlocking in status AppMod\n" );
4504 /* DIB was already protected in Coerce */
4505 /* this case is ordinary only called from the signal handler,
4506 * so we don't bother to check for !commit */
4509 LeaveCriticalSection(&physBitmap
->lock
);
4510 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
4513 /***********************************************************************
4514 * X11DRV_CoerceDIBSection
4516 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
, BOOL lossy
)
4518 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4519 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
, lossy
);
4522 /***********************************************************************
4523 * X11DRV_LockDIBSection
4525 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
, BOOL lossy
)
4527 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4528 return X11DRV_DIB_Lock(physDev
->bitmap
, req
, lossy
);
4531 /***********************************************************************
4532 * X11DRV_UnlockDIBSection
4534 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
4536 if (!physDev
|| !physDev
->bitmap
) return;
4537 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
4541 #ifdef HAVE_LIBXXSHM
4542 /***********************************************************************
4543 * X11DRV_XShmErrorHandler
4546 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
4548 return 1; /* FIXME: should check event contents */
4551 /***********************************************************************
4552 * X11DRV_XShmCreateImage
4555 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
4556 XShmSegmentInfo
* shminfo
)
4560 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
4563 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
4565 if( shminfo
->shmid
!= -1 )
4567 shminfo
->shmaddr
= image
->data
= shmat(shminfo
->shmid
, 0, 0);
4568 if( shminfo
->shmaddr
!= (char*)-1 )
4572 shminfo
->readOnly
= FALSE
;
4573 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
4574 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
4575 XSync( gdi_display
, False
);
4576 if (X11DRV_check_error()) ok
= FALSE
;
4579 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4580 return image
; /* Success! */
4582 /* An error occurred */
4583 shmdt(shminfo
->shmaddr
);
4585 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4586 shminfo
->shmid
= -1;
4588 XFlush(gdi_display
);
4589 XDestroyImage(image
);
4594 #endif /* HAVE_LIBXXSHM */
4597 /***********************************************************************
4598 * X11DRV_CreateDIBSection (X11DRV.@)
4600 HBITMAP
X11DRV_CreateDIBSection( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
,
4601 const BITMAPINFO
*bmi
, UINT usage
)
4603 X_PHYSBITMAP
*physBitmap
;
4606 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
4607 physBitmap
->status
= DIB_Status_None
;
4609 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
4611 /* create color map */
4612 if (dib
.dsBm
.bmBitsPixel
<= 8)
4614 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( usage
== DIB_PAL_COLORS
? physDev
: NULL
,
4615 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
4616 &physBitmap
->nColorMap
);
4617 physBitmap
->colorTable
= X11DRV_DIB_BuildColorTable( physDev
, usage
, dib
.dsBm
.bmBitsPixel
, bmi
);
4620 /* create pixmap and X image */
4622 physBitmap
->pixmap_depth
= (dib
.dsBm
.bmBitsPixel
== 1) ? 1 : screen_depth
;
4623 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
4624 dib
.dsBm
.bmHeight
, physBitmap
->pixmap_depth
);
4625 #ifdef HAVE_LIBXXSHM
4626 physBitmap
->shminfo
.shmid
= -1;
4627 if (!XShmQueryExtension(gdi_display
) ||
4628 !(physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4629 physBitmap
->pixmap_depth
, &physBitmap
->shminfo
)) )
4631 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4632 physBitmap
->pixmap_depth
);
4633 wine_tsx11_unlock();
4634 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
4636 /* install fault handler */
4637 InitializeCriticalSection( &physBitmap
->lock
);
4639 physBitmap
->base
= dib
.dsBm
.bmBits
;
4640 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
4641 physBitmap
->status
= DIB_Status_AppMod
;
4644 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
4645 EnterCriticalSection( &dibs_cs
);
4646 list_add_head( &dibs_list
, &physBitmap
->entry
);
4647 LeaveCriticalSection( &dibs_cs
);
4649 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4654 /***********************************************************************
4655 * X11DRV_DIB_DeleteDIBSection
4657 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
4661 EnterCriticalSection( &dibs_cs
);
4662 list_remove( &physBitmap
->entry
);
4663 last
= list_empty( &dibs_list
);
4664 LeaveCriticalSection( &dibs_cs
);
4668 RemoveVectoredExceptionHandler( dibs_handler
);
4669 dibs_handler
= NULL
;
4672 if (dib
->dshSection
)
4673 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
, FALSE
);
4675 if (physBitmap
->image
)
4678 #ifdef HAVE_LIBXXSHM
4679 if (physBitmap
->shminfo
.shmid
!= -1)
4681 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4682 XDestroyImage( physBitmap
->image
);
4683 shmdt( physBitmap
->shminfo
.shmaddr
);
4684 physBitmap
->shminfo
.shmid
= -1;
4688 XDestroyImage( physBitmap
->image
);
4689 wine_tsx11_unlock();
4692 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4693 HeapFree(GetProcessHeap(), 0, physBitmap
->colorTable
);
4694 DeleteCriticalSection(&physBitmap
->lock
);
4697 /***********************************************************************
4698 * SetDIBColorTable (X11DRV.@)
4700 UINT
X11DRV_SetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4704 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4706 if (!physBitmap
) return 0;
4707 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4709 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4710 UINT end
= count
+ start
;
4711 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4713 * Changing color table might change the mapping between
4714 * DIB colors and X11 colors and thus alter the visible state
4715 * of the bitmap object.
4717 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
, FALSE
);
4718 memcpy(physBitmap
->colorTable
+ start
, colors
, (end
- start
) * sizeof(RGBQUAD
));
4719 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4720 dib
.dsBm
.bmBitsPixel
,
4721 TRUE
, colors
, start
, end
);
4722 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4728 /***********************************************************************
4729 * GetDIBColorTable (X11DRV.@)
4731 UINT
X11DRV_GetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, RGBQUAD
*colors
)
4734 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4736 if (physBitmap
&& physBitmap
->colorTable
&& start
< physBitmap
->nColorMap
) {
4737 if (start
+ count
> physBitmap
->nColorMap
) count
= physBitmap
->nColorMap
- start
;
4738 memcpy(colors
, physBitmap
->colorTable
+ start
, count
* sizeof(RGBQUAD
));
4746 /***********************************************************************
4747 * X11DRV_DIB_CreateDIBFromBitmap
4749 * Allocates a packed DIB and copies the bitmap data into it.
4751 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4756 LPBITMAPINFOHEADER pbmiHeader
;
4757 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4760 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4763 * A packed DIB contains a BITMAPINFO structure followed immediately by
4764 * an optional color palette and the pixel data.
4767 /* Calculate the size of the packed DIB */
4768 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4769 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4770 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4772 /* Get the offset to the bits */
4773 OffsetBits
= cPackedSize
- cDataSize
;
4775 /* Allocate the packed DIB */
4776 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4777 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4781 WARN("Could not allocate packed DIB!\n");
4785 /* A packed DIB starts with a BITMAPINFOHEADER */
4786 pPackedDIB
= GlobalLock(hPackedDIB
);
4787 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4789 /* Init the BITMAPINFOHEADER */
4790 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
4791 pbmiHeader
->biWidth
= bmp
.bmWidth
;
4792 pbmiHeader
->biHeight
= bmp
.bmHeight
;
4793 pbmiHeader
->biPlanes
= 1;
4794 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
4795 pbmiHeader
->biCompression
= BI_RGB
;
4796 pbmiHeader
->biSizeImage
= 0;
4797 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
4798 pbmiHeader
->biClrUsed
= 0;
4799 pbmiHeader
->biClrImportant
= 0;
4801 /* Retrieve the DIB bits from the bitmap and fill in the
4802 * DIB color table if present */
4804 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
4805 hBmp
, /* Handle to bitmap */
4806 0, /* First scan line to set in dest bitmap */
4807 bmp
.bmHeight
, /* Number of scan lines to copy */
4808 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
4809 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
4810 0); /* RGB or palette index */
4811 GlobalUnlock(hPackedDIB
);
4813 /* Cleanup if GetDIBits failed */
4814 if (nLinesCopied
!= bmp
.bmHeight
)
4816 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
4817 GlobalFree(hPackedDIB
);
4824 /**************************************************************************
4825 * X11DRV_DIB_CreateDIBFromPixmap
4827 * Allocates a packed DIB and copies the Pixmap data into it.
4828 * The Pixmap passed in is deleted after the conversion.
4830 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
4833 X_PHYSBITMAP
*physBitmap
;
4834 HBITMAP hBmp
= 0, old
;
4835 HGLOBAL hPackedDIB
= 0;
4837 int x
,y
; /* Unused */
4838 unsigned border_width
; /* Unused */
4839 unsigned int depth
, width
, height
;
4841 /* Get the Pixmap dimensions and bit depth */
4843 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
4844 &border_width
, &depth
)) depth
= 0;
4845 wine_tsx11_unlock();
4846 if (!depth
) return 0;
4848 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4849 width
, height
, depth
);
4852 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4853 * and make it a container for the pixmap passed.
4855 hBmp
= CreateBitmap( width
, height
, 1, depth
, NULL
);
4857 /* force bitmap to be owned by a screen DC */
4858 hdcMem
= CreateCompatibleDC( hdc
);
4859 old
= SelectObject( hdcMem
, hBmp
);
4861 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4864 if (physBitmap
->pixmap
) XFreePixmap( gdi_display
, physBitmap
->pixmap
);
4865 physBitmap
->pixmap
= pixmap
;
4866 wine_tsx11_unlock();
4868 SelectObject( hdcMem
, old
);
4872 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4873 * A packed DIB contains a BITMAPINFO structure followed immediately by
4874 * an optional color palette and the pixel data.
4876 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
4878 /* We can now get rid of the HBITMAP wrapper we created earlier.
4879 * Note: Simply calling DeleteObject will free the embedded Pixmap as well.
4883 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
4888 /**************************************************************************
4889 * X11DRV_DIB_CreatePixmapFromDIB
4891 * Creates a Pixmap from a packed DIB
4893 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
4896 X_PHYSBITMAP
*physBitmap
;
4900 /* Create a DDB from the DIB */
4902 pbmi
= GlobalLock(hPackedDIB
);
4903 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
4904 (LPBYTE
)pbmi
+ X11DRV_DIB_BitmapInfoSize( pbmi
, DIB_RGB_COLORS
),
4905 pbmi
, DIB_RGB_COLORS
);
4906 GlobalUnlock(hPackedDIB
);
4908 /* clear the physBitmap so that we can steal its pixmap */
4909 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4910 pixmap
= physBitmap
->pixmap
;
4911 physBitmap
->pixmap
= 0;
4913 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4916 TRACE("Returning Pixmap %ld\n", pixmap
);