Fixes#974 when used in conjunction with Python 3.10.
Reviewed other uses of TemporaryDirectory in ocrmypdf and decided it
was not worth fixing them since neither are exactly production code.
Appears that these are spurious errors from qpdf probing the /DecodeParms
dict on images that don't have it.
Not sure exactly why it happens but this can be safely ignored.
ProcessPool/ThreadPool don't have the ability to notice when a child worker
was terminated. ProcessPoolExecutor and ThreadPoolExecutor do notice and
provide better error messages.
Add tests to check.
Specifying option --oversample tends to introduce upsampling in rendering
by rasterizing page to an higher DPI.
This upsampling improves OCR results, but a correct choice of interpolation
method can increase even more the OCR quality.
Ghostscript seems to use a nearest interpolation as default choice for pdf.
This method doesn't average new introduced pixels with original pixels
resulting in an almost similar image but with more pixels.
Providing -dInterpolateControl=-1 force switching interpolation on.
In this commit the above option is passed to all ghostscript rendering
calls.
After testing, rendering a page at same DPI with interpolation
enabled does not introduce significant time overhead.
time (repeat 40 gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m \
-dFirstPage=1 -dLastPage=1 -r100.000000x100.000000 \
-dInterpolateControl=-1 -o /dev/null -dAutoRotatePages=/None -f pzII.pdf)
7,66s user 0,33s system 99% cpu 8,012 total
time (repeat 40 gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m \
-dFirstPage=1 -dLastPage=1 -r100.000000x100.000000 \
-o /dev/null -dAutoRotatePages=/None -f pzII.pdf)
7,42s user 0,39s system 99% cpu 7,808 total
Ghostscript interpolation control reference:
https://www.ghostscript.com/doc/current/Use.htm
PDFs are quite likely to have a lot of pixels, e.g. large high resolution scans.
250 MP is a page of A0 sized paper scanned at 400 DPI,
should be enough in most cases.