diff --git a/rtengine/FTblockDN.cc b/rtengine/FTblockDN.cc index 53a0615a2..778265db0 100644 --- a/rtengine/FTblockDN.cc +++ b/rtengine/FTblockDN.cc @@ -29,9 +29,7 @@ #include #include "../rtgui/threadutils.h" -//#include "bilateral2.h" #include "gauss.h" - #include "rtengine.h" #include "improcfun.h" #include "LUT.h" @@ -247,7 +245,7 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt // printf("Nw=%d NH=%d tileW=%d tileH=%d\n",numtiles_W,numtiles_H,tileWskip,tileHskip); } - void ImProcFunctions::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 procparams::DefringeParams & defringe, const double expcomp, const NoisCurve & dnNoisCurve, bool lldenoiseutili, const NoisCCcurve & dnNoisCCcurve, bool ccdenoiseutili, float &chaut, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &nresi, float &highresi) + void ImProcFunctions::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 &chaut, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &nresi, float &highresi) { //#ifdef _DEBUG MyTime t1e,t2e; @@ -255,7 +253,7 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt //#endif - if (dnparams.luma==0 && dnparams.chroma==0 && !dnparams.median && !dnNoisCurve && !dnNoisCCcurve) { + if (dnparams.luma==0 && dnparams.chroma==0 && !dnparams.median && !noiseLCurve && !noiseCCurve) { //nothing to do; copy src to dst or do nothing in case src == dst if(src != dst) memcpy(dst->data,src->data,dst->width*dst->height*3*sizeof(float)); @@ -273,7 +271,7 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt float** lumcalc; float** acalc; float** bcalc; - if(lldenoiseutili || ccdenoiseutili) { + if(noiseLCurve || noiseCCurve) { hei=calclum->height; wid=calclum->width; TMatrix wprofi = iccStore->workingSpaceMatrix (params->icm.working); @@ -333,8 +331,7 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt Qhigh=1.0f; if(dnparams.smethod=="shalbi") Qhigh=1.f/(float) settings->nrhigh; if (dnparams.luma!=0 || dnparams.chroma!=0 || dnparams.methodmed=="Lab" || dnparams.methodmed=="Lonly" ) { - perf=false; - if(dnparams.dmethod=="RGB") perf=true;//RGB mode + const bool perf = (dnparams.dmethod=="RGB"); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // gamma transform for input data float gam = dnparams.gamma; @@ -592,10 +589,10 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt float B_ = gain*src->b(i,j); float Llum,alum,blum; - if(dnNoisCurve) { + if(noiseLCurve) { Llum=lumcalc[i][j]; } - if(dnNoisCCcurve) { + if(noiseCCurve) { alum=acalc[i][j]; blum=bcalc[i][j]; } @@ -633,12 +630,12 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt Color::XYZ2Lab(X, Y, Z, L, a, b); float noiseluma=(float) dnparams.luma; - if(dnNoisCurve) { + if(noiseLCurve) { float kN=Llum;//with no gamma and take into account working profile float epsi=0.01f; if(kN<2.f) kN=2.f;//avoid divided by zero if(kN>32768.f) kN=32768.f; // not strictly necessary - float kinterm=epsi+ dnNoisCurve.lutNoisCurve[(kN/32768.f)*500.f]; + float kinterm=epsi+ noiseLCurve[(kN/32768.f)*500.f]; float ki=kinterm*100.f; ki+=noiseluma; noiseluma += 1.f; @@ -646,7 +643,7 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt } noisevarab_r = SQR(realred); noisevarab_b = SQR(realblue); - if(dnNoisCCcurve) { + if(noiseCCurve) { float aN=alum; float bN=blum; float epsic=0.01f; @@ -656,7 +653,7 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt float cN=sqrt(SQR(aN)+SQR(bN)); if(cN < 100.f) cN=100.f;//avoid divided by zero - float Cinterm=1.f + ponderCC*4.f*dnNoisCCcurve.lutNoisCCcurve[(cN/30000.f)*500.f];//C=f(C) + float Cinterm=1.f + ponderCC*4.f*noiseCCurve[(cN/30000.f)*500.f];//C=f(C) noisevarchrom[i1][j1]= max(noisevarab_b,noisevarab_r)*SQR(Cinterm); // printf("NC=%f ",noisevarchrom[i1][j1]); } @@ -684,10 +681,10 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt float Z = gain*src->b(i,j); //conversion colorspace to determine luminance with no gamma float Llum,alum,blum; - if(dnNoisCurve) { + if(noiseLCurve) { Llum=lumcalc[i][j]; } - if(dnNoisCCcurve) { + if(noiseCCurve) { alum=acalc[i][j]; blum=bcalc[i][j]; } @@ -696,13 +693,13 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt Y = Y<65535.0f ? gamcurve[Y] : (Color::gamma((double)Y/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f); Z = Z<65535.0f ? gamcurve[Z] : (Color::gamma((double)Z/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f); float noiseluma=(float) dnparams.luma; - if(dnNoisCurve) { + if(noiseLCurve) { // float noiseluma=(float) dnparams.luma; float kN=Llum; float epsi=0.01f; if(kN<2.f) kN=2.f; if(kN>32768.f) kN=32768.f; - float kinterm=epsi + dnNoisCurve.lutNoisCurve[(kN/32768.f)*500.f]; + float kinterm=epsi + noiseLCurve[(kN/32768.f)*500.f]; float ki=kinterm*100.f; ki+=noiseluma; noiseluma += 1.f; @@ -711,14 +708,14 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt noisevarL = SQR((noiseluma/125.f)*(1.f+noiseluma/25.f)); noisevarab_r = SQR(realred); noisevarab_b = SQR(realblue); - if(dnNoisCCcurve) { + if(noiseCCurve) { float aN=alum; float bN=blum; float epsic=0.01f; float cN=sqrt(SQR(aN)+SQR(bN)); if(cN < 100.f) cN=100.f;//avoid divided by zero - float Cinterm=1.f + ponderCC*4.f*dnNoisCCcurve.lutNoisCCcurve[(cN/30000.f)*500.f]; + float Cinterm=1.f + ponderCC*4.f*noiseCCurve[(cN/30000.f)*500.f]; noisevarchrom[i1][j1]=max(noisevarab_b,noisevarab_r)*SQR(Cinterm); } //end chroma @@ -767,21 +764,21 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt //convert Lab Color::XYZ2Lab(X, Y, Z, L, a, b); float Llum,alum,blum; - if(dnNoisCurve || dnNoisCCcurve) { + if(noiseLCurve || noiseCCurve) { float XL,YL,ZL; Color::rgbxyz(rLum,gLum,bLum,XL,YL,ZL,wp); Color::XYZ2Lab(XL, YL, ZL, Llum, alum, blum); } float noiseluma=(float) dnparams.luma; - if(dnNoisCurve) { + if(noiseLCurve) { // float noiseluma=(float) dnparams.luma; float kN=Llum; float epsi=0.01f; if(kN<2.f) kN=2.f; if(kN>32768.f) kN=32768.f; - float kinterm=epsi + dnNoisCurve.lutNoisCurve[(kN/32768.f)*500.f]; + float kinterm=epsi + noiseLCurve[(kN/32768.f)*500.f]; float ki=kinterm*100.f; ki+=noiseluma; noiseluma += 1.f; @@ -789,13 +786,13 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt noisevarlum[i1][j1]=SQR((ki/125.f)*(1.f+ki/25.f)); } noisevarL = SQR((noiseluma/125.f)*(1.f+noiseluma/25.f)); - if(dnNoisCCcurve) { + if(noiseCCurve) { float aN=alum; float bN=blum; float epsic=0.01f; float cN=sqrt(SQR(aN)+SQR(bN)); if(cN < 100.f) cN=100.f;//avoid divided by zero - float Cinterm=1.f + ponderCC*4.f*dnNoisCCcurve.lutNoisCCcurve[(cN/30000.f)*500.f]; + float Cinterm=1.f + ponderCC*4.f*noiseCCurve[(cN/30000.f)*500.f]; noisevarchrom[i1][j1]=max(noisevarab_b,noisevarab_r)*SQR(Cinterm); } @@ -810,11 +807,11 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt } } } - // printf("OK\n"); - //initial impulse denoise - if (dnparams.luma>0.01) { - impulse_nr (labdn, float(MIN(50.0,dnparams.luma))/20.0f); - } + + //initial impulse denoise, removed in Issue 2557 +// if (dnparams.luma>0.01) { +// impulse_nr (labdn, float(MIN(50.0,dnparams.luma))/20.0f); +// } int datalen = labdn->W * labdn->H; @@ -828,9 +825,9 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt bool execwavelet=true; bool autoch=false; if(noisevarL < 0.000007f && interm_medT < 0.05f && dnparams.median && (dnparams.methodmed=="Lab" || dnparams.methodmed=="Lonly")) execwavelet=false;//do not exec wavelet if sliders luminance and chroma are very small and median need - //we considered user don't want wavelet + //we considered user don't want wavelet if(settings->leveldnautsimpl==1 && dnparams.Cmethod!="MAN") execwavelet=true; - if(settings->leveldnautsimpl==0 && dnparams.C2method!="MAN") execwavelet=true; + if(settings->leveldnautsimpl==0 && dnparams.C2method!="MANU") execwavelet=true; if(settings->leveldnautsimpl==1 && (dnparams.Cmethod=="AUT" || dnparams.Cmethod=="PRE")) autoch=true; if(settings->leveldnautsimpl==0 && dnparams.C2method=="AUTO" || dnparams.C2method=="PREV") autoch=true; @@ -859,10 +856,10 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt Ldecomp = new wavelet_decomposition (labdn->data, labdn->W, labdn->H, levwav/*maxlevels*/, 0/*subsampling*/ ); adecomp = new wavelet_decomposition (labdn->data+datalen, labdn->W, labdn->H,levwav, 1 ); bdecomp = new wavelet_decomposition (labdn->data+2*datalen, labdn->W, labdn->H, levwav, 1 ); - if(schoice==0) WaveletDenoiseAll(*Ldecomp, *adecomp, *bdecomp, noisevarL, noisevarlum, noisevarchrom, width, height, mad_LL, mad_aa, mad_bb, noisevarab_r, noisevarab_b,labdn, lldenoiseutili, dnNoisCurve, dnNoisCCcurve, ccdenoiseutili, chaut, redaut, blueaut, maxredaut, maxblueaut, schoice, autoch);//enhance mode + if(schoice==0) WaveletDenoiseAll(*Ldecomp, *adecomp, *bdecomp, noisevarL, noisevarlum, noisevarchrom, width, height, mad_LL, mad_aa, mad_bb, noisevarab_r, noisevarab_b,labdn, noiseLCurve, noiseCCurve, chaut, redaut, blueaut, maxredaut, maxblueaut, schoice, autoch);//enhance mode if(schoice==2) { - WaveletDenoiseAll_BiShrink(*Ldecomp, *adecomp, *bdecomp, noisevarL, noisevarlum, noisevarchrom, width, height, mad_LL, mad_aa, mad_bb, noisevarab_r, noisevarab_b,labdn, lldenoiseutili, dnNoisCurve, dnNoisCCcurve, ccdenoiseutili, chaut, redaut, blueaut, maxredaut, maxblueaut, schoice, autoch);//enhance mode - WaveletDenoiseAll(*Ldecomp, *adecomp, *bdecomp, noisevarL, noisevarlum, noisevarchrom, width, height, mad_LL, mad_aa, mad_bb, noisevarab_r, noisevarab_b,labdn, lldenoiseutili, dnNoisCurve, dnNoisCCcurve, ccdenoiseutili, chaut ,redaut, blueaut, maxredaut, maxblueaut, schoice, autoch); + WaveletDenoiseAll_BiShrink(*Ldecomp, *adecomp, *bdecomp, noisevarL, noisevarlum, noisevarchrom, width, height, mad_LL, mad_aa, mad_bb, noisevarab_r, noisevarab_b,labdn, noiseLCurve, noiseCCurve, chaut, redaut, blueaut, maxredaut, maxblueaut, schoice, autoch);//enhance mode + WaveletDenoiseAll(*Ldecomp, *adecomp, *bdecomp, noisevarL, noisevarlum, noisevarchrom, width, height, mad_LL, mad_aa, mad_bb, noisevarab_r, noisevarab_b,labdn, noiseLCurve, noiseCCurve, chaut ,redaut, blueaut, maxredaut, maxblueaut, schoice, autoch); } float chresid,chmaxredresid,chmaxblueresid,chresidred, chresidblue; //kall=0 call by Dcrop @@ -883,10 +880,10 @@ void ImProcFunctions::Tile_calc (int tilesize, int overlap, int kall, int imwidt //TODO: at this point wavelet coefficients storage can be freed //Issue 1680: Done now - //second impulse denoise - if (dnparams.luma>0.01) { - impulse_nr (labdn, MIN(50.0f,(float)dnparams.luma)/20.0f); - } + //second impulse denoise, removed in Issue 2557 +// if (dnparams.luma>0.01) { +// impulse_nr (labdn, MIN(50.0f,(float)dnparams.luma)/20.0f); +// } //PF_correct_RT(dst, dst, defringe.radius, defringe.threshold); @@ -1683,7 +1680,7 @@ for(int iteration=1;iteration<=dnparams.passes;iteration++){ } //end median - if(lldenoiseutili || ccdenoiseutili) { + if(noiseLCurve || noiseCCurve) { for (int i=0; i 5.f ){ + if (noiseCCurve && noiseCCurve.getSum() > 5.f ){ // printf("OUI\n"); - for (int i=0; i0.00001f) { - if (!lldenoiseutili || dnNoisCurve.nonzero < 7.f ) { - for (int i=0; i= 7.f) { - for (int i=0; i= 7.f) { + for (int i=0; i 5.f ){ + if (noiseCCurve && noiseCCurve.getSum() > 5.f ){ // printf("chroma OUI\n"); for (int i=0; iverbose) printf("noisevar=%f dnzero=%f \n",noisevar_L, dnNoisCurve.nonzero); + // if (settings->verbose) printf("noisevar=%f dnzero=%f \n",noisevar_L, noiseLCurve.sum); if (noisevar_L>0.00001f) { - if (!lldenoiseutili || dnNoisCurve.nonzero < 7.f ){//under 7 quasi no action + if (!noiseLCurve || noiseLCurve.getSum() < 7.f ){//under 7 quasi no action // printf("Luma sans\n"); for (int i=0; i= 7.f) { // printf("Luma avec\n"); + else {if (noiseLCurve && noiseLCurve.getSum() >= 7.f) { // printf("Luma avec\n"); for (int i=0; i= 1.9f && gam <= 3.f) gam=(1.4f/1.1f)*gam - 1.41818f; } gamslope = exp(log((double)gamthresh)/gam)/gamthresh; + bool perf = (dnparams.dmethod=="RGB"); if(perf) { for (int i=0; i<65536; i++) { gamcurve[i] = (Color::gamma((double)i/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)) * 32768.0f; @@ -2788,11 +2786,12 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l } - void ImProcFunctions::RGB_denoise_info(Imagefloat * src, Imagefloat * dst,Imagefloat * provicalc, bool isRAW, LUTf &gamcurve, float gam, float gamthresh, float gamslope, const procparams::DirPyrDenoiseParams & dnparams, const procparams::DefringeParams & defringe, const double expcomp, const NoisCurve & dnNoisCurve, bool lldenoiseutili, const NoisCCcurve & dnNoisCCcurve, bool ccdenoiseutili, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &minredaut, float &minblueaut, float &nresi, float &highresi, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel, float &skinc, float &nsknc) + void ImProcFunctions::RGB_denoise_info(Imagefloat * src, Imagefloat * dst,Imagefloat * provicalc, bool isRAW, LUTf &gamcurve, float gam, float gamthresh, float gamslope, const procparams::DirPyrDenoiseParams & dnparams, const double expcomp, const NoiseCurve & noiseLCurve, const NoiseCurve & noiseCCurve, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &minredaut, float &minblueaut, float &nresi, float &highresi, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel, float &skinc, float &nsknc) { // StopWatch Stop1("RGB_denoise_info"); + - if (dnparams.luma==0 && dnparams.chroma==0 && !dnparams.median ) { + if (dnparams.luma==0 && dnparams.chroma==0 && ((settings->leveldnautsimpl==1 && dnparams.Cmethod=="MAN") || (settings->leveldnautsimpl==0 && dnparams.C2method!="MANU")) && !dnparams.median && !noiseLCurve && !noiseCCurve) { //nothing to do; copy src to dst or do nothing in case src == dst return; } @@ -2803,7 +2802,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l float** lumcalc; float** acalc; float** bcalc; - if(lldenoiseutili || ccdenoiseutili) { + if(noiseLCurve || noiseCCurve) { hei=provicalc->height; wid=provicalc->width; TMatrix wprofi = iccStore->workingSpaceMatrix (params->icm.working); @@ -2846,9 +2845,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l const short int imheight=src->height, imwidth=src->width; if (dnparams.luma!=0 || dnparams.chroma!=0 || dnparams.methodmed=="Lab" || dnparams.methodmed=="Lonly" ) { - perf=false; - if(dnparams.dmethod=="RGB") perf=true;//RGB mode - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + bool perf = (dnparams.dmethod=="RGB"); // gamma transform for input data // LUTf gamcurve(65536,0); // float gam, gamthresh, gamslope; @@ -3007,10 +3004,10 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l float B_ = gain*src->b(i,j); float Llum,alum,blum; - if(dnNoisCurve) { + if(noiseLCurve) { Llum=lumcalc[i][j]; } - if(dnNoisCCcurve) { + if(noiseCCurve) { alum=acalc[i][j]; blum=bcalc[i][j]; } @@ -3045,12 +3042,12 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l Color::XYZ2Lab(X, Y, Z, L, a, b); float noiseluma=(float) dnparams.luma; - if(dnNoisCurve) { + if(noiseLCurve) { float kN=Llum;//with no gamma and take into account working profile float epsi=0.01f; if(kN<2.f) kN=2.f;//avoid divided by zero if(kN>32768.f) kN=32768.f; // not strictly necessary - float kinterm=epsi+ dnNoisCurve.lutNoisCurve[(kN/32768.f)*500.f]; + float kinterm=epsi+ noiseLCurve[(kN/32768.f)*500.f]; float ki=kinterm*100.f; ki+=noiseluma; noiseluma += 1.f; @@ -3061,7 +3058,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l noisevarab_r = SQR(realred); noisevarab_b = SQR(realblue); - if(dnNoisCCcurve) { + if(noiseCCurve) { float aN=alum; float bN=blum; float epsic=0.01f; @@ -3072,7 +3069,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l float cN=sqrt(SQR(aN)+SQR(bN)); float hN=xatan2f(bN,aN); if(cN < 100.f) cN=100.f;//avoid divided by zero - float Cinterm=1.f + 10.f*dnNoisCCcurve.lutNoisCCcurve[(cN/48000.f)*500.f];//C=f(C) + float Cinterm=1.f + 10.f*noiseCCurve[(cN/48000.f)*500.f];//C=f(C) noisevarchrom[i1][j1]=cN; noisevarhue[i1][j1]=hN; @@ -3099,10 +3096,10 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l float Z = gain*src->b(i,j); //conversion colorspace to determine luminance with no gamma float Llum,alum,blum; - if(dnNoisCurve) { + if(noiseLCurve) { Llum=lumcalc[i][j]; } - if(dnNoisCCcurve) { + if(noiseCCurve) { alum=acalc[i][j]; blum=bcalc[i][j]; } @@ -3111,13 +3108,13 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l Y = Y<65535.0f ? gamcurve[Y] : (Color::gamma((double)Y/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f); Z = Z<65535.0f ? gamcurve[Z] : (Color::gamma((double)Z/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f); float noiseluma=(float) dnparams.luma; - if(dnNoisCurve) { + if(noiseLCurve) { // float noiseluma=(float) dnparams.luma; float kN=Llum; float epsi=0.01f; if(kN<2.f) kN=2.f; if(kN>32768.f) kN=32768.f; - float kinterm=epsi + dnNoisCurve.lutNoisCurve[(kN/32768.f)*500.f]; + float kinterm=epsi + noiseLCurve[(kN/32768.f)*500.f]; float ki=kinterm*100.f; ki+=noiseluma; noiseluma += 1.f; @@ -3126,7 +3123,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l noisevarL = SQR((noiseluma/125.f)*(1.f+noiseluma/25.f)); noisevarab_r = SQR(realred); noisevarab_b = SQR(realblue); - if(dnNoisCCcurve) { + if(noiseCCurve) { float aN=alum; float bN=blum; float epsic=0.01f; @@ -3134,7 +3131,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l float cN=sqrt(SQR(aN)+SQR(bN)); if(cN < 100.f) cN=100.f;//avoid divided by zero - float Cinterm=1.f + 10.f*dnNoisCCcurve.lutNoisCCcurve[(cN/48000.f)*500.f]; + float Cinterm=1.f + 10.f*noiseCCurve[(cN/48000.f)*500.f]; //noisevarchrom[i1][j1]=0.5f*(noisevarab_b+noisevarab_r)*(Cinterm*Cinterm); noisevarchrom[i1][j1]=cN; noisevarhue[i1][j1]=hN; @@ -3185,21 +3182,21 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l //convert Lab Color::XYZ2Lab(X, Y, Z, L, a, b); float Llum,alum,blum; - if(dnNoisCurve || dnNoisCCcurve) { + if(noiseLCurve || noiseCCurve) { float XL,YL,ZL; Color::rgbxyz(rLum,gLum,bLum,XL,YL,ZL,wp); Color::XYZ2Lab(XL, YL, ZL, Llum, alum, blum); } float noiseluma=(float) dnparams.luma; - if(dnNoisCurve) { + if(noiseLCurve) { // float noiseluma=(float) dnparams.luma; float kN=Llum; float epsi=0.01f; if(kN<2.f) kN=2.f; if(kN>32768.f) kN=32768.f; - float kinterm=epsi + dnNoisCurve.lutNoisCurve[(kN/32768.f)*500.f]; + float kinterm=epsi + noiseLCurve[(kN/32768.f)*500.f]; float ki=kinterm*100.f; ki+=noiseluma; noiseluma += 1.f; @@ -3207,7 +3204,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l noisevarlum[i1][j1]=kN;//SQR((ki/125.f)*(1.f+ki/25.f)); } noisevarL = SQR((noiseluma/125.f)*(1.f+noiseluma/25.f)); - if(dnNoisCCcurve) { + if(noiseCCurve) { float aN=alum; float bN=blum; float epsic=0.01f; @@ -3215,7 +3212,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l float cN=sqrt(SQR(aN)+SQR(bN)); if(cN < 100.f) cN=100.f;//avoid divided by zero - float Cinterm=1.f + 10.f*dnNoisCCcurve.lutNoisCCcurve[(cN/48000.f)*500.f]; + float Cinterm=1.f + 10.f*noiseCCurve[(cN/48000.f)*500.f]; //noisevarchrom[i1][j1]=0.5f*(noisevarab_b+noisevarab_r)*(Cinterm*Cinterm); noisevarchrom[i1][j1]=cN; noisevarhue[i1][j1]=hN; @@ -3269,7 +3266,7 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l adecomp = new wavelet_decomposition (labdn->data+datalen, labdn->W, labdn->H,levwav, 1 ); bdecomp = new wavelet_decomposition (labdn->data+2*datalen, labdn->W, labdn->H, levwav, 1 ); bool autoch = dnparams.autochroma; - if(comptlevel==0) WaveletDenoiseAll_info(*Ldecomp, *adecomp, *bdecomp, noisevarL, noisevarlum, noisevarchrom, noisevarhue, width, height, mad_LL, mad_aa, mad_bb, noisevarab_r, noisevarab_b,labdn, lldenoiseutili, dnNoisCurve, dnNoisCCcurve, ccdenoiseutili, chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, schoice, autoch, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc,maxchred, maxchblue, minchred, minchblue, nb,chau ,chred, chblue);//enhance mode + if(comptlevel==0) WaveletDenoiseAll_info(*Ldecomp, *adecomp, *bdecomp, noisevarL, noisevarlum, noisevarchrom, noisevarhue, width, height, mad_LL, mad_aa, mad_bb, noisevarab_r, noisevarab_b,labdn, noiseLCurve, noiseCCurve, chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, schoice, autoch, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc,maxchred, maxchblue, minchred, minchblue, nb,chau ,chred, chblue);//enhance mode comptlevel+=1; float chresid,chmaxredresid,chmaxblueresid,chresidred, chresidblue; nresi=chresid; @@ -3304,18 +3301,17 @@ void ImProcFunctions::calcautodn_info (float &chaut, float &delta, int Nb, int l } //end median - if(lldenoiseutili || ccdenoiseutili) { - for (int i=0; i SSEFUNCTION void boxblur (T* src, A* dst, int radx, i for (int i=1; i<=rady; i++) { tempv = tempv + LVFU(temp[i*W+col]); } - _mm_storeu_ps( &dst[0*W+col], tempv / lenv ); + tempv = tempv/lenv; + _mm_storeu_ps( &dst[0*W+col], tempv); for (int row=1; row<=rady; row++) { lenp1v = lenv + onev; - _mm_storeu_ps( &dst[row*W+col], (LVFU(dst[(row-1)*W+col])*lenv + LVFU(temp[(row+rady)*W+col]))/lenp1v); + tempv = (tempv*lenv + LVFU(temp[(row+rady)*W+col]))/lenp1v; + _mm_storeu_ps( &dst[row*W+col], tempv); lenv = lenp1v; } for (int row = rady+1; row < H-rady; row++) { - _mm_storeu_ps( &dst[row*W+col], LVFU(dst[(row-1)*W+col]) +(LVFU(temp[(row+rady)*W+col])-LVFU(temp[(row-rady-1)*W+col]))/lenv ); + tempv = tempv +(LVFU(temp[(row+rady)*W+col])-LVFU(temp[(row-rady-1)*W+col]))/lenv ; + _mm_storeu_ps( &dst[row*W+col], tempv); } for (int row=H-rady; row &curvePoints, bool &opautili) { } } -void NoisCCcurve::Reset() { - lutNoisCCcurve.reset(); +NoiseCurve::NoiseCurve() : sum(0.f) {}; + +void NoiseCurve::Reset() { + lutNoiseCurve.reset(); + sum = 0.f; } -void NoisCCcurve::Set(const Curve *pCurve) { - if (pCurve->isIdentity()) { - lutNoisCCcurve.reset(); // raise this value if the quality suffers from this number of samples +void NoiseCurve::Set(const Curve &pCurve) { + if (pCurve.isIdentity()) { + Reset(); // raise this value if the quality suffers from this number of samples return; } - lutNoisCCcurve(501); // raise this value if the quality suffers from this number of samples - nonzeroc=0.f; + lutNoiseCurve(501); // raise this value if the quality suffers from this number of samples + sum=0.f; for (int i=0; i<501; i++) { - lutNoisCCcurve[i] = pCurve->getVal(double(i)/500.); - if(lutNoisCCcurve[i] < 0.1f) lutNoisCCcurve[i]=0.1f;//avoid 0.f for wavelet : under 0.01f quasi no action for each value - nonzeroc+=lutNoisCCcurve[i];}//minima for Wavelet about 6.f or 7.f quasi no action - //lutNoisCCcurve.dump("NoisCC"); -} -void NoisCCcurve::Set(const std::vector &curvePoints, bool &ccdenoiseutili) { - FlatCurve* tcurve = NULL; - - if (!curvePoints.empty() && curvePoints[0]>FCT_Linear && curvePoints[0]setIdentityValue(0.); + lutNoiseCurve[i] = pCurve.getVal(double(i)/500.); + if(lutNoiseCurve[i] < 0.01f) + lutNoiseCurve[i] = 0.01f;//avoid 0.f for wavelet : under 0.01f quasi no action for each value + sum += lutNoiseCurve[i]; //minima for Wavelet about 6.f or 7.f quasi no action } - if (tcurve) { - Set(tcurve);ccdenoiseutili=true; - delete tcurve; - tcurve = NULL; - } -} - - -void NoisCurve::Reset() { - lutNoisCurve.reset(); -} - -void NoisCurve::Set(const Curve *pCurve) { - if (pCurve->isIdentity()) { - lutNoisCurve.reset(); // raise this value if the quality suffers from this number of samples - return; - } - lutNoisCurve(501); // raise this value if the quality suffers from this number of samples - nonzero=0.f; - for (int i=0; i<501; i++) { - lutNoisCurve[i] = pCurve->getVal(double(i)/500.); - if(lutNoisCurve[i] < 0.01f) lutNoisCurve[i]=0.01f;//avoid 0.f for wavelet : under 0.01f quasi no action for each value - nonzero+=lutNoisCurve[i];}//minima for Wavelet about 6.f or 7.f quasi no action //lutNoisCurve.dump("Nois"); } -void NoisCurve::Set(const std::vector &curvePoints, bool &lldenoiseutili) { - FlatCurve* tcurve = NULL; +void NoiseCurve::Set(const std::vector &curvePoints) { if (!curvePoints.empty() && curvePoints[0]>FCT_Linear && curvePoints[0]setIdentityValue(0.); - } - if (tcurve) { - Set(tcurve);lldenoiseutili=true; - delete tcurve; - tcurve = NULL; + FlatCurve tcurve(curvePoints, false, CURVES_MIN_POLY_POINTS/2); + tcurve.setIdentityValue(0.); + Set(tcurve); + } else { + Reset(); } } + void ColorGradientCurve::Reset() { lut1.reset(); lut2.reset(); diff --git a/rtengine/curves.h b/rtengine/curves.h index 2e88b1712..831af5003 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -372,30 +372,20 @@ class OpacityCurve { operator bool (void) const { return lutOpacityCurve; } }; -class NoisCurve { +class NoiseCurve { + private: + LUTf lutNoiseCurve; // 0xffff range + float sum; + void Set(const Curve &pCurve); + public: - LUTf lutNoisCurve; // 0xffff range - float nonzero; - virtual ~NoisCurve() {}; - + virtual ~NoiseCurve() {}; + NoiseCurve(); void Reset(); - void Set(const Curve *pCurve); - void Set(const std::vector &curvePoints, bool &lldenoiseutili); - - operator bool (void) const { return lutNoisCurve; } -}; - -class NoisCCcurve { - public: - LUTf lutNoisCCcurve; // 0xffff range - float nonzeroc; - virtual ~NoisCCcurve() {}; - - void Reset(); - void Set(const Curve *pCurve); - void Set(const std::vector &curvePoints, bool &ccdenoiseutili); - - operator bool (void) const { return lutNoisCCcurve; } + void Set(const std::vector &curvePoints); + float getSum() const {return sum;} + float operator[](float index) const { return lutNoiseCurve[index]; } + operator bool (void) const { return lutNoiseCurve; } }; class ColorGradientCurve { diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 2b9359d05..e89ddb3dc 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -162,15 +162,14 @@ void Crop::update (int todo) { int skipP=1;//force Skip for noise evaluation Imagefloat *calclum = NULL;//for Luminance denoise curve - NoisCurve dnNoisCurve; - NoisCCcurve dnNoisCCcurve; - bool lldenoiseutili=false; - bool ccdenoiseutili=false; + NoiseCurve noiseLCurve; + NoiseCurve noiseCCurve; float autoNR = (float) settings->nrauto;// float autoNRmax = (float) settings->nrautomax;// float autohigh = (float) settings->nrhigh;// - params.dirpyrDenoise.getCurves(dnNoisCurve, dnNoisCCcurve, lldenoiseutili, ccdenoiseutili); + DirPyrDenoiseParams denoiseParams = params.dirpyrDenoise; + denoiseParams.getCurves(noiseLCurve, noiseCCurve); int tilesize; int overlap; @@ -205,20 +204,20 @@ void Crop::update (int todo) { for(int cX=0;cXleveldnautsimpl==1){ - if(params.dirpyrDenoise.Cmethod=="MAN" || params.dirpyrDenoise.Cmethod=="PON" ) { + if(denoiseParams.Cmethod=="MAN" || denoiseParams.Cmethod=="PON" ) { PreviewProps pp (trafx, trafy, trafw*skip, trafh*skip, skip); parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.toneCurve, params.icm, params.raw ); } } else { - if(params.dirpyrDenoise.C2method=="MANU") { + if(denoiseParams.C2method=="MANU") { PreviewProps pp (trafx, trafy, trafw*skip, trafh*skip, skip); parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.toneCurve, params.icm, params.raw ); } } /* - if(params.dirpyrDenoise.Cmethod=="PON") { + if(denoiseParams.Cmethod=="PON") { MyTime t1dce,t2dce; t1dce.set(); @@ -228,7 +227,7 @@ void Crop::update (int todo) { origCropPart = new Imagefloat (crW, crH);//allocate memory int skipP=1; - if (skip==1 && params.dirpyrDenoise.enabled) {//evaluate Noise + if (skip==1 && denoiseParams.enabled) {//evaluate Noise for(int wcr=0;wcripf.RGB_denoise_info(provi, provi, provicalc, parent->imgsrc->isRAW(), params.dirpyrDenoise, params.defringe, parent->imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve,lldenoiseutili, dnNoisCCcurve,ccdenoiseutili, chaut, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L); + parent->ipf.RGB_denoise_info(provi, provi, provicalc, parent->imgsrc->isRAW(), denoiseParams, params.defringe, parent->imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve,lldenoiseutili, noiseCCurve,ccdenoiseutili, chaut, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L); //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); if(maxredaut > maxblueaut) { maxr=(maxredaut-chaut)/(autoNRmax/2.f); @@ -282,11 +281,11 @@ void Crop::update (int todo) { } */ - if((settings->leveldnautsimpl==1 && params.dirpyrDenoise.Cmethod=="PRE") || (settings->leveldnautsimpl==0 && params.dirpyrDenoise.C2method=="PREV")) { + if((settings->leveldnautsimpl==1 && denoiseParams.Cmethod=="PRE") || (settings->leveldnautsimpl==0 && denoiseParams.C2method=="PREV")) { PreviewProps pp (trafx, trafy, trafw*skip, trafh*skip, skip); parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.toneCurve, params.icm, params.raw ); - if((!isDetailWindow) && parent->adnListener && skip==1 && params.dirpyrDenoise.enabled) { + if((!isDetailWindow) && parent->adnListener && skip==1 && denoiseParams.enabled) { float lowdenoise=1.f; int levaut=settings->leveldnaut; if(levaut==1) //Standard @@ -312,7 +311,7 @@ void Crop::update (int todo) { if(settings->leveldnv ==3) {crW=tileWskip-10;crH=tileHskip-10;} - if (skip==1 && params.dirpyrDenoise.enabled) { + if (skip==1 && denoiseParams.enabled) { float adjustr=1.f; if (params.icm.working=="ProPhoto") {adjustr =1.f;} else if (params.icm.working=="Adobe RGB") {adjustr = 1.f/1.3f;} @@ -349,9 +348,9 @@ void Crop::update (int todo) { chaut=0.f;redaut=0.f; blueaut=0.f; maxredaut=0.f; maxblueaut=0.f;minredaut=0.f; minblueaut=0.f; 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(denoiseParams, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope); - parent->ipf.RGB_denoise_info(provi, provi, provicalc, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, params.defringe, parent->imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve,lldenoiseutili, dnNoisCCcurve,ccdenoiseutili, chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut,nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); + parent->ipf.RGB_denoise_info(provi, provi, provicalc, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, denoiseParams, parent->imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut,nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); // 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; @@ -377,17 +376,17 @@ void Crop::update (int todo) { }//maxb mxr - empirical evaluation red / blue - 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); + denoiseParams.chroma=chaut/(autoNR*multip*adjustr*lowdenoise); + denoiseParams.redchro=maxr; + denoiseParams.bluechro=maxb; + parent->adnListener->chromaChanged(denoiseParams.chroma, denoiseParams.redchro, denoiseParams.bluechro); delete provi; } } } - if((settings->leveldnautsimpl==1 && params.dirpyrDenoise.Cmethod=="AUT") || (settings->leveldnautsimpl==0 && params.dirpyrDenoise.C2method=="AUTO")) { + if((settings->leveldnautsimpl==1 && denoiseParams.Cmethod=="AUT") || (settings->leveldnautsimpl==0 && denoiseParams.C2method=="AUTO")) { MyTime t1aue,t2aue; t1aue.set(); @@ -405,10 +404,10 @@ void Crop::update (int todo) { lowdenoise=0.7f; - if (skip==1 && params.dirpyrDenoise.enabled) {//evaluate Noise + if (skip==1 && denoiseParams.enabled) {//evaluate Noise 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(denoiseParams, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope); int Nb[9]; #pragma omp parallel @@ -443,7 +442,7 @@ void Crop::update (int todo) { float chaut=0.f, redaut=0.f, blueaut=0.f, maxredaut=0.f, maxblueaut=0.f, minredaut=0.f, minblueaut=0.f, nresi=0.f, highresi=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; // chaut=0.f;redaut=0.f; blueaut=0.f; maxredaut=0.f; maxblueaut=0.f; chromina=0.f; sigma=0.f; - parent->ipf.RGB_denoise_info(provi, provi, provicalc, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, params.defringe, parent->imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve,lldenoiseutili, dnNoisCCcurve,ccdenoiseutili, chaut, nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); + parent->ipf.RGB_denoise_info(provi, provi, provicalc, parent->imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, denoiseParams, parent->imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, chaut, nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, 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); @@ -553,11 +552,11 @@ void Crop::update (int todo) { } // printf("DCROP skip=%d cha=%f red=%f bl=%f \n",skip, chM,maxr,maxb); - params.dirpyrDenoise.chroma=chM/(autoNR*multip*adjustr); - params.dirpyrDenoise.redchro=maxr; - params.dirpyrDenoise.bluechro=maxb; + denoiseParams.chroma=chM/(autoNR*multip*adjustr); + denoiseParams.redchro=maxr; + denoiseParams.bluechro=maxb; if(parent->adnListener) { - parent->adnListener->chromaChanged(params.dirpyrDenoise.chroma, params.dirpyrDenoise.redchro, params.dirpyrDenoise.bluechro); + parent->adnListener->chromaChanged(denoiseParams.chroma, denoiseParams.redchro, denoiseParams.bluechro); } } if (settings->verbose) { @@ -567,22 +566,23 @@ void Crop::update (int todo) { //end evaluate noise } - // 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 + // if(denoiseParams.Cmethod=="AUT" || denoiseParams.Cmethod=="PON") {//reinit origCrop after Auto + if((settings->leveldnautsimpl==1 && denoiseParams.Cmethod=="AUT") || (settings->leveldnautsimpl==0 && denoiseParams.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.icm, params.raw ); } - if(params.dirpyrDenoise.Lmethod=="CUR") params.dirpyrDenoise.luma=0.5f;//very small value to init process - select curve or slider - if(params.dirpyrDenoise.Lmethod=="SLI") lldenoiseutili=false; - - if(!lldenoiseutili) - dnNoisCurve.Reset(); - if(!ccdenoiseutili) - dnNoisCCcurve.Reset(); + if(denoiseParams.Lmethod == "CUR") { + if(noiseLCurve) + denoiseParams.luma = 0.5f; //very small value to init process - select curve or slider + else + denoiseParams.luma = 0.0f; + } else if(denoiseParams.Lmethod == "SLI") + noiseLCurve.Reset(); - if((lldenoiseutili || ccdenoiseutili ) && skip==1 && params.dirpyrDenoise.enabled) {//only allocate memory if enabled and skip + + if((noiseLCurve || noiseCCurve ) && skip==1 && denoiseParams.enabled) {//only allocate memory if enabled and skip calclum = new Imagefloat (cropw, croph);//for Luminance denoise curve if(origCrop != calclum) origCrop->copyData(calclum); @@ -592,19 +592,19 @@ void Crop::update (int todo) { if(skip!=1) if(parent->adnListener) parent->adnListener->noiseChanged(0.f, 0.f); if (todo & M_LINDENOISE) { - if (skip==1 && params.dirpyrDenoise.enabled) { + if (skip==1 && denoiseParams.enabled) { int kall=0; float chaut, redaut, blueaut, maxredaut, maxblueaut, nresi, highresi; - parent->ipf.RGB_denoise(kall, origCrop, origCrop, calclum, ch_M, max_r, max_b, parent->imgsrc->isRAW(), /*Roffset,*/ params.dirpyrDenoise, params.defringe, parent->imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve,lldenoiseutili, dnNoisCCcurve,ccdenoiseutili, chaut, redaut, blueaut, maxredaut, maxblueaut, nresi, highresi); + parent->ipf.RGB_denoise(kall, origCrop, origCrop, calclum, ch_M, max_r, max_b, parent->imgsrc->isRAW(), /*Roffset,*/ denoiseParams, parent->imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, chaut, redaut, blueaut, maxredaut, maxblueaut, nresi, highresi); if(parent->adnListener) parent->adnListener->noiseChanged(nresi, highresi); if(settings->leveldnautsimpl==1) { - if((params.dirpyrDenoise.Cmethod=="AUT" || params.dirpyrDenoise.Cmethod=="PRE") && (parent->adnListener)) // force display value of sliders - parent->adnListener->chromaChanged(params.dirpyrDenoise.chroma, params.dirpyrDenoise.redchro, params.dirpyrDenoise.bluechro); + if((denoiseParams.Cmethod=="AUT" || denoiseParams.Cmethod=="PRE") && (parent->adnListener)) // force display value of sliders + parent->adnListener->chromaChanged(denoiseParams.chroma, denoiseParams.redchro, denoiseParams.bluechro); } else { - if((params.dirpyrDenoise.C2method=="AUTO" || params.dirpyrDenoise.C2method=="PREV") && (parent->adnListener)) // force display value of sliders - parent->adnListener->chromaChanged(params.dirpyrDenoise.chroma, params.dirpyrDenoise.redchro, params.dirpyrDenoise.bluechro); + if((denoiseParams.C2method=="AUTO" || denoiseParams.C2method=="PREV") && (parent->adnListener)) // force display value of sliders + parent->adnListener->chromaChanged(denoiseParams.chroma, denoiseParams.redchro, denoiseParams.bluechro); } diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index e43fcbaaf..4ee5b9dfe 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -85,7 +85,7 @@ ImProcCoordinator::ImProcCoordinator () pW(-1), pH(-1), plistener(NULL), imageListener(NULL), aeListener(NULL), hListener(NULL),acListener(NULL), abwListener(NULL),actListener(NULL),adnListener(NULL), - resultValid(false), changeSinceLast(0), updaterRunning(false), destroying(false),utili(false),autili(false),lldenoiseutili(false), opautili(false),ccdenoiseutili(false), + resultValid(false), changeSinceLast(0), updaterRunning(false), destroying(false),utili(false),autili(false),opautili(false), butili(false),ccutili(false),cclutili(false),clcutili(false),fullw(1),fullh(1) {} @@ -271,9 +271,9 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) { //ColorTemp::CAT02 (orig_prev, ¶ms) ; Imagefloat *calclum = NULL ; - lldenoiseutili=false; - ccdenoiseutili=false; - params.dirpyrDenoise.getCurves(dnNoisCurve,dnNoisCCcurve,lldenoiseutili, ccdenoiseutili); + DirPyrDenoiseParams denoiseParams = params.dirpyrDenoise; + + denoiseParams.getCurves(noiseLCurve,noiseCCurve); int nbw=6;//nb tile W int nbh=4;// @@ -281,15 +281,16 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) { float *max_r = new float [nbw*nbh];//allocate memory float *max_b = new float [nbw*nbh];//allocate memory - if(params.dirpyrDenoise.Lmethod=="CUR") params.dirpyrDenoise.luma=0.5f; - if(params.dirpyrDenoise.Lmethod=="SLI") lldenoiseutili=false; + if(denoiseParams.Lmethod == "CUR") { + if(noiseLCurve) + denoiseParams.luma = 0.5f; + else + denoiseParams.luma = 0.0f; + } else if(denoiseParams.Lmethod == "SLI") + noiseLCurve.Reset(); - if(!lldenoiseutili) - dnNoisCurve.Reset(); - if(!ccdenoiseutili) - dnNoisCCcurve.Reset(); - if((lldenoiseutili || ccdenoiseutili) && params.dirpyrDenoise.enabled && (scale==1)){//only allocate memory if enabled and scale=1 + if((noiseLCurve || noiseCCurve) && denoiseParams.enabled && (scale==1)){//only allocate memory if enabled and scale=1 calclum = new Imagefloat (pW, pH);//for Luminance denoise curve if(orig_prev != calclum) orig_prev->copyData(calclum); @@ -298,10 +299,10 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) { } //always enabled to calculated auto Chroma if (todo & M_LINDENOISE) { - if (params.dirpyrDenoise.enabled && (scale==1)) { + if (denoiseParams.enabled && (scale==1)) { printf("IMPROC\n"); int kall=1; - ipf.RGB_denoise(kall, orig_prev, orig_prev, calclum, ch_M, max_r, max_b, imgsrc->isRAW(), params.dirpyrDenoise, params.defringe, imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve, lldenoiseutili, dnNoisCCcurve,ccdenoiseutili, chaut, redaut, blueaut, maxredaut, maxblueaut, nresi, highresi); + ipf.RGB_denoise(kall, orig_prev, orig_prev, calclum, ch_M, max_r, max_b, imgsrc->isRAW(), denoiseParams, imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, chaut, redaut, blueaut, maxredaut, maxblueaut, nresi, highresi); } } // delete calclum; diff --git a/rtengine/improccoordinator.h b/rtengine/improccoordinator.h index 95d8b35e0..958df0277 100644 --- a/rtengine/improccoordinator.h +++ b/rtengine/improccoordinator.h @@ -120,15 +120,13 @@ class ImProcCoordinator : public StagedImageProcessor { bool ccutili; bool cclutili; bool clcutili; - bool lldenoiseutili; - bool ccdenoiseutili; bool opautili; ToneCurve customToneCurve1; ToneCurve customToneCurve2; ColorGradientCurve ctColorCurve; OpacityCurve ctOpacityCurve; - NoisCurve dnNoisCurve; - NoisCCcurve dnNoisCCcurve; + NoiseCurve noiseLCurve; + NoiseCurve noiseCCurve; ColorAppearance customColCurve1; ColorAppearance customColCurve2; ColorAppearance customColCurve3; diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index a35262e4a..e287c3eb8 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -175,9 +175,6 @@ class ImProcFunctions { bool iGamma; // true if inverse gamma has to be applied in rgbProc double g; static LUTf cachef; - float noisered; - float noiseblue; - bool perf; float Qhigh; double lumimul[3]; // float chau; @@ -278,9 +275,9 @@ class ImProcFunctions { //void output_tile_row (float *Lbloxrow, float ** Lhipassdn, float ** tilemask, int height, int width, int top, int blkrad ); 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 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 procparams::DefringeParams & defringe, const double expcomp,const NoisCurve & ctNoisCurve , bool lldenoiseutili, const NoisCCcurve & ctNoisCCcurve , bool ccdenoiseutili, float &chaut, float &redaut, float &blueaut, float &maxredaut, float & maxblueaut, float &nresi, float &highresi); + 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 & ctNoisCurve , const NoiseCurve & ctNoisCCcurve , float &chaut, float &redaut, float &blueaut, float &maxredaut, float & maxblueaut, float &nresi, float &highresi); void RGB_denoise_infoGamCurve(const procparams::DirPyrDenoiseParams & dnparams, bool isRAW, LUTf &gamcurve, float &gam, float &gamthresh, float &gamslope); - void RGB_denoise_info(Imagefloat * src, Imagefloat * dst, Imagefloat * calclum, bool isRAW, LUTf &gamcurve, float gam, float gamthresh, float gamslope, const procparams::DirPyrDenoiseParams & dnparams, const procparams::DefringeParams & defringe, const double expcomp,const NoisCurve & ctNoisCurve , bool lldenoiseutili, const NoisCCcurve & ctNoisCCcurve , bool ccdenoiseutili, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float & maxblueaut, float &minredaut, float & minblueaut,float &nresi, float &highresi, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel,float &skinc, float &nsknc); + void RGB_denoise_info(Imagefloat * src, Imagefloat * dst, Imagefloat * calclum, bool isRAW, LUTf &gamcurve, float gam, float gamthresh, float gamslope, const procparams::DirPyrDenoiseParams & dnparams, const double expcomp,const NoiseCurve & ctNoisCurve, const NoiseCurve & ctNoisCCcurve, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float & maxblueaut, float &minredaut, float & minblueaut,float &nresi, float &highresi, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel,float &skinc, float &nsknc); void RGBtile_denoise (float * fLblox, int hblproc, float noisevar_L, float * nbrwt, float * blurbuffer ); //for DCT void RGBoutput_tile_row (float *Lbloxrow, float ** Ldetail, float ** tilemask_out, int height, int width, int top ); //void WaveletDenoise(cplx_wavelet_decomposition &DualTreeCoeffs, float noisevar ); @@ -288,13 +285,13 @@ class ImProcFunctions { // void WaveletDenoiseAll(wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_a, // wavelet_decomposition &WaveletCoeffs_b, float noisevar_L, float noisevar_ab, wavelet_decomposition &wch, NoiImage * noi ); void WaveletDenoiseAll(wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_a, - wavelet_decomposition &WaveletCoeffs_b, float noisevar_L, float **noisevarlum, float **noisevarchrom, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb, LabImage * noi, bool lldenoiseutili, const NoisCurve & dnNoisCurve, const NoisCCcurve & dnNoisCCcurve, bool ccdenoiseutili, float &chaut, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, int schoice, bool autoch); + wavelet_decomposition &WaveletCoeffs_b, float noisevar_L, float **noisevarlum, float **noisevarchrom, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb, LabImage * noi, const NoiseCurve & dnNoisCurve, const NoiseCurve & dnNoisCCcurve, float &chaut, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, int schoice, bool autoch); void WaveletDenoiseAll_info(wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_a, - wavelet_decomposition &WaveletCoeffs_b, float noisevar_L, float **noisevarlum, float **noisevarchrom, float **noisevarhue, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb, LabImage * noi, bool lldenoiseutili, const NoisCurve & dnNoisCurve, const NoisCCcurve & dnNoisCCcurve, bool ccdenoiseutili, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut,float &minredaut, float & minblueaut, int schoice, bool autoch, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel,float &skinc, float &nsknc, + wavelet_decomposition &WaveletCoeffs_b, float noisevar_L, float **noisevarlum, float **noisevarchrom, float **noisevarhue, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb, LabImage * noi, const NoiseCurve & dnNoisCurve, const NoiseCurve & dnNoisCCcurve, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut,float &minredaut, float & minblueaut, int schoice, bool autoch, 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); void WaveletDenoiseAll_BiShrink(wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_a, - wavelet_decomposition &WaveletCoeffs_b, float noisevar_L, float **noisevarlum, float **noisevarchrom, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb, LabImage * noi, bool lldenoiseutili, const NoisCurve & dnNoisCurve, const NoisCCcurve & dnNoisCCcurve, bool ccdenoiseutili, float &chaut, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, int schoice, bool autoch); + wavelet_decomposition &WaveletCoeffs_b, float noisevar_L, float **noisevarlum, float **noisevarchrom, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb, LabImage * noi, const NoiseCurve & dnNoisCurve, const NoiseCurve & dnNoisCCcurve, float &chaut, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, int schoice, bool autoch); //void BiShrink(float * ReCoeffs, float * ImCoeffs, float * ReParents, float * ImParents, // int W, int H, int level, int padding, float noisevar); //void Shrink(float ** WavCoeffs, int W, int H, int level, float noisevar); @@ -302,9 +299,9 @@ class ImProcFunctions { // int W_L, int H_L, int W_ab, int H_ab, int W_h, int H_h, int skip_L, int skip_ab, int skip_h, float noisevar_L, float noisevar_ab, float **WavCoeffs_h, LabImage * noi); void ShrinkAll(float ** WavCoeffs_L, float ** WavCoeffs_a, float ** WavCoeffs_b, int level, - int W_L, int H_L, int W_ab, int H_ab, int skip_L, int skip_ab, float noisevar_L, float **noisevarlum, float **noisevarchrom, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb,LabImage * noi, bool lldenoiseutili, const NoisCurve & dnNoisCurve, const NoisCCcurve & dnNoisCCcurve, bool ccdenoiseutili, float &chaut, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, int callby, bool autoch, float * madaa = NULL, float * madab = NULL, float * madaL = NULL, bool madCalculated= false); + int W_L, int H_L, int W_ab, int H_ab, int skip_L, int skip_ab, float noisevar_L, float **noisevarlum, float **noisevarchrom, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb,LabImage * noi, const NoiseCurve & dnNoisCurve, const NoiseCurve & dnNoisCCcurve, float &chaut, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, int callby, bool autoch, float * madaa = NULL, float * madab = NULL, float * madaL = NULL, bool madCalculated= false); void ShrinkAll_info(float ** WavCoeffs_L, float ** WavCoeffs_a, float ** WavCoeffs_b, int level, - int W_L, int H_L, int W_ab, int H_ab, int skip_L, int skip_ab, float noisevar_L, float **noisevarlum, float **noisevarchrom, float **noisevarhue, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb,LabImage * noi, bool lldenoiseutili, const NoisCurve & dnNoisCurve, const NoisCCcurve & dnNoisCCcurve, bool ccdenoiseutili, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &minredaut, float &minblueaut, int callby, bool autoch, int schoice, int lvl, float &chromina, float &sigma, float &lumema, float &sigma_L, float &redyel,float &skinc, float &nsknc, + int W_L, int H_L, int W_ab, int H_ab, int skip_L, int skip_ab, float noisevar_L, float **noisevarlum, float **noisevarchrom, float **noisevarhue, int width, int height, float *mad_LL, float *mad_aa, float *mad_bb, float noisevar_abr, float noisevar_abb,LabImage * noi, const NoiseCurve & dnNoisCurve, const NoiseCurve & dnNoisCCcurve, float &chaut, int &Nb, float &redaut, float &blueaut, float &maxredaut, float &maxblueaut, float &minredaut, float &minblueaut, int callby, bool autoch, 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, float * madaa = NULL, float * madab = NULL, float * madaL = NULL, bool madCalculated= false); void Noise_residual(wavelet_decomposition &WaveletCoeffs_L, wavelet_decomposition &WaveletCoeffs_a, wavelet_decomposition &WaveletCoeffs_b, int width, int height, float &chresid, float &chmaxredresid,float &chmaxblueresid, float &chresidred, float & chresidblue, float resid, float residblue, float residred, float maxredresid, float maxblueresid, float nbresid); 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); diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 9e8fbf335..315775b1a 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -467,14 +467,9 @@ void DirPyrDenoiseParams::setDefault() { gamma = 1.7; } -void DirPyrDenoiseParams::getCurves(NoisCurve &lcurveLUT, NoisCCcurve &cccurveLUT, bool &lldenoiseutili, bool &ccdenoiseutili) const { - std::vector llCurve; - llCurve = this->lcurve; - lcurveLUT.Set(llCurve, lldenoiseutili); - std::vector ccCurve; - ccCurve = this->cccurve; - cccurveLUT.Set(ccCurve, ccdenoiseutili); - +void DirPyrDenoiseParams::getCurves(NoiseCurve &lCurve, NoiseCurve &cCurve) const { + lCurve.Set(this->lcurve); + cCurve.Set(this->cccurve); } diff --git a/rtengine/procparams.h b/rtengine/procparams.h index c42077091..79dd5f0e6 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -32,8 +32,7 @@ namespace rtengine { class ColorGradientCurve; class OpacityCurve; -class NoisCurve; -class NoisCCcurve; +class NoiseCurve; namespace procparams { @@ -570,8 +569,7 @@ class DirPyrDenoiseParams { DirPyrDenoiseParams (); void setDefault(); // SHOULD BE GENERALIZED TO ALL CLASSES! - // void getCurves(NoisCurve &lcurveLUT, bool &lldenoiseutili) const; - void getCurves(NoisCurve &lcurveLUT,NoisCCcurve &cccurveLUT,bool &lldenoiseutili,bool &ccdenoiseutili ) const; + void getCurves(NoiseCurve &lCurve, NoiseCurve &cCurve) const; static void getDefaultNoisCurve(std::vector &curve); static void getDefaultCCCurve(std::vector &curve); diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index e6068de85..d07ef7749 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -125,12 +125,10 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p currWB.update(rm, gm, bm, params.wb.equal); } - NoisCurve dnNoisCurve; - bool lldenoiseutili=false; - bool ccdenoiseutili=false; - NoisCCcurve dnNoisCCcurve; + NoiseCurve noiseLCurve; + NoiseCurve noiseCCurve; Imagefloat *calclum = NULL ; - params.dirpyrDenoise.getCurves(dnNoisCurve, dnNoisCCcurve, lldenoiseutili, ccdenoiseutili); + params.dirpyrDenoise.getCurves(noiseLCurve, noiseCCurve); float autoNR = (float) settings->nrauto;// float autoNRmax = (float) settings->nrautomax;// float autohigh = (float) settings->nrhigh;// @@ -218,7 +216,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p float chaut, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc; int Nb; chaut=0.f;redaut=0.f; blueaut=0.f; maxredaut=0.f; maxblueaut=0.f;chromina=0.f; sigma=0.f; - ipf.RGB_denoise_info(provi, provi, provicalc, imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, params.defringe, imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve,lldenoiseutili, dnNoisCCcurve,ccdenoiseutili, chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); + ipf.RGB_denoise_info(provi, provi, provicalc, imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); float multip=1.f; float adjustr=1.f; if (params.icm.working=="ProPhoto") {adjustr =1.f;}// @@ -329,10 +327,10 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p if((settings->leveldnautsimpl==1 && params.dirpyrDenoise.Cmethod=="AUT") || (settings->leveldnautsimpl==0 && params.dirpyrDenoise.C2method=="AUTO")) { MyTime t1aue,t2aue; t1aue.set(); - int crW,crH; + int crW,crH; if(settings->leveldnv ==0) {crW=100;crH=100;} if(settings->leveldnv ==1) {crW=250;crH=250;} - if(settings->leveldnv ==2) {crW=int(tileWskip/2);crH=int(tileHskip/2);} + if(settings->leveldnv ==2) {crW=int(tileWskip/2);crH=int(tileHskip/2);} // if(settings->leveldnv ==2) {crW=int(tileWskip/2);crH=int(1.15f*(tileWskip/2));}//adapted to scale of preview if(settings->leveldnv ==3) {crW=tileWskip-10;crH=tileHskip-10;} @@ -346,58 +344,48 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p float gam, gamthresh, gamslope; ipf.RGB_denoise_infoGamCurve(params.dirpyrDenoise, imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope); int Nb[9]; - #pragma omp parallel - { + int coordW[3];//coordonate of part of image to mesure noise + int coordH[3]; + int begW=50; + int begH=50; + coordW[0]=begW;coordW[1]=fw/2-crW/2;coordW[2]=fw-crW-begW; + coordH[0]=begH;coordH[1]=fh/2-crH/2;coordH[2]=fh-crH-begH; + #pragma omp parallel + { Imagefloat *origCropPart;//init auto noise origCropPart = new Imagefloat (crW, crH);//allocate memory Imagefloat *provi; Imagefloat *provicalc; provi = new Imagefloat (crW, crH); provicalc = new Imagefloat (crW, crH); - int coordW[3];//coordonate of part of image to mesure noise - int coordH[3]; - int begW=50; - int begH=50; - coordW[0]=begW;coordW[1]=fw/2-crW/2;coordW[2]=fw-crW-begW; - coordH[0]=begH;coordH[1]=fh/2-crH/2;coordH[2]=fh-crH-begH; #pragma omp for schedule(dynamic) collapse(2) nowait for(int wcr=0;wcr<=2;wcr++) { for(int hcr=0;hcr<=2;hcr++) { - - PreviewProps ppP (coordW[wcr] , coordH[hcr], crW, crH, 1); - - imgsrc->getImage (currWB, tr, origCropPart, ppP, params.toneCurve, params.icm, params.raw); - - if(origCropPart != provi) - origCropPart->copyData(provi); - if(origCropPart != provicalc) - origCropPart->copyData(provicalc); - imgsrc->convertColorSpace(provicalc, params.icm, currWB, params.raw);//for denoise luminance curve - float maxr=0.f; - float maxb=0.f; - float pondcorrec=1.0f; - int nb = 0; - float chaut=0.f, redaut=0.f, blueaut=0.f, maxredaut=0.f, maxblueaut=0.f, minredaut=0.f, minblueaut=0.f, nresi=0.f, highresi=0.f, chromina=0.f, sigma=0.f, lumema=0.f, sigma_L=0.f, redyel=0.f, skinc=0.f, nsknc=0.f; - ipf.RGB_denoise_info(provi, provi, provicalc, imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise,params.defringe, imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve,lldenoiseutili, dnNoisCCcurve,ccdenoiseutili, chaut, nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); - - Nb[hcr*3 + wcr] = nb; - ch_M[hcr*3 + wcr]=pondcorrec*chaut; - max_r[hcr*3 + wcr]=pondcorrec*maxredaut; - max_b[hcr*3 + wcr]=pondcorrec*maxblueaut; - min_r[hcr*3 + wcr]=pondcorrec*minredaut; - min_b[hcr*3 + wcr]=pondcorrec*minblueaut; - lumL[hcr*3 + wcr]=lumema; - chromC[hcr*3 + wcr]=chromina; - ry[hcr*3 + wcr]=redyel; - sk[hcr*3 + wcr]=skinc; - pcsk[hcr*3 + wcr]=nsknc; - + PreviewProps ppP (coordW[wcr] , coordH[hcr], crW, crH, 1); + imgsrc->getImage (currWB, tr, origCropPart, ppP, params.toneCurve, params.icm, params.raw); + origCropPart->copyData(provi); + origCropPart->copyData(provicalc); + imgsrc->convertColorSpace(provicalc, params.icm, currWB, params.raw);//for denoise luminance curve + int nb = 0; + float chaut=0.f, redaut=0.f, blueaut=0.f, maxredaut=0.f, maxblueaut=0.f, minredaut=0.f, minblueaut=0.f, nresi=0.f, highresi=0.f, chromina=0.f, sigma=0.f, lumema=0.f, sigma_L=0.f, redyel=0.f, skinc=0.f, nsknc=0.f; + ipf.RGB_denoise_info(provi, provi, provicalc, imgsrc->isRAW(), gamcurve, gam, gamthresh, gamslope, params.dirpyrDenoise, imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, chaut, nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc); + Nb[hcr*3 + wcr] = nb; + ch_M[hcr*3 + wcr] = chaut; + max_r[hcr*3 + wcr] = maxredaut; + max_b[hcr*3 + wcr] = maxblueaut; + min_r[hcr*3 + wcr] = minredaut; + min_b[hcr*3 + wcr] = minblueaut; + lumL[hcr*3 + wcr] = lumema; + chromC[hcr*3 + wcr] = chromina; + ry[hcr*3 + wcr] = redyel; + sk[hcr*3 + wcr] = skinc; + pcsk[hcr*3 + wcr] = nsknc; } } - delete provicalc; - delete provi; - delete origCropPart; + delete provicalc; + delete provi; + delete origCropPart; } float chM=0.f; float MaxR=0.f; @@ -406,11 +394,11 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p float MinB=100000000.f; float maxr=0.f; float maxb=0.f; - float multip=1.f; + float multip=1.f; float adjustr=1.f; float Max_R[9]={0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f}; float Max_B[9]={0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f}; - float Min_R[9]; + float Min_R[9]; float Min_B[9]; float MaxRMoy=0.f; float MaxBMoy=0.f; @@ -428,19 +416,16 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p if(!imgsrc->isRAW()) multip=2.f;//take into account gamma for TIF / JPG approximate value...not good fot gamma=1 float maxmax; - float minmin; float delta[9]; int mode=1; int lissage=settings->leveldnliss; - float redyel, skinc, nsknc; for(int k=0;k<9;k++) { - maxmax=max(max_r[k],max_b[k]); - ipf.calcautodn_info (ch_M[k], delta[k], Nb[k], levaut, maxmax, lumL[k], chromC[k], mode, lissage,ry[k], sk[k], pcsk[k] ); + maxmax = max(max_r[k],max_b[k]); + ipf.calcautodn_info (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]); } for(int k=0;k<9;k++) { if(max_r[k] > max_b[k]) { - minmin=min(min_r[k],min_b[k]); //printf("R delta=%f koef=%f\n",delta[k],autoNRmax*multip*adjustr*lowdenoise); Max_R[k]=(delta[k])/((autoNRmax*multip*adjustr*lowdenoise)/2.f); Min_B[k]= -(ch_M[k]-min_b[k])/(autoNRmax*multip*adjustr*lowdenoise); @@ -448,7 +433,6 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p Min_R[k]=0.f; } else { - minmin=min(min_r[k],min_b[k]); //printf("B delta=%f koef=%f\n",delta[k],autoNRmax*multip*adjustr*lowdenoise); Max_B[k]=(delta[k])/((autoNRmax*multip*adjustr*lowdenoise)/2.f); Min_R[k]=- (ch_M[k]-min_r[k]) / (autoNRmax*multip*adjustr*lowdenoise); @@ -536,32 +520,36 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p // perform luma/chroma denoise // CieImage *cieView; -// NoisCurve dnNoisCurve; +// NoisCurve noiseLCurve; // bool lldenoiseutili=false; // Imagefloat *calclum ; -// params.dirpyrDenoise.getCurves(dnNoisCurve, lldenoiseutili); +// params.dirpyrDenoise.getCurves(noiseLCurve, lldenoiseutili); // if (params.dirpyrDenoise.enabled && lldenoiseutili) { - if(params.dirpyrDenoise.Lmethod=="CUR") params.dirpyrDenoise.luma=0.5f; - if(params.dirpyrDenoise.Lmethod=="SLI") lldenoiseutili=false; - if(!lldenoiseutili) - dnNoisCurve.Reset(); - if(!ccdenoiseutili) - dnNoisCCcurve.Reset(); - if (params.dirpyrDenoise.enabled && (lldenoiseutili || ccdenoiseutili )) { + DirPyrDenoiseParams denoiseParams = params.dirpyrDenoise; // make a copy because we cheat here + + if(denoiseParams.Lmethod == "CUR") { + if(noiseLCurve) + denoiseParams.luma = 0.5f; + else + denoiseParams.luma = 0.0f; + } else if(denoiseParams.Lmethod=="SLI") + noiseLCurve.Reset(); + + if (denoiseParams.enabled && (noiseLCurve || noiseCCurve )) { calclum = new Imagefloat (fw, fh);//for luminance denoise curve if(baseImg != calclum) baseImg->copyData(calclum); imgsrc->convertColorSpace(calclum, params.icm, currWB, params.raw); } - if (params.dirpyrDenoise.enabled) { - // CurveFactory::denoiseLL(lldenoiseutili, params.dirpyrDenoise.lcurve, Noisecurve,1); - //params.dirpyrDenoise.getCurves(dnNoisCurve); -// ipf.RGB_denoise(baseImg, baseImg, calclum, imgsrc->isRAW(), params.dirpyrDenoise, params.defringe, imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve, lldenoiseutili); + if (denoiseParams.enabled) { + // CurveFactory::denoiseLL(lldenoiseutili, denoiseParams.lcurve, Noisecurve,1); + //denoiseParams.getCurves(noiseLCurve); +// ipf.RGB_denoise(baseImg, baseImg, calclum, imgsrc->isRAW(), denoiseParams, params.defringe, imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, lldenoiseutili); float chaut, redaut, blueaut, maxredaut, maxblueaut, nresi, highresi, chromina, sigma, lumema, sigma_L, redyel, skinc, nsknc; int kall=2; - ipf.RGB_denoise(kall, baseImg, baseImg, calclum, ch_M, max_r, max_b, imgsrc->isRAW(), params.dirpyrDenoise, params.defringe, imgsrc->getDirPyrDenoiseExpComp(), dnNoisCurve, lldenoiseutili, dnNoisCCcurve,ccdenoiseutili, chaut, redaut, blueaut, maxredaut, maxblueaut, nresi, highresi); + ipf.RGB_denoise(kall, baseImg, baseImg, calclum, ch_M, max_r, max_b, imgsrc->isRAW(), denoiseParams, imgsrc->getDirPyrDenoiseExpComp(), noiseLCurve, noiseCCurve, chaut, redaut, blueaut, maxredaut, maxblueaut, nresi, highresi); } // delete calclum; @@ -695,7 +683,8 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p customToneCurve2.Reset(); ctColorCurve.Reset(); ctOpacityCurve.Reset(); - dnNoisCurve.Reset(); + noiseLCurve.Reset(); + noiseCCurve.Reset(); customToneCurvebw1.Reset(); customToneCurvebw2.Reset();