Skip to content

Commit 6ffb53f

Browse files
committed
win32: Show TIFF errors 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. Such error messages can be triggered by TIFF files which include vendor specific tags. Signed-off-by: Stefan Weil <[email protected]>
1 parent 460c4a6 commit 6ffb53f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/api/tesseractmain.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242

4343
#include <tiffio.h>
4444

45+
static void Win32ErrorHandler(const char* module, const char* fmt,
46+
va_list ap) {
47+
if (module != nullptr) {
48+
fprintf(stderr, "%s: ", module);
49+
}
50+
vfprintf(stderr, fmt, ap);
51+
fprintf(stderr, ".\n");
52+
}
53+
4554
static void Win32WarningHandler(const char* module, const char* fmt,
4655
va_list ap) {
4756
if (module != nullptr) {
@@ -481,9 +490,10 @@ int main(int argc, char** argv) {
481490
#endif
482491

483492
#if defined(HAVE_TIFFIO_H) && defined(_WIN32)
484-
/* Show libtiff warnings on console (not in GUI). */
493+
/* Show libtiff errors and warnings on console (not in GUI). */
494+
TIFFSetErrorHandler(Win32ErrorHandler);
485495
TIFFSetWarningHandler(Win32WarningHandler);
486-
#endif /* HAVE_TIFFIO_H && _WIN32 */
496+
#endif // HAVE_TIFFIO_H && _WIN32
487497

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

0 commit comments

Comments
 (0)