tiffiop.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. * Copyright (c) 1988-1997 Sam Leffler
  3. * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and
  6. * its documentation for any purpose is hereby granted without fee, provided
  7. * that (i) the above copyright notices and this permission notice appear in
  8. * all copies of the software and related documentation, and (ii) the names of
  9. * Sam Leffler and Silicon Graphics may not be used in any advertising or
  10. * publicity relating to the software without the specific, prior written
  11. * permission of Sam Leffler and Silicon Graphics.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  18. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. #ifndef _TIFFIOP_
  25. #define _TIFFIOP_
  26. /*
  27. * ``Library-private'' definitions.
  28. */
  29. #include "tif_config.h"
  30. #ifdef HAVE_FCNTL_H
  31. #include <fcntl.h>
  32. #endif
  33. #ifdef HAVE_SYS_TYPES_H
  34. #include <sys/types.h>
  35. #endif
  36. #include <string.h>
  37. #ifdef HAVE_ASSERT_H
  38. #include <assert.h>
  39. #else
  40. #define assert(x)
  41. #endif
  42. #include "tif_hash_set.h"
  43. #include "tiffio.h"
  44. #include "tif_dir.h"
  45. #include <limits.h>
  46. #ifndef STRIP_SIZE_DEFAULT
  47. #define STRIP_SIZE_DEFAULT 8192
  48. #endif
  49. #ifndef TIFF_MAX_DIR_COUNT
  50. #define TIFF_MAX_DIR_COUNT 1048576
  51. #endif
  52. #define TIFF_NON_EXISTENT_DIR_NUMBER UINT_MAX
  53. #define streq(a, b) (strcmp(a, b) == 0)
  54. #define strneq(a, b, n) (strncmp(a, b, n) == 0)
  55. #ifndef TRUE
  56. #define TRUE 1
  57. #define FALSE 0
  58. #endif
  59. typedef struct client_info
  60. {
  61. struct client_info *next;
  62. void *data;
  63. char *name;
  64. } TIFFClientInfoLink;
  65. /*
  66. * Typedefs for ``method pointers'' used internally.
  67. * these are deprecated and provided only for backwards compatibility.
  68. */
  69. typedef unsigned char tidataval_t; /* internal image data value type */
  70. typedef tidataval_t *tidata_t; /* reference to internal image data */
  71. typedef void (*TIFFVoidMethod)(TIFF *);
  72. typedef int (*TIFFBoolMethod)(TIFF *);
  73. typedef int (*TIFFPreMethod)(TIFF *, uint16_t);
  74. typedef int (*TIFFCodeMethod)(TIFF *tif, uint8_t *buf, tmsize_t size,
  75. uint16_t sample);
  76. typedef int (*TIFFSeekMethod)(TIFF *, uint32_t);
  77. typedef void (*TIFFPostMethod)(TIFF *tif, uint8_t *buf, tmsize_t size);
  78. typedef uint32_t (*TIFFStripMethod)(TIFF *, uint32_t);
  79. typedef void (*TIFFTileMethod)(TIFF *, uint32_t *, uint32_t *);
  80. struct TIFFOffsetAndDirNumber
  81. {
  82. uint64_t offset;
  83. tdir_t dirNumber;
  84. };
  85. typedef struct TIFFOffsetAndDirNumber TIFFOffsetAndDirNumber;
  86. typedef union
  87. {
  88. TIFFHeaderCommon common;
  89. TIFFHeaderClassic classic;
  90. TIFFHeaderBig big;
  91. } TIFFHeaderUnion;
  92. struct tiff
  93. {
  94. char *tif_name; /* name of open file */
  95. int tif_fd; /* open file descriptor */
  96. int tif_mode; /* open mode (O_*) */
  97. uint32_t tif_flags;
  98. #define TIFF_FILLORDER 0x00003U /* natural bit fill order for machine */
  99. #define TIFF_DIRTYHEADER 0x00004U /* header must be written on close */
  100. #define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */
  101. #define TIFF_BUFFERSETUP 0x00010U /* data buffers setup */
  102. #define TIFF_CODERSETUP 0x00020U /* encoder/decoder setup done */
  103. #define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
  104. #define TIFF_SWAB 0x00080U /* byte swap file information */
  105. #define TIFF_NOBITREV 0x00100U /* inhibit bit reversal logic */
  106. #define TIFF_MYBUFFER 0x00200U /* my raw data buffer; free on close */
  107. #define TIFF_ISTILED 0x00400U /* file is tile, not strip- based */
  108. #define TIFF_MAPPED 0x00800U /* file is mapped into memory */
  109. #define TIFF_POSTENCODE 0x01000U /* need call to postencode routine */
  110. #define TIFF_INSUBIFD 0x02000U /* currently writing a subifd */
  111. #define TIFF_UPSAMPLED 0x04000U /* library is doing data up-sampling */
  112. #define TIFF_STRIPCHOP 0x08000U /* enable strip chopping support */
  113. #define TIFF_HEADERONLY \
  114. 0x10000U /* read header only, do not process the first directory */
  115. #define TIFF_NOREADRAW \
  116. 0x20000U /* skip reading of raw uncompressed image data */
  117. #define TIFF_INCUSTOMIFD 0x40000U /* currently writing a custom IFD */
  118. #define TIFF_BIGTIFF 0x80000U /* read/write bigtiff */
  119. #define TIFF_BUF4WRITE 0x100000U /* rawcc bytes are for writing */
  120. #define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
  121. #define TIFF_PERSAMPLE 0x400000U /* get/set per sample tags as arrays */
  122. #define TIFF_BUFFERMMAP \
  123. 0x800000U /* read buffer (tif_rawdata) points into mmap() memory */
  124. #define TIFF_DEFERSTRILELOAD \
  125. 0x1000000U /* defer strip/tile offset/bytecount array loading. */
  126. #define TIFF_LAZYSTRILELOAD \
  127. 0x2000000U /* lazy/ondemand loading of strip/tile offset/bytecount values. \
  128. Only used if TIFF_DEFERSTRILELOAD is set and in read-only \
  129. mode */
  130. #define TIFF_CHOPPEDUPARRAYS \
  131. 0x4000000U /* set when allocChoppedUpStripArrays() has modified strip \
  132. array */
  133. uint64_t tif_diroff; /* file offset of current directory */
  134. uint64_t tif_nextdiroff; /* file offset of following directory */
  135. uint64_t tif_lastdiroff; /* file offset of last directory written so far */
  136. TIFFHashSet *tif_map_dir_offset_to_number;
  137. TIFFHashSet *tif_map_dir_number_to_offset;
  138. int tif_setdirectory_force_absolute; /* switch between relative and absolute
  139. stepping in TIFFSetDirectory() */
  140. TIFFDirectory tif_dir; /* internal rep of current directory */
  141. TIFFDirectory
  142. tif_customdir; /* custom IFDs are separated from the main ones */
  143. TIFFHeaderUnion tif_header; /* file's header block Classic/BigTIFF union */
  144. uint16_t tif_header_size; /* file's header block and its length */
  145. uint32_t tif_row; /* current scanline */
  146. /* There are IFDs in the file and an "active" IFD in memory,
  147. * from which fields are "set" and "get".
  148. * tif_curdir is set to:
  149. * a) TIFF_NON_EXISTENT_DIR_NUMBER if there is no IFD in the file
  150. * or the state is unknown,
  151. * or the last read (i.e. TIFFFetchDirectory()) failed,
  152. * or a custom directory was written.
  153. * b) IFD index of last IFD written in the file. In this case the
  154. * active IFD is a new (empty) one and tif_diroff is zero.
  155. * If writing fails, tif_curdir is not changed.
  156. * c) IFD index of IFD read from file into memory (=active IFD),
  157. * even if IFD is corrupt and TIFFReadDirectory() returns 0.
  158. * Then tif_diroff contains the offset of the IFD in the file.
  159. * d) IFD index 0, whenever a custom directory or an unchained SubIFD
  160. * was read. */
  161. tdir_t tif_curdir; /* current directory (index) */
  162. /* tif_curdircount: number of directories (main-IFDs) in file:
  163. * - TIFF_NON_EXISTENT_DIR_NUMBER means 'dont know number of IFDs'.
  164. * - 0 means 'empty file opened for writing, but no IFD written yet' */
  165. tdir_t tif_curdircount;
  166. uint32_t tif_curstrip; /* current strip for read/write */
  167. uint64_t tif_curoff; /* current offset for read/write */
  168. uint64_t tif_lastvalidoff; /* last valid offset allowed for rewrite in
  169. place. Used only by TIFFAppendToStrip() */
  170. uint64_t tif_dataoff; /* current offset for writing dir (IFD) */
  171. /* SubIFD support */
  172. uint16_t tif_nsubifd; /* remaining subifds to write */
  173. uint64_t tif_subifdoff; /* offset for patching SubIFD link */
  174. /* tiling support */
  175. uint32_t tif_col; /* current column (offset by row too) */
  176. uint32_t tif_curtile; /* current tile for read/write */
  177. tmsize_t tif_tilesize; /* # of bytes in a tile */
  178. /* compression scheme hooks */
  179. int tif_decodestatus;
  180. TIFFBoolMethod tif_fixuptags; /* called in TIFFReadDirectory */
  181. TIFFBoolMethod tif_setupdecode; /* called once before predecode */
  182. TIFFPreMethod tif_predecode; /* pre- row/strip/tile decoding */
  183. TIFFBoolMethod tif_setupencode; /* called once before preencode */
  184. int tif_encodestatus;
  185. TIFFPreMethod tif_preencode; /* pre- row/strip/tile encoding */
  186. TIFFBoolMethod tif_postencode; /* post- row/strip/tile encoding */
  187. TIFFCodeMethod tif_decoderow; /* scanline decoding routine */
  188. TIFFCodeMethod tif_encoderow; /* scanline encoding routine */
  189. TIFFCodeMethod tif_decodestrip; /* strip decoding routine */
  190. TIFFCodeMethod tif_encodestrip; /* strip encoding routine */
  191. TIFFCodeMethod tif_decodetile; /* tile decoding routine */
  192. TIFFCodeMethod tif_encodetile; /* tile encoding routine */
  193. TIFFVoidMethod tif_close; /* cleanup-on-close routine */
  194. TIFFSeekMethod tif_seek; /* position within a strip routine */
  195. TIFFVoidMethod tif_cleanup; /* cleanup state routine */
  196. TIFFStripMethod tif_defstripsize; /* calculate/constrain strip size */
  197. TIFFTileMethod tif_deftilesize; /* calculate/constrain tile size */
  198. uint8_t *tif_data; /* compression scheme private data */
  199. /* input/output buffering */
  200. tmsize_t tif_scanlinesize; /* # of bytes in a scanline */
  201. tmsize_t tif_scanlineskew; /* scanline skew for reading strips */
  202. uint8_t *tif_rawdata; /* raw data buffer */
  203. tmsize_t tif_rawdatasize; /* # of bytes in raw data buffer */
  204. tmsize_t tif_rawdataoff; /* rawdata offset within strip */
  205. tmsize_t tif_rawdataloaded; /* amount of data in rawdata */
  206. uint8_t *tif_rawcp; /* current spot in raw buffer */
  207. tmsize_t tif_rawcc; /* bytes unread from raw buffer */
  208. /* memory-mapped file support */
  209. uint8_t *tif_base; /* base of mapped file */
  210. tmsize_t tif_size; /* size of mapped file region (bytes, thus tmsize_t) */
  211. TIFFMapFileProc tif_mapproc; /* map file method */
  212. TIFFUnmapFileProc tif_unmapproc; /* unmap file method */
  213. /* input/output callback methods */
  214. thandle_t tif_clientdata; /* callback parameter */
  215. TIFFReadWriteProc tif_readproc; /* read method */
  216. TIFFReadWriteProc tif_writeproc; /* write method */
  217. TIFFSeekProc tif_seekproc; /* lseek method */
  218. TIFFCloseProc tif_closeproc; /* close method */
  219. TIFFSizeProc tif_sizeproc; /* filesize method */
  220. /* post-decoding support */
  221. TIFFPostMethod tif_postdecode; /* post decoding routine */
  222. /* tag support */
  223. TIFFField **tif_fields; /* sorted table of registered tags */
  224. size_t tif_nfields; /* # entries in registered tag table */
  225. const TIFFField *tif_foundfield; /* cached pointer to already found tag */
  226. TIFFTagMethods tif_tagmethods; /* tag get/set/print routines */
  227. TIFFClientInfoLink *tif_clientinfo; /* extra client information. */
  228. /* Backward compatibility stuff. We need these two fields for
  229. * setting up an old tag extension scheme. */
  230. TIFFFieldArray *tif_fieldscompat;
  231. size_t tif_nfieldscompat;
  232. /* Error handler support */
  233. TIFFErrorHandlerExtR tif_errorhandler;
  234. void *tif_errorhandler_user_data;
  235. TIFFErrorHandlerExtR tif_warnhandler;
  236. void *tif_warnhandler_user_data;
  237. tmsize_t tif_max_single_mem_alloc; /* in bytes. 0 for unlimited */
  238. tmsize_t tif_max_cumulated_mem_alloc; /* in bytes. 0 for unlimited */
  239. tmsize_t tif_cur_cumulated_mem_alloc; /* in bytes */
  240. };
  241. struct TIFFOpenOptions
  242. {
  243. TIFFErrorHandlerExtR errorhandler; /* may be NULL */
  244. void *errorhandler_user_data; /* may be NULL */
  245. TIFFErrorHandlerExtR warnhandler; /* may be NULL */
  246. void *warnhandler_user_data; /* may be NULL */
  247. tmsize_t max_single_mem_alloc; /* in bytes. 0 for unlimited */
  248. tmsize_t max_cumulated_mem_alloc; /* in bytes. 0 for unlimited */
  249. };
  250. #define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
  251. #define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  252. #define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0)
  253. #define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0)
  254. #define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
  255. #define TIFFReadFile(tif, buf, size) \
  256. ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
  257. #define TIFFWriteFile(tif, buf, size) \
  258. ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
  259. #define TIFFSeekFile(tif, off, whence) \
  260. ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
  261. #define TIFFCloseFile(tif) ((*(tif)->tif_closeproc)((tif)->tif_clientdata))
  262. #define TIFFGetFileSize(tif) ((*(tif)->tif_sizeproc)((tif)->tif_clientdata))
  263. #define TIFFMapFileContents(tif, paddr, psize) \
  264. ((*(tif)->tif_mapproc)((tif)->tif_clientdata, (paddr), (psize)))
  265. #define TIFFUnmapFileContents(tif, addr, size) \
  266. ((*(tif)->tif_unmapproc)((tif)->tif_clientdata, (addr), (size)))
  267. /*
  268. * Default Read/Seek/Write definitions.
  269. */
  270. #ifndef ReadOK
  271. #define ReadOK(tif, buf, size) (TIFFReadFile((tif), (buf), (size)) == (size))
  272. #endif
  273. #ifndef SeekOK
  274. #define SeekOK(tif, off) _TIFFSeekOK(tif, off)
  275. #endif
  276. #ifndef WriteOK
  277. #define WriteOK(tif, buf, size) (TIFFWriteFile((tif), (buf), (size)) == (size))
  278. #endif
  279. /* NB: the uint32_t casts are to silence certain ANSI-C compilers */
  280. #define TIFFhowmany_32(x, y) \
  281. (((uint32_t)x < (0xffffffff - (uint32_t)(y - 1))) \
  282. ? ((((uint32_t)(x)) + (((uint32_t)(y)) - 1)) / ((uint32_t)(y))) \
  283. : 0U)
  284. /* Variant of TIFFhowmany_32() that doesn't return 0 if x close to MAXUINT. */
  285. /* Caution: TIFFhowmany_32_maxuint_compat(x,y)*y might overflow */
  286. #define TIFFhowmany_32_maxuint_compat(x, y) \
  287. (((uint32_t)(x) / (uint32_t)(y)) + \
  288. ((((uint32_t)(x) % (uint32_t)(y)) != 0) ? 1 : 0))
  289. #define TIFFhowmany8_32(x) \
  290. (((x)&0x07) ? ((uint32_t)(x) >> 3) + 1 : (uint32_t)(x) >> 3)
  291. #define TIFFroundup_32(x, y) (TIFFhowmany_32(x, y) * (y))
  292. #define TIFFhowmany_64(x, y) \
  293. ((((uint64_t)(x)) + (((uint64_t)(y)) - 1)) / ((uint64_t)(y)))
  294. #define TIFFhowmany8_64(x) \
  295. (((x)&0x07) ? ((uint64_t)(x) >> 3) + 1 : (uint64_t)(x) >> 3)
  296. #define TIFFroundup_64(x, y) (TIFFhowmany_64(x, y) * (y))
  297. /* Safe multiply which returns zero if there is an *unsigned* integer overflow.
  298. * This macro is not safe for *signed* integer types */
  299. #define TIFFSafeMultiply(t, v, m) \
  300. ((((t)(m) != (t)0) && (((t)(((v) * (m)) / (m))) == (t)(v))) \
  301. ? (t)((v) * (m)) \
  302. : (t)0)
  303. #define TIFFmax(A, B) ((A) > (B) ? (A) : (B))
  304. #define TIFFmin(A, B) ((A) < (B) ? (A) : (B))
  305. #define TIFFArrayCount(a) (sizeof(a) / sizeof((a)[0]))
  306. /*
  307. Support for large files.
  308. Windows read/write APIs support only 'unsigned int' rather than 'size_t'.
  309. Windows off_t is only 32-bit, even in 64-bit builds.
  310. */
  311. #if defined(HAVE_FSEEKO)
  312. /*
  313. Use fseeko() and ftello() if they are available since they use
  314. 'off_t' rather than 'long'. It is wrong to use fseeko() and
  315. ftello() only on systems with special LFS support since some systems
  316. (e.g. FreeBSD) support a 64-bit off_t by default.
  317. For MinGW, __MSVCRT_VERSION__ must be at least 0x800 to expose these
  318. interfaces. The MinGW compiler must support the requested version. MinGW
  319. does not distribute the CRT (it is supplied by Microsoft) so the correct CRT
  320. must be available on the target computer in order for the program to run.
  321. */
  322. #if defined(HAVE_FSEEKO)
  323. #define fseek(stream, offset, whence) fseeko(stream, offset, whence)
  324. #define ftell(stream, offset, whence) ftello(stream, offset, whence)
  325. #endif
  326. #endif
  327. #if defined(_WIN32) && \
  328. !(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800)
  329. typedef unsigned int TIFFIOSize_t;
  330. #define _TIFF_lseek_f(fildes, offset, whence) \
  331. _lseeki64(fildes, /* __int64 */ offset, whence)
  332. /* #define _TIFF_tell_f(fildes) /\* __int64 *\/ _telli64(fildes) */
  333. #define _TIFF_fseek_f(stream, offset, whence) \
  334. _fseeki64(stream, /* __int64 */ offset, whence)
  335. #define _TIFF_fstat_f(fildes, stat_buff) \
  336. _fstati64(fildes, /* struct _stati64 */ stat_buff)
  337. /* #define _TIFF_ftell_f(stream) /\* __int64 *\/ _ftelli64(stream) */
  338. /* #define _TIFF_stat_f(path,stat_buff) _stati64(path,/\* struct _stati64 *\/
  339. * stat_buff) */
  340. #define _TIFF_stat_s struct _stati64
  341. #define _TIFF_off_t __int64
  342. #else
  343. typedef size_t TIFFIOSize_t;
  344. #define _TIFF_lseek_f(fildes, offset, whence) lseek(fildes, offset, whence)
  345. /* #define _TIFF_tell_f(fildes) (_TIFF_lseek_f(fildes,0,SEEK_CUR)) */
  346. #define _TIFF_fseek_f(stream, offset, whence) fseek(stream, offset, whence)
  347. #define _TIFF_fstat_f(fildes, stat_buff) fstat(fildes, stat_buff)
  348. /* #define _TIFF_ftell_f(stream) ftell(stream) */
  349. /* #define _TIFF_stat_f(path,stat_buff) stat(path,stat_buff) */
  350. #define _TIFF_stat_s struct stat
  351. #define _TIFF_off_t off_t
  352. #endif
  353. #if defined(__has_attribute) && defined(__clang__)
  354. #if __has_attribute(no_sanitize)
  355. #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW \
  356. __attribute__((no_sanitize("unsigned-integer-overflow")))
  357. #else
  358. #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
  359. #endif
  360. #else
  361. #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
  362. #endif
  363. #if defined(__cplusplus)
  364. extern "C"
  365. {
  366. #endif
  367. extern int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata,
  368. const char *mode, const char *module);
  369. extern int _TIFFNoRowEncode(TIFF *tif, uint8_t *pp, tmsize_t cc,
  370. uint16_t s);
  371. extern int _TIFFNoStripEncode(TIFF *tif, uint8_t *pp, tmsize_t cc,
  372. uint16_t s);
  373. extern int _TIFFNoTileEncode(TIFF *, uint8_t *pp, tmsize_t cc, uint16_t s);
  374. extern int _TIFFNoRowDecode(TIFF *tif, uint8_t *pp, tmsize_t cc,
  375. uint16_t s);
  376. extern int _TIFFNoStripDecode(TIFF *tif, uint8_t *pp, tmsize_t cc,
  377. uint16_t s);
  378. extern int _TIFFNoTileDecode(TIFF *, uint8_t *pp, tmsize_t cc, uint16_t s);
  379. extern void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc);
  380. extern int _TIFFNoPreCode(TIFF *tif, uint16_t s);
  381. extern int _TIFFNoSeek(TIFF *tif, uint32_t off);
  382. extern void _TIFFSwab16BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
  383. extern void _TIFFSwab24BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
  384. extern void _TIFFSwab32BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
  385. extern void _TIFFSwab64BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
  386. extern int TIFFFlushData1(TIFF *tif);
  387. extern int TIFFDefaultDirectory(TIFF *tif);
  388. extern void _TIFFSetDefaultCompressionState(TIFF *tif);
  389. extern int _TIFFRewriteField(TIFF *, uint16_t, TIFFDataType, tmsize_t,
  390. void *);
  391. extern int TIFFSetCompressionScheme(TIFF *tif, int scheme);
  392. extern int TIFFSetDefaultCompressionState(TIFF *tif);
  393. extern uint32_t _TIFFDefaultStripSize(TIFF *tif, uint32_t s);
  394. extern void _TIFFDefaultTileSize(TIFF *tif, uint32_t *tw, uint32_t *th);
  395. extern void _TIFFsetByteArray(void **, const void *, uint32_t);
  396. extern void _TIFFsetByteArrayExt(TIFF *, void **, const void *, uint32_t);
  397. extern void _TIFFsetShortArray(uint16_t **, const uint16_t *, uint32_t);
  398. extern void _TIFFsetShortArrayExt(TIFF *, uint16_t **, const uint16_t *,
  399. uint32_t);
  400. extern void _TIFFsetLongArray(uint32_t **, const uint32_t *, uint32_t);
  401. extern void _TIFFsetLongArrayExt(TIFF *, uint32_t **, const uint32_t *,
  402. uint32_t);
  403. extern void _TIFFsetFloatArray(float **, const float *, uint32_t);
  404. extern void _TIFFsetFloatArrayExt(TIFF *, float **, const float *,
  405. uint32_t);
  406. extern void _TIFFsetDoubleArray(double **, const double *, uint32_t);
  407. extern void _TIFFsetDoubleArrayExt(TIFF *, double **, const double *,
  408. uint32_t);
  409. extern void _TIFFprintAscii(FILE *, const char *);
  410. extern void _TIFFprintAsciiTag(FILE *, const char *, const char *);
  411. extern TIFFErrorHandler _TIFFwarningHandler;
  412. extern TIFFErrorHandler _TIFFerrorHandler;
  413. extern TIFFErrorHandlerExt _TIFFwarningHandlerExt;
  414. extern TIFFErrorHandlerExt _TIFFerrorHandlerExt;
  415. void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata,
  416. const char *module, const char *fmt, ...)
  417. TIFF_ATTRIBUTE((__format__(__printf__, 4, 5)));
  418. extern uint32_t _TIFFMultiply32(TIFF *, uint32_t, uint32_t, const char *);
  419. extern uint64_t _TIFFMultiply64(TIFF *, uint64_t, uint64_t, const char *);
  420. extern tmsize_t _TIFFMultiplySSize(TIFF *, tmsize_t, tmsize_t,
  421. const char *);
  422. extern tmsize_t _TIFFCastUInt64ToSSize(TIFF *, uint64_t, const char *);
  423. extern void *_TIFFCheckMalloc(TIFF *, tmsize_t, tmsize_t, const char *);
  424. extern void *_TIFFCheckRealloc(TIFF *, void *, tmsize_t, tmsize_t,
  425. const char *);
  426. extern float _TIFFClampDoubleToFloat(double);
  427. extern uint32_t _TIFFClampDoubleToUInt32(double);
  428. extern void _TIFFCleanupIFDOffsetAndNumberMaps(TIFF *tif);
  429. extern tmsize_t _TIFFReadEncodedStripAndAllocBuffer(TIFF *tif,
  430. uint32_t strip,
  431. void **buf,
  432. tmsize_t bufsizetoalloc,
  433. tmsize_t size_to_read);
  434. extern tmsize_t _TIFFReadEncodedTileAndAllocBuffer(TIFF *tif, uint32_t tile,
  435. void **buf,
  436. tmsize_t bufsizetoalloc,
  437. tmsize_t size_to_read);
  438. extern tmsize_t _TIFFReadTileAndAllocBuffer(TIFF *tif, void **buf,
  439. tmsize_t bufsizetoalloc,
  440. uint32_t x, uint32_t y,
  441. uint32_t z, uint16_t s);
  442. extern int _TIFFSeekOK(TIFF *tif, toff_t off);
  443. extern int TIFFInitDumpMode(TIFF *, int);
  444. #ifdef PACKBITS_SUPPORT
  445. extern int TIFFInitPackBits(TIFF *, int);
  446. #endif
  447. #ifdef CCITT_SUPPORT
  448. extern int TIFFInitCCITTRLE(TIFF *, int), TIFFInitCCITTRLEW(TIFF *, int);
  449. extern int TIFFInitCCITTFax3(TIFF *, int), TIFFInitCCITTFax4(TIFF *, int);
  450. #endif
  451. #ifdef THUNDER_SUPPORT
  452. extern int TIFFInitThunderScan(TIFF *, int);
  453. #endif
  454. #ifdef NEXT_SUPPORT
  455. extern int TIFFInitNeXT(TIFF *, int);
  456. #endif
  457. #ifdef LZW_SUPPORT
  458. extern int TIFFInitLZW(TIFF *, int);
  459. #endif
  460. #ifdef OJPEG_SUPPORT
  461. extern int TIFFInitOJPEG(TIFF *, int);
  462. #endif
  463. #ifdef JPEG_SUPPORT
  464. extern int TIFFInitJPEG(TIFF *, int);
  465. extern int TIFFJPEGIsFullStripRequired(TIFF *);
  466. #endif
  467. #ifdef JBIG_SUPPORT
  468. extern int TIFFInitJBIG(TIFF *, int);
  469. #endif
  470. #ifdef ZIP_SUPPORT
  471. extern int TIFFInitZIP(TIFF *, int);
  472. #endif
  473. #ifdef PIXARLOG_SUPPORT
  474. extern int TIFFInitPixarLog(TIFF *, int);
  475. #endif
  476. #ifdef LOGLUV_SUPPORT
  477. extern int TIFFInitSGILog(TIFF *, int);
  478. #endif
  479. #ifdef LERC_SUPPORT
  480. extern int TIFFInitLERC(TIFF *tif, int);
  481. #endif
  482. #ifdef LZMA_SUPPORT
  483. extern int TIFFInitLZMA(TIFF *, int);
  484. #endif
  485. #ifdef ZSTD_SUPPORT
  486. extern int TIFFInitZSTD(TIFF *, int);
  487. #endif
  488. #ifdef WEBP_SUPPORT
  489. extern int TIFFInitWebP(TIFF *, int);
  490. #endif
  491. extern const TIFFCodec _TIFFBuiltinCODECS[];
  492. extern void TIFFCIELab16ToXYZ(TIFFCIELabToRGB *, uint32_t l, int32_t a,
  493. int32_t b, float *, float *, float *);
  494. extern void *_TIFFmallocExt(TIFF *tif, tmsize_t s);
  495. extern void *_TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz);
  496. extern void *_TIFFreallocExt(TIFF *tif, void *p, tmsize_t s);
  497. extern void _TIFFfreeExt(TIFF *tif, void *p);
  498. #if defined(__cplusplus)
  499. }
  500. #endif
  501. #endif /* _TIFFIOP_ */