Add support for TurboVNC pseudo-encodings and Grayscale JPEG compression so that, when a TurboVNC viewer is connected, the TigerVNC Server will behave exactly like the TurboVNC Server.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4641 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/TightEncoder.cxx b/common/rfb/TightEncoder.cxx
index e35bad6..b7ef223 100644
--- a/common/rfb/TightEncoder.cxx
+++ b/common/rfb/TightEncoder.cxx
@@ -117,9 +117,21 @@
 void TightEncoder::setQualityLevel(int level)
 {
   if (level >= 0 && level <= 9) {
-    pjconf = &conf[level];
+    jpegQuality = conf[level].jpegQuality;
+    jpegSubsampling = conf[level].jpegSubsampling;
   } else {
-    pjconf = NULL;
+    jpegQuality = -1;
+    jpegSubsampling = SUBSAMP_UNDEFINED;
+  }
+}
+
+void TightEncoder::setFineQualityLevel(int quality, JPEG_SUBSAMP subsampling)
+{
+  if (quality >= 1 && quality <= 100) {
+    jpegQuality = quality;
+  }
+  if (subsampling >= SUBSAMP_NONE && subsampling <= SUBSAMP_GRAY) {
+    jpegSubsampling = subsampling;
   }
 }
 
@@ -333,6 +345,14 @@
       sr.setXYWH(dx, dy, dw, dh);
       if (checkSolidTile(sr, &colorValue, false)) {
 
+         if (jpegSubsampling == SUBSAMP_GRAY && jpegQuality != -1) {
+           Colour rgb;
+           serverpf.rgbFromPixel(colorValue, NULL, &rgb);
+           rdr::U32 lum = ((257 * rgb.r) + (504 * rgb.g) + (98 * rgb.b)
+                           + 16500) / 1000;
+           colorValue = lum + (lum << 8) + (lum << 16);
+         }
+
         // Get dimensions of solid-color area.
         sr.setXYWH(dx, dy, r.br.x - dx, r.br.y - dy);
         findBestSolidArea(sr, colorValue, bestr);