@@ -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
5253static 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 " ;
0 commit comments