mirror of
https://github.com/microsoft/DirectXTex.git
synced 2026-02-04 04:16:12 +01:00
Constify tools
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user