Industrial Training




JPEG File Layout and Format 2



JPEG File Layout and Format

The File Layout


A JPEG file is partitioned by markers. Each marker is immediately preceded by an all 1 byte (0xff). Although there are more markers, We will discuss the following markers:

Marker Name

Marker Identifier

Description

SOI

0xd8

Start of Image

APP0

0xe0

JFIF application segment

APPn

0xe1 – 0xef

Other APP segments

DQT

0xdb

Quantization Table

SOF0

0xc0

Start of Frame

DHT

0xc4

Huffman Table

SOS

0xda

Start of Scan

EOI

0xd9

End of Image

If a 0xff byte occurs in the compressed image data either a zero byte (0x00) or a marker identifier follows it. Normally the only marker that should be found once the image data is started is an EOI. When a 0xff byte is found followed by a zero byte (0x00) the zero byte must be discarded.

A JPEG file consists of the eight following parts:

  1. A Start of Image SOI

  2. An APP0 Marker

    1. APP0 length

    2. Identifier

    3. Version

    4. Units for X & Y densities

    5. X density

    6. Y density

    7. Thumbnail horizontal pixels

    8. Thumbnail vertical pixels

    9. Thumbnail RGB bitmap

  3. APPn Markers where n can be form 1 to 15 (Optional)

    1. APPn length

    2. Application specific information

  4. One or more quantization tables DQT

    1. Quantization table length

    2. Quantization table number

    3. Quantization table

  5. A Start of Frame SOF0

    1. Start of Frame length

    2. Precision (Bits per pixel per color component)

    3. Image height

    4. Image width

    5. Number of color components

    6. For each component

      1. An ID

      2. A vertical sample factor

      3. A horizontal sample factor

      4. A quantization table#

  6. One or more huffman tables DHT

    1. Huffman table length

    2. Type, AC or DC

    3. Index

    4. A Bits table

    5. A Value table

  7. A Start of Scan SOS

    1. Start of Scan length

    2. Number of color components

    3. For each component

      1. An ID

      2. An AC table #

      3. An DC table #

    4. Compressed image data (Not included in Start of Scan length)

  8. An End of Image EOI

JPEG File Format

Header :

  1. · It occupies two bytes.
  2. · 0xff, 0xd8 (SOI : Start Of Image ) (these two identify a JPEG/JFIF file)

Segments or markers:

  1. · Following the SOI marker, there can be any number of “segments” or “markers” such as APP0,DQT, DHT, SOF, SOS and so on.
  2. · An APP0 segment is immediately follows the SOI marker.

Trailer:

  1. · It occupies two bytes.
  2. · 0xff, 0xd9 (EOI: End of Image) (these two identify end of image).

Format of each segment:

Header (4 bytes):

0xff 1byte identifies segment .

n 1byte type of segment.

sh, sl 2bytes size of the segment, including these two bytes, but not including the 0xff and the type byte. Note, not intel order: high byte first, low byte last!

Contents of the segment: max. 65533 bytes.

Notes:

    1. There are parameterless segments (denoted with a '*' below) that DON'T have a size specification (and no contents), just 0xff and the type byte.
    1. Any number of 0xff bytes between segments is legal and must be skipped.

Segment types:

SOI 0xd8 Start Of Image

APP0 0xe0 JFIF APP0 segment marker,

APP15 0xef ignore

SOF0 0xc0 Start Of Frame (baseline JPEG), for details see below

SOF1 0xc1 Start Of Frame (baseline JPEG), for details see below

SOF2 0xc2 usually unsupported

SOF3 0xc3 usually unsupported

SOF5 0xc5 usually unsupported

SOF6 0xc6 usually unsupported

SOF7 0xc7 usually unsupported

SOF9 0xc9 for arithmetic coding, usually unsupported

SOF10 0xca usually unsupported

SOF11 0xcb usually unsupported

SOF13 0xcd usually unsupported

SOF14 0xce usually unsupported

SOF15 0xcf usually unsupported

DHT 0xc4 Define Huffman Table

DQT 0xdb Define Quantization Table

SOS 0xda Start Of Scan

JPG 0xc8 undefined/reserved (causes decoding error)

JPG0 0xf0 ignore (skip)

JPG13 0xfd ignore (skip)

DAC 0xcc Define Arithmetic Table, usually unsupported

DNL 0xdc usually unsupported, ignore

DRI 0xdd Define Restart Interval, for details see below

DHP 0xde ignore (skip)

EXP 0xdf ignore (skip)

*RST0 0xd0 RSTn are used for resync, may be ignored

*RST1 0xd1

*RST2 0xd2

*RST3 0xd3

*RST4 0xd4

*RST5 0xd5

*RST6 0xd6

*RST7 0xd7

*TEM 0x01 usually causes a decoding error, may be ignored

COM 0xfe Comment, may be ignored

EOI 0xd9 End Of Image

All other segment types are reserved and should be ignored (skipped).

SOF0 (Start Of Frame 0) marker:

Field Size Description

Marker Identifier 2 bytes 0xff, 0xc0 to identify SOF0 marker

Length 2 bytes This value equals to 8 + components*3 value

Data precision 1 byte This is in bits/sample, usually 8

(12 and 16 not supported by most software).

Image height 2 bytes This must be > 0

Image Width 2 bytes This must be > 0

Number of components 1 byte Usually 1 = grey scaled, 3 = color YcbCr or YIQ

4 = color CMYK

Each component 3 bytes Read each component data of 3 bytes. It contains,

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

sampling factors (1byte) (bit 0-3 vertical., 4-7 horizontal.),

quantization table number (1 byte)).

Remarks: JFIF uses either 1 component (Y, greyscaled) or 3 components (YCbCr, sometimes called YUV, colour).



Hi I am Pluto.