Skip to content

Commit 708ded8

Browse files
committed
Updated for latest changes to command line tools
1 parent a81f479 commit 708ded8

File tree

1 file changed

+136
-70
lines changed

1 file changed

+136
-70
lines changed

Texenvmap/texenvmap.cpp

+136-70
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ namespace
9999
enum OPTIONS : uint32_t
100100
{
101101
OPT_RECURSIVE = 1,
102-
OPT_FILELIST,
103-
OPT_WIDTH,
104-
OPT_HEIGHT,
105-
OPT_FORMAT,
106-
OPT_FILTER,
107-
OPT_SRGBI,
108-
OPT_SRGBO,
109-
OPT_SRGB,
110-
OPT_OUTPUTFILE,
111102
OPT_TOLOWER,
112103
OPT_OVERWRITE,
113104
OPT_USE_DX10,
@@ -118,10 +109,21 @@ namespace
118109
OPT_TA_WRAP,
119110
OPT_TA_MIRROR,
120111
OPT_GPU,
121-
OPT_MAX
112+
OPT_FLAGS_MAX,
113+
OPT_FILELIST,
114+
OPT_WIDTH,
115+
OPT_HEIGHT,
116+
OPT_FORMAT,
117+
OPT_FILTER,
118+
OPT_SRGBI,
119+
OPT_SRGBO,
120+
OPT_SRGB,
121+
OPT_OUTPUTFILE,
122+
OPT_VERSION,
123+
OPT_HELP,
122124
};
123125

124-
static_assert(OPT_MAX <= 32, "dwOptions is a unsigned int bitfield");
126+
static_assert(OPT_FLAGS_MAX <= 32, "dwOptions is a unsigned int bitfield");
125127

126128
//////////////////////////////////////////////////////////////////////////////
127129
//////////////////////////////////////////////////////////////////////////////
@@ -160,6 +162,23 @@ namespace
160162
{ nullptr, 0 }
161163
};
162164

165+
const SValue<uint32_t> g_pOptionsLong[] =
166+
{
167+
{ L"file-list", OPT_FILELIST },
168+
{ L"format", OPT_FORMAT },
169+
{ L"height", OPT_HEIGHT },
170+
{ L"help", OPT_HELP },
171+
{ L"image-filter", OPT_FILTER },
172+
{ L"overwrite", OPT_OVERWRITE },
173+
{ L"separate-alpha", OPT_SEPALPHA },
174+
{ L"srgb-in", OPT_SRGBI },
175+
{ L"srgb-out", OPT_SRGBO },
176+
{ L"to-lowercase", OPT_TOLOWER },
177+
{ L"version", OPT_VERSION },
178+
{ L"width", OPT_WIDTH },
179+
{ nullptr, 0 }
180+
};
181+
163182
#define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt }
164183

165184
const SValue<DXGI_FORMAT> g_pFormats[] =
@@ -229,19 +248,19 @@ namespace
229248
{ nullptr, TEX_FILTER_DEFAULT }
230249
};
231250

232-
#define CODEC_DDS 0xFFFF0001
233-
#define CODEC_TGA 0xFFFF0002
234-
#define CODEC_HDR 0xFFFF0005
251+
constexpr uint32_t CODEC_DDS = 0xFFFF0001;
252+
constexpr uint32_t CODEC_TGA = 0xFFFF0002;
253+
constexpr uint32_t CODEC_HDR = 0xFFFF0005;
235254

236-
#ifdef USE_OPENEXR
237-
#define CODEC_EXR 0xFFFF0006
238-
#endif
239-
#ifdef USE_LIBJPEG
240-
#define CODEC_JPEG 0xFFFF0007
241-
#endif
242-
#ifdef USE_LIBPNG
243-
#define CODEC_PNG 0xFFFF0008
244-
#endif
255+
#ifdef USE_OPENEXR
256+
constexpr uint32_t CODEC_EXR = 0xFFFF0008;
257+
#endif
258+
#ifdef USE_LIBJPEG
259+
constexpr uint32_t CODEC_JPEG = 0xFFFF0009;
260+
#endif
261+
#ifdef USE_LIBPNG
262+
constexpr uint32_t CODEC_PNG = 0xFFFF000A;
263+
#endif
245264

