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

Commit 2f5cdd6

Browse files
committed
cli: Add --swizzle to convert action
1 parent b3bc1df commit 2f5cdd6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
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,12 +379,24 @@ 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
}
379386

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+
}
399+
380400
// Set the properties based on user input
381401
if (!set_properties(vtfFile.get())) {
382402
std::cerr << "Could not set properties on VTF\n";

src/common/image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ uint32_t imglib::swizzle_from_str(const char* str) {
429429
case 'a': v = 3; break;
430430
default: return 0xFFFFFFFF;
431431
}
432-
mask |= v << (i*8);
432+
mask |= v << ((lwiconv::MAX_CHANNELS-i-1)*8);
433433
}
434434
return mask;
435435
}

0 commit comments

Comments
 (0)