diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index aed4cce33..84f05bba5 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,11 +1,11 @@ -RAWTHERAPEE 5 DEVELOPMENT RELEASE NOTES ---------------------------------------- +RAWTHERAPEE 5.1-dev RELEASE NOTES +--------------------------------- +This is a development version of RawTherapee. We update the code almost daily. Every few months, once enough changes have accumulated and the code is stabilized, we make a new official release. Every code change between these releases is known as a "development" version, and this is one of them. + RawTherapee provides you with a selection of powerful tools with which you can practice the art of developing raw photos. Be sure to read RawPedia to understand how each tool works so that you may make the most of it. http://rawpedia.rawtherapee.com/ A great place to start is the "Getting Started" article. Click on "Main page" in the top-left corner when you have finished reading that article to see all other articles. -This is a development version of RawTherapee. We update the code almost daily. Every few months, once enough changes have accumulated and the code is stabilized, we make a new official release. Every code change between these releases is known as a "development" version, and this is one of them. - While we only commit tested and relatively stable code and so the development versions should be fairly stable, you should be aware that: - Development versions only had limited testing, so there may be bugs unknown to us. - You should report these bugs so that they get fixed for the next stable release. See @@ -15,7 +15,7 @@ While we only commit tested and relatively stable code and so the development ve News Relevant to Photographers ------------------------------ -- RawTherapee 5 supports most raw formats, including some unusual ones like those from cameras using Foveon and X-Trans sensors. If you're wondering whether it supports your camera's raw format, first download RawTherapee 5 and try for yourself. If a raw format is not supported it will either not open, or the preview in the Editor tab will appear black, white, or have a strong color cast - usually magenta. In that case, read the "Adding Support for New Raw Formats" RawPedia article. +- RawTherapee supports most raw formats, including some unusual ones like those from cameras using Foveon and X-Trans sensors. If you're wondering whether it supports your camera's raw format, first download RawTherapee and try for yourself. If a raw format is not supported it will either not open, or the preview in the Editor tab will appear black, white, or have a strong color cast - usually magenta. In that case, read the "Adding Support for New Raw Formats" RawPedia article. In order to use RawTherapee efficiently you should know that: - You can scroll all panels using the mouse scroll-wheel. @@ -24,27 +24,27 @@ In order to use RawTherapee efficiently you should know that: - All curves support the Shift and Ctrl keys while dragging a point. Shift+drag makes the point snap to meaningful axes (top, bottom, diagonal, other), while Ctrl+drag makes your mouse movement super-fine for precise point positioning. - There are many keyboard shortcuts which make working with RawTherapee much faster and give you greater control. Make sure you familiarize yourself with them on RawPedia's "Keyboard Shortcuts" page! -New features since 5.0-r1: -- +New features since 5.1: +- This section will be completed when 5.2 is released. News Relevant to Package Maintainers ------------------------------------ -- To get the latest development version, use the "dev" branch. -- All development now uses GTK3, requiring version >=3.16. There are known bugs using GTK+ versions 3.20-3.22 where scrollbars may appear stuck (issue #3545) and where the Retinex tool's "Gain and Offset" panel may appear under the "Transmission" panel (issue #3525) until the user hovers the mouse cursor over a curve button. For this reason we recommend using GTK+ 3.16-3.18 if possible. -- GTK2 is no longer supported. Use branch "gtk2" if you want to compile a GTK2 version, but remember that there will be no improvements to it after 5.0-r1. +- No significant changes since 5.1. +- Requires GTK+ version >=3.16. +- GTK2 is not supported. 5.0-r1 was the last GTK2 release. - Branches "master" and "gtk3" are dead, do not use them. - RawTherapee 5 requires GCC-4.9 or higher, or Clang. - Do not use -ffast-math, it will not make RawTherapee faster but will introduce artifacts. -- Use -o3, it will make RawTherapee faster with no known side-effects. -- For stable builds (RT5) use -DCACHE_NAME_SUFFIX="" -- For development builds use -DCACHE_NAME_SUFFIX="5-dev" -- Windows builders should compile on a drive letter which users are most unlikely to have, such as Y:, due to the "There is no disk in the drive" error (issue #3544). +- Use -O3, it will make RawTherapee faster with no known side-effects. +- For stable releases use -DCACHE_NAME_SUFFIX="" +- For development builds and release-candidates use -DCACHE_NAME_SUFFIX="5-dev" News Relevant to Developers --------------------------- -- Use C++11 +- Announce and discuss your plans in GitHub before starting work. +- Keep branches small so that completed and working features can be merged into the "dev" branch often, and so that they can be abandoned if they head in the wrong direction. +- Use C++11. - Code must be run through astyle. -- Commits automatically trigger a compilation using Travis CI. DOCUMENTATION ------------- @@ -59,8 +59,8 @@ http://rawpedia.rawtherapee.com/How_to_write_useful_bug_reports LIVE CHAT WITH USERS AND DEVELOPERS -------------------------------------- Network: freenode - Server: chat.freenode.net - Channel #rawtherapee + Server: chat.freenode.net + Channel: #rawtherapee You can use freenode webchat to communicate without installing anything: http://webchat.freenode.net/?randomnick=1&channels=rawtherapee&prompt=1 diff --git a/doc/manpage/rawtherapee.1 b/doc/manpage/rawtherapee.1 index bbd2a4f44..5e3024a99 100644 --- a/doc/manpage/rawtherapee.1 +++ b/doc/manpage/rawtherapee.1 @@ -1,4 +1,4 @@ -.TH RAWTHERAPEE 1 "July 05, 2016" +.TH RAWTHERAPEE 1 "May 10, 2017" .SH NAME RawTherapee - An advanced, cross-platform program for developing raw photos. .SH DESCRIPTION @@ -14,11 +14,14 @@ RawTherapee - An advanced, cross-platform program for developing raw photos. The pipe symbol | indicates a choice of one or the other. The dash symbol - denotes a range of possible values from one to the other. .SH SYNOPSIS + RawTherapee GUI rawtherapee Start File Browser inside folder. rawtherapee Start Image Editor with file. - rawtherapee -c | Convert files in batch with default parameters. - rawtherapee -c | Convert files in batch with your own settings. - rawtherapee [-o |-O ] [-s|-S] [-p [-p ...] ] [-d] [ -j[1-100] [-js<1-3>] | [-b<8|16>] [-t[z] | [-n]] ] [-Y] -c + + RawTherapee CLI + rawtherapee-cli -c | Convert files in batch using default parameters. + rawtherapee-cli -c | Convert files in batch using your own settings. + rawtherapee-cli [-o |-O ] [-q] [-a] [-s|-S] [-p [-p ...] ] [-d] [ -j[1-100] [-js<1-3>] | [-b<8|16>] [-t[z] | [-n]] ] [-Y] -c .SH OPTIONS -c Specify one or more input files. -c must be the last option. @@ -26,6 +29,9 @@ RawTherapee - An advanced, cross-platform program for developing raw photos. Saves output file alongside input file if -o is not specified. -O | Set output file or folder and copy pp3 file into it. Saves output file alongside input file if -O is not specified. + -q Quick-start mode. Does not load cached files to speedup start time. + -a Process all supported image file types when specifying a folder, even those + not currently selected in Preferences > File Browser > Parsed Extensions. -s Use the existing sidecar file to build the processing parameters, e.g. for photo.raw there should be a photo.raw.pp3 file in the same folder. If the sidecar file does not exist, neutral values will be used. diff --git a/rtdata/images/rt_splash_5.svg b/rtdata/images/rt_splash.svg similarity index 65% rename from rtdata/images/rt_splash_5.svg rename to rtdata/images/rt_splash.svg index 8f556f37e..d860798bd 100644 --- a/rtdata/images/rt_splash_5.svg +++ b/rtdata/images/rt_splash.svg @@ -15,328 +15,15 @@ id="svg2" version="1.1" inkscape:version="0.91 r13725" - sodipodi:docname="rt_splash_5.svg" + sodipodi:docname="rt_splash.svg" style="enable-background:new" - inkscape:export-filename="/tmp/rt_splash_5.png" + inkscape:export-filename="/tmp/rt_splash_51-dev.png" inkscape:export-xdpi="90" inkscape:export-ydpi="90"> RawTherapee Splash Screen - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 + .1 + + Development + & p, int poly_pn) x[i] = p[ix++]; y[i] = p[ix++]; - if (x[i] != y[i]) { + if (std::fabs(x[i] - y[i]) >= 0.000009) { + // the smallest possible difference between x and y curve point values is ~ 0.00001 + // checking against >= 0.000009 is a bit saver than checking against >= 0.00001 identity = false; } } diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index c68158634..5c96aa6fd 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -78,6 +78,7 @@ void ImProcFunctions::updateColorProfiles (const Glib::ustring& monitorProfile, monitorTransform = nullptr; cmsHPROFILE monitor = nullptr; + if (!monitorProfile.empty()) { #if !defined(__APPLE__) // No support for monitor profiles on OS X, all data is sRGB monitor = ICCStore::getInstance()->getProfile (monitorProfile); @@ -90,32 +91,37 @@ void ImProcFunctions::updateColorProfiles (const Glib::ustring& monitorProfile, MyMutex::MyLock lcmsLock (*lcmsMutex); cmsUInt32Number flags; - cmsHPROFILE iprof = cmsCreateLab4Profile(nullptr); + cmsHPROFILE iprof = cmsCreateLab4Profile (nullptr); bool softProofCreated = false; if (softProof) { cmsHPROFILE oprof = nullptr; + if (!settings->printerProfile.empty()) { - oprof = ICCStore::getInstance()->getProfile(settings->printerProfile); + oprof = ICCStore::getInstance()->getProfile (settings->printerProfile); } if (oprof) { // NOCACHE is for thread safety, NOOPTIMIZE for precision flags = cmsFLAGS_SOFTPROOFING | cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE; + if (settings->printerBPC) { flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } + if (gamutCheck) { flags |= cmsFLAGS_GAMUTCHECK; } - monitorTransform = cmsCreateProofingTransform( - iprof, TYPE_Lab_FLT, - monitor, TYPE_RGB_8, - oprof, - monitorIntent, settings->printerIntent, - flags - ); + + monitorTransform = cmsCreateProofingTransform ( + iprof, TYPE_Lab_FLT, + monitor, TYPE_RGB_8, + oprof, + monitorIntent, settings->printerIntent, + flags + ); + if (monitorTransform) { softProofCreated = true; } @@ -124,13 +130,15 @@ void ImProcFunctions::updateColorProfiles (const Glib::ustring& monitorProfile, if (!softProofCreated) { flags = cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE; + if (settings->monitorBPC) { flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } + monitorTransform = cmsCreateTransform (iprof, TYPE_Lab_FLT, monitor, TYPE_RGB_8, monitorIntent, flags); } - cmsCloseProfile(iprof); + cmsCloseProfile (iprof); } } @@ -145,19 +153,19 @@ void ImProcFunctions::firstAnalysis (const Imagefloat* const original, const Pro int W = original->getWidth(); int H = original->getHeight(); - float lumimulf[3] = {static_cast(lumimul[0]), static_cast(lumimul[1]), static_cast(lumimul[2])}; + float lumimulf[3] = {static_cast (lumimul[0]), static_cast (lumimul[1]), static_cast (lumimul[2])}; // calculate histogram of the y channel needed for contrast curve calculation in exposure adjustments histogram.clear(); - if(multiThread) { + if (multiThread) { #ifdef _OPENMP - const int numThreads = min(max(W * H / (int)histogram.getSize(), 1), omp_get_max_threads()); + const int numThreads = min (max (W * H / (int)histogram.getSize(), 1), omp_get_max_threads()); #pragma omp parallel num_threads(numThreads) if(numThreads>1) #endif { - LUTu hist(histogram.getSize()); + LUTu hist (histogram.getSize()); hist.clear(); #ifdef _OPENMP #pragma omp for nowait @@ -166,9 +174,9 @@ void ImProcFunctions::firstAnalysis (const Imagefloat* const original, const Pro for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { - float r = original->r(i, j); - float g = original->g(i, j); - float b = original->b(i, j); + float r = original->r (i, j); + float g = original->g (i, j); + float b = original->b (i, j); int y = (lumimulf[0] * r + lumimulf[1] * g + lumimulf[2] * b); hist[y]++; @@ -182,15 +190,15 @@ void ImProcFunctions::firstAnalysis (const Imagefloat* const original, const Pro } #ifdef _OPENMP - static_cast(numThreads); // to silence cppcheck warning + static_cast (numThreads); // to silence cppcheck warning #endif } else { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { - float r = original->r(i, j); - float g = original->g(i, j); - float b = original->b(i, j); + float r = original->r (i, j); + float g = original->g (i, j); + float b = original->b (i, j); int y = (lumimulf[0] * r + lumimulf[1] * g + lumimulf[2] * b); histogram[y]++; @@ -204,7 +212,7 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh const ColorAppearance & customColCurve1, const ColorAppearance & customColCurve2, const ColorAppearance & customColCurve3, LUTu & histLCAM, LUTu & histCCAM, LUTf & CAMBrightCurveJ, LUTf & CAMBrightCurveQ, float &mean, int Iterates, int scale, bool execsharp, double &d, int scalecd, int rtt) { - if(params->colorappearance.enabled) { + if (params->colorappearance.enabled) { //int lastskip; //if(rtt==1) {lastskip=scalecd;} //not for Rtthumbnail @@ -217,15 +225,15 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh bool jp = false; //preparate for histograms CIECAM - if(pW != 1) { //only with improccoordinator - dLcurve(65536, 0); + if (pW != 1) { //only with improccoordinator + dLcurve (65536, 0); dLcurve.clear(); - hist16JCAM(65536, 0); + hist16JCAM (65536, 0); hist16JCAM.clear(); for (int i = 0; i < 32768; i++) { //# 32768*1.414 approximation maxi for chroma float val = (double)i / 32767.0; - dLcurve[i] = CLIPD(val); + dLcurve[i] = CLIPD (val); } } @@ -233,14 +241,14 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh LUTu hist16_CCAM; bool chropC = false; - if(pW != 1) { //only with improccoordinator - dCcurve(65536, 0); - hist16_CCAM(65536); + if (pW != 1) { //only with improccoordinator + dCcurve (65536, 0); + hist16_CCAM (65536); hist16_CCAM.clear(); for (int i = 0; i < 48000; i++) { //# 32768*1.414 approximation maxi for chroma float valc = (double)i / 47999.0; - dCcurve[i] = CLIPD(valc); + dCcurve[i] = CLIPD (valc); } } @@ -267,22 +275,22 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh ColorTemp::temp2mulxyz (params->wb.temperature, params->wb.green, params->wb.method, Xw, Zw); //compute white Xw Yw Zw : white current WB //viewing condition for surround - if(params->colorappearance.surround == "Average") { + if (params->colorappearance.surround == "Average") { f = 1.00; c = 0.69; nc = 1.00; f2 = 1.0, c2 = 0.69, nc2 = 1.0; - } else if(params->colorappearance.surround == "Dim") { + } else if (params->colorappearance.surround == "Dim") { f2 = 0.9; c2 = 0.59; nc2 = 0.9; f = 1.0, c = 0.69, nc = 1.0; - } else if(params->colorappearance.surround == "Dark") { + } else if (params->colorappearance.surround == "Dark") { f2 = 0.8; c2 = 0.525; nc2 = 0.8; f = 1.0, c = 0.69, nc = 1.0; - } else if(params->colorappearance.surround == "ExtremelyDark") { + } else if (params->colorappearance.surround == "ExtremelyDark") { f2 = 0.8; c2 = 0.41; nc2 = 0.8; @@ -290,7 +298,7 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh } //scene condition for surround - if(params->colorappearance.surrsource) { + if (params->colorappearance.surrsource) { f = 0.85; // if user => source image has surround very dark c = 0.55; nc = 0.85; @@ -299,12 +307,12 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh //with which algorithme if (params->colorappearance.algo == "JC") { alg = 0; - } else if(params->colorappearance.algo == "JS") { + } else if (params->colorappearance.algo == "JS") { alg = 1; - } else if(params->colorappearance.algo == "QM") { + } else if (params->colorappearance.algo == "QM") { alg = 2; algepd = true; - } else if(params->colorappearance.algo == "ALL") { + } else if (params->colorappearance.algo == "ALL") { alg = 3; algepd = true; } @@ -313,35 +321,35 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh bool needQ = (alg == 2 || alg == 3); //settings white point of output device - or illuminant viewing - if(settings->viewingdevice == 0) { + if (settings->viewingdevice == 0) { xwd = 96.42; //5000K ywd = 100.0; zwd = 82.52; - } else if(settings->viewingdevice == 1) { + } else if (settings->viewingdevice == 1) { xwd = 95.68; //5500 ywd = 100.0; zwd = 92.15; - } else if(settings->viewingdevice == 2) { + } else if (settings->viewingdevice == 2) { xwd = 95.24; //6000 ywd = 100.0; zwd = 100.81; - } else if(settings->viewingdevice == 3) { + } else if (settings->viewingdevice == 3) { xwd = 95.04; //6500 ywd = 100.0; zwd = 108.88; - } else if(settings->viewingdevice == 4) { + } else if (settings->viewingdevice == 4) { xwd = 109.85; //tungsten ywd = 100.0; zwd = 35.58; - } else if(settings->viewingdevice == 5) { + } else if (settings->viewingdevice == 5) { xwd = 99.18; //fluo F2 ywd = 100.0; zwd = 67.39; - } else if(settings->viewingdevice == 6) { + } else if (settings->viewingdevice == 6) { xwd = 95.04; //fluo F7 ywd = 100.0; zwd = 108.75; - } else if(settings->viewingdevice == 7) { + } else if (settings->viewingdevice == 7) { xwd = 100.96; //fluo F11 ywd = 100.0; zwd = 64.35; @@ -349,32 +357,32 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh //settings mean Luminance Y of output device or viewing - if(settings->viewingdevicegrey == 0) { + if (settings->viewingdevicegrey == 0) { yb2 = 5.0; - } else if(settings->viewingdevicegrey == 1) { + } else if (settings->viewingdevicegrey == 1) { yb2 = 10.0; - } else if(settings->viewingdevicegrey == 2) { + } else if (settings->viewingdevicegrey == 2) { yb2 = 15.0; - } else if(settings->viewingdevicegrey == 3) { + } else if (settings->viewingdevicegrey == 3) { yb2 = 18.0; - } else if(settings->viewingdevicegrey == 4) { + } else if (settings->viewingdevicegrey == 4) { yb2 = 23.0; - } else if(settings->viewingdevicegrey == 5) { + } else if (settings->viewingdevicegrey == 5) { yb2 = 30.0; - } else if(settings->viewingdevicegrey == 6) { + } else if (settings->viewingdevicegrey == 6) { yb2 = 40.0; } //La and la2 = ambiant luminosity scene and viewing - la = double(params->colorappearance.adapscen); + la = double (params->colorappearance.adapscen); - if(pwb == 2) { - if(params->colorappearance.autoadapscen) { + if (pwb == 2) { + if (params->colorappearance.autoadapscen) { la = adap; } } - la2 = double(params->colorappearance.adaplum); + la2 = double (params->colorappearance.adaplum); // level of adaptation double deg = (params->colorappearance.degree) / 100.0; @@ -391,20 +399,20 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh float hue = params->colorappearance.colorh; double rstprotection = 100. - params->colorappearance.rstprotection; - if(schr > 0.0) { + if (schr > 0.0) { schr = schr / 2.0f; //divide sensibility for saturation } // extracting datas from 'params' to avoid cache flush (to be confirmed) ColorAppearanceParams::eTCModeId curveMode = params->colorappearance.curveMode; ColorAppearanceParams::eTCModeId curveMode2 = params->colorappearance.curveMode2; - bool hasColCurve1 = bool(customColCurve1); - bool hasColCurve2 = bool(customColCurve2); + bool hasColCurve1 = bool (customColCurve1); + bool hasColCurve2 = bool (customColCurve2); ColorAppearanceParams::eCTCModeId curveMode3 = params->colorappearance.curveMode3; - bool hasColCurve3 = bool(customColCurve3); + bool hasColCurve3 = bool (customColCurve3); - if(CAMBrightCurveJ.dirty || CAMBrightCurveQ.dirty) { + if (CAMBrightCurveJ.dirty || CAMBrightCurveQ.dirty) { LUTu hist16J; LUTu hist16Q; @@ -428,34 +436,34 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh if (currL > 95.) { koef = 1.f; - } else if(currL > 85.) { + } else if (currL > 85.) { koef = 0.97f; - } else if(currL > 80.) { + } else if (currL > 80.) { koef = 0.93f; - } else if(currL > 70.) { + } else if (currL > 70.) { koef = 0.87f; - } else if(currL > 60.) { + } else if (currL > 60.) { koef = 0.85f; - } else if(currL > 50.) { + } else if (currL > 50.) { koef = 0.8f; - } else if(currL > 40.) { + } else if (currL > 40.) { koef = 0.75f; - } else if(currL > 30.) { + } else if (currL > 30.) { koef = 0.7f; - } else if(currL > 20.) { + } else if (currL > 20.) { koef = 0.7f; - } else if(currL > 10.) { + } else if (currL > 10.) { koef = 0.9f; - } else if(currL > 0.) { + } else if (currL > 0.) { koef = 1.0f; } if (needJ) { - hist16J[CLIP((int)((koef * lab->L[i][j])))]++; //evaluate histogram luminance L # J + hist16J[CLIP ((int) ((koef * lab->L[i][j])))]++; //evaluate histogram luminance L # J } if (needQ) { - hist16Q[CLIP((int) (32768.f * sqrt((koef * (lab->L[i][j])) / 32768.f)))]++; //for brightness Q : approximation for Q=wh*sqrt(J/100) J not equal L + hist16Q[CLIP ((int) (32768.f * sqrt ((koef * (lab->L[i][j])) / 32768.f)))]++; //for brightness Q : approximation for Q=wh*sqrt(J/100) J not equal L } sum += koef * lab->L[i][j]; //evaluate mean J to calcualte Yb @@ -467,7 +475,7 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh //evaluate lightness, contrast if (needJ) { if (!CAMBrightCurveJ) { - CAMBrightCurveJ(65536, 0); + CAMBrightCurveJ (65536, 0); CAMBrightCurveJ.dirty = false; } @@ -476,7 +484,7 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh if (needQ) { if (!CAMBrightCurveQ) { - CAMBrightCurveQ(65536, 0); + CAMBrightCurveQ (65536, 0); CAMBrightCurveQ.dirty = false; } @@ -484,40 +492,40 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh } } - if(settings->viewinggreySc == 0) { //auto + if (settings->viewinggreySc == 0) { //auto if (mean < 15.f) { yb = 3.0; - } else if(mean < 30.f) { + } else if (mean < 30.f) { yb = 5.0; - } else if(mean < 40.f) { + } else if (mean < 40.f) { yb = 10.0; - } else if(mean < 45.f) { + } else if (mean < 45.f) { yb = 15.0; - } else if(mean < 50.f) { + } else if (mean < 50.f) { yb = 18.0; - } else if(mean < 55.f) { + } else if (mean < 55.f) { yb = 23.0; - } else if(mean < 60.f) { + } else if (mean < 60.f) { yb = 30.0; - } else if(mean < 70.f) { + } else if (mean < 70.f) { yb = 40.0; - } else if(mean < 80.f) { + } else if (mean < 80.f) { yb = 60.0; - } else if(mean < 90.f) { + } else if (mean < 90.f) { yb = 80.0; } else { yb = 90.0; } } - if(settings->viewinggreySc == 1) { + if (settings->viewinggreySc == 1) { yb = 18.0; } int gamu = 0; bool highlight = params->toneCurve.hrenabled; //Get the value if "highlight reconstruction" is activated - if(params->colorappearance.gamut) { + if (params->colorappearance.gamut) { gamu = 1; //enabled gamut control } @@ -527,14 +535,14 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh double xw1, yw1, zw1, xw2, yw2, zw2; // settings of WB: scene and viewing - if(params->colorappearance.wbmodel == "RawT") { + if (params->colorappearance.wbmodel == "RawT") { xw1 = 96.46; //use RT WB; CAT 02 is used for output device (see prefreneces) yw1 = 100.0; zw1 = 82.445; xw2 = xwd; yw2 = ywd; zw2 = zwd; - } else /*if(params->colorappearance.wbmodel == "RawTCAT02")*/ { + } else { /*if(params->colorappearance.wbmodel == "RawTCAT02")*/ xw1 = xw; // Settings RT WB are used for CAT02 => mix , CAT02 is use for output device (screen: D50 D65, projector: lamp, LED) see preferences yw1 = yw; zw1 = zw; @@ -544,9 +552,9 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh } double cz, wh, pfl; - Ciecam02::initcam1(gamu, yb, pilot, f, la, xw, yw, zw, n, d, nbb, ncb, cz, aw, wh, pfl, fl, c); + Ciecam02::initcam1 (gamu, yb, pilot, f, la, xw, yw, zw, n, d, nbb, ncb, cz, aw, wh, pfl, fl, c); double nj, dj, nbbj, ncbj, czj, awj, flj; - Ciecam02::initcam2(gamu, yb2, f2, la2, xw2, yw2, zw2, nj, dj, nbbj, ncbj, czj, awj, flj); + Ciecam02::initcam2 (gamu, yb2, f2, la2, xw2, yw2, zw2, nj, dj, nbbj, ncbj, czj, awj, flj); @@ -579,7 +587,7 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh double x, y, z; double epsil = 0.0001; //convert Lab => XYZ - Color::Lab2XYZ(L, a, b, x1, y1, z1); + Color::Lab2XYZ (L, a, b, x1, y1, z1); // double J, C, h, Q, M, s, aw, fl, wh; double J, C, h, Q, M, s; @@ -594,12 +602,12 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh y = (double)y1 / 655.35; z = (double)z1 / 655.35; //process source==> normal - Ciecam02::xyz2jchqms_ciecam02( J, C, h, - Q, M, s, aw, fl, wh, - x, y, z, - xw1, yw1, zw1, - yb, la, - f, c, nc, pilot, gamu , n, nbb, ncb, pfl, cz, d ); + Ciecam02::xyz2jchqms_ciecam02 ( J, C, h, + Q, M, s, aw, fl, wh, + x, y, z, + xw1, yw1, zw1, + yb, la, + f, c, nc, pilot, gamu , n, nbb, ncb, pfl, cz, d ); Jpro = J; Cpro = C; hpro = h; @@ -612,60 +620,60 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh f_l = fl; // we cannot have all algoritms with all chroma curves - if(alg == 1) { + if (alg == 1) { // Lightness saturation - if(Jpro > 99.9f) { + if (Jpro > 99.9f) { Jpro = 99.9f; } - Jpro = (CAMBrightCurveJ[(float)(Jpro * 327.68)]) / 327.68; //ligthness CIECAM02 + contrast + Jpro = (CAMBrightCurveJ[ (float) (Jpro * 327.68)]) / 327.68; //ligthness CIECAM02 + contrast double sres; double Sp = spro / 100.0; double parsat = 1.5; //parsat=1.5 =>saturation ; 1.8 => chroma ; 2.5 => colorfullness (personal evaluation) - if(schr == -100.0) { + if (schr == -100.0) { schr = -99.8; } - Ciecam02::curvecolor(schr, Sp , sres, parsat); - double coe = pow(fl, 0.25); + Ciecam02::curvecolor (schr, Sp , sres, parsat); + double coe = pow (fl, 0.25); float dred = 100.f; // in C mode float protect_red = 80.0f; // in C mode - dred = 100.0 * sqrt((dred * coe) / Qpro); - protect_red = 100.0 * sqrt((protect_red * coe) / Qpro); + dred = 100.0 * sqrt ((dred * coe) / Qpro); + protect_red = 100.0 * sqrt ((protect_red * coe) / Qpro); int sk = 0; float ko = 100.f; - Color::skinred(Jpro, hpro, sres, Sp, dred, protect_red, sk, rstprotection, ko, spro); - Qpro = ( 4.0 / c ) * sqrt( Jpro / 100.0 ) * ( aw + 4.0 ) ; + Color::skinred (Jpro, hpro, sres, Sp, dred, protect_red, sk, rstprotection, ko, spro); + Qpro = ( 4.0 / c ) * sqrt ( Jpro / 100.0 ) * ( aw + 4.0 ) ; Cpro = (spro * spro * Qpro) / (10000.0); - } else if(alg == 3 || alg == 0 || alg == 2) { + } else if (alg == 3 || alg == 0 || alg == 2) { double coef = 32760. / wh; - if(alg == 3 || alg == 2) { - if(Qpro * coef > 32767.0f) { - Qpro = (CAMBrightCurveQ[(float)32767.0f]) / coef; //brightness and contrast + if (alg == 3 || alg == 2) { + if (Qpro * coef > 32767.0f) { + Qpro = (CAMBrightCurveQ[ (float)32767.0f]) / coef; //brightness and contrast } else { - Qpro = (CAMBrightCurveQ[(float)(Qpro * coef)]) / coef; //brightness and contrast + Qpro = (CAMBrightCurveQ[ (float) (Qpro * coef)]) / coef; //brightness and contrast } } double Mp, sres; - double coe = pow(fl, 0.25); + double coe = pow (fl, 0.25); Mp = Mpro / 100.0; double parsat = 2.5; - if(mchr == -100.0) { + if (mchr == -100.0) { mchr = -99.8 ; } - if(mchr == 100.0) { + if (mchr == 100.0) { mchr = 99.9; } - if(alg == 3 || alg == 2) { - Ciecam02::curvecolor(mchr, Mp , sres, parsat); + if (alg == 3 || alg == 2) { + Ciecam02::curvecolor (mchr, Mp , sres, parsat); } else { - Ciecam02::curvecolor(0.0, Mp , sres, parsat); //colorfullness + Ciecam02::curvecolor (0.0, Mp , sres, parsat); //colorfullness } float dred = 100.f; //in C mode @@ -674,77 +682,77 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh protect_red *= coe; //M mode int sk = 0; float ko = 100.f; - Color::skinred(Jpro, hpro, sres, Mp, dred, protect_red, sk, rstprotection, ko, Mpro); + Color::skinred (Jpro, hpro, sres, Mp, dred, protect_red, sk, rstprotection, ko, Mpro); Jpro = (100.0 * Qpro * Qpro) / (wh * wh); Cpro = Mpro / coe; - spro = 100.0 * sqrt( Mpro / Qpro ); + spro = 100.0 * sqrt ( Mpro / Qpro ); - if(alg != 2) { - if(Jpro > 99.9f) { + if (alg != 2) { + if (Jpro > 99.9f) { Jpro = 99.9f; } - Jpro = (CAMBrightCurveJ[(float)(Jpro * 327.68f)]) / 327.68f; //ligthness CIECAM02 + contrast + Jpro = (CAMBrightCurveJ[ (float) (Jpro * 327.68f)]) / 327.68f; //ligthness CIECAM02 + contrast } double Cp; double Sp = spro / 100.0; parsat = 1.5; - if(schr == -100.0) { + if (schr == -100.0) { schr = -99.; } - if(schr == 100.0) { + if (schr == 100.0) { schr = 98.; } - if(alg == 3) { - Ciecam02::curvecolor(schr, Sp , sres, parsat); + if (alg == 3) { + Ciecam02::curvecolor (schr, Sp , sres, parsat); } else { - Ciecam02::curvecolor(0.0, Sp , sres, parsat); //saturation + Ciecam02::curvecolor (0.0, Sp , sres, parsat); //saturation } dred = 100.f; // in C mode protect_red = 80.0f; // in C mode - dred = 100.0 * sqrt((dred * coe) / Q); - protect_red = 100.0 * sqrt((protect_red * coe) / Q); + dred = 100.0 * sqrt ((dred * coe) / Q); + protect_red = 100.0 * sqrt ((protect_red * coe) / Q); sk = 0; - Color::skinred(Jpro, hpro, sres, Sp, dred, protect_red, sk, rstprotection, ko, spro); + Color::skinred (Jpro, hpro, sres, Sp, dred, protect_red, sk, rstprotection, ko, spro); //double Q1; - Qpro = ( 4.0 / c ) * sqrt( Jpro / 100.0 ) * ( aw + 4.0 ) ; + Qpro = ( 4.0 / c ) * sqrt ( Jpro / 100.0 ) * ( aw + 4.0 ) ; Cpro = (spro * spro * Qpro) / (10000.0); Cp = Cpro / 100.0; parsat = 1.8; //parsat=1.5 =>saturation ; 1.8 => chroma ; 2.5 => colorfullness (personal evaluation : for not) - if(chr == -100.0) { + if (chr == -100.0) { chr = -99.8; } - if(alg != 2) { - Ciecam02::curvecolor(chr, Cp , sres, parsat); + if (alg != 2) { + Ciecam02::curvecolor (chr, Cp , sres, parsat); } else { - Ciecam02::curvecolor(0.0, Cp , sres, parsat); //chroma + Ciecam02::curvecolor (0.0, Cp , sres, parsat); //chroma } dred = 55.f; protect_red = 30.0f; sk = 1; - Color::skinred(Jpro, hpro, sres, Cp, dred, protect_red, sk, rstprotection, ko, Cpro); + Color::skinred (Jpro, hpro, sres, Cp, dred, protect_red, sk, rstprotection, ko, Cpro); - if(Jpro < 1. && Cpro > 12.) { + if (Jpro < 1. && Cpro > 12.) { Cpro = 12.; //reduce artifacts by "pseudo gamut control CIECAM" - } else if(Jpro < 2. && Cpro > 15.) { + } else if (Jpro < 2. && Cpro > 15.) { Cpro = 15.; - } else if(Jpro < 4. && Cpro > 30.) { + } else if (Jpro < 4. && Cpro > 30.) { Cpro = 30.; - } else if(Jpro < 7. && Cpro > 50.) { + } else if (Jpro < 7. && Cpro > 50.) { Cpro = 50.; } hpro = hpro + hue; - if( hpro < 0.0 ) { + if ( hpro < 0.0 ) { hpro += 360.0; //hue } } @@ -762,28 +770,28 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh float Jold100 = (float) Jpro; float redu = 25.f; float reduc = 1.f; - const Lightcurve& userColCurveJ1 = static_cast(customColCurve1); - userColCurveJ1.Apply(Jj); + const Lightcurve& userColCurveJ1 = static_cast (customColCurve1); + userColCurveJ1.Apply (Jj); - if(Jj > Jold) { - if(Jj < 65535.f) { - if(Jold < 327.68f * redu) { + if (Jj > Jold) { + if (Jj < 65535.f) { + if (Jold < 327.68f * redu) { Jj = 0.3f * (Jj - Jold) + Jold; //divide sensibility } else { - reduc = LIM((100.f - Jold100) / (100.f - redu), 0.f, 1.f); + reduc = LIM ((100.f - Jold100) / (100.f - redu), 0.f, 1.f); Jj = 0.3f * reduc * (Jj - Jold) + Jold; //reduct sensibility in highlights } } - } else if(Jj > 10.f) { + } else if (Jj > 10.f) { Jj = 0.8f * (Jj - Jold) + Jold; } else if (Jj >= 0.f) { Jj = 0.90f * (Jj - Jold) + Jold; // not zero ==>artifacts } - Jpro = (double)(Jj / 327.68f); + Jpro = (double) (Jj / 327.68f); - if(Jpro < 1.) { + if (Jpro < 1.) { Jpro = 1.; } @@ -798,29 +806,29 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh float redu = 20.f; float reduc = 1.f; - const Brightcurve& userColCurveB1 = static_cast(customColCurve1); - userColCurveB1.Apply(Qq); + const Brightcurve& userColCurveB1 = static_cast (customColCurve1); + userColCurveB1.Apply (Qq); - if(Qq > Qold) { - if(Qq < 65535.f) { - if(Qold < 327.68f * redu) { + if (Qq > Qold) { + if (Qq < 65535.f) { + if (Qold < 327.68f * redu) { Qq = 0.25f * (Qq - Qold) + Qold; //divide sensibility } else { - reduc = LIM((100.f - Qold100) / (100.f - redu), 0.f, 1.f); + reduc = LIM ((100.f - Qold100) / (100.f - redu), 0.f, 1.f); Qq = 0.25f * reduc * (Qq - Qold) + Qold; //reduct sensibility in highlights } } - } else if(Qq > 10.f) { + } else if (Qq > 10.f) { Qq = 0.5f * (Qq - Qold) + Qold; } else if (Qq >= 0.f) { Qq = 0.7f * (Qq - Qold) + Qold; // not zero ==>artifacts } - Qpro = (double)(Qq * (coef) / 327.68f); - Jpro = 100.*(Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); + Qpro = (double) (Qq * (coef) / 327.68f); + Jpro = 100.* (Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); t1B = true; - if(Jpro < 1.) { + if (Jpro < 1.) { Jpro = 1.; } @@ -839,35 +847,35 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh float Jold100 = (float) Jpro; float redu = 25.f; float reduc = 1.f; - const Lightcurve& userColCurveJ2 = static_cast(customColCurve2); - userColCurveJ2.Apply(Jj); + const Lightcurve& userColCurveJ2 = static_cast (customColCurve2); + userColCurveJ2.Apply (Jj); - if(Jj > Jold) { - if(Jj < 65535.f) { - if(Jold < 327.68f * redu) { + if (Jj > Jold) { + if (Jj < 65535.f) { + if (Jold < 327.68f * redu) { Jj = 0.3f * (Jj - Jold) + Jold; //divide sensibility } else { - reduc = LIM((100.f - Jold100) / (100.f - redu), 0.f, 1.f); + reduc = LIM ((100.f - Jold100) / (100.f - redu), 0.f, 1.f); Jj = 0.3f * reduc * (Jj - Jold) + Jold; //reduct sensibility in highlights } } - } else if(Jj > 10.f) { - if(!t1L) { + } else if (Jj > 10.f) { + if (!t1L) { Jj = 0.8f * (Jj - Jold) + Jold; } else { Jj = 0.4f * (Jj - Jold) + Jold; } } else if (Jj >= 0.f) { - if(!t1L) { + if (!t1L) { Jj = 0.90f * (Jj - Jold) + Jold; // not zero ==>artifacts } else { Jj = 0.5f * (Jj - Jold) + Jold; } } - Jpro = (double)(Jj / 327.68f); + Jpro = (double) (Jj / 327.68f); - if(Jpro < 1.) { + if (Jpro < 1.) { Jpro = 1.; } @@ -880,40 +888,40 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh float redu = 20.f; float reduc = 1.f; - const Brightcurve& userColCurveB2 = static_cast(customColCurve2); - userColCurveB2.Apply(Qq); + const Brightcurve& userColCurveB2 = static_cast (customColCurve2); + userColCurveB2.Apply (Qq); - if(Qq > Qold) { - if(Qq < 65535.f) { - if(Qold < 327.68f * redu) { + if (Qq > Qold) { + if (Qq < 65535.f) { + if (Qold < 327.68f * redu) { Qq = 0.25f * (Qq - Qold) + Qold; //divide sensibility } else { - reduc = LIM((100.f - Qold100) / (100.f - redu), 0.f, 1.f); + reduc = LIM ((100.f - Qold100) / (100.f - redu), 0.f, 1.f); Qq = 0.25f * reduc * (Qq - Qold) + Qold; //reduct sensibility in highlights } } - } else if(Qq > 10.f) { + } else if (Qq > 10.f) { Qq = 0.5f * (Qq - Qold) + Qold; } else if (Qq >= 0.f) { Qq = 0.7f * (Qq - Qold) + Qold; // not zero ==>artifacts } - Qpro = (double)(Qq * (coef) / 327.68f); - Jpro = 100.*(Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); + Qpro = (double) (Qq * (coef) / 327.68f); + Jpro = 100.* (Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); t2B = true; - if(t1L) { //to workaround the problem if we modify curve1-lightnees after curve2 brightness(the cat that bites its own tail!) in fact it's another type of curve only for this case + if (t1L) { //to workaround the problem if we modify curve1-lightnees after curve2 brightness(the cat that bites its own tail!) in fact it's another type of curve only for this case coef = 2.f; //adapt Q to J approximation Qq = (float) Qpro * coef; Qold = Qq; - const Lightcurve& userColCurveJ1 = static_cast(customColCurve1); - userColCurveJ1.Apply(Qq); + const Lightcurve& userColCurveJ1 = static_cast (customColCurve1); + userColCurveJ1.Apply (Qq); Qq = 0.1f * (Qq - Qold) + Qold; //approximative adaptation - Qpro = (double)(Qq / coef); - Jpro = 100.*(Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); + Qpro = (double) (Qq / coef); + Jpro = 100.* (Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); } - if(Jpro < 1.) { + if (Jpro < 1.) { Jpro = 1.; } } @@ -925,21 +933,21 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh double coef = 327.68 / parsat; float Cc = (float) Cpro * coef; float Ccold = Cc; - const Chromacurve& userColCurve = static_cast(customColCurve3); - userColCurve.Apply(Cc); + const Chromacurve& userColCurve = static_cast (customColCurve3); + userColCurve.Apply (Cc); float dred = 55.f; float protect_red = 30.0f; float sk = 1; float ko = 1.f / coef; - Color::skinred(Jpro, hpro, Cc, Ccold, dred, protect_red, sk, rstprotection, ko, Cpro); + Color::skinred (Jpro, hpro, Cc, Ccold, dred, protect_red, sk, rstprotection, ko, Cpro); - if(Jpro < 1. && Cpro > 12.) { + if (Jpro < 1. && Cpro > 12.) { Cpro = 12.; //reduce artifacts by "pseudo gamut control CIECAM" - } else if(Jpro < 2. && Cpro > 15.) { + } else if (Jpro < 2. && Cpro > 15.) { Cpro = 15.; - } else if(Jpro < 4. && Cpro > 30.) { + } else if (Jpro < 4. && Cpro > 30.) { Cpro = 30.; - } else if(Jpro < 7. && Cpro > 50.) { + } else if (Jpro < 7. && Cpro > 50.) { Cpro = 50.; } @@ -949,18 +957,18 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh double coef = 327.68 / parsat; float Ss = (float) spro * coef; float Sold = Ss; - const Saturcurve& userColCurve = static_cast(customColCurve3); - userColCurve.Apply(Ss); + const Saturcurve& userColCurve = static_cast (customColCurve3); + userColCurve.Apply (Ss); Ss = 0.6f * (Ss - Sold) + Sold; //divide sensibility saturation - double coe = pow(fl, 0.25); + double coe = pow (fl, 0.25); float dred = 100.f; // in C mode float protect_red = 80.0f; // in C mode - dred = 100.0 * sqrt((dred * coe) / Qpro); - protect_red = 100.0 * sqrt((protect_red * coe) / Qpro); + dred = 100.0 * sqrt ((dred * coe) / Qpro); + protect_red = 100.0 * sqrt ((protect_red * coe) / Qpro); int sk = 0; float ko = 1.f / coef; - Color::skinred(Jpro, hpro, Ss, Sold, dred, protect_red, sk, rstprotection, ko, spro); - Qpro = ( 4.0 / c ) * sqrt( Jpro / 100.0 ) * ( aw + 4.0 ) ; + Color::skinred (Jpro, hpro, Ss, Sold, dred, protect_red, sk, rstprotection, ko, spro); + Qpro = ( 4.0 / c ) * sqrt ( Jpro / 100.0 ) * ( aw + 4.0 ) ; Cpro = (spro * spro * Qpro) / (10000.0); c1s = 1; @@ -969,25 +977,25 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh double coef = 327.68 / parsat; float Mm = (float) Mpro * coef; float Mold = Mm; - const Colorfcurve& userColCurve = static_cast(customColCurve3); - userColCurve.Apply(Mm); - double coe = pow(fl, 0.25); + const Colorfcurve& userColCurve = static_cast (customColCurve3); + userColCurve.Apply (Mm); + double coe = pow (fl, 0.25); float dred = 100.f; //in C mode float protect_red = 80.0f; // in C mode dred *= coe; //in M mode protect_red *= coe; int sk = 0; float ko = 1.f / coef; - Color::skinred(Jpro, hpro, Mm, Mold, dred, protect_red, sk, rstprotection, ko, Mpro); + Color::skinred (Jpro, hpro, Mm, Mold, dred, protect_red, sk, rstprotection, ko, Mpro); Cpro = Mpro / coe; - if(Jpro < 1. && Mpro > 12.*coe) { + if (Jpro < 1. && Mpro > 12.*coe) { Mpro = 12.*coe; //reduce artifacts by "pseudo gamut control CIECAM" - } else if(Jpro < 2. && Mpro > 15.*coe) { + } else if (Jpro < 2. && Mpro > 15.*coe) { Mpro = 15.*coe; - } else if(Jpro < 4. && Mpro > 30.*coe) { + } else if (Jpro < 4. && Mpro > 30.*coe) { Mpro = 30.*coe; - } else if(Jpro < 7. && Mpro > 50.*coe) { + } else if (Jpro < 7. && Mpro > 50.*coe) { Mpro = 50.*coe; } @@ -997,17 +1005,17 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh } //to retrieve the correct values of variables - if(t2B && t1B) { + if (t2B && t1B) { Jpro = (100.0 * Qpro * Qpro) / (wh * wh); // for brightness curve } - if(c1s == 1) { - Qpro = ( 4.0 / c ) * sqrt( Jpro / 100.0 ) * ( aw + 4.0 ) ; //for saturation curve + if (c1s == 1) { + Qpro = ( 4.0 / c ) * sqrt ( Jpro / 100.0 ) * ( aw + 4.0 ) ; //for saturation curve Cpro = (spro * spro * Qpro) / (10000.0); } - if(c1co == 1) { - double coe = pow(fl, 0.25); // for colorfullness curve + if (c1co == 1) { + double coe = pow (fl, 0.25); // for colorfullness curve Cpro = Mpro / coe; } @@ -1019,7 +1027,7 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh h = hpro; s = spro; - if(params->colorappearance.tonecie || settings->autocielab) { //use pointer for tonemapping with CIECAM and also sharpening , defringe, contrast detail + if (params->colorappearance.tonecie || settings->autocielab) { //use pointer for tonemapping with CIECAM and also sharpening , defringe, contrast detail // if(params->colorappearance.tonecie || params->colorappearance.sharpcie){//use pointer for tonemapping with CIECAM and also sharpening , defringe, contrast detail float Qred = ( 4.0 / c) * ( aw + 4.0 ); //estimate Q max if J=100.0 ncie->Q_p[i][j] = (float)Q + epsil; //epsil to avoid Q=0 @@ -1028,19 +1036,19 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh ncie->h_p[i][j] = (float)h; ncie->C_p[i][j] = (float)C + epsil; // ncie->s_p[i][j]=(float)s; - ncie->sh_p[i][j] = (float) 32768.*(( 4.0 / c ) * sqrt( J / 100.0 ) * ( aw + 4.0 )) / Qred ; + ncie->sh_p[i][j] = (float) 32768.* (( 4.0 / c ) * sqrt ( J / 100.0 ) * ( aw + 4.0 )) / Qred ; // ncie->ch_p[i][j]=(float) 327.68*C; - if(ncie->Q_p[i][j] < minQ) { + if (ncie->Q_p[i][j] < minQ) { minQ = ncie->Q_p[i][j]; //minima } - if(ncie->Q_p[i][j] > maxQ) { + if (ncie->Q_p[i][j] > maxQ) { maxQ = ncie->Q_p[i][j]; //maxima } } - if(!params->colorappearance.tonecie || !settings->autocielab || !params->epd.enabled ) { + if (!params->colorappearance.tonecie || !settings->autocielab || !params->epd.enabled ) { // if(!params->epd.enabled || !params->colorappearance.tonecie || !settings->autocielab){ // if(!params->epd.enabled || !params->colorappearance.tonecie || !params->colorappearance.sharpcie){ @@ -1049,10 +1057,10 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh int libr = 0; int colch = 0; - if(curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { + if (curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { brli = 70.0; libr = 1; - } else if(curveMode == ColorAppearanceParams::TC_MODE_LIGHT) { + } else if (curveMode == ColorAppearanceParams::TC_MODE_LIGHT) { brli = 327.; libr = 0; } @@ -1060,25 +1068,26 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh if (curveMode3 == ColorAppearanceParams::TC_MODE_CHROMA) { chsacol = 327.; colch = 0; - } else if(curveMode3 == ColorAppearanceParams::TC_MODE_SATUR) { + } else if (curveMode3 == ColorAppearanceParams::TC_MODE_SATUR) { chsacol = 450.0; colch = 1; - } else if(curveMode3 == ColorAppearanceParams::TC_MODE_COLORF) { + } else if (curveMode3 == ColorAppearanceParams::TC_MODE_COLORF) { chsacol = 327.0; colch = 2; } - if(ciedata) { + if (ciedata) { // Data for J Q M s and C histograms //update histogram jp = true; - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator int posl; - if(libr == 1) { - posl = CLIP((int)(Q * brli)); //40.0 to 100.0 approximative factor for Q - 327 for J - } else /*if(libr == 0)*/ { - posl = CLIP((int)(J * brli)); //327 for J + + if (libr == 1) { + posl = CLIP ((int) (Q * brli)); //40.0 to 100.0 approximative factor for Q - 327 for J + } else { /*if(libr == 0)*/ + posl = CLIP ((int) (J * brli)); //327 for J } hist16JCAM[posl]++; @@ -1086,14 +1095,15 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh chropC = true; - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator int posc; - if(colch == 0) { - posc = CLIP((int)(C * chsacol)); //450.0 approximative factor for s 320 for M - } else if(colch == 1) { - posc = CLIP((int)(s * chsacol)); - } else /*if(colch == 2)*/ { - posc = CLIP((int)(M * chsacol)); + + if (colch == 0) { + posc = CLIP ((int) (C * chsacol)); //450.0 approximative factor for s 320 for M + } else if (colch == 1) { + posc = CLIP ((int) (s * chsacol)); + } else { /*if(colch == 2)*/ + posc = CLIP ((int) (M * chsacol)); } hist16_CCAM[posc]++; @@ -1103,42 +1113,42 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh double xx, yy, zz; //double nj, nbbj, ncbj, flj, czj, dj, awj; //process normal==> viewing - Ciecam02::jch2xyz_ciecam02( xx, yy, zz, - J, C, h, - xw2, yw2, zw2, - yb2, la2, - f2, c2, nc2, gamu, nj, nbbj, ncbj, flj, czj, dj, awj); + Ciecam02::jch2xyz_ciecam02 ( xx, yy, zz, + J, C, h, + xw2, yw2, zw2, + yb2, la2, + f2, c2, nc2, gamu, nj, nbbj, ncbj, flj, czj, dj, awj); x = (float)xx * 655.35; y = (float)yy * 655.35; z = (float)zz * 655.35; float Ll, aa, bb; //convert xyz=>lab - Color::XYZ2Lab(x, y, z, Ll, aa, bb); + Color::XYZ2Lab (x, y, z, Ll, aa, bb); lab->L[i][j] = Ll; lab->a[i][j] = aa; lab->b[i][j] = bb; // gamut control in Lab mode; I must study how to do with cIECAM only - if(gamu == 1) { + if (gamu == 1) { float R, G, B; float HH, Lprov1, Chprov1; Lprov1 = lab->L[i][j] / 327.68f; - Chprov1 = sqrt(SQR(lab->a[i][j] / 327.68f) + SQR(lab->b[i][j] / 327.68f)); - HH = atan2(lab->b[i][j], lab->a[i][j]); + Chprov1 = sqrt (SQR (lab->a[i][j] / 327.68f) + SQR (lab->b[i][j] / 327.68f)); + HH = atan2 (lab->b[i][j], lab->a[i][j]); #ifdef _DEBUG bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (HH, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f); + Color::gamutLchonly (HH, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f); #endif lab->L[i][j] = Lprov1 * 327.68f; - lab->a[i][j] = 327.68f * Chprov1 * cos(HH); - lab->b[i][j] = 327.68f * Chprov1 * sin(HH); + lab->a[i][j] = 327.68f * Chprov1 * cos (HH); + lab->b[i][j] = 327.68f * Chprov1 * sin (HH); } } @@ -1146,26 +1156,26 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh } // End of parallelization - if(!params->epd.enabled || !params->colorappearance.tonecie || !settings->autocielab) { //normal + if (!params->epd.enabled || !params->colorappearance.tonecie || !settings->autocielab) { //normal //if(!params->epd.enabled || !params->colorappearance.tonecie || !params->colorappearance.sharpcie){//normal - if(ciedata) { + if (ciedata) { //update histogram J - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator for (int i = 0; i < 32768; i++) { // if (jp) { float hval = dLcurve[i]; - int hi = (int)(255.0 * CLIPD(hval)); // + int hi = (int) (255.0 * CLIPD (hval)); // histLCAM[hi] += hist16JCAM[i] ; } } } - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator for (int i = 0; i < 48000; i++) { // if (chropC) { float hvalc = dCcurve[i]; - int hic = (int)(255.0 * CLIPD(hvalc)); // + int hic = (int) (255.0 * CLIPD (hvalc)); // histCCAM[hic] += hist16_CCAM[i] ; } } @@ -1177,35 +1187,35 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh if (settings->verbose) { t2e.set(); - printf("CIECAM02 performed in %d usec:\n", t2e.etime(t1e)); + printf ("CIECAM02 performed in %d usec:\n", t2e.etime (t1e)); // printf("minc=%f maxc=%f minj=%f maxj=%f\n",minc,maxc,minj,maxj); } #endif - if(settings->autocielab) { + if (settings->autocielab) { //if(params->colorappearance.sharpcie) { //all this treatments reduce artifacts, but can lead to slightly different results - if(params->defringe.enabled) if(execsharp) { + if (params->defringe.enabled) if (execsharp) { ImProcFunctions::defringecam (ncie); // } //if(params->dirpyrequalizer.enabled) if(execsharp) { - if(params->dirpyrequalizer.enabled) { - if(params->dirpyrequalizer.gamutlab /*&& execsharp*/) { - float b_l = static_cast(params->dirpyrequalizer.hueskin.value[0]) / 100.0f; - float t_l = static_cast(params->dirpyrequalizer.hueskin.value[1]) / 100.0f; - float b_r = static_cast(params->dirpyrequalizer.hueskin.value[2]) / 100.0f; - float t_r = static_cast(params->dirpyrequalizer.hueskin.value[3]) / 100.0f; + if (params->dirpyrequalizer.enabled) { + if (params->dirpyrequalizer.gamutlab /*&& execsharp*/) { + float b_l = static_cast (params->dirpyrequalizer.hueskin.value[0]) / 100.0f; + float t_l = static_cast (params->dirpyrequalizer.hueskin.value[1]) / 100.0f; + float b_r = static_cast (params->dirpyrequalizer.hueskin.value[2]) / 100.0f; + float t_r = static_cast (params->dirpyrequalizer.hueskin.value[3]) / 100.0f; float artifact = (float) settings->artifact_cbdl; - if(artifact > 6.f) { + if (artifact > 6.f) { artifact = 6.f; } - if(artifact < 0.f) { + if (artifact < 0.f) { artifact = 1.f; } @@ -1217,38 +1227,38 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh } } - if(params->colorappearance.badpixsl > 0) if(execsharp) { + if (params->colorappearance.badpixsl > 0) if (execsharp) { int mode = params->colorappearance.badpixsl; ImProcFunctions::badpixcam (ncie, 3.4, 5, mode, 0, 0, 0, 0, 0, 0, 1);//for bad pixels CIECAM } - if (params->sharpenMicro.enabled)if(execsharp) { - ImProcFunctions::MLmicrocontrastcam(ncie); + if (params->sharpenMicro.enabled)if (execsharp) { + ImProcFunctions::MLmicrocontrastcam (ncie); } - if(params->sharpening.enabled) - if(execsharp) { + if (params->sharpening.enabled) + if (execsharp) { float **buffer = lab->L; // We can use the L-buffer from lab as buffer to save some memory ImProcFunctions::sharpeningcam (ncie, buffer); // sharpening adapted to CIECAM } //if(params->dirpyrequalizer.enabled) if(execsharp) { - if(params->dirpyrequalizer.enabled /*&& (execsharp)*/) { + if (params->dirpyrequalizer.enabled /*&& (execsharp)*/) { // if (params->dirpyrequalizer.algo=="FI") choice=0; // else if(params->dirpyrequalizer.algo=="LA") choice=1; - if(rtt == 1) { - float b_l = static_cast(params->dirpyrequalizer.hueskin.value[0]) / 100.0f; - float t_l = static_cast(params->dirpyrequalizer.hueskin.value[1]) / 100.0f; - float b_r = static_cast(params->dirpyrequalizer.hueskin.value[2]) / 100.0f; - float t_r = static_cast(params->dirpyrequalizer.hueskin.value[3]) / 100.0f; + if (rtt == 1) { + float b_l = static_cast (params->dirpyrequalizer.hueskin.value[0]) / 100.0f; + float t_l = static_cast (params->dirpyrequalizer.hueskin.value[1]) / 100.0f; + float b_r = static_cast (params->dirpyrequalizer.hueskin.value[2]) / 100.0f; + float t_r = static_cast (params->dirpyrequalizer.hueskin.value[3]) / 100.0f; int choice = 0; //not disabled in case of ! always 0 - dirpyr_equalizercam(ncie, ncie->sh_p, ncie->sh_p, ncie->W, ncie->H, ncie->h_p, ncie->C_p, params->dirpyrequalizer.mult, params->dirpyrequalizer.threshold, params->dirpyrequalizer.skinprotect, true, params->dirpyrequalizer.gamutlab, b_l, t_l, t_r, b_r, choice, scalecd); //contrast by detail adapted to CIECAM + dirpyr_equalizercam (ncie, ncie->sh_p, ncie->sh_p, ncie->W, ncie->H, ncie->h_p, ncie->C_p, params->dirpyrequalizer.mult, params->dirpyrequalizer.threshold, params->dirpyrequalizer.skinprotect, true, params->dirpyrequalizer.gamutlab, b_l, t_l, t_r, b_r, choice, scalecd); //contrast by detail adapted to CIECAM } } float Qredi = ( 4.0 / c_) * ( a_w + 4.0 ); - float co_e = (pow(f_l, 0.25f)); + float co_e = (pow (f_l, 0.25f)); #ifndef _DEBUG #pragma omp parallel default(shared) firstprivate(height,width, Qredi,a_w,c_) @@ -1262,18 +1272,18 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh for (int j = 0; j < width; j++) { float interm = Qredi * ncie->sh_p[i][j] / (32768.f); ncie->J_p[i][j] = 100.0 * interm * interm / ((a_w + 4.) * (a_w + 4.) * (4. / c_) * (4. / c_)); - ncie->Q_p[i][j] = ( 4.0 / c_) * ( a_w + 4.0 ) * sqrt(ncie->J_p[i][j] / 100.f); + ncie->Q_p[i][j] = ( 4.0 / c_) * ( a_w + 4.0 ) * sqrt (ncie->J_p[i][j] / 100.f); ncie->M_p[i][j] = ncie->C_p[i][j] * co_e; } } } - if((params->colorappearance.tonecie || (params->colorappearance.tonecie && params->epd.enabled)) || (params->sharpening.enabled && settings->autocielab) + if ((params->colorappearance.tonecie || (params->colorappearance.tonecie && params->epd.enabled)) || (params->sharpening.enabled && settings->autocielab) || (params->dirpyrequalizer.enabled && settings->autocielab) || (params->defringe.enabled && settings->autocielab) || (params->sharpenMicro.enabled && settings->autocielab) || (params->colorappearance.badpixsl > 0 && settings->autocielab)) { - if(params->epd.enabled && params->colorappearance.tonecie && algepd) { - ImProcFunctions::EPDToneMapCIE(ncie, a_w, c_, w_h, width, height, begh, endh, minQ, maxQ, Iterates, scale ); + if (params->epd.enabled && params->colorappearance.tonecie && algepd) { + ImProcFunctions::EPDToneMapCIE (ncie, a_w, c_, w_h, width, height, begh, endh, minQ, maxQ, Iterates, scale ); } //EPDToneMapCIE adapted to CIECAM @@ -1302,11 +1312,11 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh double xx, yy, zz; float x, y, z; const float eps = 0.0001; - float co_e = (pow(f_l, 0.25f)) + eps; + float co_e = (pow (f_l, 0.25f)) + eps; // if(params->epd.enabled) ncie->J_p[i][j]=(100.0* ncie->Q_p[i][j]*ncie->Q_p[i][j])/(w_h*w_h); - if(params->epd.enabled) { - ncie->J_p[i][j] = (100.0 * ncie->Q_p[i][j] * ncie->Q_p[i][j]) / SQR((4. / c) * (aw + 4.)); + if (params->epd.enabled) { + ncie->J_p[i][j] = (100.0 * ncie->Q_p[i][j] * ncie->Q_p[i][j]) / SQR ((4. / c) * (aw + 4.)); } ncie->C_p[i][j] = (ncie->M_p[i][j]) / co_e; @@ -1316,10 +1326,10 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh int libr = 0; int colch = 0; - if(curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { + if (curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { brli = 70.0; libr = 1; - } else if(curveMode == ColorAppearanceParams::TC_MODE_LIGHT) { + } else if (curveMode == ColorAppearanceParams::TC_MODE_LIGHT) { brli = 327.; libr = 0; } @@ -1327,25 +1337,26 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh if (curveMode3 == ColorAppearanceParams::TC_MODE_CHROMA) { chsacol = 327.; colch = 0; - } else if(curveMode3 == ColorAppearanceParams::TC_MODE_SATUR) { + } else if (curveMode3 == ColorAppearanceParams::TC_MODE_SATUR) { chsacol = 450.0; colch = 1; - } else if(curveMode3 == ColorAppearanceParams::TC_MODE_COLORF) { + } else if (curveMode3 == ColorAppearanceParams::TC_MODE_COLORF) { chsacol = 327.0; colch = 2; } - if(ciedata) { + if (ciedata) { // Data for J Q M s and C histograms //update histogram jp = true; - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator int posl; - if(libr == 1) { - posl = CLIP((int)(ncie->Q_p[i][j] * brli)); //40.0 to 100.0 approximative factor for Q - 327 for J - } else /*if(libr == 0)*/ { - posl = CLIP((int)(ncie->J_p[i][j] * brli)); //327 for J + + if (libr == 1) { + posl = CLIP ((int) (ncie->Q_p[i][j] * brli)); //40.0 to 100.0 approximative factor for Q - 327 for J + } else { /*if(libr == 0)*/ + posl = CLIP ((int) (ncie->J_p[i][j] * brli)); //327 for J } hist16JCAM[posl]++; @@ -1353,15 +1364,16 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh chropC = true; - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator int posc; - if(colch == 0) { - posc = CLIP((int)(ncie->C_p[i][j] * chsacol)); //450.0 approximative factor for s 320 for M - } else if(colch == 1) { - float sa_t = 100.f * sqrt(ncie->C_p[i][j] / ncie->Q_p[i][j]); //Q_p always > 0 - posc = CLIP((int)(sa_t * chsacol)); - } else /*if(colch == 2)*/ { - posc = CLIP((int)(ncie->M_p[i][j] * chsacol)); + + if (colch == 0) { + posc = CLIP ((int) (ncie->C_p[i][j] * chsacol)); //450.0 approximative factor for s 320 for M + } else if (colch == 1) { + float sa_t = 100.f * sqrt (ncie->C_p[i][j] / ncie->Q_p[i][j]); //Q_p always > 0 + posc = CLIP ((int) (sa_t * chsacol)); + } else { /*if(colch == 2)*/ + posc = CLIP ((int) (ncie->M_p[i][j] * chsacol)); } hist16_CCAM[posc]++; @@ -1370,41 +1382,41 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh //end histograms // double nd, nbbd, ncbd, fld, czd, dd, awd; - Ciecam02::jch2xyz_ciecam02( xx, yy, zz, - ncie->J_p[i][j], ncie->C_p[i][j], ncie->h_p[i][j], - xw2, yw2, zw2, - yb2, la2, - f2, c2, nc2, gamu, nj, nbbj, ncbj, flj, czj, dj, awj); + Ciecam02::jch2xyz_ciecam02 ( xx, yy, zz, + ncie->J_p[i][j], ncie->C_p[i][j], ncie->h_p[i][j], + xw2, yw2, zw2, + yb2, la2, + f2, c2, nc2, gamu, nj, nbbj, ncbj, flj, czj, dj, awj); x = (float)xx * 655.35; y = (float)yy * 655.35; z = (float)zz * 655.35; float Ll, aa, bb; //convert xyz=>lab - Color::XYZ2Lab(x, y, z, Ll, aa, bb); + Color::XYZ2Lab (x, y, z, Ll, aa, bb); lab->L[i][j] = Ll; lab->a[i][j] = aa; lab->b[i][j] = bb; - if(gamu == 1) { + if (gamu == 1) { float R, G, B; float HH, Lprov1, Chprov1; Lprov1 = lab->L[i][j] / 327.68f; - Chprov1 = sqrt(SQR(lab->a[i][j] / 327.68f) + SQR(lab->b[i][j] / 327.68f)); - HH = atan2(lab->b[i][j], lab->a[i][j]); + Chprov1 = sqrt (SQR (lab->a[i][j] / 327.68f) + SQR (lab->b[i][j] / 327.68f)); + HH = atan2 (lab->b[i][j], lab->a[i][j]); #ifdef _DEBUG bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, Lprov1, Chprov1, R, G, B, wipa, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (HH, Lprov1, Chprov1, R, G, B, wipa, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, Lprov1, Chprov1, R, G, B, wipa, highlight, 0.15f, 0.96f); + Color::gamutLchonly (HH, Lprov1, Chprov1, R, G, B, wipa, highlight, 0.15f, 0.96f); #endif lab->L[i][j] = Lprov1 * 327.68f; - lab->a[i][j] = 327.68f * Chprov1 * cos(HH); - lab->b[i][j] = 327.68f * Chprov1 * sin(HH); + lab->a[i][j] = 327.68f * Chprov1 * cos (HH); + lab->b[i][j] = 327.68f * Chprov1 * sin (HH); } } @@ -1413,24 +1425,24 @@ void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int begh, int endh //end parallelization //show CIECAM histograms - if(ciedata) { + if (ciedata) { //update histogram J and Q - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator for (int i = 0; i < 32768; i++) { // if (jp) { float hval = dLcurve[i]; - int hi = (int)(255.0 * CLIPD(hval)); // + int hi = (int) (255.0 * CLIPD (hval)); // histLCAM[hi] += hist16JCAM[i] ; } } } //update color histogram M,s,C - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator for (int i = 0; i < 48000; i++) { // if (chropC) { float hvalc = dCcurve[i]; - int hic = (int)(255.0 * CLIPD(hvalc)); // + int hic = (int) (255.0 * CLIPD (hvalc)); // histCCAM[hic] += hist16_CCAM[i] ; } } @@ -1449,7 +1461,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int const ColorAppearance & customColCurve1, const ColorAppearance & customColCurve2, const ColorAppearance & customColCurve3, LUTu & histLCAM, LUTu & histCCAM, LUTf & CAMBrightCurveJ, LUTf & CAMBrightCurveQ, float &mean, int Iterates, int scale, bool execsharp, float &d, int scalecd, int rtt) { - if(params->colorappearance.enabled) { + if (params->colorappearance.enabled) { #ifdef _DEBUG MyTime t1e, t2e; @@ -1460,10 +1472,10 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int LUTu hist16JCAM; LUTu hist16_CCAM; - if(pW != 1 && params->colorappearance.datacie) { //only with improccoordinator - hist16JCAM(32768); + if (pW != 1 && params->colorappearance.datacie) { //only with improccoordinator + hist16JCAM (32768); hist16JCAM.clear(); - hist16_CCAM(48000); + hist16_CCAM (48000); hist16_CCAM.clear(); } @@ -1481,29 +1493,29 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int bool algepd = false; const bool epdEnabled = params->epd.enabled; - bool ciedata = (params->colorappearance.datacie && pW != 1) && !((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) + bool ciedata = (params->colorappearance.datacie && pW != 1) && ! ((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) || (params->dirpyrequalizer.enabled && settings->autocielab) || (params->defringe.enabled && settings->autocielab) || (params->sharpenMicro.enabled && settings->autocielab) || (params->impulseDenoise.enabled && settings->autocielab) || (params->colorappearance.badpixsl > 0 && settings->autocielab)); ColorTemp::temp2mulxyz (params->wb.temperature, params->wb.green, params->wb.method, Xw, Zw); //compute white Xw Yw Zw : white current WB //viewing condition for surround - if(params->colorappearance.surround == "Average") { + if (params->colorappearance.surround == "Average") { f = 1.00f; c = 0.69f; nc = 1.00f; f2 = 1.0f, c2 = 0.69f, nc2 = 1.0f; - } else if(params->colorappearance.surround == "Dim") { + } else if (params->colorappearance.surround == "Dim") { f2 = 0.9f; c2 = 0.59f; nc2 = 0.9f; f = 1.0f, c = 0.69f, nc = 1.0f; - } else if(params->colorappearance.surround == "Dark") { + } else if (params->colorappearance.surround == "Dark") { f2 = 0.8f; c2 = 0.525f; nc2 = 0.8f; f = 1.0f, c = 0.69f, nc = 1.0f; - } else if(params->colorappearance.surround == "ExtremelyDark") { + } else if (params->colorappearance.surround == "ExtremelyDark") { f2 = 0.8f; c2 = 0.41f; nc2 = 0.8f; @@ -1511,7 +1523,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } //scene condition for surround - if(params->colorappearance.surrsource) { + if (params->colorappearance.surrsource) { f = 0.85f; // if user => source image has surround very dark c = 0.55f; nc = 0.85f; @@ -1520,9 +1532,9 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int //with which algorithm if (params->colorappearance.algo == "JC") { alg = 0; - } else if(params->colorappearance.algo == "JS") { + } else if (params->colorappearance.algo == "JS") { alg = 1; - } else if(params->colorappearance.algo == "QM") { + } else if (params->colorappearance.algo == "QM") { alg = 2; algepd = true; } else { /*if(params->colorappearance.algo == "ALL")*/ @@ -1531,31 +1543,31 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } //settings white point of output device - or illuminant viewing - if(settings->viewingdevice == 0) { + if (settings->viewingdevice == 0) { xwd = 96.42f; //5000K ywd = 100.0f; zwd = 82.52f; - } else if(settings->viewingdevice == 1) { + } else if (settings->viewingdevice == 1) { xwd = 95.68f; //5500 ywd = 100.0f; zwd = 92.15f; - } else if(settings->viewingdevice == 2) { + } else if (settings->viewingdevice == 2) { xwd = 95.24f; //6000 ywd = 100.0f; zwd = 100.81f; - } else if(settings->viewingdevice == 3) { + } else if (settings->viewingdevice == 3) { xwd = 95.04f; //6500 ywd = 100.0f; zwd = 108.88f; - } else if(settings->viewingdevice == 4) { + } else if (settings->viewingdevice == 4) { xwd = 109.85f; //tungsten ywd = 100.0f; zwd = 35.58f; - } else if(settings->viewingdevice == 5) { + } else if (settings->viewingdevice == 5) { xwd = 99.18f; //fluo F2 ywd = 100.0f; zwd = 67.39f; - } else if(settings->viewingdevice == 6) { + } else if (settings->viewingdevice == 6) { xwd = 95.04f; //fluo F7 ywd = 100.0f; zwd = 108.75f; @@ -1567,32 +1579,36 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int //settings mean Luminance Y of output device or viewing - if(settings->viewingdevicegrey == 0) { + if (settings->viewingdevicegrey == 0) { yb2 = 5.0f; - } else if(settings->viewingdevicegrey == 1) { + } else if (settings->viewingdevicegrey == 1) { yb2 = 10.0f; - } else if(settings->viewingdevicegrey == 2) { + } else if (settings->viewingdevicegrey == 2) { yb2 = 15.0f; - } else if(settings->viewingdevicegrey == 3) { + } else if (settings->viewingdevicegrey == 3) { yb2 = 18.0f; - } else if(settings->viewingdevicegrey == 4) { + } else if (settings->viewingdevicegrey == 4) { yb2 = 23.0f; - } else if(settings->viewingdevicegrey == 5) { + } else if (settings->viewingdevicegrey == 5) { yb2 = 30.0f; } else { /* if(settings->viewingdevicegrey == 6)*/ yb2 = 40.0f; } //La and la2 = ambiant luminosity scene and viewing - la = float(params->colorappearance.adapscen); + la = float (params->colorappearance.adapscen); - if(pwb == 2) { - if(params->colorappearance.autoadapscen) { + if (pwb == 2) { + if (params->colorappearance.autoadapscen) { la = adap; } } - const float la2 = float(params->colorappearance.adaplum); + if (alg >= 2 && la < 200.f) { + la = 200.f; + } + + const float la2 = float (params->colorappearance.adaplum); // level of adaptation const float deg = (params->colorappearance.degree) / 100.0f; @@ -1601,33 +1617,33 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int //algoritm's params float chr = 0.f; - if(alg == 0 || alg == 3) { + if (alg == 0 || alg == 3) { chr = params->colorappearance.chroma; - if(chr == -100.0f) { + if (chr == -100.0f) { chr = -99.8f; } } float schr = 0.f; - if(alg == 3 || alg == 1) { + if (alg == 3 || alg == 1) { schr = params->colorappearance.schroma; - if(schr > 0.0) { + if (schr > 0.0) { schr = schr / 2.0f; //divide sensibility for saturation } - if(alg == 3) { - if(schr == -100.0f) { + if (alg == 3) { + if (schr == -100.0f) { schr = -99.f; } - if(schr == 100.0f) { + if (schr == 100.0f) { schr = 98.f; } } else { - if(schr == -100.0f) { + if (schr == -100.0f) { schr = -99.8f; } } @@ -1635,14 +1651,14 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float mchr = 0.f; - if(alg == 3 || alg == 2) { + if (alg == 3 || alg == 2) { mchr = params->colorappearance.mchroma; - if(mchr == -100.0f) { + if (mchr == -100.0f) { mchr = -99.8f ; } - if(mchr == 100.0f) { + if (mchr == 100.0f) { mchr = 99.9f; } } @@ -1652,21 +1668,21 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int // extracting datas from 'params' to avoid cache flush (to be confirmed) const ColorAppearanceParams::eTCModeId curveMode = params->colorappearance.curveMode; - const bool hasColCurve1 = bool(customColCurve1); + const bool hasColCurve1 = bool (customColCurve1); const bool t1L = hasColCurve1 && curveMode == ColorAppearanceParams::TC_MODE_LIGHT; const ColorAppearanceParams::eTCModeId curveMode2 = params->colorappearance.curveMode2; - const bool hasColCurve2 = bool(customColCurve2); + const bool hasColCurve2 = bool (customColCurve2); const ColorAppearanceParams::eCTCModeId curveMode3 = params->colorappearance.curveMode3; - const bool hasColCurve3 = bool(customColCurve3); + const bool hasColCurve3 = bool (customColCurve3); bool needJ = (alg == 0 || alg == 1 || alg == 3); bool needQ = (alg == 2 || alg == 3); LUTu hist16J; LUTu hist16Q; - if((needJ && CAMBrightCurveJ.dirty) || (needQ && CAMBrightCurveQ.dirty) || (std::isnan(mean) && settings->viewinggreySc != 0)) { + if ((needJ && CAMBrightCurveJ.dirty) || (needQ && CAMBrightCurveQ.dirty) || (std::isnan (mean) && settings->viewinggreySc != 0)) { if (needJ) { hist16J (32768); @@ -1681,7 +1697,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float sum = 0.f; #ifdef _OPENMP - const int numThreads = min(max(width * height / 65536, 1), omp_get_max_threads()); + const int numThreads = min (max (width * height / 65536, 1), omp_get_max_threads()); #pragma omp parallel num_threads(numThreads) if(numThreads>1) #endif { @@ -1689,12 +1705,12 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int LUTu hist16Qthr; if (needJ) { - hist16Jthr(hist16J.getSize()); + hist16Jthr (hist16J.getSize()); hist16Jthr.clear(); } if (needQ) { - hist16Qthr(hist16Q.getSize()); + hist16Qthr (hist16Q.getSize()); hist16Qthr.clear(); } @@ -1705,10 +1721,10 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float currL = lab->L[i][j] / 327.68f; float koef; //rough correspondence between L and J - if(currL > 50.f) { - if(currL > 70.f) { - if(currL > 80.f) { - if(currL > 85.f) { + if (currL > 50.f) { + if (currL > 70.f) { + if (currL > 80.f) { + if (currL > 85.f) { koef = 0.97f; } else { koef = 0.93f; @@ -1724,9 +1740,9 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } } } else { - if(currL > 10.f) { - if(currL > 20.f) { - if(currL > 40.f) { + if (currL > 10.f) { + if (currL > 20.f) { + if (currL > 40.f) { koef = 0.75f; } else { koef = 0.7f; @@ -1740,11 +1756,11 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } if (needJ) { - hist16Jthr[(int)((koef * lab->L[i][j]))]++; //evaluate histogram luminance L # J + hist16Jthr[ (int) ((koef * lab->L[i][j]))]++; //evaluate histogram luminance L # J } if (needQ) { - hist16Qthr[(int) (sqrtf((koef * (lab->L[i][j])) * 32768.f))]++; //for brightness Q : approximation for Q=wh*sqrt(J/100) J not equal L + hist16Qthr[ (int) (sqrtf ((koef * (lab->L[i][j])) * 32768.f))]++; //for brightness Q : approximation for Q=wh*sqrt(J/100) J not equal L } sum += koef * lab->L[i][j]; //evaluate mean J to calculate Yb @@ -1752,17 +1768,17 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int #pragma omp critical { - if(needJ) { + if (needJ) { hist16J += hist16Jthr; } - if(needQ) { + if (needQ) { hist16Q += hist16Qthr; } } - if(std::isnan(mean)) { + if (std::isnan (mean)) { mean = (sum / ((height) * width)) / 327.68f; //for Yb for all image...if one day "pipette" we can adapt Yb for each zone } } @@ -1772,31 +1788,31 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int //evaluate lightness, contrast } - if(settings->viewinggreySc == 0) { //auto + if (settings->viewinggreySc == 0) { //auto if (mean < 15.f) { yb = 3.0f; - } else if(mean < 30.f) { + } else if (mean < 30.f) { yb = 5.0f; - } else if(mean < 40.f) { + } else if (mean < 40.f) { yb = 10.0f; - } else if(mean < 45.f) { + } else if (mean < 45.f) { yb = 15.0f; - } else if(mean < 50.f) { + } else if (mean < 50.f) { yb = 18.0f; - } else if(mean < 55.f) { + } else if (mean < 55.f) { yb = 23.0f; - } else if(mean < 60.f) { + } else if (mean < 60.f) { yb = 30.0f; - } else if(mean < 70.f) { + } else if (mean < 70.f) { yb = 40.0f; - } else if(mean < 80.f) { + } else if (mean < 80.f) { yb = 60.0f; - } else if(mean < 90.f) { + } else if (mean < 90.f) { yb = 80.0f; } else { yb = 90.0f; } - } else if(settings->viewinggreySc == 1) { + } else if (settings->viewinggreySc == 1) { yb = 18.0f; //fixed } @@ -1809,14 +1825,14 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float xw1, yw1, zw1, xw2, yw2, zw2; // settings of WB: scene and viewing - if(params->colorappearance.wbmodel == "RawT") { + if (params->colorappearance.wbmodel == "RawT") { xw1 = 96.46f; //use RT WB; CAT 02 is used for output device (see prefreneces) yw1 = 100.0f; zw1 = 82.445f; xw2 = xwd; yw2 = ywd; zw2 = zwd; - } else /*if(params->colorappearance.wbmodel == "RawTCAT02")*/ { + } else { /*if(params->colorappearance.wbmodel == "RawTCAT02")*/ xw1 = xw; // Settings RT WB are used for CAT02 => mix , CAT02 is use for output device (screen: D50 D65, projector: lamp, LED) see preferences yw1 = yw; zw1 = zw; @@ -1826,12 +1842,12 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } float cz, wh, pfl; - Ciecam02::initcam1float(gamu, yb, pilot, f, la, xw, yw, zw, n, d, nbb, ncb, cz, aw, wh, pfl, fl, c); - const float pow1 = pow_F( 1.64f - pow_F( 0.29f, n ), 0.73f ); + Ciecam02::initcam1float (gamu, yb, pilot, f, la, xw, yw, zw, n, d, nbb, ncb, cz, aw, wh, pfl, fl, c); + const float pow1 = pow_F ( 1.64f - pow_F ( 0.29f, n ), 0.73f ); float nj, dj, nbbj, ncbj, czj, awj, flj; - Ciecam02::initcam2float(gamu, yb2, f2, la2, xw2, yw2, zw2, nj, dj, nbbj, ncbj, czj, awj, flj); + Ciecam02::initcam2float (gamu, yb2, f2, la2, xw2, yw2, zw2, nj, dj, nbbj, ncbj, czj, awj, flj); const float reccmcz = 1.f / (c2 * czj); - const float pow1n = pow_F( 1.64f - pow_F( 0.29f, nj ), 0.73f ); + const float pow1n = pow_F ( 1.64f - pow_F ( 0.29f, nj ), 0.73f ); const float epsil = 0.0001f; const float w_h = wh + epsil; @@ -1839,19 +1855,19 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int const float a_w = aw; const float c_ = c; const float f_l = fl; - const float coe = pow_F(fl, 0.25f); + const float coe = pow_F (fl, 0.25f); const float QproFactor = ( 0.4f / c ) * ( aw + 4.0f ) ; - const bool LabPassOne = !((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) - || (params->dirpyrequalizer.enabled && settings->autocielab) || (params->defringe.enabled && settings->autocielab) || (params->sharpenMicro.enabled && settings->autocielab) - || (params->impulseDenoise.enabled && settings->autocielab) || (params->colorappearance.badpixsl > 0 && settings->autocielab)); + const bool LabPassOne = ! ((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) + || (params->dirpyrequalizer.enabled && settings->autocielab) || (params->defringe.enabled && settings->autocielab) || (params->sharpenMicro.enabled && settings->autocielab) + || (params->impulseDenoise.enabled && settings->autocielab) || (params->colorappearance.badpixsl > 0 && settings->autocielab)); if (needJ) { if (!CAMBrightCurveJ) { - CAMBrightCurveJ(32768, LUT_CLIP_ABOVE); + CAMBrightCurveJ (32768, LUT_CLIP_ABOVE); } - if(CAMBrightCurveJ.dirty) { + if (CAMBrightCurveJ.dirty) { Ciecam02::curveJfloat (params->colorappearance.jlight, params->colorappearance.contrast, hist16J, CAMBrightCurveJ);//lightness and contrast J CAMBrightCurveJ /= 327.68f; CAMBrightCurveJ.dirty = false; @@ -1860,10 +1876,10 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int if (needQ) { if (!CAMBrightCurveQ) { - CAMBrightCurveQ(32768, LUT_CLIP_ABOVE); + CAMBrightCurveQ (32768, LUT_CLIP_ABOVE); } - if(CAMBrightCurveQ.dirty) { + if (CAMBrightCurveQ.dirty) { Ciecam02::curveJfloat (params->colorappearance.qbright, params->colorappearance.qcontrast, hist16Q, CAMBrightCurveQ);//brightness and contrast Q CAMBrightCurveQ /= coefQ; CAMBrightCurveQ.dirty = false; @@ -1874,9 +1890,9 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int //matrix for current working space TMatrix wiprof = ICCStore::getInstance()->workingSpaceInverseMatrix (params->icm.working); const float wip[3][3] = { - {(float)wiprof[0][0], (float)wiprof[0][1], (float)wiprof[0][2]}, - {(float)wiprof[1][0], (float)wiprof[1][1], (float)wiprof[1][2]}, - {(float)wiprof[2][0], (float)wiprof[2][1], (float)wiprof[2][2]} + { (float)wiprof[0][0], (float)wiprof[0][1], (float)wiprof[0][2]}, + { (float)wiprof[1][0], (float)wiprof[1][1], (float)wiprof[1][2]}, + { (float)wiprof[2][0], (float)wiprof[2][1], (float)wiprof[2][2]} }; #ifdef __SSE2__ @@ -1908,42 +1924,42 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int vfloat x, y, z; vfloat J, C, h, Q, M, s; - vfloat c655d35 = F2V(655.35f); + vfloat c655d35 = F2V (655.35f); - for(k = 0; k < width - 3; k += 4) { - Color::Lab2XYZ(LVFU(lab->L[i][k]), LVFU(lab->a[i][k]), LVFU(lab->b[i][k]), x, y, z); + for (k = 0; k < width - 3; k += 4) { + Color::Lab2XYZ (LVFU (lab->L[i][k]), LVFU (lab->a[i][k]), LVFU (lab->b[i][k]), x, y, z); x = x / c655d35; y = y / c655d35; z = z / c655d35; - Ciecam02::xyz2jchqms_ciecam02float( J, C, h, - Q, M, s, F2V(aw), F2V(fl), F2V(wh), - x, y, z, - F2V(xw1), F2V(yw1), F2V(zw1), - F2V(c), F2V(nc), F2V(pow1), F2V(nbb), F2V(ncb), F2V(pfl), F2V(cz), F2V(d)); - STVF(Jbuffer[k], J); - STVF(Cbuffer[k], C); - STVF(hbuffer[k], h); - STVF(Qbuffer[k], Q); - STVF(Mbuffer[k], M); - STVF(sbuffer[k], s); + Ciecam02::xyz2jchqms_ciecam02float ( J, C, h, + Q, M, s, F2V (aw), F2V (fl), F2V (wh), + x, y, z, + F2V (xw1), F2V (yw1), F2V (zw1), + F2V (c), F2V (nc), F2V (pow1), F2V (nbb), F2V (ncb), F2V (pfl), F2V (cz), F2V (d)); + STVF (Jbuffer[k], J); + STVF (Cbuffer[k], C); + STVF (hbuffer[k], h); + STVF (Qbuffer[k], Q); + STVF (Mbuffer[k], M); + STVF (sbuffer[k], s); } - for(; k < width; k++) { + for (; k < width; k++) { float L = lab->L[i][k]; float a = lab->a[i][k]; float b = lab->b[i][k]; float x, y, z; //convert Lab => XYZ - Color::Lab2XYZ(L, a, b, x, y, z); + Color::Lab2XYZ (L, a, b, x, y, z); x = x / 655.35f; y = y / 655.35f; z = z / 655.35f; float J, C, h, Q, M, s; - Ciecam02::xyz2jchqms_ciecam02float( J, C, h, - Q, M, s, aw, fl, wh, - x, y, z, - xw1, yw1, zw1, - c, nc, gamu, pow1, nbb, ncb, pfl, cz, d); + Ciecam02::xyz2jchqms_ciecam02float ( J, C, h, + Q, M, s, aw, fl, wh, + x, y, z, + xw1, yw1, zw1, + c, nc, gamu, pow1, nbb, ncb, pfl, cz, d); Jbuffer[k] = J; Cbuffer[k] = C; hbuffer[k] = h; @@ -1972,16 +1988,16 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float b = lab->b[i][j]; float x1, y1, z1; //convert Lab => XYZ - Color::Lab2XYZ(L, a, b, x1, y1, z1); + Color::Lab2XYZ (L, a, b, x1, y1, z1); x = (float)x1 / 655.35f; y = (float)y1 / 655.35f; z = (float)z1 / 655.35f; //process source==> normal - Ciecam02::xyz2jchqms_ciecam02float( J, C, h, - Q, M, s, aw, fl, wh, - x, y, z, - xw1, yw1, zw1, - c, nc, gamu, pow1, nbb, ncb, pfl, cz, d); + Ciecam02::xyz2jchqms_ciecam02float ( J, C, h, + Q, M, s, aw, fl, wh, + x, y, z, + xw1, yw1, zw1, + c, nc, gamu, pow1, nbb, ncb, pfl, cz, d); #endif float Jpro, Cpro, hpro, Qpro, Mpro, spro; Jpro = J; @@ -1992,75 +2008,75 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int spro = s; // we cannot have all algorithms with all chroma curves - if(alg == 0) { + if (alg == 0) { Jpro = CAMBrightCurveJ[Jpro * 327.68f]; //lightness CIECAM02 + contrast - Qpro = QproFactor * sqrtf(Jpro); + Qpro = QproFactor * sqrtf (Jpro); float Cp = (spro * spro * Qpro) / (1000000.f); Cpro = Cp * 100.f; float sres; - Ciecam02::curvecolorfloat(chr, Cp , sres, 1.8f); - Color::skinredfloat(Jpro, hpro, sres, Cp, 55.f, 30.f, 1, rstprotection, 100.f, Cpro); - } else if(alg == 1) { + Ciecam02::curvecolorfloat (chr, Cp , sres, 1.8f); + Color::skinredfloat (Jpro, hpro, sres, Cp, 55.f, 30.f, 1, rstprotection, 100.f, Cpro); + } else if (alg == 1) { // Lightness saturation Jpro = CAMBrightCurveJ[Jpro * 327.68f]; //lightness CIECAM02 + contrast float sres; float Sp = spro / 100.0f; float parsat = 1.5f; //parsat=1.5 =>saturation ; 1.8 => chroma ; 2.5 => colorfullness (personal evaluation) - Ciecam02::curvecolorfloat(schr, Sp , sres, parsat); + Ciecam02::curvecolorfloat (schr, Sp , sres, parsat); float dred = 100.f; // in C mode float protect_red = 80.0f; // in C mode - dred = 100.0f * sqrtf((dred * coe) / Qpro); - protect_red = 100.0f * sqrtf((protect_red * coe) / Qpro); - Color::skinredfloat(Jpro, hpro, sres, Sp, dred, protect_red, 0, rstprotection, 100.f, spro); - Qpro = QproFactor * sqrtf(Jpro); + dred = 100.0f * sqrtf ((dred * coe) / Qpro); + protect_red = 100.0f * sqrtf ((protect_red * coe) / Qpro); + Color::skinredfloat (Jpro, hpro, sres, Sp, dred, protect_red, 0, rstprotection, 100.f, spro); + Qpro = QproFactor * sqrtf (Jpro); Cpro = (spro * spro * Qpro) / (10000.0f); - } else if(alg == 2) { - Qpro = CAMBrightCurveQ[(float)(Qpro * coefQ)]; //brightness and contrast + } else if (alg == 2) { + Qpro = CAMBrightCurveQ[ (float) (Qpro * coefQ)]; //brightness and contrast float Mp, sres; Mp = Mpro / 100.0f; - Ciecam02::curvecolorfloat(mchr, Mp , sres, 2.5f); + Ciecam02::curvecolorfloat (mchr, Mp , sres, 2.5f); float dred = 100.f; //in C mode float protect_red = 80.0f; // in C mode dred *= coe; //in M mode protect_red *= coe; //M mode - Color::skinredfloat(Jpro, hpro, sres, Mp, dred, protect_red, 0, rstprotection, 100.f, Mpro); - Jpro = SQR((10.f * Qpro) / wh); + Color::skinredfloat (Jpro, hpro, sres, Mp, dred, protect_red, 0, rstprotection, 100.f, Mpro); + Jpro = SQR ((10.f * Qpro) / wh); Cpro = Mpro / coe; Qpro = (Qpro == 0.f ? epsil : Qpro); // avoid division by zero - spro = 100.0f * sqrtf( Mpro / Qpro ); + spro = 100.0f * sqrtf ( Mpro / Qpro ); } else { /*if(alg == 3) */ - Qpro = CAMBrightCurveQ[(float)(Qpro * coefQ)]; //brightness and contrast + Qpro = CAMBrightCurveQ[ (float) (Qpro * coefQ)]; //brightness and contrast float Mp, sres; Mp = Mpro / 100.0f; - Ciecam02::curvecolorfloat(mchr, Mp , sres, 2.5f); + Ciecam02::curvecolorfloat (mchr, Mp , sres, 2.5f); float dred = 100.f; //in C mode float protect_red = 80.0f; // in C mode dred *= coe; //in M mode protect_red *= coe; //M mode - Color::skinredfloat(Jpro, hpro, sres, Mp, dred, protect_red, 0, rstprotection, 100.f, Mpro); - Jpro = SQR((10.f * Qpro) / wh); + Color::skinredfloat (Jpro, hpro, sres, Mp, dred, protect_red, 0, rstprotection, 100.f, Mpro); + Jpro = SQR ((10.f * Qpro) / wh); Cpro = Mpro / coe; Qpro = (Qpro == 0.f ? epsil : Qpro); // avoid division by zero - spro = 100.0f * sqrtf( Mpro / Qpro ); + spro = 100.0f * sqrtf ( Mpro / Qpro ); - if(Jpro > 99.9f) { + if (Jpro > 99.9f) { Jpro = 99.9f; } - Jpro = CAMBrightCurveJ[(float)(Jpro * 327.68f)]; //lightness CIECAM02 + contrast + Jpro = CAMBrightCurveJ[ (float) (Jpro * 327.68f)]; //lightness CIECAM02 + contrast float Sp = spro / 100.0f; - Ciecam02::curvecolorfloat(schr, Sp , sres, 1.5f); + Ciecam02::curvecolorfloat (schr, Sp , sres, 1.5f); dred = 100.f; // in C mode protect_red = 80.0f; // in C mode - dred = 100.0f * sqrtf((dred * coe) / Q); - protect_red = 100.0f * sqrtf((protect_red * coe) / Q); - Color::skinredfloat(Jpro, hpro, sres, Sp, dred, protect_red, 0, rstprotection, 100.f, spro); - Qpro = QproFactor * sqrtf(Jpro); + dred = 100.0f * sqrtf ((dred * coe) / Q); + protect_red = 100.0f * sqrtf ((protect_red * coe) / Q); + Color::skinredfloat (Jpro, hpro, sres, Sp, dred, protect_red, 0, rstprotection, 100.f, spro); + Qpro = QproFactor * sqrtf (Jpro); float Cp = (spro * spro * Qpro) / (1000000.f); Cpro = Cp * 100.f; - Ciecam02::curvecolorfloat(chr, Cp , sres, 1.8f); - Color::skinredfloat(Jpro, hpro, sres, Cp, 55.f, 30.f, 1, rstprotection, 100.f, Cpro); + Ciecam02::curvecolorfloat (chr, Cp , sres, 1.8f); + Color::skinredfloat (Jpro, hpro, sres, Cp, 55.f, 30.f, 1, rstprotection, 100.f, Cpro); // disabled this code, Issue 2690 // if(Jpro < 1.f && Cpro > 12.f) Cpro=12.f;//reduce artifacts by "pseudo gamut control CIECAM" // else if(Jpro < 2.f && Cpro > 15.f) Cpro=15.f; @@ -2068,7 +2084,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int // else if(Jpro < 7.f && Cpro > 50.f) Cpro=50.f; hpro = hpro + hue; - if( hpro < 0.0f ) { + if ( hpro < 0.0f ) { hpro += 360.0f; //hue } } @@ -2080,27 +2096,27 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float Jold100 = (float) Jpro; float redu = 25.f; float reduc = 1.f; - const Lightcurve& userColCurveJ1 = static_cast(customColCurve1); - userColCurveJ1.Apply(Jj); + const Lightcurve& userColCurveJ1 = static_cast (customColCurve1); + userColCurveJ1.Apply (Jj); - if(Jj > Jold) { - if(Jj < 65535.f) { - if(Jold < 327.68f * redu) { + if (Jj > Jold) { + if (Jj < 65535.f) { + if (Jold < 327.68f * redu) { Jj = 0.3f * (Jj - Jold) + Jold; //divide sensibility } else { - reduc = LIM((100.f - Jold100) / (100.f - redu), 0.f, 1.f); + reduc = LIM ((100.f - Jold100) / (100.f - redu), 0.f, 1.f); Jj = 0.3f * reduc * (Jj - Jold) + Jold; //reduct sensibility in highlights } } - } else if(Jj > 10.f) { + } else if (Jj > 10.f) { Jj = 0.8f * (Jj - Jold) + Jold; } else if (Jj >= 0.f) { Jj = 0.90f * (Jj - Jold) + Jold; // not zero ==>artifacts } - Jpro = (float)(Jj / 327.68f); + Jpro = (float) (Jj / 327.68f); - if(Jpro < 1.f) { + if (Jpro < 1.f) { Jpro = 1.f; } } else if (curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { @@ -2113,28 +2129,28 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float redu = 20.f; float reduc = 1.f; - const Brightcurve& userColCurveB1 = static_cast(customColCurve1); - userColCurveB1.Apply(Qq); + const Brightcurve& userColCurveB1 = static_cast (customColCurve1); + userColCurveB1.Apply (Qq); - if(Qq > Qold) { - if(Qq < 65535.f) { - if(Qold < 327.68f * redu) { + if (Qq > Qold) { + if (Qq < 65535.f) { + if (Qold < 327.68f * redu) { Qq = 0.25f * (Qq - Qold) + Qold; //divide sensibility } else { - reduc = LIM((100.f - Qold100) / (100.f - redu), 0.f, 1.f); + reduc = LIM ((100.f - Qold100) / (100.f - redu), 0.f, 1.f); Qq = 0.25f * reduc * (Qq - Qold) + Qold; //reduct sensibility in highlights } } - } else if(Qq > 10.f) { + } else if (Qq > 10.f) { Qq = 0.5f * (Qq - Qold) + Qold; } else if (Qq >= 0.f) { Qq = 0.7f * (Qq - Qold) + Qold; // not zero ==>artifacts } - Qpro = (float)(Qq * (coef) / 327.68f); + Qpro = (float) (Qq * (coef) / 327.68f); Jpro = 100.f * (Qpro * Qpro) / ((4.0f / c) * (4.0f / c) * (aw + 4.0f) * (aw + 4.0f)); - if(Jpro < 1.f) { + if (Jpro < 1.f) { Jpro = 1.f; } } @@ -2147,35 +2163,35 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float Jold100 = (float) Jpro; float redu = 25.f; float reduc = 1.f; - const Lightcurve& userColCurveJ2 = static_cast(customColCurve2); - userColCurveJ2.Apply(Jj); + const Lightcurve& userColCurveJ2 = static_cast (customColCurve2); + userColCurveJ2.Apply (Jj); - if(Jj > Jold) { - if(Jj < 65535.f) { - if(Jold < 327.68f * redu) { + if (Jj > Jold) { + if (Jj < 65535.f) { + if (Jold < 327.68f * redu) { Jj = 0.3f * (Jj - Jold) + Jold; //divide sensibility } else { - reduc = LIM((100.f - Jold100) / (100.f - redu), 0.f, 1.f); + reduc = LIM ((100.f - Jold100) / (100.f - redu), 0.f, 1.f); Jj = 0.3f * reduc * (Jj - Jold) + Jold; //reduct sensibility in highlights } } - } else if(Jj > 10.f) { - if(!t1L) { + } else if (Jj > 10.f) { + if (!t1L) { Jj = 0.8f * (Jj - Jold) + Jold; } else { Jj = 0.4f * (Jj - Jold) + Jold; } } else if (Jj >= 0.f) { - if(!t1L) { + if (!t1L) { Jj = 0.90f * (Jj - Jold) + Jold; // not zero ==>artifacts } else { Jj = 0.5f * (Jj - Jold) + Jold; } } - Jpro = (float)(Jj / 327.68f); + Jpro = (float) (Jj / 327.68f); - if(Jpro < 1.f) { + if (Jpro < 1.f) { Jpro = 1.f; } @@ -2188,39 +2204,39 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float redu = 20.f; float reduc = 1.f; - const Brightcurve& userColCurveB2 = static_cast(customColCurve2); - userColCurveB2.Apply(Qq); + const Brightcurve& userColCurveB2 = static_cast (customColCurve2); + userColCurveB2.Apply (Qq); - if(Qq > Qold) { - if(Qq < 65535.f) { - if(Qold < 327.68f * redu) { + if (Qq > Qold) { + if (Qq < 65535.f) { + if (Qold < 327.68f * redu) { Qq = 0.25f * (Qq - Qold) + Qold; //divide sensibility } else { - reduc = LIM((100.f - Qold100) / (100.f - redu), 0.f, 1.f); + reduc = LIM ((100.f - Qold100) / (100.f - redu), 0.f, 1.f); Qq = 0.25f * reduc * (Qq - Qold) + Qold; //reduct sensibility in highlights } } - } else if(Qq > 10.f) { + } else if (Qq > 10.f) { Qq = 0.5f * (Qq - Qold) + Qold; } else if (Qq >= 0.f) { Qq = 0.7f * (Qq - Qold) + Qold; // not zero ==>artifacts } - Qpro = (float)(Qq * (coef) / 327.68f); + Qpro = (float) (Qq * (coef) / 327.68f); Jpro = 100.f * (Qpro * Qpro) / ((4.0f / c) * (4.0f / c) * (aw + 4.0f) * (aw + 4.0f)); - if(t1L) { //to workaround the problem if we modify curve1-lightnees after curve2 brightness(the cat that bites its own tail!) in fact it's another type of curve only for this case + if (t1L) { //to workaround the problem if we modify curve1-lightnees after curve2 brightness(the cat that bites its own tail!) in fact it's another type of curve only for this case coef = 2.f; //adapt Q to J approximation Qq = (float) Qpro * coef; Qold = Qq; - const Lightcurve& userColCurveJ1 = static_cast(customColCurve1); - userColCurveJ1.Apply(Qq); + const Lightcurve& userColCurveJ1 = static_cast (customColCurve1); + userColCurveJ1.Apply (Qq); Qq = 0.05f * (Qq - Qold) + Qold; //approximative adaptation - Qpro = (float)(Qq / coef); + Qpro = (float) (Qq / coef); Jpro = 100.f * (Qpro * Qpro) / ((4.0f / c) * (4.0f / c) * (aw + 4.0f) * (aw + 4.0f)); } - if(Jpro < 1.f) { + if (Jpro < 1.f) { Jpro = 1.f; } } @@ -2232,13 +2248,13 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float coef = 327.68f / parsat; float Cc = (float) Cpro * coef; float Ccold = Cc; - const Chromacurve& userColCurve = static_cast(customColCurve3); - userColCurve.Apply(Cc); + const Chromacurve& userColCurve = static_cast (customColCurve3); + userColCurve.Apply (Cc); float dred = 55.f; float protect_red = 30.0f; int sk = 1; float ko = 1.f / coef; - Color::skinredfloat(Jpro, hpro, Cc, Ccold, dred, protect_red, sk, rstprotection, ko, Cpro); + Color::skinredfloat (Jpro, hpro, Cc, Ccold, dred, protect_red, sk, rstprotection, ko, Cpro); /* if(Jpro < 1.f && Cpro > 12.f) { Cpro = 12.f; //reduce artifacts by "pseudo gamut control CIECAM" @@ -2255,32 +2271,32 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float coef = 327.68f / parsat; float Ss = (float) spro * coef; float Sold = Ss; - const Saturcurve& userColCurve = static_cast(customColCurve3); - userColCurve.Apply(Ss); + const Saturcurve& userColCurve = static_cast (customColCurve3); + userColCurve.Apply (Ss); Ss = 0.6f * (Ss - Sold) + Sold; //divide sensibility saturation float dred = 100.f; // in C mode float protect_red = 80.0f; // in C mode - dred = 100.0f * sqrtf((dred * coe) / Qpro); - protect_red = 100.0f * sqrtf((protect_red * coe) / Qpro); + dred = 100.0f * sqrtf ((dred * coe) / Qpro); + protect_red = 100.0f * sqrtf ((protect_red * coe) / Qpro); int sk = 0; float ko = 1.f / coef; - Color::skinredfloat(Jpro, hpro, Ss, Sold, dred, protect_red, sk, rstprotection, ko, spro); - Qpro = ( 4.0f / c ) * sqrtf( Jpro / 100.0f ) * ( aw + 4.0f ) ; + Color::skinredfloat (Jpro, hpro, Ss, Sold, dred, protect_red, sk, rstprotection, ko, spro); + Qpro = ( 4.0f / c ) * sqrtf ( Jpro / 100.0f ) * ( aw + 4.0f ) ; Cpro = (spro * spro * Qpro) / (10000.0f); } else if (curveMode3 == ColorAppearanceParams::TC_MODE_COLORF) { // float parsat = 0.8f; //0.68; float coef = 327.68f / parsat; float Mm = (float) Mpro * coef; float Mold = Mm; - const Colorfcurve& userColCurve = static_cast(customColCurve3); - userColCurve.Apply(Mm); + const Colorfcurve& userColCurve = static_cast (customColCurve3); + userColCurve.Apply (Mm); float dred = 100.f; //in C mode float protect_red = 80.0f; // in C mode dred *= coe; //in M mode protect_red *= coe; int sk = 0; float ko = 1.f / coef; - Color::skinredfloat(Jpro, hpro, Mm, Mold, dred, protect_red, sk, rstprotection, ko, Mpro); + Color::skinredfloat (Jpro, hpro, Mm, Mold, dred, protect_red, sk, rstprotection, ko, Mpro); /* if(Jpro < 1.f && Mpro > 12.f * coe) { Mpro = 12.f * coe; //reduce artifacts by "pseudo gamut control CIECAM" @@ -2307,28 +2323,28 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int h = hpro; s = spro; - if(params->colorappearance.tonecie || settings->autocielab) { //use pointer for tonemapping with CIECAM and also sharpening , defringe, contrast detail + if (params->colorappearance.tonecie || settings->autocielab) { //use pointer for tonemapping with CIECAM and also sharpening , defringe, contrast detail ncie->Q_p[i][j] = (float)Q + epsil; //epsil to avoid Q=0 ncie->M_p[i][j] = (float)M + epsil; ncie->J_p[i][j] = (float)J + epsil; ncie->h_p[i][j] = (float)h; ncie->C_p[i][j] = (float)C + epsil; - ncie->sh_p[i][j] = (float) 3276.8f * (sqrtf( J ) ) ; + ncie->sh_p[i][j] = (float) 3276.8f * (sqrtf ( J ) ) ; - if(epdEnabled) { - if(ncie->Q_p[i][j] < minQThr) { + if (epdEnabled) { + if (ncie->Q_p[i][j] < minQThr) { minQThr = ncie->Q_p[i][j]; //minima } - if(ncie->Q_p[i][j] > maxQThr) { + if (ncie->Q_p[i][j] > maxQThr) { maxQThr = ncie->Q_p[i][j]; //maxima } } } - if(!params->colorappearance.tonecie || !settings->autocielab || !epdEnabled) { + if (!params->colorappearance.tonecie || !settings->autocielab || !epdEnabled) { - if(ciedata) { //only with improccoordinator + if (ciedata) { //only with improccoordinator // Data for J Q M s and C histograms int posl, posc; float brli = 327.f; @@ -2337,7 +2353,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float colch; //update histogram - if(curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { + if (curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { brli = 70.0f; libr = Q; //40.0 to 100.0 approximative factor for Q - 327 for J } else { /*if(curveMode == ColorAppearanceParams::TC_MODE_LIGHT)*/ @@ -2345,26 +2361,26 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int libr = J; //327 for J } - posl = (int)(libr * brli); + posl = (int) (libr * brli); hist16JCAM[posl]++; if (curveMode3 == ColorAppearanceParams::TC_MODE_CHROMA) { - chsacol = 327.f; + chsacol = 400.f;//327 colch = C; //450.0 approximative factor for s 320 for M - } else if(curveMode3 == ColorAppearanceParams::TC_MODE_SATUR) { + } else if (curveMode3 == ColorAppearanceParams::TC_MODE_SATUR) { chsacol = 450.0f; colch = s; } else { /*if(curveMode3 == ColorAppearanceParams::TC_MODE_COLORF)*/ - chsacol = 327.0f; + chsacol = 400.0f;//327 colch = M; } - posc = (int)(colch * chsacol); + posc = (int) (colch * chsacol); hist16_CCAM[posc]++; } - if(LabPassOne) { + if (LabPassOne) { #ifdef __SSE2__ // write to line buffers Jbuffer[j] = J; @@ -2374,27 +2390,27 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float xx, yy, zz; //process normal==> viewing - Ciecam02::jch2xyz_ciecam02float( xx, yy, zz, - J, C, h, - xw2, yw2, zw2, - f2, c2, nc2, gamu, pow1n, nbbj, ncbj, flj, czj, dj, awj); + Ciecam02::jch2xyz_ciecam02float ( xx, yy, zz, + J, C, h, + xw2, yw2, zw2, + f2, c2, nc2, gamu, pow1n, nbbj, ncbj, flj, czj, dj, awj); float x, y, z; x = xx * 655.35f; y = yy * 655.35f; z = zz * 655.35f; float Ll, aa, bb; //convert xyz=>lab - Color::XYZ2Lab(x, y, z, Ll, aa, bb); + Color::XYZ2Lab (x, y, z, Ll, aa, bb); // gamut control in Lab mode; I must study how to do with cIECAM only - if(gamu == 1) { + if (gamu == 1) { float HH, Lprov1, Chprov1; Lprov1 = Ll / 327.68f; - Chprov1 = sqrtf(SQR(aa) + SQR(bb)) / 327.68f; - HH = xatan2f(bb, aa); + Chprov1 = sqrtf (SQR (aa) + SQR (bb)) / 327.68f; + HH = xatan2f (bb, aa); float2 sincosval; - if(Chprov1 == 0.0f) { + if (Chprov1 == 0.0f) { sincosval.y = 1.f; sincosval.x = 0.0f; } else { @@ -2407,10 +2423,10 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f); + Color::gamutLchonly (sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f); #endif lab->L[i][j] = Lprov1 * 327.68f; @@ -2434,31 +2450,31 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float *ybuffer = Mbuffer; float *zbuffer = sbuffer; - for(k = 0; k < bufferLength; k += 4) { - Ciecam02::jch2xyz_ciecam02float( x, y, z, - LVF(Jbuffer[k]), LVF(Cbuffer[k]), LVF(hbuffer[k]), - F2V(xw2), F2V(yw2), F2V(zw2), - F2V(f2), F2V(nc2), F2V(pow1n), F2V(nbbj), F2V(ncbj), F2V(flj), F2V(dj), F2V(awj), F2V(reccmcz)); - STVF(xbuffer[k], x * c655d35); - STVF(ybuffer[k], y * c655d35); - STVF(zbuffer[k], z * c655d35); + for (k = 0; k < bufferLength; k += 4) { + Ciecam02::jch2xyz_ciecam02float ( x, y, z, + LVF (Jbuffer[k]), LVF (Cbuffer[k]), LVF (hbuffer[k]), + F2V (xw2), F2V (yw2), F2V (zw2), + F2V (f2), F2V (nc2), F2V (pow1n), F2V (nbbj), F2V (ncbj), F2V (flj), F2V (dj), F2V (awj), F2V (reccmcz)); + STVF (xbuffer[k], x * c655d35); + STVF (ybuffer[k], y * c655d35); + STVF (zbuffer[k], z * c655d35); } // XYZ2Lab uses a lookup table. The function behind that lut is a cube root. // SSE can't beat the speed of that lut, so it doesn't make sense to use SSE - for(int j = 0; j < width; j++) { + for (int j = 0; j < width; j++) { float Ll, aa, bb; //convert xyz=>lab - Color::XYZ2Lab(xbuffer[j], ybuffer[j], zbuffer[j], Ll, aa, bb); + Color::XYZ2Lab (xbuffer[j], ybuffer[j], zbuffer[j], Ll, aa, bb); // gamut control in Lab mode; I must study how to do with cIECAM only - if(gamu == 1) { + if (gamu == 1) { float Lprov1, Chprov1; Lprov1 = Ll / 327.68f; - Chprov1 = sqrtf(SQR(aa) + SQR(bb)) / 327.68f; + Chprov1 = sqrtf (SQR (aa) + SQR (bb)) / 327.68f; float2 sincosval; - if(Chprov1 == 0.0f) { + if (Chprov1 == 0.0f) { sincosval.y = 1.f; sincosval.x = 0.0f; } else { @@ -2470,10 +2486,10 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f); + Color::gamutLchonly (sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f); #endif lab->L[i][j] = Lprov1 * 327.68f; lab->a[i][j] = 327.68f * Chprov1 * sincosval.y; @@ -2490,24 +2506,24 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int #pragma omp critical { - if(minQThr < minQ) { + if (minQThr < minQ) { minQ = minQThr; } - if(maxQThr > maxQ) { + if (maxQThr > maxQ) { maxQ = maxQThr; } } } // End of parallelization - if(!params->colorappearance.tonecie || !settings->autocielab) { //normal + if (!params->colorappearance.tonecie || !settings->autocielab) { //normal - if(ciedata) { + if (ciedata) { //update histogram J - hist16JCAM.compressTo(histLCAM); + hist16JCAM.compressTo (histLCAM); //update histogram C - hist16_CCAM.compressTo(histCCAM); + hist16_CCAM.compressTo (histCCAM); } } @@ -2515,14 +2531,14 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int if (settings->verbose) { t2e.set(); - printf("CIECAM02 performed in %d usec:\n", t2e.etime(t1e)); + printf ("CIECAM02 performed in %d usec:\n", t2e.etime (t1e)); // printf("minc=%f maxc=%f minj=%f maxj=%f\n",minc,maxc,minj,maxj); } #endif - if(settings->autocielab) { - if((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) + if (settings->autocielab) { + if ((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) || (params->dirpyrequalizer.enabled && settings->autocielab) || (params->defringe.enabled && settings->autocielab) || (params->sharpenMicro.enabled && settings->autocielab) || (params->impulseDenoise.enabled && settings->autocielab) || (params->colorappearance.badpixsl > 0 && settings->autocielab)) { @@ -2530,27 +2546,27 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int //all this treatments reduce artefacts, but can leed to slighty different results - if(params->defringe.enabled) - if(execsharp) { + if (params->defringe.enabled) + if (execsharp) { lab->deleteLab(); ImProcFunctions::defringecam (ncie);//defringe adapted to CIECAM lab->reallocLab(); } //if(params->dirpyrequalizer.enabled) if(execsharp) { - if(params->dirpyrequalizer.enabled) { - if(params->dirpyrequalizer.gamutlab /*&& execsharp*/) {//remove artifacts by gaussian blur - skin control - float b_l = static_cast(params->dirpyrequalizer.hueskin.value[0]) / 100.0f; - float t_l = static_cast(params->dirpyrequalizer.hueskin.value[1]) / 100.0f; - float b_r = static_cast(params->dirpyrequalizer.hueskin.value[2]) / 100.0f; - float t_r = static_cast(params->dirpyrequalizer.hueskin.value[3]) / 100.0f; + if (params->dirpyrequalizer.enabled) { + if (params->dirpyrequalizer.gamutlab /*&& execsharp*/) { //remove artifacts by gaussian blur - skin control + float b_l = static_cast (params->dirpyrequalizer.hueskin.value[0]) / 100.0f; + float t_l = static_cast (params->dirpyrequalizer.hueskin.value[1]) / 100.0f; + float b_r = static_cast (params->dirpyrequalizer.hueskin.value[2]) / 100.0f; + float t_r = static_cast (params->dirpyrequalizer.hueskin.value[3]) / 100.0f; float artifact = (float) settings->artifact_cbdl; - if(artifact > 6.f) { + if (artifact > 6.f) { artifact = 6.f; } - if(artifact < 0.f) { + if (artifact < 0.f) { artifact = 1.f; } @@ -2563,14 +2579,14 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } //if(params->colorappearance.badpixsl > 0) { int mode=params->colorappearance.badpixsl; - if(params->colorappearance.badpixsl > 0) if(execsharp) { + if (params->colorappearance.badpixsl > 0) if (execsharp) { int mode = params->colorappearance.badpixsl; lab->deleteLab(); ImProcFunctions::badpixcam (ncie, 3.0, 10, mode, 0, 0, 0, 0, 0, 0, 1);//for bad pixels CIECAM lab->reallocLab(); } - if(params->impulseDenoise.enabled) if(execsharp) { + if (params->impulseDenoise.enabled) if (execsharp) { float **buffers[3]; buffers[0] = lab->L; buffers[1] = lab->a; @@ -2578,29 +2594,29 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int ImProcFunctions::impulsedenoisecam (ncie, buffers); //impulse adapted to CIECAM } - if (params->sharpenMicro.enabled)if(execsharp) { - ImProcFunctions::MLmicrocontrastcam(ncie); + if (params->sharpenMicro.enabled)if (execsharp) { + ImProcFunctions::MLmicrocontrastcam (ncie); } - if(params->sharpening.enabled) - if(execsharp) { + if (params->sharpening.enabled) + if (execsharp) { float **buffer = lab->L; // We can use the L-buffer from lab as buffer to save some memory ImProcFunctions::sharpeningcam (ncie, buffer); // sharpening adapted to CIECAM } //if(params->dirpyrequalizer.enabled) if(execsharp) { - if(params->dirpyrequalizer.enabled /*&& execsharp*/) { + if (params->dirpyrequalizer.enabled /*&& execsharp*/) { // if(params->dirpyrequalizer.algo=="FI") choice=0; // else if(params->dirpyrequalizer.algo=="LA") choice=1; - if(rtt == 1) { - float b_l = static_cast(params->dirpyrequalizer.hueskin.value[0]) / 100.0f; - float t_l = static_cast(params->dirpyrequalizer.hueskin.value[1]) / 100.0f; - float b_r = static_cast(params->dirpyrequalizer.hueskin.value[2]) / 100.0f; - float t_r = static_cast(params->dirpyrequalizer.hueskin.value[3]) / 100.0f; + if (rtt == 1) { + float b_l = static_cast (params->dirpyrequalizer.hueskin.value[0]) / 100.0f; + float t_l = static_cast (params->dirpyrequalizer.hueskin.value[1]) / 100.0f; + float b_r = static_cast (params->dirpyrequalizer.hueskin.value[2]) / 100.0f; + float t_r = static_cast (params->dirpyrequalizer.hueskin.value[3]) / 100.0f; int choice = 0; // I have not suppress this statement in case of !! always to 0 lab->deleteLab(); - dirpyr_equalizercam(ncie, ncie->sh_p, ncie->sh_p, ncie->W, ncie->H, ncie->h_p, ncie->C_p, params->dirpyrequalizer.mult, params->dirpyrequalizer.threshold, params->dirpyrequalizer.skinprotect, true, params->dirpyrequalizer.gamutlab, b_l, t_l, t_r, b_r, choice, scalecd); //contrast by detail adapted to CIECAM + dirpyr_equalizercam (ncie, ncie->sh_p, ncie->sh_p, ncie->W, ncie->H, ncie->h_p, ncie->C_p, params->dirpyrequalizer.mult, params->dirpyrequalizer.threshold, params->dirpyrequalizer.skinprotect, true, params->dirpyrequalizer.gamutlab, b_l, t_l, t_r, b_r, choice, scalecd); //contrast by detail adapted to CIECAM lab->reallocLab(); } @@ -2613,7 +2629,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } const float Qredi = ( 4.0f / c_) * ( a_w + 4.0f ); - const float co_e = (pow_F(f_l, 0.25f)); + const float co_e = (pow_F (f_l, 0.25f)); #ifndef _DEBUG @@ -2626,8 +2642,8 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int for (int i = 0; i < height; i++) // update CieImages with new values after sharpening, defringe, contrast by detail level for (int j = 0; j < width; j++) { - float interm = fabsf(ncie->sh_p[i][j] / (32768.f)); - ncie->J_p[i][j] = 100.0f * SQR(interm); + float interm = fabsf (ncie->sh_p[i][j] / (32768.f)); + ncie->J_p[i][j] = 100.0f * SQR (interm); ncie->Q_p[i][j] = interm * Qredi; ncie->M_p[i][j] = ncie->C_p[i][j] * co_e; } @@ -2635,15 +2651,15 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } } - if((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) + if ((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) || (params->dirpyrequalizer.enabled && settings->autocielab) || (params->defringe.enabled && settings->autocielab) || (params->sharpenMicro.enabled && settings->autocielab) || (params->impulseDenoise.enabled && settings->autocielab) || (params->colorappearance.badpixsl > 0 && settings->autocielab)) { ciedata = (params->colorappearance.datacie && pW != 1); - if(epdEnabled && params->colorappearance.tonecie && algepd) { + if (epdEnabled && params->colorappearance.tonecie && algepd) { lab->deleteLab(); - ImProcFunctions::EPDToneMapCIE(ncie, a_w, c_, w_h, width, height, begh, endh, minQ, maxQ, Iterates, scale ); + ImProcFunctions::EPDToneMapCIE (ncie, a_w, c_, w_h, width, height, begh, endh, minQ, maxQ, Iterates, scale ); lab->reallocLab(); } @@ -2651,7 +2667,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int constexpr float eps = 0.0001f; - const float co_e = (pow_F(f_l, 0.25f)) + eps; + const float co_e = (pow_F (f_l, 0.25f)) + eps; #ifndef _DEBUG #pragma omp parallel @@ -2675,14 +2691,14 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int for (int j = 0; j < width; j++) { // if(epdEnabled) ncie->J_p[i][j]=(100.0f* ncie->Q_p[i][j]*ncie->Q_p[i][j])/(w_h*w_h); - if(epdEnabled) { - ncie->J_p[i][j] = (100.0f * ncie->Q_p[i][j] * ncie->Q_p[i][j]) / SQR((4.f / c) * (aw + 4.f)); + if (epdEnabled) { + ncie->J_p[i][j] = (100.0f * ncie->Q_p[i][j] * ncie->Q_p[i][j]) / SQR ((4.f / c) * (aw + 4.f)); } const float ncie_C_p = (ncie->M_p[i][j]) / co_e; //show histogram in CIECAM mode (Q,J, M,s,C) - if(ciedata) { + if (ciedata) { // Data for J Q M s and C histograms int posl, posc; float brli = 327.f; @@ -2690,7 +2706,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float libr; float colch; - if(curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { + if (curveMode == ColorAppearanceParams::TC_MODE_BRIGHT) { brli = 70.0f; libr = ncie->Q_p[i][j]; //40.0 to 100.0 approximative factor for Q - 327 for J } else { /*if(curveMode == ColorAppearanceParams::TC_MODE_LIGHT)*/ @@ -2698,21 +2714,21 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int libr = ncie->J_p[i][j]; //327 for J } - posl = (int)(libr * brli); + posl = (int) (libr * brli); hist16JCAM[posl]++; if (curveMode3 == ColorAppearanceParams::TC_MODE_CHROMA) { chsacol = 327.f; colch = ncie_C_p; - } else if(curveMode3 == ColorAppearanceParams::TC_MODE_SATUR) { + } else if (curveMode3 == ColorAppearanceParams::TC_MODE_SATUR) { chsacol = 450.0f; - colch = 100.f * sqrtf(ncie_C_p / ncie->Q_p[i][j]); + colch = 100.f * sqrtf (ncie_C_p / ncie->Q_p[i][j]); } else { /*if(curveMode3 == ColorAppearanceParams::TC_MODE_COLORF)*/ chsacol = 327.0f; colch = ncie->M_p[i][j]; } - posc = (int)(colch * chsacol); + posc = (int) (colch * chsacol); hist16_CCAM[posc]++; } @@ -2724,24 +2740,24 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int hbuffer[j] = ncie->h_p[i][j]; #else float xx, yy, zz; - Ciecam02::jch2xyz_ciecam02float( xx, yy, zz, - ncie->J_p[i][j], ncie_C_p, ncie->h_p[i][j], - xw2, yw2, zw2, - f2, c2, nc2, gamu, pow1n, nbbj, ncbj, flj, czj, dj, awj); + Ciecam02::jch2xyz_ciecam02float ( xx, yy, zz, + ncie->J_p[i][j], ncie_C_p, ncie->h_p[i][j], + xw2, yw2, zw2, + f2, c2, nc2, gamu, pow1n, nbbj, ncbj, flj, czj, dj, awj); float x = (float)xx * 655.35f; float y = (float)yy * 655.35f; float z = (float)zz * 655.35f; float Ll, aa, bb; //convert xyz=>lab - Color::XYZ2Lab(x, y, z, Ll, aa, bb); + Color::XYZ2Lab (x, y, z, Ll, aa, bb); - if(gamu == 1) { + if (gamu == 1) { float Lprov1, Chprov1; Lprov1 = Ll / 327.68f; - Chprov1 = sqrtf(SQR(aa) + SQR(bb)) / 327.68f; + Chprov1 = sqrtf (SQR (aa) + SQR (bb)) / 327.68f; float2 sincosval; - if(Chprov1 == 0.0f) { + if (Chprov1 == 0.0f) { sincosval.y = 1.f; sincosval.x = 0.0f; } else { @@ -2754,10 +2770,10 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f); + Color::gamutLchonly (sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f); #endif lab->L[i][j] = Lprov1 * 327.68f; @@ -2776,35 +2792,35 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int // process line buffers int k; vfloat x, y, z; - vfloat c655d35 = F2V(655.35f); + vfloat c655d35 = F2V (655.35f); - for(k = 0; k < bufferLength; k += 4) { - Ciecam02::jch2xyz_ciecam02float( x, y, z, - LVF(Jbuffer[k]), LVF(Cbuffer[k]), LVF(hbuffer[k]), - F2V(xw2), F2V(yw2), F2V(zw2), - F2V(f2), F2V(nc2), F2V(pow1n), F2V(nbbj), F2V(ncbj), F2V(flj), F2V(dj), F2V(awj), F2V(reccmcz)); + for (k = 0; k < bufferLength; k += 4) { + Ciecam02::jch2xyz_ciecam02float ( x, y, z, + LVF (Jbuffer[k]), LVF (Cbuffer[k]), LVF (hbuffer[k]), + F2V (xw2), F2V (yw2), F2V (zw2), + F2V (f2), F2V (nc2), F2V (pow1n), F2V (nbbj), F2V (ncbj), F2V (flj), F2V (dj), F2V (awj), F2V (reccmcz)); x *= c655d35; y *= c655d35; z *= c655d35; - STVF(xbuffer[k], x); - STVF(ybuffer[k], y); - STVF(zbuffer[k], z); + STVF (xbuffer[k], x); + STVF (ybuffer[k], y); + STVF (zbuffer[k], z); } // XYZ2Lab uses a lookup table. The function behind that lut is a cube root. // SSE can't beat the speed of that lut, so it doesn't make sense to use SSE - for(int j = 0; j < width; j++) { + for (int j = 0; j < width; j++) { float Ll, aa, bb; //convert xyz=>lab - Color::XYZ2Lab(xbuffer[j], ybuffer[j], zbuffer[j], Ll, aa, bb); + Color::XYZ2Lab (xbuffer[j], ybuffer[j], zbuffer[j], Ll, aa, bb); - if(gamu == 1) { + if (gamu == 1) { float Lprov1, Chprov1; Lprov1 = Ll / 327.68f; - Chprov1 = sqrtf(SQR(aa) + SQR(bb)) / 327.68f; + Chprov1 = sqrtf (SQR (aa) + SQR (bb)) / 327.68f; float2 sincosval; - if(Chprov1 == 0.0f) { + if (Chprov1 == 0.0f) { sincosval.y = 1.f; sincosval.x = 0.0f; } else { @@ -2816,10 +2832,10 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f); + Color::gamutLchonly (sincosval, Lprov1, Chprov1, wip, highlight, 0.15f, 0.96f); #endif lab->L[i][j] = Lprov1 * 327.68f; lab->a[i][j] = 327.68f * Chprov1 * sincosval.y; @@ -2838,13 +2854,13 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } //end parallelization //show CIECAM histograms - if(ciedata) { + if (ciedata) { //update histogram J and Q //update histogram J - hist16JCAM.compressTo(histLCAM); + hist16JCAM.compressTo (histLCAM); //update color histogram M,s,C - hist16_CCAM.compressTo(histCCAM); + hist16_CCAM.compressTo (histCCAM); } } } @@ -2866,20 +2882,20 @@ void ImProcFunctions::moyeqt (Imagefloat* working, float &moyS, float &eqty) for (int i = 0; i < tHh; i++) { for (int j = 0; j < tWw; j++) { - float s = Color::rgb2s(CLIP(working->r(i, j)), CLIP(working->g(i, j)), CLIP(working->b(i, j))); + float s = Color::rgb2s (CLIP (working->r (i, j)), CLIP (working->g (i, j)), CLIP (working->b (i, j))); moy += s; - sqrs += SQR(s); + sqrs += SQR (s); } } moy /= (tHh * tWw); sqrs /= (tHh * tWw); - eqty = sqrt(sqrs - SQR(moy)); + eqty = sqrt (sqrs - SQR (moy)); moyS = moy; } static inline void -filmlike_clip_rgb_tone(float *r, float *g, float *b, const float L) +filmlike_clip_rgb_tone (float *r, float *g, float *b, const float L) { float r_ = *r > L ? L : *r; float b_ = *b > L ? L : *b; @@ -2890,18 +2906,18 @@ filmlike_clip_rgb_tone(float *r, float *g, float *b, const float L) } static void -filmlike_clip(float *r, float *g, float *b) +filmlike_clip (float *r, float *g, float *b) { // This is Adobe's hue-stable film-like curve with a diagonal, ie only used for clipping. Can probably be further optimized. const float L = 65535.0; if (*r >= *g) { if (*g > *b) { // Case 1: r >= g > b - filmlike_clip_rgb_tone(r, g, b, L); + filmlike_clip_rgb_tone (r, g, b, L); } else if (*b > *r) { // Case 2: b > r >= g - filmlike_clip_rgb_tone(b, r, g, L); + filmlike_clip_rgb_tone (b, r, g, L); } else if (*b > *g) { // Case 3: r >= b > g - filmlike_clip_rgb_tone(r, b, g, L); + filmlike_clip_rgb_tone (r, b, g, L); } else { // Case 4: r >= g == b *r = *r > L ? L : *r; *g = *g > L ? L : *g; @@ -2909,11 +2925,11 @@ filmlike_clip(float *r, float *g, float *b) } } else { if (*r >= *b) { // Case 5: g > r >= b - filmlike_clip_rgb_tone(g, r, b, L); + filmlike_clip_rgb_tone (g, r, b, L); } else if (*b > *g) { // Case 6: b > g > r - filmlike_clip_rgb_tone(b, g, r, L); + filmlike_clip_rgb_tone (b, g, r, L); } else { // Case 7: g >= b > r - filmlike_clip_rgb_tone(g, b, r, L); + filmlike_clip_rgb_tone (g, b, r, L); } } } @@ -2968,20 +2984,20 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float toxyz[3][3] = { { - static_cast( wprof[0][0] / Color::D50x), - static_cast( wprof[0][1] / Color::D50x), - static_cast( wprof[0][2] / Color::D50x) + static_cast ( wprof[0][0] / Color::D50x), + static_cast ( wprof[0][1] / Color::D50x), + static_cast ( wprof[0][2] / Color::D50x) }, { - static_cast( wprof[1][0]), - static_cast( wprof[1][1]), - static_cast( wprof[1][2]) + static_cast ( wprof[1][0]), + static_cast ( wprof[1][1]), + static_cast ( wprof[1][2]) }, { - static_cast( wprof[2][0] / Color::D50z), - static_cast( wprof[2][1] / Color::D50z), - static_cast( wprof[2][2] / Color::D50z) + static_cast ( wprof[2][0] / Color::D50z), + static_cast ( wprof[2][1] / Color::D50z), + static_cast ( wprof[2][2] / Color::D50z) } }; - float maxFactorToxyz = max(toxyz[1][0],toxyz[1][1],toxyz[1][2]); + float maxFactorToxyz = max (toxyz[1][0], toxyz[1][1], toxyz[1][2]); float equalR = maxFactorToxyz / toxyz[1][0]; float equalG = maxFactorToxyz / toxyz[1][1]; float equalB = maxFactorToxyz / toxyz[1][2]; @@ -3008,10 +3024,10 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer FlatCurve* vCurve = nullptr; FlatCurve* bwlCurve = nullptr; - FlatCurveType hCurveType = (FlatCurveType)params->hsvequalizer.hcurve.at(0); - FlatCurveType sCurveType = (FlatCurveType)params->hsvequalizer.scurve.at(0); - FlatCurveType vCurveType = (FlatCurveType)params->hsvequalizer.vcurve.at(0); - FlatCurveType bwlCurveType = (FlatCurveType)params->blackwhite.luminanceCurve.at(0); + FlatCurveType hCurveType = (FlatCurveType)params->hsvequalizer.hcurve.at (0); + FlatCurveType sCurveType = (FlatCurveType)params->hsvequalizer.scurve.at (0); + FlatCurveType vCurveType = (FlatCurveType)params->hsvequalizer.vcurve.at (0); + FlatCurveType bwlCurveType = (FlatCurveType)params->blackwhite.luminanceCurve.at (0); bool hCurveEnabled = hCurveType > FCT_Linear; bool sCurveEnabled = sCurveType > FCT_Linear; bool vCurveEnabled = vCurveType > FCT_Linear; @@ -3019,7 +3035,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer // TODO: We should create a 'skip' value like for CurveFactory::complexsgnCurve (rtengine/curves.cc) if (hCurveEnabled) { - hCurve = new FlatCurve(params->hsvequalizer.hcurve); + hCurve = new FlatCurve (params->hsvequalizer.hcurve); if (hCurve->isIdentity()) { delete hCurve; @@ -3029,7 +3045,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } if (sCurveEnabled) { - sCurve = new FlatCurve(params->hsvequalizer.scurve); + sCurve = new FlatCurve (params->hsvequalizer.scurve); if (sCurve->isIdentity()) { delete sCurve; @@ -3039,7 +3055,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } if (vCurveEnabled) { - vCurve = new FlatCurve(params->hsvequalizer.vcurve); + vCurve = new FlatCurve (params->hsvequalizer.vcurve); if (vCurve->isIdentity()) { delete vCurve; @@ -3049,7 +3065,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } if (bwlCurveEnabled) { - bwlCurve = new FlatCurve(params->blackwhite.luminanceCurve); + bwlCurve = new FlatCurve (params->blackwhite.luminanceCurve); if (bwlCurve->isIdentity()) { delete bwlCurve; @@ -3069,23 +3085,23 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer #endif if ( params->filmSimulation.enabled && !params->filmSimulation.clutFilename.empty() ) { - hald_clut = CLUTStore::getInstance().getClut( params->filmSimulation.clutFilename ); + hald_clut = CLUTStore::getInstance().getClut ( params->filmSimulation.clutFilename ); if ( hald_clut ) { clutAndWorkingProfilesAreSame = hald_clut->getProfile() == params->icm.working; if ( !clutAndWorkingProfilesAreSame ) { - xyz2clut = ICCStore::getInstance()->workingSpaceInverseMatrix( hald_clut->getProfile() ); - clut2xyz = ICCStore::getInstance()->workingSpaceMatrix( hald_clut->getProfile() ); + xyz2clut = ICCStore::getInstance()->workingSpaceInverseMatrix ( hald_clut->getProfile() ); + clut2xyz = ICCStore::getInstance()->workingSpaceMatrix ( hald_clut->getProfile() ); #ifdef __SSE2__ for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { - v_work2xyz[i][j] = F2V(wprof[i][j]); - v_xyz2clut[i][j] = F2V(xyz2clut[i][j]); - v_xyz2work[i][j] = F2V(wiprof[i][j]); - v_clut2xyz[i][j] = F2V(clut2xyz[i][j]); + v_work2xyz[i][j] = F2V (wprof[i][j]); + v_xyz2clut[i][j] = F2V (xyz2clut[i][j]); + v_xyz2work[i][j] = F2V (wiprof[i][j]); + v_clut2xyz[i][j] = F2V (clut2xyz[i][j]); } } @@ -3095,41 +3111,41 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } } - const float film_simulation_strength = static_cast(params->filmSimulation.strength) / 100.0f; + const float film_simulation_strength = static_cast (params->filmSimulation.strength) / 100.0f; const float exp_scale = pow (2.0, expcomp); - const float comp = (max(0.0, expcomp) + 1.0) * hlcompr / 100.0; - const float shoulder = ((65536.0 / max(1.0f, exp_scale)) * (hlcomprthresh / 200.0)) + 0.1; + const float comp = (max (0.0, expcomp) + 1.0) * hlcompr / 100.0; + const float shoulder = ((65536.0 / max (1.0f, exp_scale)) * (hlcomprthresh / 200.0)) + 0.1; const float hlrange = 65536.0 - shoulder; const bool isProPhoto = (params->icm.working == "ProPhoto"); // extracting datas from 'params' to avoid cache flush (to be confirmed) ToneCurveParams::eTCModeId curveMode = params->toneCurve.curveMode; ToneCurveParams::eTCModeId curveMode2 = params->toneCurve.curveMode2; bool highlight = params->toneCurve.hrenabled;//Get the value if "highlight reconstruction" is activated - bool hasToneCurve1 = bool(customToneCurve1); - bool hasToneCurve2 = bool(customToneCurve2); + bool hasToneCurve1 = bool (customToneCurve1); + bool hasToneCurve2 = bool (customToneCurve2); BlackWhiteParams::eTCModeId beforeCurveMode = params->blackwhite.beforeCurveMode; BlackWhiteParams::eTCModeId afterCurveMode = params->blackwhite.afterCurveMode; - bool hasToneCurvebw1 = bool(customToneCurvebw1); - bool hasToneCurvebw2 = bool(customToneCurvebw2); + bool hasToneCurvebw1 = bool (customToneCurvebw1); + bool hasToneCurvebw2 = bool (customToneCurvebw2); PerceptualToneCurveState ptc1ApplyState, ptc2ApplyState; if (hasToneCurve1 && curveMode == ToneCurveParams::TC_MODE_PERCEPTUAL) { - const PerceptualToneCurve& userToneCurve = static_cast(customToneCurve1); - userToneCurve.initApplyState(ptc1ApplyState, params->icm.working); + const PerceptualToneCurve& userToneCurve = static_cast (customToneCurve1); + userToneCurve.initApplyState (ptc1ApplyState, params->icm.working); } if (hasToneCurve2 && curveMode2 == ToneCurveParams::TC_MODE_PERCEPTUAL) { - const PerceptualToneCurve& userToneCurve = static_cast(customToneCurve2); - userToneCurve.initApplyState(ptc2ApplyState, params->icm.working); + const PerceptualToneCurve& userToneCurve = static_cast (customToneCurve2); + userToneCurve.initApplyState (ptc2ApplyState, params->icm.working); } - bool hasColorToning = params->colorToning.enabled && bool(ctOpacityCurve) && bool(ctColorCurve); + 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); + float strProtect = (float (params->colorToning.strength) / 100.f); /* // Debug output - Color LUTf points @@ -3161,52 +3177,52 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } */ - float RedLow = (100.f + float(params->colorToning.redlow)) / 100.f; //printf("Rel=%f\n",RedLow); - float GreenLow = (100.f + float(params->colorToning.greenlow)) / 100.f; //printf("Gre=%f\n",GreenLow); - float BlueLow = (100.f + float(params->colorToning.bluelow)) / 100.f; //printf("Blu=%f\n",BlueLow); - float RedMed = (100.f + float(params->colorToning.redmed)) / 100.f; - float GreenMed = (100.f + float(params->colorToning.greenmed)) / 100.f; - float BlueMed = (100.f + float(params->colorToning.bluemed)) / 100.f; - float RedHigh = (100.f + float(params->colorToning.redhigh)) / 100.f; //printf("RedH=%f\n",RedHigh); - float GreenHigh = (100.f + float(params->colorToning.greenhigh)) / 100.f; - float BlueHigh = (100.f + float(params->colorToning.bluehigh)) / 100.f; - float SatLow = float(params->colorToning.shadowsColSat.value[0]) / 100.f; - float SatHigh = float(params->colorToning.hlColSat.value[0]) / 100.f; + float RedLow = (100.f + float (params->colorToning.redlow)) / 100.f; //printf("Rel=%f\n",RedLow); + float GreenLow = (100.f + float (params->colorToning.greenlow)) / 100.f; //printf("Gre=%f\n",GreenLow); + float BlueLow = (100.f + float (params->colorToning.bluelow)) / 100.f; //printf("Blu=%f\n",BlueLow); + float RedMed = (100.f + float (params->colorToning.redmed)) / 100.f; + float GreenMed = (100.f + float (params->colorToning.greenmed)) / 100.f; + float BlueMed = (100.f + float (params->colorToning.bluemed)) / 100.f; + float RedHigh = (100.f + float (params->colorToning.redhigh)) / 100.f; //printf("RedH=%f\n",RedHigh); + float GreenHigh = (100.f + float (params->colorToning.greenhigh)) / 100.f; + float BlueHigh = (100.f + float (params->colorToning.bluehigh)) / 100.f; + float SatLow = float (params->colorToning.shadowsColSat.value[0]) / 100.f; + float SatHigh = float (params->colorToning.hlColSat.value[0]) / 100.f; - float Balan = float(params->colorToning.balance); + float Balan = float (params->colorToning.balance); - float chMixRR = float(params->chmixer.red[0]); - float chMixRG = float(params->chmixer.red[1]); - float chMixRB = float(params->chmixer.red[2]); - float chMixGR = float(params->chmixer.green[0]); - float chMixGG = float(params->chmixer.green[1]); - float chMixGB = float(params->chmixer.green[2]); - float chMixBR = float(params->chmixer.blue[0]); - float chMixBG = float(params->chmixer.blue[1]); - float chMixBB = float(params->chmixer.blue[2]); + float chMixRR = float (params->chmixer.red[0]); + float chMixRG = float (params->chmixer.red[1]); + float chMixRB = float (params->chmixer.red[2]); + float chMixGR = float (params->chmixer.green[0]); + float chMixGG = float (params->chmixer.green[1]); + float chMixGB = float (params->chmixer.green[2]); + float chMixBR = float (params->chmixer.blue[0]); + float chMixBG = float (params->chmixer.blue[1]); + float chMixBB = float (params->chmixer.blue[2]); int shHighlights = params->sh.highlights; int shShadows = params->sh.shadows; bool blackwhite = params->blackwhite.enabled; bool complem = params->blackwhite.enabledcc; - float bwr = float(params->blackwhite.mixerRed); - float bwg = float(params->blackwhite.mixerGreen); - float bwb = float(params->blackwhite.mixerBlue); - float bwrgam = float(params->blackwhite.gammaRed); - float bwggam = float(params->blackwhite.gammaGreen); - float bwbgam = float(params->blackwhite.gammaBlue); - float mixerOrange = float(params->blackwhite.mixerOrange); - float mixerYellow = float(params->blackwhite.mixerYellow); - float mixerCyan = float(params->blackwhite.mixerCyan); - float mixerMagenta = float(params->blackwhite.mixerMagenta); - float mixerPurple = float(params->blackwhite.mixerPurple); + float bwr = float (params->blackwhite.mixerRed); + float bwg = float (params->blackwhite.mixerGreen); + float bwb = float (params->blackwhite.mixerBlue); + float bwrgam = float (params->blackwhite.gammaRed); + float bwggam = float (params->blackwhite.gammaGreen); + float bwbgam = float (params->blackwhite.gammaBlue); + float mixerOrange = float (params->blackwhite.mixerOrange); + float mixerYellow = float (params->blackwhite.mixerYellow); + float mixerCyan = float (params->blackwhite.mixerCyan); + float mixerMagenta = float (params->blackwhite.mixerMagenta); + float mixerPurple = float (params->blackwhite.mixerPurple); int algm = 0; if (params->blackwhite.method == "Desaturation") { algm = 0; - } else if(params->blackwhite.method == "LumEqualizer") { + } else if (params->blackwhite.method == "LumEqualizer") { algm = 1; - } else if(params->blackwhite.method == "ChannelMixer") { + } else if (params->blackwhite.method == "ChannelMixer") { algm = 2; } @@ -3217,15 +3233,15 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float gamvalb = 125.f; bool computeMixerAuto = params->blackwhite.autoc && (autor < -5000.f); - if(bwrgam < 0) { + if (bwrgam < 0) { gamvalr = 100.f; } - if(bwggam < 0) { + if (bwggam < 0) { gamvalg = 100.f; } - if(bwbgam < 0) { + if (bwbgam < 0) { gamvalb = 100.f; } @@ -3241,20 +3257,20 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer bool hasgammabw = gammabwr != 1.f || gammabwg != 1.f || gammabwb != 1.f; if (hasColorToning || blackwhite || (params->dirpyrequalizer.cbdlMethod == "bef" && params->dirpyrequalizer.enabled)) { - tmpImage = new Imagefloat(working->getWidth(), working->getHeight()); + tmpImage = new Imagefloat (working->getWidth(), working->getHeight()); } // For tonecurve histogram int toneCurveHistSize = histToneCurve ? histToneCurve.getSize() : 0; int histToneCurveCompression = 0; - if(toneCurveHistSize > 0) { + if (toneCurveHistSize > 0) { histToneCurve.clear(); - histToneCurveCompression = log2(65536 / toneCurveHistSize); + histToneCurveCompression = log2 (65536 / toneCurveHistSize); } // For tonecurve histogram - const float lumimulf[3] = {static_cast(lumimul[0]), static_cast(lumimul[1]), static_cast(lumimul[2])}; + const float lumimulf[3] = {static_cast (lumimul[0]), static_cast (lumimul[1]), static_cast (lumimul[2])}; #define TS 112 @@ -3267,13 +3283,13 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer char *editIFloatBuffer = nullptr; char *editWhateverBuffer = nullptr; - buffer = (char *) malloc(3 * sizeof(float) * TS * TS + 20 * 64 + 63); + buffer = (char *) malloc (3 * sizeof (float) * TS * TS + 20 * 64 + 63); char *data; - data = (char*)( ( uintptr_t(buffer) + uintptr_t(63)) / 64 * 64); + data = (char*) ( ( uintptr_t (buffer) + uintptr_t (63)) / 64 * 64); - float *rtemp = (float(*))data; - float *gtemp = (float (*)) ((char*)rtemp + sizeof(float) * TS * TS + 4 * 64); - float *btemp = (float (*)) ((char*)gtemp + sizeof(float) * TS * TS + 8 * 64); + float *rtemp = (float (*))data; + float *gtemp = (float (*)) ((char*)rtemp + sizeof (float) * TS * TS + 4 * 64); + float *btemp = (float (*)) ((char*)gtemp + sizeof (float) * TS * TS + 8 * 64); int istart; int jstart; int tW; @@ -3283,26 +3299,27 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float *editIFloatTmpR = nullptr, *editIFloatTmpG = nullptr, *editIFloatTmpB = nullptr, *editWhateverTmp = nullptr; if (editImgFloat) { - editIFloatBuffer = (char *) malloc(3 * sizeof(float) * TS * TS + 20 * 64 + 63); - data = (char*)( ( uintptr_t(editIFloatBuffer) + uintptr_t(63)) / 64 * 64); + editIFloatBuffer = (char *) malloc (3 * sizeof (float) * TS * TS + 20 * 64 + 63); + data = (char*) ( ( uintptr_t (editIFloatBuffer) + uintptr_t (63)) / 64 * 64); - editIFloatTmpR = (float(*))data; - editIFloatTmpG = (float (*)) ((char*)editIFloatTmpR + sizeof(float) * TS * TS + 4 * 64); - editIFloatTmpB = (float (*)) ((char*)editIFloatTmpG + sizeof(float) * TS * TS + 8 * 64); + editIFloatTmpR = (float (*))data; + editIFloatTmpG = (float (*)) ((char*)editIFloatTmpR + sizeof (float) * TS * TS + 4 * 64); + editIFloatTmpB = (float (*)) ((char*)editIFloatTmpG + sizeof (float) * TS * TS + 8 * 64); } if (editWhatever) { - editWhateverBuffer = (char *) malloc(sizeof(float) * TS * TS + 20 * 64 + 63); - data = (char*)( ( uintptr_t(editWhateverBuffer) + uintptr_t(63)) / 64 * 64); + editWhateverBuffer = (char *) malloc (sizeof (float) * TS * TS + 20 * 64 + 63); + data = (char*) ( ( uintptr_t (editWhateverBuffer) + uintptr_t (63)) / 64 * 64); - editWhateverTmp = (float(*))data; + editWhateverTmp = (float (*))data; } float out_rgbx[4 * TS] ALIGNED16; // Line buffer for CLUT LUTu histToneCurveThr; - if(toneCurveHistSize > 0) { - histToneCurveThr(toneCurveHistSize); + + if (toneCurveHistSize > 0) { + histToneCurveThr (toneCurveHistSize); histToneCurveThr.clear(); } @@ -3310,19 +3327,19 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer #pragma omp for schedule(dynamic) collapse(2) #endif - for(int ii = 0; ii < working->getHeight(); ii += TS) - for(int jj = 0; jj < working->getWidth(); jj += TS) { + for (int ii = 0; ii < working->getHeight(); ii += TS) + for (int jj = 0; jj < working->getWidth(); jj += TS) { istart = ii; jstart = jj; - tH = min(ii + TS, working->getHeight()); - tW = min(jj + TS, working->getWidth()); + tH = min (ii + TS, working->getHeight()); + tW = min (jj + TS, working->getWidth()); for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - rtemp[ti * TS + tj] = working->r(i, j); - gtemp[ti * TS + tj] = working->g(i, j); - btemp[ti * TS + tj] = working->b(i, j); + rtemp[ti * TS + tj] = working->r (i, j); + gtemp[ti * TS + tj] = working->g (i, j); + btemp[ti * TS + tj] = working->b (i, j); } } @@ -3415,7 +3432,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } if (dcpProf) { - dcpProf->step2ApplyTile(rtemp, gtemp, btemp, tW - jstart, tH - istart, TS, asIn); + dcpProf->step2ApplyTile (rtemp, gtemp, btemp, tW - jstart, tH - istart, TS, asIn); } for (int i = istart, ti = 0; i < tH; i++, ti++) { @@ -3438,7 +3455,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } if (r > 65535 || g > 65535 || b > 65535) { - filmlike_clip(&r, &g, &b); + filmlike_clip (&r, &g, &b); } rtemp[ti * TS + tj] = r; @@ -3454,9 +3471,10 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer rtemp[ti * TS + tj] = tonecurve[ rtemp[ti * TS + tj] ]; gtemp[ti * TS + tj] = tonecurve[ gtemp[ti * TS + tj] ]; btemp[ti * TS + tj] = tonecurve[ btemp[ti * TS + tj] ]; - if(histToneCurveThr) { - int y = CLIP(lumimulf[0] * Color::gamma2curve[rtemp[ti * TS + tj]] + lumimulf[1] * Color::gamma2curve[gtemp[ti * TS + tj]] + lumimulf[2] * Color::gamma2curve[btemp[ti * TS + tj]]); - histToneCurveThr[y>>histToneCurveCompression]++; + + if (histToneCurveThr) { + int y = CLIP (lumimulf[0] * Color::gamma2curve[rtemp[ti * TS + tj]] + lumimulf[1] * Color::gamma2curve[gtemp[ti * TS + tj]] + lumimulf[2] * Color::gamma2curve[btemp[ti * TS + tj]]); + histToneCurveThr[y >> histToneCurveCompression]++; } } } @@ -3475,58 +3493,58 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer if (curveMode == ToneCurveParams::TC_MODE_STD) { // Standard for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const StandardToneCurve& userToneCurve = static_cast(customToneCurve1); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const StandardToneCurve& userToneCurve = static_cast (customToneCurve1); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode == ToneCurveParams::TC_MODE_FILMLIKE) { // Adobe like for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const AdobeToneCurve& userToneCurve = static_cast(customToneCurve1); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const AdobeToneCurve& userToneCurve = static_cast (customToneCurve1); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode == ToneCurveParams::TC_MODE_SATANDVALBLENDING) { // apply the curve on the saturation and value channels for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const SatAndValueBlendingToneCurve& userToneCurve = static_cast(customToneCurve1); - rtemp[ti * TS + tj] = CLIP(rtemp[ti * TS + tj]); - gtemp[ti * TS + tj] = CLIP(gtemp[ti * TS + tj]); - btemp[ti * TS + tj] = CLIP(btemp[ti * TS + tj]); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const SatAndValueBlendingToneCurve& userToneCurve = static_cast (customToneCurve1); + rtemp[ti * TS + tj] = CLIP (rtemp[ti * TS + tj]); + gtemp[ti * TS + tj] = CLIP (gtemp[ti * TS + tj]); + btemp[ti * TS + tj] = CLIP (btemp[ti * TS + tj]); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode == ToneCurveParams::TC_MODE_WEIGHTEDSTD) { // apply the curve to the rgb channels, weighted - const WeightedStdToneCurve& userToneCurve = static_cast(customToneCurve1); + const WeightedStdToneCurve& userToneCurve = static_cast (customToneCurve1); for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - rtemp[ti * TS + tj] = CLIP(rtemp[ti * TS + tj]); - gtemp[ti * TS + tj] = CLIP(gtemp[ti * TS + tj]); - btemp[ti * TS + tj] = CLIP(btemp[ti * TS + tj]); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + rtemp[ti * TS + tj] = CLIP (rtemp[ti * TS + tj]); + gtemp[ti * TS + tj] = CLIP (gtemp[ti * TS + tj]); + btemp[ti * TS + tj] = CLIP (btemp[ti * TS + tj]); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode == ToneCurveParams::TC_MODE_LUMINANCE) { // apply the curve to the luminance channel - const LuminanceToneCurve& userToneCurve = static_cast(customToneCurve1); + const LuminanceToneCurve& userToneCurve = static_cast (customToneCurve1); for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - rtemp[ti * TS + tj] = CLIP(rtemp[ti * TS + tj]); - gtemp[ti * TS + tj] = CLIP(gtemp[ti * TS + tj]); - btemp[ti * TS + tj] = CLIP(btemp[ti * TS + tj]); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + rtemp[ti * TS + tj] = CLIP (rtemp[ti * TS + tj]); + gtemp[ti * TS + tj] = CLIP (gtemp[ti * TS + tj]); + btemp[ti * TS + tj] = CLIP (btemp[ti * TS + tj]); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode == ToneCurveParams::TC_MODE_PERCEPTUAL) { // apply curve while keeping color appearance constant - const PerceptualToneCurve& userToneCurve = static_cast(customToneCurve1); + const PerceptualToneCurve& userToneCurve = static_cast (customToneCurve1); for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - rtemp[ti * TS + tj] = CLIP(rtemp[ti * TS + tj]); - gtemp[ti * TS + tj] = CLIP(gtemp[ti * TS + tj]); - btemp[ti * TS + tj] = CLIP(btemp[ti * TS + tj]); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], ptc1ApplyState); + rtemp[ti * TS + tj] = CLIP (rtemp[ti * TS + tj]); + gtemp[ti * TS + tj] = CLIP (gtemp[ti * TS + tj]); + btemp[ti * TS + tj] = CLIP (btemp[ti * TS + tj]); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], ptc1ApplyState); } } } @@ -3546,46 +3564,46 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer if (curveMode2 == ToneCurveParams::TC_MODE_STD) { // Standard for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const StandardToneCurve& userToneCurve = static_cast(customToneCurve2); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const StandardToneCurve& userToneCurve = static_cast (customToneCurve2); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode2 == ToneCurveParams::TC_MODE_FILMLIKE) { // Adobe like for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const AdobeToneCurve& userToneCurve = static_cast(customToneCurve2); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const AdobeToneCurve& userToneCurve = static_cast (customToneCurve2); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode2 == ToneCurveParams::TC_MODE_SATANDVALBLENDING) { // apply the curve on the saturation and value channels for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const SatAndValueBlendingToneCurve& userToneCurve = static_cast(customToneCurve2); - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const SatAndValueBlendingToneCurve& userToneCurve = static_cast (customToneCurve2); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode2 == ToneCurveParams::TC_MODE_WEIGHTEDSTD) { // apply the curve to the rgb channels, weighted - const WeightedStdToneCurve& userToneCurve = static_cast(customToneCurve2); + const WeightedStdToneCurve& userToneCurve = static_cast (customToneCurve2); for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode2 == ToneCurveParams::TC_MODE_LUMINANCE) { // apply the curve to the luminance channel - const LuminanceToneCurve& userToneCurve = static_cast(customToneCurve2); + const LuminanceToneCurve& userToneCurve = static_cast (customToneCurve2); for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (curveMode2 == ToneCurveParams::TC_MODE_PERCEPTUAL) { // apply curve while keeping color appearance constant - const PerceptualToneCurve& userToneCurve = static_cast(customToneCurve2); + const PerceptualToneCurve& userToneCurve = static_cast (customToneCurve2); for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - userToneCurve.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], ptc2ApplyState); + userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], ptc2ApplyState); } } } @@ -3646,9 +3664,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float y = toxyz[1][0] * r + toxyz[1][1] * g + toxyz[1][2] * b; float z = toxyz[2][0] * r + toxyz[2][1] * g + toxyz[2][2] * b; - float fx = x < MAXVALF ? Color::cachef[x] : 327.68f * std::cbrt(x / MAXVALF); - float fy = y < MAXVALF ? Color::cachef[y] : 327.68f * std::cbrt(y / MAXVALF); - float fz = z < MAXVALF ? Color::cachef[z] : 327.68f * std::cbrt(z / MAXVALF); + float fx = x < MAXVALF ? Color::cachef[x] : 327.68f * std::cbrt (x / MAXVALF); + float fy = y < MAXVALF ? Color::cachef[y] : 327.68f * std::cbrt (y / MAXVALF); + float fz = z < MAXVALF ? Color::cachef[z] : 327.68f * std::cbrt (z / MAXVALF); float a_1 = 500.0f * (fx - fy); float b_1 = 200.0f * (fy - fz); @@ -3672,19 +3690,19 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer // Luminosity after // only Luminance in Lab float newy = toxyz[1][0] * r + toxyz[1][1] * g + toxyz[1][2] * b; - float newfy = newy < MAXVALF ? Color::cachef[newy] : 327.68f * std::cbrt(newy / MAXVALF); + float newfy = newy < MAXVALF ? Color::cachef[newy] : 327.68f * std::cbrt (newy / MAXVALF); float L_2 = 116.0f * newfy - 5242.88f; //gamut control - if(settings->rgbcurveslumamode_gamut) { + if (settings->rgbcurveslumamode_gamut) { float Lpro = L_2 / 327.68f; - float Chpro = sqrtf(SQR(a_1) + SQR(b_1)) / 327.68f; + float Chpro = sqrtf (SQR (a_1) + SQR (b_1)) / 327.68f; float HH = NAN; // we set HH to NAN, because then it will be calculated in Color::gamutLchonly only if needed // float HH = xatan2f(b_1, a_1); // According to mathematical laws we can get the sin and cos of HH by simple operations even if we don't calculate HH float2 sincosval; - if(Chpro == 0.0f) { + if (Chpro == 0.0f) { sincosval.y = 1.0f; sincosval.x = 0.0f; } else { @@ -3696,17 +3714,17 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, sincosval, Lpro, Chpro, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], wip, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (HH, sincosval, Lpro, Chpro, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, sincosval, Lpro, Chpro, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], wip, highlight, 0.15f, 0.96f); + Color::gamutLchonly (HH, sincosval, Lpro, Chpro, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], wip, highlight, 0.15f, 0.96f); #endif - //end of gamut control + //end of gamut control } else { float x_, y_, z_; //calculate RGB with L_2 and old value of a and b - Color::Lab2XYZ(L_2, a_1, b_1, x_, y_, z_) ; - Color::xyz2rgb(x_, y_, z_, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], wip); + Color::Lab2XYZ (L_2, a_1, b_1, x_, y_, z_) ; + Color::xyz2rgb (x_, y_, z_, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], wip); } } } @@ -3717,7 +3735,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { float h, s, v; - Color::rgb2hsv(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], h, s, v); + Color::rgb2hsv (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], h, s, v); editWhateverTmp[ti * TS + tj] = h; } } @@ -3732,10 +3750,10 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float g = gtemp[ti * TS + tj]; float b = btemp[ti * TS + tj]; float h, s, v; - Color::rgb2hsv(r, g, b, h, s, v); + Color::rgb2hsv (r, g, b, h, s, v); if (sat > 0) { - s = (1.f - satby100) * s + satby100 * (1.f - SQR(SQR(1.f - min(s, 1.0f)))); + s = (1.f - satby100) * s + satby100 * (1.f - SQR (SQR (1.f - min (s, 1.0f)))); if (s < 0.f) { s = 0.f; @@ -3746,7 +3764,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer //HSV equalizer if (hCurveEnabled) { - h = (hCurve->getVal(double(h)) - 0.5) * 2.f + h; + h = (hCurve->getVal (double (h)) - 0.5) * 2.f + h; if (h > 1.0f) { h -= 1.0f; @@ -3757,10 +3775,10 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer if (sCurveEnabled) { //shift saturation - float satparam = (sCurve->getVal(double(h)) - 0.5) * 2; + float satparam = (sCurve->getVal (double (h)) - 0.5) * 2; if (satparam > 0.00001f) { - s = (1.f - satparam) * s + satparam * (1.f - SQR(1.f - min(s, 1.0f))); + s = (1.f - satparam) * s + satparam * (1.f - SQR (1.f - min (s, 1.0f))); if (s < 0.f) { s = 0.f; @@ -3777,11 +3795,11 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } //shift value - float valparam = vCurve->getVal((double)h) - 0.5f; - valparam *= (1.f - SQR(SQR(1.f - min(s, 1.0f)))); + float valparam = vCurve->getVal ((double)h) - 0.5f; + valparam *= (1.f - SQR (SQR (1.f - min (s, 1.0f)))); if (valparam > 0.00001f) { - v = (1.f - valparam) * v + valparam * (1.f - SQR(1.f - min(v, 1.0f))); // SQR (SQR to increase action and avoid artefacts + v = (1.f - valparam) * v + valparam * (1.f - SQR (1.f - min (v, 1.0f))); // SQR (SQR to increase action and avoid artefacts if (v < 0) { v = 0; @@ -3794,7 +3812,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } - Color::hsv2rgb(h, s, v, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + Color::hsv2rgb (h, s, v, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } @@ -3805,12 +3823,12 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float r = rtemp[ti * TS + tj]; float g = gtemp[ti * TS + tj]; - if(r == 0.0f || g == 0.0f) { + if (r == 0.0f || g == 0.0f) { float b = btemp[ti * TS + tj]; float h, s, v; - Color::rgb2hsv(r, g, b, h, s, v); + Color::rgb2hsv (r, g, b, h, s, v); s *= 0.99f; - Color::hsv2rgb(h, s, v, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + Color::hsv2rgb (h, s, v, rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } @@ -3822,7 +3840,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float reducac = 0.4f; int preser = 0; - if(params->colorToning.lumamode) { + if (params->colorToning.lumamode) { preser = 1; } @@ -3836,14 +3854,14 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer iplow = (float)ctColorCurve.low; iphigh = (float)ctColorCurve.high; //2 colours - ctColorCurve.getVal(iphigh, xh, yh, zh); - ctColorCurve.getVal(iplow, xl, yl, zl); + ctColorCurve.getVal (iphigh, xh, yh, zh); + ctColorCurve.getVal (iplow, xl, yl, zl); - Color::xyz2rgb(xh, yh, zh, rh, gh, bh, wip); - Color::xyz2rgb(xl, yl, zl, rl, gl, bl, wip); + Color::xyz2rgb (xh, yh, zh, rh, gh, bh, wip); + Color::xyz2rgb (xl, yl, zl, rl, gl, bl, wip); //reteave rgb value with s and l =1 - retreavergb(rl, gl, bl); - retreavergb(rh, gh, bh); + retreavergb (rl, gl, bl); + retreavergb (rh, gh, bh); //printf("rl=%f gl=%f bl=%f\n",rl,gl,bl); for (int i = istart, ti = 0; i < tH; i++, ti++) { @@ -3883,7 +3901,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer int preser = 0; //bool execbal = params->colorToning.method=="Splitbal"; - if(params->colorToning.lumamode) { + if (params->colorToning.lumamode) { preser = 1; } @@ -3899,16 +3917,16 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float lumafter = 0.299f * ro + 0.587f * go + 0.114f * bo; float preserv = 1.f; - if(preser == 1) { + if (preser == 1) { preserv = lumbefore / lumafter; } ro *= preserv; go *= preserv; bo *= preserv; - ro = CLIP(ro); - go = CLIP(go); - bo = CLIP(bo); + ro = CLIP (ro); + go = CLIP (go); + bo = CLIP (bo); rtemp[ti * TS + tj] = ro; gtemp[ti * TS + tj] = go; btemp[ti * TS + tj] = bo; @@ -3934,13 +3952,13 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer metchrom = 3; } - if(metchrom == 3) { + if (metchrom == 3) { twocol = false; } float iplow = 0.f, iphigh = 0.f; - if(!twocol) { + if (!twocol) { iplow = (float)ctColorCurve.low; iphigh = (float)ctColorCurve.high; } @@ -3967,13 +3985,13 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float b = btemp[ti * TS + tj]; float ro, go, bo; labtoning (r, g, b, ro, go, bo, algm, metchrom, twoc, satLimit, satLimitOpacity, ctColorCurve, ctOpacityCurve, clToningcurve, cl2Toningcurve, iplow, iphigh, wp, wip); - rtemp[ti * TS + tj] = CLIP(ro); //I used CLIP because there is a little bug in gamutLchonly that return 65536.ii intead of 65535 ==> crash - gtemp[ti * TS + tj] = CLIP(go); - btemp[ti * TS + tj] = CLIP(bo); + rtemp[ti * TS + tj] = CLIP (ro); //I used CLIP because there is a little bug in gamutLchonly that return 65536.ii intead of 65535 ==> crash + gtemp[ti * TS + tj] = CLIP (go); + btemp[ti * TS + tj] = CLIP (bo); } } } - } else if (params->colorToning.method.substr(0, 3) == "RGB" && opautili) { + } else if (params->colorToning.method.substr (0, 3) == "RGB" && opautili) { // color toning for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { @@ -3984,28 +4002,28 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer // Luminance = (0.299f*r + 0.587f*g + 0.114f*b) float h, s, l; - Color::rgb2hsl(r, g, b, h, s, l); + Color::rgb2hsl (r, g, b, h, s, l); - float l_ = Color::gamma_srgb(l * 65535.f) / 65535.f; + float l_ = Color::gamma_srgb (l * 65535.f) / 65535.f; // get the opacity and tweak it to preserve saturated colors float opacity; - if(ctOpacityCurve) { - opacity = (1.f - min(s / satLimit, 1.f) * (1.f - satLimitOpacity)) * ctOpacityCurve.lutOpacityCurve[l_ * 500.f]; + if (ctOpacityCurve) { + opacity = (1.f - min (s / satLimit, 1.f) * (1.f - satLimitOpacity)) * ctOpacityCurve.lutOpacityCurve[l_ * 500.f]; } - if(!ctOpacityCurve) { + if (!ctOpacityCurve) { opacity = 0.f; } float r2, g2, b2; - ctColorCurve.getVal(l_, r2, g2, b2); // get the color from the color curve + ctColorCurve.getVal (l_, r2, g2, b2); // get the color from the color curve float h2, s2, l2; - Color::rgb2hsl(r2, g2, b2, h2, s2, l2); // transform this new color to hsl + Color::rgb2hsl (r2, g2, b2, h2, s2, l2); // transform this new color to hsl - Color::hsl2rgb(h2, s + ((1.f - s) * (1.f - l) * 0.7f), l, r2, g2, b2); + Color::hsl2rgb (h2, s + ((1.f - s) * (1.f - l) * 0.7f), l, r2, g2, b2); rtemp[ti * TS + tj] = r + (r2 - r) * opacity; // merge the color to the old color, depending on the opacity gtemp[ti * TS + tj] = g + (g2 - g) * opacity; @@ -4029,53 +4047,53 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int j = jstart, tj = 0; j < tW; j++, tj++) { float X, Y, Z, L, aa, bb; //rgb=>lab - Color::rgbxyz(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], X, Y, Z, wp); + Color::rgbxyz (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], X, Y, Z, wp); //convert Lab - Color::XYZ2Lab(X, Y, Z, L, aa, bb); + Color::XYZ2Lab (X, Y, Z, L, aa, bb); //end rgb=>lab - float HH = xatan2f(bb, aa); // HH hue in -3.141 +3.141 + float HH = xatan2f (bb, aa); // HH hue in -3.141 +3.141 - editWhateverTmp[ti * TS + tj] = float(Color::huelab_to_huehsv2(HH)); + editWhateverTmp[ti * TS + tj] = float (Color::huelab_to_huehsv2 (HH)); } } } //black and white - if(blackwhite) { + if (blackwhite) { if (hasToneCurvebw1) { if (beforeCurveMode == BlackWhiteParams::TC_MODE_STD_BW) { // Standard for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const StandardToneCurvebw& userToneCurvebw = static_cast(customToneCurvebw1); - userToneCurvebw.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const StandardToneCurvebw& userToneCurvebw = static_cast (customToneCurvebw1); + userToneCurvebw.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (beforeCurveMode == BlackWhiteParams::TC_MODE_FILMLIKE_BW) { // Adobe like for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const AdobeToneCurvebw& userToneCurvebw = static_cast(customToneCurvebw1); - userToneCurvebw.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const AdobeToneCurvebw& userToneCurvebw = static_cast (customToneCurvebw1); + userToneCurvebw.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (beforeCurveMode == BlackWhiteParams::TC_MODE_SATANDVALBLENDING_BW) { // apply the curve on the saturation and value channels for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const SatAndValueBlendingToneCurvebw& userToneCurvebw = static_cast(customToneCurvebw1); - rtemp[ti * TS + tj] = CLIP(rtemp[ti * TS + tj]); - gtemp[ti * TS + tj] = CLIP(gtemp[ti * TS + tj]); - btemp[ti * TS + tj] = CLIP(btemp[ti * TS + tj]); - userToneCurvebw.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + const SatAndValueBlendingToneCurvebw& userToneCurvebw = static_cast (customToneCurvebw1); + rtemp[ti * TS + tj] = CLIP (rtemp[ti * TS + tj]); + gtemp[ti * TS + tj] = CLIP (gtemp[ti * TS + tj]); + btemp[ti * TS + tj] = CLIP (btemp[ti * TS + tj]); + userToneCurvebw.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } else if (beforeCurveMode == BlackWhiteParams::TC_MODE_WEIGHTEDSTD_BW) { // apply the curve to the rgb channels, weighted for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) { - const WeightedStdToneCurvebw& userToneCurvebw = static_cast(customToneCurvebw1); - rtemp[ti * TS + tj] = CLIP(rtemp[ti * TS + tj]); - gtemp[ti * TS + tj] = CLIP(gtemp[ti * TS + tj]); - btemp[ti * TS + tj] = CLIP(btemp[ti * TS + tj]); + const WeightedStdToneCurvebw& userToneCurvebw = static_cast (customToneCurvebw1); + rtemp[ti * TS + tj] = CLIP (rtemp[ti * TS + tj]); + gtemp[ti * TS + tj] = CLIP (gtemp[ti * TS + tj]); + btemp[ti * TS + tj] = CLIP (btemp[ti * TS + tj]); - userToneCurvebw.Apply(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); + userToneCurvebw.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]); } } } @@ -4104,20 +4122,25 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer // -------------------------------------------------- #ifndef __SSE2__ + //gamma correction: pseudo TRC curve if (hasgammabw) { Color::trcGammaBW (r, g, b, gammabwr, gammabwg, gammabwb); } + #endif rtemp[ti * TS + tj] = r; gtemp[ti * TS + tj] = g; btemp[ti * TS + tj] = b; } + #ifdef __SSE2__ + if (hasgammabw) { //gamma correction: pseudo TRC curve Color::trcGammaBWRow (&rtemp[ti * TS], >emp[ti * TS], &btemp[ti * TS], tW - jstart, gammabwr, gammabwg, gammabwb); } + #endif } @@ -4126,15 +4149,15 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int j = jstart, tj = 0; j < tW; j++, tj++) { //rgb => xyz float X, Y, Z; - Color::rgbxyz(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], X, Y, Z, wp); + Color::rgbxyz (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], X, Y, Z, wp); //xyz => Lab float L, aa, bb; - Color::XYZ2Lab(X, Y, Z, L, aa, bb); - float CC = sqrtf(SQR(aa) + SQR(bb)) / 327.68f; //CC chromaticity in 0..180 or more - float HH = xatan2f(bb, aa); // HH hue in -3.141 +3.141 + Color::XYZ2Lab (X, Y, Z, L, aa, bb); + float CC = sqrtf (SQR (aa) + SQR (bb)) / 327.68f; //CC chromaticity in 0..180 or more + float HH = xatan2f (bb, aa); // HH hue in -3.141 +3.141 float2 sincosval; - if(CC == 0.0f) { + if (CC == 0.0f) { sincosval.y = 1.f; sincosval.x = 0.0f; } else { @@ -4144,17 +4167,18 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer if (bwlCurveEnabled) { L /= 32768.f; - double hr = Color::huelab_to_huehsv2(HH); - float valparam = float((bwlCurve->getVal(hr) - 0.5f) * 2.0f); //get l_r=f(H) + double hr = Color::huelab_to_huehsv2 (HH); + float valparam = float ((bwlCurve->getVal (hr) - 0.5f) * 2.0f); //get l_r=f(H) float kcc = (CC / 70.f); //take Chroma into account...70 "middle" of chromaticity (arbitrary and simple), one can imagine other algorithme //reduct action for low chroma and increase action for high chroma valparam *= kcc; - if(valparam > 0.f) { - L = (1.f - valparam) * L + valparam * (1.f - SQR(SQR(SQR(SQR(1.f - min(L, 1.0f)))))); // SQR (SQR((SQR) to increase action in low light + if (valparam > 0.f) { + L = (1.f - valparam) * L + valparam * (1.f - SQR (SQR (SQR (SQR (1.f - min (L, 1.0f)))))); // SQR (SQR((SQR) to increase action in low light } else { L *= (1.f + valparam); //for negative } + L *= 32768.f; } @@ -4164,29 +4188,34 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, sincosval, L, CC, RR, GG, BB, wip, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (HH, sincosval, L, CC, RR, GG, BB, wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, sincosval, L, CC, RR, GG, BB, wip, highlight, 0.15f, 0.96f); + Color::gamutLchonly (HH, sincosval, L, CC, RR, GG, BB, wip, highlight, 0.15f, 0.96f); #endif L *= 327.68f; //convert l => rgb - Color::L2XYZ(L, X, Y, Z); + Color::L2XYZ (L, X, Y, Z); float newRed; // We use the red channel for bw - Color::xyz2r(X, Y, Z, newRed, wip); + Color::xyz2r (X, Y, Z, newRed, wip); rtemp[ti * TS + tj] = gtemp[ti * TS + tj] = btemp[ti * TS + tj] = newRed; #ifndef __SSE2__ + if (hasgammabw) { //gamma correction: pseudo TRC curve Color::trcGammaBW (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], gammabwr, gammabwg, gammabwb); } + #endif } + #ifdef __SSE2__ + if (hasgammabw) { //gamma correction: pseudo TRC curve Color::trcGammaBWRow (&rtemp[ti * TS], >emp[ti * TS], &btemp[ti * TS], tW - jstart, gammabwr, gammabwg, gammabwb); } + #endif } } @@ -4205,19 +4234,19 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer #ifdef __SSE2__ for (; j < tW - 3; j += 4, tj += 4) { - vfloat sourceR = LVF(rtemp[ti * TS + tj]); - vfloat sourceG = LVF(gtemp[ti * TS + tj]); - vfloat sourceB = LVF(btemp[ti * TS + tj]); + vfloat sourceR = LVF (rtemp[ti * TS + tj]); + vfloat sourceG = LVF (gtemp[ti * TS + tj]); + vfloat sourceB = LVF (btemp[ti * TS + tj]); vfloat x; vfloat y; vfloat z; - Color::rgbxyz(sourceR, sourceG, sourceB, x, y, z, v_work2xyz); - Color::xyz2rgb(x, y, z, sourceR, sourceG, sourceB, v_xyz2clut); + Color::rgbxyz (sourceR, sourceG, sourceB, x, y, z, v_work2xyz); + Color::xyz2rgb (x, y, z, sourceR, sourceG, sourceB, v_xyz2clut); - STVF(rtemp[ti * TS + tj], sourceR); - STVF(gtemp[ti * TS + tj], sourceG); - STVF(btemp[ti * TS + tj], sourceB); + STVF (rtemp[ti * TS + tj], sourceR); + STVF (gtemp[ti * TS + tj], sourceG); + STVF (btemp[ti * TS + tj], sourceB); } #endif @@ -4228,8 +4257,8 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float &sourceB = btemp[ti * TS + tj]; float x, y, z; - Color::rgbxyz( sourceR, sourceG, sourceB, x, y, z, wprof ); - Color::xyz2rgb(x, y, z, sourceR, sourceG, sourceB, xyz2clut); + Color::rgbxyz ( sourceR, sourceG, sourceB, x, y, z, wprof ); + Color::xyz2rgb (x, y, z, sourceR, sourceG, sourceB, xyz2clut); } } @@ -4239,15 +4268,15 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float &sourceB = btemp[ti * TS + tj]; // Apply gamma sRGB (default RT) - sourceR = Color::gamma_srgbclipped(sourceR); - sourceG = Color::gamma_srgbclipped(sourceG); - sourceB = Color::gamma_srgbclipped(sourceB); + sourceR = Color::gamma_srgbclipped (sourceR); + sourceG = Color::gamma_srgbclipped (sourceG); + sourceB = Color::gamma_srgbclipped (sourceB); } const std::size_t line_offset = ti * TS; - hald_clut->getRGB( + hald_clut->getRGB ( film_simulation_strength, - std::min(TS, tW - jstart), + std::min (TS, tW - jstart), rtemp + line_offset, gtemp + line_offset, btemp + line_offset, @@ -4260,9 +4289,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float &sourceB = btemp[ti * TS + tj]; // Apply inverse gamma sRGB - sourceR = Color::igamma_srgb(out_rgbx[tj * 4 + 0]); - sourceG = Color::igamma_srgb(out_rgbx[tj * 4 + 1]); - sourceB = Color::igamma_srgb(out_rgbx[tj * 4 + 2]); + sourceR = Color::igamma_srgb (out_rgbx[tj * 4 + 0]); + sourceG = Color::igamma_srgb (out_rgbx[tj * 4 + 1]); + sourceB = Color::igamma_srgb (out_rgbx[tj * 4 + 2]); } if (!clutAndWorkingProfilesAreSame) { @@ -4273,19 +4302,19 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer #ifdef __SSE2__ for (; j < tW - 3; j += 4, tj += 4) { - vfloat sourceR = LVF(rtemp[ti * TS + tj]); - vfloat sourceG = LVF(gtemp[ti * TS + tj]); - vfloat sourceB = LVF(btemp[ti * TS + tj]); + vfloat sourceR = LVF (rtemp[ti * TS + tj]); + vfloat sourceG = LVF (gtemp[ti * TS + tj]); + vfloat sourceB = LVF (btemp[ti * TS + tj]); vfloat x; vfloat y; vfloat z; - Color::rgbxyz(sourceR, sourceG, sourceB, x, y, z, v_clut2xyz); - Color::xyz2rgb(x, y, z, sourceR, sourceG, sourceB, v_xyz2work); + Color::rgbxyz (sourceR, sourceG, sourceB, x, y, z, v_clut2xyz); + Color::xyz2rgb (x, y, z, sourceR, sourceG, sourceB, v_xyz2work); - STVF(rtemp[ti * TS + tj], sourceR); - STVF(gtemp[ti * TS + tj], sourceG); - STVF(btemp[ti * TS + tj], sourceB); + STVF (rtemp[ti * TS + tj], sourceR); + STVF (gtemp[ti * TS + tj], sourceG); + STVF (btemp[ti * TS + tj], sourceB); } #endif @@ -4296,8 +4325,8 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float &sourceB = btemp[ti * TS + tj]; float x, y, z; - Color::rgbxyz(sourceR, sourceG, sourceB, x, y, z, clut2xyz); - Color::xyz2rgb( x, y, z, sourceR, sourceG, sourceB, wiprof ); + Color::rgbxyz (sourceR, sourceG, sourceB, x, y, z, clut2xyz); + Color::xyz2rgb ( x, y, z, sourceR, sourceG, sourceB, wiprof ); } } } @@ -4311,11 +4340,11 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer // filling the pipette buffer by the content of the temp pipette buffers if (editImgFloat) { - editImgFloat->r(i, j) = editIFloatTmpR[ti * TS + tj]; - editImgFloat->g(i, j) = editIFloatTmpG[ti * TS + tj]; - editImgFloat->b(i, j) = editIFloatTmpB[ti * TS + tj]; + editImgFloat->r (i, j) = editIFloatTmpR[ti * TS + tj]; + editImgFloat->g (i, j) = editIFloatTmpG[ti * TS + tj]; + editImgFloat->b (i, j) = editIFloatTmpB[ti * TS + tj]; } else if (editWhatever) { - editWhatever->v(i, j) = editWhateverTmp[ti * TS + tj]; + editWhatever->v (i, j) = editWhateverTmp[ti * TS + tj]; } float r = rtemp[ti * TS + tj]; @@ -4328,9 +4357,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float fx, fy, fz; - fx = (x < 65535.0f ? Color::cachef[x] : 327.68f * std::cbrt(x / MAXVALF)); - fy = (y < 65535.0f ? Color::cachef[y] : 327.68f * std::cbrt(y / MAXVALF)); - fz = (z < 65535.0f ? Color::cachef[z] : 327.68f * std::cbrt(z / MAXVALF)); + fx = (x < 65535.0f ? Color::cachef[x] : 327.68f * std::cbrt (x / MAXVALF)); + fy = (y < 65535.0f ? Color::cachef[y] : 327.68f * std::cbrt (y / MAXVALF)); + fz = (z < 65535.0f ? Color::cachef[z] : 327.68f * std::cbrt (z / MAXVALF)); lab->L[i][j] = (116.0f * fy - 5242.88f); //5242.88=16.0*327.68; lab->a[i][j] = (500.0f * (fx - fy) ); @@ -4359,22 +4388,22 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int j = jstart, tj = 0; j < tW; j++, tj++) { // filling the pipette buffer by the content of the temp pipette buffers if (editImgFloat) { - editImgFloat->r(i, j) = editIFloatTmpR[ti * TS + tj]; - editImgFloat->g(i, j) = editIFloatTmpG[ti * TS + tj]; - editImgFloat->b(i, j) = editIFloatTmpB[ti * TS + tj]; + editImgFloat->r (i, j) = editIFloatTmpR[ti * TS + tj]; + editImgFloat->g (i, j) = editIFloatTmpG[ti * TS + tj]; + editImgFloat->b (i, j) = editIFloatTmpB[ti * TS + tj]; } else if (editWhatever) { - editWhatever->v(i, j) = editWhateverTmp[ti * TS + tj]; + editWhatever->v (i, j) = editWhateverTmp[ti * TS + tj]; } - tmpImage->r(i, j) = rtemp[ti * TS + tj]; - tmpImage->g(i, j) = gtemp[ti * TS + tj]; - tmpImage->b(i, j) = btemp[ti * TS + tj]; + tmpImage->r (i, j) = rtemp[ti * TS + tj]; + tmpImage->g (i, j) = gtemp[ti * TS + tj]; + tmpImage->b (i, j) = btemp[ti * TS + tj]; } } } } - free(buffer); + free (buffer); if (editIFloatBuffer) { free (editIFloatBuffer); @@ -4383,13 +4412,14 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer if (editWhateverBuffer) { free (editWhateverBuffer); } + #ifdef _OPENMP -#pragma omp critical -{ - if(toneCurveHistSize > 0) { - histToneCurve += histToneCurveThr; - } -} + #pragma omp critical + { + if (toneCurveHistSize > 0) { + histToneCurve += histToneCurveThr; + } + } #endif // _OPENMP } @@ -4412,9 +4442,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int i = 0; i < tH; i++) { for (int j = 0; j < tW; j++) { - nr += tmpImage->r(i, j); - ng += tmpImage->g(i, j); - nb += tmpImage->b(i, j); + nr += tmpImage->r (i, j); + ng += tmpImage->g (i, j); + nb += tmpImage->b (i, j); } } @@ -4423,9 +4453,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer double kng = srgb / ng; double knb = srgb / nb; double sk = knr + kng + knb; - autor = (float)(100.0 * knr / sk); - autog = (float)(100.0 * kng / sk); - autob = (float)(100.0 * knb / sk); + autor = (float) (100.0 * knr / sk); + autog = (float) (100.0 * kng / sk); + autob = (float) (100.0 * knb / sk); } @@ -4442,9 +4472,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer } float filcor; - Color::computeBWMixerConstants(params->blackwhite.setting, params->blackwhite.filter, params->blackwhite.algo, filcor, - bwr, bwg, bwb, mixerOrange, mixerYellow, mixerCyan, mixerPurple, mixerMagenta, - params->blackwhite.autoc, complem, kcorec, rrm, ggm, bbm); + Color::computeBWMixerConstants (params->blackwhite.setting, params->blackwhite.filter, params->blackwhite.algo, filcor, + bwr, bwg, bwb, mixerOrange, mixerYellow, mixerCyan, mixerPurple, mixerMagenta, + params->blackwhite.autoc, complem, kcorec, rrm, ggm, bbm); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 16) @@ -4454,20 +4484,25 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int j = 0; j < tW; j++) { //mix channel - tmpImage->r(i, j) = tmpImage->g(i, j) = tmpImage->b(i, j) = CLIP((bwr * tmpImage->r(i, j) + bwg * tmpImage->g(i, j) + bwb * tmpImage->b(i, j)) * kcorec); + tmpImage->r (i, j) = tmpImage->g (i, j) = tmpImage->b (i, j) = CLIP ((bwr * tmpImage->r (i, j) + bwg * tmpImage->g (i, j) + bwb * tmpImage->b (i, j)) * kcorec); #ifndef __SSE2__ + //gamma correction: pseudo TRC curve if (hasgammabw) { - Color::trcGammaBW (tmpImage->r(i, j), tmpImage->g(i, j), tmpImage->b(i, j), gammabwr, gammabwg, gammabwb); + Color::trcGammaBW (tmpImage->r (i, j), tmpImage->g (i, j), tmpImage->b (i, j), gammabwr, gammabwg, gammabwb); } + #endif } + #ifdef __SSE2__ + if (hasgammabw) { //gamma correction: pseudo TRC curve - Color::trcGammaBWRow (tmpImage->r(i), tmpImage->g(i), tmpImage->b(i), tW, gammabwr, gammabwg, gammabwb); + Color::trcGammaBWRow (tmpImage->r (i), tmpImage->g (i), tmpImage->b (i), tW, gammabwr, gammabwg, gammabwb); } + #endif } } @@ -4479,7 +4514,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int i = 0; i < tH; i++) { for (int j = 0; j < tW; j++) { - editWhatever->v(i, j) = Color::gamma2curve[tmpImage->r(i, j)] / 65535.f; // assuming that r=g=b + editWhatever->v (i, j) = Color::gamma2curve[tmpImage->r (i, j)] / 65535.f; // assuming that r=g=b } } } @@ -4493,8 +4528,8 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int i = 0; i < tH; i++) { for (int j = 0; j < tW; j++) { - const StandardToneCurvebw& userToneCurve = static_cast(customToneCurvebw2); - userToneCurve.Apply(tmpImage->r(i, j), tmpImage->g(i, j), tmpImage->b(i, j)); + const StandardToneCurvebw& userToneCurve = static_cast (customToneCurvebw2); + userToneCurve.Apply (tmpImage->r (i, j), tmpImage->g (i, j), tmpImage->b (i, j)); } } } else if (afterCurveMode == BlackWhiteParams::TC_MODE_WEIGHTEDSTD_BW) { // apply the curve to the rgb channels, weighted @@ -4504,13 +4539,13 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int i = 0; i < tH; i++) { //for ulterior usage if bw data modified for (int j = 0; j < tW; j++) { - const WeightedStdToneCurvebw& userToneCurve = static_cast(customToneCurvebw2); + const WeightedStdToneCurvebw& userToneCurve = static_cast (customToneCurvebw2); - tmpImage->r(i, j) = CLIP(tmpImage->r(i, j)); - tmpImage->g(i, j) = CLIP(tmpImage->g(i, j)); - tmpImage->b(i, j) = CLIP(tmpImage->b(i, j)); + tmpImage->r (i, j) = CLIP (tmpImage->r (i, j)); + tmpImage->g (i, j) = CLIP (tmpImage->g (i, j)); + tmpImage->b (i, j) = CLIP (tmpImage->b (i, j)); - userToneCurve.Apply(tmpImage->r(i, j), tmpImage->g(i, j), tmpImage->b(i, j)); + userToneCurve.Apply (tmpImage->r (i, j), tmpImage->g (i, j), tmpImage->b (i, j)); } } } @@ -4518,7 +4553,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer //colortoning with black and white if (hasColorToning) { - if(params->colorToning.method == "Splitco") { + if (params->colorToning.method == "Splitco") { /* #if 1 for (int i=istart,ti=0; icolorToning.lumamode) { + if (params->colorToning.lumamode) { preser = 1; } @@ -4548,32 +4583,32 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int i = 0; i < tH; i++) { for (int j = 0; j < tW; j++) { - float r = tmpImage->r(i, j); - float g = tmpImage->g(i, j); - float b = tmpImage->b(i, j); + float r = tmpImage->r (i, j); + float g = tmpImage->g (i, j); + float b = tmpImage->b (i, j); float lumbefore = 0.299f * r + 0.587f * g + 0.114f * b; - if(lumbefore < 65000.f && lumbefore > 500.f) { //reduct artifacts for highlights an extrem shadows + if (lumbefore < 65000.f && lumbefore > 500.f) { //reduct artifacts for highlights an extrem shadows float ro, go, bo; int mode = 1; toningsmh (r, g, b, ro, go, bo, RedLow, GreenLow, BlueLow, RedMed, GreenMed, BlueMed, RedHigh, GreenHigh, BlueHigh, reducac, mode, preser, strProtect); float lumafter = 0.299f * ro + 0.587f * go + 0.114f * bo; float preserv = 1.f; - if(preser == 1) { + if (preser == 1) { preserv = lumbefore / lumafter; } ro *= preserv; go *= preserv; bo *= preserv; - ro = CLIP(ro); - go = CLIP(go); - bo = CLIP(bo); - tmpImage->r(i, j) = ro; - tmpImage->g(i, j) = go; - tmpImage->b(i, j) = bo; + ro = CLIP (ro); + go = CLIP (go); + bo = CLIP (bo); + tmpImage->r (i, j) = ro; + tmpImage->g (i, j) = go; + tmpImage->b (i, j) = bo; } } } @@ -4586,7 +4621,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float reducac = 0.4f; int preser = 0; - if(params->colorToning.lumamode) { + if (params->colorToning.lumamode) { preser = 1; } @@ -4601,31 +4636,31 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer iphigh = (float)ctColorCurve.high; //2 colours - ctColorCurve.getVal(iphigh, xh, yh, zh); - ctColorCurve.getVal(iplow, xl, yl, zl); + ctColorCurve.getVal (iphigh, xh, yh, zh); + ctColorCurve.getVal (iplow, xl, yl, zl); - Color::xyz2rgb(xh, yh, zh, rh, gh, bh, wip); - Color::xyz2rgb(xl, yl, zl, rl, gl, bl, wip); + Color::xyz2rgb (xh, yh, zh, rh, gh, bh, wip); + Color::xyz2rgb (xl, yl, zl, rl, gl, bl, wip); //retrieve rgb value with s and l =1 - retreavergb(rl, gl, bl); - retreavergb(rh, gh, bh); + retreavergb (rl, gl, bl); + retreavergb (rh, gh, bh); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 5) #endif for (int i = 0; i < tH; i++) { for (int j = 0; j < tW; j++) { - float r = tmpImage->r(i, j); - float g = tmpImage->g(i, j); - float b = tmpImage->b(i, j); + float r = tmpImage->r (i, j); + float g = tmpImage->g (i, j); + float b = tmpImage->b (i, j); float ro, go, bo; int mode = 1; toning2col (r, g, b, ro, go, bo, iplow, iphigh, rl, gl, bl, rh, gh, bh, SatLow, SatHigh, balanS, balanH, reducac, mode, preser, strProtect); - tmpImage->r(i, j) = ro; - tmpImage->g(i, j) = go; - tmpImage->b(i, j) = bo; + tmpImage->r (i, j) = ro; + tmpImage->g (i, j) = go; + tmpImage->b (i, j) = bo; } } } @@ -4646,13 +4681,13 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer metchrom = 3; } - if(metchrom == 3) { + if (metchrom == 3) { twocol = false; } float iplow = 0.f, iphigh = 0.f; - if(!twocol) { + if (!twocol) { iplow = (float)ctColorCurve.low; iphigh = (float)ctColorCurve.high; @@ -4660,7 +4695,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer int twoc = 0; //integer instead of bool to let more possible choice...other than 2 and 500. - if(!twocol) { + if (!twocol) { twoc = 0; // 2 colours } else { twoc = 1; // 500 colours @@ -4668,32 +4703,32 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer if (params->colorToning.method == "Lab") { algm = 1; - } else if(params->colorToning.method == "Lch") { + } else if (params->colorToning.method == "Lch") { algm = 2; //in case of } - if(algm <= 2) { + if (algm <= 2) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 5) #endif for (int i = 0; i < tH; i++) { for (int j = 0; j < tW; j++) { - float r = tmpImage->r(i, j); - float g = tmpImage->g(i, j); - float b = tmpImage->b(i, j); + float r = tmpImage->r (i, j); + float g = tmpImage->g (i, j); + float b = tmpImage->b (i, j); float ro, bo, go; labtoning (r, g, b, ro, go, bo, algm, metchrom, twoc, satLimit, satLimitOpacity, ctColorCurve, ctOpacityCurve, clToningcurve, cl2Toningcurve, iplow, iphigh, wp, wip); - tmpImage->r(i, j) = CLIP(ro); - tmpImage->g(i, j) = CLIP(go); - tmpImage->b(i, j) = CLIP(bo); + tmpImage->r (i, j) = CLIP (ro); + tmpImage->g (i, j) = CLIP (go); + tmpImage->b (i, j) = CLIP (bo); } } } } - else if (params->colorToning.method.substr(0, 3) == "RGB" && opautili) { + else if (params->colorToning.method.substr (0, 3) == "RGB" && opautili) { // color toning #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 5) @@ -4701,31 +4736,31 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int i = 0; i < tH; i++) { for (int j = 0; j < tW; j++) { - float r = tmpImage->r(i, j); - float g = tmpImage->g(i, j); - float b = tmpImage->b(i, j); + float r = tmpImage->r (i, j); + float g = tmpImage->g (i, j); + float b = tmpImage->b (i, j); // Luminance = (0.299f*r + 0.587f*g + 0.114f*b) float h, s, l; - Color::rgb2hsl(r, g, b, h, s, l); + Color::rgb2hsl (r, g, b, h, s, l); - float l_ = Color::gamma_srgb(l * 65535.f) / 65535.f; + float l_ = Color::gamma_srgb (l * 65535.f) / 65535.f; // get the opacity and tweak it to preserve saturated colors float opacity = ctOpacityCurve.lutOpacityCurve[l_ * 500.f] / 4.f; float r2, g2, b2; - ctColorCurve.getVal(l_, r2, g2, b2); // get the color from the color curve + ctColorCurve.getVal (l_, r2, g2, b2); // get the color from the color curve float h2, s2, l2; - Color::rgb2hsl(r2, g2, b2, h2, s2, l2); // transform this new color to hsl + Color::rgb2hsl (r2, g2, b2, h2, s2, l2); // transform this new color to hsl - Color::hsl2rgb(h2, s2, l, r2, g2, b2); + Color::hsl2rgb (h2, s2, l, r2, g2, b2); - tmpImage->r(i, j) = r + (r2 - r) * opacity; - tmpImage->g(i, j) = g + (g2 - g) * opacity; - tmpImage->b(i, j) = b + (b2 - b) * opacity; + tmpImage->r (i, j) = r + (r2 - r) * opacity; + tmpImage->g (i, j) = g + (g2 - g) * opacity; + tmpImage->b (i, j) = b + (b2 - b) * opacity; } } } @@ -4760,9 +4795,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer for (int i = 0; i < tH; i++) { for (int j = 0; j < tW; j++) { - float r = tmpImage->r(i, j); - float g = tmpImage->g(i, j); - float b = tmpImage->b(i, j); + float r = tmpImage->r (i, j); + float g = tmpImage->g (i, j); + float b = tmpImage->b (i, j); float x = toxyz[0][0] * r + toxyz[0][1] * g + toxyz[0][2] * b; float y = toxyz[1][0] * r + toxyz[1][1] * g + toxyz[1][2] * b; @@ -4770,9 +4805,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float fx, fy, fz; - fx = (x < MAXVALF ? Color::cachef[x] : 327.68f * std::cbrt(x / MAXVALF)); - fy = (y < MAXVALF ? Color::cachef[y] : 327.68f * std::cbrt(y / MAXVALF)); - fz = (z < MAXVALF ? Color::cachef[z] : 327.68f * std::cbrt(z / MAXVALF)); + fx = (x < MAXVALF ? Color::cachef[x] : 327.68f * std::cbrt (x / MAXVALF)); + fy = (y < MAXVALF ? Color::cachef[y] : 327.68f * std::cbrt (y / MAXVALF)); + fz = (z < MAXVALF ? Color::cachef[z] : 327.68f * std::cbrt (z / MAXVALF)); lab->L[i][j] = 116.0f * fy - 5242.88f; //5242.88=16.0*327.68; lab->a[i][j] = 500.0f * (fx - fy); @@ -4808,31 +4843,31 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer **/ void ImProcFunctions::retreavergb (float &r, float &g, float &b) { - float mini = min(r, g, b); - float maxi = max(r, g, b); + float mini = min (r, g, b); + float maxi = max (r, g, b); float kkm = 65535.f / maxi; - if(b == mini && r == maxi) { + if (b == mini && r == maxi) { r = 65535.f; g = kkm * (g - b); b = 0.f; - } else if(b == mini && g == maxi) { + } else if (b == mini && g == maxi) { g = 65535.f; r = kkm * (r - b); b = 0.f; - } else if(g == mini && r == maxi) { + } else if (g == mini && r == maxi) { r = 65535.f; b = kkm * (b - g); g = 0.f; - } else if(g == mini && b == maxi) { + } else if (g == mini && b == maxi) { b = 65535.f; r = kkm * (r - g); g = 0.f; - } else if(r == mini && b == maxi) { + } else if (r == mini && b == maxi) { b = 65535.f; g = kkm * (g - r); r = 0.f; - } else if(r == mini && g == maxi) { + } else if (r == mini && g == maxi) { g = 65535.f; b = kkm * (b - r); r = 0.f; @@ -4857,7 +4892,7 @@ void ImProcFunctions::secondeg_end (float reducac, float vinf, float &aa, float float a3 = 1.f - v0 * v0; float a4 = me * me - v0 * v0; aa = (1.f + (zrd - 1.f) * (1 - v0) / a2) / (a4 * (1.f - v0) / a2 - a3); - bb = -(1.f + a3 * aa) / (1.f - v0); + bb = - (1.f + a3 * aa) / (1.f - v0); cc = - (aa + bb); } @@ -4906,7 +4941,7 @@ void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go float GreenL = 1.f + (GreenLow - 1.f) * 0.4f; float BlueL = 1.f + (BlueLow - 1.f) * bmu; float h, s, v; - Color::rgb2hsv(r, g, b, h, s, v); + Color::rgb2hsv (r, g, b, h, s, v); float ksat = 1.f; float ksatlow = 1.f; // float s_0=0.55f; @@ -4923,10 +4958,10 @@ void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go float rlh = 2.2f; //1.1 float rlob = bmu; //for BW old mode - if(mode == 0) { //color - rlo *= pow_F(strProtect, 0.4f); //0.5 ==> 0.75 - rlh *= pow_F(strProtect, 0.4f); - rlm *= pow_F(strProtect, 0.4f); + if (mode == 0) { //color + rlo *= pow_F (strProtect, 0.4f); //0.5 ==> 0.75 + rlh *= pow_F (strProtect, 0.4f); + rlm *= pow_F (strProtect, 0.4f); } else { //bw coefficient to preserve same results as before for satlimtopacity = 0.5 (default) rlo = strProtect * 0.8f; //0.4 rlob = strProtect; //0.5 @@ -4934,17 +4969,17 @@ void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go rlh = strProtect * 2.4f; //1.2 } - if(mode == 0) { + if (mode == 0) { rlob = rlo; } //fixed value of reducac=0.3 //secondeg_end (reducac, v0, aa, bb, cc); - if(mode == 1) { + if (mode == 1) { reducac = 0.5f; //black and white mode - if(v > 0.15f) { + if (v > 0.15f) { kl = (-1.f / 0.85f) * v + (1.f) / 0.85f; //Low light ==> decrease action after v=0.15 } } else { //color @@ -4955,63 +4990,63 @@ void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go float aab, bbb; secondeg_begin (0.7f, v0, aab, bbb); - if(v > v0) { + if (v > v0) { kl = aa * v * v + bb * v + cc; //verified ==> exact } else if (mode == 0) { kl = aab * v * v + bbb * v; //ksatlow=ksat; } } - if(RedLow != 1.f) { + if (RedLow != 1.f) { RedL = 1.f + (RedLow - 1.f) * kl * ksat * rlo; //0.4 - if(RedLow >= 1.f) { + if (RedLow >= 1.f) { g -= 20000.f * (RedL - 1.f) * ksatlow; b -= 20000.f * (RedL - 1.f) * ksatlow; } else { r += 20000.f * (RedL - 1.f) * ksatlow; } - r = CLIP(r); - g = CLIP(g); - b = CLIP(b); + r = CLIP (r); + g = CLIP (g); + b = CLIP (b); } - if(GreenLow != 1.f) { + if (GreenLow != 1.f) { GreenL = 1.f + (GreenLow - 1.f) * kl * ksat * rlo; //0.4 - if(GreenLow >= 1.f) { + if (GreenLow >= 1.f) { r -= 20000.f * (GreenL - 1.f) * ksatlow; b -= 20000.f * (GreenL - 1.f) * ksatlow; } else { g += 20000.f * (GreenL - 1.f) * ksatlow; } - r = CLIP(r); - b = CLIP(b); - g = CLIP(g); + r = CLIP (r); + b = CLIP (b); + g = CLIP (g); } - if(BlueLow != 1.f) { + if (BlueLow != 1.f) { BlueL = 1.f + (BlueLow - 1.f) * kl * ksat * rlob; - if(BlueLow >= 1.f) { + if (BlueLow >= 1.f) { r -= 20000.f * (BlueL - 1.f) * ksatlow; g -= 20000.f * (BlueL - 1.f) * ksatlow; } else { b += 20000.f * (BlueL - 1.f) * ksatlow; } - r = CLIP(r); - g = CLIP(g); - b = CLIP(b); + r = CLIP (r); + g = CLIP (g); + b = CLIP (b); } // mid tones float km; float v0m = 0.5f; //max action - if(v < v0m) { + if (v < v0m) { float aam, bbm; float vend = v0m; secondeg_begin (reducac, vend, aam, bbm); @@ -5025,67 +5060,67 @@ void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go float RedM = 1.f + (RedMed - 1.f) * rlm; - if(RedMed != 1.f) { + if (RedMed != 1.f) { RedM = 1.f + (RedMed - 1.f) * km * rlm; - if(RedMed >= 1.f) { + if (RedMed >= 1.f) { r += 20000.f * (RedM - 1.f); g -= 10000.f * (RedM - 1.f); b -= 10000.f * (RedM - 1.f); - r = CLIP(r); - g = CLIP(g); - b = CLIP(b); + r = CLIP (r); + g = CLIP (g); + b = CLIP (b); } else { r += 10000.f * (RedM - 1.f); g -= 20000.f * (RedM - 1.f); b -= 20000.f * (RedM - 1.f); - r = CLIP(r); - g = CLIP(g); - b = CLIP(b); + r = CLIP (r); + g = CLIP (g); + b = CLIP (b); } } float GreenM = 1.f + (GreenMed - 1.f) * rlm; - if(GreenMed != 1.f) { + if (GreenMed != 1.f) { GreenM = 1.f + (GreenMed - 1.f) * km * rlm; - if(GreenMed >= 1.f) { + if (GreenMed >= 1.f) { r -= 10000.f * (GreenM - 1.f); g += 20000.f * (GreenM - 1.f); b -= 10000.f * (GreenM - 1.f); - r = CLIP(r); - g = CLIP(g); - b = CLIP(b); + r = CLIP (r); + g = CLIP (g); + b = CLIP (b); } else { r -= 20000.f * (GreenM - 1.f); g += 10000.f * (GreenM - 1.f); b -= 20000.f * (GreenM - 1.f); - r = CLIP(r); - g = CLIP(g); - b = CLIP(b); + r = CLIP (r); + g = CLIP (g); + b = CLIP (b); } } float BlueM = 1.f + (BlueMed - 1.f) * rlm; - if(BlueMed != 1.f) { + if (BlueMed != 1.f) { BlueM = 1.f + (BlueMed - 1.f) * km * rlm; - if(BlueMed >= 1.f) { + if (BlueMed >= 1.f) { r -= 10000.f * (BlueM - 1.f); g -= 10000.f * (BlueM - 1.f); b += 20000.f * (BlueM - 1.f); - r = CLIP(r); - g = CLIP(g); - b = CLIP(b); + r = CLIP (r); + g = CLIP (g); + b = CLIP (b); } else { r -= 20000.f * (BlueM - 1.f); g -= 20000.f * (BlueM - 1.f); b += 10000.f * (BlueM - 1.f); - r = CLIP(r); - g = CLIP(g); - b = CLIP(b); + r = CLIP (r); + g = CLIP (g); + b = CLIP (b); } } @@ -5098,7 +5133,7 @@ void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go // float hmu=1.5f; // if(mode==1) hmu=1.2f;//for BW old mode - if(v > v00) { + if (v > v00) { kh = (-1.f / (1.f - v00)) * v + (1.f) / (1.f - v00); //High tones } else { kh = aa0 * v * v + bb0 * v; //verification = good @@ -5108,49 +5143,49 @@ void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go float GreenH = 1.f + (GreenHigh - 1.f) * rlh; float BlueH = 1.f + (BlueHigh - 1.f) * rlh; //1.2 - if(RedHigh != 1.f) { + if (RedHigh != 1.f) { RedH = 1.f + (RedHigh - 1.f) * kh * rlh; //1.2 - if(RedHigh >= 1.f) { + if (RedHigh >= 1.f) { r += 20000.f * (RedH - 1.f); - r = CLIP(r); + r = CLIP (r); } else { g -= 20000.f * (RedH - 1.f); b -= 20000.f * (RedH - 1.f); } - g = CLIP(g); - b = CLIP(b); + g = CLIP (g); + b = CLIP (b); } - if(GreenHigh != 1.f) { + if (GreenHigh != 1.f) { GreenH = 1.f + (GreenHigh - 1.f) * kh * rlh; //1.2 - if(GreenHigh >= 1.f) { + if (GreenHigh >= 1.f) { g += 20000.f * (GreenH - 1.f); - g = CLIP(g); + g = CLIP (g); } else { r -= 20000.f * (GreenH - 1.f); b -= 20000.f * (GreenH - 1.f); } - r = CLIP(r); - b = CLIP(b); + r = CLIP (r); + b = CLIP (b); } - if(BlueHigh != 1.f) { + if (BlueHigh != 1.f) { BlueH = 1.f + (BlueHigh - 1.f) * kh * rlh; //1.2 - if(BlueHigh >= 1.f) { + if (BlueHigh >= 1.f) { b += 20000.f * (BlueH - 1.f); - b = CLIP(b); + b = CLIP (b); } else { r -= 20000.f * (BlueH - 1.f); g -= 20000.f * (BlueH - 1.f); } - r = CLIP(r); - g = CLIP(g); + r = CLIP (r); + g = CLIP (g); } ro = r; @@ -5174,9 +5209,9 @@ void ImProcFunctions::toning2col (float r, float g, float b, float &ro, float &g { float lumbefore = 0.299f * r + 0.587f * g + 0.114f * b; float h, s, l; - Color::rgb2hsl(r, g, b, h, s, l); + Color::rgb2hsl (r, g, b, h, s, l); float v; - Color::rgb2hsv(r, g, b, h, s, v); + Color::rgb2hsv (r, g, b, h, s, v); float ksat = 1.f; float ksatlow = 1.f; /* @@ -5188,8 +5223,8 @@ void ImProcFunctions::toning2col (float r, float g, float b, float &ro, float &g float kl = 1.f; float rlo = 1.f; float rlh = 2.2f; - rlo *= pow_F(strProtect, 0.4f); //0.5 ==> 0.75 transfered value for more action - rlh *= pow_F(strProtect, 0.4f); + rlo *= pow_F (strProtect, 0.4f); //0.5 ==> 0.75 transfered value for more action + rlh *= pow_F (strProtect, 0.4f); //low tones //second degree float aa, bb, cc; @@ -5199,54 +5234,54 @@ void ImProcFunctions::toning2col (float r, float g, float b, float &ro, float &g secondeg_begin (0.7f, iplow, aab, bbb); - if(v > iplow) { + if (v > iplow) { kl = aa * v * v + bb * v + cc; } else if (mode == 0) { kl = aab * v * v + bbb * v; } - if(SatLow > 0.f) { + if (SatLow > 0.f) { //rl gl bl float krl = rl / (rl + gl + bl); float kgl = gl / (rl + gl + bl); float kbl = bl / (rl + gl + bl); float RedL, GreenL, BlueL; - if(g < 20000.f || b < 20000.f || r < 20000.f) { - float kmgb = min(r, g, b); //I have tested ...0.85 compromise... - kl *= pow((kmgb / 20000.f), 0.85f); + if (g < 20000.f || b < 20000.f || r < 20000.f) { + float kmgb = min (r, g, b); //I have tested ...0.85 compromise... + kl *= pow ((kmgb / 20000.f), 0.85f); } RedL = 1.f + (SatLow * krl) * kl * ksat * rlo * balanS; //0.4 - if(krl > 0.f) { + if (krl > 0.f) { g -= 20000.f * (RedL - 1.f) * ksatlow; b -= 20000.f * (RedL - 1.f) * ksatlow; } - g = CLIP(g); - b = CLIP(b); + g = CLIP (g); + b = CLIP (b); GreenL = 1.f + (SatLow * kgl) * kl * ksat * rlo * balanS; //0.4 - if(kgl > 0.f) { + if (kgl > 0.f) { r -= 20000.f * (GreenL - 1.f) * ksatlow; b -= 20000.f * (GreenL - 1.f) * ksatlow; } - r = CLIP(r); - b = CLIP(b); + r = CLIP (r); + b = CLIP (b); BlueL = 1.f + (SatLow * kbl) * kl * ksat * rlo * balanS; //0.4 - if(kbl > 0.f) { + if (kbl > 0.f) { r -= 20000.f * (BlueL - 1.f) * ksatlow; g -= 20000.f * (BlueL - 1.f) * ksatlow; } - r = CLIP(r); - g = CLIP(g); + r = CLIP (r); + g = CLIP (g); } //high tones @@ -5255,15 +5290,15 @@ void ImProcFunctions::toning2col (float r, float g, float b, float &ro, float &g //fixed value of reducac ==0.4; secondeg_begin (reducac, iphigh, aa0, bb0); - if(v > iphigh) { + if (v > iphigh) { kh = (-1.f / (1.f - iphigh)) * v + (1.f) / (1.f - iphigh); //Low light ==> decrease action after iplow } else { kh = aa0 * v * v + bb0 * v; } - if(g > 45535.f || b > 45535.f || r > 45535.f) { - float kmgb = max(r, g, b); + if (g > 45535.f || b > 45535.f || r > 45535.f) { + float kmgb = max (r, g, b); float cora = 1.f / (45535.f - 65535.f); float corb = 1.f - cora * 45535.f; float cor = kmgb * cora + corb; @@ -5276,45 +5311,45 @@ void ImProcFunctions::toning2col (float r, float g, float b, float &ro, float &g } - if(SatHigh > 0.f) { + if (SatHigh > 0.f) { float RedH, GreenH, BlueH; float krh = rh / (rh + gh + bh); float kgh = gh / (rh + gh + bh); float kbh = bh / (rh + gh + bh); RedH = 1.f + (SatHigh * krh) * kh * rlh * balanH; //1.2 - if(krh > 0.f) { + if (krh > 0.f) { r += 20000.f * (RedH - 1.f); - r = CLIP(r); + r = CLIP (r); } - g = CLIP(g); - b = CLIP(b); + g = CLIP (g); + b = CLIP (b); GreenH = 1.f + (SatHigh * kgh) * kh * rlh * balanH; //1.2 - if(kgh > 0.f) { + if (kgh > 0.f) { g += 20000.f * (GreenH - 1.f); - g = CLIP(g); + g = CLIP (g); } - r = CLIP(r); - b = CLIP(b); + r = CLIP (r); + b = CLIP (b); BlueH = 1.f + (SatHigh * kbh) * kh * rlh * balanH; //1.2 - if(kbh > 0.f) { + if (kbh > 0.f) { b += 20000.f * (BlueH - 1.f); - b = CLIP(b); + b = CLIP (b); } - r = CLIP(r); - g = CLIP(g); + r = CLIP (r); + g = CLIP (g); } float lumafter = 0.299f * r + 0.587f * g + 0.114f * b; float preserv = 1.f; - if(preser == 1) { + if (preser == 1) { preserv = lumbefore / lumafter; } @@ -5325,9 +5360,9 @@ void ImProcFunctions::toning2col (float r, float g, float b, float &ro, float &g ro *= preserv; go *= preserv; bo *= preserv; - ro = CLIP(ro); - go = CLIP(go); - bo = CLIP(bo); + ro = CLIP (ro); + go = CLIP (go); + bo = CLIP (bo); } /** @@ -5346,21 +5381,21 @@ void ImProcFunctions::labtoning (float r, float g, float b, float &ro, float &go { float realL; float h, s, l; - Color::rgb2hsl(r, g, b, h, s, l); + Color::rgb2hsl (r, g, b, h, s, l); float x2, y2, z2; float xl, yl, zl; - if(twoc != 1) { + if (twoc != 1) { l = (Color::gammatab_13_2[ l * 65535.f]) / 65535.f; //to compensate L from Lab iphigh = (Color::gammatab_13_2[iphigh * 65535.f]) / 65535.f; iplow = (Color::gammatab_13_2[ iplow * 65535.f]) / 65535.f; } - if(twoc == 1) { - ctColorCurve.getVal(l, x2, y2, z2); + if (twoc == 1) { + ctColorCurve.getVal (l, x2, y2, z2); } else { - ctColorCurve.getVal(iphigh, x2, y2, z2); - ctColorCurve.getVal(iplow, xl, yl, zl); + ctColorCurve.getVal (iphigh, x2, y2, z2); + ctColorCurve.getVal (iplow, xl, yl, zl); } realL = l; @@ -5372,8 +5407,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; - 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)); + 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; bool chr = true; @@ -5382,23 +5417,23 @@ void ImProcFunctions::labtoning (float r, float g, float b, float &ro, float &go float chromat, luma; if (clToningcurve[lm * 65535.f] / (lm * 65535.f) < 1.f) { - chromat = (clToningcurve[(lm) * 65535.f] / (lm * 65535.f)) - 1.f; //special effect + chromat = (clToningcurve[ (lm) * 65535.f] / (lm * 65535.f)) - 1.f; //special effect } else { - chromat = 1.f - SQR(SQR((lm * 65535.f) / clToningcurve[(lm) * 65535.f])); //apply C=f(L) acts on 'a' and 'b' + chromat = 1.f - SQR (SQR ((lm * 65535.f) / clToningcurve[ (lm) * 65535.f])); //apply C=f(L) acts on 'a' and 'b' } if (cl2Toningcurve[lm * 65535.f] / (lm * 65535.f) < 1.f) { - luma = (cl2Toningcurve[(lm) * 65535.f] / (lm * 65535.f)) - 1.f; //special effect + luma = (cl2Toningcurve[ (lm) * 65535.f] / (lm * 65535.f)) - 1.f; //special effect } else { - luma = 1.f - SQR(SQR((lm * 65535.f) / (cl2Toningcurve[(lm) * 65535.f]))); //apply C2=f(L) acts only on 'b' + luma = 1.f - SQR (SQR ((lm * 65535.f) / (cl2Toningcurve[ (lm) * 65535.f]))); //apply C2=f(L) acts only on 'b' } int todo = 1; if (algm == 1) { - Color::interpolateRGBColor(realL, iplow, iphigh, algm, opacity, twoc, metchrom, chr, lum, chromat, luma, r, g, b, xl, yl, zl, x2, y2, z2, todo, wp, wip, ro, go, bo); + Color::interpolateRGBColor (realL, iplow, iphigh, algm, opacity, twoc, metchrom, chr, lum, chromat, luma, r, g, b, xl, yl, zl, x2, y2, z2, todo, wp, wip, ro, go, bo); } else { - Color::interpolateRGBColor(realL, iplow, iphigh, algm, opacity2, twoc, metchrom, chr, lum, chromat, luma, r, g, b, xl, yl, zl, x2, y2, z2, todo, wp, wip, ro, go, bo); + Color::interpolateRGBColor (realL, iplow, iphigh, algm, opacity2, twoc, metchrom, chr, lum, chromat, luma, r, g, b, xl, yl, zl, x2, y2, z2, todo, wp, wip, ro, go, bo); } } @@ -5456,7 +5491,7 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu bool chutili = false; if (params->labCurve.chromaticity > -100) { - chCurve = new FlatCurve(params->labCurve.chcurve); + chCurve = new FlatCurve (params->labCurve.chcurve); if (!chCurve || chCurve->isIdentity()) { if (chCurve) { @@ -5473,7 +5508,7 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu bool lhutili = false; if (params->labCurve.chromaticity > -100) { - lhCurve = new FlatCurve(params->labCurve.lhcurve); + lhCurve = new FlatCurve (params->labCurve.lhcurve); if (!lhCurve || lhCurve->isIdentity()) { if (lhCurve) { @@ -5490,7 +5525,7 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu bool hhutili = false; if (params->labCurve.chromaticity > -100) { - hhCurve = new FlatCurve(params->labCurve.hhcurve); + hhCurve = new FlatCurve (params->labCurve.hhcurve); if (!hhCurve || hhCurve->isIdentity()) { if (hhCurve) { @@ -5508,10 +5543,10 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu LUTu hist16Llad; //preparate for histograms CIECAM - if(pW != 1) { //only with improccoordinator - hist16Clad(65536); + if (pW != 1) { //only with improccoordinator + hist16Clad (65536); hist16Clad.clear(); - hist16Llad(65536); + hist16Llad (65536); hist16Llad.clear(); } @@ -5565,38 +5600,38 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu float protect_red, protect_redh; protect_red = protectRed;//default=60 chroma: one can put more or less if necessary...in 'option' 40...160 - if(protect_red < 20.0f) { + if (protect_red < 20.0f) { protect_red = 20.0; // avoid too low value } - if(protect_red > 180.0f) { + if (protect_red > 180.0f) { protect_red = 180.0; // avoid too high value } - protect_redh = float(protectRedH); //default=0.4 rad : one can put more or less if necessary...in 'option' 0.2 ..1.0 + protect_redh = float (protectRedH); //default=0.4 rad : one can put more or less if necessary...in 'option' 0.2 ..1.0 - if(protect_redh < 0.1f) { + if (protect_redh < 0.1f) { protect_redh = 0.1f; //avoid divide by 0 and negatives values } - if(protect_redh > 1.0f) { + if (protect_redh > 1.0f) { protect_redh = 1.0f; //avoid too big values } float protect_redhcur = protectRedH;//default=0.4 rad : one can put more or less if necessary...in 'option' 0.2 ..1 - if(protect_redhcur < 0.1f) { + if (protect_redhcur < 0.1f) { protect_redhcur = 0.1f; //avoid divide by 0 and negatives values:minimal protection for transition } - if(protect_redhcur > 3.5f) { + if (protect_redhcur > 3.5f) { protect_redhcur = 3.5f; //avoid too big values } //increase saturation after denoise : ...approximation float factnoise = 1.f; - if(params->dirpyrDenoise.enabled) { + if (params->dirpyrDenoise.enabled) { factnoise = (1.f + params->dirpyrDenoise.chroma / 500.f); //levels=5 // if(yyyy) factnoise=(1.f+params->dirpyrDenoise.chroma/100.f);//levels=7 } @@ -5637,28 +5672,28 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu if (avoidColorShift) // only if user activate Lab adjustments - if(autili || butili || ccutili || cclutili || chutili || lhutili || hhutili || clcutili || utili || chromaticity) { - Color::LabGamutMunsell(lold->L[i], lold->a[i], lold->b[i], W, /*corMunsell*/true, /*lumaMuns*/false, params->toneCurve.hrenabled, /*gamut*/true, wip, multiThread); + if (autili || butili || ccutili || cclutili || chutili || lhutili || hhutili || clcutili || utili || chromaticity) { + Color::LabGamutMunsell (lold->L[i], lold->a[i], lold->b[i], W, /*corMunsell*/true, /*lumaMuns*/false, params->toneCurve.hrenabled, /*gamut*/true, wip, multiThread); } #ifdef __SSE2__ // precalculate some values using SSE - if(bwToning || (!autili && !butili)) { - __m128 c327d68v = _mm_set1_ps(327.68f); + if (bwToning || (!autili && !butili)) { + __m128 c327d68v = _mm_set1_ps (327.68f); __m128 av, bv; int k; for (k = 0; k < W - 3; k += 4) { - av = LVFU(lold->a[i][k]); - bv = LVFU(lold->b[i][k]); - STVF(HHBuffer[k], xatan2f(bv, av)); - STVF(CCBuffer[k], _mm_sqrt_ps(SQRV(av) + SQRV(bv)) / c327d68v); + av = LVFU (lold->a[i][k]); + bv = LVFU (lold->b[i][k]); + STVF (HHBuffer[k], xatan2f (bv, av)); + STVF (CCBuffer[k], _mm_sqrt_ps (SQRV (av) + SQRV (bv)) / c327d68v); } - for(; k < W; k++) { - HHBuffer[k] = xatan2f(lold->b[i][k], lold->a[i][k]); - CCBuffer[k] = sqrt(SQR(lold->a[i][k]) + SQR(lold->b[i][k])) / 327.68f; + for (; k < W; k++) { + HHBuffer[k] = xatan2f (lold->b[i][k], lold->a[i][k]); + CCBuffer[k] = sqrt (SQR (lold->a[i][k]) + SQR (lold->b[i][k])) / 327.68f; } } @@ -5674,18 +5709,18 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu float memChprov; float2 sincosval; - if(bwToning) { // this values will be also set when bwToning is false some lines down + if (bwToning) { // this values will be also set when bwToning is false some lines down #ifdef __SSE2__ // use precalculated values from above HH = HHBuffer[j]; CC = CCBuffer[j]; #else - HH = xatan2f(lold->b[i][j], lold->a[i][j]); - CC = sqrt(SQR(lold->a[i][j]) + SQR(lold->b[i][j])) / 327.68f; + HH = xatan2f (lold->b[i][j], lold->a[i][j]); + CC = sqrt (SQR (lold->a[i][j]) + SQR (lold->b[i][j])) / 327.68f; #endif // According to mathematical laws we can get the sin and cos of HH by simple operations - if(CC == 0.0f) { + if (CC == 0.0f) { sincosval.y = 1.0f; sincosval.x = 0.0f; } else { @@ -5699,20 +5734,20 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu } if (editPipette && editID == EUID_Lab_LCurve) { - editWhatever->v(i, j) = LIM01(Lin / 32768.0f); // Lab L pipette + editWhatever->v (i, j) = LIM01 (Lin / 32768.0f); // Lab L pipette } lnew->L[i][j] = curve[Lin]; float Lprov1 = (lnew->L[i][j]) / 327.68f; - if(editPipette) { + if (editPipette) { if (editID == EUID_Lab_aCurve) { // Lab a pipette float chromapipa = lold->a[i][j] + (32768.f * 1.28f); - editWhatever->v(i, j) = LIM01((chromapipa) / (65536.f * 1.28f)); + editWhatever->v (i, j) = LIM01 ((chromapipa) / (65536.f * 1.28f)); } else if (editID == EUID_Lab_bCurve) { //Lab b pipette float chromapipb = lold->b[i][j] + (32768.f * 1.28f); - editWhatever->v(i, j) = LIM01((chromapipb) / (65536.f * 1.28f)); + editWhatever->v (i, j) = LIM01 ((chromapipb) / (65536.f * 1.28f)); } } @@ -5720,35 +5755,35 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu atmp = lold->a[i][j]; - if(autili) { + if (autili) { atmp = acurve[atmp + 32768.0f] - 32768.0f; // curves Lab a } btmp = lold->b[i][j]; - if(butili) { + if (butili) { btmp = bcurve[btmp + 32768.0f] - 32768.0f; // curves Lab b } - if(!bwToning) { //take into account modification of 'a' and 'b' + if (!bwToning) { //take into account modification of 'a' and 'b' #ifdef __SSE2__ - if(!autili && !butili) { + if (!autili && !butili) { // use precalculated values from above HH = HHBuffer[j]; CC = CCBuffer[j]; } else { - CC = sqrt(SQR(atmp) + SQR(btmp)) / 327.68f; - HH = xatan2f(btmp, atmp); + CC = sqrt (SQR (atmp) + SQR (btmp)) / 327.68f; + HH = xatan2f (btmp, atmp); } #else - CC = sqrt(SQR(atmp) + SQR(btmp)) / 327.68f; - HH = xatan2f(btmp, atmp); + CC = sqrt (SQR (atmp) + SQR (btmp)) / 327.68f; + HH = xatan2f (btmp, atmp); #endif // According to mathematical laws we can get the sin and cos of HH by simple operations //float2 sincosval; - if(CC == 0.f) { + if (CC == 0.f) { sincosval.y = 1.f; sincosval.x = 0.f; } else { @@ -5761,10 +5796,10 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu memChprov = Chprov; } // now new values of lold with 'a' and 'b' - if(editPipette) + if (editPipette) if (editID == EUID_Lab_LHCurve || editID == EUID_Lab_CHCurve || editID == EUID_Lab_HHCurve) {//H pipette - float valpar = Color::huelab_to_huehsv2(HH); - editWhatever->v(i, j) = valpar; + float valpar = Color::huelab_to_huehsv2 (HH); + editWhatever->v (i, j) = valpar; } if (lhutili) { // L=f(H) @@ -5772,7 +5807,7 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu float l_r;//Luminance Lab in 0..1 l_r = Lprov1 / 100.f; { - float valparam = float((lhCurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f)); //get l_r=f(H) + float valparam = float ((lhCurve->getVal (Color::huelab_to_huehsv2 (HH)) - 0.5f)); //get l_r=f(H) float valparamneg; valparamneg = valparam; float kcc = (CC / amountchroma); //take Chroma into account...40 "middle low" of chromaticity (arbitrary and simple), one can imagine other algorithme @@ -5780,8 +5815,8 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu valparam *= 2.f * kcc; valparamneg *= kcc; //slightly different for negative - if(valparam > 0.f) { - l_r = (1.f - valparam) * l_r + valparam * (1.f - SQR(((SQR(1.f - min(l_r, 1.0f)))))); + if (valparam > 0.f) { + l_r = (1.f - valparam) * l_r + valparam * (1.f - SQR (((SQR (1.f - min (l_r, 1.0f)))))); } else //for negative { @@ -5792,7 +5827,7 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu Lprov1 = l_r * 100.f; - float Chprov2 = sqrt(SQR(atmp) + SQR(btmp)) / 327.68f; + float Chprov2 = sqrt (SQR (atmp) + SQR (btmp)) / 327.68f; //Gamut control especialy fot negative values slightly different of gamutlchonly bool inRGB; @@ -5805,14 +5840,14 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu float fx = (0.002f * aprov1) + fy; float fz = fy - (0.005f * bprov1); - float x_ = 65535.0f * Color::f2xyz(fx) * Color::D50x; - float z_ = 65535.0f * Color::f2xyz(fz) * Color::D50z; + float x_ = 65535.0f * Color::f2xyz (fx) * Color::D50x; + float z_ = 65535.0f * Color::f2xyz (fz) * Color::D50z; float y_ = (Lprov1 > Color::epskap) ? 65535.0 * fy * fy * fy : 65535.0 * Lprov1 / Color::kappa; float R, G, B; - Color::xyz2rgb(x_, y_, z_, R, G, B, wip); + Color::xyz2rgb (x_, y_, z_, R, G, B, wip); if (R < 0.0f || G < 0.0f || B < 0.0f) { - if(Lprov1 < 0.1f) { + if (Lprov1 < 0.1f) { Lprov1 = 0.1f; } @@ -5834,8 +5869,8 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu // calculate C=f(H) if (chutili) { - double hr = Color::huelab_to_huehsv2(HH); - float chparam = float((chCurve->getVal(hr) - 0.5f) * 2.0f); //get C=f(H) + double hr = Color::huelab_to_huehsv2 (HH); + float chparam = float ((chCurve->getVal (hr) - 0.5f) * 2.0f); //get C=f(H) float chromaChfactor = 1.0f + chparam; atmp *= chromaChfactor;//apply C=f(H) btmp *= chromaChfactor; @@ -5843,15 +5878,15 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu if (hhutili) { // H=f(H) //hue Lab in -PI +PI - float valparam = float((hhCurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f) * 1.7f) + HH; //get H=f(H) 1.7 optimisation ! + float valparam = float ((hhCurve->getVal (Color::huelab_to_huehsv2 (HH)) - 0.5f) * 1.7f) + HH; //get H=f(H) 1.7 optimisation ! HH = valparam; - sincosval = xsincosf(HH); + sincosval = xsincosf (HH); } - if(!bwToning) { + if (!bwToning) { float factorskin, factorsat, factorskinext; - if(chromapro > 1.f) { + if (chromapro > 1.f) { float scale = scaleConst;//reduction in normal zone float scaleext = 1.f;//reduction in transition zone Color::scalered ( rstprotection, chromapro, 0.0, HH, protect_redh, scale, scaleext);//1.0 @@ -5870,11 +5905,11 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu if (Lprov1 < 25.f) { dred = 40.f; - } else if(Lprov1 < 30.f) { + } else if (Lprov1 < 30.f) { dred = 3.f * Lprov1 - 35.f; - } else if(Lprov1 < 70.f) { + } else if (Lprov1 < 70.f) { dred = 55.f; - } else if(Lprov1 < 75.f) { + } else if (Lprov1 < 75.f) { dred = -3.f * Lprov1 + 265.f; } else { dred = 40.f; @@ -5888,7 +5923,7 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu btmp *= factorsat; if (editPipette && editID == EUID_Lab_CLCurve) { - editWhatever->v(i, j) = LIM01(LL / 100.f); // Lab C=f(L) pipette + editWhatever->v (i, j) = LIM01 (LL / 100.f); // Lab C=f(L) pipette } if (clut) { // begin C=f(L) @@ -5901,31 +5936,31 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu float deltaHH;//HH value transition for C curve protect_redcur = curf * protectRed; //default=60 chroma: one can put more or less if necessary...in 'option' 40...160==> curf =because curve is more progressive - if(protect_redcur < 20.0f) { + if (protect_redcur < 20.0f) { protect_redcur = 20.0; // avoid too low value } - if(protect_redcur > 180.0f) { + if (protect_redcur > 180.0f) { protect_redcur = 180.0; // avoid too high value } - protect_redhcur = curf * float(protectRedH); //default=0.4 rad : one can put more or less if necessary...in 'option' 0.2 ..1.0 ==> curf =because curve is more progressive + protect_redhcur = curf * float (protectRedH); //default=0.4 rad : one can put more or less if necessary...in 'option' 0.2 ..1.0 ==> curf =because curve is more progressive - if(protect_redhcur < 0.1f) { + if (protect_redhcur < 0.1f) { protect_redhcur = 0.1f; //avoid divide by 0 and negatives values } - if(protect_redhcur > 1.0f) { + if (protect_redhcur > 1.0f) { protect_redhcur = 1.0f; //avoid too big values } deltaHH = protect_redhcur; //transition hue - if(chromaCfactor > 0.0) { + if (chromaCfactor > 0.0) { Color::scalered ( rstprotection, chromaCfactor, 0.0, HH, deltaHH, scale, scaleext); //1.0 } - if(chromaCfactor > 1.0) { + if (chromaCfactor > 1.0) { float interm = (chromaCfactor - 1.0f) * 100.0f; factorskin = 1.0f + (interm * scale) / 100.0f; factorskinext = 1.0f + (interm * scaleext) / 100.0f; @@ -5947,13 +5982,13 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu // I have placed C=f(C) after all C treatments to assure maximum amplitude of "C" if (editPipette && editID == EUID_Lab_CCurve) { - float chromapip = sqrt(SQR(atmp) + SQR(btmp) + 0.001f); - editWhatever->v(i, j) = LIM01((chromapip) / (48000.f)); + float chromapip = sqrt (SQR (atmp) + SQR (btmp) + 0.001f); + editWhatever->v (i, j) = LIM01 ((chromapip) / (48000.f)); }//Lab C=f(C) pipette if (ccut) { float factorskin, factorsat, factor, factorskinext; - float chroma = sqrt(SQR(atmp) + SQR(btmp) + 0.001f); + float chroma = sqrt (SQR (atmp) + SQR (btmp) + 0.001f); float chromaCfactor = (satcurve[chroma * adjustr]) / (chroma * adjustr); //apply C=f(C) float curf = 0.7f; //empirical coeff because curve is more progressive float scale = 100.0f / 100.1f; //reduction in normal zone for curve CC @@ -5962,31 +5997,31 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu float deltaHH;//HH value transition for CC curve protect_redcur = curf * protectRed; //default=60 chroma: one can put more or less if necessary...in 'option' 40...160==> curf =because curve is more progressive - if(protect_redcur < 20.0f) { + if (protect_redcur < 20.0f) { protect_redcur = 20.0; // avoid too low value } - if(protect_redcur > 180.0f) { + if (protect_redcur > 180.0f) { protect_redcur = 180.0; // avoid too high value } - protect_redhcur = curf * float(protectRedH); //default=0.4 rad : one can put more or less if necessary...in 'option' 0.2 ..1.0 ==> curf =because curve is more progressive + protect_redhcur = curf * float (protectRedH); //default=0.4 rad : one can put more or less if necessary...in 'option' 0.2 ..1.0 ==> curf =because curve is more progressive - if(protect_redhcur < 0.1f) { + if (protect_redhcur < 0.1f) { protect_redhcur = 0.1f; //avoid divide by 0 and negatives values } - if(protect_redhcur > 1.0f) { + if (protect_redhcur > 1.0f) { protect_redhcur = 1.0f; //avoid too big values } deltaHH = protect_redhcur; //transition hue - if(chromaCfactor > 0.0) { + if (chromaCfactor > 0.0) { Color::scalered ( rstprotection, chromaCfactor, 0.0, HH, deltaHH, scale, scaleext); //1.0 } - if(chromaCfactor > 1.0) { + if (chromaCfactor > 1.0) { float interm = (chromaCfactor - 1.0f) * 100.0f; factorskin = 1.0f + (interm * scale) / 100.0f; factorskinext = 1.0f + (interm * scaleext) / 100.0f; @@ -6009,14 +6044,14 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu // end chroma C=f(C) //update histogram C - if(pW != 1) { //only with improccoordinator - int posp = (int)sqrt(atmp * atmp + btmp * btmp); + if (pW != 1) { //only with improccoordinator + int posp = (int)sqrt (atmp * atmp + btmp * btmp); hist16Clad[posp]++; } if (editPipette && editID == EUID_Lab_LCCurve) { - float chromapiplc = sqrt(SQR(atmp) + SQR(btmp) + 0.001f); - editWhatever->v(i, j) = LIM01((chromapiplc) / (48000.f)); + float chromapiplc = sqrt (SQR (atmp) + SQR (btmp) + 0.001f); + editWhatever->v (i, j) = LIM01 ((chromapiplc) / (48000.f)); }//Lab L=f(C) pipette @@ -6034,43 +6069,43 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu float zz = 0.0f; float yy = 0.0f; - if(Chprov1 < chrmin) { - yy = SQR(Chprov1 / chrmin) * xx; + if (Chprov1 < chrmin) { + yy = SQR (Chprov1 / chrmin) * xx; } else { yy = xx; //avoid artifact for low C } - if(!LCredsk) { + if (!LCredsk) { skbeg = -3.1415; skend = 3.14159; skdeltaHH = 0.001f; } - if(HH > skbeg && HH < skend ) { + if (HH > skbeg && HH < skend ) { zz = yy; - } else if(HH > skbeg - skdeltaHH && HH <= skbeg) { //transition + } else if (HH > skbeg - skdeltaHH && HH <= skbeg) { //transition aa = yy / skdeltaHH; bb = -aa * (skbeg - skdeltaHH); zz = aa * HH + bb; - } else if(HH >= skend && HH < skend + skdeltaHH) { //transition + } else if (HH >= skend && HH < skend + skdeltaHH) { //transition aa = -yy / skdeltaHH; bb = -aa * (skend + skdeltaHH); zz = aa * HH + bb; } - float chroma = sqrt(SQR(atmp) + SQR(btmp) + 0.001f); + float chroma = sqrt (SQR (atmp) + SQR (btmp) + 0.001f); float Lc = (lhskcurve[chroma * adjustr]) / (chroma * adjustr); //apply L=f(C) Lc = (Lc - 1.0f) * zz + 1.0f; //reduct action Lprov1 *= Lc; //adjust luminance } //update histo LC - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator int posl = Lprov1 * 327.68f; hist16Llad[posl]++; } - Chprov1 = sqrt(SQR(atmp) + SQR(btmp)) / 327.68f; + Chprov1 = sqrt (SQR (atmp) + SQR (btmp)) / 327.68f; // labCurve.bwtoning option allows to decouple modulation of a & b curves by saturation // with bwtoning enabled the net effect of a & b curves is visible @@ -6081,17 +6116,17 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu if (avoidColorShift) { //gamutmap Lch ==> preserve Hue,but a little slower than gamutbdy for high values...and little faster for low values - if(gamutLch) { + if (gamutLch) { float R, G, B; #ifdef _DEBUG bool neg = false; bool more_rgb = false; //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, sincosval, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f, neg, more_rgb); + Color::gamutLchonly (HH, sincosval, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f, neg, more_rgb); #else //gamut control : Lab values are in gamut - Color::gamutLchonly(HH, sincosval, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f); + Color::gamutLchonly (HH, sincosval, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f); #endif lnew->L[i][j] = Lprov1 * 327.68f; // float2 sincosval = xsincosf(HH); @@ -6101,9 +6136,9 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu //use gamutbdy //Luv limiter float Y, u, v; - Color::Lab2Yuv(lnew->L[i][j], atmp, btmp, Y, u, v); + Color::Lab2Yuv (lnew->L[i][j], atmp, btmp, Y, u, v); //Yuv2Lab includes gamut restriction map - Color::Yuv2Lab(Y, u, v, lnew->L[i][j], lnew->a[i][j], lnew->b[i][j], wp); + Color::Yuv2Lab (Y, u, v, lnew->L[i][j], lnew->a[i][j], lnew->b[i][j], wp); } if (utili || autili || butili || ccut || clut || cclutili || chutili || lhutili || hhutili || clcutili || chromaticity) { @@ -6111,16 +6146,16 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu float correctlum = 0.f; Lprov1 = lnew->L[i][j] / 327.68f; - Chprov = sqrt(SQR(lnew->a[i][j]) + SQR(lnew->b[i][j])) / 327.68f; + Chprov = sqrt (SQR (lnew->a[i][j]) + SQR (lnew->b[i][j])) / 327.68f; #ifdef _DEBUG - Color::AllMunsellLch(/*lumaMuns*/true, Lprov1, LL, HH, Chprov, memChprov, correctionHue, correctlum, MunsDebugInfo); + Color::AllMunsellLch (/*lumaMuns*/true, Lprov1, LL, HH, Chprov, memChprov, correctionHue, correctlum, MunsDebugInfo); #else - Color::AllMunsellLch(/*lumaMuns*/true, Lprov1, LL, HH, Chprov, memChprov, correctionHue, correctlum); + Color::AllMunsellLch (/*lumaMuns*/true, Lprov1, LL, HH, Chprov, memChprov, correctionHue, correctlum); #endif - if(correctionHue != 0.f || correctlum != 0.f) { - if(fabs(correctionHue) < 0.015f) { + if (correctionHue != 0.f || correctlum != 0.f) { + if (fabs (correctionHue) < 0.015f) { HH += correctlum; // correct only if correct Munsell chroma very little. } @@ -6130,7 +6165,7 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu else if(fabs(correctionHue) < 0.1f) HH+=0.35f*correctlum; else if(fabs(correctionHue) < 0.015f) HH+=correctlum; // correct only if correct Munsell chroma very little. */ - sincosval = xsincosf(HH + correctionHue); + sincosval = xsincosf (HH + correctionHue); } lnew->a[i][j] = 327.68f * Chprov * sincosval.y; // apply Munsell @@ -6139,7 +6174,7 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu } else { // if(Lprov1 > maxlp) maxlp=Lprov1; // if(Lprov1 < minlp) minlp=Lprov1; - if(!bwToning) { + if (!bwToning) { lnew->L[i][j] = Lprov1 * 327.68f; // float2 sincosval = xsincosf(HH); lnew->a[i][j] = 327.68f * Chprov1 * sincosval.y; @@ -6154,20 +6189,20 @@ SSEFUNCTION void ImProcFunctions::chromiLuminanceCurve (PipetteBuffer *pipetteBu } } // end of parallelization - if(pW != 1) { //only with improccoordinator + if (pW != 1) { //only with improccoordinator //update histogram C with data chromaticity and not with CC curve - hist16Clad.compressTo(histCCurve); + hist16Clad.compressTo (histCCurve); //update histogram L with data luminance - hist16Llad.compressTo(histLCurve); + hist16Llad.compressTo (histLCurve); } #ifdef _DEBUG if (settings->verbose) { t2e.set(); - printf("Color::AllMunsellLch (correction performed in %d usec):\n", t2e.etime(t1e)); - printf(" Munsell chrominance: MaxBP=%1.2frad MaxRY=%1.2frad MaxGY=%1.2frad MaxRP=%1.2frad dep=%u\n", MunsDebugInfo->maxdhue[0], MunsDebugInfo->maxdhue[1], MunsDebugInfo->maxdhue[2], MunsDebugInfo->maxdhue[3], MunsDebugInfo->depass); - printf(" Munsell luminance : MaxBP=%1.2frad MaxRY=%1.2frad MaxGY=%1.2frad MaxRP=%1.2frad dep=%u\n", MunsDebugInfo->maxdhuelum[0], MunsDebugInfo->maxdhuelum[1], MunsDebugInfo->maxdhuelum[2], MunsDebugInfo->maxdhuelum[3], MunsDebugInfo->depassLum); + printf ("Color::AllMunsellLch (correction performed in %d usec):\n", t2e.etime (t1e)); + printf (" Munsell chrominance: MaxBP=%1.2frad MaxRY=%1.2frad MaxGY=%1.2frad MaxRP=%1.2frad dep=%u\n", MunsDebugInfo->maxdhue[0], MunsDebugInfo->maxdhue[1], MunsDebugInfo->maxdhue[2], MunsDebugInfo->maxdhue[3], MunsDebugInfo->depass); + printf (" Munsell luminance : MaxBP=%1.2frad MaxRY=%1.2frad MaxGY=%1.2frad MaxRP=%1.2frad dep=%u\n", MunsDebugInfo->maxdhuelum[0], MunsDebugInfo->maxdhuelum[1], MunsDebugInfo->maxdhuelum[2], MunsDebugInfo->maxdhuelum[3], MunsDebugInfo->depassLum); } delete MunsDebugInfo; @@ -6298,69 +6333,69 @@ void ImProcFunctions::defringe (LabImage* lab) if (params->defringe.enabled && lab->W >= 8 && lab->H >= 8) { - PF_correct_RT(lab, lab, params->defringe.radius, params->defringe.threshold); + PF_correct_RT (lab, lab, params->defringe.radius, params->defringe.threshold); } } void ImProcFunctions::defringecam (CieImage* ncie) { if (params->defringe.enabled && ncie->W >= 8 && ncie->H >= 8) { - PF_correct_RTcam(ncie, ncie, params->defringe.radius, params->defringe.threshold); + PF_correct_RTcam (ncie, ncie, params->defringe.radius, params->defringe.threshold); } } -void ImProcFunctions::badpixcam(CieImage* ncie, double rad, int thr, int mode, float b_l, float t_l, float t_r, float b_r, float skinprot, float chrom, int hotbad) +void ImProcFunctions::badpixcam (CieImage* ncie, double rad, int thr, int mode, float b_l, float t_l, float t_r, float b_r, float skinprot, float chrom, int hotbad) { - if(ncie->W >= 8 && ncie->H >= 8) { - Badpixelscam(ncie, ncie, rad, thr, mode, b_l, t_l, t_r, b_r, skinprot, chrom, hotbad); + if (ncie->W >= 8 && ncie->H >= 8) { + Badpixelscam (ncie, ncie, rad, thr, mode, b_l, t_l, t_r, b_r, skinprot, chrom, hotbad); } } -void ImProcFunctions::badpixlab(LabImage* lab, double rad, int thr, int mode, float b_l, float t_l, float t_r, float b_r, float skinprot, float chrom) +void ImProcFunctions::badpixlab (LabImage* lab, double rad, int thr, int mode, float b_l, float t_l, float t_r, float b_r, float skinprot, float chrom) { - if(lab->W >= 8 && lab->H >= 8) { - BadpixelsLab(lab, lab, rad, thr, mode, b_l, t_l, t_r, b_r, skinprot, chrom); + if (lab->W >= 8 && lab->H >= 8) { + BadpixelsLab (lab, lab, rad, thr, mode, b_l, t_l, t_r, b_r, skinprot, chrom); } } void ImProcFunctions::dirpyrequalizer (LabImage* lab, int scale) { if (params->dirpyrequalizer.enabled && lab->W >= 8 && lab->H >= 8) { - float b_l = static_cast(params->dirpyrequalizer.hueskin.value[0]) / 100.0f; - float t_l = static_cast(params->dirpyrequalizer.hueskin.value[1]) / 100.0f; - float b_r = static_cast(params->dirpyrequalizer.hueskin.value[2]) / 100.0f; - float t_r = static_cast(params->dirpyrequalizer.hueskin.value[3]) / 100.0f; + float b_l = static_cast (params->dirpyrequalizer.hueskin.value[0]) / 100.0f; + float t_l = static_cast (params->dirpyrequalizer.hueskin.value[1]) / 100.0f; + float b_r = static_cast (params->dirpyrequalizer.hueskin.value[2]) / 100.0f; + float t_r = static_cast (params->dirpyrequalizer.hueskin.value[3]) / 100.0f; int choice = 0; //I have not disabled this statement in case of ! always 0 // if (params->dirpyrequalizer.algo=="FI") choice=0; // else if(params->dirpyrequalizer.algo=="LA") choice=1; float artifact = (float) settings->artifact_cbdl; - if(artifact > 6.f) { + if (artifact > 6.f) { artifact = 6.f; } - if(artifact < 0.f) { + if (artifact < 0.f) { artifact = 1.f; } float chrom = 50.f; - if(params->dirpyrequalizer.gamutlab) { + if (params->dirpyrequalizer.gamutlab) { ImProcFunctions::badpixlab (lab, artifact, 5, 3, b_l, t_l, t_r, b_r, params->dirpyrequalizer.skinprotect, chrom); //for artifacts } //dirpyrLab_equalizer(lab, lab, params->dirpyrequalizer.mult); - dirpyr_equalizer(lab->L, lab->L, lab->W, lab->H, lab->a, lab->b, lab->a, lab->b, params->dirpyrequalizer.mult, params->dirpyrequalizer.threshold, params->dirpyrequalizer.skinprotect, params->dirpyrequalizer.gamutlab, b_l, t_l, t_r, b_r, choice, scale); + dirpyr_equalizer (lab->L, lab->L, lab->W, lab->H, lab->a, lab->b, lab->a, lab->b, params->dirpyrequalizer.mult, params->dirpyrequalizer.threshold, params->dirpyrequalizer.skinprotect, params->dirpyrequalizer.gamutlab, b_l, t_l, t_r, b_r, choice, scale); } } -void ImProcFunctions::EPDToneMapCIE(CieImage *ncie, float a_w, float c_, float w_h, int Wid, int Hei, int begh, int endh, float minQ, float maxQ, unsigned int Iterates, int skip) +void ImProcFunctions::EPDToneMapCIE (CieImage *ncie, float a_w, float c_, float w_h, int Wid, int Hei, int begh, int endh, float minQ, float maxQ, unsigned int Iterates, int skip) { - if(!params->epd.enabled) { + if (!params->epd.enabled) { return; } - if(params->wavelet.enabled && params->wavelet.tmrs != 0) { + if (params->wavelet.enabled && params->wavelet.tmrs != 0) { return; } @@ -6373,14 +6408,14 @@ void ImProcFunctions::EPDToneMapCIE(CieImage *ncie, float a_w, float c_, float w float *Qpr = ncie->Q_p[0]; if (settings->verbose) { - printf("minQ=%f maxQ=%f Qpro=%f\n", minQ, maxQ, Qpro); + printf ("minQ=%f maxQ=%f Qpro=%f\n", minQ, maxQ, Qpro); } - if(maxQ > Qpro) { + if (maxQ > Qpro) { Qpro = maxQ; } - EdgePreservingDecomposition epd(Wid, Hei); + EdgePreservingDecomposition epd (Wid, Hei); #pragma omp parallel for @@ -6389,24 +6424,24 @@ void ImProcFunctions::EPDToneMapCIE(CieImage *ncie, float a_w, float c_, float w ncie->Q_p[i][j] = gamm * ncie->Q_p[i][j] / (Qpro); } - float Compression = expf(-stren); //This modification turns numbers symmetric around 0 into exponents. + float Compression = expf (-stren); //This modification turns numbers symmetric around 0 into exponents. float DetailBoost = stren; - if(stren < 0.0f) { + if (stren < 0.0f) { DetailBoost = 0.0f; //Go with effect of exponent only if uncompressing. } //Auto select number of iterates. Note that p->EdgeStopping = 0 makes a Gaussian blur. - if(Iterates == 0) { - Iterates = (unsigned int)(edgest * 15.0); + if (Iterates == 0) { + Iterates = (unsigned int) (edgest * 15.0); } //Jacques Desmis : always Iterates=5 for compatibility images between preview and output - epd.CompressDynamicRange(Qpr, (float)sca / skip, (float)edgest, Compression, DetailBoost, Iterates, rew, Qpr); + epd.CompressDynamicRange (Qpr, (float)sca / skip, (float)edgest, Compression, DetailBoost, Iterates, rew, Qpr); //Restore past range, also desaturate a bit per Mantiuk's Color correction for tone mapping. - float s = (1.0f + 38.7889f) * powf(Compression, 1.5856f) / (1.0f + 38.7889f * powf(Compression, 1.5856f)); + float s = (1.0f + 38.7889f) * powf (Compression, 1.5856f) / (1.0f + 38.7889f * powf (Compression, 1.5856f)); #ifndef _DEBUG #pragma omp parallel for schedule(dynamic,10) #endif @@ -6459,18 +6494,18 @@ void ImProcFunctions::EPDToneMapCIE(CieImage *ncie, float a_w, float c_, float w //Map tones by way of edge preserving decomposition. Is this the right way to include source? //#include "EdgePreservingDecomposition.cc" -void ImProcFunctions::EPDToneMap(LabImage *lab, unsigned int Iterates, int skip) +void ImProcFunctions::EPDToneMap (LabImage *lab, unsigned int Iterates, int skip) { //Hasten access to the parameters. // EPDParams *p = (EPDParams *)(¶ms->epd); //Enabled? Leave now if not. // if(!p->enabled) return; - if(!params->epd.enabled) { + if (!params->epd.enabled) { return; } - if(params->wavelet.enabled && params->wavelet.tmrs != 0) { + if (params->wavelet.enabled && params->wavelet.tmrs != 0) { return; } @@ -6484,7 +6519,7 @@ void ImProcFunctions::EPDToneMap(LabImage *lab, unsigned int Iterates, int skip) float *a = lab->a[0]; float *b = lab->b[0]; size_t N = lab->W * lab->H; - EdgePreservingDecomposition epd(lab->W, lab->H); + EdgePreservingDecomposition epd (lab->W, lab->H); //Due to the taking of logarithms, L must be nonnegative. Further, scale to 0 to 1 using nominal range of L, 0 to 15 bit. float minL = FLT_MAX; @@ -6495,35 +6530,35 @@ void ImProcFunctions::EPDToneMap(LabImage *lab, unsigned int Iterates, int skip) float lmaxL = 0.f; #pragma omp for - for(size_t i = 0; i < N; i++) { - if(L[i] < lminL) { + for (size_t i = 0; i < N; i++) { + if (L[i] < lminL) { lminL = L[i]; } - if(L[i] > lmaxL) { + if (L[i] > lmaxL) { lmaxL = L[i]; } } #pragma omp critical { - if(lminL < minL) { + if (lminL < minL) { minL = lminL; } - if(lmaxL > maxL) { + if (lmaxL > maxL) { maxL = lmaxL; } } } - if(minL > 0.0f) { + if (minL > 0.0f) { minL = 0.0f; //Disable the shift if there are no negative numbers. I wish there were just no negative numbers to begin with. } #pragma omp parallel for - for(size_t i = 0; i < N; ++i) + for (size_t i = 0; i < N; ++i) //{L[i] = (L[i] - minL)/32767.0f; { L[i] = (L[i] - minL) / maxL; @@ -6531,16 +6566,16 @@ void ImProcFunctions::EPDToneMap(LabImage *lab, unsigned int Iterates, int skip) } //Some interpretations. - float Compression = expf(-stren); //This modification turns numbers symmetric around 0 into exponents. + float Compression = expf (-stren); //This modification turns numbers symmetric around 0 into exponents. float DetailBoost = stren; - if(stren < 0.0f) { + if (stren < 0.0f) { DetailBoost = 0.0f; //Go with effect of exponent only if uncompressing. } //Auto select number of iterates. Note that p->EdgeStopping = 0 makes a Gaussian blur. - if(Iterates == 0) { - Iterates = (unsigned int)(edgest * 15.0f); + if (Iterates == 0) { + Iterates = (unsigned int) (edgest * 15.0f); } /* Debuggery. Saves L for toying with outside of RT. @@ -6550,15 +6585,15 @@ void ImProcFunctions::EPDToneMap(LabImage *lab, unsigned int Iterates, int skip) fwrite(L, N, sizeof(float), f); fclose(f);*/ - epd.CompressDynamicRange(L, sca / float(skip), edgest, Compression, DetailBoost, Iterates, rew, L); + epd.CompressDynamicRange (L, sca / float (skip), edgest, Compression, DetailBoost, Iterates, rew, L); //Restore past range, also desaturate a bit per Mantiuk's Color correction for tone mapping. - float s = (1.0f + 38.7889f) * powf(Compression, 1.5856f) / (1.0f + 38.7889f * powf(Compression, 1.5856f)); + float s = (1.0f + 38.7889f) * powf (Compression, 1.5856f) / (1.0f + 38.7889f * powf (Compression, 1.5856f)); #ifdef _OPENMP #pragma omp parallel for // removed schedule(dynamic,10) #endif - for(size_t ii = 0; ii < N; ++ii) { + for (size_t ii = 0; ii < N; ++ii) { a[ii] *= s; b[ii] *= s; L[ii] = L[ii] * maxL * (1.f / gamm) + minL; @@ -6579,7 +6614,7 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double float ave = 0.f, hidev = 0.f, lodev = 0.f; //find average luminance - histogram.getSumAndAverage(sum, ave); + histogram.getSumAndAverage (sum, ave); //find median of luminance int median = 0, count = histogram[0]; @@ -6606,18 +6641,18 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double int i = 0; - for (; i < min((int)ave, imax); i++) { + for (; i < min ((int)ave, imax); i++) { if (count < 8) { octile[count] += histogram[i]; if (octile[count] > sum / 8.f || (count == 7 && octile[count] > sum / 16.f)) { - octile[count] = xlog(1. + (float)i) / log(2.f); + octile[count] = xlog (1. + (float)i) / log (2.f); count++;// = min(count+1,7); } } //lodev += SQR(ave-i)*histogram[i]; - lodev += (xlog(ave + 1.f) - xlog((float)i + 1.)) * histogram[i]; + lodev += (xlog (ave + 1.f) - xlog ((float)i + 1.)) * histogram[i]; losum += histogram[i]; } @@ -6626,13 +6661,13 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double octile[count] += histogram[i]; if (octile[count] > sum / 8.f || (count == 7 && octile[count] > sum / 16.f)) { - octile[count] = xlog(1. + (float)i) / log(2.f); + octile[count] = xlog (1. + (float)i) / log (2.f); count++;// = min(count+1,7); } } //hidev += SQR(i-ave)*histogram[i]; - hidev += (xlog((float)i + 1.) - xlog(ave + 1.f)) * histogram[i]; + hidev += (xlog ((float)i + 1.) - xlog (ave + 1.f)) * histogram[i]; hisum += histogram[i]; } @@ -6650,12 +6685,12 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double // lodev = (lodev / (log(2.f) * losum)); // hidev = (hidev / (log(2.f) * hisum)); - if (octile[6] > log1p((float)imax) / log2(2.f)) { //if very overxposed image + if (octile[6] > log1p ((float)imax) / log2 (2.f)) { //if very overxposed image octile[6] = 1.5f * octile[5] - 0.5f * octile[4]; overex = 2; } - if (octile[7] > log1p((float)imax) / log2(2.f)) { //if overexposed + if (octile[7] > log1p ((float)imax) / log2 (2.f)) { //if overexposed octile[7] = 1.5f * octile[6] - 0.5f * octile[5]; overex = 1; } @@ -6668,7 +6703,7 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double oct7 = octile[7]; - for(int i = 1; i < 8; i++) { + for (int i = 1; i < 8; i++) { if (octile[i] == 0.0f) { octile[i] = octile[i - 1]; } @@ -6677,7 +6712,7 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double // compute weighted average separation of octiles // for future use in contrast setting for (int i = 1; i < 6; i++) { - ospread += (octile[i + 1] - octile[i]) / max(0.5f, (i > 2 ? (octile[i + 1] - octile[3]) : (octile[3] - octile[i]))); + ospread += (octile[i + 1] - octile[i]) / max (0.5f, (i > 2 ? (octile[i + 1] - octile[3]) : (octile[3] - octile[i]))); } ospread /= 5.f; @@ -6703,7 +6738,7 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double } //compute clipped white point - unsigned int clippable = (int)(sum * clip / 100.f ); + unsigned int clippable = (int) (sum * clip / 100.f ); clipped = 0; int whiteclip = (imax) - 1; @@ -6737,24 +6772,24 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double //sets the mean or median at middle gray, and the amount that sets the estimated top //of the histogram at or near clipping. //float expcomp1 = (log(/*(median/ave)*//*(hidev/lodev)*/midgray*scale/(ave-shc+midgray*shc))+log((hidev/lodev)))/log(2.f); - float expcomp1 = (log(/*(median/ave)*//*(hidev/lodev)*/midgray * scale / (ave - shc + midgray * shc))) / log(2.f); + float expcomp1 = (log (/*(median/ave)*//*(hidev/lodev)*/midgray * scale / (ave - shc + midgray * shc))) / log (2.f); float expcomp2; - if(overex == 0) { // image is not overexposed - expcomp2 = 0.5f * ( (15.5f - histcompr - (2.f * oct7 - oct6)) + log(scale / rawmax) / log(2.f) ); + if (overex == 0) { // image is not overexposed + expcomp2 = 0.5f * ( (15.5f - histcompr - (2.f * oct7 - oct6)) + log (scale / rawmax) / log (2.f) ); } else { - expcomp2 = 0.5f * ( (15.5f - histcompr - (2.f * octile[7] - octile[6])) + log(scale / rawmax) / log(2.f) ); + expcomp2 = 0.5f * ( (15.5f - histcompr - (2.f * octile[7] - octile[6])) + log (scale / rawmax) / log (2.f) ); } - if(fabs(expcomp1) - fabs(expcomp2) > 1.f) { //for great expcomp - expcomp = (expcomp1 * fabs(expcomp2) + expcomp2 * fabs(expcomp1)) / (fabs(expcomp1) + fabs(expcomp2)); + if (fabs (expcomp1) - fabs (expcomp2) > 1.f) { //for great expcomp + expcomp = (expcomp1 * fabs (expcomp2) + expcomp2 * fabs (expcomp1)) / (fabs (expcomp1) + fabs (expcomp2)); } else { expcomp = 0.5 * (double)expcomp1 + 0.5 * (double) expcomp2; //for small expcomp } - float gain = exp((float)expcomp * log(2.f)); + float gain = exp ((float)expcomp * log (2.f)); - float corr = sqrt(gain * scale / rawmax); + float corr = sqrt (gain * scale / rawmax); black = (int) shc * corr; @@ -6763,12 +6798,12 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double //this is a series approximation of the actual formula for comp, //which is a transcendental equation float comp = (gain * ((float)whiteclip) / scale - 1.f) * 2.3f; // 2.3 instead of 2 to increase slightly comp - hlcompr = (int)(100.*comp / (max(0.0, expcomp) + 1.0)); - hlcompr = max(0, min(100, hlcompr)); + hlcompr = (int) (100.*comp / (max (0.0, expcomp) + 1.0)); + hlcompr = max (0, min (100, hlcompr)); //now find brightness if gain didn't bring ave to midgray using //the envelope of the actual 'control cage' brightness curve for simplicity - float midtmp = gain * sqrt(median * ave) / scale; + float midtmp = gain * sqrt (median * ave) / scale; if (midtmp < 0.1f) { bright = (midgray - midtmp) * 15.0 / (midtmp); @@ -6776,13 +6811,13 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double bright = (midgray - midtmp) * 15.0 / (0.10833 - 0.0833 * midtmp); } - bright = 0.25 */*(median/ave)*(hidev/lodev)*/max(0, bright); + bright = 0.25 */*(median/ave)*(hidev/lodev)*/max (0, bright); //compute contrast that spreads the average spacing of octiles contr = (int) 50.0f * (1.1f - ospread); - contr = max(0, min(100, contr)); + contr = max (0, min (100, contr)); //take gamma into account - double whiteclipg = (int)(CurveFactory::gamma2 (whiteclip * corr / 65536.0) * 65536.0); + double whiteclipg = (int) (CurveFactory::gamma2 (whiteclip * corr / 65536.0) * 65536.0); float gavg = 0.; @@ -6804,10 +6839,10 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double } } - whiteclipg = CurveFactory::igamma2 ((float)(whiteclipg / 65535.0)) * 65535.0; //need to inverse gamma transform to get correct exposure compensation parameter + whiteclipg = CurveFactory::igamma2 ((float) (whiteclipg / 65535.0)) * 65535.0; //need to inverse gamma transform to get correct exposure compensation parameter //corection with gamma - black = (int)((65535 * black) / whiteclipg); + black = (int) ((65535 * black) / whiteclipg); //expcomp = log(65535.0 / (whiteclipg)) / log(2.0); //diagnostics @@ -6863,7 +6898,7 @@ void ImProcFunctions::getAutoExp (const LUTu &histogram, int histcompr, double expcomp = 12.0; } - bright = max(-100, min(bright, 100)); + bright = max (-100, min (bright, 100)); } @@ -6926,7 +6961,7 @@ double ImProcFunctions::getAutoDistor (const Glib::ustring &fname, int thumb_si double dist_amount; int dist_result = calcDistortion (thumbGray, rawGray, width, h_thumb, 1, dist_amount); - if(dist_result == -1) { // not enough features found, try increasing max. number of features by factor 4 + if (dist_result == -1) { // not enough features found, try increasing max. number of features by factor 4 calcDistortion (thumbGray, rawGray, width, h_thumb, 4, dist_amount); } @@ -6940,13 +6975,13 @@ double ImProcFunctions::getAutoDistor (const Glib::ustring &fname, int thumb_si } } -void ImProcFunctions::rgb2lab(const Imagefloat &src, LabImage &dst, const Glib::ustring &workingSpace) +void ImProcFunctions::rgb2lab (const Imagefloat &src, LabImage &dst, const Glib::ustring &workingSpace) { - TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix( workingSpace ); + TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix ( workingSpace ); const float wp[3][3] = { - {static_cast(wprof[0][0]), static_cast(wprof[0][1]), static_cast(wprof[0][2])}, - {static_cast(wprof[1][0]), static_cast(wprof[1][1]), static_cast(wprof[1][2])}, - {static_cast(wprof[2][0]), static_cast(wprof[2][1]), static_cast(wprof[2][2])} + {static_cast (wprof[0][0]), static_cast (wprof[0][1]), static_cast (wprof[0][2])}, + {static_cast (wprof[1][0]), static_cast (wprof[1][1]), static_cast (wprof[1][2])}, + {static_cast (wprof[2][0]), static_cast (wprof[2][1]), static_cast (wprof[2][2])} }; const int W = src.getWidth(); @@ -6956,23 +6991,23 @@ void ImProcFunctions::rgb2lab(const Imagefloat &src, LabImage &dst, const Glib:: #pragma omp parallel for schedule(dynamic,16) #endif - for(int i = 0; i < H; i++) { - for(int j = 0; j < W; j++) { + for (int i = 0; i < H; i++) { + for (int j = 0; j < W; j++) { float X, Y, Z; - Color::rgbxyz(src.r(i, j), src.g(i, j), src.b(i, j), X, Y, Z, wp); + Color::rgbxyz (src.r (i, j), src.g (i, j), src.b (i, j), X, Y, Z, wp); //convert Lab - Color::XYZ2Lab(X, Y, Z, dst.L[i][j], dst.a[i][j], dst.b[i][j]); + Color::XYZ2Lab (X, Y, Z, dst.L[i][j], dst.a[i][j], dst.b[i][j]); } } } -SSEFUNCTION void ImProcFunctions::lab2rgb(const LabImage &src, Imagefloat &dst, const Glib::ustring &workingSpace) +SSEFUNCTION void ImProcFunctions::lab2rgb (const LabImage &src, Imagefloat &dst, const Glib::ustring &workingSpace) { - TMatrix wiprof = ICCStore::getInstance()->workingSpaceInverseMatrix( workingSpace ); + TMatrix wiprof = ICCStore::getInstance()->workingSpaceInverseMatrix ( workingSpace ); const float wip[3][3] = { - {static_cast(wiprof[0][0]), static_cast(wiprof[0][1]), static_cast(wiprof[0][2])}, - {static_cast(wiprof[1][0]), static_cast(wiprof[1][1]), static_cast(wiprof[1][2])}, - {static_cast(wiprof[2][0]), static_cast(wiprof[2][1]), static_cast(wiprof[2][2])} + {static_cast (wiprof[0][0]), static_cast (wiprof[0][1]), static_cast (wiprof[0][2])}, + {static_cast (wiprof[1][0]), static_cast (wiprof[1][1]), static_cast (wiprof[1][2])}, + {static_cast (wiprof[2][0]), static_cast (wiprof[2][1]), static_cast (wiprof[2][2])} }; const int W = dst.getWidth(); @@ -6980,9 +7015,9 @@ SSEFUNCTION void ImProcFunctions::lab2rgb(const LabImage &src, Imagefloat &dst, #ifdef __SSE2__ vfloat wipv[3][3]; - for(int i = 0; i < 3; i++) { - for(int j = 0; j < 3; j++) { - wipv[i][j] = F2V(wiprof[i][j]); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + wipv[i][j] = F2V (wiprof[i][j]); } } @@ -6992,26 +7027,26 @@ SSEFUNCTION void ImProcFunctions::lab2rgb(const LabImage &src, Imagefloat &dst, #pragma omp parallel for schedule(dynamic,16) #endif - for(int i = 0; i < H; i++) { + for (int i = 0; i < H; i++) { int j = 0; #ifdef __SSE2__ - for(; j < W - 3; j += 4) { + for (; j < W - 3; j += 4) { vfloat X, Y, Z; vfloat R, G, B; - Color::Lab2XYZ(LVFU(src.L[i][j]), LVFU(src.a[i][j]), LVFU(src.b[i][j]), X, Y, Z); - Color::xyz2rgb(X, Y, Z, R, G, B, wipv); - STVFU(dst.r(i, j), R); - STVFU(dst.g(i, j), G); - STVFU(dst.b(i, j), B); + Color::Lab2XYZ (LVFU (src.L[i][j]), LVFU (src.a[i][j]), LVFU (src.b[i][j]), X, Y, Z); + Color::xyz2rgb (X, Y, Z, R, G, B, wipv); + STVFU (dst.r (i, j), R); + STVFU (dst.g (i, j), G); + STVFU (dst.b (i, j), B); } #endif - for(; j < W; j++) { + for (; j < W; j++) { float X, Y, Z; - Color::Lab2XYZ(src.L[i][j], src.a[i][j], src.b[i][j], X, Y, Z); - Color::xyz2rgb(X, Y, Z, dst.r(i, j), dst.g(i, j), dst.b(i, j), wip); + Color::Lab2XYZ (src.L[i][j], src.a[i][j], src.b[i][j], X, Y, Z); + Color::xyz2rgb (X, Y, Z, dst.r (i, j), dst.g (i, j), dst.b (i, j), wip); } } } diff --git a/rtengine/ipsharpen.cc b/rtengine/ipsharpen.cc index 0fd9eba83..388567f8a 100644 --- a/rtengine/ipsharpen.cc +++ b/rtengine/ipsharpen.cc @@ -23,6 +23,7 @@ #include "rt_math.h" #include "sleef.c" #include "opthelper.h" + using namespace std; namespace rtengine @@ -31,8 +32,6 @@ namespace rtengine #undef ABS #define ABS(a) ((a)<0?-(a):(a)) -#define CLIREF(x) LIM(x,-200000.0f,200000.0f) // avoid overflow : do not act directly on image[] or pix[] - extern const Settings* settings; SSEFUNCTION void ImProcFunctions::dcdamping (float** aI, float** aO, float damping, int W, int H) @@ -561,6 +560,7 @@ void ImProcFunctions::MLsharpen (LabImage* lab) //! MicroContrast is a sharpening method developed by Manuel Llorens and documented here: http://www.rawness.es/sharpening/?lang=en //!
The purpose is maximize clarity of the image without creating halo's. //!
Addition from JD : pyramid + pondered contrast with matrix 5x5 +//!
2017 Ingo Weyrich : reduced processing time //! \param luminance : Luminance channel of image void ImProcFunctions::MLmicrocontrast(float** luminance, int W, int H) { @@ -568,20 +568,12 @@ void ImProcFunctions::MLmicrocontrast(float** luminance, int W, int H) return; } - MyTime t1e, t2e; - t1e.set(); - - int k = params->sharpenMicro.matrix ? 1 : 2; + const int k = params->sharpenMicro.matrix ? 1 : 2; // k=2 matrix 5x5 k=1 matrix 3x3 - int offset, offset2, i, j, col, row, n; - float temp, temp2, temp3, temp4, tempL; - float *LM, v, s, contrast; - int signs[25]; - int width = W, height = H; - float uniform = params->sharpenMicro.uniformity;//between 0 to 100 - int unif; - unif = (int)(uniform / 10.0f); //put unif between 0 to 10 + const int width = W, height = H; + const float uniform = params->sharpenMicro.uniformity; //between 0 to 100 + const int unif = (int)(uniform / 10.0f); //put unif between 0 to 10 float amount = params->sharpenMicro.amount / 1500.0f; //amount 2000.0 quasi no artefacts ==> 1500 = maximum, after artefacts if (amount < 0.000001f) { @@ -594,127 +586,97 @@ void ImProcFunctions::MLmicrocontrast(float** luminance, int W, int H) if (settings->verbose) { printf ("Micro-contrast amount %f\n", amount); - } - - if (settings->verbose) { printf ("Micro-contrast uniformity %i\n", unif); } //modulation uniformity in function of luminance - float L98[11] = {0.001f, 0.0015f, 0.002f, 0.004f, 0.006f, 0.008f, 0.01f, 0.03f, 0.05f, 0.1f, 0.1f}; - float L95[11] = {0.0012f, 0.002f, 0.005f, 0.01f, 0.02f, 0.05f, 0.1f, 0.12f, 0.15f, 0.2f, 0.25f}; - float L92[11] = {0.01f, 0.015f, 0.02f, 0.06f, 0.10f, 0.13f, 0.17f, 0.25f, 0.3f, 0.32f, 0.35f}; - float L90[11] = {0.015f, 0.02f, 0.04f, 0.08f, 0.12f, 0.15f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f}; - float L87[11] = {0.025f, 0.03f, 0.05f, 0.1f, 0.15f, 0.25f, 0.3f, 0.4f, 0.5f, 0.63f, 0.75f}; - float L83[11] = {0.055f, 0.08f, 0.1f, 0.15f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.75f, 0.85f}; - float L80[11] = {0.15f, 0.2f, 0.25f, 0.3f, 0.35f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f}; - float L75[11] = {0.22f, 0.25f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.85f, 0.9f, 0.95f}; - float L70[11] = {0.35f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.97f, 1.0f, 1.0f, 1.0f, 1.0f}; - float L63[11] = {0.55f, 0.6f, 0.7f, 0.8f, 0.85f, 0.9f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; - float L58[11] = {0.75f, 0.77f, 0.8f, 0.9f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; + const float L98[11] = {0.001f, 0.0015f, 0.002f, 0.004f, 0.006f, 0.008f, 0.01f, 0.03f, 0.05f, 0.1f, 0.1f}; + const float L95[11] = {0.0012f, 0.002f, 0.005f, 0.01f, 0.02f, 0.05f, 0.1f, 0.12f, 0.15f, 0.2f, 0.25f}; + const float L92[11] = {0.01f, 0.015f, 0.02f, 0.06f, 0.10f, 0.13f, 0.17f, 0.25f, 0.3f, 0.32f, 0.35f}; + const float L90[11] = {0.015f, 0.02f, 0.04f, 0.08f, 0.12f, 0.15f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f}; + const float L87[11] = {0.025f, 0.03f, 0.05f, 0.1f, 0.15f, 0.25f, 0.3f, 0.4f, 0.5f, 0.63f, 0.75f}; + const float L83[11] = {0.055f, 0.08f, 0.1f, 0.15f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.75f, 0.85f}; + const float L80[11] = {0.15f, 0.2f, 0.25f, 0.3f, 0.35f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f}; + const float L75[11] = {0.22f, 0.25f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.85f, 0.9f, 0.95f}; + const float L70[11] = {0.35f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.97f, 1.0f, 1.0f, 1.0f, 1.0f}; + const float L63[11] = {0.55f, 0.6f, 0.7f, 0.8f, 0.85f, 0.9f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; + const float L58[11] = {0.75f, 0.77f, 0.8f, 0.9f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; //default 5 //modulation contrast - float Cont0[11] = {0.05f, 0.1f, 0.2f, 0.25f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f}; - float Cont1[11] = {0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 0.95f, 1.0f}; - float Cont2[11] = {0.2f, 0.40f, 0.6f, 0.7f, 0.8f, 0.85f, 0.90f, 0.95f, 1.0f, 1.05f, 1.10f}; - float Cont3[11] = {0.5f, 0.6f, 0.7f, 0.8f, 0.85f, 0.9f, 1.0f, 1.0f, 1.05f, 1.10f, 1.20f}; - float Cont4[11] = {0.8f, 0.85f, 0.9f, 0.95f, 1.0f, 1.05f, 1.10f, 1.150f, 1.2f, 1.25f, 1.40f}; - float Cont5[11] = {1.0f, 1.1f, 1.2f, 1.25f, 1.3f, 1.4f, 1.45f, 1.50f, 1.6f, 1.65f, 1.80f}; + const float Cont0[11] = {0.05f, 0.1f, 0.2f, 0.25f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f}; + const float Cont1[11] = {0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 0.95f, 1.0f}; + const float Cont2[11] = {0.2f, 0.40f, 0.6f, 0.7f, 0.8f, 0.85f, 0.90f, 0.95f, 1.0f, 1.05f, 1.10f}; + const float Cont3[11] = {0.5f, 0.6f, 0.7f, 0.8f, 0.85f, 0.9f, 1.0f, 1.0f, 1.05f, 1.10f, 1.20f}; + const float Cont4[11] = {0.8f, 0.85f, 0.9f, 0.95f, 1.0f, 1.05f, 1.10f, 1.150f, 1.2f, 1.25f, 1.40f}; + const float Cont5[11] = {1.0f, 1.1f, 1.2f, 1.25f, 1.3f, 1.4f, 1.45f, 1.50f, 1.6f, 1.65f, 1.80f}; + + const float s = amount; + const float sqrt2 = sqrt(2.0); + const float sqrt1d25 = sqrt(1.25); + float *LM = new float[width * height]; //allocation for Luminance - float chmax = 8.0f; - LM = new float[width * height]; //allocation for Luminance #ifdef _OPENMP - #pragma omp parallel for private(offset, i,j) shared(LM) + #pragma omp parallel +#endif +{ + +#ifdef _OPENMP + #pragma omp for schedule(dynamic,16) #endif - for(j = 0; j < height; j++) - for(i = 0, offset = j * width + i; i < width; i++, offset++) { - LM[offset] = luminance[j][i] / 327.68f; // adjust to 0.100 and to RT variables + for(int j = 0; j < height; j++) + for(int i = 0, offset = j * width + i; i < width; i++, offset++) { + LM[offset] = luminance[j][i] / 327.68f; // adjust to [0;100] and to RT variables } #ifdef _OPENMP - #pragma omp parallel for private(j,i,offset,s,signs,v,n,row,col,offset2,contrast,temp,temp2,tempL,temp4) shared(luminance,LM,amount,chmax,unif,k,L98,L95,L92,L90,L87,L83,L80,L75,L70,L63,L58,Cont0,Cont1,Cont2,Cont3,Cont4,Cont5) + #pragma omp for schedule(dynamic,16) #endif - for(j = k; j < height - k; j++) - for(i = k, offset = j * width + i; i < width - k; i++, offset++) { - s = amount; - v = LM[offset]; - n = 0; + for(int j = k; j < height - k; j++) + for(int i = k, offset = j * width + i; i < width - k; i++, offset++) { + float v = LM[offset]; - for(row = j - k; row <= j + k; row++) - for(col = i - k, offset2 = row * width + col; col <= i + k; col++, offset2++) { - signs[n] = 0; + float contrast; + if (k == 1) { + contrast = sqrtf(SQR(LM[offset + 1] - LM[offset - 1]) + SQR(LM[offset + width] - LM[offset - width])) * 0.125f; //for 3x3 + } else /* if (k==2) */ contrast = sqrtf(SQR(LM[offset + 1] - LM[offset - 1]) + SQR(LM[offset + width] - LM[offset - width]) + + SQR(LM[offset + 2] - LM[offset - 2]) + SQR(LM[offset + 2 * width] - LM[offset - 2 * width])) * 0.0625f; //for 5x5 - if (v < LM[offset2]) { - signs[n] = -1; - } - - if (v > LM[offset2]) { - signs[n] = 1; - } - - n++; - } - - if (k == 1) { - contrast = sqrt(fabs(LM[offset + 1] - LM[offset - 1]) * fabs(LM[offset + 1] - LM[offset - 1]) + fabs(LM[offset + width] - LM[offset - width]) * fabs(LM[offset + width] - LM[offset - width])) / chmax; //for 3x3 - } else /* if (k==2) */ contrast = sqrt(fabs(LM[offset + 1] - LM[offset - 1]) * fabs(LM[offset + 1] - LM[offset - 1]) + fabs(LM[offset + width] - LM[offset - width]) * fabs(LM[offset + width] - LM[offset - width]) - + fabs(LM[offset + 2] - LM[offset - 2]) * fabs(LM[offset + 2] - LM[offset - 2]) + fabs(LM[offset + 2 * width] - LM[offset - 2 * width]) * fabs(LM[offset + 2 * width] - LM[offset - 2 * width])) / (2 * chmax); //for 5x5 - - if (contrast > 1.0f) { - contrast = 1.0f; - } + contrast = std::min(contrast, 1.f); //matrix 5x5 - temp = luminance[j][i] / 327.68f; //begin 3x3 - temp += CLIREF(v - LM[offset - width - 1]) * sqrtf(2.0f) * s; - temp += CLIREF(v - LM[offset - width]) * s; - temp += CLIREF(v - LM[offset - width + 1]) * sqrtf(2.0f) * s; - temp += CLIREF(v - LM[offset - 1]) * s; - temp += CLIREF(v - LM[offset + 1]) * s; - temp += CLIREF(v - LM[offset + width - 1]) * sqrtf(2.0f) * s; - temp += CLIREF(v - LM[offset + width]) * s; - temp += CLIREF(v - LM[offset + width + 1]) * sqrtf(2.0f) * s; //end 3x3 + float temp = v + 4.f *( v * (s + sqrt2 * s)); //begin 3x3 + float temp1 = sqrt2 * s *(LM[offset - width - 1] + LM[offset - width + 1] + LM[offset + width - 1] + LM[offset + width + 1]); + temp1 += s * (LM[offset - width] + LM[offset - 1] + LM[offset + 1] + LM[offset + width]); + + temp -= temp1; // add JD continue 5x5 if (k == 2) { - temp += 2.0f * CLIREF(v - LM[offset + 2 * width]) * s; - temp += 2.0f * CLIREF(v - LM[offset - 2 * width]) * s; - temp += 2.0f * CLIREF(v - LM[offset - 2 ]) * s; - temp += 2.0f * CLIREF(v - LM[offset + 2 ]) * s; + float temp2 = -(LM[offset + 2 * width] + LM[offset - 2 * width] + LM[offset - 2] + LM[offset + 2]); - temp += 2.0f * CLIREF(v - LM[offset + 2 * width - 1]) * s * sqrtf(1.25f); // 1.25 = 1*1 + 0.5*0.5 - temp += 2.0f * CLIREF(v - LM[offset + 2 * width - 2]) * s * sqrtf(2.00f); - temp += 2.0f * CLIREF(v - LM[offset + 2 * width + 1]) * s * sqrtf(1.25f); - temp += 2.0f * CLIREF(v - LM[offset + 2 * width + 2]) * s * sqrtf(2.00f); - temp += 2.0f * CLIREF(v - LM[offset + width + 2]) * s * sqrtf(1.25f); - temp += 2.0f * CLIREF(v - LM[offset + width - 2]) * s * sqrtf(1.25f); - temp += 2.0f * CLIREF(v - LM[offset - 2 * width - 1]) * s * sqrtf(1.25f); - temp += 2.0f * CLIREF(v - LM[offset - 2 * width - 2]) * s * sqrtf(2.00f); - temp += 2.0f * CLIREF(v - LM[offset - 2 * width + 1]) * s * sqrtf(1.25f); - temp += 2.0f * CLIREF(v - LM[offset - 2 * width + 2]) * s * sqrtf(2.00f); - temp += 2.0f * CLIREF(v - LM[offset - width + 2]) * s * sqrtf(1.25f); - temp += 2.0f * CLIREF(v - LM[offset - width - 2]) * s * sqrtf(1.25f); + temp2 -= sqrt1d25 * (LM[offset + 2 * width - 1] + LM[offset + 2 * width + 1] + LM[offset + width + 2] + LM[offset + width - 2] + + LM[offset - 2 * width - 1] + LM[offset - 2 * width + 1] + LM[offset - width + 2] + LM[offset - width - 2]); + + temp2 -= sqrt2 * (LM[offset + 2 * width - 2] + LM[offset + 2 * width + 2] + LM[offset - 2 * width - 2] + LM[offset - 2 * width + 2]); + temp2 += 18.601126159f * v ; // 18.601126159 = 4 + 4 * sqrt(2) + 8 * sqrt(1.25) + temp2 *= 2.f * s; + temp += temp2; } - if (temp < 0.0f) { - temp = 0.0f; - } + temp = std::max(temp, 0.f); - v = temp; - - n = 0; - - for(row = j - k; row <= j + k; row++) { - for(col = i - k, offset2 = row * width + col; col <= i + k; col++, offset2++) { - if (((v < LM[offset2]) && (signs[n] > 0)) || ((v > LM[offset2]) && (signs[n] < 0))) { - temp = v * 0.75f + LM[offset2] * 0.25f; // 0.75 0.25 + for(int row = j + k, n = SQR(2*k+1) - 1; row >= j - k; row--) { + for(int offset2 = row * width + i + k; offset2 >= row * width + i - k; offset2--) { + if((LM[offset2] - temp) * (v - LM[offset2]) > 0.f) { + temp = intp(0.75f, temp, LM[offset2]); + goto breakout; } - - n++; + n--; } } + breakout: if (LM[offset] > 95.0f || LM[offset] < 5.0f) { contrast *= Cont0[unif]; //+ JD : luminance pyramid to adjust contrast by evaluation of LM[offset] @@ -730,184 +692,114 @@ void ImProcFunctions::MLmicrocontrast(float** luminance, int W, int H) contrast *= Cont5[unif]; //(2.0f/k)*Cont5[unif]; } - if (contrast > 1.0f) { - contrast = 1.0f; - } + contrast = std::min(contrast, 1.f); - tempL = 327.68f * (temp * (1.0f - contrast) + LM[offset] * contrast); + float tempL = intp(contrast, LM[offset], temp); // JD: modulation of microcontrast in function of original Luminance and modulation of luminance - temp2 = tempL / (327.68f * LM[offset]); //for highlights - - if (temp2 > 1.0f) { - if (temp2 > 1.70f) { - temp2 = 1.70f; //limit action - } - - if (LM[offset] > 98.0f) { - luminance[j][i] = LM[offset] * 327.68f; + if (tempL > LM[offset]) { + float temp2 = tempL / LM[offset]; //for highlights + temp2 = std::min(temp2, 1.7f); //limit action + temp2 -= 1.f; + if (LM[offset] > 98.0f) { + temp = 0.f; } else if (LM[offset] > 95.0f) { - temp = (L95[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L95[unif]; } else if (LM[offset] > 92.0f) { - temp = (L92[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L92[unif]; } else if (LM[offset] > 90.0f) { - temp = (L90[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L90[unif]; } else if (LM[offset] > 87.0f) { - temp = (L87[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L87[unif]; } else if (LM[offset] > 83.0f) { - temp = (L83[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L83[unif]; } else if (LM[offset] > 80.0f) { - temp = (L80[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L80[unif]; } else if (LM[offset] > 75.0f) { - temp = (L75[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L75[unif]; } else if (LM[offset] > 70.0f) { - temp = (L70[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L70[unif]; } else if (LM[offset] > 63.0f) { - temp = (L63[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L63[unif]; } else if (LM[offset] > 58.0f) { - temp = (L58[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L58[unif]; } else if (LM[offset] > 42.0f) { - temp = (L58[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L58[unif]; } else if (LM[offset] > 37.0f) { - temp = (L63[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L63[unif]; } else if (LM[offset] > 30.0f) { - temp = (L70[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L70[unif]; } else if (LM[offset] > 25.0f) { - temp = (L75[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L75[unif]; } else if (LM[offset] > 20.0f) { - temp = (L80[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L80[unif]; } else if (LM[offset] > 17.0f) { - temp = (L83[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L83[unif]; } else if (LM[offset] > 13.0f) { - temp = (L87[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L87[unif]; } else if (LM[offset] > 10.0f) { - temp = (L90[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; + temp = L90[unif]; } else if (LM[offset] > 5.0f) { - temp = (L95[unif] * (temp2 - 1.f)) + 1.0f; - luminance[j][i] = temp * LM[offset] * 327.68f; - } else if (LM[offset] > 0.0f) { - luminance[j][i] = LM[offset] * 327.68f; + temp = L95[unif]; + } else { + temp = 0.f; + } + luminance[j][i] *= (temp * temp2 + 1.f); + } else { + + float temp4 = LM[offset] / tempL; // + + if (temp4 > 1.0f) { + temp4 = std::min(temp4, 1.7f); //limit action + temp4 -= 1.f; + if (LM[offset] < 2.0f) { + temp = L98[unif]; + } else if (LM[offset] < 5.0f) { + temp = L95[unif]; + } else if (LM[offset] < 8.0f) { + temp = L92[unif]; + } else if (LM[offset] < 10.0f) { + temp = L90[unif]; + } else if (LM[offset] < 13.0f) { + temp = L87[unif]; + } else if (LM[offset] < 17.0f) { + temp = L83[unif]; + } else if (LM[offset] < 20.0f) { + temp = L80[unif]; + } else if (LM[offset] < 25.0f) { + temp = L75[unif]; + } else if (LM[offset] < 30.0f) { + temp = L70[unif]; + } else if (LM[offset] < 37.0f) { + temp = L63[unif]; + } else if (LM[offset] < 42.0f) { + temp = L58[unif]; + } else if (LM[offset] < 58.0f) { + temp = L58[unif]; + } else if (LM[offset] < 63.0f) { + temp = L63[unif]; + } else if (LM[offset] < 70.0f) { + temp = L70[unif]; + } else if (LM[offset] < 75.0f) { + temp = L75[unif]; + } else if (LM[offset] < 80.0f) { + temp = L80[unif]; + } else if (LM[offset] < 83.0f) { + temp = L83[unif]; + } else if (LM[offset] < 87.0f) { + temp = L87[unif]; + } else if (LM[offset] < 90.0f) { + temp = L90[unif]; + } else if (LM[offset] < 95.0f) { + temp = L95[unif]; + } else { + temp = 0.f; + } + luminance[j][i] /= (temp * temp4 + 1.f); } } - - temp4 = (327.68f * LM[offset]) / tempL; // - - if (temp4 > 1.0f) { - if (temp4 > 1.7f) { - temp4 = 1.7f; //limit action - } - - if (LM[offset] < 2.0f) { - temp3 = temp4 - 1.0f; - temp = (L98[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 5.0f) { - temp3 = temp4 - 1.0f; - temp = (L95[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 8.0f) { - temp3 = temp4 - 1.0f; - temp = (L92[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 10.0f) { - temp3 = temp4 - 1.0f; - temp = (L90[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 13.0f) { - temp3 = temp4 - 1.0f; - temp = (L87[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 17.0f) { - temp3 = temp4 - 1.0f; - temp = (L83[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 20.0f) { - temp3 = temp4 - 1.0f; - temp = (L80[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 25.0f) { - temp3 = temp4 - 1.0f; - temp = (L75[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 30.0f) { - temp3 = temp4 - 1.0f; - temp = (L70[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 37.0f) { - temp3 = temp4 - 1.0f; - temp = (L63[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 42.0f) { - temp3 = temp4 - 1.0f; - temp = (L58[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 58.0f) { - temp3 = temp4 - 1.0f; - temp = (L58[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 63.0f) { - temp3 = temp4 - 1.0f; - temp = (L63[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 70.0f) { - temp3 = temp4 - 1.0f; - temp = (L70[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 75.0f) { - temp3 = temp4 - 1.0f; - temp = (L75[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 80.0f) { - temp3 = temp4 - 1.0f; - temp = (L80[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 83.0f) { - temp3 = temp4 - 1.0f; - temp = (L83[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 87.0f) { - temp3 = temp4 - 1.0f; - temp = (L87[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 90.0f) { - temp3 = temp4 - 1.0f; - temp = (L90[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 95.0f) { - temp3 = temp4 - 1.0f; - temp = (L95[unif] * temp3) + 1.0f; - luminance[j][i] = (LM[offset] * 327.68f) / temp; - } else if (LM[offset] < 100.0f) { - luminance[j][i] = LM[offset] * 327.68f; - } - } - } - +} delete [] LM; - t2e.set(); - - if (settings->verbose) { - printf("Micro-contrast %d usec\n", t2e.etime(t1e)); - } - } void ImProcFunctions::MLmicrocontrast(LabImage* lab) diff --git a/rtengine/pixelshift.cc b/rtengine/pixelshift.cc index 835aa7631..e7d6b86c7 100644 --- a/rtengine/pixelshift.cc +++ b/rtengine/pixelshift.cc @@ -1,13 +1,8 @@ //////////////////////////////////////////////////////////////// // -// pentax pixelshift algorithm with motion detection +// Algorithm for Pentax Pixel Shift raw files with motion detection // -// -// If motion correction is enabled only the pixels which are not detected as motion are set -// That means for a complete image you have to demosaic one of the frames with a bayer demosaicer to fill red, green and blue -// before calling pixelshift in case motion correction is enabled. -// -// copyright (c) Ingo Weyrich 2016 +// Copyright (C) 2016 - 2017 Ingo Weyrich // // // pixelshift.cc is free software: you can redistribute it and/or modify @@ -31,73 +26,29 @@ #include "procparams.h" #include "gauss.h" #include "median.h" -#define BENCHMARK -#include "StopWatch.h" namespace { -float greenDiff(float a, float b, bool adaptive, float stddevFactor, float eperIso, float nreadIso, float prnu, bool showMotion) +float greenDiff(float a, float b, float stddevFactor, float eperIso, float nreadIso, float prnu) { // calculate the difference between two green samples -#ifdef PIXELSHIFTDEV - if(adaptive) { -#endif - float gDiff = a - b; - gDiff *= eperIso; - gDiff *= gDiff; - float avg = (a + b) * 0.5f; - avg *= eperIso; - prnu *= avg; - float stddev = stddevFactor * (avg + nreadIso + prnu * prnu); - float result = gDiff - stddev; - - if(!showMotion) { - return result; - } else if(result > 0.f) { // for the motion mask - return std::fabs(a - b) / (std::max(a, b) + 0.01f); - } else { - return 0.f; - } -#ifdef PIXELSHIFTDEV - - } else { - float gDiff = std::fabs(a - b); - // add a small epsilon to avoid division by zero - float maxVal = std::max(a, b) + 0.01f; - return gDiff / maxVal; - } -#endif -} - -#ifdef PIXELSHIFTDEV -float nonGreenDiff(float a, float b, float stddevFactor, float eperIso, float nreadIso, float prnu, bool showMotion) -{ - // calculate the difference between two nongreen samples float gDiff = a - b; gDiff *= eperIso; gDiff *= gDiff; - float avg = (a + b) / 2.f; + float avg = (a + b) * 0.5f; avg *= eperIso; prnu *= avg; float stddev = stddevFactor * (avg + nreadIso + prnu * prnu); - float result = gDiff - stddev; - - if(!showMotion) { - return result; - } else if(result > 0.f) { // for the motion mask - return std::fabs(a - b) / (std::max(a, b) + 0.01f); - } else { - return 0.f; - } + return gDiff - stddev; } -#endif -float nonGreenDiffCross(float right, float left, float top, float bottom, float centre, float clippedVal, float stddevFactor, float eperIso, float nreadIso, float prnu, bool showMotion) +float nonGreenDiffCross(float right, float left, float top, float bottom, float centre, float clippedVal, float stddevFactor, float eperIso, float nreadIso, float prnu) { if(rtengine::max(right, left, top, bottom, centre) > clippedVal) { return 0.f; } + // check non green cross float hDiff = (right + left) * 0.5f - centre; hDiff *= eperIso; @@ -109,36 +60,32 @@ float nonGreenDiffCross(float right, float left, float top, float bottom, float avg *= eperIso; prnu *= avg; float stddev = stddevFactor * (avg + nreadIso + prnu * prnu); - float result = std::min(hDiff, vDiff) - stddev; - - if(!showMotion) { - return result; - } else if(result > 0.f) { // for the motion mask - return std::sqrt((result / (stddev + result + 0.01f))); - } else { - return 0.f; - } + return std::min(hDiff, vDiff) - stddev; } -void paintMotionMask(int index, bool showMotion, float gridMax, bool showOnlyMask, float *maskDest, float *nonMaskDest0, float *nonMaskDest1) +void paintMotionMask(int index, bool showMotion, bool showOnlyMask, float *maskDest, float *nonMaskDest0, float *nonMaskDest1) { if(showMotion) { if(!showOnlyMask) { // if showMotion is enabled colourize the pixel - maskDest[index] = 1000.f + 25000.f * gridMax; + maskDest[index] = 13500.f; nonMaskDest1[index] = nonMaskDest0[index] = 0.f; } else { - maskDest[index] = nonMaskDest0[index] = nonMaskDest1[index] = 1000.f + 25000.f * gridMax; + maskDest[index] = nonMaskDest0[index] = nonMaskDest1[index] = 65535.f; } } } void invertMask(int xStart, int xEnd, int yStart, int yEnd, const array2D &maskIn, array2D &maskOut) { +#ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) +#endif for(int i = yStart; i < yEnd; ++i) { +#ifdef _OPENMP #pragma omp simd +#endif for(int j = xStart; j < xEnd; ++j) { maskOut[i][j] = ~maskIn[i][j]; @@ -148,10 +95,14 @@ void invertMask(int xStart, int xEnd, int yStart, int yEnd, const array2D &maskIn, array2D &maskOut) { +#ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) +#endif for(int i = yStart; i < yEnd; ++i) { +#ifdef _OPENMP #pragma omp simd +#endif for(int j = xStart; j < xEnd; ++j) { maskOut[i][j] ^= maskIn[i][j]; @@ -168,7 +119,7 @@ void floodFill4Impl(int y, int x, int xStart, int xEnd, int yStart, int yEnd, ar coordStack.pop(); auto x = coord.first, y = coord.second; - if (mask[y][x] == 255) { + if(mask[y][x] == 255) { auto yUp = y - 1, yDown = y + 1; bool lastXUp = false, lastXDown = false, firstXUp = false, firstXDown = false; mask[y][x] = 0; @@ -244,27 +195,37 @@ void floodFill4Impl(int y, int x, int xStart, int xEnd, int yStart, int yEnd, ar void floodFill4(int xStart, int xEnd, int yStart, int yEnd, array2D &mask) { +#ifdef _OPENMP #pragma omp parallel +#endif { std::stack, std::vector>> coordStack; +#ifdef _OPENMP #pragma omp for schedule(dynamic,128) nowait +#endif for(uint16_t i = yStart; i < yEnd; i++) { floodFill4Impl(i, xStart, xStart, xEnd, yStart, yEnd, mask, coordStack); } +#ifdef _OPENMP #pragma omp for schedule(dynamic,128) nowait +#endif for(int16_t i = yEnd - 1; i >= 0 ; i--) { floodFill4Impl(i, xEnd - 1, xStart, xEnd, yStart, yEnd, mask, coordStack); } +#ifdef _OPENMP #pragma omp sections nowait +#endif { +#ifdef _OPENMP #pragma omp section +#endif { uint16_t i = yStart; @@ -273,7 +234,9 @@ void floodFill4(int xStart, int xEnd, int yStart, int yEnd, array2D &ma floodFill4Impl(i, j, xStart, xEnd, yStart, yEnd, mask, coordStack); } } +#ifdef _OPENMP #pragma omp section +#endif { uint16_t i = yStart; @@ -282,7 +245,9 @@ void floodFill4(int xStart, int xEnd, int yStart, int yEnd, array2D &ma floodFill4Impl(i, j, xStart, xEnd, yStart, yEnd, mask, coordStack); } } +#ifdef _OPENMP #pragma omp section +#endif { uint16_t i = yEnd; @@ -291,7 +256,9 @@ void floodFill4(int xStart, int xEnd, int yStart, int yEnd, array2D &ma floodFill4Impl(i, j, xStart, xEnd, yStart, yEnd, mask, coordStack); } } +#ifdef _OPENMP #pragma omp section +#endif { uint16_t i = yEnd; @@ -307,11 +274,12 @@ void floodFill4(int xStart, int xEnd, int yStart, int yEnd, array2D &ma void calcFrameBrightnessFactor(unsigned int frame, uint32_t datalen, LUT *histo[4], float brightnessFactor[4]) { float medians[4]; + for(int i = 0; i < 4; ++i) { //find median of histogram uint32_t median = 0, count = 0; - while (count < datalen / 2) { + while(count < datalen / 2) { count += (*histo[i])[median]; ++median; } @@ -333,186 +301,95 @@ using namespace std; using namespace rtengine; void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RAWParams::BayerSensor &bayerParamsIn, unsigned int frame, const std::string &model, float rawWpCorrection) { -#ifdef PIXELSHIFTDEV - BENCHFUN -#endif if(numFrames != 4) { // fallback for non pixelshift files - amaze_demosaic_RT (0, 0, winw, winh, rawData, red, green, blue); + amaze_demosaic_RT(winx, winy, winw, winh, rawData, red, green, blue); return; } RAWParams::BayerSensor bayerParams = bayerParamsIn; -#ifndef PIXELSHIFTDEV bayerParams.pixelShiftAutomatic = true; -#endif if(bayerParams.pixelShiftMotionCorrectionMethod == RAWParams::BayerSensor::Automatic) { bool pixelShiftEqualBright = bayerParams.pixelShiftEqualBright; bayerParams.setPixelShiftDefaults(); bayerParams.pixelShiftEqualBright = pixelShiftEqualBright; } else if(bayerParams.pixelShiftMotionCorrectionMethod == RAWParams::BayerSensor::Off) { - bayerParams.pixelShiftMotion = 0; bayerParams.pixelShiftAutomatic = false; bayerParams.pixelShiftShowMotion = false; } - if((bayerParams.pixelShiftMotion > 0 || bayerParams.pixelShiftAutomatic)) { - if(bayerParams.pixelShiftMedian) { // We need the amaze demosaiced frames for motion correction -#ifdef PIXELSHIFTDEV - if(!bayerParams.pixelShiftMedian3) { -#endif + const bool showMotion = bayerParams.pixelShiftShowMotion; + const bool showOnlyMask = bayerParams.pixelShiftShowMotionMaskOnly && showMotion; + + if(bayerParams.pixelShiftAutomatic) { + if(!showOnlyMask) { + if(bayerParams.pixelShiftMedian) { // We need the amaze demosaiced frames for motion correction if(bayerParams.pixelShiftLmmse) { lmmse_interpolate_omp(winw, winh, *(rawDataFrames[0]), red, green, blue, bayerParams.lmmse_iterations); } else { - amaze_demosaic_RT (0, 0, winw, winh, *(rawDataFrames[0]), red, green, blue); + amaze_demosaic_RT(winx, winy, winw, winh, *(rawDataFrames[0]), red, green, blue); } - multi_array2D redTmp(W,H); - multi_array2D greenTmp(W,H); - multi_array2D blueTmp(W,H); - for(int i=0;i<3;i++) { + + multi_array2D redTmp(winw, winh); + multi_array2D greenTmp(winw, winh); + multi_array2D blueTmp(winw, winh); + + for(int i = 0; i < 3; i++) { if(bayerParams.pixelShiftLmmse) { - lmmse_interpolate_omp(winw, winh, *(rawDataFrames[i+1]), redTmp[i], greenTmp[i], blueTmp[i], bayerParams.lmmse_iterations); + lmmse_interpolate_omp(winw, winh, *(rawDataFrames[i + 1]), redTmp[i], greenTmp[i], blueTmp[i], bayerParams.lmmse_iterations); } else { - amaze_demosaic_RT (0, 0, winw, winh, *(rawDataFrames[i+1]), redTmp[i], greenTmp[i], blueTmp[i]); + amaze_demosaic_RT(winx, winy, winw, winh, *(rawDataFrames[i + 1]), redTmp[i], greenTmp[i], blueTmp[i]); } } + +#ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) - for(int i=border;i redTmp(W,H); - multi_array2D greenTmp(W,H); - multi_array2D blueTmp(W,H); - for(unsigned int i=0, frameIndex = 0;i<4;++i) { - if(i != currFrame) { - if(bayerParams.pixelShiftLmmse) { - lmmse_interpolate_omp(winw, winh, *(rawDataFrames[i]), redTmp[frameIndex], greenTmp[frameIndex], blueTmp[frameIndex], bayerParams.lmmse_iterations); - } else { - amaze_demosaic_RT (0, 0, winw, winh, *(rawDataFrames[i]), redTmp[frameIndex], greenTmp[frameIndex], blueTmp[frameIndex]); - } - ++frameIndex; - } - } - unsigned int offsX0 = 0, offsY0 = 0; - unsigned int offsX1 = 0, offsY1 = 0; - unsigned int offsX2 = 0, offsY2 = 0; - - // We have to adjust the offsets for the selected subframe we exclude from median - switch (currFrame) { - case 0: - offsY0 = 1; - offsX0 = 0; - offsY1 = 1; - offsX1 = 1; - offsY2 = 0; - offsX2 = 1; - break; - - case 1: - offsY0 = 0; - offsX0 = 0; - offsY1 = 1; - offsX1 = 1; - offsY2 = 0; - offsX2 = 1; - break; - - case 2: - offsY0 = 0; - offsX0 = 0; - offsY1 = 1; - offsX1 = 0; - offsY2 = 0; - offsX2 = 1; - break; - - case 3: - offsY0 = 0; - offsX0 = 0; - offsY1 = 1; - offsX1 = 0; - offsY2 = 1; - offsX2 = 1; - } - - #pragma omp parallel for schedule(dynamic,16) - for(int i=border;i 0; - float stddevFactorGreen = bayerParams.pixelShiftStddevFactorGreen; - float stddevFactorRed = bayerParams.pixelShiftStddevFactorRed; - float stddevFactorBlue = bayerParams.pixelShiftStddevFactorBlue; - float nreadIso = bayerParams.pixelShiftNreadIso; - float prnu = bayerParams.pixelShiftPrnu; - const float redBlueWeight = bayerParams.pixelShiftRedBlueWeight + 1.f; -#else - float stddevFactorGreen = 5.f; - float stddevFactorRed = 5.f; - float stddevFactorBlue = 5.f; - float nreadIso = 0.f; - float prnu = 1.f; - const float redBlueWeight = 0.7f + 1.f; -#endif + constexpr float stddevFactorGreen = 25.f; + constexpr float stddevFactorRed = 25.f; + constexpr float stddevFactorBlue = 25.f; + constexpr float prnu = 0.01f; + constexpr float redBlueWeight = 0.7f + 1.f; float eperIso = bayerParams.pixelShiftEperIso; const bool checkNonGreenCross = bayerParams.pixelShiftNonGreenCross; const bool checkGreen = bayerParams.pixelShiftGreen; - const float greenWeight = 2.f; + constexpr float greenWeight = 2.f; const bool blurMap = bayerParams.pixelShiftBlur; const float sigma = bayerParams.pixelShiftSigma; -#ifdef PIXELSHIFTDEV - const bool checkNonGreenHorizontal = bayerParams.pixelShiftNonGreenHorizontal; - const bool checkNonGreenVertical = bayerParams.pixelShiftNonGreenVertical; - const bool checkNonGreenAmaze = bayerParams.pixelShiftNonGreenAmaze; - const bool checkNonGreenCross2 = bayerParams.pixelShiftNonGreenCross2; - const float threshold = bayerParams.pixelShiftSum + 9.f; - const bool experimental0 = bayerParams.pixelShiftExp0; -#else constexpr float threshold = 3.f + 9.f; -#endif const bool holeFill = bayerParams.pixelShiftHoleFill; const bool equalBrightness = bayerParams.pixelShiftEqualBright; const bool equalChannel = bayerParams.pixelShiftEqualBrightChannel; @@ -546,8 +423,7 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA 1.5f, // ISO 25600 1.5f, // ISO 32000 1.5f, // ISO 40000 - 1.5f, // ISO 51200 - 1.5f // ISO > 51200 (we get a max ISO value of 65535 from dcraw) + 1.5f // ISO 51200 }; static const float ePerIsoK3II = 0.35f; @@ -590,6 +466,7 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA static const float ePerIsoK1 = 0.75f; + // currently nReadK70 is used for K-70 and KP static const float nReadK70[] = { 4.0f, // ISO 100 4.0f, // ISO 125 4.0f, // ISO 160 @@ -618,50 +495,28 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA 3.0f, // ISO 32000 3.0f, // ISO 40000 3.0f, // ISO 51200 - 3.0f // ISO > 51200 (we get a max ISO value of 65535 from dcraw) + 3.0f, // ISO 64000 + 3.0f, // ISO 80000 + 3.0f, // ISO 102400 + 3.0f, // ISO 128000 + 3.0f, // ISO 160000 + 3.0f, // ISO 204800 + 3.0f, // ISO 256000 + 3.0f, // ISO 320000 + 3.0f, // ISO 409600 + 3.0f, // ISO 512000 + 3.0f, // ISO 640000 + 3.0f // ISO 819200 }; static const float ePerIsoK70 = 0.5f; - if (plistener) { - plistener->setProgressStr (Glib::ustring::compose(M("TP_RAW_DMETHOD_PROGRESSBAR"), RAWParams::BayerSensor::methodstring[RAWParams::BayerSensor::pixelshift])); + if(plistener) { + plistener->setProgressStr(Glib::ustring::compose(M("TP_RAW_DMETHOD_PROGRESSBAR"), RAWParams::BayerSensor::methodstring[RAWParams::BayerSensor::pixelshift])); plistener->setProgress(0.0); } - -#ifdef PIXELSHIFTDEV - const bool skip = (gridSize_ == RAWParams::BayerSensor::ePSMotionCorrection::Grid1x2); - int gridSize = 1; - - bool nOf3x3 = false; - - switch (gridSize_) { - case RAWParams::BayerSensor::ePSMotionCorrection::Grid1x1: - case RAWParams::BayerSensor::ePSMotionCorrection::Grid1x2: - gridSize = 1; - break; - - case RAWParams::BayerSensor::ePSMotionCorrection::Grid3x3: - gridSize = 3; - break; - - case RAWParams::BayerSensor::ePSMotionCorrection::Grid5x5: - gridSize = 5; - break; - - case RAWParams::BayerSensor::ePSMotionCorrection::Grid7x7: - gridSize = 7; - break; - - case RAWParams::BayerSensor::ePSMotionCorrection::Grid3x3New: - gridSize = 1; - nOf3x3 = true; - } -#else - const bool nOf3x3 = true; -#endif - - if(adaptive && blurMap && nOf3x3 && smoothFactor == 0.f && !showMotion) { + if(adaptive && blurMap && smoothFactor == 0.f && !showMotion) { if(plistener) { plistener->setProgress(1.0); } @@ -669,20 +524,6 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA return; } -#ifdef PIXELSHIFTDEV - // Lookup table for non adaptive (slider) mode - LUTf log2Lut(32768, LUT_CLIP_BELOW | LUT_CLIP_ABOVE); - - if(detectMotion && !adaptive) { - const float lutStrength = 2.f; - log2Lut[0] = 0; - - for(int i = 2; i < 65536; i += 2) { - log2Lut[i >> 1] = lutStrength * log2(i) / 100.f; - } - } -#endif - const float scaleGreen = 1.f / scale_mul[1]; float nRead; @@ -696,27 +537,15 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA } else if(model.find("K-1") != string::npos) { nRead = nReadK1[nReadIndex]; eperIsoModel = ePerIsoK1; - } else { + } else { // as long as we don't have values for Pentax KP, we use the values from K-70 nRead = nReadK70[nReadIndex]; eperIsoModel = ePerIsoK70; } - nRead *= pow(2.f, nreadIso); eperIsoModel *= pow(2.f, eperIso); -#ifdef PIXELSHIFTDEV - if(adaptive && experimental0) { - eperIso = eperIsoModel * sqrtf(100.f / (rawWpCorrection * idata->getISOSpeed())); - } else { - eperIso = eperIsoModel * (100.f / (rawWpCorrection * idata->getISOSpeed())); - } -#else eperIso = eperIsoModel * (100.f / (rawWpCorrection * idata->getISOSpeed())); -#endif -#ifdef PIXELSHIFTDEV - std::cout << "WL: " << c_white[0] << " BL: " << c_black[0] << " ePerIso multiplicator: " << (65535.f / (c_white[0] - c_black[0])) << std::endl; -#endif const float eperIsoRed = (eperIso / scale_mul[0]) * (65535.f / (c_white[0] - c_black[0])); const float eperIsoGreen = (eperIso * scaleGreen) * (65535.f / (c_white[1] - c_black[1])); const float eperIsoBlue = (eperIso / scale_mul[2]) * (65535.f / (c_white[2] - c_black[2])); @@ -724,44 +553,8 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA const float clippedRed = 65535.f / scale_mul[0]; const float clippedBlue = 65535.f / scale_mul[2]; - prnu /= 100.f; - stddevFactorGreen *= stddevFactorGreen; - stddevFactorRed *= stddevFactorRed; - stddevFactorBlue *= stddevFactorBlue; - - nRead *= nRead; - // If the values of two corresponding green pixels differ my more then motionThreshold %, the pixel will be treated as a badGreen pixel - const float motionThreshold = 1.f - (motion / 100.f); - // For shades of green motion indicators -#ifdef PIXELSHIFTDEV - const float blendFactor = ((adaptive || motion == 0.f) ? 1.f : 1.f / (1.f - motionThreshold)); -#endif - int offsX = 0, offsY = 0; - - if(!bayerParams.pixelShiftMedian || !adaptive) { - // We have to adjust the offsets for the selected subframe we use for areas with motion - switch (frame) { - case 0: - offsX = offsY = 0; - break; - - case 1: - offsX = 0; - offsY = 1; - break; - - case 2: - offsX = offsY = 1; - break; - - case 3: - offsX = 1; - offsY = 0; - } - } - // calculate average green brightness for each frame float greenBrightness[4] = {1.f, 1.f, 1.f, 1.f}; float redBrightness[4] = {1.f, 1.f, 1.f, 1.f}; @@ -811,6 +604,7 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA for(int j = winx + 1, offset = FC(i, j) & 1; j < winw - 1; ++j, offset ^= 1) { (*histogreenThr[1 - offset])[(*rawDataFrames[1 - offset])[i - offset + 1][j]]++; (*histogreenThr[3 - offset])[(*rawDataFrames[3 - offset])[i + offset][j + 1]]++; + if(bluerow) { (*historedThr[2 - offset])[(*rawDataFrames[2 - offset])[i + 1][j - offset + 1]]++; (*histoblueThr[(offset << 1) + offset])[(*rawDataFrames[(offset << 1) + offset])[i][j + offset]]++; @@ -821,7 +615,9 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA } } +#ifdef _OPENMP #pragma omp critical +#endif { for(int i = 0; i < 4; ++i) { (*histogreen[i]) += (*histogreenThr[i]); @@ -843,556 +639,146 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA delete histoblue[i]; delete histogreen[i]; } - -#ifdef PIXELSHIFTDEV - std::cout << "blue brightness factors by median : " << blueBrightness[0] << " " << blueBrightness[1] << " " << blueBrightness[2] << " " << blueBrightness[3] << std::endl; - std::cout << "red brightness factors by median : " << redBrightness[0] << " " << redBrightness[1] << " " << redBrightness[2] << " " << redBrightness[3] << std::endl; - std::cout << "green brightness factors by median : " << greenBrightness[0] << " " << greenBrightness[1] << " " << greenBrightness[2] << " " << greenBrightness[3] << std::endl; -#endif - } - const float thresh = adaptive ? 0.f : motionThreshold; - array2D psRed(winw + 32, winh); // increase width to avoid cache conflicts - array2D psG1(winw + 32, winh); - array2D psG2(winw + 32, winh); - array2D psBlue(winw + 32, winh); - if(!equalChannel) { - for(int i = 0; i < 4; ++i ) { + for(int i = 0; i < 4; ++i) { redBrightness[i] = blueBrightness[i] = greenBrightness[i]; } } -// fill channels psRed, psG1, psG2 and psBlue -#ifdef _OPENMP - #pragma omp parallel for schedule(dynamic,16) -#endif - for(int i = winy + 1; i < winh - 1; ++i) { - float *greenDest1 = psG1[i]; - float *greenDest2 = psG2[i]; - float *nonGreenDest0 = psRed[i]; - float *nonGreenDest1 = psBlue[i]; - float ngbright[2][4] = {{redBrightness[0],redBrightness[1],redBrightness[2],redBrightness[3]}, - {blueBrightness[0],blueBrightness[1],blueBrightness[2],blueBrightness[3]} - }; - int ng = 0; - int j = winx + 1; - int c = FC(i, j); - - if ((c + FC(i, j + 1)) == 3) { - // row with blue pixels => swap destination pointers for non green pixels - std::swap(nonGreenDest0, nonGreenDest1); - std::swap(greenDest1, greenDest2); - ng ^= 1; - } - - // offset to keep the code short. It changes its value between 0 and 1 for each iteration of the loop - unsigned int offset = c & 1; - - for(; j < winw - 1; ++j) { - // store the values from the 4 frames into 4 different temporary planes - greenDest1[j] = (*rawDataFrames[1 - offset])[i - offset + 1][j] * greenBrightness[1 - offset]; - greenDest2[j] = (*rawDataFrames[3 - offset])[i + offset][j + 1] * greenBrightness[3 - offset]; - nonGreenDest0[j] = (*rawDataFrames[(offset << 1) + offset])[i][j + offset] * ngbright[ng][(offset << 1) + offset]; - nonGreenDest1[j] = (*rawDataFrames[2 - offset])[i + 1][j - offset + 1] * ngbright[ng^1][2 - offset]; - offset ^= 1; // 0 => 1 or 1 => 0 - } - } - -// now that the temporary planes are filled for easy access we do the motion detection -#ifdef PIXELSHIFTDEV - int sum[2] = {0}; - float pixelcount = ((winh - (border + offsY) - (winy + border - offsY)) * (winw - (border + offsX) - (winx + border - offsX))) / 2.f; -#endif - - array2D psMask(winw, winh); + if(adaptive) { + // fill channels psRed and psBlue + array2D psRed(winw + 32, winh); // increase width to avoid cache conflicts + array2D psBlue(winw + 32, winh); #ifdef _OPENMP - #pragma omp parallel -#endif - { -#ifdef PIXELSHIFTDEV - int sumThr[2] = {0}; -#endif -#ifdef _OPENMP - #pragma omp for schedule(dynamic,16) nowait -#endif - - for(int i = winy + border - offsY; i < winh - (border + offsY); ++i) { -#ifdef PIXELSHIFTDEV - float *greenDest = green[i + offsY]; - float *redDest = red[i + offsY]; - float *blueDest = blue[i + offsY]; -#endif - int j = winx + border - offsX; - -#ifdef PIXELSHIFTDEV - float greenDifMax[gridSize]; // Here we store the maximum differences per Column - - // green channel motion detection checks the grid around the pixel for differences in green channels - - if(detectMotion || (adaptive && checkGreen)) { - if(gridSize == 3) { - // compute maximum of differences for first two columns of 3x3 grid - greenDifMax[0] = std::max({greenDiff(psG1[i - 1][j - 1], psG2[i - 1][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j - 1], psG2[ i ][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j - 1], psG2[i + 1][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[1] = std::max({greenDiff(psG1[i - 1][ j ], psG2[i - 1][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][ j ], psG2[ i ][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][ j ], psG2[i + 1][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - } else if(gridSize == 5) { - // compute maximum of differences for first four columns of 5x5 grid - greenDifMax[0] = std::max({greenDiff(psG1[i - 2][j - 2], psG2[i - 2][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j - 2], psG2[i - 1][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j - 2], psG2[ i ][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j - 2], psG2[i + 1][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j - 2], psG2[i + 2][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[1] = std::max({greenDiff(psG1[i - 2][j - 1], psG2[i - 2][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j - 1], psG2[i - 1][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j - 1], psG2[ i ][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j - 1], psG2[i + 1][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j - 1], psG2[i + 2][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[2] = std::max({greenDiff(psG1[i - 2][ j ], psG2[i - 2][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][ j ], psG2[i - 1][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][ j ], psG2[ i ][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][ j ], psG2[i + 1][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][ j ], psG2[i + 2][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[3] = std::max({greenDiff(psG1[i - 2][j + 1], psG2[i - 2][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j + 1], psG2[i - 1][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j + 1], psG2[ i ][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j + 1], psG2[i + 1][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j + 1], psG2[i + 2][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - } else if(gridSize == 7) { - // compute maximum of differences for first six columns of 7x7 grid - greenDifMax[0] = std::max({greenDiff(psG1[i - 3][j - 3], psG2[i - 3][j - 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 2][j - 3], psG2[i - 2][j - 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j - 3], psG2[i - 1][j - 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j - 3], psG2[ i ][j - 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j - 3], psG2[i + 1][j - 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j - 3], psG2[i + 2][j - 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 3][j - 3], psG2[i + 3][j - 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[1] = std::max({greenDiff(psG1[i - 3][j - 2], psG2[i - 3][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 2][j - 2], psG2[i - 2][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j - 2], psG2[i - 1][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j - 2], psG2[ i ][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j - 2], psG2[i + 1][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j - 2], psG2[i + 2][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 3][j - 2], psG2[i + 3][j - 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[2] = std::max({greenDiff(psG1[i - 3][j - 1], psG2[i - 3][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 2][j - 1], psG2[i - 2][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j - 1], psG2[i - 1][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j - 1], psG2[ i ][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j - 1], psG2[i + 1][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j - 1], psG2[i + 2][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 3][j - 1], psG2[i + 3][j - 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[3] = std::max({greenDiff(psG1[i - 3][ j ], psG2[i - 3][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 2][ j ], psG2[i - 2][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][ j ], psG2[i - 1][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][ j ], psG2[ i ][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][ j ], psG2[i + 1][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][ j ], psG2[i + 2][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 3][ j ], psG2[i + 3][ j ], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[4] = std::max({greenDiff(psG1[i - 3][j + 1], psG2[i - 3][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 2][j + 1], psG2[i - 2][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j + 1], psG2[i - 1][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j + 1], psG2[ i ][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j + 1], psG2[i + 1][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j + 1], psG2[i + 2][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 3][j + 1], psG2[i + 3][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - greenDifMax[5] = std::max({greenDiff(psG1[i - 3][j + 2], psG2[i - 3][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 2][j + 2], psG2[i - 2][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j + 2], psG2[i - 1][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j + 2], psG2[ i ][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j + 2], psG2[i + 1][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j + 2], psG2[i + 2][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 3][j + 2], psG2[i + 3][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - } - - } - - // this is the index for the last column of the grid. Obviously we have to start with gridSize - 1 - int lastIndex = gridSize - 1; - float korr = 0.f; - bool blueRow = false; + #pragma omp parallel for schedule(dynamic,16) #endif + for(int i = winy + 1; i < winh - 1; ++i) { + float *nonGreenDest0 = psRed[i]; + float *nonGreenDest1 = psBlue[i]; + float ngbright[2][4] = {{redBrightness[0], redBrightness[1], redBrightness[2], redBrightness[3]}, + {blueBrightness[0], blueBrightness[1], blueBrightness[2], blueBrightness[3]} + }; + int ng = 0; + int j = winx + 1; int c = FC(i, j); -#ifdef PIXELSHIFTDEV - if (c == 2 || ((c & 1) && FC(i, j + 1) == 2)) { + if((c + FC(i, j + 1)) == 3) { // row with blue pixels => swap destination pointers for non green pixels - blueRow = true; + std::swap(nonGreenDest0, nonGreenDest1); + ng ^= 1; } -#endif + // offset to keep the code short. It changes its value between 0 and 1 for each iteration of the loop unsigned int offset = c & 1; - for(; j < winw - (border + offsX); ++j) { + for(; j < winw - 1; ++j) { + // store the non green values from the 4 frames into 2 temporary planes + nonGreenDest0[j] = (*rawDataFrames[(offset << 1) + offset])[i][j + offset] * ngbright[ng][(offset << 1) + offset]; + nonGreenDest1[j] = (*rawDataFrames[2 - offset])[i + 1][j - offset + 1] * ngbright[ng ^ 1][2 - offset]; + offset ^= 1; // 0 => 1 or 1 => 0 + } + } + + // now that the temporary planes are filled for easy access we do the motion detection + array2D psMask(winw, winh); + + int offsX = 0, offsY = 0; + + if(!bayerParams.pixelShiftMedian) { + // We have to adjust the offsets for the selected subframe we use for areas with motion + switch(frame) { + case 0: + offsX = offsY = 0; + break; + + case 1: + offsX = 0; + offsY = 1; + break; + + case 2: + offsX = offsY = 1; + break; + + case 3: + offsX = 1; + offsY = 0; + } + } + + +#ifdef _OPENMP + #pragma omp parallel for schedule(dynamic,16) +#endif + + for(int i = winy + border - offsY; i < winh - (border + offsY); ++i) { + // offset to keep the code short. It changes its value between 0 and 1 for each iteration of the loop + unsigned int offset = FC(i, winx + border - offsX) & 1; + + for(int j = winx + border - offsX; j < winw - (border + offsX); ++j, offset ^= 1) { psMask[i][j] = 1.f; - offset ^= 1; // 0 => 1 or 1 => 0 - -#ifdef PIXELSHIFTDEV - if(detectMotion || (adaptive && checkGreen)) { - bool skipNext = false; - float gridMax = 0.f; -#else - if(adaptive && checkGreen) { - float gridMax; -#endif - -#ifdef PIXELSHIFTDEV - - if(gridSize < 2) { - // compute difference for current pixel and skip next pixel, that's roughly the method from dcrawps -#endif - gridMax = greenDiff(psG1[i][j], psG2[i][j], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion); -#ifdef PIXELSHIFTDEV - - skipNext = skip; - } else if(gridSize == 3) { - // compute maximum of differences for third column of 3x3 grid and save at position lastIndex - greenDifMax[lastIndex] = std::max({greenDiff(psG1[i - 1][j + 1], psG2[i - 1][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j + 1], psG2[ i ][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j + 1], psG2[i + 1][j + 1], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - // calculate maximum of whole grid by calculating maximum of grid column max values - gridMax = std::max({greenDifMax[0], greenDifMax[1], greenDifMax[2]}); - // adjust index for next column - lastIndex ++; - lastIndex = lastIndex == gridSize ? 0 : lastIndex; - } else if(gridSize == 5) { - // compute maximum of differences for fifth column of 5x5 grid and save at position lastIndex - greenDifMax[lastIndex] = std::max({greenDiff(psG1[i - 2][j + 2], psG2[i - 2][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j + 2], psG2[i - 1][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j + 2], psG2[ i ][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j + 2], psG2[i + 1][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j + 2], psG2[i + 2][j + 2], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion) - }); - // calculate maximum of whole grid by calculating maximum of grid column max values - gridMax = std::max({greenDifMax[0], greenDifMax[1], greenDifMax[2], greenDifMax[3], greenDifMax[4]}); - // adjust index for next column - lastIndex ++; - lastIndex = lastIndex == gridSize ? 0 : lastIndex; - } else if(gridSize == 7) { - // compute maximum of differences for 7th column of 7x7 grid and save at position lastIndex - greenDifMax[lastIndex] = std::max({greenDiff(psG1[i - 3][j + 3], psG2[i - 3][j + 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 2][j + 3], psG2[i - 2][j + 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i - 1][j + 3], psG2[i - 1][j + 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[ i ][j + 3], psG2[ i ][j + 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 1][j + 3], psG2[i + 1][j + 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 2][j + 3], psG2[i + 2][j + 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - greenDiff(psG1[i + 3][j + 3], psG2[i + 3][j + 3], adaptive, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion), - }); - // calculate maximum of whole grid by calculating maximum of grid column max values - gridMax = std::max({greenDifMax[0], greenDifMax[1], greenDifMax[2], greenDifMax[3], greenDifMax[4], greenDifMax[5], greenDifMax[6]}); - // adjust index for next column - lastIndex ++; - lastIndex = lastIndex == gridSize ? 0 : lastIndex; - } - - if(!adaptive) { - // increase motion detection dependent on brightness - korr = log2Lut[((int)(psG1[i][j] * scaleGreen)) >> 1]; - } - - if (gridMax > thresh - korr) { -#else - if (gridMax > thresh) { - -#endif - -#ifdef PIXELSHIFTDEV - sumThr[offset] ++; - - if(nOf3x3) { -#endif - psMask[i][j] = greenWeight; -#ifdef PIXELSHIFTDEV - } - - else if((offset == (frame & 1)) && checkNonGreenVertical) { - if(frame > 1) { - green[i + offsY][j + offsX] = blueRow ? psG1[i][j] : psG2[i][j]; - } else { - green[i + offsY][j + offsX] = blueRow ? psG2[i][j] : psG1[i][j];; - } - - } else { - // at least one of the tested green pixels of the grid is detected as motion - paintMotionMask(j + offsX, showMotion, (gridMax - thresh + korr) * blendFactor, showOnlyMask, greenDest, redDest, blueDest); - - if(skipNext) { - // treat the horizontally next pixel also as motion - j++; - paintMotionMask(j + offsX, showMotion, (gridMax - thresh + korr) * blendFactor, showOnlyMask, greenDest, redDest, blueDest); - } - } - -#endif - // do not set the motion pixel values. They have already been set by demosaicer or showMotion + if(checkGreen) { + if(greenDiff((*rawDataFrames[1 - offset])[i - offset + 1][j] * greenBrightness[1 - offset], (*rawDataFrames[3 - offset])[i + offset][j + 1] * greenBrightness[3 - offset], stddevFactorGreen, eperIsoGreen, nRead, prnu) > 0.f) { + psMask[i][j] = greenWeight; + // do not set the motion pixel values. They have already been set by demosaicer continue; } } - if(adaptive) { - if(checkNonGreenCross) { - // check red cross - float redTop = psRed[i - 1][ j ]; - float redLeft = psRed[ i ][j - 1]; - float redCentre = psRed[ i ][ j ]; - float redRight = psRed[ i ][j + 1]; - float redBottom = psRed[i + 1][ j ]; - float redDiff = nonGreenDiffCross(redRight, redLeft, redTop, redBottom, redCentre, clippedRed, stddevFactorRed, eperIsoRed, nRead, prnu, showMotion); + if(checkNonGreenCross) { + // check red cross + float redTop = psRed[i - 1][ j ]; + float redLeft = psRed[ i ][j - 1]; + float redCentre = psRed[ i ][ j ]; + float redRight = psRed[ i ][j + 1]; + float redBottom = psRed[i + 1][ j ]; + float redDiff = nonGreenDiffCross(redRight, redLeft, redTop, redBottom, redCentre, clippedRed, stddevFactorRed, eperIsoRed, nRead, prnu); - if(redDiff > 0.f) { -#ifdef PIXELSHIFTDEV - - if(nOf3x3) { -#endif - psMask[i][j] = redBlueWeight; -#ifdef PIXELSHIFTDEV - } else { - paintMotionMask(j + offsX, showMotion, redDiff, showOnlyMask, redDest, blueDest, greenDest); - } - -#endif - continue; - } - - // check blue cross - float blueTop = psBlue[i - 1][ j ]; - float blueLeft = psBlue[ i ][j - 1]; - float blueCentre = psBlue[ i ][ j ]; - float blueRight = psBlue[ i ][j + 1]; - float blueBottom = psBlue[i + 1][ j ]; - float blueDiff = nonGreenDiffCross(blueRight, blueLeft, blueTop, blueBottom, blueCentre, clippedBlue, stddevFactorBlue, eperIsoBlue, nRead, prnu, showMotion); - - if(blueDiff > 0.f) { -#ifdef PIXELSHIFTDEV - - if(nOf3x3) { -#endif - psMask[i][j] = redBlueWeight; -#ifdef PIXELSHIFTDEV - } else { - paintMotionMask(j + offsX, showMotion, blueDiff, showOnlyMask, blueDest, redDest, greenDest); - } - -#endif - continue; - - } + if(redDiff > 0.f) { + psMask[i][j] = redBlueWeight; + continue; } -#ifdef PIXELSHIFTDEV + // check blue cross + float blueTop = psBlue[i - 1][ j ]; + float blueLeft = psBlue[ i ][j - 1]; + float blueCentre = psBlue[ i ][ j ]; + float blueRight = psBlue[ i ][j + 1]; + float blueBottom = psBlue[i + 1][ j ]; + float blueDiff = nonGreenDiffCross(blueRight, blueLeft, blueTop, blueBottom, blueCentre, clippedBlue, stddevFactorBlue, eperIsoBlue, nRead, prnu); - if(checkNonGreenHorizontal) { - float redLeft = psRed[ i ][j - 1]; - float redCentre = psRed[ i ][ j ]; - float redRight = psRed[ i ][j + 1]; - - float redDiffLeft = redLeft - redCentre; - float redDiffRight = redRight - redCentre; - - if(redDiffLeft * redDiffRight >= 0.f) { - float redAvg = (redRight + redLeft) / 2.f; - float redDiffHor = nonGreenDiff(redCentre, redAvg, stddevFactorRed, eperIsoRed, nRead, prnu, showMotion); - - if(redDiffHor > 0.f) { - if(nOf3x3) { - psMask[i][j] = redBlueWeight; - } else { - paintMotionMask(j + offsX, showMotion, redDiffHor, showOnlyMask, redDest, blueDest, greenDest); - } - - continue; - } - } - - float blueLeft = psBlue[ i ][j - 1]; - float blueCentre = psBlue[ i ][ j ]; - float blueRight = psBlue[ i ][j + 1]; - - float blueDiffLeft = blueLeft - blueCentre; - float blueDiffRight = blueRight - blueCentre; - - if(blueDiffLeft * blueDiffRight >= 0.f) { - float blueAvg = (blueRight + blueLeft) / 2.f; - float blueDiffHor = nonGreenDiff(blueCentre, blueAvg, stddevFactorBlue, eperIsoBlue, nRead, prnu, showMotion); - - if(blueDiffHor > 0.f) { - if(nOf3x3) { - psMask[i][j] = redBlueWeight; - } else { - paintMotionMask(j + offsX, showMotion, blueDiffHor, showOnlyMask, blueDest, redDest, greenDest); - } - - continue; - } - } + if(blueDiff > 0.f) { + psMask[i][j] = redBlueWeight; + continue; } - - if(checkNonGreenVertical) { - // check red vertically - float redTop = psRed[i - 1][ j ]; - float redCentre = psRed[ i ][ j ]; - float redBottom = psRed[i + 1][ j ]; - - float redDiffTop = redTop - redCentre; - float redDiffBottom = redBottom - redCentre; - - if(redDiffTop * redDiffBottom >= 0.f) { - float redAvg = (redTop + redBottom) / 2.f; - float redDiff = nonGreenDiff(redCentre, redAvg, stddevFactorRed, eperIsoRed, nRead, prnu, showMotion); - - if(redDiff > 0.f) { - if(nOf3x3) { - psMask[i][j] = redBlueWeight; - } else { - paintMotionMask(j + offsX, showMotion, redDiff, showOnlyMask, redDest, blueDest, greenDest); - } - - continue; - } - } - - // check blue vertically - float blueTop = psBlue[i - 1][ j ]; - float blueCentre = psBlue[ i ][ j ]; - float blueBottom = psBlue[i + 1][ j ]; - - float blueDiffTop = blueTop - blueCentre; - float blueDiffBottom = blueBottom - blueCentre; - - if(blueDiffTop * blueDiffBottom >= 0.f) { - float blueAvg = (blueTop + blueBottom) / 2.f; - float blueDiff = nonGreenDiff(blueCentre, blueAvg, stddevFactorBlue, eperIsoBlue, nRead, prnu, showMotion); - - if(blueDiff > 0.f) { - if(nOf3x3) { - psMask[i][j] = redBlueWeight; - } else { - paintMotionMask(j + offsX, showMotion, blueDiff, showOnlyMask, blueDest, redDest, greenDest); - } - - continue; - } - } - } - - if(checkNonGreenAmaze) { - // check current pixel against amaze - float redCentre = psRed[ i ][ j ]; - float redAmaze = red[i + offsY][j + offsX]; - - float redDiffAmaze = nonGreenDiff(redCentre, redAmaze, stddevFactorRed, eperIsoRed, nRead, prnu, showMotion); - - if(redDiffAmaze > 0.f) { - if(nOf3x3) { - psMask[i][j] = redBlueWeight; - } else { - paintMotionMask(j + offsX, showMotion, redDiffAmaze, showOnlyMask, redDest, blueDest, greenDest); - } - - continue; - } - - float blueCentre = psBlue[ i ][ j ]; - float blueAmaze = blue[i + offsY][j + offsX]; - - float blueDiffAmaze = nonGreenDiff(blueCentre, blueAmaze, stddevFactorBlue, eperIsoBlue, nRead, prnu, showMotion); - - if(blueDiffAmaze > 0.f) { - if(nOf3x3) { - psMask[i][j] = redBlueWeight; - } else { - paintMotionMask(j + offsX, showMotion, blueDiffAmaze, showOnlyMask, blueDest, redDest, greenDest); - } - - continue; - } - } - - if(checkNonGreenCross2) { // for green amaze - float greenCentre = (psG1[ i ][ j ] + psG2[ i ][ j ]) / 2.f; - float greenAmaze = green[i + offsY][j + offsX]; - float greenDiffAmaze = nonGreenDiff(greenCentre, greenAmaze, stddevFactorGreen, eperIsoGreen, nRead, prnu, showMotion); - - if(greenDiffAmaze > 0.f) { - if(nOf3x3) { - psMask[i][j] = greenWeight; - } else { - paintMotionMask(j + offsX, showMotion, greenDiffAmaze, showOnlyMask, greenDest, redDest, blueDest); - } - - continue; - } - } - - if(experimental0) { // for experiments - - } - -#endif } if(showOnlyMask) { // we want only motion mask => paint areas without motion in pure black red[i + offsY][j + offsX] = green[i + offsY][j + offsX] = blue[i + offsY][j + offsX] = 0.f; - } else if(!(adaptive && nOf3x3)) { - // no motion detected, replace the a priori demosaiced values by the pixelshift combined values - red[i + offsY][j + offsX] = psRed[i][j]; - green[i + offsY][j + offsX] = (psG1[i][j] + psG2[i][j]) / 2.f; - blue[i + offsY][j + offsX] = psBlue[i][j]; } } } -#ifdef PIXELSHIFTDEV - -#ifdef _OPENMP - #pragma omp critical -#endif - { - sum[0] += sumThr[0]; - sum[1] += sumThr[1]; - } -#endif - } - - -#ifdef PIXELSHIFTDEV - float percent0 = 100.f * sum[0] / pixelcount; - float percent1 = 100.f * sum[1] / pixelcount; - - std::cout << fileName << " : Green detections at stddev " << std::setprecision( 2 ) << bayerParams.pixelShiftStddevFactorGreen << " : Frame 1/3 : " << std::setprecision( 6 ) << sum[0] << " (" << percent0 << "%)" << " Frame 2/4 : " << sum[1] << " (" << percent1 << "%)" << std::endl; -#endif - - if(adaptive && nOf3x3) { if(blurMap) { +#ifdef _OPENMP #pragma omp parallel +#endif { gaussianBlur(psMask, psMask, winw, winh, sigma); } } - array2D mask(W, H, ARRAY2D_CLEAR_DATA); + array2D mask(winw, winh, ARRAY2D_CLEAR_DATA); +#ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) +#endif for(int i = winy + border - offsY; i < winh - (border + offsY); ++i) { int j = winx + border - offsX; @@ -1420,18 +806,20 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA } if(holeFill) { - array2D maskInv(W, H); + array2D maskInv(winw, winh); invertMask(winx + border - offsX, winw - (border + offsX), winy + border - offsY, winh - (border + offsY), mask, maskInv); floodFill4(winx + border - offsX, winw - (border + offsX), winy + border - offsY, winh - (border + offsY), maskInv); xorMasks(winx + border - offsX, winw - (border + offsX), winy + border - offsY, winh - (border + offsY), maskInv, mask); } - +#ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) +#endif for(int i = winy + border - offsY; i < winh - (border + offsY); ++i) { #ifdef __SSE2__ + // pow() is expensive => precalculate blend factor using SSE if(smoothTransitions) { // vfloat onev = F2V(1.f); vfloat smoothv = F2V(smoothFactor); @@ -1454,29 +842,66 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, const RA float *redDest = red[i + offsY]; float *blueDest = blue[i + offsY]; - for(int j = winx + border - offsX; j < winw - (border + offsX); ++j) { + // offset to keep the code short. It changes its value between 0 and 1 for each iteration of the loop + unsigned int offset = FC(i, winx + border - offsX) & 1; + + for(int j = winx + border - offsX; j < winw - (border + offsX); ++j, offset ^= 1) { if(mask[i][j] == 255) { - paintMotionMask(j + offsX, showMotion, 0.5f, showOnlyMask, greenDest, redDest, blueDest); + paintMotionMask(j + offsX, showMotion, showOnlyMask, greenDest, redDest, blueDest); } else if(showOnlyMask) { // we want only motion mask => paint areas without motion in pure black redDest[j + offsX] = greenDest[j + offsX] = blueDest[j + offsX] = 0.f; } else { if(smoothTransitions) { #ifdef __SSE2__ + // use precalculated blend factor const float blend = psMask[i][j]; #else const float blend = smoothFactor == 0.f ? 1.f : pow_F(std::max(psMask[i][j] - 1.f, 0.f), smoothFactor); #endif redDest[j + offsX] = intp(blend, redDest[j + offsX], psRed[i][j] ); - greenDest[j + offsX] = intp(blend, greenDest[j + offsX], (psG1[i][j] + psG2[i][j]) * 0.5f); + greenDest[j + offsX] = intp(blend, greenDest[j + offsX], ((*rawDataFrames[1 - offset])[i - offset + 1][j] * greenBrightness[1 - offset] + (*rawDataFrames[3 - offset])[i + offset][j + 1] * greenBrightness[3 - offset]) * 0.5f); blueDest[j + offsX] = intp(blend, blueDest[j + offsX], psBlue[i][j]); } else { redDest[j + offsX] = psRed[i][j]; - greenDest[j + offsX] = (psG1[i][j] + psG2[i][j]) * 0.5f; + greenDest[j + offsX] = ((*rawDataFrames[1 - offset])[i - offset + 1][j] * greenBrightness[1 - offset] + (*rawDataFrames[3 - offset])[i + offset][j + 1] * greenBrightness[3 - offset]) * 0.5f; blueDest[j + offsX] = psBlue[i][j]; } } } } + } else { + // motion detection off => combine the 4 raw frames + float ngbright[2][4] = {{redBrightness[0], redBrightness[1], redBrightness[2], redBrightness[3]}, + {blueBrightness[0], blueBrightness[1], blueBrightness[2], blueBrightness[3]} + }; +#ifdef _OPENMP + #pragma omp parallel for schedule(dynamic,16) +#endif + + for(int i = winy + 1; i < winh - 1; ++i) { + float *nonGreenDest0 = red[i]; + float *nonGreenDest1 = blue[i]; + int ng = 0; + int j = winx + 1; + int c = FC(i, j); + + if((c + FC(i, j + 1)) == 3) { + // row with blue pixels => swap destination pointers for non green pixels + std::swap(nonGreenDest0, nonGreenDest1); + ng ^= 1; + } + + // offset to keep the code short. It changes its value between 0 and 1 for each iteration of the loop + unsigned int offset = c & 1; + + for(; j < winw - 1; ++j) { + // set red, green and blue values + green[i][j] = ((*rawDataFrames[1 - offset])[i - offset + 1][j] * greenBrightness[1 - offset] + (*rawDataFrames[3 - offset])[i + offset][j + 1] * greenBrightness[3 - offset]) * 0.5f; + nonGreenDest0[j] = (*rawDataFrames[(offset << 1) + offset])[i][j + offset] * ngbright[ng][(offset << 1) + offset]; + nonGreenDest1[j] = (*rawDataFrames[2 - offset])[i + 1][j - offset + 1] * ngbright[ng ^ 1][2 - offset]; + offset ^= 1; // 0 => 1 or 1 => 0 + } + } } if(plistener) { diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index d8dc7eb1d..7b6ee8782 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -39,6 +39,7 @@ RawImage::~RawImage() { if(ifp) { fclose(ifp); + ifp = nullptr; } if( image ) { @@ -410,7 +411,11 @@ int RawImage::loadRaw (bool loadData, unsigned int imageNum, bool closeFile, Pro verbose = settings->verbose; oprof = nullptr; - ifp = gfopen (ifname); // Maps to either file map or direct fopen + if(!ifp) { + ifp = gfopen (ifname); // Maps to either file map or direct fopen + } else { + fseek (ifp, 0, SEEK_SET); + } if (!ifp) { return 3; diff --git a/rtengine/rt_math.h b/rtengine/rt_math.h index 6e1138476..17a292618 100644 --- a/rtengine/rt_math.h +++ b/rtengine/rt_math.h @@ -87,6 +87,13 @@ constexpr T CLIP(const T& a) return LIM(a, static_cast(0), static_cast(MAXVAL)); } +template +constexpr T SGN(const T& a) +{ + // returns -1 for a < 0, 0 for a = 0 and +1 for a > 0 + return (T(0) < a) - (a < T(0)); +} + template constexpr T intp(T a, T b, T c) { diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index af7ab983b..3a37996a0 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -102,7 +102,6 @@ BatchQueuePanel::BatchQueuePanel (FileCatalog* aFileCatalog) #else outdirFolder = Gtk::manage (new MyFileChooserButton (M("PREFERENCES_OUTDIRFOLDER"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER)); hb3->pack_start (*outdirFolder); - outdirFolder->signal_current_folder_changed().connect (sigc::mem_fun(*this, &BatchQueuePanel::pathFolderChanged)); outdirFolder->signal_selection_changed().connect (sigc::mem_fun(*this, &BatchQueuePanel::pathFolderChanged)); outdirFolder->set_tooltip_markup (M("PREFERENCES_OUTDIRFOLDERHINT")); diff --git a/rtgui/colorappearance.cc b/rtgui/colorappearance.cc index cdcfb10f2..59bdb4b31 100644 --- a/rtgui/colorappearance.cc +++ b/rtgui/colorappearance.cc @@ -24,12 +24,12 @@ using namespace rtengine; using namespace rtengine::procparams; -ColorAppearance::ColorAppearance () : FoldableToolPanel(this, "colorappearance", M("TP_COLORAPP_LABEL"), false, true) +ColorAppearance::ColorAppearance () : FoldableToolPanel (this, "colorappearance", M ("TP_COLORAPP_LABEL"), false, true) { - CurveListener::setMulti(true); + CurveListener::setMulti (true); std::vector milestones; - milestones.push_back( GradientMilestone(0., 0., 0., 0.) ); - milestones.push_back( GradientMilestone(1., 1., 1., 1.) ); + milestones.push_back ( GradientMilestone (0., 0., 0., 0.) ); + milestones.push_back ( GradientMilestone (1., 1., 1., 1.) ); // ------------------------ Process #1: Converting to CIECAM @@ -40,51 +40,51 @@ ColorAppearance::ColorAppearance () : FoldableToolPanel(this, "colorappearance", // Vertical box container for the content of the Process 1 frame Gtk::VBox *p1VBox; - p1Frame = Gtk::manage (new Gtk::Frame(M("TP_COLORAPP_LABEL_SCENE")) ); - p1Frame->set_label_align(0.025, 0.5); + p1Frame = Gtk::manage (new Gtk::Frame (M ("TP_COLORAPP_LABEL_SCENE")) ); + p1Frame->set_label_align (0.025, 0.5); p1VBox = Gtk::manage ( new Gtk::VBox()); - p1VBox->set_spacing(2); + p1VBox->set_spacing (2); - degree = Gtk::manage (new Adjuster (M("TP_COLORAPP_CIECAT_DEGREE"), 0., 100., 1., 100.)); + degree = Gtk::manage (new Adjuster (M ("TP_COLORAPP_CIECAT_DEGREE"), 0., 100., 1., 100.)); if (degree->delay < options.adjusterMaxDelay) { degree->delay = options.adjusterMaxDelay; } degree->throwOnButtonRelease(); - degree->addAutoButton(M("TP_COLORAPP_DEGREE_AUTO_TOOLTIP")); - degree->set_tooltip_markup (M("TP_COLORAPP_DEGREE_TOOLTIP")); + degree->addAutoButton (M ("TP_COLORAPP_DEGREE_AUTO_TOOLTIP")); + degree->set_tooltip_markup (M ("TP_COLORAPP_DEGREE_TOOLTIP")); p1VBox->pack_start (*degree); - surrsource = Gtk::manage (new Gtk::CheckButton (M("TP_COLORAPP_SURSOURCE"))); - surrsource->set_tooltip_markup (M("TP_COLORAPP_SURSOURCE_TOOLTIP")); + surrsource = Gtk::manage (new Gtk::CheckButton (M ("TP_COLORAPP_SURSOURCE"))); + surrsource->set_tooltip_markup (M ("TP_COLORAPP_SURSOURCE_TOOLTIP")); p1VBox->pack_start (*surrsource, Gtk::PACK_SHRINK); Gtk::HBox* wbmHBox = Gtk::manage (new Gtk::HBox ()); wbmHBox->set_spacing (2); - wbmHBox->set_tooltip_markup (M("TP_COLORAPP_MODEL_TOOLTIP")); - Gtk::Label* wbmLab = Gtk::manage (new Gtk::Label (M("TP_COLORAPP_MODEL") + ":")); + wbmHBox->set_tooltip_markup (M ("TP_COLORAPP_MODEL_TOOLTIP")); + Gtk::Label* wbmLab = Gtk::manage (new Gtk::Label (M ("TP_COLORAPP_MODEL") + ":")); wbmHBox->pack_start (*wbmLab, Gtk::PACK_SHRINK); wbmodel = Gtk::manage (new MyComboBoxText ()); - wbmodel->append (M("TP_COLORAPP_WBRT")); - wbmodel->append (M("TP_COLORAPP_WBCAM")); + wbmodel->append (M ("TP_COLORAPP_WBRT")); + wbmodel->append (M ("TP_COLORAPP_WBCAM")); wbmodel->set_active (0); wbmHBox->pack_start (*wbmodel); p1VBox->pack_start (*wbmHBox); - adapscen = Gtk::manage (new Adjuster (M("TP_COLORAPP_ADAPTSCENE"), 0.001, 16384., 0.001, 2000.));// EV -7 ==> EV 17 + adapscen = Gtk::manage (new Adjuster (M ("TP_COLORAPP_ADAPTSCENE"), 0.001, 16384., 0.001, 2000.)); // EV -7 ==> EV 17 if (adapscen->delay < options.adjusterMaxDelay) { adapscen->delay = options.adjusterMaxDelay; } adapscen->throwOnButtonRelease(); - adapscen->addAutoButton(M("TP_COLORAPP_ADAP_AUTO_TOOLTIP")); - adapscen->set_tooltip_markup (M("TP_COLORAPP_ADAPTSCENE_TOOLTIP")); + adapscen->addAutoButton (M ("TP_COLORAPP_ADAP_AUTO_TOOLTIP")); + adapscen->set_tooltip_markup (M ("TP_COLORAPP_ADAPTSCENE_TOOLTIP")); p1VBox->pack_start (*adapscen); - p1Frame->add(*p1VBox); + p1Frame->add (*p1VBox); pack_start (*p1Frame, Gtk::PACK_EXPAND_WIDGET, 4); @@ -96,123 +96,123 @@ ColorAppearance::ColorAppearance () : FoldableToolPanel(this, "colorappearance", // Vertical box container for the content of the Process 1 frame Gtk::VBox *p2VBox; - p2Frame = Gtk::manage (new Gtk::Frame(M("TP_COLORAPP_LABEL_CAM02")) ); - p2Frame->set_label_align(0.025, 0.5); + p2Frame = Gtk::manage (new Gtk::Frame (M ("TP_COLORAPP_LABEL_CAM02")) ); + p2Frame->set_label_align (0.025, 0.5); p2VBox = Gtk::manage ( new Gtk::VBox()); - p2VBox->set_spacing(2); + p2VBox->set_spacing (2); Gtk::HBox* alHBox = Gtk::manage (new Gtk::HBox ()); alHBox->set_spacing (2); - alHBox->set_tooltip_markup (M("TP_COLORAPP_ALGO_TOOLTIP")); - Gtk::Label* alLabel = Gtk::manage (new Gtk::Label (M("TP_COLORAPP_ALGO") + ":")); + alHBox->set_tooltip_markup (M ("TP_COLORAPP_ALGO_TOOLTIP")); + Gtk::Label* alLabel = Gtk::manage (new Gtk::Label (M ("TP_COLORAPP_ALGO") + ":")); alHBox->pack_start (*alLabel, Gtk::PACK_SHRINK); algo = Gtk::manage (new MyComboBoxText ()); - algo->append (M("TP_COLORAPP_ALGO_JC")); - algo->append (M("TP_COLORAPP_ALGO_JS")); - algo->append (M("TP_COLORAPP_ALGO_QM")); - algo->append (M("TP_COLORAPP_ALGO_ALL")); + algo->append (M ("TP_COLORAPP_ALGO_JC")); + algo->append (M ("TP_COLORAPP_ALGO_JS")); + algo->append (M ("TP_COLORAPP_ALGO_QM")); + algo->append (M ("TP_COLORAPP_ALGO_ALL")); algo->set_active (0); alHBox->pack_start (*algo); p2VBox->pack_start (*alHBox); p2VBox->pack_start (*Gtk::manage (new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET, 4); - jlight = Gtk::manage (new Adjuster (M("TP_COLORAPP_LIGHT"), -100.0, 100.0, 0.1, 0.)); + jlight = Gtk::manage (new Adjuster (M ("TP_COLORAPP_LIGHT"), -100.0, 100.0, 0.1, 0.)); if (jlight->delay < options.adjusterMaxDelay) { jlight->delay = options.adjusterMaxDelay; } jlight->throwOnButtonRelease(); - jlight->set_tooltip_markup (M("TP_COLORAPP_LIGHT_TOOLTIP")); + jlight->set_tooltip_markup (M ("TP_COLORAPP_LIGHT_TOOLTIP")); p2VBox->pack_start (*jlight); - qbright = Gtk::manage (new Adjuster (M("TP_COLORAPP_BRIGHT"), -100.0, 100.0, 0.1, 0.)); + qbright = Gtk::manage (new Adjuster (M ("TP_COLORAPP_BRIGHT"), -100.0, 100.0, 0.1, 0.)); if (qbright->delay < options.adjusterMaxDelay) { qbright->delay = options.adjusterMaxDelay; } qbright->throwOnButtonRelease(); - qbright->set_tooltip_markup (M("TP_COLORAPP_BRIGHT_TOOLTIP")); + qbright->set_tooltip_markup (M ("TP_COLORAPP_BRIGHT_TOOLTIP")); p2VBox->pack_start (*qbright); - chroma = Gtk::manage (new Adjuster (M("TP_COLORAPP_CHROMA"), -100.0, 100.0, 0.1, 0.)); + chroma = Gtk::manage (new Adjuster (M ("TP_COLORAPP_CHROMA"), -100.0, 100.0, 0.1, 0.)); if (chroma->delay < options.adjusterMaxDelay) { chroma->delay = options.adjusterMaxDelay; } chroma->throwOnButtonRelease(); - chroma->set_tooltip_markup (M("TP_COLORAPP_CHROMA_TOOLTIP")); + chroma->set_tooltip_markup (M ("TP_COLORAPP_CHROMA_TOOLTIP")); p2VBox->pack_start (*chroma); - schroma = Gtk::manage (new Adjuster (M("TP_COLORAPP_CHROMA_S"), -100.0, 100.0, 0.1, 0.)); + schroma = Gtk::manage (new Adjuster (M ("TP_COLORAPP_CHROMA_S"), -100.0, 100.0, 0.1, 0.)); if (schroma->delay < options.adjusterMaxDelay) { schroma->delay = options.adjusterMaxDelay; } schroma->throwOnButtonRelease(); - schroma->set_tooltip_markup (M("TP_COLORAPP_CHROMA_S_TOOLTIP")); + schroma->set_tooltip_markup (M ("TP_COLORAPP_CHROMA_S_TOOLTIP")); p2VBox->pack_start (*schroma); - mchroma = Gtk::manage (new Adjuster (M("TP_COLORAPP_CHROMA_M"), -100.0, 100.0, 0.1, 0.)); + mchroma = Gtk::manage (new Adjuster (M ("TP_COLORAPP_CHROMA_M"), -100.0, 100.0, 0.1, 0.)); if (mchroma->delay < options.adjusterMaxDelay) { mchroma->delay = options.adjusterMaxDelay; } mchroma->throwOnButtonRelease(); - mchroma->set_tooltip_markup (M("TP_COLORAPP_CHROMA_M_TOOLTIP")); + mchroma->set_tooltip_markup (M ("TP_COLORAPP_CHROMA_M_TOOLTIP")); p2VBox->pack_start (*mchroma); - rstprotection = Gtk::manage ( new Adjuster (M("TP_COLORAPP_RSTPRO"), 0., 100., 0.1, 0.) ); + rstprotection = Gtk::manage ( new Adjuster (M ("TP_COLORAPP_RSTPRO"), 0., 100., 0.1, 0.) ); if (rstprotection->delay < options.adjusterMaxDelay) { rstprotection->delay = options.adjusterMaxDelay; } rstprotection->throwOnButtonRelease(); - rstprotection->set_tooltip_markup (M("TP_COLORAPP_RSTPRO_TOOLTIP")); + rstprotection->set_tooltip_markup (M ("TP_COLORAPP_RSTPRO_TOOLTIP")); p2VBox->pack_start (*rstprotection); - contrast = Gtk::manage (new Adjuster (M("TP_COLORAPP_CONTRAST"), -100.0, 100.0, 0.1, 0.)); + contrast = Gtk::manage (new Adjuster (M ("TP_COLORAPP_CONTRAST"), -100.0, 100.0, 0.1, 0.)); if (contrast->delay < options.adjusterMaxDelay) { contrast->delay = options.adjusterMaxDelay; } contrast->throwOnButtonRelease(); - contrast->set_tooltip_markup (M("TP_COLORAPP_CONTRAST_TOOLTIP")); + contrast->set_tooltip_markup (M ("TP_COLORAPP_CONTRAST_TOOLTIP")); p2VBox->pack_start (*contrast); - qcontrast = Gtk::manage (new Adjuster (M("TP_COLORAPP_CONTRAST_Q"), -100.0, 100.0, 0.1, 0.)); + qcontrast = Gtk::manage (new Adjuster (M ("TP_COLORAPP_CONTRAST_Q"), -100.0, 100.0, 0.1, 0.)); if (qcontrast->delay < options.adjusterMaxDelay) { qcontrast->delay = options.adjusterMaxDelay; } qcontrast->throwOnButtonRelease(); - qcontrast->set_tooltip_markup (M("TP_COLORAPP_CONTRAST_Q_TOOLTIP")); + qcontrast->set_tooltip_markup (M ("TP_COLORAPP_CONTRAST_Q_TOOLTIP")); p2VBox->pack_start (*qcontrast); - colorh = Gtk::manage (new Adjuster (M("TP_COLORAPP_HUE"), -100.0, 100.0, 0.1, 0.)); + colorh = Gtk::manage (new Adjuster (M ("TP_COLORAPP_HUE"), -100.0, 100.0, 0.1, 0.)); if (colorh->delay < options.adjusterMaxDelay) { colorh->delay = options.adjusterMaxDelay; } colorh->throwOnButtonRelease(); - colorh->set_tooltip_markup (M("TP_COLORAPP_HUE_TOOLTIP")); + colorh->set_tooltip_markup (M ("TP_COLORAPP_HUE_TOOLTIP")); p2VBox->pack_start (*colorh); - tonecie = Gtk::manage (new Gtk::CheckButton (M("TP_COLORAPP_TONECIE"))); - tonecie->set_tooltip_markup (M("TP_COLORAPP_TONECIE_TOOLTIP")); - tonecieconn = tonecie->signal_toggled().connect( sigc::mem_fun(*this, &ColorAppearance::tonecie_toggled) ); + tonecie = Gtk::manage (new Gtk::CheckButton (M ("TP_COLORAPP_TONECIE"))); + tonecie->set_tooltip_markup (M ("TP_COLORAPP_TONECIE_TOOLTIP")); + tonecieconn = tonecie->signal_toggled().connect ( sigc::mem_fun (*this, &ColorAppearance::tonecie_toggled) ); p2VBox->pack_start (*tonecie); /* sharpcie = Gtk::manage (new Gtk::CheckButton (M("TP_COLORAPP_SHARPCIE"))); @@ -223,52 +223,52 @@ ColorAppearance::ColorAppearance () : FoldableToolPanel(this, "colorappearance", p2VBox->pack_start (*Gtk::manage (new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET, 4); toneCurveMode = Gtk::manage (new MyComboBoxText ()); - toneCurveMode->append (M("TP_COLORAPP_TCMODE_LIGHTNESS")); - toneCurveMode->append (M("TP_COLORAPP_TCMODE_BRIGHTNESS")); + toneCurveMode->append (M ("TP_COLORAPP_TCMODE_LIGHTNESS")); + toneCurveMode->append (M ("TP_COLORAPP_TCMODE_BRIGHTNESS")); toneCurveMode->set_active (0); - toneCurveMode->set_tooltip_text(M("TP_COLORAPP_TCMODE_LABEL1")); + toneCurveMode->set_tooltip_text (M ("TP_COLORAPP_TCMODE_LABEL1")); - curveEditorG = new CurveEditorGroup (options.lastToneCurvesDir, M("TP_COLORAPP_CURVEEDITOR1")); + curveEditorG = new CurveEditorGroup (options.lastToneCurvesDir, M ("TP_COLORAPP_CURVEEDITOR1")); curveEditorG->setCurveListener (this); - curveEditorG->setTooltip(M("TP_COLORAPP_CURVEEDITOR1_TOOLTIP")); + curveEditorG->setTooltip (M ("TP_COLORAPP_CURVEEDITOR1_TOOLTIP")); - shape = static_cast(curveEditorG->addCurve(CT_Diagonal, "", toneCurveMode)); + shape = static_cast (curveEditorG->addCurve (CT_Diagonal, "", toneCurveMode)); - tcmodeconn = toneCurveMode->signal_changed().connect( sigc::mem_fun(*this, &ColorAppearance::curveMode1Changed), true ); + tcmodeconn = toneCurveMode->signal_changed().connect ( sigc::mem_fun (*this, &ColorAppearance::curveMode1Changed), true ); toneCurveMode2 = Gtk::manage (new MyComboBoxText ()); - toneCurveMode2->append (M("TP_COLORAPP_TCMODE_LIGHTNESS")); - toneCurveMode2->append (M("TP_COLORAPP_TCMODE_BRIGHTNESS")); + toneCurveMode2->append (M ("TP_COLORAPP_TCMODE_LIGHTNESS")); + toneCurveMode2->append (M ("TP_COLORAPP_TCMODE_BRIGHTNESS")); toneCurveMode2->set_active (0); - toneCurveMode2->set_tooltip_text(M("TP_COLORAPP_TCMODE_LABEL2")); + toneCurveMode2->set_tooltip_text (M ("TP_COLORAPP_TCMODE_LABEL2")); - curveEditorG2 = new CurveEditorGroup (options.lastToneCurvesDir, M("TP_COLORAPP_CURVEEDITOR2")); + curveEditorG2 = new CurveEditorGroup (options.lastToneCurvesDir, M ("TP_COLORAPP_CURVEEDITOR2")); curveEditorG2->setCurveListener (this); - shape2 = static_cast(curveEditorG2->addCurve(CT_Diagonal, "", toneCurveMode2)); + shape2 = static_cast (curveEditorG2->addCurve (CT_Diagonal, "", toneCurveMode2)); - tcmode2conn = toneCurveMode2->signal_changed().connect( sigc::mem_fun(*this, &ColorAppearance::curveMode2Changed), true ); + tcmode2conn = toneCurveMode2->signal_changed().connect ( sigc::mem_fun (*this, &ColorAppearance::curveMode2Changed), true ); toneCurveMode3 = Gtk::manage (new MyComboBoxText ()); - toneCurveMode3->append (M("TP_COLORAPP_TCMODE_CHROMA")); - toneCurveMode3->append (M("TP_COLORAPP_TCMODE_SATUR")); - toneCurveMode3->append (M("TP_COLORAPP_TCMODE_COLORF")); + toneCurveMode3->append (M ("TP_COLORAPP_TCMODE_CHROMA")); + toneCurveMode3->append (M ("TP_COLORAPP_TCMODE_SATUR")); + toneCurveMode3->append (M ("TP_COLORAPP_TCMODE_COLORF")); toneCurveMode3->set_active (0); - toneCurveMode3->set_tooltip_text(M("TP_COLORAPP_TCMODE_LABEL3")); + toneCurveMode3->set_tooltip_text (M ("TP_COLORAPP_TCMODE_LABEL3")); - curveEditorG3 = new CurveEditorGroup (options.lastToneCurvesDir, M("TP_COLORAPP_CURVEEDITOR3")); + curveEditorG3 = new CurveEditorGroup (options.lastToneCurvesDir, M ("TP_COLORAPP_CURVEEDITOR3")); curveEditorG3->setCurveListener (this); - shape3 = static_cast(curveEditorG3->addCurve(CT_Diagonal, "", toneCurveMode3)); - shape3->setRangeLabels( - M("TP_LABCURVE_CURVEEDITOR_CC_RANGE1"), M("TP_LABCURVE_CURVEEDITOR_CC_RANGE2"), - M("TP_LABCURVE_CURVEEDITOR_CC_RANGE3"), M("TP_LABCURVE_CURVEEDITOR_CC_RANGE4") + shape3 = static_cast (curveEditorG3->addCurve (CT_Diagonal, "", toneCurveMode3)); + shape3->setRangeLabels ( + M ("TP_LABCURVE_CURVEEDITOR_CC_RANGE1"), M ("TP_LABCURVE_CURVEEDITOR_CC_RANGE2"), + M ("TP_LABCURVE_CURVEEDITOR_CC_RANGE3"), M ("TP_LABCURVE_CURVEEDITOR_CC_RANGE4") ); - shape3->setBottomBarColorProvider(this, 1); - shape3->setLeftBarColorProvider(this, 1); - shape3->setRangeDefaultMilestones(0.05, 0.2, 0.58); + shape3->setBottomBarColorProvider (this, 1); + shape3->setLeftBarColorProvider (this, 1); + shape3->setRangeDefaultMilestones (0.05, 0.2, 0.58); // shape3->setBottomBarColorProvider(this, 2); @@ -278,51 +278,51 @@ ColorAppearance::ColorAppearance () : FoldableToolPanel(this, "colorappearance", // The milestones are still the same than those define above //milestones.push_back( GradientMilestone(0., 0., 0., 0.) ); //milestones.push_back( GradientMilestone(1., 1., 1., 1.) ); - shape->setBottomBarBgGradient(milestones); - shape->setLeftBarBgGradient(milestones); - shape2->setBottomBarBgGradient(milestones); - shape2->setLeftBarBgGradient(milestones); + shape->setBottomBarBgGradient (milestones); + shape->setLeftBarBgGradient (milestones); + shape2->setBottomBarBgGradient (milestones); + shape2->setLeftBarBgGradient (milestones); std::vector shape3Milestones; float R, G, B; for (int i = 0; i < 7; i++) { - float x = float(i) * (1.0f / 6.0); - Color::hsv2rgb01(x, 0.5f, 0.5f, R, G, B); - shape3Milestones.push_back( GradientMilestone(double(x), double(R), double(G), double(B)) ); + float x = float (i) * (1.0f / 6.0); + Color::hsv2rgb01 (x, 0.5f, 0.5f, R, G, B); + shape3Milestones.push_back ( GradientMilestone (double (x), double (R), double (G), double (B)) ); } - shape3->setBottomBarBgGradient(shape3Milestones); - shape3->setLeftBarBgGradient(shape3Milestones); + shape3->setBottomBarBgGradient (shape3Milestones); + shape3->setLeftBarBgGradient (shape3Milestones); - shape3->setRangeDefaultMilestones(0.05, 0.2, 0.58); + shape3->setRangeDefaultMilestones (0.05, 0.2, 0.58); curveEditorG->curveListComplete(); curveEditorG2->curveListComplete(); - curveEditorG2->setTooltip(M("TP_COLORAPP_CURVEEDITOR2_TOOLTIP")); + curveEditorG2->setTooltip (M ("TP_COLORAPP_CURVEEDITOR2_TOOLTIP")); curveEditorG3->curveListComplete(); - curveEditorG3->setTooltip(M("TP_COLORAPP_CURVEEDITOR3_TOOLTIP")); - tcmode3conn = toneCurveMode3->signal_changed().connect( sigc::mem_fun(*this, &ColorAppearance::curveMode3Changed), true ); + curveEditorG3->setTooltip (M ("TP_COLORAPP_CURVEEDITOR3_TOOLTIP")); + tcmode3conn = toneCurveMode3->signal_changed().connect ( sigc::mem_fun (*this, &ColorAppearance::curveMode3Changed), true ); - p2VBox->pack_start( *curveEditorG, Gtk::PACK_SHRINK, 2); - p2VBox->pack_start( *curveEditorG2, Gtk::PACK_SHRINK, 2); - p2VBox->pack_start( *curveEditorG3, Gtk::PACK_SHRINK, 2); + p2VBox->pack_start ( *curveEditorG, Gtk::PACK_SHRINK, 2); + p2VBox->pack_start ( *curveEditorG2, Gtk::PACK_SHRINK, 2); + p2VBox->pack_start ( *curveEditorG3, Gtk::PACK_SHRINK, 2); // ------------------------ Choice CIECAM data - datacie = Gtk::manage (new Gtk::CheckButton (M("TP_COLORAPP_DATACIE"))); - datacie->set_tooltip_markup (M("TP_COLORAPP_DATACIE_TOOLTIP")); - datacieconn = datacie->signal_toggled().connect( sigc::mem_fun(*this, &ColorAppearance::datacie_toggled) ); + datacie = Gtk::manage (new Gtk::CheckButton (M ("TP_COLORAPP_DATACIE"))); + datacie->set_tooltip_markup (M ("TP_COLORAPP_DATACIE_TOOLTIP")); + datacieconn = datacie->signal_toggled().connect ( sigc::mem_fun (*this, &ColorAppearance::datacie_toggled) ); p2VBox->pack_start (*datacie); //------------------------- - p2Frame->add(*p2VBox); + p2Frame->add (*p2VBox); pack_start (*p2Frame, Gtk::PACK_EXPAND_WIDGET, 4); @@ -337,46 +337,46 @@ ColorAppearance::ColorAppearance () : FoldableToolPanel(this, "colorappearance", // Vertical box container for the content of the Process 3 frame Gtk::VBox *p3VBox; - p3Frame = Gtk::manage (new Gtk::Frame(M("TP_COLORAPP_LABEL_VIEWING")) ); // "Editing viewing conditions" ??? - p3Frame->set_label_align(0.025, 0.5); + p3Frame = Gtk::manage (new Gtk::Frame (M ("TP_COLORAPP_LABEL_VIEWING")) ); // "Editing viewing conditions" ??? + p3Frame->set_label_align (0.025, 0.5); p3VBox = Gtk::manage ( new Gtk::VBox()); - p3VBox->set_spacing(2); + p3VBox->set_spacing (2); - adaplum = Gtk::manage (new Adjuster (M("TP_COLORAPP_ADAPTVIEWING"), 0.1, 1000., 0.1, 16.)); + adaplum = Gtk::manage (new Adjuster (M ("TP_COLORAPP_ADAPTVIEWING"), 0.1, 1000., 0.1, 16.)); if (adaplum->delay < options.adjusterMaxDelay) { adaplum->delay = options.adjusterMaxDelay; } adaplum->throwOnButtonRelease(); - adaplum->set_tooltip_markup (M("TP_COLORAPP_ADAPTVIEWING_TOOLTIP")); + adaplum->set_tooltip_markup (M ("TP_COLORAPP_ADAPTVIEWING_TOOLTIP")); p3VBox->pack_start (*adaplum); Gtk::HBox* surrHBox = Gtk::manage (new Gtk::HBox ()); surrHBox->set_spacing (2); - surrHBox->set_tooltip_markup(M("TP_COLORAPP_SURROUND_TOOLTIP")); - Gtk::Label* surrLabel = Gtk::manage (new Gtk::Label (M("TP_COLORAPP_SURROUND") + ":")); + surrHBox->set_tooltip_markup (M ("TP_COLORAPP_SURROUND_TOOLTIP")); + Gtk::Label* surrLabel = Gtk::manage (new Gtk::Label (M ("TP_COLORAPP_SURROUND") + ":")); surrHBox->pack_start (*surrLabel, Gtk::PACK_SHRINK); surround = Gtk::manage (new MyComboBoxText ()); - surround->append (M("TP_COLORAPP_SURROUND_AVER")); - surround->append (M("TP_COLORAPP_SURROUND_DIM")); - surround->append (M("TP_COLORAPP_SURROUND_DARK")); - surround->append (M("TP_COLORAPP_SURROUND_EXDARK")); + surround->append (M ("TP_COLORAPP_SURROUND_AVER")); + surround->append (M ("TP_COLORAPP_SURROUND_DIM")); + surround->append (M ("TP_COLORAPP_SURROUND_DARK")); + surround->append (M ("TP_COLORAPP_SURROUND_EXDARK")); surround->set_active (1); surrHBox->pack_start (*surround); p3VBox->pack_start (*surrHBox); - p3Frame->add(*p3VBox); + p3Frame->add (*p3VBox); pack_start (*p3Frame, Gtk::PACK_EXPAND_WIDGET, 4); // ------------------------ Lab Gamut control - gamut = Gtk::manage (new Gtk::CheckButton (M("TP_COLORAPP_GAMUT"))); - gamut->set_tooltip_markup (M("TP_COLORAPP_GAMUT_TOOLTIP")); - gamutconn = gamut->signal_toggled().connect( sigc::mem_fun(*this, &ColorAppearance::gamut_toggled) ); + gamut = Gtk::manage (new Gtk::CheckButton (M ("TP_COLORAPP_GAMUT"))); + gamut->set_tooltip_markup (M ("TP_COLORAPP_GAMUT_TOOLTIP")); + gamutconn = gamut->signal_toggled().connect ( sigc::mem_fun (*this, &ColorAppearance::gamut_toggled) ); pack_start (*gamut, Gtk::PACK_SHRINK); // ------------------------ Bad pixel control @@ -387,23 +387,23 @@ ColorAppearance::ColorAppearance () : FoldableToolPanel(this, "colorappearance", badpixconn = badpix->signal_toggled().connect( sigc::mem_fun(*this, &ColorAppearance::badpix_toggled) ); pack_start (*badpix, Gtk::PACK_SHRINK); */ - badpixsl = Gtk::manage (new Adjuster (M("TP_COLORAPP_BADPIXSL"), 0, 2, 1, 0)); + badpixsl = Gtk::manage (new Adjuster (M ("TP_COLORAPP_BADPIXSL"), 0, 2, 1, 0)); if (badpixsl->delay < options.adjusterMaxDelay) { badpixsl->delay = options.adjusterMaxDelay; } badpixsl->throwOnButtonRelease(); - badpixsl->set_tooltip_markup (M("TP_COLORAPP_BADPIXSL_TOOLTIP")); + badpixsl->set_tooltip_markup (M ("TP_COLORAPP_BADPIXSL_TOOLTIP")); pack_start (*badpixsl, Gtk::PACK_SHRINK); // ------------------------ Listening events - surrconn = surrsource->signal_toggled().connect( sigc::mem_fun(*this, &ColorAppearance::surrsource_toggled) ); - wbmodelconn = wbmodel->signal_changed().connect ( sigc::mem_fun(*this, &ColorAppearance::wbmodelChanged) ); - algoconn = algo->signal_changed().connect ( sigc::mem_fun(*this, &ColorAppearance::algoChanged) ); - surroundconn = surround->signal_changed().connect ( sigc::mem_fun(*this, &ColorAppearance::surroundChanged) ); + surrconn = surrsource->signal_toggled().connect ( sigc::mem_fun (*this, &ColorAppearance::surrsource_toggled) ); + wbmodelconn = wbmodel->signal_changed().connect ( sigc::mem_fun (*this, &ColorAppearance::wbmodelChanged) ); + algoconn = algo->signal_changed().connect ( sigc::mem_fun (*this, &ColorAppearance::algoChanged) ); + surroundconn = surround->signal_changed().connect ( sigc::mem_fun (*this, &ColorAppearance::surroundChanged) ); degree->setAdjusterListener (this); adapscen->setAdjusterListener (this); @@ -433,12 +433,12 @@ ColorAppearance::~ColorAppearance () -bool ColorAppearance::bgTTipQuery(int x, int y, bool keyboard_tooltip, const Glib::RefPtr& tooltip) +bool ColorAppearance::bgTTipQuery (int x, int y, bool keyboard_tooltip, const Glib::RefPtr& tooltip) { return true; } -bool ColorAppearance::srTTipQuery(int x, int y, bool keyboard_tooltip, const Glib::RefPtr& tooltip) +bool ColorAppearance::srTTipQuery (int x, int y, bool keyboard_tooltip, const Glib::RefPtr& tooltip) { return true; } @@ -447,15 +447,15 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited) { disableListener (); - tcmodeconn.block(true); - tcmode2conn.block(true); - tcmode3conn.block(true); + tcmodeconn.block (true); + tcmode2conn.block (true); + tcmode3conn.block (true); shape->setCurve (pp->colorappearance.curve); shape2->setCurve (pp->colorappearance.curve2); shape3->setCurve (pp->colorappearance.curve3); - toneCurveMode->set_active(pp->colorappearance.curveMode); - toneCurveMode2->set_active(pp->colorappearance.curveMode2); - toneCurveMode3->set_active(pp->colorappearance.curveMode3); + toneCurveMode->set_active (pp->colorappearance.curveMode); + toneCurveMode2->set_active (pp->colorappearance.curveMode2); + toneCurveMode3->set_active (pp->colorappearance.curveMode3); curveMode3Changed(); // This will set the correct sensitive state of depending Adjusters if (pedited) { @@ -488,23 +488,23 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited) shape3->setUnChanged (!pedited->colorappearance.curve3); if (!pedited->colorappearance.curveMode) { - toneCurveMode->set_active(2); + toneCurveMode->set_active (2); } if (!pedited->colorappearance.curveMode2) { - toneCurveMode2->set_active(2); + toneCurveMode2->set_active (2); } if (!pedited->colorappearance.curveMode3) { - toneCurveMode3->set_active(3); + toneCurveMode3->set_active (3); } } - setEnabled(pp->colorappearance.enabled); + setEnabled (pp->colorappearance.enabled); - surroundconn.block(true); + surroundconn.block (true); if (pedited && !pedited->colorappearance.surround) { surround->set_active (4); @@ -518,11 +518,11 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited) surround->set_active (3); } - surroundconn.block(false); + surroundconn.block (false); // Have to be manually called to handle initial state update surroundChanged(); - wbmodelconn.block(true); + wbmodelconn.block (true); if (pedited && !pedited->colorappearance.wbmodel) { wbmodel->set_active (2); @@ -532,11 +532,11 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited) wbmodel->set_active (1); } - wbmodelconn.block(false); + wbmodelconn.block (false); // Have to be manually called to handle initial state update wbmodelChanged(); - algoconn.block(true); + algoconn.block (true); if (pedited && !pedited->colorappearance.algo) { algo->set_active (4); @@ -550,7 +550,7 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited) algo->set_active (3); } - algoconn.block(false); + algoconn.block (false); // Have to be manually called to handle initial state update algoChanged(); @@ -584,7 +584,7 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited) lastAutoAdapscen = pp->colorappearance.autoadapscen; degree->setValue (pp->colorappearance.degree); - degree->setAutoValue(pp->colorappearance.autodegree); + degree->setAutoValue (pp->colorappearance.autodegree); adapscen->setValue (pp->colorappearance.adapscen); adapscen->setAutoValue (pp->colorappearance.autoadapscen); @@ -600,9 +600,9 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited) qcontrast->setValue (pp->colorappearance.qcontrast); colorh->setValue (pp->colorappearance.colorh); - tcmode3conn.block(false); - tcmode2conn.block(false); - tcmodeconn.block(false); + tcmode3conn.block (false); + tcmode2conn.block (false); + tcmodeconn.block (false); enableListener (); } void ColorAppearance::autoOpenCurve () @@ -686,9 +686,9 @@ void ColorAppearance::write (ProcParams* pp, ParamsEdited* pedited) pedited->colorappearance.autodegree = !degree->getAutoInconsistent(); pedited->colorappearance.autoadapscen = !adapscen->getAutoInconsistent(); pedited->colorappearance.enabled = !get_inconsistent(); - pedited->colorappearance.surround = surround->get_active_text() != M("GENERAL_UNCHANGED"); - pedited->colorappearance.wbmodel = wbmodel->get_active_text() != M("GENERAL_UNCHANGED"); - pedited->colorappearance.algo = algo->get_active_text() != M("GENERAL_UNCHANGED"); + pedited->colorappearance.surround = surround->get_active_text() != M ("GENERAL_UNCHANGED"); + pedited->colorappearance.wbmodel = wbmodel->get_active_text() != M ("GENERAL_UNCHANGED"); + pedited->colorappearance.algo = algo->get_active_text() != M ("GENERAL_UNCHANGED"); pedited->colorappearance.surrsource = !surrsource->get_inconsistent(); pedited->colorappearance.gamut = !gamut->get_inconsistent(); // pedited->colorappearance.badpix = !badpix->get_inconsistent(); @@ -735,11 +735,11 @@ void ColorAppearance::curveChanged (CurveEditor* ce) if (listener) { if (ce == shape) { - listener->panelChanged (EvCATCurve1, M("HISTORY_CUSTOMCURVE")); + listener->panelChanged (EvCATCurve1, M ("HISTORY_CUSTOMCURVE")); } else if (ce == shape2) { - listener->panelChanged (EvCATCurve2, M("HISTORY_CUSTOMCURVE")); + listener->panelChanged (EvCATCurve2, M ("HISTORY_CUSTOMCURVE")); } else if (ce == shape3) { - listener->panelChanged (EvCATCurve3, M("HISTORY_CUSTOMCURVE")); + listener->panelChanged (EvCATCurve3, M ("HISTORY_CUSTOMCURVE")); } } } @@ -747,7 +747,7 @@ void ColorAppearance::curveChanged (CurveEditor* ce) void ColorAppearance::curveMode1Changed () { if (listener) { - Glib::signal_idle().connect (sigc::mem_fun(*this, &ColorAppearance::curveMode1Changed_)); + Glib::signal_idle().connect (sigc::mem_fun (*this, &ColorAppearance::curveMode1Changed_)); } } @@ -763,7 +763,7 @@ bool ColorAppearance::curveMode1Changed_ () void ColorAppearance::curveMode2Changed () { if (listener) { - Glib::signal_idle().connect (sigc::mem_fun(*this, &ColorAppearance::curveMode2Changed_)); + Glib::signal_idle().connect (sigc::mem_fun (*this, &ColorAppearance::curveMode2Changed_)); } } @@ -781,18 +781,18 @@ void ColorAppearance::curveMode3Changed () int tcMode3 = toneCurveMode3->get_active_row_number(); if (tcMode3 == 0) { - chroma->set_sensitive(true); - schroma->set_sensitive(true); + chroma->set_sensitive (true); + schroma->set_sensitive (true); } else if (tcMode3 == 2) { - chroma->set_sensitive(false); - schroma->set_sensitive(false); + chroma->set_sensitive (false); + schroma->set_sensitive (false); } else if (tcMode3 == 1) { - chroma->set_sensitive(false); - schroma->set_sensitive(true); + chroma->set_sensitive (false); + schroma->set_sensitive (true); } if (listener) { - Glib::signal_idle().connect (sigc::mem_fun(*this, &ColorAppearance::curveMode3Changed_)); + Glib::signal_idle().connect (sigc::mem_fun (*this, &ColorAppearance::curveMode3Changed_)); } } @@ -823,9 +823,9 @@ void ColorAppearance::surrsource_toggled () if (listener) { if (surrsource->get_active ()) { - listener->panelChanged (EvCATsurr, M("GENERAL_ENABLED")); + listener->panelChanged (EvCATsurr, M ("GENERAL_ENABLED")); } else { - listener->panelChanged (EvCATsurr, M("GENERAL_DISABLED")); + listener->panelChanged (EvCATsurr, M ("GENERAL_DISABLED")); } } } @@ -848,9 +848,9 @@ void ColorAppearance::gamut_toggled () if (listener) { if (gamut->get_active ()) { - listener->panelChanged (EvCATgamut, M("GENERAL_ENABLED")); + listener->panelChanged (EvCATgamut, M ("GENERAL_ENABLED")); } else { - listener->panelChanged (EvCATgamut, M("GENERAL_DISABLED")); + listener->panelChanged (EvCATgamut, M ("GENERAL_DISABLED")); } } @@ -899,9 +899,9 @@ void ColorAppearance::datacie_toggled () if (listener) { if (datacie->get_active ()) { - listener->panelChanged (EvCATdatacie, M("GENERAL_ENABLED")); + listener->panelChanged (EvCATdatacie, M ("GENERAL_ENABLED")); } else { - listener->panelChanged (EvCATdatacie, M("GENERAL_DISABLED")); + listener->panelChanged (EvCATdatacie, M ("GENERAL_DISABLED")); } } } @@ -923,9 +923,9 @@ void ColorAppearance::tonecie_toggled () if (listener) { if (tonecie->get_active ()) { - listener->panelChanged (EvCATtonecie, M("GENERAL_ENABLED")); + listener->panelChanged (EvCATtonecie, M ("GENERAL_ENABLED")); } else { - listener->panelChanged (EvCATtonecie, M("GENERAL_DISABLED")); + listener->panelChanged (EvCATtonecie, M ("GENERAL_DISABLED")); } } @@ -1009,12 +1009,12 @@ void ColorAppearance::autoCamChanged (double ccam) { nextCcam = ccam; - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->autoCamComputed_(); + const auto func = [] (gpointer data) -> gboolean { + static_cast (data)->autoCamComputed_(); return FALSE; }; - idle_register.add(func, this); + idle_register.add (func, this); } bool ColorAppearance::autoCamComputed_ () @@ -1032,12 +1032,12 @@ void ColorAppearance::adapCamChanged (double cadap) { nextCadap = cadap; - const auto func = [](gpointer data) -> gboolean { - static_cast(data)->adapCamComputed_(); + const auto func = [] (gpointer data) -> gboolean { + static_cast (data)->adapCamComputed_(); return FALSE; }; - idle_register.add(func, this); + idle_register.add (func, this); } bool ColorAppearance::adapCamComputed_ () @@ -1063,46 +1063,46 @@ void ColorAppearance::colorForValue (double valX, double valY, enum ColorCaller: if (callerId == 1) { // cc - bottom bar - float value = (1.f - 0.7f) * float(valX) + 0.7f; + float value = (1.f - 0.7f) * float (valX) + 0.7f; // whole hue range // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before) - Color::hsv2rgb01(float(valY), float(valX), value, R, G, B); + Color::hsv2rgb01 (float (valY), float (valX), value, R, G, B); } - caller->ccRed = double(R); - caller->ccGreen = double(G); - caller->ccBlue = double(B); + caller->ccRed = double (R); + caller->ccGreen = double (G); + caller->ccBlue = double (B); } void ColorAppearance::adjusterChanged (Adjuster* a, double newval) { if (listener && (multiImage || getEnabled()) ) { - if(a == degree) { + if (a == degree) { listener->panelChanged (EvCATDegree, a->getTextValue()); - } else if(a == adapscen) { + } else if (a == adapscen) { listener->panelChanged (EvCATAdapscen, a->getTextValue()); - } else if(a == adaplum) { + } else if (a == adaplum) { listener->panelChanged (EvCATAdapLum, a->getTextValue()); - } else if(a == badpixsl) { + } else if (a == badpixsl) { listener->panelChanged (EvCATbadpix, a->getTextValue()); - } else if(a == jlight) { + } else if (a == jlight) { listener->panelChanged (EvCATJLight, a->getTextValue()); - } else if(a == qbright) { + } else if (a == qbright) { listener->panelChanged (EvCATQbright, a->getTextValue()); - } else if(a == chroma) { + } else if (a == chroma) { listener->panelChanged (EvCATChroma, a->getTextValue()); - } else if(a == schroma) { + } else if (a == schroma) { listener->panelChanged (EvCATSChroma, a->getTextValue()); - } else if(a == mchroma) { + } else if (a == mchroma) { listener->panelChanged (EvCATMChroma, a->getTextValue()); - } else if(a == rstprotection) { + } else if (a == rstprotection) { listener->panelChanged (EvCATRstpro, a->getTextValue()); - } else if(a == contrast) { + } else if (a == contrast) { listener->panelChanged (EvCATContrast, a->getTextValue()); - } else if(a == colorh) { + } else if (a == colorh) { listener->panelChanged (EvCAThue, a->getTextValue()); - } else if(a == qcontrast) { + } else if (a == qcontrast) { listener->panelChanged (EvCATQContrast, a->getTextValue()); } @@ -1114,19 +1114,19 @@ void ColorAppearance::adjusterAutoToggled (Adjuster* a, bool newval) if (multiImage) { if (degree->getAutoInconsistent()) { - degree->setAutoInconsistent(false); - degree->setAutoValue(false); + degree->setAutoInconsistent (false); + degree->setAutoValue (false); } else if (lastAutoDegree) { - degree->setAutoInconsistent(true); + degree->setAutoInconsistent (true); } lastAutoDegree = degree->getAutoValue(); if (adapscen->getAutoInconsistent()) { - adapscen->setAutoInconsistent(false); - adapscen->setAutoValue(false); + adapscen->setAutoInconsistent (false); + adapscen->setAutoValue (false); } else if (lastAutoAdapscen) { - adapscen->setAutoInconsistent(true); + adapscen->setAutoInconsistent (true); } lastAutoAdapscen = adapscen->getAutoValue(); @@ -1135,23 +1135,23 @@ void ColorAppearance::adjusterAutoToggled (Adjuster* a, bool newval) if (listener && (multiImage || getEnabled()) ) { - if(a == degree) { + if (a == degree) { if (degree->getAutoInconsistent()) { - listener->panelChanged (EvCATAutoDegree, M("GENERAL_UNCHANGED")); + listener->panelChanged (EvCATAutoDegree, M ("GENERAL_UNCHANGED")); } else if (degree->getAutoValue()) { - listener->panelChanged (EvCATAutoDegree, M("GENERAL_ENABLED")); + listener->panelChanged (EvCATAutoDegree, M ("GENERAL_ENABLED")); } else { - listener->panelChanged (EvCATAutoDegree, M("GENERAL_DISABLED")); + listener->panelChanged (EvCATAutoDegree, M ("GENERAL_DISABLED")); } } - if(a == adapscen) { + if (a == adapscen) { if (adapscen->getAutoInconsistent()) { - listener->panelChanged (EvCATAutoAdap, M("GENERAL_UNCHANGED")); + listener->panelChanged (EvCATAutoAdap, M ("GENERAL_UNCHANGED")); } else if (adapscen->getAutoValue()) { - listener->panelChanged (EvCATAutoAdap, M("GENERAL_ENABLED")); + listener->panelChanged (EvCATAutoAdap, M ("GENERAL_ENABLED")); } else { - listener->panelChanged (EvCATAutoAdap, M("GENERAL_DISABLED")); + listener->panelChanged (EvCATAutoAdap, M ("GENERAL_DISABLED")); } } @@ -1163,13 +1163,13 @@ void ColorAppearance::enabledChanged () if (listener) { if (get_inconsistent()) { - listener->panelChanged (EvCATEnabled, M("GENERAL_UNCHANGED")); + listener->panelChanged (EvCATEnabled, M ("GENERAL_UNCHANGED")); } else if (getEnabled()) { - listener->panelChanged (EvCATEnabled, M("GENERAL_ENABLED")); + listener->panelChanged (EvCATEnabled, M ("GENERAL_ENABLED")); curveEditorG->set_sensitive (true); toneCurveMode->set_sensitive (true); } else { - listener->panelChanged (EvCATEnabled, M("GENERAL_DISABLED")); + listener->panelChanged (EvCATEnabled, M ("GENERAL_DISABLED")); } } } @@ -1282,12 +1282,12 @@ void ColorAppearance::setBatchMode (bool batchMode) qcontrast->showEditedCB (); colorh->showEditedCB (); - surround->append (M("GENERAL_UNCHANGED")); - wbmodel->append (M("GENERAL_UNCHANGED")); - algo->append (M("GENERAL_UNCHANGED")); - toneCurveMode->append (M("GENERAL_UNCHANGED")); - toneCurveMode2->append (M("GENERAL_UNCHANGED")); - toneCurveMode3->append (M("GENERAL_UNCHANGED")); + surround->append (M ("GENERAL_UNCHANGED")); + wbmodel->append (M ("GENERAL_UNCHANGED")); + algo->append (M ("GENERAL_UNCHANGED")); + toneCurveMode->append (M ("GENERAL_UNCHANGED")); + toneCurveMode2->append (M ("GENERAL_UNCHANGED")); + toneCurveMode3->append (M ("GENERAL_UNCHANGED")); curveEditorG->setBatchMode (batchMode); curveEditorG2->setBatchMode (batchMode); @@ -1306,35 +1306,35 @@ void ColorAppearance::updateCurveBackgroundHistogram (LUTu & histToneCurve, LUTu void ColorAppearance::setAdjusterBehavior (bool degreeadd, bool adapscenadd, bool adaplumadd, bool badpixsladd, bool jlightadd, bool chromaadd, bool contrastadd, bool rstprotectionadd, bool qbrightadd, bool qcontrastadd, bool schromaadd, bool mchromaadd, bool colorhadd) { - degree->setAddMode(degreeadd); - adapscen->setAddMode(adapscenadd); - adaplum->setAddMode(adaplumadd); - badpixsl->setAddMode(badpixsladd); - jlight->setAddMode(jlightadd); - qbright->setAddMode(qbrightadd); - chroma->setAddMode(chromaadd); - schroma->setAddMode(schromaadd); - mchroma->setAddMode(mchromaadd); - rstprotection->setAddMode(rstprotectionadd); - contrast->setAddMode(contrastadd); - qcontrast->setAddMode(qcontrastadd); - colorh->setAddMode(colorhadd); + degree->setAddMode (degreeadd); + adapscen->setAddMode (adapscenadd); + adaplum->setAddMode (adaplumadd); + badpixsl->setAddMode (badpixsladd); + jlight->setAddMode (jlightadd); + qbright->setAddMode (qbrightadd); + chroma->setAddMode (chromaadd); + schroma->setAddMode (schromaadd); + mchroma->setAddMode (mchromaadd); + rstprotection->setAddMode (rstprotectionadd); + contrast->setAddMode (contrastadd); + qcontrast->setAddMode (qcontrastadd); + colorh->setAddMode (colorhadd); } void ColorAppearance::trimValues (rtengine::procparams::ProcParams* pp) { - degree->trimValue(pp->colorappearance.degree); - adapscen->trimValue(pp->colorappearance.adapscen); - adaplum->trimValue(pp->colorappearance.adaplum); - badpixsl->trimValue(pp->colorappearance.badpixsl); - jlight->trimValue(pp->colorappearance.jlight); - qbright->trimValue(pp->colorappearance.qbright); - chroma->trimValue(pp->colorappearance.chroma); - schroma->trimValue(pp->colorappearance.schroma); - mchroma->trimValue(pp->colorappearance.mchroma); - rstprotection->trimValue(pp->colorappearance.rstprotection); - contrast->trimValue(pp->colorappearance.contrast); - qcontrast->trimValue(pp->colorappearance.qcontrast); - colorh->trimValue(pp->colorappearance.colorh); + degree->trimValue (pp->colorappearance.degree); + adapscen->trimValue (pp->colorappearance.adapscen); + adaplum->trimValue (pp->colorappearance.adaplum); + badpixsl->trimValue (pp->colorappearance.badpixsl); + jlight->trimValue (pp->colorappearance.jlight); + qbright->trimValue (pp->colorappearance.qbright); + chroma->trimValue (pp->colorappearance.chroma); + schroma->trimValue (pp->colorappearance.schroma); + mchroma->trimValue (pp->colorappearance.mchroma); + rstprotection->trimValue (pp->colorappearance.rstprotection); + contrast->trimValue (pp->colorappearance.contrast); + qcontrast->trimValue (pp->colorappearance.qcontrast); + colorh->trimValue (pp->colorappearance.colorh); } diff --git a/rtgui/diagonalcurveeditorsubgroup.cc b/rtgui/diagonalcurveeditorsubgroup.cc index d12cdf023..936bf0d64 100644 --- a/rtgui/diagonalcurveeditorsubgroup.cc +++ b/rtgui/diagonalcurveeditorsubgroup.cc @@ -620,7 +620,9 @@ void DiagonalCurveEditorSubGroup::switchGUI() } else { // dCurve ave a ColorProvider or a background gradient defined, so we create/update the object if (!leftBar) { - leftBar = new ColoredBar(RTO_Bottom2Top); + leftBar = new ColoredBar(RTO_Bottom2Top); + + } if (barColorProvider) { diff --git a/rtgui/extprog.cc b/rtgui/extprog.cc index bdbbb85b4..33424fac9 100644 --- a/rtgui/extprog.cc +++ b/rtgui/extprog.cc @@ -324,7 +324,7 @@ bool ExtProgStore::openInCustomEditor (const Glib::ustring& fileName) #if defined WIN32 const auto cmdLine = Glib::ustring("\"") + options.customEditorProg + Glib::ustring("\""); - auto success = ShellExecute( NULL, "open", cmdLine.c_str(), fileName.c_str(), NULL, SW_SHOWNORMAL ); + auto success = ShellExecute( NULL, "open", cmdLine.c_str(), ('"' + fileName + '"').c_str(), NULL, SW_SHOWNORMAL ); return (uintptr_t)success > 32; #elif defined __APPLE__ diff --git a/rtgui/labcurve.cc b/rtgui/labcurve.cc index dc9e404fb..c39dc99fc 100644 --- a/rtgui/labcurve.cc +++ b/rtgui/labcurve.cc @@ -574,6 +574,21 @@ void LCurve::colorForValue (double valX, double valY, enum ColorCaller::ElemType // whole hue range // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before) Color::hsv2rgb01(float(valY), float(valX), value, R, G, B); + } else if (callerId == 6) { // cc - left bar + + float value = (1.f - 0.7f) * float(valX) + 0.7f; + float hue = (1.14056f - 0.92f) * float(valY) + 0.92f; + + if (hue > 1.0f) { + hue -= 1.0f; + } + + // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before) + Color::hsv2rgb01(hue, float(valX), value, R, G, B); + + // whole hue range + // Y axis / from 0.15 up to 0.75 (arbitrary values; was 0.45 before) + // Color::hsv2rgb01(float(valY), float(valX), value, R, G, B); } else if (callerId == 3) { // lc - bottom bar float value = (1.f - 0.7f) * float(valX) + 0.7f; diff --git a/rtgui/main-cli.cc b/rtgui/main-cli.cc index 91dfc9204..2a2afca63 100644 --- a/rtgui/main-cli.cc +++ b/rtgui/main-cli.cc @@ -425,7 +425,7 @@ int processLineParams( int argc, char **argv ) case 't': outputType = "tif"; - compression = ((currParam.at(2) != 'z') ? 0 : 1); + compression = ((currParam.size() < 3 || currParam.at(2) != 'z') ? 0 : 1); break; case 'n': @@ -549,9 +549,8 @@ int processLineParams( int argc, char **argv ) std::cout << std::endl; #endif std::cout << "Options:" << std::endl; - std::cout << " " << Glib::path_get_basename(argv[0]) << " [-o |-O ] [-s|-S] [-p [-p ...] ] [-d] [ -j[1-100] [-js<1-3>] | [-b<8|16>] [-t[z] | [-n]] ] [-Y] [-f] -c " << std::endl; + std::cout << " " << Glib::path_get_basename(argv[0]) << "[-o |-O ] [-q] [-a] [-s|-S] [-p [-p ...] ] [-d] [ -j[1-100] [-js<1-3>] | [-b<8|16>] [-t[z] | [-n]] ] [-Y] [-f] -c " << std::endl; std::cout << std::endl; - std::cout << " -q Quick Start mode : do not load cached files to speedup start time." << std::endl; std::cout << " -c Specify one or more input files or directory." << std::endl; std::cout << " When specifying directories, Rawtherapee will look for images files that comply with the" << std::endl; std::cout << " selected extensions (see also '-a')." << std::endl; @@ -560,8 +559,9 @@ int processLineParams( int argc, char **argv ) std::cout << " Saves output file alongside input file if -o is not specified." << std::endl; std::cout << " -O | Set output file or folder and copy " << pparamsExt << " file into it." << std::endl; std::cout << " Saves output file alongside input file if -O is not specified." << std::endl; - std::cout << " -a stand for 'all'. When specifying a directory, process all images specified in the" << std::endl; - std::cout << " extension list from the options file, even those currently not seleted" << std::endl; + std::cout << " -q Quick-start mode. Does not load cached files to speedup start time." << std::endl; + std::cout << " -a Process all supported image file types when specifying a folder, even those" << std::endl; + std::cout << " not currently selected in Preferences > File Browser > Parsed Extensions." << std::endl; std::cout << " -s Use the existing sidecar file to build the processing parameters," << std::endl; std::cout << " e.g. for photo.raw there should be a photo.raw." << pparamsExt << " file in the same folder." << std::endl; std::cout << " If the sidecar file does not exist, neutral values will be used." << std::endl; diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index d01d00327..bd5929289 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -518,7 +518,7 @@ Gtk::Widget* Preferences::getProcParamsPanel () mvbpp->pack_start ( *fdf , Gtk::PACK_SHRINK, 4); //dfconn = darkFrameDir->signal_file_set().connect ( sigc::mem_fun(*this, &Preferences::darkFrameChanged), true); - dfconn = darkFrameDir->signal_current_folder_changed().connect ( sigc::mem_fun(*this, &Preferences::darkFrameChanged), true); + dfconn = darkFrameDir->signal_selection_changed().connect ( sigc::mem_fun(*this, &Preferences::darkFrameChanged), true); // FLATFIELD Gtk::Frame* fff = Gtk::manage (new Gtk::Frame (M("PREFERENCES_FLATFIELD")) ); @@ -535,7 +535,7 @@ Gtk::Widget* Preferences::getProcParamsPanel () mvbpp->pack_start ( *fff , Gtk::PACK_SHRINK, 4); //ffconn = flatFieldDir->signal_file_set().connect ( sigc::mem_fun(*this, &Preferences::flatFieldChanged), true); - ffconn = flatFieldDir->signal_current_folder_changed().connect ( sigc::mem_fun(*this, &Preferences::flatFieldChanged), true); + ffconn = flatFieldDir->signal_selection_changed().connect ( sigc::mem_fun(*this, &Preferences::flatFieldChanged), true); //Cluts Dir Gtk::Frame* clutsDirFrame = Gtk::manage (new Gtk::Frame (M("PREFERENCES_FILMSIMULATION")) ); diff --git a/rtgui/rtwindow.cc b/rtgui/rtwindow.cc index 6d23c0d26..a34843d38 100644 --- a/rtgui/rtwindow.cc +++ b/rtgui/rtwindow.cc @@ -18,6 +18,7 @@ */ #include +#include #include "rtwindow.h" #include "options.h" #include "preferences.h" @@ -327,22 +328,38 @@ void RTWindow::on_realize () mainWindowCursorManager.init(get_window()); - // Check if first run of this version, then display the Release Notes text - if (options.version != versionString) { + // Display release notes only if new major version. + // Pattern matches "5.1" from "5.1-23-g12345678" + std::string vs[] = {versionString, options.version}; + std::regex pat("(^[0-9.]+).*"); + std::smatch sm; + std::vector vMajor; + for (const auto &v : vs) { + if (std::regex_match(v, sm, pat)) { + if (sm.size() == 2) { + std::ssub_match smsub = sm[1]; + vMajor.push_back(smsub.str()); + } + } + } - // Update the version parameter with the right value - options.version = versionString; + if (vMajor.size() == 2) { + if (vMajor[0] != vMajor[1]) { - splash = new Splash (*this); - splash->set_transient_for (*this); - splash->signal_delete_event().connect( sigc::mem_fun(*this, &RTWindow::splashClosed) ); + // Update the version parameter with the right value + options.version = versionString; - if (splash->hasReleaseNotes()) { - splash->showReleaseNotes(); - splash->show (); - } else { - delete splash; - splash = nullptr; + splash = new Splash (*this); + splash->set_transient_for (*this); + splash->signal_delete_event().connect( sigc::mem_fun(*this, &RTWindow::splashClosed) ); + + if (splash->hasReleaseNotes()) { + splash->showReleaseNotes(); + splash->show (); + } else { + delete splash; + splash = nullptr; + } } } }