enikey | d336f40 | 2008-12-19 05:43:25 +0000 | [diff] [blame] | 1 | package com.tightvnc.decoder; |
| 2 | |
enikey | ccf6e7c | 2008-12-19 06:00:18 +0000 | [diff] [blame] | 3 | import com.tightvnc.vncviewer.RfbInputStream; |
| 4 | import java.awt.Graphics; |
| 5 | import java.awt.Color; |
| 6 | import java.io.ByteArrayInputStream; |
| 7 | import java.io.DataInputStream; |
| 8 | import java.io.IOException; |
enikey | d336f40 | 2008-12-19 05:43:25 +0000 | [diff] [blame] | 9 | |
enikey | ccf6e7c | 2008-12-19 06:00:18 +0000 | [diff] [blame] | 10 | // |
| 11 | // Class that used for decoding RRE encoded data. |
| 12 | // |
| 13 | |
| 14 | public 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 | // |
| 47 | // Save decoded data to RecordInterface |
| 48 | // |
| 49 | if (rec.canWrite()) { |
| 50 | rec.writeIntBE(nSubrects); |
| 51 | rec.write(bg_buf); |
| 52 | rec.write(buf); |
| 53 | } |
| 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 | } |
enikey | d336f40 | 2008-12-19 05:43:25 +0000 | [diff] [blame] | 74 | } |