|
|
@ -6,13 +6,17 @@ import ( |
|
|
|
"image/color" |
|
|
|
"io" |
|
|
|
"io/ioutil" |
|
|
|
"math/bits" |
|
|
|
"os" |
|
|
|
) |
|
|
|
|
|
|
|
// RGB24 is a color with 8-bit red, green and blue channels.
|
|
|
|
type RGB24 struct { |
|
|
|
R, G, B uint8 |
|
|
|
} |
|
|
|
|
|
|
|
// RGBA returns the alpha-premultiplied red, green, blue and alpha values
|
|
|
|
// for the color.
|
|
|
|
func (c RGB24) RGBA() (r, g, b, a uint32) { |
|
|
|
r = uint32(c.R) | uint32(c.R)<<8 |
|
|
|
g = uint32(c.G) | uint32(c.G)<<8 |
|
|
@ -21,7 +25,8 @@ func (c RGB24) RGBA() (r, g, b, a uint32) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func readRGB24(r io.Reader) (RGB24, error) { |
|
|
|
// DecodeRGB24 decodes one RGB24 color from the supplied Reader.
|
|
|
|
func DecodeRGB24(r io.Reader) (RGB24, error) { |
|
|
|
var c RGB24 |
|
|
|
if err := binary.Read(r, binary.BigEndian, &c); err != nil { |
|
|
|
return c, err |
|
|
@ -29,9 +34,17 @@ func readRGB24(r io.Reader) (RGB24, error) { |
|
|
|
return c, nil |
|
|
|
} |
|
|
|
|
|
|
|
type RGBA4Bit uint16 |
|
|
|
// RGBA16 is a color with 4-bit red, green, blue and alpha channels.
|
|
|
|
type RGBA16 uint16 |
|
|
|
|
|
|
|
func (c RGBA4Bit) RGBA() (r, g, b, a uint32) { |
|
|
|
// ByteSwap swaps the endianness of the color.
|
|
|
|
func (c *RGBA16) ByteSwap() { |
|
|
|
*c = RGBA16(bits.Reverse16(uint16(*c))) |
|
|
|
} |
|
|
|
|
|
|
|
// RGBA returns the alpha-premultiplied red, green, blue and alpha values
|
|
|
|
// for the color.
|
|
|
|
func (c RGBA16) RGBA() (r, g, b, a uint32) { |
|
|
|
r = uint32((c&0xf000)>>12) * 0x1111 |
|
|
|
g = uint32((c&0x0f00)>>8) * 0x1111 |
|
|
|
b = uint32((c&0x00f0)>>4) * 0x1111 |
|
|
@ -39,6 +52,15 @@ func (c RGBA4Bit) RGBA() (r, g, b, a uint32) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// DecodeRGBA16 decodes one RGBA16 color from the supplied Reader.
|
|
|
|
func DecodeRGBA16(r io.Reader, byteOrder binary.ByteOrder) (RGBA16, error) { |
|
|
|
var c RGBA16 |
|
|
|
if err := binary.Read(r, byteOrder, &c); err != nil { |
|
|
|
return c, err |
|
|
|
} |
|
|
|
return c, nil |
|
|
|
} |
|
|
|
|
|
|
|
// Pin2DMDColoring contains a coloring description.
|
|
|
|
type Pin2DMDColoring struct { |
|
|
|
Version uint8 |
|
|
@ -140,17 +162,18 @@ func (c *Pin2DMDColoring) FindMapping(p *Plane, reverse bool) *Mapping { |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
// LoadPin2DMDColoring loads *.pal files.
|
|
|
|
// LoadPin2DMDColoring loads *.pal Pin2DMD colorization files.
|
|
|
|
func LoadPin2DMDColoring(name string) (*Pin2DMDColoring, error) { |
|
|
|
f, err := os.Open(name) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
defer func() { _ = f.Close() }() |
|
|
|
return ReadPin2DMDColoring(f) |
|
|
|
return DecodePin2DMDColoring(f) |
|
|
|
} |
|
|
|
|
|
|
|
func ReadPin2DMDColoring(r io.Reader) (c *Pin2DMDColoring, err error) { |
|
|
|
// DecodePin2DMDColoring decodes palette mappings from the supplied Reader.
|
|
|
|
func DecodePin2DMDColoring(r io.Reader) (c *Pin2DMDColoring, err error) { |
|
|
|
c = new(Pin2DMDColoring) |
|
|
|
if err = binary.Read(r, binary.BigEndian, &c.Version); err != nil { |
|
|
|
return |
|
|
@ -204,7 +227,7 @@ func ReadPalette(r io.Reader) (p *Palette, err error) { |
|
|
|
A: 0xff, |
|
|
|
} |
|
|
|
/* |
|
|
|
if p.Colors[i], err = readRGB24(r); err != nil { |
|
|
|
if p.Colors[i], err = DecodeRGB24(r); err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
*/ |
|
|
|