What Is in the JPEG Start of Frame Marker?

The Start of Frame (SOF) marker segment in a JPEG file establishes the core structural and geometric metadata required by decoders to reconstruct the image. This article breaks down the exact binary data fields contained inside the JPEG SOF marker segment, explaining how sample precision, image dimensions, color component definitions, chroma subsampling factors, and quantization table assignments are structured.

Role and Identification of the SOF Marker

In the JPEG standard (ITU-T T.81 / ISO/IEC 10918-1), the Start of Frame marker signals the beginning of the frame parameters and specifies the compression process used. The marker itself is a two-byte code starting with 0xFF followed by a byte ranging from 0xC0 to 0xCF (excluding 0xC4, 0xC8, and 0xCC, which are reserved for other table types). The most common markers are:

Immediately following the two-byte SOF marker is the payload containing the frame header data.

Detailed Breakdown of the SOF Segment Fields

The payload of an SOF marker contains a sequence of specific fields in a fixed order:

1. Frame Header Length (\(L_f\))

2. Sample Precision (\(P\))

3. Image Height (\(Y\))

4. Image Width (\(X\))

5. Number of Image Components (\(N_f\))

6. Component Specification Parameters

Following the number of components (\(N_f\)), the SOF segment contains a repeating block of 3 bytes for each component. Therefore, this section is \(N_f \times 3\) bytes long. For each component, the following three parameters are declared:

Summary of the Binary Layout

Field Size Purpose
Marker 2 bytes Identifies the SOF type (0xFFC0, 0xFFC2, etc.)
\(L_f\) 2 bytes Length of the frame header segment
\(P\) 1 byte Sample precision (bit depth, usually 8)
\(Y\) 2 bytes Maximum image height in pixels
\(X\) 2 bytes Maximum image width in pixels
\(N_f\) 1 byte Number of color components
For each component:
\(C_i\) 1 byte Component ID (e.g., 1=Y, 2=Cb, 3=Cr)
\(H_i / V_i\) 1 byte Horizontal and vertical subsampling factors (4 bits each)
\(Tq_i\) 1 byte Quantization table index linked to this component