2 * X11DRV device-independent bitmaps
4 * Copyright 1993,1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
26 #include <X11/extensions/XShm.h>
27 # ifdef HAVE_SYS_SHM_H
30 # ifdef HAVE_SYS_IPC_H
33 #endif /* defined(HAVE_LIBXXSHM) */
42 #include "wine/exception.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(bitmap
);
47 static struct list dibs_list
= LIST_INIT(dibs_list
);
49 static CRITICAL_SECTION dibs_cs
;
50 static CRITICAL_SECTION_DEBUG dibs_cs_debug
=
53 { &dibs_cs_debug
.ProcessLocksList
, &dibs_cs_debug
.ProcessLocksList
},
54 0, 0, { (DWORD_PTR
)(__FILE__
": dibs_cs") }
56 static CRITICAL_SECTION dibs_cs
= { &dibs_cs_debug
, -1, 0, 0, 0, 0 };
58 static PVOID dibs_handler
;
60 static int ximageDepthTable
[32];
62 /* This structure holds the arguments for DIB_SetImageBits() */
65 X11DRV_PDEVICE
*physDev
;
68 PALETTEENTRY
*palentry
;
88 enum x11drv_shm_mode shm_mode
;
91 X_PHYSBITMAP
*physBitmap
;
92 } X11DRV_DIB_IMAGEBITS_DESCR
;
97 RLE_EOL
= 0, /* End of line */
98 RLE_END
= 1, /* End of bitmap */
99 RLE_DELTA
= 2 /* Delta */
103 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*,INT
);
106 Some of the following helper functions are duplicated in
110 /***********************************************************************
111 * DIB_DoProtectDIBSection
113 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP
*physBitmap
, DWORD new_prot
)
117 VirtualProtect(physBitmap
->base
, physBitmap
->size
, new_prot
, &old_prot
);
118 TRACE("Changed protection from %d to %d\n", old_prot
, new_prot
);
121 /***********************************************************************
122 * X11DRV_DIB_GetXImageWidthBytes
124 * Return the width of an X image in bytes
126 static inline int X11DRV_DIB_GetXImageWidthBytes( int width
, int depth
)
128 if (!depth
|| depth
> 32) goto error
;
130 if (!ximageDepthTable
[depth
-1])
132 XImage
*testimage
= XCreateImage( gdi_display
, visual
, depth
,
133 ZPixmap
, 0, NULL
, 1, 1, 32, 20 );
136 ximageDepthTable
[depth
-1] = testimage
->bits_per_pixel
;
137 XDestroyImage( testimage
);
139 else ximageDepthTable
[depth
-1] = -1;
141 if (ximageDepthTable
[depth
-1] != -1)
142 return (4 * ((width
* ximageDepthTable
[depth
-1] + 31) / 32));
145 WARN( "(%d): Unsupported depth\n", depth
);
150 /***********************************************************************
151 * X11DRV_DIB_GetDIBWidthBytes
153 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
155 static int X11DRV_DIB_GetDIBWidthBytes( int width
, int depth
)
161 case 1: words
= (width
+ 31) / 32; break;
162 case 4: words
= (width
+ 7) / 8; break;
163 case 8: words
= (width
+ 3) / 4; break;
165 case 16: words
= (width
+ 1) / 2; break;
166 case 24: words
= (width
* 3 + 3) / 4; break;
168 WARN("(%d): Unsupported depth\n", depth
);
177 /***********************************************************************
178 * X11DRV_DIB_GetDIBImageBytes
180 * Return the number of bytes used to hold the image in a DIB bitmap.
182 static int X11DRV_DIB_GetDIBImageBytes( int width
, int height
, int depth
)
184 return X11DRV_DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
188 /***********************************************************************
191 * Return the size of the bitmap info structure including color table.
193 int bitmap_info_size( const BITMAPINFO
* info
, WORD coloruse
)
195 unsigned int colors
, size
, masks
= 0;
197 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
199 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
200 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
201 return sizeof(BITMAPCOREHEADER
) + colors
*
202 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
204 else /* assume BITMAPINFOHEADER */
206 colors
= info
->bmiHeader
.biClrUsed
;
207 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
208 colors
= 1 << info
->bmiHeader
.biBitCount
;
209 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
210 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
211 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
216 /***********************************************************************
217 * X11DRV_DIB_CreateXImage
221 XImage
*X11DRV_DIB_CreateXImage( int width
, int height
, int depth
)
224 XImage
*image
= NULL
;
228 width_bytes
= X11DRV_DIB_GetXImageWidthBytes( width
, depth
);
229 data
= HeapAlloc( GetProcessHeap(), 0, height
* width_bytes
);
230 if (data
) image
= XCreateImage( gdi_display
, visual
, depth
, ZPixmap
, 0,
231 data
, width
, height
, 32, width_bytes
);
232 if (!image
) HeapFree( GetProcessHeap(), 0, data
);
238 /***********************************************************************
239 * X11DRV_DIB_DestroyXImage
241 * Destroy an X image created with X11DRV_DIB_CreateXImage.
243 void X11DRV_DIB_DestroyXImage( XImage
*image
)
245 HeapFree( GetProcessHeap(), 0, image
->data
);
248 XDestroyImage( image
);
253 /***********************************************************************
254 * DIB_GetBitmapInfoEx
256 * Get the info from a bitmap header.
257 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
259 static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER
*header
, LONG
*width
,
260 LONG
*height
, WORD
*planes
, WORD
*bpp
,
261 WORD
*compr
, DWORD
*size
)
263 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
265 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
266 *width
= core
->bcWidth
;
267 *height
= core
->bcHeight
;
268 *planes
= core
->bcPlanes
;
269 *bpp
= core
->bcBitCount
;
274 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
))
276 *width
= header
->biWidth
;
277 *height
= header
->biHeight
;
278 *planes
= header
->biPlanes
;
279 *bpp
= header
->biBitCount
;
280 *compr
= header
->biCompression
;
281 *size
= header
->biSizeImage
;
284 ERR("(%d): unknown/wrong size for header\n", header
->biSize
);
289 /***********************************************************************
290 * X11DRV_DIB_GetColorCount
292 * Computes the number of colors for the bitmap palette.
293 * Should not be called for a >8-bit deep bitmap.
295 static unsigned int X11DRV_DIB_GetColorCount(const BITMAPINFO
*info
)
298 BOOL core_info
= info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
);
302 colors
= 1 << ((const BITMAPCOREINFO
*)info
)->bmciHeader
.bcBitCount
;
306 colors
= info
->bmiHeader
.biClrUsed
;
307 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
311 ERR("called with >256 colors!\n");
317 /***********************************************************************
320 * Get the info from a bitmap header.
321 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
323 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
324 LONG
*height
, WORD
*bpp
, WORD
*compr
)
329 return DIB_GetBitmapInfoEx( header
, width
, height
, &planes
, bpp
, compr
, &size
);
333 static inline BOOL
colour_is_brighter(RGBQUAD c1
, RGBQUAD c2
)
335 return (c1
.rgbRed
* c1
.rgbRed
+ c1
.rgbGreen
* c1
.rgbGreen
+ c1
.rgbBlue
* c1
.rgbBlue
) >
336 (c2
.rgbRed
* c2
.rgbRed
+ c2
.rgbGreen
* c2
.rgbGreen
+ c2
.rgbBlue
* c2
.rgbBlue
);
339 /***********************************************************************
340 * X11DRV_DIB_GenColorMap
342 * Fills the color map of a bitmap palette. Should not be called
343 * for a >8-bit deep bitmap.
345 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE
*physDev
, int *colorMapping
,
346 WORD coloruse
, WORD depth
, BOOL quads
,
347 const void *colorPtr
, int start
, int end
)
351 if (coloruse
== DIB_RGB_COLORS
)
355 const RGBQUAD
* rgb
= colorPtr
;
357 if (depth
== 1) /* Monochrome */
362 if (GetDIBColorTable( physDev
->dev
.hdc
, 0, 2, table
) == 2)
363 invert
= !colour_is_brighter(table
[1], table
[0]);
365 for (i
= start
; i
< end
; i
++, rgb
++)
366 colorMapping
[i
] = ((rgb
->rgbRed
+ rgb
->rgbGreen
+
367 rgb
->rgbBlue
> 255*3/2 && !invert
) ||
368 (rgb
->rgbRed
+ rgb
->rgbGreen
+
369 rgb
->rgbBlue
<= 255*3/2 && invert
));
372 for (i
= start
; i
< end
; i
++, rgb
++)
373 colorMapping
[i
] = X11DRV_PALETTE_LookupPixel(physDev
->color_shifts
, RGB(rgb
->rgbRed
,
379 const RGBTRIPLE
* rgb
= colorPtr
;
381 if (depth
== 1) /* Monochrome */
386 if (GetDIBColorTable( physDev
->dev
.hdc
, 0, 2, table
) == 2)
387 invert
= !colour_is_brighter(table
[1], table
[0]);
389 for (i
= start
; i
< end
; i
++, rgb
++)
390 colorMapping
[i
] = ((rgb
->rgbtRed
+ rgb
->rgbtGreen
+
391 rgb
->rgbtBlue
> 255*3/2 && !invert
) ||
392 (rgb
->rgbtRed
+ rgb
->rgbtGreen
+
393 rgb
->rgbtBlue
<= 255*3/2 && invert
));
396 for (i
= start
; i
< end
; i
++, rgb
++)
397 colorMapping
[i
] = X11DRV_PALETTE_LookupPixel(physDev
->color_shifts
, RGB(rgb
->rgbtRed
,
402 else /* DIB_PAL_COLORS */
404 const WORD
* index
= colorPtr
;
406 for (i
= start
; i
< end
; i
++, index
++)
407 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(*index
) );
413 /***********************************************************************
414 * X11DRV_DIB_BuildColorMap
416 * Build the color map from the bitmap palette. Should not be called
417 * for a >8-bit deep bitmap.
419 static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
420 const BITMAPINFO
*info
, int *nColors
)
423 const void *colorPtr
;
427 *nColors
= X11DRV_DIB_GetColorCount(info
);
428 if (!*nColors
) return NULL
;
430 isInfo
= info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
);
431 colorPtr
= (const BYTE
*)info
+ (WORD
)info
->bmiHeader
.biSize
;
432 if (!(colorMapping
= HeapAlloc(GetProcessHeap(), 0, *nColors
* sizeof(int) )))
435 return X11DRV_DIB_GenColorMap( physDev
, colorMapping
, coloruse
, depth
,
436 isInfo
, colorPtr
, 0, *nColors
);
439 /***********************************************************************
440 * X11DRV_DIB_MapColor
442 static int X11DRV_DIB_MapColor( int *physMap
, int nPhysMap
, int phys
, int oldcol
)
446 if ((oldcol
< nPhysMap
) && (physMap
[oldcol
] == phys
))
449 for (color
= 0; color
< nPhysMap
; color
++)
450 if (physMap
[color
] == phys
)
453 WARN("Strange color %08x\n", phys
);
458 /*********************************************************************
459 * X11DRV_DIB_GetNearestIndex
461 * Helper for X11DRV_DIB_GetDIBits.
462 * Returns the nearest colour table index for a given RGB.
463 * Nearest is defined by minimizing the sum of the squares.
465 static INT
X11DRV_DIB_GetNearestIndex(RGBQUAD
*colormap
, int numColors
, BYTE r
, BYTE g
, BYTE b
)
467 INT i
, best
= -1, diff
, bestdiff
= -1;
470 for(color
= colormap
, i
= 0; i
< numColors
; color
++, i
++) {
471 diff
= (r
- color
->rgbRed
) * (r
- color
->rgbRed
) +
472 (g
- color
->rgbGreen
) * (g
- color
->rgbGreen
) +
473 (b
- color
->rgbBlue
) * (b
- color
->rgbBlue
);
476 if(best
== -1 || diff
< bestdiff
) {
483 /*********************************************************************
484 * X11DRV_DIB_MaskToShift
486 * Helper for X11DRV_DIB_GetDIBits.
487 * Returns the by how many bits to shift a given color so that it is
488 * in the proper position.
490 INT
X11DRV_DIB_MaskToShift(DWORD mask
)
498 while ((mask
&1)==0) {
505 /***********************************************************************
506 * X11DRV_DIB_CheckMask
508 * Check RGB mask if it is either 0 or matches visual's mask.
510 static inline int X11DRV_DIB_CheckMask(int red_mask
, int green_mask
, int blue_mask
)
512 return ( red_mask
== 0 && green_mask
== 0 && blue_mask
== 0 ) ||
513 ( red_mask
== visual
->red_mask
&& green_mask
== visual
->green_mask
&&
514 blue_mask
== visual
->blue_mask
);
517 /***********************************************************************
518 * X11DRV_DIB_SetImageBits_1
520 * SetDIBits for a 1-bit deep DIB.
522 static void X11DRV_DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
523 DWORD srcwidth
, DWORD dstwidth
, int left
,
524 int *colors
, XImage
*bmpImage
, int linebytes
)
533 srcbits
= srcbits
+ linebytes
* (lines
- 1);
534 linebytes
= -linebytes
;
537 if ((extra
= (left
& 7)) != 0) {
541 srcbits
+= left
>> 3;
542 width
= min(srcwidth
, dstwidth
);
544 /* ==== pal 1 dib -> any bmp format ==== */
545 for (h
= lines
-1; h
>=0; h
--) {
547 for (i
= width
/8, x
= left
; i
> 0; i
--) {
549 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
550 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
551 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
552 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
553 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
554 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
555 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
556 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
562 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
563 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
564 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
565 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
566 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
567 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
568 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
571 srcbits
+= linebytes
;
575 /***********************************************************************
576 * X11DRV_DIB_GetImageBits_1
578 * GetDIBits for a 1-bit deep DIB.
580 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
581 DWORD dstwidth
, DWORD srcwidth
,
582 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
583 XImage
*bmpImage
, int linebytes
)
586 int h
, width
= min(dstwidth
, srcwidth
);
590 dstbits
= dstbits
+ linebytes
* (lines
- 1);
591 linebytes
= -linebytes
;
594 switch (bmpImage
->depth
)
598 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
600 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
603 for (h
=lines
-1; h
>=0; h
--) {
607 for (x
=0; x
<width
; x
++) {
609 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
610 dstval
|=(X11DRV_DIB_GetNearestIndex
614 srcval
.peBlue
) << (7 - (x
& 7)));
623 /* pad with 0 to DWORD alignment */
624 for (x
= (x
+7)&~7; x
< ((width
+ 31) & ~31); x
+=8)
626 dstbits
+= linebytes
;
634 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
, bmpImage
->green_mask
, bmpImage
->blue_mask
)
636 /* ==== pal 8 bmp -> pal 1 dib ==== */
638 const BYTE
* srcpixel
;
641 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
643 for (h
=0; h
<lines
; h
++) {
648 for (x
=0; x
<width
; x
++) {
650 srcval
=srccolors
[*srcpixel
++];
651 dstval
|=(X11DRV_DIB_GetNearestIndex
655 srcval
.peBlue
) << (7-(x
&7)) );
664 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
665 dstbits
+= linebytes
;
676 const WORD
* srcpixel
;
679 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
681 if (bmpImage
->green_mask
==0x03e0) {
682 if (bmpImage
->red_mask
==0x7c00) {
683 /* ==== rgb 555 bmp -> pal 1 dib ==== */
684 for (h
=0; h
<lines
; h
++) {
689 for (x
=0; x
<width
; x
++) {
692 dstval
|=(X11DRV_DIB_GetNearestIndex
694 ((srcval
>> 7) & 0xf8) | /* r */
695 ((srcval
>> 12) & 0x07),
696 ((srcval
>> 2) & 0xf8) | /* g */
697 ((srcval
>> 7) & 0x07),
698 ((srcval
<< 3) & 0xf8) | /* b */
699 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
708 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
709 dstbits
+= linebytes
;
711 } else if (bmpImage
->blue_mask
==0x7c00) {
712 /* ==== bgr 555 bmp -> pal 1 dib ==== */
713 for (h
=0; h
<lines
; h
++) {
718 for (x
=0; x
<width
; x
++) {
721 dstval
|=(X11DRV_DIB_GetNearestIndex
723 ((srcval
<< 3) & 0xf8) | /* r */
724 ((srcval
>> 2) & 0x07),
725 ((srcval
>> 2) & 0xf8) | /* g */
726 ((srcval
>> 7) & 0x07),
727 ((srcval
>> 7) & 0xf8) | /* b */
728 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
737 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
738 dstbits
+= linebytes
;
743 } else if (bmpImage
->green_mask
==0x07e0) {
744 if (bmpImage
->red_mask
==0xf800) {
745 /* ==== rgb 565 bmp -> pal 1 dib ==== */
746 for (h
=0; h
<lines
; h
++) {
751 for (x
=0; x
<width
; x
++) {
754 dstval
|=(X11DRV_DIB_GetNearestIndex
756 ((srcval
>> 8) & 0xf8) | /* r */
757 ((srcval
>> 13) & 0x07),
758 ((srcval
>> 3) & 0xfc) | /* g */
759 ((srcval
>> 9) & 0x03),
760 ((srcval
<< 3) & 0xf8) | /* b */
761 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
770 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
771 dstbits
+= linebytes
;
773 } else if (bmpImage
->blue_mask
==0xf800) {
774 /* ==== bgr 565 bmp -> pal 1 dib ==== */
775 for (h
=0; h
<lines
; h
++) {
780 for (x
=0; x
<width
; x
++) {
783 dstval
|=(X11DRV_DIB_GetNearestIndex
785 ((srcval
<< 3) & 0xf8) | /* r */
786 ((srcval
>> 2) & 0x07),
787 ((srcval
>> 3) & 0xfc) | /* g */
788 ((srcval
>> 9) & 0x03),
789 ((srcval
>> 8) & 0xf8) | /* b */
790 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
799 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
800 dstbits
+= linebytes
;
819 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
820 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
822 if (bmpImage
->green_mask
!=0x00ff00 ||
823 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
825 } else if (bmpImage
->blue_mask
==0xff) {
826 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
827 for (h
=0; h
<lines
; h
++) {
832 for (x
=0; x
<width
; x
++) {
833 dstval
|=(X11DRV_DIB_GetNearestIndex
837 srcbyte
[0]) << (7-(x
&7)) );
838 srcbyte
+=bytes_per_pixel
;
847 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
848 dstbits
+= linebytes
;
851 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
852 for (h
=0; h
<lines
; h
++) {
857 for (x
=0; x
<width
; x
++) {
858 dstval
|=(X11DRV_DIB_GetNearestIndex
862 srcbyte
[2]) << (7-(x
&7)) );
863 srcbyte
+=bytes_per_pixel
;
872 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
873 dstbits
+= linebytes
;
884 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
886 /* ==== any bmp format -> pal 1 dib ==== */
887 if ((unsigned)colors
[0].rgbRed
+colors
[0].rgbGreen
+colors
[0].rgbBlue
>=
888 (unsigned)colors
[1].rgbRed
+colors
[1].rgbGreen
+colors
[1].rgbBlue
)
891 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
892 "%s color mapping\n",
893 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
894 bmpImage
->green_mask
, bmpImage
->blue_mask
,
895 neg
?"negative":"direct" );
897 for (h
=lines
-1; h
>=0; h
--) {
901 for (x
=0; x
<width
; x
++) {
902 dstval
|=((XGetPixel( bmpImage
, x
, h
) >= white
) ^ neg
) << (7 - (x
&7));
911 dstbits
+= linebytes
;
918 /***********************************************************************
919 * X11DRV_DIB_SetImageBits_4
921 * SetDIBits for a 4-bit deep DIB.
923 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
924 DWORD srcwidth
, DWORD dstwidth
, int left
,
925 int *colors
, XImage
*bmpImage
, int linebytes
)
933 srcbits
= srcbits
+ linebytes
* (lines
- 1);
934 linebytes
= -linebytes
;
941 srcbits
+= left
>> 1;
942 width
= min(srcwidth
, dstwidth
);
944 /* ==== pal 4 dib -> any bmp format ==== */
945 for (h
= lines
-1; h
>= 0; h
--) {
947 for (i
= width
/2, x
= left
; i
> 0; i
--) {
948 BYTE srcval
=*srcbyte
++;
949 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
950 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
953 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
954 srcbits
+= linebytes
;
960 /***********************************************************************
961 * X11DRV_DIB_GetImageBits_4
963 * GetDIBits for a 4-bit deep DIB.
965 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
966 DWORD srcwidth
, DWORD dstwidth
,
967 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
968 XImage
*bmpImage
, int linebytes
)
971 int h
, width
= min(srcwidth
, dstwidth
);
976 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
977 linebytes
= -linebytes
;
980 switch (bmpImage
->depth
) {
983 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
985 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
988 for (h
= lines
-1; h
>= 0; h
--) {
992 for (x
= 0; x
< width
; x
++) {
994 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
995 dstval
|=(X11DRV_DIB_GetNearestIndex
999 srcval
.peBlue
) << (4-((x
&1)<<2)));
1008 dstbits
+= linebytes
;
1016 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1018 /* ==== pal 8 bmp -> pal 4 dib ==== */
1019 const void* srcbits
;
1020 const BYTE
*srcpixel
;
1023 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1024 for (h
=0; h
<lines
; h
++) {
1029 for (x
=0; x
<width
; x
++) {
1030 PALETTEENTRY srcval
;
1031 srcval
= srccolors
[*srcpixel
++];
1032 dstval
|=(X11DRV_DIB_GetNearestIndex
1036 srcval
.peBlue
) << (4*(1-(x
&1))) );
1045 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1046 dstbits
+= linebytes
;
1056 const void* srcbits
;
1057 const WORD
* srcpixel
;
1060 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1062 if (bmpImage
->green_mask
==0x03e0) {
1063 if (bmpImage
->red_mask
==0x7c00) {
1064 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1065 for (h
=0; h
<lines
; h
++) {
1070 for (x
=0; x
<width
; x
++) {
1073 dstval
|=(X11DRV_DIB_GetNearestIndex
1075 ((srcval
>> 7) & 0xf8) | /* r */
1076 ((srcval
>> 12) & 0x07),
1077 ((srcval
>> 2) & 0xf8) | /* g */
1078 ((srcval
>> 7) & 0x07),
1079 ((srcval
<< 3) & 0xf8) | /* b */
1080 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1089 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1090 dstbits
+= linebytes
;
1092 } else if (bmpImage
->blue_mask
==0x7c00) {
1093 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1094 for (h
=0; h
<lines
; h
++) {
1099 for (x
=0; x
<width
; x
++) {
1102 dstval
|=(X11DRV_DIB_GetNearestIndex
1104 ((srcval
<< 3) & 0xf8) | /* r */
1105 ((srcval
>> 2) & 0x07),
1106 ((srcval
>> 2) & 0xf8) | /* g */
1107 ((srcval
>> 7) & 0x07),
1108 ((srcval
>> 7) & 0xf8) | /* b */
1109 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1118 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1119 dstbits
+= linebytes
;
1124 } else if (bmpImage
->green_mask
==0x07e0) {
1125 if (bmpImage
->red_mask
==0xf800) {
1126 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1127 for (h
=0; h
<lines
; h
++) {
1132 for (x
=0; x
<width
; x
++) {
1135 dstval
|=(X11DRV_DIB_GetNearestIndex
1137 ((srcval
>> 8) & 0xf8) | /* r */
1138 ((srcval
>> 13) & 0x07),
1139 ((srcval
>> 3) & 0xfc) | /* g */
1140 ((srcval
>> 9) & 0x03),
1141 ((srcval
<< 3) & 0xf8) | /* b */
1142 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1151 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1152 dstbits
+= linebytes
;
1154 } else if (bmpImage
->blue_mask
==0xf800) {
1155 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1156 for (h
=0; h
<lines
; h
++) {
1161 for (x
=0; x
<width
; x
++) {
1164 dstval
|=(X11DRV_DIB_GetNearestIndex
1166 ((srcval
<< 3) & 0xf8) | /* r */
1167 ((srcval
>> 2) & 0x07),
1168 ((srcval
>> 3) & 0xfc) | /* g */
1169 ((srcval
>> 9) & 0x03),
1170 ((srcval
>> 8) & 0xf8) | /* b */
1171 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1180 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1181 dstbits
+= linebytes
;
1193 if (bmpImage
->bits_per_pixel
==24) {
1194 const void* srcbits
;
1195 const BYTE
*srcbyte
;
1198 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1200 if (bmpImage
->green_mask
!=0x00ff00 ||
1201 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1203 } else if (bmpImage
->blue_mask
==0xff) {
1204 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1205 for (h
=0; h
<lines
; h
++) {
1208 for (x
=0; x
<width
/2; x
++) {
1209 /* Do 2 pixels at a time */
1210 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1215 X11DRV_DIB_GetNearestIndex
1223 /* And then the odd pixel */
1224 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1230 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1231 dstbits
+= linebytes
;
1234 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1235 for (h
=0; h
<lines
; h
++) {
1238 for (x
=0; x
<width
/2; x
++) {
1239 /* Do 2 pixels at a time */
1240 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1245 X11DRV_DIB_GetNearestIndex
1253 /* And then the odd pixel */
1254 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1260 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1261 dstbits
+= linebytes
;
1270 const void* srcbits
;
1271 const BYTE
*srcbyte
;
1274 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1276 if (bmpImage
->green_mask
!=0x00ff00 ||
1277 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1279 } else if (bmpImage
->blue_mask
==0xff) {
1280 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1281 for (h
=0; h
<lines
; h
++) {
1284 for (x
=0; x
<width
/2; x
++) {
1285 /* Do 2 pixels at a time */
1286 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1291 X11DRV_DIB_GetNearestIndex
1299 /* And then the odd pixel */
1300 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1306 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1307 dstbits
+= linebytes
;
1310 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1311 for (h
=0; h
<lines
; h
++) {
1314 for (x
=0; x
<width
/2; x
++) {
1315 /* Do 2 pixels at a time */
1316 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1321 X11DRV_DIB_GetNearestIndex
1329 /* And then the odd pixel */
1330 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1336 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1337 dstbits
+= linebytes
;
1348 /* ==== any bmp format -> pal 4 dib ==== */
1349 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1350 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1351 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1352 for (h
=lines
-1; h
>=0; h
--) {
1354 for (x
=0; x
<(width
& ~1); x
+=2) {
1355 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1356 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1359 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1361 dstbits
+= linebytes
;
1368 /***********************************************************************
1369 * X11DRV_DIB_SetImageBits_RLE4
1371 * SetDIBits for a 4-bit deep compressed DIB.
1373 static void X11DRV_DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
,
1374 DWORD srcwidth
, DWORD dstwidth
,
1375 int left
, int *colors
,
1378 unsigned int x
= 0, width
= min(srcwidth
, dstwidth
);
1379 int y
= lines
- 1, c
, length
;
1380 const BYTE
*begin
= bits
;
1385 if (length
) { /* encoded */
1388 if (x
>= (left
+ width
)) break;
1389 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1391 if (!length
--) break;
1392 if (x
>= (left
+ width
)) break;
1393 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1413 default: /* absolute */
1416 if (x
>= left
&& x
< (left
+ width
))
1417 XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1419 if (!length
--) break;
1420 if (x
>= left
&& x
< (left
+ width
))
1421 XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1424 if ((bits
- begin
) & 1)
1433 /***********************************************************************
1434 * X11DRV_DIB_SetImageBits_8
1436 * SetDIBits for an 8-bit deep DIB.
1438 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1439 DWORD srcwidth
, DWORD dstwidth
, int left
,
1440 const int *colors
, XImage
*bmpImage
,
1444 int h
, width
= min(srcwidth
, dstwidth
);
1445 const BYTE
* srcbyte
;
1451 srcbits
= srcbits
+ linebytes
* (lines
-1);
1452 linebytes
= -linebytes
;
1457 switch (bmpImage
->depth
) {
1460 /* Some X servers might have 32 bit/ 16bit deep pixel */
1461 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1462 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1464 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1465 dstbits
=(BYTE
*)bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1466 for (h
= lines
; h
--; ) {
1467 #if defined(__i386__) && defined(__GNUC__)
1468 int _cl1
,_cl2
; /* temp outputs for asm below */
1469 /* Borrowed from DirectDraw */
1470 __asm__
__volatile__(
1475 " movw (%%edx,%%eax,4),%%ax\n"
1477 " xor %%eax,%%eax\n"
1479 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1484 :"eax", "cc", "memory"
1487 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1488 for (x
=0; x
<width
/2; x
++) {
1489 /* Do 2 pixels at a time */
1490 *dstpixel
++=(colors
[srcbyte
[1]] << 16) | colors
[srcbyte
[0]];
1494 /* And then the odd pixel */
1495 *((WORD
*)dstpixel
)=colors
[srcbyte
[0]];
1498 srcbyte
= (srcbits
+= linebytes
);
1499 dstbits
-= bmpImage
->bytes_per_line
;
1506 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1507 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1509 dstbits
=(BYTE
*)bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1510 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1511 for (h
= lines
; h
--; ) {
1512 #if defined(__i386__) && defined(__GNUC__)
1513 int _cl1
,_cl2
; /* temp outputs for asm below */
1514 /* Borrowed from DirectDraw */
1515 __asm__
__volatile__(
1520 " movl (%%edx,%%eax,4),%%eax\n"
1522 " xor %%eax,%%eax\n"
1524 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1529 :"eax", "cc", "memory"
1532 DWORD
* dstpixel
=(DWORD
*)dstbits
;
1533 for (x
=0; x
<width
; x
++) {
1534 *dstpixel
++=colors
[*srcbyte
++];
1537 srcbyte
= (srcbits
+= linebytes
);
1538 dstbits
-= bmpImage
->bytes_per_line
;
1544 break; /* use slow generic case below */
1547 /* ==== pal 8 dib -> any bmp format ==== */
1548 for (h
=lines
-1; h
>=0; h
--) {
1549 for (x
=left
; x
<width
+left
; x
++) {
1550 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1552 srcbyte
= (srcbits
+= linebytes
);
1556 /***********************************************************************
1557 * X11DRV_DIB_GetImageBits_8
1559 * GetDIBits for an 8-bit deep DIB.
1561 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1562 DWORD srcwidth
, DWORD dstwidth
,
1563 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1564 XImage
*bmpImage
, int linebytes
)
1567 int h
, width
= min(srcwidth
, dstwidth
);
1573 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1574 linebytes
= -linebytes
;
1579 * This condition is true when GetImageBits has been called by
1580 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1581 * 256 colormaps, so we'll just use it for GetDIBits calls.
1582 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1584 if (!srccolors
) goto updatesection
;
1586 switch (bmpImage
->depth
) {
1589 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1592 /* ==== pal 1 bmp -> pal 8 dib ==== */
1593 /* ==== pal 4 bmp -> pal 8 dib ==== */
1594 for (h
=lines
-1; h
>=0; h
--) {
1596 for (x
=0; x
<width
; x
++) {
1597 PALETTEENTRY srcval
;
1598 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1599 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1604 dstbits
+= linebytes
;
1612 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1614 /* ==== pal 8 bmp -> pal 8 dib ==== */
1615 const void* srcbits
;
1616 const BYTE
* srcpixel
;
1618 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1619 for (h
=0; h
<lines
; h
++) {
1622 for (x
= 0; x
< width
; x
++) {
1623 PALETTEENTRY srcval
;
1624 srcval
=srccolors
[*srcpixel
++];
1625 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1630 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1631 dstbits
+= linebytes
;
1641 const void* srcbits
;
1642 const WORD
* srcpixel
;
1645 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1647 if (bmpImage
->green_mask
==0x03e0) {
1648 if (bmpImage
->red_mask
==0x7c00) {
1649 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1650 for (h
=0; h
<lines
; h
++) {
1653 for (x
=0; x
<width
; x
++) {
1656 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1658 ((srcval
>> 7) & 0xf8) | /* r */
1659 ((srcval
>> 12) & 0x07),
1660 ((srcval
>> 2) & 0xf8) | /* g */
1661 ((srcval
>> 7) & 0x07),
1662 ((srcval
<< 3) & 0xf8) | /* b */
1663 ((srcval
>> 2) & 0x07) );
1665 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1666 dstbits
+= linebytes
;
1668 } else if (bmpImage
->blue_mask
==0x7c00) {
1669 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1670 for (h
=0; h
<lines
; h
++) {
1673 for (x
=0; x
<width
; x
++) {
1676 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1678 ((srcval
<< 3) & 0xf8) | /* r */
1679 ((srcval
>> 2) & 0x07),
1680 ((srcval
>> 2) & 0xf8) | /* g */
1681 ((srcval
>> 7) & 0x07),
1682 ((srcval
>> 7) & 0xf8) | /* b */
1683 ((srcval
>> 12) & 0x07) );
1685 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1686 dstbits
+= linebytes
;
1691 } else if (bmpImage
->green_mask
==0x07e0) {
1692 if (bmpImage
->red_mask
==0xf800) {
1693 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1694 for (h
=0; h
<lines
; h
++) {
1697 for (x
=0; x
<width
; x
++) {
1700 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1702 ((srcval
>> 8) & 0xf8) | /* r */
1703 ((srcval
>> 13) & 0x07),
1704 ((srcval
>> 3) & 0xfc) | /* g */
1705 ((srcval
>> 9) & 0x03),
1706 ((srcval
<< 3) & 0xf8) | /* b */
1707 ((srcval
>> 2) & 0x07) );
1709 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1710 dstbits
+= linebytes
;
1712 } else if (bmpImage
->blue_mask
==0xf800) {
1713 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1714 for (h
=0; h
<lines
; h
++) {
1717 for (x
=0; x
<width
; x
++) {
1720 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1722 ((srcval
<< 3) & 0xf8) | /* r */
1723 ((srcval
>> 2) & 0x07),
1724 ((srcval
>> 3) & 0xfc) | /* g */
1725 ((srcval
>> 9) & 0x03),
1726 ((srcval
>> 8) & 0xf8) | /* b */
1727 ((srcval
>> 13) & 0x07) );
1729 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1730 dstbits
+= linebytes
;
1744 const void* srcbits
;
1745 const BYTE
*srcbyte
;
1747 int bytes_per_pixel
;
1749 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1750 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1752 if (bmpImage
->green_mask
!=0x00ff00 ||
1753 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1755 } else if (bmpImage
->blue_mask
==0xff) {
1756 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1757 for (h
=0; h
<lines
; h
++) {
1760 for (x
=0; x
<width
; x
++) {
1761 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1766 srcbyte
+=bytes_per_pixel
;
1768 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1769 dstbits
+= linebytes
;
1772 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1773 for (h
=0; h
<lines
; h
++) {
1776 for (x
=0; x
<width
; x
++) {
1777 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1782 srcbyte
+=bytes_per_pixel
;
1784 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1785 dstbits
+= linebytes
;
1793 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1794 bmpImage
->depth
, bmpImage
->red_mask
,
1795 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1797 /* ==== any bmp format -> pal 8 dib ==== */
1798 for (h
=lines
-1; h
>=0; h
--) {
1800 for (x
=0; x
<width
; x
++) {
1801 *dstbyte
=X11DRV_DIB_MapColor
1803 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1806 dstbits
+= linebytes
;
1812 /***********************************************************************
1813 * X11DRV_DIB_SetImageBits_RLE8
1815 * SetDIBits for an 8-bit deep compressed DIB.
1817 * This function rewritten 941113 by James Youngman. WINE blew out when I
1818 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1820 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1821 * 'End of bitmap' escape code. This code is very much laxer in what it
1822 * allows to end the expansion. Possibly too lax. See the note by
1823 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1824 * bitmap should end with RleEnd, but on the other hand, software exists
1825 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1828 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1829 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1832 static void X11DRV_DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
,
1833 DWORD srcwidth
, DWORD dstwidth
,
1834 int left
, int *colors
,
1837 unsigned int x
; /* X-position on each line. Increases. */
1838 int y
; /* Line #. Starts at lines-1, decreases */
1839 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
1840 BYTE length
; /* The length pf a run */
1841 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
1844 * Note that the bitmap data is stored by Windows starting at the
1845 * bottom line of the bitmap and going upwards. Within each line,
1846 * the data is stored left-to-right. That's the reason why line
1847 * goes from lines-1 to 0. [JAY]
1857 * If the length byte is not zero (which is the escape value),
1858 * We have a run of length pixels all the same colour. The colour
1859 * index is stored next.
1861 * If the length byte is zero, we need to read the next byte to
1862 * know what to do. [JAY]
1867 * [Run-Length] Encoded mode
1869 int color
= colors
[*pIn
++];
1870 while (length
-- && x
< (left
+ dstwidth
)) {
1871 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1878 * Escape codes (may be an absolute sequence though)
1880 escape_code
= (*pIn
++);
1889 /* Not all RLE8 bitmaps end with this code. For
1890 * example, Paint Shop Pro produces some that don't.
1891 * That's (I think) what caused the previous
1892 * implementation to fail. [JAY]
1901 default: /* switch to absolute mode */
1902 length
= escape_code
;
1905 int color
= colors
[*pIn
++];
1906 if (x
>= (left
+ dstwidth
))
1911 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1915 * If you think for a moment you'll realise that the
1916 * only time we could ever possibly read an odd
1917 * number of bytes is when there is a 0x00 (escape),
1918 * a value >0x02 (absolute mode) and then an odd-
1919 * length run. Therefore this is the only place we
1920 * need to worry about it. Everywhere else the
1921 * bytes are always read in pairs. [JAY]
1923 if (escape_code
& 1) pIn
++; /* Throw away the pad byte. */
1925 } /* switch (escape_code) : Escape sequence */
1931 /***********************************************************************
1932 * X11DRV_DIB_SetImageBits_16
1934 * SetDIBits for a 16-bit deep DIB.
1936 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1937 DWORD srcwidth
, DWORD dstwidth
, int left
,
1938 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1939 XImage
*bmpImage
, int linebytes
)
1942 int h
, width
= min(srcwidth
, dstwidth
);
1943 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1948 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1949 linebytes
= -linebytes
;
1952 switch (bmpImage
->depth
)
1959 srcbits
=srcbits
+left
*2;
1960 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1962 if (bmpImage
->green_mask
==0x03e0) {
1963 if (gSrc
==bmpImage
->green_mask
) {
1964 if (rSrc
==bmpImage
->red_mask
) {
1965 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1966 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1967 convs
->Convert_5x5_asis
1970 dstbits
,-bmpImage
->bytes_per_line
);
1971 } else if (rSrc
==bmpImage
->blue_mask
) {
1972 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1973 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1974 convs
->Convert_555_reverse
1977 dstbits
,-bmpImage
->bytes_per_line
);
1980 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1981 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1982 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1983 convs
->Convert_565_to_555_asis
1986 dstbits
,-bmpImage
->bytes_per_line
);
1988 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1989 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1990 convs
->Convert_565_to_555_reverse
1993 dstbits
,-bmpImage
->bytes_per_line
);
1996 } else if (bmpImage
->green_mask
==0x07e0) {
1997 if (gSrc
==bmpImage
->green_mask
) {
1998 if (rSrc
==bmpImage
->red_mask
) {
1999 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
2000 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
2001 convs
->Convert_5x5_asis
2004 dstbits
,-bmpImage
->bytes_per_line
);
2006 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
2007 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
2008 convs
->Convert_565_reverse
2011 dstbits
,-bmpImage
->bytes_per_line
);
2014 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
2015 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
2016 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
2017 convs
->Convert_555_to_565_asis
2020 dstbits
,-bmpImage
->bytes_per_line
);
2022 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
2023 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
2024 convs
->Convert_555_to_565_reverse
2027 dstbits
,-bmpImage
->bytes_per_line
);
2037 if (bmpImage
->bits_per_pixel
==24) {
2040 srcbits
=srcbits
+left
*2;
2041 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2043 if (bmpImage
->green_mask
!=0x00ff00 ||
2044 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2046 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2047 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2049 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2050 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2051 convs
->Convert_555_to_888_asis
2054 dstbits
,-bmpImage
->bytes_per_line
);
2056 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2057 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2058 convs
->Convert_565_to_888_asis
2061 dstbits
,-bmpImage
->bytes_per_line
);
2065 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2066 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2067 convs
->Convert_555_to_888_reverse
2070 dstbits
,-bmpImage
->bytes_per_line
);
2072 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2073 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2074 convs
->Convert_565_to_888_reverse
2077 dstbits
,-bmpImage
->bytes_per_line
);
2088 srcbits
=srcbits
+left
*2;
2089 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2091 if (bmpImage
->green_mask
!=0x00ff00 ||
2092 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2094 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2095 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2097 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2098 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2099 convs
->Convert_555_to_0888_asis
2102 dstbits
,-bmpImage
->bytes_per_line
);
2104 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2105 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2106 convs
->Convert_565_to_0888_asis
2109 dstbits
,-bmpImage
->bytes_per_line
);
2113 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2114 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2115 convs
->Convert_555_to_0888_reverse
2118 dstbits
,-bmpImage
->bytes_per_line
);
2120 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2121 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2122 convs
->Convert_565_to_0888_reverse
2125 dstbits
,-bmpImage
->bytes_per_line
);
2133 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2134 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2135 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2141 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2142 const WORD
* srcpixel
;
2143 int rShift1
,gShift1
,bShift1
;
2144 int rShift2
,gShift2
,bShift2
;
2147 /* Set color scaling values */
2148 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
2149 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
2150 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
2155 /* Green has 5 bits, like the others */
2159 /* Green has 6 bits, not 5. Compensate. */
2168 /* We could split it into four separate cases to optimize
2169 * but it is probably not worth it.
2171 for (h
=lines
-1; h
>=0; h
--) {
2172 srcpixel
=(const WORD
*)srcbits
;
2173 for (x
=left
; x
<width
+left
; x
++) {
2175 BYTE red
,green
,blue
;
2176 srcval
=*srcpixel
++ << 16;
2177 red
= ((srcval
>> rShift1
) & 0xf8) |
2178 ((srcval
>> rShift2
) & 0x07);
2179 green
=((srcval
>> gShift1
) & gMask1
) |
2180 ((srcval
>> gShift2
) & gMask2
);
2181 blue
= ((srcval
>> bShift1
) & 0xf8) |
2182 ((srcval
>> bShift2
) & 0x07);
2183 XPutPixel(bmpImage
, x
, h
,
2184 X11DRV_PALETTE_ToPhysical
2185 (physDev
, RGB(red
,green
,blue
)));
2187 srcbits
+= linebytes
;
2195 /***********************************************************************
2196 * X11DRV_DIB_GetImageBits_16
2198 * GetDIBits for an 16-bit deep DIB.
2200 static void X11DRV_DIB_GetImageBits_16( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
2201 DWORD dstwidth
, DWORD srcwidth
,
2202 PALETTEENTRY
*srccolors
,
2203 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2204 XImage
*bmpImage
, int linebytes
)
2207 int h
, width
= min(srcwidth
, dstwidth
);
2208 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2213 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
2214 linebytes
= -linebytes
;
2217 switch (bmpImage
->depth
)
2222 const char* srcbits
;
2224 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2226 if (bmpImage
->green_mask
==0x03e0) {
2227 if (gDst
==bmpImage
->green_mask
) {
2228 if (rDst
==bmpImage
->red_mask
) {
2229 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2230 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2231 convs
->Convert_5x5_asis
2233 srcbits
,-bmpImage
->bytes_per_line
,
2236 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2237 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2238 convs
->Convert_555_reverse
2240 srcbits
,-bmpImage
->bytes_per_line
,
2244 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2245 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2246 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2247 convs
->Convert_555_to_565_asis
2249 srcbits
,-bmpImage
->bytes_per_line
,
2252 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2253 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2254 convs
->Convert_555_to_565_reverse
2256 srcbits
,-bmpImage
->bytes_per_line
,
2260 } else if (bmpImage
->green_mask
==0x07e0) {
2261 if (gDst
==bmpImage
->green_mask
) {
2262 if (rDst
== bmpImage
->red_mask
) {
2263 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2264 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2265 convs
->Convert_5x5_asis
2267 srcbits
,-bmpImage
->bytes_per_line
,
2270 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2271 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2272 convs
->Convert_565_reverse
2274 srcbits
,-bmpImage
->bytes_per_line
,
2278 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2279 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2280 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2281 convs
->Convert_565_to_555_asis
2283 srcbits
,-bmpImage
->bytes_per_line
,
2286 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2287 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2288 convs
->Convert_565_to_555_reverse
2290 srcbits
,-bmpImage
->bytes_per_line
,
2301 if (bmpImage
->bits_per_pixel
== 24) {
2302 const char* srcbits
;
2304 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2306 if (bmpImage
->green_mask
!=0x00ff00 ||
2307 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2309 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2310 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2312 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2313 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2314 convs
->Convert_888_to_555_asis
2316 srcbits
,-bmpImage
->bytes_per_line
,
2319 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2320 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2321 convs
->Convert_888_to_565_asis
2323 srcbits
,-bmpImage
->bytes_per_line
,
2328 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2329 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2330 convs
->Convert_888_to_555_reverse
2332 srcbits
,-bmpImage
->bytes_per_line
,
2335 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2336 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2337 convs
->Convert_888_to_565_reverse
2339 srcbits
,-bmpImage
->bytes_per_line
,
2349 const char* srcbits
;
2351 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2353 if (bmpImage
->green_mask
!=0x00ff00 ||
2354 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2356 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2357 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2359 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2360 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2361 convs
->Convert_0888_to_555_asis
2363 srcbits
,-bmpImage
->bytes_per_line
,
2366 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2367 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2368 convs
->Convert_0888_to_565_asis
2370 srcbits
,-bmpImage
->bytes_per_line
,
2375 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2376 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2377 convs
->Convert_0888_to_555_reverse
2379 srcbits
,-bmpImage
->bytes_per_line
,
2382 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2383 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2384 convs
->Convert_0888_to_565_reverse
2386 srcbits
,-bmpImage
->bytes_per_line
,
2395 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2397 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2398 int rShift
,gShift
,bShift
;
2401 /* Shift everything 16 bits left so that all shifts are >0,
2402 * even for BGR DIBs. Then a single >> 16 will bring everything
2405 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2406 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2407 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2409 /* 6 bits for the green */
2415 for (h
= lines
- 1; h
>= 0; h
--) {
2416 dstpixel
=(LPWORD
)dstbits
;
2417 for (x
= 0; x
< width
; x
++) {
2418 PALETTEENTRY srcval
;
2420 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2421 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2422 ((srcval
.peGreen
<< gShift
) & gDst
) |
2423 ((srcval
.peBlue
<< bShift
) & bDst
);
2424 *dstpixel
++=dstval
>> 16;
2426 dstbits
+= linebytes
;
2434 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2436 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2437 int rShift
,gShift
,bShift
;
2438 const BYTE
* srcbits
;
2439 const BYTE
* srcpixel
;
2442 /* Shift everything 16 bits left so that all shifts are >0,
2443 * even for BGR DIBs. Then a single >> 16 will bring everything
2446 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2447 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2448 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2450 /* 6 bits for the green */
2456 srcbits
=(BYTE
*)bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2457 for (h
=0; h
<lines
; h
++) {
2459 dstpixel
=(LPWORD
)dstbits
;
2460 for (x
= 0; x
< width
; x
++) {
2461 PALETTEENTRY srcval
;
2463 srcval
=srccolors
[*srcpixel
++];
2464 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2465 ((srcval
.peGreen
<< gShift
) & gDst
) |
2466 ((srcval
.peBlue
<< bShift
) & bDst
);
2467 *dstpixel
++=dstval
>> 16;
2469 srcbits
-= bmpImage
->bytes_per_line
;
2470 dstbits
+= linebytes
;
2480 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2481 int rShift
,gShift
,bShift
;
2484 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2485 bmpImage
->depth
, bmpImage
->red_mask
,
2486 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2489 /* Shift everything 16 bits left so that all shifts are >0,
2490 * even for BGR DIBs. Then a single >> 16 will bring everything
2493 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2494 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2495 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2497 /* 6 bits for the green */
2503 for (h
= lines
- 1; h
>= 0; h
--) {
2504 dstpixel
=(LPWORD
)dstbits
;
2505 for (x
= 0; x
< width
; x
++) {
2508 srcval
=X11DRV_PALETTE_ToLogical(physDev
, XGetPixel(bmpImage
, x
, h
));
2509 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2510 ((GetGValue(srcval
) << gShift
) & gDst
) |
2511 ((GetBValue(srcval
) << bShift
) & bDst
);
2512 *dstpixel
++=dstval
>> 16;
2514 dstbits
+= linebytes
;
2522 /***********************************************************************
2523 * X11DRV_DIB_SetImageBits_24
2525 * SetDIBits for a 24-bit deep DIB.
2527 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2528 DWORD srcwidth
, DWORD dstwidth
, int left
,
2529 X11DRV_PDEVICE
*physDev
,
2530 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2531 XImage
*bmpImage
, DWORD linebytes
)
2534 int h
, width
= min(srcwidth
, dstwidth
);
2535 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2540 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2541 linebytes
= -linebytes
;
2544 switch (bmpImage
->depth
)
2547 if (bmpImage
->bits_per_pixel
==24) {
2550 srcbits
=srcbits
+left
*3;
2551 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2553 if (bmpImage
->green_mask
!=0x00ff00 ||
2554 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2556 } else if (rSrc
==bmpImage
->red_mask
) {
2557 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2558 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2559 convs
->Convert_888_asis
2562 dstbits
,-bmpImage
->bytes_per_line
);
2564 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2565 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2566 convs
->Convert_888_reverse
2569 dstbits
,-bmpImage
->bytes_per_line
);
2579 srcbits
=srcbits
+left
*3;
2580 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2582 if (bmpImage
->green_mask
!=0x00ff00 ||
2583 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2585 } else if (rSrc
==bmpImage
->red_mask
) {
2586 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2587 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2588 convs
->Convert_888_to_0888_asis
2591 dstbits
,-bmpImage
->bytes_per_line
);
2593 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2594 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2595 convs
->Convert_888_to_0888_reverse
2598 dstbits
,-bmpImage
->bytes_per_line
);
2608 srcbits
=srcbits
+left
*3;
2609 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2611 if (bmpImage
->green_mask
==0x03e0) {
2612 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2613 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2614 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2615 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2616 convs
->Convert_888_to_555_asis
2619 dstbits
,-bmpImage
->bytes_per_line
);
2620 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2621 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2622 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2623 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2624 convs
->Convert_888_to_555_reverse
2627 dstbits
,-bmpImage
->bytes_per_line
);
2631 } else if (bmpImage
->green_mask
==0x07e0) {
2632 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2633 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2634 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2635 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2636 convs
->Convert_888_to_565_asis
2639 dstbits
,-bmpImage
->bytes_per_line
);
2640 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2641 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2642 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2643 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2644 convs
->Convert_888_to_565_reverse
2647 dstbits
,-bmpImage
->bytes_per_line
);
2659 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2660 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2661 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2667 /* ==== rgb 888 dib -> any bmp format ==== */
2668 const BYTE
* srcbyte
;
2670 /* Windows only supports one 24bpp DIB format: RGB888 */
2672 for (h
= lines
- 1; h
>= 0; h
--) {
2674 for (x
= left
; x
< width
+left
; x
++) {
2675 XPutPixel(bmpImage
, x
, h
,
2676 X11DRV_PALETTE_ToPhysical
2677 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2680 srcbits
+= linebytes
;
2688 /***********************************************************************
2689 * X11DRV_DIB_GetImageBits_24
2691 * GetDIBits for an 24-bit deep DIB.
2693 static void X11DRV_DIB_GetImageBits_24( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
2694 DWORD dstwidth
, DWORD srcwidth
,
2695 PALETTEENTRY
*srccolors
,
2696 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2697 XImage
*bmpImage
, DWORD linebytes
)
2700 int h
, width
= min(srcwidth
, dstwidth
);
2701 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2706 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2707 linebytes
= -linebytes
;
2710 switch (bmpImage
->depth
)
2713 if (bmpImage
->bits_per_pixel
==24) {
2714 const char* srcbits
;
2716 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2718 if (bmpImage
->green_mask
!=0x00ff00 ||
2719 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2721 } else if (rDst
==bmpImage
->red_mask
) {
2722 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2723 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2724 convs
->Convert_888_asis
2726 srcbits
,-bmpImage
->bytes_per_line
,
2729 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2730 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2731 convs
->Convert_888_reverse
2733 srcbits
,-bmpImage
->bytes_per_line
,
2742 const char* srcbits
;
2744 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2746 if (bmpImage
->green_mask
!=0x00ff00 ||
2747 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2749 } else if (rDst
==bmpImage
->red_mask
) {
2750 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2751 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2752 convs
->Convert_0888_to_888_asis
2754 srcbits
,-bmpImage
->bytes_per_line
,
2757 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2758 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2759 convs
->Convert_0888_to_888_reverse
2761 srcbits
,-bmpImage
->bytes_per_line
,
2770 const char* srcbits
;
2772 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2774 if (bmpImage
->green_mask
==0x03e0) {
2775 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2776 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2777 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2778 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2779 convs
->Convert_555_to_888_asis
2781 srcbits
,-bmpImage
->bytes_per_line
,
2783 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2784 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2785 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2786 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2787 convs
->Convert_555_to_888_reverse
2789 srcbits
,-bmpImage
->bytes_per_line
,
2794 } else if (bmpImage
->green_mask
==0x07e0) {
2795 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2796 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2797 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2798 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2799 convs
->Convert_565_to_888_asis
2801 srcbits
,-bmpImage
->bytes_per_line
,
2803 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2804 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2805 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2806 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2807 convs
->Convert_565_to_888_reverse
2809 srcbits
,-bmpImage
->bytes_per_line
,
2822 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2824 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2827 /* Windows only supports one 24bpp DIB format: rgb 888 */
2828 for (h
= lines
- 1; h
>= 0; h
--) {
2830 for (x
= 0; x
< width
; x
++) {
2831 PALETTEENTRY srcval
;
2832 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2833 dstbyte
[0]=srcval
.peBlue
;
2834 dstbyte
[1]=srcval
.peGreen
;
2835 dstbyte
[2]=srcval
.peRed
;
2838 dstbits
+= linebytes
;
2846 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2848 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2849 const void* srcbits
;
2850 const BYTE
* srcpixel
;
2853 /* Windows only supports one 24bpp DIB format: rgb 888 */
2854 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2855 for (h
= lines
- 1; h
>= 0; h
--) {
2858 for (x
= 0; x
< width
; x
++ ) {
2859 PALETTEENTRY srcval
;
2860 srcval
=srccolors
[*srcpixel
++];
2861 dstbyte
[0]=srcval
.peBlue
;
2862 dstbyte
[1]=srcval
.peGreen
;
2863 dstbyte
[2]=srcval
.peRed
;
2866 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2867 dstbits
+= linebytes
;
2877 /* ==== any bmp format -> 888 dib ==== */
2880 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2881 bmpImage
->depth
, bmpImage
->red_mask
,
2882 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2885 /* Windows only supports one 24bpp DIB format: rgb 888 */
2886 for (h
= lines
- 1; h
>= 0; h
--) {
2888 for (x
= 0; x
< width
; x
++) {
2889 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2890 (physDev
, XGetPixel( bmpImage
, x
, h
));
2891 dstbyte
[0]=GetBValue(srcval
);
2892 dstbyte
[1]=GetGValue(srcval
);
2893 dstbyte
[2]=GetRValue(srcval
);
2896 dstbits
+= linebytes
;
2904 /***********************************************************************
2905 * X11DRV_DIB_SetImageBits_32
2907 * SetDIBits for a 32-bit deep DIB.
2909 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2910 DWORD srcwidth
, DWORD dstwidth
, int left
,
2911 X11DRV_PDEVICE
*physDev
,
2912 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2917 int h
, width
= min(srcwidth
, dstwidth
);
2918 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2923 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2924 linebytes
= -linebytes
;
2927 switch (bmpImage
->depth
)
2930 if (bmpImage
->bits_per_pixel
==24) {
2933 srcbits
=srcbits
+left
*4;
2934 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2936 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2937 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2938 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2939 convs
->Convert_0888_to_888_asis
2942 dstbits
,-bmpImage
->bytes_per_line
);
2943 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2944 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2946 /* the tests below assume sane bmpImage masks */
2947 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2948 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2949 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2950 convs
->Convert_0888_to_888_reverse
2953 dstbits
,-bmpImage
->bytes_per_line
);
2954 } else if (bmpImage
->blue_mask
==0xff) {
2955 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2956 convs
->Convert_any0888_to_rgb888
2960 dstbits
,-bmpImage
->bytes_per_line
);
2962 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2963 convs
->Convert_any0888_to_bgr888
2967 dstbits
,-bmpImage
->bytes_per_line
);
2977 srcbits
=srcbits
+left
*4;
2978 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2980 if (gSrc
==bmpImage
->green_mask
) {
2981 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2982 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2983 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2984 convs
->Convert_0888_asis
2987 dstbits
,-bmpImage
->bytes_per_line
);
2988 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2989 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2991 /* the tests below assume sane bmpImage masks */
2992 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
2993 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2994 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2995 convs
->Convert_0888_reverse
2998 dstbits
,-bmpImage
->bytes_per_line
);
3000 /* ==== any 0888 dib -> any 0888 bmp ==== */
3001 convs
->Convert_0888_any
3005 dstbits
,-bmpImage
->bytes_per_line
,
3006 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3008 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3009 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3011 /* the tests below assume sane bmpImage masks */
3013 /* ==== any 0888 dib -> any 0888 bmp ==== */
3014 convs
->Convert_0888_any
3018 dstbits
,-bmpImage
->bytes_per_line
,
3019 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3029 srcbits
=srcbits
+left
*4;
3030 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
3032 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
3033 if (bmpImage
->green_mask
==0x03e0) {
3034 if (bmpImage
->red_mask
==0x7f00) {
3035 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
3036 convs
->Convert_0888_to_555_asis
3039 dstbits
,-bmpImage
->bytes_per_line
);
3040 } else if (bmpImage
->blue_mask
==0x7f00) {
3041 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
3042 convs
->Convert_0888_to_555_reverse
3045 dstbits
,-bmpImage
->bytes_per_line
);
3049 } else if (bmpImage
->green_mask
==0x07e0) {
3050 if (bmpImage
->red_mask
==0xf800) {
3051 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3052 convs
->Convert_0888_to_565_asis
3055 dstbits
,-bmpImage
->bytes_per_line
);
3056 } else if (bmpImage
->blue_mask
==0xf800) {
3057 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3058 convs
->Convert_0888_to_565_reverse
3061 dstbits
,-bmpImage
->bytes_per_line
);
3068 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
3069 if (bmpImage
->green_mask
==0x03e0) {
3070 if (bmpImage
->blue_mask
==0x7f00) {
3071 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3072 convs
->Convert_0888_to_555_asis
3075 dstbits
,-bmpImage
->bytes_per_line
);
3076 } else if (bmpImage
->red_mask
==0x7f00) {
3077 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3078 convs
->Convert_0888_to_555_reverse
3081 dstbits
,-bmpImage
->bytes_per_line
);
3085 } else if (bmpImage
->green_mask
==0x07e0) {
3086 if (bmpImage
->blue_mask
==0xf800) {
3087 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3088 convs
->Convert_0888_to_565_asis
3091 dstbits
,-bmpImage
->bytes_per_line
);
3092 } else if (bmpImage
->red_mask
==0xf800) {
3093 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3094 convs
->Convert_0888_to_565_reverse
3097 dstbits
,-bmpImage
->bytes_per_line
);
3105 if (bmpImage
->green_mask
==0x03e0 &&
3106 (bmpImage
->red_mask
==0x7f00 ||
3107 bmpImage
->blue_mask
==0x7f00)) {
3108 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3109 convs
->Convert_any0888_to_5x5
3113 dstbits
,-bmpImage
->bytes_per_line
,
3114 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3115 } else if (bmpImage
->green_mask
==0x07e0 &&
3116 (bmpImage
->red_mask
==0xf800 ||
3117 bmpImage
->blue_mask
==0xf800)) {
3118 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3119 convs
->Convert_any0888_to_5x5
3123 dstbits
,-bmpImage
->bytes_per_line
,
3124 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3134 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3135 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
3136 bmpImage
->green_mask
, bmpImage
->blue_mask
);
3142 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3143 const DWORD
* srcpixel
;
3144 int rShift
,gShift
,bShift
;
3146 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
3147 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
3148 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
3150 for (h
= lines
- 1; h
>= 0; h
--) {
3151 srcpixel
=(const DWORD
*)srcbits
;
3152 for (x
= left
; x
< width
+left
; x
++) {
3154 BYTE red
,green
,blue
;
3155 srcvalue
=*srcpixel
++;
3156 red
= (srcvalue
>> rShift
) & 0xff;
3157 green
=(srcvalue
>> gShift
) & 0xff;
3158 blue
= (srcvalue
>> bShift
) & 0xff;
3159 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
3160 (physDev
, RGB(red
,green
,blue
)));
3162 srcbits
+= linebytes
;
3170 /***********************************************************************
3171 * X11DRV_DIB_GetImageBits_32
3173 * GetDIBits for an 32-bit deep DIB.
3175 static void X11DRV_DIB_GetImageBits_32( X11DRV_PDEVICE
*physDev
, int lines
, BYTE
*dstbits
,
3176 DWORD dstwidth
, DWORD srcwidth
,
3177 PALETTEENTRY
*srccolors
,
3178 DWORD rDst
, DWORD gDst
, DWORD bDst
,
3179 XImage
*bmpImage
, int linebytes
)
3182 int h
, width
= min(srcwidth
, dstwidth
);
3183 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
3188 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
3189 linebytes
= -linebytes
;
3192 switch (bmpImage
->depth
)
3195 if (bmpImage
->bits_per_pixel
==24) {
3196 const void* srcbits
;
3198 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3200 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
3201 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3202 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3203 convs
->Convert_888_to_0888_asis
3205 srcbits
,-bmpImage
->bytes_per_line
,
3207 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3208 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3210 /* the tests below assume sane bmpImage masks */
3211 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
3212 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3213 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3214 convs
->Convert_888_to_0888_reverse
3216 srcbits
,-bmpImage
->bytes_per_line
,
3218 } else if (bmpImage
->blue_mask
==0xff) {
3219 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3220 convs
->Convert_rgb888_to_any0888
3222 srcbits
,-bmpImage
->bytes_per_line
,
3226 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3227 convs
->Convert_bgr888_to_any0888
3229 srcbits
,-bmpImage
->bytes_per_line
,
3239 const char* srcbits
;
3241 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3243 if (gDst
==bmpImage
->green_mask
) {
3244 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
3245 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3246 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3247 convs
->Convert_0888_asis
3249 srcbits
,-bmpImage
->bytes_per_line
,
3251 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3252 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3254 /* the tests below assume sane bmpImage masks */
3255 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
3256 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3257 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3258 convs
->Convert_0888_reverse
3260 srcbits
,-bmpImage
->bytes_per_line
,
3263 /* ==== any 0888 bmp -> any 0888 dib ==== */
3264 convs
->Convert_0888_any
3266 srcbits
,-bmpImage
->bytes_per_line
,
3267 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3271 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3272 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3274 /* the tests below assume sane bmpImage masks */
3276 /* ==== any 0888 bmp -> any 0888 dib ==== */
3277 convs
->Convert_0888_any
3279 srcbits
,-bmpImage
->bytes_per_line
,
3280 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3290 const char* srcbits
;
3292 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3294 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
3295 if (bmpImage
->green_mask
==0x03e0) {
3296 if (bmpImage
->red_mask
==0x7f00) {
3297 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3298 convs
->Convert_555_to_0888_asis
3300 srcbits
,-bmpImage
->bytes_per_line
,
3302 } else if (bmpImage
->blue_mask
==0x7f00) {
3303 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3304 convs
->Convert_555_to_0888_reverse
3306 srcbits
,-bmpImage
->bytes_per_line
,
3311 } else if (bmpImage
->green_mask
==0x07e0) {
3312 if (bmpImage
->red_mask
==0xf800) {
3313 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3314 convs
->Convert_565_to_0888_asis
3316 srcbits
,-bmpImage
->bytes_per_line
,
3318 } else if (bmpImage
->blue_mask
==0xf800) {
3319 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3320 convs
->Convert_565_to_0888_reverse
3322 srcbits
,-bmpImage
->bytes_per_line
,
3330 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
3331 if (bmpImage
->green_mask
==0x03e0) {
3332 if (bmpImage
->blue_mask
==0x7f00) {
3333 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3334 convs
->Convert_555_to_0888_asis
3336 srcbits
,-bmpImage
->bytes_per_line
,
3338 } else if (bmpImage
->red_mask
==0x7f00) {
3339 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3340 convs
->Convert_555_to_0888_reverse
3342 srcbits
,-bmpImage
->bytes_per_line
,
3347 } else if (bmpImage
->green_mask
==0x07e0) {
3348 if (bmpImage
->blue_mask
==0xf800) {
3349 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3350 convs
->Convert_565_to_0888_asis
3352 srcbits
,-bmpImage
->bytes_per_line
,
3354 } else if (bmpImage
->red_mask
==0xf800) {
3355 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3356 convs
->Convert_565_to_0888_reverse
3358 srcbits
,-bmpImage
->bytes_per_line
,
3367 if (bmpImage
->green_mask
==0x03e0 &&
3368 (bmpImage
->red_mask
==0x7f00 ||
3369 bmpImage
->blue_mask
==0x7f00)) {
3370 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3371 convs
->Convert_5x5_to_any0888
3373 srcbits
,-bmpImage
->bytes_per_line
,
3374 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3377 } else if (bmpImage
->green_mask
==0x07e0 &&
3378 (bmpImage
->red_mask
==0xf800 ||
3379 bmpImage
->blue_mask
==0xf800)) {
3380 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3381 convs
->Convert_5x5_to_any0888
3383 srcbits
,-bmpImage
->bytes_per_line
,
3384 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3396 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3398 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3399 int rShift
,gShift
,bShift
;
3402 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3403 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3404 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3405 for (h
= lines
- 1; h
>= 0; h
--) {
3406 dstpixel
=(DWORD
*)dstbits
;
3407 for (x
= 0; x
< width
; x
++) {
3408 PALETTEENTRY srcval
;
3409 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3410 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3411 (srcval
.peGreen
<< gShift
) |
3412 (srcval
.peBlue
<< bShift
);
3414 dstbits
+= linebytes
;
3422 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3424 /* ==== pal 8 bmp -> any 0888 dib ==== */
3425 int rShift
,gShift
,bShift
;
3426 const void* srcbits
;
3427 const BYTE
* srcpixel
;
3430 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3431 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3432 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3433 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3434 for (h
= lines
- 1; h
>= 0; h
--) {
3436 dstpixel
=(DWORD
*)dstbits
;
3437 for (x
= 0; x
< width
; x
++) {
3438 PALETTEENTRY srcval
;
3439 srcval
=srccolors
[*srcpixel
++];
3440 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3441 (srcval
.peGreen
<< gShift
) |
3442 (srcval
.peBlue
<< bShift
);
3444 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3445 dstbits
+= linebytes
;
3455 /* ==== any bmp format -> any 0888 dib ==== */
3456 int rShift
,gShift
,bShift
;
3459 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3460 bmpImage
->depth
, bmpImage
->red_mask
,
3461 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3464 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3465 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3466 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3467 for (h
= lines
- 1; h
>= 0; h
--) {
3468 dstpixel
=(DWORD
*)dstbits
;
3469 for (x
= 0; x
< width
; x
++) {
3471 srcval
=X11DRV_PALETTE_ToLogical(physDev
, XGetPixel(bmpImage
, x
, h
));
3472 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3473 (GetGValue(srcval
) << gShift
) |
3474 (GetBValue(srcval
) << bShift
);
3476 dstbits
+= linebytes
;
3483 static int XGetSubImageErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
3485 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
3488 /***********************************************************************
3489 * X11DRV_DIB_SetImageBits_GetSubImage
3491 * Helper for X11DRV_DIB_SetImageBits
3493 static void X11DRV_DIB_SetImageBits_GetSubImage(
3494 const X11DRV_DIB_IMAGEBITS_DESCR
*descr
, XImage
*bmpImage
)
3496 /* compressed bitmaps may contain gaps in them. So make a copy
3497 * of the existing pixels first */
3500 SetRect( &bmprc
, descr
->xDest
, descr
->yDest
,
3501 descr
->xDest
+ descr
->width
, descr
->yDest
+ descr
->height
);
3502 GetRgnBox( descr
->physDev
->region
, &rc
);
3503 /* convert from dc to drawable origin */
3504 OffsetRect( &rc
, descr
->physDev
->dc_rect
.left
, descr
->physDev
->dc_rect
.top
);
3505 /* clip visible rect with bitmap */
3506 if( IntersectRect( &rc
, &rc
, &bmprc
))
3508 X11DRV_expect_error( gdi_display
, XGetSubImageErrorHandler
, NULL
);
3509 XGetSubImage( gdi_display
, descr
->drawable
, rc
.left
, rc
.top
,
3510 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, AllPlanes
,
3512 descr
->xSrc
+ rc
.left
- bmprc
.left
,
3513 descr
->ySrc
+ rc
.top
- bmprc
.top
);
3514 X11DRV_check_error();
3518 /***********************************************************************
3519 * X11DRV_DIB_SetImageBits
3521 * Transfer the bits to an X image.
3522 * Helper function for SetDIBits() and SetDIBitsToDevice().
3524 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3526 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3527 void *old_data
= NULL
;
3532 bmpImage
= descr
->image
;
3534 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3535 descr
->infoWidth
, lines
, 32, 0 );
3536 bmpImage
->data
= HeapAlloc( GetProcessHeap(), 0, lines
* bmpImage
->bytes_per_line
);
3537 if(bmpImage
->data
== NULL
) {
3538 ERR("Out of memory!\n");
3539 XDestroyImage( bmpImage
);
3540 wine_tsx11_unlock();
3545 bmpImage
->red_mask
= descr
->shifts
->physicalRed
.max
<< descr
->shifts
->physicalRed
.shift
;
3546 bmpImage
->green_mask
= descr
->shifts
->physicalGreen
.max
<< descr
->shifts
->physicalGreen
.shift
;
3547 bmpImage
->blue_mask
= descr
->shifts
->physicalBlue
.max
<< descr
->shifts
->physicalBlue
.shift
;
3550 wine_tsx11_unlock();
3552 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3553 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3554 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3555 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3556 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3558 #ifdef HAVE_LIBXXSHM
3559 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
3560 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3561 && descr
->xDest
== 0 && descr
->yDest
== 0)
3563 TRACE("Using the shared pixmap data.\n");
3566 XSync( gdi_display
, False
);
3567 wine_tsx11_unlock();
3569 old_data
= descr
->image
->data
;
3570 descr
->image
->data
= descr
->physBitmap
->shminfo
.shmaddr
;
3574 /* Transfer the pixels */
3577 switch(descr
->infoBpp
)
3580 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3581 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3582 bmpImage
, descr
->dibpitch
);
3585 if (descr
->compression
) {
3586 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3587 X11DRV_DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
3588 descr
->infoWidth
, descr
->width
,
3589 descr
->xSrc
, (int *)(descr
->colorMap
),
3592 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3593 descr
->infoWidth
, descr
->width
,
3594 descr
->xSrc
, (int*)(descr
->colorMap
),
3595 bmpImage
, descr
->dibpitch
);
3598 if (descr
->compression
) {
3599 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3600 X11DRV_DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
3601 descr
->infoWidth
, descr
->width
,
3602 descr
->xSrc
, (int *)(descr
->colorMap
),
3605 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3606 descr
->infoWidth
, descr
->width
,
3607 descr
->xSrc
, (int *)(descr
->colorMap
),
3608 bmpImage
, descr
->dibpitch
);
3612 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3613 descr
->infoWidth
, descr
->width
,
3614 descr
->xSrc
, descr
->physDev
,
3615 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3616 bmpImage
, descr
->dibpitch
);
3619 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3620 descr
->infoWidth
, descr
->width
,
3621 descr
->xSrc
, descr
->physDev
,
3622 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3623 bmpImage
, descr
->dibpitch
);
3626 X11DRV_DIB_SetImageBits_32( descr
->lines
, descr
->bits
,
3627 descr
->infoWidth
, descr
->width
,
3628 descr
->xSrc
, descr
->physDev
,
3629 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3630 bmpImage
, descr
->dibpitch
);
3633 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3639 WARN( "invalid bits pointer %p\n", descr
->bits
);
3644 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3645 descr
->drawable
, descr
->gc
, bmpImage
,
3646 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3647 descr
->width
, descr
->height
);
3652 #ifdef HAVE_LIBXXSHM
3653 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
3654 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3655 && descr
->xDest
== 0 && descr
->yDest
== 0)
3657 XSync( gdi_display
, False
);
3659 else if (descr
->shm_mode
== X11DRV_SHM_IMAGE
&& descr
->image
)
3661 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3662 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3663 descr
->width
, descr
->height
, FALSE
);
3664 XSync( gdi_display
, 0 );
3669 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3670 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3671 descr
->width
, descr
->height
);
3675 if (old_data
) descr
->image
->data
= old_data
;
3677 if (!descr
->image
) X11DRV_DIB_DestroyXImage( bmpImage
);
3678 wine_tsx11_unlock();
3682 /***********************************************************************
3683 * X11DRV_DIB_GetImageBits
3685 * Transfer the bits from an X image.
3687 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3689 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3690 void *old_data
= NULL
;
3695 bmpImage
= descr
->image
;
3697 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3698 descr
->infoWidth
, lines
, 32, 0 );
3699 bmpImage
->data
= HeapAlloc( GetProcessHeap(), 0, lines
* bmpImage
->bytes_per_line
);
3700 if(bmpImage
->data
== NULL
) {
3701 ERR("Out of memory!\n");
3702 XDestroyImage( bmpImage
);
3703 wine_tsx11_unlock();
3708 bmpImage
->red_mask
= descr
->shifts
->physicalRed
.max
<< descr
->shifts
->physicalRed
.shift
;
3709 bmpImage
->green_mask
= descr
->shifts
->physicalGreen
.max
<< descr
->shifts
->physicalGreen
.shift
;
3710 bmpImage
->blue_mask
= descr
->shifts
->physicalBlue
.max
<< descr
->shifts
->physicalBlue
.shift
;
3714 #ifdef HAVE_LIBXXSHM
3716 /* We must not call XShmGetImage() with a bitmap which is bigger than the available area.
3717 If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */
3718 if (descr
->shm_mode
== X11DRV_SHM_PIXMAP
&& descr
->image
3719 && descr
->xSrc
== 0 && descr
->ySrc
== 0
3720 && descr
->xDest
== 0 && descr
->yDest
== 0
3721 && bmpImage
->width
<= (descr
->width
- descr
->xSrc
)
3722 && bmpImage
->height
<= (descr
->height
- descr
->ySrc
))
3724 XSync( gdi_display
, False
);
3725 old_data
= bmpImage
->data
;
3726 bmpImage
->data
= descr
->physBitmap
->shminfo
.shmaddr
;
3727 TRACE("Using shared pixmap data.\n");
3729 else if (descr
->shm_mode
== X11DRV_SHM_IMAGE
&& descr
->image
3730 && bmpImage
->width
<= (descr
->width
- descr
->xSrc
)
3731 && bmpImage
->height
<= (descr
->height
- descr
->ySrc
))
3733 int saveRed
, saveGreen
, saveBlue
;
3735 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3736 gdi_display
, descr
->drawable
, bmpImage
,
3737 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3739 /* We must save and restore the bmpImage's masks in order
3740 * to preserve them across the call to XShmGetImage, which
3741 * decides to eliminate them since it doesn't happen to know
3742 * what the format of the image is supposed to be, even though
3744 saveRed
= bmpImage
->red_mask
;
3745 saveBlue
= bmpImage
->blue_mask
;
3746 saveGreen
= bmpImage
->green_mask
;
3748 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3749 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3751 bmpImage
->red_mask
= saveRed
;
3752 bmpImage
->blue_mask
= saveBlue
;
3753 bmpImage
->green_mask
= saveGreen
;
3756 #endif /* HAVE_LIBXXSHM */
3758 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3759 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3760 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3761 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3762 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3763 bmpImage
, descr
->xDest
, descr
->yDest
);
3765 wine_tsx11_unlock();
3767 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3768 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3769 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3770 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3771 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3772 /* Transfer the pixels */
3773 switch(descr
->infoBpp
)
3776 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3777 descr
->infoWidth
, descr
->width
,
3778 descr
->colorMap
, descr
->palentry
,
3779 bmpImage
, descr
->dibpitch
);
3783 if (descr
->compression
) {
3784 FIXME("Compression not yet supported!\n");
3785 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 4 ) * abs(descr
->lines
))
3788 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3789 descr
->infoWidth
, descr
->width
,
3790 descr
->colorMap
, descr
->palentry
,
3791 bmpImage
, descr
->dibpitch
);
3794 if (descr
->compression
) {
3795 FIXME("Compression not yet supported!\n");
3796 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 8 ) * abs(descr
->lines
))
3799 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3800 descr
->infoWidth
, descr
->width
,
3801 descr
->colorMap
, descr
->palentry
,
3802 bmpImage
, descr
->dibpitch
);
3806 X11DRV_DIB_GetImageBits_16( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3807 descr
->infoWidth
,descr
->width
,
3809 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3810 bmpImage
, descr
->dibpitch
);
3814 X11DRV_DIB_GetImageBits_24( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3815 descr
->infoWidth
,descr
->width
,
3817 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3818 bmpImage
, descr
->dibpitch
);
3822 X11DRV_DIB_GetImageBits_32( descr
->physDev
, descr
->lines
, (LPVOID
)descr
->bits
,
3823 descr
->infoWidth
, descr
->width
,
3825 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3826 bmpImage
, descr
->dibpitch
);
3830 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3834 if (old_data
) bmpImage
->data
= old_data
;
3835 if (!descr
->image
) X11DRV_DIB_DestroyXImage( bmpImage
);
3839 /*************************************************************************
3840 * X11DRV_SetDIBitsToDevice
3843 INT
X11DRV_SetDIBitsToDevice( PHYSDEV dev
, INT xDest
, INT yDest
, DWORD cx
, DWORD cy
,
3844 INT xSrc
, INT ySrc
, UINT startscan
, UINT lines
, LPCVOID bits
,
3845 const BITMAPINFO
*info
, UINT coloruse
)
3847 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3848 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3853 int rop
= X11DRV_XROPfunction
[GetROP2(dev
->hdc
) - 1];
3855 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3856 &descr
.infoBpp
, &descr
.compression
) == -1)
3859 top_down
= (height
< 0);
3860 if (top_down
) height
= -height
;
3864 LPtoDP(dev
->hdc
, &pt
, 1);
3866 if (!lines
|| (startscan
>= height
)) return 0;
3867 if (!top_down
&& startscan
+ lines
> height
) lines
= height
- startscan
;
3869 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3870 * and clamp all values to fit inside [startscan,startscan+lines]
3872 if (ySrc
+ cy
<= startscan
+ lines
)
3874 UINT y
= startscan
+ lines
- (ySrc
+ cy
);
3875 if (ySrc
< startscan
) cy
-= (startscan
- ySrc
);
3878 /* avoid getting unnecessary lines */
3880 if (y
>= lines
) return 0;
3885 if (y
>= lines
) return lines
;
3886 ySrc
= y
; /* need to get all lines in top down mode */
3891 if (ySrc
>= startscan
+ lines
) return lines
;
3892 pt
.y
+= ySrc
+ cy
- (startscan
+ lines
);
3893 cy
= startscan
+ lines
- ySrc
;
3895 if (cy
> lines
) cy
= lines
;
3897 if (xSrc
>= width
) return lines
;
3898 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
3899 if (!cx
|| !cy
) return lines
;
3901 /* Update the pixmap from the DIB section */
3902 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
3904 X11DRV_SetupGCForText( physDev
); /* To have the correct colors */
3906 XSetFunction(gdi_display
, physDev
->gc
, rop
);
3907 wine_tsx11_unlock();
3909 switch (descr
.infoBpp
)
3914 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3916 physDev
->depth
, info
, &descr
.nColorMap
);
3917 if (!descr
.colorMap
) return 0;
3918 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3922 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3923 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3924 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3930 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3931 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3932 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3937 descr
.physDev
= physDev
;
3940 descr
.palentry
= NULL
;
3941 descr
.lines
= top_down
? -lines
: lines
;
3942 descr
.infoWidth
= width
;
3943 descr
.depth
= physDev
->depth
;
3944 descr
.shifts
= physDev
->color_shifts
;
3945 descr
.drawable
= physDev
->drawable
;
3946 descr
.gc
= physDev
->gc
;
3949 descr
.xDest
= physDev
->dc_rect
.left
+ pt
.x
;
3950 descr
.yDest
= physDev
->dc_rect
.top
+ pt
.y
;
3953 descr
.shm_mode
= X11DRV_SHM_NONE
;
3954 descr
.dibpitch
= ((width
* descr
.infoBpp
+ 31) &~31) / 8;
3955 descr
.physBitmap
= NULL
;
3957 result
= X11DRV_DIB_SetImageBits( &descr
);
3959 if (descr
.infoBpp
<= 8)
3960 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3962 /* Update the DIBSection of the pixmap */
3963 X11DRV_UnlockDIBSection(physDev
, TRUE
);
3968 /***********************************************************************
3969 * SetDIBits (X11DRV.@)
3971 INT
X11DRV_SetDIBits( PHYSDEV dev
, HBITMAP hbitmap
, UINT startscan
,
3972 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
, UINT coloruse
)
3974 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
3975 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3976 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3978 LONG width
, height
, tmpheight
;
3981 descr
.physDev
= physDev
;
3983 if (!physBitmap
) return 0;
3985 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3986 &descr
.infoBpp
, &descr
.compression
) == -1)
3990 if (height
< 0) height
= -height
;
3991 if (!lines
|| (startscan
>= height
))
3994 if (!GetObjectW( hbitmap
, sizeof(ds
), &ds
)) return 0;
3996 if (startscan
+ lines
> height
) lines
= height
- startscan
;
3998 switch (descr
.infoBpp
)
4003 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
4004 descr
.physDev
, coloruse
,
4005 physBitmap
->pixmap_depth
,
4006 info
, &descr
.nColorMap
);
4007 if (!descr
.colorMap
) return 0;
4008 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4012 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4013 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4014 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4020 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4021 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4022 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4031 descr
.palentry
= NULL
;
4032 descr
.infoWidth
= width
;
4033 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
4034 descr
.depth
= physBitmap
->pixmap_depth
;
4035 descr
.shifts
= physBitmap
->trueColor
? &physBitmap
->pixmap_color_shifts
: NULL
;
4036 descr
.drawable
= physBitmap
->pixmap
;
4037 descr
.gc
= get_bitmap_gc(physBitmap
->pixmap_depth
);
4041 descr
.yDest
= height
- startscan
- lines
;
4042 descr
.width
= ds
.dsBm
.bmWidth
;
4043 descr
.height
= lines
;
4044 descr
.shm_mode
= X11DRV_SHM_NONE
;
4045 descr
.dibpitch
= ((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8;
4046 descr
.physBitmap
= NULL
;
4047 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
4048 result
= X11DRV_DIB_SetImageBits( &descr
);
4050 /* optimisation for the case where the input bits are in exactly the same
4051 * format as the internal representation and copying to the app bits is
4052 * cheap - saves a round trip to the X server */
4053 if (descr
.compression
== BI_RGB
&&
4054 coloruse
== DIB_RGB_COLORS
&&
4055 descr
.infoBpp
== ds
.dsBm
.bmBitsPixel
&&
4056 physBitmap
->base
&& physBitmap
->size
< 65536)
4058 unsigned int srcwidthb
= X11DRV_DIB_GetDIBWidthBytes( width
, descr
.infoBpp
);
4059 int dstwidthb
= ds
.dsBm
.bmWidthBytes
;
4060 LPBYTE dbits
= physBitmap
->base
+ startscan
* dstwidthb
;
4061 const BYTE
*sbits
= bits
;
4065 TRACE("syncing compatible set bits to app bits\n");
4066 if ((tmpheight
< 0) ^ physBitmap
->topdown
)
4068 dbits
+= dstwidthb
* (lines
-1);
4069 dstwidthb
= -dstwidthb
;
4071 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4072 widthb
= min(srcwidthb
, abs(dstwidthb
));
4073 for (y
= 0; y
< lines
; y
++, dbits
+= dstwidthb
, sbits
+= srcwidthb
)
4074 memcpy(dbits
, sbits
, widthb
);
4075 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4076 physBitmap
->status
= DIB_Status_InSync
;
4078 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4080 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4085 /***********************************************************************
4086 * GetDIBits (X11DRV.@)
4088 INT
X11DRV_GetDIBits( PHYSDEV dev
, HBITMAP hbitmap
, UINT startscan
, UINT lines
,
4089 LPVOID bits
, BITMAPINFO
*info
, UINT coloruse
)
4091 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
4092 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
4094 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4095 PALETTEENTRY palette
[256];
4098 LONG width
, tempHeight
;
4102 static const PALETTEENTRY peBlack
= {0,0,0,0};
4103 static const PALETTEENTRY peWhite
= {255,255,255,0};
4105 if (!physBitmap
) return 0;
4106 if (!(obj_size
= GetObjectW( hbitmap
, sizeof(dib
), &dib
))) return 0;
4108 bitmap_type
= DIB_GetBitmapInfo( (BITMAPINFOHEADER
*)info
, &width
, &tempHeight
, &descr
.infoBpp
, &descr
.compression
);
4109 if (bitmap_type
== -1)
4111 ERR("Invalid bitmap\n");
4115 if (physBitmap
->pixmap_depth
> 1)
4117 GetPaletteEntries( GetCurrentObject( dev
->hdc
, OBJ_PAL
), 0, 256, palette
);
4121 palette
[0] = peBlack
;
4122 palette
[1] = peWhite
;
4125 descr
.lines
= tempHeight
;
4126 core_header
= (bitmap_type
== 0);
4127 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
4129 TRACE("%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
4130 lines
, dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
, width
, descr
.lines
, startscan
);
4132 if( lines
> dib
.dsBm
.bmHeight
) lines
= dib
.dsBm
.bmHeight
;
4134 height
= descr
.lines
;
4135 if (height
< 0) height
= -height
;
4136 if( lines
> height
) lines
= height
;
4137 /* Top-down images have a negative biHeight, the scanlines of these images
4138 * were inverted in X11DRV_DIB_GetImageBits_xx
4139 * To prevent this we simply change the sign of lines
4140 * (the number of scan lines to copy).
4141 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
4143 if( descr
.lines
< 0 && lines
> 0) lines
= -lines
;
4145 if( startscan
>= dib
.dsBm
.bmHeight
) return 0;
4147 descr
.colorMap
= NULL
;
4149 switch (descr
.infoBpp
)
4154 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4155 if(coloruse
== DIB_RGB_COLORS
)
4156 descr
.colorMap
= colorPtr
;
4158 int num_colors
= 1 << descr
.infoBpp
, i
;
4161 WORD
*index
= colorPtr
;
4162 descr
.colorMap
= rgb
= HeapAlloc(GetProcessHeap(), 0, num_colors
* sizeof(RGBQUAD
));
4163 for(i
= 0; i
< num_colors
; i
++, rgb
++, index
++) {
4164 colref
= X11DRV_PALETTE_ToLogical(physDev
, X11DRV_PALETTE_ToPhysical(physDev
, PALETTEINDEX(*index
)));
4165 rgb
->rgbRed
= GetRValue(colref
);
4166 rgb
->rgbGreen
= GetGValue(colref
);
4167 rgb
->rgbBlue
= GetBValue(colref
);
4168 rgb
->rgbReserved
= 0;
4174 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4175 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4176 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4180 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4181 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4182 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4186 descr
.physDev
= physDev
;
4187 descr
.palentry
= palette
;
4189 descr
.image
= physBitmap
->image
;
4190 descr
.infoWidth
= width
;
4191 descr
.lines
= lines
;
4192 descr
.depth
= physBitmap
->pixmap_depth
;
4193 descr
.shifts
= physBitmap
->trueColor
? &physBitmap
->pixmap_color_shifts
: NULL
;
4194 descr
.drawable
= physBitmap
->pixmap
;
4195 descr
.gc
= get_bitmap_gc(physBitmap
->pixmap_depth
);
4196 descr
.width
= dib
.dsBm
.bmWidth
;
4197 descr
.height
= dib
.dsBm
.bmHeight
;
4201 descr
.sizeImage
= core_header
? 0 : info
->bmiHeader
.biSizeImage
;
4202 descr
.physBitmap
= physBitmap
;
4204 if (descr
.lines
> 0)
4206 descr
.ySrc
= (descr
.height
-1) - (startscan
+ (lines
-1));
4210 descr
.ySrc
= startscan
;
4212 descr
.shm_mode
= physBitmap
->shm_mode
;
4213 descr
.dibpitch
= (((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8);
4215 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
);
4216 X11DRV_DIB_GetImageBits( &descr
);
4217 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4219 if(!core_header
&& info
->bmiHeader
.biSizeImage
== 0) /* Fill in biSizeImage */
4220 info
->bmiHeader
.biSizeImage
= X11DRV_DIB_GetDIBImageBytes( descr
.infoWidth
,
4224 if (descr
.compression
== BI_BITFIELDS
)
4226 *(DWORD
*)info
->bmiColors
= descr
.rMask
;
4227 *((DWORD
*)info
->bmiColors
+ 1) = descr
.gMask
;
4228 *((DWORD
*)info
->bmiColors
+ 2) = descr
.bMask
;
4230 else if (!core_header
)
4232 /* if RLE or JPEG compression were supported,
4233 * this line would be invalid. */
4234 info
->bmiHeader
.biCompression
= 0;
4237 if(descr
.colorMap
!= colorPtr
)
4238 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4242 /***********************************************************************
4243 * X11DRV_DIB_DoCopyDIBSection
4245 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
4246 void *colorMap
, int nColorMap
,
4247 Drawable dest
, GC gc
,
4248 DWORD xSrc
, DWORD ySrc
,
4249 DWORD xDest
, DWORD yDest
,
4250 DWORD width
, DWORD height
)
4252 DIBSECTION dibSection
;
4253 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4254 int identity
[2] = {0,1};
4256 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
4258 descr
.physDev
= NULL
;
4259 descr
.palentry
= NULL
;
4260 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
4261 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
4262 descr
.lines
= physBitmap
->topdown
? -dibSection
.dsBmih
.biHeight
: dibSection
.dsBmih
.biHeight
;
4263 descr
.image
= physBitmap
->image
;
4264 descr
.colorMap
= colorMap
;
4265 descr
.nColorMap
= nColorMap
;
4266 descr
.bits
= dibSection
.dsBm
.bmBits
;
4267 descr
.depth
= physBitmap
->pixmap_depth
;
4268 descr
.shifts
= physBitmap
->trueColor
? &physBitmap
->pixmap_color_shifts
: NULL
;
4269 descr
.compression
= dibSection
.dsBmih
.biCompression
;
4270 descr
.physBitmap
= physBitmap
;
4272 if(descr
.infoBpp
== 1)
4273 descr
.colorMap
= (void*)identity
;
4275 switch (descr
.infoBpp
)
4280 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4284 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
4285 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
4286 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
4291 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
4292 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
4293 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
4298 descr
.drawable
= dest
;
4302 descr
.xDest
= xDest
;
4303 descr
.yDest
= yDest
;
4304 descr
.width
= width
;
4305 descr
.height
= height
;
4306 descr
.sizeImage
= 0;
4308 descr
.shm_mode
= physBitmap
->shm_mode
;
4309 #ifdef HAVE_LIBXXSHM
4310 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
&& physBitmap
->pixmap
!= dest
)
4312 descr
.shm_mode
= X11DRV_SHM_NONE
;
4315 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
4319 TRACE("Copying from Pixmap to DIB bits\n");
4320 X11DRV_DIB_GetImageBits( &descr
);
4324 TRACE("Copying from DIB bits to Pixmap\n");
4325 X11DRV_DIB_SetImageBits( &descr
);
4329 /***********************************************************************
4330 * X11DRV_DIB_CopyDIBSection
4332 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE
*physDevSrc
, X11DRV_PDEVICE
*physDevDst
,
4333 DWORD xSrc
, DWORD ySrc
, DWORD xDest
, DWORD yDest
,
4334 DWORD width
, DWORD height
)
4337 X_PHYSBITMAP
*physBitmap
;
4338 unsigned int nColorMap
;
4342 TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc
->dev
.hdc
, physDevDst
->dev
.hdc
,
4343 xSrc
, ySrc
, xDest
, yDest
, width
, height
);
4344 /* this function is meant as an optimization for BitBlt,
4345 * not to be called otherwise */
4346 physBitmap
= physDevSrc
->bitmap
;
4347 if (!physBitmap
|| GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
4349 ERR("called for non-DIBSection!?\n");
4352 /* while BitBlt should already have made sure we only get
4353 * positive values, we should check for oversize values */
4354 if ((xSrc
< dib
.dsBm
.bmWidth
) &&
4355 (ySrc
< dib
.dsBm
.bmHeight
)) {
4356 if (xSrc
+ width
> dib
.dsBm
.bmWidth
)
4357 width
= dib
.dsBm
.bmWidth
- xSrc
;
4358 if (ySrc
+ height
> dib
.dsBm
.bmHeight
)
4359 height
= dib
.dsBm
.bmHeight
- ySrc
;
4360 /* if the source bitmap is 8bpp or less, we're supposed to use the
4361 * DC's palette for color conversion (not the DIB color table) */
4362 if (dib
.dsBm
.bmBitsPixel
<= 8) {
4363 HPALETTE hPalette
= GetCurrentObject( physDevSrc
->dev
.hdc
, OBJ_PAL
);
4364 if (!hPalette
|| (hPalette
== GetStockObject(DEFAULT_PALETTE
))) {
4365 /* HACK: no palette has been set in the source DC,
4366 * use the DIB colormap instead - this is necessary in some
4367 * cases since we need to do depth conversion in some places
4368 * where real Windows can just copy data straight over */
4369 x11ColorMap
= physBitmap
->colorMap
;
4370 nColorMap
= physBitmap
->nColorMap
;
4371 freeColorMap
= FALSE
;
4373 const BITMAPINFO
* info
= (BITMAPINFO
*)&dib
.dsBmih
;
4376 nColorMap
= X11DRV_DIB_GetColorCount(info
);
4377 x11ColorMap
= HeapAlloc(GetProcessHeap(), 0, nColorMap
* sizeof(int));
4378 for (i
= 0; i
< nColorMap
; i
++)
4379 x11ColorMap
[i
] = X11DRV_PALETTE_ToPhysical(physDevSrc
, PALETTEINDEX(i
));
4380 freeColorMap
= TRUE
;
4387 freeColorMap
= FALSE
;
4389 /* perform the copy */
4390 X11DRV_DIB_DoCopyDIBSection(physBitmap
, FALSE
, x11ColorMap
, nColorMap
,
4391 physDevDst
->drawable
, physDevDst
->gc
, xSrc
, ySrc
,
4392 physDevDst
->dc_rect
.left
+ xDest
, physDevDst
->dc_rect
.top
+ yDest
,
4394 /* free color mapping */
4396 HeapFree(GetProcessHeap(), 0, x11ColorMap
);
4400 /***********************************************************************
4401 * X11DRV_DIB_DoUpdateDIBSection
4403 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
4407 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
4408 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
4409 physBitmap
->colorMap
, physBitmap
->nColorMap
,
4410 physBitmap
->pixmap
, get_bitmap_gc(physBitmap
->pixmap_depth
),
4411 0, 0, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
);
4414 /***********************************************************************
4415 * X11DRV_DIB_FaultHandler
4417 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
4419 X_PHYSBITMAP
*physBitmap
= NULL
;
4423 const size_t pagemask
= getpagesize() - 1;
4425 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
4426 return EXCEPTION_CONTINUE_SEARCH
;
4428 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
4430 EnterCriticalSection(&dibs_cs
);
4431 LIST_FOR_EACH( ptr
, &dibs_list
)
4433 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
4434 if ((physBitmap
->base
<= addr
) &&
4435 (addr
< physBitmap
->base
+ ((physBitmap
->size
+ pagemask
) & ~pagemask
)))
4441 LeaveCriticalSection(&dibs_cs
);
4443 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
4445 if (addr
>= physBitmap
->base
+ physBitmap
->size
)
4446 WARN( "%p: access to %p beyond the end of the DIB\n", physBitmap
->hbitmap
, addr
);
4448 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
);
4449 if (ep
->ExceptionRecord
->ExceptionInformation
[0] == EXCEPTION_WRITE_FAULT
) {
4450 /* the app tried to write the DIB bits */
4451 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
);
4453 /* the app tried to read the DIB bits */
4454 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
);
4456 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4458 return EXCEPTION_CONTINUE_EXECUTION
;
4461 /***********************************************************************
4464 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
)
4466 INT ret
= DIB_Status_None
;
4468 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4469 EnterCriticalSection(&physBitmap
->lock
);
4470 ret
= physBitmap
->status
;
4472 case DIB_Status_GdiMod
:
4473 /* GDI access - request to draw on pixmap */
4474 switch (physBitmap
->status
)
4477 case DIB_Status_None
:
4478 physBitmap
->p_status
= DIB_Status_GdiMod
;
4479 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4482 case DIB_Status_GdiMod
:
4483 TRACE("GdiMod requested in status GdiMod\n" );
4484 physBitmap
->p_status
= DIB_Status_GdiMod
;
4487 case DIB_Status_InSync
:
4488 TRACE("GdiMod requested in status InSync\n" );
4489 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4490 physBitmap
->status
= DIB_Status_GdiMod
;
4491 physBitmap
->p_status
= DIB_Status_InSync
;
4494 case DIB_Status_AppMod
:
4495 TRACE("GdiMod requested in status AppMod\n" );
4496 /* make it readonly to avoid app changing data while we copy */
4497 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4498 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4499 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4500 physBitmap
->p_status
= DIB_Status_AppMod
;
4501 physBitmap
->status
= DIB_Status_GdiMod
;
4506 case DIB_Status_InSync
:
4507 /* App access - request access to read DIB surface */
4508 /* (typically called from signal handler) */
4509 switch (physBitmap
->status
)
4512 case DIB_Status_None
:
4513 /* shouldn't happen from signal handler */
4516 case DIB_Status_GdiMod
:
4517 TRACE("InSync requested in status GdiMod\n" );
4518 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4519 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4520 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4521 physBitmap
->status
= DIB_Status_InSync
;
4524 case DIB_Status_InSync
:
4525 TRACE("InSync requested in status InSync\n" );
4526 /* shouldn't happen from signal handler */
4529 case DIB_Status_AppMod
:
4530 TRACE("InSync requested in status AppMod\n" );
4531 /* no reason to do anything here, and this
4532 * shouldn't happen from signal handler */
4537 case DIB_Status_AppMod
:
4538 /* App access - request access to write DIB surface */
4539 /* (typically called from signal handler) */
4540 switch (physBitmap
->status
)
4543 case DIB_Status_None
:
4544 /* shouldn't happen from signal handler */
4547 case DIB_Status_GdiMod
:
4548 TRACE("AppMod requested in status GdiMod\n" );
4549 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4550 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4551 physBitmap
->status
= DIB_Status_AppMod
;
4554 case DIB_Status_InSync
:
4555 TRACE("AppMod requested in status InSync\n" );
4556 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4557 physBitmap
->status
= DIB_Status_AppMod
;
4560 case DIB_Status_AppMod
:
4561 TRACE("AppMod requested in status AppMod\n" );
4562 /* shouldn't happen from signal handler */
4567 /* it is up to the caller to do the copy/conversion, probably
4568 * using the return value to decide where to copy from */
4570 LeaveCriticalSection(&physBitmap
->lock
);
4574 /***********************************************************************
4577 INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
)
4579 INT ret
= DIB_Status_None
;
4581 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4582 TRACE("Locking %p from thread %04x\n", physBitmap
->hbitmap
, GetCurrentThreadId());
4583 EnterCriticalSection(&physBitmap
->lock
);
4584 ret
= physBitmap
->status
;
4585 if (req
!= DIB_Status_None
)
4586 X11DRV_DIB_Coerce(physBitmap
, req
);
4590 /***********************************************************************
4593 void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
4595 if (!physBitmap
->image
) return; /* not a DIB section */
4596 switch (physBitmap
->status
)
4599 case DIB_Status_None
:
4600 /* in case anyone is wondering, this is the "signal handler doesn't
4601 * work" case, where we always have to be ready for app access */
4603 switch (physBitmap
->p_status
)
4605 case DIB_Status_GdiMod
:
4606 TRACE("Unlocking and syncing from GdiMod\n" );
4607 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4611 TRACE("Unlocking without needing to sync\n" );
4615 else TRACE("Unlocking with no changes\n");
4616 physBitmap
->p_status
= DIB_Status_None
;
4619 case DIB_Status_GdiMod
:
4620 TRACE("Unlocking in status GdiMod\n" );
4621 /* DIB was protected in Coerce */
4623 /* no commit, revert to InSync if applicable */
4624 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
4625 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
4626 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4627 physBitmap
->status
= DIB_Status_InSync
;
4632 case DIB_Status_InSync
:
4633 TRACE("Unlocking in status InSync\n" );
4634 /* DIB was already protected in Coerce */
4637 case DIB_Status_AppMod
:
4638 TRACE("Unlocking in status AppMod\n" );
4639 /* DIB was already protected in Coerce */
4640 /* this case is ordinary only called from the signal handler,
4641 * so we don't bother to check for !commit */
4644 LeaveCriticalSection(&physBitmap
->lock
);
4645 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
4648 /***********************************************************************
4649 * X11DRV_CoerceDIBSection
4651 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4653 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4654 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
);
4657 /***********************************************************************
4658 * X11DRV_LockDIBSection
4660 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
)
4662 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4663 return X11DRV_DIB_Lock(physDev
->bitmap
, req
);
4666 /***********************************************************************
4667 * X11DRV_UnlockDIBSection
4669 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
4671 if (!physDev
|| !physDev
->bitmap
) return;
4672 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
4676 #ifdef HAVE_LIBXXSHM
4677 /***********************************************************************
4678 * X11DRV_XShmErrorHandler
4681 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
4683 return 1; /* FIXME: should check event contents */
4686 /***********************************************************************
4687 * X11DRV_XShmCreateImage
4690 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
4691 XShmSegmentInfo
* shminfo
)
4695 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
4698 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
4700 if( shminfo
->shmid
!= -1 )
4702 shminfo
->shmaddr
= shmat( shminfo
->shmid
, 0, 0 );
4703 if( shminfo
->shmaddr
!= (char*)-1 )
4707 shminfo
->readOnly
= FALSE
;
4708 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
4709 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
4710 XSync( gdi_display
, False
);
4711 if (X11DRV_check_error()) ok
= FALSE
;
4714 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4715 return image
; /* Success! */
4717 /* An error occurred */
4718 shmdt(shminfo
->shmaddr
);
4720 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4721 shminfo
->shmid
= -1;
4723 XFlush(gdi_display
);
4724 XDestroyImage(image
);
4729 #endif /* HAVE_LIBXXSHM */
4731 static Bool
X11DRV_DIB_QueryXShm( Bool
*pixmaps
)
4733 static Bool have_xshm
, have_xshm_pixmaps
;
4734 static BOOL initialized
;
4738 #ifdef HAVE_LIBXXSHM
4741 have_xshm
= XShmQueryVersion( gdi_display
, &major
, &minor
, &have_xshm_pixmaps
);
4746 *pixmaps
= have_xshm_pixmaps
;
4750 /***********************************************************************
4751 * X11DRV_CreateDIBSection (X11DRV.@)
4753 HBITMAP
X11DRV_CreateDIBSection( PHYSDEV dev
, HBITMAP hbitmap
, const BITMAPINFO
*bmi
, UINT usage
)
4755 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
4756 X_PHYSBITMAP
*physBitmap
;
4760 #ifdef HAVE_LIBXXSHM
4764 DIB_GetBitmapInfo( &bmi
->bmiHeader
, &w
, &h
, &bpp
, &compr
);
4766 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
4767 if (h
< 0) physBitmap
->topdown
= TRUE
;
4768 physBitmap
->status
= DIB_Status_None
;
4770 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
4772 /* create color map */
4773 if (dib
.dsBm
.bmBitsPixel
<= 8)
4775 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( physDev
,
4776 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
4777 &physBitmap
->nColorMap
);
4780 if (!X11DRV_XRender_SetPhysBitmapDepth( physBitmap
, dib
.dsBm
.bmBitsPixel
, &dib
))
4782 if (dib
.dsBm
.bmBitsPixel
== 1)
4784 physBitmap
->pixmap_depth
= 1;
4785 physBitmap
->trueColor
= FALSE
;
4789 physBitmap
->pixmap_depth
= screen_depth
;
4790 physBitmap
->pixmap_color_shifts
= X11DRV_PALETTE_default_shifts
;
4791 physBitmap
->trueColor
= (visual
->class == TrueColor
|| visual
->class == DirectColor
);
4795 /* create pixmap and X image */
4797 #ifdef HAVE_LIBXXSHM
4798 physBitmap
->shminfo
.shmid
= -1;
4800 if (X11DRV_DIB_QueryXShm( &pixmaps
)
4801 && (physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4802 physBitmap
->pixmap_depth
, &physBitmap
->shminfo
)))
4806 physBitmap
->shm_mode
= X11DRV_SHM_PIXMAP
;
4807 physBitmap
->image
->data
= HeapAlloc( GetProcessHeap(), 0,
4808 dib
.dsBm
.bmHeight
* physBitmap
->image
->bytes_per_line
);
4812 physBitmap
->shm_mode
= X11DRV_SHM_IMAGE
;
4813 physBitmap
->image
->data
= physBitmap
->shminfo
.shmaddr
;
4819 physBitmap
->shm_mode
= X11DRV_SHM_NONE
;
4820 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4821 physBitmap
->pixmap_depth
);
4824 #ifdef HAVE_LIBXXSHM
4825 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
)
4827 TRACE("Creating shared pixmap for bmp %p.\n", physBitmap
->hbitmap
);
4828 physBitmap
->pixmap
= XShmCreatePixmap( gdi_display
, root_window
,
4829 physBitmap
->shminfo
.shmaddr
, &physBitmap
->shminfo
,
4830 dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4831 physBitmap
->pixmap_depth
);
4836 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
4837 dib
.dsBm
.bmHeight
, physBitmap
->pixmap_depth
);
4840 wine_tsx11_unlock();
4841 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
4843 if (physBitmap
->trueColor
)
4845 ColorShifts
*shifts
= &physBitmap
->pixmap_color_shifts
;
4847 /* When XRender is around and used, we also support dibsections in other formats like 16-bit. In these
4848 * cases we need to override the mask of XImages. The reason is that during XImage creation the masks are
4849 * derived from a 24-bit visual (no 16-bit ones are around when X runs at 24-bit). SetImageBits and other
4850 * functions rely on the color masks for proper color conversion, so we need to override the masks here. */
4851 physBitmap
->image
->red_mask
= shifts
->physicalRed
.max
<< shifts
->physicalRed
.shift
;
4852 physBitmap
->image
->green_mask
= shifts
->physicalGreen
.max
<< shifts
->physicalGreen
.shift
;
4853 physBitmap
->image
->blue_mask
= shifts
->physicalBlue
.max
<< shifts
->physicalBlue
.shift
;
4856 /* install fault handler */
4857 InitializeCriticalSection( &physBitmap
->lock
);
4858 physBitmap
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": X_PHYSBITMAP.lock");
4860 physBitmap
->base
= dib
.dsBm
.bmBits
;
4861 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
4862 physBitmap
->status
= DIB_Status_AppMod
;
4865 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
4866 EnterCriticalSection( &dibs_cs
);
4867 list_add_head( &dibs_list
, &physBitmap
->entry
);
4868 LeaveCriticalSection( &dibs_cs
);
4870 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4875 /***********************************************************************
4876 * X11DRV_DIB_DeleteDIBSection
4878 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
4882 EnterCriticalSection( &dibs_cs
);
4883 list_remove( &physBitmap
->entry
);
4884 last
= list_empty( &dibs_list
);
4885 LeaveCriticalSection( &dibs_cs
);
4889 RemoveVectoredExceptionHandler( dibs_handler
);
4890 dibs_handler
= NULL
;
4893 if (dib
->dshSection
)
4894 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
);
4896 if (physBitmap
->image
)
4899 #ifdef HAVE_LIBXXSHM
4900 if (physBitmap
->shminfo
.shmid
!= -1)
4902 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4903 if (physBitmap
->shm_mode
== X11DRV_SHM_PIXMAP
) X11DRV_DIB_DestroyXImage( physBitmap
->image
);
4904 else XDestroyImage( physBitmap
->image
);
4905 shmdt( physBitmap
->shminfo
.shmaddr
);
4906 physBitmap
->shminfo
.shmid
= -1;
4907 physBitmap
->shm_mode
= X11DRV_SHM_NONE
;
4911 X11DRV_DIB_DestroyXImage( physBitmap
->image
);
4912 wine_tsx11_unlock();
4915 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4916 physBitmap
->lock
.DebugInfo
->Spare
[0] = 0;
4917 DeleteCriticalSection(&physBitmap
->lock
);
4920 /***********************************************************************
4921 * SetDIBColorTable (X11DRV.@)
4923 UINT
X11DRV_SetDIBColorTable( PHYSDEV dev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4925 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
4928 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4930 if (!physBitmap
) return 0;
4931 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4933 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4934 UINT end
= count
+ start
;
4935 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4937 * Changing color table might change the mapping between
4938 * DIB colors and X11 colors and thus alter the visible state
4939 * of the bitmap object.
4942 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4943 * at least for a 1 bpp dibsection
4945 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
);
4946 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4947 dib
.dsBm
.bmBitsPixel
,
4948 TRUE
, colors
, start
, end
);
4949 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4956 /***********************************************************************
4957 * X11DRV_DIB_CreateDIBFromBitmap
4959 * Allocates a packed DIB and copies the bitmap data into it.
4961 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4966 LPBITMAPINFOHEADER pbmiHeader
;
4967 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4970 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4973 * A packed DIB contains a BITMAPINFO structure followed immediately by
4974 * an optional color palette and the pixel data.
4977 /* Calculate the size of the packed DIB */
4978 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4979 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4980 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4982 /* Get the offset to the bits */
4983 OffsetBits
= cPackedSize
- cDataSize
;
4985 /* Allocate the packed DIB */
4986 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4987 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4991 WARN("Could not allocate packed DIB!\n");
4995 /* A packed DIB starts with a BITMAPINFOHEADER */
4996 pPackedDIB
= GlobalLock(hPackedDIB
);
4997 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4999 /* Init the BITMAPINFOHEADER */
5000 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
5001 pbmiHeader
->biWidth
= bmp
.bmWidth
;
5002 pbmiHeader
->biHeight
= bmp
.bmHeight
;
5003 pbmiHeader
->biPlanes
= 1;
5004 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
5005 pbmiHeader
->biCompression
= BI_RGB
;
5006 pbmiHeader
->biSizeImage
= 0;
5007 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
5008 pbmiHeader
->biClrUsed
= 0;
5009 pbmiHeader
->biClrImportant
= 0;
5011 /* Retrieve the DIB bits from the bitmap and fill in the
5012 * DIB color table if present */
5014 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
5015 hBmp
, /* Handle to bitmap */
5016 0, /* First scan line to set in dest bitmap */
5017 bmp
.bmHeight
, /* Number of scan lines to copy */
5018 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
5019 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
5020 0); /* RGB or palette index */
5021 GlobalUnlock(hPackedDIB
);
5023 /* Cleanup if GetDIBits failed */
5024 if (nLinesCopied
!= bmp
.bmHeight
)
5026 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
5027 GlobalFree(hPackedDIB
);
5034 /**************************************************************************
5035 * X11DRV_DIB_CreateDIBFromPixmap
5037 * Allocates a packed DIB and copies the Pixmap data into it.
5038 * The Pixmap passed in is deleted after the conversion.
5040 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
5043 X_PHYSBITMAP
*physBitmap
;
5046 HGLOBAL hPackedDIB
= 0;
5048 int x
,y
; /* Unused */
5049 unsigned border_width
; /* Unused */
5050 unsigned int depth
, width
, height
;
5052 /* Get the Pixmap dimensions and bit depth */
5054 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
5055 &border_width
, &depth
)) depth
= 0;
5056 wine_tsx11_unlock();
5057 if (!pixmap_formats
[depth
]) return 0;
5059 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
5060 width
, height
, depth
);
5063 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
5064 * and make it a container for the pixmap passed.
5066 if (!(hBmp
= CreateBitmap( width
, height
, 1, pixmap_formats
[depth
]->bits_per_pixel
, NULL
))) return 0;
5068 /* force bitmap to be owned by a screen DC */
5069 hdcMem
= CreateCompatibleDC( hdc
);
5070 SelectObject( hdcMem
, SelectObject( hdcMem
, hBmp
));
5073 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
5075 /* swap the new pixmap in */
5076 orig_pixmap
= physBitmap
->pixmap
;
5077 physBitmap
->pixmap
= pixmap
;
5080 * Create a packed DIB from the Pixmap wrapper bitmap created above.
5081 * A packed DIB contains a BITMAPINFO structure followed immediately by
5082 * an optional color palette and the pixel data.
5084 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
5086 /* we can now get rid of the HBITMAP and its original pixmap */
5087 physBitmap
->pixmap
= orig_pixmap
;
5090 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
5095 /**************************************************************************
5096 * X11DRV_DIB_CreatePixmapFromDIB
5098 * Creates a Pixmap from a packed DIB
5100 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
5103 X_PHYSBITMAP
*physBitmap
;
5107 /* Create a DDB from the DIB */
5109 pbmi
= GlobalLock(hPackedDIB
);
5110 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
5111 (LPBYTE
)pbmi
+ bitmap_info_size( pbmi
, DIB_RGB_COLORS
),
5112 pbmi
, DIB_RGB_COLORS
);
5113 GlobalUnlock(hPackedDIB
);
5115 /* clear the physBitmap so that we can steal its pixmap */
5116 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
5117 pixmap
= physBitmap
->pixmap
;
5118 physBitmap
->pixmap
= 0;
5120 /* Delete the DDB we created earlier now that we have stolen its pixmap */
5123 TRACE("Returning Pixmap %lx\n", pixmap
);