After the header and any colour table the file holds the pixels of every mipmap level, one level straight after the other. There is no level directory, no size field and no padding: where a level starts follows from the header alone.
Order and rows
- The levels are stored largest first: level 0 is the largest, the one the LOD range names second, and the last level is the smallest.
- Within a level the rows run from the top row down, and the pixels of a row from left to right. A row has exactly width × pixel size bytes: no padding.
- Every level uses the same pixel format.
Size of each level
The longer side of level 0 is the largest LOD, and each next level has half the length (the smallest is 1). The shorter side follows from the aspect ratio, at least 1:
longer(k) = largest ÷ 2^k
shorter(k) = max(1, longer(k) × shorter-ratio ÷ longer-ratio)
For a 256-pixel texture with the ratio 1 1 the nine levels are:
| Level | Size | Pixels | Bytes at 1 byte a pixel | At 2 bytes | At 4 bytes |
|---|---|---|---|---|---|
| 0 | 256 × 256 | 65536 | 65536 | 131072 | 262144 |
| 1 | 128 × 128 | 16384 | 16384 | 32768 | 65536 |
| 2 | 64 × 64 | 4096 | 4096 | 8192 | 16384 |
| 3 | 32 × 32 | 1024 | 1024 | 2048 | 4096 |
| 4 | 16 × 16 | 256 | 256 | 512 | 1024 |
| 5 | 8 × 8 | 64 | 64 | 128 | 256 |
| 6 | 4 × 4 | 16 | 16 | 32 | 64 |
| 7 | 2 × 2 | 4 | 4 | 8 | 16 |
| 8 | 1 × 1 | 1 | 1 | 2 | 4 |
| All | 87381 | 87381 | 174762 | 349524 |
A level starts where the one before it ends. Level 0 starts at the header’s length, plus 80 bytes for a YIQ table or 1024 for a palette.
Checking the size of a file
A well-formed file is exactly header + table + Σ(width × height) × pixel size
bytes long. Examples from real files:
| Format and levels | Header | Table | Pixels | File size |
|---|---|---|---|---|
| rgb565, 256 × 256, 9 levels | 51 | 0 | 87381 × 2 = 174762 | 174813 |
| yiq, 256 × 256, 9 levels | 48 | 80 | 87381 | 87509 |
| p8, 256 × 256, 9 levels | 47 | 1024 | 87381 | 88452 |
| argb8888, 256 × 256, 9 levels | 53 | 0 | 87381 × 4 = 349524 | 349577 |
| ayiq8422, ratio 1 2, 128 long, 8 levels | 53 | 80 | 10923 × 2 = 21846 | 21979 |
The last row has levels of 64 × 128, 32 × 64, 16 × 32, 8 × 16, 4 × 8, 2 × 4, 1 × 2 and 1 × 1 pixels, which add up to 10923 pixels. Among the 212 distinct files checked every file had exactly this size, so no file has bytes after the last level.
Files with fewer levels
A LOD range such as 128 128 holds one level and no smaller ones; the
file is then just the header, any table and one level. Of the 212 files checked, 19 have one level and the rest have from
2 to 9.