summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-14 14:24:01 +1100
committerTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-14 14:24:01 +1100
commit7041bdaeff0456f549ffed48f3c8bc442193b0ce (patch)
treee4b790ec0fbb599e23ee0c0a18952d5a039a3fb8
parentfbf406c34adb0a65924f15a1f0e5142e695b36ad (diff)
feat(png): Implement chunk handlers for IHDR and IDAT
-rw-r--r--include/tinyff/image/png.h6
-rw-r--r--src/format/image/png.c26
2 files changed, 27 insertions, 5 deletions
diff --git a/include/tinyff/image/png.h b/include/tinyff/image/png.h
index 80e8fe6..9348dce 100644
--- a/include/tinyff/image/png.h
+++ b/include/tinyff/image/png.h
@@ -46,9 +46,9 @@ typedef struct {
} ff_png_chunk_handler;
const ff_png_chunk_handler ff_png_chunk_handlers[] = {
- {"IHDR", NULL},
- {"IDAT", NULL},
- {"IEND", NULL},
+ {"IHDR", ff_png_header_handler},
+ {"IDAT", ff_png_data_handler},
+ {"IEND", ff_png_end_handler},
{NULL, NULL} // Terminator
diff --git a/src/format/image/png.c b/src/format/image/png.c
index d177819..8662fa2 100644
--- a/src/format/image/png.c
+++ b/src/format/image/png.c
@@ -55,13 +55,15 @@ ff_result ff_open_png(const char *filepath, ff_png_ctx **out_ctx)
return FF_RESULT_OK;
}
-void ff_png_header_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
+// Handlers
+
+ff_result ff_png_header_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
{
ff_dprintf("png: IHDR chunk received (len=%zu)\n", len);
if (len != 13) {
ff_dprintf("png: invalid IHDR length\n");
- return;
+ return FF_RESULT_ERROR_INVALID_FILE;
}
uint32_t w = get_big_endian(buf);
@@ -81,4 +83,24 @@ void ff_png_header_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
ctx->color_type = buf[9];
ff_dprintf("png: IHDR stored in context\n");
+
+ return FF_RESULT_OK;
+}
+
+ff_result ff_png_data_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
+{
+ ff_dprintf("png: IDAT chunk received (len=%zu)\n", len);
+
+ // For now, compression handling is not implemented
+ // and instead will assume data is uncompressed
+
+ ff_dprintf("png: IDAT handler WIP - data is assumed uncompressed\n");
+ ff_dprintf("png: IDAT handler WIP - expect undefined behavior\n");
+
+ // We will need to loop over all the scanlines and apply filters
+ // But im too lazy to do that right now
+ // TODO implement
+
+
+ return FF_RESULT_WARN_NO_IMPL;
} \ No newline at end of file