Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / libtiff / tiffiop.h
1 /* $Id: tiffiop.h,v 1.1 2005-06-17 13:54:52 vp153 Exp $ */
2
3 /*
4  * Copyright (c) 1988-1997 Sam Leffler
5  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and 
8  * its documentation for any purpose is hereby granted without fee, provided
9  * that (i) the above copyright notices and this permission notice appear in
10  * all copies of the software and related documentation, and (ii) the names of
11  * Sam Leffler and Silicon Graphics may not be used in any advertising or
12  * publicity relating to the software without the specific, prior written
13  * permission of Sam Leffler and Silicon Graphics.
14  * 
15  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
18  * 
19  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
24  * OF THIS SOFTWARE.
25  */
26
27 #ifndef _TIFFIOP_
28 #define _TIFFIOP_
29 /*
30  * ``Library-private'' definitions.
31  */
32
33 #include "tif_config.h"
34
35 #if HAVE_FCNTL_H
36 # include <fcntl.h>
37 #endif
38
39 #if HAVE_SYS_TYPES_H
40 # include <sys/types.h>
41 #endif
42
43 #if HAVE_STRING_H
44 # include <string.h>
45 #endif
46
47 #if HAVE_ASSERT_H
48 # include <assert.h>
49 #else
50 # define assert(x) 
51 #endif
52
53 #include "tiffio.h"
54 #include "tif_dir.h"
55
56 typedef double dblparam_t;
57
58 #define GLOBALDATA(TYPE,NAME)   extern TYPE NAME
59
60 #define    streq(a,b)      (strcmp(a,b) == 0)
61
62 #ifndef TRUE
63 #define TRUE    1
64 #define FALSE   0
65 #endif
66
67 typedef struct client_info {
68     struct client_info *next;
69     void      *data;
70     char      *name;
71 } TIFFClientInfoLink;
72
73 /*
74  * Typedefs for ``method pointers'' used internally.
75  */
76 typedef unsigned char tidataval_t;      /* internal image data value type */
77 typedef tidataval_t* tidata_t;          /* reference to internal image data */
78
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
88 struct tiff {
89         char*           tif_name;       /* name of open file */
90         int             tif_fd;         /* open file descriptor */
91         int             tif_mode;       /* open mode (O_*) */
92         uint32          tif_flags;
93 #define TIFF_FILLORDER          0x0003  /* natural bit fill order for machine */
94 #define TIFF_DIRTYHEADER        0x0004  /* header must be written on close */
95 #define TIFF_DIRTYDIRECT        0x0008  /* current directory must be written */
96 #define TIFF_BUFFERSETUP        0x0010  /* data buffers setup */
97 #define TIFF_CODERSETUP         0x0020  /* encoder/decoder setup done */
98 #define TIFF_BEENWRITING        0x0040  /* written 1+ scanlines to file */
99 #define TIFF_SWAB               0x0080  /* byte swap file information */
100 #define TIFF_NOBITREV           0x0100  /* inhibit bit reversal logic */
101 #define TIFF_MYBUFFER           0x0200  /* my raw data buffer; free on close */
102 #define TIFF_ISTILED            0x0400  /* file is tile, not strip- based */
103 #define TIFF_MAPPED             0x0800  /* file is mapped into memory */
104 #define TIFF_POSTENCODE         0x1000  /* need call to postencode routine */
105 #define TIFF_INSUBIFD           0x2000  /* currently writing a subifd */
106 #define TIFF_UPSAMPLED          0x4000  /* library is doing data up-sampling */ 
107 #define TIFF_STRIPCHOP          0x8000  /* enable strip chopping support */
108         toff_t          tif_diroff;     /* file offset of current directory */
109         toff_t          tif_nextdiroff; /* file offset of following directory */
110         toff_t*         tif_dirlist;    /* list of offsets to already seen */
111                                         /* directories to prevent IFD looping */
112         uint16          tif_dirnumber;  /* number of already seen directories */
113         TIFFDirectory   tif_dir;        /* internal rep of current directory */
114         TIFFHeader      tif_header;     /* file's header block */
115         const int*      tif_typeshift;  /* data type shift counts */
116         const long*     tif_typemask;   /* data type masks */
117         uint32          tif_row;        /* current scanline */
118         tdir_t          tif_curdir;     /* current directory (index) */
119         tstrip_t        tif_curstrip;   /* current strip for read/write */
120         toff_t          tif_curoff;     /* current offset for read/write */
121         toff_t          tif_dataoff;    /* current offset for writing dir */
122 /* SubIFD support */
123         uint16          tif_nsubifd;    /* remaining subifds to write */
124         toff_t          tif_subifdoff;  /* offset for patching SubIFD link */
125 /* tiling support */
126         uint32          tif_col;        /* current column (offset by row too) */
127         ttile_t         tif_curtile;    /* current tile for read/write */
128         tsize_t         tif_tilesize;   /* # of bytes in a tile */
129 /* compression scheme hooks */
130         int             tif_decodestatus;
131         TIFFBoolMethod  tif_setupdecode;/* called once before predecode */
132         TIFFPreMethod   tif_predecode;  /* pre- row/strip/tile decoding */
133         TIFFBoolMethod  tif_setupencode;/* called once before preencode */
134         int             tif_encodestatus;
135         TIFFPreMethod   tif_preencode;  /* pre- row/strip/tile encoding */
136         TIFFBoolMethod  tif_postencode; /* post- row/strip/tile encoding */
137         TIFFCodeMethod  tif_decoderow;  /* scanline decoding routine */
138         TIFFCodeMethod  tif_encoderow;  /* scanline encoding routine */
139         TIFFCodeMethod  tif_decodestrip;/* strip decoding routine */
140         TIFFCodeMethod  tif_encodestrip;/* strip encoding routine */
141         TIFFCodeMethod  tif_decodetile; /* tile decoding routine */
142         TIFFCodeMethod  tif_encodetile; /* tile encoding routine */
143         TIFFVoidMethod  tif_close;      /* cleanup-on-close routine */
144         TIFFSeekMethod  tif_seek;       /* position within a strip routine */
145         TIFFVoidMethod  tif_cleanup;    /* cleanup state routine */
146         TIFFStripMethod tif_defstripsize;/* calculate/constrain strip size */
147         TIFFTileMethod  tif_deftilesize;/* calculate/constrain tile size */
148         tidata_t        tif_data;       /* compression scheme private data */
149 /* input/output buffering */
150         tsize_t         tif_scanlinesize;/* # of bytes in a scanline */
151         tsize_t         tif_scanlineskew;/* scanline skew for reading strips */
152         tidata_t        tif_rawdata;    /* raw data buffer */
153         tsize_t         tif_rawdatasize;/* # of bytes in raw data buffer */
154         tidata_t        tif_rawcp;      /* current spot in raw buffer */
155         tsize_t         tif_rawcc;      /* bytes unread from raw buffer */
156 /* memory-mapped file support */
157         tidata_t        tif_base;       /* base of mapped file */
158         toff_t          tif_size;       /* size of mapped file region (bytes) */
159         TIFFMapFileProc tif_mapproc;    /* map file method */
160         TIFFUnmapFileProc tif_unmapproc;/* unmap file method */
161 /* input/output callback methods */
162         thandle_t       tif_clientdata; /* callback parameter */
163         TIFFReadWriteProc tif_readproc; /* read method */
164         TIFFReadWriteProc tif_writeproc;/* write method */
165         TIFFSeekProc    tif_seekproc;   /* lseek method */
166         TIFFCloseProc   tif_closeproc;  /* close method */
167         TIFFSizeProc    tif_sizeproc;   /* filesize method */
168 /* post-decoding support */
169         TIFFPostMethod  tif_postdecode; /* post decoding routine */
170 /* tag support */
171         TIFFFieldInfo** tif_fieldinfo;  /* sorted table of registered tags */
172         int             tif_nfields;    /* # entries in registered tag table */
173         const TIFFFieldInfo *tif_foundfield;/* cached pointer to already found tag */
174         TIFFTagMethods  tif_tagmethods; /* tag get/set/print routines */
175         TIFFClientInfoLink *tif_clientinfo; /* extra client information. */
176 };
177
178 #define isPseudoTag(t)  (t > 0xffff)    /* is tag value normal or pseudo */
179
180 #define isTiled(tif)    (((tif)->tif_flags & TIFF_ISTILED) != 0)
181 #define isMapped(tif)   (((tif)->tif_flags & TIFF_MAPPED) != 0)
182 #define isFillOrder(tif, o)     (((tif)->tif_flags & (o)) != 0)
183 #define isUpSampled(tif)        (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
184 #define TIFFReadFile(tif, buf, size) \
185         ((*(tif)->tif_readproc)((tif)->tif_clientdata,buf,size))
186 #define TIFFWriteFile(tif, buf, size) \
187         ((*(tif)->tif_writeproc)((tif)->tif_clientdata,buf,size))
188 #define TIFFSeekFile(tif, off, whence) \
189         ((*(tif)->tif_seekproc)((tif)->tif_clientdata,(toff_t)(off),whence))
190 #define TIFFCloseFile(tif) \
191         ((*(tif)->tif_closeproc)((tif)->tif_clientdata))
192 #define TIFFGetFileSize(tif) \
193         ((*(tif)->tif_sizeproc)((tif)->tif_clientdata))
194 #define TIFFMapFileContents(tif, paddr, psize) \
195         ((*(tif)->tif_mapproc)((tif)->tif_clientdata,paddr,psize))
196 #define TIFFUnmapFileContents(tif, addr, size) \
197         ((*(tif)->tif_unmapproc)((tif)->tif_clientdata,addr,size))
198
199 /*
200  * Default Read/Seek/Write definitions.
201  */
202 #ifndef ReadOK
203 #define ReadOK(tif, buf, size) \
204         (TIFFReadFile(tif, (tdata_t) buf, (tsize_t)(size)) == (tsize_t)(size))
205 #endif
206 #ifndef SeekOK
207 #define SeekOK(tif, off) \
208         (TIFFSeekFile(tif, (toff_t) off, SEEK_SET) == (toff_t) off)
209 #endif
210 #ifndef WriteOK
211 #define WriteOK(tif, buf, size) \
212         (TIFFWriteFile(tif, (tdata_t) buf, (tsize_t) size) == (tsize_t) size)
213 #endif
214
215 /* NB: the uint32 casts are to silence certain ANSI-C compilers */
216 #define TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y)))
217 #define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3)
218 #define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y))
219
220 #define TIFFmax(A,B) ((A)>(B)?(A):(B))
221 #define TIFFmin(A,B) ((A)<(B)?(A):(B))
222
223 #if defined(__cplusplus)
224 extern "C" {
225 #endif
226 extern  int _TIFFgetMode(const char*, const char*);
227 extern  int _TIFFNoRowEncode(TIFF*, tidata_t, tsize_t, tsample_t);
228 extern  int _TIFFNoStripEncode(TIFF*, tidata_t, tsize_t, tsample_t);
229 extern  int _TIFFNoTileEncode(TIFF*, tidata_t, tsize_t, tsample_t);
230 extern  int _TIFFNoRowDecode(TIFF*, tidata_t, tsize_t, tsample_t);
231 extern  int _TIFFNoStripDecode(TIFF*, tidata_t, tsize_t, tsample_t);
232 extern  int _TIFFNoTileDecode(TIFF*, tidata_t, tsize_t, tsample_t);
233 extern  void _TIFFNoPostDecode(TIFF*, tidata_t, tsize_t);
234 extern  int  _TIFFNoPreCode (TIFF*, tsample_t); 
235 extern  int _TIFFNoSeek(TIFF*, uint32);
236 extern  void _TIFFSwab16BitData(TIFF*, tidata_t, tsize_t);
237 extern  void _TIFFSwab32BitData(TIFF*, tidata_t, tsize_t);
238 extern  void _TIFFSwab64BitData(TIFF*, tidata_t, tsize_t);
239 extern  int TIFFFlushData1(TIFF*);
240 extern  void TIFFFreeDirectory(TIFF*);
241 extern  int TIFFDefaultDirectory(TIFF*);
242 extern  int TIFFSetCompressionScheme(TIFF*, int);
243 extern  int TIFFSetDefaultCompressionState(TIFF*);
244 extern  uint32 _TIFFDefaultStripSize(TIFF*, uint32);
245 extern  void _TIFFDefaultTileSize(TIFF*, uint32*, uint32*);
246
247 extern  void _TIFFsetByteArray(void**, void*, long);
248 extern  void _TIFFsetString(char**, char*);
249 extern  void _TIFFsetShortArray(uint16**, uint16*, long);
250 extern  void _TIFFsetLongArray(uint32**, uint32*, long);
251 extern  void _TIFFsetFloatArray(float**, float*, long);
252 extern  void _TIFFsetDoubleArray(double**, double*, long);
253
254 extern  void _TIFFprintAscii(FILE*, const char*);
255 extern  void _TIFFprintAsciiTag(FILE*, const char*, const char*);
256
257 GLOBALDATA(TIFFErrorHandler,_TIFFwarningHandler);
258 GLOBALDATA(TIFFErrorHandler,_TIFFerrorHandler);
259
260 extern  int TIFFInitDumpMode(TIFF*, int);
261 #ifdef PACKBITS_SUPPORT
262 extern  int TIFFInitPackBits(TIFF*, int);
263 #endif
264 #ifdef CCITT_SUPPORT
265 extern  int TIFFInitCCITTRLE(TIFF*, int), TIFFInitCCITTRLEW(TIFF*, int);
266 extern  int TIFFInitCCITTFax3(TIFF*, int), TIFFInitCCITTFax4(TIFF*, int);
267 #endif
268 #ifdef THUNDER_SUPPORT
269 extern  int TIFFInitThunderScan(TIFF*, int);
270 #endif
271 #ifdef NEXT_SUPPORT
272 extern  int TIFFInitNeXT(TIFF*, int);
273 #endif
274 #ifdef LZW_SUPPORT
275 extern  int TIFFInitLZW(TIFF*, int);
276 #endif
277 #ifdef OJPEG_SUPPORT
278 extern  int TIFFInitOJPEG(TIFF*, int);
279 #endif
280 #ifdef JPEG_SUPPORT
281 extern  int TIFFInitJPEG(TIFF*, int);
282 #endif
283 #ifdef JBIG_SUPPORT
284 extern  int TIFFInitJBIG(TIFF*, int);
285 #endif
286 #ifdef ZIP_SUPPORT
287 extern  int TIFFInitZIP(TIFF*, int);
288 #endif
289 #ifdef PIXARLOG_SUPPORT
290 extern  int TIFFInitPixarLog(TIFF*, int);
291 #endif
292 #ifdef LOGLUV_SUPPORT
293 extern  int TIFFInitSGILog(TIFF*, int);
294 #endif
295 #ifdef VMS
296 extern  const TIFFCodec _TIFFBuiltinCODECS[];
297 #else
298 extern  TIFFCodec _TIFFBuiltinCODECS[];
299 #endif
300
301 #if defined(__cplusplus)
302 }
303 #endif
304 #endif /* _TIFFIOP_ */
305
306 /* vim: set ts=8 sts=8 sw=8 noet: */