JPEG
m |
(New section about JPEG types) |
||
Line 29: | Line 29: | ||
An APP segment's data usually begins with NUL-terminated string to identify the type of data contained in it. The actual payload data then begins after the NUL byte. This is a convention, not a part of the JPEG specification. | An APP segment's data usually begins with NUL-terminated string to identify the type of data contained in it. The actual payload data then begins after the NUL byte. This is a convention, not a part of the JPEG specification. | ||
+ | |||
+ | == Types of JPEG files == | ||
+ | |||
+ | The following types are not disjoint. For example, a progressive JPEG may use arithmetic coding. | ||
+ | |||
+ | === Baseline === | ||
+ | |||
+ | JPEGs with an SOF0 marker are known as ''Baseline'' JPEGs. They are always lossy, not progressive, use Huffman coding, and have a bit depth of 8. Every application that supports JPEG is supposed to at least support Baseline JPEG. | ||
+ | |||
+ | === Progressive === | ||
+ | |||
+ | Progressive JPEG rearranges the image data, so that the the first part of it represents a very low quality version of the entire image, rather than a high quality version of a small part of the image. | ||
+ | |||
+ | === Arithmetic coding === | ||
+ | |||
+ | Even lossy JPEG makes use of a lossless compression algorithm. The lossless algorithm is usually [[Huffman coding]], but [[arithmetic coding]] may be used instead. JPEG's arithmetic coding usually results in a smaller file size, but it is not as widely supported as one might hope, probably because it used to be encumbered by [[patents]]. | ||
+ | |||
+ | === 12-bit === | ||
+ | |||
+ | Except for Baseline JPEG, all lossy types of JPEG may use a bit depth of either 8 or 12 bits per sample. Few applications support 12 bits, though. | ||
+ | |||
+ | === Lossless JPEG === | ||
+ | |||
+ | JPEG supports true lossless compression, but it is used so rarely that JPEG is commonly thought of as strictly a lossy format. A lossless JPEG image may have any bit depth from 2 to 16. Few applications support lossless JPEG, but it does find some use in the medical industry, such as in [[DICOM]] files. | ||
+ | |||
+ | === Hierarchical === | ||
+ | |||
+ | Also called "differential", hierarchical JPEG is vaguely similar to progressive JPEG, but geared toward storing multiple sizes of the same image, such that the decoder can select the size it prefers. Hierarchical JPEGs are, to a close approximation, nonexistent. | ||
== Related Formats == | == Related Formats == |
Revision as of 18:10, 23 February 2013
JPEG, named after the Joint Photographic Experts Group, which created the format, is a lossy compressed format well-suited to photographic images. Line drawings do better with non-lossy compressed bitmaps such as GIF and PNG.
Depending on context, "JPEG" may mean the compression algorithm, or the JPEG interchange format (JIF) defined in the JPEG standard.
In and of itself, JPEG is not really a suitable format for image interchange, for several reasons:
- It essentially only defines a way to store one or more arrays of numbers. It does not say how to interpret those numbers as an image. The decoder will just have to guess.
- It is large and general, and it would be unrealistic to expect every decoder to support all of it.
- It has no standard way to store metadata.
To address these issues, a number of JPEG subformats have been invented. JFIF is by far the most popular of them, though a significant minority of JPEG files use Exif/JPEG instead. The SPIFF file format was intended as a replacement for JFIF but never caught on widely.
Contents |
Format
A JPEG file consists largely of a sequence of tagged segments. Each segment begins with a two-byte "marker". The first byte of a marker is 0xff. The second may have any value except 0x00 or 0xff, and indicates the type of data stored in the segment. Segment types are assigned names; for example, 0xd9 is "SOI", and 0xe1 is "APP1".
Segment types 0x01, and 0xd0 through 0xd9, consist entirely of the two-byte marker. All other markers are followed by a two-byte integer indicating the size of the segment, followed by the payload data contained in the segment.
The image data is the exception to this segmented format. It appears between the 0xda ("SOS") and 0xd9 ("EOI") segments, but there is no prefix to indicate its size. Instead, any 0xff bytes in the image data are escaped as 0xff 0x00, so that they won't be mistaken for markers.
Application segments
There are 16 segment types reserved for application-specific data: 0xe0 ("APP0") through 0xef ("APP15").
An APP segment's data usually begins with NUL-terminated string to identify the type of data contained in it. The actual payload data then begins after the NUL byte. This is a convention, not a part of the JPEG specification.
Types of JPEG files
The following types are not disjoint. For example, a progressive JPEG may use arithmetic coding.
Baseline
JPEGs with an SOF0 marker are known as Baseline JPEGs. They are always lossy, not progressive, use Huffman coding, and have a bit depth of 8. Every application that supports JPEG is supposed to at least support Baseline JPEG.
Progressive
Progressive JPEG rearranges the image data, so that the the first part of it represents a very low quality version of the entire image, rather than a high quality version of a small part of the image.
Arithmetic coding
Even lossy JPEG makes use of a lossless compression algorithm. The lossless algorithm is usually Huffman coding, but arithmetic coding may be used instead. JPEG's arithmetic coding usually results in a smaller file size, but it is not as widely supported as one might hope, probably because it used to be encumbered by patents.
12-bit
Except for Baseline JPEG, all lossy types of JPEG may use a bit depth of either 8 or 12 bits per sample. Few applications support 12 bits, though.
Lossless JPEG
JPEG supports true lossless compression, but it is used so rarely that JPEG is commonly thought of as strictly a lossy format. A lossless JPEG image may have any bit depth from 2 to 16. Few applications support lossless JPEG, but it does find some use in the medical industry, such as in DICOM files.
Hierarchical
Also called "differential", hierarchical JPEG is vaguely similar to progressive JPEG, but geared toward storing multiple sizes of the same image, such that the decoder can select the size it prefers. Hierarchical JPEGs are, to a close approximation, nonexistent.
Related Formats
ICC profile data is contained in an APP2 "ICC_PROFILE" segment.
The Exif standard uses an APP1 "Exif" segment.
FlashPix data is contained in APP2 "FPXR" segments in Exif-compliant JPEGs. Refer to the Exif specification.
Photoshop Image Resources is contained in an APP13 "Photoshop 3.0" segment.
IPTC metadata often appears in JPEG files, embedded in Photoshop Image Resources.
XMP metadata is contained in an APP1 "http://ns.adobe.com/xap/1.0/" segment.
Many other file formats, such as TIFF, MNG, and DICOM, can contain JPEG-compressed data or encapsulated JPEG files.