Library:Libjpeg
| Developer | Independent JPEG Group (Thomas G. Lane; Guido Vollbeding from version 7) |
|---|---|
| Platforms | any (portable C); libjpeg.so.62 / .8 / .9, jpeg62.dll, libjpeg-9.dll |
| Versions | 1 (1991) to 6b (27-Mar-1998), 7 (2009), 8-8d (2010-2012), 9-9f (2013-2024) |
| License | IJG License (BSD-like, advertising clause for documentation) |
| Website | https://ijg.org/ |
| On this wiki | Facts · Code · Notes · Topics |
The Independent JPEG Group's JPEG library (IJG libjpeg, releases 1 to 9f, 1991-2024, by Thomas G. Lane and later Guido Vollbeding), the reference JPEG codec whose API (jpeg_create_decompress, jpeg_read_header, jpeg_read_scanlines...), message table and constant tables live on in libjpeg-turbo and in countless static copies. Its version 6b (1998) API is still the one most programs are built against.
Overview
libjpeg is the original free JPEG codec, written by the Independent JPEG Group. Version 6b (March 1998) was the last release by Tom Lane and became the stable ABI everybody targeted (libjpeg.so.62); Guido Vollbeding's later releases (7 in 2009, 8 in 2010, 9 in 2013, up to 9f in January 2024) changed the API/ABI and added non-standard features (SmartScale, DCT scaling to other block sizes, arithmetic coding in 7). Most Linux distributions, browsers and toolkits moved to Library:Libjpeg-turbo, a fork of 6b that can emulate the 6b, 7 or 8 API. Both share almost all of the code described here, so the identification below works for the whole family; Library:Libjpeg-turbo#Identification tells the two apart.
Identification
- JVERSION string in the message table (
jpeg_std_message_table, entry JMSG_VERSION): the release and date separated by two spaces, NUL-terminated:"6b 27-Mar-1998","8d 15-Jan-2012","9f 14-Jan-2024". libjpeg-turbo stores the string of the API it emulates ("6b 27-Mar-1998","7 27-Jun-2009"or"8d 15-Jan-2012"), so the string gives the API level, not the library. See Fact:Libjpeg/string/JVERSION. - Copyright string next to it (JMSG_COPYRIGHT): IJG
"Copyright (C) 1998, Thomas G. Lane"(6b) or"Copyright (C) 2012, Thomas G. Lane, Guido Vollbeding"(7-9f, year of the release); libjpeg-turbo"Copyright (C) 1991-2026 The libjpeg-turbo Project and many others". - Message strings:
JPEG parameter struct mismatch: library thinks size is %u, caller expects %u,Wrong JPEG library version: library is %d, caller expects %d,Not a JPEG file: starts with 0x%02x 0x%02x,Improper call to JPEG library in state %d,Corrupt JPEG data: %u extraneous bytes before marker 0x%02x,Bogus message code %d(entry 0). They are in every build that links jerror.c, i.e. every build. - jpeg_natural_order[80]:
const intzigzag-to-natural table with 16 extra entries of 63 "for safety in decoder" (jutils.c); 320 bytes of int32. IJG 7+ also hasjpeg_natural_order7...jpeg_natural_order2for its smaller block sizes; libjpeg-turbo does not. - jpeg_aritab[114] (jaricom.c, IJG 7+ and libjpeg-turbo with arithmetic coding): packed Qe values, first entries 0x5A1D0181, 0x2586020E, 0x11140310, 0x080B0412.
- API version immediates:
jpeg_create_decompress(cinfo)is a macro forjpeg_CreateDecompress(cinfo, JPEG_LIB_VERSION, sizeof(struct jpeg_decompress_struct)), so every caller passes 62, 70, 80 or 90 and the struct size as constants, and the library compares both (Fact:Libjpeg/behavior/jpeg CreateDecompress version and size check). - Exports (DLL/.so builds):
jpeg_CreateDecompress,jpeg_CreateCompress,jpeg_std_error,jpeg_read_header,jpeg_start_decompress,jpeg_read_scanlines,jpeg_finish_decompress,jpeg_destroy_decompress,jpeg_set_defaults,jpeg_set_quality,jpeg_write_scanlines,jpeg_resync_to_restart;jpeg_mem_src/jpeg_mem_destfrom version 8 (and in libjpeg-turbo for all API levels by default).
The wiki's jpegscan searches a binary for all of these; export_symbols with subject Library:Libjpeg gives a Ghidra/IDA script for the signature facts.
Versions
| JPEG_LIB_VERSION | Releases | Notes |
|---|---|---|
| 62 | 6b (1998) | the classic ABI, libjpeg.so.62; libjpeg-turbo's default
|
| 70 | 7 (2009) | arithmetic coding, jpeg_natural_order2..7, new struct fields (ABI break)
|
| 80 | 8, 8a-8d (2010-2012) | jpeg_mem_src/jpeg_mem_dest, SmartScale
|
| 90 | 9, 9a-9f (2013-2024) | colour transforms (color_transform), not emulated by libjpeg-turbo
|
The message code numbers shift with the API level: JERR_BAD_LIB_VERSION is 12 for API 6b and 13 for 7+, JERR_BAD_STRUCT_SIZE 21 / 22 (Fact:Libjpeg/enum/J MESSAGE CODE). In code they appear as the value stored to err->msg_code (offset 0x28 of jpeg_error_mgr on 64-bit, 0x14 on 32-bit) before the call through err->error_exit (offset 0).
API overview
- Decompression:
jpeg_std_error(&jerr),jpeg_create_decompress(jpeg_CreateDecompress),jpeg_stdio_srcorjpeg_mem_src,jpeg_read_header(cinfo, TRUE), set output parameters,jpeg_start_decompress, loopjpeg_read_scanlines,jpeg_finish_decompress,jpeg_destroy_decompress. - Compression mirrors it with
jpeg_set_defaults,jpeg_set_quality(cinfo, q, TRUE),jpeg_start_compress,jpeg_write_scanlines,jpeg_finish_compress. - Errors:
jpeg_error_mgris a table of function pointers (error_exit,emit_message,output_message,format_message,reset_error_mgr) followed bymsg_codeand the message parameters; applications replaceerror_exitwith alongjmp. The defaulterror_exitprints the message and callsexit().
Data structures
struct jpeg_error_mgr(unchanged since 6b): five method pointers, thenint msg_codeat 0x28 (64-bit) / 0x14 (32-bit) andmsg_parm.i[]right after it;jpeg_message_tableat 0x88 on 64-bit (Fact:Libjpeg/struct/jpeg error mgr). EveryERREXITnin the library compiles to stores into these two fields followed by a call througherr->error_exit(offset 0), which makes error paths easy to label.booleanisunsigned charon Windows (jconfig.vc, libjpeg-turbo's jconfig.h under_WIN32) andintelsewhere (Fact:Libjpeg/behavior/Windows boolean is unsigned char); struct layouts therefore differ between Windows and Unix even at the same pointer size.sizeof(struct jpeg_decompress_struct)/sizeof(struct jpeg_compress_struct)per API level and ABI, i.e. the constants passed tojpeg_CreateDecompress/jpeg_CreateCompress: API 6b 632/520 on LP64, 600/504 on Win64, 432/360 on Win32; API 8 656/584 on LP64, 624/568 on Win64 (Fact:Libjpeg/identification/Struct sizes by API level and ABI, computed with structsize).jpeg_component_info,JQUANT_TBL(UINT16 quantval[64]in natural order +boolean sent_table) andJHUFF_TBL(UINT8 bits[17],UINT8 huffval[256],boolean sent_table) are public too; the 17-bytebits[]with an unused element 0 is why libjpeg-style code keeps Huffman counts with a leading 0.
Pitfalls
- The quantisation tables and the Annex K Huffman tables are the JPEG standard's examples: every JPEG encoder has them. Only their libjpeg-specific shapes help (unsigned int[64] quant tables, 17-byte
bits[]arrays with a leading 0), and even those are copied: FFmpeg'sff_mjpeg_bits_ac_luminance[17]has the same leading 0. jpeg_natural_orderis also copied byte for byte by other libraries: a full FFmpeg 9.0 Windows build (which links libjxl) contains two int32 copies of the 80-entry table and none of the message strings. Require the message strings or JVERSION before calling it libjpeg.JVERSION "8d 15-Jan-2012"does not mean IJG 8d: check the copyright string or the libjpeg-turbo markers.
Code & repositories
- https://github.com/libjpeg-turbo/libjpeg-turbo @
2fa570c514a4b0e70342ef8b32ce1cda21b85710· license: IJG AND BSD-3-Clause AND Zlib (declared: the detector found none; check the repository)
The official libjpeg-turbo source (main branch, 3.2.0 + 47 commits). Its history also contains the IJG releases as tags jpeg-1 to jpeg-9f, so one clone answers questions about both libraries. testimages/ holds free test JPEGs (testorig.jpg, testimgari.jpg arithmetic, testimgint.jpg, 12-bit and lossless samples). License: IJG License + BSD-3-Clause (LICENSE.md, README.ijg), SIMD code Zlib.
Tested on: Read at commit 2fa570c5 and at every release tag for the version markers; not built (no C compiler on the test machine). Behaviour checked on files written by Pillow 12.3.0, which links libjpeg-turbo v3.1.4.1. · checked 2026-10-17; last activity 2026-10-13; Note: the latest release ships binaries; the wiki links only the source, never the binaries
Evidence & references
- IJG history is imported into the libjpeg-turbo repository as tags
jpeg-1...jpeg-9f; JVERSION/JCOPYRIGHT read from jversion.h at every tag, message tables from jerror.h at jpeg-6b, jpeg-8d, jpeg-9f. - libjpeg-turbo commit 2fa570c514a4b0e70342ef8b32ce1cda21b85710: src/jerror.h 45-141, src/jerror.c 47, src/jutils.c 59-70, src/jaricom.c 32-35, src/jdapimin.c 39-48, src/jpeglib.h 968-973.