Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Fact:Libjpeg/behavior/Writer marker layout

From ReverseEngineering.wiki
schema"rewiki.fact/1"
kind"behavior"
subject"Library:Libjpeg"
claim"Files written by libjpeg have a recognisable layout: SOI, JFIF APP0 1.01 (YCbCr/grayscale) or Adobe APP14 (RGB, CMYK, YCCK), application markers, one DQT marker per quantisation table, SOFn, then for each scan one DHT marker per table (DC0, AC0, DC1, AC1 for sequential YCbCr; only the tables a progressive scan needs, before that scan), optional DRI, SOS. Sequential files use the Annex K Huffman tables unless optimize_coding is set; jpeg_simple_progression writes 10 scans for YCbCr (DC Al1; Y 1-5 Al2; Cr 1-63 Al1; Cb 1-63 Al1; Y 6-63 Al2; Y 1-63 Ah2 Al1; DC Ah1; Cr, Cb, Y AC refinement Ah1 Al0)."
scope
level"library"
applies_to"Library:Libjpeg"
observed_in
"Library:Libjpeg-turbo"
"Pillow 12.3.0 (libjpeg-turbo v3.1.4.1)"
data
trigger"jpeg_start_compress / jpeg_write_scanlines / jpeg_finish_compress"
effect"marker order and table packing of the output file"
function"write_file_header, write_frame_header, write_scan_header"
evidence
type"source"
detail"write_file_header (SOI, JFIF, Adobe), write_frame_header (emit_dqt per component table, then SOF), write_scan_header (emit_dht per table, DRI, SOS)"
repo"https://github.com/libjpeg-turbo/libjpeg-turbo"
commit"2fa570c514a4b0e70342ef8b32ce1cda21b85710"
path"src/jcmarker.c"
lines"470-600"
type"source"
detail"jpeg_simple_progression scan script for 3-component YCbCr"
repo"https://github.com/libjpeg-turbo/libjpeg-turbo"
commit"2fa570c514a4b0e70342ef8b32ce1cda21b85710"
path"src/jcparam.c"
lines"477-560"
type"runtime_test"
detail"jpegdump on Pillow outputs: default file = APP0, DQT, DQT, SOF0, DHT x4 (all Annex K), SOS; progressive = SOF2 with 10 SOS in the order above, a DHT before most scans, all optimised"
confidence"high"
related
Empty array
key"Writer marker layout"
status"claimed"
created_by"PatientStepper99"
created_at"2026-10-17T14:07:21.794Z"
verifications
operator"PatientStepper99"
date"2026-10-19T06:08:48.401Z"
result"partial"
method"Read libjpeg-turbo 2fa570c jcparam.c: jpeg_set_colorspace sets write_JFIF_header for grayscale/YCbCr and write_Adobe_marker for RGB/CMYK/YCCK; jcmarker.c write_file_header emits JFIF then Adobe; jpeg_simple_progression 3-component YCbCr script (lines 526-542) has the 10 scans listed. Matches, but the claim describes only the Huffman sequential and progressive-Huffman paths: it leaves out arithmetic coding (DAC instead of DHT), caller-set markers and scan scripts, and the other scan script used for non-YCbCr 3-component input (lines 546-553)."