diff options
author | Pierre Ossman <ossman@cendio.se> | 2014-01-20 15:05:21 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2014-07-07 14:50:11 +0200 |
commit | b6b4dc6487690e891ec2487c6cf765d36821fe3a (patch) | |
tree | 77d2e0f49461c7ff8fc78872c9763fe9b6f67adb /common/rfb/PixelFormat.inl | |
parent | bcc295e5a60954ff39b011d6a2cbdf052a0efafc (diff) | |
download | tigervnc-b6b4dc6487690e891ec2487c6cf765d36821fe3a.tar.gz tigervnc-b6b4dc6487690e891ec2487c6cf765d36821fe3a.zip |
Remove full support for colour maps
Gets rid of a loooot of code and complexity.
Colour map clients are still supported through an
automatically generated map, but we lose the ability to
develop a client or server that uses colour maps
internally.
Diffstat (limited to 'common/rfb/PixelFormat.inl')
-rw-r--r-- | common/rfb/PixelFormat.inl | 168 |
1 files changed, 59 insertions, 109 deletions
diff --git a/common/rfb/PixelFormat.inl b/common/rfb/PixelFormat.inl index 547fae5d..4bc4a709 100644 --- a/common/rfb/PixelFormat.inl +++ b/common/rfb/PixelFormat.inl @@ -75,131 +75,81 @@ inline void PixelFormat::bufferFromPixel(rdr::U8* buffer, Pixel p) const } -inline Pixel PixelFormat::pixelFromRGB(rdr::U16 red, rdr::U16 green, rdr::U16 blue, ColourMap* cm) const +inline Pixel PixelFormat::pixelFromRGB(rdr::U16 red, rdr::U16 green, rdr::U16 blue) const { - if (trueColour) { - Pixel p; - - /* We don't need to mask since we shift out unwanted bits */ - p = ((Pixel)red >> (16 - redBits)) << redShift; - p |= ((Pixel)green >> (16 - greenBits)) << greenShift; - p |= ((Pixel)blue >> (16 - blueBits)) << blueShift; - } else if (cm) { - // Try to find the closest pixel by Cartesian distance - int colours = 1 << depth; - int diff = 256 * 256 * 4; - int col = 0; - for (int i=0; i<colours; i++) { - int r, g, b; - cm->lookup(i, &r, &g, &b); - int rd = (r-red) >> 8; - int gd = (g-green) >> 8; - int bd = (b-blue) >> 8; - int d = rd*rd + gd*gd + bd*bd; - if (d < diff) { - col = i; - diff = d; - } - } - return col; - } else { - // XXX just return 0 for colour map? - return 0; - } + Pixel p; + + /* We don't need to mask since we shift out unwanted bits */ + p = ((Pixel)red >> (16 - redBits)) << redShift; + p |= ((Pixel)green >> (16 - greenBits)) << greenShift; + p |= ((Pixel)blue >> (16 - blueBits)) << blueShift; + + return p; } -inline Pixel PixelFormat::pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue, ColourMap* cm) const +inline Pixel PixelFormat::pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue) const { - if (trueColour) { - Pixel p; + Pixel p; - p = ((Pixel)red >> (8 - redBits)) << redShift; - p |= ((Pixel)green >> (8 - greenBits)) << greenShift; - p |= ((Pixel)blue >> (8 - blueBits)) << blueShift; + p = ((Pixel)red >> (8 - redBits)) << redShift; + p |= ((Pixel)green >> (8 - greenBits)) << greenShift; + p |= ((Pixel)blue >> (8 - blueBits)) << blueShift; - return p; - } else { - return pixelFromRGB((rdr::U16)(red << 8 | red), - (rdr::U16)(green << 8 | green), - (rdr::U16)(blue << 8 | blue), cm); - } + return p; } -inline void PixelFormat::rgbFromPixel(Pixel p, ColourMap* cm, rdr::U16 *r, rdr::U16 *g, rdr::U16 *b) const +inline void PixelFormat::rgbFromPixel(Pixel p, rdr::U16 *r, rdr::U16 *g, rdr::U16 *b) const { - if (trueColour) { - int mb, rb, gb, bb; - - /* Bit replication is much cheaper than multiplication and division */ - - mb = minBits; - rb = redBits; - gb = greenBits; - bb = blueBits; - - *r = (p >> redShift) << (16 - rb); - *g = (p >> greenShift) << (16 - gb); - *b = (p >> blueShift) << (16 - bb); - - while (mb < 16) { - *r = *r | (*r >> rb); - *g = *g | (*g >> gb); - *b = *b | (*b >> bb); - mb <<= 1; - rb <<= 1; - gb <<= 1; - bb <<= 1; - } - } else if (cm) { - int ir, ig, ib; - cm->lookup(p, &ir, &ig, &ib); - *r = ir; - *g = ig; - *b = ib; - } else { - // XXX just return 0 for colour map? - *r = 0; - *g = 0; - *b = 0; + int mb, rb, gb, bb; + + /* Bit replication is much cheaper than multiplication and division */ + + mb = minBits; + rb = redBits; + gb = greenBits; + bb = blueBits; + + *r = (p >> redShift) << (16 - rb); + *g = (p >> greenShift) << (16 - gb); + *b = (p >> blueShift) << (16 - bb); + + while (mb < 16) { + *r = *r | (*r >> rb); + *g = *g | (*g >> gb); + *b = *b | (*b >> bb); + mb <<= 1; + rb <<= 1; + gb <<= 1; + bb <<= 1; } } -inline void PixelFormat::rgbFromPixel(Pixel p, ColourMap* cm, rdr::U8 *r, rdr::U8 *g, rdr::U8 *b) const +inline void PixelFormat::rgbFromPixel(Pixel p, rdr::U8 *r, rdr::U8 *g, rdr::U8 *b) const { - if (trueColour) { - int mb, rb, gb, bb; - - /* Bit replication is much cheaper than multiplication and division */ - - mb = minBits; - rb = redBits; - gb = greenBits; - bb = blueBits; - - *r = (p >> redShift) << (8 - rb); - *g = (p >> greenShift) << (8 - gb); - *b = (p >> blueShift) << (8 - bb); - - while (mb < 8) { - *r = *r | (*r >> rb); - *g = *g | (*g >> gb); - *b = *b | (*b >> bb); - mb <<= 1; - rb <<= 1; - gb <<= 1; - bb <<= 1; - } - } else { - rdr::U16 r2, g2, b2; - - rgbFromPixel(p, cm, &r2, &g2, &b2); - - *r = r2 >> 8; - *g = g2 >> 8; - *b = b2 >> 8; + int mb, rb, gb, bb; + + /* Bit replication is much cheaper than multiplication and division */ + + mb = minBits; + rb = redBits; + gb = greenBits; + bb = blueBits; + + *r = (p >> redShift) << (8 - rb); + *g = (p >> greenShift) << (8 - gb); + *b = (p >> blueShift) << (8 - bb); + + while (mb < 8) { + *r = *r | (*r >> rb); + *g = *g | (*g >> gb); + *b = *b | (*b >> bb); + mb <<= 1; + rb <<= 1; + gb <<= 1; + bb <<= 1; } } |