summaryrefslogtreecommitdiffstats
path: root/common/rfb/PixelFormat.inl
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2014-01-20 17:23:51 +0100
committerPierre Ossman <ossman@cendio.se>2014-07-07 13:27:09 +0200
commit8b874e4a09f5afb64a1f5354e7da1491c3322b04 (patch)
tree9a44b8abb196f67b8391053ad0945bd7a7aa87cb /common/rfb/PixelFormat.inl
parenta22459d356be884aca3f4a1974de3e005da8ce7c (diff)
downloadtigervnc-8b874e4a09f5afb64a1f5354e7da1491c3322b04.tar.gz
tigervnc-8b874e4a09f5afb64a1f5354e7da1491c3322b04.zip
Optimise the RGB to pixel conversion to simple shifts
Might as well make it inline at this point as well as it is used heavily in other routines that convert entire blocks of pixels.
Diffstat (limited to 'common/rfb/PixelFormat.inl')
-rw-r--r--common/rfb/PixelFormat.inl52
1 files changed, 52 insertions, 0 deletions
diff --git a/common/rfb/PixelFormat.inl b/common/rfb/PixelFormat.inl
index 5743e495..547fae5d 100644
--- a/common/rfb/PixelFormat.inl
+++ b/common/rfb/PixelFormat.inl
@@ -75,6 +75,58 @@ 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
+{
+ 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;
+ }
+}
+
+
+inline Pixel PixelFormat::pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue, ColourMap* cm) const
+{
+ if (trueColour) {
+ Pixel p;
+
+ 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);
+ }
+}
+
+
inline void PixelFormat::rgbFromPixel(Pixel p, ColourMap* cm, rdr::U16 *r, rdr::U16 *g, rdr::U16 *b) const
{
if (trueColour) {