aseprite_loader/binary/chunks/
old_palette.rs1use nom::multi::count;
2
3use crate::binary::{
4 errors::ParseResult,
5 scalars::{byte, parse_rgb, word, Byte, RGB},
6};
7
8#[derive(Debug)]
9pub struct OldPaletteChunk {
18 pub packets: Vec<Packet>,
19}
20
21#[derive(Debug)]
22pub struct Packet {
23 pub entries_to_skip: Byte,
24 pub colors: Vec<RGB>,
25}
26
27pub fn parse_old_palette_chunk(input: &[u8]) -> ParseResult<'_, OldPaletteChunk> {
28 let (input, number_of_packets) = word(input)?;
29 let (input, packets) = count(parse_packet, number_of_packets.into())(input)?;
30 Ok((input, OldPaletteChunk { packets }))
31}
32
33pub fn parse_packet(input: &[u8]) -> ParseResult<'_, Packet> {
34 let (input, entries_to_skip) = byte(input)?;
35 let (input, number_of_colors) = byte(input)?;
36 let number_of_colors = if number_of_colors == 0 {
37 256usize
38 } else {
39 number_of_colors.into()
40 };
41 let (input, colors) = count(parse_rgb, number_of_colors)(input)?;
42 Ok((
43 input,
44 Packet {
45 entries_to_skip,
46 colors,
47 },
48 ))
49}