1 /* PDFlib GmbH cvsid: $Id: tif_dir.h,v 1.10 2005/12/21 14:12:52 rjs 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 _TIFFDIR_
28 #define	_TIFFDIR_
29 /*
30  * ``Library-private'' Directory-related Definitions.
31  */
32 
33 /*
34  * Internal format of a TIFF directory entry.
35  */
36 typedef	struct {
37 #define	FIELD_SETLONGS	4
38 	/* bit vector of fields that are set */
39 	unsigned long	td_fieldsset[FIELD_SETLONGS];
40 
41 	uint32	td_imagewidth, td_imagelength, td_imagedepth;
42 	uint32	td_tilewidth, td_tilelength, td_tiledepth;
43 	uint32	td_subfiletype;
44 	uint16	td_bitspersample;
45 	uint16	td_sampleformat;
46 	uint16	td_compression;
47 	uint16	td_photometric;
48 	uint16	td_threshholding;
49 	uint16	td_fillorder;
50 	uint16	td_orientation;
51 	uint16	td_samplesperpixel;
52 	uint32	td_rowsperstrip;
53 	uint16	td_minsamplevalue, td_maxsamplevalue;
54 	double	td_sminsamplevalue, td_smaxsamplevalue;
55 	float	td_xresolution, td_yresolution;
56 	uint16	td_resolutionunit;
57 	uint16	td_planarconfig;
58 	float	td_xposition, td_yposition;
59 	uint16	td_pagenumber[2];
60 	uint16*	td_colormap[3];
61 	char*   td_opiimageid;
62 	uint16	td_halftonehints[2];
63 	uint16	td_extrasamples;
64 	uint16*	td_sampleinfo;
65 	double	td_stonits;
66 	tstrip_t td_stripsperimage;
67 	tstrip_t td_nstrips;		/* size of offset & bytecount arrays */
68 	uint32*	td_stripoffset;
69 	uint32*	td_stripbytecount;
70 	int	td_stripbytecountsorted;
71 	/* is the bytecount array sorted ascending? */
72 	uint16	td_nsubifd;
73 	uint32*	td_subifd;
74 	/* YCbCr parameters */
75 	float*	td_ycbcrcoeffs;
76 	uint16	td_ycbcrsubsampling[2];
77 	uint16	td_ycbcrpositioning;
78 	/* Colorimetry parameters */
79 	float*	td_whitepoint;
80 	float*	td_refblackwhite;
81 	uint16*	td_transferfunction[3];
82 	/* CMYK parameters */
83 	uint16	td_inkset;
84 	uint16	td_ninks;
85 	uint16	td_dotrange[2];
86 	int	td_inknameslen;
87 	char*	td_inknames;
88 	/* ICC parameters */
89 	uint32	td_profileLength;
90 	void	*td_profileData;
91 	/* Adobe Photoshop tag handling */
92 	uint32	td_photoshopLength;
93 	void	*td_photoshopData;
94 	/* IPTC parameters */
95 	uint32	td_richtiffiptcLength;
96 	void	*td_richtiffiptcData;
97 	uint32	td_xmlpacketLength;
98 	void	*td_xmlpacketData;
99 	int     td_customValueCount;
100         TIFFTagValue *td_customValues;
101 } TIFFDirectory;
102 
103 /*
104  * Field flags used to indicate fields that have
105  * been set in a directory, and to reference fields
106  * when manipulating a directory.
107  */
108 
109 /*
110  * FIELD_IGNORE is used to signify tags that are to
111  * be processed but otherwise ignored.  This permits
112  * antiquated tags to be quietly read and discarded.
113  * Note that a bit *is* allocated for ignored tags;
114  * this is understood by the directory reading logic
115  * which uses this fact to avoid special-case handling
116  */
117 #define	FIELD_IGNORE			0
118 
119 /* multi-item fields */
120 #define	FIELD_IMAGEDIMENSIONS		1
121 #define FIELD_TILEDIMENSIONS		2
122 #define	FIELD_RESOLUTION		3
123 #define	FIELD_POSITION			4
124 
125 /* single-item fields */
126 #define	FIELD_SUBFILETYPE		5
127 #define	FIELD_BITSPERSAMPLE		6
128 #define	FIELD_COMPRESSION		7
129 #define	FIELD_PHOTOMETRIC		8
130 #define	FIELD_THRESHHOLDING		9
131 #define	FIELD_FILLORDER			10
132 /* unused - was FIELD_DOCUMENTNAME	11 */
133 /* unused - was FIELD_IMAGEDESCRIPTION	12 */
134 /* unused - was FIELD_MAKE		13 */
135 /* unused - was FIELD_MODEL		14 */
136 #define	FIELD_ORIENTATION		15
137 #define	FIELD_SAMPLESPERPIXEL		16
138 #define	FIELD_ROWSPERSTRIP		17
139 #define	FIELD_MINSAMPLEVALUE		18
140 #define	FIELD_MAXSAMPLEVALUE		19
141 #define	FIELD_PLANARCONFIG		20
142 /* unused - was FIELD_PAGENAME		21 */
143 #define	FIELD_RESOLUTIONUNIT		22
144 #define	FIELD_PAGENUMBER		23
145 #define	FIELD_STRIPBYTECOUNTS		24
146 #define	FIELD_STRIPOFFSETS		25
147 #define	FIELD_COLORMAP			26
148 /* unused - was FIELD_ARTIST		27 */
149 /* unused - was FIELD_DATETIME		28 */
150 /* unused - was FIELD_HOSTCOMPUTER	29 */
151 /* unused - was FIELD_SOFTWARE          30 */
152 #define FIELD_OPIIMAGEID		30
153 #define	FIELD_EXTRASAMPLES		31
154 #define FIELD_SAMPLEFORMAT		32
155 #define	FIELD_SMINSAMPLEVALUE		33
156 #define	FIELD_SMAXSAMPLEVALUE		34
157 #define FIELD_IMAGEDEPTH		35
158 #define FIELD_TILEDEPTH			36
159 #define	FIELD_HALFTONEHINTS		37
160 #define FIELD_YCBCRCOEFFICIENTS		38
161 #define FIELD_YCBCRSUBSAMPLING		39
162 #define FIELD_YCBCRPOSITIONING		40
163 #define	FIELD_REFBLACKWHITE		41
164 #define	FIELD_WHITEPOINT		42
165 /* unused - was FIELD_PRIMARYCHROMAS	43 */
166 #define	FIELD_TRANSFERFUNCTION		44
167 #define	FIELD_INKSET			45
168 #define	FIELD_INKNAMES			46
169 #define	FIELD_DOTRANGE			47
170 /* unused - was FIELD_TARGETPRINTER	48 */
171 #define	FIELD_SUBIFD			49
172 #define	FIELD_NUMBEROFINKS		50
173 #define FIELD_ICCPROFILE		51
174 #define FIELD_PHOTOSHOP			52
175 #define FIELD_RICHTIFFIPTC		53
176 #define FIELD_STONITS			54
177 /* unused - was FIELD_IMAGEFULLWIDTH	55 */
178 /* unused - was FIELD_IMAGEFULLLENGTH	56 */
179 /* unused - was FIELD_TEXTUREFORMAT	57 */
180 /* unused - was FIELD_WRAPMODES		58 */
181 /* unused - was FIELD_FOVCOT		59 */
182 /* unused - was FIELD_MATRIX_WORLDTOSCREEN	60 */
183 /* unused - was FIELD_MATRIX_WORLDTOCAMERA	61 */
184 /* unused - was FIELD_COPYRIGHT		62 */
185 #define FIELD_XMLPACKET			63
186 /*      FIELD_CUSTOM (see tiffio.h)     65 */
187 /* end of support for well-known tags; codec-private tags follow */
188 #define	FIELD_CODEC			66	/* base of codec-private tags */
189 
190 
191 /*
192  * Pseudo-tags don't normally need field bits since they
193  * are not written to an output file (by definition).
194  * The library also has express logic to always query a
195  * codec for a pseudo-tag so allocating a field bit for
196  * one is a waste.   If codec wants to promote the notion
197  * of a pseudo-tag being ``set'' or ``unset'' then it can
198  * do using internal state flags without polluting the
199  * field bit space defined for real tags.
200  */
201 #define	FIELD_PSEUDO			0
202 
203 #define	FIELD_LAST			(32*FIELD_SETLONGS-1)
204 
205 #define	TIFFExtractData(tif, type, v) \
206     ((uint32) ((tif)->tif_header.tiff_magic == TIFF_BIGENDIAN ? \
207         ((v) >> (tif)->tif_typeshift[type]) & (tif)->tif_typemask[type] : \
208 	(v) & (tif)->tif_typemask[type]))
209 #define	TIFFInsertData(tif, type, v) \
210     ((uint32) ((tif)->tif_header.tiff_magic == TIFF_BIGENDIAN ? \
211         ((v) & (tif)->tif_typemask[type]) << (tif)->tif_typeshift[type] : \
212 	(v) & (tif)->tif_typemask[type]))
213 
214 
215 #define BITn(n)				(((unsigned long)1L)<<((n)&0x1f))
216 #define BITFIELDn(tif, n)		((tif)->tif_dir.td_fieldsset[(n)/32])
217 #define TIFFFieldSet(tif, field)	(BITFIELDn(tif, field) & BITn(field))
218 #define TIFFSetFieldBit(tif, field)	(BITFIELDn(tif, field) |= BITn(field))
219 #define TIFFClrFieldBit(tif, field)	(BITFIELDn(tif, field) &= ~BITn(field))
220 
221 #define	FieldSet(fields, f)		(fields[(f)/32] & BITn(f))
222 #define	ResetFieldBit(fields, f)	(fields[(f)/32] &= ~BITn(f))
223 
224 #if defined(__cplusplus)
225 extern "C" {
226 #endif
227 extern	void _TIFFSetupFieldInfo(TIFF*);
228 extern	void _TIFFPrintFieldInfo(TIFF*, FILE*);
229 extern	TIFFDataType _TIFFSampleToTagType(TIFF*);
230 extern  const TIFFFieldInfo* _TIFFFindOrRegisterFieldInfo( TIFF *tif,
231 							   ttag_t tag,
232 							   TIFFDataType dt );
233 extern  TIFFFieldInfo* _TIFFCreateAnonFieldInfo( TIFF *tif, ttag_t tag,
234                                                  TIFFDataType dt );
235 
236 #define _TIFFMergeFieldInfo	    TIFFMergeFieldInfo
237 #define _TIFFFindFieldInfo	    TIFFFindFieldInfo
238 #define _TIFFFindFieldInfoByName    TIFFFindFieldInfoByName
239 #define _TIFFFieldWithTag	    TIFFFieldWithTag
240 #define _TIFFFieldWithName	    TIFFFieldWithName
241 
242 #if defined(__cplusplus)
243 }
244 #endif
245 #endif /* _TIFFDIR_ */
246 
247 /* vim: set ts=8 sts=8 sw=8 noet: */
248