43 lines
712 B
Go
Raw Normal View History

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