annotate src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java @ 560:bdd659ce8e64

fix null renderer
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 31 Jan 2020 11:41:13 +0900
parents ff4c1972aa2e
children 5bbe53b47d0a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC.
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 // All rights reserved.
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //-------------------------------------------------------------------------
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is part of the TightVNC software. Please visit our Web site:
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 // http://www.tightvnc.com/
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 // This program is free software; you can redistribute it and/or modify
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // it under the terms of the GNU General Public License as published by
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 // the Free Software Foundation; either version 2 of the License, or
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 // (at your option) any later version.
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 // This program is distributed in the hope that it will be useful,
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 // GNU General Public License for more details.
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 // You should have received a copy of the GNU General Public License along
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 // with this program; if not, write to the Free Software Foundation, Inc.,
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 //-------------------------------------------------------------------------
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 package com.glavsoft.rfb.encoding.decoder;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 import com.glavsoft.drawing.Renderer;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 import com.glavsoft.exceptions.TransportException;
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
29 import com.glavsoft.rfb.encoding.EncodingType;
545
1ba61b57be39 add test routine in -p ( running as root mode )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 543
diff changeset
30 import com.glavsoft.rfb.protocol.ReceiverTask;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 import com.glavsoft.transport.Reader;
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
32 import jp.ac.u_ryukyu.treevnc.CheckDelay;
498
8d95d64c33bf add multicastPut
oshiro
parents: 275
diff changeset
33 import jp.ac.u_ryukyu.treevnc.TreeRFBProto;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
35 import java.io.UnsupportedEncodingException;
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
36 import java.nio.ByteBuffer;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
37 import java.util.LinkedList;
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
38 import java.util.zip.Deflater;
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
39
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 public class ZRLEDecoder extends ZlibDecoder {
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
41 private static final int MAX_TILE_SIZE = 64;
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
42 private int[] decodedBitmap;
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
43 private int[] palette;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
45 class TileLoop {
535
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
46 private final boolean blocking;
538
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
47 private int deflate_size = 55507;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
48 private ByteBuffer c1;
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
49 private int width; // phase2 length
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
50 private FramebufferUpdateRectangle c1rect;
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
51 private int prevLineOffset;
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
52 private int prevC1Offset;
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
53 private int prevC1LineOffset;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
54 private int prevoffset;
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
55 private Deflater deflater;
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
56
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
57 /**
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
58 * Multicast framebufferUpdate to children.
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
59 * read FrameBuffferUpdate. If it is ZLE, make it ZLEE which is self contained compressed packet.
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
60 * put the packet to the multicastqueue. Then normal rendering engine read the same stream using is.reset().
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
61 * <p>
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
62 * Haeder
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
63 * messageID ( FrameBuffer Update
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
64 * 1 byte padding
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
65 * 2 byte numberofrectangle
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
66 * 2 - U16 - x-position
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
67 * 2 - U16 - y-position
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
68 * 2 - U16 - width
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
69 * 2 - U16 - height
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
70 * 4 - S32 - encoding-type
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
71 * 4 byte datalengths
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
72 * datalengths databyte
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
73 *
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
74 * @throws TransportException
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
75 * @throws UnsupportedEncodingException
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
76 */
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
77
533
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
78 public TileLoop(int offset) {
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
79 prevoffset = prevLineOffset = offset;
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
80 prevC1Offset = 0;
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
81 if (offset < deflate_size + spanGap) {
535
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
82 // packet size fit in broadcast send it all at once
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
83 blocking = false;
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
84 } else
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
85 blocking = true;
533
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
86 }
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
87
535
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
88 private void zrleeBlocking(TreeRFBProto rfb, ByteBuffer header, FramebufferUpdateRectangle rect, byte bytes[]) {
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
89 // dump32(inputs);
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
90 deflater = rfb.deflater;
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
91 c1rect = new FramebufferUpdateRectangle(rect.x, rect.y, 0, 0);
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
92 newMulticastPacket(rfb, rect);
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
93 c1.put(header.get(0));
535
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
94 if (!blocking) {
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
95 deflater.setInput(bytes, 0, prevoffset);
535
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
96 deflater.deflate(c1);
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
97 flushMuticast(rfb);
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
98 }
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
99 return;
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
100 }
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
101
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
102 private void newMulticastPacket(TreeRFBProto rfb, FramebufferUpdateRectangle rect) {
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
103 c1 = rfb.multicastqueue.allocate(deflate_size + 20);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
104 c1.limit(c1.limit() - 20);
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
105 if (rfb.addSerialNum)
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
106 c1.putLong(rfb.counter++);
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
107 if (rfb.checkDelay)
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
108 CheckDelay.checkDelay(c1, rect.x, rect.y, rect.width, rect.height, System.currentTimeMillis(), EncodingType.CHECK_DELAY);
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
109 c1.put((byte) 0);
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
110 c1.put((byte) 0);
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
111 c1.putShort((short) 0);
550
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
112 c1.position(c1.position() + 12);
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
113 c1.putInt(0); // should be data length
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
114 prevC1Offset = c1.position();
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
115 prevC1LineOffset = prevC1Offset;
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
116 width = 0;
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
117 c1rect.width = c1rect.height = 0;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
118 }
531
13d3c4341d14 remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 529
diff changeset
119
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
120 int spanGap = 128;
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
121 /**
534
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
122 * Series of tiles compose at most three rectangles. SYNC_FLUSH is necessary on
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
123 * rectangle boundaries.
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
124 * <p>
545
1ba61b57be39 add test routine in -p ( running as root mode )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 543
diff changeset
125 * +----+
1ba61b57be39 add test routine in -p ( running as root mode )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 543
diff changeset
126 * | | phase 0
1ba61b57be39 add test routine in -p ( running as root mode )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 543
diff changeset
127 * +---------------+
1ba61b57be39 add test routine in -p ( running as root mode )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 543
diff changeset
128 * | | phase 1
1ba61b57be39 add test routine in -p ( running as root mode )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 543
diff changeset
129 * +----+----------+
1ba61b57be39 add test routine in -p ( running as root mode )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 543
diff changeset
130 * | | phase 2
1ba61b57be39 add test routine in -p ( running as root mode )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 543
diff changeset
131 * +----+
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
132 * <p>
534
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
133 * Broadcast packet have to less than 64kbytes
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
134 * A tile 64x64x3 11288byte, a packet can contain 5 raw tiles, when these are
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
135 * compressed 10 to 100 tiles can be stored. It is impossible to predict the
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
136 * compression rate. To check the compressed capacity, Deflate.needsInputs() can
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
137 * be used. If needsInputs() is false on SYNC_FLUSH, smaller input is necessary.
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
138 * <p>
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
139 * We'll try 512 tiles before SYNC_FLUSH in a phase, if it fails try flush former 256 tiles.
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
140 * If it will failed again, flush the previous line and do flush 512 tiles in new Packet.
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
141 * If it failed again try former 256 tiles flushed, if this failes again dicard the former half.
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
142 * The last case cannot happen but former 256 tiles have to be flushed, because the next 256 lines
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
143 * may failed again and restart the from this point.
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
144 * The next packet start with later 256 tiles filled and unflushed.
534
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
145 *
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
146 * @param rfb
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
147 * @param last
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
148 * @param rect
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
149 * @param bytes
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
150 * @param offset
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
151 * @param tileW
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
152 * @param tileH
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
153 */
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
154
534
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
155 int MAX_ZTILE = 512;
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
156
531
13d3c4341d14 remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 529
diff changeset
157 public void multicastPut(TreeRFBProto rfb, boolean last, FramebufferUpdateRectangle rect, byte[] bytes, int offset, int tileW, int tileH) {
535
17a2d0ea5c03 fix on ZRLEDecoder
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
158 if (!blocking) return;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
159 int span = offset - prevoffset;
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
160 deflater.setInput(bytes, prevoffset, span);
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
161 prevoffset = offset;
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
162 width += tileW;
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
163 if (c1rect.x > rect.x) { // phase 0
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
164 if (c1rect.x + c1rect.width < rect.x + rect.width) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
165 compressAndCheckFlush(rfb, rect, bytes, offset, false, last);
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
166 } else {
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
167 c1rect.width = rect.x + rect.width - c1rect.x;
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
168 prevC1LineOffset = c1.position();
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
169 compressAndCheckFlush(rfb, rect, bytes, offset, true, last);
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
170 }
538
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
171 } else { // phase 1
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
172 if (width >= rect.width) {
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
173 c1rect.width = rect.width;
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
174 width = 0;
531
13d3c4341d14 remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 529
diff changeset
175 prevLineOffset = offset;
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
176 prevC1LineOffset = c1.position();
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
177 compressAndCheckFlush(rfb, rect, bytes, offset, true, last);
533
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
178 } else {
538
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
179 compressAndCheckFlush(rfb, rect, bytes, offset, false, last);
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
180
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
181
534
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
182 }
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
183 }
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
184 }
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
185
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
186 private boolean compressAndCheckFlush(TreeRFBProto rfb, FramebufferUpdateRectangle rect, byte[] bytes, int offset, boolean flush, boolean last) {
538
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
187 deflater.deflate(c1, Deflater.NO_FLUSH);
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
188 int headerLength = 20;
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
189 if (!deflater.needsInput()) {
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
190 deflater.finish();
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
191 if (offset != prevLineOffset) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
192 // fix phase1 rectangle header
550
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
193 //c1.putShort(prevC1Offset - 16, (short) c1rect.x);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
194 //c1.putShort(prevC1Offset - 14, (short) c1rect.y);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
195 //c1.putShort(prevC1Offset - 12, (short) c1rect.width);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
196 //c1.putShort(prevC1Offset - 10, (short) c1rect.height);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
197 //c1.putInt(prevC1Offset - 8, EncodingType.ZRLEE.getId());
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
198 //c1.putInt(prevC1Offset - 4, c1.position() - prevC1LineOffset - 12); // data length
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
199 //c1.putShort(2, (short) (c1.getShort(2) + 1)); // increment rectangle count
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
200
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
201
550
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
202 //if (c1rect.x == rect.x) { // phase0 needs no phase1
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
203 // // make header space for phase2
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
204 // c1.limit(c1.limit() + headerLength);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
205 // int pos = c1.position() - 1;
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
206 // // to make rectangle header shift last bytes
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
207 // for (int i = 0; i < pos - prevC1LineOffset; i++) {
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
208 // c1.array()[pos + headerLength - i] = c1.array()[pos - i];
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
209 // }
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
210 // prevC1Offset = prevC1LineOffset;
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
211 //}
534
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
212 }
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
213 flushRectangle(rect);
538
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
214 flushMuticast(rfb);
6620e04f994c fix ZRLEDecoder
riono
parents: 535
diff changeset
215 newMulticastPacket(rfb, rect);
534
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
216 deflater.deflate(c1, Deflater.NO_FLUSH);
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
217 return true;
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
218 } else if (last) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
219 flushRectangle(rect);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
220 flushMuticast(rfb);
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
221 return true;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
222 }
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
223 return false;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
224 }
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
225
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
226 /**
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
227 * fix rectangle header
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
228 * create next rectangle header
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
229 * update position paramater
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
230 * send muticast pacate if nessesally
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
231 */
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
232 private void flushRectangle(FramebufferUpdateRectangle rect) {
550
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
233 c1.putShort(prevC1Offset - 16, (short) c1rect.x);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
234 c1.putShort(prevC1Offset - 14, (short) c1rect.y);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
235 c1.putShort(prevC1Offset - 12, (short) c1rect.width);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
236 c1.putShort(prevC1Offset - 10, (short) c1rect.height);
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
237 c1.putInt(prevC1Offset - 8, EncodingType.ZRLEE.getId());
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
238 c1.putInt(prevC1Offset - 4, c1.position() - prevC1Offset - 12); // data length
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
239 c1.putShort(2, (short) (c1.getShort(2) + 1)); // increment rectangle count
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
240 prevC1Offset = c1.position();
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
241
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
242 nextPhase(rect);
534
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
243 }
a3d0ba67e8cf try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 533
diff changeset
244
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
245 private void nextPhase(FramebufferUpdateRectangle rect) {
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
246 if (c1rect.x + c1rect.width < rect.x + rect.width) {
532
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
247 c1rect.x = c1rect.width; // next rectangle is phase 1
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
248 } else {
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
249 c1rect.x = rect.x;
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
250 c1rect.y += c1rect.height;
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
251 }
9292035b8d93 fix forloop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 531
diff changeset
252 width = 0;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
253 }
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
254
531
13d3c4341d14 remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 529
diff changeset
255 private void flushMuticast(TreeRFBProto rfb) {
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
256 c1.flip();
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
257 //System.out.println("multicastPut: " + c1rect + " length: " + (c1.remaining()-c1headerPos-header.limit()));
529
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
258 deflater.reset();
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
259
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
260 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
261 bufs.add(c1);
552
ff4c1972aa2e fix frame buffer test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 550
diff changeset
262 rfb.getContext().checkFrameBufferRectanble(c1);
529
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
263 if (rfb.isTreeManager() && rfb.connectionPresenter.isUseMulticast()) {
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
264 for (ByteBuffer buf : bufs)
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
265 rfb.getViewer().getRfbBroadcastListener().multicastUpdateRectangle(buf);
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
266 } else {
560
bdd659ce8e64 fix null renderer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 552
diff changeset
267 rfb.multicastqueue.put(bufs);
529
9de5137e1598 refactoring flushRectangle
anatofuz
parents: 528
diff changeset
268 }
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
269 }
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
270 }
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
271
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
272 @Override
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 public void decode(Reader reader, Renderer renderer,
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
274 FramebufferUpdateRectangle rect) throws TransportException {
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 int zippedLength = (int) reader.readUInt32();
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 if (0 == zippedLength) return;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 int length = rect.width * rect.height * renderer.getBytesPerPixel();
3
e7ce2b2ffed8 add and modify files
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
278 byte[] bytes = unzip(reader, zippedLength, length, rect.getEncodingType());
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
279 decode1(renderer, null, rect, bytes, zippedLength, null);
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
280 }
533
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
281
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
282
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
283 public void multicastDecode(Reader reader, Renderer renderer,
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
284 FramebufferUpdateRectangle rect, TreeRFBProto rfb) throws TransportException {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
285 ByteBuffer header = ByteBuffer.allocate(16);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
286 reader.read(header.array());
533
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
287 int zippedLength = (int) reader.readUInt32();
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
288 if (0 == zippedLength) return;
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
289 int length = rect.width * rect.height * renderer.getBytesPerPixel();
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
290 byte[] bytes = unzip(reader, zippedLength, length, rect.getEncodingType());
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
291 decode1(renderer, header, rect, bytes, zippedLength, rfb);
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
292 }
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
293
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
294 public void decode1(Renderer renderer, ByteBuffer header, FramebufferUpdateRectangle rect, byte[] bytes, int zippedLength, TreeRFBProto rfbProto) throws TransportException {
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 int offset = zippedLength;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 int maxX = rect.x + rect.width;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 int maxY = rect.y + rect.height;
528
2956c4a7bfbd define TileLoop class
anatofuz
parents: 527
diff changeset
298
533
4be31e107121 fix bloking
riono210
parents: 532
diff changeset
299 TileLoop tileloop = new TileLoop(zippedLength);
550
9c0cbe119155 fix make rectangle packet in client
e165729 <e165729@ie.u-ryukyu.ac.jp>
parents: 545
diff changeset
300 //System.out.println("decode1: "+rect.toString());
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
301 if (null == palette) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
302 palette = new int[128];
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
303 }
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
304 if (null == decodedBitmap) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
305 decodedBitmap = new int[MAX_TILE_SIZE * MAX_TILE_SIZE];
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
306 }
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
307
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
308 if (rfbProto.multicastBlocking) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
309 tileloop.zrleeBlocking(rfbProto, header, rect, bytes);
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
310 }
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
311 try {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
312 for (int tileY = rect.y; tileY < maxY; tileY += MAX_TILE_SIZE) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
313 int tileHeight = Math.min(maxY - tileY, MAX_TILE_SIZE);
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
314 tileloop.c1rect.height += tileHeight;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
316 for (int tileX = rect.x; tileX < maxX; tileX += MAX_TILE_SIZE) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
317 int tileWidth = Math.min(maxX - tileX, MAX_TILE_SIZE);
541
355954eac478 fix ZRLEDecoder
riono
parents: 539
diff changeset
318 tileloop.c1rect.width += tileWidth;
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
319 int subencoding = bytes[offset++] & 0x0ff;
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
320 if (subencoding != 0)
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
321 System.out.println("----------------" + subencoding);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
322 // 128 -plain RLE, 130-255 - Palette RLE
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
323 boolean isRle = (subencoding & 128) != 0;
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
324 // 2 to 16 for raw packed palette data, 130 to 255 for Palette RLE (subencoding - 128)
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
325 int paletteSize = subencoding & 127;
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
326 offset += readPalette(bytes, offset, renderer, paletteSize);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
327 if (1 == subencoding) { // A solid tile consisting of a single colour
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
328 renderer.fillRect(palette[0], tileX, tileY, tileWidth, tileHeight);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
329 } else if (isRle) {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
330 if (0 == paletteSize) { // subencoding == 128 (or paletteSize == 0) - Plain RLE
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
331 offset += decodePlainRle(bytes, offset, renderer, tileX, tileY, tileWidth, tileHeight);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
332 } else {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
333 offset += decodePaletteRle(bytes, offset, renderer, tileX, tileY, tileWidth, tileHeight);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
334 }
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 } else {
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
336 if (0 == paletteSize) { // subencoding == 0 (or paletteSize == 0) - raw CPIXEL data
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
337 offset += decodeRaw(bytes, offset, renderer, tileX, tileY, tileWidth, tileHeight);
63
84f1c39ba3bf temp commit
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
338 // System.out.println("offset:"+offset);
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
339 } else {
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
340 offset += decodePacked(bytes, offset, renderer, paletteSize, tileX, tileY, tileWidth, tileHeight);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
341 }
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 }
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
343 if (rfbProto != null && rfbProto.multicastBlocking)
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
344 tileloop.multicastPut(rfbProto, false, rect, bytes, offset, tileWidth, tileHeight);
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 }
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
347 if (rfbProto != null && rfbProto.multicastBlocking)
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
348 tileloop.multicastPut(rfbProto, true, rect, bytes, offset, 0, 0);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
349 } catch (Exception e) {
560
bdd659ce8e64 fix null renderer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 552
diff changeset
350 e.printStackTrace();
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
351 if (rfbProto != null && rfbProto.multicastBlocking)
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
352 tileloop.multicastPut(rfbProto, true, rect, bytes, offset, 0, 0);
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
353 throw e;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
539
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
357
cb7c23cca231 fix ZRLEDecoder
riono
parents: 538
diff changeset
358
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 private int decodePlainRle(byte[] bytes, int offset, Renderer renderer,
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 int tileX, int tileY, int tileWidth, int tileHeight) {
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
361 int bytesPerCPixel = renderer.getBytesPerCPixel();
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 int decodedOffset = 0;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 int decodedEnd = tileWidth * tileHeight;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 int index = offset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 while (decodedOffset < decodedEnd) {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 int color = renderer.getCompactPixelColor(bytes, index);
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 index += bytesPerCPixel;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 int rlength = 1;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 do {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 rlength += bytes[index] & 0x0ff;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 } while ((bytes[index++] & 0x0ff) == 255);
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 assert rlength <= decodedEnd - decodedOffset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 renderer.fillColorBitmapWithColor(decodedBitmap, decodedOffset, rlength, color);
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 decodedOffset += rlength;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 renderer.drawColoredBitmap(decodedBitmap, tileX, tileY, tileWidth, tileHeight);
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 return index - offset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 private int decodePaletteRle(byte[] bytes, int offset, Renderer renderer,
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
381 int tileX, int tileY, int tileWidth, int tileHeight) {
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 int decodedOffset = 0;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 int decodedEnd = tileWidth * tileHeight;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 int index = offset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 while (decodedOffset < decodedEnd) {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 int colorIndex = bytes[index++];
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 int color = palette[colorIndex & 127];
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 int rlength = 1;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 if ((colorIndex & 128) != 0) {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 do {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 rlength += bytes[index] & 0x0ff;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 } while (bytes[index++] == (byte) 255);
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 assert rlength <= decodedEnd - decodedOffset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 renderer.fillColorBitmapWithColor(decodedBitmap, decodedOffset, rlength, color);
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 decodedOffset += rlength;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 renderer.drawColoredBitmap(decodedBitmap, tileX, tileY, tileWidth, tileHeight);
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 return index - offset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 private int decodePacked(byte[] bytes, int offset, Renderer renderer,
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
403 int paletteSize, int tileX, int tileY, int tileWidth, int tileHeight) {
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 int bitsPerPalletedPixel = paletteSize > 16 ? 8 : paletteSize > 4 ? 4
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 : paletteSize > 2 ? 2 : 1;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 int packedOffset = offset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 int decodedOffset = 0;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 for (int i = 0; i < tileHeight; ++i) {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 int decodedRowEnd = decodedOffset + tileWidth;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 int byteProcessed = 0;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 int bitsRemain = 0;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 while (decodedOffset < decodedRowEnd) {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 if (bitsRemain == 0) {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 byteProcessed = bytes[packedOffset++];
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 bitsRemain = 8;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 bitsRemain -= bitsPerPalletedPixel;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 int index = byteProcessed >> bitsRemain & (1 << bitsPerPalletedPixel) - 1 & 127;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 int color = palette[index];
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
421 renderer.fillColorBitmapWithColor(decodedBitmap, decodedOffset, 1, color);
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 ++decodedOffset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 }
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
425 renderer.drawColoredBitmap(decodedBitmap, tileX, tileY, tileWidth, tileHeight);
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 return packedOffset - offset;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 private int decodeRaw(byte[] bytes, int offset, Renderer renderer,
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 int tileX, int tileY, int tileWidth, int tileHeight) throws TransportException {
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 return renderer.drawCompactBytes(bytes, offset, tileX, tileY, tileWidth, tileHeight);
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
434 private int readPalette(byte[] bytes, int offset, Renderer renderer, int paletteSize) {
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
435 final int bytesPerCPixel = renderer.getBytesPerCPixel();
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 for (int i=0; i<paletteSize; ++i) {
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
437 palette[i] = renderer.getCompactPixelColor(bytes, offset + i* bytesPerCPixel);
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 }
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
439 return paletteSize * bytesPerCPixel;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 }
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441
526
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
442
fcd833c2e148 Multicast Bloking in ZRLEDecoder
riono210
parents: 515
diff changeset
443
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 }