APPLETEXTURECONVERTER(3) Library Functions Manual APPLETEXTURECONVERTER(3)

AppleTextureConverter — compress, decompress and compare GPU textures

Static library libAppleTextureConverter.a (-lAppleTextureConverter)

#include <AppleTextureConverter.h>

bool
ATC_InitialiseDefaultOptions(ATC_Options *options);

const ATC_CompressorInfo *
ATC_QueryCompressorInfo(const ATC_Context *context, ATC_Compressor compressor);

ATC_Error
ATC_CreateTexture2D(const ATC_Context *context, uint32_t width, uint32_t height, uint32_t numMipLevels, ATC_Format format, ATC_ColorGamut colorGamut, bool isNormalMap, const ATC_Texture **texture);

ATC_Error
ATC_CreateTexture2DArray(const ATC_Context *context, uint32_t width, uint32_t height, uint32_t elements, uint32_t numMipLevels, ATC_Format format, ATC_ColorGamut colorGamut, bool isNormalMap, const ATC_Texture **texture);

ATC_Error
ATC_CreateTexture3D(const ATC_Context *context, uint32_t width, uint32_t height, uint32_t depth, uint32_t numMipLevels, ATC_Format format, ATC_ColorGamut colorGamut, bool isNormalMap, const ATC_Texture **texture);

ATC_Error
ATC_CreateTextureCube(const ATC_Context *context, uint32_t size, uint32_t numMipLevels, ATC_Format format, ATC_ColorGamut colorGamut, bool isNormalMap, const ATC_Texture **texture);

ATC_Error
ATC_DeleteTexture(const ATC_Context *context, const ATC_Texture *texture, bool freeSurfaces);

ATC_Error
ATC_GetSurface(const ATC_Context *context, const ATC_Texture *texture, uint32_t elementOrFace, uint32_t mipLevel, ATC_Surface **pSurface);

ATC_Error
ATC_CompressMemory(const ATC_Context *context, const ATC_Texture *sourceTex, const ATC_Texture **destTex, const ATC_Options *options);

ATC_Error
ATC_CompressFile(const ATC_Context *context, const char *sourceFile, const char *destFile, const ATC_Options *options);

ATC_Error
ATC_DecompressMemory(const ATC_Context *context, const ATC_Texture *sourceTex, const ATC_Texture **destTex, const ATC_Options *options);

ATC_Error
ATC_DecompressFile(const ATC_Context *context, const char *sourceFile, const char *destFile, const ATC_Options *options);

ATC_Error
ATC_CompareMemory(const ATC_Context *context, const ATC_Texture *refImage, const ATC_Texture *compImage, const ATC_Options *options, ATC_ErrorMetrics *metrics);

ATC_Error
ATC_CompareFile(const ATC_Context *context, const char *refFile, const char *compFile, const ATC_Options *options, ATC_ErrorMetrics *metrics);

AppleTextureConverter provides a simple API for compressing, decompressing & comparing textures. Textures can be either in memory or from file. For example usage check below.

Every function takes an optional ATC_Context that supplies the memory allocator, the message callback and a user-data pointer; pass NULL for the defaults. Operations are configured with an ATC_Options structure: initialise it with (), then set the fields to change. A field that a TextureConverter(1) option sets lists that option.

This page describes API version 5 (ATC_API_VER) of the library shipped with TextureConverter 5.2.240000. The API can change between versions in ways that break source compatibility.

bool (ATC_Options *options);

Initialise ATC_Options to default options. Use of ATC_InitialiseDefaultOptions is optional and may be skipped if you set all the parameters explicitly.

options
Pointer to the ATC_Options struct to initialise.

const ATC_CompressorInfo * (const ATC_Context *context, ATC_Compressor compressor);

Query the capabilties & options supported for a given compressor.

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
compressor
Compressor ID to query.

ATC_Error (const ATC_Context *context, uint32_t width, uint32_t height, uint32_t numMipLevels, ATC_Format format, ATC_ColorGamut colorGamut, bool isNormalMap, const ATC_Texture **texture);

Create a 2D Texture

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
width
Width of the texture. Must be greater than zero & not greater than atcMaxExtent.
height
Height of the texture. Must be greater than zero & not greater than atcMaxExtent.
numMipLevels
Number of mip-levels. Must not exceed atcMaxMipMaps, nor the full chain down to 1x1 (3D: 1x1x1).
format
Format of the texture.
colorGamut
Color gamut of the texture, sRGB or DisplayP3 if it is a color. Must be atcColorGamutNone for normal maps.
isNormalMap
Texture is a normal map.
texture
(Out) Pointer to the created texture.

ATC_Error (const ATC_Context *context, uint32_t width, uint32_t height, uint32_t elements, uint32_t numMipLevels, ATC_Format format, ATC_ColorGamut colorGamut, bool isNormalMap, const ATC_Texture **texture);

Create a 2D Texture Array

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
width
Width of the texture. Must be greater than zero & not greater than atcMaxExtent.
height
Height of the texture. Must be greater than zero & not greater than atcMaxExtent.
elements
Number of elements. Must be greater than one & not greater than atcMaxElements.
numMipLevels
Number of mip-levels. Must not exceed atcMaxMipMaps, nor the full chain down to 1x1 (3D: 1x1x1).
format
Format of the texture.
colorGamut
Color gamut of the texture, sRGB or DisplayP3 if it is a color. Must be atcColorGamutNone for normal maps.
isNormalMap
Texture is a normal map.
texture
(Out) Pointer to the created texture.

