move _TIFFClampDoubleToFloat() to tif_aux.c
the same function was declared in tif_dir.c and tif_dirwrite.c see http://bugzilla.maptools.org/show_bug.cgi?id=2842
This commit is contained in:
parent
ae0bed1fe5
commit
8420a31e8c
@ -30,6 +30,7 @@
|
||||
#include "tiffiop.h"
|
||||
#include "tif_predict.h"
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
uint32
|
||||
_TIFFMultiply32(TIFF* tif, uint32 first, uint32 second, const char* where)
|
||||
@ -357,6 +358,15 @@ _TIFFUInt64ToDouble(uint64 ui64)
|
||||
}
|
||||
}
|
||||
|
||||
float _TIFFClampDoubleToFloat( double val )
|
||||
{
|
||||
if( val > FLT_MAX )
|
||||
return FLT_MAX;
|
||||
if( val < -FLT_MAX )
|
||||
return -FLT_MAX;
|
||||
return (float)val;
|
||||
}
|
||||
|
||||
int _TIFFSeekOK(TIFF* tif, toff_t off)
|
||||
{
|
||||
/* Huge offsets, especially -1 / UINT64_MAX, can cause issues */
|
||||
|
@ -29,7 +29,6 @@
|
||||
* (and also some miscellaneous stuff)
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
#include <float.h>
|
||||
|
||||
/*
|
||||
* These are used in the backwards compatibility code...
|
||||
@ -167,15 +166,6 @@ bad:
|
||||
return (0);
|
||||
}
|
||||
|
||||
static float TIFFClampDoubleToFloat( double val )
|
||||
{
|
||||
if( val > FLT_MAX )
|
||||
return FLT_MAX;
|
||||
if( val < -FLT_MAX )
|
||||
return -FLT_MAX;
|
||||
return (float)val;
|
||||
}
|
||||
|
||||
static int
|
||||
_TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
||||
{
|
||||
@ -346,13 +336,13 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
||||
dblval = va_arg(ap, double);
|
||||
if( dblval < 0 )
|
||||
goto badvaluedouble;
|
||||
td->td_xresolution = TIFFClampDoubleToFloat( dblval );
|
||||
td->td_xresolution = _TIFFClampDoubleToFloat( dblval );
|
||||
break;
|
||||
case TIFFTAG_YRESOLUTION:
|
||||
dblval = va_arg(ap, double);
|
||||
if( dblval < 0 )
|
||||
goto badvaluedouble;
|
||||
td->td_yresolution = TIFFClampDoubleToFloat( dblval );
|
||||
td->td_yresolution = _TIFFClampDoubleToFloat( dblval );
|
||||
break;
|
||||
case TIFFTAG_PLANARCONFIG:
|
||||
v = (uint16) va_arg(ap, uint16_vap);
|
||||
@ -361,10 +351,10 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
||||
td->td_planarconfig = (uint16) v;
|
||||
break;
|
||||
case TIFFTAG_XPOSITION:
|
||||
td->td_xposition = TIFFClampDoubleToFloat( va_arg(ap, double) );
|
||||
td->td_xposition = _TIFFClampDoubleToFloat( va_arg(ap, double) );
|
||||
break;
|
||||
case TIFFTAG_YPOSITION:
|
||||
td->td_yposition = TIFFClampDoubleToFloat( va_arg(ap, double) );
|
||||
td->td_yposition = _TIFFClampDoubleToFloat( va_arg(ap, double) );
|
||||
break;
|
||||
case TIFFTAG_RESOLUTIONUNIT:
|
||||
v = (uint16) va_arg(ap, uint16_vap);
|
||||
@ -710,7 +700,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|
||||
case TIFF_SRATIONAL:
|
||||
case TIFF_FLOAT:
|
||||
{
|
||||
float v2 = TIFFClampDoubleToFloat(va_arg(ap, double));
|
||||
float v2 = _TIFFClampDoubleToFloat(va_arg(ap, double));
|
||||
_TIFFmemcpy(val, &v2, tv_size);
|
||||
}
|
||||
break;
|
||||
|
@ -28,7 +28,6 @@
|
||||
* Directory Write Support Routines.
|
||||
*/
|
||||
#include "tiffiop.h"
|
||||
#include <float.h>
|
||||
|
||||
#ifdef HAVE_IEEEFP
|
||||
#define TIFFCvtNativeToIEEEFloat(tif, n, fp)
|
||||
@ -946,15 +945,6 @@ bad:
|
||||
return(0);
|
||||
}
|
||||
|
||||
static float TIFFClampDoubleToFloat( double val )
|
||||
{
|
||||
if( val > FLT_MAX )
|
||||
return FLT_MAX;
|
||||
if( val < -FLT_MAX )
|
||||
return -FLT_MAX;
|
||||
return (float)val;
|
||||
}
|
||||
|
||||
static int8 TIFFClampDoubleToInt8( double val )
|
||||
{
|
||||
if( val > 127 )
|
||||
@ -1029,7 +1019,7 @@ TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* di
|
||||
if (tif->tif_dir.td_bitspersample<=32)
|
||||
{
|
||||
for (i = 0; i < count; ++i)
|
||||
((float*)conv)[i] = TIFFClampDoubleToFloat(value[i]);
|
||||
((float*)conv)[i] = _TIFFClampDoubleToFloat(value[i]);
|
||||
ok = TIFFWriteDirectoryTagFloatArray(tif,ndir,dir,tag,count,(float*)conv);
|
||||
}
|
||||
else
|
||||
|
@ -374,6 +374,8 @@ extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*);
|
||||
extern double _TIFFUInt64ToDouble(uint64);
|
||||
extern float _TIFFUInt64ToFloat(uint64);
|
||||
|
||||
extern float _TIFFClampDoubleToFloat(double);
|
||||
|
||||
extern tmsize_t
|
||||
_TIFFReadEncodedStripAndAllocBuffer(TIFF* tif, uint32 strip,
|
||||
void **buf, tmsize_t bufsizetoalloc,
|
||||
|
Loading…
Reference in New Issue
Block a user