246265
const SValue<uint32_t> g_pExtFileTypes[] =
247266
{
@@ -381,20 +400,28 @@ namespace
381400

382401
static const wchar_t* const s_usage =
383402
L"Usage: texenvmap <command> <options> [--] <files>\n\n"
403+
L"\nCOMMANDS\n"
384404
L" cubic create cubic environment map\n"
385405
L" sphere create sphere environment map\n"
386406
L" dualparabola create dual-parabolic environment map\n"
407+
L"\nOPTIONS\n"
387408
L" -r wildcard filename search is recursive\n"
388-
L" -flist <filename> use text file with a list of input files (one per line)\n"
389-
L" -w <n> width\n"
390-
L" -h <n> height\n"
391-
L" -f <format> format\n"
392-
L" -if <filter> image filtering\n"
393-
L" -srgb{i|o} sRGB {input, output}\n"
394-
L" -o <filename> output filename\n"
395-
L" -l force output filename to lower case\n"
396-
L" -y overwrite existing output file (if any)\n"
397-
L" -sepalpha resize alpha channel separately from color channels\n"
409+
L" -flist <filename>, --file-list <filename>\n"
410+
L" use text file with a list of input files (one per line)\n"
411+
L"\n"
412+
L" -w <n>, --width <n> width for output\n"
413+
L" -h <n>, --height <n> height for output\n"
414+
L" -f <format>, --format <format> pixel format for output\n"
415+
L"\n"
416+
L" -if <filter>, --image-filter <filter> image filtering\n"
417+
L" -srgb{i|o}, --srgb-in, --srgb-out sRGB {input, output}\n"
418+
L"\n"
419+
L" -o <filename> output filename\n"
420+
L" -l, --to-lowercase force output filename to lower case\n"
421+
L" -y, --overwrite overwrite existing output file (if any)\n"
422+
L"\n"
423+
L" -sepalpha, --separate-alpha resize/generate mips alpha channel separately from color channels\n"
424+
L"\n"
398425
L" -nowic Force non-WIC filtering\n"
399426
L" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n"
400427
L" -alpha convert premultiplied alpha to straight alpha\n"
@@ -1098,49 +1125,88 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
10981125
{
10991126
PWSTR pArg = argv[iArg];
11001127

1101-
if (allowOpts
1102-
&& ('-' == pArg[0]) && ('-' == pArg[1]))
1128+
if (allowOpts && (('-' == pArg[0]) || ('/' == pArg[0])))
11031129
{
1104-
if (pArg[2] == 0)
1105-
{
1106-
// "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths.
1107-
allowOpts = false;
1108-
}
1109-
else if (!_wcsicmp(pArg, L"--version"))
1130+
uint32_t dwOption = 0;
1131+
PWSTR pValue = nullptr;
1132+
1133+
if (('-' == pArg[0]) && ('-' == pArg[1]))
11101134
{
1111-
PrintLogo(true, g_ToolName, g_Description);
1112-
return 0;
1135+
if (pArg[2] == 0)
1136+
{
1137+
// "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths.
1138+
allowOpts = false;
1139+
continue;
1140+
}
1141+
else
1142+
{
1143+
pArg += 2;
1144+
1145+
for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue);
1146+
1147+
if (*pValue)
1148+
*pValue++ = 0;
1149+
1150+
dwOption = LookupByName(pArg, g_pOptionsLong);
1151+
}
11131152
}
1114-
else if (!_wcsicmp(pArg, L"--help"))
1153+
else
11151154
{
1116-
PrintUsage();
1117-
return 0;
1155+
pArg++;
1156+
1157+
for (pValue = pArg; *pValue && (':' != *pValue) && ('=' != *pValue); ++pValue);
1158+
1159+
if (*pValue)
1160+
*pValue++ = 0;
1161+
1162+
dwOption = LookupByName(pArg, g_pOptions);
1163+
1164+
if (!dwOption)
1165+
{
1166+
if (LookupByName(pArg, g_pOptionsLong))
1167+
{
1168+
wprintf(L"ERROR: did you mean `--%ls` (with two dashes)?\n", pArg);
1169+
return 1;
1170+
}
1171+
}
11181172
}
1119-
else
1173+
1174+
switch (dwOption)
11201175
{
1121-
wprintf(L"Unknown option: %ls\n", pArg);
1176+
case 0:
1177+
wprintf(L"ERROR: Unknown option: `%ls`\n\nUse %ls --help\n", pArg, g_ToolName);
11221178
return 1;
1123-
}
1124-
}
1125-
else if (allowOpts
1126-
&& (('-' == pArg[0]) || ('/' == pArg[0])))
1127-
{
1128-
pArg++;
1129-
PWSTR pValue;
11301179

1131-
for (pValue = pArg; *pValue && (':' != *pValue); pValue++);
1180+
case OPT_FILELIST:
1181+
case OPT_WIDTH:
1182+
case OPT_HEIGHT:
1183+
case OPT_FORMAT:
1184+
case OPT_FILTER:
1185+
case OPT_SRGBI:
1186+
case OPT_SRGBO:
1187+
case OPT_SRGB:
1188+
case OPT_OUTPUTFILE:
1189+
// These don't use flag bits
1190+
break;
11321191

1133-
if (*pValue)
1134-
*pValue++ = 0;
1192+
case OPT_VERSION:
1193+
PrintLogo(true, g_ToolName, g_Description);
1194+
return 0;
11351195

1136-
const uint32_t dwOption = LookupByName(pArg, g_pOptions);
1137-
if (!dwOption || (dwOptions & (1 << dwOption)))
1138-
{
1196+
case OPT_HELP:
11391197
PrintUsage();
1140-
return 1;
1141-
}
1198+
return 0;
11421199

1143-
dwOptions |= 1 << dwOption;
1200+
default:
1201+
if (dwOptions & (UINT32_C(1) << dwOption))
1202+
{
1203+
wprintf(L"ERROR: Duplicate option: `%ls`\n\n", pArg);
1204+
return 1;
1205+
}
1206+
1207+
dwOptions |= (UINT32_C(1) << dwOption);
1208+
break;
1209+
}
11441210

11451211
// Handle options with additional value parameter
11461212
switch (dwOption)
@@ -1303,7 +1369,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
13031369
{
13041370
const size_t count = conversion.size();
13051371
std::filesystem::path path(pArg);
1306-
SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0, nullptr);
1372+
SearchForFiles(path.make_preferred(), conversion, (dwOptions & (UINT32_C(1) << OPT_RECURSIVE)) != 0, nullptr);
13071373
if (conversion.size() <= count)
13081374
{
13091375
wprintf(L"No matching files found for %ls\n", pArg);
@@ -1325,7 +1391,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
13251391
return 0;
13261392
}
13271393

1328-
if (~dwOptions & (1 << OPT_NOLOGO))
1394+
if (~dwOptions & (UINT32_C(1) << OPT_NOLOGO))
13291395
PrintLogo(false, g_ToolName, g_Description);
13301396

13311397
ComPtr<ID3D11Device> pDevice;
@@ -1602,7 +1668,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
16021668
}
16031669

