2017-06-26 13:20:39 +03:00
|
|
|
package vnc
|
|
|
|
|
|
|
|
type RawEncoding struct {
|
|
|
|
Colors []Color
|
|
|
|
}
|
|
|
|
|
2017-07-14 02:01:24 +03:00
|
|
|
func (*RawEncoding) Supported(Conn) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-06-26 13:20:39 +03:00
|
|
|
func (enc *RawEncoding) Write(c Conn, rect *Rectangle) error {
|
|
|
|
var err error
|
2017-06-30 16:13:01 +03:00
|
|
|
|
2017-06-26 13:20:39 +03:00
|
|
|
for _, clr := range enc.Colors {
|
|
|
|
if err = clr.Write(c); err != nil {
|
2017-06-30 16:13:01 +03:00
|
|
|
return err
|
2017-06-26 13:20:39 +03:00
|
|
|
}
|
|
|
|
}
|
2017-06-30 16:13:01 +03:00
|
|
|
|
2017-06-26 13:20:39 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read implements the Encoding interface.
|
|
|
|
func (enc *RawEncoding) Read(c Conn, rect *Rectangle) error {
|
|
|
|
pf := c.PixelFormat()
|
|
|
|
cm := c.ColorMap()
|
|
|
|
colors := make([]Color, rect.Area())
|
2017-06-30 16:13:01 +03:00
|
|
|
|
2017-06-26 13:20:39 +03:00
|
|
|
for y := uint16(0); y < rect.Height; y++ {
|
|
|
|
for x := uint16(0); x < rect.Width; x++ {
|
2017-06-30 00:24:39 +03:00
|
|
|
color := NewColor(&pf, &cm)
|
2017-06-30 16:13:01 +03:00
|
|
|
if err := color.Read(c); err != nil {
|
|
|
|
return err
|
2017-06-26 13:20:39 +03:00
|
|
|
}
|
|
|
|
colors[int(y)*int(rect.Width)+int(x)] = *color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enc.Colors = colors
|
2017-06-30 16:13:01 +03:00
|
|
|
return nil
|
2017-06-26 13:20:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*RawEncoding) Type() EncodingType { return EncRaw }
|