Multi-page TIFF buffering is broken - fix #233

This commit is contained in:
Zdenko Podobný 2016-12-07 21:40:51 +01:00
parent 092c7d5690
commit 245eebdf29
2 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -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);
}