// SPDX-License-Identifier: Apache-2.01// ----------------------------------------------------------------------------2// Copyright 2020-2025 Arm Limited3//4// Licensed under the Apache License, Version 2.0 (the "License"); you may not5// use this file except in compliance with the License. You may obtain a copy6// of the License at:7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing, software11// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13// License for the specific language governing permissions and limitations14// under the License.15// ----------------------------------------------------------------------------1617/**18* @brief The core astcenc codec library interface.19*20* This interface is the entry point to the core astcenc codec. It aims to be easy to use for21* non-experts, but also to allow experts to have fine control over the compressor heuristics if22* needed. The core codec only handles compression and decompression, transferring all inputs and23* outputs via memory buffers. To catch obvious input/output buffer sizing issues, which can cause24* security and stability problems, all transfer buffers are explicitly sized.25*26* While the aim is that we keep this interface mostly stable, it should be viewed as a mutable27* interface tied to a specific source version. We are not trying to maintain backwards28* compatibility across codec versions.29*30* The API state management is based around an explicit context object, which is the context for all31* allocated memory resources needed to compress and decompress a single image. A context can be32* used to sequentially compress multiple images using the same configuration, allowing setup33* overheads to be amortized over multiple images, which is particularly important when images are34* small.35*36* Multi-threading can be used two ways.37*38* * An application wishing to process multiple images in parallel can allocate multiple39* contexts and assign each context to a thread.40* * An application wishing to process a single image in using multiple threads can configure41* contexts for multi-threaded use, and invoke astcenc_compress/decompress() once per thread42* for faster processing. The caller is responsible for creating the worker threads, and43* synchronizing between images.44*45* Extended instruction set support46* ================================47*48* This library supports use of extended instruction sets, such as SSE4.1 and AVX2. These are49* enabled at compile time when building the library. There is no runtime checking in the core50* library that the instruction sets used are actually available. Checking compatibility is the51* responsibility of the calling code.52*53* Threading54* =========55*56* In pseudo-code, the usage for manual user threading looks like this:57*58* // Configure the compressor run59* astcenc_config my_config;60* astcenc_config_init(..., &my_config);61*62* // Power users can tweak <my_config> settings here ...63*64* // Allocate working state given config and thread_count65* astcenc_context* my_context;66* astcenc_context_alloc(&my_config, thread_count, &my_context);67*68* // Compress each image using these config settings69* foreach image:70* // For each thread in the thread pool71* for i in range(0, thread_count):72* astcenc_compress_image(my_context, &my_input, my_output, i);73*74* astcenc_compress_reset(my_context);75*76* // Clean up77* astcenc_context_free(my_context);78*79* Images80* ======81*82* The codec supports compressing single images, which can be either 2D images or volumetric 3D83* images. Calling code is responsible for any handling of aggregate types, such as mipmap chains,84* texture arrays, or sliced 3D textures.85*86* Images are passed in as an astcenc_image structure. Inputs can be either 8-bit unorm, 16-bit87* half-float, or 32-bit float, as indicated by the data_type field.88*89* Images can be any dimension; there is no requirement to be a multiple of the ASTC block size.90*91* Data is always passed in as 4 color components, and accessed as an array of 2D image slices. Data92* within an image slice is always tightly packed without padding. Addressing looks like this:93*94* data[z_coord][y_coord * x_dim * 4 + x_coord * 4 ] // Red95* data[z_coord][y_coord * x_dim * 4 + x_coord * 4 + 1] // Green96* data[z_coord][y_coord * x_dim * 4 + x_coord * 4 + 2] // Blue97* data[z_coord][y_coord * x_dim * 4 + x_coord * 4 + 3] // Alpha98*99* Common compressor usage100* =======================101*102* One of the most important things for coding image quality is to align the input data component103* count with the ASTC color endpoint mode. This avoids wasting bits encoding components you don't104* actually need in the endpoint colors.105*106* | Input data | Encoding swizzle | Sampling swizzle |107* | ------------ | ---------------- | ---------------- |108* | 1 component | RRR1 | .[rgb] |109* | 2 components | RRRG | .[rgb]a |110* | 3 components | RGB1 | .rgb |111* | 4 components | RGBA | .rgba |112*113* The 1 and 2 component modes recommend sampling from "g" to recover the luminance value as this114* provide best compatibility with other texture formats where the green component may be stored at115* higher precision than the others, such as RGB565. For ASTC any of the RGB components can be used;116* the luminance endpoint component will be returned for all three.117*118* When using the normal map compression mode ASTC will store normals as a two component X+Y map.119* Input images must contain unit-length normalized and should be passed in using a two component120* swizzle. The astcenc command line tool defaults to an RRRG swizzle, but some developers prefer121* to use GGGR for compatability with BC5n which will work just as well. The Z component can be122* recovered programmatically in shader code, using knowledge that the vector is unit length and123* that Z must be positive for a tangent-space normal map.124*125* Decompress-only usage126* =====================127*128* For some use cases it is useful to have a cut-down context and/or library which supports129* decompression but not compression.130*131* A context can be made decompress-only using the ASTCENC_FLG_DECOMPRESS_ONLY flag when the context132* is allocated. These contexts have lower dynamic memory footprint than a full context.133*134* The entire library can be made decompress-only by building the files with the define135* ASTCENC_DECOMPRESS_ONLY set. In this build the context will be smaller, and the library will136* exclude the functionality which is only needed for compression. This reduces the binary size by137* ~180KB. For these builds contexts must be created with the ASTCENC_FLG_DECOMPRESS_ONLY flag.138*139* Note that context structures returned by a library built as decompress-only are incompatible with140* a library built with compression included, and visa versa, as they have different sizes and141* memory layout.142*143* Self-decompress-only usage144* ==========================145*146* ASTC is a complex format with a large search space. The parts of this search space that are147* searched is determined by heuristics that are, in part, tied to the quality level used when148* creating the context.149*150* A normal context is capable of decompressing any ASTC texture, including those generated by other151* compressors with unknown heuristics. This is the most flexible implementation, but forces the152* data tables used by the codec to include entries that are not needed during compression. This153* can slow down context creation by a significant amount, especially for the faster compression154* modes where few data table entries are actually used. To optimize this use case the context can155* be created with the ASTCENC_FLG_SELF_DECOMPRESS_ONLY flag. This tells the compressor that it will156* only be asked to decompress images that it compressed itself, allowing the data tables to157* exclude entries that are not needed by the current compression configuration. This reduces the158* size of the context data tables in memory and improves context creation performance. Note that,159* as of the 3.6 release, this flag no longer affects compression performance.160*161* Using this flag while attempting to decompress an valid image which was created by another162* compressor, or even another astcenc compressor version or configuration, may result in blocks163* returning as solid magenta or NaN value error blocks.164*/165166#ifndef ASTCENC_INCLUDED167#define ASTCENC_INCLUDED168169#include <cstddef>170#include <cstdint>171172#if defined(ASTCENC_DYNAMIC_LIBRARY)173#if defined(_MSC_VER)174#define ASTCENC_PUBLIC extern "C" __declspec(dllexport)175#else176#define ASTCENC_PUBLIC extern "C" __attribute__ ((visibility ("default")))177#endif178#else179#define ASTCENC_PUBLIC180#endif181182/* ============================================================================183Data declarations184============================================================================ */185186/**187* @brief An opaque structure; see astcenc_internal.h for definition.188*/189struct astcenc_context;190191/**192* @brief A codec API error code.193*/194enum astcenc_error {195/** @brief The call was successful. */196ASTCENC_SUCCESS = 0,197/** @brief The call failed due to low memory, or undersized I/O buffers. */198ASTCENC_ERR_OUT_OF_MEM,199/** @brief The call failed due to the build using fast math. */200ASTCENC_ERR_BAD_CPU_FLOAT,201/** @brief The call failed due to an out-of-spec parameter. */202ASTCENC_ERR_BAD_PARAM,203/** @brief The call failed due to an out-of-spec block size. */204ASTCENC_ERR_BAD_BLOCK_SIZE,205/** @brief The call failed due to an out-of-spec color profile. */206ASTCENC_ERR_BAD_PROFILE,207/** @brief The call failed due to an out-of-spec quality value. */208ASTCENC_ERR_BAD_QUALITY,209/** @brief The call failed due to an out-of-spec component swizzle. */210ASTCENC_ERR_BAD_SWIZZLE,211/** @brief The call failed due to an out-of-spec flag set. */212ASTCENC_ERR_BAD_FLAGS,213/** @brief The call failed due to the context not supporting the operation. */214ASTCENC_ERR_BAD_CONTEXT,215/** @brief The call failed due to unimplemented functionality. */216ASTCENC_ERR_NOT_IMPLEMENTED,217/** @brief The call failed due to an out-of-spec decode mode flag set. */218ASTCENC_ERR_BAD_DECODE_MODE,219#if defined(ASTCENC_DIAGNOSTICS)220/** @brief The call failed due to an issue with diagnostic tracing. */221ASTCENC_ERR_DTRACE_FAILURE,222#endif223};224225/**226* @brief A codec color profile.227*/228enum astcenc_profile {229/** @brief The LDR sRGB color profile. */230ASTCENC_PRF_LDR_SRGB = 0,231/** @brief The LDR linear color profile. */232ASTCENC_PRF_LDR,233/** @brief The HDR RGB with LDR alpha color profile. */234ASTCENC_PRF_HDR_RGB_LDR_A,235/** @brief The HDR RGBA color profile. */236ASTCENC_PRF_HDR237};238239/** @brief The fastest, lowest quality, search preset. */240static const float ASTCENC_PRE_FASTEST = 0.0f;241242/** @brief The fast search preset. */243static const float ASTCENC_PRE_FAST = 10.0f;244245/** @brief The medium quality search preset. */246static const float ASTCENC_PRE_MEDIUM = 60.0f;247248/** @brief The thorough quality search preset. */249static const float ASTCENC_PRE_THOROUGH = 98.0f;250251/** @brief The thorough quality search preset. */252static const float ASTCENC_PRE_VERYTHOROUGH = 99.0f;253254/** @brief The exhaustive, highest quality, search preset. */255static const float ASTCENC_PRE_EXHAUSTIVE = 100.0f;256257/**258* @brief A codec component swizzle selector.259*/260enum astcenc_swz261{262/** @brief Select the red component. */263ASTCENC_SWZ_R = 0,264/** @brief Select the green component. */265ASTCENC_SWZ_G = 1,266/** @brief Select the blue component. */267ASTCENC_SWZ_B = 2,268/** @brief Select the alpha component. */269ASTCENC_SWZ_A = 3,270/** @brief Use a constant zero component. */271ASTCENC_SWZ_0 = 4,272/** @brief Use a constant one component. */273ASTCENC_SWZ_1 = 5,274/** @brief Use a reconstructed normal vector Z component. */275ASTCENC_SWZ_Z = 6276};277278/**279* @brief A texel component swizzle.280*/281struct astcenc_swizzle282{283/** @brief The red component selector. */284astcenc_swz r;285/** @brief The green component selector. */286astcenc_swz g;287/** @brief The blue component selector. */288astcenc_swz b;289/** @brief The alpha component selector. */290astcenc_swz a;291};292293/**294* @brief A texel component data format.295*/296enum astcenc_type297{298/** @brief Unorm 8-bit data per component. */299ASTCENC_TYPE_U8 = 0,300/** @brief 16-bit float per component. */301ASTCENC_TYPE_F16 = 1,302/** @brief 32-bit float per component. */303ASTCENC_TYPE_F32 = 2304};305306/**307* @brief Function pointer type for compression progress reporting callback.308*/309extern "C" typedef void (*astcenc_progress_callback)(float);310311/**312* @brief Enable normal map compression.313*314* Input data will be treated a two component normal map, storing X and Y, and the codec will315* optimize for angular error rather than simple linear PSNR. In this mode the input swizzle should316* be e.g. rrrg (the default ordering for ASTC normals on the command line) or gggr (the ordering317* used by BC5n).318*/319static const unsigned int ASTCENC_FLG_MAP_NORMAL = 1 << 0;320321/**322* @brief Enable compression heuristics that assume use of decode_unorm8 decode mode.323*324* The decode_unorm8 decode mode rounds differently to the decode_fp16 decode mode, so enabling this325* flag during compression will allow the compressor to use the correct rounding when selecting326* encodings. This will improve the compressed image quality if your application is using the327* decode_unorm8 decode mode, but will reduce image quality if using decode_fp16.328*329* Note that LDR_SRGB images will always use decode_unorm8 for the RGB channels, irrespective of330* this setting.331*/332static const unsigned int ASTCENC_FLG_USE_DECODE_UNORM8 = 1 << 1;333334/**335* @brief Enable alpha weighting.336*337* The input alpha value is used for transparency, so errors in the RGB components are weighted by338* the transparency level. This allows the codec to more accurately encode the alpha value in areas339* where the color value is less significant.340*/341static const unsigned int ASTCENC_FLG_USE_ALPHA_WEIGHT = 1 << 2;342343/**344* @brief Enable perceptual error metrics.345*346* This mode enables perceptual compression mode, which will optimize for perceptual error rather347* than best PSNR. Only some input modes support perceptual error metrics.348*/349static const unsigned int ASTCENC_FLG_USE_PERCEPTUAL = 1 << 3;350351/**352* @brief Create a decompression-only context.353*354* This mode disables support for compression. This enables context allocation to skip some355* transient buffer allocation, resulting in lower memory usage.356*/357static const unsigned int ASTCENC_FLG_DECOMPRESS_ONLY = 1 << 4;358359/**360* @brief Create a self-decompression context.361*362* This mode configures the compressor so that it is only guaranteed to be able to decompress images363* that were actually created using the current context. This is the common case for compression use364* cases, and setting this flag enables additional optimizations, but does mean that the context365* cannot reliably decompress arbitrary ASTC images.366*/367static const unsigned int ASTCENC_FLG_SELF_DECOMPRESS_ONLY = 1 << 5;368369/**370* @brief Enable RGBM map compression.371*372* Input data will be treated as HDR data that has been stored in an LDR RGBM-encoded wrapper373* format. Data must be preprocessed by the user to be in LDR RGBM format before calling the374* compression function, this flag is only used to control the use of RGBM-specific heuristics and375* error metrics.376*377* IMPORTANT: The ASTC format is prone to bad failure modes with unconstrained RGBM data; very small378* M values can round to zero due to quantization and result in black or white pixels. It is highly379* recommended that the minimum value of M used in the encoding is kept above a lower threshold (try380* 16 or 32). Applying this threshold reduces the number of very dark colors that can be381* represented, but is still higher precision than 8-bit LDR.382*383* When this flag is set the value of @c rgbm_m_scale in the context must be set to the RGBM scale384* factor used during reconstruction. This defaults to 5 when in RGBM mode.385*386* It is recommended that the value of @c cw_a_weight is set to twice the value of the multiplier387* scale, ensuring that the M value is accurately encoded. This defaults to 10 when in RGBM mode,388* matching the default scale factor.389*/390static const unsigned int ASTCENC_FLG_MAP_RGBM = 1 << 6;391392/**393* @brief The bit mask of all valid flags.394*/395static const unsigned int ASTCENC_ALL_FLAGS =396ASTCENC_FLG_MAP_NORMAL |397ASTCENC_FLG_MAP_RGBM |398ASTCENC_FLG_USE_ALPHA_WEIGHT |399ASTCENC_FLG_USE_PERCEPTUAL |400ASTCENC_FLG_USE_DECODE_UNORM8 |401ASTCENC_FLG_DECOMPRESS_ONLY |402ASTCENC_FLG_SELF_DECOMPRESS_ONLY;403404/**405* @brief The config structure.406*407* This structure will initially be populated by a call to astcenc_config_init, but power users may408* modify it before calling astcenc_context_alloc. See astcenccli_toplevel_help.cpp for full user409* documentation of the power-user settings.410*411* Note for any settings which are associated with a specific color component, the value in the412* config applies to the component that exists after any compression data swizzle is applied.413*/414struct astcenc_config415{416/** @brief The color profile. */417astcenc_profile profile;418419/** @brief The set of set flags. */420unsigned int flags;421422/** @brief The ASTC block size X dimension. */423unsigned int block_x;424425/** @brief The ASTC block size Y dimension. */426unsigned int block_y;427428/** @brief The ASTC block size Z dimension. */429unsigned int block_z;430431/** @brief The red component weight scale for error weighting (-cw). */432float cw_r_weight;433434/** @brief The green component weight scale for error weighting (-cw). */435float cw_g_weight;436437/** @brief The blue component weight scale for error weighting (-cw). */438float cw_b_weight;439440/** @brief The alpha component weight scale for error weighting (-cw). */441float cw_a_weight;442443/**444* @brief The radius for any alpha-weight scaling (-a).445*446* It is recommended that this is set to 1 when using FLG_USE_ALPHA_WEIGHT on a texture that447* will be sampled using linear texture filtering to minimize color bleed out of transparent448* texels that are adjacent to non-transparent texels.449*/450unsigned int a_scale_radius;451452/** @brief The RGBM scale factor for the shared multiplier (-rgbm). */453float rgbm_m_scale;454455/**456* @brief The maximum number of partitions searched (-partitioncountlimit).457*458* Valid values are between 1 and 4.459*/460unsigned int tune_partition_count_limit;461462/**463* @brief The maximum number of partitions searched (-2partitionindexlimit).464*465* Valid values are between 1 and 1024.466*/467unsigned int tune_2partition_index_limit;468469/**470* @brief The maximum number of partitions searched (-3partitionindexlimit).471*472* Valid values are between 1 and 1024.473*/474unsigned int tune_3partition_index_limit;475476/**477* @brief The maximum number of partitions searched (-4partitionindexlimit).478*479* Valid values are between 1 and 1024.480*/481unsigned int tune_4partition_index_limit;482483/**484* @brief The maximum centile for block modes searched (-blockmodelimit).485*486* Valid values are between 1 and 100.487*/488unsigned int tune_block_mode_limit;489490/**491* @brief The maximum iterative refinements applied (-refinementlimit).492*493* Valid values are between 1 and N; there is no technical upper limit494* but little benefit is expected after N=4.495*/496unsigned int tune_refinement_limit;497498/**499* @brief The number of trial candidates per mode search (-candidatelimit).500*501* Valid values are between 1 and TUNE_MAX_TRIAL_CANDIDATES.502*/503unsigned int tune_candidate_limit;504505/**506* @brief The number of trial partitionings per search (-2partitioncandidatelimit).507*508* Valid values are between 1 and TUNE_MAX_PARTITIONING_CANDIDATES.509*/510unsigned int tune_2partitioning_candidate_limit;511512/**513* @brief The number of trial partitionings per search (-3partitioncandidatelimit).514*515* Valid values are between 1 and TUNE_MAX_PARTITIONING_CANDIDATES.516*/517unsigned int tune_3partitioning_candidate_limit;518519/**520* @brief The number of trial partitionings per search (-4partitioncandidatelimit).521*522* Valid values are between 1 and TUNE_MAX_PARTITIONING_CANDIDATES.523*/524unsigned int tune_4partitioning_candidate_limit;525526/**527* @brief The dB threshold for stopping block search (-dblimit).528*529* This option is ineffective for HDR textures.530*/531float tune_db_limit;532533/**534* @brief The amount of MSE overshoot needed to early-out trials.535*536* The first early-out is for 1 partition, 1 plane trials, where we try a minimal encode using537* the high probability block modes. This can short-cut compression for simple blocks.538*539* The second early-out is for refinement trials, where we can exit refinement once quality is540* reached.541*/542float tune_mse_overshoot;543544/**545* @brief The threshold for skipping 3.1/4.1 trials (-2partitionlimitfactor).546*547* This option is further scaled for normal maps, so it skips less often.548*/549float tune_2partition_early_out_limit_factor;550551/**552* @brief The threshold for skipping 4.1 trials (-3partitionlimitfactor).553*554* This option is further scaled for normal maps, so it skips less often.555*/556float tune_3partition_early_out_limit_factor;557558/**559* @brief The threshold for skipping two weight planes (-2planelimitcorrelation).560*561* This option is ineffective for normal maps.562*/563float tune_2plane_early_out_limit_correlation;564565/**566* @brief The config enable for the mode0 fast-path search.567*568* If this is set to TUNE_MIN_TEXELS_MODE0 or higher then the early-out fast mode0569* search is enabled. This option is ineffective for 3D block sizes.570*/571float tune_search_mode0_enable;572573/**574* @brief The progress callback, can be @c nullptr.575*576* If this is specified the codec will peridocially report progress for577* compression as a percentage between 0 and 100. The callback is called from one578* of the compressor threads, so doing significant work in the callback will579* reduce compression performance.580*/581astcenc_progress_callback progress_callback;582583#if defined(ASTCENC_DIAGNOSTICS)584/**585* @brief The path to save the diagnostic trace data to.586*587* This option is not part of the public API, and requires special builds588* of the library.589*/590const char* trace_file_path;591#endif592};593594/**595* @brief An uncompressed 2D or 3D image.596*597* 3D image are passed in as an array of 2D slices. Each slice has identical598* size and color format.599*/600struct astcenc_image601{602/** @brief The X dimension of the image, in texels. */603unsigned int dim_x;604605/** @brief The Y dimension of the image, in texels. */606unsigned int dim_y;607608/** @brief The Z dimension of the image, in texels. */609unsigned int dim_z;610611/** @brief The data type per component. */612astcenc_type data_type;613614/** @brief The array of 2D slices, of length @c dim_z. */615void** data;616};617618/**619* @brief A block encoding metadata query result.620*621* If the block is an error block or a constant color block or an error block all fields other than622* the profile, block dimensions, and error/constant indicator will be zero.623*/624struct astcenc_block_info625{626/** @brief The block encoding color profile. */627astcenc_profile profile;628629/** @brief The number of texels in the X dimension. */630unsigned int block_x;631632/** @brief The number of texels in the Y dimension. */633unsigned int block_y;634635/** @brief The number of texel in the Z dimension. */636unsigned int block_z;637638/** @brief The number of texels in the block. */639unsigned int texel_count;640641/** @brief True if this block is an error block. */642bool is_error_block;643644/** @brief True if this block is a constant color block. */645bool is_constant_block;646647/** @brief True if this block is an HDR block. */648bool is_hdr_block;649650/** @brief True if this block uses two weight planes. */651bool is_dual_plane_block;652653/** @brief The number of partitions if not constant color. */654unsigned int partition_count;655656/** @brief The partition index if 2 - 4 partitions used. */657unsigned int partition_index;658659/** @brief The component index of the second plane if dual plane. */660unsigned int dual_plane_component;661662/** @brief The color endpoint encoding mode for each partition. */663unsigned int color_endpoint_modes[4];664665/** @brief The number of color endpoint quantization levels. */666unsigned int color_level_count;667668/** @brief The number of weight quantization levels. */669unsigned int weight_level_count;670671/** @brief The number of weights in the X dimension. */672unsigned int weight_x;673674/** @brief The number of weights in the Y dimension. */675unsigned int weight_y;676677/** @brief The number of weights in the Z dimension. */678unsigned int weight_z;679680/** @brief The unpacked color endpoints for each partition. */681float color_endpoints[4][2][4];682683/** @brief The per-texel interpolation weights for the block. */684float weight_values_plane1[216];685686/** @brief The per-texel interpolation weights for the block. */687float weight_values_plane2[216];688689/** @brief The per-texel partition assignments for the block. */690uint8_t partition_assignment[216];691};692693/**694* Populate a codec config based on default settings.695*696* Power users can edit the returned config struct to fine tune before allocating the context.697*698* @param profile Color profile.699* @param block_x ASTC block size X dimension.700* @param block_y ASTC block size Y dimension.701* @param block_z ASTC block size Z dimension.702* @param quality Search quality preset / effort level. Either an703* @c ASTCENC_PRE_* value, or a effort level between 0704* and 100. Performance is not linear between 0 and 100.705706* @param flags A valid set of @c ASTCENC_FLG_* flag bits.707* @param[out] config Output config struct to populate.708*709* @return @c ASTCENC_SUCCESS on success, or an error if the inputs are invalid710* either individually, or in combination.711*/712ASTCENC_PUBLIC astcenc_error astcenc_config_init(713astcenc_profile profile,714unsigned int block_x,715unsigned int block_y,716unsigned int block_z,717float quality,718unsigned int flags,719astcenc_config* config);720721/**722* @brief Allocate a new codec context based on a config.723*724* This function allocates all of the memory resources and threads needed by the codec. This can be725* slow, so it is recommended that contexts are reused to serially compress or decompress multiple726* images to amortize setup cost.727*728* Contexts can be allocated to support only decompression using the @c ASTCENC_FLG_DECOMPRESS_ONLY729* flag when creating the configuration. The compression functions will fail if invoked. For a730* decompress-only library build the @c ASTCENC_FLG_DECOMPRESS_ONLY flag must be set when creating731* any context.732*733* @param[in] config Codec config.734* @param thread_count Thread count to configure for.735* @param[out] context Location to store an opaque context pointer.736*737* @return @c ASTCENC_SUCCESS on success, or an error if context creation failed.738*/739ASTCENC_PUBLIC astcenc_error astcenc_context_alloc(740const astcenc_config* config,741unsigned int thread_count,742astcenc_context** context);743744/**745* @brief Compress an image.746*747* A single context can only compress or decompress a single image at a time.748*749* For a context configured for multi-threading, any set of the N threads can call this function.750* Work will be dynamically scheduled across the threads available. Each thread must have a unique751* @c thread_index.752*753* @param context Codec context.754* @param[in,out] image An input image, in 2D slices.755* @param swizzle Compression data swizzle, applied before compression.756* @param[out] data_out Pointer to output data array.757* @param data_len Length of the output data array.758* @param thread_index Thread index [0..N-1] of calling thread.759*760* @return @c ASTCENC_SUCCESS on success, or an error if compression failed.761*/762ASTCENC_PUBLIC astcenc_error astcenc_compress_image(763astcenc_context* context,764astcenc_image* image,765const astcenc_swizzle* swizzle,766uint8_t* data_out,767size_t data_len,768unsigned int thread_index);769770/**771* @brief Reset the codec state for a new compression.772*773* The caller is responsible for synchronizing threads in the worker thread pool. This function must774* only be called when all threads have exited the @c astcenc_compress_image() function for image N,775* but before any thread enters it for image N + 1.776*777* Calling this is not required (but won't hurt), if the context is created for single threaded use.778*779* @param context Codec context.780*781* @return @c ASTCENC_SUCCESS on success, or an error if reset failed.782*/783ASTCENC_PUBLIC astcenc_error astcenc_compress_reset(784astcenc_context* context);785786/**787* @brief Cancel any pending compression operation.788*789* The caller must behave as if the compression completed normally, even though the data will be790* undefined. They are still responsible for synchronizing threads in the worker thread pool, and791* must call reset before starting another compression.792*793* @param context Codec context.794*795* @return @c ASTCENC_SUCCESS on success, or an error if cancellation failed.796*/797ASTCENC_PUBLIC astcenc_error astcenc_compress_cancel(798astcenc_context* context);799800/**801* @brief Decompress an image.802*803* @param context Codec context.804* @param[in] data Pointer to compressed data.805* @param data_len Length of the compressed data, in bytes.806* @param[in,out] image_out Output image.807* @param swizzle Decompression data swizzle, applied after decompression.808* @param thread_index Thread index [0..N-1] of calling thread.809*810* @return @c ASTCENC_SUCCESS on success, or an error if decompression failed.811*/812ASTCENC_PUBLIC astcenc_error astcenc_decompress_image(813astcenc_context* context,814const uint8_t* data,815size_t data_len,816astcenc_image* image_out,817const astcenc_swizzle* swizzle,818unsigned int thread_index);819820/**821* @brief Reset the codec state for a new decompression.822*823* The caller is responsible for synchronizing threads in the worker thread pool. This function must824* only be called when all threads have exited the @c astcenc_decompress_image() function for image825* N, but before any thread enters it for image N + 1.826*827* Calling this is not required (but won't hurt), if the context is created for single threaded use.828*829* @param context Codec context.830*831* @return @c ASTCENC_SUCCESS on success, or an error if reset failed.832*/833ASTCENC_PUBLIC astcenc_error astcenc_decompress_reset(834astcenc_context* context);835836/**837* Free the compressor context.838*839* @param context The codec context.840*/841ASTCENC_PUBLIC void astcenc_context_free(842astcenc_context* context);843844/**845* @brief Provide a high level summary of a block's encoding.846*847* This feature is primarily useful for codec developers but may be useful for developers building848* advanced content packaging pipelines.849*850* @param context Codec context.851* @param data One block of compressed ASTC data.852* @param info The output info structure to populate.853*854* @return @c ASTCENC_SUCCESS if the block was decoded, or an error otherwise. Note that this855* function will return success even if the block itself was an error block encoding, as the856* decode was correctly handled.857*/858ASTCENC_PUBLIC astcenc_error astcenc_get_block_info(859astcenc_context* context,860const uint8_t data[16],861astcenc_block_info* info);862863/**864* @brief Get a printable string for specific status code.865*866* @param status The status value.867*868* @return A human readable nul-terminated string.869*/870ASTCENC_PUBLIC const char* astcenc_get_error_string(871astcenc_error status);872873#endif874875876