Added new color toning method "L*a*b* regions"

Allows to specify various "regions" of the image with masks, and to correct
for hue, saturation and lightness.

Inspired by the existing L*a*b* grid (in turn taken from darktable)
This commit is contained in:
Alberto Griggio
2018-10-25 16:46:11 +02:00
parent eee6837385
commit 1a3fd9f157
18 changed files with 854 additions and 32 deletions

View File

@@ -614,6 +614,66 @@ bool LocalContrastParams::operator!=(const LocalContrastParams &other) const
const double ColorToningParams::LABGRID_CORR_MAX = 12000.f;
const double ColorToningParams::LABGRID_CORR_SCALE = 3.f;
ColorToningParams::LabCorrectionRegion::LabCorrectionRegion():
a(0),
b(0),
saturation(0),
lightness(0),
hueMask{
FCT_MinMaxCPoints,
0.166666667,
1.,
0.35,
0.35,
0.8287775246,
1.,
0.35,
0.35
},
chromaticityMask{
FCT_MinMaxCPoints,
0.,
1.,
0.35,
0.35,
1.,
1.,
0.35,
0.35
},
lightnessMask{
FCT_MinMaxCPoints,
0.,
1.,
0.35,
0.35,
1.,
1.,
0.35,
0.35
}
{
}
bool ColorToningParams::LabCorrectionRegion::operator==(const LabCorrectionRegion &other) const
{
return a == other.a
&& b == other.b
&& saturation == other.saturation
&& lightness == other.lightness
&& hueMask == other.hueMask
&& chromaticityMask == other.chromaticityMask
&& lightnessMask == other.lightnessMask;
}
bool ColorToningParams::LabCorrectionRegion::operator!=(const LabCorrectionRegion &other) const
{
return !(*this == other);
}
ColorToningParams::ColorToningParams() :
enabled(false),
autosat(true),
@@ -688,7 +748,9 @@ ColorToningParams::ColorToningParams() :
labgridALow(0.0),
labgridBLow(0.0),
labgridAHigh(0.0),
labgridBHigh(0.0)
labgridBHigh(0.0),
labregions{LabCorrectionRegion()},
labregionsShowMask(-1)
{
}
@@ -724,7 +786,9 @@ bool ColorToningParams::operator ==(const ColorToningParams& other) const
&& labgridALow == other.labgridALow
&& labgridBLow == other.labgridBLow
&& labgridAHigh == other.labgridAHigh
&& labgridBHigh == other.labgridBHigh;
&& labgridBHigh == other.labgridBHigh
&& labregions == other.labregions
&& labregionsShowMask == other.labregionsShowMask;
}
bool ColorToningParams::operator !=(const ColorToningParams& other) const
@@ -3383,6 +3447,20 @@ int ProcParams::save(const Glib::ustring& fname, const Glib::ustring& fname2, bo
saveToKeyfile(!pedited || pedited->colorToning.labgridBLow, "ColorToning", "LabGridBLow", colorToning.labgridBLow, keyFile);
saveToKeyfile(!pedited || pedited->colorToning.labgridAHigh, "ColorToning", "LabGridAHigh", colorToning.labgridAHigh, keyFile);
saveToKeyfile(!pedited || pedited->colorToning.labgridBHigh, "ColorToning", "LabGridBHigh", colorToning.labgridBHigh, keyFile);
if (!pedited || pedited->colorToning.labregions) {
for (size_t j = 0; j < colorToning.labregions.size(); ++j) {
std::string n = std::to_string(j+1);
auto &l = colorToning.labregions[j];
putToKeyfile("ColorToning", Glib::ustring("LabRegionA_") + n, l.a, keyFile);
putToKeyfile("ColorToning", Glib::ustring("LabRegionB_") + n, l.b, keyFile);
putToKeyfile("ColorToning", Glib::ustring("LabRegionSaturation_") + n, l.saturation, keyFile);
putToKeyfile("ColorToning", Glib::ustring("LabRegionLightness_") + n, l.lightness, keyFile);
putToKeyfile("ColorToning", Glib::ustring("LabRegionHueMask_") + n, l.hueMask, keyFile);
putToKeyfile("ColorToning", Glib::ustring("LabRegionChromaticityMask_") + n, l.chromaticityMask, keyFile);
putToKeyfile("ColorToning", Glib::ustring("LabRegionLightnessMask_") + n, l.lightnessMask, keyFile);
}
}
saveToKeyfile(!pedited || pedited->colorToning.labregionsShowMask, "ColorToning", "LabRegionsShowMask", colorToning.labregionsShowMask, keyFile);
// Raw
saveToKeyfile(!pedited || pedited->raw.darkFrame, "RAW", "DarkFrame", relativePathIfInside(fname, fnameAbsolute, raw.dark_frame), keyFile);
@@ -4740,6 +4818,49 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited)
colorToning.labgridBLow *= scale;
colorToning.labgridBHigh *= scale;
}
std::vector<ColorToningParams::LabCorrectionRegion> lg;
bool found = false;
bool done = false;
for (int i = 1; !done; ++i) {
ColorToningParams::LabCorrectionRegion cur;
done = true;
std::string n = std::to_string(i);
if (assignFromKeyfile(keyFile, "ColorToning", Glib::ustring("LabRegionA_") + n, pedited, cur.a, pedited->colorToning.labregions)) {
found = true;
done = false;
}
if (assignFromKeyfile(keyFile, "ColorToning", Glib::ustring("LabRegionB_") + n, pedited, cur.b, pedited->colorToning.labregions)) {
found = true;
done = false;
}
if (assignFromKeyfile(keyFile, "ColorToning", Glib::ustring("LabRegionSaturation_") + n, pedited, cur.saturation, pedited->colorToning.labregions)) {
found = true;
done = false;
}
if (assignFromKeyfile(keyFile, "ColorToning", Glib::ustring("LabRegionLightness_") + n, pedited, cur.lightness, pedited->colorToning.labregions)) {
found = true;
done = false;
}
if (assignFromKeyfile(keyFile, "ColorToning", Glib::ustring("LabRegionHueMask_") + n, pedited, cur.hueMask, pedited->colorToning.labregions)) {
found = true;
done = false;
}
if (assignFromKeyfile(keyFile, "ColorToning", Glib::ustring("LabRegionChromaticityMask_") + n, pedited, cur.chromaticityMask, pedited->colorToning.labregions)) {
found = true;
done = false;
}
if (assignFromKeyfile(keyFile, "ColorToning", Glib::ustring("LabRegionLightnessMask_") + n, pedited, cur.lightnessMask, pedited->colorToning.labregions)) {
found = true;
done = false;
}
if (!done) {
lg.emplace_back(cur);
}
}
if (found) {
colorToning.labregions = std::move(lg);
}
assignFromKeyfile(keyFile, "ColorToning", "LabRegionsShowMask", pedited, colorToning.labregionsShowMask, pedited->colorToning.labregionsShowMask);
}
if (keyFile.has_group("RAW")) {