Added options CompressLevel and CustomCompressLevel


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@58 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/rfb/CMsgWriter.cxx b/rfb/CMsgWriter.cxx
index 1693cbf..c9912ce 100644
--- a/rfb/CMsgWriter.cxx
+++ b/rfb/CMsgWriter.cxx
@@ -76,7 +76,9 @@
     }
   }
   encodings[nEncodings++] = pseudoEncodingLastRect;
-  if (cp->qualityLevel >= 0 && cp->qualityLevel <= 9)
+  if (cp->customCompressLevel && cp->compressLevel >= 0 && cp->compressLevel <= 9)
+      encodings[nEncodings++] = pseudoEncodingCompressLevel0 + cp->compressLevel;
+  if (!cp->noJpeg && cp->qualityLevel >= 0 && cp->qualityLevel <= 9)
       encodings[nEncodings++] = pseudoEncodingQualityLevel0 + cp->qualityLevel;
 
   writeSetEncodings(nEncodings, encodings);
diff --git a/rfb/ConnParams.cxx b/rfb/ConnParams.cxx
index 33cd21d..7dcfdcc 100644
--- a/rfb/ConnParams.cxx
+++ b/rfb/ConnParams.cxx
@@ -27,9 +27,9 @@
 
 ConnParams::ConnParams()
   : majorVersion(0), minorVersion(0), width(0), height(0), useCopyRect(false),
-    supportsLocalCursor(false), supportsDesktopResize(false),
-    supportsLastRect(false), qualityLevel(-1), noJpeg(false),
-    name_(0), nEncodings_(0), encodings_(0),
+    supportsLocalCursor(false), supportsDesktopResize(false), supportsLastRect(false), 
+    customCompressLevel(false), compressLevel(6), noJpeg(false), qualityLevel(-1), 
+    name_(0), nEncodings_(0), encodings_(0), 
     currentEncoding_(encodingRaw), verStrPos(0)
 {
   setName("");
@@ -89,8 +89,10 @@
   useCopyRect = false;
   supportsLocalCursor = false;
   supportsLastRect = false;
+  customCompressLevel = false;
+  compressLevel = -1;
+  noJpeg = true;
   qualityLevel = -1;
-  noJpeg = false;
   currentEncoding_ = encodingRaw;
 
   for (int i = nEncodings-1; i >= 0; i--) {
@@ -104,10 +106,15 @@
       supportsDesktopResize = true;
     else if (encodings[i] == pseudoEncodingLastRect)
       supportsLastRect = true;
-    else if (encodings[i] >= pseudoEncodingQualityLevel0 &&
-             encodings[i] <= pseudoEncodingQualityLevel9)
-	qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
-    else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i]))
+    else if (encodings[i] >= pseudoEncodingCompressLevel0 &&
+	     encodings[i] <= pseudoEncodingCompressLevel9) {
+      customCompressLevel = true;
+      compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
+    } else if (encodings[i] >= pseudoEncodingQualityLevel0 &&
+	       encodings[i] <= pseudoEncodingQualityLevel9) {
+      noJpeg = false;
+      qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
+    } else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i]))
       currentEncoding_ = encodings[i];
   }
 }
diff --git a/rfb/ConnParams.h b/rfb/ConnParams.h
index 4d08b6d..70578ea 100644
--- a/rfb/ConnParams.h
+++ b/rfb/ConnParams.h
@@ -73,8 +73,10 @@
     bool supportsDesktopResize;
     bool supportsLastRect;
 
-    int qualityLevel;
+    bool customCompressLevel;
+    int compressLevel;
     bool noJpeg;
+    int qualityLevel;
 
   private:
 
diff --git a/rfb/encodings.h b/rfb/encodings.h
index f0f639b..a40af82 100644
--- a/rfb/encodings.h
+++ b/rfb/encodings.h
@@ -37,6 +37,8 @@
   const unsigned int pseudoEncodingLastRect = 0xFFFFFF20;
   const unsigned int pseudoEncodingQualityLevel0 = 0xFFFFFFE0;
   const unsigned int pseudoEncodingQualityLevel9 = 0xFFFFFFE9;
