53 if (c ==
' ' || c ==
'\r' || c ==
'\n' || c ==
'\t')
72 size_t pos = str.find(
" ");
73 while (pos != std::string::npos)
85 pos = str.find(
"\\{");
86 while (pos != std::string::npos)
89 pos = str.find(
"\\{");
91 pos = str.find(
"\\}");
92 while (pos != std::string::npos)
95 pos = str.find(
"\\}");
105 while (pos != std::string::npos)
107 str.insert(pos,
"\\\"");
108 pos = str.find(
"{", pos + 4);
111 while (pos != std::string::npos)
113 str.insert(pos + 1,
"\\\"");
114 pos = str.find(
"}", pos + 5);
123 name[0] = toupper(name[0]);
124 size_t pos = name.find(
"_");
125 while (pos != std::string::npos)
128 name[pos] = toupper(name[pos]);
129 pos = name.find(
"_", pos);
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 size_t end_pos = line.find(
"\"", start_pos);
204 yuv_specs = line.substr(start_pos, end_pos - start_pos);
214 const std::string& base_filename,
215 const std::string& src_ext,
216 const std::string& out_ext,
217 const std::string& ref_filename,
218 const std::string& yuv_specs,
220 int num_components,
double* mse,
int* pae)
223 std::string wavelet, cb_dims;
224 size_t start_pos = base_filename.find(
"_irv97_");
225 if (start_pos != std::string::npos)
230 file <<
"/////////////////////////////////////////////////////////"
231 <<
"//////////////////////" << std::endl;
232 file <<
"// Test ojph_expand with " <<
"codeblocks when the "
233 << wavelet <<
" wavelet is used." << std::endl;
234 if (out_ext.compare(
"yuv") == 0)
235 file <<
"// and the color components are subsampled." << std::endl;
236 file <<
"// Command-line options used to obtain this file is:" << std::endl;
237 while (comment.length() > 0)
240 size_t pos = comment.rfind(
' ', len);
241 if (comment.length() > len && pos != std::string::npos) {
242 file <<
"// " << comment.substr(0, pos) << std::endl;
243 comment.erase(0, pos + 1);
246 file <<
"// " << comment << std::endl;
253 file <<
" double mse[" << num_components <<
"] = { ";
254 for (
int i = 0; i < num_components; ++i) {
255 file << std::setprecision(6) << mse[i];
256 if (i < num_components - 1)
259 file <<
"};" << std::endl;
260 file <<
" int pae[" << num_components <<
"] = { ";
261 for (
int i = 0; i < num_components; ++i) {
263 if (i < num_components - 1)
266 file <<
"};" << std::endl;
267 file <<
" run_ojph_expand(\"" << base_filename <<
"\", \""
268 << src_ext <<
"\", \"" << out_ext <<
"\");" << std::endl;
269 file <<
" run_mse_pae(\"" << base_filename <<
"\", \""
270 << out_ext <<
"\", \"" << ref_filename <<
"\"," << std::endl;
271 file <<
" \"" << yuv_specs <<
"\", "
272 << num_components <<
", mse, pae);" << std::endl;
273 file <<
"}" << std::endl << std::endl;
279 const std::string& src_filename,
280 const std::string& ref_filename,
281 const std::string& base_filename,
282 const std::string& out_ext,
283 const std::string& decode_ext,
284 const std::string& yuv_specs,
286 std::string extra_cmd_options,
287 int num_components,
double* mse,
int* pae)
289 std::string wavelet, cb_dims;
290 size_t start_pos = base_filename.find(
"_irv97_");
291 if (start_pos != std::string::npos)
297 file <<
"/////////////////////////////////////////////////////////"
298 <<
"//////////////////////" << std::endl;
299 file <<
"// Test ojph_compress with " <<
"codeblocks when the "
300 << wavelet <<
" wavelet is used";
301 if (out_ext.compare(
"yuv") == 0) {
302 file <<
"," << std::endl <<
"// and the color components are subsampled.";
306 file <<
"." << std::endl;
307 file <<
"// We test by comparing MSE and PAE of decoded images. ";
310 file <<
"// The compressed file is obtained using these command-line "
311 "options:" << std::endl;
312 while (comment.length() > 0)
315 size_t pos = comment.rfind(
' ', len);
316 if (comment.length() > len && pos < comment.length()) {
317 file <<
"// " << comment.substr(0, pos) << std::endl;
318 comment.erase(0, pos + 1);
321 file <<
"// " << comment << std::endl;
329 file <<
" double mse[" << num_components <<
"] = { ";
330 for (
int i = 0; i < num_components; ++i) {
331 file << std::setprecision(6) << mse[i];
332 if (i < num_components - 1)
335 file <<
"};" << std::endl;
336 file <<
" int pae[" << num_components <<
"] = { ";
337 for (
int i = 0; i < num_components; ++i) {
339 if (i < num_components - 1)
342 file <<
"};" << std::endl;
345 file <<
" run_ojph_compress(\"" << ref_filename <<
"\"," << std::endl;
347 file <<
" \"" << base_filename <<
"\", \"\", \"" <<
"j2c" <<
"\",";
350 while (extra_cmd_options.length() > 0)
353 size_t pos = extra_cmd_options.rfind(
' ', len);
354 if (extra_cmd_options.length() > len && pos != std::string::npos) {
356 file << extra_cmd_options.substr(0, pos) <<
"\"";
357 extra_cmd_options.erase(0, pos);
358 if (extra_cmd_options.empty())
359 file <<
");" << std::endl;
365 file << extra_cmd_options <<
"\");" << std::endl;
366 extra_cmd_options.clear();
371 file <<
" run_ojph_compress_expand(\"" << base_filename <<
"\", \""
372 <<
"j2c" <<
"\", \"" << decode_ext <<
"\");" << std::endl;
375 file <<
" run_mse_pae(\"" << base_filename <<
"\", \""
376 << decode_ext <<
"\"," << std::endl;
377 file <<
" \"" << ref_filename <<
"\", \"" << yuv_specs <<
"\", "
378 << num_components <<
", mse, pae);" << std::endl;
381 file <<
"}" << std::endl << std::endl;
387 const std::string& ref_filename,
388 const std::string& base_filename,
389 const std::string& out_ext,
391 std::string extra_cmd_options)
393 std::string wavelet, cb_dims;
394 size_t start_pos = base_filename.find(
"_irv97_");
395 if (start_pos != std::string::npos)
401 file <<
"/////////////////////////////////////////////////////////"
402 <<
"//////////////////////" << std::endl;
403 file <<
"// Test ojph_compress with " <<
"codeblocks when the "
404 << wavelet <<
" wavelet is used";
405 if (out_ext.compare(
"yuv") == 0) {
406 file <<
"," << std::endl <<
"// and the color components are subsampled.";
410 file <<
"." << std::endl;
411 file <<
"// We test by comparing coded images, ignoring comments. ";
414 file <<
"// The compressed file is obtained using these command-line "
415 "options:" << std::endl;
417 while (comment.length() > 0)
420 size_t pos = comment.rfind(
' ', len);
421 if (comment.length() > len && pos < comment.length()) {
422 file <<
"// " << comment.substr(0, pos) << std::endl;
423 comment.erase(0, pos + 1);
426 file <<
"// " << comment << std::endl;
433 file <<
"Compare) {" << std::endl;
436 file <<
" run_ojph_compress(\"" << ref_filename <<
"\"," << std::endl;
438 file <<
" \"" << base_filename <<
"\", \"_compare\", \"" <<
"j2c";
439 file <<
"\"," << std::endl;
441 while (extra_cmd_options.length() > 0)
444 size_t pos = extra_cmd_options.rfind(
' ', len);
445 if (extra_cmd_options.length() > len && pos != std::string::npos) {
447 file << extra_cmd_options.substr(0, pos) <<
"\"";
448 extra_cmd_options.erase(0, pos);
449 if (extra_cmd_options.empty())
450 file <<
");" << std::endl;
456 file << extra_cmd_options <<
"\");" << std::endl;
457 extra_cmd_options.clear();
462 file <<
" compare_files(\"" << base_filename <<
"\", \"_compare\", \"";
463 file <<
"j2c" <<
"\");" << std::endl;
466 file <<
"}" << std::endl << std::endl;
471int main(
int argc,
char *argv[])
473 const char mse_pae_filename[] =
474 "../../build/tests/jp2k_test_codestreams/openjph/mse_pae.txt";
475 const char cmdlines_filename[] =
"ht_cmdlines.txt";
476 const char out_filename[] =
"openjph_tests.cpp";
478 std::ifstream mse_pae_file;
479 mse_pae_file.open(mse_pae_filename, std::ios_base::in);
480 if (mse_pae_file.fail()) {
481 std::cerr <<
"Failed to open " << mse_pae_filename <<
"." << std::endl;
485 std::ifstream cmdlines_file;
486 cmdlines_file.open(cmdlines_filename, std::ios_base::in);
487 if (cmdlines_file.fail()) {
488 std::cerr <<
"Failed to open " << cmdlines_filename <<
"." << std::endl;
492 std::ofstream out_file;
493 out_file.open(out_filename, std::ios_base::out);
494 if (out_file.fail()) {
495 std::cerr <<
"Failed to open " << out_filename <<
"." << std::endl;
499 while (mse_pae_file.good())
502 std::string ht_filename, src_filename, ref_filename;
503 mse_pae_file >> ht_filename;
504 std::string base_filename = ht_filename.substr(0, ht_filename.rfind(
"."));
505 std::string src_ext = ht_filename.substr(ht_filename.rfind(
".") + 1);
506 mse_pae_file >> ref_filename;
507 std::string out_ext = ref_filename.substr(ref_filename.rfind(
".") + 1);
508 ref_filename = ref_filename.substr(ref_filename.rfind(
"/") + 1);
511 std::cout <<
"base_filename = " << base_filename << std::endl;
512 std::cout <<
"src_ext = " << src_ext << std::endl;
513 std::cout <<
"out_ext = " << out_ext << std::endl;
514 std::cout <<
"ref_filename = " << ref_filename << std::endl;
516 constexpr int max_components = 10;
517 int num_components = 0;
518 double mse[max_components];
519 int pae[max_components];
521 int c = mse_pae_file.peek();
522 while (mse_pae_file.good() && std::isdigit(c))
524 if (num_components >= max_components)
525 std::cerr <<
"More than " << max_components <<
" were found in "
526 << mse_pae_filename <<
"; this is not supported." << std::endl;
527 mse_pae_file >> mse[num_components];
528 mse_pae_file >> pae[num_components];
529 std::cout <<
"mse = " << mse[num_components] << std::endl;
530 std::cout <<
"pae = " << pae[num_components] << std::endl;
533 c = mse_pae_file.peek();
537 if (base_filename.find(
"_dec_") != std::string::npos)
539 std::string yuv_specs, comment, extra_cmd_options;
541 yuv_specs, extra_cmd_options);
543 ref_filename, yuv_specs, comment, num_components, mse, pae);
548 if (base_filename.find(
"_enc_") != std::string::npos)
550 std::string yuv_specs, comment, extra_cmd_options;
552 yuv_specs, extra_cmd_options);
553 std::cout <<
"src_filename = " << src_filename << std::endl;
555 src_ext, out_ext, yuv_specs, comment, extra_cmd_options, num_components,
int main(int argc, char *argv[])
void process_cmdlines(std::ifstream &file, const std::string base_filename, std::string &src_filename, std::string &comment, std::string &yuv_specs, std::string &extra_cmd_options)
std::string prepare_test_name(std::string name)
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 insert_quotes(std::string &str)
void remove_double_spaces(std::string &str)
void eat_white_spaces(std::ifstream &file)
void remove_back_slashes(std::string &str)
void write_file_compare(std::ofstream &file, const std::string &ref_filename, const std::string &base_filename, const std::string &out_ext, std::string comment, std::string extra_cmd_options)
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)