Skip to content

Commit

Permalink
Require libjpeg for reading and writing tiff files
Browse files Browse the repository at this point in the history
* Also fix colorcontent_reg to work with different jpeg libraries
* Fixes Issue #719 and Issue #720, reported by @johnsonea.
* Documentation change for Issue #717, reported by @kloczek.
  • Loading branch information
DanBloomberg committed Nov 1, 2023
1 parent 6d2c1c5 commit 21d901e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
7 changes: 5 additions & 2 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ <h2> <A NAME="BUILDING">
This works even if you build in a different
place from the distribution. The -j parameter
should not exceed half the number of cores.
If the test fails, just run with 'make check']
NOTE: If the test fails, it's likely due to a race
condition. Rerun with 'make check']

Configure supports installing in a local directory (e.g., one that
doesn't require root access). For example, to install in $HOME/local,
Expand Down Expand Up @@ -968,7 +969,9 @@ <h2> <A NAME="CONTENTS">
text and line art images, but it does quite poorly for halftones.
It has good and stable support by Leffler's open source library,
which is clean and small. Tiff also supports multipage
images through a directory structure. See tiffio.c
images through a directory structure. Note: because jpeg is
a supported tiff compression mode, leptonica requires linking
both libtiff and libjpeg to read and write tiff. See tiffio.c

- BMP has (until recently) had no compression. It is a simple
format with colormaps that requires no external libraries.
Expand Down
6 changes: 4 additions & 2 deletions prog/colorcontent_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ L_REGPARAMS *rp;
pixDestroy(&pix2);
pixDestroy(&pix3);

/* Do a simple color quantization with sigbits = 3 */
/* Do a simple color quantization with sigbits = 3.
* Roundoff from different jpeg decompression algorithms can
* result in differing numbers of colors by a few percent. */
pix1 = pixRead("wyom.jpg");
pixNumColors(pix1, 1, &ncolors); /* >255, so should give 0 */
regTestCompareValues(rp, ncolors, 132165, 0.0); /* 4 */
regTestCompareValues(rp, ncolors, 132165, 10000.0); /* 4 */
pix2 = pixSimpleColorQuantize(pix1, 3, 3, 20);
pixDisplayWithTitle(pix2, 1000, 0, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 5 */
Expand Down
4 changes: 2 additions & 2 deletions src/readfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ PIXCMAP *cmap;
#endif /* HAVE_LIBPNG */

/* ----------------------- TIFF -------------------------- */
#if HAVE_LIBTIFF
#if HAVE_LIBTIFF && HAVE_LIBJPEG
/* TIFF works for 1, 2, 4, 8, 16 and 32 bpp images.
* Because 8 bpp tiff always writes 256 entry colormaps, the
* colormap sizes may be different for 8 bpp images with
Expand Down Expand Up @@ -1478,7 +1478,7 @@ PIXCMAP *cmap;
}
pixDestroy(&pix1);
}
#endif /* HAVE_LIBTIFF */
#endif /* HAVE_LIBTIFF && HAVE_LIBJPEG */

/* ----------------------- PNM -------------------------- */

Expand Down
15 changes: 8 additions & 7 deletions src/tiffio.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
* tiff library, such as G3, G4, RLE and LZW.
* * The exception is the old-style jpeg tiff format (OJPEG), which
* is not supported.
* * We support only one format, ZIP, that uses an external library.
* * We support two formats requiring external libraries: ZIP and JPEG
* Both libz and libjpeg are required.
* * At present we do not support WEBP in tiff, which uses
* libwebp and was added in tifflib 4.1.0 in 2019.
* Note 3: On Windows with 2 bpp or 4 bpp images, the bytes in the
Expand All @@ -130,9 +131,9 @@
#include <fcntl.h>
#include "allheaders.h"

/* --------------------------------------------*/
#if HAVE_LIBTIFF /* defined in environ.h */
/* --------------------------------------------*/
/* ---------------------------------------------------------*/
#if HAVE_LIBTIFF && HAVE_LIBJPEG /* defined in environ.h */
/* ---------------------------------------------------------*/

#include "tiff.h"
#include "tiffio.h"
Expand Down Expand Up @@ -2877,6 +2878,6 @@ TIFF *tif;
return ret;
}

/* --------------------------------------------*/
#endif /* HAVE_LIBTIFF */
/* --------------------------------------------*/
/* ---------------------------------------*/
#endif /* HAVE_LIBTIFF && HAVE_LIBJPEG */
/* ---------------------------------------*/
12 changes: 6 additions & 6 deletions src/tiffiostub.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

#include "allheaders.h"

/* --------------------------------------------*/
#if !HAVE_LIBTIFF /* defined in environ.h */
/* --------------------------------------------*/
/* -----------------------------------------------------------*/
#if !HAVE_LIBTIFF || !HAVE_LIBJPEG /* defined in environ.h */
/* -----------------------------------------------------------*/

PIX * pixReadTiff(const char *filename, l_int32 n)
{
Expand Down Expand Up @@ -233,6 +233,6 @@ l_ok pixWriteMemTiffCustom(l_uint8 **pdata, size_t *psize, PIX *pix,
return ERROR_INT("function not present", __func__, 1);
}

/* --------------------------------------------*/
#endif /* !HAVE_LIBTIFF */
/* --------------------------------------------*/
/* -----------------------------------------*/
#endif /* !HAVE_LIBTIFF || !HAVE_LIBJPEG */
/* -----------------------------------------*/

0 comments on commit 21d901e

Please sign in to comment.