forked from saily/vnc2video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding_copyrect.go
62 lines (54 loc) · 1.51 KB
/
encoding_copyrect.go
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
51
52
53
54
55
56
57
58
59
60
61
62
package vnc2video
import (
"encoding/binary"
"image"
"image/draw"
"vnc2video/logger"
)
type CopyRectEncoding struct {
SX, SY uint16
Image draw.Image
}
func (*CopyRectEncoding) Supported(Conn) bool {
return true
}
func (*CopyRectEncoding) Reset() error {
return nil
}
func (*CopyRectEncoding) Type() EncodingType { return EncCopyRect }
func (enc *CopyRectEncoding) SetTargetImage(img draw.Image) {
//logger.Tracef("!!!!!!!!!!!!!setting image: %v", img.Bounds())
enc.Image = img
}
func (enc *CopyRectEncoding) Read(c Conn, rect *Rectangle) error {
logger.Tracef("Reading: CopyRect %v", rect)
if err := binary.Read(c, binary.BigEndian, &enc.SX); err != nil {
return err
}
if err := binary.Read(c, binary.BigEndian, &enc.SY); err != nil {
return err
}
cpyIm := image.NewRGBA(image.Rectangle{Min: image.Point{0, 0}, Max: image.Point{int(rect.Width), int(rect.Height)}})
for x := 0; x < int(rect.Width); x++ {
for y := 0; y < int(rect.Height); y++ {
col := enc.Image.At(x+int(enc.SX), y+int(enc.SY))
cpyIm.Set(x, y, col)
}
}
for x := 0; x < int(rect.Width); x++ {
for y := 0; y < int(rect.Height); y++ {
col := cpyIm.At(x, y)
enc.Image.Set(int(rect.X)+x, int(rect.Y)+y, col)
}
}
return nil
}
func (enc *CopyRectEncoding) Write(c Conn, rect *Rectangle) error {
if err := binary.Write(c, binary.BigEndian, enc.SX); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.SY); err != nil {
return err
}
return nil
}