]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/tiff/libtiff/tiffiop.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / tiff / libtiff / tiffiop.h
... / ...
CommitLineData
1
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
26#ifndef _TIFFIOP_
27#define _TIFFIOP_
28/*
29 * ``Library-private'' definitions.
30 */
31
32#include <tif_config.h>
33
34#ifdef HAVE_FCNTL_H
35# include <fcntl.h>
36#endif
37
38#ifdef HAVE_SYS_TYPES_H
39# include <sys/types.h>
40#endif
41
42#ifdef HAVE_STRING_H
43# include <string.h>
44#endif
45
46#ifdef HAVE_ASSERT_H
47# include <assert.h>
48#else
49# define assert(x)
50#endif
51
52#ifdef HAVE_SEARCH_H
53# include <search.h>
54#else
55extern void *lfind(const void *, const void *, size_t *, size_t,
56 int (*)(const void *, const void *));
57#endif
58
59#include "tiffio.h"
60
61#include "tif_dir.h"
62
63#ifndef STRIP_SIZE_DEFAULT
64# define STRIP_SIZE_DEFAULT 8192
65#endif
66
67#define streq(a,b) (strcmp(a,b) == 0)
68
69#ifndef TRUE
70#define TRUE 1
71#define FALSE 0
72#endif
73
74typedef struct client_info {
75 struct client_info *next;
76 void *data;
77 char *name;
78} TIFFClientInfoLink;
79
80/*
81 * Typedefs for ``method pointers'' used internally.
82 * these are depriciated and provided only for backwards compatibility
83 */
84typedef unsigned char tidataval_t; /* internal image data value type */
85typedef tidataval_t* tidata_t; /* reference to internal image data */
86
87typedef void (*TIFFVoidMethod)(TIFF*);
88typedef int (*TIFFBoolMethod)(TIFF*);
89typedef int (*TIFFPreMethod)(TIFF*, uint16);
90typedef int (*TIFFCodeMethod)(TIFF* tif, uint8* buf, tmsize_t size, uint16 sample);
91typedef int (*TIFFSeekMethod)(TIFF*, uint32);
92typedef void (*TIFFPostMethod)(TIFF* tif, uint8* buf, tmsize_t size);
93typedef uint32 (*TIFFStripMethod)(TIFF*, uint32);
94typedef void (*TIFFTileMethod)(TIFF*, uint32*, uint32*);
95
96struct tiff {
97 char* tif_name; /* name of open file */
98 int tif_fd; /* open file descriptor */
99 int tif_mode; /* open mode (O_*) */
100 uint32 tif_flags;
101 #define TIFF_FILLORDER 0x00003 /* natural bit fill order for machine */
102 #define TIFF_DIRTYHEADER 0x00004 /* header must be written on close */
103 #define TIFF_DIRTYDIRECT 0x00008 /* current directory must be written */
104 #define TIFF_BUFFERSETUP 0x00010 /* data buffers setup */
105 #define TIFF_CODERSETUP 0x00020 /* encoder/decoder setup done */
106 #define TIFF_BEENWRITING 0x00040 /* written 1+ scanlines to file */
107 #define TIFF_SWAB 0x00080 /* byte swap file information */
108 #define TIFF_NOBITREV 0x00100 /* inhibit bit reversal logic */
109 #define TIFF_MYBUFFER 0x00200 /* my raw data buffer; free on close */
110 #define TIFF_ISTILED 0x00400 /* file is tile, not strip- based */
111 #define TIFF_MAPPED 0x00800 /* file is mapped into memory */
112 #define TIFF_POSTENCODE 0x01000 /* need call to postencode routine */
113 #define TIFF_INSUBIFD 0x02000 /* currently writing a subifd */
114 #define TIFF_UPSAMPLED 0x04000 /* library is doing data up-sampling */
115 #define TIFF_STRIPCHOP 0x08000 /* enable strip chopping support */
116 #define TIFF_HEADERONLY 0x10000 /* read header only, do not process the first directory */
117 #define TIFF_NOREADRAW 0x20000 /* skip reading of raw uncompressed image data */
118 #define TIFF_INCUSTOMIFD 0x40000 /* currently writing a custom IFD */
119 #define TIFF_BIGTIFF 0x80000 /* read/write bigtiff */
120 #define TIFF_BUF4WRITE 0x100000 /* rawcc bytes are for writing */
121 #define TIFF_DIRTYSTRIP 0x200000 /* stripoffsets/stripbytecount dirty*/
122 #define TIFF_PERSAMPLE 0x400000 /* get/set per sample tags as arrays */
123 #define TIFF_BUFFERMMAP 0x800000 /* read buffer (tif_rawdata) points into mmap() memory */
124 uint64 tif_diroff; /* file offset of current directory */
125 uint64 tif_nextdiroff; /* file offset of following directory */
126 uint64* tif_dirlist; /* list of offsets to already seen directories to prevent IFD looping */
127 uint16 tif_dirlistsize; /* number of entires in offset list */
128 uint16 tif_dirnumber; /* number of already seen directories */
129 TIFFDirectory tif_dir; /* internal rep of current directory */
130 TIFFDirectory tif_customdir; /* custom IFDs are separated from the main ones */
131 union {
132 TIFFHeaderCommon common;
133 TIFFHeaderClassic classic;
134 TIFFHeaderBig big;
135 } tif_header;
136 uint16 tif_header_size; /* file's header block and its length */
137 uint32 tif_row; /* current scanline */
138 uint16 tif_curdir; /* current directory (index) */
139 uint32 tif_curstrip; /* current strip for read/write */
140 uint64 tif_curoff; /* current offset for read/write */
141 uint64 tif_dataoff; /* current offset for writing dir */
142 /* SubIFD support */
143 uint16 tif_nsubifd; /* remaining subifds to write */
144 uint64 tif_subifdoff; /* offset for patching SubIFD link */
145 /* tiling support */
146 uint32 tif_col; /* current column (offset by row too) */
147 uint32 tif_curtile; /* current tile for read/write */
148 tmsize_t tif_tilesize; /* # of bytes in a tile */
149 /* compression scheme hooks */
150 int tif_decodestatus;
151 TIFFBoolMethod tif_fixuptags; /* called in TIFFReadDirectory */
152 TIFFBoolMethod tif_setupdecode; /* called once before predecode */
153 TIFFPreMethod tif_predecode; /* pre- row/strip/tile decoding */
154 TIFFBoolMethod tif_setupencode; /* called once before preencode */
155 int tif_encodestatus;
156 TIFFPreMethod tif_preencode; /* pre- row/strip/tile encoding */
157 TIFFBoolMethod tif_postencode; /* post- row/strip/tile encoding */
158 TIFFCodeMethod tif_decoderow; /* scanline decoding routine */
159 TIFFCodeMethod tif_encoderow; /* scanline encoding routine */
160 TIFFCodeMethod tif_decodestrip; /* strip decoding routine */
161 TIFFCodeMethod tif_encodestrip; /* strip encoding routine */
162 TIFFCodeMethod tif_decodetile; /* tile decoding routine */
163 TIFFCodeMethod tif_encodetile; /* tile encoding routine */
164 TIFFVoidMethod tif_close; /* cleanup-on-close routine */
165 TIFFSeekMethod tif_seek; /* position within a strip routine */
166 TIFFVoidMethod tif_cleanup; /* cleanup state routine */
167 TIFFStripMethod tif_defstripsize; /* calculate/constrain strip size */
168 TIFFTileMethod tif_deftilesize; /* calculate/constrain tile size */
169 uint8* tif_data; /* compression scheme private data */
170 /* input/output buffering */
171 tmsize_t tif_scanlinesize; /* # of bytes in a scanline */
172 tmsize_t tif_scanlineskew; /* scanline skew for reading strips */
173 uint8* tif_rawdata; /* raw data buffer */
174 tmsize_t tif_rawdatasize; /* # of bytes in raw data buffer */
175 tmsize_t tif_rawdataoff; /* rawdata offset within strip */
176 tmsize_t tif_rawdataloaded;/* amount of data in rawdata */
177 uint8* tif_rawcp; /* current spot in raw buffer */
178 tmsize_t tif_rawcc; /* bytes unread from raw buffer */
179 /* memory-mapped file support */
180 uint8* tif_base; /* base of mapped file */
181 tmsize_t tif_size; /* size of mapped file region (bytes, thus tmsize_t) */
182 TIFFMapFileProc tif_mapproc; /* map file method */
183 TIFFUnmapFileProc tif_unmapproc; /* unmap file method */
184 /* input/output callback methods */
185 thandle_t tif_clientdata; /* callback parameter */
186 TIFFReadWriteProc tif_readproc; /* read method */
187 TIFFReadWriteProc tif_writeproc; /* write method */
188 TIFFSeekProc tif_seekproc; /* lseek method */
189 TIFFCloseProc tif_closeproc; /* close method */
190 TIFFSizeProc tif_sizeproc; /* filesize method */
191 /* post-decoding support */
192 TIFFPostMethod tif_postdecode; /* post decoding routine */
193 /* tag support */
194 TIFFField** tif_fields; /* sorted table of registered tags */
195 size_t tif_nfields; /* # entries in registered tag table */
196 const TIFFField* tif_foundfield; /* cached pointer to already found tag */
197 TIFFTagMethods tif_tagmethods; /* tag get/set/print routines */
198 TIFFClientInfoLink* tif_clientinfo; /* extra client information. */
199 /* Backward compatibility stuff. We need these two fields for
200 * setting up an old tag extension scheme. */
201 TIFFFieldArray* tif_fieldscompat;
202 size_t tif_nfieldscompat;
203};
204
205#define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
206
207#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
208#define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0)
209#define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0)
210#define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
211#define TIFFReadFile(tif, buf, size) \
212 ((*(tif)->tif_readproc)((tif)->tif_clientdata,(buf),(size)))
213#define TIFFWriteFile(tif, buf, size) \
214 ((*(tif)->tif_writeproc)((tif)->tif_clientdata,(buf),(size)))
215#define TIFFSeekFile(tif, off, whence) \
216 ((*(tif)->tif_seekproc)((tif)->tif_clientdata,(off),(whence)))
217#define TIFFCloseFile(tif) \
218 ((*(tif)->tif_closeproc)((tif)->tif_clientdata))
219#define TIFFGetFileSize(tif) \
220 ((*(tif)->tif_sizeproc)((tif)->tif_clientdata))
221#define TIFFMapFileContents(tif, paddr, psize) \
222 ((*(tif)->tif_mapproc)((tif)->tif_clientdata,(paddr),(psize)))
223#define TIFFUnmapFileContents(tif, addr, size) \
224 ((*(tif)->tif_unmapproc)((tif)->tif_clientdata,(addr),(size)))
225
226/*
227 * Default Read/Seek/Write definitions.
228 */
229#ifndef ReadOK
230#define ReadOK(tif, buf, size) \
231 (TIFFReadFile((tif),(buf),(size))==(size))
232#endif
233#ifndef SeekOK
234#define SeekOK(tif, off) \
235 (TIFFSeekFile((tif),(off),SEEK_SET)==(off))
236#endif
237#ifndef WriteOK
238#define WriteOK(tif, buf, size) \
239 (TIFFWriteFile((tif),(buf),(size))==(size))
240#endif
241
242/* NB: the uint32 casts are to silence certain ANSI-C compilers */
243#define TIFFhowmany_32(x, y) (((uint32)x < (0xffffffff - (uint32)(y-1))) ? \
244 ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) : \
245 0U)
246#define TIFFhowmany8_32(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3)
247#define TIFFroundup_32(x, y) (TIFFhowmany_32(x,y)*(y))
248#define TIFFhowmany_64(x, y) ((((uint64)(x))+(((uint64)(y))-1))/((uint64)(y)))
249#define TIFFhowmany8_64(x) (((x)&0x07)?((uint64)(x)>>3)+1:(uint64)(x)>>3)
250#define TIFFroundup_64(x, y) (TIFFhowmany_64(x,y)*(y))
251
252/* Safe multiply which returns zero if there is an integer overflow */
253#define TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0)
254
255#define TIFFmax(A,B) ((A)>(B)?(A):(B))
256#define TIFFmin(A,B) ((A)<(B)?(A):(B))
257
258#define TIFFArrayCount(a) (sizeof (a) / sizeof ((a)[0]))
259
260#if defined(__cplusplus)
261extern "C" {
262#endif
263extern int _TIFFgetMode(const char* mode, const char* module);
264extern int _TIFFNoRowEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s);
265extern int _TIFFNoStripEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s);
266extern int _TIFFNoTileEncode(TIFF*, uint8* pp, tmsize_t cc, uint16 s);
267extern int _TIFFNoRowDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s);
268extern int _TIFFNoStripDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s);
269extern int _TIFFNoTileDecode(TIFF*, uint8* pp, tmsize_t cc, uint16 s);
270extern void _TIFFNoPostDecode(TIFF* tif, uint8* buf, tmsize_t cc);
271extern int _TIFFNoPreCode(TIFF* tif, uint16 s);
272extern int _TIFFNoSeek(TIFF* tif, uint32 off);
273extern void _TIFFSwab16BitData(TIFF* tif, uint8* buf, tmsize_t cc);
274extern void _TIFFSwab24BitData(TIFF* tif, uint8* buf, tmsize_t cc);
275extern void _TIFFSwab32BitData(TIFF* tif, uint8* buf, tmsize_t cc);
276extern void _TIFFSwab64BitData(TIFF* tif, uint8* buf, tmsize_t cc);
277extern int TIFFFlushData1(TIFF* tif);
278extern int TIFFDefaultDirectory(TIFF* tif);
279extern void _TIFFSetDefaultCompressionState(TIFF* tif);
280extern int _TIFFRewriteField(TIFF *, uint16, TIFFDataType, tmsize_t, void *);
281extern int TIFFSetCompressionScheme(TIFF* tif, int scheme);
282extern int TIFFSetDefaultCompressionState(TIFF* tif);
283extern uint32 _TIFFDefaultStripSize(TIFF* tif, uint32 s);
284extern void _TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th);
285extern int _TIFFDataSize(TIFFDataType type);
286
287extern void _TIFFsetByteArray(void**, void*, uint32);
288extern void _TIFFsetString(char**, char*);
289extern void _TIFFsetShortArray(uint16**, uint16*, uint32);
290extern void _TIFFsetLongArray(uint32**, uint32*, uint32);
291extern void _TIFFsetFloatArray(float**, float*, uint32);
292extern void _TIFFsetDoubleArray(double**, double*, uint32);
293
294extern void _TIFFprintAscii(FILE*, const char*);
295extern void _TIFFprintAsciiTag(FILE*, const char*, const char*);
296
297extern TIFFErrorHandler _TIFFwarningHandler;
298extern TIFFErrorHandler _TIFFerrorHandler;
299extern TIFFErrorHandlerExt _TIFFwarningHandlerExt;
300extern TIFFErrorHandlerExt _TIFFerrorHandlerExt;
301
302extern uint32 _TIFFMultiply32(TIFF*, uint32, uint32, const char*);
303extern uint64 _TIFFMultiply64(TIFF*, uint64, uint64, const char*);
304extern void* _TIFFCheckMalloc(TIFF*, tmsize_t, tmsize_t, const char*);
305extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*);
306
307extern double _TIFFUInt64ToDouble(uint64);
308extern float _TIFFUInt64ToFloat(uint64);
309
310extern int TIFFInitDumpMode(TIFF*, int);
311#ifdef PACKBITS_SUPPORT
312extern int TIFFInitPackBits(TIFF*, int);
313#endif
314#ifdef CCITT_SUPPORT
315extern int TIFFInitCCITTRLE(TIFF*, int), TIFFInitCCITTRLEW(TIFF*, int);
316extern int TIFFInitCCITTFax3(TIFF*, int), TIFFInitCCITTFax4(TIFF*, int);
317#endif
318#ifdef THUNDER_SUPPORT
319extern int TIFFInitThunderScan(TIFF*, int);
320#endif
321#ifdef NEXT_SUPPORT
322extern int TIFFInitNeXT(TIFF*, int);
323#endif
324#ifdef LZW_SUPPORT
325extern int TIFFInitLZW(TIFF*, int);
326#endif
327#ifdef OJPEG_SUPPORT
328extern int TIFFInitOJPEG(TIFF*, int);
329#endif
330#ifdef JPEG_SUPPORT
331extern int TIFFInitJPEG(TIFF*, int);
332#endif
333#ifdef JBIG_SUPPORT
334extern int TIFFInitJBIG(TIFF*, int);
335#endif
336#ifdef ZIP_SUPPORT
337extern int TIFFInitZIP(TIFF*, int);
338#endif
339#ifdef PIXARLOG_SUPPORT
340extern int TIFFInitPixarLog(TIFF*, int);
341#endif
342#ifdef LOGLUV_SUPPORT
343extern int TIFFInitSGILog(TIFF*, int);
344#endif
345#ifdef LZMA_SUPPORT
346extern int TIFFInitLZMA(TIFF*, int);
347#endif
348#ifdef VMS
349extern const TIFFCodec _TIFFBuiltinCODECS[];
350#else
351extern TIFFCodec _TIFFBuiltinCODECS[];
352#endif
353
354#if defined(__cplusplus)
355}
356#endif
357#endif /* _TIFFIOP_ */
358
359/* vim: set ts=8 sts=8 sw=8 noet: */
360/*
361 * Local Variables:
362 * mode: c
363 * c-basic-offset: 8
364 * fill-column: 78
365 * End:
366 */