From 9baccee8c5c7fdbbef0a7b48b81bc5ab285ea94c Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 20 Nov 2019 00:29:48 -0800 Subject: [PATCH] leptonica: Handle API change for pixFindPageForeground --- src/ocrmypdf/leptonica.py | 13 +++++------- src/ocrmypdf/lib/compile_leptonica.py | 30 +++++++++++++++++++-------- tests/test_lept.py | 4 ++++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/ocrmypdf/leptonica.py b/src/ocrmypdf/leptonica.py index ef2a2b82..831a0695 100644 --- a/src/ocrmypdf/leptonica.py +++ b/src/ocrmypdf/leptonica.py @@ -506,17 +506,14 @@ class Pix(LeptonicaObject): display=0, pdfdir=ffi.NULL, ): + if get_leptonica_version() < 'leptonica-1.76': + # Leptonica 1.76 changed the API for pixFindPageForeground; we don't + # support the old version + raise LeptonicaError("Not available in this version of Leptonica") with _LeptonicaErrorTrap(): cropbox = Box( lept.pixFindPageForeground( - self._cdata, - threshold, - mindist, - erasedist, - pagenum, - showmorph, - display, - pdfdir, + self._cdata, threshold, mindist, erasedist, showmorph, ffi.NULL ) ) diff --git a/src/ocrmypdf/lib/compile_leptonica.py b/src/ocrmypdf/lib/compile_leptonica.py index 5cfbb6f2..e6d3c9f3 100644 --- a/src/ocrmypdf/lib/compile_leptonica.py +++ b/src/ocrmypdf/lib/compile_leptonica.py @@ -74,6 +74,17 @@ struct Pixa }; typedef struct Pixa PIXA; +/*! Array of compressed pix */ +struct PixaComp +{ + l_int32 n; /*!< number of PixComp in ptr array */ + l_int32 nalloc; /*!< number of PixComp ptrs allocated */ + l_int32 offset; /*!< indexing offset into ptr array */ + struct PixComp **pixc; /*!< the array of ptrs to PixComp */ + struct Boxa *boxa; /*!< array of boxes */ +}; +typedef struct PixaComp PIXAC; + struct Box { l_int32 x; @@ -294,14 +305,12 @@ pixCleanBackgroundToWhite(PIX *pixs, l_int32 whiteval); BOX * -pixFindPageForeground(PIX *pixs, - l_int32 threshold, - l_int32 mindist, - l_int32 erasedist, - l_int32 pagenum, - l_int32 showmorph, - l_int32 display, - const char *pdfdir); +pixFindPageForeground ( PIX *pixs, + l_int32 threshold, + l_int32 mindist, + l_int32 erasedist, + l_int32 showmorph, + PIXAC *pixac ); PIX * pixClipRectangle(PIX *pixs, @@ -414,7 +423,10 @@ pixExtractBarcodes(PIX *pixs, l_int32 debugflag); BOXA * -pixLocateBarcodes ( PIX *pixs, l_int32 thresh, PIX **ppixb, PIX **ppixm ); +pixLocateBarcodes ( PIX *pixs, + l_int32 thresh, + PIX **ppixb, + PIX **ppixm ); SARRAY * pixReadBarcodes(PIXA *pixa, diff --git a/tests/test_lept.py b/tests/test_lept.py index 2504c600..b74f417b 100644 --- a/tests/test_lept.py +++ b/tests/test_lept.py @@ -63,6 +63,10 @@ def test_pix_otsu(crom_pix): assert im1bpp.mode == '1' +@pytest.mark.skipif( + lept.get_leptonica_version() < 'leptonica-1.76', + reason="needs new leptonica for API change", +) def test_crop(resources): pix = lept.Pix.open(resources / 'linn.png') foreground = pix.crop_to_foreground()