EN605.617.81.FA21_StephenSe.../src/arg_parse.cc

75 lines
2.6 KiB
C++
Raw Normal View History

2021-12-01 08:31:51 +00:00
#include "arg_parse.h"
#include <cstring>
#include <iostream>
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 <filename> | --input <filename>] [-o "
"<filename> | --output <filename>] [-b <filename> | --blue "
"<filename>] [-g | --gray] [--image] [--video] [--video-pngs] "
"[--overwrite]\n"
2021-12-01 08:31:51 +00:00
" -h | --help\t\t\t\tPrint this usage text\n"
" -i <filename> | --input <filename>\tSet input filename\n"
" -o <filename> | --output <filename>\tSet output filename\n"
" -b <filename> | --blue <filename>\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"
2021-12-01 08:31:51 +00:00
" --overwrite\t\t\t\tAllow overwriting existing files\n"
<< 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;
2021-12-01 08:31:51 +00:00
} 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;
}