From 5cd902341d5e08ba9833a3b79426261f84fb7231 Mon Sep 17 00:00:00 2001 From: betzalel Date: Thu, 18 Jan 2018 09:22:11 +0200 Subject: [PATCH] initial cursor support (just getting the image and location), not drawing correctly yet --- encoding.go | 3 ++- encoding_cursor.go | 5 ++++- encoding_hextile.go | 2 +- encoding_pointer_pos.go | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 encoding_pointer_pos.go diff --git a/encoding.go b/encoding.go index 0af7546..5211ef3 100644 --- a/encoding.go +++ b/encoding.go @@ -45,6 +45,7 @@ const ( EncJPEGQualityLevelPseudo3 EncodingType = -30 EncJPEGQualityLevelPseudo2 EncodingType = -31 EncJPEGQualityLevelPseudo1 EncodingType = -32 + EncPointerPosPseudo EncodingType = -232 EncCursorPseudo EncodingType = -239 EncXCursorPseudo EncodingType = -240 EncDesktopSizePseudo EncodingType = -223 @@ -80,7 +81,7 @@ var bPool = sync.Pool{ } type Renderer interface { - SetTargetImage(draw.Image) + SetTargetImage(draw.Image) } // Encoding represents interface for vnc encoding diff --git a/encoding_cursor.go b/encoding_cursor.go index 012f270..8356b80 100644 --- a/encoding_cursor.go +++ b/encoding_cursor.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "image/color" "image/draw" + "vnc2video/logger" ) type CursorPseudoEncoding struct { @@ -27,6 +28,7 @@ func (enc *CursorPseudoEncoding) Reset() error { func (*CursorPseudoEncoding) Type() EncodingType { return EncCursorPseudo } func (enc *CursorPseudoEncoding) Read(c Conn, rect *Rectangle) error { + logger.Debugf("CursorPseudoEncoding.Read: got rect: %v", rect) //rgba := make([]byte, int(rect.Height)*int(rect.Width)*int(c.PixelFormat().BPP/8)) numColors := int(rect.Height) * int(rect.Width) colors := make([]color.Color, numColors) @@ -53,7 +55,8 @@ func (enc *CursorPseudoEncoding) Read(c Conn, rect *Rectangle) error { for x := 0; x < int(rect.Width); x++ { offset := y*int(rect.Width) + x if bitmask[y*int(scanLine)+x/8]&(1< 0 { - enc.Image.Set(x, y, colors[offset]) + enc.Image.Set(x+int(rect.X), y+int(rect.Y), colors[offset]) + //logger.Debugf("CursorPseudoEncoding.Read: setting pixel: (%d,%d) %v", x+int(rect.X), y+int(rect.Y), colors[offset]) } } } diff --git a/encoding_hextile.go b/encoding_hextile.go index 6004ccc..b59f7c2 100644 --- a/encoding_hextile.go +++ b/encoding_hextile.go @@ -101,7 +101,7 @@ func (z *HextileEncoding) Read(r Conn, rect *Rectangle) error { //logger.Debugf("%v %v", rBounds, bgCol) } rBounds := image.Rectangle{Min: image.Point{int(tx), int(ty)}, Max: image.Point{int(tx) + int(tw), int(ty) + int(th)}} - logger.Debugf("filling background rect: %v, col: %v", rBounds, bgCol) + //logger.Debugf("filling background rect: %v, col: %v", rBounds, bgCol) FillRect(z.Image, &rBounds, bgCol) if (subencoding & HextileForegroundSpecified) != 0 { diff --git a/encoding_pointer_pos.go b/encoding_pointer_pos.go new file mode 100644 index 0000000..0b3572d --- /dev/null +++ b/encoding_pointer_pos.go @@ -0,0 +1,38 @@ +package vnc2video + +import ( + "image" + "image/draw" + "vnc2video/logger" +) + +type CursorPosPseudoEncoding struct { + prevPosBackup draw.Image + prevPositionRect image.Rectangle + cursorImage draw.Image + Image draw.Image +} + +func (*CursorPosPseudoEncoding) Supported(Conn) bool { + return true +} + +func (enc *CursorPosPseudoEncoding) SetTargetImage(img draw.Image) { + enc.Image = img +} + +func (enc *CursorPosPseudoEncoding) Reset() error { + return nil +} + +func (*CursorPosPseudoEncoding) Type() EncodingType { return EncPointerPosPseudo } + +func (enc *CursorPosPseudoEncoding) Read(c Conn, rect *Rectangle) error { + logger.Debugf("CursorPosPseudoEncoding: got cursot pos update: %v", rect) + return nil +} + +func (enc *CursorPosPseudoEncoding) Write(c Conn, rect *Rectangle) error { + + return nil +}