/src/FreeImage/Source/LibTIFF/tiffiop.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 353 lines · 260 code · 33 blank · 60 comment · 12 complexity · cd2766d92b67d93e2383e0761f7a1d52 MD5 · raw file

  1. /* $Id: tiffiop.h,v 1.37 2011/04/10 17:14:09 drolon 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. /*
  52. Libtiff itself does not require a 64-bit type, but bundled TIFF
  53. utilities may use it.
  54. */
  55. #if !defined(__xlC__) && !defined(__xlc__) // Already defined there (#2301)
  56. #define TIFF_INT64_T signed long long
  57. #define TIFF_UINT64_T unsigned long long
  58. #endif
  59. #include "tiffio.h"
  60. #include "tif_dir.h"
  61. #ifndef STRIP_SIZE_DEFAULT
  62. # define STRIP_SIZE_DEFAULT 8192
  63. #endif
  64. #define streq(a,b) (strcmp(a,b) == 0)
  65. #ifndef TRUE
  66. #define TRUE 1
  67. #define FALSE 0
  68. #endif
  69. typedef struct client_info {
  70. struct client_info *next;
  71. void *data;
  72. char *name;
  73. } TIFFClientInfoLink;
  74. /*
  75. * Typedefs for ``method pointers'' used internally.
  76. */
  77. typedef unsigned char tidataval_t; /* internal image data value type */
  78. typedef tidataval_t* tidata_t; /* reference to internal image data */
  79. typedef void (*TIFFVoidMethod)(TIFF*);
  80. typedef int (*TIFFBoolMethod)(TIFF*);
  81. typedef int (*TIFFPreMethod)(TIFF*, tsample_t);
  82. typedef int (*TIFFCodeMethod)(TIFF*, tidata_t, tsize_t, tsample_t);
  83. typedef int (*TIFFSeekMethod)(TIFF*, uint32);
  84. typedef void (*TIFFPostMethod)(TIFF*, tidata_t, tsize_t);
  85. typedef uint32 (*TIFFStripMethod)(TIFF*, uint32);
  86. typedef void (*TIFFTileMethod)(TIFF*, uint32*, uint32*);
  87. struct tiff {
  88. char* tif_name; /* name of open file */
  89. int tif_fd; /* open file descriptor */
  90. int tif_mode; /* open mode (O_*) */
  91. uint32 tif_flags;
  92. #define TIFF_FILLORDER 0x00003 /* natural bit fill order for machine */
  93. #define TIFF_DIRTYHEADER 0x00004 /* header must be written on close */
  94. #define TIFF_DIRTYDIRECT 0x00008 /* current directory must be written */
  95. #define TIFF_BUFFERSETUP 0x00010 /* data buffers setup */
  96. #define TIFF_CODERSETUP 0x00020 /* encoder/decoder setup done */
  97. #define TIFF_BEENWRITING 0x00040 /* written 1+ scanlines to file */
  98. #define TIFF_SWAB 0x00080 /* byte swap file information */
  99. #define TIFF_NOBITREV 0x00100 /* inhibit bit reversal logic */
  100. #define TIFF_MYBUFFER 0x00200 /* my raw data buffer; free on close */
  101. #define TIFF_ISTILED 0x00400 /* file is tile, not strip- based */
  102. #define TIFF_MAPPED 0x00800 /* file is mapped into memory */
  103. #define TIFF_POSTENCODE 0x01000 /* need call to postencode routine */
  104. #define TIFF_INSUBIFD 0x02000 /* currently writing a subifd */
  105. #define TIFF_UPSAMPLED 0x04000 /* library is doing data up-sampling */
  106. #define TIFF_STRIPCHOP 0x08000 /* enable strip chopping support */
  107. #define TIFF_HEADERONLY 0x10000 /* read header only, do not process */
  108. /* the first directory */
  109. #define TIFF_NOREADRAW 0x20000 /* skip reading of raw uncompressed */
  110. /* image data */
  111. #define TIFF_INCUSTOMIFD 0x40000 /* currently writing a custom IFD */
  112. toff_t tif_diroff; /* file offset of current directory */
  113. toff_t tif_nextdiroff; /* file offset of following directory */
  114. toff_t* tif_dirlist; /* list of offsets to already seen */
  115. /* directories to prevent IFD looping */
  116. tsize_t tif_dirlistsize;/* number of entires in offset list */
  117. uint16 tif_dirnumber; /* number of already seen directories */
  118. TIFFDirectory tif_dir; /* internal rep of current directory */
  119. TIFFDirectory tif_customdir; /* custom IFDs are separated from
  120. the main ones */
  121. TIFFHeader tif_header; /* file's header block */
  122. const int* tif_typeshift; /* data type shift counts */
  123. const long* tif_typemask; /* data type masks */
  124. uint32 tif_row; /* current scanline */
  125. tdir_t tif_curdir; /* current directory (index) */
  126. tstrip_t tif_curstrip; /* current strip for read/write */
  127. toff_t tif_curoff; /* current offset for read/write */
  128. toff_t tif_dataoff; /* current offset for writing dir */
  129. /* SubIFD support */
  130. uint16 tif_nsubifd; /* remaining subifds to write */
  131. toff_t tif_subifdoff; /* offset for patching SubIFD link */
  132. /* tiling support */
  133. uint32 tif_col; /* current column (offset by row too) */
  134. ttile_t tif_curtile; /* current tile for read/write */
  135. tsize_t tif_tilesize; /* # of bytes in a tile */
  136. /* compression scheme hooks */
  137. int tif_decodestatus;
  138. TIFFBoolMethod tif_setupdecode;/* called once before predecode */
  139. TIFFPreMethod tif_predecode; /* pre- row/strip/tile decoding */
  140. TIFFBoolMethod tif_setupencode;/* called once before preencode */
  141. int tif_encodestatus;
  142. TIFFPreMethod tif_preencode; /* pre- row/strip/tile encoding */
  143. TIFFBoolMethod tif_postencode; /* post- row/strip/tile encoding */
  144. TIFFCodeMethod tif_decoderow; /* scanline decoding routine */
  145. TIFFCodeMethod tif_encoderow; /* scanline encoding routine */
  146. TIFFCodeMethod tif_decodestrip;/* strip decoding routine */
  147. TIFFCodeMethod tif_encodestrip;/* strip encoding routine */
  148. TIFFCodeMethod tif_decodetile; /* tile decoding routine */
  149. TIFFCodeMethod tif_encodetile; /* tile encoding routine */
  150. TIFFVoidMethod tif_close; /* cleanup-on-close routine */
  151. TIFFSeekMethod tif_seek; /* position within a strip routine */
  152. TIFFVoidMethod tif_cleanup; /* cleanup state routine */
  153. TIFFStripMethod tif_defstripsize;/* calculate/constrain strip size */
  154. TIFFTileMethod tif_deftilesize;/* calculate/constrain tile size */
  155. tidata_t tif_data; /* compression scheme private data */
  156. /* input/output buffering */
  157. tsize_t tif_scanlinesize;/* # of bytes in a scanline */
  158. tsize_t tif_scanlineskew;/* scanline skew for reading strips */
  159. tidata_t tif_rawdata; /* raw data buffer */
  160. tsize_t tif_rawdatasize;/* # of bytes in raw data buffer */
  161. tidata_t tif_rawcp; /* current spot in raw buffer */
  162. tsize_t tif_rawcc; /* bytes unread from raw buffer */
  163. /* memory-mapped file support */
  164. tidata_t tif_base; /* base of mapped file */
  165. toff_t tif_size; /* size of mapped file region (bytes)
  166. FIXME: it should be tsize_t */
  167. TIFFMapFileProc tif_mapproc; /* map file method */
  168. TIFFUnmapFileProc tif_unmapproc;/* unmap file method */
  169. /* input/output callback methods */
  170. thandle_t tif_clientdata; /* callback parameter */
  171. TIFFReadWriteProc tif_readproc; /* read method */
  172. TIFFReadWriteProc tif_writeproc;/* write method */
  173. TIFFSeekProc tif_seekproc; /* lseek method */
  174. TIFFCloseProc tif_closeproc; /* close method */
  175. TIFFSizeProc tif_sizeproc; /* filesize method */
  176. /* post-decoding support */
  177. TIFFPostMethod tif_postdecode; /* post decoding routine */
  178. /* tag support */
  179. TIFFFieldInfo** tif_fieldinfo; /* sorted table of registered tags */
  180. size_t tif_nfields; /* # entries in registered tag table */
  181. const TIFFFieldInfo *tif_foundfield;/* cached pointer to already found tag */
  182. TIFFTagMethods tif_tagmethods; /* tag get/set/print routines */
  183. TIFFClientInfoLink *tif_clientinfo; /* extra client information. */
  184. };
  185. #define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
  186. #define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
  187. #define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0)
  188. #define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0)
  189. #define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
  190. #define TIFFReadFile(tif, buf, size) \
  191. ((*(tif)->tif_readproc)((tif)->tif_clientdata,buf,size))
  192. #define TIFFWriteFile(tif, buf, size) \
  193. ((*(tif)->tif_writeproc)((tif)->tif_clientdata,buf,size))
  194. #define TIFFSeekFile(tif, off, whence) \
  195. ((*(tif)->tif_seekproc)((tif)->tif_clientdata,(toff_t)(off),whence))
  196. #define TIFFCloseFile(tif) \
  197. ((*(tif)->tif_closeproc)((tif)->tif_clientdata))
  198. #define TIFFGetFileSize(tif) \
  199. ((*(tif)->tif_sizeproc)((tif)->tif_clientdata))
  200. #define TIFFMapFileContents(tif, paddr, psize) \
  201. ((*(tif)->tif_mapproc)((tif)->tif_clientdata,paddr,psize))
  202. #define TIFFUnmapFileContents(tif, addr, size) \
  203. ((*(tif)->tif_unmapproc)((tif)->tif_clientdata,addr,size))
  204. /*
  205. * Default Read/Seek/Write definitions.
  206. */
  207. #ifndef ReadOK
  208. #define ReadOK(tif, buf, size) \
  209. (TIFFReadFile(tif, (tdata_t) buf, (tsize_t)(size)) == (tsize_t)(size))
  210. #endif
  211. #ifndef SeekOK
  212. #define SeekOK(tif, off) \
  213. (TIFFSeekFile(tif, (toff_t) off, SEEK_SET) == (toff_t) off)
  214. #endif
  215. #ifndef WriteOK
  216. #define WriteOK(tif, buf, size) \
  217. (TIFFWriteFile(tif, (tdata_t) buf, (tsize_t) size) == (tsize_t) size)
  218. #endif
  219. /* NB: the uint32 casts are to silence certain ANSI-C compilers */
  220. #define TIFFhowmany(x, y) (((uint32)x < (0xffffffff - (uint32)(y-1))) ? \
  221. ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) : \
  222. 0U)
  223. #define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3)
  224. #define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y))
  225. /* Safe multiply which returns zero if there is an integer overflow */
  226. #define TIFFSafeMultiply(t,v,m) ((((t)m != (t)0) && (((t)((v*m)/m)) == (t)v)) ? (t)(v*m) : (t)0)
  227. #define TIFFmax(A,B) ((A)>(B)?(A):(B))
  228. #define TIFFmin(A,B) ((A)<(B)?(A):(B))
  229. #define TIFFArrayCount(a) (sizeof (a) / sizeof ((a)[0]))
  230. #if defined(__cplusplus)
  231. extern "C" {
  232. #endif
  233. extern int _TIFFgetMode(const char*, const char*);
  234. extern int _TIFFNoRowEncode(TIFF*, tidata_t, tsize_t, tsample_t);
  235. extern int _TIFFNoStripEncode(TIFF*, tidata_t, tsize_t, tsample_t);
  236. extern int _TIFFNoTileEncode(TIFF*, tidata_t, tsize_t, tsample_t);
  237. extern int _TIFFNoRowDecode(TIFF*, tidata_t, tsize_t, tsample_t);
  238. extern int _TIFFNoStripDecode(TIFF*, tidata_t, tsize_t, tsample_t);
  239. extern int _TIFFNoTileDecode(TIFF*, tidata_t, tsize_t, tsample_t);
  240. extern void _TIFFNoPostDecode(TIFF*, tidata_t, tsize_t);
  241. extern int _TIFFNoPreCode (TIFF*, tsample_t);
  242. extern int _TIFFNoSeek(TIFF*, uint32);
  243. extern void _TIFFSwab16BitData(TIFF*, tidata_t, tsize_t);
  244. extern void _TIFFSwab24BitData(TIFF*, tidata_t, tsize_t);
  245. extern void _TIFFSwab32BitData(TIFF*, tidata_t, tsize_t);
  246. extern void _TIFFSwab64BitData(TIFF*, tidata_t, tsize_t);
  247. extern int TIFFFlushData1(TIFF*);
  248. extern int TIFFDefaultDirectory(TIFF*);
  249. extern void _TIFFSetDefaultCompressionState(TIFF*);
  250. extern int TIFFSetCompressionScheme(TIFF*, int);
  251. extern int TIFFSetDefaultCompressionState(TIFF*);
  252. extern uint32 _TIFFDefaultStripSize(TIFF*, uint32);
  253. extern void _TIFFDefaultTileSize(TIFF*, uint32*, uint32*);
  254. extern int _TIFFDataSize(TIFFDataType);
  255. extern void _TIFFsetByteArray(void**, void*, uint32);
  256. extern void _TIFFsetString(char**, char*);
  257. extern void _TIFFsetShortArray(uint16**, uint16*, uint32);
  258. extern void _TIFFsetLongArray(uint32**, uint32*, uint32);
  259. extern void _TIFFsetFloatArray(float**, float*, uint32);
  260. extern void _TIFFsetDoubleArray(double**, double*, uint32);
  261. extern void _TIFFprintAscii(FILE*, const char*);
  262. extern void _TIFFprintAsciiTag(FILE*, const char*, const char*);
  263. extern TIFFErrorHandler _TIFFwarningHandler;
  264. extern TIFFErrorHandler _TIFFerrorHandler;
  265. extern TIFFErrorHandlerExt _TIFFwarningHandlerExt;
  266. extern TIFFErrorHandlerExt _TIFFerrorHandlerExt;
  267. extern tdata_t _TIFFCheckMalloc(TIFF*, size_t, size_t, const char*);
  268. extern tdata_t _TIFFCheckRealloc(TIFF*, tdata_t, size_t, size_t, const char*);
  269. extern int TIFFInitDumpMode(TIFF*, int);
  270. #ifdef PACKBITS_SUPPORT
  271. extern int TIFFInitPackBits(TIFF*, int);
  272. #endif
  273. #ifdef CCITT_SUPPORT
  274. extern int TIFFInitCCITTRLE(TIFF*, int), TIFFInitCCITTRLEW(TIFF*, int);
  275. extern int TIFFInitCCITTFax3(TIFF*, int), TIFFInitCCITTFax4(TIFF*, int);
  276. #endif
  277. #ifdef THUNDER_SUPPORT
  278. extern int TIFFInitThunderScan(TIFF*, int);
  279. #endif
  280. #ifdef NEXT_SUPPORT
  281. extern int TIFFInitNeXT(TIFF*, int);
  282. #endif
  283. #ifdef LZW_SUPPORT
  284. extern int TIFFInitLZW(TIFF*, int);
  285. #endif
  286. #ifdef OJPEG_SUPPORT
  287. extern int TIFFInitOJPEG(TIFF*, int);
  288. #endif
  289. #ifdef JPEG_SUPPORT
  290. extern int TIFFInitJPEG(TIFF*, int);
  291. #endif
  292. #ifdef JBIG_SUPPORT
  293. extern int TIFFInitJBIG(TIFF*, int);
  294. #endif
  295. #ifdef ZIP_SUPPORT
  296. extern int TIFFInitZIP(TIFF*, int);
  297. #endif
  298. #ifdef PIXARLOG_SUPPORT
  299. extern int TIFFInitPixarLog(TIFF*, int);
  300. #endif
  301. #ifdef LOGLUV_SUPPORT
  302. extern int TIFFInitSGILog(TIFF*, int);
  303. #endif
  304. #ifdef VMS
  305. extern const TIFFCodec _TIFFBuiltinCODECS[];
  306. #else
  307. extern TIFFCodec _TIFFBuiltinCODECS[];
  308. #endif
  309. #if defined(__cplusplus)
  310. }
  311. #endif
  312. #endif /* _TIFFIOP_ */
  313. /* vim: set ts=8 sts=8 sw=8 noet: */
  314. /*
  315. * Local Variables:
  316. * mode: c
  317. * c-basic-offset: 8
  318. * fill-column: 78
  319. * End:
  320. */