diff mbox series

[FFmpeg-devel,v3,2/2] avcodec/pngenc: write sBIT chunks

Message ID 20230322032626.45777-3-leo.izen@gmail.com
State New
Headers show
Series PNG sBIT chunk support | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Leo Izen March 22, 2023, 3:26 a.m. UTC
Add support for writing sBIT chunks, which mark the significant
bit depth of the PNG file. This obtains the metadata using the field
bits_per_raw_sample of AVCodecContext.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
 libavcodec/pngenc.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 1489256d00..21b033ea16 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -442,6 +442,12 @@  static int encode_headers(AVCodecContext *avctx, const AVFrame *pict)
     if (png_get_gama(pict->color_trc, s->buf))
         png_write_chunk(&s->bytestream, MKTAG('g', 'A', 'M', 'A'), s->buf, 4);
 
+    if (avctx->bits_per_raw_sample > 0 && avctx->bits_per_raw_sample < s->bit_depth) {
+        int len = ff_png_get_nb_channels(s->color_type);
+        memset(s->buf, avctx->bits_per_raw_sample, len);
+        png_write_chunk(&s->bytestream, MKTAG('s', 'B', 'I', 'T'), s->buf, len);
+    }
+
     /* put the palette if needed, must be after colorspace information */
     if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
         int has_alpha, alpha, i;