From a69c631f22a76e3ed4085fd7717d4a4082e372b5 Mon Sep 17 00:00:00 2001 From: Hombre Date: Sat, 3 Sep 2016 00:49:35 +0200 Subject: [PATCH] Fix issue #3411 + revert some code to the old one for better readability --- rtengine/iccstore.cc | 3 +- rtengine/image16.cc | 16 +++---- rtengine/image16.h | 2 +- rtengine/iplab2rgb.cc | 97 ++++++++---------------------------------- rtengine/procparams.cc | 2 +- rtengine/settings.h | 2 +- rtgui/paramsedited.cc | 2 - 7 files changed, 31 insertions(+), 93 deletions(-) diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index b0be63151..13d1fbbdd 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -519,11 +519,12 @@ cmsHPROFILE ICCStore::createGammaProfile (const procparams::ColorManagementParam // 7 parameters for smoother curves cmsFloat64Number Parameters[7] = { ga[0], ga[1], ga[2], ga[3], ga[4], ga[5], ga[6] } ; + lcmsMutex->lock (); cmsWhitePointFromTemp(&xyD, (double)temp); GammaTRC[0] = GammaTRC[1] = GammaTRC[2] = cmsBuildParametricToneCurve(NULL, 5, Parameters); //5 = smoother than 4 cmsHPROFILE oprofdef = cmsCreateRGBProfile(&xyD, &Primaries, GammaTRC); //oprofdef become Outputprofile - cmsFreeToneCurve(GammaTRC[0]); + lcmsMutex->unlock (); return oprofdef; } diff --git a/rtengine/image16.cc b/rtengine/image16.cc index d57bcf6a9..f41ccd036 100644 --- a/rtengine/image16.cc +++ b/rtengine/image16.cc @@ -326,7 +326,7 @@ Image16::tofloat() } // Parallized transformation; create transform with cmsFLAGS_NOCACHE! -void Image16::ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage) +void Image16::ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage, int cx, int cy) { // LittleCMS cannot parallelize planar Lab float images // so build temporary buffers to allow multi processor execution @@ -341,15 +341,15 @@ void Image16::ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImag #pragma omp for schedule(static) #endif - for (int y = 0; y < height; y++) + for (int y = cy; y < cy + height; y++) { unsigned short *pRGB, *pR, *pG, *pB; float *pLab, *pL, *pa, *pb; pLab= bufferLab.data; - pL = labImage.L[y]; - pa = labImage.a[y]; - pb = labImage.b[y]; + pL = labImage.L[y] + cx; + pa = labImage.a[y] + cx; + pb = labImage.b[y] + cx; for (int x = 0; x < width; x++) { *(pLab++) = *(pL++) / 327.68f; @@ -360,9 +360,9 @@ void Image16::ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImag cmsDoTransform (hTransform, bufferLab.data, bufferRGB.data, width); pRGB = bufferRGB.data; - pR = r(y); - pG = g(y); - pB = b(y); + pR = r(y - cy); + pG = g(y - cy); + pB = b(y - cy); for (int x = 0; x < width; x++) { *(pR++) = *(pRGB++); diff --git a/rtengine/image16.h b/rtengine/image16.h index 7fcff307f..58e142560 100644 --- a/rtengine/image16.h +++ b/rtengine/image16.h @@ -96,7 +96,7 @@ public: delete this; } - void ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage); + void ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage, int cx, int cy); }; } diff --git a/rtengine/iplab2rgb.cc b/rtengine/iplab2rgb.cc index 62af03f0a..01144b397 100644 --- a/rtengine/iplab2rgb.cc +++ b/rtengine/iplab2rgb.cc @@ -238,14 +238,14 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, float* rL = lab->L[i]; float* ra = lab->a[i]; float* rb = lab->b[i]; - uint8_t* dest = image->r(i - cy) + cx; + int ix = 3 * i * cw; for (int j = cx; j < cx + cw; j++) { - float fy = (0.0086206897f * (*rL)) / 327.68f + 0.1379310345f; // (L+16)/116 - float fx = (0.002f * *(ra++)) / 327.68f + fy; - float fz = fy - (0.005f * *(rb++)) / 327.68f; - float LL = *(rL++) / 327.68f; + float fy = (0.0086206897f * rL[j]) / 327.68f + 0.1379310345f; // (L+16)/116 + float fx = (0.002f * ra[j]) / 327.68f + fy; + float fz = fy - (0.005f * rb[j]) / 327.68f; + float LL = rL[j] / 327.68f; float x_ = 65535.0f * Color::f2xyz(fx) * Color::D50x; //float y_ = 65535.0f * Color::f2xyz(fy); @@ -254,9 +254,9 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, Color::xyz2rgb(x_, y_, z_, R, G, B, xyz_rgb); - *(dest++) = (int)Color::gamma2curve[CLIP(R)] >> 8; - *(dest++) = (int)Color::gamma2curve[CLIP(G)] >> 8; - *(dest++) = (int)Color::gamma2curve[CLIP(B)] >> 8; + image->data[ix++] = (int)Color::gamma2curve[R] >> 8; + image->data[ix++] = (int)Color::gamma2curve[G] >> 8; + image->data[ix++] = (int)Color::gamma2curve[B] >> 8; } } } @@ -314,63 +314,6 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int } if (oprof) { - - - /* - - -#ifdef _OPENMP - #pragma omp parallel for schedule(dynamic,16) if (multiThread) -#endif - - for (int i = cy; i < cy + ch; i++) { - float* rL = lab->L[i]; - float* ra = lab->a[i]; - float* rb = lab->b[i]; - short* xa = (short*)image->r(i - cy) + cx; - short* ya = (short*)image->g(i - cy) + cx; - short* za = (short*)image->b(i - cy) + cx; - - for (int j = 0; j < cw; j++) { - - float fy = (0.0086206897f * *rL) / 327.68f + 0.1379310345f; // (L+16)/116 - float fx = (0.002f * *(ra++)) / 327.68f + fy; - float fz = fy - (0.005f * *(rb++)) / 327.68f; - float LL = *(rL++) / 327.68f; - - float x_ = 65535.0f * Color::f2xyz(fx) * Color::D50x; - //float y_ = 65535.0f * Color::f2xyz(fy); - float z_ = 65535.0f * Color::f2xyz(fz) * Color::D50z; - float y_ = (LL > (float)Color::epskap) ? 65535.0f * fy * fy * fy : 65535.0f * LL / (float)Color::kappa; - - *xa = CLIP((int) round(x_)) ; - *(ya++) = CLIP((int) round(y_)); - *za = CLIP((int) round(z_)); - - if(bw && y_ < 65535.f) { //force Bw value and take highlight into account - *xa = (int) round(y_ * Color::D50x); - *za = (int) round(y_ * Color::D50z); - } - ++xa; - ++za; - } - } - - cmsHPROFILE iprof = iccStore->getXYZProfile (); - - - */ - - cmsHPROFILE iprof = cmsCreateLab4Profile(nullptr); - - - - - // ---------------------------------------------------------------------------- - - - - cmsUInt32Number flags = cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE; if (icm.outputBPC) { flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; @@ -378,12 +321,11 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int } else printf("lab2rgb16 / icm.outputBPC=false / outputIntent=%d\n", icm.outputIntent); lcmsMutex->lock (); - //cmsHTRANSFORM hTransform = cmsCreateTransform (iprof, TYPE_RGB_16, oprof, TYPE_RGB_16, icm.outputIntent, flags); + cmsHPROFILE iprof = cmsCreateLab4Profile(nullptr); cmsHTRANSFORM hTransform = cmsCreateTransform (iprof, TYPE_Lab_FLT, oprof, TYPE_RGB_16, icm.outputIntent, flags); lcmsMutex->unlock (); - //image->ExecCMSTransform(hTransform); - image->ExecCMSTransform(hTransform, *lab); + image->ExecCMSTransform(hTransform, *lab, cx, cy); cmsDeleteTransform(hTransform); } else { // @@ -395,16 +337,13 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int float* rL = lab->L[i]; float* ra = lab->a[i]; float* rb = lab->b[i]; - uint16_t* rR = image->r(i - cy) + cx; - uint16_t* rG = image->g(i - cy) + cx; - uint16_t* rB = image->b(i - cy) + cx; - for (int j = 0; j < cw; j++) { + for (int j = cx; j < cx + cw; j++) { - float fy = (0.0086206897f * *rL) / 327.68f + 0.1379310345f; // (L+16)/116 - float fx = (0.002f * *(ra++)) / 327.68f + fy; - float fz = fy - (0.005f * *(rb++)) / 327.68f; - float LL = *(rL++) / 327.68f; + float fy = (0.0086206897f * rL[j]) / 327.68f + 0.1379310345f; // (L+16)/116 + float fx = (0.002f * ra[j]) / 327.68f + fy; + float fz = fy - (0.005f * rb[j]) / 327.68f; + float LL = rL[j] / 327.68f; float x_ = 65535.0f * Color::f2xyz(fx) * Color::D50x; //float y_ = 65535.0 * Color::f2xyz(fy); @@ -413,9 +352,9 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int Color::xyz2srgb(x_, y_, z_, R, G, B); - *(rR++) = (int)Color::gamma2curve[CLIP(R)]; - *(rG++) = (int)Color::gamma2curve[CLIP(G)]; - *(rB++) = (int)Color::gamma2curve[CLIP(B)]; + image->r(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(R)]; + image->g(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(G)]; + image->b(i - cy, j - cx) = (int)Color::gamma2curve[CLIP(B)]; } } } diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index a5a2515a5..69cdd17c5 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -5930,7 +5930,7 @@ int ProcParams::load (const Glib::ustring &fname, ParamsEdited* pedited) icm.outputBPC = keyFile.get_boolean ("Color Management", "OutputBPC"); if (pedited) { - pedited->icm.gamfree = true; + pedited->icm.outputBPC = true; } } diff --git a/rtengine/settings.h b/rtengine/settings.h index 3c728f061..4599a28a7 100644 --- a/rtengine/settings.h +++ b/rtengine/settings.h @@ -40,7 +40,7 @@ public: Glib::ustring monitorProfile; ///< ICC profile name used for the monitor RenderingIntent monitorIntent; ///< Colorimetric intent used with the above profile - bool monitorBPC; ///< Black Point Compensation for the WCS->Monitor transform (directly, i.e. not soft-proofing) + bool monitorBPC; ///< Black Point Compensation for the Labimage->Monitor transform (directly, i.e. not soft-proofing and no WCS in between) bool autoMonitorProfile; ///< Try to auto-determine the correct monitor color profile bool autocielab; bool rgbcurveslumamode_gamut;// controls gamut enforcement for RGB curves in lumamode diff --git a/rtgui/paramsedited.cc b/rtgui/paramsedited.cc index b448cd2ee..ff3e4c0b1 100644 --- a/rtgui/paramsedited.cc +++ b/rtgui/paramsedited.cc @@ -2216,8 +2216,6 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten toEdit.icm.outputBPC = mods.icm.outputBPC; } - //if (icm.gampos) toEdit.icm.gampos = mods.icm.gampos; - //if (icm.slpos) toEdit.icm.slpos = mods.icm.slpos; if (icm.gampos) { toEdit.icm.gampos = dontforceSet && options.baBehav[ADDSET_FREE_OUPUT_GAMMA] ? toEdit.icm.gampos + mods.icm.gampos : mods.icm.gampos; }