From a0f8168a6ccf515cfba669d8fe3bf94210be2e12 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 26 Jun 2017 18:21:15 +0300 Subject: [PATCH] add new encodings Signed-off-by: Vasiliy Tolstov --- encoding.go | 2 + encoding_desktopname.go | 35 +++++++++++++++++ encoding_xcursor.go | 85 +++++++++++++++++++++++++++++++++++++++++ encodingtype_string.go | 84 ++++++++++++++++++++-------------------- 4 files changed, 165 insertions(+), 41 deletions(-) create mode 100644 encoding_desktopname.go create mode 100644 encoding_xcursor.go diff --git a/encoding.go b/encoding.go index 05d5aaa..df3c1b0 100644 --- a/encoding.go +++ b/encoding.go @@ -36,6 +36,7 @@ const ( EncJPEGQualityLevelPseudo2 EncodingType = -31 EncJPEGQualityLevelPseudo1 EncodingType = -32 EncColorPseudo EncodingType = -239 + EncXCursorPseudo EncodingType = -240 EncDesktopSizePseudo EncodingType = -223 EncLastRectPseudo EncodingType = -224 EncCompressionLevel10 EncodingType = -247 @@ -51,6 +52,7 @@ const ( EncQEMUPointerMotionChangePseudo EncodingType = -257 EncQEMUExtendedKeyEventPseudo EncodingType = -258 EncTightPng EncodingType = -260 + EncDesktopNamePseudo EncodingType = -307 EncExtendedDesktopSizePseudo EncodingType = -308 EncXvpPseudo EncodingType = -309 EncFencePseudo EncodingType = -312 diff --git a/encoding_desktopname.go b/encoding_desktopname.go new file mode 100644 index 0000000..dc8e620 --- /dev/null +++ b/encoding_desktopname.go @@ -0,0 +1,35 @@ +package vnc + +import "encoding/binary" + +// DesktopNamePseudoEncoding represents a desktop size message from the server. +type DesktopNamePseudoEncoding struct { + Name []byte +} + +func (*DesktopNamePseudoEncoding) Type() EncodingType { return EncDesktopNamePseudo } + +// Read implements the Encoding interface. +func (enc *DesktopNamePseudoEncoding) Read(c Conn, rect *Rectangle) error { + var length uint32 + if err := binary.Read(c, binary.BigEndian, &length); err != nil { + return err + } + name := make([]byte, length) + if err := binary.Read(c, binary.BigEndian, &name); err != nil { + return err + } + enc.Name = name + return nil +} + +func (enc *DesktopNamePseudoEncoding) Write(c Conn, rect *Rectangle) error { + if err := binary.Write(c, binary.BigEndian, uint32(len(enc.Name))); err != nil { + return err + } + if err := binary.Write(c, binary.BigEndian, enc.Name); err != nil { + return err + } + + return c.Flush() +} diff --git a/encoding_xcursor.go b/encoding_xcursor.go new file mode 100644 index 0000000..796ca34 --- /dev/null +++ b/encoding_xcursor.go @@ -0,0 +1,85 @@ +package vnc + +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) 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 +} diff --git a/encodingtype_string.go b/encodingtype_string.go index 723779b..3c997f0 100644 --- a/encodingtype_string.go +++ b/encodingtype_string.go @@ -4,7 +4,7 @@ package vnc import "fmt" -const _EncodingType_name = "EncContinuousUpdatesPseudoEncFencePseudoEncClientRedirectEncXvpPseudoEncExtendedDesktopSizePseudoEncTightPngEncQEMUExtendedKeyEventPseudoEncQEMUPointerMotionChangePseudoEncCompressionLevel1EncCompressionLevel2EncCompressionLevel3EncCompressionLevel4EncCompressionLevel5EncCompressionLevel6EncCompressionLevel7EncCompressionLevel8EncCompressionLevel9EncCompressionLevel10EncColorPseudoEncLastRectPseudoEncDesktopSizePseudoEncJPEGQualityLevelPseudo1EncJPEGQualityLevelPseudo2EncJPEGQualityLevelPseudo3EncJPEGQualityLevelPseudo4EncJPEGQualityLevelPseudo5EncJPEGQualityLevelPseudo6EncJPEGQualityLevelPseudo7EncJPEGQualityLevelPseudo8EncJPEGQualityLevelPseudo9EncJPEGQualityLevelPseudo10EncRawEncCopyRectEncRREEncCoRREEncHextileEncZlibEncTightEncZlibHexEncUltra1EncUltra2EncTRLEEncZRLEEncJPEGEncJRLE" +const _EncodingType_name = "EncContinuousUpdatesPseudoEncFencePseudoEncClientRedirectEncXvpPseudoEncExtendedDesktopSizePseudoEncDesktopNamePseudoEncTightPngEncQEMUExtendedKeyEventPseudoEncQEMUPointerMotionChangePseudoEncCompressionLevel1EncCompressionLevel2EncCompressionLevel3EncCompressionLevel4EncCompressionLevel5EncCompressionLevel6EncCompressionLevel7EncCompressionLevel8EncCompressionLevel9EncCompressionLevel10EncXCursorPseudoEncColorPseudoEncLastRectPseudoEncDesktopSizePseudoEncJPEGQualityLevelPseudo1EncJPEGQualityLevelPseudo2EncJPEGQualityLevelPseudo3EncJPEGQualityLevelPseudo4EncJPEGQualityLevelPseudo5EncJPEGQualityLevelPseudo6EncJPEGQualityLevelPseudo7EncJPEGQualityLevelPseudo8EncJPEGQualityLevelPseudo9EncJPEGQualityLevelPseudo10EncRawEncCopyRectEncRREEncCoRREEncHextileEncZlibEncTightEncZlibHexEncUltra1EncUltra2EncTRLEEncZRLEEncJPEGEncJRLE" var _EncodingType_map = map[EncodingType]string{ -313: _EncodingType_name[0:26], @@ -12,46 +12,48 @@ var _EncodingType_map = map[EncodingType]string{ -311: _EncodingType_name[40:57], -309: _EncodingType_name[57:69], -308: _EncodingType_name[69:97], - -260: _EncodingType_name[97:108], - -258: _EncodingType_name[108:137], - -257: _EncodingType_name[137:169], - -256: _EncodingType_name[169:189], - -255: _EncodingType_name[189:209], - -254: _EncodingType_name[209:229], - -253: _EncodingType_name[229:249], - -252: _EncodingType_name[249:269], - -251: _EncodingType_name[269:289], - -250: _EncodingType_name[289:309], - -249: _EncodingType_name[309:329], - -248: _EncodingType_name[329:349], - -247: _EncodingType_name[349:370], - -239: _EncodingType_name[370:384], - -224: _EncodingType_name[384:401], - -223: _EncodingType_name[401:421], - -32: _EncodingType_name[421:447], - -31: _EncodingType_name[447:473], - -30: _EncodingType_name[473:499], - -29: _EncodingType_name[499:525], - -28: _EncodingType_name[525:551], - -27: _EncodingType_name[551:577], - -26: _EncodingType_name[577:603], - -25: _EncodingType_name[603:629], - -24: _EncodingType_name[629:655], - -23: _EncodingType_name[655:682], - 0: _EncodingType_name[682:688], - 1: _EncodingType_name[688:699], - 2: _EncodingType_name[699:705], - 4: _EncodingType_name[705:713], - 5: _EncodingType_name[713:723], - 6: _EncodingType_name[723:730], - 7: _EncodingType_name[730:738], - 8: _EncodingType_name[738:748], - 9: _EncodingType_name[748:757], - 10: _EncodingType_name[757:766], - 15: _EncodingType_name[766:773], - 16: _EncodingType_name[773:780], - 21: _EncodingType_name[780:787], - 22: _EncodingType_name[787:794], + -307: _EncodingType_name[97:117], + -260: _EncodingType_name[117:128], + -258: _EncodingType_name[128:157], + -257: _EncodingType_name[157:189], + -256: _EncodingType_name[189:209], + -255: _EncodingType_name[209:229], + -254: _EncodingType_name[229:249], + -253: _EncodingType_name[249:269], + -252: _EncodingType_name[269:289], + -251: _EncodingType_name[289:309], + -250: _EncodingType_name[309:329], + -249: _EncodingType_name[329:349], + -248: _EncodingType_name[349:369], + -247: _EncodingType_name[369:390], + -240: _EncodingType_name[390:406], + -239: _EncodingType_name[406:420], + -224: _EncodingType_name[420:437], + -223: _EncodingType_name[437:457], + -32: _EncodingType_name[457:483], + -31: _EncodingType_name[483:509], + -30: _EncodingType_name[509:535], + -29: _EncodingType_name[535:561], + -28: _EncodingType_name[561:587], + -27: _EncodingType_name[587:613], + -26: _EncodingType_name[613:639], + -25: _EncodingType_name[639:665], + -24: _EncodingType_name[665:691], + -23: _EncodingType_name[691:718], + 0: _EncodingType_name[718:724], + 1: _EncodingType_name[724:735], + 2: _EncodingType_name[735:741], + 4: _EncodingType_name[741:749], + 5: _EncodingType_name[749:759], + 6: _EncodingType_name[759:766], + 7: _EncodingType_name[766:774], + 8: _EncodingType_name[774:784], + 9: _EncodingType_name[784:793], + 10: _EncodingType_name[793:802], + 15: _EncodingType_name[802:809], + 16: _EncodingType_name[809:816], + 21: _EncodingType_name[816:823], + 22: _EncodingType_name[823:830], } func (i EncodingType) String() string {