1cc1dc7a3Sopenharmony_ci# The .astc File Format
2cc1dc7a3Sopenharmony_ci
3cc1dc7a3Sopenharmony_ciThe default file format for compressed textures generated by `astcenc`, as well
4cc1dc7a3Sopenharmony_cias from many other ASTC compressors, is the `.astc` format. This is a very
5cc1dc7a3Sopenharmony_cisimple format consisting of a small header followed immediately by the binary
6cc1dc7a3Sopenharmony_cipayload for a single image surface.
7cc1dc7a3Sopenharmony_ci
8cc1dc7a3Sopenharmony_ciHeader
9cc1dc7a3Sopenharmony_ci======
10cc1dc7a3Sopenharmony_ci
11cc1dc7a3Sopenharmony_ciThe header is a fixed 16 byte structure, defined as storing only bytes to avoid
12cc1dc7a3Sopenharmony_ciany endianness issues or incur any padding overhead.
13cc1dc7a3Sopenharmony_ci
14cc1dc7a3Sopenharmony_ci```
15cc1dc7a3Sopenharmony_cistruct astc_header
16cc1dc7a3Sopenharmony_ci{
17cc1dc7a3Sopenharmony_ci    uint8_t magic[4];
18cc1dc7a3Sopenharmony_ci    uint8_t block_x;
19cc1dc7a3Sopenharmony_ci    uint8_t block_y;
20cc1dc7a3Sopenharmony_ci    uint8_t block_z;
21cc1dc7a3Sopenharmony_ci    uint8_t dim_x[3];
22cc1dc7a3Sopenharmony_ci    uint8_t dim_y[3];
23cc1dc7a3Sopenharmony_ci    uint8_t dim_z[3];
24cc1dc7a3Sopenharmony_ci};
25cc1dc7a3Sopenharmony_ci```
26cc1dc7a3Sopenharmony_ci
27cc1dc7a3Sopenharmony_ciMagic number
28cc1dc7a3Sopenharmony_ci------------
29cc1dc7a3Sopenharmony_ci
30cc1dc7a3Sopenharmony_ciThe 4 byte magic number at the start of the file acts as a format identifier.
31cc1dc7a3Sopenharmony_ci
32cc1dc7a3Sopenharmony_ci```
33cc1dc7a3Sopenharmony_ci    magic[0] = 0x13;
34cc1dc7a3Sopenharmony_ci    magic[1] = 0xAB;
35cc1dc7a3Sopenharmony_ci    magic[2] = 0xA1;
36cc1dc7a3Sopenharmony_ci    magic[3] = 0x5C;
37cc1dc7a3Sopenharmony_ci```
38cc1dc7a3Sopenharmony_ci
39cc1dc7a3Sopenharmony_ciBlock size
40cc1dc7a3Sopenharmony_ci----------
41cc1dc7a3Sopenharmony_ci
42cc1dc7a3Sopenharmony_ciThe `block_*` fields store the ASTC block dimensions in texels. For 2D images
43cc1dc7a3Sopenharmony_cithe Z dimension must be set to 1.
44cc1dc7a3Sopenharmony_ci
45cc1dc7a3Sopenharmony_ciImage dimensions
46cc1dc7a3Sopenharmony_ci----------------
47cc1dc7a3Sopenharmony_ci
48cc1dc7a3Sopenharmony_ciThe `dim_*` fields store the image dimensions in texels.  For 2D images the
49cc1dc7a3Sopenharmony_ciZ dimension must be set to 1.
50cc1dc7a3Sopenharmony_ci
51cc1dc7a3Sopenharmony_ciNote that the image is not required to be an exact multiple of the compressed
52cc1dc7a3Sopenharmony_ciblock size; the compressed data may include padding that is discarded during
53cc1dc7a3Sopenharmony_cidecompression.
54cc1dc7a3Sopenharmony_ci
55cc1dc7a3Sopenharmony_ciEach dimension is a 24 bit unsigned value that is reconstructed from the stored
56cc1dc7a3Sopenharmony_cibyte values as:
57cc1dc7a3Sopenharmony_ci
58cc1dc7a3Sopenharmony_ci```
59cc1dc7a3Sopenharmony_cidecoded_dim = dim[0] + (dim[1] << 8) + (dim[2] << 16);
60cc1dc7a3Sopenharmony_ci```
61cc1dc7a3Sopenharmony_ci
62cc1dc7a3Sopenharmony_ciBinary payload
63cc1dc7a3Sopenharmony_ci==============
64cc1dc7a3Sopenharmony_ci
65cc1dc7a3Sopenharmony_ciThe binary payload is a byte stream that immediately follows the header. It
66cc1dc7a3Sopenharmony_cicontains 16 bytes per compressed block. The number of compressed blocks is
67cc1dc7a3Sopenharmony_cidetermined from the header information.
68cc1dc7a3Sopenharmony_ci
69cc1dc7a3Sopenharmony_ci- - -
70cc1dc7a3Sopenharmony_ci
71cc1dc7a3Sopenharmony_ci_Copyright © 2020-2022, Arm Limited and contributors. All rights reserved._
72