ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/tiffio.h
Revision: 3.1
Committed: Sat Feb 22 02:07:22 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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