summaryrefslogtreecommitdiff
path: root/vendor/png/src/chunk.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/png/src/chunk.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/png/src/chunk.rs')
-rw-r--r--vendor/png/src/chunk.rs98
1 files changed, 98 insertions, 0 deletions
diff --git a/vendor/png/src/chunk.rs b/vendor/png/src/chunk.rs
new file mode 100644
index 0000000..39578a4
--- /dev/null
+++ b/vendor/png/src/chunk.rs
@@ -0,0 +1,98 @@
+//! Chunk types and functions
+#![allow(dead_code)]
+#![allow(non_upper_case_globals)]
+use core::fmt;
+
+#[derive(Clone, Copy, PartialEq, Eq, Hash)]
+pub struct ChunkType(pub [u8; 4]);
+
+// -- Critical chunks --
+
+/// Image header
+pub const IHDR: ChunkType = ChunkType(*b"IHDR");
+/// Palette
+pub const PLTE: ChunkType = ChunkType(*b"PLTE");
+/// Image data
+pub const IDAT: ChunkType = ChunkType(*b"IDAT");
+/// Image trailer
+pub const IEND: ChunkType = ChunkType(*b"IEND");
+
+// -- Ancillary chunks --
+
+/// Transparency
+pub const tRNS: ChunkType = ChunkType(*b"tRNS");
+/// Background colour
+pub const bKGD: ChunkType = ChunkType(*b"bKGD");
+/// Image last-modification time
+pub const tIME: ChunkType = ChunkType(*b"tIME");
+/// Physical pixel dimensions
+pub const pHYs: ChunkType = ChunkType(*b"pHYs");
+/// Source system's pixel chromaticities
+pub const cHRM: ChunkType = ChunkType(*b"cHRM");
+/// Source system's gamma value
+pub const gAMA: ChunkType = ChunkType(*b"gAMA");
+/// sRGB color space chunk
+pub const sRGB: ChunkType = ChunkType(*b"sRGB");
+/// ICC profile chunk
+pub const iCCP: ChunkType = ChunkType(*b"iCCP");
+/// Latin-1 uncompressed textual data
+pub const tEXt: ChunkType = ChunkType(*b"tEXt");
+/// Latin-1 compressed textual data
+pub const zTXt: ChunkType = ChunkType(*b"zTXt");
+/// UTF-8 textual data
+pub const iTXt: ChunkType = ChunkType(*b"iTXt");
+
+// -- Extension chunks --
+
+/// Animation control
+pub const acTL: ChunkType = ChunkType(*b"acTL");
+/// Frame control
+pub const fcTL: ChunkType = ChunkType(*b"fcTL");
+/// Frame data
+pub const fdAT: ChunkType = ChunkType(*b"fdAT");
+
+// -- Chunk type determination --
+
+/// Returns true if the chunk is critical.
+pub fn is_critical(ChunkType(type_): ChunkType) -> bool {
+ type_[0] & 32 == 0
+}
+
+/// Returns true if the chunk is private.
+pub fn is_private(ChunkType(type_): ChunkType) -> bool {
+ type_[1] & 32 != 0
+}
+
+/// Checks whether the reserved bit of the chunk name is set.
+/// If it is set the chunk name is invalid.
+pub fn reserved_set(ChunkType(type_): ChunkType) -> bool {
+ type_[2] & 32 != 0
+}
+
+/// Returns true if the chunk is safe to copy if unknown.
+pub fn safe_to_copy(ChunkType(type_): ChunkType) -> bool {
+ type_[3] & 32 != 0
+}
+
+impl fmt::Debug for ChunkType {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ struct DebugType([u8; 4]);
+
+ impl fmt::Debug for DebugType {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ for &c in &self.0[..] {
+ write!(f, "{}", char::from(c).escape_debug())?;
+ }
+ Ok(())
+ }
+ }
+
+ f.debug_struct("ChunkType")
+ .field("type", &DebugType(self.0))
+ .field("critical", &is_critical(*self))
+ .field("private", &is_private(*self))
+ .field("reserved", &reserved_set(*self))
+ .field("safecopy", &safe_to_copy(*self))
+ .finish()
+ }
+}