Try to optimize paletted images

This commit is contained in:
James R. Barlow
2018-05-11 23:42:26 -07:00
parent 8790fc2c1b
commit 6c50c70235
3 changed files with 13 additions and 2 deletions
+10 -1
View File
@@ -125,7 +125,7 @@ def extract_image(*, doc, pike, root, log, image, xref, jbig2s,
log.debug("Skipping small image, xref {}".format(xref))
return False
bpc = image.get('/BitsPerComponent', 8)
bpc = int(image.get('/BitsPerComponent', 8))
cs = image.get('/ColorSpace', '')
w = int(image.Width)
h = int(image.Height)
@@ -177,6 +177,15 @@ def extract_image(*, doc, pike, root, log, image, xref, jbig2s,
raw_jpeg_data = raw_jpeg.read_raw_bytes()
(root / '{:08d}.jpg'.format(xref)).write_bytes(raw_jpeg_data)
jpegs.append(xref)
elif cs[0] == '/Indexed' \
and cs[1] in SIMPLE_COLORSPACES \
and options.optimize >= 3 \
and fitz:
# Try to improve on indexed images - these are far from low hanging
# fruit in most cases
pix = fitz.Pixmap(doc, xref)
pix.writePNG(make_img_name(root, xref), savealpha=False)
pngs.append(xref)
elif cs in SIMPLE_COLORSPACES and fitz:
# For any 'inferior' filter including /FlateDecode we extract
# and recode as /FlateDecode
+3
View File
@@ -514,6 +514,9 @@ class CompressedData:
raise LeptonicaError("CompressedData.open")
return CompressedData(p_compdata[0])
def __len__(self):
return self._compdata.nbytescomp
def read(self):
buf = ffi.buffer(self._compdata.datacomp, self._compdata.nbytescomp)
return bytes(buf)
-1
View File
@@ -960,7 +960,6 @@ def weave_layers(
procset = pdf_base.pages[0].Resources.ProcSet
font = pdf_base.pages[0].Resources.Font.get(font_key)
pdf_base.save(output_file)