2 * X11DRV device-independent bitmaps
4 * Copyright 1993,1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <X11/extensions/XShm.h>
26 # ifdef HAVE_SYS_SHM_H
29 # ifdef HAVE_SYS_IPC_H
32 #endif /* defined(HAVE_LIBXXSHM) */
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(bitmap);
46 static struct list dibs_list = LIST_INIT(dibs_list);
48 static CRITICAL_SECTION dibs_cs;
49 static CRITICAL_SECTION_DEBUG dibs_cs_debug =
52 { &dibs_cs_debug.ProcessLocksList, &dibs_cs_debug.ProcessLocksList },
53 0, 0, { (DWORD_PTR)(__FILE__ ": dibs_cs") }
55 static CRITICAL_SECTION dibs_cs = { &dibs_cs_debug, -1, 0, 0, 0, 0 };
57 static PVOID dibs_handler;
59 static int ximageDepthTable[32];
61 /* This structure holds the arguments for DIB_SetImageBits() */
64 X11DRV_PDEVICE *physDev;
67 PALETTEENTRY *palentry;
89 } X11DRV_DIB_IMAGEBITS_DESCR;
94 RLE_EOL = 0, /* End of line */
95 RLE_END = 1, /* End of bitmap */
96 RLE_DELTA = 2 /* Delta */
100 static INT X11DRV_DIB_Coerce(X_PHYSBITMAP *,INT,BOOL);
101 static INT X11DRV_DIB_Lock(X_PHYSBITMAP *,INT,BOOL);
102 static void X11DRV_DIB_Unlock(X_PHYSBITMAP *,BOOL);
105 Some of the following helper functions are duplicated in
109 /***********************************************************************
110 * X11DRV_DIB_GetXImageWidthBytes
112 * Return the width of an X image in bytes
114 inline static int X11DRV_DIB_GetXImageWidthBytes( int width, int depth )
116 if (!depth || depth > 32) goto error;
118 if (!ximageDepthTable[depth-1])
120 XImage *testimage = XCreateImage( gdi_display, visual, depth,
121 ZPixmap, 0, NULL, 1, 1, 32, 20 );
124 ximageDepthTable[depth-1] = testimage->bits_per_pixel;
125 XDestroyImage( testimage );
127 else ximageDepthTable[depth-1] = -1;
129 if (ximageDepthTable[depth-1] != -1)
130 return (4 * ((width * ximageDepthTable[depth-1] + 31) / 32));
133 WARN( "(%d): Unsupported depth\n", depth );
138 /***********************************************************************
139 * X11DRV_DIB_GetDIBWidthBytes
141 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
143 static int X11DRV_DIB_GetDIBWidthBytes( int width, int depth )
149 case 1: words = (width + 31) / 32; break;
150 case 4: words = (width + 7) / 8; break;
151 case 8: words = (width + 3) / 4; break;
153 case 16: words = (width + 1) / 2; break;
154 case 24: words = (width * 3 + 3) / 4; break;
156 WARN("(%d): Unsupported depth\n", depth );
165 /***********************************************************************
166 * X11DRV_DIB_GetDIBImageBytes
168 * Return the number of bytes used to hold the image in a DIB bitmap.
170 static int X11DRV_DIB_GetDIBImageBytes( int width, int height, int depth )
172 return X11DRV_DIB_GetDIBWidthBytes( width, depth ) * abs( height );
176 /***********************************************************************
177 * X11DRV_DIB_BitmapInfoSize
179 * Return the size of the bitmap info structure including color table.
181 int X11DRV_DIB_BitmapInfoSize( const BITMAPINFO * info, WORD coloruse )
185 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
187 const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info;
188 colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
189 return sizeof(BITMAPCOREHEADER) + colors *
190 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
192 else /* assume BITMAPINFOHEADER */
194 colors = info->bmiHeader.biClrUsed;
195 if (!colors && (info->bmiHeader.biBitCount <= 8))
196 colors = 1 << info->bmiHeader.biBitCount;
197 return sizeof(BITMAPINFOHEADER) + colors *
198 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
203 /***********************************************************************
204 * X11DRV_DIB_CreateXImage
208 XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth )
214 width_bytes = X11DRV_DIB_GetXImageWidthBytes( width, depth );
215 image = XCreateImage( gdi_display, visual, depth, ZPixmap, 0,
216 calloc( height, width_bytes ),
217 width, height, 32, width_bytes );
223 /***********************************************************************
224 * DIB_GetBitmapInfoEx
226 * Get the info from a bitmap header.
227 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
229 static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER *header, LONG *width,
230 LONG *height, WORD *planes, WORD *bpp,
231 WORD *compr, DWORD *size )
233 if (header->biSize == sizeof(BITMAPCOREHEADER))
235 const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)header;
236 *width = core->bcWidth;
237 *height = core->bcHeight;
238 *planes = core->bcPlanes;
239 *bpp = core->bcBitCount;
244 if (header->biSize >= sizeof(BITMAPINFOHEADER))
246 *width = header->biWidth;
247 *height = header->biHeight;
248 *planes = header->biPlanes;
249 *bpp = header->biBitCount;
250 *compr = header->biCompression;
251 *size = header->biSizeImage;
254 ERR("(%d): unknown/wrong size for header\n", header->biSize );
259 /***********************************************************************
262 * Get the info from a bitmap header.
263 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
265 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width,
266 LONG *height, WORD *bpp, WORD *compr )
271 return DIB_GetBitmapInfoEx( header, width, height, &planes, bpp, compr, &size);
275 static inline BOOL colour_is_brighter(RGBQUAD c1, RGBQUAD c2)
277 return (c1.rgbRed * c1.rgbRed + c1.rgbGreen * c1.rgbGreen + c1.rgbBlue * c1.rgbBlue) >
278 (c2.rgbRed * c2.rgbRed + c2.rgbGreen * c2.rgbGreen + c2.rgbBlue * c2.rgbBlue);
281 /***********************************************************************
282 * X11DRV_DIB_GenColorMap
284 * Fills the color map of a bitmap palette. Should not be called
285 * for a >8-bit deep bitmap.
287 static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE *physDev, int *colorMapping,
288 WORD coloruse, WORD depth, BOOL quads,
289 const void *colorPtr, int start, int end )
293 if (coloruse == DIB_RGB_COLORS)
297 const RGBQUAD * rgb = (const RGBQUAD *)colorPtr;
299 if (depth == 1) /* Monochrome */
304 if (GetDIBColorTable( physDev->hdc, 0, 2, table ) == 2)
305 invert = !colour_is_brighter(table[1], table[0]);
307 for (i = start; i < end; i++, rgb++)
308 colorMapping[i] = ((rgb->rgbRed + rgb->rgbGreen +
309 rgb->rgbBlue > 255*3/2 && !invert) ||
310 (rgb->rgbRed + rgb->rgbGreen +
311 rgb->rgbBlue <= 255*3/2 && invert));
314 for (i = start; i < end; i++, rgb++)
315 colorMapping[i] = X11DRV_PALETTE_ToPhysical( NULL, RGB(rgb->rgbRed,
321 const RGBTRIPLE * rgb = (const RGBTRIPLE *)colorPtr;
323 if (depth == 1) /* Monochrome */
328 if (GetDIBColorTable( physDev->hdc, 0, 2, table ) == 2)
329 invert = !colour_is_brighter(table[1], table[0]);
331 for (i = start; i < end; i++, rgb++)
332 colorMapping[i] = ((rgb->rgbtRed + rgb->rgbtGreen +
333 rgb->rgbtBlue > 255*3/2 && !invert) ||
334 (rgb->rgbtRed + rgb->rgbtGreen +
335 rgb->rgbtBlue <= 255*3/2 && invert));
338 for (i = start; i < end; i++, rgb++)
339 colorMapping[i] = X11DRV_PALETTE_ToPhysical( NULL, RGB(rgb->rgbtRed,
344 else /* DIB_PAL_COLORS */
347 const WORD * index = (const WORD *)colorPtr;
349 for (i = start; i < end; i++, index++)
350 colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(*index) );
352 for (i = start; i < end; i++)
353 colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(i) );
360 /***********************************************************************
361 * X11DRV_DIB_BuildColorMap
363 * Build the color map from the bitmap palette. Should not be called
364 * for a >8-bit deep bitmap.
366 static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE *physDev, WORD coloruse, WORD depth,
367 const BITMAPINFO *info, int *nColors )
371 const void *colorPtr;
374 isInfo = info->bmiHeader.biSize != sizeof(BITMAPCOREHEADER);
378 colors = info->bmiHeader.biClrUsed;
379 if (!colors) colors = 1 << info->bmiHeader.biBitCount;
383 colors = 1 << ((const BITMAPCOREHEADER *)info)->bcBitCount;
386 colorPtr = (const BYTE*) info + (WORD) info->bmiHeader.biSize;
390 ERR("called with >256 colors!\n");
394 /* just so CopyDIBSection doesn't have to create an identity palette */
395 if (coloruse == (WORD)-1) colorPtr = NULL;
397 if (!(colorMapping = HeapAlloc(GetProcessHeap(), 0, colors * sizeof(int) )))
401 return X11DRV_DIB_GenColorMap( physDev, colorMapping, coloruse, depth,
402 isInfo, colorPtr, 0, colors);
405 /***********************************************************************
406 * X11DRV_DIB_MapColor
408 static int X11DRV_DIB_MapColor( int *physMap, int nPhysMap, int phys, int oldcol )
412 if ((oldcol < nPhysMap) && (physMap[oldcol] == phys))
415 for (color = 0; color < nPhysMap; color++)
416 if (physMap[color] == phys)
419 WARN("Strange color %08x\n", phys);
424 /*********************************************************************
425 * X11DRV_DIB_GetNearestIndex
427 * Helper for X11DRV_DIB_GetDIBits.
428 * Returns the nearest colour table index for a given RGB.
429 * Nearest is defined by minimizing the sum of the squares.
431 static INT X11DRV_DIB_GetNearestIndex(RGBQUAD *colormap, int numColors, BYTE r, BYTE g, BYTE b)
433 INT i, best = -1, diff, bestdiff = -1;
436 for(color = colormap, i = 0; i < numColors; color++, i++) {
437 diff = (r - color->rgbRed) * (r - color->rgbRed) +
438 (g - color->rgbGreen) * (g - color->rgbGreen) +
439 (b - color->rgbBlue) * (b - color->rgbBlue);
442 if(best == -1 || diff < bestdiff) {
449 /*********************************************************************
450 * X11DRV_DIB_MaskToShift
452 * Helper for X11DRV_DIB_GetDIBits.
453 * Returns the by how many bits to shift a given color so that it is
454 * in the proper position.
456 INT X11DRV_DIB_MaskToShift(DWORD mask)
464 while ((mask&1)==0) {
471 /***********************************************************************
472 * X11DRV_DIB_CheckMask
474 * Check RGB mask if it is either 0 or matches visual's mask.
476 static inline int X11DRV_DIB_CheckMask(int red_mask, int green_mask, int blue_mask)
478 return ( red_mask == 0 && green_mask == 0 && blue_mask == 0 ) ||
479 ( red_mask == visual->red_mask && green_mask == visual->green_mask &&
480 blue_mask == visual->blue_mask );
483 /***********************************************************************
484 * X11DRV_DIB_SetImageBits_1
486 * SetDIBits for a 1-bit deep DIB.
488 static void X11DRV_DIB_SetImageBits_1( int lines, const BYTE *srcbits,
489 DWORD srcwidth, DWORD dstwidth, int left,
490 int *colors, XImage *bmpImage, DWORD linebytes)
499 srcbits = srcbits + linebytes * (lines - 1);
500 linebytes = -linebytes;
503 if ((extra = (left & 7)) != 0) {
507 srcbits += left >> 3;
508 width = min(srcwidth, dstwidth);
510 /* ==== pal 1 dib -> any bmp format ==== */
511 for (h = lines-1; h >=0; h--) {
513 /* FIXME: should avoid putting x<left pixels (minor speed issue) */
514 for (i = width/8, x = left; i > 0; i--) {
516 XPutPixel( bmpImage, x++, h, colors[ srcval >> 7] );
517 XPutPixel( bmpImage, x++, h, colors[(srcval >> 6) & 1] );
518 XPutPixel( bmpImage, x++, h, colors[(srcval >> 5) & 1] );
519 XPutPixel( bmpImage, x++, h, colors[(srcval >> 4) & 1] );
520 XPutPixel( bmpImage, x++, h, colors[(srcval >> 3) & 1] );
521 XPutPixel( bmpImage, x++, h, colors[(srcval >> 2) & 1] );
522 XPutPixel( bmpImage, x++, h, colors[(srcval >> 1) & 1] );
523 XPutPixel( bmpImage, x++, h, colors[ srcval & 1] );
529 case 7: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
530 case 6: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
531 case 5: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
532 case 4: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
533 case 3: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
534 case 2: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1;
535 case 1: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]);
538 srcbits += linebytes;
542 /***********************************************************************
543 * X11DRV_DIB_GetImageBits_1
545 * GetDIBits for a 1-bit deep DIB.
547 static void X11DRV_DIB_GetImageBits_1( int lines, BYTE *dstbits,
548 DWORD dstwidth, DWORD srcwidth,
549 RGBQUAD *colors, PALETTEENTRY *srccolors,
550 XImage *bmpImage, DWORD linebytes )
553 int h, width = min(dstwidth, srcwidth);
557 dstbits = dstbits + linebytes * (lines - 1);
558 linebytes = -linebytes;
561 switch (bmpImage->depth)
565 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
567 /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */
570 for (h=lines-1; h>=0; h--) {
574 for (x=0; x<width; x++) {
576 srcval=srccolors[XGetPixel(bmpImage, x, h)];
577 dstval|=(X11DRV_DIB_GetNearestIndex
581 srcval.peBlue) << (7 - (x & 7)));
590 dstbits += linebytes;
598 if (X11DRV_DIB_CheckMask(bmpImage->red_mask, bmpImage->green_mask, bmpImage->blue_mask)
600 /* ==== pal 8 bmp -> pal 1 dib ==== */
602 const BYTE* srcpixel;
605 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
607 for (h=0; h<lines; h++) {
612 for (x=0; x<width; x++) {
614 srcval=srccolors[(int)*srcpixel++];
615 dstval|=(X11DRV_DIB_GetNearestIndex
619 srcval.peBlue) << (7-(x&7)) );
628 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
629 dstbits += linebytes;
640 const WORD* srcpixel;
643 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
645 if (bmpImage->green_mask==0x03e0) {
646 if (bmpImage->red_mask==0x7c00) {
647 /* ==== rgb 555 bmp -> pal 1 dib ==== */
648 for (h=0; h<lines; h++) {
653 for (x=0; x<width; x++) {
656 dstval|=(X11DRV_DIB_GetNearestIndex
658 ((srcval >> 7) & 0xf8) | /* r */
659 ((srcval >> 12) & 0x07),
660 ((srcval >> 2) & 0xf8) | /* g */
661 ((srcval >> 7) & 0x07),
662 ((srcval << 3) & 0xf8) | /* b */
663 ((srcval >> 2) & 0x07) ) << (7-(x&7)) );
672 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
673 dstbits += linebytes;
675 } else if (bmpImage->blue_mask==0x7c00) {
676 /* ==== bgr 555 bmp -> pal 1 dib ==== */
677 for (h=0; h<lines; h++) {
682 for (x=0; x<width; x++) {
685 dstval|=(X11DRV_DIB_GetNearestIndex
687 ((srcval << 3) & 0xf8) | /* r */
688 ((srcval >> 2) & 0x07),
689 ((srcval >> 2) & 0xf8) | /* g */
690 ((srcval >> 7) & 0x07),
691 ((srcval >> 7) & 0xf8) | /* b */
692 ((srcval >> 12) & 0x07) ) << (7-(x&7)) );
701 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
702 dstbits += linebytes;
707 } else if (bmpImage->green_mask==0x07e0) {
708 if (bmpImage->red_mask==0xf800) {
709 /* ==== rgb 565 bmp -> pal 1 dib ==== */
710 for (h=0; h<lines; h++) {
715 for (x=0; x<width; x++) {
718 dstval|=(X11DRV_DIB_GetNearestIndex
720 ((srcval >> 8) & 0xf8) | /* r */
721 ((srcval >> 13) & 0x07),
722 ((srcval >> 3) & 0xfc) | /* g */
723 ((srcval >> 9) & 0x03),
724 ((srcval << 3) & 0xf8) | /* b */
725 ((srcval >> 2) & 0x07) ) << (7-(x&7)) );
734 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
735 dstbits += linebytes;
737 } else if (bmpImage->blue_mask==0xf800) {
738 /* ==== bgr 565 bmp -> pal 1 dib ==== */
739 for (h=0; h<lines; h++) {
744 for (x=0; x<width; x++) {
747 dstval|=(X11DRV_DIB_GetNearestIndex
749 ((srcval << 3) & 0xf8) | /* r */
750 ((srcval >> 2) & 0x07),
751 ((srcval >> 3) & 0xfc) | /* g */
752 ((srcval >> 9) & 0x03),
753 ((srcval >> 8) & 0xf8) | /* b */
754 ((srcval >> 13) & 0x07) ) << (7-(x&7)) );
763 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
764 dstbits += linebytes;
783 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
784 bytes_per_pixel=(bmpImage->bits_per_pixel==24?3:4);
786 if (bmpImage->green_mask!=0x00ff00 ||
787 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
789 } else if (bmpImage->blue_mask==0xff) {
790 /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */
791 for (h=0; h<lines; h++) {
796 for (x=0; x<width; x++) {
797 dstval|=(X11DRV_DIB_GetNearestIndex
801 srcbyte[0]) << (7-(x&7)) );
802 srcbyte+=bytes_per_pixel;
811 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
812 dstbits += linebytes;
815 /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */
816 for (h=0; h<lines; h++) {
821 for (x=0; x<width; x++) {
822 dstval|=(X11DRV_DIB_GetNearestIndex
826 srcbyte[2]) << (7-(x&7)) );
827 srcbyte+=bytes_per_pixel;
836 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
837 dstbits += linebytes;
848 unsigned long white = (1 << bmpImage->bits_per_pixel) - 1;
850 /* ==== any bmp format -> pal 1 dib ==== */
851 if ((unsigned)colors[0].rgbRed+colors[0].rgbGreen+colors[0].rgbBlue >=
852 (unsigned)colors[1].rgbRed+colors[1].rgbGreen+colors[1].rgbBlue )
855 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, "
856 "%s color mapping\n",
857 bmpImage->bits_per_pixel, bmpImage->red_mask,
858 bmpImage->green_mask, bmpImage->blue_mask,
859 neg?"negative":"direct" );
861 for (h=lines-1; h>=0; h--) {
865 for (x=0; x<width; x++) {
866 dstval|=((XGetPixel( bmpImage, x, h) >= white) ^ neg) << (7 - (x&7));
875 dstbits += linebytes;
882 /***********************************************************************
883 * X11DRV_DIB_SetImageBits_4
885 * SetDIBits for a 4-bit deep DIB.
887 static void X11DRV_DIB_SetImageBits_4( int lines, const BYTE *srcbits,
888 DWORD srcwidth, DWORD dstwidth, int left,
889 int *colors, XImage *bmpImage, DWORD linebytes)
897 srcbits = srcbits + linebytes * (lines - 1);
898 linebytes = -linebytes;
905 srcbits += left >> 1;
906 width = min(srcwidth, dstwidth);
908 /* ==== pal 4 dib -> any bmp format ==== */
909 for (h = lines-1; h >= 0; h--) {
911 for (i = width/2, x = left; i > 0; i--) {
912 BYTE srcval=*srcbyte++;
913 XPutPixel( bmpImage, x++, h, colors[srcval >> 4] );
914 XPutPixel( bmpImage, x++, h, colors[srcval & 0x0f] );
917 XPutPixel( bmpImage, x, h, colors[*srcbyte >> 4] );
918 srcbits += linebytes;
924 /***********************************************************************
925 * X11DRV_DIB_GetImageBits_4
927 * GetDIBits for a 4-bit deep DIB.
929 static void X11DRV_DIB_GetImageBits_4( int lines, BYTE *dstbits,
930 DWORD srcwidth, DWORD dstwidth,
931 RGBQUAD *colors, PALETTEENTRY *srccolors,
932 XImage *bmpImage, DWORD linebytes )
935 int h, width = min(srcwidth, dstwidth);
941 dstbits = dstbits + ( linebytes * (lines-1) );
942 linebytes = -linebytes;
947 switch (bmpImage->depth) {
950 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
952 /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */
955 for (h = lines-1; h >= 0; h--) {
959 for (x = 0; x < width; x++) {
961 srcval=srccolors[XGetPixel(bmpImage, x, h)];
962 dstval|=(X11DRV_DIB_GetNearestIndex
966 srcval.peBlue) << (4-((x&1)<<2)));
975 dstbits += linebytes;
983 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
985 /* ==== pal 8 bmp -> pal 4 dib ==== */
987 const BYTE *srcpixel;
990 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
991 for (h=0; h<lines; h++) {
996 for (x=0; x<width; x++) {
998 srcval = srccolors[(int)*srcpixel++];
999 dstval|=(X11DRV_DIB_GetNearestIndex
1003 srcval.peBlue) << (4*(1-(x&1))) );
1012 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1013 dstbits += linebytes;
1023 const void* srcbits;
1024 const WORD* srcpixel;
1027 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1029 if (bmpImage->green_mask==0x03e0) {
1030 if (bmpImage->red_mask==0x7c00) {
1031 /* ==== rgb 555 bmp -> pal 4 dib ==== */
1032 for (h=0; h<lines; h++) {
1037 for (x=0; x<width; x++) {
1040 dstval|=(X11DRV_DIB_GetNearestIndex
1042 ((srcval >> 7) & 0xf8) | /* r */
1043 ((srcval >> 12) & 0x07),
1044 ((srcval >> 2) & 0xf8) | /* g */
1045 ((srcval >> 7) & 0x07),
1046 ((srcval << 3) & 0xf8) | /* b */
1047 ((srcval >> 2) & 0x07) ) << ((1-(x&1))<<2) );
1056 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1057 dstbits += linebytes;
1059 } else if (bmpImage->blue_mask==0x7c00) {
1060 /* ==== bgr 555 bmp -> pal 4 dib ==== */
1061 for (h=0; h<lines; h++) {
1066 for (x=0; x<width; x++) {
1069 dstval|=(X11DRV_DIB_GetNearestIndex
1071 ((srcval << 3) & 0xf8) | /* r */
1072 ((srcval >> 2) & 0x07),
1073 ((srcval >> 2) & 0xf8) | /* g */
1074 ((srcval >> 7) & 0x07),
1075 ((srcval >> 7) & 0xf8) | /* b */
1076 ((srcval >> 12) & 0x07) ) << ((1-(x&1))<<2) );
1085 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1086 dstbits += linebytes;
1091 } else if (bmpImage->green_mask==0x07e0) {
1092 if (bmpImage->red_mask==0xf800) {
1093 /* ==== rgb 565 bmp -> pal 4 dib ==== */
1094 for (h=0; h<lines; h++) {
1099 for (x=0; x<width; x++) {
1102 dstval|=(X11DRV_DIB_GetNearestIndex
1104 ((srcval >> 8) & 0xf8) | /* r */
1105 ((srcval >> 13) & 0x07),
1106 ((srcval >> 3) & 0xfc) | /* g */
1107 ((srcval >> 9) & 0x03),
1108 ((srcval << 3) & 0xf8) | /* b */
1109 ((srcval >> 2) & 0x07) ) << ((1-(x&1))<<2) );
1118 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1119 dstbits += linebytes;
1121 } else if (bmpImage->blue_mask==0xf800) {
1122 /* ==== bgr 565 bmp -> pal 4 dib ==== */
1123 for (h=0; h<lines; h++) {
1128 for (x=0; x<width; x++) {
1131 dstval|=(X11DRV_DIB_GetNearestIndex
1133 ((srcval << 3) & 0xf8) | /* r */
1134 ((srcval >> 2) & 0x07),
1135 ((srcval >> 3) & 0xfc) | /* g */
1136 ((srcval >> 9) & 0x03),
1137 ((srcval >> 8) & 0xf8) | /* b */
1138 ((srcval >> 13) & 0x07) ) << ((1-(x&1))<<2) );
1147 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1148 dstbits += linebytes;
1160 if (bmpImage->bits_per_pixel==24) {
1161 const void* srcbits;
1162 const BYTE *srcbyte;
1165 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1167 if (bmpImage->green_mask!=0x00ff00 ||
1168 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1170 } else if (bmpImage->blue_mask==0xff) {
1171 /* ==== rgb 888 bmp -> pal 4 dib ==== */
1172 for (h=0; h<lines; h++) {
1175 for (x=0; x<width/2; x++) {
1176 /* Do 2 pixels at a time */
1177 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1182 X11DRV_DIB_GetNearestIndex
1190 /* And the the odd pixel */
1191 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1197 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1198 dstbits += linebytes;
1201 /* ==== bgr 888 bmp -> pal 4 dib ==== */
1202 for (h=0; h<lines; h++) {
1205 for (x=0; x<width/2; x++) {
1206 /* Do 2 pixels at a time */
1207 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1212 X11DRV_DIB_GetNearestIndex
1220 /* And the the odd pixel */
1221 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1227 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1228 dstbits += linebytes;
1237 const void* srcbits;
1238 const BYTE *srcbyte;
1241 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1243 if (bmpImage->green_mask!=0x00ff00 ||
1244 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1246 } else if (bmpImage->blue_mask==0xff) {
1247 /* ==== rgb 0888 bmp -> pal 4 dib ==== */
1248 for (h=0; h<lines; h++) {
1251 for (x=0; x<width/2; x++) {
1252 /* Do 2 pixels at a time */
1253 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1258 X11DRV_DIB_GetNearestIndex
1266 /* And the the odd pixel */
1267 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1273 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1274 dstbits += linebytes;
1277 /* ==== bgr 0888 bmp -> pal 4 dib ==== */
1278 for (h=0; h<lines; h++) {
1281 for (x=0; x<width/2; x++) {
1282 /* Do 2 pixels at a time */
1283 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1288 X11DRV_DIB_GetNearestIndex
1296 /* And the the odd pixel */
1297 *dstbyte++=(X11DRV_DIB_GetNearestIndex
1303 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1304 dstbits += linebytes;
1315 /* ==== any bmp format -> pal 4 dib ==== */
1316 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n",
1317 bmpImage->bits_per_pixel, bmpImage->red_mask,
1318 bmpImage->green_mask, bmpImage->blue_mask );
1319 for (h=lines-1; h>=0; h--) {
1321 for (x=0; x<(width & ~1); x+=2) {
1322 *dstbyte++=(X11DRV_DIB_MapColor((int*)colors, 16, XGetPixel(bmpImage, x, h), 0) << 4) |
1323 X11DRV_DIB_MapColor((int*)colors, 16, XGetPixel(bmpImage, x+1, h), 0);
1326 *dstbyte=(X11DRV_DIB_MapColor((int *)colors, 16, XGetPixel(bmpImage, x, h), 0) << 4);
1328 dstbits += linebytes;
1335 /***********************************************************************
1336 * X11DRV_DIB_SetImageBits_RLE4
1338 * SetDIBits for a 4-bit deep compressed DIB.
1340 static void X11DRV_DIB_SetImageBits_RLE4( int lines, const BYTE *bits,
1341 DWORD srcwidth, DWORD dstwidth,
1342 int left, int *colors,
1345 unsigned int x = 0, width = min(srcwidth, dstwidth);
1346 int y = lines - 1, c, length;
1347 const BYTE *begin = bits;
1352 if (length) { /* encoded */
1355 if (x >= (left + width)) break;
1356 if( x >= left) XPutPixel(bmpImage, x, y, colors[c >> 4]);
1358 if (!length--) break;
1359 if (x >= (left + width)) break;
1360 if( x >= left) XPutPixel(bmpImage, x, y, colors[c & 0xf]);
1380 default: /* absolute */
1383 if (x >= left && x < (left + width))
1384 XPutPixel(bmpImage, x, y, colors[c >> 4]);
1386 if (!length--) break;
1387 if (x >= left && x < (left + width))
1388 XPutPixel(bmpImage, x, y, colors[c & 0xf]);
1391 if ((bits - begin) & 1)
1400 /***********************************************************************
1401 * X11DRV_DIB_SetImageBits_8
1403 * SetDIBits for an 8-bit deep DIB.
1405 static void X11DRV_DIB_SetImageBits_8( int lines, const BYTE *srcbits,
1406 DWORD srcwidth, DWORD dstwidth, int left,
1407 const int *colors, XImage *bmpImage,
1411 int h, width = min(srcwidth, dstwidth);
1412 const BYTE* srcbyte;
1418 srcbits = srcbits + linebytes * (lines-1);
1419 linebytes = -linebytes;
1424 switch (bmpImage->depth) {
1427 #if defined(__i386__) && defined(__GNUC__)
1428 /* Some X servers might have 32 bit/ 16bit deep pixel */
1429 if (lines && width && (bmpImage->bits_per_pixel == 16) &&
1430 (ImageByteOrder(gdi_display)==LSBFirst) )
1432 dstbits=(BYTE*)bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line;
1433 /* FIXME: Does this really handle all these cases correctly? */
1434 /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */
1435 for (h = lines ; h--; ) {
1436 int _cl1,_cl2; /* temp outputs for asm below */
1437 /* Borrowed from DirectDraw */
1438 __asm__ __volatile__(
1443 " movw (%%edx,%%eax,4),%%ax\n"
1445 " xor %%eax,%%eax\n"
1447 :"=S" (srcbyte), "=D" (_cl1), "=c" (_cl2)
1452 :"eax", "cc", "memory"
1454 srcbyte = (srcbits += linebytes);
1455 dstbits -= bmpImage->bytes_per_line;
1463 #if defined(__i386__) && defined(__GNUC__)
1464 if (lines && width && (bmpImage->bits_per_pixel == 32) &&
1465 (ImageByteOrder(gdi_display)==LSBFirst) )
1467 dstbits=(BYTE*)bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line;
1468 /* FIXME: Does this really handle both cases correctly? */
1469 /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */
1470 for (h = lines ; h--; ) {
1471 int _cl1,_cl2; /* temp outputs for asm below */
1472 /* Borrowed from DirectDraw */
1473 __asm__ __volatile__(
1478 " movl (%%edx,%%eax,4),%%eax\n"
1480 " xor %%eax,%%eax\n"
1482 :"=S" (srcbyte), "=D" (_cl1), "=c" (_cl2)
1487 :"eax", "cc", "memory"
1489 srcbyte = (srcbits += linebytes);
1490 dstbits -= bmpImage->bytes_per_line;
1497 break; /* use slow generic case below */
1500 /* ==== pal 8 dib -> any bmp format ==== */
1501 for (h=lines-1; h>=0; h--) {
1502 for (x=left; x<width+left; x++) {
1503 XPutPixel(bmpImage, x, h, colors[*srcbyte++]);
1505 srcbyte = (srcbits += linebytes);
1509 /***********************************************************************
1510 * X11DRV_DIB_GetImageBits_8
1512 * GetDIBits for an 8-bit deep DIB.
1514 static void X11DRV_DIB_GetImageBits_8( int lines, BYTE *dstbits,
1515 DWORD srcwidth, DWORD dstwidth,
1516 RGBQUAD *colors, PALETTEENTRY *srccolors,
1517 XImage *bmpImage, DWORD linebytes )
1520 int h, width = min(srcwidth, dstwidth);
1526 dstbits = dstbits + ( linebytes * (lines-1) );
1527 linebytes = -linebytes;
1532 * This condition is true when GetImageBits has been called by
1533 * UpdateDIBSection. For now, GetNearestIndex is too slow to support
1534 * 256 colormaps, so we'll just use it for GetDIBits calls.
1535 * (In some cases, in an updateDIBSection, the returned colors are bad too)
1537 if (!srccolors) goto updatesection;
1539 switch (bmpImage->depth) {
1542 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
1545 /* ==== pal 1 bmp -> pal 8 dib ==== */
1546 /* ==== pal 4 bmp -> pal 8 dib ==== */
1547 for (h=lines-1; h>=0; h--) {
1549 for (x=0; x<width; x++) {
1550 PALETTEENTRY srcval;
1551 srcval=srccolors[XGetPixel(bmpImage, x, h)];
1552 *dstbyte++=X11DRV_DIB_GetNearestIndex(colors, 256,
1557 dstbits += linebytes;
1565 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
1567 /* ==== pal 8 bmp -> pal 8 dib ==== */
1568 const void* srcbits;
1569 const BYTE* srcpixel;
1571 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1572 for (h=0; h<lines; h++) {
1575 for (x = 0; x < width; x++) {
1576 PALETTEENTRY srcval;
1577 srcval=srccolors[(int)*srcpixel++];
1578 *dstbyte++=X11DRV_DIB_GetNearestIndex(colors, 256,
1583 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1584 dstbits += linebytes;
1594 const void* srcbits;
1595 const WORD* srcpixel;
1598 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1600 if (bmpImage->green_mask==0x03e0) {
1601 if (bmpImage->red_mask==0x7c00) {
1602 /* ==== rgb 555 bmp -> pal 8 dib ==== */
1603 for (h=0; h<lines; h++) {
1606 for (x=0; x<width; x++) {
1609 *dstbyte++=X11DRV_DIB_GetNearestIndex
1611 ((srcval >> 7) & 0xf8) | /* r */
1612 ((srcval >> 12) & 0x07),
1613 ((srcval >> 2) & 0xf8) | /* g */
1614 ((srcval >> 7) & 0x07),
1615 ((srcval << 3) & 0xf8) | /* b */
1616 ((srcval >> 2) & 0x07) );
1618 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1619 dstbits += linebytes;
1621 } else if (bmpImage->blue_mask==0x7c00) {
1622 /* ==== bgr 555 bmp -> pal 8 dib ==== */
1623 for (h=0; h<lines; h++) {
1626 for (x=0; x<width; x++) {
1629 *dstbyte++=X11DRV_DIB_GetNearestIndex
1631 ((srcval << 3) & 0xf8) | /* r */
1632 ((srcval >> 2) & 0x07),
1633 ((srcval >> 2) & 0xf8) | /* g */
1634 ((srcval >> 7) & 0x07),
1635 ((srcval >> 7) & 0xf8) | /* b */
1636 ((srcval >> 12) & 0x07) );
1638 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1639 dstbits += linebytes;
1644 } else if (bmpImage->green_mask==0x07e0) {
1645 if (bmpImage->red_mask==0xf800) {
1646 /* ==== rgb 565 bmp -> pal 8 dib ==== */
1647 for (h=0; h<lines; h++) {
1650 for (x=0; x<width; x++) {
1653 *dstbyte++=X11DRV_DIB_GetNearestIndex
1655 ((srcval >> 8) & 0xf8) | /* r */
1656 ((srcval >> 13) & 0x07),
1657 ((srcval >> 3) & 0xfc) | /* g */
1658 ((srcval >> 9) & 0x03),
1659 ((srcval << 3) & 0xf8) | /* b */
1660 ((srcval >> 2) & 0x07) );
1662 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1663 dstbits += linebytes;
1665 } else if (bmpImage->blue_mask==0xf800) {
1666 /* ==== bgr 565 bmp -> pal 8 dib ==== */
1667 for (h=0; h<lines; h++) {
1670 for (x=0; x<width; x++) {
1673 *dstbyte++=X11DRV_DIB_GetNearestIndex
1675 ((srcval << 3) & 0xf8) | /* r */
1676 ((srcval >> 2) & 0x07),
1677 ((srcval >> 3) & 0xfc) | /* g */
1678 ((srcval >> 9) & 0x03),
1679 ((srcval >> 8) & 0xf8) | /* b */
1680 ((srcval >> 13) & 0x07) );
1682 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1683 dstbits += linebytes;
1697 const void* srcbits;
1698 const BYTE *srcbyte;
1700 int bytes_per_pixel;
1702 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
1703 bytes_per_pixel=(bmpImage->bits_per_pixel==24?3:4);
1705 if (bmpImage->green_mask!=0x00ff00 ||
1706 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1708 } else if (bmpImage->blue_mask==0xff) {
1709 /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */
1710 for (h=0; h<lines; h++) {
1713 for (x=0; x<width; x++) {
1714 *dstbyte++=X11DRV_DIB_GetNearestIndex
1719 srcbyte+=bytes_per_pixel;
1721 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1722 dstbits += linebytes;
1725 /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */
1726 for (h=0; h<lines; h++) {
1729 for (x=0; x<width; x++) {
1730 *dstbyte++=X11DRV_DIB_GetNearestIndex
1735 srcbyte+=bytes_per_pixel;
1737 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
1738 dstbits += linebytes;
1746 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
1747 bmpImage->depth, bmpImage->red_mask,
1748 bmpImage->green_mask, bmpImage->blue_mask );
1750 /* ==== any bmp format -> pal 8 dib ==== */
1751 for (h=lines-1; h>=0; h--) {
1753 for (x=0; x<width; x++) {
1754 *dstbyte=X11DRV_DIB_MapColor
1756 XGetPixel(bmpImage, x, h), *dstbyte);
1759 dstbits += linebytes;
1765 /***********************************************************************
1766 * X11DRV_DIB_SetImageBits_RLE8
1768 * SetDIBits for an 8-bit deep compressed DIB.
1770 * This function rewritten 941113 by James Youngman. WINE blew out when I
1771 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
1773 * This was because the algorithm assumed that all RLE8 bitmaps end with the
1774 * 'End of bitmap' escape code. This code is very much laxer in what it
1775 * allows to end the expansion. Possibly too lax. See the note by
1776 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
1777 * bitmap should end with RleEnd, but on the other hand, software exists
1778 * that produces ones that don't and Windows 3.1 doesn't complain a bit
1781 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
1782 * James A. Youngman <mbcstjy@afs.man.ac.uk>
1785 static void X11DRV_DIB_SetImageBits_RLE8( int lines, const BYTE *bits,
1786 DWORD srcwidth, DWORD dstwidth,
1787 int left, int *colors,
1790 unsigned int x; /* X-position on each line. Increases. */
1791 int y; /* Line #. Starts at lines-1, decreases */
1792 const BYTE *pIn = bits; /* Pointer to current position in bits */
1793 BYTE length; /* The length pf a run */
1794 BYTE escape_code; /* See enum Rle8_EscapeCodes.*/
1797 * Note that the bitmap data is stored by Windows starting at the
1798 * bottom line of the bitmap and going upwards. Within each line,
1799 * the data is stored left-to-right. That's the reason why line
1800 * goes from lines-1 to 0. [JAY]
1810 * If the length byte is not zero (which is the escape value),
1811 * We have a run of length pixels all the same colour. The colour
1812 * index is stored next.
1814 * If the length byte is zero, we need to read the next byte to
1815 * know what to do. [JAY]
1820 * [Run-Length] Encoded mode
1822 int color = colors[*pIn++];
1823 while (length-- && x < (left + dstwidth)) {
1824 if( x >= left) XPutPixel(bmpImage, x, y, color);
1831 * Escape codes (may be an absolute sequence though)
1833 escape_code = (*pIn++);
1842 /* Not all RLE8 bitmaps end with this code. For
1843 * example, Paint Shop Pro produces some that don't.
1844 * That's (I think) what caused the previous
1845 * implementation to fail. [JAY]
1854 default: /* switch to absolute mode */
1855 length = escape_code;
1858 int color = colors[*pIn++];
1859 if (x >= (left + dstwidth))
1864 if( x >= left) XPutPixel(bmpImage, x, y, color);
1868 * If you think for a moment you'll realise that the
1869 * only time we could ever possibly read an odd
1870 * number of bytes is when there is a 0x00 (escape),
1871 * a value >0x02 (absolute mode) and then an odd-
1872 * length run. Therefore this is the only place we
1873 * need to worry about it. Everywhere else the
1874 * bytes are always read in pairs. [JAY]
1876 if (escape_code & 1) pIn++; /* Throw away the pad byte. */
1878 } /* switch (escape_code) : Escape sequence */
1884 /***********************************************************************
1885 * X11DRV_DIB_SetImageBits_16
1887 * SetDIBits for a 16-bit deep DIB.
1889 static void X11DRV_DIB_SetImageBits_16( int lines, const BYTE *srcbits,
1890 DWORD srcwidth, DWORD dstwidth, int left,
1891 X11DRV_PDEVICE *physDev, DWORD rSrc, DWORD gSrc, DWORD bSrc,
1892 XImage *bmpImage, DWORD linebytes )
1895 int h, width = min(srcwidth, dstwidth);
1896 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap;
1901 srcbits = srcbits + ( linebytes * (lines-1));
1902 linebytes = -linebytes;
1905 switch (bmpImage->depth)
1912 srcbits=srcbits+left*2;
1913 dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line;
1915 if (bmpImage->green_mask==0x03e0) {
1916 if (gSrc==bmpImage->green_mask) {
1917 if (rSrc==bmpImage->red_mask) {
1918 /* ==== rgb 555 dib -> rgb 555 bmp ==== */
1919 /* ==== bgr 555 dib -> bgr 555 bmp ==== */
1920 convs->Convert_5x5_asis
1923 dstbits,-bmpImage->bytes_per_line);
1924 } else if (rSrc==bmpImage->blue_mask) {
1925 /* ==== rgb 555 dib -> bgr 555 bmp ==== */
1926 /* ==== bgr 555 dib -> rgb 555 bmp ==== */
1927 convs->Convert_555_reverse
1930 dstbits,-bmpImage->bytes_per_line);
1933 if (rSrc==bmpImage->red_mask || bSrc==bmpImage->blue_mask) {
1934 /* ==== rgb 565 dib -> rgb 555 bmp ==== */
1935 /* ==== bgr 565 dib -> bgr 555 bmp ==== */
1936 convs->Convert_565_to_555_asis
1939 dstbits,-bmpImage->bytes_per_line);
1941 /* ==== rgb 565 dib -> bgr 555 bmp ==== */
1942 /* ==== bgr 565 dib -> rgb 555 bmp ==== */
1943 convs->Convert_565_to_555_reverse
1946 dstbits,-bmpImage->bytes_per_line);
1949 } else if (bmpImage->green_mask==0x07e0) {
1950 if (gSrc==bmpImage->green_mask) {
1951 if (rSrc==bmpImage->red_mask) {
1952 /* ==== rgb 565 dib -> rgb 565 bmp ==== */
1953 /* ==== bgr 565 dib -> bgr 565 bmp ==== */
1954 convs->Convert_5x5_asis
1957 dstbits,-bmpImage->bytes_per_line);
1959 /* ==== rgb 565 dib -> bgr 565 bmp ==== */
1960 /* ==== bgr 565 dib -> rgb 565 bmp ==== */
1961 convs->Convert_565_reverse
1964 dstbits,-bmpImage->bytes_per_line);
1967 if (rSrc==bmpImage->red_mask || bSrc==bmpImage->blue_mask) {
1968 /* ==== rgb 555 dib -> rgb 565 bmp ==== */
1969 /* ==== bgr 555 dib -> bgr 565 bmp ==== */
1970 convs->Convert_555_to_565_asis
1973 dstbits,-bmpImage->bytes_per_line);
1975 /* ==== rgb 555 dib -> bgr 565 bmp ==== */
1976 /* ==== bgr 555 dib -> rgb 565 bmp ==== */
1977 convs->Convert_555_to_565_reverse
1980 dstbits,-bmpImage->bytes_per_line);
1990 if (bmpImage->bits_per_pixel==24) {
1993 srcbits=srcbits+left*2;
1994 dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line;
1996 if (bmpImage->green_mask!=0x00ff00 ||
1997 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
1999 } else if ((rSrc==0x1f && bmpImage->red_mask==0xff) ||
2000 (bSrc==0x1f && bmpImage->blue_mask==0xff)) {
2002 /* ==== rgb 555 dib -> rgb 888 bmp ==== */
2003 /* ==== bgr 555 dib -> bgr 888 bmp ==== */
2004 convs->Convert_555_to_888_asis
2007 dstbits,-bmpImage->bytes_per_line);
2009 /* ==== rgb 565 dib -> rgb 888 bmp ==== */
2010 /* ==== bgr 565 dib -> bgr 888 bmp ==== */
2011 convs->Convert_565_to_888_asis
2014 dstbits,-bmpImage->bytes_per_line);
2018 /* ==== rgb 555 dib -> bgr 888 bmp ==== */
2019 /* ==== bgr 555 dib -> rgb 888 bmp ==== */
2020 convs->Convert_555_to_888_reverse
2023 dstbits,-bmpImage->bytes_per_line);
2025 /* ==== rgb 565 dib -> bgr 888 bmp ==== */
2026 /* ==== bgr 565 dib -> rgb 888 bmp ==== */
2027 convs->Convert_565_to_888_reverse
2030 dstbits,-bmpImage->bytes_per_line);
2041 srcbits=srcbits+left*2;
2042 dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line;
2044 if (bmpImage->green_mask!=0x00ff00 ||
2045 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2047 } else if ((rSrc==0x1f && bmpImage->red_mask==0xff) ||
2048 (bSrc==0x1f && bmpImage->blue_mask==0xff)) {
2050 /* ==== rgb 555 dib -> rgb 0888 bmp ==== */
2051 /* ==== bgr 555 dib -> bgr 0888 bmp ==== */
2052 convs->Convert_555_to_0888_asis
2055 dstbits,-bmpImage->bytes_per_line);
2057 /* ==== rgb 565 dib -> rgb 0888 bmp ==== */
2058 /* ==== bgr 565 dib -> bgr 0888 bmp ==== */
2059 convs->Convert_565_to_0888_asis
2062 dstbits,-bmpImage->bytes_per_line);
2066 /* ==== rgb 555 dib -> bgr 0888 bmp ==== */
2067 /* ==== bgr 555 dib -> rgb 0888 bmp ==== */
2068 convs->Convert_555_to_0888_reverse
2071 dstbits,-bmpImage->bytes_per_line);
2073 /* ==== rgb 565 dib -> bgr 0888 bmp ==== */
2074 /* ==== bgr 565 dib -> rgb 0888 bmp ==== */
2075 convs->Convert_565_to_0888_reverse
2078 dstbits,-bmpImage->bytes_per_line);
2086 WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2087 rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask,
2088 bmpImage->green_mask, bmpImage->blue_mask );
2094 /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */
2095 const WORD* srcpixel;
2096 int rShift1,gShift1,bShift1;
2097 int rShift2,gShift2,bShift2;
2100 /* Set color scaling values */
2101 rShift1=16+X11DRV_DIB_MaskToShift(rSrc)-3;
2102 gShift1=16+X11DRV_DIB_MaskToShift(gSrc)-3;
2103 bShift1=16+X11DRV_DIB_MaskToShift(bSrc)-3;
2108 /* Green has 5 bits, like the others */
2112 /* Green has 6 bits, not 5. Compensate. */
2121 /* We could split it into four separate cases to optimize
2122 * but it is probably not worth it.
2124 for (h=lines-1; h>=0; h--) {
2125 srcpixel=(const WORD*)srcbits;
2126 for (x=left; x<width+left; x++) {
2128 BYTE red,green,blue;
2129 srcval=*srcpixel++ << 16;
2130 red= ((srcval >> rShift1) & 0xf8) |
2131 ((srcval >> rShift2) & 0x07);
2132 green=((srcval >> gShift1) & gMask1) |
2133 ((srcval >> gShift2) & gMask2);
2134 blue= ((srcval >> bShift1) & 0xf8) |
2135 ((srcval >> bShift2) & 0x07);
2136 XPutPixel(bmpImage, x, h,
2137 X11DRV_PALETTE_ToPhysical
2138 (physDev, RGB(red,green,blue)));
2140 srcbits += linebytes;
2148 /***********************************************************************
2149 * X11DRV_DIB_GetImageBits_16
2151 * GetDIBits for an 16-bit deep DIB.
2153 static void X11DRV_DIB_GetImageBits_16( int lines, BYTE *dstbits,
2154 DWORD dstwidth, DWORD srcwidth,
2155 PALETTEENTRY *srccolors,
2156 DWORD rDst, DWORD gDst, DWORD bDst,
2157 XImage *bmpImage, DWORD dibpitch )
2160 int h, width = min(srcwidth, dstwidth);
2161 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap;
2163 DWORD linebytes = dibpitch;
2168 dstbits = dstbits + ( linebytes * (lines-1));
2169 linebytes = -linebytes;
2172 switch (bmpImage->depth)
2177 const char* srcbits;
2179 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2181 if (bmpImage->green_mask==0x03e0) {
2182 if (gDst==bmpImage->green_mask) {
2183 if (rDst==bmpImage->red_mask) {
2184 /* ==== rgb 555 bmp -> rgb 555 dib ==== */
2185 /* ==== bgr 555 bmp -> bgr 555 dib ==== */
2186 convs->Convert_5x5_asis
2188 srcbits,-bmpImage->bytes_per_line,
2191 /* ==== rgb 555 bmp -> bgr 555 dib ==== */
2192 /* ==== bgr 555 bmp -> rgb 555 dib ==== */
2193 convs->Convert_555_reverse
2195 srcbits,-bmpImage->bytes_per_line,
2199 if (rDst==bmpImage->red_mask || bDst==bmpImage->blue_mask) {
2200 /* ==== rgb 555 bmp -> rgb 565 dib ==== */
2201 /* ==== bgr 555 bmp -> bgr 565 dib ==== */
2202 convs->Convert_555_to_565_asis
2204 srcbits,-bmpImage->bytes_per_line,
2207 /* ==== rgb 555 bmp -> bgr 565 dib ==== */
2208 /* ==== bgr 555 bmp -> rgb 565 dib ==== */
2209 convs->Convert_555_to_565_reverse
2211 srcbits,-bmpImage->bytes_per_line,
2215 } else if (bmpImage->green_mask==0x07e0) {
2216 if (gDst==bmpImage->green_mask) {
2217 if (rDst == bmpImage->red_mask) {
2218 /* ==== rgb 565 bmp -> rgb 565 dib ==== */
2219 /* ==== bgr 565 bmp -> bgr 565 dib ==== */
2220 convs->Convert_5x5_asis
2222 srcbits,-bmpImage->bytes_per_line,
2225 /* ==== rgb 565 bmp -> bgr 565 dib ==== */
2226 /* ==== bgr 565 bmp -> rgb 565 dib ==== */
2227 convs->Convert_565_reverse
2229 srcbits,-bmpImage->bytes_per_line,
2233 if (rDst==bmpImage->red_mask || bDst==bmpImage->blue_mask) {
2234 /* ==== rgb 565 bmp -> rgb 555 dib ==== */
2235 /* ==== bgr 565 bmp -> bgr 555 dib ==== */
2236 convs->Convert_565_to_555_asis
2238 srcbits,-bmpImage->bytes_per_line,
2241 /* ==== rgb 565 bmp -> bgr 555 dib ==== */
2242 /* ==== bgr 565 bmp -> rgb 555 dib ==== */
2243 convs->Convert_565_to_555_reverse
2245 srcbits,-bmpImage->bytes_per_line,
2256 if (bmpImage->bits_per_pixel == 24) {
2257 const char* srcbits;
2259 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2261 if (bmpImage->green_mask!=0x00ff00 ||
2262 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2264 } else if ((rDst==0x1f && bmpImage->red_mask==0xff) ||
2265 (bDst==0x1f && bmpImage->blue_mask==0xff)) {
2267 /* ==== rgb 888 bmp -> rgb 555 dib ==== */
2268 /* ==== bgr 888 bmp -> bgr 555 dib ==== */
2269 convs->Convert_888_to_555_asis
2271 srcbits,-bmpImage->bytes_per_line,
2274 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2275 /* ==== rgb 888 bmp -> rgb 565 dib ==== */
2276 convs->Convert_888_to_565_asis
2278 srcbits,-bmpImage->bytes_per_line,
2283 /* ==== rgb 888 bmp -> bgr 555 dib ==== */
2284 /* ==== bgr 888 bmp -> rgb 555 dib ==== */
2285 convs->Convert_888_to_555_reverse
2287 srcbits,-bmpImage->bytes_per_line,
2290 /* ==== rgb 888 bmp -> bgr 565 dib ==== */
2291 /* ==== bgr 888 bmp -> rgb 565 dib ==== */
2292 convs->Convert_888_to_565_reverse
2294 srcbits,-bmpImage->bytes_per_line,
2304 const char* srcbits;
2306 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2308 if (bmpImage->green_mask!=0x00ff00 ||
2309 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2311 } else if ((rDst==0x1f && bmpImage->red_mask==0xff) ||
2312 (bDst==0x1f && bmpImage->blue_mask==0xff)) {
2314 /* ==== rgb 0888 bmp -> rgb 555 dib ==== */
2315 /* ==== bgr 0888 bmp -> bgr 555 dib ==== */
2316 convs->Convert_0888_to_555_asis
2318 srcbits,-bmpImage->bytes_per_line,
2321 /* ==== rgb 0888 bmp -> rgb 565 dib ==== */
2322 /* ==== bgr 0888 bmp -> bgr 565 dib ==== */
2323 convs->Convert_0888_to_565_asis
2325 srcbits,-bmpImage->bytes_per_line,
2330 /* ==== rgb 0888 bmp -> bgr 555 dib ==== */
2331 /* ==== bgr 0888 bmp -> rgb 555 dib ==== */
2332 convs->Convert_0888_to_555_reverse
2334 srcbits,-bmpImage->bytes_per_line,
2337 /* ==== rgb 0888 bmp -> bgr 565 dib ==== */
2338 /* ==== bgr 0888 bmp -> rgb 565 dib ==== */
2339 convs->Convert_0888_to_565_reverse
2341 srcbits,-bmpImage->bytes_per_line,
2350 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
2352 /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */
2353 int rShift,gShift,bShift;
2356 /* Shift everything 16 bits left so that all shifts are >0,
2357 * even for BGR DIBs. Then a single >> 16 will bring everything
2360 rShift=16+X11DRV_DIB_MaskToShift(rDst)-3;
2361 gShift=16+X11DRV_DIB_MaskToShift(gDst)-3;
2362 bShift=16+X11DRV_DIB_MaskToShift(bDst)-3;
2364 /* 6 bits for the green */
2370 for (h = lines - 1; h >= 0; h--) {
2371 dstpixel=(LPWORD)dstbits;
2372 for (x = 0; x < width; x++) {
2373 PALETTEENTRY srcval;
2375 srcval=srccolors[XGetPixel(bmpImage, x, h)];
2376 dstval=((srcval.peRed << rShift) & rDst) |
2377 ((srcval.peGreen << gShift) & gDst) |
2378 ((srcval.peBlue << bShift) & bDst);
2379 *dstpixel++=dstval >> 16;
2381 dstbits += linebytes;
2389 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
2391 /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */
2392 int rShift,gShift,bShift;
2393 const BYTE* srcbits;
2394 const BYTE* srcpixel;
2397 /* Shift everything 16 bits left so that all shifts are >0,
2398 * even for BGR DIBs. Then a single >> 16 will bring everything
2401 rShift=16+X11DRV_DIB_MaskToShift(rDst)-3;
2402 gShift=16+X11DRV_DIB_MaskToShift(gDst)-3;
2403 bShift=16+X11DRV_DIB_MaskToShift(bDst)-3;
2405 /* 6 bits for the green */
2411 srcbits=(BYTE*)bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2412 for (h=0; h<lines; h++) {
2414 dstpixel=(LPWORD)dstbits;
2415 for (x = 0; x < width; x++) {
2416 PALETTEENTRY srcval;
2418 srcval=srccolors[(int)*srcpixel++];
2419 dstval=((srcval.peRed << rShift) & rDst) |
2420 ((srcval.peGreen << gShift) & gDst) |
2421 ((srcval.peBlue << bShift) & bDst);
2422 *dstpixel++=dstval >> 16;
2424 srcbits -= bmpImage->bytes_per_line;
2425 dstbits += linebytes;
2435 /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */
2436 int rShift,gShift,bShift;
2439 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n",
2440 bmpImage->depth, bmpImage->red_mask,
2441 bmpImage->green_mask, bmpImage->blue_mask,
2444 /* Shift everything 16 bits left so that all shifts are >0,
2445 * even for BGR DIBs. Then a single >> 16 will bring everything
2448 rShift=16+X11DRV_DIB_MaskToShift(rDst)-3;
2449 gShift=16+X11DRV_DIB_MaskToShift(gDst)-3;
2450 bShift=16+X11DRV_DIB_MaskToShift(bDst)-3;
2452 /* 6 bits for the green */
2458 for (h = lines - 1; h >= 0; h--) {
2459 dstpixel=(LPWORD)dstbits;
2460 for (x = 0; x < width; x++) {
2463 srcval=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage, x, h));
2464 dstval=((GetRValue(srcval) << rShift) & rDst) |
2465 ((GetGValue(srcval) << gShift) & gDst) |
2466 ((GetBValue(srcval) << bShift) & bDst);
2467 *dstpixel++=dstval >> 16;
2469 dstbits += linebytes;
2477 /***********************************************************************
2478 * X11DRV_DIB_SetImageBits_24
2480 * SetDIBits for a 24-bit deep DIB.
2482 static void X11DRV_DIB_SetImageBits_24( int lines, const BYTE *srcbits,
2483 DWORD srcwidth, DWORD dstwidth, int left,
2484 X11DRV_PDEVICE *physDev,
2485 DWORD rSrc, DWORD gSrc, DWORD bSrc,
2486 XImage *bmpImage, DWORD linebytes )
2489 int h, width = min(srcwidth, dstwidth);
2490 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap;
2495 srcbits = srcbits + linebytes * (lines - 1);
2496 linebytes = -linebytes;
2499 switch (bmpImage->depth)
2502 if (bmpImage->bits_per_pixel==24) {
2505 srcbits=srcbits+left*3;
2506 dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line;
2508 if (bmpImage->green_mask!=0x00ff00 ||
2509 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2511 } else if (rSrc==bmpImage->red_mask) {
2512 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
2513 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
2514 convs->Convert_888_asis
2517 dstbits,-bmpImage->bytes_per_line);
2519 /* ==== rgb 888 dib -> bgr 888 bmp ==== */
2520 /* ==== bgr 888 dib -> rgb 888 bmp ==== */
2521 convs->Convert_888_reverse
2524 dstbits,-bmpImage->bytes_per_line);
2534 srcbits=srcbits+left*3;
2535 dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line;
2537 if (bmpImage->green_mask!=0x00ff00 ||
2538 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2540 } else if (rSrc==bmpImage->red_mask) {
2541 /* ==== rgb 888 dib -> rgb 0888 bmp ==== */
2542 /* ==== bgr 888 dib -> bgr 0888 bmp ==== */
2543 convs->Convert_888_to_0888_asis
2546 dstbits,-bmpImage->bytes_per_line);
2548 /* ==== rgb 888 dib -> bgr 0888 bmp ==== */
2549 /* ==== bgr 888 dib -> rgb 0888 bmp ==== */
2550 convs->Convert_888_to_0888_reverse
2553 dstbits,-bmpImage->bytes_per_line);
2563 srcbits=srcbits+left*3;
2564 dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line;
2566 if (bmpImage->green_mask==0x03e0) {
2567 if ((rSrc==0xff0000 && bmpImage->red_mask==0x7f00) ||
2568 (bSrc==0xff0000 && bmpImage->blue_mask==0x7f00)) {
2569 /* ==== rgb 888 dib -> rgb 555 bmp ==== */
2570 /* ==== bgr 888 dib -> bgr 555 bmp ==== */
2571 convs->Convert_888_to_555_asis
2574 dstbits,-bmpImage->bytes_per_line);
2575 } else if ((rSrc==0xff && bmpImage->red_mask==0x7f00) ||
2576 (bSrc==0xff && bmpImage->blue_mask==0x7f00)) {
2577 /* ==== rgb 888 dib -> bgr 555 bmp ==== */
2578 /* ==== bgr 888 dib -> rgb 555 bmp ==== */
2579 convs->Convert_888_to_555_reverse
2582 dstbits,-bmpImage->bytes_per_line);
2586 } else if (bmpImage->green_mask==0x07e0) {
2587 if ((rSrc==0xff0000 && bmpImage->red_mask==0xf800) ||
2588 (bSrc==0xff0000 && bmpImage->blue_mask==0xf800)) {
2589 /* ==== rgb 888 dib -> rgb 565 bmp ==== */
2590 /* ==== bgr 888 dib -> bgr 565 bmp ==== */
2591 convs->Convert_888_to_565_asis
2594 dstbits,-bmpImage->bytes_per_line);
2595 } else if ((rSrc==0xff && bmpImage->red_mask==0xf800) ||
2596 (bSrc==0xff && bmpImage->blue_mask==0xf800)) {
2597 /* ==== rgb 888 dib -> bgr 565 bmp ==== */
2598 /* ==== bgr 888 dib -> rgb 565 bmp ==== */
2599 convs->Convert_888_to_565_reverse
2602 dstbits,-bmpImage->bytes_per_line);
2614 WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
2615 rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask,
2616 bmpImage->green_mask, bmpImage->blue_mask );
2622 /* ==== rgb 888 dib -> any bmp bormat ==== */
2623 const BYTE* srcbyte;
2625 /* Windows only supports one 24bpp DIB format: RGB888 */
2627 for (h = lines - 1; h >= 0; h--) {
2628 srcbyte=(const BYTE*)srcbits;
2629 for (x = left; x < width+left; x++) {
2630 XPutPixel(bmpImage, x, h,
2631 X11DRV_PALETTE_ToPhysical
2632 (physDev, RGB(srcbyte[2], srcbyte[1], srcbyte[0])));
2635 srcbits += linebytes;
2643 /***********************************************************************
2644 * X11DRV_DIB_GetImageBits_24
2646 * GetDIBits for an 24-bit deep DIB.
2648 static void X11DRV_DIB_GetImageBits_24( int lines, BYTE *dstbits,
2649 DWORD dstwidth, DWORD srcwidth,
2650 PALETTEENTRY *srccolors,
2651 DWORD rDst, DWORD gDst, DWORD bDst,
2652 XImage *bmpImage, DWORD linebytes )
2655 int h, width = min(srcwidth, dstwidth);
2656 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap;
2661 dstbits = dstbits + ( linebytes * (lines-1) );
2662 linebytes = -linebytes;
2665 switch (bmpImage->depth)
2668 if (bmpImage->bits_per_pixel==24) {
2669 const char* srcbits;
2671 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2673 if (bmpImage->green_mask!=0x00ff00 ||
2674 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2676 } else if (rDst==bmpImage->red_mask) {
2677 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
2678 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
2679 convs->Convert_888_asis
2681 srcbits,-bmpImage->bytes_per_line,
2684 /* ==== rgb 888 bmp -> bgr 888 dib ==== */
2685 /* ==== bgr 888 bmp -> rgb 888 dib ==== */
2686 convs->Convert_888_reverse
2688 srcbits,-bmpImage->bytes_per_line,
2697 const char* srcbits;
2699 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2701 if (bmpImage->green_mask!=0x00ff00 ||
2702 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2704 } else if (rDst==bmpImage->red_mask) {
2705 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
2706 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
2707 convs->Convert_0888_to_888_asis
2709 srcbits,-bmpImage->bytes_per_line,
2712 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
2713 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
2714 convs->Convert_0888_to_888_reverse
2716 srcbits,-bmpImage->bytes_per_line,
2725 const char* srcbits;
2727 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2729 if (bmpImage->green_mask==0x03e0) {
2730 if ((rDst==0xff0000 && bmpImage->red_mask==0x7f00) ||
2731 (bDst==0xff0000 && bmpImage->blue_mask==0x7f00)) {
2732 /* ==== rgb 555 bmp -> rgb 888 dib ==== */
2733 /* ==== bgr 555 bmp -> bgr 888 dib ==== */
2734 convs->Convert_555_to_888_asis
2736 srcbits,-bmpImage->bytes_per_line,
2738 } else if ((rDst==0xff && bmpImage->red_mask==0x7f00) ||
2739 (bDst==0xff && bmpImage->blue_mask==0x7f00)) {
2740 /* ==== rgb 555 bmp -> bgr 888 dib ==== */
2741 /* ==== bgr 555 bmp -> rgb 888 dib ==== */
2742 convs->Convert_555_to_888_reverse
2744 srcbits,-bmpImage->bytes_per_line,
2749 } else if (bmpImage->green_mask==0x07e0) {
2750 if ((rDst==0xff0000 && bmpImage->red_mask==0xf800) ||
2751 (bDst==0xff0000 && bmpImage->blue_mask==0xf800)) {
2752 /* ==== rgb 565 bmp -> rgb 888 dib ==== */
2753 /* ==== bgr 565 bmp -> bgr 888 dib ==== */
2754 convs->Convert_565_to_888_asis
2756 srcbits,-bmpImage->bytes_per_line,
2758 } else if ((rDst==0xff && bmpImage->red_mask==0xf800) ||
2759 (bDst==0xff && bmpImage->blue_mask==0xf800)) {
2760 /* ==== rgb 565 bmp -> bgr 888 dib ==== */
2761 /* ==== bgr 565 bmp -> rgb 888 dib ==== */
2762 convs->Convert_565_to_888_reverse
2764 srcbits,-bmpImage->bytes_per_line,
2777 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
2779 /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */
2782 /* Windows only supports one 24bpp DIB format: rgb 888 */
2783 for (h = lines - 1; h >= 0; h--) {
2785 for (x = 0; x < width; x++) {
2786 PALETTEENTRY srcval;
2787 srcval=srccolors[XGetPixel(bmpImage, x, h)];
2788 dstbyte[0]=srcval.peBlue;
2789 dstbyte[1]=srcval.peGreen;
2790 dstbyte[2]=srcval.peRed;
2793 dstbits += linebytes;
2801 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
2803 /* ==== pal 8 bmp -> rgb 888 dib ==== */
2804 const void* srcbits;
2805 const BYTE* srcpixel;
2808 /* Windows only supports one 24bpp DIB format: rgb 888 */
2809 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
2810 for (h = lines - 1; h >= 0; h--) {
2813 for (x = 0; x < width; x++ ) {
2814 PALETTEENTRY srcval;
2815 srcval=srccolors[(int)*srcpixel++];
2816 dstbyte[0]=srcval.peBlue;
2817 dstbyte[1]=srcval.peGreen;
2818 dstbyte[2]=srcval.peRed;
2821 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
2822 dstbits += linebytes;
2832 /* ==== any bmp format -> 888 dib ==== */
2835 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n",
2836 bmpImage->depth, bmpImage->red_mask,
2837 bmpImage->green_mask, bmpImage->blue_mask,
2840 /* Windows only supports one 24bpp DIB format: rgb 888 */
2841 for (h = lines - 1; h >= 0; h--) {
2843 for (x = 0; x < width; x++) {
2844 COLORREF srcval=X11DRV_PALETTE_ToLogical
2845 (XGetPixel( bmpImage, x, h ));
2846 dstbyte[0]=GetBValue(srcval);
2847 dstbyte[1]=GetGValue(srcval);
2848 dstbyte[2]=GetRValue(srcval);
2851 dstbits += linebytes;
2859 /***********************************************************************
2860 * X11DRV_DIB_SetImageBits_32
2862 * SetDIBits for a 32-bit deep DIB.
2864 static void X11DRV_DIB_SetImageBits_32(int lines, const BYTE *srcbits,
2865 DWORD srcwidth, DWORD dstwidth, int left,
2866 X11DRV_PDEVICE *physDev,
2867 DWORD rSrc, DWORD gSrc, DWORD bSrc,
2873 int h, width = min(srcwidth, dstwidth);
2874 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap;
2879 srcbits = srcbits + ( linebytes * (lines-1) );
2880 linebytes = -linebytes;
2883 ptr = (const DWORD *) srcbits + left;
2885 switch (bmpImage->depth)
2888 if (bmpImage->bits_per_pixel==24) {
2891 srcbits=srcbits+left*4;
2892 dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line;
2894 if (rSrc==bmpImage->red_mask && gSrc==bmpImage->green_mask && bSrc==bmpImage->blue_mask) {
2895 /* ==== rgb 0888 dib -> rgb 888 bmp ==== */
2896 /* ==== bgr 0888 dib -> bgr 888 bmp ==== */
2897 convs->Convert_0888_to_888_asis
2900 dstbits,-bmpImage->bytes_per_line);
2901 } else if (bmpImage->green_mask!=0x00ff00 ||
2902 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2904 /* the tests below assume sane bmpImage masks */
2905 } else if (rSrc==bmpImage->blue_mask && gSrc==bmpImage->green_mask && bSrc==bmpImage->red_mask) {
2906 /* ==== rgb 0888 dib -> bgr 888 bmp ==== */
2907 /* ==== bgr 0888 dib -> rgb 888 bmp ==== */
2908 convs->Convert_0888_to_888_reverse
2911 dstbits,-bmpImage->bytes_per_line);
2912 } else if (bmpImage->blue_mask==0xff) {
2913 /* ==== any 0888 dib -> rgb 888 bmp ==== */
2914 convs->Convert_any0888_to_rgb888
2918 dstbits,-bmpImage->bytes_per_line);
2920 /* ==== any 0888 dib -> bgr 888 bmp ==== */
2921 convs->Convert_any0888_to_bgr888
2925 dstbits,-bmpImage->bytes_per_line);
2935 srcbits=srcbits+left*4;
2936 dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line;
2938 if (gSrc==bmpImage->green_mask) {
2939 if (rSrc==bmpImage->red_mask && bSrc==bmpImage->blue_mask) {
2940 /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
2941 /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
2942 convs->Convert_0888_asis
2945 dstbits,-bmpImage->bytes_per_line);
2946 } else if (bmpImage->green_mask!=0x00ff00 ||
2947 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2949 /* the tests below assume sane bmpImage masks */
2950 } else if (rSrc==bmpImage->blue_mask && bSrc==bmpImage->red_mask) {
2951 /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */
2952 /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */
2953 convs->Convert_0888_reverse
2956 dstbits,-bmpImage->bytes_per_line);
2958 /* ==== any 0888 dib -> any 0888 bmp ==== */
2959 convs->Convert_0888_any
2963 dstbits,-bmpImage->bytes_per_line,
2964 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
2966 } else if (bmpImage->green_mask!=0x00ff00 ||
2967 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
2969 /* the tests below assume sane bmpImage masks */
2971 /* ==== any 0888 dib -> any 0888 bmp ==== */
2972 convs->Convert_0888_any
2976 dstbits,-bmpImage->bytes_per_line,
2977 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
2987 srcbits=srcbits+left*4;
2988 dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line;
2990 if (rSrc==0xff0000 && gSrc==0x00ff00 && bSrc==0x0000ff) {
2991 if (bmpImage->green_mask==0x03e0) {
2992 if (bmpImage->red_mask==0x7f00) {
2993 /* ==== rgb 0888 dib -> rgb 555 bmp ==== */
2994 convs->Convert_0888_to_555_asis
2997 dstbits,-bmpImage->bytes_per_line);
2998 } else if (bmpImage->blue_mask==0x7f00) {
2999 /* ==== rgb 0888 dib -> bgr 555 bmp ==== */
3000 convs->Convert_0888_to_555_reverse
3003 dstbits,-bmpImage->bytes_per_line);
3007 } else if (bmpImage->green_mask==0x07e0) {
3008 if (bmpImage->red_mask==0xf800) {
3009 /* ==== rgb 0888 dib -> rgb 565 bmp ==== */
3010 convs->Convert_0888_to_565_asis
3013 dstbits,-bmpImage->bytes_per_line);
3014 } else if (bmpImage->blue_mask==0xf800) {
3015 /* ==== rgb 0888 dib -> bgr 565 bmp ==== */
3016 convs->Convert_0888_to_565_reverse
3019 dstbits,-bmpImage->bytes_per_line);
3026 } else if (rSrc==0x0000ff && gSrc==0x00ff00 && bSrc==0xff0000) {
3027 if (bmpImage->green_mask==0x03e0) {
3028 if (bmpImage->blue_mask==0x7f00) {
3029 /* ==== bgr 0888 dib -> bgr 555 bmp ==== */
3030 convs->Convert_0888_to_555_asis
3033 dstbits,-bmpImage->bytes_per_line);
3034 } else if (bmpImage->red_mask==0x7f00) {
3035 /* ==== bgr 0888 dib -> rgb 555 bmp ==== */
3036 convs->Convert_0888_to_555_reverse
3039 dstbits,-bmpImage->bytes_per_line);
3043 } else if (bmpImage->green_mask==0x07e0) {
3044 if (bmpImage->blue_mask==0xf800) {
3045 /* ==== bgr 0888 dib -> bgr 565 bmp ==== */
3046 convs->Convert_0888_to_565_asis
3049 dstbits,-bmpImage->bytes_per_line);
3050 } else if (bmpImage->red_mask==0xf800) {
3051 /* ==== bgr 0888 dib -> rgb 565 bmp ==== */
3052 convs->Convert_0888_to_565_reverse
3055 dstbits,-bmpImage->bytes_per_line);
3063 if (bmpImage->green_mask==0x03e0 &&
3064 (bmpImage->red_mask==0x7f00 ||
3065 bmpImage->blue_mask==0x7f00)) {
3066 /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */
3067 convs->Convert_any0888_to_5x5
3071 dstbits,-bmpImage->bytes_per_line,
3072 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
3073 } else if (bmpImage->green_mask==0x07e0 &&
3074 (bmpImage->red_mask==0xf800 ||
3075 bmpImage->blue_mask==0xf800)) {
3076 /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */
3077 convs->Convert_any0888_to_5x5
3081 dstbits,-bmpImage->bytes_per_line,
3082 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
3092 WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n",
3093 rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask,
3094 bmpImage->green_mask, bmpImage->blue_mask );
3100 /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
3101 const DWORD* srcpixel;
3102 int rShift,gShift,bShift;
3104 rShift=X11DRV_DIB_MaskToShift(rSrc);
3105 gShift=X11DRV_DIB_MaskToShift(gSrc);
3106 bShift=X11DRV_DIB_MaskToShift(bSrc);
3108 for (h = lines - 1; h >= 0; h--) {
3109 srcpixel=(const DWORD*)srcbits;
3110 for (x = left; x < width+left; x++) {
3112 BYTE red,green,blue;
3113 srcvalue=*srcpixel++;
3114 red= (srcvalue >> rShift) & 0xff;
3115 green=(srcvalue >> gShift) & 0xff;
3116 blue= (srcvalue >> bShift) & 0xff;
3117 XPutPixel(bmpImage, x, h, X11DRV_PALETTE_ToPhysical
3118 (physDev, RGB(red,green,blue)));
3120 srcbits += linebytes;
3128 /***********************************************************************
3129 * X11DRV_DIB_GetImageBits_32
3131 * GetDIBits for an 32-bit deep DIB.
3133 static void X11DRV_DIB_GetImageBits_32( int lines, BYTE *dstbits,
3134 DWORD dstwidth, DWORD srcwidth,
3135 PALETTEENTRY *srccolors,
3136 DWORD rDst, DWORD gDst, DWORD bDst,
3137 XImage *bmpImage, DWORD linebytes )
3140 int h, width = min(srcwidth, dstwidth);
3142 const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap;
3147 dstbits = dstbits + ( linebytes * (lines-1) );
3148 linebytes = -linebytes;
3153 switch (bmpImage->depth)
3156 if (bmpImage->bits_per_pixel==24) {
3157 const void* srcbits;
3159 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
3161 if (rDst==bmpImage->red_mask && gDst==bmpImage->green_mask && bDst==bmpImage->blue_mask) {
3162 /* ==== rgb 888 bmp -> rgb 0888 dib ==== */
3163 /* ==== bgr 888 bmp -> bgr 0888 dib ==== */
3164 convs->Convert_888_to_0888_asis
3166 srcbits,-bmpImage->bytes_per_line,
3168 } else if (bmpImage->green_mask!=0x00ff00 ||
3169 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
3171 /* the tests below assume sane bmpImage masks */
3172 } else if (rDst==bmpImage->blue_mask && gDst==bmpImage->green_mask && bDst==bmpImage->red_mask) {
3173 /* ==== rgb 888 bmp -> bgr 0888 dib ==== */
3174 /* ==== bgr 888 bmp -> rgb 0888 dib ==== */
3175 convs->Convert_888_to_0888_reverse
3177 srcbits,-bmpImage->bytes_per_line,
3179 } else if (bmpImage->blue_mask==0xff) {
3180 /* ==== rgb 888 bmp -> any 0888 dib ==== */
3181 convs->Convert_rgb888_to_any0888
3183 srcbits,-bmpImage->bytes_per_line,
3187 /* ==== bgr 888 bmp -> any 0888 dib ==== */
3188 convs->Convert_bgr888_to_any0888
3190 srcbits,-bmpImage->bytes_per_line,
3200 const char* srcbits;
3202 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
3204 if (gDst==bmpImage->green_mask) {
3205 if (rDst==bmpImage->red_mask && bDst==bmpImage->blue_mask) {
3206 /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
3207 /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
3208 convs->Convert_0888_asis
3210 srcbits,-bmpImage->bytes_per_line,
3212 } else if (bmpImage->green_mask!=0x00ff00 ||
3213 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
3215 /* the tests below assume sane bmpImage masks */
3216 } else if (rDst==bmpImage->blue_mask && bDst==bmpImage->red_mask) {
3217 /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */
3218 /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */
3219 convs->Convert_0888_reverse
3221 srcbits,-bmpImage->bytes_per_line,
3224 /* ==== any 0888 bmp -> any 0888 dib ==== */
3225 convs->Convert_0888_any
3227 srcbits,-bmpImage->bytes_per_line,
3228 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask,
3232 } else if (bmpImage->green_mask!=0x00ff00 ||
3233 (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) {
3235 /* the tests below assume sane bmpImage masks */
3237 /* ==== any 0888 bmp -> any 0888 dib ==== */
3238 convs->Convert_0888_any
3240 srcbits,-bmpImage->bytes_per_line,
3241 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask,
3251 const char* srcbits;
3253 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
3255 if (rDst==0xff0000 && gDst==0x00ff00 && bDst==0x0000ff) {
3256 if (bmpImage->green_mask==0x03e0) {
3257 if (bmpImage->red_mask==0x7f00) {
3258 /* ==== rgb 555 bmp -> rgb 0888 dib ==== */
3259 convs->Convert_555_to_0888_asis
3261 srcbits,-bmpImage->bytes_per_line,
3263 } else if (bmpImage->blue_mask==0x7f00) {
3264 /* ==== bgr 555 bmp -> rgb 0888 dib ==== */
3265 convs->Convert_555_to_0888_reverse
3267 srcbits,-bmpImage->bytes_per_line,
3272 } else if (bmpImage->green_mask==0x07e0) {
3273 if (bmpImage->red_mask==0xf800) {
3274 /* ==== rgb 565 bmp -> rgb 0888 dib ==== */
3275 convs->Convert_565_to_0888_asis
3277 srcbits,-bmpImage->bytes_per_line,
3279 } else if (bmpImage->blue_mask==0xf800) {
3280 /* ==== bgr 565 bmp -> rgb 0888 dib ==== */
3281 convs->Convert_565_to_0888_reverse
3283 srcbits,-bmpImage->bytes_per_line,
3291 } else if (rDst==0x0000ff && gDst==0x00ff00 && bDst==0xff0000) {
3292 if (bmpImage->green_mask==0x03e0) {
3293 if (bmpImage->blue_mask==0x7f00) {
3294 /* ==== bgr 555 bmp -> bgr 0888 dib ==== */
3295 convs->Convert_555_to_0888_asis
3297 srcbits,-bmpImage->bytes_per_line,
3299 } else if (bmpImage->red_mask==0x7f00) {
3300 /* ==== rgb 555 bmp -> bgr 0888 dib ==== */
3301 convs->Convert_555_to_0888_reverse
3303 srcbits,-bmpImage->bytes_per_line,
3308 } else if (bmpImage->green_mask==0x07e0) {
3309 if (bmpImage->blue_mask==0xf800) {
3310 /* ==== bgr 565 bmp -> bgr 0888 dib ==== */
3311 convs->Convert_565_to_0888_asis
3313 srcbits,-bmpImage->bytes_per_line,
3315 } else if (bmpImage->red_mask==0xf800) {
3316 /* ==== rgb 565 bmp -> bgr 0888 dib ==== */
3317 convs->Convert_565_to_0888_reverse
3319 srcbits,-bmpImage->bytes_per_line,
3328 if (bmpImage->green_mask==0x03e0 &&
3329 (bmpImage->red_mask==0x7f00 ||
3330 bmpImage->blue_mask==0x7f00)) {
3331 /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */
3332 convs->Convert_5x5_to_any0888
3334 srcbits,-bmpImage->bytes_per_line,
3335 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask,
3338 } else if (bmpImage->green_mask==0x07e0 &&
3339 (bmpImage->red_mask==0xf800 ||
3340 bmpImage->blue_mask==0xf800)) {
3341 /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */
3342 convs->Convert_5x5_to_any0888
3344 srcbits,-bmpImage->bytes_per_line,
3345 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask,
3357 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
3359 /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */
3360 int rShift,gShift,bShift;
3363 rShift=X11DRV_DIB_MaskToShift(rDst);
3364 gShift=X11DRV_DIB_MaskToShift(gDst);
3365 bShift=X11DRV_DIB_MaskToShift(bDst);
3366 for (h = lines - 1; h >= 0; h--) {
3367 dstpixel=(DWORD*)dstbits;
3368 for (x = 0; x < width; x++) {
3369 PALETTEENTRY srcval;
3370 srcval = srccolors[XGetPixel(bmpImage, x, h)];
3371 *dstpixel++=(srcval.peRed << rShift) |
3372 (srcval.peGreen << gShift) |
3373 (srcval.peBlue << bShift);
3375 dstbits += linebytes;
3383 if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask)
3385 /* ==== pal 8 bmp -> any 0888 dib ==== */
3386 int rShift,gShift,bShift;
3387 const void* srcbits;
3388 const BYTE* srcpixel;
3391 rShift=X11DRV_DIB_MaskToShift(rDst);
3392 gShift=X11DRV_DIB_MaskToShift(gDst);
3393 bShift=X11DRV_DIB_MaskToShift(bDst);
3394 srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line;
3395 for (h = lines - 1; h >= 0; h--) {
3397 dstpixel=(DWORD*)dstbits;
3398 for (x = 0; x < width; x++) {
3399 PALETTEENTRY srcval;
3400 srcval=srccolors[(int)*srcpixel++];
3401 *dstpixel++=(srcval.peRed << rShift) |
3402 (srcval.peGreen << gShift) |
3403 (srcval.peBlue << bShift);
3405 srcbits = (const char*)srcbits - bmpImage->bytes_per_line;
3406 dstbits += linebytes;
3416 /* ==== any bmp format -> any 0888 dib ==== */
3417 int rShift,gShift,bShift;
3420 WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n",
3421 bmpImage->depth, bmpImage->red_mask,
3422 bmpImage->green_mask, bmpImage->blue_mask,
3425 rShift=X11DRV_DIB_MaskToShift(rDst);
3426 gShift=X11DRV_DIB_MaskToShift(gDst);
3427 bShift=X11DRV_DIB_MaskToShift(bDst);
3428 for (h = lines - 1; h >= 0; h--) {
3429 dstpixel=(DWORD*)dstbits;
3430 for (x = 0; x < width; x++) {
3432 srcval=X11DRV_PALETTE_ToLogical(XGetPixel(bmpImage, x, h));
3433 *dstpixel++=(GetRValue(srcval) << rShift) |
3434 (GetGValue(srcval) << gShift) |
3435 (GetBValue(srcval) << bShift);
3437 dstbits += linebytes;
3444 static int XGetSubImageErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
3446 return (event->request_code == X_GetImage && event->error_code == BadMatch);
3449 /***********************************************************************
3450 * X11DRV_DIB_SetImageBits_GetSubImage
3452 * Helper for X11DRV_DIB_SetImageBits
3454 static void X11DRV_DIB_SetImageBits_GetSubImage(
3455 const X11DRV_DIB_IMAGEBITS_DESCR *descr, XImage *bmpImage)
3457 /* compressed bitmaps may contain gaps in them. So make a copy
3458 * of the existing pixels first */
3461 SetRect( &bmprc, descr->xDest, descr->yDest,
3462 descr->xDest + descr->width , descr->yDest + descr->height );
3463 GetRgnBox( descr->physDev->region, &rc );
3464 /* convert from dc to drawable origin */
3465 OffsetRect( &rc, descr->physDev->dc_rect.left, descr->physDev->dc_rect.top);
3466 /* clip visible rect with bitmap */
3467 if( IntersectRect( &rc, &rc, &bmprc))
3469 X11DRV_expect_error( gdi_display, XGetSubImageErrorHandler, NULL );
3470 XGetSubImage( gdi_display, descr->drawable, rc.left, rc.top,
3471 rc.right - rc.left, rc.bottom - rc.top, AllPlanes,
3473 descr->xSrc + rc.left - bmprc.left,
3474 descr->ySrc + rc.top - bmprc.top);
3475 X11DRV_check_error();
3479 /***********************************************************************
3480 * X11DRV_DIB_SetImageBits
3482 * Transfer the bits to an X image.
3483 * Helper function for SetDIBits() and SetDIBitsToDevice().
3485 static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr )
3487 int lines = descr->lines >= 0 ? descr->lines : -descr->lines;
3492 bmpImage = descr->image;
3494 bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL,
3495 descr->infoWidth, lines, 32, 0 );
3496 bmpImage->data = calloc( lines, bmpImage->bytes_per_line );
3497 if(bmpImage->data == NULL) {
3498 ERR("Out of memory!\n");
3499 XDestroyImage( bmpImage );
3500 wine_tsx11_unlock();
3505 TRACE("Dib: depth=%d r=%x g=%x b=%x\n",
3506 descr->infoBpp,descr->rMask,descr->gMask,descr->bMask);
3507 TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n",
3508 bmpImage->depth,bmpImage->bits_per_pixel,
3509 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
3511 /* Transfer the pixels */
3512 switch(descr->infoBpp)
3515 X11DRV_DIB_SetImageBits_1( descr->lines, descr->bits, descr->infoWidth,
3516 descr->width, descr->xSrc, (int *)(descr->colorMap),
3517 bmpImage, descr->dibpitch );
3520 if (descr->compression) {
3521 X11DRV_DIB_SetImageBits_GetSubImage( descr, bmpImage);
3522 X11DRV_DIB_SetImageBits_RLE4( descr->lines, descr->bits,
3523 descr->infoWidth, descr->width,
3524 descr->xSrc, (int *)(descr->colorMap),
3527 X11DRV_DIB_SetImageBits_4( descr->lines, descr->bits,
3528 descr->infoWidth, descr->width,
3529 descr->xSrc, (int*)(descr->colorMap),
3530 bmpImage, descr->dibpitch );
3533 if (descr->compression) {
3534 X11DRV_DIB_SetImageBits_GetSubImage( descr, bmpImage);
3535 X11DRV_DIB_SetImageBits_RLE8( descr->lines, descr->bits,
3536 descr->infoWidth, descr->width,
3537 descr->xSrc, (int *)(descr->colorMap),
3540 X11DRV_DIB_SetImageBits_8( descr->lines, descr->bits,
3541 descr->infoWidth, descr->width,
3542 descr->xSrc, (int *)(descr->colorMap),
3543 bmpImage, descr->dibpitch );
3547 X11DRV_DIB_SetImageBits_16( descr->lines, descr->bits,
3548 descr->infoWidth, descr->width,
3549 descr->xSrc, descr->physDev,
3550 descr->rMask, descr->gMask, descr->bMask,
3551 bmpImage, descr->dibpitch);
3554 X11DRV_DIB_SetImageBits_24( descr->lines, descr->bits,
3555 descr->infoWidth, descr->width,
3556 descr->xSrc, descr->physDev,
3557 descr->rMask, descr->gMask, descr->bMask,
3558 bmpImage, descr->dibpitch);
3561 X11DRV_DIB_SetImageBits_32( descr->lines, descr->bits,
3562 descr->infoWidth, descr->width,
3563 descr->xSrc, descr->physDev,
3564 descr->rMask, descr->gMask, descr->bMask,
3565 bmpImage, descr->dibpitch);
3568 WARN("(%d): Invalid depth\n", descr->infoBpp );
3572 TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n",
3573 descr->drawable, descr->gc, bmpImage,
3574 descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
3575 descr->width, descr->height);
3576 #ifdef HAVE_LIBXXSHM
3577 if (descr->image && descr->useShm)
3579 XShmPutImage( gdi_display, descr->drawable, descr->gc, bmpImage,
3580 descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
3581 descr->width, descr->height, FALSE );
3582 XSync( gdi_display, 0 );
3586 XPutImage( gdi_display, descr->drawable, descr->gc, bmpImage,
3587 descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
3588 descr->width, descr->height );
3590 if (!descr->image) XDestroyImage( bmpImage );
3591 wine_tsx11_unlock();
3595 /***********************************************************************
3596 * X11DRV_DIB_GetImageBits
3598 * Transfer the bits from an X image.
3600 static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr )
3602 int lines = descr->lines >= 0 ? descr->lines : -descr->lines;
3607 bmpImage = descr->image;
3609 bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL,
3610 descr->infoWidth, lines, 32, 0 );
3611 bmpImage->data = calloc( lines, bmpImage->bytes_per_line );
3612 if(bmpImage->data == NULL) {
3613 ERR("Out of memory!\n");
3614 XDestroyImage( bmpImage );
3615 wine_tsx11_unlock();
3620 #ifdef HAVE_LIBXXSHM
3621 if (descr->image && descr->useShm)
3623 int saveRed, saveGreen, saveBlue;
3625 TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n",
3626 gdi_display, descr->drawable, bmpImage,
3627 descr->xSrc, descr->ySrc, AllPlanes);
3629 /* We must save and restore the bmpImage's masks in order
3630 * to preserve them across the call to XShmGetImage, which
3631 * decides to eleminate them since it doesn't happen to know
3632 * what the format of the image is supposed to be, even though
3634 saveRed = bmpImage->red_mask;
3635 saveBlue= bmpImage->blue_mask;
3636 saveGreen = bmpImage->green_mask;
3638 XShmGetImage( gdi_display, descr->drawable, bmpImage,
3639 descr->xSrc, descr->ySrc, AllPlanes);
3641 bmpImage->red_mask = saveRed;
3642 bmpImage->blue_mask = saveBlue;
3643 bmpImage->green_mask = saveGreen;
3646 #endif /* HAVE_LIBXXSHM */
3648 TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n",
3649 gdi_display, descr->drawable, descr->xSrc, descr->ySrc, descr->width,
3650 lines, AllPlanes, ZPixmap, bmpImage, descr->xDest, descr->yDest);
3651 XGetSubImage( gdi_display, descr->drawable, descr->xSrc, descr->ySrc,
3652 descr->width, lines, AllPlanes, ZPixmap,
3653 bmpImage, descr->xDest, descr->yDest );
3656 TRACE("Dib: depth=%2d r=%x g=%x b=%x\n",
3657 descr->infoBpp,descr->rMask,descr->gMask,descr->bMask);
3658 TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n",
3659 bmpImage->depth,bmpImage->bits_per_pixel,
3660 bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask);
3661 /* Transfer the pixels */
3662 switch(descr->infoBpp)
3665 X11DRV_DIB_GetImageBits_1( descr->lines,(LPVOID)descr->bits,
3666 descr->infoWidth, descr->width,
3667 descr->colorMap, descr->palentry,
3668 bmpImage, descr->dibpitch );
3672 if (descr->compression) {
3673 FIXME("Compression not yet supported!\n");
3674 if(descr->sizeImage < X11DRV_DIB_GetDIBWidthBytes( descr->infoWidth, 4 ) * abs(descr->lines))
3677 X11DRV_DIB_GetImageBits_4( descr->lines,(LPVOID)descr->bits,
3678 descr->infoWidth, descr->width,
3679 descr->colorMap, descr->palentry,
3680 bmpImage, descr->dibpitch );
3683 if (descr->compression) {
3684 FIXME("Compression not yet supported!\n");
3685 if(descr->sizeImage < X11DRV_DIB_GetDIBWidthBytes( descr->infoWidth, 8 ) * abs(descr->lines))
3688 X11DRV_DIB_GetImageBits_8( descr->lines, (LPVOID)descr->bits,
3689 descr->infoWidth, descr->width,
3690 descr->colorMap, descr->palentry,
3691 bmpImage, descr->dibpitch );
3695 X11DRV_DIB_GetImageBits_16( descr->lines, (LPVOID)descr->bits,
3696 descr->infoWidth,descr->width,
3698 descr->rMask, descr->gMask, descr->bMask,
3699 bmpImage, descr->dibpitch );
3703 X11DRV_DIB_GetImageBits_24( descr->lines, (LPVOID)descr->bits,
3704 descr->infoWidth,descr->width,
3706 descr->rMask, descr->gMask, descr->bMask,
3707 bmpImage, descr->dibpitch);
3711 X11DRV_DIB_GetImageBits_32( descr->lines, (LPVOID)descr->bits,
3712 descr->infoWidth, descr->width,
3714 descr->rMask, descr->gMask, descr->bMask,
3715 bmpImage, descr->dibpitch);
3719 WARN("(%d): Invalid depth\n", descr->infoBpp );
3723 if (!descr->image) XDestroyImage( bmpImage );
3724 wine_tsx11_unlock();
3728 /*************************************************************************
3729 * X11DRV_SetDIBitsToDevice
3732 INT X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE *physDev, INT xDest, INT yDest, DWORD cx,
3733 DWORD cy, INT xSrc, INT ySrc,
3734 UINT startscan, UINT lines, LPCVOID bits,
3735 const BITMAPINFO *info, UINT coloruse )
3737 X11DRV_DIB_IMAGEBITS_DESCR descr;
3743 if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height,
3744 &descr.infoBpp, &descr.compression ) == -1)
3747 top_down = (height < 0);
3748 if (top_down) height = -height;
3752 LPtoDP(physDev->hdc, &pt, 1);
3754 if (!lines || (startscan >= height)) return 0;
3755 if (!top_down && startscan + lines > height) lines = height - startscan;
3757 /* make xSrc,ySrc point to the upper-left corner, not the lower-left one,
3758 * and clamp all values to fit inside [startscan,startscan+lines]
3760 if (ySrc + cy <= startscan + lines)
3762 UINT y = startscan + lines - (ySrc + cy);
3763 if (ySrc < startscan) cy -= (startscan - ySrc);
3766 /* avoid getting unnecessary lines */
3768 if (y >= lines) return 0;
3773 if (y >= lines) return lines;
3774 ySrc = y; /* need to get all lines in top down mode */
3779 if (ySrc >= startscan + lines) return lines;
3780 pt.y += ySrc + cy - (startscan + lines);
3781 cy = startscan + lines - ySrc;
3783 if (cy > lines) cy = lines;
3785 if (xSrc >= width) return lines;
3786 if (xSrc + cx >= width) cx = width - xSrc;
3787 if (!cx || !cy) return lines;
3789 /* Update the pixmap from the DIB section */
3790 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
3792 X11DRV_SetupGCForText( physDev ); /* To have the correct colors */
3794 XSetFunction(gdi_display, physDev->gc, X11DRV_XROPfunction[GetROP2(physDev->hdc) - 1]);
3795 wine_tsx11_unlock();
3797 switch (descr.infoBpp)
3802 descr.colorMap = (RGBQUAD *)X11DRV_DIB_BuildColorMap(
3804 physDev->depth, info, &descr.nColorMap );
3805 if (!descr.colorMap) return 0;
3806 descr.rMask = descr.gMask = descr.bMask = 0;
3810 descr.rMask = (descr.compression == BI_BITFIELDS) ? *(const DWORD *)info->bmiColors : 0x7c00;
3811 descr.gMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 1) : 0x03e0;
3812 descr.bMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 2) : 0x001f;
3818 descr.rMask = (descr.compression == BI_BITFIELDS) ? *(const DWORD *)info->bmiColors : 0xff0000;
3819 descr.gMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 1) : 0x00ff00;
3820 descr.bMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 2) : 0x0000ff;
3825 descr.physDev = physDev;
3828 descr.palentry = NULL;
3829 descr.lines = top_down ? -lines : lines;
3830 descr.infoWidth = width;
3831 descr.depth = physDev->depth;
3832 descr.drawable = physDev->drawable;
3833 descr.gc = physDev->gc;
3836 descr.xDest = physDev->dc_rect.left + pt.x;
3837 descr.yDest = physDev->dc_rect.top + pt.y;
3840 descr.useShm = FALSE;
3841 descr.dibpitch = ((width * descr.infoBpp + 31) &~31) / 8;
3843 result = X11DRV_DIB_SetImageBits( &descr );
3845 if (descr.infoBpp <= 8)
3846 HeapFree(GetProcessHeap(), 0, descr.colorMap);
3848 /* Update the DIBSection of the pixmap */
3849 X11DRV_UnlockDIBSection(physDev, TRUE);
3854 /***********************************************************************
3855 * SetDIBits (X11DRV.@)
3857 INT X11DRV_SetDIBits( X11DRV_PDEVICE *physDev, HBITMAP hbitmap, UINT startscan,
3858 UINT lines, LPCVOID bits, const BITMAPINFO *info, UINT coloruse )
3860 X_PHYSBITMAP *physBitmap = X11DRV_get_phys_bitmap( hbitmap );
3861 X11DRV_DIB_IMAGEBITS_DESCR descr;
3863 LONG width, height, tmpheight;
3866 descr.physDev = physDev;
3868 if (!physBitmap) return 0;
3870 if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height,
3871 &descr.infoBpp, &descr.compression ) == -1)
3875 if (height < 0) height = -height;
3876 if (!lines || (startscan >= height))
3879 if (!GetObjectW( hbitmap, sizeof(bitmap), &bitmap )) return 0;
3881 if (startscan + lines > height) lines = height - startscan;
3883 switch (descr.infoBpp)
3888 descr.colorMap = (RGBQUAD *)X11DRV_DIB_BuildColorMap(
3889 descr.physDev, coloruse,
3890 physBitmap->pixmap_depth,
3891 info, &descr.nColorMap );
3892 if (!descr.colorMap) return 0;
3893 descr.rMask = descr.gMask = descr.bMask = 0;
3897 descr.rMask = (descr.compression == BI_BITFIELDS) ? *(const DWORD *)info->bmiColors : 0x7c00;
3898 descr.gMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 1) : 0x03e0;
3899 descr.bMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 2) : 0x001f;
3905 descr.rMask = (descr.compression == BI_BITFIELDS) ? *(const DWORD *)info->bmiColors : 0xff0000;
3906 descr.gMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 1) : 0x00ff00;
3907 descr.bMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 2) : 0x0000ff;
3916 descr.palentry = NULL;
3917 descr.infoWidth = width;
3918 descr.lines = tmpheight >= 0 ? lines : -lines;
3919 descr.depth = physBitmap->pixmap_depth;
3920 descr.drawable = physBitmap->pixmap;
3921 descr.gc = BITMAP_GC(physBitmap);
3925 descr.yDest = height - startscan - lines;
3926 descr.width = bitmap.bmWidth;
3927 descr.height = lines;
3928 descr.useShm = FALSE;
3929 descr.dibpitch = ((descr.infoWidth * descr.infoBpp + 31) &~31) / 8;
3930 X11DRV_DIB_Lock( physBitmap, DIB_Status_GdiMod, FALSE );
3931 result = X11DRV_DIB_SetImageBits( &descr );
3932 X11DRV_DIB_Unlock( physBitmap, TRUE );
3934 HeapFree(GetProcessHeap(), 0, descr.colorMap);
3939 /***********************************************************************
3940 * GetDIBits (X11DRV.@)
3942 INT X11DRV_GetDIBits( X11DRV_PDEVICE *physDev, HBITMAP hbitmap, UINT startscan, UINT lines,
3943 LPVOID bits, BITMAPINFO *info, UINT coloruse )
3945 X_PHYSBITMAP *physBitmap = X11DRV_get_phys_bitmap( hbitmap );
3947 X11DRV_DIB_IMAGEBITS_DESCR descr;
3948 PALETTEENTRY palette[256];
3951 LONG width, tempHeight;
3956 GetPaletteEntries( GetCurrentObject( physDev->hdc, OBJ_PAL ), 0, 256, palette );
3958 if (!physBitmap) return 0;
3959 if (!(obj_size = GetObjectW( hbitmap, sizeof(dib), &dib ))) return 0;
3961 bitmap_type = DIB_GetBitmapInfo( (BITMAPINFOHEADER*)info, &width, &tempHeight, &descr.infoBpp, &descr.compression);
3962 descr.lines = tempHeight;
3963 if (bitmap_type == -1)
3965 ERR("Invalid bitmap\n");
3968 core_header = (bitmap_type == 0);
3969 colorPtr = (LPBYTE) info + (WORD) info->bmiHeader.biSize;
3971 TRACE("%u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
3972 lines, dib.dsBm.bmWidth, dib.dsBm.bmHeight, width, descr.lines, startscan);
3974 if( lines > dib.dsBm.bmHeight ) lines = dib.dsBm.bmHeight;
3976 height = descr.lines;
3977 if (height < 0) height = -height;
3978 if( lines > height ) lines = height;
3979 /* Top-down images have a negative biHeight, the scanlines of theses images
3980 * were inverted in X11DRV_DIB_GetImageBits_xx
3981 * To prevent this we simply change the sign of lines
3982 * (the number of scan lines to copy).
3983 * Negative lines are correctly handled by X11DRV_DIB_GetImageBits_xx.
3985 if( descr.lines < 0 && lines > 0) lines = -lines;
3987 if( startscan >= dib.dsBm.bmHeight ) return 0;
3989 descr.colorMap = NULL;
3991 switch (descr.infoBpp)
3996 descr.rMask= descr.gMask = descr.bMask = 0;
3997 if(coloruse == DIB_RGB_COLORS)
3998 descr.colorMap = colorPtr;
4000 int num_colors = 1 << descr.infoBpp, i;
4003 WORD *index = (WORD*)colorPtr;
4004 descr.colorMap = rgb = HeapAlloc(GetProcessHeap(), 0, num_colors * sizeof(RGBQUAD));
4005 for(i = 0; i < num_colors; i++, rgb++, index++) {
4006 colref = X11DRV_PALETTE_ToLogical(X11DRV_PALETTE_ToPhysical(physDev, PALETTEINDEX(*index)));
4007 rgb->rgbRed = GetRValue(colref);
4008 rgb->rgbGreen = GetGValue(colref);
4009 rgb->rgbBlue = GetBValue(colref);
4010 rgb->rgbReserved = 0;
4016 descr.rMask = (descr.compression == BI_BITFIELDS) ? *(const DWORD *)info->bmiColors : 0x7c00;
4017 descr.gMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 1) : 0x03e0;
4018 descr.bMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 2) : 0x001f;
4022 descr.rMask = (descr.compression == BI_BITFIELDS) ? *(const DWORD *)info->bmiColors : 0xff0000;
4023 descr.gMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 1) : 0x00ff00;
4024 descr.bMask = (descr.compression == BI_BITFIELDS) ? *((const DWORD *)info->bmiColors + 2) : 0x0000ff;
4028 descr.physDev = physDev;
4029 descr.palentry = palette;
4031 descr.image = physBitmap->image;
4032 descr.infoWidth = width;
4033 descr.lines = lines;
4034 descr.depth = physBitmap->pixmap_depth;
4035 descr.drawable = physBitmap->pixmap;
4036 descr.gc = BITMAP_GC(physBitmap);
4037 descr.width = dib.dsBm.bmWidth;
4038 descr.height = dib.dsBm.bmHeight;
4042 descr.sizeImage = core_header ? 0 : info->bmiHeader.biSizeImage;
4044 if (descr.lines > 0)
4046 descr.ySrc = (descr.height-1) - (startscan + (lines-1));
4050 descr.ySrc = startscan;
4052 #ifdef HAVE_LIBXXSHM
4053 descr.useShm = (obj_size == sizeof(DIBSECTION)) && (physBitmap->shminfo.shmid != -1);
4055 descr.useShm = FALSE;
4057 descr.dibpitch = (obj_size == sizeof(DIBSECTION)) ? dib.dsBm.bmWidthBytes
4058 : (((descr.infoWidth * descr.infoBpp + 31) &~31) / 8);
4060 X11DRV_DIB_Lock( physBitmap, DIB_Status_GdiMod, FALSE );
4061 X11DRV_DIB_GetImageBits( &descr );
4062 X11DRV_DIB_Unlock( physBitmap, TRUE );
4064 if(!core_header && info->bmiHeader.biSizeImage == 0) /* Fill in biSizeImage */
4065 info->bmiHeader.biSizeImage = X11DRV_DIB_GetDIBImageBytes( descr.infoWidth,
4069 if (descr.compression == BI_BITFIELDS)
4071 *(DWORD *)info->bmiColors = descr.rMask;
4072 *((DWORD *)info->bmiColors + 1) = descr.gMask;
4073 *((DWORD *)info->bmiColors + 2) = descr.bMask;
4075 else if (!core_header)
4077 /* if RLE or JPEG compression were supported,
4078 * this line would be invalid. */
4079 info->bmiHeader.biCompression = 0;
4082 if(descr.colorMap != colorPtr)
4083 HeapFree(GetProcessHeap(), 0, descr.colorMap);
4087 /***********************************************************************
4088 * DIB_DoProtectDIBSection
4090 static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP *physBitmap, DWORD new_prot )
4094 VirtualProtect(physBitmap->base, physBitmap->size, new_prot, &old_prot);
4095 TRACE("Changed protection from %d to %d\n", old_prot, new_prot);
4098 /***********************************************************************
4099 * X11DRV_DIB_DoCopyDIBSection
4101 static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP *physBitmap, BOOL toDIB,
4102 void *colorMap, int nColorMap,
4103 Drawable dest, GC gc,
4104 DWORD xSrc, DWORD ySrc,
4105 DWORD xDest, DWORD yDest,
4106 DWORD width, DWORD height)
4108 DIBSECTION dibSection;
4109 X11DRV_DIB_IMAGEBITS_DESCR descr;
4110 int identity[2] = {0,1};
4112 if (!GetObjectW( physBitmap->hbitmap, sizeof(dibSection), &dibSection )) return;
4114 descr.physDev = NULL;
4115 descr.palentry = NULL;
4116 descr.infoWidth = dibSection.dsBmih.biWidth;
4117 descr.infoBpp = dibSection.dsBmih.biBitCount;
4118 descr.lines = dibSection.dsBmih.biHeight;
4119 descr.image = physBitmap->image;
4120 descr.colorMap = colorMap;
4121 descr.nColorMap = nColorMap;
4122 descr.bits = dibSection.dsBm.bmBits;
4123 descr.depth = physBitmap->pixmap_depth;
4124 descr.compression = dibSection.dsBmih.biCompression;
4126 if(descr.infoBpp == 1)
4127 descr.colorMap = (void*)identity;
4129 switch (descr.infoBpp)
4134 descr.rMask = descr.gMask = descr.bMask = 0;
4138 descr.rMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[0] : 0x7c00;
4139 descr.gMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[1] : 0x03e0;
4140 descr.bMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[2] : 0x001f;
4145 descr.rMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[0] : 0xff0000;
4146 descr.gMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[1] : 0x00ff00;
4147 descr.bMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[2] : 0x0000ff;
4152 descr.drawable = dest;
4156 descr.xDest = xDest;
4157 descr.yDest = yDest;
4158 descr.width = width;
4159 descr.height = height;
4160 descr.sizeImage = 0;
4162 #ifdef HAVE_LIBXXSHM
4163 descr.useShm = (physBitmap->shminfo.shmid != -1);
4165 descr.useShm = FALSE;
4167 descr.dibpitch = dibSection.dsBm.bmWidthBytes;
4171 TRACE("Copying from Pixmap to DIB bits\n");
4172 X11DRV_DIB_GetImageBits( &descr );
4176 TRACE("Copying from DIB bits to Pixmap\n");
4177 X11DRV_DIB_SetImageBits( &descr );
4181 /***********************************************************************
4182 * X11DRV_DIB_CopyDIBSection
4184 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE *physDevDst,
4185 DWORD xSrc, DWORD ySrc, DWORD xDest, DWORD yDest,
4186 DWORD width, DWORD height)
4189 X_PHYSBITMAP *physBitmap;
4190 int nColorMap = 0, *colorMap = NULL, aColorMap = FALSE;
4192 TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc->hdc, physDevDst->hdc,
4193 xSrc, ySrc, xDest, yDest, width, height);
4194 /* this function is meant as an optimization for BitBlt,
4195 * not to be called otherwise */
4196 physBitmap = physDevSrc->bitmap;
4197 if (!physBitmap || GetObjectW( physBitmap->hbitmap, sizeof(dib), &dib ) != sizeof(dib))
4199 ERR("called for non-DIBSection!?\n");
4202 /* while BitBlt should already have made sure we only get
4203 * positive values, we should check for oversize values */
4204 if ((xSrc < dib.dsBm.bmWidth) &&
4205 (ySrc < dib.dsBm.bmHeight)) {
4206 if (xSrc + width > dib.dsBm.bmWidth)
4207 width = dib.dsBm.bmWidth - xSrc;
4208 if (ySrc + height > dib.dsBm.bmHeight)
4209 height = dib.dsBm.bmHeight - ySrc;
4210 /* if the source bitmap is 8bpp or less, we're supposed to use the
4211 * DC's palette for color conversion (not the DIB color table) */
4212 if (dib.dsBm.bmBitsPixel <= 8) {
4213 HPALETTE hPalette = GetCurrentObject( physDevSrc->hdc, OBJ_PAL );
4214 if (!hPalette || (hPalette == GetStockObject(DEFAULT_PALETTE))) {
4215 /* HACK: no palette has been set in the source DC,
4216 * use the DIB colormap instead - this is necessary in some
4217 * cases since we need to do depth conversion in some places
4218 * where real Windows can just copy data straight over */
4219 colorMap = physBitmap->colorMap;
4220 nColorMap = physBitmap->nColorMap;
4222 colorMap = X11DRV_DIB_BuildColorMap( physDevSrc, (WORD)-1,
4223 dib.dsBm.bmBitsPixel,
4224 (BITMAPINFO*)&dib.dsBmih,
4226 if (colorMap) aColorMap = TRUE;
4229 /* perform the copy */
4230 X11DRV_DIB_DoCopyDIBSection(physBitmap, FALSE, colorMap, nColorMap,
4231 physDevDst->drawable, physDevDst->gc, xSrc, ySrc,
4232 physDevDst->dc_rect.left + xDest, physDevDst->dc_rect.top + yDest,
4234 /* free color mapping */
4236 HeapFree(GetProcessHeap(), 0, colorMap);
4240 /***********************************************************************
4241 * X11DRV_DIB_DoUpdateDIBSection
4243 static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP *physBitmap, BOOL toDIB)
4247 GetObjectW( physBitmap->hbitmap, sizeof(bitmap), &bitmap );
4248 X11DRV_DIB_DoCopyDIBSection(physBitmap, toDIB,
4249 physBitmap->colorMap, physBitmap->nColorMap,
4250 physBitmap->pixmap, BITMAP_GC(physBitmap),
4251 0, 0, 0, 0, bitmap.bmWidth, bitmap.bmHeight);
4254 /***********************************************************************
4255 * X11DRV_DIB_FaultHandler
4257 static LONG CALLBACK X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep )
4259 X_PHYSBITMAP *physBitmap = NULL;
4264 if (ep->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
4265 return EXCEPTION_CONTINUE_SEARCH;
4267 addr = (BYTE *)ep->ExceptionRecord->ExceptionInformation[1];
4269 EnterCriticalSection(&dibs_cs);
4270 LIST_FOR_EACH( ptr, &dibs_list )
4272 physBitmap = LIST_ENTRY( ptr, X_PHYSBITMAP, entry );
4273 if ((physBitmap->base <= addr) && (addr < physBitmap->base + physBitmap->size))
4279 LeaveCriticalSection(&dibs_cs);
4281 if (!found) return EXCEPTION_CONTINUE_SEARCH;
4283 X11DRV_DIB_Lock( physBitmap, DIB_Status_None, FALSE );
4284 if (ep->ExceptionRecord->ExceptionInformation[0] == EXCEPTION_WRITE_FAULT) {
4285 /* the app tried to write the DIB bits */
4286 X11DRV_DIB_Coerce( physBitmap, DIB_Status_AppMod, FALSE );
4288 /* the app tried to read the DIB bits */
4289 X11DRV_DIB_Coerce( physBitmap, DIB_Status_InSync, FALSE );
4291 X11DRV_DIB_Unlock( physBitmap, TRUE );
4293 return EXCEPTION_CONTINUE_EXECUTION;
4296 /***********************************************************************
4299 static INT X11DRV_DIB_Coerce(X_PHYSBITMAP *physBitmap, INT req, BOOL lossy)
4301 INT ret = DIB_Status_None;
4303 if (!physBitmap->image) return ret; /* not a DIB section */
4304 EnterCriticalSection(&physBitmap->lock);
4305 ret = physBitmap->status;
4307 case DIB_Status_GdiMod:
4308 /* GDI access - request to draw on pixmap */
4309 switch (physBitmap->status)
4312 case DIB_Status_None:
4313 physBitmap->p_status = DIB_Status_GdiMod;
4314 X11DRV_DIB_DoUpdateDIBSection( physBitmap, FALSE );
4317 case DIB_Status_GdiMod:
4318 TRACE("GdiMod requested in status GdiMod\n" );
4319 physBitmap->p_status = DIB_Status_GdiMod;
4322 case DIB_Status_InSync:
4323 TRACE("GdiMod requested in status InSync\n" );
4324 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_NOACCESS );
4325 physBitmap->status = DIB_Status_GdiMod;
4326 physBitmap->p_status = DIB_Status_InSync;
4329 case DIB_Status_AppMod:
4330 TRACE("GdiMod requested in status AppMod\n" );
4332 /* make it readonly to avoid app changing data while we copy */
4333 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY );
4334 X11DRV_DIB_DoUpdateDIBSection( physBitmap, FALSE );
4336 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_NOACCESS );
4337 physBitmap->p_status = DIB_Status_AppMod;
4338 physBitmap->status = DIB_Status_GdiMod;
4343 case DIB_Status_InSync:
4344 /* App access - request access to read DIB surface */
4345 /* (typically called from signal handler) */
4346 switch (physBitmap->status)
4349 case DIB_Status_None:
4350 /* shouldn't happen from signal handler */
4353 case DIB_Status_GdiMod:
4354 TRACE("InSync requested in status GdiMod\n" );
4356 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE );
4357 X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE );
4359 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY );
4360 physBitmap->status = DIB_Status_InSync;
4363 case DIB_Status_InSync:
4364 TRACE("InSync requested in status InSync\n" );
4365 /* shouldn't happen from signal handler */
4368 case DIB_Status_AppMod:
4369 TRACE("InSync requested in status AppMod\n" );
4370 /* no reason to do anything here, and this
4371 * shouldn't happen from signal handler */
4376 case DIB_Status_AppMod:
4377 /* App access - request access to write DIB surface */
4378 /* (typically called from signal handler) */
4379 switch (physBitmap->status)
4382 case DIB_Status_None:
4383 /* shouldn't happen from signal handler */
4386 case DIB_Status_GdiMod:
4387 TRACE("AppMod requested in status GdiMod\n" );
4388 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE );
4389 if (!lossy) X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE );
4390 physBitmap->status = DIB_Status_AppMod;
4393 case DIB_Status_InSync:
4394 TRACE("AppMod requested in status InSync\n" );
4395 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE );
4396 physBitmap->status = DIB_Status_AppMod;
4399 case DIB_Status_AppMod:
4400 TRACE("AppMod requested in status AppMod\n" );
4401 /* shouldn't happen from signal handler */
4406 /* it is up to the caller to do the copy/conversion, probably
4407 * using the return value to decide where to copy from */
4409 LeaveCriticalSection(&physBitmap->lock);
4413 /***********************************************************************
4416 static INT X11DRV_DIB_Lock(X_PHYSBITMAP *physBitmap, INT req, BOOL lossy)
4418 INT ret = DIB_Status_None;
4420 if (!physBitmap->image) return ret; /* not a DIB section */
4421 TRACE("Locking %p from thread %04x\n", physBitmap->hbitmap, GetCurrentThreadId());
4422 EnterCriticalSection(&physBitmap->lock);
4423 ret = physBitmap->status;
4424 if (req != DIB_Status_None)
4425 X11DRV_DIB_Coerce(physBitmap, req, lossy);
4429 /***********************************************************************
4432 static void X11DRV_DIB_Unlock(X_PHYSBITMAP *physBitmap, BOOL commit)
4434 if (!physBitmap->image) return; /* not a DIB section */
4435 switch (physBitmap->status)
4438 case DIB_Status_None:
4439 /* in case anyone is wondering, this is the "signal handler doesn't
4440 * work" case, where we always have to be ready for app access */
4442 switch (physBitmap->p_status)
4444 case DIB_Status_GdiMod:
4445 TRACE("Unlocking and syncing from GdiMod\n" );
4446 X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE );
4450 TRACE("Unlocking without needing to sync\n" );
4454 else TRACE("Unlocking with no changes\n");
4455 physBitmap->p_status = DIB_Status_None;
4458 case DIB_Status_GdiMod:
4459 TRACE("Unlocking in status GdiMod\n" );
4460 /* DIB was protected in Coerce */
4462 /* no commit, revert to InSync if applicable */
4463 if ((physBitmap->p_status == DIB_Status_InSync) ||
4464 (physBitmap->p_status == DIB_Status_AppMod)) {
4465 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY );
4466 physBitmap->status = DIB_Status_InSync;
4471 case DIB_Status_InSync:
4472 TRACE("Unlocking in status InSync\n" );
4473 /* DIB was already protected in Coerce */
4476 case DIB_Status_AppMod:
4477 TRACE("Unlocking in status AppMod\n" );
4478 /* DIB was already protected in Coerce */
4479 /* this case is ordinary only called from the signal handler,
4480 * so we don't bother to check for !commit */
4483 LeaveCriticalSection(&physBitmap->lock);
4484 TRACE("Unlocked %p\n", physBitmap->hbitmap);
4487 /***********************************************************************
4488 * X11DRV_CoerceDIBSection
4490 INT X11DRV_CoerceDIBSection(X11DRV_PDEVICE *physDev, INT req, BOOL lossy)
4492 if (!physDev || !physDev->bitmap) return DIB_Status_None;
4493 return X11DRV_DIB_Coerce(physDev->bitmap, req, lossy);
4496 /***********************************************************************
4497 * X11DRV_LockDIBSection
4499 INT X11DRV_LockDIBSection(X11DRV_PDEVICE *physDev, INT req, BOOL lossy)
4501 if (!physDev || !physDev->bitmap) return DIB_Status_None;
4502 return X11DRV_DIB_Lock(physDev->bitmap, req, lossy);
4505 /***********************************************************************
4506 * X11DRV_UnlockDIBSection
4508 void X11DRV_UnlockDIBSection(X11DRV_PDEVICE *physDev, BOOL commit)
4510 if (!physDev || !physDev->bitmap) return;
4511 X11DRV_DIB_Unlock(physDev->bitmap, commit);
4515 #ifdef HAVE_LIBXXSHM
4516 /***********************************************************************
4517 * X11DRV_XShmErrorHandler
4520 static int XShmErrorHandler( Display *dpy, XErrorEvent *event, void *arg )
4522 return 1; /* FIXME: should check event contents */
4525 /***********************************************************************
4526 * X11DRV_XShmCreateImage
4529 static XImage *X11DRV_XShmCreateImage( int width, int height, int bpp,
4530 XShmSegmentInfo* shminfo)
4534 image = XShmCreateImage(gdi_display, visual, bpp, ZPixmap, NULL, shminfo, width, height);
4537 shminfo->shmid = shmget(IPC_PRIVATE, image->bytes_per_line * height,
4539 if( shminfo->shmid != -1 )
4541 shminfo->shmaddr = image->data = shmat(shminfo->shmid, 0, 0);
4542 if( shminfo->shmaddr != (char*)-1 )
4546 shminfo->readOnly = FALSE;
4547 X11DRV_expect_error( gdi_display, XShmErrorHandler, NULL );
4548 ok = (XShmAttach( gdi_display, shminfo ) != 0);
4549 XSync( gdi_display, False );
4550 if (X11DRV_check_error()) ok = FALSE;
4553 shmctl(shminfo->shmid, IPC_RMID, 0);
4554 return image; /* Success! */
4556 /* An error occurred */
4557 shmdt(shminfo->shmaddr);
4559 shmctl(shminfo->shmid, IPC_RMID, 0);
4560 shminfo->shmid = -1;
4562 XFlush(gdi_display);
4563 XDestroyImage(image);
4568 #endif /* HAVE_LIBXXSHM */
4571 /***********************************************************************
4572 * X11DRV_CreateDIBSection (X11DRV.@)
4574 HBITMAP X11DRV_CreateDIBSection( X11DRV_PDEVICE *physDev, HBITMAP hbitmap,
4575 const BITMAPINFO *bmi, UINT usage )
4577 X_PHYSBITMAP *physBitmap;
4580 if (!(physBitmap = X11DRV_init_phys_bitmap( hbitmap ))) return 0;
4581 physBitmap->status = DIB_Status_None;
4583 GetObjectW( hbitmap, sizeof(dib), &dib );
4585 /* create color map */
4586 if (dib.dsBm.bmBitsPixel <= 8)
4588 physBitmap->colorMap = X11DRV_DIB_BuildColorMap( physDev,
4589 usage, dib.dsBm.bmBitsPixel, bmi,
4590 &physBitmap->nColorMap );
4593 /* create pixmap and X image */
4595 physBitmap->pixmap_depth = (dib.dsBm.bmBitsPixel == 1) ? 1 : screen_depth;
4596 physBitmap->pixmap = XCreatePixmap( gdi_display, root_window, dib.dsBm.bmWidth,
4597 dib.dsBm.bmHeight, physBitmap->pixmap_depth );
4598 #ifdef HAVE_LIBXXSHM
4599 physBitmap->shminfo.shmid = -1;
4600 if (!XShmQueryExtension(gdi_display) ||
4601 !(physBitmap->image = X11DRV_XShmCreateImage( dib.dsBm.bmWidth, dib.dsBm.bmHeight,
4602 physBitmap->pixmap_depth, &physBitmap->shminfo )) )
4604 physBitmap->image = X11DRV_DIB_CreateXImage( dib.dsBm.bmWidth, dib.dsBm.bmHeight,
4605 physBitmap->pixmap_depth );
4606 wine_tsx11_unlock();
4607 if (!physBitmap->pixmap || !physBitmap->image) return 0;
4609 /* install fault handler */
4610 InitializeCriticalSection( &physBitmap->lock );
4612 physBitmap->base = dib.dsBm.bmBits;
4613 physBitmap->size = dib.dsBmih.biSizeImage;
4614 physBitmap->status = DIB_Status_AppMod;
4617 dibs_handler = AddVectoredExceptionHandler( TRUE, X11DRV_DIB_FaultHandler );
4618 EnterCriticalSection( &dibs_cs );
4619 list_add_head( &dibs_list, &physBitmap->entry );
4620 LeaveCriticalSection( &dibs_cs );
4622 X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE );
4627 /***********************************************************************
4628 * X11DRV_DIB_DeleteDIBSection
4630 void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP *physBitmap, DIBSECTION *dib)
4634 EnterCriticalSection( &dibs_cs );
4635 list_remove( &physBitmap->entry );
4636 last = list_empty( &dibs_list );
4637 LeaveCriticalSection( &dibs_cs );
4641 RemoveVectoredExceptionHandler( dibs_handler );
4642 dibs_handler = NULL;
4645 if (dib->dshSection)
4646 X11DRV_DIB_Coerce(physBitmap, DIB_Status_InSync, FALSE);
4648 if (physBitmap->image)
4651 #ifdef HAVE_LIBXXSHM
4652 if (physBitmap->shminfo.shmid != -1)
4654 XShmDetach( gdi_display, &(physBitmap->shminfo) );
4655 XDestroyImage( physBitmap->image );
4656 shmdt( physBitmap->shminfo.shmaddr );
4657 physBitmap->shminfo.shmid = -1;
4661 XDestroyImage( physBitmap->image );
4662 wine_tsx11_unlock();
4665 HeapFree(GetProcessHeap(), 0, physBitmap->colorMap);
4666 DeleteCriticalSection(&physBitmap->lock);
4669 /***********************************************************************
4670 * SetDIBColorTable (X11DRV.@)
4672 UINT X11DRV_SetDIBColorTable( X11DRV_PDEVICE *physDev, UINT start, UINT count, const RGBQUAD *colors )
4676 X_PHYSBITMAP *physBitmap = physDev->bitmap;
4678 if (!physBitmap) return 0;
4679 GetObjectW( physBitmap->hbitmap, sizeof(dib), &dib );
4681 if (physBitmap->colorMap && start < physBitmap->nColorMap) {
4682 UINT end = count + start;
4683 if (end > physBitmap->nColorMap) end = physBitmap->nColorMap;
4685 * Changing color table might change the mapping between
4686 * DIB colors and X11 colors and thus alter the visible state
4687 * of the bitmap object.
4690 * FIXME we need to recalculate the pen, brush, text and bkgnd pixels here,
4691 * at least for a 1 bpp dibsection
4693 X11DRV_DIB_Lock( physBitmap, DIB_Status_AppMod, FALSE );
4694 X11DRV_DIB_GenColorMap( physDev, physBitmap->colorMap, DIB_RGB_COLORS,
4695 dib.dsBm.bmBitsPixel,
4696 TRUE, colors, start, end );
4697 X11DRV_DIB_Unlock( physBitmap, TRUE );
4704 /***********************************************************************
4705 * X11DRV_DIB_CreateDIBFromBitmap
4707 * Allocates a packed DIB and copies the bitmap data into it.
4709 HGLOBAL X11DRV_DIB_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp)
4714 LPBITMAPINFOHEADER pbmiHeader;
4715 unsigned int cDataSize, cPackedSize, OffsetBits;
4718 if (!GetObjectW( hBmp, sizeof(bmp), &bmp )) return 0;
4721 * A packed DIB contains a BITMAPINFO structure followed immediately by
4722 * an optional color palette and the pixel data.
4725 /* Calculate the size of the packed DIB */
4726 cDataSize = X11DRV_DIB_GetDIBWidthBytes( bmp.bmWidth, bmp.bmBitsPixel ) * abs( bmp.bmHeight );
4727 cPackedSize = sizeof(BITMAPINFOHEADER)
4728 + ( (bmp.bmBitsPixel <= 8) ? (sizeof(RGBQUAD) * (1 << bmp.bmBitsPixel)) : 0 )
4730 /* Get the offset to the bits */
4731 OffsetBits = cPackedSize - cDataSize;
4733 /* Allocate the packed DIB */
4734 TRACE("\tAllocating packed DIB of size %d\n", cPackedSize);
4735 hPackedDIB = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE /*| GMEM_ZEROINIT*/,
4739 WARN("Could not allocate packed DIB!\n");
4743 /* A packed DIB starts with a BITMAPINFOHEADER */
4744 pPackedDIB = GlobalLock(hPackedDIB);
4745 pbmiHeader = (LPBITMAPINFOHEADER)pPackedDIB;
4747 /* Init the BITMAPINFOHEADER */
4748 pbmiHeader->biSize = sizeof(BITMAPINFOHEADER);
4749 pbmiHeader->biWidth = bmp.bmWidth;
4750 pbmiHeader->biHeight = bmp.bmHeight;
4751 pbmiHeader->biPlanes = 1;
4752 pbmiHeader->biBitCount = bmp.bmBitsPixel;
4753 pbmiHeader->biCompression = BI_RGB;
4754 pbmiHeader->biSizeImage = 0;
4755 pbmiHeader->biXPelsPerMeter = pbmiHeader->biYPelsPerMeter = 0;
4756 pbmiHeader->biClrUsed = 0;
4757 pbmiHeader->biClrImportant = 0;
4759 /* Retrieve the DIB bits from the bitmap and fill in the
4760 * DIB color table if present */
4762 nLinesCopied = GetDIBits(hdc, /* Handle to device context */
4763 hBmp, /* Handle to bitmap */
4764 0, /* First scan line to set in dest bitmap */
4765 bmp.bmHeight, /* Number of scan lines to copy */
4766 pPackedDIB + OffsetBits, /* [out] Address of array for bitmap bits */
4767 (LPBITMAPINFO) pbmiHeader, /* [out] Address of BITMAPINFO structure */
4768 0); /* RGB or palette index */
4769 GlobalUnlock(hPackedDIB);
4771 /* Cleanup if GetDIBits failed */
4772 if (nLinesCopied != bmp.bmHeight)
4774 TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied, bmp.bmHeight);
4775 GlobalFree(hPackedDIB);
4782 /**************************************************************************
4783 * X11DRV_DIB_CreateDIBFromPixmap
4785 * Allocates a packed DIB and copies the Pixmap data into it.
4786 * The Pixmap passed in is deleted after the conversion.
4788 HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc)
4791 X_PHYSBITMAP *physBitmap;
4792 HBITMAP hBmp = 0, old;
4793 HGLOBAL hPackedDIB = 0;
4795 int x,y; /* Unused */
4796 unsigned border_width; /* Unused */
4797 unsigned int depth, width, height;
4799 /* Get the Pixmap dimensions and bit depth */
4801 if (!XGetGeometry(gdi_display, pixmap, &root, &x, &y, &width, &height,
4802 &border_width, &depth)) depth = 0;
4803 wine_tsx11_unlock();
4804 if (!depth) return 0;
4806 TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
4807 width, height, depth);
4810 * Create an HBITMAP with the same dimensions and BPP as the pixmap,
4811 * and make it a container for the pixmap passed.
4813 hBmp = CreateBitmap( width, height, 1, depth, NULL );
4815 /* force bitmap to be owned by a screen DC */
4816 hdcMem = CreateCompatibleDC( hdc );
4817 old = SelectObject( hdcMem, hBmp );
4819 physBitmap = X11DRV_get_phys_bitmap( hBmp );
4822 if (physBitmap->pixmap) XFreePixmap( gdi_display, physBitmap->pixmap );
4823 physBitmap->pixmap = pixmap;
4824 wine_tsx11_unlock();
4826 SelectObject( hdcMem, old );
4830 * Create a packed DIB from the Pixmap wrapper bitmap created above.
4831 * A packed DIB contains a BITMAPINFO structure followed immediately by
4832 * an optional color palette and the pixel data.
4834 hPackedDIB = X11DRV_DIB_CreateDIBFromBitmap(hdc, hBmp);
4836 /* We can now get rid of the HBITMAP wrapper we created earlier.
4837 * Note: Simply calling DeleteObject will free the embedded Pixmap as well.
4841 TRACE("\tReturning packed DIB %p\n", hPackedDIB);
4846 /**************************************************************************
4847 * X11DRV_DIB_CreatePixmapFromDIB
4849 * Creates a Pixmap from a packed DIB
4851 Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc )
4854 X_PHYSBITMAP *physBitmap;
4858 /* Create a DDB from the DIB */
4860 pbmi = GlobalLock(hPackedDIB);
4861 hBmp = CreateDIBitmap(hdc, &pbmi->bmiHeader, CBM_INIT,
4862 (LPBYTE)pbmi + X11DRV_DIB_BitmapInfoSize( pbmi, DIB_RGB_COLORS ),
4863 pbmi, DIB_RGB_COLORS);
4864 GlobalUnlock(hPackedDIB);
4866 /* clear the physBitmap so that we can steal its pixmap */
4867 physBitmap = X11DRV_get_phys_bitmap( hBmp );
4868 pixmap = physBitmap->pixmap;
4869 physBitmap->pixmap = 0;
4871 /* Delete the DDB we created earlier now that we have stolen its pixmap */
4874 TRACE("Returning Pixmap %ld\n", pixmap);