Mercurial > hg > Applications > TreeVNC
changeset 564:0751cb6c0715
fix deflator
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 03 Feb 2020 16:38:51 +0900 |
parents | 5bbe53b47d0a |
children | 2a601e25ce10 |
files | src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java |
diffstat | 1 files changed, 21 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Mon Feb 03 15:19:30 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Mon Feb 03 16:38:51 2020 +0900 @@ -27,11 +27,9 @@ import com.glavsoft.drawing.Renderer; import com.glavsoft.exceptions.TransportException; import com.glavsoft.rfb.encoding.EncodingType; -import com.glavsoft.rfb.protocol.ReceiverTask; import com.glavsoft.transport.Reader; import jp.ac.u_ryukyu.treevnc.CheckDelay; import jp.ac.u_ryukyu.treevnc.TreeRFBProto; - import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.util.LinkedList; @@ -155,71 +153,44 @@ int MAX_ZTILE = 512; public void multicastPut(TreeRFBProto rfb, boolean last, FramebufferUpdateRectangle rect, byte[] bytes, int offset, int tileW, int tileH) { + boolean flush = false; if (!blocking) return; int span = offset - prevoffset; deflater.setInput(bytes, prevoffset, span); + int output = deflater.deflate(c1, Deflater.NO_FLUSH); + if (output==0 && ! deflater.needsInput() ) { + // compression failed + deflater.finish(); + flushRectangle(rect); + flushMuticast(rfb); + if (!last) { + newMulticastPacket(rfb, rect); + deflater.deflate(c1, Deflater.NO_FLUSH); + } else { + deflater.deflate(c1, Deflater.NO_FLUSH); + deflater.finish(); + flushMuticast(rfb); + } + return ; + } prevoffset = offset; width += tileW; if (c1rect.x > rect.x) { // phase 0 if (c1rect.x + c1rect.width < rect.x + rect.width) { - compressAndCheckFlush(rfb, rect, bytes, offset, false, last); - } else { + } else { // end of phase 0 c1rect.width = rect.x + rect.width - c1rect.x; prevC1LineOffset = c1.position(); - compressAndCheckFlush(rfb, rect, bytes, offset, true, last); } } else { // phase 1 - if (width >= rect.width) { + if (width >= rect.width) { // next line c1rect.width = rect.width; width = 0; prevLineOffset = offset; prevC1LineOffset = c1.position(); - compressAndCheckFlush(rfb, rect, bytes, offset, true, last); - } else { - compressAndCheckFlush(rfb, rect, bytes, offset, false, last); } } } - private boolean compressAndCheckFlush(TreeRFBProto rfb, FramebufferUpdateRectangle rect, byte[] bytes, int offset, boolean flush, boolean last) { - deflater.deflate(c1, Deflater.NO_FLUSH); - int headerLength = 20; - if (!deflater.needsInput()) { - deflater.finish(); - if (offset != prevLineOffset) { - // fix phase1 rectangle header - //c1.putShort(prevC1Offset - 16, (short) c1rect.x); - //c1.putShort(prevC1Offset - 14, (short) c1rect.y); - //c1.putShort(prevC1Offset - 12, (short) c1rect.width); - //c1.putShort(prevC1Offset - 10, (short) c1rect.height); - //c1.putInt(prevC1Offset - 8, EncodingType.ZRLEE.getId()); - //c1.putInt(prevC1Offset - 4, c1.position() - prevC1LineOffset - 12); // data length - //c1.putShort(2, (short) (c1.getShort(2) + 1)); // increment rectangle count - - - //if (c1rect.x == rect.x) { // phase0 needs no phase1 - // // make header space for phase2 - // c1.limit(c1.limit() + headerLength); - // int pos = c1.position() - 1; - // // to make rectangle header shift last bytes - // for (int i = 0; i < pos - prevC1LineOffset; i++) { - // c1.array()[pos + headerLength - i] = c1.array()[pos - i]; - // } - // prevC1Offset = prevC1LineOffset; - //} - } - flushRectangle(rect); - flushMuticast(rfb); - newMulticastPacket(rfb, rect); - deflater.deflate(c1, Deflater.NO_FLUSH); - return true; - } else if (last) { - flushRectangle(rect); - flushMuticast(rfb); - return true; - } - return false; - } /** * fix rectangle header @@ -236,7 +207,6 @@ c1.putInt(prevC1Offset - 4, c1.position() - prevC1Offset - 12); // data length c1.putShort(2, (short) (c1.getShort(2) + 1)); // increment rectangle count prevC1Offset = c1.position(); - nextPhase(rect); } @@ -313,7 +283,8 @@ for (int tileX = rect.x; tileX < maxX; tileX += MAX_TILE_SIZE) { int tileWidth = Math.min(maxX - tileX, MAX_TILE_SIZE); - tileloop.c1rect.width += tileWidth; + if (tileloop.c1rect.x + tileloop.c1rect.width < rect.x + rect.width) + tileloop.c1rect.width += tileWidth; int subencoding = bytes[offset++] & 0x0ff; if (subencoding != 0) System.out.println("----------------" + subencoding);