2 * X11DRV device-independent bitmaps
4 * Copyright 1993,1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <X11/extensions/XShm.h>
26 # ifdef HAVE_SYS_SHM_H
29 # ifdef HAVE_SYS_IPC_H
32 #endif /* defined(HAVE_LIBXXSHM) */
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(bitmap
);
46 static struct list dibs_list
= LIST_INIT(dibs_list
);
48 static CRITICAL_SECTION dibs_cs
;
49 static CRITICAL_SECTION_DEBUG dibs_cs_debug
=
52 { &dibs_cs_debug
.ProcessLocksList
, &dibs_cs_debug
.ProcessLocksList
},
53 0, 0, { (DWORD_PTR
)(__FILE__
": dibs_cs") }
55 static CRITICAL_SECTION dibs_cs
= { &dibs_cs_debug
, -1, 0, 0, 0, 0 };
57 static PVOID dibs_handler
;
59 static int ximageDepthTable
[32];
61 /* This structure holds the arguments for DIB_SetImageBits() */
64 X11DRV_PDEVICE
*physDev
;
67 PALETTEENTRY
*palentry
;
89 } X11DRV_DIB_IMAGEBITS_DESCR
;
94 RLE_EOL
= 0, /* End of line */
95 RLE_END
= 1, /* End of bitmap */
96 RLE_DELTA
= 2 /* Delta */
100 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*,INT
,BOOL
);
101 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*,INT
,BOOL
);
102 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*,BOOL
);
105 Some of the following helper functions are duplicated in
109 /***********************************************************************
110 * X11DRV_DIB_GetXImageWidthBytes
112 * Return the width of an X image in bytes
114 inline static int X11DRV_DIB_GetXImageWidthBytes( int width
, int depth
)
116 if (!depth
|| depth
> 32) goto error
;
118 if (!ximageDepthTable
[depth
-1])
120 XImage
*testimage
= XCreateImage( gdi_display
, visual
, depth
,
121 ZPixmap
, 0, NULL
, 1, 1, 32, 20 );
124 ximageDepthTable
[depth
-1] = testimage
->bits_per_pixel
;
125 XDestroyImage( testimage
);
127 else ximageDepthTable
[depth
-1] = -1;
129 if (ximageDepthTable
[depth
-1] != -1)
130 return (4 * ((width
* ximageDepthTable
[depth
-1] + 31) / 32));
133 WARN( "(%d): Unsupported depth\n", depth
);
138 /***********************************************************************
139 * X11DRV_DIB_GetDIBWidthBytes
141 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
143 static int X11DRV_DIB_GetDIBWidthBytes( int width
, int depth
)
149 case 1: words
= (width
+ 31) / 32; break;
150 case 4: words
= (width
+ 7) / 8; break;
151 case 8: words
= (width
+ 3) / 4; break;
153 case 16: words
= (width
+ 1) / 2; break;
154 case 24: words
= (width
* 3 + 3) / 4; break;
156 WARN("(%d): Unsupported depth\n", depth
);
165 /***********************************************************************
166 * X11DRV_DIB_GetDIBImageBytes
168 * Return the number of bytes used to hold the image in a DIB bitmap.
170 static int X11DRV_DIB_GetDIBImageBytes( int width
, int height
, int depth
)
172 return X11DRV_DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
176 /***********************************************************************
177 * X11DRV_DIB_BitmapInfoSize
179 * Return the size of the bitmap info structure including color table.
181 int X11DRV_DIB_BitmapInfoSize( const BITMAPINFO
* info
, WORD coloruse
)
185 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
187 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
188 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
189 return sizeof(BITMAPCOREHEADER
) + colors
*
190 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
192 else /* assume BITMAPINFOHEADER */
194 colors
= info
->bmiHeader
.biClrUsed
;
195 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
196 colors
= 1 << info
->bmiHeader
.biBitCount
;
197 return sizeof(BITMAPINFOHEADER
) + colors
*
198 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
203 /***********************************************************************
204 * X11DRV_DIB_CreateXImage
208 XImage
*X11DRV_DIB_CreateXImage( int width
, int height
, int depth
)
214 width_bytes
= X11DRV_DIB_GetXImageWidthBytes( width
, depth
);
215 image
= XCreateImage( gdi_display
, visual
, depth
, ZPixmap
, 0,
216 calloc( height
, width_bytes
),
217 width
, height
, 32, width_bytes
);
223 /***********************************************************************
224 * DIB_GetBitmapInfoEx
226 * Get the info from a bitmap header.
227 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
229 static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER
*header
, LONG
*width
,
230 LONG
*height
, WORD
*planes
, WORD
*bpp
,
231 WORD
*compr
, DWORD
*size
)
233 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
235 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
236 *width
= core
->bcWidth
;
237 *height
= core
->bcHeight
;
238 *planes
= core
->bcPlanes
;
239 *bpp
= core
->bcBitCount
;
244 if (header
->biSize
>= sizeof(BITMAPINFOHEADER
))
246 *width
= header
->biWidth
;
247 *height
= header
->biHeight
;
248 *planes
= header
->biPlanes
;
249 *bpp
= header
->biBitCount
;
250 *compr
= header
->biCompression
;
251 *size
= header
->biSizeImage
;
254 ERR("(%ld): unknown/wrong size for header\n", header
->biSize
);
259 /***********************************************************************
262 * Get the info from a bitmap header.
263 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
265 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
266 LONG
*height
, WORD
*bpp
, WORD
*compr
)
271 return DIB_GetBitmapInfoEx( header
, width
, height
, &planes
, bpp
, compr
, &size
);
275 /***********************************************************************
276 * X11DRV_DIB_GenColorMap
278 * Fills the color map of a bitmap palette. Should not be called
279 * for a >8-bit deep bitmap.
281 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE
*physDev
, int *colorMapping
,
282 WORD coloruse
, WORD depth
, BOOL quads
,
283 const void *colorPtr
, int start
, int end
)
287 if (coloruse
== DIB_RGB_COLORS
)
291 const RGBQUAD
* rgb
= (const RGBQUAD
*)colorPtr
;
293 if (depth
== 1) /* Monochrome */
294 for (i
= start
; i
< end
; i
++, rgb
++)
295 colorMapping
[i
] = (rgb
->rgbRed
+ rgb
->rgbGreen
+
296 rgb
->rgbBlue
> 255*3/2);
298 for (i
= start
; i
< end
; i
++, rgb
++)
299 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, RGB(rgb
->rgbRed
,
305 const RGBTRIPLE
* rgb
= (const RGBTRIPLE
*)colorPtr
;
307 if (depth
== 1) /* Monochrome */
308 for (i
= start
; i
< end
; i
++, rgb
++)
309 colorMapping
[i
] = (rgb
->rgbtRed
+ rgb
->rgbtGreen
+
310 rgb
->rgbtBlue
> 255*3/2);
312 for (i
= start
; i
< end
; i
++, rgb
++)
313 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, RGB(rgb
->rgbtRed
,
318 else /* DIB_PAL_COLORS */
321 const WORD
* index
= (const WORD
*)colorPtr
;
323 for (i
= start
; i
< end
; i
++, index
++)
324 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(*index
) );
326 for (i
= start
; i
< end
; i
++)
327 colorMapping
[i
] = X11DRV_PALETTE_ToPhysical( physDev
, PALETTEINDEX(i
) );
334 /***********************************************************************
335 * X11DRV_DIB_BuildColorMap
337 * Build the color map from the bitmap palette. Should not be called
338 * for a >8-bit deep bitmap.
340 int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
341 const BITMAPINFO
*info
, int *nColors
)
345 const void *colorPtr
;
348 isInfo
= info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
);
352 colors
= info
->bmiHeader
.biClrUsed
;
353 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
357 colors
= 1 << ((const BITMAPCOREHEADER
*)info
)->bcBitCount
;
360 colorPtr
= (const BYTE
*) info
+ (WORD
) info
->bmiHeader
.biSize
;
364 ERR("called with >256 colors!\n");
368 /* just so CopyDIBSection doesn't have to create an identity palette */
369 if (coloruse
== (WORD
)-1) colorPtr
= NULL
;
371 if (!(colorMapping
= HeapAlloc(GetProcessHeap(), 0, colors
* sizeof(int) )))
375 return X11DRV_DIB_GenColorMap( physDev
, colorMapping
, coloruse
, depth
,
376 isInfo
, colorPtr
, 0, colors
);
379 /***********************************************************************
380 * X11DRV_DIB_BuildColorTable
382 * Build the dib color table. This either keeps a copy of the bmiColors array if
383 * usage is DIB_RGB_COLORS, or looks up the palette indicies if usage is
385 * Should not be called for a >8-bit deep bitmap.
387 static RGBQUAD
*X11DRV_DIB_BuildColorTable( X11DRV_PDEVICE
*physDev
, WORD coloruse
, WORD depth
,
388 const BITMAPINFO
*info
)
393 BOOL core_info
= info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
);
397 colors
= 1 << ((const BITMAPCOREINFO
*) info
)->bmciHeader
.bcBitCount
;
401 colors
= info
->bmiHeader
.biClrUsed
;
402 if (!colors
) colors
= 1 << info
->bmiHeader
.biBitCount
;
406 ERR("called with >256 colors!\n");
410 if (!(colorTable
= HeapAlloc(GetProcessHeap(), 0, colors
* sizeof(RGBQUAD
) )))
413 if(coloruse
== DIB_RGB_COLORS
)
417 /* Convert RGBTRIPLEs to RGBQUADs */
418 for (i
=0; i
< colors
; i
++)
420 colorTable
[i
].rgbRed
= ((const BITMAPCOREINFO
*) info
)->bmciColors
[i
].rgbtRed
;
421 colorTable
[i
].rgbGreen
= ((const BITMAPCOREINFO
*) info
)->bmciColors
[i
].rgbtGreen
;
422 colorTable
[i
].rgbBlue
= ((const BITMAPCOREINFO
*) info
)->bmciColors
[i
].rgbtBlue
;
423 colorTable
[i
].rgbReserved
= 0;
428 memcpy(colorTable
, (const BYTE
*) info
+ (WORD
) info
->bmiHeader
.biSize
, colors
* sizeof(RGBQUAD
));
433 HPALETTE hpal
= GetCurrentObject(physDev
->hdc
, OBJ_PAL
);
434 PALETTEENTRY
* pal_ents
;
435 const WORD
*index
= (const WORD
*) ((const BYTE
*) info
+ (WORD
) info
->bmiHeader
.biSize
);
436 int logcolors
, entry
;
438 logcolors
= GetPaletteEntries( hpal
, 0, 0, NULL
);
439 pal_ents
= HeapAlloc(GetProcessHeap(), 0, logcolors
* sizeof(*pal_ents
));
440 logcolors
= GetPaletteEntries( hpal
, 0, logcolors
, pal_ents
);
442 for(i
= 0; i
< colors
; i
++, index
++)
444 entry
= *index
% logcolors
;
445 colorTable
[i
].rgbRed
= pal_ents
[entry
].peRed
;
446 colorTable
[i
].rgbGreen
= pal_ents
[entry
].peGreen
;
447 colorTable
[i
].rgbBlue
= pal_ents
[entry
].peBlue
;
448 colorTable
[i
].rgbReserved
= 0;
451 HeapFree(GetProcessHeap(), 0, pal_ents
);
457 /***********************************************************************
458 * X11DRV_DIB_MapColor
460 static int X11DRV_DIB_MapColor( int *physMap
, int nPhysMap
, int phys
, int oldcol
)
464 if ((oldcol
< nPhysMap
) && (physMap
[oldcol
] == phys
))
467 for (color
= 0; color
< nPhysMap
; color
++)
468 if (physMap
[color
] == phys
)
471 WARN("Strange color %08x\n", phys
);
476 /*********************************************************************
477 * X11DRV_DIB_GetNearestIndex
479 * Helper for X11DRV_DIB_GetDIBits.
480 * Returns the nearest colour table index for a given RGB.
481 * Nearest is defined by minimizing the sum of the squares.
483 static INT
X11DRV_DIB_GetNearestIndex(RGBQUAD
*colormap
, int numColors
, BYTE r
, BYTE g
, BYTE b
)
485 INT i
, best
= -1, diff
, bestdiff
= -1;
488 for(color
= colormap
, i
= 0; i
< numColors
; color
++, i
++) {
489 diff
= (r
- color
->rgbRed
) * (r
- color
->rgbRed
) +
490 (g
- color
->rgbGreen
) * (g
- color
->rgbGreen
) +
491 (b
- color
->rgbBlue
) * (b
- color
->rgbBlue
);
494 if(best
== -1 || diff
< bestdiff
) {
501 /*********************************************************************
502 * X11DRV_DIB_MaskToShift
504 * Helper for X11DRV_DIB_GetDIBits.
505 * Returns the by how many bits to shift a given color so that it is
506 * in the proper position.
508 INT
X11DRV_DIB_MaskToShift(DWORD mask
)
516 while ((mask
&1)==0) {
523 /***********************************************************************
524 * X11DRV_DIB_CheckMask
526 * Check RGB mask if it is either 0 or matches visual's mask.
528 static inline int X11DRV_DIB_CheckMask(int red_mask
, int green_mask
, int blue_mask
)
530 return ( red_mask
== 0 && green_mask
== 0 && blue_mask
== 0 ) ||
531 ( red_mask
== visual
->red_mask
&& green_mask
== visual
->green_mask
&&
532 blue_mask
== visual
->blue_mask
);
535 /***********************************************************************
536 * X11DRV_DIB_SetImageBits_1
538 * SetDIBits for a 1-bit deep DIB.
540 static void X11DRV_DIB_SetImageBits_1( int lines
, const BYTE
*srcbits
,
541 DWORD srcwidth
, DWORD dstwidth
, int left
,
542 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
551 srcbits
= srcbits
+ linebytes
* (lines
- 1);
552 linebytes
= -linebytes
;
555 if ((extra
= (left
& 7)) != 0) {
559 srcbits
+= left
>> 3;
560 width
= min(srcwidth
, dstwidth
);
562 /* ==== pal 1 dib -> any bmp format ==== */
563 for (h
= lines
-1; h
>=0; h
--) {
565 /* FIXME: should avoid putting x<left pixels (minor speed issue) */
566 for (i
= width
/8, x
= left
; i
> 0; i
--) {
568 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
>> 7] );
569 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 6) & 1] );
570 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 5) & 1] );
571 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 4) & 1] );
572 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 3) & 1] );
573 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 2) & 1] );
574 XPutPixel( bmpImage
, x
++, h
, colors
[(srcval
>> 1) & 1] );
575 XPutPixel( bmpImage
, x
++, h
, colors
[ srcval
& 1] );
581 case 7: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
582 case 6: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
583 case 5: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
584 case 4: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
585 case 3: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
586 case 2: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]); srcval
<<=1;
587 case 1: XPutPixel(bmpImage
, x
++, h
, colors
[srcval
>> 7]);
590 srcbits
+= linebytes
;
594 /***********************************************************************
595 * X11DRV_DIB_GetImageBits_1
597 * GetDIBits for a 1-bit deep DIB.
599 static void X11DRV_DIB_GetImageBits_1( int lines
, BYTE
*dstbits
,
600 DWORD dstwidth
, DWORD srcwidth
,
601 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
602 XImage
*bmpImage
, DWORD linebytes
)
605 int h
, width
= min(dstwidth
, srcwidth
);
609 dstbits
= dstbits
+ linebytes
* (lines
- 1);
610 linebytes
= -linebytes
;
613 switch (bmpImage
->depth
)
617 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
619 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
622 for (h
=lines
-1; h
>=0; h
--) {
626 for (x
=0; x
<width
; x
++) {
628 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
629 dstval
|=(X11DRV_DIB_GetNearestIndex
633 srcval
.peBlue
) << (7 - (x
& 7)));
642 dstbits
+= linebytes
;
650 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
, bmpImage
->green_mask
, bmpImage
->blue_mask
)
652 /* ==== pal 8 bmp -> pal 1 dib ==== */
654 const BYTE
* srcpixel
;
657 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
659 for (h
=0; h
<lines
; h
++) {
664 for (x
=0; x
<width
; x
++) {
666 srcval
=srccolors
[(int)*srcpixel
++];
667 dstval
|=(X11DRV_DIB_GetNearestIndex
671 srcval
.peBlue
) << (7-(x
&7)) );
680 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
681 dstbits
+= linebytes
;
692 const WORD
* srcpixel
;
695 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
697 if (bmpImage
->green_mask
==0x03e0) {
698 if (bmpImage
->red_mask
==0x7c00) {
699 /* ==== rgb 555 bmp -> pal 1 dib ==== */
700 for (h
=0; h
<lines
; h
++) {
705 for (x
=0; x
<width
; x
++) {
708 dstval
|=(X11DRV_DIB_GetNearestIndex
710 ((srcval
>> 7) & 0xf8) | /* r */
711 ((srcval
>> 12) & 0x07),
712 ((srcval
>> 2) & 0xf8) | /* g */
713 ((srcval
>> 7) & 0x07),
714 ((srcval
<< 3) & 0xf8) | /* b */
715 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
724 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
725 dstbits
+= linebytes
;
727 } else if (bmpImage
->blue_mask
==0x7c00) {
728 /* ==== bgr 555 bmp -> pal 1 dib ==== */
729 for (h
=0; h
<lines
; h
++) {
734 for (x
=0; x
<width
; x
++) {
737 dstval
|=(X11DRV_DIB_GetNearestIndex
739 ((srcval
<< 3) & 0xf8) | /* r */
740 ((srcval
>> 2) & 0x07),
741 ((srcval
>> 2) & 0xf8) | /* g */
742 ((srcval
>> 7) & 0x07),
743 ((srcval
>> 7) & 0xf8) | /* b */
744 ((srcval
>> 12) & 0x07) ) << (7-(x
&7)) );
753 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
754 dstbits
+= linebytes
;
759 } else if (bmpImage
->green_mask
==0x07e0) {
760 if (bmpImage
->red_mask
==0xf800) {
761 /* ==== rgb 565 bmp -> pal 1 dib ==== */
762 for (h
=0; h
<lines
; h
++) {
767 for (x
=0; x
<width
; x
++) {
770 dstval
|=(X11DRV_DIB_GetNearestIndex
772 ((srcval
>> 8) & 0xf8) | /* r */
773 ((srcval
>> 13) & 0x07),
774 ((srcval
>> 3) & 0xfc) | /* g */
775 ((srcval
>> 9) & 0x03),
776 ((srcval
<< 3) & 0xf8) | /* b */
777 ((srcval
>> 2) & 0x07) ) << (7-(x
&7)) );
786 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
787 dstbits
+= linebytes
;
789 } else if (bmpImage
->blue_mask
==0xf800) {
790 /* ==== bgr 565 bmp -> pal 1 dib ==== */
791 for (h
=0; h
<lines
; h
++) {
796 for (x
=0; x
<width
; x
++) {
799 dstval
|=(X11DRV_DIB_GetNearestIndex
801 ((srcval
<< 3) & 0xf8) | /* r */
802 ((srcval
>> 2) & 0x07),
803 ((srcval
>> 3) & 0xfc) | /* g */
804 ((srcval
>> 9) & 0x03),
805 ((srcval
>> 8) & 0xf8) | /* b */
806 ((srcval
>> 13) & 0x07) ) << (7-(x
&7)) );
815 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
816 dstbits
+= linebytes
;
835 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
836 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
838 if (bmpImage
->green_mask
!=0x00ff00 ||
839 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
841 } else if (bmpImage
->blue_mask
==0xff) {
842 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
843 for (h
=0; h
<lines
; h
++) {
848 for (x
=0; x
<width
; x
++) {
849 dstval
|=(X11DRV_DIB_GetNearestIndex
853 srcbyte
[0]) << (7-(x
&7)) );
854 srcbyte
+=bytes_per_pixel
;
863 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
864 dstbits
+= linebytes
;
867 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
868 for (h
=0; h
<lines
; h
++) {
873 for (x
=0; x
<width
; x
++) {
874 dstval
|=(X11DRV_DIB_GetNearestIndex
878 srcbyte
[2]) << (7-(x
&7)) );
879 srcbyte
+=bytes_per_pixel
;
888 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
889 dstbits
+= linebytes
;
900 unsigned long white
= (1 << bmpImage
->bits_per_pixel
) - 1;
902 /* ==== any bmp format -> pal 1 dib ==== */
903 if ((unsigned)colors
[0].rgbRed
+colors
[0].rgbGreen
+colors
[0].rgbBlue
>=
904 (unsigned)colors
[1].rgbRed
+colors
[1].rgbGreen
+colors
[1].rgbBlue
)
907 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
908 "%s color mapping\n",
909 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
910 bmpImage
->green_mask
, bmpImage
->blue_mask
,
911 neg
?"negative":"direct" );
913 for (h
=lines
-1; h
>=0; h
--) {
917 for (x
=0; x
<width
; x
++) {
918 dstval
|=((XGetPixel( bmpImage
, x
, h
) >= white
) ^ neg
) << (7 - (x
&7));
927 dstbits
+= linebytes
;
934 /***********************************************************************
935 * X11DRV_DIB_SetImageBits_4
937 * SetDIBits for a 4-bit deep DIB.
939 static void X11DRV_DIB_SetImageBits_4( int lines
, const BYTE
*srcbits
,
940 DWORD srcwidth
, DWORD dstwidth
, int left
,
941 int *colors
, XImage
*bmpImage
, DWORD linebytes
)
949 srcbits
= srcbits
+ linebytes
* (lines
- 1);
950 linebytes
= -linebytes
;
957 srcbits
+= left
>> 1;
958 width
= min(srcwidth
, dstwidth
);
960 /* ==== pal 4 dib -> any bmp format ==== */
961 for (h
= lines
-1; h
>= 0; h
--) {
963 for (i
= width
/2, x
= left
; i
> 0; i
--) {
964 BYTE srcval
=*srcbyte
++;
965 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
>> 4] );
966 XPutPixel( bmpImage
, x
++, h
, colors
[srcval
& 0x0f] );
969 XPutPixel( bmpImage
, x
, h
, colors
[*srcbyte
>> 4] );
970 srcbits
+= linebytes
;
976 /***********************************************************************
977 * X11DRV_DIB_GetImageBits_4
979 * GetDIBits for a 4-bit deep DIB.
981 static void X11DRV_DIB_GetImageBits_4( int lines
, BYTE
*dstbits
,
982 DWORD srcwidth
, DWORD dstwidth
,
983 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
984 XImage
*bmpImage
, DWORD linebytes
)
987 int h
, width
= min(srcwidth
, dstwidth
);
993 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
994 linebytes
= -linebytes
;
999 switch (bmpImage
->depth
) {
1002 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1004 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
1007 for (h
= lines
-1; h
>= 0; h
--) {
1011 for (x
= 0; x
< width
; x
++) {
1012 PALETTEENTRY srcval
;
1013 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1014 dstval
|=(X11DRV_DIB_GetNearestIndex
1018 srcval
.peBlue
) << (4-((x
&1)<<2)));
1027 dstbits
+= linebytes
;
1035 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1037 /* ==== pal 8 bmp -> pal 4 dib ==== */
1038 const void* srcbits
;
1039 const BYTE
*srcpixel
;
1042 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1043 for (h
=0; h
<lines
; h
++) {
1048 for (x
=0; x
<width
; x
++) {
1049 PALETTEENTRY srcval
;
1050 srcval
= srccolors
[(int)*srcpixel
++];
1051 dstval
|=(X11DRV_DIB_GetNearestIndex
1055 srcval
.peBlue
) << (4*(1-(x
&1))) );
1064 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1065 dstbits
+= linebytes
;
1075 const void* srcbits
;
1076 const WORD
* srcpixel
;
1079 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1081 if (bmpImage
->green_mask
==0x03e0) {
1082 if (bmpImage
->red_mask
==0x7c00) {
1083 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1084 for (h
=0; h
<lines
; h
++) {
1089 for (x
=0; x
<width
; x
++) {
1092 dstval
|=(X11DRV_DIB_GetNearestIndex
1094 ((srcval
>> 7) & 0xf8) | /* r */
1095 ((srcval
>> 12) & 0x07),
1096 ((srcval
>> 2) & 0xf8) | /* g */
1097 ((srcval
>> 7) & 0x07),
1098 ((srcval
<< 3) & 0xf8) | /* b */
1099 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1108 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1109 dstbits
+= linebytes
;
1111 } else if (bmpImage
->blue_mask
==0x7c00) {
1112 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1113 for (h
=0; h
<lines
; h
++) {
1118 for (x
=0; x
<width
; x
++) {
1121 dstval
|=(X11DRV_DIB_GetNearestIndex
1123 ((srcval
<< 3) & 0xf8) | /* r */
1124 ((srcval
>> 2) & 0x07),
1125 ((srcval
>> 2) & 0xf8) | /* g */
1126 ((srcval
>> 7) & 0x07),
1127 ((srcval
>> 7) & 0xf8) | /* b */
1128 ((srcval
>> 12) & 0x07) ) << ((1-(x
&1))<<2) );
1137 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1138 dstbits
+= linebytes
;
1143 } else if (bmpImage
->green_mask
==0x07e0) {
1144 if (bmpImage
->red_mask
==0xf800) {
1145 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1146 for (h
=0; h
<lines
; h
++) {
1151 for (x
=0; x
<width
; x
++) {
1154 dstval
|=(X11DRV_DIB_GetNearestIndex
1156 ((srcval
>> 8) & 0xf8) | /* r */
1157 ((srcval
>> 13) & 0x07),
1158 ((srcval
>> 3) & 0xfc) | /* g */
1159 ((srcval
>> 9) & 0x03),
1160 ((srcval
<< 3) & 0xf8) | /* b */
1161 ((srcval
>> 2) & 0x07) ) << ((1-(x
&1))<<2) );
1170 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1171 dstbits
+= linebytes
;
1173 } else if (bmpImage
->blue_mask
==0xf800) {
1174 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1175 for (h
=0; h
<lines
; h
++) {
1180 for (x
=0; x
<width
; x
++) {
1183 dstval
|=(X11DRV_DIB_GetNearestIndex
1185 ((srcval
<< 3) & 0xf8) | /* r */
1186 ((srcval
>> 2) & 0x07),
1187 ((srcval
>> 3) & 0xfc) | /* g */
1188 ((srcval
>> 9) & 0x03),
1189 ((srcval
>> 8) & 0xf8) | /* b */
1190 ((srcval
>> 13) & 0x07) ) << ((1-(x
&1))<<2) );
1199 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1200 dstbits
+= linebytes
;
1212 if (bmpImage
->bits_per_pixel
==24) {
1213 const void* srcbits
;
1214 const BYTE
*srcbyte
;
1217 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1219 if (bmpImage
->green_mask
!=0x00ff00 ||
1220 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1222 } else if (bmpImage
->blue_mask
==0xff) {
1223 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1224 for (h
=0; h
<lines
; h
++) {
1227 for (x
=0; x
<width
/2; x
++) {
1228 /* Do 2 pixels at a time */
1229 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1234 X11DRV_DIB_GetNearestIndex
1242 /* And the the odd pixel */
1243 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1249 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1250 dstbits
+= linebytes
;
1253 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1254 for (h
=0; h
<lines
; h
++) {
1257 for (x
=0; x
<width
/2; x
++) {
1258 /* Do 2 pixels at a time */
1259 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1264 X11DRV_DIB_GetNearestIndex
1272 /* And the the odd pixel */
1273 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1279 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1280 dstbits
+= linebytes
;
1289 const void* srcbits
;
1290 const BYTE
*srcbyte
;
1293 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1295 if (bmpImage
->green_mask
!=0x00ff00 ||
1296 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1298 } else if (bmpImage
->blue_mask
==0xff) {
1299 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1300 for (h
=0; h
<lines
; h
++) {
1303 for (x
=0; x
<width
/2; x
++) {
1304 /* Do 2 pixels at a time */
1305 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1310 X11DRV_DIB_GetNearestIndex
1318 /* And the the odd pixel */
1319 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1325 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1326 dstbits
+= linebytes
;
1329 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1330 for (h
=0; h
<lines
; h
++) {
1333 for (x
=0; x
<width
/2; x
++) {
1334 /* Do 2 pixels at a time */
1335 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1340 X11DRV_DIB_GetNearestIndex
1348 /* And the the odd pixel */
1349 *dstbyte
++=(X11DRV_DIB_GetNearestIndex
1355 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1356 dstbits
+= linebytes
;
1367 /* ==== any bmp format -> pal 4 dib ==== */
1368 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1369 bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
1370 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1371 for (h
=lines
-1; h
>=0; h
--) {
1373 for (x
=0; x
<(width
& ~1); x
+=2) {
1374 *dstbyte
++=(X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4) |
1375 X11DRV_DIB_MapColor((int*)colors
, 16, XGetPixel(bmpImage
, x
+1, h
), 0);
1378 *dstbyte
=(X11DRV_DIB_MapColor((int *)colors
, 16, XGetPixel(bmpImage
, x
, h
), 0) << 4);
1380 dstbits
+= linebytes
;
1387 /***********************************************************************
1388 * X11DRV_DIB_SetImageBits_RLE4
1390 * SetDIBits for a 4-bit deep compressed DIB.
1392 static void X11DRV_DIB_SetImageBits_RLE4( int lines
, const BYTE
*bits
,
1393 DWORD srcwidth
, DWORD dstwidth
,
1394 int left
, int *colors
,
1397 unsigned int x
= 0, width
= min(srcwidth
, dstwidth
);
1398 int y
= lines
- 1, c
, length
;
1399 const BYTE
*begin
= bits
;
1404 if (length
) { /* encoded */
1407 if (x
>= (left
+ width
)) break;
1408 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1410 if (!length
--) break;
1411 if (x
>= (left
+ width
)) break;
1412 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1432 default: /* absolute */
1435 if (x
>= left
&& x
< (left
+ width
))
1436 XPutPixel(bmpImage
, x
, y
, colors
[c
>> 4]);
1438 if (!length
--) break;
1439 if (x
>= left
&& x
< (left
+ width
))
1440 XPutPixel(bmpImage
, x
, y
, colors
[c
& 0xf]);
1443 if ((bits
- begin
) & 1)
1452 /***********************************************************************
1453 * X11DRV_DIB_SetImageBits_8
1455 * SetDIBits for an 8-bit deep DIB.
1457 static void X11DRV_DIB_SetImageBits_8( int lines
, const BYTE
*srcbits
,
1458 DWORD srcwidth
, DWORD dstwidth
, int left
,
1459 const int *colors
, XImage
*bmpImage
,
1463 int h
, width
= min(srcwidth
, dstwidth
);
1464 const BYTE
* srcbyte
;
1470 srcbits
= srcbits
+ linebytes
* (lines
-1);
1471 linebytes
= -linebytes
;
1476 switch (bmpImage
->depth
) {
1479 #if defined(__i386__) && defined(__GNUC__)
1480 /* Some X servers might have 32 bit/ 16bit deep pixel */
1481 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 16) &&
1482 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1484 dstbits
=(BYTE
*)bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1485 /* FIXME: Does this really handle all these cases correctly? */
1486 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1487 for (h
= lines
; h
--; ) {
1488 int _cl1
,_cl2
; /* temp outputs for asm below */
1489 /* Borrowed from DirectDraw */
1490 __asm__
__volatile__(
1495 " movw (%%edx,%%eax,4),%%ax\n"
1497 " xor %%eax,%%eax\n"
1499 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1504 :"eax", "cc", "memory"
1506 srcbyte
= (srcbits
+= linebytes
);
1507 dstbits
-= bmpImage
->bytes_per_line
;
1515 #if defined(__i386__) && defined(__GNUC__)
1516 if (lines
&& width
&& (bmpImage
->bits_per_pixel
== 32) &&
1517 (ImageByteOrder(gdi_display
)==LSBFirst
) )
1519 dstbits
=(BYTE
*)bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
1520 /* FIXME: Does this really handle both cases correctly? */
1521 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1522 for (h
= lines
; h
--; ) {
1523 int _cl1
,_cl2
; /* temp outputs for asm below */
1524 /* Borrowed from DirectDraw */
1525 __asm__
__volatile__(
1530 " movl (%%edx,%%eax,4),%%eax\n"
1532 " xor %%eax,%%eax\n"
1534 :"=S" (srcbyte
), "=D" (_cl1
), "=c" (_cl2
)
1539 :"eax", "cc", "memory"
1541 srcbyte
= (srcbits
+= linebytes
);
1542 dstbits
-= bmpImage
->bytes_per_line
;
1549 break; /* use slow generic case below */
1552 /* ==== pal 8 dib -> any bmp format ==== */
1553 for (h
=lines
-1; h
>=0; h
--) {
1554 for (x
=left
; x
<width
+left
; x
++) {
1555 XPutPixel(bmpImage
, x
, h
, colors
[*srcbyte
++]);
1557 srcbyte
= (srcbits
+= linebytes
);
1561 /***********************************************************************
1562 * X11DRV_DIB_GetImageBits_8
1564 * GetDIBits for an 8-bit deep DIB.
1566 static void X11DRV_DIB_GetImageBits_8( int lines
, BYTE
*dstbits
,
1567 DWORD srcwidth
, DWORD dstwidth
,
1568 RGBQUAD
*colors
, PALETTEENTRY
*srccolors
,
1569 XImage
*bmpImage
, DWORD linebytes
)
1572 int h
, width
= min(srcwidth
, dstwidth
);
1578 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
1579 linebytes
= -linebytes
;
1584 * This condition is true when GetImageBits has been called by
1585 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1586 * 256 colormaps, so we'll just use for for GetDIBits calls.
1587 * (In somes cases, in a updateDIBSection, the returned colors are bad too)
1589 if (!srccolors
) goto updatesection
;
1591 switch (bmpImage
->depth
) {
1594 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1597 /* ==== pal 1 bmp -> pal 8 dib ==== */
1598 /* ==== pal 4 bmp -> pal 8 dib ==== */
1599 for (h
=lines
-1; h
>=0; h
--) {
1601 for (x
=0; x
<width
; x
++) {
1602 PALETTEENTRY srcval
;
1603 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
1604 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1609 dstbits
+= linebytes
;
1617 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
1619 /* ==== pal 8 bmp -> pal 8 dib ==== */
1620 const void* srcbits
;
1621 const BYTE
* srcpixel
;
1623 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1624 for (h
=0; h
<lines
; h
++) {
1627 for (x
= 0; x
< width
; x
++) {
1628 PALETTEENTRY srcval
;
1629 srcval
=srccolors
[(int)*srcpixel
++];
1630 *dstbyte
++=X11DRV_DIB_GetNearestIndex(colors
, 256,
1635 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1636 dstbits
+= linebytes
;
1646 const void* srcbits
;
1647 const WORD
* srcpixel
;
1650 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1652 if (bmpImage
->green_mask
==0x03e0) {
1653 if (bmpImage
->red_mask
==0x7c00) {
1654 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1655 for (h
=0; h
<lines
; h
++) {
1658 for (x
=0; x
<width
; x
++) {
1661 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1663 ((srcval
>> 7) & 0xf8) | /* r */
1664 ((srcval
>> 12) & 0x07),
1665 ((srcval
>> 2) & 0xf8) | /* g */
1666 ((srcval
>> 7) & 0x07),
1667 ((srcval
<< 3) & 0xf8) | /* b */
1668 ((srcval
>> 2) & 0x07) );
1670 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1671 dstbits
+= linebytes
;
1673 } else if (bmpImage
->blue_mask
==0x7c00) {
1674 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1675 for (h
=0; h
<lines
; h
++) {
1678 for (x
=0; x
<width
; x
++) {
1681 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1683 ((srcval
<< 3) & 0xf8) | /* r */
1684 ((srcval
>> 2) & 0x07),
1685 ((srcval
>> 2) & 0xf8) | /* g */
1686 ((srcval
>> 7) & 0x07),
1687 ((srcval
>> 7) & 0xf8) | /* b */
1688 ((srcval
>> 12) & 0x07) );
1690 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1691 dstbits
+= linebytes
;
1696 } else if (bmpImage
->green_mask
==0x07e0) {
1697 if (bmpImage
->red_mask
==0xf800) {
1698 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1699 for (h
=0; h
<lines
; h
++) {
1702 for (x
=0; x
<width
; x
++) {
1705 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1707 ((srcval
>> 8) & 0xf8) | /* r */
1708 ((srcval
>> 13) & 0x07),
1709 ((srcval
>> 3) & 0xfc) | /* g */
1710 ((srcval
>> 9) & 0x03),
1711 ((srcval
<< 3) & 0xf8) | /* b */
1712 ((srcval
>> 2) & 0x07) );
1714 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1715 dstbits
+= linebytes
;
1717 } else if (bmpImage
->blue_mask
==0xf800) {
1718 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1719 for (h
=0; h
<lines
; h
++) {
1722 for (x
=0; x
<width
; x
++) {
1725 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1727 ((srcval
<< 3) & 0xf8) | /* r */
1728 ((srcval
>> 2) & 0x07),
1729 ((srcval
>> 3) & 0xfc) | /* g */
1730 ((srcval
>> 9) & 0x03),
1731 ((srcval
>> 8) & 0xf8) | /* b */
1732 ((srcval
>> 13) & 0x07) );
1734 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1735 dstbits
+= linebytes
;
1749 const void* srcbits
;
1750 const BYTE
*srcbyte
;
1752 int bytes_per_pixel
;
1754 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
1755 bytes_per_pixel
=(bmpImage
->bits_per_pixel
==24?3:4);
1757 if (bmpImage
->green_mask
!=0x00ff00 ||
1758 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
1760 } else if (bmpImage
->blue_mask
==0xff) {
1761 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1762 for (h
=0; h
<lines
; h
++) {
1765 for (x
=0; x
<width
; x
++) {
1766 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1771 srcbyte
+=bytes_per_pixel
;
1773 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1774 dstbits
+= linebytes
;
1777 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1778 for (h
=0; h
<lines
; h
++) {
1781 for (x
=0; x
<width
; x
++) {
1782 *dstbyte
++=X11DRV_DIB_GetNearestIndex
1787 srcbyte
+=bytes_per_pixel
;
1789 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
1790 dstbits
+= linebytes
;
1798 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1799 bmpImage
->depth
, bmpImage
->red_mask
,
1800 bmpImage
->green_mask
, bmpImage
->blue_mask
);
1802 /* ==== any bmp format -> pal 8 dib ==== */
1803 for (h
=lines
-1; h
>=0; h
--) {
1805 for (x
=0; x
<width
; x
++) {
1806 *dstbyte
=X11DRV_DIB_MapColor
1808 XGetPixel(bmpImage
, x
, h
), *dstbyte
);
1811 dstbits
+= linebytes
;
1817 /***********************************************************************
1818 * X11DRV_DIB_SetImageBits_RLE8
1820 * SetDIBits for an 8-bit deep compressed DIB.
1822 * This function rewritten 941113 by James Youngman. WINE blew out when I
1823 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1825 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1826 * 'End of bitmap' escape code. This code is very much laxer in what it
1827 * allows to end the expansion. Possibly too lax. See the note by
1828 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1829 * bitmap should end with RleEnd, but on the other hand, software exists
1830 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1833 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1834 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1837 static void X11DRV_DIB_SetImageBits_RLE8( int lines
, const BYTE
*bits
,
1838 DWORD srcwidth
, DWORD dstwidth
,
1839 int left
, int *colors
,
1842 unsigned int x
; /* X-position on each line. Increases. */
1843 int y
; /* Line #. Starts at lines-1, decreases */
1844 const BYTE
*pIn
= bits
; /* Pointer to current position in bits */
1845 BYTE length
; /* The length pf a run */
1846 BYTE escape_code
; /* See enum Rle8_EscapeCodes.*/
1849 * Note that the bitmap data is stored by Windows starting at the
1850 * bottom line of the bitmap and going upwards. Within each line,
1851 * the data is stored left-to-right. That's the reason why line
1852 * goes from lines-1 to 0. [JAY]
1862 * If the length byte is not zero (which is the escape value),
1863 * We have a run of length pixels all the same colour. The colour
1864 * index is stored next.
1866 * If the length byte is zero, we need to read the next byte to
1867 * know what to do. [JAY]
1872 * [Run-Length] Encoded mode
1874 int color
= colors
[*pIn
++];
1875 while (length
-- && x
< (left
+ dstwidth
)) {
1876 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1883 * Escape codes (may be an absolute sequence though)
1885 escape_code
= (*pIn
++);
1894 /* Not all RLE8 bitmaps end with this code. For
1895 * example, Paint Shop Pro produces some that don't.
1896 * That's (I think) what caused the previous
1897 * implementation to fail. [JAY]
1906 default: /* switch to absolute mode */
1907 length
= escape_code
;
1910 int color
= colors
[*pIn
++];
1911 if (x
>= (left
+ dstwidth
))
1916 if( x
>= left
) XPutPixel(bmpImage
, x
, y
, color
);
1920 * If you think for a moment you'll realise that the
1921 * only time we could ever possibly read an odd
1922 * number of bytes is when there is a 0x00 (escape),
1923 * a value >0x02 (absolute mode) and then an odd-
1924 * length run. Therefore this is the only place we
1925 * need to worry about it. Everywhere else the
1926 * bytes are always read in pairs. [JAY]
1928 if (escape_code
& 1) pIn
++; /* Throw away the pad byte. */
1930 } /* switch (escape_code) : Escape sequence */
1936 /***********************************************************************
1937 * X11DRV_DIB_SetImageBits_16
1939 * SetDIBits for a 16-bit deep DIB.
1941 static void X11DRV_DIB_SetImageBits_16( int lines
, const BYTE
*srcbits
,
1942 DWORD srcwidth
, DWORD dstwidth
, int left
,
1943 X11DRV_PDEVICE
*physDev
, DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
1944 XImage
*bmpImage
, DWORD linebytes
)
1947 int h
, width
= min(srcwidth
, dstwidth
);
1948 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
1953 srcbits
= srcbits
+ ( linebytes
* (lines
-1));
1954 linebytes
= -linebytes
;
1957 switch (bmpImage
->depth
)
1964 srcbits
=srcbits
+left
*2;
1965 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
1967 if (bmpImage
->green_mask
==0x03e0) {
1968 if (gSrc
==bmpImage
->green_mask
) {
1969 if (rSrc
==bmpImage
->red_mask
) {
1970 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1971 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1972 convs
->Convert_5x5_asis
1975 dstbits
,-bmpImage
->bytes_per_line
);
1976 } else if (rSrc
==bmpImage
->blue_mask
) {
1977 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1978 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1979 convs
->Convert_555_reverse
1982 dstbits
,-bmpImage
->bytes_per_line
);
1985 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
1986 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1987 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1988 convs
->Convert_565_to_555_asis
1991 dstbits
,-bmpImage
->bytes_per_line
);
1993 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1994 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1995 convs
->Convert_565_to_555_reverse
1998 dstbits
,-bmpImage
->bytes_per_line
);
2001 } else if (bmpImage
->green_mask
==0x07e0) {
2002 if (gSrc
==bmpImage
->green_mask
) {
2003 if (rSrc
==bmpImage
->red_mask
) {
2004 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
2005 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
2006 convs
->Convert_5x5_asis
2009 dstbits
,-bmpImage
->bytes_per_line
);
2011 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
2012 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
2013 convs
->Convert_565_reverse
2016 dstbits
,-bmpImage
->bytes_per_line
);
2019 if (rSrc
==bmpImage
->red_mask
|| bSrc
==bmpImage
->blue_mask
) {
2020 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
2021 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
2022 convs
->Convert_555_to_565_asis
2025 dstbits
,-bmpImage
->bytes_per_line
);
2027 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
2028 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
2029 convs
->Convert_555_to_565_reverse
2032 dstbits
,-bmpImage
->bytes_per_line
);
2042 if (bmpImage
->bits_per_pixel
==24) {
2045 srcbits
=srcbits
+left
*2;
2046 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2048 if (bmpImage
->green_mask
!=0x00ff00 ||
2049 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2051 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2052 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2054 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2055 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2056 convs
->Convert_555_to_888_asis
2059 dstbits
,-bmpImage
->bytes_per_line
);
2061 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2062 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2063 convs
->Convert_565_to_888_asis
2066 dstbits
,-bmpImage
->bytes_per_line
);
2070 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2071 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2072 convs
->Convert_555_to_888_reverse
2075 dstbits
,-bmpImage
->bytes_per_line
);
2077 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2078 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2079 convs
->Convert_565_to_888_reverse
2082 dstbits
,-bmpImage
->bytes_per_line
);
2093 srcbits
=srcbits
+left
*2;
2094 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2096 if (bmpImage
->green_mask
!=0x00ff00 ||
2097 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2099 } else if ((rSrc
==0x1f && bmpImage
->red_mask
==0xff) ||
2100 (bSrc
==0x1f && bmpImage
->blue_mask
==0xff)) {
2102 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2103 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2104 convs
->Convert_555_to_0888_asis
2107 dstbits
,-bmpImage
->bytes_per_line
);
2109 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2110 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2111 convs
->Convert_565_to_0888_asis
2114 dstbits
,-bmpImage
->bytes_per_line
);
2118 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2119 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2120 convs
->Convert_555_to_0888_reverse
2123 dstbits
,-bmpImage
->bytes_per_line
);
2125 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2126 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2127 convs
->Convert_565_to_0888_reverse
2130 dstbits
,-bmpImage
->bytes_per_line
);
2138 WARN("from 16 bit DIB (%lx,%lx,%lx) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2139 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2140 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2146 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2147 const WORD
* srcpixel
;
2148 int rShift1
,gShift1
,bShift1
;
2149 int rShift2
,gShift2
,bShift2
;
2152 /* Set color scaling values */
2153 rShift1
=16+X11DRV_DIB_MaskToShift(rSrc
)-3;
2154 gShift1
=16+X11DRV_DIB_MaskToShift(gSrc
)-3;
2155 bShift1
=16+X11DRV_DIB_MaskToShift(bSrc
)-3;
2160 /* Green has 5 bits, like the others */
2164 /* Green has 6 bits, not 5. Compensate. */
2173 /* We could split it into four separate cases to optimize
2174 * but it is probably not worth it.
2176 for (h
=lines
-1; h
>=0; h
--) {
2177 srcpixel
=(const WORD
*)srcbits
;
2178 for (x
=left
; x
<width
+left
; x
++) {
2180 BYTE red
,green
,blue
;
2181 srcval
=*srcpixel
++ << 16;
2182 red
= ((srcval
>> rShift1
) & 0xf8) |
2183 ((srcval
>> rShift2
) & 0x07);
2184 green
=((srcval
>> gShift1
) & gMask1
) |
2185 ((srcval
>> gShift2
) & gMask2
);
2186 blue
= ((srcval
>> bShift1
) & 0xf8) |
2187 ((srcval
>> bShift2
) & 0x07);
2188 XPutPixel(bmpImage
, x
, h
,
2189 X11DRV_PALETTE_ToPhysical
2190 (physDev
, RGB(red
,green
,blue
)));
2192 srcbits
+= linebytes
;
2200 /***********************************************************************
2201 * X11DRV_DIB_GetImageBits_16
2203 * GetDIBits for an 16-bit deep DIB.
2205 static void X11DRV_DIB_GetImageBits_16( int lines
, BYTE
*dstbits
,
2206 DWORD dstwidth
, DWORD srcwidth
,
2207 PALETTEENTRY
*srccolors
,
2208 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2209 XImage
*bmpImage
, DWORD dibpitch
)
2212 int h
, width
= min(srcwidth
, dstwidth
);
2213 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2215 DWORD linebytes
= dibpitch
;
2220 dstbits
= dstbits
+ ( linebytes
* (lines
-1));
2221 linebytes
= -linebytes
;
2224 switch (bmpImage
->depth
)
2229 const char* srcbits
;
2231 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2233 if (bmpImage
->green_mask
==0x03e0) {
2234 if (gDst
==bmpImage
->green_mask
) {
2235 if (rDst
==bmpImage
->red_mask
) {
2236 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2237 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2238 convs
->Convert_5x5_asis
2240 srcbits
,-bmpImage
->bytes_per_line
,
2243 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2244 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2245 convs
->Convert_555_reverse
2247 srcbits
,-bmpImage
->bytes_per_line
,
2251 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2252 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2253 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2254 convs
->Convert_555_to_565_asis
2256 srcbits
,-bmpImage
->bytes_per_line
,
2259 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2260 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2261 convs
->Convert_555_to_565_reverse
2263 srcbits
,-bmpImage
->bytes_per_line
,
2267 } else if (bmpImage
->green_mask
==0x07e0) {
2268 if (gDst
==bmpImage
->green_mask
) {
2269 if (rDst
== bmpImage
->red_mask
) {
2270 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2271 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2272 convs
->Convert_5x5_asis
2274 srcbits
,-bmpImage
->bytes_per_line
,
2277 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2278 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2279 convs
->Convert_565_reverse
2281 srcbits
,-bmpImage
->bytes_per_line
,
2285 if (rDst
==bmpImage
->red_mask
|| bDst
==bmpImage
->blue_mask
) {
2286 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2287 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2288 convs
->Convert_565_to_555_asis
2290 srcbits
,-bmpImage
->bytes_per_line
,
2293 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2294 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2295 convs
->Convert_565_to_555_reverse
2297 srcbits
,-bmpImage
->bytes_per_line
,
2308 if (bmpImage
->bits_per_pixel
== 24) {
2309 const char* srcbits
;
2311 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2313 if (bmpImage
->green_mask
!=0x00ff00 ||
2314 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2316 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2317 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2319 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2320 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2321 convs
->Convert_888_to_555_asis
2323 srcbits
,-bmpImage
->bytes_per_line
,
2326 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2327 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2328 convs
->Convert_888_to_565_asis
2330 srcbits
,-bmpImage
->bytes_per_line
,
2335 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2336 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2337 convs
->Convert_888_to_555_reverse
2339 srcbits
,-bmpImage
->bytes_per_line
,
2342 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2343 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2344 convs
->Convert_888_to_565_reverse
2346 srcbits
,-bmpImage
->bytes_per_line
,
2356 const char* srcbits
;
2358 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2360 if (bmpImage
->green_mask
!=0x00ff00 ||
2361 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2363 } else if ((rDst
==0x1f && bmpImage
->red_mask
==0xff) ||
2364 (bDst
==0x1f && bmpImage
->blue_mask
==0xff)) {
2366 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2367 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2368 convs
->Convert_0888_to_555_asis
2370 srcbits
,-bmpImage
->bytes_per_line
,
2373 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2374 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2375 convs
->Convert_0888_to_565_asis
2377 srcbits
,-bmpImage
->bytes_per_line
,
2382 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2383 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2384 convs
->Convert_0888_to_555_reverse
2386 srcbits
,-bmpImage
->bytes_per_line
,
2389 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2390 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2391 convs
->Convert_0888_to_565_reverse
2393 srcbits
,-bmpImage
->bytes_per_line
,
2402 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2404 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2405 int rShift
,gShift
,bShift
;
2408 /* Shift everything 16 bits left so that all shifts are >0,
2409 * even for BGR DIBs. Then a single >> 16 will bring everything
2412 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2413 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2414 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2416 /* 6 bits for the green */
2422 for (h
= lines
- 1; h
>= 0; h
--) {
2423 dstpixel
=(LPWORD
)dstbits
;
2424 for (x
= 0; x
< width
; x
++) {
2425 PALETTEENTRY srcval
;
2427 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2428 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2429 ((srcval
.peGreen
<< gShift
) & gDst
) |
2430 ((srcval
.peBlue
<< bShift
) & bDst
);
2431 *dstpixel
++=dstval
>> 16;
2433 dstbits
+= linebytes
;
2441 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2443 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2444 int rShift
,gShift
,bShift
;
2445 const BYTE
* srcbits
;
2446 const BYTE
* srcpixel
;
2449 /* Shift everything 16 bits left so that all shifts are >0,
2450 * even for BGR DIBs. Then a single >> 16 will bring everything
2453 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2454 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2455 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2457 /* 6 bits for the green */
2463 srcbits
=(BYTE
*)bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2464 for (h
=0; h
<lines
; h
++) {
2466 dstpixel
=(LPWORD
)dstbits
;
2467 for (x
= 0; x
< width
; x
++) {
2468 PALETTEENTRY srcval
;
2470 srcval
=srccolors
[(int)*srcpixel
++];
2471 dstval
=((srcval
.peRed
<< rShift
) & rDst
) |
2472 ((srcval
.peGreen
<< gShift
) & gDst
) |
2473 ((srcval
.peBlue
<< bShift
) & bDst
);
2474 *dstpixel
++=dstval
>> 16;
2476 srcbits
-= bmpImage
->bytes_per_line
;
2477 dstbits
+= linebytes
;
2487 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2488 int rShift
,gShift
,bShift
;
2491 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%lx,%lx,%lx)\n",
2492 bmpImage
->depth
, bmpImage
->red_mask
,
2493 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2496 /* Shift everything 16 bits left so that all shifts are >0,
2497 * even for BGR DIBs. Then a single >> 16 will bring everything
2500 rShift
=16+X11DRV_DIB_MaskToShift(rDst
)-3;
2501 gShift
=16+X11DRV_DIB_MaskToShift(gDst
)-3;
2502 bShift
=16+X11DRV_DIB_MaskToShift(bDst
)-3;
2504 /* 6 bits for the green */
2510 for (h
= lines
- 1; h
>= 0; h
--) {
2511 dstpixel
=(LPWORD
)dstbits
;
2512 for (x
= 0; x
< width
; x
++) {
2515 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
2516 dstval
=((GetRValue(srcval
) << rShift
) & rDst
) |
2517 ((GetGValue(srcval
) << gShift
) & gDst
) |
2518 ((GetBValue(srcval
) << bShift
) & bDst
);
2519 *dstpixel
++=dstval
>> 16;
2521 dstbits
+= linebytes
;
2529 /***********************************************************************
2530 * X11DRV_DIB_SetImageBits_24
2532 * SetDIBits for a 24-bit deep DIB.
2534 static void X11DRV_DIB_SetImageBits_24( int lines
, const BYTE
*srcbits
,
2535 DWORD srcwidth
, DWORD dstwidth
, int left
,
2536 X11DRV_PDEVICE
*physDev
,
2537 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2538 XImage
*bmpImage
, DWORD linebytes
)
2541 int h
, width
= min(srcwidth
, dstwidth
);
2542 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2547 srcbits
= srcbits
+ linebytes
* (lines
- 1);
2548 linebytes
= -linebytes
;
2551 switch (bmpImage
->depth
)
2554 if (bmpImage
->bits_per_pixel
==24) {
2557 srcbits
=srcbits
+left
*3;
2558 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2560 if (bmpImage
->green_mask
!=0x00ff00 ||
2561 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2563 } else if (rSrc
==bmpImage
->red_mask
) {
2564 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2565 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2566 convs
->Convert_888_asis
2569 dstbits
,-bmpImage
->bytes_per_line
);
2571 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2572 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2573 convs
->Convert_888_reverse
2576 dstbits
,-bmpImage
->bytes_per_line
);
2586 srcbits
=srcbits
+left
*3;
2587 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2589 if (bmpImage
->green_mask
!=0x00ff00 ||
2590 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2592 } else if (rSrc
==bmpImage
->red_mask
) {
2593 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2594 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2595 convs
->Convert_888_to_0888_asis
2598 dstbits
,-bmpImage
->bytes_per_line
);
2600 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2601 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2602 convs
->Convert_888_to_0888_reverse
2605 dstbits
,-bmpImage
->bytes_per_line
);
2615 srcbits
=srcbits
+left
*3;
2616 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
2618 if (bmpImage
->green_mask
==0x03e0) {
2619 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2620 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2621 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2622 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2623 convs
->Convert_888_to_555_asis
2626 dstbits
,-bmpImage
->bytes_per_line
);
2627 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0x7f00) ||
2628 (bSrc
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2629 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2630 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2631 convs
->Convert_888_to_555_reverse
2634 dstbits
,-bmpImage
->bytes_per_line
);
2638 } else if (bmpImage
->green_mask
==0x07e0) {
2639 if ((rSrc
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2640 (bSrc
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2641 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2642 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2643 convs
->Convert_888_to_565_asis
2646 dstbits
,-bmpImage
->bytes_per_line
);
2647 } else if ((rSrc
==0xff && bmpImage
->red_mask
==0xf800) ||
2648 (bSrc
==0xff && bmpImage
->blue_mask
==0xf800)) {
2649 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2650 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2651 convs
->Convert_888_to_565_reverse
2654 dstbits
,-bmpImage
->bytes_per_line
);
2666 WARN("from 24 bit DIB (%lx,%lx,%lx) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2667 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
2668 bmpImage
->green_mask
, bmpImage
->blue_mask
);
2674 /* ==== rgb 888 dib -> any bmp bormat ==== */
2675 const BYTE
* srcbyte
;
2677 /* Windows only supports one 24bpp DIB format: RGB888 */
2679 for (h
= lines
- 1; h
>= 0; h
--) {
2680 srcbyte
=(const BYTE
*)srcbits
;
2681 for (x
= left
; x
< width
+left
; x
++) {
2682 XPutPixel(bmpImage
, x
, h
,
2683 X11DRV_PALETTE_ToPhysical
2684 (physDev
, RGB(srcbyte
[2], srcbyte
[1], srcbyte
[0])));
2687 srcbits
+= linebytes
;
2695 /***********************************************************************
2696 * X11DRV_DIB_GetImageBits_24
2698 * GetDIBits for an 24-bit deep DIB.
2700 static void X11DRV_DIB_GetImageBits_24( int lines
, BYTE
*dstbits
,
2701 DWORD dstwidth
, DWORD srcwidth
,
2702 PALETTEENTRY
*srccolors
,
2703 DWORD rDst
, DWORD gDst
, DWORD bDst
,
2704 XImage
*bmpImage
, DWORD linebytes
)
2707 int h
, width
= min(srcwidth
, dstwidth
);
2708 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
2713 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
2714 linebytes
= -linebytes
;
2717 switch (bmpImage
->depth
)
2720 if (bmpImage
->bits_per_pixel
==24) {
2721 const char* srcbits
;
2723 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2725 if (bmpImage
->green_mask
!=0x00ff00 ||
2726 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2728 } else if (rDst
==bmpImage
->red_mask
) {
2729 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2730 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2731 convs
->Convert_888_asis
2733 srcbits
,-bmpImage
->bytes_per_line
,
2736 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2737 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2738 convs
->Convert_888_reverse
2740 srcbits
,-bmpImage
->bytes_per_line
,
2749 const char* srcbits
;
2751 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2753 if (bmpImage
->green_mask
!=0x00ff00 ||
2754 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2756 } else if (rDst
==bmpImage
->red_mask
) {
2757 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2758 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2759 convs
->Convert_0888_to_888_asis
2761 srcbits
,-bmpImage
->bytes_per_line
,
2764 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2765 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2766 convs
->Convert_0888_to_888_reverse
2768 srcbits
,-bmpImage
->bytes_per_line
,
2777 const char* srcbits
;
2779 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2781 if (bmpImage
->green_mask
==0x03e0) {
2782 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0x7f00) ||
2783 (bDst
==0xff0000 && bmpImage
->blue_mask
==0x7f00)) {
2784 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2785 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2786 convs
->Convert_555_to_888_asis
2788 srcbits
,-bmpImage
->bytes_per_line
,
2790 } else if ((rDst
==0xff && bmpImage
->red_mask
==0x7f00) ||
2791 (bDst
==0xff && bmpImage
->blue_mask
==0x7f00)) {
2792 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2793 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2794 convs
->Convert_555_to_888_reverse
2796 srcbits
,-bmpImage
->bytes_per_line
,
2801 } else if (bmpImage
->green_mask
==0x07e0) {
2802 if ((rDst
==0xff0000 && bmpImage
->red_mask
==0xf800) ||
2803 (bDst
==0xff0000 && bmpImage
->blue_mask
==0xf800)) {
2804 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2805 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2806 convs
->Convert_565_to_888_asis
2808 srcbits
,-bmpImage
->bytes_per_line
,
2810 } else if ((rDst
==0xff && bmpImage
->red_mask
==0xf800) ||
2811 (bDst
==0xff && bmpImage
->blue_mask
==0xf800)) {
2812 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2813 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2814 convs
->Convert_565_to_888_reverse
2816 srcbits
,-bmpImage
->bytes_per_line
,
2829 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2831 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2834 /* Windows only supports one 24bpp DIB format: rgb 888 */
2835 for (h
= lines
- 1; h
>= 0; h
--) {
2837 for (x
= 0; x
< width
; x
++) {
2838 PALETTEENTRY srcval
;
2839 srcval
=srccolors
[XGetPixel(bmpImage
, x
, h
)];
2840 dstbyte
[0]=srcval
.peBlue
;
2841 dstbyte
[1]=srcval
.peGreen
;
2842 dstbyte
[2]=srcval
.peRed
;
2845 dstbits
+= linebytes
;
2853 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
2855 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2856 const void* srcbits
;
2857 const BYTE
* srcpixel
;
2860 /* Windows only supports one 24bpp DIB format: rgb 888 */
2861 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
2862 for (h
= lines
- 1; h
>= 0; h
--) {
2865 for (x
= 0; x
< width
; x
++ ) {
2866 PALETTEENTRY srcval
;
2867 srcval
=srccolors
[(int)*srcpixel
++];
2868 dstbyte
[0]=srcval
.peBlue
;
2869 dstbyte
[1]=srcval
.peGreen
;
2870 dstbyte
[2]=srcval
.peRed
;
2873 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
2874 dstbits
+= linebytes
;
2884 /* ==== any bmp format -> 888 dib ==== */
2887 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%lx,%lx,%lx)\n",
2888 bmpImage
->depth
, bmpImage
->red_mask
,
2889 bmpImage
->green_mask
, bmpImage
->blue_mask
,
2892 /* Windows only supports one 24bpp DIB format: rgb 888 */
2893 for (h
= lines
- 1; h
>= 0; h
--) {
2895 for (x
= 0; x
< width
; x
++) {
2896 COLORREF srcval
=X11DRV_PALETTE_ToLogical
2897 (XGetPixel( bmpImage
, x
, h
));
2898 dstbyte
[0]=GetBValue(srcval
);
2899 dstbyte
[1]=GetGValue(srcval
);
2900 dstbyte
[2]=GetRValue(srcval
);
2903 dstbits
+= linebytes
;
2911 /***********************************************************************
2912 * X11DRV_DIB_SetImageBits_32
2914 * SetDIBits for a 32-bit deep DIB.
2916 static void X11DRV_DIB_SetImageBits_32(int lines
, const BYTE
*srcbits
,
2917 DWORD srcwidth
, DWORD dstwidth
, int left
,
2918 X11DRV_PDEVICE
*physDev
,
2919 DWORD rSrc
, DWORD gSrc
, DWORD bSrc
,
2925 int h
, width
= min(srcwidth
, dstwidth
);
2926 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_dst_byteswap
;
2931 srcbits
= srcbits
+ ( linebytes
* (lines
-1) );
2932 linebytes
= -linebytes
;
2935 ptr
= (const DWORD
*) srcbits
+ left
;
2937 switch (bmpImage
->depth
)
2940 if (bmpImage
->bits_per_pixel
==24) {
2943 srcbits
=srcbits
+left
*4;
2944 dstbits
=bmpImage
->data
+left
*3+(lines
-1)*bmpImage
->bytes_per_line
;
2946 if (rSrc
==bmpImage
->red_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->blue_mask
) {
2947 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2948 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2949 convs
->Convert_0888_to_888_asis
2952 dstbits
,-bmpImage
->bytes_per_line
);
2953 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2954 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
2956 /* the tests below assume sane bmpImage masks */
2957 } else if (rSrc
==bmpImage
->blue_mask
&& gSrc
==bmpImage
->green_mask
&& bSrc
==bmpImage
->red_mask
) {
2958 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2959 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2960 convs
->Convert_0888_to_888_reverse
2963 dstbits
,-bmpImage
->bytes_per_line
);
2964 } else if (bmpImage
->blue_mask
==0xff) {
2965 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2966 convs
->Convert_any0888_to_rgb888
2970 dstbits
,-bmpImage
->bytes_per_line
);
2972 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2973 convs
->Convert_any0888_to_bgr888
2977 dstbits
,-bmpImage
->bytes_per_line
);
2987 srcbits
=srcbits
+left
*4;
2988 dstbits
=bmpImage
->data
+left
*4+(lines
-1)*bmpImage
->bytes_per_line
;
2990 if (gSrc
==bmpImage
->green_mask
) {
2991 if (rSrc
==bmpImage
->red_mask
&& bSrc
==bmpImage
->blue_mask
) {
2992 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2993 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2994 convs
->Convert_0888_asis
2997 dstbits
,-bmpImage
->bytes_per_line
);
2998 } else if (bmpImage
->green_mask
!=0x00ff00 ||
2999 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3001 /* the tests below assume sane bmpImage masks */
3002 } else if (rSrc
==bmpImage
->blue_mask
&& bSrc
==bmpImage
->red_mask
) {
3003 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
3004 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
3005 convs
->Convert_0888_reverse
3008 dstbits
,-bmpImage
->bytes_per_line
);
3010 /* ==== any 0888 dib -> any 0888 bmp ==== */
3011 convs
->Convert_0888_any
3015 dstbits
,-bmpImage
->bytes_per_line
,
3016 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3018 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3019 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3021 /* the tests below assume sane bmpImage masks */
3023 /* ==== any 0888 dib -> any 0888 bmp ==== */
3024 convs
->Convert_0888_any
3028 dstbits
,-bmpImage
->bytes_per_line
,
3029 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3039 srcbits
=srcbits
+left
*4;
3040 dstbits
=bmpImage
->data
+left
*2+(lines
-1)*bmpImage
->bytes_per_line
;
3042 if (rSrc
==0xff0000 && gSrc
==0x00ff00 && bSrc
==0x0000ff) {
3043 if (bmpImage
->green_mask
==0x03e0) {
3044 if (bmpImage
->red_mask
==0x7f00) {
3045 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
3046 convs
->Convert_0888_to_555_asis
3049 dstbits
,-bmpImage
->bytes_per_line
);
3050 } else if (bmpImage
->blue_mask
==0x7f00) {
3051 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
3052 convs
->Convert_0888_to_555_reverse
3055 dstbits
,-bmpImage
->bytes_per_line
);
3059 } else if (bmpImage
->green_mask
==0x07e0) {
3060 if (bmpImage
->red_mask
==0xf800) {
3061 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3062 convs
->Convert_0888_to_565_asis
3065 dstbits
,-bmpImage
->bytes_per_line
);
3066 } else if (bmpImage
->blue_mask
==0xf800) {
3067 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3068 convs
->Convert_0888_to_565_reverse
3071 dstbits
,-bmpImage
->bytes_per_line
);
3078 } else if (rSrc
==0x0000ff && gSrc
==0x00ff00 && bSrc
==0xff0000) {
3079 if (bmpImage
->green_mask
==0x03e0) {
3080 if (bmpImage
->blue_mask
==0x7f00) {
3081 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3082 convs
->Convert_0888_to_555_asis
3085 dstbits
,-bmpImage
->bytes_per_line
);
3086 } else if (bmpImage
->red_mask
==0x7f00) {
3087 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3088 convs
->Convert_0888_to_555_reverse
3091 dstbits
,-bmpImage
->bytes_per_line
);
3095 } else if (bmpImage
->green_mask
==0x07e0) {
3096 if (bmpImage
->blue_mask
==0xf800) {
3097 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3098 convs
->Convert_0888_to_565_asis
3101 dstbits
,-bmpImage
->bytes_per_line
);
3102 } else if (bmpImage
->red_mask
==0xf800) {
3103 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3104 convs
->Convert_0888_to_565_reverse
3107 dstbits
,-bmpImage
->bytes_per_line
);
3115 if (bmpImage
->green_mask
==0x03e0 &&
3116 (bmpImage
->red_mask
==0x7f00 ||
3117 bmpImage
->blue_mask
==0x7f00)) {
3118 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3119 convs
->Convert_any0888_to_5x5
3123 dstbits
,-bmpImage
->bytes_per_line
,
3124 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3125 } else if (bmpImage
->green_mask
==0x07e0 &&
3126 (bmpImage
->red_mask
==0xf800 ||
3127 bmpImage
->blue_mask
==0xf800)) {
3128 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3129 convs
->Convert_any0888_to_5x5
3133 dstbits
,-bmpImage
->bytes_per_line
,
3134 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3144 WARN("from 32 bit DIB (%lx,%lx,%lx) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3145 rSrc
, gSrc
, bSrc
, bmpImage
->bits_per_pixel
, bmpImage
->red_mask
,
3146 bmpImage
->green_mask
, bmpImage
->blue_mask
);
3152 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3153 const DWORD
* srcpixel
;
3154 int rShift
,gShift
,bShift
;
3156 rShift
=X11DRV_DIB_MaskToShift(rSrc
);
3157 gShift
=X11DRV_DIB_MaskToShift(gSrc
);
3158 bShift
=X11DRV_DIB_MaskToShift(bSrc
);
3160 for (h
= lines
- 1; h
>= 0; h
--) {
3161 srcpixel
=(const DWORD
*)srcbits
;
3162 for (x
= left
; x
< width
+left
; x
++) {
3164 BYTE red
,green
,blue
;
3165 srcvalue
=*srcpixel
++;
3166 red
= (srcvalue
>> rShift
) & 0xff;
3167 green
=(srcvalue
>> gShift
) & 0xff;
3168 blue
= (srcvalue
>> bShift
) & 0xff;
3169 XPutPixel(bmpImage
, x
, h
, X11DRV_PALETTE_ToPhysical
3170 (physDev
, RGB(red
,green
,blue
)));
3172 srcbits
+= linebytes
;
3180 /***********************************************************************
3181 * X11DRV_DIB_GetImageBits_32
3183 * GetDIBits for an 32-bit deep DIB.
3185 static void X11DRV_DIB_GetImageBits_32( int lines
, BYTE
*dstbits
,
3186 DWORD dstwidth
, DWORD srcwidth
,
3187 PALETTEENTRY
*srccolors
,
3188 DWORD rDst
, DWORD gDst
, DWORD bDst
,
3189 XImage
*bmpImage
, DWORD linebytes
)
3192 int h
, width
= min(srcwidth
, dstwidth
);
3194 const dib_conversions
*convs
= (bmpImage
->byte_order
== LSBFirst
) ? &dib_normal
: &dib_src_byteswap
;
3199 dstbits
= dstbits
+ ( linebytes
* (lines
-1) );
3200 linebytes
= -linebytes
;
3205 switch (bmpImage
->depth
)
3208 if (bmpImage
->bits_per_pixel
==24) {
3209 const void* srcbits
;
3211 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3213 if (rDst
==bmpImage
->red_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->blue_mask
) {
3214 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3215 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3216 convs
->Convert_888_to_0888_asis
3218 srcbits
,-bmpImage
->bytes_per_line
,
3220 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3221 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3223 /* the tests below assume sane bmpImage masks */
3224 } else if (rDst
==bmpImage
->blue_mask
&& gDst
==bmpImage
->green_mask
&& bDst
==bmpImage
->red_mask
) {
3225 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3226 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3227 convs
->Convert_888_to_0888_reverse
3229 srcbits
,-bmpImage
->bytes_per_line
,
3231 } else if (bmpImage
->blue_mask
==0xff) {
3232 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3233 convs
->Convert_rgb888_to_any0888
3235 srcbits
,-bmpImage
->bytes_per_line
,
3239 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3240 convs
->Convert_bgr888_to_any0888
3242 srcbits
,-bmpImage
->bytes_per_line
,
3252 const char* srcbits
;
3254 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3256 if (gDst
==bmpImage
->green_mask
) {
3257 if (rDst
==bmpImage
->red_mask
&& bDst
==bmpImage
->blue_mask
) {
3258 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3259 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3260 convs
->Convert_0888_asis
3262 srcbits
,-bmpImage
->bytes_per_line
,
3264 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3265 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3267 /* the tests below assume sane bmpImage masks */
3268 } else if (rDst
==bmpImage
->blue_mask
&& bDst
==bmpImage
->red_mask
) {
3269 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3270 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3271 convs
->Convert_0888_reverse
3273 srcbits
,-bmpImage
->bytes_per_line
,
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
,
3284 } else if (bmpImage
->green_mask
!=0x00ff00 ||
3285 (bmpImage
->red_mask
|bmpImage
->blue_mask
)!=0xff00ff) {
3287 /* the tests below assume sane bmpImage masks */
3289 /* ==== any 0888 bmp -> any 0888 dib ==== */
3290 convs
->Convert_0888_any
3292 srcbits
,-bmpImage
->bytes_per_line
,
3293 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3303 const char* srcbits
;
3305 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3307 if (rDst
==0xff0000 && gDst
==0x00ff00 && bDst
==0x0000ff) {
3308 if (bmpImage
->green_mask
==0x03e0) {
3309 if (bmpImage
->red_mask
==0x7f00) {
3310 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3311 convs
->Convert_555_to_0888_asis
3313 srcbits
,-bmpImage
->bytes_per_line
,
3315 } else if (bmpImage
->blue_mask
==0x7f00) {
3316 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3317 convs
->Convert_555_to_0888_reverse
3319 srcbits
,-bmpImage
->bytes_per_line
,
3324 } else if (bmpImage
->green_mask
==0x07e0) {
3325 if (bmpImage
->red_mask
==0xf800) {
3326 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3327 convs
->Convert_565_to_0888_asis
3329 srcbits
,-bmpImage
->bytes_per_line
,
3331 } else if (bmpImage
->blue_mask
==0xf800) {
3332 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3333 convs
->Convert_565_to_0888_reverse
3335 srcbits
,-bmpImage
->bytes_per_line
,
3343 } else if (rDst
==0x0000ff && gDst
==0x00ff00 && bDst
==0xff0000) {
3344 if (bmpImage
->green_mask
==0x03e0) {
3345 if (bmpImage
->blue_mask
==0x7f00) {
3346 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3347 convs
->Convert_555_to_0888_asis
3349 srcbits
,-bmpImage
->bytes_per_line
,
3351 } else if (bmpImage
->red_mask
==0x7f00) {
3352 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3353 convs
->Convert_555_to_0888_reverse
3355 srcbits
,-bmpImage
->bytes_per_line
,
3360 } else if (bmpImage
->green_mask
==0x07e0) {
3361 if (bmpImage
->blue_mask
==0xf800) {
3362 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3363 convs
->Convert_565_to_0888_asis
3365 srcbits
,-bmpImage
->bytes_per_line
,
3367 } else if (bmpImage
->red_mask
==0xf800) {
3368 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3369 convs
->Convert_565_to_0888_reverse
3371 srcbits
,-bmpImage
->bytes_per_line
,
3380 if (bmpImage
->green_mask
==0x03e0 &&
3381 (bmpImage
->red_mask
==0x7f00 ||
3382 bmpImage
->blue_mask
==0x7f00)) {
3383 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3384 convs
->Convert_5x5_to_any0888
3386 srcbits
,-bmpImage
->bytes_per_line
,
3387 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3390 } else if (bmpImage
->green_mask
==0x07e0 &&
3391 (bmpImage
->red_mask
==0xf800 ||
3392 bmpImage
->blue_mask
==0xf800)) {
3393 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3394 convs
->Convert_5x5_to_any0888
3396 srcbits
,-bmpImage
->bytes_per_line
,
3397 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
,
3409 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3411 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3412 int rShift
,gShift
,bShift
;
3415 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3416 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3417 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3418 for (h
= lines
- 1; h
>= 0; h
--) {
3419 dstpixel
=(DWORD
*)dstbits
;
3420 for (x
= 0; x
< width
; x
++) {
3421 PALETTEENTRY srcval
;
3422 srcval
= srccolors
[XGetPixel(bmpImage
, x
, h
)];
3423 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3424 (srcval
.peGreen
<< gShift
) |
3425 (srcval
.peBlue
<< bShift
);
3427 dstbits
+= linebytes
;
3435 if (X11DRV_DIB_CheckMask(bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
)
3437 /* ==== pal 8 bmp -> any 0888 dib ==== */
3438 int rShift
,gShift
,bShift
;
3439 const void* srcbits
;
3440 const BYTE
* srcpixel
;
3443 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3444 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3445 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3446 srcbits
=bmpImage
->data
+(lines
-1)*bmpImage
->bytes_per_line
;
3447 for (h
= lines
- 1; h
>= 0; h
--) {
3449 dstpixel
=(DWORD
*)dstbits
;
3450 for (x
= 0; x
< width
; x
++) {
3451 PALETTEENTRY srcval
;
3452 srcval
=srccolors
[(int)*srcpixel
++];
3453 *dstpixel
++=(srcval
.peRed
<< rShift
) |
3454 (srcval
.peGreen
<< gShift
) |
3455 (srcval
.peBlue
<< bShift
);
3457 srcbits
= (const char*)srcbits
- bmpImage
->bytes_per_line
;
3458 dstbits
+= linebytes
;
3468 /* ==== any bmp format -> any 0888 dib ==== */
3469 int rShift
,gShift
,bShift
;
3472 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%lx,%lx,%lx)\n",
3473 bmpImage
->depth
, bmpImage
->red_mask
,
3474 bmpImage
->green_mask
, bmpImage
->blue_mask
,
3477 rShift
=X11DRV_DIB_MaskToShift(rDst
);
3478 gShift
=X11DRV_DIB_MaskToShift(gDst
);
3479 bShift
=X11DRV_DIB_MaskToShift(bDst
);
3480 for (h
= lines
- 1; h
>= 0; h
--) {
3481 dstpixel
=(DWORD
*)dstbits
;
3482 for (x
= 0; x
< width
; x
++) {
3484 srcval
=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage
, x
, h
));
3485 *dstpixel
++=(GetRValue(srcval
) << rShift
) |
3486 (GetGValue(srcval
) << gShift
) |
3487 (GetBValue(srcval
) << bShift
);
3489 dstbits
+= linebytes
;
3496 static int XGetSubImageErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
3498 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
3501 /***********************************************************************
3502 * X11DRV_DIB_SetImageBits_GetSubImage
3504 * Helper for X11DRV_DIB_SetImageBits
3506 static void X11DRV_DIB_SetImageBits_GetSubImage(
3507 const X11DRV_DIB_IMAGEBITS_DESCR
*descr
, XImage
*bmpImage
)
3509 /* compressed bitmaps may contain gaps in them. So make a copy
3510 * of the existing pixels first */
3513 SetRect( &bmprc
, descr
->xDest
, descr
->yDest
,
3514 descr
->xDest
+ descr
->width
, descr
->yDest
+ descr
->height
);
3515 GetRgnBox( descr
->physDev
->region
, &rc
);
3516 /* convert from dc to drawable origin */
3517 OffsetRect( &rc
, descr
->physDev
->org
.x
, descr
->physDev
->org
.y
);
3518 /* clip visible rect with bitmap */
3519 if( IntersectRect( &rc
, &rc
, &bmprc
))
3521 X11DRV_expect_error( gdi_display
, XGetSubImageErrorHandler
, NULL
);
3522 XGetSubImage( gdi_display
, descr
->drawable
, rc
.left
, rc
.top
,
3523 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, AllPlanes
,
3525 descr
->xSrc
+ rc
.left
- bmprc
.left
,
3526 descr
->ySrc
+ rc
.top
- bmprc
.top
);
3527 X11DRV_check_error();
3531 /***********************************************************************
3532 * X11DRV_DIB_SetImageBits
3534 * Transfer the bits to an X image.
3535 * Helper function for SetDIBits() and SetDIBitsToDevice().
3537 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3539 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3544 bmpImage
= descr
->image
;
3546 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3547 descr
->infoWidth
, lines
, 32, 0 );
3548 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3549 if(bmpImage
->data
== NULL
) {
3550 ERR("Out of memory!\n");
3551 XDestroyImage( bmpImage
);
3552 wine_tsx11_unlock();
3557 TRACE("Dib: depth=%d r=%lx g=%lx b=%lx\n",
3558 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3559 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3560 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3561 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3563 /* Transfer the pixels */
3564 switch(descr
->infoBpp
)
3567 X11DRV_DIB_SetImageBits_1( descr
->lines
, descr
->bits
, descr
->infoWidth
,
3568 descr
->width
, descr
->xSrc
, (int *)(descr
->colorMap
),
3569 bmpImage
, descr
->dibpitch
);
3572 if (descr
->compression
) {
3573 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3574 X11DRV_DIB_SetImageBits_RLE4( descr
->lines
, descr
->bits
,
3575 descr
->infoWidth
, descr
->width
,
3576 descr
->xSrc
, (int *)(descr
->colorMap
),
3579 X11DRV_DIB_SetImageBits_4( descr
->lines
, descr
->bits
,
3580 descr
->infoWidth
, descr
->width
,
3581 descr
->xSrc
, (int*)(descr
->colorMap
),
3582 bmpImage
, descr
->dibpitch
);
3585 if (descr
->compression
) {
3586 X11DRV_DIB_SetImageBits_GetSubImage( descr
, bmpImage
);
3587 X11DRV_DIB_SetImageBits_RLE8( descr
->lines
, descr
->bits
,
3588 descr
->infoWidth
, descr
->width
,
3589 descr
->xSrc
, (int *)(descr
->colorMap
),
3592 X11DRV_DIB_SetImageBits_8( descr
->lines
, descr
->bits
,
3593 descr
->infoWidth
, descr
->width
,
3594 descr
->xSrc
, (int *)(descr
->colorMap
),
3595 bmpImage
, descr
->dibpitch
);
3599 X11DRV_DIB_SetImageBits_16( descr
->lines
, descr
->bits
,
3600 descr
->infoWidth
, descr
->width
,
3601 descr
->xSrc
, descr
->physDev
,
3602 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3603 bmpImage
, descr
->dibpitch
);
3606 X11DRV_DIB_SetImageBits_24( descr
->lines
, descr
->bits
,
3607 descr
->infoWidth
, descr
->width
,
3608 descr
->xSrc
, descr
->physDev
,
3609 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3610 bmpImage
, descr
->dibpitch
);
3613 X11DRV_DIB_SetImageBits_32( descr
->lines
, descr
->bits
,
3614 descr
->infoWidth
, descr
->width
,
3615 descr
->xSrc
, descr
->physDev
,
3616 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3617 bmpImage
, descr
->dibpitch
);
3620 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3624 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3625 descr
->drawable
, descr
->gc
, bmpImage
,
3626 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3627 descr
->width
, descr
->height
);
3628 #ifdef HAVE_LIBXXSHM
3631 XShmPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3632 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3633 descr
->width
, descr
->height
, FALSE
);
3634 XSync( gdi_display
, 0 );
3638 XPutImage( gdi_display
, descr
->drawable
, descr
->gc
, bmpImage
,
3639 descr
->xSrc
, descr
->ySrc
, descr
->xDest
, descr
->yDest
,
3640 descr
->width
, descr
->height
);
3642 if (!descr
->image
) XDestroyImage( bmpImage
);
3643 wine_tsx11_unlock();
3647 /***********************************************************************
3648 * X11DRV_DIB_GetImageBits
3650 * Transfer the bits from an X image.
3652 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR
*descr
)
3654 int lines
= descr
->lines
>= 0 ? descr
->lines
: -descr
->lines
;
3659 bmpImage
= descr
->image
;
3661 bmpImage
= XCreateImage( gdi_display
, visual
, descr
->depth
, ZPixmap
, 0, NULL
,
3662 descr
->infoWidth
, lines
, 32, 0 );
3663 bmpImage
->data
= calloc( lines
, bmpImage
->bytes_per_line
);
3664 if(bmpImage
->data
== NULL
) {
3665 ERR("Out of memory!\n");
3666 XDestroyImage( bmpImage
);
3667 wine_tsx11_unlock();
3672 #ifdef HAVE_LIBXXSHM
3675 int saveRed
, saveGreen
, saveBlue
;
3677 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3678 gdi_display
, descr
->drawable
, bmpImage
,
3679 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3681 /* We must save and restore the bmpImage's masks in order
3682 * to preserve them across the call to XShmGetImage, which
3683 * decides to eleminate them since it doesn't happen to know
3684 * what the format of the image is supposed to be, even though
3686 saveRed
= bmpImage
->red_mask
;
3687 saveBlue
= bmpImage
->blue_mask
;
3688 saveGreen
= bmpImage
->green_mask
;
3690 XShmGetImage( gdi_display
, descr
->drawable
, bmpImage
,
3691 descr
->xSrc
, descr
->ySrc
, AllPlanes
);
3693 bmpImage
->red_mask
= saveRed
;
3694 bmpImage
->blue_mask
= saveBlue
;
3695 bmpImage
->green_mask
= saveGreen
;
3698 #endif /* HAVE_LIBXXSHM */
3700 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3701 gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
, descr
->width
,
3702 lines
, AllPlanes
, ZPixmap
, bmpImage
, descr
->xDest
, descr
->yDest
);
3703 XGetSubImage( gdi_display
, descr
->drawable
, descr
->xSrc
, descr
->ySrc
,
3704 descr
->width
, lines
, AllPlanes
, ZPixmap
,
3705 bmpImage
, descr
->xDest
, descr
->yDest
);
3708 TRACE("Dib: depth=%2d r=%lx g=%lx b=%lx\n",
3709 descr
->infoBpp
,descr
->rMask
,descr
->gMask
,descr
->bMask
);
3710 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3711 bmpImage
->depth
,bmpImage
->bits_per_pixel
,
3712 bmpImage
->red_mask
,bmpImage
->green_mask
,bmpImage
->blue_mask
);
3713 /* Transfer the pixels */
3714 switch(descr
->infoBpp
)
3717 X11DRV_DIB_GetImageBits_1( descr
->lines
,(LPVOID
)descr
->bits
,
3718 descr
->infoWidth
, descr
->width
,
3719 descr
->colorMap
, descr
->palentry
,
3720 bmpImage
, descr
->dibpitch
);
3724 if (descr
->compression
) {
3725 FIXME("Compression not yet supported!\n");
3726 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 4 ) * abs(descr
->lines
))
3729 X11DRV_DIB_GetImageBits_4( descr
->lines
,(LPVOID
)descr
->bits
,
3730 descr
->infoWidth
, descr
->width
,
3731 descr
->colorMap
, descr
->palentry
,
3732 bmpImage
, descr
->dibpitch
);
3735 if (descr
->compression
) {
3736 FIXME("Compression not yet supported!\n");
3737 if(descr
->sizeImage
< X11DRV_DIB_GetDIBWidthBytes( descr
->infoWidth
, 8 ) * abs(descr
->lines
))
3740 X11DRV_DIB_GetImageBits_8( descr
->lines
, (LPVOID
)descr
->bits
,
3741 descr
->infoWidth
, descr
->width
,
3742 descr
->colorMap
, descr
->palentry
,
3743 bmpImage
, descr
->dibpitch
);
3747 X11DRV_DIB_GetImageBits_16( descr
->lines
, (LPVOID
)descr
->bits
,
3748 descr
->infoWidth
,descr
->width
,
3750 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3751 bmpImage
, descr
->dibpitch
);
3755 X11DRV_DIB_GetImageBits_24( descr
->lines
, (LPVOID
)descr
->bits
,
3756 descr
->infoWidth
,descr
->width
,
3758 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3759 bmpImage
, descr
->dibpitch
);
3763 X11DRV_DIB_GetImageBits_32( descr
->lines
, (LPVOID
)descr
->bits
,
3764 descr
->infoWidth
, descr
->width
,
3766 descr
->rMask
, descr
->gMask
, descr
->bMask
,
3767 bmpImage
, descr
->dibpitch
);
3771 WARN("(%d): Invalid depth\n", descr
->infoBpp
);
3775 if (!descr
->image
) XDestroyImage( bmpImage
);
3776 wine_tsx11_unlock();
3780 /*************************************************************************
3781 * X11DRV_SetDIBitsToDevice
3784 INT
X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE
*physDev
, INT xDest
, INT yDest
, DWORD cx
,
3785 DWORD cy
, INT xSrc
, INT ySrc
,
3786 UINT startscan
, UINT lines
, LPCVOID bits
,
3787 const BITMAPINFO
*info
, UINT coloruse
)
3789 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3795 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3796 &descr
.infoBpp
, &descr
.compression
) == -1)
3799 top_down
= (height
< 0);
3800 if (top_down
) height
= -height
;
3804 LPtoDP(physDev
->hdc
, &pt
, 1);
3806 if (!lines
|| (startscan
>= height
)) return 0;
3807 if (!top_down
&& startscan
+ lines
> height
) lines
= height
- startscan
;
3809 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3810 * and clamp all values to fit inside [startscan,startscan+lines]
3812 if (ySrc
+ cy
<= startscan
+ lines
)
3814 UINT y
= startscan
+ lines
- (ySrc
+ cy
);
3815 if (ySrc
< startscan
) cy
-= (startscan
- ySrc
);
3818 /* avoid getting unnecessary lines */
3820 if (y
>= lines
) return 0;
3825 if (y
>= lines
) return lines
;
3826 ySrc
= y
; /* need to get all lines in top down mode */
3831 if (ySrc
>= startscan
+ lines
) return lines
;
3832 pt
.y
+= ySrc
+ cy
- (startscan
+ lines
);
3833 cy
= startscan
+ lines
- ySrc
;
3835 if (cy
> lines
) cy
= lines
;
3837 if (xSrc
>= width
) return lines
;
3838 if (xSrc
+ cx
>= width
) cx
= width
- xSrc
;
3839 if (!cx
|| !cy
) return lines
;
3841 /* Update the pixmap from the DIB section */
3842 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
, FALSE
);
3844 X11DRV_SetupGCForText( physDev
); /* To have the correct colors */
3846 XSetFunction(gdi_display
, physDev
->gc
, X11DRV_XROPfunction
[GetROP2(physDev
->hdc
) - 1]);
3847 wine_tsx11_unlock();
3849 switch (descr
.infoBpp
)
3854 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3855 coloruse
== DIB_PAL_COLORS
? physDev
: NULL
, coloruse
,
3856 physDev
->depth
, info
, &descr
.nColorMap
);
3857 if (!descr
.colorMap
) return 0;
3858 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3862 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3863 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3864 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3870 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3871 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3872 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3877 descr
.physDev
= physDev
;
3880 descr
.palentry
= NULL
;
3881 descr
.lines
= top_down
? -lines
: lines
;
3882 descr
.infoWidth
= width
;
3883 descr
.depth
= physDev
->depth
;
3884 descr
.drawable
= physDev
->drawable
;
3885 descr
.gc
= physDev
->gc
;
3888 descr
.xDest
= physDev
->org
.x
+ pt
.x
;
3889 descr
.yDest
= physDev
->org
.y
+ pt
.y
;
3892 descr
.useShm
= FALSE
;
3893 descr
.dibpitch
= ((width
* descr
.infoBpp
+ 31) &~31) / 8;
3895 result
= X11DRV_DIB_SetImageBits( &descr
);
3897 if (descr
.infoBpp
<= 8)
3898 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3900 /* Update the DIBSection of the pixmap */
3901 X11DRV_UnlockDIBSection(physDev
, TRUE
);
3906 /***********************************************************************
3907 * SetDIBits (X11DRV.@)
3909 INT
X11DRV_SetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
,
3910 UINT lines
, LPCVOID bits
, const BITMAPINFO
*info
, UINT coloruse
)
3912 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3913 X11DRV_DIB_IMAGEBITS_DESCR descr
;
3915 LONG width
, height
, tmpheight
;
3918 descr
.physDev
= physDev
;
3920 if (!physBitmap
) return 0;
3922 if (DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
3923 &descr
.infoBpp
, &descr
.compression
) == -1)
3927 if (height
< 0) height
= -height
;
3928 if (!lines
|| (startscan
>= height
))
3931 if (!GetObjectW( hbitmap
, sizeof(bitmap
), &bitmap
)) return 0;
3933 if (startscan
+ lines
> height
) lines
= height
- startscan
;
3935 switch (descr
.infoBpp
)
3940 descr
.colorMap
= (RGBQUAD
*)X11DRV_DIB_BuildColorMap(
3941 coloruse
== DIB_PAL_COLORS
? descr
.physDev
: NULL
, coloruse
,
3942 physBitmap
->pixmap_depth
,
3943 info
, &descr
.nColorMap
);
3944 if (!descr
.colorMap
) return 0;
3945 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
3949 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
3950 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
3951 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
3957 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
3958 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
3959 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
3968 descr
.palentry
= NULL
;
3969 descr
.infoWidth
= width
;
3970 descr
.lines
= tmpheight
>= 0 ? lines
: -lines
;
3971 descr
.depth
= physBitmap
->pixmap_depth
;
3972 descr
.drawable
= physBitmap
->pixmap
;
3973 descr
.gc
= BITMAP_GC(physBitmap
);
3977 descr
.yDest
= height
- startscan
- lines
;
3978 descr
.width
= bitmap
.bmWidth
;
3979 descr
.height
= lines
;
3980 descr
.useShm
= FALSE
;
3981 descr
.dibpitch
= ((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8;
3982 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
, FALSE
);
3983 result
= X11DRV_DIB_SetImageBits( &descr
);
3984 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
3986 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
3991 /***********************************************************************
3992 * GetDIBits (X11DRV.@)
3994 INT
X11DRV_GetDIBits( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
, UINT startscan
, UINT lines
,
3995 LPVOID bits
, BITMAPINFO
*info
, UINT coloruse
)
3997 X_PHYSBITMAP
*physBitmap
= X11DRV_get_phys_bitmap( hbitmap
);
3999 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4000 PALETTEENTRY palette
[256];
4003 LONG width
, tempHeight
;
4008 GetPaletteEntries( GetCurrentObject( physDev
->hdc
, OBJ_PAL
), 0, 256, palette
);
4010 if (!physBitmap
) return 0;
4011 if (!(obj_size
= GetObjectW( hbitmap
, sizeof(dib
), &dib
))) return 0;
4013 bitmap_type
= DIB_GetBitmapInfo( (BITMAPINFOHEADER
*)info
, &width
, &tempHeight
, &descr
.infoBpp
, &descr
.compression
);
4014 descr
.lines
= tempHeight
;
4015 if (bitmap_type
== -1)
4017 ERR("Invalid bitmap\n");
4020 core_header
= (bitmap_type
== 0);
4021 colorPtr
= (LPBYTE
) info
+ (WORD
) info
->bmiHeader
.biSize
;
4023 TRACE("%u scanlines of (%i,%i) -> (%li,%i) starting from %u\n",
4024 lines
, dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
, width
, descr
.lines
, startscan
);
4026 if( lines
> dib
.dsBm
.bmHeight
) lines
= dib
.dsBm
.bmHeight
;
4028 height
= descr
.lines
;
4029 if (height
< 0) height
= -height
;
4030 if( lines
> height
) lines
= height
;
4031 /* Top-down images have a negative biHeight, the scanlines of theses images
4032 * were inverted in X11DRV_DIB_GetImageBits_xx
4033 * To prevent this we simply change the sign of lines
4034 * (the number of scan lines to copy).
4035 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
4037 if( descr
.lines
< 0 && lines
> 0) lines
= -lines
;
4039 if( startscan
>= dib
.dsBm
.bmHeight
) return 0;
4041 descr
.colorMap
= NULL
;
4043 switch (descr
.infoBpp
)
4048 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4049 if(coloruse
== DIB_RGB_COLORS
)
4050 descr
.colorMap
= colorPtr
;
4052 int num_colors
= 1 << descr
.infoBpp
, i
;
4055 WORD
*index
= (WORD
*)colorPtr
;
4056 descr
.colorMap
= rgb
= HeapAlloc(GetProcessHeap(), 0, num_colors
* sizeof(RGBQUAD
));
4057 for(i
= 0; i
< num_colors
; i
++, rgb
++, index
++) {
4058 colref
= X11DRV_PALETTE_ToLogical(X11DRV_PALETTE_ToPhysical(physDev
, PALETTEINDEX(*index
)));
4059 rgb
->rgbRed
= GetRValue(colref
);
4060 rgb
->rgbGreen
= GetGValue(colref
);
4061 rgb
->rgbBlue
= GetBValue(colref
);
4062 rgb
->rgbReserved
= 0;
4068 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0x7c00;
4069 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x03e0;
4070 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x001f;
4074 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? *(const DWORD
*)info
->bmiColors
: 0xff0000;
4075 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 1) : 0x00ff00;
4076 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? *((const DWORD
*)info
->bmiColors
+ 2) : 0x0000ff;
4080 descr
.physDev
= physDev
;
4081 descr
.palentry
= palette
;
4084 descr
.infoWidth
= width
;
4085 descr
.lines
= lines
;
4086 descr
.depth
= physBitmap
->pixmap_depth
;
4087 descr
.drawable
= physBitmap
->pixmap
;
4088 descr
.gc
= BITMAP_GC(physBitmap
);
4089 descr
.width
= dib
.dsBm
.bmWidth
;
4090 descr
.height
= dib
.dsBm
.bmHeight
;
4094 descr
.sizeImage
= core_header
? 0 : info
->bmiHeader
.biSizeImage
;
4096 if (descr
.lines
> 0)
4098 descr
.ySrc
= (descr
.height
-1) - (startscan
+ (lines
-1));
4102 descr
.ySrc
= startscan
;
4104 #ifdef HAVE_LIBXXSHM
4105 descr
.useShm
= (obj_size
== sizeof(DIBSECTION
)) && (physBitmap
->shminfo
.shmid
!= -1);
4107 descr
.useShm
= FALSE
;
4109 descr
.dibpitch
= (obj_size
== sizeof(DIBSECTION
)) ? dib
.dsBm
.bmWidthBytes
4110 : (((descr
.infoWidth
* descr
.infoBpp
+ 31) &~31) / 8);
4112 X11DRV_DIB_Lock( physBitmap
, DIB_Status_GdiMod
, FALSE
);
4113 X11DRV_DIB_GetImageBits( &descr
);
4114 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4116 if(!core_header
&& info
->bmiHeader
.biSizeImage
== 0) /* Fill in biSizeImage */
4117 info
->bmiHeader
.biSizeImage
= X11DRV_DIB_GetDIBImageBytes( descr
.infoWidth
,
4121 if (descr
.compression
== BI_BITFIELDS
)
4123 *(DWORD
*)info
->bmiColors
= descr
.rMask
;
4124 *((DWORD
*)info
->bmiColors
+ 1) = descr
.gMask
;
4125 *((DWORD
*)info
->bmiColors
+ 2) = descr
.bMask
;
4127 else if (!core_header
)
4129 /* if RLE or JPEG compression were supported,
4130 * this line would be invalid. */
4131 info
->bmiHeader
.biCompression
= 0;
4134 if(descr
.colorMap
&& descr
.colorMap
!= colorPtr
)
4135 HeapFree(GetProcessHeap(), 0, descr
.colorMap
);
4139 /***********************************************************************
4140 * DIB_DoProtectDIBSection
4142 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP
*physBitmap
, DWORD new_prot
)
4146 VirtualProtect(physBitmap
->base
, physBitmap
->size
, new_prot
, &old_prot
);
4147 TRACE("Changed protection from %ld to %ld\n", old_prot
, new_prot
);
4150 /***********************************************************************
4151 * X11DRV_DIB_DoCopyDIBSection
4153 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
,
4154 void *colorMap
, int nColorMap
,
4155 Drawable dest
, GC gc
,
4156 DWORD xSrc
, DWORD ySrc
,
4157 DWORD xDest
, DWORD yDest
,
4158 DWORD width
, DWORD height
)
4160 DIBSECTION dibSection
;
4161 X11DRV_DIB_IMAGEBITS_DESCR descr
;
4162 int identity
[2] = {0,1};
4164 if (!GetObjectW( physBitmap
->hbitmap
, sizeof(dibSection
), &dibSection
)) return;
4166 descr
.physDev
= NULL
;
4167 descr
.palentry
= NULL
;
4168 descr
.infoWidth
= dibSection
.dsBmih
.biWidth
;
4169 descr
.infoBpp
= dibSection
.dsBmih
.biBitCount
;
4170 descr
.lines
= dibSection
.dsBmih
.biHeight
;
4171 descr
.image
= physBitmap
->image
;
4172 descr
.colorMap
= colorMap
;
4173 descr
.nColorMap
= nColorMap
;
4174 descr
.bits
= dibSection
.dsBm
.bmBits
;
4175 descr
.depth
= physBitmap
->pixmap_depth
;
4176 descr
.compression
= dibSection
.dsBmih
.biCompression
;
4178 if(descr
.infoBpp
== 1)
4179 descr
.colorMap
= (void*)identity
;
4181 switch (descr
.infoBpp
)
4186 descr
.rMask
= descr
.gMask
= descr
.bMask
= 0;
4190 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0x7c00;
4191 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x03e0;
4192 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x001f;
4197 descr
.rMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[0] : 0xff0000;
4198 descr
.gMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[1] : 0x00ff00;
4199 descr
.bMask
= (descr
.compression
== BI_BITFIELDS
) ? dibSection
.dsBitfields
[2] : 0x0000ff;
4204 descr
.drawable
= dest
;
4208 descr
.xDest
= xDest
;
4209 descr
.yDest
= yDest
;
4210 descr
.width
= width
;
4211 descr
.height
= height
;
4212 descr
.sizeImage
= 0;
4214 #ifdef HAVE_LIBXXSHM
4215 descr
.useShm
= (physBitmap
->shminfo
.shmid
!= -1);
4217 descr
.useShm
= FALSE
;
4219 descr
.dibpitch
= dibSection
.dsBm
.bmWidthBytes
;
4223 TRACE("Copying from Pixmap to DIB bits\n");
4224 X11DRV_DIB_GetImageBits( &descr
);
4228 TRACE("Copying from DIB bits to Pixmap\n");
4229 X11DRV_DIB_SetImageBits( &descr
);
4233 /***********************************************************************
4234 * X11DRV_DIB_CopyDIBSection
4236 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE
*physDevSrc
, X11DRV_PDEVICE
*physDevDst
,
4237 DWORD xSrc
, DWORD ySrc
, DWORD xDest
, DWORD yDest
,
4238 DWORD width
, DWORD height
)
4241 X_PHYSBITMAP
*physBitmap
;
4242 int nColorMap
= 0, *colorMap
= NULL
, aColorMap
= FALSE
;
4244 TRACE("(%p,%p,%ld,%ld,%ld,%ld,%ld,%ld)\n", physDevSrc
->hdc
, physDevDst
->hdc
,
4245 xSrc
, ySrc
, xDest
, yDest
, width
, height
);
4246 /* this function is meant as an optimization for BitBlt,
4247 * not to be called otherwise */
4248 physBitmap
= physDevSrc
->bitmap
;
4249 if (!physBitmap
|| GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
4251 ERR("called for non-DIBSection!?\n");
4254 /* while BitBlt should already have made sure we only get
4255 * positive values, we should check for oversize values */
4256 if ((xSrc
< dib
.dsBm
.bmWidth
) &&
4257 (ySrc
< dib
.dsBm
.bmHeight
)) {
4258 if (xSrc
+ width
> dib
.dsBm
.bmWidth
)
4259 width
= dib
.dsBm
.bmWidth
- xSrc
;
4260 if (ySrc
+ height
> dib
.dsBm
.bmHeight
)
4261 height
= dib
.dsBm
.bmHeight
- ySrc
;
4262 /* if the source bitmap is 8bpp or less, we're supposed to use the
4263 * DC's palette for color conversion (not the DIB color table) */
4264 if (dib
.dsBm
.bmBitsPixel
<= 8) {
4265 HPALETTE hPalette
= GetCurrentObject( physDevSrc
->hdc
, OBJ_PAL
);
4266 if (!hPalette
|| (hPalette
== GetStockObject(DEFAULT_PALETTE
))) {
4267 /* HACK: no palette has been set in the source DC,
4268 * use the DIB colormap instead - this is necessary in some
4269 * cases since we need to do depth conversion in some places
4270 * where real Windows can just copy data straight over */
4271 colorMap
= physBitmap
->colorMap
;
4272 nColorMap
= physBitmap
->nColorMap
;
4274 colorMap
= X11DRV_DIB_BuildColorMap( physDevSrc
, (WORD
)-1,
4275 dib
.dsBm
.bmBitsPixel
,
4276 (BITMAPINFO
*)&dib
.dsBmih
,
4278 if (colorMap
) aColorMap
= TRUE
;
4281 /* perform the copy */
4282 X11DRV_DIB_DoCopyDIBSection(physBitmap
, FALSE
, colorMap
, nColorMap
,
4283 physDevDst
->drawable
, physDevDst
->gc
, xSrc
, ySrc
,
4284 physDevDst
->org
.x
+ xDest
, physDevDst
->org
.y
+ yDest
,
4286 /* free color mapping */
4288 HeapFree(GetProcessHeap(), 0, colorMap
);
4292 /***********************************************************************
4293 * X11DRV_DIB_DoUpdateDIBSection
4295 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP
*physBitmap
, BOOL toDIB
)
4299 GetObjectW( physBitmap
->hbitmap
, sizeof(bitmap
), &bitmap
);
4300 X11DRV_DIB_DoCopyDIBSection(physBitmap
, toDIB
,
4301 physBitmap
->colorMap
, physBitmap
->nColorMap
,
4302 physBitmap
->pixmap
, BITMAP_GC(physBitmap
),
4303 0, 0, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
);
4306 /***********************************************************************
4307 * X11DRV_DIB_FaultHandler
4309 static LONG CALLBACK
X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep
)
4311 X_PHYSBITMAP
*physBitmap
= NULL
;
4316 if (ep
->ExceptionRecord
->ExceptionCode
!= EXCEPTION_ACCESS_VIOLATION
)
4317 return EXCEPTION_CONTINUE_SEARCH
;
4319 addr
= (BYTE
*)ep
->ExceptionRecord
->ExceptionInformation
[1];
4321 EnterCriticalSection(&dibs_cs
);
4322 LIST_FOR_EACH( ptr
, &dibs_list
)
4324 physBitmap
= LIST_ENTRY( ptr
, X_PHYSBITMAP
, entry
);
4325 if ((physBitmap
->base
<= addr
) && (addr
< physBitmap
->base
+ physBitmap
->size
))
4331 LeaveCriticalSection(&dibs_cs
);
4333 if (!found
) return EXCEPTION_CONTINUE_SEARCH
;
4335 X11DRV_DIB_Lock( physBitmap
, DIB_Status_None
, FALSE
);
4336 if (ep
->ExceptionRecord
->ExceptionInformation
[0]) {
4337 /* the app tried to write the DIB bits */
4338 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_AppMod
, FALSE
);
4340 /* the app tried to read the DIB bits */
4341 X11DRV_DIB_Coerce( physBitmap
, DIB_Status_InSync
, FALSE
);
4343 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4345 return EXCEPTION_CONTINUE_EXECUTION
;
4348 /***********************************************************************
4351 static INT
X11DRV_DIB_Coerce(X_PHYSBITMAP
*physBitmap
, INT req
, BOOL lossy
)
4353 INT ret
= DIB_Status_None
;
4355 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4356 EnterCriticalSection(&physBitmap
->lock
);
4357 ret
= physBitmap
->status
;
4359 case DIB_Status_GdiMod
:
4360 /* GDI access - request to draw on pixmap */
4361 switch (physBitmap
->status
)
4364 case DIB_Status_None
:
4365 physBitmap
->p_status
= DIB_Status_GdiMod
;
4366 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4369 case DIB_Status_GdiMod
:
4370 TRACE("GdiMod requested in status GdiMod\n" );
4371 physBitmap
->p_status
= DIB_Status_GdiMod
;
4374 case DIB_Status_InSync
:
4375 TRACE("GdiMod requested in status InSync\n" );
4376 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4377 physBitmap
->status
= DIB_Status_GdiMod
;
4378 physBitmap
->p_status
= DIB_Status_InSync
;
4381 case DIB_Status_AppMod
:
4382 TRACE("GdiMod requested in status AppMod\n" );
4384 /* make it readonly to avoid app changing data while we copy */
4385 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4386 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, FALSE
);
4388 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_NOACCESS
);
4389 physBitmap
->p_status
= DIB_Status_AppMod
;
4390 physBitmap
->status
= DIB_Status_GdiMod
;
4395 case DIB_Status_InSync
:
4396 /* App access - request access to read DIB surface */
4397 /* (typically called from signal handler) */
4398 switch (physBitmap
->status
)
4401 case DIB_Status_None
:
4402 /* shouldn't happen from signal handler */
4405 case DIB_Status_GdiMod
:
4406 TRACE("InSync requested in status GdiMod\n" );
4408 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4409 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4411 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4412 physBitmap
->status
= DIB_Status_InSync
;
4415 case DIB_Status_InSync
:
4416 TRACE("InSync requested in status InSync\n" );
4417 /* shouldn't happen from signal handler */
4420 case DIB_Status_AppMod
:
4421 TRACE("InSync requested in status AppMod\n" );
4422 /* no reason to do anything here, and this
4423 * shouldn't happen from signal handler */
4428 case DIB_Status_AppMod
:
4429 /* App access - request access to write DIB surface */
4430 /* (typically called from signal handler) */
4431 switch (physBitmap
->status
)
4434 case DIB_Status_None
:
4435 /* shouldn't happen from signal handler */
4438 case DIB_Status_GdiMod
:
4439 TRACE("AppMod requested in status GdiMod\n" );
4440 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4441 if (!lossy
) X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4442 physBitmap
->status
= DIB_Status_AppMod
;
4445 case DIB_Status_InSync
:
4446 TRACE("AppMod requested in status InSync\n" );
4447 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4448 physBitmap
->status
= DIB_Status_AppMod
;
4451 case DIB_Status_AppMod
:
4452 TRACE("AppMod requested in status AppMod\n" );
4453 /* shouldn't happen from signal handler */
4458 /* it is up to the caller to do the copy/conversion, probably
4459 * using the return value to decide where to copy from */
4461 LeaveCriticalSection(&physBitmap
->lock
);
4465 /***********************************************************************
4468 static INT
X11DRV_DIB_Lock(X_PHYSBITMAP
*physBitmap
, INT req
, BOOL lossy
)
4470 INT ret
= DIB_Status_None
;
4472 if (!physBitmap
->image
) return ret
; /* not a DIB section */
4473 TRACE("Locking %p from thread %04lx\n", physBitmap
->hbitmap
, GetCurrentThreadId());
4474 EnterCriticalSection(&physBitmap
->lock
);
4475 ret
= physBitmap
->status
;
4476 if (req
!= DIB_Status_None
)
4477 X11DRV_DIB_Coerce(physBitmap
, req
, lossy
);
4481 /***********************************************************************
4484 static void X11DRV_DIB_Unlock(X_PHYSBITMAP
*physBitmap
, BOOL commit
)
4486 if (!physBitmap
->image
) return; /* not a DIB section */
4487 switch (physBitmap
->status
)
4490 case DIB_Status_None
:
4491 /* in case anyone is wondering, this is the "signal handler doesn't
4492 * work" case, where we always have to be ready for app access */
4494 switch (physBitmap
->p_status
)
4496 case DIB_Status_GdiMod
:
4497 TRACE("Unlocking and syncing from GdiMod\n" );
4498 X11DRV_DIB_DoUpdateDIBSection( physBitmap
, TRUE
);
4502 TRACE("Unlocking without needing to sync\n" );
4506 else TRACE("Unlocking with no changes\n");
4507 physBitmap
->p_status
= DIB_Status_None
;
4510 case DIB_Status_GdiMod
:
4511 TRACE("Unlocking in status GdiMod\n" );
4512 /* DIB was protected in Coerce */
4514 /* no commit, revert to InSync if applicable */
4515 if ((physBitmap
->p_status
== DIB_Status_InSync
) ||
4516 (physBitmap
->p_status
== DIB_Status_AppMod
)) {
4517 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READONLY
);
4518 physBitmap
->status
= DIB_Status_InSync
;
4523 case DIB_Status_InSync
:
4524 TRACE("Unlocking in status InSync\n" );
4525 /* DIB was already protected in Coerce */
4528 case DIB_Status_AppMod
:
4529 TRACE("Unlocking in status AppMod\n" );
4530 /* DIB was already protected in Coerce */
4531 /* this case is ordinary only called from the signal handler,
4532 * so we don't bother to check for !commit */
4535 LeaveCriticalSection(&physBitmap
->lock
);
4536 TRACE("Unlocked %p\n", physBitmap
->hbitmap
);
4539 /***********************************************************************
4540 * X11DRV_CoerceDIBSection
4542 INT
X11DRV_CoerceDIBSection(X11DRV_PDEVICE
*physDev
, INT req
, BOOL lossy
)
4544 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4545 return X11DRV_DIB_Coerce(physDev
->bitmap
, req
, lossy
);
4548 /***********************************************************************
4549 * X11DRV_LockDIBSection
4551 INT
X11DRV_LockDIBSection(X11DRV_PDEVICE
*physDev
, INT req
, BOOL lossy
)
4553 if (!physDev
|| !physDev
->bitmap
) return DIB_Status_None
;
4554 return X11DRV_DIB_Lock(physDev
->bitmap
, req
, lossy
);
4557 /***********************************************************************
4558 * X11DRV_UnlockDIBSection
4560 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE
*physDev
, BOOL commit
)
4562 if (!physDev
|| !physDev
->bitmap
) return;
4563 X11DRV_DIB_Unlock(physDev
->bitmap
, commit
);
4567 #ifdef HAVE_LIBXXSHM
4568 /***********************************************************************
4569 * X11DRV_XShmErrorHandler
4572 static int XShmErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
4574 return 1; /* FIXME: should check event contents */
4577 /***********************************************************************
4578 * X11DRV_XShmCreateImage
4581 static XImage
*X11DRV_XShmCreateImage( int width
, int height
, int bpp
,
4582 XShmSegmentInfo
* shminfo
)
4586 image
= XShmCreateImage(gdi_display
, visual
, bpp
, ZPixmap
, NULL
, shminfo
, width
, height
);
4589 shminfo
->shmid
= shmget(IPC_PRIVATE
, image
->bytes_per_line
* height
,
4591 if( shminfo
->shmid
!= -1 )
4593 shminfo
->shmaddr
= image
->data
= shmat(shminfo
->shmid
, 0, 0);
4594 if( shminfo
->shmaddr
!= (char*)-1 )
4598 shminfo
->readOnly
= FALSE
;
4599 X11DRV_expect_error( gdi_display
, XShmErrorHandler
, NULL
);
4600 ok
= (XShmAttach( gdi_display
, shminfo
) != 0);
4601 XSync( gdi_display
, False
);
4602 if (X11DRV_check_error()) ok
= FALSE
;
4605 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4606 return image
; /* Success! */
4608 /* An error occurred */
4609 shmdt(shminfo
->shmaddr
);
4611 shmctl(shminfo
->shmid
, IPC_RMID
, 0);
4612 shminfo
->shmid
= -1;
4614 XFlush(gdi_display
);
4615 XDestroyImage(image
);
4620 #endif /* HAVE_LIBXXSHM */
4623 /***********************************************************************
4624 * X11DRV_CreateDIBSection (X11DRV.@)
4626 HBITMAP
X11DRV_CreateDIBSection( X11DRV_PDEVICE
*physDev
, HBITMAP hbitmap
,
4627 const BITMAPINFO
*bmi
, UINT usage
)
4629 X_PHYSBITMAP
*physBitmap
;
4632 if (!(physBitmap
= X11DRV_init_phys_bitmap( hbitmap
))) return 0;
4633 physBitmap
->status
= DIB_Status_None
;
4635 GetObjectW( hbitmap
, sizeof(dib
), &dib
);
4637 /* create color map */
4638 if (dib
.dsBm
.bmBitsPixel
<= 8)
4640 physBitmap
->colorMap
= X11DRV_DIB_BuildColorMap( usage
== DIB_PAL_COLORS
? physDev
: NULL
,
4641 usage
, dib
.dsBm
.bmBitsPixel
, bmi
,
4642 &physBitmap
->nColorMap
);
4643 physBitmap
->colorTable
= X11DRV_DIB_BuildColorTable( physDev
, usage
, dib
.dsBm
.bmBitsPixel
, bmi
);
4646 /* create pixmap and X image */
4648 physBitmap
->pixmap_depth
= (dib
.dsBm
.bmBitsPixel
== 1) ? 1 : screen_depth
;
4649 physBitmap
->pixmap
= XCreatePixmap( gdi_display
, root_window
, dib
.dsBm
.bmWidth
,
4650 dib
.dsBm
.bmHeight
, physBitmap
->pixmap_depth
);
4651 #ifdef HAVE_LIBXXSHM
4652 physBitmap
->shminfo
.shmid
= -1;
4653 if (!XShmQueryExtension(gdi_display
) ||
4654 !(physBitmap
->image
= X11DRV_XShmCreateImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4655 physBitmap
->pixmap_depth
, &physBitmap
->shminfo
)) )
4657 physBitmap
->image
= X11DRV_DIB_CreateXImage( dib
.dsBm
.bmWidth
, dib
.dsBm
.bmHeight
,
4658 physBitmap
->pixmap_depth
);
4659 wine_tsx11_unlock();
4660 if (!physBitmap
->pixmap
|| !physBitmap
->image
) return 0;
4662 /* install fault handler */
4663 InitializeCriticalSection( &physBitmap
->lock
);
4665 physBitmap
->base
= dib
.dsBm
.bmBits
;
4666 physBitmap
->size
= dib
.dsBmih
.biSizeImage
;
4667 physBitmap
->status
= DIB_Status_AppMod
;
4670 dibs_handler
= AddVectoredExceptionHandler( TRUE
, X11DRV_DIB_FaultHandler
);
4671 EnterCriticalSection( &dibs_cs
);
4672 list_add_head( &dibs_list
, &physBitmap
->entry
);
4673 LeaveCriticalSection( &dibs_cs
);
4675 X11DRV_DIB_DoProtectDIBSection( physBitmap
, PAGE_READWRITE
);
4680 /***********************************************************************
4681 * X11DRV_DIB_DeleteDIBSection
4683 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP
*physBitmap
, DIBSECTION
*dib
)
4687 EnterCriticalSection( &dibs_cs
);
4688 list_remove( &physBitmap
->entry
);
4689 last
= list_empty( &dibs_list
);
4690 LeaveCriticalSection( &dibs_cs
);
4694 RemoveVectoredExceptionHandler( dibs_handler
);
4695 dibs_handler
= NULL
;
4698 if (dib
->dshSection
)
4699 X11DRV_DIB_Coerce(physBitmap
, DIB_Status_InSync
, FALSE
);
4701 if (physBitmap
->image
)
4704 #ifdef HAVE_LIBXXSHM
4705 if (physBitmap
->shminfo
.shmid
!= -1)
4707 XShmDetach( gdi_display
, &(physBitmap
->shminfo
) );
4708 XDestroyImage( physBitmap
->image
);
4709 shmdt( physBitmap
->shminfo
.shmaddr
);
4710 physBitmap
->shminfo
.shmid
= -1;
4714 XDestroyImage( physBitmap
->image
);
4715 wine_tsx11_unlock();
4718 HeapFree(GetProcessHeap(), 0, physBitmap
->colorMap
);
4719 HeapFree(GetProcessHeap(), 0, physBitmap
->colorTable
);
4720 DeleteCriticalSection(&physBitmap
->lock
);
4723 /***********************************************************************
4724 * SetDIBColorTable (X11DRV.@)
4726 UINT
X11DRV_SetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, const RGBQUAD
*colors
)
4730 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4732 if (!physBitmap
) return 0;
4733 GetObjectW( physBitmap
->hbitmap
, sizeof(dib
), &dib
);
4735 if (physBitmap
->colorMap
&& start
< physBitmap
->nColorMap
) {
4736 UINT end
= count
+ start
;
4737 if (end
> physBitmap
->nColorMap
) end
= physBitmap
->nColorMap
;
4739 * Changing color table might change the mapping between
4740 * DIB colors and X11 colors and thus alter the visible state
4741 * of the bitmap object.
4743 X11DRV_DIB_Lock( physBitmap
, DIB_Status_AppMod
, FALSE
);
4744 memcpy(physBitmap
->colorTable
+ start
, colors
, (end
- start
) * sizeof(RGBQUAD
));
4745 X11DRV_DIB_GenColorMap( physDev
, physBitmap
->colorMap
, DIB_RGB_COLORS
,
4746 dib
.dsBm
.bmBitsPixel
,
4747 TRUE
, colors
, start
, end
);
4748 X11DRV_DIB_Unlock( physBitmap
, TRUE
);
4754 /***********************************************************************
4755 * GetDIBColorTable (X11DRV.@)
4757 UINT
X11DRV_GetDIBColorTable( X11DRV_PDEVICE
*physDev
, UINT start
, UINT count
, RGBQUAD
*colors
)
4760 X_PHYSBITMAP
*physBitmap
= physDev
->bitmap
;
4762 if (physBitmap
&& physBitmap
->colorTable
&& start
< physBitmap
->nColorMap
) {
4763 if (start
+ count
> physBitmap
->nColorMap
) count
= physBitmap
->nColorMap
- start
;
4764 memcpy(colors
, physBitmap
->colorTable
+ start
, count
* sizeof(RGBQUAD
));
4772 /***********************************************************************
4773 * X11DRV_DIB_CreateDIBFromBitmap
4775 * Allocates a packed DIB and copies the bitmap data into it.
4777 HGLOBAL
X11DRV_DIB_CreateDIBFromBitmap(HDC hdc
, HBITMAP hBmp
)
4782 LPBITMAPINFOHEADER pbmiHeader
;
4783 unsigned int cDataSize
, cPackedSize
, OffsetBits
;
4786 if (!GetObjectW( hBmp
, sizeof(bmp
), &bmp
)) return 0;
4789 * A packed DIB contains a BITMAPINFO structure followed immediately by
4790 * an optional color palette and the pixel data.
4793 /* Calculate the size of the packed DIB */
4794 cDataSize
= X11DRV_DIB_GetDIBWidthBytes( bmp
.bmWidth
, bmp
.bmBitsPixel
) * abs( bmp
.bmHeight
);
4795 cPackedSize
= sizeof(BITMAPINFOHEADER
)
4796 + ( (bmp
.bmBitsPixel
<= 8) ? (sizeof(RGBQUAD
) * (1 << bmp
.bmBitsPixel
)) : 0 )
4798 /* Get the offset to the bits */
4799 OffsetBits
= cPackedSize
- cDataSize
;
4801 /* Allocate the packed DIB */
4802 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize
);
4803 hPackedDIB
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
/*| GMEM_ZEROINIT*/,
4807 WARN("Could not allocate packed DIB!\n");
4811 /* A packed DIB starts with a BITMAPINFOHEADER */
4812 pPackedDIB
= GlobalLock(hPackedDIB
);
4813 pbmiHeader
= (LPBITMAPINFOHEADER
)pPackedDIB
;
4815 /* Init the BITMAPINFOHEADER */
4816 pbmiHeader
->biSize
= sizeof(BITMAPINFOHEADER
);
4817 pbmiHeader
->biWidth
= bmp
.bmWidth
;
4818 pbmiHeader
->biHeight
= bmp
.bmHeight
;
4819 pbmiHeader
->biPlanes
= 1;
4820 pbmiHeader
->biBitCount
= bmp
.bmBitsPixel
;
4821 pbmiHeader
->biCompression
= BI_RGB
;
4822 pbmiHeader
->biSizeImage
= 0;
4823 pbmiHeader
->biXPelsPerMeter
= pbmiHeader
->biYPelsPerMeter
= 0;
4824 pbmiHeader
->biClrUsed
= 0;
4825 pbmiHeader
->biClrImportant
= 0;
4827 /* Retrieve the DIB bits from the bitmap and fill in the
4828 * DIB color table if present */
4830 nLinesCopied
= GetDIBits(hdc
, /* Handle to device context */
4831 hBmp
, /* Handle to bitmap */
4832 0, /* First scan line to set in dest bitmap */
4833 bmp
.bmHeight
, /* Number of scan lines to copy */
4834 pPackedDIB
+ OffsetBits
, /* [out] Address of array for bitmap bits */
4835 (LPBITMAPINFO
) pbmiHeader
, /* [out] Address of BITMAPINFO structure */
4836 0); /* RGB or palette index */
4837 GlobalUnlock(hPackedDIB
);
4839 /* Cleanup if GetDIBits failed */
4840 if (nLinesCopied
!= bmp
.bmHeight
)
4842 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied
, bmp
.bmHeight
);
4843 GlobalFree(hPackedDIB
);
4850 /**************************************************************************
4851 * X11DRV_DIB_CreateDIBFromPixmap
4853 * Allocates a packed DIB and copies the Pixmap data into it.
4854 * The Pixmap passed in is deleted after the conversion.
4856 HGLOBAL
X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap
, HDC hdc
)
4859 X_PHYSBITMAP
*physBitmap
;
4860 HBITMAP hBmp
= 0, old
;
4861 HGLOBAL hPackedDIB
= 0;
4863 int x
,y
; /* Unused */
4864 unsigned border_width
; /* Unused */
4865 unsigned int depth
, width
, height
;
4867 /* Get the Pixmap dimensions and bit depth */
4869 if (!XGetGeometry(gdi_display
, pixmap
, &root
, &x
, &y
, &width
, &height
,
4870 &border_width
, &depth
)) depth
= 0;
4871 wine_tsx11_unlock();
4872 if (!depth
) return 0;
4874 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4875 width
, height
, depth
);
4878 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4879 * and make it a container for the pixmap passed.
4881 hBmp
= CreateBitmap( width
, height
, 1, depth
, NULL
);
4883 /* force bitmap to be owned by a screen DC */
4884 hdcMem
= CreateCompatibleDC( hdc
);
4885 old
= SelectObject( hdcMem
, hBmp
);
4887 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4890 if (physBitmap
->pixmap
) XFreePixmap( gdi_display
, physBitmap
->pixmap
);
4891 physBitmap
->pixmap
= pixmap
;
4892 wine_tsx11_unlock();
4894 SelectObject( hdcMem
, old
);
4898 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4899 * A packed DIB contains a BITMAPINFO structure followed immediately by
4900 * an optional color palette and the pixel data.
4902 hPackedDIB
= X11DRV_DIB_CreateDIBFromBitmap(hdc
, hBmp
);
4904 /* We can now get rid of the HBITMAP wrapper we created earlier.
4905 * Note: Simply calling DeleteObject will free the embedded Pixmap as well.
4909 TRACE("\tReturning packed DIB %p\n", hPackedDIB
);
4914 /**************************************************************************
4915 * X11DRV_DIB_CreatePixmapFromDIB
4917 * Creates a Pixmap from a packed DIB
4919 Pixmap
X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB
, HDC hdc
)
4922 X_PHYSBITMAP
*physBitmap
;
4926 /* Create a DDB from the DIB */
4928 pbmi
= GlobalLock(hPackedDIB
);
4929 hBmp
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
,
4930 (LPBYTE
)pbmi
+ X11DRV_DIB_BitmapInfoSize( pbmi
, DIB_RGB_COLORS
),
4931 pbmi
, DIB_RGB_COLORS
);
4932 GlobalUnlock(hPackedDIB
);
4934 /* clear the physBitmap so that we can steal its pixmap */
4935 physBitmap
= X11DRV_get_phys_bitmap( hBmp
);
4936 pixmap
= physBitmap
->pixmap
;
4937 physBitmap
->pixmap
= 0;
4939 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4942 TRACE("Returning Pixmap %ld\n", pixmap
);