2018-07-27 16:55:06 +03:00
|
|
|
package rfb
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
import (
|
|
|
|
"bytes"
|
2017-07-04 01:36:10 +03:00
|
|
|
"image"
|
2017-06-18 22:38:59 +03:00
|
|
|
"sync"
|
2017-06-13 01:52:07 +03:00
|
|
|
)
|
|
|
|
|
2017-06-12 14:11:23 +03:00
|
|
|
// EncodingType represents a known VNC encoding type.
|
|
|
|
type EncodingType int32
|
|
|
|
|
|
|
|
//go:generate stringer -type=EncodingType
|
|
|
|
|
|
|
|
const (
|
2017-07-04 01:36:10 +03:00
|
|
|
// EncRaw raw encoding
|
|
|
|
EncRaw EncodingType = 0
|
|
|
|
// EncCopyRect copyrect encoding
|
|
|
|
EncCopyRect EncodingType = 1
|
|
|
|
|
2017-06-18 19:42:41 +03:00
|
|
|
EncRRE EncodingType = 2
|
|
|
|
EncCoRRE EncodingType = 4
|
|
|
|
EncHextile EncodingType = 5
|
|
|
|
EncZlib EncodingType = 6
|
|
|
|
EncTight EncodingType = 7
|
|
|
|
EncZlibHex EncodingType = 8
|
|
|
|
EncUltra1 EncodingType = 9
|
|
|
|
EncUltra2 EncodingType = 10
|
|
|
|
EncJPEG EncodingType = 21
|
|
|
|
EncJRLE EncodingType = 22
|
|
|
|
EncTRLE EncodingType = 15
|
|
|
|
EncZRLE EncodingType = 16
|
2017-06-30 00:24:39 +03:00
|
|
|
EncAtenAST2100 EncodingType = 0x57
|
|
|
|
EncAtenASTJPEG EncodingType = 0x58
|
|
|
|
EncAtenHermon EncodingType = 0x59
|
|
|
|
EncAtenYarkon EncodingType = 0x60
|
|
|
|
EncAtenPilot3 EncodingType = 0x61
|
2017-06-18 19:42:41 +03:00
|
|
|
EncJPEGQualityLevelPseudo10 EncodingType = -23
|
|
|
|
EncJPEGQualityLevelPseudo9 EncodingType = -24
|
|
|
|
EncJPEGQualityLevelPseudo8 EncodingType = -25
|
|
|
|
EncJPEGQualityLevelPseudo7 EncodingType = -26
|
|
|
|
EncJPEGQualityLevelPseudo6 EncodingType = -27
|
|
|
|
EncJPEGQualityLevelPseudo5 EncodingType = -28
|
|
|
|
EncJPEGQualityLevelPseudo4 EncodingType = -29
|
|
|
|
EncJPEGQualityLevelPseudo3 EncodingType = -30
|
|
|
|
EncJPEGQualityLevelPseudo2 EncodingType = -31
|
|
|
|
EncJPEGQualityLevelPseudo1 EncodingType = -32
|
2017-06-30 00:24:39 +03:00
|
|
|
EncCursorPseudo EncodingType = -239
|
2017-06-26 18:21:15 +03:00
|
|
|
EncXCursorPseudo EncodingType = -240
|
2017-06-18 19:42:41 +03:00
|
|
|
EncDesktopSizePseudo EncodingType = -223
|
|
|
|
EncLastRectPseudo EncodingType = -224
|
|
|
|
EncCompressionLevel10 EncodingType = -247
|
|
|
|
EncCompressionLevel9 EncodingType = -248
|
|
|
|
EncCompressionLevel8 EncodingType = -249
|
|
|
|
EncCompressionLevel7 EncodingType = -250
|
|
|
|
EncCompressionLevel6 EncodingType = -251
|
|
|
|
EncCompressionLevel5 EncodingType = -252
|
|
|
|
EncCompressionLevel4 EncodingType = -253
|
|
|
|
EncCompressionLevel3 EncodingType = -254
|
|
|
|
EncCompressionLevel2 EncodingType = -255
|
|
|
|
EncCompressionLevel1 EncodingType = -256
|
|
|
|
EncQEMUPointerMotionChangePseudo EncodingType = -257
|
|
|
|
EncQEMUExtendedKeyEventPseudo EncodingType = -258
|
|
|
|
EncTightPng EncodingType = -260
|
2020-01-23 01:52:23 +03:00
|
|
|
EncLedStatePseudo EncodingType = -261
|
2017-06-26 18:21:15 +03:00
|
|
|
EncDesktopNamePseudo EncodingType = -307
|
2017-06-18 19:42:41 +03:00
|
|
|
EncExtendedDesktopSizePseudo EncodingType = -308
|
|
|
|
EncXvpPseudo EncodingType = -309
|
2017-06-30 00:24:39 +03:00
|
|
|
EncClientRedirect EncodingType = -311
|
2017-06-18 19:42:41 +03:00
|
|
|
EncFencePseudo EncodingType = -312
|
|
|
|
EncContinuousUpdatesPseudo EncodingType = -313
|
|
|
|
)
|
|
|
|
|
2017-06-18 22:38:59 +03:00
|
|
|
var bPool = sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
// The Pool's New function should generally only return pointer
|
|
|
|
// types, since a pointer can be put into the return interface
|
|
|
|
// value without an allocation:
|
|
|
|
return new(bytes.Buffer)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-07-04 01:36:10 +03:00
|
|
|
// Encoding represents interface for vnc encoding
|
2017-06-12 14:11:23 +03:00
|
|
|
type Encoding interface {
|
|
|
|
Type() EncodingType
|
|
|
|
Read(Conn, *Rectangle) error
|
|
|
|
Write(Conn, *Rectangle) error
|
2017-07-14 02:01:24 +03:00
|
|
|
Supported(Conn) bool
|
2017-06-12 14:11:23 +03:00
|
|
|
}
|
|
|
|
|
2017-06-18 19:42:41 +03:00
|
|
|
func setBit(n uint8, pos uint8) uint8 {
|
|
|
|
n |= (1 << pos)
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func clrBit(n uint8, pos uint8) uint8 {
|
|
|
|
n = n &^ (1 << pos)
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func hasBit(n uint8, pos uint8) bool {
|
|
|
|
v := n & (1 << pos)
|
|
|
|
return (v > 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBit(n uint8, pos uint8) uint8 {
|
|
|
|
n = n & (1 << pos)
|
|
|
|
return n
|
|
|
|
}
|
2017-07-04 01:36:10 +03:00
|
|
|
|
|
|
|
func newRGBAImage(rgba []byte, rect *Rectangle) image.Image {
|
|
|
|
img := &image.RGBA{Stride: 4 * int(rect.Width)}
|
|
|
|
img.Pix = rgba
|
|
|
|
img.Rect.Max.X = int(rect.Width)
|
|
|
|
img.Rect.Max.Y = int(rect.Height)
|
|
|
|
return img
|
|
|
|
}
|