From patchwork Mon Jan 26 10:42:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick ten Wolde X-Patchwork-Id: 25961 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 3AEA5C328D for ; Mon, 26 Jan 2026 10:48:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CF78D61FD6; Mon, 26 Jan 2026 11:48:11 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UY0b3RIO"; dkim-atps=neutral Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 87E3061FCB for ; Mon, 26 Jan 2026 11:43:05 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-b885e8c6700so504149366b.0 for ; Mon, 26 Jan 2026 02:43:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769424185; x=1770028985; 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; bh=BuGJ6GBXuA/foj3gVZf4nP7l068XJowglMv0fhOWjtQ=; b=UY0b3RIO+IG52Cg/rNTLsMTfeLbFH3aRqt/vVFGwNVftjmF+9VXAO25NHB/bD9Vp8u 2uRwdLwn7UyB/gX/kp/qlUwuUN6q+43Kw/z9co4QBJOvCykTEtZEq/q29RJcM+1MhA7t kSsV5CHQaxLxXwkx4031SBSrrOU4Go5EMDKiPvCtJIYJPqWqtiAKp27v1RYehv0MlShJ Ba6+x7PY2d6gwxADGbZne3wHta6DdP4Pxe3Cis9izEbEbUADnXTjSq+kiZVOW1QywCC5 2hcDpMM7uAknCTA9P/zeT61RdsskCB+s0j1YbyYu766nvCxHHY1u3dJYUQsJ58/ZrT6o CRjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769424185; x=1770028985; 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; bh=BuGJ6GBXuA/foj3gVZf4nP7l068XJowglMv0fhOWjtQ=; b=lRCe9NcB/v9U/e4NAaqsxsePPWOxU/Zscl0DlEVSw2Bf+hZOnRWyxA9qMf5po5fnwn z0sO892g4z2WH8KUoNGqS7XeTt+zFgpA/uWSHVScI1zNDpUP6v4xBxUKY6ekX61navaq PgEZ67QyD+KDMkEGEdFQhIyvCMsUKhx5OKtcmTdqdA16Pead6ek+NLpCnbLZ9D2J1xUX o4aGR2VlCkq5n193aNUQARzJ/qkdra4XJViTXjV2td/y3WCckxiF0QJyBnLqH42IpMES gNcrAL7VxCz1xakGW84MzCaVMZcFhOcLkTpFJMBytoRHZ43qiXWUuuPGDNbY7Y6V+J92 aHrA== X-Gm-Message-State: AOJu0YwaJNT452I6mEjfO8jUA9CxRrmMIa/bCae6lVDM7jazVW66n6iT 2FpJysO5NekQ9zhvscAXbfBwQIBOFuQHvqTOjLt8R/MY82dntavnbFvgZ2zPPw== X-Gm-Gg: AZuq6aJVPf2s0jpI/KDssnQtbOAUwEyRQLkoa1MJH4xfdOItDmpfume4V+IkpBfOzlZ wxDK59jIq1udXzAQlPLzmkP79COPkwm4UehjjVTw1BaIQgMMMqw9bfavG3rIJI5tlbZjv+fqGvQ +c7MdhsU85nX+msGhWnp7Zstfyu/Ho44TruL4UuZYC/dHsyRkb6SwswqdNXvHMivxH3jMx0gaz5 VsklqVXd3Cyu5qB4t/euEGD/uNjjxgeKVB7qkuoUvgKR9JhN3rGWp801ZEVUrxW7OFcneUE7EL5 8A96YjhXKwUHJu0PMnXmQMgGPIICTXqK4x9o9PBiFbBDJzMvS6tsIsQajc6vxaW7RLZAIhBOTzT m42dhxrClLMRvKyEiscW5Nnu8YAy5aI6WRTGbxrjOmD0/0oTxxsw+tQGXpxpLRikbKjKPY87BmE yEjETPUI6vwdB6kIfAT8rK5D6RSKURzp4YDWGGxNhIZv0PLrcAU+OtGTvby3Y2660= X-Received: by 2002:a17:907:1c15:b0:b88:5957:2d65 with SMTP id a640c23a62f3a-b8d20e49d2dmr287851366b.37.1769424184303; Mon, 26 Jan 2026 02:43:04 -0800 (PST) Received: from castortop.wolde.loc (195-240-110-192.fixed.kpn.net. [195.240.110.192]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b885b7661f7sm599220366b.54.2026.01.26.02.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 02:43:03 -0800 (PST) From: Rick ten Wolde To: libcamera-devel@lists.libcamera.org Cc: xander.c.pronk@gmail.com, derekgielen@outlook.com, 22012540@student.hhs.nl, rick.w.ten.wolde@gmail.com, johannes.goede@oss.qualcomm.com, Rick ten Wolde Subject: [PATCH 3/7] ipa: simple: Add LSC algorithm Date: Mon, 26 Jan 2026 11:42:51 +0100 Message-ID: <20260126104256.119697-4-rick.w.ten.wolde@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260126104256.119697-1-rick.w.ten.wolde@gmail.com> References: <20260126104256.119697-1-rick.w.ten.wolde@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 26 Jan 2026 11:48:05 +0100 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" From: Xander Pronk Add LSC algorithm module. Co-authored-by: Rick ten Wolde Signed-off-by: Rick ten Wolde Signed-off-by: Xander Pronk --- src/ipa/simple/algorithms/lsc.cpp | 69 +++++++++++++++++++++++++++ src/ipa/simple/algorithms/lsc.h | 49 +++++++++++++++++++ src/ipa/simple/algorithms/meson.build | 1 + 3 files changed, 119 insertions(+) create mode 100644 src/ipa/simple/algorithms/lsc.cpp create mode 100644 src/ipa/simple/algorithms/lsc.h diff --git a/src/ipa/simple/algorithms/lsc.cpp b/src/ipa/simple/algorithms/lsc.cpp new file mode 100644 index 00000000..95783e4e --- /dev/null +++ b/src/ipa/simple/algorithms/lsc.cpp @@ -0,0 +1,69 @@ +#include "lsc.h" + +#include + +#include +#include + +#include + +#include "libcamera/internal/matrix.h" + + +namespace libcamera { + +namespace ipa::soft::algorithms { + +LOG_DEFINE_CATEGORY(IPASoftLsc) +int Lsc::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) +{ + int ret_r = lsc_r.readYaml(tuningData["grids"], "ct", "r"); + int ret_g = lsc_r.readYaml(tuningData["grids"], "ct", "g"); + int ret_b = lsc_r.readYaml(tuningData["grids"], "ct", "b"); + + if (ret_r < 0 || ret_g < 0 || ret_b < 0) { + LOG(IPASoftLsc, Error) + << "Failed to parse 'lsc' parameter from tuning file."; + return -1; + } + + return 0; +} + +int Lsc::configure([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const IPAConfigInfo &configInfo) +{ + return 0; +} + + +void Lsc::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params) +{ + unsigned int ct = context.activeState.awb.temperatureK; + if (ct == 0) + ct = 2700; + const Matrix matrix_r = lsc_r.getInterpolated(ct); + const Matrix matrix_g = lsc_r.getInterpolated(ct); + const Matrix matrix_b = lsc_r.getInterpolated(ct); + + for (unsigned long i = 0; i < matrix_r.data().size(); ++i) { + params->LSC_red[i] = matrix_r.data()[i]; + params->LSC_green[i] = matrix_g.data()[i]; + params->LSC_blue[i] = matrix_b.data()[i]; + } +} + +void Lsc::process([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + [[maybe_unused]] const SwIspStats *stats, + [[maybe_unused]] ControlList &metadata) +{ +} + +REGISTER_IPA_ALGORITHM(Lsc, "Lsc") + +} /* namespace ipa::soft::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/simple/algorithms/lsc.h b/src/ipa/simple/algorithms/lsc.h new file mode 100644 index 00000000..8a3123ad --- /dev/null +++ b/src/ipa/simple/algorithms/lsc.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024-2025, Red Hat Inc. + * + * Color correction matrix + */ + +#pragma once + +#include + +#include "libcamera/internal/matrix.h" + +#include + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::soft::algorithms { + + +class Lsc : public Algorithm +{ +public: + Lsc() = default; + ~Lsc() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + int configure(IPAContext &context, + const IPAConfigInfo &configInfo) override; + void prepare(IPAContext &context, + const uint32_t frame, + IPAFrameContext &frameContext, + DebayerParams *params) override; + void process(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + const SwIspStats *stats, + ControlList &metadata) override; + +private: + Interpolator> lsc_r; + Interpolator> lsc_g; + Interpolator> lsc_b; +}; + +} /* namespace ipa::soft::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build index 2d0adb05..9cfc8030 100644 --- a/src/ipa/simple/algorithms/meson.build +++ b/src/ipa/simple/algorithms/meson.build @@ -6,4 +6,5 @@ soft_simple_ipa_algorithms = files([ 'blc.cpp', 'ccm.cpp', 'lut.cpp', + 'lsc.cpp', ])