png/
chunk.rs

1//! Chunk types and functions
2#![allow(dead_code)]
3#![allow(non_upper_case_globals)]
4
5pub type ChunkType = [u8; 4];
6
7// -- Critical chunks --
8
9/// Image header
10pub const IHDR: ChunkType = [b'I', b'H', b'D', b'R'];
11/// Palette
12pub const PLTE: ChunkType = [b'P', b'L', b'T', b'E'];
13/// Image data
14pub const IDAT: ChunkType = [b'I', b'D', b'A', b'T'];
15/// Image trailer
16pub const IEND: ChunkType = [b'I', b'E', b'N', b'D'];
17
18// -- Ancillary chunks --
19
20/// Transparency
21pub const tRNS: ChunkType = [b't', b'R', b'N', b'S'];
22/// Background colour
23pub const bKGD: ChunkType = [b'b', b'K', b'G', b'D'];
24/// Image last-modification time
25pub const tIME: ChunkType = [b't', b'I', b'M', b'E'];
26/// Physical pixel dimensions
27pub const pHYs: ChunkType = [b'p', b'H', b'Y', b's'];
28
29// -- Extension chunks --
30
31/// Animation control
32pub const acTL: ChunkType = [b'a', b'c', b'T', b'L'];
33/// Frame control
34pub const fcTL: ChunkType = [b'f', b'c', b'T', b'L'];
35/// Frame data
36pub const fdAT: ChunkType = [b'f', b'd', b'A', b'T'];
37
38// -- Chunk type determination --
39
40/// Returns true if the chunk is critical.
41pub fn is_critical(type_: ChunkType) -> bool {
42    type_[0] & 32 == 0
43}
44
45/// Returns true if the chunk is private.
46pub fn is_private(type_: ChunkType) -> bool {
47    type_[1] & 32 != 0
48}
49
50/// Checks whether the reserved bit of the chunk name is set.
51/// If it is set the chunk name is invalid.
52pub fn reserved_set(type_: ChunkType) -> bool {
53    type_[2] & 32 != 0
54}
55
56/// Returns true if the chunk is safe to copy if unknown.
57pub fn safe_to_copy(type_: ChunkType) -> bool {
58    type_[3] & 32 != 0
59}