Mercurial > hg > Applications > TreeVNC
annotate src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java @ 534:a3d0ba67e8cf
try 512 tiles / 256 tiles flush
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 06 May 2019 16:59:25 +0900 |
parents | 4be31e107121 |
children | 17a2d0ea5c03 |
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 | 29 import com.glavsoft.rfb.encoding.EncodingType; |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 import com.glavsoft.transport.Reader; |
526 | 31 import jp.ac.u_ryukyu.treevnc.CheckDelay; |
498 | 32 import jp.ac.u_ryukyu.treevnc.TreeRFBProto; |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 |
526 | 34 import java.io.UnsupportedEncodingException; |
35 import java.nio.ByteBuffer; | |
528 | 36 import java.util.LinkedList; |
526 | 37 import java.util.zip.Deflater; |
38 | |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 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
|
40 private static final int MAX_TILE_SIZE = 64; |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
41 private int[] decodedBitmap; |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
42 private int[] palette; |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 |
528 | 44 class TileLoop { |
45 private int deflate_size = 65507; | |
46 private ByteBuffer c1; | |
532 | 47 private int width; // phase2 length |
528 | 48 private FramebufferUpdateRectangle c1rect; |
49 private int c1headerPos; | |
50 private int prevLineOffset; | |
51 private int prevC1Offset; | |
52 private int prevoffset; | |
53 private Deflater deflater; | |
529 | 54 private int rectPos; |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
55 private int ztileInLine; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
56 private int hwidth; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
57 private int hc1width; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
58 private int hoffset; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
59 private int hc1offset; |
528 | 60 |
61 /** | |
62 * Multicast framebufferUpdate to children. | |
63 * read FrameBuffferUpdate. If it is ZLE, make it ZLEE which is self contained compressed packet. | |
64 * put the packet to the multicastqueue. Then normal rendering engine read the same stream using is.reset(). | |
65 * | |
66 * Haeder | |
67 * messageID ( FrameBuffer Update | |
68 * 1 byte padding | |
69 * 2 byte numberofrectangle | |
70 * 2 - U16 - x-position | |
71 * 2 - U16 - y-position | |
72 * 2 - U16 - width | |
73 * 2 - U16 - height | |
74 * 4 - S32 - encoding-type | |
75 * 4 byte datalengths | |
76 * datalengths databyte | |
77 * | |
78 * @throws TransportException | |
79 * @throws UnsupportedEncodingException | |
80 */ | |
81 | |
533 | 82 public TileLoop(int offset) { |
83 prevoffset = prevLineOffset = prevC1Offset = offset; | |
84 } | |
528 | 85 |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
86 private void zrleeBlocking(TreeRFBProto rfb, ByteBuffer header, FramebufferUpdateRectangle rect) { |
528 | 87 // dump32(inputs); |
88 deflater = rfb.deflater; | |
532 | 89 newMulticastPacket(rfb, rect); |
90 c1.put(header.get(0)); | |
91 c1rect = new FramebufferUpdateRectangle(rect.x, rect.y, 0, 0); | |
92 return; | |
93 } | |
94 | |
95 private void newMulticastPacket(TreeRFBProto rfb, FramebufferUpdateRectangle rect) { | |
528 | 96 c1 = rfb.multicastqueue.allocate(deflate_size); |
97 if (rfb.addSerialNum) | |
98 c1.putLong(rfb.counter++); | |
99 if (rfb.checkDelay) | |
100 CheckDelay.checkDelay(c1, rect.x, rect.y, rect.width, rect.height, System.currentTimeMillis(), EncodingType.CHECK_DELAY); | |
101 c1headerPos = c1.position(); | |
532 | 102 c1.put((byte) 0); |
103 c1.put((byte) 0); | |
104 c1.putShort((short) 0); | |
105 c1.position(c1.position()+16); | |
106 c1.putInt(0); // should be data length | |
107 width = 0; | |
108 rectPos = 4; | |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
109 ztileInLine = 0; |
528 | 110 } |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
111 |
528 | 112 int spanGap = 128; |
113 /** | |
114 * | |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
115 * 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
|
116 * rectangle boundaries. |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
117 * |
532 | 118 * +----+ |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
119 * | | | phase 0 |
532 | 120 * +---------------+ |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
121 * | | | phase 1 |
532 | 122 * +----+----------+ |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
123 * | | | phase 2 |
532 | 124 * +----+ |
125 * | |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
126 * Broadcast packet have to less than 64kbytes |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
127 * A tile 8x8x3 192byte, a packet can contain 340 raw tiles, when these are |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
128 * compressed 500 to 2000 tiles can be stored. It is impossible to predict the |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
129 * compression rate. To check the compressed capacity, Deflate.needsInputs() can |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
130 * be used. If needsInputs() is false on SYNC_FLUSH, smaller input is necessary. |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
131 * |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
132 * We'll try 512 tiles before SYNC_FLUSH in a phase, if it fails try 256. |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
133 * If it will failed again, flush the previous line and try again. |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
134 * If 256 tiles are failed in new packet, discard it. |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
135 * |
528 | 136 * @param rfb |
137 * @param last | |
138 * @param rect | |
139 * @param bytes | |
140 * @param offset | |
141 * @param tileW | |
142 * @param tileH | |
143 */ | |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
144 |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
145 int MAX_ZTILE = 512; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
146 |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
147 public void multicastPut(TreeRFBProto rfb, boolean last, FramebufferUpdateRectangle rect, byte[] bytes, int offset, int tileW, int tileH) { |
528 | 148 int span = offset - prevoffset; |
149 deflater.setInput(bytes,prevoffset,span); | |
150 prevoffset = offset; | |
532 | 151 c1rect.width += tileW; width += tileW; |
152 if (c1rect.x > rect.x) { // phase 0 | |
153 if (c1rect.x+c1rect.width < rect.x+rect.width) { | |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
154 compressAndCheckFlush(rfb, rect, bytes, offset,false, last); |
532 | 155 } else { |
156 c1rect.width = rect.x+rect.width-c1rect.x ; | |
157 c1rect.height += tileH; | |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
158 compressAndCheckFlush(rfb,rect,bytes,offset,true, last); |
528 | 159 } |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
160 } else if (!last && c1.remaining() > spanGap) { // phase 1 |
532 | 161 if (width >= rect.width) { |
162 c1rect.width = rect.width; | |
163 width = 0; | |
164 c1rect.height += tileH; | |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
165 prevLineOffset = offset; |
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
166 prevC1Offset = c1.position(); |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
167 compressAndCheckFlush(rfb,rect,bytes,offset,true, last); |
533 | 168 } else { |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
169 compressAndCheckFlush(rfb,rect,bytes,offset,false, last); |
533 | 170 } |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
171 } else { // phase2 |
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
172 // rewind to the last line finish phase 1 |
532 | 173 int savew = width; |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
174 c1.position(prevC1Offset); |
532 | 175 flushRectangle(rect); |
176 if (savew>0) { | |
177 // recompress overrun and flush phase 2 | |
178 c1rect.width = savew; | |
179 c1rect.height = tileH; | |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
180 compressAndCheckFlush(rfb,rect,bytes,offset,true, last); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
181 } |
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 private void compressAndCheckFlush(TreeRFBProto rfb, FramebufferUpdateRectangle rect, byte[] bytes, int offset, boolean flush, boolean last) { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
186 if (!flush && ztileInLine++ < MAX_ZTILE) { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
187 if (ztileInLine == MAX_ZTILE/2) { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
188 hwidth = width; hc1width = c1rect.width; hoffset = offset; hc1offset = c1.position(); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
189 } |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
190 deflater.deflate(c1, Deflater.NO_FLUSH); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
191 } else { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
192 deflater.deflate(c1, Deflater.SYNC_FLUSH); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
193 if (!deflater.needsInput()) { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
194 // too large, try half line |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
195 width = hwidth; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
196 c1rect.width = hc1width; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
197 c1.position(hc1offset); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
198 deflater.setInput(bytes, prevLineOffset, hoffset - prevC1Offset); |
532 | 199 deflater.deflate(c1, Deflater.SYNC_FLUSH); |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
200 int from, len; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
201 if (!deflater.needsInput()) { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
202 // flush previous line and start new packet |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
203 c1.position(prevC1Offset); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
204 unputrectangle(); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
205 flushMuticast(rfb); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
206 newMulticastPacket(rfb, rect); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
207 nextRectangle(rect); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
208 // we already reached MIX_ZTILE do half of them, do compress right now |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
209 from = prevC1Offset; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
210 len = offset - prevLineOffset; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
211 deflater.setInput(bytes, from, len); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
212 deflater.deflate(c1, Deflater.SYNC_FLUSH); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
213 if (deflater.needsInput()) { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
214 flushRectangle(rect); // we are the flushed last line |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
215 return; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
216 } |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
217 // half size should always succeed |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
218 from = prevC1Offset; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
219 len = hoffset - prevLineOffset; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
220 deflater.setInput(bytes, from, len); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
221 deflater.deflate(c1, Deflater.SYNC_FLUSH); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
222 if (!deflater.needsInput()) { /* fatal error discard this line */ |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
223 if (!last) { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
224 newMulticastPacket(rfb, rect); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
225 nextRectangle(rect); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
226 } |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
227 return; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
228 } else |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
229 flushRectangle(rect); // normal case |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
230 // later half is remain continue |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
231 } else { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
232 flushMuticast(rfb); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
233 newMulticastPacket(rfb,rect); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
234 nextRectangle(rect); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
235 } |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
236 // do later half in new Packet |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
237 from = hoffset ; len = offset - hoffset; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
238 deflater.setInput(bytes, from, len); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
239 deflater.deflate(c1, Deflater.NO_FLUSH); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
240 hwidth = width; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
241 hoffset = offset; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
242 hc1offset = c1.position(); |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
243 ztileInLine = MAX_ZTILE/2; |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
244 } |
528 | 245 } |
246 } | |
247 | |
248 /** | |
249 * fix rectangle header | |
250 * create next rectangle header | |
251 * update position paramater | |
252 * send muticast pacate if nessesally | |
253 */ | |
532 | 254 private void flushRectangle(FramebufferUpdateRectangle rect) { |
529 | 255 c1.putShort(rectPos + 0, (short)c1rect.x); |
256 c1.putShort(rectPos + 2, (short)c1rect.y); | |
257 c1.putShort(rectPos + 4, (short)c1rect.width); | |
258 c1.putShort(rectPos + 6, (short)c1rect.height); | |
259 c1.putInt(rectPos + 8,EncodingType.ZRLEE.getId()); | |
532 | 260 c1.putInt(rectPos + 12, c1.position()-rectPos-12); // data length |
529 | 261 rectPos = c1.position(); |
532 | 262 c1.putShort(2,(short)(c1.getShort(2)+1)); // increment rectangle count |
263 nextRectangle(rect); | |
534
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
264 ztileInLine = 0; |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
265 } |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
266 |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
267 private void unputrectangle() { |
a3d0ba67e8cf
try 512 tiles / 256 tiles flush
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
533
diff
changeset
|
268 c1.putShort(2,(short)(c1.getShort(2)-1)); // last rectangle is canceled |
532 | 269 } |
270 | |
271 private void nextRectangle(FramebufferUpdateRectangle rect) { | |
272 if (c1rect.x+c1rect.width < rect.x+rect.width) { | |
273 c1rect.x = c1rect.width; // next rectangle is phase 1 | |
274 } else { | |
275 c1rect.x = rect.x; | |
276 c1rect.y += c1rect.height; | |
277 } | |
278 width = 0; | |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
279 c1rect.width = 0; |
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
280 c1rect.height = 0; |
528 | 281 } |
282 | |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
283 private void flushMuticast(TreeRFBProto rfb) { |
528 | 284 c1.flip(); |
285 //System.out.println("multicastPut: " + c1rect + " length: " + (c1.remaining()-c1headerPos-header.limit())); | |
286 try { | |
529 | 287 deflater.reset(); |
288 | |
289 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); | |
290 bufs.add(c1); | |
291 if (rfb.isTreeManager() && rfb.connectionPresenter.isUseMulticast()) { | |
292 for (ByteBuffer buf : bufs) | |
293 rfb.getViewer().getRfbBroadcastListener().multicastUpdateRectangle(buf); | |
294 } else { | |
295 rfb.multicastqueue.waitput(bufs); | |
296 } | |
528 | 297 } catch (InterruptedException e) { |
298 e.printStackTrace(); | |
299 } | |
300 } | |
301 } | |
526 | 302 |
303 @Override | |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
304 public void decode(Reader reader, Renderer renderer, |
275 | 305 FramebufferUpdateRectangle rect) throws TransportException { |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
306 int zippedLength = (int) reader.readUInt32(); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
307 if (0 == zippedLength) return; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
308 int length = rect.width * rect.height * renderer.getBytesPerPixel(); |
3 | 309 byte[] bytes = unzip(reader, zippedLength, length, rect.getEncodingType()); |
526 | 310 decode1(renderer, null, rect, bytes, zippedLength, null); |
182 | 311 } |
533 | 312 |
313 | |
314 public void multicastDecode(Reader reader, Renderer renderer, | |
315 FramebufferUpdateRectangle rect, TreeRFBProto rfb) throws TransportException { | |
316 ByteBuffer header = ByteBuffer.allocate(16); | |
317 reader.read(header.array()); | |
318 int zippedLength = (int) reader.readUInt32(); | |
319 if (0 == zippedLength) return; | |
320 int length = rect.width * rect.height * renderer.getBytesPerPixel(); | |
321 byte[] bytes = unzip(reader, zippedLength, length, rect.getEncodingType()); | |
322 decode1(renderer, header, rect, bytes, zippedLength, rfb); | |
323 } | |
324 | |
526 | 325 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
|
326 int offset = zippedLength; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
327 int maxX = rect.x + rect.width; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
328 int maxY = rect.y + rect.height; |
528 | 329 |
533 | 330 TileLoop tileloop = new TileLoop(zippedLength); |
501 | 331 //System.out.println("decode1: "+rect); |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
332 if (null == palette) { |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
333 palette = new int [128]; |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
334 } |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
335 if (null == decodedBitmap) { |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
336 decodedBitmap = new int[MAX_TILE_SIZE * MAX_TILE_SIZE]; |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
337 } |
526 | 338 |
339 if (rfbProto.multicastBlocking) { | |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
340 tileloop.zrleeBlocking(rfbProto, header, rect); |
526 | 341 } |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
342 for (int tileY = rect.y; tileY < maxY; tileY += MAX_TILE_SIZE) { |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
343 int tileHeight = Math.min(maxY - tileY, MAX_TILE_SIZE); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
344 |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
345 for (int tileX = rect.x; tileX < maxX; tileX += MAX_TILE_SIZE) { |
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
346 int tileWidth = Math.min(maxX - tileX, MAX_TILE_SIZE); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
347 int subencoding = bytes[offset++] & 0x0ff; |
63 | 348 if(subencoding!=0) |
349 System.out.println("----------------"+subencoding); | |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
350 // 128 -plain RLE, 130-255 - Palette RLE |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
351 boolean isRle = (subencoding & 128) != 0; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
352 // 2 to 16 for raw packed palette data, 130 to 255 for Palette RLE (subencoding - 128) |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
353 int paletteSize = subencoding & 127; |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
354 offset += readPalette(bytes, offset, renderer, paletteSize); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
355 if (1 == subencoding) { // A solid tile consisting of a single colour |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
356 renderer.fillRect(palette[0], tileX, tileY, tileWidth, tileHeight); |
500 | 357 } else if (isRle) { |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
358 if (0 == paletteSize) { // subencoding == 128 (or paletteSize == 0) - Plain RLE |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
359 offset += decodePlainRle(bytes, offset, renderer, tileX, tileY, tileWidth, tileHeight); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
360 } else { |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
361 offset += decodePaletteRle(bytes, offset, renderer, tileX, tileY, tileWidth, tileHeight); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
362 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
363 } else { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
364 if (0 == paletteSize) { // subencoding == 0 (or paletteSize == 0) - raw CPIXEL data |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
365 offset += decodeRaw(bytes, offset, renderer, tileX, tileY, tileWidth, tileHeight); |
63 | 366 // System.out.println("offset:"+offset); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
367 } else { |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
368 offset += decodePacked(bytes, offset, renderer, paletteSize, tileX, tileY, tileWidth, tileHeight); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
369 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
370 } |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
371 if (rfbProto != null && rfbProto.multicastBlocking) 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
|
372 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
373 } |
531
13d3c4341d14
remove .idea modules fix for loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
529
diff
changeset
|
374 if (rfbProto != null && rfbProto.multicastBlocking) tileloop.multicastPut(rfbProto, true, rect, bytes, offset, 0, 0); |
0
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 |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
377 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
|
378 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
|
379 int bytesPerCPixel = renderer.getBytesPerCPixel(); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
380 int decodedOffset = 0; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
381 int decodedEnd = tileWidth * tileHeight; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
382 int index = offset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
383 while (decodedOffset < decodedEnd) { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
384 int color = renderer.getCompactPixelColor(bytes, index); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
385 index += bytesPerCPixel; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
386 int rlength = 1; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
387 do { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
388 rlength += bytes[index] & 0x0ff; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
389 } while ((bytes[index++] & 0x0ff) == 255); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
390 assert rlength <= decodedEnd - decodedOffset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
391 renderer.fillColorBitmapWithColor(decodedBitmap, decodedOffset, rlength, color); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
392 decodedOffset += rlength; |
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 renderer.drawColoredBitmap(decodedBitmap, tileX, tileY, tileWidth, tileHeight); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
395 return index - offset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
396 } |
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 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
|
399 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
|
400 int decodedOffset = 0; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
401 int decodedEnd = tileWidth * tileHeight; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
402 int index = offset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403 while (decodedOffset < decodedEnd) { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
404 int colorIndex = bytes[index++]; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
405 int color = palette[colorIndex & 127]; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
406 int rlength = 1; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
407 if ((colorIndex & 128) != 0) { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
408 do { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
409 rlength += bytes[index] & 0x0ff; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
410 } while (bytes[index++] == (byte) 255); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
411 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
412 assert rlength <= decodedEnd - decodedOffset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
413 renderer.fillColorBitmapWithColor(decodedBitmap, decodedOffset, rlength, color); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
414 decodedOffset += rlength; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
415 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
416 renderer.drawColoredBitmap(decodedBitmap, tileX, tileY, tileWidth, tileHeight); |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
417 return index - offset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
418 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
419 |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
420 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
|
421 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
|
422 int bitsPerPalletedPixel = paletteSize > 16 ? 8 : paletteSize > 4 ? 4 |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
423 : paletteSize > 2 ? 2 : 1; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
424 int packedOffset = offset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
425 int decodedOffset = 0; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
426 for (int i = 0; i < tileHeight; ++i) { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
427 int decodedRowEnd = decodedOffset + tileWidth; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
428 int byteProcessed = 0; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
429 int bitsRemain = 0; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
430 |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
431 while (decodedOffset < decodedRowEnd) { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
432 if (bitsRemain == 0) { |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433 byteProcessed = bytes[packedOffset++]; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
434 bitsRemain = 8; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
435 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
436 bitsRemain -= bitsPerPalletedPixel; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
437 int index = byteProcessed >> bitsRemain & (1 << bitsPerPalletedPixel) - 1 & 127; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
438 int color = palette[index]; |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
439 renderer.fillColorBitmapWithColor(decodedBitmap, decodedOffset, 1, color); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
440 ++decodedOffset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
441 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
442 } |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
443 renderer.drawColoredBitmap(decodedBitmap, tileX, tileY, tileWidth, tileHeight); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
444 return packedOffset - offset; |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
445 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
446 |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
447 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
|
448 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
|
449 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
|
450 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
451 |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
452 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
|
453 final int bytesPerCPixel = renderer.getBytesPerCPixel(); |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
454 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
|
455 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
|
456 } |
57
17b702648079
version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
457 return paletteSize * bytesPerCPixel; |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
458 } |
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
459 |
526 | 460 |
461 | |
0
4689cc86d6cb
create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
462 } |