aboutsummaryrefslogtreecommitdiffstats
path: root/common/rfb/PixelFormat.cxx
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.cxx
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.cxx')
-rw-r--r--common/rfb/PixelFormat.cxx18
1 files changed, 12 insertions, 6 deletions
diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx
index 76051dc4..883b0410 100644
--- a/common/rfb/PixelFormat.cxx
+++ b/common/rfb/PixelFormat.cxx
@@ -34,6 +34,7 @@
using namespace rfb;
rdr::U8 PixelFormat::upconvTable[256*8];
+rdr::U8 PixelFormat::downconvTable[256*8];
class PixelFormat::Init {
public:
@@ -47,24 +48,29 @@ PixelFormat::Init::Init()
{
int bits;
- // Bit replication is almost perfect, but not quite. And
+ // Shifting bits is almost perfect, but not quite. And
// a lookup table is still quicker when there is a large
// difference between the source and destination depth.
for (bits = 1;bits <= 8;bits++) {
int i, maxVal;
- rdr::U8 *subTable;
+ rdr::U8 *subUpTable;
+ rdr::U8 *subDownTable;
maxVal = (1 << bits) - 1;
- subTable = &upconvTable[(bits-1)*256];
+ subUpTable = &upconvTable[(bits-1)*256];
+ subDownTable = &downconvTable[(bits-1)*256];
for (i = 0;i <= maxVal;i++)
- subTable[i] = i * 255 / maxVal;
+ subUpTable[i] = i * 255 / maxVal;
- // Duplicate the table so that we don't have to care about
+ // Duplicate the up table so that we don't have to care about
// the upper bits when doing a lookup
for (;i < 256;i += maxVal+1)
- memcpy(&subTable[i], &subTable[0], maxVal+1);
+ memcpy(&subUpTable[i], &subUpTable[0], maxVal+1);
+
+ for (i = 0;i <= 255;i++)
+ subDownTable[i] = (i * maxVal + 128) / 255;
}
}