@@ -140,31 +140,6 @@ const int CB2GI = -5636;
140
140
const int CR2GI = -11698 ;
141
141
const int CR2RI = 22987 ;
142
142
143
- // computes cubic spline coefficients for a function: (xi=i, yi=f[i]), i=0..n
144
- template <typename _Tp> static void splineBuild (const _Tp* f, int n, _Tp* tab)
145
- {
146
- _Tp cn = 0 ;
147
- int i;
148
- tab[0 ] = tab[1 ] = (_Tp)0 ;
149
-
150
- for (i = 1 ; i < n-1 ; i++)
151
- {
152
- _Tp t = 3 *(f[i+1 ] - 2 *f[i] + f[i-1 ]);
153
- _Tp l = 1 /(4 - tab[(i-1 )*4 ]);
154
- tab[i*4 ] = l; tab[i*4 +1 ] = (t - tab[(i-1 )*4 +1 ])*l;
155
- }
156
-
157
- for (i = n-1 ; i >= 0 ; i--)
158
- {
159
- _Tp c = tab[i*4 +1 ] - tab[i*4 ]*cn;
160
- _Tp b = f[i+1 ] - f[i] - (cn + c*2 )*(_Tp)0.3333333333333333 ;
161
- _Tp d = (cn - c)*(_Tp)0.3333333333333333 ;
162
- tab[i*4 ] = f[i]; tab[i*4 +1 ] = b;
163
- tab[i*4 +2 ] = c; tab[i*4 +3 ] = d;
164
- cn = c;
165
- }
166
- }
167
-
168
143
static void splineBuild (const softfloat* f, int n, float * tab)
169
144
{
170
145
const softfloat f2 (2 ), f3 (3 ), f4 (4 );
@@ -173,7 +148,7 @@ static void splineBuild(const softfloat* f, int n, float* tab)
173
148
int i;
174
149
tab[0 ] = tab[1 ] = 0 .0f ;
175
150
176
- for (i = 1 ; i < n-1 ; i++)
151
+ for (i = 1 ; i <= n-1 ; i++)
177
152
{
178
153
softfloat t = (f[i+1 ] - f[i]*f2 + f[i-1 ])*f3;
179
154
softfloat l = softfloat::one ()/(f4 - sftab[(i-1 )*4 ]);
@@ -5845,10 +5820,11 @@ static const softdouble D65[] = {softdouble::fromRaw(0x3fee6a22b3892ee8),
5845
5820
softdouble::fromRaw (0x3ff16b8950763a19 )};
5846
5821
5847
5822
enum { LAB_CBRT_TAB_SIZE = 1024 , GAMMA_TAB_SIZE = 1024 };
5848
- static float LabCbrtTab[LAB_CBRT_TAB_SIZE* 4 ] ;
5823
+ static float *LabCbrtTab ;
5849
5824
static const float LabCbrtTabScale = softfloat(LAB_CBRT_TAB_SIZE*2 )/softfloat(3 );
5850
5825
5851
- static float sRGBGammaTab [GAMMA_TAB_SIZE*4 ], sRGBInvGammaTab [GAMMA_TAB_SIZE*4 ];
5826
+ static float *sRGBGammaTab ;
5827
+ static float *sRGBInvGammaTab ;
5852
5828
static const float GammaTabScale ((int )GAMMA_TAB_SIZE);
5853
5829
5854
5830
static ushort sRGBGammaTab_b [256 ], linearGammaTab_b[256 ];
@@ -5873,21 +5849,21 @@ enum
5873
5849
trilinear_shift = 8 - lab_lut_shift + 1 ,
5874
5850
TRILINEAR_BASE = (1 << trilinear_shift)
5875
5851
};
5876
- static int16_t RGB2LabLUT_s16[LAB_LUT_DIM*LAB_LUT_DIM*LAB_LUT_DIM* 3 * 8 ] ;
5852
+ static int16_t *RGB2LabLUT_s16 ;
5877
5853
static int16_t trilinearLUT[TRILINEAR_BASE*TRILINEAR_BASE*TRILINEAR_BASE*8 ];
5878
5854
static ushort LabToYF_b[256 *2 ];
5879
5855
static const int minABvalue = -8145 ;
5880
- static int abToXZ_b[LAB_BASE* 9 / 4 ] ;
5856
+ static int *abToXZ_b ;
5881
5857
// Luv constants
5882
5858
static const bool enableRGB2LuvInterpolation = true ;
5883
5859
static const bool enablePackedRGB2Luv = true ;
5884
5860
static const bool enablePackedLuv2RGB = true ;
5885
- static int16_t RGB2LuvLUT_s16[LAB_LUT_DIM*LAB_LUT_DIM*LAB_LUT_DIM* 3 * 8 ] ;
5861
+ static int16_t *RGB2LuvLUT_s16 ;
5886
5862
static const softfloat uLow (-134 ), uHigh(220 ), uRange(uHigh-uLow);
5887
5863
static const softfloat vLow (-140 ), vHigh(122 ), vRange(vHigh-vLow);
5888
- static int LuToUp_b[ 256 * 256 ] ;
5889
- static int LvToVp_b[ 256 * 256 ] ;
5890
- static long long int LvToVpl_b[ 256 * 256 ] ;
5864
+ static int *LuToUp_b ;
5865
+ static int *LvToVp_b ;
5866
+ static long long int *LvToVpl_b ;
5891
5867
5892
5868
#define clip (value ) \
5893
5869
value < 0 .0f ? 0 .0f : value > 1 .0f ? 1 .0f : value;
@@ -5935,6 +5911,7 @@ static void initLabTabs()
5935
5911
softfloat x = scale*softfloat (i);
5936
5912
f[i] = x < lthresh ? mulAdd (x, lscale, lbias) : cbrt (x);
5937
5913
}
5914
+ LabCbrtTab = new float [LAB_CBRT_TAB_SIZE*4 ];
5938
5915
splineBuild (f, LAB_CBRT_TAB_SIZE, LabCbrtTab);
5939
5916
5940
5917
scale = softfloat::one ()/softfloat (GammaTabScale);
@@ -5944,6 +5921,9 @@ static void initLabTabs()
5944
5921
g[i] = applyGamma (x);
5945
5922
ig[i] = applyInvGamma (x);
5946
5923
}
5924
+
5925
+ sRGBGammaTab = new float [GAMMA_TAB_SIZE*4 ];
5926
+ sRGBInvGammaTab = new float [GAMMA_TAB_SIZE*4 ];
5947
5927
splineBuild (g, GAMMA_TAB_SIZE, sRGBGammaTab );
5948
5928
splineBuild (ig, GAMMA_TAB_SIZE, sRGBInvGammaTab );
5949
5929
@@ -5999,6 +5979,7 @@ static void initLabTabs()
5999
5979
}
6000
5980
6001
5981
// Lookup table for a,b to x,z conversion
5982
+ abToXZ_b = new int [LAB_BASE*9 /4 ];
6002
5983
for (i = minABvalue; i < LAB_BASE*9 /4 +minABvalue; i++)
6003
5984
{
6004
5985
int v;
@@ -6032,6 +6013,9 @@ static void initLabTabs()
6032
6013
*/
6033
6014
6034
6015
// Luv LUT
6016
+ LuToUp_b = new int [256 *256 ];
6017
+ LvToVp_b = new int [256 *256 ];
6018
+ LvToVpl_b = new long long int [256 *256 ];
6035
6019
for (int LL = 0 ; LL < 256 ; LL++)
6036
6020
{
6037
6021
softfloat L = softfloat (LL*100 )/f255;
@@ -6145,6 +6129,8 @@ static void initLabTabs()
6145
6129
}
6146
6130
}
6147
6131
}
6132
+ RGB2LabLUT_s16 = new int16_t [LAB_LUT_DIM*LAB_LUT_DIM*LAB_LUT_DIM*3 *8 ];
6133
+ RGB2LuvLUT_s16 = new int16_t [LAB_LUT_DIM*LAB_LUT_DIM*LAB_LUT_DIM*3 *8 ];
6148
6134
for (int p = 0 ; p < LAB_LUT_DIM; p++)
6149
6135
{
6150
6136
for (int q = 0 ; q < LAB_LUT_DIM; q++)
@@ -6199,15 +6185,15 @@ static void initLabTabs()
6199
6185
6200
6186
6201
6187
// cx, cy, cz are in [0; LAB_BASE]
6202
- static inline void trilinearInterpolate (int cx, int cy, int cz, int16_t * LUT,
6188
+ static inline void trilinearInterpolate (int cx, int cy, int cz, const int16_t * LUT,
6203
6189
int & a, int & b, int & c)
6204
6190
{
6205
6191
// LUT idx of origin pt of cube
6206
6192
int tx = cx >> (lab_base_shift - lab_lut_shift);
6207
6193
int ty = cy >> (lab_base_shift - lab_lut_shift);
6208
6194
int tz = cz >> (lab_base_shift - lab_lut_shift);
6209
6195
6210
- int16_t * baseLUT = &LUT[3 *8 *tx + (3 *8 *LAB_LUT_DIM)*ty + (3 *8 *LAB_LUT_DIM*LAB_LUT_DIM)*tz];
6196
+ const int16_t * baseLUT = &LUT[3 *8 *tx + (3 *8 *LAB_LUT_DIM)*ty + (3 *8 *LAB_LUT_DIM*LAB_LUT_DIM)*tz];
6211
6197
int aa[8 ], bb[8 ], cc[8 ];
6212
6198
for (int i = 0 ; i < 8 ; i++)
6213
6199
{
0 commit comments