diff options
| author | Watson Wheeler <git@tazy.dev> | 2026-06-28 16:51:48 +1000 |
|---|---|---|
| committer | Watson Wheeler <git@tazy.dev> | 2026-06-28 16:51:48 +1000 |
| commit | 776e8e082d00af3919618e57aac1b89d76a9454f (patch) | |
| tree | 3b0b10112112144198f7ac6efc62dd9088a48b96 /src/format/image | |
| parent | 6dbd45aaa78bdd049c2d10856312f4df437b845b (diff) | |
feat(png): encode IHDR to stream in ff_encode_png
Signed-off-by: Watson Wheeler <git@tazy.dev>
Diffstat (limited to 'src/format/image')
| -rw-r--r-- | src/format/image/png.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/format/image/png.c b/src/format/image/png.c index 51cc979..535c539 100644 --- a/src/format/image/png.c +++ b/src/format/image/png.c @@ -503,11 +503,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; |
