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
|
|
27 import com.glavsoft.drawing.Renderer;
|
|
28 import com.glavsoft.exceptions.TransportException;
|
|
29 import com.glavsoft.transport.Reader;
|
|
30
|
|
31 /**
|
|
32 * Decoder for RichCursor pseudo encoding
|
|
33 */
|
|
34 public class RichCursorDecoder extends Decoder {
|
|
35 private static RichCursorDecoder instance = new RichCursorDecoder();
|
|
36
|
|
37 private RichCursorDecoder() { /*empty*/ }
|
|
38
|
|
39 public static RichCursorDecoder getInstance() {
|
|
40 return instance;
|
|
41 }
|
|
42
|
|
43 @Override
|
|
44 public void decode(Reader reader, Renderer renderer,
|
|
45 FramebufferUpdateRectangle rect) throws TransportException {
|
|
46 int bytesPerPixel = renderer.getBytesPerPixel();
|
|
47 int length = rect.width * rect.height * bytesPerPixel;
|
|
48 if (0 == length)
|
|
49 return;
|
|
50 byte[] buffer = ByteBuffer.getInstance().getBuffer(length);
|
|
51 reader.readBytes(buffer, 0, length);
|
|
52
|
|
53 StringBuilder sb = new StringBuilder(" ");
|
|
54 for (int i=0; i<length; ++i) {
|
|
55 sb.append(Integer.toHexString(buffer[i]&0xff)).append(" ");
|
|
56 }
|
|
57 int scanLine = (int) Math.floor((rect.width + 7) / 8);
|
|
58 byte[] bitmask = new byte[scanLine * rect.height];
|
|
59 reader.readBytes(bitmask, 0, bitmask.length);
|
|
60
|
|
61 sb = new StringBuilder(" ");
|
|
62 for (int i=0; i<bitmask.length; ++i) {
|
|
63 sb.append(Integer.toHexString(bitmask[i]&0xff)).append(" ");
|
|
64 }
|
|
65 int[] cursorPixels = new int[rect.width * rect.height];
|
|
66 for (int y = 0; y < rect.height; ++y) {
|
|
67 for (int x = 0; x < rect.width; ++x) {
|
|
68 int offset = y * rect.width + x;
|
|
69 cursorPixels[offset] = isBitSet(bitmask[y * scanLine + x / 8], x % 8) ?
|
|
70 0xFF000000 | renderer.getPixelColor(buffer, offset * bytesPerPixel) :
|
|
71 0; // transparent
|
|
72 }
|
|
73 }
|
|
74 renderer.createCursor(cursorPixels, rect);
|
|
75 }
|
|
76
|
|
77 private boolean isBitSet(byte aByte, int index) {
|
|
78 return (aByte & 1 << 7 - index) > 0;
|
|
79 }
|
|
80
|
|
81 }
|