PBRT
/home/felix/UBC/projects/AdaptiveLightfieldSampling/pbrt_v2/src/3rdparty/tiff-3.9.4/tiffiop.h
00001 /* $Id: tiffiop.h,v 1.51.2.6 2010-06-12 02:55:16 bfriesen Exp $ */
00002 
00003 /*
00004  * Copyright (c) 1988-1997 Sam Leffler
00005  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
00006  *
00007  * Permission to use, copy, modify, distribute, and sell this software and 
00008  * its documentation for any purpose is hereby granted without fee, provided
00009  * that (i) the above copyright notices and this permission notice appear in
00010  * all copies of the software and related documentation, and (ii) the names of
00011  * Sam Leffler and Silicon Graphics may not be used in any advertising or
00012  * publicity relating to the software without the specific, prior written
00013  * permission of Sam Leffler and Silicon Graphics.
00014  * 
00015  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
00016  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
00017  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
00018  * 
00019  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
00020  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
00021  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00022  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
00023  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
00024  * OF THIS SOFTWARE.
00025  */
00026 
00027 #ifndef _TIFFIOP_
00028 #define _TIFFIOP_
00029 /*
00030  * ``Library-private'' definitions.
00031  */
00032 
00033 #include "tif_config.h"
00034 
00035 #ifdef HAVE_FCNTL_H
00036 # include <fcntl.h>
00037 #endif
00038 
00039 #ifdef HAVE_SYS_TYPES_H
00040 # include <sys/types.h>
00041 #endif
00042 
00043 #ifdef HAVE_STRING_H
00044 # include <string.h>
00045 #endif
00046 
00047 #ifdef HAVE_ASSERT_H
00048 # include <assert.h>
00049 #else
00050 # define assert(x) 
00051 #endif
00052 
00053 #ifdef HAVE_SEARCH_H
00054 # include <search.h>
00055 #else
00056 extern void *lfind(const void *, const void *, size_t *, size_t,
00057                    int (*)(const void *, const void *));
00058 #endif
00059 
00060 /*
00061   Libtiff itself does not require a 64-bit type, but bundled TIFF
00062   utilities may use it.
00063 */
00064 typedef TIFF_INT64_T  int64;
00065 typedef TIFF_UINT64_T uint64;
00066 
00067 #include "tiffio.h"
00068 #include "tif_dir.h"
00069 
00070 #ifndef STRIP_SIZE_DEFAULT
00071 # define STRIP_SIZE_DEFAULT 8192
00072 #endif
00073 
00074 #define    streq(a,b)      (strcmp(a,b) == 0)
00075 
00076 #ifndef TRUE
00077 #define TRUE    1
00078 #define FALSE   0
00079 #endif
00080 
00081 typedef struct client_info {
00082     struct client_info *next;
00083     void      *data;
00084     char      *name;
00085 } TIFFClientInfoLink;
00086 
00087 /*
00088  * Typedefs for ``method pointers'' used internally.
00089  */
00090 typedef unsigned char tidataval_t;      /* internal image data value type */
00091 typedef tidataval_t* tidata_t;          /* reference to internal image data */
00092 
00093 typedef void (*TIFFVoidMethod)(TIFF*);
00094 typedef int (*TIFFBoolMethod)(TIFF*);
00095 typedef int (*TIFFPreMethod)(TIFF*, tsample_t);
00096 typedef int (*TIFFCodeMethod)(TIFF*, tidata_t, tsize_t, tsample_t);
00097 typedef int (*TIFFSeekMethod)(TIFF*, uint32);
00098 typedef void (*TIFFPostMethod)(TIFF*, tidata_t, tsize_t);
00099 typedef uint32 (*TIFFStripMethod)(TIFF*, uint32);
00100 typedef void (*TIFFTileMethod)(TIFF*, uint32*, uint32*);
00101 
00102 struct tiff {
00103         char*           tif_name;       /* name of open file */
00104         int             tif_fd;         /* open file descriptor */
00105         int             tif_mode;       /* open mode (O_*) */
00106         uint32          tif_flags;
00107 #define TIFF_FILLORDER          0x00003 /* natural bit fill order for machine */
00108 #define TIFF_DIRTYHEADER        0x00004 /* header must be written on close */
00109 #define TIFF_DIRTYDIRECT        0x00008 /* current directory must be written */
00110 #define TIFF_BUFFERSETUP        0x00010 /* data buffers setup */
00111 #define TIFF_CODERSETUP         0x00020 /* encoder/decoder setup done */
00112 #define TIFF_BEENWRITING        0x00040 /* written 1+ scanlines to file */
00113 #define TIFF_SWAB               0x00080 /* byte swap file information */
00114 #define TIFF_NOBITREV           0x00100 /* inhibit bit reversal logic */
00115 #define TIFF_MYBUFFER           0x00200 /* my raw data buffer; free on close */
00116 #define TIFF_ISTILED            0x00400 /* file is tile, not strip- based */
00117 #define TIFF_MAPPED             0x00800 /* file is mapped into memory */
00118 #define TIFF_POSTENCODE         0x01000 /* need call to postencode routine */
00119 #define TIFF_INSUBIFD           0x02000 /* currently writing a subifd */
00120 #define TIFF_UPSAMPLED          0x04000 /* library is doing data up-sampling */ 
00121 #define TIFF_STRIPCHOP          0x08000 /* enable strip chopping support */
00122 #define TIFF_HEADERONLY         0x10000 /* read header only, do not process */
00123                                         /* the first directory */
00124 #define TIFF_NOREADRAW          0x20000 /* skip reading of raw uncompressed */
00125                                         /* image data */
00126 #define TIFF_INCUSTOMIFD        0x40000 /* currently writing a custom IFD */
00127         toff_t          tif_diroff;     /* file offset of current directory */
00128         toff_t          tif_nextdiroff; /* file offset of following directory */
00129         toff_t*         tif_dirlist;    /* list of offsets to already seen */
00130                                         /* directories to prevent IFD looping */
00131         tsize_t         tif_dirlistsize;/* number of entires in offset list */
00132         uint16          tif_dirnumber;  /* number of already seen directories */
00133         TIFFDirectory   tif_dir;        /* internal rep of current directory */
00134         TIFFDirectory   tif_customdir;  /* custom IFDs are separated from
00135                                            the main ones */
00136         TIFFHeader      tif_header;     /* file's header block */
00137         const int*      tif_typeshift;  /* data type shift counts */
00138         const long*     tif_typemask;   /* data type masks */
00139         uint32          tif_row;        /* current scanline */
00140         tdir_t          tif_curdir;     /* current directory (index) */
00141         tstrip_t        tif_curstrip;   /* current strip for read/write */
00142         toff_t          tif_curoff;     /* current offset for read/write */
00143         toff_t          tif_dataoff;    /* current offset for writing dir */
00144 /* SubIFD support */
00145         uint16          tif_nsubifd;    /* remaining subifds to write */
00146         toff_t          tif_subifdoff;  /* offset for patching SubIFD link */
00147 /* tiling support */
00148         uint32          tif_col;        /* current column (offset by row too) */
00149         ttile_t         tif_curtile;    /* current tile for read/write */
00150         tsize_t         tif_tilesize;   /* # of bytes in a tile */
00151 /* compression scheme hooks */
00152         int             tif_decodestatus;
00153         TIFFBoolMethod  tif_setupdecode;/* called once before predecode */
00154         TIFFPreMethod   tif_predecode;  /* pre- row/strip/tile decoding */
00155         TIFFBoolMethod  tif_setupencode;/* called once before preencode */
00156         int             tif_encodestatus;
00157         TIFFPreMethod   tif_preencode;  /* pre- row/strip/tile encoding */
00158         TIFFBoolMethod  tif_postencode; /* post- row/strip/tile encoding */
00159         TIFFCodeMethod  tif_decoderow;  /* scanline decoding routine */
00160         TIFFCodeMethod  tif_encoderow;  /* scanline encoding routine */
00161         TIFFCodeMethod  tif_decodestrip;/* strip decoding routine */
00162         TIFFCodeMethod  tif_encodestrip;/* strip encoding routine */
00163         TIFFCodeMethod  tif_decodetile; /* tile decoding routine */
00164         TIFFCodeMethod  tif_encodetile; /* tile encoding routine */
00165         TIFFVoidMethod  tif_close;      /* cleanup-on-close routine */
00166         TIFFSeekMethod  tif_seek;       /* position within a strip routine */
00167         TIFFVoidMethod  tif_cleanup;    /* cleanup state routine */
00168         TIFFStripMethod tif_defstripsize;/* calculate/constrain strip size */
00169         TIFFTileMethod  tif_deftilesize;/* calculate/constrain tile size */
00170         tidata_t        tif_data;       /* compression scheme private data */
00171 /* input/output buffering */
00172         tsize_t         tif_scanlinesize;/* # of bytes in a scanline */
00173         tsize_t         tif_scanlineskew;/* scanline skew for reading strips */
00174         tidata_t        tif_rawdata;    /* raw data buffer */
00175         tsize_t         tif_rawdatasize;/* # of bytes in raw data buffer */
00176         tidata_t        tif_rawcp;      /* current spot in raw buffer */
00177         tsize_t         tif_rawcc;      /* bytes unread from raw buffer */
00178 /* memory-mapped file support */
00179         tidata_t        tif_base;       /* base of mapped file */
00180         toff_t          tif_size;       /* size of mapped file region (bytes)
00181                                            FIXME: it should be tsize_t */
00182         TIFFMapFileProc tif_mapproc;    /* map file method */
00183         TIFFUnmapFileProc tif_unmapproc;/* unmap file method */
00184 /* input/output callback methods */
00185         thandle_t       tif_clientdata; /* callback parameter */
00186         TIFFReadWriteProc tif_readproc; /* read method */
00187         TIFFReadWriteProc tif_writeproc;/* write method */
00188         TIFFSeekProc    tif_seekproc;   /* lseek method */
00189         TIFFCloseProc   tif_closeproc;  /* close method */
00190         TIFFSizeProc    tif_sizeproc;   /* filesize method */
00191 /* post-decoding support */
00192         TIFFPostMethod  tif_postdecode; /* post decoding routine */
00193 /* tag support */
00194         TIFFFieldInfo** tif_fieldinfo;  /* sorted table of registered tags */
00195         size_t          tif_nfields;    /* # entries in registered tag table */
00196         const TIFFFieldInfo *tif_foundfield;/* cached pointer to already found tag */
00197         TIFFTagMethods  tif_tagmethods; /* tag get/set/print routines */
00198         TIFFClientInfoLink *tif_clientinfo; /* extra client information. */
00199 };
00200 
00201 #define isPseudoTag(t)  (t > 0xffff)    /* is tag value normal or pseudo */
00202 
00203 #define isTiled(tif)    (((tif)->tif_flags & TIFF_ISTILED) != 0)
00204 #define isMapped(tif)   (((tif)->tif_flags & TIFF_MAPPED) != 0)
00205 #define isFillOrder(tif, o)     (((tif)->tif_flags & (o)) != 0)
00206 #define isUpSampled(tif)        (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
00207 #define TIFFReadFile(tif, buf, size) \
00208         ((*(tif)->tif_readproc)((tif)->tif_clientdata,buf,size))
00209 #define TIFFWriteFile(tif, buf, size) \
00210         ((*(tif)->tif_writeproc)((tif)->tif_clientdata,buf,size))
00211 #define TIFFSeekFile(tif, off, whence) \
00212         ((*(tif)->tif_seekproc)((tif)->tif_clientdata,(toff_t)(off),whence))
00213 #define TIFFCloseFile(tif) \
00214         ((*(tif)->tif_closeproc)((tif)->tif_clientdata))
00215 #define TIFFGetFileSize(tif) \
00216         ((*(tif)->tif_sizeproc)((tif)->tif_clientdata))
00217 #define TIFFMapFileContents(tif, paddr, psize) \
00218         ((*(tif)->tif_mapproc)((tif)->tif_clientdata,paddr,psize))
00219 #define TIFFUnmapFileContents(tif, addr, size) \
00220         ((*(tif)->tif_unmapproc)((tif)->tif_clientdata,addr,size))
00221 
00222 /*
00223  * Default Read/Seek/Write definitions.
00224  */
00225 #ifndef ReadOK
00226 #define ReadOK(tif, buf, size) \
00227         (TIFFReadFile(tif, (tdata_t) buf, (tsize_t)(size)) == (tsize_t)(size))
00228 #endif
00229 #ifndef SeekOK
00230 #define SeekOK(tif, off) \
00231         (TIFFSeekFile(tif, (toff_t) off, SEEK_SET) == (toff_t) off)
00232 #endif
00233 #ifndef WriteOK
00234 #define WriteOK(tif, buf, size) \
00235         (TIFFWriteFile(tif, (tdata_t) buf, (tsize_t) size) == (tsize_t) size)
00236 #endif
00237 
00238 /* NB: the uint32 casts are to silence certain ANSI-C compilers */
00239 #define TIFFhowmany(x, y) (((uint32)x < (0xffffffff - (uint32)(y-1))) ? \
00240                            ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) : \
00241                            0U)
00242 #define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3)
00243 #define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y))
00244 
00245 /* Safe multiply which returns zero if there is an integer overflow */
00246 #define TIFFSafeMultiply(t,v,m) ((((t)m != (t)0) && (((t)((v*m)/m)) == (t)v)) ? (t)(v*m) : (t)0)
00247 
00248 #define TIFFmax(A,B) ((A)>(B)?(A):(B))
00249 #define TIFFmin(A,B) ((A)<(B)?(A):(B))
00250 
00251 #define TIFFArrayCount(a) (sizeof (a) / sizeof ((a)[0]))
00252 
00253 #if defined(__cplusplus)
00254 extern "C" {
00255 #endif
00256 extern  int _TIFFgetMode(const char*, const char*);
00257 extern  int _TIFFNoRowEncode(TIFF*, tidata_t, tsize_t, tsample_t);
00258 extern  int _TIFFNoStripEncode(TIFF*, tidata_t, tsize_t, tsample_t);
00259 extern  int _TIFFNoTileEncode(TIFF*, tidata_t, tsize_t, tsample_t);
00260 extern  int _TIFFNoRowDecode(TIFF*, tidata_t, tsize_t, tsample_t);
00261 extern  int _TIFFNoStripDecode(TIFF*, tidata_t, tsize_t, tsample_t);
00262 extern  int _TIFFNoTileDecode(TIFF*, tidata_t, tsize_t, tsample_t);
00263 extern  void _TIFFNoPostDecode(TIFF*, tidata_t, tsize_t);
00264 extern  int  _TIFFNoPreCode (TIFF*, tsample_t); 
00265 extern  int _TIFFNoSeek(TIFF*, uint32);
00266 extern  void _TIFFSwab16BitData(TIFF*, tidata_t, tsize_t);
00267 extern  void _TIFFSwab24BitData(TIFF*, tidata_t, tsize_t);
00268 extern  void _TIFFSwab32BitData(TIFF*, tidata_t, tsize_t);
00269 extern  void _TIFFSwab64BitData(TIFF*, tidata_t, tsize_t);
00270 extern  int TIFFFlushData1(TIFF*);
00271 extern  int TIFFDefaultDirectory(TIFF*);
00272 extern  void _TIFFSetDefaultCompressionState(TIFF*);
00273 extern  int TIFFSetCompressionScheme(TIFF*, int);
00274 extern  int TIFFSetDefaultCompressionState(TIFF*);
00275 extern  uint32 _TIFFDefaultStripSize(TIFF*, uint32);
00276 extern  void _TIFFDefaultTileSize(TIFF*, uint32*, uint32*);
00277 extern  int _TIFFDataSize(TIFFDataType);
00278 
00279 extern  void _TIFFsetByteArray(void**, void*, uint32);
00280 extern  void _TIFFsetString(char**, char*);
00281 extern  void _TIFFsetShortArray(uint16**, uint16*, uint32);
00282 extern  void _TIFFsetLongArray(uint32**, uint32*, uint32);
00283 extern  void _TIFFsetFloatArray(float**, float*, uint32);
00284 extern  void _TIFFsetDoubleArray(double**, double*, uint32);
00285 
00286 extern  void _TIFFprintAscii(FILE*, const char*);
00287 extern  void _TIFFprintAsciiTag(FILE*, const char*, const char*);
00288 
00289 extern  TIFFErrorHandler _TIFFwarningHandler;
00290 extern  TIFFErrorHandler _TIFFerrorHandler;
00291 extern  TIFFErrorHandlerExt _TIFFwarningHandlerExt;
00292 extern  TIFFErrorHandlerExt _TIFFerrorHandlerExt;
00293 
00294 extern  tdata_t _TIFFCheckMalloc(TIFF*, size_t, size_t, const char*);
00295 extern  tdata_t _TIFFCheckRealloc(TIFF*, tdata_t, size_t, size_t, const char*);
00296 
00297 extern  int TIFFInitDumpMode(TIFF*, int);
00298 #ifdef PACKBITS_SUPPORT
00299 extern  int TIFFInitPackBits(TIFF*, int);
00300 #endif
00301 #ifdef CCITT_SUPPORT
00302 extern  int TIFFInitCCITTRLE(TIFF*, int), TIFFInitCCITTRLEW(TIFF*, int);
00303 extern  int TIFFInitCCITTFax3(TIFF*, int), TIFFInitCCITTFax4(TIFF*, int);
00304 #endif
00305 #ifdef THUNDER_SUPPORT
00306 extern  int TIFFInitThunderScan(TIFF*, int);
00307 #endif
00308 #ifdef NEXT_SUPPORT
00309 extern  int TIFFInitNeXT(TIFF*, int);
00310 #endif
00311 #ifdef LZW_SUPPORT
00312 extern  int TIFFInitLZW(TIFF*, int);
00313 #endif
00314 #ifdef OJPEG_SUPPORT
00315 extern  int TIFFInitOJPEG(TIFF*, int);
00316 #endif
00317 #ifdef JPEG_SUPPORT
00318 extern  int TIFFInitJPEG(TIFF*, int);
00319 #endif
00320 #ifdef JBIG_SUPPORT
00321 extern  int TIFFInitJBIG(TIFF*, int);
00322 #endif
00323 #ifdef ZIP_SUPPORT
00324 extern  int TIFFInitZIP(TIFF*, int);
00325 #endif
00326 #ifdef PIXARLOG_SUPPORT
00327 extern  int TIFFInitPixarLog(TIFF*, int);
00328 #endif
00329 #ifdef LOGLUV_SUPPORT
00330 extern  int TIFFInitSGILog(TIFF*, int);
00331 #endif
00332 #ifdef VMS
00333 extern  const TIFFCodec _TIFFBuiltinCODECS[];
00334 #else
00335 extern  TIFFCodec _TIFFBuiltinCODECS[];
00336 #endif
00337 
00338 #if defined(__cplusplus)
00339 }
00340 #endif
00341 #endif /* _TIFFIOP_ */
00342 
00343 /* vim: set ts=8 sts=8 sw=8 noet: */
00344 /*
00345  * Local Variables:
00346  * mode: c
00347  * c-basic-offset: 8
00348  * fill-column: 78
00349  * End:
00350  */