Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libtiff to v4.6.0 #15

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
524 changes: 270 additions & 254 deletions Source/LibTIFF4/CMakeLists.txt

Large diffs are not rendered by default.

3,835 changes: 3,834 additions & 1 deletion Source/LibTIFF4/ChangeLog
tbeu marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Source/LibTIFF4/RELEASE-DATE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20210416
20230908
29 changes: 1 addition & 28 deletions Source/LibTIFF4/tif_config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@
/* Define to 1 if you have the `getopt' function. */
#cmakedefine HAVE_GETOPT 1

/* Define to 1 if you have the <GLUT/glut.h> header file. */
#cmakedefine HAVE_GLUT_GLUT_H 1

/* Define to 1 if you have the <GL/glut.h> header file. */
#cmakedefine HAVE_GL_GLUT_H 1

/* Define to 1 if you have the <GL/glu.h> header file. */
#cmakedefine HAVE_GL_GLU_H 1

/* Define to 1 if you have the <GL/gl.h> header file. */
#cmakedefine HAVE_GL_GL_H 1

/* Define to 1 if you have the <io.h> header file. */
#cmakedefine HAVE_IO_H 1

Expand All @@ -61,12 +49,6 @@
/* Define to 1 if you have the `mmap' function. */
#cmakedefine HAVE_MMAP 1

/* Define to 1 if you have the <OpenGL/glu.h> header file. */
#cmakedefine HAVE_OPENGL_GLU_H 1

/* Define to 1 if you have the <OpenGL/gl.h> header file. */
#cmakedefine HAVE_OPENGL_GL_H 1

/* Define to 1 if you have the `setmode' function. */
#cmakedefine HAVE_SETMODE 1

Expand Down Expand Up @@ -100,33 +82,24 @@
/* Define to the full name of this package. */
#define PACKAGE_NAME "@PACKAGE_NAME@"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "@PACKAGE_STRING@"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "@PACKAGE_TARNAME@"

/* Define to the home page for this package. */
#define PACKAGE_URL "@PACKAGE_URL@"

/* Define to the version of this package. */
#define PACKAGE_VERSION "@PACKAGE_VERSION@"

/* Size of size_t */
#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@

/* Default size of the strip in bytes (when strip chopping enabled) */
#define STRIP_SIZE_DEFAULT @STRIP_SIZE_DEFAULT@
#cmakedefine STRIP_SIZE_DEFAULT @STRIP_SIZE_DEFAULT@

/** Maximum number of TIFF IFDs that libtiff can iterate through in a file. */
#define TIFF_MAX_DIR_COUNT @TIFF_MAX_DIR_COUNT@

/* define to use win32 IO system */
#cmakedefine USE_WIN32_FILEIO 1

/* Version number of package */
#define VERSION "@PACKAGE_VERSION@"

/* Support WEBP compression */
#cmakedefine WEBP_SUPPORT 1

Expand Down
27 changes: 0 additions & 27 deletions Source/LibTIFF4/tif_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@
/* Define to 1 if you have the `getopt' function. */
#undef HAVE_GETOPT

/* Define to 1 if you have the <GLUT/glut.h> header file. */
#undef HAVE_GLUT_GLUT_H

/* Define to 1 if you have the <GL/glut.h> header file. */
#undef HAVE_GL_GLUT_H

/* Define to 1 if you have the <GL/glu.h> header file. */
#undef HAVE_GL_GLU_H

/* Define to 1 if you have the <GL/gl.h> header file. */
#undef HAVE_GL_GL_H

/* Define to 1 if you have the <io.h> header file. */
#undef HAVE_IO_H

Expand All @@ -61,12 +49,6 @@
/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP

/* Define to 1 if you have the <OpenGL/glu.h> header file. */
#undef HAVE_OPENGL_GLU_H

/* Define to 1 if you have the <OpenGL/gl.h> header file. */
#undef HAVE_OPENGL_GL_H

