Set up filter_ocr_image hook

This commit is contained in:
James R. Barlow
2020-05-01 02:56:41 -07:00
parent 8d2535e327
commit be107b4fed
5 changed files with 30 additions and 9 deletions
+1 -1
View File
@@ -194,7 +194,7 @@ def validate_pdfinfo_options(context):
"form and all filled form fields. The output PDF will be "
"'flattened' and will no longer be fillable."
)
context.plugin_manager.hook.prepare(options=options)
context.plugin_manager.hook.validate(pdfinfo=pdfinfo, options=options)
def get_page_dpi(pageinfo, options):
+17
View File
@@ -1,3 +1,20 @@
# © 2020 James R. Barlow: github.com/jbarlow83
#
# This file is part of OCRmyPDF.
#
# OCRmyPDF is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OCRmyPDF is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
import importlib
import pluggy
+2
View File
@@ -320,6 +320,8 @@ def run_pipeline(options, api=False):
options,
)
pm.hook.prepare(options=options)
# Gather pdfinfo and create context
pdfinfo = get_pdfinfo(
origin_pdf,
+9
View File
@@ -1,11 +1,20 @@
import logging
from ocrmypdf import hookimpl
log = logging.getLogger(__name__)
@hookimpl
def prepare(options):
pass
@hookimpl
def validate(pdfinfo, options):
pass
@hookimpl
def filter_ocr_image(image):
return image
+1 -8
View File
@@ -33,13 +33,6 @@ def prepare(options: Namespace) -> None:
The plugin may modify the options. All objects that are in options must
be picklable so they can be marshalled to child worker processes.
Typically, a plugin will call ``registry.register_plugin(__name__)`` to register
all of its public functions with the plugin registry. Functions that are
not intended for registration should be prefixed with an underscore.
Functions that imported from other modules will be ignored by
``.register_plugin()``. For example if you use ``from os import basename``,
``basename`` will not be registered.
"""
@@ -57,7 +50,7 @@ def validate(pdfinfo: PdfInfo, options: Namespace) -> None:
"""
@hookspec
@hookspec(firstresult=True)
def filter_ocr_image(image: Image) -> Image:
"""Called to filter the image before it is sent to OCR.