]> git.sesse.net Git - nageru/blob - flags.cpp
Support changing the interpolation quality.
[nageru] / flags.cpp
1 #include "flags.h"
2
3 #include <getopt.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include <utility>
9
10 using namespace std;
11
12 Flags global_flags;
13
14 // Long options that have no corresponding short option.
15 enum LongOption {
16         OPTION_HELP = 1000,
17         OPTION_SLOW_DOWN_INPUT = 1001
18 };
19
20 void usage()
21 {
22         fprintf(stderr, "Usage: futatabi [OPTION]... SOURCE_URL\n");
23         fprintf(stderr, "\n");
24         fprintf(stderr, "      --help                      print usage information\n");
25         fprintf(stderr, "      --slow-down-input           slow down input to realtime (default on if no\n");
26         fprintf(stderr, "                                    source URL given)");
27         fprintf(stderr, "  -q, --interpolation-quality N   1 = fastest\n");
28         fprintf(stderr, "                                  2 = default (realtime 720p on fast embedded GPUs)\n");
29         fprintf(stderr, "                                  3 = good (realtime 720p on GTX 970 or so)\n");
30         fprintf(stderr, "                                  4 = best (not realtime on any current GPU)\n");
31 }
32
33 void parse_flags(int argc, char * const argv[])
34 {
35         static const option long_options[] = {
36                 { "help", no_argument, 0, OPTION_HELP },
37                 { "slow-down-input", no_argument, 0, OPTION_SLOW_DOWN_INPUT },
38                 { "interpolation-quality", required_argument, 0, 'q' },
39                 { 0, 0, 0, 0 }
40         };
41         for ( ;; ) {
42                 int option_index = 0;
43                 int c = getopt_long(argc, argv, "q:", long_options, &option_index);
44
45                 if (c == -1) {
46                         break;
47                 }
48                 switch (c) {
49                 case OPTION_SLOW_DOWN_INPUT:
50                         global_flags.slow_down_input = true;
51                         break;
52                 case 'q':
53                         global_flags.interpolation_quality = atoi(optarg);
54                         break;
55                 case OPTION_HELP:
56                         usage();
57                         exit(0);
58                 default:
59                         fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
60                         fprintf(stderr, "\n");
61                         usage();
62                         exit(1);
63                 }
64         }
65
66         if (global_flags.interpolation_quality < 1 || global_flags.interpolation_quality > 4) {
67                 fprintf(stderr, "Interpolation quality must be 1, 2, 3 or 4.\n");
68                 usage();
69                 exit(1);
70         }
71 }