+  const unsigned int pseudoEncodingCompressLevel0 = 0xFFFFFF00;
+  const unsigned int pseudoEncodingCompressLevel9 = 0xFFFFFF00;
 
   int encodingNum(const char* name);
   const char* encodingName(unsigned int num);
diff --git a/vncviewer/CViewOptions.cxx b/vncviewer/CViewOptions.cxx
index 199ddb5..457da48 100644
--- a/vncviewer/CViewOptions.cxx
+++ b/vncviewer/CViewOptions.cxx
@@ -81,15 +81,24 @@
 static StringParameter monitor("Monitor", "The monitor to open the VNC Viewer window on, if available.", "");
 static StringParameter menuKey("MenuKey", "The key which brings up the popup menu", "F8");
 
-static IntParameter qualityLevel("QualityLevel",
-				 "JPEG quality level. "
-				 "0 = Low, 9 = High",
-				 5);
+static BoolParameter customCompressLevel("CustomCompressLevel",
+				      "Use custom compression level",
+				      false);
+
+static IntParameter compressLevel("CompressLevel",
+				  "Use specified compression level"
+				  "0 = Low, 9 = High",
+				  6);
 
 static BoolParameter noJpeg("NoJPEG",
 			    "Disable lossy JPEG compression in Tight encoding.",
 			    false);
 
+static IntParameter qualityLevel("QualityLevel",
+				 "JPEG quality level. "
+				 "0 = Low, 9 = High",
+				 6);
+
 CViewOptions::CViewOptions()
 : useLocalCursor(::useLocalCursor), useDesktopResize(::useDesktopResize),
 autoSelect(::autoSelect), fullColour(::fullColour), fullScreen(::fullScreen),
@@ -97,7 +106,8 @@
 preferredEncoding(encodingZRLE), clientCutText(::clientCutText), serverCutText(::serverCutText),
 protocol3_3(::protocol3_3), acceptBell(::acceptBell), lowColourLevel(::lowColourLevel),
 pointerEventInterval(ptrEventInterval), emulate3(::emulate3), monitor(::monitor.getData()),
-qualityLevel(::qualityLevel), noJpeg(::noJpeg)
+customCompressLevel(::customCompressLevel), compressLevel(::compressLevel), 
+noJpeg(::noJpeg), qualityLevel(::qualityLevel)
 {
   CharArray encodingName(::preferredEncoding.getData());
   preferredEncoding = encodingNum(encodingName.buf);
@@ -197,10 +207,14 @@
             monitor.replaceBuf(value.takeBuf());
           } else if (stricmp(name.buf, "MenuKey") == 0) {
             setMenuKey(value.buf);
-          } else if (stricmp(name.buf, "QualityLevel") == 0) {
-	    qualityLevel = atoi(value.buf);
+          } else if (stricmp(name.buf, "CustomCompressLevel") == 0) {
+	    customCompressLevel = atoi(value.buf);
+          } else if (stricmp(name.buf, "CompressLevel") == 0) {
+	    compressLevel = atoi(value.buf);
           } else if (stricmp(name.buf, "NoJPEG") == 0) {
 	    noJpeg = atoi(value.buf);
+          } else if (stricmp(name.buf, "QualityLevel") == 0) {
+	    qualityLevel = atoi(value.buf);
             // Legacy options
           } else if (stricmp(name.buf, "Preferred_Encoding") == 0) {
             preferredEncoding = atoi(value.buf);
@@ -284,8 +298,10 @@
     if (monitor.buf)
       fprintf(f, "Monitor=%s\n", monitor.buf);
     fprintf(f, "MenuKey=%s\n", CharArray(menuKeyName()).buf);
-    fprintf(f, "QualityLevel=%d\n", qualityLevel);
+    fprintf(f, "CustomCompressLevel=%d\n", customCompressLevel);
+    fprintf(f, "CompressLevel=%d\n", compressLevel);
     fprintf(f, "NoJPEG=%d\n", noJpeg);
+    fprintf(f, "QualityLevel=%d\n", qualityLevel);
     fclose(f); f=0;
 
     setConfigFileName(filename);
@@ -318,8 +334,10 @@
   if (monitor.buf)
     key.setString(_T("Monitor"), TStr(monitor.buf));
   key.setString(_T("MenuKey"), TCharArray(menuKeyName()).buf);
-  key.setInt(_T("QualityLevel"), qualityLevel);
+  key.setInt(_T("CustomCompressLevel"), customCompressLevel);
+  key.setInt(_T("CompressLevel"), compressLevel);
   key.setInt(_T("NoJPEG"), noJpeg);
+  key.setInt(_T("QualityLevel"), qualityLevel);
 }
 
 
