Skip to content

Commit 21e1489

Browse files
committed
remove FORJ, FORIJ and fix warnings
Signed-off-by: Aleksandr Motsjonov <[email protected]>
1 parent dfe8fb7 commit 21e1489

File tree

10 files changed

+155
-121
lines changed

10 files changed

+155
-121
lines changed

src/rawtoaces_core/define.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
# define FALSE 0
3838
#endif
3939

40-
#define FORJ( val ) for ( int j = 0; j < val; j++ )
41-
#define FORIJ( val1, val2 ) \
42-
for ( int i = 0; i < val1; i++ ) \
43-
for ( int j = 0; j < val2; j++ )
4440
#define countSize( a ) ( static_cast<int>( sizeof( a ) / sizeof( ( a )[0] ) ) )
4541

4642
namespace rta
@@ -269,7 +265,7 @@ inline void lowerCase( char *tex )
269265
{
270266
std::string tmp( tex );
271267

272-
for ( int i = 0; i < tmp.size(); i++ )
268+
for ( size_t i = 0; i < tmp.size(); i++ )
273269
tex[i] = tolower( tex[i] );
274270
};
275271

@@ -296,7 +292,7 @@ inline bool isCTLetterDigit( const char c )
296292
// to represent color temperature(s) (e.g., D60, 3200K)
297293
inline bool isValidCT( std::string str )
298294
{
299-
int i = 0;
295+
size_t i = 0;
300296
size_t length = str.length();
301297

302298
if ( length == 0 )

src/rawtoaces_core/mathOps.h

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace core
2323

2424
template <typename T> int isSquare( const vector<vector<T>> &vm )
2525
{
26-
for ( int i = 0; i < vm.size(); i++ )
26+
for ( size_t i = 0; i < vm.size(); i++ )
2727
{
2828
if ( vm[i].size() != vm.size() )
2929
return 0;
@@ -86,31 +86,38 @@ vector<vector<T>> invertVM( const vector<vector<T>> &vMtx )
8686

8787
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> m;
8888
m.resize( vMtx.size(), vMtx[0].size() );
89-
FORIJ( m.rows(), m.cols() ) m( i, j ) = vMtx[i][j];
89+
for ( Eigen::Index i = 0; i < m.rows(); i++ )
90+
for ( Eigen::Index j = 0; j < m.cols(); j++ )
91+
m( i, j ) = vMtx[i][j];
9092

9193
// Map < Eigen::Matrix < T, Eigen::Dynamic, Eigen::Dynamic, RowMajor > > m (vMtx[0]);
9294
// m.resize(vMtx.size(), vMtx[0].size());
9395

9496
m = m.inverse();
9597

9698
vector<vector<T>> vMtxR( m.rows(), vector<T>( m.cols() ) );
97-
FORIJ( m.rows(), m.cols() ) vMtxR[i][j] = m( i, j );
99+
for ( Eigen::Index i = 0; i < m.rows(); i++ )
100+
for ( Eigen::Index j = 0; j < m.cols(); j++ )
101+
vMtxR[i][j] = m( i, j );
98102

99103
return vMtxR;
100104
};
101105

102106
template <typename T> vector<T> invertV( const vector<T> &vMtx )
103107
{
104-
int size = std::sqrt( static_cast<int>( vMtx.size() ) );
108+
size_t size = std::sqrt( static_cast<size_t>( vMtx.size() ) );
105109
vector<vector<T>> tmp( size, vector<T>( size ) );
106110

107-
FORIJ( size, size )
108-
tmp[i][j] = vMtx[i * size + j];
111+
for ( size_t i = 0; i < size; i++ )
112+
for ( size_t j = 0; j < size; j++ )
113+
tmp[i][j] = vMtx[i * size + j];
109114

110115
tmp = invertVM( tmp );
111116
vector<T> result( vMtx.size() );
112117

113-
FORIJ( size, size ) result[i * size + j] = tmp[i][j];
118+
for ( size_t i = 0; i < size; i++ )
119+
for ( size_t j = 0; j < size; j++ )
120+
result[i * size + j] = tmp[i][j];
114121

115122
return result;
116123
};
@@ -138,11 +145,15 @@ vector<vector<T>> transposeVec( const vector<vector<T>> &vMtx )
138145
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> m;
139146
m.resize( vMtx.size(), vMtx[0].size() );
140147

141-
FORIJ( m.rows(), m.cols() ) m( i, j ) = vMtx[i][j];
148+
for ( Eigen::Index i = 0; i < m.rows(); i++ )
149+
for ( Eigen::Index j = 0; j < m.cols(); j++ )
150+
m( i, j ) = vMtx[i][j];
142151
m.transposeInPlace();
143152

144153
vector<vector<T>> vTran( m.rows(), vector<T>( m.cols() ) );
145-
FORIJ( m.rows(), m.cols() ) vTran[i][j] = m( i, j );
154+
for ( Eigen::Index i = 0; i < m.rows(); i++ )
155+
for ( Eigen::Index j = 0; j < m.cols(); j++ )
156+
vTran[i][j] = m( i, j );
146157

147158
return vTran;
148159
};
@@ -162,12 +173,12 @@ template <typename T> T sumVectorM( const vector<vector<T>> &vct )
162173
size_t row = vct.size();
163174
size_t col = vct[0].size();
164175

165-
T sum = T( 0 );
166176
Eigen::Matrix<T, Eigen::Dynamic, 1> v;
167177
v.resize( row * col, 1 );
168178

169-
FORIJ( row, col )
170-
v( i * col + j ) = vct[i][j];
179+
for ( size_t i = 0; i < row; i++ )
180+
for ( size_t j = 0; j < col; j++ )
181+
v( i * col + j ) = vct[i][j];
171182

172183
return v.sum();
173184
};
@@ -177,11 +188,11 @@ template <typename T> void scaleVector( vector<T> &vct, const T scale )
177188
Eigen::Matrix<T, Eigen::Dynamic, 1> v;
178189
v.resize( vct.size(), 1 );
179190