16041670
// --- Undo Premultiplied Alpha (if requested) ---------------------------------
1605-
if ((dwOptions & (1 << OPT_DEMUL_ALPHA))
1671+
if ((dwOptions & (UINT32_C(1) << OPT_DEMUL_ALPHA))
16061672
&& HasAlpha(info.format)
16071673
&& info.format != DXGI_FORMAT_A8_UNORM)
16081674
{
@@ -1794,12 +1860,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
17941860
wprintf(L"\nWriting %ls ", outputFile.c_str());
17951861
fflush(stdout);
17961862

1797-
if (dwOptions & (1 << OPT_TOLOWER))
1863+
if (dwOptions & (UINT32_C(1) << OPT_TOLOWER))
17981864
{
17991865
std::transform(outputFile.begin(), outputFile.end(), outputFile.begin(), towlower);
18001866
}
18011867

1802-
if (~dwOptions & (1 << OPT_OVERWRITE))
1868+
if (~dwOptions & (UINT32_C(1) << OPT_OVERWRITE))
18031869
{
18041870
if (GetFileAttributesW(outputFile.c_str()) != INVALID_FILE_ATTRIBUTES)
18051871
{
@@ -1836,7 +1902,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
18361902
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
18371903

18381904
hr = SaveToDDSFile(imageArray, 6, mdata,
1839-
(dwOptions & (1 << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE,
1905+
(dwOptions & (UINT32_C(1) << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE,
18401906
outputFile.c_str());
18411907
if (FAILED(hr))
18421908
{

0 commit comments

Comments
 (0)