summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tinyff/image/png.h30
-rw-r--r--src/format/image/png.c21
2 files changed, 46 insertions, 5 deletions
diff --git a/include/tinyff/image/png.h b/include/tinyff/image/png.h
index 9348dce..a77092a 100644
--- a/include/tinyff/image/png.h
+++ b/include/tinyff/image/png.h
@@ -17,13 +17,29 @@ static const unsigned char PNG_SIGNATURE[8] = {
typedef struct {
+
+ // Raw file handle
FILE *raw;
+
+ // Image dimensions
uint32_t width;
uint32_t height;
+
+ // Color information
uint8_t bit_depth;
uint8_t color_type;
- uint8_t *pixels;
- size_t count_pixels;
+
+ // Image data
+ //
+ // It's weird because theres actually multiple ways to store it
+ // we need to be able to have the same fields to hold the data
+ // or have two seperate fields and a flag pointing to which one is actually
+ // being used sorta because of palette vs direct color
+ // so until i find a better way than holding this crappy project together with duct tape
+ // im just gonna use two fields and a flag
+ // but again with bit depths and color types this can get really messy really fast
+ // and i have NO idea what what type direct color data should be stored as.
+ // god... i hate png
bool valid;
} ff_png_ctx;
@@ -49,6 +65,9 @@ const ff_png_chunk_handler ff_png_chunk_handlers[] = {
{"IHDR", ff_png_header_handler},
{"IDAT", ff_png_data_handler},
{"IEND", ff_png_end_handler},
+ {"PLTE", ff_png_palette_handler},
+
+ // From now on, the handlers will be for ancillary chunks
{NULL, NULL} // Terminator
@@ -58,9 +77,10 @@ const ff_png_chunk_handler ff_png_chunk_handlers[] = {
// Massive W.I.P
// Required by definition
-void ff_png_header_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IHDR
-void ff_png_data_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IDAT
-void ff_png_end_handler(uint8_t *buf, size_t len, ff_png_ctx* ctx); // IEND
+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
diff --git a/src/format/image/png.c b/src/format/image/png.c
index 8662fa2..11f4093 100644
--- a/src/format/image/png.c
+++ b/src/format/image/png.c
@@ -1,5 +1,6 @@
#include "tinyff/image/png.h"
#include "tinyff/dbg.h"
+#include "png.h"
ff_result ff_png_isvalid(FILE *file)
{
@@ -87,6 +88,18 @@ ff_result ff_png_header_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
return FF_RESULT_OK;
}
+ff_result ff_png_chunk_palette_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
+{
+ ff_dprintf("png: PLTE chunk received (len=%zu)\n", len);
+
+ uint16_t num_entries = len / 3;
+ ff_dprintf("png: PLTE contains %u palette entries\n", num_entries);
+
+
+
+ return FF_RESULT_WARN_NO_IMPL;
+}
+
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);
@@ -103,4 +116,12 @@ ff_result ff_png_data_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
return FF_RESULT_WARN_NO_IMPL;
+}
+
+ff_result ff_png_end_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
+{
+ ff_dprintf("png: IEND chunk received (len=%zu)\n", len);
+ ff_dprintf("png: all chunks received\n");
+
+ return FF_RESULT_OK;
} \ No newline at end of file