From 9cb80ba2af5985fea12e51ca4ceb1b937b5b1828 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Wed, 23 Oct 2024 22:16:38 -0700 Subject: [PATCH 01/18] Convert texconv to use GNU-style long options --- Texconv/texconv.cpp | 254 ++++++++++++++++++++++++++++---------------- 1 file changed, 160 insertions(+), 94 deletions(-) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index e096cc13..2a004299 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -166,7 +166,9 @@ namespace OPT_USE_XBOX, OPT_XGMODE, #endif - OPT_MAX + OPT_FLAGS_MAX, + OPT_VERSION, + OPT_HELP, }; enum @@ -187,7 +189,7 @@ namespace FORMAT_DXT5_RXGB, }; - static_assert(OPT_MAX <= 64, "dwOptions is a unsigned int bitfield"); + static_assert(OPT_FLAGS_MAX <= 64, "dwOptions is a unsigned int bitfield"); const SValue g_pOptions[] = { @@ -210,20 +212,11 @@ namespace { L"hflip", OPT_HFLIP }, { L"vflip", OPT_VFLIP }, { L"dword", OPT_DDS_DWORD_ALIGN }, - { L"badtails", OPT_DDS_BAD_DXTN_TAILS }, - { L"permissive", OPT_DDS_PERMISSIVE }, - { L"ignoremips", OPT_DDS_IGNORE_MIPS }, { L"dx10", OPT_USE_DX10 }, { L"dx9", OPT_USE_DX9 }, - { L"tga20", OPT_TGA20 }, - { L"tgazeroalpha", OPT_TGAZEROALPHA }, { L"wicq", OPT_WIC_QUALITY }, - { L"wiclossless", OPT_WIC_LOSSLESS }, - { L"wicmulti", OPT_WIC_MULTIFRAME }, { L"nologo", OPT_NOLOGO }, - { L"timing", OPT_TIMING }, { L"sepalpha", OPT_SEPALPHA }, - { L"keepcoverage", OPT_PRESERVE_ALPHA_COVERAGE }, { L"nowic", OPT_NO_WIC }, { L"tu", OPT_TYPELESS_UNORM }, { L"tf", OPT_TYPELESS_FLOAT }, @@ -232,7 +225,6 @@ namespace { L"xlum", OPT_EXPAND_LUMINANCE }, { L"wrap", OPT_TA_WRAP }, { L"mirror", OPT_TA_MIRROR }, - { L"singleproc", OPT_FORCE_SINGLEPROC }, { L"gpu", OPT_GPU }, { L"nogpu", OPT_NOGPU }, { L"fl", OPT_FEATURE_LEVEL }, @@ -243,14 +235,8 @@ namespace { L"nmapamp", OPT_NORMAL_MAP_AMPLITUDE }, { L"bc", OPT_BC_COMPRESS }, { L"c", OPT_COLORKEY }, - { L"tonemap", OPT_TONEMAP }, { L"x2bias", OPT_X2_BIAS }, - { L"inverty", OPT_INVERT_Y }, - { L"reconstructz", OPT_RECONSTRUCT_Z }, - { L"rotatecolor", OPT_ROTATE_COLOR }, { L"nits", OPT_PAPER_WHITE_NITS }, - { L"fixbc4x4", OPT_BCNONMULT4FIX }, - { L"swizzle", OPT_SWIZZLE }, #ifdef USE_XBOX_EXTS { L"xbox", OPT_USE_XBOX }, { L"xgmode", OPT_XGMODE }, @@ -258,6 +244,57 @@ namespace { nullptr, 0 } }; + const SValue g_pOptionsLong[] = + { + { L"alpha-threshold", OPT_ALPHA_THRESHOLD }, + { L"alpha-weight", OPT_ALPHA_WEIGHT }, + { L"bad-tails", OPT_DDS_BAD_DXTN_TAILS }, + { L"block-compress", OPT_BC_COMPRESS }, + { L"color-key", OPT_COLORKEY }, + { L"expand-luminance", OPT_EXPAND_LUMINANCE }, + { L"feature-level", OPT_FEATURE_LEVEL }, + { L"file-list", OPT_FILELIST }, + { L"file-type", OPT_FILETYPE }, + { L"fit-power-of-2", OPT_FIT_POWEROF2 }, + { L"fix-bc-4x4", OPT_BCNONMULT4FIX }, + { L"format", OPT_FORMAT }, + { L"height", OPT_HEIGHT }, + { L"help", OPT_HELP }, + { L"horizontal-flip", OPT_HFLIP }, + { L"ignore-mips", OPT_DDS_IGNORE_MIPS }, + { L"image-filter", OPT_FILTER }, + { L"invert-y", OPT_INVERT_Y }, + { L"keep-coverage", OPT_PRESERVE_ALPHA_COVERAGE }, + { L"mip-levels", OPT_MIPLEVELS }, + { L"normalmap-amplitude", OPT_NORMAL_MAP_AMPLITUDE }, + { L"normalmap", OPT_NORMAL_MAP }, + { L"overwrite", OPT_OVERWRITE }, + { L"paper-white-nits", OPT_PAPER_WHITE_NITS }, + { L"permissive", OPT_DDS_PERMISSIVE }, + { L"prefix", OPT_PREFIX }, + { L"premultiplied-alpha", OPT_PREMUL_ALPHA }, + { L"reconstruct-z", OPT_RECONSTRUCT_Z }, + { L"rotate-color", OPT_ROTATE_COLOR }, + { L"separate-alpha", OPT_SEPALPHA }, + { L"single-proc", OPT_FORCE_SINGLEPROC }, + { L"srgb-in", OPT_SRGBI }, + { L"srgb-out", OPT_SRGBO }, + { L"suffix", OPT_SUFFIX }, + { L"swizzle", OPT_SWIZZLE }, + { L"tga-zero-alpha", OPT_TGAZEROALPHA }, + { L"tga20", OPT_TGA20 }, + { L"timing", OPT_TIMING }, + { L"to-lowercase", OPT_TOLOWER }, + { L"tonemap", OPT_TONEMAP }, + { L"version", OPT_VERSION }, + { L"vertical-flip", OPT_VFLIP }, + { L"wic-lossless", OPT_WIC_LOSSLESS }, + { L"wic-multiframe", OPT_WIC_MULTIFRAME }, + { L"wic-quality", OPT_WIC_QUALITY }, + { L"width", OPT_WIDTH }, + { nullptr, 0 } + }; + #define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } const SValue g_pFormats[] = @@ -693,53 +730,58 @@ namespace L" -r wildcard filename search is recursive\n" L" -r:flatten flatten the directory structure (default)\n" L" -r:keep keep the directory structure\n" - L" -flist use text file with a list of input files (one per line)\n" + L" -flist , --file-list \n" + L" use text file with a list of input files (one per line)\n" L"\n" - L" -w width\n" - L" -h height\n" - L" -m miplevels\n" - L" -f format\n" + L" -w , --width width for output\n" + L" -h , --height height for output\n" + L" -m , --mip-levels miplevels for output\n" + L" -f , --format pixel format for output\n" L"\n" - L" -if image filtering\n" - L" -srgb{i|o} sRGB {input, output}\n" + L" -if , --image-filter image filtering\n" + L" -srgb{i|o}, --srgb-in, --srgb-out sRGB {input, output}\n" L"\n" - L" -px name prefix\n" - L" -sx name suffix\n" - L" -o output directory\n" - L" -l force output filename to lower case\n" - L" -y overwrite existing output file (if any)\n" - L" -ft output file type\n" + L" -px , --prefix name prefix\n" + L" -sx , --suffix name suffix\n" + L" -o output directory\n" + L" -l, --to-lowercase force output filename to lower case\n" + L" -y, --overwrite overwrite existing output file (if any)\n" + L" -ft , --file-type output file type\n" L"\n" - L" -hflip horizonal flip of source image\n" - L" -vflip vertical flip of source image\n" + L" -hflip, --horizontal-flip horizonal flip of source image\n" + L" -vflip, --vertical-flip vertical flip of source image\n" L"\n" - L" -sepalpha resize/generate mips alpha channel separately\n" - L" from color channels\n" - L" -keepcoverage Preserve alpha coverage in mips for alpha test ref\n" + L" -sepalpha, --separate-alpha resize/generate mips alpha channel separately from color channels\n" + L" --keep-coverage Preserve alpha coverage in mips for alpha test ref\n" L"\n" - L" -nowic Force non-WIC filtering\n" - L" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n" - L" -pmalpha convert final texture to use premultiplied alpha\n" - L" -alpha convert premultiplied alpha to straight alpha\n" - L" -at Alpha threshold used for BC1, RGBA5551, and WIC\n" - L" (defaults to 0.5)\n" + L" -nowic Force non-WIC filtering\n" + L" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n" + L" -pmalpha, --premultiplied-alpha convert final texture to use premultiplied alpha\n" + L" -alpha convert premultiplied alpha to straight alpha\n" + L" -at , --alpha-threshold \n" + L" Alpha threshold used for BC1, RGBA5551, and WIC\n" + L" (defaults to 0.5)\n" L"\n" - L" -fl Set maximum feature level target (defaults to 11.0)\n" - L" -pow2 resize to fit a power-of-2, respecting aspect ratio\n" + L" -fl , --feature-level \n" + L" Set maximum feature level target (defaults to 11.0)\n" + L" -pow2, --fit-power-of-2\n" + L" resize to fit a power-of-2, respecting aspect ratio\n" L"\n" - L" -nmap converts height-map to normal-map\n" + L" -nmap , --normal-map \n" + L" converts height-map to normal-map\n" L" options must be one or more of\n" L" r, g, b, a, l, m, u, v, i, o\n" - L" -nmapamp normal map amplitude (defaults to 1.0)\n" + L" -nmapamp , --normalmap-amplitude \n" + L" normal map amplitude (defaults to 1.0)\n" L"\n" - L" (DDS input only)\n" - L" -t{u|f} TYPELESS format is treated as UNORM or FLOAT\n" - L" -dword Use DWORD instead of BYTE alignment\n" - L" -badtails Fix for older DXTn with bad mipchain tails\n" - L" -permissive Allow some DX9 variants with unusual header values\n" - L" -ignoremips Reads just the top-level mip which reads some invalid files\n" - L" -fixbc4x4 Fix for odd-sized BC files that Direct3D can't load\n" - L" -xlum expand legacy L8, L16, and A8P8 formats\n" + L" (DDS input only)\n" + L" -t{u|f} TYPELESS format is treated as UNORM or FLOAT\n" + L" -dword Use DWORD instead of BYTE alignment\n" + L" --bad-tails Fix for older DXTn with bad mipchain tails\n" + L" --permissive Allow some DX9 variants with unusual header values\n" + L" --ignore-mips Reads just the top-level mip which reads some invalid files\n" + L" --fix-bc-4x4 Fix for odd-sized BC files that Direct3D can't load\n" + L" -xlum, --expand-luminance Expand legacy L8, L16, and A8P8 formats\n" L"\n" L" (DDS output only)\n" L" -dx10 Force use of 'DX10' extended header\n" @@ -750,39 +792,44 @@ namespace #endif L"\n" L" (TGA input only)\n" - L" -tgazeroalpha Allow all zero alpha channel files to be loaded 'as is'\n" + L" --tga-zero-alpha Allow all zero alpha channel files to be loaded 'as is'\n" L"\n" L" (TGA output only)\n" - L" -tga20 Write file including TGA 2.0 extension area\n" + L" --tga20 Write file including TGA 2.0 extension area\n" L"\n" L" (BMP, PNG, JPG, TIF, WDP output only)\n" - L" -wicq When writing images with WIC use quality (0.0 to 1.0)\n" - L" -wiclossless When writing images with WIC use lossless mode\n" - L" -wicmulti When writing images with WIC encode multiframe images\n" + L" -wicq , --wic-quality \n" + L" When writing images with WIC use quality (0.0 to 1.0)\n" + L" --wic-lossless When writing images with WIC use lossless mode\n" + L" --wic-multiframe When writing images with WIC encode multiframe images\n" L"\n" L" -nologo suppress copyright message\n" - L" -timing Display elapsed processing time\n" + L" --timing display elapsed processing time\n" L"\n" #ifdef _OPENMP - L" -singleproc Do not use multi-threaded compression\n" + L" --single-proc Do not use multi-threaded compression\n" #endif L" -gpu Select GPU for DirectCompute-based codecs (0 is default)\n" L" -nogpu Do not use DirectCompute-based codecs\n" L"\n" - L" -bc Sets options for BC compression\n" + L" -bc , --block-compress \n" + L" Sets options for BC compression\n" L" options must be one or more of\n" L" d, u, q, x\n" - L" -aw BC7 GPU compressor weighting for alpha error metric\n" + L" -aw , --alpha-weight \n" + L" BC7 GPU compressor weighting for alpha error metric\n" L" (defaults to 1.0)\n" L"\n" - L" -c colorkey (a.k.a. chromakey) transparency\n" - L" -rotatecolor rotates color primaries and/or applies a curve\n" - L" -nits paper-white value in nits to use for HDR10 (def: 200.0)\n" - L" -tonemap Apply a tonemap operator based on maximum luminance\n" + L" -c , --color-key colorkey (a.k.a. chromakey) transparency\n" + L" --rotate-color rotates color primaries and/or applies a curve\n" + L"\n" + L" -nits , --paper-white-nits \n" + L" paper-white value in nits to use for HDR10 (def: 200.0)\n" + L" --tonemap Apply a tonemap operator based on maximum luminance\n" L" -x2bias Enable *2 - 1 conversion cases for unorm/pos-only-float\n" - L" -inverty Invert Y (i.e. green) channel values\n" - L" -reconstructz Rebuild Z (blue) channel assuming X/Y are normals\n" - L" -swizzle Swizzle image channels using HLSL-style mask\n" + L" --invert-y Invert Y (i.e. green) channel values\n" + L" --reconstruct-z Rebuild Z (blue) channel assuming X/Y are normals\n" + L" --swizzle Swizzle image channels using HLSL-style mask\n" L"\n" L" '-- ' is needed if any input filepath starts with the '-' or '/' character\n"; @@ -1218,34 +1265,55 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { PWSTR pArg = argv[iArg]; - if (allowOpts - && ('-' == pArg[0]) && ('-' == pArg[1])) + if (allowOpts && (('-' == pArg[0]) || ('/' == pArg[0]))) { - if (pArg[2] == 0) - { - // "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths. - allowOpts = false; - } - else if (!_wcsicmp(pArg,L"--version")) + uint64_t dwOption = 0; + + if (('-' == pArg[0]) && ('-' == pArg[1])) { - PrintLogo(true, g_ToolName, g_Description); - return 0; + if (pArg[2] == 0) + { + // "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths. + allowOpts = false; + } + else + { + pArg += 2; + dwOption = LookupByName(pArg, g_pOptionsLong); + + if (dwOption == OPT_VERSION) + { + PrintLogo(true, g_ToolName, g_Description); + return 0; + } + else if (dwOption == OPT_HELP) + { + PrintUsage(); + return 0; + } + } } - else if (!_wcsicmp(pArg, L"--help")) + else if (('-' == pArg[0]) || ('/' == pArg[0])) { - PrintUsage(); - return 0; + pArg++; + 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; + } + } } - else + + if (!dwOption) { - wprintf(L"Unknown option: %ls\n", pArg); + wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName); return 1; } - } - else if (allowOpts - && (('-' == pArg[0]) || ('/' == pArg[0]))) - { - pArg++; + PWSTR pValue; for (pValue = pArg; *pValue && (':' != *pValue); pValue++); @@ -1253,11 +1321,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) if (*pValue) *pValue++ = 0; - const uint64_t dwOption = LookupByName(pArg, g_pOptions); - - if (!dwOption || (dwOptions & (uint64_t(1) << dwOption))) + if (dwOptions & (uint64_t(1) << dwOption)) { - PrintUsage(); + wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); return 1; } From 4e1b1a32d34f814038e815dedc19783904b5088e Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Wed, 23 Oct 2024 22:20:53 -0700 Subject: [PATCH 02/18] Fix -- usage --- Texconv/texconv.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 2a004299..0e6de3a8 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -1275,6 +1275,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { // "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths. allowOpts = false; + continue; } else { From 26b96aedd60922a46835c99fe414635bb5174591 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Thu, 24 Oct 2024 10:56:24 -0700 Subject: [PATCH 03/18] Keep -tga20 --- Texconv/texconv.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 0e6de3a8..0aaad106 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -214,6 +214,7 @@ namespace { L"dword", OPT_DDS_DWORD_ALIGN }, { L"dx10", OPT_USE_DX10 }, { L"dx9", OPT_USE_DX9 }, + { L"tga20", OPT_TGA20 }, { L"wicq", OPT_WIC_QUALITY }, { L"nologo", OPT_NOLOGO }, { L"sepalpha", OPT_SEPALPHA }, @@ -235,7 +236,6 @@ namespace { L"nmapamp", OPT_NORMAL_MAP_AMPLITUDE }, { L"bc", OPT_BC_COMPRESS }, { L"c", OPT_COLORKEY }, - { L"x2bias", OPT_X2_BIAS }, { L"nits", OPT_PAPER_WHITE_NITS }, #ifdef USE_XBOX_EXTS { L"xbox", OPT_USE_XBOX }, @@ -251,6 +251,7 @@ namespace { L"bad-tails", OPT_DDS_BAD_DXTN_TAILS }, { L"block-compress", OPT_BC_COMPRESS }, { L"color-key", OPT_COLORKEY }, + { L"dword-alignment", OPT_DDS_DWORD_ALIGN }, { L"expand-luminance", OPT_EXPAND_LUMINANCE }, { L"feature-level", OPT_FEATURE_LEVEL }, { L"file-list", OPT_FILELIST }, @@ -266,8 +267,8 @@ namespace { L"invert-y", OPT_INVERT_Y }, { L"keep-coverage", OPT_PRESERVE_ALPHA_COVERAGE }, { L"mip-levels", OPT_MIPLEVELS }, - { L"normalmap-amplitude", OPT_NORMAL_MAP_AMPLITUDE }, - { L"normalmap", OPT_NORMAL_MAP }, + { L"normal-map-amplitude", OPT_NORMAL_MAP_AMPLITUDE }, + { L"normal-map", OPT_NORMAL_MAP }, { L"overwrite", OPT_OVERWRITE }, { L"paper-white-nits", OPT_PAPER_WHITE_NITS }, { L"permissive", OPT_DDS_PERMISSIVE }, @@ -282,16 +283,21 @@ namespace { L"suffix", OPT_SUFFIX }, { L"swizzle", OPT_SWIZZLE }, { L"tga-zero-alpha", OPT_TGAZEROALPHA }, - { L"tga20", OPT_TGA20 }, { L"timing", OPT_TIMING }, { L"to-lowercase", OPT_TOLOWER }, { L"tonemap", OPT_TONEMAP }, + { L"typeless-unorm", OPT_TYPELESS_UNORM }, + { L"typeless-float", OPT_TYPELESS_FLOAT }, { L"version", OPT_VERSION }, { L"vertical-flip", OPT_VFLIP }, { L"wic-lossless", OPT_WIC_LOSSLESS }, { L"wic-multiframe", OPT_WIC_MULTIFRAME }, { L"wic-quality", OPT_WIC_QUALITY }, { L"width", OPT_WIDTH }, + { L"x2-bias", OPT_X2_BIAS }, + #ifdef USE_XBOX_EXTS + { L"xbox-mode", OPT_XGMODE }, + #endif { nullptr, 0 } }; @@ -771,12 +777,13 @@ namespace L" converts height-map to normal-map\n" L" options must be one or more of\n" L" r, g, b, a, l, m, u, v, i, o\n" - L" -nmapamp , --normalmap-amplitude \n" + L" -nmapamp , --normal-map-amplitude \n" L" normal map amplitude (defaults to 1.0)\n" L"\n" L" (DDS input only)\n" - L" -t{u|f} TYPELESS format is treated as UNORM or FLOAT\n" - L" -dword Use DWORD instead of BYTE alignment\n" + L" -tu, --typeless-unorm TYPELESS format is treated as UNORM\n" + L" -tf, --typeless-float TYPELESS format is treated as FLOAT\n" + L" -dword, --dword-alignment Use DWORD instead of BYTE alignment\n" L" --bad-tails Fix for older DXTn with bad mipchain tails\n" L" --permissive Allow some DX9 variants with unusual header values\n" L" --ignore-mips Reads just the top-level mip which reads some invalid files\n" @@ -788,14 +795,15 @@ namespace L" -dx9 Force use of legacy DX9 header\n" #ifdef USE_XBOX_EXTS L" -xbox Tile/swizzle and use 'XBOX' variant of DDS\n" - L" -xgmode Tile/swizzle using provided memory layout mode\n" + L" -xgmode , --xbox-mode \n"\ + L" Tile/swizzle using provided memory layout mode\n" #endif L"\n" L" (TGA input only)\n" L" --tga-zero-alpha Allow all zero alpha channel files to be loaded 'as is'\n" L"\n" L" (TGA output only)\n" - L" --tga20 Write file including TGA 2.0 extension area\n" + L" -tga20 Write file including TGA 2.0 extension area\n" L"\n" L" (BMP, PNG, JPG, TIF, WDP output only)\n" L" -wicq , --wic-quality \n" @@ -826,7 +834,7 @@ namespace L" -nits , --paper-white-nits \n" L" paper-white value in nits to use for HDR10 (def: 200.0)\n" L" --tonemap Apply a tonemap operator based on maximum luminance\n" - L" -x2bias Enable *2 - 1 conversion cases for unorm/pos-only-float\n" + L" --x2-bias Enable *2 - 1 conversion cases for unorm/pos-only-float\n" L" --invert-y Invert Y (i.e. green) channel values\n" L" --reconstruct-z Rebuild Z (blue) channel assuming X/Y are normals\n" L" --swizzle Swizzle image channels using HLSL-style mask\n" @@ -1261,7 +1269,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) std::list conversion; bool allowOpts = true; - for (int iArg = 1; iArg < argc; iArg++) + for (int iArg = 1; iArg < argc; ++iArg) { PWSTR pArg = argv[iArg]; @@ -1294,7 +1302,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } } } - else if (('-' == pArg[0]) || ('/' == pArg[0])) + else { pArg++; dwOption = LookupByName(pArg, g_pOptions); @@ -1315,9 +1323,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } - PWSTR pValue; + PWSTR pValue = pArg; - for (pValue = pArg; *pValue && (':' != *pValue); pValue++); + for (; *pValue && (':' != *pValue); ++pValue); if (*pValue) *pValue++ = 0; From 1b0a82bdd47da06b7b5db34956bef9e55e47f3ed Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Thu, 24 Oct 2024 11:09:04 -0700 Subject: [PATCH 04/18] Add hints for changes to GNU-style --- Texconv/texconv.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 0aaad106..df863af7 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -301,6 +301,26 @@ namespace { nullptr, 0 } }; + const SValue g_pOptionsOld[] = + { + { L"badtails", L"bad-tails" }, + { L"fixbc4x4", L"fix-bc-4x4" }, + { L"ignoremips", L"ignore-mips" }, + { L"inverty", L"invert-y" }, + { L"keepcoverage", L"keep-coverage" }, + { L"permissive", L"permissive" }, + { L"reconstructz", L"reconstruct-z" }, + { L"rotatecolor", L"rotate-color" }, + { L"singleproc", L"single-proc" }, + { L"swizzle", L"swizzle" }, + { L"tgazeroalpha", L"tga-zero-alpha" }, + { L"timing", L"timing" }, + { L"tonemap", L"tonemap" }, + { L"wiclossless", L"wic-lossless" }, + { L"wicmulti", L"wic-multiframe" }, + { L"x2bias", L"x2-bias" }, + }; + #define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } const SValue g_pFormats[] = @@ -1314,6 +1334,15 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"ERROR: did you mean `--%ls` (with two dashes)?\n", pArg); return 1; } + else + { + auto hint = LookupByName(pArg, g_pOptionsOld); + if (hint) + { + wprintf(L"ERROR: use `--%ls` (with two dashes) instead\n", hint); + return 1; + } + } } } From be46790d3c284f4ebda7ce9cb1b2e7da2192c2b2 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Thu, 24 Oct 2024 11:09:59 -0700 Subject: [PATCH 05/18] Remove redundant hints --- Texconv/texconv.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index df863af7..768b1abb 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -308,14 +308,10 @@ namespace { L"ignoremips", L"ignore-mips" }, { L"inverty", L"invert-y" }, { L"keepcoverage", L"keep-coverage" }, - { L"permissive", L"permissive" }, { L"reconstructz", L"reconstruct-z" }, { L"rotatecolor", L"rotate-color" }, { L"singleproc", L"single-proc" }, - { L"swizzle", L"swizzle" }, { L"tgazeroalpha", L"tga-zero-alpha" }, - { L"timing", L"timing" }, - { L"tonemap", L"tonemap" }, { L"wiclossless", L"wic-lossless" }, { L"wicmulti", L"wic-multiframe" }, { L"x2bias", L"x2-bias" }, From 0047cf1e3c46db490a049441f82b590c4808c90d Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Thu, 24 Oct 2024 12:38:18 -0700 Subject: [PATCH 06/18] Code review --- Texconv/texconv.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 768b1abb..49db1b38 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -315,6 +315,7 @@ namespace { L"wiclossless", L"wic-lossless" }, { L"wicmulti", L"wic-multiframe" }, { L"x2bias", L"x2-bias" }, + { nullptr, nullptr } }; #define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } @@ -1292,6 +1293,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) if (allowOpts && (('-' == pArg[0]) || ('/' == pArg[0]))) { uint64_t dwOption = 0; + PWSTR pValue = nullptr; if (('-' == pArg[0]) && ('-' == pArg[1])) { @@ -1304,6 +1306,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) else { pArg += 2; + + for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue); + + if (*pValue) + *pValue++ = 0; + dwOption = LookupByName(pArg, g_pOptionsLong); if (dwOption == OPT_VERSION) @@ -1321,6 +1329,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) else { pArg++; + + for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue); + + if (*pValue) + *pValue++ = 0; + dwOption = LookupByName(pArg, g_pOptions); if (!dwOption) @@ -1348,13 +1362,6 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } - PWSTR pValue = pArg; - - for (; *pValue && (':' != *pValue); ++pValue); - - if (*pValue) - *pValue++ = 0; - if (dwOptions & (uint64_t(1) << dwOption)) { wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); From 3f2d7fd645d89c73d02db91e9caa4d2800773c54 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 25 Oct 2024 17:06:04 -0700 Subject: [PATCH 07/18] keep all existing switches to avoid breaking changes --- Texconv/texconv.cpp | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 49db1b38..6a961873 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -241,6 +241,25 @@ namespace { L"xbox", OPT_USE_XBOX }, { L"xgmode", OPT_XGMODE }, #endif + + // Deprecated options (recommend using new -- alternatives) + { L"badtails", OPT_DDS_BAD_DXTN_TAILS }, + { L"permissive", OPT_DDS_PERMISSIVE }, + { L"ignoremips", OPT_DDS_IGNORE_MIPS }, + { L"tgazeroalpha", OPT_TGAZEROALPHA }, + { L"wiclossless", OPT_WIC_LOSSLESS }, + { L"wicmulti", OPT_WIC_MULTIFRAME }, + { L"timing", OPT_TIMING }, + { L"keepcoverage", OPT_PRESERVE_ALPHA_COVERAGE }, + { L"singleproc", OPT_FORCE_SINGLEPROC }, + { L"tonemap", OPT_TONEMAP }, + { L"x2bias", OPT_X2_BIAS }, + { L"inverty", OPT_INVERT_Y }, + { L"reconstructz", OPT_RECONSTRUCT_Z }, + { L"rotatecolor", OPT_ROTATE_COLOR }, + { L"fixbc4x4", OPT_BCNONMULT4FIX }, + { L"swizzle", OPT_SWIZZLE }, + { nullptr, 0 } }; @@ -301,23 +320,6 @@ namespace { nullptr, 0 } }; - const SValue g_pOptionsOld[] = - { - { L"badtails", L"bad-tails" }, - { L"fixbc4x4", L"fix-bc-4x4" }, - { L"ignoremips", L"ignore-mips" }, - { L"inverty", L"invert-y" }, - { L"keepcoverage", L"keep-coverage" }, - { L"reconstructz", L"reconstruct-z" }, - { L"rotatecolor", L"rotate-color" }, - { L"singleproc", L"single-proc" }, - { L"tgazeroalpha", L"tga-zero-alpha" }, - { L"wiclossless", L"wic-lossless" }, - { L"wicmulti", L"wic-multiframe" }, - { L"x2bias", L"x2-bias" }, - { nullptr, nullptr } - }; - #define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } const SValue g_pFormats[] = @@ -1344,15 +1346,6 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"ERROR: did you mean `--%ls` (with two dashes)?\n", pArg); return 1; } - else - { - auto hint = LookupByName(pArg, g_pOptionsOld); - if (hint) - { - wprintf(L"ERROR: use `--%ls` (with two dashes) instead\n", hint); - return 1; - } - } } } From 45cf94a59fb99e5b8979da036e36b182a7bd0076 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 25 Oct 2024 17:46:03 -0700 Subject: [PATCH 08/18] Convert texassemble to use GNU-style long options --- Texassemble/texassemble.cpp | 161 +++++++++++++++++++++++++----------- 1 file changed, 112 insertions(+), 49 deletions(-) diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index 91a9f543..f773e604 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -138,10 +138,12 @@ namespace OPT_GIF_BGCOLOR, OPT_SWIZZLE, OPT_STRIP_MIPS, - OPT_MAX + OPT_FLAGS_MAX, + 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"); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// @@ -194,13 +196,38 @@ namespace { L"wrap", OPT_TA_WRAP }, { L"mirror", OPT_TA_MIRROR }, { L"fl", OPT_FEATURE_LEVEL }, + + // Deprecated options (recommend using new -- alternatives) { L"tonemap", OPT_TONEMAP }, { L"bgcolor", OPT_GIF_BGCOLOR }, { L"swizzle", OPT_SWIZZLE }, { L"stripmips", OPT_STRIP_MIPS }, + { nullptr, 0 } }; + const SValue g_pOptionsLong[] = + { + { L"feature-level", OPT_FEATURE_LEVEL }, + { L"file-list", OPT_FILELIST }, + { L"format", OPT_FORMAT }, + { L"gif-bg-color", OPT_GIF_BGCOLOR }, + { 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"strip-mips", OPT_STRIP_MIPS }, + { L"swizzle", OPT_SWIZZLE }, + { L"to-lowercase", OPT_TOLOWER }, + { L"tonemap", OPT_TONEMAP }, + { L"version", OPT_VERSION }, + { L"width", OPT_WIDTH }, + { nullptr, 0 } + }; + #define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } const SValue g_pFormats[] = @@ -500,7 +527,7 @@ namespace static const wchar_t* const s_usage = L"Usage: texassemble [--] \n" - L"\n" + L"\nCOMMANDS\n" L" cube create cubemap\n" L" volume create volume map\n" L" array create texture array\n" @@ -518,34 +545,43 @@ namespace L" cube-from-ht create cubemap from a h-tee image\n" L" cube-from-hs create cubemap from a h-strip image\n" L" cube-from-vs create cubemap from a v-strip image\n" - L"\n" + L"\nOPTIONS\n" L" -r wildcard filename search is recursive\n" - L" -flist use text file with a list of input files (one per line)\n" - L" -w width\n" - L" -h height\n" - L" -f format\n" - L" -if image filtering\n" - L" -srgb{i|o} sRGB {input, output}\n" - L" -o output filename\n" - L" -l force output filename to lower case\n" - L" -y overwrite existing output file (if any)\n" - L" -sepalpha resize alpha channel separately from color channels\n" + L" -flist , --file-list \n" + L" use text file with a list of input files (one per line)\n" + L"\n" + L" -w , --width width for output\n" + L" -h , --height height for output\n" + L" -f , --format pixel format for output\n" + L"\n" + L" -if , --image-filter image filtering\n" + L" -srgb{i|o}, --srgb-in, --srgb-out sRGB {input, output}\n" + L"\n" + L" -o output filename\n" + L" -l, --to-lowercase force output filename to lower case\n" + L" -y, --overwrite overwrite existing output file (if any)\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" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n" L" -alpha convert premultiplied alpha to straight alpha\n" L" -dx10 Force use of 'DX10' extended header\n" L" -nologo suppress copyright message\n" - L" -fl Set maximum feature level target (defaults to 11.0)\n" + L"\n" + L" -fl , --feature-level \n" + L" Set maximum feature level target (defaults to 11.0)\n" + L"\n" L" -tonemap Apply a tonemap operator based on maximum luminance\n" L"\n" L" (gif only)\n" - L" -bgcolor Use background color instead of transparency\n" + L" --gif-bg-color Use background color instead of transparency\n" L"\n" L" (merge only)\n" - L" -swizzle Select channels for merge (defaults to rgbB)\n" + L" --swizzle Select channels for merge (defaults to rgbB)\n" L"\n" L" (cube, volume, array, cubearray, merge only)\n" - L" -stripmips Use only base image from input dds files\n" + L" --strip-mips Use only base image from input dds files\n" L"\n" L" '-- ' is needed if any input filepath starts with the '-' or '/' character\n"; @@ -775,6 +811,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; } + // check for these before the command if (('-' == argv[1][0]) && ('-' == argv[1][1])) { if (!_wcsicmp(argv[1], L"--version")) @@ -824,50 +861,76 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) std::list conversion; bool allowOpts = true; - for (int iArg = 2; iArg < argc; iArg++) + for (int iArg = 2; iArg < argc; ++iArg) { PWSTR pArg = argv[iArg]; - if (allowOpts - && ('-' == pArg[0]) && ('-' == pArg[1])) + if (allowOpts && (('-' == pArg[0]) || ('/' == pArg[0]))) { - if (pArg[2] == 0) - { - // "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths. - allowOpts = false; - } - else if (!_wcsicmp(pArg, L"--version")) - { - PrintLogo(true, g_ToolName, g_Description); - return 0; - } - else if (!_wcsicmp(pArg, L"--help")) + uint64_t dwOption = 0; + PWSTR pValue = nullptr; + + if (('-' == pArg[0]) && ('-' == pArg[1])) { - PrintUsage(); - return 0; + if (pArg[2] == 0) + { + // "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths. + allowOpts = false; + continue; + } + else + { + pArg += 2; + + for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue); + + if (*pValue) + *pValue++ = 0; + + dwOption = LookupByName(pArg, g_pOptionsLong); + + if (dwOption == OPT_VERSION) + { + PrintLogo(true, g_ToolName, g_Description); + return 0; + } + else if (dwOption == OPT_HELP) + { + PrintUsage(); + return 0; + } + } } else { - wprintf(L"Unknown option: %ls\n", pArg); - return 1; - } - } - else if (allowOpts - && (('-' == pArg[0]) || ('/' == pArg[0]))) - { - pArg++; - PWSTR pValue; + pArg++; + + for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue); + + if (*pValue) + *pValue++ = 0; - for (pValue = pArg; *pValue && (':' != *pValue); pValue++); + dwOption = LookupByName(pArg, g_pOptions); - if (*pValue) - *pValue++ = 0; + if (!dwOption) + { + if (LookupByName(pArg, g_pOptionsLong)) + { + wprintf(L"ERROR: did you mean `--%ls` (with two dashes)?\n", pArg); + return 1; + } + } + } - const uint32_t dwOption = LookupByName(pArg, g_pOptions); + if (!dwOption) + { + wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName); + return 1; + } - if (!dwOption || (dwOptions & (1 << dwOption))) + if (dwOptions & (1 << dwOption)) { - PrintUsage(); + wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); return 1; } From 98c9b73275526b2347885eb9f14af4062b685a03 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 25 Oct 2024 18:24:48 -0700 Subject: [PATCH 09/18] texdiag fixes for dumpdds --- Texdiag/texdiag.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index c8a8e214..c9371bb9 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -423,7 +423,7 @@ namespace { PrintLogo(false, g_ToolName, g_Description); - static const wchar_t* const s_usage = + static const wchar_t *const s_usage = L"Usage: texdiag [--] \n" L"\n" L" info Output image metadata\n" @@ -446,7 +446,7 @@ namespace L"\n" L" (diff only)\n" L" -f format\n" - L" -o output filename\n" + L" -o output filename for diff; output path for dumpdds\n" L" -l force output filename to lower case\n" L" -y overwrite existing output file (if any)\n" L" -c highlight difference color (defaults to off)\n" @@ -3173,9 +3173,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_OUTPUTFILE: - if (dwCommand != CMD_DIFF) + if (dwCommand != CMD_DIFF && dwCommand != CMD_DUMPDDS) { - wprintf(L"-o only valid for use with diff command\n"); + wprintf(L"-o only valid for use with diff or dumpdds commands\n"); return 1; } else @@ -3183,7 +3183,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) std::filesystem::path path(pValue); outputFile = path.make_preferred().native(); - fileType = LookupByName(path.extension().c_str(), g_pExtFileTypes); + if (dwCommand == CMD_DIFF) + { + fileType = LookupByName(path.extension().c_str(), g_pExtFileTypes); + } } break; @@ -3656,6 +3659,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) auto const ext = LookupByValue(fileType, g_pDumpFileTypes); + std::filesystem::path basePath(outputFile); + if (info.depth > 1) { wprintf(L"Writing by mip (%3zu) and slice (%3zu)...", info.mipLevels, info.depth); @@ -3684,10 +3689,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) swprintf_s(subFname, L"%ls_slice%03zu", curpath.stem().c_str(), slice); } - outputFile.assign(subFname); - outputFile.append(ext); + std::filesystem::path output(basePath); + output.append(subFname); + output.replace_extension(ext); - hr = SaveImage(img, outputFile.c_str(), fileType); + hr = SaveImage(img, output.c_str(), fileType); if (FAILED(hr)) { wprintf(L" FAILED (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); @@ -3728,10 +3734,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) swprintf_s(subFname, L"%ls_item%03zu", curpath.stem().c_str(), item); } - outputFile.assign(subFname); - outputFile.append(ext); + std::filesystem::path output(basePath); + output.append(subFname); + output.replace_extension(ext); - hr = SaveImage(img, outputFile.c_str(), fileType); + hr = SaveImage(img, output.c_str(), fileType); if (FAILED(hr)) { wprintf(L" FAILED (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); From a050b63bc58ad0b1357753c0cfede9876a16250f Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 25 Oct 2024 18:44:59 -0700 Subject: [PATCH 10/18] Convert texdiag to use GNU-style long options --- Texdiag/texdiag.cpp | 182 +++++++++++++++++++++++++++++--------------- 1 file changed, 122 insertions(+), 60 deletions(-) diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index c9371bb9..672edd78 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -115,10 +115,12 @@ namespace OPT_DIFF_COLOR, OPT_THRESHOLD, OPT_FILELIST, - OPT_MAX + OPT_FLAGS_MAX, + 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"); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// @@ -141,9 +143,6 @@ namespace { L"f", OPT_FORMAT }, { L"if", OPT_FILTER }, { L"dword", OPT_DDS_DWORD_ALIGN }, - { L"badtails", OPT_DDS_BAD_DXTN_TAILS }, - { L"permissive", OPT_DDS_PERMISSIVE }, - { L"ignoremips", OPT_DDS_IGNORE_MIPS }, { L"nologo", OPT_NOLOGO }, { L"o", OPT_OUTPUTFILE }, { L"l", OPT_TOLOWER }, @@ -152,14 +151,44 @@ namespace { L"tu", OPT_TYPELESS_UNORM }, { L"tf", OPT_TYPELESS_FLOAT }, { L"xlum", OPT_EXPAND_LUMINANCE }, - { L"targetx", OPT_TARGET_PIXELX }, - { L"targety", OPT_TARGET_PIXELY }, { L"c", OPT_DIFF_COLOR }, { L"t", OPT_THRESHOLD }, { L"flist", OPT_FILELIST }, + + // Deprecated options (recommend using new -- alternatives) + { L"badtails", OPT_DDS_BAD_DXTN_TAILS }, + { L"permissive", OPT_DDS_PERMISSIVE }, + { L"ignoremips", OPT_DDS_IGNORE_MIPS }, + { L"targetx", OPT_TARGET_PIXELX }, + { L"targety", OPT_TARGET_PIXELY }, + { nullptr, 0 } }; + const SValue g_pOptionsLong[] = + { + { L"bad-tails", OPT_DDS_BAD_DXTN_TAILS }, + { L"dword-alignment", OPT_DDS_DWORD_ALIGN }, + { L"expand-luminance", OPT_EXPAND_LUMINANCE }, + { L"file-list", OPT_FILELIST }, + { L"file-type", OPT_FILETYPE }, + { L"format", OPT_FORMAT }, + { L"help", OPT_HELP }, + { L"ignore-mips", OPT_DDS_IGNORE_MIPS }, + { L"image-filter", OPT_FILTER }, + { L"overwrite", OPT_OVERWRITE }, + { L"permissive", OPT_DDS_PERMISSIVE }, + { L"target-x", OPT_TARGET_PIXELX }, + { L"target-y", OPT_TARGET_PIXELY }, + { L"to-lowercase", OPT_TOLOWER }, + { L"typeless-unorm", OPT_TYPELESS_UNORM }, + { L"typeless-float", OPT_TYPELESS_FLOAT }, + { L"version", OPT_VERSION }, + { L"diff-color", OPT_DIFF_COLOR }, + { L"threshold", OPT_THRESHOLD }, + { nullptr, 0 } + }; + #define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } const SValue g_pFormats[] = @@ -423,44 +452,51 @@ namespace { PrintLogo(false, g_ToolName, g_Description); - static const wchar_t *const s_usage = + static const wchar_t* const s_usage = L"Usage: texdiag [--] \n" - L"\n" + L"\nCOMMANDS\n" L" info Output image metadata\n" L" analyze Analyze and summarize image information\n" L" compare Compare two images with MSE error metric\n" L" diff Generate difference image from two images\n" L" dumpbc Dump out compressed blocks (DDS BC only)\n" L" dumpdds Dump out all the images in a complex DDS\n" - L"\n" + L"\nOPTIONS\n" L" -r wildcard filename search is recursive\n" - L" -if image filtering\n" + L" -flist , --file-list \n" + L" use text file with a list of input files (one per line)\n" + L"\n" + L" -if , --image-filter image filtering\n" L"\n" - L" (DDS input only)\n" - L" -t{u|f} TYPELESS format is treated as UNORM or FLOAT\n" - L" -dword Use DWORD instead of BYTE alignment\n" - L" -badtails Fix for older DXTn with bad mipchain tails\n" - L" -permissive Allow some DX9 variants with unusual header values\n" - L" -ignoremips Reads just the top-level mip which reads some invalid files\n" - L" -xlum expand legacy L8, L16, and A8P8 formats\n" + L" (DDS input only)\n" + L" -tu, --typeless-unorm TYPELESS format is treated as UNORM\n" + L" -tf, --typeless-float TYPELESS format is treated as FLOAT\n" + L" -dword, --dword-alignment Use DWORD instead of BYTE alignment\n" + L" --bad-tails Fix for older DXTn with bad mipchain tails\n" + L" --permissive Allow some DX9 variants with unusual header values\n" + L" --ignore-mips Reads just the top-level mip which reads some invalid files\n" + L" -xlum, --expand-luminance Expand legacy L8, L16, and A8P8 formats\n" L"\n" - L" (diff only)\n" - L" -f format\n" - L" -o output filename for diff; output path for dumpdds\n" - L" -l force output filename to lower case\n" - L" -y overwrite existing output file (if any)\n" - L" -c highlight difference color (defaults to off)\n" - L" -t highlight threshold (defaults to 0.25)\n" + L" (diff only)\n" + L" -f , --format pixel format for output\n" + L" -o output filename for diff\n" + L" -l, --to-lowercase force output filename to lower case\n" + L" -y, --overwrite overwrite existing output file (if any)\n" + L" -c , --diff-color \n" + L" highlight difference color (defaults to off)\n" + L" -t , --threshold \n" + L" highlight threshold (defaults to 0.25)\n" L"\n" L" (dumpbc only)\n" - L" -targetx dump pixels at location x (defaults to all)\n" - L" -targety dump pixels at location y (defaults to all)\n" + L" --target-x dump pixels at location x (defaults to all)\n" + L" --target-y dump pixels at location y (defaults to all)\n" L"\n" L" (dumpdds only)\n" - L" -ft output file type\n" + L" -o output path for dumpdds\n" + L" -ft , --file-type \n" + " output file type\n" L"\n" L" -nologo suppress copyright message\n" - L" -flist use text file with a list of input files (one per line)\n" L"\n" L" '-- ' is needed if any input filepath starts with the '-' or '/' character\n"; @@ -3062,50 +3098,76 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) std::list conversion; bool allowOpts = true; - for (int iArg = 2; iArg < argc; iArg++) + for (int iArg = 2; iArg < argc; ++iArg) { PWSTR pArg = argv[iArg]; - if (allowOpts - && ('-' == pArg[0]) && ('-' == pArg[1])) + if (allowOpts && (('-' == pArg[0]) || ('/' == pArg[0]))) { - if (pArg[2] == 0) - { - // "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths. - allowOpts = false; - } - else if (!_wcsicmp(pArg, L"--version")) - { - PrintLogo(true, g_ToolName, g_Description); - return 0; - } - else if (!_wcsicmp(pArg, L"--help")) + uint64_t dwOption = 0; + PWSTR pValue = nullptr; + + if (('-' == pArg[0]) && ('-' == pArg[1])) { - PrintUsage(); - return 0; + if (pArg[2] == 0) + { + // "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths. + allowOpts = false; + continue; + } + else + { + pArg += 2; + + for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue); + + if (*pValue) + *pValue++ = 0; + + dwOption = LookupByName(pArg, g_pOptionsLong); + + if (dwOption == OPT_VERSION) + { + PrintLogo(true, g_ToolName, g_Description); + return 0; + } + else if (dwOption == OPT_HELP) + { + PrintUsage(); + return 0; + } + } } else { - wprintf(L"Unknown option: %ls\n", pArg); - return 1; - } - } - else if (allowOpts - && (('-' == pArg[0]) || ('/' == pArg[0]))) - { - pArg++; - PWSTR pValue; + pArg++; - for (pValue = pArg; *pValue && (':' != *pValue); pValue++); + for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue); - if (*pValue) - *pValue++ = 0; + if (*pValue) + *pValue++ = 0; - const uint32_t dwOption = LookupByName(pArg, g_pOptions); + 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; + } + } + } + + if (!dwOption) + { + wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName); + return 1; + } - if (!dwOption || (dwOptions & (1 << dwOption))) + if (dwOptions & (1 << dwOption)) { - PrintUsage(); + wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); return 1; } From 28bfdbb8473c003bcf9d14417efe225034d9c1b3 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 26 Oct 2024 11:25:28 -0700 Subject: [PATCH 11/18] Change some use of #define to constexpr --- DirectXTex/DirectXTex.h | 8 ++++---- Texassemble/texassemble.cpp | 12 ++++++------ Texconv/texconv.cpp | 20 ++++++++++---------- Texdiag/texdiag.cpp | 14 +++++++------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index 61c7a017..7efb0538 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -74,7 +74,7 @@ namespace DirectX size_t __cdecl BytesPerBlock(_In_ DXGI_FORMAT fmt) noexcept; - enum FORMAT_TYPE + enum FORMAT_TYPE : uint32_t { FORMAT_TYPE_TYPELESS, FORMAT_TYPE_FLOAT, @@ -136,7 +136,7 @@ namespace DirectX //--------------------------------------------------------------------------------- // Texture metadata - enum TEX_DIMENSION + enum TEX_DIMENSION : uint32_t // Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION { TEX_DIMENSION_TEXTURE1D = 2, @@ -155,7 +155,7 @@ namespace DirectX TEX_MISC2_ALPHA_MODE_MASK = 0x7L, }; - enum TEX_ALPHA_MODE + enum TEX_ALPHA_MODE : uint32_t // Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2 { TEX_ALPHA_MODE_UNKNOWN = 0, @@ -934,7 +934,7 @@ namespace DirectX //--------------------------------------------------------------------------------- // WIC utility code #ifdef _WIN32 - enum WICCodecs + enum WICCodecs : uint32_t { WIC_CODEC_BMP = 1, // Windows Bitmap (.bmp) WIC_CODEC_JPEG, // Joint Photographic Experts Group (.jpg, .jpeg) diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index f773e604..276ec0a4 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -344,18 +344,18 @@ namespace { nullptr, TEX_FILTER_DEFAULT } }; - #define CODEC_DDS 0xFFFF0001 - #define CODEC_TGA 0xFFFF0002 - #define CODEC_HDR 0xFFFF0005 + constexpr uint32_t CODEC_DDS = 0xFFFF0001; + constexpr uint32_t CODEC_TGA = 0xFFFF0002; + constexpr uint32_t CODEC_HDR = 0xFFFF0005; #ifdef USE_OPENEXR - #define CODEC_EXR 0xFFFF0006 + constexpr uint32_t CODEC_EXR = 0xFFFF0008; #endif #ifdef USE_LIBJPEG - #define CODEC_JPEG 0xFFFF0007 + constexpr uint32_t CODEC_JPEG = 0xFFFF0009; #endif #ifdef USE_LIBPNG - #define CODEC_PNG 0xFFFF0008 + constexpr uint32_t CODEC_PNG = 0xFFFF000A; #endif const SValue g_pExtFileTypes[] = diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 6a961873..47b43d77 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -544,22 +544,22 @@ namespace { nullptr, 0 }, }; - #define CODEC_DDS 0xFFFF0001 - #define CODEC_TGA 0xFFFF0002 - #define CODEC_HDP 0xFFFF0003 - #define CODEC_JXR 0xFFFF0004 - #define CODEC_HDR 0xFFFF0005 - #define CODEC_PPM 0xFFFF0006 - #define CODEC_PFM 0xFFFF0007 + constexpr uint32_t CODEC_DDS = 0xFFFF0001; + constexpr uint32_t CODEC_TGA = 0xFFFF0002; + constexpr uint32_t CODEC_HDP = 0xFFFF0003; + constexpr uint32_t CODEC_JXR = 0xFFFF0004; + constexpr uint32_t CODEC_HDR = 0xFFFF0005; + constexpr uint32_t CODEC_PPM = 0xFFFF0006; + constexpr uint32_t CODEC_PFM = 0xFFFF0007; #ifdef USE_OPENEXR - #define CODEC_EXR 0xFFFF0008 + constexpr uint32_t CODEC_EXR = 0xFFFF0008; #endif #ifdef USE_LIBJPEG - #define CODEC_JPEG 0xFFFF0009 + constexpr uint32_t CODEC_JPEG = 0xFFFF0009; #endif #ifdef USE_LIBPNG - #define CODEC_PNG 0xFFFF000A + constexpr uint32_t CODEC_PNG = 0xFFFF000A; #endif const SValue g_pSaveFileTypes[] = // valid formats to write to diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index 672edd78..b7326fde 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -379,18 +379,18 @@ namespace { nullptr, TEX_FILTER_DEFAULT } }; - #define CODEC_DDS 0xFFFF0001 - #define CODEC_TGA 0xFFFF0002 - #define CODEC_HDR 0xFFFF0005 + constexpr uint32_t CODEC_DDS = 0xFFFF0001; + constexpr uint32_t CODEC_TGA = 0xFFFF0002; + constexpr uint32_t CODEC_HDR = 0xFFFF0005; #ifdef USE_OPENEXR - #define CODEC_EXR 0xFFFF0006 + constexpr uint32_t CODEC_EXR = 0xFFFF0008; #endif #ifdef USE_LIBJPEG - #define CODEC_JPEG 0xFFFF0007 + constexpr uint32_t CODEC_JPEG = 0xFFFF0009; #endif #ifdef USE_LIBPNG - #define CODEC_PNG 0xFFFF0008 + constexpr uint32_t CODEC_PNG = 0xFFFF000A; #endif const SValue g_pDumpFileTypes[] = @@ -1388,7 +1388,7 @@ namespace //-------------------------------------------------------------------------------------- #define SIGN_EXTEND(x,nb) ((((x)&(1<<((nb)-1)))?((~0)^((1<<(nb))-1)):0)|(x)) -#define NUM_PIXELS_PER_BLOCK 16 + constexpr size_t NUM_PIXELS_PER_BLOCK = 16; void Print565(uint16_t rgb) { From af8ae93f3537e3e92b864190f75f6c46a3b4fa43 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 26 Oct 2024 11:49:13 -0700 Subject: [PATCH 12/18] Minor code review --- Texassemble/texassemble.cpp | 3 +-- Texconv/texconv.cpp | 33 +++++++++++---------------------- Texdiag/texdiag.cpp | 3 +-- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index 276ec0a4..1bc1c3e3 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -1097,8 +1097,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) maxVolume = LookupByName(pValue, g_pFeatureLevelsVolume); if (!maxSize || !maxCube || !maxArray || !maxVolume) { - wprintf(L"Invalid value specified with -fl (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -fl (%ls)\n\n", pValue); PrintUsage(); return 1; } diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 47b43d77..fb90b2c6 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -1412,8 +1412,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) case OPT_WIDTH: if (swscanf_s(pValue, L"%zu", &width) != 1) { - wprintf(L"Invalid value specified with -w (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -w (%ls)\n\n", pValue); PrintUsage(); return 1; } @@ -1432,8 +1431,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) case OPT_MIPLEVELS: if (swscanf_s(pValue, L"%zu", &mipLevels) != 1) { - wprintf(L"Invalid value specified with -m (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -m (%ls)\n\n", pValue); PrintUsage(); return 1; } @@ -1459,8 +1457,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; default: - wprintf(L"Invalid value specified with -f (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -f (%ls)\n\n", pValue); PrintUsage(); return 1; } @@ -1472,8 +1469,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) dwFilter = static_cast(LookupByName(pValue, g_pFilters)); if (!dwFilter) { - wprintf(L"Invalid value specified with -if (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -if (%ls)\n\n", pValue); PrintUsage(); return 1; } @@ -1483,8 +1479,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) dwRotateColor = LookupByName(pValue, g_pRotateColor); if (!dwRotateColor) { - wprintf(L"Invalid value specified with -rotatecolor (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -rotatecolor (%ls)\n\n", pValue); PrintUsage(); return 1; } @@ -1529,8 +1524,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) FileType = LookupByName(pValue, g_pSaveFileTypes); if (!FileType) { - wprintf(L"Invalid value specified with -ft (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -ft (%ls)\n\n", pValue); PrintUsage(); return 1; } @@ -1671,8 +1665,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) maxSize = LookupByName(pValue, g_pFeatureLevels); if (!maxSize) { - wprintf(L"Invalid value specified with -fl (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -fl (%ls)\n\n", pValue); PrintUsage(); return 1; } @@ -1681,15 +1674,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) case OPT_ALPHA_THRESHOLD: if (swscanf_s(pValue, L"%f", &alphaThreshold) != 1) { - wprintf(L"Invalid value specified with -at (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -at (%ls)\n\n", pValue); PrintUsage(); return 1; } else if (alphaThreshold < 0.f) { - wprintf(L"-at (%ls) parameter must be positive\n", pValue); - wprintf(L"\n"); + wprintf(L"-at (%ls) parameter must be positive\n\n", pValue); return 1; } break; @@ -1697,15 +1688,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) case OPT_ALPHA_WEIGHT: if (swscanf_s(pValue, L"%f", &alphaWeight) != 1) { - wprintf(L"Invalid value specified with -aw (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -aw (%ls)\n\n", pValue); PrintUsage(); return 1; } else if (alphaWeight < 0.f) { - wprintf(L"-aw (%ls) parameter must be positive\n", pValue); - wprintf(L"\n"); + wprintf(L"-aw (%ls) parameter must be positive\n\n", pValue); return 1; } break; diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index b7326fde..c975ab5a 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -3263,8 +3263,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) fileType = LookupByName(pValue, g_pDumpFileTypes); if (!fileType) { - wprintf(L"Invalid value specified with -ft (%ls)\n", pValue); - wprintf(L"\n"); + wprintf(L"Invalid value specified with -ft (%ls)\n\n", pValue); PrintUsage(); return 1; } From 619453e59d8190858bdbecf6c280b421130ca006 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 26 Oct 2024 12:14:26 -0700 Subject: [PATCH 13/18] More code review --- Texassemble/texassemble.cpp | 84 ++++++++++++++++++------------------- Texconv/texconv.cpp | 38 ++++++++--------- Texdiag/texdiag.cpp | 60 +++++++++++++------------- 3 files changed, 91 insertions(+), 91 deletions(-) diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index 1bc1c3e3..a4ae0324 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -888,17 +888,6 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) *pValue++ = 0; dwOption = LookupByName(pArg, g_pOptionsLong); - - if (dwOption == OPT_VERSION) - { - PrintLogo(true, g_ToolName, g_Description); - return 0; - } - else if (dwOption == OPT_HELP) - { - PrintUsage(); - return 0; - } } } else @@ -922,19 +911,30 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } } - if (!dwOption) + switch (dwOption) { + case 0: wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName); return 1; - } - if (dwOptions & (1 << dwOption)) - { - wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); - return 1; - } + case OPT_VERSION: + PrintLogo(true, g_ToolName, g_Description); + return 0; + + case OPT_HELP: + PrintUsage(); + return 0; - dwOptions |= 1 << dwOption; + default: + if (dwOptions & (1u << dwOption)) + { + wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); + return 1; + } + + dwOptions |= (1u << dwOption); + break; + } // Handle options with additional value parameter switch (dwOption) @@ -1154,7 +1154,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { const size_t count = conversion.size(); std::filesystem::path path(pArg); - SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0, nullptr); + SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1u << OPT_RECURSIVE)) != 0, nullptr); if (conversion.size() <= count) { wprintf(L"No matching files found for %ls\n", pArg); @@ -1176,7 +1176,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; } - if (~dwOptions & (1 << OPT_NOLOGO)) + if (~dwOptions & (1u << OPT_NOLOGO)) PrintLogo(false, g_ToolName, g_Description); switch (dwCommand) @@ -1231,7 +1231,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) outputFile = curpath.stem().concat(L".dds").native(); } - hr = LoadAnimatedGif(curpath.c_str(), loadedImages, (dwOptions & (1 << OPT_GIF_BGCOLOR)) != 0); + hr = LoadAnimatedGif(curpath.c_str(), loadedImages, (dwOptions & (1u << OPT_GIF_BGCOLOR)) != 0); if (FAILED(hr)) { wprintf(L" FAILED (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); @@ -1358,7 +1358,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\nERROR: Can't assemble complex surfaces\n"); return 1; } - else if ((info.mipLevels > 1) && ((dwOptions & (1 << OPT_STRIP_MIPS)) == 0)) + else if ((info.mipLevels > 1) && ((dwOptions & (1u << OPT_STRIP_MIPS)) == 0)) { switch (dwCommand) { @@ -1538,7 +1538,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Strip Mips (if requested) ----------------------------------------------- - if ((info.mipLevels > 1) && (dwOptions & (1 << OPT_STRIP_MIPS))) + if ((info.mipLevels > 1) && (dwOptions & (1u << OPT_STRIP_MIPS))) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -1588,7 +1588,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Undo Premultiplied Alpha (if requested) --------------------------------- - if ((dwOptions & (1 << OPT_DEMUL_ALPHA)) + if ((dwOptions & (1u << OPT_DEMUL_ALPHA)) && HasAlpha(info.format) && info.format != DXGI_FORMAT_A8_UNORM) { @@ -1695,7 +1695,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Tonemap (if requested) -------------------------------------------------- - if (dwOptions & (1 << OPT_TONEMAP)) + if (dwOptions & (1u << OPT_TONEMAP)) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -2035,12 +2035,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1 << OPT_TOLOWER)) + if (dwOptions & (1u << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1 << OPT_OVERWRITE)) + if (~dwOptions & (1u << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2103,12 +2103,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1 << OPT_TOLOWER)) + if (dwOptions & (1u << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1 << OPT_OVERWRITE)) + if (~dwOptions & (1u << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2172,12 +2172,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1 << OPT_TOLOWER)) + if (dwOptions & (1u << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1 << OPT_OVERWRITE)) + if (~dwOptions & (1u << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2371,12 +2371,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1 << OPT_TOLOWER)) + if (dwOptions & (1u << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1 << OPT_OVERWRITE)) + if (~dwOptions & (1u << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2386,7 +2386,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } hr = SaveToDDSFile(result.GetImages(), result.GetImageCount(), result.GetMetadata(), - (dwOptions & (1 << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE, + (dwOptions & (1u << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE, outputFile.c_str()); if (FAILED(hr)) { @@ -2429,12 +2429,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1 << OPT_TOLOWER)) + if (dwOptions & (1u << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1 << OPT_OVERWRITE)) + if (~dwOptions & (1u << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2444,7 +2444,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } hr = SaveToDDSFile(result.GetImages(), result.GetImageCount(), result.GetMetadata(), - (dwOptions & (1 << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE, + (dwOptions & (1u << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE, outputFile.c_str()); if (FAILED(hr)) { @@ -2518,7 +2518,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) case CMD_ARRAY: case CMD_GIF: - hr = result.InitializeArrayFromImages(&imageArray[0], imageArray.size(), (dwOptions & (1 << OPT_USE_DX10)) != 0); + hr = result.InitializeArrayFromImages(&imageArray[0], imageArray.size(), (dwOptions & (1u << OPT_USE_DX10)) != 0); break; case CMD_CUBE: @@ -2542,12 +2542,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1 << OPT_TOLOWER)) + if (dwOptions & (1u << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1 << OPT_OVERWRITE)) + if (~dwOptions & (1u << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2557,7 +2557,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } hr = SaveToDDSFile(result.GetImages(), result.GetImageCount(), result.GetMetadata(), - (dwOptions & (1 << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE, + (dwOptions & (1u << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE, outputFile.c_str()); if (FAILED(hr)) { diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index fb90b2c6..c5d18008 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -1315,17 +1315,6 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) *pValue++ = 0; dwOption = LookupByName(pArg, g_pOptionsLong); - - if (dwOption == OPT_VERSION) - { - PrintLogo(true, g_ToolName, g_Description); - return 0; - } - else if (dwOption == OPT_HELP) - { - PrintUsage(); - return 0; - } } } else @@ -1349,19 +1338,30 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } } - if (!dwOption) + switch (dwOption) { + case 0: wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName); return 1; - } - if (dwOptions & (uint64_t(1) << dwOption)) - { - wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); - return 1; - } + case OPT_VERSION: + PrintLogo(true, g_ToolName, g_Description); + return 0; + + case OPT_HELP: + PrintUsage(); + return 0; - dwOptions |= (uint64_t(1) << dwOption); + default: + if (dwOptions & (uint64_t(1) << dwOption)) + { + wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); + return 1; + } + + dwOptions |= (uint64_t(1) << dwOption); + break; + } // Handle options with additional value parameter switch (dwOption) diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index c975ab5a..78a18ed0 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -534,15 +534,15 @@ namespace if (_wcsicmp(ext.c_str(), L".dds") == 0) { DDS_FLAGS ddsFlags = DDS_FLAGS_ALLOW_LARGE_FILES; - if (dwOptions & (1 << OPT_DDS_DWORD_ALIGN)) + if (dwOptions & (1u << OPT_DDS_DWORD_ALIGN)) ddsFlags |= DDS_FLAGS_LEGACY_DWORD; - if (dwOptions & (1 << OPT_EXPAND_LUMINANCE)) + if (dwOptions & (1u << OPT_EXPAND_LUMINANCE)) ddsFlags |= DDS_FLAGS_EXPAND_LUMINANCE; - if (dwOptions & (1 << OPT_DDS_BAD_DXTN_TAILS)) + if (dwOptions & (1u << OPT_DDS_BAD_DXTN_TAILS)) ddsFlags |= DDS_FLAGS_BAD_DXTN_TAILS; - if (dwOptions & (1 << OPT_DDS_PERMISSIVE)) + if (dwOptions & (1u << OPT_DDS_PERMISSIVE)) ddsFlags |= DDS_FLAGS_PERMISSIVE; - if (dwOptions & (1 << OPT_DDS_IGNORE_MIPS)) + if (dwOptions & (1u << OPT_DDS_IGNORE_MIPS)) ddsFlags |= DDS_FLAGS_IGNORE_MIPS; HRESULT hr = LoadFromDDSFile(fileName, ddsFlags, &info, *image); @@ -551,11 +551,11 @@ namespace if (IsTypeless(info.format)) { - if (dwOptions & (1 << OPT_TYPELESS_UNORM)) + if (dwOptions & (1u << OPT_TYPELESS_UNORM)) { info.format = MakeTypelessUNORM(info.format); } - else if (dwOptions & (1 << OPT_TYPELESS_FLOAT)) + else if (dwOptions & (1u << OPT_TYPELESS_FLOAT)) { info.format = MakeTypelessFLOAT(info.format); } @@ -3125,17 +3125,6 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) *pValue++ = 0; dwOption = LookupByName(pArg, g_pOptionsLong); - - if (dwOption == OPT_VERSION) - { - PrintLogo(true, g_ToolName, g_Description); - return 0; - } - else if (dwOption == OPT_HELP) - { - PrintUsage(); - return 0; - } } } else @@ -3159,19 +3148,30 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } } - if (!dwOption) + switch (dwOption) { + case 0: wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName); return 1; - } - if (dwOptions & (1 << dwOption)) - { - wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); - return 1; - } + case OPT_VERSION: + PrintLogo(true, g_ToolName, g_Description); + return 0; + + case OPT_HELP: + PrintUsage(); + return 0; - dwOptions |= 1 << dwOption; + default: + if (dwOptions & (1u << dwOption)) + { + wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); + return 1; + } + + dwOptions |= (1u << dwOption); + break; + } // Handle options with additional value parameter switch (dwOption) @@ -3341,7 +3341,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { const size_t count = conversion.size(); std::filesystem::path path(pArg); - SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0, nullptr); + SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1u << OPT_RECURSIVE)) != 0, nullptr); if (conversion.size() <= count) { wprintf(L"No matching files found for %ls\n", pArg); @@ -3363,7 +3363,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; } - if (~dwOptions & (1 << OPT_NOLOGO)) + if (~dwOptions & (1u << OPT_NOLOGO)) PrintLogo(false, g_ToolName, g_Description); switch (dwCommand) @@ -3444,12 +3444,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } - if (dwOptions & (1 << OPT_TOLOWER)) + if (dwOptions & (1u << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1 << OPT_OVERWRITE)) + if (~dwOptions & (1u << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { From 4f6458d6e65c4fc5383b3591c4eb7042f0119732 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 26 Oct 2024 13:25:54 -0700 Subject: [PATCH 14/18] reclaim flags bits from options that need them --- Texconv/texconv.cpp | 69 ++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index c5d18008..82b32778 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -103,21 +103,8 @@ namespace enum OPTIONS : uint64_t { OPT_RECURSIVE = 1, - OPT_FILELIST, - OPT_WIDTH, - OPT_HEIGHT, - OPT_MIPLEVELS, - OPT_FORMAT, - OPT_FILTER, - OPT_SRGBI, - OPT_SRGBO, - OPT_SRGB, - OPT_PREFIX, - OPT_SUFFIX, - OPT_OUTPUTDIR, OPT_TOLOWER, OPT_OVERWRITE, - OPT_FILETYPE, OPT_HFLIP, OPT_VFLIP, OPT_DDS_DWORD_ALIGN, @@ -128,7 +115,6 @@ namespace OPT_USE_DX9, OPT_TGA20, OPT_TGAZEROALPHA, - OPT_WIC_QUALITY, OPT_WIC_LOSSLESS, OPT_WIC_MULTIFRAME, OPT_NOLOGO, @@ -145,28 +131,42 @@ namespace OPT_FORCE_SINGLEPROC, OPT_GPU, OPT_NOGPU, - OPT_FEATURE_LEVEL, OPT_FIT_POWEROF2, - OPT_ALPHA_THRESHOLD, - OPT_ALPHA_WEIGHT, OPT_NORMAL_MAP, - OPT_NORMAL_MAP_AMPLITUDE, - OPT_BC_COMPRESS, OPT_COLORKEY, OPT_TONEMAP, OPT_X2_BIAS, OPT_PRESERVE_ALPHA_COVERAGE, OPT_INVERT_Y, OPT_RECONSTRUCT_Z, - OPT_ROTATE_COLOR, - OPT_PAPER_WHITE_NITS, OPT_BCNONMULT4FIX, - OPT_SWIZZLE, #ifdef USE_XBOX_EXTS OPT_USE_XBOX, OPT_XGMODE, #endif OPT_FLAGS_MAX, + OPT_FILELIST, + OPT_WIDTH, + OPT_HEIGHT, + OPT_MIPLEVELS, + OPT_FORMAT, + OPT_FILTER, + OPT_SRGBI, + OPT_SRGBO, + OPT_SRGB, + OPT_PREFIX, + OPT_SUFFIX, + OPT_OUTPUTDIR, + OPT_FILETYPE, + OPT_WIC_QUALITY, + OPT_FEATURE_LEVEL, + OPT_ALPHA_THRESHOLD, + OPT_ALPHA_WEIGHT, + OPT_NORMAL_MAP_AMPLITUDE, + OPT_BC_COMPRESS, + OPT_ROTATE_COLOR, + OPT_PAPER_WHITE_NITS, + OPT_SWIZZLE, OPT_VERSION, OPT_HELP, }; @@ -1344,6 +1344,31 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) 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_MIPLEVELS: + case OPT_FORMAT: + case OPT_FILTER: + case OPT_SRGBI: + case OPT_SRGBO: + case OPT_SRGB: + case OPT_PREFIX: + case OPT_SUFFIX: + case OPT_OUTPUTDIR: + case OPT_FILETYPE: + case OPT_WIC_QUALITY: + case OPT_FEATURE_LEVEL: + case OPT_ALPHA_THRESHOLD: + case OPT_ALPHA_WEIGHT: + case OPT_NORMAL_MAP_AMPLITUDE: + case OPT_BC_COMPRESS: + case OPT_ROTATE_COLOR: + case OPT_PAPER_WHITE_NITS: + case OPT_SWIZZLE: + // These don't use flag bits + break; + case OPT_VERSION: PrintLogo(true, g_ToolName, g_Description); return 0; From 4cecb73f9fb8eef95d1650fc2a4cb4de8cf9dbab Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 26 Oct 2024 13:30:07 -0700 Subject: [PATCH 15/18] reclaim flags bits from options that need them --- Texdiag/texdiag.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index 78a18ed0..4d6ee4d9 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -96,26 +96,26 @@ namespace enum OPTIONS : uint32_t { OPT_RECURSIVE = 1, - OPT_FORMAT, - OPT_FILTER, OPT_DDS_DWORD_ALIGN, OPT_DDS_BAD_DXTN_TAILS, OPT_DDS_PERMISSIVE, OPT_DDS_IGNORE_MIPS, - OPT_OUTPUTFILE, OPT_TOLOWER, OPT_OVERWRITE, - OPT_FILETYPE, OPT_NOLOGO, OPT_TYPELESS_UNORM, OPT_TYPELESS_FLOAT, OPT_EXPAND_LUMINANCE, + OPT_FLAGS_MAX, + OPT_FORMAT, + OPT_FILTER, + OPT_OUTPUTFILE, + OPT_FILETYPE, OPT_TARGET_PIXELX, OPT_TARGET_PIXELY, OPT_DIFF_COLOR, OPT_THRESHOLD, OPT_FILELIST, - OPT_FLAGS_MAX, OPT_VERSION, OPT_HELP, }; @@ -3154,6 +3154,18 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName); return 1; + case OPT_FORMAT: + case OPT_FILTER: + case OPT_OUTPUTFILE: + case OPT_FILETYPE: + case OPT_TARGET_PIXELX: + case OPT_TARGET_PIXELY: + case OPT_DIFF_COLOR: + case OPT_THRESHOLD: + case OPT_FILELIST: + // These don't use flag bits + break; + case OPT_VERSION: PrintLogo(true, g_ToolName, g_Description); return 0; From 3ca3a7d12904802447cf2449c9d8ca25cee749b4 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 26 Oct 2024 13:34:59 -0700 Subject: [PATCH 16/18] reclaim flags bits from options that need them --- Texassemble/texassemble.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index a4ae0324..f61b2468 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -115,15 +115,6 @@ namespace enum OPTIONS : uint32_t { OPT_RECURSIVE = 1, - OPT_FILELIST, - OPT_WIDTH, - OPT_HEIGHT, - OPT_FORMAT, - OPT_FILTER, - OPT_SRGBI, - OPT_SRGBO, - OPT_SRGB, - OPT_OUTPUTFILE, OPT_TOLOWER, OPT_OVERWRITE, OPT_USE_DX10, @@ -133,12 +124,21 @@ namespace OPT_DEMUL_ALPHA, OPT_TA_WRAP, OPT_TA_MIRROR, - OPT_FEATURE_LEVEL, OPT_TONEMAP, OPT_GIF_BGCOLOR, - OPT_SWIZZLE, OPT_STRIP_MIPS, OPT_FLAGS_MAX, + OPT_FILELIST, + OPT_WIDTH, + OPT_HEIGHT, + OPT_FORMAT, + OPT_FILTER, + OPT_SRGBI, + OPT_SRGBO, + OPT_SRGB, + OPT_OUTPUTFILE, + OPT_FEATURE_LEVEL, + OPT_SWIZZLE, OPT_VERSION, OPT_HELP, }; @@ -917,6 +917,20 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) 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: + case OPT_FEATURE_LEVEL: + case OPT_SWIZZLE: + // These don't use flag bits + break; + case OPT_VERSION: PrintLogo(true, g_ToolName, g_Description); return 0; From 415563b753b04fda2992cf8472e56b2e60c107d0 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 26 Oct 2024 13:38:25 -0700 Subject: [PATCH 17/18] Code review --- Texassemble/texassemble.cpp | 2 +- Texdiag/texdiag.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index f61b2468..de2b19af 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -867,7 +867,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) if (allowOpts && (('-' == pArg[0]) || ('/' == pArg[0]))) { - uint64_t dwOption = 0; + uint32_t dwOption = 0; PWSTR pValue = nullptr; if (('-' == pArg[0]) && ('-' == pArg[1])) diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index 4d6ee4d9..f29d9dbd 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -3104,7 +3104,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) if (allowOpts && (('-' == pArg[0]) || ('/' == pArg[0]))) { - uint64_t dwOption = 0; + uint32_t dwOption = 0; PWSTR pValue = nullptr; if (('-' == pArg[0]) && ('-' == pArg[1])) From 8478e6d3093001dd4e50ec7ce40fd0c4fe541285 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 26 Oct 2024 18:56:53 -0700 Subject: [PATCH 18/18] Code review for cstdint constants --- Texassemble/texassemble.cpp | 50 +++++++++++------------ Texconv/texconv.cpp | 80 ++++++++++++++++++------------------- Texdiag/texdiag.cpp | 26 ++++++------ 3 files changed, 78 insertions(+), 78 deletions(-) diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index de2b19af..1518a309 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -940,13 +940,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; default: - if (dwOptions & (1u << dwOption)) + if (dwOptions & (UINT32_C(1) << dwOption)) { wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); return 1; } - dwOptions |= (1u << dwOption); + dwOptions |= (UINT32_C(1) << dwOption); break; } @@ -1168,7 +1168,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { const size_t count = conversion.size(); std::filesystem::path path(pArg); - SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1u << OPT_RECURSIVE)) != 0, nullptr); + SearchForFiles(path.make_preferred(), conversion, (dwOptions & (UINT32_C(1) << OPT_RECURSIVE)) != 0, nullptr); if (conversion.size() <= count) { wprintf(L"No matching files found for %ls\n", pArg); @@ -1190,7 +1190,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; } - if (~dwOptions & (1u << OPT_NOLOGO)) + if (~dwOptions & (UINT32_C(1) << OPT_NOLOGO)) PrintLogo(false, g_ToolName, g_Description); switch (dwCommand) @@ -1245,7 +1245,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) outputFile = curpath.stem().concat(L".dds").native(); } - hr = LoadAnimatedGif(curpath.c_str(), loadedImages, (dwOptions & (1u << OPT_GIF_BGCOLOR)) != 0); + hr = LoadAnimatedGif(curpath.c_str(), loadedImages, (dwOptions & (UINT32_C(1) << OPT_GIF_BGCOLOR)) != 0); if (FAILED(hr)) { wprintf(L" FAILED (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); @@ -1372,7 +1372,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\nERROR: Can't assemble complex surfaces\n"); return 1; } - else if ((info.mipLevels > 1) && ((dwOptions & (1u << OPT_STRIP_MIPS)) == 0)) + else if ((info.mipLevels > 1) && ((dwOptions & (UINT32_C(1) << OPT_STRIP_MIPS)) == 0)) { switch (dwCommand) { @@ -1552,7 +1552,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Strip Mips (if requested) ----------------------------------------------- - if ((info.mipLevels > 1) && (dwOptions & (1u << OPT_STRIP_MIPS))) + if ((info.mipLevels > 1) && (dwOptions & (UINT32_C(1) << OPT_STRIP_MIPS))) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -1602,7 +1602,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Undo Premultiplied Alpha (if requested) --------------------------------- - if ((dwOptions & (1u << OPT_DEMUL_ALPHA)) + if ((dwOptions & (UINT32_C(1) << OPT_DEMUL_ALPHA)) && HasAlpha(info.format) && info.format != DXGI_FORMAT_A8_UNORM) { @@ -1709,7 +1709,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Tonemap (if requested) -------------------------------------------------- - if (dwOptions & (1u << OPT_TONEMAP)) + if (dwOptions & (UINT32_C(1) << OPT_TONEMAP)) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -2049,12 +2049,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1u << OPT_TOLOWER)) + if (dwOptions & (UINT32_C(1) << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1u << OPT_OVERWRITE)) + if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2117,12 +2117,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1u << OPT_TOLOWER)) + if (dwOptions & (UINT32_C(1) << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1u << OPT_OVERWRITE)) + if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2186,12 +2186,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1u << OPT_TOLOWER)) + if (dwOptions & (UINT32_C(1) << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1u << OPT_OVERWRITE)) + if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2385,12 +2385,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1u << OPT_TOLOWER)) + if (dwOptions & (UINT32_C(1) << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1u << OPT_OVERWRITE)) + if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2400,7 +2400,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } hr = SaveToDDSFile(result.GetImages(), result.GetImageCount(), result.GetMetadata(), - (dwOptions & (1u << 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()); if (FAILED(hr)) { @@ -2443,12 +2443,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1u << OPT_TOLOWER)) + if (dwOptions & (UINT32_C(1) << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1u << OPT_OVERWRITE)) + if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2458,7 +2458,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } hr = SaveToDDSFile(result.GetImages(), result.GetImageCount(), result.GetMetadata(), - (dwOptions & (1u << 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()); if (FAILED(hr)) { @@ -2532,7 +2532,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) case CMD_ARRAY: case CMD_GIF: - hr = result.InitializeArrayFromImages(&imageArray[0], imageArray.size(), (dwOptions & (1u << OPT_USE_DX10)) != 0); + hr = result.InitializeArrayFromImages(&imageArray[0], imageArray.size(), (dwOptions & (UINT32_C(1) << OPT_USE_DX10)) != 0); break; case CMD_CUBE: @@ -2556,12 +2556,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"\n"); fflush(stdout); - if (dwOptions & (1u << OPT_TOLOWER)) + if (dwOptions & (UINT32_C(1) << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1u << OPT_OVERWRITE)) + if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -2571,7 +2571,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } hr = SaveToDDSFile(result.GetImages(), result.GetImageCount(), result.GetMetadata(), - (dwOptions & (1u << 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()); if (FAILED(hr)) { diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 82b32778..653a1cc1 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -1378,13 +1378,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; default: - if (dwOptions & (uint64_t(1) << dwOption)) + if (dwOptions & (UINT64_C(1) << dwOption)) { wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); return 1; } - dwOptions |= (uint64_t(1) << dwOption); + dwOptions |= (UINT64_C(1) << dwOption); break; } @@ -1556,7 +1556,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_PREMUL_ALPHA: - if (dwOptions & (uint64_t(1) << OPT_DEMUL_ALPHA)) + if (dwOptions & (UINT64_C(1) << OPT_DEMUL_ALPHA)) { wprintf(L"Can't use -pmalpha and -alpha at same time\n\n"); PrintUsage(); @@ -1565,7 +1565,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_DEMUL_ALPHA: - if (dwOptions & (uint64_t(1) << OPT_PREMUL_ALPHA)) + if (dwOptions & (UINT64_C(1) << OPT_PREMUL_ALPHA)) { wprintf(L"Can't use -pmalpha and -alpha at same time\n\n"); PrintUsage(); @@ -1796,7 +1796,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_USE_DX10: - if (dwOptions & (uint64_t(1) << OPT_USE_DX9)) + if (dwOptions & (UINT64_C(1) << OPT_USE_DX9)) { wprintf(L"Can't use -dx9 and -dx10 at same time\n\n"); PrintUsage(); @@ -1805,7 +1805,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_USE_DX9: - if (dwOptions & (uint64_t(1) << OPT_USE_DX10)) + if (dwOptions & (UINT64_C(1) << OPT_USE_DX10)) { wprintf(L"Can't use -dx9 and -dx10 at same time\n\n"); PrintUsage(); @@ -1927,7 +1927,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { const size_t count = conversion.size(); std::filesystem::path path(pArg); - SearchForFiles(path.make_preferred(), conversion, (dwOptions & (uint64_t(1) << OPT_RECURSIVE)) != 0, nullptr); + SearchForFiles(path.make_preferred(), conversion, (dwOptions & (UINT64_C(1) << OPT_RECURSIVE)) != 0, nullptr); if (conversion.size() <= count) { wprintf(L"No matching files found for %ls\n", pArg); @@ -1949,7 +1949,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; } - if (~dwOptions & (uint64_t(1) << OPT_NOLOGO)) + if (~dwOptions & (UINT64_C(1) << OPT_NOLOGO)) PrintLogo(false, g_ToolName, g_Description); auto fileTypeName = LookupByValue(FileType, g_pSaveFileTypes); @@ -2034,15 +2034,15 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) #endif // USE_XBOX_EXTS { DDS_FLAGS ddsFlags = DDS_FLAGS_ALLOW_LARGE_FILES; - if (dwOptions & (uint64_t(1) << OPT_DDS_DWORD_ALIGN)) + if (dwOptions & (UINT64_C(1) << OPT_DDS_DWORD_ALIGN)) ddsFlags |= DDS_FLAGS_LEGACY_DWORD; - if (dwOptions & (uint64_t(1) << OPT_EXPAND_LUMINANCE)) + if (dwOptions & (UINT64_C(1) << OPT_EXPAND_LUMINANCE)) ddsFlags |= DDS_FLAGS_EXPAND_LUMINANCE; - if (dwOptions & (uint64_t(1) << OPT_DDS_BAD_DXTN_TAILS)) + if (dwOptions & (UINT64_C(1) << OPT_DDS_BAD_DXTN_TAILS)) ddsFlags |= DDS_FLAGS_BAD_DXTN_TAILS; - if (dwOptions & (uint64_t(1) << OPT_DDS_PERMISSIVE)) + if (dwOptions & (UINT64_C(1) << OPT_DDS_PERMISSIVE)) ddsFlags |= DDS_FLAGS_PERMISSIVE; - if (dwOptions & (uint64_t(1) << OPT_DDS_IGNORE_MIPS)) + if (dwOptions & (UINT64_C(1) << OPT_DDS_IGNORE_MIPS)) ddsFlags |= DDS_FLAGS_IGNORE_MIPS; hr = LoadFromDDSFile(curpath.c_str(), ddsFlags, &info, *image); @@ -2056,11 +2056,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) if (IsTypeless(info.format)) { - if (dwOptions & (uint64_t(1) << OPT_TYPELESS_UNORM)) + if (dwOptions & (UINT64_C(1) << OPT_TYPELESS_UNORM)) { info.format = MakeTypelessUNORM(info.format); } - else if (dwOptions & (uint64_t(1) << OPT_TYPELESS_FLOAT)) + else if (dwOptions & (UINT64_C(1) << OPT_TYPELESS_FLOAT)) { info.format = MakeTypelessFLOAT(info.format); } @@ -2088,7 +2088,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) else if (_wcsicmp(ext.c_str(), L".tga") == 0) { TGA_FLAGS tgaFlags = (IsBGR(format)) ? TGA_FLAGS_BGR : TGA_FLAGS_NONE; - if (dwOptions & (uint64_t(1) << OPT_TGAZEROALPHA)) + if (dwOptions & (UINT64_C(1) << OPT_TGAZEROALPHA)) { tgaFlags |= TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA; } @@ -2256,7 +2256,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) // Direct3D can only create BC resources with multiple-of-4 top levels if ((info.width % 4) != 0 || (info.height % 4) != 0) { - if (dwOptions & (uint64_t(1) << OPT_BCNONMULT4FIX)) + if (dwOptions & (UINT64_C(1) << OPT_BCNONMULT4FIX)) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -2360,7 +2360,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Undo Premultiplied Alpha (if requested) --------------------------------- - if ((dwOptions & (uint64_t(1) << OPT_DEMUL_ALPHA)) + if ((dwOptions & (UINT64_C(1) << OPT_DEMUL_ALPHA)) && HasAlpha(info.format) && info.format != DXGI_FORMAT_A8_UNORM) { @@ -2411,7 +2411,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Flip/Rotate ------------------------------------------------------------- - if (dwOptions & ((uint64_t(1) << OPT_HFLIP) | (uint64_t(1) << OPT_VFLIP))) + if (dwOptions & ((UINT64_C(1) << OPT_HFLIP) | (UINT64_C(1) << OPT_VFLIP))) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -2422,10 +2422,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) TEX_FR_FLAGS dwFlags = TEX_FR_ROTATE0; - if (dwOptions & (uint64_t(1) << OPT_HFLIP)) + if (dwOptions & (UINT64_C(1) << OPT_HFLIP)) dwFlags |= TEX_FR_FLIP_HORIZONTAL; - if (dwOptions & (uint64_t(1) << OPT_VFLIP)) + if (dwOptions & (UINT64_C(1) << OPT_VFLIP)) dwFlags |= TEX_FR_FLIP_VERTICAL; assert(dwFlags != 0); @@ -2472,7 +2472,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) sizewarn = true; } - if (dwOptions & (uint64_t(1) << OPT_FIT_POWEROF2)) + if (dwOptions & (UINT64_C(1) << OPT_FIT_POWEROF2)) { FitPowerOf2(info.width, info.height, twidth, theight, maxSize); } @@ -2844,7 +2844,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Tonemap (if requested) -------------------------------------------------- - if (dwOptions & uint64_t(1) << OPT_TONEMAP) + if (dwOptions & UINT64_C(1) << OPT_TONEMAP) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -2924,7 +2924,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Convert ----------------------------------------------------------------- - if (dwOptions & (uint64_t(1) << OPT_NORMAL_MAP)) + if (dwOptions & (UINT64_C(1) << OPT_NORMAL_MAP)) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -3012,7 +3012,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- ColorKey/ChromaKey ------------------------------------------------------ - if ((dwOptions & (uint64_t(1) << OPT_COLORKEY)) + if ((dwOptions & (UINT64_C(1) << OPT_COLORKEY)) && HasAlpha(info.format)) { std::unique_ptr timage(new (std::nothrow) ScratchImage); @@ -3071,7 +3071,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Invert Y Channel -------------------------------------------------------- - if (dwOptions & (uint64_t(1) << OPT_INVERT_Y)) + if (dwOptions & (UINT64_C(1) << OPT_INVERT_Y)) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -3120,7 +3120,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Reconstruct Z Channel --------------------------------------------------- - if (dwOptions & (uint64_t(1) << OPT_RECONSTRUCT_Z)) + if (dwOptions & (UINT64_C(1) << OPT_RECONSTRUCT_Z)) { std::unique_ptr timage(new (std::nothrow) ScratchImage); if (!timage) @@ -3382,7 +3382,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } // --- Premultiplied alpha (if requested) -------------------------------------- - if ((dwOptions & (uint64_t(1) << OPT_PREMUL_ALPHA)) + if ((dwOptions & (UINT64_C(1) << OPT_PREMUL_ALPHA)) && HasAlpha(info.format) && info.format != DXGI_FORMAT_A8_UNORM) { @@ -3552,7 +3552,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { s_tryonce = true; - if (!(dwOptions & (uint64_t(1) << OPT_NOGPU))) + if (!(dwOptions & (UINT64_C(1) << OPT_NOGPU))) { if (!CreateDevice(adapter, pDevice.GetAddressOf())) wprintf(L"\nWARNING: DirectCompute is not available, using BC6H / BC7 CPU codec\n"); @@ -3571,7 +3571,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) TEX_COMPRESS_FLAGS cflags = dwCompress; #ifdef _OPENMP - if (!(dwOptions & (uint64_t(1) << OPT_FORCE_SINGLEPROC))) + if (!(dwOptions & (UINT64_C(1) << OPT_FORCE_SINGLEPROC))) { cflags |= TEX_COMPRESS_PARALLEL; } @@ -3631,7 +3631,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { // Aleady set TEX_ALPHA_MODE_PREMULTIPLIED } - else if (dwOptions & (uint64_t(1) << OPT_SEPALPHA)) + else if (dwOptions & (UINT64_C(1) << OPT_SEPALPHA)) { info.SetAlphaMode(TEX_ALPHA_MODE_CUSTOM); } @@ -3652,7 +3652,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) const size_t nimg = image->GetImageCount(); #ifdef USE_XBOX_EXTS - const bool isXboxOut = ((FileType == CODEC_DDS) && (dwOptions & (uint64_t(1) << OPT_USE_XBOX))) != 0; + const bool isXboxOut = ((FileType == CODEC_DDS) && (dwOptions & (UINT64_C(1) << OPT_USE_XBOX))) != 0; #else constexpr bool isXboxOut = false; #endif @@ -3699,7 +3699,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } std::wstring destName = dest.c_str(); - if (dwOptions & (uint64_t(1) << OPT_TOLOWER)) + if (dwOptions & (UINT64_C(1) << OPT_TOLOWER)) { std::transform(destName.begin(), destName.end(), destName.begin(), towlower); } @@ -3708,7 +3708,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) wprintf(L"writing %ls", destName.c_str()); fflush(stdout); - if (~dwOptions & (uint64_t(1) << OPT_OVERWRITE)) + if (~dwOptions & (UINT64_C(1) << OPT_OVERWRITE)) { if (GetFileAttributesW(destName.c_str()) != INVALID_FILE_ATTRIBUTES) { @@ -3736,11 +3736,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) #endif // USE_XBOX_EXTS { DDS_FLAGS ddsFlags = DDS_FLAGS_NONE; - if (dwOptions & (uint64_t(1) << OPT_USE_DX10)) + if (dwOptions & (UINT64_C(1) << OPT_USE_DX10)) { ddsFlags |= DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2; } - else if (dwOptions & (uint64_t(1) << OPT_USE_DX9)) + else if (dwOptions & (UINT64_C(1) << OPT_USE_DX9)) { if (dxt5rxgb) { @@ -3755,7 +3755,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case CODEC_TGA: - hr = SaveToTGAFile(img[0], TGA_FLAGS_NONE, destName.c_str(), (dwOptions & (uint64_t(1) << OPT_TGA20)) ? &info : nullptr); + hr = SaveToTGAFile(img[0], TGA_FLAGS_NONE, destName.c_str(), (dwOptions & (UINT64_C(1) << OPT_TGA20)) ? &info : nullptr); break; case CODEC_HDR: @@ -3789,11 +3789,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) default: { const WICCodecs codec = (FileType == CODEC_HDP || FileType == CODEC_JXR) ? WIC_CODEC_WMP : static_cast(FileType); - const size_t nimages = (dwOptions & (uint64_t(1) << OPT_WIC_MULTIFRAME)) ? nimg : 1; + const size_t nimages = (dwOptions & (UINT64_C(1) << OPT_WIC_MULTIFRAME)) ? nimg : 1; hr = SaveToWICFile(img, nimages, WIC_FLAGS_NONE, GetWICCodec(codec), destName.c_str(), nullptr, [&](IPropertyBag2* props) { - const bool wicLossless = (dwOptions & (uint64_t(1) << OPT_WIC_LOSSLESS)) != 0; + const bool wicLossless = (dwOptions & (UINT64_C(1) << OPT_WIC_LOSSLESS)) != 0; switch (FileType) { @@ -3884,7 +3884,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) if (non4bc) wprintf(L"\nWARNING: Direct3D requires BC image to be multiple of 4 in width & height\n"); - if (dwOptions & (uint64_t(1) << OPT_TIMING)) + if (dwOptions & (UINT64_C(1) << OPT_TIMING)) { LARGE_INTEGER qpcEnd = {}; std::ignore = QueryPerformanceCounter(&qpcEnd); diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index f29d9dbd..f6a6fc80 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -534,15 +534,15 @@ namespace if (_wcsicmp(ext.c_str(), L".dds") == 0) { DDS_FLAGS ddsFlags = DDS_FLAGS_ALLOW_LARGE_FILES; - if (dwOptions & (1u << OPT_DDS_DWORD_ALIGN)) + if (dwOptions & (UINT32_C(1) << OPT_DDS_DWORD_ALIGN)) ddsFlags |= DDS_FLAGS_LEGACY_DWORD; - if (dwOptions & (1u << OPT_EXPAND_LUMINANCE)) + if (dwOptions & (UINT32_C(1) << OPT_EXPAND_LUMINANCE)) ddsFlags |= DDS_FLAGS_EXPAND_LUMINANCE; - if (dwOptions & (1u << OPT_DDS_BAD_DXTN_TAILS)) + if (dwOptions & (UINT32_C(1) << OPT_DDS_BAD_DXTN_TAILS)) ddsFlags |= DDS_FLAGS_BAD_DXTN_TAILS; - if (dwOptions & (1u << OPT_DDS_PERMISSIVE)) + if (dwOptions & (UINT32_C(1) << OPT_DDS_PERMISSIVE)) ddsFlags |= DDS_FLAGS_PERMISSIVE; - if (dwOptions & (1u << OPT_DDS_IGNORE_MIPS)) + if (dwOptions & (UINT32_C(1) << OPT_DDS_IGNORE_MIPS)) ddsFlags |= DDS_FLAGS_IGNORE_MIPS; HRESULT hr = LoadFromDDSFile(fileName, ddsFlags, &info, *image); @@ -551,11 +551,11 @@ namespace if (IsTypeless(info.format)) { - if (dwOptions & (1u << OPT_TYPELESS_UNORM)) + if (dwOptions & (UINT32_C(1) << OPT_TYPELESS_UNORM)) { info.format = MakeTypelessUNORM(info.format); } - else if (dwOptions & (1u << OPT_TYPELESS_FLOAT)) + else if (dwOptions & (UINT32_C(1) << OPT_TYPELESS_FLOAT)) { info.format = MakeTypelessFLOAT(info.format); } @@ -3175,13 +3175,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; default: - if (dwOptions & (1u << dwOption)) + if (dwOptions & (UINT32_C(1) << dwOption)) { wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg); return 1; } - dwOptions |= (1u << dwOption); + dwOptions |= (UINT32_C(1) << dwOption); break; } @@ -3353,7 +3353,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { const size_t count = conversion.size(); std::filesystem::path path(pArg); - SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1u << OPT_RECURSIVE)) != 0, nullptr); + SearchForFiles(path.make_preferred(), conversion, (dwOptions & (UINT32_C(1) << OPT_RECURSIVE)) != 0, nullptr); if (conversion.size() <= count) { wprintf(L"No matching files found for %ls\n", pArg); @@ -3375,7 +3375,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; } - if (~dwOptions & (1u << OPT_NOLOGO)) + if (~dwOptions & (UINT32_C(1) << OPT_NOLOGO)) PrintLogo(false, g_ToolName, g_Description); switch (dwCommand) @@ -3456,12 +3456,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } - if (dwOptions & (1u << OPT_TOLOWER)) + if (dwOptions & (UINT32_C(1) << OPT_TOLOWER)) { std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower); } - if (~dwOptions & (1u << OPT_OVERWRITE)) + if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE)) { if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES) {