@@ -140,32 +140,35 @@ const int CB2GI = -5636;
140
140
const int CR2GI = -11698 ;
141
141
const int CR2RI = 22987 ;
142
142
143
- static void splineBuild (const softfloat* f, int n, float * tab )
143
+ static const float * splineBuild (const softfloat* f, size_t n )
144
144
{
145
+ float * tab = cv::allocSingleton<float >(n * 4 );
145
146
const softfloat f2 (2 ), f3 (3 ), f4 (4 );
146
147
softfloat cn (0 );
147
148
softfloat* sftab = reinterpret_cast <softfloat*>(tab);
148
- int i;
149
149
tab[0 ] = tab[1 ] = 0 .0f ;
150
150
151
- for (i = 1 ; i <= n- 1 ; i++)
151
+ for (size_t i = 1 ; i < n ; i++)
152
152
{
153
153
softfloat t = (f[i+1 ] - f[i]*f2 + f[i-1 ])*f3;
154
154
softfloat l = softfloat::one ()/(f4 - sftab[(i-1 )*4 ]);
155
155
sftab[i*4 ] = l; sftab[i*4 +1 ] = (t - sftab[(i-1 )*4 +1 ])*l;
156
156
}
157
157
158
- for (i = n- 1 ; i >= 0 ; i-- )
158
+ for (size_t j = 0 ; j < n; ++j )
159
159
{
160
+ size_t i = n - j - 1 ;
160
161
softfloat c = sftab[i*4 +1 ] - sftab[i*4 ]*cn;
161
162
softfloat b = f[i+1 ] - f[i] - (cn + c*f2)/f3;
162
163
softfloat d = (cn - c)/f3;
163
164
sftab[i*4 ] = f[i]; sftab[i*4 +1 ] = b;
164
165
sftab[i*4 +2 ] = c; sftab[i*4 +3 ] = d;
165
166
cn = c;
166
167
}
168
+ return tab;
167
169
}
168
170
171
+
169
172
// interpolates value of a function at x, 0 <= x <= n using a cubic spline.
170
173
template <typename _Tp> static inline _Tp splineInterpolate (_Tp x, const _Tp* tab, int n)
171
174
{
@@ -5820,11 +5823,11 @@ static const softdouble D65[] = {softdouble::fromRaw(0x3fee6a22b3892ee8),
5820
5823
softdouble::fromRaw (0x3ff16b8950763a19 )};
5821
5824
5822
5825
enum { LAB_CBRT_TAB_SIZE = 1024 , GAMMA_TAB_SIZE = 1024 };
5823
- static float *LabCbrtTab;
5826
+ static const float *LabCbrtTab = 0 ;
5824
5827
static const float LabCbrtTabScale = softfloat(LAB_CBRT_TAB_SIZE*2 )/softfloat(3 );
5825
5828
5826
- static float *sRGBGammaTab ;
5827
- static float *sRGBInvGammaTab ;
5829
+ static const float *sRGBGammaTab = 0 ;
5830
+ static const float *sRGBInvGammaTab = 0 ;
5828
5831
static const float GammaTabScale ((int )GAMMA_TAB_SIZE);
5829
5832
5830
5833
static ushort sRGBGammaTab_b [256 ], linearGammaTab_b[256 ];
@@ -5911,8 +5914,7 @@ static void initLabTabs()
5911
5914
softfloat x = scale*softfloat (i);
5912
5915
f[i] = x < lthresh ? mulAdd (x, lscale, lbias) : cbrt (x);
5913
5916
}
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);
5916
5918
5917
5919
scale = softfloat::one ()/softfloat (GammaTabScale);
5918
5920
for (i = 0 ; i <= GAMMA_TAB_SIZE; i++)
@@ -5922,10 +5924,8 @@ static void initLabTabs()
5922
5924
ig[i] = applyInvGamma (x);
5923
5925
}
5924
5926
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);
5929
5929
5930
5930
static const softfloat intScale (255 *(1 << gamma_shift));
5931
5931
for (i = 0 ; i < 256 ; i++)
0 commit comments