Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/libtiff-src/tif_dir.h

raw
1 /*
2 * Copyright (c) 1988-1997 Sam Leffler
3 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
12 *
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25 #ifndef _TIFFDIR_
26 #define _TIFFDIR_
27
28 #include "tiff.h"
29 #include "tiffio.h"
30
31 /*
32 * ``Library-private'' Directory-related Definitions.
33 */
34
35 typedef struct
36 {
37 const TIFFField *info;
38 int count;
39 void *value;
40 } TIFFTagValue;
41
42 /*
43 * TIFF Image File Directories are comprised of a table of field
44 * descriptors of the form shown below. The table is sorted in
45 * ascending order by tag. The values associated with each entry are
46 * disjoint and may appear anywhere in the file (so long as they are
47 * placed on a word boundary).
48 *
49 * If the value is 4 bytes or less, in ClassicTIFF, or 8 bytes or less in
50 * BigTIFF, then it is placed in the offset field to save space. If so,
51 * it is left-justified in the offset field.
52 */
53 typedef struct
54 {
55 uint16_t tdir_tag; /* see below */
56 uint16_t tdir_type; /* data type; see below */
57 uint64_t tdir_count; /* number of items; length in spec */
58 union
59 {
60 uint16_t toff_short;
61 uint32_t toff_long;
62 uint64_t toff_long8;
63 } tdir_offset; /* either offset or the data itself if fits */
64 uint8_t tdir_ignore; /* flag status to ignore tag when parsing tags in
65 tif_dirread.c */
66 } TIFFDirEntry;
67
68 typedef struct
69 {
70 uint64_t offset;
71 uint64_t length;
72 } TIFFEntryOffsetAndLength; /* auxiliary for evaluating size of IFD data */
73
74 /*
75 * Internal format of a TIFF directory entry.
76 */
77 typedef struct
78 {
79 #define FIELDSET_ITEMS 4
80 /* bit vector of fields that are set */
81 uint32_t td_fieldsset[FIELDSET_ITEMS];
82
83 uint32_t td_imagewidth, td_imagelength, td_imagedepth;
84 uint32_t td_tilewidth, td_tilelength, td_tiledepth;
85 uint32_t td_subfiletype;
86 uint16_t td_bitspersample;
87 uint16_t td_sampleformat;
88 uint16_t td_compression;
89 uint16_t td_photometric;
90 uint16_t td_threshholding;
91 uint16_t td_fillorder;
92 uint16_t td_orientation;
93 uint16_t td_samplesperpixel;
94 uint32_t td_rowsperstrip;
95 uint16_t td_minsamplevalue, td_maxsamplevalue;
96 double *td_sminsamplevalue;
97 double *td_smaxsamplevalue;
98 float td_xresolution, td_yresolution;
99 uint16_t td_resolutionunit;
100 uint16_t td_planarconfig;
101 float td_xposition, td_yposition;
102 uint16_t td_pagenumber[2];
103 uint16_t *td_colormap[3];
104 uint16_t td_halftonehints[2];
105 uint16_t td_extrasamples;
106 uint16_t *td_sampleinfo;
107 /* even though the name is misleading, td_stripsperimage is the number
108 * of striles (=strips or tiles) per plane, and td_nstrips the total
109 * number of striles */
110 uint32_t td_stripsperimage;
111 uint32_t td_nstrips; /* size of offset & bytecount arrays */
112 uint64_t
113 *td_stripoffset_p; /* should be accessed with TIFFGetStrileOffset */
114 uint64_t *td_stripbytecount_p; /* should be accessed with
115 TIFFGetStrileByteCount */
116 uint32_t
117 td_stripoffsetbyteallocsize; /* number of elements currently allocated
118 for td_stripoffset/td_stripbytecount.
119 Only used if TIFF_LAZYSTRILELOAD is set
120 */
121 #ifdef STRIPBYTECOUNTSORTED_UNUSED
122 int td_stripbytecountsorted; /* is the bytecount array sorted ascending? */
123 #endif
124 /* Be aware that the parameters of td_stripoffset_entry and
125 * td_stripbytecount_entry are swapped but tdir_offset is not
126 * and has to be swapped when used. */
127 TIFFDirEntry td_stripoffset_entry; /* for deferred loading */
128 TIFFDirEntry td_stripbytecount_entry; /* for deferred loading */
129 uint16_t td_nsubifd;
130 uint64_t *td_subifd;
131 /* YCbCr parameters */
132 uint16_t td_ycbcrsubsampling[2];
133 uint16_t td_ycbcrpositioning;
134 /* Colorimetry parameters */
135 uint16_t *td_transferfunction[3];
136 float *td_refblackwhite;
137 /* CMYK parameters */
138 int td_inknameslen;
139 char *td_inknames;
140 uint16_t td_numberofinks; /* number of inks in InkNames string */
141
142 int td_customValueCount;
143 TIFFTagValue *td_customValues;
144
145 unsigned char
146 td_deferstrilearraywriting; /* see TIFFDeferStrileArrayWriting() */
147
148 unsigned char
149 td_iswrittentofile; /* indicates if current IFD is present on file */
150
151 /* LibTIFF writes all data that does not fit into the IFD entries directly
152 * after the IFD tag entry part. When reading, only the IFD data directly
153 * and continuously behind the IFD tags is taken into account for the IFD
154 * data size.*/
155 uint64_t td_dirdatasize_write; /* auxiliary for evaluating size of IFD data
156 to be written */
157 uint64_t td_dirdatasize_read; /* auxiliary for evaluating size of IFD data
158 read from file */
159 uint32_t td_dirdatasize_Noffsets; /* auxiliary counter for
160 tif_dir.td_dirdatasize_offsets array */
161 TIFFEntryOffsetAndLength
162 *td_dirdatasize_offsets; /* auxiliary array for all offsets of IFD tag
163 entries with data outside the IFD tag
164 entries. */
165 } TIFFDirectory;
166
167 /*
168 * Field flags used to indicate fields that have been set in a directory, and
169 * to reference fields when manipulating a directory.
170 */
171
172 /*
173 * FIELD_IGNORE is used to signify tags that are to be processed but otherwise
174 * ignored. This permits antiquated tags to be quietly read and discarded.
175 * Note that a bit *is* allocated for ignored tags; this is understood by the
176 * directory reading logic which uses this fact to avoid special-case handling
177 */
178 #define FIELD_IGNORE 0
179
180 /* multi-item fields */
181 #define FIELD_IMAGEDIMENSIONS 1
182 #define FIELD_TILEDIMENSIONS 2
183 #define FIELD_RESOLUTION 3
184 #define FIELD_POSITION 4
185
186 /* single-item fields */
187 #define FIELD_SUBFILETYPE 5
188 #define FIELD_BITSPERSAMPLE 6
189 #define FIELD_COMPRESSION 7
190 #define FIELD_PHOTOMETRIC 8
191 #define FIELD_THRESHHOLDING 9
192 #define FIELD_FILLORDER 10
193 #define FIELD_ORIENTATION 15
194 #define FIELD_SAMPLESPERPIXEL 16
195 #define FIELD_ROWSPERSTRIP 17
196 #define FIELD_MINSAMPLEVALUE 18
197 #define FIELD_MAXSAMPLEVALUE 19
198 #define FIELD_PLANARCONFIG 20
199 #define FIELD_RESOLUTIONUNIT 22
200 #define FIELD_PAGENUMBER 23
201 #define FIELD_STRIPBYTECOUNTS 24
202 #define FIELD_STRIPOFFSETS 25
203 #define FIELD_COLORMAP 26
204 #define FIELD_EXTRASAMPLES 31
205 #define FIELD_SAMPLEFORMAT 32
206 #define FIELD_SMINSAMPLEVALUE 33
207 #define FIELD_SMAXSAMPLEVALUE 34
208 #define FIELD_IMAGEDEPTH 35
209 #define FIELD_TILEDEPTH 36
210 #define FIELD_HALFTONEHINTS 37
211 #define FIELD_YCBCRSUBSAMPLING 39
212 #define FIELD_YCBCRPOSITIONING 40
213 #define FIELD_REFBLACKWHITE 41
214 #define FIELD_TRANSFERFUNCTION 44
215 #define FIELD_INKNAMES 46
216 #define FIELD_SUBIFD 49
217 #define FIELD_NUMBEROFINKS 50
218 /* FIELD_CUSTOM (see tiffio.h) 65 */
219 /* end of support for well-known tags; codec-private tags follow */
220 #define FIELD_CODEC 66 /* base of codec-private tags */
221
222 /*
223 * Pseudo-tags don't normally need field bits since they are not written to an
224 * output file (by definition). The library also has express logic to always
225 * query a codec for a pseudo-tag so allocating a field bit for one is a
226 * waste. If codec wants to promote the notion of a pseudo-tag being ``set''
227 * or ``unset'' then it can do using internal state flags without polluting
228 * the field bit space defined for real tags.
229 */
230 #define FIELD_PSEUDO 0
231
232 #define FIELD_LAST (32 * FIELDSET_ITEMS - 1)
233
234 #define BITn(n) (((uint32_t)1L) << ((n)&0x1f))
235 #define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n) / 32])
236 #define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field))
237 #define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field))
238 #define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field))
239
240 #define FieldSet(fields, f) (fields[(f) / 32] & BITn(f))
241 #define ResetFieldBit(fields, f) (fields[(f) / 32] &= ~BITn(f))
242
243 typedef enum
244 {
245 TIFF_SETGET_UNDEFINED = 0,
246 TIFF_SETGET_ASCII = 1,
247 TIFF_SETGET_UINT8 = 2,
248 TIFF_SETGET_SINT8 = 3,
249 TIFF_SETGET_UINT16 = 4,
250 TIFF_SETGET_SINT16 = 5,
251 TIFF_SETGET_UINT32 = 6,
252 TIFF_SETGET_SINT32 = 7,
253 TIFF_SETGET_UINT64 = 8,
254 TIFF_SETGET_SINT64 = 9,
255 TIFF_SETGET_FLOAT = 10,
256 TIFF_SETGET_DOUBLE = 11,
257 TIFF_SETGET_IFD8 = 12,
258 TIFF_SETGET_INT = 13,
259 TIFF_SETGET_UINT16_PAIR = 14,
260 TIFF_SETGET_C0_ASCII = 15,
261 TIFF_SETGET_C0_UINT8 = 16,
262 TIFF_SETGET_C0_SINT8 = 17,
263 TIFF_SETGET_C0_UINT16 = 18,
264 TIFF_SETGET_C0_SINT16 = 19,
265 TIFF_SETGET_C0_UINT32 = 20,
266 TIFF_SETGET_C0_SINT32 = 21,
267 TIFF_SETGET_C0_UINT64 = 22,
268 TIFF_SETGET_C0_SINT64 = 23,
269 TIFF_SETGET_C0_FLOAT = 24,
270 TIFF_SETGET_C0_DOUBLE = 25,
271 TIFF_SETGET_C0_IFD8 = 26,
272 TIFF_SETGET_C16_ASCII = 27,
273 TIFF_SETGET_C16_UINT8 = 28,
274 TIFF_SETGET_C16_SINT8 = 29,
275 TIFF_SETGET_C16_UINT16 = 30,
276 TIFF_SETGET_C16_SINT16 = 31,
277 TIFF_SETGET_C16_UINT32 = 32,
278 TIFF_SETGET_C16_SINT32 = 33,
279 TIFF_SETGET_C16_UINT64 = 34,
280 TIFF_SETGET_C16_SINT64 = 35,
281 TIFF_SETGET_C16_FLOAT = 36,
282 TIFF_SETGET_C16_DOUBLE = 37,
283 TIFF_SETGET_C16_IFD8 = 38,
284 TIFF_SETGET_C32_ASCII = 39,
285 TIFF_SETGET_C32_UINT8 = 40,
286 TIFF_SETGET_C32_SINT8 = 41,
287 TIFF_SETGET_C32_UINT16 = 42,
288 TIFF_SETGET_C32_SINT16 = 43,
289 TIFF_SETGET_C32_UINT32 = 44,
290 TIFF_SETGET_C32_SINT32 = 45,
291 TIFF_SETGET_C32_UINT64 = 46,
292 TIFF_SETGET_C32_SINT64 = 47,
293 TIFF_SETGET_C32_FLOAT = 48,
294 TIFF_SETGET_C32_DOUBLE = 49,
295 TIFF_SETGET_C32_IFD8 = 50,
296 TIFF_SETGET_OTHER = 51
297 } TIFFSetGetFieldType;
298
299 #if defined(__cplusplus)
300 extern "C"
301 {
302 #endif
303
304 extern const TIFFFieldArray *_TIFFGetFields(void);
305 extern const TIFFFieldArray *_TIFFGetExifFields(void);
306 extern const TIFFFieldArray *_TIFFGetGpsFields(void);
307 extern void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *infoarray);
308 extern void _TIFFPrintFieldInfo(TIFF *, FILE *);
309
310 extern int _TIFFFillStriles(TIFF *);
311
312 typedef enum
313 {
314 tfiatImage,
315 tfiatExif,
316 tfiatGps, /* EXIF-GPS fields array type */
317 tfiatOther
318 } TIFFFieldArrayType;
319
320 struct _TIFFFieldArray
321 {
322 TIFFFieldArrayType type; /* array type, will be used to determine if IFD
323 is image and such */
324 uint32_t allocated_size; /* 0 if array is constant, other if modified by
325 future definition extension support */
326 uint32_t count; /* number of elements in fields array */
327 TIFFField *fields; /* actual field info */
328 };
329
330 struct _TIFFField
331 {
332 uint32_t field_tag; /* field's tag */
333 short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */
334 short field_writecount; /* write count/TIFF_VARIABLE */
335 TIFFDataType field_type; /* type of associated data */
336 uint32_t
337 field_anonymous; /* if true, this is a unknown / anonymous tag */
338 TIFFSetGetFieldType set_field_type; /* type to be passed to TIFFSetField
339 and TIFFGetField*/
340 TIFFSetGetFieldType get_field_type; /* not used */
341 unsigned short field_bit; /* bit in fieldsset bit vector */
342 unsigned char field_oktochange; /* if true, can change while writing */
343 unsigned char field_passcount; /* if true, pass dir count on set */
344 char *field_name; /* ASCII name */
345 TIFFFieldArray *field_subfields; /* if field points to child ifds, child
346 ifd field definition array */
347 };
348
349 extern int _TIFFMergeFields(TIFF *, const TIFFField[], uint32_t);
350 extern const TIFFField *_TIFFFindOrRegisterField(TIFF *, uint32_t,
351 TIFFDataType);
352 extern TIFFField *_TIFFCreateAnonField(TIFF *, uint32_t, TIFFDataType);
353 extern int _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag);
354 extern int _TIFFCheckDirNumberAndOffset(TIFF *tif, tdir_t dirn,
355 uint64_t diroff);
356 extern int _TIFFGetDirNumberFromOffset(TIFF *tif, uint64_t diroff,
357 tdir_t *dirn);
358 extern int _TIFFGetOffsetFromDirNumber(TIFF *tif, tdir_t dirn,
359 uint64_t *diroff);
360 extern int _TIFFRemoveEntryFromDirectoryListByOffset(TIFF *tif,
361 uint64_t diroff);
362
363 #if defined(__cplusplus)
364 }
365 #endif
366 #endif /* _TIFFDIR_ */