From d6663fe7b71db340b3c7a1d069c473f725caa3a8 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 29 Aug 2022 12:19:25 -0400 Subject: Trying to support the superior operating system. Also reformat a bit of legacy code. Smells like mold. --- tests/testdrive.cpp | 160 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 92 insertions(+), 68 deletions(-) (limited to 'tests') diff --git a/tests/testdrive.cpp b/tests/testdrive.cpp index c0d1038..2d8b0eb 100644 --- a/tests/testdrive.cpp +++ b/tests/testdrive.cpp @@ -1,5 +1,3 @@ -#include "signature.hpp" - #include #include @@ -16,44 +14,55 @@ #include +#ifdef _WIN32 //for the superior operating system +#include +#include +#include +#endif + +#include "signature.hpp" +#include "imageutil.hpp" + #include "thread_pool.hpp" #define DEBUG 0 +namespace fs = std::filesystem; + int ctr; int recursive; -int njobs=1; -double threshold=0.3; -std::vector paths; -std::vector files; +int njobs = 1; +double threshold = 0.3; +std::vector paths; +std::vector files; int nsliceh = 3; int nslicev = 3; signature_config cfg_full = { - 9, //slices - 3, //blur_window - 2, //min_window - true, //crop - true, //comp - 0.5, //pr - 1./128,//noise_threshold - 0.05, //contrast_threshold - 0.25 //max_cropping + 9, //slices + 3, //blur_window + 2, //min_window + true, //crop + true, //comp + 0.5, //pr + 1./128, //noise_threshold + 0.05, //contrast_threshold + 0.25 //max_cropping }; signature_config cfg_subslice = { - 4, //slices - 16, //blur_window - 2, //min_window - false, //crop - true, //comp - 0.5, //pr - 1./64, //noise_threshold - 0.05, //contrast_threshold - 0.25 //max_cropping + 4, //slices + 16, //blur_window + 2, //min_window + false, //crop + true, //comp + 0.5, //pr + 1./64, //noise_threshold + 0.05, //contrast_threshold + 0.25 //max_cropping }; struct sig_eq @@ -73,48 +82,59 @@ std::vector> out; int parse_arguments(int argc,char **argv) { - recursive=0; - int help=0; + recursive = 0; + int help = 0; option longopt[]= { - {"recursive",no_argument ,&recursive,1}, -// {"destdir" ,required_argument,0 ,'D'}, - {"jobs" ,required_argument,0 ,'j'}, -// {"threshold",required_argument,0 ,'d'}, - {"help" ,no_argument ,&help ,1}, - {0 ,0 ,0 ,0} + {"recursive", no_argument , &recursive, 1}, +// {"destdir" , required_argument, 0 , 'D'}, + {"jobs" , required_argument, 0 , 'j'}, +// {"threshold", required_argument, 0 , 'd'}, + {"help" , no_argument , &help , 1}, + {0 , 0 , 0 , 0} }; while(1) { - int idx=0; - int c=getopt_long(argc,argv,"rhj:",longopt,&idx); - if(!~c)break; - switch(c) + int idx = 0; + int c = getopt_long(argc, argv, "rhj:", longopt, &idx); + if (!~c) break; + switch (c) { case 0: - if(longopt[idx].flag)break; - if(std::string("jobs")==longopt[idx].name) - sscanf(optarg,"%d",&njobs); - //if(std::string("threshold")==longopt[idx].name) - //sscanf(optarg,"%lf",&threshold); + if (longopt[idx].flag) break; + if (std::string("jobs") == longopt[idx].name) + sscanf(optarg, "%d", &njobs); + //if(std::string("threshold") == longopt[idx].name) + //sscanf(optarg, "%lf", &threshold); break; case 'r': - recursive=1; + recursive = 1; break; case 'h': - help=1; + help = 1; break; case 'j': - sscanf(optarg,"%d",&njobs); + sscanf(optarg, "%d", &njobs); break; case 'd': - sscanf(optarg,"%lf",&threshold); + //sscanf(optarg, "%lf", &threshold); break; } } - for(;optind1||threshold<0) + if (threshold > 1 || threshold < 0) { puts("Invalid threshold value."); return 2; } - if(threshold<1e-6)threshold=1e-6; - if(!paths.size()) + if (threshold < 1e-6) threshold = 1e-6; + if (!paths.size()) { puts("Missing image path."); return 2; @@ -141,12 +161,12 @@ int parse_arguments(int argc,char **argv) return 0; } -void build_file_list(std::filesystem::path path,bool recursive,std::vector&out) +void build_file_list(fs::path path, bool recursive, std::vector &out) { - if(recursive) + if (recursive) { - auto dirit=std::filesystem::recursive_directory_iterator(path); - for(auto &p:dirit) + auto dirit = fs::recursive_directory_iterator(path); + for (auto &p : dirit) { FILE* fp = fopen(p.path().c_str(),"r"); char c[8]; @@ -164,8 +184,8 @@ void build_file_list(std::filesystem::path path,bool recursive,std::vector 1 s.dump(); @@ -250,36 +270,40 @@ void job_func(int thid, size_t id) void run() { thread_pool tp(njobs); - for(size_t i=0;i