Skip to content

Commit

Permalink
Merge pull request #9086 from rouault/resync_libtiff_shapelib_win32
Browse files Browse the repository at this point in the history
Internal libtiff and shapelib: resync with upstream (_WIN32 related changes)
  • Loading branch information
rouault authored Jan 25, 2024
2 parents e6601a7 + f8dcb70 commit 2083b8d
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 162 deletions.
47 changes: 0 additions & 47 deletions frmts/gtiff/libtiff/tif_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,53 +385,6 @@ int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag, ...)
return (ok);
}

struct _Int64Parts
{
int32_t low, high;
};

typedef union
{
struct _Int64Parts part;
int64_t value;
} _Int64;

float _TIFFUInt64ToFloat(uint64_t ui64)
{
_Int64 i;

i.value = ui64;
if (i.part.high >= 0)
{
return (float)i.value;
}
else
{
long double df;
df = (long double)i.value;
df += 18446744073709551616.0; /* adding 2**64 */
return (float)df;
}
}

double _TIFFUInt64ToDouble(uint64_t ui64)
{
_Int64 i;

i.value = ui64;
if (i.part.high >= 0)
{
return (double)i.value;
}
else
{
long double df;
df = (long double)i.value;
df += 18446744073709551616.0; /* adding 2**64 */
return (double)df;
}
}

float _TIFFClampDoubleToFloat(double val)
{
if (val > FLT_MAX)
Expand Down
36 changes: 0 additions & 36 deletions frmts/gtiff/libtiff/tif_dirread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,16 +1016,7 @@ TIFFReadDirEntryFloat(TIFF *tif, TIFFDirEntry *direntry, float *value)
err = TIFFReadDirEntryCheckedLong8(tif, direntry, &m);
if (err != TIFFReadDirEntryErrOk)
return (err);
#if defined(__WIN32__) && (_MSC_VER < 1500)
/*
* XXX: MSVC 6.0 does not support conversion
* of 64-bit integers into floating point
* values.
*/
*value = _TIFFUInt64ToFloat(m);
#else
*value = (float)m;
#endif
return (TIFFReadDirEntryErrOk);
}
case TIFF_SLONG8:
Expand Down Expand Up @@ -1130,16 +1121,7 @@ TIFFReadDirEntryDouble(TIFF *tif, TIFFDirEntry *direntry, double *value)
err = TIFFReadDirEntryCheckedLong8(tif, direntry, &m);
if (err != TIFFReadDirEntryErrOk)
return (err);
#if defined(__WIN32__) && (_MSC_VER < 1500)
/*
* XXX: MSVC 6.0 does not support conversion
* of 64-bit integers into floating point
* values.
*/
*value = _TIFFUInt64ToDouble(m);
#else
*value = (double)m;
#endif
return (TIFFReadDirEntryErrOk);
}
case TIFF_SLONG8:
Expand Down Expand Up @@ -2904,16 +2886,7 @@ TIFFReadDirEntryFloatArray(TIFF *tif, TIFFDirEntry *direntry, float **value)
{
if (tif->tif_flags & TIFF_SWAB)
TIFFSwabLong8(ma);
#if defined(__WIN32__) && (_MSC_VER < 1500)
/*
* XXX: MSVC 6.0 does not support
* conversion of 64-bit integers into
* floating point values.
*/
*mb++ = _TIFFUInt64ToFloat(*ma++);
#else
*mb++ = (float)(*ma++);
#endif
}
}
break;
Expand Down Expand Up @@ -3149,16 +3122,7 @@ TIFFReadDirEntryDoubleArray(TIFF *tif, TIFFDirEntry *direntry, double **value)
{
if (tif->tif_flags & TIFF_SWAB)
TIFFSwabLong8(ma);
#if defined(__WIN32__) && (_MSC_VER < 1500)
/*
* XXX: MSVC 6.0 does not support
* conversion of 64-bit integers into
* floating point values.
*/
*mb++ = _TIFFUInt64ToDouble(*ma++);
#else
*mb++ = (double)(*ma++);
#endif
}
}
break;
Expand Down
37 changes: 0 additions & 37 deletions frmts/gtiff/libtiff/tif_jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,43 +73,6 @@ int TIFFReInitJPEG_12(TIFF *tif, const JPEGOtherSettings *otherSettings,
int scheme, int is_encode);
int TIFFJPEGIsFullStripRequired_12(TIFF *tif);

/* We undefine FAR to avoid conflict with JPEG definition */

#ifdef FAR
#undef FAR
#endif

/*
Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is
not defined. Unfortunately, the MinGW and Borland compilers include
a typedef for INT32, which causes a conflict. MSVC does not include
a conflicting typedef given the headers which are included.
*/
#if defined(__BORLANDC__) || defined(__MINGW32__)
#define XMD_H 1
#endif

/*
The windows RPCNDR.H file defines boolean, but defines it with the
unsigned char size. You should compile JPEG library using appropriate
definitions in jconfig.h header, but many users compile library in wrong
way. That causes errors of the following type:
"JPEGLib: JPEG parameter struct mismatch: library thinks size is 432,
caller expects 464"
For such users we will fix the problem here. See install.doc file from
the JPEG library distribution for details.
*/

/* Define "boolean" as unsigned char, not int, per Windows custom. */
#if defined(__WIN32__) && !defined(__MINGW32__)
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif

