From 5b07fa200334bd4932f7b0506cc38bd331ca84f4 Mon Sep 17 00:00:00 2001 From: Florian Sylvestre Date: Wed, 27 Jul 2022 10:38:19 +0200 Subject: ipa: rkisp1: Add support of ColorProcessing control Add ColorProcessing algorithm that is in charge to manage brightness, contrast and saturation controls. These controls are currently based on user controls. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/ipa/rkisp1/algorithms/cproc.cpp | 97 +++++++++++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/cproc.h | 30 +++++++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + 3 files changed, 128 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/cproc.cpp create mode 100644 src/ipa/rkisp1/algorithms/cproc.h (limited to 'src/ipa/rkisp1/algorithms') diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp new file mode 100644 index 00000000..bca5ab69 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/cproc.cpp @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * cproc.cpp - RkISP1 Color Processing control + */ + +#include "cproc.h" + +#include +#include + +#include + +#include + +/** + * \file cproc.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class ColorProcessing + * \brief RkISP1 Color Processing control + * + * The ColorProcessing algorithm is responsible for applying brightness, + * contrast and saturation corrections. The values are directly provided + * through requests by the corresponding controls. + */ + +LOG_DEFINE_CATEGORY(RkISP1CProc) + +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void ColorProcessing::queueRequest(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + const ControlList &controls) +{ + auto &cproc = context.frameContext.cproc; + + const auto &brightness = controls.get(controls::Brightness); + if (brightness) { + cproc.brightness = std::clamp(std::lround(*brightness * 128), -128, 127); + cproc.updateParams = true; + + LOG(RkISP1CProc, Debug) << "Set brightness to " << *brightness; + } + + const auto &contrast = controls.get(controls::Contrast); + if (contrast) { + cproc.contrast = std::clamp(std::lround(*contrast * 128), 0, 255); + cproc.updateParams = true; + + LOG(RkISP1CProc, Debug) << "Set contrast to " << *contrast; + } + + const auto saturation = controls.get(controls::Saturation); + if (saturation) { + cproc.saturation = std::clamp(std::lround(*saturation * 128), 0, 255); + cproc.updateParams = true; + + LOG(RkISP1CProc, Debug) << "Set saturation to " << *saturation; + } +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void ColorProcessing::prepare(IPAContext &context, + rkisp1_params_cfg *params) +{ + auto &cproc = context.frameContext.cproc; + + /* Check if the algorithm configuration has been updated. */ + if (!cproc.updateParams) + return; + + cproc.updateParams = false; + + params->others.cproc_config.brightness = cproc.brightness; + params->others.cproc_config.contrast = cproc.contrast; + params->others.cproc_config.sat = cproc.saturation; + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_CPROC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_CPROC; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CPROC; +} + +REGISTER_IPA_ALGORITHM(ColorProcessing, "ColorProcessing") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/cproc.h b/src/ipa/rkisp1/algorithms/cproc.h new file mode 100644 index 00000000..4b7e4064 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/cproc.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * cproc.h - RkISP1 Color Processing control + */ + +#pragma once + +#include + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class ColorProcessing : public Algorithm +{ +public: + ColorProcessing() = default; + ~ColorProcessing() = default; + + void queueRequest(IPAContext &context, const uint32_t frame, + const ControlList &controls) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index dcd24fe0..e48974b4 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', + 'cproc.cpp', 'dpcc.cpp', 'filter.cpp', 'gsl.cpp', -- cgit v1.2.1