This converts an image assuming the original is not using premultiplied alpha into a premultiplied alpha version of the same image. The format and size are not changed.

Breaking Change notice: The 'flags' parameter was not present in the August 2013 and previous versions of DirectXTex.

HRESULT PremultiplyAlpha( _In_ const Image& srcImage, _In_ DWORD flags,
    _Out_ ScratchImage& image );

HRESULT PremultiplyAlpha( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata, _In_ DWORD flags,
    _Out_ ScratchImage& result );

Parameters

flags: Combination of options to apply
  • PMALPHA_IGNORE_SRGB Ignore any sRGB colorspace conversions

This controls color space transformation for conversions.
  • TEX_PMALPHA_SRGB_IN Indicates the input format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_PMALPHA_SRGB_OUT Indicates the output format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_PMALPHA_SRGB This is the same as setting both TEX_PMALPHA_SRGB_IN and TEX_PMALPHA_SRGB_OUT

Example

ScratchImage srcImage;

...

ScratchImage destImage;
hr = PremultiplyAlpha( srcImage.GetImages(), srcImage.GetImageCount(), srcImage.GetMetadata(), TEX_PMALPHA_DEFAULT, destImage );
if ( FAILED(hr) )
    ...

Remarks

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 DirectXTK).

Related Links

http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx
http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BPremultiplied%20alpha%5D%5D
http://ssp.impulsetrain.com/2011-08-10_Gamma_Correction_vs__Premultiplied_Pixels.html

Last edited Jun 22, 2015 at 6:30 AM by walbourn, version 5