Code review feedback

This commit is contained in:
Chuck Walbourn 2016-09-12 12:01:48 -07:00
parent 7275893dbe
commit 481fe3afe0
3 changed files with 36 additions and 0 deletions

View File

@ -192,7 +192,10 @@ HRESULT DirectX::FlipRotate(
const Image *rimage = image.GetImage(0, 0, 0);
if (!rimage)
{
image.Release();
return E_POINTER;
}
WICPixelFormatGUID pfGUID;
if (_DXGIToWIC(srcImage.format, pfGUID))

View File

@ -31,6 +31,7 @@
// we support only that one as that's what other Radiance parsing code does as well.
//
//Uncomment to disable the use of adapative RLE encoding when writing an HDR. Used for testing only.
//#define DISABLE_COMPRESS
using namespace DirectX;
@ -503,6 +504,11 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
size_t pixelLen = remaining;
const Image* img = image.GetImage(0, 0, 0);
if (!img)
{
image.Release();
return E_POINTER;
}
auto destPtr = img->pixels;
@ -530,6 +536,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
// Adaptive Run Length Encoding (RLE)
if (size_t((inColor[2] << 8) + inColor[3]) != mdata.width)
{
image.Release();
return E_FAIL;
}
@ -540,6 +547,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
{
if (pixelLen < 2)
{
image.Release();
return E_FAIL;
}
@ -551,6 +559,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
runLen &= 127;
if (pixelCount + runLen > mdata.width)
{
image.Release();
return E_FAIL;
}
@ -566,6 +575,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
}
else if ((size < size_t(runLen + 1)) || ((pixelCount + runLen) > mdata.width))
{
image.Release();
return E_FAIL;
}
else
@ -602,6 +612,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
size_t spanLen = inColor[3] << bitShift;
if (spanLen + pixelCount > mdata.width)
{
image.Release();
return E_FAIL;
}
@ -633,6 +644,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
if (pixelLen < 4)
{
image.Release();
return E_FAIL;
}
@ -794,7 +806,10 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob)
#else
std::unique_ptr<uint8_t[]> temp(new (std::nothrow) uint8_t[rowPitch * 2]);
if (!temp)
{
blob.Release();
return E_OUTOFMEMORY;
}
auto rgbe = temp.get();
auto enc = temp.get() + rowPitch;
@ -821,7 +836,10 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob)
hr = blob.Trim(dPtr - reinterpret_cast<uint8_t*>(blob.GetBufferPointer()));
if (FAILED(hr))
{
blob.Release();
return hr;
}
return S_OK;
}

View File

@ -1076,11 +1076,17 @@ HRESULT DirectX::LoadFromTGAFile(
assert(image.GetImageCount() == 1);
const Image* img = image.GetImage(0, 0, 0);
if (!img)
{
image.Release();
return E_POINTER;
}
uint8_t *pPixels = img->pixels;
if (!pPixels)
{
image.Release();
return E_POINTER;
}
size_t rowPitch = img->rowPitch;
@ -1128,14 +1134,20 @@ HRESULT DirectX::LoadFromTGAFile(
assert(image.GetImageCount() == 1);
const Image* img = image.GetImage(0, 0, 0);
if (!img)
{
image.Release();
return E_POINTER;
}
// Scan for non-zero alpha channel
bool nonzeroa = false;
const uint8_t *pPixels = img->pixels;
if (!pPixels)
{
image.Release();
return E_POINTER;
}
size_t rowPitch = img->rowPitch;
@ -1165,7 +1177,10 @@ HRESULT DirectX::LoadFromTGAFile(
{
hr = SetAlphaChannelToOpaque(img);
if (FAILED(hr))
{
image.Release();
return hr;
}
}
}
break;