180-
for ( int i = 0; i < vct.size(); i++ )
191+
for ( size_t i = 0; i < vct.size(); i++ )
181192
v( i, 0 ) = vct[i];
182193
v *= scale;
183194

184-
for ( int i = 0; i < vct.size(); i++ )
195+
for ( size_t i = 0; i < vct.size(); i++ )
185196
vct[i] = v( i, 0 );
186197

187198
return;
@@ -214,8 +225,8 @@ vector<T> mulVector( vector<T> vct1, vector<T> vct2, int k = 3 )
214225
int rows = ( static_cast<int>( vct1.size() ) ) / k;
215226
int cols = ( static_cast<int>( vct2.size() ) ) / k;
216227

217-
assert( rows * k == vct1.size() );
218-
assert( k * cols == vct2.size() );
228+
assert( static_cast<size_t>( rows * k ) == vct1.size() );
229+
assert( static_cast<size_t>( k * cols ) == vct2.size() );
219230

220231
vector<T> vct3( rows * cols );
221232
T *pA = &vct1[0];
@@ -246,15 +257,19 @@ mulVector( const vector<vector<T>> &vct1, const vector<vector<T>> &vct2 )
246257
m1.resize( vct1.size(), vct1[0].size() );
247258
m2.resize( vct2[0].size(), vct2.size() );
248259

249-
FORIJ( m1.rows(), m1.cols() )
250-
m1( i, j ) = vct1[i][j];
251-
FORIJ( m2.rows(), m2.cols() )
252-
m2( i, j ) = vct2[j][i];
260+
for ( Eigen::Index i = 0; i < m1.rows(); i++ )
261+
for ( Eigen::Index j = 0; j < m1.cols(); j++ )
262+
m1( i, j ) = vct1[i][j];
263+
for ( Eigen::Index i = 0; i < m2.rows(); i++ )
264+
for ( Eigen::Index j = 0; j < m2.cols(); j++ )
265+
m2( i, j ) = vct2[j][i];
253266

254267
m3 = m1 * m2;
255268

