lazarus/formats/dat/dat.go

43 lines
727 B
Go
Raw Normal View History

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-01 18:30:35 +00:00
type DatPalette struct {
2018-12-31 18:54:33 +00:00
Colors [256]math.Color3b
}
type color struct {
B byte
G byte
R byte
2018-12-16 22:09:18 +00:00
}
2019-01-01 18:30:35 +00:00
func NewFromReader(reader io.Reader) (*DatPalette, 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
}
2019-01-01 18:30:35 +00:00
palette := new(DatPalette)
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}
}
return palette, nil
2018-12-16 22:09:18 +00:00
}
2019-01-01 18:30:35 +00:00
func NewFromGrayscale() *DatPalette {
palette := new(DatPalette)
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}
}
return palette
}