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 77337484CB for ; Sun, 4 Feb 2024 09:36:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7043C68D17D; Sun, 4 Feb 2024 11:36:09 +0200 (EET) Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB88868D14F for ; Sun, 4 Feb 2024 11:36:02 +0200 (EET) Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3bc21303a35so1178326b6e.0 for ; Sun, 04 Feb 2024 01:36:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707039361; x=1707644161; darn=ffmpeg.org; 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=tvOJWO40b9AKWcb884QDYCohflBmKbIezEfSfLJt5oE=; b=Ng834W5zB8ayDn8XaKwfYKiVbD/C3h7YtfPwizsA+TWGxqwvgaKm4VxwgaHoVIRqeb 1/Y/JyCsmZX1FHK/Oumw0SjjFcs8+grEWY6R/D4nl2c/dLE1XQUXCsLEgbNoAEqVGmcP VI0fx/Wvh+7hxmi3z7jFllNNNINVwjfaoPxtFgqZnSmHsr7Ei3A9XbFQlhYVd/Ah+9yY 43omuFtqQ+A8UFzqx8mo/Rz0NyyujRvODcabObNCwkfDVxyv0kpELgmYXJA/oStIruUe Lbw02KP9jCgWdvBP7NygwDIub+jBIy5WQB0Eu+K6hhnHWPMLiWfWfr3poBqTJfbIItUK rvSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707039361; x=1707644161; 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=tvOJWO40b9AKWcb884QDYCohflBmKbIezEfSfLJt5oE=; b=pbQZcmI4nPNJE9WGRlV7VYNUf+YlBM6rZcYgT9tHOYp4H0Ksbwvce20BViykrtiUeE yHx629bwrVNA5OU+P5AOgV3xQvpypvh57WezzfRrfl7wasFzzRSC6pzXgE3Sd8RG1FKI rbVRJaCGPfk3UTuRHqRKWd2nhFOaYXIttxZGhMQyGrnmo+2D92F7YAfrO3r+ZtmedE3a eiUD+l87w+uDqae+KwdeSyXL4Tj9nYv9Zb03mM17bH2imzDPCasrehqrqZ3kqdLt1PVR djIqPDOSHcci6YFgXkVhUtmInBhh3cHWA4LZ4k1sFD4duTnPqkdcfAcWaBaRTH//qOO2 onMQ== X-Gm-Message-State: AOJu0YzEg88FGETj/5S0yjSOVQ2UPw9p+yrfvuJm2HUnLCgvPvWnE0Xi VOX9+njAQNe3R9T2lIsGr7UUD1dN86EArDfSec8CBYayxOg9cUK7lr0rHtd7 X-Google-Smtp-Source: AGHT+IH10I4mlrh0uoYph4Ex9AAYg53sahwEKpkSl7OPqhX+SkLGZSLcOTDpOeBabjNNPW6sq5hvaQ== X-Received: by 2002:a9d:5914:0:b0:6dc:8bc:43f0 with SMTP id t20-20020a9d5914000000b006dc08bc43f0mr12388974oth.3.1707039360854; Sun, 04 Feb 2024 01:36:00 -0800 (PST) Received: from gauss.local (c-68-56-149-176.hsd1.mi.comcast.net. [68.56.149.176]) by smtp.gmail.com with ESMTPSA id lz8-20020a0562145c4800b006837a012417sm2594431qvb.51.2024.02.04.01.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 01:36:00 -0800 (PST) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Sun, 4 Feb 2024 04:35:57 -0500 Message-ID: <20240204093558.793427-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240204093558.793427-1-leo.izen@gmail.com> References: <20240204093558.793427-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/2] avcodec/pngdec: read cLLi and mDVc 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: These chunks contain the Content Light Level Information and the Mastering Display Color Volume information that FFmpeg already supports as AVFrameSideData. This patch adds support for the png decoder to read these chunks if present and attach the corresponding side data to the decoded frame. Signed-off-by: Leo Izen --- libavcodec/pngdec.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index d1aae4c70e..026da30c25 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -29,6 +29,7 @@ #include "libavutil/csp.h" #include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/pixfmt.h" #include "libavutil/rational.h" #include "libavutil/stereo3d.h" @@ -81,6 +82,14 @@ typedef struct PNGDecContext { enum AVColorPrimaries cicp_primaries; enum AVColorTransferCharacteristic cicp_trc; enum AVColorRange cicp_range; + int have_clli; + uint32_t clli_max; + uint32_t clli_avg; + int have_mdvc; + uint16_t mdvc_primaries[3][2]; + uint16_t mdvc_white_point[2]; + uint32_t mdvc_max_lum; + uint32_t mdvc_min_lum; enum PNGHeaderState hdr_state; enum PNGImageState pic_state; @@ -731,6 +740,36 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame) if (!s->has_trns && s->significant_bits > 0) avctx->bits_per_raw_sample = s->significant_bits; + if (s->have_clli) { + AVContentLightMetadata *clli = + av_content_light_metadata_create_side_data(frame); + if (!clli) + return AVERROR(ENOMEM); + /* + * 0.0001 divisor value + * see: https://www.w3.org/TR/png-3/#cLLi-chunk + */ + clli->MaxCLL = s->clli_max / 10000; + clli->MaxFALL = s->clli_avg / 10000; + } + + if (s->have_mdvc) { + AVMasteringDisplayMetadata *mdvc = + av_mastering_display_metadata_create_side_data(frame); + if (!mdvc) + return AVERROR(ENOMEM); + mdvc->has_primaries = 1; + for (int i = 0; i < 3; i++) { + mdvc->display_primaries[i][0] = av_make_q(s->mdvc_primaries[i][0], 50000); + mdvc->display_primaries[i][1] = av_make_q(s->mdvc_primaries[i][1], 50000); + } + mdvc->white_point[0] = av_make_q(s->mdvc_white_point[0], 50000); + mdvc->white_point[1] = av_make_q(s->mdvc_white_point[1], 50000); + mdvc->has_luminance = 1; + mdvc->max_luminance = av_make_q(s->mdvc_max_lum, 10000); + mdvc->min_luminance = av_make_q(s->mdvc_min_lum, 10000); + } + return 0; } @@ -1508,6 +1547,30 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, break; } + case MKTAG('c', 'L', 'L', 'i'): + if (bytestream2_get_bytes_left(&gb_chunk) != 8) { + av_log(avctx, AV_LOG_WARNING, "Invalid cLLi chunk size: %d\n", bytestream2_get_bytes_left(&gb_chunk)); + break; + } + s->have_clli = 1; + s->clli_max = bytestream2_get_be32u(&gb_chunk); + s->clli_avg = bytestream2_get_be32u(&gb_chunk); + break; + case MKTAG('m', 'D', 'V', 'c'): + if (bytestream2_get_bytes_left(&gb_chunk) != 24) { + av_log(avctx, AV_LOG_WARNING, "Invalid mDVc chunk size: %d\n", bytestream2_get_bytes_left(&gb_chunk)); + break; + } + s->have_mdvc = 1; + for (int i = 0; i < 3; i++) { + s->mdvc_primaries[i][0] = bytestream2_get_be16u(&gb_chunk); + s->mdvc_primaries[i][1] = bytestream2_get_be16u(&gb_chunk); + } + s->mdvc_white_point[0] = bytestream2_get_be16u(&gb_chunk); + s->mdvc_white_point[1] = bytestream2_get_be16u(&gb_chunk); + s->mdvc_max_lum = bytestream2_get_be32u(&gb_chunk); + s->mdvc_min_lum = bytestream2_get_be32u(&gb_chunk); + break; case MKTAG('I', 'E', 'N', 'D'): if (!(s->pic_state & PNG_ALLIMAGE)) av_log(avctx, AV_LOG_ERROR, "IEND without all image\n"); -- 2.43.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".