Project

General

Profile

Actions

The Metadata in JPEG files » History » Revision 5

« Previous | Revision 5/36 (diff) | Next »
Tuan Nhu, 22 Jul 2013 11:41


The Metadata in JPEG files

This article shares my investigations about the metadata structure in JPEG files. It also introduces briefly the algorithm used in exiv2 to read and write Exif, IPTC, XMP data and image comments on the JPEG files.

Background

JPEG ISO standard is a commonly used method of lossy compression for digital photography. The name "JPEG" stands for Joint Photographic Experts Group, the name of the committee.

JPEG refers only to a class of compression algorithms, not to a specific file format. In order to produce files with embedded JPEG streams, a number of file format standards have been adapted or devised. Some of them are JPEG /JFIF, JPEG /SPIFF (Still Picture Interchange File Format), JPEG /CIFF, JPEG/Exif (Exchangeable image file format).

Among them, the most common types are JPEG/Exif and JPEG/JFIF.
  • JPEG/Exif is the most common image format used by digital cameras and other photographic image capture devices.
  • JPEG/JFIF is the most common format for storing and transmitting photographic images on the World Wide Web.

The metadata structure in JPEG

A JPEG file contains several segments; each segment contains different kinds of data, delimited by two-byte codes called markers. The markers are hexadecimal; they begin with 0xFF and end with a code (1 byte) indicating the kind of marker.

Some markers consist of just those two bytes; others are followed by two bytes indicating the length of marker-specific payload data that follows. The length includes the two bytes for the length, but not the two bytes for the marker.

Short name Bytes Payload Name and Comments
SOI 0xFF, 0xD8 None Start Of Image
SOF0 0xFF, 0xC0 Variable size Start Of Frame (Baseline DCT)
Indicates that this is a baseline DCT-based JPEG, and specifies the width, height, number of components, and component subsampling
SOF2 0xFF, 0xC2 Variable size Start Of Frame (Progressive DCT)
Indicates that this is a progressive DCT-based JPEG, and specifies the width, height, number of components, and component subsampling
DHT 0xFF, 0xC4 Variable size Define Huffman Table(s)
DQT 0xFF, 0xDB Variable size Define Quantization Table(s)
DRI 0xFF, 0xDD 2 bytes Define Restart Interval
Specifies the interval between RSTn markers, in macroblocks. This marker is followed by two bytes indicating the fixed size so it can be treated like any other variable size segment.
SOS 0xFF, 0xDA Variable size Start Of Scan
Begins a top-to-bottom scan of the image. In baseline DCT JPEG images, there is generally a single scan. Progressive DCT JPEG images usually contain multiple scans. This marker specifies which slice of data it will contain, and is immediately followed by entropy-coded data.
RSTn 0xFF, 0xDn
n(n=0..7)
None Restart
Inserted every r macroblocks, where r is the restart interval set by a DRI marker. Not used if there was no DRI marker. The low 3 bits of the marker code cycle in value from 0 to 7.
APPn 0xFF, 0xEn Variable size Application-specific
For example, an Exif JPEG file uses an APP1 marker to store metadata, laid out in a structure based closely on TIFF.
COM 0xFF, 0xFE Variable size Comment
EOI 0xFF, 0xD9 None End Of Image

Fig.1. The common JPEG markers. From Wikipedia, https://en.wikipedia.org/wiki/JPEG

Updated by Tuan Nhu over 8 years ago · 5 revisions