]> git.saurik.com Git - wxWidgets.git/blame - src/tiff/tiffio.h
fingers crossed..
[wxWidgets.git] / src / tiff / tiffio.h
CommitLineData
b47c832e
RR
1/* $Header$ */
2
3/*
4 * Copyright (c) 1988-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6 *
94fbea12 7 * Permission to use, copy, modify, distribute, and sell this software and
b47c832e
RR
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.
94fbea12
DW
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 *
b47c832e
RR
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,
94fbea12
DW
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
b47c832e
RR
24 * OF THIS SOFTWARE.
25 */
26
27#ifndef _TIFFIO_
28#define _TIFFIO_
29
30/*
31 * TIFF I/O Library Definitions.
32 */
33#include "tiff.h"
34
35/*
36 * This define can be used in code that requires
37 * compilation-related definitions specific to a
38 * version or versions of the library. Runtime
39 * version checking should be done based on the
40 * string returned by TIFFGetVersion.
41 */
42#define TIFFLIB_VERSION 19970127 /* January 27, 1997 */
43
44/*
45 * TIFF is defined as an incomplete type to hide the
46 * library's internal data structures from clients.
47 */
48typedef struct tiff TIFF;
49
50/*
51 * The following typedefs define the intrinsic size of
52 * data types used in the *exported* interfaces. These
53 * definitions depend on the proper definition of types
54 * in tiff.h. Note also that the varargs interface used
55 * to pass tag types and values uses the types defined in
56 * tiff.h directly.
57 *
58 * NB: ttag_t is unsigned int and not unsigned short because
59 * ANSI C requires that the type before the ellipsis be a
60 * promoted type (i.e. one of int, unsigned int, pointer,
61 * or double) and because we defined pseudo-tags that are
62 * outside the range of legal Aldus-assigned tags.
63 * NB: tsize_t is int32 and not uint32 because some functions
64 * return -1.
65 * NB: toff_t is not off_t for many reasons; TIFFs max out at
66 * 32-bit file offsets being the most important
67 */
68typedef uint32 ttag_t; /* directory tag */
69typedef uint16 tdir_t; /* directory index */
70typedef uint16 tsample_t; /* sample number */
71typedef uint32 tstrip_t; /* strip number */
72typedef uint32 ttile_t; /* tile number */
73typedef int32 tsize_t; /* i/o size in bytes */
74typedef void* tdata_t; /* image data ref */
75typedef int32 toff_t; /* file offset */
76
77#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32))
78#define __WIN32__
79#endif
80#if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows)
81#include <windows.h>
82#ifdef __WIN32__
83DECLARE_HANDLE(thandle_t); /* Win32 file handle */
84#else
85typedef HFILE thandle_t; /* client data handle */
86#endif
87#else
88typedef void* thandle_t; /* client data handle */
89#endif
90
615a9936 91#if defined(__VISAGECPP__)
94fbea12
DW
92#define LINKAGEMODE _Optlink
93#else
94#define LINKAGEMODE
95#endif
96
b47c832e
RR
97#ifndef NULL
98#define NULL 0
99#endif
100
101/*
102 * Flags to pass to TIFFPrintDirectory to control
103 * printing of data structures that are potentially
104 * very large. Bit-or these flags to enable printing
105 * multiple items.
106 */
107#define TIFFPRINT_NONE 0x0 /* no extra info */
108#define TIFFPRINT_STRIPS 0x1 /* strips/tiles info */
109#define TIFFPRINT_CURVES 0x2 /* color/gray response curves */
110#define TIFFPRINT_COLORMAP 0x4 /* colormap */
111#define TIFFPRINT_JPEGQTABLES 0x100 /* JPEG Q matrices */
112#define TIFFPRINT_JPEGACTABLES 0x200 /* JPEG AC tables */
113#define TIFFPRINT_JPEGDCTABLES 0x200 /* JPEG DC tables */
114
115/*
116 * RGBA-style image support.
117 */
118typedef unsigned char TIFFRGBValue; /* 8-bit samples */
119typedef struct _TIFFRGBAImage TIFFRGBAImage;
120/*
121 * The image reading and conversion routines invoke
122 * ``put routines'' to copy/image/whatever tiles of
94fbea12 123 * raw image data. A default set of routines are
b47c832e
RR
124 * provided to convert/copy raw image data to 8-bit
125 * packed ABGR format rasters. Applications can supply
126 * alternate routines that unpack the data into a
127 * different format or, for example, unpack the data
128 * and draw the unpacked raster on the display.
129 */
94fbea12 130typedef void (LINKAGEMODE *tileContigRoutine)
b47c832e
RR
131 (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
132 unsigned char*);
94fbea12 133typedef void (LINKAGEMODE *tileSeparateRoutine)
b47c832e
RR
134 (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32,
135 unsigned char*, unsigned char*, unsigned char*, unsigned char*);
136/*
137 * RGBA-reader state.
138 */
139typedef struct { /* YCbCr->RGB support */
140 TIFFRGBValue* clamptab; /* range clamping table */
141 int* Cr_r_tab;
142 int* Cb_b_tab;
143 int32* Cr_g_tab;
144 int32* Cb_g_tab;
145 float coeffs[3]; /* cached for repeated use */
146} TIFFYCbCrToRGB;
147
148struct _TIFFRGBAImage {
149 TIFF* tif; /* image handle */
150 int stoponerr; /* stop on read error */
151 int isContig; /* data is packed/separate */
152 int alpha; /* type of alpha data present */
153 uint32 width; /* image width */
154 uint32 height; /* image height */
155 uint16 bitspersample; /* image bits/sample */
156 uint16 samplesperpixel; /* image samples/pixel */
157 uint16 orientation; /* image orientation */
158 uint16 photometric; /* image photometric interp */
159 uint16* redcmap; /* colormap pallete */
160 uint16* greencmap;
161 uint16* bluecmap;
162 /* get image data routine */
94fbea12 163 int (LINKAGEMODE *get)(TIFFRGBAImage*, uint32*, uint32, uint32);
b47c832e
RR
164 union {
165 void (*any)(TIFFRGBAImage*);
166 tileContigRoutine contig;
167 tileSeparateRoutine separate;
168 } put; /* put decoded strip/tile */
169 TIFFRGBValue* Map; /* sample mapping array */
170 uint32** BWmap; /* black&white map */
171 uint32** PALmap; /* palette image map */
172 TIFFYCbCrToRGB* ycbcr; /* YCbCr conversion state */
173
174 int row_offset;
175 int col_offset;
176};
177
178/*
179 * Macros for extracting components from the
180 * packed ABGR form returned by TIFFReadRGBAImage.
181 */
182#define TIFFGetR(abgr) ((abgr) & 0xff)
183#define TIFFGetG(abgr) (((abgr) >> 8) & 0xff)
184#define TIFFGetB(abgr) (((abgr) >> 16) & 0xff)
185#define TIFFGetA(abgr) (((abgr) >> 24) & 0xff)
186
187/*
188 * A CODEC is a software package that implements decoding,
189 * encoding, or decoding+encoding of a compression algorithm.
190 * The library provides a collection of builtin codecs.
191 * More codecs may be registered through calls to the library
192 * and/or the builtin implementations may be overridden.
193 */
94fbea12 194typedef int (LINKAGEMODE *TIFFInitMethod)(TIFF*, int);
b47c832e
RR
195typedef struct {
196 char* name;
197 uint16 scheme;
198 TIFFInitMethod init;
199} TIFFCodec;
200
201#include <stdio.h>
202#include <stdarg.h>
203
204#if defined(__cplusplus)
205extern "C" {
206#endif
94fbea12
DW
207typedef void (LINKAGEMODE *TIFFErrorHandler)(const char*, const char*, va_list);
208typedef tsize_t (LINKAGEMODE *TIFFReadWriteProc)(thandle_t, tdata_t, tsize_t);
209typedef toff_t (LINKAGEMODE *TIFFSeekProc)(thandle_t, toff_t, int);
210typedef int (LINKAGEMODE *TIFFCloseProc)(thandle_t);
211typedef toff_t (LINKAGEMODE *TIFFSizeProc)(thandle_t);
212typedef int (LINKAGEMODE *TIFFMapFileProc)(thandle_t, tdata_t*, toff_t*);
213typedef void (LINKAGEMODE *TIFFUnmapFileProc)(thandle_t, tdata_t, toff_t);
214typedef void (LINKAGEMODE *TIFFExtendProc)(TIFF*);
b47c832e
RR
215
216extern const char* TIFFGetVersion(void);
217
218extern const TIFFCodec* TIFFFindCODEC(uint16);
219extern TIFFCodec* TIFFRegisterCODEC(uint16, const char*, TIFFInitMethod);
220extern void TIFFUnRegisterCODEC(TIFFCodec*);
221
222extern tdata_t _TIFFmalloc(tsize_t);
223extern tdata_t _TIFFrealloc(tdata_t, tsize_t);
224extern void _TIFFmemset(tdata_t, int, tsize_t);
225extern void _TIFFmemcpy(tdata_t, const tdata_t, tsize_t);
226extern int _TIFFmemcmp(const tdata_t, const tdata_t, tsize_t);
227extern void _TIFFfree(tdata_t);
228
229extern void TIFFClose(TIFF*);
230extern int TIFFFlush(TIFF*);
231extern int TIFFFlushData(TIFF*);
232extern int TIFFGetField(TIFF*, ttag_t, ...);
233extern int TIFFVGetField(TIFF*, ttag_t, va_list);
234extern int TIFFGetFieldDefaulted(TIFF*, ttag_t, ...);
235extern int TIFFVGetFieldDefaulted(TIFF*, ttag_t, va_list);
236extern int TIFFReadDirectory(TIFF*);
237extern tsize_t TIFFScanlineSize(TIFF*);
238extern tsize_t TIFFRasterScanlineSize(TIFF*);
239extern tsize_t TIFFStripSize(TIFF*);
240extern tsize_t TIFFVStripSize(TIFF*, uint32);
241extern tsize_t TIFFTileRowSize(TIFF*);
242extern tsize_t TIFFTileSize(TIFF*);
243extern tsize_t TIFFVTileSize(TIFF*, uint32);
244extern uint32 TIFFDefaultStripSize(TIFF*, uint32);
245extern void TIFFDefaultTileSize(TIFF*, uint32*, uint32*);
246extern int TIFFFileno(TIFF*);
247extern int TIFFGetMode(TIFF*);
248extern int TIFFIsTiled(TIFF*);
249extern int TIFFIsByteSwapped(TIFF*);
250extern int TIFFIsUpSampled(TIFF*);
251extern int TIFFIsMSB2LSB(TIFF*);
252extern uint32 TIFFCurrentRow(TIFF*);
253extern tdir_t TIFFCurrentDirectory(TIFF*);
254extern tdir_t TIFFNumberOfDirectories(TIFF*);
255extern uint32 TIFFCurrentDirOffset(TIFF*);
256extern tstrip_t TIFFCurrentStrip(TIFF*);
257extern ttile_t TIFFCurrentTile(TIFF*);
258extern int TIFFReadBufferSetup(TIFF*, tdata_t, tsize_t);
259extern int TIFFWriteBufferSetup(TIFF*, tdata_t, tsize_t);
260extern int TIFFLastDirectory(TIFF*);
261extern int TIFFSetDirectory(TIFF*, tdir_t);
262extern int TIFFSetSubDirectory(TIFF*, uint32);
263extern int TIFFUnlinkDirectory(TIFF*, tdir_t);
264extern int TIFFSetField(TIFF*, ttag_t, ...);
265extern int TIFFVSetField(TIFF*, ttag_t, va_list);
266extern int TIFFWriteDirectory(TIFF *);
267extern int TIFFReassignTagToIgnore(enum TIFFIgnoreSense, int);
268
269#if defined(c_plusplus) || defined(__cplusplus)
270extern void TIFFPrintDirectory(TIFF*, FILE*, long = 0);
271extern int TIFFReadScanline(TIFF*, tdata_t, uint32, tsample_t = 0);
272extern int TIFFWriteScanline(TIFF*, tdata_t, uint32, tsample_t = 0);
273extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int = 0);
274#else
275extern void TIFFPrintDirectory(TIFF*, FILE*, long);
276extern int TIFFReadScanline(TIFF*, tdata_t, uint32, tsample_t);
277extern int TIFFWriteScanline(TIFF*, tdata_t, uint32, tsample_t);
278extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int);
279#endif
280
281extern int TIFFReadRGBAStrip(TIFF*, tstrip_t, uint32 * );
282extern int TIFFReadRGBATile(TIFF*, uint32, uint32, uint32 * );
283extern int TIFFRGBAImageOK(TIFF*, char [1024]);
284extern int TIFFRGBAImageBegin(TIFFRGBAImage*, TIFF*, int, char [1024]);
285extern int TIFFRGBAImageGet(TIFFRGBAImage*, uint32*, uint32, uint32);
286extern void TIFFRGBAImageEnd(TIFFRGBAImage*);
287extern TIFF* TIFFOpen(const char*, const char*);
288extern TIFF* TIFFFdOpen(int, const char*, const char*);
289extern TIFF* TIFFClientOpen(const char*, const char*,
290 thandle_t,
291 TIFFReadWriteProc, TIFFReadWriteProc,
292 TIFFSeekProc, TIFFCloseProc,
293 TIFFSizeProc,
294 TIFFMapFileProc, TIFFUnmapFileProc);
295extern const char* TIFFFileName(TIFF*);
296extern void TIFFError(const char*, const char*, ...);
297extern void TIFFWarning(const char*, const char*, ...);
298extern TIFFErrorHandler TIFFSetErrorHandler(TIFFErrorHandler);
299extern TIFFErrorHandler TIFFSetWarningHandler(TIFFErrorHandler);
300extern TIFFExtendProc TIFFSetTagExtender(TIFFExtendProc);
301extern ttile_t TIFFComputeTile(TIFF*, uint32, uint32, uint32, tsample_t);
302extern int TIFFCheckTile(TIFF*, uint32, uint32, uint32, tsample_t);
303extern ttile_t TIFFNumberOfTiles(TIFF*);
304extern tsize_t TIFFReadTile(TIFF*,
305 tdata_t, uint32, uint32, uint32, tsample_t);
306extern tsize_t TIFFWriteTile(TIFF*,
307 tdata_t, uint32, uint32, uint32, tsample_t);
308extern tstrip_t TIFFComputeStrip(TIFF*, uint32, tsample_t);
309extern tstrip_t TIFFNumberOfStrips(TIFF*);
310extern tsize_t TIFFReadEncodedStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
311extern tsize_t TIFFReadRawStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
312extern tsize_t TIFFReadEncodedTile(TIFF*, ttile_t, tdata_t, tsize_t);
313extern tsize_t TIFFReadRawTile(TIFF*, ttile_t, tdata_t, tsize_t);
314extern tsize_t TIFFWriteEncodedStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
315extern tsize_t TIFFWriteRawStrip(TIFF*, tstrip_t, tdata_t, tsize_t);
316extern tsize_t TIFFWriteEncodedTile(TIFF*, ttile_t, tdata_t, tsize_t);
317extern tsize_t TIFFWriteRawTile(TIFF*, ttile_t, tdata_t, tsize_t);
318extern void TIFFSetWriteOffset(TIFF*, toff_t);
319extern void TIFFSwabShort(uint16*);
320extern void TIFFSwabLong(uint32*);
321extern void TIFFSwabDouble(double*);
322extern void TIFFSwabArrayOfShort(uint16*, unsigned long);
323extern void TIFFSwabArrayOfLong(uint32*, unsigned long);
324extern void TIFFSwabArrayOfDouble(double*, unsigned long);
325extern void TIFFReverseBits(unsigned char *, unsigned long);
326extern const unsigned char* TIFFGetBitRevTable(int);
327#if defined(__cplusplus)
328}
329#endif
330#endif /* _TIFFIO_ */