diff options
| author | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-01-26 20:38:22 +1100 |
|---|---|---|
| committer | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-01-26 20:38:22 +1100 |
| commit | 245c07842e49da00c254b2ffb411763e71deaa67 (patch) | |
| tree | 979672c3b48e7346e561f1f153953efcdd1e601f | |
| parent | d249266adfcbe24ec9fd9dd4967a84dd42b24507 (diff) | |
feat(png): Decompress IDAT using tinf uncompress (WIP)
| -rw-r--r-- | include/tinyff/image/png.h | 3 | ||||
| -rw-r--r-- | src/format/image/png.c | 21 |
2 files changed, 17 insertions, 7 deletions
diff --git a/include/tinyff/image/png.h b/include/tinyff/image/png.h index 0b2ce34..c195951 100644 --- a/include/tinyff/image/png.h +++ b/include/tinyff/image/png.h @@ -11,6 +11,9 @@ #include "tinyff/common.h" #include "tinyff/stream.h" +// External +#include "ext/tinf.h" + static const unsigned char PNG_SIGNATURE[8] = { 0x89, 'P', 'N', 'G', 0x0D, 0x0A, 0x1A, 0x0A diff --git a/src/format/image/png.c b/src/format/image/png.c index fc3d84a..ef30dcd 100644 --- a/src/format/image/png.c +++ b/src/format/image/png.c @@ -129,16 +129,23 @@ 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); - // For now, compression handling is not implemented - // and instead will assume data is uncompressed + // Update: Now I got tinf integrated, I can actually implement this - ff_dprintf("png: IDAT handler WIP - data is assumed uncompressed\n"); - ff_dprintf("png: IDAT handler WIP - expect undefined behavior\n"); + uint8_t *uncompressed_data = NULL; + + // Getting the size is weird cause it could the sample count + // could be different based on color type and bit depth + // TODO: Calculate properly + size_t uncompressed_size = ctx->width * ctx->height; // WIP based size + + uncompressed_data = malloc(uncompressed_size); - // We will need to loop over all the scanlines and apply filters - // But im too lazy to do that right now - // TODO implement + if (!uncompressed_data) { + ff_dprintf("png: failed to allocate memory for uncompressed data\n"); + return FF_RESULT_ERROR_MEMORY_ALLOCATION; + } + tinf_uncompress(uncompressed_data, uncompressed_size, buf, len); return FF_RESULT_WARN_NO_IMPL; } |
