|
|
24df78 |
From 9ed8c91366c9f6a3c9068aee6c5a7a0fe1c5c9c8 Mon Sep 17 00:00:00 2001
|
|
|
24df78 |
From: Thomas Bernard <miniupnp@free.fr>
|
|
|
24df78 |
Date: Tue, 12 Feb 2019 16:04:28 +0100
|
|
|
24df78 |
Subject: [PATCH] move _TIFFClampDoubleToFloat() to tif_aux.c
|
|
|
24df78 |
|
|
|
24df78 |
the same function was declared in tif_dir.c and tif_dirwrite.c
|
|
|
24df78 |
|
|
|
24df78 |
see http://bugzilla.maptools.org/show_bug.cgi?id=2842
|
|
|
24df78 |
|
|
|
24df78 |
(cherry picked from commit 8420a31e8ca5181ca36580cfeeca28661b348262)
|
|
|
24df78 |
---
|
|
|
24df78 |
libtiff/tif_aux.c | 10 ++++++++++
|
|
|
24df78 |
libtiff/tif_dir.c | 20 +++++---------------
|
|
|
24df78 |
libtiff/tif_dirwrite.c | 12 +-----------
|
|
|
24df78 |
libtiff/tiffiop.h | 2 ++
|
|
|
24df78 |
4 files changed, 18 insertions(+), 26 deletions(-)
|
|
|
24df78 |
|
|
|
24df78 |
diff --git a/libtiff/tif_aux.c b/libtiff/tif_aux.c
|
|
|
24df78 |
index 38a98b67..2071d19c 100644
|
|
|
24df78 |
--- a/libtiff/tif_aux.c
|
|
|
24df78 |
+++ b/libtiff/tif_aux.c
|
|
|
24df78 |
@@ -32,6 +32,7 @@
|
|
|
24df78 |
#include "tiffiop.h"
|
|
|
24df78 |
#include "tif_predict.h"
|
|
|
24df78 |
#include <math.h>
|
|
|
24df78 |
+#include <float.h>
|
|
|
24df78 |
|
|
|
24df78 |
uint32
|
|
|
24df78 |
_TIFFMultiply32(TIFF* tif, uint32 first, uint32 second, const char* where)
|
|
|
24df78 |
@@ -398,6 +399,15 @@ _TIFFUInt64ToDouble(uint64 ui64)
|
|
|
24df78 |
}
|
|
|
24df78 |
}
|
|
|
24df78 |
|
|
|
24df78 |
+float _TIFFClampDoubleToFloat( double val )
|
|
|
24df78 |
+{
|
|
|
24df78 |
+ if( val > FLT_MAX )
|
|
|
24df78 |
+ return FLT_MAX;
|
|
|
24df78 |
+ if( val < -FLT_MAX )
|
|
|
24df78 |
+ return -FLT_MAX;
|
|
|
24df78 |
+ return (float)val;
|
|
|
24df78 |
+}
|
|
|
24df78 |
+
|
|
|
24df78 |
int _TIFFSeekOK(TIFF* tif, toff_t off)
|
|
|
24df78 |
{
|
|
|
24df78 |
/* Huge offsets, especially -1 / UINT64_MAX, can cause issues */
|
|
|
24df78 |
diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c
|
|
|
24df78 |
index f126f2aa..ad550c65 100644
|
|
|
24df78 |
--- a/libtiff/tif_dir.c
|
|
|
24df78 |
+++ b/libtiff/tif_dir.c
|
|
|
24df78 |
@@ -31,7 +31,6 @@
|
|
|
24df78 |
* (and also some miscellaneous stuff)
|
|
|
24df78 |
*/
|
|
|
24df78 |
#include "tiffiop.h"
|
|
|
24df78 |
-#include <float.h>
|
|
|
24df78 |
|
|
|
24df78 |
/*
|
|
|
24df78 |
* These are used in the backwards compatibility code...
|
|
|
24df78 |
@@ -155,15 +154,6 @@ bad:
|
|
|
24df78 |
return (0);
|
|
|
24df78 |
}
|
|
|
24df78 |
|
|
|
24df78 |
-static float TIFFClampDoubleToFloat( double val )
|
|
|
24df78 |
-{
|
|
|
24df78 |
- if( val > FLT_MAX )
|
|
|
24df78 |
- return FLT_MAX;
|
|
|
24df78 |
- if( val < -FLT_MAX )
|
|
|
24df78 |
- return -FLT_MAX;
|
|
|
24df78 |
- return (float)val;
|
|
|
24df78 |
-}
|
|
|
24df78 |
-
|
|
|
24df78 |
static int
|
|
|
24df78 |
_TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|
|
24df78 |
{
|
|
|
24df78 |
@@ -322,13 +312,13 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|
|
24df78 |
dblval = va_arg(ap, double);
|
|
|
24df78 |
if( dblval != dblval || dblval < 0 )
|
|
|
24df78 |
goto badvaluedouble;
|
|
|
24df78 |
- td->td_xresolution = TIFFClampDoubleToFloat( dblval );
|
|
|
24df78 |
+ td->td_xresolution = _TIFFClampDoubleToFloat( dblval );
|
|
|
24df78 |
break;
|
|
|
24df78 |
case TIFFTAG_YRESOLUTION:
|
|
|
24df78 |
dblval = va_arg(ap, double);
|
|
|
24df78 |
if( dblval != dblval || dblval < 0 )
|
|
|
24df78 |
goto badvaluedouble;
|
|
|
24df78 |
- td->td_yresolution = TIFFClampDoubleToFloat( dblval );
|
|
|
24df78 |
+ td->td_yresolution = _TIFFClampDoubleToFloat( dblval );
|
|
|
24df78 |
break;
|
|
|
24df78 |
case TIFFTAG_PLANARCONFIG:
|
|
|
24df78 |
v = (uint16) va_arg(ap, uint16_vap);
|
|
|
24df78 |
@@ -337,10 +327,10 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|
|
24df78 |
td->td_planarconfig = (uint16) v;
|
|
|
24df78 |
break;
|
|
|
24df78 |
case TIFFTAG_XPOSITION:
|
|
|
24df78 |
- td->td_xposition = TIFFClampDoubleToFloat( va_arg(ap, double) );
|
|
|
24df78 |
+ td->td_xposition = _TIFFClampDoubleToFloat( va_arg(ap, double) );
|
|
|
24df78 |
break;
|
|
|
24df78 |
case TIFFTAG_YPOSITION:
|
|
|
24df78 |
- td->td_yposition = TIFFClampDoubleToFloat( va_arg(ap, double) );
|
|
|
24df78 |
+ td->td_yposition = _TIFFClampDoubleToFloat( va_arg(ap, double) );
|
|
|
24df78 |
break;
|
|
|
24df78 |
case TIFFTAG_RESOLUTIONUNIT:
|
|
|
24df78 |
v = (uint16) va_arg(ap, uint16_vap);
|
|
|
24df78 |
@@ -686,7 +676,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
|
|
24df78 |
case TIFF_SRATIONAL:
|
|
|
24df78 |
case TIFF_FLOAT:
|
|
|
24df78 |
{
|
|
|
24df78 |
- float v2 = TIFFClampDoubleToFloat(va_arg(ap, double));
|
|
|
24df78 |
+ float v2 = _TIFFClampDoubleToFloat(va_arg(ap, double));
|
|
|
24df78 |
_TIFFmemcpy(val, &v2, tv_size);
|
|
|
24df78 |
}
|
|
|
24df78 |
break;
|
|
|
24df78 |
diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c
|
|
|
24df78 |
index 5d0a6699..03a9f296 100644
|
|
|
24df78 |
--- a/libtiff/tif_dirwrite.c
|
|
|
24df78 |
+++ b/libtiff/tif_dirwrite.c
|
|
|
24df78 |
@@ -30,7 +30,6 @@
|
|
|
24df78 |
* Directory Write Support Routines.
|
|
|
24df78 |
*/
|
|
|
24df78 |
#include "tiffiop.h"
|
|
|
24df78 |
-#include <float.h>
|
|
|
24df78 |
|
|
|
24df78 |
#ifdef HAVE_IEEEFP
|
|
|
24df78 |
#define TIFFCvtNativeToIEEEFloat(tif, n, fp)
|
|
|
24df78 |
@@ -948,15 +947,6 @@ bad:
|
|
|
24df78 |
return(0);
|
|
|
24df78 |
}
|
|
|
24df78 |
|
|
|
24df78 |
-static float TIFFClampDoubleToFloat( double val )
|
|
|
24df78 |
-{
|
|
|
24df78 |
- if( val > FLT_MAX )
|
|
|
24df78 |
- return FLT_MAX;
|
|
|
24df78 |
- if( val < -FLT_MAX )
|
|
|
24df78 |
- return -FLT_MAX;
|
|
|
24df78 |
- return (float)val;
|
|
|
24df78 |
-}
|
|
|
24df78 |
-
|
|
|
24df78 |
static int8 TIFFClampDoubleToInt8( double val )
|
|
|
24df78 |
{
|
|
|
24df78 |
if( val > 127 )
|
|
|
24df78 |
@@ -1031,7 +1021,7 @@ TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* di
|
|
|
24df78 |
if (tif->tif_dir.td_bitspersample<=32)
|
|
|
24df78 |
{
|
|
|
24df78 |
for (i = 0; i < count; ++i)
|
|
|
24df78 |
- ((float*)conv)[i] = TIFFClampDoubleToFloat(value[i]);
|
|
|
24df78 |
+ ((float*)conv)[i] = _TIFFClampDoubleToFloat(value[i]);
|
|
|
24df78 |
ok = TIFFWriteDirectoryTagFloatArray(tif,ndir,dir,tag,count,(float*)conv);
|
|
|
24df78 |
}
|
|
|
24df78 |
else
|
|
|
24df78 |
diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h
|
|
|
24df78 |
index d4b86314..05ba735b 100644
|
|
|
24df78 |
--- a/libtiff/tiffiop.h
|
|
|
24df78 |
+++ b/libtiff/tiffiop.h
|
|
|
24df78 |
@@ -377,6 +377,8 @@ extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*);
|
|
|
24df78 |
extern double _TIFFUInt64ToDouble(uint64);
|
|
|
24df78 |
extern float _TIFFUInt64ToFloat(uint64);
|
|
|
24df78 |
|
|
|
24df78 |
+extern float _TIFFClampDoubleToFloat(double);
|
|
|
24df78 |
+
|
|
|
24df78 |
extern tmsize_t
|
|
|
24df78 |
_TIFFReadEncodedStripAndAllocBuffer(TIFF* tif, uint32 strip,
|
|
|
24df78 |
void **buf, tmsize_t bufsizetoalloc,
|