ReactOS  0.4.13-dev-39-g8b6696f
tif_dir.c
Go to the documentation of this file.
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 /*
26  * TIFF Library.
27  *
28  * Directory Tag Get & Set Routines.
29  * (and also some miscellaneous stuff)
30  */
31 #include <precomp.h>
32 #include <float.h>
33 
34 /*
35  * These are used in the backwards compatibility code...
36  */
37 #define DATATYPE_VOID 0 /* !untyped data */
38 #define DATATYPE_INT 1 /* !signed integer data */
39 #define DATATYPE_UINT 2 /* !unsigned integer data */
40 #define DATATYPE_IEEEFP 3 /* !IEEE floating point data */
41 
42 static void
43 setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
44 {
45  if (*vpp) {
46  _TIFFfree(*vpp);
47  *vpp = 0;
48  }
49  if (vp) {
50  tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
51  if (elem_size && bytes / elem_size == nmemb)
52  *vpp = (void*) _TIFFmalloc(bytes);
53  if (*vpp)
54  _TIFFmemcpy(*vpp, vp, bytes);
55  }
56 }
57 void _TIFFsetByteArray(void** vpp, void* vp, uint32 n)
58  { setByteArray(vpp, vp, n, 1); }
59 void _TIFFsetString(char** cpp, char* cp)
60  { setByteArray((void**) cpp, (void*) cp, strlen(cp)+1, 1); }
61 static void _TIFFsetNString(char** cpp, char* cp, uint32 n)
62  { setByteArray((void**) cpp, (void*) cp, n, 1); }
64  { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
66  { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }
67 static void _TIFFsetLong8Array(uint64** lpp, uint64* lp, uint32 n)
68  { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint64)); }
69 void _TIFFsetFloatArray(float** fpp, float* fp, uint32 n)
70  { setByteArray((void**) fpp, (void*) fp, n, sizeof (float)); }
71 void _TIFFsetDoubleArray(double** dpp, double* dp, uint32 n)
72  { setByteArray((void**) dpp, (void*) dp, n, sizeof (double)); }
73 
74 static void
75 setDoubleArrayOneValue(double** vpp, double value, size_t nmemb)
76 {
77  if (*vpp)
78  _TIFFfree(*vpp);
79  *vpp = _TIFFmalloc(nmemb*sizeof(double));
80  if (*vpp)
81  {
82  while (nmemb--)
83  ((double*)*vpp)[nmemb] = value;
84  }
85 }
86 
87 /*
88  * Install extra samples information.
89  */
90 static int
92 {
93 /* XXX: Unassociated alpha data == 999 is a known Corel Draw bug, see below */
94 #define EXTRASAMPLE_COREL_UNASSALPHA 999
95 
96  uint16* va;
97  uint32 i;
98 
99  *v = (uint16) va_arg(ap, uint16_vap);
100  if ((uint16) *v > td->td_samplesperpixel)
101  return 0;
102  va = va_arg(ap, uint16*);
103  if (*v > 0 && va == NULL) /* typically missing param */
104  return 0;
105  for (i = 0; i < *v; i++) {
106  if (va[i] > EXTRASAMPLE_UNASSALPHA) {
107  /*
108  * XXX: Corel Draw is known to produce incorrect
109  * ExtraSamples tags which must be patched here if we
110  * want to be able to open some of the damaged TIFF
111  * files:
112  */
113  if (va[i] == EXTRASAMPLE_COREL_UNASSALPHA)
115  else
116  return 0;
117  }
118  }
119  td->td_extrasamples = (uint16) *v;
121  return 1;
122 
123 #undef EXTRASAMPLE_COREL_UNASSALPHA
124 }
125 
126 /*
127  * Confirm we have "samplesperpixel" ink names separated by \0. Returns
128  * zero if the ink names are not as expected.
129  */
130 static uint32
131 checkInkNamesString(TIFF* tif, uint32 slen, const char* s)
132 {
133  TIFFDirectory* td = &tif->tif_dir;
135 
136  if (slen > 0) {
137  const char* ep = s+slen;
138  const char* cp = s;
139  for (; i > 0; i--) {
140  for (; cp < ep && *cp != '\0'; cp++) {}
141  if (cp >= ep)
142  goto bad;
143  cp++; /* skip \0 */
144  }
145  return ((uint32)(cp-s));
146  }
147 bad:
148  TIFFErrorExt(tif->tif_clientdata, "TIFFSetField",
149  "%s: Invalid InkNames value; expecting %d names, found %d",
150  tif->tif_name,
151  td->td_samplesperpixel,
152  td->td_samplesperpixel-i);
153  return (0);
154 }
155 
156 static float TIFFClampDoubleToFloat( double val )
157 {
158  if( val > FLT_MAX )
159  return FLT_MAX;
160  if( val < -FLT_MAX )
161  return -FLT_MAX;
162  return (float)val;
163 }
164 
165 static int
167 {
168  static const char module[] = "_TIFFVSetField";
169 
170  TIFFDirectory* td = &tif->tif_dir;
171  int status = 1;
172  uint32 v32, i, v;
173  double dblval;
174  char* s;
175  const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
176  uint32 standard_tag = tag;
177  if( fip == NULL ) /* cannot happen since OkToChangeTag() already checks it */
178  return 0;
179  /*
180  * We want to force the custom code to be used for custom
181  * fields even if the tag happens to match a well known
182  * one - important for reinterpreted handling of standard
183  * tag values in custom directories (i.e. EXIF)
184  */
185  if (fip->field_bit == FIELD_CUSTOM) {
186  standard_tag = 0;
187  }
188 
189  switch (standard_tag) {
190  case TIFFTAG_SUBFILETYPE:
192  break;
193  case TIFFTAG_IMAGEWIDTH:
194  td->td_imagewidth = (uint32) va_arg(ap, uint32);
195  break;
196  case TIFFTAG_IMAGELENGTH:
198  break;
201  /*
202  * If the data require post-decoding processing to byte-swap
203  * samples, set it up here. Note that since tags are required
204  * to be ordered, compression code can override this behaviour
205  * in the setup method if it wants to roll the post decoding
206  * work in with its normal work.
207  */
208  if (tif->tif_flags & TIFF_SWAB) {
209  if (td->td_bitspersample == 8)
211  else if (td->td_bitspersample == 16)
213  else if (td->td_bitspersample == 24)
215  else if (td->td_bitspersample == 32)
217  else if (td->td_bitspersample == 64)
219  else if (td->td_bitspersample == 128) /* two 64's */
221  }
222  break;
223  case TIFFTAG_COMPRESSION:
224  v = (uint16) va_arg(ap, uint16_vap);
225  /*
226  * If we're changing the compression scheme, the notify the
227  * previous module so that it can cleanup any state it's
228  * setup.
229  */
230  if (TIFFFieldSet(tif, FIELD_COMPRESSION)) {
231  if ((uint32)td->td_compression == v)
232  break;
233  (*tif->tif_cleanup)(tif);
234  tif->tif_flags &= ~TIFF_CODERSETUP;
235  }
236  /*
237  * Setup new compression routine state.
238  */
239  if( (status = TIFFSetCompressionScheme(tif, v)) != 0 )
240  td->td_compression = (uint16) v;
241  else
242  status = 0;
243  break;
244  case TIFFTAG_PHOTOMETRIC:
246  break;
249  break;
250  case TIFFTAG_FILLORDER:
251  v = (uint16) va_arg(ap, uint16_vap);
252  if (v != FILLORDER_LSB2MSB && v != FILLORDER_MSB2LSB)
253  goto badvalue;
254  td->td_fillorder = (uint16) v;
255  break;
256  case TIFFTAG_ORIENTATION:
257  v = (uint16) va_arg(ap, uint16_vap);
259  goto badvalue;
260  else
261  td->td_orientation = (uint16) v;
262  break;
264  v = (uint16) va_arg(ap, uint16_vap);
265  if (v == 0)
266  goto badvalue;
267  if( v != td->td_samplesperpixel )
268  {
269  /* See http://bugzilla.maptools.org/show_bug.cgi?id=2500 */
270  if( td->td_sminsamplevalue != NULL )
271  {
273  "SamplesPerPixel tag value is changing, "
274  "but SMinSampleValue tag was read with a different value. Cancelling it");
277  td->td_sminsamplevalue = NULL;
278  }
279  if( td->td_smaxsamplevalue != NULL )
280  {
282  "SamplesPerPixel tag value is changing, "
283  "but SMaxSampleValue tag was read with a different value. Cancelling it");
286  td->td_smaxsamplevalue = NULL;
287  }
288  }
289  td->td_samplesperpixel = (uint16) v;
290  break;
292  v32 = (uint32) va_arg(ap, uint32);
293  if (v32 == 0)
294  goto badvalue32;
295  td->td_rowsperstrip = v32;
296  if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) {
297  td->td_tilelength = v32;
298  td->td_tilewidth = td->td_imagewidth;
299  }
300  break;
303  break;
306  break;
308  if (tif->tif_flags & TIFF_PERSAMPLE)
310  else
312  break;
314  if (tif->tif_flags & TIFF_PERSAMPLE)
316  else
318  break;
319  case TIFFTAG_XRESOLUTION:
320  dblval = va_arg(ap, double);
321  if( dblval < 0 )
322  goto badvaluedouble;
323  td->td_xresolution = TIFFClampDoubleToFloat( dblval );
324  break;
325  case TIFFTAG_YRESOLUTION:
326  dblval = va_arg(ap, double);
327  if( dblval < 0 )
328  goto badvaluedouble;
329  td->td_yresolution = TIFFClampDoubleToFloat( dblval );
330  break;
332  v = (uint16) va_arg(ap, uint16_vap);
334  goto badvalue;
335  td->td_planarconfig = (uint16) v;
336  break;
337  case TIFFTAG_XPOSITION:
338  td->td_xposition = TIFFClampDoubleToFloat( va_arg(ap, double) );
339  break;
340  case TIFFTAG_YPOSITION:
341  td->td_yposition = TIFFClampDoubleToFloat( va_arg(ap, double) );
342  break;
344  v = (uint16) va_arg(ap, uint16_vap);
345  if (v < RESUNIT_NONE || RESUNIT_CENTIMETER < v)
346  goto badvalue;
347  td->td_resolutionunit = (uint16) v;
348  break;
349  case TIFFTAG_PAGENUMBER:
350  td->td_pagenumber[0] = (uint16) va_arg(ap, uint16_vap);
351  td->td_pagenumber[1] = (uint16) va_arg(ap, uint16_vap);
352  break;
356  break;
357  case TIFFTAG_COLORMAP:
358  v32 = (uint32)(1L<<td->td_bitspersample);
359  _TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32);
360  _TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32);
361  _TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32);
362  break;
364  if (!setExtraSamples(td, ap, &v))
365  goto badvalue;
366  break;
367  case TIFFTAG_MATTEING:
368  td->td_extrasamples = (((uint16) va_arg(ap, uint16_vap)) != 0);
369  if (td->td_extrasamples) {
371  _TIFFsetShortArray(&td->td_sampleinfo, &sv, 1);
372  }
373  break;
374  case TIFFTAG_TILEWIDTH:
375  v32 = (uint32) va_arg(ap, uint32);
376  if (v32 % 16) {
377  if (tif->tif_mode != O_RDONLY)
378  goto badvalue32;
380  "Nonstandard tile width %d, convert file", v32);
381  }
382  td->td_tilewidth = v32;
383  tif->tif_flags |= TIFF_ISTILED;
384  break;
385  case TIFFTAG_TILELENGTH:
386  v32 = (uint32) va_arg(ap, uint32);
387  if (v32 % 16) {
388  if (tif->tif_mode != O_RDONLY)
389  goto badvalue32;
391  "Nonstandard tile length %d, convert file", v32);
392  }
393  td->td_tilelength = v32;
394  tif->tif_flags |= TIFF_ISTILED;
395  break;
396  case TIFFTAG_TILEDEPTH:
397  v32 = (uint32) va_arg(ap, uint32);
398  if (v32 == 0)
399  goto badvalue32;
400  td->td_tiledepth = v32;
401  break;
402  case TIFFTAG_DATATYPE:
403  v = (uint16) va_arg(ap, uint16_vap);
404  switch (v) {
405  case DATATYPE_VOID: v = SAMPLEFORMAT_VOID; break;
406  case DATATYPE_INT: v = SAMPLEFORMAT_INT; break;
407  case DATATYPE_UINT: v = SAMPLEFORMAT_UINT; break;
408  case DATATYPE_IEEEFP: v = SAMPLEFORMAT_IEEEFP;break;
409  default: goto badvalue;
410  }
411  td->td_sampleformat = (uint16) v;
412  break;
414  v = (uint16) va_arg(ap, uint16_vap);
416  goto badvalue;
417  td->td_sampleformat = (uint16) v;
418 
419  /* Try to fix up the SWAB function for complex data. */
421  && td->td_bitspersample == 32
426  && td->td_bitspersample == 64
429  break;
430  case TIFFTAG_IMAGEDEPTH:
431  td->td_imagedepth = (uint32) va_arg(ap, uint32);
432  break;
433  case TIFFTAG_SUBIFD:
434  if ((tif->tif_flags & TIFF_INSUBIFD) == 0) {
437  (uint32) td->td_nsubifd);
438  } else {
440  "%s: Sorry, cannot nest SubIFDs",
441  tif->tif_name);
442  status = 0;
443  }
444  break;
447  break;
451  break;
453  v = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1;
454  for (i = 0; i < v; i++)
456  va_arg(ap, uint16*), 1U<<td->td_bitspersample);
457  break;
459  /* XXX should check for null range */
460  _TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);
461  break;
462  case TIFFTAG_INKNAMES:
463  v = (uint16) va_arg(ap, uint16_vap);
464  s = va_arg(ap, char*);
465  v = checkInkNamesString(tif, v, s);
466  status = v > 0;
467  if( v > 0 ) {
468  _TIFFsetNString(&td->td_inknames, s, v);
469  td->td_inknameslen = v;
470  }
471  break;
472  case TIFFTAG_PERSAMPLE:
473  v = (uint16) va_arg(ap, uint16_vap);
474  if( v == PERSAMPLE_MULTI )
475  tif->tif_flags |= TIFF_PERSAMPLE;
476  else
477  tif->tif_flags &= ~TIFF_PERSAMPLE;
478  break;
479  default: {
480  TIFFTagValue *tv;
481  int tv_size, iCustom;
482 
483  /*
484  * This can happen if multiple images are open with different
485  * codecs which have private tags. The global tag information
486  * table may then have tags that are valid for one file but not
487  * the other. If the client tries to set a tag that is not valid
488  * for the image's codec then we'll arrive here. This
489  * happens, for example, when tiffcp is used to convert between
490  * compression schemes and codec-specific tags are blindly copied.
491  */
492  if(fip->field_bit != FIELD_CUSTOM) {
494  "%s: Invalid %stag \"%s\" (not supported by codec)",
495  tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
496  fip->field_name);
497  status = 0;
498  break;
499  }
500 
501  /*
502  * Find the existing entry for this custom value.
503  */
504  tv = NULL;
505  for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++) {
506  if (td->td_customValues[iCustom].info->field_tag == tag) {
507  tv = td->td_customValues + iCustom;
508  if (tv->value != NULL) {
509  _TIFFfree(tv->value);
510  tv->value = NULL;
511  }
512  break;
513  }
514  }
515 
516  /*
517  * Grow the custom list if the entry was not found.
518  */
519  if(tv == NULL) {
520  TIFFTagValue *new_customValues;
521 
522  td->td_customValueCount++;
523  new_customValues = (TIFFTagValue *)
525  sizeof(TIFFTagValue) * td->td_customValueCount);
526  if (!new_customValues) {
528  "%s: Failed to allocate space for list of custom values",
529  tif->tif_name);
530  status = 0;
531  goto end;
532  }
533 
534  td->td_customValues = new_customValues;
535 
536  tv = td->td_customValues + (td->td_customValueCount - 1);
537  tv->info = fip;
538  tv->value = NULL;
539  tv->count = 0;
540  }
541 
542  /*
543  * Set custom value ... save a copy of the custom tag value.
544  */
545  tv_size = _TIFFDataSize(fip->field_type);
546  if (tv_size == 0) {
547  status = 0;
549  "%s: Bad field type %d for \"%s\"",
550  tif->tif_name, fip->field_type,
551  fip->field_name);
552  goto end;
553  }
554 
555  if (fip->field_type == TIFF_ASCII)
556  {
557  uint32 ma;
558  char* mb;
559  if (fip->field_passcount)
560  {
562  ma=(uint32)va_arg(ap,uint32);
563  mb=(char*)va_arg(ap,char*);
564  }
565  else
566  {
567  mb=(char*)va_arg(ap,char*);
568  ma=(uint32)(strlen(mb)+1);
569  }
570  tv->count=ma;
571  setByteArray(&tv->value,mb,ma,1);
572  }
573  else
574  {
575  if (fip->field_passcount) {
576  if (fip->field_writecount == TIFF_VARIABLE2)
577  tv->count = (uint32) va_arg(ap, uint32);
578  else
579  tv->count = (int) va_arg(ap, int);
580  } else if (fip->field_writecount == TIFF_VARIABLE
581  || fip->field_writecount == TIFF_VARIABLE2)
582  tv->count = 1;
583  else if (fip->field_writecount == TIFF_SPP)
584  tv->count = td->td_samplesperpixel;
585  else
586  tv->count = fip->field_writecount;
587 
588  if (tv->count == 0) {
589  status = 0;
591  "%s: Null count for \"%s\" (type "
592  "%d, writecount %d, passcount %d)",
593  tif->tif_name,
594  fip->field_name,
595  fip->field_type,
596  fip->field_writecount,
597  fip->field_passcount);
598  goto end;
599  }
600 
601  tv->value = _TIFFCheckMalloc(tif, tv->count, tv_size,
602  "custom tag binary object");
603  if (!tv->value) {
604  status = 0;
605  goto end;
606  }
607 
608  if (fip->field_tag == TIFFTAG_DOTRANGE
609  && strcmp(fip->field_name,"DotRange") == 0) {
610  /* TODO: This is an evil exception and should not have been
611  handled this way ... likely best if we move it into
612  the directory structure with an explicit field in
613  libtiff 4.1 and assign it a FIELD_ value */
614  uint16 v2[2];
615  v2[0] = (uint16)va_arg(ap, int);
616  v2[1] = (uint16)va_arg(ap, int);
617  _TIFFmemcpy(tv->value, &v2, 4);
618  }
619 
620  else if (fip->field_passcount
623  || fip->field_writecount == TIFF_SPP
624  || tv->count > 1) {
625  _TIFFmemcpy(tv->value, va_arg(ap, void *),
626  tv->count * tv_size);
627  } else {
628  char *val = (char *)tv->value;
629  assert( tv->count == 1 );
630 
631  switch (fip->field_type) {
632  case TIFF_BYTE:
633  case TIFF_UNDEFINED:
634  {
635  uint8 v2 = (uint8)va_arg(ap, int);
636  _TIFFmemcpy(val, &v2, tv_size);
637  }
638  break;
639  case TIFF_SBYTE:
640  {
641  int8 v2 = (int8)va_arg(ap, int);
642  _TIFFmemcpy(val, &v2, tv_size);
643  }
644  break;
645  case TIFF_SHORT:
646  {
647  uint16 v2 = (uint16)va_arg(ap, int);
648  _TIFFmemcpy(val, &v2, tv_size);
649  }
650  break;
651  case TIFF_SSHORT:
652  {
653  int16 v2 = (int16)va_arg(ap, int);
654  _TIFFmemcpy(val, &v2, tv_size);
655  }
656  break;
657  case TIFF_LONG:
658  case TIFF_IFD:
659  {
660  uint32 v2 = va_arg(ap, uint32);
661  _TIFFmemcpy(val, &v2, tv_size);
662  }
663  break;
664  case TIFF_SLONG:
665  {
666  int32 v2 = va_arg(ap, int32);
667  _TIFFmemcpy(val, &v2, tv_size);
668  }
669  break;
670  case TIFF_LONG8:
671  case TIFF_IFD8:
672  {
673  uint64 v2 = va_arg(ap, uint64);
674  _TIFFmemcpy(val, &v2, tv_size);
675  }
676  break;
677  case TIFF_SLONG8:
678  {
679  int64 v2 = va_arg(ap, int64);
680  _TIFFmemcpy(val, &v2, tv_size);
681  }
682  break;
683  case TIFF_RATIONAL:
684  case TIFF_SRATIONAL:
685  case TIFF_FLOAT:
686  {
687  float v2 = TIFFClampDoubleToFloat(va_arg(ap, double));
688  _TIFFmemcpy(val, &v2, tv_size);
689  }
690  break;
691  case TIFF_DOUBLE:
692  {
693  double v2 = va_arg(ap, double);
694  _TIFFmemcpy(val, &v2, tv_size);
695  }
696  break;
697  default:
698  _TIFFmemset(val, 0, tv_size);
699  status = 0;
700  break;
701  }
702  }
703  }
704  }
705  }
706  if (status) {
707  const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
708  if (fip2)
709  TIFFSetFieldBit(tif, fip2->field_bit);
710  tif->tif_flags |= TIFF_DIRTYDIRECT;
711  }
712 
713 end:
714  va_end(ap);
715  return (status);
716 badvalue:
717  {
718  const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
720  "%s: Bad value %u for \"%s\" tag",
721  tif->tif_name, v,
722  fip2 ? fip2->field_name : "Unknown");
723  va_end(ap);
724  }
725  return (0);
726 badvalue32:
727  {
728  const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
730  "%s: Bad value %u for \"%s\" tag",
731  tif->tif_name, v32,
732  fip2 ? fip2->field_name : "Unknown");
733  va_end(ap);
734  }
735  return (0);
736 badvaluedouble:
737  {
738  const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
740  "%s: Bad value %f for \"%s\" tag",
741  tif->tif_name, dblval,
742  fip2 ? fip2->field_name : "Unknown");
743  va_end(ap);
744  }
745  return (0);
746 }
747 
748 /*
749  * Return 1/0 according to whether or not
750  * it is permissible to set the tag's value.
751  * Note that we allow ImageLength to be changed
752  * so that we can append and extend to images.
753  * Any other tag may not be altered once writing
754  * has commenced, unless its value has no effect
755  * on the format of the data that is written.
756  */
757 static int
759 {
760  const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
761  if (!fip) { /* unknown tag */
762  TIFFErrorExt(tif->tif_clientdata, "TIFFSetField", "%s: Unknown %stag %u",
763  tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", tag);
764  return (0);
765  }
766  if (tag != TIFFTAG_IMAGELENGTH && (tif->tif_flags & TIFF_BEENWRITING) &&
767  !fip->field_oktochange) {
768  /*
769  * Consult info table to see if tag can be changed
770  * after we've started writing. We only allow changes
771  * to those tags that don't/shouldn't affect the
772  * compression and/or format of the data.
773  */
774  TIFFErrorExt(tif->tif_clientdata, "TIFFSetField",
775  "%s: Cannot modify tag \"%s\" while writing",
776  tif->tif_name, fip->field_name);
777  return (0);
778  }
779  return (1);
780 }
781 
782 /*
783  * Record the value of a field in the
784  * internal directory structure. The
785  * field will be written to the file
786  * when/if the directory structure is
787  * updated.
788  */
789 int
791 {
792  va_list ap;
793  int status;
794 
795  va_start(ap, tag);
796  status = TIFFVSetField(tif, tag, ap);
797  va_end(ap);
798  return (status);
799 }
800 
801 /*
802  * Clear the contents of the field in the internal structure.
803  */
804 int
806 {
807  const TIFFField *fip = TIFFFieldWithTag(tif, tag);
808  TIFFDirectory* td = &tif->tif_dir;
809 
810  if( !fip )
811  return 0;
812 
813  if( fip->field_bit != FIELD_CUSTOM )
814  TIFFClrFieldBit(tif, fip->field_bit);
815  else
816  {
817  TIFFTagValue *tv = NULL;
818  int i;
819 
820  for (i = 0; i < td->td_customValueCount; i++) {
821 
822  tv = td->td_customValues + i;
823  if( tv->info->field_tag == tag )
824  break;
825  }
826 
827  if( i < td->td_customValueCount )
828  {
829  _TIFFfree(tv->value);
830  for( ; i < td->td_customValueCount-1; i++) {
831  td->td_customValues[i] = td->td_customValues[i+1];
832  }
833  td->td_customValueCount--;
834  }
835  }
836 
837  tif->tif_flags |= TIFF_DIRTYDIRECT;
838 
839  return (1);
840 }
841 
842 /*
843  * Like TIFFSetField, but taking a varargs
844  * parameter list. This routine is useful
845  * for building higher-level interfaces on
846  * top of the library.
847  */
848 int
850 {
851  return OkToChangeTag(tif, tag) ?
852  (*tif->tif_tagmethods.vsetfield)(tif, tag, ap) : 0;
853 }
854 
855 static int
857 {
858  TIFFDirectory* td = &tif->tif_dir;
859  int ret_val = 1;
860  uint32 standard_tag = tag;
861  const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
862  if( fip == NULL ) /* cannot happen since TIFFGetField() already checks it */
863  return 0;
864 
865  /*
866  * We want to force the custom code to be used for custom
867  * fields even if the tag happens to match a well known
868  * one - important for reinterpreted handling of standard
869  * tag values in custom directories (i.e. EXIF)
870  */
871  if (fip->field_bit == FIELD_CUSTOM) {
872  standard_tag = 0;
873  }
874 
875  if( standard_tag == TIFFTAG_NUMBEROFINKS )
876  {
877  int i;
878  for (i = 0; i < td->td_customValueCount; i++) {
879  uint16 val;
880  TIFFTagValue *tv = td->td_customValues + i;
881  if (tv->info->field_tag != standard_tag)
882  continue;
883  if( tv->value == NULL )
884  return 0;
885  val = *(uint16 *)tv->value;
886  /* Truncate to SamplesPerPixel, since the */
887  /* setting code for INKNAMES assume that there are SamplesPerPixel */
888  /* inknames. */
889  /* Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2599 */
890  if( val > td->td_samplesperpixel )
891  {
892  TIFFWarningExt(tif->tif_clientdata,"_TIFFVGetField",
893  "Truncating NumberOfInks from %u to %u",
894  val, td->td_samplesperpixel);
895  val = td->td_samplesperpixel;
896  }
897  *va_arg(ap, uint16*) = val;
898  return 1;
899  }
900  return 0;
901  }
902 
903  switch (standard_tag) {
904  case TIFFTAG_SUBFILETYPE:
905  *va_arg(ap, uint32*) = td->td_subfiletype;
906  break;
907  case TIFFTAG_IMAGEWIDTH:
908  *va_arg(ap, uint32*) = td->td_imagewidth;
909  break;
910  case TIFFTAG_IMAGELENGTH:
911  *va_arg(ap, uint32*) = td->td_imagelength;
912  break;
914  *va_arg(ap, uint16*) = td->td_bitspersample;
915  break;
916  case TIFFTAG_COMPRESSION:
917  *va_arg(ap, uint16*) = td->td_compression;
918  break;
919  case TIFFTAG_PHOTOMETRIC:
920  *va_arg(ap, uint16*) = td->td_photometric;
921  break;
923  *va_arg(ap, uint16*) = td->td_threshholding;
924  break;
925  case TIFFTAG_FILLORDER:
926  *va_arg(ap, uint16*) = td->td_fillorder;
927  break;
928  case TIFFTAG_ORIENTATION:
929  *va_arg(ap, uint16*) = td->td_orientation;
930  break;
933  break;
935  *va_arg(ap, uint32*) = td->td_rowsperstrip;
936  break;
938  *va_arg(ap, uint16*) = td->td_minsamplevalue;
939  break;
941  *va_arg(ap, uint16*) = td->td_maxsamplevalue;
942  break;
944  if (tif->tif_flags & TIFF_PERSAMPLE)
945  *va_arg(ap, double**) = td->td_sminsamplevalue;
946  else
947  {
948  /* libtiff historically treats this as a single value. */
949  uint16 i;
950  double v = td->td_sminsamplevalue[0];
951  for (i=1; i < td->td_samplesperpixel; ++i)
952  if( td->td_sminsamplevalue[i] < v )
953  v = td->td_sminsamplevalue[i];
954  *va_arg(ap, double*) = v;
955  }
956  break;
958  if (tif->tif_flags & TIFF_PERSAMPLE)
959  *va_arg(ap, double**) = td->td_smaxsamplevalue;
960  else
961  {
962  /* libtiff historically treats this as a single value. */
963  uint16 i;
964  double v = td->td_smaxsamplevalue[0];
965  for (i=1; i < td->td_samplesperpixel; ++i)
966  if( td->td_smaxsamplevalue[i] > v )
967  v = td->td_smaxsamplevalue[i];
968  *va_arg(ap, double*) = v;
969  }
970  break;
971  case TIFFTAG_XRESOLUTION:
972  *va_arg(ap, float*) = td->td_xresolution;
973  break;
974  case TIFFTAG_YRESOLUTION:
975  *va_arg(ap, float*) = td->td_yresolution;
976  break;
978  *va_arg(ap, uint16*) = td->td_planarconfig;
979  break;
980  case TIFFTAG_XPOSITION:
981  *va_arg(ap, float*) = td->td_xposition;
982  break;
983  case TIFFTAG_YPOSITION:
984  *va_arg(ap, float*) = td->td_yposition;
985  break;
987  *va_arg(ap, uint16*) = td->td_resolutionunit;
988  break;
989  case TIFFTAG_PAGENUMBER:
990  *va_arg(ap, uint16*) = td->td_pagenumber[0];
991  *va_arg(ap, uint16*) = td->td_pagenumber[1];
992  break;
994  *va_arg(ap, uint16*) = td->td_halftonehints[0];
995  *va_arg(ap, uint16*) = td->td_halftonehints[1];
996  break;
997  case TIFFTAG_COLORMAP:
998  *va_arg(ap, uint16**) = td->td_colormap[0];
999  *va_arg(ap, uint16**) = td->td_colormap[1];
1000  *va_arg(ap, uint16**) = td->td_colormap[2];
1001  break;
1002  case TIFFTAG_STRIPOFFSETS:
1003  case TIFFTAG_TILEOFFSETS:
1004  _TIFFFillStriles( tif );
1005  *va_arg(ap, uint64**) = td->td_stripoffset;
1006  break;
1009  _TIFFFillStriles( tif );
1010  *va_arg(ap, uint64**) = td->td_stripbytecount;
1011  break;
1012  case TIFFTAG_MATTEING:
1013  *va_arg(ap, uint16*) =
1014  (td->td_extrasamples == 1 &&
1016  break;
1017  case TIFFTAG_EXTRASAMPLES:
1018  *va_arg(ap, uint16*) = td->td_extrasamples;
1019  *va_arg(ap, uint16**) = td->td_sampleinfo;
1020  break;
1021  case TIFFTAG_TILEWIDTH:
1022  *va_arg(ap, uint32*) = td->td_tilewidth;
1023  break;
1024  case TIFFTAG_TILELENGTH:
1025  *va_arg(ap, uint32*) = td->td_tilelength;
1026  break;
1027  case TIFFTAG_TILEDEPTH:
1028  *va_arg(ap, uint32*) = td->td_tiledepth;
1029  break;
1030  case TIFFTAG_DATATYPE:
1031  switch (td->td_sampleformat) {
1032  case SAMPLEFORMAT_UINT:
1033  *va_arg(ap, uint16*) = DATATYPE_UINT;
1034  break;
1035  case SAMPLEFORMAT_INT:
1036  *va_arg(ap, uint16*) = DATATYPE_INT;
1037  break;
1038  case SAMPLEFORMAT_IEEEFP:
1040  break;
1041  case SAMPLEFORMAT_VOID:
1042  *va_arg(ap, uint16*) = DATATYPE_VOID;
1043  break;
1044  }
1045  break;
1046  case TIFFTAG_SAMPLEFORMAT:
1047  *va_arg(ap, uint16*) = td->td_sampleformat;
1048  break;
1049  case TIFFTAG_IMAGEDEPTH:
1050  *va_arg(ap, uint32*) = td->td_imagedepth;
1051  break;
1052  case TIFFTAG_SUBIFD:
1053  *va_arg(ap, uint16*) = td->td_nsubifd;
1054  *va_arg(ap, uint64**) = td->td_subifd;
1055  break;
1057  *va_arg(ap, uint16*) = td->td_ycbcrpositioning;
1058  break;
1060  *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[0];
1061  *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1];
1062  break;
1064  *va_arg(ap, uint16**) = td->td_transferfunction[0];
1065  if (td->td_samplesperpixel - td->td_extrasamples > 1) {
1066  *va_arg(ap, uint16**) = td->td_transferfunction[1];
1067  *va_arg(ap, uint16**) = td->td_transferfunction[2];
1068  } else {
1069  *va_arg(ap, uint16**) = NULL;
1070  *va_arg(ap, uint16**) = NULL;
1071  }
1072  break;
1074  *va_arg(ap, float**) = td->td_refblackwhite;
1075  break;
1076  case TIFFTAG_INKNAMES:
1077  *va_arg(ap, char**) = td->td_inknames;
1078  break;
1079  default:
1080  {
1081  int i;
1082 
1083  /*
1084  * This can happen if multiple images are open
1085  * with different codecs which have private
1086  * tags. The global tag information table may
1087  * then have tags that are valid for one file
1088  * but not the other. If the client tries to
1089  * get a tag that is not valid for the image's
1090  * codec then we'll arrive here.
1091  */
1092  if( fip->field_bit != FIELD_CUSTOM )
1093  {
1094  TIFFErrorExt(tif->tif_clientdata, "_TIFFVGetField",
1095  "%s: Invalid %stag \"%s\" "
1096  "(not supported by codec)",
1097  tif->tif_name,
1098  isPseudoTag(tag) ? "pseudo-" : "",
1099  fip->field_name);
1100  ret_val = 0;
1101  break;
1102  }
1103 
1104  /*
1105  * Do we have a custom value?
1106  */
1107  ret_val = 0;
1108  for (i = 0; i < td->td_customValueCount; i++) {
1109  TIFFTagValue *tv = td->td_customValues + i;
1110 
1111  if (tv->info->field_tag != tag)
1112  continue;
1113 
1114  if (fip->field_passcount) {
1115  if (fip->field_readcount == TIFF_VARIABLE2)
1116  *va_arg(ap, uint32*) = (uint32)tv->count;
1117  else /* Assume TIFF_VARIABLE */
1118  *va_arg(ap, uint16*) = (uint16)tv->count;
1119  *va_arg(ap, void **) = tv->value;
1120  ret_val = 1;
1121  } else if (fip->field_tag == TIFFTAG_DOTRANGE
1122  && strcmp(fip->field_name,"DotRange") == 0) {
1123  /* TODO: This is an evil exception and should not have been
1124  handled this way ... likely best if we move it into
1125  the directory structure with an explicit field in
1126  libtiff 4.1 and assign it a FIELD_ value */
1127  *va_arg(ap, uint16*) = ((uint16 *)tv->value)[0];
1128  *va_arg(ap, uint16*) = ((uint16 *)tv->value)[1];
1129  ret_val = 1;
1130  } else {
1131  if (fip->field_type == TIFF_ASCII
1132  || fip->field_readcount == TIFF_VARIABLE
1133  || fip->field_readcount == TIFF_VARIABLE2
1134  || fip->field_readcount == TIFF_SPP
1135  || tv->count > 1) {
1136  *va_arg(ap, void **) = tv->value;
1137  ret_val = 1;
1138  } else {
1139  char *val = (char *)tv->value;
1140  assert( tv->count == 1 );
1141  switch (fip->field_type) {
1142  case TIFF_BYTE:
1143  case TIFF_UNDEFINED:
1144  *va_arg(ap, uint8*) =
1145  *(uint8 *)val;
1146  ret_val = 1;
1147  break;
1148  case TIFF_SBYTE:
1149  *va_arg(ap, int8*) =
1150  *(int8 *)val;
1151  ret_val = 1;
1152  break;
1153  case TIFF_SHORT:
1154  *va_arg(ap, uint16*) =
1155  *(uint16 *)val;
1156  ret_val = 1;
1157  break;
1158  case TIFF_SSHORT:
1159  *va_arg(ap, int16*) =
1160  *(int16 *)val;
1161  ret_val = 1;
1162  break;
1163  case TIFF_LONG:
1164  case TIFF_IFD:
1165  *va_arg(ap, uint32*) =
1166  *(uint32 *)val;
1167  ret_val = 1;
1168  break;
1169  case TIFF_SLONG:
1170  *va_arg(ap, int32*) =
1171  *(int32 *)val;
1172  ret_val = 1;
1173  break;
1174  case TIFF_LONG8:
1175  case TIFF_IFD8:
1176  *va_arg(ap, uint64*) =
1177  *(uint64 *)val;
1178  ret_val = 1;
1179  break;
1180  case TIFF_SLONG8:
1181  *va_arg(ap, int64*) =
1182  *(int64 *)val;
1183  ret_val = 1;
1184  break;
1185  case TIFF_RATIONAL:
1186  case TIFF_SRATIONAL:
1187  case TIFF_FLOAT:
1188  *va_arg(ap, float*) =
1189  *(float *)val;
1190  ret_val = 1;
1191  break;
1192  case TIFF_DOUBLE:
1193  *va_arg(ap, double*) =
1194  *(double *)val;
1195  ret_val = 1;
1196  break;
1197  default:
1198  ret_val = 0;
1199  break;
1200  }
1201  }
1202  }
1203  break;
1204  }
1205  }
1206  }
1207  return(ret_val);
1208 }
1209 
1210 /*
1211  * Return the value of a field in the
1212  * internal directory structure.
1213  */
1214 int
1216 {
1217  int status;
1218  va_list ap;
1219 
1220  va_start(ap, tag);
1221  status = TIFFVGetField(tif, tag, ap);
1222  va_end(ap);
1223  return (status);
1224 }
1225 
1226 /*
1227  * Like TIFFGetField, but taking a varargs
1228  * parameter list. This routine is useful
1229  * for building higher-level interfaces on
1230  * top of the library.
1231  */
1232 int
1234 {
1235  const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
1236  return (fip && (isPseudoTag(tag) || TIFFFieldSet(tif, fip->field_bit)) ?
1237  (*tif->tif_tagmethods.vgetfield)(tif, tag, ap) : 0);
1238 }
1239 
1240 #define CleanupField(member) { \
1241  if (td->member) { \
1242  _TIFFfree(td->member); \
1243  td->member = 0; \
1244  } \
1245 }
1246 
1247 /*
1248  * Release storage associated with a directory.
1249  */
1250 void
1252 {
1253  TIFFDirectory *td = &tif->tif_dir;
1254  int i;
1255 
1257  CleanupField(td_sminsamplevalue);
1258  CleanupField(td_smaxsamplevalue);
1259  CleanupField(td_colormap[0]);
1260  CleanupField(td_colormap[1]);
1261  CleanupField(td_colormap[2]);
1262  CleanupField(td_sampleinfo);
1263  CleanupField(td_subifd);
1264  CleanupField(td_inknames);
1265  CleanupField(td_refblackwhite);
1266  CleanupField(td_transferfunction[0]);
1267  CleanupField(td_transferfunction[1]);
1268  CleanupField(td_transferfunction[2]);
1269  CleanupField(td_stripoffset);
1270  CleanupField(td_stripbytecount);
1273 
1274  /* Cleanup custom tag values */
1275  for( i = 0; i < td->td_customValueCount; i++ ) {
1276  if (td->td_customValues[i].value)
1278  }
1279 
1280  td->td_customValueCount = 0;
1281  CleanupField(td_customValues);
1282 
1283 #if defined(DEFER_STRILE_LOAD)
1284  _TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
1285  _TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry));
1286 #endif
1287 }
1288 #undef CleanupField
1289 
1290 /*
1291  * Client Tag extension support (from Niles Ritter).
1292  */
1294 
1297 {
1299  _TIFFextender = extender;
1300  return (prev);
1301 }
1302 
1303 /*
1304  * Setup for a new directory. Should we automatically call
1305  * TIFFWriteDirectory() if the current one is dirty?
1306  *
1307  * The newly created directory will not exist on the file till
1308  * TIFFWriteDirectory(), TIFFFlush() or TIFFClose() is called.
1309  */
1310 int
1312 {
1313  TIFFDefaultDirectory(tif);
1314  tif->tif_diroff = 0;
1315  tif->tif_nextdiroff = 0;
1316  tif->tif_curoff = 0;
1317  tif->tif_row = (uint32) -1;
1318  tif->tif_curstrip = (uint32) -1;
1319 
1320  return 0;
1321 }
1322 
1323 int
1325 {
1326  TIFFDefaultDirectory(tif);
1327 
1328  /*
1329  * Reset the field definitions to match the application provided list.
1330  * Hopefully TIFFDefaultDirectory() won't have done anything irreversable
1331  * based on it's assumption this is an image directory.
1332  */
1333  _TIFFSetupFields(tif, infoarray);
1334 
1335  tif->tif_diroff = 0;
1336  tif->tif_nextdiroff = 0;
1337  tif->tif_curoff = 0;
1338  tif->tif_row = (uint32) -1;
1339  tif->tif_curstrip = (uint32) -1;
1340 
1341  return 0;
1342 }
1343 
1344 int
1346 {
1350 }
1351 
1352 /*
1353  * Setup a default directory structure.
1354  */
1355 int
1357 {
1358  register TIFFDirectory* td = &tif->tif_dir;
1360 
1363 
1364  _TIFFmemset(td, 0, sizeof (*td));
1366  td->td_bitspersample = 1;
1369  td->td_samplesperpixel = 1;
1370  td->td_rowsperstrip = (uint32) -1;
1371  td->td_tilewidth = 0;
1372  td->td_tilelength = 0;
1373  td->td_tiledepth = 1;
1374  td->td_stripbytecountsorted = 1; /* Our own arrays always sorted. */
1377  td->td_imagedepth = 1;
1378  td->td_ycbcrsubsampling[0] = 2;
1379  td->td_ycbcrsubsampling[1] = 2;
1382  tif->tif_foundfield = NULL;
1385  tif->tif_tagmethods.printdir = NULL;
1386  /*
1387  * Give client code a chance to install their own
1388  * tag extensions & methods, prior to compression overloads,
1389  * but do some prior cleanup first. (http://trac.osgeo.org/gdal/ticket/5054)
1390  */
1391  if (tif->tif_nfieldscompat > 0) {
1392  uint32 i;
1393 
1394  for (i = 0; i < tif->tif_nfieldscompat; i++) {
1395  if (tif->tif_fieldscompat[i].allocated_size)
1397  }
1399  tif->tif_nfieldscompat = 0;
1400  tif->tif_fieldscompat = NULL;
1401  }
1402  if (_TIFFextender)
1403  (*_TIFFextender)(tif);
1405  /*
1406  * NB: The directory is marked dirty as a result of setting
1407  * up the default compression scheme. However, this really
1408  * isn't correct -- we want TIFF_DIRTYDIRECT to be set only
1409  * if the user does something. We could just do the setup
1410  * by hand, but it seems better to use the normal mechanism
1411  * (i.e. TIFFSetField).
1412  */
1413  tif->tif_flags &= ~TIFF_DIRTYDIRECT;
1414 
1415  /*
1416  * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19
1417  * we clear the ISTILED flag when setting up a new directory.
1418  * Should we also be clearing stuff like INSUBIFD?
1419  */
1420  tif->tif_flags &= ~TIFF_ISTILED;
1421 
1422  return (1);
1423 }
1424 
1425 static int
1427 {
1428  static const char module[] = "TIFFAdvanceDirectory";
1429  if (isMapped(tif))
1430  {
1431  uint64 poff=*nextdir;
1432  if (!(tif->tif_flags&TIFF_BIGTIFF))
1433  {
1434  tmsize_t poffa,poffb,poffc,poffd;
1435  uint16 dircount;
1436  uint32 nextdir32;
1437  poffa=(tmsize_t)poff;
1438  poffb=poffa+sizeof(uint16);
1439  if (((uint64)poffa!=poff)||(poffb<poffa)||(poffb<(tmsize_t)sizeof(uint16))||(poffb>tif->tif_size))
1440  {
1441  TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory count");
1442  *nextdir=0;
1443  return(0);
1444  }
1445  _TIFFmemcpy(&dircount,tif->tif_base+poffa,sizeof(uint16));
1446  if (tif->tif_flags&TIFF_SWAB)
1447  TIFFSwabShort(&dircount);
1448  poffc=poffb+dircount*12;
1449  poffd=poffc+sizeof(uint32);
1450  if ((poffc<poffb)||(poffc<dircount*12)||(poffd<poffc)||(poffd<(tmsize_t)sizeof(uint32))||(poffd>tif->tif_size))
1451  {
1452  TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory link");
1453  return(0);
1454  }
1455  if (off!=NULL)
1456  *off=(uint64)poffc;
1457  _TIFFmemcpy(&nextdir32,tif->tif_base+poffc,sizeof(uint32));
1458  if (tif->tif_flags&TIFF_SWAB)
1459  TIFFSwabLong(&nextdir32);
1460  *nextdir=nextdir32;
1461  }
1462  else
1463  {
1464  tmsize_t poffa,poffb,poffc,poffd;
1465  uint64 dircount64;
1466  uint16 dircount16;
1467  poffa=(tmsize_t)poff;
1468  poffb=poffa+sizeof(uint64);
1469  if (((uint64)poffa!=poff)||(poffb<poffa)||(poffb<(tmsize_t)sizeof(uint64))||(poffb>tif->tif_size))
1470  {
1471  TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory count");
1472  return(0);
1473  }
1474  _TIFFmemcpy(&dircount64,tif->tif_base+poffa,sizeof(uint64));
1475  if (tif->tif_flags&TIFF_SWAB)
1476  TIFFSwabLong8(&dircount64);
1477  if (dircount64>0xFFFF)
1478  {
1479  TIFFErrorExt(tif->tif_clientdata,module,"Sanity check on directory count failed");
1480  return(0);
1481  }
1482  dircount16=(uint16)dircount64;
1483  poffc=poffb+dircount16*20;
1484  poffd=poffc+sizeof(uint64);
1485  if ((poffc<poffb)||(poffc<dircount16*20)||(poffd<poffc)||(poffd<(tmsize_t)sizeof(uint64))||(poffd>tif->tif_size))
1486  {
1487  TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory link");
1488  return(0);
1489  }
1490  if (off!=NULL)
1491  *off=(uint64)poffc;
1492  _TIFFmemcpy(nextdir,tif->tif_base+poffc,sizeof(uint64));
1493  if (tif->tif_flags&TIFF_SWAB)
1494  TIFFSwabLong8(nextdir);
1495  }
1496  return(1);
1497  }
1498  else
1499  {
1500  if (!(tif->tif_flags&TIFF_BIGTIFF))
1501  {
1502  uint16 dircount;
1503  uint32 nextdir32;
1504  if (!SeekOK(tif, *nextdir) ||
1505  !ReadOK(tif, &dircount, sizeof (uint16))) {
1506  TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count",
1507  tif->tif_name);
1508  return (0);
1509  }
1510  if (tif->tif_flags & TIFF_SWAB)
1511  TIFFSwabShort(&dircount);
1512  if (off != NULL)
1513  *off = TIFFSeekFile(tif,
1514  dircount*12, SEEK_CUR);
1515  else
1516  (void) TIFFSeekFile(tif,
1517  dircount*12, SEEK_CUR);
1518  if (!ReadOK(tif, &nextdir32, sizeof (uint32))) {
1519  TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory link",
1520  tif->tif_name);
1521  return (0);
1522  }
1523  if (tif->tif_flags & TIFF_SWAB)
1524  TIFFSwabLong(&nextdir32);
1525  *nextdir=nextdir32;
1526  }
1527  else
1528  {
1529  uint64 dircount64;
1530  uint16 dircount16;
1531  if (!SeekOK(tif, *nextdir) ||
1532  !ReadOK(tif, &dircount64, sizeof (uint64))) {
1533  TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count",
1534  tif->tif_name);
1535  return (0);
1536  }
1537  if (tif->tif_flags & TIFF_SWAB)
1538  TIFFSwabLong8(&dircount64);
1539  if (dircount64>0xFFFF)
1540  {
1541  TIFFErrorExt(tif->tif_clientdata, module, "Error fetching directory count");
1542  return(0);
1543  }
1544  dircount16 = (uint16)dircount64;
1545  if (off != NULL)
1546  *off = TIFFSeekFile(tif,
1547  dircount16*20, SEEK_CUR);
1548  else
1549  (void) TIFFSeekFile(tif,
1550  dircount16*20, SEEK_CUR);
1551  if (!ReadOK(tif, nextdir, sizeof (uint64))) {
1553  "%s: Error fetching directory link",
1554  tif->tif_name);
1555  return (0);
1556  }
1557  if (tif->tif_flags & TIFF_SWAB)
1558  TIFFSwabLong8(nextdir);
1559  }
1560  return (1);
1561  }
1562 }
1563 
1564 /*
1565  * Count the number of directories in a file.
1566  */
1567 uint16
1569 {
1570  static const char module[] = "TIFFNumberOfDirectories";
1571  uint64 nextdir;
1572  uint16 n;
1573  if (!(tif->tif_flags&TIFF_BIGTIFF))
1574  nextdir = tif->tif_header.classic.tiff_diroff;
1575  else
1576  nextdir = tif->tif_header.big.tiff_diroff;
1577  n = 0;
1578  while (nextdir != 0 && TIFFAdvanceDirectory(tif, &nextdir, NULL))
1579  {
1580  if (n != 65535) {
1581  ++n;
1582  }
1583  else
1584  {
1586  "Directory count exceeded 65535 limit,"
1587  " giving up on counting.");
1588  return (65535);
1589  }
1590  }
1591  return (n);
1592 }
1593 
1594 /*
1595  * Set the n-th directory as the current directory.
1596  * NB: Directories are numbered starting at 0.
1597  */
1598 int
1600 {
1601  uint64 nextdir;
1602  uint16 n;
1603 
1604  if (!(tif->tif_flags&TIFF_BIGTIFF))
1605  nextdir = tif->tif_header.classic.tiff_diroff;
1606  else
1607  nextdir = tif->tif_header.big.tiff_diroff;
1608  for (n = dirn; n > 0 && nextdir != 0; n--)
1609  if (!TIFFAdvanceDirectory(tif, &nextdir, NULL))
1610  return (0);
1611  tif->tif_nextdiroff = nextdir;
1612  /*
1613  * Set curdir to the actual directory index. The
1614  * -1 is because TIFFReadDirectory will increment
1615  * tif_curdir after successfully reading the directory.
1616  */
1617  tif->tif_curdir = (dirn - n) - 1;
1618  /*
1619  * Reset tif_dirnumber counter and start new list of seen directories.
1620  * We need this to prevent IFD loops.
1621  */
1622  tif->tif_dirnumber = 0;
1623  return (TIFFReadDirectory(tif));
1624 }
1625 
1626 /*
1627  * Set the current directory to be the directory
1628  * located at the specified file offset. This interface
1629  * is used mainly to access directories linked with
1630  * the SubIFD tag (e.g. thumbnail images).
1631  */
1632 int
1634 {
1635  tif->tif_nextdiroff = diroff;
1636  /*
1637  * Reset tif_dirnumber counter and start new list of seen directories.
1638  * We need this to prevent IFD loops.
1639  */
1640  tif->tif_dirnumber = 0;
1641  return (TIFFReadDirectory(tif));
1642 }
1643 
1644 /*
1645  * Return file offset of the current directory.
1646  */
1647 uint64
1649 {
1650  return (tif->tif_diroff);
1651 }
1652 
1653 /*
1654  * Return an indication of whether or not we are
1655  * at the last directory in the file.
1656  */
1657 int
1659 {
1660  return (tif->tif_nextdiroff == 0);
1661 }
1662 
1663 /*
1664  * Unlink the specified directory from the directory chain.
1665  */
1666 int
1668 {
1669  static const char module[] = "TIFFUnlinkDirectory";
1670  uint64 nextdir;
1671  uint64 off;
1672  uint16 n;
1673 
1674  if (tif->tif_mode == O_RDONLY) {
1676  "Can not unlink directory in read-only file");
1677  return (0);
1678  }
1679  /*
1680  * Go to the directory before the one we want
1681  * to unlink and nab the offset of the link
1682  * field we'll need to patch.
1683  */
1684  if (!(tif->tif_flags&TIFF_BIGTIFF))
1685  {
1686  nextdir = tif->tif_header.classic.tiff_diroff;
1687  off = 4;
1688  }
1689  else
1690  {
1691  nextdir = tif->tif_header.big.tiff_diroff;
1692  off = 8;
1693  }
1694  for (n = dirn-1; n > 0; n--) {
1695  if (nextdir == 0) {
1696  TIFFErrorExt(tif->tif_clientdata, module, "Directory %d does not exist", dirn);
1697  return (0);
1698  }
1699  if (!TIFFAdvanceDirectory(tif, &nextdir, &off))
1700  return (0);
1701  }
1702  /*
1703  * Advance to the directory to be unlinked and fetch
1704  * the offset of the directory that follows.
1705  */
1706  if (!TIFFAdvanceDirectory(tif, &nextdir, NULL))
1707  return (0);
1708  /*
1709  * Go back and patch the link field of the preceding
1710  * directory to point to the offset of the directory
1711  * that follows.
1712  */
1713  (void) TIFFSeekFile(tif, off, SEEK_SET);
1714  if (!(tif->tif_flags&TIFF_BIGTIFF))
1715  {
1716  uint32 nextdir32;
1717  nextdir32=(uint32)nextdir;
1718  assert((uint64)nextdir32==nextdir);
1719  if (tif->tif_flags & TIFF_SWAB)
1720  TIFFSwabLong(&nextdir32);
1721  if (!WriteOK(tif, &nextdir32, sizeof (uint32))) {
1722  TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link");
1723  return (0);
1724  }
1725  }
1726  else
1727  {
1728  if (tif->tif_flags & TIFF_SWAB)
1729  TIFFSwabLong8(&nextdir);
1730  if (!WriteOK(tif, &nextdir, sizeof (uint64))) {
1731  TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link");
1732  return (0);
1733  }
1734  }
1735  /*
1736  * Leave directory state setup safely. We don't have
1737  * facilities for doing inserting and removing directories,
1738  * so it's safest to just invalidate everything. This
1739  * means that the caller can only append to the directory
1740  * chain.
1741  */
1742  (*tif->tif_cleanup)(tif);
1743  if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {
1744  _TIFFfree(tif->tif_rawdata);
1745  tif->tif_rawdata = NULL;
1746  tif->tif_rawcc = 0;
1747  tif->tif_rawdataoff = 0;
1748  tif->tif_rawdataloaded = 0;
1749  }
1751  TIFFFreeDirectory(tif);
1752  TIFFDefaultDirectory(tif);
1753  tif->tif_diroff = 0; /* force link on next write */
1754  tif->tif_nextdiroff = 0; /* next write must be at end */
1755  tif->tif_curoff = 0;
1756  tif->tif_row = (uint32) -1;
1757  tif->tif_curstrip = (uint32) -1;
1758  return (1);
1759 }
1760 
1761 /* vim: set ts=8 sts=8 sw=8 noet: */
1762 /*
1763  * Local Variables:
1764  * mode: c
1765  * c-basic-offset: 8
1766  * fill-column: 78
1767  * End:
1768  */
unsigned long long uint64
Definition: platform.h:18
static void _TIFFsetNString(char **cpp, char *cp, uint32 n)
Definition: tif_dir.c:61
#define DATATYPE_IEEEFP
Definition: tif_dir.c:40
#define TIFFTAG_SUBFILETYPE
Definition: tiff.h:146
#define TIFF_BEENWRITING
Definition: tiffiop.h:112
TIFFTagMethods tif_tagmethods
Definition: tiffiop.h:203
void _TIFFsetString(char **cpp, char *cp)
Definition: tif_dir.c:59
void _TIFFsetLongArray(uint32 **lpp, uint32 *lp, uint32 n)
Definition: tif_dir.c:65
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
#define SEEK_CUR
Definition: util.h:63
#define TIFF_VARIABLE
Definition: tiffio.h:313
uint16 td_ycbcrpositioning
Definition: tif_dir.h:111
#define FIELD_CUSTOM
Definition: tiffio.h:317
uint64 TIFFCurrentDirOffset(TIFF *tif)
Definition: tif_dir.c:1648
float td_yposition
Definition: tif_dir.h:89
uint16 td_bitspersample
Definition: tif_dir.h:74
int TIFFReadDirectory(TIFF *tif)
Definition: tif_dirread.c:3542
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TIFFClrFieldBit(tif, field)
Definition: tif_dir.h:194
uint32 td_tiledepth
Definition: tif_dir.h:72
void _TIFFSwab64BitData(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1563
#define TIFFTAG_BITSPERSAMPLE
Definition: tiff.h:156
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_warning.c:65
static void setByteArray(void **vpp, void *vp, size_t nmemb, size_t elem_size)
Definition: tif_dir.c:43
#define TIFFTAG_ROWSPERSTRIP
Definition: tiff.h:233
uint8 * tif_base
Definition: tiffiop.h:186
int TIFFLastDirectory(TIFF *tif)
Definition: tif_dir.c:1658
#define TIFF_ANY
Definition: tiffio.h:312
char * td_inknames
Definition: tif_dir.h:117
int td_inknameslen
Definition: tif_dir.h:116
#define TIFFTAG_STRIPBYTECOUNTS
Definition: tiff.h:234
#define TIFFTAG_COLORMAP
Definition: tiff.h:284
#define THRESHHOLD_BILEVEL
Definition: tiff.h:210
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define FLT_MAX
Definition: gcc_float.h:107
static int _TIFFVGetField(TIFF *tif, uint32 tag, va_list ap)
Definition: tif_dir.c:856
#define TIFFTAG_EXTRASAMPLES
Definition: tiff.h:304
#define WriteOK(tif, buf, size)
Definition: tiffiop.h:243
#define TIFFTAG_ORIENTATION
Definition: tiff.h:223
#define isPseudoTag(t)
Definition: tiffiop.h:211
int TIFFSetSubDirectory(TIFF *tif, uint64 diroff)
Definition: tif_dir.c:1633
unsigned int uint32
Definition: types.h:32
#define TIFFSeekFile(tif, off, whence)
Definition: tiffiop.h:221
#define TIFF_ISTILED
Definition: tiffiop.h:116
#define TIFFTAG_IMAGEWIDTH
Definition: tiff.h:154
#define TIFFTAG_YRESOLUTION
Definition: tiff.h:238
static int OkToChangeTag(TIFF *tif, uint32 tag)
Definition: tif_dir.c:758
#define U(x)
Definition: wordpad.c:44
#define TIFFTAG_DATATYPE
Definition: tiff.h:385
#define TIFFTAG_MINSAMPLEVALUE
Definition: tiff.h:235
#define TIFFTAG_INKNAMES
Definition: tiff.h:300
#define TIFFTAG_FILLORDER
Definition: tiff.h:215
static const TIFFFieldArray tiffFieldArray
Definition: tif_dirinfo.c:48
TIFFTagValue * td_customValues
Definition: tif_dir.h:120
static void setDoubleArrayOneValue(double **vpp, double value, size_t nmemb)
Definition: tif_dir.c:75
uint32 tif_curstrip
Definition: tiffiop.h:145
uint16 td_halftonehints[2]
Definition: tif_dir.h:92
#define FILLORDER_LSB2MSB
Definition: tiff.h:217
GLdouble n
Definition: glext.h:7729
int count
Definition: tif_dir.h:37
#define assert(x)
Definition: debug.h:53
Definition: ecma_167.h:138
static int _TIFFVSetField(TIFF *tif, uint32 tag, va_list ap)
Definition: tif_dir.c:166
const TIFFFieldArray * _TIFFGetFields(void)
Definition: tif_dirinfo.c:305
#define TIFFTAG_DOTRANGE
Definition: tiff.h:302
uint8 * tif_rawdata
Definition: tiffiop.h:179
uint32 td_imagedepth
Definition: tif_dir.h:71
int td_customValueCount
Definition: tif_dir.h:119
#define TIFFTAG_STRIPOFFSETS
Definition: tiff.h:222
#define TIFFTAG_SUBIFD
Definition: tiff.h:296
#define TIFFTAG_THRESHHOLDING
Definition: tiff.h:209
GLuint GLuint end
Definition: gl.h:1545
#define PERSAMPLE_MULTI
Definition: tiff.h:609
#define TIFFTAG_YCBCRSUBSAMPLING
Definition: tiff.h:367
uint64 tif_curoff
Definition: tiffiop.h:146
thandle_t tif_clientdata
Definition: tiffiop.h:191
tmsize_t tif_rawdataoff
Definition: tiffiop.h:181
#define TIFFTAG_YPOSITION
Definition: tiff.h:244
#define TIFFTAG_SMINSAMPLEVALUE
Definition: tiff.h:315
long long int64
Definition: platform.h:13
#define TIFFTAG_REFERENCEBLACKWHITE
Definition: tiff.h:371
tmsize_t tif_rawcc
Definition: tiffiop.h:184
uint16 tif_curdir
Definition: tiffiop.h:144
#define TIFFTAG_PLANARCONFIG
Definition: tiff.h:239
#define ORIENTATION_TOPLEFT
Definition: tiff.h:224
#define TIFFTAG_MATTEING
Definition: tiff.h:384
char * tif_name
Definition: tiffiop.h:103
#define TIFF_DIRTYDIRECT
Definition: tiffiop.h:109
Definition: tiffiop.h:102
#define FIELD_YCBCRSUBSAMPLING
Definition: tif_dir.h:167
int TIFFUnsetField(TIFF *tif, uint32 tag)
Definition: tif_dir.c:805
int TIFFSetDirectory(TIFF *tif, uint16 dirn)
Definition: tif_dir.c:1599
#define FIELD_SETLONGS
Definition: tif_dir.h:67
#define SAMPLEFORMAT_INT
Definition: tiff.h:310
#define FIELD_SMAXSAMPLEVALUE
Definition: tif_dir.h:163
float td_xresolution
Definition: tif_dir.h:86
#define TIFFTAG_PERSAMPLE
Definition: tiff.h:607
#define RESUNIT_INCH
Definition: tiff.h:264
#define TIFFTAG_TILEBYTECOUNTS
Definition: tiff.h:289
uint32 td_tilelength
Definition: tif_dir.h:72
unsigned short field_bit
Definition: tif_dir.h:286
int TIFFGetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:1215
void _TIFFSwab32BitData(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1555
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
float td_xposition
Definition: tif_dir.h:89
#define TIFFSetFieldBit(tif, field)
Definition: tif_dir.h:193
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define TIFF_BIGTIFF
Definition: tiffiop.h:125
#define va_end(ap)
Definition: acmsvcex.h:90
#define TIFF_SWAB
Definition: tiffiop.h:113
#define TIFFTAG_YCBCRPOSITIONING
Definition: tiff.h:368
TIFFPrintMethod printdir
Definition: tiffio.h:340
#define TIFFTAG_TILEWIDTH
Definition: tiff.h:286
#define DATATYPE_VOID
Definition: tif_dir.c:37
char * field_name
Definition: tif_dir.h:289
int td_stripbytecountsorted
Definition: tif_dir.h:102
uint32 td_subfiletype
Definition: tif_dir.h:73
uint16 * td_sampleinfo
Definition: tif_dir.h:94
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:85
uint16 td_nsubifd
Definition: tif_dir.h:107
int TIFFCreateCustomDirectory(TIFF *tif, const TIFFFieldArray *infoarray)
Definition: tif_dir.c:1324
#define YCBCRPOSITION_CENTERED
Definition: tiff.h:369
uint16 td_resolutionunit
Definition: tif_dir.h:87
void _TIFFsetFloatArray(float **fpp, float *fp, uint32 n)
Definition: tif_dir.c:69
#define TIFFTAG_TILELENGTH
Definition: tiff.h:287
int tif_mode
Definition: tiffiop.h:105
static TIFFExtendProc _TIFFextender
Definition: tif_dir.c:1293
uint32 tif_flags
Definition: tiffiop.h:106
short field_writecount
Definition: tif_dir.h:281
smooth NULL
Definition: ftsmooth.c:416
#define TIFFTAG_IMAGELENGTH
Definition: tiff.h:155
#define TIFFTAG_TILEOFFSETS
Definition: tiff.h:288
#define TIFFTAG_SAMPLESPERPIXEL
Definition: tiff.h:232
char * va_list
Definition: acmsvcex.h:78
TIFFFieldArray * tif_fieldscompat
Definition: tiffiop.h:207
uint16 td_planarconfig
Definition: tif_dir.h:88
#define SAMPLEFORMAT_VOID
Definition: tiff.h:312
uint16 * td_colormap[3]
Definition: tif_dir.h:91
double * td_sminsamplevalue
Definition: tif_dir.h:84
uint64 tif_nextdiroff
Definition: tiffiop.h:131
#define TIFF_POSTENCODE
Definition: tiffiop.h:118
uint16 td_orientation
Definition: tif_dir.h:80
int TIFFVGetField(TIFF *tif, uint32 tag, va_list ap)
Definition: tif_dir.c:1233
#define EXTRASAMPLE_COREL_UNASSALPHA
uint16 td_minsamplevalue
Definition: tif_dir.h:83
#define isMapped(tif)
Definition: tiffiop.h:214
uint32 allocated_size
Definition: tif_dir.h:273
void * _TIFFmalloc(tmsize_t s)
Definition: tif_unix.c:309
#define CleanupField(member)
Definition: tif_dir.c:1240
uint16 TIFFNumberOfDirectories(TIFF *tif)
Definition: tif_dir.c:1568
GLuint GLfloat * val
Definition: glext.h:7180
void TIFFFreeDirectory(TIFF *tif)
Definition: tif_dir.c:1251
unsigned char field_passcount
Definition: tif_dir.h:288
#define TIFF_BUF4WRITE
Definition: tiffiop.h:126
#define SEEK_SET
Definition: jmemansi.c:26
int TIFFVSetField(TIFF *tif, uint32 tag, va_list ap)
Definition: tif_dir.c:849
void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *fieldarray)
Definition: tif_dirinfo.c:317
union tiff::@3297 tif_header
#define SAMPLEFORMAT_COMPLEXIEEEFP
Definition: tiff.h:314
#define SAMPLEFORMAT_UINT
Definition: tiff.h:309
void TIFFSwabShort(uint16 *wp)
Definition: tif_swab.c:34
static uint32 checkInkNamesString(TIFF *tif, uint32 slen, const char *s)
Definition: tif_dir.c:131
const TIFFField * info
Definition: tif_dir.h:36
int TIFFUnlinkDirectory(TIFF *tif, uint16 dirn)
Definition: tif_dir.c:1667
#define TIFF_PERSAMPLE
Definition: tiffiop.h:128
uint32 tiff_diroff
Definition: tiff.h:98
#define RESUNIT_CENTIMETER
Definition: tiff.h:265
uint16 td_extrasamples
Definition: tif_dir.h:93
uint32 td_imagelength
Definition: tif_dir.h:71
uint32 field_tag
Definition: tif_dir.h:279
#define SAMPLEFORMAT_IEEEFP
Definition: tiff.h:311
TIFFField * fields
Definition: tif_dir.h:275
int badvalue
Definition: class.c:931
TIFFPostMethod tif_postdecode
Definition: tiffiop.h:198
#define TIFFTAG_XPOSITION
Definition: tiff.h:243
uint16 td_photometric
Definition: tif_dir.h:77
#define TIFFTAG_HALFTONEHINTS
Definition: tiff.h:285
unsigned char uint8
Definition: types.h:28
void _TIFFSwab24BitData(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1547
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
double * td_smaxsamplevalue
Definition: tif_dir.h:85
#define TIFFTAG_PHOTOMETRIC
Definition: tiff.h:195
static int TIFFAdvanceDirectory(TIFF *tif, uint64 *nextdir, uint64 *off)
Definition: tif_dir.c:1426
#define EXTRASAMPLE_UNASSALPHA
Definition: tiff.h:307
#define TIFFFieldSet(tif, field)
Definition: tif_dir.h:192
uint16 td_fillorder
Definition: tif_dir.h:79
#define TIFFTAG_PAGENUMBER
Definition: tiff.h:266
static void _TIFFsetLong8Array(uint64 **lpp, uint64 *lp, uint32 n)
Definition: tif_dir.c:67
void _TIFFsetByteArray(void **vpp, void *vp, uint32 n)
Definition: tif_dir.c:57
#define FIELD_COMPRESSION
Definition: tif_dir.h:145
uint64 * td_stripoffset
Definition: tif_dir.h:100
#define FIELD_SMINSAMPLEVALUE
Definition: tif_dir.h:162
int uint16_vap
Definition: tiff.h:86
tmsize_t tif_rawdataloaded
Definition: tiffiop.h:182
uint16 tif_dirnumber
Definition: tiffiop.h:134
void(* TIFFExtendProc)(TIFF *)
Definition: tiffio.h:284
void * _TIFFrealloc(void *p, tmsize_t s)
Definition: tif_unix.c:332
static const WCHAR L[]
Definition: oid.c:1250
#define TIFFTAG_TRANSFERFUNCTION
Definition: tiff.h:273
uint64 tif_diroff
Definition: tiffiop.h:130
#define COMPRESSION_NONE
Definition: tiff.h:158
#define TIFFTAG_COMPRESSION
Definition: tiff.h:157
uint32 td_tilewidth
Definition: tif_dir.h:72
uint16 td_sampleformat
Definition: tif_dir.h:75
uint16 td_threshholding
Definition: tif_dir.h:78
tmsize_t tif_size
Definition: tiffiop.h:187
#define PLANARCONFIG_SEPARATE
Definition: tiff.h:241
uint64 * td_stripbytecount
Definition: tif_dir.h:101
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:172
GLdouble s
Definition: gl.h:2039
const TIFFFieldArray * _TIFFGetExifFields(void)
Definition: tif_dirinfo.c:311
void _TIFFNoPostDecode(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1533
void _TIFFSwab16BitData(TIFF *tif, uint8 *buf, tmsize_t cc)
Definition: tif_read.c:1539
uint16 td_pagenumber[2]
Definition: tif_dir.h:90
#define TIFFTAG_NUMBEROFINKS
Definition: tiff.h:301
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32 tag)
Definition: tif_dirinfo.c:558
unsigned char field_oktochange
Definition: tif_dir.h:287
#define TIFFTAG_SMAXSAMPLEVALUE
Definition: tiff.h:316
GLsizei const GLfloat * value
Definition: glext.h:6069
#define DATATYPE_UINT
Definition: tif_dir.c:39
#define TIFF_BUFFERSETUP
Definition: tiffiop.h:110
#define TIFF_CODERSETUP
Definition: tiffiop.h:111
#define FIELD_YCBCRPOSITIONING
Definition: tif_dir.h:168
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
int _TIFFDataSize(TIFFDataType type)
Definition: tif_dirinfo.c:476
#define TIFF_VARIABLE2
Definition: tiffio.h:315
uint16 td_maxsamplevalue
Definition: tif_dir.h:83
void * value
Definition: tif_dir.h:38
#define va_arg(ap, T)
Definition: acmsvcex.h:89
TIFFHeaderBig big
Definition: tiffiop.h:140
uint32 td_rowsperstrip
Definition: tif_dir.h:82
const GLdouble * v
Definition: gl.h:2040
uint64 * td_subifd
Definition: tif_dir.h:108
uint32 tif_row
Definition: tiffiop.h:143
TIFFDataType field_type
Definition: tif_dir.h:282
#define TIFFTAG_TILEDEPTH
Definition: tiff.h:387
TIFFVGetMethod vgetfield
Definition: tiffio.h:339
#define TIFFTAG_IMAGEDEPTH
Definition: tiff.h:386
#define TIFFTAG_RESOLUTIONUNIT
Definition: tiff.h:262
void TIFFSwabLong(uint32 *lp)
Definition: tif_swab.c:45
#define TIFF_SPP
Definition: tiffio.h:314
uint16 td_ycbcrsubsampling[2]
Definition: tif_dir.h:110
#define TIFFTAG_XRESOLUTION
Definition: tiff.h:237
unsigned short uint16
Definition: types.h:30
short int16
Definition: platform.h:11
TIFFDirectory tif_dir
Definition: tiffiop.h:135
static float TIFFClampDoubleToFloat(double val)
Definition: tif_dir.c:156
#define FIELD_TILEDIMENSIONS
Definition: tif_dir.h:138
#define va_start(ap, A)
Definition: acmsvcex.h:91
int TIFFSetCompressionScheme(TIFF *tif, int scheme)
Definition: tif_compress.c:160
#define SeekOK(tif, off)
Definition: tiffiop.h:240
float * td_refblackwhite
Definition: tif_dir.h:114
uint16 * td_transferfunction[3]
Definition: tif_dir.h:113
TIFFExtendProc TIFFSetTagExtender(TIFFExtendProc extender)
Definition: tif_dir.c:1296
#define SAMPLEFORMAT_COMPLEXINT
Definition: tiff.h:313
size_t tif_nfieldscompat
Definition: tiffiop.h:208
int TIFFCreateEXIFDirectory(TIFF *tif)
Definition: tif_dir.c:1345
unsigned long td_fieldsset[FIELD_SETLONGS]
Definition: tif_dir.h:69
int TIFFDefaultDirectory(TIFF *tif)
Definition: tif_dir.c:1356
void _TIFFsetShortArray(uint16 **wpp, uint16 *wp, uint32 n)
Definition: tif_dir.c:63
POINT cp
Definition: magnifier.c:60
long int32
Definition: platform.h:12
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
#define ReadOK(tif, buf, size)
Definition: tiffiop.h:236
TIFFVSetMethod vsetfield
Definition: tiffio.h:338
float td_yresolution
Definition: tif_dir.h:86
const TIFFField * TIFFFindField(TIFF *tif, uint32 tag, TIFFDataType dt)
Definition: tif_dirinfo.c:506
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define DATATYPE_INT
Definition: tif_dir.c:38
uint64 tiff_diroff
Definition: tiff.h:105
#define RESUNIT_NONE
Definition: tiff.h:263
uint16 td_samplesperpixel
Definition: tif_dir.h:81
static int setExtraSamples(TIFFDirectory *td, va_list ap, uint32 *v)
Definition: tif_dir.c:91
TIFFHeaderClassic classic
Definition: tiffiop.h:139
Definition: tiff.h:137
int TIFFCreateDirectory(TIFF *tif)
Definition: tif_dir.c:1311
uint16 td_compression
Definition: tif_dir.h:76
const TIFFField * tif_foundfield
Definition: tiffiop.h:202
void _TIFFfree(void *p)
Definition: tif_unix.c:326
#define TIFFTAG_SAMPLEFORMAT
Definition: tiff.h:308
#define EXTRASAMPLE_ASSOCALPHA
Definition: tiff.h:306
uint32 td_imagewidth
Definition: tif_dir.h:71
void _TIFFsetDoubleArray(double **dpp, double *dp, uint32 n)
Definition: tif_dir.c:71
#define ORIENTATION_LEFTBOT
Definition: tiff.h:231
static SERVICE_STATUS status
Definition: service.c:31
#define TIFF_INSUBIFD
Definition: tiffiop.h:119
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:790
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:344
static const TIFFFieldArray exifFieldArray
Definition: tif_dirinfo.c:49
#define FILLORDER_MSB2LSB
Definition: tiff.h:216
#define TIFFTAG_MAXSAMPLEVALUE
Definition: tiff.h:236
#define TIFF_MYBUFFER
Definition: tiffiop.h:115
void TIFFSwabLong8(uint64 *lp)
Definition: tif_swab.c:57
#define PLANARCONFIG_CONTIG
Definition: tiff.h:240
int _TIFFFillStriles(TIFF *tif)
Definition: tif_dirread.c:5812
char int8
Definition: platform.h:10
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
short field_readcount
Definition: tif_dir.h:280
#define O_RDONLY
Definition: acwin.h:82
off
Definition: i386-dis.c:3909
Definition: ps.c:97
char * tag
Definition: main.c:59