From 9da7de408069e021bd6a20a922fb1d7d4f0fec99 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Sat, 14 May 2016 12:04:02 +0200 Subject: [PATCH] Fixed a bug I introduced with last commit and changed argument order of Ciecam02::curveJfloat --- rtengine/ciecam02.cc | 11 ++++++++--- rtengine/ciecam02.h | 2 +- rtengine/improcfun.cc | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rtengine/ciecam02.cc b/rtengine/ciecam02.cc index ae9460bff..3bbc261cf 100644 --- a/rtengine/ciecam02.cc +++ b/rtengine/ciecam02.cc @@ -180,7 +180,7 @@ void Ciecam02::curveJ (double br, double contr, int db, LUTf & outCurve, LUTu & } } -void Ciecam02::curveJfloat (float br, float contr, LUTf & outCurve, const LUTu & histogram ) +void Ciecam02::curveJfloat (float br, float contr, const LUTu & histogram, LUTf & outCurve) { // check if brightness curve is needed @@ -233,10 +233,15 @@ void Ciecam02::curveJfloat (float br, float contr, LUTf & outCurve, const LUTu & if (contr > 0.00001f || contr < -0.00001f) { // compute mean luminance of the image with the curve applied - float sum, avg; + float sum = 0.f; + float avg = 0.f; - histogram.getSumAndAverage(sum, avg); + for (int i = 0; i < 32768; i++) { + avg += outCurve[i] * histogram[i];//approximation for average : usage of L (lab) instead of J + sum += histogram[i]; + } + avg /= sum; std::vector contrastcurvePoints(9); contrastcurvePoints[0] = double(DCT_NURBS); diff --git a/rtengine/ciecam02.h b/rtengine/ciecam02.h index 927b69b0e..199d03f59 100644 --- a/rtengine/ciecam02.h +++ b/rtengine/ciecam02.h @@ -74,7 +74,7 @@ public: static void curvecolor(double satind, double satval, double &sres, double parsat); static void curvecolorfloat(float satind, float satval, float &sres, float parsat); static void curveJ (double br, double contr, int db, LUTf & outCurve , LUTu & histogram ) ; - static void curveJfloat (float br, float contr, LUTf & outCurve , const LUTu & histogram ) ; + static void curveJfloat (float br, float contr, const LUTu & histogram, LUTf & outCurve ) ; /** * Inverse transform from CIECAM02 JCh to XYZ. diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 786ec0b38..eb95510be 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -1790,7 +1790,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float jli = params->colorappearance.jlight; float contra = params->colorappearance.contrast; - Ciecam02::curveJfloat (jli, contra, CAMBrightCurveJ, hist16J);//lightness and contrast J + Ciecam02::curveJfloat (jli, contra, hist16J, CAMBrightCurveJ);//lightness and contrast J } if (needQ) { @@ -1802,7 +1802,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float qbri = params->colorappearance.qbright; float qcontra = params->colorappearance.qcontrast; - Ciecam02::curveJfloat (qbri, qcontra, CAMBrightCurveQ, hist16Q);//brightness and contrast Q + Ciecam02::curveJfloat (qbri, qcontra, hist16Q, CAMBrightCurveQ);//brightness and contrast Q } }