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