optimize: fix PNGs that were reduced to 1-bit being inverted

At some point the color gets flipped, we have to flip it again,
for mono.

Incidentally this exposed an unused
optimization. Should change the
first past to scan all images and
record monochrome xrefs, then optimize
JPEG and PNG, possibly adding
mono images to the monochrome
queue. Finally, do JBIG2 optimization.
This commit is contained in:
James R. Barlow
2018-06-29 00:09:20 -07:00
parent 9637696a54
commit 0029cc4fe7
2 changed files with 5 additions and 0 deletions
+3
View File
@@ -496,6 +496,9 @@ class Pix:
raise LeptonicaError("Generate PDF data failed")
return CompressedData(p_compdata[0])
def invert(self):
return Pix(lept.pixInvert(ffi.NULL, self._pix))
@staticmethod
def _pix_destroy(pix):
p_pix = ffi.new('PIX **', pix)
+2
View File
@@ -261,6 +261,8 @@ def transcode_pngs(pike, pngs, root, log, options):
# Open, transcode (!), package for PDF
try:
pix = leptonica.Pix.open(png_name(root, xref))
if pix.depth == 1:
pix = pix.invert() # PDF assumes 1 is black for monochrome
compdata = pix.generate_pdf_ci_data(
leptonica.lept.L_FLATE_ENCODE, 0
)