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