refactoring/cleanup of class for dynamic processing profile rules
This commit is contained in:
@@ -23,17 +23,26 @@
|
|||||||
using namespace rtengine;
|
using namespace rtengine;
|
||||||
using namespace rtengine::procparams;
|
using namespace rtengine::procparams;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const int ISO_MAX = 512000;
|
||||||
|
const double FNUMBER_MAX = 100.0;
|
||||||
|
const double FOCALLEN_MAX = 10000.0;
|
||||||
|
const double SHUTTERSPEED_MIN = 1.0/10000.0;
|
||||||
|
const double SHUTTERSPEED_MAX = 1000.0;
|
||||||
|
const double EXPCOMP_MIN = -20.0;
|
||||||
|
const double EXPCOMP_MAX = 20.0;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
DynamicProfileEntry::DynamicProfileEntry():
|
DynamicProfileEntry::DynamicProfileEntry():
|
||||||
serial_number(0),
|
serial_number(0),
|
||||||
has_iso(false), iso_min(0), iso_max(1000000),
|
iso(0, ISO_MAX),
|
||||||
has_fnumber(false), fnumber_min(0.0), fnumber_max(1000.0),
|
fnumber(0, FNUMBER_MAX),
|
||||||
has_focallen(false), focallen_min(0.0), focallen_max(1000000.0),
|
focallen(0, FOCALLEN_MAX),
|
||||||
has_shutterspeed(false), shutterspeed_min(1000.0), shutterspeed_max(1.0/1000000.0),
|
shutterspeed(SHUTTERSPEED_MIN, SHUTTERSPEED_MAX),
|
||||||
has_expcomp(false), expcomp_min(-100.0), expcomp_max(100.0),
|
expcomp(EXPCOMP_MIN, EXPCOMP_MAX)
|
||||||
has_make(false), make(""),
|
|
||||||
has_model(false), model(""),
|
|
||||||
has_lens(false), lens(""),
|
|
||||||
profilepath("")
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,63 +55,104 @@ bool DynamicProfileEntry::operator<(const DynamicProfileEntry &other) const
|
|||||||
|
|
||||||
bool DynamicProfileEntry::matches(const rtengine::ImageMetaData *im)
|
bool DynamicProfileEntry::matches(const rtengine::ImageMetaData *im)
|
||||||
{
|
{
|
||||||
if (has_iso) {
|
return (iso(im->getISOSpeed())
|
||||||
int iso = im->getISOSpeed();
|
&& fnumber(im->getFNumber())
|
||||||
if (iso < iso_min || iso > iso_max) {
|
&& focallen(im->getFocalLen())
|
||||||
return false;
|
&& shutterspeed(im->getShutterSpeed())
|
||||||
|
&& expcomp(im->getExpComp())
|
||||||
|
&& make(im->getMake())
|
||||||
|
&& model(im->getModel())
|
||||||
|
&& lens(im->getLens()));
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void get_int_range(DynamicProfileEntry::Range<int> &dest,
|
||||||
|
const Glib::KeyFile &kf, const Glib::ustring &group,
|
||||||
|
const Glib::ustring &key)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
int min = kf.get_integer(group, key + "_min");
|
||||||
|
int max = kf.get_integer(group, key + "_max");
|
||||||
|
if (min <= max) {
|
||||||
|
dest.min = min;
|
||||||
|
dest.max = max;
|
||||||
|
}
|
||||||
|
} catch (Glib::KeyFileError &e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (has_fnumber) {
|
|
||||||
double fnumber = im->getFNumber();
|
|
||||||
if (fnumber < fnumber_min || fnumber > fnumber_max) {
|
void get_double_range(DynamicProfileEntry::Range<double> &dest,
|
||||||
return false;
|
const Glib::KeyFile &kf, const Glib::ustring &group,
|
||||||
|
const Glib::ustring &key)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
int min = kf.get_double(group, key + "_min");
|
||||||
|
int max = kf.get_double(group, key + "_max");
|
||||||
|
if (min <= max) {
|
||||||
|
dest.min = min;
|
||||||
|
dest.max = max;
|
||||||
|
}
|
||||||
|
} catch (Glib::KeyFileError &e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (has_focallen) {
|
|
||||||
double focallen = im->getFocalLen();
|
|
||||||
if (focallen < focallen_min || focallen > focallen_max) {
|
void get_optional(DynamicProfileEntry::Optional<Glib::ustring> &dest,
|
||||||
return false;
|
const Glib::KeyFile &kf, const Glib::ustring &group,
|
||||||
|
const Glib::ustring &key)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
bool e = kf.get_boolean(group, key + "_enabled");
|
||||||
|
if (e) {
|
||||||
|
Glib::ustring s = kf.get_string(group, key + "_value");
|
||||||
|
dest.enabled = e;
|
||||||
|
dest.value = s;
|
||||||
|
}
|
||||||
|
} catch (Glib::KeyFileError &) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (has_shutterspeed) {
|
|
||||||
double shutterspeed = im->getShutterSpeed();
|
void set_int_range(Glib::KeyFile &kf, const Glib::ustring &group,
|
||||||
if (shutterspeed < shutterspeed_min || shutterspeed > shutterspeed_max){
|
const Glib::ustring &key,
|
||||||
return false;
|
const DynamicProfileEntry::Range<int> &val)
|
||||||
|
{
|
||||||
|
kf.set_integer(group, key + "_min", val.min);
|
||||||
|
kf.set_integer(group, key + "_max", val.max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_double_range(Glib::KeyFile &kf, const Glib::ustring &group,
|
||||||
|
const Glib::ustring &key,
|
||||||
|
const DynamicProfileEntry::Range<double> &val)
|
||||||
|
{
|
||||||
|
kf.set_double(group, key + "_min", val.min);
|
||||||
|
kf.set_double(group, key + "_max", val.max);
|
||||||
}
|
}
|
||||||
if (has_expcomp) {
|
|
||||||
double expcomp = im->getExpComp();
|
void set_optional(Glib::KeyFile &kf, const Glib::ustring &group,
|
||||||
if (expcomp < expcomp_min || expcomp > expcomp_max) {
|
const Glib::ustring &key,
|
||||||
return false;
|
const DynamicProfileEntry::Optional<Glib::ustring> &val)
|
||||||
}
|
{
|
||||||
}
|
kf.set_boolean(group, key + "_enabled", val.enabled);
|
||||||
if (has_make) {
|
kf.set_string(group, key + "_value", val.value);
|
||||||
if (im->getMake() != make) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (has_model) {
|
|
||||||
if (im->getModel() != model) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (has_lens) {
|
|
||||||
if (im->getLens() != lens) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
bool loadDynamicProfileEntries(std::vector<DynamicProfileEntry> &out)
|
bool loadDynamicProfileEntries(std::vector<DynamicProfileEntry> &out)
|
||||||
{
|
{
|
||||||
out.clear();
|
out.clear();
|
||||||
Glib::KeyFile kf;
|
Glib::KeyFile kf;
|
||||||
|
try {
|
||||||
if (!kf.load_from_file(
|
if (!kf.load_from_file(
|
||||||
Glib::build_filename(Options::rtdir, "dynamicprofile.cfg"))) {
|
Glib::build_filename(Options::rtdir, "dynamicprofile.cfg"))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} catch (Glib::Error &e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
printf("loading dynamic profiles...\n");
|
printf("loading dynamic profiles...\n");
|
||||||
auto groups = kf.get_groups();
|
auto groups = kf.get_groups();
|
||||||
for (auto group : groups) {
|
for (auto group : groups) {
|
||||||
@@ -120,42 +170,48 @@ bool loadDynamicProfileEntries(std::vector<DynamicProfileEntry> &out)
|
|||||||
out.emplace_back(DynamicProfileEntry());
|
out.emplace_back(DynamicProfileEntry());
|
||||||
DynamicProfileEntry &entry = out.back();
|
DynamicProfileEntry &entry = out.back();
|
||||||
entry.serial_number = serial;
|
entry.serial_number = serial;
|
||||||
entry.has_iso = kf.get_boolean(group, "has_iso");
|
get_int_range(entry.iso, kf, group, "iso");
|
||||||
entry.iso_min = kf.get_integer(group, "iso_min");
|
get_double_range(entry.fnumber, kf, group, "fnumber");
|
||||||
entry.iso_max = kf.get_integer(group, "iso_max");
|
get_double_range(entry.focallen, kf, group, "focallen");
|
||||||
|
get_double_range(entry.shutterspeed, kf, group, "shutterspeed");
|
||||||
entry.has_fnumber = kf.get_boolean(group, "has_fnumber");
|
get_double_range(entry.expcomp, kf, group, "expcomp");
|
||||||
entry.fnumber_min = kf.get_double(group, "fnumber_min");
|
get_optional(entry.make, kf, group, "make");
|
||||||
entry.fnumber_max = kf.get_double(group, "fnumber_max");
|
get_optional(entry.model, kf, group, "model");
|
||||||
|
get_optional(entry.lens, kf, group, "lens");
|
||||||
entry.has_focallen = kf.get_boolean(group, "has_focallen");
|
try {
|
||||||
entry.focallen_min = kf.get_double(group, "focallen_min");
|
|
||||||
entry.focallen_max = kf.get_double(group, "focallen_max");
|
|
||||||
|
|
||||||
entry.has_shutterspeed = kf.get_boolean(group, "has_shutterspeed");
|
|
||||||
entry.shutterspeed_min = kf.get_double(group, "shutterspeed_min");
|
|
||||||
entry.shutterspeed_max = kf.get_double(group, "shutterspeed_max");
|
|
||||||
|
|
||||||
entry.has_expcomp = kf.get_boolean(group, "has_expcomp");
|
|
||||||
entry.expcomp_min = kf.get_double(group, "expcomp_min");
|
|
||||||
entry.expcomp_max = kf.get_double(group, "expcomp_max");
|
|
||||||
|
|
||||||
entry.has_make = kf.get_boolean(group, "has_make");
|
|
||||||
entry.make = kf.get_string(group, "make");
|
|
||||||
|
|
||||||
entry.has_model = kf.get_boolean(group, "has_model");
|
|
||||||
entry.model = kf.get_string(group, "model");
|
|
||||||
|
|
||||||
entry.has_lens = kf.get_boolean(group, "has_lens");
|
|
||||||
entry.lens = kf.get_string(group, "lens");
|
|
||||||
|
|
||||||
entry.profilepath = kf.get_string(group, "profilepath");
|
entry.profilepath = kf.get_string(group, "profilepath");
|
||||||
|
} catch (Glib::KeyFileError &) {
|
||||||
|
out.pop_back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::sort(out.begin(), out.end());
|
std::sort(out.begin(), out.end());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool storeDynamicProfileEntries(const std::vector<DynamicProfileEntry> &entries)
|
||||||
|
{
|
||||||
|
printf("saving dynamic profiles...\n");
|
||||||
|
Glib::KeyFile kf;
|
||||||
|
for (auto &entry : entries) {
|
||||||
|
std::ostringstream buf;
|
||||||
|
buf << "entry " << entry.serial_number;
|
||||||
|
Glib::ustring group = buf.str();
|
||||||
|
set_int_range(kf, group, "iso", entry.iso);
|
||||||
|
set_double_range(kf, group, "fnumber", entry.fnumber);
|
||||||
|
set_double_range(kf, group, "focallen", entry.focallen);
|
||||||
|
set_double_range(kf, group, "shutterspeed", entry.shutterspeed);
|
||||||
|
set_double_range(kf, group, "expcomp", entry.expcomp);
|
||||||
|
set_optional(kf, group, "make", entry.make);
|
||||||
|
set_optional(kf, group, "model", entry.model);
|
||||||
|
set_optional(kf, group, "lens", entry.lens);
|
||||||
|
kf.set_string(group, "profilepath", entry.profilepath);
|
||||||
|
}
|
||||||
|
return kf.save_to_file(
|
||||||
|
Glib::build_filename(Options::rtdir, "dynamicprofile.cfg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PartialProfile *loadDynamicProfile(const ImageMetaData *im)
|
PartialProfile *loadDynamicProfile(const ImageMetaData *im)
|
||||||
{
|
{
|
||||||
PartialProfile *ret = new PartialProfile(true, true);
|
PartialProfile *ret = new PartialProfile(true, true);
|
||||||
@@ -177,4 +233,3 @@ PartialProfile *loadDynamicProfile(const ImageMetaData *im)
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,52 +20,57 @@
|
|||||||
#define _DYNAMICPROFILE_H_
|
#define _DYNAMICPROFILE_H_
|
||||||
|
|
||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
|
#include <vector>
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
class DynamicProfileEntry {
|
class DynamicProfileEntry {
|
||||||
public:
|
public:
|
||||||
|
template <class T>
|
||||||
|
struct Range {
|
||||||
|
T min;
|
||||||
|
T max;
|
||||||
|
explicit Range(T l=T(), T u=T()): min(l), max(u) {}
|
||||||
|
|
||||||
|
bool operator()(T val) const
|
||||||
|
{
|
||||||
|
return val >= min && val <= max;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct Optional {
|
||||||
|
T value;
|
||||||
|
bool enabled;
|
||||||
|
explicit Optional(T v=T(), bool e=false): value(v), enabled(e) {}
|
||||||
|
|
||||||
|
bool operator()(const T &val) const
|
||||||
|
{
|
||||||
|
return !enabled || value == val;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
DynamicProfileEntry();
|
DynamicProfileEntry();
|
||||||
bool matches(const rtengine::ImageMetaData *im);
|
bool matches(const rtengine::ImageMetaData *im);
|
||||||
bool operator<(const DynamicProfileEntry &other) const;
|
bool operator<(const DynamicProfileEntry &other) const;
|
||||||
|
|
||||||
int serial_number;
|
int serial_number;
|
||||||
|
Range<int> iso;
|
||||||
bool has_iso;
|
Range<double> fnumber;
|
||||||
int iso_min;
|
Range<double> focallen;
|
||||||
int iso_max;
|
Range<double> shutterspeed;
|
||||||
|
Range<double> expcomp;
|
||||||
bool has_fnumber;
|
Optional<Glib::ustring> make;
|
||||||
double fnumber_min;
|
Optional<Glib::ustring> model;
|
||||||
double fnumber_max;
|
Optional<Glib::ustring> lens;
|
||||||
|
|
||||||
bool has_focallen;
|
|
||||||
double focallen_min;
|
|
||||||
double focallen_max;
|
|
||||||
|
|
||||||
bool has_shutterspeed;
|
|
||||||
double shutterspeed_min;
|
|
||||||
double shutterspeed_max;
|
|
||||||
|
|
||||||
bool has_expcomp;
|
|
||||||
double expcomp_min;
|
|
||||||
double expcomp_max;
|
|
||||||
|
|
||||||
bool has_make;
|
|
||||||
std::string make;
|
|
||||||
|
|
||||||
bool has_model;
|
|
||||||
std::string model;
|
|
||||||
|
|
||||||
bool has_lens;
|
|
||||||
std::string lens;
|
|
||||||
|
|
||||||
Glib::ustring profilepath;
|
Glib::ustring profilepath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool loadDynamicProfileEntries(std::vector<DynamicProfileEntry> &out);
|
bool loadDynamicProfileEntries(std::vector<DynamicProfileEntry> &out);
|
||||||
|
bool storeDynamicProfileEntries(
|
||||||
|
const std::vector<DynamicProfileEntry> &entries);
|
||||||
|
|
||||||
rtengine::procparams::PartialProfile *loadDynamicProfile(
|
rtengine::procparams::PartialProfile *loadDynamicProfile(
|
||||||
const rtengine::ImageMetaData *im);
|
const rtengine::ImageMetaData *im);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user