← back to roto on ba3a.dev

PaletteCodec

Reads a Palette from the two plain-text formats pixel artists share palettes in, told apart by the file's extension, and writes one as .hex:

  • .gpl, the GIMP palette: a GIMP Palette first line, optional Name:, Columns: and Channels: headers and # comments, then one red green blue [name] line per colour — or red green blue alpha [name] under Channels: RGBA, where every alpha must be 255;

  • .hex, one rrggbb per line, with or without a leading #, as Lospec exports it.

Entry names are not kept. Anything else is a PaletteFormatException naming the line; Roto only reads .gpl, and writes only .hex.

Functions

Link copied to clipboard
fun read(path: Path): Palette

The palette in path, read as .gpl or .hex by its extension.

Link copied to clipboard

The palette in input, a .gpl file; input is read to its end but not closed.

Link copied to clipboard

The palette in input, a .hex file; input is read to its end but not closed.

Link copied to clipboard
fun write(palette: Palette, path: Path)

Writes palette to path as .hex: one lower-case #rrggbb per line, UTF-8, \n endings, through AtomicFile. Any other extension is a PaletteFormatException.

Link copied to clipboard
fun writeHex(palette: Palette, output: OutputStream)

Writes palette to output as .hex text, as write does; output is not closed.