MCPcopy Create free account
hub / github.com/creatale/node-dv / ProcessPagesFileList

Method ProcessPagesFileList

deps/tesseract/api/baseapi.cpp:960–1016  ·  view source on GitHub ↗

If flist exists, get data from there. Otherwise get data from buf. Seems convoluted, but is the easiest way I know of to meet multiple goals. Support streaming from stdin, and also work on platforms lacking fmemopen.

Source from the content-addressed store, hash-verified

958// goals. Support streaming from stdin, and also work on platforms
959// lacking fmemopen.
960bool TessBaseAPI::ProcessPagesFileList(FILE *flist,
961 STRING *buf,
962 const char* retry_config,
963 int timeout_millisec,
964 TessResultRenderer* renderer,
965 int tessedit_page_number) {
966 if (!flist && !buf) return false;
967 int page = (tessedit_page_number >= 0) ? tessedit_page_number : 0;
968 char pagename[MAX_PATH];
969
970 GenericVector<STRING> lines;
971 if (!flist) {
972 buf->split('\n', &lines);
973 if (lines.empty()) return false;
974 }
975
976 // Skip to the requested page number.
977 for (int i = 0; i < page; i++) {
978 if (flist) {
979 if (fgets(pagename, sizeof(pagename), flist) == NULL) break;
980 }
981 }
982
983 // Begin producing output
984 if (renderer && !renderer->BeginDocument(unknown_title_)) {
985 return false;
986 }
987
988 // Loop over all pages - or just the requested one
989 while (true) {
990 if (flist) {
991 if (fgets(pagename, sizeof(pagename), flist) == NULL) break;
992 } else {
993 if (page >= lines.size()) break;
994 snprintf(pagename, sizeof(pagename), "%s", lines[page].c_str());
995 }
996 chomp_string(pagename);
997 Pix *pix = pixRead(pagename);
998 if (pix == NULL) {
999 tprintf("Image file %s cannot be read!\n", pagename);
1000 return false;
1001 }
1002 tprintf("Page %d : %s\n", page, pagename);
1003 bool r = ProcessPage(pix, page, pagename, retry_config,
1004 timeout_millisec, renderer);
1005 pixDestroy(&pix);
1006 if (!r) return false;
1007 if (tessedit_page_number >= 0) break;
1008 ++page;
1009 }
1010
1011 // Finish producing output
1012 if (renderer && !renderer->EndDocument()) {
1013 return false;
1014 }
1015 return true;
1016}
1017

Callers

nothing calls this directly

Calls 9

chomp_stringFunction · 0.85
pixReadFunction · 0.85
pixDestroyFunction · 0.85
BeginDocumentMethod · 0.80
EndDocumentMethod · 0.80
splitMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected