From f357b1bf6ea39d8118e90f8a371974d29bd054e3 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 26 Jul 2022 02:36:38 +0300 Subject: ipa: raspberrypi: Return an error code from Algorithm::read() When encountering errors, the Algorithm::read() function either uses LOG(Fatal) or throws exceptions from the boost property_tree functions. To prepare for replacing boost JSON parse with the YamlParser class, give the Algorithm::read() function the ability to return an error code, and propagate it all the way to the IPA module init() function. All algorithm classes return a hardcoded 0 value for now, subsequent commits will change that. Signed-off-by: Laurent Pinchart Reviewed-by: Naushir Patuck Tested-by: Naushir Patuck --- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 38 ++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 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 03ae3350..b3627769 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -50,7 +50,7 @@ char const *Alsc::name() const return NAME; } -static void generateLut(double *lut, boost::property_tree::ptree const ¶ms) +static int generateLut(double *lut, boost::property_tree::ptree const ¶ms) { double cstrength = params.get("corner_strength", 2.0); if (cstrength <= 1.0) @@ -71,9 +71,10 @@ static void generateLut(double *lut, boost::property_tree::ptree const ¶ms) (f2 * f2); /* this reproduces the cos^4 rule */ } } + return 0; } -static void readLut(double *lut, boost::property_tree::ptree const ¶ms) +static int readLut(double *lut, boost::property_tree::ptree const ¶ms) { int num = 0; const int maxNum = XY; @@ -84,11 +85,12 @@ static void readLut(double *lut, boost::property_tree::ptree const ¶ms) } if (num < maxNum) LOG(RPiAlsc, Fatal) << "Alsc: too few entries in LSC table"; + return 0; } -static void readCalibrations(std::vector &calibrations, - boost::property_tree::ptree const ¶ms, - std::string const &name) +static int readCalibrations(std::vector &calibrations, + boost::property_tree::ptree const ¶ms, + std::string const &name) { if (params.get_child_optional(name)) { double lastCt = 0; @@ -117,9 +119,10 @@ static void readCalibrations(std::vector &calibrations, << "Read " << name << " calibration for ct " << ct; } } + return 0; } -void Alsc::read(boost::property_tree::ptree const ¶ms) +int Alsc::read(boost::property_tree::ptree const ¶ms) { config_.framePeriod = params.get("frame_period", 12); config_.startupFrames = params.get("startup_frames", 10); @@ -135,19 +138,32 @@ void Alsc::read(boost::property_tree::ptree const ¶ms) params.get("luminance_strength", 1.0); for (int i = 0; i < XY; i++) config_.luminanceLut[i] = 1.0; + + int ret = 0; + if (params.get_child_optional("corner_strength")) - generateLut(config_.luminanceLut, params); + ret = generateLut(config_.luminanceLut, params); else if (params.get_child_optional("luminance_lut")) - readLut(config_.luminanceLut, - params.get_child("luminance_lut")); + ret = readLut(config_.luminanceLut, + params.get_child("luminance_lut")); else LOG(RPiAlsc, Warning) << "no luminance table - assume unity everywhere"; - readCalibrations(config_.calibrationsCr, params, "calibrations_Cr"); - readCalibrations(config_.calibrationsCb, params, "calibrations_Cb"); + if (ret) + return ret; + + ret = readCalibrations(config_.calibrationsCr, params, "calibrations_Cr"); + if (ret) + return ret; + ret = readCalibrations(config_.calibrationsCb, params, "calibrations_Cb"); + 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); + + return 0; } static double getCt(Metadata *metadata, double defaultCt); -- cgit v1.2.1