#include "arg_parse.h" #include #include Args::Args() : do_dither_image_(true), do_dither_grayscaled_(false), do_overwrite_(false), input_filename(), output_filename() {} void Args::PrintUsage() { std::cout << "Usage: [-h | --help] [-i | --input ] [-o " " | --output ] [-b | --blue " "] [-g | --gray] [--image] [--video] [--video-pngs] " "[--overwrite]\n" " -h | --help\t\t\t\tPrint this usage text\n" " -i | --input \tSet input filename\n" " -o | --output \tSet output filename\n" " -b | --blue \tSet input blue_noise filename\n" " -g | --gray\t\t\t\tDither output in grayscale\n" " --image\t\t\t\tDither a single image\n" " --video\t\t\t\tDither frames in a video\n" " --video-pngs\t\t\t\tDither frames but output as individual pngs\n" " --overwrite\t\t\t\tAllow overwriting existing files\n" "It is recommended to use the .png extension for image output, and " ".mp4 for video output." << std::endl; } bool Args::ParseArgs(int argc, char **argv) { --argc; ++argv; while (argc > 0) { if (std::strcmp(argv[0], "-h") == 0 || std::strcmp(argv[0], "--help") == 0) { PrintUsage(); return true; } else if (argc > 1 && (std::strcmp(argv[0], "-i") == 0 || std::strcmp(argv[0], "--input") == 0)) { input_filename = std::string(argv[1]); --argc; ++argv; } else if (argc > 1 && (std::strcmp(argv[0], "-o") == 0 || std::strcmp(argv[0], "--output") == 0)) { output_filename = std::string(argv[1]); --argc; ++argv; } else if (argc > 1 && (std::strcmp(argv[0], "-b") == 0 || std::strcmp(argv[0], "--blue") == 0)) { blue_noise_filename = std::string(argv[1]); --argc; ++argv; } else if (std::strcmp(argv[0], "-g") == 0 || std::strcmp(argv[0], "--gray") == 0) { do_dither_grayscaled_ = true; } else if (std::strcmp(argv[0], "--image") == 0) { do_dither_image_ = true; } else if (std::strcmp(argv[0], "--video") == 0) { do_dither_image_ = false; } else if (std::strcmp(argv[0], "--video-pngs") == 0) { do_dither_image_ = false; do_video_pngs_ = true; } else if (std::strcmp(argv[0], "--overwrite") == 0) { do_overwrite_ = true; } else { std::cout << "WARNING: Ignoring invalid input \"" << argv[0] << '"' << std::endl; } --argc; ++argv; } return false; }