lazarus/formats/dat/dat.go

32 lines
509 B
Go
Raw Normal View History

2018-12-16 22:09:18 +00:00
package dat
import (
"encoding/binary"
imageColor "image/color"
2018-12-16 22:09:18 +00:00
"io"
)
type Palette struct {
2018-12-21 04:31:43 +00:00
Colors [256]imageColor.RGBA
}
type color struct {
B byte
G byte
R byte
2018-12-16 22:09:18 +00:00
}
func NewFromReader(reader io.Reader) (*Palette, error) {
var colors [256]color
if err := binary.Read(reader, binary.LittleEndian, &colors); err != nil {
2018-12-16 22:09:18 +00:00
return nil, err
}
palette := new(Palette)
for i, color := range colors {
2018-12-21 04:31:43 +00:00
palette.Colors[i] = imageColor.RGBA{color.R, color.G, color.B, 0xff}
}
return palette, nil
2018-12-16 22:09:18 +00:00
}