mirror of
https://github.com/amitbet/vnc2video.git
synced 2025-09-18 16:08:40 +00:00
fixed copyrect & some refactoring
This commit is contained in:
@@ -20,8 +20,13 @@ func (*CopyRectEncoding) Reset() error {
|
||||
}
|
||||
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 {
|
||||
logger.Debugf("Reading: CopyRect%v", rect)
|
||||
logger.Debugf("Reading: CopyRect %v", rect)
|
||||
if err := binary.Read(c, binary.BigEndian, &enc.SX); err != nil {
|
||||
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)}})
|
||||
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))
|
||||
cpyIm.Set(x, y, col)
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"io"
|
||||
"vnc2video/logger"
|
||||
)
|
||||
|
||||
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
|
||||
func ReadColor(c io.Reader, pf *PixelFormat) (*color.RGBA, error) {
|
||||
if pf.TrueColor == 0 {
|
||||
|
@@ -298,7 +298,28 @@ func (enc *ZRLEEncoding) handlePlainRLETile(tileOffsetX int, tileOffsetY int, ti
|
||||
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) {
|
||||
if pf.TrueColor == 0 {
|
||||
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)
|
||||
var col *color.RGBA
|
||||
if isZRLEFormat {
|
||||
//tbytes := make([]byte, 3)
|
||||
tbytes, err := ReadBytes(3, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user