From patchwork Fri Sep 4 06:28:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Manresa" X-Patchwork-Id: 28192 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D29A6C334D for ; Fri, 4 Sep 2026 06:28:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0E7B168602; Fri, 4 Sep 2026 08:28:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aIW0BDzk"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 56A34685FB for ; Fri, 4 Sep 2026 08:28:41 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-49a97714f5dso5060815e9.0 for ; Thu, 03 Sep 2026 23:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788503321; x=1789108121; darn=lists.libcamera.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:content-type; bh=vbuBEL+Sm45XiPnBHi31ELtmCqDk9FNm6xvNeLZclvk=; b=aIW0BDzkJmFrXnviQvmtv2/n6GCHFgrUe6WPqDgQVDnQJ/U++7FBYQItflbSYLBUMl 1hhMBHRtZSm0/ymyD6MlYM3UCNC/N4nc7f2NJ5BUO4m6jfSwHhM35+LZvG1EP1XAp+eU UNEyPtYi76GjWHdj8SRGed20CbTqUnHKvN9aYNQke7suqpoGEvmKKN2jXdIptTpuO0aF l175D/AlC7KYrY75jULuMt9ARfkiAiavLy2z97daf6cWqvdReVYf6X7u34crG1G6r4LQ mtsDak9liHUS/O3WDzFRnNx2r+lla2NM9Lj4XimruEJQuMbjnHuIskUDIPj73ANICgzb WIQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788503321; x=1789108121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=vbuBEL+Sm45XiPnBHi31ELtmCqDk9FNm6xvNeLZclvk=; b=BbzbfxlqLBB0xatGGm6aB+DWQlrciskAUBttij/dCn3C+KIv68+YXvNaoS2DAyP9w2 csenzXv6ZtPmt2SXPvsRmLncx/Vbnj1cbP31jt3Ke5m+vncX9DLXxkEumO6FSbmuKD3K UtrCj8FrP9Zrb5GpVlkfWmzpACeN9vQjhtZ+ksSH7bR2OuOr6yXJNEQkT4irouUd3qIb iC3wAgeZwJfyKs/pOdSFrSr82ANjoXNP81VdkL016z70rHlKojJdaLwgVZVue75zys4a kzGu5+sWGBfSgztPApq0qFo7bXA5E8LQss8F5GCNpi6R1TQ+ycx8P72w1Gh3EzQkjE2H 3DbQ== X-Gm-Message-State: AFuF++nVUHSkfb5yNdfFq/hXgfRlWiIIVp2Cf5jOTkzw9ofIizdAqdIr ewSGrS6Ro9OvKNfNoBc5U1tnWL6r3dnFQW+k3KdJv+PqJ5ZeOjXyBhJYl7+FeLHCiA== X-Gm-Gg: AYBFou0COoXyFydMqZpZWRM9ZaYXZuFnD8k4FB2UqeNav3SZnh9l15ExOQhYRBj6ezx 930KxuwFXgot8jzYsfNHNrnidqPt6ubydjFYCUR+RylR/K5lI/4M3GkzSoCEi4pl4ObyKZ1qlAU v8R9VRERjbSb19Ktea2Gqokkee0nOCqVIhjNU06D2St8cdg3nyYVEkn9THn7L5t1Iw3zPdydhnp dp4azMzFjW9EngFwKnP1465fNkDSrFzU+j/3KKuGxKWsv6AqQzPOhZsvKH1HnxoM4AdYfPaMyVv 2/MswXCNn2WNGM4L7k5q5ZkPVoep40+CNWknaHIk5eml76waRJurDzi68sOwHY9S4jWv1Ybu0bO CCZpS501xZaDCOLjtGRL7hUuFSQ7PSugHtuPPVe5eo9oWG10XJUkKlwoumaqn5u8zWeQcYwFjcp pDAWbIZkXT/VF4iHopaMINDTbrpAaSJcGtBdA+Qzxdz3CIeEiD22HpdPomIPRdaImNSnchhgQmT 5c6i3s5amrUfkOkyFXaYHBQWSucsAQhhbJ9UKwE3GxMo1f5 X-Received: by 2002:a05:600c:a087:b0:49c:fa20:cc07 with SMTP id 5b1f17b1804b1-49cfa20ccc6mr16723225e9.30.1788503320510; Thu, 03 Sep 2026 23:28:40 -0700 (PDT) Received: from latitude7275 (84.124.213.91.dyn.user.ono.com. [84.124.213.91]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cee5f9114sm125681225e9.5.2026.09.03.23.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 23:28:40 -0700 (PDT) From: "D. Manresa" To: libcamera-devel@lists.libcamera.org Cc: "D. Manresa" Subject: [PATCH 3/3] ipa: ipu3: tone_mapping: Make the gamma configurable Date: Fri, 4 Sep 2026 08:28:40 +0200 Message-ID: <20260904062840.46739-4-dmanresa@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904062840.46739-1-dmanresa@gmail.com> References: <20260904062840.46739-1-dmanresa@gmail.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The tone mapping algorithm hard-codes a gamma of 1.1, which produces an almost linear output and dark mid-tones for a display-referred consumer. Add an optional 'gamma' tuning parameter, keeping 1.1 as the default. While at it, document an observation made on a Dell Latitude 7275 with the IPU3 firmware currently distributed for Linux: in the video pipe the LUT contents are ignored and a fixed curve is applied whenever the gamma block is programmed (gammas of 0.5, 1.1 and 3.0 produce identical output), while leaving the block unprogrammed results in a linear ramp. Signed-off-by: D. Manresa --- src/ipa/ipu3/algorithms/tone_mapping.cpp | 37 +++++++++++++++++++++++- src/ipa/ipu3/algorithms/tone_mapping.h | 3 ++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/ipa/ipu3/algorithms/tone_mapping.cpp b/src/ipa/ipu3/algorithms/tone_mapping.cpp index 160338c..160b015 100644 --- a/src/ipa/ipu3/algorithms/tone_mapping.cpp +++ b/src/ipa/ipu3/algorithms/tone_mapping.cpp @@ -7,9 +7,14 @@ #include "tone_mapping.h" +#include #include #include +#include + +#include "libcamera/internal/value_node.h" + /** * \file tone_mapping.h */ @@ -26,9 +31,39 @@ namespace ipa::ipu3::algorithms { * generated based on a gamma parameter. */ +LOG_DEFINE_CATEGORY(IPU3ToneMapping) + +/* Historical default, kept for existing tuning files. */ +static constexpr double kDefaultGamma = 1.1; + ToneMapping::ToneMapping() - : gamma_(1.0) + : gamma_(1.0), tunedGamma_(kDefaultGamma) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + * + * The optional \a gamma tuning parameter sets the exponent of the encoding + * curve programmed in the ImgU gamma correction LUT, output = input^(1/gamma). + * The default is 1.1. + * + * Note that on the IPU3 firmware currently distributed for Linux + * (irci_irci_ecr-master_20161208_0213_20170112_1500) the video pipe applies + * a fixed curve when the gamma block is programmed and ignores the LUT + * contents: values of 0.5, 1.1 and 3.0 produce identical output, while not + * programming the block yields a linear ramp. The parameter is still useful + * to document the intent and for firmware that honours the LUT. + */ +int ToneMapping::init([[maybe_unused]] IPAContext &context, + const ValueNode &tuningData) { + tunedGamma_ = std::clamp(tuningData["gamma"].get().value_or(kDefaultGamma), + 0.5, 4.0); + + LOG(IPU3ToneMapping, Debug) << "Gamma " << tunedGamma_; + + return 0; } /** diff --git a/src/ipa/ipu3/algorithms/tone_mapping.h b/src/ipa/ipu3/algorithms/tone_mapping.h index b2b3801..6c12867 100644 --- a/src/ipa/ipu3/algorithms/tone_mapping.h +++ b/src/ipa/ipu3/algorithms/tone_mapping.h @@ -18,6 +18,8 @@ class ToneMapping : public Algorithm public: ToneMapping(); + int init(IPAContext &context, const ValueNode &tuningData) override; + int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override; @@ -28,6 +30,7 @@ public: private: double gamma_; + double tunedGamma_; }; } /* namespace ipa::ipu3::algorithms */