ATC_Error (const ATC_Context *context, uint32_t width, uint32_t height, uint32_t depth, uint32_t numMipLevels, ATC_Format format, ATC_ColorGamut colorGamut, bool isNormalMap, const ATC_Texture **texture);

Create a 3D Texture

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
width
Width of the texture. Must be greater than zero & not greater than atcMaxExtent.
height
Height of the texture. Must be greater than zero & not greater than atcMaxExtent.
depth
Depth of the texture. Must be greater than one & not greater than atcMaxDepth.
numMipLevels
Number of mip-levels. Must not exceed atcMaxMipMaps, nor the full chain down to 1x1 (3D: 1x1x1).
format
Format of the texture.
colorGamut
Color gamut of the texture, sRGB or DisplayP3 if it is a color. Must be atcColorGamutNone for normal maps.
isNormalMap
Texture is a normal map.
texture
(Out) Pointer to the created texture.

ATC_Error (const ATC_Context *context, uint32_t size, uint32_t numMipLevels, ATC_Format format, ATC_ColorGamut colorGamut, bool isNormalMap, const ATC_Texture **texture);

Create a Cubemap Texture

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
size
Width & Height of the cube faces. Must be greater than zero & not greater than atcMaxExtent.
numMipLevels
Number of mip-levels. Must not exceed atcMaxMipMaps, nor the full chain down to 1x1 (3D: 1x1x1).
format
Format of the texture.
colorGamut
Color gamut of the texture, sRGB or DisplayP3 if it is a color. Must be atcColorGamutNone for normal maps.
isNormalMap
Texture is a normal map.
texture
(Out) Address of the created texture pointer.

ATC_Error (const ATC_Context *context, const ATC_Texture *texture, bool freeSurfaces);

Free the memory used for a texture through the ATC_MemoryDeallocator function defined in ATC_Context.

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
texture
Pointer to the ATC_Texture to delete.
freeSurfaces
Bool indicating whether to also free the memory allocatted for surface data.

ATC_Error (const ATC_Context *context, const ATC_Texture *texture, uint32_t elementOrFace, uint32_t mipLevel, ATC_Surface **pSurface);

Retrieve a pointer to the specified surface.

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
texture
Pointer to the ATC_Texture .
elementOrFace
The element, face or slice of the texture to access, depending on the texture type.
mipLevel
The mip-level of the texture to access.
pSurface
(Out) Address of the surface pointer.

ATC_Error (const ATC_Context *context, const ATC_Texture *sourceTex, const ATC_Texture **destTex, const ATC_Options *options);

Compress texture from memory to memory. Destination memory will be allocated using the ATC_MemoryAllocator function defined in ATC_Context.

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
sourceTex
Pointer to the source texture. The source texture must be an uncompressed format.
destTex
(Out) Pointer to the destination texture created by this function.
options
Pointer to the options defining how to compress the texture. Must not be NULL (atcErrorInvalidOptions).

ATC_Error (const ATC_Context *context, const char *sourceFile, const char *destFile, const ATC_Options *options);

Compress texture from file to file.

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
sourceFile
File path for the source texture. The source texture must be an uncompressed format.
destFile
File path for the destination texture. On success the destination is overwritten; on atcErrorUnsupportedFormatForFile, atcErrorSourceFileNotFound or atcErrorCannotCreateDestFile destFile is left untouched (no zero-byte file is created).
options
Pointer to the options defining how to compress the texture. Must not be NULL (atcErrorInvalidOptions).

ATC_Error (const ATC_Context *context, const ATC_Texture *sourceTex, const ATC_Texture **destTex, const ATC_Options *options);

Decompress texture from memory to memory. Destination memory will be allocated using the ATC_MemoryAllocator function defined in ATC_Context.

Single-channel decode contract (applies equally to ATC_DecompressFile below): single-channel COLOR formats — R8 (unorm/srgb), R16F, R32F, and the compressed 1-channel formats BC4 (unorm/snorm) and EAC_R11 (unorm/snorm) — decompress to the red-only convention: the stored channel lands in R and TC writes G=0, B=0, A=1 into the destination RGBA buffer. A8 likewise decompresses to (R,0,0,1) on every container (TC treats its single byte as a red value). This describes the bytes TC writes into the destination surface; it is not a Metal/Vulkan/D3D sampling-swizzle guarantee (e.g. Vulkan VK_FORMAT_A8 samples as (0,0,0,A)).

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
sourceTex
Pointer to the source texture. The source texture must be a compressed format.
destTex
(Out) Pointer to the destination texture created by this function.
options
Pointer to the options defining how to decompress the texture. Must not be NULL (atcErrorInvalidOptions).

ATC_Error (const ATC_Context *context, const char *sourceFile, const char *destFile, const ATC_Options *options);

Decompress texture from file to file.

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
sourceFile
File path for the source texture. The source texture must be a compressed format.
destFile
File path for the destination texture. On success the destination is overwritten; on atcErrorUnsupportedFormatForFile, atcErrorSourceFileNotFound or atcErrorCannotCreateDestFile destFile is left untouched (no zero-byte file is created).
options
Pointer to the options defining how to decompress the texture. Must not be NULL (atcErrorInvalidOptions).

