avcodec/pngenc: write sBIT chunks

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>
This commit is contained in:
Leo Izen 2023-03-21 23:26:26 -04:00
parent 84b454935f
commit c125860892
No known key found for this signature in database
GPG Key ID: 5A71C331FD2FA19A
1 changed files with 6 additions and 0 deletions

View File

@ -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;