7. Description of the ETC1 Compressed Texture Format

ETC1 compressed textures are compressed using the Ericsson Texture Compression (ETC) algorithm. This format is well suited to hardware decompression, allowing for higher-speed processing than conventional textures. This algorithm can compress each 4x4 texel block of a 24-bit color image (RGB8) down to just 8 bytes (64 bits), helping reduce texture memory requirements. However, the compression method applied by this algorithm assumes that the colors within each individual block tend to be similar, making it more suited to compression of photographs of landscapes or people than to images that have very different RGB component values (such as both red and blue areas) within the same blocks.

That said, this compression method works well for the 3DS system's own image format that adds a 4-bit alpha value to each texel (for 128 bits in total).

This chapter describes the ETC1 compressed texture format and the format conversions needed for use in the 3DS system.

7.1. ETC Format

The ETC format splits each 4x4 texel block into 4x2 or 2x4 sub-blocks. For each sub-block it stores a table containing the sub-block's base color (an RGB value) and delta values as compared to that base color. The format has two modes, individual mode and differential mode, but the only difference is in the format of the base color contained in the first 32 bits. The latter 32 bits are the same in both modes, and the decompression algorithm is also the same, aside from how it decodes the base color.

The following figure shows the ETC1 compressed texture bit layout. The data is arranged with the alpha channel coming before the color channel.

Figure 7-1. Bit Layout in ETC1 Compressed Textures

7.1.1. Texel Layout and Sub-Blocks

The latter 32 bits are further subdivided into MSB (most significant bit) and LSB (least significant bit) regions, of 16 bits each. In each region, the upper-left texel corresponds to the least significant bit. Bits increase in significance as you move from top to bottom down the texels, and the lower-right texel corresponds to the most significant bit. In other words, the least significant bits in each region (bits 0 and 16) correspond to the texel in the upper left, with the next texel down corresponding to the next-most-significant bit. Upon reaching the bottom of this column of texels, the next texel is at the top of the next column to the right, until reaching the most significant bits (bits 15 and 31) corresponding to the texel in the lower right of the block.

Depending on the flipbit (bit 32) value, the blocks are subdivided either vertically (2x4) or horizontally (4x2). These groups of eight subdivided texels are called sub-blocks, with either the left or top sub-block designated as sub-block 1, and the right or bottom sub-block as sub-block 2. The texel layout order differs depending on which way the block was subdivided.

Figure 7-2. Texel and sub-block Layout

Texel layout / sub-block layout / sub-block 1 / sub-block 2 / Flipbit

7.1.2. Determining the Base Color

The base color is determined separately for each sub-block, and the method for determining the format and base color depends on the diffbit value (bit 33).

With a diffbit value of 0, the format is individual mode and the R, G, and B components of the base color for each sub-block are assigned 4 bits each. Sub-block 1 is (R1, G1, B1) and sub-block 2 is (R2, G2, B2). The base color is the 8-bit value that results from concatenating this 4-bit value twice. (This binary operation is equivalent to multiplying the decimal value of the original 4 bits by 17.) With an R1 value of 1001b (9), the red component of the base color for sub-block 1 would be 10011001b (153).

With a diffbit value of 1 the format is differential mode. In this mode, the R, G, and B components for sub-block 1 are assigned 5 bits each. For sub-block 2, 3 bits are assigned to each component, with the values being the difference (delta values) as compared to the 5-bit values for sub-block 1. For sub-block 1 values (R1', G1', B1'), the sub-block 2 values are (R1'+dR2, G1'+dG2, B1'+dB2). The sub-block 1 base color is determined by concatenating the most-significant 3 bits of each component value after the initial 5 bits, for a total of 8 bits (effectively multiplying the original 5-bit value by 8.25). The sub-block 2 base color is determined by adding the 3-bit delta, expressed as a two's complement value (between +3 and -4), to the 5 bits of the sub-block 1 value, and then concatenating the most-significant 3 bits of each component value after the initial 5 bits. So for an R1' value of 11001b (25) and a dR2 value of 100b (-4), the base color red component of sub-block 1 is 11001110b (206), and the base color red component of sub-block 2 is 11001b (25) - 100b (4) = 10101b (21), which then becomes 10101101b (173). Combinations where the result of adding the delta value falls outside the range from 0 through 31 cause unstable operations. Such combinations must be avoided during compression.

Table 7-1. Bit Arrays and Post-Concatenation Values in Individual Mode
Bit Arrays Values Bit Arrays Values Bit Arrays Values Bit Arrays Values
0000b 0 0100b 68 1000b 136 1100b 204
0001b 17 0101b 85 1001b 153 1101b 221
0010b 34 0110b 102 1010b 170 1110b 238
0011b 51 0111b 119 1011b 187 1111b 255
Table 7-2. Bit Arrays, Post-Concatenation Values, and Values Plus Delta in Differential Mode
Bit Arrays Values

100b
(–4)

