| Message ID | 20261029174329.246241-1-barnabas.pocze@ideasonboard.com |
|---|---|
| State | Accepted |
| Headers | show |
| Series |
|
| Related | show |
Quoting Barnabás Pőcze (2026-10-29 17:43:29) > It is somewhat unfortunate that the parsing logic uses the enum names directly, > and does not have separate key -> value mapping like the rpi ipa has. Commit > 974102049a41 ("libcamera: controls: Remove common enum prefix") has changed > some enum names, crucially some of those have been used in tuning files. > > To make the the transition, add support for using the old names and warn > about the new names. This keeps the users happy and working so I'm good with this. We discussed offline how we'll make this into an error which prints the changes required after release, but for 0.8 we'll handle the conversion internally. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > --- > > Another approach in addition to https://patchwork.libcamera.org/project/libcamera/list/?series=6318, > this is more code, but keeps the old files working. (Apart from the virtual pipeline handler > config file.) > > Similarly, only compile tested. > > --- > src/ipa/libipa/agc_mean_luminance.cpp | 54 ++++++++++++++++++++++++++- > src/ipa/libipa/awb.cpp | 40 ++++++++++++++++---- > 2 files changed, 85 insertions(+), 9 deletions(-) > > diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp > index 486c09c076..a39ea5e504 100644 > --- a/src/ipa/libipa/agc_mean_luminance.cpp > +++ b/src/ipa/libipa/agc_mean_luminance.cpp > @@ -237,11 +237,36 @@ int AgcMeanLuminance::parseConstraint(const ValueNode &modeDict, int32_t id) > > int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) > { > + static constexpr std::tuple<std::string_view, std::string_view, controls::AeConstraintModeEnum> compat[] = { > + { "ConstraintNormal", "Normal", controls::AeConstraintModeNormal }, > + { "ConstraintHighlight", "Highlight", controls::AeConstraintModeHighlight }, > + { "ConstraintShadows", "Shadows", controls::AeConstraintModeShadows }, > + { "ConstraintCustom", "Custom", controls::AeConstraintModeCustom }, > + }; > + > const ValueNode &constraintModes = tuningData[controls::AeConstraintMode.name()]; > if (constraintModes.isDictionary()) { > for (const auto &[modeName, modeDict] : constraintModes.asDict()) { > + std::optional<controls::AeConstraintModeEnum> modeValue; > + > auto it = AeConstraintModeNameValueMap.find(modeName); > if (it == AeConstraintModeNameValueMap.end()) { > + for (const auto &[oldName, newName, v] : compat) { > + if (modeName != oldName) > + continue; > + > + modeValue = v; > + > + LOG(AgcMeanLuminance, Warning) > + << "Constraint mode '" << oldName << "' has been renamed to '" > + << newName << "', please fix the tuning file"; > + break; > + } > + } else { > + modeValue = static_cast<controls::AeConstraintModeEnum>(it->second); > + } > + > + if (!modeValue) { > LOG(AgcMeanLuminance, Warning) > << "Skipping unknown constraint mode '" << modeName << "'"; > continue; > @@ -253,7 +278,7 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) > return -EINVAL; > } > > - int ret = parseConstraint(modeDict, it->second); > + int ret = parseConstraint(modeDict, *modeValue); > if (ret) > return ret; > } > @@ -281,11 +306,36 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) > > int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData) > { > + static constexpr std::tuple<std::string_view, std::string_view, controls::AeExposureModeEnum> compat[] = { > + { "ExposureNormal", "Normal", controls::AeExposureModeNormal }, > + { "ExposureShort", "Short", controls::AeExposureModeShort }, > + { "ExposureLong", "Long", controls::AeExposureModeLong }, > + { "ExposureCustom", "Custom", controls::AeExposureModeCustom }, > + }; > + > const ValueNode &exposureModes = tuningData[controls::AeExposureMode.name()]; > if (exposureModes.isDictionary()) { > for (const auto &[modeName, modeValues] : exposureModes.asDict()) { > + std::optional<controls::AeExposureModeEnum> modeValue; > + > auto it = AeExposureModeNameValueMap.find(modeName); > if (it == AeExposureModeNameValueMap.end()) { > + for (const auto &[oldName, newName, v] : compat) { > + if (modeName != oldName) > + continue; > + > + modeValue = v; > + > + LOG(AgcMeanLuminance, Warning) > + << "Exposure mode '" << oldName << "' has been renamed to '" > + << newName << "', please fix the tuning file"; > + break; > + } > + } else { > + modeValue = static_cast<controls::AeExposureModeEnum>(it->second); > + } > + > + if (!modeValue) { > LOG(AgcMeanLuminance, Warning) > << "Skipping unknown exposure mode '" << modeName << "'"; > continue; > @@ -322,7 +372,7 @@ int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData) > }); > } > > - exposureModeHelpers_.try_emplace(it->second, stages); > + exposureModeHelpers_.try_emplace(*modeValue, stages); > } > } > > diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp > index cad2b5777f..3b95fecee8 100644 > --- a/src/ipa/libipa/awb.cpp > +++ b/src/ipa/libipa/awb.cpp > @@ -451,9 +451,38 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, > return -EINVAL; > } > > + static constexpr std::tuple<std::string_view, std::string_view, controls::AwbModeEnum> compat[] = { > + { "AwbAuto", "Auto", controls::AwbModeAuto }, > + { "AwbIncandescent", "Incandescent", controls::AwbModeIncandescent }, > + { "AwbTungsten", "Tungsten", controls::AwbModeTungsten }, > + { "AwbFluorescent", "Fluorescent", controls::AwbModeFluorescent }, > + { "AwbIndoor", "Indoor", controls::AwbModeIndoor }, > + { "AwbDaylight", "Daylight", controls::AwbModeDaylight }, > + { "AwbCloudy", "Cloudy", controls::AwbModeCloudy }, > + { "AwbCustom", "Custom", controls::AwbModeCustom }, > + }; > + > for (const auto &[modeName, modeDict] : modes.asDict()) { > - if (controls::AwbModeNameValueMap.find(modeName) == > - controls::AwbModeNameValueMap.end()) { > + std::optional<controls::AwbModeEnum> modeValue; > + > + auto it = controls::AwbModeNameValueMap.find(modeName); > + if (it == controls::AwbModeNameValueMap.end()) { > + for (const auto &[oldName, newName, v] : compat) { > + if (modeName != oldName) > + continue; > + > + modeValue = v; > + > + LOG(Awb, Warning) > + << "AWB mode '" << oldName << " has been renamed to '" > + << newName << "', please fix the tuning file"; > + break; > + } > + } else { > + modeValue = static_cast<controls::AwbModeEnum>(it->second); > + } > + > + if (!modeValue) { > LOG(Awb, Warning) > << "Skipping unknown AWB mode '" > << modeName << "'"; > @@ -466,10 +495,7 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, > return -EINVAL; > } > > - const auto &modeValue = static_cast<controls::AwbModeEnum>( > - controls::AwbModeNameValueMap.at(modeName)); > - > - ModeConfig &config = modes_[modeValue]; > + ModeConfig &config = modes_[*modeValue]; > > auto hi = modeDict["hi"].get<double>(); > if (!hi) { > @@ -487,7 +513,7 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, > } > config.ctLo = *lo; > > - availableModes.push_back(modeValue); > + availableModes.push_back(*modeValue); > } > > if (modes_.empty()) { > -- > 2.56.0
On Fri, Oct 30, 2026 at 11:21:13AM +0000, Kieran Bingham wrote: > Quoting Barnabás Pőcze (2026-10-29 17:43:29) > > It is somewhat unfortunate that the parsing logic uses the enum names directly, > > and does not have separate key -> value mapping like the rpi ipa has. Commit > > 974102049a41 ("libcamera: controls: Remove common enum prefix") has changed > > some enum names, crucially some of those have been used in tuning files. > > > > To make the the transition, add support for using the old names and warn > > about the new names. > > This keeps the users happy and working so I'm good with this. > > We discussed offline how we'll make this into an error which prints the > changes required after release, but for 0.8 we'll handle the conversion > internally. > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > > --- > > > > Another approach in addition to https://patchwork.libcamera.org/project/libcamera/list/?series=6318, > > this is more code, but keeps the old files working. (Apart from the virtual pipeline handler > > config file.) > > > > Similarly, only compile tested. > > > > --- > > src/ipa/libipa/agc_mean_luminance.cpp | 54 ++++++++++++++++++++++++++- > > src/ipa/libipa/awb.cpp | 40 ++++++++++++++++---- > > 2 files changed, 85 insertions(+), 9 deletions(-) > > > > diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp > > index 486c09c076..a39ea5e504 100644 > > --- a/src/ipa/libipa/agc_mean_luminance.cpp > > +++ b/src/ipa/libipa/agc_mean_luminance.cpp > > @@ -237,11 +237,36 @@ int AgcMeanLuminance::parseConstraint(const ValueNode &modeDict, int32_t id) > > > > int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) > > { > > + static constexpr std::tuple<std::string_view, std::string_view, controls::AeConstraintModeEnum> compat[] = { > > + { "ConstraintNormal", "Normal", controls::AeConstraintModeNormal }, > > + { "ConstraintHighlight", "Highlight", controls::AeConstraintModeHighlight }, > > + { "ConstraintShadows", "Shadows", controls::AeConstraintModeShadows }, > > + { "ConstraintCustom", "Custom", controls::AeConstraintModeCustom }, > > + }; > > + > > const ValueNode &constraintModes = tuningData[controls::AeConstraintMode.name()]; > > if (constraintModes.isDictionary()) { > > for (const auto &[modeName, modeDict] : constraintModes.asDict()) { > > + std::optional<controls::AeConstraintModeEnum> modeValue; > > + > > auto it = AeConstraintModeNameValueMap.find(modeName); > > if (it == AeConstraintModeNameValueMap.end()) { > > + for (const auto &[oldName, newName, v] : compat) { > > + if (modeName != oldName) > > + continue; > > + > > + modeValue = v; > > + > > + LOG(AgcMeanLuminance, Warning) > > + << "Constraint mode '" << oldName << "' has been renamed to '" > > + << newName << "', please fix the tuning file"; We could make it more explicit: << "Constraint mode '" << oldName << "' has been renamed to '" << newName << "', please update the tuning file. Backward " << "compatibility will be removed in a future release." Hoping it would push people to update their tuning files faster (I know, I'm a hopeless optimist). The log level could also be pushed to Error to make that more visible (assuming people look at the log). One day we should add support to overlay important announcement on the images themselves :-) > > + break; > > + } > > + } else { > > + modeValue = static_cast<controls::AeConstraintModeEnum>(it->second); > > + } > > + > > + if (!modeValue) { > > LOG(AgcMeanLuminance, Warning) > > << "Skipping unknown constraint mode '" << modeName << "'"; > > continue; > > @@ -253,7 +278,7 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) > > return -EINVAL; > > } > > > > - int ret = parseConstraint(modeDict, it->second); > > + int ret = parseConstraint(modeDict, *modeValue); > > if (ret) > > return ret; > > } > > @@ -281,11 +306,36 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) > > > > int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData) > > { > > + static constexpr std::tuple<std::string_view, std::string_view, controls::AeExposureModeEnum> compat[] = { > > + { "ExposureNormal", "Normal", controls::AeExposureModeNormal }, > > + { "ExposureShort", "Short", controls::AeExposureModeShort }, > > + { "ExposureLong", "Long", controls::AeExposureModeLong }, > > + { "ExposureCustom", "Custom", controls::AeExposureModeCustom }, > > + }; > > + > > const ValueNode &exposureModes = tuningData[controls::AeExposureMode.name()]; > > if (exposureModes.isDictionary()) { > > for (const auto &[modeName, modeValues] : exposureModes.asDict()) { > > + std::optional<controls::AeExposureModeEnum> modeValue; > > + > > auto it = AeExposureModeNameValueMap.find(modeName); > > if (it == AeExposureModeNameValueMap.end()) { > > + for (const auto &[oldName, newName, v] : compat) { > > + if (modeName != oldName) > > + continue; > > + > > + modeValue = v; > > + > > + LOG(AgcMeanLuminance, Warning) > > + << "Exposure mode '" << oldName << "' has been renamed to '" > > + << newName << "', please fix the tuning file"; > > + break; > > + } > > + } else { > > + modeValue = static_cast<controls::AeExposureModeEnum>(it->second); > > + } > > + > > + if (!modeValue) { > > LOG(AgcMeanLuminance, Warning) > > << "Skipping unknown exposure mode '" << modeName << "'"; > > continue; > > @@ -322,7 +372,7 @@ int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData) > > }); > > } > > > > - exposureModeHelpers_.try_emplace(it->second, stages); > > + exposureModeHelpers_.try_emplace(*modeValue, stages); > > } > > } > > > > diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp > > index cad2b5777f..3b95fecee8 100644 > > --- a/src/ipa/libipa/awb.cpp > > +++ b/src/ipa/libipa/awb.cpp > > @@ -451,9 +451,38 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, > > return -EINVAL; > > } > > > > + static constexpr std::tuple<std::string_view, std::string_view, controls::AwbModeEnum> compat[] = { > > + { "AwbAuto", "Auto", controls::AwbModeAuto }, > > + { "AwbIncandescent", "Incandescent", controls::AwbModeIncandescent }, > > + { "AwbTungsten", "Tungsten", controls::AwbModeTungsten }, > > + { "AwbFluorescent", "Fluorescent", controls::AwbModeFluorescent }, > > + { "AwbIndoor", "Indoor", controls::AwbModeIndoor }, > > + { "AwbDaylight", "Daylight", controls::AwbModeDaylight }, > > + { "AwbCloudy", "Cloudy", controls::AwbModeCloudy }, > > + { "AwbCustom", "Custom", controls::AwbModeCustom }, > > + }; > > + > > for (const auto &[modeName, modeDict] : modes.asDict()) { > > - if (controls::AwbModeNameValueMap.find(modeName) == > > - controls::AwbModeNameValueMap.end()) { > > + std::optional<controls::AwbModeEnum> modeValue; > > + > > + auto it = controls::AwbModeNameValueMap.find(modeName); > > + if (it == controls::AwbModeNameValueMap.end()) { > > + for (const auto &[oldName, newName, v] : compat) { > > + if (modeName != oldName) > > + continue; > > + > > + modeValue = v; > > + > > + LOG(Awb, Warning) > > + << "AWB mode '" << oldName << " has been renamed to '" > > + << newName << "', please fix the tuning file"; > > + break; > > + } > > + } else { > > + modeValue = static_cast<controls::AwbModeEnum>(it->second); > > + } > > + > > + if (!modeValue) { > > LOG(Awb, Warning) > > << "Skipping unknown AWB mode '" > > << modeName << "'"; > > @@ -466,10 +495,7 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, > > return -EINVAL; > > } > > > > - const auto &modeValue = static_cast<controls::AwbModeEnum>( > > - controls::AwbModeNameValueMap.at(modeName)); > > - > > - ModeConfig &config = modes_[modeValue]; > > + ModeConfig &config = modes_[*modeValue]; > > > > auto hi = modeDict["hi"].get<double>(); > > if (!hi) { > > @@ -487,7 +513,7 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, > > } > > config.ctLo = *lo; > > > > - availableModes.push_back(modeValue); > > + availableModes.push_back(*modeValue); > > } > > > > if (modes_.empty()) {
diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index 486c09c076..a39ea5e504 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -237,11 +237,36 @@ int AgcMeanLuminance::parseConstraint(const ValueNode &modeDict, int32_t id) int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) { + static constexpr std::tuple<std::string_view, std::string_view, controls::AeConstraintModeEnum> compat[] = { + { "ConstraintNormal", "Normal", controls::AeConstraintModeNormal }, + { "ConstraintHighlight", "Highlight", controls::AeConstraintModeHighlight }, + { "ConstraintShadows", "Shadows", controls::AeConstraintModeShadows }, + { "ConstraintCustom", "Custom", controls::AeConstraintModeCustom }, + }; + const ValueNode &constraintModes = tuningData[controls::AeConstraintMode.name()]; if (constraintModes.isDictionary()) { for (const auto &[modeName, modeDict] : constraintModes.asDict()) { + std::optional<controls::AeConstraintModeEnum> modeValue; + auto it = AeConstraintModeNameValueMap.find(modeName); if (it == AeConstraintModeNameValueMap.end()) { + for (const auto &[oldName, newName, v] : compat) { + if (modeName != oldName) + continue; + + modeValue = v; + + LOG(AgcMeanLuminance, Warning) + << "Constraint mode '" << oldName << "' has been renamed to '" + << newName << "', please fix the tuning file"; + break; + } + } else { + modeValue = static_cast<controls::AeConstraintModeEnum>(it->second); + } + + if (!modeValue) { LOG(AgcMeanLuminance, Warning) << "Skipping unknown constraint mode '" << modeName << "'"; continue; @@ -253,7 +278,7 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) return -EINVAL; } - int ret = parseConstraint(modeDict, it->second); + int ret = parseConstraint(modeDict, *modeValue); if (ret) return ret; } @@ -281,11 +306,36 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData) int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData) { + static constexpr std::tuple<std::string_view, std::string_view, controls::AeExposureModeEnum> compat[] = { + { "ExposureNormal", "Normal", controls::AeExposureModeNormal }, + { "ExposureShort", "Short", controls::AeExposureModeShort }, + { "ExposureLong", "Long", controls::AeExposureModeLong }, + { "ExposureCustom", "Custom", controls::AeExposureModeCustom }, + }; + const ValueNode &exposureModes = tuningData[controls::AeExposureMode.name()]; if (exposureModes.isDictionary()) { for (const auto &[modeName, modeValues] : exposureModes.asDict()) { + std::optional<controls::AeExposureModeEnum> modeValue; + auto it = AeExposureModeNameValueMap.find(modeName); if (it == AeExposureModeNameValueMap.end()) { + for (const auto &[oldName, newName, v] : compat) { + if (modeName != oldName) + continue; + + modeValue = v; + + LOG(AgcMeanLuminance, Warning) + << "Exposure mode '" << oldName << "' has been renamed to '" + << newName << "', please fix the tuning file"; + break; + } + } else { + modeValue = static_cast<controls::AeExposureModeEnum>(it->second); + } + + if (!modeValue) { LOG(AgcMeanLuminance, Warning) << "Skipping unknown exposure mode '" << modeName << "'"; continue; @@ -322,7 +372,7 @@ int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData) }); } - exposureModeHelpers_.try_emplace(it->second, stages); + exposureModeHelpers_.try_emplace(*modeValue, stages); } } diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp index cad2b5777f..3b95fecee8 100644 --- a/src/ipa/libipa/awb.cpp +++ b/src/ipa/libipa/awb.cpp @@ -451,9 +451,38 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, return -EINVAL; } + static constexpr std::tuple<std::string_view, std::string_view, controls::AwbModeEnum> compat[] = { + { "AwbAuto", "Auto", controls::AwbModeAuto }, + { "AwbIncandescent", "Incandescent", controls::AwbModeIncandescent }, + { "AwbTungsten", "Tungsten", controls::AwbModeTungsten }, + { "AwbFluorescent", "Fluorescent", controls::AwbModeFluorescent }, + { "AwbIndoor", "Indoor", controls::AwbModeIndoor }, + { "AwbDaylight", "Daylight", controls::AwbModeDaylight }, + { "AwbCloudy", "Cloudy", controls::AwbModeCloudy }, + { "AwbCustom", "Custom", controls::AwbModeCustom }, + }; + for (const auto &[modeName, modeDict] : modes.asDict()) { - if (controls::AwbModeNameValueMap.find(modeName) == - controls::AwbModeNameValueMap.end()) { + std::optional<controls::AwbModeEnum> modeValue; + + auto it = controls::AwbModeNameValueMap.find(modeName); + if (it == controls::AwbModeNameValueMap.end()) { + for (const auto &[oldName, newName, v] : compat) { + if (modeName != oldName) + continue; + + modeValue = v; + + LOG(Awb, Warning) + << "AWB mode '" << oldName << " has been renamed to '" + << newName << "', please fix the tuning file"; + break; + } + } else { + modeValue = static_cast<controls::AwbModeEnum>(it->second); + } + + if (!modeValue) { LOG(Awb, Warning) << "Skipping unknown AWB mode '" << modeName << "'"; @@ -466,10 +495,7 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, return -EINVAL; } - const auto &modeValue = static_cast<controls::AwbModeEnum>( - controls::AwbModeNameValueMap.at(modeName)); - - ModeConfig &config = modes_[modeValue]; + ModeConfig &config = modes_[*modeValue]; auto hi = modeDict["hi"].get<double>(); if (!hi) { @@ -487,7 +513,7 @@ int AwbAlgorithmBase::parseModeConfigs(const ValueNode &tuningData, } config.ctLo = *lo; - availableModes.push_back(modeValue); + availableModes.push_back(*modeValue); } if (modes_.empty()) {
It is somewhat unfortunate that the parsing logic uses the enum names directly, and does not have separate key -> value mapping like the rpi ipa has. Commit 974102049a41 ("libcamera: controls: Remove common enum prefix") has changed some enum names, crucially some of those have been used in tuning files. To make the the transition, add support for using the old names and warn about the new names. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- Another approach in addition to https://patchwork.libcamera.org/project/libcamera/list/?series=6318, this is more code, but keeps the old files working. (Apart from the virtual pipeline handler config file.) Similarly, only compile tested. --- src/ipa/libipa/agc_mean_luminance.cpp | 54 ++++++++++++++++++++++++++- src/ipa/libipa/awb.cpp | 40 ++++++++++++++++---- 2 files changed, 85 insertions(+), 9 deletions(-) -- 2.56.0