-
Notifications
You must be signed in to change notification settings - Fork 465
PremultiplyAlpha
| DirectXTex |
|---|
This converts an image to using premultiplied alpha. The format and size are not changed.
Note that the conversion to premultipled alpha is not fully reversible. For example if alpha is 0, then all the color information becomes 0.
HRESULT PremultiplyAlpha( const Image& srcImage, TEX_PMALPHA_FLAGS flags,
ScratchImage& image );
HRESULT PremultiplyAlpha( const Image* srcImages, size_t nimages,
const TexMetadata& metadata, TEX_PMALPHA_FLAGS flags,
ScratchImage& result );Breaking Change notice: The flags parameter was not present in the August 2013 and previous versions of DirectXTex.
flags: Combination of options to apply
-
PMALPHA_IGNORE_SRGBIgnore any sRGB colorspace conversions -
TEX_PMALPHA_REVERSEIf set to true, then the conversion goes from premultipled alpha to nonpremultipled alpha (a.k.a. straight alpha).
This controls color space transformation for conversions.
-
TEX_PMALPHA_SRGB_INIndicates the input format is the sRGB format. This is implied if using aDXGI_FORMAT_*_SRGBformat -
TEX_PMALPHA_SRGB_OUTIndicates the output format is the sRGB format. This is implied if using aDXGI_FORMAT_*_SRGBformat -
TEX_PMALPHA_SRGBThis is the same as setting bothTEX_PMALPHA_SRGB_INandTEX_PMALPHA_SRGB_OUT
These functions will succeed with an S_OK or will return an HRESULT error code (E_INVALIDARG, E_OUTOFMEMORY, E_FAIL, E_POINTER, HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), or HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)).
These functions are marked noexcept, and do not throw C++ exceptions.
This function does not operate directly on block compressed images. See Decompress and Compress.
This function cannot operate directly on a planar format image. See ConvertToSinglePlane for a method for converting planar data to a format that is supported by this routine.
This is most useful for working with rendering that relies on premultiplied alpha blending (see DirectX Tool Kit for DX11 / DX12).
ScratchImage srcImage;
...
ScratchImage destImage;
hr = PremultiplyAlpha( srcImage.GetImages(), srcImage.GetImageCount(),
srcImage.GetMetadata(), TEX_PMALPHA_DEFAULT, destImage );
if ( FAILED(hr) )
...Premultiplied alpha
Premultiplied alpha and image composition
Premultiplied alpha in XNA Game Studio 4.0
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Xbox One
- Xbox Series X|S
- Windows Subsystem for Linux
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v20
- GCC 10.5, 11.4, 12.3, 13.3, 14.2
- MinGW 12.2, 13.2
- CMake 3.21
DirectX Tool Kit for DirectX 11