Mercurial > hg > Applications > tvnjviewer
changeset 20:419ac2f759d5
copy unzip method from TreeVNC and improve
author | sugi |
---|---|
date | Wed, 05 Nov 2014 22:46:57 +0900 |
parents | 6886a2e890cc |
children | 966878ff1227 |
files | src/main/java/com/glavsoft/rfb/encoding/decoder/AliceVNCMessage.java src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java src/main/java/com/glavsoft/rfb/encoding/decoder/ZlibDecoder.java |
diffstat | 3 files changed, 33 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/AliceVNCMessage.java Tue Nov 04 11:37:09 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/AliceVNCMessage.java Wed Nov 05 22:46:57 2014 +0900 @@ -13,8 +13,7 @@ public int width; public int height; public int encodingTypeId; - //public byte[] buf; - public int offset; + //public byte[] buf; public String name;
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Tue Nov 04 11:37:09 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Wed Nov 05 22:46:57 2014 +0900 @@ -24,11 +24,15 @@ package com.glavsoft.rfb.encoding.decoder; +import java.util.zip.DataFormatException; +import java.util.zip.Inflater; + import alice.datasegment.DataSegment; import alice.datasegment.ReceiveData; import com.glavsoft.drawing.Renderer; import com.glavsoft.exceptions.TransportException; +import com.glavsoft.rfb.encoding.EncodingType; import com.glavsoft.transport.Reader; public class ZRLEDecoder extends ZlibDecoder { @@ -43,17 +47,17 @@ if (0 == zippedLength) return; int length = rect.width * rect.height * renderer.getBytesPerPixel(); byte[] bytes = unzip(reader, zippedLength, length); - int offset = zippedLength; + System.out.println(bytes.length); AliceVNCMessage message = new AliceVNCMessage(); message.setRectangle(rect); - message.offset = offset; + message.encodingTypeId = EncodingType.ZRLEE.getId(); ReceiveData rData = new ReceiveData(bytes.clone(), false, false); DataSegment.getLocal().put("pixelByteArray", rData, null); rData = new ReceiveData(message, false, false); DataSegment.getLocal().put("aliceVNCMessage", rData, null); - decode(renderer, rect, bytes, offset); + decode(renderer, rect, bytes, 0); } public void decode(Renderer renderer, @@ -181,4 +185,28 @@ } return paletteSize * bytesPerCPixel; } + + @Override + protected byte[] unzip(Reader reader, int zippedLength, int length) + throws TransportException { + byte[] input = ByteBuffer.getInstance().getBuffer(zippedLength); + byte[] bytes = new byte[length]; + reader.readBytes(input, 0, zippedLength); + if (null == decoder) { + decoder = new Inflater(); + } + decoder.setInput(input, 0, zippedLength); + int position = 0; + try { + do { + int len = decoder.inflate(bytes, position, bytes.length - position); + if (len > 0) { + position += len; + } + } while (!decoder.needsInput()); + } catch (DataFormatException e) { + throw new TransportException("cannot inflate Zlib data", e); + } + return bytes; + } }
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZlibDecoder.java Tue Nov 04 11:37:09 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZlibDecoder.java Wed Nov 05 22:46:57 2014 +0900 @@ -33,7 +33,7 @@ import java.util.zip.Inflater; public class ZlibDecoder extends Decoder { - private Inflater decoder; + protected Inflater decoder; @Override public void decode(Reader reader, Renderer renderer,