From e894794e1a9ba312de945d325d824787589429bd Mon Sep 17 00:00:00 2001 From: jdc Date: Thu, 18 Sep 2014 07:25:31 +0200 Subject: [PATCH] Color toning - set opacity to linear does not turns color toning off - issue2014 --- rtengine/curves.cc | 4 ++-- rtengine/curves.h | 2 +- rtengine/dcrop.cc | 2 +- rtengine/improccoordinator.cc | 11 +++++++---- rtengine/improccoordinator.h | 1 + rtengine/improcfun.cc | 26 +++++++++++++------------- rtengine/improcfun.h | 4 ++-- rtengine/procparams.cc | 8 ++++---- rtengine/procparams.h | 2 +- rtengine/rtthumbnail.cc | 5 +++-- rtengine/simpleprocess.cc | 5 +++-- 11 files changed, 38 insertions(+), 32 deletions(-) diff --git a/rtengine/curves.cc b/rtengine/curves.cc index 1c80af035..5b127e8cc 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -1166,7 +1166,7 @@ void OpacityCurve::Set(const Curve *pCurve) { //lutOpacityCurve.dump("opacity"); } -void OpacityCurve::Set(const std::vector &curvePoints) { +void OpacityCurve::Set(const std::vector &curvePoints, bool &opautili) { FlatCurve* tcurve = NULL; if (!curvePoints.empty() && curvePoints[0]>FCT_Linear && curvePoints[0] &curvePoints) { tcurve->setIdentityValue(0.); } if (tcurve) { - Set(tcurve); + Set(tcurve);opautili=true; delete tcurve; tcurve = NULL; } diff --git a/rtengine/curves.h b/rtengine/curves.h index 5e0ecbc7b..da06d4f92 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -335,7 +335,7 @@ class OpacityCurve { void Reset(); void Set(const Curve *pCurve); - void Set(const std::vector &curvePoints); + void Set(const std::vector &curvePoints, bool &opautili); // TODO: transfer this method to the Color class... float blend (float x, float lower, float upper) const { diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 080291819..046539555 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -239,7 +239,7 @@ void Crop::update (int todo) { if (todo & M_RGBCURVE) parent->ipf.rgbProc (baseCrop, laboCrop, this, parent->hltonecurve, parent->shtonecurve, parent->tonecurve, cshmap, - params.toneCurve.saturation, parent->rCurve, parent->gCurve, parent->bCurve, satLimit ,satLimitOpacity, parent->ctColorCurve, parent->ctOpacityCurve, parent->clToningcurve,parent->cl2Toningcurve, + params.toneCurve.saturation, parent->rCurve, parent->gCurve, parent->bCurve, satLimit ,satLimitOpacity, parent->ctColorCurve, parent->ctOpacityCurve, parent->opautili, parent->clToningcurve,parent->cl2Toningcurve, parent->customToneCurve1, parent->customToneCurve2, parent->beforeToneCurveBW, parent->afterToneCurveBW,rrm, ggm, bbm, parent->bwAutoR, parent->bwAutoG, parent->bwAutoB); diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 5069c6ae8..978fcd5f0 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -83,7 +83,7 @@ ImProcCoordinator::ImProcCoordinator () pW(-1), pH(-1), plistener(NULL), imageListener(NULL), aeListener(NULL), hListener(NULL),acListener(NULL), abwListener(NULL),actListener(NULL), - resultValid(false), changeSinceLast(0), updaterRunning(false), destroying(false),utili(false),autili(false),lldenoiseutili(false), + resultValid(false), changeSinceLast(0), updaterRunning(false), destroying(false),utili(false),autili(false),lldenoiseutili(false), opautili(false), butili(false),ccutili(false),cclutili(false),clcutili(false),fullw(1),fullh(1) {} @@ -356,8 +356,11 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) { {wiprof[1][0],wiprof[1][1],wiprof[1][2]}, {wiprof[2][0],wiprof[2][1],wiprof[2][2]} }; - params.colorToning.getCurves(ctColorCurve, ctOpacityCurve, wp, wip); - + opautili=false; + params.colorToning.getCurves(ctColorCurve, ctOpacityCurve, wp, wip, opautili); + if(opautili) printf("OPA OUI\n"); + if(!opautili) printf("OPA NON\n"); + bool clctoningutili=false; bool llctoningutili=false; CurveFactory::curveToningCL(clctoningutili, params.colorToning.clcurve, clToningcurve,scale==1 ? 1 : 16); @@ -412,7 +415,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) { // if it's just crop we just need the histogram, no image updates if ( todo & M_RGBCURVE ) { ipf.rgbProc (oprevi, oprevl, NULL, hltonecurve, shtonecurve, tonecurve, shmap, params.toneCurve.saturation, - rCurve, gCurve, bCurve, satLimit ,satLimitOpacity, ctColorCurve, ctOpacityCurve, clToningcurve, cl2Toningcurve, customToneCurve1, customToneCurve2,beforeToneCurveBW, afterToneCurveBW, rrm, ggm, bbm, bwAutoR, bwAutoG, bwAutoB, params.toneCurve.expcomp, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh); + rCurve, gCurve, bCurve, satLimit ,satLimitOpacity, ctColorCurve, ctOpacityCurve, opautili, clToningcurve, cl2Toningcurve, customToneCurve1, customToneCurve2,beforeToneCurveBW, afterToneCurveBW, rrm, ggm, bbm, bwAutoR, bwAutoG, bwAutoB, params.toneCurve.expcomp, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh); if(params.blackwhite.enabled && params.blackwhite.autoc && abwListener) { if (settings->verbose) printf("ImProcCoordinator / Auto B&W coefs: R=%.2f G=%.2f B=%.2f\n", bwAutoR, bwAutoG, bwAutoB); diff --git a/rtengine/improccoordinator.h b/rtengine/improccoordinator.h index 52bb630fc..3ab5bc9b8 100644 --- a/rtengine/improccoordinator.h +++ b/rtengine/improccoordinator.h @@ -121,6 +121,7 @@ class ImProcCoordinator : public StagedImageProcessor { bool cclutili; bool clcutili; bool lldenoiseutili; + bool opautili; ToneCurve customToneCurve1; ToneCurve customToneCurve2; ColorGradientCurve ctColorCurve; diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index d7c1c6518..fc9247bfc 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -2134,14 +2134,14 @@ float mo=0.f; void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *editBuffer, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, - SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit ,float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, LUTf & clToningcurve,LUTf & cl2Toningcurve, + SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit ,float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, bool opautili, LUTf & clToningcurve,LUTf & cl2Toningcurve, const ToneCurve & customToneCurve1,const ToneCurve & customToneCurve2, const ToneCurve & customToneCurvebw1,const ToneCurve & customToneCurvebw2, double &rrm, double &ggm, double &bbm, float &autor, float &autog, float &autob ) { - rgbProc (working, lab, editBuffer, hltonecurve, shtonecurve, tonecurve, shmap, sat, rCurve, gCurve, bCurve, satLimit ,satLimitOpacity, ctColorCurve, ctOpacityCurve, clToningcurve, cl2Toningcurve,customToneCurve1, customToneCurve2, customToneCurvebw1, customToneCurvebw2,rrm, ggm, bbm, autor, autog, autob, params->toneCurve.expcomp, params->toneCurve.hlcompr, params->toneCurve.hlcomprthresh); + rgbProc (working, lab, editBuffer, hltonecurve, shtonecurve, tonecurve, shmap, sat, rCurve, gCurve, bCurve, satLimit ,satLimitOpacity, ctColorCurve, ctOpacityCurve, opautili, clToningcurve, cl2Toningcurve,customToneCurve1, customToneCurve2, customToneCurvebw1, customToneCurvebw2,rrm, ggm, bbm, autor, autog, autob, params->toneCurve.expcomp, params->toneCurve.hlcompr, params->toneCurve.hlcomprthresh); } // Process RGB image and convert to LAB space void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *editBuffer, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, - SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit ,float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, LUTf & clToningcurve,LUTf & cl2Toningcurve, + SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit ,float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, bool opautili, LUTf & clToningcurve,LUTf & cl2Toningcurve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, const ToneCurve & customToneCurvebw1,const ToneCurve & customToneCurvebw2,double &rrm, double &ggm, double &bbm, float &autor, float &autog, float &autob, double expcomp, int hlcompr, int hlcomprthresh) { LUTf iGammaLUTf; @@ -2300,7 +2300,6 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *e bool hasToneCurvebw2 = bool(customToneCurvebw2); bool hasColorToning = params->colorToning.enabled && bool(ctOpacityCurve) && bool(ctColorCurve); - // float satLimit = float(params->colorToning.satProtectionThreshold)/100.f*0.7f+0.3f; // float satLimitOpacity = 1.f-(float(params->colorToning.saturatedOpacity)/100.f); float strProtect = (float(params->colorToning.strength)/100.f); @@ -2967,13 +2966,13 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *e rtemp[ti*TS+tj]=ro; gtemp[ti*TS+tj]=go; btemp[ti*TS+tj]=bo; - } + } } //#endif } //colortoning with shift color XYZ or Lch - else if (params->colorToning.method=="Lab") { + else if (params->colorToning.method=="Lab" && opautili) { int algm=0; bool twocol = true;//true=500 color false=2 color int metchrom; @@ -3010,7 +3009,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *e } } } - else if (params->colorToning.method.substr(0,3)=="RGB") { + else if (params->colorToning.method.substr(0,3)=="RGB" && opautili) { // color toning for (int i=istart,ti=0; i(s/satLimit, 1.f)*(1.f-satLimitOpacity)) * ctOpacityCurve.lutOpacityCurve[l_*500.f]; - + float opacity; + if(ctOpacityCurve) opacity = (1.f-min(s/satLimit, 1.f)*(1.f-satLimitOpacity)) * ctOpacityCurve.lutOpacityCurve[l_*500.f]; + if(!ctOpacityCurve) opacity=0.f; float r2, g2, b2; ctColorCurve.getVal(l_, r2, g2, b2); // get the color from the color curve @@ -3555,7 +3555,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *e } //colortoning with shift color Lab - else if (params->colorToning.method=="Lab") { + else if (params->colorToning.method=="Lab" && opautili) { int algm=0; bool twocol = true; int metchrom; @@ -3598,7 +3598,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *e } } - else if (params->colorToning.method.substr(0,3)=="RGB") { + else if (params->colorToning.method.substr(0,3)=="RGB" && opautili) { // color toning #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 5) @@ -4209,8 +4209,8 @@ void ImProcFunctions::labtoning (float r, float g, float b, float &ro, float &go // get the opacity and tweak it to preserve saturated colors //float l_ = Color::gamma_srgb(l*65535.f)/65535.f; - float opacity = (1.f-min(s/satLimit, 1.f)*(1.f-satLimitOpacity)) * ctOpacityCurve.lutOpacityCurve[l*500.f]; - + float opacity; + opacity = (1.f-min(s/satLimit, 1.f)*(1.f-satLimitOpacity)) * ctOpacityCurve.lutOpacityCurve[l*500.f]; float opacity2 = (1.f-min(s/satLimit, 1.f)*(1.f-satLimitOpacity)); //float ro, go, bo; diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 5c90ef594..f6c41dc15 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -195,10 +195,10 @@ class ImProcFunctions { void firstAnalysis (Imagefloat* working, const ProcParams* params, LUTu & vhist16, double gamma); void rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *editBuffer, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, - SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit , float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve,LUTf & clcurve, LUTf & cl2curve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, + SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit , float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, bool opautili, LUTf & clcurve, LUTf & cl2curve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, const ToneCurve & customToneCurvebw1,const ToneCurve & customToneCurvebw2, double &rrm, double &ggm, double &bbm, float &autor, float &autog, float &autob); void rgbProc (Imagefloat* working, LabImage* lab, EditBuffer *editBuffer, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, - SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit , float satLimitOpacity,const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, LUTf & clcurve, LUTf & cl2curve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, + SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit , float satLimitOpacity,const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, bool opautili, LUTf & clcurve, LUTf & cl2curve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, const ToneCurve & customToneCurvebw1,const ToneCurve & customToneCurvebw2, double &rrm, double &ggm, double &bbm, float &autor, float &autog, float &autob, double expcomp, int hlcompr, int hlcomprthresh); void labtoning (float r, float g, float b, float &ro, float &go, float &bo, int algm, int metchrom, int twoc, float satLimit, float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, LUTf & clToningcurve,LUTf & cl2Toningcurve, float iplow, float iphigh, double wp[3][3], double wip[3][3] ); diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 868d4b94d..e1cedb572 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -383,7 +383,7 @@ void ColorToningParams::slidersToCurve(std::vector &colorCurve, std::vec opacityCurve.at(8) = 0.35; } -void ColorToningParams::getCurves(ColorGradientCurve &colorCurveLUT, OpacityCurve &opacityCurveLUT, const double xyz_rgb[3][3], const double rgb_xyz[3][3]) const { +void ColorToningParams::getCurves(ColorGradientCurve &colorCurveLUT, OpacityCurve &opacityCurveLUT, const double xyz_rgb[3][3], const double rgb_xyz[3][3], bool &opautili) const { float satur=0.8f; float lumin=0.5f;//middle of luminance for optimization of gamut - no real importance...as we work in XYZ and gamut control @@ -402,15 +402,15 @@ void ColorToningParams::getCurves(ColorGradientCurve &colorCurveLUT, OpacityCurv if(twocolor=="Separ") satur=0.9f; if(twocolor=="All" || twocolor=="Two") satur=0.9f; colorCurveLUT.SetXYZ(cCurve, xyz_rgb, rgb_xyz, satur, lumin); - opacityCurveLUT.Set(oCurve); + opacityCurveLUT.Set(oCurve, opautili); } else if(method=="Splitlr" || method=="Splitco") { colorCurveLUT.SetXYZ(cCurve, xyz_rgb, rgb_xyz, satur, lumin); - opacityCurveLUT.Set(oCurve); + opacityCurveLUT.Set(oCurve, opautili); } else if(method.substr(0,3)=="RGB") { colorCurveLUT.SetRGB(cCurve, xyz_rgb, rgb_xyz); - opacityCurveLUT.Set(oCurve); + opacityCurveLUT.Set(oCurve, opautili); } } diff --git a/rtengine/procparams.h b/rtengine/procparams.h index 68d16e45a..bc630ef98 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -307,7 +307,7 @@ class ColorToningParams { /// @brief Specifically transform the sliders values to their curve equivalences void slidersToCurve(std::vector &colorCurve, std::vector &opacityCurve) const; /// @brief Fill the ColorGradientCurve and OpacityCurve LUTf from the control points curve or sliders value - void getCurves(ColorGradientCurve &colorCurveLUT, OpacityCurve &opacityCurveLUT, const double xyz_rgb[3][3], const double rgb_xyz[3][3]) const; + void getCurves(ColorGradientCurve &colorCurveLUT, OpacityCurve &opacityCurveLUT, const double xyz_rgb[3][3], const double rgb_xyz[3][3], bool &opautili) const; static void getDefaultColorCurve(std::vector &curve); static void getDefaultOpacityCurve(std::vector &curve); diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 0f2325afd..6a0ea177b 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -866,7 +866,8 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, int rhei {wiprof[1][0],wiprof[1][1],wiprof[1][2]}, {wiprof[2][0],wiprof[2][1],wiprof[2][2]} }; - params.colorToning.getCurves(ctColorCurve, ctOpacityCurve, wp, wip); + bool opautili=false; + params.colorToning.getCurves(ctColorCurve, ctOpacityCurve, wp, wip, opautili); //params.dirpyrDenoise.getCurves(dnNoisCurve, lldenoisutili); LabImage* labView = new LabImage (fw,fh); @@ -898,7 +899,7 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, int rhei } autor = autog = autob = -9000.f; // This will ask to compute the "auto" values for the B&W tool - ipf.rgbProc (baseImg, labView, NULL, curve1, curve2, curve, shmap, params.toneCurve.saturation, rCurve, gCurve, bCurve, satLimit ,satLimitOpacity, ctColorCurve, ctOpacityCurve, clToningcurve, cl2Toningcurve, customToneCurve1, customToneCurve2, customToneCurvebw1, customToneCurvebw2,rrm, ggm, bbm, autor, autog, autob, expcomp, hlcompr, hlcomprthresh); + ipf.rgbProc (baseImg, labView, NULL, curve1, curve2, curve, shmap, params.toneCurve.saturation, rCurve, gCurve, bCurve, satLimit ,satLimitOpacity, ctColorCurve, ctOpacityCurve, opautili, clToningcurve, cl2Toningcurve, customToneCurve1, customToneCurve2, customToneCurvebw1, customToneCurvebw2,rrm, ggm, bbm, autor, autog, autob, expcomp, hlcompr, hlcomprthresh); // freeing up some memory customToneCurve1.Reset(); diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 67faf44c2..0a6bc6912 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -240,7 +240,8 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p {wiprof[1][0],wiprof[1][1],wiprof[1][2]}, {wiprof[2][0],wiprof[2][1],wiprof[2][2]} }; - params.colorToning.getCurves(ctColorCurve, ctOpacityCurve, wp, wip); + bool opautili=false; + params.colorToning.getCurves(ctColorCurve, ctOpacityCurve, wp, wip, opautili); bool clctoningutili=false; CurveFactory::curveToningCL(clctoningutili, params.colorToning.clcurve, clToningcurve, 1); @@ -271,7 +272,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p } autor = -9000.f; // This will ask to compute the "auto" values for the B&W tool (have to be inferior to -5000) - ipf.rgbProc (baseImg, labView, NULL, curve1, curve2, curve, shmap, params.toneCurve.saturation, rCurve, gCurve, bCurve, satLimit ,satLimitOpacity, ctColorCurve, ctOpacityCurve, clToningcurve, cl2Toningcurve,customToneCurve1, customToneCurve2,customToneCurvebw1, customToneCurvebw2, rrm, ggm, bbm, autor, autog, autob, expcomp, hlcompr, hlcomprthresh); + ipf.rgbProc (baseImg, labView, NULL, curve1, curve2, curve, shmap, params.toneCurve.saturation, rCurve, gCurve, bCurve, satLimit ,satLimitOpacity, ctColorCurve, ctOpacityCurve, opautili, clToningcurve, cl2Toningcurve,customToneCurve1, customToneCurve2,customToneCurvebw1, customToneCurvebw2, rrm, ggm, bbm, autor, autog, autob, expcomp, hlcompr, hlcomprthresh); if (settings->verbose) printf("Output image / Auto B&W coefs: R=%.2f G=%.2f B=%.2f\n", autor, autog, autob);