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