From 1dec86435dc0b79cd5dd29fee024372e94c9ee92 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Wed, 14 Sep 2016 00:21:44 -0700 Subject: [PATCH] Code review feedback --- DirectXTex/DirectXTex.h | 7 +++++-- DirectXTex/DirectXTexPMAlpha.cpp | 14 ++++++-------- Texconv/texconv.cpp | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index 8e59c9b..57db489 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -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 diff --git a/DirectXTex/DirectXTexPMAlpha.cpp b/DirectXTex/DirectXTexPMAlpha.cpp index ae6717c..b82492d 100644 --- a/DirectXTex/DirectXTexPMAlpha.cpp +++ b/DirectXTex/DirectXTexPMAlpha.cpp @@ -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); } diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 334bfb6..aec3517 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -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);