clean code and test for FFTW

This commit is contained in:
Desmis 2019-12-02 18:34:20 +01:00
parent 10d2c6a2a6
commit 554d43eef9
3 changed files with 28 additions and 37 deletions

View File

@ -2262,7 +2262,7 @@ TP_LOCALLAB_FATLEVEL;Detail levels
TP_LOCALLAB_FATSHFRA;Dynamic Range Compression Mask TP_LOCALLAB_FATSHFRA;Dynamic Range Compression Mask
TP_LOCALLAB_FEATH_TOOLTIP;Gradient width in percent of the Spot diagonal\n.. TP_LOCALLAB_FEATH_TOOLTIP;Gradient width in percent of the Spot diagonal\n..
TP_LOCALLAB_FEATVALUE;Feather gradient TP_LOCALLAB_FEATVALUE;Feather gradient
TP_LOCALLAB_FFTCOL_MASK;FFTW TP_LOCALLAB_FFTCOL_MASK;FFTW (to test ?)
TP_LOCALLAB_FFTW2;Use Fast Fourier Transform (TIF, JPG,..) TP_LOCALLAB_FFTW2;Use Fast Fourier Transform (TIF, JPG,..)
TP_LOCALLAB_FFTW;Use Fast Fourier Transform TP_LOCALLAB_FFTW;Use Fast Fourier Transform
TP_LOCALLAB_GAM;Gamma TP_LOCALLAB_GAM;Gamma

View File

