Documentation
¶
Overview ¶
Package pal implements reading and writing of Total Annihilation .PAL palette files.
A TA palette is a fixed 1024-byte blob: 256 entries of 4 bytes each, laid out as R, G, B, A in little-endian order. The alpha byte is unused by the game (always 0 in Cavedog's files) and color index 0 acts as transparent.
The same on-disk layout is also reused for the .ALP shadow-alpha, .LHT light and .SHD shadow lookup tables — they are 1024-byte index→index mappings, not RGB palettes, so this package treats them as raw byte tables when asked.
Index ¶
- Constants
- func LoadLookupFromFile(path string) ([]byte, error)
- func LoadLookupFromReader(r io.Reader) ([]byte, error)
- func RenderLookupSwatch(table []byte, palette *Palette, cellSize int) (*image.RGBA, error)
- func WritePNG(w io.Writer, img image.Image) error
- type Palette
- func (p *Palette) ColorModel() color.Palette
- func (p *Palette) Equals(other *Palette) bool
- func (p *Palette) Histogram() (unique int, duplicates int)
- func (p *Palette) IsLikelyTAPalette() bool
- func (p *Palette) RenderSwatch(cellSize int) *image.RGBA
- func (p *Palette) Write(w io.Writer) error
- func (p *Palette) WriteGPL(w io.Writer, name string) error
- func (p *Palette) WriteJASC(w io.Writer) error
Constants ¶
const EntryCount = 256
EntryCount is the number of color entries in a TA palette (always 256).
const FileSize = EntryCount * 4
FileSize is the on-disk size in bytes of a TA palette file (256 × 4).
Variables ¶
This section is empty.
Functions ¶
func LoadLookupFromFile ¶
LoadLookupFromFile is the file-path equivalent of LoadLookupFromReader.
func LoadLookupFromReader ¶
LoadLookupFromReader parses a 1024-byte color-index lookup table (.ALP, .LHT or .SHD). These files share the .PAL size but each byte is an index into the main palette rather than a color channel.
The returned slice has length FileSize and is the raw file bytes — readers that need the table as a 256×4 grid (the canonical ALP/LHT layout) can index directly.
func RenderLookupSwatch ¶
RenderLookupSwatch renders a 1024-byte color-index lookup table as a 256×4 grid of cellSize×cellSize squares using the given palette for the index→RGB mapping. Returns an RGBA image of size 256*cellSize × 4*cellSize. Suitable for .ALP/.LHT/.SHD which are all 256×4 index tables.
Types ¶
type Palette ¶
type Palette struct {
Colors [EntryCount]color.RGBA
Raw []byte
}
Palette is a parsed TA .PAL file. The Raw slice keeps the original bytes so callers that care about the unused alpha byte (or want to round-trip the file byte-for-byte) can recover it.
func LoadFromBytes ¶
LoadFromBytes parses a .PAL file from a byte slice.
func LoadFromFile ¶
LoadFromFile parses a .PAL file at path.
func LoadFromReader ¶
LoadFromReader parses a .PAL file from r.
Color index 0 is reported with alpha=0 to match how every other kbot loader treats the TA palette (the engine uses index 0 as the transparent sentinel). All other entries are returned fully opaque.
func (*Palette) ColorModel ¶
ColorModel returns the palette as a Go image/color Palette.
func (*Palette) Equals ¶
Equals reports whether two palettes have the same RGB values (alpha is ignored because color index 0 always carries the transparent override).
func (*Palette) Histogram ¶
Histogram returns a summary of how many distinct RGB triples the palette contains. Index 0 is excluded because it is the transparent sentinel. The result is useful when comparing palettes since Cavedog's defaults reserve certain ranges for team colors and shadows.
func (*Palette) IsLikelyTAPalette ¶
IsLikelyTAPalette returns true if the file's alpha bytes are all zero, which is the case for Cavedog-shipped TA palettes (and a common sanity check).
func (*Palette) RenderSwatch ¶
RenderSwatch renders the 256 entries as a 16×16 grid of cellSize×cellSize squares. cellSize<=0 defaults to 16 (256×256 image).
func (*Palette) Write ¶
Write encodes p back to a .PAL file. When Raw is set (e.g. for a palette loaded with LoadFromReader) the original bytes are emitted verbatim so any unused alpha bytes are preserved. Otherwise the alpha byte for every entry is zero — matching Cavedog's files.