From a27ee3ee8c88ccfe4bd1b5323ab1351fd69386ed Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sun, 3 Mar 2019 17:50:12 -0800 Subject: [PATCH] optimize: use Decode to invert 1bpp PNGs for now --- src/ocrmypdf/optimize.py | 12 ++++++++---- tests/test_optimize.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ocrmypdf/optimize.py b/src/ocrmypdf/optimize.py index b4dc866f..4ab6920c 100644 --- a/src/ocrmypdf/optimize.py +++ b/src/ocrmypdf/optimize.py @@ -341,7 +341,7 @@ def transcode_pngs(pike, images, image_name_fn, root, log, options): max_workers=options.jobs ) as executor: for xref in images: - log.info(image_name_fn(root, xref)) + log.debug(image_name_fn(root, xref)) executor.submit( pngquant.quantize, image_name_fn(root, xref), @@ -412,13 +412,17 @@ def transcode_pngs(pike, images, image_name_fn, root, log, options): if compdata.spp == 1: # PDF interprets binary-1 as black in 1bpp, but PNG sets # black to 0 for 1bpp. Create a palette that informs the PDF - # of the mapping. - palette = [Name.Indexed, Name.DeviceGray, 1, b"\xff\x00"] - cs = palette + # of the mapping - seems cleaner to go this way but pikepdf + # needs to be patched to support it. + # palette = [Name.Indexed, Name.DeviceGray, 1, b"\xff\x00"] + # cs = palette + cs = Name.DeviceGray elif compdata.spp == 3: cs = Name.DeviceRGB elif compdata.spp == 4: cs = Name.DeviceCMYK + if compdata.bps == 1: + im_obj.Decode = [1, 0] # Bit of a kludge but this inverts photometric too im_obj.ColorSpace = cs im_obj.write(compdata.read(), filter=Name.FlateDecode, decode_parms=dparms) diff --git a/tests/test_optimize.py b/tests/test_optimize.py index e2eef80b..6884ee8e 100644 --- a/tests/test_optimize.py +++ b/tests/test_optimize.py @@ -120,7 +120,7 @@ def test_flate_to_jbig2(resources, outdir, spoof_tesseract_noop): '--image-dpi', '100', '--png-quality', - '10', + '50', '--optimize', '3', env=spoof_tesseract_noop,