1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-21 12:00:06 +00:00

Constify tools

This commit is contained in:
Chuck Walbourn 2022-03-01 14:31:55 -08:00
parent 44e7464954
commit a8b5aab1c0
6 changed files with 105 additions and 105 deletions

View File

@ -171,7 +171,7 @@ HRESULT LoadAnimatedGif(const wchar_t* szFile, std::vector<std::unique_ptr<Scrat
hr = metareader->GetMetadataByName(L"/logscrdesc/GlobalColorTableFlag", &propValue);
if (SUCCEEDED(hr))
{
bool hasTable = (propValue.vt == VT_BOOL && propValue.boolVal);
const bool hasTable = (propValue.vt == VT_BOOL && propValue.boolVal);
PropVariantClear(&propValue);
if (hasTable)
@ -181,7 +181,7 @@ HRESULT LoadAnimatedGif(const wchar_t* szFile, std::vector<std::unique_ptr<Scrat
{
if (propValue.vt == VT_UI1)
{
uint8_t index = propValue.bVal;
const uint8_t index = propValue.bVal;
if (index < actualColors)
{
@ -387,7 +387,7 @@ HRESULT LoadAnimatedGif(const wchar_t* szFile, std::vector<std::unique_ptr<Scrat
if (!iframe || transparentIndex == -1)
{
Rect fullRect(0, 0, img->width, img->height);
const Rect fullRect(0, 0, img->width, img->height);
hr = CopyRectangle(*img, fullRect, *composedImage, TEX_FILTER_DEFAULT, size_t(rct.left), size_t(rct.top));
if (FAILED(hr))
return hr;

View File

@ -640,7 +640,7 @@ namespace
{
while (pValue->name)
{
size_t cchName = wcslen(pValue->name);
const size_t cchName = wcslen(pValue->name);
if (cch + cchName + 2 >= 80)
{
@ -663,7 +663,7 @@ namespace
wchar_t appName[_MAX_PATH] = {};
if (GetModuleFileNameW(nullptr, appName, static_cast<DWORD>(std::size(appName))))
{
DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
const DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
if (size > 0)
{
auto verInfo = std::make_unique<uint8_t[]>(size);
@ -698,7 +698,7 @@ namespace
LPWSTR errorText = nullptr;
DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
const DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr, static_cast<DWORD>(hr),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);
@ -970,7 +970,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 0;
}
uint32_t dwCommand = LookupByName(argv[1], g_pCommands);
const uint32_t dwCommand = LookupByName(argv[1], g_pCommands);
switch (dwCommand)
{
case CMD_CUBE:
@ -1008,7 +1008,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (*pValue)
*pValue++ = 0;
uint32_t dwOption = LookupByName(pArg, g_pOptions);
const uint32_t dwOption = LookupByName(pArg, g_pOptions);
if (!dwOption || (dwOptions & (1 << dwOption)))
{
@ -1233,7 +1233,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
else if (wcspbrk(pArg, L"?*") != nullptr)
{
size_t count = conversion.size();
const size_t count = conversion.size();
SearchForFiles(pArg, conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0);
if (conversion.size() <= count)
{
@ -1493,7 +1493,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)
@ -1529,7 +1529,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
const Image* img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)
@ -1627,7 +1627,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)
@ -1746,10 +1746,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
XMVECTOR value = inPixels[j];
XMVECTOR scale = XMVectorDivide(
const XMVECTOR scale = XMVectorDivide(
XMVectorAdd(g_XMOne, XMVectorDivide(value, maxLum)),
XMVectorAdd(g_XMOne, value));
XMVECTOR nvalue = XMVectorMultiply(value, scale);
const XMVECTOR nvalue = XMVectorMultiply(value, scale);
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
@ -1921,7 +1921,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
Rect rect(0, 0, width, height);
const Rect rect(0, 0, width, height);
size_t offsetx = 0;
size_t offsety = 0;
@ -2025,8 +2025,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
// Merge with our first source image
const Image& rgb = *loadedImages[0]->GetImage(0, 0, 0);
XMVECTOR zc = XMVectorSelectControl(zeroElements[0], zeroElements[1], zeroElements[2], zeroElements[3]);
XMVECTOR oc = XMVectorSelectControl(oneElements[0], oneElements[1], oneElements[2], oneElements[3]);
const XMVECTOR zc = XMVectorSelectControl(zeroElements[0], zeroElements[1], zeroElements[2], zeroElements[3]);
const XMVECTOR oc = XMVectorSelectControl(oneElements[0], oneElements[1], oneElements[2], oneElements[3]);
ScratchImage result;
hr = TransformImage(rgb, [&, zc, oc](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
@ -2078,8 +2078,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
case CMD_ARRAY_STRIP:
{
size_t twidth = width;
size_t theight = height * images;
const size_t twidth = width;
const size_t theight = height * images;
ScratchImage result;
hr = result.Initialize2D(format, twidth, theight, 1, 1);
@ -2103,9 +2103,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
Rect rect(0, 0, width, height);
const Rect rect(0, 0, width, height);
size_t offsetx = 0;
constexpr size_t offsetx = 0;
size_t offsety = 0;
offsety = index * height;

View File

@ -151,7 +151,7 @@ namespace
if (header->biSizeImage != image.GetPixelsSize())
return E_UNEXPECTED;
size_t remaining = size - filehdr->bfOffBits;
const size_t remaining = size - filehdr->bfOffBits;
if (!remaining)
return E_FAIL;

View File

@ -159,7 +159,7 @@ HRESULT __cdecl LoadFromPortablePixMap(
if (ppmData[0] != 'P' || (ppmData[1] != '3' && ppmData[1] != '6'))
return E_FAIL;
bool ascii = ppmData[1] == '3';
const bool ascii = ppmData[1] == '3';
enum
{
@ -343,7 +343,7 @@ HRESULT __cdecl SaveToPortablePixMap(
}
char header[256] = {};
int len = sprintf_s(header, "P6\n%zu %zu\n255\n", image.width, image.height);
const int len = sprintf_s(header, "P6\n%zu %zu\n255\n", image.width, image.height);
if (len == -1)
return E_UNEXPECTED;
@ -498,14 +498,14 @@ HRESULT __cdecl LoadFromPortablePixMapHDR(
if (sscanf_s(dataStr, "%f%s", &aspectRatio, junkStr, 256) != 1)
return E_FAIL;
bool bigendian = (aspectRatio >= 0);
const bool bigendian = (aspectRatio >= 0);
pData += len + 1;
pfmSize -= len + 1;
if (!pfmSize)
return E_FAIL;
size_t scanline = width * (half16 ? sizeof(uint16_t) : sizeof(float)) * (monochrome ? 1 : 3);
const size_t scanline = width * (half16 ? sizeof(uint16_t) : sizeof(float)) * (monochrome ? 1 : 3);
if (pfmSize < scanline * height)
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
@ -636,7 +636,7 @@ HRESULT __cdecl SaveToPortablePixMapHDR(
}
char header[256] = {};
int len = sprintf_s(header, "P%c\n%zu %zu\n-1.000000\n",
const int len = sprintf_s(header, "P%c\n%zu %zu\n-1.000000\n",
(image.format == DXGI_FORMAT_R32_FLOAT) ? 'f' : 'F',
image.width, image.height);

View File

@ -504,7 +504,7 @@ namespace
using ScopedFindHandle = std::unique_ptr<void, find_closer>;
inline static bool ispow2(size_t x)
constexpr static bool ispow2(size_t x)
{
return ((x != 0) && !(x & (x - 1)));
}
@ -791,7 +791,7 @@ namespace
{
while (pValue->name)
{
size_t cchName = wcslen(pValue->name);
const size_t cchName = wcslen(pValue->name);
if (cch + cchName + 2 >= 80)
{
@ -814,7 +814,7 @@ namespace
wchar_t appName[_MAX_PATH] = {};
if (GetModuleFileNameW(nullptr, appName, static_cast<UINT>(std::size(appName))))
{
DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
const DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
if (size > 0)
{
auto verInfo = std::make_unique<uint8_t[]>(size);
@ -989,7 +989,7 @@ namespace
LPWSTR errorText = nullptr;
DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
const DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr, static_cast<DWORD>(hr),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);
@ -1034,7 +1034,7 @@ namespace
return false;
}
D3D_FEATURE_LEVEL featureLevels[] =
const D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
@ -1112,7 +1112,7 @@ namespace
void FitPowerOf2(size_t origx, size_t origy, _Inout_ size_t& targetx, _Inout_ size_t& targety, size_t maxsize)
{
float origAR = float(origx) / float(origy);
const float origAR = float(origx) / float(origy);
if (origx > origy)
{
@ -1123,7 +1123,7 @@ namespace
float bestScore = FLT_MAX;
for (size_t y = maxsize; y > 0; y >>= 1)
{
float score = fabsf((float(x) / float(y)) - origAR);
const float score = fabsf((float(x) / float(y)) - origAR);
if (score < bestScore)
{
bestScore = score;
@ -1140,7 +1140,7 @@ namespace
float bestScore = FLT_MAX;
for (size_t x = maxsize; x > 0; x >>= 1)
{
float score = fabsf((float(x) / float(y)) - origAR);
const float score = fabsf((float(x) / float(y)) - origAR);
if (score < bestScore)
{
bestScore = score;
@ -1150,7 +1150,7 @@ namespace
}
}
size_t CountMips(_In_ size_t width, _In_ size_t height) noexcept
constexpr size_t CountMips(_In_ size_t width, _In_ size_t height) noexcept
{
size_t mipLevels = 1;
@ -1168,7 +1168,7 @@ namespace
return mipLevels;
}
size_t CountMips3D(_In_ size_t width, _In_ size_t height, _In_ size_t depth) noexcept
constexpr size_t CountMips3D(_In_ size_t width, _In_ size_t height, _In_ size_t depth) noexcept
{
size_t mipLevels = 1;
@ -1238,13 +1238,13 @@ namespace
inline float LinearToST2084(float normalizedLinearValue)
{
float ST2084 = pow((0.8359375f + 18.8515625f * pow(abs(normalizedLinearValue), 0.1593017578f)) / (1.0f + 18.6875f * pow(abs(normalizedLinearValue), 0.1593017578f)), 78.84375f);
const float ST2084 = pow((0.8359375f + 18.8515625f * pow(abs(normalizedLinearValue), 0.1593017578f)) / (1.0f + 18.6875f * pow(abs(normalizedLinearValue), 0.1593017578f)), 78.84375f);
return ST2084; // Don't clamp between [0..1], so we can still perform operations on scene values higher than 10,000 nits
}
inline float ST2084ToLinear(float ST2084)
{
float normalizedLinear = pow(std::max(pow(abs(ST2084), 1.0f / 78.84375f) - 0.8359375f, 0.0f) / (18.8515625f - 18.6875f * pow(abs(ST2084), 1.0f / 78.84375f)), 1.0f / 0.1593017578f);
const float normalizedLinear = pow(std::max(pow(abs(ST2084), 1.0f / 78.84375f) - 0.8359375f, 0.0f) / (18.8515625f - 18.6875f * pow(abs(ST2084), 1.0f / 78.84375f)), 1.0f / 0.1593017578f);
return normalizedLinear;
}
@ -1411,7 +1411,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (*pValue)
*pValue++ = 0;
uint64_t dwOption = LookupByName(pArg, g_pOptions);
const uint64_t dwOption = LookupByName(pArg, g_pOptions);
if (!dwOption || (dwOptions & (uint64_t(1) << dwOption)))
{
@ -1914,7 +1914,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
else if (wcspbrk(pArg, L"?*") != nullptr)
{
size_t count = conversion.size();
const size_t count = conversion.size();
SearchForFiles(pArg, conversion, (dwOptions & (uint64_t(1) << OPT_RECURSIVE)) != 0, nullptr);
if (conversion.size() <= count)
{
@ -2135,7 +2135,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)
@ -2168,7 +2168,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
image.swap(timage);
}
DXGI_FORMAT tformat = (format == DXGI_FORMAT_UNKNOWN) ? info.format : format;
const DXGI_FORMAT tformat = (format == DXGI_FORMAT_UNKNOWN) ? info.format : format;
// --- Decompress --------------------------------------------------------------
std::unique_ptr<ScratchImage> cimage;
@ -2239,7 +2239,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)
@ -2297,7 +2297,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)
@ -2432,7 +2432,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (tMips > 0)
{
size_t maxMips = (info.depth > 1)
const size_t maxMips = (info.depth > 1)
? CountMips3D(info.width, info.height, info.depth)
: CountMips(info.width, info.height);
@ -2455,8 +2455,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
XMVECTOR zc = XMVectorSelectControl(zeroElements[0], zeroElements[1], zeroElements[2], zeroElements[3]);
XMVECTOR oc = XMVectorSelectControl(oneElements[0], oneElements[1], oneElements[2], oneElements[3]);
const XMVECTOR zc = XMVectorSelectControl(zeroElements[0], zeroElements[1], zeroElements[2], zeroElements[3]);
const XMVECTOR oc = XMVectorSelectControl(oneElements[0], oneElements[1], oneElements[2], oneElements[3]);
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&, zc, oc](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
@ -2548,7 +2548,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
UNREFERENCED_PARAMETER(y);
XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
const XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
for (size_t j = 0; j < w; ++j)
{
@ -2585,7 +2585,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
XMVECTOR value = inPixels[j];
XMVECTOR nvalue = XMVector3Transform(value, c_from709to2020);
const XMVECTOR nvalue = XMVector3Transform(value, c_from709to2020);
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
@ -2600,7 +2600,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
UNREFERENCED_PARAMETER(y);
XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
const XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
for (size_t j = 0; j < w; ++j)
{
@ -2637,7 +2637,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
XMVECTOR value = inPixels[j];
XMVECTOR nvalue = XMVector3Transform(value, c_from2020to709);
const XMVECTOR nvalue = XMVector3Transform(value, c_from2020to709);
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
@ -2652,7 +2652,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
UNREFERENCED_PARAMETER(y);
XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
const XMVECTOR paperWhite = XMVectorReplicate(paperWhiteNits);
for (size_t j = 0; j < w; ++j)
{
@ -2689,7 +2689,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
XMVECTOR value = inPixels[j];
XMVECTOR nvalue = XMVector3Transform(value, c_fromP3D65to2020);
const XMVECTOR nvalue = XMVector3Transform(value, c_fromP3D65to2020);
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
@ -2708,7 +2708,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
XMVECTOR value = inPixels[j];
XMVECTOR nvalue = XMVector3Transform(value, c_from709toP3D65);
const XMVECTOR nvalue = XMVector3Transform(value, c_from709toP3D65);
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
@ -2727,7 +2727,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
XMVECTOR value = inPixels[j];
XMVECTOR nvalue = XMVector3Transform(value, c_fromP3D65to709);
const XMVECTOR nvalue = XMVector3Transform(value, c_fromP3D65to709);
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
@ -2811,10 +2811,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
XMVECTOR value = inPixels[j];
XMVECTOR scale = XMVectorDivide(
const XMVECTOR scale = XMVectorDivide(
XMVectorAdd(g_XMOne, XMVectorDivide(value, maxLum)),
XMVectorAdd(g_XMOne, value));
XMVECTOR nvalue = XMVectorMultiply(value, scale);
const XMVECTOR nvalue = XMVectorMultiply(value, scale);
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
@ -3010,9 +3010,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
const XMVECTOR value = inPixels[j];
XMVECTOR inverty = XMVectorSubtract(g_XMOne, value);
const XMVECTOR inverty = XMVectorSubtract(g_XMOne, value);
outPixels[j] = XMVectorSelect(value, inverty, s_selecty);
}
@ -3061,7 +3061,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
const XMVECTOR value = inPixels[j];
XMVECTOR z;
if (isunorm)
@ -3315,7 +3315,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)
@ -3378,7 +3378,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)
@ -3499,7 +3499,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
PrintInfo(info);
wprintf(L"\n");
@ -3523,7 +3523,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
continue;
}
auto err = static_cast<DWORD>(SHCreateDirectoryExW(nullptr, szPath, nullptr));
auto const err = static_cast<DWORD>(SHCreateDirectoryExW(nullptr, szPath, nullptr));
if (err != ERROR_SUCCESS && err != ERROR_ALREADY_EXISTS)
{
wprintf(L" directory creation FAILED (%08X%ls)\n",
@ -3619,12 +3619,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
default:
{
WICCodecs codec = (FileType == CODEC_HDP || FileType == CODEC_JXR) ? WIC_CODEC_WMP : static_cast<WICCodecs>(FileType);
size_t nimages = (dwOptions & (uint64_t(1) << OPT_WIC_MULTIFRAME)) ? nimg : 1;
const WICCodecs codec = (FileType == CODEC_HDP || FileType == CODEC_JXR) ? WIC_CODEC_WMP : static_cast<WICCodecs>(FileType);
const size_t nimages = (dwOptions & (uint64_t(1) << OPT_WIC_MULTIFRAME)) ? nimg : 1;
hr = SaveToWICFile(img, nimages, WIC_FLAGS_NONE, GetWICCodec(codec), szDest, nullptr,
[&](IPropertyBag2* props)
{
bool wicLossless = (dwOptions & (uint64_t(1) << OPT_WIC_LOSSLESS)) != 0;
const bool wicLossless = (dwOptions & (uint64_t(1) << OPT_WIC_LOSSLESS)) != 0;
switch (FileType)
{
@ -3716,7 +3716,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
LARGE_INTEGER qpcEnd = {};
std::ignore = QueryPerformanceCounter(&qpcEnd);
LONGLONG delta = qpcEnd.QuadPart - qpcStart.QuadPart;
const LONGLONG delta = qpcEnd.QuadPart - qpcStart.QuadPart;
wprintf(L"\n Processing time: %f seconds\n", double(delta) / double(qpcFreq.QuadPart));
}

View File

@ -598,7 +598,7 @@ namespace
{
while (pValue->name)
{
size_t cchName = wcslen(pValue->name);
const size_t cchName = wcslen(pValue->name);
if (cch + cchName + 2 >= 80)
{
@ -621,7 +621,7 @@ namespace
wchar_t appName[_MAX_PATH] = {};
if (GetModuleFileNameW(nullptr, appName, static_cast<DWORD>(std::size(appName))))
{
DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
const DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
if (size > 0)
{
auto verInfo = std::make_unique<uint8_t[]>(size);
@ -701,7 +701,7 @@ namespace
LPWSTR errorText = nullptr;
DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
const DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr, static_cast<DWORD>(hr),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);
@ -877,7 +877,7 @@ namespace
for (size_t x = 0; x < width; ++x)
{
XMVECTOR v = *pixels++;
const XMVECTOR v = *pixels++;
luminance = XMVectorMax(luminance, XMVector3Dot(v, s_luminance));
minv = XMVectorMin(minv, v);
maxv = XMVectorMax(maxv, v);
@ -917,7 +917,7 @@ namespace
XMStoreFloat4(&result.imageMin, minv);
XMStoreFloat4(&result.imageMax, maxv);
XMVECTOR pixelv = XMVectorReplicate(float(totalPixels));
const XMVECTOR pixelv = XMVectorReplicate(float(totalPixels));
XMVECTOR avgv = XMVectorDivide(acc, pixelv);
XMStoreFloat4(&result.imageAvg, avgv);
@ -930,9 +930,9 @@ namespace
for (size_t x = 0; x < width; ++x)
{
XMVECTOR v = *pixels++;
const XMVECTOR v = *pixels++;
XMVECTOR diff = XMVectorSubtract(v, avgv);
const XMVECTOR diff = XMVectorSubtract(v, avgv);
acc = XMVectorMultiplyAdd(diff, diff, acc);
}
});
@ -941,7 +941,7 @@ namespace
XMStoreFloat4(&result.imageVariance, acc);
XMVECTOR stddev = XMVectorSqrt(acc);
const XMVECTOR stddev = XMVectorSqrt(acc);
XMStoreFloat4(&result.imageStdDev, stddev);
@ -1446,14 +1446,14 @@ namespace
ScratchImage diffImage;
HRESULT hr = TransformImage(*imageA, [&](XMVECTOR* outPixels, const XMVECTOR * inPixels, size_t width, size_t y)
{
XMVECTOR tolerance = XMVectorReplicate(threshold);
const XMVECTOR tolerance = XMVectorReplicate(threshold);
auto *inPixelsB = reinterpret_cast<XMVECTOR*>(imageB->pixels + (y*imageB->rowPitch));
for (size_t x = 0; x < width; ++x)
{
XMVECTOR v1 = *inPixels++;
XMVECTOR v2 = *inPixelsB++;
const XMVECTOR v2 = *inPixelsB++;
v1 = XMVectorSubtract(v1, v2);
v1 = XMVectorAbs(v1);
@ -1567,9 +1567,9 @@ namespace
void Print565(uint16_t rgb)
{
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));
auto const r = float(((rgb >> 11) & 31) * (1.0f / 31.0f));
auto const g = float(((rgb >> 5) & 63) * (1.0f / 63.0f));
auto const b = float(((rgb >> 0) & 31) * (1.0f / 31.0f));
wprintf(L"(R: %.3f, G: %.3f, B: %.3f)", r, g, b);
}
@ -1906,7 +1906,7 @@ namespace
};
static_assert(sizeof(bc6h_mode1) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode1*>(sptr);
@ -1982,7 +1982,7 @@ namespace
};
static_assert(sizeof(bc6h_mode2) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode2*>(sptr);
@ -2059,7 +2059,7 @@ namespace
};
static_assert(sizeof(bc6h_mode3) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode3*>(sptr);
@ -2136,7 +2136,7 @@ namespace
};
static_assert(sizeof(bc6h_mode4) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode4*>(sptr);
@ -2211,7 +2211,7 @@ namespace
};
static_assert(sizeof(bc6h_mode5) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode5*>(sptr);
@ -2285,7 +2285,7 @@ namespace
};
static_assert(sizeof(bc6h_mode6) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode6*>(sptr);
@ -2359,7 +2359,7 @@ namespace
};
static_assert(sizeof(bc6h_mode7) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode7*>(sptr);
@ -2435,7 +2435,7 @@ namespace
};
static_assert(sizeof(bc6h_mode8) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode8*>(sptr);
@ -2511,7 +2511,7 @@ namespace
};
static_assert(sizeof(bc6h_mode9) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode9*>(sptr);
@ -2587,7 +2587,7 @@ namespace
};
static_assert(sizeof(bc6h_mode10) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode10*>(sptr);
@ -2647,7 +2647,7 @@ namespace
};
static_assert(sizeof(bc6h_mode11) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode11*>(sptr);
@ -2694,7 +2694,7 @@ namespace
};
static_assert(sizeof(bc6h_mode12) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode12*>(sptr);
@ -2745,7 +2745,7 @@ namespace
};
static_assert(sizeof(bc6h_mode13) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode13*>(sptr);
@ -2808,7 +2808,7 @@ namespace
};
static_assert(sizeof(bc6h_mode14) == 16, "Block size must be 16 bytes");
bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false;
auto m = reinterpret_cast<const bc6h_mode14*>(sptr);
@ -3062,7 +3062,7 @@ namespace
wprintf(L"\t A1:(%0.3f)\n", float(m->a1) / 63.f);
wprintf(L"\t Colors: ");
uint64_t color_index = uint64_t(m->color_index) | uint64_t(m->color_indexn << 14);
const uint64_t color_index = uint64_t(m->color_index) | uint64_t(m->color_indexn << 14);
if (m->idx)
PrintIndex3bpp(color_index, 0, 0);
else
@ -3238,7 +3238,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 0;
}
uint32_t dwCommand = LookupByName(argv[1], g_pCommands);
const uint32_t dwCommand = LookupByName(argv[1], g_pCommands);
switch (dwCommand)
{
case CMD_INFO:
@ -3271,7 +3271,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (*pValue)
*pValue++ = 0;
uint32_t dwOption = LookupByName(pArg, g_pOptions);
const uint32_t dwOption = LookupByName(pArg, g_pOptions);
if (!dwOption || (dwOptions & (1 << dwOption)))
{
@ -3446,7 +3446,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
else if (wcspbrk(pArg, L"?*") != nullptr)
{
size_t count = conversion.size();
const size_t count = conversion.size();
SearchForFiles(pArg, conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0);
if (conversion.size() <= count)
{
@ -3716,9 +3716,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
wprintf(L"\n Minimum MSE: %f (%f %f %f %f) PSNR %f dB\n", min_mse, min_mseV[0], min_mseV[1], min_mseV[2], min_mseV[3],
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 = sum_mseV[2] / double(total_images);
const double total_mseV0 = sum_mseV[0] / double(total_images);
const double total_mseV1 = sum_mseV[1] / double(total_images);
const 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,
@ -3809,7 +3809,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wprintf(L"\n images = %zu\n", image->GetImageCount());
auto sizeInKb = static_cast<uint32_t>(image->GetPixelsSize() / 1024);
auto const sizeInKb = static_cast<uint32_t>(image->GetPixelsSize() / 1024);
wprintf(L" pixel size = %u (KB)\n\n", sizeInKb);
}
@ -4021,7 +4021,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
auto img = image->GetImage(0, 0, 0);
assert(img);
size_t nimg = image->GetImageCount();
const size_t nimg = image->GetImageCount();
std::unique_ptr<ScratchImage> timage(new (std::nothrow) ScratchImage);
if (!timage)