From patchwork Wed Jul 27 08:40:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16833 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 BD256BE173 for ; Wed, 27 Jul 2022 08:41:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7B6B763312; Wed, 27 Jul 2022 10:41:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658911263; bh=L8zcJvYk5eCtVtABJBzMpd6199t9z/gw39saggoKRy8=; 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=HQTCuqcg2HGxRp9i7JvU3heIXp6cbc/SGPJNNa6PxUfVfoIJbxMuKDgXwUMEzTnWk 47zbyQ5ivTuXKjHAqwzCVTs9yGR7rulwzKM319+0GVSMqYQAJQmEhygPSkseKXnuX0 xwIPFrNTFa5JUSt4nmtqaSPWjPzn9BBGjITtgoUSfEdUfmvaHzJq/sew696eGL5xC1 fNsNcuBJHbWIzjEJ3NwH4nT6YJxpmYuarcB5XIkVqRbVIpuS3dH14/jdPxxF6yT9kk nMFn+EBKUO3EHeNK9vhr8MXLU5yM8DPrur7WVRteaLM5S9i/Z2+EOfBr+UCpEomKBB NV2rvTUjn8+dw== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D9AC63312 for ; Wed, 27 Jul 2022 10:41:00 +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="V6V1eVYy"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id h8so23179896wrw.1 for ; Wed, 27 Jul 2022 01:41:00 -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=QGUnf825e0hZiXwvZbecuTHzWDnko3nc68Y60Kvh/aw=; b=V6V1eVYy29vPoWaX4Zn0RNFvTsByxzVyBQ1cGrPWMIYuszNE9fP0dBy1rZae8+MzIz Nc3raSYzxa7nDmCXeWzT/Hml5tAtfQ97fGlNEuXtcngZEmB+u/nFH9UuZEZa9/p9Js4K tu3TfjpWmi1ACcZ+xNQPD/Iwz8PHSnyunzJ/sSYeotUETR10QT7y4S7DjQnJTg2RXJhy BcFpsYPeu8kQhYM4LDhhA8/B5AvpYVsNTaaciBRG6rOvthMc6v7Q5LB4zo1KtTPKm1B6 ULGFYXkzkiSIslGDrvObChZoiSAzmuuxzWiTAC/KS+DT3hyPTT2bBRltHKKaRF7B0/Qq 9A0Q== 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=QGUnf825e0hZiXwvZbecuTHzWDnko3nc68Y60Kvh/aw=; b=0OfKqZeV4aGQzqt6dtRxo/5Eix2SCKXtcXAqg2XTkIvTLGOK5IaA3wj4yA9nbu7zjC S8tx2d2cysZcUPC0yUGzG6dNjaGdEs6sOk7aFcFPam3bml02xOBYbnv2U2yCNONMUwcL KNgQV0vWtBXqH/POq2+xHl2cFAB9eouasn5G36GWzKm/9m88vusIu448UoUnGNknfMEn 5UjEDf2p+FY6reOHabAbv2/tdmwWjaGsbBzTKFoeFc6kUs6r2WPw5fhcP4jsQD/b67H4 hiJcD7ZFXoR+N4hl3EwK/Hh5pr8oTOTqSyKU3ldo1ek7gHyXw4diZUft80OBPz38X9EL TAwg== X-Gm-Message-State: AJIora/x9+f1c4xZK0xNqzoWW/OiIFX/WvCPg2yY9gfYN+EabNTux7oz Hi0qXgwMVlWirDaSw/wkXrksPC890xdH5QIs X-Google-Smtp-Source: AGRyM1vrvq13nbAiOcmFiWwE8LBG1YHKU5uFNtOVgWudRbyb0zXPBkdaJa0t322p2aOBZJXo6sy7HA== X-Received: by 2002:a05:6000:989:b0:21e:7178:1f99 with SMTP id by9-20020a056000098900b0021e71781f99mr11920925wrb.581.1658911259728; Wed, 27 Jul 2022 01:40:59 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:5810:316e:87c:fc17]) by smtp.gmail.com with ESMTPSA id 16-20020a05600c241000b003a2f6367049sm1464275wmp.48.2022.07.27.01.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jul 2022 01:40:59 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Jul 2022 10:40:49 +0200 Message-Id: <20220727084052.590421-3-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220727084052.590421-1-fsylvestre@baylibre.com> References: <20220727084052.590421-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 linearizes the sensor output to compensate the sensor non-linearities by applying piecewise linear functions 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 ++ 4 files changed, 188 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..09588464 --- /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 functions 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 ] ...