/cocos2dx/platform/third_party/linux/libtiff/include/tiffiop.h

https://bitbucket.org/Tsiannian/cocos2d-x · C++ Header · 366 lines · 279 code · 33 blank · 54 comment · 8 complexity · 54b108382f84f405e5b27e101c02334a MD5 · raw file

  1. /* $Id: tiffiop.h,v 1.82 2011-02-18 20:53:05 fwarmerdam Exp $ */
  2. /*
  3. * Copyright (c) 1988-1997 Sam Leffler
  4. * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  5. *
  6. * Permission to use, copy, modify, distribute, and sell this software and
  7. * its documentation for any purpose is hereby granted without fee, provided
  8. * that (i) the above copyright notices and this permission notice appear in
  9. * all copies of the software and related documentation, and (ii) the names of
  10. * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11. * publicity relating to the software without the specific, prior written
  12. * permission of Sam Leffler and Silicon Graphics.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  15. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  16. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  22. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  23. * OF THIS SOFTWARE.
  24. */
  25. #ifndef _TIFFIOP_
  26. #define _TIFFIOP_
  27. /*
  28. * ``Library-private'' definitions.
  29. */
  30. #include "tif_config.h"
  31. #ifdef HAVE_FCNTL_H
  32. # include <fcntl.h>
  33. #endif
  34. #ifdef HAVE_SYS_TYPES_H
  35. # include <sys/types.h>
  36. #endif
  37. #ifdef HAVE_STRING_H
  38. # include <string.h>
  39. #endif
  40. #ifdef HAVE_ASSERT_H
  41. # include <assert.h>
  42. #else
  43. # define assert(x)
  44. #endif
  45. #ifdef HAVE_SEARCH_H
  46. # include <search.h>
  47. #else
  48. extern void *lfind(const void *, const void *, size_t *, size_t,
  49. int (*)(const void *, const void *));
  50. #endif
  51. #include "tiffio.h"
  52. #include "tif_dir.h"
  53. #ifndef STRIP_SIZE_DEFAULT
  54. # define STRIP_SIZE_DEFAULT 8192
  55. #endif
  56. #define streq(a,b) (strcmp(a,b) == 0)
  57. #ifndef TRUE
  58. #define TRUE 1
  59. #define FALSE 0
  60. #endif
  61. typedef struct client_info {
  62. struct client_info *next;
  63. void *data;
  64. char *name;
  65. } TIFFClientInfoLink;
  66. /*
  67. * Typedefs for ``method pointers'' used internally.
  68. * these are depriciated and provided only for backwards compatibility
  69. */
  70. typedef unsigned char tidataval_t; /* internal image data value type */
  71. typedef tidataval_t* tidata_t; /* reference to internal image data */
  72. typedef void (*TIFFVoidMethod)(TIFF*);
  73. typedef int (*TIFFBoolMethod)(TIFF*);
  74. typedef int (*TIFFPreMethod)(TIFF*, uint16);
  75. typedef int (*TIFFCodeMethod)(TIFF* tif, uint8* buf, tmsize_t size, uint16 sample);
  76. typedef int (*TIFFSeekMethod)(TIFF*, uint32);
  77. typedef void (*TIFFPostMethod)(TIFF* tif, uint8* buf, tmsize_t size);
  78. typedef uint32 (*TIFFStripMethod)(TIFF*, uint32);
  79. typedef void (*TIFFTileMethod)(TIFF*, uint32*, uint32*);
  80. struct tiff {
  81. char* tif_name; /* name of open file */
  82. int tif_fd; /* open file descriptor */
  83. int tif_mode; /* open mode (O_*) */
  84. uint32 tif_flags;
  85. #define TIFF_FILLORDER 0x00003 /* natural bit fill order for machine */
  86. #define TIFF_DIRTYHEADER 0x00004 /* header must be written on close */
  87. #define TIFF_DIRTYDIRECT 0x00008 /* current directory must be written */
  88. #define TIFF_BUFFERSETUP 0x00010 /* data buffers setup */
  89. #define TIFF_CODERSETUP 0x00020 /* encoder/decoder setup done */
  90. #define TIFF_BEENWRITING 0x00040 /* written 1+ scanlines to file */
  91. #define TIFF_SWAB 0x00080 /* byte swap file information */
  92. #define TIFF_NOBITREV 0x00100 /* inhibit bit reversal logic */
  93. #define TIFF_MYBUFFER 0x00200 /* my raw data buffer; free on close */
  94. #define TIFF_ISTILED 0x00400 /* file is tile, not strip- based */
  95. #define TIFF_MAPPED 0x00800 /* file is mapped into memory */
  96. #define TIFF_POSTENCODE 0x01000 /* need call to postencode routine */
  97. #define TIFF_INSUBIFD 0x02000 /* currently writing a subifd */
  98. #define TIFF_UPSAMPLED 0x04000 /* library is doing data up-sampling */
  99. #define TIFF_STRIPCHOP 0x08000 /* enable strip chopping support */
  100. #define TIFF_HEADERONLY 0x10000 /* read header only, do not process the first directory */
  101. #define TIFF_NOREADRAW 0x20000 /* skip reading of raw uncompressed image data */
  102. #define TIFF_INCUSTOMIFD 0x40000 /* currently writing a custom IFD */
  103. #define TIFF_BIGTIFF 0x80000 /* read/write bigtiff */
  104. #define TIFF_BUF4WRITE 0x100000 /* rawcc bytes are for writing */
  105. #define TIFF_DIRTYSTRIP 0x200000 /* stripoffsets/stripbytecount dirty*/
  106. #define TIFF_PERSAMPLE 0x400000 /* get/set per sample tags as arrays */
  107. uint64 tif_diroff; /* file offset of current directory */
  108. uint64 tif_nextdiroff; /* file offset of following directory */
  109. uint64* tif_dirlist; /* list of offsets to already seen directories to prevent IFD looping */
  110. uint16 tif_dirlistsize; /* number of entires in offset list */
  111. uint16 tif_dirnumber; /* number of already seen directories */
  112. TIFFDirectory tif_dir; /* internal rep of current directory */
  113. TIFFDirectory tif_customdir; /* custom IFDs are separated from the main ones */
  114. union {
  115. TIFFHeaderCommon common;
  116. TIFFHeaderClassic classic;
  117. TIFFHeaderBig big;
  118. } tif_header;
  119. uint16 tif_header_size; /* file's header block and its length */
  120. uint32 tif_row; /* current scanline */
  121. uint16 tif_curdir; /* current directory (index) */
  122. uint32 tif_curstrip; /* current strip for read/write */
  123. uint64 tif_curoff; /* current offset for read/write */
  124. uint64 tif_dataoff; /* current offset for writing dir */
  125. /* SubIFD support */
  126. uint16 tif_nsubifd; /* remaining subifds to write */
  127. uint64 tif_subifdoff; /* offset for patching SubIFD link */
  128. /* tiling support */
  129. uint32 tif_col; /* current column (offset by row too) */
  130. uint32 tif_curtile; /* current tile for read/write */
  131. tmsize_t tif_tilesize; /* # of bytes in a tile */
  132. /* compression scheme hooks */
  133. int tif_decodestatus;
  134. TIFFBoolMethod tif_fixuptags; /* called in TIFFReadDirectory */
  135. TIFFBoolMethod tif_setupdecode; /* called once before predecode */
  136. TIFFPreMethod tif_predecode; /* pre- row/strip/tile decoding */
  137. TIFFBoolMethod tif_setupencode; /* called once before preencode */
  138. int tif_encodestatus;
  139. TIFFPreMethod tif_preencode; /* pre- row/strip/tile encoding */
  140. TIFFBoolMethod tif_postencode; /* post- row/strip/tile encoding */
  141. TIFFCodeMethod tif_decoderow; /* scanline decoding routine */
  142. TIFFCodeMethod tif_encoderow; /* scanline encoding routine */
  143. TIFFCodeMethod tif_decodestrip; /* strip decoding routine */
  144. TIFFCodeMethod tif_encodestrip; /* strip encoding routine */
  145. TIFFCodeMethod tif_decodetile; /* tile decoding routine */
  146. TIFFCodeMethod tif_encodetile; /* tile encoding routine */
  147. TIFFVoidMethod tif_close; /* cleanup-on-close routine */
  148. TIFFSeekMethod tif_seek; /* position within a strip routine */
  149. TIFFVoidMethod tif_cleanup; /* cleanup state routine */
  150. TIFFStripMethod tif_defstripsize; /* calculate/constrain strip size */
  151. TIFFTileMethod tif_deftilesize; /* calculate/constrain tile size */
  152. uint8* tif_data; /* compression scheme private data */
  153. /* input/output buffering */
  154. tmsize_t tif_scanlinesize; /* # of bytes in a scanline */
  155. tmsize_t tif_scanlineskew; /* scanline skew for reading strips */
  156. uint8* tif_rawdata; /* raw data buffer */
  157. tmsize_t tif_rawdatasize; /* # of bytes in raw data buffer */
  158. tmsize_t tif_rawdataoff; /* rawdata offset within strip */
  159. tmsize_t tif_rawdataloaded;/* amount of data in rawdata */
  160. uint8* tif_rawcp; /* current spot in raw buffer */
  161. tmsize_t tif_rawcc; /* bytes unread from raw buffer */
  162. /* memory-mapped file support */
  163. uint8* tif_base; /* base of mapped file */
  164. tmsize_t tif_size; /* size of mapped file region (bytes, thus tmsize_t) */
  165. TIFFMapFileProc tif_mapproc; /* map file method */
  166. TIFFUnmapFileProc tif_unmapproc; /* unmap file method */
  167. /* input/output callback methods */
  168. thandle_t tif_clientdata; /* callback parameter */
  169. TIFFReadWriteProc tif_readproc; /* read method */
  170. TIFFReadWriteProc tif_writeproc; /* write method */
  171. TIFFSeekProc tif_seekproc; /* lseek method */
  172. TIFFCloseProc tif_closeproc; /* close method */
  173. TIFFSizeProc tif_sizeproc; /* filesize method */
  174. /* post-decoding support */
  175. TIFFPostMethod tif_postdecode; /* post decoding routine */
  176. /* tag support */
  177. TIFFField** tif_fields; /* sorted table of registered tags */
  178. size_t tif_nfields; /* # entries in registered tag table */
  179. const TIFFField* tif_foundfield; /* cached pointer to already found tag */
  180. TIFFTagMethods tif_tagmethods; /* tag get/set/print routines */
  181. TIFFClientInfoLink* tif_clientinfo; /* extra client information. */
  182. /* Backward compatibility stuff. We need these two fields for
  183. * setting up an old tag extension scheme. */
  184. TIFFFieldArray* tif_fieldscompat;
  185. size_t tif_nfieldscompat;
  186. };
  187. #define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
  188. #define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  189. #define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0)
  190. #define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0)
  191. #define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
  192. #define TIFFReadFile(tif, buf, size) \
  193. ((*(tif)->tif_readproc)((tif)->tif_clientdata,(buf),(size)))
  194. #define TIFFWriteFile(tif, buf, size) \
  195. ((*(tif)->tif_writeproc)((tif)->tif_clientdata,(buf),(size)))
  196. #define TIFFSeekFile(tif, off, whence) \
  197. ((*(tif)->tif_seekproc)((tif)->tif_clientdata,(off),(whence)))
  198. #define TIFFCloseFile(tif) \
  199. ((*(tif)->tif_closeproc)((tif)->tif_clientdata))
  200. #define TIFFGetFileSize(tif) \
  201. ((*(tif)->tif_sizeproc)((tif)->tif_clientdata))
  202. #define TIFFMapFileContents(tif, paddr, psize) \
  203. ((*(tif)->tif_mapproc)((tif)->tif_clientdata,(paddr),(psize)))
  204. #define TIFFUnmapFileContents(tif, addr, size) \
  205. ((*(tif)->tif_unmapproc)((tif)->tif_clientdata,(addr),(size)))
  206. /*
  207. * Default Read/Seek/Write definitions.
  208. */
  209. #ifndef ReadOK
  210. #define ReadOK(tif, buf, size) \
  211. (TIFFReadFile((tif),(buf),(size))==(size))
  212. #endif
  213. #ifndef SeekOK
  214. #define SeekOK(tif, off) \
  215. (TIFFSeekFile((tif),(off),SEEK_SET)==(off))
  216. #endif
  217. #ifndef WriteOK
  218. #define WriteOK(tif, buf, size) \
  219. (TIFFWriteFile((tif),(buf),(size))==(size))
  220. #endif
  221. /* NB: the uint32 casts are to silence certain ANSI-C compilers */
  222. #define TIFFhowmany_32(x, y) (((uint32)x < (0xffffffff - (uint32)(y-1))) ? \
  223. ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) : \
  224. 0U)
  225. #define TIFFhowmany8_32(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3)
  226. #define TIFFroundup_32(x, y) (TIFFhowmany_32(x,y)*(y))
  227. #define TIFFhowmany_64(x, y) ((((uint64)(x))+(((uint64)(y))-1))/((uint64)(y)))
  228. #define TIFFhowmany8_64(x) (((x)&0x07)?((uint64)(x)>>3)+1:(uint64)(x)>>3)
  229. #define TIFFroundup_64(x, y) (TIFFhowmany_64(x,y)*(y))
  230. /* Safe multiply which returns zero if there is an integer overflow */
  231. #define TIFFSafeMultiply(t,v,m) ((((t)m != (t)0) && (((t)((v*m)/m)) == (t)v)) ? (t)(v*m) : (t)0)
  232. #define TIFFmax(A,B) ((A)>(B)?(A):(B))
  233. #define TIFFmin(A,B) ((A)<(B)?(A):(B))
  234. #define TIFFArrayCount(a) (sizeof (a) / sizeof ((a)[0]))
  235. #if defined(__cplusplus)
  236. extern "C" {
  237. #endif
  238. extern int _TIFFgetMode(const char* mode, const char* module);
  239. extern int _TIFFNoRowEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s);
  240. extern int _TIFFNoStripEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s);
  241. extern int _TIFFNoTileEncode(TIFF*, uint8* pp, tmsize_t cc, uint16 s);
  242. extern int _TIFFNoRowDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s);
  243. extern int _TIFFNoStripDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s);
  244. extern int _TIFFNoTileDecode(TIFF*, uint8* pp, tmsize_t cc, uint16 s);
  245. extern void _TIFFNoPostDecode(TIFF* tif, uint8* buf, tmsize_t cc);
  246. extern int _TIFFNoPreCode(TIFF* tif, uint16 s);
  247. extern int _TIFFNoSeek(TIFF* tif, uint32 off);
  248. extern void _TIFFSwab16BitData(TIFF* tif, uint8* buf, tmsize_t cc);
  249. extern void _TIFFSwab24BitData(TIFF* tif, uint8* buf, tmsize_t cc);
  250. extern void _TIFFSwab32BitData(TIFF* tif, uint8* buf, tmsize_t cc);
  251. extern void _TIFFSwab64BitData(TIFF* tif, uint8* buf, tmsize_t cc);
  252. extern int TIFFFlushData1(TIFF* tif);
  253. extern int TIFFDefaultDirectory(TIFF* tif);
  254. extern void _TIFFSetDefaultCompressionState(TIFF* tif);
  255. extern int _TIFFRewriteField(TIFF *, uint16, TIFFDataType, tmsize_t, void *);
  256. extern int TIFFSetCompressionScheme(TIFF* tif, int scheme);
  257. extern int TIFFSetDefaultCompressionState(TIFF* tif);
  258. extern uint32 _TIFFDefaultStripSize(TIFF* tif, uint32 s);
  259. extern void _TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th);
  260. extern int _TIFFDataSize(TIFFDataType type);
  261. extern void _TIFFsetByteArray(void**, void*, uint32);
  262. extern void _TIFFsetString(char**, char*);
  263. extern void _TIFFsetShortArray(uint16**, uint16*, uint32);
  264. extern void _TIFFsetLongArray(uint32**, uint32*, uint32);
  265. extern void _TIFFsetFloatArray(float**, float*, uint32);
  266. extern void _TIFFsetDoubleArray(double**, double*, uint32);
  267. extern void _TIFFprintAscii(FILE*, const char*);
  268. extern void _TIFFprintAsciiTag(FILE*, const char*, const char*);
  269. extern TIFFErrorHandler _TIFFwarningHandler;
  270. extern TIFFErrorHandler _TIFFerrorHandler;
  271. extern TIFFErrorHandlerExt _TIFFwarningHandlerExt;
  272. extern TIFFErrorHandlerExt _TIFFerrorHandlerExt;
  273. extern uint32 _TIFFMultiply32(TIFF*, uint32, uint32, const char*);
  274. extern uint64 _TIFFMultiply64(TIFF*, uint64, uint64, const char*);
  275. extern void* _TIFFCheckMalloc(TIFF*, tmsize_t, tmsize_t, const char*);
  276. extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*);
  277. extern double _TIFFUInt64ToDouble(uint64);
  278. extern float _TIFFUInt64ToFloat(uint64);
  279. extern int TIFFInitDumpMode(TIFF*, int);
  280. #ifdef PACKBITS_SUPPORT
  281. extern int TIFFInitPackBits(TIFF*, int);
  282. #endif
  283. #ifdef CCITT_SUPPORT
  284. extern int TIFFInitCCITTRLE(TIFF*, int), TIFFInitCCITTRLEW(TIFF*, int);
  285. extern int TIFFInitCCITTFax3(TIFF*, int), TIFFInitCCITTFax4(TIFF*, int);
  286. #endif
  287. #ifdef THUNDER_SUPPORT
  288. extern int TIFFInitThunderScan(TIFF*, int);
  289. #endif
  290. #ifdef NEXT_SUPPORT
  291. extern int TIFFInitNeXT(TIFF*, int);
  292. #endif
  293. #ifdef LZW_SUPPORT
  294. extern int TIFFInitLZW(TIFF*, int);
  295. #endif
  296. #ifdef OJPEG_SUPPORT
  297. extern int TIFFInitOJPEG(TIFF*, int);
  298. #endif
  299. #ifdef JPEG_SUPPORT
  300. extern int TIFFInitJPEG(TIFF*, int);
  301. #endif
  302. #ifdef JBIG_SUPPORT
  303. extern int TIFFInitJBIG(TIFF*, int);
  304. #endif
  305. #ifdef ZIP_SUPPORT
  306. extern int TIFFInitZIP(TIFF*, int);
  307. #endif
  308. #ifdef PIXARLOG_SUPPORT
  309. extern int TIFFInitPixarLog(TIFF*, int);
  310. #endif
  311. #ifdef LOGLUV_SUPPORT
  312. extern int TIFFInitSGILog(TIFF*, int);
  313. #endif
  314. #ifdef LZMA_SUPPORT
  315. extern int TIFFInitLZMA(TIFF*, int);
  316. #endif
  317. #ifdef VMS
  318. extern const TIFFCodec _TIFFBuiltinCODECS[];
  319. #else
  320. extern TIFFCodec _TIFFBuiltinCODECS[];
  321. #endif
  322. #if defined(__cplusplus)
  323. }
  324. #endif
  325. #endif /* _TIFFIOP_ */
  326. /* vim: set ts=8 sts=8 sw=8 noet: */
  327. /*
  328. * Local Variables:
  329. * mode: c
  330. * c-basic-offset: 8
  331. * fill-column: 78
  332. * End:
  333. */