From 1181cc0a6cc18c0d7a4142a9a11252964c29ddc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Tue, 2 Mar 2021 21:44:05 +0100 Subject: [PATCH] Always use L_FLATE_ENCODE in PdfRenderer (fixes #31) LIBRARY CHANGE --- tesseract4android/src/main/cpp/leptonica/CMakeLists.txt | 2 ++ .../src/main/cpp/tesseract/src/src/api/pdfrenderer.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tesseract4android/src/main/cpp/leptonica/CMakeLists.txt b/tesseract4android/src/main/cpp/leptonica/CMakeLists.txt index 52d127dc..9d7f22a8 100644 --- a/tesseract4android/src/main/cpp/leptonica/CMakeLists.txt +++ b/tesseract4android/src/main/cpp/leptonica/CMakeLists.txt @@ -67,6 +67,8 @@ add_definitions(-DANDROID_BUILD) add_definitions(-DHAVE_LIBJPEG=1) add_definitions(-DHAVE_LIBPNG=1) add_definitions(-DHAVE_LIBZ=1) +# TODO: Enable this when we use minSdkVersion 23 or higher and remove workaround in pdfrenderer.cpp +#add_definitions(-DHAVE_FMEMOPEN=1) # Ignore some warnings during build target_compile_options(leptonica PRIVATE "-Wno-address-of-packed-member") diff --git a/tesseract4android/src/main/cpp/tesseract/src/src/api/pdfrenderer.cpp b/tesseract4android/src/main/cpp/tesseract/src/src/api/pdfrenderer.cpp index 2ee85fed..4dc224a1 100644 --- a/tesseract4android/src/main/cpp/tesseract/src/src/api/pdfrenderer.cpp +++ b/tesseract4android/src/main/cpp/tesseract/src/src/api/pdfrenderer.cpp @@ -675,8 +675,14 @@ bool TessPDFRenderer::imageToPDFObj(Pix *pix, L_Compressed_Data *cid = nullptr; +#ifdef __ANDROID__ // Remove this when we use minSdkVersion 23 or higher + bool flateEncode = true; +#else + bool flateEncode = pixGetInputFormat(pix) == IFF_PNG; +#endif + int sad = 0; - if (pixGetInputFormat(pix) == IFF_PNG) + if (flateEncode) sad = pixGenerateCIData(pix, L_FLATE_ENCODE, 0, 0, &cid); if (!cid) { sad = l_generateCIDataForPdf(filename, pix, jpg_quality, &cid);