jbig2dec-delphi
Delphi port of jbig2dec v0.20 - JBIG2 bi-level image decoder (98/98 tests pass, pixel-exact match with C)
- Active · last change 2-27-2026
- ★ 1 on GitHub
README
jbig2dec - Delphi Port
A complete Delphi port of jbig2dec v0.20, the open-source JBIG2 bi-level image decoder originally developed by Artifex Software.
JBIG2 is a lossy and lossless compression standard for bi-level (black and white) images, commonly used in PDF documents and document scanning.
Features
- Full JBIG2 compliance: symbol dictionaries, text regions, generic regions, halftone regions, pattern dictionaries, MMR/Group 4 fax
- 98/98 test files decoded successfully (0 crashes, 0 timeouts)
- 86/86 pixel-exact match with C jbig2dec v0.20 output
- Type 36 intermediate generic regions: implemented beyond the C version (which marks this as "not yet implemented"), correctly decoding 12 additional test files
- Context reuse ($0100/$0200 segment flags) fully supported
- BMP output via VCL
TBitmap
Build Requirements
- Delphi 10.1 Berlin or later (Win32 target)
- No third-party libraries required
Compiling the CLI tool
dcc32 -Q -B -NSSystem -NSWinapi -NSVcl -U"<RTL_PATH>" jbig2dec.dprWhere <RTL_PATH> is your Delphi RTL library path, e.g.:
"C:\Program Files (x86)\Embarcadero\Studio\18.0\lib\win32\release"Compiling the test suite
dcc32 -Q -B -NSSystem -NSWinapi -NSVcl -U"<RTL_PATH>" JBIG2DecTest.dprCLI Usage
jbig2dec [options] <file.jbig2>
jbig2dec [options] <global_stream> <page_stream>Options
| Option | Description |
|---|---|
-h, --help |
Print usage and exit |
-V, --version |
Print version and exit |
-q, --quiet |
Suppress diagnostic output |
-v, --verbose |
Set verbosity level (0-3, default 1) |
-o <file> |
Output filename (default: input with .bmp extension) |
-e, --embedded |
Expect embedded bitstream without file header |
Examples
Decode a JBIG2 file to BMP:
jbig2dec document.jbig2Specify output filename:
jbig2dec -o output.bmp document.jbig2Decode PDF-embedded streams (global + page):
jbig2dec globals.jbig2 page1.jbig2Multi-page files produce numbered outputs: output.bmp, output.page2.bmp, output.page3.bmp, etc.
Library API
For programmatic use, call JBIG2DecodeToBitmap from the JBIG2Dec unit:
uses JBIG2Dec;
var
Pages: TArray<TBitmap>;
Data: TBytes;
begin
Data := TFile.ReadAllBytes('document.jbig2');
if JBIG2DecodeToBitmap(@Data[0], Length(Data), Pages) >= 0 then
begin
Pages[0].SaveToFile('page1.bmp');
// ...free bitmaps when done
end;
end;Unit Structure
| Unit | Description |
|---|---|
JBIG2Dec.Types |
Shared types, constants, enums, records |
JBIG2Dec.Image |
Image allocation, pixel access, composition |
JBIG2Dec.Arith |
QM arithmetic decoder, integer and IAID contexts |
JBIG2Dec.Huffman |
Huffman decoder, 15 standard tables (A-O) |
JBIG2Dec.MMR |
MMR/Group 4 fax decoding |
JBIG2Dec.Generic |
Generic and refinement region decoding |
JBIG2Dec.SymbolDict |
Symbol dictionary segments |
JBIG2Dec.Text |
Text region decoding |
JBIG2Dec.Halftone |
Pattern dictionary and halftone regions |
JBIG2Dec.pas |
Main API, context, segment dispatch, page management |
License
This project is licensed under the GNU General Public License v3.0 (or later), the same license as the original C jbig2dec. See LICENSE and COPYING for details.
Credits
- Original C jbig2dec: Copyright (C) 2001-2023 Artifex Software, Inc.
- Delphi port: Faithful translation of jbig2dec v0.20 C source to Object Pascal
- Original project: https://jbig2dec.com/

