Roderick Colenbrander : winex11: Introduce a new function for looking up the physical color of a pixel for use with colormap generation-like functions .

Alexandre Julliard julliard at winehq.org
Wed Sep 2 09:31:30 CDT 2009


Module: wine
Branch: master
Commit: 3878b4810e9e97d95bda0ca2e4b09d9114b21e5f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3878b4810e9e97d95bda0ca2e4b09d9114b21e5f

Author: Roderick Colenbrander <thunderbird2k at gmail.com>
Date:   Tue Sep  1 20:10:32 2009 +0200

winex11: Introduce a new function for looking up the physical color of a pixel for use with colormap generation-like functions.

This prepares to a rewrite of X11DRV_PALETTE_ToPhysical which requires
the physDev for retrieving the color shifts.

---

 dlls/winex11.drv/dib.c     |    4 +-
 dlls/winex11.drv/palette.c |   67 ++++++++++++++++++++++++++++++++++++++++++-
 dlls/winex11.drv/x11drv.h  |    1 +
 3 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/dlls/winex11.drv/dib.c b/dlls/winex11.drv/dib.c
index 794029a..b40215a 100644
--- a/dlls/winex11.drv/dib.c
+++ b/dlls/winex11.drv/dib.c
@@ -371,7 +371,7 @@ static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE *physDev, int *colorMapping,
             }
             else
                 for (i = start; i < end; i++, rgb++)
-                    colorMapping[i] = X11DRV_PALETTE_ToPhysical( NULL, RGB(rgb->rgbRed,
+                    colorMapping[i] = X11DRV_PALETTE_LookupPixel(RGB(rgb->rgbRed,
                                                                 rgb->rgbGreen,
                                                                 rgb->rgbBlue));
         }
@@ -395,7 +395,7 @@ static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE *physDev, int *colorMapping,
             }
             else
                 for (i = start; i < end; i++, rgb++)
-                    colorMapping[i] = X11DRV_PALETTE_ToPhysical( NULL, RGB(rgb->rgbtRed,
+                    colorMapping[i] = X11DRV_PALETTE_LookupPixel(RGB(rgb->rgbtRed,
                                                                rgb->rgbtGreen,
                                                                rgb->rgbtBlue));
         }
diff --git a/dlls/winex11.drv/palette.c b/dlls/winex11.drv/palette.c
index 356cb95..1863e9a 100644
--- a/dlls/winex11.drv/palette.c
+++ b/dlls/winex11.drv/palette.c
@@ -1016,6 +1016,70 @@ int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
 }
 
 /***********************************************************************
+ *           X11DRV_PALETTE_LookupPixel
+ */
+int X11DRV_PALETTE_LookupPixel(COLORREF color )
+{
+    unsigned char spec_type = color >> 24;
+
+    /* Only accept RGB which has spec_type = 0 */
+    if(spec_type)
+        return 0;
+
+    color &= 0xffffff;
+
+    if ( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED )
+    {
+        unsigned long red, green, blue;
+        red = GetRValue(color); green = GetGValue(color); blue = GetBValue(color);
+
+        if (X11DRV_PALETTE_Graymax)
+        {
+            /* grayscale only; return scaled value */
+            return ( (red * 30 + green * 59 + blue * 11) * X11DRV_PALETTE_Graymax) / 25500;
+        }
+        else
+        {
+            /* scale each individually and construct the TrueColor pixel value */
+            if (X11DRV_PALETTE_PRed.scale < 8)
+                red = red >> (8-X11DRV_PALETTE_PRed.scale);
+            else if (X11DRV_PALETTE_PRed.scale > 8)
+                red =   red   << (X11DRV_PALETTE_PRed.scale-8) |
+                        red   >> (16-X11DRV_PALETTE_PRed.scale);
+            if (X11DRV_PALETTE_PGreen.scale < 8)
+                green = green >> (8-X11DRV_PALETTE_PGreen.scale);
+            else if (X11DRV_PALETTE_PGreen.scale > 8)
+                green = green << (X11DRV_PALETTE_PGreen.scale-8) |
+                        green >> (16-X11DRV_PALETTE_PGreen.scale);
+            if (X11DRV_PALETTE_PBlue.scale < 8)
+                blue =  blue  >> (8-X11DRV_PALETTE_PBlue.scale);
+            else if (X11DRV_PALETTE_PBlue.scale > 8)
+                blue =  blue  << (X11DRV_PALETTE_PBlue.scale-8) |
+                        blue  >> (16-X11DRV_PALETTE_PBlue.scale);
+
+            return (red << X11DRV_PALETTE_PRed.shift) | (green << X11DRV_PALETTE_PGreen.shift) | (blue << X11DRV_PALETTE_PBlue.shift);
+        }
+    }
+    else
+    {
+        WORD index;
+        HPALETTE hPal = GetStockObject(DEFAULT_PALETTE);
+        int *mapping = palette_get_mapping( hPal );
+
+        if (!mapping)
+            WARN("Palette %p is not realized\n", hPal);
+
+        EnterCriticalSection( &palette_cs );
+        index = X11DRV_SysPaletteLookupPixel( color, FALSE);
+        if (X11DRV_PALETTE_PaletteToXPixel)
+            index = X11DRV_PALETTE_PaletteToXPixel[index];
+        LeaveCriticalSection( &palette_cs );
+        return index;
+    }
+}
+
+
+/***********************************************************************
  *           X11DRV_PALETTE_LookupSystemXPixel
  */
 static int X11DRV_PALETTE_LookupSystemXPixel(COLORREF col)
@@ -1192,8 +1256,7 @@ UINT X11DRV_RealizePalette( X11DRV_PDEVICE *physDev, HPALETTE hpal, BOOL primary
                 }
                 else if ( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL )
                 {
-                    index = X11DRV_PALETTE_ToPhysical( NULL,
-                                                       RGB( entries[i].peRed, entries[i].peGreen, entries[i].peBlue ));
+                    index = X11DRV_PALETTE_LookupPixel( RGB( entries[i].peRed, entries[i].peGreen, entries[i].peBlue ));
                 }
 
                 /* we have to map to existing entry in the system palette */
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index 26671eb..7f94153 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -477,6 +477,7 @@ extern BOOL X11DRV_IsSolidColor(COLORREF color);
 
 extern COLORREF X11DRV_PALETTE_ToLogical(int pixel);
 extern int X11DRV_PALETTE_ToPhysical(X11DRV_PDEVICE *physDev, COLORREF color);
+extern int X11DRV_PALETTE_LookupPixel(COLORREF color);
 
 extern unsigned int depth_to_bpp( unsigned int depth );
 




More information about the wine-cvs mailing list