2 * X11DRV device-independent bitmaps
4 * Copyright 1993,1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
26 #include <X11/extensions/XShm.h>
27 # ifdef HAVE_SYS_SHM_H
30 # ifdef HAVE_SYS_IPC_H
33 #endif /* defined(HAVE_LIBXXSHM) */
42 #include "wine/exception.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(bitmap);
47 static struct list dibs_list = LIST_INIT(dibs_list);
49 static CRITICAL_SECTION dibs_cs;
50 static CRITICAL_SECTION_DEBUG dibs_cs_debug =
53 { &dibs_cs_debug.ProcessLocksList, &dibs_cs_debug.ProcessLocksList },
54 0, 0, { (DWORD_PTR)(__FILE__ ": dibs_cs") }
56 static CRITICAL_SECTION dibs_cs = { &dibs_cs_debug, -1, 0, 0, 0, 0 };
58 static PVOID dibs_handler;
60 static int ximageDepthTable[32];
62 /* This structure holds the arguments for DIB_SetImageBits() */
65 X11DRV_PDEVICE *physDev;
68 PALETTEENTRY *palentry;
88 enum x11drv_shm_mode shm_mode;
91 X_PHYSBITMAP *physBitmap;
92 } X11DRV_DIB_IMAGEBITS_DESCR;
97 RLE_EOL = 0, /* End of line */
98 RLE_END = 1, /* End of bitmap */
99 RLE_DELTA = 2 /* Delta */
103 static INT X11DRV_DIB_Coerce(X_PHYSBITMAP *,INT);
106 Some of the following helper functions are duplicated in
110 /***********************************************************************
111 * DIB_DoProtectDIBSection
113 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP *physBitmap, DWORD new_prot )
117 VirtualProtect(physBitmap->base, physBitmap->size, new_prot, &old_prot);
118 TRACE("Changed protection from %d to %d\n", old_prot, new_prot);
121 /***********************************************************************
122 * X11DRV_DIB_GetXImageWidthBytes
124 * Return the width of an X image in bytes
126 static inline int X11DRV_DIB_GetXImageWidthBytes( int width, int depth )
128 if (!depth || depth > 32) goto error;
130 if (!ximageDepthTable[depth-1])
132 XImage *testimage = XCreateImage( gdi_display, visual, depth,
133 ZPixmap, 0, NULL, 1, 1, 32, 20 );
136 ximageDepthTable[depth-1] = testimage->bits_per_pixel;
137 XDestroyImage( testimage );
139 else ximageDepthTable[depth-1] = -1;
141 if (ximageDepthTable[depth-1] != -1)
142 return (4 * ((width * ximageDepthTable[depth-1] + 31) / 32));
145 WARN( "(%d): Unsupported depth\n", depth );
150 /***********************************************************************
151 * X11DRV_DIB_GetDIBWidthBytes
153 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
155 static int X11DRV_DIB_GetDIBWidthBytes( int width, int depth )
161 case 1: words = (width + 31) / 32; break;
162 case 4: words = (width + 7) / 8; break;
163 case 8: words = (width + 3) / 4; break;
165 case 16: words = (width + 1) / 2; break;
166 case 24: words = (width * 3 + 3) / 4; break;
168 WARN("(%d): Unsupported depth\n", depth );
177 /***********************************************************************
180 * Return the size of the bitmap info structure including color table.
182 int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
184 unsigned int colors, size, masks = 0;
186 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
188 const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info;
189 colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
190 return sizeof(BITMAPCOREHEADER) + colors *
191 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
193 else /* assume BITMAPINFOHEADER */
195 colors = info->bmiHeader.biClrUsed;
196 if (!colors && (info->bmiHeader.biBitCount <= 8))
197 colors = 1 << info->bmiHeader.biBitCount;
198 if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
199 size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
200 return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
205 /***********************************************************************
206 * X11DRV_DIB_CreateXImage
210 XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth )
213 XImage *image = NULL;
217 width_bytes = X11DRV_DIB_GetXImageWidthBytes( width, depth );
218 data = HeapAlloc( GetProcessHeap(), 0, height * width_bytes );
219 if (data) image = XCreateImage( gdi_display, visual, depth, ZPixmap, 0,
220 data, width, height, 32, width_bytes );
221 if (!image) HeapFree( GetProcessHeap(), 0, data );
227 /***********************************************************************
228 * X11DRV_DIB_DestroyXImage
230 * Destroy an X image created with X11DRV_DIB_CreateXImage.
232 void X11DRV_DIB_DestroyXImage( XImage *image )
234 HeapFree( GetProcessHeap(), 0, image->data );
237 XDestroyImage( image );
242 /***********************************************************************
243 * X11DRV_DIB_GetColorCount
245 * Computes the number of colors for the bitmap palette.
246 * Should not be called for a >8-bit deep bitmap.
248 static unsigned int X11DRV_DIB_GetColorCount(const BITMAPINFO *info)
250 unsigned int colors = min( info->bmiHeader.biClrUsed, 256 );
251 if (!colors) colors = 1 << info->bmiHeader.biBitCount;
256 static inline BOOL colour_is_brighter(RGBQUAD c1, RGBQUAD c2)
258 return (c1.rgbRed * c1.rgbRed + c1.rgbGreen * c1.rgbGreen + c1.rgbBlue * c1.rgbBlue) >
259 (c2.rgbRed * c2.rgbRed + c2.rgbGreen * c2.rgbGreen + c2.rgbBlue * c2.rgbBlue);
262 /***********************************************************************
263 * X11DRV_DIB_GenColorMap
265 * Fills the color map of a bitmap palette. Should not be called
266 * for a >8-bit deep bitmap.
268 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE *physDev, int *colorMapping,
269 WORD coloruse, WORD depth, const void *colorPtr, int start, int end )
273 if (coloruse == DIB_RGB_COLORS)
275 const RGBQUAD * rgb = colorPtr;
277 if (depth == 1) /* Monochrome */
282 if (GetDIBColorTable( physDev->dev.hdc, 0, 2, table ) == 2)
283 invert = !colour_is_brighter(table[1], table[0]);
285 for (i = start; i < end; i++, rgb++)
286 colorMapping[i] = ((rgb->rgbRed + rgb->rgbGreen +
287 rgb->rgbBlue > 255*3/2 && !invert) ||
288 (rgb->rgbRed + rgb->rgbGreen +
289 rgb->rgbBlue <= 255*3/2 && invert));
292 for (i = start; i < end; i++, rgb++)
293 colorMapping[i] = X11DRV_PALETTE_LookupPixel(physDev->color_shifts, RGB(rgb->rgbRed,
297 else /* DIB_PAL_COLORS */
299 const WORD * index = colorPtr;
301 for (i = start; i < end; i++, index++)
302 colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(*index) );
308 /***********************************************************************
309 * X11DRV_DIB_BuildColorMap
311 * Build the color map from the bitmap palette. Should not be called
312 * for a >8-bit deep bitmap.
314 static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE *physDev, WORD coloruse, WORD depth,
315 const BITMAPINFO *info, int *nColors )
317 const void *colorPtr;
321 *nColors = X11DRV_DIB_GetColorCount(info);
322 if (!*nColors) return NULL;
324 colorPtr = (const BYTE*)info + (WORD)info->bmiHeader.biSize;
325 if (!(colorMapping = HeapAlloc(GetProcessHeap(), 0, *nColors * sizeof(int) )))
328 return X11DRV_DIB_GenColorMap( physDev, colorMapping, coloruse, depth,
329 colorPtr, 0, *nColors);
332 /***********************************************************************
333 * X11DRV_DIB_MapColor
335 static int X11DRV_DIB_MapColor( int *physMap, int nPhysMap, int phys, int oldcol )
339 if ((oldcol < nPhysMap) && (physMap[oldcol] == phys))
342 for (color = 0; color < nPhysMap; color++)
343 if (physMap[color] == phys)
346 WARN("Strange color %08x\n", phys);
351 /*********************************************************************
352 * X11DRV_DIB_GetNearestIndex
354 * Helper for X11DRV_DIB_GetDIBits.
355 * Returns the nearest colour table index for a given RGB.
356 * Nearest is defined by minimizing the sum of the squares.
358 static INT X11DRV_DIB_GetNearestIndex(RGBQUAD *colormap, int numColors, BYTE r, BYTE g, BYTE b)
360 INT i, best = -1, diff, bestdiff = -1;
363 for(color = colormap, i = 0; i < numColors; color++, i++) {
364 diff = (r - color->rgbRed) * (r - color->rgbRed) +
365 (g - color->rgbGreen) * (g - color->rgbGreen) +
366 (b - color->rgbBlue) * (b - color->rgbBlue);
369 if(best == -1 || diff < bestdiff) {
376 /*********************************************************************
377 * X11DRV_DIB_MaskToShift
379 * Helper for X11DRV_DIB_GetDIBits.
380 * Returns the by how many bits to shift a given color so that it is
381 * in the proper position.
383 INT X11DRV_DIB_MaskToShift(DWORD mask)
391 while ((mask&1)==0) {
398 /***********************************************************************
399 * X11DRV_DIB_CheckMask
401 * Check RGB mask if it is either 0 or matches visual's mask.
403 static inline int X11DRV_DIB_CheckMask(int red_mask, int green_mask, int blue_mask)
405 return ( red_mask == 0 && green_mask == 0 && blue_mask == 0 ) ||
406 ( red_mask == visual->red_mask && green_mask == visual->green_mask &&
407 blue_mask == visual->blue_mask );
410 /***********************************************************************
411 * X11DRV_DIB_SetImageBits_1
413 * SetDIBits for a 1-bit deep DIB.
415 static void X11DRV_DIB_SetImageBits_1( int lines, const BYTE *srcbits,
416 DWORD srcwidth, DWORD dstwidth, int left,
417 int *colors, XImage *bmpImage, int linebytes)
426 srcbits = srcbits + linebytes * (lines - 1);
427 linebytes = -linebytes;
430 if ((extra = (left & 7)) != 0) {
434 srcbits += left >> 3;
435 width = min(srcwidth, dstwidth);
437 /* ==== pal 1 dib -> any bmp format ==== */
438 for (h = lines-1; h >=0; h--) {
440 for (i = width/8, x = left; i > 0; i--) {
442 XPutPixel( bmpImage, x++, h, colors[ srcval >> 7] );
443 XPutPixel( bmpImage, x++, h, colors[(srcval >> 6) & 1] );
444 XPutPixel( bmpImage, x++, h, colors[(srcval >> 5) & 1] );
445 XPutPixel( bmpImage, x++, h, colors[(srcval >> 4) & 1] );
446 XPutPixel( bmpImage, x++, h, colors[(srcval >> 3) & 1] );
447 XPutPixel( bmpImage, x++, h, colors[(srcval >> 2) & 1] );
448 XPutPixel( bmpImage, x++, h, colors[(srcval >> 1) & 1] );
449 XPutPixel( bmpImage, x++, h, colors[ srcval & 1] );
455 case 7: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
456 case 6: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
457 case 5: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
458 case 4: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
459 case 3: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
460 case 2: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
461 case 1: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]);
464 srcbits += linebytes;
468 /***********************************************************************
469 * X11DRV_DIB_GetImageBits_1
471 * GetDIBits for a 1-bit deep DIB.
473 static void X11DRV_DIB_GetImageBits_1( int lines, BYTE *dstbits,
474 DWORD dstwidth, DWORD srcwidth,
475 RGBQUAD *colors, PALETTEENTRY *srccolors,
476 XImage *bmpImage, int linebytes )
479 int h, width = min(dstwidth, srcwidth);
483 dstbits = dstbits + linebytes * (lines - 1);
484 linebytes = -linebytes;
487 switch (bmpImage->depth)
491 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
493 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
496 for (h=lines-1; h>=0; h--) {
500 for (x=0; x<width; x++) {
502 srcval=srccolors[XGetPixel(bmpImage, x, h)];
503 dstval|=(X11DRV_DIB_GetNearestIndex
507 srcval.peBlue) << (7 - (x & 7)));
516 /* pad with 0 to DWORD alignment */
517 for (x = (x+7)&~7; x < ((width + 31) & ~31); x+=8)
519 dstbits += linebytes;
527 if (X11DRV_DIB_CheckMask(bmpImage->red_mask, bmpImage->green_mask, bmpImage->blue_mask)
529 /* ==== pal 8 bmp -> pal 1 dib ==== */
531 const BYTE* srcpixel;
534 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
536 for (h=0; h<lines; h++) {
541 for (x=0; x<width; x++) {
543 srcval=srccolors[*srcpixel++];
544 dstval|=(X11DRV_DIB_GetNearestIndex
548 srcval.peBlue) << (7-(x&7)) );
557 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
558 dstbits += linebytes;
569 const WORD* srcpixel;
572 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
574 if (bmpImage->green_mask==0x03e0) {
575 if (bmpImage->red_mask==0x7c00) {
576 /* ==== rgb 555 bmp -> pal 1 dib ==== */
577 for (h=0; h<lines; h++) {
582 for (x=0; x<width; x++) {
585 dstval|=(X11DRV_DIB_GetNearestIndex
587 ((srcval >> 7) & 0xf8) | /* r */
588 ((srcval >> 12) & 0x07),
589 ((srcval >> 2) & 0xf8) | /* g */
590 ((srcval >> 7) & 0x07),
591 ((srcval << 3) & 0xf8) | /* b */
592 ((srcval >> 2) & 0x07) ) << (7-(x&7)) );
601 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
602 dstbits += linebytes;
604 } else if (bmpImage->blue_mask==0x7c00) {
605 /* ==== bgr 555 bmp -> pal 1 dib ==== */
606 for (h=0; h<lines; h++) {
611 for (x=0; x<width; x++) {
614 dstval|=(X11DRV_DIB_GetNearestIndex
616 ((srcval << 3) & 0xf8) | /* r */
617 ((srcval >> 2) & 0x07),
618 ((srcval >> 2) & 0xf8) | /* g */
619 ((srcval >> 7) & 0x07),
620 ((srcval >> 7) & 0xf8) | /* b */
621 ((srcval >> 12) & 0x07) ) << (7-(x&7)) );
630 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
631 dstbits += linebytes;
636 } else if (bmpImage->green_mask==0x07e0) {
637 if (bmpImage->red_mask==0xf800) {
638 /* ==== rgb 565 bmp -> pal 1 dib ==== */
639 for (h=0; h<lines; h++) {
644 for (x=0; x<width; x++) {
647 dstval|=(X11DRV_DIB_GetNearestIndex
649 ((srcval >> 8) & 0xf8) | /* r */
650 ((srcval >> 13) & 0x07),
651 ((srcval >> 3) & 0xfc) | /* g */
652 ((srcval >> 9) & 0x03),
653 ((srcval << 3) & 0xf8) | /* b */
654 ((srcval >> 2) & 0x07) ) << (7-(x&7)) );
663 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
664 dstbits += linebytes;
666 } else if (bmpImage->blue_mask==0xf800) {
667 /* ==== bgr 565 bmp -> pal 1 dib ==== */
668 for (h=0; h<lines; h++) {
673 for (x=0; x<width; x++) {
676 dstval|=(X11DRV_DIB_GetNearestIndex
678 ((srcval << 3) & 0xf8) | /* r */
679 ((srcval >> 2) & 0x07),
680 ((srcval >> 3) & 0xfc) | /* g */
681 ((srcval >> 9) & 0x03),
682 ((srcval >> 8) & 0xf8) | /* b */
683 ((srcval >> 13) & 0x07) ) << (7-(x&7)) );
692 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
693 dstbits += linebytes;
712 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
713 bytes_per_pixel=(bmpImage->bits_per_pixel==24?3:4);
715 if (bmpImage->green_mask!=0x00ff00 ||
716 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
718 } else if (bmpImage->blue_mask==0xff) {
719 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
720 for (h=0; h<lines; h++) {
725 for (x=0; x<width; x++) {
726 dstval|=(X11DRV_DIB_GetNearestIndex
730 srcbyte[0]) << (7-(x&7)) );
731 srcbyte+=bytes_per_pixel;
740 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
741 dstbits += linebytes;
744 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
745 for (h=0; h<lines; h++) {
750 for (x=0; x<width; x++) {
751 dstval|=(X11DRV_DIB_GetNearestIndex
755 srcbyte[2]) << (7-(x&7)) );
756 srcbyte+=bytes_per_pixel;
765 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
766 dstbits += linebytes;
777 unsigned long white = (1 << bmpImage->bits_per_pixel) - 1;
779 /* ==== any bmp format -> pal 1 dib ==== */
780 if ((unsigned)colors[0].rgbRed+colors[0].rgbGreen+colors[0].rgbBlue >=
781 (unsigned)colors[1].rgbRed+colors[1].rgbGreen+colors[1].rgbBlue )
784 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
785 "%s color mapping\n",
786 bmpImage->bits_per_pixel, bmpImage->red_mask,
787 bmpImage->green_mask, bmpImage->blue_mask,
788 neg?"negative":"direct" );
790 for (h=lines-1; h>=0; h--) {
794 for (x=0; x<width; x++) {
795 dstval|=((XGetPixel( bmpImage, x, h) >= white) ^ neg) << (7 - (x&7));
804 dstbits += linebytes;
811 /***********************************************************************
812 * X11DRV_DIB_SetImageBits_4
814 * SetDIBits for a 4-bit deep DIB.
816 static void X11DRV_DIB_SetImageBits_4( int lines, const BYTE *srcbits,
817 DWORD srcwidth, DWORD dstwidth, int left,
818 int *colors, XImage *bmpImage, int linebytes)
826 srcbits = srcbits + linebytes * (lines - 1);
827 linebytes = -linebytes;
834 srcbits += left >> 1;
835 width = min(srcwidth, dstwidth);
837 /* ==== pal 4 dib -> any bmp format ==== */
838 for (h = lines-1; h >= 0; h--) {
840 for (i = width/2, x = left; i > 0; i--) {
841 BYTE srcval=*srcbyte++;
842 XPutPixel( bmpImage, x++, h, colors[srcval >> 4] );
843 XPutPixel( bmpImage, x++, h, colors[srcval & 0x0f] );
846 XPutPixel( bmpImage, x, h, colors[*srcbyte >> 4] );
847 srcbits += linebytes;
853 /***********************************************************************
854 * X11DRV_DIB_GetImageBits_4
856 * GetDIBits for a 4-bit deep DIB.
858 static void X11DRV_DIB_GetImageBits_4( int lines, BYTE *dstbits,
859 DWORD srcwidth, DWORD dstwidth,
860 RGBQUAD *colors, PALETTEENTRY *srccolors,
861 XImage *bmpImage, int linebytes )
864 int h, width = min(srcwidth, dstwidth);
869 dstbits = dstbits + ( linebytes * (lines-1) );
870 linebytes = -linebytes;
873 switch (bmpImage->depth) {
876 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
878 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
881 for (h = lines-1; h >= 0; h--) {
885 for (x = 0; x < width; x++) {
887 srcval=srccolors[XGetPixel(bmpImage, x, h)];
888 dstval|=(X11DRV_DIB_GetNearestIndex
892 srcval.peBlue) << (4-((x&1)<<2)));
901 dstbits += linebytes;
909 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
911 /* ==== pal 8 bmp -> pal 4 dib ==== */
913 const BYTE *srcpixel;
916 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
917 for (h=0; h<lines; h++) {
922 for (x=0; x<width; x++) {
924 srcval = srccolors[*srcpixel++];
925 dstval|=(X11DRV_DIB_GetNearestIndex
929 srcval.peBlue) << (4*(1-(x&1))) );
938 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
939 dstbits += linebytes;
950 const WORD* srcpixel;
953 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
955 if (bmpImage->green_mask==0x03e0) {
956 if (bmpImage->red_mask==0x7c00) {
957 /* ==== rgb 555 bmp -> pal 4 dib ==== */
958 for (h=0; h<lines; h++) {
963 for (x=0; x<width; x++) {
966 dstval|=(X11DRV_DIB_GetNearestIndex
968 ((srcval >> 7) & 0xf8) | /* r */
969 ((srcval >> 12) & 0x07),
970 ((srcval >> 2) & 0xf8) | /* g */
971 ((srcval >> 7) & 0x07),
972 ((srcval << 3) & 0xf8) | /* b */
973 ((srcval >> 2) & 0x07) ) << ((1-(x&1))<<2) );
982 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
983 dstbits += linebytes;
985 } else if (bmpImage->blue_mask==0x7c00) {
986 /* ==== bgr 555 bmp -> pal 4 dib ==== */
987 for (h=0; h<lines; h++) {
992 for (x=0; x<width; x++) {
995 dstval|=(X11DRV_DIB_GetNearestIndex
997 ((srcval << 3) & 0xf8) | /* r */
998 ((srcval >> 2) & 0x07),
999 ((srcval >> 2) & 0xf8) | /* g */
1000 ((srcval >> 7) & 0x07),
1001 ((srcval >> 7) & 0xf8) | /* b */
1002 ((srcval >> 12) & 0x07) ) << ((1-(x&1))<<2) );
1011 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1012 dstbits += linebytes;
1017 } else if (bmpImage->green_mask==0x07e0) {
1018 if (bmpImage->red_mask==0xf800) {
1019 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1020 for (h=0; h<lines; h++) {
1025 for (x=0; x<width; x++) {
1028 dstval|=(X11DRV_DIB_GetNearestIndex
1030 ((srcval >> 8) & 0xf8) | /* r */
1031 ((srcval >> 13) & 0x07),
1032 ((srcval >> 3) & 0xfc) | /* g */
1033 ((srcval >> 9) & 0x03),
1034 ((srcval << 3) & 0xf8) | /* b */
1035 ((srcval >> 2) & 0x07) ) << ((1-(x&1))<<2) );
1044 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1045 dstbits += linebytes;
1047 } else if (bmpImage->blue_mask==0xf800) {
1048 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1049 for (h=0; h<lines; h++) {
1054 for (x=0; x<width; x++) {
1057 dstval|=(X11DRV_DIB_GetNearestIndex
1059 ((srcval << 3) & 0xf8) | /* r */
1060 ((srcval >> 2) & 0x07),
1061 ((srcval >> 3) & 0xfc) | /* g */
1062 ((srcval >> 9) & 0x03),
1063 ((srcval >> 8) & 0xf8) | /* b */
1064 ((srcval >> 13) & 0x07) ) << ((1-(x&1))<<2) );
1073 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1074 dstbits += linebytes;
1086 if (bmpImage->bits_per_pixel==24) {
1087 const void* srcbits;
1088 const BYTE *srcbyte;
1091 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1093 if (bmpImage->green_mask!=0x00ff00 ||
1094 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1096 } else if (bmpImage->blue_mask==0xff) {
1097 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1098 for (h=0; h<lines; h++) {
1101 for (x=0; x<width/2; x++) {
1102 /* Do 2 pixels at a time */
1103 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1108 X11DRV_DIB_GetNearestIndex
1116 /* And then the odd pixel */
1117 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1123 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1124 dstbits += linebytes;
1127 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1128 for (h=0; h<lines; h++) {
1131 for (x=0; x<width/2; x++) {
1132 /* Do 2 pixels at a time */
1133 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1138 X11DRV_DIB_GetNearestIndex
1146 /* And then the odd pixel */
1147 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1153 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1154 dstbits += linebytes;
1163 const void* srcbits;
1164 const BYTE *srcbyte;
1167 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1169 if (bmpImage->green_mask!=0x00ff00 ||
1170 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1172 } else if (bmpImage->blue_mask==0xff) {
1173 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1174 for (h=0; h<lines; h++) {
1177 for (x=0; x<width/2; x++) {
1178 /* Do 2 pixels at a time */
1179 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1184 X11DRV_DIB_GetNearestIndex
1192 /* And then the odd pixel */
1193 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1199 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1200 dstbits += linebytes;
1203 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1204 for (h=0; h<lines; h++) {
1207 for (x=0; x<width/2; x++) {
1208 /* Do 2 pixels at a time */
1209 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1214 X11DRV_DIB_GetNearestIndex
1222 /* And then the odd pixel */
1223 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1229 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1230 dstbits += linebytes;
1241 /* ==== any bmp format -> pal 4 dib ==== */
1242 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1243 bmpImage->bits_per_pixel, bmpImage->red_mask,
1244 bmpImage->green_mask, bmpImage->blue_mask );
1245 for (h=lines-1; h>=0; h--) {
1247 for (x=0; x<(width & ~1); x+=2) {
1248 *dstbyte++=(X11DRV_DIB_MapColor((int*)colors, 16, XGetPixel(bmpImage, x, h), 0) << 4) |
1249 X11DRV_DIB_MapColor((int*)colors, 16, XGetPixel(bmpImage, x+1, h), 0);
1252 *dstbyte=(X11DRV_DIB_MapColor((int *)colors, 16, XGetPixel(bmpImage, x, h), 0) << 4);
1254 dstbits += linebytes;
1261 /***********************************************************************
1262 * X11DRV_DIB_SetImageBits_RLE4
1264 * SetDIBits for a 4-bit deep compressed DIB.
1266 static void X11DRV_DIB_SetImageBits_RLE4( int lines, const BYTE *bits,
1267 DWORD srcwidth, DWORD dstwidth,
1268 int left, int *colors,
1271 unsigned int x = 0, width = min(srcwidth, dstwidth);
1272 int y = lines - 1, c, length;
1273 const BYTE *begin = bits;
1278 if (length) { /* encoded */
1281 if (x >= (left + width)) break;
1282 if( x >= left) XPutPixel(bmpImage, x, y, colors[c >> 4]);
1284 if (!length--) break;
1285 if (x >= (left + width)) break;
1286 if( x >= left) XPutPixel(bmpImage, x, y, colors[c & 0xf]);
1306 default: /* absolute */
1309 if (x >= left && x < (left + width))
1310 XPutPixel(bmpImage, x, y, colors[c >> 4]);
1312 if (!length--) break;
1313 if (x >= left && x < (left + width))
1314 XPutPixel(bmpImage, x, y, colors[c & 0xf]);
1317 if ((bits - begin) & 1)
1326 /***********************************************************************
1327 * X11DRV_DIB_SetImageBits_8
1329 * SetDIBits for an 8-bit deep DIB.
1331 static void X11DRV_DIB_SetImageBits_8( int lines, const BYTE *srcbits,
1332 DWORD srcwidth, DWORD dstwidth, int left,
1333 const int *colors, XImage *bmpImage,
1337 int h, width = min(srcwidth, dstwidth);
1338 const BYTE* srcbyte;
1344 srcbits = srcbits + linebytes * (lines-1);
1345 linebytes = -linebytes;
1350 switch (bmpImage->depth) {
1353 /* Some X servers might have 32 bit/ 16bit deep pixel */
1354 if (lines && width && (bmpImage->bits_per_pixel == 16) &&
1355 (ImageByteOrder(gdi_display)==LSBFirst) )
1357 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1358 dstbits=(BYTE*)bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line;
1359 for (h = lines ; h--; ) {
1360 #if defined(__i386__) && defined(__GNUC__)
1361 int _cl1,_cl2; /* temp outputs for asm below */
1362 /* Borrowed from DirectDraw */
1363 __asm__ __volatile__(
1368 " movw (%%edx,%%eax,4),%%ax\n"
1370 " xor %%eax,%%eax\n"
1372 :"=S" (srcbyte), "=D" (_cl1), "=c" (_cl2)
1377 :"eax", "cc", "memory"
1380 DWORD* dstpixel=(DWORD*)dstbits;
1381 for (x=0; x<width/2; x++) {
1382 /* Do 2 pixels at a time */
1383 *dstpixel++=(colors[srcbyte[1]] << 16) | colors[srcbyte[0]];
1387 /* And then the odd pixel */
1388 *((WORD*)dstpixel)=colors[srcbyte[0]];
1391 srcbyte = (srcbits += linebytes);
1392 dstbits -= bmpImage->bytes_per_line;
1399 if (lines && width && (bmpImage->bits_per_pixel == 32) &&
1400 (ImageByteOrder(gdi_display)==LSBFirst) )
1402 dstbits=(BYTE*)bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line;
1403 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1404 for (h = lines ; h--; ) {
1405 #if defined(__i386__) && defined(__GNUC__)
1406 int _cl1,_cl2; /* temp outputs for asm below */
1407 /* Borrowed from DirectDraw */
1408 __asm__ __volatile__(
1413 " movl (%%edx,%%eax,4),%%eax\n"
1415 " xor %%eax,%%eax\n"
1417 :"=S" (srcbyte), "=D" (_cl1), "=c" (_cl2)
1422 :"eax", "cc", "memory"
1425 DWORD* dstpixel=(DWORD*)dstbits;
1426 for (x=0; x<width; x++) {
1427 *dstpixel++=colors[*srcbyte++];
1430 srcbyte = (srcbits += linebytes);
1431 dstbits -= bmpImage->bytes_per_line;
1437 break; /* use slow generic case below */
1440 /* ==== pal 8 dib -> any bmp format ==== */
1441 for (h=lines-1; h>=0; h--) {
1442 for (x=left; x<width+left; x++) {
1443 XPutPixel(bmpImage, x, h, colors[*srcbyte++]);
1445 srcbyte = (srcbits += linebytes);
1449 /***********************************************************************
1450 * X11DRV_DIB_GetImageBits_8
1452 * GetDIBits for an 8-bit deep DIB.
1454 static void X11DRV_DIB_GetImageBits_8( int lines, BYTE *dstbits,
1455 DWORD srcwidth, DWORD dstwidth,
1456 RGBQUAD *colors, PALETTEENTRY *srccolors,
1457 XImage *bmpImage, int linebytes )
1460 int h, width = min(srcwidth, dstwidth);
1466 dstbits = dstbits + ( linebytes * (lines-1) );
1467 linebytes = -linebytes;
1472 * This condition is true when GetImageBits has been called by
1473 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1474 * 256 colormaps, so we'll just use it for GetDIBits calls.
1475 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1477 if (!srccolors) goto updatesection;
1479 switch (bmpImage->depth) {
1482 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
1485 /* ==== pal 1 bmp -> pal 8 dib ==== */
1486 /* ==== pal 4 bmp -> pal 8 dib ==== */
1487 for (h=lines-1; h>=0; h--) {
1489 for (x=0; x<width; x++) {
1490 PALETTEENTRY srcval;
1491 srcval=srccolors[XGetPixel(bmpImage, x, h)];
1492 *dstbyte++=X11DRV_DIB_GetNearestIndex(colors, 256,
1497 dstbits += linebytes;
1505 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
1507 /* ==== pal 8 bmp -> pal 8 dib ==== */
1508 const void* srcbits;
1509 const BYTE* srcpixel;
1511 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1512 for (h=0; h<lines; h++) {
1515 for (x = 0; x < width; x++) {
1516 PALETTEENTRY srcval;
1517 srcval=srccolors[*srcpixel++];
1518 *dstbyte++=X11DRV_DIB_GetNearestIndex(colors, 256,
1523 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1524 dstbits += linebytes;
1534 const void* srcbits;
1535 const WORD* srcpixel;
1538 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1540 if (bmpImage->green_mask==0x03e0) {
1541 if (bmpImage->red_mask==0x7c00) {
1542 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1543 for (h=0; h<lines; h++) {
1546 for (x=0; x<width; x++) {
1549 *dstbyte++=X11DRV_DIB_GetNearestIndex
1551 ((srcval >> 7) & 0xf8) | /* r */
1552 ((srcval >> 12) & 0x07),
1553 ((srcval >> 2) & 0xf8) | /* g */
1554 ((srcval >> 7) & 0x07),
1555 ((srcval << 3) & 0xf8) | /* b */
1556 ((srcval >> 2) & 0x07) );
1558 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1559 dstbits += linebytes;
1561 } else if (bmpImage->blue_mask==0x7c00) {
1562 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1563 for (h=0; h<lines; h++) {
1566 for (x=0; x<width; x++) {
1569 *dstbyte++=X11DRV_DIB_GetNearestIndex
1571 ((srcval << 3) & 0xf8) | /* r */
1572 ((srcval >> 2) & 0x07),
1573 ((srcval >> 2) & 0xf8) | /* g */
1574 ((srcval >> 7) & 0x07),
1575 ((srcval >> 7) & 0xf8) | /* b */
1576 ((srcval >> 12) & 0x07) );
1578 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1579 dstbits += linebytes;
1584 } else if (bmpImage->green_mask==0x07e0) {
1585 if (bmpImage->red_mask==0xf800) {
1586 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1587 for (h=0; h<lines; h++) {
1590 for (x=0; x<width; x++) {
1593 *dstbyte++=X11DRV_DIB_GetNearestIndex
1595 ((srcval >> 8) & 0xf8) | /* r */
1596 ((srcval >> 13) & 0x07),
1597 ((srcval >> 3) & 0xfc) | /* g */
1598 ((srcval >> 9) & 0x03),
1599 ((srcval << 3) & 0xf8) | /* b */
1600 ((srcval >> 2) & 0x07) );
1602 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1603 dstbits += linebytes;
1605 } else if (bmpImage->blue_mask==0xf800) {
1606 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1607 for (h=0; h<lines; h++) {
1610 for (x=0; x<width; x++) {
1613 *dstbyte++=X11DRV_DIB_GetNearestIndex
1615 ((srcval << 3) & 0xf8) | /* r */
1616 ((srcval >> 2) & 0x07),
1617 ((srcval >> 3) & 0xfc) | /* g */
1618 ((srcval >> 9) & 0x03),
1619 ((srcval >> 8) & 0xf8) | /* b */
1620 ((srcval >> 13) & 0x07) );
1622 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1623 dstbits += linebytes;
1637 const void* srcbits;
1638 const BYTE *srcbyte;
1640 int bytes_per_pixel;
1642 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1643 bytes_per_pixel=(bmpImage->bits_per_pixel==24?3:4);
1645 if (bmpImage->green_mask!=0x00ff00 ||
1646 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1648 } else if (bmpImage->blue_mask==0xff) {
1649 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1650 for (h=0; h<lines; h++) {
1653 for (x=0; x<width; x++) {
1654 *dstbyte++=X11DRV_DIB_GetNearestIndex
1659 srcbyte+=bytes_per_pixel;
1661 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1662 dstbits += linebytes;
1665 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1666 for (h=0; h<lines; h++) {
1669 for (x=0; x<width; x++) {
1670 *dstbyte++=X11DRV_DIB_GetNearestIndex
1675 srcbyte+=bytes_per_pixel;
1677 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1678 dstbits += linebytes;
1686 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1687 bmpImage->depth, bmpImage->red_mask,
1688 bmpImage->green_mask, bmpImage->blue_mask );
1690 /* ==== any bmp format -> pal 8 dib ==== */
1691 for (h=lines-1; h>=0; h--) {
1693 for (x=0; x<width; x++) {
1694 *dstbyte=X11DRV_DIB_MapColor
1696 XGetPixel(bmpImage, x, h), *dstbyte);
1699 dstbits += linebytes;
1705 /***********************************************************************
1706 * X11DRV_DIB_SetImageBits_RLE8
1708 * SetDIBits for an 8-bit deep compressed DIB.
1710 * This function rewritten 941113 by James Youngman. WINE blew out when I
1711 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1713 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1714 * 'End of bitmap' escape code. This code is very much laxer in what it
1715 * allows to end the expansion. Possibly too lax. See the note by
1716 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1717 * bitmap should end with RleEnd, but on the other hand, software exists
1718 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1721 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1722 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1725 static void X11DRV_DIB_SetImageBits_RLE8( int lines, const BYTE *bits,
1726 DWORD srcwidth, DWORD dstwidth,
1727 int left, int *colors,
1730 unsigned int x; /* X-position on each line. Increases. */
1731 int y; /* Line #. Starts at lines-1, decreases */
1732 const BYTE *pIn = bits; /* Pointer to current position in bits */
1733 BYTE length; /* The length pf a run */
1734 BYTE escape_code; /* See enum Rle8_EscapeCodes.*/
1737 * Note that the bitmap data is stored by Windows starting at the
1738 * bottom line of the bitmap and going upwards. Within each line,
1739 * the data is stored left-to-right. That's the reason why line
1740 * goes from lines-1 to 0. [JAY]
1750 * If the length byte is not zero (which is the escape value),
1751 * We have a run of length pixels all the same colour. The colour
1752 * index is stored next.
1754 * If the length byte is zero, we need to read the next byte to
1755 * know what to do. [JAY]
1760 * [Run-Length] Encoded mode
1762 int color = colors[*pIn++];
1763 while (length-- && x < (left + dstwidth)) {
1764 if( x >= left) XPutPixel(bmpImage, x, y, color);
1771 * Escape codes (may be an absolute sequence though)
1773 escape_code = (*pIn++);
1782 /* Not all RLE8 bitmaps end with this code. For
1783 * example, Paint Shop Pro produces some that don't.
1784 * That's (I think) what caused the previous
1785 * implementation to fail. [JAY]
1794 default: /* switch to absolute mode */
1795 length = escape_code;
1798 int color = colors[*pIn++];
1799 if (x >= (left + dstwidth))
1804 if( x >= left) XPutPixel(bmpImage, x, y, color);
1808 * If you think for a moment you'll realise that the
1809 * only time we could ever possibly read an odd
1810 * number of bytes is when there is a 0x00 (escape),
1811 * a value >0x02 (absolute mode) and then an odd-
1812 * length run. Therefore this is the only place we
1813 * need to worry about it. Everywhere else the
1814 * bytes are always read in pairs. [JAY]
1816 if (escape_code & 1) pIn++; /* Throw away the pad byte. */
1818 } /* switch (escape_code) : Escape sequence */
1824 /***********************************************************************
1825 * X11DRV_DIB_SetImageBits_16
1827 * SetDIBits for a 16-bit deep DIB.
1829 static void X11DRV_DIB_SetImageBits_16( int lines, const BYTE *srcbits,
1830 DWORD srcwidth, DWORD dstwidth, int left,
1831 X11DRV_PDEVICE *physDev, DWORD rSrc, DWORD gSrc, DWORD bSrc,
1832 XImage *bmpImage, int linebytes )
1835 int h, width = min(srcwidth, dstwidth);
1836 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap;
1841 srcbits = srcbits + ( linebytes * (lines-1));
1842 linebytes = -linebytes;
1845 switch (bmpImage->depth)
1852 srcbits=srcbits+left*2;
1853 dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line;
1855 if (bmpImage->green_mask==0x03e0) {
1856 if (gSrc==bmpImage->green_mask) {
1857 if (rSrc==bmpImage->red_mask) {
1858 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1859 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1860 convs->Convert_5x5_asis
1863 dstbits,-bmpImage->bytes_per_line);
1864 } else if (rSrc==bmpImage->blue_mask) {
1865 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1866 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1867 convs->Convert_555_reverse
1870 dstbits,-bmpImage->bytes_per_line);
1873 if (rSrc==bmpImage->red_mask || bSrc==bmpImage->blue_mask) {
1874 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1875 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1876 convs->Convert_565_to_555_asis
1879 dstbits,-bmpImage->bytes_per_line);
1881 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1882 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1883 convs->Convert_565_to_555_reverse
1886 dstbits,-bmpImage->bytes_per_line);
1889 } else if (bmpImage->green_mask==0x07e0) {
1890 if (gSrc==bmpImage->green_mask) {
1891 if (rSrc==bmpImage->red_mask) {
1892 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
1893 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
1894 convs->Convert_5x5_asis
1897 dstbits,-bmpImage->bytes_per_line);
1899 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
1900 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
1901 convs->Convert_565_reverse
1904 dstbits,-bmpImage->bytes_per_line);
1907 if (rSrc==bmpImage->red_mask || bSrc==bmpImage->blue_mask) {
1908 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
1909 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
1910 convs->Convert_555_to_565_asis
1913 dstbits,-bmpImage->bytes_per_line);
1915 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
1916 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
1917 convs->Convert_555_to_565_reverse
1920 dstbits,-bmpImage->bytes_per_line);
1930 if (bmpImage->bits_per_pixel==24) {
1933 srcbits=srcbits+left*2;
1934 dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line;
1936 if (bmpImage->green_mask!=0x00ff00 ||
1937 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1939 } else if ((rSrc==0x1f && bmpImage->red_mask==0xff) ||
1940 (bSrc==0x1f && bmpImage->blue_mask==0xff)) {
1942 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
1943 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
1944 convs->Convert_555_to_888_asis
1947 dstbits,-bmpImage->bytes_per_line);
1949 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
1950 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
1951 convs->Convert_565_to_888_asis
1954 dstbits,-bmpImage->bytes_per_line);
1958 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
1959 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
1960 convs->Convert_555_to_888_reverse
1963 dstbits,-bmpImage->bytes_per_line);
1965 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
1966 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
1967 convs->Convert_565_to_888_reverse
1970 dstbits,-bmpImage->bytes_per_line);
1981 srcbits=srcbits+left*2;
1982 dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line;
1984 if (bmpImage->green_mask!=0x00ff00 ||
1985 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1987 } else if ((rSrc==0x1f && bmpImage->red_mask==0xff) ||
1988 (bSrc==0x1f && bmpImage->blue_mask==0xff)) {
1990 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
1991 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
1992 convs->Convert_555_to_0888_asis
1995 dstbits,-bmpImage->bytes_per_line);
1997 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
1998 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
1999 convs->Convert_565_to_0888_asis
2002 dstbits,-bmpImage->bytes_per_line);
2006 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2007 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2008 convs->Convert_555_to_0888_reverse
2011 dstbits,-bmpImage->bytes_per_line);
2013 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2014 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2015 convs->Convert_565_to_0888_reverse
2018 dstbits,-bmpImage->bytes_per_line);
2026 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2027 rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask,
2028 bmpImage->green_mask, bmpImage->blue_mask );
2034 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2035 const WORD* srcpixel;
2036 int rShift1,gShift1,bShift1;
2037 int rShift2,gShift2,bShift2;
2040 /* Set color scaling values */
2041 rShift1=16+X11DRV_DIB_MaskToShift(rSrc)-3;
2042 gShift1=16+X11DRV_DIB_MaskToShift(gSrc)-3;
2043 bShift1=16+X11DRV_DIB_MaskToShift(bSrc)-3;
2048 /* Green has 5 bits, like the others */
2052 /* Green has 6 bits, not 5. Compensate. */
2061 /* We could split it into four separate cases to optimize
2062 * but it is probably not worth it.
2064 for (h=lines-1; h>=0; h--) {
2065 srcpixel=(const WORD*)srcbits;
2066 for (x=left; x<width+left; x++) {
2068 BYTE red,green,blue;
2069 srcval=*srcpixel++ << 16;
2070 red= ((srcval >> rShift1) & 0xf8) |
2071 ((srcval >> rShift2) & 0x07);
2072 green=((srcval >> gShift1) & gMask1) |
2073 ((srcval >> gShift2) & gMask2);
2074 blue= ((srcval >> bShift1) & 0xf8) |
2075 ((srcval >> bShift2) & 0x07);
2076 XPutPixel(bmpImage, x, h,
2077 X11DRV_PALETTE_ToPhysical
2078 (physDev, RGB(red,green,blue)));
2080 srcbits += linebytes;
2088 /***********************************************************************
2089 * X11DRV_DIB_GetImageBits_16
2091 * GetDIBits for an 16-bit deep DIB.
2093 static void X11DRV_DIB_GetImageBits_16( X11DRV_PDEVICE *physDev, int lines, BYTE *dstbits,
2094 DWORD dstwidth, DWORD srcwidth,
2095 PALETTEENTRY *srccolors,
2096 DWORD rDst, DWORD gDst, DWORD bDst,
2097 XImage *bmpImage, int linebytes )
2100 int h, width = min(srcwidth, dstwidth);
2101 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap;
2106 dstbits = dstbits + ( linebytes * (lines-1));
2107 linebytes = -linebytes;
2110 switch (bmpImage->depth)
2115 const char* srcbits;
2117 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2119 if (bmpImage->green_mask==0x03e0) {
2120 if (gDst==bmpImage->green_mask) {
2121 if (rDst==bmpImage->red_mask) {
2122 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2123 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2124 convs->Convert_5x5_asis
2126 srcbits,-bmpImage->bytes_per_line,
2129 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2130 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2131 convs->Convert_555_reverse
2133 srcbits,-bmpImage->bytes_per_line,
2137 if (rDst==bmpImage->red_mask || bDst==bmpImage->blue_mask) {
2138 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2139 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2140 convs->Convert_555_to_565_asis
2142 srcbits,-bmpImage->bytes_per_line,
2145 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2146 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2147 convs->Convert_555_to_565_reverse
2149 srcbits,-bmpImage->bytes_per_line,
2153 } else if (bmpImage->green_mask==0x07e0) {
2154 if (gDst==bmpImage->green_mask) {
2155 if (rDst == bmpImage->red_mask) {
2156 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2157 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2158 convs->Convert_5x5_asis
2160 srcbits,-bmpImage->bytes_per_line,
2163 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2164 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2165 convs->Convert_565_reverse
2167 srcbits,-bmpImage->bytes_per_line,
2171 if (rDst==bmpImage->red_mask || bDst==bmpImage->blue_mask) {
2172 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2173 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2174 convs->Convert_565_to_555_asis
2176 srcbits,-bmpImage->bytes_per_line,
2179 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2180 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2181 convs->Convert_565_to_555_reverse
2183 srcbits,-bmpImage->bytes_per_line,
2194 if (bmpImage->bits_per_pixel == 24) {
2195 const char* srcbits;
2197 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2199 if (bmpImage->green_mask!=0x00ff00 ||
2200 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2202 } else if ((rDst==0x1f && bmpImage->red_mask==0xff) ||
2203 (bDst==0x1f && bmpImage->blue_mask==0xff)) {
2205 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2206 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2207 convs->Convert_888_to_555_asis
2209 srcbits,-bmpImage->bytes_per_line,
2212 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2213 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2214 convs->Convert_888_to_565_asis
2216 srcbits,-bmpImage->bytes_per_line,
2221 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2222 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2223 convs->Convert_888_to_555_reverse
2225 srcbits,-bmpImage->bytes_per_line,
2228 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2229 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2230 convs->Convert_888_to_565_reverse
2232 srcbits,-bmpImage->bytes_per_line,
2242 const char* srcbits;
2244 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2246 if (bmpImage->green_mask!=0x00ff00 ||
2247 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2249 } else if ((rDst==0x1f && bmpImage->red_mask==0xff) ||
2250 (bDst==0x1f && bmpImage->blue_mask==0xff)) {
2252 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2253 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2254 convs->Convert_0888_to_555_asis
2256 srcbits,-bmpImage->bytes_per_line,
2259 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2260 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2261 convs->Convert_0888_to_565_asis
2263 srcbits,-bmpImage->bytes_per_line,
2268 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2269 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2270 convs->Convert_0888_to_555_reverse
2272 srcbits,-bmpImage->bytes_per_line,
2275 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2276 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2277 convs->Convert_0888_to_565_reverse
2279 srcbits,-bmpImage->bytes_per_line,
2288 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
2290 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2291 int rShift,gShift,bShift;
2294 /* Shift everything 16 bits left so that all shifts are >0,
2295 * even for BGR DIBs. Then a single >> 16 will bring everything
2298 rShift=16+X11DRV_DIB_MaskToShift(rDst)-3;
2299 gShift=16+X11DRV_DIB_MaskToShift(gDst)-3;
2300 bShift=16+X11DRV_DIB_MaskToShift(bDst)-3;
2302 /* 6 bits for the green */
2308 for (h = lines - 1; h >= 0; h--) {
2309 dstpixel=(LPWORD)dstbits;
2310 for (x = 0; x < width; x++) {
2311 PALETTEENTRY srcval;
2313 srcval=srccolors[XGetPixel(bmpImage, x, h)];
2314 dstval=((srcval.peRed << rShift) & rDst) |
2315 ((srcval.peGreen << gShift) & gDst) |
2316 ((srcval.peBlue << bShift) & bDst);
2317 *dstpixel++=dstval >> 16;
2319 dstbits += linebytes;
2327 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
2329 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2330 int rShift,gShift,bShift;
2331 const BYTE* srcbits;
2332 const BYTE* srcpixel;
2335 /* Shift everything 16 bits left so that all shifts are >0,
2336 * even for BGR DIBs. Then a single >> 16 will bring everything
2339 rShift=16+X11DRV_DIB_MaskToShift(rDst)-3;
2340 gShift=16+X11DRV_DIB_MaskToShift(gDst)-3;
2341 bShift=16+X11DRV_DIB_MaskToShift(bDst)-3;
2343 /* 6 bits for the green */
2349 srcbits=(BYTE*)bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2350 for (h=0; h<lines; h++) {
2352 dstpixel=(LPWORD)dstbits;
2353 for (x = 0; x < width; x++) {
2354 PALETTEENTRY srcval;
2356 srcval=srccolors[*srcpixel++];
2357 dstval=((srcval.peRed << rShift) & rDst) |
2358 ((srcval.peGreen << gShift) & gDst) |
2359 ((srcval.peBlue << bShift) & bDst);
2360 *dstpixel++=dstval >> 16;
2362 srcbits -= bmpImage->bytes_per_line;
2363 dstbits += linebytes;
2373 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2374 int rShift,gShift,bShift;
2377 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2378 bmpImage->depth, bmpImage->red_mask,
2379 bmpImage->green_mask, bmpImage->blue_mask,
2382 /* Shift everything 16 bits left so that all shifts are >0,
2383 * even for BGR DIBs. Then a single >> 16 will bring everything
2386 rShift=16+X11DRV_DIB_MaskToShift(rDst)-3;
2387 gShift=16+X11DRV_DIB_MaskToShift(gDst)-3;
2388 bShift=16+X11DRV_DIB_MaskToShift(bDst)-3;
2390 /* 6 bits for the green */
2396 for (h = lines - 1; h >= 0; h--) {
2397 dstpixel=(LPWORD)dstbits;
2398 for (x = 0; x < width; x++) {
2401 srcval=X11DRV_PALETTE_ToLogical(physDev, XGetPixel(bmpImage, x, h));
2402 dstval=((GetRValue(srcval) << rShift) & rDst) |
2403 ((GetGValue(srcval) << gShift) & gDst) |
2404 ((GetBValue(srcval) << bShift) & bDst);
2405 *dstpixel++=dstval >> 16;
2407 dstbits += linebytes;
2415 /***********************************************************************
2416 * X11DRV_DIB_SetImageBits_24
2418 * SetDIBits for a 24-bit deep DIB.
2420 static void X11DRV_DIB_SetImageBits_24( int lines, const BYTE *srcbits,
2421 DWORD srcwidth, DWORD dstwidth, int left,
2422 X11DRV_PDEVICE *physDev,
2423 DWORD rSrc, DWORD gSrc, DWORD bSrc,
2424 XImage *bmpImage, DWORD linebytes )
2427 int h, width = min(srcwidth, dstwidth);
2428 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap;
2433 srcbits = srcbits + linebytes * (lines - 1);
2434 linebytes = -linebytes;
2437 switch (bmpImage->depth)
2440 if (bmpImage->bits_per_pixel==24) {
2443 srcbits=srcbits+left*3;
2444 dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line;
2446 if (bmpImage->green_mask!=0x00ff00 ||
2447 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2449 } else if (rSrc==bmpImage->red_mask) {
2450 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2451 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2452 convs->Convert_888_asis
2455 dstbits,-bmpImage->bytes_per_line);
2457 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2458 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2459 convs->Convert_888_reverse
2462 dstbits,-bmpImage->bytes_per_line);
2472 srcbits=srcbits+left*3;
2473 dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line;
2475 if (bmpImage->green_mask!=0x00ff00 ||
2476 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2478 } else if (rSrc==bmpImage->red_mask) {
2479 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2480 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2481 convs->Convert_888_to_0888_asis
2484 dstbits,-bmpImage->bytes_per_line);
2486 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2487 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2488 convs->Convert_888_to_0888_reverse
2491 dstbits,-bmpImage->bytes_per_line);
2501 srcbits=srcbits+left*3;
2502 dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line;
2504 if (bmpImage->green_mask==0x03e0) {
2505 if ((rSrc==0xff0000 && bmpImage->red_mask==0x7f00) ||
2506 (bSrc==0xff0000 && bmpImage->blue_mask==0x7f00)) {
2507 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2508 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2509 convs->Convert_888_to_555_asis
2512 dstbits,-bmpImage->bytes_per_line);
2513 } else if ((rSrc==0xff && bmpImage->red_mask==0x7f00) ||
2514 (bSrc==0xff && bmpImage->blue_mask==0x7f00)) {
2515 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2516 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2517 convs->Convert_888_to_555_reverse
2520 dstbits,-bmpImage->bytes_per_line);
2524 } else if (bmpImage->green_mask==0x07e0) {
2525 if ((rSrc==0xff0000 && bmpImage->red_mask==0xf800) ||
2526 (bSrc==0xff0000 && bmpImage->blue_mask==0xf800)) {
2527 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2528 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2529 convs->Convert_888_to_565_asis
2532 dstbits,-bmpImage->bytes_per_line);
2533 } else if ((rSrc==0xff && bmpImage->red_mask==0xf800) ||
2534 (bSrc==0xff && bmpImage->blue_mask==0xf800)) {
2535 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2536 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2537 convs->Convert_888_to_565_reverse
2540 dstbits,-bmpImage->bytes_per_line);
2552 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2553 rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask,
2554 bmpImage->green_mask, bmpImage->blue_mask );
2560 /* ==== rgb 888 dib -> any bmp format ==== */
2561 const BYTE* srcbyte;
2563 /* Windows only supports one 24bpp DIB format: RGB888 */
2565 for (h = lines - 1; h >= 0; h--) {
2567 for (x = left; x < width+left; x++) {
2568 XPutPixel(bmpImage, x, h,
2569 X11DRV_PALETTE_ToPhysical
2570 (physDev, RGB(srcbyte[2], srcbyte[1], srcbyte[0])));
2573 srcbits += linebytes;
2581 /***********************************************************************
2582 * X11DRV_DIB_GetImageBits_24
2584 * GetDIBits for an 24-bit deep DIB.
2586 static void X11DRV_DIB_GetImageBits_24( X11DRV_PDEVICE *physDev, int lines, BYTE *dstbits,
2587 DWORD dstwidth, DWORD srcwidth,
2588 PALETTEENTRY *srccolors,
2589 DWORD rDst, DWORD gDst, DWORD bDst,
2590 XImage *bmpImage, DWORD linebytes )
2593 int h, width = min(srcwidth, dstwidth);
2594 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap;
2599 dstbits = dstbits + ( linebytes * (lines-1) );
2600 linebytes = -linebytes;
2603 switch (bmpImage->depth)
2606 if (bmpImage->bits_per_pixel==24) {
2607 const char* srcbits;
2609 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2611 if (bmpImage->green_mask!=0x00ff00 ||
2612 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2614 } else if (rDst==bmpImage->red_mask) {
2615 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2616 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2617 convs->Convert_888_asis
2619 srcbits,-bmpImage->bytes_per_line,
2622 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2623 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2624 convs->Convert_888_reverse
2626 srcbits,-bmpImage->bytes_per_line,
2635 const char* srcbits;
2637 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2639 if (bmpImage->green_mask!=0x00ff00 ||
2640 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2642 } else if (rDst==bmpImage->red_mask) {
2643 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2644 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2645 convs->Convert_0888_to_888_asis
2647 srcbits,-bmpImage->bytes_per_line,
2650 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2651 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2652 convs->Convert_0888_to_888_reverse
2654 srcbits,-bmpImage->bytes_per_line,
2663 const char* srcbits;
2665 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2667 if (bmpImage->green_mask==0x03e0) {
2668 if ((rDst==0xff0000 && bmpImage->red_mask==0x7f00) ||
2669 (bDst==0xff0000 && bmpImage->blue_mask==0x7f00)) {
2670 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2671 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2672 convs->Convert_555_to_888_asis
2674 srcbits,-bmpImage->bytes_per_line,
2676 } else if ((rDst==0xff && bmpImage->red_mask==0x7f00) ||
2677 (bDst==0xff && bmpImage->blue_mask==0x7f00)) {
2678 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2679 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2680 convs->Convert_555_to_888_reverse
2682 srcbits,-bmpImage->bytes_per_line,
2687 } else if (bmpImage->green_mask==0x07e0) {
2688 if ((rDst==0xff0000 && bmpImage->red_mask==0xf800) ||
2689 (bDst==0xff0000 && bmpImage->blue_mask==0xf800)) {
2690 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2691 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2692 convs->Convert_565_to_888_asis
2694 srcbits,-bmpImage->bytes_per_line,
2696 } else if ((rDst==0xff && bmpImage->red_mask==0xf800) ||
2697 (bDst==0xff && bmpImage->blue_mask==0xf800)) {
2698 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2699 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2700 convs->Convert_565_to_888_reverse
2702 srcbits,-bmpImage->bytes_per_line,
2715 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
2717 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2720 /* Windows only supports one 24bpp DIB format: rgb 888 */
2721 for (h = lines - 1; h >= 0; h--) {
2723 for (x = 0; x < width; x++) {
2724 PALETTEENTRY srcval;
2725 srcval=srccolors[XGetPixel(bmpImage, x, h)];
2726 dstbyte[0]=srcval.peBlue;
2727 dstbyte[1]=srcval.peGreen;
2728 dstbyte[2]=srcval.peRed;
2731 dstbits += linebytes;
2739 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
2741 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2742 const void* srcbits;
2743 const BYTE* srcpixel;
2746 /* Windows only supports one 24bpp DIB format: rgb 888 */
2747 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2748 for (h = lines - 1; h >= 0; h--) {
2751 for (x = 0; x < width; x++ ) {
2752 PALETTEENTRY srcval;
2753 srcval=srccolors[*srcpixel++];
2754 dstbyte[0]=srcval.peBlue;
2755 dstbyte[1]=srcval.peGreen;
2756 dstbyte[2]=srcval.peRed;
2759 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
2760 dstbits += linebytes;
2770 /* ==== any bmp format -> 888 dib ==== */
2773 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2774 bmpImage->depth, bmpImage->red_mask,
2775 bmpImage->green_mask, bmpImage->blue_mask,
2778 /* Windows only supports one 24bpp DIB format: rgb 888 */
2779 for (h = lines - 1; h >= 0; h--) {
2781 for (x = 0; x < width; x++) {
2782 COLORREF srcval=X11DRV_PALETTE_ToLogical
2783 (physDev, XGetPixel( bmpImage, x, h ));
2784 dstbyte[0]=GetBValue(srcval);
2785 dstbyte[1]=GetGValue(srcval);
2786 dstbyte[2]=GetRValue(srcval);
2789 dstbits += linebytes;
2797 /***********************************************************************
2798 * X11DRV_DIB_SetImageBits_32
2800 * SetDIBits for a 32-bit deep DIB.
2802 static void X11DRV_DIB_SetImageBits_32(int lines, const BYTE *srcbits,
2803 DWORD srcwidth, DWORD dstwidth, int left,
2804 X11DRV_PDEVICE *physDev,
2805 DWORD rSrc, DWORD gSrc, DWORD bSrc,
2810 int h, width = min(srcwidth, dstwidth);
2811 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap;
2816 srcbits = srcbits + ( linebytes * (lines-1) );
2817 linebytes = -linebytes;
2820 switch (bmpImage->depth)
2823 if (bmpImage->bits_per_pixel==24) {
2826 srcbits=srcbits+left*4;
2827 dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line;
2829 if (rSrc==bmpImage->red_mask && gSrc==bmpImage->green_mask && bSrc==bmpImage->blue_mask) {
2830 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2831 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2832 convs->Convert_0888_to_888_asis
2835 dstbits,-bmpImage->bytes_per_line);
2836 } else if (bmpImage->green_mask!=0x00ff00 ||
2837 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2839 /* the tests below assume sane bmpImage masks */
2840 } else if (rSrc==bmpImage->blue_mask && gSrc==bmpImage->green_mask && bSrc==bmpImage->red_mask) {
2841 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2842 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2843 convs->Convert_0888_to_888_reverse
2846 dstbits,-bmpImage->bytes_per_line);
2847 } else if (bmpImage->blue_mask==0xff) {
2848 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2849 convs->Convert_any0888_to_rgb888
2853 dstbits,-bmpImage->bytes_per_line);
2855 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2856 convs->Convert_any0888_to_bgr888
2860 dstbits,-bmpImage->bytes_per_line);
2870 srcbits=srcbits+left*4;
2871 dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line;
2873 if (gSrc==bmpImage->green_mask) {
2874 if (rSrc==bmpImage->red_mask && bSrc==bmpImage->blue_mask) {
2875 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2876 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2877 convs->Convert_0888_asis
2880 dstbits,-bmpImage->bytes_per_line);
2881 } else if (bmpImage->green_mask!=0x00ff00 ||
2882 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2884 /* the tests below assume sane bmpImage masks */
2885 } else if (rSrc==bmpImage->blue_mask && bSrc==bmpImage->red_mask) {
2886 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2887 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2888 convs->Convert_0888_reverse
2891 dstbits,-bmpImage->bytes_per_line);
2893 /* ==== any 0888 dib -> any 0888 bmp ==== */
2894 convs->Convert_0888_any
2898 dstbits,-bmpImage->bytes_per_line,
2899 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
2901 } else if (bmpImage->green_mask!=0x00ff00 ||
2902 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2904 /* the tests below assume sane bmpImage masks */
2906 /* ==== any 0888 dib -> any 0888 bmp ==== */
2907 convs->Convert_0888_any
2911 dstbits,-bmpImage->bytes_per_line,
2912 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
2922 srcbits=srcbits+left*4;
2923 dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line;
2925 if (rSrc==0xff0000 && gSrc==0x00ff00 && bSrc==0x0000ff) {
2926 if (bmpImage->green_mask==0x03e0) {
2927 if (bmpImage->red_mask==0x7f00) {
2928 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
2929 convs->Convert_0888_to_555_asis
2932 dstbits,-bmpImage->bytes_per_line);
2933 } else if (bmpImage->blue_mask==0x7f00) {
2934 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
2935 convs->Convert_0888_to_555_reverse
2938 dstbits,-bmpImage->bytes_per_line);
2942 } else if (bmpImage->green_mask==0x07e0) {
2943 if (bmpImage->red_mask==0xf800) {
2944 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
2945 convs->Convert_0888_to_565_asis
2948 dstbits,-bmpImage->bytes_per_line);
2949 } else if (bmpImage->blue_mask==0xf800) {
2950 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
2951 convs->Convert_0888_to_565_reverse
2954 dstbits,-bmpImage->bytes_per_line);
2961 } else if (rSrc==0x0000ff && gSrc==0x00ff00 && bSrc==0xff0000) {
2962 if (bmpImage->green_mask==0x03e0) {
2963 if (bmpImage->blue_mask==0x7f00) {
2964 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
2965 convs->Convert_0888_to_555_asis
2968 dstbits,-bmpImage->bytes_per_line);
2969 } else if (bmpImage->red_mask==0x7f00) {
2970 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
2971 convs->Convert_0888_to_555_reverse
2974 dstbits,-bmpImage->bytes_per_line);
2978 } else if (bmpImage->green_mask==0x07e0) {
2979 if (bmpImage->blue_mask==0xf800) {
2980 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
2981 convs->Convert_0888_to_565_asis
2984 dstbits,-bmpImage->bytes_per_line);
2985 } else if (bmpImage->red_mask==0xf800) {
2986 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
2987 convs->Convert_0888_to_565_reverse
2990 dstbits,-bmpImage->bytes_per_line);
2998 if (bmpImage->green_mask==0x03e0 &&
2999 (bmpImage->red_mask==0x7f00 ||
3000 bmpImage->blue_mask==0x7f00)) {
3001 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3002 convs->Convert_any0888_to_5x5
3006 dstbits,-bmpImage->bytes_per_line,
3007 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
3008 } else if (bmpImage->green_mask==0x07e0 &&
3009 (bmpImage->red_mask==0xf800 ||
3010 bmpImage->blue_mask==0xf800)) {
3011 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3012 convs->Convert_any0888_to_5x5
3016 dstbits,-bmpImage->bytes_per_line,
3017 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
3027 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3028 rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask,
3029 bmpImage->green_mask, bmpImage->blue_mask );
3035 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3036 const DWORD* srcpixel;
3037 int rShift,gShift,bShift;
3039 rShift=X11DRV_DIB_MaskToShift(rSrc);
3040 gShift=X11DRV_DIB_MaskToShift(gSrc);
3041 bShift=X11DRV_DIB_MaskToShift(bSrc);
3043 for (h = lines - 1; h >= 0; h--) {
3044 srcpixel=(const DWORD*)srcbits;
3045 for (x = left; x < width+left; x++) {
3047 BYTE red,green,blue;
3048 srcvalue=*srcpixel++;
3049 red= (srcvalue >> rShift) & 0xff;
3050 green=(srcvalue >> gShift) & 0xff;
3051 blue= (srcvalue >> bShift) & 0xff;
3052 XPutPixel(bmpImage, x, h, X11DRV_PALETTE_ToPhysical
3053 (physDev, RGB(red,green,blue)));
3055 srcbits += linebytes;
3063 /***********************************************************************
3064 * X11DRV_DIB_GetImageBits_32
3066 * GetDIBits for an 32-bit deep DIB.
3068 static void X11DRV_DIB_GetImageBits_32( X11DRV_PDEVICE *physDev, int lines, BYTE *dstbits,
3069 DWORD dstwidth, DWORD srcwidth,
3070 PALETTEENTRY *srccolors,
3071 DWORD rDst, DWORD gDst, DWORD bDst,
3072 XImage *bmpImage, int linebytes )
3075 int h, width = min(srcwidth, dstwidth);
3076 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap;
3081 dstbits = dstbits + ( linebytes * (lines-1) );
3082 linebytes = -linebytes;
3085 switch (bmpImage->depth)
3088 if (bmpImage->bits_per_pixel==24) {
3089 const void* srcbits;
3091 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
3093 if (rDst==bmpImage->red_mask && gDst==bmpImage->green_mask && bDst==bmpImage->blue_mask) {
3094 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3095 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3096 convs->Convert_888_to_0888_asis
3098 srcbits,-bmpImage->bytes_per_line,
3100 } else if (bmpImage->green_mask!=0x00ff00 ||
3101 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
3103 /* the tests below assume sane bmpImage masks */
3104 } else if (rDst==bmpImage->blue_mask && gDst==bmpImage->green_mask && bDst==bmpImage->red_mask) {
3105 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3106 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3107 convs->Convert_888_to_0888_reverse
3109 srcbits,-bmpImage->bytes_per_line,
3111 } else if (bmpImage->blue_mask==0xff) {
3112 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3113 convs->Convert_rgb888_to_any0888
3115 srcbits,-bmpImage->bytes_per_line,
3119 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3120 convs->Convert_bgr888_to_any0888
3122 srcbits,-bmpImage->bytes_per_line,
3132 const char* srcbits;
3134 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
3136 if (gDst==bmpImage->green_mask) {
3137 if (rDst==bmpImage->red_mask && bDst==bmpImage->blue_mask) {
3138 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3139 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3140 convs->Convert_0888_asis
3142 srcbits,-bmpImage->bytes_per_line,
3144 } else if (bmpImage->green_mask!=0x00ff00 ||
3145 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
3147 /* the tests below assume sane bmpImage masks */
3148 } else if (rDst==bmpImage->blue_mask && bDst==bmpImage->red_mask) {
3149 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3150 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3151 convs->Convert_0888_reverse
3153 srcbits,-bmpImage->bytes_per_line,
3156 /* ==== any 0888 bmp -> any 0888 dib ==== */
3157 convs->Convert_0888_any
3159 srcbits,-bmpImage->bytes_per_line,
3160 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask,
3164 } else if (bmpImage->green_mask!=0x00ff00 ||
3165 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
3167 /* the tests below assume sane bmpImage masks */
3169 /* ==== any 0888 bmp -> any 0888 dib ==== */
3170 convs->Convert_0888_any
3172 srcbits,-bmpImage->bytes_per_line,
3173 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask,
3183 const char* srcbits;
3185 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
3187 if (rDst==0xff0000 && gDst==0x00ff00 && bDst==0x0000ff) {
3188 if (bmpImage->green_mask==0x03e0) {
3189 if (bmpImage->red_mask==0x7f00) {
3190 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3191 convs->Convert_555_to_0888_asis
3193 srcbits,-bmpImage->bytes_per_line,
3195 } else if (bmpImage->blue_mask==0x7f00) {
3196 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3197 convs->Convert_555_to_0888_reverse
3199 srcbits,-bmpImage->bytes_per_line,
3204 } else if (bmpImage->green_mask==0x07e0) {
3205 if (bmpImage->red_mask==0xf800) {
3206 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3207 convs->Convert_565_to_0888_asis
3209 srcbits,-bmpImage->bytes_per_line,
3211 } else if (bmpImage->blue_mask==0xf800) {
3212 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3213 convs->Convert_565_to_0888_reverse
3215 srcbits,-bmpImage->bytes_per_line,
3223 } else if (rDst==0x0000ff && gDst==0x00ff00 && bDst==0xff0000) {
3224 if (bmpImage->green_mask==0x03e0) {
3225 if (bmpImage->blue_mask==0x7f00) {
3226 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3227 convs->Convert_555_to_0888_asis
3229 srcbits,-bmpImage->bytes_per_line,
3231 } else if (bmpImage->red_mask==0x7f00) {
3232 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3233 convs->Convert_555_to_0888_reverse
3235 srcbits,-bmpImage->bytes_per_line,
3240 } else if (bmpImage->green_mask==0x07e0) {
3241 if (bmpImage->blue_mask==0xf800) {
3242 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3243 convs->Convert_565_to_0888_asis
3245 srcbits,-bmpImage->bytes_per_line,
3247 } else if (bmpImage->red_mask==0xf800) {
3248 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3249 convs->Convert_565_to_0888_reverse
3251 srcbits,-bmpImage->bytes_per_line,
3260 if (bmpImage->green_mask==0x03e0 &&
3261 (bmpImage->red_mask==0x7f00 ||
3262 bmpImage->blue_mask==0x7f00)) {
3263 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3264 convs->Convert_5x5_to_any0888
3266 srcbits,-bmpImage->bytes_per_line,
3267 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask,
3270 } else if (bmpImage->green_mask==0x07e0 &&
3271 (bmpImage->red_mask==0xf800 ||
3272 bmpImage->blue_mask==0xf800)) {
3273 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3274 convs->Convert_5x5_to_any0888
3276 srcbits,-bmpImage->bytes_per_line,
3277 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask,
3289 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
3291 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3292 int rShift,gShift,bShift;
3295 rShift=X11DRV_DIB_MaskToShift(rDst);
3296 gShift=X11DRV_DIB_MaskToShift(gDst);
3297 bShift=X11DRV_DIB_MaskToShift(bDst);
3298 for (h = lines - 1; h >= 0; h--) {
3299 dstpixel=(DWORD*)dstbits;
3300 for (x = 0; x < width; x++) {
3301 PALETTEENTRY srcval;
3302 srcval = srccolors[XGetPixel(bmpImage, x, h)];
3303 *dstpixel++=(srcval.peRed << rShift) |
3304 (srcval.peGreen << gShift) |
3305 (srcval.peBlue << bShift);
3307 dstbits += linebytes;
3315 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
3317 /* ==== pal 8 bmp -> any 0888 dib ==== */
3318 int rShift,gShift,bShift;
3319 const void* srcbits;
3320 const BYTE* srcpixel;
3323 rShift=X11DRV_DIB_MaskToShift(rDst);
3324 gShift=X11DRV_DIB_MaskToShift(gDst);
3325 bShift=X11DRV_DIB_MaskToShift(bDst);
3326 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
3327 for (h = lines - 1; h >= 0; h--) {
3329 dstpixel=(DWORD*)dstbits;
3330 for (x = 0; x < width; x++) {
3331 PALETTEENTRY srcval;
3332 srcval=srccolors[*srcpixel++];
3333 *dstpixel++=(srcval.peRed << rShift) |
3334 (srcval.peGreen << gShift) |
3335 (srcval.peBlue << bShift);
3337 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
3338 dstbits += linebytes;
3348 /* ==== any bmp format -> any 0888 dib ==== */
3349 int rShift,gShift,bShift;
3352 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3353 bmpImage->depth, bmpImage->red_mask,
3354 bmpImage->green_mask, bmpImage->blue_mask,
3357 rShift=X11DRV_DIB_MaskToShift(rDst);
3358 gShift=X11DRV_DIB_MaskToShift(gDst);
3359 bShift=X11DRV_DIB_MaskToShift(bDst);
3360 for (h = lines - 1; h >= 0; h--) {
3361 dstpixel=(DWORD*)dstbits;
3362 for (x = 0; x < width; x++) {
3364 srcval=X11DRV_PALETTE_ToLogical(physDev, XGetPixel(bmpImage, x, h));
3365 *dstpixel++=(GetRValue(srcval) << rShift) |
3366 (GetGValue(srcval) << gShift) |
3367 (GetBValue(srcval) << bShift);
3369 dstbits += linebytes;
3376 static int XGetSubImageErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
3378 return (event->request_code == X_GetImage && event->error_code == BadMatch);
3381 /***********************************************************************
3382 * X11DRV_DIB_SetImageBits_GetSubImage
3384 * Helper for X11DRV_DIB_SetImageBits
3386 static void X11DRV_DIB_SetImageBits_GetSubImage(
3387 const X11DRV_DIB_IMAGEBITS_DESCR *descr, XImage *bmpImage)
3389 /* compressed bitmaps may contain gaps in them. So make a copy
3390 * of the existing pixels first */
3393 SetRect( &bmprc, descr->xDest, descr->yDest,
3394 descr->xDest + descr->width , descr->yDest + descr->height );
3395 GetRgnBox( descr->physDev->region, &rc );
3396 /* convert from dc to drawable origin */
3397 OffsetRect( &rc, descr->physDev->dc_rect.left, descr->physDev->dc_rect.top);
3398 /* clip visible rect with bitmap */
3399 if( IntersectRect( &rc, &rc, &bmprc))
3401 X11DRV_expect_error( gdi_display, XGetSubImageErrorHandler, NULL );
3402 XGetSubImage( gdi_display, descr->drawable, rc.left, rc.top,
3403 rc.right - rc.left, rc.bottom - rc.top, AllPlanes,
3405 descr->xSrc + rc.left - bmprc.left,
3406 descr->ySrc + rc.top - bmprc.top);
3407 X11DRV_check_error();
3411 /***********************************************************************
3412 * X11DRV_DIB_SetImageBits
3414 * Transfer the bits to an X image.
3415 * Helper function for SetDIBits() and SetDIBitsToDevice().
3417 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr )
3419 int lines = descr->lines >= 0 ? descr->lines : -descr->lines;
3420 void *old_data = NULL;
3425 bmpImage = descr->image;
3427 bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL,
3428 descr->infoWidth, lines, 32, 0 );
3429 bmpImage->data = HeapAlloc( GetProcessHeap(), 0, lines * bmpImage->bytes_per_line );
3430 if(bmpImage->data == NULL) {
3431 ERR("Out of memory!\n");
3432 XDestroyImage( bmpImage );
3433 wine_tsx11_unlock();
3438 bmpImage->red_mask = descr->shifts->physicalRed.max << descr->shifts->physicalRed.shift;
3439 bmpImage->green_mask = descr->shifts->physicalGreen.max << descr->shifts->physicalGreen.shift;
3440 bmpImage->blue_mask = descr->shifts->physicalBlue.max << descr->shifts->physicalBlue.shift;
3443 wine_tsx11_unlock();
3445 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3446 descr->infoBpp,descr->rMask,descr->gMask,descr->bMask);
3447 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3448 bmpImage->depth,bmpImage->bits_per_pixel,
3449 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
3451 #ifdef HAVE_LIBXXSHM
3452 if (descr->shm_mode == X11DRV_SHM_PIXMAP
3453 && descr->xSrc == 0 && descr->ySrc == 0
3454 && descr->xDest == 0 && descr->yDest == 0)
3456 TRACE("Using the shared pixmap data.\n");
3459 XSync( gdi_display, False );
3460 wine_tsx11_unlock();
3462 old_data = descr->image->data;
3463 descr->image->data = descr->physBitmap->shminfo.shmaddr;
3467 /* Transfer the pixels */
3470 switch(descr->infoBpp)
3473 X11DRV_DIB_SetImageBits_1( descr->lines, descr->bits, descr->infoWidth,
3474 descr->width, descr->xSrc, (int *)(descr->colorMap),
3475 bmpImage, descr->dibpitch );
3478 if (descr->compression) {
3479 X11DRV_DIB_SetImageBits_GetSubImage( descr, bmpImage);
3480 X11DRV_DIB_SetImageBits_RLE4( descr->lines, descr->bits,
3481 descr->infoWidth, descr->width,
3482 descr->xSrc, (int *)(descr->colorMap),
3485 X11DRV_DIB_SetImageBits_4( descr->lines, descr->bits,
3486 descr->infoWidth, descr->width,
3487 descr->xSrc, (int*)(descr->colorMap),
3488 bmpImage, descr->dibpitch );
3491 if (descr->compression) {
3492 X11DRV_DIB_SetImageBits_GetSubImage( descr, bmpImage);
3493 X11DRV_DIB_SetImageBits_RLE8( descr->lines, descr->bits,
3494 descr->infoWidth, descr->width,
3495 descr->xSrc, (int *)(descr->colorMap),
3498 X11DRV_DIB_SetImageBits_8( descr->lines, descr->bits,
3499 descr->infoWidth, descr->width,
3500 descr->xSrc, (int *)(descr->colorMap),
3501 bmpImage, descr->dibpitch );
3505 X11DRV_DIB_SetImageBits_16( descr->lines, descr->bits,
3506 descr->infoWidth, descr->width,
3507 descr->xSrc, descr->physDev,
3508 descr->rMask, descr->gMask, descr->bMask,
3509 bmpImage, descr->dibpitch);
3512 X11DRV_DIB_SetImageBits_24( descr->lines, descr->bits,
3513 descr->infoWidth, descr->width,
3514 descr->xSrc, descr->physDev,
3515 descr->rMask, descr->gMask, descr->bMask,
3516 bmpImage, descr->dibpitch);
3519 X11DRV_DIB_SetImageBits_32( descr->lines, descr->bits,
3520 descr->infoWidth, descr->width,
3521 descr->xSrc, descr->physDev,
3522 descr->rMask, descr->gMask, descr->bMask,
3523 bmpImage, descr->dibpitch);
3526 WARN("(%d): Invalid depth\n", descr->infoBpp );
3532 WARN( "invalid bits pointer %p\n", descr->bits );
3537 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3538 descr->drawable, descr->gc, bmpImage,
3539 descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
3540 descr->width, descr->height);
3545 #ifdef HAVE_LIBXXSHM
3546 if (descr->shm_mode == X11DRV_SHM_PIXMAP
3547 && descr->xSrc == 0 && descr->ySrc == 0
3548 && descr->xDest == 0 && descr->yDest == 0)
3550 XSync( gdi_display, False );
3552 else if (descr->shm_mode == X11DRV_SHM_IMAGE && descr->image)
3554 XShmPutImage( gdi_display, descr->drawable, descr->gc, bmpImage,
3555 descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
3556 descr->width, descr->height, FALSE );
3557 XSync( gdi_display, 0 );
3562 XPutImage( gdi_display, descr->drawable, descr->gc, bmpImage,
3563 descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
3564 descr->width, descr->height );
3568 if (old_data) descr->image->data = old_data;
3570 if (!descr->image) X11DRV_DIB_DestroyXImage( bmpImage );
3571 wine_tsx11_unlock();
3575 /***********************************************************************
3576 * X11DRV_DIB_GetImageBits
3578 * Transfer the bits from an X image.
3580 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr )
3582 int lines = descr->lines >= 0 ? descr->lines : -descr->lines;
3583 void *old_data = NULL;
3588 bmpImage = descr->image;
3590 bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL,
3591 descr->infoWidth, lines, 32, 0 );
3592 bmpImage->data = HeapAlloc( GetProcessHeap(), 0, lines * bmpImage->bytes_per_line );
3593 if(bmpImage->data == NULL) {
3594 ERR("Out of memory!\n");
3595 XDestroyImage( bmpImage );
3596 wine_tsx11_unlock();
3601 bmpImage->red_mask = descr->shifts->physicalRed.max << descr->shifts->physicalRed.shift;
3602 bmpImage->green_mask = descr->shifts->physicalGreen.max << descr->shifts->physicalGreen.shift;
3603 bmpImage->blue_mask = descr->shifts->physicalBlue.max << descr->shifts->physicalBlue.shift;
3607 #ifdef HAVE_LIBXXSHM
3609 /* We must not call XShmGetImage() with a bitmap which is bigger than the available area.
3610 If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */
3611 if (descr->shm_mode == X11DRV_SHM_PIXMAP && descr->image
3612 && descr->xSrc == 0 && descr->ySrc == 0
3613 && descr->xDest == 0 && descr->yDest == 0
3614 && bmpImage->width <= (descr->width - descr->xSrc)
3615 && bmpImage->height <= (descr->height - descr->ySrc))
3617 XSync( gdi_display, False );
3618 old_data = bmpImage->data;
3619 bmpImage->data = descr->physBitmap->shminfo.shmaddr;
3620 TRACE("Using shared pixmap data.\n");
3622 else if (descr->shm_mode == X11DRV_SHM_IMAGE && descr->image
3623 && bmpImage->width <= (descr->width - descr->xSrc)
3624 && bmpImage->height <= (descr->height - descr->ySrc))
3626 int saveRed, saveGreen, saveBlue;
3628 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3629 gdi_display, descr->drawable, bmpImage,
3630 descr->xSrc, descr->ySrc, AllPlanes);
3632 /* We must save and restore the bmpImage's masks in order
3633 * to preserve them across the call to XShmGetImage, which
3634 * decides to eliminate them since it doesn't happen to know
3635 * what the format of the image is supposed to be, even though
3637 saveRed = bmpImage->red_mask;
3638 saveBlue= bmpImage->blue_mask;
3639 saveGreen = bmpImage->green_mask;
3641 XShmGetImage( gdi_display, descr->drawable, bmpImage,
3642 descr->xSrc, descr->ySrc, AllPlanes);
3644 bmpImage->red_mask = saveRed;
3645 bmpImage->blue_mask = saveBlue;
3646 bmpImage->green_mask = saveGreen;
3649 #endif /* HAVE_LIBXXSHM */
3651 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3652 gdi_display, descr->drawable, descr->xSrc, descr->ySrc, descr->width,
3653 lines, AllPlanes, ZPixmap, bmpImage, descr->xDest, descr->yDest);
3654 XGetSubImage( gdi_display, descr->drawable, descr->xSrc, descr->ySrc,
3655 descr->width, lines, AllPlanes, ZPixmap,
3656 bmpImage, descr->xDest, descr->yDest );
3658 wine_tsx11_unlock();
3660 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3661 descr->infoBpp,descr->rMask,descr->gMask,descr->bMask);
3662 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3663 bmpImage->depth,bmpImage->bits_per_pixel,
3664 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
3665 /* Transfer the pixels */
3666 switch(descr->infoBpp)
3669 X11DRV_DIB_GetImageBits_1( descr->lines,(LPVOID)descr->bits,
3670 descr->infoWidth, descr->width,
3671 descr->colorMap, descr->palentry,
3672 bmpImage, descr->dibpitch );
3676 if (descr->compression) {
3677 FIXME("Compression not yet supported!\n");
3678 if(descr->sizeImage < X11DRV_DIB_GetDIBWidthBytes( descr->infoWidth, 4 ) * abs(descr->lines))
3681 X11DRV_DIB_GetImageBits_4( descr->lines,(LPVOID)descr->bits,
3682 descr->infoWidth, descr->width,
3683 descr->colorMap, descr->palentry,
3684 bmpImage, descr->dibpitch );
3687 if (descr->compression) {
3688 FIXME("Compression not yet supported!\n");
3689 if(descr->sizeImage < X11DRV_DIB_GetDIBWidthBytes( descr->infoWidth, 8 ) * abs(descr->lines))
3692 X11DRV_DIB_GetImageBits_8( descr->lines, (LPVOID)descr->bits,
3693 descr->infoWidth, descr->width,
3694 descr->colorMap, descr->palentry,
3695 bmpImage, descr->dibpitch );
3699 X11DRV_DIB_GetImageBits_16( descr->physDev, descr->lines, (LPVOID)descr->bits,
3700 descr->infoWidth,descr->width,
3702 descr->rMask, descr->gMask, descr->bMask,
3703 bmpImage, descr->dibpitch );
3707 X11DRV_DIB_GetImageBits_24( descr->physDev, descr->lines, (LPVOID)descr->bits,
3708 descr->infoWidth,descr->width,
3710 descr->rMask, descr->gMask, descr->bMask,
3711 bmpImage, descr->dibpitch);
3715 X11DRV_DIB_GetImageBits_32( descr->physDev, descr->lines, (LPVOID)descr->bits,
3716 descr->infoWidth, descr->width,
3718 descr->rMask, descr->gMask, descr->bMask,
3719 bmpImage, descr->dibpitch);
3723 WARN("(%d): Invalid depth\n", descr->infoBpp );
3727 if (old_data) bmpImage->data = old_data;
3728 if (!descr->image) X11DRV_DIB_DestroyXImage( bmpImage );
3732 /*************************************************************************
3733 * X11DRV_SetDIBitsToDevice
3736 INT X11DRV_SetDIBitsToDevice( PHYSDEV dev, INT xDest, INT yDest, DWORD cx, DWORD cy,
3737 INT xSrc, INT ySrc, UINT startscan, UINT lines, LPCVOID bits,
3738 const BITMAPINFO *info, UINT coloruse )
3740 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
3741 X11DRV_DIB_IMAGEBITS_DESCR descr;
3746 int rop = X11DRV_XROPfunction[GetROP2(dev->hdc) - 1];
3748 top_down = (info->bmiHeader.biHeight < 0);
3749 height = abs( info->bmiHeader.biHeight );
3750 descr.infoBpp = info->bmiHeader.biBitCount;
3751 descr.compression = info->bmiHeader.biCompression;
3755 LPtoDP(dev->hdc, &pt, 1);
3757 if (!lines || (startscan >= height)) return 0;
3758 if (!top_down && startscan + lines > height) lines = height - startscan;
3760 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3761 * and clamp all values to fit inside [startscan,startscan+lines]
3763 if (ySrc + cy <= startscan + lines)
3765 UINT y = startscan + lines - (ySrc + cy);
3766 if (ySrc < startscan) cy -= (startscan - ySrc);
3769 /* avoid getting unnecessary lines */
3771 if (y >= lines) return 0;
3776 if (y >= lines) return lines;
3777 ySrc = y; /* need to get all lines in top down mode */
3782 if (ySrc >= startscan + lines) return lines;
3783 pt.y += ySrc + cy - (startscan + lines);
3784 cy = startscan + lines - ySrc;
3786 if (cy > lines) cy = lines;
3788 if (xSrc >= info->bmiHeader.biWidth) return lines;
3789 if (xSrc + cx >= info->bmiHeader.biWidth) cx = info->bmiHeader.biWidth - xSrc;
3790 if (!cx || !cy) return lines;
3792 /* Update the pixmap from the DIB section */
3793 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
3795 X11DRV_SetupGCForText( physDev ); /* To have the correct colors */
3797 XSetFunction(gdi_display, physDev->gc, rop);
3798 wine_tsx11_unlock();
3800 switch (descr.infoBpp)
3805 descr.colorMap = (RGBQUAD *)X11DRV_DIB_BuildColorMap(
3807 physDev->depth, info, &descr.nColorMap );
3808 if (!descr.colorMap) return 0;
3809 descr.rMask = descr.gMask = descr.bMask = 0;
3813 descr.rMask = (descr.compression == BI_BITFIELDS) ? *(const DWORD *)info->bmiColors : 0x7c00;
3814 descr.gMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 1) : 0x03e0;
3815 descr.bMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 2) : 0x001f;
3821 descr.rMask = (descr.compression == BI_BITFIELDS) ? *(const DWORD *)info->bmiColors : 0xff0000;
3822 descr.gMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 1) : 0x00ff00;
3823 descr.bMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 2) : 0x0000ff;
3828 descr.physDev = physDev;
3831 descr.palentry = NULL;
3832 descr.lines = top_down ? -lines : lines;
3833 descr.infoWidth = info->bmiHeader.biWidth;
3834 descr.depth = physDev->depth;
3835 descr.shifts = physDev->color_shifts;
3836 descr.drawable = physDev->drawable;
3837 descr.gc = physDev->gc;
3840 descr.xDest = physDev->dc_rect.left + pt.x;
3841 descr.yDest = physDev->dc_rect.top + pt.y;
3844 descr.shm_mode = X11DRV_SHM_NONE;
3845 descr.dibpitch = X11DRV_DIB_GetDIBWidthBytes( info->bmiHeader.biWidth, info->bmiHeader.biBitCount );
3846 descr.physBitmap = NULL;
3848 result = X11DRV_DIB_SetImageBits( &descr );
3850 if (descr.infoBpp <= 8)
3851 HeapFree(GetProcessHeap(), 0, descr.colorMap);
3853 /* Update the DIBSection of the pixmap */
3854 X11DRV_UnlockDIBSection(physDev, TRUE);
3859 /***********************************************************************
3860 * X11DRV_DIB_DoCopyDIBSection
3862 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP *physBitmap, BOOL toDIB,
3863 void *colorMap, int nColorMap,
3864 Drawable dest, GC gc,
3865 DWORD xSrc, DWORD ySrc,
3866 DWORD xDest, DWORD yDest,
3867 DWORD width, DWORD height)
3869 DIBSECTION dibSection;
3870 X11DRV_DIB_IMAGEBITS_DESCR descr;
3871 int identity[2] = {0,1};
3873 if (!GetObjectW( physBitmap->hbitmap, sizeof(dibSection), &dibSection )) return;
3875 descr.physDev = NULL;
3876 descr.palentry = NULL;
3877 descr.infoWidth = dibSection.dsBmih.biWidth;
3878 descr.infoBpp = dibSection.dsBmih.biBitCount;
3879 descr.lines = physBitmap->topdown ? -dibSection.dsBmih.biHeight : dibSection.dsBmih.biHeight;
3880 descr.image = physBitmap->image;
3881 descr.colorMap = colorMap;
3882 descr.nColorMap = nColorMap;
3883 descr.bits = dibSection.dsBm.bmBits;
3884 descr.depth = physBitmap->pixmap_depth;
3885 descr.shifts = physBitmap->trueColor ? &physBitmap->pixmap_color_shifts : NULL;
3886 descr.compression = dibSection.dsBmih.biCompression;
3887 descr.physBitmap = physBitmap;
3889 if(descr.infoBpp == 1)
3890 descr.colorMap = (void*)identity;
3892 switch (descr.infoBpp)
3897 descr.rMask = descr.gMask = descr.bMask = 0;
3901 descr.rMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[0] : 0x7c00;
3902 descr.gMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[1] : 0x03e0;
3903 descr.bMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[2] : 0x001f;
3908 descr.rMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[0] : 0xff0000;
3909 descr.gMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[1] : 0x00ff00;
3910 descr.bMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[2] : 0x0000ff;
3915 descr.drawable = dest;
3919 descr.xDest = xDest;
3920 descr.yDest = yDest;
3921 descr.width = width;
3922 descr.height = height;
3923 descr.sizeImage = 0;
3925 descr.shm_mode = physBitmap->shm_mode;
3926 #ifdef HAVE_LIBXXSHM
3927 if (physBitmap->shm_mode == X11DRV_SHM_PIXMAP && physBitmap->pixmap != dest)
3929 descr.shm_mode = X11DRV_SHM_NONE;
3932 descr.dibpitch = dibSection.dsBm.bmWidthBytes;
3936 TRACE("Copying from Pixmap to DIB bits\n");
3937 X11DRV_DIB_GetImageBits( &descr );
3941 TRACE("Copying from DIB bits to Pixmap\n");
3942 X11DRV_DIB_SetImageBits( &descr );
3946 /***********************************************************************
3947 * X11DRV_DIB_CopyDIBSection
3949 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE *physDevDst,
3950 DWORD xSrc, DWORD ySrc, DWORD xDest, DWORD yDest,
3951 DWORD width, DWORD height)
3954 X_PHYSBITMAP *physBitmap;
3955 unsigned int nColorMap;
3959 TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc->dev.hdc, physDevDst->dev.hdc,
3960 xSrc, ySrc, xDest, yDest, width, height);
3961 /* this function is meant as an optimization for BitBlt,
3962 * not to be called otherwise */
3963 physBitmap = physDevSrc->bitmap;
3964 if (!physBitmap || GetObjectW( physBitmap->hbitmap, sizeof(dib), &dib ) != sizeof(dib))
3966 ERR("called for non-DIBSection!?\n");
3969 /* while BitBlt should already have made sure we only get
3970 * positive values, we should check for oversize values */
3971 if ((xSrc < dib.dsBm.bmWidth) &&
3972 (ySrc < dib.dsBm.bmHeight)) {
3973 if (xSrc + width > dib.dsBm.bmWidth)
3974 width = dib.dsBm.bmWidth - xSrc;
3975 if (ySrc + height > dib.dsBm.bmHeight)
3976 height = dib.dsBm.bmHeight - ySrc;
3977 /* if the source bitmap is 8bpp or less, we're supposed to use the
3978 * DC's palette for color conversion (not the DIB color table) */
3979 if (dib.dsBm.bmBitsPixel <= 8) {
3980 HPALETTE hPalette = GetCurrentObject( physDevSrc->dev.hdc, OBJ_PAL );
3981 if (!hPalette || (hPalette == GetStockObject(DEFAULT_PALETTE))) {
3982 /* HACK: no palette has been set in the source DC,
3983 * use the DIB colormap instead - this is necessary in some
3984 * cases since we need to do depth conversion in some places
3985 * where real Windows can just copy data straight over */
3986 x11ColorMap = physBitmap->colorMap;
3987 nColorMap = physBitmap->nColorMap;
3988 freeColorMap = FALSE;
3990 const BITMAPINFO* info = (BITMAPINFO*)&dib.dsBmih;
3993 nColorMap = X11DRV_DIB_GetColorCount(info);
3994 x11ColorMap = HeapAlloc(GetProcessHeap(), 0, nColorMap * sizeof(int));
3995 for (i = 0; i < nColorMap; i++)
3996 x11ColorMap[i] = X11DRV_PALETTE_ToPhysical(physDevSrc, PALETTEINDEX(i));
3997 freeColorMap = TRUE;
4004 freeColorMap = FALSE;
4006 /* perform the copy */
4007 X11DRV_DIB_DoCopyDIBSection(physBitmap, FALSE, x11ColorMap, nColorMap,
4008 physDevDst->drawable, physDevDst->gc, xSrc, ySrc,
4009 physDevDst->dc_rect.left + xDest, physDevDst->dc_rect.top + yDest,
4011 /* free color mapping */
4013 HeapFree(GetProcessHeap(), 0, x11ColorMap);
4017 /***********************************************************************
4018 * X11DRV_DIB_DoUpdateDIBSection
4020 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP *physBitmap, BOOL toDIB)
4024 GetObjectW( physBitmap->hbitmap, sizeof(bitmap), &bitmap );
4025 X11DRV_DIB_DoCopyDIBSection(physBitmap, toDIB,
4026 physBitmap->colorMap, physBitmap->nColorMap,
4027 physBitmap->pixmap, get_bitmap_gc(physBitmap->pixmap_depth),
4028 0, 0, 0, 0, bitmap.bmWidth, bitmap.bmHeight);
4031 /***********************************************************************
4032 * X11DRV_DIB_FaultHandler
4034 static LONG CALLBACK X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep )
4036 X_PHYSBITMAP *physBitmap = NULL;
4040 const size_t pagemask = getpagesize() - 1;
4042 if (ep->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
4043 return EXCEPTION_CONTINUE_SEARCH;
4045 addr = (BYTE *)ep->ExceptionRecord->ExceptionInformation[1];
4047 EnterCriticalSection(&dibs_cs);
4048 LIST_FOR_EACH( ptr, &dibs_list )
4050 physBitmap = LIST_ENTRY( ptr, X_PHYSBITMAP, entry );
4051 if ((physBitmap->base <= addr) &&
4052 (addr < physBitmap->base + ((physBitmap->size + pagemask) & ~pagemask)))
4058 LeaveCriticalSection(&dibs_cs);
4060 if (!found) return EXCEPTION_CONTINUE_SEARCH;
4062 if (addr >= physBitmap->base + physBitmap->size)
4063 WARN( "%p: access to %p beyond the end of the DIB\n", physBitmap->hbitmap, addr );
4065 X11DRV_DIB_Lock( physBitmap, DIB_Status_None );
4066 if (ep->ExceptionRecord->ExceptionInformation[0] == EXCEPTION_WRITE_FAULT) {
4067 /* the app tried to write the DIB bits */
4068 X11DRV_DIB_Coerce( physBitmap, DIB_Status_AppMod);
4070 /* the app tried to read the DIB bits */
4071 X11DRV_DIB_Coerce( physBitmap, DIB_Status_InSync);
4073 X11DRV_DIB_Unlock( physBitmap, TRUE );
4075 return EXCEPTION_CONTINUE_EXECUTION;
4078 /***********************************************************************
4081 static INT X11DRV_DIB_Coerce(X_PHYSBITMAP *physBitmap, INT req)
4083 INT ret = DIB_Status_None;
4085 if (!physBitmap->image) return ret; /* not a DIB section */
4086 EnterCriticalSection(&physBitmap->lock);
4087 ret = physBitmap->status;
4089 case DIB_Status_GdiMod:
4090 /* GDI access - request to draw on pixmap */
4091 switch (physBitmap->status)
4094 case DIB_Status_None:
4095 physBitmap->p_status = DIB_Status_GdiMod;
4096 X11DRV_DIB_DoUpdateDIBSection( physBitmap, FALSE );
4099 case DIB_Status_GdiMod:
4100 TRACE("GdiMod requested in status GdiMod\n" );
4101 physBitmap->p_status = DIB_Status_GdiMod;
4104 case DIB_Status_InSync:
4105 TRACE("GdiMod requested in status InSync\n" );
4106 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_NOACCESS );
4107 physBitmap->status = DIB_Status_GdiMod;
4108 physBitmap->p_status = DIB_Status_InSync;
4111 case DIB_Status_AppMod:
4112 TRACE("GdiMod requested in status AppMod\n" );
4113 /* make it readonly to avoid app changing data while we copy */
4114 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY );
4115 X11DRV_DIB_DoUpdateDIBSection( physBitmap, FALSE );
4116 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_NOACCESS );
4117 physBitmap->p_status = DIB_Status_AppMod;
4118 physBitmap->status = DIB_Status_GdiMod;
4123 case DIB_Status_InSync:
4124 /* App access - request access to read DIB surface */
4125 /* (typically called from signal handler) */
4126 switch (physBitmap->status)
4129 case DIB_Status_None:
4130 /* shouldn't happen from signal handler */
4133 case DIB_Status_GdiMod:
4134 TRACE("InSync requested in status GdiMod\n" );
4135 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE );
4136 X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE );
4137 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY );
4138 physBitmap->status = DIB_Status_InSync;
4141 case DIB_Status_InSync:
4142 TRACE("InSync requested in status InSync\n" );
4143 /* shouldn't happen from signal handler */
4146 case DIB_Status_AppMod:
4147 TRACE("InSync requested in status AppMod\n" );
4148 /* no reason to do anything here, and this
4149 * shouldn't happen from signal handler */
4154 case DIB_Status_AppMod:
4155 /* App access - request access to write DIB surface */
4156 /* (typically called from signal handler) */
4157 switch (physBitmap->status)
4160 case DIB_Status_None:
4161 /* shouldn't happen from signal handler */
4164 case DIB_Status_GdiMod:
4165 TRACE("AppMod requested in status GdiMod\n" );
4166 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE );
4167 X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE );
4168 physBitmap->status = DIB_Status_AppMod;
4171 case DIB_Status_InSync:
4172 TRACE("AppMod requested in status InSync\n" );
4173 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE );
4174 physBitmap->status = DIB_Status_AppMod;
4177 case DIB_Status_AppMod:
4178 TRACE("AppMod requested in status AppMod\n" );
4179 /* shouldn't happen from signal handler */
4184 /* it is up to the caller to do the copy/conversion, probably
4185 * using the return value to decide where to copy from */
4187 LeaveCriticalSection(&physBitmap->lock);
4191 /***********************************************************************
4194 INT X11DRV_DIB_Lock(X_PHYSBITMAP *physBitmap, INT req)
4196 INT ret = DIB_Status_None;
4198 if (!physBitmap->image) return ret; /* not a DIB section */
4199 TRACE("Locking %p from thread %04x\n", physBitmap->hbitmap, GetCurrentThreadId());
4200 EnterCriticalSection(&physBitmap->lock);
4201 ret = physBitmap->status;
4202 if (req != DIB_Status_None)
4203 X11DRV_DIB_Coerce(physBitmap, req);
4207 /***********************************************************************
4210 void X11DRV_DIB_Unlock(X_PHYSBITMAP *physBitmap, BOOL commit)
4212 if (!physBitmap->image) return; /* not a DIB section */
4213 switch (physBitmap->status)
4216 case DIB_Status_None:
4217 /* in case anyone is wondering, this is the "signal handler doesn't
4218 * work" case, where we always have to be ready for app access */
4220 switch (physBitmap->p_status)
4222 case DIB_Status_GdiMod:
4223 TRACE("Unlocking and syncing from GdiMod\n" );
4224 X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE );
4228 TRACE("Unlocking without needing to sync\n" );
4232 else TRACE("Unlocking with no changes\n");
4233 physBitmap->p_status = DIB_Status_None;
4236 case DIB_Status_GdiMod:
4237 TRACE("Unlocking in status GdiMod\n" );
4238 /* DIB was protected in Coerce */
4240 /* no commit, revert to InSync if applicable */
4241 if ((physBitmap->p_status == DIB_Status_InSync) ||
4242 (physBitmap->p_status == DIB_Status_AppMod)) {
4243 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY );
4244 physBitmap->status = DIB_Status_InSync;
4249 case DIB_Status_InSync:
4250 TRACE("Unlocking in status InSync\n" );
4251 /* DIB was already protected in Coerce */
4254 case DIB_Status_AppMod:
4255 TRACE("Unlocking in status AppMod\n" );
4256 /* DIB was already protected in Coerce */
4257 /* this case is ordinary only called from the signal handler,
4258 * so we don't bother to check for !commit */
4261 LeaveCriticalSection(&physBitmap->lock);
4262 TRACE("Unlocked %p\n", physBitmap->hbitmap);
4265 /***********************************************************************
4266 * X11DRV_CoerceDIBSection
4268 INT X11DRV_CoerceDIBSection(X11DRV_PDEVICE *physDev, INT req)
4270 if (!physDev || !physDev->bitmap) return DIB_Status_None;
4271 return X11DRV_DIB_Coerce(physDev->bitmap, req);
4274 /***********************************************************************
4275 * X11DRV_LockDIBSection
4277 INT X11DRV_LockDIBSection(X11DRV_PDEVICE *physDev, INT req)
4279 if (!physDev || !physDev->bitmap) return DIB_Status_None;
4280 return X11DRV_DIB_Lock(physDev->bitmap, req);
4283 /***********************************************************************
4284 * X11DRV_UnlockDIBSection
4286 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE *physDev, BOOL commit)
4288 if (!physDev || !physDev->bitmap) return;
4289 X11DRV_DIB_Unlock(physDev->bitmap, commit);
4293 #ifdef HAVE_LIBXXSHM
4294 /***********************************************************************
4295 * X11DRV_XShmErrorHandler
4298 static int XShmErrorHandler( Display *dpy, XErrorEvent *event, void *arg )
4300 return 1; /* FIXME: should check event contents */
4303 /***********************************************************************
4304 * X11DRV_XShmCreateImage
4307 static XImage *X11DRV_XShmCreateImage( int width, int height, int bpp,
4308 XShmSegmentInfo* shminfo)
4312 image = XShmCreateImage(gdi_display, visual, bpp, ZPixmap, NULL, shminfo, width, height);
4315 shminfo->shmid = shmget(IPC_PRIVATE, image->bytes_per_line * height,
4317 if( shminfo->shmid != -1 )
4319 shminfo->shmaddr = shmat( shminfo->shmid, 0, 0 );
4320 if( shminfo->shmaddr != (char*)-1 )
4324 shminfo->readOnly = FALSE;
4325 X11DRV_expect_error( gdi_display, XShmErrorHandler, NULL );
4326 ok = (XShmAttach( gdi_display, shminfo ) != 0);
4327 XSync( gdi_display, False );
4328 if (X11DRV_check_error()) ok = FALSE;
4331 shmctl(shminfo->shmid, IPC_RMID, 0);
4332 return image; /* Success! */
4334 /* An error occurred */
4335 shmdt(shminfo->shmaddr);
4337 shmctl(shminfo->shmid, IPC_RMID, 0);
4338 shminfo->shmid = -1;
4340 XFlush(gdi_display);
4341 XDestroyImage(image);
4346 #endif /* HAVE_LIBXXSHM */
4348 static Bool X11DRV_DIB_QueryXShm( Bool *pixmaps )
4350 static Bool have_xshm, have_xshm_pixmaps;
4351 static BOOL initialized;
4355 #ifdef HAVE_LIBXXSHM
4358 have_xshm = XShmQueryVersion( gdi_display, &major, &minor, &have_xshm_pixmaps );
4363 *pixmaps = have_xshm_pixmaps;
4367 /***********************************************************************
4368 * X11DRV_CreateDIBSection (X11DRV.@)
4370 HBITMAP X11DRV_CreateDIBSection( PHYSDEV dev, HBITMAP hbitmap, const BITMAPINFO *bmi, UINT usage )
4372 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
4373 X_PHYSBITMAP *physBitmap;
4375 #ifdef HAVE_LIBXXSHM
4379 if (!(physBitmap = X11DRV_init_phys_bitmap( hbitmap ))) return 0;
4380 physBitmap->topdown = bmi->bmiHeader.biHeight < 0;
4381 physBitmap->status = DIB_Status_None;
4383 GetObjectW( hbitmap, sizeof(dib), &dib );
4385 /* create color map */
4386 if (dib.dsBm.bmBitsPixel <= 8)
4388 physBitmap->colorMap = X11DRV_DIB_BuildColorMap( physDev,
4389 usage, dib.dsBm.bmBitsPixel, bmi,
4390 &physBitmap->nColorMap );
4393 if (!X11DRV_XRender_SetPhysBitmapDepth( physBitmap, dib.dsBm.bmBitsPixel, &dib ))
4395 if (dib.dsBm.bmBitsPixel == 1)
4397 physBitmap->pixmap_depth = 1;
4398 physBitmap->trueColor = FALSE;
4402 physBitmap->pixmap_depth = screen_depth;
4403 physBitmap->pixmap_color_shifts = X11DRV_PALETTE_default_shifts;
4404 physBitmap->trueColor = (visual->class == TrueColor || visual->class == DirectColor);
4408 /* create pixmap and X image */
4410 #ifdef HAVE_LIBXXSHM
4411 physBitmap->shminfo.shmid = -1;
4413 if (X11DRV_DIB_QueryXShm( &pixmaps )
4414 && (physBitmap->image = X11DRV_XShmCreateImage( dib.dsBm.bmWidth, dib.dsBm.bmHeight,
4415 physBitmap->pixmap_depth, &physBitmap->shminfo )))
4419 physBitmap->shm_mode = X11DRV_SHM_PIXMAP;
4420 physBitmap->image->data = HeapAlloc( GetProcessHeap(), 0,
4421 dib.dsBm.bmHeight * physBitmap->image->bytes_per_line );
4425 physBitmap->shm_mode = X11DRV_SHM_IMAGE;
4426 physBitmap->image->data = physBitmap->shminfo.shmaddr;
4432 physBitmap->shm_mode = X11DRV_SHM_NONE;
4433 physBitmap->image = X11DRV_DIB_CreateXImage( dib.dsBm.bmWidth, dib.dsBm.bmHeight,
4434 physBitmap->pixmap_depth );
4437 #ifdef HAVE_LIBXXSHM
4438 if (physBitmap->shm_mode == X11DRV_SHM_PIXMAP)
4440 TRACE("Creating shared pixmap for bmp %p.\n", physBitmap->hbitmap);
4441 physBitmap->pixmap = XShmCreatePixmap( gdi_display, root_window,
4442 physBitmap->shminfo.shmaddr, &physBitmap->shminfo,
4443 dib.dsBm.bmWidth, dib.dsBm.bmHeight,
4444 physBitmap->pixmap_depth );
4449 physBitmap->pixmap = XCreatePixmap( gdi_display, root_window, dib.dsBm.bmWidth,
4450 dib.dsBm.bmHeight, physBitmap->pixmap_depth );
4453 wine_tsx11_unlock();
4454 if (!physBitmap->pixmap || !physBitmap->image) return 0;
4456 if (physBitmap->trueColor)
4458 ColorShifts *shifts = &physBitmap->pixmap_color_shifts;
4460 /* When XRender is around and used, we also support dibsections in other formats like 16-bit. In these
4461 * cases we need to override the mask of XImages. The reason is that during XImage creation the masks are
4462 * derived from a 24-bit visual (no 16-bit ones are around when X runs at 24-bit). SetImageBits and other
4463 * functions rely on the color masks for proper color conversion, so we need to override the masks here. */
4464 physBitmap->image->red_mask = shifts->physicalRed.max << shifts->physicalRed.shift;
4465 physBitmap->image->green_mask = shifts->physicalGreen.max << shifts->physicalGreen.shift;
4466 physBitmap->image->blue_mask = shifts->physicalBlue.max << shifts->physicalBlue.shift;
4469 /* install fault handler */
4470 InitializeCriticalSection( &physBitmap->lock );
4471 physBitmap->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": X_PHYSBITMAP.lock");
4473 physBitmap->base = dib.dsBm.bmBits;
4474 physBitmap->size = dib.dsBmih.biSizeImage;
4475 physBitmap->status = DIB_Status_AppMod;
4478 dibs_handler = AddVectoredExceptionHandler( TRUE, X11DRV_DIB_FaultHandler );
4479 EnterCriticalSection( &dibs_cs );
4480 list_add_head( &dibs_list, &physBitmap->entry );
4481 LeaveCriticalSection( &dibs_cs );
4483 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE );
4488 /***********************************************************************
4489 * X11DRV_DIB_DeleteDIBSection
4491 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP *physBitmap, DIBSECTION *dib)
4495 EnterCriticalSection( &dibs_cs );
4496 list_remove( &physBitmap->entry );
4497 last = list_empty( &dibs_list );
4498 LeaveCriticalSection( &dibs_cs );
4502 RemoveVectoredExceptionHandler( dibs_handler );
4503 dibs_handler = NULL;
4506 if (dib->dshSection)
4507 X11DRV_DIB_Coerce(physBitmap, DIB_Status_InSync);
4509 if (physBitmap->image)
4512 #ifdef HAVE_LIBXXSHM
4513 if (physBitmap->shminfo.shmid != -1)
4515 XShmDetach( gdi_display, &(physBitmap->shminfo) );
4516 if (physBitmap->shm_mode == X11DRV_SHM_PIXMAP) X11DRV_DIB_DestroyXImage( physBitmap->image );
4517 else XDestroyImage( physBitmap->image );
4518 shmdt( physBitmap->shminfo.shmaddr );
4519 physBitmap->shminfo.shmid = -1;
4520 physBitmap->shm_mode = X11DRV_SHM_NONE;
4524 X11DRV_DIB_DestroyXImage( physBitmap->image );
4525 wine_tsx11_unlock();
4528 HeapFree(GetProcessHeap(), 0, physBitmap->colorMap);
4529 physBitmap->lock.DebugInfo->Spare[0] = 0;
4530 DeleteCriticalSection(&physBitmap->lock);
4533 /***********************************************************************
4534 * SetDIBColorTable (X11DRV.@)
4536 UINT X11DRV_SetDIBColorTable( PHYSDEV dev, UINT start, UINT count, const RGBQUAD *colors )
4538 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
4541 X_PHYSBITMAP *physBitmap = physDev->bitmap;
4543 if (!physBitmap) return 0;
4544 GetObjectW( physBitmap->hbitmap, sizeof(dib), &dib );
4546 if (physBitmap->colorMap && start < physBitmap->nColorMap) {
4547 UINT end = count + start;
4548 if (end > physBitmap->nColorMap) end = physBitmap->nColorMap;
4550 * Changing color table might change the mapping between
4551 * DIB colors and X11 colors and thus alter the visible state
4552 * of the bitmap object.
4555 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4556 * at least for a 1 bpp dibsection
4558 X11DRV_DIB_Lock( physBitmap, DIB_Status_AppMod );
4559 X11DRV_DIB_GenColorMap( physDev, physBitmap->colorMap, DIB_RGB_COLORS,
4560 dib.dsBm.bmBitsPixel, colors, start, end );
4561 X11DRV_DIB_Unlock( physBitmap, TRUE );
4568 /***********************************************************************
4569 * X11DRV_DIB_CreateDIBFromBitmap
4571 * Allocates a packed DIB and copies the bitmap data into it.
4573 HGLOBAL X11DRV_DIB_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp)
4578 LPBITMAPINFOHEADER pbmiHeader;
4579 unsigned int cDataSize, cPackedSize, OffsetBits;
4582 if (!GetObjectW( hBmp, sizeof(bmp), &bmp )) return 0;
4585 * A packed DIB contains a BITMAPINFO structure followed immediately by
4586 * an optional color palette and the pixel data.
4589 /* Calculate the size of the packed DIB */
4590 cDataSize = X11DRV_DIB_GetDIBWidthBytes( bmp.bmWidth, bmp.bmBitsPixel ) * abs( bmp.bmHeight );
4591 cPackedSize = sizeof(BITMAPINFOHEADER)
4592 + ( (bmp.bmBitsPixel <= 8) ? (sizeof(RGBQUAD) * (1 << bmp.bmBitsPixel)) : 0 )
4594 /* Get the offset to the bits */
4595 OffsetBits = cPackedSize - cDataSize;
4597 /* Allocate the packed DIB */
4598 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize);
4599 hPackedDIB = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE /*| GMEM_ZEROINIT*/,
4603 WARN("Could not allocate packed DIB!\n");
4607 /* A packed DIB starts with a BITMAPINFOHEADER */
4608 pPackedDIB = GlobalLock(hPackedDIB);
4609 pbmiHeader = (LPBITMAPINFOHEADER)pPackedDIB;
4611 /* Init the BITMAPINFOHEADER */
4612 pbmiHeader->biSize = sizeof(BITMAPINFOHEADER);
4613 pbmiHeader->biWidth = bmp.bmWidth;
4614 pbmiHeader->biHeight = bmp.bmHeight;
4615 pbmiHeader->biPlanes = 1;
4616 pbmiHeader->biBitCount = bmp.bmBitsPixel;
4617 pbmiHeader->biCompression = BI_RGB;
4618 pbmiHeader->biSizeImage = 0;
4619 pbmiHeader->biXPelsPerMeter = pbmiHeader->biYPelsPerMeter = 0;
4620 pbmiHeader->biClrUsed = 0;
4621 pbmiHeader->biClrImportant = 0;
4623 /* Retrieve the DIB bits from the bitmap and fill in the
4624 * DIB color table if present */
4626 nLinesCopied = GetDIBits(hdc, /* Handle to device context */
4627 hBmp, /* Handle to bitmap */
4628 0, /* First scan line to set in dest bitmap */
4629 bmp.bmHeight, /* Number of scan lines to copy */
4630 pPackedDIB + OffsetBits, /* [out] Address of array for bitmap bits */
4631 (LPBITMAPINFO) pbmiHeader, /* [out] Address of BITMAPINFO structure */
4632 0); /* RGB or palette index */
4633 GlobalUnlock(hPackedDIB);
4635 /* Cleanup if GetDIBits failed */
4636 if (nLinesCopied != bmp.bmHeight)
4638 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied, bmp.bmHeight);
4639 GlobalFree(hPackedDIB);
4646 /**************************************************************************
4647 * X11DRV_DIB_CreateDIBFromPixmap
4649 * Allocates a packed DIB and copies the Pixmap data into it.
4650 * The Pixmap passed in is deleted after the conversion.
4652 HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc)
4655 X_PHYSBITMAP *physBitmap;
4658 HGLOBAL hPackedDIB = 0;
4660 int x,y; /* Unused */
4661 unsigned border_width; /* Unused */
4662 unsigned int depth, width, height;
4664 /* Get the Pixmap dimensions and bit depth */
4666 if (!XGetGeometry(gdi_display, pixmap, &root, &x, &y, &width, &height,
4667 &border_width, &depth)) depth = 0;
4668 wine_tsx11_unlock();
4669 if (!pixmap_formats[depth]) return 0;
4671 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4672 width, height, depth);
4675 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4676 * and make it a container for the pixmap passed.
4678 if (!(hBmp = CreateBitmap( width, height, 1, pixmap_formats[depth]->bits_per_pixel, NULL ))) return 0;
4680 /* force bitmap to be owned by a screen DC */
4681 hdcMem = CreateCompatibleDC( hdc );
4682 SelectObject( hdcMem, SelectObject( hdcMem, hBmp ));
4685 physBitmap = X11DRV_get_phys_bitmap( hBmp );
4687 /* swap the new pixmap in */
4688 orig_pixmap = physBitmap->pixmap;
4689 physBitmap->pixmap = pixmap;
4692 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4693 * A packed DIB contains a BITMAPINFO structure followed immediately by
4694 * an optional color palette and the pixel data.
4696 hPackedDIB = X11DRV_DIB_CreateDIBFromBitmap(hdc, hBmp);
4698 /* we can now get rid of the HBITMAP and its original pixmap */
4699 physBitmap->pixmap = orig_pixmap;
4702 TRACE("\tReturning packed DIB %p\n", hPackedDIB);
4707 /**************************************************************************
4708 * X11DRV_DIB_CreatePixmapFromDIB
4710 * Creates a Pixmap from a packed DIB
4712 Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc )
4715 X_PHYSBITMAP *physBitmap;
4719 /* Create a DDB from the DIB */
4721 pbmi = GlobalLock(hPackedDIB);
4722 hBmp = CreateDIBitmap(hdc, &pbmi->bmiHeader, CBM_INIT,
4723 (LPBYTE)pbmi + bitmap_info_size( pbmi, DIB_RGB_COLORS ),
4724 pbmi, DIB_RGB_COLORS);
4725 GlobalUnlock(hPackedDIB);
4727 /* clear the physBitmap so that we can steal its pixmap */
4728 physBitmap = X11DRV_get_phys_bitmap( hBmp );
4729 pixmap = physBitmap->pixmap;
4730 physBitmap->pixmap = 0;
4732 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4735 TRACE("Returning Pixmap %lx\n", pixmap);