diff --git a/rtdata/languages/default b/rtdata/languages/default index 46b2041451..2bc74bf8a9 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -972,10 +972,6 @@ PREFERENCES_CACHECLEARTHUMBS;Clear Thumbnails PREFERENCES_CACHEMAXENTRIES;Maximum number of cache entries PREFERENCES_CACHEOPTS;Cache Options PREFERENCES_CACHETHUMBHEIGHT;Maximum thumbnail height -PREFERENCES_CIEART;CIECAM02 optimization -PREFERENCES_CIEART_FRAME;CIECAM02-Specific Settings -PREFERENCES_CIEART_LABEL;Use float precision instead of double -PREFERENCES_CIEART_TOOLTIP;If enabled, CIECAM02 calculations are performed in the single-precision floating-point format instead of the double-precision one. This provides a small increase in speed at the expense of a negligible loss of quality. PREFERENCES_CLIPPINGIND;Clipping Indication PREFERENCES_CLUTSCACHE;HaldCLUT Cache PREFERENCES_CLUTSCACHE_LABEL;Maximum number of cached CLUTs diff --git a/rtengine/ciecam02.cc b/rtengine/ciecam02.cc index 560d5721a7..f9475eb4e1 100644 --- a/rtengine/ciecam02.cc +++ b/rtengine/ciecam02.cc @@ -38,25 +38,6 @@ namespace rtengine extern const Settings* settings; #endif -void Ciecam02::curvecolor (double satind, double satval, double &sres, double parsat) -{ - if (satind >= 0.0) { - sres = (1. - (satind) / 100.) * satval + (satind) / 100.* (1. - SQR (SQR (1. - min (satval, 1.0)))); - - if (sres > parsat) { - sres = parsat; - } - - if (sres < 0.) { - sres = 0.; - } - } else { - if (satind < -0.1) { - sres = satval * (1. + (satind) / 100.); - } - } -} - void Ciecam02::curvecolorfloat (float satind, float satval, float &sres, float parsat) { if (satind > 0.f) { @@ -76,111 +57,6 @@ void Ciecam02::curvecolorfloat (float satind, float satval, float &sres, float p } } -void Ciecam02::curveJ (double br, double contr, int db, LUTf & outCurve, LUTu & histogram ) -{ - LUTf dcurve (65536, 0); - int skip = 1; - - // check if brightness curve is needed - if (br > 0.00001 || br < -0.00001) { - - std::vector brightcurvePoints; - brightcurvePoints.resize (9); - brightcurvePoints.at (0) = double (DCT_NURBS); - - brightcurvePoints.at (1) = 0.; // black point. Value in [0 ; 1] range - brightcurvePoints.at (2) = 0.; // black point. Value in [0 ; 1] range - - if (br > 0) { - brightcurvePoints.at (3) = 0.1; // toe point - brightcurvePoints.at (4) = 0.1 + br / 150.0; //value at toe point - - brightcurvePoints.at (5) = 0.7; // shoulder point - brightcurvePoints.at (6) = min (1.0, 0.7 + br / 300.0); //value at shoulder point - } else { - brightcurvePoints.at (3) = 0.1 - br / 150.0; // toe point - brightcurvePoints.at (4) = 0.1; // value at toe point - - brightcurvePoints.at (5) = min (1.0, 0.7 - br / 300.0); // shoulder point - brightcurvePoints.at (6) = 0.7; // value at shoulder point - } - - brightcurvePoints.at (7) = 1.; // white point - brightcurvePoints.at (8) = 1.; // value at white point - - DiagonalCurve* brightcurve = new DiagonalCurve (brightcurvePoints, CURVES_MIN_POLY_POINTS / skip); - - // Applying brightness curve - for (int i = 0; i < 32768; i++) { - - // change to [0,1] range - float val = (float)i / 32767.0; - - // apply brightness curve - val = brightcurve->getVal (val); - - // store result in a temporary array - dcurve[i] = CLIPD (val); - } - - delete brightcurve; - } else { - // for (int i=0; i<32768; i++) { // L values range up to 32767, higher values are for highlight overflow - for (int i = 0; i < (32768 * db); i++) { // L values range up to 32767, higher values are for highlight overflow - - // set the identity curve in the temporary array - dcurve[i] = (float)i / (db * 32768.0f); - } - } - - - if (contr > 0.00001 || contr < -0.00001) { - - // compute mean luminance of the image with the curve applied - int sum = 0; - float avg = 0; - - //float sqavg = 0; - for (int i = 0; i < 32768; i++) { - avg += dcurve[i] * histogram[i];//approximation for average : usage of L (lab) instead of J - sum += histogram[i]; - } - - avg /= sum; - std::vector contrastcurvePoints; - contrastcurvePoints.resize (9); - contrastcurvePoints.at (0) = double (DCT_NURBS); - - contrastcurvePoints.at (1) = 0.; // black point. Value in [0 ; 1] range - contrastcurvePoints.at (2) = 0.; // black point. Value in [0 ; 1] range - - contrastcurvePoints.at (3) = avg - avg * (0.6 - contr / 250.0); // toe point - contrastcurvePoints.at (4) = avg - avg * (0.6 + contr / 250.0); // value at toe point - - contrastcurvePoints.at (5) = avg + (1 - avg) * (0.6 - contr / 250.0); // shoulder point - contrastcurvePoints.at (6) = avg + (1 - avg) * (0.6 + contr / 250.0); // value at shoulder point - - contrastcurvePoints.at (7) = 1.; // white point - contrastcurvePoints.at (8) = 1.; // value at white point - - DiagonalCurve* contrastcurve = new DiagonalCurve (contrastcurvePoints, CURVES_MIN_POLY_POINTS / skip); - - // apply contrast enhancement - for (int i = 0; i < (32768 * db); i++) { - dcurve[i] = contrastcurve->getVal (dcurve[i]); - } - - delete contrastcurve; - } - - // for (int i=0; i<32768; i++) outCurve[i] = 32768.0*dcurve[i]; - for (int i = 0; i < (db * 32768); i++) { - outCurve[i] = db * 32768.0 * dcurve[i]; - } -// printf("double out500=%f out15000=%f\n", outCurve[500], outCurve[15000]); - -} - void Ciecam02::curveJfloat (float br, float contr, const LUTu & histogram, LUTf & outCurve) { @@ -298,28 +174,11 @@ void Ciecam02::curveJfloat (float br, float contr, const LUTu & histogram, LUTf * */ -double Ciecam02::d_factor ( double f, double la ) -{ - return f * (1.0 - ((1.0 / 3.6) * exp ((-la - 42.0) / 92.0))); -} - float Ciecam02::d_factorfloat ( float f, float la ) { return f * (1.0f - ((1.0f / 3.6f) * xexpf ((-la - 42.0f) / 92.0f))); } -double Ciecam02::calculate_fl_from_la_ciecam02 ( double la ) -{ - double la5 = la * 5.0; - double k = 1.0 / (la5 + 1.0); - - /* Calculate k^4. */ - k = k * k; - k = k * k; - - return (0.2 * k * la5) + (0.1 * (1.0 - k) * (1.0 - k) * std::cbrt (la5)); -} - float Ciecam02::calculate_fl_from_la_ciecam02float ( float la ) { float la5 = la * 5.0f; @@ -332,34 +191,6 @@ float Ciecam02::calculate_fl_from_la_ciecam02float ( float la ) return (0.2f * k * la5) + (0.1f * (1.0f - k) * (1.0f - k) * std::cbrt (la5)); } -double Ciecam02::achromatic_response_to_white ( double x, double y, double z, double d, double fl, double nbb, int gamu ) -{ - double r, g, b; - double rc, gc, bc; - double rp, gp, bp; - double rpa, gpa, bpa; - gamu = 1; - xyz_to_cat02 ( r, g, b, x, y, z, gamu ); - - rc = r * (((y * d) / r) + (1.0 - d)); - gc = g * (((y * d) / g) + (1.0 - d)); - bc = b * (((y * d) / b) + (1.0 - d)); - - cat02_to_hpe ( rp, gp, bp, rc, gc, bc, gamu ); - - if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk - rp = MAXR (rp, 0.0); - gp = MAXR (gp, 0.0); - bp = MAXR (bp, 0.0); - } - - rpa = nonlinear_adaptation ( rp, fl ); - gpa = nonlinear_adaptation ( gp, fl ); - bpa = nonlinear_adaptation ( bp, fl ); - - return ((2.0 * rpa) + gpa + ((1.0 / 20.0) * bpa) - 0.305) * nbb; -} - float Ciecam02::achromatic_response_to_whitefloat ( float x, float y, float z, float d, float fl, float nbb, int gamu ) { float r, g, b; @@ -388,24 +219,6 @@ float Ciecam02::achromatic_response_to_whitefloat ( float x, float y, float z, f return ((2.0f * rpa) + gpa + ((1.0f / 20.0f) * bpa) - 0.305f) * nbb; } -void Ciecam02::xyz_to_cat02 ( double &r, double &g, double &b, double x, double y, double z, int gamu ) -{ - gamu = 1; - - if (gamu == 0) { - r = ( 0.7328 * x) + (0.4296 * y) - (0.1624 * z); - g = (-0.7036 * x) + (1.6975 * y) + (0.0061 * z); - b = ( 0.0030 * x) + (0.0136 * y) + (0.9834 * z); - } else if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk - //r = ( 0.7328 * x) + (0.4296 * y) - (0.1624 * z); - //g = (-0.7036 * x) + (1.6975 * y) + (0.0061 * z); - //b = ( 0.0000 * x) + (0.0000 * y) + (1.0000 * z); - r = ( 1.007245 * x) + (0.011136 * y) - (0.018381 * z); //Changjun Li - g = (-0.318061 * x) + (1.314589 * y) + (0.003471 * z); - b = ( 0.0000 * x) + (0.0000 * y) + (1.0000 * z); - } -} - void Ciecam02::xyz_to_cat02float ( float &r, float &g, float &b, float x, float y, float z, int gamu ) { gamu = 1; @@ -433,24 +246,6 @@ void Ciecam02::xyz_to_cat02float ( vfloat &r, vfloat &g, vfloat &b, vfloat x, vf } #endif -void Ciecam02::cat02_to_xyz ( double &x, double &y, double &z, double r, double g, double b, int gamu ) -{ - gamu = 1; - - if (gamu == 0) { - x = ( 1.096124 * r) - (0.278869 * g) + (0.182745 * b); - y = ( 0.454369 * r) + (0.473533 * g) + (0.072098 * b); - z = (-0.009628 * r) - (0.005698 * g) + (1.015326 * b); - } else if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk - //x = ( 1.0978566 * r) - (0.277843 * g) + (0.179987 * b); - //y = ( 0.455053 * r) + (0.473938 * g) + (0.0710096* b); - //z = ( 0.000000 * r) - (0.000000 * g) + (1.000000 * b); - x = ( 0.99015849 * r) - (0.00838772 * g) + (0.018229217 * b); //Changjun Li - y = ( 0.239565979 * r) + (0.758664642 * g) + (0.001770137 * b); - z = ( 0.000000 * r) - (0.000000 * g) + (1.000000 * b); - } -} - void Ciecam02::cat02_to_xyzfloat ( float &x, float &y, float &z, float r, float g, float b, int gamu ) { gamu = 1; @@ -478,14 +273,6 @@ void Ciecam02::cat02_to_xyzfloat ( vfloat &x, vfloat &y, vfloat &z, vfloat r, vf } #endif -void Ciecam02::hpe_to_xyz ( double &x, double &y, double &z, double r, double g, double b ) -{ - x = (1.910197 * r) - (1.112124 * g) + (0.201908 * b); - y = (0.370950 * r) + (0.629054 * g) - (0.000008 * b); - z = b; -} - - void Ciecam02::hpe_to_xyzfloat ( float &x, float &y, float &z, float r, float g, float b ) { x = (1.910197f * r) - (1.112124f * g) + (0.201908f * b); @@ -501,21 +288,6 @@ void Ciecam02::hpe_to_xyzfloat ( vfloat &x, vfloat &y, vfloat &z, vfloat r, vflo } #endif -void Ciecam02::cat02_to_hpe ( double &rh, double &gh, double &bh, double r, double g, double b, int gamu ) -{ - gamu = 1; - - if (gamu == 0) { - rh = ( 0.7409792 * r) + (0.2180250 * g) + (0.0410058 * b); - gh = ( 0.2853532 * r) + (0.6242014 * g) + (0.0904454 * b); - bh = (-0.0096280 * r) - (0.0056980 * g) + (1.0153260 * b); - } else if (gamu == 1) { //Changjun Li - rh = ( 0.550930835 * r) + (0.519435987 * g) - ( 0.070356303 * b); - gh = ( 0.055954056 * r) + (0.89973132 * g) + (0.044315524 * b); - bh = (0.0 * r) - (0.0 * g) + (1.0 * b); - } -} - void Ciecam02::cat02_to_hpefloat ( float &rh, float &gh, float &bh, float r, float g, float b, int gamu ) { gamu = 1; @@ -541,18 +313,6 @@ void Ciecam02::cat02_to_hpefloat ( vfloat &rh, vfloat &gh, vfloat &bh, vfloat r, } #endif -void Ciecam02::Aab_to_rgb ( double &r, double &g, double &b, double A, double aa, double bb, double nbb ) -{ - double x = (A / nbb) + 0.305; - - /* c1 c2 c3 */ - r = (0.32787 * x) + (0.32145 * aa) + (0.20527 * bb); - /* c1 c4 c5 */ - g = (0.32787 * x) - (0.63507 * aa) - (0.18603 * bb); - /* c1 c6 c7 */ - b = (0.32787 * x) - (0.15681 * aa) - (4.49038 * bb); -} - void Ciecam02::Aab_to_rgbfloat ( float &r, float &g, float &b, float A, float aa, float bb, float nbb ) { float x = (A / nbb) + 0.305f; @@ -578,34 +338,6 @@ void Ciecam02::Aab_to_rgbfloat ( vfloat &r, vfloat &g, vfloat &b, vfloat A, vflo } #endif -void Ciecam02::calculate_ab ( double &aa, double &bb, double h, double e, double t, double nbb, double a ) -{ - double hrad = (h * rtengine::RT_PI) / 180.0; - double sinh = sin ( hrad ); - double cosh = cos ( hrad ); - double x = (a / nbb) + 0.305; - double p3 = 21.0 / 20.0; - - if ( fabs ( sinh ) >= fabs ( cosh ) ) { - bb = ((0.32787 * x) * (2.0 + p3)) / - ((e / (t * sinh)) - - // ((0.32145 - 0.63507 - (p3 * 0.15681)) * (cosh / sinh)) - - // (0.20527 - 0.18603 - (p3 * 4.49038))); - ((-0.31362 - (p3 * 0.15681)) * (cosh / sinh)) - - (0.01924 - (p3 * 4.49038))); - - aa = (bb * cosh) / sinh; - } else { - aa = ((0.32787 * x) * (2.0 + p3)) / - ((e / (t * cosh)) - - // (0.32145 - 0.63507 - (p3 * 0.15681)) - - // ((0.20527 - 0.18603 - (p3 * 4.49038)) * (sinh / cosh))); - (-0.31362 - (p3 * 0.15681)) - - ((0.01924 - (p3 * 4.49038)) * (sinh / cosh))); - - bb = (aa * sinh) / cosh; - } -} void Ciecam02::calculate_abfloat ( float &aa, float &bb, float h, float e, float t, float nbb, float a ) { float2 sincosval = xsincosf(h * rtengine::RT_PI_F_180); @@ -675,32 +407,6 @@ void Ciecam02::calculate_abfloat ( vfloat &aa, vfloat &bb, vfloat h, vfloat e, v #endif -void Ciecam02::initcam1 (double gamu, double yb, double pilotd, double f, double la, double xw, double yw, double zw, double &n, double &d, double &nbb, double &ncb, - double &cz, double &aw, double &wh, double &pfl, double &fl, double &c) -{ - n = yb / yw; - - if (pilotd == 2.0) { - d = d_factor ( f, la ); - } else { - d = pilotd; - } - - fl = calculate_fl_from_la_ciecam02 ( la ); - nbb = ncb = 0.725 * pow ( 1.0 / n, 0.2 ); - cz = 1.48 + sqrt ( n ); - aw = achromatic_response_to_white ( xw, yw, zw, d, fl, nbb, gamu ); - wh = ( 4.0 / c ) * ( aw + 4.0 ) * pow ( fl, 0.25 ); - pfl = pow ( fl, 0.25 ); -#ifdef _DEBUG - - if (settings->verbose) { - printf ("Source double d=%f aw=%f fl=%f wh=%f\n", d, aw, fl, wh); - } - -#endif -} - void Ciecam02::initcam1float (float gamu, float yb, float pilotd, float f, float la, float xw, float yw, float zw, float &n, float &d, float &nbb, float &ncb, float &cz, float &aw, float &wh, float &pfl, float &fl, float &c) { @@ -727,31 +433,6 @@ void Ciecam02::initcam1float (float gamu, float yb, float pilotd, float f, float #endif } -void Ciecam02::initcam2 (double gamu, double yb, double pilotd, double f, double la, double xw, double yw, double zw, double &n, double &d, double &nbb, double &ncb, - double &cz, double &aw, double &fl) -{ - n = yb / yw; - - if (pilotd == 2.0) { - d = d_factorfloat ( f, la ); - } else { - d = pilotd; - } - -// d = d_factor( f, la ); - fl = calculate_fl_from_la_ciecam02 ( la ); - nbb = ncb = 0.725 * pow ( 1.0 / n, 0.2 ); - cz = 1.48 + sqrt ( n ); - aw = achromatic_response_to_white ( xw, yw, zw, d, fl, nbb, gamu ); -#ifdef _DEBUG - - if (settings->verbose) { - printf ("Viewing double d=%f aw=%f fl=%f n=%f\n", d, aw, fl, n); - } - -#endif -} - void Ciecam02::initcam2float (float gamu, float yb, float pilotd, float f, float la, float xw, float yw, float zw, float &n, float &d, float &nbb, float &ncb, float &cz, float &aw, float &fl) { @@ -777,89 +458,6 @@ void Ciecam02::initcam2float (float gamu, float yb, float pilotd, float f, float #endif } -void Ciecam02::xyz2jchqms_ciecam02 ( double &J, double &C, double &h, double &Q, double &M, double &s, double &aw, double &fl, double &wh, - double x, double y, double z, double xw, double yw, double zw, - double c, double nc, int gamu, double n, double nbb, double ncb, double pfl, double cz, double d) -{ - double r, g, b; - double rw, gw, bw; - double rc, gc, bc; - double rp, gp, bp; - double rpa, gpa, bpa; - double a, ca, cb; - double e, t; - double myh; - gamu = 1; - xyz_to_cat02 ( r, g, b, x, y, z, gamu ); - xyz_to_cat02 ( rw, gw, bw, xw, yw, zw, gamu ); - rc = r * (((yw * d) / rw) + (1.0 - d)); - gc = g * (((yw * d) / gw) + (1.0 - d)); - bc = b * (((yw * d) / bw) + (1.0 - d)); - - cat02_to_hpe ( rp, gp, bp, rc, gc, bc, gamu ); - - if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk - rp = MAXR (rp, 0.0); - gp = MAXR (gp, 0.0); - bp = MAXR (bp, 0.0); - } - - rpa = nonlinear_adaptation ( rp, fl ); - gpa = nonlinear_adaptation ( gp, fl ); - bpa = nonlinear_adaptation ( bp, fl ); - - ca = rpa - ((12.0 * gpa) / 11.0) + (bpa / 11.0); - cb = (1.0 / 9.0) * (rpa + gpa - (2.0 * bpa)); - - myh = (180.0 / rtengine::RT_PI) * atan2 ( cb, ca ); - - if ( myh < 0.0 ) { - myh += 360.0; - } - - //we can also calculate H, if necessary...but it's using time...for what usage ? - /*double temp; - if(myh<20.14) { - temp = ((myh + 122.47)/1.2) + ((20.14 - myh)/0.8); - H = 300 + (100*((myh + 122.47)/1.2)) / temp; - } - else if(myh < 90.0) { - temp = ((myh - 20.14)/0.8) + ((90.00 - myh)/0.7); - H = (100*((myh - 20.14)/0.8)) / temp; - } - else if (myh < 164.25) { - temp = ((myh - 90.00)/0.7) + ((164.25 - myh)/1.0); - H = 100 + ((100*((myh - 90.00)/0.7)) / temp); - } - else if (myh < 237.53) { - temp = ((myh - 164.25)/1.0) + ((237.53 - myh)/1.2); - H = 200 + ((100*((myh - 164.25)/1.0)) / temp); - } - else { - temp = ((myh - 237.53)/1.2) + ((360 - myh + 20.14)/0.8); - H = 300 + ((100*((myh - 237.53)/1.2)) / temp); - } - */ - a = ((2.0 * rpa) + gpa + ((1.0 / 20.0) * bpa) - 0.305) * nbb; - - if (gamu == 1) { - a = MAXR (a, 0.0); //gamut correction M.H.Brill S.Susstrunk - } - - J = 100.0 * pow ( a / aw, c * cz ); - - e = ((12500.0 / 13.0) * nc * ncb) * (cos ( ((myh * rtengine::RT_PI) / 180.0) + 2.0 ) + 3.8); - t = (e * sqrt ( (ca * ca) + (cb * cb) )) / (rpa + gpa + ((21.0 / 20.0) * bpa)); - - C = pow ( t, 0.9 ) * sqrt ( J / 100.0 ) - * pow ( 1.64 - pow ( 0.29, n ), 0.73 ); - - Q = wh * sqrt ( J / 100.0 ); - M = C * pfl; - s = 100.0 * sqrt ( M / Q ); - h = myh; -} - void Ciecam02::xyz2jchqms_ciecam02float ( float &J, float &C, float &h, float &Q, float &M, float &s, float aw, float fl, float wh, float x, float y, float z, float xw, float yw, float zw, float c, float nc, int gamu, float pow1, float nbb, float ncb, float pfl, float cz, float d) @@ -1046,41 +644,6 @@ void Ciecam02::xyz2jch_ciecam02float ( float &J, float &C, float &h, float aw, f h = (myh * 180.f) / (float)rtengine::RT_PI; } - -void Ciecam02::jch2xyz_ciecam02 ( double &x, double &y, double &z, double J, double C, double h, - double xw, double yw, double zw, - double c, double nc, int gamu, double n, double nbb, double ncb, double fl, double cz, double d, double aw ) -{ - double r, g, b; - double rc, gc, bc; - double rp, gp, bp; - double rpa, gpa, bpa; - double rw, gw, bw; - double a, ca, cb; - double e, t; - gamu = 1; - xyz_to_cat02 ( rw, gw, bw, xw, yw, zw, gamu ); - e = ((12500.0 / 13.0) * nc * ncb) * (cos ( ((h * rtengine::RT_PI) / 180.0) + 2.0 ) + 3.8); - a = pow ( J / 100.0, 1.0 / (c * cz) ) * aw; - t = pow ( C / (sqrt ( J / 100) * pow ( 1.64 - pow ( 0.29, n ), 0.73 )), 10.0 / 9.0 ); - - calculate_ab ( ca, cb, h, e, t, nbb, a ); - Aab_to_rgb ( rpa, gpa, bpa, a, ca, cb, nbb ); - - rp = inverse_nonlinear_adaptation ( rpa, fl ); - gp = inverse_nonlinear_adaptation ( gpa, fl ); - bp = inverse_nonlinear_adaptation ( bpa, fl ); - - hpe_to_xyz ( x, y, z, rp, gp, bp ); - xyz_to_cat02 ( rc, gc, bc, x, y, z, gamu ); - - r = rc / (((yw * d) / rw) + (1.0 - d)); - g = gc / (((yw * d) / gw) + (1.0 - d)); - b = bc / (((yw * d) / bw) + (1.0 - d)); - - cat02_to_xyz ( x, y, z, r, g, b, gamu ); -} - void Ciecam02::jch2xyz_ciecam02float ( float &x, float &y, float &z, float J, float C, float h, float xw, float yw, float zw, float c, float nc, int gamu, float pow1, float nbb, float ncb, float fl, float cz, float d, float aw) @@ -1167,19 +730,6 @@ void Ciecam02::jch2xyz_ciecam02float ( vfloat &x, vfloat &y, vfloat &z, vfloat J } #endif -double Ciecam02::nonlinear_adaptation ( double c, double fl ) -{ - double p; - - if (c < 0.0) { - p = pow ( (-1.0 * fl * c) / 100.0, 0.42 ); - return ((-1.0 * 400.0 * p) / (27.13 + p)) + 0.1; - } else { - p = pow ( (fl * c) / 100.0, 0.42 ); - return ((400.0 * p) / (27.13 + p)) + 0.1; - } -} - float Ciecam02::nonlinear_adaptationfloat ( float c, float fl ) { float p; @@ -1207,19 +757,6 @@ vfloat Ciecam02::nonlinear_adaptationfloat ( vfloat c, vfloat fl ) } #endif -double Ciecam02::inverse_nonlinear_adaptation ( double c, double fl ) -{ - int c1; - - if (c - 0.1 < 0.0) { - c1 = -1; - } else { - c1 = 1; - } - - return c1 * (100.0 / fl) * pow ( (27.13 * fabs ( c - 0.1 )) / (400.0 - fabs ( c - 0.1 )), 1.0 / 0.42 ); -} - float Ciecam02::inverse_nonlinear_adaptationfloat ( float c, float fl ) { c -= 0.1f; diff --git a/rtengine/ciecam02.h b/rtengine/ciecam02.h index 55d807b7e1..d55b1a4059 100644 --- a/rtengine/ciecam02.h +++ b/rtengine/ciecam02.h @@ -28,17 +28,9 @@ namespace rtengine class Ciecam02 { private: - static double d_factor ( double f, double la ); static float d_factorfloat ( float f, float la ); - static double calculate_fl_from_la_ciecam02 ( double la ); static float calculate_fl_from_la_ciecam02float ( float la ); - static double achromatic_response_to_white ( double x, double y, double z, double d, double fl, double nbb, int gamu ); static float achromatic_response_to_whitefloat ( float x, float y, float z, float d, float fl, float nbb, int gamu ); - static void xyz_to_cat02 ( double &r, double &g, double &b, double x, double y, double z, int gamu ); - static void cat02_to_hpe ( double &rh, double &gh, double &bh, double r, double g, double b, int gamu ); - static void cat02_to_xyz ( double &x, double &y, double &z, double r, double g, double b, int gamu ); - static void hpe_to_xyz ( double &x, double &y, double &z, double r, double g, double b ); - static void xyz_to_cat02float ( float &r, float &g, float &b, float x, float y, float z, int gamu ); static void cat02_to_hpefloat ( float &rh, float &gh, float &bh, float r, float g, float b, int gamu ); @@ -48,13 +40,7 @@ class Ciecam02 static vfloat nonlinear_adaptationfloat ( vfloat c, vfloat fl ); #endif - static void Aab_to_rgb ( double &r, double &g, double &b, double A, double aa, double bb, double nbb ); - static void calculate_ab ( double &aa, double &bb, double h, double e, double t, double nbb, double a ); - - static double nonlinear_adaptation ( double c, double fl ); static float nonlinear_adaptationfloat ( float c, float fl ); - static double inverse_nonlinear_adaptation ( double c, double fl ); - static float inverse_nonlinear_adaptationfloat ( float c, float fl ); static void calculate_abfloat ( float &aa, float &bb, float h, float e, float t, float nbb, float a ); @@ -71,20 +57,12 @@ class Ciecam02 public: Ciecam02 () {} - 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, const LUTu & histogram, LUTf & outCurve ) ; /** * Inverse transform from CIECAM02 JCh to XYZ. */ - static void jch2xyz_ciecam02 ( double &x, double &y, double &z, - double J, double C, double h, - double xw, double yw, double zw, - double c, double nc, int gamu, double n, double nbb, double ncb, double fl, double cz, double d, double aw); - - static void jch2xyz_ciecam02float ( float &x, float &y, float &z, float J, float C, float h, float xw, float yw, float zw, @@ -98,24 +76,12 @@ class Ciecam02 /** * Forward transform from XYZ to CIECAM02 JCh. */ - static void initcam1 (double gamu, double yb, double pilotd, double f, double la, double xw, double yw, double zw, double &n, double &d, double &nbb, double &ncb, - double &cz, double &aw, double &wh, double &pfl, double &fl, double &c); - - static void initcam2 (double gamu, double yb, double pilotd, double f, double la, double xw, double yw, double zw, double &n, double &d, double &nbb, double &ncb, - double &cz, double &aw, double &fl); - static void initcam1float (float gamu, float yb, float pilotd, float f, float la, float xw, float yw, float zw, float &n, float &d, float &nbb, float &ncb, float &cz, float &aw, float &wh, float &pfl, float &fl, float &c); static void initcam2float (float gamu, float yb, float pilotd, float f, float la, float xw, float yw, float zw, float &n, float &d, float &nbb, float &ncb, float &cz, float &aw, float &fl); - static void xyz2jchqms_ciecam02 ( double &J, double &C, double &h, - double &Q, double &M, double &s, double &aw, double &fl, double &wh, - double x, double y, double z, - double xw, double yw, double zw, - double c, double nc, int gamu, double n, double nbb, double ncb, double pfl, double cz, double d ); - static void xyz2jch_ciecam02float ( float &J, float &C, float &h, float aw, float fl, float x, float y, float z, diff --git a/rtengine/colortemp.h b/rtengine/colortemp.h index 145c8ed207..d529d844e4 100644 --- a/rtengine/colortemp.h +++ b/rtengine/colortemp.h @@ -96,8 +96,6 @@ class ColorTemp static void temp2mulxyz (double tem, const std::string &method, double &Xxyz, double &Zxyz); static void cieCAT02(double Xw, double Yw, double Zw, double &CAM02BB00, double &CAM02BB01, double &CAM02BB02, double &CAM02BB10, double &CAM02BB11, double &CAM02BB12, double &CAM02BB20, double &CAM02BB21, double &CAM02BB22, double adap ); - //static void CAT02 (Imagefloat* baseImg, const ProcParams* params); - //static void ciecam_02 (LabImage* lab, const ProcParams* params); bool operator== (const ColorTemp& other) const { diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 482b64a559..079a5de16a 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -1026,16 +1026,9 @@ void Crop::update (int todo) cieCrop = new CieImage (cropw, croph); } - if (settings->ciecamfloat) { - float d, dj, yb; // not used after this block - parent->ipf.ciecam_02float (cieCrop, float (adap), 1, 2, labnCrop, ¶ms, parent->customColCurve1, parent->customColCurve2, parent->customColCurve3, + float d, dj, yb; // not used after this block + parent->ipf.ciecam_02float (cieCrop, float (adap), 1, 2, labnCrop, ¶ms, parent->customColCurve1, parent->customColCurve2, parent->customColCurve3, dummy, dummy, parent->CAMBrightCurveJ, parent->CAMBrightCurveQ, parent->CAMMean, 5, skip, execsharp, d, dj, yb, 1); - } else { - double dd, dj; // not used after this block - - parent->ipf.ciecam_02 (cieCrop, adap, 1, 2, labnCrop, ¶ms, parent->customColCurve1, parent->customColCurve2, parent->customColCurve3, - dummy, dummy, parent->CAMBrightCurveJ, parent->CAMBrightCurveQ, parent->CAMMean, 5, skip, execsharp, dd, dj, 1); - } } else { // CIECAM is disabled, we free up its image buffer to save some space if (cieCrop) { diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index f47eb81462..08fe8db0e1 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -459,1294 +459,6 @@ void ImProcFunctions::firstAnalysis (const Imagefloat* const original, const Pro } } -// Copyright (c) 2012 Jacques Desmis -void ImProcFunctions::ciecam_02 (CieImage* ncie, double adap, int pW, int pwb, LabImage* lab, const ProcParams* params, - const ColorAppearance & customColCurve1, const ColorAppearance & customColCurve2, const ColorAppearance & customColCurve3, - LUTu & histLCAM, LUTu & histCCAM, LUTf & CAMBrightCurveJ, LUTf & CAMBrightCurveQ, float &mean, int Iterates, int scale, bool execsharp, double &d, double &dj, int rtt) -{ - if (params->colorappearance.enabled) { -//int lastskip; -//if(rtt==1) {lastskip=scale;} //not for Rtthumbnail - -#ifdef _DEBUG - MyTime t1e, t2e; - t1e.set(); -#endif - LUTf dLcurve; - LUTu hist16JCAM; - bool jp = false; - - //preparate for histograms CIECAM - if (pW != 1) { //only with improccoordinator - dLcurve (65536, 0); - dLcurve.clear(); - hist16JCAM (65536, 0); - hist16JCAM.clear(); - - for (int i = 0; i < 32768; i++) { //# 32768*1.414 approximation maxi for chroma - float val = (double)i / 32767.0; - dLcurve[i] = CLIPD (val); - } - } - - LUTf dCcurve; - LUTu hist16_CCAM; - bool chropC = false; - - if (pW != 1) { //only with improccoordinator - dCcurve (65536, 0); - hist16_CCAM (65536); - hist16_CCAM.clear(); - - for (int i = 0; i < 48000; i++) { //# 32768*1.414 approximation maxi for chroma - float valc = (double)i / 47999.0; - dCcurve[i] = CLIPD (valc); - } - } - - //end preparate histogram - int width = lab->W, height = lab->H; - float minQ = 10000.f; - float maxQ = -1000.f; - float a_w; - float c_; - float f_l; - double Yw; - Yw = 1.0; - double Xw, Zw; - double Xwout, Zwout; - double Xwsc, Zwsc; - - double f = 0., c = 0., nc = 0., yb = 0., la, xw, yw, zw, f2 = 0., c2 = 0., nc2 = 0., yb2 = 0., la2; - double fl, n, nbb, ncb, aw; - double xwd = 0., ywd, zwd = 0.; - double xws, yws, zws; - int alg = 0; - bool algepd = false; - float sum = 0.f; - - bool ciedata = params->colorappearance.datacie; - - ColorTemp::temp2mulxyz (params->wb.temperature, params->wb.method, Xw, Zw); //compute white Xw Yw Zw : white current WB - ColorTemp::temp2mulxyz (params->colorappearance.tempout, "Custom", Xwout, Zwout); - ColorTemp::temp2mulxyz (params->colorappearance.tempsc, "Custom", Xwsc, Zwsc); - - //viewing condition for surrsrc - if (params->colorappearance.surrsrc == "Average") { - f = 1.00; - c = 0.69; - nc = 1.00; - } else if (params->colorappearance.surrsrc == "Dim") { - f = 0.9; - c = 0.59; - nc = 0.9; - } else if (params->colorappearance.surrsrc == "Dark") { - f = 0.8; - c = 0.525; - nc = 0.8; - } else if (params->colorappearance.surrsrc == "ExtremelyDark") { - f = 0.8; - c = 0.41; - nc = 0.8; - } - - - //viewing condition for surround - if (params->colorappearance.surround == "Average") { - f2 = 1.0, c2 = 0.69, nc2 = 1.0; - } else if (params->colorappearance.surround == "Dim") { - f2 = 0.9; - c2 = 0.59; - nc2 = 0.9; - } else if (params->colorappearance.surround == "Dark") { - f2 = 0.8; - c2 = 0.525; - nc2 = 0.8; - } else if (params->colorappearance.surround == "ExtremelyDark") { - f2 = 0.8; - c2 = 0.41; - nc2 = 0.8; - } - - /* - //scene condition for surround - if (params->colorappearance.surrsource) { - f = 0.85; // if user => source image has surround very dark - c = 0.55; - nc = 0.85; - } - */ - //with which algorithme - if (params->colorappearance.algo == "JC") { - alg = 0; - } else if (params->colorappearance.algo == "JS") { - alg = 1; - } else if (params->colorappearance.algo == "QM") { - alg = 2; - algepd = true; - } else if (params->colorappearance.algo == "ALL") { - alg = 3; - algepd = true; - } - - bool needJ = (alg == 0 || alg == 1 || alg == 3); - bool needQ = (alg == 2 || alg == 3); - /* - //settings white point of output device - or illuminant viewing - if (settings->viewingdevice == 0) { - xwd = 96.42; //5000K - ywd = 100.0; - zwd = 82.52; - } else if (settings->viewingdevice == 1) { - xwd = 95.68; //5500 - ywd = 100.0; - zwd = 92.15; - } else if (settings->viewingdevice == 2) { - xwd = 95.24; //6000 - ywd = 100.0; - zwd = 100.81; - } else if (settings->viewingdevice == 3) { - xwd = 95.04; //6500 - ywd = 100.0; - zwd = 108.88; - } else if (settings->viewingdevice == 4) { - xwd = 109.85; //tungsten - ywd = 100.0; - zwd = 35.58; - } else if (settings->viewingdevice == 5) { - xwd = 99.18; //fluo F2 - ywd = 100.0; - zwd = 67.39; - } else if (settings->viewingdevice == 6) { - xwd = 95.04; //fluo F7 - ywd = 100.0; - zwd = 108.75; - } else if (settings->viewingdevice == 7) { - xwd = 100.96; //fluo F11 - ywd = 100.0; - zwd = 64.35; - } - */ - - xwd = 100. * Xwout; - zwd = 100. * Zwout; - ywd = 100. / params->colorappearance.greenout;//approximation to simplify - - xws = 100. * Xwsc; - zws = 100. * Zwsc; - yws = 100. / params->colorappearance.greensc;//approximation to simplify - - /* - //settings mean Luminance Y of output device or viewing - if (settings->viewingdevicegrey == 0) { - yb2 = 5.0; - } else if (settings->viewingdevicegrey == 1) { - yb2 = 10.0; - } else if (settings->viewingdevicegrey == 2) { - yb2 = 15.0; - } else if (settings->viewingdevicegrey == 3) { - yb2 = 18.0; - } else if (settings->viewingdevicegrey == 4) { - yb2 = 23.0; - } else if (settings->viewingdevicegrey == 5) { - yb2 = 30.0; - } else if (settings->viewingdevicegrey == 6) { - yb2 = 40.0; - } - */ - yb2 = params->colorappearance.ybout; - - //La and la2 = ambiant luminosity scene and viewing - la = double (params->colorappearance.adapscen); - - if (pwb == 2) { - if (params->colorappearance.autoadapscen) { - la = adap; - } - } - - la2 = double (params->colorappearance.adaplum); - - // level of adaptation - double deg = (params->colorappearance.degree) / 100.0; - double pilot = params->colorappearance.autodegree ? 2.0 : deg; - - - const float degout = (params->colorappearance.degreeout) / 100.0; - const float pilotout = params->colorappearance.autodegreeout ? 2.0 : degout; - - //algoritm's params - float jli = params->colorappearance.jlight; - float chr = params->colorappearance.chroma; - float contra = params->colorappearance.contrast; - float qbri = params->colorappearance.qbright; - float schr = params->colorappearance.schroma; - float mchr = params->colorappearance.mchroma; - float qcontra = params->colorappearance.qcontrast; - float hue = params->colorappearance.colorh; - double rstprotection = 100. - params->colorappearance.rstprotection; - - if (schr > 0.0) { - schr = schr / 2.0f; //divide sensibility for saturation - } - - // extracting datas from 'params' to avoid cache flush (to be confirmed) - ColorAppearanceParams::TcMode curveMode = params->colorappearance.curveMode; - ColorAppearanceParams::TcMode curveMode2 = params->colorappearance.curveMode2; - bool hasColCurve1 = bool (customColCurve1); - bool hasColCurve2 = bool (customColCurve2); - ColorAppearanceParams::CtcMode curveMode3 = params->colorappearance.curveMode3; - bool hasColCurve3 = bool (customColCurve3); - - - if (CAMBrightCurveJ.dirty || CAMBrightCurveQ.dirty) { - LUTu hist16J; - LUTu hist16Q; - - if (needJ) { - hist16J (65536); - hist16J.clear(); - } - - if (needQ) { - hist16Q (65536); - hist16Q.clear(); - } - - float koef = 1.0f; //rough correspondence between L and J - - for (int i = 0; i < height; i++) - - // for (int i=begh; iL[i][j] / 327.68f; - - if (currL > 95.) { - koef = 1.f; - } else if (currL > 85.) { - koef = 0.97f; - } else if (currL > 80.) { - koef = 0.93f; - } else if (currL > 70.) { - koef = 0.87f; - } else if (currL > 60.) { - koef = 0.85f; - } else if (currL > 50.) { - koef = 0.8f; - } else if (currL > 40.) { - koef = 0.75f; - } else if (currL > 30.) { - koef = 0.7f; - } else if (currL > 20.) { - koef = 0.7f; - } else if (currL > 10.) { - koef = 0.9f; - } else if (currL > 0.) { - koef = 1.0f; - } - - if (needJ) { - hist16J[CLIP ((int) ((koef * lab->L[i][j])))]++; //evaluate histogram luminance L # J - } - - if (needQ) { - hist16Q[CLIP ((int) (32768.f * sqrt ((koef * (lab->L[i][j])) / 32768.f)))]++; //for brightness Q : approximation for Q=wh*sqrt(J/100) J not equal L - } - - sum += koef * lab->L[i][j]; //evaluate mean J to calculate Yb - } - - //mean=(sum/((endh-begh)*width))/327.68f;//for Yb for all image...if one day "pipette" we can adapt Yb for each zone - mean = (sum / ((height) * width)) / 327.68f; //for Yb for all image...if one day "pipette" we can adapt Yb for each zone - - //evaluate lightness, contrast - if (needJ) { - if (!CAMBrightCurveJ) { - CAMBrightCurveJ (65536, 0); - CAMBrightCurveJ.dirty = false; - } - - Ciecam02::curveJ (jli, contra, 1, CAMBrightCurveJ, hist16J);//lightness and contrast J - } - - if (needQ) { - if (!CAMBrightCurveQ) { - CAMBrightCurveQ (65536, 0); - CAMBrightCurveQ.dirty = false; - } - - Ciecam02::curveJ (qbri, qcontra, 1, CAMBrightCurveQ, hist16Q);//brightness and contrast Q - } - } - - // if (settings->viewinggreySc == 0) { //auto - if (params->colorappearance.autoybscen && pwb == 2) {//auto - - if (mean < 15.f) { - yb = 3.0; - } else if (mean < 30.f) { - yb = 5.0; - } else if (mean < 40.f) { - yb = 10.0; - } else if (mean < 45.f) { - yb = 15.0; - } else if (mean < 50.f) { - yb = 18.0; - } else if (mean < 55.f) { - yb = 23.0; - } else if (mean < 60.f) { - yb = 30.0; - } else if (mean < 70.f) { - yb = 40.0; - } else if (mean < 80.f) { - yb = 60.0; - } else if (mean < 90.f) { - yb = 80.0; - } else { - yb = 90.0; - } - } else { - yb = params->colorappearance.ybscen; - } - - if (settings->viewinggreySc == 1) { - yb = 18.0; - } - - int gamu = 0; - bool highlight = params->toneCurve.hrenabled; //Get the value if "highlight reconstruction" is activated - - if (params->colorappearance.gamut) { - gamu = 1; //enabled gamut control - } - - xw = 100.0 * Xw; - yw = 100.0 * Yw; - zw = 100.0 * Zw; - double xw1 = 0., yw1 = 0., zw1 = 0., xw2 = 0., yw2 = 0., zw2 = 0.; - - // settings of WB: scene and viewing - if (params->colorappearance.wbmodel == "RawT") { - xw1 = 96.46; //use RT WB; CAT 02 is used for output device (see prefreneces) - yw1 = 100.0; - zw1 = 82.445; - xw2 = xwd; - yw2 = ywd; - zw2 = zwd; - } else if (params->colorappearance.wbmodel == "RawTCAT02") { - xw1 = xw; // Settings RT WB are used for CAT02 => mix , CAT02 is use for output device (screen: D50 D65, projector: lamp, LED) see preferences - yw1 = yw; - zw1 = zw; - xw2 = xwd; - yw2 = ywd; - zw2 = zwd; - } else if (params->colorappearance.wbmodel == "free") { - xw1 = xws; // free temp and green - yw1 = yws; - zw1 = zws; - xw2 = xwd; - yw2 = ywd; - zw2 = zwd; - } - - double cz, wh, pfl; - Ciecam02::initcam1 (gamu, yb, pilot, f, la, xw, yw, zw, n, d, nbb, ncb, cz, aw, wh, pfl, fl, c); - double nj, nbbj, ncbj, czj, awj, flj; - Ciecam02::initcam2 (gamu, yb2, pilotout, f2, la2, xw2, yw2, zw2, nj, dj, nbbj, ncbj, czj, awj, flj); - - - - -#ifndef _DEBUG - #pragma omp parallel default(shared) firstprivate(lab,xw1,xw2,yw1,yw2,zw1,zw2,pilot,jli,chr,yb,la,yb2,la2,fl,nc,f,c, height,width,nc2,f2,c2, alg,algepd, gamu, highlight, rstprotection, pW, scale) -#endif - { - //matrix for current working space - TMatrix wiprof = ICCStore::getInstance()->workingSpaceInverseMatrix (params->icm.working); - double wip[3][3] = { - {wiprof[0][0], wiprof[0][1], wiprof[0][2]}, - {wiprof[1][0], wiprof[1][1], wiprof[1][2]}, - {wiprof[2][0], wiprof[2][1], wiprof[2][2]} - }; - -#ifndef _DEBUG - #pragma omp for schedule(dynamic, 10) -#endif - - for (int i = 0; i < height; i++) - -// for (int i=begh; iL[i][j]; - float a = lab->a[i][j]; - float b = lab->b[i][j]; - float x1, y1, z1; - double x, y, z; - double epsil = 0.0001; - //convert Lab => XYZ - Color::Lab2XYZ (L, a, b, x1, y1, z1); - // double J, C, h, Q, M, s, aw, fl, wh; - double J, C, h, Q, M, s; - - double Jpro, Cpro, hpro, Qpro, Mpro, spro; - bool t1L = false; - bool t1B = false; - bool t2B = false; - int c1s = 0; - int c1co = 0; - //double n,nbb,ncb,pfl,cz,d; - x = (double)x1 / 655.35; - y = (double)y1 / 655.35; - z = (double)z1 / 655.35; - //process source==> normal - Ciecam02::xyz2jchqms_ciecam02 ( J, C, h, - Q, M, s, aw, fl, wh, - x, y, z, - xw1, yw1, zw1, - c, nc, gamu, n, nbb, ncb, pfl, cz, d ); - Jpro = J; - Cpro = C; - hpro = h; - Qpro = Q; - Mpro = M; - spro = s; - a_w = aw; - c_ = c; - f_l = fl; - - // we cannot have all algorithms with all chroma curves - if (alg == 1) { - // Lightness saturation - if (Jpro > 99.9f) { - Jpro = 99.9f; - } - - Jpro = (CAMBrightCurveJ[ (float) (Jpro * 327.68)]) / 327.68; //ligthness CIECAM02 + contrast - double sres; - double Sp = spro / 100.0; - double parsat = 1.5; //parsat=1.5 =>saturation ; 1.8 => chroma ; 2.5 => colorfullness (personal evaluation) - - if (schr == -100.0) { - schr = -99.8; - } - - Ciecam02::curvecolor (schr, Sp, sres, parsat); - double coe = pow (fl, 0.25); - float dred = 100.f; // in C mode - float protect_red = 80.0f; // in C mode - dred = 100.0 * sqrt ((dred * coe) / Qpro); - protect_red = 100.0 * sqrt ((protect_red * coe) / Qpro); - int sk = 0; - float ko = 100.f; - Color::skinred (Jpro, hpro, sres, Sp, dred, protect_red, sk, rstprotection, ko, spro); - Qpro = ( 4.0 / c ) * sqrt ( Jpro / 100.0 ) * ( aw + 4.0 ) ; - Cpro = (spro * spro * Qpro) / (10000.0); - } else if (alg == 3 || alg == 0 || alg == 2) { - double coef = 32760. / wh; - - if (alg == 3 || alg == 2) { - if (Qpro * coef > 32767.0f) { - Qpro = (CAMBrightCurveQ[ (float)32767.0f]) / coef; //brightness and contrast - } else { - Qpro = (CAMBrightCurveQ[ (float) (Qpro * coef)]) / coef; //brightness and contrast - } - } - - double Mp, sres; - double coe = pow (fl, 0.25); - Mp = Mpro / 100.0; - double parsat = 2.5; - - if (mchr == -100.0) { - mchr = -99.8 ; - } - - if (mchr == 100.0) { - mchr = 99.9; - } - - if (alg == 3 || alg == 2) { - Ciecam02::curvecolor (mchr, Mp, sres, parsat); - } else { - Ciecam02::curvecolor (0.0, Mp, sres, parsat); //colorfullness - } - - float dred = 100.f; //in C mode - float protect_red = 80.0f; // in C mode - dred *= coe; //in M mode - protect_red *= coe; //M mode - int sk = 0; - float ko = 100.f; - Color::skinred (Jpro, hpro, sres, Mp, dred, protect_red, sk, rstprotection, ko, Mpro); - Jpro = (100.0 * Qpro * Qpro) / (wh * wh); - Cpro = Mpro / coe; - spro = 100.0 * sqrt ( Mpro / Qpro ); - - if (alg != 2) { - if (Jpro > 99.9f) { - Jpro = 99.9f; - } - - Jpro = (CAMBrightCurveJ[ (float) (Jpro * 327.68f)]) / 327.68f; //ligthness CIECAM02 + contrast - } - - double Cp; - double Sp = spro / 100.0; - parsat = 1.5; - - if (schr == -100.0) { - schr = -99.; - } - - if (schr == 100.0) { - schr = 98.; - } - - if (alg == 3) { - Ciecam02::curvecolor (schr, Sp, sres, parsat); - } else { - Ciecam02::curvecolor (0.0, Sp, sres, parsat); //saturation - } - - dred = 100.f; // in C mode - protect_red = 80.0f; // in C mode - dred = 100.0 * sqrt ((dred * coe) / Q); - protect_red = 100.0 * sqrt ((protect_red * coe) / Q); - sk = 0; - Color::skinred (Jpro, hpro, sres, Sp, dred, protect_red, sk, rstprotection, ko, spro); - //double Q1; - Qpro = ( 4.0 / c ) * sqrt ( Jpro / 100.0 ) * ( aw + 4.0 ) ; - Cpro = (spro * spro * Qpro) / (10000.0); - Cp = Cpro / 100.0; - parsat = 1.8; //parsat=1.5 =>saturation ; 1.8 => chroma ; 2.5 => colorfullness (personal evaluation : for not) - - if (chr == -100.0) { - chr = -99.8; - } - - if (alg != 2) { - Ciecam02::curvecolor (chr, Cp, sres, parsat); - } else { - Ciecam02::curvecolor (0.0, Cp, sres, parsat); //chroma - } - - dred = 55.f; - protect_red = 30.0f; - sk = 1; - Color::skinred (Jpro, hpro, sres, Cp, dred, protect_red, sk, rstprotection, ko, Cpro); - - if (Jpro < 1. && Cpro > 12.) { - Cpro = 12.; //reduce artifacts by "pseudo gamut control CIECAM" - } else if (Jpro < 2. && Cpro > 15.) { - Cpro = 15.; - } else if (Jpro < 4. && Cpro > 30.) { - Cpro = 30.; - } else if (Jpro < 7. && Cpro > 50.) { - Cpro = 50.; - } - - hpro = hpro + hue; - - if ( hpro < 0.0 ) { - hpro += 360.0; //hue - } - } - - if (hasColCurve1) {//curve 1 with Lightness and Brightness - if (curveMode == ColorAppearanceParams::TcMode::LIGHT) { - /* float Jj=(float) Jpro*327.68; - float Jold=Jj; - const Lightcurve& userColCurve = static_cast(customColCurve1); - userColCurve.Apply(Jj); - Jj=0.7f*(Jj-Jold)+Jold;//divide sensibility - */ - float Jj = (float) Jpro * 327.68f; - float Jold = Jj; - float Jold100 = (float) Jpro; - float redu = 25.f; - float reduc = 1.f; - const Lightcurve& userColCurveJ1 = static_cast (customColCurve1); - userColCurveJ1.Apply (Jj); - - if (Jj > Jold) { - if (Jj < 65535.f) { - if (Jold < 327.68f * redu) { - Jj = 0.3f * (Jj - Jold) + Jold; //divide sensibility - } else { - reduc = LIM ((100.f - Jold100) / (100.f - redu), 0.f, 1.f); - Jj = 0.3f * reduc * (Jj - Jold) + Jold; //reduct sensibility in highlights - } - } - } else if (Jj > 10.f) { - Jj = 0.8f * (Jj - Jold) + Jold; - } else if (Jj >= 0.f) { - Jj = 0.90f * (Jj - Jold) + Jold; // not zero ==>artifacts - } - - - Jpro = (double) (Jj / 327.68f); - - if (Jpro < 1.) { - Jpro = 1.; - } - - t1L = true; - } else if (curveMode == ColorAppearanceParams::TcMode::BRIGHT) { - //attention! Brightness curves are open - unlike Lightness or Lab or RGB==> rendering and algorithms will be different - float coef = ((aw + 4.f) * (4.f / c)) / 100.f; - float Qanc = Qpro; - float Qq = (float) Qpro * 327.68f * (1.f / coef); - float Qold100 = (float) Qpro / coef; - - float Qold = Qq; - float redu = 20.f; - float reduc = 1.f; - - const Brightcurve& userColCurveB1 = static_cast (customColCurve1); - userColCurveB1.Apply (Qq); - - if (Qq > Qold) { - if (Qq < 65535.f) { - if (Qold < 327.68f * redu) { - Qq = 0.25f * (Qq - Qold) + Qold; //divide sensibility - } else { - reduc = LIM ((100.f - Qold100) / (100.f - redu), 0.f, 1.f); - Qq = 0.25f * reduc * (Qq - Qold) + Qold; //reduct sensibility in highlights - } - } - } else if (Qq > 10.f) { - Qq = 0.5f * (Qq - Qold) + Qold; - } else if (Qq >= 0.f) { - Qq = 0.7f * (Qq - Qold) + Qold; // not zero ==>artifacts - } - - if (Qold == 0.f) { - Qold = 0.001f; - } - - Qpro = Qanc * (Qq / Qold); - Jpro = Jpro * SQR (Qq / Qold); - -// Qpro = (double) (Qq * (coef) / 327.68f); -// Jpro = 100.* (Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); - t1B = true; - - if (Jpro < 1.) { - Jpro = 1.; - } - - } - } - - if (hasColCurve2) {//curve 2 with Lightness and Brightness - if (curveMode2 == ColorAppearanceParams::TcMode::LIGHT) { - float Jj = (float) Jpro * 327.68; - float Jold = Jj; - /* - const Lightcurve& userColCurve = static_cast(customColCurve2); - userColCurve.Apply(Jj); - Jj=0.7f*(Jj-Jold)+Jold;//divide sensibility - */ - float Jold100 = (float) Jpro; - float redu = 25.f; - float reduc = 1.f; - const Lightcurve& userColCurveJ2 = static_cast (customColCurve2); - userColCurveJ2.Apply (Jj); - - if (Jj > Jold) { - if (Jj < 65535.f) { - if (Jold < 327.68f * redu) { - Jj = 0.3f * (Jj - Jold) + Jold; //divide sensibility - } else { - reduc = LIM ((100.f - Jold100) / (100.f - redu), 0.f, 1.f); - Jj = 0.3f * reduc * (Jj - Jold) + Jold; //reduct sensibility in highlights - } - } - } else if (Jj > 10.f) { - if (!t1L) { - Jj = 0.8f * (Jj - Jold) + Jold; - } else { - Jj = 0.4f * (Jj - Jold) + Jold; - } - } else if (Jj >= 0.f) { - if (!t1L) { - Jj = 0.90f * (Jj - Jold) + Jold; // not zero ==>artifacts - } else { - Jj = 0.5f * (Jj - Jold) + Jold; - } - } - - Jpro = (double) (Jj / 327.68f); - - if (Jpro < 1.) { - Jpro = 1.; - } - - } else if (curveMode2 == ColorAppearanceParams::TcMode::BRIGHT) { // - float Qanc = Qpro; - float coef = ((aw + 4.f) * (4.f / c)) / 100.f; - float Qq = (float) Qpro * 327.68f * (1.f / coef); - float Qold100 = (float) Qpro / coef; - - float Qold = Qq; - float redu = 20.f; - float reduc = 1.f; - - const Brightcurve& userColCurveB2 = static_cast (customColCurve2); - userColCurveB2.Apply (Qq); - - if (Qq > Qold) { - if (Qq < 65535.f) { - if (Qold < 327.68f * redu) { - Qq = 0.25f * (Qq - Qold) + Qold; //divide sensibility - } else { - reduc = LIM ((100.f - Qold100) / (100.f - redu), 0.f, 1.f); - Qq = 0.25f * reduc * (Qq - Qold) + Qold; //reduct sensibility in highlights - } - } - } else if (Qq > 10.f) { - Qq = 0.5f * (Qq - Qold) + Qold; - } else if (Qq >= 0.f) { - Qq = 0.7f * (Qq - Qold) + Qold; // not zero ==>artifacts - } - - if (Qold == 0.f) { - Qold = 0.001f; - } - - // Qpro = (float) (Qq * (coef) / 327.68f); - Qpro = Qanc * (Qq / Qold); - Jpro = Jpro * SQR (Qq / Qold); - - // Qpro = (double) (Qq * (coef) / 327.68f); - // Jpro = 100.* (Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); - t2B = true; - - if (t1L) { //to workaround the problem if we modify curve1-lightnees after curve2 brightness(the cat that bites its own tail!) in fact it's another type of curve only for this case - coef = 2.f; //adapt Q to J approximation - Qq = (float) Qpro * coef; - Qold = Qq; - const Lightcurve& userColCurveJ1 = static_cast (customColCurve1); - userColCurveJ1.Apply (Qq); - Qq = 0.1f * (Qq - Qold) + Qold; //approximative adaptation - Qpro = (double) (Qq / coef); - Jpro = 100.* (Qpro * Qpro) / ((4.0 / c) * (4.0 / c) * (aw + 4.0) * (aw + 4.0)); - } - - if (Jpro < 1.) { - Jpro = 1.; - } - } - } - - if (hasColCurve3) {//curve 3 with chroma saturation colorfullness - if (curveMode3 == ColorAppearanceParams::CtcMode::CHROMA) { - double parsat = 0.8; //0.68; - double coef = 327.68 / parsat; - float Cc = (float) Cpro * coef; - float Ccold = Cc; - const Chromacurve& userColCurve = static_cast (customColCurve3); - userColCurve.Apply (Cc); - float dred = 55.f; - float protect_red = 30.0f; - float sk = 1; - float ko = 1.f / coef; - Color::skinred (Jpro, hpro, Cc, Ccold, dred, protect_red, sk, rstprotection, ko, Cpro); - - if (Jpro < 1. && Cpro > 12.) { - Cpro = 12.; //reduce artifacts by "pseudo gamut control CIECAM" - } else if (Jpro < 2. && Cpro > 15.) { - Cpro = 15.; - } else if (Jpro < 4. && Cpro > 30.) { - Cpro = 30.; - } else if (Jpro < 7. && Cpro > 50.) { - Cpro = 50.; - } - - // Cpro=Cc/coef; - } else if (curveMode3 == ColorAppearanceParams::CtcMode::SATUR) { // - double parsat = 0.8; //0.6 - double coef = 327.68 / parsat; - float Ss = (float) spro * coef; - float Sold = Ss; - const Saturcurve& userColCurve = static_cast (customColCurve3); - userColCurve.Apply (Ss); - Ss = 0.6f * (Ss - Sold) + Sold; //divide sensibility saturation - double coe = pow (fl, 0.25); - float dred = 100.f; // in C mode - float protect_red = 80.0f; // in C mode - dred = 100.0 * sqrt ((dred * coe) / Qpro); - protect_red = 100.0 * sqrt ((protect_red * coe) / Qpro); - int sk = 0; - float ko = 1.f / coef; - Color::skinred (Jpro, hpro, Ss, Sold, dred, protect_red, sk, rstprotection, ko, spro); - Qpro = ( 4.0 / c ) * sqrt ( Jpro / 100.0 ) * ( aw + 4.0 ) ; - Cpro = (spro * spro * Qpro) / (10000.0); - c1s = 1; - - } else if (curveMode3 == ColorAppearanceParams::CtcMode::COLORF) { // - double parsat = 0.8; //0.68; - double coef = 327.68 / parsat; - float Mm = (float) Mpro * coef; - float Mold = Mm; - const Colorfcurve& userColCurve = static_cast (customColCurve3); - userColCurve.Apply (Mm); - double coe = pow (fl, 0.25); - float dred = 100.f; //in C mode - float protect_red = 80.0f; // in C mode - dred *= coe; //in M mode - protect_red *= coe; - int sk = 0; - float ko = 1.f / coef; - Color::skinred (Jpro, hpro, Mm, Mold, dred, protect_red, sk, rstprotection, ko, Mpro); - Cpro = Mpro / coe; - - if (Jpro < 1. && Mpro > 12.*coe) { - Mpro = 12.*coe; //reduce artifacts by "pseudo gamut control CIECAM" - } else if (Jpro < 2. && Mpro > 15.*coe) { - Mpro = 15.*coe; - } else if (Jpro < 4. && Mpro > 30.*coe) { - Mpro = 30.*coe; - } else if (Jpro < 7. && Mpro > 50.*coe) { - Mpro = 50.*coe; - } - - - c1co = 1; - } - } - - //to retrieve the correct values of variables - if (t2B && t1B) { - Jpro = (100.0 * Qpro * Qpro) / (wh * wh); // for brightness curve - } - - if (c1s == 1) { - Qpro = ( 4.0 / c ) * sqrt ( Jpro / 100.0 ) * ( aw + 4.0 ) ; //for saturation curve - Cpro = (spro * spro * Qpro) / (10000.0); - } - - if (c1co == 1) { - double coe = pow (fl, 0.25); // for colorfullness curve - Cpro = Mpro / coe; - } - - //retrieve values C,J...s - C = Cpro; - J = Jpro; - Q = Qpro; - M = Mpro; - h = hpro; - s = spro; - - if (params->colorappearance.tonecie || settings->autocielab) { //use pointer for tonemapping with CIECAM and also sharpening , defringe, contrast detail - // if(params->colorappearance.tonecie || params->colorappearance.sharpcie){//use pointer for tonemapping with CIECAM and also sharpening , defringe, contrast detail - float Qred = ( 4.0 / c) * ( aw + 4.0 ); //estimate Q max if J=100.0 - ncie->Q_p[i][j] = (float)Q + epsil; //epsil to avoid Q=0 - ncie->M_p[i][j] = (float)M + epsil; - ncie->J_p[i][j] = (float)J + epsil; - ncie->h_p[i][j] = (float)h; - ncie->C_p[i][j] = (float)C + epsil; - // ncie->s_p[i][j]=(float)s; - ncie->sh_p[i][j] = (float) 32768.* (( 4.0 / c ) * sqrt ( J / 100.0 ) * ( aw + 4.0 )) / Qred ; - - // ncie->ch_p[i][j]=(float) 327.68*C; - if (ncie->Q_p[i][j] < minQ) { - minQ = ncie->Q_p[i][j]; //minima - } - - if (ncie->Q_p[i][j] > maxQ) { - maxQ = ncie->Q_p[i][j]; //maxima - } - } - - if (!params->colorappearance.tonecie || !settings->autocielab || !params->epd.enabled ) { - -// if(!params->epd.enabled || !params->colorappearance.tonecie || !settings->autocielab){ - // if(!params->epd.enabled || !params->colorappearance.tonecie || !params->colorappearance.sharpcie){ - double brli = 327.; - double chsacol = 327.; - int libr = 0; - int colch = 0; - - if (curveMode == ColorAppearanceParams::TcMode::BRIGHT) { - brli = 70.0; - libr = 1; - } else if (curveMode == ColorAppearanceParams::TcMode::LIGHT) { - brli = 327.; - libr = 0; - } - - if (curveMode3 == ColorAppearanceParams::CtcMode::CHROMA) { - chsacol = 400.;//327.; - colch = 0; - } else if (curveMode3 == ColorAppearanceParams::CtcMode::SATUR) { - chsacol = 450.0; - colch = 1; - } else if (curveMode3 == ColorAppearanceParams::CtcMode::COLORF) { - chsacol = 400.;//327.0; - colch = 2; - } - - if (ciedata) { - // Data for J Q M s and C histograms - //update histogram - jp = true; - - if (pW != 1) { //only with improccoordinator - int posl; - - if (libr == 1) { - posl = CLIP ((int) (Q * brli)); //40.0 to 100.0 approximative factor for Q - 327 for J - } else { /*if(libr == 0)*/ - posl = CLIP ((int) (J * brli)); //327 for J - } - - hist16JCAM[posl]++; - } - - chropC = true; - - if (pW != 1) { //only with improccoordinator - int posc; - - if (colch == 0) { - posc = CLIP ((int) (C * chsacol)); //450.0 approximative factor for s 320 for M - } else if (colch == 1) { - posc = CLIP ((int) (s * chsacol)); - } else { /*if(colch == 2)*/ - posc = CLIP ((int) (M * chsacol)); - } - - hist16_CCAM[posc]++; - } - } - - double xx, yy, zz; - //double nj, nbbj, ncbj, flj, czj, dj, awj; - //process normal==> viewing - Ciecam02::jch2xyz_ciecam02 ( xx, yy, zz, - J, C, h, - xw2, yw2, zw2, - c2, nc2, gamu, nj, nbbj, ncbj, flj, czj, dj, awj); - x = (float)xx * 655.35; - y = (float)yy * 655.35; - z = (float)zz * 655.35; - float Ll, aa, bb; - //convert xyz=>lab - Color::XYZ2Lab (x, y, z, Ll, aa, bb); - lab->L[i][j] = Ll; - lab->a[i][j] = aa; - lab->b[i][j] = bb; - - // gamut control in Lab mode; I must study how to do with cIECAM only - if (gamu == 1) { - float R, G, B; - float HH, Lprov1, Chprov1; - Lprov1 = lab->L[i][j] / 327.68f; - Chprov1 = sqrt (SQR (lab->a[i][j] / 327.68f) + SQR (lab->b[i][j] / 327.68f)); - HH = atan2 (lab->b[i][j], lab->a[i][j]); - -#ifdef _DEBUG - bool neg = false; - bool more_rgb = false; - //gamut control : Lab values are in gamut - Color::gamutLchonly (HH, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f, neg, more_rgb); -#else - //gamut control : Lab values are in gamut - Color::gamutLchonly (HH, Lprov1, Chprov1, R, G, B, wip, highlight, 0.15f, 0.96f); -#endif - - lab->L[i][j] = Lprov1 * 327.68f; - lab->a[i][j] = 327.68f * Chprov1 * cos (HH); - lab->b[i][j] = 327.68f * Chprov1 * sin (HH); - - } - } - } - } - - // End of parallelization - if (!params->epd.enabled || !params->colorappearance.tonecie || !settings->autocielab) { //normal -//if(!params->epd.enabled || !params->colorappearance.tonecie || !params->colorappearance.sharpcie){//normal - - if (ciedata) { - //update histogram J - if (pW != 1) { //only with improccoordinator - for (int i = 0; i < 32768; i++) { // - if (jp) { - float hval = dLcurve[i]; - int hi = (int) (255.0 * CLIPD (hval)); // - histLCAM[hi] += hist16JCAM[i] ; - } - } - } - - if (pW != 1) { //only with improccoordinator - for (int i = 0; i < 48000; i++) { // - if (chropC) { - float hvalc = dCcurve[i]; - int hic = (int) (255.0 * CLIPD (hvalc)); // - histCCAM[hic] += hist16_CCAM[i] ; - } - } - } - } - } - -#ifdef _DEBUG - - if (settings->verbose) { - t2e.set(); - printf ("CIECAM02 performed in %d usec:\n", t2e.etime (t1e)); - // printf("minc=%f maxc=%f minj=%f maxj=%f\n",minc,maxc,minj,maxj); - } - -#endif - - if (settings->autocielab) { -//if(params->colorappearance.sharpcie) { - -//all this treatments reduce artifacts, but can lead to slightly different results - if (params->defringe.enabled) if (execsharp) { - ImProcFunctions::defringecam (ncie); // - } - -//if(params->dirpyrequalizer.enabled) if(execsharp) { - if (params->dirpyrequalizer.enabled && params->dirpyrequalizer.gamutlab && rtt) { //remove artifacts by gaussian blur - skin control, but not for thumbs - constexpr float artifact = 4.f; - constexpr float chrom = 50.f; - const bool hotbad = params->dirpyrequalizer.skinprotect != 0.0; - ImProcFunctions::badpixcam (ncie, artifact / scale, 5, 2, chrom, hotbad); //enabled remove artifacts for cbDL - } - - if (params->colorappearance.badpixsl > 0 && execsharp) { - int mode = params->colorappearance.badpixsl; - ImProcFunctions::badpixcam (ncie, 3.4, 5, mode, 0, true);//for bad pixels CIECAM - } - - if (params->sharpenMicro.enabled)if (execsharp) { - ImProcFunctions::MLmicrocontrastcam (ncie); - } - - if (params->sharpening.enabled) - if (execsharp) { - float **buffer = lab->L; // We can use the L-buffer from lab as buffer to save some memory - ImProcFunctions::sharpeningcam (ncie, buffer); // sharpening adapted to CIECAM - } - -//if(params->dirpyrequalizer.enabled) if(execsharp) { - if (params->dirpyrequalizer.enabled /*&& (execsharp)*/) { - -// if (params->dirpyrequalizer.algo=="FI") choice=0; -// else if(params->dirpyrequalizer.algo=="LA") choice=1; - if (rtt == 1) { - float b_l = static_cast (params->dirpyrequalizer.hueskin.getBottomLeft()) / 100.0f; - float t_l = static_cast (params->dirpyrequalizer.hueskin.getTopLeft()) / 100.0f; - float t_r = static_cast (params->dirpyrequalizer.hueskin.getTopRight()) / 100.0f; - dirpyr_equalizercam (ncie, ncie->sh_p, ncie->sh_p, ncie->W, ncie->H, ncie->h_p, ncie->C_p, params->dirpyrequalizer.mult, params->dirpyrequalizer.threshold, params->dirpyrequalizer.skinprotect, true, b_l, t_l, t_r, scale); //contrast by detail adapted to CIECAM - } - } - - float Qredi = ( 4.0 / c_) * ( a_w + 4.0 ); - float co_e = (pow (f_l, 0.25f)); - -#ifndef _DEBUG - #pragma omp parallel default(shared) firstprivate(height,width, Qredi,a_w,c_) -#endif - { -#ifndef _DEBUG - #pragma omp for schedule(dynamic, 10) -#endif - - for (int i = 0; i < height; i++) // update CieImages with new values after sharpening, defringe, contrast by detail level - for (int j = 0; j < width; j++) { - float interm = Qredi * ncie->sh_p[i][j] / (32768.f); - ncie->J_p[i][j] = 100.0 * interm * interm / ((a_w + 4.) * (a_w + 4.) * (4. / c_) * (4. / c_)); - ncie->Q_p[i][j] = ( 4.0 / c_) * ( a_w + 4.0 ) * sqrt (ncie->J_p[i][j] / 100.f); - ncie->M_p[i][j] = ncie->C_p[i][j] * co_e; - } - } - } - - if ((params->colorappearance.tonecie || (params->colorappearance.tonecie && params->epd.enabled)) || (params->sharpening.enabled && settings->autocielab) - || (params->dirpyrequalizer.enabled && settings->autocielab) || (params->defringe.enabled && settings->autocielab) || (params->sharpenMicro.enabled && settings->autocielab) - || (params->colorappearance.badpixsl > 0 && settings->autocielab)) { - - if (params->epd.enabled && params->colorappearance.tonecie && algepd) { - ImProcFunctions::EPDToneMapCIE (ncie, a_w, c_, width, height, minQ, maxQ, Iterates, scale ); - } - - //EPDToneMapCIE adapted to CIECAM - - -#ifndef _DEBUG - #pragma omp parallel default(shared) firstprivate(lab,xw2,yw2,zw2,chr,yb,la2,yb2, height,width, nc2,f2,c2, gamu, highlight,pW) -#endif - { - TMatrix wiprofa = ICCStore::getInstance()->workingSpaceInverseMatrix (params->icm.working); - double wipa[3][3] = { - {wiprofa[0][0], wiprofa[0][1], wiprofa[0][2]}, - {wiprofa[1][0], wiprofa[1][1], wiprofa[1][2]}, - {wiprofa[2][0], wiprofa[2][1], wiprofa[2][2]} - }; - - -#ifndef _DEBUG - #pragma omp for schedule(dynamic, 10) -#endif - - for (int i = 0; i < height; i++) // update CIECAM with new values after tone-mapping - - // for (int i=begh; iepd.enabled) ncie->J_p[i][j]=(100.0* ncie->Q_p[i][j]*ncie->Q_p[i][j])/(w_h*w_h); - if (params->epd.enabled) { - ncie->J_p[i][j] = (100.0 * ncie->Q_p[i][j] * ncie->Q_p[i][j]) / SQR ((4. / c) * (aw + 4.)); - } - - ncie->C_p[i][j] = (ncie->M_p[i][j]) / co_e; - //show histogram in CIECAM mode (Q,J, M,s,C) - double brli = 327.; - double chsacol = 327.; - int libr = 0; - int colch = 0; - - if (curveMode == ColorAppearanceParams::TcMode::BRIGHT) { - brli = 70.0; - libr = 1; - } else if (curveMode == ColorAppearanceParams::TcMode::LIGHT) { - brli = 327.; - libr = 0; - } - - if (curveMode3 == ColorAppearanceParams::CtcMode::CHROMA) { - chsacol = 400.;//327.; - colch = 0; - } else if (curveMode3 == ColorAppearanceParams::CtcMode::SATUR) { - chsacol = 450.0; - colch = 1; - } else if (curveMode3 == ColorAppearanceParams::CtcMode::COLORF) { - chsacol = 400.;//327.0; - colch = 2; - } - - if (ciedata) { - // Data for J Q M s and C histograms - //update histogram - jp = true; - - if (pW != 1) { //only with improccoordinator - int posl; - - if (libr == 1) { - posl = CLIP ((int) (ncie->Q_p[i][j] * brli)); //40.0 to 100.0 approximative factor for Q - 327 for J - } else { /*if(libr == 0)*/ - posl = CLIP ((int) (ncie->J_p[i][j] * brli)); //327 for J - } - - hist16JCAM[posl]++; - } - - chropC = true; - - if (pW != 1) { //only with improccoordinator - int posc; - - if (colch == 0) { - posc = CLIP ((int) (ncie->C_p[i][j] * chsacol)); //450.0 approximative factor for s 320 for M - } else if (colch == 1) { - float sa_t = 100.f * sqrt (ncie->C_p[i][j] / ncie->Q_p[i][j]); //Q_p always > 0 - posc = CLIP ((int) (sa_t * chsacol)); - } else { /*if(colch == 2)*/ - posc = CLIP ((int) (ncie->M_p[i][j] * chsacol)); - } - - hist16_CCAM[posc]++; - } - } - - //end histograms - // double nd, nbbd, ncbd, fld, czd, dd, awd; - Ciecam02::jch2xyz_ciecam02 ( xx, yy, zz, - ncie->J_p[i][j], ncie->C_p[i][j], ncie->h_p[i][j], - xw2, yw2, zw2, - c2, nc2, gamu, nj, nbbj, ncbj, flj, czj, dj, awj); - x = (float)xx * 655.35; - y = (float)yy * 655.35; - z = (float)zz * 655.35; - float Ll, aa, bb; - //convert xyz=>lab - Color::XYZ2Lab (x, y, z, Ll, aa, bb); - lab->L[i][j] = Ll; - lab->a[i][j] = aa; - lab->b[i][j] = bb; - - if (gamu == 1) { - float R, G, B; - float HH, Lprov1, Chprov1; - Lprov1 = lab->L[i][j] / 327.68f; - Chprov1 = sqrt (SQR (lab->a[i][j] / 327.68f) + SQR (lab->b[i][j] / 327.68f)); - HH = atan2 (lab->b[i][j], lab->a[i][j]); - -#ifdef _DEBUG - bool neg = false; - bool more_rgb = false; - //gamut control : Lab values are in gamut - Color::gamutLchonly (HH, Lprov1, Chprov1, R, G, B, wipa, highlight, 0.15f, 0.96f, neg, more_rgb); -#else - //gamut control : Lab values are in gamut - Color::gamutLchonly (HH, Lprov1, Chprov1, R, G, B, wipa, highlight, 0.15f, 0.96f); -#endif - - lab->L[i][j] = Lprov1 * 327.68f; - lab->a[i][j] = 327.68f * Chprov1 * cos (HH); - lab->b[i][j] = 327.68f * Chprov1 * sin (HH); - } - } - - - } - - //end parallelization - //show CIECAM histograms - if (ciedata) { - //update histogram J and Q - if (pW != 1) { //only with improccoordinator - for (int i = 0; i < 32768; i++) { // - if (jp) { - float hval = dLcurve[i]; - int hi = (int) (255.0 * CLIPD (hval)); // - histLCAM[hi] += hist16JCAM[i] ; - } - } - } - - //update color histogram M,s,C - if (pW != 1) { //only with improccoordinator - for (int i = 0; i < 48000; i++) { // - if (chropC) { - float hvalc = dCcurve[i]; - int hic = (int) (255.0 * CLIPD (hvalc)); // - histCCAM[hic] += hist16_CCAM[i] ; - } - } - } - } - - } - - } -} -//end CIECAM - - // Copyright (c) 2012 Jacques Desmis void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int pW, int pwb, LabImage* lab, const ProcParams* params, const ColorAppearance & customColCurve1, const ColorAppearance & customColCurve2, const ColorAppearance & customColCurve3, diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 6fc98ef3f1..fbddd491d2 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -228,9 +228,6 @@ class ImProcFunctions void ciecam_02float (CieImage* ncie, float adap, int pW, int pwb, LabImage* lab, const ProcParams* params, const ColorAppearance & customColCurve1, const ColorAppearance & customColCurve, const ColorAppearance & customColCurve3, LUTu &histLCAM, LUTu &histCCAM, LUTf & CAMBrightCurveJ, LUTf & CAMBrightCurveQ, float &mean, int Iterates, int scale, bool execsharp, float &d, float &dj, float &yb, int rtt); - void ciecam_02 (CieImage* ncie, double adap, int pW, int pwb, LabImage* lab, const ProcParams* params, - const ColorAppearance & customColCurve1, const ColorAppearance & customColCurve, const ColorAppearance & customColCurve3, - LUTu &histLCAM, LUTu &histCCAM, LUTf & CAMBrightCurveJ, LUTf & CAMBrightCurveQ, float &mean, int Iterates, int scale, bool execsharp, double &d, double &dj, int rtt); void chromiLuminanceCurve (PipetteBuffer *pipetteBuffer, int pW, LabImage* lold, LabImage* lnew, LUTf &acurve, LUTf &bcurve, LUTf & satcurve, LUTf & satclcurve, LUTf &clcurve, LUTf &curve, bool utili, bool autili, bool butili, bool ccutili, bool cclutili, bool clcutili, LUTu &histCCurve, LUTu &histLurve); void vibrance (LabImage* lab);//Jacques' vibrance // void colorCurve (LabImage* lold, LabImage* lnew); diff --git a/rtengine/settings.h b/rtengine/settings.h index 74a855c3fc..639d3bf4a9 100644 --- a/rtengine/settings.h +++ b/rtengine/settings.h @@ -64,7 +64,6 @@ class Settings bool gamutICC; // no longer used bool gamutLch; - bool ciecamfloat; bool HistogramWorking; int amchroma; int protectred; diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 17ecb6730c..0e9629498c 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -1166,23 +1166,8 @@ class ImageProcessor LUTf CAMBrightCurveQ; float CAMMean = NAN; - if (params.sharpening.enabled) { - if (settings->ciecamfloat) { - float d, dj, yb; - ipf.ciecam_02float (cieView, float (adap), 1, 2, labView, ¶ms, customColCurve1, customColCurve2, customColCurve3, dummy, dummy, CAMBrightCurveJ, CAMBrightCurveQ, CAMMean, 5, 1, true, d, dj, yb, 1); - } else { - double dd, dj; - ipf.ciecam_02 (cieView, adap, 1, 2, labView, ¶ms, customColCurve1, customColCurve2, customColCurve3, dummy, dummy, CAMBrightCurveJ, CAMBrightCurveQ, CAMMean, 5, 1, true, dd, dj, 1); - } - } else { - if (settings->ciecamfloat) { - float d, dj, yb; - ipf.ciecam_02float (cieView, float (adap), 1, 2, labView, ¶ms, customColCurve1, customColCurve2, customColCurve3, dummy, dummy, CAMBrightCurveJ, CAMBrightCurveQ, CAMMean, 5, 1, true, d, dj, yb, 1); - } else { - double dd, dj; - ipf.ciecam_02 (cieView, adap, 1, 2, labView, ¶ms, customColCurve1, customColCurve2, customColCurve3, dummy, dummy, CAMBrightCurveJ, CAMBrightCurveQ, CAMMean, 5, 1, true, dd, dj, 1); - } - } + float d, dj, yb; + ipf.ciecam_02float (cieView, float (adap), 1, 2, labView, ¶ms, customColCurve1, customColCurve2, customColCurve3, dummy, dummy, CAMBrightCurveJ, CAMBrightCurveQ, CAMMean, 5, 1, true, d, dj, yb, 1); } delete cieView; diff --git a/rtgui/options.cc b/rtgui/options.cc index 2e8d20f96d..46ea165493 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -548,7 +548,6 @@ void Options::setDefaults () rtSettings.level0_cbdl = 0; rtSettings.level123_cbdl = 30; - rtSettings.ciecamfloat = true; rtSettings.protectred = 60; rtSettings.protectredh = 0.3; rtSettings.CRI_color = 0; @@ -1428,11 +1427,6 @@ void Options::readFromFile (Glib::ustring fname) rtSettings.gamutICC = keyFile.get_boolean ("Color Management", "GamutICC"); } - //if ( keyFile.has_key ("Color Management", "BWcomplement")) rtSettings.bw_complementary = keyFile.get_boolean("Color Management", "BWcomplement"); - if ( keyFile.has_key ("Color Management", "Ciecamfloat")) { - rtSettings.ciecamfloat = keyFile.get_boolean ("Color Management", "Ciecamfloat"); - } - if ( keyFile.has_key ("Color Management", "AdobeRGB")) { rtSettings.adobe = keyFile.get_string ("Color Management", "AdobeRGB"); } @@ -1993,8 +1987,6 @@ void Options::saveToFile (Glib::ustring fname) keyFile.set_string ("Color Management", "Bruce", rtSettings.bruce); keyFile.set_integer ("Color Management", "WhiteBalanceSpotSize", whiteBalanceSpotSize); keyFile.set_boolean ("Color Management", "GamutICC", rtSettings.gamutICC); - //keyFile.set_boolean ("Color Management", "BWcomplement", rtSettings.bw_complementary); - keyFile.set_boolean ("Color Management", "Ciecamfloat", rtSettings.ciecamfloat); keyFile.set_boolean ("Color Management", "GamutLch", rtSettings.gamutLch); keyFile.set_integer ("Color Management", "ProtectRed", rtSettings.protectred); keyFile.set_integer ("Color Management", "Amountchroma", rtSettings.amchroma); diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index 1089918867..2c5154942f 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -270,7 +270,6 @@ Gtk::Widget* Preferences::getBatchProcPanel () mi = behModel->append (); mi->set_value (behavColumns.label, M ("TP_COLORAPP_LABEL")); - appendBehavList (mi, M ("TP_COLORAPP_CIECAT_DEGREE"), ADDSET_CAT_DEGREE, true); appendBehavList (mi, M ("TP_COLORAPP_ADAPTSCENE"), ADDSET_CAT_ADAPTSCENE, true); appendBehavList (mi, M ("TP_COLORAPP_LIGHT"), ADDSET_CAT_LIGHT, true); appendBehavList (mi, M ("TP_COLORAPP_BRIGHT"), ADDSET_CAT_BRIGHT, true); @@ -903,71 +902,6 @@ Gtk::Widget* Preferences::getColorManagementPanel () mvbcm->pack_start (*fprinter, Gtk::PACK_SHRINK); - //------------------------- CIECAM ---------------------- - - /* - Gtk::Label* viewlab = Gtk::manage (new Gtk::Label (M ("PREFERENCES_VIEW") + ":", Gtk::ALIGN_START)); - setExpandAlignProperties (viewlab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - - view = Gtk::manage (new Gtk::ComboBoxText ()); - setExpandAlignProperties (view, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); - view->append (M("PREFERENCES_D50_MENU")); - - view->append (M ("PREFERENCES_D50")); - view->append (M("PREFERENCES_D55")); - view->append (M("PREFERENCES_D60")); - view->append (M("PREFERENCES_D65")); - view->append (M("PREFERENCES_BLACKBODY")); - view->append (M("PREFERENCES_FLUOF2")); - view->append (M("PREFERENCES_FLUOF7")); - view->append (M("PREFERENCES_FLUOF11")); - - Gtk::Label* greylab = Gtk::manage (new Gtk::Label (M ("PREFERENCES_GREY") + ":", Gtk::ALIGN_START)); - setExpandAlignProperties (greylab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - grey = Gtk::manage (new Gtk::ComboBoxText ()); - setExpandAlignProperties (grey, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); - grey->append (M("PREFERENCES_GREY05")); - grey->append (M("PREFERENCES_GREY10")); - grey->append (M("PREFERENCES_GREY15")); - grey->append (M ("PREFERENCES_GREY18")); - grey->append (M("PREFERENCES_GREY18_MENU")); - - grey->append (M("PREFERENCES_GREY23")); - grey->append (M("PREFERENCES_GREY30")); - grey->append (M("PREFERENCES_GREY40")); - */ - /* - Gtk::Label* greySclab = Gtk::manage (new Gtk::Label (M ("PREFERENCES_GREYSC") + ":", Gtk::ALIGN_START)); - setExpandAlignProperties (greySclab, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - greySc = Gtk::manage (new Gtk::ComboBoxText ()); - setExpandAlignProperties (greySc, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER); - greySc->append (M ("PREFERENCES_GREYSCA")); - greySc->append (M ("PREFERENCES_GREYSC18")); - */ - Gtk::Frame* fcielab = Gtk::manage ( new Gtk::Frame (M ("PREFERENCES_CIEART_FRAME")) ); - setExpandAlignProperties (fcielab, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_START); - - Gtk::Grid* colo = Gtk::manage (new Gtk::Grid ()); - setExpandAlignProperties (colo, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_FILL); - Gtk::Label* lreloadneeded1 = Gtk::manage (new Gtk::Label (M ("PREFERENCES_IMG_RELOAD_NEEDED"), Gtk::ALIGN_START)); - setExpandAlignProperties (lreloadneeded1, true, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - colo->attach (*lreloadneeded1, 0, 0, 2, 1); - /* - colo->attach (*viewlab, 0, 1, 1, 1); - colo->attach (*view, 1, 1, 1, 1); - colo->attach (*greylab, 0, 2, 1, 1); - colo->attach (*grey, 1, 2, 1, 1); - */ -// colo->attach (*greySclab, 0, 3, 1, 1); -// colo->attach (*greySc, 1, 3, 1, 1); - cbciecamfloat = Gtk::manage (new Gtk::CheckButton (M ("PREFERENCES_CIEART_LABEL"))); - setExpandAlignProperties (cbciecamfloat, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - colo->attach (*cbciecamfloat, 0, 4, 2, 1); - cbciecamfloat->set_tooltip_markup (M ("PREFERENCES_CIEART_TOOLTIP")); - fcielab->add (*colo); - - mvbcm->pack_start (*fcielab, Gtk::PACK_SHRINK, 4); - return mvbcm; } @@ -1789,7 +1723,6 @@ void Preferences::storePreferences () // moptions.rtSettings.viewingdevicegrey = grey->get_active_row_number (); // moptions.rtSettings.viewinggreySc = greySc->get_active_row_number (); // moptions.rtSettings.autocielab = cbAutocielab->get_active (); - moptions.rtSettings.ciecamfloat = cbciecamfloat->get_active (); moptions.rtSettings.leveldnv = dnv->get_active_row_number (); moptions.rtSettings.leveldnti = dnti->get_active_row_number (); moptions.rtSettings.leveldnliss = dnliss->get_active_row_number (); @@ -1961,7 +1894,6 @@ void Preferences::fillPreferences () cbdaubech->set_active (moptions.rtSettings.daubech); // cbAutocielab->set_active (moptions.rtSettings.autocielab); - cbciecamfloat->set_active (moptions.rtSettings.ciecamfloat); languages->set_active_text (moptions.language); ckbLangAutoDetect->set_active (moptions.languageAutoDetect); int themeNbr = getThemeRowNumber (moptions.theme); diff --git a/rtgui/preferences.h b/rtgui/preferences.h index ecf3638d99..3a51deb137 100644 --- a/rtgui/preferences.h +++ b/rtgui/preferences.h @@ -114,7 +114,6 @@ class Preferences : public Gtk::Dialog, public ProfileStoreListener Gtk::CheckButton* monBPC; Gtk::CheckButton* cbAutoMonProfile; //Gtk::CheckButton* cbAutocielab; - Gtk::CheckButton* cbciecamfloat; Gtk::CheckButton* cbdaubech; Gtk::SpinButton* hlThresh; Gtk::SpinButton* shThresh;