TrueColor <16bpp modes

François Gouget fgouget at codeweavers.com
Wed Dec 19 22:05:41 CST 2001


   There is a problem with <16bpp TrueColor modes: some windows
applications will just check BITSPERPIXEL and if it's < 16 they will
assume that we are running with a 2/16/256 color palette.

   What are the affected modes:
 * 15bpp: rgb555 and bgr555
 * 8bpp:  VNC's bgr233 mode!


   This patch is an ugly hack but it seems to work relatively well.
   The trick is to lie to the application about the screen depth. If we
have a TrueColor mode but a <16bpp screen depth then we return 16bpp
anyway. But then the application is going to create 16bpp bitmaps, and
CreateBitmap will try to create a 16bpp pixmap... and this is likely to
fail.
   So in CreateBitmap we reestablish the truth and put the right depth
in bitmap.bmBitsPixel. Actually some X servers, especially the 4 series
seem to support many pixmap bit depth so this may not always be
necessary. Anyway, we then rely on the code in dib.c to do the
conversions from one format to the other.
   The last bit in bitblt.c may not be necessary. It seemed useful once
but I'm not convinced anymore.

   Well, if anyone's interested in hacking more on this, have fun (and
let me know if you find interesting stuff or have questions :-).

 
-- 
François Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: graphics/x11drv/bitmap.c
===================================================================
RCS file: /home/wine/wine/graphics/x11drv/bitmap.c,v
retrieving revision 1.34
diff -u -r1.34 bitmap.c
--- graphics/x11drv/bitmap.c	2001/09/07 15:28:10	1.34
+++ graphics/x11drv/bitmap.c	2001/12/20 00:31:19
@@ -156,6 +156,14 @@
         GDI_ReleaseObj( hbitmap );
         return 0;
     }
+    /* In case we lied to the application wrt. the screen depth, then it's 
+     * time to patch things up before X complains it does not support this 
+     * color depth. Of course it means we'll have to convert depths from 
+     * DIB to Bmp.
+     */
+    if (bmp->bitmap.bmBitsPixel==16 && screen_depth<16 && (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL))
+        bmp->bitmap.bmBitsPixel=screen_depth;
+
     if ((bmp->bitmap.bmBitsPixel != 1) && (bmp->bitmap.bmBitsPixel != screen_depth))
     {
         ERR("Trying to make bitmap with planes=%d, bpp=%d\n",
Index: graphics/x11drv/init.c
===================================================================
RCS file: /home/wine/wine/graphics/x11drv/init.c,v
retrieving revision 1.41
diff -u -r1.41 init.c
--- graphics/x11drv/init.c	2001/07/29 20:25:15	1.41
+++ graphics/x11drv/init.c	2001/12/20 00:31:22
@@ -190,7 +190,11 @@
     case VERTRES:
         return screen_height;
     case BITSPIXEL:
-        return screen_depth;
+        /* Some applications assume that if the bpp<16 then we are using a 
+         * palette. This is wrong, we could be in 15bpp, or even bgr233 in VNC.
+         * So we just lie to them.
+         */
+        return (screen_depth<16 && X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) ? 16 : screen_depth;
     case PLANES:
         return 1;
     case NUMBRUSHES:
@@ -202,10 +206,11 @@
     case NUMFONTS:
         return 0;
     case NUMCOLORS:
-        /* MSDN: Number of entries in the device's color table, if the device has
-         * a color depth of no more than 8 bits per pixel.For devices with greater
-         * color depths, -1 is returned. */
-        return (screen_depth > 8) ? -1 : (1 << screen_depth);
+        /* MSDN: Number of entries in the device's color table, if the 
+         * device has a color depth of no more than 8 bits per pixel. For 
+         * devices with greater color depths, -1 is returned.
+         */
+        return (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) ? -1 : (1 << screen_depth);
     case PDEVICESIZE:
         return sizeof(X11DRV_PDEVICE);
     case CURVECAPS:
Index: graphics/x11drv/bitblt.c
===================================================================
RCS file: /home/wine/wine/graphics/x11drv/bitblt.c,v
retrieving revision 1.37
diff -u -r1.37 bitblt.c
--- graphics/x11drv/bitblt.c	2001/10/03 18:45:41	1.37
+++ graphics/x11drv/bitblt.c	2001/12/20 00:31:19
@@ -626,7 +626,7 @@
     pdata += swap ? start+width-1 : start;
     if (image->depth == depthDst)  /* color -> color */
     {
-        if (X11DRV_PALETTE_XPixelToPalette && (depthDst != 1))
+        if (!(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) && X11DRV_PALETTE_XPixelToPalette && (depthDst != 1))
             if (swap) for (i = 0; i < width; i++)
                 *pdata-- = X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, i, row )];
             else for (i = 0; i < width; i++)


More information about the wine-devel mailing list