1diff a/third_party/libtiff/tiffiop.h b/third_party/libtiff/tiffiop.h
2--- a/third_party/libtiff/tiffiop.h
3+++ b/third_party/libtiff/tiffiop.h
4@@ -30,7 +30,7 @@
5  * ``Library-private'' definitions.
6  */
7
8-#include "tif_config.h"
9+#include "tiffconf.h"
10
11 #ifdef HAVE_FCNTL_H
12 # include <fcntl.h>
13@@ -59,8 +59,7 @@
14
15 #if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF)
16 #undef snprintf
17-#define snprintf _TIFF_snprintf_f
18-extern int snprintf(char* str, size_t size, const char* format, ...);
19+#define snprintf FXSYS_snprintf
20 #endif
21
22 #include "tiffio.h"
23diff a/third_party/libtiff/tif_jpeg.c b/third_party/libtiff/tif_jpeg.c
24--- a/third_party/libtiff/tif_jpeg.c
25+++ b/third_party/libtiff/tif_jpeg.c
26@@ -85,8 +85,16 @@
27 # define HAVE_BOOLEAN            /* prevent jmorecfg.h from redefining it */
28 #endif
29
30-#include "jpeglib.h"
31-#include "jerror.h"
32+#if defined(USE_SYSTEM_LIBJPEG)
33+#include <jerror.h>
34+#include <jpeglib.h>
35+#elif defined(USE_LIBJPEG_TURBO)
36+#include "third_party/libjpeg_turbo/jerror.h"
37+#include "third_party/libjpeg_turbo/jpeglib.h"
38+#else
39+#include "third_party/libjpeg/jerror.h"
40+#include "third_party/libjpeg/jpeglib.h"
41+#endif
42
43 /*
44  * Do we want to do special processing suitable for when JSAMPLE is a
45diff a/third_party/libtiff/tif_ojpeg.c b/third_party/libtiff/tif_ojpeg.c
46--- a/third_party/libtiff/tif_ojpeg.c
47+++ b/third_party/libtiff/tif_ojpeg.c
48@@ -214,8 +214,17 @@
49 # define HAVE_BOOLEAN            /* prevent jmorecfg.h from redefining it */
50 #endif
51
52-#include "jpeglib.h"
53-#include "jerror.h"
54+#if defined(USE_SYSTEM_LIBJPEG)
55+#include <jerror.h>
56+#include <jpeglib.h>
57+#elif defined(USE_LIBJPEG_TURBO)
58+#include "third_party/libjpeg_turbo/jerror.h"
59+#include "third_party/libjpeg_turbo/jpeglib.h"
60+#else
61+#include "third_party/libjpeg/jerror.h"
62+#include "third_party/libjpeg/jpeglib.h"
63+#endif
64+
65
66 typedef struct jpeg_error_mgr jpeg_error_mgr;
67 typedef struct jpeg_common_struct jpeg_common_struct;
68diff a/third_party/libtiff/tiffconf.h b/third_party/libtiff/tiffconf.h
69--- /dev/null
70+++ b/third_party/libtiff/tiffconf.h
71@@ -0,0 +1,240 @@
72+/* libtiff/tiffconf.h.  Generated by configure.  */
73+/*
74+  Configuration defines for installed libtiff.
75+  This file maintained for backward compatibility. Do not use definitions
76+  from this file in your programs.
77+*/
78+#ifndef _TIFFCONF_
79+#define _TIFFCONF_
80+
81+#include "build/build_config.h"
82+#include "core/fxcrt/fx_system.h"
83+
84+//NOTE: The tiff codec requires an ANSI C compiler environment for building and
85+//    presumes an ANSI C environment for use.
86+
87+# define HAVE_SYS_TYPES_H 1
88+# define HAVE_FCNTL_H 1
89+
90+/* Compatibility stuff. */
91+
92+/* Define to 1 if you have the <assert.h> header file. */
93+#define HAVE_ASSERT_H 1
94+
95+/* Define as 0 or 1 according to the floating point format suported by the
96+   machine */
97+#define HAVE_IEEEFP 1
98+
99+/* Define to 1 if you have the <string.h> header file. */
100+//#define HAVE_STRING_H 1
101+//fx_system.h already include the string.h in ANSIC
102+
103+/* Define to 1 if you have the <search.h> header file. */
104+#if defined(OS_WIN)
105+// search.h is always available in VS 2015 and above, and may be
106+// available in earlier versions.
107+#define HAVE_SEARCH_H 1
108+#endif
109+
110+static const size_t sizeOfInt = sizeof(int);
111+/* The size of a `int', as computed by sizeof. */
112+#define SIZEOF_INT sizeOfInt
113+
114+static const size_t sizeOfULong = sizeof(unsigned long);
115+/* The size of `unsigned long', as computed by sizeof. */
116+#define SIZEOF_UNSIGNED_LONG sizeOfULong
117+
118+static const size_t sizeOfVoidP = sizeof(void*);
119+/* The size of void* as computed by sizeof. */
120+#define SIZEOF_VOIDP sizeOfVoidP
121+
122+/* Signed 8-bit type */
123+#define TIFF_INT8_T signed char
124+
125+/* Unsigned 8-bit type */
126+#define TIFF_UINT8_T unsigned char
127+
128+/* Signed 16-bit type */
129+#define TIFF_INT16_T signed short
130+
131+/* Unsigned 16-bit type */
132+#define TIFF_UINT16_T unsigned short
133+
134+/* Signed 32-bit type */
135+#define TIFF_INT32_T signed int
136+
137+/* Unsigned 32-bit type */
138+#define TIFF_UINT32_T unsigned int
139+
140+/* Signed 32-bit type formatter */
141+#define TIFF_INT32_FORMAT "%d"
142+
143+/* Unsigned 32-bit type formatter */
144+#define TIFF_UINT32_FORMAT "%u"
145+
146+#ifdef _MSC_VER   // windows
147+
148+/* Signed 64-bit type formatter */
149+#define TIFF_INT64_FORMAT "%I64d"
150+
151+/* Unsigned 64-bit type formatter */
152+#define TIFF_UINT64_FORMAT "%I64u"
153+
154+/* Signed 64-bit type */
155+#define TIFF_INT64_T signed __int64
156+
157+/* Unsigned 64-bit type */
158+#define TIFF_UINT64_T unsigned __int64
159+
160+#else           // linux/unix
161+
162+#if 0 //_FX_CPU_ == _FX_X64_  // linux/unix 64
163+
164+/* Signed 64-bit type formatter */
165+#define TIFF_INT64_FORMAT "%ld"
166+
167+/* Unsigned 64-bit type formatter */
168+#define TIFF_UINT64_FORMAT "%lu"
169+
170+/* Signed 64-bit type */
171+#define TIFF_INT64_T signed long
172+
173+#else           // linux/unix 32
174+
175+/* Signed 64-bit type formatter */
176+#define TIFF_INT64_FORMAT "%lld"
177+
178+/* Unsigned 64-bit type formatter */
179+#define TIFF_UINT64_FORMAT "%llu"
180+
181+/* Signed 64-bit type */
182+#define TIFF_INT64_T signed long long
183+
184+#endif            // end _FX_CPU_
185+
186+/* Unsigned 64-bit type */
187+#define TIFF_UINT64_T unsigned long long
188+
189+#endif
190+
191+
192+/* Signed size type */
193+#ifdef _MSC_VER
194+
195+#if defined(_WIN64)
196+#define TIFF_SSIZE_T signed __int64
197+#else
198+#define TIFF_SSIZE_T signed int
199+#endif
200+
201+#else
202+
203+#define TIFF_SSIZE_T signed long
204+
205+#endif
206+
207+/* Signed size type formatter */
208+#if defined(_WIN64)
209+#define TIFF_SSIZE_FORMAT "%I64d"
210+#else
211+#define TIFF_SSIZE_FORMAT "%ld"
212+#endif
213+
214+/* Pointer difference type */
215+#ifdef _MSC_VER
216+#define TIFF_PTRDIFF_T long
217+#else
218+#define TIFF_PTRDIFF_T ptrdiff_t
219+#endif
220+
221+/* Signed 64-bit type */
222+/*#define TIFF_INT64_T signed __int64*/
223+
224+/* Unsigned 64-bit type */
225+/*#define TIFF_UINT64_T unsigned __int64*/
226+
227+/* Define to `__inline__' or `__inline' if that's what the C compiler
228+   calls it, or to nothing if 'inline' is not supported under any name.  */
229+#ifndef __cplusplus
230+# ifndef inline
231+#  define inline __inline
232+# endif
233+#endif
234+
235+#define lfind _lfind
236+
237+#define BSDTYPES
238+
239+/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
240+#define HOST_FILLORDER FILLORDER_LSB2MSB
241+
242+/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian
243+   (Intel) */
244+#if _FX_ENDIAN_ == _FX_BIG_ENDIAN_
245+# define HOST_BIGENDIAN 1
246+#else
247+# define HOST_BIGENDIAN 0
248+#endif
249+
250+/* Support CCITT Group 3 & 4 algorithms */
251+#define CCITT_SUPPORT 1
252+
253+/* Support JPEG compression (requires IJG JPEG library) */
254+#define JPEG_SUPPORT 1
255+
256+/* Support LogLuv high dynamic range encoding */
257+#define LOGLUV_SUPPORT 1
258+
259+/* Support LZW algorithm */
260+#define LZW_SUPPORT 1
261+
262+/* Support NeXT 2-bit RLE algorithm */
263+#define NEXT_SUPPORT 1
264+
265+/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation
266+   fails with unpatched IJG JPEG library) */
267+/* #undef OJPEG_SUPPORT */
268+
269+/* Support Macintosh PackBits algorithm */
270+#define PACKBITS_SUPPORT 1
271+
272+/* Support Pixar log-format algorithm (requires Zlib) */
273+#define PIXARLOG_SUPPORT 1
274+
275+/* Support ThunderScan 4-bit RLE algorithm */
276+#define THUNDER_SUPPORT 1
277+
278+/* Support Deflate compression */
279+/* #undef ZIP_SUPPORT */
280+
281+/* Support strip chopping (whether or not to convert single-strip uncompressed
282+   images to mutiple strips of ~8Kb to reduce memory usage) */
283+#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP
284+
285+/* Enable SubIFD tag (330) support */
286+#define SUBIFD_SUPPORT 1
287+
288+/* Treat extra sample as alpha (default enabled). The RGBA interface will
289+   treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many
290+   packages produce RGBA files but don't mark the alpha properly. */
291+#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1
292+
293+/* Pick up YCbCr subsampling info from the JPEG data stream to support files
294+   lacking the tag (default enabled). */
295+#define CHECK_JPEG_YCBCR_SUBSAMPLING 1
296+
297+/* Support MS MDI magic number files as TIFF */
298+#define MDI_SUPPORT 1
299+
300+/*
301+ * Feature support definitions.
302+ * XXX: These macros are obsoleted. Don't use them in your apps!
303+ * Macros stays here for backward compatibility and should be always defined.
304+ */
305+#define COLORIMETRY_SUPPORT
306+#define YCBCR_SUPPORT
307+#define CMYK_SUPPORT
308+#define ICC_SUPPORT
309+#define PHOTOSHOP_SUPPORT
310+#define IPTC_SUPPORT
311+
312+#endif /* _TIFFCONF_ */
313