mirror of
https://github.com/amitbet/vnc2video.git
synced 2025-08-02 05:21:48 +00:00
added rre encoding (tested)
This commit is contained in:
parent
b858291681
commit
5c0f72a0cb
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"image"
|
"image"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
|
"vnc2video/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CopyRectEncoding struct {
|
type CopyRectEncoding struct {
|
||||||
@ -20,6 +21,7 @@ func (*CopyRectEncoding) Reset() error {
|
|||||||
func (*CopyRectEncoding) Type() EncodingType { return EncCopyRect }
|
func (*CopyRectEncoding) Type() EncodingType { return EncCopyRect }
|
||||||
|
|
||||||
func (enc *CopyRectEncoding) Read(c Conn, rect *Rectangle) error {
|
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 {
|
if err := binary.Read(c, binary.BigEndian, &enc.SX); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package vnc2video
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"image/draw"
|
||||||
"io"
|
"io"
|
||||||
//"image/draw"
|
//"image/draw"
|
||||||
)
|
)
|
||||||
@ -11,6 +12,26 @@ type RREEncoding struct {
|
|||||||
numSubRects uint32
|
numSubRects uint32
|
||||||
backgroundColor []byte
|
backgroundColor []byte
|
||||||
subRectData []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) {
|
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
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *RREEncoding) Type() int32 {
|
func (enc *RREEncoding) Read(r Conn, rect *Rectangle) error {
|
||||||
return 2
|
|
||||||
}
|
|
||||||
func (z *RREEncoding) Read(r Conn, rect *Rectangle) error {
|
|
||||||
//func (z *RREEncoding) Read(pixelFmt *PixelFormat, rect *Rectangle, r io.Reader) (Encoding, 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
|
var numOfSubrectangles uint32
|
||||||
if err := binary.Read(r, binary.BigEndian, &numOfSubrectangles); err != nil {
|
if err := binary.Read(r, binary.BigEndian, &numOfSubrectangles); err != nil {
|
||||||
@ -46,19 +65,45 @@ func (z *RREEncoding) Read(r Conn, rect *Rectangle) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
z.numSubRects = numOfSubrectangles
|
enc.numSubRects = numOfSubrectangles
|
||||||
|
|
||||||
//read whole-rect background color
|
//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)
|
||||||
|
|
||||||
|
for i := 0; i < int(numOfSubrectangles); i++ {
|
||||||
|
color, err := ReadColor(r, &pf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//read all individual rects (color=bytesPerPixel + x=16b + y=16b + w=16b + h=16b)
|
x, err := ReadUint16(r)
|
||||||
z.subRectData, err = ReadBytes(int(numOfSubrectangles)*(bytesPerPixel+8), r) // x+y+w+h=8 bytes
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -529,23 +529,6 @@ func (enc *TightEncoding) readTightPalette(connReader Conn, bytesPixel int) (col
|
|||||||
return paletteColors, nil
|
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) {
|
func (enc *TightEncoding) ReadTightData(dataSize int, c Conn, decoderId int) ([]byte, error) {
|
||||||
|
|
||||||
logger.Debugf(">>> Reading zipped tight data from decoder: %d", decoderId)
|
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
|
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