diff --git a/rtengine/dirpyr_equalizer.cc b/rtengine/dirpyr_equalizer.cc index 21d87b1ef..f243ebe66 100644 --- a/rtengine/dirpyr_equalizer.cc +++ b/rtengine/dirpyr_equalizer.cc @@ -354,18 +354,24 @@ void ImProcFunctions::cbdl_local_temp(float ** src, float ** loctemp, int srcwid } // with the current implementation of idirpyr_eq_channel we can safely use the buffer from last level as buffer, saves some memory - float ** buffer = dirpyrlo[lastlevel - 1]; -/* - // array2D resid5(srcwidth, srcheight); - array2D residbuff(srcwidth, srcheight); - - #pragma omp parallel for - for (int i = 0; i < srcheight; i++) { +// float ** buffer = dirpyrlo[lastlevel - 1]; + array2D residbuff(srcwidth, srcheight); + array2D resid5(srcwidth, srcheight); + + #pragma omp parallel for + for (int i = 0; i < srcheight; i++) for (int j = 0; j < srcwidth; j++) { - // resid5[i][j] = dirpyrlo[lastlevel - 1][i][j]; //CLIPLL(buffer[i][j]); - residbuff[i][j] = buffer[i][j]; + residbuff[i][j] = 0.f; } - } + + #pragma omp parallel for + for (int i = 0; i < srcheight; i++) + for (int j = 0; j < srcwidth; j++) { + residbuff[i][j] = dirpyrlo[lastlevel - 1][i][j]; + resid5[i][j] = dirpyrlo[lastlevel - 1][i][j]; + } + + double avg = 0.f; if(contres != 0.f) { int ng = 0; @@ -399,30 +405,29 @@ void ImProcFunctions::cbdl_local_temp(float ** src, float ** loctemp, int srcwid } } - */ + for (int level = lastlevel - 1; level > 0; level--) { - idirpyr_eq_channel_loc(dirpyrlo[level], dirpyrlo[level - 1], buffer /*residbuff*/, srcwidth, srcheight, level, multi, dirpyrThreshold, nullptr, nullptr, skinprot, gamutlab, b_l, t_l, t_r, b_r, choice); + idirpyr_eq_channel_loc(dirpyrlo[level], dirpyrlo[level - 1], residbuff, srcwidth, srcheight, level, multi, dirpyrThreshold, nullptr, nullptr, skinprot, gamutlab, b_l, t_l, t_r, b_r, choice); } scale = scalesloc[0]; - idirpyr_eq_channel_loc(dirpyrlo[0], src, buffer/*residbuff*/, srcwidth, srcheight, 0, multi, dirpyrThreshold, nullptr, nullptr, skinprot, gamutlab, b_l, t_l, t_r, b_r, choice); + idirpyr_eq_channel_loc(dirpyrlo[0], src, residbuff, srcwidth, srcheight, 0, multi, dirpyrThreshold, nullptr, nullptr, skinprot, gamutlab, b_l, t_l, t_r, b_r, choice); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// array2D loct(srcwidth, srcheight); -// #pragma omp parallel for -// for (int i = 0; i < srcheight; i++) -// for (int j = 0; j < srcwidth; j++) { -// loct[i][j] = CLIPLL(residbuff[i][j]); // TODO: Really a clip necessary? -// } + array2D loct(srcwidth, srcheight); + #pragma omp parallel for + for (int i = 0; i < srcheight; i++) + for (int j = 0; j < srcwidth; j++) { + loct[i][j] = CLIPLL(residbuff[i][j]); // TODO: Really a clip necessary? + } - // float clar = 0.01f * mergeL; + float clar = 0.01f * mergeL; #pragma omp parallel for for (int i = 0; i < srcheight; i++) for (int j = 0; j < srcwidth; j++) { - // loctemp[i][j] = CLIPLL((1.f + clar) * loct[i][j] - clar * resid5[i][j]);//there is a bug ==> leads to crash in some cases but where ?? - loctemp[i][j] = CLIPLL(buffer[i][j]); + loctemp[i][j] = CLIPLL((1.f + clar) * loct[i][j] - clar * resid5[i][j]); } } @@ -797,7 +802,6 @@ void ImProcFunctions::idirpyr_eq_channel_loc(float ** data_coarse, float ** data } else { offs = -1.f; } - float multbis[5]; multbis[level] = mult[level]; //multbis to reduce artifacts for high values mult @@ -809,11 +813,33 @@ void ImProcFunctions::idirpyr_eq_channel_loc(float ** data_coarse, float ** data // if(level == 5 && mult[level] > 1.f) { // multbis[level] = 1.f + 0.45f * (mult[level] - 1.f); // } - +/* + LUTf irangefn(0x20000); + { + const float noisehi = 1.33f * noise * 0.1f * dirpyrThreshold / expf(level * log(3.0)), noiselo = 0.66f * noise * 0.1f * dirpyrThreshold / expf(level * log(3.0)); + // const float noisehi = 1.33f * noise * 0.1 / expf(level * log(3.0)), noiselo = 0.66f * noise * 0.1 / expf(level * log(3.0)); + //printf("level=%i multlev=%f noisehi=%f noiselo=%f skinprot=%f\n",level,mult[level], noisehi, noiselo, skinprot); + printf("moihi=%f noilo=%f\n", noisehi, noiselo); + for (int i = 0; i < 0x20000; i++) { + if (abs(i - 0x10000) > noisehi || multbis[level] < 1.0) { + irangefn[i] = multbis[level] + offs; + } else { + if (abs(i - 0x10000) < noiselo) { + irangefn[i] = 1.f + offs ; + } else { + irangefn[i] = 1.f + offs + (multbis[level] - 1.f) * (noisehi) / (noisehi - noiselo + 0.01f) ; + } + } + // printf("i=%f ", irangefn[i]); + + } + } +*/ LUTf irangefn(0x20000); { - const float noisehi = 1.33f * noise * dirpyrThreshold / expf(level * log(3.0)), noiselo = 0.66f * noise * dirpyrThreshold / expf(level * log(3.0)); + const float noisehi = 1.33f * noise * 0.1f * dirpyrThreshold / expf(level * log(3.0)), noiselo = 0.66f * noise * 0.1f * dirpyrThreshold / expf(level * log(3.0)); //printf("level=%i multlev=%f noisehi=%f noiselo=%f skinprot=%f\n",level,mult[level], noisehi, noiselo, skinprot); + printf("noihi=%f noilo=%f\n", noisehi, noiselo); for (int i = 0; i < 0x20000; i++) { if (abs(i - 0x10000) > noisehi || multbis[level] < 1.0) { @@ -827,18 +853,26 @@ void ImProcFunctions::idirpyr_eq_channel_loc(float ** data_coarse, float ** data } } } + - if (skinprot == 0.f) + // if (skinprot == 0.f) #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) #endif for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { float hipass = (data_fine[i][j] - data_coarse[i][j]); - buffer[i][j] += irangefn[hipass + 0x10000] * hipass; + // buffer[i][j] += irangefn[hipass + 0x10000] * hipass; + // if((hipass) <= 0.f) printf("N"); + // if((hipass + 0x10000 ) >= 0x15000f) printf("T"); + buffer[i][j] += CLIPLL(irangefn[hipass + 0x10000] * hipass); + // buffer[i][j] += hipass; + buffer[i][j] = CLIPLL(buffer[i][j]); + // printf("bu=%f ", buffer[i][j]); + } } - +irangefn.clear(); /* else if(skinprot > 0.f) #ifdef _OPENMP diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 90684f56c..c0c1eba75 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -578,8 +578,8 @@ static void calcLocalParams(int sp, int oW, int oH, const LocallabParams& locall lp.sensh = local_sensih; lp.dehaze = local_dehaze; lp.senscb = local_sensicb; - lp.clarityml = 0.f; //local_clarityml; - lp.contresid = 0.f; //local_contresid; + lp.clarityml = local_clarityml; + lp.contresid = local_contresid; lp.cont = local_contrast; lp.ligh = local_lightness; lp.lowA = labgridALowloc; @@ -5521,8 +5521,10 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o const int yend = std::min(static_cast(lp.yc + lp.ly) - cy, original->H); const int xstart = std::max(static_cast(lp.xc - lp.lxL) - cx, 0); const int xend = std::min(static_cast(lp.xc + lp.lx) - cx, original->W); - int bfh = yend - ystart; - int bfw = xend - xstart; + int bfh = yend - ystart + del; + int bfw = xend - xstart + del; + // int bfh = int (lp.ly + lp.lyT) + del; //bfw bfh real size of square zone + // int bfw = int (lp.lx + lp.lxL) + del; if (bfw > 32 && bfh > 32) { array2D bufsh(bfw, bfh); @@ -5549,7 +5551,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o loctemp->b[y - ystart][x - xstart] = origcbdl->b[y - ystart][x - xstart] = original->b[y][x]; } } -/* + if(lp.clarityml != 0.f && lp.mulloc[4] == 1.0) {//enabled last level to retrieve level 5 and residual image in case user not select level 5 lp.mulloc[4]= 1.001f; } @@ -5557,7 +5559,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o if(lp.contresid != 0.f && lp.mulloc[4] == 1.0) {//enabled last level to retrieve level 5 and residual image in case user not select level 5 lp.mulloc[4]= 1.001f; } -*/ + ImProcFunctions::cbdl_local_temp(bufsh, loctemp->L, bfw, bfh, lp.mulloc, 1.f, lp.threshol, lp.clarityml, lp.contresid, skinprot, false, b_l, t_l, t_r, b_r, choice, sk); float minL = loctemp->L[0][0] - origcbdl->L[0][0]; @@ -5606,7 +5608,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o float multc[5]; float clarich = 0.5f * lp.clarityml; -/* + if(clarich > 0.f && lp.mulloc[0] == 1.f) { //to enabled in case of user select only clarity lp.mulloc[0] = 1.01f; } @@ -5614,7 +5616,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o if(lp.contresid != 0.f && lp.mulloc[0] == 1.f) { //to enabled in case of user select only clarity lp.mulloc[0] = 1.01f; } -*/ + for (int lv = 0; lv < 5; lv++) { multc[lv] = rtengine::max((lp.chromacb * ((float) lp.mulloc[lv] - 1.f) / 100.f) + 1.f, 0.f); } diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index aa5b21fef..ff3e6919f 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -950,7 +950,7 @@ Locallab::Locallab(): ToolParamBlock* const residBox = Gtk::manage(new ToolParamBlock()); residBox->pack_start(*clarityml); residBox->pack_start(*contresid); -// residFrame->add(*residBox); + residFrame->add(*residBox); cbdlBox->pack_start(*residFrame); cbdlBox->pack_start(*softradiuscb); cbdlBox->pack_start(*sensicb);