Mercurial > hg > Members > riono > TreeVNC_ja_comment
comparison src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java @ 496:1f3f2abc9c1b
fix zrleeBlocking
author | oshiro |
---|---|
date | Mon, 11 Feb 2019 19:24:39 +0900 |
parents | 11f587612329 |
children | 62d6e9180a11 |
comparison
equal
deleted
inserted
replaced
495:11f587612329 | 496:1f3f2abc9c1b |
---|---|
630 * @param reader | 630 * @param reader |
631 * @throws TransportException | 631 * @throws TransportException |
632 * @throws UnsupportedEncodingException | 632 * @throws UnsupportedEncodingException |
633 */ | 633 */ |
634 public void readSendData(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect) | 634 public void readSendData(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect) |
635 throws Exception { | 635 throws TransportException,UnsupportedEncodingException { |
636 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); | 636 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); |
637 int BLOCKSIZE = 64 * 1024; | 637 int BLOCKSIZE = 64 * 1024; |
638 int headerLen = rect.getEncodingType() == EncodingType.CHECK_DELAY ? 24 : 16; | 638 int headerLen = rect.getEncodingType() == EncodingType.CHECK_DELAY ? 24 : 16; |
639 ByteBuffer header = multicastqueue.allocate(headerLen); | 639 ByteBuffer header = multicastqueue.allocate(headerLen); |
640 ByteBuffer serial = multicastqueue.allocate(4 + 8); | 640 ByteBuffer serial = multicastqueue.allocate(4 + 8); |
649 int encoding = header.getInt(12); | 649 int encoding = header.getInt(12); |
650 | 650 |
651 if (encoding == EncodingType.ZRLE.getId() | 651 if (encoding == EncodingType.ZRLE.getId() |
652 || encoding == EncodingType.ZLIB.getId()) { | 652 || encoding == EncodingType.ZLIB.getId()) { |
653 if (true) { | 653 if (true) { |
654 zrleeBlocking(dataLen, reader, bytes, rect, context.getPixelFormat().bitsPerPixel/8, bufs, header); | 654 try { |
655 zrleeBlocking(dataLen, reader, bytes, rect, context.getPixelFormat().bitsPerPixel/8, bufs, header); | |
656 } catch (DataFormatException e) { | |
657 e.printStackTrace(); | |
658 } | |
655 return; | 659 return; |
656 } | 660 } |
657 // recompress into ZREE | 661 // recompress into ZREE |
658 // uncompressed result is remain in bytes | 662 // uncompressed result is remain in bytes |
659 ByteBuffer len = multicastqueue.allocate(4); | 663 ByteBuffer len = multicastqueue.allocate(4); |
730 * @throws TransportException | 734 * @throws TransportException |
731 * @throws UnsupportedEncodingException | 735 * @throws UnsupportedEncodingException |
732 */ | 736 */ |
733 | 737 |
734 | 738 |
735 private void zrleeBlocking(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect, int bytePerPixel, LinkedList<ByteBuffer> bufs, ByteBuffer header) throws Exception { | 739 private void zrleeBlocking(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect, int bytePerPixel, LinkedList<ByteBuffer> bufs, ByteBuffer header) throws TransportException, DataFormatException { |
736 ByteBuffer len = multicastqueue.allocate(4); | 740 ByteBuffer len = multicastqueue.allocate(4); |
737 reader.readBytes(len.array(), 0, 4); | 741 reader.readBytes(len.array(), 0, 4); |
738 len.limit(4); | 742 len.limit(4); |
739 ByteBuffer inputData = multicastqueue.allocate(dataLen - 20); | 743 ByteBuffer inputData = multicastqueue.allocate(dataLen - 20); |
740 reader.readBytes(inputData.array(), 0, inputData.capacity()); | 744 reader.readBytes(inputData.array(), 0, inputData.capacity()); |
753 unzip(inflater, inputs, 0, bytes, inflate_size); | 757 unzip(inflater, inputs, 0, bytes, inflate_size); |
754 // dump32(inputs); | 758 // dump32(inputs); |
755 out.add(ByteBuffer.wrap(bytes)); | 759 out.add(ByteBuffer.wrap(bytes)); |
756 int inputIndex = 0; | 760 int inputIndex = 0; |
757 ByteBuffer c1 = multicastqueue.allocate(deflate_size); | 761 ByteBuffer c1 = multicastqueue.allocate(deflate_size); |
758 int x = rect.x, y = rect.y, w = 0, h = 0, w0 = 0, h0 = 0; | 762 int x = rect.x, y = rect.y, w = 0, h = 0, w0 = 0, h0 = 0; |
759 int span = rect.width; | 763 int span = rect.width; |
760 while (inputIndex < inflate_size) { | 764 while (inputIndex < inflate_size) { |
761 deflater.setInput(bytes,inputIndex,span * bytePerPixel); | 765 deflater.setInput(bytes,inputIndex,span * bytePerPixel); |
762 if (c1.remaining() < span * bytePerPixel || inputIndex < inflate_size - span * bytePerPixel) { | 766 if (c1.remaining() < span * bytePerPixel || inputIndex >= inflate_size - span * bytePerPixel) { |
763 deflater.deflate(c1,Deflater.FULL_FLUSH); | 767 deflater.deflate(c1,Deflater.FULL_FLUSH); |
764 c1.flip(); | 768 c1.flip(); |
765 writeUpdateRectangleWithHeader(c1,header,c1.remaining(),x+w,y+h,h-h0,w-w0); | 769 try { |
770 writeUpdateRectangleWithHeader(c1,header,c1.remaining(),x+w,y+h,rect.width,h-h0); | |
771 } catch (InterruptedException e) { | |
772 e.printStackTrace(); | |
773 } | |
766 h0 = h; | 774 h0 = h; |
767 w0 = w; | 775 w0 = w; |
768 c1.reset(); | 776 c1.reset(); |
769 } else { | 777 } else { |
770 deflater.deflate(c1); | 778 deflater.deflate(c1,Deflater.SYNC_FLUSH); |
771 } | 779 } |
772 w += span; | 780 w += span; |
773 if (w >= rect.width ) { | 781 if (w >= rect.width ) { |
774 h++; | 782 h++; |
775 w = 0; | 783 w = 0; |