encodings

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HexTileRaw                 = 1 << 0 // Raw数据:不压缩,直接传送,一般此位置1时其它位都置0
	HexTileBackgroundSpecified = 1 << 1 // 包含背景色数据:标志位之后需要接收背景色数据
	HexTileForegroundSpecified = 1 << 2 // 包含前景色数据:背景色之后需要接收前景色数据
	HexTileAnySubRects         = 1 << 3 // 是否含有子块:只要该块中含有两种及两种以上颜色,则此位置1
	HexTileSubRectsColoured    = 1 << 4 // 子块的颜色:如果含有两种颜色,此位置0,子块颜色用前景色;若该块中含有两种以上的颜色,此位置1,子块颜色需要单独指明
)
View Source
const (
	TightFilterCopy     = 0
	TightFilterPalette  = 1
	TightFilterGradient = 2
)
View Source
const (
	ZRLERawPixelData = 0
	ZRLESingleColour = 1
)

Variables

View Source
var TightMinToCompress int = 12

Functions

func IsCPixelSpecific

func IsCPixelSpecific(pf *rfb.PixelFormat) bool

func ReadBytes

func ReadBytes(count int, r io.Reader) ([]byte, error)

func ReadPixel

func ReadPixel(c io.Reader, pf *rfb.PixelFormat) ([]byte, error)

func ReadUint16

func ReadUint16(r io.Reader) (uint16, error)

func ReadUint32

func ReadUint32(r io.Reader) (uint32, error)

func ReadUint8

func ReadUint8(r io.Reader) (uint8, error)

Types

type CoRREEncoding

type CoRREEncoding struct {
	// contains filtered or unexported fields
}

CoRREEncoding CoRRE是RRE的变体,它把发送的最大矩形限制在255×255个像素以内,用一个字节就能表示子矩形的维度。 如果服务器想要发送一个超出限制的矩形,则只要把它划分成几个更小的RFB矩形即可。 “对于通常的桌面,这样的方式具有比RRE更好的压缩度”。 实际上,如果进一步限制矩形的大小,就能够获得最好的压缩度。“矩形的最大值越小,决策的尺度就越好”。 但是,如果把矩形的最大值限制得太小,就增加了矩形的数量,而由于每个RFB矩形都会有一定的开销,结果反而会使压缩度变差。 所以应该选择一个比较恰当的数字。在目前的实现中,采用的最大值为48×48。

func (*CoRREEncoding) Clone

func (that *CoRREEncoding) Clone(data ...bool) rfb.IEncoding

func (*CoRREEncoding) Read

func (that *CoRREEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*CoRREEncoding) Supported

func (that *CoRREEncoding) Supported(session rfb.ISession) bool

func (*CoRREEncoding) Type

func (that *CoRREEncoding) Type() rfb.EncodingType

func (*CoRREEncoding) Write

func (that *CoRREEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) (err error)

type CopyRectEncoding

type CopyRectEncoding struct {
	SX, SY uint16
}

CopyRectEncoding 该编码方式对于客户端在某些已经有了相同的象素数据的时候是非常简单和有效的。 这种编码方式在网络中表现为x,y 坐标。让客户端知道去拷贝那一个矩形的象素数据。 它可以应用于很多种情况。最明显的就是当用户在屏幕上移动某一个窗口的时候,还有在窗口内容滚动的时候。 在优化画的时候不是很明显,一个比较智能的服务器可能只会发送一次,因为它知道在客户端的帧缓存里已经存在了。 复制矩形编码并不是完全独立地发送所有的数据矩形,而是对于像素值完全相同的一组矩形, 只发送第一个矩形全部数据,随后的矩形则只需要发送左上角X、Y坐标。 实际上,复制矩形编码主要指的就是随后的这一系列X、Y坐标,而对于第一个矩形具体采用何种编码类型并没有限制, 仅仅需要知道第一个矩形在帧缓冲区中的位置,以便于完成复制操作。 因此,往往是把复制矩形编码和其它针对某一个矩形的编码类型结合使用。

