1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
6 #ifndef TOOLS_BENCHMARK_BENCHMARK_ARGS_H_
7 #define TOOLS_BENCHMARK_BENCHMARK_ARGS_H_
9 // Command line parsing and arguments for benchmark_xl
18 #include "lib/extras/dec/color_hints.h"
19 #include "lib/jxl/base/override.h"
20 #include "lib/jxl/base/status.h"
21 #include "lib/jxl/butteraugli/butteraugli.h"
22 #include "lib/jxl/color_encoding_internal.h"
23 #include "tools/args.h"
24 #include "tools/cmdline.h"
29 using ::jxl::ColorEncoding;
30 using ::jxl::Override;
33 std::vector<std::string> SplitString(const std::string& s, char c);
35 int ParseIntParam(const std::string& param, int lower_bound, int upper_bound);
37 struct BenchmarkArgs {
38 using OptionId = jpegxl::tools::CommandLineParser::OptionId;
40 void AddFlag(bool* field, const char* longName, const char* help,
42 const char* noName = RememberString_(std::string("no") + longName);
43 cmdline.AddOptionFlag('\0', longName, nullptr, field,
44 &jpegxl::tools::SetBooleanTrue);
45 cmdline.AddOptionFlag('\0', noName, help, field,
46 &jpegxl::tools::SetBooleanFalse);
47 *field = defaultValue;
50 OptionId AddOverride(Override* field, const char* longName,
52 OptionId result = cmdline.AddOptionValue('\0', longName, "0|1", help, field,
53 &jpegxl::tools::ParseOverride);
54 *field = Override::kDefault;
58 OptionId AddString(std::string* field, const char* longName, const char* help,
59 const std::string& defaultValue = "") {
60 OptionId result = cmdline.AddOptionValue(
61 '\0', longName, "<string>", help, field, &jpegxl::tools::ParseString);
62 *field = defaultValue;
66 OptionId AddFloat(float* field, const char* longName, const char* help,
68 OptionId result = cmdline.AddOptionValue('\0', longName, "<scalar>", help,
69 field, &jpegxl::tools::ParseFloat);
70 *field = defaultValue;
74 OptionId AddDouble(double* field, const char* longName, const char* help,
75 double defaultValue) {
76 OptionId result = cmdline.AddOptionValue(
77 '\0', longName, "<scalar>", help, field, &jpegxl::tools::ParseDouble);
78 *field = defaultValue;
82 OptionId AddSigned(int* field, const char* longName, const char* help,
84 OptionId result = cmdline.AddOptionValue(
85 '\0', longName, "<integer>", help, field, &jpegxl::tools::ParseSigned);
86 *field = defaultValue;
90 OptionId AddUnsigned(size_t* field, const char* longName, const char* help,
91 size_t defaultValue) {
93 cmdline.AddOptionValue('\0', longName, "<unsigned>", help, field,
94 &jpegxl::tools::ParseUnsigned);
95 *field = defaultValue;
99 Status AddCommandLineOptions();
101 Status ValidateArgs();
103 bool Parse(int argc, const char** argv) { return cmdline.Parse(argc, argv); }
105 void PrintHelp() const { cmdline.PrintHelp(); }
110 bool print_details_csv;
111 bool print_more_stats;
112 bool print_distance_percentiles;
114 bool save_compressed;
115 bool save_decompressed;
116 std::string output_extension; // see CodecFromPath
117 std::string output_description; // see ParseDescription
118 ColorEncoding output_encoding; // determined by output_description
121 bool skip_butteraugli;
123 float intensity_target;
125 std::string color_hints_string;
126 jxl::extras::ColorHints color_hints;
128 size_t override_bitdepth;
135 bool write_html_report;
136 bool html_report_self_contained;
137 bool html_report_use_decompressed;
138 bool html_report_add_heatmap;
142 std::string originals_url;
143 std::string output_dir;
150 std::string sample_tmp_dir;
153 int sample_dimensions;
158 std::string extra_metrics;
160 jpegxl::tools::CommandLineParser cmdline;
163 const char* RememberString_(const std::string& text) {
164 const char* data = text.c_str();
165 std::vector<char> copy(data, data + text.size() + 1);
166 string_pool_.push_back(copy);
167 return string_pool_.back().data();
170 // A memory pool with stable addresses for strings to provide stable
171 // const char pointers to cmdline.h for dynamic help/name strings.
172 std::deque<std::vector<char>> string_pool_;
176 BenchmarkArgs* Args();
179 } // namespace jpegxl
181 #endif // TOOLS_BENCHMARK_BENCHMARK_ARGS_H_