diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 3b1ebfdab..731eca086 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -1011,6 +1011,8 @@ void Crop::update(int todo) parent->ipf.ip_wavelet(labnCrop, labnCrop, kall, WaveParams, wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL, parent->wavclCurve, skip); } + parent->ipf.softLight(labnCrop); + // } // } diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 5cc93d3c7..2aaf018fb 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -792,7 +792,8 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) } - + ipf.softLight(nprevl); + if (params.colorappearance.enabled) { //L histo and Chroma histo for ciecam // histogram well be for Lab (Lch) values, because very difficult to do with J,Q, M, s, C diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 7d9d080e2..57475af9c 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -3186,7 +3186,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } } - softLight(rtemp, gtemp, btemp, istart, jstart, tW, tH, TS); + //softLight(rtemp, gtemp, btemp, istart, jstart, tW, tH, TS); if (!blackwhite) { if (editImgFloat || editWhatever) { diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index a97ecef40..066d1e306 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -343,7 +343,7 @@ public: void localContrast(LabImage *lab); void colorToningLabGrid(LabImage *lab, int xstart, int xend, int ystart, int yend, bool MultiThread); void shadowsHighlights(LabImage *lab); - void softLight(float *red, float *green, float *blue, int istart, int jstart, int tW, int tH, int TS); + void softLight(LabImage *lab); Image8* lab2rgb(LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool consider_histogram_settings = true); Imagefloat* lab2rgbOut(LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm); diff --git a/rtengine/ipsoftlight.cc b/rtengine/ipsoftlight.cc index 35bf9577a..74fb543aa 100644 --- a/rtengine/ipsoftlight.cc +++ b/rtengine/ipsoftlight.cc @@ -26,48 +26,49 @@ namespace rtengine { -void ImProcFunctions::softLight(float *red, float *green, float *blue, int istart, int jstart, int tW, int tH, int TS) +namespace { + +inline float sl(float blend, float x) +{ + if (!OOG(x)) { + const float orig = 1.f - blend; + float v = Color::gamma_srgb(x) / MAXVALF; + // Pegtop's formula from + // https://en.wikipedia.org/wiki/Blend_modes#Soft_Light + float v2 = v * v; + float v22 = v2 * 2.f; + v = v2 + v22 - v22 * v; + x = blend * Color::igamma_srgb(v * MAXVALF) + orig * x; + } + return x; +} + +} // namespace + + +void ImProcFunctions::softLight(LabImage *lab) { if (!params->softlight.enabled || !params->softlight.strength) { return; } + Imagefloat working(lab->W, lab->H); + lab2rgb(*lab, working, params->icm.workingProfile); + const float blend = params->softlight.strength / 100.f; - const float orig = 1.f - blend; - - const auto apply = - [=](float x) -> float - { - if (!OOG(x)) { - float v = Color::gamma_srgb(x) / MAXVALF; - // Pegtop's formula from - // https://en.wikipedia.org/wiki/Blend_modes#Soft_Light - float v2 = v * v; - float v22 = v2 * 2.f; - v = v2 + v22 - v22 * v; - x = blend * Color::igamma_srgb(v * MAXVALF) + orig * x; - } - return x; - }; #ifdef _OPENMP - #pragma omp parallel if (multiThread) + #pragma omp parallel for #endif - { - int ti = 0; -#ifdef _OPENMP - #pragma omp for -#endif - for (int i = istart; i < tH; i++) { - for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const int idx = ti * TS + tj; - red[idx] = apply(red[idx]); - green[idx] = apply(green[idx]); - blue[idx] = apply(blue[idx]); - } - ++ti; + for (int y = 0; y < working.getHeight(); ++y) { + for (int x = 0; x < working.getWidth(); ++x) { + working.r(y, x) = sl(blend, working.r(y, x)); + working.g(y, x) = sl(blend, working.g(y, x)); + working.b(y, x) = sl(blend, working.b(y, x)); } } + + rgb2lab(working, *lab, params->icm.workingProfile); } } // namespace rtengine diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 79dee36bf..afd8836a1 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -1368,6 +1368,8 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT ipf.EPDToneMap (labView, 5, 6); } + ipf.softLight(labView); + if (params.colorappearance.enabled) { CurveFactory::curveLightBrightColor ( params.colorappearance.curve, diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 06e2b13bf..24301e129 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -1135,6 +1135,8 @@ private: wavCLVCurve.Reset(); + ipf.softLight(labView); + //Colorappearance and tone-mapping associated int f_w = 1, f_h = 1; diff --git a/rtgui/softlight.cc b/rtgui/softlight.cc index 0ee4c64b9..072c45e98 100644 --- a/rtgui/softlight.cc +++ b/rtgui/softlight.cc @@ -28,8 +28,8 @@ using namespace rtengine::procparams; SoftLight::SoftLight(): FoldableToolPanel(this, "softlight", M("TP_SOFTLIGHT_LABEL"), false, true) { auto m = ProcEventMapper::getInstance(); - EvSoftLightEnabled = m->newEvent(RGBCURVE, "HISTORY_MSG_SOFTLIGHT_ENABLED"); - EvSoftLightStrength = m->newEvent(RGBCURVE, "HISTORY_MSG_SOFTLIGHT_STRENGTH"); + EvSoftLightEnabled = m->newEvent(LUMINANCECURVE, "HISTORY_MSG_SOFTLIGHT_ENABLED"); + EvSoftLightStrength = m->newEvent(LUMINANCECURVE, "HISTORY_MSG_SOFTLIGHT_STRENGTH"); strength = Gtk::manage(new Adjuster(M("TP_SOFTLIGHT_STRENGTH"), 0., 100., 1., 30.)); strength->setAdjusterListener(this);