What is JPEG?

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

Baseline DCT

SOF1

0xFFC1

Variable

Extended sequential DCT

SOF2

0xFFC2

Variable

Progressive DCT

SOF3

0xFFC3

Variable

Sequential losses

SOF5

0xFFC5

Variable

Differential sequential DCT

SOF6

0xFFC6

Variable

Differential progressive DCT

SOF7

0xFFC7

Variable

Differential losses

SOF9

0xFFC9

Variable

Extended sequential DCT

SOF10

0xFFCA

Variable

Progressive DCT

SOF11

0xFFCB

Variable

Sequential losses

SOF13

0xFFCD

Variable

Differential sequential DCT

SOF14

0xFFCE

Variable

Differential progressive DCT

SOF15

0xFFCF

Variable

Differential losses

APPn

0xFFE0-0xFFEF

Variable

Application markers

COM

0xFFFE

Variable

Comment

DAC

0xFFCC

Variable

Arithmetic conditioning table(s)

DHP

0xFFDE

Variable

Define hierarchical progression

DHT

0xFFC4

Variable

Huffman table(s)

DNL

0xFFDC

4

Number of lines.

DQT

0xFFDB

Variable

Quantization tables(s)

DRI

0xFFDD

4

Restart interval

EOI

0xFFD9

0

End of image

EXP

0xFFDF

3

Expand reference image(s)

JPG

0xFFC8

 

Reserved

JPGn

0xFFF0-0xFFFD

 

Reserved

RES

0xFF02-0xFFBF

 

Reserved

RSTn

0xFFD0-0xFFD7

 

Restart with module 8 counter

SOI

0xFFD8

0

Start of image

SOS

0xFFDA

0

Start of scan

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

Frame header length

 

Lf

16

Sample precision

 

P

8

Number of lines

 

Y

16

Number of samples per line

 

X

16

Number of components in frame

 

Nf

8

Frame components (1 ... Nf)

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

Scan header length

 

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

End of spectral selection

 

Se

8

Successive approximation bit position high

 

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

Huffman table definition length

 

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

Arithmetic coding conditioning table length

 

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

Quantization table definition length

 

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