Theoretical Paper
- Computer Organization
- Data Structure
- Digital Electronics
- Object Oriented Programming
- Discrete Mathematics
- Graph Theory
- Operating Systems
- Software Engineering
- Computer Graphics
- Database Management System
- Operation Research
- Computer Networking
- Image Processing
- Internet Technologies
- Micro Processor
- E-Commerce & ERP
Practical Paper
Industrial Training
JPEG File Layout and Format
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:
-
A Start of Image SOI
-
An APP0 Marker
-
APP0 length
-
Identifier
-
Version
-
Units for X & Y densities
-
X density
-
Y density
-
Thumbnail horizontal pixels
-
Thumbnail vertical pixels
-
Thumbnail RGB bitmap
-
-
APPn Markers where n can be form 1 to 15 (Optional)
-
APPn length
-
Application specific information
-
-
One or more quantization tables DQT
-
Quantization table length
-
Quantization table number
-
Quantization table
-
-
A Start of Frame SOF0
-
Start of Frame length
-
Precision (Bits per pixel per color component)
-
Image height
-
Image width
-
Number of color components
-
For each component
-
An ID
-
A vertical sample factor
-
A horizontal sample factor
-
A quantization table#
-
-
-
One or more huffman tables DHT
-
Huffman table length
-
Type, AC or DC
-
Index
-
A Bits table
-
A Value table
-
-
A Start of Scan SOS
-
Start of Scan length
-
Number of color components
-
For each component
-
An ID
-
An AC table #
-
An DC table #
-
-
Compressed image data (Not included in Start of Scan length)
-
-
An End of Image EOI
JPEG File Format
Header :
- · It occupies two bytes.
- · 0xff, 0xd8 (SOI : Start Of Image ) (these two identify a JPEG/JFIF file)
Segments or markers:
- · Following the SOI marker, there can be any number of “segments” or “markers” such as APP0,DQT, DHT, SOF, SOS and so on.
- · An APP0 segment is immediately follows the SOI marker.
Trailer:
- · It occupies two bytes.
- · 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:
-
- There are parameterless segments (denoted with a '*' below) that DON'T have a size specification (and no contents), just 0xff and the type byte.
-
- 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).