]> source.dussan.org Git - tigervnc.git/commitdiff
Revert r4498 and fix #3305357 properly. The issue was two-fold: (1) the compress...
authorDRC <dcommander@users.sourceforge.net>
Tue, 9 Aug 2011 11:12:55 +0000 (11:12 +0000)
committerDRC <dcommander@users.sourceforge.net>
Tue, 9 Aug 2011 11:12:55 +0000 (11:12 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4617 3789f03b-4d11-0410-bbf8-ca57d06f2519

common/rdr/ZlibOutStream.cxx
common/rfb/tightEncode.h

index c39aa55dcc4bd0762e81ed3760e9e293ecd3d260..c86a5a5585a1e21c1dc6751c34d6d8ccf554ff80 100644 (file)
@@ -1,4 +1,5 @@
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
+ * Copyright (C) 2011 D. R. Commander.  All Rights Reserved.
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -88,6 +89,10 @@ void ZlibOutStream::flush()
 //        fprintf(stderr,"zos flush: calling deflate, avail_in %d, avail_out %d\n",
 //                zs->avail_in,zs->avail_out);
       checkCompressionLevel();
+      if (zs->avail_in != 0) {
+        int rc = deflate(zs, Z_SYNC_FLUSH);
+        if (rc != Z_OK) throw Exception("ZlibOutStream: deflate failed");
+      }
 
 //        fprintf(stderr,"zos flush: after deflate: %d bytes\n",
 //                zs->next_out-underlying->getptr());
@@ -119,7 +124,11 @@ int ZlibOutStream::overrun(int itemSize, int nItems)
 //        fprintf(stderr,"zos overrun: calling deflate, avail_in %d, avail_out %d\n",
 //                zs->avail_in,zs->avail_out);
 
-      checkCompressionLevel();
+     checkCompressionLevel();
+     if (zs->avail_in != 0) {
+       int rc = deflate(zs, 0);
+       if (rc != Z_OK) throw Exception("ZlibOutStream: deflate failed");
+     }
 
 //        fprintf(stderr,"zos overrun: after deflate: %d bytes\n",
 //                zs->next_out-underlying->getptr());
@@ -151,15 +160,9 @@ int ZlibOutStream::overrun(int itemSize, int nItems)
 void ZlibOutStream::checkCompressionLevel()
 {
   if (newLevel != compressionLevel) {
-    int rc = deflate(zs, Z_SYNC_FLUSH);
-    if (rc != Z_OK) 
-      throw Exception("ZlibOutStream: deflate failed");
-    if (deflateParams (zs, newLevel, Z_DEFAULT_STRATEGY) != Z_OK)
+    if (deflateParams (zs, newLevel, Z_DEFAULT_STRATEGY) != Z_OK) {
       throw Exception("ZlibOutStream: deflateParams failed");
+    }
     compressionLevel = newLevel;
-  } else {
-    int rc = deflate(zs, Z_SYNC_FLUSH);
-    if (rc != Z_OK) 
-      throw Exception("ZlibOutStream: deflate failed");
   }
 }
index 2e6d0d8861ba85bdd35d948f9a943b0f4097c78a..9877759ad3546321c87b35941ef1c8453f99137a 100644 (file)
@@ -1,4 +1,5 @@
 /* Copyright (C) 2000-2003 Constantin Kaplinsky.  All Rights Reserved.
+ * Copyright (C) 2011 D. R. Commander.  All Rights Reserved.
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -188,7 +189,9 @@ static void compressData(rdr::OutStream *os, rdr::ZlibOutStream *zos,
   } else {
     // FIXME: Using a temporary MemOutStream may be not efficient.
     //        Maybe use the same static object used in the JPEG coder?
-    rdr::MemOutStream mem_os;
+    int maxBeforeSize = s_pconf->maxRectSize * (BPP / 8);
+    int maxAfterSize = maxBeforeSize + (maxBeforeSize + 99) / 100 + 12;
+    rdr::MemOutStream mem_os(maxAfterSize);
     zos->setUnderlying(&mem_os);
     zos->setCompressionLevel(zlibLevel);
     zos->writeBytes(buf, length);