- RULES.md - project-specific rules
- docs/CONVENTIONS.md - gobig2-specific style
- docs/LIBRARIES.md - dependency policy
- docs/TESTING.md - test categories and bar
- docs/TOOLS.md - Taskfile-centric workflow
Project info:
- README.md - public-facing overview
- docs/design/ - design notes (ITU spec deviations, etc.)
Pure-Go decoder for ITU-T T.88 / ISO/IEC 14492 (JBIG2)
bi-level image streams. Two on-the-wire forms supported:
standalone .jb2 / .jbig2 files (T.88 Annex E header) and
PDF-embedded segment streams (the bytes a PDF reader's
/JBIG2Decode filter delivers). No cgo. No third-party runtime
deps.
Public API lives in three files at repo root:
- jbig2.go -
Decoder, three constructors,Decode/DecodeContext/DecodeAll,DecodeConfig,ParseGlobals,image.Decoderegistration. - errors.go - sentinel taxonomy (
ErrMalformed,ErrResourceBudget,ErrUnsupported). - limits.go -
Limitsstruct,DefaultLimits, the process-wideApplycap propagator.
Two CLI binaries under cmd/.
The internal packages mirror the JBIG2 spec's section layout -
each one owns a single decoding procedure or piece of shared
plumbing. The orchestrator is internal/segment; everything
else is a leaf the orchestrator dispatches into.
- jbig2.go - package doc,
Decoder, constructors, decode loop, multi-page handling,image.Decoderegistration. - errors.go -
ErrMalformed,ErrResourceBudget,ErrUnsupportedsentinels. - limits.go -
Limitsstruct, nine resource caps,DefaultLimits,Apply(process-wide). - example_pdf_test.go - runnable godoc example of the PDF-embedded flow.
- cmd/gobig2/ - decode a
.jb2/ PDF-embedded stream to PNG; exit codes mirror the sentinel taxonomy. - cmd/extract-jbig2/ - walk a PDF, dump every
/JBIG2Decodeimage XObject (and/JBIG2Globals) as.jb2fixture files. - cmd/perf-cross/ - dev / CI tool: wall-clock bench gobig2 against jbig2dec, mutool, pdfimages, and PDFBox over the bundled SerenityOS subset plus optional
-extra-corpus-dirsynthesized fixtures; emits Markdown + JSON. Driven bytask bench:crossand the.github/workflows/perf-linux.ymlworkflow.
- scripts/perf/synthesize-corpus.sh - generates ~600 dpi A4 JBIG2 fixtures (generic-region + symbol-mode encodings) via
jbig2enc+ ImageMagick, dropped under./tmp/perf-corpus/forcmd/perf-crossto consume. Wrapped bytask bench:corpus; CI runs it cached behindactions/cache.
- internal/bio/ -
BitStreamover a byte buffer; the single bit-I/O primitive every higher decoder reaches for. - internal/arith/ - JBIG2 MQ arithmetic coder (T.88 Annex E) plus integer / IAID adapters; inner loop of every context-coded region.
- internal/huffman/ - T.88 Annex B standard tables (B.1-B.15) and user-defined-table parser.
- internal/mmr/ - CCITT Group 4 / T.6 (MMR) bitmap decoding (the non-arithmetic generic-region path).
- internal/intmath/ - small integer helpers shared across decoders, isolated for unit-testability.
- internal/generic/ - generic-region decoding procedure (T.88 §6.2); workhorse coding mode, also exposes the MMR entry point.
- internal/refinement/ - generic refinement region (T.88 §6.3); delta-context re-rendering used by aggregate symbols and standalone refinement segments.
- internal/symbol/ - symbol dictionary (
sdd.go, T.88 §6.5) and text region (trd.go, T.88 §6.4) decoding. - internal/halftone/ - pattern dictionary (T.88 §6.7, type-16) and halftone region (T.88 §6.6, type-22/23); coupled because the halftone region indexes into the pattern dict.
- internal/segment/ - segment table, header parsing,
Documentorchestrator that dispatches per-segment Procs and stitches results onto the page bitmap. - internal/page/ - bi-level
Imagetype; packed MSB-first byte buffer with get/set/compose primitives andimage/color.Grayconversion. - internal/state/ - cross-cutting enums and constants shared between decoders and orchestrator; broken out to avoid import cycles.
- internal/probe/ - file-header magic detection, organization-mode classification, embedded-stream sniff + endianness heuristic.
- internal/input/ - bounded
io.Readerslurp (MaxBytescap), globals sanity check. - internal/errs/ - sentinel error values the public package re-exports; lives here so internal packages can wrap without importing the root.
- internal/gobig2test/ - public-API contract tests, SerenityOS corpus runner, ITU-T T.88 Annex A conformance runner (env-gated), fuzz targets, pathological-input regressions, limits enforcement, benchmarks.
- testdata/serenityos/ - bundled SerenityOS JBIG2 corpus (always runs).
- testdata/pdf-embedded/ - sample PDF-extracted stream for the godoc example.
- testdata/perf/ - 27-fixture perf matrix (300/600 dpi A4 pages under jbig2enc's generic / generic+TPGD / symbol-mode flag combos, plus classifier-tuning specials). Consumed by
BenchmarkPerfCorpus(task bench:perf). Regen via scripts/perf/build-perf-testdata.sh (task bench:perf-rebuild).