mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-09-23 02:19:52 +00:00
general refactoring + fixed setcursorpseudo
This commit is contained in:
@@ -27,7 +27,7 @@ func (z *CopyRectEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return 4, nil
|
||||
}
|
||||
|
||||
func (z *CopyRectEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
func (z *CopyRectEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
z.copyRectSrcX, _ = r.ReadUint16()
|
||||
z.copyRectSrcY, _ = r.ReadUint16()
|
||||
return z, nil
|
||||
|
@@ -36,7 +36,7 @@ func (z *CoRREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (z *CoRREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
func (z *CoRREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||
numOfSubrectangles, err := r.ReadUint32()
|
||||
if err != nil {
|
||||
|
@@ -15,7 +15,7 @@ func (pe *EncCursorPseudo) Type() int32 {
|
||||
func (z *EncCursorPseudo) WriteTo(w io.Writer) (n int, err error) {
|
||||
return 0, nil
|
||||
}
|
||||
func (pe *EncCursorPseudo) Read(pf *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
func (pe *EncCursorPseudo) Read(pf *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
if rect.Width*rect.Height == 0 {
|
||||
return pe, nil
|
||||
}
|
||||
|
@@ -1,84 +1,84 @@
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
HextileRaw = 1
|
||||
HextileBackgroundSpecified = 2
|
||||
HextileForegroundSpecified = 4
|
||||
HextileAnySubrects = 8
|
||||
HextileSubrectsColoured = 16
|
||||
)
|
||||
|
||||
type HextileEncoding struct {
|
||||
//Colors []Color
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
func (z *HextileEncoding) Type() int32 {
|
||||
return 5
|
||||
}
|
||||
func (z *HextileEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
func (z *HextileEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
bytesPerPixel := int(pixelFmt.BPP) / 8
|
||||
|
||||
r.StartByteCollection()
|
||||
defer func() {
|
||||
z.bytes = r.EndByteCollection()
|
||||
}()
|
||||
|
||||
for ty := rect.Y; ty < rect.Y+rect.Height; ty += 16 {
|
||||
th := 16
|
||||
if rect.Y+rect.Height-ty < 16 {
|
||||
th = int(rect.Y) + int(rect.Height) - int(ty)
|
||||
}
|
||||
|
||||
for tx := rect.X; tx < rect.X+rect.Width; tx += 16 {
|
||||
tw := 16
|
||||
if rect.X+rect.Width-tx < 16 {
|
||||
tw = int(rect.X) + int(rect.Width) - int(tx)
|
||||
}
|
||||
|
||||
//handle Hextile Subrect(tx, ty, tw, th):
|
||||
subencoding, err := r.ReadUint8()
|
||||
|
||||
if err != nil {
|
||||
logger.Errorf("HextileEncoding.Read: error in hextile reader: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if (subencoding & HextileRaw) != 0 {
|
||||
r.ReadBytes(tw * th * bytesPerPixel)
|
||||
continue
|
||||
}
|
||||
if (subencoding & HextileBackgroundSpecified) != 0 {
|
||||
r.ReadBytes(int(bytesPerPixel))
|
||||
}
|
||||
if (subencoding & HextileForegroundSpecified) != 0 {
|
||||
r.ReadBytes(int(bytesPerPixel))
|
||||
}
|
||||
if (subencoding & HextileAnySubrects) == 0 {
|
||||
//logger.Debug("hextile reader: no Subrects")
|
||||
continue
|
||||
}
|
||||
|
||||
nSubrects, err := r.ReadUint8()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bufsize := int(nSubrects) * 2
|
||||
if (subencoding & HextileSubrectsColoured) != 0 {
|
||||
bufsize += int(nSubrects) * int(bytesPerPixel)
|
||||
}
|
||||
r.ReadBytes(bufsize)
|
||||
}
|
||||
}
|
||||
|
||||
return z, nil
|
||||
}
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
HextileRaw = 1
|
||||
HextileBackgroundSpecified = 2
|
||||
HextileForegroundSpecified = 4
|
||||
HextileAnySubrects = 8
|
||||
HextileSubrectsColoured = 16
|
||||
)
|
||||
|
||||
type HextileEncoding struct {
|
||||
//Colors []Color
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
func (z *HextileEncoding) Type() int32 {
|
||||
return 5
|
||||
}
|
||||
func (z *HextileEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
func (z *HextileEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
bytesPerPixel := int(pixelFmt.BPP) / 8
|
||||
|
||||
r.StartByteCollection()
|
||||
defer func() {
|
||||
z.bytes = r.EndByteCollection()
|
||||
}()
|
||||
|
||||
for ty := rect.Y; ty < rect.Y+rect.Height; ty += 16 {
|
||||
th := 16
|
||||
if rect.Y+rect.Height-ty < 16 {
|
||||
th = int(rect.Y) + int(rect.Height) - int(ty)
|
||||
}
|
||||
|
||||
for tx := rect.X; tx < rect.X+rect.Width; tx += 16 {
|
||||
tw := 16
|
||||
if rect.X+rect.Width-tx < 16 {
|
||||
tw = int(rect.X) + int(rect.Width) - int(tx)
|
||||
}
|
||||
|
||||
//handle Hextile Subrect(tx, ty, tw, th):
|
||||
subencoding, err := r.ReadUint8()
|
||||
|
||||
if err != nil {
|
||||
logger.Errorf("HextileEncoding.Read: error in hextile reader: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if (subencoding & HextileRaw) != 0 {
|
||||
r.ReadBytes(tw * th * bytesPerPixel)
|
||||
continue
|
||||
}
|
||||
if (subencoding & HextileBackgroundSpecified) != 0 {
|
||||
r.ReadBytes(int(bytesPerPixel))
|
||||
}
|
||||
if (subencoding & HextileForegroundSpecified) != 0 {
|
||||
r.ReadBytes(int(bytesPerPixel))
|
||||
}
|
||||
if (subencoding & HextileAnySubrects) == 0 {
|
||||
//logger.Debug("hextile reader: no Subrects")
|
||||
continue
|
||||
}
|
||||
|
||||
nSubrects, err := r.ReadUint8()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bufsize := int(nSubrects) * 2
|
||||
if (subencoding & HextileSubrectsColoured) != 0 {
|
||||
bufsize += int(nSubrects) * int(bytesPerPixel)
|
||||
}
|
||||
r.ReadBytes(bufsize)
|
||||
}
|
||||
}
|
||||
|
||||
return z, nil
|
||||
}
|
||||
|
@@ -15,6 +15,6 @@ func (pe *PseudoEncoding) Type() int32 {
|
||||
func (z *PseudoEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return 0, nil
|
||||
}
|
||||
func (pe *PseudoEncoding) Read(*common.PixelFormat, *common.Rectangle, *common.RfbReadHelper) (common.Encoding, error) {
|
||||
func (pe *PseudoEncoding) Read(*common.PixelFormat, *common.Rectangle, *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
return pe, nil
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ func (*RawEncoding) Type() int32 {
|
||||
func (z *RawEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
func (*RawEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
func (*RawEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
|
||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||
|
||||
|
@@ -1,59 +1,59 @@
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
)
|
||||
|
||||
type RREEncoding struct {
|
||||
//Colors []Color
|
||||
numSubRects uint32
|
||||
backgroundColor []byte
|
||||
subRectData []byte
|
||||
}
|
||||
|
||||
func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
binary.Write(w, binary.BigEndian, z.numSubRects)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
w.Write(z.backgroundColor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
w.Write(z.subRectData)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
b := len(z.backgroundColor) + len(z.subRectData) + 4
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (z *RREEncoding) Type() int32 {
|
||||
return 2
|
||||
}
|
||||
func (z *RREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||
numOfSubrectangles, err := r.ReadUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
z.numSubRects = numOfSubrectangles
|
||||
|
||||
//read whole-rect background color
|
||||
z.backgroundColor, err = r.ReadBytes(bytesPerPixel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//read all individual rects (color=bytesPerPixel + x=16b + y=16b + w=16b + h=16b)
|
||||
z.subRectData, err = r.ReadBytes(int(numOfSubrectangles) * (bytesPerPixel + 8)) // x+y+w+h=8 bytes
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return z, nil
|
||||
}
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
)
|
||||
|
||||
type RREEncoding struct {
|
||||
//Colors []Color
|
||||
numSubRects uint32
|
||||
backgroundColor []byte
|
||||
subRectData []byte
|
||||
}
|
||||
|
||||
func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
binary.Write(w, binary.BigEndian, z.numSubRects)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
w.Write(z.backgroundColor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
w.Write(z.subRectData)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
b := len(z.backgroundColor) + len(z.subRectData) + 4
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (z *RREEncoding) Type() int32 {
|
||||
return 2
|
||||
}
|
||||
func (z *RREEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
bytesPerPixel := int(pixelFmt.BPP / 8)
|
||||
numOfSubrectangles, err := r.ReadUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
z.numSubRects = numOfSubrectangles
|
||||
|
||||
//read whole-rect background color
|
||||
z.backgroundColor, err = r.ReadBytes(bytesPerPixel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//read all individual rects (color=bytesPerPixel + x=16b + y=16b + w=16b + h=16b)
|
||||
z.subRectData, err = r.ReadBytes(int(numOfSubrectangles) * (bytesPerPixel + 8)) // x+y+w+h=8 bytes
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return z, nil
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ type TightEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
|
||||
func (*TightEncoding) Type() int32 { return int32(common.EncTight) }
|
||||
|
||||
func calcTightBytePerPixel(pf *common.PixelFormat) int {
|
||||
@@ -51,7 +50,7 @@ func StoreBytes(bytes *bytes.Buffer, data []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
bytesPixel := calcTightBytePerPixel(pixelFmt)
|
||||
|
||||
r.StartByteCollection()
|
||||
|
@@ -17,7 +17,7 @@ func (z *TightPngEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
|
||||
func (*TightPngEncoding) Type() int32 { return int32(common.EncTightPng) }
|
||||
|
||||
func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
bytesPixel := calcTightBytePerPixel(pixelFmt)
|
||||
r.StartByteCollection()
|
||||
defer func() {
|
||||
|
@@ -1,38 +1,38 @@
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
)
|
||||
|
||||
type ZLibEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
func (z *ZLibEncoding) Type() int32 {
|
||||
return 6
|
||||
}
|
||||
func (z *ZLibEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
func (z *ZLibEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
//conn := common.RfbReadHelper{Reader:r}
|
||||
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
|
||||
//bytesPerPixel := c.PixelFormat.BPP / 8
|
||||
bytes := &bytes.Buffer{}
|
||||
len, err := r.ReadUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
binary.Write(bytes, binary.BigEndian, len)
|
||||
bts, err := r.ReadBytes(int(len))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
StoreBytes(bytes, bts)
|
||||
z.bytes = bytes.Bytes()
|
||||
return z, nil
|
||||
}
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
)
|
||||
|
||||
type ZLibEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
func (z *ZLibEncoding) Type() int32 {
|
||||
return 6
|
||||
}
|
||||
func (z *ZLibEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
func (z *ZLibEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
//conn := common.RfbReadHelper{Reader:r}
|
||||
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
|
||||
//bytesPerPixel := c.PixelFormat.BPP / 8
|
||||
bytes := &bytes.Buffer{}
|
||||
len, err := r.ReadUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
binary.Write(bytes, binary.BigEndian, len)
|
||||
bts, err := r.ReadBytes(int(len))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
StoreBytes(bytes, bts)
|
||||
z.bytes = bytes.Bytes()
|
||||
return z, nil
|
||||
}
|
||||
|
@@ -1,38 +1,38 @@
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
)
|
||||
|
||||
type ZRLEEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
func (z *ZRLEEncoding) Type() int32 {
|
||||
return 16
|
||||
}
|
||||
|
||||
func (z *ZRLEEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
|
||||
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||
|
||||
bytes := &bytes.Buffer{}
|
||||
len, err := r.ReadUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
binary.Write(bytes, binary.BigEndian, len)
|
||||
bts, err := r.ReadBytes(int(len))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
StoreBytes(bytes, bts)
|
||||
z.bytes = bytes.Bytes()
|
||||
return z, nil
|
||||
}
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
)
|
||||
|
||||
type ZRLEEncoding struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
func (z *ZRLEEncoding) Type() int32 {
|
||||
return 16
|
||||
}
|
||||
|
||||
func (z *ZRLEEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return w.Write(z.bytes)
|
||||
}
|
||||
|
||||
func (z *ZRLEEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
|
||||
bytes := &bytes.Buffer{}
|
||||
len, err := r.ReadUint32()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
binary.Write(bytes, binary.BigEndian, len)
|
||||
bts, err := r.ReadBytes(int(len))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
StoreBytes(bytes, bts)
|
||||
z.bytes = bytes.Bytes()
|
||||
return z, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user