@@ -99,15 +99,6 @@ namespace
99
99
enum OPTIONS : uint32_t
100
100
{
101
101
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,
111
102
OPT_TOLOWER,
112
103
OPT_OVERWRITE,
113
104
OPT_USE_DX10,
@@ -118,10 +109,21 @@ namespace
118
109
OPT_TA_WRAP,
119
110
OPT_TA_MIRROR,
120
111
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,
122
124
};
123
125
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" );
125
127
126
128
// ////////////////////////////////////////////////////////////////////////////
127
129
// ////////////////////////////////////////////////////////////////////////////
@@ -160,6 +162,23 @@ namespace
160
162
{ nullptr , 0 }
161
163
};
162
164
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
+
163
182
#define DEFFMT (fmt ) { L## #fmt, DXGI_FORMAT_ ## fmt }
164
183
165
184
const SValue<DXGI_FORMAT> g_pFormats[] =
@@ -229,19 +248,19 @@ namespace
229
248
{ nullptr , TEX_FILTER_DEFAULT }
230
249
};
231
250
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 ;
235
254
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
245
264
246
265
const SValue<uint32_t > g_pExtFileTypes[] =
247
266
{
@@ -381,20 +400,28 @@ namespace
381
400
382
401
static const wchar_t * const s_usage =
383
402
L" Usage: texenvmap <command> <options> [--] <files>\n\n "
403
+ L" \n COMMANDS\n "
384
404
L" cubic create cubic environment map\n "
385
405
L" sphere create sphere environment map\n "
386
406
L" dualparabola create dual-parabolic environment map\n "
407
+ L" \n OPTIONS\n "
387
408
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 "
398
425
L" -nowic Force non-WIC filtering\n "
399
426
L" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n "
400
427
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[])
1098
1125
{
1099
1126
PWSTR pArg = argv[iArg];
1100
1127
1101
- if (allowOpts
1102
- && (' -' == pArg[0 ]) && (' -' == pArg[1 ]))
1128
+ if (allowOpts && ((' -' == pArg[0 ]) || (' /' == pArg[0 ])))
1103
1129
{
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 ]))
1110
1134
{
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
+ }
1113
1152
}
1114
- else if (! _wcsicmp (pArg, L" --help " ))
1153
+ else
1115
1154
{
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
+ }
1118
1172
}
1119
- else
1173
+
1174
+ switch (dwOption)
1120
1175
{
1121
- wprintf (L" Unknown option: %ls\n " , pArg);
1176
+ case 0 :
1177
+ wprintf (L" ERROR: Unknown option: `%ls`\n\n Use %ls --help\n " , pArg, g_ToolName);
1122
1178
return 1 ;
1123
- }
1124
- }
1125
- else if (allowOpts
1126
- && ((' -' == pArg[0 ]) || (' /' == pArg[0 ])))
1127
- {
1128
- pArg++;
1129
- PWSTR pValue;
1130
1179
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 ;
1132
1191
1133
- if (*pValue)
1134
- *pValue++ = 0 ;
1192
+ case OPT_VERSION:
1193
+ PrintLogo (true , g_ToolName, g_Description);
1194
+ return 0 ;
1135
1195
1136
- const uint32_t dwOption = LookupByName (pArg, g_pOptions);
1137
- if (!dwOption || (dwOptions & (1 << dwOption)))
1138
- {
1196
+ case OPT_HELP:
1139
1197
PrintUsage ();
1140
- return 1 ;
1141
- }
1198
+ return 0 ;
1142
1199
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
+ }
1144
1210
1145
1211
// Handle options with additional value parameter
1146
1212
switch (dwOption)
@@ -1303,7 +1369,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
1303
1369
{
1304
1370
const size_t count = conversion.size ();
1305
1371
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 );
1307
1373
if (conversion.size () <= count)
1308
1374
{
1309
1375
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[])
1325
1391
return 0 ;
1326
1392
}
1327
1393
1328
- if (~dwOptions & (1 << OPT_NOLOGO))
1394
+ if (~dwOptions & (UINT32_C ( 1 ) << OPT_NOLOGO))
1329
1395
PrintLogo (false , g_ToolName, g_Description);
1330
1396
1331
1397
ComPtr<ID3D11Device> pDevice;
@@ -1602,7 +1668,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
1602
1668
}
1603
1669
1604
1670
// --- Undo Premultiplied Alpha (if requested) ---------------------------------
1605
- if ((dwOptions & (1 << OPT_DEMUL_ALPHA))
1671
+ if ((dwOptions & (UINT32_C ( 1 ) << OPT_DEMUL_ALPHA))
1606
1672
&& HasAlpha (info.format )
1607
1673
&& info.format != DXGI_FORMAT_A8_UNORM)
1608
1674
{
@@ -1794,12 +1860,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
1794
1860
wprintf (L" \n Writing %ls " , outputFile.c_str ());
1795
1861
fflush (stdout);
1796
1862
1797
- if (dwOptions & (1 << OPT_TOLOWER))
1863
+ if (dwOptions & (UINT32_C ( 1 ) << OPT_TOLOWER))
1798
1864
{
1799
1865
std::transform (outputFile.begin (), outputFile.end (), outputFile.begin (), towlower);
1800
1866
}
1801
1867
1802
- if (~dwOptions & (1 << OPT_OVERWRITE))
1868
+ if (~dwOptions & (UINT32_C ( 1 ) << OPT_OVERWRITE))
1803
1869
{
1804
1870
if (GetFileAttributesW (outputFile.c_str ()) != INVALID_FILE_ATTRIBUTES)
1805
1871
{
@@ -1836,7 +1902,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
1836
1902
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
1837
1903
1838
1904
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,
1840
1906
outputFile.c_str ());
1841
1907
if (FAILED (hr))
1842
1908
{
0 commit comments