4 * Copyright (c) 1988-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
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.
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.
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
30 * Directory Tag Get & Set Routines.
31 * (and also some miscellaneous stuff)
36 * These are used in the backwards compatibility code...
38 #define DATATYPE_VOID 0 /* !untyped data */
39 #define DATATYPE_INT 1 /* !signed integer data */
40 #define DATATYPE_UINT 2 /* !unsigned integer data */
41 #define DATATYPE_IEEEFP 3 /* !IEEE floating point data */
44 setByteArray(void** vpp
, void* vp
, size_t nmemb
, size_t elem_size
)
47 _TIFFfree(*vpp
), *vpp
= 0;
49 tsize_t bytes
= nmemb
* elem_size
;
50 if (elem_size
&& bytes
/ elem_size
== nmemb
)
51 *vpp
= (void*) _TIFFmalloc(bytes
);
53 _TIFFmemcpy(*vpp
, vp
, bytes
);
56 void _TIFFsetByteArray(void** vpp
, void* vp
, long n
)
57 { setByteArray(vpp
, vp
, n
, 1); }
58 void _TIFFsetString(char** cpp
, char* cp
)
59 { setByteArray((void**) cpp
, (void*) cp
, strlen(cp
)+1, 1); }
60 void _TIFFsetNString(char** cpp
, char* cp
, long n
)
61 { setByteArray((void**) cpp
, (void*) cp
, n
, 1); }
62 void _TIFFsetShortArray(uint16
** wpp
, uint16
* wp
, long n
)
63 { setByteArray((void**) wpp
, (void*) wp
, n
, sizeof (uint16
)); }
64 void _TIFFsetLongArray(uint32
** lpp
, uint32
* lp
, long n
)
65 { setByteArray((void**) lpp
, (void*) lp
, n
, sizeof (uint32
)); }
66 void _TIFFsetFloatArray(float** fpp
, float* fp
, long n
)
67 { setByteArray((void**) fpp
, (void*) fp
, n
, sizeof (float)); }
68 void _TIFFsetDoubleArray(double** dpp
, double* dp
, long n
)
69 { setByteArray((void**) dpp
, (void*) dp
, n
, sizeof (double)); }
72 * Install extra samples information.
75 setExtraSamples(TIFFDirectory
* td
, va_list ap
, int* v
)
81 if ((uint16
) *v
> td
->td_samplesperpixel
)
83 va
= va_arg(ap
, uint16
*);
84 if (*v
> 0 && va
== NULL
) /* typically missing param */
86 for (i
= 0; i
< *v
; i
++)
87 if (va
[i
] > EXTRASAMPLE_UNASSALPHA
)
89 td
->td_extrasamples
= (uint16
) *v
;
90 _TIFFsetShortArray(&td
->td_sampleinfo
, va
, td
->td_extrasamples
);
95 checkInkNamesString(TIFF
* tif
, int slen
, const char* s
)
97 TIFFDirectory
* td
= &tif
->tif_dir
;
98 int i
= td
->td_samplesperpixel
;
101 const char* ep
= s
+slen
;
104 for (; *cp
!= '\0'; cp
++)
112 TIFFError("TIFFSetField",
113 "%s: Invalid InkNames value; expecting %d names, found %d",
115 td
->td_samplesperpixel
,
116 td
->td_samplesperpixel
-i
);
121 _TIFFVSetField(TIFF
* tif
, ttag_t tag
, va_list ap
)
123 static const char module[] = "_TIFFVSetField";
125 TIFFDirectory
* td
= &tif
->tif_dir
;
133 case TIFFTAG_SUBFILETYPE
:
134 td
->td_subfiletype
= va_arg(ap
, uint32
);
136 case TIFFTAG_IMAGEWIDTH
:
137 td
->td_imagewidth
= va_arg(ap
, uint32
);
139 case TIFFTAG_IMAGELENGTH
:
140 td
->td_imagelength
= va_arg(ap
, uint32
);
142 case TIFFTAG_BITSPERSAMPLE
:
143 td
->td_bitspersample
= (uint16
) va_arg(ap
, int);
145 * If the data require post-decoding processing
146 * to byte-swap samples, set it up here. Note
147 * that since tags are required to be ordered,
148 * compression code can override this behaviour
149 * in the setup method if it wants to roll the
150 * post decoding work in with its normal work.
152 if (tif
->tif_flags
& TIFF_SWAB
) {
153 if (td
->td_bitspersample
== 16)
154 tif
->tif_postdecode
= _TIFFSwab16BitData
;
155 else if (td
->td_bitspersample
== 32)
156 tif
->tif_postdecode
= _TIFFSwab32BitData
;
157 else if (td
->td_bitspersample
== 64)
158 tif
->tif_postdecode
= _TIFFSwab64BitData
;
161 case TIFFTAG_COMPRESSION
:
162 v
= va_arg(ap
, int) & 0xffff;
164 * If we're changing the compression scheme,
165 * the notify the previous module so that it
166 * can cleanup any state it's setup.
168 if (TIFFFieldSet(tif
, FIELD_COMPRESSION
)) {
169 if (td
->td_compression
== v
)
171 (*tif
->tif_cleanup
)(tif
);
172 tif
->tif_flags
&= ~TIFF_CODERSETUP
;
175 * Setup new compression routine state.
177 if( (status
= TIFFSetCompressionScheme(tif
, v
)) != 0 )
178 td
->td_compression
= (uint16
) v
;
182 case TIFFTAG_PHOTOMETRIC
:
183 td
->td_photometric
= (uint16
) va_arg(ap
, int);
185 case TIFFTAG_THRESHHOLDING
:
186 td
->td_threshholding
= (uint16
) va_arg(ap
, int);
188 case TIFFTAG_FILLORDER
:
190 if (v
!= FILLORDER_LSB2MSB
&& v
!= FILLORDER_MSB2LSB
)
192 td
->td_fillorder
= (uint16
) v
;
194 case TIFFTAG_DOCUMENTNAME
:
195 _TIFFsetString(&td
->td_documentname
, va_arg(ap
, char*));
198 _TIFFsetString(&td
->td_artist
, va_arg(ap
, char*));
200 case TIFFTAG_DATETIME
:
201 _TIFFsetString(&td
->td_datetime
, va_arg(ap
, char*));
203 case TIFFTAG_HOSTCOMPUTER
:
204 _TIFFsetString(&td
->td_hostcomputer
, va_arg(ap
, char*));
206 case TIFFTAG_IMAGEDESCRIPTION
:
207 _TIFFsetString(&td
->td_imagedescription
, va_arg(ap
, char*));
210 _TIFFsetString(&td
->td_make
, va_arg(ap
, char*));
213 _TIFFsetString(&td
->td_model
, va_arg(ap
, char*));
215 case TIFFTAG_COPYRIGHT
:
216 _TIFFsetString(&td
->td_copyright
, va_arg(ap
, char*));
218 case TIFFTAG_ORIENTATION
:
220 if (v
< ORIENTATION_TOPLEFT
|| ORIENTATION_LEFTBOT
< v
) {
221 TIFFWarning(tif
->tif_name
,
222 "Bad value %ld for \"%s\" tag ignored",
223 v
, _TIFFFieldWithTag(tif
, tag
)->field_name
);
225 td
->td_orientation
= (uint16
) v
;
227 case TIFFTAG_SAMPLESPERPIXEL
:
228 /* XXX should cross check -- e.g. if pallette, then 1 */
232 td
->td_samplesperpixel
= (uint16
) v
;
234 case TIFFTAG_ROWSPERSTRIP
:
235 v32
= va_arg(ap
, uint32
);
238 td
->td_rowsperstrip
= v32
;
239 if (!TIFFFieldSet(tif
, FIELD_TILEDIMENSIONS
)) {
240 td
->td_tilelength
= v32
;
241 td
->td_tilewidth
= td
->td_imagewidth
;
244 case TIFFTAG_MINSAMPLEVALUE
:
245 td
->td_minsamplevalue
= (uint16
) va_arg(ap
, int);
247 case TIFFTAG_MAXSAMPLEVALUE
:
248 td
->td_maxsamplevalue
= (uint16
) va_arg(ap
, int);
250 case TIFFTAG_SMINSAMPLEVALUE
:
251 td
->td_sminsamplevalue
= (double) va_arg(ap
, dblparam_t
);
253 case TIFFTAG_SMAXSAMPLEVALUE
:
254 td
->td_smaxsamplevalue
= (double) va_arg(ap
, dblparam_t
);
256 case TIFFTAG_XRESOLUTION
:
257 td
->td_xresolution
= (float) va_arg(ap
, dblparam_t
);
259 case TIFFTAG_YRESOLUTION
:
260 td
->td_yresolution
= (float) va_arg(ap
, dblparam_t
);
262 case TIFFTAG_PLANARCONFIG
:
264 if (v
!= PLANARCONFIG_CONTIG
&& v
!= PLANARCONFIG_SEPARATE
)
266 td
->td_planarconfig
= (uint16
) v
;
268 case TIFFTAG_PAGENAME
:
269 _TIFFsetString(&td
->td_pagename
, va_arg(ap
, char*));
271 case TIFFTAG_XPOSITION
:
272 td
->td_xposition
= (float) va_arg(ap
, dblparam_t
);
274 case TIFFTAG_YPOSITION
:
275 td
->td_yposition
= (float) va_arg(ap
, dblparam_t
);
277 case TIFFTAG_RESOLUTIONUNIT
:
279 if (v
< RESUNIT_NONE
|| RESUNIT_CENTIMETER
< v
)
281 td
->td_resolutionunit
= (uint16
) v
;
283 case TIFFTAG_PAGENUMBER
:
284 td
->td_pagenumber
[0] = (uint16
) va_arg(ap
, int);
285 td
->td_pagenumber
[1] = (uint16
) va_arg(ap
, int);
287 case TIFFTAG_HALFTONEHINTS
:
288 td
->td_halftonehints
[0] = (uint16
) va_arg(ap
, int);
289 td
->td_halftonehints
[1] = (uint16
) va_arg(ap
, int);
291 case TIFFTAG_COLORMAP
:
292 v32
= (uint32
)(1L<<td
->td_bitspersample
);
293 _TIFFsetShortArray(&td
->td_colormap
[0], va_arg(ap
, uint16
*), v32
);
294 _TIFFsetShortArray(&td
->td_colormap
[1], va_arg(ap
, uint16
*), v32
);
295 _TIFFsetShortArray(&td
->td_colormap
[2], va_arg(ap
, uint16
*), v32
);
297 case TIFFTAG_EXTRASAMPLES
:
298 if (!setExtraSamples(td
, ap
, &v
))
301 case TIFFTAG_MATTEING
:
302 td
->td_extrasamples
= (uint16
) (va_arg(ap
, int) != 0);
303 if (td
->td_extrasamples
) {
304 uint16 sv
= EXTRASAMPLE_ASSOCALPHA
;
305 _TIFFsetShortArray(&td
->td_sampleinfo
, &sv
, 1);
308 case TIFFTAG_TILEWIDTH
:
309 v32
= va_arg(ap
, uint32
);
311 if (tif
->tif_mode
!= O_RDONLY
)
313 TIFFWarning(tif
->tif_name
,
314 "Nonstandard tile width %d, convert file", v32
);
316 td
->td_tilewidth
= v32
;
317 tif
->tif_flags
|= TIFF_ISTILED
;
319 case TIFFTAG_TILELENGTH
:
320 v32
= va_arg(ap
, uint32
);
322 if (tif
->tif_mode
!= O_RDONLY
)
324 TIFFWarning(tif
->tif_name
,
325 "Nonstandard tile length %d, convert file", v32
);
327 td
->td_tilelength
= v32
;
328 tif
->tif_flags
|= TIFF_ISTILED
;
330 case TIFFTAG_TILEDEPTH
:
331 v32
= va_arg(ap
, uint32
);
334 td
->td_tiledepth
= v32
;
336 case TIFFTAG_DATATYPE
:
339 case DATATYPE_VOID
: v
= SAMPLEFORMAT_VOID
; break;
340 case DATATYPE_INT
: v
= SAMPLEFORMAT_INT
; break;
341 case DATATYPE_UINT
: v
= SAMPLEFORMAT_UINT
; break;
342 case DATATYPE_IEEEFP
: v
= SAMPLEFORMAT_IEEEFP
;break;
343 default: goto badvalue
;
345 td
->td_sampleformat
= (uint16
) v
;
347 case TIFFTAG_SAMPLEFORMAT
:
349 if (v
< SAMPLEFORMAT_UINT
|| SAMPLEFORMAT_COMPLEXIEEEFP
< v
)
351 td
->td_sampleformat
= (uint16
) v
;
353 /* Try to fix up the SWAB function for complex data. */
354 if( td
->td_sampleformat
== SAMPLEFORMAT_COMPLEXINT
355 && td
->td_bitspersample
== 32
356 && tif
->tif_postdecode
== _TIFFSwab32BitData
)
357 tif
->tif_postdecode
= _TIFFSwab16BitData
;
358 else if( (td
->td_sampleformat
== SAMPLEFORMAT_COMPLEXINT
359 || td
->td_sampleformat
== SAMPLEFORMAT_COMPLEXIEEEFP
)
360 && td
->td_bitspersample
== 64
361 && tif
->tif_postdecode
== _TIFFSwab64BitData
)
362 tif
->tif_postdecode
= _TIFFSwab32BitData
;
363 else if( td
->td_sampleformat
== SAMPLEFORMAT_COMPLEXIEEEFP
364 && td
->td_bitspersample
== 128
365 && tif
->tif_postdecode
== NULL
)
366 tif
->tif_postdecode
= _TIFFSwab64BitData
;
368 case TIFFTAG_IMAGEDEPTH
:
369 td
->td_imagedepth
= va_arg(ap
, uint32
);
371 case TIFFTAG_STONITS
:
372 d
= va_arg(ap
, dblparam_t
);
377 /* Begin Pixar Tags */
378 case TIFFTAG_PIXAR_IMAGEFULLWIDTH
:
379 td
->td_imagefullwidth
= va_arg(ap
, uint32
);
381 case TIFFTAG_PIXAR_IMAGEFULLLENGTH
:
382 td
->td_imagefulllength
= va_arg(ap
, uint32
);
384 case TIFFTAG_PIXAR_TEXTUREFORMAT
:
385 _TIFFsetString(&td
->td_textureformat
, va_arg(ap
, char*));
387 case TIFFTAG_PIXAR_WRAPMODES
:
388 _TIFFsetString(&td
->td_wrapmodes
, va_arg(ap
, char*));
390 case TIFFTAG_PIXAR_FOVCOT
:
391 td
->td_fovcot
= (float) va_arg(ap
, dblparam_t
);
393 case TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN
:
394 _TIFFsetFloatArray(&td
->td_matrixWorldToScreen
,
395 va_arg(ap
, float*), 16);
397 case TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA
:
398 _TIFFsetFloatArray(&td
->td_matrixWorldToCamera
,
399 va_arg(ap
, float*), 16);
404 if ((tif
->tif_flags
& TIFF_INSUBIFD
) == 0) {
405 td
->td_nsubifd
= (uint16
) va_arg(ap
, int);
406 _TIFFsetLongArray(&td
->td_subifd
, va_arg(ap
, uint32
*),
407 (long) td
->td_nsubifd
);
409 TIFFError(module, "%s: Sorry, cannot nest SubIFDs",
414 case TIFFTAG_YCBCRCOEFFICIENTS
:
415 _TIFFsetFloatArray(&td
->td_ycbcrcoeffs
, va_arg(ap
, float*), 3);
417 case TIFFTAG_YCBCRPOSITIONING
:
418 td
->td_ycbcrpositioning
= (uint16
) va_arg(ap
, int);
420 case TIFFTAG_YCBCRSUBSAMPLING
:
421 td
->td_ycbcrsubsampling
[0] = (uint16
) va_arg(ap
, int);
422 td
->td_ycbcrsubsampling
[1] = (uint16
) va_arg(ap
, int);
424 case TIFFTAG_WHITEPOINT
:
425 _TIFFsetFloatArray(&td
->td_whitepoint
, va_arg(ap
, float*), 2);
427 case TIFFTAG_PRIMARYCHROMATICITIES
:
428 _TIFFsetFloatArray(&td
->td_primarychromas
, va_arg(ap
, float*), 6);
430 case TIFFTAG_TRANSFERFUNCTION
:
431 v
= (td
->td_samplesperpixel
- td
->td_extrasamples
) > 1 ? 3 : 1;
432 for (i
= 0; i
< v
; i
++)
433 _TIFFsetShortArray(&td
->td_transferfunction
[i
],
434 va_arg(ap
, uint16
*), 1L<<td
->td_bitspersample
);
436 case TIFFTAG_REFERENCEBLACKWHITE
:
437 /* XXX should check for null range */
438 _TIFFsetFloatArray(&td
->td_refblackwhite
, va_arg(ap
, float*), 6);
441 td
->td_inkset
= (uint16
) va_arg(ap
, int);
443 case TIFFTAG_DOTRANGE
:
444 /* XXX should check for null range */
445 td
->td_dotrange
[0] = (uint16
) va_arg(ap
, int);
446 td
->td_dotrange
[1] = (uint16
) va_arg(ap
, int);
448 case TIFFTAG_INKNAMES
:
450 s
= va_arg(ap
, char*);
451 i
= checkInkNamesString(tif
, i
, s
);
454 _TIFFsetNString(&td
->td_inknames
, s
, i
);
455 td
->td_inknameslen
= i
;
458 case TIFFTAG_NUMBEROFINKS
:
459 td
->td_ninks
= (uint16
) va_arg(ap
, int);
461 case TIFFTAG_TARGETPRINTER
:
462 _TIFFsetString(&td
->td_targetprinter
, va_arg(ap
, char*));
464 case TIFFTAG_ICCPROFILE
:
465 td
->td_profileLength
= (uint32
) va_arg(ap
, uint32
);
466 _TIFFsetByteArray(&td
->td_profileData
, va_arg(ap
, void*),
467 td
->td_profileLength
);
469 case TIFFTAG_PHOTOSHOP
:
470 td
->td_photoshopLength
= (uint32
) va_arg(ap
, uint32
);
471 _TIFFsetByteArray (&td
->td_photoshopData
, va_arg(ap
, void*),
472 td
->td_photoshopLength
);
474 case TIFFTAG_RICHTIFFIPTC
:
475 td
->td_richtiffiptcLength
= (uint32
) va_arg(ap
, uint32
);
476 _TIFFsetLongArray ((uint32
**)&td
->td_richtiffiptcData
,
478 td
->td_richtiffiptcLength
);
480 case TIFFTAG_XMLPACKET
:
481 td
->td_xmlpacketLength
= (uint32
) va_arg(ap
, uint32
);
482 _TIFFsetByteArray(&td
->td_xmlpacketData
, va_arg(ap
, void*),
483 td
->td_xmlpacketLength
);
486 const TIFFFieldInfo
* fip
= _TIFFFindFieldInfo(tif
, tag
, TIFF_ANY
);
488 int tv_size
, iCustom
;
491 * This can happen if multiple images are open with
492 * different codecs which have private tags. The
493 * global tag information table may then have tags
494 * that are valid for one file but not the other.
495 * If the client tries to set a tag that is not valid
496 * for the image's codec then we'll arrive here. This
497 * happens, for example, when tiffcp is used to convert
498 * between compression schemes and codec-specific tags
499 * are blindly copied.
501 if( fip
== NULL
|| fip
->field_bit
!= FIELD_CUSTOM
)
504 "%s: Invalid %stag \"%s\" (not supported by codec)",
505 tif
->tif_name
, isPseudoTag(tag
) ? "pseudo-" : "",
506 _TIFFFieldWithTag(tif
, tag
)->field_name
);
512 * Find the existing entry for this custom value.
515 for( iCustom
= 0; iCustom
< td
->td_customValueCount
; iCustom
++ )
517 if( td
->td_customValues
[iCustom
].info
== fip
)
519 tv
= td
->td_customValues
+ iCustom
;
520 if( tv
->value
!= NULL
)
521 _TIFFfree( tv
->value
);
527 * Grow the custom list if the entry was not found.
531 TIFFTagValue
*new_customValues
;
533 td
->td_customValueCount
++;
534 new_customValues
= (TIFFTagValue
*)
535 _TIFFrealloc(td
->td_customValues
,
536 sizeof(TIFFTagValue
) * td
->td_customValueCount
);
537 if (!new_customValues
) {
539 "%s: Failed to allocate space for list of custom values",
545 td
->td_customValues
= new_customValues
;
547 tv
= td
->td_customValues
+ (td
->td_customValueCount
-1);
554 * Set custom value ... save a copy of the custom tag value.
556 tv_size
= TIFFDataWidth(fip
->field_type
);
557 if( fip
->field_passcount
)
558 tv
->count
= (int) va_arg(ap
, int);
561 if( fip
->field_passcount
)
563 tv
->value
= _TIFFmalloc(tv_size
* tv
->count
);
568 _TIFFmemcpy( tv
->value
, (void *) va_arg(ap
,void*),
569 tv
->count
* tv_size
);
571 else if( fip
->field_type
== TIFF_ASCII
)
573 const char *value
= (const char *) va_arg(ap
,const char *);
574 tv
->count
= strlen(value
)+1;
575 tv
->value
= _TIFFmalloc(tv
->count
);
580 strcpy( tv
->value
, value
);
584 /* not supporting "pass by value" types yet */
585 TIFFWarning(module, " ... pass by value not implemented.");
587 tv
->value
= _TIFFmalloc(tv_size
* tv
->count
);
592 _TIFFmemset( tv
->value
, 0, tv
->count
* tv_size
);
598 TIFFSetFieldBit(tif
, _TIFFFieldWithTag(tif
, tag
)->field_bit
);
599 tif
->tif_flags
|= TIFF_DIRTYDIRECT
;
606 TIFFError(module, "%.1000s: Bad value %d for \"%s\"",
607 tif
->tif_name
, v
, _TIFFFieldWithTag(tif
, tag
)->field_name
);
611 TIFFError(module, "%.1000s: Bad value %ld for \"%s\"",
612 tif
->tif_name
, v32
, _TIFFFieldWithTag(tif
, tag
)->field_name
);
616 TIFFError(module, "%.1000s: Bad value %f for \"%s\"",
617 tif
->tif_name
, d
, _TIFFFieldWithTag(tif
, tag
)->field_name
);
623 * Return 1/0 according to whether or not
624 * it is permissible to set the tag's value.
625 * Note that we allow ImageLength to be changed
626 * so that we can append and extend to images.
627 * Any other tag may not be altered once writing
628 * has commenced, unless its value has no effect
629 * on the format of the data that is written.
632 OkToChangeTag(TIFF
* tif
, ttag_t tag
)
634 const TIFFFieldInfo
* fip
= _TIFFFindFieldInfo(tif
, tag
, TIFF_ANY
);
635 if (!fip
) { /* unknown tag */
636 TIFFError("TIFFSetField", "%s: Unknown %stag %u",
637 tif
->tif_name
, isPseudoTag(tag
) ? "pseudo-" : "", tag
);
640 if (tag
!= TIFFTAG_IMAGELENGTH
&& (tif
->tif_flags
& TIFF_BEENWRITING
) &&
641 !fip
->field_oktochange
) {
643 * Consult info table to see if tag can be changed
644 * after we've started writing. We only allow changes
645 * to those tags that don't/shouldn't affect the
646 * compression and/or format of the data.
648 TIFFError("TIFFSetField",
649 "%s: Cannot modify tag \"%s\" while writing",
650 tif
->tif_name
, fip
->field_name
);
657 * Record the value of a field in the
658 * internal directory structure. The
659 * field will be written to the file
660 * when/if the directory structure is
664 TIFFSetField(TIFF
* tif
, ttag_t tag
, ...)
670 status
= TIFFVSetField(tif
, tag
, ap
);
676 * Like TIFFSetField, but taking a varargs
677 * parameter list. This routine is useful
678 * for building higher-level interfaces on
679 * top of the library.
682 TIFFVSetField(TIFF
* tif
, ttag_t tag
, va_list ap
)
684 return OkToChangeTag(tif
, tag
) ?
685 (*tif
->tif_tagmethods
.vsetfield
)(tif
, tag
, ap
) : 0;
689 _TIFFVGetField(TIFF
* tif
, ttag_t tag
, va_list ap
)
691 TIFFDirectory
* td
= &tif
->tif_dir
;
695 case TIFFTAG_SUBFILETYPE
:
696 *va_arg(ap
, uint32
*) = td
->td_subfiletype
;
698 case TIFFTAG_IMAGEWIDTH
:
699 *va_arg(ap
, uint32
*) = td
->td_imagewidth
;
701 case TIFFTAG_IMAGELENGTH
:
702 *va_arg(ap
, uint32
*) = td
->td_imagelength
;
704 case TIFFTAG_BITSPERSAMPLE
:
705 *va_arg(ap
, uint16
*) = td
->td_bitspersample
;
707 case TIFFTAG_COMPRESSION
:
708 *va_arg(ap
, uint16
*) = td
->td_compression
;
710 case TIFFTAG_PHOTOMETRIC
:
711 *va_arg(ap
, uint16
*) = td
->td_photometric
;
713 case TIFFTAG_THRESHHOLDING
:
714 *va_arg(ap
, uint16
*) = td
->td_threshholding
;
716 case TIFFTAG_FILLORDER
:
717 *va_arg(ap
, uint16
*) = td
->td_fillorder
;
719 case TIFFTAG_DOCUMENTNAME
:
720 *va_arg(ap
, char**) = td
->td_documentname
;
723 *va_arg(ap
, char**) = td
->td_artist
;
725 case TIFFTAG_DATETIME
:
726 *va_arg(ap
, char**) = td
->td_datetime
;
728 case TIFFTAG_HOSTCOMPUTER
:
729 *va_arg(ap
, char**) = td
->td_hostcomputer
;
731 case TIFFTAG_IMAGEDESCRIPTION
:
732 *va_arg(ap
, char**) = td
->td_imagedescription
;
735 *va_arg(ap
, char**) = td
->td_make
;
738 *va_arg(ap
, char**) = td
->td_model
;
740 case TIFFTAG_COPYRIGHT
:
741 *va_arg(ap
, char**) = td
->td_copyright
;
743 case TIFFTAG_ORIENTATION
:
744 *va_arg(ap
, uint16
*) = td
->td_orientation
;
746 case TIFFTAG_SAMPLESPERPIXEL
:
747 *va_arg(ap
, uint16
*) = td
->td_samplesperpixel
;
749 case TIFFTAG_ROWSPERSTRIP
:
750 *va_arg(ap
, uint32
*) = td
->td_rowsperstrip
;
752 case TIFFTAG_MINSAMPLEVALUE
:
753 *va_arg(ap
, uint16
*) = td
->td_minsamplevalue
;
755 case TIFFTAG_MAXSAMPLEVALUE
:
756 *va_arg(ap
, uint16
*) = td
->td_maxsamplevalue
;
758 case TIFFTAG_SMINSAMPLEVALUE
:
759 *va_arg(ap
, double*) = td
->td_sminsamplevalue
;
761 case TIFFTAG_SMAXSAMPLEVALUE
:
762 *va_arg(ap
, double*) = td
->td_smaxsamplevalue
;
764 case TIFFTAG_XRESOLUTION
:
765 *va_arg(ap
, float*) = td
->td_xresolution
;
767 case TIFFTAG_YRESOLUTION
:
768 *va_arg(ap
, float*) = td
->td_yresolution
;
770 case TIFFTAG_PLANARCONFIG
:
771 *va_arg(ap
, uint16
*) = td
->td_planarconfig
;
773 case TIFFTAG_XPOSITION
:
774 *va_arg(ap
, float*) = td
->td_xposition
;
776 case TIFFTAG_YPOSITION
:
777 *va_arg(ap
, float*) = td
->td_yposition
;
779 case TIFFTAG_PAGENAME
:
780 *va_arg(ap
, char**) = td
->td_pagename
;
782 case TIFFTAG_RESOLUTIONUNIT
:
783 *va_arg(ap
, uint16
*) = td
->td_resolutionunit
;
785 case TIFFTAG_PAGENUMBER
:
786 *va_arg(ap
, uint16
*) = td
->td_pagenumber
[0];
787 *va_arg(ap
, uint16
*) = td
->td_pagenumber
[1];
789 case TIFFTAG_HALFTONEHINTS
:
790 *va_arg(ap
, uint16
*) = td
->td_halftonehints
[0];
791 *va_arg(ap
, uint16
*) = td
->td_halftonehints
[1];
793 case TIFFTAG_COLORMAP
:
794 *va_arg(ap
, uint16
**) = td
->td_colormap
[0];
795 *va_arg(ap
, uint16
**) = td
->td_colormap
[1];
796 *va_arg(ap
, uint16
**) = td
->td_colormap
[2];
798 case TIFFTAG_STRIPOFFSETS
:
799 case TIFFTAG_TILEOFFSETS
:
800 *va_arg(ap
, uint32
**) = td
->td_stripoffset
;
802 case TIFFTAG_STRIPBYTECOUNTS
:
803 case TIFFTAG_TILEBYTECOUNTS
:
804 *va_arg(ap
, uint32
**) = td
->td_stripbytecount
;
806 case TIFFTAG_MATTEING
:
807 *va_arg(ap
, uint16
*) =
808 (td
->td_extrasamples
== 1 &&
809 td
->td_sampleinfo
[0] == EXTRASAMPLE_ASSOCALPHA
);
811 case TIFFTAG_EXTRASAMPLES
:
812 *va_arg(ap
, uint16
*) = td
->td_extrasamples
;
813 *va_arg(ap
, uint16
**) = td
->td_sampleinfo
;
815 case TIFFTAG_TILEWIDTH
:
816 *va_arg(ap
, uint32
*) = td
->td_tilewidth
;
818 case TIFFTAG_TILELENGTH
:
819 *va_arg(ap
, uint32
*) = td
->td_tilelength
;
821 case TIFFTAG_TILEDEPTH
:
822 *va_arg(ap
, uint32
*) = td
->td_tiledepth
;
824 case TIFFTAG_DATATYPE
:
825 switch (td
->td_sampleformat
) {
826 case SAMPLEFORMAT_UINT
:
827 *va_arg(ap
, uint16
*) = DATATYPE_UINT
;
829 case SAMPLEFORMAT_INT
:
830 *va_arg(ap
, uint16
*) = DATATYPE_INT
;
832 case SAMPLEFORMAT_IEEEFP
:
833 *va_arg(ap
, uint16
*) = DATATYPE_IEEEFP
;
835 case SAMPLEFORMAT_VOID
:
836 *va_arg(ap
, uint16
*) = DATATYPE_VOID
;
840 case TIFFTAG_SAMPLEFORMAT
:
841 *va_arg(ap
, uint16
*) = td
->td_sampleformat
;
843 case TIFFTAG_IMAGEDEPTH
:
844 *va_arg(ap
, uint32
*) = td
->td_imagedepth
;
846 case TIFFTAG_STONITS
:
847 *va_arg(ap
, double*) = td
->td_stonits
;
850 *va_arg(ap
, uint16
*) = td
->td_nsubifd
;
851 *va_arg(ap
, uint32
**) = td
->td_subifd
;
853 case TIFFTAG_YCBCRCOEFFICIENTS
:
854 *va_arg(ap
, float**) = td
->td_ycbcrcoeffs
;
856 case TIFFTAG_YCBCRPOSITIONING
:
857 *va_arg(ap
, uint16
*) = td
->td_ycbcrpositioning
;
859 case TIFFTAG_YCBCRSUBSAMPLING
:
860 *va_arg(ap
, uint16
*) = td
->td_ycbcrsubsampling
[0];
861 *va_arg(ap
, uint16
*) = td
->td_ycbcrsubsampling
[1];
863 case TIFFTAG_WHITEPOINT
:
864 *va_arg(ap
, float**) = td
->td_whitepoint
;
866 case TIFFTAG_PRIMARYCHROMATICITIES
:
867 *va_arg(ap
, float**) = td
->td_primarychromas
;
869 case TIFFTAG_TRANSFERFUNCTION
:
870 *va_arg(ap
, uint16
**) = td
->td_transferfunction
[0];
871 if (td
->td_samplesperpixel
- td
->td_extrasamples
> 1) {
872 *va_arg(ap
, uint16
**) = td
->td_transferfunction
[1];
873 *va_arg(ap
, uint16
**) = td
->td_transferfunction
[2];
876 case TIFFTAG_REFERENCEBLACKWHITE
:
877 *va_arg(ap
, float**) = td
->td_refblackwhite
;
880 *va_arg(ap
, uint16
*) = td
->td_inkset
;
882 case TIFFTAG_DOTRANGE
:
883 *va_arg(ap
, uint16
*) = td
->td_dotrange
[0];
884 *va_arg(ap
, uint16
*) = td
->td_dotrange
[1];
886 case TIFFTAG_INKNAMES
:
887 *va_arg(ap
, char**) = td
->td_inknames
;
889 case TIFFTAG_NUMBEROFINKS
:
890 *va_arg(ap
, uint16
*) = td
->td_ninks
;
892 case TIFFTAG_TARGETPRINTER
:
893 *va_arg(ap
, char**) = td
->td_targetprinter
;
895 case TIFFTAG_ICCPROFILE
:
896 *va_arg(ap
, uint32
*) = td
->td_profileLength
;
897 *va_arg(ap
, void**) = td
->td_profileData
;
899 case TIFFTAG_PHOTOSHOP
:
900 *va_arg(ap
, uint32
*) = td
->td_photoshopLength
;
901 *va_arg(ap
, void**) = td
->td_photoshopData
;
903 case TIFFTAG_RICHTIFFIPTC
:
904 *va_arg(ap
, uint32
*) = td
->td_richtiffiptcLength
;
905 *va_arg(ap
, void**) = td
->td_richtiffiptcData
;
907 case TIFFTAG_XMLPACKET
:
908 *va_arg(ap
, uint32
*) = td
->td_xmlpacketLength
;
909 *va_arg(ap
, void**) = td
->td_xmlpacketData
;
911 /* Begin Pixar Tags */
912 case TIFFTAG_PIXAR_IMAGEFULLWIDTH
:
913 *va_arg(ap
, uint32
*) = td
->td_imagefullwidth
;
915 case TIFFTAG_PIXAR_IMAGEFULLLENGTH
:
916 *va_arg(ap
, uint32
*) = td
->td_imagefulllength
;
918 case TIFFTAG_PIXAR_TEXTUREFORMAT
:
919 *va_arg(ap
, char**) = td
->td_textureformat
;
921 case TIFFTAG_PIXAR_WRAPMODES
:
922 *va_arg(ap
, char**) = td
->td_wrapmodes
;
924 case TIFFTAG_PIXAR_FOVCOT
:
925 *va_arg(ap
, float*) = td
->td_fovcot
;
927 case TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN
:
928 *va_arg(ap
, float**) = td
->td_matrixWorldToScreen
;
930 case TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA
:
931 *va_arg(ap
, float**) = td
->td_matrixWorldToCamera
;
937 const TIFFFieldInfo
* fip
= _TIFFFindFieldInfo(tif
, tag
, TIFF_ANY
);
941 * This can happen if multiple images are open with
942 * different codecs which have private tags. The
943 * global tag information table may then have tags
944 * that are valid for one file but not the other.
945 * If the client tries to get a tag that is not valid
946 * for the image's codec then we'll arrive here.
948 if( fip
== NULL
|| fip
->field_bit
!= FIELD_CUSTOM
)
950 TIFFError("_TIFFVGetField",
951 "%s: Invalid %stag \"%s\" (not supported by codec)",
952 tif
->tif_name
, isPseudoTag(tag
) ? "pseudo-" : "",
953 _TIFFFieldWithTag(tif
, tag
)->field_name
);
959 ** Do we have a custom value?
962 for( i
= 0; i
< td
->td_customValueCount
; i
++ )
964 TIFFTagValue
*tv
= td
->td_customValues
+ i
;
966 if( tv
->info
->field_tag
!= tag
)
969 if( fip
->field_passcount
)
971 *va_arg(ap
, u_short
*) = (u_short
) tv
->count
;
972 *va_arg(ap
, void **) = tv
->value
;
976 else if( fip
->field_type
== TIFF_ASCII
)
978 *va_arg(ap
, void **) = tv
->value
;
984 printf( "TIFFVGetField ... pass by value not imp.\n" );
994 * Return the value of a field in the
995 * internal directory structure.
998 TIFFGetField(TIFF
* tif
, ttag_t tag
, ...)
1004 status
= TIFFVGetField(tif
, tag
, ap
);
1010 * Like TIFFGetField, but taking a varargs
1011 * parameter list. This routine is useful
1012 * for building higher-level interfaces on
1013 * top of the library.
1016 TIFFVGetField(TIFF
* tif
, ttag_t tag
, va_list ap
)
1018 const TIFFFieldInfo
* fip
= _TIFFFindFieldInfo(tif
, tag
, TIFF_ANY
);
1019 return (fip
&& (isPseudoTag(tag
) || TIFFFieldSet(tif
, fip
->field_bit
)) ?
1020 (*tif
->tif_tagmethods
.vgetfield
)(tif
, tag
, ap
) : 0);
1023 #define CleanupField(member) { \
1025 _TIFFfree(td->member); \
1031 * Release storage associated with a directory.
1034 TIFFFreeDirectory(TIFF
* tif
)
1036 TIFFDirectory
*td
= &tif
->tif_dir
;
1039 CleanupField(td_colormap
[0]);
1040 CleanupField(td_colormap
[1]);
1041 CleanupField(td_colormap
[2]);
1042 CleanupField(td_documentname
);
1043 CleanupField(td_artist
);
1044 CleanupField(td_datetime
);
1045 CleanupField(td_hostcomputer
);
1046 CleanupField(td_imagedescription
);
1047 CleanupField(td_make
);
1048 CleanupField(td_model
);
1049 CleanupField(td_copyright
);
1050 CleanupField(td_pagename
);
1051 CleanupField(td_sampleinfo
);
1052 CleanupField(td_subifd
);
1053 CleanupField(td_ycbcrcoeffs
);
1054 CleanupField(td_inknames
);
1055 CleanupField(td_targetprinter
);
1056 CleanupField(td_whitepoint
);
1057 CleanupField(td_primarychromas
);
1058 CleanupField(td_refblackwhite
);
1059 CleanupField(td_transferfunction
[0]);
1060 CleanupField(td_transferfunction
[1]);
1061 CleanupField(td_transferfunction
[2]);
1062 CleanupField(td_profileData
);
1063 CleanupField(td_photoshopData
);
1064 CleanupField(td_richtiffiptcData
);
1065 CleanupField(td_xmlpacketData
);
1066 CleanupField(td_stripoffset
);
1067 CleanupField(td_stripbytecount
);
1068 /* Begin Pixar Tags */
1069 CleanupField(td_textureformat
);
1070 CleanupField(td_wrapmodes
);
1071 CleanupField(td_matrixWorldToScreen
);
1072 CleanupField(td_matrixWorldToCamera
);
1073 /* End Pixar Tags */
1075 /* Cleanup custom tag values */
1076 for( i
= 0; i
< td
->td_customValueCount
; i
++ )
1077 _TIFFfree( td
->td_customValues
[i
].value
);
1079 if( td
->td_customValues
!= NULL
)
1080 _TIFFfree( td
->td_customValues
);
1086 * Client Tag extension support (from Niles Ritter).
1088 static TIFFExtendProc _TIFFextender
= (TIFFExtendProc
) NULL
;
1091 TIFFSetTagExtender(TIFFExtendProc extender
)
1093 TIFFExtendProc prev
= _TIFFextender
;
1094 _TIFFextender
= extender
;
1099 * Setup for a new directory. Should we automatically call
1100 * TIFFWriteDirectory() if the current one is dirty?
1102 * The newly created directory will not exist on the file till
1103 * TIFFWriteDirectory(), TIFFFlush() or TIFFClose() is called.
1106 TIFFCreateDirectory(TIFF
* tif
)
1108 TIFFDefaultDirectory(tif
);
1109 tif
->tif_diroff
= 0;
1110 tif
->tif_nextdiroff
= 0;
1111 tif
->tif_curoff
= 0;
1112 tif
->tif_row
= (uint32
) -1;
1113 tif
->tif_curstrip
= (tstrip_t
) -1;
1119 * Setup a default directory structure.
1122 TIFFDefaultDirectory(TIFF
* tif
)
1124 register TIFFDirectory
* td
= &tif
->tif_dir
;
1126 _TIFFSetupFieldInfo(tif
);
1127 _TIFFmemset(td
, 0, sizeof (*td
));
1128 td
->td_fillorder
= FILLORDER_MSB2LSB
;
1129 td
->td_bitspersample
= 1;
1130 td
->td_threshholding
= THRESHHOLD_BILEVEL
;
1131 td
->td_orientation
= ORIENTATION_TOPLEFT
;
1132 td
->td_samplesperpixel
= 1;
1133 td
->td_rowsperstrip
= (uint32
) -1;
1134 td
->td_tilewidth
= (uint32
) -1;
1135 td
->td_tilelength
= (uint32
) -1;
1136 td
->td_tiledepth
= 1;
1137 td
->td_resolutionunit
= RESUNIT_INCH
;
1138 td
->td_sampleformat
= SAMPLEFORMAT_UINT
;
1139 td
->td_imagedepth
= 1;
1140 td
->td_ycbcrsubsampling
[0] = 2;
1141 td
->td_ycbcrsubsampling
[1] = 2;
1142 td
->td_ycbcrpositioning
= YCBCRPOSITION_CENTERED
;
1143 td
->td_inkset
= INKSET_CMYK
;
1145 tif
->tif_postdecode
= _TIFFNoPostDecode
;
1146 tif
->tif_tagmethods
.vsetfield
= _TIFFVSetField
;
1147 tif
->tif_tagmethods
.vgetfield
= _TIFFVGetField
;
1148 tif
->tif_tagmethods
.printdir
= NULL
;
1150 * Give client code a chance to install their own
1151 * tag extensions & methods, prior to compression overloads.
1154 (*_TIFFextender
)(tif
);
1155 (void) TIFFSetField(tif
, TIFFTAG_COMPRESSION
, COMPRESSION_NONE
);
1157 * NB: The directory is marked dirty as a result of setting
1158 * up the default compression scheme. However, this really
1159 * isn't correct -- we want TIFF_DIRTYDIRECT to be set only
1160 * if the user does something. We could just do the setup
1161 * by hand, but it seems better to use the normal mechanism
1162 * (i.e. TIFFSetField).
1164 tif
->tif_flags
&= ~TIFF_DIRTYDIRECT
;
1167 * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19
1168 * we clear the ISTILED flag when setting up a new directory.
1169 * Should we also be clearing stuff like INSUBIFD?
1171 tif
->tif_flags
&= ~TIFF_ISTILED
;
1177 TIFFAdvanceDirectory(TIFF
* tif
, uint32
* nextdir
, toff_t
* off
)
1179 static const char module[] = "TIFFAdvanceDirectory";
1183 toff_t poff
=*nextdir
;
1184 if (poff
+sizeof(uint16
) > tif
->tif_size
)
1186 TIFFError(module, "%s: Error fetching directory count",
1190 _TIFFmemcpy(&dircount
, tif
->tif_base
+poff
, sizeof (uint16
));
1191 if (tif
->tif_flags
& TIFF_SWAB
)
1192 TIFFSwabShort(&dircount
);
1193 poff
+=sizeof (uint16
)+dircount
*sizeof (TIFFDirEntry
);
1196 if (((toff_t
) (poff
+sizeof (uint32
))) > tif
->tif_size
)
1198 TIFFError(module, "%s: Error fetching directory link",
1202 _TIFFmemcpy(nextdir
, tif
->tif_base
+poff
, sizeof (uint32
));
1203 if (tif
->tif_flags
& TIFF_SWAB
)
1204 TIFFSwabLong(nextdir
);
1209 if (!SeekOK(tif
, *nextdir
) ||
1210 !ReadOK(tif
, &dircount
, sizeof (uint16
))) {
1211 TIFFError(module, "%s: Error fetching directory count",
1215 if (tif
->tif_flags
& TIFF_SWAB
)
1216 TIFFSwabShort(&dircount
);
1218 *off
= TIFFSeekFile(tif
,
1219 dircount
*sizeof (TIFFDirEntry
), SEEK_CUR
);
1221 (void) TIFFSeekFile(tif
,
1222 dircount
*sizeof (TIFFDirEntry
), SEEK_CUR
);
1223 if (!ReadOK(tif
, nextdir
, sizeof (uint32
))) {
1224 TIFFError(module, "%s: Error fetching directory link",
1228 if (tif
->tif_flags
& TIFF_SWAB
)
1229 TIFFSwabLong(nextdir
);
1235 * Count the number of directories in a file.
1238 TIFFNumberOfDirectories(TIFF
* tif
)
1240 toff_t nextdir
= tif
->tif_header
.tiff_diroff
;
1243 while (nextdir
!= 0 && TIFFAdvanceDirectory(tif
, &nextdir
, NULL
))
1249 * Set the n-th directory as the current directory.
1250 * NB: Directories are numbered starting at 0.
1253 TIFFSetDirectory(TIFF
* tif
, tdir_t dirn
)
1258 nextdir
= tif
->tif_header
.tiff_diroff
;
1259 for (n
= dirn
; n
> 0 && nextdir
!= 0; n
--)
1260 if (!TIFFAdvanceDirectory(tif
, &nextdir
, NULL
))
1262 tif
->tif_nextdiroff
= nextdir
;
1264 * Set curdir to the actual directory index. The
1265 * -1 is because TIFFReadDirectory will increment
1266 * tif_curdir after successfully reading the directory.
1268 tif
->tif_curdir
= (dirn
- n
) - 1;
1270 * Reset tif_dirnumber counter nad start new list of seen directories.
1271 * We need this in order to prevent IFD loops.
1273 tif
->tif_dirnumber
= 0;
1274 return (TIFFReadDirectory(tif
));
1278 * Set the current directory to be the directory
1279 * located at the specified file offset. This interface
1280 * is used mainly to access directories linked with
1281 * the SubIFD tag (e.g. thumbnail images).
1284 TIFFSetSubDirectory(TIFF
* tif
, uint32 diroff
)
1286 tif
->tif_nextdiroff
= diroff
;
1288 * Reset tif_dirnumber counter nad start new list of seen directories.
1289 * We need this in order to prevent IFD loops.
1291 tif
->tif_dirnumber
= 0;
1292 return (TIFFReadDirectory(tif
));
1296 * Return file offset of the current directory.
1299 TIFFCurrentDirOffset(TIFF
* tif
)
1301 return (tif
->tif_diroff
);
1305 * Return an indication of whether or not we are
1306 * at the last directory in the file.
1309 TIFFLastDirectory(TIFF
* tif
)
1311 return (tif
->tif_nextdiroff
== 0);
1315 * Unlink the specified directory from the directory chain.
1318 TIFFUnlinkDirectory(TIFF
* tif
, tdir_t dirn
)
1320 static const char module[] = "TIFFUnlinkDirectory";
1325 if (tif
->tif_mode
== O_RDONLY
) {
1326 TIFFError(module, "Can not unlink directory in read-only file");
1330 * Go to the directory before the one we want
1331 * to unlink and nab the offset of the link
1332 * field we'll need to patch.
1334 nextdir
= tif
->tif_header
.tiff_diroff
;
1335 off
= sizeof (uint16
) + sizeof (uint16
);
1336 for (n
= dirn
-1; n
> 0; n
--) {
1338 TIFFError(module, "Directory %d does not exist", dirn
);
1341 if (!TIFFAdvanceDirectory(tif
, &nextdir
, &off
))
1345 * Advance to the directory to be unlinked and fetch
1346 * the offset of the directory that follows.
1348 if (!TIFFAdvanceDirectory(tif
, &nextdir
, NULL
))
1351 * Go back and patch the link field of the preceding
1352 * directory to point to the offset of the directory
1355 (void) TIFFSeekFile(tif
, off
, SEEK_SET
);
1356 if (tif
->tif_flags
& TIFF_SWAB
)
1357 TIFFSwabLong(&nextdir
);
1358 if (!WriteOK(tif
, &nextdir
, sizeof (uint32
))) {
1359 TIFFError(module, "Error writing directory link");
1363 * Leave directory state setup safely. We don't have
1364 * facilities for doing inserting and removing directories,
1365 * so it's safest to just invalidate everything. This
1366 * means that the caller can only append to the directory
1369 (*tif
->tif_cleanup
)(tif
);
1370 if ((tif
->tif_flags
& TIFF_MYBUFFER
) && tif
->tif_rawdata
) {
1371 _TIFFfree(tif
->tif_rawdata
);
1372 tif
->tif_rawdata
= NULL
;
1375 tif
->tif_flags
&= ~(TIFF_BEENWRITING
|TIFF_BUFFERSETUP
|TIFF_POSTENCODE
);
1376 TIFFFreeDirectory(tif
);
1377 TIFFDefaultDirectory(tif
);
1378 tif
->tif_diroff
= 0; /* force link on next write */
1379 tif
->tif_nextdiroff
= 0; /* next write must be at end */
1380 tif
->tif_curoff
= 0;
1381 tif
->tif_row
= (uint32
) -1;
1382 tif
->tif_curstrip
= (tstrip_t
) -1;
1388 * Author: Bruce Cameron <cameron@petris.com>
1390 * Set a table of tags that are to be replaced during directory process by the
1391 * 'IGNORE' state - or return TRUE/FALSE for the requested tag such that
1392 * 'ReadDirectory' can use the stored information.
1395 TIFFReassignTagToIgnore (enum TIFFIgnoreSense task
, int TIFFtagID
)
1397 static int TIFFignoretags
[FIELD_LAST
];
1398 static int tagcount
= 0 ;
1399 int i
; /* Loop index */
1400 int j
; /* Loop index */
1405 if ( tagcount
< (FIELD_LAST
- 1) )
1407 for ( j
= 0 ; j
< tagcount
; ++j
)
1408 { /* Do not add duplicate tag */
1409 if ( TIFFignoretags
[j
] == TIFFtagID
)
1412 TIFFignoretags
[tagcount
++] = TIFFtagID
;
1418 for ( i
= 0 ; i
< tagcount
; ++i
)
1420 if ( TIFFignoretags
[i
] == TIFFtagID
)
1426 tagcount
= 0 ; /* Clear the list */