PageRenderTime 80ms CodeModel.GetById 23ms app.highlight 49ms RepoModel.GetById 1ms app.codeStats 1ms

/src/FreeImage/Source/LibTIFF/tiffiop.h

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