diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 7efc47b5b..2038ece9b 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -190,7 +190,8 @@ public: void maskcalccol(bool invmask, bool pde, int bfw, int bfh, int xstart, int ystart, int sk, int cx, int cy, LabImage* bufcolorig, LabImage* bufmaskblurcol, LabImage* originalmaskcol, LabImage* original, /*LabImage * transformed, */int inv, const struct local_params & lp, const LocCCmaskCurve & locccmasCurve, bool & lcmasutili, const LocLLmaskCurve & locllmasCurve, bool & llmasutili, const LocHHmaskCurve & lochhmasCurve, bool &lhmasutili, bool multiThread, bool enaMask, bool showmaske, bool deltaE, bool modmask, bool zero, bool modif, float chrom, float rad, float lap, float gamma, float slope, float blendm); - + void discrete_laplacian_threshold(float * data_out, const float * data_in, size_t nx, size_t ny, float t); + void normalize_mean_dt(float *data, const float *ref, size_t size, float mod); void retinex_pde(float *datain, float * dataout, int bfw, int bfh, float thresh, float multy, float *dE, int show, int dEenable, int normalize); void exposure_pde(float *dataor, float *datain, float * dataout, int bfw, int bfh, float thresh, float mod); diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index e29e77e5e..5b18497f5 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -2447,7 +2447,7 @@ static void showmask(const local_params& lp, int xstart, int ystart, int cx, int } } -static float *discrete_laplacian_threshold(float * data_out, const float * data_in, size_t nx, size_t ny, float t) +void ImProcFunctions::discrete_laplacian_threshold(float * data_out, const float * data_in, size_t nx, size_t ny, float t) { BENCHFUN @@ -2523,7 +2523,7 @@ static float *discrete_laplacian_threshold(float * data_out, const float * data_ } } - return data_out; +// return data_out; } static double *cos_table(size_t size) @@ -2722,7 +2722,7 @@ void ImProcFunctions::retinex_pde(float * datain, float * dataout, int bfw, int } //first call to laplacian with plein strength - (void) discrete_laplacian_threshold(data_tmp, datain, bfw, bfh, thresh); + ImProcFunctions::discrete_laplacian_threshold(data_tmp, datain, bfw, bfh, thresh); if (NULL == (data_fft = (float *) fftwf_malloc(sizeof(float) * bfw * bfh))) { fprintf(stderr, "allocation error\n"); @@ -2738,7 +2738,7 @@ void ImProcFunctions::retinex_pde(float * datain, float * dataout, int bfw, int } //second call to laplacian with 40% strength ==> reduce effect if we are far from ref (deltaE) - (void) discrete_laplacian_threshold(data_tmp04, datain, bfw, bfh, 0.4f * thresh); + ImProcFunctions::discrete_laplacian_threshold(data_tmp04, datain, bfw, bfh, 0.4f * thresh); if (NULL == (data_fft04 = (float *) fftwf_malloc(sizeof(float) * bfw * bfh))) { fprintf(stderr, "allocation error\n"); @@ -2784,9 +2784,11 @@ void ImProcFunctions::retinex_pde(float * datain, float * dataout, int bfw, int fftwf_free(data_fft04); fftwf_free(data_tmp); fftwf_free(data_tmp04); - if (dEenable == 1) { + + if (dEenable == 1) { fftwf_destroy_plan(dct_fw04); } + /* solve the Poisson PDE in Fourier space */ /* 1. / (float) (bfw * bfh)) is the DCT normalisation term, see libfftw */ (void) rex_poisson_dct(data_fft, bfw, bfh, 1. / (double)(bfw * bfh)); @@ -2837,8 +2839,8 @@ void ImProcFunctions::retinex_pde(float * datain, float * dataout, int bfw, int } void ImProcFunctions::maskcalccol(bool invmask, bool pde, int bfw, int bfh, int xstart, int ystart, int sk, int cx, int cy, LabImage* bufcolorig, LabImage* bufmaskblurcol, LabImage* originalmaskcol, LabImage* original, /*LabImage * transformed, */int inv, const struct local_params & lp, - const LocCCmaskCurve & locccmasCurve, bool & lcmasutili, const LocLLmaskCurve & locllmasCurve, bool & llmasutili, const LocHHmaskCurve & lochhmasCurve, bool &lhmasutili, bool multiThread, - bool enaMask, bool showmaske, bool deltaE, bool modmask, bool zero, bool modif, float chrom, float rad, float lap, float gamma, float slope, float blendm) + const LocCCmaskCurve & locccmasCurve, bool & lcmasutili, const LocLLmaskCurve & locllmasCurve, bool & llmasutili, const LocHHmaskCurve & lochhmasCurve, bool &lhmasutili, bool multiThread, + bool enaMask, bool showmaske, bool deltaE, bool modmask, bool zero, bool modif, float chrom, float rad, float lap, float gamma, float slope, float blendm) { array2D ble(bfw, bfh); array2D guid(bfw, bfh); @@ -2945,7 +2947,7 @@ void ImProcFunctions::maskcalccol(bool invmask, bool pde, int bfw, int bfh, int } } } - + if (rad > 0.f) { guidedFilter(guid, ble, ble, rad * 10.f / sk, 0.001, multiThread, 4); } @@ -2978,12 +2980,13 @@ void ImProcFunctions::maskcalccol(bool invmask, bool pde, int bfw, int bfh, int datain[y * bfw + x] = bufmaskblurcol->L[y][x]; } } - if(!pde) { - (void) discrete_laplacian_threshold(data_tmp, datain, bfw, bfh, 200.f * lap); + + if (!pde) { + ImProcFunctions::discrete_laplacian_threshold(data_tmp, datain, bfw, bfh, 200.f * lap); } else { ImProcFunctions::retinex_pde(datain, data_tmp, bfw, bfh, 12.f * lap, 1.f, nullptr, 0, 0, 1); } - + #ifdef _OPENMP #pragma omp parallel for #endif @@ -4782,7 +4785,7 @@ void ImProcFunctions::exposure_pde(float * dataor, float * datain, float * datao abort(); } - (void) discrete_laplacian_threshold(data_tmp, datain, bfw, bfh, thresh); + ImProcFunctions::discrete_laplacian_threshold(data_tmp, datain, bfw, bfh, thresh); if (NULL == (data_fft = (float *) fftwf_malloc(sizeof(float) * bfw * bfh))) { fprintf(stderr, "allocation error\n"); @@ -6923,8 +6926,8 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o } } - if(!pde) { - (void) discrete_laplacian_threshold(data_tmp, datain, GW, GH, 200.f * lap); + if (!pde) { + ImProcFunctions::discrete_laplacian_threshold(data_tmp, datain, GW, GH, 200.f * lap); } else { ImProcFunctions::retinex_pde(datain, data_tmp, GW, GH, 12.f * lap, 1.f, nullptr, 0, 0, 1); } diff --git a/rtengine/ipretinex.cc b/rtengine/ipretinex.cc index a411f1999..a54003b64 100644 --- a/rtengine/ipretinex.cc +++ b/rtengine/ipretinex.cc @@ -95,69 +95,6 @@ void calcGammaLut(double gamma, double ts, LUTf &gammaLut) } } -static float *discrete_laplacian_threshold_reti(float * data_out, const float * data_in, size_t nx, size_t ny, float t) -{//same as in iplocallab.cc - BENCHFUN - - size_t i, j; - float *ptr_out; - float diff = 0.f; - const float *ptr_in, *ptr_in_xm1, *ptr_in_xp1, *ptr_in_ym1, *ptr_in_yp1; - - if (NULL == data_in || NULL == data_out) { - fprintf(stderr, "a pointer is NULL and should not be so\n"); - abort(); - } - ptr_in = data_in; - ptr_in_xm1 = data_in - 1; - ptr_in_xp1 = data_in + 1; - ptr_in_ym1 = data_in - nx; - ptr_in_yp1 = data_in + nx; - ptr_out = data_out; - - for (j = 0; j < ny; j++) { - for (i = 0; i < nx; i++) { - *ptr_out = 0.f; - - if (0 < i) { - diff = *ptr_in - *ptr_in_xm1; - - if (fabs(diff) > t) { - *ptr_out += diff; - } - } - if (nx - 1 > i) { - diff = *ptr_in - *ptr_in_xp1; - - if (fabs(diff) > t) { - *ptr_out += diff; - } - } - if (0 < j) { - diff = *ptr_in - *ptr_in_ym1; - - if (fabs(diff) > t) { - *ptr_out += diff; - } - } - if (ny - 1 > j) { - diff = *ptr_in - *ptr_in_yp1; - - if (fabs(diff) > t) { - *ptr_out += diff; - } - } - ptr_in++; - ptr_in_xm1++; - ptr_in_xp1++; - ptr_in_ym1++; - ptr_in_yp1++; - ptr_out++; - } - } - return data_out; -} - void retinex_scales(float* scales, int nscales, int mode, int s, float high) { if (s < 3) { @@ -914,7 +851,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e void ImProcFunctions::maskforretinex(int sp, int before, float ** luminance, float ** out, int W_L, int H_L, int skip, const LocCCmaskCurve & locccmasretiCurve, bool &lcmasretiutili, const LocLLmaskCurve & locllmasretiCurve, bool &llmasretiutili, const LocHHmaskCurve & lochhmasretiCurve, bool & lhmasretiutili, int llretiMask, bool retiMasktmap, bool retiMask, - float rad, float lap, float gamm, float slop, float chro, float blend, LabImage * bufreti, LabImage * bufmask, LabImage * buforig, LabImage * buforigmas, bool multiThread) + float rad, float lap, float gamm, float slop, float chro, float blend, LabImage * bufreti, LabImage * bufmask, LabImage * buforig, LabImage * buforigmas, bool multiThread) { array2D loctemp(W_L, H_L); array2D ble(W_L, H_L); @@ -1015,36 +952,37 @@ void ImProcFunctions::maskforretinex(int sp, int before, float ** luminance, flo bufmaskblurreti->L[ir][jr] = lutTonemaskreti[L_]; } - if (lap > 0.f) { - float *datain = new float[H_L * W_L]; - float *data_tmp = new float[H_L * W_L]; + if (lap > 0.f) { + float *datain = new float[H_L * W_L]; + float *data_tmp = new float[H_L * W_L]; #ifdef _OPENMP - #pragma omp parallel for + #pragma omp parallel for #endif - for (int y = 0; y < H_L; y++) { - for (int x = 0; x < W_L; x++) { - datain[y * W_L + x] = bufmaskblurreti->L[y][x]; - } + for (int y = 0; y < H_L; y++) { + for (int x = 0; x < W_L; x++) { + datain[y * W_L + x] = bufmaskblurreti->L[y][x]; } - - (void) discrete_laplacian_threshold_reti(data_tmp, datain, W_L, H_L, 200.f * lap); -#ifdef _OPENMP - #pragma omp parallel for -#endif - - for (int y = 0; y < H_L; y++) { - for (int x = 0; x < W_L; x++) { - bufmaskblurreti->L[y][x] = data_tmp[y * W_L + x]; - } - } - - delete [] datain; - delete [] data_tmp; - } + ImProcFunctions::discrete_laplacian_threshold(data_tmp, datain, W_L, H_L, 200.f * lap); + // (void) discrete_laplacian_threshold_reti(data_tmp, datain, W_L, H_L, 200.f * lap); +#ifdef _OPENMP + #pragma omp parallel for +#endif + + for (int y = 0; y < H_L; y++) { + for (int x = 0; x < W_L; x++) { + bufmaskblurreti->L[y][x] = data_tmp[y * W_L + x]; + } + } + + delete [] datain; + delete [] data_tmp; + + } + //blend #ifdef _OPENMP #pragma omp parallel @@ -1658,6 +1596,7 @@ void ImProcFunctions::MSRLocal(int sp, bool fftw, int lum, float** reducDE, LabI } } + float rad = loc.spots.at(sp).radmaskreti; float slop = loc.spots.at(sp).slomaskreti; float gamm = loc.spots.at(sp).gammaskreti; @@ -1668,8 +1607,9 @@ void ImProcFunctions::MSRLocal(int sp, bool fftw, int lum, float** reducDE, LabI if (lum == 1 && (llretiMask == 3 || llretiMask == 0 || llretiMask == 2 || llretiMask == 4)) { //only mask with luminance on last scale int before = 1; maskforretinex(sp, before, luminance, nullptr, W_L, H_L, skip, locccmasretiCurve, lcmasretiutili, locllmasretiCurve, llmasretiutili, lochhmasretiCurve, lhmasretiutili, llretiMask, retiMasktmap, retiMask, - rad, lap, gamm, slop, chro, blend , bufreti, bufmask, buforig, buforigmas, multiThread); + rad, lap, gamm, slop, chro, blend, bufreti, bufmask, buforig, buforigmas, multiThread); } + //mask does not interfered with datas displayed Tmean = mean;