mirror of
https://github.com/microsoft/DirectXTex.git
synced 2025-07-09 19:50:13 +02:00
texconv: Ensure mipslevel is valid when resizing
This commit is contained in:
parent
52a02b5556
commit
66ffe6e882
@ -1060,6 +1060,45 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t CountMips(_In_ size_t width, _In_ size_t height) noexcept
|
||||||
|
{
|
||||||
|
size_t mipLevels = 1;
|
||||||
|
|
||||||
|
while (height > 1 || width > 1)
|
||||||
|
{
|
||||||
|
if (height > 1)
|
||||||
|
height >>= 1;
|
||||||
|
|
||||||
|
if (width > 1)
|
||||||
|
width >>= 1;
|
||||||
|
|
||||||
|
++mipLevels;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mipLevels;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t CountMips3D(_In_ size_t width, _In_ size_t height, _In_ size_t depth) noexcept
|
||||||
|
{
|
||||||
|
size_t mipLevels = 1;
|
||||||
|
|
||||||
|
while (height > 1 || width > 1 || depth > 1)
|
||||||
|
{
|
||||||
|
if (height > 1)
|
||||||
|
height >>= 1;
|
||||||
|
|
||||||
|
if (width > 1)
|
||||||
|
width >>= 1;
|
||||||
|
|
||||||
|
if (depth > 1)
|
||||||
|
depth >>= 1;
|
||||||
|
|
||||||
|
++mipLevels;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mipLevels;
|
||||||
|
}
|
||||||
|
|
||||||
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 =
|
const XMMATRIX c_from709to2020 =
|
||||||
@ -2321,6 +2360,18 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
|
|
||||||
image.swap(timage);
|
image.swap(timage);
|
||||||
cimage.reset();
|
cimage.reset();
|
||||||
|
|
||||||
|
if (tMips > 0)
|
||||||
|
{
|
||||||
|
size_t maxMips = (info.depth > 1)
|
||||||
|
? CountMips3D(info.width, info.height, info.depth)
|
||||||
|
: CountMips(info.width, info.height);
|
||||||
|
|
||||||
|
if (tMips > maxMips)
|
||||||
|
{
|
||||||
|
tMips = maxMips;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Swizzle (if requested) --------------------------------------------------
|
// --- Swizzle (if requested) --------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user