mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-31 07:39:08 +00:00
pdfcraft_filters::encode_jbig2 stores each distinct mark of a 1-bit image (8-connected black pixels, at most 256 a side) once, as a symbol in a symbol dictionary, and places its exact copies with an immediate lossless text region that refers to it. Larger marks, and in a second plan marks that occur once, go to a generic region over their box. It keeps whichever of that and the generic coding (encode_jbig2_generic, unchanged) is smaller. Only exact copies share a symbol, so the stream decodes to the same bits. Written from the JBIG committee's ISO/IEC 14492 Final Committee Draft: 6.4 and 6.5 (text region and symbol dictionary decoding), 7.2, 7.4.2 and 7.4.3 (segment headers and syntax) and Annex A (the integer coders, checked against its worked example and Table A.1). On six pages of rendered 300 dpi text the output is 28% of the generic coding's size and 17% of Group 4's, at about 100 ms a page; hayro-jbig2 and Poppler (pdfimages) both decode it to the original bits. Scans, whose copies of a letter are seldom identical, gain little: that needs refinement coding. A dictionary shared between pages (/JBIG2Globals) is a further step. The optimizer's Monochrome Images > JBIG2 (lossless) and doc_optimize mono jbig2 use it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P6yUtvWGPsJpMLyh6pxSXG