1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-22 04:20:07 +00:00

Updated for latest changes to command line tools

This commit is contained in:
Chuck Walbourn 2024-10-28 16:37:30 -07:00
parent a81f47952e
commit 708ded8419

View File

@ -99,15 +99,6 @@ namespace
enum OPTIONS : uint32_t enum OPTIONS : uint32_t
{ {
OPT_RECURSIVE = 1, OPT_RECURSIVE = 1,
OPT_FILELIST,
OPT_WIDTH,
OPT_HEIGHT,
OPT_FORMAT,
OPT_FILTER,
OPT_SRGBI,
OPT_SRGBO,
OPT_SRGB,
OPT_OUTPUTFILE,
OPT_TOLOWER, OPT_TOLOWER,
OPT_OVERWRITE, OPT_OVERWRITE,
OPT_USE_DX10, OPT_USE_DX10,
@ -118,10 +109,21 @@ namespace
OPT_TA_WRAP, OPT_TA_WRAP,
OPT_TA_MIRROR, OPT_TA_MIRROR,
OPT_GPU, OPT_GPU,
OPT_MAX OPT_FLAGS_MAX,
OPT_FILELIST,
OPT_WIDTH,
OPT_HEIGHT,
OPT_FORMAT,
OPT_FILTER,
OPT_SRGBI,
OPT_SRGBO,
OPT_SRGB,
OPT_OUTPUTFILE,
OPT_VERSION,
OPT_HELP,
}; };
static_assert(OPT_MAX <= 32, "dwOptions is a unsigned int bitfield"); static_assert(OPT_FLAGS_MAX <= 32, "dwOptions is a unsigned int bitfield");
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -160,6 +162,23 @@ namespace
{ nullptr, 0 } { nullptr, 0 }
}; };
const SValue<uint32_t> g_pOptionsLong[] =
{
{ L"file-list", OPT_FILELIST },
{ L"format", OPT_FORMAT },
{ L"height", OPT_HEIGHT },
{ L"help", OPT_HELP },
{ L"image-filter", OPT_FILTER },
{ L"overwrite", OPT_OVERWRITE },
{ L"separate-alpha", OPT_SEPALPHA },
{ L"srgb-in", OPT_SRGBI },
{ L"srgb-out", OPT_SRGBO },
{ L"to-lowercase", OPT_TOLOWER },
{ L"version", OPT_VERSION },
{ L"width", OPT_WIDTH },
{ nullptr, 0 }
};
#define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } #define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt }
const SValue<DXGI_FORMAT> g_pFormats[] = const SValue<DXGI_FORMAT> g_pFormats[] =
@ -229,18 +248,18 @@ namespace
{ nullptr, TEX_FILTER_DEFAULT } { nullptr, TEX_FILTER_DEFAULT }
}; };
#define CODEC_DDS 0xFFFF0001 constexpr uint32_t CODEC_DDS = 0xFFFF0001;
#define CODEC_TGA 0xFFFF0002 constexpr uint32_t CODEC_TGA = 0xFFFF0002;
#define CODEC_HDR 0xFFFF0005 constexpr uint32_t CODEC_HDR = 0xFFFF0005;
#ifdef USE_OPENEXR #ifdef USE_OPENEXR
#define CODEC_EXR 0xFFFF0006 constexpr uint32_t CODEC_EXR = 0xFFFF0008;
#endif #endif
#ifdef USE_LIBJPEG #ifdef USE_LIBJPEG
#define CODEC_JPEG 0xFFFF0007 constexpr uint32_t CODEC_JPEG = 0xFFFF0009;
#endif #endif
#ifdef USE_LIBPNG #ifdef USE_LIBPNG
#define CODEC_PNG 0xFFFF0008 constexpr uint32_t CODEC_PNG = 0xFFFF000A;
#endif #endif
const SValue<uint32_t> g_pExtFileTypes[] = const SValue<uint32_t> g_pExtFileTypes[] =
@ -381,20 +400,28 @@ namespace
static const wchar_t* const s_usage = static const wchar_t* const s_usage =
L"Usage: texenvmap <command> <options> [--] <files>\n\n" L"Usage: texenvmap <command> <options> [--] <files>\n\n"
L"\nCOMMANDS\n"
L" cubic create cubic environment map\n" L" cubic create cubic environment map\n"
L" sphere create sphere environment map\n" L" sphere create sphere environment map\n"
L" dualparabola create dual-parabolic environment map\n" L" dualparabola create dual-parabolic environment map\n"
L"\nOPTIONS\n"
L" -r wildcard filename search is recursive\n" L" -r wildcard filename search is recursive\n"
L" -flist <filename> use text file with a list of input files (one per line)\n" L" -flist <filename>, --file-list <filename>\n"
L" -w <n> width\n" L" use text file with a list of input files (one per line)\n"
L" -h <n> height\n" L"\n"
L" -f <format> format\n" L" -w <n>, --width <n> width for output\n"
L" -if <filter> image filtering\n" L" -h <n>, --height <n> height for output\n"
L" -srgb{i|o} sRGB {input, output}\n" L" -f <format>, --format <format> pixel format for output\n"
L"\n"
L" -if <filter>, --image-filter <filter> image filtering\n"
L" -srgb{i|o}, --srgb-in, --srgb-out sRGB {input, output}\n"
L"\n"
L" -o <filename> output filename\n" L" -o <filename> output filename\n"
L" -l force output filename to lower case\n" L" -l, --to-lowercase force output filename to lower case\n"
L" -y overwrite existing output file (if any)\n" L" -y, --overwrite overwrite existing output file (if any)\n"
L" -sepalpha resize alpha channel separately from color channels\n" L"\n"
L" -sepalpha, --separate-alpha resize/generate mips alpha channel separately from color channels\n"
L"\n"
L" -nowic Force non-WIC filtering\n" L" -nowic Force non-WIC filtering\n"
L" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n" L" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n"
L" -alpha convert premultiplied alpha to straight alpha\n" L" -alpha convert premultiplied alpha to straight alpha\n"
@ -1098,49 +1125,88 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{ {
PWSTR pArg = argv[iArg]; PWSTR pArg = argv[iArg];
if (allowOpts if (allowOpts && (('-' == pArg[0]) || ('/' == pArg[0])))
&& ('-' == pArg[0]) && ('-' == pArg[1])) {
uint32_t dwOption = 0;
PWSTR pValue = nullptr;
if (('-' == pArg[0]) && ('-' == pArg[1]))
{ {
if (pArg[2] == 0) if (pArg[2] == 0)
{ {
// "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths. // "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths.
allowOpts = false; allowOpts = false;
} continue;
else if (!_wcsicmp(pArg, L"--version"))
{
PrintLogo(true, g_ToolName, g_Description);
return 0;
}
else if (!_wcsicmp(pArg, L"--help"))
{
PrintUsage();
return 0;
} }
else else
{ {
wprintf(L"Unknown option: %ls\n", pArg); pArg += 2;
return 1;
}
}
else if (allowOpts
&& (('-' == pArg[0]) || ('/' == pArg[0])))
{
pArg++;
PWSTR pValue;
for (pValue = pArg; *pValue && (':' != *pValue); pValue++); for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue);
if (*pValue) if (*pValue)
*pValue++ = 0; *pValue++ = 0;
const uint32_t dwOption = LookupByName(pArg, g_pOptions); dwOption = LookupByName(pArg, g_pOptionsLong);
if (!dwOption || (dwOptions & (1 << dwOption))) }
}
else
{ {
pArg++;
for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue);
if (*pValue)
*pValue++ = 0;
dwOption = LookupByName(pArg, g_pOptions);
if (!dwOption)
{
if (LookupByName(pArg, g_pOptionsLong))
{
wprintf(L"ERROR: did you mean `--%ls` (with two dashes)?\n", pArg);
return 1;
}
}
}
switch (dwOption)
{
case 0:
wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName);
return 1;
case OPT_FILELIST:
case OPT_WIDTH:
case OPT_HEIGHT:
case OPT_FORMAT:
case OPT_FILTER:
case OPT_SRGBI:
case OPT_SRGBO:
case OPT_SRGB:
case OPT_OUTPUTFILE:
// These don't use flag bits
break;
case OPT_VERSION:
PrintLogo(true, g_ToolName, g_Description);
return 0;
case OPT_HELP:
PrintUsage(); PrintUsage();
return 0;
default:
if (dwOptions & (UINT32_C(1) << dwOption))
{
wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg);
return 1; return 1;
} }
dwOptions |= 1 << dwOption; dwOptions |= (UINT32_C(1) << dwOption);
break;
}
// Handle options with additional value parameter // Handle options with additional value parameter
switch (dwOption) switch (dwOption)
@ -1303,7 +1369,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{ {
const size_t count = conversion.size(); const size_t count = conversion.size();
std::filesystem::path path(pArg); std::filesystem::path path(pArg);
SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0, nullptr); SearchForFiles(path.make_preferred(), conversion, (dwOptions & (UINT32_C(1) << OPT_RECURSIVE)) != 0, nullptr);
if (conversion.size() <= count) if (conversion.size() <= count)
{ {
wprintf(L"No matching files found for %ls\n", pArg); wprintf(L"No matching files found for %ls\n", pArg);
@ -1325,7 +1391,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 0; return 0;
} }
if (~dwOptions & (1 << OPT_NOLOGO)) if (~dwOptions & (UINT32_C(1) << OPT_NOLOGO))
PrintLogo(false, g_ToolName, g_Description); PrintLogo(false, g_ToolName, g_Description);
ComPtr<ID3D11Device> pDevice; ComPtr<ID3D11Device> pDevice;
@ -1602,7 +1668,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
} }
// --- Undo Premultiplied Alpha (if requested) --------------------------------- // --- Undo Premultiplied Alpha (if requested) ---------------------------------
if ((dwOptions & (1 << OPT_DEMUL_ALPHA)) if ((dwOptions & (UINT32_C(1) << OPT_DEMUL_ALPHA))
&& HasAlpha(info.format) && HasAlpha(info.format)
&& info.format != DXGI_FORMAT_A8_UNORM) && info.format != DXGI_FORMAT_A8_UNORM)
{ {
@ -1794,12 +1860,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wprintf(L"\nWriting %ls ", outputFile.c_str()); wprintf(L"\nWriting %ls ", outputFile.c_str());
fflush(stdout); fflush(stdout);
if (dwOptions & (1 << OPT_TOLOWER)) if (dwOptions & (UINT32_C(1) << OPT_TOLOWER))
{ {
std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower);
} }
if (~dwOptions & (1 << OPT_OVERWRITE)) if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE))
{ {
if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES)
{ {
@ -1836,7 +1902,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
mdata.dimension = TEX_DIMENSION_TEXTURE2D; mdata.dimension = TEX_DIMENSION_TEXTURE2D;
hr = SaveToDDSFile(imageArray, 6, mdata, hr = SaveToDDSFile(imageArray, 6, mdata,
(dwOptions & (1 << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE, (dwOptions & (UINT32_C(1) << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE,
outputFile.c_str()); outputFile.c_str());
if (FAILED(hr)) if (FAILED(hr))
{ {