256269
vector<vector<T>> vct3( m3.rows(), vector<T>( m3.cols() ) );
257-
FORIJ( m3.rows(), m3.cols() ) vct3[i][j] = m3( i, j );
270+
for ( Eigen::Index i = 0; i < m3.rows(); i++ )
271+
for ( Eigen::Index j = 0; j < m3.cols(); j++ )
272+
vct3[i][j] = m3( i, j );
258273

259274
return vct3;
260275
};
@@ -268,9 +283,10 @@ vector<T> mulVector( const vector<vector<T>> &vct1, const vector<T> &vct2 )
268283
m1.resize( vct1.size(), vct1[0].size() );
269284
m2.resize( vct2.size(), 1 );
270285

271-
FORIJ( m1.rows(), m1.cols() )
272-
m1( i, j ) = vct1[i][j];
273-
for ( int i = 0; i < m2.rows(); i++ )
286+
for ( Eigen::Index i = 0; i < m1.rows(); i++ )
287+
for ( Eigen::Index j = 0; j < m1.cols(); j++ )
288+
m1( i, j ) = vct1[i][j];
289+
for ( Eigen::Index i = 0; i < m2.rows(); i++ )
274290
m2( i, 0 ) = vct2[i];
275291

276292
m3 = m1 * m2;
@@ -301,7 +317,7 @@ T calculate_SSE( const vector<T> &tcp, const vector<T> &src )
301317
vector<T> tmp( src.size() );
302318

303319
T sum = T( 0.0 );
304-
for ( int i = 0; i < tcp.size(); i++ )
320+
for ( size_t i = 0; i < tcp.size(); i++ )
305321
sum += std::pow( ( tcp[i] / src[i] - 1.0 ), T( 2.0 ) );
306322

