clang warning cleanup for command-line tools

This commit is contained in:
Chuck Walbourn 2019-07-05 23:48:39 -07:00
Родитель 3adb8d7ecb
Коммит 2aab4c9d8e
3 изменённых файлов: 197 добавлений и 120 удалений

Просмотреть файл

@ -15,7 +15,6 @@
#define NOMINMAX
#define NODRAWTEXT
#define NOGDI
#define NOBITMAP
#define NOMCX
#define NOSERVICE
#define NOHELP
@ -262,7 +261,10 @@ const SValue g_pFilters [] =
#define CODEC_DDS 0xFFFF0001
#define CODEC_TGA 0xFFFF0002
#define CODEC_HDR 0xFFFF0005
#ifdef USE_OPENEXR
#define CODEC_EXR 0xFFFF0006
#endif
const SValue g_pExtFileTypes [] =
{
@ -296,7 +298,9 @@ namespace
typedef std::unique_ptr<void, find_closer> ScopedFindHandle;
#ifdef _PREFAST_
#pragma prefast(disable : 26018, "Only used with static internal arrays")
#endif
DWORD LookupByName(const wchar_t *pName, const SValue *pArray)
{
@ -391,7 +395,7 @@ namespace
{
for (const SValue *pFormat = g_pFormats; pFormat->pName; pFormat++)
{
if ((DXGI_FORMAT)pFormat->dwValue == Format)
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{
wprintf(pFormat->pName);
break;
@ -449,6 +453,11 @@ namespace
case TEX_ALPHA_MODE_STRAIGHT:
wprintf(L" \x0e0:NonPM");
break;
case TEX_ALPHA_MODE_CUSTOM:
wprintf(L" \x0e0:Custom");
break;
case TEX_ALPHA_MODE_UNKNOWN:
break;
}
wprintf(L")");
@ -570,7 +579,7 @@ namespace
(destRect.bottom > static_cast<long>(img.height)) ? static_cast<long>(img.height) : destRect.bottom
};
auto ptr = reinterpret_cast<uint8_t*>(img.pixels + clipped.top * img.rowPitch + clipped.left * sizeof(uint32_t));
auto ptr = reinterpret_cast<uint8_t*>(img.pixels + size_t(clipped.top) * img.rowPitch + size_t(clipped.left) * sizeof(uint32_t));
for (long y = clipped.top; y < clipped.bottom; ++y)
{
@ -597,7 +606,7 @@ namespace
};
auto rawPtr = reinterpret_cast<uint8_t*>(raw.pixels);
auto composedPtr = reinterpret_cast<uint8_t*>(composed.pixels + clipped.top * composed.rowPitch + clipped.left * sizeof(uint32_t));
auto composedPtr = reinterpret_cast<uint8_t*>(composed.pixels + size_t(clipped.top) * composed.rowPitch + size_t(clipped.left) * sizeof(uint32_t));
for (long y = clipped.top; y < clipped.bottom; ++y)
{
@ -876,7 +885,7 @@ namespace
{
Rect fullRect(0, 0, img->width, img->height);
hr = CopyRectangle(*img, fullRect, *composedImage, TEX_FILTER_DEFAULT, rct.left, rct.top);
hr = CopyRectangle(*img, fullRect, *composedImage, TEX_FILTER_DEFAULT, size_t(rct.left), size_t(rct.top));
if (FAILED(hr))
return hr;
}
@ -903,7 +912,9 @@ namespace
//--------------------------------------------------------------------------------------
// Entry-point
//--------------------------------------------------------------------------------------
#ifdef _PREFAST_
#pragma prefast(disable : 28198, "Command-line tool, frees all memory on exit")
#endif
int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
@ -1002,6 +1013,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
iArg++;
pValue = argv[iArg];
}
break;
default:
break;
}
switch (dwOption)
@ -1162,6 +1177,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
break;
default:
break;
}
}
else if (wcspbrk(pArg, L"?*") != nullptr)
@ -1214,6 +1232,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
break;
default:
break;
}
// Convert images
@ -1393,12 +1414,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
else
{
// WIC shares the same filter values for mode and dither
static_assert(WIC_FLAGS_DITHER == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_DITHER), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_DITHER_DIFFUSION == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_DITHER_DIFFUSION), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_POINT == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_POINT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_LINEAR == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_LINEAR), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_CUBIC == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_CUBIC), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_FANT == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_FANT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_DITHER) == static_cast<int>(TEX_FILTER_DITHER), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_DITHER_DIFFUSION) == static_cast<int>(TEX_FILTER_DITHER_DIFFUSION), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_POINT) == static_cast<int>(TEX_FILTER_POINT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_LINEAR) == static_cast<int>(TEX_FILTER_LINEAR), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_CUBIC) == static_cast<int>(TEX_FILTER_CUBIC), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_FANT) == static_cast<int>(TEX_FILTER_FANT), "WIC_FLAGS_* & TEX_FILTER_* should match");
hr = LoadFromWICFile(pConv->szSrc, dwFilter | WIC_FLAGS_ALL_FRAMES, &info, *image);
if (FAILED(hr))
@ -1472,7 +1493,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
continue;
}
const TexMetadata& tinfo = timage->GetMetadata();
auto& tinfo = timage->GetMetadata();
info.format = tinfo.format;
@ -1560,7 +1581,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
const TexMetadata& tinfo = timage->GetMetadata();
auto& tinfo = timage->GetMetadata();
assert(tinfo.width == width && tinfo.height == height && tinfo.mipLevels == 1);
info.width = tinfo.width;
@ -1589,13 +1610,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
// Compute max luminosity across all images
XMVECTOR maxLum = XMVectorZero();
hr = EvaluateImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](const XMVECTOR* pixels, size_t width, size_t y)
[&](const XMVECTOR* pixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
static const XMVECTORF32 s_luminance = {{{ 0.3f, 0.59f, 0.11f, 0.f }}};
static const XMVECTORF32 s_luminance = { { { 0.3f, 0.59f, 0.11f, 0.f } } };
XMVECTOR v = *pixels++;
@ -1615,11 +1636,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
maxLum = XMVectorMultiply(maxLum, maxLum);
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -1639,8 +1660,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
#ifndef NDEBUG
auto& tinfo = timage->GetMetadata();
(void)tinfo;
#endif
assert(info.width == tinfo.width);
assert(info.height == tinfo.height);
@ -1676,7 +1698,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
const TexMetadata& tinfo = timage->GetMetadata();
auto& tinfo = timage->GetMetadata();
assert(tinfo.format == format);
info.format = tinfo.format;
@ -1769,6 +1791,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case CMD_V_STRIP:
twidth = width;
theight = height * 6;
break;
default:
break;
}
ScratchImage result;
@ -1838,6 +1864,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
// posx, negx, posy, negy, posz, negz
offsety = index * height;
break;
default:
break;
}
hr = CopyRectangle(*img, rect, *dest, dwFilter | dwFilterOpts, offsetx, offsety);
@ -1886,11 +1915,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
const Image& img = *alphaImage.GetImage(0, 0, 0);
hr = EvaluateImage(*loadedImages[1]->GetImage(0, 0, 0),
[&](const XMVECTOR* pixels, size_t width, size_t y)
[&](const XMVECTOR* pixels, size_t w, size_t y)
{
auto alphaPtr = reinterpret_cast<float*>(img.pixels + img.rowPitch * y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = pixels[j];
@ -1909,11 +1938,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
const Image& rgb = *loadedImages[0]->GetImage(0, 0, 0);
ScratchImage result;
hr = TransformImage(rgb, [&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
hr = TransformImage(rgb, [&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
auto alphaPtr = reinterpret_cast<float*>(img.pixels + img.rowPitch * y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2027,11 +2056,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
for (auto it = loadedImages.cbegin(); it != loadedImages.cend(); ++it)
{
const ScratchImage* simage = it->get();
assert(simage != 0);
assert(simage != nullptr);
for (size_t j = 0; j < simage->GetMetadata().arraySize; ++j)
{
const Image* img = simage->GetImage(0, j, 0);
assert(img != 0);
assert(img != nullptr);
imageArray.push_back(*img);
}
}
@ -2052,6 +2081,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case CMD_CUBEARRAY:
hr = result.InitializeCubeFromImages(&imageArray[0], imageArray.size());
break;
default:
break;
}
if (FAILED(hr))

Просмотреть файл

@ -390,7 +390,10 @@ const SValue g_pRotateColor[] =
#define CODEC_HDP 0xFFFF0003
#define CODEC_JXR 0xFFFF0004
#define CODEC_HDR 0xFFFF0005
#ifdef USE_OPENEXR
#define CODEC_EXR 0xFFFF0006
#endif
const SValue g_pSaveFileTypes[] = // valid formats to write to
{
@ -449,7 +452,9 @@ namespace
return ((x != 0) && !(x & (x - 1)));
}
#ifdef _PREFAST_
#pragma prefast(disable : 26018, "Only used with static internal arrays")
#endif
DWORD LookupByName(const wchar_t *pName, const SValue *pArray)
{
@ -558,7 +563,7 @@ namespace
{
for (const SValue *pFormat = g_pFormats; pFormat->pName; pFormat++)
{
if ((DXGI_FORMAT)pFormat->dwValue == Format)
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{
wprintf(pFormat->pName);
return;
@ -567,7 +572,7 @@ namespace
for (const SValue *pFormat = g_pReadOnlyFormats; pFormat->pName; pFormat++)
{
if ((DXGI_FORMAT)pFormat->dwValue == Format)
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{
wprintf(pFormat->pName);
return;
@ -627,6 +632,11 @@ namespace
case TEX_ALPHA_MODE_STRAIGHT:
wprintf(L" \x0e0:NonPM");
break;
case TEX_ALPHA_MODE_CUSTOM:
wprintf(L" \x0e0:Custom");
break;
case TEX_ALPHA_MODE_UNKNOWN:
break;
}
wprintf(L")");
@ -831,7 +841,7 @@ namespace
ComPtr<IDXGIFactory1> dxgiFactory;
if (GetDXGIFactory(dxgiFactory.GetAddressOf()))
{
if (FAILED(dxgiFactory->EnumAdapters(adapter, pAdapter.GetAddressOf())))
if (FAILED(dxgiFactory->EnumAdapters(static_cast<UINT>(adapter), pAdapter.GetAddressOf())))
{
wprintf(L"\nERROR: Invalid GPU adapter index (%d)!\n", adapter);
return false;
@ -930,30 +940,30 @@ namespace
}
}
const XMVECTORF32 c_MaxNitsFor2084 = {{{ 10000.0f, 10000.0f, 10000.0f, 1.f }}};
const XMVECTORF32 c_MaxNitsFor2084 = { { { 10000.0f, 10000.0f, 10000.0f, 1.f } } };
const XMMATRIX c_from709to2020 =
{
0.6274040f, 0.0690970f, 0.0163916f, 0.f,
0.3292820f, 0.9195400f, 0.0880132f, 0.f,
0.0433136f, 0.0113612f, 0.8955950f, 0.f,
0.f, 0.f, 0.f, 1.f
XMVECTOR { 0.6274040f, 0.0690970f, 0.0163916f, 0.f },
XMVECTOR { 0.3292820f, 0.9195400f, 0.0880132f, 0.f },
XMVECTOR { 0.0433136f, 0.0113612f, 0.8955950f, 0.f },
XMVECTOR { 0.f, 0.f, 0.f, 1.f }
};
const XMMATRIX c_from2020to709 =
{
1.6604910f, -0.1245505f, -0.0181508f, 0.f,
-0.5876411f, 1.1328999f, -0.1005789f, 0.f,
-0.0728499f, -0.0083494f, 1.1187297f, 0.f,
0.f, 0.f, 0.f, 1.f
XMVECTOR { 1.6604910f, -0.1245505f, -0.0181508f, 0.f },
XMVECTOR { -0.5876411f, 1.1328999f, -0.1005789f, 0.f },
XMVECTOR { -0.0728499f, -0.0083494f, 1.1187297f, 0.f },
XMVECTOR { 0.f, 0.f, 0.f, 1.f }
};
const XMMATRIX c_fromP3to2020 =
{
0.753845f, 0.0457456f, -0.00121055f, 0.f,
0.198593f, 0.941777f, 0.0176041f, 0.f,
0.047562f, 0.0124772f, 0.983607f, 0.f,
0.f, 0.f, 0.f, 1.f
XMVECTOR { 0.753845f, 0.0457456f, -0.00121055f, 0.f },
XMVECTOR { 0.198593f, 0.941777f, 0.0176041f, 0.f },
XMVECTOR { 0.047562f, 0.0124772f, 0.983607f, 0.f },
XMVECTOR { 0.f, 0.f, 0.f, 1.f }
};
inline float LinearToST2084(float normalizedLinearValue)
@ -1064,7 +1074,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
HRESULT hr = image.Initialize2D(format, header->biWidth, header->biHeight, 1, 1);
HRESULT hr = image.Initialize2D(format, size_t(header->biWidth), size_t(header->biHeight), 1, 1);
if (FAILED(hr))
return hr;
@ -1095,7 +1105,9 @@ namespace
//--------------------------------------------------------------------------------------
// Entry-point
//--------------------------------------------------------------------------------------
#ifdef _PREFAST_
#pragma prefast(disable : 28198, "Command-line tool, frees all memory on exit")
#endif
int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
@ -1788,12 +1800,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
else
{
// WIC shares the same filter values for mode and dither
static_assert(WIC_FLAGS_DITHER == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_DITHER), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_DITHER_DIFFUSION == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_DITHER_DIFFUSION), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_POINT == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_POINT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_LINEAR == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_LINEAR), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_CUBIC == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_CUBIC), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_FANT == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_FANT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_DITHER) == static_cast<int>(TEX_FILTER_DITHER), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_DITHER_DIFFUSION) == static_cast<int>(TEX_FILTER_DITHER_DIFFUSION), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_POINT) == static_cast<int>(TEX_FILTER_POINT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_LINEAR) == static_cast<int>(TEX_FILTER_LINEAR), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_CUBIC) == static_cast<int>(TEX_FILTER_CUBIC), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_FANT) == static_cast<int>(TEX_FILTER_FANT), "WIC_FLAGS_* & TEX_FILTER_* should match");
DWORD wicFlags = dwFilter;
if (FileType == CODEC_DDS)
@ -2077,8 +2089,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
#ifndef NDEBUG
auto& tinfo = timage->GetMetadata();
(void)tinfo;
#endif
assert(tinfo.format == DXGI_FORMAT_R16G16B16A16_FLOAT);
info.format = DXGI_FORMAT_R16G16B16A16_FLOAT;
@ -2106,13 +2119,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
case ROTATE_709_TO_HDR10:
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2139,11 +2152,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case ROTATE_709_TO_2020:
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2158,13 +2171,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case ROTATE_HDR10_TO_709:
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2191,11 +2204,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case ROTATE_2020_TO_709:
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2210,13 +2223,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case ROTATE_P3_TO_HDR10:
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2243,11 +2256,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case ROTATE_P3_TO_2020:
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2270,8 +2283,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
#ifndef NDEBUG
auto& tinfo = timage->GetMetadata();
(void)tinfo;
#endif
assert(info.width == tinfo.width);
assert(info.height == tinfo.height);
@ -2299,13 +2313,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
// Compute max luminosity across all images
XMVECTOR maxLum = XMVectorZero();
hr = EvaluateImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](const XMVECTOR* pixels, size_t width, size_t y)
[&](const XMVECTOR* pixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
static const XMVECTORF32 s_luminance = {{{ 0.3f, 0.59f, 0.11f, 0.f }}};
static const XMVECTORF32 s_luminance = { { { 0.3f, 0.59f, 0.11f, 0.f } } };
XMVECTOR v = *pixels++;
@ -2325,11 +2339,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
maxLum = XMVectorMultiply(maxLum, maxLum);
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2349,8 +2363,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
#ifndef NDEBUG
auto& tinfo = timage->GetMetadata();
(void)tinfo;
#endif
assert(info.width == tinfo.width);
assert(info.height == tinfo.height);
@ -2452,13 +2467,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
XMVECTOR colorKeyValue = XMLoadColor(reinterpret_cast<const XMCOLOR*>(&colorKey));
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
static const XMVECTORF32 s_tolerance = {{{ 0.2f, 0.2f, 0.2f, 0.f }}};
static const XMVECTORF32 s_tolerance = { { { 0.2f, 0.2f, 0.2f, 0.f } } };
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2480,8 +2495,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
#ifndef NDEBUG
auto& tinfo = timage->GetMetadata();
(void)tinfo;
#endif
assert(info.width == tinfo.width);
assert(info.height == tinfo.height);
@ -2507,13 +2523,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t width, size_t y)
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
static const XMVECTORU32 s_selecty = { { { XM_SELECT_0, XM_SELECT_1, XM_SELECT_0, XM_SELECT_0 } } };
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < width; ++j)
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
@ -2528,8 +2544,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
#ifndef NDEBUG
auto& tinfo = timage->GetMetadata();
(void)tinfo;
#endif
assert(info.width == tinfo.width);
assert(info.height == tinfo.height);
@ -2727,8 +2744,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
}
#ifndef NDEBUG
auto& tinfo = timage->GetMetadata();
(void)tinfo;
#endif
assert(info.width == tinfo.width);
assert(info.height == tinfo.height);
@ -2856,6 +2874,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
}
break;
default:
break;
}
DWORD cflags = dwCompress;
@ -2945,7 +2966,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wcscpy_s(pConv->szDest, MAX_PATH, szPrefix);
pchSlash = wcsrchr(pConv->szSrc, L'\\');
if (pchSlash != 0)
if (pchSlash)
wcscat_s(pConv->szDest, MAX_PATH, pchSlash + 1);
else
wcscat_s(pConv->szDest, MAX_PATH, pConv->szSrc);

