"Fossies" - the Fresh Open Source Software Archive

Member "rawtherapee-5.7/rtgui/labcurve.cc" (10 Sep 2019, 24294 Bytes) of package /linux/misc/rawtherapee-5.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "labcurve.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.6_vs_5.7.

    1 /*
    2  *  This file is part of RawTherapee.
    3  *
    4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
    5  *
    6  *  RawTherapee is free software: you can redistribute it and/or modify
    7  *  it under the terms of the GNU General Public License as published by
    8  *  the Free Software Foundation, either version 3 of the License, or
    9  *  (at your option) any later version.
   10  *
   11  *  RawTherapee is distributed in the hope that it will be useful,
   12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  *  GNU General Public License for more details.
   15  *
   16  *  You should have received a copy of the GNU General Public License
   17  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
   18  */
   19 #include <iomanip>
   20 
   21 #include "labcurve.h"
   22 
   23 #include "../rtengine/improcfun.h"
   24 #include "../rtengine/procparams.h"
   25 #include "editcallbacks.h"
   26 
   27 using namespace rtengine;
   28 using namespace rtengine::procparams;
   29 
   30 LCurve::LCurve () : FoldableToolPanel(this, "labcurves", M("TP_LABCURVE_LABEL"), false, true)
   31 {
   32     brightness = Gtk::manage (new Adjuster (M("TP_LABCURVE_BRIGHTNESS"), -100., 100., 1., 0.));
   33     contrast   = Gtk::manage (new Adjuster (M("TP_LABCURVE_CONTRAST"), -100., 100., 1., 0.));
   34     chromaticity   = Gtk::manage (new Adjuster (M("TP_LABCURVE_CHROMATICITY"), -100., 100., 1., 0.));
   35     chromaticity->set_tooltip_markup(M("TP_LABCURVE_CHROMA_TOOLTIP"));
   36 
   37     pack_start (*brightness);
   38     brightness->show ();
   39 
   40     pack_start (*contrast);
   41     contrast->show ();
   42 
   43     pack_start (*chromaticity);
   44     chromaticity->show ();
   45 
   46     brightness->setAdjusterListener (this);
   47     contrast->setAdjusterListener (this);
   48     chromaticity->setAdjusterListener (this);
   49 
   50     brightness->setLogScale(2, 0, true);
   51     contrast->setLogScale(2, 0, true);
   52     chromaticity->setLogScale(2, 0, true);
   53 
   54     //%%%%%%%%%%%%%%%%%%
   55     Gtk::HSeparator *hsep2 = Gtk::manage (new  Gtk::HSeparator());
   56     hsep2->show ();
   57     pack_start (*hsep2, Gtk::PACK_EXPAND_WIDGET, 4);
   58 
   59     avoidcolorshift = Gtk::manage (new Gtk::CheckButton (M("TP_LABCURVE_AVOIDCOLORSHIFT")));
   60     avoidcolorshift->set_tooltip_text (M("TP_LABCURVE_AVOIDCOLORSHIFT_TOOLTIP"));
   61     pack_start (*avoidcolorshift, Gtk::PACK_SHRINK, 4);
   62 
   63     lcredsk = Gtk::manage (new Gtk::CheckButton (M("TP_LABCURVE_LCREDSK")));
   64     lcredsk->set_tooltip_markup (M("TP_LABCURVE_LCREDSK_TIP"));
   65     pack_start (*lcredsk);
   66 
   67     rstprotection = Gtk::manage ( new Adjuster (M("TP_LABCURVE_RSTPROTECTION"), 0., 100., 0.1, 0.) );
   68     pack_start (*rstprotection);
   69     rstprotection->show ();
   70 
   71     rstprotection->setAdjusterListener (this);
   72     rstprotection->set_tooltip_text (M("TP_LABCURVE_RSTPRO_TOOLTIP"));
   73 
   74     acconn = avoidcolorshift->signal_toggled().connect( sigc::mem_fun(*this, &LCurve::avoidcolorshift_toggled) );
   75     lcconn = lcredsk->signal_toggled().connect( sigc::mem_fun(*this, &LCurve::lcredsk_toggled) );
   76 
   77     //%%%%%%%%%%%%%%%%%%%
   78 
   79     Gtk::HSeparator *hsep3 = Gtk::manage (new  Gtk::HSeparator());
   80     hsep3->show ();
   81     pack_start (*hsep3, Gtk::PACK_EXPAND_WIDGET, 4);
   82 
   83     curveEditorG = new CurveEditorGroup (options.lastLabCurvesDir);
   84     curveEditorG->setCurveListener (this);
   85 
   86     lshape = static_cast<DiagonalCurveEditor*>(curveEditorG->addCurve(CT_Diagonal, "L*"));
   87     lshape->setTooltip(M("TP_LABCURVE_CURVEEDITOR_LL_TOOLTIP"));
   88     lshape->setEditID(EUID_Lab_LCurve, BT_SINGLEPLANE_FLOAT);
   89 
   90     ashape = static_cast<DiagonalCurveEditor*>(curveEditorG->addCurve(CT_Diagonal, "a*"));
   91     ashape->setEditID(EUID_Lab_aCurve, BT_SINGLEPLANE_FLOAT);
   92 
   93     ashape->setRangeLabels(
   94         M("TP_LABCURVE_CURVEEDITOR_A_RANGE1"), M("TP_LABCURVE_CURVEEDITOR_A_RANGE2"),
   95         M("TP_LABCURVE_CURVEEDITOR_A_RANGE3"), M("TP_LABCURVE_CURVEEDITOR_A_RANGE4")
   96     );
   97     //from green to magenta
   98     std::vector<GradientMilestone> milestones = {
   99         GradientMilestone(0., 0., 1., 0.),
  100         GradientMilestone(1., 1., 0., 1.)
  101     };
  102     ashape->setBottomBarBgGradient(milestones);
  103     ashape->setLeftBarBgGradient(milestones);
  104 
  105     bshape = static_cast<DiagonalCurveEditor*>(curveEditorG->addCurve(CT_Diagonal, "b*"));
  106     bshape->setRangeLabels(
  107         M("TP_LABCURVE_CURVEEDITOR_B_RANGE1"), M("TP_LABCURVE_CURVEEDITOR_B_RANGE2"),
  108         M("TP_LABCURVE_CURVEEDITOR_B_RANGE3"), M("TP_LABCURVE_CURVEEDITOR_B_RANGE4")
  109     );
  110     bshape->setEditID(EUID_Lab_bCurve, BT_SINGLEPLANE_FLOAT);
  111 
  112     //from blue to yellow
  113     milestones = {
  114         GradientMilestone(0., 0., 0., 1.),
  115         GradientMilestone(1., 1., 1., 0.)
  116     };
  117     bshape->setBottomBarBgGradient(milestones);
  118     bshape->setLeftBarBgGradient(milestones);
  119 
  120     curveEditorG->newLine();  //  ------------------------------------------------ second line
  121 
  122     lhshape = static_cast<FlatCurveEditor*>(curveEditorG->addCurve(CT_Flat, M("TP_LABCURVE_CURVEEDITOR_LH")));
  123     lhshape->setTooltip(M("TP_LABCURVE_CURVEEDITOR_LH_TOOLTIP"));
  124     lhshape->setCurveColorProvider(this, 4);
  125     lhshape->setEditID(EUID_Lab_LHCurve, BT_SINGLEPLANE_FLOAT);
  126 
  127 
  128     chshape = static_cast<FlatCurveEditor*>(curveEditorG->addCurve(CT_Flat, M("TP_LABCURVE_CURVEEDITOR_CH")));
  129     chshape->setTooltip(M("TP_LABCURVE_CURVEEDITOR_CH_TOOLTIP"));
  130     chshape->setCurveColorProvider(this, 1);
  131     chshape->setEditID(EUID_Lab_CHCurve, BT_SINGLEPLANE_FLOAT);
  132 
  133 
  134     hhshape = static_cast<FlatCurveEditor*>(curveEditorG->addCurve(CT_Flat, M("TP_LABCURVE_CURVEEDITOR_HH")));
  135     hhshape->setTooltip(M("TP_LABCURVE_CURVEEDITOR_HH_TOOLTIP"));
  136     hhshape->setCurveColorProvider(this, 5);
  137     hhshape->setEditID(EUID_Lab_HHCurve, BT_SINGLEPLANE_FLOAT);
  138 
  139     curveEditorG->newLine();  //  ------------------------------------------------ 3rd line
  140 
  141     ccshape = static_cast<DiagonalCurveEditor*>(curveEditorG->addCurve(CT_Diagonal, M("TP_LABCURVE_CURVEEDITOR_CC")));
  142     ccshape->setTooltip(M("TP_LABCURVE_CURVEEDITOR_CC_TOOLTIP"));
  143     ccshape->setEditID(EUID_Lab_CCurve, BT_SINGLEPLANE_FLOAT);
  144     ccshape->setRangeLabels(
  145         M("TP_LABCURVE_CURVEEDITOR_CC_RANGE1"), M("TP_LABCURVE_CURVEEDITOR_CC_RANGE2"),
  146         M("TP_LABCURVE_CURVEEDITOR_CC_RANGE3"), M("TP_LABCURVE_CURVEEDITOR_CC_RANGE4")
  147     );
  148 
  149     ccshape->setBottomBarColorProvider(this, 2);
  150     ccshape->setLeftBarColorProvider(this, 7);
  151     ccshape->setRangeDefaultMilestones(0.05, 0.2, 0.58);
  152 
  153     lcshape = static_cast<DiagonalCurveEditor*>(curveEditorG->addCurve(CT_Diagonal, M("TP_LABCURVE_CURVEEDITOR_LC")));
  154     lcshape->setTooltip(M("TP_LABCURVE_CURVEEDITOR_LC_TOOLTIP"));
  155     lcshape->setEditID(EUID_Lab_LCCurve, BT_SINGLEPLANE_FLOAT);
  156 
  157     // left and bottom bar uses the same caller id because the will display the same content
  158     lcshape->setBottomBarColorProvider(this, 2);
  159     lcshape->setRangeLabels(
  160         M("TP_LABCURVE_CURVEEDITOR_CC_RANGE1"), M("TP_LABCURVE_CURVEEDITOR_CC_RANGE2"),
  161         M("TP_LABCURVE_CURVEEDITOR_CC_RANGE3"), M("TP_LABCURVE_CURVEEDITOR_CC_RANGE4")
  162     );
  163     lcshape->setRangeDefaultMilestones(0.05, 0.2, 0.58);
  164 
  165     clshape = static_cast<DiagonalCurveEditor*>(curveEditorG->addCurve(CT_Diagonal, M("TP_LABCURVE_CURVEEDITOR_CL")));
  166     clshape->setTooltip(M("TP_LABCURVE_CURVEEDITOR_CL_TOOLTIP"));
  167     clshape->setEditID(EUID_Lab_CLCurve, BT_SINGLEPLANE_FLOAT);
  168 
  169     clshape->setLeftBarColorProvider(this, 7);
  170     clshape->setRangeDefaultMilestones(0.25, 0.5, 0.75);
  171 
  172     milestones = {
  173         GradientMilestone(0., 0., 0., 0.),
  174         GradientMilestone(1., 1., 1., 1.)
  175     };
  176     clshape->setBottomBarBgGradient(milestones);
  177 
  178 
  179     // Setting the gradient milestones
  180 
  181     // from black to white
  182     milestones.emplace_back(0., 0., 0., 0.);
  183     milestones.emplace_back(1., 1., 1., 1.);
  184     lshape->setBottomBarBgGradient(milestones);
  185     lshape->setLeftBarBgGradient(milestones);
  186     milestones.emplace_back(0., 0., 0., 0.);
  187     milestones.emplace_back(1., 1., 1., 1.);
  188     lcshape->setRangeDefaultMilestones(0.05, 0.2, 0.58);
  189 
  190     lcshape->setBottomBarBgGradient(milestones);
  191 
  192     milestones.at(0).r = milestones.at(0).g = milestones.at(0).b = 0.1;
  193     milestones.at(1).r = milestones.at(1).g = milestones.at(1).b = 0.8;
  194     lcshape->setLeftBarBgGradient(milestones);
  195 
  196     // whole hue range
  197     milestones.clear();
  198 
  199     for (int i = 0; i < 7; i++) {
  200         float R, G, B;
  201         float x = float(i) * (1.0f / 6.0);
  202         Color::hsv2rgb01(x, 0.5f, 0.5f, R, G, B);
  203         milestones.emplace_back(x, R, G, B);
  204     }
  205 
  206     chshape->setBottomBarBgGradient(milestones);
  207     lhshape->setBottomBarBgGradient(milestones);
  208     hhshape->setBottomBarBgGradient(milestones);
  209 
  210 
  211     // This will add the reset button at the end of the curveType buttons
  212     curveEditorG->curveListComplete();
  213 
  214     pack_start (*curveEditorG, Gtk::PACK_SHRINK, 4);
  215     Gtk::HSeparator *hsepdh = Gtk::manage (new  Gtk::HSeparator());
  216     hsepdh->show ();
  217     pack_start (*hsepdh, Gtk::PACK_EXPAND_WIDGET, 4);
  218 
  219 }
  220 
  221 LCurve::~LCurve ()
  222 {
  223     delete curveEditorG;
  224 
  225 }
  226 
  227 void LCurve::read (const ProcParams* pp, const ParamsEdited* pedited)
  228 {
  229 
  230     disableListener ();
  231 
  232     if (pedited) {
  233         brightness->setEditedState (pedited->labCurve.brightness ? Edited : UnEdited);
  234         contrast->setEditedState (pedited->labCurve.contrast ? Edited : UnEdited);
  235         chromaticity->setEditedState (pedited->labCurve.chromaticity ? Edited : UnEdited);
  236 
  237         //%%%%%%%%%%%%%%%%%%%%%%
  238         rstprotection->setEditedState (pedited->labCurve.rstprotection ? Edited : UnEdited);
  239         avoidcolorshift->set_inconsistent (!pedited->labCurve.avoidcolorshift);
  240         lcredsk->set_inconsistent (!pedited->labCurve.lcredsk);
  241 
  242         //%%%%%%%%%%%%%%%%%%%%%%
  243 
  244         lshape->setUnChanged   (!pedited->labCurve.lcurve);
  245         ashape->setUnChanged   (!pedited->labCurve.acurve);
  246         bshape->setUnChanged   (!pedited->labCurve.bcurve);
  247         ccshape->setUnChanged  (!pedited->labCurve.cccurve);
  248         chshape->setUnChanged  (!pedited->labCurve.chcurve);
  249         lhshape->setUnChanged  (!pedited->labCurve.lhcurve);
  250         hhshape->setUnChanged  (!pedited->labCurve.hhcurve);
  251         lcshape->setUnChanged  (!pedited->labCurve.lccurve);
  252         clshape->setUnChanged  (!pedited->labCurve.clcurve);
  253 
  254         set_inconsistent(multiImage && !pedited->labCurve.enabled);
  255     }
  256 
  257     brightness->setValue    (pp->labCurve.brightness);
  258     contrast->setValue      (pp->labCurve.contrast);
  259     chromaticity->setValue  (pp->labCurve.chromaticity);
  260     adjusterChanged(chromaticity, pp->labCurve.chromaticity); // To update the GUI sensitiveness
  261     //%%%%%%%%%%%%%%%%%%%%%%
  262     rstprotection->setValue (pp->labCurve.rstprotection);
  263 
  264     bwtconn.block (true);
  265     acconn.block (true);
  266     lcconn.block (true);
  267     avoidcolorshift->set_active (pp->labCurve.avoidcolorshift);
  268     lcredsk->set_active (pp->labCurve.lcredsk);
  269 
  270     bwtconn.block (false);
  271     acconn.block (false);
  272     lcconn.block (false);
  273 
  274     lastACVal = pp->labCurve.avoidcolorshift;
  275     lastLCVal = pp->labCurve.lcredsk;
  276     //%%%%%%%%%%%%%%%%%%%%%%
  277 
  278     lshape->setCurve   (pp->labCurve.lcurve);
  279     ashape->setCurve   (pp->labCurve.acurve);
  280     bshape->setCurve   (pp->labCurve.bcurve);
  281     ccshape->setCurve  (pp->labCurve.cccurve);
  282     chshape->setCurve  (pp->labCurve.chcurve);
  283     lhshape->setCurve  (pp->labCurve.lhcurve);
  284     hhshape->setCurve  (pp->labCurve.hhcurve);
  285     lcshape->setCurve  (pp->labCurve.lccurve);
  286     clshape->setCurve  (pp->labCurve.clcurve);
  287 
  288     setEnabled(pp->labCurve.enabled);
  289     
  290     queue_draw();
  291 
  292     enableListener ();
  293 }
  294 
  295 void LCurve::autoOpenCurve ()
  296 {
  297     // Open up the first curve if selected
  298     bool active = lshape->openIfNonlinear();
  299 
  300     if (!active) {
  301         active = ashape->openIfNonlinear();
  302     }
  303 
  304     if (!active) {
  305         active = bshape->openIfNonlinear();
  306     }
  307 
  308     if (!active) {
  309         active = ccshape->openIfNonlinear();
  310     }
  311 
  312     if (!active) {
  313         active = chshape->openIfNonlinear();
  314     }
  315 
  316     if (!active) {
  317         active = lhshape->openIfNonlinear();
  318     }
  319 
  320     if (!active) {
  321         active = hhshape->openIfNonlinear();
  322     }
  323 
  324     if (!active) {
  325         active = lcshape->openIfNonlinear();
  326     }
  327 
  328     if (!active) {
  329         clshape->openIfNonlinear();
  330     }
  331 
  332 }
  333 
  334 void LCurve::setEditProvider  (EditDataProvider *provider)
  335 {
  336     lshape->setEditProvider(provider);
  337     ccshape->setEditProvider(provider);
  338     lcshape->setEditProvider(provider);
  339     clshape->setEditProvider(provider);
  340     lhshape->setEditProvider(provider);
  341     chshape->setEditProvider(provider);
  342     hhshape->setEditProvider(provider);
  343     ashape->setEditProvider(provider);
  344     bshape->setEditProvider(provider);
  345 
  346 }
  347 
  348 
  349 void LCurve::write (ProcParams* pp, ParamsEdited* pedited)
  350 {
  351     pp->labCurve.enabled = getEnabled();
  352     
  353     pp->labCurve.brightness    = brightness->getValue ();
  354     pp->labCurve.contrast      = (int)contrast->getValue ();
  355     pp->labCurve.chromaticity  = (int)chromaticity->getValue ();
  356     //%%%%%%%%%%%%%%%%%%%%%%
  357     pp->labCurve.avoidcolorshift = avoidcolorshift->get_active ();
  358     pp->labCurve.lcredsk         = lcredsk->get_active ();
  359 
  360     pp->labCurve.rstprotection   = rstprotection->getValue ();
  361     //%%%%%%%%%%%%%%%%%%%%%%
  362 
  363     pp->labCurve.lcurve  = lshape->getCurve ();
  364     pp->labCurve.acurve  = ashape->getCurve ();
  365     pp->labCurve.bcurve  = bshape->getCurve ();
  366     pp->labCurve.cccurve = ccshape->getCurve ();
  367     pp->labCurve.chcurve = chshape->getCurve ();
  368     pp->labCurve.lhcurve = lhshape->getCurve ();
  369     pp->labCurve.hhcurve = hhshape->getCurve ();
  370     pp->labCurve.lccurve = lcshape->getCurve ();
  371     pp->labCurve.clcurve = clshape->getCurve ();
  372 
  373     if (pedited) {
  374         pedited->labCurve.brightness   = brightness->getEditedState ();
  375         pedited->labCurve.contrast     = contrast->getEditedState ();
  376         pedited->labCurve.chromaticity = chromaticity->getEditedState ();
  377 
  378         //%%%%%%%%%%%%%%%%%%%%%%
  379         pedited->labCurve.avoidcolorshift = !avoidcolorshift->get_inconsistent();
  380         pedited->labCurve.lcredsk         = !lcredsk->get_inconsistent();
  381 
  382         pedited->labCurve.rstprotection   = rstprotection->getEditedState ();
  383 
  384         pedited->labCurve.lcurve    = !lshape->isUnChanged ();
  385         pedited->labCurve.acurve    = !ashape->isUnChanged ();
  386         pedited->labCurve.bcurve    = !bshape->isUnChanged ();
  387         pedited->labCurve.cccurve   = !ccshape->isUnChanged ();
  388         pedited->labCurve.chcurve   = !chshape->isUnChanged ();
  389         pedited->labCurve.lhcurve   = !lhshape->isUnChanged ();
  390         pedited->labCurve.hhcurve   = !hhshape->isUnChanged ();
  391         pedited->labCurve.lccurve   = !lcshape->isUnChanged ();
  392         pedited->labCurve.clcurve   = !clshape->isUnChanged ();
  393 
  394         pedited->labCurve.enabled = !get_inconsistent();
  395     }
  396 
  397 }
  398 
  399 void LCurve::setDefaults (const ProcParams* defParams, const ParamsEdited* pedited)
  400 {
  401 
  402     brightness->setDefault (defParams->labCurve.brightness);
  403     contrast->setDefault (defParams->labCurve.contrast);
  404     chromaticity->setDefault (defParams->labCurve.chromaticity);
  405     rstprotection->setDefault (defParams->labCurve.rstprotection);
  406 
  407     if (pedited) {
  408         brightness->setDefaultEditedState (pedited->labCurve.brightness ? Edited : UnEdited);
  409         contrast->setDefaultEditedState (pedited->labCurve.contrast ? Edited : UnEdited);
  410         chromaticity->setDefaultEditedState (pedited->labCurve.chromaticity ? Edited : UnEdited);
  411         rstprotection->setDefaultEditedState (pedited->labCurve.rstprotection ? Edited : UnEdited);
  412     } else {
  413         brightness->setDefaultEditedState (Irrelevant);
  414         contrast->setDefaultEditedState (Irrelevant);
  415         chromaticity->setDefaultEditedState (Irrelevant);
  416         rstprotection->setDefaultEditedState (Irrelevant);
  417     }
  418 }
  419 
  420 //%%%%%%%%%%%%%%%%%%%%%%
  421 //Color shift control changed
  422 void LCurve::avoidcolorshift_toggled ()
  423 {
  424 
  425     if (batchMode) {
  426         if (avoidcolorshift->get_inconsistent()) {
  427             avoidcolorshift->set_inconsistent (false);
  428             acconn.block (true);
  429             avoidcolorshift->set_active (false);
  430             acconn.block (false);
  431         } else if (lastACVal) {
  432             avoidcolorshift->set_inconsistent (true);
  433         }
  434 
  435         lastACVal = avoidcolorshift->get_active ();
  436     }
  437 
  438     if (listener && getEnabled()) {
  439         if (avoidcolorshift->get_active ()) {
  440             listener->panelChanged (EvLAvoidColorShift, M("GENERAL_ENABLED"));
  441         } else {
  442             listener->panelChanged (EvLAvoidColorShift, M("GENERAL_DISABLED"));
  443         }
  444     }
  445 }
  446 
  447 void LCurve::lcredsk_toggled ()
  448 {
  449 
  450     if (batchMode) {
  451         if (lcredsk->get_inconsistent()) {
  452             lcredsk->set_inconsistent (false);
  453             lcconn.block (true);
  454             lcredsk->set_active (false);
  455             lcconn.block (false);
  456         } else if (lastLCVal) {
  457             lcredsk->set_inconsistent (true);
  458         }
  459 
  460         lastLCVal = lcredsk->get_active ();
  461     } else {
  462         lcshape->refresh();
  463     }
  464 
  465     if (listener && getEnabled()) {
  466         if (lcredsk->get_active ()) {
  467             listener->panelChanged (EvLLCredsk, M("GENERAL_ENABLED"));
  468         } else {
  469             listener->panelChanged (EvLLCredsk, M("GENERAL_DISABLED"));
  470         }
  471     }
  472 }
  473 
  474 //%%%%%%%%%%%%%%%%%%%%%%
  475 
  476 /*
  477  * Curve listener
  478  *
  479  * If more than one curve has been added, the curve listener is automatically
  480  * set to 'multi=true', and send a pointer of the modified curve in a parameter
  481  */
  482 void LCurve::curveChanged (CurveEditor* ce)
  483 {
  484 
  485     if (listener && getEnabled()) {
  486         if (ce == lshape) {
  487             listener->panelChanged (EvLLCurve, M("HISTORY_CUSTOMCURVE"));
  488         }
  489 
  490         if (ce == ashape) {
  491             listener->panelChanged (EvLaCurve, M("HISTORY_CUSTOMCURVE"));
  492         }
  493 
  494         if (ce == bshape) {
  495             listener->panelChanged (EvLbCurve, M("HISTORY_CUSTOMCURVE"));
  496         }
  497 
  498         if (ce == ccshape) {
  499             listener->panelChanged (EvLCCCurve, M("HISTORY_CUSTOMCURVE"));
  500         }
  501 
  502         if (ce == chshape) {
  503             listener->panelChanged (EvLCHCurve, M("HISTORY_CUSTOMCURVE"));
  504         }
  505 
  506         if (ce == lhshape) {
  507             listener->panelChanged (EvLLHCurve, M("HISTORY_CUSTOMCURVE"));
  508         }
  509 
  510         if (ce == hhshape) {
  511             listener->panelChanged (EvLHHCurve, M("HISTORY_CUSTOMCURVE"));
  512         }
  513 
  514         if (ce == lcshape) {
  515             listener->panelChanged (EvLLCCurve, M("HISTORY_CUSTOMCURVE"));
  516         }
  517 
  518         if (ce == clshape) {
  519             listener->panelChanged (EvLCLCurve, M("HISTORY_CUSTOMCURVE"));
  520         }
  521 
  522 
  523     }
  524 }
  525 
  526 void LCurve::adjusterChanged(Adjuster* a, double newval)
  527 {
  528     Glib::ustring costr;
  529 
  530     if (a == brightness) {
  531         costr = Glib::ustring::format (std::setw(3), std::fixed, std::setprecision(2), a->getValue());
  532     } else if (a == rstprotection) {
  533         costr = Glib::ustring::format (std::setw(3), std::fixed, std::setprecision(1), a->getValue());
  534     } else {
  535         costr = Glib::ustring::format ((int)a->getValue());
  536     }
  537 
  538     if (a == brightness) {
  539         if (listener && getEnabled()) {
  540             listener->panelChanged (EvLBrightness, costr);
  541         }
  542     } else if (a == contrast) {
  543         if (listener && getEnabled()) {
  544             listener->panelChanged (EvLContrast, costr);
  545         }
  546     } else if (a == rstprotection) {
  547         if (listener && getEnabled()) {
  548             listener->panelChanged (EvLRSTProtection, costr);
  549         }
  550     } else if (a == chromaticity) {
  551         if (multiImage) {
  552             //if chromaticity==-100 (lowest value), we enter the B&W mode and avoid color shift and rstprotection has no effect
  553             rstprotection->set_sensitive( true );
  554             avoidcolorshift->set_sensitive( true );
  555             lcredsk->set_sensitive( true );
  556         } else {
  557             //if chromaticity==-100 (lowest value), we enter the B&W mode and avoid color shift and rstprotection has no effect
  558             rstprotection->set_sensitive( int(newval) > -100 ); //no reason for grey rstprotection
  559             avoidcolorshift->set_sensitive( int(newval) > -100 );
  560             lcredsk->set_sensitive( int(newval) > -100 );
  561         }
  562 
  563         if (listener && getEnabled()) {
  564             listener->panelChanged (EvLSaturation, costr);
  565         }
  566     }
  567 }
  568 
  569 void LCurve::colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller *caller)
  570 {
  571 
  572     float R = 0.f, G = 0.f, B = 0.f;
  573 
  574     if (elemType == ColorCaller::CCET_VERTICAL_BAR) {
  575         valY = 0.5;
  576     }
  577 
  578     if (callerId == 1) {         // ch - main curve
  579         Color::hsv2rgb01(float(valX), float(valY), 0.5f, R, G, B);
  580     } else if (callerId == 2) {  // cc - bottom bar
  581         float value = (1.f - 0.7f) * float(valX) + 0.7f;
  582         // whole hue range
  583         // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before)
  584         Color::hsv2rgb01(float(valY*0.8), float(valX), value, R, G, B);
  585     } else if (callerId == 6) {  // cc - left bar
  586         float value = (1.f - 0.7f) * float(valX) + 0.7f;
  587         float hue = (1.14056f - 0.92f) * float(valY) + 0.92f;
  588         if (hue > 1.0f) {
  589             hue -= 1.0f;
  590         }
  591         // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before)
  592         Color::hsv2rgb01(hue, float(valX), value, R, G, B);
  593     } else if (callerId == 3) {  // lc - bottom bar
  594         float value = (1.f - 0.7f) * float(valX) + 0.7f;
  595         if (lcredsk->get_active()) {
  596             // skin range
  597             // -0.1 rad < Hue < 1.6 rad
  598             // Y axis / from 0.92 up to 0.14056
  599             float hue = (1.14056f - 0.92f) * float(valY) + 0.92f;
  600             if (hue > 1.0f) {
  601                 hue -= 1.0f;
  602             }
  603             // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before)
  604             Color::hsv2rgb01(hue, float(valX), value, R, G, B);
  605         } else {
  606             // whole hue range
  607             // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before)
  608             Color::hsv2rgb01(float(valY*0.8), float(valX), value, R, G, B);
  609         }
  610     } else if (callerId == 4) {  // LH - bottom bar
  611         Color::hsv2rgb01(float(valX), 0.5f, float(valY), R, G, B);
  612     } else if (callerId == 5) {  // HH - bottom bar
  613         float h = float((valY - 0.5) * 0.3 + valX);
  614         if (h > 1.0f) {
  615             h -= 1.0f;
  616         } else if (h < 0.0f) {
  617             h += 1.0f;
  618         }
  619         Color::hsv2rgb01(h, 0.5f, 0.5f, R, G, B);
  620     } else if (callerId == 7) {  // cc and cl - left bar
  621         float value = (1.f - 0.7f) * float(valX) + 0.7f;
  622         // whole hue range
  623         // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before)
  624         Color::hsv2rgb01(float(valY*0.8), 1.f - float(valX), value, R, G, B);
  625     }
  626 
  627     caller->ccRed = double(R);
  628     caller->ccGreen = double(G);
  629     caller->ccBlue = double(B);
  630 }
  631 
  632 void LCurve::setBatchMode (bool batchMode)
  633 {
  634 
  635     ToolPanel::setBatchMode (batchMode);
  636     brightness->showEditedCB ();
  637     contrast->showEditedCB ();
  638     chromaticity->showEditedCB ();
  639     rstprotection->showEditedCB ();
  640     curveEditorG->setBatchMode (batchMode);
  641     lcshape->setBottomBarColorProvider(nullptr, -1);
  642     lcshape->setLeftBarColorProvider(nullptr, -1);
  643 }
  644 
  645 
  646 void LCurve::updateCurveBackgroundHistogram(
  647     const LUTu& histToneCurve,
  648     const LUTu& histLCurve,
  649     const LUTu& histCCurve,
  650     const LUTu& histLCAM,
  651     const LUTu& histCCAM,
  652     const LUTu& histRed,
  653     const LUTu& histGreen,
  654     const LUTu& histBlue,
  655     const LUTu& histLuma,
  656     const LUTu& histLRETI
  657 )
  658 {
  659     lshape->updateBackgroundHistogram (histLCurve);
  660     ccshape->updateBackgroundHistogram (histCCurve);
  661 }
  662 
  663 void LCurve::setAdjusterBehavior (bool bradd, bool contradd, bool satadd)
  664 {
  665 
  666     brightness->setAddMode(bradd);
  667     contrast->setAddMode(contradd);
  668     chromaticity->setAddMode(satadd);
  669 }
  670 
  671 void LCurve::trimValues (rtengine::procparams::ProcParams* pp)
  672 {
  673 
  674     brightness->trimValue(pp->labCurve.brightness);
  675     contrast->trimValue(pp->labCurve.contrast);
  676     chromaticity->trimValue(pp->labCurve.chromaticity);
  677 }
  678 
  679 void LCurve::enabledChanged()
  680 {
  681     if (listener) {
  682         if (get_inconsistent()) {
  683             listener->panelChanged (EvLEnabled, M("GENERAL_UNCHANGED"));
  684         } else if (getEnabled()) {
  685             listener->panelChanged (EvLEnabled, M("GENERAL_ENABLED"));
  686         } else {
  687             listener->panelChanged (EvLEnabled, M("GENERAL_DISABLED"));
  688         }
  689     }
  690 }