You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

50 lines
1.8 KiB

  1. #include "parseargs.hh"
  2. #include <boost/program_options.hpp>
  3. #include <cstdlib>
  4. #include <iostream>
  5. constexpr int DEFAULT_ITERATIONS = 5000;
  6. using path = std::filesystem::path;
  7. namespace po = boost::program_options;
  8. void processFilenames(po::variables_map const &vm, path const &t_input,
  9. path &t_output) {
  10. if (!vm.count("output")) {
  11. t_output.replace_filename("output_" +
  12. std::string{t_input.filename().string()});
  13. } else if (!t_output.has_extension()) {
  14. t_output.replace_extension(".png");
  15. }
  16. }
  17. std::tuple<path, path, int, int, bool> parse_args(int t_ac, char **t_av) {
  18. po::options_description desc("Allowed options");
  19. desc.add_options()
  20. ("help,h", "Display this help message")
  21. ("input,i", po::value<path>(), "Input image")
  22. ("output,o", po::value<path>(),
  23. "Image output path (default: input path + \"_output\")")
  24. ("method,m", po::value<int>(), "Method number to be used (default: 1)")
  25. ("iterations,n", po::value<int>(), "Number of iterations (default: 5000)")
  26. ("verbose,v", "Enables verbosity");
  27. po::variables_map vm;
  28. po::store(po::parse_command_line(t_ac, t_av, desc), vm);
  29. po::notify(vm);
  30. if (vm.count("help") || !vm.count("input")) {
  31. std::cout << desc << "\n";
  32. std::exit(1);
  33. }
  34. auto const input_path = vm["input"].as<path>();
  35. auto output_path =
  36. vm.count("output") ? vm["output"].as<path>() : input_path.filename();
  37. processFilenames(vm, input_path, output_path);
  38. return std::make_tuple(input_path, output_path,
  39. vm.count("iterations") ? vm["iterations"].as<int>()
  40. : DEFAULT_ITERATIONS,
  41. vm.count("method") ? vm["method"].as<int>() : 1,
  42. vm.count("verbose") ? true : false);
  43. }