2 releases
0.1.1 | May 18, 2020 |
---|---|
0.1.0 | Aug 4, 2019 |
#44 in #palette
Used in 3 crates
(2 directly)
12KB
281 lines
JASC Palette file reader/writer.
Parses and stringifes palette files containing any number of colours.
JASC palette files follow a simple format:
JASC-PAL
0100
$num_colors
$rgb...
Colours are represented using the rgb
crate.
Example
use std::io::Cursor;
use jascpal::{Palette, PaletteIndex, Color};
let cursor = Cursor::new(b"JASC-PAL\r\n0100\r\n2\r\n0 0 0\r\n255 255 255\r\n".to_vec());
let pal = Palette::read_from(cursor).unwrap();
assert_eq!(pal[PaletteIndex::from(0)], Color { r: 0, g: 0, b: 0 });
assert_eq!(pal[PaletteIndex::from(1)], Color { r: 255, g: 255, b: 255 });
let mut pal = pal;
pal[PaletteIndex::from(1)] = Color { r: 0, g: 255, b: 255 };
pal.add(Color { r: 255, g: 0, b: 0 });
assert_eq!(
pal.to_string(),
"JASC-PAL\r\n0100\r\n3\r\n0 0 0\r\n0 255 255\r\n255 0 0\r\n".to_string()
);
Dependencies
~1.2–1.8MB
~37K SLoC