Industrial Training




JPEG File Layout and Format



APP0 (JFIF segment marker) marker:

Field Size Description

Marker Identifier 2 bytes 0xff, 0xe0 to identify APP0 marker

Length 2 bytes It must be >= 16

File Identifier Mark 5 bytes This identifies JFIF.

'JFIF'#0 (0x4a, 0x46, 0x49, 0x46, 0x00)

Major revision number 1 byte Should be 1, otherwise error

Minor revision number 1 byte Should be 0..2, otherwise try to decode anyway

Units for x/y densities 1 byte 0 = no units, x/y-density specify the aspect ratio instead

1 = x/y-density are dots/inch

2 = x/y-density are dots/cm

X-density 2 bytes It should be <> 0

Y-density 2 bytes It should be <> 0

Thumbnail width 1 byte -------

Thumbnail height 1 byte -------

Bytes to be read n bytes For thumbnail (RGB 24 bit), n = width*height*3 bytes should be read immediately followed by thumbnail height

Remarks:

    1. If there's no 'JFIF'#0, or the length is < 16, then it is probably not a JFIF segment and should be ignored.
    1. Normally units=0, x-dens=1, y-dens=1, meaning that the aspect ratio is 1:1 (evenly scaled).
    1. JFIF files including thumbnails are very rare, the thumbnail can usually be ignored. If there's no thumbnail, then width=0 and height=0.If the length doesn't match the thumbnail size, a warning may be printed, then continue decoding.

DHT( Define Huffman Table) marker:

Field Size Description

Marker Identifier 2 bytes 0xff, 0xc4 to identify DHT marker

Length 2 bytes This specify length of Huffman table

HT information 1 byte bit 0..3 : number of HT (0..3, otherwise error)

bit 4 : type of HT, 0 = DC table, 1 = AC table

bit 5..7 : not used, must be 0

Number of Symbols 16 bytes Number of symbols with codes of length 1..16,

the sum(n) of these bytes is the total number of codes,

which must be <= 256

Symbols n bytes Table containing the symbols in order of increasing

code length ( n = total number of codes ).

Remarks: A single DHT segment may contain multiple HTs, each with its own information byte.

DRI (Define Restart Interval) marker:

Field Size Description

Marker Identifier 2 bytes 0xff, 0xdd identifies DRI marker

Length 2 bytes It must be 4

Restart interval 2 bytes This is in units of MCU blocks, means that every n MCU

blocks a RSTn marker can be found. The first marker will

be RST0, then RST1 etc, after RST7 repeating from RST0.

DQT (Define Quantization Table) marker:

Field Size Description

Marker Identifier 2 bytes 0xff, 0xdb identifies DQT

Length 2 bytes This gives the length of QT.

QT information 1 byte bit 0..3: number of QT (0..3, otherwise error)

bit 4..7: precision of QT, 0 = 8 bit, otherwise 16 bit

Bytes n bytes This gives QT values, n = 64*(precision+1)

Remarks:

    1. A single DQT segment may contain multiple QTs, each with its own information byte.
    1. For precision=1 (16 bit), the order is high-low for each of the 64 words.

DAC (Define Arithmetic Table) marker:

  • Current software does not support arithmetic coding .

  • JPEG files using arithmetic coding can not be processed.

SOS (Start Of Scan) marker:

Field Size Description

Marker Identifier 2 bytes 0xff, 0xda identify SOS marker

Length 2 bytes This must be equal to 6+2*(number of components in scan).

Number of

Components in scan 1 byte This must be >= 1 and <=4 (otherwise error), usually 1 or 3

Each component 2 bytes For each component, read 2 bytes. It contains,

1 byte Component Id (1=Y, 2=Cb, 3=Cr, 4=I, 5=Q),

1 byte Huffman table to use :

bit 0..3 : AC table (0..3)

bit 4..7 : DC table (0..3)

Ignorable Bytes 3 bytes We have to skip 3 bytes.

Remarks: The image data (scans) is immediately following the SOS segment.



Hi I am Pluto.