From 896e80d9a7bef29b8d7379ff5b956b6ed9e595db Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 15 Jul 2016 23:00:00 +0200 Subject: [PATCH 1/2] win32: Show TIFF warnings on console Showing them in a window (default) is not acceptable for a console application like Tesseract which must be able to work in batch mode. Signed-off-by: Stefan Weil --- api/tesseractmain.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/tesseractmain.cpp b/api/tesseractmain.cpp index 169bb424fb..848a7a7fdd 100644 --- a/api/tesseractmain.cpp +++ b/api/tesseractmain.cpp @@ -33,6 +33,23 @@ #include "openclwrapper.h" #include "osdetect.h" +#if defined(_WIN32) + +#include +#include + +static void Win32WarningHandler(const char* module, const char* fmt, + va_list ap) { + if (module != NULL) { + fprintf(stderr, "%s: ", module); + } + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} + +#endif /* _WIN32 */ + void PrintVersionInfo() { char *versionStrP; @@ -352,6 +369,11 @@ int main(int argc, char **argv) { int arg_i = 1; tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO; +#if defined(_WIN32) + /* Show libtiff warnings on console (not in GUI). */ + TIFFSetWarningHandler(Win32WarningHandler); +#endif /* _WIN32 */ + ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath, &list_langs, &print_parameters, From 75fdc086ececb7ef8f480262e07343f77c4b4638 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 17 Jul 2016 12:07:58 +0200 Subject: [PATCH 2/2] win32: Check whether tiffio.h is available The previous commit added a dependency on tiffio.h, so enable the new code only if that file is available. The code which conditionally defines HAVE_TIFFIO_H was already there although that macro was unused up to now. Signed-off-by: Stefan Weil --- api/tesseractmain.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/tesseractmain.cpp b/api/tesseractmain.cpp index 848a7a7fdd..798888fc49 100644 --- a/api/tesseractmain.cpp +++ b/api/tesseractmain.cpp @@ -33,7 +33,7 @@ #include "openclwrapper.h" #include "osdetect.h" -#if defined(_WIN32) +#if defined(HAVE_TIFFIO_H) && defined(_WIN32) #include #include @@ -48,7 +48,7 @@ static void Win32WarningHandler(const char* module, const char* fmt, fprintf(stderr, ".\n"); } -#endif /* _WIN32 */ +#endif /* HAVE_TIFFIO_H && _WIN32 */ void PrintVersionInfo() { char *versionStrP; @@ -369,10 +369,10 @@ int main(int argc, char **argv) { int arg_i = 1; tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO; -#if defined(_WIN32) +#if defined(HAVE_TIFFIO_H) && defined(_WIN32) /* Show libtiff warnings on console (not in GUI). */ TIFFSetWarningHandler(Win32WarningHandler); -#endif /* _WIN32 */ +#endif /* HAVE_TIFFIO_H && _WIN32 */ ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath,