leptonica icon indicating copy to clipboard operation
leptonica copied to clipboard

Suggest noting that libtiff must have been compiled with JPEG compression support for tests to run correctly

Open johnsonea opened this issue 1 year ago • 4 comments

If libtiff has NOT been installed with JPEG compression (i.e., ./configure --enable-jpeg --enable-old-jpeg), then ioformats_reg gives errors on four images (FILE_8BPP_1, FILE_8BPP_2, FILE_8BPP_3, "testbuffer.tif") .

A note or warning in the leptonica documentation that JPEG must be enabled in libtiff would be helpful. Thx!

(pngio_reg also gave errors that disappeared when libtiff was recomplied with JPEGs upport, but I did not investigate closely to see where or why.)

johnsonea avatar Nov 01 '23 07:11 johnsonea

Thank you. I will amend the README.html to note that libjpeg is required with libtiff. Also:

  • modify tiffio.c to require libjpeg
  • modify tiffiostub.c to be used if libjpeg is not defined
  • modify ioFormatTest() to require libjpeg for tiff tests.

DanBloomberg avatar Nov 01 '23 21:11 DanBloomberg

I'm not sure whether that's the best solution for the reported issue. TIFF files can be uncompressed, and such files work well with Leptonica and a libtiff without JPEG support.

stweil avatar Nov 01 '23 21:11 stweil

It seems to me quite complicated to not require jpeg support for tiff, because many of the functions in tiffio.c accept the JPEG compression type as an argument. And because tiff, jpeg and png are the standard, expected libraries in the environment in which tesseract is running, it doesn't seem like a stretch to require jpeg for read/write of tiff.

Also, for maintenance it is important to do everything possible to avoid problems with building that happen because functions asked for are missing. And if there is a failure at runtime, it's good to have a simple error message that says something to the effect that tiff is not supported. I could expand that error message in tiffiostub.c if you think it would be useful in the event of a runtime error to point out the necessity of having both libtiff and libjpeg.

DanBloomberg avatar Nov 01 '23 23:11 DanBloomberg

To diagnose why some TIFF images were giving an error, I temporarily edited libtiff's tif_getimage.c to add an fprintf(stderr,...,emsg) call in function TIFFReadRGBAImageOriented to see what the real error was. That was obviously a hack and not appropriate for real operation.

libtiff does have an error mechanism that -- if you can figure out how to use it's TIFFError*, TIFFErrorHandler* and TIFFSetErrorHandler* functions (I couldn't decipher how to use them) -- might provide a significantly more precise error message within leptonica's tiff* functions. That would be very helpful to the user.

johnsonea avatar Nov 01 '23 23:11 johnsonea