aboutsummaryrefslogtreecommitdiffstats
path: root/common/rfb/PixelFormat.inl
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2018-03-01 14:11:39 +0100
committerPierre Ossman <ossman@cendio.se>2018-03-01 14:11:39 +0100
commit816baa35ae5374f350ee4031ac54d7d1e90af183 (patch)
tree9bdd1b3e1753798c020490d1f41f5d21f6ae2c51 /common/rfb/PixelFormat.inl
parente6810fa3e598c06f64f82af0141c7da3b8f9b9a8 (diff)
downloadtigervnc-816baa35ae5374f350ee4031ac54d7d1e90af183.tar.gz
tigervnc-816baa35ae5374f350ee4031ac54d7d1e90af183.zip
Fix rounding error in pixel down conversion
Simple shifting can give noticable rounding errors if there is a large difference in the number of bits between the formats. Do the proper thing via a lookup table, the same way things are done for up conversion.
Diffstat (limited to 'common/rfb/PixelFormat.inl')
-rw-r--r--common/rfb/PixelFormat.inl13
1 files changed, 6 insertions, 7 deletions
diff --git a/common/rfb/PixelFormat.inl b/common/rfb/PixelFormat.inl
index f9fb1254..5a40379a 100644
--- a/common/rfb/PixelFormat.inl
+++ b/common/rfb/PixelFormat.inl
@@ -79,10 +79,9 @@ inline Pixel PixelFormat::pixelFromRGB(rdr::U16 red, rdr::U16 green, rdr::U16 bl
{
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;
+ p = (Pixel)downconvTable[(redBits-1)*256 + (red >> 8)] << redShift;
+ p |= (Pixel)downconvTable[(greenBits-1)*256 + (green >> 8)] << greenShift;
+ p |= (Pixel)downconvTable[(blueBits-1)*256 + (blue >> 8)] << blueShift;
return p;
}
@@ -92,9 +91,9 @@ inline Pixel PixelFormat::pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue)
{
Pixel p;
- p = ((Pixel)red >> (8 - redBits)) << redShift;
- p |= ((Pixel)green >> (8 - greenBits)) << greenShift;
- p |= ((Pixel)blue >> (8 - blueBits)) << blueShift;
+ p = (Pixel)downconvTable[(redBits-1)*256 + red] << redShift;
+ p |= (Pixel)downconvTable[(greenBits-1)*256 + green] << greenShift;
+ p |= (Pixel)downconvTable[(blueBits-1)*256 + blue] << blueShift;
return p;
}