diff --git a/src/img2pdf.py b/src/img2pdf.py index c8601e7..2c90c20 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -1318,10 +1318,16 @@ def get_imgmetadata( INCH_PER_METER = 39.370079 if xres == 0: hdpi = default_dpi + elif xres < 1000: + # If xres is very small, it's likely accidentally expressed in dpi instead + # of dpm. See e.g. https://github.com/agl/jbig2enc/issues/86 + hdpi = xres else: hdpi = int(float(xres) / INCH_PER_METER) if yres == 0: vdpi = default_dpi + elif yres < 1000: + vdpi = yres else: vdpi = int(float(yres) / INCH_PER_METER) ndpi = (hdpi, vdpi) @@ -1840,9 +1846,8 @@ def read_images( # For now we only support single-page generic coding of JBIG2, for example as generated by # https://github.com/agl/jbig2enc # - # In fact, you can pipe an example image like 042.bmp from https://git.ghostscript.com/?p=tests.git;a=blob_plain;f=jbig2/042.bmp;hb=HEAD - # directly into img2pdf: - # jbig2 042.bmp | img2pdf > 042.pdf + # In fact, you can pipe an example image `like src/tests/input/mono.png` directly into img2pdf: + # jbig2 src/tests/input/mono.png | img2pdf -o src/tests/output/mono.png.pdf # # For this we assume that the first 13 bytes are the JBIG file header describing a document with one page, # followed by a "page information" segment describing the dimensions of that page. @@ -1854,11 +1859,11 @@ def read_images( # \_____________________/ | \_________/ \______ # magic-bytes org/unk pages seg-num # - # 00 30 00 01 00 00 00 13 || 00 00 06 c0 00 00 09 23 + # 00 30 00 01 00 00 00 13 || 00 00 00 73 00 00 00 30 # _/ | | | \_________/ || \_________/ \_________/ # type refs page seg-size || width-px height-px # - # 00 00 00 00 00 00 00 00 + # 00 00 00 48 00 00 00 48 # \_________/ \_________/ # xres yres # diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py index efa3585..9238c75 100755 --- a/src/img2pdf_test.py +++ b/src/img2pdf_test.py @@ -6861,7 +6861,7 @@ def test_layout(layout_test_cases): @pytest.fixture( scope="session", - params=[filename for filename in os.listdir(os.path.join(os.path.dirname(__file__), "tests", "input")) if not filename.endswith(".jb2.bmp")], + params=os.listdir(os.path.join(os.path.dirname(__file__), "tests", "input")), ) def general_input(request): assert os.path.isfile( @@ -6988,9 +6988,9 @@ def test_general(general_input, engine): assert sorted(x.Root.Pages.keys()) == ["/Count", "/Kids", "/Type"] assert x.Root.Pages.Type == "/Pages" if f.endswith(".jb2"): - # PIL doens't support .jb2, so we load the original .bmp, which + # PIL doens't support .jb2, so we load the original .png, which # was converted to the .jb2 using `jbig2enc`. - orig_img = Image.open(f.replace(".jb2", ".jb2.bmp")) + orig_img = Image.open(f.replace(".jb2", ".png")) else: orig_img = Image.open(f) for pagenum in range(len(x.Root.Pages.Kids)): diff --git a/src/tests/input/042.jb2 b/src/tests/input/042.jb2 deleted file mode 100644 index 3f5262f..0000000 Binary files a/src/tests/input/042.jb2 and /dev/null differ diff --git a/src/tests/input/042.jb2.bmp b/src/tests/input/042.jb2.bmp deleted file mode 100644 index 8ad82de..0000000 Binary files a/src/tests/input/042.jb2.bmp and /dev/null differ diff --git a/src/tests/input/mono.jb2 b/src/tests/input/mono.jb2 new file mode 100644 index 0000000..2f236f6 Binary files /dev/null and b/src/tests/input/mono.jb2 differ diff --git a/src/tests/output/042.jb2.pdf b/src/tests/output/042.jb2.pdf deleted file mode 100644 index 0d24d01..0000000 Binary files a/src/tests/output/042.jb2.pdf and /dev/null differ diff --git a/src/tests/output/mono.jb2.pdf b/src/tests/output/mono.jb2.pdf new file mode 100644 index 0000000..f60bc18 Binary files /dev/null and b/src/tests/output/mono.jb2.pdf differ