@ -3450,6 +3450,10 @@ void ImProcFunctions::maskcalccol(int call, bool invmask, bool pde, int bfw, int
} }
JaggedArray<float> blendstru(bfw, bfh); JaggedArray<float> blendstru(bfw, bfh);
if (lp.blurcolmask >= 0.25f && strumask == 0.f) {
strumask = 0.1f; // to enable a small mask make FFT good ...why ??
}
if (strumask > 0.f) { if (strumask > 0.f) {
float delstrumask = 4.1f - strumask;//4.1 = 2 * max slider strumask + 0.1 float delstrumask = 4.1f - strumask;//4.1 = 2 * max slider strumask + 0.1
@ -3473,8 +3477,11 @@ void ImProcFunctions::maskcalccol(int call, bool invmask, bool pde, int bfw, int
buildBlendMask(bufcolorig->L, blendblur, bfw, bfh, contra, 1.f); buildBlendMask(bufcolorig->L, blendblur, bfw, bfh, contra, 1.f);
float radblur = 0.002f * rad;//empirical value float radblur = 0.25f + 0.002f * fabs(rad);//empirical value
float rm = radblur / sk; float rm = radblur / sk;
if(lp.fftColorMask) {
if(rm < 1.f) rm = 1.f;
}
if (rm > 0) { if (rm > 0) {
float **mb = blendblur; float **mb = blendblur;
@ -3482,7 +3489,8 @@ void ImProcFunctions::maskcalccol(int call, bool invmask, bool pde, int bfw, int
} }
if (lp.blurcolmask >= 0.25f) { if (lp.blurcolmask >= 0.25f) {
if (!lp.fftColorMask || (lp.fftColorMask && call != 2)) { if (!lp.fftColorMask) { // || (lp.fftColorMask && call != 2)) {
printf("call=%i\n", call);
gaussianBlur(bufcolorig->L, blur, bfw, bfh, lp.blurcolmask / sk); gaussianBlur(bufcolorig->L, blur, bfw, bfh, lp.blurcolmask / sk);
} else { } else {
ImProcFunctions::fftw_convol_blur2(bufcolorig->L, blur, bfw, bfh, lp.blurcolmask / sk, 0, 0); ImProcFunctions::fftw_convol_blur2(bufcolorig->L, blur, bfw, bfh, lp.blurcolmask / sk, 0, 0);
@ -3554,11 +3562,9 @@ void ImProcFunctions::maskcalccol(int call, bool invmask, bool pde, int bfw, int
if (lp.contcolmask > 0.f) { if (lp.contcolmask > 0.f) {
if (lp.blurcolmask >= 0.25f) { if (lp.blurcolmask >= 0.25f) {
// printf("OK 3\n");
float prov = intp(blendstru[ir][jr], bufcolorig->L[ir][jr], max(blur[ir][jr], 0.0f)); float prov = intp(blendstru[ir][jr], bufcolorig->L[ir][jr], max(blur[ir][jr], 0.0f));
kmasblur = bufcolorig->L[ir][jr] - prov ; kmasblur = bufcolorig->L[ir][jr] - prov ;
// printf("OK 4\n");
} }
} }
@ -5989,7 +5995,8 @@ void ImProcFunctions::fftw_convol_blur(float * input, float * output, int bfw, i
out = (float*) fftwf_malloc(sizeof(float) * (bfw * bfh));//allocate real datas for FFT out = (float*) fftwf_malloc(sizeof(float) * (bfw * bfh));//allocate real datas for FFT
if (fftkern == 1) { //allocate memory FFT if kernel fft = 1 if (fftkern == 1) { //allocate memory FFT if kernel fft = 1
kern = new float[bfw * bfh]; // kern = new float[bfw * bfh];
kern = (float*) fftwf_malloc(sizeof(float) * (bfw * bfh));//allocate real datas for FFT
outkern = (float*) fftwf_malloc(sizeof(float) * (bfw * bfh));//allocate real datas for FFT outkern = (float*) fftwf_malloc(sizeof(float) * (bfw * bfh));//allocate real datas for FFT
} }
@ -6050,7 +6057,9 @@ void ImProcFunctions::fftw_convol_blur(float * input, float * output, int bfw, i
} }
fftwf_free(outkern); fftwf_free(outkern);
delete [] kern; fftwf_free(kern);
// delete [] kern;
} else if (fftkern == 0) {//whithout FFT kernel } else if (fftkern == 0) {//whithout FFT kernel
if (algo == 0) { if (algo == 0) {
@ -7984,23 +7993,6 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o
int llColorMask, int llColorMaskinv, int llExpMask, int llExpMaskinv, int llSHMask, int llSHMaskinv, int llvibMask, int llcbMask, int llretiMask, int llsoftMask, int lltmMask, int llblMask, int llColorMask, int llColorMaskinv, int llExpMask, int llExpMaskinv, int llSHMask, int llSHMaskinv, int llvibMask, int llcbMask, int llretiMask, int llsoftMask, int lltmMask, int llblMask,
float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax) float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax)
{ {
/* comment on processus deltaE
* the algo uses 3 different ways to manage deltaE according to the type of intervention
* if we call "applyproc" : the datas produced upstream in bfw, bfh coordinate by the function producing something curves, retinex, exposure, etc.
* direct : in this case we use directly the datas produced upstream by "applyproc", with only a regulation produce for deltaE by reducdE
* direct : we found in this case "applyproc" modify data with low amplitude : BlurNoise, CBDL, Denoise, Sharp, TM
* with first use of "buflight" on which is apply "applyproc", in this case we apply realstrdE = reducdE * buflight with a function of type 328.f * realstrdE
* in this case we found "applyproc" which result in direct use on Luminance : Exposure, Color and Light, Shadows highlight, SoftLight, Local contrast
* with second use of "buflight" on which is apply "applyproc", in this case we apply realstrdE = reducdE * buflight with a function of type fli = (100.f + realstrdE) / 100.f;
* in this case we found "applyproc" which result in large variations of L : Retinex
* if you change you must test before
*/
//general call of others functions : important return hueref, chromaref, lumaref //general call of others functions : important return hueref, chromaref, lumaref
if (params->locallab.enabled) { if (params->locallab.enabled) {
BENCHFUN BENCHFUN
@ -8444,8 +8436,8 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o
#endif #endif
{ {
gaussianBlur(bufmaskblurbl->L, bufmaskorigbl->L, GW, GH, radiusb); gaussianBlur(bufmaskblurbl->L, bufmaskorigbl->L, GW, GH, radiusb);
gaussianBlur(bufmaskblurbl->a, bufmaskorigbl->a, GW, GH, 1.f + (0.05f * lp.radmabl) / sk); gaussianBlur(bufmaskblurbl->a, bufmaskorigbl->a, GW, GH, 1.f + (0.005f * lp.radmabl) / sk);
gaussianBlur(bufmaskblurbl->b, bufmaskorigbl->b, GW, GH, 1.f + (0.05f * lp.radmabl) / sk); gaussianBlur(bufmaskblurbl->b, bufmaskorigbl->b, GW, GH, 1.f + (0.005f * lp.radmabl) / sk);
} }
if (lp.showmaskblmet == 0 || lp.showmaskblmet == 1 || lp.showmaskblmet == 2 || lp.showmaskblmet == 4 || lp.enablMask) { if (lp.showmaskblmet == 0 || lp.showmaskblmet == 1 || lp.showmaskblmet == 2 || lp.showmaskblmet == 4 || lp.enablMask) {
@ -8477,11 +8469,10 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o
int isogr = params->locallab.spots.at(sp).isogr; int isogr = params->locallab.spots.at(sp).isogr;
int strengr = params->locallab.spots.at(sp).strengr; int strengr = params->locallab.spots.at(sp).strengr;
int scalegr = params->locallab.spots.at(sp).scalegr; int scalegr = params->locallab.spots.at(sp).scalegr;
//here no optimization FFTW, complex to do ! only cost time
if (bfw >= mSP && bfh >= mSP) { if (bfw >= mSP && bfh >= mSP) {
// const int GW = transformed->W;
//const int GH = transformed->H;
JaggedArray<float> bufchroi(GW, GH); JaggedArray<float> bufchroi(GW, GH);
std::unique_ptr<LabImage> bufgbi(new LabImage(GW, GH)); std::unique_ptr<LabImage> bufgbi(new LabImage(GW, GH));
JaggedArray<float> bufchro(bfw, bfh); JaggedArray<float> bufchro(bfw, bfh);
@ -9891,7 +9882,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o
int xend = std::min(static_cast<int>(lp.xc + lp.lx) - cx, original->W); int xend = std::min(static_cast<int>(lp.xc + lp.lx) - cx, original->W);
int bfh = yend - ystart; int bfh = yend - ystart;
int bfw = xend - xstart; int bfw = xend - xstart;
//vriable for fast FFTW //variable for fast FFTW
int bfhr = bfh; int bfhr = bfh;
int bfwr = bfw; int bfwr = bfw;
bool reduH = false; bool reduH = false;
@ -9903,8 +9894,8 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o
optfft(N_fftwsize, bfh, bfw, bfhr, bfwr, reduH, reduW, lp, original->H, original->W, xstart, ystart, xend, yend, cx, cy); optfft(N_fftwsize, bfh, bfw, bfhr, bfwr, reduH, reduW, lp, original->H, original->W, xstart, ystart, xend, yend, cx, cy);
} }
std::unique_ptr<LabImage> bufexporig(new LabImage(bfw, bfh)); //buffer for data in zone limit std::unique_ptr<LabImage> bufexporig(new LabImage(bfw, bfh));
std::unique_ptr<LabImage> bufexpfin(new LabImage(bfw, bfh)); //buffer for data in zone limit std::unique_ptr<LabImage> bufexpfin(new LabImage(bfw, bfh));
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for schedule(dynamic,16) #pragma omp parallel for schedule(dynamic,16)
@ -10322,7 +10313,8 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o
} }
} }
} }
/*
//use by old function transit_shapedetect keep in case of
float minL = tmp1->L[0][0] - bufgb->L[0][0]; float minL = tmp1->L[0][0] - bufgb->L[0][0];
float maxL = minL; float maxL = minL;
float minC = sqrt(SQR(tmp1->a[0][0]) + SQR(tmp1->b[0][0])) - sqrt(SQR(bufgb->a[0][0]) + SQR(bufgb->b[0][0])); float minC = sqrt(SQR(tmp1->a[0][0]) + SQR(tmp1->b[0][0])) - sqrt(SQR(bufgb->a[0][0]) + SQR(bufgb->b[0][0]));
@ -10365,7 +10357,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o
bufchro[y][x] /= coefC; bufchro[y][x] /= coefC;
} }
} }
*/
transit_shapedetect2(call, 10, bufgb.get(), tmp1.get(), nullptr, hueref, chromaref, lumaref, sobelref, 0.f, nullptr, lp, original, transformed, cx, cy, sk); transit_shapedetect2(call, 10, bufgb.get(), tmp1.get(), nullptr, hueref, chromaref, lumaref, sobelref, 0.f, nullptr, lp, original, transformed, cx, cy, sk);
// transit_shapedetect(10, tmp1.get(), nullptr, bufchro, false, hueref, chromaref, lumaref, sobelref, 0.f, nullptr, lp, original, transformed, cx, cy, sk); // transit_shapedetect(10, tmp1.get(), nullptr, bufchro, false, hueref, chromaref, lumaref, sobelref, 0.f, nullptr, lp, original, transformed, cx, cy, sk);
@ -10442,7 +10434,6 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o
// } // }
//&& lp.retiena //&& lp.retiena
// if (lp.dehaze > 0 && lp.str < 0.2f && lp.retiena) {
if (lp.dehaze > 0 && lp.retiena) { if (lp.dehaze > 0 && lp.retiena) {
int ystart = std::max(static_cast<int>(lp.yc - lp.lyT) - cy, 0); int ystart = std::max(static_cast<int>(lp.yc - lp.lyT) - cy, 0);
int yend = std::min(static_cast<int>(lp.yc + lp.ly) - cy, original->H); int yend = std::min(static_cast<int>(lp.yc + lp.ly) - cy, original->H);

View File

@ -1274,8 +1274,8 @@ void ImProcFunctions::MSRLocal(int call, int sp, bool fftw, int lum, float** red
kg = 1.f; kg = 1.f;
kr = sigm; kr = sigm;
} }
printf("call=%i\n", call);
if (!fftw || (fftw && call != 2)) { if (!fftw) { // || (fftw && call != 2)) {
if (scale == scal - 1) { if (scale == scal - 1) {
gaussianBlur(src, out, W_L, H_L, kg * RetinexScales[scale], true); gaussianBlur(src, out, W_L, H_L, kg * RetinexScales[scale], true);
} else { // reuse result of last iteration } else { // reuse result of last iteration