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 01DFB4418E for ; Thu, 2 Feb 2023 15:10:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5898368BDC5; Thu, 2 Feb 2023 17:09:50 +0200 (EET) Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1192668B4A7 for ; Thu, 2 Feb 2023 17:09:43 +0200 (EET) Received: by mail-il1-f174.google.com with SMTP id x6so854443ilv.7 for ; Thu, 02 Feb 2023 07:09:42 -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=TT41DEBfb3qw9p0mHaQn83C2MVl7vckkhPk7wPW8IvbrSVchcXhhvjBx1EQANdyo1B 66haEZnW8PWNRn00rHX0RqlgAn+DZxdjjSizJ75uD5JKxiMONo/7qPtvagljgACY4gtr 17nBAB6+D3Tw+KeFzvTP3F/7soURXc1uOfMGAsYj/4gp8YA5UibI0Pc33d1Mhu1Rtm1S jcIA7Euks6SgnC9qpCIwjFNmHsakkKBXMO2RrFs4r4ujk5Wn9XfbZ59IKjIpLeYk3sWm PuraEqXFrs0auJkTw/JXhR82q0jhusRtmIFkxfIlCI09jxqa1cgZSSkZV0Vb+nqxzK3y uYnw== 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=2WcZvCChkQH3psb+PZAKCvr/RXgghZGNpRLl93I17G2PnHt+1793B7ZYp4dsrwMcYK Fpv2TiXgNAmjvt2kowrlRSkm5rRKpZumU3bclO141HLIkT1iRLW3my7nbaj13Pjm2uoU Kp6f2ljATKoRi2b61eZPC4LNDSth5FKYZFlbrp2ancrpwpKONMhFPitx52OnPwTWDqMq L0B9hBJa0v/UcTyLO1fRbrA7RiRP1ceSnj4cUsFq2/X2lAUt+Nb+JDx3CNMD8GSivsXM 7S0DVZZQzusrNajZqUslV8M07AISGmazsfdGQZseDXFsCThr3NTJRZ7UPzrBT/xjAEy/ POyQ== X-Gm-Message-State: AO0yUKXKt4jeKn+meFa2keyumylCXoLFWZWSkBvnuIIQqv7jbm9i2QU+ cO3nPNLFaSG8BVxATWX9R+by4791zYEZLw== X-Google-Smtp-Source: AK7set9XNGefW9bG+GZ1bZkXv5jGb4uuLu91eeih9mbq7DTGT6DtfI7L8wZRHgy0eRdp1Q1z9Pg9ww== X-Received: by 2002:a05:6e02:1746:b0:30d:bf1a:b174 with SMTP id y6-20020a056e02174600b0030dbf1ab174mr5643388ill.1.1675350581657; Thu, 02 Feb 2023 07:09:41 -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 r7-20020a92d987000000b0030f43cefc4bsm6570122iln.53.2023.02.02.07.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 07:09:41 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Thu, 2 Feb 2023 10:09:36 -0500 Message-Id: <20230202150938.22297-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202150938.22297-1-leo.izen@gmail.com> References: <20230202150938.22297-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/3] avcodec/pngenc: 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".