This is a djvu format decoder, like libdjvu, but better:
- smaller
bun cmd/compare-code-sizes.tsshows 100 kB (us) vs. 720 kB of libdjvue - plain C, no dependencies (vs. C++)
- simpler API
- simpler to integrate: copy dist/djvu.h and dist/djvu.c into your project. This is amalgamated src/* into a single file, like sqlite
- mostly faster, according to benchmarks (
bun cmd/bench.ts) - tested on thousands of .djvu files for bit-by-bit correctness to libdjvu
See src/djvu.h. Sketch:
djvu_init(); /* once, before threads */
djvu_ctx *ctx = djvu_ctx_new(NULL, NULL, NULL, NULL, on_error, NULL);
djvu_doc *doc = djvu_doc_open(ctx, data, len); /* data must outlive doc */
int n = djvu_doc_page_count(doc);
djvu_page_info info; djvu_doc_page_info(doc, 0, &info);
djvu_image *img = djvu_page_render(doc, 0, 1); /* gray8 / rgb24 */
char *txt = djvu_page_text(doc, 0);Requires clang, bun, and git. cmd/get-deps.ts clones the DjvuNet,
DjVuLibre, and DjvuNet/artifacts repos into deps/; the .djvu samples in
those checkouts are the test corpus. build.ts and tests.ts call it
automatically.
bun cmd/get-deps.ts # clone deps (the corpus; auto-run below)
bun cmd/build.ts # build reference tools + the C library and djvu_test.exe
bun cmd/tests.ts -all # build, then verify render + text against DjVuLibre
bun cmd/fuzz.ts -check-crashes # replay tracked fuzz/crashes under ASan (CI)
CI (GitHub Actions): .github/workflows/ci.yml — MSVC/Linux smoke + amalgamation,
fuzz crash regression, WASM decode.
djvu_test CLI (jbig2dec-flavored):
djvu_test -info in.djvu
djvu_test -page N -out out.pgm in.djvu
djvu_test -page N -text in.djvu
This is automatic, ai assited port of of DjvuNet (C#) DjVu decoder, done with Grok Build.
Correctness is verified against DjVuLibre
(ddjvu, djvutxt) on the sample files in deps/DjvuNet/Specs, and my own collection large collection of djvu files collected for testing SumatraPDF.