From d21dde71b3d23e334ea48bae75ad290539536a5d Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Wed, 13 Oct 1999 13:48:11 +0000
Subject: [PATCH] Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello
 <abbeyj@wpi.edu> Fixes problems with color drift when switching to/from
 logical/physical colors.

---
 graphics/x11drv/palette.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/graphics/x11drv/palette.c b/graphics/x11drv/palette.c
index 320cd96ef42..3be89c7f078 100644
--- a/graphics/x11drv/palette.c
+++ b/graphics/x11drv/palette.c
@@ -631,9 +631,9 @@ COLORREF X11DRV_PALETTE_ToLogical(int pixel)
          color.red = (pixel >> X11DRV_PALETTE_Redshift) & X11DRV_PALETTE_Redmax;
          color.green = (pixel >> X11DRV_PALETTE_Greenshift) & X11DRV_PALETTE_Greenmax;
          color.blue = (pixel >> X11DRV_PALETTE_Blueshift) & X11DRV_PALETTE_Bluemax;
-         return RGB((color.red * 255)/X11DRV_PALETTE_Redmax,
-                    (color.green * 255)/X11DRV_PALETTE_Greenmax,
-                    (color.blue * 255)/X11DRV_PALETTE_Bluemax);
+         return RGB(MulDiv(color.red, 255, X11DRV_PALETTE_Redmax),
+		    MulDiv(color.green, 255, X11DRV_PALETTE_Greenmax),
+		    MulDiv(color.blue, 255, X11DRV_PALETTE_Bluemax));
     }
 
     /* check if we can bypass X */
@@ -716,9 +716,12 @@ int X11DRV_PALETTE_ToPhysical( DC *dc, COLORREF color )
 	else
         {
 	    /* scale each individually and construct the TrueColor pixel value */
-	    if (X11DRV_PALETTE_Redmax != 255) red = (red * X11DRV_PALETTE_Redmax) / 255;
-            if (X11DRV_PALETTE_Greenmax != 255) green = (green * X11DRV_PALETTE_Greenmax) / 255;
-	    if (X11DRV_PALETTE_Bluemax != 255) blue = (blue * X11DRV_PALETTE_Bluemax) / 255;
+	    if (X11DRV_PALETTE_Redmax != 255)
+		red = MulDiv(red, X11DRV_PALETTE_Redmax, 255);
+	    if (X11DRV_PALETTE_Greenmax != 255)
+		green = MulDiv(green, X11DRV_PALETTE_Greenmax, 255);
+	    if (X11DRV_PALETTE_Bluemax != 255)
+		blue = MulDiv(blue, X11DRV_PALETTE_Bluemax, 255);
 
 	    GDI_HEAP_UNLOCK( hPal );
 	    return (red << X11DRV_PALETTE_Redshift) | (green << X11DRV_PALETTE_Greenshift) | (blue << X11DRV_PALETTE_Blueshift);