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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Naushir Patuck <naush@raspberrypi.com> Tested-by: Naushir Patuck <naush@raspberrypi.com>
This commit is contained in:
parent
0c84c67e39
commit
f357b1bf6e
31 changed files with 151 additions and 75 deletions
|
@ -9,8 +9,9 @@
|
|||
|
||||
using namespace RPiController;
|
||||
|
||||
void Algorithm::read([[maybe_unused]] boost::property_tree::ptree const ¶ms)
|
||||
int Algorithm::read([[maybe_unused]] boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Algorithm::initialise()
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
virtual bool isPaused() const { return paused_; }
|
||||
virtual void pause() { paused_ = true; }
|
||||
virtual void resume() { paused_ = false; }
|
||||
virtual void read(boost::property_tree::ptree const ¶ms);
|
||||
virtual int read(boost::property_tree::ptree const ¶ms);
|
||||
virtual void initialise();
|
||||
virtual void switchMode(CameraMode const &cameraMode, Metadata *metadata);
|
||||
virtual void prepare(Metadata *imageMetadata);
|
||||
|
|
|
@ -32,19 +32,23 @@ Controller::Controller(char const *jsonFilename)
|
|||
|
||||
Controller::~Controller() {}
|
||||
|
||||
void Controller::read(char const *filename)
|
||||
int Controller::read(char const *filename)
|
||||
{
|
||||
boost::property_tree::ptree root;
|
||||
boost::property_tree::read_json(filename, root);
|
||||
for (auto const &keyAndValue : root) {
|
||||
Algorithm *algo = createAlgorithm(keyAndValue.first.c_str());
|
||||
if (algo) {
|
||||
algo->read(keyAndValue.second);
|
||||
int ret = algo->read(keyAndValue.second);
|
||||
if (ret)
|
||||
return ret;
|
||||
algorithms_.push_back(AlgorithmPtr(algo));
|
||||
} else
|
||||
LOG(RPiController, Warning)
|
||||
<< "No algorithm found for \"" << keyAndValue.first << "\"";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Algorithm *Controller::createAlgorithm(char const *name)
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
Controller(char const *jsonFilename);
|
||||
~Controller();
|
||||
Algorithm *createAlgorithm(char const *name);
|
||||
void read(char const *filename);
|
||||
int read(char const *filename);
|
||||
void initialise();
|
||||
void switchMode(CameraMode const &cameraMode, Metadata *metadata);
|
||||
void prepare(Metadata *imageMetadata);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
using namespace RPiController;
|
||||
|
||||
void Pwl::read(boost::property_tree::ptree const ¶ms)
|
||||
int Pwl::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
for (auto it = params.begin(); it != params.end(); it++) {
|
||||
double x = it->second.get_value<double>();
|
||||
|
@ -22,6 +22,7 @@ void Pwl::read(boost::property_tree::ptree const ¶ms)
|
|||
points_.push_back(Point(x, y));
|
||||
}
|
||||
assert(points_.size() >= 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Pwl::append(double x, double y, const double eps)
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
};
|
||||
Pwl() {}
|
||||
Pwl(std::vector<Point> const &points) : points_(points) {}
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
void append(double x, double y, const double eps = 1e-6);
|
||||
void prepend(double x, double y, const double eps = 1e-6);
|
||||
Interval domain() const;
|
||||
|
|
|
@ -30,7 +30,7 @@ LOG_DEFINE_CATEGORY(RPiAgc)
|
|||
|
||||
static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */
|
||||
|
||||
void AgcMeteringMode::read(boost::property_tree::ptree const ¶ms)
|
||||
int AgcMeteringMode::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
int num = 0;
|
||||
for (auto &p : params.get_child("weights")) {
|
||||
|
@ -40,6 +40,7 @@ void AgcMeteringMode::read(boost::property_tree::ptree const ¶ms)
|
|||
}
|
||||
if (num != AgcStatsSize)
|
||||
LOG(RPiAgc, Fatal) << "AgcMeteringMode: insufficient weights";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::string
|
||||
|
@ -73,7 +74,7 @@ static int readList(std::vector<Duration> &list,
|
|||
return list.size();
|
||||
}
|
||||
|
||||
void AgcExposureMode::read(boost::property_tree::ptree const ¶ms)
|
||||
int AgcExposureMode::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
int numShutters = readList(shutter, params.get_child("shutter"));
|
||||
int numAgs = readList(gain, params.get_child("gain"));
|
||||
|
@ -83,6 +84,7 @@ void AgcExposureMode::read(boost::property_tree::ptree const ¶ms)
|
|||
if (numShutters != numAgs)
|
||||
LOG(RPiAgc, Fatal)
|
||||
<< "AgcExposureMode: expect same number of exposure and gain entries in exposure profile";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::string
|
||||
|
@ -100,7 +102,7 @@ readExposureModes(std::map<std::string, AgcExposureMode> &exposureModes,
|
|||
return first;
|
||||
}
|
||||
|
||||
void AgcConstraint::read(boost::property_tree::ptree const ¶ms)
|
||||
int AgcConstraint::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
std::string boundString = params.get<std::string>("bound", "");
|
||||
transform(boundString.begin(), boundString.end(),
|
||||
|
@ -110,7 +112,7 @@ void AgcConstraint::read(boost::property_tree::ptree const ¶ms)
|
|||
bound = boundString == "UPPER" ? Bound::UPPER : Bound::LOWER;
|
||||
qLo = params.get<double>("q_lo");
|
||||
qHi = params.get<double>("q_hi");
|
||||
yTarget.read(params.get_child("y_target"));
|
||||
return yTarget.read(params.get_child("y_target"));
|
||||
}
|
||||
|
||||
static AgcConstraintMode
|
||||
|
@ -137,13 +139,17 @@ static std::string readConstraintModes(std::map<std::string, AgcConstraintMode>
|
|||
return first;
|
||||
}
|
||||
|
||||
void AgcConfig::read(boost::property_tree::ptree const ¶ms)
|
||||
int AgcConfig::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
LOG(RPiAgc, Debug) << "AgcConfig";
|
||||
defaultMeteringMode = readMeteringModes(meteringModes, params.get_child("metering_modes"));
|
||||
defaultExposureMode = readExposureModes(exposureModes, params.get_child("exposure_modes"));
|
||||
defaultConstraintMode = readConstraintModes(constraintModes, params.get_child("constraint_modes"));
|
||||
yTarget.read(params.get_child("y_target"));
|
||||
|
||||
int ret = yTarget.read(params.get_child("y_target"));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
speed = params.get<double>("speed", 0.2);
|
||||
startupFrames = params.get<uint16_t>("startup_frames", 10);
|
||||
convergenceFrames = params.get<unsigned int>("convergence_frames", 6);
|
||||
|
@ -152,6 +158,7 @@ void AgcConfig::read(boost::property_tree::ptree const ¶ms)
|
|||
/* Start with quite a low value as ramping up is easier than ramping down. */
|
||||
defaultExposureTime = params.get<double>("default_exposure_time", 1000) * 1us;
|
||||
defaultAnalogueGain = params.get<double>("default_analogueGain", 1.0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Agc::ExposureValues::ExposureValues()
|
||||
|
@ -182,10 +189,14 @@ char const *Agc::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void Agc::read(boost::property_tree::ptree const ¶ms)
|
||||
int Agc::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
LOG(RPiAgc, Debug) << "Agc";
|
||||
config_.read(params);
|
||||
|
||||
int ret = config_.read(params);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* Set the config's defaults (which are the first ones it read) as our
|
||||
* current modes, until someone changes them. (they're all known to
|
||||
|
@ -200,6 +211,7 @@ void Agc::read(boost::property_tree::ptree const ¶ms)
|
|||
/* Set up the "last shutter/gain" values, in case AGC starts "disabled". */
|
||||
status_.shutterTime = config_.defaultExposureTime;
|
||||
status_.analogueGain = config_.defaultAnalogueGain;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Agc::isPaused() const
|
||||
|
|
|
@ -28,13 +28,13 @@ namespace RPiController {
|
|||
|
||||
struct AgcMeteringMode {
|
||||
double weights[AgcStatsSize];
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
};
|
||||
|
||||
struct AgcExposureMode {
|
||||
std::vector<libcamera::utils::Duration> shutter;
|
||||
std::vector<double> gain;
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
};
|
||||
|
||||
struct AgcConstraint {
|
||||
|
@ -43,13 +43,13 @@ struct AgcConstraint {
|
|||
double qLo;
|
||||
double qHi;
|
||||
Pwl yTarget;
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
};
|
||||
|
||||
typedef std::vector<AgcConstraint> AgcConstraintMode;
|
||||
|
||||
struct AgcConfig {
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
std::map<std::string, AgcMeteringMode> meteringModes;
|
||||
std::map<std::string, AgcExposureMode> exposureModes;
|
||||
std::map<std::string, AgcConstraintMode> constraintModes;
|
||||
|
@ -74,7 +74,7 @@ class Agc : public AgcAlgorithm
|
|||
public:
|
||||
Agc(Controller *controller);
|
||||
char const *name() const override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
/* AGC handles "pausing" for itself. */
|
||||
bool isPaused() const override;
|
||||
void pause() override;
|
||||
|
|
|
@ -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<double>("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,9 +85,10 @@ 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<AlscCalibration> &calibrations,
|
||||
static int readCalibrations(std::vector<AlscCalibration> &calibrations,
|
||||
boost::property_tree::ptree const ¶ms,
|
||||
std::string const &name)
|
||||
{
|
||||
|
@ -117,9 +119,10 @@ static void readCalibrations(std::vector<AlscCalibration> &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<uint16_t>("frame_period", 12);
|
||||
config_.startupFrames = params.get<uint16_t>("startup_frames", 10);
|
||||
|
@ -135,19 +138,32 @@ void Alsc::read(boost::property_tree::ptree const ¶ms)
|
|||
params.get<double>("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,
|
||||
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<double>("default_ct", 4500.0);
|
||||
config_.threshold = params.get<double>("threshold", 1e-3);
|
||||
config_.lambdaBound = params.get<double>("lambda_bound", 0.05);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double getCt(Metadata *metadata, double defaultCt);
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
char const *name() const override;
|
||||
void initialise() override;
|
||||
void switchMode(CameraMode const &cameraMode, Metadata *metadata) override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
void process(StatisticsPtr &stats, Metadata *imageMetadata) override;
|
||||
|
||||
|
|
|
@ -26,19 +26,20 @@ static constexpr unsigned int AwbStatsSizeY = DEFAULT_AWB_REGIONS_Y;
|
|||
* elsewhere (ALSC and AGC).
|
||||
*/
|
||||
|
||||
void AwbMode::read(boost::property_tree::ptree const ¶ms)
|
||||
int AwbMode::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
ctLo = params.get<double>("lo");
|
||||
ctHi = params.get<double>("hi");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AwbPrior::read(boost::property_tree::ptree const ¶ms)
|
||||
int AwbPrior::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
lux = params.get<double>("lux");
|
||||
prior.read(params.get_child("prior"));
|
||||
return prior.read(params.get_child("prior"));
|
||||
}
|
||||
|
||||
static void readCtCurve(Pwl &ctR, Pwl &ctB,
|
||||
static int readCtCurve(Pwl &ctR, Pwl &ctB,
|
||||
boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
int num = 0;
|
||||
|
@ -55,21 +56,28 @@ static void readCtCurve(Pwl &ctR, Pwl &ctB,
|
|||
}
|
||||
if (num < 2)
|
||||
LOG(RPiAwb, Fatal) << "AwbConfig: insufficient points in CT curve";
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AwbConfig::read(boost::property_tree::ptree const ¶ms)
|
||||
int AwbConfig::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
int ret;
|
||||
bayes = params.get<int>("bayes", 1);
|
||||
framePeriod = params.get<uint16_t>("framePeriod", 10);
|
||||
startupFrames = params.get<uint16_t>("startupFrames", 10);
|
||||
convergenceFrames = params.get<unsigned int>("convergence_frames", 3);
|
||||
speed = params.get<double>("speed", 0.05);
|
||||
if (params.get_child_optional("ct_curve"))
|
||||
readCtCurve(ctR, ctB, params.get_child("ct_curve"));
|
||||
if (params.get_child_optional("ct_curve")) {
|
||||
ret = readCtCurve(ctR, ctB, params.get_child("ct_curve"));
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
if (params.get_child_optional("priors")) {
|
||||
for (auto &p : params.get_child("priors")) {
|
||||
AwbPrior prior;
|
||||
prior.read(p.second);
|
||||
ret = prior.read(p.second);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (!priors.empty() && prior.lux <= priors.back().lux)
|
||||
LOG(RPiAwb, Fatal) << "AwbConfig: Prior must be ordered in increasing lux value";
|
||||
priors.push_back(prior);
|
||||
|
@ -79,7 +87,9 @@ void AwbConfig::read(boost::property_tree::ptree const ¶ms)
|
|||
}
|
||||
if (params.get_child_optional("modes")) {
|
||||
for (auto &p : params.get_child("modes")) {
|
||||
modes[p.first].read(p.second);
|
||||
ret = modes[p.first].read(p.second);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (defaultMode == nullptr)
|
||||
defaultMode = &modes[p.first];
|
||||
}
|
||||
|
@ -110,6 +120,7 @@ void AwbConfig::read(boost::property_tree::ptree const ¶ms)
|
|||
whitepointB = params.get<double>("whitepoint_b", 0.0);
|
||||
if (bayes == false)
|
||||
sensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */
|
||||
return 0;
|
||||
}
|
||||
|
||||
Awb::Awb(Controller *controller)
|
||||
|
@ -137,9 +148,9 @@ char const *Awb::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void Awb::read(boost::property_tree::ptree const ¶ms)
|
||||
int Awb::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
config_.read(params);
|
||||
return config_.read(params);
|
||||
}
|
||||
|
||||
void Awb::initialise()
|
||||
|
|
|
@ -19,20 +19,20 @@ namespace RPiController {
|
|||
/* Control algorithm to perform AWB calculations. */
|
||||
|
||||
struct AwbMode {
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
double ctLo; /* low CT value for search */
|
||||
double ctHi; /* high CT value for search */
|
||||
};
|
||||
|
||||
struct AwbPrior {
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
double lux; /* lux level */
|
||||
Pwl prior; /* maps CT to prior log likelihood for this lux level */
|
||||
};
|
||||
|
||||
struct AwbConfig {
|
||||
AwbConfig() : defaultMode(nullptr) {}
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
/* Only repeat the AWB calculation every "this many" frames */
|
||||
uint16_t framePeriod;
|
||||
/* number of initial frames for which speed taken as 1.0 (maximum) */
|
||||
|
@ -90,7 +90,7 @@ public:
|
|||
~Awb();
|
||||
char const *name() const override;
|
||||
void initialise() override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
/* AWB handles "pausing" for itself. */
|
||||
bool isPaused() const override;
|
||||
void pause() override;
|
||||
|
|
|
@ -31,7 +31,7 @@ char const *BlackLevel::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void BlackLevel::read(boost::property_tree::ptree const ¶ms)
|
||||
int BlackLevel::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
uint16_t blackLevel = params.get<uint16_t>(
|
||||
"black_level", 4096); /* 64 in 10 bits scaled to 16 bits */
|
||||
|
@ -42,6 +42,7 @@ void BlackLevel::read(boost::property_tree::ptree const ¶ms)
|
|||
<< " Read black levels red " << blackLevelR_
|
||||
<< " green " << blackLevelG_
|
||||
<< " blue " << blackLevelB_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BlackLevel::prepare(Metadata *imageMetadata)
|
||||
|
|
|
@ -18,7 +18,7 @@ class BlackLevel : public Algorithm
|
|||
public:
|
||||
BlackLevel(Controller *controller);
|
||||
char const *name() const override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -39,7 +39,7 @@ Matrix::Matrix(double m0, double m1, double m2, double m3, double m4, double m5,
|
|||
m[0][0] = m0, m[0][1] = m1, m[0][2] = m2, m[1][0] = m3, m[1][1] = m4,
|
||||
m[1][2] = m5, m[2][0] = m6, m[2][1] = m7, m[2][2] = m8;
|
||||
}
|
||||
void Matrix::read(boost::property_tree::ptree const ¶ms)
|
||||
int Matrix::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
double *ptr = (double *)m;
|
||||
int n = 0;
|
||||
|
@ -50,6 +50,7 @@ void Matrix::read(boost::property_tree::ptree const ¶ms)
|
|||
}
|
||||
if (n < 9)
|
||||
LOG(RPiCcm, Fatal) << "Ccm: too few values in CCM";
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ccm::Ccm(Controller *controller)
|
||||
|
@ -60,21 +61,32 @@ char const *Ccm::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void Ccm::read(boost::property_tree::ptree const ¶ms)
|
||||
int Ccm::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
if (params.get_child_optional("saturation"))
|
||||
config_.saturation.read(params.get_child("saturation"));
|
||||
int ret;
|
||||
|
||||
if (params.get_child_optional("saturation")) {
|
||||
ret = config_.saturation.read(params.get_child("saturation"));
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (auto &p : params.get_child("ccms")) {
|
||||
CtCcm ctCcm;
|
||||
ctCcm.ct = p.second.get<double>("ct");
|
||||
ctCcm.ccm.read(p.second.get_child("ccm"));
|
||||
ret = ctCcm.ccm.read(p.second.get_child("ccm"));
|
||||
if (ret)
|
||||
return ret;
|
||||
if (!config_.ccms.empty() &&
|
||||
ctCcm.ct <= config_.ccms.back().ct)
|
||||
LOG(RPiCcm, Fatal) << "Ccm: CCM not in increasing colour temperature order";
|
||||
config_.ccms.push_back(std::move(ctCcm));
|
||||
}
|
||||
|
||||
if (config_.ccms.empty())
|
||||
LOG(RPiCcm, Fatal) << "Ccm: no CCMs specified";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Ccm::setSaturation(double saturation)
|
||||
|
|
|
@ -20,7 +20,7 @@ struct Matrix {
|
|||
double m6, double m7, double m8);
|
||||
Matrix();
|
||||
double m[3][3];
|
||||
void read(boost::property_tree::ptree const ¶ms);
|
||||
int read(boost::property_tree::ptree const ¶ms);
|
||||
};
|
||||
static inline Matrix operator*(double d, Matrix const &m)
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ class Ccm : public CcmAlgorithm
|
|||
public:
|
||||
Ccm(Controller *controller = NULL);
|
||||
char const *name() const override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void setSaturation(double saturation) override;
|
||||
void initialise() override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
|
|
|
@ -38,7 +38,7 @@ char const *Contrast::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void Contrast::read(boost::property_tree::ptree const ¶ms)
|
||||
int Contrast::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
/* enable adaptive enhancement by default */
|
||||
config_.ceEnable = params.get<int>("ce_enable", 1);
|
||||
|
@ -52,7 +52,7 @@ void Contrast::read(boost::property_tree::ptree const ¶ms)
|
|||
config_.hiHistogram = params.get<double>("hi_histogram", 0.95);
|
||||
config_.hiLevel = params.get<double>("hi_level", 0.95);
|
||||
config_.hiMax = params.get<double>("hi_max", 2000);
|
||||
config_.gammaCurve.read(params.get_child("gamma_curve"));
|
||||
return config_.gammaCurve.read(params.get_child("gamma_curve"));
|
||||
}
|
||||
|
||||
void Contrast::setBrightness(double brightness)
|
||||
|
|
|
@ -34,7 +34,7 @@ class Contrast : public ContrastAlgorithm
|
|||
public:
|
||||
Contrast(Controller *controller = NULL);
|
||||
char const *name() const override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void setBrightness(double brightness) override;
|
||||
void setContrast(double contrast) override;
|
||||
void initialise() override;
|
||||
|
|
|
@ -31,11 +31,12 @@ char const *Dpc::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void Dpc::read(boost::property_tree::ptree const ¶ms)
|
||||
int Dpc::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
config_.strength = params.get<int>("strength", 1);
|
||||
if (config_.strength < 0 || config_.strength > 2)
|
||||
LOG(RPiDpc, Fatal) << "Dpc: bad strength value";
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Dpc::prepare(Metadata *imageMetadata)
|
||||
|
|
|
@ -22,7 +22,7 @@ class Dpc : public Algorithm
|
|||
public:
|
||||
Dpc(Controller *controller);
|
||||
char const *name() const override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -35,14 +35,20 @@ char const *Geq::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void Geq::read(boost::property_tree::ptree const ¶ms)
|
||||
int Geq::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
config_.offset = params.get<uint16_t>("offset", 0);
|
||||
config_.slope = params.get<double>("slope", 0.0);
|
||||
if (config_.slope < 0.0 || config_.slope >= 1.0)
|
||||
LOG(RPiGeq, Fatal) << "Geq: bad slope value";
|
||||
if (params.get_child_optional("strength"))
|
||||
config_.strength.read(params.get_child("strength"));
|
||||
|
||||
if (params.get_child_optional("strength")) {
|
||||
int ret = config_.strength.read(params.get_child("strength"));
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Geq::prepare(Metadata *imageMetadata)
|
||||
|
|
|
@ -24,7 +24,7 @@ class Geq : public Algorithm
|
|||
public:
|
||||
Geq(Controller *controller);
|
||||
char const *name() const override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -38,7 +38,7 @@ char const *Lux::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void Lux::read(boost::property_tree::ptree const ¶ms)
|
||||
int Lux::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
referenceShutterSpeed_ =
|
||||
params.get<double>("reference_shutter_speed") * 1.0us;
|
||||
|
@ -47,6 +47,7 @@ void Lux::read(boost::property_tree::ptree const ¶ms)
|
|||
referenceY_ = params.get<double>("reference_Y");
|
||||
referenceLux_ = params.get<double>("reference_lux");
|
||||
currentAperture_ = referenceAperture_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Lux::setCurrentAperture(double aperture)
|
||||
|
|
|
@ -22,7 +22,7 @@ class Lux : public Algorithm
|
|||
public:
|
||||
Lux(Controller *controller);
|
||||
char const *name() const override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
void process(StatisticsPtr &stats, Metadata *imageMetadata) override;
|
||||
void setCurrentAperture(double aperture);
|
||||
|
|
|
@ -41,10 +41,11 @@ void Noise::switchMode(CameraMode const &cameraMode,
|
|||
modeFactor_ = std::max(1.0, cameraMode.noiseFactor);
|
||||
}
|
||||
|
||||
void Noise::read(boost::property_tree::ptree const ¶ms)
|
||||
int Noise::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
referenceConstant_ = params.get<double>("reference_constant");
|
||||
referenceSlope_ = params.get<double>("reference_slope");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Noise::prepare(Metadata *imageMetadata)
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
Noise(Controller *controller);
|
||||
char const *name() const override;
|
||||
void switchMode(CameraMode const &cameraMode, Metadata *metadata) override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -34,10 +34,11 @@ char const *Sdn::name() const
|
|||
return NAME;
|
||||
}
|
||||
|
||||
void Sdn::read(boost::property_tree::ptree const ¶ms)
|
||||
int Sdn::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
deviation_ = params.get<double>("deviation", 3.2);
|
||||
strength_ = params.get<double>("strength", 0.75);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sdn::initialise()
|
||||
|
|
|
@ -18,7 +18,7 @@ class Sdn : public DenoiseAlgorithm
|
|||
public:
|
||||
Sdn(Controller *controller = NULL);
|
||||
char const *name() const override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void initialise() override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
void setMode(DenoiseMode mode) override;
|
||||
|
|
|
@ -37,7 +37,7 @@ void Sharpen::switchMode(CameraMode const &cameraMode,
|
|||
modeFactor_ = std::max(1.0, cameraMode.noiseFactor);
|
||||
}
|
||||
|
||||
void Sharpen::read(boost::property_tree::ptree const ¶ms)
|
||||
int Sharpen::read(boost::property_tree::ptree const ¶ms)
|
||||
{
|
||||
threshold_ = params.get<double>("threshold", 1.0);
|
||||
strength_ = params.get<double>("strength", 1.0);
|
||||
|
@ -46,6 +46,7 @@ void Sharpen::read(boost::property_tree::ptree const ¶ms)
|
|||
<< "Read threshold " << threshold_
|
||||
<< " strength " << strength_
|
||||
<< " limit " << limit_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sharpen::setStrength(double strength)
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
Sharpen(Controller *controller);
|
||||
char const *name() const override;
|
||||
void switchMode(CameraMode const &cameraMode, Metadata *metadata) override;
|
||||
void read(boost::property_tree::ptree const ¶ms) override;
|
||||
int read(boost::property_tree::ptree const ¶ms) override;
|
||||
void setStrength(double strength) override;
|
||||
void prepare(Metadata *imageMetadata) override;
|
||||
|
||||
|
|
|
@ -229,7 +229,14 @@ int IPARPi::init(const IPASettings &settings, IPAInitResult *result)
|
|||
result->sensorConfig.sensorMetadata = sensorMetadata;
|
||||
|
||||
/* Load the tuning file for this sensor. */
|
||||
controller_.read(settings.configurationFile.c_str());
|
||||
int ret = controller_.read(settings.configurationFile.c_str());
|
||||
if (ret) {
|
||||
LOG(IPARPI, Error)
|
||||
<< "Failed to load tuning data file "
|
||||
<< settings.configurationFile;
|
||||
return ret;
|
||||
}
|
||||
|
||||
controller_.initialise();
|
||||
|
||||
/* Return the controls handled by the IPA */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue