Compresses an image or set of images to a block-compressed (BC) format.

HRESULT Compress( _In_ const Image& srcImage, _In_ DXGI_FORMAT format,
    _In_ DWORD compress, _In_ float alphaRef,
    _Out_ ScratchImage& cImage );

HRESULT Compress( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef,
    _Out_ ScratchImage& cImages );

HRESULT Compress( _In_ ID3D11Device* pDevice, _In_ const Image& srcImage,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight,
    _Out_ ScratchImage& image );

HRESULT Compress( _In_ ID3D11Device* pDevice,
    _In_ const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight,
    _Out_ ScratchImage& cImages );

Parameters

device: The DirectCompute based versions of Compress require a Direct3D 11 device with Feature Level 10.0 or greater that supports DirectCompute.

format: Format to compress to. Must be a BC compressed format (i.e. DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB - DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM_SRGB)

Note that the DirectCompute based versions of Compress only support DXGI_FORMAT_BC6H_UF16, DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_BC7_UNORM, and DXGI_FORMAT_BC7_UNORM_SRGB

compress: Compress control flags

alphaRef: Threshold reference value when compressing an alpha channel for BC1 formats which support 1-bit transparency. (0 to 1 range)

alphaWeight: Used to weight the error metric's alpha computation for the BC7 GPU compressor. Use 1.0 for default, or a larger number to improve alpha accuracy potentially at the expense of the color channels.

Related flags

TEX_COMPRESS_DEFAULT Default flags.

Dithering

  • TEX_COMPRESS_RGB_DITHER Enables dithering RGB colors for BC1-3 compression
  • TEX_COMPRESS_A_DITHER Enables dithering alpha channel for BC1-3 compression
  • TEX_COMPRESS_DITHER Same as TEX_COMPRESS_RGB_DITHER and TEX_COMPRESS_A_DITHER

Weighting

  • TEX_COMPRESS_UNIFORM By default, BC1-3 uses a perceptual weighting. By using this flag, the perceptual weighting is disabled which can be useful when using the RGB channels for other data.

Threading

  • TEX_COMPRESS_PARALLEL This opts-in to multi-threaded compression if enabled.

Color space

  • TEX_COMPRESS_SRGB_IN Indicates the input format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_COMPRESS_SRGB_OUT Indicates the output format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_COMPRESS_SRGB This is the same as setting both TEX_COMPRESS_SRGB_IN and TEX_COMPRESS_SRGB_OUT

The sRGB color space overall is approximately equivalent to gamma 2.2. It's actually linear below a threshold, and gamma 2.4 beyond that.
http://en.wikipedia.org/wiki/SRGB

BC7

  • TEX_COMPRESS_BC7_USE_3SUBSETS Indicates that BC7 compression should use the 3 subset modes (mode 0 and 2). Otherwise it skips these to improve compression performance.

Example

ScratchImage srcImage;

...

ScratchImage bcImage;
hr = Compress( srcImage.GetImages(), srcImage.GetImageCount(), srcImage.GetMetadata(), DXGI_FORMAT_BC3_UNORM, TEX_COMPRESS_DEFAULT, 0.5f, bcImage );
if ( FAILED(hr) )
    ...

Remarks

By default, the BC1 - BC3 color encoding algorithms will use a perceptual weighting of the Red and Blue channels which usually gives better visual results for standard color textures. For textures that do not contain color data, you will likely want to use TEX_COMPRESS_UNIFORM to disable the perceptual weighting.

When compressing for BC4, only the RED channel in the original image is used. When compressing for BC5, only the RED and GREEN channels are used.

The DirectXTex library functions allow arbitrary sized images to handle non-power-of-2 mipmapped BC textures. Note that Direct3D will not allow a resource to be created using BC format with the top-level size set to something other than a multiple of 4 in width and height, even though it does allow the mipchain below it to not meet that requirement. In other words, the library allows some textures to be compressed that are not actually valid on Direct3D 11.

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.

Release Notes

The software based encoder for BC6H and BC7 is computationally expensive and can be quite slow. The DirectCompute based encoder which is much faster has been integrated into the DirectXTex library, but the standalone version is also available http://code.msdn.microsoft.com/BC6HBC7-DirectCompute-35e8884a

Threading

The CPU-based compressor will use all cores on a system if given TEX_COMPRESS_PARALLEL for the BC6H / BC7 CPU codec.

The DirectCompute GPU-based compressor makes use of the device's immediate context.

Related Links

http://msdn.microsoft.com/en-us/library/bb204843.aspx
http://msdn.microsoft.com/en-us/library/bb694531.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/hh308955.aspx
http://en.wikipedia.org/wiki/S3_Texture_Compression
http://en.wikipedia.org/wiki/3Dc
http://developer.download.nvidia.com/opengl/specs/GL_ARB_texture_compression_bptc.txt

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