From 365427ae873ef3e148159832c92ff080d78743cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20=C3=85strand?= Date: Wed, 29 Dec 2004 10:59:03 +0000 Subject: [PATCH] Added options CompressLevel and CustomCompressLevel git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@58 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- rfb/CMsgWriter.cxx | 4 +++- rfb/ConnParams.cxx | 23 +++++++++++++-------- rfb/ConnParams.h | 4 +++- rfb/encodings.h | 2 ++ vncviewer/CViewOptions.cxx | 41 ++++++++++++++++++++++++++++--------- vncviewer/CViewOptions.h | 6 +++++- vncviewer/OptionsDialog.cxx | 4 ++++ vncviewer/cview.cxx | 4 +++- 8 files changed, 66 insertions(+), 22 deletions(-) diff --git a/rfb/CMsgWriter.cxx b/rfb/CMsgWriter.cxx index 1693cbfd..c9912cea 100644 --- a/rfb/CMsgWriter.cxx +++ b/rfb/CMsgWriter.cxx @@ -76,7 +76,9 @@ void CMsgWriter::writeSetEncodings(int preferredEncoding, bool useCopyRect) } } 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 33cd21d8..7dcfdccf 100644 --- a/rfb/ConnParams.cxx +++ b/rfb/ConnParams.cxx @@ -27,9 +27,9 @@ using namespace rfb; 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 @@ void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings) 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 @@ void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings) 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 4d08b6d9..70578eac 100644 --- a/rfb/ConnParams.h +++ b/rfb/ConnParams.h @@ -73,8 +73,10 @@ namespace rfb { 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 f0f639bb..a40af822 100644 --- a/rfb/encodings.h +++ b/rfb/encodings.h @@ -37,6 +37,8 @@ namespace rfb { 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 199ddb5e..457da488 100644 --- a/vncviewer/CViewOptions.cxx +++ b/vncviewer/CViewOptions.cxx @@ -81,15 +81,24 @@ static BoolParameter acceptBell("AcceptBell", 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 @@ shared(::sharedConnection), sendPtrEvents(::sendPtrEvents), sendKeyEvents(::send 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 @@ void CViewOptions::readFromFile(const char* filename) { 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 @@ void CViewOptions::writeToFile(const char* filename) { 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 @@ void CViewOptions::writeDefaults() { 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 @@ CViewOptions& CViewOptions::operator=(const CViewOptions& o) { 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 88b659f0..e45612c3 100644 --- a/vncviewer/CViewOptions.h +++ b/vncviewer/CViewOptions.h @@ -77,8 +77,12 @@ namespace rfb { 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 4ff4600c..ae3f08a6 100644 --- a/vncviewer/OptionsDialog.cxx +++ b/vncviewer/OptionsDialog.cxx @@ -93,6 +93,8 @@ public: 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 @@ public: 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 ef0aa3ea..1a7507a3 100644 --- a/vncviewer/cview.cxx +++ b/vncviewer/cview.cxx @@ -252,8 +252,10 @@ CView::applyOptions(CViewOptions& opt) { (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; -- 2.39.5