summaryrefslogtreecommitdiff
path: root/src/format/image
diff options
context:
space:
mode:
authorGarden <gardendistrict0x0@outlook.com>2025-12-18 21:14:42 +1100
committerGarden <gardendistrict0x0@outlook.com>2025-12-18 21:14:42 +1100
commita65f99a64e1937411a9268213c55f1b030df7af5 (patch)
tree2f20a154cb9b564a0646cc5fa56bbc8e80cc6f2a /src/format/image
parentd43248b74af0bece228e9b80251cd3512e878ca9 (diff)
feat(png): Validate signiture header
Diffstat (limited to 'src/format/image')
-rw-r--r--src/format/image/png.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/format/image/png.c b/src/format/image/png.c
new file mode 100644
index 0000000..b29e271
--- /dev/null
+++ b/src/format/image/png.c
@@ -0,0 +1,37 @@
+#include "tinyff/image/png.h"
+#include "png.h"
+
+ff_result ff_png_isvalid(FILE *file)
+{
+ char raw_sig[8];
+ if (fread(raw_sig, sizeof(char), 8, file) != 8) {
+ // Inable to read first 8 bytes
+ fclose(file);
+ return FF_RESULT_ERROR_INVALID_FILE;
+ }
+
+ if (memcmp(raw_sig, PNG_SIGNATURE, 8) != 0) {
+ // Signiture did not match
+ fclose(file);
+ return FF_RESULT_ERROR_INVALID_FILE_SIGNITURE;
+ }
+
+ return FF_RESULT_OK;
+}
+
+ff_png_ctx *ff_open_png(const char *filepath) {
+ // Validate
+
+ ff_png_ctx ctx;
+ ctx.raw = fopen(filepath, "rb");
+
+ if (!ctx.raw) {
+ return NULL;
+ }
+
+ if (ff_png_isvalid(ctx.raw) != FF_RESULT_OK) {
+ return NULL;
+ }
+
+ // TODO: Parse
+} \ No newline at end of file