diff --git a/rtengine/EdgePreservingDecomposition.cc b/rtengine/EdgePreservingDecomposition.cc index 9e71b6a06..34ac2440b 100644 --- a/rtengine/EdgePreservingDecomposition.cc +++ b/rtengine/EdgePreservingDecomposition.cc @@ -939,7 +939,7 @@ void EdgePreservingDecomposition::CompressDynamicRange(float *Source, float Scal cev = xexpf(LVFU(Source[i]) + LVFU(u[i]) * (tempv)) - epsv; uev = xexpf(LVFU(u[i])) - epsv; sourcev = xexpf(LVFU(Source[i])) - epsv; - _mm_storeu_ps( &Source[i], cev + DetailBoostv * (sourcev - uev) ); + _mm_storeu_ps( &Source[i], cev + DetailBoostv * (sourcev - uev)); } } diff --git a/rtengine/FTblockDN.cc b/rtengine/FTblockDN.cc index be46c88f4..fca26987f 100644 --- a/rtengine/FTblockDN.cc +++ b/rtengine/FTblockDN.cc @@ -1098,9 +1098,6 @@ BENCHFUN } if (execwavelet) {//gain time if user choose only median sliders L <=1 slider chrom master < 1 - wavelet_decomposition* Ldecomp; - wavelet_decomposition* adecomp; - int levwav = 5; float maxreal = max(realred, realblue); @@ -1141,9 +1138,9 @@ BENCHFUN levwav = min(maxlev2, levwav); // if (settings->verbose) printf("levwavelet=%i noisevarA=%f noisevarB=%f \n",levwav, noisevarab_r, noisevarab_b); - Ldecomp = new wavelet_decomposition(labdn->L[0], labdn->W, labdn->H, levwav, 1, 1, max(1, denoiseNestedLevels)); + const std::unique_ptr Ldecomp(new wavelet_decomposition(labdn->L[0], labdn->W, labdn->H, levwav, 1, 1, max(1, denoiseNestedLevels))); - if (Ldecomp->memoryAllocationFailed) { + if (Ldecomp->memory_allocation_failed()) { memoryAllocationFailed = true; } @@ -1162,7 +1159,7 @@ BENCHFUN int Wlvl_L = Ldecomp->level_W(lvl); int Hlvl_L = Ldecomp->level_H(lvl); - float ** WavCoeffs_L = Ldecomp->level_coeffs(lvl); + const float* const* WavCoeffs_L = Ldecomp->level_coeffs(lvl); if (!denoiseMethodRgb) { madL[lvl][dir - 1] = SQR(Mad(WavCoeffs_L[dir], Wlvl_L * Hlvl_L)); @@ -1179,9 +1176,9 @@ BENCHFUN float chmaxresid = 0.f; float chmaxresidtemp = 0.f; - adecomp = new wavelet_decomposition(labdn->a[0], labdn->W, labdn->H, levwav, 1, 1, max(1, denoiseNestedLevels)); + std::unique_ptr adecomp(new wavelet_decomposition(labdn->a[0], labdn->W, labdn->H, levwav, 1, 1, max(1, denoiseNestedLevels))); - if (adecomp->memoryAllocationFailed) { + if (adecomp->memory_allocation_failed()) { memoryAllocationFailed = true; } @@ -1213,12 +1210,12 @@ BENCHFUN adecomp->reconstruct(labdn->a[0]); } - delete adecomp; + adecomp.reset(); if (!memoryAllocationFailed) { - wavelet_decomposition* bdecomp = new wavelet_decomposition(labdn->b[0], labdn->W, labdn->H, levwav, 1, 1, max(1, denoiseNestedLevels)); + std::unique_ptr bdecomp(new wavelet_decomposition(labdn->b[0], labdn->W, labdn->H, levwav, 1, 1, max(1, denoiseNestedLevels))); - if (bdecomp->memoryAllocationFailed) { + if (bdecomp->memory_allocation_failed()) { memoryAllocationFailed = true; } @@ -1253,7 +1250,7 @@ BENCHFUN bdecomp->reconstruct(labdn->b[0]); } - delete bdecomp; + bdecomp.reset(); if (!memoryAllocationFailed) { if (denoiseLuminance) { @@ -1293,8 +1290,6 @@ BENCHFUN } } } - - delete Ldecomp; } if (!memoryAllocationFailed) { @@ -2177,7 +2172,7 @@ void ImProcFunctions::Noise_residualAB(const wavelet_decomposition &WaveletCoeff const int Wlvl_ab = WaveletCoeffs_ab.level_W(lvl); const int Hlvl_ab = WaveletCoeffs_ab.level_H(lvl); - float ** WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(lvl); + const float* const* WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(lvl); const float madC = SQR(denoiseMethodRgb ? MadRgb(WavCoeffs_ab[dir], Wlvl_ab * Hlvl_ab) : Mad(WavCoeffs_ab[dir], Wlvl_ab * Hlvl_ab)); resid += madC; @@ -2192,7 +2187,7 @@ void ImProcFunctions::Noise_residualAB(const wavelet_decomposition &WaveletCoeff chmaxresid = maxresid; } -bool ImProcFunctions::WaveletDenoiseAll_BiShrinkL(const wavelet_decomposition &WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge, int denoiseNestedLevels) +bool ImProcFunctions::WaveletDenoiseAll_BiShrinkL(wavelet_decomposition& WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge, int denoiseNestedLevels) { int maxlvl = min(WaveletCoeffs_L.maxlevel(), 5); const float eps = 0.01f; @@ -2243,7 +2238,7 @@ bool ImProcFunctions::WaveletDenoiseAll_BiShrinkL(const wavelet_decomposition &W int Wlvl_L = WaveletCoeffs_L.level_W(lvl); int Hlvl_L = WaveletCoeffs_L.level_H(lvl); - float ** WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); + float* const* WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); if (lvl == maxlvl - 1) { // int edge = 0; @@ -2375,8 +2370,7 @@ bool ImProcFunctions::WaveletDenoiseAll_BiShrinkL(const wavelet_decomposition &W } -bool ImProcFunctions::WaveletDenoiseAll_BiShrinkAB(const wavelet_decomposition &WaveletCoeffs_L, const wavelet_decomposition &WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float *variC, int local, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, int denoiseNestedLevels) - +bool ImProcFunctions::WaveletDenoiseAll_BiShrinkAB(wavelet_decomposition& WaveletCoeffs_L, wavelet_decomposition& WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float *variC, int local, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, int denoiseNestedLevels) { int maxlvl = WaveletCoeffs_L.maxlevel(); @@ -2432,7 +2426,7 @@ bool ImProcFunctions::WaveletDenoiseAll_BiShrinkAB(const wavelet_decomposition & // compute median absolute deviation (MAD) of detail coefficients as robust noise estimator int Wlvl_ab = WaveletCoeffs_ab.level_W(lvl); int Hlvl_ab = WaveletCoeffs_ab.level_H(lvl); - float ** WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(lvl); + const float* const* WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(lvl); if (!denoiseMethodRgb) { madab[lvl][dir - 1] = SQR(Mad(WavCoeffs_ab[dir], Wlvl_ab * Hlvl_ab)); @@ -2451,8 +2445,8 @@ bool ImProcFunctions::WaveletDenoiseAll_BiShrinkAB(const wavelet_decomposition & int Wlvl_ab = WaveletCoeffs_ab.level_W(lvl); int Hlvl_ab = WaveletCoeffs_ab.level_H(lvl); - float ** WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); - float ** WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(lvl); + float* const* WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); + float* const* WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(lvl); if (lvl == maxlvl - 1) { ShrinkAllAB(WaveletCoeffs_L, WaveletCoeffs_ab, buffer, lvl, dir, noisevarchrom, noisevar_ab, useNoiseCCurve, autoch, denoiseMethodRgb, madL[lvl], nullptr, 0, madab[lvl], true); @@ -2546,7 +2540,7 @@ bool ImProcFunctions::WaveletDenoiseAll_BiShrinkAB(const wavelet_decomposition & } -bool ImProcFunctions::WaveletDenoiseAllL(const wavelet_decomposition &WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge, int denoiseNestedLevels)//mod JD +bool ImProcFunctions::WaveletDenoiseAllL(wavelet_decomposition& WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge, int denoiseNestedLevels)//mod JD { @@ -2607,7 +2601,7 @@ bool ImProcFunctions::WaveletDenoiseAllL(const wavelet_decomposition &WaveletCoe } -bool ImProcFunctions::WaveletDenoiseAllAB(const wavelet_decomposition &WaveletCoeffs_L, const wavelet_decomposition &WaveletCoeffs_ab, +bool ImProcFunctions::WaveletDenoiseAllAB(wavelet_decomposition& WaveletCoeffs_L, wavelet_decomposition& WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float *variC, int local, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, int denoiseNestedLevels)//mod JD { @@ -2671,7 +2665,7 @@ bool ImProcFunctions::WaveletDenoiseAllAB(const wavelet_decomposition &WaveletCo -void ImProcFunctions::ShrinkAllL(const wavelet_decomposition &WaveletCoeffs_L, float **buffer, int level, int dir, +void ImProcFunctions::ShrinkAllL(wavelet_decomposition& WaveletCoeffs_L, float **buffer, int level, int dir, float *noisevarlum, float * madL, float * vari, int edge) { @@ -2685,7 +2679,7 @@ void ImProcFunctions::ShrinkAllL(const wavelet_decomposition &WaveletCoeffs_L, f const int W_L = WaveletCoeffs_L.level_W(level); const int H_L = WaveletCoeffs_L.level_H(level); - float ** WavCoeffs_L = WaveletCoeffs_L.level_coeffs(level); + float* const* WavCoeffs_L = WaveletCoeffs_L.level_coeffs(level); const float mad_L = madL[dir - 1] ; const float levelFactor = mad_L * 5.f / static_cast(level + 1); @@ -2762,7 +2756,7 @@ void ImProcFunctions::ShrinkAllL(const wavelet_decomposition &WaveletCoeffs_L, f } -void ImProcFunctions::ShrinkAllAB(const wavelet_decomposition & WaveletCoeffs_L, const wavelet_decomposition & WaveletCoeffs_ab, float **buffer, int level, int dir, +void ImProcFunctions::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 * variC, int local, float * madaab, bool madCalculated) @@ -2781,8 +2775,8 @@ void ImProcFunctions::ShrinkAllAB(const wavelet_decomposition & WaveletCoeffs_L, int W_ab = WaveletCoeffs_ab.level_W(level); int H_ab = WaveletCoeffs_ab.level_H(level); - float ** WavCoeffs_L = WaveletCoeffs_L.level_coeffs(level); - float ** WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(level); + float* const* WavCoeffs_L = WaveletCoeffs_L.level_coeffs(level); + float* const* WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(level); float madab; float mad_L = madL[dir - 1]; @@ -2901,7 +2895,7 @@ void ImProcFunctions::ShrinkAllAB(const wavelet_decomposition & WaveletCoeffs_L, delete [] nvc; } -void ImProcFunctions::ShrinkAll_info(float ** WavCoeffs_a, float ** WavCoeffs_b, +void ImProcFunctions::ShrinkAll_info(const float* const* WavCoeffs_a, const float* const* 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) @@ -3031,8 +3025,8 @@ void ImProcFunctions::WaveletDenoiseAll_info(int levwav, const wavelet_decomposi int Wlvl_ab = WaveletCoeffs_a.level_W(lvl); int Hlvl_ab = WaveletCoeffs_a.level_H(lvl); - float ** WavCoeffs_a = WaveletCoeffs_a.level_coeffs(lvl); - float ** WavCoeffs_b = WaveletCoeffs_b.level_coeffs(lvl); + const float* const* WavCoeffs_a = WaveletCoeffs_a.level_coeffs(lvl); + const float* const* WavCoeffs_b = WaveletCoeffs_b.level_coeffs(lvl); ShrinkAll_info(WavCoeffs_a, WavCoeffs_b, Wlvl_ab, Hlvl_ab, noisevarlum, noisevarchrom, noisevarhue, chaut, Nb, redaut, blueaut, maxredaut, maxblueaut, minredaut, minblueaut, diff --git a/rtengine/cplx_wavelet_dec.h b/rtengine/cplx_wavelet_dec.h index 1137a0937..592bd2f37 100644 --- a/rtengine/cplx_wavelet_dec.h +++ b/rtengine/cplx_wavelet_dec.h @@ -33,37 +33,38 @@ class wavelet_decomposition : public NonCopyable { public: - - typedef float internal_type; - float *coeff0; - bool memoryAllocationFailed; - -private: - - static const int maxlevels = 10;//should be greater than any conceivable order of decimation - - int lvltot, subsamp; - int m_w, m_h;//dimensions - - int wavfilt_len, wavfilt_offset; - float *wavfilt_anal; - float *wavfilt_synth; - - - wavelet_level * wavelet_decomp[maxlevels]; - -public: + using internal_type = float; template wavelet_decomposition(E * src, int width, int height, int maxlvl, int subsampling, int skipcrop = 1, int numThreads = 1, int Daub4Len = 6); ~wavelet_decomposition(); - internal_type ** level_coeffs(int level) const + bool memory_allocation_failed() const + { + return memoryAllocationFailed; + } + + const internal_type* const* level_coeffs(int level) const { return wavelet_decomp[level]->subbands(); } + internal_type* const* level_coeffs(int level) + { + return wavelet_decomp[level]->subbands(); + } + + const internal_type* get_coeff0() const + { + return coeff0; + } + + internal_type* get_coeff0() + { + return coeff0; + } + int level_W(int level) const { return wavelet_decomp[level]->width(); @@ -88,13 +89,47 @@ public: { return subsamp; } + template void reconstruct(E * dst, const float blend = 1.f); + +private: + static const int maxlevels = 10; // should be greater than any conceivable order of decimation + + int lvltot; + int subsamp; + // Dimensions + int m_w; + int m_h; + + int wavfilt_len; + int wavfilt_offset; + internal_type* wavfilt_anal; + internal_type* wavfilt_synth; + + internal_type* coeff0; + bool memoryAllocationFailed; + + wavelet_level* wavelet_decomp[maxlevels]; }; template -wavelet_decomposition::wavelet_decomposition(E * src, int width, int height, int maxlvl, int subsampling, int skipcrop, int numThreads, int Daub4Len) - : coeff0(nullptr), memoryAllocationFailed(false), lvltot(0), subsamp(subsampling), m_w(width), m_h(height) +wavelet_decomposition::wavelet_decomposition( + E * src, + int width, + int height, + int maxlvl, + int subsampling, + int skipcrop, + int numThreads, + int Daub4Len +) : + lvltot(0), + subsamp(subsampling), + m_w(width), + m_h(height), + coeff0(nullptr), + memoryAllocationFailed(false) { //initialize wavelet filters diff --git a/rtengine/imagedata.cc b/rtengine/imagedata.cc index f9406b270..5025b31e5 100644 --- a/rtengine/imagedata.cc +++ b/rtengine/imagedata.cc @@ -546,9 +546,9 @@ FrameData::FrameData(rtexif::TagDirectory* frameRootDir_, rtexif::TagDirectory* if (mnote->getTag("FocalLengthIn35mmFilm")) { focal_len35mm = mnote->getTag("FocalLengthIn35mmFilm")->toDouble(); } - } else if (mnote && (!make.compare(0, 4, "SONY") || !make.compare(0, 6, "KONICA"))) { - if (mnote->getTag("LensID")) { - lens = mnote->getTag("LensID")->valueToString(); + } else if (!make.compare (0, 4, "SONY") || !make.compare (0, 6, "KONICA")) { + if (mnote->getTag ("LensID")) { + lens = mnote->getTag ("LensID")->valueToString (); if (lens == "Unknown") { lens_from_make_and_model(); } @@ -564,8 +564,8 @@ FrameData::FrameData(rtexif::TagDirectory* frameRootDir_, rtexif::TagDirectory* if (lens == "Unknown") { lens_from_make_and_model(); } - } else if (mnote && !make.compare(0, 9, "Panasonic")) { - if (mnote->getTag("LensType")) { + } else if (!make.compare (0, 9, "Panasonic")) { + if (mnote->getTag ("LensType")) { std::string panalens = mnote->getTag("LensType")->valueToString(); if (panalens.find("LUMIX") != Glib::ustring::npos) { diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 2ed5139f6..65c40b108 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -5247,123 +5247,73 @@ void ImProcFunctions::EPDToneMaplocal(int sp, LabImage *lab, LabImage *tmp1, uns -//Map tones by way of edge preserving decomposition. Is this the right way to include source? -//#include "EdgePreservingDecomposition.cc" +//Map tones by way of edge preserving decomposition. void ImProcFunctions::EPDToneMap(LabImage *lab, unsigned int Iterates, int skip) { - //Hasten access to the parameters. -// EPDParams *p = (EPDParams *)(¶ms->epd); - //Enabled? Leave now if not. -// if(!p->enabled) return; if (!params->epd.enabled) { return; } -/* - if (params->wavelet.enabled && params->wavelet.tmrs != 0) { - return; - } -*/ - float stren = params->epd.strength; - float edgest = params->epd.edgeStopping; - float sca = params->epd.scale; - float gamm = params->epd.gamma; - float rew = params->epd.reweightingIterates; + + const float stren = params->epd.strength; + const float edgest = std::min(params->epd.edgeStopping, params->localContrast.enabled ? 3.0 : 4.0); + const float sca = params->epd.scale; + const float gamm = params->epd.gamma; + const float rew = params->epd.reweightingIterates; //Pointers to whole data and size of it. float *L = lab->L[0]; float *a = lab->a[0]; float *b = lab->b[0]; - size_t N = lab->W * lab->H; + const size_t N = lab->W * lab->H; + EdgePreservingDecomposition epd(lab->W, lab->H); //Due to the taking of logarithms, L must be nonnegative. Further, scale to 0 to 1 using nominal range of L, 0 to 15 bit. - float minL = FLT_MAX; - float maxL = 0.f; + float minL = L[0]; + float maxL = L[0]; #ifdef _OPENMP - #pragma omp parallel + #pragma omp parallel for reduction(min:minL) reduction(max:maxL) #endif - { - float lminL = FLT_MAX; - float lmaxL = 0.f; -#ifdef _OPENMP - #pragma omp for -#endif - - for (size_t i = 0; i < N; i++) { - if (L[i] < lminL) { - lminL = L[i]; - } - - if (L[i] > lmaxL) { - lmaxL = L[i]; - } - } - -#ifdef _OPENMP - #pragma omp critical -#endif - { - if (lminL < minL) { - minL = lminL; - } - - if (lmaxL > maxL) { - maxL = lmaxL; - } - } + for (size_t i = 1; i < N; i++) { + minL = std::min(minL, L[i]); + maxL = std::max(maxL, L[i]); } - if (minL > 0.0f) { - minL = 0.0f; //Disable the shift if there are no negative numbers. I wish there were just no negative numbers to begin with. + if (maxL == 0.f) { // black input => do nothing + return; } - if (maxL == 0.f) { // avoid division by zero - maxL = 1.f; - } + minL = std::min(minL, 0.f); //Disable the shift if there are no negative numbers. I wish there were just no negative numbers to begin with. #ifdef _OPENMP #pragma omp parallel for #endif - - for (size_t i = 0; i < N; ++i) - //{L[i] = (L[i] - minL)/32767.0f; - { - L[i] = (L[i] - minL) / maxL; - L[i] *= gamm; + for (size_t i = 0; i < N; ++i) { + L[i] = (L[i] - minL) * (gamm / maxL); } //Some interpretations. - float Compression = expf(-stren); //This modification turns numbers symmetric around 0 into exponents. - float DetailBoost = stren; - - if (stren < 0.0f) { - DetailBoost = 0.0f; //Go with effect of exponent only if uncompressing. - } + const float Compression = expf(-stren); //This modification turns numbers symmetric around 0 into exponents. + const float DetailBoost = std::max(stren, 0.f); //Go with effect of exponent only if uncompressing. //Auto select number of iterates. Note that p->EdgeStopping = 0 makes a Gaussian blur. if (Iterates == 0) { - Iterates = (unsigned int)(edgest * 15.0f); + Iterates = edgest * 15.f; } - /* Debuggery. Saves L for toying with outside of RT. - char nm[64]; - sprintf(nm, "%ux%ufloat.bin", lab->W, lab->H); - FILE *f = fopen(nm, "wb"); - fwrite(L, N, sizeof(float), f); - fclose(f);*/ - - epd.CompressDynamicRange(L, sca / float (skip), edgest, Compression, DetailBoost, Iterates, rew); + epd.CompressDynamicRange (L, sca / skip, edgest, Compression, DetailBoost, Iterates, rew); //Restore past range, also desaturate a bit per Mantiuk's Color correction for tone mapping. - float s = (1.0f + 38.7889f) * powf(Compression, 1.5856f) / (1.0f + 38.7889f * powf(Compression, 1.5856f)); -#ifdef _OPENMP - #pragma omp parallel for // removed schedule(dynamic,10) -#endif + const float s = (1.f + 38.7889f) * std::pow(Compression, 1.5856f) / (1.f + 38.7889f * std::pow(Compression, 1.5856f)); + maxL /= gamm; +#ifdef _OPENMP + #pragma omp parallel for +#endif for (size_t ii = 0; ii < N; ++ii) { a[ii] *= s; b[ii] *= s; - L[ii] = L[ii] * maxL * (1.f / gamm) + minL; + L[ii] = L[ii] * maxL + minL; } } diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 047bb9ab1..8d75329cd 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -218,10 +218,10 @@ public: 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); + void EPDToneMapResid(float * WavCoeffs_L0, unsigned int Iterates, int skip, const struct cont_params& cp, int W_L, int H_L, float max0); void CompressDR(float *Source, int W_L, int H_L, float Compression, float DetailBoost); void Compresslevels(float **Source, int W_L, int H_L, float compression, float detailattenuator, float thres, float mean, float maxp, float meanN, float maxN, float madL); - void ContrastResid(float * WavCoeffs_L0, struct cont_params &cp, int W_L, int H_L, float max0, float min0); + void ContrastResid(float * WavCoeffs_L0, const struct cont_params &cp, int W_L, int H_L, float max0); void EPDToneMap(LabImage *lab, unsigned int Iterates = 0, int skip = 1); void EPDToneMaplocal(int sp, LabImage *lab, LabImage *tmp1, unsigned int Iterates, int skip); @@ -338,13 +338,13 @@ public: const LocwavCurve & locedgwavCurve, bool locedgwavutili, float sigm, float offs,int & maxlvl, float fatdet, float fatanch, float chromalev, float chromablu, bool blurlc, bool blurena, bool levelena, bool comprena, bool compreena, float compress, float thres); - void wavcont(const struct local_params& lp, float ** tmp, const wavelet_decomposition &wdspot, float ****templevel, int level_bl, int maxlvl, + void wavcont(const struct local_params& lp, float ** tmp, wavelet_decomposition &wdspot, float ****templevel, int level_bl, int maxlvl, const LocwavCurve & loclevwavCurve, bool loclevwavutili, const LocwavCurve & loccompwavCurve, bool loccompwavutili, const LocwavCurve & loccomprewavCurve, bool loccomprewavutili, float radlevblur, int process, float chromablu, float thres, float sigmadc, float deltad); - void wavcbd(const wavelet_decomposition &wdspot, int level_bl, int maxlvl, + void wavcbd(wavelet_decomposition &wdspot, int level_bl, int maxlvl, const LocwavCurve& locconwavCurve, bool locconwavutili, float sigm, float offs, float chromalev, int sk); void transit_shapedetect2(int call, int senstype, const LabImage * bufexporig, const LabImage * bufexpfin, LabImage * originalmask, const float hueref, const float chromaref, const float lumaref, float sobelref, float meansobel, float ** blend2, struct local_params & lp, LabImage * original, LabImage * transformed, int cx, int cy, int sk); @@ -370,29 +370,29 @@ public: 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 Wavblcurve & wavblcurve, const WavOpacityCurveRG & waOpacityCurveRG, const WavOpacityCurveSH & waOpacityCurveSH, const WavOpacityCurveBY & waOpacityCurveBY, const WavOpacityCurveW & waOpacityCurveW, const WavOpacityCurveWL & waOpacityCurveWL, const LUTf &wavclCurve, int skip); - void WaveletcontAllL(LabImage * lab, float **varhue, float **varchrom, const wavelet_decomposition &WaveletCoeffs_L, const Wavblcurve & wavblcurve, + void WaveletcontAllL(LabImage * lab, float **varhue, float **varchrom, wavelet_decomposition& WaveletCoeffs_L, const Wavblcurve & wavblcurve, struct cont_params &cp, int skip, float *mean, float *sigma, float *MaxP, float *MaxN, const WavCurve & wavCLVCcurve, const WavOpacityCurveW & waOpacityCurveW, const WavOpacityCurveSH & waOpacityCurveSH, FlatCurve* ChCurve, bool Chutili); - void WaveletcontAllLfinal(const wavelet_decomposition &WaveletCoeffs_L, const cont_params &cp, float *mean, float *sigma, float *MaxP, const WavOpacityCurveWL & waOpacityCurveWL); - void WaveletcontAllAB(LabImage * lab, float **varhue, float **varchrom, const wavelet_decomposition &WaveletCoeffs_a, const Wavblcurve & wavblcurve, const WavOpacityCurveW & waOpacityCurveW, + void WaveletcontAllLfinal(wavelet_decomposition& WaveletCoeffs_L, const 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 Wavblcurve & wavblcurve, const WavOpacityCurveW & waOpacityCurveW, struct cont_params &cp, const bool useChannelA, int skip, float *meanab, float *sigmaab); - void WaveletAandBAllAB(const wavelet_decomposition &WaveletCoeffs_a, const wavelet_decomposition &WaveletCoeffs_b, + void WaveletAandBAllAB(wavelet_decomposition& WaveletCoeffs_a, wavelet_decomposition& WaveletCoeffs_b, const 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, + void ContAllL(float** koeLi, float maxkoeLi, bool lipschitz, int maxlvl, LabImage * lab, const float* const* varhue, const float* const* varchrom, float* const* 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, const WavOpacityCurveSH & waOpacityCurveSH, FlatCurve* ChCurve, bool Chutili); - void finalContAllL(float ** WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, const cont_params &cp, + void finalContAllL(float* const* WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, const 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, + void ContAllAB(LabImage * lab, int maxlvl, float **varhue, float **varchrom, float* const* 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, float *meanab, float *sigmaab); void Evaluate2(const wavelet_decomposition &WaveletCoeffs_L, float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN); - void Eval2(float ** WavCoeffs_L, int level, + void Eval2(const float* const* WavCoeffs_L, int level, int W_L, int H_L, float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN); void calceffect(int level, float *mean, float *sigma, float *mea, float effect, float offs); - 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, float gradw, float tloww, float ** koeLi, int level, int dir, int W_L, int H_L, float edd, float *maxkoeLi, float **tmC = nullptr); + void Aver(const float* HH_Coeffs, int datalen, float &averagePlus, float &averageNeg, float &max, float &min); + void Sigma(const float* HH_Coeffs, int datalen, float averagePlus, float averageNeg, float &sigmaPlus, float &sigmaNeg); + void calckoe(const float* const* WavCoeffs_LL, float gradw, float tloww, 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); @@ -406,18 +406,18 @@ public: const 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 WaveletDenoiseAllL(const wavelet_decomposition &WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge, int denoiseNestedLevels); - bool WaveletDenoiseAllAB(const wavelet_decomposition &WaveletCoeffs_L, const wavelet_decomposition &WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float *variC, int local, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, int denoiseNestedLevels); + bool WaveletDenoiseAllL(wavelet_decomposition& WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge, int denoiseNestedLevels); + bool WaveletDenoiseAllAB(wavelet_decomposition& WaveletCoeffs_L, wavelet_decomposition& WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float *variC, int local, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, int denoiseNestedLevels); - bool WaveletDenoiseAll_BiShrinkL(const wavelet_decomposition &WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge, int denoiseNestedLevels); - bool WaveletDenoiseAll_BiShrinkAB(const wavelet_decomposition &WaveletCoeffs_L, const wavelet_decomposition &WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float *variC, int local, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, int denoiseNestedLevels); + bool WaveletDenoiseAll_BiShrinkL(wavelet_decomposition& WaveletCoeffs_L, float *noisevarlum, float madL[8][3], float * vari, int edge, int denoiseNestedLevels); + bool WaveletDenoiseAll_BiShrinkAB(wavelet_decomposition& WaveletCoeffs_L, wavelet_decomposition& WaveletCoeffs_ab, float *noisevarchrom, float madL[8][3], float *variC, int local, float noisevar_ab, const bool useNoiseCCurve, bool autoch, bool denoiseMethodRgb, int denoiseNestedLevels); - void ShrinkAllL(const wavelet_decomposition &WaveletCoeffs_L, float **buffer, int level, int dir, float *noisevarlum, float * madL, float * vari, int edge); - void ShrinkAllAB(const wavelet_decomposition &WaveletCoeffs_L, const wavelet_decomposition &WaveletCoeffs_ab, float **buffer, int level, int dir, + 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 * variC, int local, float * madaab = nullptr, bool madCalculated = false); - void ShrinkAll_info(float ** WavCoeffs_a, float ** WavCoeffs_b, + void ShrinkAll_info(const float* const* WavCoeffs_a, const float* const* 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(const wavelet_decomposition &WaveletCoeffs_ab, float &chresid, float &chmaxresid, bool denoiseMethodRgb); diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 3521e65a3..d53b45019 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -4037,7 +4037,7 @@ void ImProcFunctions::maskcalccol(bool invmask, bool pde, int bfw, int bfh, int #endif wavelet_decomposition *wdspot = new wavelet_decomposition(bufmaskblurcol->L[0], bfw, bfh, maxlvl, 1, sk, numThreads, lp.daubLen); - if (wdspot->memoryAllocationFailed) { + if (wdspot->memory_allocation_failed()) { return; } float mean[10]; @@ -4066,7 +4066,7 @@ void ImProcFunctions::maskcalccol(bool invmask, bool pde, int bfw, int bfh, int for (int level = level_bl; level < maxlvl; ++level) { int W_L = wdspot->level_W(level); int H_L = wdspot->level_H(level); - float **wav_L = wdspot->level_coeffs(level); + float* const* wav_L = wdspot->level_coeffs(level); if (MaxP[level] > 0.f && mean[level] != 0.f && sigma[level] != 0.f) { float insigma = 0.666f; //SD @@ -6733,7 +6733,7 @@ void ImProcFunctions::fftw_tile_blur(int GW, int GH, int tilssize, int max_numbl fftwf_cleanup(); } -void ImProcFunctions::wavcbd(const wavelet_decomposition &wdspot, int level_bl, int maxlvl, +void ImProcFunctions::wavcbd(wavelet_decomposition &wdspot, int level_bl, int maxlvl, const LocwavCurve& locconwavCurve, bool locconwavutili, float sigm, float offs, float chromalev, int sk) { if (locconwavCurve && locconwavutili) { @@ -6754,7 +6754,7 @@ void ImProcFunctions::wavcbd(const wavelet_decomposition &wdspot, int level_bl, const int H_L = wdspot.level_H(level); float mea[9]; - float **wav_L = wdspot.level_coeffs(level); + float* const* wav_L = wdspot.level_coeffs(level); //offset float rap = offs * mean[level] - 2.f * sigm * sigma[level]; @@ -6894,7 +6894,7 @@ void ImProcFunctions::Compresslevels(float **Source, int W_L, int H_L, float com } -void ImProcFunctions::wavcont(const struct local_params& lp, float ** tmp, const wavelet_decomposition& wdspot, float ****templevel, int level_bl, int maxlvl, +void ImProcFunctions::wavcont(const struct local_params& lp, float ** tmp, wavelet_decomposition& wdspot, float ****templevel, int level_bl, int maxlvl, const LocwavCurve & loclevwavCurve, bool loclevwavutili, const LocwavCurve & loccompwavCurve, bool loccompwavutili, const LocwavCurve & loccomprewavCurve, bool loccomprewavutili, @@ -6923,7 +6923,7 @@ void ImProcFunctions::wavcont(const struct local_params& lp, float ** tmp, const for (int level = level_bl; level < maxlvl; ++level) { int W_L = wdspot.level_W(level); int H_L = wdspot.level_H(level); - float **wav_L = wdspot.level_coeffs(level); + auto wav_L = wdspot.level_coeffs(level); madL[level][dir - 1] = Mad(wav_L[dir], W_L * H_L);//evaluate noise by level for (int y = 0; y < H_L; y++) { @@ -6956,7 +6956,7 @@ void ImProcFunctions::wavcont(const struct local_params& lp, float ** tmp, const float mea[10]; calceffect(level, mean, sigma, mea, effect, offs); - float **WavL = wdspot.level_coeffs(level); + auto WavL = wdspot.level_coeffs(level); for (int co = 0; co < H_L * W_L; co++) { const float WavCL = std::fabs(WavL[dir][co]); @@ -7018,7 +7018,7 @@ void ImProcFunctions::wavcont(const struct local_params& lp, float ** tmp, const float offs = 1.f; float mea[10]; calceffect(level, mean, sigma, mea, effect, offs); - float **WavL = wdspot.level_coeffs(level); + auto WavL = wdspot.level_coeffs(level); for (int co = 0; co < H_L * W_L; co++) { const float WavCL = std::fabs(WavL[dir][co]); @@ -7111,7 +7111,7 @@ void ImProcFunctions::wavcont(const struct local_params& lp, float ** tmp, const float mea[10]; calceffect(level, mean, sigma, mea, effect, offs); - float **WavL = wdspot.level_coeffs(level); + auto WavL = wdspot.level_coeffs(level); for (int co = 0; co < H_L * W_L; co++) { const float WavCL = std::fabs(WavL[dir][co]); @@ -7176,7 +7176,7 @@ void ImProcFunctions::wavcont(const struct local_params& lp, float ** tmp, const for (int level = level_bl; level < maxlvl; ++level) { int W_L = wdspot.level_W(level); int H_L = wdspot.level_H(level); - float **wav_L = wdspot.level_coeffs(level); + auto wav_L = wdspot.level_coeffs(level); for (int y = 0; y < H_L; y++) { for (int x = 0; x < W_L; x++) { @@ -7219,7 +7219,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float wavelet_decomposition *wdspot = new wavelet_decomposition(tmp[0], bfw, bfh, maxlvl, 1, sk, numThreads, lp.daubLen); //first decomposition for compress dynamic range positive values and other process - if (wdspot->memoryAllocationFailed) { + if (wdspot->memory_allocation_failed()) { return; } @@ -7276,7 +7276,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float if (MaxP[level] > 0.f && mean[level] != 0.f && sigma[level] != 0.f) { const int W_L = wdspot->level_W(level); const int H_L = wdspot->level_H(level); - float **wav_L = wdspot->level_coeffs(level); + float* const* wav_L = wdspot->level_coeffs(level); const float effect = lp.sigmalc2; constexpr float offset = 1.f; float mea[10]; @@ -7369,7 +7369,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float int W_L = wdspot->level_W(0); int H_L = wdspot->level_H(0); - float *wav_L0 = wdspot->coeff0; + float *wav_L0 = wdspot->get_coeff0(); if (radblur > 0.f && blurena) { array2D bufl(W_L, H_L); @@ -7628,7 +7628,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float for (int dir = 1; dir < 4; dir++) { const int W_L = wdspot->level_W(lvl); const int H_L = wdspot->level_H(lvl); - float **wav_L = wdspot->level_coeffs(lvl); + float* const* wav_L = wdspot->level_coeffs(lvl); const float effect = lp.sigmaed; constexpr float offset = 1.f; float mea[10]; @@ -7661,7 +7661,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float beta[co] = 0.05f; } } - calckoe(wav_L, gradw, tloww, koeLi, lvl, dir, W_L, H_L, edd, maxkoeLi, tmC); + calckoe(wav_L, gradw, tloww, koeLi, lvl, dir, W_L, H_L, edd, maxkoeLi[lvl * 3 + dir - 1], tmC); // return convolution KoeLi and maxkoeLi of level 0 1 2 3 and Dir Horiz, Vert, Diag } } @@ -7799,7 +7799,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float for (int dir = 1; dir < 4; dir++) { int W_L = wdspot->level_W(lvl); int H_L = wdspot->level_H(lvl); - float **wav_L = wdspot->level_coeffs(lvl); + float* const* wav_L = wdspot->level_coeffs(lvl); float lev = float (lvl); float koef = ak * lvl + bk; //modulate for levels : more levels high, more koef low ==> concentrated action on low levels, without or near for high levels @@ -7935,7 +7935,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float for (int level = level_bl; level < maxlvl; ++level) { int W_L = wdspot->level_W(level); int H_L = wdspot->level_H(level); - float **wav_L = wdspot->level_coeffs(level); + float* const* wav_L = wdspot->level_coeffs(level); // printf("W_L=%i H_L=%i lev=%i\n", W_L, H_L, level); if (MaxP[level] > 0.f && mean[level] != 0.f && sigma[level] != 0.f) { @@ -8005,7 +8005,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float if (wavcurvecon && (chromalev != 1.f) && levelena) { // a and b if need ) {//contrast by levels for chroma a and b wdspota = new wavelet_decomposition(tmpa[0], bfw, bfh, maxlvl, 1, sk, numThreads, lp.daubLen); - if (wdspota->memoryAllocationFailed) { + if (wdspota->memory_allocation_failed()) { return; } @@ -8015,7 +8015,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float wdspotb = new wavelet_decomposition(tmpb[0], bfw, bfh, maxlvl, 1, sk, numThreads, lp.daubLen); - if (wdspotb->memoryAllocationFailed) { + if (wdspotb->memory_allocation_failed()) { return; } @@ -8030,7 +8030,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float // a wdspota = new wavelet_decomposition(tmpa[0], bfw, bfh, maxlvl, 1, sk, numThreads, lp.daubLen); - if (wdspota->memoryAllocationFailed) { + if (wdspota->memory_allocation_failed()) { return; } @@ -8084,7 +8084,7 @@ void ImProcFunctions::wavcontrast4(struct local_params& lp, float ** tmp, float //b wdspotb = new wavelet_decomposition(tmpb[0], bfw, bfh, maxlvl, 1, sk, numThreads, lp.daubLen); - if (wdspotb->memoryAllocationFailed) { + if (wdspotb->memory_allocation_failed()) { return; } @@ -8462,7 +8462,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f float madL[10][3]; int edge = 2; - if (!Ldecomp.memoryAllocationFailed) { + if (!Ldecomp.memory_allocation_failed()) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) collapse(2) if (multiThread) #endif @@ -8470,8 +8470,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f for (int dir = 1; dir < 4; dir++) { int Wlvl_L = Ldecomp.level_W(lvl); int Hlvl_L = Ldecomp.level_H(lvl); - - float ** WavCoeffs_L = Ldecomp.level_coeffs(lvl); + const float* const* WavCoeffs_L = Ldecomp.level_coeffs(lvl); madL[lvl][dir - 1] = SQR(Mad(WavCoeffs_L[dir], Wlvl_L * Hlvl_L)); } @@ -8636,7 +8635,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f noiseccb = 0.00001f; } - if (!adecomp.memoryAllocationFailed && !bdecomp.memoryAllocationFailed) { + if (!adecomp.memory_allocation_failed() && !bdecomp.memory_allocation_failed()) { float maxcfine = 0.f; float maxccoarse = 0.f; @@ -8889,7 +8888,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f } } - if (!Ldecomp.memoryAllocationFailed) { + if (!Ldecomp.memory_allocation_failed()) { Lin = new array2D(GW, GH); #ifdef _OPENMP #pragma omp parallel for if (multiThread) @@ -8903,13 +8902,13 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f Ldecomp.reconstruct(tmp1.L[0]); } - if (!Ldecomp.memoryAllocationFailed && aut == 0) { + if (!Ldecomp.memory_allocation_failed() && aut == 0) { if ((lp.noiself >= 0.01f || lp.noiself0 >= 0.01f || lp.noiself2 >= 0.01f || lp.noiselc >= 0.01f) && levred == 7 && lp.noiseldetail != 100.f) { fftw_denoise(GW, GH, max_numblox_W, min_numblox_W, tmp1.L, Lin, numThreads, lp, 0); } } - if (!adecomp.memoryAllocationFailed) { + if (!adecomp.memory_allocation_failed()) { Ain = new array2D(GW, GH); #ifdef _OPENMP #pragma omp parallel for if (multiThread) @@ -8924,14 +8923,14 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f } - if (!adecomp.memoryAllocationFailed && aut == 0) { + if (!adecomp.memory_allocation_failed() && aut == 0) { if ((lp.noisecf >= 0.01f || lp.noisecc >= 0.01f) && levred == 7 && lp.noisechrodetail != 100.f) { fftw_denoise(GW, GH, max_numblox_W, min_numblox_W, tmp1.a, Ain, numThreads, lp, 1); } } - if (!bdecomp.memoryAllocationFailed) { + if (!bdecomp.memory_allocation_failed()) { Bin = new array2D(GW, GH); #ifdef _OPENMP @@ -8947,7 +8946,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f } - if (!bdecomp.memoryAllocationFailed && aut == 0) { + if (!bdecomp.memory_allocation_failed() && aut == 0) { if ((lp.noisecf >= 0.01f || lp.noisecc >= 0.01f) && levred == 7 && lp.noisechrodetail != 100.f) { fftw_denoise(GW, GH, max_numblox_W, min_numblox_W, tmp1.b, Bin, numThreads, lp, 1); } @@ -9005,7 +9004,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f float madL[10][3]; int edge = 2; - if (!Ldecomp.memoryAllocationFailed) { + if (!Ldecomp.memory_allocation_failed()) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) collapse(2) if (multiThread) #endif @@ -9014,7 +9013,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f int Wlvl_L = Ldecomp.level_W(lvl); int Hlvl_L = Ldecomp.level_H(lvl); - float ** WavCoeffs_L = Ldecomp.level_coeffs(lvl); + const float* const* WavCoeffs_L = Ldecomp.level_coeffs(lvl); madL[lvl][dir - 1] = SQR(Mad(WavCoeffs_L[dir], Wlvl_L * Hlvl_L)); } @@ -9179,7 +9178,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f } - if (!adecomp.memoryAllocationFailed && !bdecomp.memoryAllocationFailed) { + if (!adecomp.memory_allocation_failed() && !bdecomp.memory_allocation_failed()) { float maxcfine = 0.f; float maxccoarse = 0.f; @@ -9430,7 +9429,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f } } - if (!Ldecomp.memoryAllocationFailed) { + if (!Ldecomp.memory_allocation_failed()) { Lin = new array2D(bfw, bfh); #ifdef _OPENMP @@ -9446,7 +9445,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f } - if (!Ldecomp.memoryAllocationFailed && aut == 0) { + if (!Ldecomp.memory_allocation_failed() && aut == 0) { if ((lp.noiself >= 0.01f || lp.noiself0 >= 0.01f || lp.noiself2 >= 0.01f || lp.noiselc >= 0.01f) && levred == 7 && lp.noiseldetail != 100.f) { @@ -9455,7 +9454,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f } - if (!adecomp.memoryAllocationFailed) { + if (!adecomp.memory_allocation_failed()) { Ain = new array2D(bfw, bfh); #ifdef _OPENMP #pragma omp parallel for if (multiThread) @@ -9469,14 +9468,14 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f adecomp.reconstruct(bufwv.a[0]); } - if (!adecomp.memoryAllocationFailed && aut == 0) { + if (!adecomp.memory_allocation_failed() && aut == 0) { if ((lp.noisecf >= 0.001f || lp.noisecc >= 0.001f) && levred == 7 && lp.noisechrodetail != 100.f) { fftw_denoise(bfw, bfh, max_numblox_W, min_numblox_W, bufwv.a, Ain, numThreads, lp, 1); } } - if (!bdecomp.memoryAllocationFailed) { + if (!bdecomp.memory_allocation_failed()) { Bin = new array2D(bfw, bfh); #ifdef _OPENMP #pragma omp parallel for if (multiThread) @@ -9490,7 +9489,7 @@ void ImProcFunctions::DeNoise(int call, int del, float * slidL, float * slida, f bdecomp.reconstruct(bufwv.b[0]); } - if (!bdecomp.memoryAllocationFailed && aut == 0) { + if (!bdecomp.memory_allocation_failed() && aut == 0) { if ((lp.noisecf >= 0.001f || lp.noisecc >= 0.001f) && levred == 7 && lp.noisechrodetail != 100.f) { fftw_denoise(bfw, bfh, max_numblox_W, min_numblox_W, bufwv.b, Bin, numThreads, lp, 1); } @@ -9551,7 +9550,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm wavelet_decomposition *wdspotresid = new wavelet_decomposition(tmpresid->L[0], tmpresid->W, tmpresid->H, wavelet_level, 1, sk, numThreads, lp.daubLen); - if (wdspotresid->memoryAllocationFailed) { + if (wdspotresid->memory_allocation_failed()) { return; } @@ -9565,7 +9564,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm for (int level = 0; level < maxlvlresid; ++level) { int W_L = wdspotresid->level_W(level); int H_L = wdspotresid->level_H(level); - float **wav_Lresid = wdspotresid->level_coeffs(level); + float* const* wav_Lresid = wdspotresid->level_coeffs(level); for (int i = 0; i < W_L * H_L; i++) { wav_Lresid[dir][i] = 0.f; @@ -9573,7 +9572,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm } } } else {//Sharp - float *wav_L0resid = wdspotresid->coeff0; + float *wav_L0resid = wdspotresid->get_coeff0(); int W_L = wdspotresid->level_W(0); int H_L = wdspotresid->level_H(0); @@ -9591,7 +9590,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm wavelet_decomposition *wdspotresida = new wavelet_decomposition(tmpresid->a[0], tmpresid->W, tmpresid->H, wavelet_level, 1, sk, numThreads, lp.daubLen); - if (wdspotresida->memoryAllocationFailed) { + if (wdspotresida->memory_allocation_failed()) { return; } @@ -9605,7 +9604,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm for (int level = 0; level < maxlvlresid; ++level) { int W_L = wdspotresida->level_W(level); int H_L = wdspotresida->level_H(level); - float **wav_Lresida = wdspotresida->level_coeffs(level); + float* const* wav_Lresida = wdspotresida->level_coeffs(level); for (int i = 0; i < W_L * H_L; i++) { wav_Lresida[dir][i] = 0.f; @@ -9613,7 +9612,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm } } } else {//Sharp - float *wav_L0resida = wdspotresida->coeff0; + float *wav_L0resida = wdspotresida->get_coeff0(); int W_L = wdspotresida->level_W(0); int H_L = wdspotresida->level_H(0); @@ -9627,7 +9626,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm wavelet_decomposition *wdspotresidb = new wavelet_decomposition(tmpresid->b[0], tmpresid->W, tmpresid->H, wavelet_level, 1, sk, numThreads, lp.daubLen); - if (wdspotresidb->memoryAllocationFailed) { + if (wdspotresidb->memory_allocation_failed()) { return; } @@ -9641,7 +9640,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm for (int level = 0; level < maxlvlresid; ++level) { int W_L = wdspotresidb->level_W(level); int H_L = wdspotresidb->level_H(level); - float **wav_Lresidb = wdspotresidb->level_coeffs(level); + float* const* wav_Lresidb = wdspotresidb->level_coeffs(level); for (int i = 0; i < W_L * H_L; i++) { wav_Lresidb[dir][i] = 0.f; @@ -9649,7 +9648,7 @@ void clarimerge(struct local_params& lp, float &mL, float &mC, bool &exec, LabIm } } } else {//Sharp - float *wav_L0residb = wdspotresidb->coeff0; + float *wav_L0residb = wdspotresidb->get_coeff0(); int W_L = wdspotresidb->level_W(0); int H_L = wdspotresidb->level_H(0); @@ -12019,11 +12018,11 @@ void ImProcFunctions::Lab_Local( wavelet_decomposition *wdspota = new wavelet_decomposition(tmp1->a[0], tmp1->W, tmp1->H, wavelet_level, 1, sk, numThreads, lp.daubLen); - if (wdspota->memoryAllocationFailed) { + if (wdspota->memory_allocation_failed()) { return; } - float *wav_ab0a = wdspota->coeff0; + float *wav_ab0a = wdspota->get_coeff0(); // int maxlvla = wdspota->maxlevel(); int W_La = wdspota->level_W(0); int H_La = wdspota->level_H(0); @@ -12070,12 +12069,11 @@ void ImProcFunctions::Lab_Local( wavelet_decomposition *wdspotb = new wavelet_decomposition(tmp1->b[0], tmp1->W, tmp1->H, wavelet_level, 1, sk, numThreads, lp.daubLen); - if (wdspotb->memoryAllocationFailed) { + if (wdspotb->memory_allocation_failed()) { return; } - float *wav_ab0b = wdspotb->coeff0; - // int maxlvlb = wdspotb->maxlevel(); + float *wav_ab0b = wdspotb->get_coeff0(); int W_Lb = wdspotb->level_W(0); int H_Lb = wdspotb->level_H(0); diff --git a/rtengine/ipwavelet.cc b/rtengine/ipwavelet.cc index ecdcd3cc2..1dc33e726 100644 --- a/rtengine/ipwavelet.cc +++ b/rtengine/ipwavelet.cc @@ -110,7 +110,6 @@ struct cont_params { bool lip3; bool tonemap; bool diag; - int TMmeth; float tmstrength; float balan; float sigmafin; @@ -891,7 +890,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const if (levwavL > 0) { const std::unique_ptr Ldecomp(new wavelet_decomposition(labco->data, labco->W, labco->H, levwavL, 1, skip, rtengine::max(1, wavNestedLevels), DaubLen)); - if (!Ldecomp->memoryAllocationFailed) { + if (!Ldecomp->memory_allocation_failed()) { float madL[10][3]; // float madL[8][3]; @@ -904,7 +903,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const int Wlvl_L = Ldecomp->level_W(lvl); int Hlvl_L = Ldecomp->level_H(lvl); - float ** WavCoeffs_L = Ldecomp->level_coeffs(lvl); + const float* const* WavCoeffs_L = Ldecomp->level_coeffs(lvl); madL[lvl][dir - 1] = SQR(Mad(WavCoeffs_L[dir], Wlvl_L * Hlvl_L)); @@ -1285,7 +1284,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const if (levwava > 0) { const std::unique_ptr adecomp(new wavelet_decomposition(labco->data + datalen, labco->W, labco->H, levwava, 1, skip, rtengine::max(1, wavNestedLevels), DaubLen)); - if (!adecomp->memoryAllocationFailed) { + if (!adecomp->memory_allocation_failed()) { if (cp.noiseena && ((cp.chromfi > 0.f || cp.chromco > 0.f) && cp.chromco < 2.f )) { WaveletDenoiseAllAB(*Ldecomp, *adecomp, noisevarchrom, madL, variC, edge, noisevarab_r, true, false, false, 1); } else if (cp.chromfi > 0.f && cp.chromco >= 2.f){ @@ -1322,7 +1321,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const if (levwavb > 0) { const std::unique_ptr bdecomp(new wavelet_decomposition(labco->data + 2 * datalen, labco->W, labco->H, levwavb, 1, skip, rtengine::max(1, wavNestedLevels), DaubLen)); - if (!bdecomp->memoryAllocationFailed) { + if (!bdecomp->memory_allocation_failed()) { if (cp.noiseena && ((cp.chromfi > 0.f || cp.chromco > 0.f) && cp.chromco < 2.f )) { WaveletDenoiseAllAB(*Ldecomp, *bdecomp, noisevarchrom, madL, variCb, edge, noisevarab_r, true, false, false, 1); } else if (cp.chromfi > 0.f && cp.chromco >= 2.f){ @@ -1338,12 +1337,6 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const } else {// a and b int levwavab = levwav; - if (!exblurab && cp.chrores == 0.f && cp.blurcres == 0.f && !hhutili && params->wavelet.CLmethod == "all") { // no processing of residual ab => we probably can reduce the number of levels - while (levwavab > 0 && (((cp.CHmet == 2 && (cp.chro == 0.f || cp.mul[levwavab - 1] == 0.f)) || (cp.CHmet != 2 && (levwavab == 10 || (!cp.curv || cp.mulC[levwavab - 1] == 0.f))))) && (!cp.opaRG || levwavab == 10 || (cp.opaRG && cp.mulopaRG[levwavab - 1] == 0.f)) && ((levwavab == 10 || (cp.CHSLmet == 1 && cp.mulC[levwavab - 1] == 0.f)))) { - levwavab--; - } - } - if (cp.chromfi > 0.f || cp.chromco > 0.f) { if (levwavab < 7) { levwavab = 7; @@ -1354,7 +1347,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const const std::unique_ptr adecomp(new wavelet_decomposition(labco->data + datalen, labco->W, labco->H, levwavab, 1, skip, rtengine::max(1, wavNestedLevels), DaubLen)); const std::unique_ptr bdecomp(new wavelet_decomposition(labco->data + 2 * datalen, labco->W, labco->H, levwavab, 1, skip, rtengine::max(1, wavNestedLevels), DaubLen)); - if (!adecomp->memoryAllocationFailed && !bdecomp->memoryAllocationFailed) { + if (!adecomp->memory_allocation_failed() && !bdecomp->memory_allocation_failed()) { if (cp.noiseena && ((cp.chromfi > 0.f || cp.chromco > 0.f) && cp.chromco < 2.f)) { WaveletDenoiseAllAB(*Ldecomp, *adecomp, noisevarchrom, madL, variC, edge, noisevarab_r, true, false, false, 1); } else if (cp.chromfi > 0.f && cp.chromco >= 2.f){ @@ -1634,7 +1627,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const } -void ImProcFunctions::Aver(float * RESTRICT DataList, int datalen, float &averagePlus, float &averageNeg, float &max, float &min) +void ImProcFunctions::Aver(const float* RESTRICT DataList, int datalen, float &averagePlus, float &averageNeg, float &max, float &min) { //find absolute mean @@ -1689,7 +1682,7 @@ void ImProcFunctions::Aver(float * RESTRICT DataList, int datalen, float &averag } -void ImProcFunctions::Sigma(float * RESTRICT DataList, int datalen, float averagePlus, float averageNeg, float &sigmaPlus, float &sigmaNeg) +void ImProcFunctions::Sigma(const float* RESTRICT DataList, int datalen, float averagePlus, float averageNeg, float &sigmaPlus, float &sigmaNeg) { int countP = 0, countN = 0; double variP = 0.0, variN = 0.0; // use double precision for large summations @@ -1734,7 +1727,7 @@ void ImProcFunctions::Evaluate2(const wavelet_decomposition &WaveletCoeffs_L, int Wlvl_L = WaveletCoeffs_L.level_W(lvl); int Hlvl_L = WaveletCoeffs_L.level_H(lvl); - float ** WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); + const float* const* WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); Eval2(WavCoeffs_L, lvl, Wlvl_L, Hlvl_L, mean, meanN, sigma, sigmaN, MaxP, MaxN); } @@ -1793,7 +1786,7 @@ void ImProcFunctions::calceffect(int level, float *mean, float *sigma, float *me mea[9] = offs * mean[level] + effect * 2.5f * sigma[level]; //99% } -void ImProcFunctions::Eval2(float ** WavCoeffs_L, int level, +void ImProcFunctions::Eval2(const float* const* WavCoeffs_L, int level, int W_L, int H_L, float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN) { @@ -1895,219 +1888,128 @@ void ImProcFunctions::CompressDR(float *Source, int W_L, int H_L, float Compress } -void ImProcFunctions::ContrastResid(float * WavCoeffs_L0, struct cont_params &cp, int W_L, int H_L, float max0, float min0) +void ImProcFunctions::ContrastResid(float * WavCoeffs_L0, const cont_params &cp, int W_L, int H_L, float max0) { - float stren = cp.tmstrength; - float gamm = params->wavelet.gamma; - cp.TMmeth = 2; //default after testing - - if (cp.TMmeth == 1) { - min0 = 0.0f; - max0 = 32768.f; - } else if (cp.TMmeth == 2) { - min0 = 0.0f; - } + const float stren = cp.tmstrength; + const float gamm = params->wavelet.gamma; #ifdef _OPENMP #pragma omp parallel for #endif for (int i = 0; i < W_L * H_L; i++) { - WavCoeffs_L0[i] = (WavCoeffs_L0[i] - min0) / max0; - WavCoeffs_L0[i] *= gamm; - } - - float Compression = expf(-stren); //This modification turns numbers symmetric around 0 into exponents. - float DetailBoost = stren; - - if (stren < 0.0f) { - DetailBoost = 0.0f; //Go with effect of exponent only if uncompressing. + WavCoeffs_L0[i] *= (gamm / max0); } + const float Compression = std::exp(-stren); //This modification turns numbers symmetric around 0 into exponents. + const float DetailBoost = std::max(stren, 0.f); //Go with effect of exponent only if uncompressing. CompressDR(WavCoeffs_L0, W_L, H_L, Compression, DetailBoost); - + max0 /= gamm; #ifdef _OPENMP #pragma omp parallel for // removed schedule(dynamic,10) #endif for (int ii = 0; ii < W_L * H_L; ii++) { - WavCoeffs_L0[ii] = WavCoeffs_L0[ii] * max0 * (1.f / gamm) + min0; + WavCoeffs_L0[ii] *= max0; } } - - - -void ImProcFunctions::EPDToneMapResid(float * WavCoeffs_L0, unsigned int Iterates, int skip, struct cont_params& cp, int W_L, int H_L, float max0, float min0) +void ImProcFunctions::EPDToneMapResid(float * WavCoeffs_L0, unsigned int Iterates, int skip, const cont_params& cp, int W_L, int H_L, float max0) { - float stren = cp.tmstrength; - float edgest = params->wavelet.edgs; - float sca = params->wavelet.scale; - float gamm = params->wavelet.gamma; - int rew = 0; //params->epd.reweightingIterates; + const float stren = cp.tmstrength; + const float edgest = params->wavelet.edgs; + const float sca = params->wavelet.scale; + const float gamm = params->wavelet.gamma; + constexpr int rew = 0; //params->epd.reweightingIterates; + EdgePreservingDecomposition epd2(W_L, H_L); - cp.TMmeth = 2; //default after testing - if (cp.TMmeth == 1) { - min0 = 0.0f; - max0 = 32768.f; - } else if (cp.TMmeth == 2) { - min0 = 0.0f; - } - - // max0=32768.f; #ifdef _OPENMP #pragma omp parallel for #endif for (int i = 0; i < W_L * H_L; i++) { - WavCoeffs_L0[i] = (WavCoeffs_L0[i] - min0) / max0; - WavCoeffs_L0[i] *= gamm; + WavCoeffs_L0[i] *= (gamm / max0); } - float Compression = expf(-stren); //This modification turns numbers symmetric around 0 into exponents. - float DetailBoost = stren; - - if (stren < 0.0f) { - DetailBoost = 0.0f; //Go with effect of exponent only if uncompressing. - } + const float Compression = std::exp(-stren); //This modification turns numbers symmetric around 0 into exponents. + const float DetailBoost = std::max(stren, 0.f); //Go with effect of exponent only if uncompressing. //Auto select number of iterates. Note that p->EdgeStopping = 0 makes a Gaussian blur. if (Iterates == 0) { Iterates = (unsigned int)(edgest * 15.0f); } + epd2.CompressDynamicRange(WavCoeffs_L0, sca / skip, edgest, Compression, DetailBoost, Iterates, rew); - epd2.CompressDynamicRange(WavCoeffs_L0, (float)sca / skip, edgest, Compression, DetailBoost, Iterates, rew); - + max0 /= gamm; //Restore past range, also desaturate a bit per Mantiuk's Color correction for tone mapping. #ifdef _OPENMP #pragma omp parallel for // removed schedule(dynamic,10) #endif for (int ii = 0; ii < W_L * H_L; ii++) { - WavCoeffs_L0[ii] = WavCoeffs_L0[ii] * max0 * (1.f / gamm) + min0; + WavCoeffs_L0[ii] *= max0; } } -void ImProcFunctions::WaveletcontAllLfinal(const wavelet_decomposition &WaveletCoeffs_L, const cont_params &cp, float *mean, float *sigma, float *MaxP, const WavOpacityCurveWL & waOpacityCurveWL) +void ImProcFunctions::WaveletcontAllLfinal(wavelet_decomposition& WaveletCoeffs_L, const cont_params &cp, float *mean, float *sigma, float *MaxP, const WavOpacityCurveWL & waOpacityCurveWL) { int maxlvl = WaveletCoeffs_L.maxlevel(); - float * WavCoeffs_L0 = WaveletCoeffs_L.coeff0; + float* WavCoeffs_L0 = WaveletCoeffs_L.get_coeff0(); for (int dir = 1; dir < 4; dir++) { for (int lvl = 0; lvl < maxlvl; lvl++) { int Wlvl_L = WaveletCoeffs_L.level_W(lvl); int Hlvl_L = WaveletCoeffs_L.level_H(lvl); - float ** WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); + float* const* WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); finalContAllL(WavCoeffs_L, WavCoeffs_L0, lvl, dir, cp, Wlvl_L, Hlvl_L, mean, sigma, MaxP, waOpacityCurveWL); } } } -void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float **varchrom, const wavelet_decomposition &WaveletCoeffs_L, const Wavblcurve & wavblcurve, +void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float **varchrom, wavelet_decomposition& WaveletCoeffs_L, const Wavblcurve & wavblcurve, struct cont_params &cp, int skip, float *mean, float *sigma, float *MaxP, float *MaxN, const WavCurve & wavCLVCcurve, const WavOpacityCurveW & waOpacityCurveW, const WavOpacityCurveSH & waOpacityCurveSH, FlatCurve* ChCurve, bool Chutili) { const int maxlvl = WaveletCoeffs_L.maxlevel(); const int W_L = WaveletCoeffs_L.level_W(0); const int H_L = WaveletCoeffs_L.level_H(0); - float * WavCoeffs_L0 = WaveletCoeffs_L.coeff0; + float* WavCoeffs_L0 = WaveletCoeffs_L.get_coeff0(); - float contrast = cp.contrast; + const float contrast = cp.contrast; double avedbl = 0.0; // use double precision for large summations float max0 = 0.f; - float min0 = FLT_MAX; - if (contrast != 0.f || (cp.tonemap && cp.resena)) { // contrast = 0.f means that all will be multiplied by 1.f, so we can skip this step + if (contrast != 0.f || (cp.tonemap && cp.resena)) { // contrast = 0.f means that all will be multiplied by 1.f, so we can skip this step #ifdef _OPENMP - #pragma omp parallel for reduction(+:avedbl) num_threads(wavNestedLevels) if (wavNestedLevels>1) + #pragma omp parallel for reduction(+:avedbl) reduction(max:max0) num_threads(wavNestedLevels) if (wavNestedLevels>1) #endif for (int i = 0; i < W_L * H_L; i++) { avedbl += static_cast(WavCoeffs_L0[i]); + max0 = std::max(WavCoeffs_L0[i], max0); } - -#ifdef _OPENMP - #pragma omp parallel num_threads(wavNestedLevels) if (wavNestedLevels>1) -#endif - { - float lminL = FLT_MAX; - float lmaxL = 0.f; - -#ifdef _OPENMP - #pragma omp for -#endif - - for (int i = 0; i < W_L * H_L; i++) { - if (WavCoeffs_L0[i] < lminL) { - lminL = WavCoeffs_L0[i]; - } - - if (WavCoeffs_L0[i] > lmaxL) { - lmaxL = WavCoeffs_L0[i]; - } - - } - -#ifdef _OPENMP - #pragma omp critical -#endif - { - if (lminL < min0) { - min0 = lminL; - } - - if (lmaxL > max0) { - max0 = lmaxL; - } - } - - } - } - //tone mapping - if (cp.tonemap && cp.contmet == 2 && cp.resena) { + if (cp.tonemap && cp.contmet == 2 && cp.resena) { //iterate = 5 - EPDToneMapResid(WavCoeffs_L0, 0, skip, cp, W_L, H_L, max0, min0); - + EPDToneMapResid(WavCoeffs_L0, 0, skip, cp, W_L, H_L, max0); } //end tonemapping max0 /= 327.68f; - min0 /= 327.68f; - float ave = avedbl / (double)(W_L * H_L); - float avg = ave / 32768.f; - float *koeLi[12]; - float maxkoeLi[12]; + const float ave = avedbl / (W_L * H_L); + const float avg = LIM01(ave / 32768.f); - float *koeLibuffer = nullptr; - - for (int y = 0; y < 12; y++) { - maxkoeLi[y] = 0.f; //9 - } - - koeLibuffer = new float[12 * H_L * W_L]; //12 - - for (int i = 0; i < 12; i++) { //9 - koeLi[i] = &koeLibuffer[i * W_L * H_L]; - } - - for (int j = 0; j < 12; j++) //9 - for (int i = 0; i < W_L * H_L; i++) { - koeLi[j][i] = 0.f; - } - - avg = LIM01(avg); - double contreal = 0.6 * contrast; + const double contreal = 0.6 * contrast; DiagonalCurve resid_contrast({ DCT_NURBS, 0, 0, @@ -2116,43 +2018,29 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float * 1, 1 }); + if (contrast != 0.f && cp.resena && max0 > 0.f) { // contrast = 0.f means that all will be multiplied by 1.f, so we can skip this step #ifdef _OPENMP - #pragma omp parallel num_threads(wavNestedLevels) if (wavNestedLevels>1) -#endif - { - if (contrast != 0.f && cp.resena && max0 > 0.f) { // contrast = 0.f means that all will be multiplied by 1.f, so we can skip this step - { - -#ifdef _OPENMP - #pragma omp for + #pragma omp parallel for num_threads(wavNestedLevels) if (wavNestedLevels>1) #endif - for (int i = 0; i < W_L * H_L; i++) { - float buf = LIM01(WavCoeffs_L0[i] / 32768.f); - buf = resid_contrast.getVal(buf); - buf *= 32768.f; - WavCoeffs_L0[i] = buf; - } - } - } - - - if (cp.tonemap && cp.contmet == 1 && cp.resena) { - float maxp = max0 * 256.f; - float minp = min0 * 256.f; -#ifdef _OPENMP - #pragma omp single -#endif - ContrastResid(WavCoeffs_L0, cp, W_L, H_L, maxp, minp); + for (int i = 0; i < W_L * H_L; i++) { + float buf = LIM01(WavCoeffs_L0[i] / 32768.f); + buf = resid_contrast.getVal(buf); + buf *= 32768.f; + WavCoeffs_L0[i] = buf; } } - if ((cp.conres >= 0.f || cp.conresH >= 0.f) && cp.resena && !cp.oldsh) { // cp.conres = 0.f and cp.comresH = 0.f means that all will be multiplied by 1.f, so we can skip this step - LabImage *temp = nullptr; - temp = new LabImage(W_L, H_L); + if (cp.tonemap && cp.contmet == 1 && cp.resena) { + const float maxp = max0 * 256.f; + ContrastResid(WavCoeffs_L0, cp, W_L, H_L, maxp); + } + + if ((cp.conres >= 0.f || cp.conresH >= 0.f) && cp.resena && !cp.oldsh) { // cp.conres = 0.f and cp.comresH = 0.f means that all will be multiplied by 1.f, so we can skip this step + const std::unique_ptr temp(new LabImage(W_L, H_L)); #ifdef _OPENMP - #pragma omp for + #pragma omp parallel for num_threads(wavNestedLevels) if (wavNestedLevels>1) #endif for (int i = 0; i < H_L; i++) { @@ -2161,12 +2049,10 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float * } } - { - ImProcFunctions::shadowsHighlights(temp, true, 1, cp.conresH, cp.conres, cp.radius, skip, cp.thH, cp.th); - } + ImProcFunctions::shadowsHighlights(temp.get(), true, 1, cp.conresH, cp.conres, cp.radius, skip, cp.thH, cp.th); #ifdef _OPENMP - #pragma omp for + #pragma omp parallel for num_threads(wavNestedLevels) if (wavNestedLevels>1) #endif for (int i = 0; i < H_L; i++) { @@ -2174,18 +2060,11 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float * WavCoeffs_L0[i * W_L + j] = temp->L[i][j]; } } - - delete temp; - } -#ifdef _OPENMP - #pragma omp barrier -#endif - if ((cp.conres != 0.f || cp.conresH != 0.f) && cp.resena && cp.oldsh) { // cp.conres = 0.f and cp.comresH = 0.f means that all will be multiplied by 1.f, so we can skip this step #ifdef _OPENMP - #pragma omp for nowait + #pragma omp parallel for #endif for (int i = 0; i < W_L * H_L; i++) { @@ -2256,6 +2135,14 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float * int n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n32; n0 = n1 = n2 = n3 = n4 = n5 = n6 = n7 = n8 = n9 = n10 = n32 = 0; + float *koeLi[12]; + + const std::unique_ptr koeLibuffer(new float[12 * H_L * W_L]()); + + for (int i = 0; i < 12; i++) { + koeLi[i] = &koeLibuffer[i * W_L * H_L]; + } + #ifdef _OPENMP #pragma omp parallel num_threads(wavNestedLevels) if (wavNestedLevels>1) #endif @@ -2270,10 +2157,10 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float * constexpr float eddlow = 15.f; float eddlipinfl = 0.005f * cp.edgsens + 0.4f; float eddlipampl = 1.f + cp.edgampl / 50.f; - + float maxkoeLi[12] = {0.f}; if (cp.detectedge) { //enabled Lipschitz control...more memory..more time... - float *tmCBuffer = new float[H_L * W_L]; + const std::unique_ptr tmCBuffer(new float[H_L * W_L]); float *tmC[H_L]; for (int i = 0; i < H_L; i++) { @@ -2288,15 +2175,14 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float * for (int lvl = 0; lvl < 4; lvl++) { for (int dir = 1; dir < 4; dir++) { - float ** WavCoeffs_LL = WaveletCoeffs_L.level_coeffs(lvl); - // calckoe(WavCoeffs_LL, cp, koeLi, lvl, dir, WaveletCoeffs_L.level_W(lvl), WaveletCoeffs_L.level_H(lvl), edd, maxkoeLi, tmC); - calckoe (WavCoeffs_LL, gradw, tloww, koeLi, lvl , dir, W_L, H_L, edd, maxkoeLi, tmC); + const float* const* WavCoeffs_LL = WaveletCoeffs_L.level_coeffs(lvl); + float tempkoeli; + calckoe (WavCoeffs_LL, gradw, tloww, koeLi, lvl , dir, W_L, H_L, edd, tempkoeli, tmC); + maxkoeLi[lvl * 3 + dir - 1] = tempkoeli; // return convolution KoeLi and maxkoeLi of level 0 1 2 3 and Dir Horiz, Vert, Diag } } - delete [] tmCBuffer; - float aamp = 1.f + cp.eddetthrHi / 100.f; for (int lvl = 0; lvl < 4; lvl++) { @@ -2412,10 +2298,9 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float * int Wlvl_L = WaveletCoeffs_L.level_W(lvl); int Hlvl_L = WaveletCoeffs_L.level_H(lvl); - float ** WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); + float* const* WavCoeffs_L = WaveletCoeffs_L.level_coeffs(lvl); -// ContAllL(koeLi, maxkoeLi, true, maxlvl, labco, varhue, varchrom, WavCoeffs_L, WavCoeffs_L0, lvl, dir, cp, Wlvl_L, Hlvl_L, skip, mean, sigma, MaxP, MaxN, wavCLVCcurve, waOpacityCurveW, ChCurve, Chutili); - ContAllL(koeLi, maxkoeLi, true, maxlvl, labco, varhue, varchrom, WavCoeffs_L, WavCoeffs_L0, lvl, dir, cp, Wlvl_L, Hlvl_L, skip, mean, sigma, MaxP, MaxN, wavCLVCcurve, waOpacityCurveW, waOpacityCurveSH, ChCurve, Chutili); + ContAllL(koeLi, maxkoeLi[lvl * 3 + dir - 1], true, maxlvl, labco, varhue, varchrom, WavCoeffs_L, WavCoeffs_L0, lvl, dir, cp, Wlvl_L, Hlvl_L, skip, mean, sigma, MaxP, MaxN, wavCLVCcurve, waOpacityCurveW, waOpacityCurveSH, ChCurve, Chutili); int minWL = min(Wlvl_L, Hlvl_L); if(minWL > 180) { @@ -2500,14 +2385,9 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float * } } } - - //delete edge detection - if (koeLibuffer) { - delete [] koeLibuffer; - } } -void ImProcFunctions::WaveletAandBAllAB(const wavelet_decomposition &WaveletCoeffs_a, const wavelet_decomposition &WaveletCoeffs_b, +void ImProcFunctions::WaveletAandBAllAB(wavelet_decomposition& WaveletCoeffs_a, wavelet_decomposition& WaveletCoeffs_b, const cont_params &cp, FlatCurve* hhCurve, bool hhutili) { // StopWatch Stop1("WaveletAandBAllAB"); @@ -2515,8 +2395,8 @@ void ImProcFunctions::WaveletAandBAllAB(const wavelet_decomposition &WaveletCoef int W_L = WaveletCoeffs_a.level_W(0); int H_L = WaveletCoeffs_a.level_H(0); - float * WavCoeffs_a0 = WaveletCoeffs_a.coeff0; - float * WavCoeffs_b0 = WaveletCoeffs_b.coeff0; + float* WavCoeffs_a0 = WaveletCoeffs_a.get_coeff0(); + float* WavCoeffs_b0 = WaveletCoeffs_b.get_coeff0(); #ifdef _OPENMP #pragma omp parallel num_threads(wavNestedLevels) if (wavNestedLevels>1) #endif @@ -2573,7 +2453,7 @@ void ImProcFunctions::WaveletAandBAllAB(const wavelet_decomposition &WaveletCoef } -void ImProcFunctions::WaveletcontAllAB(LabImage * labco, float ** varhue, float **varchrom, const wavelet_decomposition &WaveletCoeffs_ab, const Wavblcurve & wavblcurve, const WavOpacityCurveW & waOpacityCurveW, +void ImProcFunctions::WaveletcontAllAB(LabImage * labco, float ** varhue, float **varchrom, wavelet_decomposition& WaveletCoeffs_ab, const Wavblcurve & wavblcurve, const WavOpacityCurveW & waOpacityCurveW, struct cont_params &cp, const bool useChannelA, int skip, float *meanab, float *sigmaab) { @@ -2581,7 +2461,7 @@ void ImProcFunctions::WaveletcontAllAB(LabImage * labco, float ** varhue, float int W_L = WaveletCoeffs_ab.level_W(0); int H_L = WaveletCoeffs_ab.level_H(0); - float * WavCoeffs_ab0 = WaveletCoeffs_ab.coeff0; + float* WavCoeffs_ab0 = WaveletCoeffs_ab.get_coeff0(); #ifdef _OPENMP #pragma omp parallel num_threads(wavNestedLevels) if (wavNestedLevels>1) @@ -2730,7 +2610,7 @@ void ImProcFunctions::WaveletcontAllAB(LabImage * labco, float ** varhue, float int Wlvl_ab = WaveletCoeffs_ab.level_W(lvl); int Hlvl_ab = WaveletCoeffs_ab.level_H(lvl); - float ** WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(lvl); + float* const* WavCoeffs_ab = WaveletCoeffs_ab.level_coeffs(lvl); ContAllAB(labco, maxlvl, varhue, varchrom, WavCoeffs_ab, WavCoeffs_ab0, lvl, dir, waOpacityCurveW, cp, Wlvl_ab, Hlvl_ab, useChannelA, meanab, sigmaab); int minWL = min(Wlvl_ab, Hlvl_ab); @@ -2811,7 +2691,7 @@ void ImProcFunctions::WaveletcontAllAB(LabImage * labco, float ** varhue, float //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //void ImProcFunctions::calckoe(float ** WavCoeffs_LL, const cont_params& cp, float *koeLi[12], int level, int dir, int W_L, int H_L, float edd, float *maxkoeLi, float **tmC) -void ImProcFunctions::calckoe (float ** WavCoeffs_LL, float gradw, float tloww, float *koeLi[12], int level, int dir, int W_L, int H_L, float edd, float *maxkoeLi, float **tmC) +void ImProcFunctions::calckoe (const float* const* WavCoeffs_LL, float gradw, float tloww, float *koeLi[12], int level, int dir, int W_L, int H_L, float edd, float &maxkoeLi, float **tmC) { int borderL = 2; @@ -2937,19 +2817,19 @@ void ImProcFunctions::calckoe (float ** WavCoeffs_LL, float gradw, float tloww, koeLi[level * 3 + dir - 1][i * W_L + j] = rtengine::min(thr2, std::fabs(tmC[i][j] / temp)); // limit maxi //it will be more complicated to calculate both Wh and Wv, but we have also Wd==> pseudo Lipschitz - if (koeLi[level * 3 + dir - 1][i * W_L + j] > maxkoeLi[level * 3 + dir - 1]) { - maxkoeLi[level * 3 + dir - 1] = koeLi[level * 3 + dir - 1][i * W_L + j]; + if (koeLi[level * 3 + dir - 1][i * W_L + j] > maxkoeLi) { + maxkoeLi = koeLi[level * 3 + dir - 1][i * W_L + j]; } - float diff = maxkoeLi[level * 3 + dir - 1] - koeLi[level * 3 + dir - 1][i * W_L + j]; + float diff = maxkoeLi - koeLi[level * 3 + dir - 1][i * W_L + j]; diff *= diffFactor; - koeLi[level * 3 + dir - 1][i * W_L + j] = maxkoeLi[level * 3 + dir - 1] - diff; + koeLi[level * 3 + dir - 1][i * W_L + j] = maxkoeLi - diff; } } } -void ImProcFunctions::finalContAllL(float ** WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, const cont_params &cp, +void ImProcFunctions::finalContAllL(float* const* WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, const cont_params &cp, int W_L, int H_L, float *mean, float *sigma, float *MaxP, const WavOpacityCurveWL & waOpacityCurveWL) { if (cp.diagcurv && cp.finena && MaxP[level] > 0.f && mean[level] != 0.f && sigma[level] != 0.f) { //curve @@ -3103,7 +2983,7 @@ void ImProcFunctions::finalContAllL(float ** WavCoeffs_L, float * WavCoeffs_L0, } -void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz, int maxlvl, LabImage * labco, float ** varhue, float **varchrom, float ** WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, struct cont_params &cp, +void ImProcFunctions::ContAllL(float *koeLi[12], float maxkoeLi, bool lipschitz, int maxlvl, LabImage * labco, const float* const* varhue, const float* const* varchrom, float* const* 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, const WavOpacityCurveSH & waOpacityCurveSH, FlatCurve* ChCurve, bool Chutili) { assert(level >= 0); @@ -3359,7 +3239,7 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz if (lipschitz) { if (level < 4) { - edge = 1.f + (edgePrecalc - 1.f) * (koeLi[level * 3][k]) / (1.f + 0.9f * maxkoeLi[level * 3 + dir - 1]); + edge = 1.f + (edgePrecalc - 1.f) * (koeLi[level * 3][k]) / (1.f + 0.9f * maxkoeLi); } else { edge = edgePrecalc; } @@ -3465,7 +3345,7 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz if (lipschitz) { if (level < 4) { - edge = 1.f + (edgePrecalc - 1.f) * (koeLi[level * 3][k]) / (1.f + 0.9f * maxkoeLi[level * 3 + dir - 1]); + edge = 1.f + (edgePrecalc - 1.f) * (koeLi[level * 3][k]) / (1.f + 0.9f * maxkoeLi); } else { edge = edgePrecalc; } @@ -3894,7 +3774,7 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz // choicelevel = choicelevel == -1 ? 4 : choicelevel; } -void ImProcFunctions::ContAllAB(LabImage * labco, int maxlvl, float ** varhue, float **varchrom, float ** WavCoeffs_ab, float * WavCoeffs_ab0, int level, int dir, const WavOpacityCurveW & waOpacityCurveW, struct cont_params &cp, +void ImProcFunctions::ContAllAB(LabImage * labco, int maxlvl, float ** varhue, float **varchrom, float* const* WavCoeffs_ab, float * WavCoeffs_ab0, int level, int dir, const WavOpacityCurveW & waOpacityCurveW, struct cont_params &cp, int W_ab, int H_ab, const bool useChannelA, float *meanab, float *sigmaab) { float cpMul = cp.mul[level]; diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index cad0d7f4f..1c5451b34 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -498,11 +498,10 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog // dcraw needs this global variable to hold pixel data image = (dcrawImage_t)calloc (static_cast(height) * static_cast(width) * sizeof * image + meta_length, 1); - meta_data = (char *) (image + static_cast(height) * static_cast(width)); - - if (!image) { + if(!image) { return 200; } + meta_data = (char *) (image + static_cast(height) * static_cast(width)); /* Issue 2467 if (setjmp (failure)) { diff --git a/rtexif/rtexif.cc b/rtexif/rtexif.cc index 95b46c2b9..c0038c067 100644 --- a/rtexif/rtexif.cc +++ b/rtexif/rtexif.cc @@ -3059,19 +3059,14 @@ void ExifManager::parse (bool isRaw, bool skipIgnored, bool parseJpeg) bool frameRootDetected = false; - if(!frameRootDetected) { - std::vector risTagList = root->findTags("RawImageSegmentation"); - if (!risTagList.empty()) { - for (auto ris : risTagList) { - frames.push_back(ris->getParent()); - frameRootDetected = true; + for (auto ris : root->findTags("RawImageSegmentation")) { + frames.push_back(ris->getParent()); + frameRootDetected = true; - #if PRINT_METADATA_TREE - printf("\n--------------- FRAME (RAWIMAGESEGMENTATION) ---------------\n\n"); - ris->getParent()->printAll (); - #endif - } - } +#if PRINT_METADATA_TREE + printf("\n--------------- FRAME (RAWIMAGESEGMENTATION) ---------------\n\n"); + ris->getParent()->printAll (); +#endif } if(!frameRootDetected) { diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 102c17daf..42a2263e2 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -2446,6 +2446,8 @@ bool FileCatalog::handleShortcutKey (GdkEventKey* event) case GDK_KEY_underscore: zoomOut(); return true; + default: // do nothing, avoids a cppcheck false positive + break; } } diff --git a/rtgui/main.cc b/rtgui/main.cc index 0c35c0ef8..7bb4afdc9 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -441,7 +441,7 @@ int main (int argc, char **argv) if (argc > 1) { if (!remote && !Glib::file_test (argv1, Glib::FILE_TEST_EXISTS ) && !Glib::file_test (argv1, Glib::FILE_TEST_IS_DIR)) { - bool stdoutRedirecttoConsole = (GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)) == 0x0000); + const bool stdoutRedirecttoConsole = (GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)) == 0x0000); // open console, if stdout is invalid if (stdoutRedirecttoConsole) { // check if parameter -w was passed. @@ -473,10 +473,9 @@ int main (int argc, char **argv) cursorInfo.bVisible = false; SetConsoleCursorInfo ( GetStdHandle ( STD_OUTPUT_HANDLE ), &cursorInfo ); - if (stdoutRedirecttoConsole) { // if stdout is Redirect to console, we also redirect stderr to console - freopen ( "CON", "w", stdout ) ; - freopen ( "CON", "w", stderr ) ; - } + // we also redirect stderr to console + freopen ( "CON", "w", stdout ) ; + freopen ( "CON", "w", stderr ) ; freopen ( "CON", "r", stdin ) ; diff --git a/rtgui/thumbnail.cc b/rtgui/thumbnail.cc index c5ae27c95..c1884edeb 100644 --- a/rtgui/thumbnail.cc +++ b/rtgui/thumbnail.cc @@ -875,7 +875,7 @@ void Thumbnail::_loadThumbnail(bool firstTrial) if (!succ && firstTrial) { _generateThumbnailImage (); - if (cfs.supported && firstTrial) { + if (cfs.supported) { _loadThumbnail (false); }