Debian Codegraph @

.cargo/vendor/png/src/chunk.rs

raw
1 //! Chunk types and functions
2 #![allow(dead_code)]
3 #![allow(non_upper_case_globals)]
4 use core::fmt;
5
6 #[derive(Clone, Copy, PartialEq, Eq, Hash)]
7 pub struct ChunkType(pub [u8; 4]);
8
9 // -- Critical chunks --
10
11 /// Image header
12 pub const IHDR: ChunkType = ChunkType(*b"IHDR");
13 /// Palette
14 pub const PLTE: ChunkType = ChunkType(*b"PLTE");
15 /// Image data
16 pub const IDAT: ChunkType = ChunkType(*b"IDAT");
17 /// Image trailer
18 pub const IEND: ChunkType = ChunkType(*b"IEND");
19
20 // -- Ancillary chunks --
21
22 /// Transparency
23 pub const tRNS: ChunkType = ChunkType(*b"tRNS");
24 /// Background colour
25 pub const bKGD: ChunkType = ChunkType(*b"bKGD");
26 /// Image last-modification time
27 pub const tIME: ChunkType = ChunkType(*b"tIME");
28 /// Physical pixel dimensions
29 pub const pHYs: ChunkType = ChunkType(*b"pHYs");
30 /// Source system's pixel chromaticities
31 pub const cHRM: ChunkType = ChunkType(*b"cHRM");
32 /// Source system's gamma value
33 pub const gAMA: ChunkType = ChunkType(*b"gAMA");
34 /// sRGB color space chunk
35 pub const sRGB: ChunkType = ChunkType(*b"sRGB");
36 /// ICC profile chunk
37 pub const iCCP: ChunkType = ChunkType(*b"iCCP");
38 /// Coding-independent code points for video signal type identification chunk
39 pub const cICP: ChunkType = ChunkType(*b"cICP");
40 /// Mastering Display Color Volume chunk
41 pub const mDCV: ChunkType = ChunkType(*b"mDCV");
42 /// Content Light Level Information chunk
43 pub const cLLI: ChunkType = ChunkType(*b"cLLI");
44 /// EXIF metadata chunk
45 pub const eXIf: ChunkType = ChunkType(*b"eXIf");
46 /// Latin-1 uncompressed textual data
47 pub const tEXt: ChunkType = ChunkType(*b"tEXt");
48 /// Latin-1 compressed textual data
49 pub const zTXt: ChunkType = ChunkType(*b"zTXt");
50 /// UTF-8 textual data
51 pub const iTXt: ChunkType = ChunkType(*b"iTXt");
52 // Significant bits
53 pub const sBIT: ChunkType = ChunkType(*b"sBIT");
54
55 // -- Extension chunks --
56
57 /// Animation control
58 pub const acTL: ChunkType = ChunkType(*b"acTL");
59 /// Frame control
60 pub const fcTL: ChunkType = ChunkType(*b"fcTL");
61 /// Frame data
62 pub const fdAT: ChunkType = ChunkType(*b"fdAT");
63
64 // -- Chunk type determination --
65
66 /// Returns true if the chunk is critical.
67 pub fn is_critical(ChunkType(type_): ChunkType) -> bool {
68 type_[0] & 32 == 0
69 }
70
71 /// Returns true if the chunk is private.
72 pub fn is_private(ChunkType(type_): ChunkType) -> bool {
73 type_[1] & 32 != 0
74 }
75
76 /// Checks whether the reserved bit of the chunk name is set.
77 /// If it is set the chunk name is invalid.
78 pub fn reserved_set(ChunkType(type_): ChunkType) -> bool {
79 type_[2] & 32 != 0
80 }
81
82 /// Returns true if the chunk is safe to copy if unknown.
83 pub fn safe_to_copy(ChunkType(type_): ChunkType) -> bool {
84 type_[3] & 32 != 0
85 }
86
87 impl 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 }