summaryrefslogtreecommitdiff
path: root/image/png/types.ha
diff options
context:
space:
mode:
authorLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:11:21 +0200
committerLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:51:35 +0200
commitae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch)
tree5f462459ae4b47d22114eed717d1382d08cf4dfe /image/png/types.ha
Initial commit (import old repo)HEADmain
Diffstat (limited to 'image/png/types.ha')
-rw-r--r--image/png/types.ha69
1 files changed, 69 insertions, 0 deletions
diff --git a/image/png/types.ha b/image/png/types.ha
new file mode 100644
index 0000000..b970175
--- /dev/null
+++ b/image/png/types.ha
@@ -0,0 +1,69 @@
+// The PNG magic number.
+export const magic: [_]u8 = [137, 80, 78, 71, 13, 10, 26, 10];
+
+def MAGIC_LEN: size = 8;
+
+// The chunk header type for an IHDR chunk.
+export def IHDR: u32 = 0x49484452;
+
+// The chunk header type for a PLTE chunk.
+export def PLTE: u32 = 0x504c5445;
+
+// The chunk header type for an IDAT chunk.
+export def IDAT: u32 = 0x49444154;
+
+// The chunk header type for an IEND chunk.
+export def IEND: u32 = 0x49454e44;
+
+// The chunk header type for a tRNS chunk.
+export def TRNS: u32 = 0x74524e53;
+
+// The chunk header type for a gAMA chunk.
+export def GAMA: u32 = 0x67414d41;
+
+// The chunk header type for an sRGB chunk.
+export def SRGB: u32 = 0x73524742;
+
+// The chunk header type for an iCCP chunk.
+export def ICCP: u32 = 0x69434350;
+
+// The chunk header type for a tEXT chunk.
+export def TEXT: u32 = 0x74455854;
+
+// The chunk header type for a zTXT chunk.
+export def ZTXT: u32 = 0x7a545854;
+
+// The chunk header type for an iTXT chunk.
+export def ITXT: u32 = 0x69545854;
+
+// The chunk header type for a bKGD chunk.
+export def BKGD: u32 = 0x624b4744;
+
+// The chunk header type for a pHYS chunk.
+export def PHYS: u32 = 0x70485953;
+
+// The chunk header type for a sBIT chunk.
+export def SBIT: u32 = 0x73424954;
+
+// The chunk header type for a sPLT chunk.
+export def SPLT: u32 = 0x73504c54;
+
+// The chunk header type for a hIST chunk.
+export def HIST: u32 = 0x68495354;
+
+// The chunk header type for a tIME chunk.
+export def TIME: u32 = 0x74494d45;
+
+// Returns true if the given chunk type is a "critical" chunk.
+export fn is_critical(ctype: u32) bool = {
+ return ctype & (1 << 29) == 0;
+};
+
+@test fn is_critical() void = {
+ assert(is_critical(IHDR) == true);
+ assert(is_critical(PLTE) == true);
+ assert(is_critical(IDAT) == true);
+ assert(is_critical(IEND) == true);
+ assert(is_critical(HIST) == false);
+ assert(is_critical(TIME) == false);
+};