-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Attach (recommended) or Link to PDF file
Hello,
I wrote a JBIG2 decoder a while ago. As part of that, I made a fairly extensive suite of test inputs. (I also wrote a JBIG2 encoder for that.)
All of the test images decode fine in at least some decoder implementation that isn't mine (usually PDFium or Acrobat Reader). Many decode fine in pdf.js, but several don't. I had filed bugs for some of the issues found by it (#17871, #17883, #20439, #20461), but there are many more left.
The test files are available here, all bitmap-*.jbig2 files:
https://github.com/SerenityOS/serenity/tree/master/Tests/LibGfx/test-inputs/jbig2/
They all decode to exactly the same bitmap when decoded correctly, bitmap.bmp in that directory.
I'm also attaching a zip file with these files, and a zip with these files embedded in PDF files. (In "Additional context" below.)
Since there aren't many jbig2 test files out there, maybe this is useful to you.
All the test files are created from json descriptions:
https://github.com/SerenityOS/serenity/tree/master/Tests/LibGfx/test-inputs/jbig2/json
In case it's interesting, this is the tool that reads the json files:
https://github.com/SerenityOS/serenity/blob/master/Userland/Utilities/jbig2-from-json.cpp
This is the writer and reader:
https://github.com/SerenityOS/serenity/blob/master/Userland/Libraries/LibGfx/ImageFormats/JBIG2Writer.cpp
https://github.com/SerenityOS/serenity/blob/master/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp
https://github.com/SerenityOS/serenity/blob/master/Userland/Libraries/LibGfx/ImageFormats/JBIG2Shared.cpp
(All bitmap-*json are by me. The project license is BSD 2-clause, but you could also use them under a different license if that's more convenient for some reason.)
It's of course possible that the bitstreams aren't valid! If you find a problem in a bitstream, please let me know, and I'll try to fix it.
They're not completely busted, as annex-h.json produces exactly the bitstream in annex h of the jbig2 spec.
I'll do a few more minor tweaks to some of these files, but as far as I know they're a pretty complete test of what's in the spec. (It's missing a few corner cases here and there still.) It does not contain tests for EXTTEMPLATE, since not a single jbig2 reader seems to have support for that, and my goal was to only include files that decode fine in at least one decoder implementation that's not written by me. It also doesn't test colors, for the same reason.
I hope this is useful!
Web browser and its version
Firefox
Operating system and its version
macOS 15.6.2
PDF.js version
n/a
Is the bug present in the latest PDF.js version?
Yes
Is a browser extension
No
Steps to reproduce the problem
Not really a bug. The idea is that you'd add all these files as test inputs, and made sure that they all decode to bitmap.bmp. The ones that don't are likely bugs.
What is the expected behavior?
(see above)
What went wrong?
(see above)
Link to a viewer
No response
Additional context
Raw files: serenity-jbig2-files.zip
Updated Jan 2026: serenity-jbig2-files.zip
Embedded in PDFs: jbig2-pdfs.zip
Updated Jan 2026: jbig2-pdfs.zip
https://github.com/SerenityOS/serenity/blob/master/Meta/jbig2_to_pdf.py is what did the embedding.
(I opened a similar issue with the jbig2dec folks: https://bugs.ghostscript.com/show_bug.cgi?id=708983. PDFium also added these files to their test suite.)