Exclude Group 3 images from optimization

This commit is contained in:
James R. Barlow
2021-03-20 23:28:21 -07:00
parent d8f47768f9
commit 0a42934c08
2 changed files with 17 additions and 0 deletions
+4
View File
@@ -95,6 +95,10 @@ def extract_image_filter(
log.debug(f"Skipping JPEG2000 iamge, xref {xref}")
return None # Don't do JPEG2000
if filtdp[0] == Name.CCITTFaxDecode and filtdp[1].get('/K', 0) >= 0:
log.debug(f"Skipping CCITT Group 3 image, xref {xref}")
return None # pikepdf doesn't support Group 3 yet
if Name.Decode in image:
log.debug(f"Skipping image with Decode table, xref {xref}")
return None # Don't mess with custom Decode tables
+13
View File
@@ -185,3 +185,16 @@ def test_optimize_off(resources, outpdf):
'--plugin',
'tests/plugins/tesseract_noop.py',
)
def test_group3(resources, outdir):
with pikepdf.open(resources / 'ccitt.pdf') as pdf:
im = pdf.pages[0].Resources.XObject['/Im1']
assert (
opt.extract_image_filter(pdf, outdir, im, im.objgen[0]) is not None
), "Group 4 should be allowed"
im.DecodeParms['/K'] = 0
assert (
opt.extract_image_filter(pdf, outdir, im, im.objgen[0]) is None
), "Group 3 should be disallowed"