From e7ea6fd77f9cc102ba49d119e6e0cf0dcb5d1bd2 Mon Sep 17 00:00:00 2001 From: Fredrick Brennan Date: Thu, 10 Nov 2022 04:36:46 -0500 Subject: [PATCH] patterns: Added APNG support to PNG pattern (#53) --- patterns/png.hexpat | 46 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/patterns/png.hexpat b/patterns/png.hexpat index ff55e03..f88c675 100644 --- a/patterns/png.hexpat +++ b/patterns/png.hexpat @@ -1,6 +1,5 @@ #pragma MIME image/png #pragma endian big -#pragma pattern_limit 0 struct header_t { u8 highBitByte; @@ -88,6 +87,33 @@ fn text_len() { return len; }; +enum BlendOp: u8 { + Source = 0x0, + Over +}; + +enum DisposeOp: u8 { + None = 0x0, + Background, + Previous +}; + +struct fctl_t { + u32 sequence_no [[comment("Sequence №")]]; + u32 width [[comment("Frame width")]]; + u32 height [[comment("Frame height")]]; + u32 xoff; + u32 yoff; + u16 delay_num [[comment("Frame delay fraction numerator")]]; + u16 delay_den [[comment("Frame delay fraction denominator")]]; + DisposeOp dispose_op; + BlendOp blend_op; +}; + +struct fdat_t { + u32 sequence_no; +}; + struct itxt_t { char keyword[]; u8 compression_flag; @@ -145,18 +171,20 @@ struct chunk_t { sRGB srgb; } else if (name == pHYs_k) { phys_t phys; - } else if (name == acTL_k) { - actl_t actl; - } else if (name == fcTL_k) { + } else if (type == acTL_k) { + actl_t actl [[comment("Animation control chunk")]]; + } else if (type == fcTL_k) { fctl_t fctl [[comment("Frame control chunk")]]; - } else if (name == iTXt_k) { + } else if (type == iTXt_k) { itxt_t text; + } else if (type == gAMA_k) { + u32 gamma [[name("image gamma"), comment("4 byte unsigned integer representing gamma times 100000")]]; + } else if (type == iCCP_k) { + iccp_t iccp; } else if (name == tEXt_k) { text_t text; } else if (name == zTXt_k) { ztxt_t text; - } else if (name == gAMA_k) { - u32 gamma [[name("image gamma"), comment("4 byte unsigned integer representing gamma times 100000")]]; } else if (name == iCCP_k) { iccp_t iccp; } else if (name == fdAT_k) { @@ -180,6 +208,4 @@ struct chunk_set { header_t header @ 0x00 [[comment("PNG file signature"), name("Signature")]]; chunk_t ihdr_chunk @ 0x08 [[comment("PNG Header chunk"), name("IHDR")]]; chunk_set set @ $ [[comment("PNG Chunks"), name("Chunks"), inline]]; -chunk_t iend_chunk @ $ [[comment("Image End Chunk"), name("IEND")]]; - -// vim: syntax=rust +chunk_t iend_chunk @ $ [[comment("Image End Chunk"), name("IEND")]]; \ No newline at end of file