Skip to content

Commit

Permalink
win32: Show TIFF errors on console
Browse files Browse the repository at this point in the history
Showing them in a window (default) is not acceptable for a console
application like Tesseract which must be able to work in batch mode.

Such error messages can be triggered by TIFF files which include
vendor specific tags.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Oct 13, 2018
1 parent 460c4a6 commit 6ffb53f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@

#include <tiffio.h>

static void Win32ErrorHandler(const char* module, const char* fmt,
va_list ap) {
if (module != nullptr) {
fprintf(stderr, "%s: ", module);
}
vfprintf(stderr, fmt, ap);
fprintf(stderr, ".\n");
}

static void Win32WarningHandler(const char* module, const char* fmt,
va_list ap) {
if (module != nullptr) {
Expand Down Expand Up @@ -481,9 +490,10 @@ int main(int argc, char** argv) {
#endif

#if defined(HAVE_TIFFIO_H) && defined(_WIN32)
/* Show libtiff warnings on console (not in GUI). */
/* Show libtiff errors and warnings on console (not in GUI). */
TIFFSetErrorHandler(Win32ErrorHandler);
TIFFSetWarningHandler(Win32WarningHandler);
#endif /* HAVE_TIFFIO_H && _WIN32 */
#endif // HAVE_TIFFIO_H && _WIN32

ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath, &dpi,
&list_langs, &print_parameters, &vars_vec, &vars_values, &arg_i,
Expand Down

0 comments on commit 6ffb53f

Please sign in to comment.