summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-30 13:59:43 +1100
committerTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-30 13:59:43 +1100
commit3a0c2223e660dac7105efb51f4e0d5a33bf7cfa9 (patch)
tree83d1b5a9d6bc1838c10809fc89426fbbbb562759
parentded9f0da7e545d25e7e9fb7c86b5e1e5c34f005f (diff)
refactor(png): Relocate ff_png_bpp to png.c from png.h
-rw-r--r--include/tinyff/image/png.h19
-rw-r--r--src/format/image/png.c28
2 files changed, 26 insertions, 21 deletions
diff --git a/include/tinyff/image/png.h b/include/tinyff/image/png.h
index 3937e8d..fd8d29d 100644
--- a/include/tinyff/image/png.h
+++ b/include/tinyff/image/png.h
@@ -60,24 +60,7 @@ typedef struct {
// Small BpP helper function
-static inline uint16_t ff_png_bpp(ff_png_ctx *ctx)
-{
- int16_t byte_depth = ctx->bit_depth / 8;
- switch (ctx->color_type) {
- case 0: // Grayscale
- return byte_depth * 1; // Gray
- case 2: // Truecolor
- return byte_depth * 3; // R, G, B
- case 3: // Indexed-color
- return byte_depth * 1; // Index
- case 4: // Grayscale with alpha
- return byte_depth * 2; // Gray w/ alpha
- case 6: // Truecolor with alpha
- return byte_depth * 4; // R, G, B w/ alpha
- default:
- return 0; // damn, you corrupt
- }
-}
+static inline uint16_t ff_png_bpp(ff_png_ctx *ctx);
// Chunk handling
diff --git a/src/format/image/png.c b/src/format/image/png.c
index 28f5328..5adb27a 100644
--- a/src/format/image/png.c
+++ b/src/format/image/png.c
@@ -68,6 +68,25 @@ ff_result ff_open_png(ff_stream *stream, ff_png_ctx **out_ctx)
// Handlers
+inline uint16_t ff_png_bpp(ff_png_ctx *ctx)
+{
+ int16_t byte_depth = ctx->bit_depth / 8;
+ switch (ctx->color_type) {
+ case 0: // Grayscale
+ return byte_depth * 1; // Gray
+ case 2: // Truecolor
+ return byte_depth * 3; // R, G, B
+ case 3: // Indexed-color
+ return byte_depth * 1; // Index
+ case 4: // Grayscale with alpha
+ return byte_depth * 2; // Gray w/ alpha
+ case 6: // Truecolor with alpha
+ return byte_depth * 4; // R, G, B w/ alpha
+ default:
+ return 0; // damn, you corrupt
+ }
+}
+
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);
@@ -164,10 +183,13 @@ ff_result ff_png_data_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
// Iterate over every scanline
for (int iline = 0; iline < ctx->height; iline++) {
- uint8_t line_filter = buf[0];
+ // Make some variables so it's not hella unreadable
+ size_t bpp = ff_png_bpp(ctx);
+ size_t scanline_start = iline * (1 + (ctx->width * bpp));
+ uint8_t filter_type = uncompressed_data[scanline_start];
- // WIP: i have to go to bed :(
- // If anyone is reading this have a good day :)
+ //
+
}
// Ahh yes, the memory demons