Skip to content

Commit

Permalink
ipa: rkisp1: Rename frameContext to activeState
Browse files Browse the repository at this point in the history
The RkISP1 IPA module creates a single instance of its IPAFrameContext
structure, effectively using it more as an active state than a per-frame
context. To prepare for the introduction of a real per-frame context,
move all the members of the IPAFrameContext structure to a new
IPAActiveState structure. The IPAFrameContext becomes effectively
unused at runtime, and will be populated back with per-frame data after
converting the RkISP1 IPA module to using a frame context queue.

The IPAActiveState structure will slowly morph into a different entity
as individual algorithm get later ported to the frame context API.

While at it, fix a typo in the documentation of the
Agc::computeExposure() function that incorrectly refers to the frame
context instead of the global context.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
  • Loading branch information
kbingham authored and pinchartl committed Sep 28, 2022
1 parent 80d6657 commit 9063733
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 93 deletions.
23 changes: 13 additions & 10 deletions src/ipa/rkisp1/algorithms/agc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ Agc::Agc()
int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)
{
/* Configure the default exposure and gain. */
context.frameContext.agc.gain = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);
context.frameContext.agc.exposure = 10ms / context.configuration.sensor.lineDuration;
context.activeState.agc.gain = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);
context.activeState.agc.exposure = 10ms / context.configuration.sensor.lineDuration;

/*
* According to the RkISP1 documentation:
Expand All @@ -98,7 +98,10 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)
context.configuration.agc.measureWindow.h_size = 3 * configInfo.outputSize.width / 4;
context.configuration.agc.measureWindow.v_size = 3 * configInfo.outputSize.height / 4;

/* \todo Use actual frame index by populating it in the frameContext. */
/*
* \todo Use the upcoming per-frame context API that will provide a
* frame index
*/
frameCount_ = 0;
return 0;
}
Expand Down Expand Up @@ -140,18 +143,18 @@ utils::Duration Agc::filterExposure(utils::Duration exposureValue)

/**
* \brief Estimate the new exposure and gain values
* \param[inout] frameContext The shared IPA frame Context
* \param[inout] context The shared IPA Context
* \param[in] yGain The gain calculated on the current brightness level
* \param[in] iqMeanGain The gain calculated based on the relative luminance target
*/
void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain)
{
IPASessionConfiguration &configuration = context.configuration;
IPAFrameContext &frameContext = context.frameContext;
IPAActiveState &activeState = context.activeState;

/* Get the effective exposure and gain applied on the sensor. */
uint32_t exposure = frameContext.sensor.exposure;
double analogueGain = frameContext.sensor.gain;
uint32_t exposure = activeState.sensor.exposure;
double analogueGain = activeState.sensor.gain;

/* Use the highest of the two gain estimates. */
double evGain = std::max(yGain, iqMeanGain);
Expand Down Expand Up @@ -216,8 +219,8 @@ void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain)
<< stepGain;

/* Update the estimated exposure and gain. */
frameContext.agc.exposure = shutterTime / configuration.sensor.lineDuration;
frameContext.agc.gain = stepGain;
activeState.agc.exposure = shutterTime / configuration.sensor.lineDuration;
activeState.agc.gain = stepGain;
}

