blob: e2b5feb2f546a60e0b2b8454c8de609f66ab2397 [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
enikey6558a302008-12-24 05:14:30 +000016 final static int EncodingRRE = 2;
17
enikeyccf6e7c2008-12-19 06:00:18 +000018 public RREDecoder(Graphics g, RfbInputStream is) {
19 super(g, is);
20 }
21
22 public RREDecoder(Graphics g, RfbInputStream is, int frameBufferW,
23 int frameBufferH) {
24 super(g, is, frameBufferW, frameBufferH);
25 }
26
27 //
28 // Override handleRect method to decode RRE encoded data insted of
29 // raw pixel data.
30 //
31
32 public void handleRect(int x, int y, int w, int h) throws IOException {
33 int nSubrects = rfbis.readU32();
34 byte[] bg_buf = new byte[bytesPerPixel];
35 rfbis.readFully(bg_buf);
36 Color pixel;
37 if (bytesPerPixel == 1) {
38 pixel = getColor256()[bg_buf[0] & 0xFF];
39 } else {
40 pixel = new Color(bg_buf[2] & 0xFF, bg_buf[1] & 0xFF, bg_buf[0] & 0xFF);
41 }
42 graphics.setColor(pixel);
43 graphics.fillRect(x, y, w, h);
44 byte[] buf = new byte[nSubrects * (bytesPerPixel + 8)];
45 rfbis.readFully(buf);
46 DataInputStream ds = new DataInputStream(new ByteArrayInputStream(buf));
47
48 //
enikey8beb7782008-12-24 04:37:56 +000049 // Save decoded data to data output stream
enikeyccf6e7c2008-12-19 06:00:18 +000050 //
enikey8beb7782008-12-24 04:37:56 +000051 if (dos != null) {
52 dos.writeInt(nSubrects);
53 dos.write(bg_buf);
54 dos.write(buf);
enikeyccf6e7c2008-12-19 06:00:18 +000055 }
56
57 int sx, sy, sw, sh;
58 for (int j = 0; j < nSubrects; j++) {
59 if (bytesPerPixel == 1) {
60 pixel = getColor256()[ds.readUnsignedByte()];
61 } else {
62 ds.skip(4);
63 pixel = new Color(buf[j*12+2] & 0xFF,
64 buf[j*12+1] & 0xFF,
65 buf[j*12] & 0xFF);
66 }
67 sx = x + ds.readUnsignedShort();
68 sy = y + ds.readUnsignedShort();
69 sw = ds.readUnsignedShort();
70 sh = ds.readUnsignedShort();
71
72 graphics.setColor(pixel);
73 graphics.fillRect(sx, sy, sw, sh);
74 }
75 }
enikeyd336f402008-12-19 05:43:25 +000076}