PR #26166 opened by Mika1130 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26166 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26166.patch
Fix corrupted mastering-display primary coordinates in the PNG/APNG encoder's mDCV output. Each primary contains two 16-bit coordinates, so advance by four bytes instead of two. Update `fate-png-mdcv`, whose reference recorded the corrupted metadata and the corresponding PNG checksum. Tested on macOS arm64: `fate-png-mdcv`, 325 tests with `make -j8 fate SAMPLES=`, PNG/APNG metadata and pixel checks, and ASan encoding checks. >From 2c54a50244d37cbf36322e2a6e1b40c211af5247 Mon Sep 17 00:00:00 2001 From: Mika1130 <[email protected]> Date: Wed, 18 Nov 2026 14:26:34 +0800 Subject: [PATCH] avcodec/pngenc: fix mDCV primary coordinate offsets Each mDCV primary contains two 16-bit coordinates. Use a four-byte stride instead of two to avoid overlapping the coordinate pairs in PNG and APNG output. Update fate-png-mdcv, whose reference recorded the corrupted metadata and corresponding PNG checksum. Signed-off-by: Mika1130 <[email protected]> --- libavcodec/pngenc.c | 4 ++-- tests/ref/fate/png-mdcv | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 86380e0c6ec..ece6b4854a2 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -466,8 +466,8 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) AVMasteringDisplayMetadata *mdcv = (AVMasteringDisplayMetadata *) side_data->data; if (mdcv->has_luminance && mdcv->has_primaries) { for (int i = 0; i < 3; i++) { - AV_WB16(s->buf + 2*i, PNG_Q2D(mdcv->display_primaries[i][0], 50000)); - AV_WB16(s->buf + 2*i + 2, PNG_Q2D(mdcv->display_primaries[i][1], 50000)); + AV_WB16(s->buf + 4*i, PNG_Q2D(mdcv->display_primaries[i][0], 50000)); + AV_WB16(s->buf + 4*i + 2, PNG_Q2D(mdcv->display_primaries[i][1], 50000)); } AV_WB16(s->buf + 12, PNG_Q2D(mdcv->white_point[0], 50000)); AV_WB16(s->buf + 14, PNG_Q2D(mdcv->white_point[1], 50000)); diff --git a/tests/ref/fate/png-mdcv b/tests/ref/fate/png-mdcv index 32dfdfcf4e6..27212336fa5 100644 --- a/tests/ref/fate/png-mdcv +++ b/tests/ref/fate/png-mdcv @@ -1,4 +1,4 @@ -f4a586ca1ac51c3db64e58552b990234 *tests/data/fate/png-mdcv.image2pipe +6dfb3ec17af14e304c882df92f5d3cc7 *tests/data/fate/png-mdcv.image2pipe 495592 tests/data/fate/png-mdcv.image2pipe #tb 0: 1/25 #media_type 0: video @@ -11,11 +11,11 @@ frames.frame.0.side_data_list.side_data.0.max_content=1000 frames.frame.0.side_data_list.side_data.0.max_average=200 frames.frame.0.side_data_list.side_data.1.side_data_type="Mastering display metadata" frames.frame.0.side_data_list.side_data.1.red_x="13250/50000" -frames.frame.0.side_data_list.side_data.1.red_y="7500/50000" -frames.frame.0.side_data_list.side_data.1.green_x="34000/50000" -frames.frame.0.side_data_list.side_data.1.green_y="16000/50000" -frames.frame.0.side_data_list.side_data.1.blue_x="2/50000" -frames.frame.0.side_data_list.side_data.1.blue_y="0/50000" +frames.frame.0.side_data_list.side_data.1.red_y="34500/50000" +frames.frame.0.side_data_list.side_data.1.green_x="7500/50000" +frames.frame.0.side_data_list.side_data.1.green_y="3000/50000" +frames.frame.0.side_data_list.side_data.1.blue_x="34000/50000" +frames.frame.0.side_data_list.side_data.1.blue_y="16000/50000" frames.frame.0.side_data_list.side_data.1.white_point_x="15635/50000" frames.frame.0.side_data_list.side_data.1.white_point_y="16450/50000" frames.frame.0.side_data_list.side_data.1.min_luminance="50/10000" -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
