1 Star 0 Fork 0

Cloudy/vnc2video

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
encoding_rre.go 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
amit bezalel 提交于 2018-01-20 13:20 . added rre encoding (tested)
package vnc2video
import (
"encoding/binary"
"image/draw"
"io"
//"image/draw"
)
type RREEncoding struct {
//Colors []Color
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) {
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 (enc *RREEncoding) Read(r Conn, rect *Rectangle) error {
//func (z *RREEncoding) Read(pixelFmt *PixelFormat, rect *Rectangle, r io.Reader) (Encoding, error) {
pf := r.PixelFormat()
//bytesPerPixel := int(pf.BPP / 8)
var numOfSubrectangles uint32
if err := binary.Read(r, binary.BigEndian, &numOfSubrectangles); err != nil {
return err
}
var err error
enc.numSubRects = numOfSubrectangles
//read whole-rect background color
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 {
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/itcloudy/vnc2video.git
git@gitee.com:itcloudy/vnc2video.git
itcloudy
vnc2video
vnc2video
master

搜索帮助