@@ -133,10 +133,11 @@ void initialise_gamma(pisp_be_gamma_config &gamma, const json &root)
133133 }
134134}
135135
136- void read_resample (std::vector<std::pair<std::string, pisp_be_resample_config>> &resample_filter_map ,
137- std::vector<std::pair< double , std::string>> &resample_select_list, const json &root)
136+ void read_resample (libpisp::ResampleMap &resample_filter_map, libpisp::ResampleList &resample_select_list ,
137+ const json &root)
138138{
139139 auto &filters = root[" resample" ][" filters" ];
140+ unsigned int i = 0 , j = 0 ;
140141
141142 for (auto const &[name, filter] : filters.items ())
142143 {
@@ -148,22 +149,28 @@ void read_resample(std::vector<std::pair<std::string, pisp_be_resample_config>>
148149 throw std::runtime_error (" read_resample: Incorrect number of filter coefficients" );
149150
150151 memcpy (r.coef , coefs.data (), sizeof (r.coef ));
151- resample_filter_map.emplace_back (name, r);
152+ resample_filter_map[i++] = { name, r };
153+ if (i == resample_filter_map.size ())
154+ break ;
152155 }
153156
157+ i = 0 ;
154158 auto &smart = root[" resample" ][" smart_selection" ];
155159 for (auto &scale : smart[" downscale" ])
156- resample_select_list.emplace_back (scale.get <double >(), std::string {});
160+ {
161+ resample_select_list[i++] = { scale.get <double >(), std::string {} };
162+ if (i == resample_select_list.size ())
163+ break ;
164+ }
157165
158- unsigned int i = 0 ;
159166 for (auto &filter : smart[" filter" ])
160167 {
161- resample_select_list[i ].second = filter.get <std::string>();
162- if (++i == resample_select_list.size ())
168+ resample_select_list[j++ ].second = filter.get <std::string>();
169+ if (j == resample_select_list.size ())
163170 break ;
164171 }
165- if (i != resample_select_list. size () )
166- throw std::runtime_error (" read_resample: Incorrect number of filters" );
172+ if (j != i )
173+ throw std::runtime_error (" read_resample: Incorrect number of smart filters/downscale factors " );
167174}
168175
169176// Macros for the sharpening filters, to avoid repeating the same code 5 times
@@ -222,10 +229,10 @@ void read_sharpen(pisp_be_sharpen_config &sharpen, pisp_be_sh_fc_combine_config
222229 shfc.y_factor = params[" shfc_y_factor" ].get <double >() * (1 << 8 );
223230}
224231
225- void read_ycbcr (std::vector<std::pair<std::string, pisp_be_ccm_config>> &ycbcr_map,
226- std::vector<std::pair<std::string, pisp_be_ccm_config>> &inverse_ycbcr_map, const json &root)
232+ void read_ycbcr (libpisp::YcbcrMap &ycbcr_map, libpisp::YcbcrMap &inverse_ycbcr_map, const json &root)
227233{
228234 auto encoding = root[" colour_encoding" ];
235+ unsigned int i = 0 ;
229236
230237 for (auto const &[format, enc] : encoding.items ())
231238 {
@@ -247,15 +254,17 @@ void read_ycbcr(std::vector<std::pair<std::string, pisp_be_ccm_config>> &ycbcr_m
247254 memcpy (ccm.offsets , offsets.data (), sizeof (ccm.offsets ));
248255
249256 if (key == " ycbcr" )
250- ycbcr_map. emplace_back ( format, ccm) ;
257+ ycbcr_map[i] = { format, ccm } ;
251258 else
252- inverse_ycbcr_map. emplace_back ( format, ccm) ;
259+ inverse_ycbcr_map[i] = { format, ccm } ;
253260 }
261+
262+ if (++i == ycbcr_map.size ())
263+ break ;
254264 }
255265}
256266
257- void get_matrix (pisp_be_ccm_config &matrix, const std::vector<std::pair<std::string, pisp_be_ccm_config>> &map,
258- const std::string &colour_space)
267+ void get_matrix (pisp_be_ccm_config &matrix, const libpisp::YcbcrMap &map, const std::string &colour_space)
259268{
260269 memset (matrix.coeffs , 0 , sizeof (matrix.coeffs ));
261270 memset (matrix.offsets , 0 , sizeof (matrix.offsets ));
0 commit comments