Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit e438128

Browse files
committed
cli: Add --swizzle to convert action
1 parent cb37815 commit e438128

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/cli/action_convert.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace opts
4747
static int nomips;
4848
static int toDX;
4949
static int quiet;
50+
static int swizzle;
5051
} // namespace opts
5152

5253
static bool get_version_from_str(const std::string& str, int& major, int& minor);
@@ -236,6 +237,13 @@ const OptionList& ActionConvert::get_options() const {
236237
.type(OptType::Bool)
237238
.help("Silence output messages that aren't errors")
238239
);
240+
241+
opts::swizzle = opts.add(
242+
ActionOption()
243+
.long_opt("--swizzle")
244+
.type(OptType::String)
245+
.help("Perform an in-place swizzle on the image data")
246+
);
239247
};
240248
return opts;
241249
}
@@ -371,11 +379,23 @@ bool ActionConvert::process_file(
371379
auto image = std::make_shared<imglib::Image>(
372380
vtfFile->GetData(0, 0, 0, 0), procChanType, 4, vtfFile->GetWidth(), vtfFile->GetHeight(), true);
373381
if (!image->process(imglib::PROC_GL_TO_DX_NORM)) {
374-
375382
std::cerr << "Could not process vtf\n";
376383
return false;
377384
}
378385
}
386+
387+
// Swizzle the image if requested
388+
if (opts.has(opts::swizzle)) {
389+
uint32_t mask = imglib::swizzle_from_str(opts.get<std::string>(opts::swizzle).data());
390+
if (mask != lwiconv::NO_SWIZZLE) {
391+
auto image = std::make_shared<imglib::Image>(
392+
vtfFile->GetData(0, 0, 0, 0), procChanType, 4, vtfFile->GetWidth(), vtfFile->GetHeight(), true);
393+
if (!image->swizzle(mask)) {
394+
std::cerr << "Could not swizzle vtf\n";
395+
return false;
396+
}
397+
}
398+
}
379399

380400
// Set the properties based on user input
381401
if (!set_properties(vtfFile.get())) {

0 commit comments

Comments
 (0)