#include "jerror.h"
#include "jpeglib.h"

Expand Down
24 changes: 0 additions & 24 deletions frmts/gtiff/libtiff/tif_ojpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,6 @@ static const TIFFField ojpegFields[] = {
#include <setjmp.h>
#endif

/* We undefine FAR to avoid conflict with JPEG definition */

#ifdef FAR
#undef FAR
#endif

/*
Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is
not defined. Unfortunately, the MinGW and Borland compilers include
a typedef for INT32, which causes a conflict. MSVC does not include
a conflicting typedef given the headers which are included.
*/
#if defined(__BORLANDC__) || defined(__MINGW32__)
#define XMD_H 1
#endif

/* Define "boolean" as unsigned char, not int, per Windows custom. */
#if defined(__WIN32__) && !defined(__MINGW32__)
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif

#include "jerror.h"
#include "jpeglib.h"

Expand Down
14 changes: 5 additions & 9 deletions frmts/gtiff/libtiff/tiffio.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,14 @@ typedef tstrile_t ttile_t; /* tile number */
typedef tmsize_t tsize_t; /* i/o size in bytes */
typedef void *tdata_t; /* image data ref */

#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32))
#define __WIN32__
#endif

/*
* On windows you should define USE_WIN32_FILEIO if you are using tif_win32.c
* or AVOID_WIN32_FILEIO if you are using something else (like tif_unix.c).
*
* By default tif_unix.c is assumed.
*/

#if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows)
#if defined(_WIN32)
#if !defined(__CYGWIN) && !defined(AVOID_WIN32_FILEIO) && \
!defined(USE_WIN32_FILEIO)
#define AVOID_WIN32_FILEIO
Expand All @@ -98,11 +94,11 @@ typedef void *tdata_t; /* image data ref */
#if defined(USE_WIN32_FILEIO)
#define VC_EXTRALEAN
#include <windows.h>
#ifdef __WIN32__
#ifdef _WIN32
DECLARE_HANDLE(thandle_t); /* Win32 file handle */
#else
typedef HFILE thandle_t; /* client data handle */
#endif /* __WIN32__ */
#endif /* _WIN32 */
#else
typedef void *thandle_t; /* client data handle */
#endif /* USE_WIN32_FILEIO */
Expand Down Expand Up @@ -522,11 +518,11 @@ extern int TIFFReadRGBAImageOriented(TIFF *, uint32_t, uint32_t, uint32_t *,

extern TIFF *TIFFOpen(const char *, const char *);
extern TIFF *TIFFOpenExt(const char *, const char *, TIFFOpenOptions *opts);
#ifdef __WIN32__
#ifdef _WIN32
extern TIFF *TIFFOpenW(const wchar_t *, const char *);
extern TIFF *TIFFOpenWExt(const wchar_t *, const char *,
TIFFOpenOptions *opts);
#endif /* __WIN32__ */
#endif /* _WIN32 */
extern TIFF *TIFFFdOpen(int, const char *, const char *);
extern TIFF *TIFFFdOpenExt(int, const char *, const char *,
TIFFOpenOptions *opts);
Expand Down
5 changes: 1 addition & 4 deletions frmts/gtiff/libtiff/tiffiop.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ struct TIFFOpenOptions
#define ftell(stream, offset, whence) ftello(stream, offset, whence)
#endif
#endif
#if defined(__WIN32__) && !(defined(_MSC_VER) && _MSC_VER < 1400) && \
#if defined(_WIN32) && \
!(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800)
typedef unsigned int TIFFIOSize_t;
#define _TIFF_lseek_f(fildes, offset, whence) \
Expand Down Expand Up @@ -440,9 +440,6 @@ extern "C"
extern void *_TIFFCheckRealloc(TIFF *, void *, tmsize_t, tmsize_t,
const char *);

extern double _TIFFUInt64ToDouble(uint64_t);
extern float _TIFFUInt64ToFloat(uint64_t);

extern float _TIFFClampDoubleToFloat(double);
extern uint32_t _TIFFClampDoubleToUInt32(double);

Expand Down
4 changes: 2 additions & 2 deletions ogr/ogrsf_frmts/shape/dbfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#if defined(_MSC_VER)
#define STRCASECMP(a, b) (_stricmp(a, b))
#elif defined(_WIN32) || defined(_WIN32)
#elif defined(_WIN32)
#define STRCASECMP(a, b) (stricmp(a, b))
#else
#include <strings.h>
Expand All @@ -37,7 +37,7 @@
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#elif defined(_WIN32) || defined(_WIN32)
#elif defined(_WIN32)
#ifndef snprintf
#define snprintf _snprintf
#endif
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/shape/sbnsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#elif defined(WIN32) || defined(_WIN32)
#elif defined(_WIN32)
#ifndef snprintf
#define snprintf _snprintf
#endif
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/shape/shapefil.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extern "C"
/* On some platforms, additional file IO hooks are defined that */
/* UTF-8 encoded filenames Unicode filenames */
/* -------------------------------------------------------------------- */
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
#if defined(_WIN32)
#define SHPAPI_WINDOWS
#define SHPAPI_UTF8_HOOKS
#endif
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/shape/shpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#elif defined(WIN32) || defined(_WIN32)
#elif defined(_WIN32)
#ifndef snprintf
#define snprintf _snprintf
#endif
Expand Down

0 comments on commit 2083b8d

Please sign in to comment.