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 9350B452ED for ; Tue, 17 Jan 2023 18:51:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 10F0E68BEAA; Tue, 17 Jan 2023 20:51:06 +0200 (EET) Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CBF1E68BE96 for ; Tue, 17 Jan 2023 20:50:57 +0200 (EET) Received: by mail-il1-f169.google.com with SMTP id m7so3300301ilh.7 for ; Tue, 17 Jan 2023 10:50:57 -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=UQc5xGT/5XxXsCA/iQilrvFYo8CDuMU9RR91Zcl5vF4=; b=OTRqTBDUGqP8H6oFnfZUfhkBzAHQSMFXqbI1Mt6fI1E85UWZydnqJSmLJ21LhzZp9M 5xYSmBHliY9iSEZ7EdMCLhoBO6IrxrqFm4uDw2LCpJKex7FY2YAYTwusiM7EWg3dee2c 2hrbFJS3AFUGhYyuhofpB1xLLkOjlNAziNGXE9vpo0Rc3XHWdsgRjXtL/jzs1MpamsMH qVWs2a4q4vBTH1i6wuRCdPwWgOEJPE33944tn0v3eumrxPglnpxsOtgHWi6Hz101s0p0 B8CBTEhblUDEvcIGNiUdoDQMmulL6cMng2ipRbXuh4lCf6yTD8sAYvMxHGnFK+qwZ5PJ 1zDQ== 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=UQc5xGT/5XxXsCA/iQilrvFYo8CDuMU9RR91Zcl5vF4=; b=BXcjZ9NCzg8xfxRXtzHC9uaza4oi4J9q4C55ONZ5c1qQzhLh0lq6PTLrJaFaS8rgvB ckqUiAjZuRovip7lwwe3S1Y3gqQetUWEqQ4QluRxKpIt+P51hYimy/4dpX+/1N9+WfL8 pkYQvxxUjUbbwD4ngFkRDyasrMlrA0oBNyKCR+h5SOmcOI1lrjIbBud495CfdPUBOvSs Kzv+d4Pe+EGcp6IEXsp0LU0c8Sca3SCD/iHcfJ4B+g8YEKtXP5DGg+EumwTea2X1Q1rm 6uSVIBbmY021TEC3UqG9W+Qcia6G3wzy1LicMkks5GhG+hVPaBaSTBivUuKpa4P4Aj8G GoIA== X-Gm-Message-State: AFqh2koUslWfNDk+GY7ahneeufgzDRkj6LLVm8MMzoIBk3scahBuC/I5 T3Kz4okBv0g6wFX39NzhHanjVDNobVs= X-Google-Smtp-Source: AMrXdXt/xr1ggDBE/L68OHdeq8/jjbuh6zgNbmjqfVKiRP9frGeRWSLnjnrfYY74uwIF/UWnFRjYuw== X-Received: by 2002:a92:6a09:0:b0:304:d0b7:e362 with SMTP id f9-20020a926a09000000b00304d0b7e362mr3469938ilc.5.1673981456417; Tue, 17 Jan 2023 10:50:56 -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 y93-20020a029566000000b003a4894d46e0sm2262223jah.176.2023.01.17.10.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 10:50:56 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Jan 2023 13:50:50 -0500 Message-Id: <20230117185051.475157-3-leo.izen@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230117185051.475157-1-leo.izen@gmail.com> References: <20230117185051.475157-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/3] avcodec/pngdec: support decoding sRGB chunks 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: If an sRGB chunk is present in the PNG file, this commit will cause the png decoder to ignore the cHRM and gAMA chunks and tag the resulting AVFrames with BT.709 primaries, and ISO/IEC 61966-2-1 transfer. If these tags are present in the AVFrame, pngenc.c already writes this chunk, so no change was needed on the encode-side. The PNG spec does not define what happens if sRGB and iCCP are present at the same time, it just recommends that this not happen. As of this patch, the decoder will have the ICC profile take precedence, and it will not tag the pixel data as sRGB. Signed-off-by: Leo Izen --- libavcodec/pngdec.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 32e7773bcb..1f9ed894de 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -75,6 +75,7 @@ typedef struct PNGDecContext { int have_chrm; uint32_t white_point[2]; uint32_t display_primaries[3][2]; + int have_srgb; enum PNGHeaderState hdr_state; enum PNGImageState pic_state; @@ -1313,6 +1314,11 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, } break; } + case MKTAG('s', 'R', 'G', 'B'): + /* skip rendering intent byte */ + bytestream2_skip(&gb_chunk, 1); + s->have_srgb = 1; + break; case MKTAG('i', 'C', 'C', 'P'): { if ((ret = decode_iccp_chunk(s, &gb_chunk, p)) < 0) goto fail; @@ -1468,6 +1474,7 @@ static void clear_frame_metadata(PNGDecContext *s) s->stereo_mode = -1; s->have_chrm = 0; + s->have_srgb = 0; av_dict_free(&s->frame_metadata); } @@ -1486,6 +1493,9 @@ static int output_frame(PNGDecContext *s, AVFrame *f) memcpy(sd->data, s->iccp_data, s->iccp_data_len); av_dict_set(&sd->metadata, "name", s->iccp_name, 0); + } else if (s->have_srgb) { + avctx->color_primaries = f->color_primaries = AVCOL_PRI_BT709; + avctx->color_trc = f->color_trc = AVCOL_TRC_IEC61966_2_1; } else if (s->have_chrm) { AVColorPrimariesDesc desc; enum AVColorPrimaries prim; @@ -1504,8 +1514,8 @@ static int output_frame(PNGDecContext *s, AVFrame *f) av_log(avctx, AV_LOG_WARNING, "unknown cHRM primaries\n"); } - /* this chunk overrides gAMA */ - if (s->iccp_data) + /* these chunks overrides gAMA */ + if (s->iccp_data || s->have_srgb) av_dict_set(&s->frame_metadata, "gamma", NULL, 0); avctx->colorspace = f->colorspace = AVCOL_SPC_RGB; -- 2.39.0 _______________________________________________ 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".