Compute the number of rectangles as required by Tight.
The encoder actually seems to work now.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@166 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/rfb/VNCSConnectionST.cxx b/rfb/VNCSConnectionST.cxx
index 3ae378e..426ecd4 100644
--- a/rfb/VNCSConnectionST.cxx
+++ b/rfb/VNCSConnectionST.cxx
@@ -561,7 +561,18 @@
   updates.enable_copyrect(cp.useCopyRect);
   updates.get_update(&update, requested);
   if (!update.is_empty() || writer()->needFakeUpdate() || drawRenderedCursor) {
-    int nRects = update.numRects() + (drawRenderedCursor ? 1 : 0);
+    // Compute the number of rectangles. Tight encoder makes the things more
+    // complicated as compared to the original RealVNC.
+    writer()->setupCurrentEncoder();
+    int nRects = update.copied.numRects() + (drawRenderedCursor ? 1 : 0);
+    std::vector<Rect> rects;
+    std::vector<Rect>::const_iterator i;
+    update.changed.get_rects(&rects);
+    for (i = rects.begin(); i != rects.end(); i++) {
+      if (i->width() && i->height())
+	nRects += writer()->getNumRects(*i);
+    }
+    
     writer()->writeFramebufferUpdateStart(nRects);
     Region updatedRegion;
     writer()->writeRects(update, &image_getter, &updatedRegion);