added simple local contrast tool

Borrowed from G'MIC
This commit is contained in:
Alberto Griggio
2017-12-19 01:03:52 +01:00
parent d1d91869c8
commit b8777b3d87
16 changed files with 414 additions and 1 deletions

View File

@@ -148,6 +148,7 @@ set(NONCLISOURCEFILES
xtransrawexposure.cc
zoompanel.cc
fattaltonemap.cc
localcontrast.cc
)
include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}")

157
rtgui/localcontrast.cc Normal file
View File

@@ -0,0 +1,157 @@
/** -*- C++ -*-
*
* This file is part of RawTherapee.
*
* Copyright (c) 2017 Alberto Griggio <alberto.griggio@gmail.com>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include "localcontrast.h"
#include <iomanip>
#include <cmath>
using namespace rtengine;
using namespace rtengine::procparams;
LocalContrast::LocalContrast(): FoldableToolPanel(this, "localcontrast", M("TP_LOCALCONTRAST_LABEL"), false, true)
{
radius = Gtk::manage(new Adjuster(M("TP_LOCALCONTRAST_RADIUS"), 3., 200., 1., 8.));
amount = Gtk::manage(new Adjuster(M("TP_LOCALCONTRAST_AMOUNT"), 0., 1., 0.01, 0.2));
darkness = Gtk::manage(new Adjuster(M("TP_LOCALCONTRAST_DARKNESS"), 0., 4., 0.1, 1.));
lightness = Gtk::manage(new Adjuster(M("TP_LOCALCONTRAST_LIGHTNESS"), 0., 4., 0.1, 1.));
radius->setAdjusterListener(this);
amount->setAdjusterListener(this);
darkness->setAdjusterListener(this);
lightness->setAdjusterListener(this);
radius->show();
amount->show();
darkness->show();
lightness->show();
pack_start(*radius);
pack_start(*amount);
pack_start(*darkness);
pack_start(*lightness);
}
void LocalContrast::read(const ProcParams *pp, const ParamsEdited *pedited)
{
disableListener();
if (pedited) {
radius->setEditedState(pedited->localContrast.radius ? Edited : UnEdited);
amount->setEditedState(pedited->localContrast.amount ? Edited : UnEdited);
darkness->setEditedState(pedited->localContrast.darkness ? Edited : UnEdited);
lightness->setEditedState(pedited->localContrast.lightness ? Edited : UnEdited);
set_inconsistent(multiImage && !pedited->localContrast.enabled);
}
setEnabled(pp->localContrast.enabled);
radius->setValue(pp->localContrast.radius);
amount->setValue(pp->localContrast.amount);
darkness->setValue(pp->localContrast.darkness);
lightness->setValue(pp->localContrast.lightness);
enableListener();
}
void LocalContrast::write(ProcParams *pp, ParamsEdited *pedited)
{
pp->localContrast.radius = radius->getValue();
pp->localContrast.amount = amount->getValue();
pp->localContrast.darkness = darkness->getValue();
pp->localContrast.lightness = lightness->getValue();
pp->localContrast.enabled = getEnabled();
if (pedited) {
pedited->localContrast.radius = radius->getEditedState();
pedited->localContrast.amount = amount->getEditedState();
pedited->localContrast.darkness = darkness->getEditedState();
pedited->localContrast.lightness = lightness->getEditedState();
pedited->localContrast.enabled = !get_inconsistent();
}
}
void LocalContrast::setDefaults(const ProcParams *defParams, const ParamsEdited *pedited)
{
radius->setDefault(defParams->localContrast.radius);
amount->setDefault(defParams->localContrast.amount);
darkness->setDefault(defParams->localContrast.darkness);
lightness->setDefault(defParams->localContrast.lightness);
if (pedited) {
radius->setDefaultEditedState(pedited->localContrast.radius ? Edited : UnEdited);
amount->setDefaultEditedState(pedited->localContrast.amount ? Edited : UnEdited);
darkness->setDefaultEditedState(pedited->localContrast.darkness ? Edited : UnEdited);
lightness->setDefaultEditedState(pedited->localContrast.lightness ? Edited : UnEdited);
} else {
radius->setDefaultEditedState(Irrelevant);
amount->setDefaultEditedState(Irrelevant);
darkness->setDefaultEditedState(Irrelevant);
lightness->setDefaultEditedState(Irrelevant);
}
}
void LocalContrast::adjusterChanged(Adjuster* a, double newval)
{
if (listener && getEnabled()) {
if (a == radius) {
listener->panelChanged(EvLocalContrastRadius, a->getTextValue());
} else if (a == amount) {
listener->panelChanged(EvLocalContrastAmount, a->getTextValue());
} else if (a == darkness) {
listener->panelChanged(EvLocalContrastDarkness, a->getTextValue());
} else if (a == lightness) {
listener->panelChanged(EvLocalContrastLightness, a->getTextValue());
}
}
}
void LocalContrast::enabledChanged ()
{
if (listener) {
if (get_inconsistent()) {
listener->panelChanged(EvLocalContrastEnabled, M("GENERAL_UNCHANGED"));
} else if (getEnabled()) {
listener->panelChanged(EvLocalContrastEnabled, M("GENERAL_ENABLED"));
} else {
listener->panelChanged(EvLocalContrastEnabled, M("GENERAL_DISABLED"));
}
}
}
void LocalContrast::setBatchMode(bool batchMode)
{
ToolPanel::setBatchMode(batchMode);
radius->showEditedCB();
amount->showEditedCB();
darkness->showEditedCB();
lightness->showEditedCB();
}
// void LocalContrast::setAdjusterBehavior (bool alphaAdd, bool betaAdd)
// {
// threshold->setAddMode(alphaAdd);
// amount->setAddMode(betaAdd);
// }

47
rtgui/localcontrast.h Normal file
View File

@@ -0,0 +1,47 @@
/** -*- C++ -*-
*
* This file is part of RawTherapee.
*
* Copyright (c) 2017 Alberto Griggio <alberto.griggio@gmail.com>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <gtkmm.h>
#include "adjuster.h"
#include "toolpanel.h"
class LocalContrast: public ToolParamBlock, public AdjusterListener, public FoldableToolPanel
{
protected:
Adjuster *radius;
Adjuster *amount;
Adjuster *darkness;
Adjuster *lightness;
public:
LocalContrast();
void read(const rtengine::procparams::ProcParams *pp, const ParamsEdited *pedited=nullptr);
void write(rtengine::procparams::ProcParams *pp, ParamsEdited *pedited=nullptr);
void setDefaults(const rtengine::procparams::ProcParams *defParams, const ParamsEdited *pedited=nullptr);
void setBatchMode(bool batchMode);
void adjusterChanged(Adjuster *a, double newval);
void enabledChanged();
// void setAdjusterBehavior(bool alphaAdd, bool betaAdd);
};

View File

@@ -98,6 +98,11 @@ void ParamsEdited::set (bool v)
labCurve.avoidcolorshift = v;
labCurve.rstprotection = v;
labCurve.lcredsk = v;
localContrast.enabled = v;
localContrast.radius = v;
localContrast.amount = v;
localContrast.darkness = v;
localContrast.lightness = v;
rgbCurves.enabled = v;
rgbCurves.lumamode = v;
rgbCurves.rcurve = v;
@@ -643,6 +648,13 @@ void ParamsEdited::initFrom (const std::vector<rtengine::procparams::ProcParams>
labCurve.avoidcolorshift = labCurve.avoidcolorshift && p.labCurve.avoidcolorshift == other.labCurve.avoidcolorshift;
labCurve.rstprotection = labCurve.rstprotection && p.labCurve.rstprotection == other.labCurve.rstprotection;
labCurve.lcredsk = labCurve.lcredsk && p.labCurve.lcredsk == other.labCurve.lcredsk;
localContrast.enabled = localContrast.enabled && p.localContrast.enabled == other.localContrast.enabled;
localContrast.radius = localContrast.radius && p.localContrast.radius == other.localContrast.radius;
localContrast.amount = localContrast.amount && p.localContrast.amount == other.localContrast.amount;
localContrast.darkness = localContrast.darkness && p.localContrast.darkness == other.localContrast.darkness;
localContrast.lightness = localContrast.lightness && p.localContrast.lightness == other.localContrast.lightness;
rgbCurves.enabled = rgbCurves.enabled && p.rgbCurves.enabled == other.rgbCurves.enabled;
rgbCurves.lumamode = rgbCurves.lumamode && p.rgbCurves.lumamode == other.rgbCurves.lumamode;
rgbCurves.rcurve = rgbCurves.rcurve && p.rgbCurves.rcurve == other.rgbCurves.rcurve;
@@ -1370,6 +1382,22 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten
toEdit.labCurve.lcredsk = mods.labCurve.lcredsk;
}
if (localContrast.enabled) {
toEdit.localContrast.enabled = mods.localContrast.enabled;
}
if (localContrast.radius) {
toEdit.localContrast.radius = mods.localContrast.radius;
}
if (localContrast.amount) {
toEdit.localContrast.amount = mods.localContrast.amount;
}
if (localContrast.darkness) {
toEdit.localContrast.darkness = mods.localContrast.darkness;
}
if (localContrast.lightness) {
toEdit.localContrast.lightness = mods.localContrast.lightness;
}
if (rgbCurves.enabled) {
toEdit.rgbCurves.enabled = mods.rgbCurves.enabled;
}

View File

@@ -118,6 +118,17 @@ public:
bool clcurve;
};
class LocalContrastParamsEdited {
public:
bool enabled;
bool radius;
bool amount;
bool darkness;
bool lightness;
};
class RGBCurvesParamsEdited
{
@@ -793,6 +804,7 @@ public:
GeneralParamsEdited general;
ToneCurveParamsEdited toneCurve;
LCurveParamsEdited labCurve;
LocalContrastParamsEdited localContrast;
RGBCurvesParamsEdited rgbCurves;
ColorToningEdited colorToning;
RetinexParamsEdited retinex;

View File

@@ -41,6 +41,7 @@ ToolPanelCoordinator::ToolPanelCoordinator (bool batch) : ipc (nullptr), hasChan
coarse = Gtk::manage (new CoarsePanel ());
toneCurve = Gtk::manage (new ToneCurve ());
shadowshighlights = Gtk::manage (new ShadowsHighlights ());
localContrast = Gtk::manage(new LocalContrast());
impulsedenoise = Gtk::manage (new ImpulseDenoise ());
defringe = Gtk::manage (new Defringe ());
dirpyrdenoise = Gtk::manage (new DirPyrDenoise ());
@@ -106,6 +107,7 @@ ToolPanelCoordinator::ToolPanelCoordinator (bool batch) : ipc (nullptr), hasChan
addPanel (colorPanel, vibrance);
addPanel (colorPanel, chmixer);
addPanel (colorPanel, blackwhite);
addPanel (exposurePanel, localContrast);
addPanel (exposurePanel, shadowshighlights);
addPanel (detailsPanel, sharpening);
addPanel (detailsPanel, sharpenEdge);

View File

@@ -79,6 +79,7 @@
#include "filmsimulation.h"
#include "prsharpening.h"
#include "fattaltonemap.h"
#include "localcontrast.h"
#include "guiutils.h"
class ImageEditorCoordinator;
@@ -120,6 +121,7 @@ protected:
Crop* crop;
ToneCurve* toneCurve;
ShadowsHighlights* shadowshighlights;
LocalContrast *localContrast;
Defringe* defringe;
ImpulseDenoise* impulsedenoise;
DirPyrDenoise* dirpyrdenoise;