From patchwork Fri Jul 22 15:16:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16734 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 AE590BD1F1 for ; Fri, 22 Jul 2022 15:16:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 675BE63318; Fri, 22 Jul 2022 17:16:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658503007; bh=pMzNI7g/tFbiOPklsa+5EIbxGf0di9GSiColgaj2RLM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=2SRKZKqeSL7aDQTk94mb8Fy/3Pfu048wC9+ehaGDVA3W3wuFoarczA8pG5mcvK6sx JA9hKOj8EhkDO0D7hmpsRu2Qv9AoIrjSuXRNR3CcuqD964ItlgQuHPcJW6HiOKGss8 q4kR7j3qoGsXZg4bbRj5zT5Lxrp5ceZOlfB6u1joS+fX8yNPK6ylJACKvZFFY3A6OS PaGR7sdemHxHuPOKVTZHmsaZHqNruiQBse7CDnLyjxBYytqiEdP1EQvrdozWnIQzoC VVK8fXiJvDkQ09RnfRE9Se9FpdcIz+YGXJZjI8OTKeZqxHk2gWEgyTePW7qgsuJwOX v4fWfF7OgR1iA== Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CD7C863313 for ; Fri, 22 Jul 2022 17:16:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="gX0b9CIz"; dkim-atps=neutral Received: by mail-wr1-x42a.google.com with SMTP id h9so6979995wrm.0 for ; Fri, 22 Jul 2022 08:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m7hUmiaKzanMb2eUzI916OaV1LitMalvbU40wiWSryc=; b=gX0b9CIzCIJV45UAC8oEJpx39U6HMCh1mTKKpfvs+fJjsULfE8JKLLSW9yzfz1FleI oauBy7kbxLMxlHoAqBo+r5KJyqNKN2D/6yVxAW1zZ82GTyip4F2yK2P2Jp4SGawknCsP SiYNuMnb0SQqWFIm3YTh6+7Q1rcqGZXuYYrIDI5VR/nhci6z1a4BmJjL5IVC7Qs7e4IG IHtLQEPdlLzW/hE2rnaVRYNMotSKvst9HFYw2ix1aAtYytlFaUFMoU+a3Vk4nC91z6Lp ThJK8eVORRGii4ykUp5UyIv981AZGMYuscG7g8IY4crhuLdhlJIQGNVen+MH6qUfkT1M 3jYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m7hUmiaKzanMb2eUzI916OaV1LitMalvbU40wiWSryc=; b=OrFdEdRUysDLiI9iMLBl7IlHnkKZahGUndHv1sZYbU7U8YW9pn37IJGQEQQd2tN2di M4F6UaRgLtSybnJeN1jrqOfUB7P71+r4mHEnlIUkn6s4fDPPWDbDls58q0pvd16y0URs Sp0dVG3CaDEOSEPeYAkmIMXuT2WM6KxcIVBvgwwXQXMRyrXheesb1FOhlGKEKudM3/mf yk170jnwHmQoEADpkULc8AQiE7YrrU79SX0+Z1qktPvXo1FjZFaxDhSpKWWuwhYutzvE XhmFyY7dPBG2RVuTIc8xjQsyctbqqBl3KmVH4JAE8pcSKjHWc0iHrBl143Rj5HhnSeZa chSA== X-Gm-Message-State: AJIora/HlT6mYxgRCGHyz92xCIOa5IpKsuG75tGEnIDXKQsMVuOimzIk pvaR6TS33r2c/M1Zt3l8CVzns50Wf2iYoQH+ X-Google-Smtp-Source: AGRyM1uMTXsACDZrKMEsZHAxrFkRR610oGE/gyz72LdNVr0x0QLvhkERpQCsPH8TIgoE0I/HonxjPg== X-Received: by 2002:a5d:5847:0:b0:21d:b75e:12d0 with SMTP id i7-20020a5d5847000000b0021db75e12d0mr294379wrf.208.1658503004069; Fri, 22 Jul 2022 08:16:44 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:e9da:4076:6aa:6cd2]) by smtp.gmail.com with ESMTPSA id b1-20020a5d4d81000000b0021e4fd8e10bsm4871557wru.11.2022.07.22.08.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 08:16:43 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jul 2022 17:16:31 +0200 Message-Id: <20220722151635.239221-2-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722151635.239221-1-fsylvestre@baylibre.com> References: <20220722151635.239221-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/5] libcamera: yaml_parser: Add getList() function 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: , X-Patchwork-Original-From: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Allow to retrieve a YAML list of any already supported types in a std::vector. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- include/libcamera/internal/yaml_parser.h | 16 ++++++ src/libcamera/yaml_parser.cpp | 66 ++++++++++++++++++++++++ test/yaml-parser.cpp | 6 +++ 3 files changed, 88 insertions(+) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 064cf443..39161bbb 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -167,6 +167,22 @@ public: #endif T get(const T &defaultValue, bool *ok = nullptr) const; +#ifndef __DOXYGEN__ + template || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v> * = nullptr> +#else + template +#endif + std::vector getList(bool *ok = nullptr) const; + DictAdapter asDict() const { return DictAdapter{ dictionary_ }; } ListAdapter asList() const { return ListAdapter{ list_ }; } diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 5c45e44e..125a348e 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -325,6 +325,72 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const #endif /* __DOXYGEN__ */ +/** + * \fn template YamlObject::getList(bool *ok) const + * \brief Parse the YamlObject as a list of \a T + * \param[out] ok The result of whether the parse succeeded + * + * This function parses the value of the YamlObject as a list of \a T objects, + * and returns the value as a \a std::vector. If parsing fails \a ok is set + * to false and a default empty vector is returned. Otherwise, the + * YamlObject list of values is returned, and \a ok is set to true. + * + * The \a ok pointer is optional and can be a nullptr if the caller doesn't + * need to know if parsing succeeded. + * + * \return Value as a std::vector type + */ + +#ifndef __DOXYGEN__ + +template || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v> *> +std::vector YamlObject::getList(bool *ok) const +{ + setOk(ok, false); + + if (type_ != Type::List) + return {}; + + std::vector value; + value.reserve(list_.size()); + + /* + * Provide somme dummy defaultValue to get() function and rely on the + * ok variable to know if the parsing was correct. + */ + T defaultValue{}; + + for (const YamlObject &entry : asList()) { + bool result; + value.emplace_back(entry.get(defaultValue, &result)); + if (!result) + return {}; + } + + setOk(ok, true); + return value; +} + +template std::vector YamlObject::getList(bool *ok) const; +template std::vector YamlObject::getList(bool *ok) const; +template std::vector YamlObject::getList(bool *ok) const; +template std::vector YamlObject::getList(bool *ok) const; +template std::vector YamlObject::getList(bool *ok) const; +template std::vector YamlObject::getList(bool *ok) const; +template std::vector YamlObject::getList(bool *ok) const; +template std::vector YamlObject::getList(bool *ok) const; + +#endif /* __DOXYGEN__ */ + /** * \fn YamlObject::asDict() const * \brief Wrap a dictionary YamlObject in an adapter that exposes iterators diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 38f84823..bb96a11b 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -524,6 +524,12 @@ protected: return TestFail; } + std::vector values = firstElement.getList(); + if (values.size() != 2 || values[0] != 1 || values[1] != 2) { + cerr << "getList() failed to return correct vector" << std::endl; + return TestFail; + } + auto &secondElement = level2Obj[1]; if (!secondElement.isDictionary() || !secondElement.contains("one") || From patchwork Fri Jul 22 15:16:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16735 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 9AD34BD1F1 for ; Fri, 22 Jul 2022 15:16:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 370256331A; Fri, 22 Jul 2022 17:16:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658503008; bh=e3gnoIE7hd1H2qwFxVryzwpZZW6NgAb9iQnQIzAeH5Q=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QOn6ebpYWsRvPq1kiRQ17mx2qUsLo8JuaF5oW7ytF81PJ9I1/BgrH5xgQ+rwYSO7X HgXdegHzRFtY0MNhuEzCL4VSQEy8KRzO1raretdlyMRh1hTc7Yux4KACofrxJbQgCO zKAy5TCzKlba20051fVx0w5VcVQwUzb0RgrYUjTZwwq0OEqYmN4u6WWR7twl6lmF6z ldJzfSNECDtlCTfaFAM73Z4kt/6PjeWPDu3S12IA4BXFFKog6QQjMvIuzU7MSM/0kp UuzxZit4EHkyMMot5+SYUBU0KP3saUKRwu8yg0ormLrQC1te0JfybDeM61PTdu0Kli H5d05S2UNpWQw== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B3A01603F5 for ; Fri, 22 Jul 2022 17:16:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="Uerl0jVl"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id ay11-20020a05600c1e0b00b003a3013da120so5376449wmb.5 for ; Fri, 22 Jul 2022 08:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7No+ATRUBr79WnsG3uZbVTv6ZwY75D8K0UmViluBK9E=; b=Uerl0jVl0VgGI8u2HFyphtrdm952s7gCLfb6YiKL6L3+4gEmRZ7KwOAZFeEwDBXQbD bIEgn0vfnllMjE5SvL1LEMybHRqCQBPpzwkfBhaepsDqZehcWPGu51DI0KZe4FMJku2s dXq+rX3zI4xaxp6j84nH4uMD7zDIIXZXXZaniUduw3ADicjLXIkWHRQKLsUcnkkZjW31 M+L33ydIsizNmR0C81kxw3baiDolV5KdHZEunvJf6/UC7znqErZI6vWijb8RF8YFrK/P BvEiFXImjTw+VL+eAa3SePax1bOomQrDz8TwwnvKgul90h3D6yb+v/+LuBIs8/pF0mVk /TXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7No+ATRUBr79WnsG3uZbVTv6ZwY75D8K0UmViluBK9E=; b=T9IGtfWU/IA+ZqxS5JDngH7ntc804VcmsZSy77JtR5exgFCMBlH5JFBCHEvNyh8rPi 6hT0stCe6PBXD08l+WO9CirtNFB9CA4747VMKEVB9xDwBvZ6rqXIhIrOjOMp3UiDudDq noougw/PfTNKRLHEIs7w/4N6eMY4H5RZCj7+mUmtMnGayxCPov3zFCDfFkWqxCw12nut TrB5Bj2tfX4XhldOSQ/kkjmLf8pN42bvD9d9TTolkUzkmceXzYl6EAW3bQe/aapswDmW C/iHAd2xjBT506S7oTvhQ6t+8JKFqxkZCeK4EWM1ucK3OwW261O43ZGNZWxlEJrOlYna MTxg== X-Gm-Message-State: AJIora/15IDCwvX1xiVfkwDb14CuKJOAwejD4d2iuO8Oc8YLb3iU2He5 CXs8I3jRhtOuI9wl+ooZDaBYSKpkSfdL4f8y X-Google-Smtp-Source: AGRyM1uThCey8dPEKVOAZ5WGBN1grPll2fcXaDcMnuLXAz0ZlxA120dqIAO1+KipYN7zNzlyurfbOg== X-Received: by 2002:a05:600c:4e0d:b0:3a3:bc7:e9ec with SMTP id b13-20020a05600c4e0d00b003a30bc7e9ecmr13028937wmq.167.1658503005003; Fri, 22 Jul 2022 08:16:45 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:e9da:4076:6aa:6cd2]) by smtp.gmail.com with ESMTPSA id b1-20020a5d4d81000000b0021e4fd8e10bsm4871557wru.11.2022.07.22.08.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 08:16:44 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jul 2022 17:16:32 +0200 Message-Id: <20220722151635.239221-3-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722151635.239221-1-fsylvestre@baylibre.com> References: <20220722151635.239221-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/5] ipa: rkisp1: Add support of Gamma Sensor Linearization control 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: , X-Patchwork-Original-From: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The GammaSensorLinearization algorithm improves the image dynamic using a coefficient table in the YAML tuning file. The GammaSensorLinearization algorithm linearizes the sensor output to compensate the sensor non-linearities by applying piecewise linear curves to the red, green and blue channels. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/rkisp1/algorithms/gsl.cpp | 147 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/gsl.h | 34 ++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 6 ++ src/ipa/rkisp1/rkisp1.cpp | 1 + 5 files changed, 189 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/gsl.cpp create mode 100644 src/ipa/rkisp1/algorithms/gsl.h diff --git a/src/ipa/rkisp1/algorithms/gsl.cpp b/src/ipa/rkisp1/algorithms/gsl.cpp new file mode 100644 index 00000000..1680ddc3 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/gsl.cpp @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * gsl.cpp - RkISP1 Gamma Sensor Linearization control + */ + +#include "gsl.h" + +#include + +#include "libcamera/internal/yaml_parser.h" + +#include "linux/rkisp1-config.h" + +/** + * \file gsl.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class GammaSensorLinearization + * \brief RkISP1 Gamma Sensor Linearization control + * + * This algorithm linearizes the sensor output to compensate the sensor + * non-linearities by applying piecewise linear curves to the red, green and + * blue channels. + * + * The curves are specified in the tuning data and defined using 17 points. + * + * - The X coordinates are expressed using 16 intervals, with the first point + * at X coordinate 0. Each interval is expressed as a 2-bit value DX (from + * GAMMA_DX_1 to GAMMA_DX_16), stored in the RKISP1_CIF_ISP_GAMMA_DX_LO and + * RKISP1_CIF_ISP_GAMMA_DX_HI registers. The real interval is equal to + * \f$2^{dx+4}\f$. X coordinates are shared between the red, green and blue + * curves. + * + * - The Y coordinates are specified as 17 values separately for the + * red, green and blue channels, with a 12-bit resolution. Each value must be + * in the [-2048, 2047] range compared to the previous value. + */ + +LOG_DEFINE_CATEGORY(RkISP1Gsl) + +static constexpr unsigned int kDegammaXIntervals = 16; + +GammaSensorLinearization::GammaSensorLinearization() + : initialized_(false) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context, + const YamlObject &tuningData) +{ + std::vector xIntervals = tuningData["x-intervals"].getList(); + if (xIntervals.size() != kDegammaXIntervals) { + LOG(RkISP1Gsl, Error) + << "Invalid 'x' coordinates: expected " + << kDegammaXIntervals << " elements, got " + << xIntervals.size(); + + return -EINVAL; + } + + /* Compute gammaDx_ intervals from xIntervals values */ + gammaDx_[0] = 0; + gammaDx_[1] = 0; + for (unsigned int i = 0; i < kDegammaXIntervals; ++i) + gammaDx_[i / 8] |= (xIntervals[i] & 0x07) << ((i % 8) * 4); + + const YamlObject &yObject = tuningData["y"]; + if (!yObject.isDictionary()) { + LOG(RkISP1Gsl, Error) + << "Issue while parsing 'y' in tuning file: " + << "entry must be a dictionary"; + return -EINVAL; + } + + curveYr_ = yObject["red"].getList(); + if (curveYr_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { + LOG(RkISP1Gsl, Error) + << "Invalid 'y:red' coordinates: expected " + << RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE + << " elements, got " << curveYr_.size(); + return -EINVAL; + } + + curveYg_ = yObject["green"].getList(); + if (curveYg_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { + LOG(RkISP1Gsl, Error) + << "Invalid 'y:green' coordinates: expected " + << RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE + << " elements, got " << curveYg_.size(); + return -EINVAL; + } + + curveYb_ = yObject["blue"].getList(); + if (curveYb_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { + LOG(RkISP1Gsl, Error) + << "Invalid 'y:blue' coordinates: expected " + << RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE + << " elements, got " << curveYb_.size(); + return -EINVAL; + } + + initialized_ = true; + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void GammaSensorLinearization::prepare(IPAContext &context, + rkisp1_params_cfg *params) +{ + if (context.frameContext.frameCount > 0) + return; + + if (!initialized_) + return; + + params->others.sdg_config.xa_pnts.gamma_dx0 = gammaDx_[0]; + params->others.sdg_config.xa_pnts.gamma_dx1 = gammaDx_[1]; + + std::copy(curveYr_.begin(), curveYr_.end(), + params->others.sdg_config.curve_r.gamma_y); + std::copy(curveYg_.begin(), curveYg_.end(), + params->others.sdg_config.curve_g.gamma_y); + std::copy(curveYb_.begin(), curveYb_.end(), + params->others.sdg_config.curve_b.gamma_y); + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_SDG; + params->module_ens |= RKISP1_CIF_ISP_MODULE_SDG; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_SDG; +} + +REGISTER_IPA_ALGORITHM(GammaSensorLinearization, "GammaSensorLinearization") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/gsl.h b/src/ipa/rkisp1/algorithms/gsl.h new file mode 100644 index 00000000..db287dc2 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/gsl.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * gsl.h - RkISP1 Gamma Sensor Linearization control + */ + +#pragma once + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class GammaSensorLinearization : public Algorithm +{ +public: + GammaSensorLinearization(); + ~GammaSensorLinearization() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + +private: + bool initialized_; + uint32_t gammaDx_[2]; + std::vector curveYr_; + std::vector curveYg_; + std::vector curveYb_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 7ec53d89..0597c353 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -4,4 +4,5 @@ rkisp1_ipa_algorithms = files([ 'agc.cpp', 'awb.cpp', 'blc.cpp', + 'gsl.cpp', ]) diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index 232d8ae8..13f76412 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -10,4 +10,10 @@ algorithms: Gr: 256 Gb: 256 B: 256 + - GammaSensorLinearization: + x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] + y: + red: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] + green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] + blue: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] ... diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 4018265c..1c002939 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -31,6 +31,7 @@ #include "algorithms/algorithm.h" #include "algorithms/awb.h" #include "algorithms/blc.h" +#include "algorithms/gsl.h" #include "libipa/camera_sensor_helper.h" #include "ipa_context.h" From patchwork Fri Jul 22 15:16:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16736 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 19F03BD1F1 for ; Fri, 22 Jul 2022 15:16:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C795A6331E; Fri, 22 Jul 2022 17:16:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658503009; bh=uIQRt3tgLBP2wUuVLW3iScSP9ZCGC1V+KOdc1uSOlU4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aNa77w8AeUOICOGmnqndxoTbkWWNE8pHCBGU0c6XbHB5KZTXbM+0z1ufwdGJTfS+U lYEb4X/tO5vw3Tby5+MqUTWjRWA4aj32m/Mk6sluZj5nmSA2P3ZWweaLzvp9oEEjfU wGKy/9RTgsY7qA86EhE50P/Sn9VJOWMBuHKiYV31/50GZ+0ghtTwsyVrIpJXsFHiku /CbgqVwVquBJcmyF+KejD805dBmUSSHFlf5W2mkyfEd4gZWvbHI0ZmzNKgGBA9R89K yfH6WodqLDC5uN6TSwRVUf66karHZqOxIF7ZLMJWjmLoAI/X8vnwfgSSgzmGA4oVm4 0BD+r6FtxD7VQ== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C400B63313 for ; Fri, 22 Jul 2022 17:16:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="OEo6D+Jp"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id l15so2883200wro.11 for ; Fri, 22 Jul 2022 08:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0GDsfgHnGEmlcwmNDd4pSttSpqPQsfWll1BGmVaQbT0=; b=OEo6D+Jp2y4+NYnekHG5DsIufNxOfv9Xnti6AlZnEXEP2oCIpWM/g95ZETHA6PWoXo G2be2UpmrUoE+nOy3dAnTSU40xn6XhNaJpO0oGauzLSPi8BTNXdeomYMgnOR36qlDPE1 naM4TgXv5FlZHNtE56LDLnt8eg1G0Zc2RiQuLC5wjTB/4VdUhqFMEXv47a7n2BSsj40r tiMp7/8uy+w3F68R1cK7CJQ3zwyUZeXZjdtiut41ESOMZX43oli3mgkgrK8qJP8H8loj dacPVyz6L5pl5mmWK/n9squNrDvqPn743yt2k2pd4z2Qsj5aLIZ+mDDx350iTq+tWV++ bExA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0GDsfgHnGEmlcwmNDd4pSttSpqPQsfWll1BGmVaQbT0=; b=MMAnuvxvlo+MmqyNcH86hEwnFsr41L2y3kl3Es8eLQ3gGT9KuKLV7+NSOL4Yg+ScVd GAPhUtWh2U+KCBU+aEe7lAItIqwebj3lSMYRTFIL1F8NzU/WTeaQxDMW1wp41Z3ItB8a lN1GltCGpjmXcWXZjBDVl/ouz95tnPk6nNZDCN10VE5u1ek3CBOHRElPTX0PzsoDV5/+ DTkadiMkJL0fUEqtWsDdpuZ6y6fidcXkVdS7C216atGFjrCoIKDJKE74A/kzw7mD7ovq HkWOzfD/SHy8wGqQH5dDDyuzgCJ7VHKAXI1D8t1PHqg/HFcm+XNDR+Q+umlr/j0ueqOa dEDQ== X-Gm-Message-State: AJIora91v2mkKo//IYRaP93vN1UMLIae3lfl/NmJUuHJI74F+bMjhVfr DIWN1kBNjl7E6ruRxpWJZ/rr7bcIAdJdqsYW X-Google-Smtp-Source: AGRyM1tUrxC7H9CF4XbxpHysuutF5xWyviWro9ofyb12CXFLJY3ilAOLjqzWC86+Gkw8vXUVLrqBVA== X-Received: by 2002:a5d:45d0:0:b0:21e:48a5:660e with SMTP id b16-20020a5d45d0000000b0021e48a5660emr301357wrs.122.1658503005850; Fri, 22 Jul 2022 08:16:45 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:e9da:4076:6aa:6cd2]) by smtp.gmail.com with ESMTPSA id b1-20020a5d4d81000000b0021e4fd8e10bsm4871557wru.11.2022.07.22.08.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 08:16:45 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jul 2022 17:16:33 +0200 Message-Id: <20220722151635.239221-4-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722151635.239221-1-fsylvestre@baylibre.com> References: <20220722151635.239221-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/5] ipa: rkisp1: Add support of Lens Shading Correction control 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: , X-Patchwork-Original-From: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Lens Shading Correction algorithm applies a correction on the pixels based on values defined in the YAML tuning file. Signed-off-by: Florian Sylvestre --- src/ipa/rkisp1/algorithms/lsc.cpp | 170 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/lsc.h | 38 ++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 79 ++++++++++++ src/ipa/rkisp1/ipa_context.h | 1 + src/ipa/rkisp1/rkisp1.cpp | 2 + 6 files changed, 291 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/lsc.cpp create mode 100644 src/ipa/rkisp1/algorithms/lsc.h diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp new file mode 100644 index 00000000..8a53bc74 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -0,0 +1,170 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * lsc.cpp - RkISP1 Lens Shading Correction control + */ + +#include "lsc.h" + +#include + +#include + +#include "libcamera/internal/yaml_parser.h" + +#include "linux/rkisp1-config.h" + +/** + * \file lsc.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class LensShadingCorrection + * \brief RkISP1 Lens Shading Correction control + * + * Due to the optical characteristics of the lens, the light intensity received + * by the sensor is not uniform. + * + * The Lens Shading Correction algorithm applies a correction on the pixels for + * each component based on measurement done during the camera tuning process. + */ + +LOG_DEFINE_CATEGORY(RkISP1Lsc) + +LensShadingCorrection::LensShadingCorrection() + : initialized_(false) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int LensShadingCorrection::init([[maybe_unused]] IPAContext &context, + const YamlObject &tuningData) +{ + xSize_ = tuningData["x-size"].getList(); + if (xSize_.size() != RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'x-size'" + << "in tuning file (list size:" + << xSize_.size() << "/" + << RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE << ")"; + return -EINVAL; + } + + ySize_ = tuningData["y-size"].getList(); + if (ySize_.size() != RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'y-size'" + << "in tuning file (list size:" + << ySize_.size() << "/" + << RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE << ")"; + return -EINVAL; + } + + rData_ = tuningData["r"].getList(); + if (rData_.size() != RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'r'" + << "in tuning file (list size:" + << rData_.size() << "/" + << RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX << ")"; + return -EINVAL; + } + + grData_ = tuningData["gr"].getList(); + if (grData_.size() != RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'gr'" + << "in tuning file (list size:" + << grData_.size() << "/" + << RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX << ")"; + return -EINVAL; + } + + gbData_ = tuningData["gb"].getList(); + if (gbData_.size() != RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'gb'" + << "in tuning file (list size:" + << gbData_.size() << "/" + << RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX << ")"; + return -EINVAL; + } + + bData_ = tuningData["b"].getList(); + if (bData_.size() != RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'b'" + << "in tuning file (list size:" + << bData_.size() << "/" + << RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX << ")"; + return -EINVAL; + } + + initialized_ = true; + + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void LensShadingCorrection::prepare(IPAContext &context, + rkisp1_params_cfg *params) +{ + if (context.frameContext.frameCount > 0) + return; + + if (!initialized_) + return; + + Size total_size{}; + + for (unsigned int i = 0; i < RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE; ++i) { + struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config; + Size &size = context.configuration.sensor.size; + + config.x_size_tbl[i] = xSize_[i] * size.width; + config.y_size_tbl[i] = ySize_[i] * size.height; + total_size.width += config.x_size_tbl[i]; + total_size.height += config.y_size_tbl[i]; + + /* + * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and + * y_size_tbl items shall be equal to respectively size.width/2 and + * size.height/2. Enforce it by computing the last tables value. + */ + if (i == RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE - 1) { + config.x_size_tbl[i] += total_size.width - size.width / 2; + config.y_size_tbl[i] += total_size.height - size.height / 2; + } + + config.x_grad_tbl[i] = round(32768 / config.x_size_tbl[i]); + config.y_grad_tbl[i] = round(32768 / config.y_size_tbl[i]); + } + + std::copy(rData_.begin(), rData_.end(), + ¶ms->others.lsc_config.r_data_tbl[0][0]); + std::copy(grData_.begin(), grData_.end(), + ¶ms->others.lsc_config.gr_data_tbl[0][0]); + std::copy(gbData_.begin(), gbData_.end(), + ¶ms->others.lsc_config.gb_data_tbl[0][0]); + std::copy(bData_.begin(), bData_.end(), + ¶ms->others.lsc_config.b_data_tbl[0][0]); + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_LSC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_LSC; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_LSC; +} + +REGISTER_IPA_ALGORITHM(LensShadingCorrection, "LensShadingCorrection") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h new file mode 100644 index 00000000..fdb2ec1d --- /dev/null +++ b/src/ipa/rkisp1/algorithms/lsc.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * lsc.h - RkISP1 Lens Shading Correction control + */ + +#pragma once + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class LensShadingCorrection : public Algorithm +{ +public: + LensShadingCorrection(); + ~LensShadingCorrection() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + +private: + bool initialized_; + + std::vector rData_; + std::vector grData_; + std::vector gbData_; + std::vector bData_; + + std::vector xSize_; + std::vector ySize_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 0597c353..64e11dce 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -5,4 +5,5 @@ rkisp1_ipa_algorithms = files([ 'awb.cpp', 'blc.cpp', 'gsl.cpp', + 'lsc.cpp', ]) diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index 13f76412..fa2ae436 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -16,4 +16,83 @@ algorithms: red: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] blue: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] + - LensShadingCorrection: + x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] + y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] + r: [ + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + ] + gr: [ + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + ] + gb: [ + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + ] + b: [ + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + ] ... diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index f387cace..3bfb262c 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -33,6 +33,7 @@ struct IPASessionConfiguration { struct { utils::Duration lineDuration; + Size size; } sensor; struct { diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 1c002939..af0f43f2 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -32,6 +32,7 @@ #include "algorithms/awb.h" #include "algorithms/blc.h" #include "algorithms/gsl.h" +#include "algorithms/lsc.h" #include "libipa/camera_sensor_helper.h" #include "ipa_context.h" @@ -212,6 +213,7 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, /* Set the hardware revision for the algorithms. */ context_.configuration.hw.revision = hwRevision_; + context_.configuration.sensor.size = info.outputSize; context_.configuration.sensor.lineDuration = info.lineLength * 1.0s / info.pixelRate; /* From patchwork Fri Jul 22 15:16:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16737 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 CA30FC3274 for ; Fri, 22 Jul 2022 15:16:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E23E63314; Fri, 22 Jul 2022 17:16:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658503010; bh=wWBuBcx/XaLrQ1+NMyjnmoz87X5iS6GJhakQMoFluaY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=o7kbBVscIdRiJAuDRdcMHPRNLBbHM0R/ULkz6P40fEiMAOzpXwVE3W9e6ln5MnibZ kcrwHWo5LDWm8PzS6Fa5Cm24TZsHw3Z7CgpFI032ViXFV1j44gvOLxDr7tLsqrEJP0 CySCwC8pNL8CsbOwXZz/LeeVO1WwBWiBLSFN7WDI/MZT/75hF9ieO+YqLLIjnWf3ji ALZ1Kp1hpOZZTFdz/wNZte6j5kFRI/deFHXCAKeTpxLMKIKe+IgRfpUo9cDkFnCGTo knskROD4JYeYdfkxWwsmpyWtm4sq639hJEvGS1t4sWmz5fW/CaVmAQhw8q7OjSiCsp xVwi48aLMnNEQ== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B4066603F5 for ; Fri, 22 Jul 2022 17:16:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="V/kO/3Cw"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id m17so6648166wrw.7 for ; Fri, 22 Jul 2022 08:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TQefclzKT5h8W1Lm30sOGdD8+kMgz34+n//X7ZBEL7c=; b=V/kO/3CwrRkpzIbuK/3mAmOC8lR5wJFqWkIhESmOOYg0U2BPUbRm+zxYZ/M9pXbS9F CX30aUBlOpLu1ORU6kiWGot5wqOeI6MeGTorNPVYuHadGgLDiNVRwUypX7VBOn5XHnbu QuGE9z0YJGKUHIU6V4VGrI4cUZdebuaRwuIzHgFVnb0XneG0+nCo0jD6Gjl5eKCIzBGZ 1Oizf1y072esOQ0cy7MqtCBiWgT+rXxDEAWjABw8c0sKMcymGHkt2jJ0lywISA6ilyAL HHYdp5PDLr92S6f9ubCVsEs37bfZq5GY22sZXWcgjtrMgqcHPynBingFlglt6/lLXF6x BzMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TQefclzKT5h8W1Lm30sOGdD8+kMgz34+n//X7ZBEL7c=; b=zlfSOTLwGY3t96E8+zrITpJA/tO9ZoNM6gBynMvMQhlSsQcf2LB+MW0vBAJnusPtWd RxpoXYPnoBBhl698BtBf27GdD/EbA1Ui7kFDLWApcu8XPBrUXb5iRgK6Pvk/hY/eiNwC FjzdNLI0+8dwLc7q/98oPovXJ9OUilt4CUtI/hiPnBO64ZduoWH71shriPPdSAxwf57t dRfjIW9MCe+lidBi9wuOuIBP/Fh7xiqhuu9w34pZZDO+LjokAG6TsX7LGgjnsF6qVvCP OuekVQFpjiK6BoP9386rsYtIcndoTTAzmcnm9tWLh+XWyoUQfn18BfyuqeTu5v/UCwlK Afyg== X-Gm-Message-State: AJIora90/rHBtdl31sRakREserhvubSgRoDwsAGfpp77GbqLsQxwNdIt 4+/BFs54/VCErVZvJsbtblX8mwUXMp7u7QMG X-Google-Smtp-Source: AGRyM1skafGEbwufB6V6VB1jYO1C5Vv4EVlj3BsNjFJCeynkuwk3QXQlHFHz7xttFD0vDjyfzlhw7w== X-Received: by 2002:a5d:6c62:0:b0:21d:c697:87f2 with SMTP id r2-20020a5d6c62000000b0021dc69787f2mr265880wrz.283.1658503006913; Fri, 22 Jul 2022 08:16:46 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:e9da:4076:6aa:6cd2]) by smtp.gmail.com with ESMTPSA id b1-20020a5d4d81000000b0021e4fd8e10bsm4871557wru.11.2022.07.22.08.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 08:16:46 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jul 2022 17:16:34 +0200 Message-Id: <20220722151635.239221-5-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722151635.239221-1-fsylvestre@baylibre.com> References: <20220722151635.239221-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/5] include: linux: Update rkisp1 kernel header for DPCC configuration 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: , X-Patchwork-Original-From: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To improve the kernel interface, a proposal has been made to the linux-kernel [1] to improve the configuration of the Defective Pixel Cluster Correction (DPCC). [1] https://lore.kernel.org/linux-media/20220616160456.21549-1-laurent.pinchart@ideasonboard.com/ Update the local copy of the rkisp1-config.h to match the proposal. Signed-off-by: Florian Sylvestre Acked-by: Paul Elder Reviewed-by: Laurent Pinchart --- include/linux/rkisp1-config.h | 77 +++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/include/linux/rkisp1-config.h b/include/linux/rkisp1-config.h index 9be67d63..0ed3dca8 100644 --- a/include/linux/rkisp1-config.h +++ b/include/linux/rkisp1-config.h @@ -117,7 +117,46 @@ /* * Defect Pixel Cluster Correction */ -#define RKISP1_CIF_ISP_DPCC_METHODS_MAX 3 +#define RKISP1_CIF_ISP_DPCC_METHODS_MAX 3 + +#define RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE (1U << 2) + +#define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER (1U << 0) +#define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_RB_CENTER (1U << 1) +#define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_G_3X3 (1U << 2) +#define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_RB_3X3 (1U << 3) + +/* 0-2 for sets 1-3 */ +#define RKISP1_CIF_ISP_DPCC_SET_USE_STAGE1_USE_SET(n) ((n) << 0) +#define RKISP1_CIF_ISP_DPCC_SET_USE_STAGE1_USE_FIX_SET (1U << 3) + +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_GREEN_ENABLE (1U << 0) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE (1U << 1) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_GREEN_ENABLE (1U << 2) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE (1U << 3) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_GREEN_ENABLE (1U << 4) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_RED_BLUE_ENABLE (1U << 8) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE (1U << 9) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_RED_BLUE_ENABLE (1U << 10) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE (1U << 11) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_RED_BLUE_ENABLE (1U << 12) + +#define RKISP1_CIF_ISP_DPCC_LINE_THRESH_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_LINE_THRESH_RB(v) ((v) << 8) +#define RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_RB(v) ((v) << 8) +#define RKISP1_CIF_ISP_DPCC_PG_FAC_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_PG_FAC_RB(v) ((v) << 8) +#define RKISP1_CIF_ISP_DPCC_RND_THRESH_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_RND_THRESH_RB(v) ((v) << 8) +#define RKISP1_CIF_ISP_DPCC_RG_FAC_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_RG_FAC_RB(v) ((v) << 8) + +#define RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_G(n, v) ((v) << ((n) * 4)) +#define RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_RB(n, v) ((v) << ((n) * 4 + 2)) + +#define RKISP1_CIF_ISP_DPCC_RND_OFFS_n_G(n, v) ((v) << ((n) * 4)) +#define RKISP1_CIF_ISP_DPCC_RND_OFFS_n_RB(n, v) ((v) << ((n) * 4 + 2)) /* * Denoising pre filter @@ -250,16 +289,20 @@ struct rkisp1_cif_isp_bls_config { }; /** - * struct rkisp1_cif_isp_dpcc_methods_config - Methods Configuration used by DPCC + * struct rkisp1_cif_isp_dpcc_methods_config - DPCC methods set configuration * - * Methods Configuration used by Defect Pixel Cluster Correction + * This structure stores the configuration of one set of methods for the DPCC + * algorithm. Multiple methods can be selected in each set (independently for + * the Green and Red/Blue components) through the @method field, the result is + * the logical AND of all enabled methods. The remaining fields set thresholds + * and factors for each method. * - * @method: Method enable bits - * @line_thresh: Line threshold - * @line_mad_fac: Line MAD factor - * @pg_fac: Peak gradient factor - * @rnd_thresh: Rank Neighbor Difference threshold - * @rg_fac: Rank gradient factor + * @method: Method enable bits (RKISP1_CIF_ISP_DPCC_METHODS_SET_*) + * @line_thresh: Line threshold (RKISP1_CIF_ISP_DPCC_LINE_THRESH_*) + * @line_mad_fac: Line Mean Absolute Difference factor (RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_*) + * @pg_fac: Peak gradient factor (RKISP1_CIF_ISP_DPCC_PG_FAC_*) + * @rnd_thresh: Rank Neighbor Difference threshold (RKISP1_CIF_ISP_DPCC_RND_THRESH_*) + * @rg_fac: Rank gradient factor (RKISP1_CIF_ISP_DPCC_RG_FAC_*) */ struct rkisp1_cif_isp_dpcc_methods_config { __u32 method; @@ -273,14 +316,16 @@ struct rkisp1_cif_isp_dpcc_methods_config { /** * struct rkisp1_cif_isp_dpcc_config - Configuration used by DPCC * - * Configuration used by Defect Pixel Cluster Correction + * Configuration used by Defect Pixel Cluster Correction. Three sets of methods + * can be configured and selected through the @set_use field. The result is the + * logical OR of all enabled sets. * - * @mode: dpcc output mode - * @output_mode: whether use hard coded methods - * @set_use: stage1 methods set - * @methods: methods config - * @ro_limits: rank order limits - * @rnd_offs: differential rank offsets for rank neighbor difference + * @mode: DPCC mode (RKISP1_CIF_ISP_DPCC_MODE_*) + * @output_mode: Interpolation output mode (RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_*) + * @set_use: Methods sets selection (RKISP1_CIF_ISP_DPCC_SET_USE_*) + * @methods: Methods sets configuration + * @ro_limits: Rank order limits (RKISP1_CIF_ISP_DPCC_RO_LIMITS_*) + * @rnd_offs: Differential rank offsets for rank neighbor difference (RKISP1_CIF_ISP_DPCC_RND_OFFS_*) */ struct rkisp1_cif_isp_dpcc_config { __u32 mode; From patchwork Fri Jul 22 15:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16738 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 4EB70BD1F1 for ; Fri, 22 Jul 2022 15:16:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1014563321; Fri, 22 Jul 2022 17:16:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658503013; bh=bFyW4JUEnCaSackTx56yzW4CEXURmCpaUklJwVdeSnM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=gqQ5jRRm5UAEznLqO+EU3VtrlMHFOBo0zJFOmuOTs2WLJq52rQB+GbjvhnoWI3H4S yv9yJ66G095CSrBENh+5NPs8OM+sQR/A0FmE8JVhJBJsTIw7rG6czyrZldD904ctjm kk/AoUe1k8Q1K4q9FXhQ77iO/nz+KiNpx/pHgpJF4uOEoocc2RB3EEU5hnogzuh+7/ 5rGbILrMwRYWVR5OdwuPT08vBmoy7MoFG8pOM35Sg+wvaeHHkErZjsnKASGPI1x36k 1x2i9QOtvXlK8f+3XJ8+DTK+TW3NzR07933EACElaujDFxuPAKJU68IpGOOA0FCJz/ nQ/W8flbhwk9g== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C4AF563315 for ; Fri, 22 Jul 2022 17:16:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="CZRAqHMb"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id d8so6912978wrp.6 for ; Fri, 22 Jul 2022 08:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wi42NH23iXD/ebJYrLMxC/2ih+jeQJgZqeQSk6mmsDY=; b=CZRAqHMbsJVdb56efB2omDhHRiMhO//7u8r6svXTOnHme88KA2N4rucrbrM5z57Nym 15P+dgt4+zuJHv/7YsM6mesBYsMXoCQl8AHLpdnlZdnPnokI37GoTGJs4ucGpy2sk0ed 2xI8YiWdvLo9QRckw9IyY4tY+Go7uHTBa07OnTcuE0gvQzO/JfYcnE8iDgwsFvucEv0V vx/BFLIhcN+eGgnAqHx2qJ9i8RZg1FGSh2FeskJQ+S1fkWxYPymaRgCbPP2diqxX2yYi FPzUdSvjQsEPg7UviTcDyaN7n72xeZHDa1bu8yzw7JVx3MvmsCQLdEzhJqO1a9FmNX/Y 9yFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wi42NH23iXD/ebJYrLMxC/2ih+jeQJgZqeQSk6mmsDY=; b=lVD+dqvWjazpo9RjHSLtWtxASQ1xbH3mCQQfKXAb96K0OPbjN3siXiBnvegDKGXL4H Ujlz4PwJadJ/wPSB2Bj3fMAjwYekiekdhx1LLqh3hqXbjk43/YUJulkDTyOMu5G6bdav 18qQ2xSgd9kv0vz2xSCJZ/ys/+auIPLi1LgXbUkLHxFyPyVnmsHV8wsNAZtKzHEyWO99 FsLE3fX2586PpAhEEJmPL2JHi4TfYddOzftIygmvydXDkZa2/ARaBUiq9mjfP3yDR0dx nj+1J5I5Ek+2VUEvr6qbKjoHH2LntDx1AhQRQOlANa9z4Dpa8GBagGSsWHzOjbBPtJsV BIwA== X-Gm-Message-State: AJIora9daoA9SjKUllrreqKloOSnVZFSeUoTrZiAbEg1k4NqbG0iH0zN Ywe42bMcjr/KpCP/TFfAyLxtezr/WnmjyJ5B X-Google-Smtp-Source: AGRyM1uujGO4AiGIXrBaf7wCoCdnhZQBlcLAulcB3+htaekdY8C+Z/iumQFcdiU0qA3Foiuy3/ZzKQ== X-Received: by 2002:adf:e54a:0:b0:21e:61f3:de49 with SMTP id z10-20020adfe54a000000b0021e61f3de49mr290413wrm.25.1658503008092; Fri, 22 Jul 2022 08:16:48 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:e9da:4076:6aa:6cd2]) by smtp.gmail.com with ESMTPSA id b1-20020a5d4d81000000b0021e4fd8e10bsm4871557wru.11.2022.07.22.08.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 08:16:47 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jul 2022 17:16:35 +0200 Message-Id: <20220722151635.239221-6-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722151635.239221-1-fsylvestre@baylibre.com> References: <20220722151635.239221-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/5] ipa: rkisp1: Add support of Defect Pixel Cluster Correction control 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: , X-Patchwork-Original-From: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Defect Pixel Cluster Correction algorithm is responsible to minimize the impact of defective pixels. The on-the-fly method is actually used, based on coefficient provided by the tuning file. Signed-off-by: Florian Sylvestre --- src/ipa/rkisp1/algorithms/dpcc.cpp | 262 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/dpcc.h | 31 +++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 60 ++++++ src/ipa/rkisp1/rkisp1.cpp | 1 + 5 files changed, 355 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/dpcc.cpp create mode 100644 src/ipa/rkisp1/algorithms/dpcc.h diff --git a/src/ipa/rkisp1/algorithms/dpcc.cpp b/src/ipa/rkisp1/algorithms/dpcc.cpp new file mode 100644 index 00000000..c1598b6c --- /dev/null +++ b/src/ipa/rkisp1/algorithms/dpcc.cpp @@ -0,0 +1,262 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * dpcc.cpp - RkISP1 Defect Pixel Cluster Correction control + */ + +#include "dpcc.h" + +#include + +#include "libcamera/internal/yaml_parser.h" + +#include "linux/rkisp1-config.h" + +/** + * \file dpcc.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class DefectPixelClusterCorrection + * \brief RkISP1 Defect Pixel Cluster Correction control + * + * Depending of the sensor quality, some pixels can be defective and then + * appear significantly brighter or darker than the other pixels. + * + * The Defect Pixel Cluster Correction algorithms is responsible to minimize + * the impact of the pixels. + * This can be done with algorithms applied at run time (on-the-fly method) or + * with a table of defective pixels. Only first method is supported for the + * moment. + */ + +LOG_DEFINE_CATEGORY(RkISP1Dpcc) + +DefectPixelClusterCorrection::DefectPixelClusterCorrection() + : initialized_(false), config_({}) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int DefectPixelClusterCorrection::init([[maybe_unused]] IPAContext &context, + const YamlObject &tuningData) +{ + config_.mode = + RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE; + config_.output_mode = + RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER | + RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_RB_CENTER; + + config_.set_use = tuningData["fixed-set"].get(false) + ? RKISP1_CIF_ISP_DPCC_SET_USE_STAGE1_USE_FIX_SET + : 0; + + /* Get all defined sets to apply (up to 3). */ + const YamlObject &setsObject = tuningData["sets"]; + if (!setsObject.isList()) { + LOG(RkISP1Dpcc, Error) + << "'sets' parameter not found in tuning file"; + return -EINVAL; + } + + if (setsObject.size() > RKISP1_CIF_ISP_DPCC_METHODS_MAX) { + LOG(RkISP1Dpcc, Error) + << "'sets' size in tuning file (" << setsObject.size() + << ") exceeds the maximum hardware capacity (3)"; + return -EINVAL; + } + + for (std::size_t i = 0; i < setsObject.size(); ++i) { + struct rkisp1_cif_isp_dpcc_methods_config &method = config_.methods[i]; + const YamlObject &set = setsObject[i]; + uint16_t value; + + /* Enable set if described in Yaml tuning file. */ + config_.set_use |= 1 << i; + + /* PG Method */ + const YamlObject &pgObject = set["pg-factor"]; + + if (pgObject.contains("green")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_GREEN_ENABLE; + + value = pgObject["green"].get(0); + method.pg_fac |= + RKISP1_CIF_ISP_DPCC_PG_FAC_G(value); + } + + if (pgObject.contains("red-blue")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_RED_BLUE_ENABLE; + + value = pgObject["red-blue"].get(0); + method.pg_fac |= + RKISP1_CIF_ISP_DPCC_PG_FAC_RB(value); + } + + /* RO Method */ + const YamlObject &roObject = set["ro-limits"]; + + if (roObject.contains("green")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_GREEN_ENABLE; + + value = roObject["green"].get(0); + config_.ro_limits |= + RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_G(i, value); + } + + if (roObject.contains("red-blue")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_RED_BLUE_ENABLE; + + value = roObject["red-blue"].get(0); + config_.ro_limits |= + RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_RB(i, value); + } + + /* RG Method */ + const YamlObject &rgObject = set["rg-factor"]; + method.rg_fac = 0; + + if (rgObject.contains("green")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_GREEN_ENABLE; + + value = rgObject["green"].get(0); + method.rg_fac |= + RKISP1_CIF_ISP_DPCC_RG_FAC_G(value); + } + + if (rgObject.contains("red-blue")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_RED_BLUE_ENABLE; + + value = rgObject["red-blue"].get(0); + method.rg_fac |= + RKISP1_CIF_ISP_DPCC_RG_FAC_RB(value); + } + + /* RND Method */ + const YamlObject &rndOffsetsObject = set["rnd-offsets"]; + + if (rndOffsetsObject.contains("green")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE; + + value = rndOffsetsObject["green"].get(0); + config_.rnd_offs |= + RKISP1_CIF_ISP_DPCC_RND_OFFS_n_G(i, value); + } + + if (rndOffsetsObject.contains("red-blue")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE; + + value = rndOffsetsObject["red-blue"].get(0); + config_.rnd_offs |= + RKISP1_CIF_ISP_DPCC_RND_OFFS_n_RB(i, value); + } + + const YamlObject &rndThresholdObject = set["rnd-threshold"]; + method.rnd_thresh = 0; + + if (rndThresholdObject.contains("green")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE; + + value = rndThresholdObject["green"].get(0); + method.rnd_thresh |= + RKISP1_CIF_ISP_DPCC_RND_THRESH_G(value); + } + + if (rndThresholdObject.contains("red-blue")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE; + + value = rndThresholdObject["red-blue"].get(0); + method.rnd_thresh |= + RKISP1_CIF_ISP_DPCC_RND_THRESH_RB(value); + } + + /* LC Method */ + const YamlObject &lcThresholdObject = set["line-threshold"]; + method.line_thresh = 0; + + if (lcThresholdObject.contains("green")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE; + + value = lcThresholdObject["green"].get(0); + method.line_thresh |= + RKISP1_CIF_ISP_DPCC_LINE_THRESH_G(value); + } + + if (lcThresholdObject.contains("red-blue")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE; + + value = lcThresholdObject["red-blue"].get(0); + method.line_thresh |= + RKISP1_CIF_ISP_DPCC_LINE_THRESH_RB(value); + } + + const YamlObject &lcTMadFactorObject = set["line-mad-factor"]; + method.line_mad_fac = 0; + + if (lcTMadFactorObject.contains("green")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE; + + value = lcTMadFactorObject["green"].get(0); + method.line_mad_fac |= + RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_G(value); + } + + if (lcTMadFactorObject.contains("red-blue")) { + method.method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE; + + value = lcTMadFactorObject["red-blue"].get(0); + method.line_mad_fac |= + RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_RB(value); + } + } + + initialized_ = true; + + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void DefectPixelClusterCorrection::prepare(IPAContext &context, + rkisp1_params_cfg *params) +{ + if (context.frameContext.frameCount > 0) + return; + + if (!initialized_) + return; + + params->others.dpcc_config = config_; + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_DPCC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_DPCC; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_DPCC; +} + +REGISTER_IPA_ALGORITHM(DefectPixelClusterCorrection, "DefectPixelClusterCorrection") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/dpcc.h b/src/ipa/rkisp1/algorithms/dpcc.h new file mode 100644 index 00000000..ce332c3a --- /dev/null +++ b/src/ipa/rkisp1/algorithms/dpcc.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * dpcc.h - RkISP1 Defect Pixel Cluster Correction control + */ + +#pragma once + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class DefectPixelClusterCorrection : public Algorithm +{ +public: + DefectPixelClusterCorrection(); + ~DefectPixelClusterCorrection() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + +private: + bool initialized_; + rkisp1_cif_isp_dpcc_config config_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 64e11dce..87007493 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -4,6 +4,7 @@ rkisp1_ipa_algorithms = files([ 'agc.cpp', 'awb.cpp', 'blc.cpp', + 'dpcc.cpp', 'gsl.cpp', 'lsc.cpp', ]) diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index fa2ae436..2315ec43 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -95,4 +95,64 @@ algorithms: 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, ] + - DefectPixelClusterCorrection: + fixed-set: false + sets: + # PG, LC, RO, RND, RG + - line-threshold: + green: 8 + red-blue: 8 + line-mad-factor: + green: 4 + red-blue: 4 + pg-factor: + green: 8 + red-blue: 8 + rnd-threshold: + green: 10 + red-blue: 10 + rg-factor: + green: 32 + red-blue: 32 + ro-limits: + green: 1 + red-blue: 1 + rnd-offsets: + green: 2 + red-blue: 2 + # PG, LC, RO + - line-threshold: + green: 24 + red-blue: 32 + line-mad-factor: + green: 16 + red-blue: 24 + pg-factor: + green: 6 + red-blue: 8 + ro-limits: + green: 2 + red-blue: 2 + # PG, LC, RO, RND, RG + - line-threshold: + green: 32 + red-blue: 32 + line-mad-factor: + green: 4 + red-blue: 4 + pg-factor: + green: 10 + red-blue: 10 + rnd-threshold: + green: 6 + red-blue: 8 + rg-factor: + green: 4 + red-blue: 4 + ro-limits: + green: 1 + red-blue: 2 + rnd-offsets: + green: 2 + red-blue: 2 ... diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index af0f43f2..caa67cf0 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -31,6 +31,7 @@ #include "algorithms/algorithm.h" #include "algorithms/awb.h" #include "algorithms/blc.h" +#include "algorithms/dpcc.h" #include "algorithms/gsl.h" #include "algorithms/lsc.h" #include "libipa/camera_sensor_helper.h"