diff options
| author | Watson Wheeler <git@tazy.dev> | 2026-06-28 16:51:48 +1000 |
|---|---|---|
| committer | Watson Wheeler <git@tazy.dev> | 2026-07-02 19:39:07 +1000 |
| commit | 96f54c3f68c04e732320b53c0e5d526d59ccf4b9 (patch) | |
| tree | 00c6e4b3fa64248726b5dde52bdbb789cd8683ab /src/format/image/png.c | |
| parent | ca28abe6901902932cf8083c2a4e6c0d1f34fed2 (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/png.c')
| -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 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; |
