blob: 72a5fdfbc2f336d40ca58ff60af9c88d62cf60cd [file] [log] [blame]
enikeyd336f402008-12-19 05:43:25 +00001package com.tightvnc.decoder;
2
enikeyccf6e7c2008-12-19 06:00:18 +00003import com.tightvnc.vncviewer.RfbInputStream;
4import java.awt.Graphics;
5import java.awt.Color;
6import java.io.ByteArrayInputStream;
7import java.io.DataInputStream;
8import java.io.IOException;
enikeyd336f402008-12-19 05:43:25 +00009
enikeyccf6e7c2008-12-19 06:00:18 +000010//
11// Class that used for decoding RRE encoded data.
12//
13
14public class RREDecoder extends RawDecoder {
15
16 public RREDecoder(Graphics g, RfbInputStream is) {
17 super(g, is);
18 }
19
20 public RREDecoder(Graphics g, RfbInputStream is, int frameBufferW,
21 int frameBufferH) {
22 super(g, is, frameBufferW, frameBufferH);
23 }
24
25 //
26 // Override handleRect method to decode RRE encoded data insted of
27 // raw pixel data.
28 //
29
30 public void handleRect(int x, int y, int w, int h) throws IOException {
31 int nSubrects = rfbis.readU32();
32 byte[] bg_buf = new byte[bytesPerPixel];
33 rfbis.readFully(bg_buf);
34 Color pixel;
35 if (bytesPerPixel == 1) {
36 pixel = getColor256()[bg_buf[0] & 0xFF];
37 } else {
38 pixel = new Color(bg_buf[2] & 0xFF, bg_buf[1] & 0xFF, bg_buf[0] & 0xFF);
39 }
40 graphics.setColor(pixel);
41 graphics.fillRect(x, y, w, h);
42 byte[] buf = new byte[nSubrects * (bytesPerPixel + 8)];
43 rfbis.readFully(buf);
44 DataInputStream ds = new DataInputStream(new ByteArrayInputStream(buf));
45
46 //
enikey8beb7782008-12-24 04:37:56 +000047 // Save decoded data to data output stream
enikeyccf6e7c2008-12-19 06:00:18 +000048 //
enikey8beb7782008-12-24 04:37:56 +000049 if (dos != null) {
50 dos.writeInt(nSubrects);
51 dos.write(bg_buf);
52 dos.write(buf);
enikeyccf6e7c2008-12-19 06:00:18 +000053 }
54
55 int sx, sy, sw, sh;
56 for (int j = 0; j < nSubrects; j++) {
57 if (bytesPerPixel == 1) {
58 pixel = getColor256()[ds.readUnsignedByte()];
59 } else {
60 ds.skip(4);
61 pixel = new Color(buf[j*12+2] & 0xFF,
62 buf[j*12+1] & 0xFF,
63 buf[j*12] & 0xFF);
64 }
65 sx = x + ds.readUnsignedShort();
66 sy = y + ds.readUnsignedShort();
67 sw = ds.readUnsignedShort();
68 sh = ds.readUnsignedShort();
69
70 graphics.setColor(pixel);
71 graphics.fillRect(sx, sy, sw, sh);
72 }
73 }
enikeyd336f402008-12-19 05:43:25 +000074}