From 416685c295353b5816689994c7c58ae7db3e878d Mon Sep 17 00:00:00 2001 From: Jeremy Uejio Date: Tue, 25 Nov 2008 16:26:44 -0800 Subject: [PATCH] Refix Sun bug #6685465: Xephyr uses wrong or bad colortable in 8-bit mode This is a refix of the previous fix for CR 6685465. In the first fix I was shifting the colors to match the mask by the bits_per_rgb amount in the visual structure. That field has nothing to do with the # of bits to shift by. I should just instead shift the bits to match the mask. --- hw/kdrive/ephyr/hostx.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c index 1bc95a8fc..d289d7335 100644 --- a/hw/kdrive/ephyr/hostx.c +++ b/hw/kdrive/ephyr/hostx.c @@ -578,14 +578,14 @@ hostx_get_visual_masks (EphyrScreenInfo screen, } static int -hostx_calculate_color_shift(unsigned long mask, - int bits_per_rgb) +hostx_calculate_color_shift(unsigned long mask) { - int shift = 0; - while(mask) { - mask = mask >> bits_per_rgb; - if (mask) shift += bits_per_rgb; - } + int shift = 1; + /* count # of bits in mask */ + while (mask=(mask>>1)) shift++; + /* cmap entry is an unsigned char so adjust it by size of that */ + shift = shift - sizeof(unsigned char) * 8; + if (shift < 0) shift = 0; return shift; } @@ -601,12 +601,9 @@ hostx_set_cmap_entry(unsigned char idx, static int first_time = 1; if (first_time) { first_time = 0; - rshift = hostx_calculate_color_shift(HostX.visual->red_mask, - HostX.visual->bits_per_rgb); - gshift = hostx_calculate_color_shift(HostX.visual->green_mask, - HostX.visual->bits_per_rgb); - bshift = hostx_calculate_color_shift(HostX.visual->blue_mask, - HostX.visual->bits_per_rgb); + rshift = hostx_calculate_color_shift(HostX.visual->red_mask); + gshift = hostx_calculate_color_shift(HostX.visual->green_mask); + bshift = hostx_calculate_color_shift(HostX.visual->blue_mask); } HostX.cmap[idx] = ((r << rshift) & HostX.visual->red_mask) | ((g << gshift) & HostX.visual->green_mask) |