101b
(–3)

110b
(–2)

111b
(–1)

000b
(0)

001b
(+1)

010b
(+2)

011b
(+3)

00000b 0 - - - - 0 8 16 24
00001b 8 - - - 0 8 16 24 33
00010b 16 - - 0 8 16 24 33 41
00011b 24 - 0 8 16 24 33 41 49
00100b 33 0 8 16 24 33 41 49 57
00101b 41 8 16 24 33 41 49 57 66
00110b 49 16 24 33 41 49 57 66 74
00111b 57 24 33 41 49 57 66 74 82
01000b 66 33 41 49 57 66 74 82 90
01001b 74 41 49 57 66 74 82 90 99
01010b 82 49 57 66 74 82 90 99 107
01011b 90 57 66 74 82 90 99 107 115
01100b 99 66 74 82 90 99 107 115 123
01101b 107 74 82 90 99 107 115 123 132
01110b 115 82 90 99 107 115 123 132 140
01111b 123 90 99 107 115 123 132 140 148
10000b 132 99 107 115 123 132 140 148 156
10001b 140 107 115 123 132 140 148 156 165
10010b 148 115 123 132 140 148 156 165 173
10011b 156 123 132 140 148 156 165 173 181
10100b 165 132 140 148 156 165 173 181 189
10101b 173 140 148 156 165 173 181 189 198
10110b 181 148 156 165 173 181 189 198 206
10111b 189 156 165 173 181 189 198 206 214
11000b 198 165 173 181 189 198 206 214 222
11001b 206 173 181 189 198 206 214 222 231
11010b 214 181 189 198 206 214 222 231 239
11011b 222 189 198 206 214 222 231 239 247
11100b 231 198 206 214 222 231 239 247 255
11101b 239 206 214 222 231 239 247 255 -
11110b 247 214 222 231 239 247 255 - -
11111b 255 222 231 239 247 255 - - -

7.1.3. Determining the Delta Tables and Texel Colors

The final texel colors are determined by adding delta values selected from the delta table to the base color.

The delta table is specified by a "table codeword" (TableCW) section for each sub-block. Bits 37 through 39 are used for TableCW1 for sub-block 1, and bits 34 through 36 are used for TableCW2 for sub-block 2, with each 3-bit region allowing for 8 different bit values. Four delta values are given by the delta table. The delta values for each texel are determined using these in combination with the MSB and LSB. The selected delta value is added to all the RGB components of the base color, and the resulting values are clamped to the 0 through 255 range. For example, given a delta table value of 011b, an MSB of 1, and an LSB of 1, -42 is added to all components of the base color. Assuming a base color of (33, 198, 99), the resulting texel color is (0, 156, 57).

Table 7-3. TableCW, MSB, and LSB Combinations and Delta Values
TableCW MSB=1
LSB=1
MSB=1
LSB=0
MSB=0
LSB=0
MSB=0
LSB=1
000b -8 -2 +2 +8
001b -17 -5 +5 +17
010b -29 -9 +9 +29
011b -42 -13 +13 +42
100b -60 -18 +18 +60
101b -80 -24 +24 +80
110b -106 -33 +33 +106
111b -183 -47 +47 +183

7.2. PICA Native Format Compressed Textures

When using ETC1 compressed textures on the 3DS system, the format must be PICA native format. PICA native format follows the OpenGL ES standard specification, except for differences in the lookup origin and block layout for texels, and in the byte order.

7.2.1. V-Flipping

The texel lookup origin in the OpenGL ES specification is (u, v) = (0.0, 0.0), but on the 3DS system, this is (u, v) = (0.0, 1.0). You must first flip a texture image in the v coordinate direction (V-flip) before compressing it.

7.2.2. Block Format

ETC1-compressed textures define a metablock as two 4x4 texel blocks each in the u and v directions, for a total of 8x8 texels. Blocks within a metablock are laid out in a zigzag pattern, with the metablocks themselves laid out consecutively in the u direction.

Figure 7-3. Block Lookup Order in ETC1 Compressed Textures

Original u v 0.0 1.0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

7.2.3. Byte Order

The 3DS byte order differs from the OpenGL ES specification, due to differing endianness. Looking at the bit layout in terms of the actual byte order reveals the following points.

Figure 7-4. Bit Layout In Terms of Actual Byte Order

Color channel In both cases Diffbit +0 byte +1 byte +2 byte +3 byte Least significant pixel index bits (LSB) Most significant pixel index bits (MSB) Individual mode +4 byte +5 byte +6 byte +7 byte TableCW1 TableCW2 Flipbit BaseColor1 BaseColor2 B1 B2 G1 G2 R1 R2 DiffColor2 B1' dB2 G1' dG2 R1' dR2 Alpha channel

The color channel data is byte-swapped in units of 8 bytes, but alpha channel data is not byte-swapped. Alpha channel data still comes before color channel data.


CONFIDENTIAL