mirror of
https://github.com/microsoft/DirectXTex.git
synced 2025-07-13 21:50:13 +02:00
Code review feedback for TGA
This commit is contained in:
parent
bfa3a11aee
commit
13e90f900f
@ -117,14 +117,14 @@ namespace
|
|||||||
|
|
||||||
enum CONVERSION_FLAGS
|
enum CONVERSION_FLAGS
|
||||||
{
|
{
|
||||||
CONV_FLAGS_NONE = 0x0,
|
CONV_FLAGS_NONE = 0x0,
|
||||||
CONV_FLAGS_EXPAND = 0x1, // Conversion requires expanded pixel size
|
CONV_FLAGS_EXPAND = 0x1, // Conversion requires expanded pixel size
|
||||||
CONV_FLAGS_INVERTX = 0x2, // If set, scanlines are right-to-left
|
CONV_FLAGS_INVERTX = 0x2, // If set, scanlines are right-to-left
|
||||||
CONV_FLAGS_INVERTY = 0x4, // If set, scanlines are top-to-bottom
|
CONV_FLAGS_INVERTY = 0x4, // If set, scanlines are top-to-bottom
|
||||||
CONV_FLAGS_RLE = 0x8, // Source data is RLE compressed
|
CONV_FLAGS_RLE = 0x8, // Source data is RLE compressed
|
||||||
|
|
||||||
CONV_FLAGS_SWIZZLE = 0x10000, // Swizzle BGR<->RGB data
|
CONV_FLAGS_SWIZZLE = 0x10000, // Swizzle BGR<->RGB data
|
||||||
CONV_FLAGS_888 = 0x20000, // 24bpp format
|
CONV_FLAGS_888 = 0x20000, // 24bpp format
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -284,18 +284,11 @@ namespace
|
|||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
|
||||||
// Compute TGA image data pitch
|
// Compute TGA image data pitch
|
||||||
size_t rowPitch;
|
size_t rowPitch, slicePitch;
|
||||||
if (convFlags & CONV_FLAGS_EXPAND)
|
HRESULT hr = ComputePitch(image->format, image->width, image->height, rowPitch, slicePitch,
|
||||||
{
|
(convFlags & CONV_FLAGS_EXPAND) ? CP_FLAGS_24BPP : CP_FLAGS_NONE);
|
||||||
rowPitch = image->width * 3;
|
if (FAILED(hr))
|
||||||
}
|
return hr;
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t slicePitch;
|
|
||||||
HRESULT hr = ComputePitch(image->format, image->width, image->height, rowPitch, slicePitch, CP_FLAGS_NONE);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto sPtr = static_cast<const uint8_t*>(pSource);
|
auto sPtr = static_cast<const uint8_t*>(pSource);
|
||||||
const uint8_t* endPtr = sPtr + size;
|
const uint8_t* endPtr = sPtr + size;
|
||||||
@ -454,7 +447,7 @@ namespace
|
|||||||
if (maxalpha == 0)
|
if (maxalpha == 0)
|
||||||
{
|
{
|
||||||
opaquealpha = true;
|
opaquealpha = true;
|
||||||
HRESULT hr = SetAlphaChannelToOpaque(image);
|
hr = SetAlphaChannelToOpaque(image);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -599,7 +592,7 @@ namespace
|
|||||||
if (maxalpha == 0)
|
if (maxalpha == 0)
|
||||||
{
|
{
|
||||||
opaquealpha = true;
|
opaquealpha = true;
|
||||||
HRESULT hr = SetAlphaChannelToOpaque(image);
|
hr = SetAlphaChannelToOpaque(image);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -634,18 +627,11 @@ namespace
|
|||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
|
||||||
// Compute TGA image data pitch
|
// Compute TGA image data pitch
|
||||||
size_t rowPitch;
|
size_t rowPitch, slicePitch;
|
||||||
if (convFlags & CONV_FLAGS_EXPAND)
|
HRESULT hr = ComputePitch(image->format, image->width, image->height, rowPitch, slicePitch,
|
||||||
{
|
(convFlags & CONV_FLAGS_EXPAND) ? CP_FLAGS_24BPP : CP_FLAGS_NONE);
|
||||||
rowPitch = image->width * 3;
|
if (FAILED(hr))
|
||||||
}
|
return hr;
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t slicePitch;
|
|
||||||
HRESULT hr = ComputePitch(image->format, image->width, image->height, rowPitch, slicePitch, CP_FLAGS_NONE);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto sPtr = static_cast<const uint8_t*>(pSource);
|
auto sPtr = static_cast<const uint8_t*>(pSource);
|
||||||
const uint8_t* endPtr = sPtr + size;
|
const uint8_t* endPtr = sPtr + size;
|
||||||
@ -719,7 +705,7 @@ namespace
|
|||||||
if (maxalpha == 0)
|
if (maxalpha == 0)
|
||||||
{
|
{
|
||||||
opaquealpha = true;
|
opaquealpha = true;
|
||||||
HRESULT hr = SetAlphaChannelToOpaque(image);
|
hr = SetAlphaChannelToOpaque(image);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -787,7 +773,7 @@ namespace
|
|||||||
if (maxalpha == 0)
|
if (maxalpha == 0)
|
||||||
{
|
{
|
||||||
opaquealpha = true;
|
opaquealpha = true;
|
||||||
HRESULT hr = SetAlphaChannelToOpaque(image);
|
hr = SetAlphaChannelToOpaque(image);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -1480,17 +1466,10 @@ HRESULT DirectX::SaveToTGAMemory(const Image& image, Blob& blob, const TexMetada
|
|||||||
|
|
||||||
// Determine memory required for image data
|
// Determine memory required for image data
|
||||||
size_t rowPitch, slicePitch;
|
size_t rowPitch, slicePitch;
|
||||||
if (convFlags & CONV_FLAGS_888)
|
hr = ComputePitch(image.format, image.width, image.height, rowPitch, slicePitch,
|
||||||
{
|
(convFlags & CONV_FLAGS_888) ? CP_FLAGS_24BPP : CP_FLAGS_NONE);
|
||||||
rowPitch = image.width * 3;
|
if (FAILED(hr))
|
||||||
slicePitch = image.height * rowPitch;
|
return hr;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hr = ComputePitch(image.format, image.width, image.height, rowPitch, slicePitch, CP_FLAGS_NONE);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = blob.Initialize(sizeof(TGA_HEADER)
|
hr = blob.Initialize(sizeof(TGA_HEADER)
|
||||||
+ slicePitch
|
+ slicePitch
|
||||||
@ -1585,28 +1564,10 @@ HRESULT DirectX::SaveToTGAFile(const Image& image, const wchar_t* szFile, const
|
|||||||
|
|
||||||
// Determine size for TGA pixel data
|
// Determine size for TGA pixel data
|
||||||
size_t rowPitch, slicePitch;
|
size_t rowPitch, slicePitch;
|
||||||
if (convFlags & CONV_FLAGS_888)
|
hr = ComputePitch(image.format, image.width, image.height, rowPitch, slicePitch,
|
||||||
{
|
(convFlags & CONV_FLAGS_888) ? CP_FLAGS_24BPP : CP_FLAGS_NONE);
|
||||||
uint64_t pitch = uint64_t(image.width) * 3u;
|
if (FAILED(hr))
|
||||||
uint64_t slice = uint64_t(image.height) * pitch;
|
return hr;
|
||||||
|
|
||||||
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
|
||||||
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
|
||||||
if (pitch > UINT32_MAX || slice > UINT32_MAX)
|
|
||||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
|
||||||
#else
|
|
||||||
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rowPitch = static_cast<size_t>(pitch);
|
|
||||||
slicePitch = static_cast<size_t>(slice);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hr = ComputePitch(image.format, image.width, image.height, rowPitch, slicePitch, CP_FLAGS_NONE);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slicePitch < 65535)
|
if (slicePitch < 65535)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user