From 752e1562b3f3940989a550dee0ba2ad8f14f4695 Mon Sep 17 00:00:00 2001 From: Oliver Duis Date: Wed, 11 Jul 2012 22:51:57 +0200 Subject: [PATCH] Reworked color functions 2 see issue 1052 --- rtengine/curves.cc | 24 ------------------------ rtengine/curves.h | 20 -------------------- rtengine/init.cc | 4 ++-- rtengine/rawimagesource.cc | 14 +++++++------- rtengine/rtthumbnail.cc | 14 +++++++------- rtengine/stdimagesource.cc | 15 ++++++++------- 6 files changed, 24 insertions(+), 67 deletions(-) diff --git a/rtengine/curves.cc b/rtengine/curves.cc index e06d747c3..e6ef98cf6 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -695,28 +695,4 @@ namespace rtengine { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -LUTf CurveFactory::gammatab; -LUTf CurveFactory::igammatab_srgb; -LUTf CurveFactory::gammatab_srgb; - -void CurveFactory::init () { - - gammatab(65536,0); - igammatab_srgb(65536,0); - gammatab_srgb(65536,0); - - for (int i=0; i<65536; i++) - gammatab_srgb[i] = (65535.0 * gamma2 (i/65535.0)); - for (int i=0; i<65536; i++) - igammatab_srgb[i] = (65535.0 * igamma2 (i/65535.0)); - for (int i=0; i<65536; i++) - gammatab[i] = (65535.0 * pow (i/65535.0, 0.454545)); - -/* 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);*/ -} - } diff --git a/rtengine/curves.h b/rtengine/curves.h index 7a1c16c1c..5d27da3f2 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -45,12 +45,6 @@ class CurveFactory { protected: - // look-up tables for the standard srgb gamma and its inverse (filled by init()) - static LUTf igammatab_srgb; - static LUTf gammatab_srgb; - // look-up tables for the simple exponential gamma - static LUTf gammatab; - // functions calculating the parameters of the contrast curve based on the desired slope at the center static double solve_upper (double m, double c, double deriv); static double solve_lower (double m, double c, double deriv); @@ -151,9 +145,6 @@ class CurveFactory { } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - static void init (); - static void cleanup (); - static inline double centercontrast (double x, double b, double m); // standard srgb gamma and its inverse @@ -171,17 +162,6 @@ class CurveFactory { return (x <= start*slope ? x/slope : exp(log((x+add)/mul)*gamma) ); } - // gamma functions on [0,65535] based on look-up tables - static inline float gamma_srgb (int x) { return gammatab_srgb[x]; } - static inline float gamma (int x) { return gammatab[x]; } - static inline float igamma_srgb (int x) { return igammatab_srgb[x]; } - static inline float gamma_srgb (float x) { return gammatab_srgb[x]; } - static inline float gamma (float x) { return gammatab[x]; } - static inline float igamma_srgb (float x) { return igammatab_srgb[x]; } - //static inline float gamma_srgb (double x) { return gammatab_srgb[x]; } - //static inline float gamma (double x) { return gammatab[x]; } - //static inline float igamma_srgb (double x) { return igammatab_srgb[x]; } - static inline float hlcurve (const float exp_scale, const float comp, const float hlrange, float level) { if (comp>0.0) { diff --git a/rtengine/init.cc b/rtengine/init.cc index 36cabc6e1..81b422257 100644 --- a/rtengine/init.cc +++ b/rtengine/init.cc @@ -21,7 +21,6 @@ #include "dcp.h" #include "improcfun.h" #include "improccoordinator.h" -#include "curves.h" #include "dfmanager.h" #include "ffmanager.h" #include "rtthumbnail.h" @@ -43,7 +42,7 @@ int init (const Settings* s, Glib::ustring baseDir) { profileStore.init (); ProcParams::init (); - CurveFactory::init (); + Color::init(); ImProcFunctions::initMunsell(); ImProcFunctions::initCache (); Thumbnail::initGamma (); @@ -57,6 +56,7 @@ int init (const Settings* s, Glib::ustring baseDir) { void cleanup () { ProcParams::cleanup (); + Color::cleanup (); ImProcFunctions::cleanupCache (); Thumbnail::cleanupGamma (); } diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 2bf944b0e..f654350f5 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -2298,29 +2298,29 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU if (ri->isBayer()) { for (int j=start; jISGREEN(i,j)) { - if(i &1) idx = CLIP((int)CurveFactory::gamma(mult*(ri->data[i][j]-(cblacksom[1]/*+black_lev[1]*/))));// green 1 + if(i &1) idx = CLIP((int)Color::gamma(mult*(ri->data[i][j]-(cblacksom[1]/*+black_lev[1]*/))));// green 1 else - idx = CLIP((int)CurveFactory::gamma(mult*(ri->data[i][j]-(cblacksom[3]/*+black_lev[3]*/))));//green 2 + idx = CLIP((int)Color::gamma(mult*(ri->data[i][j]-(cblacksom[3]/*+black_lev[3]*/))));//green 2 histGreenRaw[idx>>8]++; } else if (ri->ISRED(i,j)) { - idx = CLIP((int)CurveFactory::gamma(mult*(ri->data[i][j]-(cblacksom[0]/*+black_lev[0]*/)))); + idx = CLIP((int)Color::gamma(mult*(ri->data[i][j]-(cblacksom[0]/*+black_lev[0]*/)))); histRedRaw[idx>>8]++; } else if (ri->ISBLUE(i,j)) { - idx = CLIP((int)CurveFactory::gamma(mult*(ri->data[i][j]-(cblacksom[2]/*+black_lev[2]*/)))); + idx = CLIP((int)Color::gamma(mult*(ri->data[i][j]-(cblacksom[2]/*+black_lev[2]*/)))); histBlueRaw[idx>>8]++; } } } else { for (int j=start; j<3*end; j++) { - idx = CLIP((int)CurveFactory::gamma(mult*(ri->data[i][j]-cblack[0]))); + idx = CLIP((int)Color::gamma(mult*(ri->data[i][j]-cblack[0]))); histRedRaw[idx>>8]++; - idx = CLIP((int)CurveFactory::gamma(mult*(ri->data[i][j+1]-cblack[1]))); + idx = CLIP((int)Color::gamma(mult*(ri->data[i][j+1]-cblack[1]))); histGreenRaw[idx>>8]++; - idx = CLIP((int)CurveFactory::gamma(mult*(ri->data[i][j+2]-cblack[2]))); + idx = CLIP((int)Color::gamma(mult*(ri->data[i][j+2]-cblack[2]))); histBlueRaw[idx>>8]++; } } diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 8f1d46962..f268c9d08 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -110,9 +110,9 @@ Thumbnail* Thumbnail::loadFromImage (const Glib::ustring& fname, int &w, int &h, tpp->aeHistogram.clear(); int ix = 0; for (int i=0; iheight*img->width; i++) { - int rtmp=CurveFactory::igamma_srgb (img->data[ix++]); - int gtmp=CurveFactory::igamma_srgb (img->data[ix++]); - int btmp=CurveFactory::igamma_srgb (img->data[ix++]); + int rtmp=Color::igamma_srgb (img->data[ix++]); + int gtmp=Color::igamma_srgb (img->data[ix++]); + int btmp=Color::igamma_srgb (img->data[ix++]); tpp->aeHistogram[rtmp>>tpp->aeHistCompression]++; tpp->aeHistogram[gtmp>>tpp->aeHistCompression]+=2; @@ -502,9 +502,9 @@ 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,CurveFactory::sRGBGamma)); + igammatab[i] = (unsigned short)(255.0*pow((double)i/255.0,Color::sRGBGamma)); for (int i=0; i<65536; i++) - gammatab[i] = (unsigned char)(255.0*pow((double)i/65535.0,1.f/CurveFactory::sRGBGamma)); + gammatab[i] = (unsigned char)(255.0*pow((double)i/65535.0,1.f/Color::sRGBGamma)); } void Thumbnail::cleanupGamma () { @@ -693,7 +693,7 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, int rhei ipf.setScale (sqrt(double(fw*fw+fh*fh))/sqrt(double(thumbImg->width*thumbImg->width+thumbImg->height*thumbImg->height))*scale); LUTu hist16 (65536); - double gamma = isRaw ? CurveFactory::sRGBGamma : 0; // usually in ImageSource, but we don't have that here + double gamma = isRaw ? Color::sRGBGamma : 0; // usually in ImageSource, but we don't have that here ipf.firstAnalysis (baseImg, ¶ms, hist16, gamma); // perform transform @@ -876,7 +876,7 @@ void Thumbnail::getSpotWB (const procparams::ProcParams& params, int xp, int yp, // calculate spot wb (copy & pasted from stdimagesource) unsigned short igammatab[256]; for (int i=0; i<256; i++) - igammatab[i] = (unsigned short)(255.0*pow(i/255.0,CurveFactory::sRGBGamma)); + igammatab[i] = (unsigned short)(255.0*pow(i/255.0,Color::sRGBGamma)); int x; int y; double reds = 0, greens = 0, blues = 0; int rn = 0, gn = 0, bn = 0; diff --git a/rtengine/stdimagesource.cc b/rtengine/stdimagesource.cc index f9911de56..138a553da 100644 --- a/rtengine/stdimagesource.cc +++ b/rtengine/stdimagesource.cc @@ -20,6 +20,7 @@ #include "mytime.h" #include "iccstore.h" #include "curves.h" +#include "color.h" #undef THREAD_PRIORITY_NORMAL @@ -228,9 +229,9 @@ void StdImageSource::getImage_ (ColorTemp ctemp, int tran, Imagefloat* image, Pr for (int m=0; mr[i+m][jx+n]); - gtot += CurveFactory::igamma_srgb(img->g[i+m][jx+n]); - btot += CurveFactory::igamma_srgb(img->b[i+m][jx+n]); + rtot += Color::igamma_srgb(img->r[i+m][jx+n]); + gtot += Color::igamma_srgb(img->g[i+m][jx+n]); + btot += Color::igamma_srgb(img->b[i+m][jx+n]); } line_red[j] = rtot; line_green[j] = gtot; @@ -238,7 +239,7 @@ void StdImageSource::getImage_ (ColorTemp ctemp, int tran, Imagefloat* image, Pr } // covert back to gamma and clip -#define GCLIP( x ) CurveFactory::gamma_srgb(CLIP(x)) +#define GCLIP( x ) Color::gamma_srgb(CLIP(x)) if ((mtran & TR_ROT) == TR_R180) for (int j=0; jheight; i++) for (int j=0; jwidth; j++) { - histogram[(int)CurveFactory::igamma_srgb (img->r[i][j])>>histcompr]++; - histogram[(int)CurveFactory::igamma_srgb (img->g[i][j])>>histcompr]++; - histogram[(int)CurveFactory::igamma_srgb (img->b[i][j])>>histcompr]++; + histogram[(int)Color::igamma_srgb (img->r[i][j])>>histcompr]++; + histogram[(int)Color::igamma_srgb (img->g[i][j])>>histcompr]++; + histogram[(int)Color::igamma_srgb (img->b[i][j])>>histcompr]++; } }