1 /* PDFlib GmbH cvsid: $Id: tiffiop.h,v 1.18 2006/08/16 22:11:43 tm 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 "port.h" /* PDFlib GmbH */ 34 #include "tiffconf.h" 35 36 # include <assert.h> 37 38 #include "tiffio.h" 39 #include "tif_dir.h" 40 41 typedef double dblparam_t; 42 43 #define GLOBALDATA(TYPE,NAME) extern TYPE NAME 44 45 #define streq(a,b) (strcmp(a,b) == 0) 46 47 #ifndef TRUE 48 #define TRUE 1 49 #define FALSE 0 50 #endif 51 52 typedef struct client_info { 53 struct client_info *next; 54 void *data; 55 char *name; 56 } TIFFClientInfoLink; 57 58 /* 59 * Typedefs for ``method pointers'' used internally. 60 */ 61 typedef unsigned char tidataval_t; /* internal image data value type */ 62 typedef tidataval_t* tidata_t; /* reference to internal image data */ 63 64 typedef void (*TIFFVoidMethod)(TIFF*); 65 typedef int (*TIFFBoolMethod)(TIFF*); 66 typedef int (*TIFFPreMethod)(TIFF*, tsample_t); 67 typedef int (*TIFFCodeMethod)(TIFF*, tidata_t, tsize_t, tsample_t); 68 typedef int (*TIFFSeekMethod)(TIFF*, uint32); 69 typedef void (*TIFFPostMethod)(TIFF*, tidata_t, tsize_t); 70 typedef uint32 (*TIFFStripMethod)(TIFF*, uint32); 71 typedef void (*TIFFTileMethod)(TIFF*, uint32*, uint32*); 72 73 struct tiff { 74 char* tif_name; /* name of open file */ 75 FILE* tif_fd; /* open file descriptor */ 76 int tif_mode; /* open mode (O_*) */ 77 uint32 tif_flags; 78 #define TIFF_FILLORDER 0x0003 /* natural bit fill order for machine */ 79 #define TIFF_DIRTYHEADER 0x0004 /* header must be written on close */ 80 #define TIFF_DIRTYDIRECT 0x0008 /* current directory must be written */ 81 #define TIFF_BUFFERSETUP 0x0010 /* data buffers setup */ 82 #define TIFF_CODERSETUP 0x0020 /* encoder/decoder setup done */ 83 #define TIFF_BEENWRITING 0x0040 /* written 1+ scanlines to file */ 84 #define TIFF_SWAB 0x0080 /* byte swap file information */ 85 #define TIFF_NOBITREV 0x0100 /* inhibit bit reversal logic */ 86 #define TIFF_MYBUFFER 0x0200 /* my raw data buffer; free on close */ 87 #define TIFF_ISTILED 0x0400 /* file is tile, not strip- based */ 88 #define TIFF_MAPPED 0x0800 /* file is mapped into memory */ 89 #define TIFF_POSTENCODE 0x1000 /* need call to postencode routine */ 90 #define TIFF_INSUBIFD 0x2000 /* currently writing a subifd */ 91 #define TIFF_UPSAMPLED 0x4000 /* library is doing data up-sampling */ 92 #define TIFF_STRIPCHOP 0x8000 /* enable strip chopping support */ 93 #define TIFF_HEADERONLY 0x10000 /* read header only, do not process */ 94 /* the first directory */ 95 toff_t tif_diroff; /* file offset of current directory */ 96 toff_t tif_nextdiroff; /* file offset of following directory */ 97 toff_t* tif_dirlist; /* list of offsets to already seen */ 98 /* directories to prevent IFD looping */ 99 uint16 tif_dirnumber; /* number of already seen directories */ 100 TIFFDirectory tif_dir; /* internal rep of current directory */ 101 TIFFHeader tif_header; /* file's header block */ 102 const int* tif_typeshift; /* data type shift counts */ 103 const long* tif_typemask; /* data type masks */ 104 uint32 tif_row; /* current scanline */ 105 tdir_t tif_curdir; /* current directory (index) */ 106 tstrip_t tif_curstrip; /* current strip for read/write */ 107 toff_t tif_curoff; /* current offset for read/write */ 108 toff_t tif_dataoff; /* current offset for writing dir */ 109 /* SubIFD support */ 110 uint16 tif_nsubifd; /* remaining subifds to write */ 111 toff_t tif_subifdoff; /* offset for patching SubIFD link */ 112 /* tiling support */ 113 uint32 tif_col; /* current column (offset by row too) */ 114 ttile_t tif_curtile; /* current tile for read/write */ 115 tsize_t tif_tilesize; /* # of bytes in a tile */ 116 /* compression scheme hooks */ 117 int tif_decodestatus; 118 TIFFBoolMethod tif_setupdecode;/* called once before predecode */ 119 TIFFPreMethod tif_predecode; /* pre- row/strip/tile decoding */ 120 TIFFBoolMethod tif_setupencode;/* called once before preencode */ 121 int tif_encodestatus; 122 TIFFPreMethod tif_preencode; /* pre- row/strip/tile encoding */ 123 TIFFBoolMethod tif_postencode; /* post- row/strip/tile encoding */ 124 TIFFCodeMethod tif_decoderow; /* scanline decoding routine */ 125 TIFFCodeMethod tif_encoderow; /* scanline encoding routine */ 126 TIFFCodeMethod tif_decodestrip;/* strip decoding routine */ 127 TIFFCodeMethod tif_encodestrip;/* strip encoding routine */ 128 TIFFCodeMethod tif_decodetile; /* tile decoding routine */ 129 TIFFCodeMethod tif_encodetile; /* tile encoding routine */ 130 TIFFVoidMethod tif_close; /* cleanup-on-close routine */ 131 TIFFSeekMethod tif_seek; /* position within a strip routine */ 132 TIFFVoidMethod tif_cleanup; /* cleanup state routine */ 133 TIFFStripMethod tif_defstripsize;/* calculate/constrain strip size */ 134 TIFFTileMethod tif_deftilesize;/* calculate/constrain tile size */ 135 tidata_t tif_data; /* compression scheme private data */ 136 /* input/output buffering */ 137 tsize_t tif_scanlinesize;/* # of bytes in a scanline */ 138 tsize_t tif_scanlineskew;/* scanline skew for reading strips */ 139 tidata_t tif_rawdata; /* raw data buffer */ 140 tsize_t tif_rawdatasize;/* # of bytes in raw data buffer */ 141 tidata_t tif_rawcp; /* current spot in raw buffer */ 142 tsize_t tif_rawcc; /* bytes unread from raw buffer */ 143 /* memory-mapped file support */ 144 tidata_t tif_base; /* base of mapped file */ 145 toff_t tif_size; /* size of mapped file region (bytes) */ 146 TIFFMapFileProc tif_mapproc; /* map file method */ 147 TIFFUnmapFileProc tif_unmapproc;/* unmap file method */ 148 /* input/output callback methods */ 149 void* tif_clientdata; /* callback parameter */ 150 TIFFReadWriteProc tif_readproc; /* read method */ 151 TIFFReadWriteProc tif_writeproc;/* write method */ 152 TIFFSeekProc tif_seekproc; /* lseek method */ 153 TIFFCloseProc tif_closeproc; /* close method */ 154 TIFFSizeProc tif_sizeproc; /* filesize method */ 155 /* post-decoding support */ 156 TIFFPostMethod tif_postdecode; /* post decoding routine */ 157 /* tag support */ 158 TIFFFieldInfo** tif_fieldinfo; /* sorted table of registered tags */ 159 size_t tif_nfields; /* # entries in registered tag table */ 160 /* cached pointer to already found tag */ 161 const TIFFFieldInfo *tif_foundfield; 162 TIFFTagMethods tif_tagmethods; /* tag get/set/print routines */ 163 TIFFClientInfoLink *tif_clientinfo; /* extra client information. */ 164 void* pdflib_opaque; /* for PDFlib memory handling */ 165 TIFFmallocHandler pdflib_malloc; /* for PDFlib memory handling */ 166 TIFFreallocHandler pdflib_realloc; /* for PDFlib memory handling */ 167 TIFFfreeHandler pdflib_free; /* for PDFlib memory handling */ 168 TIFFErrorHandler pdflib_error; /* for PDFlib */ 169 TIFFErrorHandler pdflib_warn; /* for PDFlib */ 170 }; 171 172 #define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */ 173 174 #define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0) 175 #define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0) 176 #define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0) 177 #define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0) 178 #define TIFFReadFile(tif, buf, size) \ 179 ((*(tif)->tif_readproc)((tif)->tif_clientdata,buf,size)) 180 #define TIFFWriteFile(tif, buf, size) \ 181 ((*(tif)->tif_writeproc)((tif)->tif_clientdata,buf,size)) 182 #define TIFFSeekFile(tif, off, whence) \ 183 ((*(tif)->tif_seekproc)((tif)->tif_clientdata,(toff_t)(off),whence)) 184 #define TIFFCloseFile(tif) \ 185 ((*(tif)->tif_closeproc)((tif)->tif_clientdata)) 186 #define TIFFGetFileSize(tif) \ 187 ((*(tif)->tif_sizeproc)((tif)->tif_clientdata)) 188 #define TIFFMapFileContents(tif, paddr, psize) \ 189 ((*(tif)->tif_mapproc)((tif)->tif_clientdata,paddr,psize)) 190 #define TIFFUnmapFileContents(tif, addr, size) \ 191 ((*(tif)->tif_unmapproc)((tif)->tif_clientdata,addr,size)) 192 193 /* 194 * Default Read/Seek/Write definitions. 195 */ 196 #ifndef ReadOK 197 #define ReadOK(tif, buf, size) \ 198 (TIFFReadFile(tif, (tdata_t) buf, (tsize_t)(size)) == (tsize_t)(size)) 199 #endif 200 #ifndef SeekOK 201 #define SeekOK(tif, off) \ 202 (TIFFSeekFile(tif, (toff_t) off, SEEK_SET) != (toff_t) -1) 203 #endif 204 #ifndef WriteOK 205 #define WriteOK(tif, buf, size) \ 206 (TIFFWriteFile(tif, (tdata_t) buf, (tsize_t) size) == (tsize_t) size) 207 #endif 208 209 /* NB: the uint32 casts are to silence certain ANSI-C compilers */ 210 #define TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) 211 #define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) 212 #define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y)) 213 214 #define TIFFmax(A,B) ((A)>(B)?(A):(B)) 215 #define TIFFmin(A,B) ((A)<(B)?(A):(B)) 216 217 #if defined(__cplusplus) 218 extern "C" { 219 #endif 220 extern int PDFlibEncodeError(TIFF*, tidata_t, tsize_t, tsample_t); 221 extern int _TIFFgetMode(const char*, const char*); 222 extern int _TIFFNoRowEncode(TIFF*, tidata_t, tsize_t, tsample_t); 223 extern int _TIFFNoStripEncode(TIFF*, tidata_t, tsize_t, tsample_t); 224 extern int _TIFFNoTileEncode(TIFF*, tidata_t, tsize_t, tsample_t); 225 extern int _TIFFNoRowDecode(TIFF*, tidata_t, tsize_t, tsample_t); 226 extern int _TIFFNoStripDecode(TIFF*, tidata_t, tsize_t, tsample_t); 227 extern int _TIFFNoTileDecode(TIFF*, tidata_t, tsize_t, tsample_t); 228 extern void _TIFFNoPostDecode(TIFF*, tidata_t, tsize_t); 229 extern int _TIFFNoPreCode (TIFF*, tsample_t); 230 extern int _TIFFNoSeek(TIFF*, uint32); 231 extern void _TIFFSwab16BitData(TIFF*, tidata_t, tsize_t); 232 extern void _TIFFSwab24BitData(TIFF*, tidata_t, tsize_t); 233 extern void _TIFFSwab32BitData(TIFF*, tidata_t, tsize_t); 234 extern void _TIFFSwab64BitData(TIFF*, tidata_t, tsize_t); 235 extern int TIFFFlushData1(TIFF*); 236 extern void TIFFFreeDirectory(TIFF*); 237 extern int TIFFDefaultDirectory(TIFF*); 238 extern int TIFFSetCompressionScheme(TIFF*, int); 239 extern int TIFFSetDefaultCompressionState(TIFF*); 240 extern void _TIFFSetDefaultCompressionState(TIFF*); 241 extern uint32 _TIFFDefaultStripSize(TIFF*, uint32); 242 extern void _TIFFDefaultTileSize(TIFF*, uint32*, uint32*); 243 extern int _TIFFDataSize(TIFFDataType); 244 245 extern void _TIFFsetByteArray(TIFF*, void**, void*, uint32); 246 extern void _TIFFsetString(TIFF*, char**, char*); 247 extern void _TIFFsetNString(TIFF*, char**, char*, uint32); 248 extern void _TIFFsetShortArray(TIFF*, uint16**, uint16*, uint32); 249 extern void _TIFFsetLongArray(TIFF*, uint32**, uint32*, uint32); 250 extern void _TIFFsetFloatArray(TIFF*, float**, float*, uint32); 251 extern void _TIFFsetDoubleArray(TIFF*, double**, double*, uint32); 252 253 extern void _TIFFprintAscii(FILE*, const char*); 254 extern void _TIFFprintAsciiTag(FILE*, const char*, const char*); 255 256 GLOBALDATA(TIFFErrorHandler,_TIFFwarningHandler); 257 GLOBALDATA(TIFFErrorHandler,_TIFFerrorHandler); 258 259 extern tdata_t _TIFFCheckMalloc(TIFF*, size_t, size_t, const char*); 260 261 extern int TIFFInitDumpMode(TIFF*, int); 262 #ifdef PACKBITS_SUPPORT 263 extern int TIFFInitPackBits(TIFF*, int); 264 #endif 265 #ifdef CCITT_SUPPORT 266 extern int TIFFInitCCITTRLE(TIFF*, int), TIFFInitCCITTRLEW(TIFF*, int); 267 extern int TIFFInitCCITTFax3(TIFF*, int), TIFFInitCCITTFax4(TIFF*, int); 268 #endif 269 #ifdef THUNDER_SUPPORT 270 extern int TIFFInitThunderScan(TIFF*, int); 271 #endif 272 #ifdef NEXT_SUPPORT 273 extern int TIFFInitNeXT(TIFF*, int); 274 #endif 275 #ifdef LZW_SUPPORT 276 extern int TIFFInitLZW(TIFF*, int); 277 #endif 278 #ifdef OJPEG_SUPPORT 279 extern int TIFFInitOJPEG(TIFF*, int); 280 #endif 281 #ifdef JPEG_SUPPORT 282 extern int TIFFInitJPEG(TIFF*, int); 283 #endif 284 #ifdef JBIG_SUPPORT 285 extern int TIFFInitJBIG(TIFF*, int); 286 #endif 287 #ifdef ZIP_SUPPORT 288 extern int TIFFInitZIP(TIFF*, int); 289 #endif 290 #ifdef PIXARLOG_SUPPORT 291 extern int TIFFInitPixarLog(TIFF*, int); 292 #endif 293 #ifdef LOGLUV_SUPPORT 294 extern int TIFFInitSGILog(TIFF*, int); 295 #endif 296 #ifdef VMS 297 extern const TIFFCodec _TIFFBuiltinCODECS[]; 298 #else 299 extern TIFFCodec _TIFFBuiltinCODECS[]; 300 #endif 301 302 #if defined(__cplusplus) 303 } 304 #endif 305 #endif /* _TIFFIOP_ */ 306 307 /* vim: set ts=8 sts=8 sw=8 noet: */ 308