/* Define to 1 if you have the `setmode' function. */
#undef HAVE_SETMODE

Expand Down Expand Up @@ -103,18 +85,12 @@
/* Define to the full name of this package. */
#undef PACKAGE_NAME

/* Define to the full name and version of this package. */
#undef PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME

/* Define to the home page for this package. */
#undef PACKAGE_URL

/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* The size of `size_t', as computed by sizeof. */
#undef SIZEOF_SIZE_T

Expand All @@ -127,9 +103,6 @@
/* define to use win32 IO system */
#undef USE_WIN32_FILEIO

/* Version number of package */
#undef VERSION

/* Support webp compression */
#undef WEBP_SUPPORT

Expand Down
8 changes: 4 additions & 4 deletions Source/LibTIFF4/tif_dirinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ const TIFFField *TIFFFieldWithTag(TIFF *tif, uint32_t tag)
const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
if (!fip)
{
TIFFErrorExtR(tif, "TIFFFieldWithTag",
"Internal error, unknown tag 0x%x", (unsigned int)tag);
TIFFWarningExtR(tif, "TIFFFieldWithTag", "Warning, unknown tag 0x%x",
(unsigned int)tag);
}
return (fip);
}
Expand All @@ -853,8 +853,8 @@ const TIFFField *TIFFFieldWithName(TIFF *tif, const char *field_name)
const TIFFField *fip = _TIFFFindFieldByName(tif, field_name, TIFF_ANY);
if (!fip)
{
TIFFErrorExtR(tif, "TIFFFieldWithName",
"Internal error, unknown tag %s", field_name);
TIFFWarningExtR(tif, "TIFFFieldWithName", "Warning, unknown tag %s",
field_name);
}
return (fip);
}
Expand Down
11 changes: 8 additions & 3 deletions Source/LibTIFF4/tif_dirread.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ static void TIFFReadDirEntryCheckedFloat(TIFF *tif, TIFFDirEntry *direntry,
float *value);
static enum TIFFReadDirEntryErr
TIFFReadDirEntryCheckedDouble(TIFF *tif, TIFFDirEntry *direntry, double *value);
#if 0
static enum TIFFReadDirEntryErr
TIFFReadDirEntryCheckedRationalDirect(TIFF *tif, TIFFDirEntry *direntry,
TIFFRational_t *value);

#endif
static enum TIFFReadDirEntryErr
TIFFReadDirEntryCheckRangeByteSbyte(int8_t value);
static enum TIFFReadDirEntryErr
Expand Down Expand Up @@ -3472,6 +3473,7 @@ TIFFReadDirEntryCheckedSrational(TIFF *tif, TIFFDirEntry *direntry,
return (TIFFReadDirEntryErrOk);
}

#if 0
static enum TIFFReadDirEntryErr
TIFFReadDirEntryCheckedRationalDirect(TIFF *tif, TIFFDirEntry *direntry,
TIFFRational_t *value)
Expand Down Expand Up @@ -3512,6 +3514,7 @@ TIFFReadDirEntryCheckedRationalDirect(TIFF *tif, TIFFDirEntry *direntry,
value->uDenom = m.i[1];
return (TIFFReadDirEntryErrOk);
} /*-- TIFFReadDirEntryCheckedRationalDirect() --*/
#endif

static void TIFFReadDirEntryCheckedFloat(TIFF *tif, TIFFDirEntry *direntry,
float *value)
Expand Down Expand Up @@ -4569,7 +4572,8 @@ int TIFFReadDirectory(TIFF *tif)
}
}
break;
/* END REV 4.0 COMPATIBILITY */
/* END REV 4.0 COMPATIBILITY */
#if 0
case TIFFTAG_EP_BATTERYLEVEL:
/* TIFFTAG_EP_BATTERYLEVEL can be RATIONAL or ASCII.
* LibTiff defines it as ASCII and converts RATIONAL to an
Expand Down Expand Up @@ -4613,6 +4617,7 @@ int TIFFReadDirectory(TIFF *tif)
break;
}
break;
#endif
default:
(void)TIFFFetchNormalTag(tif, dp, TRUE);
break;
Expand Down Expand Up @@ -5033,7 +5038,7 @@ static void TIFFReadDirectoryCheckOrder(TIFF *tif, TIFFDirEntry *dir,
uint16_t dircount)
{
static const char module[] = "TIFFReadDirectoryCheckOrder";
uint16_t m;
uint32_t m;
uint16_t n;
TIFFDirEntry *o;
m = 0;
Expand Down
33 changes: 20 additions & 13 deletions Source/LibTIFF4/tif_dirwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -2073,34 +2073,41 @@ static int TIFFWriteDirectoryTagTransferfunction(TIFF *tif, uint32_t *ndir,
(*ndir)++;
return (1);
}
/* TIFFTAG_TRANSFERFUNCTION expects (1 or 3) pointer to arrays with
* (1 << BitsPerSample) * uint16_t values.
*/
m = (1 << tif->tif_dir.td_bitspersample);
n = tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples;
/* clang-format off */
n = (tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples) > 1 ? 3 : 1;
/* clang-format on */

/* Check for proper number of transferfunctions */
for (int i = 0; i < n; i++)
{
if (tif->tif_dir.td_transferfunction[i] == NULL)
{
TIFFWarningExtR(
tif, module,
"Too few TransferFunctions provided. Tag not written to file");
return (1); /* Not an error; only tag is not written. */
}
}
/*
* Check if the table can be written as a single column,
* or if it must be written as 3 columns. Note that we
* write a 3-column tag if there are 2 samples/pixel and
* a single column of data won't suffice--hmm.
*/
if (n > 3)
n = 3;
if (n == 3)
{
if (tif->tif_dir.td_transferfunction[2] == NULL ||
!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],
if (!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],
tif->tif_dir.td_transferfunction[2],
m * sizeof(uint16_t)))
n = 2;
}
if (n == 2)
{
if (tif->tif_dir.td_transferfunction[1] == NULL ||
m * sizeof(uint16_t)) &&
!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],
tif->tif_dir.td_transferfunction[1],
m * sizeof(uint16_t)))
n = 1;
}
if (n == 0)
n = 1;
o = _TIFFmallocExt(tif, n * m * sizeof(uint16_t));
if (o == NULL)
{
Expand Down
87 changes: 84 additions & 3 deletions Source/LibTIFF4/tif_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ typedef struct
{
uint16_t nSamples; /* number of samples per pixel */

int lossless; /* lossy/lossless compression */
int quality_level; /* compression level */
WebPPicture sPicture; /* WebP Picture */
int lossless; /* lossy/lossless compression */
int lossless_exact; /* lossless exact mode. If TRUE, R,G,B values in areas
with alpha = 0 will be preserved */
int quality_level; /* compression level */
WebPPicture sPicture; /* WebP Picture */
WebPConfig sEncoderConfig; /* WebP encoder config */
uint8_t *pBuffer; /* buffer to hold raw data on encoding */
unsigned int buffer_offset; /* current offset into the buffer */
Expand Down Expand Up @@ -149,6 +151,64 @@ static int TWebPDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
segment_height = td->td_rowsperstrip;
}

int webp_width, webp_height;
if (!WebPGetInfo(tif->tif_rawcp,
(uint64_t)tif->tif_rawcc > UINT32_MAX
? UINT32_MAX
: (uint32_t)tif->tif_rawcc,
&webp_width, &webp_height))
{
TIFFErrorExtR(tif, module, "WebPGetInfo() failed");
return 0;
}
if ((uint32_t)webp_width != segment_width ||
(uint32_t)webp_height != segment_height)
{
TIFFErrorExtR(
tif, module, "WebP blob dimension is %dx%d. Expected %ux%u",
webp_width, webp_height, segment_width, segment_height);
return 0;
}

#if WEBP_DECODER_ABI_VERSION >= 0x0002
WebPDecoderConfig config;
if (!WebPInitDecoderConfig(&config))
{
TIFFErrorExtR(tif, module, "WebPInitDecoderConfig() failed");
return 0;
}

const bool bWebPGetFeaturesOK =
WebPGetFeatures(tif->tif_rawcp,
(uint64_t)tif->tif_rawcc > UINT32_MAX
? UINT32_MAX
: (uint32_t)tif->tif_rawcc,
&config.input) == VP8_STATUS_OK;

WebPFreeDecBuffer(&config.output);

if (!bWebPGetFeaturesOK)
{
TIFFErrorExtR(tif, module, "WebPInitDecoderConfig() failed");
return 0;
}

const int webp_bands = config.input.has_alpha ? 4 : 3;
if (webp_bands != sp->nSamples &&
/* We accept the situation where the WebP blob has only 3 bands,
* whereas the raster is 4 bands. This can happen when the alpha
* channel is fully opaque, and WebP decoding works fine in that
* situation.
*/
!(webp_bands == 3 && sp->nSamples == 4))
{
TIFFErrorExtR(tif, module,
"WebP blob band count is %d. Expected %d", webp_bands,
sp->nSamples);
return 0;
}
#endif

buffer_size = segment_width * segment_height * sp->nSamples;
if (occ == (tmsize_t)buffer_size)
{
Expand Down Expand Up @@ -461,6 +521,9 @@ static int TWebPSetupEncode(TIFF *tif)
if (sp->lossless)
{
sp->sPicture.use_argb = 1;
#if WEBP_ENCODER_ABI_VERSION >= 0x0209
sp->sEncoderConfig.exact = sp->lossless_exact;
#endif
}
#endif

Expand Down Expand Up @@ -695,6 +758,17 @@ static int TWebPVSetField(TIFF *tif, uint32_t tag, va_list ap)
"Need to upgrade WEBP driver, this version doesn't support "
"lossless compression.");
return 0;
#endif
case TIFFTAG_WEBP_LOSSLESS_EXACT:
#if WEBP_ENCODER_ABI_VERSION >= 0x0209
sp->lossless_exact = va_arg(ap, int);
return 1;
#else
TIFFErrorExtR(
tif, module,
"Need to upgrade WEBP driver, this version doesn't support "
"lossless compression.");
return 0;
#endif
default:
return (*sp->vsetparent)(tif, tag, ap);
Expand All @@ -714,6 +788,9 @@ static int TWebPVGetField(TIFF *tif, uint32_t tag, va_list ap)
case TIFFTAG_WEBP_LOSSLESS:
*va_arg(ap, int *) = sp->lossless;
break;
case TIFFTAG_WEBP_LOSSLESS_EXACT:
*va_arg(ap, int *) = sp->lossless_exact;
break;
default:
return (*sp->vgetparent)(tif, tag, ap);
}
Expand All @@ -726,6 +803,9 @@ static const TIFFField TWebPFields[] = {
{TIFFTAG_WEBP_LOSSLESS, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "WEBP lossless/lossy",
NULL},
{TIFFTAG_WEBP_LOSSLESS_EXACT, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "WEBP exact lossless",
NULL},
};

int TIFFInitWebP(TIFF *tif, int scheme)
Expand Down Expand Up @@ -764,6 +844,7 @@ int TIFFInitWebP(TIFF *tif, int scheme)
/* Default values for codec-specific fields */
sp->quality_level = 75; /* default comp. level */
sp->lossless = 0; /* default to false */
sp->lossless_exact = 1; /* exact lossless mode (if lossless enabled) */
sp->state = 0;
sp->nSamples = 0;
sp->psDecoder = NULL;
Expand Down
Loading