mirror of
https://github.com/amitbet/vnc2video.git
synced 2025-04-27 02:10:54 +00:00
added rre encoding (tested)
This commit is contained in:
parent
b858291681
commit
5c0f72a0cb
@ -4,6 +4,7 @@ import (
|
||||
"encoding/binary"
|
||||
"image"
|
||||
"image/draw"
|
||||
"vnc2video/logger"
|
||||
)
|
||||
|
||||
type CopyRectEncoding struct {
|
||||
@ -20,6 +21,7 @@ func (*CopyRectEncoding) Reset() error {
|
||||
func (*CopyRectEncoding) Type() EncodingType { return EncCopyRect }
|
||||
|
||||
func (enc *CopyRectEncoding) Read(c Conn, rect *Rectangle) error {
|
||||
logger.Debugf("Reading: CopyRect%v", rect)
|
||||
if err := binary.Read(c, binary.BigEndian, &enc.SX); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package vnc2video
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"image/draw"
|
||||
"io"
|
||||
//"image/draw"
|
||||
)
|
||||
@ -11,6 +12,26 @@ type RREEncoding struct {
|
||||
numSubRects uint32
|
||||
backgroundColor []byte
|
||||
subRectData []byte
|
||||
Image draw.Image
|
||||
}
|
||||
|
||||
func (*RREEncoding) Supported(Conn) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (enc *RREEncoding) SetTargetImage(img draw.Image) {
|
||||
enc.Image = img
|
||||
}
|
||||
|
||||
func (enc *RREEncoding) Reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*RREEncoding) Type() EncodingType { return EncRRE }
|
||||
|
||||
func (enc *RREEncoding) Write(c Conn, rect *Rectangle) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
@ -33,12 +54,10 @@ func (z *RREEncoding) WriteTo(w io.Writer) (n int, err error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (z *RREEncoding) Type() int32 {
|
||||
return 2
|
||||
}
|
||||
func (z *RREEncoding) Read(r Conn, rect *Rectangle) error {
|
||||
func (enc *RREEncoding) Read(r Conn, rect *Rectangle) error {
|
||||
//func (z *RREEncoding) Read(pixelFmt *PixelFormat, rect *Rectangle, r io.Reader) (Encoding, error) {
|
||||
bytesPerPixel := int(r.PixelFormat().BPP / 8)
|
||||
pf := r.PixelFormat()
|
||||
//bytesPerPixel := int(pf.BPP / 8)
|
||||
|
||||
var numOfSubrectangles uint32
|
||||
if err := binary.Read(r, binary.BigEndian, &numOfSubrectangles); err != nil {
|
||||
@ -46,18 +65,44 @@ func (z *RREEncoding) Read(r Conn, rect *Rectangle) error {
|
||||
}
|
||||
|
||||
var err error
|
||||
z.numSubRects = numOfSubrectangles
|
||||
enc.numSubRects = numOfSubrectangles
|
||||
|
||||
//read whole-rect background color
|
||||
z.backgroundColor, err = ReadBytes(bytesPerPixel, r)
|
||||
bgColor, err := ReadColor(r, &pf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
imgRect := MakeRectFromVncRect(rect)
|
||||
FillRect(enc.Image, &imgRect, bgColor)
|
||||
|
||||
//read all individual rects (color=bytesPerPixel + x=16b + y=16b + w=16b + h=16b)
|
||||
z.subRectData, err = ReadBytes(int(numOfSubrectangles)*(bytesPerPixel+8), r) // x+y+w+h=8 bytes
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
for i := 0; i < int(numOfSubrectangles); i++ {
|
||||
color, err := ReadColor(r, &pf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
x, err := ReadUint16(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
y, err := ReadUint16(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
width, err := ReadUint16(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
height, err := ReadUint16(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
subRect := MakeRect(int(rect.X+x), int(rect.Y+y), int(width), int(height))
|
||||
FillRect(enc.Image, &subRect, color)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -529,23 +529,6 @@ func (enc *TightEncoding) readTightPalette(connReader Conn, bytesPixel int) (col
|
||||
return paletteColors, nil
|
||||
}
|
||||
|
||||
func ReadUint8(r io.Reader) (uint8, error) {
|
||||
var myUint uint8
|
||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return myUint, nil
|
||||
}
|
||||
func ReadUint32(r io.Reader) (uint32, error) {
|
||||
var myUint uint32
|
||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return myUint, nil
|
||||
}
|
||||
|
||||
func (enc *TightEncoding) ReadTightData(dataSize int, c Conn, decoderId int) ([]byte, error) {
|
||||
|
||||
logger.Debugf(">>> Reading zipped tight data from decoder: %d", decoderId)
|
||||
|
@ -70,3 +70,36 @@ func DecodeRaw(reader io.Reader, pf *PixelFormat, rect *Rectangle, targetImage d
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReadUint8(r io.Reader) (uint8, error) {
|
||||
var myUint uint8
|
||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return myUint, nil
|
||||
}
|
||||
func ReadUint16(r io.Reader) (uint16, error) {
|
||||
var myUint uint16
|
||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return myUint, nil
|
||||
}
|
||||
|
||||
func ReadUint32(r io.Reader) (uint32, error) {
|
||||
var myUint uint32
|
||||
if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return myUint, nil
|
||||
}
|
||||
|
||||
func MakeRect(x, y, width, height int) image.Rectangle {
|
||||
return image.Rectangle{Min: image.Point{X: x, Y: y}, Max: image.Point{X: x + width, Y: y + height}}
|
||||
}
|
||||
func MakeRectFromVncRect(rect *Rectangle) image.Rectangle {
|
||||
return MakeRect(int(rect.X), int(rect.Y), int(rect.Width), int(rect.Height))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user