@@ -9,7 +9,7 @@
#include <cmath>
#include <libcamera/base/log.h>
-#include <libcamera/base/utils.h>
+#include <libcamera/base/span.h>
#include <libcamera/control_ids.h>
@@ -44,6 +44,7 @@ namespace ipa::rkisp1::algorithms {
LOG_DEFINE_CATEGORY(RkISP1Gamma)
const float kDefaultGamma = 2.2f;
+static constexpr unsigned int kNumLutSegments = RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10 - 1;
/**
* \copydoc libcamera::ipa::Algorithm::init
@@ -57,10 +58,12 @@ int GammaOutCorrection::init(IPAContext &context, const ValueNode &tuningData)
return -EINVAL;
}
- defaultGamma_ = tuningData["gamma"].get<double>(kDefaultGamma);
- context.ctrlMap[&controls::Gamma] = ControlInfo(0.1f, 10.0f, defaultGamma_);
+ std::array<unsigned int, kNumLutSegments> segments = {
+ 64, 64, 64, 64, 128, 128, 128, 128,
+ 256, 256, 256, 512, 512, 512, 512, 512
+ };
- return 0;
+ return gammaAlgo_.init(context.ctrlMap, tuningData, segments);
}
/**
@@ -69,7 +72,7 @@ int GammaOutCorrection::init(IPAContext &context, const ValueNode &tuningData)
int GammaOutCorrection::configure(IPAContext &context,
[[maybe_unused]] const IPACameraSensorInfo &configInfo)
{
- context.activeState.goc.gamma = defaultGamma_;
+ gammaAlgo_.configure(context.activeState.gamma);
return 0;
}
@@ -80,17 +83,8 @@ void GammaOutCorrection::queueRequest(IPAContext &context, const uint32_t frame,
IPAFrameContext &frameContext,
const ControlList &controls)
{
- if (frame == 0)
- frameContext.goc.update = true;
-
- const auto &gamma = controls.get(controls::Gamma);
- if (gamma) {
- context.activeState.goc.gamma = *gamma;
- frameContext.goc.update = true;
- LOG(RkISP1Gamma, Debug) << "Set gamma to " << *gamma;
- }
-
- frameContext.goc.gamma = context.activeState.goc.gamma;
+ gammaAlgo_.queueRequest(context.activeState.gamma, frame,
+ frameContext.gamma, controls);
}
/**
@@ -104,29 +98,14 @@ void GammaOutCorrection::prepare(IPAContext &context,
ASSERT(context.hw.numGammaOutSamples ==
RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10);
- if (!frameContext.goc.update)
+ if (!frameContext.gamma.update)
return;
- /*
- * The logarithmic segments as specified in the reference.
- * Plus an additional 0 to make the loop easier
- */
- static constexpr std::array<unsigned int, RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10> segments = {
- 64, 64, 64, 64, 128, 128, 128, 128, 256,
- 256, 256, 512, 512, 512, 512, 512, 0
- };
-
auto config = params->block<BlockType::Goc>();
config.setEnabled(true);
- __u16 *gamma_y = config->gamma_y;
-
- unsigned x = 0;
- for (const auto [i, size] : utils::enumerate(segments)) {
- gamma_y[i] = std::pow(x / 4096.0, 1.0 / frameContext.goc.gamma) * 1023.0;
- x += size;
- }
-
+ Span<uint16_t> lut{ config->gamma_y };
+ gammaAlgo_.prepare(frameContext.gamma, lut);
config->mode = RKISP1_CIF_ISP_GOC_MODE_LOGARITHMIC;
}
@@ -139,7 +118,7 @@ void GammaOutCorrection::process([[maybe_unused]] IPAContext &context,
[[maybe_unused]] const rkisp1_stat_buffer *stats,
ControlList &metadata)
{
- metadata.set(controls::Gamma, frameContext.goc.gamma);
+ gammaAlgo_.process(frameContext.gamma, metadata);
}
REGISTER_IPA_ALGORITHM(GammaOutCorrection, "GammaOutCorrection")
@@ -9,6 +9,9 @@
#include "algorithm.h"
+#include <libipa/fixedpoint.h>
+#include <libipa/gamma.h>
+
namespace libcamera {
namespace ipa::rkisp1::algorithms {
@@ -35,7 +38,7 @@ public:
ControlList &metadata) override;
private:
- float defaultGamma_;
+ GammaAlgorithm<RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10, UQ<0, 10>> gammaAlgo_;
};
} /* namespace ipa::rkisp1::algorithms */
@@ -30,6 +30,7 @@
#include "libipa/ccm.h"
#include "libipa/fc_queue.h"
#include "libipa/fixedpoint.h"
+#include "libipa/gamma.h"
#include "libipa/lsc.h"
namespace libcamera {
@@ -124,9 +125,7 @@ struct IPAActiveState {
uint8_t sharpness;
} filter;
- struct {
- double gamma;
- } goc;
+ ipa::gamma::ActiveState gamma;
struct {
double lux;
@@ -190,10 +189,7 @@ struct IPAFrameContext : public FrameContext {
bool update;
} filter;
- struct {
- double gamma;
- bool update;
- } goc;
+ ipa::gamma::FrameContext gamma;
struct {
uint32_t exposure;
Re-work the RkISP1 Gamma Out Correction algorithm to use the new GammaAlgorithm class from libipa, which allows us to share an implementation with the other IPAs. Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> --- src/ipa/rkisp1/algorithms/goc.cpp | 49 +++++++++++---------------------------- src/ipa/rkisp1/algorithms/goc.h | 5 +++- src/ipa/rkisp1/ipa_context.h | 10 +++----- 3 files changed, 21 insertions(+), 43 deletions(-)