summaryrefslogtreecommitdiffstats
path: root/java/src/com/tightvnc/decoder/CopyRectDecoder.java
blob: 07a14bdb05a890a72c2d8261aa6ebc1a1db934e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.tightvnc.decoder;

import com.tightvnc.vncviewer.RfbInputStream;
import java.awt.Graphics;
import java.io.IOException;

//
// Class that used for decoding CopyRect encoded data.
//

public class CopyRectDecoder extends RawDecoder {

  final static int EncodingCopyRect = 1;

  public CopyRectDecoder(Graphics g, RfbInputStream is) {
    super(g, is);
  }

  public CopyRectDecoder(Graphics g, RfbInputStream is, int frameBufferW,
                         int frameBufferH) {
    super(g, is, frameBufferW, frameBufferH);
  }

  //
  // Override handleRect method handle CopyRect
  //

  public void handleRect(int x, int y, int w, int h) throws IOException {

    //
    // Write encoding ID to record output stream
    //

    if (dos != null) {
      dos.writeInt(CopyRectDecoder.EncodingCopyRect);
    }

    int copyRectSrcX = rfbis.readU16();
    int copyRectSrcY = rfbis.readU16();

    // If the session is being recorded:
    if (dos != null) {
      dos.writeShort(copyRectSrcX);
      dos.writeShort(copyRectSrcY);
    }

    graphics.copyArea(copyRectSrcX, copyRectSrcY, w, h,
                      x - copyRectSrcX, y - copyRectSrcY);
  }
}