ATC_Error (const ATC_Context *context, const ATC_Texture *refImage, const ATC_Texture *compImage, const ATC_Options *options, ATC_ErrorMetrics *metrics);

Compare two in-memory textures.

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
refImage
Pointer to the reference texture.
compImage
Pointer to the comparison texture.
options
Pointer to the options defining how to compare the textures. Must not be NULL (atcErrorInvalidOptions).
metrics
Pointer to the ATC_ErrorMetrics. ATC_CompareMemory will populate this struct. Must not be NULL (atcErrorInvalidDestTexture).

ATC_Error (const ATC_Context *context, const char *refFile, const char *compFile, const ATC_Options *options, ATC_ErrorMetrics *metrics);

Compare two texture files.

context
(Optional) Pointer to an ATC_Context object. If null a default context is used.
refFile
File path for the reference texture.
compFile
File path for the comparison texture.
options
Pointer to the options defining how to compare the textures. Must not be NULL (atcErrorInvalidOptions).
metrics
Pointer to the ATC_ErrorMetrics. ATC_CompareFile will populate this struct. Must not be NULL (atcErrorInvalidDestTexture).

typedef void *(*ATC_MemoryAllocator)(void *userData, size_t size);

Callback function for allocating memory. Returns a pointer to the allocated memory.

These callbacks are used for any client-owned ATC_Texture the API returns: the memory-to-memory operations (ATC_CompressMemory / ATC_DecompressMemory / ATC_ConvertMemory) and ATC_LoadFile allocate their returned texture's surfaces through this callback, and the caller frees them with memoryDeallocator via ATC_DeleteTexture. ATC_CompressFile / ATC_DecompressFile stream their result to disk and never invoke the callback; all internal working buffers use an internal allocator. The default allocator (used when none is supplied) is malloc/free.

userData
User-defined value from the ATC_Context.
size
Size of memory to allocate.

typedef void (*ATC_MemoryDeallocator)(void *userData, void *data);

Callback function for deallocating memory

userData
User-defined value from the ATC_Context.
data
Pointer to the memory to de-allocate.

typedef void (*ATC_MessageCallback)(void *userData, ATC_InfoLevel level, const char *string);

Callback function for feedback from AppleTextureConverter operations.

userData
User-defined value from the ATC_Context.
level
Severity level of the feedback info.
string
String text of the feedback info.

Struct declaring the compression/decompression context

ATC_MemoryAllocator memoryAllocator
(Optional) Memory allocator function to use. If set memoryDeallocator must also be set.
ATC_MemoryDeallocator memoryDeallocator
(Optional) Memory deallocator function to be use.
ATC_MessageCallback infoMessageHandler
(Optional) Call back for info/warning/error text. If not set will default to stdout/stderr.
void* userData
(Optional) User-data value passed to callback functions.

Options to define how to perform operations.

ATC_Compressor compressor
The compressor to use while compressing. Set by --compressor.
ATC_Decompressor decompressor
The decompressor to use while decompressing. Will also be used compare operations if decompression is required.
ATC_Format format
Texture format for the destination texture. Set by --compression_format, --format.
ATC_Quality quality
Quality level to use while compressing. Set by --compression_quality.
ATC_AlphaMode alphaMode
Alpha mode for compression. Set by --alpha_mode.
bool useAlphaToCoverage
Use alpha to coverage when compressing. Set by --alpha_to_coverage.
float alphaReference
Alpha reference for useAlphaToCoverage. Set by --alpha_reference.
bool useAlphaWeight
Use alpha weight when compressing. Set by --alpha_weight.
bool isGammaInSrgb
Source texture is sRGB encoded. If false gammaIn must be set. Set by --gamma_in.
bool isGammaOutSrgb
Dest texture should be sRGB encoded. If false gammaOut must be set. Set by --gamma_out.
float gammaIn
Gamma level for the source texture if isGammaInSrgb == false. Set by --gamma_in.
float gammaOut
Gamma level the dest texture if isGammaOutSrgb == false. Set by --gamma_out.
ATC_ColorGamut colorGamutIn
Color space for the source texture. Set by --gamut_in.
ATC_ColorGamut colorGamutOut
Color space for the dest texture. This is only supported on MacOS and should be set to atcColorGamutUnknown on other platforms. On MacOS color gamut will be converted from input to output as necessary. Set by --gamut_in, --gamut_out.
uint32_t maxMipmaps
Number of mip-levels to compress/decompress/compare. If 0 the level count for the source image is used. Set by --max_mipmaps.
ATC_MipmapFilter mipmapFilter
Mip-filter to use when generating mipmaps before compression. Set by --mipmap_filter.
uint32_t maxExtent
Maximum texture extent. Textures will be downsized to fit before compression. Set by --max_extent.
ATC_RoundMode resizeRoundMode
Resize rounding mode to use if resizing before compression. Set by --resize_round_mode.
ATC_ResizeFilter resizeFilter
Filter used when downsizing to maxExtent before compression. Set by --resize_filter.
ATC_WrapMode wrapMode
Wrap mode to use when generating mipmaps or resizing the source texture. Set by --wrap_mode.
bool useRgbmEncoding
Compress to/decompress from RGBM encoding (RGB scaled by a factor M stored in the 4th channel). When compressing or converting, format must store at least 4 bits of alpha (not BC1, BGRX8, ETC2_RGB8A1, BGR5A1, RGB10A2/BGR10A2 or PVRTC RGBA), otherwise atcErrorInvalidOptions. Can not be combined with isNormalMap (atcErrorInvalidOptions). Set by --rgbm_encoding.
float rgbmRange
Range to use for RGBm encoding. Set by --rgbm_range.
bool cropUniformContent
Crop the source texture to remove uniform content before compressing. Set by --crop_uniform_content.
bool disableMultithreading
Disable multi-threading of compression, pixel-format conversion, mipmap generation and resizing. Set by --disable_multithreading.
bool flipX
Flip the source texture along the X axis before compressing. Set by --flip_x.
bool flipY
Flip the source texture along the Y axis before compressing. Set by --flip_y.
bool flipZ
Flip the source texture along the Z axis before compressing. Set by --flip_z.
bool isNormalMap
Use normal-map encoding for a tangent-space normal map. X/Y are stored in the channels each format encodes best and Z is reconstructed as sqrt(1-X^2-Y^2) on decompress (which returns X,Y,Z,1): ASTC stores X in RGB and Y in alpha; BC3 stores X in alpha and Y in green; BC5/EAC_RG11 store X,Y in red,green. BC5 is recommended. Set by --normal_map.
bool scaleRange
Scale the source texture to the entire color range before compressing. Set by --scale_range.
bool useSrgbFormat
Use sRGB pixel format for the dest texture. Set by --srgb_format.
bool isASTCHDR
The source format of an ASTC KTX texture should be treated as ASTC HDR. Set by --ASTC_HDR.
ATC_FileFormat fileFormat
File format to use for the destination texture. Set by --file_format.
bool disableAnnotation
Disable annotation when writing KTX files. Set by --disable_annotation.

