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