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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user