Mercurial > hg > Applications > TreeVNC
changeset 595:68d73c074d28
do not renew infrater in ZRLE decoder
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 14 Feb 2020 03:08:59 +0900 |
parents | 2ff55462c12d |
children | 2904bc59ac8e |
files | src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java src/main/java/com/glavsoft/rfb/encoding/decoder/ZlibDecoder.java src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java |
diffstat | 3 files changed, 29 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Thu Feb 13 21:52:36 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Fri Feb 14 03:08:59 2020 +0900 @@ -191,7 +191,7 @@ prevoffset = offset; if (last) { flushDeflator(); - if (c0rect!=null) flushRectangle(c0rect); + if (c0rect!=null) { flushRectangle(c0rect); moveNext(); } flushRectangle(c1rect); flushMuticast(rfb, bytes); return; @@ -222,6 +222,13 @@ } } + public void moveNext() { + // previous rectangle is finished, make next header space and copy already compressed part + System.arraycopy(c1.array(),prevC1LineOffset,c1.array(),c1.position()-prevC1LineOffset,16); + c1.position(c1.position()+16); + prevC1Offset = c1.position(); + } + private void flushDeflator() { c1.limit(c1.limit() + MARGIN); deflater.deflate(c1, Deflater.FULL_FLUSH);
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZlibDecoder.java Thu Feb 13 21:52:36 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZlibDecoder.java Fri Feb 14 03:08:59 2020 +0900 @@ -55,7 +55,7 @@ byte [] bytes = buf.array(); reader.readBytes(bytes, 0, zippedLength); buf.position(zippedLength); - if (null == decoder || encodingType == EncodingType.ZRLEE) { + if (null == decoder) { decoder = new Inflater(); } decoder.setInput(bytes, 0, zippedLength);
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Thu Feb 13 21:52:36 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Fri Feb 14 03:08:59 2020 +0900 @@ -244,7 +244,6 @@ } public void framebufferUpdateMessage(Reader reader) throws Exception { - int numberOfRectangles; try { reader.readByte(); // padding @@ -386,6 +385,7 @@ int numberOfRectangeles = in.readInt16(); if (true) { in.mark(c1.limit() - 4); + ZRLEDecoder decoder = new ZRLEDecoder(); int n = numberOfRectangeles; while(n-- > 0 ) { rect.fill(in); @@ -393,17 +393,25 @@ if (rect.getEncodingType() == EncodingType.ZRLEE) { int length = rect.width * rect.height * renderer.getBytesPerPixel(); int zippedLength = (int) in.readUInt32(); - ZRLEDecoder decoder = new ZRLEDecoder(); - ByteBuffer buf = decoder.unzip(in, zippedLength, length, rect.getEncodingType()); - compareBytes(buf, bytes, flushOffset, flushEnd); + if (zippedLength > in.available()) { + System.out.println("overrun zippedLength=" + zippedLength + " available="+in.available()); + } + try { + ByteBuffer buf = decoder.unzip(in, zippedLength, length, rect.getEncodingType()); + compareBytes(buf, bytes, flushOffset, flushOffset+buf.remaining()); + flushOffset += buf.remaining(); + } catch (Exception e) { + e.printStackTrace(); + } } } + assert(flushOffset==flushEnd); in.reset(); } + Decoder decoder = new ZRLEDecoder(); while (numberOfRectangeles-- > 0) { rect.fill(in); if (rect.getEncodingType() == EncodingType.ZRLEE) { - Decoder decoder = new ZRLEDecoder(); decoder.decode(in,new NullRenderer(context.getPixelFormat().bitsPerPixel/8, context.getFbWidth(), context.getFbHeight(), context.getPixelFormat()),rect); } } @@ -414,8 +422,14 @@ private void compareBytes(ByteBuffer buf, byte[] bytes, int flushOffset, int flushEnd) { int span = flushEnd - flushOffset; + int pos = buf.position(); if (buf.remaining() == span) { - + for(int i = 0;i<span;i++) { + if (buf.array()[pos+i]!=bytes[flushOffset+i]) { + System.out.println("Bytes is not equal at "+i); + break; + } + } } else { System.out.println("Bytes is not equal length "+buf.remaining()+" - "+span + " = " + (buf.remaining() - span)); }