From a876935d373c0b599e2f914624b101948660abcc Mon Sep 17 00:00:00 2001 From: Emil Martinec Date: Tue, 9 Nov 2010 00:32:14 -0600 Subject: [PATCH] Fix for oversaturated colors artifacts (yellow mostly). --- rtengine/curves.cc | 6 +++--- rtengine/curves.h | 2 +- rtengine/improccoordinator.cc | 2 +- rtengine/improccoordinator.h | 6 ++++-- rtengine/improcfun.cc | 20 ++++++++++---------- rtengine/improcfun.h | 2 +- rtengine/rtthumbnail.cc | 12 ++++++------ rtengine/simpleprocess.cc | 12 ++++++------ 8 files changed, 32 insertions(+), 30 deletions(-) diff --git a/rtengine/curves.cc b/rtengine/curves.cc index 7fb025de2..c4234a14c 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -587,7 +587,7 @@ void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, dou //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, double shcompr, double br, double contr, double defmul, double gamma_, bool igamma, const std::vector& curvePoints, unsigned int* histogram, int* hlCurve, int* shCurve, int* outCurve, unsigned int* outBeforeCCurveHistogram, int skip) { + void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, double shcompr, double br, double contr, double defmul, double gamma_, bool igamma, const std::vector& curvePoints, unsigned int* histogram, float* hlCurve, float* shCurve, int* outCurve, unsigned int* outBeforeCCurveHistogram, int skip) { double def_mul = pow (2.0, defmul); @@ -732,7 +732,7 @@ void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, dou // apply custom/parametric/NURBS curve, if any if (tcurve) { if (outBeforeCCurveHistogram) { - double hval = brightcurve->getVal (shCurve[hlCurve[(int)val]]); + double hval = brightcurve->getVal ((int)shCurve[(int)hlCurve[(int)val]]); //if (needigamma) // hval = igamma2 (hval); int hi = (int)(255.0*CLIPD(hval)); @@ -769,7 +769,7 @@ void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, dou double avg = 0; //double sqavg = 0; for (int i=0; i<=0xffff; i++) { - avg += dcurve[shCurve[hlCurve[i]]] * histogram[i]; + avg += dcurve[(int)shCurve[(int)hlCurve[i]]] * histogram[i]; //sqavg += dcurve[i]*dcurve[i] * histogram[i]; sum += histogram[i]; } diff --git a/rtengine/curves.h b/rtengine/curves.h index 37f225f24..c9bad3d37 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -157,7 +157,7 @@ class CurveFactory { public: // static void updateCurve3 (int* curve, int* ohistogram, const std::vector& cpoints, double defmul, double ecomp, int black, double hlcompr, double shcompr, double br, double contr, double gamma_, bool igamma, int skip=1); - static void complexCurve (double ecomp, double black, double hlcompr, double shcompr, double br, double contr, double defmul, double gamma_, bool igamma, const std::vector& curvePoints, unsigned int* histogram, int* hlCurve, int* shCurve, int* outCurve, unsigned int* outBeforeCCurveHistogram, int skip=1); + static void complexCurve (double ecomp, double black, double hlcompr, double shcompr, double br, double contr, double defmul, double gamma_, bool igamma, const std::vector& curvePoints, unsigned int* histogram, float* hlCurve, float* shCurve, int* outCurve, unsigned int* outBeforeCCurveHistogram, int skip=1); static void complexsgnCurve (double satclip, double satcompr, double saturation, double colormult, const std::vector& curvePoints, int* outCurve, int skip=1); }; diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 0f92783c5..770eb4135 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -178,7 +178,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) { readyphase++; if (todo & M_LUMACURVE) { - CurveFactory::complexCurve (0.0, 0.0, 0.0, 0.0, params.labCurve.brightness, params.labCurve.contrast, 0.0, 0.0, false, params.labCurve.lcurve, lhist16, chroma_acurve, chroma_bcurve, lumacurve, bcLhist, scale==1 ? 1 : 16); + CurveFactory::complexCurve (0.0, 0.0, 0.0, 0.0, params.labCurve.brightness, params.labCurve.contrast, 0.0, 0.0, false, params.labCurve.lcurve, lhist16, dummy1, dummy2, lumacurve, bcLhist, scale==1 ? 1 : 16); CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.acurve, chroma_acurve, scale==1 ? 1 : 16); CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.bcurve, chroma_bcurve, scale==1 ? 1 : 16); } diff --git a/rtengine/improccoordinator.h b/rtengine/improccoordinator.h index 81045c5f7..72bc17ac9 100644 --- a/rtengine/improccoordinator.h +++ b/rtengine/improccoordinator.h @@ -62,8 +62,10 @@ class ImProcCoordinator : public StagedImageProcessor { void freeAll (); - int hltonecurve [65536]; - int shtonecurve [65536]; + float dummy1 [65536]; + float dummy2 [65536]; + float hltonecurve [65536]; + float shtonecurve [65536]; int tonecurve [65536]; int lumacurve [65536]; diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index ef040aa3d..650e4b100 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -245,7 +245,7 @@ void ImProcFunctions::firstAnalysis (Image16* original, const ProcParams* params delete [] hist; } -void ImProcFunctions::rgbProc (Image16* working, LabImage* lab, int* hltonecurve, int* shtonecurve, int* tonecurve, SHMap* shmap, int sat) { +void ImProcFunctions::rgbProc (Image16* working, LabImage* lab, float* hltonecurve, float* shtonecurve, int* tonecurve, SHMap* shmap, int sat) { int h_th, s_th; if (shmap) { @@ -321,16 +321,14 @@ void ImProcFunctions::rgbProc (Image16* working, LabImage* lab, int* hltonecurve b = CLIP((int)(factor*b)); } } - + //float h, s, v; + //rgb2hsv(r,g,b,h,s,v); //highlight tone curve - /*r = tonecurve[r]; - g = tonecurve[g]; - b = tonecurve[b];*/ - //int Y = (int)(0.299*r + 0.587*g + 0.114*b); - //float tonefactor = (Y>0 ? (float)tonecurve1[Y]/Y : 1); - float rtonefactor = (r>0 ? (float)hltonecurve[r]/r : 1); - float gtonefactor = (g>0 ? (float)hltonecurve[g]/g : 1); - float btonefactor = (b>0 ? (float)hltonecurve[b]/b : 1); + //v = (float)hltonecurve[(int)(65535*v)]/65535; + + float rtonefactor = (r>0 ? (float)hltonecurve[r]/r : (float)hltonecurve[1]); + float gtonefactor = (g>0 ? (float)hltonecurve[g]/g : (float)hltonecurve[1]); + float btonefactor = (b>0 ? (float)hltonecurve[b]/b : (float)hltonecurve[1]); //float tonefactor = MIN(rtonefactor, MIN(gtonefactor,btonefactor)); float tonefactor = (rtonefactor+gtonefactor+btonefactor)/3; //float tonefactor = (0.299*rtonefactor+0.587*gtonefactor+0.114*btonefactor); @@ -360,6 +358,8 @@ void ImProcFunctions::rgbProc (Image16* working, LabImage* lab, int* hltonecurve } hsv2rgb(h,s,v,r,g,b); } + //hsv2rgb(h,s,v,r,g,b); + int x = (toxyz[0][0] * r + toxyz[1][0] * g + toxyz[2][0] * b) >> 15; int y = (toxyz[0][1] * r + toxyz[1][1] * g + toxyz[2][1] * b) >> 15; diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 84c6dc99e..d9c3730e2 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -79,7 +79,7 @@ class ImProcFunctions { bool needsTransform (); void firstAnalysis (Image16* working, const ProcParams* params, unsigned int* vhist16, double gamma); - void rgbProc (Image16* working, LabImage* lab, int* hltonecurve, int* shtonecurve, int* tonecurve, SHMap* shmap, int sat); + void rgbProc (Image16* working, LabImage* lab, float* hltonecurve, float* shtonecurve, int* tonecurve, SHMap* shmap, int sat); void luminanceCurve (LabImage* lold, LabImage* lnew, int* curve, int row_from, int row_to); void chrominanceCurve (LabImage* lold, LabImage* lnew, int channel, int* curve, int row_from, int row_to); void colorCurve (LabImage* lold, LabImage* lnew); diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index f2b12b8c6..d19bd3b06 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -400,8 +400,8 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, int rhei if (params.toneCurve.autoexp && aeHistogram) ipf.getAutoExp (aeHistogram, aeHistCompression, logDefGain, params.toneCurve.clip, br, bl); - int* curve1 = new int [65536]; - int* curve2 = new int [65536]; + float* curve1 = new float [65536]; + float* curve2 = new float [65536]; int* curve = new int [65536]; CurveFactory::complexCurve (br, bl/65535.0, params.toneCurve.hlcompr, params.toneCurve.shcompr, params.toneCurve.brightness, params.toneCurve.contrast, logDefGain, isRaw ? 2.2 : 0, true, params.toneCurve.curve, hist16, curve1, curve2, curve, NULL, 16); @@ -420,10 +420,10 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, int rhei // luminance processing CurveFactory::complexCurve (0.0, 0.0, 0.0, 0.0, params.labCurve.brightness, params.labCurve.contrast, 0.0, 0.0, false, params.labCurve.lcurve, hist16, curve1, curve2, curve, NULL, 16); ipf.luminanceCurve (labView, labView, curve, 0, fh); - CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.acurve, curve1, 16); - ipf.chrominanceCurve (labView, labView, 0, curve1, 0, fh); - CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.bcurve, curve1, 16); - ipf.chrominanceCurve (labView, labView, 1, curve1, 0, fh); + CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.acurve, curve, 16); + ipf.chrominanceCurve (labView, labView, 0, curve, 0, fh); + CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.bcurve, curve, 16); + ipf.chrominanceCurve (labView, labView, 1, curve, 0, fh); delete [] curve1; delete [] curve2; diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 0f28e868b..f17618b59 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -128,8 +128,8 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p ipf.getAutoExp (aehist, aehistcompr, imgsrc->getDefGain(), params.toneCurve.clip, br, bl); } - int* curve1 = new int [65536]; - int* curve2 = new int [65536]; + float* curve1 = new float [65536]; + float* curve2 = new float [65536]; int* curve = new int [65536]; CurveFactory::complexCurve (br, bl/65535.0, params.toneCurve.hlcompr, params.toneCurve.shcompr, params.toneCurve.brightness, params.toneCurve.contrast, imgsrc->getDefGain(), imgsrc->getGamma(), true, params.toneCurve.curve, hist16, curve1, curve2, curve, NULL); @@ -153,10 +153,10 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p // luminance processing CurveFactory::complexCurve (0.0, 0.0, 0.0, 0.0, params.labCurve.brightness, params.labCurve.contrast, 0.0, 0.0, false, params.labCurve.lcurve, hist16, curve1, curve2, curve, NULL); ipf.luminanceCurve (labView, labView, curve, 0, fh); - CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.acurve, curve1, 1); - ipf.chrominanceCurve (labView, labView, 0, curve1, 0, fh); - CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.bcurve, curve1, 1); - ipf.chrominanceCurve (labView, labView, 1, curve1, 0, fh); + CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.acurve, curve, 1); + ipf.chrominanceCurve (labView, labView, 0, curve, 0, fh); + CurveFactory::complexsgnCurve (0.0, 100.0, params.labCurve.saturation, 1.0, params.labCurve.bcurve, curve, 1); + ipf.chrominanceCurve (labView, labView, 1, curve, 0, fh); ipf.impulsedenoise (labView); ipf.lumadenoise (labView, buffer);