func (*CopyRectEncoding) Clone

func (that *CopyRectEncoding) Clone(data ...bool) rfb.IEncoding

func (*CopyRectEncoding) Read

func (that *CopyRectEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*CopyRectEncoding) Supported

func (that *CopyRectEncoding) Supported(session rfb.ISession) bool

func (*CopyRectEncoding) Type

func (that *CopyRectEncoding) Type() rfb.EncodingType

func (*CopyRectEncoding) Write

func (that *CopyRectEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type CursorPosPseudoEncoding

type CursorPosPseudoEncoding struct {
}

func (*CursorPosPseudoEncoding) Clone

func (that *CursorPosPseudoEncoding) Clone(data ...bool) rfb.IEncoding

func (*CursorPosPseudoEncoding) Draw

func (that *CursorPosPseudoEncoding) Draw(img draw.Image, rect *rfb.Rectangle) error

func (*CursorPosPseudoEncoding) Read

func (that *CursorPosPseudoEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*CursorPosPseudoEncoding) Supported

func (that *CursorPosPseudoEncoding) Supported(session rfb.ISession) bool

func (*CursorPosPseudoEncoding) Type

func (*CursorPosPseudoEncoding) Write

func (that *CursorPosPseudoEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type CursorPseudoEncoding

type CursorPseudoEncoding struct {
	// contains filtered or unexported fields
}

CursorPseudoEncoding 如果客户端请求指针/鼠标伪编码,那么就是说它有能力进行本地绘制鼠标。 这样就可以明显改善传输性能。服务器通过发送带有伪鼠标编码的伪矩形来设置鼠标的形状作为更新的一部分。 伪矩形的x 和y 表示鼠标的热点,宽和高表示用像素来表示鼠标的宽和高。包含宽X高像素值的数据带有位掩码。 位掩码是由从左到右,从上到下的扫描线组成,而每一扫描线被填充为floor((width +7) / 8)。 对应每一字节最重要的位表示最左边像素,对应1 位表示相应指针的像素是正确的。

func (*CursorPseudoEncoding) Clone

func (that *CursorPseudoEncoding) Clone(data ...bool) rfb.IEncoding

func (*CursorPseudoEncoding) Read

func (that *CursorPseudoEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*CursorPseudoEncoding) Supported

func (that *CursorPseudoEncoding) Supported(session rfb.ISession) bool

func (*CursorPseudoEncoding) Type

func (that *CursorPseudoEncoding) Type() rfb.EncodingType

func (*CursorPseudoEncoding) Write

func (that *CursorPseudoEncoding) Write(sess rfb.ISession, rect *rfb.Rectangle) error

type CursorWithAlphaPseudoEncoding

type CursorWithAlphaPseudoEncoding struct {
	// contains filtered or unexported fields
}

func (*CursorWithAlphaPseudoEncoding) Clone

func (that *CursorWithAlphaPseudoEncoding) Clone(data ...bool) rfb.IEncoding

func (*CursorWithAlphaPseudoEncoding) Read

func (that *CursorWithAlphaPseudoEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*CursorWithAlphaPseudoEncoding) Supported

func (that *CursorWithAlphaPseudoEncoding) Supported(session rfb.ISession) bool

func (*CursorWithAlphaPseudoEncoding) Type

func (*CursorWithAlphaPseudoEncoding) Write

func (that *CursorWithAlphaPseudoEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type DesktopNamePseudoEncoding

type DesktopNamePseudoEncoding struct {
	Name []byte
}

DesktopNamePseudoEncoding 服务端设置桌面名字的消息

func (*DesktopNamePseudoEncoding) Clone

func (that *DesktopNamePseudoEncoding) Clone(data ...bool) rfb.IEncoding

func (*DesktopNamePseudoEncoding) Read

func (that *DesktopNamePseudoEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

Read 实现了编码接口

func (*DesktopNamePseudoEncoding) Supported

func (that *DesktopNamePseudoEncoding) Supported(session rfb.ISession) bool

func (*DesktopNamePseudoEncoding) Type

func (*DesktopNamePseudoEncoding) Write

func (that *DesktopNamePseudoEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type DesktopSizePseudoEncoding

type DesktopSizePseudoEncoding struct {
}

DesktopSizePseudoEncoding 如果客户端请求桌面大小伪编码,那么就是说它能处理帧缓存宽/高的改变。 服务器通过发送带有桌面大小伪编码的伪矩形作为上一个矩形来完成一次更新。 伪矩形的x 和y 被忽略,而宽和高表示帧缓存新的宽和高。没有其他的数据与伪矩形有关。

func (*DesktopSizePseudoEncoding) Clone

func (that *DesktopSizePseudoEncoding) Clone(data ...bool) rfb.IEncoding

func (*DesktopSizePseudoEncoding) Read

func (that *DesktopSizePseudoEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

Read implements the Encoding interface.

func (*DesktopSizePseudoEncoding) Supported

func (that *DesktopSizePseudoEncoding) Supported(session rfb.ISession) bool

func (*DesktopSizePseudoEncoding) Type

func (*DesktopSizePseudoEncoding) Write

func (that *DesktopSizePseudoEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type ExtendedDesktopSizePseudo

type ExtendedDesktopSizePseudo struct {
	// contains filtered or unexported fields
}

ExtendedDesktopSizePseudo 扩展适应客户端桌面分辨率

func (*ExtendedDesktopSizePseudo) Clone

func (that *ExtendedDesktopSizePseudo) Clone(data ...bool) rfb.IEncoding

func (*ExtendedDesktopSizePseudo) Read

func (that *ExtendedDesktopSizePseudo) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*ExtendedDesktopSizePseudo) Supported

func (that *ExtendedDesktopSizePseudo) Supported(rfb.ISession) bool

func (*ExtendedDesktopSizePseudo) Type

func (*ExtendedDesktopSizePseudo) Write

func (that *ExtendedDesktopSizePseudo) Write(session rfb.ISession, rect *rfb.Rectangle) (err error)

type FencePseudo added in v1.1.1

type FencePseudo struct {
}

func (*FencePseudo) Clone added in v1.1.1

func (that *FencePseudo) Clone(_ ...bool) rfb.IEncoding

func (*FencePseudo) Read added in v1.1.1

func (that *FencePseudo) Read(_ rfb.ISession, _ *rfb.Rectangle) error

func (*FencePseudo) Supported added in v1.1.1

func (that *FencePseudo) Supported(_ rfb.ISession) bool

func (*FencePseudo) Type added in v1.1.1

func (that *FencePseudo) Type() rfb.EncodingType

func (*FencePseudo) Write added in v1.1.1

func (that *FencePseudo) Write(_ rfb.ISession, _ *rfb.Rectangle) error

type H264Encoding added in v1.1.1

type H264Encoding struct {
	// contains filtered or unexported fields
}

func (*H264Encoding) Clone added in v1.1.1

func (that *H264Encoding) Clone(data ...bool) rfb.IEncoding

func (*H264Encoding) Read added in v1.1.1

func (that *H264Encoding) Read(session rfb.ISession, rectangle *rfb.Rectangle) error

func (*H264Encoding) Supported added in v1.1.1

func (that *H264Encoding) Supported(session rfb.ISession) bool

func (*H264Encoding) Type added in v1.1.1

func (that *H264Encoding) Type() rfb.EncodingType

func (*H264Encoding) Write added in v1.1.1

func (that *H264Encoding) Write(session rfb.ISession, rectangle *rfb.Rectangle) error

type HexTileEncoding

type HexTileEncoding struct {
	// contains filtered or unexported fields
}

HexTileEncoding 是RRE编码的变种,把屏幕分成16x16象素的小块,每块用Raw或RRE方式转送. 通过解释HexTile算法,说明了简单而常用的屏幕传送和压缩算法,希望对屏幕监测、传送相关的工作有所启发

func (*HexTileEncoding) Clone

func (that *HexTileEncoding) Clone(data ...bool) rfb.IEncoding

func (*HexTileEncoding) Read

func (that *HexTileEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error
  1. 分割 a. 传送的图像区域被分为若干个大小为16×16象素的块,如果整个矩形不是16的倍数,则最后1行(或列)的块宽度(或高度)变小 b. 这些块按从左到右,从上到下的顺序排列,屏幕中变化的块被传送,不变的不被传送. c. 由于块大小是16x16,所以块内坐标XY可用一字节表示,WH可用一个字节表示
  2. 块内部的编码 a. 计算块内部的颜色数:一种、两种、多种,并记录出现频率最多的颜色为背景色,如果仅有两种颜色,则另一颜色记为前景色 b. 判断块内颜色数是否为一种,如果是,则先修改传送标志位,然后传送整块大小(0,0,w,h)和背景色,此块传送即完成. c. 如果不是一种,则把块拆分成颜色不同的小矩形,方法如下:
  3. 先把块复制到一块内存区中,以免破坏原始数据,暂称tmpBuf
  4. 从第一个象素开始判断,该点颜色是否与背景色相同.
  5. 如果不同,则分别向右和向下求得与该点颜色连续的色块.
  6. 对比右色块和下色块,取出其中较大的一个,做为一个矩形色块
  7. 在tmpBuf中把此矩形填成背景色,以避免重复判断
  8. 继续判断下一象素点…… d. 记录各个矩形色块的位置(x,y,w,h),如果块内含两种以上颜色,还要记录矩形色块的颜色值 e. 一边取得矩形色块,一边判断矩形色块描述数据的总长是否大于原始数据,如果大于原始数据,则放弃取色块,标志字节Raw(HexTileRaw)位置
  9. 以Raw方式直接传送原始数据,此块传送完成 f. 如果块含两种以上颜色,则将标志位的子块位(HexTileSubRectsColoured)置1,否则置0 g. 传送标志位,传送矩形色块个数,然后传送各矩形块数据,块中颜色数为2时不需要传送每个矩形块的颜色数据,只传位置即可. h. 注意:如果背景色或前景色与前一块(16x16块)相同,则可以不传送背景色或前景色,客户端会默认延用前一块的

func (*HexTileEncoding) Supported

func (that *HexTileEncoding) Supported(_ rfb.ISession) bool

func (*HexTileEncoding) Type

func (that *HexTileEncoding) Type() rfb.EncodingType

func (*HexTileEncoding) Write

func (that *HexTileEncoding) Write(sess rfb.ISession, rect *rfb.Rectangle) error

type LastRectPseudo added in v1.1.1

type LastRectPseudo struct {
}

func (*LastRectPseudo) Clone added in v1.1.1

func (that *LastRectPseudo) Clone(_ ...bool) rfb.IEncoding

func (*LastRectPseudo) Read added in v1.1.1

func (that *LastRectPseudo) Read(_ rfb.ISession, _ *rfb.Rectangle) error

func (*LastRectPseudo) Supported added in v1.1.1

func (that *LastRectPseudo) Supported(_ rfb.ISession) bool

func (*LastRectPseudo) Type added in v1.1.1

func (that *LastRectPseudo) Type() rfb.EncodingType

func (*LastRectPseudo) Write added in v1.1.1

func (that *LastRectPseudo) Write(_ rfb.ISession, _ *rfb.Rectangle) error

type LedStatePseudo

type LedStatePseudo struct {
	LedState uint8
}

LedStatePseudo 切换客户端本地小键盘锁定的led灯 0 滚动锁 1 数字锁定 2 大写锁定

func (*LedStatePseudo) Clone

func (that *LedStatePseudo) Clone(data ...bool) rfb.IEncoding

func (*LedStatePseudo) Read

func (that *LedStatePseudo) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*LedStatePseudo) Supported

func (that *LedStatePseudo) Supported(session rfb.ISession) bool

func (*LedStatePseudo) Type

func (that *LedStatePseudo) Type() rfb.EncodingType

func (*LedStatePseudo) Write

func (that *LedStatePseudo) Write(session rfb.ISession, rect *rfb.Rectangle) error

type RREEncoding

type RREEncoding struct {
	// contains filtered or unexported fields
}

RREEncoding RRE表示提升和运行长度,正如它名字暗示的那样,它实质上表示二维向量的运行长度编码。 RRE把矩形编码成可以被客户机的图形引擎翻译的格式。RRE不适合复杂的桌面,但在一些情况下比较有用。 RRE的思想就是把像素矩形的数据分成一些子区域,和一些压缩原始区域的单元。最近最佳的分区方式一般是比较容易计算的。 编码是由像素值组成的,Vb(基本上是在矩形中最常用的像素值)和一个计数N,紧接着是N的子矩形列表,这些里面由数组组成,(x,y)是对应子矩形的坐标, 表示子矩形上-左的坐标值,(w,h) 则表示子矩形的宽高。客户端可以通过绘制使用背景像素数据值,然后再根据子矩形来绘制原始矩形。 二维行程编码本质上是对行程编码的一个二维模拟,而其压缩度可以保证与行程编码相同甚至更好。 而且更重要的是,采用RRE编码的矩形被传送到客户端以后,可以立即有效地被最简单的图形引擎所还原。

func (*RREEncoding) Clone

func (that *RREEncoding) Clone(data ...bool) rfb.IEncoding

func (*RREEncoding) Read

func (that *RREEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*RREEncoding) Supported

func (that *RREEncoding) Supported(session rfb.ISession) bool

func (*RREEncoding) Type

func (that *RREEncoding) Type() rfb.EncodingType

func (*RREEncoding) Write

func (that *RREEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type RawEncoding

type RawEncoding struct {
	// contains filtered or unexported fields
}

RawEncoding 采用原始地像素数据,而不进行任何的加工处理。 在这种情况下,对于一个宽度乘以高度(即面积)为N的矩形,数据就由N个像素值组成,这些值表示按照扫描线顺序从左到右排列的每个像素。 很明显,这种编码方式是最简单的,也是效率最低的。 RFB要求所有的客户都必须能够处理这种原始编码的数据,并且在客户没有特别指定需要某种编码方式的时候,RFB服务器就默认生成原始编码。

func (*RawEncoding) Clone

func (that *RawEncoding) Clone(data ...bool) rfb.IEncoding

func (*RawEncoding) Read

func (that *RawEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

Read 读取原始色彩表示

func (*RawEncoding) Supported

func (that *RawEncoding) Supported(rfb.ISession) bool

func (*RawEncoding) Type

func (that *RawEncoding) Type() rfb.EncodingType

func (*RawEncoding) Write

func (that *RawEncoding) Write(sess rfb.ISession, rect *rfb.Rectangle) error

type TightEncoding

type TightEncoding struct {
	// contains filtered or unexported fields
}

func (*TightEncoding) Clone

func (that *TightEncoding) Clone(data ...bool) rfb.IEncoding

func (*TightEncoding) Read

func (that *TightEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*TightEncoding) ReadCompactLen

func (that *TightEncoding) ReadCompactLen(session rfb.ISession) (int, error)

ReadCompactLen 获取动态长度

func (*TightEncoding) ReadTightData

func (that *TightEncoding) ReadTightData(dataSize int, session rfb.ISession) error

func (*TightEncoding) Supported

func (that *TightEncoding) Supported(session rfb.ISession) bool

func (*TightEncoding) Type

func (that *TightEncoding) Type() rfb.EncodingType

func (*TightEncoding) Write

func (that *TightEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type TightPngEncoding

type TightPngEncoding struct {
	// contains filtered or unexported fields
}

func (*TightPngEncoding) Clone

func (that *TightPngEncoding) Clone(data ...bool) rfb.IEncoding

func (*TightPngEncoding) Read

func (that *TightPngEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*TightPngEncoding) ReadCompactLen

func (that *TightPngEncoding) ReadCompactLen(session rfb.ISession) (int, error)

ReadCompactLen 获取动态长度

func (*TightPngEncoding) Supported

func (that *TightPngEncoding) Supported(session rfb.ISession) bool

func (*TightPngEncoding) Type

func (that *TightPngEncoding) Type() rfb.EncodingType

func (*TightPngEncoding) Write

func (that *TightPngEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type XCursorPseudoEncoding

type XCursorPseudoEncoding struct {
	PrimaryR, PrimaryG, PrimaryB       uint8  // 主颜色
	SecondaryR, SecondaryG, SecondaryB uint8  // 次颜色
	Bitmap                             []byte //颜色位图
	Bitmask                            []byte //透明度位掩码
}

func (*XCursorPseudoEncoding) Clone

func (that *XCursorPseudoEncoding) Clone(data ...bool) rfb.IEncoding

func (*XCursorPseudoEncoding) Read

func (that *XCursorPseudoEncoding) Read(session rfb.ISession, rect *rfb.Rectangle) error

func (*XCursorPseudoEncoding) Supported

func (that *XCursorPseudoEncoding) Supported(session rfb.ISession) bool

func (*XCursorPseudoEncoding) Type

func (that *XCursorPseudoEncoding) Type() rfb.EncodingType

func (*XCursorPseudoEncoding) Write

func (that *XCursorPseudoEncoding) Write(session rfb.ISession, rect *rfb.Rectangle) error

type ZLibEncoding

type ZLibEncoding struct {
	// contains filtered or unexported fields
}

func (*ZLibEncoding) Clone

func (that *ZLibEncoding) Clone(data ...bool) rfb.IEncoding

func (*ZLibEncoding) Read

func (that *ZLibEncoding) Read(sess rfb.ISession, rect *rfb.Rectangle) error

func (*ZLibEncoding) Supported

func (that *ZLibEncoding) Supported(c rfb.ISession) bool

func (*ZLibEncoding) Type

func (that *ZLibEncoding) Type() rfb.EncodingType

func (*ZLibEncoding) Write

func (that *ZLibEncoding) Write(sess rfb.ISession, rect *rfb.Rectangle) error

type ZRLEEncoding

type ZRLEEncoding struct {
	// contains filtered or unexported fields
}

ZRLEEncoding ZRLE(Zlib Run - Length Encoding),它结合了zlib 压缩,片技术、调色板和运行长度编码。 在传输中,矩形以4 字节长度区域开始,紧接着是zlib 压缩的数据,一个单一的 zlib“流”对象被用在RFB协议的连接上, 因此ZRLE矩形必须严格的按照顺序进行编码和译码。

func (*ZRLEEncoding) Clone

func (that *ZRLEEncoding) Clone(data ...bool) rfb.IEncoding

func (*ZRLEEncoding) Read

func (that *ZRLEEncoding) Read(sess rfb.ISession, rect *rfb.Rectangle) error

func (*ZRLEEncoding) Supported

func (that *ZRLEEncoding) Supported(session rfb.ISession) bool

func (*ZRLEEncoding) Type

func (that *ZRLEEncoding) Type() rfb.EncodingType

func (*ZRLEEncoding) Write

func (that *ZRLEEncoding) Write(sess rfb.ISession, rect *rfb.Rectangle) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL