1 /* $Header: /usr/people/sam/tiff/libtiff/RCS/tiffioP.h,v 1.28 92/03/06 11:59:52 sam Exp $ */ 2 3 /* 4 * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler 5 * Copyright (c) 1991, 1992 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 #include "tiffcompat.h" 33 #include "tiff.h" 34 35 /* 36 * Internal format of a TIFF directory entry. 37 */ 38 typedef struct { 39 u_long td_fieldsset[2]; /* bit vector of fields that are set */ 40 41 u_long td_imagewidth, td_imagelength, td_imagedepth; 42 u_long td_tilewidth, td_tilelength, td_tiledepth; 43 u_short td_subfiletype; 44 u_short td_bitspersample; 45 u_short td_sampleformat; 46 u_short td_compression; 47 u_short td_photometric; 48 u_short td_threshholding; 49 u_short td_fillorder; 50 u_short td_orientation; 51 u_short td_samplesperpixel; 52 u_short td_predictor; 53 u_long td_rowsperstrip; 54 u_long td_minsamplevalue, td_maxsamplevalue; /* XXX */ 55 float td_xresolution, td_yresolution; 56 u_short td_resolutionunit; 57 u_short td_planarconfig; 58 float td_xposition, td_yposition; 59 u_long td_group3options; 60 u_long td_group4options; 61 u_short td_pagenumber[2]; 62 u_short td_matteing; 63 u_short td_cleanfaxdata; 64 u_short td_badfaxrun; 65 u_long td_badfaxlines; 66 u_short *td_colormap[3]; 67 u_short td_halftonehints[2]; 68 char *td_documentname; 69 char *td_artist; 70 char *td_datetime; 71 char *td_hostcomputer; 72 char *td_imagedescription; 73 char *td_make; 74 char *td_model; 75 char *td_software; 76 char *td_pagename; 77 u_long td_stripsperimage; 78 u_long td_nstrips; /* size of offset & bytecount arrays */ 79 u_long *td_stripoffset; 80 u_long *td_stripbytecount; 81 #ifdef YCBCR_SUPPORT 82 float *td_ycbcrcoeffs; 83 u_short td_ycbcrsubsampling[2]; 84 u_short td_ycbcrpositioning; 85 #endif 86 #ifdef JPEG_SUPPORT 87 u_short td_jpegproc; 88 u_short td_jpegrestartinterval; 89 u_char **td_qtab; 90 u_char **td_dctab; 91 u_char **td_actab; 92 #endif 93 #ifdef COLORIMETRY_SUPPORT 94 float *td_whitepoint; 95 float *td_primarychromas; 96 float *td_refblackwhite; 97 u_short *td_transferfunction[4]; 98 #endif 99 #ifdef CMYK_SUPPORT 100 u_short td_inkset; 101 u_short td_dotrange[2]; 102 char *td_inknames; 103 char *td_targetprinter; 104 #endif 105 } TIFFDirectory; 106 107 /* 108 * Field flags used to indicate fields that have 109 * been set in a directory, and to reference fields 110 * when manipulating a directory. 111 */ 112 /* multi-entry fields */ 113 #define FIELD_IMAGEDIMENSIONS 0 114 #define FIELD_TILEDIMENSIONS 1 115 #define FIELD_CELLDIMENSIONS 2 /* XXX */ 116 #define FIELD_RESOLUTION 3 117 #define FIELD_POSITION 4 118 /* single-entry fields */ 119 #define FIELD_SUBFILETYPE 5 120 #define FIELD_BITSPERSAMPLE 6 121 #define FIELD_COMPRESSION 7 122 #define FIELD_PHOTOMETRIC 8 123 #define FIELD_THRESHHOLDING 9 124 #define FIELD_FILLORDER 10 125 #define FIELD_DOCUMENTNAME 11 126 #define FIELD_IMAGEDESCRIPTION 12 127 #define FIELD_MAKE 13 128 #define FIELD_MODEL 14 129 #define FIELD_ORIENTATION 15 130 #define FIELD_SAMPLESPERPIXEL 16 131 #define FIELD_ROWSPERSTRIP 17 132 #define FIELD_MINSAMPLEVALUE 18 133 #define FIELD_MAXSAMPLEVALUE 19 134 #define FIELD_PLANARCONFIG 20 135 #define FIELD_PAGENAME 21 136 #define FIELD_GROUP3OPTIONS 22 137 #define FIELD_GROUP4OPTIONS 23 138 #define FIELD_RESOLUTIONUNIT 24 139 #define FIELD_PAGENUMBER 25 140 #define FIELD_STRIPBYTECOUNTS 26 141 #define FIELD_STRIPOFFSETS 27 142 #define FIELD_COLORMAP 28 143 #define FIELD_PREDICTOR 29 144 #define FIELD_ARTIST 30 145 #define FIELD_DATETIME 31 146 #define FIELD_HOSTCOMPUTER 32 147 #define FIELD_SOFTWARE 33 148 #define FIELD_MATTEING 34 149 #define FIELD_BADFAXLINES 35 150 #define FIELD_CLEANFAXDATA 36 151 #define FIELD_BADFAXRUN 37 152 #define FIELD_SAMPLEFORMAT 38 153 #define FIELD_SMINSAMPLEVALUE 39 154 #define FIELD_SMAXSAMPLEVALUE 40 155 #define FIELD_IMAGEDEPTH 41 156 #define FIELD_TILEDEPTH 42 157 #define FIELD_HALFTONEHINTS 43 158 #ifdef YCBCR_SUPPORT 159 #define FIELD_YCBCRCOEFFICIENTS 44 160 #define FIELD_YCBCRSUBSAMPLING 45 161 #define FIELD_YCBCRPOSITIONING 46 162 #endif 163 #ifdef JPEG_SUPPORT 164 #define FIELD_JPEGPROC 47 165 #define FIELD_JPEGRESTARTINTERVAL 48 166 #define FIELD_JPEGQTABLES 49 167 #define FIELD_JPEGDCTABLES 50 168 #define FIELD_JPEGACTABLES 51 169 #endif 170 #ifdef COLORIMETRY_SUPPORT 171 #define FIELD_REFBLACKWHITE 52 172 #define FIELD_WHITEPOINT 53 173 #define FIELD_PRIMARYCHROMAS 54 174 #define FIELD_TRANSFERFUNCTION 55 175 #endif 176 #ifdef CMYK_SUPPORT 177 #define FIELD_INKSET 56 178 #define FIELD_INKNAMES 57 179 #define FIELD_DOTRANGE 58 180 #define FIELD_TARGETPRINTER 59 181 #endif 182 #define FIELD_LAST 59 183 184 #define TIFFExtractData(tif, type, v) \ 185 ((tif)->tif_header.tiff_magic == TIFF_BIGENDIAN ? \ 186 ((v) >> (tif)->tif_typeshift[type]) & (tif)->tif_typemask[type] : \ 187 (v) & (tif)->tif_typemask[type]) 188 #define TIFFInsertData(tif, type, v) \ 189 ((tif)->tif_header.tiff_magic == TIFF_BIGENDIAN ? \ 190 ((v) & (tif)->tif_typemask[type]) << (tif)->tif_typeshift[type] : \ 191 (v) & (tif)->tif_typemask[type]) 192 193 typedef struct { 194 u_short field_tag; /* field's tag */ 195 short field_readcount; /* read count (-1 for unknown) */ 196 short field_writecount; /* write count (-1 for unknown) */ 197 TIFFDataType field_type; /* type of associated data */ 198 u_short field_bit; /* bit in fieldsset bit vector */ 199 u_short field_oktochange; /* if true, can change while writing */ 200 char *field_name; /* ASCII name */ 201 } TIFFFieldInfo; 202 203 #define FIELD_IGNORE ((u_short)-1) /* tags processed but ignored */ 204 205 #define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */ 206 #define TIFF_VARIABLE -1 /* marker for variable length tags */ 207 #define TIFF_SPP -2 /* marker for SamplesPerPixel tags */ 208 209 extern const TIFFFieldInfo tiffFieldInfo[];/* table of field descriptors */ 210 extern const int tiffDataWidth[]; /* table of tag datatype widths */ 211 212 #define BITn(n) (((unsigned)1L)<<((n)&0x1f)) 213 #define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n)/32]) 214 #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field)) 215 #define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field)) 216 #define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field)) 217 218 #define FieldSet(fields, f) (fields[(f)/32] & BITn(f)) 219 #define ResetFieldBit(fields, f) (fields[(f)/32] &= ~BITn(f)) 220 221 struct tiff { 222 char *tif_name; /* name of open file */ 223 short tif_fd; /* open file descriptor */ 224 short tif_mode; /* open mode (O_*) */ 225 char tif_fillorder; /* natural bit fill order for machine */ 226 char tif_options; /* compression-specific options */ 227 short tif_flags; 228 #define TIFF_DIRTYHEADER 0x1 /* header must be written on close */ 229 #define TIFF_DIRTYDIRECT 0x2 /* current directory must be written */ 230 #define TIFF_BUFFERSETUP 0x4 /* data buffers setup */ 231 #define TIFF_BEENWRITING 0x8 /* written 1+ scanlines to file */ 232 #define TIFF_SWAB 0x10 /* byte swap file information */ 233 #define TIFF_NOBITREV 0x20 /* inhibit bit reversal logic */ 234 #define TIFF_MYBUFFER 0x40 /* my raw data buffer; free on close */ 235 #define TIFF_ISTILED 0x80 /* file is tile, not strip- based */ 236 #define TIFF_MAPPED 0x100 /* file is mapped into memory */ 237 #define TIFF_POSTENCODE 0x200 /* need call to postencode routine */ 238 long tif_diroff; /* file offset of current directory */ 239 long tif_nextdiroff; /* file offset of following directory */ 240 TIFFDirectory tif_dir; /* internal rep of current directory */ 241 TIFFHeader tif_header; /* file's header block */ 242 int const *tif_typeshift; /* data type shift counts */ 243 long const *tif_typemask; /* data type masks */ 244 long tif_row; /* current scanline */ 245 int tif_curdir; /* current directory (index) */ 246 int tif_curstrip; /* current strip for read/write */ 247 long tif_curoff; /* current offset for read/write */ 248 /* tiling support */ 249 long tif_col; /* current column (offset by row too) */ 250 int tif_curtile; /* current tile for read/write */ 251 long tif_tilesize; /* # of bytes in a tile */ 252 /* compression scheme hooks */ 253 int (*tif_predecode)(); /* pre row/strip/tile decoding */ 254 int (*tif_preencode)(); /* pre row/strip/tile encoding */ 255 int (*tif_postencode)(); /* post row/strip/tile encoding */ 256 int (*tif_decoderow)(); /* scanline decoding routine */ 257 int (*tif_encoderow)(); /* scanline encoding routine */ 258 int (*tif_decodestrip)(); /* strip decoding routine */ 259 int (*tif_encodestrip)(); /* strip encoding routine */ 260 int (*tif_decodetile)(); /* tile decoding routine */ 261 int (*tif_encodetile)(); /* tile encoding routine */ 262 int (*tif_close)(); /* cleanup-on-close routine */ 263 int (*tif_seek)(); /* position within a strip routine */ 264 int (*tif_cleanup)(); /* routine called to cleanup state */ 265 char *tif_data; /* compression scheme private data */ 266 /* input/output buffering */ 267 int tif_scanlinesize; /* # of bytes in a scanline */ 268 int tif_scanlineskew; /* scanline skew for reading strips */ 269 char *tif_rawdata; /* raw data buffer */ 270 long tif_rawdatasize; /* # of bytes in raw data buffer */ 271 char *tif_rawcp; /* current spot in raw buffer */ 272 long tif_rawcc; /* bytes unread from raw buffer */ 273 #ifdef MMAP_SUPPORT 274 char* tif_base; /* base of mapped file */ 275 long tif_size; /* size of mapped file region (bytes) */ 276 #endif 277 }; 278 279 #define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0) 280 #ifdef MMAP_SUPPORT 281 #define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0) 282 #else 283 #define isMapped(tif) 0 /* force dead code */ 284 #endif 285 286 /* generic option bit names */ 287 #define TIFF_OPT0 0x1 288 #define TIFF_OPT1 0x2 289 #define TIFF_OPT2 0x4 290 #define TIFF_OPT3 0x8 291 #define TIFF_OPT4 0x10 292 #define TIFF_OPT5 0x20 293 #define TIFF_OPT6 0x40 294 #define TIFF_OPT7 0x80 295 296 #include "tiffio.h" 297 298 /* NB: the u_int casts are to silence certain ANSI-C compilers */ 299 #ifdef howmany 300 #undef howmany 301 #endif 302 #define howmany(x, y) ((((u_int)(x))+(((u_int)(y))-1))/((u_int)(y))) 303 #ifdef roundup 304 #undef roundup 305 #endif 306 #define roundup(x, y) (howmany(x,y)*((u_int)(y))) 307 308 #if defined(c_plusplus) || defined(__cplusplus) || defined(__STDC__) || USE_PROTOTYPES 309 #if defined(__cplusplus) 310 extern "C" { 311 #endif 312 extern TIFFFieldInfo const *TIFFFindFieldInfo(u_short, TIFFDataType); 313 extern TIFFFieldInfo const *TIFFFieldWithTag(u_short); 314 extern int _TIFFgetfield(TIFFDirectory*, int, ...); 315 extern int TIFFNoRowEncode(TIFF*, u_char*, int, u_int); 316 extern int TIFFNoStripEncode(TIFF*, u_char*, int, u_int); 317 extern int TIFFNoTileEncode(TIFF*, u_char*, int, u_int); 318 extern int TIFFNoRowDecode(TIFF*, u_char*, int, u_int); 319 extern int TIFFNoStripDecode(TIFF*, u_char*, int, u_int); 320 extern int TIFFNoTileDecode(TIFF*, u_char*, int, u_int); 321 #if defined(__cplusplus) 322 } 323 #endif 324 #else 325 extern TIFFFieldInfo const *TIFFFindFieldInfo(); 326 extern TIFFFieldInfo const *TIFFFieldWithTag(); 327 extern int _TIFFgetfield(); 328 extern int TIFFNoRowEncode(); 329 extern int TIFFNoStripEncode(); 330 extern int TIFFNoTileEncode(); 331 extern int TIFFNoRowDecode(); 332 extern int TIFFNoStripDecode(); 333 extern int TIFFNoTileDecode(); 334 #endif 335 #endif /* _TIFFIOP_ */ 336