307323
return sum;
@@ -334,7 +350,7 @@ vector<T> interp1DLinear(
334350

335351
vector<T> slope, intercept, Y1;
336352

337-
for ( int i = 0; i < X0.size() - 1; i++ )
353+
for ( size_t i = 0; i < X0.size() - 1; i++ )
338354
{
339355
slope.push_back( ( Y0[i + 1] - Y0[i] ) / ( X0[i + 1] - X0[i] ) );
340356
intercept.push_back( Y0[i] - X0[i] * slope[i] );
@@ -343,7 +359,7 @@ vector<T> interp1DLinear(
343359
slope.push_back( slope[slope.size() - 1] );
344360
intercept.push_back( intercept[intercept.size() - 1] );
345361

346-
for ( int i = 0; i < X1.size(); i++ )
362+
for ( size_t i = 0; i < X1.size(); i++ )
347363
{
348364
int index = findIndexInterp1( X1[i], X0, int( X0.size() ) );
349365
if ( index != -1 )
@@ -423,17 +439,18 @@ vector<vector<T>> XYZ_to_LAB( const vector<vector<T>> &XYZ )
423439
T add = T( 16.0 / 116.0 );
424440

425441
vector<vector<T>> tmpXYZ( XYZ.size(), vector<T>( 3, T( 1.0 ) ) );
426-
FORIJ( XYZ.size(), 3 )
427-
{
428-
tmpXYZ[i][j] = XYZ[i][j] / ACES_white_point_XYZ[j];
429-
if ( tmpXYZ[i][j] > T( e ) )
430-
tmpXYZ[i][j] = ceres::pow( tmpXYZ[i][j], T( 1.0 / 3.0 ) );
431-
else
432-
tmpXYZ[i][j] = T( k ) * tmpXYZ[i][j] + add;
433-
}
442+
for ( size_t i = 0; i < XYZ.size(); i++ )
443+
for ( size_t j = 0; j < 3; j++ )
444+
{
445+
tmpXYZ[i][j] = XYZ[i][j] / ACES_white_point_XYZ[j];
446+
if ( tmpXYZ[i][j] > T( e ) )
447+
tmpXYZ[i][j] = ceres::pow( tmpXYZ[i][j], T( 1.0 / 3.0 ) );
448+
else
449+
tmpXYZ[i][j] = T( k ) * tmpXYZ[i][j] + add;
450+
}
434451

435452
vector<vector<T>> outCalcLab( XYZ.size(), vector<T>( 3 ) );
436-
for ( int i = 0; i < XYZ.size(); i++ )
453+
for ( size_t i = 0; i < XYZ.size(); i++ )
437454
{
438455
outCalcLab[i][0] = T( 116.0 ) * tmpXYZ[i][1] - T( 16.0 );
439456
outCalcLab[i][1] = T( 500.0 ) * ( tmpXYZ[i][0] - tmpXYZ[i][1] );
@@ -452,7 +469,9 @@ getCalcXYZt( const vector<vector<T>> &RGB, const T beta_params[6] )
452469
vector<vector<T>> BV( 3, vector<T>( 3 ) );
453470
vector<vector<T>> M( 3, vector<T>( 3 ) );
454471

455-
FORIJ( 3, 3 ) M[i][j] = T( acesrgb_XYZ_3[i][j] );
472+
for ( size_t i = 0; i < 3; i++ )
473+
for ( size_t j = 0; j < 3; j++ )
474+
M[i][j] = T( acesrgb_XYZ_3[i][j] );
456475

457476
BV[0][0] = beta_params[0];
458477
BV[0][1] = beta_params[1];

src/rawtoaces_core/rawtoaces_core.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ SpectralSolver::SpectralSolver(
174174
{
175175
_IDT_matrix[i].resize( 3 );
176176
_WB_multipliers[i] = 1.0;
177-
FORJ( 3 )
177+
for ( size_t j = 0; j < 3; j++ )
178178
{
179179
_IDT_matrix[i][j] = neutral3[i][j];
180180
}
@@ -577,18 +577,17 @@ std::vector<std::vector<double>> calculate_XYZ(
577577
/// @param training_illuminants Training patches transformed by illuminant (from calculate_TI)
578578
/// @return 2D vector containing RGB values for each training patch
579579
std::vector<std::vector<double>> calculate_RGB(
580-
const SpectralData &camera,
581-
const SpectralData &illuminant,
580+
const SpectralData &camera,
581+
const SpectralData & /* illuminant */,
582582
const std::vector<double> &WB_multipliers,
583583
const std::vector<Spectrum> &training_illuminants )
584584
{
585585
assert( training_illuminants.size() > 0 );
586586
assert( training_illuminants[0].values.size() == 81 );
587587

588-
const Spectrum &camera_r = camera["R"];
589-
const Spectrum &camera_g = camera["G"];
590-
const Spectrum &camera_b = camera["B"];
591-
const Spectrum &illuminant_spectrum = illuminant["power"];
588+
const Spectrum &camera_r = camera["R"];
589+
const Spectrum &camera_g = camera["G"];
590+
const Spectrum &camera_b = camera["B"];
592591

593592
std::vector<std::vector<double>> RGB;
594593
for ( auto &training_illuminant: training_illuminants )
@@ -1193,18 +1192,21 @@ vector<vector<double>> MetadataSolver::calculate_IDT_matrix()
11931192

11941193
// 2. Converts the CAT matrix to a flattened format for matrix multiplication
11951194
vector<double> XYZ_D65_acesrgb( 9 ), CAT( 9 );
1196-
FORIJ( 3, 3 )
1197-
{
1198-
XYZ_D65_acesrgb[i * 3 + j] = XYZ_D65_acesrgb_3[i][j];
1199-
CAT[i * 3 + j] = CAT_matrix[i][j];
1200-
}
1195+
for ( size_t i = 0; i < 3; i++ )
1196+
for ( size_t j = 0; j < 3; j++ )
1197+
{
1198+
XYZ_D65_acesrgb[i * 3 + j] = XYZ_D65_acesrgb_3[i][j];
1199+
CAT[i * 3 + j] = CAT_matrix[i][j];
1200+
}
12011201

12021202
// 3. Multiplies the D65 ACES RGB to XYZ matrix with the CAT matrix
12031203
vector<double> matrix = mulVector( XYZ_D65_acesrgb, CAT, 3 );
12041204

12051205
// 4. Reshapes the result into a 3×3 transformation matrix
12061206
vector<vector<double>> DNG_IDT_matrix( 3, vector<double>( 3 ) );
1207-
FORIJ( 3, 3 ) DNG_IDT_matrix[i][j] = matrix[i * 3 + j];
1207+
for ( size_t i = 0; i < 3; i++ )
1208+
for ( size_t j = 0; j < 3; j++ )
1209+
DNG_IDT_matrix[i][j] = matrix[i * 3 + j];
12081210

12091211
// 5. Validates the matrix properties (non-zero determinant)
12101212
assert( std::fabs( sumVectorM( DNG_IDT_matrix ) - 0.0 ) > 1e-09 );
@@ -1232,11 +1234,15 @@ template <typename T>
12321234
bool IDTOptimizationCost::operator()( const T *beta_params, T *residuals ) const
12331235
{
12341236
vector<vector<T>> RGB_copy( 190, vector<T>( 3 ) );
1235-
FORIJ( 190, 3 ) RGB_copy[i][j] = T( _RGB[i][j] );
1237+
for ( size_t i = 0; i < 190; i++ )
1238+
for ( size_t j = 0; j < 3; j++ )
1239+
RGB_copy[i][j] = T( _RGB[i][j] );
12361240

12371241
vector<vector<T>> out_calc_LAB =
12381242
XYZ_to_LAB( getCalcXYZt( RGB_copy, beta_params ) );
1239-
FORIJ( 190, 3 ) residuals[i * 3 + j] = _outLAB[i][j] - out_calc_LAB[i][j];
1243+
for ( size_t i = 0; i < 190; i++ )
1244+
for ( size_t j = 0; j < 3; j++ )
1245+
residuals[i * 3 + j] = _outLAB[i][j] - out_calc_LAB[i][j];
12401246

12411247
return true;
12421248
}

src/rawtoaces_core/spectral_data.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ bool SpectralData::load( const std::string &path, bool reshape )
252252
auto &set_entry = data[set_name];
253253
size_t count = set_entry.size();
254254

255-
size_t channel_index = 0;
256255
for ( auto &[bin_wavelength, bin_values]:
257256
spectral_data[set_name].items() )
258257
{
@@ -280,12 +279,10 @@ bool SpectralData::load( const std::string &path, bool reshape )
280279

281280
prev_wavelength = this_wavelength;
282281

283-
for ( int j = 0; j < count; j++ )
282+
for ( size_t j = 0; j < count; j++ )
284283
{
285284
set_entry[j].second.values.push_back( bin_values[j] );
286285
}
287-
288-
channel_index++;
289286
}
290287
}
291288

src/rawtoaces_util/image_converter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,11 +860,12 @@ void ImageConverter::init_parser( OIIO::ArgParse &arg_parser )
860860
.help(
861861
"(-v) Print progress messages. "
862862
"Repeated -v will increase verbosity." )
863-
.action(
864-
[&]( OIIO::cspan<const char *> argv ) { settings.verbosity++; } );
863+
.action( [&]( OIIO::cspan<const char *> /* argv */ ) {
864+
settings.verbosity++;
865+
} );
865866

866867
arg_parser.arg( "-v" ).hidden().action(
867-
[&]( OIIO::cspan<const char *> argv ) { settings.verbosity++; } );
868+
[&]( OIIO::cspan<const char *> /* argv */ ) { settings.verbosity++; } );
868869
}
869870

870871
bool ImageConverter::parse_parameters( const OIIO::ArgParse &arg_parser )
@@ -1521,14 +1522,14 @@ bool ImageConverter::apply_matrix(
15211522
}
15221523

15231524
bool ImageConverter::apply_scale(
1524-
OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI roi )
1525+
OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI /* roi */ )
15251526
{
15261527
return OIIO::ImageBufAlgo::mul(
15271528
dst, src, settings.headroom * settings.scale );
15281529
}
15291530

15301531
bool ImageConverter::apply_crop(
1531-
OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI roi )
1532+
OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI /* roi */ )
15321533
{
15331534
if ( settings.crop_mode == Settings::CropMode::Off )
15341535
{

0 commit comments

Comments
 (0)