changeset 495:11f587612329

change zrleeBlocking treevnc/TreeRFBProto.java
author oshiro
date Thu, 07 Feb 2019 17:04:10 +0900
parents 7007d9785737
children 1f3f2abc9c1b
files src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java
diffstat 1 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Wed Feb 06 20:39:58 2019 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Thu Feb 07 17:04:10 2019 +0900
@@ -755,23 +755,32 @@
         out.add(ByteBuffer.wrap(bytes));
         int inputIndex = 0;
         ByteBuffer c1 = multicastqueue.allocate(deflate_size);
+        int x = rect.x, y = rect.y, w = 0, h = 0, w0 = 0, h0 = 0;
+        int span = rect.width;
         while (inputIndex < inflate_size) {
-            c1.reset();
-            deflater.finish();
-            deflater.setInput(bytes,inputIndex,rect.width * bytePerPixel);
-            if (c1.remaining() < rect.width * bytePerPixel) {
+            deflater.setInput(bytes,inputIndex,span * bytePerPixel);
+            if (c1.remaining() < span * bytePerPixel || inputIndex < inflate_size - span * bytePerPixel) {
                 deflater.deflate(c1,Deflater.FULL_FLUSH);
                 c1.flip();
-                writeUpdateRectangleWithHeader(c1,header,c1.remaining());
+                writeUpdateRectangleWithHeader(c1,header,c1.remaining(),x+w,y+h,h-h0,w-w0);
+                h0 = h;
+                w0 = w;
+                c1.reset();
             } else {
                 deflater.deflate(c1);
             }
+            w += span;
+            if (w >= rect.width ) {
+                h++;
+                w = 0;
+                w0 = 0;
+            }
             inputIndex += rect.width * bytePerPixel;
         }
         return;
     }
 
-    private void writeUpdateRectangleWithHeader(ByteBuffer c1, ByteBuffer header, int len2) throws InterruptedException {
+    private void writeUpdateRectangleWithHeader(ByteBuffer c1, ByteBuffer header, int len2, int x, int y, int w, int h) throws InterruptedException {
         LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
         bufs.add(c1);
         deflater.reset();
@@ -780,10 +789,16 @@
         blen.putInt(len2);
         blen.flip();
         bufs.addFirst(blen);
+        ByteBuffer hdr = multicastqueue.allocate(header.array().length);
+        hdr.put(header.array());
+        hdr.putShort(4,(short) x);
+        hdr.putShort(6,(short) y);
+        hdr.putShort(8,(short) w);
+        hdr.putShort(10,(short) h);
         if (checkDelay) {
-            bufs = createCheckDelayHeader(bufs, header);
+            bufs = createCheckDelayHeader(bufs, hdr);
         } else {
-            bufs.addFirst(header);
+            bufs.addFirst(hdr);
         }
         if (addSerialNum) {
             addSerialNumber(bufs);