DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.72k stars 384 forks source link

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

Open johnsonea opened 8 months ago

johnsonea commented 8 months ago

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.)

DanBloomberg commented 8 months ago

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

stweil commented 8 months ago

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.

DanBloomberg commented 8 months ago

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.

johnsonea commented 8 months ago

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.