mirror of
https://github.com/microsoft/DirectXTex.git
synced 2025-07-09 11:40:14 +02:00
PremultiplyAlpha fix to avoid divide-by-zero
This commit is contained in:
parent
53b8522394
commit
1c6f993963
@ -124,7 +124,10 @@ namespace
|
|||||||
{
|
{
|
||||||
XMVECTOR v = *ptr;
|
XMVECTOR v = *ptr;
|
||||||
XMVECTOR alpha = XMVectorSplatW(*ptr);
|
XMVECTOR alpha = XMVectorSplatW(*ptr);
|
||||||
alpha = XMVectorDivide(v, alpha);
|
if (XMVectorGetX(alpha) > 0)
|
||||||
|
{
|
||||||
|
alpha = XMVectorDivide(v, alpha);
|
||||||
|
}
|
||||||
*(ptr++) = XMVectorSelect(v, alpha, g_XMSelect1110);
|
*(ptr++) = XMVectorSelect(v, alpha, g_XMSelect1110);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,9 +146,9 @@ namespace
|
|||||||
assert(srcImage.width == destImage.width);
|
assert(srcImage.width == destImage.width);
|
||||||
assert(srcImage.height == destImage.height);
|
assert(srcImage.height == destImage.height);
|
||||||
|
|
||||||
static_assert(static_cast<int>(TEX_PMALPHA_SRGB_IN) == static_cast<int>(TEX_FILTER_SRGB_IN), "TEX_PMALHPA_SRGB* should match TEX_FILTER_SRGB*");
|
static_assert(static_cast<int>(TEX_PMALPHA_SRGB_IN) == static_cast<int>(TEX_FILTER_SRGB_IN), "TEX_PMALPHA_SRGB* should match TEX_FILTER_SRGB*");
|
||||||
static_assert(static_cast<int>(TEX_PMALPHA_SRGB_OUT) == static_cast<int>(TEX_FILTER_SRGB_OUT), "TEX_PMALHPA_SRGB* should match TEX_FILTER_SRGB*");
|
static_assert(static_cast<int>(TEX_PMALPHA_SRGB_OUT) == static_cast<int>(TEX_FILTER_SRGB_OUT), "TEX_PMALPHA_SRGB* should match TEX_FILTER_SRGB*");
|
||||||
static_assert(static_cast<int>(TEX_PMALPHA_SRGB) == static_cast<int>(TEX_FILTER_SRGB), "TEX_PMALHPA_SRGB* should match TEX_FILTER_SRGB*");
|
static_assert(static_cast<int>(TEX_PMALPHA_SRGB) == static_cast<int>(TEX_FILTER_SRGB), "TEX_PMALPHA_SRGB* should match TEX_FILTER_SRGB*");
|
||||||
flags &= TEX_PMALPHA_SRGB;
|
flags &= TEX_PMALPHA_SRGB;
|
||||||
|
|
||||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
||||||
@ -167,7 +170,10 @@ namespace
|
|||||||
{
|
{
|
||||||
XMVECTOR v = *ptr;
|
XMVECTOR v = *ptr;
|
||||||
XMVECTOR alpha = XMVectorSplatW(*ptr);
|
XMVECTOR alpha = XMVectorSplatW(*ptr);
|
||||||
alpha = XMVectorDivide(v, alpha);
|
if (XMVectorGetX(alpha) > 0)
|
||||||
|
{
|
||||||
|
alpha = XMVectorDivide(v, alpha);
|
||||||
|
}
|
||||||
*(ptr++) = XMVectorSelect(v, alpha, g_XMSelect1110);
|
*(ptr++) = XMVectorSelect(v, alpha, g_XMSelect1110);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user