Compression options used only when compressing with the atcCompressorPVRTC compressor.

ATC_ChannelWeighting channelWeighting
Channel weightings to use when compressing. Set by --channel_weighting.
ATC_PVRPunchThrough pvrtcPunchThroughMode
PVRTC punch-through mode to use when compressing. Set by --pvrtc_punch_through.
uint32_t comparisonChannels
Number of channels to consider when comparing textures. Defaults to 3. 0 is treated as 1; values above the textures' own channel count are clamped to it.
bool advancedMetrics
Compute the expensive metrics (SSIM, MS-SSIM, angular error). Defaults to false. Set by --advanced_metrics.

Top-level texture.

uint32_t width
Width of the texture. Must be greater than zero & not greater than atcMaxExtent.
uint32_t height
Height of the texture. Must be greater than zero & not greater than atcMaxExtent.
uint32_t numMipLevels
Number of mip-levels. Must not exceed atcMaxMipMaps, nor the full chain down to 1x1 (3D: 1x1x1).
uint32_t depth
Depth of the texture for 3D textures. Must be greater than zero & not greater than atcMaxDepth.
uint32_t elements
Number of elements for 2D texture arrays. Must be greater than zero & not greater than atcMaxElements.
ATC_TextureType type
Type of texture (2D, Cube, etc).
ATC_Format format
Format of the texture.
ATC_ColorGamut colorGamut
Color gamut of the texture, sRGB or DisplayP3 if it is a color. Must be atcColorGamutNone for normal maps.
bool isNormalMap
Texture is a tangent-space normal map. X/Y are stored in the channels each format encodes best and Z is reconstructed as sqrt(1-X^2-Y^2) on decompress (which returns X,Y,Z,1): ASTC stores X in RGB and Y in alpha; BC3 stores X in alpha and Y in green; BC5/EAC_RG11 store X,Y in red,green. Gamut must be atcColorGamutNone.
uint32_t surfaceCount
Total number of surfaces. A hand-built source texture must supply at least as many as its shape needs (one per face/element/slice per mip, in ATC_GetSurface index order); the *Memory APIs reject a short count with atcErrorInvalidSourceTexture.
ATC_Surface* surfaces
Pointer to an array of ATC_Surface structures. Use the ATC_GetSurface function to access surfaces. Must not be NULL on a source texture (atcErrorInvalidSourceTexture).

Per-surface (mip-level-face) data.

uint32_t width
(Optional) Width of the surface. If zero this will be calculated based on ATC_Texture & mip-level.
uint32_t height
(Optional) Height of the surface. If zero this will be calculated based on ATC_Texture & mip-level.
uint32_t rowBytes
(Optional) Width of the surface rows in bytes. If zero this will be calculated based on ATC_Texture & mip-level. For compressed formats this is the bytes per row of blocks (blocksWide * bytesPerBlock); the *Memory APIs (ATC_CompressMemory / ATC_DecompressMemory / ATC_ConvertMemory) and ATC_LoadFile populate it on returned surfaces so it can be fed to e.g. MTLTexture replaceRegion (exception: Metal requires bytesPerRow=0 for PVRTC). Zero is also accepted on input, and is the initial value on ATC_CreateTexture2D/2DArray/3D/Cube surfaces.
void* data
Pointer to the surface data.
uint32_t size
Size of the surface data in bytes.

Error metrics returned by ATC_Compare functions. Note: for LDR sources MSE/RMS/PSNR are reported on the [0,255] scale. For HDR sources (half-float / F32) the reference scale is the per-image absolute peak, and for RGBM encoding it is options.rgbmRange — so PSNR is content-dependent for those inputs.

