From bf66671a6d9fa7b461d611acbba70776bf78be44 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Thu, 25 Feb 2016 15:45:42 +0100 Subject: [PATCH] Moved gamma lookup table from rtthumbnail.* to color.* --- rtengine/color.cc | 227 ++++++++++++++++++++++------------------ rtengine/color.h | 1 + rtengine/init.cc | 4 +- rtengine/rtthumbnail.cc | 45 ++------ rtengine/rtthumbnail.h | 5 - 5 files changed, 135 insertions(+), 147 deletions(-) diff --git a/rtengine/color.cc b/rtengine/color.cc index 14be09c35..dbd9c40f6 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -36,6 +36,7 @@ LUTf Color::cachef; LUTf Color::gamma2curve; LUTf Color::gammatab; +unsigned char* Color::gammatabThumb = nullptr; LUTf Color::igammatab_srgb; LUTf Color::gammatab_srgb; // LUTf Color::igammatab_709; @@ -140,6 +141,8 @@ void Color::init () cachef(maxindex, LUT_CLIP_BELOW); gamma2curve(maxindex, LUT_CLIP_BELOW | LUT_CLIP_ABOVE); gammatab(maxindex, 0); + gammatabThumb = new unsigned char[maxindex]; + igammatab_srgb(maxindex, 0); gammatab_srgb(maxindex, 0); igammatab_55(maxindex, 0); @@ -159,158 +162,172 @@ void Color::init () igammatab_145_3(maxindex, 0); #ifdef _OPENMP -#pragma omp parallel sections + #pragma omp parallel sections #endif // _OPENMP -{ + { #ifdef _OPENMP -#pragma omp section + #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) )); - } else { - cachef[i] = 327.68 * ((kappa * i / MAXVALF + 16.0) / 116.0); + + for (int i = 0; i < maxindex; i++) { + if (i > eps_max) { + cachef[i] = 327.68 * exp(1.0 / 3.0 * log((double)i / MAXVALF) ); + } else { + cachef[i] = 327.68 * ((kappa * i / MAXVALF + 16.0) / 116.0); + } } - } #ifdef _OPENMP -#pragma omp section + #pragma omp section #endif - for (int i = 0; i < maxindex; i++) { - gamma2curve[i] = (gamma2(i / 65535.0) * 65535.0); - } + + for (int i = 0; i < maxindex; i++) { + gammatab_srgb[i] = gamma2curve[i] = 65535.0 * gamma2(i / 65535.0); // two lookup tables with same content but one clips and one does not clip + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + igammatab_srgb[i] = 65535.0 * igamma2 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #pragma omp section #endif - for (int i = 0; i < maxindex; i++) { - igammatab_srgb[i] = (65535.0 * igamma2 (i / 65535.0)); - } + { + double rsRGBGamma = 1.0 / sRGBGamma; + + for (int i = 0; i < maxindex; i++) { + double val = pow (i / 65535.0, rsRGBGamma); + gammatab[i] = 65535.0 * val; + gammatabThumb[i] = (unsigned char)(255.0 * val); + } + } +#ifdef _OPENMP + #pragma omp section +#endif + + for (int i = 0; i < maxindex; i++) { + gammatab_55[i] = 65535.0 * gamma55 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + igammatab_55[i] = 65535.0 * igamma55 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + gammatab_4[i] = 65535.0 * gamma4 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + igammatab_4[i] = 65535.0 * igamma4 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + gammatab_13_2[i] = 65535.0 * gamma13_2 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + igammatab_13_2[i] = 65535.0 * igamma13_2 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + gammatab_115_2[i] = 65535.0 * gamma115_2 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + igammatab_115_2[i] = 65535.0 * igamma115_2 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + gammatab_145_3[i] = 65535.0 * gamma145_3 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + igammatab_145_3[i] = 65535.0 * igamma145_3 (i / 65535.0); + } #ifdef _OPENMP -#pragma omp section + #pragma omp section #endif - for (int i = 0; i < maxindex; i++) { - gammatab_145_3[i] = (65535.0 * gamma145_3 (i / 65535.0)); - } -#ifdef _OPENMP -#pragma omp section -#endif - for (int i = 0; i < maxindex; i++) { - igammatab_145_3[i] = (65535.0 * igamma145_3 (i / 65535.0)); - } - -#ifdef _OPENMP -#pragma omp section -#endif - for (int i = 0; i < maxindex; i++) { - gammatab_26_11[i] = (65535.0 * gamma26_11 (i / 65535.0)); - } + for (int i = 0; i < maxindex; i++) { + gammatab_26_11[i] = 65535.0 * gamma26_11 (i / 65535.0); + } //gammatab_145_3 #ifdef _OPENMP -#pragma omp section + #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 < maxindex; i++) { + igammatab_26_11[i] = 65535.0 * igamma26_11 (i / 65535.0); + } + +#ifdef _OPENMP + #pragma omp section +#endif + + for (int i = 0; i < maxindex; i++) { + gammatab_24_17a[i] = gamma24_17(i / 65535.0); + } + +#ifdef _OPENMP + #pragma omp section +#endif + + for (int i = 0; i < maxindex; i++) { + igammatab_24_17[i] = 65535.0 * igamma24_17 (i / 65535.0); + } + +#ifdef _OPENMP + #pragma omp section +#endif + initMunsell(); + +#ifdef _OPENMP + #pragma omp section +#endif + linearGammaTRC = cmsBuildGamma(NULL, 1.0); } - -#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); - } - -#ifdef _OPENMP -#pragma omp section -#endif - for (int i = 0; i < maxindex; i++) { - igammatab_24_17[i] = (65535.0 * igamma24_17 (i / 65535.0)); - } - -#ifdef _OPENMP -#pragma omp section -#endif - initMunsell(); - -#ifdef _OPENMP -#pragma omp section -#endif - linearGammaTRC = cmsBuildGamma(NULL, 1.0); -} } void Color::cleanup () @@ -318,6 +335,10 @@ void Color::cleanup () if (linearGammaTRC) { cmsFreeToneCurve(linearGammaTRC); } + + if(gammatabThumb) { + delete [] gammatabThumb; + } } void Color::rgb2hsl(float r, float g, float b, float &h, float &s, float &l) diff --git a/rtengine/color.h b/rtengine/color.h index 5d8dae55b..89c34c3ca 100644 --- a/rtengine/color.h +++ b/rtengine/color.h @@ -148,6 +148,7 @@ public: // look-up tables for the simple exponential gamma static LUTf gammatab; + static unsigned char *gammatabThumb; // for thumbnails static void init (); diff --git a/rtengine/init.cc b/rtengine/init.cc index 4ce58a2d6..4bba74a43 100644 --- a/rtengine/init.cc +++ b/rtengine/init.cc @@ -41,7 +41,7 @@ MyMutex* lcmsMutex = NULL; int init (const Settings* s, Glib::ustring baseDir, Glib::ustring userSettingsDir) { -BENCHFUN + BENCHFUN settings = s; iccStore->init (s->iccDirectory, baseDir + "/iccprofiles"); iccStore->findDefaultMonitorProfile(); @@ -53,7 +53,6 @@ BENCHFUN Color::init (); PerceptualToneCurve::init (); RawImageSource::init (); - Thumbnail::initGamma (); delete lcmsMutex; lcmsMutex = new MyMutex; dfm.init( s->darkFramesPath ); @@ -66,7 +65,6 @@ void cleanup () ProcParams::cleanup (); Color::cleanup (); - Thumbnail::cleanupGamma (); RawImageSource::cleanup (); } diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 100e82fad..e4729bead 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -718,33 +718,6 @@ Thumbnail* Thumbnail::loadFromRaw (const Glib::ustring& fname, RawMetaDataLocati #undef FISGREEN #undef FISBLUE - -unsigned short *Thumbnail::igammatab = 0; -unsigned char *Thumbnail::gammatab = 0; - -void Thumbnail::initGamma () -{ - igammatab = new unsigned short[256]; - gammatab = new unsigned char[65536]; - - for (int i = 0; i < 256; i++) { - 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)); - } -} - -void Thumbnail::cleanupGamma () -{ - delete [] igammatab; - delete [] gammatab; -} - void Thumbnail::init () { @@ -1457,9 +1430,9 @@ unsigned char* Thumbnail::getGrayscaleHistEQ (int trim_width) image->convertTo(image->r(i, j), r_); image->convertTo(image->g(i, j), g_); image->convertTo(image->b(i, j), b_); - int r = gammatab[min(r_, static_cast(max_)) * scaleForSave >> 13]; - int g = gammatab[min(g_, static_cast(max_)) * scaleForSave >> 13]; - int b = gammatab[min(b_, static_cast(max_)) * scaleForSave >> 13]; + int r = Color::gammatabThumb[min(r_, static_cast(max_)) * scaleForSave >> 13]; + int g = Color::gammatabThumb[min(g_, static_cast(max_)) * scaleForSave >> 13]; + int b = Color::gammatabThumb[min(b_, static_cast(max_)) * scaleForSave >> 13]; tmpdata[ix++] = (r * 19595 + g * 38469 + b * 7472) >> 16; } } else if (thumbImg->getType() == sImage16) { @@ -1471,9 +1444,9 @@ unsigned char* Thumbnail::getGrayscaleHistEQ (int trim_width) image->convertTo(image->r(i, j), r_); image->convertTo(image->g(i, j), g_); image->convertTo(image->b(i, j), b_); - int r = gammatab[min(r_, static_cast(max_)) * scaleForSave >> 13]; - int g = gammatab[min(g_, static_cast(max_)) * scaleForSave >> 13]; - int b = gammatab[min(b_, static_cast(max_)) * scaleForSave >> 13]; + int r = Color::gammatabThumb[min(r_, static_cast(max_)) * scaleForSave >> 13]; + int g = Color::gammatabThumb[min(g_, static_cast(max_)) * scaleForSave >> 13]; + int b = Color::gammatabThumb[min(b_, static_cast(max_)) * scaleForSave >> 13]; tmpdata[ix++] = (r * 19595 + g * 38469 + b * 7472) >> 16; } } else if (thumbImg->getType() == sImagefloat) { @@ -1485,9 +1458,9 @@ unsigned char* Thumbnail::getGrayscaleHistEQ (int trim_width) image->convertTo(image->r(i, j), r_); image->convertTo(image->g(i, j), g_); image->convertTo(image->b(i, j), b_); - int r = gammatab[min(r_, static_cast(max_)) * scaleForSave >> 13]; - int g = gammatab[min(g_, static_cast(max_)) * scaleForSave >> 13]; - int b = gammatab[min(b_, static_cast(max_)) * scaleForSave >> 13]; + int r = Color::gammatabThumb[min(r_, static_cast(max_)) * scaleForSave >> 13]; + int g = Color::gammatabThumb[min(g_, static_cast(max_)) * scaleForSave >> 13]; + int b = Color::gammatabThumb[min(b_, static_cast(max_)) * scaleForSave >> 13]; tmpdata[ix++] = (r * 19595 + g * 38469 + b * 7472) >> 16; } } diff --git a/rtengine/rtthumbnail.h b/rtengine/rtthumbnail.h index dd9d8e9ca..bc367522d 100644 --- a/rtengine/rtthumbnail.h +++ b/rtengine/rtthumbnail.h @@ -42,9 +42,6 @@ class Thumbnail void transformPixel (int x, int y, int tran, int& tx, int& ty); - static unsigned short *igammatab; - static unsigned char *gammatab; - ImageIO* thumbImg; double camwbRed; double camwbGreen; @@ -72,8 +69,6 @@ public: ~Thumbnail (); Thumbnail (); - static void initGamma (); - static void cleanupGamma (); void init (); IImage8* processImage (const procparams::ProcParams& pparams, int rheight, TypeInterpolation interp, std::string camName,