ipa: rkisp1: filter: Store per-frame information in frame context

Rework the algorithm's usage of the active state, to store the value of
controls for the last queued request in the queueRequest() function, and
store a copy of the values in the corresponding frame context. The
latter is used in the prepare() function to populate the ISP parameters
with values corresponding to the right frame.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Laurent Pinchart 2022-09-08 00:39:53 +03:00
parent 3c3e0aa123
commit a90dc9bc5c
3 changed files with 51 additions and 23 deletions

View file

@ -44,15 +44,20 @@ static constexpr uint32_t kFiltModeDefault = 0x000004f2;
*/ */
void Filter::queueRequest(IPAContext &context, void Filter::queueRequest(IPAContext &context,
[[maybe_unused]] const uint32_t frame, [[maybe_unused]] const uint32_t frame,
[[maybe_unused]] IPAFrameContext &frameContext, IPAFrameContext &frameContext,
const ControlList &controls) const ControlList &controls)
{ {
auto &filter = context.activeState.filter; auto &filter = context.activeState.filter;
bool update = false;
const auto &sharpness = controls.get(controls::Sharpness); const auto &sharpness = controls.get(controls::Sharpness);
if (sharpness) { if (sharpness) {
filter.sharpness = std::round(std::clamp(*sharpness, 0.0f, 10.0f)); unsigned int value = std::round(std::clamp(*sharpness, 0.0f, 10.0f));
filter.updateParams = true;
if (filter.sharpness != value) {
filter.sharpness = value;
update = true;
}
LOG(RkISP1Filter, Debug) << "Set sharpness to " << *sharpness; LOG(RkISP1Filter, Debug) << "Set sharpness to " << *sharpness;
} }
@ -63,42 +68,48 @@ void Filter::queueRequest(IPAContext &context,
switch (*denoise) { switch (*denoise) {
case controls::draft::NoiseReductionModeOff: case controls::draft::NoiseReductionModeOff:
filter.denoise = 0; if (filter.denoise != 0) {
filter.updateParams = true; filter.denoise = 0;
update = true;
}
break; break;
case controls::draft::NoiseReductionModeMinimal: case controls::draft::NoiseReductionModeMinimal:
filter.denoise = 1; if (filter.denoise != 1) {
filter.updateParams = true; filter.denoise = 1;
update = true;
}
break; break;
case controls::draft::NoiseReductionModeHighQuality: case controls::draft::NoiseReductionModeHighQuality:
case controls::draft::NoiseReductionModeFast: case controls::draft::NoiseReductionModeFast:
filter.denoise = 3; if (filter.denoise != 3) {
filter.updateParams = true; filter.denoise = 3;
update = true;
}
break; break;
default: default:
LOG(RkISP1Filter, Error) LOG(RkISP1Filter, Error)
<< "Unsupported denoise value " << "Unsupported denoise value "
<< *denoise; << *denoise;
break;
} }
} }
frameContext.filter.denoise = filter.denoise;
frameContext.filter.sharpness = filter.sharpness;
frameContext.filter.update = update;
} }
/** /**
* \copydoc libcamera::ipa::Algorithm::prepare * \copydoc libcamera::ipa::Algorithm::prepare
*/ */
void Filter::prepare(IPAContext &context, void Filter::prepare([[maybe_unused]] IPAContext &context,
[[maybe_unused]] const uint32_t frame, [[maybe_unused]] const uint32_t frame,
[[maybe_unused]] IPAFrameContext &frameContext, IPAFrameContext &frameContext, rkisp1_params_cfg *params)
rkisp1_params_cfg *params)
{ {
auto &filter = context.activeState.filter;
/* Check if the algorithm configuration has been updated. */ /* Check if the algorithm configuration has been updated. */
if (!filter.updateParams) if (!frameContext.filter.update)
return; return;
filter.updateParams = false;
static constexpr uint16_t filt_fac_sh0[] = { static constexpr uint16_t filt_fac_sh0[] = {
0x04, 0x07, 0x0a, 0x0c, 0x10, 0x14, 0x1a, 0x1e, 0x24, 0x2a, 0x30 0x04, 0x07, 0x0a, 0x0c, 0x10, 0x14, 0x1a, 0x1e, 0x24, 0x2a, 0x30
}; };
@ -147,8 +158,8 @@ void Filter::prepare(IPAContext &context,
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
}; };
uint8_t denoise = filter.denoise; uint8_t denoise = frameContext.filter.denoise;
uint8_t sharpness = filter.sharpness; uint8_t sharpness = frameContext.filter.sharpness;
auto &flt_config = params->others.flt_config; auto &flt_config = params->others.flt_config;
flt_config.fac_sh0 = filt_fac_sh0[sharpness]; flt_config.fac_sh0 = filt_fac_sh0[sharpness];

View file

@ -179,9 +179,6 @@ namespace libcamera::ipa::rkisp1 {
* *
* \var IPAActiveState::filter.sharpness * \var IPAActiveState::filter.sharpness
* \brief Sharpness level * \brief Sharpness level
*
* \var IPAActiveState::filter.updateParams
* \brief Indicates if ISP parameters need to be updated
*/ */
/** /**
@ -260,6 +257,21 @@ namespace libcamera::ipa::rkisp1 {
* compared to the previous frame * compared to the previous frame
*/ */
/**
* \var IPAFrameContext::filter
* \brief Filter parameters for this frame
*
* \struct IPAFrameContext::filter.denoise
* \brief Denoising level
*
* \var IPAFrameContext::filter.sharpness
* \brief Sharpness level
*
* \var IPAFrameContext::filter.updateParams
* \brief Indicates if the filter parameters have been updated compared to the
* previous frame
*/
/** /**
* \var IPAFrameContext::sensor * \var IPAFrameContext::sensor
* \brief Sensor configuration that used been used for this frame * \brief Sensor configuration that used been used for this frame

View file

@ -84,7 +84,6 @@ struct IPAActiveState {
struct { struct {
uint8_t denoise; uint8_t denoise;
uint8_t sharpness; uint8_t sharpness;
bool updateParams;
} filter; } filter;
}; };
@ -117,6 +116,12 @@ struct IPAFrameContext : public FrameContext {
bool update; bool update;
} dpf; } dpf;
struct {
uint8_t denoise;
uint8_t sharpness;
bool update;
} filter;
struct { struct {
uint32_t exposure; uint32_t exposure;
double gain; double gain;