diff --git a/rtengine/color.cc b/rtengine/color.cc index c0dbab4d3..14be09c35 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -133,11 +133,38 @@ void MunsellDebugInfo::reinitValues() void Color::init () { - int maxindex = 65536; + /*******************************************/ + + constexpr auto maxindex = 65536; + cachef(maxindex, LUT_CLIP_BELOW); - gamma2curve(maxindex, LUT_CLIP_BELOW | LUT_CLIP_ABOVE); + gammatab(maxindex, 0); + igammatab_srgb(maxindex, 0); + gammatab_srgb(maxindex, 0); + igammatab_55(maxindex, 0); + gammatab_55(maxindex, 0); + igammatab_4(maxindex, 0); + gammatab_4(maxindex, 0); + igammatab_26_11(maxindex, 0); + gammatab_26_11(maxindex, 0); + igammatab_24_17(maxindex, 0); + gammatab_24_17a(maxindex, LUT_CLIP_ABOVE | LUT_CLIP_BELOW); + gammatab_13_2(maxindex, 0); + igammatab_13_2(maxindex, 0); + gammatab_115_2(maxindex, 0); + igammatab_115_2(maxindex, 0); + gammatab_145_3(maxindex, 0); + igammatab_145_3(maxindex, 0); + +#ifdef _OPENMP +#pragma omp parallel sections +#endif // _OPENMP +{ +#ifdef _OPENMP +#pragma omp section +#endif for (int i = 0; i < maxindex; i++) { if (i > eps_max) { cachef[i] = 327.68 * ( exp(1.0 / 3.0 * log((double)i / MAXVALF) )); @@ -146,117 +173,145 @@ void Color::init () } } +#ifdef _OPENMP +#pragma omp section +#endif for (int i = 0; i < maxindex; i++) { gamma2curve[i] = (gamma2(i / 65535.0) * 65535.0); } - /*******************************************/ - - gammatab(65536, 0); - igammatab_srgb(65536, 0); - gammatab_srgb(65536, 0); - // igammatab_709(65536,0); - // gammatab_709(65536,0); - igammatab_55(65536, 0); - gammatab_55(65536, 0); - igammatab_4(65536, 0); - gammatab_4(65536, 0); - - igammatab_26_11(65536, 0); - gammatab_26_11(65536, 0); - igammatab_24_17(65536, 0); - gammatab_24_17a(65536, LUT_CLIP_ABOVE | LUT_CLIP_BELOW); - gammatab_13_2(65536, 0); - igammatab_13_2(65536, 0); - gammatab_115_2(65536, 0); - igammatab_115_2(65536, 0); - gammatab_145_3(65536, 0); - igammatab_145_3(65536, 0); - - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { gammatab_srgb[i] = (65535.0 * gamma2 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { igammatab_srgb[i] = (65535.0 * igamma2 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { gammatab[i] = (65535.0 * pow (i / 65535.0, 0.454545)); } - /* for (int i=0; i<65536; i++) - gammatab_709[i] = (65535.0 * gamma709 (i/65535.0)); - for (int i=0; i<65536; i++) - igammatab_709[i] = (65535.0 * igamma709 (i/65535.0)); - */ - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { gammatab_55[i] = (65535.0 * gamma55 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { igammatab_55[i] = (65535.0 * igamma55 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { gammatab_4[i] = (65535.0 * gamma4 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { igammatab_4[i] = (65535.0 * igamma4 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { gammatab_13_2[i] = (65535.0 * gamma13_2 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { igammatab_13_2[i] = (65535.0 * igamma13_2 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { gammatab_115_2[i] = (65535.0 * gamma115_2 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { igammatab_115_2[i] = (65535.0 * igamma115_2 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { gammatab_145_3[i] = (65535.0 * gamma145_3 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { igammatab_145_3[i] = (65535.0 * igamma145_3 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { gammatab_26_11[i] = (65535.0 * gamma26_11 (i / 65535.0)); } //gammatab_145_3 - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { igammatab_26_11[i] = (65535.0 * igamma26_11 (i / 65535.0)); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { float j = (float)i / 65535.0f; gammatab_24_17a[i] = gamma24_17(j); } - for (int i = 0; i < 65536; i++) { +#ifdef _OPENMP +#pragma omp section +#endif + for (int i = 0; i < maxindex; i++) { igammatab_24_17[i] = (65535.0 * igamma24_17 (i / 65535.0)); } - /*FILE* f = fopen ("c.txt", "wt"); - for (int i=0; i<256; i++) - fprintf (f, "%g %g\n", i/255.0, clower (i/255.0, 2.0, 1.0)); - fclose (f);*/ - +#ifdef _OPENMP +#pragma omp section +#endif initMunsell(); +#ifdef _OPENMP +#pragma omp section +#endif linearGammaTRC = cmsBuildGamma(NULL, 1.0); } +} void Color::cleanup () { diff --git a/rtengine/color.h b/rtengine/color.h index c179946f0..5d8dae55b 100644 --- a/rtengine/color.h +++ b/rtengine/color.h @@ -130,8 +130,6 @@ public: // look-up tables for the standard srgb gamma and its inverse (filled by init()) static LUTf igammatab_srgb; static LUTf gammatab_srgb; -// static LUTf igammatab_709; -// static LUTf gammatab_709; static LUTf igammatab_55; static LUTf gammatab_55; static LUTf igammatab_4; diff --git a/rtengine/curves.cc b/rtengine/curves.cc index d0b4c026f..6792df50d 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -34,6 +34,7 @@ #include "curves.h" #include "opthelper.h" #include "ciecam02.h" +#include "color.h" #undef CLIPD #define CLIPD(a) ((a)>0.0f?((a)<1.0f?(a):1.0f):0.0f) @@ -2293,7 +2294,7 @@ void PerceptualToneCurve::Apply(float &r, float &g, float &b, PerceptualToneCurv { // increase chroma scaling slightly of shadows - float nL = gamma2curve[newLuminance]; // apply gamma so we make comparison and transition with a more perceptual lightness scale + float nL = Color::gamma2curve[newLuminance]; // apply gamma so we make comparison and transition with a more perceptual lightness scale float dark_scale_factor = 1.20f; //float dark_scale_factor = 1.0 + state.debug.p2 / 100.0f; const float lolim = 0.15f; @@ -2427,7 +2428,6 @@ void PerceptualToneCurve::Apply(float &r, float &g, float &b, PerceptualToneCurv float PerceptualToneCurve::cf_range[2]; float PerceptualToneCurve::cf[1000]; -LUTf PerceptualToneCurve::gamma2curve; float PerceptualToneCurve::f, PerceptualToneCurve::c, PerceptualToneCurve::nc, PerceptualToneCurve::yb, PerceptualToneCurve::la, PerceptualToneCurve::xw, PerceptualToneCurve::yw, PerceptualToneCurve::zw, PerceptualToneCurve::gamut; float PerceptualToneCurve::n, PerceptualToneCurve::d, PerceptualToneCurve::nbb, PerceptualToneCurve::ncb, PerceptualToneCurve::cz, PerceptualToneCurve::aw, PerceptualToneCurve::wh, PerceptualToneCurve::pfl, PerceptualToneCurve::fl, PerceptualToneCurve::pow1; @@ -2490,12 +2490,6 @@ void PerceptualToneCurve::init() cf_range[0] = in_x[0]; cf_range[1] = in_x[in_len - 1]; } - gamma2curve(65536, 0); - - for (int i = 0; i < 65536; i++) { - gamma2curve[i] = CurveFactory::gamma2(i / 65535.0); - } - } void PerceptualToneCurve::initApplyState(PerceptualToneCurveState & state, Glib::ustring workingSpace) const diff --git a/rtengine/curves.h b/rtengine/curves.h index fffd7dcb7..b0e9d691f 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -843,7 +843,6 @@ class PerceptualToneCurve : public ToneCurve private: static float cf_range[2]; static float cf[1000]; - static LUTf gamma2curve; // for ciecam02 static float f, c, nc, yb, la, xw, yw, zw, gamut; static float n, d, nbb, ncb, cz, aw, wh, pfl, fl, pow1; diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 468abbe13..b604e08e1 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -64,33 +64,6 @@ using namespace procparams; extern const Settings* settings; -LUTf ImProcFunctions::cachef; -LUTf ImProcFunctions::gamma2curve; -void ImProcFunctions::initCache () -{ - - const int maxindex = 65536; - cachef(maxindex, 0/*LUT_CLIP_BELOW*/); - - gamma2curve(maxindex, 0); - - for (int i = 0; i < maxindex; i++) { - if (i > Color::eps_max) { - cachef[i] = 327.68 * ( exp(1.0 / 3.0 * log((double)i / MAXVALD) )); - } else { - cachef[i] = 327.68 * ((Color::kappa * i / MAXVALD + 16.0) / 116.0); - } - } - - for (int i = 0; i < maxindex; i++) { - gamma2curve[i] = (CurveFactory::gamma2(i / 65535.0) * 65535.0); - } -} - -void ImProcFunctions::cleanupCache () -{ - -} ImProcFunctions::~ImProcFunctions () { @@ -3806,9 +3779,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer y = toxyz[1][0] * r1 + toxyz[1][1] * g1 + toxyz[1][2] * b1; z = toxyz[2][0] * r1 + toxyz[2][1] * g1 + toxyz[2][2] * b1; - fx = (x < 65535.0f ? cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f )))); - fy = (y < 65535.0f ? cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f )))); - fz = (z < 65535.0f ? cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f )))); + fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f )))); + fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f )))); + fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f )))); L_1 = (116.0f * fy - 5242.88f); //5242.88=16.0*327.68; a_1 = (500.0f * (fx - fy) ); @@ -3836,7 +3809,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer // Luminosity after // only Luminance in Lab yy = toxyz[1][0] * r2 + toxyz[1][1] * g2 + toxyz[1][2] * b2; - fyy = (yy < 65535.0f ? cachef[std::max(yy, 0.f)] : (327.68f * float(exp(log(yy / MAXVALF) / 3.0f )))); + fyy = (yy < 65535.0f ? Color::cachef[std::max(yy, 0.f)] : (327.68f * float(exp(log(yy / MAXVALF) / 3.0f )))); L_2 = (116.0f * fyy - 5242.88f); //gamut control @@ -4429,9 +4402,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float fx, fy, fz; - fx = (x < 65535.0f ? cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f )))); - fy = (y < 65535.0f ? cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f )))); - fz = (z < 65535.0f ? cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f )))); + fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f )))); + fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f )))); + fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f )))); lab->L[i][j] = (116.0f * fy - 5242.88f); //5242.88=16.0*327.68; lab->a[i][j] = (500.0f * (fx - fy) ); @@ -4879,9 +4852,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer float fx, fy, fz; - fx = (x < 65535.0f ? cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f )))); - fy = (y < 65535.0f ? cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f )))); - fz = (z < 65535.0f ? cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f )))); + fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f )))); + fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f )))); + fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f )))); lab->L[i][j] = (116.0f * fy - 5242.88f); //5242.88=16.0*327.68; lab->a[i][j] = (500.0f * (fx - fy) ); diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 996f91c58..5348c40f5 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -57,7 +57,6 @@ using namespace procparams; class ImProcFunctions { - static LUTf gamma2curve; cmsHTRANSFORM monitorTransform; cmsHTRANSFORM lab2outputTransform; @@ -201,7 +200,6 @@ class ImProcFunctions public: - static LUTf cachef; double lumimul[3]; // float chau; // float chred; @@ -221,7 +219,6 @@ public: // float maxblueresid;//used by noise_residual // int comptlevel; - static void initCache (); static void cleanupCache (); ImProcFunctions (const ProcParams* iparams, bool imultiThread = true) diff --git a/rtengine/init.cc b/rtengine/init.cc index 9fa5c48ee..79e96e3c8 100644 --- a/rtengine/init.cc +++ b/rtengine/init.cc @@ -29,6 +29,8 @@ #include "rtthumbnail.h" #include "../rtgui/profilestore.h" #include "../rtgui/threadutils.h" +#define BENCHMARK +#include "StopWatch.h" namespace rtengine { @@ -39,11 +41,12 @@ MyMutex* lcmsMutex = NULL; int init (const Settings* s, Glib::ustring baseDir, Glib::ustring userSettingsDir) { - +BENCHFUN settings = s; +StopWatch Stopi("iccstore"); iccStore->init (s->iccDirectory, baseDir + "/iccprofiles"); iccStore->findDefaultMonitorProfile(); - +Stopi.stop(); dcpStore->init (baseDir + "/dcpprofiles"); CameraConstantsStore::getInstance ()->init (baseDir, userSettingsDir); @@ -52,7 +55,6 @@ int init (const Settings* s, Glib::ustring baseDir, Glib::ustring userSettingsDi Color::init (); PerceptualToneCurve::init (); RawImageSource::init (); - ImProcFunctions::initCache (); Thumbnail::initGamma (); delete lcmsMutex; lcmsMutex = new MyMutex; @@ -66,7 +68,6 @@ void cleanup () ProcParams::cleanup (); Color::cleanup (); - ImProcFunctions::cleanupCache (); Thumbnail::cleanupGamma (); RawImageSource::cleanup (); } diff --git a/rtengine/iplab2rgb.cc b/rtengine/iplab2rgb.cc index 89deac08f..4510044aa 100644 --- a/rtengine/iplab2rgb.cc +++ b/rtengine/iplab2rgb.cc @@ -117,9 +117,9 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image) /* copy RGB */ //int R1=((int)gamma2curve[(R)]) - data[ix++] = ((int)gamma2curve[CLIP(R)]) >> 8; - data[ix++] = ((int)gamma2curve[CLIP(G)]) >> 8; - data[ix++] = ((int)gamma2curve[CLIP(B)]) >> 8; + data[ix++] = ((int)Color::gamma2curve[CLIP(R)]) >> 8; + data[ix++] = ((int)Color::gamma2curve[CLIP(G)]) >> 8; + data[ix++] = ((int)Color::gamma2curve[CLIP(B)]) >> 8; } } } @@ -229,9 +229,9 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, Color::xyz2rgb(x_, y_, z_, R, G, B, rgb_xyz); - image->data[ix++] = (int)gamma2curve[CLIP(R)] >> 8; - image->data[ix++] = (int)gamma2curve[CLIP(G)] >> 8; - image->data[ix++] = (int)gamma2curve[CLIP(B)] >> 8; + image->data[ix++] = (int)Color::gamma2curve[CLIP(R)] >> 8; + image->data[ix++] = (int)Color::gamma2curve[CLIP(G)] >> 8; + image->data[ix++] = (int)Color::gamma2curve[CLIP(B)] >> 8; } } } @@ -331,9 +331,9 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int Color::xyz2srgb(x_, y_, z_, R, G, B); - image->r(i - cy, j - cx) = (int)gamma2curve[CLIP(R)]; - image->g(i - cy, j - cx) = (int)gamma2curve[CLIP(G)]; - image->b(i - cy, j - cx) = (int)gamma2curve[CLIP(B)]; + image->r(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(R)]; + image->g(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(G)]; + image->b(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(B)]; } } } @@ -601,9 +601,9 @@ Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int Color::xyz2srgb(x_, y_, z_, R, G, B); - image->r(i - cy, j - cx) = (int)gamma2curve[CLIP(R)]; - image->g(i - cy, j - cx) = (int)gamma2curve[CLIP(G)]; - image->b(i - cy, j - cx) = (int)gamma2curve[CLIP(B)]; + image->r(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(R)]; + image->g(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(G)]; + image->b(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(B)]; } } } diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index d1d4da54f..1aac5d0be 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -4209,14 +4209,14 @@ void RawImageSource::HLRecovery_CIELab (float* rin, float* gin, float* bin, floa float go = min(g, maxval); float bo = min(b, maxval); float yy = xyz_cam[1][0] * r + xyz_cam[1][1] * g + xyz_cam[1][2] * b; - float fy = (yy < 65535.0 ? ImProcFunctions::cachef[yy] / 327.68 : (exp(log(yy / MAXVALD) / 3.0 ))); + float fy = (yy < 65535.0 ? Color::cachef[yy] / 327.68 : (exp(log(yy / MAXVALD) / 3.0 ))); // compute LCH decompostion of the clipped pixel (only color information, thus C and H will be used) float x = xyz_cam[0][0] * ro + xyz_cam[0][1] * go + xyz_cam[0][2] * bo; float y = xyz_cam[1][0] * ro + xyz_cam[1][1] * go + xyz_cam[1][2] * bo; float z = xyz_cam[2][0] * ro + xyz_cam[2][1] * go + xyz_cam[2][2] * bo; - x = (x < 65535.0 ? ImProcFunctions::cachef[x] / 327.68 : (exp(log(x / MAXVALD) / 3.0 ))); - y = (y < 65535.0 ? ImProcFunctions::cachef[y] / 327.68 : (exp(log(y / MAXVALD) / 3.0 ))); - z = (z < 65535.0 ? ImProcFunctions::cachef[z] / 327.68 : (exp(log(z / MAXVALD) / 3.0 ))); + x = (x < 65535.0 ? Color::cachef[x] / 327.68 : (exp(log(x / MAXVALD) / 3.0 ))); + y = (y < 65535.0 ? Color::cachef[y] / 327.68 : (exp(log(y / MAXVALD) / 3.0 ))); + z = (z < 65535.0 ? Color::cachef[z] / 327.68 : (exp(log(z / MAXVALD) / 3.0 ))); // convert back to rgb double fz = fy - y + z; double fx = fy + x - y; diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index fa9622a3e..100e82fad 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -731,6 +731,9 @@ void Thumbnail::initGamma () igammatab[i] = (unsigned short)(255.0 * pow((double)i / 255.0, Color::sRGBGamma)); } +#ifdef _OPENMP +#pragma omp parallel for +#endif for (int i = 0; i < 65536; i++) { gammatab[i] = (unsigned char)(255.0 * pow((double)i / 65535.0, 1.f / Color::sRGBGamma)); }