From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9787545574 for ; Wed, 1 Feb 2023 17:44:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF9FB68BEA6; Wed, 1 Feb 2023 19:44:23 +0200 (EET) Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 24CCB68BD85 for ; Wed, 1 Feb 2023 19:44:17 +0200 (EET) Received: by mail-io1-f47.google.com with SMTP id j4so4261638iog.8 for ; Wed, 01 Feb 2023 09:44:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wLdi06ovCU2E7TKA0MS9qUhKm7S9jlZOnFQJ/cM2lyg=; b=lRdU0IlKuyBP0J47RztuZof7cHcsrZcFzvfLETGFx/mIMYOxWQrfFBq/Z5dhBOZTa6 +NpE+8OoyhPoCsEyj2raSwFIwIhWMOiiIRFGaJfLF/gXGr8IzLMzTF+WyVe47UMSCDCl xeoQljr0Io1Lrd3V/0LomQkBAGNo4qOPAb2jpTuO/J353ClCal2nkB4h8dafTOBoHTg6 jAdCBGaQFZ9wdjAKcl2UPX1yZEAMgjnv+St00+q3+0n+fX0UpS9OcYZaJ0M2f8MnY0Er QgrYFBlkav+G7v/FrEGoOBVg3GL82tzRaC4CcH/IqhtHwJfz4pn1hrr/cwDM9TN14yXa GwbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wLdi06ovCU2E7TKA0MS9qUhKm7S9jlZOnFQJ/cM2lyg=; b=XUyE2NpvktSiYLQrEPAJpTlNl8EQg2yYouEi1hyrobEKQpJ6m9hD4b2bVppRot+R/+ TI2WnEn9SYv1ppoYJnAzTArQ/Yvq5t3sAjw2mdGI5LQL46XXWwmt0PBmoyNKkpareexi UeP7QusSntflZ5YHB9/92EDwuYb1oSb2kEst+i/YEwKn9OzpoHBHYl84xGQL7Pd7dn0D BCFZl+G6sbY9prnHGuTvc7ptRYldHYyI5RVHsVn2qjhuzruNnjIAMEFfbQgMxQac6RDe E53c0bjgkqkoCEbUB3VKKEwfp+1ppD7QRSYal0y/7rsu9hXpPJ1rsmIlPTQEBj9QBYt6 NIKA== X-Gm-Message-State: AO0yUKXrqRdF1Fb+TD3kFfD1RS3DUMNa8/NSwjbOxJYcbmtPCeZjDFVJ NDBE5naYSzzCEau2F0fKz9mILQUK9xPPPw== X-Google-Smtp-Source: AK7set+bL4LJZi/NdN//ognAgFe0sTGe4G+jOxLsz2q2qoE6bXASpypjZBRS4E0oTC0nO9Bi72MAVQ== X-Received: by 2002:a5e:de07:0:b0:716:8f6a:f480 with SMTP id e7-20020a5ede07000000b007168f6af480mr1776672iok.0.1675273455799; Wed, 01 Feb 2023 09:44:15 -0800 (PST) Received: from gauss.local (c-68-41-54-207.hsd1.mi.comcast.net. [68.41.54.207]) by smtp.gmail.com with ESMTPSA id c13-20020a6b4e0d000000b00704a77b7b28sm5925685iob.54.2023.02.01.09.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:44:15 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Feb 2023 12:44:11 -0500 Message-Id: <20230201174412.78042-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230201174412.78042-1-leo.izen@gmail.com> References: <20230201174412.78042-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/2] avcodec/pngenc.c: avoid writing cICP when inappropriate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Leo Izen Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 --- 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".