JPEG (Joint Photographic Experts Group) is one of the most popular file formats for storing 8 and 24 bit continuos tone grayscale and color images.
The high efficient JPEG compression modes are:
Non-differential Huffman coding
Differential Huffman coding
Non-differential arithmetic coding.
Differential arithmetic coding.
Every class of compression method is based on the DCT (Discrete Cosine Transform) with un-correlated co-efficients. Each co-efficient can be treated independently without loss of compression efficiency. JPEG transforms the RGB data of the image into a YUV coordinate system, where the new coordinates can be evaluated in the following way:
Y = 0.3R + 0.6G + 0.1 B
V = R-Y
U = B-Y
A JPEG file can be navigated with the following markers.
Marker |
Code |
Length |
Category |
SOF0 |
0xFFC0 |
Variable |
|
SOF1 |
0xFFC1 |
Variable |
|
SOF2 |
0xFFC2 |
Variable |
|
SOF3 |
0xFFC3 |
Variable |
|
SOF5 |
0xFFC5 |
Variable |
|
SOF6 |
0xFFC6 |
Variable |
|
SOF7 |
0xFFC7 |
Variable |
|
SOF9 |
0xFFC9 |
Variable |
|
SOF10 |
0xFFCA |
Variable |
|
SOF11 |
0xFFCB |
Variable |
|
SOF13 |
0xFFCD |
Variable |
|
SOF14 |
0xFFCE |
Variable |
|
SOF15 |
0xFFCF |
Variable |
|
APPn |
0xFFE0-0xFFEF |
Variable |
|
COM |
0xFFFE |
Variable |
|
DAC |
0xFFCC |
Variable |
|
DHP |
0xFFDE |
Variable |
|
DHT |
0xFFC4 |
Variable |
|
DNL |
0xFFDC |
4 |
|
DQT |
0xFFDB |
Variable |
|
DRI |
0xFFDD |
4 |
|
EOI |
0xFFD9 |
0 |
|
EXP |
0xFFDF |
3 |
|
JPG |
0xFFC8 |
|
Reserved |
JPGn |
0xFFF0-0xFFFD |
|
Reserved |
RES |
0xFF02-0xFFBF |
|
Reserved |
RSTn |
0xFFD0-0xFFD7 |
|
Restart with module 8 counter |
SOI |
0xFFD8 |
0 |
|
SOS |
0xFFDA |
0 |
|
TEM |
0xFF01 |
0 |
For temporary use |
JPEG divides the compression sequence into frames and scans. Frames define the basic attributes of the image (size, number of components and coding technique).
The frame header (SOFn) structure is as follows:
Tag |
|
Symbol |
Size in bits |
|
Lf |
16 |
|
|
P |
8 |
|
|
Y |
16 |
|
|
X |
16 |
|
|
Nf |
8 |
|
Component id. |
Ci |
8 |
|
|
Horizontal sampling factor |
Hi |
4 |
|
Vertical sampling factor |
Vi |
4 |
|
Quantization table destination selector |
Tqi |
8 |
Scans: The scan header(SOS) structure:
Tag |
|
Symbol |
Size in bits |
|
Ls |
16 |
|
Number of components in scan |
|
Ns |
8 |
Scancomponents (1 ... Ns) |
Scan component selector |
Csk |
8 |
|
DC entropy coding table selector |
Tdk |
4 |
|
AC entropy coding table selector |
Tak |
4 |
Start of spectral selection of predictor selection |
|
Ss |
8 |
|
Se |
8 |
|
|
Ah |
4 |
|
Successive approximation bit position low or point transform |
Quantization table destination selector |
Al |
4 |
Using custom Huffman code table significantly improves the efficiency of coding. Once a Huffman table is defined, it may be used for subsequent images. The DHT marker segment structure:
Tag |
|
Symbol |
Size in bits |
|
Lh |
16 |
|
For each Huffman table |
Table class |
Tc |
4 |
|
Huffman table identifier |
Th |
4 |
|
Number of Huffman codes of length (1..16) |
Li |
8 |
|
Value associated with each Huffman codes (1..16) (1..Li) |
Lij |
8 |
The DAC marker segment structure:
Tag |
|
Symbol |
Size in bits |
|
La |
16 |
|
For each table |
Table class |
Tc |
4 |
|
Arithmetic coding condition identifier |
Ta |
4 |
|
Conditioning table value |
Cs |
8 |
The DQT marker segment structure
Tag |
|
Symbol |
Size in bits |
|
Lq |
16 |
|
For each table |
Quantimization table element precision |
Pq |
4 |
|
Quantimization table identifier |
Tq |
4 |
|
Quantimization table element (0..63) |
Qk |
8 or 16 |
JPEG has a mechanism for dividing the compressed data into independently decodable segments called restart intervals. If restart is enabled in an RSTm marker, an RST marker must be placed between the entropy coded segments for each restart interval. The DRI marker segment structure:
Tag |
Symbol |
Size in bits |
Define restart interval segment length |
Lr |
16 |
Restart interval |
Ri |
16 |