| Message ID | 20260114-sklug-lsc-resampling-v2-dev-v3-9-80cd24f4dd61@ideasonboard.com |
|---|---|
| State | Superseded |
| Headers | show |
| Series |
|
| Related | show |
2026. 01. 14. 12:58 keltezéssel, Stefan Klug írta: > The quantization functionality in the Interpolator hinders in writing It's a small thing, but I'd add "the Interpolator >type<". > nice code. Don't use it and implement the functionality directly in the > algorithm. > > While at it, reduce the threshold to half of the quantization step size, > otherwise it might happen that we skip a full quantization step. Rename > the kColourTemperatureChangeThreshhold to kColourTemperatureQuantization > to better express the usecase. > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > --- > > Changes in v3: > - Reduce threshold to quantization step/2 > - Drop unnecessary static modifier > - Collected tag > > Changes in v2: > - Added this patch > --- > src/ipa/rkisp1/algorithms/lsc.cpp | 25 ++++++++++++++++++------- > 1 file changed, 18 insertions(+), 7 deletions(-) > > diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp > index c42f74557c7364935254d75ee1fb923d176e0dbd..77ed0a95209ac13e82f4ee43f7a22095bb5fd65f 100644 > --- a/src/ipa/rkisp1/algorithms/lsc.cpp > +++ b/src/ipa/rkisp1/algorithms/lsc.cpp > @@ -70,7 +70,7 @@ LOG_DEFINE_CATEGORY(RkISP1Lsc) > > namespace { > > -constexpr int kColourTemperatureChangeThreshhold = 10; > +constexpr int kColourTemperatureQuantization = 10; > > class LscPolynomialLoader > { > @@ -308,12 +308,16 @@ std::vector<double> parseSizes(const YamlObject &tuningData, > return sizes; > } > > +unsigned int quantize(unsigned int value, unsigned int step) > +{ > + return std::lround(value / static_cast<double>(step)) * step; > +} > + > } /* namespace */ > > LensShadingCorrection::LensShadingCorrection() > : lastAppliedCt_(0), lastAppliedQuantizedCt_(0) > { > - sets_.setQuantization(kColourTemperatureChangeThreshhold); > } > > /** > @@ -426,17 +430,24 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context, > RkISP1Params *params) > { > uint32_t ct = frameContext.awb.temperatureK; > - if (std::abs(static_cast<int>(ct) - static_cast<int>(lastAppliedCt_)) < > - kColourTemperatureChangeThreshhold) > + unsigned int quantizedCt = quantize(ct, kColourTemperatureQuantization); > + int ctDiff = static_cast<int>(ct) - static_cast<int>(lastAppliedCt_); > + > + /* > + * Add a threshold so that oscillations around a quantization step don't > + * lead to constant changes. > + */ > + if (std::abs(ctDiff) < kColourTemperatureQuantization / 2) utils::abs_diff(ct, lastAppliedCt_) could be used here. Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > return; > - unsigned int quantizedCt; > - const Components &set = sets_.getInterpolated(ct, &quantizedCt); > - if (lastAppliedQuantizedCt_ == quantizedCt) > + > + if (quantizedCt == lastAppliedQuantizedCt_) > return; > > auto config = params->block<BlockType::Lsc>(); > config.setEnabled(true); > setParameters(*config); > + > + const Components &set = sets_.getInterpolated(quantizedCt); > copyTable(*config, set); > > lastAppliedCt_ = ct; >
diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp index c42f74557c7364935254d75ee1fb923d176e0dbd..77ed0a95209ac13e82f4ee43f7a22095bb5fd65f 100644 --- a/src/ipa/rkisp1/algorithms/lsc.cpp +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -70,7 +70,7 @@ LOG_DEFINE_CATEGORY(RkISP1Lsc) namespace { -constexpr int kColourTemperatureChangeThreshhold = 10; +constexpr int kColourTemperatureQuantization = 10; class LscPolynomialLoader { @@ -308,12 +308,16 @@ std::vector<double> parseSizes(const YamlObject &tuningData, return sizes; } +unsigned int quantize(unsigned int value, unsigned int step) +{ + return std::lround(value / static_cast<double>(step)) * step; +} + } /* namespace */ LensShadingCorrection::LensShadingCorrection() : lastAppliedCt_(0), lastAppliedQuantizedCt_(0) { - sets_.setQuantization(kColourTemperatureChangeThreshhold); } /** @@ -426,17 +430,24 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context, RkISP1Params *params) { uint32_t ct = frameContext.awb.temperatureK; - if (std::abs(static_cast<int>(ct) - static_cast<int>(lastAppliedCt_)) < - kColourTemperatureChangeThreshhold) + unsigned int quantizedCt = quantize(ct, kColourTemperatureQuantization); + int ctDiff = static_cast<int>(ct) - static_cast<int>(lastAppliedCt_); + + /* + * Add a threshold so that oscillations around a quantization step don't + * lead to constant changes. + */ + if (std::abs(ctDiff) < kColourTemperatureQuantization / 2) return; - unsigned int quantizedCt; - const Components &set = sets_.getInterpolated(ct, &quantizedCt); - if (lastAppliedQuantizedCt_ == quantizedCt) + + if (quantizedCt == lastAppliedQuantizedCt_) return; auto config = params->block<BlockType::Lsc>(); config.setEnabled(true); setParameters(*config); + + const Components &set = sets_.getInterpolated(quantizedCt); copyTable(*config, set); lastAppliedCt_ = ct;