Skip to main content
JPEG and PNG are the two most common raster image formats on the web and in software development. While they share nothing structurally, both use a sequenced, tagged approach to organizing image data — JPEG uses markers and PNG uses chunks — making them well-suited to Binary Internals’ tree-based visualization. Binary Internals ships a parser for each format, and both are invoked automatically by file extension. The JPEG parser identifies and annotates every 2-byte marker in the file, and the PNG parser walks every 4-part chunk from the file signature through the mandatory IEND terminator.

JPEG Overview

JPEG (defined in ITU-T T.81 and ISO/IEC 10918-1) is a lossy compression format for continuous-tone images. A JPEG file is a linear sequence of markers, each two bytes long. Most markers introduce a marker segment that begins with a 2-byte length field followed by segment data. A few markers are standalone (no segment data follows). The file always begins with the SOI marker (0xFFD8) and ends with EOI (0xFFD9).

File Extensions

.jpg and .jpeg — registered by PluginDescriptorJPEG, which returns ["jpeg", "jpg"] from getExtensions().

How the JPEG Parser Works

The JPEGFile parser reads the byte array sequentially. It validates that the file begins with SOI (0xFFD8). It then scans forward marker by marker. For each position, it checks whether the two bytes form a valid marker code (value must be in (0xFF00, 0xFFFF) exclusive). If no marker is found at the current position, the parser scans forward to the next valid marker and wraps the intervening bytes in a FileData node (labelled as compressed image data or raw data).Each recognized marker produces a typed Marker subclass. Markers with an associated length field are fully parsed into structured field nodes. Standalone markers (those with no following length or data) produce a single leaf node.

Marker Code Table

All JPEG marker codes are defined as constants in MarkerCode. Each is two bytes: the first byte is always 0xFF; the second byte identifies the marker type.

APP Segment Classes

The parser ships dedicated subclasses for the most common application segments:

Marker Structure

Each non-standalone marker has the following layout:
After SOS and restart markers, the raw compressed entropy-coded data follows until the next valid marker is found.
The PNG specification is maintained at libpng.org. The JPEG specification is ITU-T T.81 / ISO/IEC 10918-1, available from the respective standards bodies.