@@ -55,10 +55,8 @@ void calculate_daylight_SPD( const int &cct_input, Spectrum &spectrum )
5555 cct = cct_input * 1.0 ;
5656 else
5757 {
58- fprintf (
59- stderr,
60- " The range of Correlated Color Temperature for "
61- " Day Light should be from 4000 to 25000. \n " );
58+ std::cerr << " The range of Correlated Color Temperature for "
59+ << " Day Light should be from 4000 to 25000." << std::endl;
6260 exit ( 1 );
6361 }
6462
@@ -104,10 +102,8 @@ void calculate_blackbody_SPD( const int &cct, Spectrum &spectrum )
104102{
105103 if ( cct < 1500 || cct >= 4000 )
106104 {
107- fprintf (
108- stderr,
109- " The range of Color Temperature for BlackBody "
110- " should be from 1500 to 3999. \n " );
105+ std::cerr << " The range of Color Temperature for BlackBody "
106+ << " should be from 1500 to 3999." << std::endl;
111107 exit ( 1 );
112108 }
113109
@@ -147,10 +143,9 @@ void generate_illuminant(
147143 auto &main_spectral_set = main_iter->second ;
148144
149145 // Add the power channel and get a reference to it
150- auto &power_spectrum = main_spectral_set
151- .emplace_back ( SpectralData::SpectralChannel (
152- " power" , Spectrum ( 0 ) ) )
153- .second ;
146+ auto &power_data = main_spectral_set.emplace_back (
147+ SpectralData::SpectralChannel ( " power" , Spectrum ( 0 ) ) );
148+ auto &power_spectrum = power_data.second ;
154149
155150 illuminant.illuminant = type;
156151 if ( is_daylight )
@@ -168,15 +163,15 @@ SpectralSolver::SpectralSolver(
168163 : _search_directories( search_directories )
169164{
170165 verbosity = 0 ;
171- _IDT_matrix .resize ( 3 );
172- _WB_multipliers .resize ( 3 );
166+ _idt_matrix .resize ( 3 );
167+ _wb_multipliers .resize ( 3 );
173168 for ( int i = 0 ; i < 3 ; i++ )
174169 {
175- _IDT_matrix [i].resize ( 3 );
176- _WB_multipliers [i] = 1.0 ;
170+ _idt_matrix [i].resize ( 3 );
171+ _wb_multipliers [i] = 1.0 ;
177172 for ( size_t j = 0 ; j < 3 ; j++ )
178173 {
179- _IDT_matrix [i][j] = neutral3[i][j];
174+ _idt_matrix [i][j] = neutral3[i][j];
180175 }
181176 }
182177}
@@ -402,7 +397,7 @@ bool SpectralSolver::find_illuminant( const vector<double> &wb )
402397 {
403398 sse = sse_tmp;
404399 illuminant = current_illuminant;
405- _WB_multipliers = wb_tmp;
400+ _wb_multipliers = wb_tmp;
406401 }
407402 }
408403
@@ -431,7 +426,7 @@ bool SpectralSolver::calculate_WB()
431426 return false ;
432427 }
433428
434- _WB_multipliers = _calculate_WB ( camera, illuminant );
429+ _wb_multipliers = _calculate_WB ( camera, illuminant );
435430 return true ;
436431}
437432
@@ -455,7 +450,7 @@ calculate_CM( const SpectralData &camera, const SpectralData &illuminant )
455450 double g = ( camera_g * illuminant_spectrum ).integrate ();
456451 double b = ( camera_b * illuminant_spectrum ).integrate ();
457452
458- double max = std::max ( r, std::max ( g, b ) );
453+ double max = std::max ( { r, g, b } );
459454
460455 std::vector<double > result ( 3 );
461456 result[0 ] = max / r;
@@ -613,14 +608,14 @@ struct IDTOptimizationCost
613608 IDTOptimizationCost (
614609 const std::vector<std::vector<double >> &RGB,
615610 const std::vector<std::vector<double >> &out_LAB )
616- : _RGB ( RGB ), _outLAB ( out_LAB )
611+ : _in_RGB ( RGB ), _out_LAB ( out_LAB )
617612 {}
618613
619614 template <typename T>
620615 bool operator ()( const T *beta_params, T *residuals ) const ;
621616
622- const std::vector<std::vector<double >> _RGB ;
623- const std::vector<std::vector<double >> _outLAB ;
617+ const std::vector<std::vector<double >> _in_RGB ;
618+ const std::vector<std::vector<double >> _out_LAB ;
624619};
625620
626621// / Perform curve fitting optimization to find optimal IDT matrix parameters.
@@ -746,10 +741,10 @@ bool SpectralSolver::calculate_IDT_matrix()
746741 double beta_params_start[6 ] = { 1.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 };
747742
748743 auto TI = calculate_TI ( illuminant, training_data );
749- auto RGB = calculate_RGB ( camera, _WB_multipliers , TI );
744+ auto RGB = calculate_RGB ( camera, _wb_multipliers , TI );
750745 auto XYZ = calculate_XYZ ( observer, illuminant, TI );
751746
752- return curveFit ( RGB, XYZ, beta_params_start, verbosity, _IDT_matrix );
747+ return curveFit ( RGB, XYZ, beta_params_start, verbosity, _idt_matrix );
753748}
754749
755750// =====================================================================
@@ -763,12 +758,12 @@ bool SpectralSolver::calculate_IDT_matrix()
763758
764759const vector<vector<double >> &SpectralSolver::get_IDT_matrix () const
765760{
766- return _IDT_matrix ;
761+ return _idt_matrix ;
767762}
768763
769764const vector<double > &SpectralSolver::get_WB_multipliers () const
770765{
771- return _WB_multipliers ;
766+ return _wb_multipliers ;
772767}
773768
774769MetadataSolver::MetadataSolver ( const core::Metadata &metadata )
@@ -953,13 +948,13 @@ vector<double> find_XYZ_to_camera_matrix(
953948
954949 if ( metadata.calibration [0 ].illuminant == 0 )
955950 {
956- fprintf ( stderr, " No calibration illuminants were found. \n " ) ;
951+ std::cerr << " No calibration illuminants were found." << std::endl ;
957952 return metadata.calibration [0 ].XYZ_to_RGB_matrix ;
958953 }
959954
960955 if ( neutral_RGB.size () == 0 )
961956 {
962- fprintf ( stderr, " no neutral RGB values were found. \n " ) ;
957+ std::cerr << " No neutral RGB values were found." << std::endl ;
963958 return metadata.calibration [0 ].XYZ_to_RGB_matrix ;
964959 }
965960
@@ -980,16 +975,16 @@ vector<double> find_XYZ_to_camera_matrix(
980975 metadata.calibration [1 ].XYZ_to_RGB_matrix ;
981976
982977 double low_mired =
983- std::max ( min_mired, std::min ( max_mired, std::min ( mir1, mir2 ) ) );
978+ std::clamp ( std::min ( mir1, mir2 ), min_mired, max_mired );
984979 double high_mired =
985- std::max ( min_mired, std::min ( max_mired, std:: max ( mir1, mir2 ) ) );
986- double mirStep = std::max ( 5.0 , ( high_mired - low_mired ) / 50.0 );
980+ std::clamp ( std::max ( mir1, mir2 ), min_mired, max_mired );
981+ double mired_step = std::max ( 5.0 , ( high_mired - low_mired ) / 50.0 );
987982
988- double current_mired = 0.0 , last_mired = 0.0 , estimated_mired = 0.0 ,
989- current_error = 0.0 , last_error = 0.0 , smallest_error = 0.0 ;
983+ double last_mired = 0.0 , estimated_mired = 0.0 , current_error = 0.0 ,
984+ last_error = 0.0 , smallest_error = 0.0 ;
990985
991- for ( current_mired = low_mired; current_mired < high_mired ;
992- current_mired += mirStep )
986+ double current_mired = low_mired;
987+ while ( current_mired < high_mired )
993988 {
994989 current_error =
995990 current_mired -
@@ -1020,6 +1015,8 @@ vector<double> find_XYZ_to_camera_matrix(
10201015
10211016 last_error = current_error;
10221017 last_mired = current_mired;
1018+
1019+ current_mired += mired_step;
10231020 }
10241021
10251022 return XYZ_to_camera_weighted_matrix (
@@ -1232,19 +1229,19 @@ vector<vector<double>> MetadataSolver::calculate_IDT_matrix()
12321229template <typename T>
12331230bool IDTOptimizationCost::operator ()( const T *beta_params, T *residuals ) const
12341231{
1235- vector<vector<T>> RGB_copy ( _RGB .size (), vector<T>( 3 ) );
1236- for ( size_t i = 0 ; i < _RGB .size (); i++ )
1232+ vector<vector<T>> RGB_copy ( _in_RGB .size (), vector<T>( 3 ) );
1233+ for ( size_t i = 0 ; i < _in_RGB .size (); i++ )
12371234 for ( size_t j = 0 ; j < 3 ; j++ )
1238- RGB_copy[i][j] = T ( _RGB [i][j] );
1235+ RGB_copy[i][j] = T ( _in_RGB [i][j] );
12391236
12401237 vector<vector<T>> out_calc_LAB =
12411238 XYZ_to_LAB ( getCalcXYZt ( RGB_copy, beta_params ) );
1242- for ( size_t i = 0 ; i < _RGB .size (); i++ )
1239+ for ( size_t i = 0 ; i < _in_RGB .size (); i++ )
12431240 for ( size_t j = 0 ; j < 3 ; j++ )
1244- residuals[i * 3 + j] = _outLAB [i][j] - out_calc_LAB[i][j];
1241+ residuals[i * 3 + j] = _out_LAB [i][j] - out_calc_LAB[i][j];
12451242
12461243 return true ;
12471244}
12481245
12491246} // namespace core
1250- } // namespace rta
1247+ } // namespace rta
0 commit comments