SSIM, MS-SSIM, Flip and the angular-error fields are populated only when options.advancedMetrics is set (they are expensive — roughly 10x the MSE/RMS/PSNR cost; see the CLI --advanced_metrics flag); otherwise they are NaN. MS-SSIM is additionally NaN for non-LDR or <11px inputs, and the angular fields are NaN unless options.isNormalMap and the comparison has >= 3 channels.

double MSE
Mean square error.
double RMS
Root mean square error.
double PSNR
Peak signal-to-noise ratio.
bool bTexturesAreIdentical
The textures compared are identical.
double SSIM
Single-scale block SSIM (advancedMetrics; NaN otherwise).
double MSSSIM
Multi-scale SSIM (advancedMetrics + LDR >=11px; NaN otherwise).
double angularErrorMean
Mean normal angular error in degrees (advancedMetrics + normal map).
double angularErrorP95
95th-percentile angular error in degrees.
double angularErrorMax
Max angular error in degrees.
double angularErrorRms
RMS angular error in degrees.
double flipMean
FLIP / HDR-FLIP mean per-pixel error in [0,1] (advancedMetrics; NaN otherwise).
double flipP95
95th-percentile FLIP error (advancedMetrics; NaN otherwise).
double flipMax
Maximum FLIP error (advancedMetrics; NaN otherwise).

Struct describing compressor capabilities & options.

uint32_t numFormats
Number of compressed formats supported by the compressor.
ATC_Format* formats
Array of compressed formats supported by the compressor.
uint32_t numQualityLevels
Number of quality levels supported by the compressor.
ATC_Quality* qualityLevels
Array of quality levels supported by the compressor.
bool Flags.isThreadSafe
True if the compressor has been verifed to be thread-safe
bool Flags.isMultithreaded
True if the compressor is itself multi-threaded

Undefined format

Uncompressed formats. These are the source formats for compression operations and the destination formats for decompression operations. Names list the components from the lowest byte (or, for packed formats, the lowest bits) up, as Metal names its pixel formats: Rgba8Unorm holds R in byte 0, like MTLPixelFormatRGBA8Unorm, and Rgb10A2Unorm holds R in bits 9:0, like MTLPixelFormatRGB10A2Unorm.

1-channel, 8 bits-per-pixel, unsigned
1-channel, 16 bits-per-pixel, half-float
1-channel, 32 bits-per-pixel, float
2-channel, 16 bits-per-pixel, unsigned
2-channel, 32 bits-per-pixel, half-float
2-channel, 64 bits-per-pixel, float
RGB, 24 bits-per-pixel, unsigned
RGB, 48 bits-per-pixel, half-float
RGB, 96 bits-per-pixel, float
RGBA, 32 bits-per-pixel, unsigned
RGBA, 32 bits-per-pixel, signed normalized
RGBA, 32 bits-per-pixel, signed integer
RGBA, 32 bits-per-pixel, unsigned integer
RGBA, 64 bits-per-pixel, signed normalized 16-bit
RGBA, 64 bits-per-pixel, unsigned normalized 16-bit
RGBA, 64 bits-per-pixel, signed integer 16-bit
RGBA, 64 bits-per-pixel, unsigned integer 16-bit
RGBA, 64 bits-per-pixel, half-float
RGBA, 128 bits-per-pixel, float
BGRA, 32 bits-per-pixel, unsigned
BGRX, 32 bits-per-pixel, unsigned (opaque, alpha ignored)
Alpha, 8 bits-per-pixel, unsigned

16-bit packed formats. Each holds the Metal layout of the same name: MTLPixelFormatB5G6R5Unorm, MTLPixelFormatBGR5A1Unorm and MTLPixelFormatABGR4Unorm. Side note: Vulkan *_PACK16 and D3D9 formats are named from the high bits down, so the same layouts are VK_FORMAT_R5G6B5_UNORM_PACK16 / D3DFMT_R5G6B5, VK_FORMAT_A1R5G5B5_UNORM_PACK16 / D3DFMT_A1R5G5B5 and VK_FORMAT_R4G4B4A4_UNORM_PACK16. Before ATC_API_VER 5, atcFormatAbgr4Unorm was atcFormatBgra4Unorm, and all three stored B in the high bits (the Vulkan B*_PACK16 layouts).

ABGR4, 16 bits-per-pixel, 4 bits per channel, unsigned; A in bits 3:0, B in 7:4, G in 11:8, R in 15:12 (MTLPixelFormatABGR4Unorm)
B5G6R5, 16 bits-per-pixel, unsigned; B in bits 4:0, G in 10:5, R in 15:11 (MTLPixelFormatB5G6R5Unorm)
BGR5A1, 16 bits-per-pixel, unsigned; B in bits 4:0, G in 9:5, R in 14:10, A in bit 15 (MTLPixelFormatBGR5A1Unorm)
RGB10A2, 32 bits-per-pixel, unsigned normalized
RGB10A2, 32 bits-per-pixel, signed normalized
RGB10A2, 32 bits-per-pixel, signed integer
RGB10A2, 32 bits-per-pixel, unsigned integer
BGR10A2, 32 bits-per-pixel, unsigned normalized
BGR10A2, 32 bits-per-pixel, signed normalized
BGR10A2, 32 bits-per-pixel, signed integer
BGR10A2, 32 bits-per-pixel, unsigned integer

