change pixel format to pointer
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
ba36a87eb7
commit
c00b8c7ae0
@ -120,7 +120,7 @@ func (c *ClientConn) DesktopName() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PixelFormat returns connection pixel format
|
// PixelFormat returns connection pixel format
|
||||||
func (c *ClientConn) PixelFormat() PixelFormat {
|
func (c *ClientConn) PixelFormat() *PixelFormat {
|
||||||
return c.pixelFormat
|
return c.pixelFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ func (c *ClientConn) SetDesktopName(name []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetPixelFormat sets pixel format
|
// SetPixelFormat sets pixel format
|
||||||
func (c *ClientConn) SetPixelFormat(pf PixelFormat) error {
|
func (c *ClientConn) SetPixelFormat(pf *PixelFormat) error {
|
||||||
c.pixelFormat = pf
|
c.pixelFormat = pf
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ type ClientConn struct {
|
|||||||
// The pixel format associated with the connection. This shouldn't
|
// The pixel format associated with the connection. This shouldn't
|
||||||
// be modified. If you wish to set a new pixel format, use the
|
// be modified. If you wish to set a new pixel format, use the
|
||||||
// SetPixelFormat method.
|
// SetPixelFormat method.
|
||||||
pixelFormat PixelFormat
|
pixelFormat *PixelFormat
|
||||||
|
|
||||||
quitCh chan struct{}
|
quitCh chan struct{}
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
@ -298,7 +298,7 @@ type ClientConfig struct {
|
|||||||
Handlers []Handler
|
Handlers []Handler
|
||||||
SecurityHandlers []SecurityHandler
|
SecurityHandlers []SecurityHandler
|
||||||
Encodings []Encoding
|
Encodings []Encoding
|
||||||
PixelFormat PixelFormat
|
PixelFormat *PixelFormat
|
||||||
ColorMap ColorMap
|
ColorMap ColorMap
|
||||||
ClientMessageCh chan ClientMessage
|
ClientMessageCh chan ClientMessage
|
||||||
ServerMessageCh chan ServerMessage
|
ServerMessageCh chan ServerMessage
|
||||||
|
4
conn.go
4
conn.go
@ -11,8 +11,8 @@ type Conn interface {
|
|||||||
Conn() net.Conn
|
Conn() net.Conn
|
||||||
Config() interface{}
|
Config() interface{}
|
||||||
Protocol() string
|
Protocol() string
|
||||||
PixelFormat() PixelFormat
|
PixelFormat() *PixelFormat
|
||||||
SetPixelFormat(PixelFormat) error
|
SetPixelFormat(*PixelFormat) error
|
||||||
ColorMap() ColorMap
|
ColorMap() ColorMap
|
||||||
SetColorMap(ColorMap)
|
SetColorMap(ColorMap)
|
||||||
Encodings() []Encoding
|
Encodings() []Encoding
|
||||||
|
@ -28,7 +28,7 @@ func (enc *RawEncoding) Read(c Conn, rect *Rectangle) error {
|
|||||||
|
|
||||||
for y := uint16(0); y < rect.Height; y++ {
|
for y := uint16(0); y < rect.Height; y++ {
|
||||||
for x := uint16(0); x < rect.Width; x++ {
|
for x := uint16(0); x < rect.Width; x++ {
|
||||||
color := NewColor(&pf, &cm)
|
color := NewColor(pf, &cm)
|
||||||
if err := color.Read(c); err != nil {
|
if err := color.Read(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func main() {
|
|||||||
for y := 0; y < height; y++ {
|
for y := 0; y < height; y++ {
|
||||||
for x := 0; x < width; x++ {
|
for x := 0; x < width; x++ {
|
||||||
r, g, b, a := im.At(x, y).RGBA()
|
r, g, b, a := im.At(x, y).RGBA()
|
||||||
clr := rgbaToColor(&cfg.PixelFormat, r, g, b, a)
|
clr := rgbaToColor(cfg.PixelFormat, r, g, b, a)
|
||||||
colors = append(colors, *clr)
|
colors = append(colors, *clr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ const (
|
|||||||
// ServerInit struct used in server init handshake
|
// ServerInit struct used in server init handshake
|
||||||
type ServerInit struct {
|
type ServerInit struct {
|
||||||
FBWidth, FBHeight uint16
|
FBWidth, FBHeight uint16
|
||||||
PixelFormat PixelFormat
|
PixelFormat *PixelFormat
|
||||||
NameLength uint32
|
NameLength uint32
|
||||||
NameText []byte
|
NameText []byte
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ type PixelFormat struct {
|
|||||||
const pixelFormatLen = 16
|
const pixelFormatLen = 16
|
||||||
|
|
||||||
// NewPixelFormat returns a populated PixelFormat structure
|
// NewPixelFormat returns a populated PixelFormat structure
|
||||||
func NewPixelFormat(bpp uint8) PixelFormat {
|
func NewPixelFormat(bpp uint8) *PixelFormat {
|
||||||
bigEndian := uint8(0)
|
bigEndian := uint8(0)
|
||||||
// rgbMax := uint16(math.Exp2(float64(bpp))) - 1
|
// rgbMax := uint16(math.Exp2(float64(bpp))) - 1
|
||||||
rMax := uint16(255)
|
rMax := uint16(255)
|
||||||
@ -58,16 +58,16 @@ func NewPixelFormat(bpp uint8) PixelFormat {
|
|||||||
// rs, gs, bs = 0, 8, 16
|
// rs, gs, bs = 0, 8, 16
|
||||||
rs, gs, bs = 16, 8, 0
|
rs, gs, bs = 16, 8, 0
|
||||||
}
|
}
|
||||||
return PixelFormat{bpp, depth, bigEndian, tc, rMax, gMax, bMax, rs, gs, bs, [3]byte{}}
|
return &PixelFormat{bpp, depth, bigEndian, tc, rMax, gMax, bMax, rs, gs, bs, [3]byte{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPixelFormatAten returns Aten IKVM pixel format
|
// NewPixelFormatAten returns Aten IKVM pixel format
|
||||||
func NewPixelFormatAten() PixelFormat {
|
func NewPixelFormatAten() *PixelFormat {
|
||||||
return PixelFormat{16, 15, 0, 1, (1 << 5) - 1, (1 << 5) - 1, (1 << 5) - 1, 10, 5, 0, [3]byte{}}
|
return &PixelFormat{16, 15, 0, 1, (1 << 5) - 1, (1 << 5) - 1, (1 << 5) - 1, 10, 5, 0, [3]byte{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marshal implements the Marshaler interface
|
// Marshal implements the Marshaler interface
|
||||||
func (pf PixelFormat) Marshal() ([]byte, error) {
|
func (pf *PixelFormat) Marshal() ([]byte, error) {
|
||||||
// Validation checks.
|
// Validation checks.
|
||||||
switch pf.BPP {
|
switch pf.BPP {
|
||||||
case 8, 16, 32:
|
case 8, 16, 32:
|
||||||
@ -89,7 +89,7 @@ func (pf PixelFormat) Marshal() ([]byte, error) {
|
|||||||
buf.Reset()
|
buf.Reset()
|
||||||
defer bPool.Put(buf)
|
defer bPool.Put(buf)
|
||||||
|
|
||||||
if err := binary.Write(buf, binary.BigEndian, &pf); err != nil {
|
if err := binary.Write(buf, binary.BigEndian, pf); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ func (pf PixelFormat) Marshal() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read reads from an io.Reader, and populates the PixelFormat
|
// Read reads from an io.Reader, and populates the PixelFormat
|
||||||
func (pf PixelFormat) Read(r io.Reader) error {
|
func (pf *PixelFormat) Read(r io.Reader) error {
|
||||||
buf := make([]byte, pixelFormatLen)
|
buf := make([]byte, pixelFormatLen)
|
||||||
if _, err := io.ReadAtLeast(r, buf, pixelFormatLen); err != nil {
|
if _, err := io.ReadAtLeast(r, buf, pixelFormatLen); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -106,7 +106,7 @@ func (pf PixelFormat) Read(r io.Reader) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal implements the Unmarshaler interface
|
// Unmarshal implements the Unmarshaler interface
|
||||||
func (pf PixelFormat) Unmarshal(data []byte) error {
|
func (pf *PixelFormat) Unmarshal(data []byte) error {
|
||||||
buf := bPool.Get().(*bytes.Buffer)
|
buf := bPool.Get().(*bytes.Buffer)
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
defer bPool.Put(buf)
|
defer bPool.Put(buf)
|
||||||
@ -115,7 +115,7 @@ func (pf PixelFormat) Unmarshal(data []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := binary.Read(buf, binary.BigEndian, &pf); err != nil {
|
if err := binary.Read(buf, binary.BigEndian, pf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,12 +123,12 @@ func (pf PixelFormat) Unmarshal(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String implements the fmt.Stringer interface
|
// String implements the fmt.Stringer interface
|
||||||
func (pf PixelFormat) String() string {
|
func (pf *PixelFormat) String() string {
|
||||||
return fmt.Sprintf("{ bpp: %d depth: %d big-endian: %d true-color: %d red-max: %d green-max: %d blue-max: %d red-shift: %d green-shift: %d blue-shift: %d }",
|
return fmt.Sprintf("{ bpp: %d depth: %d big-endian: %d true-color: %d red-max: %d green-max: %d blue-max: %d red-shift: %d green-shift: %d blue-shift: %d }",
|
||||||
pf.BPP, pf.Depth, pf.BigEndian, pf.TrueColor, pf.RedMax, pf.GreenMax, pf.BlueMax, pf.RedShift, pf.GreenShift, pf.BlueShift)
|
pf.BPP, pf.Depth, pf.BigEndian, pf.TrueColor, pf.RedMax, pf.GreenMax, pf.BlueMax, pf.RedShift, pf.GreenShift, pf.BlueShift)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pf PixelFormat) order() binary.ByteOrder {
|
func (pf *PixelFormat) order() binary.ByteOrder {
|
||||||
if pf.BigEndian == 1 {
|
if pf.BigEndian == 1 {
|
||||||
return binary.BigEndian
|
return binary.BigEndian
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ func (c *ServerConn) DesktopName() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PixelFormat return connection pixel format
|
// PixelFormat return connection pixel format
|
||||||
func (c *ServerConn) PixelFormat() PixelFormat {
|
func (c *ServerConn) PixelFormat() *PixelFormat {
|
||||||
return c.pixelFormat
|
return c.pixelFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ func (c *ServerConn) SetDesktopName(name []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetPixelFormat sets pixel format for server conn
|
// SetPixelFormat sets pixel format for server conn
|
||||||
func (c *ServerConn) SetPixelFormat(pf PixelFormat) error {
|
func (c *ServerConn) SetPixelFormat(pf *PixelFormat) error {
|
||||||
c.pixelFormat = pf
|
c.pixelFormat = pf
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ type ServerConn struct {
|
|||||||
// The pixel format associated with the connection. This shouldn't
|
// The pixel format associated with the connection. This shouldn't
|
||||||
// be modified. If you wish to set a new pixel format, use the
|
// be modified. If you wish to set a new pixel format, use the
|
||||||
// SetPixelFormat method.
|
// SetPixelFormat method.
|
||||||
pixelFormat PixelFormat
|
pixelFormat *PixelFormat
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ type ServerConfig struct {
|
|||||||
Handlers []Handler
|
Handlers []Handler
|
||||||
SecurityHandlers []SecurityHandler
|
SecurityHandlers []SecurityHandler
|
||||||
Encodings []Encoding
|
Encodings []Encoding
|
||||||
PixelFormat PixelFormat
|
PixelFormat *PixelFormat
|
||||||
ColorMap ColorMap
|
ColorMap ColorMap
|
||||||
ClientMessageCh chan ClientMessage
|
ClientMessageCh chan ClientMessage
|
||||||
ServerMessageCh chan ServerMessage
|
ServerMessageCh chan ServerMessage
|
||||||
|
Loading…
Reference in New Issue
Block a user