From patchwork Wed May 22 14:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 20083 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 EA106BD87C for ; Wed, 22 May 2024 14:55:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AC33263488; Wed, 22 May 2024 16:55:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="K4xG6vq7"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 42FEB6347E for ; Wed, 22 May 2024 16:54:58 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:9beb:c30d:4413:8c99]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 80F78ABE; Wed, 22 May 2024 16:54:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1716389685; bh=vU50ZsFgInLrlSla/2zLTIVrqgC7JylGxZgiT52A1ZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K4xG6vq7J6osOPnfK95y+bNc/05pyuNRVEogHrc27H2wZthBjv+5beKM80tFs1XN1 XNthsoHzvndCvBrhoQKR0sZ38QDBV84rc3jpdjzfHruM3+w4VenGoBnNBCQ/l15fD7 V1jN5KBldzpxTJMZz0qMj+VMMEPlqkOv3G4T/IEQ= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 1/4] ipa: rkisp1: Add gamma algorithm Date: Wed, 22 May 2024 16:54:35 +0200 Message-Id: <20240522145438.436688-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240522145438.436688-1-stefan.klug@ideasonboard.com> References: <20240522145438.436688-1-stefan.klug@ideasonboard.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" Add a gamma algorithm for the rkisp1. It defaults to a gamma of 2.2 which closely resembles sRGB. No seperate sRGB mode was implemented because the pwl that models the gamma curve is so coarse that there is basically no difference between srgb and gamma=2.2 The gamma algorithm is not enabled by default. This will be done in future tuning file updates. Signed-off-by: Stefan Klug --- Note: This patch breaks the naming conventions. It is implemented inside goc.h/cpp because the hardware block and params inside the rkisp1 are called "goc". The class itself is called Gamma, and the algorithm is registered with the name "Gamma". The idea was that similar functionalities should be named the same inside the tuning files (even among multipe isps). It still feels a bit awkward. So thoughts are welcome :-) v1 -> v2: - fixed some style issues - fail in case of a V12 isp src/ipa/rkisp1/algorithms/goc.cpp | 100 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/goc.h | 32 +++++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + 3 files changed, 133 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/goc.cpp create mode 100644 src/ipa/rkisp1/algorithms/goc.h diff --git a/src/ipa/rkisp1/algorithms/goc.cpp b/src/ipa/rkisp1/algorithms/goc.cpp new file mode 100644 index 00000000..6f313820 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/goc.cpp @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Ideas On Board + * + * RkISP1 Gamma out control + */ +#include "goc.h" + +#include + +#include +#include + +#include "libcamera/internal/yaml_parser.h" + +#include "linux/rkisp1-config.h" + +/** + * \file goc.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class Gamma + * \brief RkISP1 Gamma out control + * + * This algorithm implements the gamma out curve for the RkISP1. + * It defaults to a gamma value of 2.2 + * As gamma is internally represented as a piecewise linear function with only + * 16 knots, the difference between gamma=2.2 and sRGB gamma is minimal. + * Therefore sRGB gamma was not implemented as special case. + * + * Useful links: + * https://www.cambridgeincolour.com/tutorials/gamma-correction.htm + * https://en.wikipedia.org/wiki/SRGB + */ + +LOG_DEFINE_CATEGORY(RkISP1Gamma) + +Gamma::Gamma() +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int Gamma::init([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const YamlObject &tuningData) +{ + if (context.hw->numGammaOutSamples != + RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10) { + LOG(RkISP1Gamma, Error) + << "Gamma is not implemented for RkISP1 V12"; + return -EINVAL; + } + + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Gamma::prepare([[maybe_unused]] IPAContext &context, + const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + rkisp1_params_cfg *params) +{ + /* The logarithmic segments as specified in the reference. + * Plus an additional 0 to make the loop easier + */ + int segments[] = { 64, 64, 64, 64, 128, 128, 128, 128, 256, 256, 256, + 512, 512, 512, 512, 512, 0 }; + auto gamma_y = params->others.goc_config.gamma_y; + + ASSERT(context.hw->numGammaOutSamples == + RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10); + + if (frame > 0) + return; + + int x = 0; + for (unsigned i = 0; i < context.hw->numGammaOutSamples; i++) { + gamma_y[i] = std::pow(x / 4096.0, 1.0 / gamma_) * 1023.0; + x += segments[i]; + } + + params->others.goc_config.mode = RKISP1_CIF_ISP_GOC_MODE_LOGARITHMIC; + params->module_en_update |= RKISP1_CIF_ISP_MODULE_GOC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_GOC; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_GOC; +} + +REGISTER_IPA_ALGORITHM(Gamma, "Gamma") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/goc.h b/src/ipa/rkisp1/algorithms/goc.h new file mode 100644 index 00000000..fe7caba3 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/goc.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Ideas On Board + * + * RkISP1 Gamma out control + */ + +#pragma once + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class Gamma : public Algorithm +{ +public: + Gamma(); + ~Gamma() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void prepare(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + rkisp1_params_cfg *params) override; + +private: + float gamma_ = 2.2; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 93a48329..6ee71a9b 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -8,6 +8,7 @@ rkisp1_ipa_algorithms = files([ 'dpcc.cpp', 'dpf.cpp', 'filter.cpp', + 'goc.cpp', 'gsl.cpp', 'lsc.cpp', ])