Compressed formats. These are the destination formats for compression operations and the sourceFile formats for decompression operations.

BC (aka DXTC) compression formats.

BC1 (DXT1) - 4x4, 4 bits-per-pixel - RGB with optional 1 bit alpha
BC2 (DXT2/DXT3) - 4x4, 8 bits-per-pixel - RGBA, explicit alpha
BC3 (DXT4/DXT5) - 4x4, 8 bits-per-pixel - RGBA, interpolated alpha
BC4 - 4x4, 4 bits-per-pixel, 1-channel, signed
BC4 - 4x4, 4 bits-per-pixel, 1-channel, unsigned
BC5 - 4x4, 8 bits-per-pixel, 2-channel, signed
BC5 - 4x4, 8 bits-per-pixel, 2-channel, unsigned
BC6S - RGB 4x4, 8 bits-per-pixel HDR, signed
BC6U - RGB 4x4, 8 bits-per-pixel HDR, unsigned
BC7 - RGB/RGBA 4x4, 8 bits-per-pixel LDR

ASTC compression formats. All ASTC formats take 16 bytes per block. Smaller block dimensions provide higher quality for lower compression-rates, higher block dimensions provide lower quality for higher compression-rates. HDR variants are supported on A13 & later GPUs.

ASTC 4x4, LDR
ASTC 4x4, HDR
ASTC 5x4, LDR
ASTC 5x4, HDR
ASTC 5x5, LDR
ASTC 5x5, HDR
ASTC 6x5, LDR
ASTC 6x5, HDR
ASTC 6x6, LDR
ASTC 6x6, HDR
ASTC 8x5, LDR
ASTC 8x5, HDR
ASTC 8x6, LDR
ASTC 8x6, HDR
ASTC 8x8, LDR
ASTC 8x8, HDR
ASTC 10x5, LDR
ASTC 10x5, HDR
ASTC 10x6, LDR
ASTC 10x6, HDR
ASTC 10x8, LDR
ASTC 10x8, HDR
ASTC 10x10, LDR
ASTC 10x10, HDR
ASTC 12x10, LDR
ASTC 12x10, HDR
ASTC 12x12, LDR
ASTC 12x12, HDR

ETC2/EAC compression formats.

EAC 1-channel, signed
EAC 1-channel, unsigned
EAC 2-channel, signed
EAC 2-channel, unsigned
EAC RGBA
ETC2 RGB
ETC2 RGB with 1-bit alpha

PVRTC compression formats. PVRTC require square power-of-two dimensions of minimum size 8x8.

PVRTC RGB 2 bits-per-pixel
PVRTC RGB 4 bits-per-pixel
PVRTC RGBA 2 bits-per-pixel
PVRTC RGBA 4 bits-per-pixel

Available texture compressors. Use ATC_QueryCompressorInfo to query compressor capabilities.

