icns_rs/
formats.rs

1#[doc(hidden)]
2#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
3pub enum FileFormat {
4    RGB,
5    ARGB,
6    MASK,
7    PNG,
8}
9
10/// # ICNS Types
11/// These are the types of icons that can be stored in an ICNS file.
12/// Not all of them are included, but the most common ones are.
13/// The full list can be found at Wikipedia
14/// https://en.wikipedia.org/wiki/Apple_Icon_Image_format#Icon_types
15#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
16pub enum IconFormats {
17    /// - OSName: is32
18    /// - Size: 16x16
19    /// - Format: 24-bit RGB icon
20    /// - OS: System 8.5+
21    IS32,
22    /// - OSName: il32
23    /// - Size: 32x32
24    /// - Format: 24-bit RGB icon
25    /// - OS: System 8.5+
26    IL32,
27    /// - OSName: ih32
28    /// - Size: 48x48
29    /// - Format: 24-bit RGB icon
30    /// - OS: System 8.5+
31    IH32,
32    /// - OSName: it32
33    /// - Size: 128x128
34    /// - Format: 24-bit RGB icon
35    /// - OS: Mac OS X 10.0+
36    IT32,
37    /// - OSName: s8mk
38    /// - Size: 16x12
39    /// - Format: 8-bit mask
40    /// - OS: System 8.5+
41    S8MK,
42    /// - OSName: l8mk
43    /// - Size: 32x32
44    /// - Format: 8-bit mask
45    /// - OS: System 8.5+
46    L8MK,
47    /// - OSName: h8mk
48    /// - Size: 48x48
49    /// - Format: 8-bit mask
50    /// - OS: System 8.5+
51    H8MK,
52    /// - OSName: t8mk
53    /// - Size: 128x128
54    /// - Format: 8-bit mask
55    /// - OS: Mac OS X 10.0+
56    T8MK,
57    /// - OSName: ic04
58    /// - Size: 16x16
59    /// - Format: ARGB
60    /// - OS: N/A
61    IC04,
62    /// - OSName: ic05
63    /// - Size: 32x32
64    /// - Format: ARGB
65    /// - OS: N/A
66    IC05,
67    /// - OSName: ic07
68    /// - Size: 128x128
69    /// - Format: PNG
70    /// - OS: Mac OS X 10.7+
71    IC07,
72    /// - OSName: ic08
73    /// - Size: 256x256
74    /// - Format: PNG
75    /// - OS: Mac OS X 10.5+
76    IC08,
77    /// - OSName: ic09
78    /// - Size: 512x512
79    /// - Format: PNG
80    /// - OS: Mac OS X 10.5+
81    IC09,
82    /// - OSName: ic10
83    /// - Size: 1024x1024
84    /// - Format: PNG
85    /// - OS: Mac OS X 10.7+
86    IC10,
87    /// - OSName: ic11
88    /// - Size: 32x32
89    /// - Format: PNG
90    /// - OS: Mac OS X 10.8+
91    IC11,
92    /// - OSName: ic12
93    /// - Size: 64x64
94    /// - Format: PNG
95    /// - OS: Mac OS X 10.8+
96    IC12,
97    /// - OSName: ic13
98    /// - Size: 256x256
99    /// - Format: PNG
100    /// - OS: Mac OS X 10.8+
101    IC13,
102    /// - OSName: ic14
103    /// - Size: 512x512
104    /// - Format: PNG
105    /// - OS: Mac OS X 10.8+
106    IC14,
107    /// - OSName: icp4
108    /// - Size: 16x16
109    /// - Format: PNG
110    /// - OS: Mac OS X 10.7+
111    ICP4,
112    /// - OSName: icp5
113    /// - Size: 32x32
114    /// - Format: PNG
115    /// - OS: Mac OS X 10.7+
116    ICP5,
117    /// - OSName: icp6
118    /// - Size: 64x64
119    /// - Format: PNG
120    /// - OS: Mac OS X 10.7+
121    ICP6,
122}
123
124impl IconFormats {
125    /// Get the default recommended format for the icon type.
126    pub fn recommended() -> Vec<IconFormats> {
127        vec![
128            IconFormats::IS32,
129            IconFormats::IL32,
130            IconFormats::IH32,
131            IconFormats::IT32,
132            IconFormats::S8MK,
133            IconFormats::L8MK,
134            IconFormats::H8MK,
135            IconFormats::T8MK,
136            IconFormats::IC04,
137            IconFormats::IC05,
138            IconFormats::IC07,
139            IconFormats::IC08,
140            IconFormats::IC09,
141            IconFormats::IC10,
142            IconFormats::IC11,
143            IconFormats::IC12,
144            IconFormats::IC13,
145            IconFormats::IC14,
146        ]
147    }
148
149    pub fn get_format(&self) -> FileFormat {
150        match self {
151            IconFormats::IS32 => FileFormat::RGB,
152            IconFormats::IL32 => FileFormat::RGB,
153            IconFormats::IH32 => FileFormat::RGB,
154            IconFormats::IT32 => FileFormat::RGB,
155            IconFormats::S8MK => FileFormat::MASK,
156            IconFormats::L8MK => FileFormat::MASK,
157            IconFormats::H8MK => FileFormat::MASK,
158            IconFormats::T8MK => FileFormat::MASK,
159            IconFormats::IC04 => FileFormat::ARGB,
160            IconFormats::IC05 => FileFormat::ARGB,
161            IconFormats::IC07 => FileFormat::PNG,
162            IconFormats::IC08 => FileFormat::PNG,
163            IconFormats::IC09 => FileFormat::PNG,
164            IconFormats::IC10 => FileFormat::PNG,
165            IconFormats::IC11 => FileFormat::PNG,
166            IconFormats::IC12 => FileFormat::PNG,
167            IconFormats::IC13 => FileFormat::PNG,
168            IconFormats::IC14 => FileFormat::PNG,
169            IconFormats::ICP4 => FileFormat::PNG,
170            IconFormats::ICP5 => FileFormat::PNG,
171            IconFormats::ICP6 => FileFormat::PNG,
172        }
173    }
174
175    pub fn get_size(&self) -> usize {
176        match self {
177            IconFormats::IS32 => 16,
178            IconFormats::IL32 => 32,
179            IconFormats::IH32 => 48,
180            IconFormats::IT32 => 128,
181            IconFormats::S8MK => 16,
182            IconFormats::L8MK => 32,
183            IconFormats::H8MK => 48,
184            IconFormats::T8MK => 128,
185            IconFormats::IC04 => 16,
186            IconFormats::IC05 => 32,
187            IconFormats::IC07 => 128,
188            IconFormats::IC08 => 256,
189            IconFormats::IC09 => 512,
190            IconFormats::IC10 => 1024,
191            IconFormats::IC11 => 32,
192            IconFormats::IC12 => 64,
193            IconFormats::IC13 => 256,
194            IconFormats::IC14 => 512,
195            IconFormats::ICP4 => 16,
196            IconFormats::ICP5 => 32,
197            IconFormats::ICP6 => 64,
198        }
199    }
200
201    pub fn get_bytes(&self) -> [u8; 4] {
202        match self {
203            IconFormats::IS32 => [0x69, 0x73, 0x33, 0x32], //is32
204            IconFormats::IL32 => [0x69, 0x6c, 0x33, 0x32], //il32
205            IconFormats::IH32 => [0x69, 0x68, 0x33, 0x32], //ih32
206            IconFormats::IT32 => [0x69, 0x74, 0x33, 0x32], //it32
207            IconFormats::S8MK => [0x73, 0x38, 0x6d, 0x6b], //s8mk
208            IconFormats::L8MK => [0x6c, 0x38, 0x6d, 0x6b], //l8mk
209            IconFormats::H8MK => [0x68, 0x38, 0x6d, 0x6b], //h8mk
210            IconFormats::T8MK => [0x74, 0x38, 0x6d, 0x6b], //t8mk
211            IconFormats::IC04 => [0x69, 0x63, 0x30, 0x34], //ic04
212            IconFormats::IC05 => [0x69, 0x63, 0x30, 0x35], //ic05
213            IconFormats::IC07 => [0x69, 0x63, 0x30, 0x37], //ic07
214            IconFormats::IC08 => [0x69, 0x63, 0x30, 0x38], //ic08
215            IconFormats::IC09 => [0x69, 0x63, 0x30, 0x39], //ic09
216            IconFormats::IC10 => [0x69, 0x63, 0x31, 0x30], //ic10
217            IconFormats::IC11 => [0x69, 0x63, 0x31, 0x31], //ic11
218            IconFormats::IC12 => [0x69, 0x63, 0x31, 0x32], //ic12
219            IconFormats::IC13 => [0x69, 0x63, 0x31, 0x33], //ic13
220            IconFormats::IC14 => [0x69, 0x63, 0x31, 0x34], //ic14
221            IconFormats::ICP4 => [0x69, 0x63, 0x70, 0x34], //icp4
222            IconFormats::ICP5 => [0x69, 0x63, 0x70, 0x35], //icp5
223            IconFormats::ICP6 => [0x69, 0x63, 0x70, 0x36], //icp6
224        }
225    }
226}