fixed copyrect & some refactoring

This commit is contained in:
amit bezalel
2018-01-24 21:15:21 +02:00
parent 902ef26b84
commit 266685537f
3 changed files with 29 additions and 27 deletions

View File

@@ -20,8 +20,13 @@ func (*CopyRectEncoding) Reset() error {
} }
func (*CopyRectEncoding) Type() EncodingType { return EncCopyRect } func (*CopyRectEncoding) Type() EncodingType { return EncCopyRect }
func (enc *CopyRectEncoding) SetTargetImage(img draw.Image) {
//logger.Debugf("!!!!!!!!!!!!!setting image: %v", img.Bounds())
enc.Image = img
}
func (enc *CopyRectEncoding) Read(c Conn, rect *Rectangle) error { func (enc *CopyRectEncoding) Read(c Conn, rect *Rectangle) error {
logger.Debugf("Reading: CopyRect%v", rect) logger.Debugf("Reading: CopyRect %v", rect)
if err := binary.Read(c, binary.BigEndian, &enc.SX); err != nil { if err := binary.Read(c, binary.BigEndian, &enc.SX); err != nil {
return err return err
} }
@@ -30,7 +35,7 @@ func (enc *CopyRectEncoding) Read(c Conn, rect *Rectangle) error {
} }
cpyIm := image.NewRGBA(image.Rectangle{Min: image.Point{0, 0}, Max: image.Point{int(rect.Width), int(rect.Height)}}) cpyIm := image.NewRGBA(image.Rectangle{Min: image.Point{0, 0}, Max: image.Point{int(rect.Width), int(rect.Height)}})
for x := 0; x < int(rect.Width); x++ { for x := 0; x < int(rect.Width); x++ {
for y := 0; x < int(rect.Height); y++ { for y := 0; y < int(rect.Height); y++ {
col := enc.Image.At(x+int(enc.SX), y+int(enc.SY)) col := enc.Image.At(x+int(enc.SX), y+int(enc.SY))
cpyIm.Set(x, y, col) cpyIm.Set(x, y, col)
} }

View File

@@ -7,7 +7,6 @@ import (
"image/color" "image/color"
"image/draw" "image/draw"
"io" "io"
"vnc2video/logger"
) )
func Min(a, b int) int { func Min(a, b int) int {
@@ -25,28 +24,6 @@ func FillRect(img draw.Image, rect *image.Rectangle, c color.Color) {
} }
} }
func readRunLength(r io.Reader) (int, error) {
runLen := 1
mod, err := ReadUint8(r)
if err != nil {
logger.Errorf("renderZRLE: error while reading mod in plain RLE subencoding: %v", err)
return 0, err
}
runLen += int(mod)
for mod == 255 {
//mod = fromZlib.read();
mod, err = ReadUint8(r)
if err != nil {
logger.Errorf("renderZRLE: error while reading mod in-loop plain RLE subencoding: %v", err)
return 0, err
}
runLen += int(mod)
}
return runLen, nil
}
// Read unmarshal color from conn // Read unmarshal color from conn
func ReadColor(c io.Reader, pf *PixelFormat) (*color.RGBA, error) { func ReadColor(c io.Reader, pf *PixelFormat) (*color.RGBA, error) {
if pf.TrueColor == 0 { if pf.TrueColor == 0 {

View File

@@ -298,7 +298,28 @@ func (enc *ZRLEEncoding) handlePlainRLETile(tileOffsetX int, tileOffsetY int, ti
return err return err
} }
// Read unmarshal color from conn func readRunLength(r io.Reader) (int, error) {
runLen := 1
addition, err := ReadUint8(r)
if err != nil {
logger.Errorf("renderZRLE: error while reading addition to runLen in plain RLE subencoding: %v", err)
return 0, err
}
runLen += int(addition)
for addition == 255 {
addition, err = ReadUint8(r)
if err != nil {
logger.Errorf("renderZRLE: error while reading addition to runLen in-loop plain RLE subencoding: %v", err)
return 0, err
}
runLen += int(addition)
}
return runLen, nil
}
// Reads cpixel color from reader
func readCPixel(c io.Reader, pf *PixelFormat) (*color.RGBA, error) { func readCPixel(c io.Reader, pf *PixelFormat) (*color.RGBA, error) {
if pf.TrueColor == 0 { if pf.TrueColor == 0 {
return nil, errors.New("support for non true color formats was not implemented") return nil, errors.New("support for non true color formats was not implemented")
@@ -307,7 +328,6 @@ func readCPixel(c io.Reader, pf *PixelFormat) (*color.RGBA, error) {
isZRLEFormat := IsCPixelSpecific(pf) isZRLEFormat := IsCPixelSpecific(pf)
var col *color.RGBA var col *color.RGBA
if isZRLEFormat { if isZRLEFormat {
//tbytes := make([]byte, 3)
tbytes, err := ReadBytes(3, c) tbytes, err := ReadBytes(3, c)
if err != nil { if err != nil {
return nil, err return nil, err