forked from deluan/vnc2video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding_xcursor.go
92 lines (81 loc) · 2.38 KB
/
encoding_xcursor.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package vnc2video
import (
"encoding/binary"
"math"
)
type XCursorPseudoEncoding struct {
PrimaryR uint8
PrimaryG uint8
PrimaryB uint8
SecondaryR uint8
SecondaryG uint8
SecondaryB uint8
Bitmap []byte
Bitmask []byte
}
func (*XCursorPseudoEncoding) Supported(Conn) bool {
return true
}
func (*XCursorPseudoEncoding) Reset() error {
return nil
}
func (*XCursorPseudoEncoding) Type() EncodingType { return EncXCursorPseudo }
// Read implements the Encoding interface.
func (enc *XCursorPseudoEncoding) Read(c Conn, rect *Rectangle) error {
if err := binary.Read(c, binary.BigEndian, &enc.PrimaryR); err != nil {
return err
}
if err := binary.Read(c, binary.BigEndian, &enc.PrimaryG); err != nil {
return err
}
if err := binary.Read(c, binary.BigEndian, &enc.PrimaryB); err != nil {
return err
}
if err := binary.Read(c, binary.BigEndian, &enc.SecondaryR); err != nil {
return err
}
if err := binary.Read(c, binary.BigEndian, &enc.SecondaryG); err != nil {
return err
}
if err := binary.Read(c, binary.BigEndian, &enc.SecondaryB); err != nil {
return err
}
bitmapsize := int(math.Floor((float64(rect.Width)+7)/8) * float64(rect.Height))
bitmasksize := int(math.Floor((float64(rect.Width)+7)/8) * float64(rect.Height))
enc.Bitmap = make([]byte, bitmapsize)
enc.Bitmask = make([]byte, bitmasksize)
if err := binary.Read(c, binary.BigEndian, &enc.Bitmap); err != nil {
return err
}
if err := binary.Read(c, binary.BigEndian, &enc.Bitmask); err != nil {
return err
}
return nil
}
func (enc *XCursorPseudoEncoding) Write(c Conn, rect *Rectangle) error {
if err := binary.Write(c, binary.BigEndian, enc.PrimaryR); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.PrimaryG); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.PrimaryB); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.SecondaryR); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.SecondaryG); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.SecondaryB); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.Bitmap); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.Bitmask); err != nil {
return err
}
return nil
}