From c00b8c7ae0e7680242a18a13c6c46487dcb251fd Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 23 Jan 2020 02:04:27 +0300 Subject: [PATCH] change pixel format to pointer Signed-off-by: Vasiliy Tolstov --- client.go | 8 ++++---- conn.go | 4 ++-- encoding_raw.go | 2 +- example/server/main.go | 2 +- messages.go | 2 +- pixel_format.go | 22 +++++++++++----------- server.go | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/client.go b/client.go index c629130..5150258 100644 --- a/client.go +++ b/client.go @@ -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 diff --git a/conn.go b/conn.go index d4d9b7b..05f72bf 100644 --- a/conn.go +++ b/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 diff --git a/encoding_raw.go b/encoding_raw.go index 65c66a2..39fbd4b 100644 --- a/encoding_raw.go +++ b/encoding_raw.go @@ -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 } diff --git a/example/server/main.go b/example/server/main.go index 6cd3f89..bb2c2a8 100644 --- a/example/server/main.go +++ b/example/server/main.go @@ -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) } } diff --git a/messages.go b/messages.go index 1803a6d..3efa5bc 100644 --- a/messages.go +++ b/messages.go @@ -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 } diff --git a/pixel_format.go b/pixel_format.go index 7a87206..0549c39 100644 --- a/pixel_format.go +++ b/pixel_format.go @@ -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 } diff --git a/server.go b/server.go index 6fd2fb8..70c0f56 100644 --- a/server.go +++ b/server.go @@ -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