From: Leo Izen <leo.izen@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Leo Izen <leo.izen@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 1/2] avcodec/pngenc.c: avoid writing cICP when inappropriate Date: Wed, 1 Feb 2023 12:44:11 -0500 Message-ID: <20230201174412.78042-2-leo.izen@gmail.com> (raw) In-Reply-To: <20230201174412.78042-1-leo.izen@gmail.com> We parse the fallback cHRM on decode and correctly determine that we have BT.709 primaries, but unknown TRC. This causes us to write cICP where we shouldn't. Primaries without transfer can be handled entirely by cHRM, so we should only write cICP if we actually know the transfer function. Additionally, we should avoid writing cICP if there's an ICC profile because the spec says decoders must prioritize cICP over the ICC profile. Signed-off-by: Leo Izen <leo.izen@gmail.com> --- libavcodec/pngenc.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 2393161c3b..81b95c143d 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -412,14 +412,25 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) } } + side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE); + if ((ret = png_write_iccp(s, side_data))) + return ret; + /* write colorspace information */ if (pict->color_primaries == AVCOL_PRI_BT709 && pict->color_trc == AVCOL_TRC_IEC61966_2_1) { s->buf[0] = 1; /* rendering intent, relative colorimetric by default */ png_write_chunk(&s->bytestream, MKTAG('s', 'R', 'G', 'B'), s->buf, 1); - } else if (pict->color_primaries != AVCOL_PRI_UNSPECIFIED || - pict->color_trc != AVCOL_TRC_UNSPECIFIED) { - /* these values match H.273 so no translation is needed */ + } else if (pict->color_trc != AVCOL_TRC_UNSPECIFIED && !side_data) { + /* + * Avoid writing cICP if the transfer is unknown. Known primaries + * with unknown transfer can be handled by cHRM. + * + * We also avoid writing cICP if an ICC Profile is present, because + * the standard requires that cICP overrides iCCP. + * + * These values match H.273 so no translation is needed. + */ s->buf[0] = pict->color_primaries; s->buf[1] = pict->color_trc; s->buf[2] = 0; /* colorspace = RGB */ @@ -432,10 +443,6 @@ 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); - side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE); - if ((ret = png_write_iccp(s, side_data))) - return ret; - /* put the palette if needed, must be after colorspace information */ if (s->color_type == PNG_COLOR_TYPE_PALETTE) { int has_alpha, alpha, i; -- 2.39.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-02-01 17:44 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-01 17:44 [FFmpeg-devel] [PATCH v2 0/2] PNG cICP improvements Leo Izen 2023-02-01 17:44 ` Leo Izen [this message] 2023-02-01 17:44 ` [FFmpeg-devel] [PATCH v2 2/2] avcodec/pngdec: read colorspace info when decoding with AVDISCARD_ALL Leo Izen 2023-02-01 19:32 ` Andreas Rheinhardt 2023-02-01 23:08 ` Leo Izen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230201174412.78042-2-leo.izen@gmail.com \ --to=leo.izen@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git