Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit bfe39fd

Browse files
committed
New report command-line option
1 parent 2fac63d commit bfe39fd

6 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/arguments/arguments.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ constexpr auto verbose_arg = optional_argument("--verbose", "Display all input f
9797

9898
constexpr auto help_arg = optional_argument("--help", "Show usage information.");
9999

100+
// Advanced options.
101+
constexpr auto alpha_black_arg = optional_arg{"--bc1-alpha-black", "-bc1-ab",
102+
"The BC1 encoder will use 3 color blocks for blocks containing black or very dark pixels. Increases texture quality "
103+
"substantially, but programs using these textures must ignore the alpha channel."};
104+
105+
constexpr auto report_arg =
106+
optional_arg{"--report", "-rp", "Prints information about the encoding process of each file."};
107+
108+
// Positional arguments.
100109
constexpr std::string_view input_name = "input";
101110
constexpr std::string_view input_help =
102111
"Encode all PNG files inside of this folder as DDS. It can also point to a single PNG file. "
@@ -108,10 +117,6 @@ constexpr std::string_view output_help =
108117
"Write DDS files to this folder instead of creating them next to input PNGs. This argument is ignored if input "
109118
"points to a TXT file.";
110119

111-
constexpr auto alpha_black_arg = optional_arg{"--bc1-alpha-black", "-bc1-ab",
112-
"The BC1 encoder will use 3 color blocks for blocks containing black or very dark pixels. Increases texture quality "
113-
"substantially, but programs using these textures must ignore the alpha channel."};
114-
115120
consteval std::size_t argument_name_total_space() {
116121
std::size_t max_space{};
117122
max_space = std::max(max_space, clean_arg.name.size() + clean_arg.shorter.size() + 2UL);
@@ -135,9 +140,10 @@ consteval std::size_t argument_name_total_space() {
135140
max_space = std::max(max_space, verbose_arg.name.size() + verbose_arg.shorter.size() + 2UL);
136141
max_space = std::max(max_space, regex_arg.name.size() + regex_arg.shorter.size() + 2UL);
137142
max_space = std::max(max_space, help_arg.name.size() + help_arg.shorter.size() + 2UL);
143+
max_space = std::max(max_space, alpha_black_arg.name.size() + alpha_black_arg.shorter.size() + 2UL);
144+
max_space = std::max(max_space, report_arg.name.size() + report_arg.shorter.size() + 2UL);
138145
max_space = std::max(max_space, input_name.size());
139146
max_space = std::max(max_space, output_name.size());
140-
max_space = std::max(max_space, alpha_black_arg.name.size() + alpha_black_arg.shorter.size() + 2UL);
141147

142148
return max_space + 2UL;
143149
}
@@ -244,6 +250,7 @@ std::string get_help(std::size_t max_threads) {
244250
ostream << "\nADVANCED OPTIONS:\n";
245251

246252
print_optional_argument(ostream, alpha_black_arg);
253+
print_optional_argument(ostream, report_arg);
247254

248255
return std::move(ostream).str();
249256
}
@@ -307,7 +314,6 @@ void argument_from_str<double>(
307314
} // anonymous namespace
308315

309316
namespace todds::args {
310-
311317
data get(int argc, char** argv) {
312318
const boost::nowide::args nowide_args(argc, argv);
313319
todds::vector<std::string_view> arguments;
@@ -426,6 +432,8 @@ data get(const todds::vector<std::string_view>& arguments) {
426432
parsed_arguments.verbose = true;
427433
} else if (matches(argument, alpha_black_arg)) {
428434
parsed_arguments.alpha_black = true;
435+
} else if (matches(argument, report_arg)) {
436+
parsed_arguments.report = true;
429437
} else {
430438
parsed_arguments.error = true;
431439
parsed_arguments.text = fmt::format("Invalid positional argument {:s}", argument);

src/arguments/include/todds/arguments.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct data {
3939
bool vflip;
4040
bool time;
4141
bool verbose;
42+
bool report;
4243
todds::regex regex;
4344
bool dry_run;
4445
bool progress;

src/pipeline/include/todds/input.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ struct input {
6262
* substantially, but programs using these textures must ignore the alpha channel.
6363
*/
6464
bool alpha_black{};
65+
66+
/** Prints information about the encoding process of each file. */
67+
bool report{};
6568
};
6669

6770
} // namespace todds::pipeline

src/pipeline/pipeline.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ void encode_as_dds(const input& input_data) {
164164

165165
cancel_encoding_log = nullptr;
166166
force_finish_flag = nullptr;
167+
168+
if (input_data.report) {
169+
boost::nowide::cout << "File;Width;Height;Mipmaps;Format\n";
170+
for (std::size_t index = 0U; index < input_data.paths.size(); ++index) {
171+
const std::string& dds_path = input_data.paths[index].second.string();
172+
const auto& data = files_data[index];
173+
boost::nowide::cout << fmt::format(
174+
"{:s};{:d};{:d};{:d};{:s}\n", dds_path, data.width, data.height, data.mipmaps, format::name(data.format));
175+
}
176+
}
167177
}
168178

169179
} // namespace todds::pipeline

src/task/task.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void run(const args::data& arguments) {
172172
input_data.scale_filter = arguments.scale_filter;
173173
input_data.progress = arguments.progress;
174174
input_data.alpha_black = arguments.alpha_black;
175+
input_data.report = arguments.report;
175176

176177
// Launch the parallel pipeline.
177178
pipeline::encode_as_dds(input_data);

test/test_arguments.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,19 @@ TEST_CASE("todds::arguments alpha_black", "[arguments]") {
610610
REQUIRE(shorter.alpha_black);
611611
}
612612
}
613+
614+
TEST_CASE("todds::arguments report", "[arguments]") {
615+
SECTION("The default value of report is false") {
616+
const auto arguments = get({binary, "."});
617+
REQUIRE(!arguments.report);
618+
}
619+
620+
SECTION("Providing the report parameter sets its value to true") {
621+
const auto arguments = get({binary, "--report", "."});
622+
REQUIRE(is_valid(arguments));
623+
REQUIRE(arguments.report);
624+
const auto shorter = get({binary, "-rp", "."});
625+
REQUIRE(is_valid(shorter));
626+
REQUIRE(shorter.report);
627+
}
628+
}

0 commit comments

Comments
 (0)