Просмотреть файл

@ -15,7 +15,6 @@
#define NOMINMAX
#define NODRAWTEXT
#define NOGDI
#define NOBITMAP
#define NOMCX
#define NOSERVICE
#define NOHELP
@ -310,7 +309,10 @@ const SValue g_pFilters[] =
#define CODEC_DDS 0xFFFF0001
#define CODEC_TGA 0xFFFF0002
#define CODEC_HDR 0xFFFF0005
#ifdef USE_OPENEXR
#define CODEC_EXR 0xFFFF0006
#endif
const SValue g_pDumpFileTypes[] =
{
@ -361,7 +363,9 @@ namespace
typedef std::unique_ptr<void, find_closer> ScopedFindHandle;
#ifdef _PREFAST_
#pragma prefast(disable : 26018, "Only used with static internal arrays")
#endif
DWORD LookupByName(const wchar_t *pName, const SValue *pArray)
{
@ -470,7 +474,7 @@ namespace
{
for (const SValue *pFormat = g_pFormats; pFormat->pName; pFormat++)
{
if ((DXGI_FORMAT)pFormat->dwValue == Format)
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{
wprintf(pFormat->pName);
return;
@ -479,7 +483,7 @@ namespace
for (const SValue *pFormat = g_pReadOnlyFormats; pFormat->pName; pFormat++)
{
if ((DXGI_FORMAT)pFormat->dwValue == Format)
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{
wprintf(pFormat->pName);
return;
@ -626,12 +630,12 @@ namespace
else
{
// WIC shares the same filter values for mode and dither
static_assert(WIC_FLAGS_DITHER == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_DITHER), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_DITHER_DIFFUSION == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_DITHER_DIFFUSION), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_POINT == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_POINT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_LINEAR == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_LINEAR), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_CUBIC == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_CUBIC), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(WIC_FLAGS_FILTER_FANT == static_cast<DirectX::WIC_FLAGS>(TEX_FILTER_FANT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_DITHER) == static_cast<int>(TEX_FILTER_DITHER), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_DITHER_DIFFUSION) == static_cast<int>(TEX_FILTER_DITHER_DIFFUSION), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_POINT) == static_cast<int>(TEX_FILTER_POINT), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_LINEAR) == static_cast<int>(TEX_FILTER_LINEAR), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_CUBIC) == static_cast<int>(TEX_FILTER_CUBIC), "WIC_FLAGS_* & TEX_FILTER_* should match");
static_assert(static_cast<int>(WIC_FLAGS_FILTER_FANT) == static_cast<int>(TEX_FILTER_FANT), "WIC_FLAGS_* & TEX_FILTER_* should match");
return LoadFromWICFile(fileName, dwFilter | WIC_FLAGS_ALL_FRAMES, &info, *image);
}
@ -705,7 +709,7 @@ namespace
HRESULT hr = EvaluateImage(image, [&](const XMVECTOR * pixels, size_t width, size_t y)
{
static const XMVECTORF32 s_luminance = {{{ 0.3f, 0.59f, 0.11f, 0.f }}};
static const XMVECTORF32 s_luminance = { { { 0.3f, 0.59f, 0.11f, 0.f } } };
UNREFERENCED_PARAMETER(y);
@ -720,22 +724,22 @@ namespace
XMFLOAT4 f;
XMStoreFloat4(&f, v);
if (!_finite(f.x))
if (!isfinite(f.x))
{
++result.specials_x;
}
if (!_finite(f.y))
if (!isfinite(f.y))
{
++result.specials_y;
}
if (!_finite(f.z))
if (!isfinite(f.z))
{
++result.specials_z;
}
if (!_finite(f.w))
if (!isfinite(f.w))
{
++result.specials_w;
}
@ -846,6 +850,9 @@ namespace
if (blockHist[8] > 0)
wprintf(L"\tReserved mode blcks - %zu\n", blockHist[8]);
break;
default:
break;
}
}
};
@ -1204,6 +1211,9 @@ namespace
++result.blockHist[8];
}
break;
default:
break;
}
sptr += sbpp;
@ -1374,9 +1384,9 @@ namespace
void Print565(uint16_t rgb)
{
float r = (float)((rgb >> 11) & 31) * (1.0f / 31.0f);
float g = (float)((rgb >> 5) & 63) * (1.0f / 63.0f);
float b = (float)((rgb >> 0) & 31) * (1.0f / 31.0f);
auto r = float(((rgb >> 11) & 31) * (1.0f / 31.0f));
auto g = float(((rgb >> 5) & 63) * (1.0f / 63.0f));
auto b = float(((rgb >> 0) & 31) * (1.0f / 31.0f));
wprintf(L"(R: %.3f, G: %.3f, B: %.3f)", r, g, b);
}
@ -1442,7 +1452,7 @@ namespace
void PrintIndex3bpp(const uint8_t data[6])
{
uint32_t bitmap = data[0] | (data[1] << 8) | (data[2] << 16);
uint32_t bitmap = uint32_t(data[0]) | (uint32_t(data[1]) << 8) | (uint32_t(data[2]) << 16);
size_t j = 0;
for (; j < (NUM_PIXELS_PER_BLOCK / 2); ++j, bitmap >>= 3)
@ -1450,7 +1460,7 @@ namespace
wprintf(L"%u%ls", bitmap & 0x7, ((j % 4) == 3) ? L" | " : L" ");
}
bitmap = data[3] | (data[4] << 8) | (data[5] << 16);
bitmap = uint32_t(data[3]) | (uint32_t(data[4]) << 8) | (uint32_t(data[5]) << 16);
for (; j < NUM_PIXELS_PER_BLOCK; ++j, bitmap >>= 3)
{
@ -1595,8 +1605,8 @@ namespace
wprintf(L"\n");
wprintf(L"\tAlpha - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
float((float)block->alpha[0] / 255.f),
float((float)block->alpha[1] / 255.f), (block->alpha[0] > block->alpha[1]) ? 8 : 6);
(float(block->alpha[0]) / 255.f),
(float(block->alpha[1]) / 255.f), (block->alpha[0] > block->alpha[1]) ? 8 : 6);
PrintIndex3bpp(block->bitmap);
@ -1609,8 +1619,8 @@ namespace
auto block = reinterpret_cast<const BC4UBlock*>(sptr);
wprintf(L"\t E0: %0.3f E1: %0.3f (%u)\n\tIndex: ",
float((float)block->red_0 / 255.f),
float((float)block->red_1 / 255.f), (block->red_0 > block->red_1) ? 8 : 6);
(float(block->red_0) / 255.f),
(float(block->red_1) / 255.f), (block->red_0 > block->red_1) ? 8 : 6);
PrintIndex3bpp(block->indices);
@ -1623,8 +1633,8 @@ namespace
auto block = reinterpret_cast<const BC4SBlock*>(sptr);
wprintf(L"\t E0: %0.3f E1: %0.3f (%u)\n\tIndex: ",
float((float)block->red_0 / 127.f),
float((float)block->red_1 / 127.f), (block->red_0 > block->red_1) ? 8 : 6);
(float(block->red_0) / 127.f),
(float(block->red_1) / 127.f), (block->red_0 > block->red_1) ? 8 : 6);
PrintIndex3bpp(block->indices);
@ -1637,16 +1647,16 @@ namespace
auto block = reinterpret_cast<const BC5UBlock*>(sptr);
wprintf(L"\tU - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
float((float)block->u.red_0 / 255.f),
float((float)block->u.red_1 / 255.f), (block->u.red_0 > block->u.red_1) ? 8 : 6);
(float(block->u.red_0) / 255.f),
(float(block->u.red_1) / 255.f), (block->u.red_0 > block->u.red_1) ? 8 : 6);
PrintIndex3bpp(block->u.indices);
wprintf(L"\n");
wprintf(L"\tV - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
float((float)block->v.red_0 / 255.f),
float((float)block->v.red_1 / 255.f), (block->v.red_0 > block->v.red_1) ? 8 : 6);
(float(block->v.red_0) / 255.f),
(float(block->v.red_1) / 255.f), (block->v.red_0 > block->v.red_1) ? 8 : 6);
PrintIndex3bpp(block->v.indices);
@ -1659,16 +1669,16 @@ namespace
auto block = reinterpret_cast<const BC5SBlock*>(sptr);
wprintf(L"\tU - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
float((float)block->u.red_0 / 127.f),
float((float)block->u.red_1 / 127.f), (block->u.red_0 > block->u.red_1) ? 8 : 6);
(float(block->u.red_0) / 127.f),
(float(block->u.red_1) / 127.f), (block->u.red_0 > block->u.red_1) ? 8 : 6);
PrintIndex3bpp(block->u.indices);
wprintf(L"\n");
wprintf(L"\tV - E0: %0.3f E1: %0.3f (%u)\n\t Index: ",
float((float)block->v.red_0 / 127.f),
float((float)block->v.red_1 / 127.f), (block->v.red_0 > block->v.red_1) ? 8 : 6);
(float(block->v.red_0) / 127.f),
(float(block->v.red_1) / 127.f), (block->v.red_0 > block->v.red_1) ? 8 : 6);
PrintIndex3bpp(block->v.indices);
@ -2659,6 +2669,9 @@ namespace
case 0x1F: // Reserved mode (5 bits, 11111)
wprintf(L"\tERROR - Reserved mode 11111\n");
break;
default:
break;
}
break;
}
@ -2866,7 +2879,7 @@ namespace
wprintf(L"\t A1:(%0.3f)\n", float(m->a1) / 63.f);
wprintf(L"\t Colors: ");
uint64_t color_index = m->color_index | (m->color_indexn << 14);
uint64_t color_index = uint64_t(m->color_index) | uint64_t(m->color_indexn << 14);
if (m->idx)
PrintIndex3bpp(color_index, 0, 0);
else
@ -3008,7 +3021,9 @@ namespace
//--------------------------------------------------------------------------------------
// Entry-point
//--------------------------------------------------------------------------------------
#ifdef _PREFAST_
#pragma prefast(disable : 28198, "Command-line tool, frees all memory on exit")
#endif
int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
@ -3100,6 +3115,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
pValue = argv[iArg];
}
break;
default:
break;
}
switch (dwOption)
@ -3237,6 +3255,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
inFile.close();
}
break;
default:
break;
}
}
else if (wcspbrk(pArg, L"?*") != nullptr)
@ -3432,13 +3453,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
min_mse = std::min(min_mse, mse);
max_mse = std::max(max_mse, mse);
sum_mse += mse;
sum_mse += double(mse);
for (size_t j = 0; j < 4; ++j)
{
min_mseV[j] = std::min(min_mseV[j], mseV[j]);
max_mseV[j] = std::max(max_mseV[j], mseV[j]);
sum_mseV[j] += mseV[j];
sum_mseV[j] += double(mseV[j]);
}
++total_images;
@ -3483,13 +3504,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
min_mse = std::min(min_mse, mse);
max_mse = std::max(max_mse, mse);
sum_mse += mse;
sum_mse += double(mse);
for (size_t j = 0; j < 4; ++j)
{
min_mseV[j] = std::min(min_mseV[j], mseV[j]);
max_mseV[j] = std::max(max_mseV[j], mseV[j]);
sum_mseV[j] += mseV[j];
sum_mseV[j] += double(mseV[j]);
}
++total_images;
@ -3508,7 +3529,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
10.0 * log10(3.0 / (double(min_mseV[0]) + double(min_mseV[1]) + double(min_mseV[2]))));
double total_mseV0 = sum_mseV[0] / double(total_images);
double total_mseV1 = sum_mseV[1] / double(total_images);
double total_mseV2 = max_mseV[2] / double(total_images);
double total_mseV2 = sum_mseV[2] / double(total_images);
wprintf(L" Average MSE: %f (%f %f %f %f) PSNR %f dB\n", sum_mse / double(total_images),
total_mseV0,
total_mseV1,
@ -3589,7 +3610,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case TEX_ALPHA_MODE_STRAIGHT:
wprintf(L"Straight");
break;
default:
case TEX_ALPHA_MODE_CUSTOM:
wprintf(L"Custom");
break;
case TEX_ALPHA_MODE_UNKNOWN:
wprintf(L"Unknown");
break;
}
@ -3710,8 +3734,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
if (pixelx >= (int)info.width
|| pixely >= (int)info.height)
if (pixelx >= int(info.width)
|| pixely >= int(info.height))
{
wprintf(L"WARNING: Specified pixel location (%d x %d) is out of range for image (%zu x %zu)\n", pixelx, pixely, info.width, info.height);
continue;