/**
Expand Down Expand Up @@ -329,7 +332,7 @@ void Agc::prepare(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
rkisp1_params_cfg *params)
{
if (context.frameContext.frameCount > 0)
if (context.activeState.frameCount > 0)
return;

/* Configure the measurement window. */
Expand Down
40 changes: 20 additions & 20 deletions src/ipa/rkisp1/algorithms/awb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ LOG_DEFINE_CATEGORY(RkISP1Awb)
int Awb::configure(IPAContext &context,
const IPACameraSensorInfo &configInfo)
{
context.frameContext.awb.gains.red = 1.0;
context.frameContext.awb.gains.blue = 1.0;
context.frameContext.awb.gains.green = 1.0;
context.frameContext.awb.autoEnabled = true;
context.activeState.awb.gains.red = 1.0;
context.activeState.awb.gains.blue = 1.0;
context.activeState.awb.gains.green = 1.0;
context.activeState.awb.autoEnabled = true;

/*
* Define the measurement window for AWB as a centered rectangle
Expand Down Expand Up @@ -79,16 +79,16 @@ void Awb::prepare(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
rkisp1_params_cfg *params)
{
params->others.awb_gain_config.gain_green_b = 256 * context.frameContext.awb.gains.green;
params->others.awb_gain_config.gain_blue = 256 * context.frameContext.awb.gains.blue;
params->others.awb_gain_config.gain_red = 256 * context.frameContext.awb.gains.red;
params->others.awb_gain_config.gain_green_r = 256 * context.frameContext.awb.gains.green;
params->others.awb_gain_config.gain_green_b = 256 * context.activeState.awb.gains.green;
params->others.awb_gain_config.gain_blue = 256 * context.activeState.awb.gains.blue;
params->others.awb_gain_config.gain_red = 256 * context.activeState.awb.gains.red;
params->others.awb_gain_config.gain_green_r = 256 * context.activeState.awb.gains.green;

/* Update the gains. */
params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_AWB_GAIN;

/* If we already have configured the gains and window, return. */
if (context.frameContext.frameCount > 0)
if (context.activeState.frameCount > 0)
return;

/* Configure the gains to apply. */
Expand Down Expand Up @@ -131,7 +131,7 @@ void Awb::queueRequest(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
const ControlList &controls)
{
auto &awb = context.frameContext.awb;
auto &awb = context.activeState.awb;

const auto &awbEnable = controls.get(controls::AwbEnable);
if (awbEnable && *awbEnable != awb.autoEnabled) {
Expand Down Expand Up @@ -162,7 +162,7 @@ void Awb::process([[maybe_unused]] IPAContext &context,
{
const rkisp1_cif_isp_stat *params = &stats->params;
const rkisp1_cif_isp_awb_stat *awb = &params->awb;
IPAFrameContext &frameContext = context.frameContext;
IPAActiveState &activeState = context.activeState;

/* Get the YCbCr mean values */
double yMean = awb->awb_mean[0].mean_y_or_g;
Expand Down Expand Up @@ -194,24 +194,24 @@ void Awb::process([[maybe_unused]] IPAContext &context,

/* Filter the values to avoid oscillations. */
double speed = 0.2;
redGain = speed * redGain + (1 - speed) * frameContext.awb.gains.red;
blueGain = speed * blueGain + (1 - speed) * frameContext.awb.gains.blue;
redGain = speed * redGain + (1 - speed) * activeState.awb.gains.red;
blueGain = speed * blueGain + (1 - speed) * activeState.awb.gains.blue;

/*
* Gain values are unsigned integer value, range 0 to 4 with 8 bit
* fractional part.
*/
if (frameContext.awb.autoEnabled) {
frameContext.awb.gains.red = std::clamp(redGain, 0.0, 1023.0 / 256);
frameContext.awb.gains.blue = std::clamp(blueGain, 0.0, 1023.0 / 256);
if (activeState.awb.autoEnabled) {
activeState.awb.gains.red = std::clamp(redGain, 0.0, 1023.0 / 256);
activeState.awb.gains.blue = std::clamp(blueGain, 0.0, 1023.0 / 256);
}
/* Hardcode the green gain to 1.0. */
frameContext.awb.gains.green = 1.0;
activeState.awb.gains.green = 1.0;

frameContext.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);
activeState.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);

LOG(RkISP1Awb, Debug) << "Gain found for red: " << context.frameContext.awb.gains.red
<< " and for blue: " << context.frameContext.awb.gains.blue;
LOG(RkISP1Awb, Debug) << "Gain found for red: " << context.activeState.awb.gains.red
<< " and for blue: " << context.activeState.awb.gains.blue;
}

REGISTER_IPA_ALGORITHM(Awb, "Awb")
Expand Down
2 changes: 1 addition & 1 deletion src/ipa/rkisp1/algorithms/blc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void BlackLevelCorrection::prepare(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
rkisp1_params_cfg *params)
{
if (context.frameContext.frameCount > 0)
if (context.activeState.frameCount > 0)
return;

if (!tuningParameters_)
Expand Down
4 changes: 2 additions & 2 deletions src/ipa/rkisp1/algorithms/cproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void ColorProcessing::queueRequest(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
const ControlList &controls)
{
auto &cproc = context.frameContext.cproc;
auto &cproc = context.activeState.cproc;

const auto &brightness = controls.get(controls::Brightness);
if (brightness) {
Expand Down Expand Up @@ -76,7 +76,7 @@ void ColorProcessing::prepare(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
rkisp1_params_cfg *params)
{
auto &cproc = context.frameContext.cproc;
auto &cproc = context.activeState.cproc;

/* Check if the algorithm configuration has been updated. */
if (!cproc.updateParams)
Expand Down
2 changes: 1 addition & 1 deletion src/ipa/rkisp1/algorithms/dpcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void DefectPixelClusterCorrection::prepare(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
rkisp1_params_cfg *params)
{
if (context.frameContext.frameCount > 0)
if (context.activeState.frameCount > 0)
return;

if (!initialized_)
Expand Down
6 changes: 3 additions & 3 deletions src/ipa/rkisp1/algorithms/dpf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void Dpf::queueRequest(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
const ControlList &controls)
{
auto &dpf = context.frameContext.dpf;
auto &dpf = context.activeState.dpf;

const auto &denoise = controls.get(controls::draft::NoiseReductionMode);
if (denoise) {
Expand Down Expand Up @@ -214,9 +214,9 @@ void Dpf::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
if (!initialized_)
return;

auto &dpf = context.frameContext.dpf;
auto &dpf = context.activeState.dpf;

if (context.frameContext.frameCount == 0) {
if (context.activeState.frameCount == 0) {
params->others.dpf_config = config_;
params->others.dpf_strength_config = strengthConfig_;

Expand Down
4 changes: 2 additions & 2 deletions src/ipa/rkisp1/algorithms/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Filter::queueRequest(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
const ControlList &controls)
{
auto &filter = context.frameContext.filter;
auto &filter = context.activeState.filter;

const auto &sharpness = controls.get(controls::Sharpness);
if (sharpness) {
Expand Down Expand Up @@ -91,7 +91,7 @@ void Filter::prepare(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
rkisp1_params_cfg *params)
{
auto &filter = context.frameContext.filter;
auto &filter = context.activeState.filter;

/* Check if the algorithm configuration has been updated. */
if (!filter.updateParams)
Expand Down
2 changes: 1 addition & 1 deletion src/ipa/rkisp1/algorithms/gsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void GammaSensorLinearization::prepare(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
rkisp1_params_cfg *params)
{
if (context.frameContext.frameCount > 0)
if (context.activeState.frameCount > 0)
return;

if (!initialized_)
Expand Down
2 changes: 1 addition & 1 deletion src/ipa/rkisp1/algorithms/lsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void LensShadingCorrection::prepare(IPAContext &context,
[[maybe_unused]] IPAFrameContext &frameContext,
rkisp1_params_cfg *params)
{
if (context.frameContext.frameCount > 0)
if (context.activeState.frameCount > 0)
return;

if (!initialized_)
Expand Down
Loading

0 comments on commit 9063733

Please sign in to comment.