After the headers, an OpenEXR file holds one offset table per part and then the chunks of pixels. All numbers are little-endian; the sizes of the basic types are on the attribute types page.
Offset tables
Each entry is an unsigned long: the offset of a chunk from the start of
the file.
- In a single-part file with no
chunkCount, the number of entries comes fromdataWindow,tilesand the compression. - In a multi-part file, the number of entries is
chunkCount. - Scan line chunks are listed by increasing y, tiles by increasing y order.
Part number
In a multi-part file (version bit 12 set), every chunk starts with a part number. Part 0 is the first header’s part. Other files have no part number.
The two sources disagree on its size. The file layout document calls it an
unsigned long (8 bytes), but the library’s C core
(OpenEXRCore/chunk.c) reads it as a 4-byte int, together
with the y coordinate or tile coordinates that follow. The document says the library
takes precedence, so a reader should expect 4 bytes.
Scan line chunk
| Field | Type | Description |
|---|---|---|
| y | int | The top scan line of the block. The first block matches the data window’s minimum y. |
| Pixel data size | int | Bytes of pixel data. |
| Pixel data | bytes | The pixels, compressed if that made them smaller. |
Uncompressed pixels are stored top to bottom. Within each scan line the channels are in alphabetical order, each channel’s values together, left to right. The last block can hold fewer lines if the data window height is not a whole number of blocks.
| Compression | Scan lines per block |
|---|---|
NO_COMPRESSION | 1 |
RLE_COMPRESSION | 1 |
ZIPS_COMPRESSION | 1 |
ZIP_COMPRESSION | 16 |
PIZ_COMPRESSION | 32 |
PXR24_COMPRESSION | 16 |
B44_COMPRESSION | 32 |
B44A_COMPRESSION | 32 |
DWAA_COMPRESSION | 32 |
DWAB_COMPRESSION | 256 |
HTJ2K256_COMPRESSION | 256 |
HTJ2K32_COMPRESSION | 32 |
LJ2K (12, library only) | 256 |
ZSTD (13, library only) | 1 |
Tile chunk
| Field | Type | Description |
|---|---|---|
| Tile coordinates | 4 × int | tileX, tileY, levelX, levelY. |
| Pixel data size | int | Bytes of pixel data. |
| Pixel data | bytes | As for a scan line, using the tile’s width and height. |
Tiles at the right or bottom edge of a level can be narrower or shorter than the others.
Deep scan line chunk
Deep images store a variable number of samples per pixel. A deep scan line chunk is:
| Field | Type | Description |
|---|---|---|
| Part number | int (see above) | Only in multi-part files. |
| y | int | The scan line. |
| Packed size of the pixel offset table | 8 bytes (signed 64-bit in the library; type not stated in the layout document) | Bytes of compressed offset table. |
| Packed size of the sample data | 8 bytes (as above) | Bytes of compressed sample data. |
| Unpacked size of the sample data | unsigned long | Bytes once expanded. |
| Pixel offset table | compressed | The sample counts. |
| Sample data | compressed | The samples. |
A deep tile chunk has the same fields, with tile coordinates in place of y. The pixel
offset table has one int per column in the data window: entry n is the
total sample count of column n and all columns to its left.
Unpacked sample data stores all samples of the first channel, then all of the second,
and so on. With ZIP_COMPRESSION, up to 16 scan lines are stored together,
with the channels grouped within each scan line.
The file layout document allows deep parts only NO_COMPRESSION,
RLE_COMPRESSION, ZIPS_COMPRESSION and
ZIP_COMPRESSION. The library’s C core accepts NONE,
RLE, ZIPS and ZSTD for deep data, and not
ZIP.
RLE and ZIP data
A block is stored uncompressed whenever compressing would not make it smaller, so a packed size equal to the unpacked size means raw data. Otherwise RLE and ZIP (and ZIPS) first transform the uncompressed bytes, from the OpenEXR C core source:
- Split: bytes at even positions go to the first half of a buffer, bytes at odd positions to the second half (the first half has ⌈n / 2⌉ bytes).
- Predict: each byte after the first is replaced by (byte − previous byte + 128) mod 256.
ZIP and ZIPS then compress with zlib: a zlib stream with its 2-byte header and Adler-32 check, not raw deflate. RLE codes runs with a signed count byte: a negative count −n is followed by n literal bytes; a count c of 0 or more is followed by one byte repeated c + 1 times. Runs are 3 to 127 bytes long when written. To decode, reverse the steps: expand, add each byte to the one before it minus 128, then interleave the two halves again.
A complete file
The OpenEXR project’s sample is a 415-byte, uncompressed, single-part scan line file,
4 by 3 pixels, with channels G (half) and Z (float). Its
offset table holds 319, 351 and 383, one per scan line, and each block has 24 bytes of
pixel data: 4 × 2 bytes of G and 4 × 4 bytes of Z.
Sources
- OpenEXR File Layout – read as website/OpenEXRFileLayout.rst in the OpenEXR GitHub repository, including the sample file
- Technical Introduction to OpenEXR – read as website/TechnicalIntroduction.rst; compression summaries
- OpenEXR source – src/lib/OpenEXRCore/chunk.c (chunk headers), compression.c (lines per chunk, deep rules, zlib), internal_rle.c and internal_zip.c