139 const std::string base_filename,
140 std::string& src_filename,
141 std::string& comment, std::string& yuv_specs,
142 std::string& extra_cmd_options)
144 file.seekg(std::ios_base::beg);
148 std::getline(file, line);
151 size_t pos = line.find(base_filename);
152 if (pos != std::string::npos)
154 size_t start_pos = line.find(
"-i");
155 if (start_pos != std::string::npos) {
156 start_pos = line.find(
"/", start_pos);
157 if (start_pos == std::string::npos) {
158 printf(
"Formatting error in cmdlines file, pos -1\n");
161 size_t end_pos = line.find(
" ", start_pos);
162 if (start_pos == std::string::npos) {
163 printf(
"Formatting error in cmdlines file, pos 0\n");
166 src_filename = line.substr(start_pos + 1, end_pos - start_pos - 1);
169 start_pos = line.find(
"-o");
170 if (start_pos != std::string::npos) {
171 size_t end_pos = line.find(
"\"", start_pos);
172 if (end_pos == std::string::npos) {
173 printf(
"Formatting error in cmdlines file, pos 1\n");
177 comment = line.substr(start_pos, end_pos - start_pos);
182 extra_cmd_options = comment;
184 for (
int i = 0; i < 2; ++i)
185 if (start_pos < extra_cmd_options.length())
186 start_pos = extra_cmd_options.find(
" ", start_pos) + 1;
189 printf(
"Formatting error in cmdlines file, pos 2\n");
192 if (start_pos < extra_cmd_options.length())
193 extra_cmd_options.erase(0, start_pos);
196 printf(
"Formatting error in cmdlines file, pos 3\n");
201 start_pos = line.find(
":");
202 if (start_pos != std::string::npos) {
203 if (std::isdigit(line.at(start_pos + 1)))
205 size_t end_pos = line.find(
"\"", start_pos);
206 yuv_specs = line.substr(start_pos, end_pos - start_pos);
217 const std::string& base_filename,
218 const std::string& src_ext,
219 const std::string& out_ext,
220 const std::string& ref_filename,
221 const std::string& yuv_specs,
223 int num_components,
double* mse,
int* pae)
226 std::string wavelet, cb_dims;
227 size_t start_pos = base_filename.find(
"_irv97_");
228 if (start_pos != std::string::npos)
233 file <<
"/////////////////////////////////////////////////////////"
234 <<
"//////////////////////" << std::endl;
235 file <<
"// Test ojph_expand with " <<
"codeblocks when the "
236 << wavelet <<
" wavelet is used." << std::endl;
237 if (out_ext.compare(
"yuv") == 0)
238 file <<
"// and the color components are subsampled." << std::endl;
239 file <<
"// Command-line options used to obtain this file is:" << std::endl;
240 while (comment.length() > 0)
243 size_t pos = comment.rfind(
' ', len);
244 if (comment.length() > len && pos != std::string::npos) {
245 file <<
"// " << comment.substr(0, pos) << std::endl;
246 comment.erase(0, pos + 1);
249 file <<
"// " << comment << std::endl;
256 file <<
" double mse[" << num_components <<
"] = { ";
257 for (
int i = 0; i < num_components; ++i) {
258 file << std::setprecision(6) << mse[i];
259 if (i < num_components - 1)
262 file <<
"};" << std::endl;
263 file <<
" int pae[" << num_components <<
"] = { ";
264 for (
int i = 0; i < num_components; ++i) {
266 if (i < num_components - 1)
269 file <<
"};" << std::endl;
270 file <<
" run_ojph_expand(\"" << base_filename <<
"\", \""
271 << src_ext <<
"\", \"" << out_ext <<
"\");" << std::endl;
272 file <<
" run_mse_pae(\"" << base_filename <<
"\", \""
273 << out_ext <<
"\", \"" << ref_filename <<
"\"," << std::endl;
274 file <<
" \"" << yuv_specs <<
"\", "
275 << num_components <<
", mse, pae);" << std::endl;
276 file <<
"}" << std::endl << std::endl;
282 const std::string& src_filename,
283 const std::string& ref_filename,
284 const std::string& base_filename,
285 const std::string& out_ext,
286 const std::string& decode_ext,
287 const std::string& yuv_specs,
289 std::string extra_cmd_options,
290 int num_components,
double* mse,
int* pae)
292 std::string wavelet, cb_dims;
293 size_t start_pos = base_filename.find(
"_irv97_");
294 if (start_pos != std::string::npos)
300 file <<
"/////////////////////////////////////////////////////////"
301 <<
"//////////////////////" << std::endl;
302 file <<
"// Test ojph_compress with " <<
"codeblocks when the "
303 << wavelet <<
" wavelet is used";
304 if (out_ext.compare(
"yuv") == 0) {
305 file <<
"," << std::endl <<
"// and the color components are subsampled.";
309 file <<
"." << std::endl;
310 file <<
"// We test by comparing MSE and PAE of decoded images. ";
313 file <<
"// The compressed file is obtained using these command-line "
314 "options:" << std::endl;
315 while (comment.length() > 0)
318 size_t pos = comment.rfind(
' ', len);
319 if (comment.length() > len && pos < comment.length()) {
320 file <<
"// " << comment.substr(0, pos) << std::endl;
321 comment.erase(0, pos + 1);
324 file <<
"// " << comment << std::endl;
332 file <<
" double mse[" << num_components <<
"] = { ";
333 for (
int i = 0; i < num_components; ++i) {
334 file << std::setprecision(6) << mse[i];
335 if (i < num_components - 1)
338 file <<
"};" << std::endl;
339 file <<
" int pae[" << num_components <<
"] = { ";
340 for (
int i = 0; i < num_components; ++i) {
342 if (i < num_components - 1)
345 file <<
"};" << std::endl;
348 file <<
" run_ojph_compress(\"" << ref_filename <<
"\"," << std::endl;
350 file <<
" \"" << base_filename <<
"\", \"\", \"" <<
"j2c" <<
"\",";
353 while (extra_cmd_options.length() > 0)
356 size_t pos = extra_cmd_options.rfind(
' ', len);
357 if (extra_cmd_options.length() > len && pos != std::string::npos) {
359 file << extra_cmd_options.substr(0, pos) <<
"\"";
360 extra_cmd_options.erase(0, pos);
361 if (extra_cmd_options.empty())
362 file <<
");" << std::endl;
368 file << extra_cmd_options <<
"\");" << std::endl;
369 extra_cmd_options.clear();
374 file <<
" run_ojph_compress_expand(\"" << base_filename <<
"\", \""
375 <<
"j2c" <<
"\", \"" << decode_ext <<
"\");" << std::endl;
378 file <<
" run_mse_pae(\"" << base_filename <<
"\", \""
379 << decode_ext <<
"\"," << std::endl;
380 file <<
" \"" << ref_filename <<
"\", \"" << yuv_specs <<
"\", "
381 << num_components <<
", mse, pae);" << std::endl;
384 file <<
"}" << std::endl << std::endl;
390 const std::string& ref_filename,
391 const std::string& base_filename,
392 const std::string& out_ext,
394 std::string extra_cmd_options)
396 std::string wavelet, cb_dims;
397 size_t start_pos = base_filename.find(
"_irv97_");
398 if (start_pos != std::string::npos)
404 file <<
"/////////////////////////////////////////////////////////"
405 <<
"//////////////////////" << std::endl;
406 file <<
"// Test ojph_compress with " <<
"codeblocks when the "
407 << wavelet <<
" wavelet is used";
408 if (out_ext.compare(
"yuv") == 0) {
409 file <<
"," << std::endl <<
"// and the color components are subsampled.";
413 file <<
"." << std::endl;
414 file <<
"// We test by comparing coded images, ignoring comments. ";
417 file <<
"// The compressed file is obtained using these command-line "
418 "options:" << std::endl;
420 while (comment.length() > 0)
423 size_t pos = comment.rfind(
' ', len);
424 if (comment.length() > len && pos < comment.length()) {
425 file <<
"// " << comment.substr(0, pos) << std::endl;
426 comment.erase(0, pos + 1);
429 file <<
"// " << comment << std::endl;
436 file <<
"Compare) {" << std::endl;
439 file <<
" run_ojph_compress(\"" << ref_filename <<
"\"," << std::endl;
441 file <<
" \"" << base_filename <<
"\", \"_compare\", \"" <<
"j2c";
442 file <<
"\"," << std::endl;
444 while (extra_cmd_options.length() > 0)
447 size_t pos = extra_cmd_options.rfind(
' ', len);
448 if (extra_cmd_options.length() > len && pos != std::string::npos) {
450 file << extra_cmd_options.substr(0, pos) <<
"\"";
451 extra_cmd_options.erase(0, pos);
452 if (extra_cmd_options.empty())
453 file <<
");" << std::endl;
459 file << extra_cmd_options <<
"\");" << std::endl;
460 extra_cmd_options.clear();
465 file <<
" compare_files(\"" << base_filename <<
"\", \"_compare\", \"";
466 file <<
"j2c" <<
"\");" << std::endl;
469 file <<
"}" << std::endl << std::endl;
474int main(
int argc,
char *argv[])
476 const char mse_pae_filename[] =
477 "../../build/tests/jp2k_test_codestreams/openjph/mse_pae.txt";
478 const char cmdlines_filename[] =
"ht_cmdlines.txt";
479 const char out_filename[] =
"openjph_tests.cpp";
481 std::ifstream mse_pae_file;
482 mse_pae_file.open(mse_pae_filename, std::ios_base::in);
483 if (mse_pae_file.fail()) {
484 std::cerr <<
"Failed to open " << mse_pae_filename <<
"." << std::endl;
488 std::ifstream cmdlines_file;
489 cmdlines_file.open(cmdlines_filename, std::ios_base::in);
490 if (cmdlines_file.fail()) {
491 std::cerr <<
"Failed to open " << cmdlines_filename <<
"." << std::endl;
495 std::ofstream out_file;
496 out_file.open(out_filename, std::ios_base::out);
497 if (out_file.fail()) {
498 std::cerr <<
"Failed to open " << out_filename <<
"." << std::endl;
502 while (mse_pae_file.good())
505 std::string ht_filename, src_filename, ref_filename;
506 mse_pae_file >> ht_filename;
507 std::string base_filename = ht_filename.substr(0, ht_filename.rfind(
"."));
508 std::string src_ext = ht_filename.substr(ht_filename.rfind(
".") + 1);
509 mse_pae_file >> ref_filename;
510 std::string out_ext = ref_filename.substr(ref_filename.rfind(
".") + 1);
511 ref_filename = ref_filename.substr(ref_filename.rfind(
"/") + 1);
514 std::cout <<
"base_filename = " << base_filename << std::endl;
515 std::cout <<
"src_ext = " << src_ext << std::endl;
516 std::cout <<
"out_ext = " << out_ext << std::endl;
517 std::cout <<
"ref_filename = " << ref_filename << std::endl;
519 constexpr int max_components = 10;
520 int num_components = 0;
521 double mse[max_components];
522 int pae[max_components];
524 int c = mse_pae_file.peek();
525 while (mse_pae_file.good() && std::isdigit(c))
527 if (num_components >= max_components)
528 std::cerr <<
"More than " << max_components <<
" were found in "
529 << mse_pae_filename <<
"; this is not supported." << std::endl;
530 mse_pae_file >> mse[num_components];
531 mse_pae_file >> pae[num_components];
532 std::cout <<
"mse = " << mse[num_components] << std::endl;
533 std::cout <<
"pae = " << pae[num_components] << std::endl;
536 c = mse_pae_file.peek();
540 if (base_filename.find(
"_dec_") != std::string::npos)
542 std::string yuv_specs, comment, extra_cmd_options;
544 yuv_specs, extra_cmd_options);
546 ref_filename, yuv_specs, comment, num_components, mse, pae);
551 if (base_filename.find(
"_enc_") != std::string::npos)
553 std::string yuv_specs, comment, extra_cmd_options;
555 yuv_specs, extra_cmd_options);
556 std::cout <<
"src_filename = " << src_filename << std::endl;
558 src_ext, out_ext, yuv_specs, comment, extra_cmd_options, num_components,
void write_expand_test(std::ofstream &file, const std::string &base_filename, const std::string &src_ext, const std::string &out_ext, const std::string &ref_filename, const std::string &yuv_specs, std::string comment, int num_components, double *mse, int *pae)
void write_compress_test(std::ofstream &file, const std::string &src_filename, const std::string &ref_filename, const std::string &base_filename, const std::string &out_ext, const std::string &decode_ext, const std::string &yuv_specs, std::string comment, std::string extra_cmd_options, int num_components, double *mse, int *pae)