]> source.dussan.org Git - tigervnc.git/commitdiff
[Developement] Added RREDecoder body (overrided handleRect method and constructors).
authorenikey <enikey@3789f03b-4d11-0410-bbf8-ca57d06f2519>
Fri, 19 Dec 2008 06:00:18 +0000 (06:00 +0000)
committerenikey <enikey@3789f03b-4d11-0410-bbf8-ca57d06f2519>
Fri, 19 Dec 2008 06:00:18 +0000 (06:00 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3419 3789f03b-4d11-0410-bbf8-ca57d06f2519

java/src/com/tightvnc/decoder/RREDecoder.java
java/src/com/tightvnc/decoder/RawDecoder.java

index 82ddb2ece6184c95d86ddda40e814a8c0b4d1b10..ce70606d063ea6056f39d7d8d8eead280d958ae2 100644 (file)
@@ -1,5 +1,74 @@
 package com.tightvnc.decoder;
 
-public class RREDecoder {
+import com.tightvnc.vncviewer.RfbInputStream;
+import java.awt.Graphics;
+import java.awt.Color;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
 
+//
+// Class that used for decoding RRE encoded data.
+//
+
+public class RREDecoder extends RawDecoder {
+
+  public RREDecoder(Graphics g, RfbInputStream is) {
+    super(g, is);
+  }
+
+  public RREDecoder(Graphics g, RfbInputStream is, int frameBufferW,
+                    int frameBufferH) {
+    super(g, is, frameBufferW, frameBufferH);
+  }
+
+  //
+  // Override handleRect method to decode RRE encoded data insted of
+  // raw pixel data.
+  //
+
+  public void handleRect(int x, int y, int w, int h) throws IOException {
+    int nSubrects = rfbis.readU32();
+    byte[] bg_buf = new byte[bytesPerPixel];
+    rfbis.readFully(bg_buf);
+    Color pixel;
+    if (bytesPerPixel == 1) {
+      pixel = getColor256()[bg_buf[0] & 0xFF];
+    } else {
+      pixel = new Color(bg_buf[2] & 0xFF, bg_buf[1] & 0xFF, bg_buf[0] & 0xFF);
+    }
+    graphics.setColor(pixel);
+    graphics.fillRect(x, y, w, h);
+    byte[] buf = new byte[nSubrects * (bytesPerPixel + 8)];
+    rfbis.readFully(buf);
+    DataInputStream ds = new DataInputStream(new ByteArrayInputStream(buf));
+
+    //
+    // Save decoded data to RecordInterface
+    //
+    if (rec.canWrite()) {
+      rec.writeIntBE(nSubrects);
+      rec.write(bg_buf);
+      rec.write(buf);
+    }
+
+    int sx, sy, sw, sh;
+    for (int j = 0; j < nSubrects; j++) {
+      if (bytesPerPixel == 1) {
+        pixel = getColor256()[ds.readUnsignedByte()];
+      } else {
+        ds.skip(4);
+        pixel = new Color(buf[j*12+2] & 0xFF,
+                          buf[j*12+1] & 0xFF,
+                          buf[j*12]   & 0xFF);
+      }
+      sx = x + ds.readUnsignedShort();
+      sy = y + ds.readUnsignedShort();
+      sw = ds.readUnsignedShort();
+      sh = ds.readUnsignedShort();
+
+      graphics.setColor(pixel);
+      graphics.fillRect(sx, sy, sw, sh);
+    }
+  }
 }
index ad0cfac7cd2f3fd0db5ae3a2dd8882ea18490b25..f2442107b6de419c46a91e952a6548c534d7976e 100644 (file)
@@ -15,6 +15,7 @@ import java.awt.Toolkit;
 // This is base decoder class.
 // Other classes will be childs of RawDecoder.
 //
+
 public class RawDecoder {
 
   public RawDecoder(Graphics g, RfbInputStream is) {