Auto compressor selects which compressor to use based on the format & quality level. Use this compressor unless you require a specific one.
Arm astc-encoder 4.8 (https://github.com/ARM-software/astc-encoder/).
Google etc2comp (https://github.com/google/etc2comp).
Intel ISPC Texture Compressor (https://github.com/GameTechDev/ISPCTextureCompressor).
NVTT (https://github.com/castano/nvidia-texture-tools).
PVRTC compressor. Available on macOS only. PVRTC support in Metal is now deprecated. Usage of ASTC/ETC2/BC formats is recommended instead.
STB DXT compressor (https://github.com/nothings/stb).

Available texture decompressors.

Auto decompressor selects which decompressor to use based on the format. Use this decompressor unless you require a specific one.
Arm astc-encoder 3.7 (https://github.com/ARM-software/astc-encoder/).
GPU texture-sampling based decompressor, using Metal on macOS & D3D11 on Windows.
NVTT (https://github.com/castano/nvidia-texture-tools).
PVRTC compressor. Available on macOS only. PVRTC support in Metal is now deprecated. Usage of ASTC/ETC2/BC formats is recommended instead.

Quality level to use when compressing. Higher quality levels entails slower compression.

Fastest/lowest-quality compression. Best avoided for release builds.
Fast/reasonable-quality compression.
Slower/better-quality compression.
Slowest/higher-quality compression. Best avoided for debug builds.

Format to use when writing texture files.

Auto-select the file format based on the filename extension.
DDS file format.
C/C++ Header
KTX file format.
KTX2 file format.
OpenEXR file format.

Alpha mode for compression.

Ignore alpha.
Pre-multiply color by alpha.
Preserve alpha.

Channel weightings to use when compressing.

Use linear weighting (1.0, 1.0, 1.0, 1.0).
Use perceptual weighting (0.299, 0.587, 0.114, 1.0).

Filtering method to use when generating mip-maps.

Box filter.
Triangle (linear) filter.
Kaiser filter.
Mitchell-Netravali bicubic filter.
Lanczos 3-lobe windowed sinc. Sharp, prone to ringing.
Lanczos 5-lobe windowed sinc. Sharper, more prone to ringing.
Catmull-Rom bicubic filter (Mitchell B=0, C=0.5).
Gaussian filter. Smooth, no ringing.

Filtering method to use when resizing textures.

Box filter.
Triangle (linear) filter.
Kaiser filter.
Mitchell-Netravali bicubic filter.
Lanczos 3-lobe windowed sinc. Sharp, prone to ringing.
Lanczos 5-lobe windowed sinc. Sharper, more prone to ringing.
Catmull-Rom bicubic filter (Mitchell B=0, C=0.5).
Gaussian filter. Smooth, no ringing.

Rounding mode to use when resizing textures.

Don't round.
Resize to next (higher) power of two.
Resize to nearest power of two.
Resize to previous (lower) power of two.
Resize to next (higher) multiple of four.
Resize to nearest multiple of four.
Resize to previous (lower) multiple of four.

Wrap mode to use when resizing textures or generating mip-maps.

Clamp to edge.
Repeat.
Mirror.

Alpha punch-through mode. Used for PVRTC compression only.

Punch-through is allowed.
Punch-through is forced-on.
Punch-through is forced-off.

Supported color gamuts

Gamut not specified.
Not color data, e.g. a normal map.
Display P3.
sRGB.

Type of texture.

2D texture.
Cubemap, atcMaxFaces faces.
3D (volume) texture.
2D texture array.

Severity level of AppleTextureConverter feedback info.

Feedback on operation progress.
Operation has succeeded, but results may be incorrect.
Error while performing requested operation. Operation has failed.

Compressed formats store fixed-size blocks of texels that the GPU decodes when it samples them.

BC
Block compression, also known as DXTC, in 4x4 texel blocks. BC1 and BC4 take 8 bytes per block; BC2, BC3, BC5, BC6H and BC7 take 16. BC4 and BC5 store one and two channels, BC6H stores HDR RGB, and the others store LDR RGB or RGBA.
ASTC
16 bytes per block at every block size from 4x4 to 12x12. Smaller blocks give higher quality at a lower compression rate. HDR variants are supported on A13 and later GPUs.
ETC2 and EAC
4x4 texel blocks. ETC2 RGB, ETC2 RGB with 1-bit alpha and single-channel EAC take 8 bytes per block; two-channel EAC and EAC RGBA take 16.
PVRTC
2 or 4 bits per pixel. PVRTC support in Metal is deprecated; use ASTC, ETC2 or BC formats instead.

For tangent-space normal maps, use normal-map mode with BC5.

Value: ‘5’. This will increment for each API update
Value: ‘15’. The maxinum supported number of mip-levels, including the top mip-level.
Value: ‘6’. Maxinum number of faces for cubemaps.
The maximum height and width of a texture. Calculated to fit atcMaxMipMaps.
Value: ‘512’. The maximum depth of a texture for 3D textures.
Value: ‘512’. The maximum number of array elements for 2D array textures.
Value: ‘512’.

When writing KTX files, the library can add these key/value entries:

ATC_KeyMtlPixelFormat
"KTXmetalPixelFormat", as defined in the KTX spec (https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html), section 5.3.3 This describes the MTLPixelFormat for the texture data. It is only set for textures where the format can not be determined from the file header. This currently means ASTC LDR & HDR textures when saved to KTX 1.1 files.
ATC_KeyPremultipliedAlpha
"com.apple.image.premultipliedAlpha". This indicates that the texture data has pre-multiplied alpha. The value is written as a 32-bit unsigned integer with zero indicating false & non-zero indicating true.
ATC_KeyColorGamut
"com.apple.image.colorGamut". Specifies the color gamut of the image. The value is written as a 0 terminated string. When compressing, it is written only when the options give a gamut (--gamut_in, or --gamut_out on colour-space builds); it is not read from the source image. CLI decompress mode rewrites the loaded image and carries over the gamut read from the source file. Values are:
  • 'sRGB'
  • 'DisplayP3'
  • when carried over from a source file: 'DCIP3', 'BT709', 'BT2020', 'BT2100', 'Adobe-RGB-1998', 'CIE-1931-XYZ' or 'ACEScg'

KTX2 records the gamut in the DFD colorPrimaries field instead, and writes this key (with ATC_KeyColorTransfer where that has a value) only when the DFD cannot record the transfer function (see below). A texture with no known gamut, including every normal map, omits this key in KTX 1.1. In KTX2, normal maps and textures given atcColorGamutNone are written with KHR_DF_PRIMARIES_UNSPECIFIED, and colour textures with no gamut given keep libktx's default BT709 primaries. Reading a KTX2 whose DFD primaries and transfer give no TextureConverter color space (e.g. ACES AP0, BT.601, or Adobe RGB with a linear transfer) prints a warning, unless the options give a gamut: a conversion does not preserve them.

ATC_KeyColorTransfer
"com.apple.image.colorTransfer". Specifies the color transfer function of the image. The value is written as a 0 terminated string. Values are:
  • 'sRGB'
  • 'linear'
  • 'PQ'
  • 'HLG'
  • 'ITU'

Omitted where the gamut implies the transfer function ('DCIP3', 'Adobe-RGB-1998', 'CIE-1931-XYZ'). KTX2 records the transfer function in the DFD transferFunction field, which may only be linear or sRGB. TextureConverter writes sRGB there for an _SRGB format, or for sRGB data in a float format, and linear otherwise. When that does not describe the data (sRGB data in any other format, PQ, HLG, ITU, and the implied transfer functions of 'DCIP3' and 'Adobe-RGB-1998'), a KTX2 also carries ATC_KeyColorGamut and, where it has a value, this key. The pair only adds what the DFD cannot state: it always agrees with the DFD's primaries and transfer. When reading a KTX2, TextureConverter uses the pair only where it agrees with the DFD, and otherwise ignores it with a warning.

ATC_KeyNormalMap
"com.apple.image.normalMap". Indicates that the texture contains a normal map (tangent-space XYZ normals). The value is written as a 32-bit unsigned integer with zero indicating false & non-zero indicating true. Written for both KTX and KTX2 files.

Functions that return ATC_Error return atcErrorNone on success. Errors returned by ATC functions. Check the ATC_MessageCallback for more details.

Success!
Unknown error.
The context struct is invalid.
The options struct is invalid.
The source texture or texture file is invalid.
The destination texture or texture file is invalid.
Error allocating memory.
The pixel format cannot be stored in the requested file/container format.
The source file does not exist or cannot be read.
The destination file cannot be created (e.g. its directory is missing or not writable).

static void* MemoryAllocator( void* userData, size_t size )
{
    return malloc(size);
}

static void MemoryDeallocator( void* userData, void* data )
{
    free(data);
}

static void MessageCallback( void* userData, ATC_InfoLevel level, const char* string )
{
    printf("ATC_Test: %s", string);
}

ATC_Context globalContext = { MemoryAllocator, MemoryDeallocator, MessageCallback, 0 };

bool ExampleFileCompression( const char* pszSourceFile, const char* pszDestFile )
{
    ATC_Options options;
    ATC_InitialiseDefaultOptions( &options );
    options.format = atcFormatBc3Unorm;
    options.quality = atcQualityHighest;

    return ( ATC_CompressFile( &globalContext, pszSourceFile, pszDestFile, &options ) == atcErrorNone );
}

bool ExampleMemoryCompression()
{
    ATC_Options options;
    ATC_InitialiseDefaultOptions(&options);
    options.format = atcFormatBc3Unorm;
    options.quality = atcQualityHighest;

    const ATC_Texture* src = NULL;
    ATC_CreateTexture2D( &globalContext, 4, 4, 1, atcFormatRgba8Unorm, atcColorGamutUnknown, false, &src );

    ATC_Surface* surface = NULL;
    ATC_GetSurface( &globalContext, src, 0, 0, &surface );
    surface->width = 4;
    surface->height = 4;
    surface->data = test_block_rgba;
    surface->size = test_block_rgba_size;

    const ATC_Texture* dest = NULL;
    bool success = ( ATC_CompressMemory( &globalContext, src, &dest, &options ) == atcErrorNone );
    if ( success )
    {
        // Use compressed image
        for (uint32_t mipLevel = 0; mipLevel < dest->numMipLevels; ++mipLevel)
        {
            ATC_Surface* surface = NULL;
            ATC_GetSurface( &globalContext, dest, 0, mipLevel, &surface);
            void* data = surface->data;
        }
    }

    ATC_DeleteTexture( &globalContext, src, false );
    ATC_DeleteTexture( &globalContext, dest, true );

    return success;
}

bool ExampleFileDecompression( const char* pszSourceFile, const char* pszDestFile )
{
    ATC_Options options;
    ATC_InitialiseDefaultOptions(&options);
    options.format = atcFormatRgba8Unorm;

    return ( ATC_DecompressFile( &globalContext, pszSourceFile, pszDestFile, &options ) == atcErrorNone );
}

bool ExampleMemoryDecompression()
{
    ATC_Options options;
    ATC_InitialiseDefaultOptions(&options);
    options.format = atcFormatRgba8Unorm;

    const ATC_Texture* src = NULL;
    ATC_CreateTexture2D( &globalContext, 4, 4, 1, atcFormatBc3Unorm, atcColorGamutUnknown, false, &src );

    ATC_Surface* surface = NULL;
    ATC_GetSurface( &globalContext, src, 0, 0, &surface );
    surface->width = 4;
    surface->height = 4;
    surface->data = test_block_bc3;
    surface->size = test_block_bc3_size;

    const ATC_Texture* dest = NULL;
    bool success = ( ATC_DecompressMemory( &globalContext, src, &dest, &options ) == atcErrorNone );
    if ( success )
    {
        // Use decompressed texture
        for (uint32_t mipLevel = 0; mipLevel < dest->numMipLevels; ++mipLevel)
        {
            ATC_Surface* surface = NULL;
            ATC_GetSurface( &globalContext, dest, 0, mipLevel, &surface);
            void* data = surface->data;
        }
    }

    // Memory may have been allocated regardless of success
    ATC_DeleteTexture( &globalContext, src, false );
    ATC_DeleteTexture( &globalContext, dest, true );

    return success;
}

In Xcode's Project Editor/Build Settings/Search Paths, Add ${SYSTEM_DEVELOPER_USR_DIR}/include to Header Search Paths & add ${SYSTEM_DEVELOPER_USR_DIR}/lib to Library Search Paths. In Xcode's Project Editor/Build Settings/Linking - General, Add -lAppleTextureConverter to Other Linker Flags.

You will also need to link with several system frameworks: (CoreFoundation/Foundation, AppKit, Metal, ImageIO & Accelerate).

In Visual Studio edit the properties for your project. C/C++ - General - Additional Include Directories - "C:\Program Files\Metal Developer Tools\include" In Visual Studio edit the properties for your project. Linker - General - Additional Library Directories - "C:\Program Files\Metal Developer Tools\lib"

TextureConverter(1)

October 19, 2026 macOS 26