From 245eebdf293ac19f1fb85c36e51daaaa1b5e5a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdenko=20Podobn=C3=BD?= Date: Wed, 7 Dec 2016 21:40:51 +0100 Subject: [PATCH] Multi-page TIFF buffering is broken - fix #233 --- api/baseapi.cpp | 6 ++++-- classify/mastertrainer.cpp | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/baseapi.cpp b/api/baseapi.cpp index 582fbfbb..4104b93d 100644 --- a/api/baseapi.cpp +++ b/api/baseapi.cpp @@ -1028,6 +1028,7 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data, OpenclDevice od; #endif // USE_OPENCL int page = (tessedit_page_number >= 0) ? tessedit_page_number : 0; + size_t offset = 0; for (; ; ++page) { if (tessedit_page_number >= 0) page = tessedit_page_number; @@ -1039,8 +1040,8 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data, } else { #endif // USE_OPENCL pix = (data) ? - pixReadMemTiff(data, size, page) : - pixReadTiff(filename, page); + pixReadMemFromMultipageTiff(data, size, &offset) : + pixReadFromMultipageTiff(filename, &offset); #ifdef USE_OPENCL } #endif // USE_OPENCL @@ -1054,6 +1055,7 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data, pixDestroy(&pix); if (!r) return false; if (tessedit_page_number >= 0) break; + if (!offset) break; } return true; #else diff --git a/classify/mastertrainer.cpp b/classify/mastertrainer.cpp index cd7e93b9..849fb060 100644 --- a/classify/mastertrainer.cpp +++ b/classify/mastertrainer.cpp @@ -214,10 +214,14 @@ void MasterTrainer::AddSample(bool verification, const char* unichar, // Must be called after ReadTrainingSamples, as the current number of images // is used as an offset for page numbers in the samples. void MasterTrainer::LoadPageImages(const char* filename) { + size_t offset = 0; int page; Pix* pix; - for (page = 0; (pix = pixReadTiff(filename, page)) != NULL; ++page) { + for (page = 0; ; page++) { + pix = pixReadFromMultipageTiff(filename, &offset); + if (!pix) break; page_images_.push_back(pix); + if (!offset) break; } tprintf("Loaded %d page images from %s\n", page, filename); }