From 19b7a942af2b5e8520bf0ce0d81b7036569e4881 Mon Sep 17 00:00:00 2001 From: Desmis Date: Sun, 29 Apr 2018 17:08:45 +0200 Subject: [PATCH] Add TRC to working profiles --- rtdata/languages/default | 9 + rtengine/dcrop.cc | 481 ++++++++++++---------- rtengine/iccstore.cc | 30 +- rtengine/image16.cc | 87 ++-- rtengine/image16.h | 51 +-- rtengine/improccoordinator.cc | 736 ++++++++++++++++++---------------- rtengine/improcfun.h | 302 +++++++------- rtengine/iplab2rgb.cc | 312 ++++++++++++-- rtengine/procparams.cc | 16 +- rtengine/procparams.h | 3 + rtengine/simpleprocess.cc | 51 +++ rtgui/icmpanel.cc | 328 +++++++++++---- rtgui/icmpanel.h | 22 +- rtgui/paramsedited.cc | 26 +- rtgui/paramsedited.h | 3 + 15 files changed, 1576 insertions(+), 881 deletions(-) diff --git a/rtdata/languages/default b/rtdata/languages/default index 5e7879daa..91533065e 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -736,6 +736,9 @@ HISTORY_MSG_METADATA_MODE;Metadata copy mode HISTORY_MSG_PREPROCESS_LINEDENOISE_DIRECTION;Line noise filter direction HISTORY_MSG_PREPROCESS_PDAFLINESFILTER;PDAF lines filter HISTORY_MSG_TM_FATTAL_ANCHOR;HDR TM - Anchor +HISTORY_MSG_ICMGAMM;Working gamma +HISTORY_MSG_ICMSLOP;Working slope +HISTORY_MSG_ICMTRCIN;TRC working method HISTORY_MSG_ICMPROFILE;Output profile type HISTORY_MSG_ICMPRIMARI;Output profile primaries HISTORY_MSG_ICMTEMP;Output IccV4 D illuminant @@ -1628,6 +1631,12 @@ TP_GAMMA_TEMP_65;D65 TP_GAMMA_TEMP_80;D80 TP_GAMMA_TEMP_INC;Incandescent 2856K TP_GAMMA_TEMP_TOOLTIP;Only whith generate ICC V4, you can change the illuminant and Free primaries +TP_GAMMA_TRCIN;Gamma - TRC +TP_GAMMA_TRCIN_NONE;None +TP_GAMMA_TRCIN_FREE;Free +TP_GAMMA_TRCIN_TOOLTIP;Only for build in profiles +TP_GAMMAWORK_GAMMA;Gamma +TP_GAMMAWORK_SLOPE;Slope TP_GENERAL_11SCALE_TOOLTIP;The effects of this tool are only visible or only accurate at a preview scale of 1:1. TP_GRADIENT_CENTER;Center TP_GRADIENT_CENTER_X;Center X diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 079a5de16..dc8acc4c7 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -28,9 +28,9 @@ namespace // "ceil" rounding template -constexpr T skips (T a, T b) +constexpr T skips(T a, T b) { - return a / b + static_cast (a % b); + return a / b + static_cast(a % b); } } @@ -40,47 +40,47 @@ namespace rtengine extern const Settings* settings; -Crop::Crop (ImProcCoordinator* parent, EditDataProvider *editDataProvider, bool isDetailWindow) - : PipetteBuffer (editDataProvider), origCrop (nullptr), laboCrop (nullptr), labnCrop (nullptr), - cropImg (nullptr), cbuf_real (nullptr), cshmap (nullptr), transCrop (nullptr), cieCrop (nullptr), cbuffer (nullptr), - updating (false), newUpdatePending (false), skip (10), - cropx (0), cropy (0), cropw (-1), croph (-1), - trafx (0), trafy (0), trafw (-1), trafh (-1), - rqcropx (0), rqcropy (0), rqcropw (-1), rqcroph (-1), - borderRequested (32), upperBorder (0), leftBorder (0), - cropAllocated (false), - cropImageListener (nullptr), parent (parent), isDetailWindow (isDetailWindow) +Crop::Crop(ImProcCoordinator* parent, EditDataProvider *editDataProvider, bool isDetailWindow) + : PipetteBuffer(editDataProvider), origCrop(nullptr), laboCrop(nullptr), labnCrop(nullptr), + cropImg(nullptr), cbuf_real(nullptr), cshmap(nullptr), transCrop(nullptr), cieCrop(nullptr), cbuffer(nullptr), + updating(false), newUpdatePending(false), skip(10), + cropx(0), cropy(0), cropw(-1), croph(-1), + trafx(0), trafy(0), trafw(-1), trafh(-1), + rqcropx(0), rqcropy(0), rqcropw(-1), rqcroph(-1), + borderRequested(32), upperBorder(0), leftBorder(0), + cropAllocated(false), + cropImageListener(nullptr), parent(parent), isDetailWindow(isDetailWindow) { - parent->crops.push_back (this); + parent->crops.push_back(this); } -Crop::~Crop () +Crop::~Crop() { - MyMutex::MyLock cropLock (cropMutex); + MyMutex::MyLock cropLock(cropMutex); - std::vector::iterator i = std::find (parent->crops.begin(), parent->crops.end(), this); + std::vector::iterator i = std::find(parent->crops.begin(), parent->crops.end(), this); - if (i != parent->crops.end ()) { - parent->crops.erase (i); + if (i != parent->crops.end()) { + parent->crops.erase(i); } - MyMutex::MyLock processingLock (parent->mProcessing); - freeAll (); -} - -void Crop::destroy () -{ - MyMutex::MyLock lock (cropMutex); - MyMutex::MyLock processingLock (parent->mProcessing); + MyMutex::MyLock processingLock(parent->mProcessing); freeAll(); } -void Crop::setListener (DetailedCropListener* il) +void Crop::destroy() +{ + MyMutex::MyLock lock(cropMutex); + MyMutex::MyLock processingLock(parent->mProcessing); + freeAll(); +} + +void Crop::setListener(DetailedCropListener* il) { // We can make reads in the IF, because the mProcessing lock is only needed for change if (cropImageListener != il) { - MyMutex::MyLock lock (cropMutex); + MyMutex::MyLock lock(cropMutex); cropImageListener = il; } } @@ -95,9 +95,9 @@ EditUniqueID Crop::getCurrEditID() * Delete the edit image buffer if there's no subscriber anymore. * If allocation has to be done, it is deferred to Crop::update */ -void Crop::setEditSubscriber (EditSubscriber* newSubscriber) +void Crop::setEditSubscriber(EditSubscriber* newSubscriber) { - MyMutex::MyLock lock (cropMutex); + MyMutex::MyLock lock(cropMutex); // At this point, editCrop.dataProvider->currSubscriber is the old subscriber EditSubscriber *oldSubscriber = PipetteBuffer::dataProvider ? PipetteBuffer::dataProvider->getCurrSubscriber() : nullptr; @@ -123,13 +123,13 @@ void Crop::setEditSubscriber (EditSubscriber* newSubscriber) bool Crop::hasListener() { - MyMutex::MyLock cropLock (cropMutex); + MyMutex::MyLock cropLock(cropMutex); return cropImageListener; } -void Crop::update (int todo) +void Crop::update(int todo) { - MyMutex::MyLock cropLock (cropMutex); + MyMutex::MyLock cropLock(cropMutex); ProcParams& params = parent->params; // CropGUIListener* cropgl; @@ -142,16 +142,16 @@ void Crop::update (int todo) bool overrideWindow = false; if (cropImageListener) { - overrideWindow = cropImageListener->getWindow (wx, wy, ww, wh, ws); + overrideWindow = cropImageListener->getWindow(wx, wy, ww, wh, ws); } // re-allocate sub-images and arrays if their dimensions changed bool needsinitupdate = false; if (!overrideWindow) { - needsinitupdate = setCropSizes (rqcropx, rqcropy, rqcropw, rqcroph, skip, true); + needsinitupdate = setCropSizes(rqcropx, rqcropy, rqcropw, rqcroph, skip, true); } else { - needsinitupdate = setCropSizes (wx, wy, ww, wh, ws, true); // this set skip=ws + needsinitupdate = setCropSizes(wx, wy, ww, wh, ws, true); // this set skip=ws } // it something has been reallocated, all processing steps have to be performed @@ -160,7 +160,7 @@ void Crop::update (int todo) } // Tells to the ImProcFunctions' tool what is the preview scale, which may lead to some simplifications - parent->ipf.setScale (skip); + parent->ipf.setScale(skip); Imagefloat* baseCrop = origCrop; int widIm = parent->fw;//full image @@ -169,12 +169,12 @@ void Crop::update (int todo) bool needstransform = parent->ipf.needsTransform(); if (todo & (M_INIT | M_LINDENOISE | M_HDR)) { - MyMutex::MyLock lock (parent->minit); // Also used in improccoord + MyMutex::MyLock lock(parent->minit); // Also used in improccoord - int tr = getCoarseBitMask (params.coarse); + int tr = getCoarseBitMask(params.coarse); if (!needsinitupdate) { - setCropSizes (rqcropx, rqcropy, rqcropw, rqcroph, skip, true); + setCropSizes(rqcropx, rqcropy, rqcropw, rqcroph, skip, true); } // printf("x=%d y=%d crow=%d croh=%d skip=%d\n",rqcropx, rqcropy, rqcropw, rqcroph, skip); @@ -186,7 +186,7 @@ void Crop::update (int todo) float autoNR = (float) settings->nrauto;// float autoNRmax = (float) settings->nrautomax;// - params.dirpyrDenoise.getCurves (noiseLCurve, noiseCCurve); + params.dirpyrDenoise.getCurves(noiseLCurve, noiseCCurve); int tilesize; int overlap; @@ -204,7 +204,7 @@ void Crop::update (int todo) int numtiles_W, numtiles_H, tilewidth, tileheight, tileWskip, tileHskip; int kall = 2; - parent->ipf.Tile_calc (tilesize, overlap, kall, widIm, heiIm, numtiles_W, numtiles_H, tilewidth, tileheight, tileWskip, tileHskip); + parent->ipf.Tile_calc(tilesize, overlap, kall, widIm, heiIm, numtiles_W, numtiles_H, tilewidth, tileheight, tileWskip, tileHskip); kall = 0; float *min_b = new float [9]; @@ -226,20 +226,20 @@ void Crop::update (int todo) } if (settings->leveldnautsimpl == 1) { - if (params.dirpyrDenoise.Cmethod == "MAN" || params.dirpyrDenoise.Cmethod == "PON" ) { - PreviewProps pp (trafx, trafy, trafw * skip, trafh * skip, skip); - parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw ); + if (params.dirpyrDenoise.Cmethod == "MAN" || params.dirpyrDenoise.Cmethod == "PON") { + PreviewProps pp(trafx, trafy, trafw * skip, trafh * skip, skip); + parent->imgsrc->getImage(parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw); } } else { if (params.dirpyrDenoise.C2method == "MANU") { - PreviewProps pp (trafx, trafy, trafw * skip, trafh * skip, skip); - parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw ); + PreviewProps pp(trafx, trafy, trafw * skip, trafh * skip, skip); + parent->imgsrc->getImage(parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw); } } if ((settings->leveldnautsimpl == 1 && params.dirpyrDenoise.Cmethod == "PRE") || (settings->leveldnautsimpl == 0 && params.dirpyrDenoise.C2method == "PREV")) { - PreviewProps pp (trafx, trafy, trafw * skip, trafh * skip, skip); - parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw ); + PreviewProps pp(trafx, trafy, trafw * skip, trafh * skip, skip); + parent->imgsrc->getImage(parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw); if ((!isDetailWindow) && parent->adnListener && skip == 1 && params.dirpyrDenoise.enabled) { float lowdenoise = 1.f; @@ -257,15 +257,15 @@ void Crop::update (int todo) int poscenterY = 0; for (int cc = 0; cc < numtiles_W; cc++) { - if (abs (centerTile_X[cc] - CenterPreview_X) < minimuX) { - minimuX = abs (centerTile_X[cc] - CenterPreview_X); + if (abs(centerTile_X[cc] - CenterPreview_X) < minimuX) { + minimuX = abs(centerTile_X[cc] - CenterPreview_X); poscenterX = cc; } } for (int cc = 0; cc < numtiles_H; cc++) { - if (abs (centerTile_Y[cc] - CenterPreview_Y) < minimuY) { - minimuY = abs (centerTile_Y[cc] - CenterPreview_Y); + if (abs(centerTile_Y[cc] - CenterPreview_Y) < minimuY) { + minimuY = abs(centerTile_Y[cc] - CenterPreview_Y); poscenterY = cc; } } @@ -292,7 +292,7 @@ void Crop::update (int todo) float adjustr = 1.f; - if (params.icm.working == "ProPhoto") { + if (params.icm.working == "ProPhoto") { adjustr = 1.f; } else if (params.icm.working == "Adobe RGB") { adjustr = 1.f / 1.3f; @@ -309,7 +309,7 @@ void Crop::update (int todo) } if (parent->adnListener) { - parent->adnListener->noiseTilePrev (centerTile_X[poscenterX], centerTile_Y[poscenterY], CenterPreview_X, CenterPreview_Y, crW, trafw * skip); + parent->adnListener->noiseTilePrev(centerTile_X[poscenterX], centerTile_Y[poscenterY], CenterPreview_X, CenterPreview_Y, crW, trafw * skip); } // I have tried "blind" some solutions..to move review ...but GUI is not my truc ! @@ -323,17 +323,17 @@ void Crop::update (int todo) // we only need image reduced to 1/4 here int W = origCrop->getWidth(); int H = origCrop->getHeight(); - Imagefloat *provicalc = new Imagefloat ((W + 1) / 2, (H + 1) / 2); //for denoise curves + Imagefloat *provicalc = new Imagefloat((W + 1) / 2, (H + 1) / 2); //for denoise curves for (int ii = 0; ii < H; ii += 2) { for (int jj = 0; jj < W; jj += 2) { - provicalc->r (ii >> 1, jj >> 1) = origCrop->r (ii, jj); - provicalc->g (ii >> 1, jj >> 1) = origCrop->g (ii, jj); - provicalc->b (ii >> 1, jj >> 1) = origCrop->b (ii, jj); + provicalc->r(ii >> 1, jj >> 1) = origCrop->r(ii, jj); + provicalc->g(ii >> 1, jj >> 1) = origCrop->g(ii, jj); + provicalc->b(ii >> 1, jj >> 1) = origCrop->b(ii, jj); } } - parent->imgsrc->convertColorSpace (provicalc, params.icm, parent->currWB); //for denoise luminance curve + parent->imgsrc->convertColorSpace(provicalc, params.icm, parent->currWB); //for denoise luminance curve float maxr = 0.f; float maxb = 0.f; @@ -347,10 +347,10 @@ void Crop::update (int todo) maxblueaut = 0.f; minredaut = 0.f; minblueaut = 0.f; - LUTf gamcurve (65536, 0); + LUTf gamcurve(65536, 0); float gam, gamthresh, gamslope; - parent->ipf.RGB_denoise_infoGamCurve (params.dirpyrDenoise, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope); - parent->ipf.RGB_denoise_info (origCrop, provicalc, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, parent->imgsrc->getDirPyrDenoiseExpComp(), chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc, true); + parent->ipf.RGB_denoise_infoGamCurve(params.dirpyrDenoise, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope); + parent->ipf.RGB_denoise_info(origCrop, provicalc, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, parent->imgsrc->getDirPyrDenoiseExpComp(), chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc, true); // printf("redy=%f skin=%f pcskin=%f\n",redyel, skinc,nsknc); // printf("DCROP skip=%d cha=%4.0f Nb=%d red=%4.0f bl=%4.0f redM=%4.0f bluM=%4.0f L=%4.0f sigL=%4.0f Ch=%4.0f Si=%4.0f\n",skip, chaut,Nb, redaut,blueaut, maxredaut, maxblueaut, lumema, sigma_L, chromina, sigma); float multip = 1.f; @@ -359,12 +359,12 @@ void Crop::update (int todo) multip = 2.f; //take into account gamma for TIF / JPG approximate value...not good for gamma=1 } - float maxmax = max (maxredaut, maxblueaut); + float maxmax = max(maxredaut, maxblueaut); float delta; int mode = 0; // float redyel, skinc, nsknc; int lissage = settings->leveldnliss; - parent->ipf.calcautodn_info (chaut, delta, Nb, levaut, maxmax, lumema, chromina, mode, lissage, redyel, skinc, nsknc); + parent->ipf.calcautodn_info(chaut, delta, Nb, levaut, maxmax, lumema, chromina, mode, lissage, redyel, skinc, nsknc); if (maxredaut > maxblueaut) { @@ -387,7 +387,7 @@ void Crop::update (int todo) params.dirpyrDenoise.chroma = chaut / (autoNR * multip * adjustr * lowdenoise); params.dirpyrDenoise.redchro = maxr; params.dirpyrDenoise.bluechro = maxb; - parent->adnListener->chromaChanged (params.dirpyrDenoise.chroma, params.dirpyrDenoise.redchro, params.dirpyrDenoise.bluechro); + parent->adnListener->chromaChanged(params.dirpyrDenoise.chroma, params.dirpyrDenoise.redchro, params.dirpyrDenoise.bluechro); delete provicalc; } @@ -423,16 +423,16 @@ void Crop::update (int todo) lowdenoise = 0.7f; } - LUTf gamcurve (65536, 0); + LUTf gamcurve(65536, 0); float gam, gamthresh, gamslope; - parent->ipf.RGB_denoise_infoGamCurve (params.dirpyrDenoise, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope); + parent->ipf.RGB_denoise_infoGamCurve(params.dirpyrDenoise, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope); int Nb[9]; #ifdef _OPENMP #pragma omp parallel #endif { - Imagefloat *origCropPart = new Imagefloat (crW, crH);//allocate memory - Imagefloat *provicalc = new Imagefloat ((crW + 1) / 2, (crH + 1) / 2); //for denoise curves + Imagefloat *origCropPart = new Imagefloat(crW, crH); //allocate memory + Imagefloat *provicalc = new Imagefloat((crW + 1) / 2, (crH + 1) / 2); //for denoise curves int coordW[3];//coordinate of part of image to measure noise int coordH[3]; @@ -450,24 +450,24 @@ void Crop::update (int todo) for (int wcr = 0; wcr <= 2; wcr++) { for (int hcr = 0; hcr <= 2; hcr++) { - PreviewProps ppP (coordW[wcr], coordH[hcr], crW, crH, 1); - parent->imgsrc->getImage (parent->currWB, tr, origCropPart, ppP, params.toneCurve, params.raw ); + PreviewProps ppP(coordW[wcr], coordH[hcr], crW, crH, 1); + parent->imgsrc->getImage(parent->currWB, tr, origCropPart, ppP, params.toneCurve, params.raw); // we only need image reduced to 1/4 here for (int ii = 0; ii < crH; ii += 2) { for (int jj = 0; jj < crW; jj += 2) { - provicalc->r (ii >> 1, jj >> 1) = origCropPart->r (ii, jj); - provicalc->g (ii >> 1, jj >> 1) = origCropPart->g (ii, jj); - provicalc->b (ii >> 1, jj >> 1) = origCropPart->b (ii, jj); + provicalc->r(ii >> 1, jj >> 1) = origCropPart->r(ii, jj); + provicalc->g(ii >> 1, jj >> 1) = origCropPart->g(ii, jj); + provicalc->b(ii >> 1, jj >> 1) = origCropPart->b(ii, jj); } } - parent->imgsrc->convertColorSpace (provicalc, params.icm, parent->currWB); //for denoise luminance curve + parent->imgsrc->convertColorSpace(provicalc, params.icm, parent->currWB); //for denoise luminance curve float pondcorrec = 1.0f; float chaut = 0.f, redaut = 0.f, blueaut = 0.f, maxredaut = 0.f, maxblueaut = 0.f, minredaut = 0.f, minblueaut = 0.f, chromina = 0.f, sigma = 0.f, lumema = 0.f, sigma_L = 0.f, redyel = 0.f, skinc = 0.f, nsknc = 0.f; int nb = 0; - parent->ipf.RGB_denoise_info (origCropPart, provicalc, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, parent->imgsrc->getDirPyrDenoiseExpComp(), chaut, nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); + parent->ipf.RGB_denoise_info(origCropPart, provicalc, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, parent->imgsrc->getDirPyrDenoiseExpComp(), chaut, nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); //printf("DCROP skip=%d cha=%f red=%f bl=%f redM=%f bluM=%f chrom=%f sigm=%f lum=%f\n",skip, chaut,redaut,blueaut, maxredaut, maxblueaut, chromina, sigma, lumema); Nb[hcr * 3 + wcr] = nb; @@ -512,7 +512,7 @@ void Crop::update (int todo) float adjustr = 1.f; - if (params.icm.working == "ProPhoto") { + if (params.icm.working == "ProPhoto") { adjustr = 1.f; // } else if (params.icm.working == "Adobe RGB") { adjustr = 1.f / 1.3f; @@ -533,8 +533,8 @@ void Crop::update (int todo) int lissage = settings->leveldnliss; for (int k = 0; k < 9; k++) { - float maxmax = max (parent->denoiseInfoStore.max_r[k], parent->denoiseInfoStore.max_b[k]); - parent->ipf.calcautodn_info (parent->denoiseInfoStore.ch_M[k], delta[k], Nb[k], levaut, maxmax, lumL[k], chromC[k], mode, lissage, ry[k], sk[k], pcsk[k]); + float maxmax = max(parent->denoiseInfoStore.max_r[k], parent->denoiseInfoStore.max_b[k]); + parent->ipf.calcautodn_info(parent->denoiseInfoStore.ch_M[k], delta[k], Nb[k], levaut, maxmax, lumL[k], chromC[k], mode, lissage, ry[k], sk[k], pcsk[k]); // printf("ch_M=%f delta=%f\n",ch_M[k], delta[k]); } @@ -599,12 +599,12 @@ void Crop::update (int todo) parent->denoiseInfoStore.valid = true; if (parent->adnListener) { - parent->adnListener->chromaChanged (params.dirpyrDenoise.chroma, params.dirpyrDenoise.redchro, params.dirpyrDenoise.bluechro); + parent->adnListener->chromaChanged(params.dirpyrDenoise.chroma, params.dirpyrDenoise.redchro, params.dirpyrDenoise.bluechro); } if (settings->verbose) { t2aue.set(); - printf ("Info denoise auto performed in %d usec:\n", t2aue.etime (t1aue)); + printf("Info denoise auto performed in %d usec:\n", t2aue.etime(t1aue)); } //end evaluate noise @@ -612,8 +612,8 @@ void Crop::update (int todo) // if(params.dirpyrDenoise.Cmethod=="AUT" || params.dirpyrDenoise.Cmethod=="PON") {//reinit origCrop after Auto if ((settings->leveldnautsimpl == 1 && params.dirpyrDenoise.Cmethod == "AUT") || (settings->leveldnautsimpl == 0 && params.dirpyrDenoise.C2method == "AUTO")) { //reinit origCrop after Auto - PreviewProps pp (trafx, trafy, trafw * skip, trafh * skip, skip); - parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw ); + PreviewProps pp(trafx, trafy, trafw * skip, trafh * skip, skip); + parent->imgsrc->getImage(parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw); } DirPyrDenoiseParams denoiseParams = params.dirpyrDenoise; @@ -628,25 +628,25 @@ void Crop::update (int todo) noiseLCurve.Reset(); } - if ((noiseLCurve || noiseCCurve ) && skip == 1 && denoiseParams.enabled) { //only allocate memory if enabled and skip + if ((noiseLCurve || noiseCCurve) && skip == 1 && denoiseParams.enabled) { //only allocate memory if enabled and skip // we only need image reduced to 1/4 here int W = origCrop->getWidth(); int H = origCrop->getHeight(); - calclum = new Imagefloat ((W + 1) / 2, (H + 1) / 2); //for denoise curves + calclum = new Imagefloat((W + 1) / 2, (H + 1) / 2); //for denoise curves for (int ii = 0; ii < H; ii += 2) { for (int jj = 0; jj < W; jj += 2) { - calclum->r (ii >> 1, jj >> 1) = origCrop->r (ii, jj); - calclum->g (ii >> 1, jj >> 1) = origCrop->g (ii, jj); - calclum->b (ii >> 1, jj >> 1) = origCrop->b (ii, jj); + calclum->r(ii >> 1, jj >> 1) = origCrop->r(ii, jj); + calclum->g(ii >> 1, jj >> 1) = origCrop->g(ii, jj); + calclum->b(ii >> 1, jj >> 1) = origCrop->b(ii, jj); } } - parent->imgsrc->convertColorSpace (calclum, params.icm, parent->currWB); //for denoise luminance curve + parent->imgsrc->convertColorSpace(calclum, params.icm, parent->currWB); //for denoise luminance curve } if (skip != 1) if (parent->adnListener) { - parent->adnListener->noiseChanged (0.f, 0.f); + parent->adnListener->noiseChanged(0.f, 0.f); } if (todo & M_LINDENOISE) { @@ -654,26 +654,26 @@ void Crop::update (int todo) int kall = 0; float nresi, highresi; - parent->ipf.RGB_denoise (kall, origCrop, origCrop, calclum, parent->denoiseInfoStore.ch_M, parent->denoiseInfoStore.max_r, parent->denoiseInfoStore.max_b, parent->imgsrc->isRAW(), /*Roffset,*/ denoiseParams, parent->imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, nresi, highresi); + parent->ipf.RGB_denoise(kall, origCrop, origCrop, calclum, parent->denoiseInfoStore.ch_M, parent->denoiseInfoStore.max_r, parent->denoiseInfoStore.max_b, parent->imgsrc->isRAW(), /*Roffset,*/ denoiseParams, parent->imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, nresi, highresi); if (parent->adnListener) { - parent->adnListener->noiseChanged (nresi, highresi); + parent->adnListener->noiseChanged(nresi, highresi); } if (settings->leveldnautsimpl == 1) { if ((denoiseParams.Cmethod == "AUT" || denoiseParams.Cmethod == "PRE") && (parent->adnListener)) { // force display value of sliders - parent->adnListener->chromaChanged (denoiseParams.chroma, denoiseParams.redchro, denoiseParams.bluechro); + parent->adnListener->chromaChanged(denoiseParams.chroma, denoiseParams.redchro, denoiseParams.bluechro); } } else { if ((denoiseParams.C2method == "AUTO" || denoiseParams.C2method == "PREV") && (parent->adnListener)) { // force display value of sliders - parent->adnListener->chromaChanged (denoiseParams.chroma, denoiseParams.redchro, denoiseParams.bluechro); + parent->adnListener->chromaChanged(denoiseParams.chroma, denoiseParams.redchro, denoiseParams.bluechro); } } } } - parent->imgsrc->convertColorSpace (origCrop, params.icm, parent->currWB); + parent->imgsrc->convertColorSpace(origCrop, params.icm, parent->currWB); delete [] min_r; delete [] min_b; @@ -688,9 +688,10 @@ void Crop::update (int todo) } // has to be called after setCropSizes! Tools prior to this point can't handle the Edit mechanism, but that shouldn't be a problem. - createBuffer (cropw, croph); + createBuffer(cropw, croph); std::unique_ptr fattalCrop; + if ((todo & M_HDR) && params.fattal.enabled) { Imagefloat *f = origCrop; int fw = skips(parent->fw, skip); @@ -700,6 +701,7 @@ void Crop::update (int todo) if (trafx || trafy || trafw != fw || trafh != fh) { need_cropping = true; + // fattal needs to work on the full image. So here we get the full // image from imgsrc, and replace the denoised crop in case if (!params.dirpyrDenoise.enabled && skip == 1 && parent->fattal_11_dcrop_cache) { @@ -708,7 +710,7 @@ void Crop::update (int todo) } else { f = new Imagefloat(fw, fh); fattalCrop.reset(f); - PreviewProps pp (0, 0, parent->fw, parent->fh, skip); + PreviewProps pp(0, 0, parent->fw, parent->fh, skip); int tr = getCoarseBitMask(params.coarse); parent->imgsrc->getImage(parent->currWB, tr, f, pp, params.toneCurve, params.raw); parent->imgsrc->convertColorSpace(f, params.icm, parent->currWB); @@ -720,8 +722,10 @@ void Crop::update (int todo) #ifdef _OPENMP #pragma omp parallel for #endif + for (int y = 0; y < baseCrop->getHeight(); ++y) { int dy = oy + y; + for (int x = 0; x < baseCrop->getWidth(); ++x) { int dx = ox + x; f->r(dy, dx) = baseCrop->r(y, x); @@ -735,6 +739,7 @@ void Crop::update (int todo) } } } + if (need_fattal) { parent->ipf.ToneMapFattal02(f); } @@ -748,8 +753,10 @@ void Crop::update (int todo) #ifdef _OPENMP #pragma omp parallel for #endif + for (int y = 0; y < trafh; ++y) { int cy = y + oy; + for (int x = 0; x < trafw; ++x) { int cx = x + ox; c->r(y, x) = f->r(cy, cx); @@ -757,24 +764,25 @@ void Crop::update (int todo) c->b(y, x) = f->b(cy, cx); } } + baseCrop = c; } else { baseCrop = f; } } - + // transform if (needstransform || ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.dirpyrequalizer.cbdlMethod == "bef" && params.dirpyrequalizer.enabled && !params.colorappearance.enabled)) { if (!transCrop) { - transCrop = new Imagefloat (cropw, croph); + transCrop = new Imagefloat(cropw, croph); } if (needstransform) - parent->ipf.transform (baseCrop, transCrop, cropx / skip, cropy / skip, trafx / skip, trafy / skip, skips (parent->fw, skip), skips (parent->fh, skip), parent->getFullWidth(), parent->getFullHeight(), - parent->imgsrc->getMetaData(), - parent->imgsrc->getRotateDegree(), false); + parent->ipf.transform(baseCrop, transCrop, cropx / skip, cropy / skip, trafx / skip, trafy / skip, skips(parent->fw, skip), skips(parent->fh, skip), parent->getFullWidth(), parent->getFullHeight(), + parent->imgsrc->getMetaData(), + parent->imgsrc->getRotateDegree(), false); else { - baseCrop->copyData (transCrop); + baseCrop->copyData(transCrop); } if (transCrop) { @@ -792,16 +800,16 @@ void Crop::update (int todo) const int W = baseCrop->getWidth(); const int H = baseCrop->getHeight(); - LabImage labcbdl (W, H); - parent->ipf.rgb2lab (*baseCrop, labcbdl, params.icm.working); - parent->ipf.dirpyrequalizer (&labcbdl, skip); - parent->ipf.lab2rgb (labcbdl, *baseCrop, params.icm.working); + LabImage labcbdl(W, H); + parent->ipf.rgb2lab(*baseCrop, labcbdl, params.icm.working); + parent->ipf.dirpyrequalizer(&labcbdl, skip); + parent->ipf.lab2rgb(labcbdl, *baseCrop, params.icm.working); } // blurmap for shadow & highlights if ((todo & M_BLURMAP) && params.sh.enabled) { - double radius = sqrt (double (skips (parent->fw, skip) * skips (parent->fw, skip) + skips (parent->fh, skip) * skips (parent->fh, skip))) / 2.0; + double radius = sqrt(double (skips(parent->fw, skip) * skips(parent->fw, skip) + skips(parent->fh, skip) * skips(parent->fh, skip))) / 2.0; double shradius = params.sh.radius; if (!params.sh.hq) { @@ -809,13 +817,13 @@ void Crop::update (int todo) } if (!cshmap) { - cshmap = new SHMap (cropw, croph, true); + cshmap = new SHMap(cropw, croph, true); } - cshmap->update (baseCrop, shradius, parent->ipf.lumimul, params.sh.hq, skip); + cshmap->update(baseCrop, shradius, parent->ipf.lumimul, params.sh.hq, skip); if (parent->shmap->min_f < 65535.f) { // don't call forceStat with wrong values - cshmap->forceStat (parent->shmap->max_f, parent->shmap->min_f, parent->shmap->avg); + cshmap->forceStat(parent->shmap->max_f, parent->shmap->min_f, parent->shmap->avg); } } @@ -833,16 +841,65 @@ void Crop::update (int todo) parent->imgsrc->getGamma()); }*/ + if (todo & M_INIT) { + if (params.icm.wtrcin == "free") { //exec TRC IN free + Glib::ustring profi; + profi = params.icm.working; + + if (profi == "sRGB" || profi == "Adobe RGB" || profi == "ProPhoto" || profi == "WideGamut" || profi == "BruceRGB" || profi == "Beta RGB" || profi == "BestRGB" || profi == "Rec2020" || profi == "ACESp0" || profi == "ACESp1") { + + //first put gamma TRC to 1 + int cw = baseCrop->getWidth(); + int ch = baseCrop->getHeight(); + Image16* readyImg0 = NULL; + double ga0, ga1, ga2, ga3, ga4, ga5, ga6; + int mul = -5; + double gga = 2.4, ssl = 12.92; + + readyImg0 = parent->ipf.workingtrc(baseCrop, cw, ch, mul, params.icm.working, gga, ssl, ga0, ga1, ga2, ga3, ga4, ga5, ga6); + + #pragma omp parallel for + + for (int row = 0; row < ch; row++) { + for (int col = 0; col < cw; col++) { + baseCrop->r(row, col) = (float)readyImg0->r(row, col); + baseCrop->g(row, col) = (float)readyImg0->g(row, col); + baseCrop->b(row, col) = (float)readyImg0->b(row, col); + } + } + + delete readyImg0; + //adjust gamma TRC + Image16* readyImg = NULL; + gga = params.icm.gamm, ssl = params.icm.slop; + mul = 5; + readyImg = parent->ipf.workingtrc(baseCrop, cw, ch, mul, params.icm.working, gga, ssl, ga0, ga1, ga2, ga3, ga4, ga5, ga6); + #pragma omp parallel for + + for (int row = 0; row < ch; row++) { + for (int col = 0; col < cw; col++) { + baseCrop->r(row, col) = (float)readyImg->r(row, col); + baseCrop->g(row, col) = (float)readyImg->g(row, col); + baseCrop->b(row, col) = (float)readyImg->b(row, col); + } + } + + delete readyImg; + + } + } + } + if (todo & M_RGBCURVE) { double rrm, ggm, bbm; DCPProfile::ApplyState as; - DCPProfile *dcpProf = parent->imgsrc->getDCP (params.icm, as); + DCPProfile *dcpProf = parent->imgsrc->getDCP(params.icm, as); LUTu histToneCurve; - parent->ipf.rgbProc (baseCrop, laboCrop, this, parent->hltonecurve, parent->shtonecurve, parent->tonecurve, cshmap, - params.toneCurve.saturation, parent->rCurve, parent->gCurve, parent->bCurve, parent->colourToningSatLimit, parent->colourToningSatLimitOpacity, parent->ctColorCurve, parent->ctOpacityCurve, parent->opautili, parent->clToningcurve, parent->cl2Toningcurve, - parent->customToneCurve1, parent->customToneCurve2, parent->beforeToneCurveBW, parent->afterToneCurveBW, rrm, ggm, bbm, - parent->bwAutoR, parent->bwAutoG, parent->bwAutoB, dcpProf, as, histToneCurve); + parent->ipf.rgbProc(baseCrop, laboCrop, this, parent->hltonecurve, parent->shtonecurve, parent->tonecurve, cshmap, + params.toneCurve.saturation, parent->rCurve, parent->gCurve, parent->bCurve, parent->colourToningSatLimit, parent->colourToningSatLimitOpacity, parent->ctColorCurve, parent->ctOpacityCurve, parent->opautili, parent->clToningcurve, parent->cl2Toningcurve, + parent->customToneCurve1, parent->customToneCurve2, parent->beforeToneCurveBW, parent->afterToneCurveBW, rrm, ggm, bbm, + parent->bwAutoR, parent->bwAutoG, parent->bwAutoB, dcpProf, as, histToneCurve); } /*xref=000;yref=000; @@ -864,7 +921,7 @@ void Crop::update (int todo) // apply luminance operations if (todo & (M_LUMINANCE + M_COLOR)) { //I made a little change here. Rather than have luminanceCurve (and others) use in/out lab images, we can do more if we copy right here. - labnCrop->CopyFrom (laboCrop); + labnCrop->CopyFrom(laboCrop); //parent->ipf.luminanceCurve (labnCrop, labnCrop, parent->lumacurve); @@ -877,29 +934,29 @@ void Crop::update (int todo) LUTu dummy; // parent->ipf.MSR(labnCrop, labnCrop->W, labnCrop->H, 1); - parent->ipf.chromiLuminanceCurve (this, 1, labnCrop, labnCrop, parent->chroma_acurve, parent->chroma_bcurve, parent->satcurve, parent->lhskcurve, parent->clcurve, parent->lumacurve, utili, autili, butili, ccutili, cclutili, clcutili, dummy, dummy); - parent->ipf.vibrance (labnCrop); + parent->ipf.chromiLuminanceCurve(this, 1, labnCrop, labnCrop, parent->chroma_acurve, parent->chroma_bcurve, parent->satcurve, parent->lhskcurve, parent->clcurve, parent->lumacurve, utili, autili, butili, ccutili, cclutili, clcutili, dummy, dummy); + parent->ipf.vibrance(labnCrop); - if ((params.colorappearance.enabled && !params.colorappearance.tonecie) || (!params.colorappearance.enabled)) { - parent->ipf.EPDToneMap (labnCrop, 5, skip); + if ((params.colorappearance.enabled && !params.colorappearance.tonecie) || (!params.colorappearance.enabled)) { + parent->ipf.EPDToneMap(labnCrop, 5, skip); } //parent->ipf.EPDToneMap(labnCrop, 5, 1); //Go with much fewer than normal iterates for fast redisplay. // for all treatments Defringe, Sharpening, Contrast detail , Microcontrast they are activated if "CIECAM" function are disabled if (skip == 1) { if ((params.colorappearance.enabled && !settings->autocielab) || (!params.colorappearance.enabled)) { - parent->ipf.impulsedenoise (labnCrop); + parent->ipf.impulsedenoise(labnCrop); } - if ((params.colorappearance.enabled && !settings->autocielab) || (!params.colorappearance.enabled) ) { - parent->ipf.defringe (labnCrop); + if ((params.colorappearance.enabled && !settings->autocielab) || (!params.colorappearance.enabled)) { + parent->ipf.defringe(labnCrop); } - parent->ipf.MLsharpen (labnCrop); + parent->ipf.MLsharpen(labnCrop); if ((params.colorappearance.enabled && !settings->autocielab) || (!params.colorappearance.enabled)) { - parent->ipf.MLmicrocontrast (labnCrop); - parent->ipf.sharpening (labnCrop, (float**)cbuffer, params.sharpening); + parent->ipf.MLmicrocontrast(labnCrop); + parent->ipf.sharpening(labnCrop, (float**)cbuffer, params.sharpening); } } @@ -908,13 +965,13 @@ void Crop::update (int todo) if (params.dirpyrequalizer.cbdlMethod == "aft") { if (((params.colorappearance.enabled && !settings->autocielab) || (!params.colorappearance.enabled))) { - parent->ipf.dirpyrequalizer (labnCrop, skip); + parent->ipf.dirpyrequalizer(labnCrop, skip); // parent->ipf.Lanczoslab (labnCrop,labnCrop , 1.f/skip); } } int kall = 0; - int minwin = min (labnCrop->W, labnCrop->H); + int minwin = min(labnCrop->W, labnCrop->H); int maxlevelcrop = 10; // if(cp.mul[9]!=0)maxlevelcrop=10; @@ -954,10 +1011,10 @@ void Crop::update (int todo) int numtiles_W, numtiles_H, tilewidth, tileheight, tileWskip, tileHskip; - parent->ipf.Tile_calc (tilesize, overlap, kall, labnCrop->W, labnCrop->H, numtiles_W, numtiles_H, tilewidth, tileheight, tileWskip, tileHskip); + parent->ipf.Tile_calc(tilesize, overlap, kall, labnCrop->W, labnCrop->H, numtiles_W, numtiles_H, tilewidth, tileheight, tileWskip, tileHskip); //now we have tile dimensions, overlaps //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - int minsizetile = min (tilewidth, tileheight); + int minsizetile = min(tilewidth, tileheight); int maxlev2 = 10; if (minsizetile < 1024 && maxlevelcrop == 10) { @@ -976,10 +1033,10 @@ void Crop::update (int todo) maxlev2 = 6; } - int maxL = min (maxlev2, maxlevelcrop); + int maxL = min(maxlev2, maxlevelcrop); if (parent->awavListener) { - parent->awavListener->wavChanged (float (maxL)); + parent->awavListener->wavChanged(float (maxL)); } if ((params.wavelet.enabled)) { @@ -991,28 +1048,28 @@ void Crop::update (int todo) LUTf wavclCurve; LUTu dummy; - params.wavelet.getCurves (wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL); + params.wavelet.getCurves(wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL); - parent->ipf.ip_wavelet (labnCrop, labnCrop, kall, WaveParams, wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL, parent->wavclCurve, skip); + parent->ipf.ip_wavelet(labnCrop, labnCrop, kall, WaveParams, wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL, parent->wavclCurve, skip); } // } // } if (params.colorappearance.enabled) { - float fnum = parent->imgsrc->getMetaData()->getFNumber (); // F number - float fiso = parent->imgsrc->getMetaData()->getISOSpeed () ; // ISO - float fspeed = parent->imgsrc->getMetaData()->getShutterSpeed () ; // Speed - double fcomp = parent->imgsrc->getMetaData()->getExpComp (); // Compensation +/- + float fnum = parent->imgsrc->getMetaData()->getFNumber(); // F number + float fiso = parent->imgsrc->getMetaData()->getISOSpeed() ; // ISO + float fspeed = parent->imgsrc->getMetaData()->getShutterSpeed() ; // Speed + double fcomp = parent->imgsrc->getMetaData()->getExpComp(); // Compensation +/- double adap; // Scene's luminosity adaptation factor if (fnum < 0.3f || fiso < 5.f || fspeed < 0.00001f) { //if no exif data or wrong adap = 2000.; } else { - double E_V = fcomp + log2 (double ((fnum * fnum) / fspeed / (fiso / 100.f))); + double E_V = fcomp + log2(double ((fnum * fnum) / fspeed / (fiso / 100.f))); E_V += params.toneCurve.expcomp;// exposure compensation in tonecurve ==> direct EV - E_V += log2 (params.raw.expos); // exposure raw white point ; log2 ==> linear to EV - adap = pow (2., E_V - 3.); // cd / m2 + E_V += log2(params.raw.expos); // exposure raw white point ; log2 ==> linear to EV + adap = pow(2., E_V - 3.); // cd / m2 // end calculation adaptation scene luminosity } @@ -1023,12 +1080,12 @@ void Crop::update (int todo) } if (!cieCrop) { - cieCrop = new CieImage (cropw, croph); + cieCrop = new CieImage(cropw, croph); } 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); + 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 { // CIECAM is disabled, we free up its image buffer to save some space if (cieCrop) { @@ -1043,13 +1100,13 @@ void Crop::update (int todo) PipetteBuffer::setReady(); // Computing the preview image, i.e. converting from lab->Monitor color space (soft-proofing disabled) or lab->Output profile->Monitor color space (soft-proofing enabled) - parent->ipf.lab2monitorRgb (labnCrop, cropImg); + parent->ipf.lab2monitorRgb(labnCrop, cropImg); if (cropImageListener) { // Computing the internal image for analysis, i.e. conversion from lab->Output profile (rtSettings.HistogramWorking disabled) or lab->WCS (rtSettings.HistogramWorking enabled) // internal image in output color space for analysis - Image8 *cropImgtrue = parent->ipf.lab2rgb (labnCrop, 0, 0, cropw, croph, params.icm); + Image8 *cropImgtrue = parent->ipf.lab2rgb(labnCrop, 0, 0, cropw, croph, params.icm); int finalW = rqcropw; @@ -1063,30 +1120,30 @@ void Crop::update (int todo) finalH = cropImg->getHeight() - upperBorder; } - Image8* final = new Image8 (finalW, finalH); - Image8* finaltrue = new Image8 (finalW, finalH); + Image8* final = new Image8(finalW, finalH); + Image8* finaltrue = new Image8(finalW, finalH); for (int i = 0; i < finalH; i++) { - memcpy (final->data + 3 * i * finalW, cropImg->data + 3 * (i + upperBorder)*cropw + 3 * leftBorder, 3 * finalW); - memcpy (finaltrue->data + 3 * i * finalW, cropImgtrue->data + 3 * (i + upperBorder)*cropw + 3 * leftBorder, 3 * finalW); + memcpy(final->data + 3 * i * finalW, cropImg->data + 3 * (i + upperBorder)*cropw + 3 * leftBorder, 3 * finalW); + memcpy(finaltrue->data + 3 * i * finalW, cropImgtrue->data + 3 * (i + upperBorder)*cropw + 3 * leftBorder, 3 * finalW); } - cropImageListener->setDetailedCrop (final, finaltrue, params.icm, params.crop, rqcropx, rqcropy, rqcropw, rqcroph, skip); + cropImageListener->setDetailedCrop(final, finaltrue, params.icm, params.crop, rqcropx, rqcropy, rqcropw, rqcroph, skip); delete final; delete finaltrue; delete cropImgtrue; } } -void Crop::freeAll () +void Crop::freeAll() { if (settings->verbose) { - printf ("freeallcrop starts %d\n", (int)cropAllocated); + printf("freeallcrop starts %d\n", (int)cropAllocated); } if (cropAllocated) { - if (origCrop ) { + if (origCrop) { delete origCrop; origCrop = nullptr; } @@ -1096,22 +1153,22 @@ void Crop::freeAll () transCrop = nullptr; } - if (laboCrop ) { + if (laboCrop) { delete laboCrop; laboCrop = nullptr; } - if (labnCrop ) { + if (labnCrop) { delete labnCrop; labnCrop = nullptr; } - if (cropImg ) { + if (cropImg) { delete cropImg; cropImg = nullptr; } - if (cieCrop ) { + if (cieCrop) { delete cieCrop; cieCrop = nullptr; } @@ -1121,12 +1178,12 @@ void Crop::freeAll () cbuf_real = nullptr; } - if (cbuffer ) { + if (cbuffer) { delete [] cbuffer; cbuffer = nullptr; } - if (cshmap ) { + if (cshmap) { delete cshmap; cshmap = nullptr; } @@ -1141,7 +1198,7 @@ void Crop::freeAll () namespace { -bool check_need_larger_crop_for_lcp_distortion (int fw, int fh, int x, int y, int w, int h, const ProcParams ¶ms) +bool check_need_larger_crop_for_lcp_distortion(int fw, int fh, int x, int y, int w, int h, const ProcParams ¶ms) { if (x == 0 && y == 0 && w == fw && h == fh) { return false; @@ -1156,15 +1213,15 @@ bool check_need_larger_crop_for_lcp_distortion (int fw, int fh, int x, int y, in * If the scale changes, this method will free all buffers and reallocate ones of the new size. * It will then tell to the SizeListener that size has changed (sizeChanged) */ -bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool internal) +bool Crop::setCropSizes(int rcx, int rcy, int rcw, int rch, int skip, bool internal) { if (settings->verbose) { - printf ("setcropsizes before lock\n"); + printf("setcropsizes before lock\n"); } if (!internal) { - cropMutex.lock (); + cropMutex.lock(); } bool changed = false; @@ -1175,12 +1232,12 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte rqcroph = rch; // store and set requested crop size - int rqx1 = LIM (rqcropx, 0, parent->fullw - 1); - int rqy1 = LIM (rqcropy, 0, parent->fullh - 1); + int rqx1 = LIM(rqcropx, 0, parent->fullw - 1); + int rqy1 = LIM(rqcropy, 0, parent->fullh - 1); int rqx2 = rqx1 + rqcropw - 1; int rqy2 = rqy1 + rqcroph - 1; - rqx2 = LIM (rqx2, 0, parent->fullw - 1); - rqy2 = LIM (rqy2, 0, parent->fullh - 1); + rqx2 = LIM(rqx2, 0, parent->fullw - 1); + rqy2 = LIM(rqy2, 0, parent->fullh - 1); this->skip = skip; @@ -1190,10 +1247,10 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte int bx2 = rqx2 + skip * borderRequested; int by2 = rqy2 + skip * borderRequested; // clip it to fit into image area - bx1 = LIM (bx1, 0, parent->fullw - 1); - by1 = LIM (by1, 0, parent->fullh - 1); - bx2 = LIM (bx2, 0, parent->fullw - 1); - by2 = LIM (by2, 0, parent->fullh - 1); + bx1 = LIM(bx1, 0, parent->fullw - 1); + by1 = LIM(by1, 0, parent->fullh - 1); + bx2 = LIM(bx2, 0, parent->fullw - 1); + by2 = LIM(by2, 0, parent->fullh - 1); int bw = bx2 - bx1 + 1; int bh = by2 - by1 + 1; @@ -1206,9 +1263,9 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte ProcParams& params = parent->params; - parent->ipf.transCoord (parent->fw, parent->fh, bx1, by1, bw, bh, orx, ory, orw, orh); + parent->ipf.transCoord(parent->fw, parent->fh, bx1, by1, bw, bh, orx, ory, orw, orh); - if (check_need_larger_crop_for_lcp_distortion (parent->fw, parent->fh, orx, ory, orw, orh, parent->params)) { + if (check_need_larger_crop_for_lcp_distortion(parent->fw, parent->fh, orx, ory, orw, orh, parent->params)) { // TODO - this is an estimate of the max distortion relative to the image size. ATM it is hardcoded to be 15%, which seems enough. If not, need to revise int dW = int (double (parent->fw) * 0.15 / (2 * skip)); int dH = int (double (parent->fh) * 0.15 / (2 * skip)); @@ -1237,34 +1294,34 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte y2 = parent->fh; } - orx = max (x1, 0); - ory = max (y1, 0); - orw = min (x2 - x1, parent->fw - orx); - orh = min (y2 - y1, parent->fh - ory); + orx = max(x1, 0); + ory = max(y1, 0); + orw = min(x2 - x1, parent->fw - orx); + orh = min(y2 - y1, parent->fh - ory); } - leftBorder = skips (rqx1 - bx1, skip); - upperBorder = skips (rqy1 - by1, skip); + leftBorder = skips(rqx1 - bx1, skip); + upperBorder = skips(rqy1 - by1, skip); - PreviewProps cp (orx, ory, orw, orh, skip); + PreviewProps cp(orx, ory, orw, orh, skip); int orW, orH; - parent->imgsrc->getSize (cp, orW, orH); + parent->imgsrc->getSize(cp, orW, orH); trafx = orx; trafy = ory; - int cw = skips (bw, skip); - int ch = skips (bh, skip); + int cw = skips(bw, skip); + int ch = skips(bh, skip); if (settings->verbose) { - printf ("setsizes starts (%d, %d, %d, %d, %d, %d)\n", orW, orH, trafw, trafh, cw, ch); + printf("setsizes starts (%d, %d, %d, %d, %d, %d)\n", orW, orH, trafw, trafh, cw, ch); } EditType editType = ET_PIPETTE; - if (const auto editProvider = PipetteBuffer::getDataProvider ()) { - if (const auto editSubscriber = editProvider->getCurrSubscriber ()) { - editType = editSubscriber->getEditingType (); + if (const auto editProvider = PipetteBuffer::getDataProvider()) { + if (const auto editSubscriber = editProvider->getCurrSubscriber()) { + editType = editSubscriber->getEditingType(); } } @@ -1279,30 +1336,30 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte origCrop = new Imagefloat; } - origCrop->allocate (trafw, trafh); // Resizing the buffer (optimization) + origCrop->allocate(trafw, trafh); // Resizing the buffer (optimization) // if transCrop doesn't exist yet, it'll be created where necessary if (transCrop) { - transCrop->allocate (cropw, croph); + transCrop->allocate(cropw, croph); } if (laboCrop) { delete laboCrop; // laboCrop can't be resized } - laboCrop = new LabImage (cropw, croph); + laboCrop = new LabImage(cropw, croph); if (labnCrop) { delete labnCrop; // labnCrop can't be resized } - labnCrop = new LabImage (cropw, croph); + labnCrop = new LabImage(cropw, croph); if (!cropImg) { cropImg = new Image8; } - cropImg->allocate (cropw, croph); // Resizing the buffer (optimization) + cropImg->allocate(cropw, croph); // Resizing the buffer (optimization) //cieCrop is only used in Crop::update, it is destroyed now but will be allocated on first use if (cieCrop) { @@ -1310,7 +1367,7 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte cieCrop = nullptr; } - if (cbuffer ) { + if (cbuffer) { delete [] cbuffer; } @@ -1318,24 +1375,24 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte delete [] cbuf_real; } - if (cshmap ) { + if (cshmap) { delete cshmap; cshmap = nullptr; } cbuffer = new float*[croph]; - cbuf_real = new float[ (croph + 2)*cropw]; + cbuf_real = new float[(croph + 2)*cropw]; for (int i = 0; i < croph; i++) { cbuffer[i] = cbuf_real + cropw * i + cropw; } if (params.sh.enabled) { - cshmap = new SHMap (cropw, croph, true); + cshmap = new SHMap(cropw, croph, true); } if (editType == ET_PIPETTE) { - PipetteBuffer::resize (cropw, croph); + PipetteBuffer::resize(cropw, croph); } else if (PipetteBuffer::bufferCreated()) { PipetteBuffer::flush(); } @@ -1349,11 +1406,11 @@ bool Crop::setCropSizes (int rcx, int rcy, int rcw, int rch, int skip, bool inte cropy = by1; if (settings->verbose) { - printf ("setsizes ends\n"); + printf("setsizes ends\n"); } if (!internal) { - cropMutex.unlock (); + cropMutex.unlock(); } return changed; @@ -1388,20 +1445,20 @@ bool Crop::tryUpdate() * * This method is called when the visible part of the crop has changed (resize, zoom, etc..), so it needs a full update */ -void Crop::fullUpdate () +void Crop::fullUpdate() { - parent->updaterThreadStart.lock (); + parent->updaterThreadStart.lock(); if (parent->updaterRunning && parent->thread) { // Do NOT reset changes here, since in a long chain of events it will lead to chroma_scale not being updated, // causing Color::lab2rgb to return a black image on some opens //parent->changeSinceLast = 0; - parent->thread->join (); + parent->thread->join(); } if (parent->plistener) { - parent->plistener->setProgressState (true); + parent->plistener->setProgressState(true); } // If there are more update request, the following WHILE will collect it @@ -1409,33 +1466,33 @@ void Crop::fullUpdate () while (newUpdatePending) { newUpdatePending = false; - update (ALL); + update(ALL); } updating = false; // end of crop update if (parent->plistener) { - parent->plistener->setProgressState (false); + parent->plistener->setProgressState(false); } - parent->updaterThreadStart.unlock (); + parent->updaterThreadStart.unlock(); } int Crop::get_skip() { - MyMutex::MyLock lock (cropMutex); + MyMutex::MyLock lock(cropMutex); return skip; } int Crop::getLeftBorder() { - MyMutex::MyLock lock (cropMutex); + MyMutex::MyLock lock(cropMutex); return leftBorder; } int Crop::getUpperBorder() { - MyMutex::MyLock lock (cropMutex); + MyMutex::MyLock lock(cropMutex); return upperBorder; } diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index 8ffa6cc35..3744fce4c 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -1404,7 +1404,7 @@ cmsHPROFILE rtengine::ICCStore::createGammaProfile(const procparams::ColorManage p[2] = icm.pgrex; p[3] = icm.pgrey; p[4] = icm.pblux; - p[5] = icm.pbluy; + p[5] = icm.pbluy; } else { p[0] = 0.7347; //default primaries p[1] = 0.2653; @@ -1463,15 +1463,17 @@ cmsHPROFILE rtengine::ICCStore::createGammaProfile(const procparams::ColorManage } else { cmsWhitePointFromTemp(&xyD, (double)temp); } - - if (icm.wtemp == "INC") xyD = {0.447573, 0.407440, 1.0}; + + if (icm.wtemp == "INC") xyD = {0.447573, 0.407440, 1.0}; // cmsWhitePointFromTemp(&xyD, (double)temp); GammaTRC[0] = GammaTRC[1] = GammaTRC[2] = cmsBuildParametricToneCurve(nullptr, 5, Parameters); //5 = smoother than 4 + cmsHPROFILE oprofdef = cmsCreateRGBProfile(&xyD, &Primaries, GammaTRC); //oprofdef become Outputprofile cmsFreeToneCurve(GammaTRC[0]); + //lcmsMutex->unlock(); return oprofdef; @@ -1533,9 +1535,9 @@ cmsHPROFILE rtengine::ICCStore::createCustomGammaOutputProfile(const procparams: outPr = "RT_acesp1"; } else if (icm.wprimari == "pfree") { outProfile = options.rtSettings.srgb; - printf("PFRRE\n"); + printf("PFRRE\n"); outPr = "RT_pfree"; - + } else { // Should not occurs if (settings->verbose) { @@ -1590,7 +1592,9 @@ cmsHPROFILE rtengine::ICCStore::createCustomGammaOutputProfile(const procparams: } else if (icm.gamma == "Lab_g3.0s9.03296") { gammaStr = "_LAB_g3.0_s9.03296"; } - outTemp = outPr; + + outTemp = outPr; + if (icm.wprofile == "v4" && icm.wtemp != "DEF") { if (icm.wtemp == "D41") { outPr = outPr + "D41"; @@ -1607,7 +1611,8 @@ cmsHPROFILE rtengine::ICCStore::createCustomGammaOutputProfile(const procparams: } else if (icm.wtemp == "INC") { outPr = outPr + "INC"; } - // printf("outpr=%s \n",outPr.c_str()); + + // printf("outpr=%s \n",outPr.c_str()); } @@ -1638,9 +1643,10 @@ cmsHPROFILE rtengine::ICCStore::createCustomGammaOutputProfile(const procparams: } else if (icm.wprofile == "v2" || icm.wprofile == "none") { outPro = outPr + "_V2_" + gammaStr + ".icc"; } + gammaWs << outTemp << gammaStr; - // gammaWs << outPro.c_str() ; + // gammaWs << outPro.c_str() ; // cmsMLUsetWide(mlu, "en", "US", gammaWs.str().c_str()); @@ -1770,7 +1776,7 @@ cmsHPROFILE rtengine::ICCStore::createCustomGammaOutputProfile(const procparams: p[3] = icm.pgrey; p[4] = icm.pblux; p[5] = icm.pbluy; - + } else { p[0] = 0.7347; //default primaries p[1] = 0.2653; @@ -1804,7 +1810,8 @@ cmsHPROFILE rtengine::ICCStore::createCustomGammaOutputProfile(const procparams: } else if (icm.wtemp == "INC") { tempv4 = 5003.; } - //printf("tempv4=%f \n", tempv4); + + //printf("tempv4=%f \n", tempv4); } @@ -1813,7 +1820,8 @@ cmsHPROFILE rtengine::ICCStore::createCustomGammaOutputProfile(const procparams: } else { cmsWhitePointFromTemp(&xyD, (double)temp); } - if (icm.wtemp == "INC") xyD = {0.447573, 0.407440, 1.0}; + + if (icm.wtemp == "INC") xyD = {0.447573, 0.407440, 1.0}; cmsToneCurve* GammaTRC[3]; diff --git a/rtengine/image16.cc b/rtengine/image16.cc index c545497e3..05219583d 100644 --- a/rtengine/image16.cc +++ b/rtengine/image16.cc @@ -25,7 +25,7 @@ namespace { -void getScanline8 (const uint16_t *red, const uint16_t *green, const uint16_t *blue, int width, unsigned char* buffer) +void getScanline8(const uint16_t *red, const uint16_t *green, const uint16_t *blue, int width, unsigned char* buffer) { for (int i = 0, ix = 0; i < width; i++) { buffer[ix++] = rtengine::uint16ToUint8Rounded(red[i]); @@ -34,7 +34,7 @@ void getScanline8 (const uint16_t *red, const uint16_t *green, const uint16_t *b } } -void getScanline16 (const uint16_t *red, const uint16_t *green, const uint16_t *blue, int width, unsigned short* buffer) +void getScanline16(const uint16_t *red, const uint16_t *green, const uint16_t *blue, int width, unsigned short* buffer) { for (int i = 0, ix = 0; i < width; i++) { buffer[ix++] = red[i]; @@ -47,20 +47,20 @@ void getScanline16 (const uint16_t *red, const uint16_t *green, const uint16_t * using namespace rtengine; -Image16::Image16 () +Image16::Image16() { } -Image16::Image16 (int w, int h) +Image16::Image16(int w, int h) { - allocate (w, h); + allocate(w, h); } -Image16::~Image16 () +Image16::~Image16() { } -void Image16::getScanline (int row, unsigned char* buffer, int bps) +void Image16::getScanline(int row, unsigned char* buffer, int bps) { if (data == nullptr) { @@ -68,9 +68,9 @@ void Image16::getScanline (int row, unsigned char* buffer, int bps) } if (bps == 16) { - getScanline16 (r(row), g(row), b(row), width, (unsigned short*)buffer); + getScanline16(r(row), g(row), b(row), width, (unsigned short*)buffer); } else if (bps == 8) { - getScanline8 (r(row), g(row), b(row), width, buffer); + getScanline8(r(row), g(row), b(row), width, buffer); } } @@ -78,7 +78,7 @@ void Image16::getScanline (int row, unsigned char* buffer, int bps) * void Image16::setScanline (int row, unsigned char* buffer, int bps, int minValue[3], int maxValue[3]); * has not been implemented yet, because as of now, this method is called for IIOSF_FLOAT sample format only */ -void Image16::setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples, float *minValue, float *maxValue) +void Image16::setScanline(int row, unsigned char* buffer, int bps, unsigned int numSamples, float *minValue, float *maxValue) { if (data == nullptr) { @@ -92,7 +92,7 @@ void Image16::setScanline (int row, unsigned char* buffer, int bps, unsigned int case (IIOSF_UNSIGNED_CHAR): { int ix = 0; - if(numSamples == 1) { + if (numSamples == 1) { for (int i = 0; i < width; ++i) { r(row, i) = g(row, i) = b(row, i) = static_cast(buffer[ix++]) * 257; } @@ -103,6 +103,7 @@ void Image16::setScanline (int row, unsigned char* buffer, int bps, unsigned int b(row, i) = static_cast(buffer[ix++]) * 257; } } + break; } @@ -130,22 +131,23 @@ void Image16::setScanline (int row, unsigned char* buffer, int bps, unsigned int */ } -Image16* Image16::copy () +Image16* Image16::copy() { - Image16* cp = new Image16 (width, height); + Image16* cp = new Image16(width, height); copyData(cp); return cp; } -void Image16::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp, bool first, procparams::ToneCurveParams hrp) +void Image16::getStdImage(ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp, bool first, procparams::ToneCurveParams hrp) { // compute channel multipliers float rm = 1.f, gm = 1.f, bm = 1.f; + if (ctemp.getTemp() >= 0) { double drm, dgm, dbm; - ctemp.getMultipliers (drm, dgm, dbm); + ctemp.getMultipliers(drm, dgm, dbm); rm = drm; gm = dgm; bm = dbm; @@ -161,7 +163,7 @@ void Image16::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Preview int sx1, sy1, sx2, sy2; - transform (pp, tran, sx1, sy1, sx2, sy2); + transform(pp, tran, sx1, sy1, sx2, sy2); int imwidth = image->getWidth(); // Destination image int imheight = image->getHeight(); // Destination image @@ -271,25 +273,22 @@ void Image16::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Preview } } - if (mtran == TR_NONE) + if (mtran == TR_NONE) for (int dst_x = 0, src_x = sx1; dst_x < imwidth; dst_x++, src_x += skip) { image->r(iy, dst_x) = lineR[dst_x]; image->g(iy, dst_x) = lineG[dst_x]; image->b(iy, dst_x) = lineB[dst_x]; - } - else if (mtran == TR_R180) + } else if (mtran == TR_R180) for (int dst_x = 0; dst_x < imwidth; dst_x++) { image->r(imheight - 1 - iy, imwidth - 1 - dst_x) = lineR[dst_x]; image->g(imheight - 1 - iy, imwidth - 1 - dst_x) = lineG[dst_x]; image->b(imheight - 1 - iy, imwidth - 1 - dst_x) = lineB[dst_x]; - } - else if (mtran == TR_R90) + } else if (mtran == TR_R90) for (int dst_x = 0, src_x = sx1; dst_x < imwidth; dst_x++, src_x += skip) { image->r(dst_x, imheight - 1 - iy) = lineR[dst_x]; image->g(dst_x, imheight - 1 - iy) = lineG[dst_x]; image->b(dst_x, imheight - 1 - iy) = lineB[dst_x]; - } - else if (mtran == TR_R270) + } else if (mtran == TR_R270) for (int dst_x = 0, src_x = sx1; dst_x < imwidth; dst_x++, src_x += skip) { image->r(imwidth - 1 - dst_x, iy) = lineR[dst_x]; image->g(imwidth - 1 - dst_x, iy) = lineG[dst_x]; @@ -334,6 +333,48 @@ Image16::tofloat() return imgfloat; } +// Parallized transformation; create transform with cmsFLAGS_NOCACHE! +void Image16::ExecCMSTransform(cmsHTRANSFORM hTransform) +{ + //cmsDoTransform(hTransform, data, data, planestride); + + // LittleCMS cannot parallelize planar setups -- Hombre: LCMS2.4 can! But it we use this new feature, memory allocation have to be modified too + // so build temporary buffers to allow multi processor execution +#ifdef _OPENMP + #pragma omp parallel +#endif + { + AlignedBuffer buffer(width * 3); + +#ifdef _OPENMP + #pragma omp for schedule(static) +#endif + + for (int y = 0; y < height; y++) + { + unsigned short *p = buffer.data, *pR = r(y), *pG = g(y), *pB = b(y); + + for (int x = 0; x < width; x++) { + *(p++) = *(pR++); + *(p++) = *(pG++); + *(p++) = *(pB++); + } + + cmsDoTransform(hTransform, buffer.data, buffer.data, width); + + p = buffer.data; + pR = r(y); + pG = g(y); + pB = b(y); + + for (int x = 0; x < width; x++) { + *(pR++) = *(p++); + *(pG++) = *(p++); + *(pB++) = *(p++); + } + } // End of parallelization + } +} // // Parallelized transformation; create transform with cmsFLAGS_NOCACHE! // void Image16::ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage, int cx, int cy) diff --git a/rtengine/image16.h b/rtengine/image16.h index af5642638..add1d6f09 100644 --- a/rtengine/image16.h +++ b/rtengine/image16.h @@ -36,65 +36,66 @@ class Image16 : public IImage16, public ImageIO public: - Image16 (); - Image16 (int width, int height); - ~Image16 (); + Image16(); + Image16(int width, int height); + ~Image16(); - Image16* copy (); + Image16* copy(); Image8* to8(); Imagefloat* tofloat(); - virtual void getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp, bool first, procparams::ToneCurveParams hrp); + virtual void getStdImage(ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp, bool first, procparams::ToneCurveParams hrp); - virtual const char* getType () const + virtual const char* getType() const { return sImage16; } - virtual int getBPS () + virtual int getBPS() { return 8 * sizeof(unsigned short); } - virtual void getScanline (int row, unsigned char* buffer, int bps); - virtual void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples, float *minValue = nullptr, float *maxValue = nullptr); + virtual void getScanline(int row, unsigned char* buffer, int bps); + virtual void setScanline(int row, unsigned char* buffer, int bps, unsigned int numSamples, float *minValue = nullptr, float *maxValue = nullptr); // functions inherited from IImage16: - virtual MyMutex& getMutex () + virtual MyMutex& getMutex() { - return mutex (); + return mutex(); } - virtual cmsHPROFILE getProfile () + virtual cmsHPROFILE getProfile() { - return getEmbeddedProfile (); + return getEmbeddedProfile(); } - virtual int getBitsPerPixel () + virtual int getBitsPerPixel() { return 8 * sizeof(unsigned short); } - virtual int saveToFile (Glib::ustring fname) + virtual int saveToFile(Glib::ustring fname) { - return save (fname); + return save(fname); } - virtual int saveAsPNG (Glib::ustring fname, int bps = -1) + virtual int saveAsPNG(Glib::ustring fname, int bps = -1) { - return savePNG (fname, bps); + return savePNG(fname, bps); } - virtual int saveAsJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3) + virtual int saveAsJPEG(Glib::ustring fname, int quality = 100, int subSamp = 3) { - return saveJPEG (fname, quality, subSamp); + return saveJPEG(fname, quality, subSamp); } - virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool uncompressed = false) + virtual int saveAsTIFF(Glib::ustring fname, int bps = -1, bool uncompressed = false) { - return saveTIFF (fname, bps, uncompressed); + return saveTIFF(fname, bps, uncompressed); } - virtual void setSaveProgressListener (ProgressListener* pl) + virtual void setSaveProgressListener(ProgressListener* pl) { - setProgressListener (pl); + setProgressListener(pl); } - virtual void free () + virtual void free() { delete this; } + void ExecCMSTransform(cmsHTRANSFORM hTransform); /* void ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage, int cx, int cy); */ }; diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index fcfe7a567..6118609cd 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -37,49 +37,49 @@ namespace rtengine extern const Settings* settings; -ImProcCoordinator::ImProcCoordinator () - : orig_prev (nullptr), oprevi (nullptr), oprevl (nullptr), nprevl (nullptr), fattal_11_dcrop_cache(nullptr), previmg (nullptr), workimg (nullptr), - ncie (nullptr), imgsrc (nullptr), shmap (nullptr), lastAwbEqual (0.), lastAwbTempBias (0.0), ipf (¶ms, true), monitorIntent (RI_RELATIVE), - softProof (false), gamutCheck (false), scale (10), highDetailPreprocessComputed (false), highDetailRawComputed (false), - allocated (false), bwAutoR (-9000.f), bwAutoG (-9000.f), bwAutoB (-9000.f), CAMMean (NAN), +ImProcCoordinator::ImProcCoordinator() + : orig_prev(nullptr), oprevi(nullptr), oprevl(nullptr), nprevl(nullptr), fattal_11_dcrop_cache(nullptr), previmg(nullptr), workimg(nullptr), + ncie(nullptr), imgsrc(nullptr), shmap(nullptr), lastAwbEqual(0.), lastAwbTempBias(0.0), ipf(¶ms, true), monitorIntent(RI_RELATIVE), + softProof(false), gamutCheck(false), scale(10), highDetailPreprocessComputed(false), highDetailRawComputed(false), + allocated(false), bwAutoR(-9000.f), bwAutoG(-9000.f), bwAutoB(-9000.f), CAMMean(NAN), - hltonecurve (65536), - shtonecurve (65536), - tonecurve (65536, 0), //,1); - lumacurve (32770, 0), // lumacurve[32768] and lumacurve[32769] will be set to 32768 and 32769 later to allow linear interpolation - chroma_acurve (65536, 0), - chroma_bcurve (65536, 0), - satcurve (65536, 0), - lhskcurve (65536, 0), - clcurve (65536, 0), - conversionBuffer (1, 1), - wavclCurve (65536, 0), - clToningcurve (65536, 0), - cl2Toningcurve (65536, 0), - Noisecurve (65536, 0), - NoiseCCcurve (65536, 0), - vhist16 (65536), vhist16bw (65536), - lhist16CAM (65536), - lhist16CCAM (65536), + hltonecurve(65536), + shtonecurve(65536), + tonecurve(65536, 0), //,1); + lumacurve(32770, 0), // lumacurve[32768] and lumacurve[32769] will be set to 32768 and 32769 later to allow linear interpolation + chroma_acurve(65536, 0), + chroma_bcurve(65536, 0), + satcurve(65536, 0), + lhskcurve(65536, 0), + clcurve(65536, 0), + conversionBuffer(1, 1), + wavclCurve(65536, 0), + clToningcurve(65536, 0), + cl2Toningcurve(65536, 0), + Noisecurve(65536, 0), + NoiseCCcurve(65536, 0), + vhist16(65536), vhist16bw(65536), + lhist16CAM(65536), + lhist16CCAM(65536), lhist16RETI(), - lhist16LClad (65536), - histRed (256), histRedRaw (256), - histGreen (256), histGreenRaw (256), - histBlue (256), histBlueRaw (256), - histLuma (256), - histToneCurve (256), - histToneCurveBW (256), - histLCurve (256), - histCCurve (256), - histLLCurve (256), + lhist16LClad(65536), + histRed(256), histRedRaw(256), + histGreen(256), histGreenRaw(256), + histBlue(256), histBlueRaw(256), + histLuma(256), + histToneCurve(256), + histToneCurveBW(256), + histLCurve(256), + histCCurve(256), + histLLCurve(256), - histLCAM (256), - histCCAM (256), - histClad (256), - bcabhist (256), - histChroma (256), + histLCAM(256), + histCCAM(256), + histClad(256), + bcabhist(256), + histChroma(256), - histLRETI (256), + histLRETI(256), CAMBrightCurveJ(), CAMBrightCurveQ(), @@ -87,35 +87,36 @@ ImProcCoordinator::ImProcCoordinator () gCurve(), bCurve(), ctColorCurve(), - rcurvehist (256), rcurvehistCropped (256), rbeforehist (256), - gcurvehist (256), gcurvehistCropped (256), gbeforehist (256), - bcurvehist (256), bcurvehistCropped (256), bbeforehist (256), - fw (0), fh (0), tr (0), - fullw (1), fullh (1), - pW (-1), pH (-1), - plistener (nullptr), imageListener (nullptr), aeListener (nullptr), acListener (nullptr), abwListener (nullptr), awbListener (nullptr), icmListener (nullptr), frameCountListener (nullptr), imageTypeListener (nullptr), actListener (nullptr), adnListener (nullptr), awavListener (nullptr), dehaListener (nullptr), hListener (nullptr), - resultValid (false), lastOutputProfile ("BADFOOD"), lastOutputIntent (RI__COUNT), lastOutputBPC (false), thread (nullptr), changeSinceLast (0), updaterRunning (false), destroying (false), utili (false), autili (false), - butili (false), ccutili (false), cclutili (false), clcutili (false), opautili (false), wavcontlutili (false), colourToningSatLimit (0.f), colourToningSatLimitOpacity (0.f), highQualityComputed (false) + rcurvehist(256), rcurvehistCropped(256), rbeforehist(256), + gcurvehist(256), gcurvehistCropped(256), gbeforehist(256), + bcurvehist(256), bcurvehistCropped(256), bbeforehist(256), + fw(0), fh(0), tr(0), + fullw(1), fullh(1), + pW(-1), pH(-1), + plistener(nullptr), imageListener(nullptr), aeListener(nullptr), acListener(nullptr), abwListener(nullptr), awbListener(nullptr), icmListener(nullptr), frameCountListener(nullptr), imageTypeListener(nullptr), actListener(nullptr), adnListener(nullptr), awavListener(nullptr), dehaListener(nullptr), hListener(nullptr), + resultValid(false), lastOutputProfile("BADFOOD"), lastOutputIntent(RI__COUNT), lastOutputBPC(false), thread(nullptr), changeSinceLast(0), updaterRunning(false), destroying(false), utili(false), autili(false), + butili(false), ccutili(false), cclutili(false), clcutili(false), opautili(false), wavcontlutili(false), colourToningSatLimit(0.f), colourToningSatLimitOpacity(0.f), highQualityComputed(false) {} -void ImProcCoordinator::assign (ImageSource* imgsrc) +void ImProcCoordinator::assign(ImageSource* imgsrc) { this->imgsrc = imgsrc; } -ImProcCoordinator::~ImProcCoordinator () +ImProcCoordinator::~ImProcCoordinator() { destroying = true; - updaterThreadStart.lock (); + updaterThreadStart.lock(); if (updaterRunning && thread) { - thread->join (); + thread->join(); } mProcessing.lock(); mProcessing.unlock(); - freeAll (); + freeAll(); + if (fattal_11_dcrop_cache) { delete fattal_11_dcrop_cache; fattal_11_dcrop_cache = nullptr; @@ -127,23 +128,23 @@ ImProcCoordinator::~ImProcCoordinator () delete toDel[i]; } - imgsrc->decreaseRef (); - updaterThreadStart.unlock (); + imgsrc->decreaseRef(); + updaterThreadStart.unlock(); } -DetailedCrop* ImProcCoordinator::createCrop (::EditDataProvider *editDataProvider, bool isDetailWindow) +DetailedCrop* ImProcCoordinator::createCrop(::EditDataProvider *editDataProvider, bool isDetailWindow) { - return new Crop (this, editDataProvider, isDetailWindow); + return new Crop(this, editDataProvider, isDetailWindow); } // todo: bitmask containing desired actions, taken from changesSinceLast // cropCall: calling crop, used to prevent self-updates ...doesn't seem to be used -void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) +void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall) { - MyMutex::MyLock processingLock (mProcessing); + MyMutex::MyLock processingLock(mProcessing); int numofphases = 14; int readyphase = 0; @@ -164,7 +165,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) // Check if any detail crops need high detail. If not, take a fast path short cut if (!highDetailNeeded) { for (size_t i = 0; i < crops.size(); i++) - if (crops[i]->get_skip() == 1 ) { // skip=1 -> full resolution + if (crops[i]->get_skip() == 1) { // skip=1 -> full resolution highDetailNeeded = true; break; } @@ -174,7 +175,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) ColorManagementParams cmp = params.icm; LCurveParams lcur = params.labCurve; - if ( !highDetailNeeded ) { + if (!highDetailNeeded) { // if below 100% magnification, take a fast path if (rp.bayersensor.method != RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::NONE) && rp.bayersensor.method != RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::NONE)) { rp.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST); @@ -191,18 +192,18 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) //rp.deadPixelFilter = rp.hotPixelFilter = false; } - progress ("Applying white balance, color correction & sRGB conversion...", 100 * readyphase / numofphases); + progress("Applying white balance, color correction & sRGB conversion...", 100 * readyphase / numofphases); if (frameCountListener) { - frameCountListener->FrameCountChanged (imgsrc->getFrameCount(), params.raw.bayersensor.imageNum); + frameCountListener->FrameCountChanged(imgsrc->getFrameCount(), params.raw.bayersensor.imageNum); } // raw auto CA is bypassed if no high detail is needed, so we have to compute it when high detail is needed - if ( (todo & M_PREPROC) || (!highDetailPreprocessComputed && highDetailNeeded)) { - imgsrc->setCurrentFrame (params.raw.bayersensor.imageNum); + if ((todo & M_PREPROC) || (!highDetailPreprocessComputed && highDetailNeeded)) { + imgsrc->setCurrentFrame(params.raw.bayersensor.imageNum); - imgsrc->preprocess ( rp, params.lensProf, params.coarse ); - imgsrc->getRAWHistogram ( histRedRaw, histGreenRaw, histBlueRaw ); + imgsrc->preprocess(rp, params.lensProf, params.coarse); + imgsrc->getRAWHistogram(histRedRaw, histGreenRaw, histBlueRaw); highDetailPreprocessComputed = highDetailNeeded; } @@ -220,23 +221,23 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) // If high detail (=100%) is newly selected, do a demosaic update, since the last was just with FAST if (imageTypeListener) { - imageTypeListener->imageTypeChanged (imgsrc->isRAW(), imgsrc->getSensorType() == ST_BAYER, imgsrc->getSensorType() == ST_FUJI_XTRANS, imgsrc->isMono()); + imageTypeListener->imageTypeChanged(imgsrc->isRAW(), imgsrc->getSensorType() == ST_BAYER, imgsrc->getSensorType() == ST_FUJI_XTRANS, imgsrc->isMono()); } - if ( (todo & M_RAW) + if ((todo & M_RAW) || (!highDetailRawComputed && highDetailNeeded) - || ( params.toneCurve.hrenabled && params.toneCurve.method != "Color" && imgsrc->isRGBSourceModified()) + || (params.toneCurve.hrenabled && params.toneCurve.method != "Color" && imgsrc->isRGBSourceModified()) || (!params.toneCurve.hrenabled && params.toneCurve.method == "Color" && imgsrc->isRGBSourceModified())) { if (settings->verbose) { if (imgsrc->getSensorType() == ST_BAYER) { - printf ("Demosaic Bayer image n.%d using method: %s\n", rp.bayersensor.imageNum + 1, rp.bayersensor.method.c_str()); + printf("Demosaic Bayer image n.%d using method: %s\n", rp.bayersensor.imageNum + 1, rp.bayersensor.method.c_str()); } else if (imgsrc->getSensorType() == ST_FUJI_XTRANS) { - printf ("Demosaic X-Trans image with using method: %s\n", rp.xtranssensor.method.c_str()); + printf("Demosaic X-Trans image with using method: %s\n", rp.xtranssensor.method.c_str()); } } - imgsrc->demosaic ( rp); //enabled demosaic + imgsrc->demosaic(rp); //enabled demosaic // if a demosaic happened we should also call getimage later, so we need to set the M_INIT flag todo |= M_INIT; @@ -247,10 +248,10 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) } if (params.retinex.enabled) { - lhist16RETI (32768); + lhist16RETI(32768); lhist16RETI.clear(); - imgsrc->retinexPrepareBuffers (params.icm, params.retinex, conversionBuffer, lhist16RETI); + imgsrc->retinexPrepareBuffers(params.icm, params.retinex, conversionBuffer, lhist16RETI); } } @@ -258,47 +259,47 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) bool dehacontlutili = false; bool mapcontlutili = false; bool useHsl = false; - LUTf cdcurve (65536, 0); - LUTf mapcurve (65536, 0); + LUTf cdcurve(65536, 0); + LUTf mapcurve(65536, 0); - imgsrc->retinexPrepareCurves (params.retinex, cdcurve, mapcurve, dehatransmissionCurve, dehagaintransmissionCurve, dehacontlutili, mapcontlutili, useHsl, lhist16RETI, histLRETI); + imgsrc->retinexPrepareCurves(params.retinex, cdcurve, mapcurve, dehatransmissionCurve, dehagaintransmissionCurve, dehacontlutili, mapcontlutili, useHsl, lhist16RETI, histLRETI); float minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax; - imgsrc->retinex ( params.icm, params.retinex, params.toneCurve, cdcurve, mapcurve, dehatransmissionCurve, dehagaintransmissionCurve, conversionBuffer, dehacontlutili, mapcontlutili, useHsl, minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax, histLRETI); //enabled Retinex + imgsrc->retinex(params.icm, params.retinex, params.toneCurve, cdcurve, mapcurve, dehatransmissionCurve, dehagaintransmissionCurve, conversionBuffer, dehacontlutili, mapcontlutili, useHsl, minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax, histLRETI); //enabled Retinex if (dehaListener) { - dehaListener->minmaxChanged (maxCD, minCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax); + dehaListener->minmaxChanged(maxCD, minCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax); } } if (todo & (M_INIT | M_LINDENOISE | M_HDR)) { - MyMutex::MyLock initLock (minit); // Also used in crop window + MyMutex::MyLock initLock(minit); // Also used in crop window - imgsrc->HLRecovery_Global ( params.toneCurve); // this handles Color HLRecovery + imgsrc->HLRecovery_Global(params.toneCurve); // this handles Color HLRecovery if (settings->verbose) { - printf ("Applying white balance, color correction & sRBG conversion...\n"); + printf("Applying white balance, color correction & sRBG conversion...\n"); } - currWB = ColorTemp (params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); + currWB = ColorTemp(params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); if (!params.wb.enabled) { currWB = ColorTemp(); } else if (params.wb.method == "Camera") { - currWB = imgsrc->getWB (); + currWB = imgsrc->getWB(); } else if (params.wb.method == "Auto") { if (lastAwbEqual != params.wb.equal || lastAwbTempBias != params.wb.tempBias) { double rm, gm, bm; - imgsrc->getAutoWBMultipliers (rm, gm, bm); + imgsrc->getAutoWBMultipliers(rm, gm, bm); if (rm != -1.) { - autoWB.update (rm, gm, bm, params.wb.equal, params.wb.tempBias); + autoWB.update(rm, gm, bm, params.wb.equal, params.wb.tempBias); lastAwbEqual = params.wb.equal; lastAwbTempBias = params.wb.tempBias; } else { lastAwbEqual = -1.; lastAwbTempBias = 0.0; - autoWB.useDefaults (params.wb.equal); + autoWB.useDefaults(params.wb.equal); } //double rr,gg,bb; @@ -309,49 +310,49 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) } if (params.wb.enabled) { - params.wb.temperature = currWB.getTemp (); - params.wb.green = currWB.getGreen (); + params.wb.temperature = currWB.getTemp(); + params.wb.green = currWB.getGreen(); } if (params.wb.method == "Auto" && awbListener && params.wb.enabled) { - awbListener->WBChanged (params.wb.temperature, params.wb.green); + awbListener->WBChanged(params.wb.temperature, params.wb.green); } - -/* - GammaValues g_a; - double pwr = 1.0 / params.icm.gampos; - double ts = params.icm.slpos; + + /* + GammaValues g_a; + double pwr = 1.0 / params.icm.gampos; + double ts = params.icm.slpos; - int mode = 0; - Color::calcGamma(pwr, ts, mode, g_a); // call to calcGamma with selected gamma and slope - printf("ga[0]=%f ga[1]=%f ga[2]=%f ga[3]=%f ga[4]=%f\n", g_a[0],g_a[1],g_a[2],g_a[3],g_a[4]); - - Glib::ustring datal; - datal = "lutsrgb.txt"; - ofstream fou(datal, ios::out | ios::trunc); - - for(int i=0; i < 212; i++) { - //printf("igamma2=%i\n", (int) 65535.f*Color::igamma2(i/212.0)); - float gam = Color::igamma2(i/211.0); - int lutga = nearbyint(65535.f* gam); - // fou << 65535*(int)Color::igamma2(i/212.0) << endl; - fou << i << " " << lutga << endl; - - } - fou.close(); -*/ - int tr = getCoarseBitMask (params.coarse); + int mode = 0; + Color::calcGamma(pwr, ts, mode, g_a); // call to calcGamma with selected gamma and slope + printf("ga[0]=%f ga[1]=%f ga[2]=%f ga[3]=%f ga[4]=%f\n", g_a[0],g_a[1],g_a[2],g_a[3],g_a[4]); - imgsrc->getFullSize (fw, fh, tr); + Glib::ustring datal; + datal = "lutsrgb.txt"; + ofstream fou(datal, ios::out | ios::trunc); + + for(int i=0; i < 212; i++) { + //printf("igamma2=%i\n", (int) 65535.f*Color::igamma2(i/212.0)); + float gam = Color::igamma2(i/211.0); + int lutga = nearbyint(65535.f* gam); + // fou << 65535*(int)Color::igamma2(i/212.0) << endl; + fou << i << " " << lutga << endl; + + } + fou.close(); + */ + int tr = getCoarseBitMask(params.coarse); + + imgsrc->getFullSize(fw, fh, tr); // Will (re)allocate the preview's buffers - setScale (scale); - PreviewProps pp (0, 0, fw, fh, scale); + setScale(scale); + PreviewProps pp(0, 0, fw, fh, scale); // Tells to the ImProcFunctions' tools what is the preview scale, which may lead to some simplifications - ipf.setScale (scale); + ipf.setScale(scale); - imgsrc->getImage (currWB, tr, orig_prev, pp, params.toneCurve, params.raw); + imgsrc->getImage(currWB, tr, orig_prev, pp, params.toneCurve, params.raw); denoiseInfoStore.valid = false; //ColorTemp::CAT02 (orig_prev, ¶ms) ; // printf("orig_prevW=%d\n scale=%d",orig_prev->width, scale); @@ -396,9 +397,9 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) } } */ - imgsrc->convertColorSpace (orig_prev, params.icm, currWB); + imgsrc->convertColorSpace(orig_prev, params.icm, currWB); - ipf.firstAnalysis (orig_prev, params, vhist16); + ipf.firstAnalysis(orig_prev, params, vhist16); } readyphase++; @@ -408,44 +409,47 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) delete fattal_11_dcrop_cache; fattal_11_dcrop_cache = nullptr; } + ipf.ToneMapFattal02(orig_prev); + if (oprevi != orig_prev) { delete oprevi; } } + oprevi = orig_prev; - progress ("Rotate / Distortion...", 100 * readyphase / numofphases); + progress("Rotate / Distortion...", 100 * readyphase / numofphases); // Remove transformation if unneeded bool needstransform = ipf.needsTransform(); - - if ((needstransform || ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.dirpyrequalizer.cbdlMethod == "bef" && params.dirpyrequalizer.enabled && !params.colorappearance.enabled)) ) { + + if ((needstransform || ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.dirpyrequalizer.cbdlMethod == "bef" && params.dirpyrequalizer.enabled && !params.colorappearance.enabled))) { assert(oprevi); Imagefloat *op = oprevi; - oprevi = new Imagefloat (pW, pH); + oprevi = new Imagefloat(pW, pH); if (needstransform) - ipf.transform (op, oprevi, 0, 0, 0, 0, pW, pH, fw, fh, - imgsrc->getMetaData(), imgsrc->getRotateDegree(), false); + ipf.transform(op, oprevi, 0, 0, 0, 0, pW, pH, fw, fh, + imgsrc->getMetaData(), imgsrc->getRotateDegree(), false); else { - op->copyData (oprevi); + op->copyData(oprevi); } } if ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.dirpyrequalizer.cbdlMethod == "bef" && params.dirpyrequalizer.enabled && !params.colorappearance.enabled) { const int W = oprevi->getWidth(); const int H = oprevi->getHeight(); - LabImage labcbdl (W, H); - ipf.rgb2lab (*oprevi, labcbdl, params.icm.working); - ipf.dirpyrequalizer (&labcbdl, scale); - ipf.lab2rgb (labcbdl, *oprevi, params.icm.working); + LabImage labcbdl(W, H); + ipf.rgb2lab(*oprevi, labcbdl, params.icm.working); + ipf.dirpyrequalizer(&labcbdl, scale); + ipf.lab2rgb(labcbdl, *oprevi, params.icm.working); } readyphase++; - progress ("Preparing shadow/highlight map...", 100 * readyphase / numofphases); + progress("Preparing shadow/highlight map...", 100 * readyphase / numofphases); if ((todo & M_BLURMAP) && params.sh.enabled) { - double radius = sqrt (double (pW * pW + pH * pH)) / 2.0; + double radius = sqrt(double (pW * pW + pH * pH)) / 2.0; double shradius = params.sh.radius; if (!params.sh.hq) { @@ -453,10 +457,10 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) } if (!shmap) { - shmap = new SHMap (pW, pH, true); + shmap = new SHMap(pW, pH, true); } - shmap->update (oprevi, shradius, ipf.lumimul, params.sh.hq, scale); + shmap->update(oprevi, shradius, ipf.lumimul, params.sh.hq, scale); } @@ -467,14 +471,15 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) if (params.toneCurve.autoexp) { LUTu aehist; int aehistcompr; - imgsrc->getAutoExpHistogram (aehist, aehistcompr); - ipf.getAutoExp (aehist, aehistcompr, params.toneCurve.clip, params.toneCurve.expcomp, - params.toneCurve.brightness, params.toneCurve.contrast, params.toneCurve.black, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh); + imgsrc->getAutoExpHistogram(aehist, aehistcompr); + ipf.getAutoExp(aehist, aehistcompr, params.toneCurve.clip, params.toneCurve.expcomp, + params.toneCurve.brightness, params.toneCurve.contrast, params.toneCurve.black, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh); if (aeListener) - aeListener->autoExpChanged (params.toneCurve.expcomp, params.toneCurve.brightness, params.toneCurve.contrast, - params.toneCurve.black, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh, params.toneCurve.hrenabled); + aeListener->autoExpChanged(params.toneCurve.expcomp, params.toneCurve.brightness, params.toneCurve.contrast, + params.toneCurve.black, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh, params.toneCurve.hrenabled); } + if (params.toneCurve.histmatching) { imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve); @@ -495,39 +500,88 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) } } - progress ("Exposure curve & CIELAB conversion...", 100 * readyphase / numofphases); + progress("Exposure curve & CIELAB conversion...", 100 * readyphase / numofphases); + + if (todo & M_INIT) { + if (params.icm.wtrcin == "free") { //exec TRC IN free + Glib::ustring profi; + profi = params.icm.working; + + if (profi == "sRGB" || profi == "Adobe RGB" || profi == "ProPhoto" || profi == "WideGamut" || profi == "BruceRGB" || profi == "Beta RGB" || profi == "BestRGB" || profi == "Rec2020" || profi == "ACESp0" || profi == "ACESp1") { + int cw = oprevi->getWidth(); + int ch = oprevi->getHeight(); + // put gamma TRC to 1 + Image16* readyImg0 = NULL; + + double ga0, ga1, ga2, ga3, ga4, ga5, ga6; + int mul = -5; + double gga = 2.4, ssl = 12.92; + + readyImg0 = ipf.workingtrc(oprevi, cw, ch, mul, params.icm.working, gga, ssl, ga0, ga1, ga2, ga3, ga4, ga5, ga6); + #pragma omp parallel for + + for (int row = 0; row < ch; row++) { + for (int col = 0; col < cw; col++) { + oprevi->r(row, col) = (float)readyImg0->r(row, col); + oprevi->g(row, col) = (float)readyImg0->g(row, col); + oprevi->b(row, col) = (float)readyImg0->b(row, col); + } + } + + delete readyImg0; + //adjust TRC + Image16* readyImg = NULL; + gga = params.icm.gamm, ssl = params.icm.slop; + mul = 5; + readyImg = ipf.workingtrc(oprevi, cw, ch, mul, params.icm.working, gga, ssl, ga0, ga1, ga2, ga3, ga4, ga5, ga6); + #pragma omp parallel for + + for (int row = 0; row < ch; row++) { + for (int col = 0; col < cw; col++) { + oprevi->r(row, col) = (float)readyImg->r(row, col); + oprevi->g(row, col) = (float)readyImg->g(row, col); + oprevi->b(row, col) = (float)readyImg->b(row, col); + } + } + + delete readyImg; + + } + } + } + if ((todo & M_RGBCURVE) || (todo & M_CROP)) { // if (hListener) oprevi->calcCroppedHistogram(params, scale, histCropped); //complexCurve also calculated pre-curves histogram depending on crop - CurveFactory::complexCurve (params.toneCurve.expcomp, params.toneCurve.black / 65535.0, - params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh, - params.toneCurve.shcompr, params.toneCurve.brightness, params.toneCurve.contrast, - params.toneCurve.curve, params.toneCurve.curve2, - vhist16, hltonecurve, shtonecurve, tonecurve, histToneCurve, customToneCurve1, customToneCurve2, 1); + CurveFactory::complexCurve(params.toneCurve.expcomp, params.toneCurve.black / 65535.0, + params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh, + params.toneCurve.shcompr, params.toneCurve.brightness, params.toneCurve.contrast, + params.toneCurve.curve, params.toneCurve.curve2, + vhist16, hltonecurve, shtonecurve, tonecurve, histToneCurve, customToneCurve1, customToneCurve2, 1); - CurveFactory::RGBCurve (params.rgbCurves.rcurve, rCurve, 1); - CurveFactory::RGBCurve (params.rgbCurves.gcurve, gCurve, 1); - CurveFactory::RGBCurve (params.rgbCurves.bcurve, bCurve, 1); + CurveFactory::RGBCurve(params.rgbCurves.rcurve, rCurve, 1); + CurveFactory::RGBCurve(params.rgbCurves.gcurve, gCurve, 1); + CurveFactory::RGBCurve(params.rgbCurves.bcurve, bCurve, 1); opautili = false; if (params.colorToning.enabled) { - TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix (params.icm.working); + TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix(params.icm.working); double wp[3][3] = { {wprof[0][0], wprof[0][1], wprof[0][2]}, {wprof[1][0], wprof[1][1], wprof[1][2]}, {wprof[2][0], wprof[2][1], wprof[2][2]} }; - params.colorToning.getCurves (ctColorCurve, ctOpacityCurve, wp, opautili); - CurveFactory::curveToning (params.colorToning.clcurve, clToningcurve, scale == 1 ? 1 : 16); - CurveFactory::curveToning (params.colorToning.cl2curve, cl2Toningcurve, scale == 1 ? 1 : 16); + params.colorToning.getCurves(ctColorCurve, ctOpacityCurve, wp, opautili); + CurveFactory::curveToning(params.colorToning.clcurve, clToningcurve, scale == 1 ? 1 : 16); + CurveFactory::curveToning(params.colorToning.cl2curve, cl2Toningcurve, scale == 1 ? 1 : 16); } if (params.blackwhite.enabled) { - CurveFactory::curveBW (params.blackwhite.beforeCurve, params.blackwhite.afterCurve, vhist16bw, histToneCurveBW, beforeToneCurveBW, afterToneCurveBW, 1); + CurveFactory::curveBW(params.blackwhite.beforeCurve, params.blackwhite.afterCurve, vhist16bw, histToneCurveBW, beforeToneCurveBW, afterToneCurveBW, 1); } colourToningSatLimit = float (params.colorToning.satProtectionThreshold) / 100.f * 0.7f + 0.3f; @@ -540,7 +594,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) if (params.colorToning.enabled && params.colorToning.autosat && params.colorToning.method != "LabGrid") { //for colortoning evaluation of saturation settings float moyS = 0.f; float eqty = 0.f; - ipf.moyeqt (oprevi, moyS, eqty);//return image : mean saturation and standard dev of saturation + ipf.moyeqt(oprevi, moyS, eqty); //return image : mean saturation and standard dev of saturation //printf("moy=%f ET=%f\n", moyS,eqty); float satp = ((moyS + 1.5f * eqty) - 0.3f) / 0.7f; //1.5 sigma ==> 93% pixels with high saturation -0.3 / 0.7 convert to Hombre scale @@ -564,11 +618,11 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) if (actListener) { //if(params.blackwhite.enabled) {actListener->autoColorTonChanged(0, satTH, satPR);} if (params.blackwhite.enabled && params.colorToning.autosat) { - actListener->autoColorTonChanged (0, satTH, satPR); //hide sliders only if autosat + actListener->autoColorTonChanged(0, satTH, satPR); //hide sliders only if autosat indi = 0; } else { if (params.colorToning.autosat) { - if (params.colorToning.method == "Lab") { + if (params.colorToning.method == "Lab") { indi = 1; } else if (params.colorToning.method == "RGBCurves") { indi = 1; @@ -586,32 +640,32 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) } // if it's just crop we just need the histogram, no image updates - if ( todo & M_RGBCURVE ) { + if (todo & M_RGBCURVE) { //initialize rrm bbm ggm different from zero to avoid black screen in some cases double rrm = 33.; double ggm = 33.; double bbm = 33.; DCPProfile::ApplyState as; - DCPProfile *dcpProf = imgsrc->getDCP (params.icm, as); + DCPProfile *dcpProf = imgsrc->getDCP(params.icm, as); - ipf.rgbProc (oprevi, oprevl, nullptr, hltonecurve, shtonecurve, tonecurve, shmap, params.toneCurve.saturation, - rCurve, gCurve, bCurve, colourToningSatLimit, colourToningSatLimitOpacity, ctColorCurve, ctOpacityCurve, opautili, clToningcurve, cl2Toningcurve, customToneCurve1, customToneCurve2, beforeToneCurveBW, afterToneCurveBW, rrm, ggm, bbm, bwAutoR, bwAutoG, bwAutoB, params.toneCurve.expcomp, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh, dcpProf, as, histToneCurve); + ipf.rgbProc(oprevi, oprevl, nullptr, hltonecurve, shtonecurve, tonecurve, shmap, params.toneCurve.saturation, + rCurve, gCurve, bCurve, colourToningSatLimit, colourToningSatLimitOpacity, ctColorCurve, ctOpacityCurve, opautili, clToningcurve, cl2Toningcurve, customToneCurve1, customToneCurve2, beforeToneCurveBW, afterToneCurveBW, rrm, ggm, bbm, bwAutoR, bwAutoG, bwAutoB, params.toneCurve.expcomp, params.toneCurve.hlcompr, params.toneCurve.hlcomprthresh, dcpProf, as, histToneCurve); if (params.blackwhite.enabled && params.blackwhite.autoc && abwListener) { if (settings->verbose) { - printf ("ImProcCoordinator / Auto B&W coefs: R=%.2f G=%.2f B=%.2f\n", bwAutoR, bwAutoG, bwAutoB); + printf("ImProcCoordinator / Auto B&W coefs: R=%.2f G=%.2f B=%.2f\n", bwAutoR, bwAutoG, bwAutoB); } - abwListener->BWChanged ((float) rrm, (float) ggm, (float) bbm); + abwListener->BWChanged((float) rrm, (float) ggm, (float) bbm); } if (params.colorToning.autosat && actListener) { if (settings->verbose) { - printf ("ImProcCoordinator / Auto CT: indi=%d satH=%d satPR=%d\n", indi, (int)colourToningSatLimit, (int) colourToningSatLimitOpacity); + printf("ImProcCoordinator / Auto CT: indi=%d satH=%d satPR=%d\n", indi, (int)colourToningSatLimit, (int) colourToningSatLimitOpacity); } - actListener->autoColorTonChanged (indi, (int) colourToningSatLimit, (int)colourToningSatLimitOpacity); //change sliders autosat + actListener->autoColorTonChanged(indi, (int) colourToningSatLimit, (int)colourToningSatLimitOpacity); //change sliders autosat } // correct GUI black and white with value @@ -619,20 +673,20 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) // compute L channel histogram int x1, y1, x2, y2; - params.crop.mapToResized (pW, pH, scale, x1, x2, y1, y2); + params.crop.mapToResized(pW, pH, scale, x1, x2, y1, y2); } readyphase++; if (todo & (M_LUMACURVE | M_CROP)) { - LUTu lhist16 (32768); + LUTu lhist16(32768); lhist16.clear(); #ifdef _OPENMP - const int numThreads = min (max (pW * pH / (int)lhist16.getSize(), 1), omp_get_max_threads()); + const int numThreads = min(max(pW * pH / (int)lhist16.getSize(), 1), omp_get_max_threads()); #pragma omp parallel num_threads(numThreads) if(numThreads>1) #endif { - LUTu lhist16thr (lhist16.getSize()); + LUTu lhist16thr(lhist16.getSize()); lhist16thr.clear(); #ifdef _OPENMP #pragma omp for nowait @@ -640,7 +694,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) for (int x = 0; x < pH; x++) for (int y = 0; y < pW; y++) { - int pos = (int) (oprevl->L[x][y]); + int pos = (int)(oprevl->L[x][y]); lhist16thr[pos]++; } @@ -650,31 +704,31 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) lhist16 += lhist16thr; } #ifdef _OPENMP - static_cast (numThreads); // to silence cppcheck warning + static_cast(numThreads); // to silence cppcheck warning #endif - CurveFactory::complexLCurve (params.labCurve.brightness, params.labCurve.contrast, params.labCurve.lcurve, lhist16, lumacurve, histLCurve, scale == 1 ? 1 : 16, utili); + CurveFactory::complexLCurve(params.labCurve.brightness, params.labCurve.contrast, params.labCurve.lcurve, lhist16, lumacurve, histLCurve, scale == 1 ? 1 : 16, utili); } if (todo & M_LUMACURVE) { - CurveFactory::curveCL (clcutili, params.labCurve.clcurve, clcurve, scale == 1 ? 1 : 16); + CurveFactory::curveCL(clcutili, params.labCurve.clcurve, clcurve, scale == 1 ? 1 : 16); - CurveFactory::complexsgnCurve (autili, butili, ccutili, cclutili, params.labCurve.acurve, params.labCurve.bcurve, params.labCurve.cccurve, - params.labCurve.lccurve, chroma_acurve, chroma_bcurve, satcurve, lhskcurve, scale == 1 ? 1 : 16); + CurveFactory::complexsgnCurve(autili, butili, ccutili, cclutili, params.labCurve.acurve, params.labCurve.bcurve, params.labCurve.cccurve, + params.labCurve.lccurve, chroma_acurve, chroma_bcurve, satcurve, lhskcurve, scale == 1 ? 1 : 16); } - if (todo & (M_LUMINANCE + M_COLOR) ) { - nprevl->CopyFrom (oprevl); + if (todo & (M_LUMINANCE + M_COLOR)) { + nprevl->CopyFrom(oprevl); - progress ("Applying Color Boost...", 100 * readyphase / numofphases); + progress("Applying Color Boost...", 100 * readyphase / numofphases); // ipf.MSR(nprevl, nprevl->W, nprevl->H, 1); histCCurve.clear(); histLCurve.clear(); - ipf.chromiLuminanceCurve (nullptr, pW, nprevl, nprevl, chroma_acurve, chroma_bcurve, satcurve, lhskcurve, clcurve, lumacurve, utili, autili, butili, ccutili, cclutili, clcutili, histCCurve, histLCurve); - ipf.vibrance (nprevl); + ipf.chromiLuminanceCurve(nullptr, pW, nprevl, nprevl, chroma_acurve, chroma_bcurve, satcurve, lhskcurve, clcurve, lumacurve, utili, autili, butili, ccutili, cclutili, clcutili, histCCurve, histLCurve); + ipf.vibrance(nprevl); - if ((params.colorappearance.enabled && !params.colorappearance.tonecie) || (!params.colorappearance.enabled)) { - ipf.EPDToneMap (nprevl, 5, scale); + if ((params.colorappearance.enabled && !params.colorappearance.tonecie) || (!params.colorappearance.enabled)) { + ipf.EPDToneMap(nprevl, 5, scale); } // for all treatments Defringe, Sharpening, Contrast detail , Microcontrast they are activated if "CIECAM" function are disabled @@ -721,9 +775,9 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) } */ if (params.dirpyrequalizer.cbdlMethod == "aft") { - if (((params.colorappearance.enabled && !settings->autocielab) || (!params.colorappearance.enabled)) ) { - progress ("Pyramid wavelet...", 100 * readyphase / numofphases); - ipf.dirpyrequalizer (nprevl, scale); + if (((params.colorappearance.enabled && !settings->autocielab) || (!params.colorappearance.enabled))) { + progress("Pyramid wavelet...", 100 * readyphase / numofphases); + ipf.dirpyrequalizer(nprevl, scale); //ipf.Lanczoslab (ip_wavelet(LabImage * lab, LabImage * dst, const procparams::EqualizerParams & eqparams), nprevl, 1.f/scale); readyphase++; } @@ -732,18 +786,18 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) wavcontlutili = false; //CurveFactory::curveWavContL ( wavcontlutili,params.wavelet.lcurve, wavclCurve, LUTu & histogramwavcl, LUTu & outBeforeWavCLurveHistogram,int skip); - CurveFactory::curveWavContL (wavcontlutili, params.wavelet.wavclCurve, wavclCurve, scale == 1 ? 1 : 16); + CurveFactory::curveWavContL(wavcontlutili, params.wavelet.wavclCurve, wavclCurve, scale == 1 ? 1 : 16); if ((params.wavelet.enabled)) { WaveletParams WaveParams = params.wavelet; // WaveParams.getCurves(wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY); - WaveParams.getCurves (wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL); + WaveParams.getCurves(wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL); int kall = 0; - progress ("Wavelet...", 100 * readyphase / numofphases); + progress("Wavelet...", 100 * readyphase / numofphases); // ipf.ip_wavelet(nprevl, nprevl, kall, WaveParams, wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, scale); - ipf.ip_wavelet (nprevl, nprevl, kall, WaveParams, wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL, wavclCurve, scale); + ipf.ip_wavelet(nprevl, nprevl, kall, WaveParams, wavCLVCurve, waOpacityCurveRG, waOpacityCurveBY, waOpacityCurveW, waOpacityCurveWL, wavclCurve, scale); } @@ -752,26 +806,27 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) //L histo and Chroma histo for ciecam // histogram well be for Lab (Lch) values, because very difficult to do with J,Q, M, s, C int x1, y1, x2, y2; - params.crop.mapToResized (pW, pH, scale, x1, x2, y1, y2); + params.crop.mapToResized(pW, pH, scale, x1, x2, y1, y2); lhist16CAM.clear(); lhist16CCAM.clear(); if (!params.colorappearance.datacie) { for (int x = 0; x < pH; x++) for (int y = 0; y < pW; y++) { - int pos = CLIP ((int) (nprevl->L[x][y])); - int posc = CLIP ((int)sqrt (nprevl->a[x][y] * nprevl->a[x][y] + nprevl->b[x][y] * nprevl->b[x][y])); + int pos = CLIP((int)(nprevl->L[x][y])); + int posc = CLIP((int)sqrt(nprevl->a[x][y] * nprevl->a[x][y] + nprevl->b[x][y] * nprevl->b[x][y])); lhist16CAM[pos]++; lhist16CCAM[posc]++; } } - CurveFactory::curveLightBrightColor (params.colorappearance.curve, params.colorappearance.curve2, params.colorappearance.curve3, - lhist16CAM, histLCAM, lhist16CCAM, histCCAM, - customColCurve1, customColCurve2, customColCurve3, 1); + CurveFactory::curveLightBrightColor(params.colorappearance.curve, params.colorappearance.curve2, params.colorappearance.curve3, + lhist16CAM, histLCAM, lhist16CCAM, histCCAM, + customColCurve1, customColCurve2, customColCurve3, 1); const FramesMetaData* metaData = imgsrc->getMetaData(); int imgNum = 0; + if (imgsrc->isRAW()) { if (imgsrc->getSensorType() == ST_BAYER) { imgNum = rtengine::LIM(params.raw.bayersensor.imageNum, 0, metaData->getFrameCount() - 1); @@ -780,19 +835,19 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) } } - float fnum = metaData->getFNumber (imgNum); // F number - float fiso = metaData->getISOSpeed (imgNum) ; // ISO - float fspeed = metaData->getShutterSpeed (imgNum) ; // Speed - double fcomp = metaData->getExpComp (imgNum); // Compensation +/- + float fnum = metaData->getFNumber(imgNum); // F number + float fiso = metaData->getISOSpeed(imgNum) ; // ISO + float fspeed = metaData->getShutterSpeed(imgNum) ; // Speed + double fcomp = metaData->getExpComp(imgNum); // Compensation +/- double adap; if (fnum < 0.3f || fiso < 5.f || fspeed < 0.00001f) { //if no exif data or wrong adap = 2000.; } else { - double E_V = fcomp + log2 (double ((fnum * fnum) / fspeed / (fiso / 100.f))); + double E_V = fcomp + log2(double ((fnum * fnum) / fspeed / (fiso / 100.f))); E_V += params.toneCurve.expcomp;// exposure compensation in tonecurve ==> direct EV - E_V += log2 (params.raw.expos); // exposure raw white point ; log2 ==> linear to EV - adap = powf (2.f, E_V - 3.f); // cd / m2 + E_V += log2(params.raw.expos); // exposure raw white point ; log2 ==> linear to EV + adap = powf(2.f, E_V - 3.f); // cd / m2 // end calculation adaptation scene luminosity } @@ -800,15 +855,15 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) bool execsharp = false; if (!ncie) { - ncie = new CieImage (pW, pH); + ncie = new CieImage(pW, pH); } if (!CAMBrightCurveJ && (params.colorappearance.algo == "JC" || params.colorappearance.algo == "JS" || params.colorappearance.algo == "ALL")) { - CAMBrightCurveJ (32768, 0); + CAMBrightCurveJ(32768, 0); } if (!CAMBrightCurveQ && (params.colorappearance.algo == "QM" || params.colorappearance.algo == "ALL")) { - CAMBrightCurveQ (32768, 0); + CAMBrightCurveQ(32768, 0); } // Issue 2785, only float version of ciecam02 for navigator and pan background @@ -816,18 +871,18 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) CAMBrightCurveJ.dirty = true; CAMBrightCurveQ.dirty = true; - ipf.ciecam_02float (ncie, float (adap), pW, 2, nprevl, ¶ms, customColCurve1, customColCurve2, customColCurve3, histLCAM, histCCAM, CAMBrightCurveJ, CAMBrightCurveQ, CAMMean, 5, scale, execsharp, d, dj, yb, 1); + ipf.ciecam_02float(ncie, float (adap), pW, 2, nprevl, ¶ms, customColCurve1, customColCurve2, customColCurve3, histLCAM, histCCAM, CAMBrightCurveJ, CAMBrightCurveQ, CAMMean, 5, scale, execsharp, d, dj, yb, 1); if ((params.colorappearance.autodegree || params.colorappearance.autodegreeout) && acListener && params.colorappearance.enabled) { - acListener->autoCamChanged (100.* (double)d, 100.* (double)dj); + acListener->autoCamChanged(100.* (double)d, 100.* (double)dj); } if (params.colorappearance.autoadapscen && acListener && params.colorappearance.enabled) { - acListener->adapCamChanged (adap); //real value of adapt scene + acListener->adapCamChanged(adap); //real value of adapt scene } if (params.colorappearance.autoybscen && acListener && params.colorappearance.enabled) { - acListener->ybCamChanged ((int) yb); //real value Yb scene + acListener->ybCamChanged((int) yb); //real value Yb scene } readyphase++; @@ -854,29 +909,29 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) lastOutputProfile = params.icm.output; lastOutputIntent = params.icm.outputIntent; lastOutputBPC = params.icm.outputBPC; - ipf.updateColorProfiles (monitorProfile, monitorIntent, softProof, gamutCheck); + ipf.updateColorProfiles(monitorProfile, monitorIntent, softProof, gamutCheck); } // process crop, if needed for (size_t i = 0; i < crops.size(); i++) - if (crops[i]->hasListener () && cropCall != crops[i] ) { - crops[i]->update (todo); // may call ourselves + if (crops[i]->hasListener() && cropCall != crops[i]) { + crops[i]->update(todo); // may call ourselves } - progress ("Conversion to RGB...", 100 * readyphase / numofphases); + progress("Conversion to RGB...", 100 * readyphase / numofphases); if ((todo != CROP && todo != MINUPDATE) || (todo & M_MONITOR)) { - MyMutex::MyLock prevImgLock (previmg->getMutex()); + MyMutex::MyLock prevImgLock(previmg->getMutex()); try { // Computing the preview image, i.e. converting from WCS->Monitor color space (soft-proofing disabled) or WCS->Printer profile->Monitor color space (soft-proofing enabled) - ipf.lab2monitorRgb (nprevl, previmg); + ipf.lab2monitorRgb(nprevl, previmg); // Computing the internal image for analysis, i.e. conversion from WCS->Output profile delete workimg; - workimg = ipf.lab2rgb (nprevl, 0, 0, pW, pH, params.icm); + workimg = ipf.lab2rgb(nprevl, 0, 0, pW, pH, params.icm); } catch (char * str) { - progress ("Error converting file...", 0); + progress("Error converting file...", 0); return; } } @@ -885,31 +940,31 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) resultValid = true; if (imageListener) { - imageListener->setImage (previmg, scale, params.crop); + imageListener->setImage(previmg, scale, params.crop); } } if (imageListener) // TODO: The WB tool should be advertised too in order to get the AutoWB's temp and green values { - imageListener->imageReady (params.crop); + imageListener->imageReady(params.crop); } readyphase++; if (hListener) { - updateLRGBHistograms (); - hListener->histogramChanged (histRed, histGreen, histBlue, histLuma, histToneCurve, histLCurve, histCCurve, /*histCLurve, histLLCurve,*/ histLCAM, histCCAM, histRedRaw, histGreenRaw, histBlueRaw, histChroma, histLRETI); + updateLRGBHistograms(); + hListener->histogramChanged(histRed, histGreen, histBlue, histLuma, histToneCurve, histLCurve, histCCurve, /*histCLurve, histLLCurve,*/ histLCAM, histCCAM, histRedRaw, histGreenRaw, histBlueRaw, histChroma, histLRETI); } } -void ImProcCoordinator::freeAll () +void ImProcCoordinator::freeAll() { if (settings->verbose) { - printf ("freeall starts %d\n", (int)allocated); + printf("freeall starts %d\n", (int)allocated); } if (allocated) { @@ -932,7 +987,7 @@ void ImProcCoordinator::freeAll () ncie = nullptr; if (imageListener) { - imageListener->delImage (previmg); + imageListener->delImage(previmg); } else { delete previmg; } @@ -956,47 +1011,47 @@ void ImProcCoordinator::freeAll () * * @param prevscale New Preview's scale. */ -void ImProcCoordinator::setScale (int prevscale) +void ImProcCoordinator::setScale(int prevscale) { if (settings->verbose) { - printf ("setscale before lock\n"); + printf("setscale before lock\n"); } - tr = getCoarseBitMask (params.coarse); + tr = getCoarseBitMask(params.coarse); int nW, nH; - imgsrc->getFullSize (fw, fh, tr); + imgsrc->getFullSize(fw, fh, tr); prevscale++; do { prevscale--; - PreviewProps pp (0, 0, fw, fh, prevscale); - imgsrc->getSize (pp, nW, nH); - } while (nH < 400 && prevscale > 1 && (nW * nH < 1000000) ); // sctually hardcoded values, perhaps a better choice is possible + PreviewProps pp(0, 0, fw, fh, prevscale); + imgsrc->getSize(pp, nW, nH); + } while (nH < 400 && prevscale > 1 && (nW * nH < 1000000)); // sctually hardcoded values, perhaps a better choice is possible if (settings->verbose) { - printf ("setscale starts (%d, %d)\n", nW, nH); + printf("setscale starts (%d, %d)\n", nW, nH); } if (nW != pW || nH != pH) { - freeAll (); + freeAll(); pW = nW; pH = nH; - orig_prev = new Imagefloat (pW, pH); + orig_prev = new Imagefloat(pW, pH); oprevi = orig_prev; - oprevl = new LabImage (pW, pH); - nprevl = new LabImage (pW, pH); + oprevl = new LabImage(pW, pH); + nprevl = new LabImage(pW, pH); //ncie is only used in ImProcCoordinator::updatePreviewImage, it will be allocated on first use and deleted if not used anymore - previmg = new Image8 (pW, pH); - workimg = new Image8 (pW, pH); + previmg = new Image8(pW, pH); + workimg = new Image8(pW, pH); if (params.sh.enabled) { - shmap = new SHMap (pW, pH, true); + shmap = new SHMap(pW, pH, true); } allocated = true; @@ -1008,26 +1063,26 @@ void ImProcCoordinator::setScale (int prevscale) fullh = fh; if (settings->verbose) { - printf ("setscale ends\n"); + printf("setscale ends\n"); } if (!sizeListeners.empty()) for (size_t i = 0; i < sizeListeners.size(); i++) { - sizeListeners[i]->sizeChanged (fullw, fullh, fw, fh); + sizeListeners[i]->sizeChanged(fullw, fullh, fw, fh); } if (settings->verbose) { - printf ("setscale ends2\n"); + printf("setscale ends2\n"); } } -void ImProcCoordinator::updateLRGBHistograms () +void ImProcCoordinator::updateLRGBHistograms() { int x1, y1, x2, y2; - params.crop.mapToResized (pW, pH, scale, x1, x2, y1, y2); + params.crop.mapToResized(pW, pH, scale, x1, x2, y1, y2); #pragma omp parallel sections { @@ -1038,7 +1093,7 @@ void ImProcCoordinator::updateLRGBHistograms () for (int i = y1; i < y2; i++) for (int j = x1; j < x2; j++) { - histChroma[ (int) (sqrtf (SQR (nprevl->a[i][j]) + SQR (nprevl->b[i][j])) / 188.f)]++; //188 = 48000/256 + histChroma[(int)(sqrtf(SQR(nprevl->a[i][j]) + SQR(nprevl->b[i][j])) / 188.f)]++; //188 = 48000/256 } } #pragma omp section @@ -1048,7 +1103,7 @@ void ImProcCoordinator::updateLRGBHistograms () for (int i = y1; i < y2; i++) for (int j = x1; j < x2; j++) { - histLuma[ (int) (nprevl->L[i][j] / 128.f)]++; + histLuma[(int)(nprevl->L[i][j] / 128.f)]++; } } #pragma omp section @@ -1076,7 +1131,7 @@ void ImProcCoordinator::updateLRGBHistograms () } -void ImProcCoordinator::progress (Glib::ustring str, int pr) +void ImProcCoordinator::progress(Glib::ustring str, int pr) { /* if (plistener) { @@ -1085,28 +1140,28 @@ void ImProcCoordinator::progress (Glib::ustring str, int pr) }*/ } -bool ImProcCoordinator::getAutoWB (double& temp, double& green, double equal, double tempBias) +bool ImProcCoordinator::getAutoWB(double& temp, double& green, double equal, double tempBias) { if (imgsrc) { if (lastAwbEqual != equal || lastAwbTempBias != tempBias) { // Issue 2500 MyMutex::MyLock lock(minit); // Also used in crop window double rm, gm, bm; - imgsrc->getAutoWBMultipliers (rm, gm, bm); + imgsrc->getAutoWBMultipliers(rm, gm, bm); if (rm != -1) { - autoWB.update (rm, gm, bm, equal, tempBias); + autoWB.update(rm, gm, bm, equal, tempBias); lastAwbEqual = equal; lastAwbTempBias = tempBias; } else { lastAwbEqual = -1.; - autoWB.useDefaults (equal); + autoWB.useDefaults(equal); lastAwbTempBias = 0.0; } } - temp = autoWB.getTemp (); - green = autoWB.getGreen (); + temp = autoWB.getTemp(); + green = autoWB.getGreen(); return true; } else { //temp = autoWB.getTemp(); @@ -1116,64 +1171,64 @@ bool ImProcCoordinator::getAutoWB (double& temp, double& green, double equal, do } } -void ImProcCoordinator::getCamWB (double& temp, double& green) +void ImProcCoordinator::getCamWB(double& temp, double& green) { if (imgsrc) { - temp = imgsrc->getWB().getTemp (); - green = imgsrc->getWB().getGreen (); + temp = imgsrc->getWB().getTemp(); + green = imgsrc->getWB().getGreen(); } } -void ImProcCoordinator::getSpotWB (int x, int y, int rect, double& temp, double& tgreen) +void ImProcCoordinator::getSpotWB(int x, int y, int rect, double& temp, double& tgreen) { ColorTemp ret; { - MyMutex::MyLock lock (mProcessing); + MyMutex::MyLock lock(mProcessing); std::vector points, red, green, blue; for (int i = y - rect; i <= y + rect; i++) for (int j = x - rect; j <= x + rect; j++) { - points.push_back (Coord2D (j, i)); + points.push_back(Coord2D(j, i)); } - ipf.transCoord (fw, fh, points, red, green, blue); + ipf.transCoord(fw, fh, points, red, green, blue); - int tr = getCoarseBitMask (params.coarse); + int tr = getCoarseBitMask(params.coarse); - ret = imgsrc->getSpotWB (red, green, blue, tr, params.wb.equal); - currWB = ColorTemp (params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); + ret = imgsrc->getSpotWB(red, green, blue, tr, params.wb.equal); + currWB = ColorTemp(params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); //double rr,gg,bb; //currWB.getMultipliers(rr,gg,bb); } // end of mutex lockong if (ret.getTemp() > 0) { - temp = ret.getTemp (); - tgreen = ret.getGreen (); + temp = ret.getTemp(); + tgreen = ret.getGreen(); } else { - temp = currWB.getTemp (); - tgreen = currWB.getGreen (); + temp = currWB.getTemp(); + tgreen = currWB.getGreen(); } } -void ImProcCoordinator::getAutoCrop (double ratio, int &x, int &y, int &w, int &h) +void ImProcCoordinator::getAutoCrop(double ratio, int &x, int &y, int &w, int &h) { - MyMutex::MyLock lock (mProcessing); + MyMutex::MyLock lock(mProcessing); LensCorrection *pLCPMap = nullptr; if (params.lensProf.useLcp() && imgsrc->getMetaData()->getFocalLen() > 0) { - const std::shared_ptr pLCPProf = LCPStore::getInstance()->getProfile (params.lensProf.lcpFile); + const std::shared_ptr pLCPProf = LCPStore::getInstance()->getProfile(params.lensProf.lcpFile); - if (pLCPProf) pLCPMap = new LCPMapper (pLCPProf, imgsrc->getMetaData()->getFocalLen(), imgsrc->getMetaData()->getFocalLen35mm(), imgsrc->getMetaData()->getFocusDist(), - 0, false, params.lensProf.useDist, fullw, fullh, params.coarse, imgsrc->getRotateDegree()); + if (pLCPProf) pLCPMap = new LCPMapper(pLCPProf, imgsrc->getMetaData()->getFocalLen(), imgsrc->getMetaData()->getFocalLen35mm(), imgsrc->getMetaData()->getFocusDist(), + 0, false, params.lensProf.useDist, fullw, fullh, params.coarse, imgsrc->getRotateDegree()); } - double fillscale = ipf.getTransformAutoFill (fullw, fullh, pLCPMap); + double fillscale = ipf.getTransformAutoFill(fullw, fullh, pLCPMap); if (ratio > 0) { w = fullw * fillscale; @@ -1192,64 +1247,64 @@ void ImProcCoordinator::getAutoCrop (double ratio, int &x, int &y, int &w, int & y = (fullh - h) / 2; } -void ImProcCoordinator::setMonitorProfile (const Glib::ustring& profile, RenderingIntent intent) +void ImProcCoordinator::setMonitorProfile(const Glib::ustring& profile, RenderingIntent intent) { monitorProfile = profile; monitorIntent = intent; } -void ImProcCoordinator::getMonitorProfile (Glib::ustring& profile, RenderingIntent& intent) const +void ImProcCoordinator::getMonitorProfile(Glib::ustring& profile, RenderingIntent& intent) const { profile = monitorProfile; intent = monitorIntent; } -void ImProcCoordinator::setSoftProofing (bool softProof, bool gamutCheck) +void ImProcCoordinator::setSoftProofing(bool softProof, bool gamutCheck) { this->softProof = softProof; this->gamutCheck = gamutCheck; } -void ImProcCoordinator::getSoftProofing (bool &softProof, bool &gamutCheck) +void ImProcCoordinator::getSoftProofing(bool &softProof, bool &gamutCheck) { softProof = this->softProof; gamutCheck = this->gamutCheck; } -void ImProcCoordinator::saveInputICCReference (const Glib::ustring& fname, bool apply_wb) +void ImProcCoordinator::saveInputICCReference(const Glib::ustring& fname, bool apply_wb) { - MyMutex::MyLock lock (mProcessing); + MyMutex::MyLock lock(mProcessing); int fW, fH; - int tr = getCoarseBitMask (params.coarse); + int tr = getCoarseBitMask(params.coarse); - imgsrc->getFullSize (fW, fH, tr); - PreviewProps pp (0, 0, fW, fH, 1); + imgsrc->getFullSize(fW, fH, tr); + PreviewProps pp(0, 0, fW, fH, 1); ProcParams ppar = params; ppar.toneCurve.hrenabled = false; ppar.icm.input = "(none)"; - Imagefloat* im = new Imagefloat (fW, fH); - imgsrc->preprocess ( ppar.raw, ppar.lensProf, ppar.coarse ); - imgsrc->demosaic (ppar.raw ); - ColorTemp currWB = ColorTemp (params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); + Imagefloat* im = new Imagefloat(fW, fH); + imgsrc->preprocess(ppar.raw, ppar.lensProf, ppar.coarse); + imgsrc->demosaic(ppar.raw); + ColorTemp currWB = ColorTemp(params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); if (params.wb.method == "Camera") { - currWB = imgsrc->getWB (); + currWB = imgsrc->getWB(); } else if (params.wb.method == "Auto") { if (lastAwbEqual != params.wb.equal || lastAwbTempBias != params.wb.tempBias) { double rm, gm, bm; - imgsrc->getAutoWBMultipliers (rm, gm, bm); + imgsrc->getAutoWBMultipliers(rm, gm, bm); if (rm != -1.) { - autoWB.update (rm, gm, bm, params.wb.equal, params.wb.tempBias); + autoWB.update(rm, gm, bm, params.wb.equal, params.wb.tempBias); lastAwbEqual = params.wb.equal; lastAwbTempBias = params.wb.tempBias; } else { lastAwbEqual = -1.; lastAwbTempBias = 0.0; - autoWB.useDefaults (params.wb.equal); + autoWB.useDefaults(params.wb.equal); } } @@ -1260,19 +1315,19 @@ void ImProcCoordinator::saveInputICCReference (const Glib::ustring& fname, bool currWB = ColorTemp(); // = no white balance } - imgsrc->getImage (currWB, tr, im, pp, ppar.toneCurve, ppar.raw); - ImProcFunctions ipf (&ppar, true); + imgsrc->getImage(currWB, tr, im, pp, ppar.toneCurve, ppar.raw); + ImProcFunctions ipf(&ppar, true); if (ipf.needsTransform()) { - Imagefloat* trImg = new Imagefloat (fW, fH); - ipf.transform (im, trImg, 0, 0, 0, 0, fW, fH, fW, fH, - imgsrc->getMetaData(), imgsrc->getRotateDegree(), true); + Imagefloat* trImg = new Imagefloat(fW, fH); + ipf.transform(im, trImg, 0, 0, 0, 0, fW, fH, fW, fH, + imgsrc->getMetaData(), imgsrc->getRotateDegree(), true); delete im; im = trImg; } if (params.crop.enabled) { - Imagefloat *tmpim = new Imagefloat (params.crop.w, params.crop.h); + Imagefloat *tmpim = new Imagefloat(params.crop.w, params.crop.h); int cx = params.crop.x; int cy = params.crop.y; int cw = params.crop.w; @@ -1281,9 +1336,9 @@ void ImProcCoordinator::saveInputICCReference (const Glib::ustring& fname, bool for (int i = cy; i < cy + ch; i++) { for (int j = cx; j < cx + cw; j++) { - tmpim->r (i - cy, j - cx) = im->r (i, j); - tmpim->g (i - cy, j - cx) = im->g (i, j); - tmpim->b (i - cy, j - cx) = im->b (i, j); + tmpim->r(i - cy, j - cx) = im->r(i, j); + tmpim->g(i - cy, j - cx) = im->g(i, j); + tmpim->b(i - cy, j - cx) = im->b(i, j); } } @@ -1296,146 +1351,149 @@ void ImProcCoordinator::saveInputICCReference (const Glib::ustring& fname, bool for (int i = 0; i < im->getHeight(); i++) { for (int j = 0; j < im->getWidth(); j++) { - im->r (i, j) = CLIP (im->r (i, j)); - im->g (i, j) = CLIP (im->g (i, j)); - im->b (i, j) = CLIP (im->b (i, j)); + im->r(i, j) = CLIP(im->r(i, j)); + im->g(i, j) = CLIP(im->g(i, j)); + im->b(i, j) = CLIP(im->b(i, j)); } } int imw, imh; - double tmpScale = ipf.resizeScale (¶ms, fW, fH, imw, imh); + double tmpScale = ipf.resizeScale(¶ms, fW, fH, imw, imh); if (tmpScale != 1.0) { - Imagefloat* tempImage = new Imagefloat (imw, imh); - ipf.resize (im, tempImage, tmpScale); + Imagefloat* tempImage = new Imagefloat(imw, imh); + ipf.resize(im, tempImage, tmpScale); delete im; im = tempImage; } - im->setMetadata (imgsrc->getMetaData()->getRootExifData ()); + im->setMetadata(imgsrc->getMetaData()->getRootExifData()); - im->saveTIFF (fname, 16, true); + im->saveTIFF(fname, 16, true); delete im; if (plistener) { - plistener->setProgressState (false); + plistener->setProgressState(false); } //im->saveJPEG (fname, 85); } -void ImProcCoordinator::stopProcessing () +void ImProcCoordinator::stopProcessing() { - updaterThreadStart.lock (); + updaterThreadStart.lock(); if (updaterRunning && thread) { changeSinceLast = 0; - thread->join (); + thread->join(); } - updaterThreadStart.unlock (); + updaterThreadStart.unlock(); } -void ImProcCoordinator::startProcessing () +void ImProcCoordinator::startProcessing() { #undef THREAD_PRIORITY_NORMAL if (!destroying) { if (!updaterRunning) { - updaterThreadStart.lock (); + updaterThreadStart.lock(); thread = nullptr; updaterRunning = true; - updaterThreadStart.unlock (); + updaterThreadStart.unlock(); //batchThread->yield(); //the running batch should wait other threads to avoid conflict - thread = Glib::Thread::create (sigc::mem_fun (*this, &ImProcCoordinator::process), 0, true, true, Glib::THREAD_PRIORITY_NORMAL); + thread = Glib::Thread::create(sigc::mem_fun(*this, &ImProcCoordinator::process), 0, true, true, Glib::THREAD_PRIORITY_NORMAL); } } } -void ImProcCoordinator::startProcessing (int changeCode) +void ImProcCoordinator::startProcessing(int changeCode) { paramsUpdateMutex.lock(); changeSinceLast |= changeCode; paramsUpdateMutex.unlock(); - startProcessing (); + startProcessing(); } -void ImProcCoordinator::process () +void ImProcCoordinator::process() { if (plistener) { - plistener->setProgressState (true); + plistener->setProgressState(true); } - paramsUpdateMutex.lock (); + paramsUpdateMutex.lock(); while (changeSinceLast) { params = nextParams; int change = changeSinceLast; changeSinceLast = 0; - paramsUpdateMutex.unlock (); + paramsUpdateMutex.unlock(); // M_VOID means no update, and is a bit higher that the rest if (change & (M_VOID - 1)) { - updatePreviewImage (change); + updatePreviewImage(change); } - paramsUpdateMutex.lock (); + paramsUpdateMutex.lock(); } - paramsUpdateMutex.unlock (); + paramsUpdateMutex.unlock(); updaterRunning = false; if (plistener) { - plistener->setProgressState (false); + plistener->setProgressState(false); } } -ProcParams* ImProcCoordinator::beginUpdateParams () +ProcParams* ImProcCoordinator::beginUpdateParams() { - paramsUpdateMutex.lock (); + paramsUpdateMutex.lock(); return &nextParams; } -void ImProcCoordinator::endUpdateParams (ProcEvent change) +void ImProcCoordinator::endUpdateParams(ProcEvent change) { int action = RefreshMapper::getInstance()->getAction(change); endUpdateParams(action); } -void ImProcCoordinator::endUpdateParams (int changeFlags) +void ImProcCoordinator::endUpdateParams(int changeFlags) { changeSinceLast |= changeFlags; - paramsUpdateMutex.unlock (); - startProcessing (); + paramsUpdateMutex.unlock(); + startProcessing(); } -bool ImProcCoordinator::getHighQualComputed() { +bool ImProcCoordinator::getHighQualComputed() +{ // this function may only be called from detail windows - if(!highQualityComputed) { - if(options.prevdemo == PD_Sidecar) { + if (!highQualityComputed) { + if (options.prevdemo == PD_Sidecar) { // we already have high quality preview setHighQualComputed(); } else { for (size_t i = 0; i < crops.size() - 1; ++i) { // -1, because last entry is the freshly created detail window - if (crops[i]->get_skip() == 1 ) { // there is at least one crop with skip == 1 => we already have high quality preview + if (crops[i]->get_skip() == 1) { // there is at least one crop with skip == 1 => we already have high quality preview setHighQualComputed(); break; } } } } + return highQualityComputed; } -void ImProcCoordinator::setHighQualComputed() { +void ImProcCoordinator::setHighQualComputed() +{ highQualityComputed = true; } diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index fbddd491d..881d0d049 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -52,28 +52,28 @@ class ImProcFunctions double scale; bool multiThread; - void calcVignettingParams (int oW, int oH, const VignettingParams& vignetting, double &w2, double &h2, double& maxRadius, double &v, double &b, double &mul); + void calcVignettingParams(int oW, int oH, const VignettingParams& vignetting, double &w2, double &h2, double& maxRadius, double &v, double &b, double &mul); - void transformLuminanceOnly (Imagefloat* original, Imagefloat* transformed, int cx, int cy, int oW, int oH, int fW, int fH); + void transformLuminanceOnly(Imagefloat* original, Imagefloat* transformed, int cx, int cy, int oW, int oH, int fW, int fH); void transformGeneral(bool highQuality, Imagefloat *original, Imagefloat *transformed, int cx, int cy, int sx, int sy, int oW, int oH, int fW, int fH, const LensCorrection *pLCPMap); void transformLCPCAOnly(Imagefloat *original, Imagefloat *transformed, int cx, int cy, const LensCorrection *pLCPMap); - void sharpenHaloCtrl (float** luminance, float** blurmap, float** base, int W, int H, const SharpeningParams &sharpenParam); - void sharpenHaloCtrl (LabImage* lab, float** blurmap, float** base, int W, int H, SharpeningParams &sharpenParam); - void sharpenHaloCtrlcam (CieImage* ncie, float** blurmap, float** base, int W, int H); - void dcdamping (float** aI, float** aO, float damping, int W, int H); + void sharpenHaloCtrl(float** luminance, float** blurmap, float** base, int W, int H, const SharpeningParams &sharpenParam); + void sharpenHaloCtrl(LabImage* lab, float** blurmap, float** base, int W, int H, SharpeningParams &sharpenParam); + void sharpenHaloCtrlcam(CieImage* ncie, float** blurmap, float** base, int W, int H); + void dcdamping(float** aI, float** aO, float damping, int W, int H); - bool needsCA (); - bool needsDistortion (); - bool needsRotation (); - bool needsPerspective (); - bool needsGradient (); - bool needsVignetting (); - bool needsLCP (); + bool needsCA(); + bool needsDistortion(); + bool needsRotation(); + bool needsPerspective(); + bool needsGradient(); + bool needsVignetting(); + bool needsLCP(); bool needsLensfun(); // static cmsUInt8Number* Mempro = NULL; - inline void interpolateTransformCubic (Imagefloat* src, int xs, int ys, double Dx, double Dy, float *r, float *g, float *b, double mul) + inline void interpolateTransformCubic(Imagefloat* src, int xs, int ys, double Dx, double Dy, float *r, float *g, float *b, double mul) { const double A = -0.85; @@ -96,9 +96,9 @@ class ImProcFunctions rd = gd = bd = 0.0; for (int i = xs, ix = 0; i < xs + 4; i++, ix++) { - rd += src->r (k, i) * w[ix]; - gd += src->g (k, i) * w[ix]; - bd += src->b (k, i) * w[ix]; + rd += src->r(k, i) * w[ix]; + gd += src->g(k, i) * w[ix]; + bd += src->b(k, i) * w[ix]; } yr[kx] = rd; @@ -134,7 +134,7 @@ class ImProcFunctions // printf ("r=%g, g=%g\n", *r, *g); } - inline void interpolateTransformChannelsCubic (float** src, int xs, int ys, double Dx, double Dy, float *r, double mul) + inline void interpolateTransformChannelsCubic(float** src, int xs, int ys, double Dx, double Dy, float *r, double mul) { const double A = -0.85; @@ -196,166 +196,170 @@ public: double lumimul[3]; - ImProcFunctions (const ProcParams* iparams, bool imultiThread = true) - : monitorTransform (nullptr), params (iparams), scale (1), multiThread (imultiThread), lumimul{} {} - ~ImProcFunctions (); - bool needsLuminanceOnly() { return !(needsCA() || needsDistortion() || needsRotation() || needsPerspective() || needsLCP() || needsLensfun()) && (needsVignetting() || needsPCVignetting() || needsGradient());} - void setScale (double iscale); + ImProcFunctions(const ProcParams* iparams, bool imultiThread = true) + : monitorTransform(nullptr), params(iparams), scale(1), multiThread(imultiThread), lumimul{} {} + ~ImProcFunctions(); + bool needsLuminanceOnly() + { + return !(needsCA() || needsDistortion() || needsRotation() || needsPerspective() || needsLCP() || needsLensfun()) && (needsVignetting() || needsPCVignetting() || needsGradient()); + } + void setScale(double iscale); - bool needsTransform (); - bool needsPCVignetting (); + bool needsTransform(); + bool needsPCVignetting(); - void firstAnalysis (const Imagefloat* const working, const ProcParams ¶ms, LUTu & vhist16); - void updateColorProfiles (const Glib::ustring& monitorProfile, RenderingIntent monitorIntent, bool softProof, bool gamutCheck); - void rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer *pipetteBuffer, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, - SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit, float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, bool opautili, LUTf & clcurve, LUTf & cl2curve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, - const ToneCurve & customToneCurvebw1, const ToneCurve & customToneCurvebw2, double &rrm, double &ggm, double &bbm, float &autor, float &autog, float &autob, DCPProfile *dcpProf, const DCPProfile::ApplyState &asIn, LUTu &histToneCurve ); - void rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer *pipetteBuffer, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, - SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit, float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, bool opautili, LUTf & clcurve, LUTf & cl2curve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, - const ToneCurve & customToneCurvebw1, const ToneCurve & customToneCurvebw2, double &rrm, double &ggm, double &bbm, float &autor, float &autog, float &autob, - double expcomp, int hlcompr, int hlcomprthresh, DCPProfile *dcpProf, const DCPProfile::ApplyState &asIn, LUTu &histToneCurve); - void labtoning (float r, float g, float b, float &ro, float &go, float &bo, int algm, int metchrom, int twoc, float satLimit, float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, LUTf & clToningcurve, LUTf & cl2Toningcurve, float iplow, float iphigh, double wp[3][3], double wip[3][3] ); - void toning2col (float r, float g, float b, float &ro, float &go, float &bo, float iplow, float iphigh, float rl, float gl, float bl, float rh, float gh, float bh, float SatLow, float SatHigh, float balanS, float balanH, float reducac, int mode, int preser, float strProtect); - void toningsmh (float r, float g, float b, float &ro, float &go, float &bo, float RedLow, float GreenLow, float BlueLow, float RedMed, float GreenMed, float BlueMed, float RedHigh, float GreenHigh, float BlueHigh, float reducac, int mode, float strProtect); - void toningsmh2 (float r, float g, float b, float &ro, float &go, float &bo, float low[3], float satLow, float med[3], float satMed, float high[3], float satHigh, float reducac, int mode, int preser); - void secondeg_begin (float reducac, float vend, float &aam, float &bbm); - void secondeg_end (float reducac, float vinf, float &aa, float &bb, float &cc); + void firstAnalysis(const Imagefloat* const working, const ProcParams ¶ms, LUTu & vhist16); + void updateColorProfiles(const Glib::ustring& monitorProfile, RenderingIntent monitorIntent, bool softProof, bool gamutCheck); + void rgbProc(Imagefloat* working, LabImage* lab, PipetteBuffer *pipetteBuffer, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, + SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit, float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, bool opautili, LUTf & clcurve, LUTf & cl2curve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, + const ToneCurve & customToneCurvebw1, const ToneCurve & customToneCurvebw2, double &rrm, double &ggm, double &bbm, float &autor, float &autog, float &autob, DCPProfile *dcpProf, const DCPProfile::ApplyState &asIn, LUTu &histToneCurve); + void rgbProc(Imagefloat* working, LabImage* lab, PipetteBuffer *pipetteBuffer, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, + SHMap* shmap, int sat, LUTf & rCurve, LUTf & gCurve, LUTf & bCurve, float satLimit, float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, bool opautili, LUTf & clcurve, LUTf & cl2curve, const ToneCurve & customToneCurve1, const ToneCurve & customToneCurve2, + const ToneCurve & customToneCurvebw1, const ToneCurve & customToneCurvebw2, double &rrm, double &ggm, double &bbm, float &autor, float &autog, float &autob, + double expcomp, int hlcompr, int hlcomprthresh, DCPProfile *dcpProf, const DCPProfile::ApplyState &asIn, LUTu &histToneCurve); + void labtoning(float r, float g, float b, float &ro, float &go, float &bo, int algm, int metchrom, int twoc, float satLimit, float satLimitOpacity, const ColorGradientCurve & ctColorCurve, const OpacityCurve & ctOpacityCurve, LUTf & clToningcurve, LUTf & cl2Toningcurve, float iplow, float iphigh, double wp[3][3], double wip[3][3]); + void toning2col(float r, float g, float b, float &ro, float &go, float &bo, float iplow, float iphigh, float rl, float gl, float bl, float rh, float gh, float bh, float SatLow, float SatHigh, float balanS, float balanH, float reducac, int mode, int preser, float strProtect); + void toningsmh(float r, float g, float b, float &ro, float &go, float &bo, float RedLow, float GreenLow, float BlueLow, float RedMed, float GreenMed, float BlueMed, float RedHigh, float GreenHigh, float BlueHigh, float reducac, int mode, float strProtect); + void toningsmh2(float r, float g, float b, float &ro, float &go, float &bo, float low[3], float satLow, float med[3], float satMed, float high[3], float satHigh, float reducac, int mode, int preser); + void secondeg_begin(float reducac, float vend, float &aam, float &bbm); + void secondeg_end(float reducac, float vinf, float &aa, float &bb, float &cc); - void retreavergb (float &r, float &g, float &b); - void moyeqt (Imagefloat* working, float &moyS, float &eqty); + void retreavergb(float &r, float &g, float &b); + void moyeqt(Imagefloat* working, float &moyS, float &eqty); - void luminanceCurve (LabImage* lold, LabImage* lnew, LUTf &curve); - 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 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 luminanceCurve(LabImage* lold, LabImage* lnew, LUTf &curve); + 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 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); - void sharpening (LabImage* lab, float** buffer, SharpeningParams &sharpenParam); - void sharpeningcam (CieImage* ncie, float** buffer); - void transform (Imagefloat* original, Imagefloat* transformed, int cx, int cy, int sx, int sy, int oW, int oH, int fW, int fH, const FramesMetaData *metadata, int rawRotationDeg, bool fullImage); - float resizeScale (const ProcParams* params, int fw, int fh, int &imw, int &imh); - void lab2monitorRgb (LabImage* lab, Image8* image); - void resize (Imagefloat* src, Imagefloat* dst, float dScale); - void Lanczos (const LabImage* src, LabImage* dst, float scale); - void Lanczos (const Imagefloat* src, Imagefloat* dst, float scale); + void sharpening(LabImage* lab, float** buffer, SharpeningParams &sharpenParam); + void sharpeningcam(CieImage* ncie, float** buffer); + void transform(Imagefloat* original, Imagefloat* transformed, int cx, int cy, int sx, int sy, int oW, int oH, int fW, int fH, const FramesMetaData *metadata, int rawRotationDeg, bool fullImage); + float resizeScale(const ProcParams* params, int fw, int fh, int &imw, int &imh); + void lab2monitorRgb(LabImage* lab, Image8* image); + void resize(Imagefloat* src, Imagefloat* dst, float dScale); + void Lanczos(const LabImage* src, LabImage* dst, float scale); + void Lanczos(const Imagefloat* src, Imagefloat* dst, float scale); - void deconvsharpening (float** luminance, float** buffer, int W, int H, const SharpeningParams &sharpenParam); - void MLsharpen (LabImage* lab);// Manuel's clarity / sharpening - void MLmicrocontrast (float** luminance, int W, int H ); //Manuel's microcontrast - void MLmicrocontrast (LabImage* lab ); //Manuel's microcontrast - void MLmicrocontrastcam (CieImage* ncie ); //Manuel's microcontrast + void deconvsharpening(float** luminance, float** buffer, int W, int H, const SharpeningParams &sharpenParam); + void MLsharpen(LabImage* lab); // Manuel's clarity / sharpening + void MLmicrocontrast(float** luminance, int W, int H); //Manuel's microcontrast + void MLmicrocontrast(LabImage* lab); //Manuel's microcontrast + void MLmicrocontrastcam(CieImage* ncie); //Manuel's microcontrast - void impulsedenoise (LabImage* lab);//Emil's impulse denoise - void impulsedenoisecam (CieImage* ncie, float **buffers[3]); - void impulse_nr (LabImage* lab, double thresh); - void impulse_nrcam (CieImage* ncie, double thresh, float **buffers[3]); + void impulsedenoise(LabImage* lab); //Emil's impulse denoise + void impulsedenoisecam(CieImage* ncie, float **buffers[3]); + void impulse_nr(LabImage* lab, double thresh); + void impulse_nrcam(CieImage* ncie, double thresh, float **buffers[3]); - void dirpyrdenoise (LabImage* src);//Emil's pyramid denoise - void dirpyrequalizer (LabImage* lab, int scale);//Emil's wavelet + void dirpyrdenoise(LabImage* src); //Emil's pyramid denoise + void dirpyrequalizer(LabImage* lab, int scale); //Emil's wavelet - void EPDToneMapResid (float * WavCoeffs_L0, unsigned int Iterates, int skip, struct cont_params& cp, int W_L, int H_L, float max0, float min0); - float *CompressDR (float *Source, int W_L, int H_L, float Compression, float DetailBoost, float *Compressed); - void ContrastResid (float * WavCoeffs_L0, struct cont_params &cp, int W_L, int H_L, float max0, float min0); - float *ContrastDR (float *Source, int W_L, int H_L, float *Contrast = nullptr); + void EPDToneMapResid(float * WavCoeffs_L0, unsigned int Iterates, int skip, struct cont_params& cp, int W_L, int H_L, float max0, float min0); + float *CompressDR(float *Source, int W_L, int H_L, float Compression, float DetailBoost, float *Compressed); + void ContrastResid(float * WavCoeffs_L0, struct cont_params &cp, int W_L, int H_L, float max0, float min0); + float *ContrastDR(float *Source, int W_L, int H_L, float *Contrast = nullptr); - void EPDToneMap (LabImage *lab, unsigned int Iterates = 0, int skip = 1); - void EPDToneMapCIE (CieImage *ncie, float a_w, float c_, int Wid, int Hei, float minQ, float maxQ, unsigned int Iterates = 0, int skip = 1); + void EPDToneMap(LabImage *lab, unsigned int Iterates = 0, int skip = 1); + void EPDToneMapCIE(CieImage *ncie, float a_w, float c_, int Wid, int Hei, float minQ, float maxQ, unsigned int Iterates = 0, int skip = 1); // pyramid denoise procparams::DirPyrDenoiseParams dnparams; - void dirpyr (LabImage* data_fine, LabImage* data_coarse, int level, LUTf &rangefn_L, LUTf &rangefn_ab, - int pitch, int scale, const int luma, int chroma ); - void idirpyr (LabImage* data_coarse, LabImage* data_fine, int level, LUTf &rangefn_L, LUTf & nrwt_l, LUTf & nrwt_ab, - int pitch, int scale, const int luma, const int chroma/*, LUTf & Lcurve, LUTf & abcurve*/ ); + void dirpyr(LabImage* data_fine, LabImage* data_coarse, int level, LUTf &rangefn_L, LUTf &rangefn_ab, + int pitch, int scale, const int luma, int chroma); + void idirpyr(LabImage* data_coarse, LabImage* data_fine, int level, LUTf &rangefn_L, LUTf & nrwt_l, LUTf & nrwt_ab, + int pitch, int scale, const int luma, const int chroma/*, LUTf & Lcurve, LUTf & abcurve*/); - void Tile_calc (int tilesize, int overlap, int kall, int imwidth, int imheight, int &numtiles_W, int &numtiles_H, int &tilewidth, int &tileheight, int &tileWskip, int &tileHskip); - void ip_wavelet (LabImage * lab, LabImage * dst, int kall, const procparams::WaveletParams & waparams, const WavCurve & wavCLVCcurve, const WavOpacityCurveRG & waOpacityCurveRG, const WavOpacityCurveBY & waOpacityCurveBY, const WavOpacityCurveW & waOpacityCurveW, const WavOpacityCurveWL & waOpacityCurveWL, LUTf &wavclCurve, int skip); + void Tile_calc(int tilesize, int overlap, int kall, int imwidth, int imheight, int &numtiles_W, int &numtiles_H, int &tilewidth, int &tileheight, int &tileWskip, int &tileHskip); + void ip_wavelet(LabImage * lab, LabImage * dst, int kall, const procparams::WaveletParams & waparams, const WavCurve & wavCLVCcurve, const WavOpacityCurveRG & waOpacityCurveRG, const WavOpacityCurveBY & waOpacityCurveBY, const WavOpacityCurveW & waOpacityCurveW, const WavOpacityCurveWL & waOpacityCurveWL, LUTf &wavclCurve, int skip); - void WaveletcontAllL (LabImage * lab, float **varhue, float **varchrom, wavelet_decomposition &WaveletCoeffs_L, - struct cont_params &cp, int skip, float *mean, float *sigma, float *MaxP, float *MaxN, const WavCurve & wavCLVCcurve, const WavOpacityCurveW & waOpacityCurveW, FlatCurve* ChCurve, bool Chutili); - void WaveletcontAllLfinal (wavelet_decomposition &WaveletCoeffs_L, struct cont_params &cp, float *mean, float *sigma, float *MaxP, const WavOpacityCurveWL & waOpacityCurveWL); - void WaveletcontAllAB (LabImage * lab, float **varhue, float **varchrom, wavelet_decomposition &WaveletCoeffs_a, const WavOpacityCurveW & waOpacityCurveW, - struct cont_params &cp, const bool useChannelA); - void WaveletAandBAllAB (wavelet_decomposition &WaveletCoeffs_a, wavelet_decomposition &WaveletCoeffs_b, - struct cont_params &cp, FlatCurve* hhcurve, bool hhutili); - void ContAllL (float **koeLi, float *maxkoeLi, bool lipschitz, int maxlvl, LabImage * lab, float **varhue, float **varchrom, float ** WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, struct cont_params &cp, - int W_L, int H_L, int skip, float *mean, float *sigma, float *MaxP, float *MaxN, const WavCurve & wavCLVCcurve, const WavOpacityCurveW & waOpacityCurveW, FlatCurve* ChCurve, bool Chutili); - void finalContAllL (float ** WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, struct cont_params &cp, - int W_L, int H_L, float *mean, float *sigma, float *MaxP, const WavOpacityCurveWL & waOpacityCurveWL); - void ContAllAB (LabImage * lab, int maxlvl, float **varhue, float **varchrom, float ** WavCoeffs_a, float * WavCoeffs_a0, int level, int dir, const WavOpacityCurveW & waOpacityCurveW, struct cont_params &cp, - int W_ab, int H_ab, const bool useChannelA); - void Evaluate2 (wavelet_decomposition &WaveletCoeffs_L, - float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN); - void Eval2 (float ** WavCoeffs_L, int level, - int W_L, int H_L, float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN); + void WaveletcontAllL(LabImage * lab, float **varhue, float **varchrom, wavelet_decomposition &WaveletCoeffs_L, + struct cont_params &cp, int skip, float *mean, float *sigma, float *MaxP, float *MaxN, const WavCurve & wavCLVCcurve, const WavOpacityCurveW & waOpacityCurveW, FlatCurve* ChCurve, bool Chutili); + void WaveletcontAllLfinal(wavelet_decomposition &WaveletCoeffs_L, struct cont_params &cp, float *mean, float *sigma, float *MaxP, const WavOpacityCurveWL & waOpacityCurveWL); + void WaveletcontAllAB(LabImage * lab, float **varhue, float **varchrom, wavelet_decomposition &WaveletCoeffs_a, const WavOpacityCurveW & waOpacityCurveW, + struct cont_params &cp, const bool useChannelA); + void WaveletAandBAllAB(wavelet_decomposition &WaveletCoeffs_a, wavelet_decomposition &WaveletCoeffs_b, + struct cont_params &cp, FlatCurve* hhcurve, bool hhutili); + void ContAllL(float **koeLi, float *maxkoeLi, bool lipschitz, int maxlvl, LabImage * lab, float **varhue, float **varchrom, float ** WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, struct cont_params &cp, + int W_L, int H_L, int skip, float *mean, float *sigma, float *MaxP, float *MaxN, const WavCurve & wavCLVCcurve, const WavOpacityCurveW & waOpacityCurveW, FlatCurve* ChCurve, bool Chutili); + void finalContAllL(float ** WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, struct cont_params &cp, + int W_L, int H_L, float *mean, float *sigma, float *MaxP, const WavOpacityCurveWL & waOpacityCurveWL); + void ContAllAB(LabImage * lab, int maxlvl, float **varhue, float **varchrom, float ** WavCoeffs_a, float * WavCoeffs_a0, int level, int dir, const WavOpacityCurveW & waOpacityCurveW, struct cont_params &cp, + int W_ab, int H_ab, const bool useChannelA); + void Evaluate2(wavelet_decomposition &WaveletCoeffs_L, + float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN); + void Eval2(float ** WavCoeffs_L, int level, + int W_L, int H_L, float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN); - void Aver (float * HH_Coeffs, int datalen, float &averagePlus, float &averageNeg, float &max, float &min); - void Sigma (float * HH_Coeffs, int datalen, float averagePlus, float averageNeg, float &sigmaPlus, float &sigmaNeg); - void calckoe (float ** WavCoeffs_LL, const struct cont_params& cp, float ** koeLi, int level, int dir, int W_L, int H_L, float edd, float *maxkoeLi, float **tmC = nullptr); + void Aver(float * HH_Coeffs, int datalen, float &averagePlus, float &averageNeg, float &max, float &min); + void Sigma(float * HH_Coeffs, int datalen, float averagePlus, float averageNeg, float &sigmaPlus, float &sigmaNeg); + void calckoe(float ** WavCoeffs_LL, const struct cont_params& cp, float ** koeLi, int level, int dir, int W_L, int H_L, float edd, float *maxkoeLi, float **tmC = nullptr); - void Median_Denoise ( float **src, float **dst, int width, int height, Median medianType, int iterations, int numThreads, float **buffer = nullptr); - void Median_Denoise ( float **src, float **dst, float upperBound, int width, int height, Median medianType, int iterations, int numThreads, float **buffer = nullptr); - void RGB_denoise (int kall, Imagefloat * src, Imagefloat * dst, Imagefloat * calclum, float * ch_M, float *max_r, float *max_b, bool isRAW, const procparams::DirPyrDenoiseParams & dnparams, const double expcomp, const NoiseCurve & noiseLCurve, const NoiseCurve & noiseCCurve, float &nresi, float &highresi); - void RGB_denoise_infoGamCurve (const procparams::DirPyrDenoiseParams & dnparams, const bool isRAW, LUTf &gamcurve, float &gam, float &gamthresh, float &gamslope); - void RGB_denoise_info (Imagefloat * src, Imagefloat * provicalc, bool isRAW, LUTf &gamcurve, float gam, float gamthresh, float gamslope, const procparams::DirPyrDenoiseParams & dnparams, const double expcomp, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float & maxblueaut, float &minredaut, float & minblueaut, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel, float &skinc, float &nsknc, bool multiThread = false); - void RGBtile_denoise (float * fLblox, int hblproc, float noisevar_Ldetail, float * nbrwt, float * blurbuffer ); //for DCT - void RGBoutput_tile_row (float *bloxrow_L, float ** Ldetail, float ** tilemask_out, int height, int width, int top ); - bool WaveletDenoiseAllL (wavelet_decomposition &WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge); - bool WaveletDenoiseAllAB (wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb); - void WaveletDenoiseAll_info (int levwav, wavelet_decomposition &WaveletCoeffs_a, - wavelet_decomposition &WaveletCoeffs_b, float **noisevarlum, float **noisevarchrom, float **noisevarhue, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &minredaut, float & minblueaut, int schoice, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel, float &skinc, float &nsknc, - float &maxchred, float &maxchblue, float &minchred, float &minchblue, int &nb, float &chau, float &chred, float &chblue, bool denoiseMethodRgb); + void Median_Denoise(float **src, float **dst, int width, int height, Median medianType, int iterations, int numThreads, float **buffer = nullptr); + void Median_Denoise(float **src, float **dst, float upperBound, int width, int height, Median medianType, int iterations, int numThreads, float **buffer = nullptr); + void RGB_denoise(int kall, Imagefloat * src, Imagefloat * dst, Imagefloat * calclum, float * ch_M, float *max_r, float *max_b, bool isRAW, const procparams::DirPyrDenoiseParams & dnparams, const double expcomp, const NoiseCurve & noiseLCurve, const NoiseCurve & noiseCCurve, float &nresi, float &highresi); + void RGB_denoise_infoGamCurve(const procparams::DirPyrDenoiseParams & dnparams, const bool isRAW, LUTf &gamcurve, float &gam, float &gamthresh, float &gamslope); + void RGB_denoise_info(Imagefloat * src, Imagefloat * provicalc, bool isRAW, LUTf &gamcurve, float gam, float gamthresh, float gamslope, const procparams::DirPyrDenoiseParams & dnparams, const double expcomp, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float & maxblueaut, float &minredaut, float & minblueaut, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel, float &skinc, float &nsknc, bool multiThread = false); + void RGBtile_denoise(float * fLblox, int hblproc, float noisevar_Ldetail, float * nbrwt, float * blurbuffer); //for DCT + void RGBoutput_tile_row(float *bloxrow_L, float ** Ldetail, float ** tilemask_out, int height, int width, int top); + bool WaveletDenoiseAllL(wavelet_decomposition &WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge); + bool WaveletDenoiseAllAB(wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb); + void WaveletDenoiseAll_info(int levwav, wavelet_decomposition &WaveletCoeffs_a, + wavelet_decomposition &WaveletCoeffs_b, float **noisevarlum, float **noisevarchrom, float **noisevarhue, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &minredaut, float & minblueaut, int schoice, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel, float &skinc, float &nsknc, + float &maxchred, float &maxchblue, float &minchred, float &minchblue, int &nb, float &chau, float &chred, float &chblue, bool denoiseMethodRgb); - bool WaveletDenoiseAll_BiShrinkL (wavelet_decomposition &WaveletCoeffs_L, float *noisevarlum, float madL[8][3]); - bool WaveletDenoiseAll_BiShrinkAB (wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float noisevar_ab, - const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb); - void ShrinkAllL (wavelet_decomposition &WaveletCoeffs_L, float **buffer, int level, int dir, float *noisevarlum, float * madL, float * vari, int edge); - void ShrinkAllAB (wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_ab, float **buffer, int level, int dir, - float *noisevarchrom, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, float * madL, float * madaab = nullptr, bool madCalculated = false); - void ShrinkAll_info (float ** WavCoeffs_a, float ** WavCoeffs_b, - int W_ab, int H_ab, float **noisevarlum, float **noisevarchrom, float **noisevarhue, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &minredaut, float &minblueaut, int schoice, int lvl, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel, float &skinc, float &nsknc, - float &maxchred, float &maxchblue, float &minchred, float &minchblue, int &nb, float &chau, float &chred, float &chblue, bool denoiseMethodRgb); - void Noise_residualAB (wavelet_decomposition &WaveletCoeffs_ab, float &chresid, float &chmaxresid, bool denoiseMethodRgb); - void calcautodn_info (float &chaut, float &delta, int Nb, int levaut, float maxmax, float lumema, float chromina, int mode, int lissage, float redyel, float skinc, float nsknc); - float MadMax (float * DataList, int &max, int datalen); - float Mad (float * DataList, const int datalen); - float MadRgb (float * DataList, const int datalen); + bool WaveletDenoiseAll_BiShrinkL(wavelet_decomposition &WaveletCoeffs_L, float *noisevarlum, float madL[8][3]); + bool WaveletDenoiseAll_BiShrinkAB(wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float noisevar_ab, + const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb); + void ShrinkAllL(wavelet_decomposition &WaveletCoeffs_L, float **buffer, int level, int dir, float *noisevarlum, float * madL, float * vari, int edge); + void ShrinkAllAB(wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_ab, float **buffer, int level, int dir, + float *noisevarchrom, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, float * madL, float * madaab = nullptr, bool madCalculated = false); + void ShrinkAll_info(float ** WavCoeffs_a, float ** WavCoeffs_b, + int W_ab, int H_ab, float **noisevarlum, float **noisevarchrom, float **noisevarhue, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &minredaut, float &minblueaut, int schoice, int lvl, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel, float &skinc, float &nsknc, + float &maxchred, float &maxchblue, float &minchred, float &minchblue, int &nb, float &chau, float &chred, float &chblue, bool denoiseMethodRgb); + void Noise_residualAB(wavelet_decomposition &WaveletCoeffs_ab, float &chresid, float &chmaxresid, bool denoiseMethodRgb); + void calcautodn_info(float &chaut, float &delta, int Nb, int levaut, float maxmax, float lumema, float chromina, int mode, int lissage, float redyel, float skinc, float nsknc); + float MadMax(float * DataList, int &max, int datalen); + float Mad(float * DataList, const int datalen); + float MadRgb(float * DataList, const int datalen); // pyramid wavelet - void dirpyr_equalizer (float ** src, float ** dst, int srcwidth, int srcheight, float ** l_a, float ** l_b, const double * mult, const double dirpyrThreshold, const double skinprot, float b_l, float t_l, float t_r, int scale);//Emil's directional pyramid wavelet - void dirpyr_equalizercam (CieImage* ncie, float ** src, float ** dst, int srcwidth, int srcheight, float ** h_p, float ** C_p, const double * mult, const double dirpyrThreshold, const double skinprot, bool execdir, float b_l, float t_l, float t_r, int scale);//Emil's directional pyramid wavelet - void dirpyr_channel (float ** data_fine, float ** data_coarse, int width, int height, int level, int scale); - void idirpyr_eq_channel (float ** data_coarse, float ** data_fine, float ** buffer, int width, int height, int level, float multi[6], const double dirpyrThreshold, float ** l_a_h, float ** l_b_c, const double skinprot, float b_l, float t_l, float t_r); - void idirpyr_eq_channelcam (float ** data_coarse, float ** data_fine, float ** buffer, int width, int height, int level, float multi[6], const double dirpyrThreshold, float ** l_a_h, float ** l_b_c, const double skinprot, float b_l, float t_l, float t_r); - void defringe (LabImage* lab); - void defringecam (CieImage* ncie); - void badpixcam (CieImage* ncie, double rad, int thr, int mode, float chrom, bool hotbad); - void badpixlab (LabImage* lab, double rad, int thr, float chrom); + void dirpyr_equalizer(float ** src, float ** dst, int srcwidth, int srcheight, float ** l_a, float ** l_b, const double * mult, const double dirpyrThreshold, const double skinprot, float b_l, float t_l, float t_r, int scale); //Emil's directional pyramid wavelet + void dirpyr_equalizercam(CieImage* ncie, float ** src, float ** dst, int srcwidth, int srcheight, float ** h_p, float ** C_p, const double * mult, const double dirpyrThreshold, const double skinprot, bool execdir, float b_l, float t_l, float t_r, int scale); //Emil's directional pyramid wavelet + void dirpyr_channel(float ** data_fine, float ** data_coarse, int width, int height, int level, int scale); + void idirpyr_eq_channel(float ** data_coarse, float ** data_fine, float ** buffer, int width, int height, int level, float multi[6], const double dirpyrThreshold, float ** l_a_h, float ** l_b_c, const double skinprot, float b_l, float t_l, float t_r); + void idirpyr_eq_channelcam(float ** data_coarse, float ** data_fine, float ** buffer, int width, int height, int level, float multi[6], const double dirpyrThreshold, float ** l_a_h, float ** l_b_c, const double skinprot, float b_l, float t_l, float t_r); + void defringe(LabImage* lab); + void defringecam(CieImage* ncie); + void badpixcam(CieImage* ncie, double rad, int thr, int mode, float chrom, bool hotbad); + void badpixlab(LabImage* lab, double rad, int thr, float chrom); - void PF_correct_RT (LabImage * lab, double radius, int thresh); - void PF_correct_RTcam (CieImage * ncie, double radius, int thresh); - void Badpixelscam (CieImage * ncie, double radius, int thresh, int mode, float chrom, bool hotbad); - void BadpixelsLab (LabImage * lab, double radius, int thresh, float chrom); + void PF_correct_RT(LabImage * lab, double radius, int thresh); + void PF_correct_RTcam(CieImage * ncie, double radius, int thresh); + void Badpixelscam(CieImage * ncie, double radius, int thresh, int mode, float chrom, bool hotbad); + void BadpixelsLab(LabImage * lab, double radius, int thresh, float chrom); void ToneMapFattal02(Imagefloat *rgb); void localContrast(LabImage *lab); void colorToningLabGrid(LabImage *lab, int xstart, int xend, int ystart, int yend, bool MultiThread); - - Image8* lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool consider_histogram_settings=true); - Imagefloat* lab2rgbOut (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, GammaValues *ga = nullptr); - // CieImage *ciec; - bool transCoord (int W, int H, int x, int y, int w, int h, int& xv, int& yv, int& wv, int& hv, double ascaleDef = -1, const LensCorrection *pLCPMap = nullptr); - bool transCoord (int W, int H, const std::vector &src, std::vector &red, std::vector &green, std::vector &blue, double ascaleDef = -1, const LensCorrection *pLCPMap = nullptr); - static void getAutoExp (const LUTu & histogram, int histcompr, double clip, double& expcomp, int& bright, int& contr, int& black, int& hlcompr, int& hlcomprthresh); - static double getAutoDistor (const Glib::ustring& fname, int thumb_size); - double getTransformAutoFill (int oW, int oH, const LensCorrection *pLCPMap = nullptr); - void rgb2lab (const Imagefloat &src, LabImage &dst, const Glib::ustring &workingSpace); - void lab2rgb (const LabImage &src, Imagefloat &dst, const Glib::ustring &workingSpace); + Image8* lab2rgb(LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool consider_histogram_settings = true); + Imagefloat* lab2rgbOut(LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, GammaValues *ga = nullptr); + // CieImage *ciec; + Image16* workingtrc(Imagefloat* working, int cw, int ch, int mul, Glib::ustring profi, double gampos, double slpos, double &ga0, double &ga1, double &ga2, double &ga3, double &ga4, double &ga5, double &ga6); + + bool transCoord(int W, int H, int x, int y, int w, int h, int& xv, int& yv, int& wv, int& hv, double ascaleDef = -1, const LensCorrection *pLCPMap = nullptr); + bool transCoord(int W, int H, const std::vector &src, std::vector &red, std::vector &green, std::vector &blue, double ascaleDef = -1, const LensCorrection *pLCPMap = nullptr); + static void getAutoExp(const LUTu & histogram, int histcompr, double clip, double& expcomp, int& bright, int& contr, int& black, int& hlcompr, int& hlcomprthresh); + static double getAutoDistor(const Glib::ustring& fname, int thumb_size); + double getTransformAutoFill(int oW, int oH, const LensCorrection *pLCPMap = nullptr); + void rgb2lab(const Imagefloat &src, LabImage &dst, const Glib::ustring &workingSpace); + void lab2rgb(const LabImage &src, Imagefloat &dst, const Glib::ustring &workingSpace); }; } #endif diff --git a/rtengine/iplab2rgb.cc b/rtengine/iplab2rgb.cc index 0c1e00774..38541829f 100644 --- a/rtengine/iplab2rgb.cc +++ b/rtengine/iplab2rgb.cc @@ -32,14 +32,15 @@ namespace rtengine extern void filmlike_clip(float *r, float *g, float *b); -namespace { +namespace +{ inline void clipLAB(float iL, float ia, float ib, float &oL, float &oa, float &ob, const float scale, const float wp[3][3], const float wip[3][3]) { if (iL < 0.f) { oL = oa = ob = 0.f; } else if (iL > 32768.f || min(ia, ib) < -42000.f || max(ia, ib) > 42000.f) { - + float X, Y, Z; float r, g, b; Color::Lab2XYZ(iL, ia, ib, X, Y, Z); @@ -50,7 +51,7 @@ inline void clipLAB(float iL, float ia, float ib, float &oL, float &oa, float &o oL /= scale; oa /= scale; ob /= scale; - + // oL = 32768.f / scale; // oa = ob = 0.f; } else { @@ -88,7 +89,7 @@ extern const Settings* settings; {static_cast (wiprof[1][0]), static_cast (wiprof[1][1]), static_cast (wiprof[1][2])}, \ {static_cast (wiprof[2][0]), static_cast (wiprof[2][1]), static_cast (wiprof[2][2])} \ } - + // Used in ImProcCoordinator::updatePreviewImage (rtengine/improccoordinator.cc) // Crop::update (rtengine/dcrop.cc) @@ -96,10 +97,10 @@ extern const Settings* settings; // // If monitorTransform, divide by 327.68 then apply monitorTransform (which can integrate soft-proofing) // otherwise divide by 327.68, convert to xyz and apply the sRGB transform, before converting with gamma2curve -void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image) +void ImProcFunctions::lab2monitorRgb(LabImage* lab, Image8* image) { DECLARE_WORKING_MATRICES_(params->icm.working); - + if (monitorTransform) { int W = lab->W; @@ -115,11 +116,12 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image) AlignedBuffer gwBuf1; AlignedBuffer gwBuf2; + if (gamutWarning) { gwBuf1.resize(3 * lab->W); gwBuf2.resize(3 * lab->W); } - + float *buffer = pBuf.data; #ifdef _OPENMP @@ -136,11 +138,11 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image) float* rb = lab->b[i]; for (int j = 0; j < W; j++) { - clipLAB(rL[j], ra[j], rb[j], buffer[iy], buffer[iy+1], buffer[iy+2], 327.68f, wp, wip); + clipLAB(rL[j], ra[j], rb[j], buffer[iy], buffer[iy + 1], buffer[iy + 2], 327.68f, wp, wip); iy += 3; } - cmsDoTransform (monitorTransform, buffer, data + ix, W); + cmsDoTransform(monitorTransform, buffer, data + ix, W); if (gamutWarning) { gamutWarning->markLine(image, i, buffer, gwBuf1.data, gwBuf2.data); @@ -172,7 +174,7 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image) //float L1=rL[j],a1=ra[j],b1=rb[j];//for testing clipLAB(rL[j], ra[j], rb[j], L, a, b, 1.f, wp, wip); - Color::Lab2XYZ(L, a, b, x_, y_, z_ ); + Color::Lab2XYZ(L, a, b, x_, y_, z_); Color::xyz2srgb(x_, y_, z_, R, G, B); @@ -195,10 +197,10 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image) // // If output profile used, divide by 327.68 then apply the "profile" profile (eventually with a standard gamma) // otherwise divide by 327.68, convert to xyz and apply the RGB transform, before converting with gamma2curve -Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool consider_histogram_settings) +Image8* ImProcFunctions::lab2rgb(LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool consider_histogram_settings) { DECLARE_WORKING_MATRICES_(icm.working); - + //gamutmap(lab); if (cx < 0) { @@ -217,23 +219,25 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, ch = lab->H - cy; } - Image8* image = new Image8 (cw, ch); + Image8* image = new Image8(cw, ch); Glib::ustring profile; bool standard_gamma; - if(settings->HistogramWorking && consider_histogram_settings) { + if (settings->HistogramWorking && consider_histogram_settings) { profile = icm.working; standard_gamma = true; } else { profile = icm.output; + if (icm.output.empty() || icm.output == ColorManagementParams::NoICMString) { profile = "sRGB"; } + standard_gamma = false; } - cmsHPROFILE oprof = ICCStore::getInstance()->getProfile (profile); + cmsHPROFILE oprof = ICCStore::getInstance()->getProfile(profile); if (oprof) { cmsHPROFILE oprofG = oprof; @@ -243,14 +247,16 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, } cmsUInt32Number flags = cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE; + if (icm.outputBPC) { flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } - lcmsMutex->lock (); + + lcmsMutex->lock(); cmsHPROFILE LabIProf = cmsCreateLab4Profile(nullptr); - cmsHTRANSFORM hTransform = cmsCreateTransform (LabIProf, TYPE_Lab_DBL, oprofG, TYPE_RGB_8, icm.outputIntent, flags); // NOCACHE is important for thread safety + cmsHTRANSFORM hTransform = cmsCreateTransform(LabIProf, TYPE_Lab_DBL, oprofG, TYPE_RGB_8, icm.outputIntent, flags); // NOCACHE is important for thread safety cmsCloseProfile(LabIProf); - lcmsMutex->unlock (); + lcmsMutex->unlock(); unsigned char *data = image->data; @@ -275,11 +281,11 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, float* rb = lab->b[i]; for (int j = cx; j < cx + cw; j++) { - clipLAB(rL[j], ra[j], rb[j], buffer[iy], buffer[iy+1], buffer[iy+2], 327.68f, wp, wip); + clipLAB(rL[j], ra[j], rb[j], buffer[iy], buffer[iy + 1], buffer[iy + 2], 327.68f, wp, wip); iy += 3; } - cmsDoTransform (hTransform, buffer, data + ix, cw); + cmsDoTransform(hTransform, buffer, data + ix, cw); } } // End of parallelization @@ -290,7 +296,7 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, } } else { - const auto xyz_rgb = ICCStore::getInstance()->workingSpaceInverseMatrix (profile); + const auto xyz_rgb = ICCStore::getInstance()->workingSpaceInverseMatrix(profile); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) if (multiThread) @@ -338,7 +344,7 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, * If a custom gamma profile can be created, divide by 327.68, convert to xyz and apply the custom gamma transform * otherwise divide by 327.68, convert to xyz and apply the sRGB transform, before converting with gamma2curve */ -Imagefloat* ImProcFunctions::lab2rgbOut (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, GammaValues *ga) +Imagefloat* ImProcFunctions::lab2rgbOut(LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, GammaValues *ga) { if (cx < 0) { @@ -357,27 +363,30 @@ Imagefloat* ImProcFunctions::lab2rgbOut (LabImage* lab, int cx, int cy, int cw, ch = lab->H - cy; } - Imagefloat* image = new Imagefloat (cw, ch); + Imagefloat* image = new Imagefloat(cw, ch); cmsHPROFILE oprof = nullptr; + if (ga) { - lcmsMutex->lock (); + lcmsMutex->lock(); ICCStore::getInstance()->getGammaArray(icm, *ga); oprof = ICCStore::getInstance()->createGammaProfile(icm, *ga); - lcmsMutex->unlock (); + lcmsMutex->unlock(); } else { - oprof = ICCStore::getInstance()->getProfile (icm.output); + oprof = ICCStore::getInstance()->getProfile(icm.output); } if (oprof) { cmsUInt32Number flags = cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE; + if (icm.outputBPC) { flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } - lcmsMutex->lock (); + + lcmsMutex->lock(); cmsHPROFILE iprof = cmsCreateLab4Profile(nullptr); - cmsHTRANSFORM hTransform = cmsCreateTransform (iprof, TYPE_Lab_FLT, oprof, TYPE_RGB_FLT, icm.outputIntent, flags); - lcmsMutex->unlock (); + cmsHTRANSFORM hTransform = cmsCreateTransform(iprof, TYPE_Lab_FLT, oprof, TYPE_RGB_FLT, icm.outputIntent, flags); + lcmsMutex->unlock(); image->ExecCMSTransform(hTransform, *lab, cx, cy); cmsDeleteTransform(hTransform); @@ -386,6 +395,7 @@ Imagefloat* ImProcFunctions::lab2rgbOut (LabImage* lab, int cx, int cy, int cw, #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) if (multiThread) #endif + for (int i = cy; i < cy + ch; i++) { float R, G, B; float* rL = lab->L[i]; @@ -416,4 +426,248 @@ Imagefloat* ImProcFunctions::lab2rgbOut (LabImage* lab, int cx, int cy, int cw, return image; } +Image16* ImProcFunctions::workingtrc(Imagefloat* working, int cw, int ch, int mul, Glib::ustring profi, double gampos, double slpos, double &ga0, double &ga1, double &ga2, double &ga3, double &ga4, double &ga5, double &ga6) +{ + TMatrix wprof; + + if (true) { + wprof = ICCStore::getInstance()->workingSpaceMatrix(params->icm.working); + } else { + wprof = ICCStore::getInstance()->workingSpaceMatrix("ProPhoto"); + profi = "ProPhoto"; + } + + double dx = Color::D50x; + double dz = Color::D50z; + { + dx = dz = 1.0; + } + double toxyz[3][3] = { + { + (wprof[0][0] / dx), //I have suppressed / Color::D50x + (wprof[0][1] / dx), + (wprof[0][2] / dx) + }, { + (wprof[1][0]), + (wprof[1][1]), + (wprof[1][2]) + }, { + (wprof[2][0] / dz), //I have suppressed / Color::D50z + (wprof[2][1] / dz), + (wprof[2][2] / dz) + } + }; + + Image16* image = new Image16(cw, ch); + + double pwr; + double ts; + ts = slpos; + + int five = mul; + + ga6 = 0.0; + pwr = 1.0 / gampos; + + if (gampos < 1.0) { + pwr = gampos; + gampos = 1. / gampos; + five = -mul; + // if(ts < 2.) five=-4; + } + + // int select_temp = 1; //5003K + const double eps = 0.000000001; // not divide by zero + + enum class ColorTemp { + D50 = 5003, // for Widegamut, Prophoto Best, Beta -> D50 + D65 = 6504, // for sRGB, AdobeRGB, Bruce Rec2020 -> D65 + D60 = 6005 //for ACESP0 and AcesP1 + + }; + ColorTemp temp = ColorTemp::D50; + + cmsHPROFILE oprofdef; + float p[6]; //primaries + + if (true) { + //primaries for 10 working profiles ==> output profiles + if (profi == "WideGamut") { + p[0] = 0.7350; //Widegamut primaries + p[1] = 0.2650; + p[2] = 0.1150; + p[3] = 0.8260; + p[4] = 0.1570; + p[5] = 0.0180; + } else if (profi == "Adobe RGB") { + p[0] = 0.6400; //Adobe primaries + p[1] = 0.3300; + p[2] = 0.2100; + p[3] = 0.7100; + p[4] = 0.1500; + p[5] = 0.0600; + temp = ColorTemp::D65; + } else if (profi == "sRGB") { + p[0] = 0.6400; // sRGB primaries + p[1] = 0.3300; + p[2] = 0.3000; + p[3] = 0.6000; + p[4] = 0.1500; + p[5] = 0.0600; + temp = ColorTemp::D65; + } else if (profi == "BruceRGB") { + p[0] = 0.6400; // Bruce primaries + p[1] = 0.3300; + p[2] = 0.2800; + p[3] = 0.6500; + p[4] = 0.1500; + p[5] = 0.0600; + temp = ColorTemp::D65; + } else if (profi == "Beta RGB") { + p[0] = 0.6888; // Beta primaries + p[1] = 0.3112; + p[2] = 0.1986; + p[3] = 0.7551; + p[4] = 0.1265; + p[5] = 0.0352; + } else if (profi == "BestRGB") { + p[0] = 0.7347; // Best primaries + p[1] = 0.2653; + p[2] = 0.2150; + p[3] = 0.7750; + p[4] = 0.1300; + p[5] = 0.0350; + } else if (profi == "Rec2020") { + p[0] = 0.7080; // Rec2020 primaries + p[1] = 0.2920; + p[2] = 0.1700; + p[3] = 0.7970; + p[4] = 0.1310; + p[5] = 0.0460; + temp = ColorTemp::D65; + } else if (profi == "ACESp0") { + p[0] = 0.7347; // ACES P0 primaries + p[1] = 0.2653; + p[2] = 0.0000; + p[3] = 1.0; + p[4] = 0.0001; + p[5] = -0.0770; + temp = ColorTemp::D60; + } else if (profi == "ACESp1") { + p[0] = 0.713; // ACES P1 primaries + p[1] = 0.293; + p[2] = 0.165; + p[3] = 0.830; + p[4] = 0.128; + p[5] = 0.044; + temp = ColorTemp::D60; + } else if (profi == "ProPhoto") { + p[0] = 0.7347; //ProPhoto and default primaries + p[1] = 0.2653; + p[2] = 0.1596; + p[3] = 0.8404; + p[4] = 0.0366; + p[5] = 0.0001; + } else { + /* + p[0] = 0.7347; //default primaries + p[1] = 0.2653; + p[2] = 0.1596; + p[3] = 0.8404; + p[4] = 0.0366; + p[5] = 0.0001; + */ + } + + if (slpos == 0) { + slpos = eps; + } + + GammaValues g_a; //gamma parameters + int mode = 0; + Color::calcGamma(pwr, ts, mode, g_a); // call to calcGamma with selected gamma and slope : return parameters for LCMS2 + + ga4 = g_a[3] * ts; + ga0 = gampos; + ga1 = 1. / (1.0 + g_a[4]); + ga2 = g_a[4] / (1.0 + g_a[4]); + ga3 = 1. / slpos; + ga5 = 0.0; + printf("ga0=%f ga1=%f ga2=%f ga3=%f ga4=%f\n", ga0, ga1, ga2, ga3, ga4); + + cmsCIExyY xyD; + + cmsCIExyYTRIPLE Primaries = { + {p[0], p[1], 1.0}, // red + {p[2], p[3], 1.0}, // green + {p[4], p[5], 1.0} // blue + }; + + cmsToneCurve* GammaTRC[3]; + cmsFloat64Number Parameters[7]; + Parameters[0] = ga0; + Parameters[1] = ga1; + Parameters[2] = ga2; + Parameters[3] = ga3; + Parameters[4] = ga4; + Parameters[5] = ga5; + Parameters[6] = ga6; +// 7 parameters for smoother curves + cmsWhitePointFromTemp(&xyD, (double)temp); + GammaTRC[0] = GammaTRC[1] = GammaTRC[2] = cmsBuildParametricToneCurve(NULL, five, Parameters);//5 = more smoother than 4 + oprofdef = cmsCreateRGBProfile(&xyD, &Primaries, GammaTRC); + cmsFreeToneCurve(GammaTRC[0]); + } + + if (oprofdef) { + #pragma omp parallel for if (multiThread) + + for (int i = 0; i < ch; i++) { + float* rr = working->r(i); + float* rg = working->g(i); + float* rb = working->b(i); + + short* xa = (short*)image->r(i); + short* ya = (short*)image->g(i); + short* za = (short*)image->b(i); + + for (int j = 0; j < cw; j++) { + float r1 = rr[j]; + float g1 = rg[j]; + float b1 = rb[j]; + + + float x_ = toxyz[0][0] * r1 + toxyz[0][1] * g1 + toxyz[0][2] * b1; + float y_ = toxyz[1][0] * r1 + toxyz[1][1] * g1 + toxyz[1][2] * b1; + float z_ = toxyz[2][0] * r1 + toxyz[2][1] * g1 + toxyz[2][2] * b1; + + xa[j] = CLIP((int) round(x_)) ; + ya[j] = CLIP((int) round(y_)); + za[j] = CLIP((int) round(z_)); + + } + } + + cmsUInt32Number flags = cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE; + + cmsHPROFILE iprof = ICCStore::getInstance()->getXYZProfile(); + lcmsMutex->lock(); + cmsHTRANSFORM hTransform = cmsCreateTransform(iprof, TYPE_RGB_16, oprofdef, TYPE_RGB_16, params->icm.outputIntent, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE); + + // cmsHTRANSFORM hTransform = cmsCreateTransform(iprof, TYPE_RGB_FLT, oprofdef, TYPE_RGB_FLT, params->icm.outputIntent, flags); + lcmsMutex->unlock(); + + image->ExecCMSTransform(hTransform); + cmsDeleteTransform(hTransform); + + + + } + + + return image; + +} + + } diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index a51ca8ae5..1921895c7 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -1965,11 +1965,15 @@ ColorManagementParams::ColorManagementParams() : pgrey(0.6000), pblux(0.1500), pbluy(0.0600), + gamm(2.4), + slop(12.92), wprimari("sRGB"), wprofile("none"), wtemp("DEF"), - freegamma(false) + freegamma(false), + wtrcin("none") + { } @@ -1995,9 +1999,12 @@ bool ColorManagementParams::operator ==(const ColorManagementParams& other) cons && pgrey == other.pgrey && pblux == other.pblux && pbluy == other.pbluy + && gamm == other.gamm + && slop == other.slop && wprimari == other.wprimari && wprofile == other.wprofile && wtemp == other.wtemp + && wtrcin == other.wtrcin && freegamma == other.freegamma; } @@ -3169,10 +3176,13 @@ int ProcParams::save(const Glib::ustring& fname, const Glib::ustring& fname2, bo saveToKeyfile(!pedited || pedited->icm.pgrey, "Color Management", "GammaPgrey", icm.pgrey, keyFile); saveToKeyfile(!pedited || pedited->icm.pblux, "Color Management", "GammaPblux", icm.pblux, keyFile); saveToKeyfile(!pedited || pedited->icm.pbluy, "Color Management", "GammaPbluy", icm.pbluy, keyFile); + saveToKeyfile(!pedited || pedited->icm.gamm, "Color Management", "GammaValueIn", icm.gamm, keyFile); + saveToKeyfile(!pedited || pedited->icm.slop, "Color Management", "GammaSlopeIn", icm.slop, keyFile); saveToKeyfile(!pedited || pedited->icm.wprimari, "Color Management", "GammaPrimari", icm.wprimari, keyFile); saveToKeyfile(!pedited || pedited->icm.wtemp, "Color Management", "GammaTemp", icm.wtemp, keyFile); saveToKeyfile(!pedited || pedited->icm.wprofile, "Color Management", "GammaProfile", icm.wprofile, keyFile); + saveToKeyfile(!pedited || pedited->icm.wtrcin, "Color Management", "GammaTRCIN", icm.wtrcin, keyFile); // Wavelet saveToKeyfile(!pedited || pedited->wavelet.enabled, "Wavelet", "Enabled", wavelet.enabled, keyFile); @@ -4201,10 +4211,14 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited) assignFromKeyfile(keyFile, "Color Management", "GammaPgrey", pedited, icm.pgrey, pedited->icm.pgrey); assignFromKeyfile(keyFile, "Color Management", "GammaPblux", pedited, icm.pblux, pedited->icm.pblux); assignFromKeyfile(keyFile, "Color Management", "GammaPbluy", pedited, icm.pbluy, pedited->icm.pbluy); + + assignFromKeyfile(keyFile, "Color Management", "GammaValueIn", pedited, icm.gamm, pedited->icm.gamm); + assignFromKeyfile(keyFile, "Color Management", "GammaSlopeIn", pedited, icm.slop, pedited->icm.slop); assignFromKeyfile(keyFile, "Color Management", "GammaPrimari", pedited, icm.wprimari, pedited->icm.wprimari); assignFromKeyfile(keyFile, "Color Management", "GammaProfile", pedited, icm.wprofile, pedited->icm.wprofile); assignFromKeyfile(keyFile, "Color Management", "GammaTemp", pedited, icm.wtemp, pedited->icm.wtemp); + assignFromKeyfile(keyFile, "Color Management", "GammaTRCIN", pedited, icm.wtrcin, pedited->icm.wtrcin); } if (keyFile.has_group("Wavelet")) { diff --git a/rtengine/procparams.h b/rtengine/procparams.h index 2c7580876..089a8505b 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -1027,12 +1027,15 @@ struct ColorManagementParams { double pgrey; double pblux; double pbluy; + double gamm; + double slop; Glib::ustring wprimari; Glib::ustring wprofile; Glib::ustring wtemp; static const Glib::ustring NoICMString; bool freegamma; + Glib::ustring wtrcin; ColorManagementParams(); diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 7b90afc1a..ef2205f67 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -896,6 +896,57 @@ private: shmap->update (baseImg, shradius, ipf.lumimul, params.sh.hq, 1); } + + //gamma TRC working + { + if (params.icm.wtrcin == "free") { //exec TRC IN free + Glib::ustring profi; + profi = params.icm.working; + + if (profi == "sRGB" || profi == "Adobe RGB" || profi == "ProPhoto" || profi == "WideGamut" || profi == "BruceRGB" || profi == "Beta RGB" || profi == "BestRGB" || profi == "Rec2020" || profi == "ACESp0" || profi == "ACESp1") { + int cw = baseImg->getWidth(); + int ch = baseImg->getHeight(); + // put gamma TRC to 1 + Image16* readyImg0 = NULL; + + double ga0, ga1, ga2, ga3, ga4, ga5, ga6; + int mul = -5; + double gga = 2.4, ssl = 12.92; + + readyImg0 = ipf.workingtrc(baseImg, cw, ch, mul, params.icm.working, gga, ssl, ga0, ga1, ga2, ga3, ga4, ga5, ga6); + #pragma omp parallel for + + for (int row = 0; row < ch; row++) { + for (int col = 0; col < cw; col++) { + baseImg->r(row, col) = (float)readyImg0->r(row, col); + baseImg->g(row, col) = (float)readyImg0->g(row, col); + baseImg->b(row, col) = (float)readyImg0->b(row, col); + } + } + + delete readyImg0; + //adjust TRC + Image16* readyImg = NULL; + gga = params.icm.gamm, ssl = params.icm.slop; + mul = 5; + readyImg = ipf.workingtrc(baseImg, cw, ch, mul, params.icm.working, gga, ssl, ga0, ga1, ga2, ga3, ga4, ga5, ga6); + #pragma omp parallel for + + for (int row = 0; row < ch; row++) { + for (int col = 0; col < cw; col++) { + baseImg->r(row, col) = (float)readyImg->r(row, col); + baseImg->g(row, col) = (float)readyImg->g(row, col); + baseImg->b(row, col) = (float)readyImg->b(row, col); + } + } + + delete readyImg; + + } + } + } + + // RGB processing curve1 (65536); diff --git a/rtgui/icmpanel.cc b/rtgui/icmpanel.cc index b53b4fe76..0561de9b4 100644 --- a/rtgui/icmpanel.cc +++ b/rtgui/icmpanel.cc @@ -43,6 +43,9 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha EvICMpgrey = m->newEvent(GAMMA, "HISTORY_MSG_ICMPGREY"); EvICMpblux = m->newEvent(GAMMA, "HISTORY_MSG_ICMPBLUX"); EvICMpbluy = m->newEvent(GAMMA, "HISTORY_MSG_ICMPBLUY"); + EvICMgamm = m->newEvent(ALLNORAW, "HISTORY_MSG_ICMGAMM"); + EvICMslop = m->newEvent(ALLNORAW, "HISTORY_MSG_ICMSLOP"); + EvICMtrcinMethod = m->newEvent(ALLNORAW, "HISTORY_MSG_ICMTRCIN"); isBatchMode = lastToneCurve = lastApplyLookTable = lastApplyBaselineExposureOffset = lastApplyHueSatMap = lastgamfree = false; @@ -180,7 +183,50 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha wnames->set_active(0); + // wFrame->add(*wVBox); + + //-----------------gamma TRC working + + trcinHBox = Gtk::manage(new Gtk::HBox()); + + Gtk::Label* trcinlab = Gtk::manage(new Gtk::Label(M("TP_GAMMA_TRCIN") + ":")); + + trcinHBox->pack_start(*trcinlab, Gtk::PACK_SHRINK); + wtrcin = Gtk::manage(new MyComboBoxText()); + trcinHBox->pack_start(*wtrcin, Gtk::PACK_EXPAND_WIDGET); + wVBox->pack_start(*trcinHBox, Gtk::PACK_EXPAND_WIDGET); + wtrcin->append(M("TP_GAMMA_TRCIN_NONE")); + wtrcin->append(M("TP_GAMMA_TRCIN_FREE")); + + wtrcin->set_active(0); + wtrcin->set_tooltip_text(M("TP_GAMMA_TRCIN_TOOLTIP")); + + + Gtk::VBox * gammaVBox = Gtk::manage(new Gtk::VBox()); + gammaVBox->set_spacing(2); + + gamm = Gtk::manage(new Adjuster(M("TP_GAMMAWORK_GAMMA"), 0.40, 6.0, 0.001, 2.4)); + slop = Gtk::manage(new Adjuster(M("TP_GAMMAWORK_SLOPE"), 0., 40., 0.01, 12.92)); + wVBox->pack_start(*gamm, Gtk::PACK_SHRINK); + gamm->show(); + + wVBox->pack_start(*slop, Gtk::PACK_SHRINK); + slop->show(); + + + gamm->setAdjusterListener(this); + slop->setAdjusterListener(this); + + if (gamm->delay < options.adjusterMaxDelay) { + gamm->delay = options.adjusterMaxDelay; + } + + if (slop->delay < options.adjusterMaxDelay) { + slop->delay = options.adjusterMaxDelay; + } + wFrame->add(*wVBox); + pack_start(*wFrame, Gtk::PACK_EXPAND_WIDGET); @@ -257,8 +303,8 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha //primaries - priHBox = Gtk::manage(new Gtk::HBox()); - + priHBox = Gtk::manage(new Gtk::HBox()); + Gtk::Label* prilab = Gtk::manage(new Gtk::Label(M("TP_GAMMA_PRIM") + ":")); priHBox->pack_start(*prilab, Gtk::PACK_SHRINK); @@ -278,19 +324,19 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha wprimari->append(M("TP_GAMMA_PRIM_FREE")); wprimari->set_active(5); - prifreeVBox = Gtk::manage(new Gtk::VBox()); - Gtk::Image* gamuts0 = Gtk::manage (new RTImage ("rt-logo-tiny.png")); - Gtk::Image* gamutl0 = Gtk::manage (new RTImage ("rt-logo-small.png")); - Gtk::Image* gamuts1 = Gtk::manage (new RTImage ("rt-logo-tiny.png")); - Gtk::Image* gamutl1 = Gtk::manage (new RTImage ("rt-logo-small.png")); - Gtk::Image* gamuts2 = Gtk::manage (new RTImage ("rt-logo-tiny.png")); - Gtk::Image* gamutl2 = Gtk::manage (new RTImage ("rt-logo-small.png")); - Gtk::Image* gamuts3 = Gtk::manage (new RTImage ("rt-logo-tiny.png")); - Gtk::Image* gamutl3 = Gtk::manage (new RTImage ("rt-logo-small.png")); - Gtk::Image* gamuts4 = Gtk::manage (new RTImage ("rt-logo-tiny.png")); - Gtk::Image* gamutl4 = Gtk::manage (new RTImage ("rt-logo-small.png")); - Gtk::Image* gamuts5 = Gtk::manage (new RTImage ("rt-logo-tiny.png")); - Gtk::Image* gamutl5 = Gtk::manage (new RTImage ("rt-logo-small.png")); + prifreeVBox = Gtk::manage(new Gtk::VBox()); + Gtk::Image* gamuts0 = Gtk::manage(new RTImage("rt-logo-tiny.png")); + Gtk::Image* gamutl0 = Gtk::manage(new RTImage("rt-logo-small.png")); + Gtk::Image* gamuts1 = Gtk::manage(new RTImage("rt-logo-tiny.png")); + Gtk::Image* gamutl1 = Gtk::manage(new RTImage("rt-logo-small.png")); + Gtk::Image* gamuts2 = Gtk::manage(new RTImage("rt-logo-tiny.png")); + Gtk::Image* gamutl2 = Gtk::manage(new RTImage("rt-logo-small.png")); + Gtk::Image* gamuts3 = Gtk::manage(new RTImage("rt-logo-tiny.png")); + Gtk::Image* gamutl3 = Gtk::manage(new RTImage("rt-logo-small.png")); + Gtk::Image* gamuts4 = Gtk::manage(new RTImage("rt-logo-tiny.png")); + Gtk::Image* gamutl4 = Gtk::manage(new RTImage("rt-logo-small.png")); + Gtk::Image* gamuts5 = Gtk::manage(new RTImage("rt-logo-tiny.png")); + Gtk::Image* gamutl5 = Gtk::manage(new RTImage("rt-logo-small.png")); predx = Gtk::manage(new Adjuster(M("TP_GAMMA_PRIM_REDX"), 0.6300, 0.7350, 0.0001, 0.6400, gamuts0, gamutl0)); predy = Gtk::manage(new Adjuster(M("TP_GAMMA_PRIM_REDY"), 0.2650, 0.3350, 0.0001, 0.3300, gamutl1, gamuts1)); @@ -307,15 +353,15 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha prifreeVBox->pack_start(*pblux, Gtk::PACK_SHRINK); prifreeVBox->pack_start(*pbluy, Gtk::PACK_SHRINK); fgVBox->pack_start(*prifreeVBox, Gtk::PACK_SHRINK); - + predx->setAdjusterListener(this); predy->setAdjusterListener(this); pgrex->setAdjusterListener(this); pgrey->setAdjusterListener(this); pblux->setAdjusterListener(this); pbluy->setAdjusterListener(this); - - //sliders gampos and slpos + + //sliders gampos and slpos fgVBox->pack_start(*gaHBox, Gtk::PACK_EXPAND_WIDGET); gampos = Gtk::manage(new Adjuster(M("TP_GAMMA_CURV"), 1, 3.5, 0.00001, 2.4)); gampos->setAdjusterListener(this); @@ -325,7 +371,7 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha } gampos->show(); - + slpos = Gtk::manage(new Adjuster(M("TP_GAMMA_SLOP"), 0, 15, 0.00001, 12.92310)); slpos->setAdjusterListener(this); @@ -338,7 +384,7 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha fgVBox->pack_start(*slpos, Gtk::PACK_SHRINK); //slope //V2 or V4 profiles - profHBox = Gtk::manage(new Gtk::HBox()); + profHBox = Gtk::manage(new Gtk::HBox()); Gtk::Label* proflab = Gtk::manage(new Gtk::Label(M("TP_GAMMA_PROF") + ":")); profHBox->pack_start(*proflab, Gtk::PACK_SHRINK); @@ -352,10 +398,10 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha wprofile->set_active(0); - + //temperature - tempHBox = Gtk::manage(new Gtk::HBox()); - + tempHBox = Gtk::manage(new Gtk::HBox()); + Gtk::Label* templab = Gtk::manage(new Gtk::Label(M("TP_GAMMA_TEMP") + ":")); tempHBox->pack_start(*templab, Gtk::PACK_SHRINK); @@ -370,7 +416,7 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha wtemp->append(M("TP_GAMMA_TEMP_65")); wtemp->append(M("TP_GAMMA_TEMP_80")); wtemp->append(M("TP_GAMMA_TEMP_INC")); - + wtemp->set_active(0); wtemp->set_tooltip_text(M("TP_GAMMA_TEMP_TOOLTIP")); @@ -424,6 +470,7 @@ ICMPanel::ICMPanel() : FoldableToolPanel(this, "icm", M("TP_ICM_LABEL")), iuncha wprimariconn = wprimari->signal_changed().connect(sigc::mem_fun(*this, &ICMPanel::wprimariChanged)); wprofileconn = wprofile->signal_changed().connect(sigc::mem_fun(*this, &ICMPanel::wprofileChanged)); wtempconn = wtemp->signal_changed().connect(sigc::mem_fun(*this, &ICMPanel::wtempChanged)); + wtrcinconn = wtrcin->signal_changed().connect(sigc::mem_fun(*this, &ICMPanel::wtrcinChanged)); obpcconn = obpc->signal_toggled().connect(sigc::mem_fun(*this, &ICMPanel::oBPCChanged)); gamcsconn = freegamma->signal_toggled().connect(sigc::mem_fun(*this, &ICMPanel::GamChanged)); @@ -615,6 +662,7 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) ConnectionBlocker wprimariconn_(wprimariconn); ConnectionBlocker wprofileconn_(wprofileconn); ConnectionBlocker wtempconn_(wtempconn); +// ConnectionBlocker wtrcinconn_(wtrcinconn); if (pp->icm.input.substr(0, 5) != "file:" && !ipDialog->get_filename().empty()) { ipDialog->set_filename(pp->icm.input); @@ -651,7 +699,7 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) wnames->set_active_text(pp->icm.working); wgamma->set_active_text(pp->icm.gamma); - + if (pp->icm.wprimari == "acesp0") { wprimari->set_active(0); } else if (pp->icm.wprimari == "acesp1") { @@ -672,13 +720,17 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) wprimari->set_active(8); } else if (pp->icm.wprimari == "BruceRGB") { wprimari->set_active(9); - } else if (pp->icm.wprimari == "pfree") { + } else if (pp->icm.wprimari == "pfree") { wprimari->set_active(10); - } - if(wprimari->get_active_row_number() == 10) prifreeVBox->set_sensitive(true); - else prifreeVBox->set_sensitive(false); + } + + if (wprimari->get_active_row_number() == 10) { + prifreeVBox->set_sensitive(true); + } else { + prifreeVBox->set_sensitive(false); + } + - if (pp->icm.wtemp == "DEF") { wtemp->set_active(0); } else if (pp->icm.wtemp == "D41") { @@ -697,6 +749,11 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) wtemp->set_active(7); } + if (pp->icm.wtrcin == "none") { + wtrcin->set_active(0); + } else if (pp->icm.wtrcin == "free") { + wtrcin->set_active(1); + } if (pp->icm.wprofile == "none") { wprofile->set_active(0); @@ -706,14 +763,17 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) wprofile->set_active(2); } - - if(wprimari->get_active_row_number() == 10) wprofile->set_active(2); - - gpChanged(); - wprofileChanged(); - wtempChanged(); - wprimariChanged(); - + + if (wprimari->get_active_row_number() == 10) { + wprofile->set_active(2); + } + + gpChanged(); + wprofileChanged(); + wtempChanged(); + wprimariChanged(); + wtrcinChanged(); + if (pp->icm.output == ColorManagementParams::NoICMString) { onames->set_active_text(M("TP_ICM_NOICM")); } else { @@ -745,13 +805,18 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) gampos->set_sensitive(pp->icm.freegamma); gampos->set_sensitive(pp->icm.gamma == "Free"); slpos->set_sensitive(pp->icm.freegamma); - slpos->set_sensitive(pp->icm.gamma == "Free"); + slpos->set_sensitive(pp->icm.gamma == "Free"); updateRenderingIntent(pp->icm.output); wprimari->set_sensitive(pp->icm.freegamma); wprofile->set_sensitive(pp->icm.freegamma); - if(wprofile->get_active_row_number() == 2) {wtemp->set_sensitive(pp->icm.freegamma);} - else {wtemp->set_sensitive(false);} - // wtemp->set_sensitive(pp->icm.freegamma); + + if (wprofile->get_active_row_number() == 2) { + wtemp->set_sensitive(pp->icm.freegamma); + } else { + wtemp->set_sensitive(false); + } + + // wtemp->set_sensitive(pp->icm.freegamma); } @@ -763,6 +828,8 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) pgrey->setValue(pp->icm.pgrey); pblux->setValue(pp->icm.pblux); pbluy->setValue(pp->icm.pbluy); + gamm->setValue(pp->icm.gamm); + slop->setValue(pp->icm.slop); if (pedited) { iunchanged->set_active(!pedited->icm.input); @@ -804,7 +871,11 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) if (!pedited->icm.wtemp) { wtemp->set_active_text(M("GENERAL_UNCHANGED")); } - + + if (!pedited->icm.wtrcin) { + wtrcin->set_active_text(M("GENERAL_UNCHANGED")); + } + gampos->setEditedState(pedited->icm.gampos ? Edited : UnEdited); slpos->setEditedState(pedited->icm.slpos ? Edited : UnEdited); predx->setEditedState(pedited->icm.predx ? Edited : UnEdited); @@ -813,6 +884,8 @@ void ICMPanel::read(const ProcParams* pp, const ParamsEdited* pedited) pgrey->setEditedState(pedited->icm.pgrey ? Edited : UnEdited); pblux->setEditedState(pedited->icm.pblux ? Edited : UnEdited); pbluy->setEditedState(pedited->icm.pbluy ? Edited : UnEdited); + gamm->setEditedState(pedited->icm.gamm ? Edited : UnEdited); + slop->setEditedState(pedited->icm.slop ? Edited : UnEdited); } @@ -845,6 +918,7 @@ void ICMPanel::write(ProcParams* pp, ParamsEdited* pedited) pp->icm.dcpIlluminant = rtengine::max(dcpIll->get_active_row_number(), 0); pp->icm.wprimari = wprimari->get_active_text(); pp->icm.wtemp = wtemp->get_active_text(); + pp->icm.wtrcin = wtrcin->get_active_text(); if (onames->get_active_text() == M("TP_ICM_NOICM")) { pp->icm.output = ColorManagementParams::NoICMString; @@ -891,7 +965,7 @@ void ICMPanel::write(ProcParams* pp, ParamsEdited* pedited) } else if (wprimari->get_active_row_number() == 10) { pp->icm.wprimari = "pfree"; } - + if (wtemp->get_active_row_number() == 0) { pp->icm.wtemp = "DEF"; } else if (wtemp->get_active_row_number() == 1) { @@ -909,7 +983,13 @@ void ICMPanel::write(ProcParams* pp, ParamsEdited* pedited) } else if (wtemp->get_active_row_number() == 7) { pp->icm.wtemp = "INC"; } - + + if (wtrcin->get_active_row_number() == 0) { + pp->icm.wtrcin = "none"; + } else if (wtrcin->get_active_row_number() == 1) { + pp->icm.wtrcin = "free"; + } + pp->icm.freegamma = freegamma->get_active(); pp->icm.toneCurve = ckbToneCurve->get_active(); pp->icm.applyLookTable = ckbApplyLookTable->get_active(); @@ -924,6 +1004,8 @@ void ICMPanel::write(ProcParams* pp, ParamsEdited* pedited) pp->icm.pgrey = (double) pgrey->getValue(); pp->icm.pblux = (double) pblux->getValue(); pp->icm.pbluy = (double) pbluy->getValue(); + pp->icm.gamm = (double) gamm->getValue(); + pp->icm.slop = (double) slop->getValue(); if (pedited) { pedited->icm.input = !iunchanged->get_active(); @@ -946,10 +1028,13 @@ void ICMPanel::write(ProcParams* pp, ParamsEdited* pedited) pedited->icm.pgrey = pgrey->getEditedState(); pedited->icm.pblux = pblux->getEditedState(); pedited->icm.pbluy = pbluy->getEditedState(); - + pedited->icm.gamm = gamm->getEditedState(); + pedited->icm.slop = slop->getEditedState(); + pedited->icm.wprimari = wprimari->get_active_text() != M("GENERAL_UNCHANGED"); pedited->icm.wprofile = wprofile->get_active_text() != M("GENERAL_UNCHANGED"); pedited->icm.wtemp = wtemp->get_active_text() != M("GENERAL_UNCHANGED"); + pedited->icm.wtrcin = wtrcin->get_active_text() != M("GENERAL_UNCHANGED"); } } @@ -963,6 +1048,8 @@ void ICMPanel::setDefaults(const ProcParams* defParams, const ParamsEdited* pedi pgrey->setDefault(defParams->icm.pgrey); pblux->setDefault(defParams->icm.pblux); pbluy->setDefault(defParams->icm.pbluy); + gamm->setDefault(defParams->icm.gamm); + slop->setDefault(defParams->icm.slop); if (pedited) { gampos->setDefaultEditedState(pedited->icm.gampos ? Edited : UnEdited); @@ -973,7 +1060,9 @@ void ICMPanel::setDefaults(const ProcParams* defParams, const ParamsEdited* pedi pgrey->setDefaultEditedState(pedited->icm.pgrey ? Edited : UnEdited); pblux->setDefaultEditedState(pedited->icm.pblux ? Edited : UnEdited); pbluy->setDefaultEditedState(pedited->icm.pbluy ? Edited : UnEdited); - + gamm->setDefaultEditedState(pedited->icm.gamm ? Edited : UnEdited); + slop->setDefaultEditedState(pedited->icm.slop ? Edited : UnEdited); + } else { gampos->setDefaultEditedState(Irrelevant); slpos->setDefaultEditedState(Irrelevant); @@ -983,7 +1072,9 @@ void ICMPanel::setDefaults(const ProcParams* defParams, const ParamsEdited* pedi pgrey->setDefaultEditedState(Irrelevant); pblux->setDefaultEditedState(Irrelevant); pbluy->setDefaultEditedState(Irrelevant); - + gamm->setDefaultEditedState(Irrelevant); + slop->setDefaultEditedState(Irrelevant); + } } @@ -1018,12 +1109,27 @@ void ICMPanel::adjusterChanged(Adjuster* a, double newval) listener->panelChanged(EvICMpbluy, costr); } } + + if (listener || batchMode) { + Glib::ustring costr2 = Glib::ustring::format(std::setw(3), std::fixed, std::setprecision(2), newval); + + if (a == gamm) { + listener->panelChanged(EvICMgamm, costr2); + } else if (a == slop) { + listener->panelChanged(EvICMslop, costr2); + } + + } } void ICMPanel::wpChanged() { - if(wprofile->get_active_row_number() == 2) {wtemp->set_sensitive(true);} - else {wtemp->set_sensitive(false);} + if (wprofile->get_active_row_number() == 2) { + wtemp->set_sensitive(true); + } else { + wtemp->set_sensitive(false); + } + if (listener) { listener->panelChanged(EvWProfile, wnames->get_active_text()); } @@ -1031,9 +1137,15 @@ void ICMPanel::wpChanged() void ICMPanel::wprimariChanged() { - if(wprimari->get_active_row_number() == 10) prifreeVBox->set_sensitive(true); - else prifreeVBox->set_sensitive(false); - if(wprimari->get_active_row_number() == 10) wprofile->set_active(2); + if (wprimari->get_active_row_number() == 10) { + prifreeVBox->set_sensitive(true); + } else { + prifreeVBox->set_sensitive(false); + } + + if (wprimari->get_active_row_number() == 10) { + wprofile->set_active(2); + } if (listener) { listener->panelChanged(EvICMprimariMethod, wprimari->get_active_text()); @@ -1042,40 +1154,68 @@ void ICMPanel::wprimariChanged() void ICMPanel::wtempChanged() { - if(wprofile->get_active_row_number() == 2){wtemp->set_sensitive(true);} - else {wtemp->set_sensitive(false);} - if(wtemp->get_active_row_number() != 0) wprofile->set_active(2); + if (wprofile->get_active_row_number() == 2) { + wtemp->set_sensitive(true); + } else { + wtemp->set_sensitive(false); + } + + if (wtemp->get_active_row_number() != 0) { + wprofile->set_active(2); + } if (listener) { listener->panelChanged(EvICMtempMethod, wtemp->get_active_text()); } } +void ICMPanel::wtrcinChanged() +{ + if (wtrcin->get_active_row_number() == 0) { + gamm->set_sensitive(false); + slop->set_sensitive(false); + + } else { + gamm->set_sensitive(true); + slop->set_sensitive(true); + } + + if (listener) { + listener->panelChanged(EvICMtrcinMethod, wtrcin->get_active_text()); + } +} + void ICMPanel::wprofileChanged() { - if(wprofile->get_active_row_number() == 2){wtemp->set_sensitive(true);} - else {wtemp->set_sensitive(false);} - if(wtemp->get_active_row_number() != 0) wprofile->set_active(2); + if (wprofile->get_active_row_number() == 2) { + wtemp->set_sensitive(true); + } else { + wtemp->set_sensitive(false); + } + + if (wtemp->get_active_row_number() != 0) { + wprofile->set_active(2); + } if (listener) { listener->panelChanged(EvICMprofileMethod, wprofile->get_active_text()); - + } } void ICMPanel::gpChanged() { - if (wgamma->get_active_row_number() == 0) { + if (wgamma->get_active_row_number() == 0) { gampos->set_sensitive(true); slpos->set_sensitive(true); - } else { + } else { gampos->set_sensitive(false); slpos->set_sensitive(false); - } + } if (listener) { listener->panelChanged(EvGAMMA, wgamma->get_active_text()); - onames->set_sensitive(wgamma->get_active_row_number() == 0); + onames->set_sensitive(wgamma->get_active_row_number() == 0); } } @@ -1231,9 +1371,12 @@ void ICMPanel::ipChanged() void ICMPanel::GamChanged() { - - if(wprofile->get_active_row_number() == 2) {wtemp->set_sensitive(true);} - else {wtemp->set_sensitive(false);} + + if (wprofile->get_active_row_number() == 2) { + wtemp->set_sensitive(true); + } else { + wtemp->set_sensitive(false); + } if (multiImage) { if (freegamma->get_inconsistent()) { @@ -1261,15 +1404,23 @@ void ICMPanel::GamChanged() slpos->set_sensitive(true); wprimari->set_sensitive(true); wprofile->set_sensitive(true); - //wtemp->set_sensitive(true); - if(wprofile->get_active_row_number() == 2) wtemp->set_sensitive(true); - priHBox->set_sensitive(true); - if(wprimari->get_active_row_number() == 10) prifreeVBox->set_sensitive(true); - else prifreeVBox->set_sensitive(false); - - gaHBox->set_sensitive(true); - profHBox->set_sensitive(true); - tempHBox->set_sensitive(true); + + //wtemp->set_sensitive(true); + if (wprofile->get_active_row_number() == 2) { + wtemp->set_sensitive(true); + } + + priHBox->set_sensitive(true); + + if (wprimari->get_active_row_number() == 10) { + prifreeVBox->set_sensitive(true); + } else { + prifreeVBox->set_sensitive(false); + } + + gaHBox->set_sensitive(true); + profHBox->set_sensitive(true); + tempHBox->set_sensitive(true); } } else { listener->panelChanged(EvGAMFREE, M("GENERAL_DISABLED")); @@ -1281,15 +1432,19 @@ void ICMPanel::GamChanged() slpos->set_sensitive(false); wprimari->set_sensitive(false); wprofile->set_sensitive(false); - if(wprofile->get_active_row_number() != 2) wtemp->set_sensitive(false); - //wtemp->set_sensitive(false); - priHBox->set_sensitive(false); - prifreeVBox->set_sensitive(false); - - gaHBox->set_sensitive(false); - profHBox->set_sensitive(false); - tempHBox->set_sensitive(false); - + + if (wprofile->get_active_row_number() != 2) { + wtemp->set_sensitive(false); + } + + //wtemp->set_sensitive(false); + priHBox->set_sensitive(false); + prifreeVBox->set_sensitive(false); + + gaHBox->set_sensitive(false); + profHBox->set_sensitive(false); + tempHBox->set_sensitive(false); + } } } @@ -1469,8 +1624,11 @@ void ICMPanel::setBatchMode(bool batchMode) wprimari->append(M("GENERAL_UNCHANGED")); wprofile->append(M("GENERAL_UNCHANGED")); wtemp->append(M("GENERAL_UNCHANGED")); + wtrcin->append(M("GENERAL_UNCHANGED")); dcpIll->append(M("GENERAL_UNCHANGED")); gampos->showEditedCB(); slpos->showEditedCB(); + gamm->showEditedCB(); + slop->showEditedCB(); } diff --git a/rtgui/icmpanel.h b/rtgui/icmpanel.h index c863c30aa..57e0be5cd 100644 --- a/rtgui/icmpanel.h +++ b/rtgui/icmpanel.h @@ -36,7 +36,11 @@ public: virtual void saveInputICCReference(Glib::ustring fname, bool apply_wb) {} }; -class ICMPanel : public ToolParamBlock, public AdjusterListener, public FoldableToolPanel, public rtengine::ICMListener +class ICMPanel : + public ToolParamBlock, + public AdjusterListener, + public FoldableToolPanel, + public rtengine::ICMListener { protected: @@ -49,8 +53,13 @@ protected: Adjuster* pgrey; Adjuster* pblux; Adjuster* pbluy; - - + Adjuster* gamm; + Adjuster* slop; + + Gtk::Label* labmga; + Gtk::HBox* gabox; + + bool lastgamfree; sigc::connection gamcsconn; //bool freegamma; @@ -76,6 +85,9 @@ private: rtengine::ProcEvent EvICMpgrey; rtengine::ProcEvent EvICMpblux; rtengine::ProcEvent EvICMpbluy; + rtengine::ProcEvent EvICMgamm; + rtengine::ProcEvent EvICMslop; + rtengine::ProcEvent EvICMtrcinMethod; Gtk::VBox * iVBox; Gtk::HBox* priHBox; @@ -83,6 +95,7 @@ private: Gtk::HBox* profHBox; Gtk::HBox* tempHBox; Gtk::VBox* prifreeVBox; + Gtk::HBox* trcinHBox; Gtk::CheckButton* obpc; Gtk::CheckButton* freegamma; @@ -109,6 +122,8 @@ private: sigc::connection wprofileconn; MyComboBoxText* wtemp; sigc::connection wtempconn; + MyComboBoxText* wtrcin; + sigc::connection wtrcinconn; MyComboBoxText* onames; sigc::connection onamesconn; @@ -141,6 +156,7 @@ public: void wprimariChanged(); void wprofileChanged(); void wtempChanged(); + void wtrcinChanged(); void opChanged(); void oiChanged(int n); void oBPCChanged(); diff --git a/rtgui/paramsedited.cc b/rtgui/paramsedited.cc index 4562d5d28..103a92d7f 100644 --- a/rtgui/paramsedited.cc +++ b/rtgui/paramsedited.cc @@ -395,9 +395,12 @@ void ParamsEdited::set(bool v) icm.pgrey = v; icm.pblux = v; icm.pbluy = v; + icm.gamm = v; + icm.slop = v; icm.wprimari = v; icm.wprofile = v; icm.wtemp = v; + icm.wtrcin = v; raw.bayersensor.method = v; raw.bayersensor.imageNum = v; raw.bayersensor.ccSteps = v; @@ -951,10 +954,13 @@ void ParamsEdited::initFrom(const std::vector& icm.pgrey = icm.pgrey && p.icm.pgrey == other.icm.pgrey; icm.pblux = icm.pblux && p.icm.pblux == other.icm.pblux; icm.pbluy = icm.pbluy && p.icm.pbluy == other.icm.pbluy; - + icm.gamm = icm.gamm && p.icm.gamm == other.icm.gamm; + icm.slop = icm.slop && p.icm.slop == other.icm.slop; + icm.wprimari = icm.wprimari && p.icm.wprimari == other.icm.wprimari; icm.wprofile = icm.wprofile && p.icm.wprofile == other.icm.wprofile; icm.wtemp = icm.wtemp && p.icm.wtemp == other.icm.wtemp; + icm.wtrcin = icm.wtrcin && p.icm.wtrcin == other.icm.wtrcin; raw.bayersensor.method = raw.bayersensor.method && p.raw.bayersensor.method == other.raw.bayersensor.method; raw.bayersensor.imageNum = raw.bayersensor.imageNum && p.raw.bayersensor.imageNum == other.raw.bayersensor.imageNum; raw.bayersensor.ccSteps = raw.bayersensor.ccSteps && p.raw.bayersensor.ccSteps == other.raw.bayersensor.ccSteps; @@ -1200,7 +1206,7 @@ void ParamsEdited::combine(rtengine::procparams::ProcParams& toEdit, const rteng if (toneCurve.clampOOG) { toEdit.toneCurve.clampOOG = mods.toneCurve.clampOOG; } - + if (retinex.enabled) { toEdit.retinex.enabled = mods.retinex.enabled; } @@ -2457,6 +2463,14 @@ void ParamsEdited::combine(rtengine::procparams::ProcParams& toEdit, const rteng toEdit.icm.slpos = dontforceSet && options.baBehav[ADDSET_FREE_OUTPUT_SLOPE] ? toEdit.icm.slpos + mods.icm.slpos : mods.icm.slpos; } + if (icm.gamm) { + toEdit.icm.gamm = mods.icm.gamm; + } + + if (icm.slop) { + toEdit.icm.slop = mods.icm.slop; + } + if (icm.predx) { toEdit.icm.predx = mods.icm.predx; } @@ -2472,7 +2486,7 @@ void ParamsEdited::combine(rtengine::procparams::ProcParams& toEdit, const rteng if (icm.pgrey) { toEdit.icm.pgrey = mods.icm.pgrey; } - + if (icm.pblux) { toEdit.icm.pblux = mods.icm.pblux; } @@ -2496,7 +2510,11 @@ void ParamsEdited::combine(rtengine::procparams::ProcParams& toEdit, const rteng if (icm.wtemp) { toEdit.icm.wtemp = mods.icm.wtemp; } - + + if (icm.wtrcin) { + toEdit.icm.wtrcin = mods.icm.wtrcin; + } + if (icm.freegamma) { toEdit.icm.freegamma = mods.icm.freegamma; } diff --git a/rtgui/paramsedited.h b/rtgui/paramsedited.h index e65efdbb0..4a83fde73 100644 --- a/rtgui/paramsedited.h +++ b/rtgui/paramsedited.h @@ -598,6 +598,9 @@ public: bool wprimari; bool wprofile; bool wtemp; + bool gamm; + bool slop; + bool wtrcin; }; class WaveletParamsEdited {