mirror of
https://github.com/microsoft/DirectXTex.git
synced 2026-02-08 22:06:13 +01:00
ComputePitch now returns an HRESULT (#113)
This commit is contained in:
@@ -686,7 +686,9 @@ HRESULT DirectX::_EncodeDDSHeader(
|
||||
}
|
||||
|
||||
size_t rowPitch, slicePitch;
|
||||
ComputePitch(metadata.format, metadata.width, metadata.height, rowPitch, slicePitch, CP_FLAGS_NONE);
|
||||
HRESULT hr = ComputePitch(metadata.format, metadata.width, metadata.height, rowPitch, slicePitch, CP_FLAGS_NONE);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
if (slicePitch > UINT32_MAX
|
||||
|| rowPitch > UINT32_MAX)
|
||||
@@ -1140,7 +1142,9 @@ namespace
|
||||
}
|
||||
|
||||
size_t pixelSize, nimages;
|
||||
_DetermineImageArray(metadata, cpFlags, nimages, pixelSize);
|
||||
if (!_DetermineImageArray(metadata, cpFlags, nimages, pixelSize))
|
||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||
|
||||
if ((nimages == 0) || (nimages != image.GetImageCount()))
|
||||
{
|
||||
return E_FAIL;
|
||||
@@ -1741,6 +1745,12 @@ HRESULT DirectX::LoadFromDDSFile(
|
||||
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
|
||||
}
|
||||
|
||||
if (image.GetPixelsSize() > UINT32_MAX)
|
||||
{
|
||||
image.Release();
|
||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||
}
|
||||
|
||||
if (!ReadFile(hFile.get(), image.GetPixels(), static_cast<DWORD>(image.GetPixelsSize()), &bytesRead, nullptr))
|
||||
{
|
||||
image.Release();
|
||||
@@ -1797,7 +1807,9 @@ HRESULT DirectX::SaveToDDSMemory(
|
||||
return E_FAIL;
|
||||
|
||||
size_t ddsRowPitch, ddsSlicePitch;
|
||||
ComputePitch(metadata.format, images[i].width, images[i].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
hr = ComputePitch(metadata.format, images[i].width, images[i].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
assert(images[i].rowPitch > 0);
|
||||
assert(images[i].slicePitch > 0);
|
||||
@@ -1868,7 +1880,12 @@ HRESULT DirectX::SaveToDDSMemory(
|
||||
else
|
||||
{
|
||||
size_t ddsRowPitch, ddsSlicePitch;
|
||||
ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
blob.Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
size_t rowPitch = images[index].rowPitch;
|
||||
|
||||
@@ -1937,7 +1954,12 @@ HRESULT DirectX::SaveToDDSMemory(
|
||||
else
|
||||
{
|
||||
size_t ddsRowPitch, ddsSlicePitch;
|
||||
ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
blob.Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
size_t rowPitch = images[index].rowPitch;
|
||||
|
||||
@@ -2049,9 +2071,11 @@ HRESULT DirectX::SaveToDDSFile(
|
||||
assert(images[index].slicePitch > 0);
|
||||
|
||||
size_t ddsRowPitch, ddsSlicePitch;
|
||||
ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
if (images[index].slicePitch == ddsSlicePitch)
|
||||
if ((images[index].slicePitch == ddsSlicePitch) && (ddsSlicePitch <= UINT32_MAX))
|
||||
{
|
||||
if (!WriteFile(hFile.get(), images[index].pixels, static_cast<DWORD>(ddsSlicePitch), &bytesWritten, nullptr))
|
||||
{
|
||||
@@ -2072,6 +2096,9 @@ HRESULT DirectX::SaveToDDSFile(
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (ddsRowPitch > UINT32_MAX)
|
||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||
|
||||
const uint8_t * __restrict sPtr = images[index].pixels;
|
||||
|
||||
size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
||||
@@ -2117,9 +2144,11 @@ HRESULT DirectX::SaveToDDSFile(
|
||||
assert(images[index].slicePitch > 0);
|
||||
|
||||
size_t ddsRowPitch, ddsSlicePitch;
|
||||
ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
if (images[index].slicePitch == ddsSlicePitch)
|
||||
if ((images[index].slicePitch == ddsSlicePitch) && (ddsSlicePitch <= UINT32_MAX))
|
||||
{
|
||||
if (!WriteFile(hFile.get(), images[index].pixels, static_cast<DWORD>(ddsSlicePitch), &bytesWritten, nullptr))
|
||||
{
|
||||
@@ -2140,6 +2169,9 @@ HRESULT DirectX::SaveToDDSFile(
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (ddsRowPitch > UINT32_MAX)
|
||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||
|
||||
const uint8_t * __restrict sPtr = images[index].pixels;
|
||||
|
||||
size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
||||
|
||||
Reference in New Issue
Block a user