Assert memory access preconditions in ImProcFunctions::ContAllL and begin to remove some of the detritus in that file as well.
This commit is contained in:
@@ -23,9 +23,9 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include "../rtgui/threadutils.h"
|
#include "../rtgui/threadutils.h"
|
||||||
|
|
||||||
#include "rtengine.h"
|
#include "rtengine.h"
|
||||||
@@ -163,9 +163,6 @@ SSEFUNCTION void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
MyTime t1e, t2e ;
|
|
||||||
t1e.set();
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// init variables to display Munsell corrections
|
// init variables to display Munsell corrections
|
||||||
MunsellDebugInfo* MunsDebugInfo = new MunsellDebugInfo();
|
MunsellDebugInfo* MunsDebugInfo = new MunsellDebugInfo();
|
||||||
@@ -219,10 +216,6 @@ SSEFUNCTION void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int
|
|||||||
cp.tonemap = true;
|
cp.tonemap = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*else if(params->wavelet.TMmethod=="std") {cp.TMmeth=1;cp.tonemap=true;}
|
|
||||||
else if(params->wavelet.TMmethod=="high") {cp.TMmeth=2;cp.tonemap=true;}
|
|
||||||
else if(params->wavelet.TMmethod=="lowhigh") {cp.TMmeth=3;cp.tonemap=true;}
|
|
||||||
*/
|
|
||||||
if(params->wavelet.TMmethod == "cont") {
|
if(params->wavelet.TMmethod == "cont") {
|
||||||
cp.contmet = 1;
|
cp.contmet = 1;
|
||||||
} else if(params->wavelet.TMmethod == "tm") {
|
} else if(params->wavelet.TMmethod == "tm") {
|
||||||
@@ -1314,15 +1307,7 @@ SSEFUNCTION void ImProcFunctions::ip_wavelet(LabImage * lab, LabImage * dst, int
|
|||||||
delete dsttmp;
|
delete dsttmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings->verbose) {
|
}
|
||||||
t2e.set();
|
|
||||||
printf("Wavelet performed in %d usec:\n", t2e.etime(t1e));
|
|
||||||
}
|
|
||||||
|
|
||||||
}//end o
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#undef TS
|
#undef TS
|
||||||
#undef fTS
|
#undef fTS
|
||||||
@@ -1460,7 +1445,6 @@ void ImProcFunctions::Eval2 (float ** WavCoeffs_L, int level, struct cont_param
|
|||||||
for (int dir = 1; dir < 4; dir++) {
|
for (int dir = 1; dir < 4; dir++) {
|
||||||
Aver(WavCoeffs_L[dir], W_L * H_L, avLP[dir], avLN[dir], maxL[dir], minL[dir]);
|
Aver(WavCoeffs_L[dir], W_L * H_L, avLP[dir], avLN[dir], maxL[dir], minL[dir]);
|
||||||
Sigma(WavCoeffs_L[dir], W_L * H_L, avLP[dir], avLN[dir], sigP[dir], sigN[dir]);
|
Sigma(WavCoeffs_L[dir], W_L * H_L, avLP[dir], avLN[dir], sigP[dir], sigN[dir]);
|
||||||
// printf("dir=%d level=%d avLP=%f max=%f avLN=%f min=%f sigP=%f sigN=%f\n",dir,level,avLP[dir] ,maxL[dir], avLN[dir] ,minL[dir], sigP[dir], sigN[dir]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AvL = 0.f;
|
AvL = 0.f;
|
||||||
@@ -1501,9 +1485,6 @@ void ImProcFunctions::Eval2 (float ** WavCoeffs_L, int level, struct cont_param
|
|||||||
sigmaN[level] = SN;
|
sigmaN[level] = SN;
|
||||||
MaxP[level] = maxLP;
|
MaxP[level] = maxLP;
|
||||||
MaxN[level] = maxLN;
|
MaxN[level] = maxLN;
|
||||||
// if(params->wavelet.CLmethod!="all") {//display only if user choose different from all
|
|
||||||
// printf("Ind=%d Level=%d MadL=%f AvL=%f AvN=%f SL=%f SN=%f maxP=%f maxN=%f\n",ind, level,MADL,mean[level],meanN[level],sigma[level],sigmaN[level],MaxP[level],MaxN[level]);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float *ImProcFunctions::ContrastDR(float *Source, int skip, struct cont_params &cp, int W_L, int H_L, float Compression, float DetailBoost, float max0, float min0, float ave, float ah, float bh, float al, float bl, float factorx, float *Contrast)
|
float *ImProcFunctions::ContrastDR(float *Source, int skip, struct cont_params &cp, int W_L, int H_L, float Compression, float DetailBoost, float max0, float min0, float ave, float ah, float bh, float al, float bl, float factorx, float *Contrast)
|
||||||
@@ -1520,27 +1501,7 @@ float *ImProcFunctions::ContrastDR(float *Source, int skip, struct cont_params &
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < W_L * H_L; i++) { //contrast
|
for (int i = 0; i < W_L * H_L; i++) { //contrast
|
||||||
/*
|
|
||||||
//source between 0 and 1
|
|
||||||
if(Source[i] < 1.f) {
|
|
||||||
float prov;
|
|
||||||
if( 32768.f*Source[i]> ave) {
|
|
||||||
float kh = ah*(Source[i]*100.f)+bh;
|
|
||||||
prov=32768.f*Source[i];
|
|
||||||
Contrast[i]=ave+kh*(Source[i]*32768.f-ave);
|
|
||||||
} else {
|
|
||||||
float kl = al*(Source[i]*100.f)+bl;
|
|
||||||
prov=32768.f*Source[i];
|
|
||||||
Contrast[i]=ave-kl*(ave-Source[i]*32768.f);
|
|
||||||
}
|
|
||||||
float diflc=Contrast[i]-prov;
|
|
||||||
diflc*=factorx;
|
|
||||||
Contrast[i] = (prov + diflc)/32768.f;
|
|
||||||
//contrast between 0 and 1
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Contrast[i] = Source[i] ;
|
Contrast[i] = Source[i] ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Contrast;
|
return Contrast;
|
||||||
@@ -1608,9 +1569,6 @@ SSEFUNCTION float *ImProcFunctions::CompressDR(float *Source, int skip, struct c
|
|||||||
temp = (Compression - 1.0f) / 20.f;
|
temp = (Compression - 1.0f) / 20.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("temp=%f \n", temp);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
#ifdef _RT_NESTED_OPENMP
|
#ifdef _RT_NESTED_OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@@ -2682,6 +2640,8 @@ 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, float ** varhue, float **varchrom, float ** WavCoeffs_L, float * WavCoeffs_L0, int level, int dir, struct cont_params &cp,
|
||||||
int W_L, int H_L, int skip, float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN, const WavCurve & wavCLVCcurve, const WavOpacityCurveW & waOpacityCurveW, FlatCurve* ChCurve, bool Chutili)
|
int W_L, int H_L, int skip, float *mean, float *meanN, float *sigma, float *sigmaN, float *MaxP, float *MaxN, const WavCurve & wavCLVCcurve, const WavOpacityCurveW & waOpacityCurveW, FlatCurve* ChCurve, bool Chutili)
|
||||||
{
|
{
|
||||||
|
assert (level >= 0);
|
||||||
|
assert (maxlvl > level);
|
||||||
|
|
||||||
static const float scales[10] = {1.f, 2.f, 4.f, 8.f, 16.f, 32.f, 64.f, 128.f, 256.f, 512.f};
|
static const float scales[10] = {1.f, 2.f, 4.f, 8.f, 16.f, 32.f, 64.f, 128.f, 256.f, 512.f};
|
||||||
float scaleskip[10];
|
float scaleskip[10];
|
||||||
@@ -2694,17 +2654,11 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
float t_r = settings->top_right;
|
float t_r = settings->top_right;
|
||||||
float t_l = settings->top_left;
|
float t_l = settings->top_left;
|
||||||
float b_r = settings->bot_right;
|
float b_r = settings->bot_right;
|
||||||
float b_l = settings->bot_left;
|
|
||||||
float edd = settings->ed_detec;
|
float edd = settings->ed_detec;
|
||||||
float eddlow = settings->ed_low;
|
|
||||||
float eddstrength = settings->ed_detecStr;
|
float eddstrength = settings->ed_detecStr;
|
||||||
float aedstr = (eddstrength - 1.f) / 90.f;
|
float aedstr = (eddstrength - 1.f) / 90.f;
|
||||||
float bedstr = 1.f - 10.f * aedstr;
|
float bedstr = 1.f - 10.f * aedstr;
|
||||||
|
|
||||||
bool refi = false;
|
|
||||||
|
|
||||||
// if(cp.lev0s > 0.f || cp.lev1s > 0.f || cp.lev2s > 0.f) refi=true;
|
|
||||||
// if(cp.val > 0 || refi) {//edge
|
|
||||||
if(cp.val > 0 && cp.edgeena) {
|
if(cp.val > 0 && cp.edgeena) {
|
||||||
float * koe;
|
float * koe;
|
||||||
float maxkoe = 0.f;
|
float maxkoe = 0.f;
|
||||||
@@ -2718,7 +2672,7 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
|
|
||||||
maxkoe = 0.f;
|
maxkoe = 0.f;
|
||||||
|
|
||||||
if(cp.detectedge) {//
|
if(cp.detectedge) {
|
||||||
float** tmC;
|
float** tmC;
|
||||||
int borderL = 1;
|
int borderL = 1;
|
||||||
tmC = new float*[H_L];
|
tmC = new float*[H_L];
|
||||||
@@ -2779,8 +2733,6 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("maxkoe=%f \n",maxkoe);
|
|
||||||
|
|
||||||
for (int i = 0; i < H_L; i++) {
|
for (int i = 0; i < H_L; i++) {
|
||||||
delete [] tmC[i];
|
delete [] tmC[i];
|
||||||
}
|
}
|
||||||
@@ -2840,9 +2792,6 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float coefsd = 0.85f; //arbitray value to reduce effect after sigma in all case
|
|
||||||
float coefmean = 0.85f; //arbitray value to reduce effect after sigma in all case
|
|
||||||
// edge = 1.f + value * exp (expkoef);//estimate edge "pseudo variance"
|
|
||||||
//take into account local contrast
|
//take into account local contrast
|
||||||
float refin = value * exp (expkoef);
|
float refin = value * exp (expkoef);
|
||||||
|
|
||||||
@@ -2868,7 +2817,6 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
|
|
||||||
float edgePrecalc = 1.f + refin; //estimate edge "pseudo variance"
|
float edgePrecalc = 1.f + refin; //estimate edge "pseudo variance"
|
||||||
|
|
||||||
//bool exa=false;
|
|
||||||
if(cp.EDmet == 2) { //curve
|
if(cp.EDmet == 2) { //curve
|
||||||
// if(exa) {//curve
|
// if(exa) {//curve
|
||||||
float insigma = 0.666f; //SD
|
float insigma = 0.666f; //SD
|
||||||
@@ -2883,7 +2831,6 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
float absciss;
|
float absciss;
|
||||||
float kinterm;
|
float kinterm;
|
||||||
float kmul;
|
float kmul;
|
||||||
// for (int i=0; i<W_L*H_L; i++) {
|
|
||||||
int borderL = 1;
|
int borderL = 1;
|
||||||
|
|
||||||
for(int i = borderL; i < H_L - borderL; i++ ) {
|
for(int i = borderL; i < H_L - borderL; i++ ) {
|
||||||
@@ -3145,7 +3092,6 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
mea[7] = mean[level] + 2.f * sigma[level]; //95%
|
mea[7] = mean[level] + 2.f * sigma[level]; //95%
|
||||||
mea[8] = mean[level] + 2.5f * sigma[level]; //99%
|
mea[8] = mean[level] + 2.5f * sigma[level]; //99%
|
||||||
|
|
||||||
bool skinControl = (skinprot != 0.f);
|
|
||||||
bool useChromAndHue = (skinprot != 0.f || cp.HSmet);
|
bool useChromAndHue = (skinprot != 0.f || cp.HSmet);
|
||||||
float modchro, kLlev;
|
float modchro, kLlev;
|
||||||
|
|
||||||
@@ -3185,8 +3131,7 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
float scale = 1.f;
|
float scale = 1.f;
|
||||||
float scale2 = 1.f;
|
float scale2 = 1.f;
|
||||||
|
|
||||||
float LL100, LL100res, LL100init;// kH[maxlvl];
|
float LL100, LL100res, LL100init, kH[maxlvl];
|
||||||
float *kH = new float [maxlvl];//allocate memory
|
|
||||||
|
|
||||||
int ii = i / W_L;
|
int ii = i / W_L;
|
||||||
int jj = i - ii * W_L;
|
int jj = i - ii * W_L;
|
||||||
@@ -3205,18 +3150,6 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
|
|
||||||
|
|
||||||
if(useChromAndHue) {
|
if(useChromAndHue) {
|
||||||
/*
|
|
||||||
int ii=i/W_L;
|
|
||||||
int jj=i-ii*W_L;
|
|
||||||
float LL = labco->L[ii*2][jj*2];
|
|
||||||
LL100=LL100init=LL/327.68f;
|
|
||||||
LL100res=WavCoeffs_L0[i]/327.68f;
|
|
||||||
float delta=fabs(LL100init-LL100res)/(maxlvl/2);
|
|
||||||
for(int ml=0;ml<maxlvl;ml++) {
|
|
||||||
if(ml < maxlvl/2) kH[ml]=(LL100res+ml*delta)/LL100res;// fixed a priori max to level middle
|
|
||||||
else kH[ml]=(LL100init-ml*delta)/LL100res;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
float modhue = varhue[ii][jj];
|
float modhue = varhue[ii][jj];
|
||||||
modchro = varchrom[ii * 2][jj * 2];
|
modchro = varchrom[ii * 2][jj * 2];
|
||||||
// hue chroma skin with initial lab datas
|
// hue chroma skin with initial lab datas
|
||||||
@@ -3248,20 +3181,10 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
} else {
|
} else {
|
||||||
scale2 = 1.f + 1.9f * valparam; //near 0 but not zero if curve # 0
|
scale2 = 1.f + 1.9f * valparam; //near 0 but not zero if curve # 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//curve Contrast / hue
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
//linear transition HL
|
//linear transition HL
|
||||||
float diagacc = 1.f;
|
float diagacc = 1.f;
|
||||||
/*
|
|
||||||
if(cp.diag) {
|
|
||||||
if(dir <=2) diagacc=0.75f;
|
|
||||||
if(dir ==3) diagacc=1.5f;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
float alpha = (1024.f + 15.f * (float) cpMul * scale * scale2 * beta * diagacc) / 1024.f ;
|
float alpha = (1024.f + 15.f * (float) cpMul * scale * scale2 * beta * diagacc) / 1024.f ;
|
||||||
|
|
||||||
if(cp.HSmet && cp.contena) {
|
if(cp.HSmet && cp.contena) {
|
||||||
@@ -3303,7 +3226,6 @@ void ImProcFunctions::ContAllL (float *koeLi[12], float *maxkoeLi, bool lipschit
|
|||||||
kLlev = alpha;
|
kLlev = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] kH;
|
|
||||||
WavCoeffs_L[dir][i] *= (kLlev);
|
WavCoeffs_L[dir][i] *= (kLlev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user