Summary: This module briefly look at the sync codes and header information that are needed in order to complete the coding process.
We have described how individual
JPEG is rather complex in this aspect, so we shall just give an overview of the basic principles (see the JPEG Book, chapter 7 for the full picture).
JPEG data is divided into segments, each of which starts with a 2-byte marker.
All markers are byte-aligned - they start on the byte boundaries of the transmission/storage medium. Any variable-length data which precedes a marker is padded with extra ones to achieve this.
The first byte of each marker is
To allow for recovery in the presence of errors, it must be possible
to detect markers without decoding all of the intervening data. Hence
markers must be unique. To achieve this, if an
Some important markers in the order they are often used are:
| Name | Code (hex) | Purpose |
|---|---|---|
| SOI | FFD8 | Start of image. |
| COM | FFFE |
Comment (segment ignored by decoder).
|
| DQT | FFDB |
Define quantisation table(s).
|
|
|
FFC0 |
Start of Baseline DCT frame.
|
| DHT | FFC4 |
Define Huffman
table(s).
|
| SOS | FFDA |
Start of
scan.
|
| EOI | FFD9 | End of image. |
In Table 1 the data which follows each
marker is shown between <> brackets. The first 2-byte word of most
segments is the length (in bytes) of the segment,
Long blocks of entropy-coded data are rather prone to being corrupted by transmission errors. To mitigate the worst aspects of this, Restart Markers (FFD0 → FFD7) may be included at regular intervals (say at the start of each row of DCT blocks in the image) so that separate parts of the entropy coded stream may be decoded independently of errors in other parts. The restart interval, if required, is defined by a DRI (FFDD) marker segment. There are 8 restart markers, which are used in sequence, so that if one (or more) is corrupted by errors, its absence may be easily detected.
The use of multiple scans within each image frame and multiple frames within a given image allows many variations on the ordering and interleaving of the compressed data. For example: