changeset 496:1f3f2abc9c1b

fix zrleeBlocking
author oshiro
date Mon, 11 Feb 2019 19:24:39 +0900
parents 11f587612329
children 62d6e9180a11
files src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java
diffstat 1 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Thu Feb 07 17:04:10 2019 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Mon Feb 11 19:24:39 2019 +0900
@@ -632,7 +632,7 @@
      * @throws UnsupportedEncodingException
      */
     public void readSendData(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect)
-            throws Exception {
+            throws TransportException,UnsupportedEncodingException {
         LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
         int BLOCKSIZE = 64 * 1024;
         int headerLen = rect.getEncodingType() == EncodingType.CHECK_DELAY ? 24 : 16;
@@ -651,7 +651,11 @@
             if (encoding == EncodingType.ZRLE.getId()
                     || encoding == EncodingType.ZLIB.getId()) {
                 if (true) {
-                    zrleeBlocking(dataLen, reader, bytes, rect, context.getPixelFormat().bitsPerPixel/8, bufs, header);
+                    try {
+                        zrleeBlocking(dataLen, reader, bytes, rect, context.getPixelFormat().bitsPerPixel/8, bufs, header);
+                    } catch (DataFormatException e) {
+                        e.printStackTrace();
+                    }
                     return;
                 }
                 // recompress into ZREE
@@ -732,7 +736,7 @@
      */
 
 
-    private void zrleeBlocking(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect, int bytePerPixel, LinkedList<ByteBuffer> bufs, ByteBuffer header) throws Exception {
+    private void zrleeBlocking(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect, int bytePerPixel, LinkedList<ByteBuffer> bufs, ByteBuffer header) throws TransportException, DataFormatException {
         ByteBuffer len = multicastqueue.allocate(4);
         reader.readBytes(len.array(), 0, 4);
         len.limit(4);
@@ -755,19 +759,23 @@
         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 x = rect.x, y = rect.y, w = 0,  h = 0, w0 = 0, h0 = 0;
         int span = rect.width;
         while (inputIndex < inflate_size) {
             deflater.setInput(bytes,inputIndex,span * bytePerPixel);
-            if (c1.remaining() < span * bytePerPixel || inputIndex < inflate_size - 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(),x+w,y+h,h-h0,w-w0);
+                try {
+                    writeUpdateRectangleWithHeader(c1,header,c1.remaining(),x+w,y+h,rect.width,h-h0);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
                 h0 = h;
                 w0 = w;
                 c1.reset();
             } else {
-                deflater.deflate(c1);
+                deflater.deflate(c1,Deflater.SYNC_FLUSH);
             }
             w += span;
             if (w >= rect.width ) {