changeset 596:2904bc59ac8e

fix phase2
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 14 Feb 2020 03:51:22 +0900
parents 68d73c074d28
children e7748e46acad
files src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java
diffstat 1 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java	Fri Feb 14 03:08:59 2020 +0900
+++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java	Fri Feb 14 03:51:22 2020 +0900
@@ -168,11 +168,10 @@
 					assert(prevoffset==offset);
 					System.out.println("od prevOffset = "+prevoffset+" span = "+(prevoffset-flushOffset));
 					if (c0rect!=null) { // finish pahse 1
-						flushRectangle(c0rect);
-						c1.position(c1.position()+16); // header space
-						prevC1Offset = c1.position();
+						flushRectangle(c0rect,prevC1LineOffset);
+						moveNext();
 					}
-					flushRectangle(c1rect); // phase 2
+					flushRectangle(c1rect,c1.position()); // phase 2
 					flushMuticast(rfb, bytes);
 					if (last) {
 						return;
@@ -191,8 +190,11 @@
 			prevoffset = offset;
 			if (last) {
 				flushDeflator();
-				if (c0rect!=null) { flushRectangle(c0rect); moveNext(); }
-				flushRectangle(c1rect);
+				if (c0rect!=null) {
+					flushRectangle(c0rect,prevC1LineOffset);
+					moveNext();
+				}
+				flushRectangle(c1rect,c1.position());
 				flushMuticast(rfb, bytes);
 				return;
 			}
@@ -201,7 +203,7 @@
 				assert(c0rect==null);
 				if (c1rect.x + c1rect.width >= rect.x + rect.width) {  // end of phase 0
 					deflater.deflate(c1,Deflater.FULL_FLUSH);
-					flushRectangle(c1rect);
+					flushRectangle(c1rect,c1.position());
 					c1.position(c1.position()+16); // header space
 					prevC1Offset = c1.position();
 					c1rect = new FramebufferUpdateRectangle(rect.x,c1rect.y+tileH,0,0);
@@ -209,6 +211,7 @@
 				}
 			} else {  // phase 1
 				if (width >= rect.width) { // next line
+					deflater.deflate(c1,Deflater.FULL_FLUSH);
 					prevC1LineOffset = c1.position();
 					if (c0rect!=null) { // extend phase 1
 						c0rect.height += tileH;
@@ -249,13 +252,13 @@
 		 * update position paramater
 		 * send muticast pacate if nessesally
 		 */
-		private void flushRectangle(FramebufferUpdateRectangle rect) {
+		private void flushRectangle(FramebufferUpdateRectangle rect,int pos) {
 			c1.putShort(prevC1Offset - 16, (short) rect.x);
 			c1.putShort(prevC1Offset - 14, (short) rect.y);
 			c1.putShort(prevC1Offset - 12, (short) rect.width);
 			c1.putShort(prevC1Offset - 10, (short) rect.height);
 			c1.putInt(prevC1Offset - 8, EncodingType.ZRLEE.getId());
-			c1.putInt(prevC1Offset  - 4, c1.position() - prevC1Offset ); // data length
+			c1.putInt(prevC1Offset  - 4, pos - prevC1Offset ); // data length
 			c1.putShort(2, (short) (c1.getShort(2) + 1));    // increment rectangle count
 		}