From c1597f989654618f782012104f547b367082fa3e Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 18 Jul 2022 09:15:58 +0100 Subject: ipa: raspberrypi: Use YamlParser to replace dependency on boost The Raspberry Pi IPA module depends on boost only to parse the JSON tuning data files. As libcamera depends on libyaml, use the YamlParser class to parse those files and drop the dependency on boost. Signed-off-by: Laurent Pinchart Tested-by: Naushir Patuck Reviewed-by: Naushir Patuck --- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 105 ++++++++++++++-------------- 1 file changed, 53 insertions(+), 52 deletions(-) (limited to 'src/ipa/raspberrypi/controller/rpi/alsc.cpp') diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index 49aaf6b7..a4afaf84 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -5,6 +5,7 @@ * alsc.cpp - ALSC (auto lens shading correction) control algorithm */ +#include #include #include @@ -50,15 +51,15 @@ char const *Alsc::name() const return NAME; } -static int generateLut(double *lut, boost::property_tree::ptree const ¶ms) +static int generateLut(double *lut, const libcamera::YamlObject ¶ms) { - double cstrength = params.get("corner_strength", 2.0); + double cstrength = params["corner_strength"].get(2.0); if (cstrength <= 1.0) { LOG(RPiAlsc, Error) << "corner_strength must be > 1.0"; return -EINVAL; } - double asymmetry = params.get("asymmetry", 1.0); + double asymmetry = params["asymmetry"].get(1.0); if (asymmetry < 0) { LOG(RPiAlsc, Error) << "asymmetry must be >= 0"; return -EINVAL; @@ -80,34 +81,35 @@ static int generateLut(double *lut, boost::property_tree::ptree const ¶ms) return 0; } -static int readLut(double *lut, boost::property_tree::ptree const ¶ms) +static int readLut(double *lut, const libcamera::YamlObject ¶ms) { - int num = 0; - const int maxNum = XY; + if (params.size() != XY) { + LOG(RPiAlsc, Error) << "Invalid number of entries in LSC table"; + return -EINVAL; + } - for (auto &p : params) { - if (num == maxNum) { - LOG(RPiAlsc, Error) << "Too many entries in LSC table"; + int num = 0; + for (const auto &p : params.asList()) { + auto value = p.get(); + if (!value) return -EINVAL; - } - lut[num++] = p.second.get_value(); + lut[num++] = *value; } - if (num < maxNum) { - LOG(RPiAlsc, Error) << "Too few entries in LSC table"; - return -EINVAL; - } return 0; } static int readCalibrations(std::vector &calibrations, - boost::property_tree::ptree const ¶ms, + const libcamera::YamlObject ¶ms, std::string const &name) { - if (params.get_child_optional(name)) { + if (params.contains(name)) { double lastCt = 0; - for (auto &p : params.get_child(name)) { - double ct = p.second.get("ct"); + for (const auto &p : params[name].asList()) { + auto value = p["ct"].get(); + if (!value) + return -EINVAL; + double ct = *value; if (ct <= lastCt) { LOG(RPiAlsc, Error) << "Entries in " << name << " must be in increasing ct order"; @@ -115,23 +117,23 @@ static int readCalibrations(std::vector &calibrations, } AlscCalibration calibration; calibration.ct = lastCt = ct; - boost::property_tree::ptree const &table = - p.second.get_child("table"); - int num = 0; - for (auto it = table.begin(); it != table.end(); it++) { - if (num == XY) { - LOG(RPiAlsc, Error) - << "Too many values for ct " << ct << " in " << name; - return -EINVAL; - } - calibration.table[num++] = - it->second.get_value(); - } - if (num != XY) { + + const libcamera::YamlObject &table = p["table"]; + if (table.size() != XY) { LOG(RPiAlsc, Error) - << "Too few values for ct " << ct << " in " << name; + << "Incorrect number of values for ct " + << ct << " in " << name; return -EINVAL; } + + int num = 0; + for (const auto &elem : table.asList()) { + value = elem.get(); + if (!value) + return -EINVAL; + calibration.table[num++] = *value; + } + calibrations.push_back(calibration); LOG(RPiAlsc, Debug) << "Read " << name << " calibration for ct " << ct; @@ -140,30 +142,29 @@ static int readCalibrations(std::vector &calibrations, return 0; } -int Alsc::read(boost::property_tree::ptree const ¶ms) +int Alsc::read(const libcamera::YamlObject ¶ms) { - config_.framePeriod = params.get("frame_period", 12); - config_.startupFrames = params.get("startup_frames", 10); - config_.speed = params.get("speed", 0.05); - double sigma = params.get("sigma", 0.01); - config_.sigmaCr = params.get("sigma_Cr", sigma); - config_.sigmaCb = params.get("sigma_Cb", sigma); - config_.minCount = params.get("min_count", 10.0); - config_.minG = params.get("min_G", 50); - config_.omega = params.get("omega", 1.3); - config_.nIter = params.get("n_iter", X + Y); + config_.framePeriod = params["frame_period"].get(12); + config_.startupFrames = params["startup_frames"].get(10); + config_.speed = params["speed"].get(0.05); + double sigma = params["sigma"].get(0.01); + config_.sigmaCr = params["sigma_Cr"].get(sigma); + config_.sigmaCb = params["sigma_Cb"].get(sigma); + config_.minCount = params["min_count"].get(10.0); + config_.minG = params["min_G"].get(50); + config_.omega = params["omega"].get(1.3); + config_.nIter = params["n_iter"].get(X + Y); config_.luminanceStrength = - params.get("luminance_strength", 1.0); + params["luminance_strength"].get(1.0); for (int i = 0; i < XY; i++) config_.luminanceLut[i] = 1.0; int ret = 0; - if (params.get_child_optional("corner_strength")) + if (params.contains("corner_strength")) ret = generateLut(config_.luminanceLut, params); - else if (params.get_child_optional("luminance_lut")) - ret = readLut(config_.luminanceLut, - params.get_child("luminance_lut")); + else if (params.contains("luminance_lut")) + ret = readLut(config_.luminanceLut, params["luminance_lut"]); else LOG(RPiAlsc, Warning) << "no luminance table - assume unity everywhere"; @@ -177,9 +178,9 @@ int Alsc::read(boost::property_tree::ptree const ¶ms) if (ret) return ret; - config_.defaultCt = params.get("default_ct", 4500.0); - config_.threshold = params.get("threshold", 1e-3); - config_.lambdaBound = params.get("lambda_bound", 0.05); + config_.defaultCt = params["default_ct"].get(4500.0); + config_.threshold = params["threshold"].get(1e-3); + config_.lambdaBound = params["lambda_bound"].get(0.05); return 0; } -- cgit v1.2.1