summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-15 20:28:07 +1100
committerTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-15 20:28:07 +1100
commit165d2bd7dde7ab55eced4556e8b1b9128276aa7b (patch)
tree24d0b3f4264b6627066aa82195f5fdb257682006 /include
parentd0fc19a97c7f115dca25f2b39b6a9fbe337b31a3 (diff)
feat(png): Refactor PNG handling to use stream interface
Diffstat (limited to 'include')
-rw-r--r--include/tinyff/image/png.h29
-rw-r--r--include/tinyff/result.h4
2 files changed, 18 insertions, 15 deletions
diff --git a/include/tinyff/image/png.h b/include/tinyff/image/png.h
index c9f3378..8858fd7 100644
--- a/include/tinyff/image/png.h
+++ b/include/tinyff/image/png.h
@@ -9,6 +9,7 @@
#include "tinyff/result.h"
#include "tinyff/common.h"
+#include "tinyff/stream.h"
static const unsigned char PNG_SIGNATURE[8] = {
@@ -22,8 +23,8 @@ typedef enum {
} ff_png_mode;
typedef struct {
- // Raw file handle
- FILE *raw;
+ // Raw stream handle
+ ff_stream *raw;
// Image dimensions
uint32_t width;
@@ -69,6 +70,16 @@ typedef struct {
ff_png_chunk_handler_ptr handler;
} ff_png_chunk_handler;
+// Handler declarations
+// Massive W.I.P
+
+// Required by definition
+ff_result ff_png_header_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IHDR
+ff_result ff_png_palette_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // PLTE
+ff_result ff_png_data_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IDAT
+ff_result ff_png_end_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IEND
+
+
const ff_png_chunk_handler ff_png_chunk_handlers[] = {
{"IHDR", ff_png_header_handler},
{"IDAT", ff_png_data_handler},
@@ -81,20 +92,10 @@ const ff_png_chunk_handler ff_png_chunk_handlers[] = {
{NULL, NULL} // Terminator
};
-// Handler declarations
-// Massive W.I.P
-
-// Required by definition
-ff_result ff_png_header_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IHDR
-ff_result ff_png_palette_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // PLTE
-ff_result ff_png_data_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IDAT
-ff_result ff_png_end_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IEND
-// PLTE is a funny one
-// Its only required for indexed color types
-ff_result ff_png_isvalid(FILE *file);
-ff_result ff_open_png(const char *filepath, ff_png_ctx **out_ctx);
+ff_result ff_png_isvalid(ff_stream *stream);
+ff_result ff_open_png(ff_stream *stream, ff_png_ctx **out_ctx);
#endif
diff --git a/include/tinyff/result.h b/include/tinyff/result.h
index daea32e..49919ed 100644
--- a/include/tinyff/result.h
+++ b/include/tinyff/result.h
@@ -12,10 +12,12 @@ typedef enum {
// -- ERRORS --
// File
- FF_RESULT_ERROR_INVALID_FILE_SIGNITURE,
FF_RESULT_ERROR_INVALID_FILE,
FF_RESULT_ERROR_READ_FILE_FAILURE,
+ // Media specific
+ FF_RESULT_ERROR_INVALID_PNG_SIGNITURE, // PNG
+
// Memory
FF_RESULT_ERROR_MEMORY_ALLOCATION,