summaryrefslogtreecommitdiff
path: root/include/tinyff
diff options
context:
space:
mode:
authortazy <gardendistrict0x0@outlook.com>2026-01-04 08:04:33 +0000
committertazy <gardendistrict0x0@outlook.com>2026-01-04 08:04:33 +0000
commitab3873609baf282f9158566c8242be2c9b126f5d (patch)
tree80af415259ee5a59540b302de58f438d57011cc5 /include/tinyff
parent896ec637777e5a657d8180c51c5e574b469b7eed (diff)
feat(png): Create header handler for the IHDR chunk
Diffstat (limited to 'include/tinyff')
-rw-r--r--include/tinyff/image/png.h38
-rw-r--r--include/tinyff/result.h3
2 files changed, 24 insertions, 17 deletions
diff --git a/include/tinyff/image/png.h b/include/tinyff/image/png.h
index 85ed179..b2f400f 100644
--- a/include/tinyff/image/png.h
+++ b/include/tinyff/image/png.h
@@ -28,31 +28,35 @@ typedef struct {
} ff_png_ctx;
-
-typedef enum {
- FF_PNG_CHUNK_TYPE_IHDR,
- FF_PNG_CHUNK_TYPE_PLTE,
- FF_PNG_CHUNK_TYPE_IDAT,
- FF_PNG_CHUNK_TYPE_IEND,
-
- // There are more,
- // but these ones will be
- // enough for now
-
- FF_PNG_CHUNK_TYPE_UNKNOWN,
-} ff_png_chunk_type;
-
-
typedef struct {
uint32_t length;
- ff_png_chunk_type type;
+ const char *type;
uint32_t *data; // length bytes (maximum is uint32_t)
uint32_t crc;
} ff_png_chunk;
+// Chunk handling
+
+typedef (*ff_png_chunk_handler_ptr)(uint8_t *data, size_t len, ff_png_ctx* ctx);
+
+typedef struct {
+ const char *type;
+ ff_png_chunk_handler_ptr handler;
+} ff_png_chunk_handler;
+
+const ff_png_chunk_handler ff_png_chunk_handlers[] = {
+ {"IHDR", NULL},
+ {"IDAT", NULL},
+ {"IEND", NULL},
+
+
+ {NULL, NULL} // Terminator
+};
+
+void ff_png_header_handler(uint8_t *data, size_t len, ff_png_ctx* ctx);
+
ff_result ff_png_isvalid(FILE *file);
ff_result ff_open_png(const char *filepath, ff_png_ctx **out_ctx);
-ff_result ff_next_chunk(FILE *file, ff_png_chunk **out_chunk);
#endif
diff --git a/include/tinyff/result.h b/include/tinyff/result.h
index 27b1ce4..9b17d4a 100644
--- a/include/tinyff/result.h
+++ b/include/tinyff/result.h
@@ -9,6 +9,9 @@ typedef enum {
FF_RESULT_ERROR_INVALID_FILE,
FF_RESULT_ERROR_READ_FILE_FAILURE,
+ // Memory
+ FF_RESULT_ERROR_MEMORY_ALLOCATION,
+
// More will be created when more errors occur
} ff_result;