Skip to content

Commit e75056a

Browse files
committed
static init
1 parent 51fc891 commit e75056a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

modules/core/include/opencv2/core/private.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ static inline cv::Size cvGetMatSize( const CvMat* mat )
159159
namespace cv
160160
{
161161
CV_EXPORTS void scalarToRawData(const cv::Scalar& s, void* buf, int type, int unroll_to = 0);
162+
163+
//! Allocate all memory buffers which will not be freed, ease filtering memcheck issues
164+
template <typename T>
165+
CV_EXPORTS T* allocSingleton(size_t count) { return new T[count]; }
162166
}
163167

164168
// property implementation macros

modules/imgproc/src/color.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,32 +140,35 @@ const int CB2GI = -5636;
140140
const int CR2GI = -11698;
141141
const int CR2RI = 22987;
142142

143-
static void splineBuild(const softfloat* f, int n, float* tab)
143+
static const float * splineBuild(const softfloat* f, size_t n)
144144
{
145+
float* tab = cv::allocSingleton<float>(n * 4);
145146
const softfloat f2(2), f3(3), f4(4);
146147
softfloat cn(0);
147148
softfloat* sftab = reinterpret_cast<softfloat*>(tab);
148-
int i;
149149
tab[0] = tab[1] = 0.0f;
150150

151-
for(i = 1; i <= n-1; i++)
151+
for(size_t i = 1; i < n; i++)
152152
{
153153
softfloat t = (f[i+1] - f[i]*f2 + f[i-1])*f3;
154154
softfloat l = softfloat::one()/(f4 - sftab[(i-1)*4]);
155155
sftab[i*4] = l; sftab[i*4+1] = (t - sftab[(i-1)*4+1])*l;
156156
}
157157

158-
for(i = n-1; i >= 0; i--)
158+
for(size_t j = 0; j < n; ++j)
159159
{
160+
size_t i = n - j - 1;
160161
softfloat c = sftab[i*4+1] - sftab[i*4]*cn;
161162
softfloat b = f[i+1] - f[i] - (cn + c*f2)/f3;
162163
softfloat d = (cn - c)/f3;
163164
sftab[i*4] = f[i]; sftab[i*4+1] = b;
164165
sftab[i*4+2] = c; sftab[i*4+3] = d;
165166
cn = c;
166167
}
168+
return tab;
167169
}
168170

171+
169172
// interpolates value of a function at x, 0 <= x <= n using a cubic spline.
170173
template<typename _Tp> static inline _Tp splineInterpolate(_Tp x, const _Tp* tab, int n)
171174
{
@@ -5820,11 +5823,11 @@ static const softdouble D65[] = {softdouble::fromRaw(0x3fee6a22b3892ee8),
58205823
softdouble::fromRaw(0x3ff16b8950763a19)};
58215824

58225825
enum { LAB_CBRT_TAB_SIZE = 1024, GAMMA_TAB_SIZE = 1024 };
5823-
static float *LabCbrtTab;
5826+
static const float *LabCbrtTab = 0;
58245827
static const float LabCbrtTabScale = softfloat(LAB_CBRT_TAB_SIZE*2)/softfloat(3);
58255828

5826-
static float *sRGBGammaTab;
5827-
static float *sRGBInvGammaTab;
5829+
static const float *sRGBGammaTab = 0;
5830+
static const float *sRGBInvGammaTab = 0;
58285831
static const float GammaTabScale((int)GAMMA_TAB_SIZE);
58295832

58305833
static ushort sRGBGammaTab_b[256], linearGammaTab_b[256];
@@ -5911,8 +5914,7 @@ static void initLabTabs()
59115914
softfloat x = scale*softfloat(i);
59125915
f[i] = x < lthresh ? mulAdd(x, lscale, lbias) : cbrt(x);
59135916
}
5914-
LabCbrtTab = new float[LAB_CBRT_TAB_SIZE*4];
5915-
splineBuild(f, LAB_CBRT_TAB_SIZE, LabCbrtTab);
5917+
LabCbrtTab = splineBuild(f, LAB_CBRT_TAB_SIZE);
59165918

59175919
scale = softfloat::one()/softfloat(GammaTabScale);
59185920
for(i = 0; i <= GAMMA_TAB_SIZE; i++)
@@ -5922,10 +5924,8 @@ static void initLabTabs()
59225924
ig[i] = applyInvGamma(x);
59235925
}
59245926

5925-
sRGBGammaTab = new float[GAMMA_TAB_SIZE*4];
5926-
sRGBInvGammaTab = new float[GAMMA_TAB_SIZE*4];
5927-
splineBuild(g, GAMMA_TAB_SIZE, sRGBGammaTab);
5928-
splineBuild(ig, GAMMA_TAB_SIZE, sRGBInvGammaTab);
5927+
sRGBGammaTab = splineBuild(g, GAMMA_TAB_SIZE);
5928+
sRGBInvGammaTab = splineBuild(ig, GAMMA_TAB_SIZE);
59295929

59305930
static const softfloat intScale(255*(1 << gamma_shift));
59315931
for(i = 0; i < 256; i++)

0 commit comments

Comments
 (0)