diff --git a/src/ocrmypdf/exec/ghostscript.py b/src/ocrmypdf/exec/ghostscript.py index e87f7193..b314c65f 100644 --- a/src/ocrmypdf/exec/ghostscript.py +++ b/src/ocrmypdf/exec/ghostscript.py @@ -32,6 +32,18 @@ def version(): return get_version('gs') +def jpeg_passthrough_available(): + """ + Ghostscript 9.23 introduced JPEG passthrough but it seems to corrupt the + last two bytes of certain images, for now we disable it for 9.23 and + do not mention it for < 9.23. + + https://bugs.ghostscript.com/show_bug.cgi?id=699216 + + """ + return False + + def _gs_error_reported(stream): return re.search(r'error', stream, flags=re.IGNORECASE) @@ -133,7 +145,8 @@ def generate_pdfa(pdf_pages, output_file, compression, log, strategy = 'RGB' if version() >= '9.19' else '/RGB' if version() == '9.23': - # 9.23: JPEG passthrough broken for image masks? + # 9.23: new feature JPEG passthrough is broken in some cases, best to + # disable it always # https://bugs.ghostscript.com/show_bug.cgi?id=699216 compression_args.append('-dPassThroughJPEGImages=false') diff --git a/tests/test_main.py b/tests/test_main.py index 3d8b03d6..94ecb466 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -610,10 +610,6 @@ def test_masks(spoof_tesseract_noop, resources, outpdf): p, out, err = run_ocrmypdf( resources / 'masks.pdf', outpdf, env=spoof_tesseract_noop) - if ghostscript.version() == '9.23' and \ - p.returncode == ExitCode.invalid_output_pdf: - pytest.xfail('https://bugs.ghostscript.com/show_bug.cgi?id=699216') - assert p.returncode == ExitCode.ok @@ -906,7 +902,7 @@ def test_compression_changed(spoof_tesseract_noop, ocrmypdf_exec, if compression == "jpeg": assert pdfimage.enc == Encoding.jpeg else: - if ghostscript.version() >= '9.23': + if ghostscript.jpeg_passthrough_available(): # Ghostscript 9.23 adds JPEG passthrough, which allows a JPEG to be # copied without transcoding - so report if image.endswith('jpg'):