2018-12-16 22:09:18 +00:00
|
|
|
package dat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"io"
|
2018-12-31 18:54:33 +00:00
|
|
|
|
|
|
|
"github.com/FooSoft/lazarus/math"
|
2018-12-16 22:09:18 +00:00
|
|
|
)
|
|
|
|
|
2019-01-09 02:45:19 +00:00
|
|
|
type Palette struct {
|
2018-12-31 18:54:33 +00:00
|
|
|
Colors [256]math.Color3b
|
2018-12-17 23:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type color struct {
|
|
|
|
B byte
|
|
|
|
G byte
|
|
|
|
R byte
|
2018-12-16 22:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 02:45:19 +00:00
|
|
|
func NewFromReader(reader io.Reader) (*Palette, error) {
|
2018-12-17 23:09:30 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-01-09 02:45:19 +00:00
|
|
|
palette := new(Palette)
|
2018-12-17 23:09:30 +00:00
|
|
|
for i, color := range colors {
|
2018-12-31 18:54:33 +00:00
|
|
|
palette.Colors[i] = math.Color3b{R: color.R, G: color.G, B: color.B}
|
2018-12-17 23:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return palette, nil
|
2018-12-16 22:09:18 +00:00
|
|
|
}
|
2018-12-30 02:21:33 +00:00
|
|
|
|
2019-01-09 02:45:19 +00:00
|
|
|
func NewFromGrayscale() *Palette {
|
|
|
|
palette := new(Palette)
|
2018-12-30 02:21:33 +00:00
|
|
|
for i := 0; i < 256; i++ {
|
|
|
|
value := uint8(i)
|
2018-12-31 18:54:33 +00:00
|
|
|
palette.Colors[i] = math.Color3b{R: value, G: value, B: value}
|
2018-12-30 02:21:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return palette
|
|
|
|
}
|