@@ -432,6 +432,13 @@ 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) {
+ size_t len = s->color_type == 0 ? 1 : s->color_type == 2 || s->color_type == 3 ? 3 :
+ s->color_type == 4 ? 2 : 4;
+ memset(s->buf, avctx->bits_per_raw_sample, len);
+ png_write_chunk(&s->bytestream, MKTAG('s', 'B', 'I', 'T'), s->buf, len);
+ }
+
side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE);
if ((ret = png_write_iccp(s, side_data)))
return ret;
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 | 7 +++++++ 1 file changed, 7 insertions(+)