From 96f54c3f68c04e732320b53c0e5d526d59ccf4b9 Mon Sep 17 00:00:00 2001 From: Watson Wheeler Date: Sun, 28 Jun 2026 16:51:48 +1000 Subject: feat(png): encode IHDR to stream in ff_encode_png Signed-off-by: Watson Wheeler --- src/format/image/png.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/format/image') diff --git a/src/format/image/png.c b/src/format/image/png.c index 80639a2..40b2e62 100644 --- a/src/format/image/png.c +++ b/src/format/image/png.c @@ -498,11 +498,26 @@ ff_result ff_encode_png(ff_ctx *ctx, ff_png_ctx *png_ctx, ff_stream *stream) stream->write(stream, 8, (void *)PNG_SIGNATURE); - // TODO: Actually write the PNG data - // For now I'll void the parameters - (void)ctx; - (void)png_ctx; + // IHDR + // TODO: Optimise this whole thing + uint8_t* ihdrbuf = ctx->allocator.ff_calloc(13, 1); + + uint8_t bewidth[4]; + ff_write_be32(bewidth, png_ctx->width); + stream->write(bewidth, 4, ihdrbuf); + + uint8_t belength[4]; + ff_write_be32(belength, png_ctx->height); + stream->write(belength, 4, ihdrbuf); + + stream->write(&png_ctx->bit_depth, 1, ihdrbuf); + stream->write(&png_ctx->color_type, 1, ihdrbuf); + stream->write(0, 1, ihdrbuf); // PNG only support 1 compression method + stream->write(&png_ctx->filter_method, 1, ihdrbuf); + stream-> write(&png_ctx->interlace_method, 1, ihdrbuf); + ff_write_chunk(stream, "IHDR", ihdrbuf, 13); + ctx->allocator.ff_free(ihdrbuf); FF_BENCH_END(ctx); return FF_RESULT_WARN_NO_IMPL; -- cgit v1.2.3