This commit is contained in:
Chuck Walbourn 2016-09-14 00:21:44 -07:00
Родитель a30c37220b
Коммит 1dec86435d
3 изменённых файлов: 12 добавлений и 11 удалений

Просмотреть файл

@ -483,6 +483,9 @@ namespace DirectX
TEX_PMALPHA_IGNORE_SRGB = 0x1,
// ignores sRGB colorspace conversions
TEX_PMALPHA_REVERSE = 0x2,
// converts from premultiplied alpha back to straight alpha
TEX_PMALPHA_SRGB_IN = 0x1000000,
TEX_PMALPHA_SRGB_OUT = 0x2000000,
TEX_PMALPHA_SRGB = ( TEX_PMALPHA_SRGB_IN | TEX_PMALPHA_SRGB_OUT ),
@ -490,9 +493,9 @@ namespace DirectX
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
};
HRESULT __cdecl PremultiplyAlpha( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image, bool reverse = false );
HRESULT __cdecl PremultiplyAlpha( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image );
HRESULT __cdecl PremultiplyAlpha( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
_In_ DWORD flags, _Out_ ScratchImage& result, bool reverse = false);
_In_ DWORD flags, _Out_ ScratchImage& result );
// Converts to/from a premultiplied alpha version of the texture
enum TEX_COMPRESS_FLAGS

Просмотреть файл

@ -198,8 +198,7 @@ _Use_decl_annotations_
HRESULT DirectX::PremultiplyAlpha(
const Image& srcImage,
DWORD flags,
ScratchImage& image,
bool reverse)
ScratchImage& image)
{
if (!srcImage.pixels)
return E_POINTER;
@ -225,7 +224,7 @@ HRESULT DirectX::PremultiplyAlpha(
return E_POINTER;
}
if (reverse)
if (flags & TEX_PMALPHA_REVERSE)
{
hr = (flags & TEX_PMALPHA_IGNORE_SRGB) ? DemultiplyAlpha(srcImage, *rimage) : DemultiplyAlphaLinear(srcImage, flags, *rimage);
}
@ -252,8 +251,7 @@ HRESULT DirectX::PremultiplyAlpha(
size_t nimages,
const TexMetadata& metadata,
DWORD flags,
ScratchImage& result,
bool reverse)
ScratchImage& result)
{
if (!srcImages || !nimages)
return E_INVALIDARG;
@ -268,11 +266,11 @@ HRESULT DirectX::PremultiplyAlpha(
if ((metadata.width > UINT32_MAX) || (metadata.height > UINT32_MAX))
return E_INVALIDARG;
if (metadata.IsPMAlpha() != reverse)
if (metadata.IsPMAlpha() != ((flags & TEX_PMALPHA_REVERSE) != 0))
return E_FAIL;
TexMetadata mdata2 = metadata;
mdata2.SetAlphaMode(reverse ? TEX_ALPHA_MODE_STRAIGHT : TEX_ALPHA_MODE_PREMULTIPLIED);
mdata2.SetAlphaMode((flags & TEX_PMALPHA_REVERSE) ? TEX_ALPHA_MODE_STRAIGHT : TEX_ALPHA_MODE_PREMULTIPLIED);
HRESULT hr = result.Initialize(mdata2);
if (FAILED(hr))
return hr;
@ -311,7 +309,7 @@ HRESULT DirectX::PremultiplyAlpha(
return E_FAIL;
}
if (reverse)
if (flags & TEX_PMALPHA_REVERSE)
{
hr = (flags & TEX_PMALPHA_IGNORE_SRGB) ? DemultiplyAlpha(src, dst) : DemultiplyAlphaLinear(src, flags, dst);
}

Просмотреть файл

@ -1557,7 +1557,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
hr = PremultiplyAlpha(img, nimg, info, dwSRGB, *timage, true);
hr = PremultiplyAlpha(img, nimg, info, TEX_PMALPHA_REVERSE | dwSRGB, *timage);
if (FAILED(hr))
{
wprintf(L" FAILED [demultiply alpha] (%x)\n", hr);