comparison src/main/java/com/glavsoft/rfb/encoding/decoder/HextileDecoder.java @ 0:4689cc86d6cb

create TreeViewer2 Repository
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Tue, 03 Jul 2012 13:20:49 +0900
parents
children 17b702648079
comparison
equal deleted inserted replaced
-1:000000000000 0:4689cc86d6cb
1 // Copyright (C) 2010, 2011 GlavSoft LLC.
2 // All rights reserved.
3 //
4 //-------------------------------------------------------------------------
5 // This file is part of the TightVNC software. Please visit our Web site:
6 //
7 // http://www.tightvnc.com/
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License along
20 // with this program; if not, write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 //-------------------------------------------------------------------------
23 //
24
25 package com.glavsoft.rfb.encoding.decoder;
26
27 import com.glavsoft.drawing.Renderer;
28 import com.glavsoft.exceptions.TransportException;
29 import com.glavsoft.transport.Reader;
30
31
32 public class HextileDecoder extends Decoder {
33 private static final int DEFAULT_TILE_SIZE = 16;
34 private static final int RAW_MASK = 1;
35 private static final int BACKGROUND_SPECIFIED_MASK = 2;
36 private static final int FOREGROUND_SPECIFIED_MASK = 4;
37 private static final int ANY_SUBRECTS_MASK = 8;
38 private static final int SUBRECTS_COLOURED_MASK = 16;
39 private static final int FG_COLOR_INDEX = 0;
40 private static final int BG_COLOR_INDEX = 1;
41
42 @Override
43 public void decode(Reader reader, Renderer renderer,
44 FramebufferUpdateRectangle rect) throws TransportException {
45 if (rect.width == 0 || rect.height == 0) return;
46 int[] colors = new int[] {-1, -1};
47 int maxX = rect.x + rect.width;
48 int maxY = rect.y + rect.height;
49 for (int tileY = rect.y; tileY < maxY;
50 tileY += DEFAULT_TILE_SIZE) {
51 int tileHeight = Math.min(maxY - tileY, DEFAULT_TILE_SIZE);
52 for (int tileX = rect.x; tileX < maxX;
53 tileX += DEFAULT_TILE_SIZE) {
54 int tileWidth = Math.min(maxX - tileX, DEFAULT_TILE_SIZE);
55 decodeHextileSubrectangle(reader, renderer, colors, tileX,
56 tileY, tileWidth, tileHeight);
57 }
58 }
59
60 }
61
62 private void decodeHextileSubrectangle(Reader reader,
63 Renderer renderer, int[] colors,
64 int tileX, int tileY, int tileWidth, int tileHeight)
65 throws TransportException {
66
67 int subencoding = reader.readUInt8();
68
69 if ((subencoding & RAW_MASK) != 0) {
70 RawDecoder.getInstance().decode(reader, renderer,
71 tileX, tileY, tileWidth, tileHeight);
72 return;
73 }
74
75 if ((subencoding & BACKGROUND_SPECIFIED_MASK) != 0) {
76 colors[BG_COLOR_INDEX] = renderer.readPixelColor(reader);
77 }
78 assert colors[BG_COLOR_INDEX] != -1;
79 renderer.fillRect(colors[BG_COLOR_INDEX],
80 tileX, tileY, tileWidth, tileHeight);
81
82 if ((subencoding & FOREGROUND_SPECIFIED_MASK) != 0) {
83 colors[FG_COLOR_INDEX] = renderer.readPixelColor(reader);
84 }
85
86 if ((subencoding & ANY_SUBRECTS_MASK) == 0)
87 return;
88
89 int numberOfSubrectangles = reader.readUInt8();
90 boolean colorSpecified =
91 (subencoding & SUBRECTS_COLOURED_MASK) != 0;
92 for (int i = 0; i < numberOfSubrectangles; ++i) {
93 if (colorSpecified) {
94 colors[FG_COLOR_INDEX] = renderer.readPixelColor(reader);
95 }
96 byte dimensions = reader.readByte(); // bits 7-4 for x, bits 3-0 for y
97 int subtileX = dimensions >> 4 & 0x0f;
98 int subtileY = dimensions & 0x0f;
99 dimensions = reader.readByte(); // bits 7-4 for w, bits 3-0 for h
100 int subtileWidth = 1 + (dimensions >> 4 & 0x0f);
101 int subtileHeight = 1 + (dimensions & 0x0f);
102 assert colors[FG_COLOR_INDEX] != -1;
103 renderer.fillRect(colors[FG_COLOR_INDEX],
104 tileX + subtileX, tileY + subtileY,
105 subtileWidth, subtileHeight);
106 }
107 }
108
109
110 }