@@ -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,11 @@ 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_spectrum =
147+ main_spectral_set
148+ .emplace_back (
149+ SpectralData::SpectralChannel ( " power" , Spectrum ( 0 ) ) )
150+ .second ;
154151
155152 illuminant.illuminant = type;
156153 if ( is_daylight )
@@ -168,15 +165,15 @@ SpectralSolver::SpectralSolver(
168165 : _search_directories( search_directories )
169166{
170167 verbosity = 0 ;
171- _IDT_matrix .resize ( 3 );
172- _WB_multipliers .resize ( 3 );
168+ _idt_matrix .resize ( 3 );
169+ _wb_multipliers .resize ( 3 );
173170 for ( int i = 0 ; i < 3 ; i++ )
174171 {
175- _IDT_matrix [i].resize ( 3 );
176- _WB_multipliers [i] = 1.0 ;
172+ _idt_matrix [i].resize ( 3 );
173+ _wb_multipliers [i] = 1.0 ;
177174 for ( size_t j = 0 ; j < 3 ; j++ )
178175 {
179- _IDT_matrix [i][j] = neutral3[i][j];
176+ _idt_matrix [i][j] = neutral3[i][j];
180177 }
181178 }
182179}
@@ -402,7 +399,7 @@ bool SpectralSolver::find_illuminant( const vector<double> &wb )
402399 {
403400 sse = sse_tmp;
404401 illuminant = current_illuminant;
405- _WB_multipliers = wb_tmp;
402+ _wb_multipliers = wb_tmp;
406403 }
407404 }
408405
@@ -431,7 +428,7 @@ bool SpectralSolver::calculate_WB()
431428 return false ;
432429 }
433430
434- _WB_multipliers = _calculate_WB ( camera, illuminant );
431+ _wb_multipliers = _calculate_WB ( camera, illuminant );
435432 return true ;
436433}
437434
@@ -455,7 +452,7 @@ calculate_CM( const SpectralData &camera, const SpectralData &illuminant )
455452 double g = ( camera_g * illuminant_spectrum ).integrate ();
456453 double b = ( camera_b * illuminant_spectrum ).integrate ();
457454
458- double max = std::max ( r, std::max ( g, b ) );
455+ double max = std::max ( { r, g, b } );
459456
460457 std::vector<double > result ( 3 );
461458 result[0 ] = max / r;
@@ -613,14 +610,14 @@ struct IDTOptimizationCost
613610 IDTOptimizationCost (
614611 const std::vector<std::vector<double >> &RGB,
615612 const std::vector<std::vector<double >> &out_LAB )
616- : _RGB ( RGB ), _outLAB ( out_LAB )
613+ : _in_RGB ( RGB ), _out_LAB ( out_LAB )
617614 {}
618615
619616 template <typename T>
620617 bool operator ()( const T *beta_params, T *residuals ) const ;
621618
622- const std::vector<std::vector<double >> _RGB ;
623- const std::vector<std::vector<double >> _outLAB ;
619+ const std::vector<std::vector<double >> _in_RGB ;
620+ const std::vector<std::vector<double >> _out_LAB ;
624621};
625622
626623// / Perform curve fitting optimization to find optimal IDT matrix parameters.
@@ -746,10 +743,10 @@ bool SpectralSolver::calculate_IDT_matrix()
746743 double beta_params_start[6 ] = { 1.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 };
747744
748745 auto TI = calculate_TI ( illuminant, training_data );
749- auto RGB = calculate_RGB ( camera, _WB_multipliers , TI );
746+ auto RGB = calculate_RGB ( camera, _wb_multipliers , TI );
750747 auto XYZ = calculate_XYZ ( observer, illuminant, TI );
751748
752- return curveFit ( RGB, XYZ, beta_params_start, verbosity, _IDT_matrix );
749+ return curveFit ( RGB, XYZ, beta_params_start, verbosity, _idt_matrix );
753750}
754751
755752// =====================================================================
@@ -763,12 +760,12 @@ bool SpectralSolver::calculate_IDT_matrix()
763760
764761const vector<vector<double >> &SpectralSolver::get_IDT_matrix () const
765762{
766- return _IDT_matrix ;
763+ return _idt_matrix ;
767764}
768765
769766const vector<double > &SpectralSolver::get_WB_multipliers () const
770767{
771- return _WB_multipliers ;
768+ return _wb_multipliers ;
772769}
773770
774771MetadataSolver::MetadataSolver ( const core::Metadata &metadata )
@@ -953,13 +950,13 @@ vector<double> find_XYZ_to_camera_matrix(
953950
954951 if ( metadata.calibration [0 ].illuminant == 0 )
955952 {
956- fprintf ( stderr, " No calibration illuminants were found. \n " ) ;
953+ std::cerr << " No calibration illuminants were found." << std::endl ;
957954 return metadata.calibration [0 ].XYZ_to_RGB_matrix ;
958955 }
959956
960957 if ( neutral_RGB.size () == 0 )
961958 {
962- fprintf ( stderr, " no neutral RGB values were found. \n " ) ;
959+ std::cerr << " No neutral RGB values were found." << std::endl ;
963960 return metadata.calibration [0 ].XYZ_to_RGB_matrix ;
964961 }
965962
@@ -980,9 +977,9 @@ vector<double> find_XYZ_to_camera_matrix(
980977 metadata.calibration [1 ].XYZ_to_RGB_matrix ;
981978
982979 double low_mired =
983- std::max ( min_mired, std::min ( max_mired, std::min ( mir1, mir2 ) ) );
980+ std::clamp ( std::min ( mir1, mir2 ), min_mired, max_mired );
984981 double high_mired =
985- std::max ( min_mired, std::min ( max_mired, std:: max ( mir1, mir2 ) ) );
982+ std::clamp ( std::max ( mir1, mir2 ), min_mired, max_mired );
986983 double mirStep = std::max ( 5.0 , ( high_mired - low_mired ) / 50.0 );
987984
988985 double current_mired = 0.0 , last_mired = 0.0 , estimated_mired = 0.0 ,
@@ -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