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
|
||||
func (c *ClientConn) PixelFormat() PixelFormat {
|
||||
func (c *ClientConn) PixelFormat() *PixelFormat {
|
||||
return c.pixelFormat
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ func (c *ClientConn) SetDesktopName(name []byte) {
|
||||
}
|
||||
|
||||
// SetPixelFormat sets pixel format
|
||||
func (c *ClientConn) SetPixelFormat(pf PixelFormat) error {
|
||||
func (c *ClientConn) SetPixelFormat(pf *PixelFormat) error {
|
||||
c.pixelFormat = pf
|
||||
return nil
|
||||
}
|
||||
@ -208,7 +208,7 @@ type ClientConn struct {
|
||||
// The pixel format associated with the connection. This shouldn't
|
||||
// be modified. If you wish to set a new pixel format, use the
|
||||
// SetPixelFormat method.
|
||||
pixelFormat PixelFormat
|
||||
pixelFormat *PixelFormat
|
||||
|
||||
quitCh chan struct{}
|
||||
quit chan struct{}
|
||||
@ -298,7 +298,7 @@ type ClientConfig struct {
|
||||
Handlers []Handler
|
||||
SecurityHandlers []SecurityHandler
|
||||
Encodings []Encoding
|
||||
PixelFormat PixelFormat
|
||||
PixelFormat *PixelFormat
|
||||
ColorMap ColorMap
|
||||
ClientMessageCh chan ClientMessage
|
||||
ServerMessageCh chan ServerMessage
|
||||
|
4
conn.go
4
conn.go
@ -11,8 +11,8 @@ type Conn interface {
|
||||
Conn() net.Conn
|
||||
Config() interface{}
|
||||
Protocol() string
|
||||
PixelFormat() PixelFormat
|
||||
SetPixelFormat(PixelFormat) error
|
||||
PixelFormat() *PixelFormat
|
||||
SetPixelFormat(*PixelFormat) error
|
||||
ColorMap() ColorMap
|
||||
SetColorMap(ColorMap)
|
||||
Encodings() []Encoding
|
||||
|
@ -28,7 +28,7 @@ func (enc *RawEncoding) Read(c Conn, rect *Rectangle) error {
|
||||
|
||||
for y := uint16(0); y < rect.Height; y++ {
|
||||
for x := uint16(0); x < rect.Width; x++ {
|
||||
color := NewColor(&pf, &cm)
|
||||
color := NewColor(pf, &cm)
|
||||
if err := color.Read(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func main() {
|
||||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ const (
|
||||
// ServerInit struct used in server init handshake
|
||||
type ServerInit struct {
|
||||
FBWidth, FBHeight uint16
|
||||
PixelFormat PixelFormat
|
||||
PixelFormat *PixelFormat
|
||||
NameLength uint32
|
||||
NameText []byte
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ type PixelFormat struct {
|
||||
const pixelFormatLen = 16
|
||||
|
||||
// NewPixelFormat returns a populated PixelFormat structure
|
||||
func NewPixelFormat(bpp uint8) PixelFormat {
|
||||
func NewPixelFormat(bpp uint8) *PixelFormat {
|
||||
bigEndian := uint8(0)
|
||||
// rgbMax := uint16(math.Exp2(float64(bpp))) - 1
|
||||
rMax := uint16(255)
|
||||
@ -58,16 +58,16 @@ func NewPixelFormat(bpp uint8) PixelFormat {
|
||||
// rs, gs, bs = 0, 8, 16
|
||||
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
|
||||
func NewPixelFormatAten() PixelFormat {
|
||||
return PixelFormat{16, 15, 0, 1, (1 << 5) - 1, (1 << 5) - 1, (1 << 5) - 1, 10, 5, 0, [3]byte{}}
|
||||
func NewPixelFormatAten() *PixelFormat {
|
||||
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
|
||||
func (pf PixelFormat) Marshal() ([]byte, error) {
|
||||
func (pf *PixelFormat) Marshal() ([]byte, error) {
|
||||
// Validation checks.
|
||||
switch pf.BPP {
|
||||
case 8, 16, 32:
|
||||
@ -89,7 +89,7 @@ func (pf PixelFormat) Marshal() ([]byte, error) {
|
||||
buf.Reset()
|
||||
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
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ func (pf PixelFormat) Marshal() ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if _, err := io.ReadAtLeast(r, buf, pixelFormatLen); err != nil {
|
||||
return err
|
||||
@ -106,7 +106,7 @@ func (pf PixelFormat) Read(r io.Reader) error {
|
||||
}
|
||||
|
||||
// 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.Reset()
|
||||
defer bPool.Put(buf)
|
||||
@ -115,7 +115,7 @@ func (pf PixelFormat) Unmarshal(data []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := binary.Read(buf, binary.BigEndian, &pf); err != nil {
|
||||
if err := binary.Read(buf, binary.BigEndian, pf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -123,12 +123,12 @@ func (pf PixelFormat) Unmarshal(data []byte) error {
|
||||
}
|
||||
|
||||
// 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 }",
|
||||
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 {
|
||||
return binary.BigEndian
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func (c *ServerConn) DesktopName() []byte {
|
||||
}
|
||||
|
||||
// PixelFormat return connection pixel format
|
||||
func (c *ServerConn) PixelFormat() PixelFormat {
|
||||
func (c *ServerConn) PixelFormat() *PixelFormat {
|
||||
return c.pixelFormat
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func (c *ServerConn) SetDesktopName(name []byte) {
|
||||
}
|
||||
|
||||
// SetPixelFormat sets pixel format for server conn
|
||||
func (c *ServerConn) SetPixelFormat(pf PixelFormat) error {
|
||||
func (c *ServerConn) SetPixelFormat(pf *PixelFormat) error {
|
||||
c.pixelFormat = pf
|
||||
return nil
|
||||
}
|
||||
@ -174,7 +174,7 @@ type ServerConn struct {
|
||||
// The pixel format associated with the connection. This shouldn't
|
||||
// be modified. If you wish to set a new pixel format, use the
|
||||
// SetPixelFormat method.
|
||||
pixelFormat PixelFormat
|
||||
pixelFormat *PixelFormat
|
||||
|
||||
quit chan struct{}
|
||||
}
|
||||
@ -195,7 +195,7 @@ type ServerConfig struct {
|
||||
Handlers []Handler
|
||||
SecurityHandlers []SecurityHandler
|
||||
Encodings []Encoding
|
||||
PixelFormat PixelFormat
|
||||
PixelFormat *PixelFormat
|
||||
ColorMap ColorMap
|
||||
ClientMessageCh chan ClientMessage
|
||||
ServerMessageCh chan ServerMessage
|
||||
|
Loading…
Reference in New Issue
Block a user