texassemble/texconv: Code cleanup

This commit is contained in:
Chuck Walbourn 2016-09-12 16:39:26 -07:00
parent dc76cc86eb
commit 2d27b1447e
2 changed files with 1295 additions and 1279 deletions

View File

@ -32,7 +32,7 @@
using namespace DirectX; using namespace DirectX;
enum OPTIONS // Note: dwOptions below assumes 32 or less options. enum OPTIONS
{ {
OPT_CUBE = 1, OPT_CUBE = 1,
OPT_VOLUME, OPT_VOLUME,
@ -179,6 +179,8 @@ SValue g_pFilters[] =
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
namespace
{
#pragma prefast(disable : 26018, "Only used with static internal arrays") #pragma prefast(disable : 26018, "Only used with static internal arrays")
DWORD LookupByName(const wchar_t *pName, const SValue *pArray) DWORD LookupByName(const wchar_t *pName, const SValue *pArray)
@ -317,6 +319,7 @@ void PrintUsage()
wprintf(L" <filter>: "); wprintf(L" <filter>: ");
PrintList(13, g_pFilters); PrintList(13, g_pFilters);
} }
}
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -372,9 +375,14 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
dwOptions |= 1 << dwOption; dwOptions |= 1 << dwOption;
if( (OPT_NOLOGO != dwOption) && (OPT_SEPALPHA != dwOption) && (OPT_USE_DX10 != dwOption) // Handle options with additional value parameter
&& (OPT_CUBE != dwOption) && (OPT_VOLUME != dwOption) && (OPT_ARRAY != dwOption) && (OPT_CUBEARRAY != dwOption) ) switch (dwOption)
{ {
case OPT_WIDTH:
case OPT_HEIGHT:
case OPT_FORMAT:
case OPT_FILTER:
case OPT_OUTPUTFILE:
if (!*pValue) if (!*pValue)
{ {
if ((iArg + 1 >= argc)) if ((iArg + 1 >= argc))
@ -496,7 +504,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> image(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> image(new (std::nothrow) ScratchImage);
if (!image) if (!image)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -513,7 +521,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|| info.mipLevels > 1 || info.mipLevels > 1
|| info.IsCubemap()) || info.IsCubemap())
{ {
wprintf( L" ERROR: Can't assemble complex surfaces\n" ); wprintf(L"\nERROR: Can't assemble complex surfaces\n");
return 1; return 1;
} }
} }
@ -568,7 +576,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -609,7 +617,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -647,7 +655,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -681,7 +689,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (images < 2) if (images < 2)
{ {
wprintf( L" ERROR: Need at least 2 images to assemble\n\n"); wprintf(L"\nERROR: Need at least 2 images to assemble\n\n");
return 1; return 1;
} }
@ -690,7 +698,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case (1 << OPT_CUBE): case (1 << OPT_CUBE):
if (images != 6) if (images != 6)
{ {
wprintf( L" ERROR: -cube requires six images to form the faces of the cubemap\n"); wprintf(L"\nERROR: -cube requires six images to form the faces of the cubemap\n");
return 1; return 1;
} }
break; break;

View File

@ -38,7 +38,7 @@
using namespace DirectX; using namespace DirectX;
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
enum OPTIONS // Note: dwOptions below assumes 64 or less options. enum OPTIONS
{ {
OPT_WIDTH = 1, OPT_WIDTH = 1,
OPT_HEIGHT, OPT_HEIGHT,
@ -343,6 +343,8 @@ SValue g_pFeatureLevels[] = // valid feature levels for -fl for maximimum si
#pragma warning( disable : 4616 6211 ) #pragma warning( disable : 4616 6211 )
namespace
{
inline static bool ispow2(size_t x) inline static bool ispow2(size_t x)
{ {
return ((x != 0) && !(x & (x - 1))); return ((x != 0) && !(x & (x - 1)));
@ -363,6 +365,7 @@ DWORD LookupByName(const wchar_t *pName, const SValue *pArray)
return 0; return 0;
} }
const wchar_t* LookupByValue(DWORD pValue, const SValue *pArray) const wchar_t* LookupByValue(DWORD pValue, const SValue *pArray)
{ {
while (pArray->pName) while (pArray->pName)
@ -376,6 +379,7 @@ const wchar_t* LookupByValue(DWORD pValue, const SValue *pArray)
return L""; return L"";
} }
void PrintFormat(DXGI_FORMAT Format) void PrintFormat(DXGI_FORMAT Format)
{ {
for (SValue *pFormat = g_pFormats; pFormat->pName; pFormat++) for (SValue *pFormat = g_pFormats; pFormat->pName; pFormat++)
@ -399,6 +403,7 @@ void PrintFormat(DXGI_FORMAT Format)
wprintf(L"*UNKNOWN*"); wprintf(L"*UNKNOWN*");
} }
void PrintInfo(const TexMetadata& info) void PrintInfo(const TexMetadata& info)
{ {
wprintf(L" (%Iux%Iu", info.width, info.height); wprintf(L" (%Iux%Iu", info.width, info.height);
@ -523,7 +528,8 @@ void PrintUsage()
wprintf(L" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n"); wprintf(L" -wrap, -mirror texture addressing mode (wrap, mirror, or clamp)\n");
wprintf(L" -pmalpha convert final texture to use premultiplied alpha\n"); wprintf(L" -pmalpha convert final texture to use premultiplied alpha\n");
wprintf(L" -pow2 resize to fit a power-of-2, respecting aspect ratio\n"); wprintf(L" -pow2 resize to fit a power-of-2, respecting aspect ratio\n");
wprintf (L" -nmap <options> converts height-map to normal-map\n" wprintf(
L" -nmap <options> converts height-map to normal-map\n"
L" options must be one or more of\n" L" options must be one or more of\n"
L" r, g, b, a, l, m, u, v, i, o\n"); L" r, g, b, a, l, m, u, v, i, o\n");
wprintf(L" -nmapamp <weight> normal map amplitude (defaults to 1.0)\n"); wprintf(L" -nmapamp <weight> normal map amplitude (defaults to 1.0)\n");
@ -547,7 +553,8 @@ void PrintUsage()
wprintf(L" -bcmax Use exchaustive compression (BC7 only)\n"); wprintf(L" -bcmax Use exchaustive compression (BC7 only)\n");
wprintf(L" -wicq <quality> When writing images with WIC use quality (0.0 to 1.0)\n"); wprintf(L" -wicq <quality> When writing images with WIC use quality (0.0 to 1.0)\n");
wprintf(L" -wiclossless When writing images with WIC use lossless mode\n"); wprintf(L" -wiclossless When writing images with WIC use lossless mode\n");
wprintf( L" -aw <weight> BC7 GPU compressor weighting for alpha error metric\n" wprintf(
L" -aw <weight> BC7 GPU compressor weighting for alpha error metric\n"
L" (defaults to 1.0)\n"); L" (defaults to 1.0)\n");
wprintf(L"\n"); wprintf(L"\n");
@ -721,6 +728,7 @@ void FitPowerOf2( size_t origx, size_t origy, size_t& targetx, size_t& targety,
} }
} }
} }
}
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -1170,7 +1178,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (!image) if (!image)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1299,7 +1307,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1339,7 +1347,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1381,7 +1389,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1427,7 +1435,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1462,7 +1470,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1501,7 +1509,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1541,7 +1549,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
} }
else else
{ {
wprintf( L" ERROR: Cannot generate mips for non-power-of-2 volume textures\n" ); wprintf(L"\nERROR: Cannot generate mips for non-power-of-2 volume textures\n");
return 1; return 1;
} }
} }
@ -1557,7 +1565,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1646,7 +1654,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1698,7 +1706,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }
@ -1762,7 +1770,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage); std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage) if (!timage)
{ {
wprintf( L" ERROR: Memory allocation failed\n" ); wprintf(L"\nERROR: Memory allocation failed\n");
return 1; return 1;
} }