make ipwavelets.cc cppcheck clean

This commit is contained in:
Ingo Weyrich
2020-05-11 22:33:43 +02:00
parent e09ab88c1c
commit 8581799a7a
2 changed files with 72 additions and 333 deletions

View File

@@ -188,7 +188,6 @@ public:
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 CompressDR(float *Source, int W_L, int H_L, float Compression, float DetailBoost);
void Compresslevels2(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 EPDToneMap(LabImage *lab, unsigned int Iterates = 0, int skip = 1);
@@ -228,9 +227,6 @@ public:
void Sigma(float * HH_Coeffs, int datalen, float averagePlus, float averageNeg, float &sigmaPlus, float &sigmaNeg);
void calckoe(float ** WavCoeffs_LL, const cont_params& cp, float ** koeLi, int level, int dir, int W_L, int H_L, float edd, float *maxkoeLi, float **tmC = nullptr);
void softproc2(const LabImage* bufcolorig, const LabImage* bufcolfin, float rad, int bfh, int bfw, double epsilmax, double epsilmin, float thres, int sk, bool multiThread, int flag);
void Median_Denoise(float **src, float **dst, int width, int height, Median medianType, int iterations, int numThreads, float **buffer = nullptr);
void Median_Denoise(float **src, float **dst, float upperBound, int width, int height, Median medianType, int iterations, int numThreads, float **buffer = nullptr);
void RGB_denoise(int kall, Imagefloat * src, Imagefloat * dst, Imagefloat * calclum, float * ch_M, float *max_r, float *max_b, bool isRAW, const procparams::DirPyrDenoiseParams & dnparams, const double expcomp, const NoiseCurve & noiseLCurve, const NoiseCurve & noiseCCurve, float &nresi, float &highresi);

View File

@@ -540,11 +540,6 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const
levwav = rtengine::min(maxlevelcrop, levwav);
// determine number of levels to process.
// for(levwav=rtengine::min(maxlevelcrop,levwav);levwav>0;levwav--)
// if(cp.mul[levwav-1]!=0.f || cp.curv)
// if(cp.mul[levwav-1]!=0.f)
// break;
// I suppress this fonctionality ==> crash for level < 3
if (levwav < 1) {
return; // nothing to do
@@ -901,9 +896,9 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const
if (levwavL > 0) {
const std::unique_ptr<wavelet_decomposition> Ldecomp(new wavelet_decomposition(labco->data, labco->W, labco->H, levwavL, 1, skip, rtengine::max(1, wavNestedLevels), DaubLen));
float madL[10][3];
if (!Ldecomp->memoryAllocationFailed) {
float madL[10][3];
// float madL[8][3];
#ifdef _OPENMP
@@ -1297,7 +1292,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const
const std::unique_ptr<wavelet_decomposition> adecomp(new wavelet_decomposition(labco->data + datalen, labco->W, labco->H, levwava, 1, skip, rtengine::max(1, wavNestedLevels), DaubLen));
if (!adecomp->memoryAllocationFailed) {
if (cp.noiseena && (cp.chromfi > 0.f || cp.chromfi > 0.f)) {
if (cp.noiseena && (cp.chromfi > 0.f || cp.chromco > 0.f)) {
WaveletDenoiseAll_BiShrinkAB(*Ldecomp, *adecomp, noisevarchrom, madL, variC, edge, noisevarab_r, true, false, false, 1);
WaveletDenoiseAllAB(*Ldecomp, *adecomp, noisevarchrom, madL, variC, edge, noisevarab_r, true, false, false, 1);
}
@@ -1331,7 +1326,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const
const std::unique_ptr<wavelet_decomposition> bdecomp(new wavelet_decomposition(labco->data + 2 * datalen, labco->W, labco->H, levwavb, 1, skip, rtengine::max(1, wavNestedLevels), DaubLen));
if (!bdecomp->memoryAllocationFailed) {
if (cp.noiseena && (cp.chromfi > 0.f || cp.chromfi > 0.f)) {
if (cp.noiseena && (cp.chromfi > 0.f || cp.chromco > 0.f)) {
WaveletDenoiseAll_BiShrinkAB(*Ldecomp, *bdecomp, noisevarchrom, madL, variCb, edge, noisevarab_r, true, false, false, 1);
WaveletDenoiseAllAB(*Ldecomp, *bdecomp, noisevarchrom, madL, variCb, edge, noisevarab_r, true, false, false, 1);
}
@@ -1361,7 +1356,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const
const std::unique_ptr<wavelet_decomposition> 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 (cp.noiseena && (cp.chromfi > 0.f || cp.chromfi > 0.f)) {
if (cp.noiseena && (cp.chromfi > 0.f || cp.chromco > 0.f)) {
WaveletDenoiseAll_BiShrinkAB(*Ldecomp, *adecomp, noisevarchrom, madL, variC, edge, noisevarab_r, true, false, false, 1);
WaveletDenoiseAllAB(*Ldecomp, *adecomp, noisevarchrom, madL, variC, edge, noisevarab_r, true, false, false, 1);
}
@@ -1372,7 +1367,7 @@ void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int kall, const
WaveletDenoiseAllAB(*Ldecomp, *bdecomp, noisevarchrom, madL, variCb, edge, noisevarab_r, true, false, false, 1);
Evaluate2(*bdecomp, meanab, meanNab, sigmaab, sigmaNab, MaxPab, MaxNab);
if (cp.noiseena && (cp.chromfi > 0.f || cp.chromfi > 0.f)) {
if (cp.noiseena && (cp.chromfi > 0.f || cp.chromco > 0.f)) {
WaveletcontAllAB(labco, varhue, varchro, *bdecomp, wavblcurve, waOpacityCurveW, cp, false, skip, meanab, sigmaab);
WaveletAandBAllAB(*adecomp, *bdecomp, cp, hhCurve, hhutili);
}
@@ -2209,13 +2204,13 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float *
float LL100 = LL / 327.68f;
float tran = 5.f;//transition
//shadow
float alp = 3.f; //increase contrast sahdow in lowlights between 1 and ??
if (cp.th > (100.f - tran)) {
tran = 100.f - cp.th;
}
if (LL100 < cp.th) {
constexpr float alp = 3.f; //increase contrast sahdow in lowlights between 1 and ??
float aalp = (1.f - alp) / cp.th; //no changes for LL100 = cp.th
float kk = aalp * LL100 + alp;
WavCoeffs_L0[i] *= (1.f + kk * cp.conres / 200.f);
@@ -2245,10 +2240,10 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float *
//Blur luma
if (cp.blurres != 0.f && cp.resena) {
int minWL = min(W_L, H_L);
float k = 0.5f;
//printf("skip=%i WL=%i HL=%i min=%i\n", skip, W_L, H_L, minWL);
if (minWL > 140) { //disabled if too low windows
constexpr float k = 0.5f;
float rad = k * cp.blurres / skip;
float * bef = new float[W_L * H_L];
float * aft = new float[W_L * H_L];
@@ -2374,12 +2369,10 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float *
//if not no edge or reduction
float bet = 1.f;
//if(cp.lip3) {//enhance algorithm
if (alph > eddlipinfl && beta < 0.85f * eddlipinfl) { //0.85 arbitrary value ==> eliminate from edge if H V D too different
bet = beta;
}
//}
float AmpLip = 1.f;
if (alph > eddlipinfl) {
@@ -2390,16 +2383,6 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float *
kampli = AmpLip / aamp;
}
// comparison betwwen pixel and neighbours to do ==> I think 3 dir above is better
/* if(cp.lip3){
koeLi[lvl*3][i*W_L + j] = (koeLi[lvl*3][i*W_L + j] + koeLi[lvl*3][(i-1)*W_L + j] + koeLi[lvl*3][(i+1)*W_L + j]
+ koeLi[lvl*3][i*W_L + j+1] + koeLi[lvl*3][i*W_L + j-1] + koeLi[lvl*3][(i-1)*W_L + j-1]
+ koeLi[lvl*3][(i-1)*W_L + j+1] +koeLi[lvl*3][(i+1)*W_L + j-1] +koeLi[lvl*3][(i+1)*W_L + j+1])/9.f;
}
*/
// apply to each direction Wavelet level : horizontal / vertiacle / diagonal
//interm += SQR(koeLi[lvl*3 + dir-1][i*W_L + j]);
interm *= kampli;
if (interm < cp.eddetthr / eddlow) {
@@ -2440,20 +2423,14 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float *
float ** 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);
//blur level
float klev = 1.f;
if (wavblcurve && wavcurvecomp && cp.blena) {
// printf("Blur level L\n");
float mea[10];
float effect = cp.bluwav;
float offs = 1.f;
const float effect = cp.bluwav;
constexpr float offs = 1.f;
float * beta = new float[Wlvl_L * Hlvl_L];
for (int co = 0; co < Hlvl_L * Wlvl_L; co++) {
beta[co] = 1.f;
}
calceffect(lvl, mean, sigma, mea, effect, offs);
float * bef = new float[Wlvl_L * Hlvl_L];
@@ -2509,8 +2486,9 @@ void ImProcFunctions::WaveletcontAllL(LabImage * labco, float ** varhue, float *
printf("lvl=%i n0=%i n32=%i n1=%i n2=%i n3=%i n4=%i n5=%i n6=%i n7=%i n8=%i n9=%i n10=%i\n", lvl, n0, n0 - n32, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10);
}
klev = (wavblcurve[lvl * 55.5f]);
float klev = (wavblcurve[lvl * 55.5f]);
//blur level
// klev *= beta * 100.f / skip;
klev *= 100.f / skip;
boxblur(bef, aft, klev, Wlvl_L, Hlvl_L, false);
@@ -2646,20 +2624,6 @@ void ImProcFunctions::WaveletcontAllAB(LabImage * labco, float ** varhue, float
if ((modhue > cp.t_ry || modhue < cp.t_ly)) {
scale = (100.f + cp.sky) / 100.1f;
}
/* else if((modhue >= cp.t_ry && modhue < cp.b_ry)) {
scale=(100.f+cp.sky)/100.1f;
float ar=(scale-1.f)/(cp.t_ry- cp.b_ry);
float br=scale-cp.t_ry*ar;
scale=ar*modhue+br;
}
else if((modhue > cp.b_ly && modhue < cp.t_ly)) {
scale=(100.f+cp.sky)/100.1f;
float al=(scale-1.f)/(-cp.b_ly + cp.t_ly);
float bl=scale-cp.t_ly*al;
scale=al*modhue+bl;
}
*/
}
WavCoeffs_ab0[i] *= (1.f + cp.chrores * (scale) / 100.f);
@@ -2727,10 +2691,10 @@ void ImProcFunctions::WaveletcontAllAB(LabImage * labco, float ** varhue, float
//Blur chroma
if (cp.blurcres != 0.f && cp.resena) {
int minWL = min(W_L, H_L);
float k = 0.5f;
//printf("skip=%i WL=%i HL=%i min=%i\n", skip, W_L, H_L, minWL);
if (minWL > 140) { //disabled if too low windows
constexpr float k = 0.5f;
float rad = k * cp.blurcres / skip;
float * bef = new float[W_L * H_L];
float * aft = new float[W_L * H_L];
@@ -2908,9 +2872,7 @@ void ImProcFunctions::calckoe(float ** WavCoeffs_LL, const cont_params& cp, floa
else if (cp.eddetthr >= 75.f) {
borderL = 2;
//if(cp.lip3 && level > 1) {
if (level > 1) { // do not activate 5x5 if level 0 or 1
for (int i = 2; i < H_L - 2; i++) {
for (int j = 2; j < W_L - 2; j++) {
// Gaussian 1.1
@@ -2958,21 +2920,6 @@ void ImProcFunctions::calckoe(float ** WavCoeffs_LL, const cont_params& cp, floa
}
/*
// I suppress these 2 convolutions ==> lees good results==> probably because structure data different and also I compare to original value which have + and -
for(int i = borderL; i < H_L-borderL; i++ ) {//[-1 0 1] x==>j
for(int j = borderL; j < W_L-borderL; j++) {
tmC[i][j]=- WavCoeffs_LL[dir][(i)*W_L + j-1] + WavCoeffs_LL[dir][(i)*W_L + j+1];
}
}
for(int i = borderL; i < H_L-borderL; i++ ) {//[1 0 -1] y==>i
for(int j = borderL; j < W_L-borderL; j++) {
tmC[i][j]= - WavCoeffs_LL[dir][(i-1)*W_L + j] + WavCoeffs_LL[dir][(i+1)*W_L + j];
}
}
*/
float thr = 40.f; //avoid artifact eg. noise...to test
float thr2 = 1.5f * edd; //edd can be modified in option ed_detect
thr2 += cp.eddet / 30.f; //to test
@@ -2988,9 +2935,6 @@ void ImProcFunctions::calckoe(float ** WavCoeffs_LL, const cont_params& cp, floa
for (int j = borderL; j < W_L - borderL; j++) {
// my own algo : probably a little false, but simpler as Lipschitz !
// Thr2 = maximum of the function ==> Lipsitch says = probably edge
// float temp = WavCoeffs_LL[dir][i*W_L + j];
// if(temp>=0.f && temp < thr) temp = thr;
// if(temp < 0.f && temp > -thr) temp = -thr;
float temp = rtengine::max(std::fabs(WavCoeffs_LL[dir][i * W_L + j]), thr);
koeLi[level * 3 + dir - 1][i * W_L + j] = rtengine::min(thr2, std::fabs(tmC[i][j] / temp)); // limit maxi
@@ -3186,9 +3130,7 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
constexpr float aedstr = (eddstrength - 1.f) / 90.f;
constexpr float bedstr = 1.f - 10.f * aedstr;
float mea[10];
// float beta = 1.f;
float * beta = new float[W_L * H_L];
std::unique_ptr<float[]> beta(new float[W_L * H_L]);
for (int co = 0; co < H_L * W_L; co++) {
beta[co] = 1.f;
@@ -3197,6 +3139,7 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
if (cp.eff < 2.5f) {
float effect = cp.eff;
float offs = 1.f;
float mea[10];
calceffect(level, mean, sigma, mea, effect, offs);
@@ -3608,8 +3551,9 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
if (!lipschitz) {
delete [] koe;
}
delete[] beta;
if (!(cp.bam && cp.finena)) {
beta.reset();
}
}
@@ -3649,7 +3593,7 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
const float lowthr = params->wavelet.lowthr;
float mea[10];
float effect = cp.sigm;
float beta;
float lbeta;
calceffect(level, mean, sigma, mea, effect, offs);
@@ -3664,34 +3608,34 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
float kLlev = 1.f;
if (cpMul < 0.f) {
beta = 1.f; // disabled for negatives values "less contrast"
lbeta = 1.f; // disabled for negatives values "less contrast"
} else {
float WavCL = std::fabs(WavCoeffs_L[dir][i]);
//reduction amplification: max action between mean / 2 and mean + sigma
// arbitrary coefficient, we can add a slider !!
if (WavCL < mea[0]) {
beta = 0.4f * red0;//preserve very low contrast (sky...)
lbeta = 0.4f * red0;//preserve very low contrast (sky...)
} else if (WavCL < mea[1]) {
beta = 0.5f * red1;
lbeta = 0.5f * red1;
} else if (WavCL < mea[2]) {
beta = 0.7f * red2;
lbeta = 0.7f * red2;
} else if (WavCL < mea[3]) {
beta = 1.f; //standard
lbeta = 1.f; //standard
} else if (WavCL < mea[4]) {
beta = 1.f;
lbeta = 1.f;
} else if (WavCL < mea[5]) {
beta = 0.8f; //+sigma
lbeta = 0.8f; //+sigma
} else if (WavCL < mea[6]) {
beta = 0.6f;
lbeta = 0.6f;
} else if (WavCL < mea[7]) {
beta = 0.4f;
lbeta = 0.4f;
} else if (WavCL < mea[8]) {
beta = 0.2f; // + 2 sigma
lbeta = 0.2f; // + 2 sigma
} else if (WavCL < mea[9]) {
beta = 0.1f;
lbeta = 0.1f;
} else {
beta = 0.0f;
lbeta = 0.0f;
}
}
@@ -3751,7 +3695,7 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
//linear transition HL
float diagacc = 1.f;
float alpha = (1024.f + 15.f * (float) cpMul * scale * scale2 * beta * diagacc) / 1024.f ;
float alpha = (1024.f + 15.f * (float) cpMul * scale * scale2 * lbeta * diagacc) / 1024.f ;
if (cp.HSmet && cp.contena) {
float aaal = (1.f - alpha) / ((cp.b_lhl - cp.t_lhl) * kH[level]);
@@ -3801,18 +3745,12 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
}
if (cp.bam && cp.finena) {
float effect = cp.sigmadir;
float offs = 1.f;
const float effect = cp.sigmadir;
constexpr float offs = 1.f;
float mea[10];
float * beta = new float[W_L * H_L];
for (int co = 0; co < H_L * W_L; co++) {
beta[co] = 1.f;
}
calceffect(level, mean, sigma, mea, effect, offs);
for (int co = 0; co < H_L * W_L; co++) {
float WavCL = std::fabs(WavCoeffs_L[dir][co]);
@@ -3841,12 +3779,7 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
}
}
if (cp.opaW && cp.BAmet == 2) {
int iteration = cp.ite;
int itplus = 7 + iteration;
int itmoins = 7 - iteration;
@@ -3945,8 +3878,6 @@ void ImProcFunctions::ContAllL(float *koeLi[12], float *maxkoeLi, bool lipschitz
}
}
}
delete[] beta;
}
// to see each level of wavelet ...level from 0 to 8
@@ -3970,9 +3901,8 @@ void ImProcFunctions::ContAllAB(LabImage * labco, int maxlvl, float ** varhue, f
float mea[10];
float effect = cp.sigmacol;
float betaab = 1.f;
float betaab;
float offs = 1.f;
float alphaC = 1.f;
calceffect(level, meanab, sigmaab, mea, effect, offs);
@@ -4022,7 +3952,7 @@ void ImProcFunctions::ContAllAB(LabImage * labco, int maxlvl, float ** varhue, f
}
alphaC = (1024.f + 15.f * cpMul * cpChrom * betaab * scale / 50.f) / 1024.f ;
const float alphaC = (1024.f + 15.f * cpMul * cpChrom * betaab * scale / 50.f) / 1024.f ;
WavCoeffs_ab[dir][i] *= alphaC;
}
@@ -4042,7 +3972,7 @@ void ImProcFunctions::ContAllAB(LabImage * labco, int maxlvl, float ** varhue, f
float mea[10];
float effect = cp.sigmacol;
float betaab = 0.f;
float betaab;
float offs = 1.f;
calceffect(level, meanab, sigmaab, mea, effect, offs);
@@ -4161,7 +4091,7 @@ void ImProcFunctions::ContAllAB(LabImage * labco, int maxlvl, float ** varhue, f
if ((useOpacity && level < 9 && mulOpacity != 0.f) && cp.toningena) { //toning
float mea[10];
float effect = cp.sigmaton;
float betaab = 0.f;
float betaab;
float offs = 1.f;
float protec = 0.01f * (100.f - cp.protab);
float aref1 = cp.a_high;
@@ -4477,191 +4407,4 @@ void ImProcFunctions::ContAllAB(LabImage * labco, int maxlvl, float ** varhue, f
}
}
void ImProcFunctions::softproc2(const LabImage* bufcolorig, const LabImage* bufcolfin, float rad, int bfh, int bfw, double epsilmax, double epsilmin, float thres, int sk, bool multiThread, int flag)
{
if (flag == 0) {
if (rad > 0.f) {
array2D<float> ble(bfw, bfh);
array2D<float> guid(bfw, bfh);
Imagefloat *tmpImage = nullptr;
tmpImage = new Imagefloat(bfw, bfh);
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int ir = 0; ir < bfh; ir++)
for (int jr = 0; jr < bfw; jr++) {
float X, Y, Z;
float L = bufcolorig->L[ir][jr];
float a = bufcolorig->a[ir][jr];
float b = bufcolorig->b[ir][jr];
Color::Lab2XYZ(L, a, b, X, Y, Z);
guid[ir][jr] = Y / 32768.f;
float La = bufcolfin->L[ir][jr];
float aa = bufcolfin->a[ir][jr];
float ba = bufcolfin->b[ir][jr];
Color::Lab2XYZ(La, aa, ba, X, Y, Z);
tmpImage->r(ir, jr) = X;
tmpImage->g(ir, jr) = Y;
tmpImage->b(ir, jr) = Z;
ble[ir][jr] = Y / 32768.f;
}
double aepsil = (epsilmax - epsilmin) / 90.f;
double bepsil = epsilmax - 100.f * aepsil;
double epsil = aepsil * 0.1 * rad + bepsil;
float blur = 10.f / sk * (thres + 0.8f * rad);
rtengine::guidedFilter(guid, ble, ble, blur, epsil, multiThread, 4);
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int ir = 0; ir < bfh; ir++)
for (int jr = 0; jr < bfw; jr++) {
float X = tmpImage->r(ir, jr);
float Y = 32768.f * ble[ir][jr];
float Z = tmpImage->b(ir, jr);
float L, a, b;
Color::XYZ2Lab(X, Y, Z, L, a, b);
bufcolfin->L[ir][jr] = L;
}
delete tmpImage;
}
} else if (flag == 1) {
if (rad > 0.f) {
array2D<float> ble(bfw, bfh);
array2D<float> blechro(bfw, bfh);
array2D<float> hue(bfw, bfh);
array2D<float> guid(bfw, bfh);
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int ir = 0; ir < bfh; ir++)
for (int jr = 0; jr < bfw; jr++) {
// hue[ir][jr] = xatan2f(bufcolfin->b[ir][jr], bufcolfin->a[ir][jr]);
// float chromah = sqrt(SQR(bufcolfin->b[ir][jr]) + SQR(bufcolfin->a[ir][jr]));
ble[ir][jr] = (bufcolfin->L[ir][jr]) / 32768.f;
// blechro[ir][jr] = chromah / 32768.f;
guid[ir][jr] = bufcolorig->L[ir][jr] / 32768.f;
}
double aepsil = (epsilmax - epsilmin) / 90.f;
double bepsil = epsilmax - 100.f * aepsil;
double epsil = aepsil * 0.1 * rad + bepsil;
if (rad != 0.f) {
float blur = rad;
blur = blur < 0.f ? -1.f / blur : 1.f + blur;
// int r1 = max(int(4 / sk * blur + 0.5), 1);
int r2 = max(int(25 / sk * blur + 0.5), 1);
if (rad < 0.f) {
epsil = 0.0001;
}
rtengine::guidedFilter(guid, ble, ble, r2, epsil, multiThread);
// rtengine::guidedFilter(guid, blechro, blechro, r1, 0.5 * epsil, multiThread);
}
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int ir = 0; ir < bfh; ir++)
for (int jr = 0; jr < bfw; jr++) {
// float2 sincosval = xsincosf(hue[ir][jr]);
bufcolfin->L[ir][jr] = 32768.f * ble[ir][jr];
// bufcolfin->a[ir][jr] = 32768.f * sincosval.y * blechro[ir][jr];
// bufcolfin->b[ir][jr] = 32768.f * sincosval.x * blechro[ir][jr];
}
}
}
}
void ImProcFunctions::Compresslevels2(float **Source, int W_L, int H_L, float compression, float detailattenuator, float thres, float mean, float maxp, float meanN, float maxN, float madL)
{
//J.Desmis 12-2019
float exponent;
if (detailattenuator > 0.f && detailattenuator < 0.05f) {
float betemp = expf(-(2.f - detailattenuator + 0.693147f)) - 1.f; //0.69315 = log(2)
exponent = 1.2f * xlogf(-betemp);
exponent /= 20.f;
} else if (detailattenuator >= 0.05f && detailattenuator < 0.25f) {
float betemp = expf(-(2.f - detailattenuator + 0.693147f)) - 1.f;
exponent = 1.2f * xlogf(-betemp);
exponent /= (-75.f * detailattenuator + 23.75f);
} else if (detailattenuator >= 0.25f) {
float betemp = expf(-(2.f - detailattenuator + 0.693147f)) - 1.f;
exponent = 1.2f * xlogf(-betemp);
exponent /= (-2.f * detailattenuator + 5.5f);
} else {
exponent = (compression - 1.0f) / 20.f;
}
exponent += 1.f;
float ap = (thres - 1.f) / (maxp - mean);
float bp = 1.f - ap * mean;
float a0 = (1.33f * thres - 1.f) / (1.f - mean);
float b0 = 1.f - a0 * mean;
float apn = (thres - 1.f) / (maxN - meanN);
float bpn = 1.f - apn * meanN;
float a0n = (1.33f * thres - 1.f) / (1.f - meanN);
float b0n = 1.f - a0n * meanN;
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int y = 0; y < H_L; y++) {
for (int x = 0; x < W_L; x++) {
float expone = 1.f;
if (Source[y][x] >= 0.f) {
if (Source[y][x] > mean) {
expone = 1.f + (exponent - 1.f) * (ap * Source[y][x] + bp);
} else {
expone = 1.f + (exponent - 1.f) * (a0 * Source[y][x] + b0);
}
Source[y][x] = xexpf(xlogf(Source[y][x] + 0.05f * madL) * expone);
} else if (Source[y][x] < 0.f) {
if (-Source[y][x] > mean) {
expone = 1.f + (exponent - 1.f) * (apn * -Source[y][x] + bpn);
} else {
expone = 1.f + (exponent - 1.f) * (a0n * -Source[y][x] + b0n);
}
Source[y][x] = -xexpf(xlogf(-Source[y][x] + 0.05f * madL) * expone);
}
}
}
}
}