The frame header says how large the image is, how many components it has and how they are sampled. Its marker also says how the image was coded. It is defined in section B.2.2 of ITU-T T.81.
Coding processes
The marker's code picks the process. Most programs handle only the first three.
SOF4, SOF8 and SOF12 do not exist: those codes are
DHT, JPG and DAC.
| Marker | Name | Process | Sample bits |
|---|---|---|---|
FF C0 | SOF0 | Baseline sequential DCT, Huffman coding | 8 |
FF C1 | SOF1 | Extended sequential DCT, Huffman coding | 8, 12 |
FF C2 | SOF2 | Progressive DCT, Huffman coding | 8, 12 |
FF C3 | SOF3 | Lossless sequential, Huffman coding | 2 to 16 |
FF C5 | SOF5 | Differential sequential DCT, Huffman coding | 8, 12 |
FF C6 | SOF6 | Differential progressive DCT, Huffman coding | 8, 12 |
FF C7 | SOF7 | Differential lossless, Huffman coding | 2 to 16 |
FF C9 | SOF9 | Extended sequential DCT, arithmetic coding | 8, 12 |
FF CA | SOF10 | Progressive DCT, arithmetic coding | 8, 12 |
FF CB | SOF11 | Lossless sequential, arithmetic coding | 2 to 16 |
FF CD | SOF13 | Differential sequential DCT, arithmetic coding | 8, 12 |
FF CE | SOF14 | Differential progressive DCT, arithmetic coding | 8, 12 |
FF CF | SOF15 | Differential lossless, arithmetic coding | 2 to 16 |
Baseline uses 8-bit samples only. The processes marked differential belong to the hierarchical mode, in which several frames follow a DHP segment.
The segment
0MarkerFF C0or another SOFn2 bytes2Lf segment length, 8 + 3 × Nf2 bytes4P sample precision in bits1 byte5Y number of lines2 bytes7X samples per line2 bytes9Nf number of components1 byte10Component 13 bytes…Further components3 bytes each
| Offset | Size | Field | Description |
|---|---|---|---|
| 4 | 1 | P | Bits per sample |
| 5 | 2 | Y | Image height. 0 means a DNL segment after the first scan gives the height. |
| 7 | 2 | X | Image width, at least 1 |
| 9 | 1 | Nf | Number of components: 1 to 4 in a progressive image, up to 255 in sequential and lossless |
Each component
| Offset | Size | Field | Description |
|---|---|---|---|
| 0 | 1 | Ci | Component identifier. Scans name components by this. |
| 1 | ½ | Hi (high 4 bits) | Horizontal sampling factor, 1 to 4 |
| 1 | ½ | Vi (low 4 bits) | Vertical sampling factor, 1 to 4 |
| 2 | 1 | Tqi | Number of the quantisation table the component uses, 0 to 3 |
JFIF files use 1 for Y, 2 for Cb and 3 for Cr. A file with components named by the letters R, G and B (82, 71 and 66) is usually taken to be RGB, with no colour transform.
Sampling and blocks
Components can be stored at different resolutions. Hmax and
Vmax are the largest factors in the frame. Component i has
x = ⌈X × Hi / Hmax⌉ samples across and
y = ⌈Y × Vi / Vmax⌉ lines down.
The samples are divided into blocks of 8 × 8, called data units. A component coded by
itself has ⌈x / 8⌉ × ⌈y / 8⌉ blocks. A component coded with others in the
same scan follows the MCU layout below, which rounds up to whole MCUs, so its blocks can
be more.
YY blocks Hi × Vi of them, in rows, left to rightHi × Vi blocksCbCb blocksHi × Vi blocksCrCr blocksHi × Vi blocks
Minimum coded units
An MCU is the group of blocks coded together. In a scan with one component it is one
block. In a scan with several components it covers
8 × Hmax pixels by 8 × Vmax, and holds
Hi × Vi blocks of each component, one component after another, each
component's blocks left to right and top to bottom. An MCU may hold at most 10 blocks.
MCUs at the right and bottom edges are always whole: a component that does not fill one
is padded out with blocks of its own, which a decoder discards.
The number of MCUs is ⌈X / (8 × Hmax)⌉ across and
⌈Y / (8 × Vmax)⌉ down.
| Common name | Y | Cb, Cr | MCU size | Blocks in an MCU |
|---|---|---|---|---|
| 4:4:4 | 1 × 1 | 1 × 1 | 8 × 8 | 3 |
| 4:2:2 | 2 × 1 | 1 × 1 | 16 × 8 | 4 |
| 4:2:0 | 2 × 2 | 1 × 1 | 16 × 16 | 6 |
| 4:1:1 | 4 × 1 | 1 × 1 | 32 × 8 | 6 |
DNL: the height, sent later
When Y is 0, a DNL segment (FF DC, length 4, 2-byte line count) directly
after the first scan gives the height. Such files are rare, and browsers do not read
them.