--- xc/programs/Xserver/mi/micmap.c.410 Tue Jun 5 00:35:39 2001 +++ xc/programs/Xserver/mi/micmap.c Tue Jun 5 00:38:02 2001 @@ -104,18 +104,41 @@ int shift = 16 - pVisual->bitsPerRGBValue; unsigned lim = (1 << pVisual->bitsPerRGBValue) - 1; - if ((pVisual->class | DynamicClass) == GrayScale) + if ((pVisual->class == PseudoColor) || (pVisual->class == DirectColor)) { - /* rescale to gray then rgb bits */ - *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100; - *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim; + /* rescale to rgb bits */ + *pred = ((*pred >> shift) * 65535) / lim; + *pgreen = ((*pgreen >> shift) * 65535) / lim; + *pblue = ((*pblue >> shift) * 65535) / lim; + } + else if (pVisual->class == GrayScale) + { + /* rescale to gray then rgb bits */ + *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100; + *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim; + } + else if (pVisual->class == StaticGray) + { + unsigned limg = pVisual->ColormapEntries - 1; + /* rescale to gray then [0..limg] then [0..65535] then rgb bits */ + *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100; + *pred = ((((*pred * (limg + 1))) >> 16) * 65535) / limg; + *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim; } else { - /* rescale to rgb bits */ - *pred = ((*pred >> shift) * 65535) / lim; - *pgreen = ((*pgreen >> shift) * 65535) / lim; - *pblue = ((*pblue >> shift) * 65535) / lim; + unsigned limr, limg, limb; + + limr = pVisual->redMask >> pVisual->offsetRed; + limg = pVisual->greenMask >> pVisual->offsetGreen; + limb = pVisual->blueMask >> pVisual->offsetBlue; + /* rescale to [0..limN] then [0..65535] then rgb bits */ + *pred = ((((((*pred * (limr + 1)) >> 16) * + 65535) / limr) >> shift) * 65535) / lim; + *pgreen = ((((((*pgreen * (limg + 1)) >> 16) * + 65535) / limg) >> shift) * 65535) / lim; + *pblue = ((((((*pblue * (limb + 1)) >> 16) * + 65535) / limb) >> shift) * 65535) / lim; } }