| 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
ATC_InitialiseDefaultOptions(),
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_InitialiseDefaultOptions(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.
const ATC_CompressorInfo *
ATC_QueryCompressorInfo(const
ATC_Context *context, ATC_Compressor
compressor);
Query the capabilties & options supported for a given 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);
Create a 2D 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);
Create a 2D Texture Array
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);
Create a 3D 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);
Create a Cubemap Texture
ATC_Error
ATC_DeleteTexture(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.
ATC_Error
ATC_GetSurface(const
ATC_Context *context, const ATC_Texture
*texture, uint32_t elementOrFace,
uint32_t mipLevel, ATC_Surface
**pSurface);
Retrieve a pointer to the specified surface.
ATC_Error
ATC_CompressMemory(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.
ATC_Error
ATC_CompressFile(const
ATC_Context *context, const char *sourceFile,
const char *destFile, const
ATC_Options *options);
Compress texture from file to file.
ATC_Error
ATC_DecompressMemory(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)).
ATC_Error
ATC_DecompressFile(const
ATC_Context *context, const char *sourceFile,
const char *destFile, const
ATC_Options *options);
Decompress texture from file to file.
ATC_Error
ATC_CompareMemory(const
ATC_Context *context, const ATC_Texture
*refImage, const ATC_Texture *compImage,
const ATC_Options *options,
ATC_ErrorMetrics *metrics);
Compare two in-memory textures.
ATC_Error
ATC_CompareFile(const
ATC_Context *context, const char *refFile,
const char *compFile, const
ATC_Options *options, ATC_ErrorMetrics
*metrics);
Compare two texture files.
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.
typedef void (*ATC_MemoryDeallocator)(void *userData, void *data);
Callback function for deallocating memory
typedef void (*ATC_MessageCallback)(void *userData, ATC_InfoLevel level, const char *string);
Callback function for feedback from AppleTextureConverter operations.
Struct declaring the compression/decompression context
Options to define how to perform operations.
--compressor.--compression_format,
--format.--compression_quality.--alpha_mode.--alpha_to_coverage.--alpha_reference.--alpha_weight.--gamma_in.--gamma_out.--gamma_in.--gamma_out.--gamut_in.--gamut_in,
--gamut_out.--max_mipmaps.--mipmap_filter.--max_extent.--resize_round_mode.--resize_filter.--wrap_mode.--rgbm_encoding.--rgbm_range.--crop_uniform_content.--disable_multithreading.--flip_x.--flip_y.--flip_z.--normal_map.--scale_range.--srgb_format.--ASTC_HDR.--file_format.--disable_annotation.Compression options used only when compressing with the atcCompressorPVRTC compressor.
--channel_weighting.--pvrtc_punch_through.--advanced_metrics.Top-level texture.
Per-surface (mip-level-face) data.
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.
Struct describing compressor capabilities & options.
atcFormatUnknownUncompressed 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.
atcFormatR8UnormatcFormatR16F16atcFormatR32F32atcFormatRg8UnormatcFormatRg16F16atcFormatRg32F32atcFormatRgb8UnormatcFormatRgb16F16atcFormatRgb32F32atcFormatRgba8UnormatcFormatRgba8SnormatcFormatRgba8SintatcFormatRgba8UintatcFormatRgba16SnormatcFormatRgba16UnormatcFormatRgba16S16atcFormatRgba16U16atcFormatRgba16F16atcFormatRgba32F32atcFormatBgra8UnormatcFormatBgrx8UnormatcFormatA8Unorm16-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).
atcFormatAbgr4UnormatcFormatB5G6R5UnormatcFormatBgr5A1UnormatcFormatRgb10A2UnormatcFormatRgb10A2SnormatcFormatRgb10A2SintatcFormatRgb10A2UintatcFormatBgr10A2UnormatcFormatBgr10A2SnormatcFormatBgr10A2SintatcFormatBgr10A2UintCompressed formats. These are the destination formats for compression operations and the sourceFile formats for decompression operations.
BC (aka DXTC) compression formats.
atcFormatBc1UnormatcFormatBc2UnormatcFormatBc3UnormatcFormatBc4SnormatcFormatBc4UnormatcFormatBc5SnormatcFormatBc5UnormatcFormatBc6Sf16atcFormatBc6Uf16atcFormatBc7UnormASTC 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.
atcFormatAstc4x4UnormatcFormatAstc4x4F16atcFormatAstc5x4UnormatcFormatAstc5x4F16atcFormatAstc5x5UnormatcFormatAstc5x5F16atcFormatAstc6x5UnormatcFormatAstc6x5F16atcFormatAstc6x6UnormatcFormatAstc6x6F16atcFormatAstc8x5UnormatcFormatAstc8x5F16atcFormatAstc8x6UnormatcFormatAstc8x6F16atcFormatAstc8x8UnormatcFormatAstc8x8F16atcFormatAstc10x5UnormatcFormatAstc10x5F16atcFormatAstc10x6UnormatcFormatAstc10x6F16atcFormatAstc10x8UnormatcFormatAstc10x8F16atcFormatAstc10x10UnormatcFormatAstc10x10F16atcFormatAstc12x10UnormatcFormatAstc12x10F16atcFormatAstc12x12UnormatcFormatAstc12x12F16ETC2/EAC compression formats.
atcFormatEacR11SnormatcFormatEacR11UnormatcFormatEacRg11SnormatcFormatEacRg11UnormatcFormatEacRgba8UnormatcFormatEtc2Rgb8UnormatcFormatEtc2Rgb8A1UnormPVRTC compression formats. PVRTC require square power-of-two dimensions of minimum size 8x8.
atcFormatPvrtcRgb2BppUnormatcFormatPvrtcRgb4BppUnormatcFormatPvrtcRgba2BppUnormatcFormatPvrtcRgba4BppUnormAvailable texture compressors. Use ATC_QueryCompressorInfo to query compressor capabilities.
atcCompressorAutoatcCompressorArmatcCompressorETC2COMPatcCompressorISPCatcCompressorNVTTatcCompressorPVRTCatcCompressorSTBAvailable texture decompressors.
atcDecompressorAutoatcDecompressorArmatcDecompressorGPUatcDecompressorNVTTatcDecompressorPVRTCQuality level to use when compressing. Higher quality levels entails slower compression.
atcQualityFastestatcQualityNormalatcQualityProductionatcQualityHighestFormat to use when writing texture files.
atcFileFormatAutoatcFileFormatDDSatcFileFormatHeaderatcFileFormatKTXatcFileFormatKTX2atcFileFormatEXRAlpha mode for compression.
atcAlphaIgnoreatcAlphaPremultiplyatcAlphaPreserveChannel weightings to use when compressing.
atcWeightingLinearatcWeightingPerceptualFiltering method to use when generating mip-maps.
atcMipmapFilterBoxatcMipmapFilterTriangleatcMipmapFilterKaiseratcMipmapFilterMitchellatcMipmapFilterLanczos3atcMipmapFilterLanczos5atcMipmapFilterCatmullRomatcMipmapFilterGaussianFiltering method to use when resizing textures.
atcResizeFilterBoxatcResizeFilterTriangleatcResizeFilterKaiseratcResizeFilterMitchellatcResizeFilterLanczos3atcResizeFilterLanczos5atcResizeFilterCatmullRomatcResizeFilterGaussianRounding mode to use when resizing textures.
atcRoundModeNoneatcRoundModeNextPowerOfTwoatcRoundModeNearestPowerOfTwoatcRoundModePreviousPowerOfTwoatcRoundModeNextMultipleOfFouratcRoundModeNearestMultipleOfFouratcRoundModePreviousMultipleOfFourWrap mode to use when resizing textures or generating mip-maps.
atcWrapModeClampatcWrapModeRepeatatcWrapModeMirrorAlpha punch-through mode. Used for PVRTC compression only.
atcPVRPunchThroughAllowedatcPVRPunchThroughForcedatcPVRPunchThroughUnusedSupported color gamuts
atcColorGamutUnknownatcColorGamutNoneatcColorGamutDisplayP3atcColorGamutSRGBType of texture.
atcTextureType2DatcTextureTypeCubeatcTextureType3DatcTextureType2DArraySeverity level of AppleTextureConverter feedback info.
atcInfoMessageatcInfoWarningatcInfoErrorCompressed formats store fixed-size blocks of texels that the GPU decodes when it samples them.
For tangent-space normal maps, use normal-map mode with BC5.
ATC_API_VER5’. This will increment for
each API updateatcMaxMipMaps15’. The maxinum supported
number of mip-levels, including the top mip-level.atcMaxFaces6’. Maxinum number of faces
for cubemaps.atcMaxExtentatcMaxDepth512’. The maximum depth of a
texture for 3D textures.atcMaxElements512’. The maximum number of
array elements for 2D array textures.atcMaxSurfaces512’.When writing KTX files, the library can add these key/value entries:
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.
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.
Functions that return ATC_Error return
atcErrorNone on success. Errors returned by ATC
functions. Check the ATC_MessageCallback for more details.
atcErrorNoneatcErrorUnknownatcErrorInvalidContextatcErrorInvalidOptionsatcErrorInvalidSourceTextureatcErrorInvalidDestTextureatcErrorMemoryatcErrorUnsupportedFormatForFileatcErrorSourceFileNotFoundatcErrorCannotCreateDestFilestatic 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"
| October 19, 2026 | macOS 26 |