IEND terminator.
- JPEG
- PNG
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 theSOI 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
TheJPEGFile 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 inMarkerCode. 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: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.