0
|
1 // Copyright (C) 2010, 2011, 2012, 2013 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
|
10
|
27 import alice.datasegment.DataSegment;
|
18
|
28 import alice.datasegment.ReceiveData;
|
10
|
29
|
0
|
30 import com.glavsoft.drawing.Renderer;
|
|
31 import com.glavsoft.exceptions.TransportException;
|
|
32 import com.glavsoft.transport.Reader;
|
|
33
|
|
34 /**
|
|
35 * Decoder for RichCursor pseudo encoding
|
|
36 */
|
|
37 public class RichCursorDecoder extends Decoder {
|
|
38 private static RichCursorDecoder instance = new RichCursorDecoder();
|
|
39
|
|
40 private RichCursorDecoder() { /*empty*/ }
|
|
41
|
|
42 public static RichCursorDecoder getInstance() {
|
|
43 return instance;
|
|
44 }
|
|
45
|
|
46 @Override
|
|
47 public void decode(Reader reader, Renderer renderer,
|
|
48 FramebufferUpdateRectangle rect) throws TransportException {
|
|
49 int bytesPerPixel = renderer.getBytesPerPixel();
|
|
50 int length = rect.width * rect.height * bytesPerPixel;
|
|
51 if (0 == length)
|
|
52 return;
|
|
53 byte[] buffer = ByteBuffer.getInstance().getBuffer(length);
|
10
|
54 reader.readBytes(buffer, 0, length);
|
|
55
|
0
|
56 StringBuilder sb = new StringBuilder(" ");
|
|
57 for (int i=0; i<length; ++i) {
|
|
58 sb.append(Integer.toHexString(buffer[i]&0xff)).append(" ");
|
|
59 }
|
|
60 int scanLine = (int) Math.floor((rect.width + 7) / 8);
|
|
61 byte[] bitmask = new byte[scanLine * rect.height];
|
|
62 reader.readBytes(bitmask, 0, bitmask.length);
|
|
63
|
10
|
64 AliceVNCMessage message = new AliceVNCMessage();
|
|
65 message.setRectangle(rect);
|
13
|
66 message.buf = buffer.clone();
|
|
67 message.bitmask = bitmask.clone();
|
18
|
68 ReceiveData rData = new ReceiveData(message, false, false);
|
|
69 DataSegment.getLocal().put("aliceVNCMessage", rData, null);
|
10
|
70
|
0
|
71 sb = new StringBuilder(" ");
|
|
72 for (int i=0; i<bitmask.length; ++i) {
|
|
73 sb.append(Integer.toHexString(bitmask[i]&0xff)).append(" ");
|
|
74 }
|
|
75 int[] cursorPixels = new int[rect.width * rect.height];
|
|
76 for (int y = 0; y < rect.height; ++y) {
|
|
77 for (int x = 0; x < rect.width; ++x) {
|
|
78 int offset = y * rect.width + x;
|
|
79 cursorPixels[offset] = isBitSet(bitmask[y * scanLine + x / 8], x % 8) ?
|
|
80 0xFF000000 | renderer.getPixelColor(buffer, offset * bytesPerPixel) :
|
|
81 0; // transparent
|
|
82 }
|
|
83 }
|
|
84 renderer.createCursor(cursorPixels, rect);
|
|
85 }
|
|
86
|
|
87 private boolean isBitSet(byte aByte, int index) {
|
|
88 return (aByte & 1 << 7 - index) > 0;
|
|
89 }
|
|
90
|
10
|
91 public void decode(Renderer renderer, AliceVNCMessage message)
|
|
92 throws TransportException {
|
|
93 FramebufferUpdateRectangle rect = message.getFramebufferUpdateRectangle();
|
|
94 int bytesPerPixel = renderer.getBytesPerPixel();
|
|
95 int length = rect.width * rect.height * bytesPerPixel;
|
|
96 if (0 == length)
|
|
97 return;
|
|
98 byte[] buffer = message.buf;
|
|
99 byte[] bitmask = message.bitmask;
|
|
100
|
|
101 StringBuilder sb = new StringBuilder(" ");
|
|
102 int scanLine = (int) Math.floor((rect.width + 7) / 8);
|
|
103
|
|
104 for (int i=0; i<bitmask.length; ++i) {
|
|
105 sb.append(Integer.toHexString(bitmask[i]&0xff)).append(" ");
|
|
106 }
|
|
107 int[] cursorPixels = new int[rect.width * rect.height];
|
|
108 for (int y = 0; y < rect.height; ++y) {
|
|
109 for (int x = 0; x < rect.width; ++x) {
|
|
110 int offset = y * rect.width + x;
|
|
111 cursorPixels[offset] = isBitSet(bitmask[y * scanLine + x / 8], x % 8) ?
|
|
112 0xFF000000 | renderer.getPixelColor(buffer, offset * bytesPerPixel) :
|
|
113 0; // transparent
|
|
114 }
|
|
115 }
|
|
116 renderer.createCursor(cursorPixels, rect);
|
|
117 }
|
0
|
118 }
|