1#![allow(dead_code)]
3#![allow(non_upper_case_globals)]
4use core::fmt;
5
6#[derive(Clone, Copy, PartialEq, Eq, Hash)]
7pub struct ChunkType(pub [u8; 4]);
8
9pub const IHDR: ChunkType = ChunkType(*b"IHDR");
13pub const PLTE: ChunkType = ChunkType(*b"PLTE");
15pub const IDAT: ChunkType = ChunkType(*b"IDAT");
17pub const IEND: ChunkType = ChunkType(*b"IEND");
19
20pub const tRNS: ChunkType = ChunkType(*b"tRNS");
24pub const bKGD: ChunkType = ChunkType(*b"bKGD");
26pub const tIME: ChunkType = ChunkType(*b"tIME");
28pub const pHYs: ChunkType = ChunkType(*b"pHYs");
30pub const cHRM: ChunkType = ChunkType(*b"cHRM");
32pub const gAMA: ChunkType = ChunkType(*b"gAMA");
34pub const sRGB: ChunkType = ChunkType(*b"sRGB");
36pub const iCCP: ChunkType = ChunkType(*b"iCCP");
38pub const cICP: ChunkType = ChunkType(*b"cICP");
40pub const mDCV: ChunkType = ChunkType(*b"mDCV");
42pub const cLLI: ChunkType = ChunkType(*b"cLLI");
44pub const eXIf: ChunkType = ChunkType(*b"eXIf");
46pub const tEXt: ChunkType = ChunkType(*b"tEXt");
48pub const zTXt: ChunkType = ChunkType(*b"zTXt");
50pub const iTXt: ChunkType = ChunkType(*b"iTXt");
52pub const sBIT: ChunkType = ChunkType(*b"sBIT");
54
55pub const acTL: ChunkType = ChunkType(*b"acTL");
59pub const fcTL: ChunkType = ChunkType(*b"fcTL");
61pub const fdAT: ChunkType = ChunkType(*b"fdAT");
63
64pub fn is_critical(ChunkType(type_): ChunkType) -> bool {
68 type_[0] & 32 == 0
69}
70
71pub fn is_private(ChunkType(type_): ChunkType) -> bool {
73 type_[1] & 32 != 0
74}
75
76pub fn reserved_set(ChunkType(type_): ChunkType) -> bool {
79 type_[2] & 32 != 0
80}
81
82pub fn safe_to_copy(ChunkType(type_): ChunkType) -> bool {
84 type_[3] & 32 != 0
85}
86
87impl fmt::Debug for ChunkType {
88 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89 struct DebugType([u8; 4]);
90
91 impl fmt::Debug for DebugType {
92 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
93 for &c in &self.0[..] {
94 write!(f, "{}", char::from(c).escape_debug())?;
95 }
96 Ok(())
97 }
98 }
99
100 f.debug_struct("ChunkType")
101 .field("type", &DebugType(self.0))
102 .field("critical", &is_critical(*self))
103 .field("private", &is_private(*self))
104 .field("reserved", &reserved_set(*self))
105 .field("safecopy", &safe_to_copy(*self))
106 .finish()
107 }
108}