Message ID | 20240419071819.1325791-4-paul.elder@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
I forgot to mention that this patch depends on "[PATCH] libcamera: utils: Add a helper to convert floating-point to fixed-point" Paul On Fri, Apr 19, 2024 at 04:18:19PM +0900, Paul Elder wrote: > Add an algorithm module to the rkisp1 IPA for crosstalk correction. > > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> > > --- > Changes in v2: > - rename ctk to ccm > - reset the matrix interpolator to identity matrix if failed to read > from tuning file > --- > src/ipa/rkisp1/algorithms/ccm.cpp | 101 ++++++++++++++++++++++++++ > src/ipa/rkisp1/algorithms/ccm.h | 41 +++++++++++ > src/ipa/rkisp1/algorithms/meson.build | 1 + > 3 files changed, 143 insertions(+) > create mode 100644 src/ipa/rkisp1/algorithms/ccm.cpp > create mode 100644 src/ipa/rkisp1/algorithms/ccm.h > > diff --git a/src/ipa/rkisp1/algorithms/ccm.cpp b/src/ipa/rkisp1/algorithms/ccm.cpp > new file mode 100644 > index 00000000..1ae6ea85 > --- /dev/null > +++ b/src/ipa/rkisp1/algorithms/ccm.cpp > @@ -0,0 +1,101 @@ > +/* SPDX-License-Identifier: LGPL-2.1-or-later */ > +/* > + * Copyright (C) 2024, Ideas On Board > + * > + * ccm.cpp - RkISP1 Cross Talk Correction control algorithm > + */ > + > +#include "ccm.h" > + > +#include <algorithm> > +#include <chrono> > +#include <cmath> > +#include <tuple> > +#include <vector> > + > +#include <libcamera/base/log.h> > +#include <libcamera/base/utils.h> > + > +#include <libcamera/ipa/core_ipa_interface.h> > + > +#include "libcamera/internal/yaml_parser.h" > + > +#include "libipa/matrix_interpolator.h" > + > +/** > + * \file ctk.h > + */ > + > +namespace libcamera { > + > +namespace ipa::rkisp1::algorithms { > + > +/** > + * \class Ccm > + * \brief A cross talk correction algorithm > + */ > + > +LOG_DEFINE_CATEGORY(RkISP1Ccm) > + > +int Ccm::parseYaml(const YamlObject &tuningData, const char *prop) > +{ > + int ret = 0; > + > + const YamlObject &yaml = tuningData[prop]; > + ret = ccm_.readYaml(yaml); > + if (ret < 0) { > + LOG(RkISP1Ccm, Error) > + << "Failed to parse '" << prop > + << "' parameter from tuning file; falling back to unit matrix"; > + ccm_.reset(); > + } > + > + return ret; > +} > + > +/** > + * \copydoc libcamera::ipa::Algorithm::init > + */ > +int Ccm::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) > +{ > + return parseYaml(tuningData, "ccms"); > +} > + > +void Ccm::setParameters(rkisp1_params_cfg *params, const Matrix<double, 3, 3> &matrix) > +{ > + struct rkisp1_cif_isp_ctk_config &config = params->others.ctk_config; > + > + /* > + * 4 bit integer and 7 bit fractional, ranging from -8 (0x400) to > + * +7.992 (0x3FF) > + */ > + for (unsigned int i = 0; i < 3; i++) > + for (unsigned int j = 0; j < 3; j++) > + config.coeff[i][j] = > + utils::floatingToFixedPoint<4, 7, uint16_t, double>(matrix.get(i, j)); > + > + LOG(RkISP1Ccm, Debug) << "Setting matrix " << matrix.toString(); > + > + params->module_en_update |= RKISP1_CIF_ISP_MODULE_CTK; > + params->module_ens |= RKISP1_CIF_ISP_MODULE_CTK; > + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CTK; > +} > + > +/** > + * \copydoc libcamera::ipa::Algorithm::prepare > + */ > +void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, > + [[maybe_unused]] IPAFrameContext &frameContext, > + rkisp1_params_cfg *params) > +{ > + uint32_t ct = context.activeState.awb.temperatureK; > + Matrix<double, 3, 3> ccm = ccm_.get(ct); > + > + setParameters(params, ccm); > +} > + > +REGISTER_IPA_ALGORITHM(Ccm, "Ccm") > + > +} /* namespace ipa::rkisp1::algorithms */ > + > +} /* namespace libcamera */ > diff --git a/src/ipa/rkisp1/algorithms/ccm.h b/src/ipa/rkisp1/algorithms/ccm.h > new file mode 100644 > index 00000000..fc88e338 > --- /dev/null > +++ b/src/ipa/rkisp1/algorithms/ccm.h > @@ -0,0 +1,41 @@ > +/* SPDX-License-Identifier: LGPL-2.1-or-later */ > +/* > + * Copyright (C) 2024, Ideas On Board > + * > + * ccm.h - RkISP1 Cross Talk Correction control algorithm > + */ > + > +#pragma once > + > +#include <linux/rkisp1-config.h> > + > +#include "libipa/matrix.h" > +#include "libipa/matrix_interpolator.h" > + > +#include "algorithm.h" > + > +namespace libcamera { > + > +namespace ipa::rkisp1::algorithms { > + > +class Ccm : public Algorithm > +{ > +public: > + Ccm(){}; > + ~Ccm() = 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: > + int parseYaml(const YamlObject &tuningData, const char *prop); > + void setParameters(rkisp1_params_cfg *params, const Matrix<double, 3, 3> &matrix); > + > + MatrixInterpolator<double, 3, 3> ccm_; > +}; > + > +} /* namespace ipa::rkisp1::algorithms */ > + > +} /* namespace libcamera */ > diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build > index 93a48329..c9891e87 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', > + 'ctk.cpp', > 'cproc.cpp', > 'dpcc.cpp', > 'dpf.cpp', > -- > 2.39.2 >
diff --git a/src/ipa/rkisp1/algorithms/ccm.cpp b/src/ipa/rkisp1/algorithms/ccm.cpp new file mode 100644 index 00000000..1ae6ea85 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/ccm.cpp @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Ideas On Board + * + * ccm.cpp - RkISP1 Cross Talk Correction control algorithm + */ + +#include "ccm.h" + +#include <algorithm> +#include <chrono> +#include <cmath> +#include <tuple> +#include <vector> + +#include <libcamera/base/log.h> +#include <libcamera/base/utils.h> + +#include <libcamera/ipa/core_ipa_interface.h> + +#include "libcamera/internal/yaml_parser.h" + +#include "libipa/matrix_interpolator.h" + +/** + * \file ctk.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class Ccm + * \brief A cross talk correction algorithm + */ + +LOG_DEFINE_CATEGORY(RkISP1Ccm) + +int Ccm::parseYaml(const YamlObject &tuningData, const char *prop) +{ + int ret = 0; + + const YamlObject &yaml = tuningData[prop]; + ret = ccm_.readYaml(yaml); + if (ret < 0) { + LOG(RkISP1Ccm, Error) + << "Failed to parse '" << prop + << "' parameter from tuning file; falling back to unit matrix"; + ccm_.reset(); + } + + return ret; +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int Ccm::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) +{ + return parseYaml(tuningData, "ccms"); +} + +void Ccm::setParameters(rkisp1_params_cfg *params, const Matrix<double, 3, 3> &matrix) +{ + struct rkisp1_cif_isp_ctk_config &config = params->others.ctk_config; + + /* + * 4 bit integer and 7 bit fractional, ranging from -8 (0x400) to + * +7.992 (0x3FF) + */ + for (unsigned int i = 0; i < 3; i++) + for (unsigned int j = 0; j < 3; j++) + config.coeff[i][j] = + utils::floatingToFixedPoint<4, 7, uint16_t, double>(matrix.get(i, j)); + + LOG(RkISP1Ccm, Debug) << "Setting matrix " << matrix.toString(); + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_CTK; + params->module_ens |= RKISP1_CIF_ISP_MODULE_CTK; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CTK; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + rkisp1_params_cfg *params) +{ + uint32_t ct = context.activeState.awb.temperatureK; + Matrix<double, 3, 3> ccm = ccm_.get(ct); + + setParameters(params, ccm); +} + +REGISTER_IPA_ALGORITHM(Ccm, "Ccm") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/ccm.h b/src/ipa/rkisp1/algorithms/ccm.h new file mode 100644 index 00000000..fc88e338 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/ccm.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Ideas On Board + * + * ccm.h - RkISP1 Cross Talk Correction control algorithm + */ + +#pragma once + +#include <linux/rkisp1-config.h> + +#include "libipa/matrix.h" +#include "libipa/matrix_interpolator.h" + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class Ccm : public Algorithm +{ +public: + Ccm(){}; + ~Ccm() = 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: + int parseYaml(const YamlObject &tuningData, const char *prop); + void setParameters(rkisp1_params_cfg *params, const Matrix<double, 3, 3> &matrix); + + MatrixInterpolator<double, 3, 3> ccm_; +}; + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 93a48329..c9891e87 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', + 'ctk.cpp', 'cproc.cpp', 'dpcc.cpp', 'dpf.cpp',
Add an algorithm module to the rkisp1 IPA for crosstalk correction. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> --- Changes in v2: - rename ctk to ccm - reset the matrix interpolator to identity matrix if failed to read from tuning file --- src/ipa/rkisp1/algorithms/ccm.cpp | 101 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/ccm.h | 41 +++++++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + 3 files changed, 143 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/ccm.cpp create mode 100644 src/ipa/rkisp1/algorithms/ccm.h