| Message ID | 20261102101610.877390-11-barnabas.pocze@ideasonboard.com |
|---|---|
| State | Superseded |
| Headers | show |
| Series |
|
| Related | show |
Hi Barnabás, Quoting Barnabás Pőcze (2026-11-02 11:15:56) > Currently `splitExposure()` will raise the exposure and analogue gain above > what is specified in the last stage, if the desired exposure could not be > reached. This behaviour is different from that of the raspberry pi ipa, > and also could be surprising to the user / tuning file creator. > > So make sure that the exposure time and analogue gain is limited by the > last stage, in addition to the runtime controlled upper bound. Yes, I think that makes sense (allthough it then requires better tuning files with proper upper limits on exposure/gain - but that is fine). > > With this change, at least one stage is required, so an assertions are added. > And the general agc algorithm is adjusted to provide stages for the fallback > "Maximize" mode. The more I think about that, is that I don't know why we'd add a maximize mode. Why not increase the last exposure/gain pair to very large values? Best regards, Stefan > > Closes: https://gitlab.freedesktop.org/camera/libcamera/-/work_items/362 > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> > --- > src/ipa/libipa/agc.cpp | 7 ++++++- > src/ipa/libipa/exposure_mode_helper.cpp | 23 +++++++++++------------ > 2 files changed, 17 insertions(+), 13 deletions(-) > > diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp > index 3bc7e67b71..2a8dd36244 100644 > --- a/src/ipa/libipa/agc.cpp > +++ b/src/ipa/libipa/agc.cpp > @@ -463,7 +463,12 @@ void addFallbacks(AgcMeanLuminance::Configuration &config) > if (config.exposureModeHelpers.empty()) > config.exposureModeHelpers.try_emplace( > controls::AeExposureModeMaximize, > - std::vector<ExposureModeHelper::Stage>{}); > + std::vector{ > + ExposureModeHelper::Stage{ > + .exposureTime = utils::Duration::max(), > + .gain = std::numeric_limits<double>::max(), > + }, > + }); > } > > } /* namespace */ > diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp > index 4076d6f385..9714cc950e 100644 > --- a/src/ipa/libipa/exposure_mode_helper.cpp > +++ b/src/ipa/libipa/exposure_mode_helper.cpp > @@ -84,6 +84,7 @@ ExposureModeHelper::ExposureModeHelper(std::vector<Stage> &&stages) > : stages_(std::move(stages)), lineDuration_(1us), minExposureTime_(0us), > maxExposureTime_(0us), minGain_(0), maxGain_(0), sensorHelper_(nullptr) > { > + ASSERT(!stages_.empty()); > } > > /** > @@ -203,8 +204,8 @@ double ExposureModeHelper::clampGain(double gain, double *quantizationGain) cons > * value. > * > * If no combination of exposure time and gain limits is found that meets the > - * required exposure, the helper falls-back to simply maximising the exposure > - * time first, followed by analogue gain, followed by digital gain. > + * required exposure, then the exposure and gain of the last stage will be used, > + * and the digital gain will be increased as necessary. > * > * During the calculations the gain missed due to quantization is recorded and > * returned as quantization gain. The quantization gain is not included in the > @@ -219,6 +220,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const > { > ASSERT(maxExposureTime_); > ASSERT(maxGain_); > + ASSERT(!stages_.empty()); > > utils::Duration exposureTime; > double gain; > @@ -240,11 +242,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const > exposure / (exposureTime * gain * quantGain) }; > } > > + utils::Duration stageExposureTime = {}; > double stageGain = clampGain(1.0); > > for (const auto &stage : stages_) { > - utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime, > - &quantGain); > + stageExposureTime = clampExposureTime(stage.exposureTime, &quantGain); > > /* > * We perform the clamping on both exposure time and gain in > @@ -265,7 +267,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const > } > > /* Clamp the exposure time to stageExposureTime and regulate gain. */ > - stageGain = clampGain(stage.gain); > + stageGain = clampGain(stage.gain, &quantGain2); > > if (stageExposureTime * stageGain >= exposure) { > exposureTime = stageExposureTime; > @@ -278,14 +280,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const > } > > /* > - * From here on all we can do is max out the exposure time, followed by > - * the analogue gain. If we still haven't achieved the target we send > - * the rest of the exposure time to digital gain. If we were given no > - * stages to use then the default stageGain of 1.0 is used so that > - * exposure time is maxed before gain is touched at all. > + * If no stages could satisfy the desired exposure, then use the last > + * stage's exposure time and gain, which is the maximum allowed. > */ > - exposureTime = clampExposureTime(exposure / stageGain, &quantGain); > - gain = clampGain(exposure / exposureTime, &quantGain2); > + exposureTime = stageExposureTime; > + gain = stageGain; > quantGain *= quantGain2; > > return { exposureTime, gain, quantGain, > -- > 2.56.0 >
2026. 11. 05. 11:13 keltezéssel, Stefan Klug írta: > Hi Barnabás, > > Quoting Barnabás Pőcze (2026-11-02 11:15:56) >> Currently `splitExposure()` will raise the exposure and analogue gain above >> what is specified in the last stage, if the desired exposure could not be >> reached. This behaviour is different from that of the raspberry pi ipa, >> and also could be surprising to the user / tuning file creator. >> >> So make sure that the exposure time and analogue gain is limited by the >> last stage, in addition to the runtime controlled upper bound. > > Yes, I think that makes sense (allthough it then requires better tuning > files with proper upper limits on exposure/gain - but that is fine). > >> >> With this change, at least one stage is required, so an assertions are added. >> And the general agc algorithm is adjusted to provide stages for the fallback >> "Maximize" mode. > > The more I think about that, is that I don't know why we'd add a > maximize mode. Why not increase the last exposure/gain pair to very > large values? Can you elaborate where you image this increase? In the tuning files "manually"? Or in the code "automatically"? Or something else? > > Best regards, > Stefan > >> >> Closes: https://gitlab.freedesktop.org/camera/libcamera/-/work_items/362 >> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> >> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> >> --- >> src/ipa/libipa/agc.cpp | 7 ++++++- >> src/ipa/libipa/exposure_mode_helper.cpp | 23 +++++++++++------------ >> 2 files changed, 17 insertions(+), 13 deletions(-) >> >> diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp >> index 3bc7e67b71..2a8dd36244 100644 >> --- a/src/ipa/libipa/agc.cpp >> +++ b/src/ipa/libipa/agc.cpp >> @@ -463,7 +463,12 @@ void addFallbacks(AgcMeanLuminance::Configuration &config) >> if (config.exposureModeHelpers.empty()) >> config.exposureModeHelpers.try_emplace( >> controls::AeExposureModeMaximize, >> - std::vector<ExposureModeHelper::Stage>{}); >> + std::vector{ >> + ExposureModeHelper::Stage{ >> + .exposureTime = utils::Duration::max(), >> + .gain = std::numeric_limits<double>::max(), >> + }, >> + }); >> } >> >> } /* namespace */ >> diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp >> index 4076d6f385..9714cc950e 100644 >> --- a/src/ipa/libipa/exposure_mode_helper.cpp >> +++ b/src/ipa/libipa/exposure_mode_helper.cpp >> @@ -84,6 +84,7 @@ ExposureModeHelper::ExposureModeHelper(std::vector<Stage> &&stages) >> : stages_(std::move(stages)), lineDuration_(1us), minExposureTime_(0us), >> maxExposureTime_(0us), minGain_(0), maxGain_(0), sensorHelper_(nullptr) >> { >> + ASSERT(!stages_.empty()); >> } >> >> /** >> @@ -203,8 +204,8 @@ double ExposureModeHelper::clampGain(double gain, double *quantizationGain) cons >> * value. >> * >> * If no combination of exposure time and gain limits is found that meets the >> - * required exposure, the helper falls-back to simply maximising the exposure >> - * time first, followed by analogue gain, followed by digital gain. >> + * required exposure, then the exposure and gain of the last stage will be used, >> + * and the digital gain will be increased as necessary. >> * >> * During the calculations the gain missed due to quantization is recorded and >> * returned as quantization gain. The quantization gain is not included in the >> @@ -219,6 +220,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const >> { >> ASSERT(maxExposureTime_); >> ASSERT(maxGain_); >> + ASSERT(!stages_.empty()); >> >> utils::Duration exposureTime; >> double gain; >> @@ -240,11 +242,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const >> exposure / (exposureTime * gain * quantGain) }; >> } >> >> + utils::Duration stageExposureTime = {}; >> double stageGain = clampGain(1.0); >> >> for (const auto &stage : stages_) { >> - utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime, >> - &quantGain); >> + stageExposureTime = clampExposureTime(stage.exposureTime, &quantGain); >> >> /* >> * We perform the clamping on both exposure time and gain in >> @@ -265,7 +267,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const >> } >> >> /* Clamp the exposure time to stageExposureTime and regulate gain. */ >> - stageGain = clampGain(stage.gain); >> + stageGain = clampGain(stage.gain, &quantGain2); >> >> if (stageExposureTime * stageGain >= exposure) { >> exposureTime = stageExposureTime; >> @@ -278,14 +280,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const >> } >> >> /* >> - * From here on all we can do is max out the exposure time, followed by >> - * the analogue gain. If we still haven't achieved the target we send >> - * the rest of the exposure time to digital gain. If we were given no >> - * stages to use then the default stageGain of 1.0 is used so that >> - * exposure time is maxed before gain is touched at all. >> + * If no stages could satisfy the desired exposure, then use the last >> + * stage's exposure time and gain, which is the maximum allowed. >> */ >> - exposureTime = clampExposureTime(exposure / stageGain, &quantGain); >> - gain = clampGain(exposure / exposureTime, &quantGain2); >> + exposureTime = stageExposureTime; >> + gain = stageGain; >> quantGain *= quantGain2; >> >> return { exposureTime, gain, quantGain, >> -- >> 2.56.0 >>
Hi Barnabás, Quoting Barnabás Pőcze (2026-11-05 11:24:03) > 2026. 11. 05. 11:13 keltezéssel, Stefan Klug írta: > > Hi Barnabás, > > > > Quoting Barnabás Pőcze (2026-11-02 11:15:56) > >> Currently `splitExposure()` will raise the exposure and analogue gain above > >> what is specified in the last stage, if the desired exposure could not be > >> reached. This behaviour is different from that of the raspberry pi ipa, > >> and also could be surprising to the user / tuning file creator. > >> > >> So make sure that the exposure time and analogue gain is limited by the > >> last stage, in addition to the runtime controlled upper bound. > > > > Yes, I think that makes sense (allthough it then requires better tuning > > files with proper upper limits on exposure/gain - but that is fine). > > > >> > >> With this change, at least one stage is required, so an assertions are added. > >> And the general agc algorithm is adjusted to provide stages for the fallback > >> "Maximize" mode. > > > > The more I think about that, is that I don't know why we'd add a > > maximize mode. Why not increase the last exposure/gain pair to very > > large values? > > Can you elaborate where you image this increase? In the tuning files "manually"? > Or in the code "automatically"? Or something else? > To me the exposure modes are "strategies" on how to reach the requested exposure. In typical cameras you can decide between aperture priority and exposure priority, which serves a similar purpose (although it doesn't include gain). Our tuning files contain "Normal" which is supposed to be well normal, "Short" which is supposed to prioritize short exposure times, thereby accepting higher gains and "Long" which reduces noise at the expense of longer exposures. But Maximize is not a strategy. It is workaround to model the old behavior. So to have the old behavior with the normal mode, you could simply set the last exposure/gain pair to very large values in the tuning file. Then we might think of a control that can be used to limit the exposure time at runtime. Basically ExposureTimeLimits and GainLimits, the same way we have FrameDurationLimits. If I understood it right, the reason for the Maximaize mode is that AgcMSV doesn't support exposure modes. Isn't that then the ExposureModeNormal for that algorithm? Best regards, Stefan > > > > > Best regards, > > Stefan > > > >> > >> Closes: https://gitlab.freedesktop.org/camera/libcamera/-/work_items/362 > >> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > >> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> > >> --- > >> src/ipa/libipa/agc.cpp | 7 ++++++- > >> src/ipa/libipa/exposure_mode_helper.cpp | 23 +++++++++++------------ > >> 2 files changed, 17 insertions(+), 13 deletions(-) > >> > >> diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp > >> index 3bc7e67b71..2a8dd36244 100644 > >> --- a/src/ipa/libipa/agc.cpp > >> +++ b/src/ipa/libipa/agc.cpp > >> @@ -463,7 +463,12 @@ void addFallbacks(AgcMeanLuminance::Configuration &config) > >> if (config.exposureModeHelpers.empty()) > >> config.exposureModeHelpers.try_emplace( > >> controls::AeExposureModeMaximize, > >> - std::vector<ExposureModeHelper::Stage>{}); > >> + std::vector{ > >> + ExposureModeHelper::Stage{ > >> + .exposureTime = utils::Duration::max(), > >> + .gain = std::numeric_limits<double>::max(), > >> + }, > >> + }); > >> } > >> > >> } /* namespace */ > >> diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp > >> index 4076d6f385..9714cc950e 100644 > >> --- a/src/ipa/libipa/exposure_mode_helper.cpp > >> +++ b/src/ipa/libipa/exposure_mode_helper.cpp > >> @@ -84,6 +84,7 @@ ExposureModeHelper::ExposureModeHelper(std::vector<Stage> &&stages) > >> : stages_(std::move(stages)), lineDuration_(1us), minExposureTime_(0us), > >> maxExposureTime_(0us), minGain_(0), maxGain_(0), sensorHelper_(nullptr) > >> { > >> + ASSERT(!stages_.empty()); > >> } > >> > >> /** > >> @@ -203,8 +204,8 @@ double ExposureModeHelper::clampGain(double gain, double *quantizationGain) cons > >> * value. > >> * > >> * If no combination of exposure time and gain limits is found that meets the > >> - * required exposure, the helper falls-back to simply maximising the exposure > >> - * time first, followed by analogue gain, followed by digital gain. > >> + * required exposure, then the exposure and gain of the last stage will be used, > >> + * and the digital gain will be increased as necessary. > >> * > >> * During the calculations the gain missed due to quantization is recorded and > >> * returned as quantization gain. The quantization gain is not included in the > >> @@ -219,6 +220,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const > >> { > >> ASSERT(maxExposureTime_); > >> ASSERT(maxGain_); > >> + ASSERT(!stages_.empty()); > >> > >> utils::Duration exposureTime; > >> double gain; > >> @@ -240,11 +242,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const > >> exposure / (exposureTime * gain * quantGain) }; > >> } > >> > >> + utils::Duration stageExposureTime = {}; > >> double stageGain = clampGain(1.0); > >> > >> for (const auto &stage : stages_) { > >> - utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime, > >> - &quantGain); > >> + stageExposureTime = clampExposureTime(stage.exposureTime, &quantGain); > >> > >> /* > >> * We perform the clamping on both exposure time and gain in > >> @@ -265,7 +267,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const > >> } > >> > >> /* Clamp the exposure time to stageExposureTime and regulate gain. */ > >> - stageGain = clampGain(stage.gain); > >> + stageGain = clampGain(stage.gain, &quantGain2); > >> > >> if (stageExposureTime * stageGain >= exposure) { > >> exposureTime = stageExposureTime; > >> @@ -278,14 +280,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const > >> } > >> > >> /* > >> - * From here on all we can do is max out the exposure time, followed by > >> - * the analogue gain. If we still haven't achieved the target we send > >> - * the rest of the exposure time to digital gain. If we were given no > >> - * stages to use then the default stageGain of 1.0 is used so that > >> - * exposure time is maxed before gain is touched at all. > >> + * If no stages could satisfy the desired exposure, then use the last > >> + * stage's exposure time and gain, which is the maximum allowed. > >> */ > >> - exposureTime = clampExposureTime(exposure / stageGain, &quantGain); > >> - gain = clampGain(exposure / exposureTime, &quantGain2); > >> + exposureTime = stageExposureTime; > >> + gain = stageGain; > >> quantGain *= quantGain2; > >> > >> return { exposureTime, gain, quantGain, > >> -- > >> 2.56.0 > >> >
diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp index 3bc7e67b71..2a8dd36244 100644 --- a/src/ipa/libipa/agc.cpp +++ b/src/ipa/libipa/agc.cpp @@ -463,7 +463,12 @@ void addFallbacks(AgcMeanLuminance::Configuration &config) if (config.exposureModeHelpers.empty()) config.exposureModeHelpers.try_emplace( controls::AeExposureModeMaximize, - std::vector<ExposureModeHelper::Stage>{}); + std::vector{ + ExposureModeHelper::Stage{ + .exposureTime = utils::Duration::max(), + .gain = std::numeric_limits<double>::max(), + }, + }); } } /* namespace */ diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp index 4076d6f385..9714cc950e 100644 --- a/src/ipa/libipa/exposure_mode_helper.cpp +++ b/src/ipa/libipa/exposure_mode_helper.cpp @@ -84,6 +84,7 @@ ExposureModeHelper::ExposureModeHelper(std::vector<Stage> &&stages) : stages_(std::move(stages)), lineDuration_(1us), minExposureTime_(0us), maxExposureTime_(0us), minGain_(0), maxGain_(0), sensorHelper_(nullptr) { + ASSERT(!stages_.empty()); } /** @@ -203,8 +204,8 @@ double ExposureModeHelper::clampGain(double gain, double *quantizationGain) cons * value. * * If no combination of exposure time and gain limits is found that meets the - * required exposure, the helper falls-back to simply maximising the exposure - * time first, followed by analogue gain, followed by digital gain. + * required exposure, then the exposure and gain of the last stage will be used, + * and the digital gain will be increased as necessary. * * During the calculations the gain missed due to quantization is recorded and * returned as quantization gain. The quantization gain is not included in the @@ -219,6 +220,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const { ASSERT(maxExposureTime_); ASSERT(maxGain_); + ASSERT(!stages_.empty()); utils::Duration exposureTime; double gain; @@ -240,11 +242,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const exposure / (exposureTime * gain * quantGain) }; } + utils::Duration stageExposureTime = {}; double stageGain = clampGain(1.0); for (const auto &stage : stages_) { - utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime, - &quantGain); + stageExposureTime = clampExposureTime(stage.exposureTime, &quantGain); /* * We perform the clamping on both exposure time and gain in @@ -265,7 +267,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const } /* Clamp the exposure time to stageExposureTime and regulate gain. */ - stageGain = clampGain(stage.gain); + stageGain = clampGain(stage.gain, &quantGain2); if (stageExposureTime * stageGain >= exposure) { exposureTime = stageExposureTime; @@ -278,14 +280,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const } /* - * From here on all we can do is max out the exposure time, followed by - * the analogue gain. If we still haven't achieved the target we send - * the rest of the exposure time to digital gain. If we were given no - * stages to use then the default stageGain of 1.0 is used so that - * exposure time is maxed before gain is touched at all. + * If no stages could satisfy the desired exposure, then use the last + * stage's exposure time and gain, which is the maximum allowed. */ - exposureTime = clampExposureTime(exposure / stageGain, &quantGain); - gain = clampGain(exposure / exposureTime, &quantGain2); + exposureTime = stageExposureTime; + gain = stageGain; quantGain *= quantGain2; return { exposureTime, gain, quantGain,