@@ -374,7 +392,10 @@
   setHost(o.host.buf);
   setMonitor(o.monitor.buf);
   menuKey = o.menuKey;
-  qualityLevel = o.qualityLevel;
+  customCompressLevel = o.customCompressLevel;
+  compressLevel = o.compressLevel;
   noJpeg = o.noJpeg;
+  qualityLevel = o.qualityLevel;
+
   return *this;
 }
diff --git a/vncviewer/CViewOptions.h b/vncviewer/CViewOptions.h
index 88b659f..e45612c 100644
--- a/vncviewer/CViewOptions.h
+++ b/vncviewer/CViewOptions.h
@@ -77,8 +77,12 @@
       unsigned int menuKey;
       void setMenuKey(const char* keyName);
       char* menuKeyName();
-      int qualityLevel;
+
+      bool customCompressLevel;
+      int compressLevel;
       bool noJpeg;
+      int qualityLevel;
+
     };
 
 
diff --git a/vncviewer/OptionsDialog.cxx b/vncviewer/OptionsDialog.cxx
index 4ff4600..ae3f08a 100644
--- a/vncviewer/OptionsDialog.cxx
+++ b/vncviewer/OptionsDialog.cxx
@@ -93,6 +93,8 @@
     case encodingHextile: setItemChecked(IDC_ENCODING_HEXTILE, true); break;
     case encodingRaw: setItemChecked(IDC_ENCODING_RAW, true); break;
     }
+    setItemChecked(IDC_ALLOW_COMPRESSLEVEL, dlg->options.customCompressLevel);
+    setItemInt(IDC_COMPRESSLEVEL, dlg->options.compressLevel);
     setItemChecked(IDC_ALLOW_JPEG, !dlg->options.noJpeg);
     setItemInt(IDC_QUALITYLEVEL, dlg->options.qualityLevel);
     onCommand(IDC_ENCODING_AUTO, 0 /* ? */); // Force enableItem status to refresh
@@ -100,6 +102,8 @@
   virtual bool onOk() {
     dlg->options.autoSelect = isItemChecked(IDC_ENCODING_AUTO);
     dlg->options.fullColour = isItemChecked(IDC_FORMAT_FULLCOLOUR);
+    dlg->options.customCompressLevel = isItemChecked(IDC_ALLOW_COMPRESSLEVEL);
+    dlg->options.compressLevel = getItemInt(IDC_COMPRESSLEVEL);
     dlg->options.noJpeg = !isItemChecked(IDC_ALLOW_JPEG);
     dlg->options.qualityLevel = getItemInt(IDC_QUALITYLEVEL);
     if (isItemChecked(IDC_FORMAT_VERYLOWCOLOUR))
diff --git a/vncviewer/cview.cxx b/vncviewer/cview.cxx
index ef0aa3e..1a7507a 100644
--- a/vncviewer/cview.cxx
+++ b/vncviewer/cview.cxx
@@ -252,8 +252,10 @@
     (options.useDesktopResize != opt.useDesktopResize));
   cp.supportsLocalCursor = options.useLocalCursor = opt.useLocalCursor;
   cp.supportsDesktopResize = options.useDesktopResize = opt.useDesktopResize;
-  cp.qualityLevel = options.qualityLevel = opt.qualityLevel;
+  cp.customCompressLevel = options.customCompressLevel = opt.customCompressLevel;
+  cp.compressLevel = options.compressLevel = opt.compressLevel;
   cp.noJpeg = options.noJpeg = opt.noJpeg;
+  cp.qualityLevel = options.qualityLevel = opt.qualityLevel;
   if (cursorAvailable)
     hideLocalCursor();
   cursorAvailable = cursorAvailable && options.useLocalCursor;