From 3a50cadddf81730043b6f6ef03d40bba8eb5cb0b Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 20 Mar 2024 18:24:57 -0400 Subject: [PATCH] Tests/LibGfx: Add a jbig2 file using basic symbol and text segments I created this file using `jbig2` (see below for details), but as far as I can tell `jbig2` does not produce spec-compliant files: 1. It always writes to 0s for the run lengths that specify how many symbols to export at the end of a symbol segment 2. It doesn't write any referred-to segments for text segments. I think it's supposed to write a referred-to segment that mentions the symbol segment the text segment refers to (?) I locally tweaked `jbig2` to fix these two defects (*), so the image added in this commit is correct as best I can tell. It opens fine using `image` and `jbig2`'s decode mode, and via `Meta/jbig2_to_pdf.py` in Firefox and Chrome. Without my tweaks, the image decodes fine with `jbig2`, but not with any of the other three. The image (in a pdf) does _not_ decode in Preview.app, either with or without my local `jbig2` tweaks. *: See the PR adding this image for my local diff. I created the test image file by running this shell script with `jbig2` tweaked as described above: #!/bin/bash set -eu I=Build/lagom/bin/image S=Tests/LibGfx/test-inputs/bmp/bitmap.bmp $I "$S" --crop 232,70,120,250 -o mouth.bmp $I "$S" --crop 135,100,100,100 -o nose.bmp $I "$S" --crop 50,108,30,30 -o top_eye.bmp $I "$S" --crop 60,265,30,30 -o bottom_eye.bmp # I then manually converted those to 1bpp using Photoshop # (Image->Mode->Grayscale, then Image->Mode->Bitmap..., # File->Save As..., bmp) since `jbig2` gets confused by non-1bpp # bmp files and `image` can't write 1bpp files :/ # # (I tried `convert ${in} -monochrome ${in}-1bpp.bmp` via # https://cancerberosgx.github.io/magic/playground/index.html # first, but that produced bmp files that neither Preview.app nor # `jbig2` could handle.) # # -HeightClass: Number of height classes # -WidthClass: Maximum number of symbols in one height class # -Simple means no refinement; the number after is the symbol's ID # The 3 numbers afer `-ID` are id, y, x. The `-ID` are sorted by x. # -RefCorner 1 means "top left". # # `jbig2` writes symbol and text segments as specified in the ini # file, and then only stores the bits of the input image that aren't # already set through symbol and text segments. cat << EOF > jbig2-symbol.ini -sym -Seg 1 -sym -file -numClass -HeightClass 3 -WidthClass 2 -sym -file -numSymbol 4 -sym -file -Height 250 -sym -file -Width 120 -Simple 0 mouth-1bpp.bmp -sym -file -EndOfHeightClass -sym -file -Height 100 -sym -file -Width 100 -Simple 1 nose-1bpp.bmp -sym -file -EndOfHeightClass -sym -file -Height 30 -sym -file -Width 30 -Simple 2 top_eye-1bpp.bmp -sym -file -Width 30 -Simple 3 bottom_eye-1bpp.bmp -sym -file -EndOfHeightClass -sym -Param -Huff_DH 0 -sym -Param -Huff_DW 0 -txt -Seg 2 -txt -Param -numInst 4 -ID 2 108 50 -ID 3 265 60 -ID 1 100 135 -ID 0 70 232 -txt -Param -RefCorner 1 -txt -Param -Xlocation 0 -txt -Param -Ylocation 0 -txt -Param -W 399 -txt -Param -H 400 EOF J=$HOME/Downloads/T-REC-T.88-201808-I\!\!SOFT-ZST-E/Software J=$J/JBIG2_SampleSoftware-A20180829/source/jbig2 $J -i "${S%.bmp}" -f bmp -o symbol -F jb2 -ini jbig2-symbol.ini --- .../LibGfx/test-inputs/jbig2/bitmap-symbol.jbig2 | Bin 0 -> 409 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Tests/LibGfx/test-inputs/jbig2/bitmap-symbol.jbig2 diff --git a/Tests/LibGfx/test-inputs/jbig2/bitmap-symbol.jbig2 b/Tests/LibGfx/test-inputs/jbig2/bitmap-symbol.jbig2 new file mode 100644 index 0000000000000000000000000000000000000000..506514fd3f80c083efbd037c725dc04264e0c327 GIT binary patch literal 409 zcmbR4y(#y7P*qK^NmAg_;ioR>q5SBP2TO8!)||e%}nl_U(#9K zW6z}S=eB!LWoJ;hNM3&RG2SoF@91W2d+c!RNyq=XS5vJI*(mPn|1!u``-yeGTp-XUXh~@OCqBzF< zNr79u>(+iy)7-G~Ovbl+0<0mb_vE%(e?8Fkto)?mrU(3IFU?T