Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- For 0 to map to 0 and 255 to map to 65535, the value must be multiplied by 257, not 256. The incorrect factor would cause the color #FFFFFF to become #FEFEFE.
v2: Also correct reverse mapping --- dlls/winex11.drv/palette.c | 42 ++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/dlls/winex11.drv/palette.c b/dlls/winex11.drv/palette.c index 25bdb5f2bf..06d02c300a 100644 --- a/dlls/winex11.drv/palette.c +++ b/dlls/winex11.drv/palette.c @@ -293,19 +293,19 @@ static BOOL X11DRV_PALETTE_BuildPrivateMap( const PALETTEENTRY *sys_pal_template { if( i < NB_RESERVED_COLORS/2 ) { - color.red = sys_pal_template[i].peRed * 65535 / 255; - color.green = sys_pal_template[i].peGreen * 65535 / 255; - color.blue = sys_pal_template[i].peBlue * 65535 / 255; - COLOR_sysPal[i] = sys_pal_template[i]; + color.red = sys_pal_template[i].peRed * (65535 / 255); + color.green = sys_pal_template[i].peGreen * (65535 / 255); + color.blue = sys_pal_template[i].peBlue * (65535 / 255); + COLOR_sysPal[i] = sys_pal_template[i]; COLOR_sysPal[i].peFlags |= PC_SYS_USED; } else if( i >= palette_size - NB_RESERVED_COLORS/2 ) { - int j = NB_RESERVED_COLORS + i - palette_size; - color.red = sys_pal_template[j].peRed * 65535 / 255; - color.green = sys_pal_template[j].peGreen * 65535 / 255; - color.blue = sys_pal_template[j].peBlue * 65535 / 255; - COLOR_sysPal[i] = sys_pal_template[j]; + int j = NB_RESERVED_COLORS + i - palette_size; + color.red = sys_pal_template[j].peRed * (65535 / 255); + color.green = sys_pal_template[j].peGreen * (65535 / 255); + color.blue = sys_pal_template[j].peBlue * (65535 / 255); + COLOR_sysPal[i] = sys_pal_template[j]; COLOR_sysPal[i].peFlags |= PC_SYS_USED; }
@@ -405,9 +405,9 @@ static BOOL X11DRV_PALETTE_BuildSharedMap( const PALETTEENTRY *sys_pal_template for( c.pixel = 0, diff = 0x7fffffff; c.pixel < max; c.pixel += step ) { XQueryColor(gdi_display, default_colormap, &c); - r = (c.red - color.red)>>8; - g = (c.green - color.green)>>8; - b = (c.blue - color.blue)>>8; + r = (c.red - color.red) / (65535 / 255); + g = (c.green - color.green) / (65535 / 255); + b = (c.blue - color.blue) / (65535 / 255); r = r*r + g*g + b*b; if( r < diff ) { best = c; diff = r; } } @@ -633,9 +633,9 @@ static void X11DRV_PALETTE_FillDefaultColors( const PALETTEENTRY *sys_pal_templa { XColor color; color.pixel = (X11DRV_PALETTE_PaletteToXPixel)? X11DRV_PALETTE_PaletteToXPixel[idx] : idx; - color.red = COLOR_sysPal[idx].peRed << 8; - color.green = COLOR_sysPal[idx].peGreen << 8; - color.blue = COLOR_sysPal[idx].peBlue << 8; + color.red = COLOR_sysPal[idx].peRed * (65535 / 255); + color.green = COLOR_sysPal[idx].peGreen * (65535 / 255); + color.blue = COLOR_sysPal[idx].peBlue * (65535 / 255); color.flags = DoRed | DoGreen | DoBlue; XStoreColor(gdi_display, default_colormap, &color); } @@ -658,7 +658,9 @@ static void X11DRV_PALETTE_FillDefaultColors( const PALETTEENTRY *sys_pal_templa xc.pixel = i;
XQueryColor(gdi_display, default_colormap, &xc); - r = xc.red>>8; g = xc.green>>8; b = xc.blue>>8; + r = xc.red / (65535 / 255); + g = xc.green / (65535 / 255); + b = xc.blue / (65535 / 255);
if( xc.pixel < 256 && X11DRV_PALETTE_CheckSysColor( sys_pal_template, RGB(r, g, b)) && XAllocColor(gdi_display, default_colormap, &xc) ) @@ -753,7 +755,7 @@ COLORREF X11DRV_PALETTE_ToLogical(X11DRV_PDEVICE *physDev, int pixel)
color.pixel = pixel; XQueryColor(gdi_display, default_colormap, &color); - return RGB(color.red >> 8, color.green >> 8, color.blue >> 8); + return RGB(color.red / (65535 / 255), color.green / (65535 / 255), color.blue / (65535 / 255)); }
@@ -1156,9 +1158,9 @@ UINT CDECL X11DRV_RealizePalette( PHYSDEV dev, HPALETTE hpal, BOOL primary ) X11DRV_PALETTE_firstFree = X11DRV_PALETTE_freeList[index];
color.pixel = (X11DRV_PALETTE_PaletteToXPixel) ? X11DRV_PALETTE_PaletteToXPixel[index] : index; - color.red = entries[i].peRed << 8; - color.green = entries[i].peGreen << 8; - color.blue = entries[i].peBlue << 8; + color.red = entries[i].peRed * (65535 / 255); + color.green = entries[i].peGreen * (65535 / 255); + color.blue = entries[i].peBlue * (65535 / 255); color.flags = DoRed | DoGreen | DoBlue; XStoreColor(gdi_display, default_colormap, &color);
Alex Henrie alexhenrie24@gmail.com writes:
Signed-off-by: Alex Henrie alexhenrie24@gmail.com
For 0 to map to 0 and 255 to map to 65535, the value must be multiplied by 257, not 256. The incorrect factor would cause the color #FFFFFF to become #FEFEFE.
v2: Also correct reverse mapping
For reverse mappings I don't think it's an improvement.
On Wed, Nov 13, 2019 at 1:33 AM Alexandre Julliard julliard@winehq.org wrote:
Alex Henrie alexhenrie24@gmail.com writes:
Signed-off-by: Alex Henrie alexhenrie24@gmail.com
For 0 to map to 0 and 255 to map to 65535, the value must be multiplied by 257, not 256. The incorrect factor would cause the color #FFFFFF to become #FEFEFE.
v2: Also correct reverse mapping
For reverse mappings I don't think it's an improvement.
Okay, then just use the first patch I sent and ignore the v2.
-Alex