Use png256 raster device when possible

Someone reported a bug where the .png input to unpaper ended up being
type 'P' (palette) for some reason, which was not supported in unpaper.

Not sure how it happened, but seemed easier to fix by explicitly
supporting. Here we use png256 if it would capture all colors in the
input file. It's up to tesseract/reportlab to make use of the palette
PNG when rendering.
This commit is contained in:
James R. Barlow 2015-08-28 04:47:57 -07:00
parent 3a445ad5f7
commit 83f9dfbac4
2 changed files with 8 additions and 2 deletions

View File

@ -475,10 +475,15 @@ def rasterize_with_ghostscript(
if all(image['comp'] == 1 for image in pageinfo['images']):
if all(image['bpc'] == 1 for image in pageinfo['images']):
device = 'pngmono'
elif not any(image['color'] == 'color'
for image in pageinfo['images']):
elif all(image['bpc'] > 1 and image['color'] == 'index'
for image in pageinfo['images']):
device = 'png256'
elif all(image['bpc'] > 1 and image['color'] == 'gray'
for image in pageinfo['images']):
device = 'pnggray'
log.debug("Rendering {0} with {1}".format(
os.path.basename(input_file), device))
xres = max(pageinfo['xres'], options.oversample or 0)
yres = max(pageinfo['yres'], options.oversample or 0)

View File

@ -34,6 +34,7 @@ FRIENDLY_COMP = {
'rgb': 3,
'cmyk': 4,
'lab': 3,
'index': 1
}