1
0
Fork 0
forked from josch/img2pdf

Use mono.jb2 for tests

This also uncovered a bug in jbig2enc where it uses the wrong unit
for resolution.
This commit is contained in:
ooBJ3u 2023-11-29 00:00:00 +00:00
parent 085dd192f6
commit b23d82c45e
7 changed files with 13 additions and 8 deletions

View file

@ -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
#

View file

@ -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)):

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 493 KiB

BIN
src/tests/input/mono.jb2 Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.