1use std::fmt::{self, Debug, Formatter};
2
3
4
5#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct RGBA(pub u32);
7impl Debug for RGBA { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { write!(fmt, "#{:08x}", self.0) } }
8
9#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum AseColorFormat {
11 Rgba,
12 Greyscale,
13 Indexed,
14
15 #[doc(hidden)] _NonExhaustive,
16}
17
18#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum PngColorProfile {
20 None,
21 SRGB,
22 Other,
23
24 #[doc(hidden)] _NonExhaustive,
25}
26
27
28
29#[derive(Clone, Copy)] pub struct FileSet {
31 pub version: &'static str,
32 pub name: &'static str,
33
34 pub src_aseprite: &'static [u8],
35 pub array_json: &'static [u8],
36 pub basic_json: &'static [u8],
37 pub hash_json: &'static [u8],
38 pub array_png: &'static [u8],
39 pub basic_png: &'static [u8],
40 pub hash_png: &'static [u8],
41
42 pub ase_color_format: AseColorFormat, pub png_color_profile: PngColorProfile,
44 pub size: [u32; 2],
45 pub pixel: [u8; 2],
46 pub pixels: Option<&'static [RGBA]>,
47 pub palette: &'static [RGBA],
48
49 pub n_frames: usize,
50 pub n_layers: usize,
51 pub n_slices: usize,
52 pub n_frametags: usize,
53
54 _non_exhaustive: ()
55}
56
57impl Default for FileSet {
58 fn default() -> Self {
59 Self {
60 version: "",
61 name: "",
62
63 src_aseprite: &[],
64 array_json: &[],
65 basic_json: &[],
66 hash_json: &[],
67 array_png: &[],
68 basic_png: &[],
69 hash_png: &[],
70
71 ase_color_format: AseColorFormat::Rgba,
72 png_color_profile: PngColorProfile::SRGB,
73 size: [1,1],
74 pixel: [1,1],
75 pixels: Some(&[RGBA(0x00000000)]),
76 palette: ARNE32,
77
78 n_frames: 1,
79 n_layers: 1,
80 n_slices: 0,
81 n_frametags: 0,
82
83 _non_exhaustive: ()
84 }
85 }
86}
87
88macro_rules! fileset {
89 ($ver:literal, $name:literal, $($tt:tt)*) => {
90 FileSet {
91 version: $ver,
92 name: $name,
93
94 src_aseprite: include_bytes!(concat!("data/", $ver, "/_src/", $name)),
95
96 array_json: include_bytes!(concat!("data/", $ver, "/array/", $name, ".json")),
97 basic_json: include_bytes!(concat!("data/", $ver, "/basic/", $name, ".json")),
98 hash_json: include_bytes!(concat!("data/", $ver, "/hash/", $name, ".json")),
99
100 array_png: include_bytes!(concat!("data/", $ver, "/array/", $name, ".png")),
101 basic_png: include_bytes!(concat!("data/", $ver, "/basic/", $name, ".png")),
102 hash_png: include_bytes!(concat!("data/", $ver, "/hash/", $name, ".png")),
103
104 $($tt)*,
105
106 .. FileSet::default()
107 }
108 };
109}
110
111impl FileSet {
112 pub fn complex_1_2_25() -> Self { fileset! { "1.2.25", "complex.aseprite", n_frames: 9, n_layers: 25, n_slices: 3, n_frametags: 6, size: [8,8], pixels: None } }
113
114 pub fn list() -> impl Iterator<Item = FileSet> + 'static {
115 vec![
116 fileset! { "1.2.25", "basic-grey-1x1-black.aseprite", ase_color_format: AseColorFormat::Greyscale, pixels: Some(&[RGBA(0x000000FF)]) },
117 fileset! { "1.2.25", "basic-grey-1x1-white.aseprite", ase_color_format: AseColorFormat::Greyscale, pixels: Some(&[RGBA(0xFFFFFFFF)]) },
118
119 fileset! { "1.2.25", "basic-indexed-1x1-transparent.aseprite", ase_color_format: AseColorFormat::Indexed, pixels: Some(&[RGBA(0x00000000)]) },
120 fileset! { "1.2.25", "basic-indexed-1x1-green.aseprite", ase_color_format: AseColorFormat::Indexed, pixels: Some(&[RGBA(0xA3CE27FF)]) },
121
122 fileset! { "1.2.25", "basic-rgba-1x1-empty.aseprite", pixels: Some(&[RGBA(0x00000000)]) },
123 fileset! { "1.2.25", "basic-rgba-1x1-green-none.aseprite", pixels: Some(&[RGBA(0xA3CE27FF)]), png_color_profile: PngColorProfile::SRGB }, fileset! { "1.2.25", "basic-rgba-1x1-green-srgb.aseprite", pixels: Some(&[RGBA(0xA3CE27FF)]), png_color_profile: PngColorProfile::SRGB },
125 fileset! { "1.2.25", "basic-rgba-1x1-green-monitor1.aseprite", pixels: Some(&[RGBA(0xA3CE27FF)]), png_color_profile: PngColorProfile::Other },
126 fileset! { "1.2.25", "basic-rgba-1x1-transparent-square.aseprite", pixel: [1,1] },
127 fileset! { "1.2.25", "basic-rgba-1x1-transparent-tall.aseprite", pixel: [1,2] },
128 fileset! { "1.2.25", "basic-rgba-1x1-transparent-wide.aseprite", pixel: [2,1] },
129 fileset! { "1.2.25", "basic-rgba-1x1-transparent.aseprite", pixel: [1,1] },
130
131 Self::complex_1_2_25(),
132 ].into_iter()
133 }
134}
135
136const ARNE32 : &'static [RGBA] = &[
137 RGBA(0x00000000), RGBA(0x9D9D9DFF), RGBA(0xFFFFFFFF), RGBA(0xBE2633FF), RGBA(0xE06F8BFF), RGBA(0x493C2BFF), RGBA(0xA46422FF), RGBA(0xEB8931FF),
138 RGBA(0xF7E26BFF), RGBA(0x2F484EFF), RGBA(0x44891AFF), RGBA(0xA3CE27FF), RGBA(0x1B2632FF), RGBA(0x005784FF), RGBA(0x31A2F2FF), RGBA(0xB2DCEFFF),
139 RGBA(0x342A97FF), RGBA(0x656D71FF), RGBA(0xCCCCCCFF), RGBA(0x732930FF), RGBA(0xCB43A7FF), RGBA(0x524F40FF), RGBA(0xAD9D33FF), RGBA(0xEC4700FF),
140 RGBA(0xFAB40BFF), RGBA(0x115E33FF), RGBA(0x14807EFF), RGBA(0x15C2A5FF), RGBA(0x225AF6FF), RGBA(0x9964F9FF), RGBA(0xF78ED6FF), RGBA(0xF4B990FF),
141];