LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_open.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
29#ifdef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS
30#undef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS
31#endif
32
38#include "tiffiop.h"
39#include <assert.h>
40#include <limits.h>
41
42/*
43 * Dummy functions to fill the omitted client procedures.
44 */
45int _tiffDummyMapProc(thandle_t fd, void **pbase, toff_t *psize)
46{
47 (void)fd;
48 (void)pbase;
49 (void)psize;
50 return (0);
51}
52
53void _tiffDummyUnmapProc(thandle_t fd, void *base, toff_t size)
54{
55 (void)fd;
56 (void)base;
57 (void)size;
58}
59
60int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata, const char *mode,
61 const char *module)
62{
63 int m = -1;
64
65 switch (mode[0])
66 {
67 case 'r':
68 m = O_RDONLY;
69 if (mode[1] == '+')
70 m = O_RDWR;
71 break;
72 case 'w':
73 case 'a':
74 m = O_RDWR | O_CREAT;
75 if (mode[0] == 'w')
76 m |= O_TRUNC;
77 break;
78 default:
79 _TIFFErrorEarly(opts, clientdata, module, "\"%s\": Bad mode", mode);
80 break;
81 }
82 return (m);
83}
84
86{
87 TIFFOpenOptions *opts =
89 return opts;
90}
91
93
95 tmsize_t max_single_mem_alloc)
96{
97 opts->max_single_mem_alloc = max_single_mem_alloc;
98}
99
101 tmsize_t max_cumulated_mem_alloc)
102{
103 opts->max_cumulated_mem_alloc = max_cumulated_mem_alloc;
104}
105
107 int warn_about_unknown_tags)
108{
109 opts->warn_about_unknown_tags = warn_about_unknown_tags;
110}
111
113 TIFFErrorHandlerExtR handler,
114 void *errorhandler_user_data)
115{
116 opts->errorhandler = handler;
117 opts->errorhandler_user_data = errorhandler_user_data;
118}
119
121 TIFFErrorHandlerExtR handler,
122 void *warnhandler_user_data)
123{
124 opts->warnhandler = handler;
125 opts->warnhandler_user_data = warnhandler_user_data;
126}
127
142 const char *pszFunction,
143 tmsize_t s)
144{
145 TIFFErrorExtR(tif, pszFunction,
146 "Memory allocation of %" PRIu64
147 " bytes is beyond the %" PRIu64
148 " byte limit defined in open options",
149 (uint64_t)s, (uint64_t)tif->tif_max_single_mem_alloc);
150}
151
167 const char *pszFunction,
168 tmsize_t s)
169{
170 TIFFErrorExtR(tif, pszFunction,
171 "Cumulated memory allocation of %" PRIu64 " + %" PRIu64
172 " bytes is beyond the %" PRIu64
173 " cumulated byte limit defined in open options",
174 (uint64_t)tif->tif_cur_cumulated_mem_alloc, (uint64_t)s,
175 (uint64_t)tif->tif_max_cumulated_mem_alloc);
176}
177
178/* When allocating memory, we write at the beginning of the buffer it size.
179 * This allows us to keep track of the total memory allocated when we
180 * malloc/calloc/realloc and free. In theory we need just SIZEOF_SIZE_T bytes
181 * for that, but on x86_64, allocations of more than 16 bytes are aligned on
182 * 16 bytes. Hence using 2 * SIZEOF_SIZE_T.
183 * It is critical that _TIFFmallocExt/_TIFFcallocExt/_TIFFreallocExt are
184 * paired with _TIFFfreeExt.
185 * CMakeLists.txt defines TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS, which in
186 * turn disables the definition of the non Ext version in tiffio.h
187 */
193#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
194
196{
197 if (s <= 0)
198 return NULL;
199 if (tif != NULL && tif->tif_max_single_mem_alloc > 0 &&
201 {
202 _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFmallocExt", s);
203 return NULL;
204 }
205 if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0)
206 {
207 if (s > tif->tif_max_cumulated_mem_alloc -
210 {
211 _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFmallocExt", s);
212 return NULL;
213 }
215 if (!ptr)
216 return NULL;
218 memcpy(ptr, &s, sizeof(s));
219 return (char *)ptr + LEADING_AREA_TO_STORE_ALLOC_SIZE;
220 }
221 return _TIFFmalloc(s);
222}
223
224void *_TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz)
225{
226 if (nmemb <= 0 || siz <= 0 || nmemb > TIFF_TMSIZE_T_MAX / siz)
227 return NULL;
228 if (tif != NULL && tif->tif_max_single_mem_alloc > 0)
229 {
230 if (nmemb * siz > tif->tif_max_single_mem_alloc)
231 {
232 _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFcallocExt",
233 nmemb * siz);
234 return NULL;
235 }
236 }
237 if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0)
238 {
239 const tmsize_t s = nmemb * siz;
240 if (s > tif->tif_max_cumulated_mem_alloc -
243 {
244 _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFcallocExt", s);
245 return NULL;
246 }
248 if (!ptr)
249 return NULL;
251 memcpy(ptr, &s, sizeof(s));
252 return (char *)ptr + LEADING_AREA_TO_STORE_ALLOC_SIZE;
253 }
254 return _TIFFcalloc(nmemb, siz);
255}
256
257void *_TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
258{
259 if (s <= 0)
260 {
261 _TIFFfreeExt(tif, p);
262 return NULL;
263 }
264 if (tif != NULL && tif->tif_max_single_mem_alloc > 0 &&
266 {
267 _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFreallocExt", s);
268 return NULL;
269 }
270 if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0)
271 {
272 void *oldPtr = p;
273 tmsize_t oldSize = 0;
274 if (p)
275 {
276 oldPtr = (char *)p - LEADING_AREA_TO_STORE_ALLOC_SIZE;
277 memcpy(&oldSize, oldPtr, sizeof(oldSize));
278 assert(oldSize <= tif->tif_cur_cumulated_mem_alloc);
279 }
280 if (s > oldSize &&
282 (tif->tif_cur_cumulated_mem_alloc - oldSize) ||
284 {
285 _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFreallocExt",
286 s - oldSize);
287 return NULL;
288 }
289 void *newPtr =
291 if (newPtr == NULL)
292 return NULL;
293 tif->tif_cur_cumulated_mem_alloc -= oldSize;
295 memcpy(newPtr, &s, sizeof(s));
296 return (char *)newPtr + LEADING_AREA_TO_STORE_ALLOC_SIZE;
297 }
298 return _TIFFrealloc(p, s);
299}
300
301void _TIFFfreeExt(TIFF *tif, void *p)
302{
303 if (p != NULL && tif != NULL && tif->tif_max_cumulated_mem_alloc > 0)
304 {
305 void *oldPtr = (char *)p - LEADING_AREA_TO_STORE_ALLOC_SIZE;
306 tmsize_t oldSize;
307 memcpy(&oldSize, oldPtr, sizeof(oldSize));
308 assert(oldSize <= tif->tif_cur_cumulated_mem_alloc);
309 tif->tif_cur_cumulated_mem_alloc -= oldSize;
310 p = oldPtr;
311 }
312 _TIFFfree(p);
313}
314
315TIFF *TIFFClientOpen(const char *name, const char *mode, thandle_t clientdata,
316 TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc,
317 TIFFSeekProc seekproc, TIFFCloseProc closeproc,
318 TIFFSizeProc sizeproc, TIFFMapFileProc mapproc,
319 TIFFUnmapFileProc unmapproc)
320{
321 return TIFFClientOpenExt(name, mode, clientdata, readproc, writeproc,
322 seekproc, closeproc, sizeproc, mapproc, unmapproc,
323 NULL);
324}
325
326TIFF *TIFFClientOpenExt(const char *name, const char *mode,
327 thandle_t clientdata, TIFFReadWriteProc readproc,
328 TIFFReadWriteProc writeproc, TIFFSeekProc seekproc,
329 TIFFCloseProc closeproc, TIFFSizeProc sizeproc,
330 TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc,
331 TIFFOpenOptions *opts)
332{
333 static const char module[] = "TIFFClientOpenExt";
334 TIFF *tif;
335 int m;
336 const char *cp;
337 size_t name_len;
338 tmsize_t size_to_alloc;
339
340 /* The following are configuration checks. They should be redundant, but
341 * should not compile to any actual code in an optimised release build
342 * anyway. If any of them fail, (makefile-based or other) configuration is
343 * not correct */
344 assert(sizeof(uint8_t) == 1);
345 assert(sizeof(int8_t) == 1);
346 assert(sizeof(uint16_t) == 2);
347 assert(sizeof(int16_t) == 2);
348 assert(sizeof(uint32_t) == 4);
349 assert(sizeof(int32_t) == 4);
350 assert(sizeof(uint64_t) == 8);
351 assert(sizeof(int64_t) == 8);
352 {
353 union
354 {
355 uint8_t a8[2];
356 uint16_t a16;
357 } n;
358 n.a8[0] = 1;
359 n.a8[1] = 0;
360 (void)n;
361#if WORDS_BIGENDIAN
362 assert(n.a16 == 256);
363#else
364 assert(n.a16 == 1);
365#endif
366 }
367
368 m = _TIFFgetMode(opts, clientdata, mode, module);
369 if (m == -1)
370 goto bad2;
371 /* Keep the length used for the allocation and the one used for the copy
372 * in a single variable, so they cannot drift apart. */
373 name_len = strlen(name) + 1;
374 size_to_alloc = (tmsize_t)(sizeof(TIFF) + name_len);
375 if (opts && opts->max_single_mem_alloc > 0 &&
376 size_to_alloc > opts->max_single_mem_alloc)
377 {
378 _TIFFErrorEarly(opts, clientdata, module,
379 "%s: Memory allocation of %" PRIu64
380 " bytes is beyond the %" PRIu64
381 " byte limit defined in open options",
382 name, (uint64_t)size_to_alloc,
383 (uint64_t)opts->max_single_mem_alloc);
384 goto bad2;
385 }
386 if (opts && opts->max_cumulated_mem_alloc > 0 &&
387 size_to_alloc > opts->max_cumulated_mem_alloc)
388 {
389 _TIFFErrorEarly(opts, clientdata, module,
390 "%s: Memory allocation of %" PRIu64
391 " bytes is beyond the %" PRIu64
392 " cumulated byte limit defined in open options",
393 name, (uint64_t)size_to_alloc,
394 (uint64_t)opts->max_cumulated_mem_alloc);
395 goto bad2;
396 }
397 tif = (TIFF *)_TIFFmallocExt(NULL, size_to_alloc);
398 if (tif == NULL)
399 {
400 _TIFFErrorEarly(opts, clientdata, module,
401 "%s: Out of memory (TIFF structure)", name);
402 goto bad2;
403 }
404 _TIFFmemset(tif, 0, sizeof(*tif));
405 tif->tif_name = (char *)tif + sizeof(TIFF);
406 _TIFFmemcpy(tif->tif_name, name, (tmsize_t)name_len);
407 tif->tif_mode = m & ~(O_CREAT | O_TRUNC);
408 tif->tif_curdir = TIFF_NON_EXISTENT_DIR_NUMBER; /* non-existent directory */
409 tif->tif_curdircount = TIFF_NON_EXISTENT_DIR_NUMBER;
410 tif->tif_curoff = 0;
411 tif->tif_clientdata = clientdata;
412 tif->tif_readproc = readproc;
413 tif->tif_writeproc = writeproc;
414 tif->tif_seekproc = seekproc;
415 tif->tif_closeproc = closeproc;
416 tif->tif_sizeproc = sizeproc;
417 tif->tif_mapproc = mapproc ? mapproc : _tiffDummyMapProc;
418 tif->tif_unmapproc = unmapproc ? unmapproc : _tiffDummyUnmapProc;
419 if (opts)
420 {
421 tif->tif_errorhandler = opts->errorhandler;
422 tif->tif_errorhandler_user_data = opts->errorhandler_user_data;
423 tif->tif_warnhandler = opts->warnhandler;
424 tif->tif_warnhandler_user_data = opts->warnhandler_user_data;
425 tif->tif_max_single_mem_alloc = opts->max_single_mem_alloc;
426 tif->tif_max_cumulated_mem_alloc = opts->max_cumulated_mem_alloc;
427 tif->tif_warn_about_unknown_tags = opts->warn_about_unknown_tags;
428 }
429
430 /* Reset tif->tif_dir structure to zero and
431 * initialize some IFD strile counter and index parameters. */
433
434 if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc)
435 {
436 TIFFErrorExtR(tif, module,
437 "One of the client procedures is NULL pointer.");
438 _TIFFfreeExt(NULL, tif);
439 goto bad2;
440 }
441
442 _TIFFSetDefaultCompressionState(tif); /* setup default state */
443 /*
444 * Default is to return data MSB2LSB and enable the
445 * use of memory-mapped files and strip chopping when
446 * a file is opened read-only.
447 */
448 tif->tif_flags = FILLORDER_MSB2LSB;
449 if (m == O_RDONLY)
450 tif->tif_flags |= TIFF_MAPPED;
451
452#ifdef STRIPCHOP_DEFAULT
453 if (m == O_RDONLY || m == O_RDWR)
454 tif->tif_flags |= STRIPCHOP_DEFAULT;
455#endif
456
457 /*
458 * Process library-specific flags in the open mode string.
459 * The following flags may be used to control intrinsic library
460 * behavior that may or may not be desirable (usually for
461 * compatibility with some application that claims to support
462 * TIFF but only supports some brain dead idea of what the
463 * vendor thinks TIFF is):
464 *
465 * 'l' use little-endian byte order for creating a file
466 * 'b' use big-endian byte order for creating a file
467 * 'L' read/write information using LSB2MSB bit order
468 * 'B' read/write information using MSB2LSB bit order
469 * 'H' deprecated alias of 'B' (emits a warning)
470 * 'M' enable use of memory-mapped files when supported
471 * 'm' disable use of memory-mapped files
472 * 'C' enable strip chopping support when reading
473 * 'c' disable strip chopping support
474 * 'h' read TIFF header only, do not load the first IFD
475 * '4' ClassicTIFF for creating a file (default)
476 * '8' BigTIFF for creating a file
477 * 'D' enable use of deferred strip/tile offset/bytecount array loading.
478 * 'O' on-demand loading of values instead of whole array loading (implies
479 * D)
480 *
481 * The use of the 'l' and 'b' flags is strongly discouraged.
482 * These flags are provided solely because numerous vendors,
483 * typically on the PC, do not correctly support TIFF; they
484 * only support the Intel little-endian byte order. This
485 * support is not configured by default because it supports
486 * the violation of the TIFF spec that says that readers *MUST*
487 * support both byte orders. It is strongly recommended that
488 * you not use this feature except to deal with busted apps
489 * that write invalid TIFF. And even in those cases you should
490 * bang on the vendors to fix their software.
491 *
492 * The 'L', 'B', and 'H' flags are intended for applications
493 * that can optimize operations on data by using a particular
494 * bit order. By default the library returns data in MSB2LSB
495 * bit order for compatibility with older versions of this
496 * library. Returning data in the bit order of the native CPU
497 * makes the most sense but also requires applications to check
498 * the value of the FillOrder tag; something they probably do
499 * not do right now.
500 *
501 * The 'M' and 'm' flags are provided because some virtual memory
502 * systems exhibit poor behavior when large images are mapped.
503 * These options permit clients to control the use of memory-mapped
504 * files on a per-file basis.
505 *
506 * The 'C' and 'c' flags are provided because the library support
507 * for chopping up large strips into multiple smaller strips is not
508 * application-transparent and as such can cause problems. The 'c'
509 * option permits applications that only want to look at the tags,
510 * for example, to get the unadulterated TIFF tag information.
511 */
512 for (cp = mode; *cp; cp++)
513 switch (*cp)
514 {
515 case 'b':
516#if !WORDS_BIGENDIAN
517 if (m & O_CREAT)
518 tif->tif_flags |= TIFF_SWAB;
519#endif
520 break;
521 case 'l':
522#if WORDS_BIGENDIAN
523 if ((m & O_CREAT))
524 tif->tif_flags |= TIFF_SWAB;
525#endif
526 break;
527 case 'B':
528 tif->tif_flags =
529 (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_MSB2LSB;
530 break;
531 case 'L':
532 tif->tif_flags =
533 (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_LSB2MSB;
534 break;
535 case 'H':
536 TIFFWarningExtR(tif, name,
537 "H(ost) mode is deprecated. Since "
538 "libtiff 4.5.1, it is an alias of 'B' / "
539 "FILLORDER_MSB2LSB.");
540 tif->tif_flags =
541 (tif->tif_flags & ~TIFF_FILLORDER) | FILLORDER_MSB2LSB;
542 break;
543 case 'M':
544 if (m == O_RDONLY)
545 tif->tif_flags |= TIFF_MAPPED;
546 break;
547 case 'm':
548 if (m == O_RDONLY)
549 tif->tif_flags &= ~TIFF_MAPPED;
550 break;
551 case 'C':
552 if (m == O_RDONLY)
553 tif->tif_flags |= TIFF_STRIPCHOP;
554 break;
555 case 'c':
556 if (m == O_RDONLY)
557 tif->tif_flags &= ~TIFF_STRIPCHOP;
558 break;
559 case 'h':
560 tif->tif_flags |= TIFF_HEADERONLY;
561 break;
562 case '8':
563 if (m & O_CREAT)
564 tif->tif_flags |= TIFF_BIGTIFF;
565 break;
566 case 'D':
567 tif->tif_flags |= TIFF_DEFERSTRILELOAD;
568 break;
569 case 'O':
570 if (m == O_RDONLY)
571 tif->tif_flags |=
573 break;
574 default:
575 break;
576 }
577
578#ifdef DEFER_STRILE_LOAD
579 /* Compatibility with old DEFER_STRILE_LOAD compilation flag */
580 /* Probably unneeded, since to the best of my knowledge (E. Rouault) */
581 /* GDAL was the only user of this, and will now use the new 'D' flag */
582 tif->tif_flags |= TIFF_DEFERSTRILELOAD;
583#endif
584
585 /*
586 * Read in TIFF header.
587 */
588 if ((m & O_TRUNC) ||
589 !ReadOK(tif, &tif->tif_header, sizeof(TIFFHeaderClassic)))
590 {
591 if (tif->tif_mode == O_RDONLY)
592 {
593 TIFFErrorExtR(tif, name, "Cannot read TIFF header");
594 goto bad;
595 }
596 /*
597 * Setup header and write.
598 */
599#if WORDS_BIGENDIAN
600 tif->tif_header.common.tiff_magic =
601 (tif->tif_flags & TIFF_SWAB) ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN;
602#else
603 tif->tif_header.common.tiff_magic =
604 (tif->tif_flags & TIFF_SWAB) ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN;
605#endif
606 TIFFHeaderUnion tif_header_swapped;
607 if (!(tif->tif_flags & TIFF_BIGTIFF))
608 {
609 tif->tif_header.common.tiff_version = TIFF_VERSION_CLASSIC;
610 tif->tif_header.classic.tiff_diroff = 0;
611 tif->tif_header_size = sizeof(TIFFHeaderClassic);
612 /* Swapped copy for writing */
613 _TIFFmemcpy(&tif_header_swapped, &tif->tif_header,
614 sizeof(TIFFHeaderUnion));
615 if (tif->tif_flags & TIFF_SWAB)
616 TIFFSwabShort(&tif_header_swapped.common.tiff_version);
617 }
618 else
619 {
620 tif->tif_header.common.tiff_version = TIFF_VERSION_BIG;
621 tif->tif_header.big.tiff_offsetsize = 8;
622 tif->tif_header.big.tiff_unused = 0;
623 tif->tif_header.big.tiff_diroff = 0;
624 tif->tif_header_size = sizeof(TIFFHeaderBig);
625 /* Swapped copy for writing */
626 _TIFFmemcpy(&tif_header_swapped, &tif->tif_header,
627 sizeof(TIFFHeaderUnion));
628 if (tif->tif_flags & TIFF_SWAB)
629 {
630 TIFFSwabShort(&tif_header_swapped.common.tiff_version);
631 TIFFSwabShort(&tif_header_swapped.big.tiff_offsetsize);
632 }
633 }
634 /*
635 * The doc for "fopen" for some STD_C_LIBs says that if you
636 * open a file for modify ("+"), then you must fseek (or
637 * fflush?) between any freads and fwrites. This is not
638 * necessary on most systems, but has been shown to be needed
639 * on Solaris.
640 */
641 TIFFSeekFile(tif, 0, SEEK_SET);
642 if (!WriteOK(tif, &tif_header_swapped,
643 (tmsize_t)(tif->tif_header_size)))
644 {
645 TIFFErrorExtR(tif, name, "Error writing TIFF header");
646 goto bad;
647 }
648 /*
649 * Setup default directory.
650 */
651 if (!TIFFDefaultDirectory(tif))
652 goto bad;
653 tif->tif_diroff = 0;
654 tif->tif_lastdiroff = 0;
655 tif->tif_setdirectory_force_absolute = FALSE;
656 /* tif_curdircount = 0 means 'empty file opened for writing, but no IFD
657 * written yet' */
658 tif->tif_curdircount = 0;
659 return (tif);
660 }
661
662 /*
663 * Setup the byte order handling according to the opened file for reading.
664 */
665 if (tif->tif_header.common.tiff_magic != TIFF_BIGENDIAN &&
666 tif->tif_header.common.tiff_magic != TIFF_LITTLEENDIAN
667#if MDI_SUPPORT
668 &&
670 tif->tif_header.common.tiff_magic != MDI_BIGENDIAN
671#else
672 tif->tif_header.common.tiff_magic != MDI_LITTLEENDIAN
673#endif
674 )
675 {
676 TIFFErrorExtR(tif, name,
677 "Not a TIFF or MDI file, bad magic number %" PRIu16
678 " (0x%" PRIx16 ")",
679#else
680 )
681 {
682 TIFFErrorExtR(tif, name,
683 "Not a TIFF file, bad magic number %" PRIu16
684 " (0x%" PRIx16 ")",
685#endif
686 tif->tif_header.common.tiff_magic,
687 tif->tif_header.common.tiff_magic);
688 goto bad;
689 }
690 if (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN)
691 {
692#if !WORDS_BIGENDIAN
693 tif->tif_flags |= TIFF_SWAB;
694#endif
695 }
696 else
697 {
698#if WORDS_BIGENDIAN
699 tif->tif_flags |= TIFF_SWAB;
700#endif
701 }
702 if (tif->tif_flags & TIFF_SWAB)
703 TIFFSwabShort(&tif->tif_header.common.tiff_version);
704 if ((tif->tif_header.common.tiff_version != TIFF_VERSION_CLASSIC) &&
705 (tif->tif_header.common.tiff_version != TIFF_VERSION_BIG))
706 {
707 TIFFErrorExtR(tif, name,
708 "Not a TIFF file, bad version number %" PRIu16
709 " (0x%" PRIx16 ")",
710 tif->tif_header.common.tiff_version,
711 tif->tif_header.common.tiff_version);
712 goto bad;
713 }
714 if (tif->tif_header.common.tiff_version == TIFF_VERSION_CLASSIC)
715 {
716 if (tif->tif_flags & TIFF_SWAB)
717 TIFFSwabLong(&tif->tif_header.classic.tiff_diroff);
718 tif->tif_header_size = sizeof(TIFFHeaderClassic);
719 }
720 else
721 {
722 if (!ReadOK(tif,
723 ((uint8_t *)(&tif->tif_header) + sizeof(TIFFHeaderClassic)),
724 (sizeof(TIFFHeaderBig) - sizeof(TIFFHeaderClassic))))
725 {
726 TIFFErrorExtR(tif, name, "Cannot read TIFF header");
727 goto bad;
728 }
729 if (tif->tif_flags & TIFF_SWAB)
730 {
731 TIFFSwabShort(&tif->tif_header.big.tiff_offsetsize);
732 TIFFSwabLong8(&tif->tif_header.big.tiff_diroff);
733 }
734 if (tif->tif_header.big.tiff_offsetsize != 8)
735 {
736 TIFFErrorExtR(tif, name,
737 "Not a TIFF file, bad BigTIFF offsetsize %" PRIu16
738 " (0x%" PRIx16 ")",
739 tif->tif_header.big.tiff_offsetsize,
740 tif->tif_header.big.tiff_offsetsize);
741 goto bad;
742 }
743 if (tif->tif_header.big.tiff_unused != 0)
744 {
745 TIFFErrorExtR(tif, name,
746 "Not a TIFF file, bad BigTIFF unused %" PRIu16
747 " (0x%" PRIx16 ")",
748 tif->tif_header.big.tiff_unused,
749 tif->tif_header.big.tiff_unused);
750 goto bad;
751 }
752 tif->tif_header_size = sizeof(TIFFHeaderBig);
753 tif->tif_flags |= TIFF_BIGTIFF;
754 }
755 tif->tif_flags |= TIFF_MYBUFFER;
756 tif->tif_rawcp = tif->tif_rawdata = 0;
757 tif->tif_rawdatasize = 0;
758 tif->tif_rawdataoff = 0;
759 tif->tif_rawdataloaded = 0;
760
761 switch (mode[0])
762 {
763 case 'r':
764 if (!(tif->tif_flags & TIFF_BIGTIFF))
765 tif->tif_nextdiroff = tif->tif_header.classic.tiff_diroff;
766 else
767 tif->tif_nextdiroff = tif->tif_header.big.tiff_diroff;
768 /*
769 * Try to use a memory-mapped file if the client
770 * has not explicitly suppressed usage with the
771 * 'm' flag in the open mode (see above).
772 */
773 if (tif->tif_flags & TIFF_MAPPED)
774 {
775 toff_t n;
776 if (TIFFMapFileContents(tif, (void **)(&tif->tif_base), &n))
777 {
778 tif->tif_size = (tmsize_t)n;
779 assert((toff_t)tif->tif_size == n);
780 }
781 else
782 tif->tif_flags &= ~TIFF_MAPPED;
783 }
784 /*
785 * Sometimes we do not want to read the first directory (for
786 * example, it may be broken) and want to proceed to other
787 * directories. I this case we use the TIFF_HEADERONLY flag to open
788 * file and return immediately after reading TIFF header.
789 * However, the pointer to TIFFSetField() and TIFFGetField()
790 * (i.e. tif->tif_tagmethods.vsetfield and
791 * tif->tif_tagmethods.vgetfield) need to be initialized, which is
792 * done in TIFFDefaultDirectory().
793 */
794 if (tif->tif_flags & TIFF_HEADERONLY)
795 {
796 if (!TIFFDefaultDirectory(tif))
797 goto bad;
798 return (tif);
799 }
800
801 /*
802 * Setup initial directory.
803 */
804 if (TIFFReadDirectory(tif))
805 {
806 return (tif);
807 }
808 break;
809 case 'a':
810 /*
811 * New directories are automatically append
812 * to the end of the directory chain when they
813 * are written out (see TIFFWriteDirectory).
814 */
815 if (!TIFFDefaultDirectory(tif))
816 goto bad;
817 return (tif);
818 default:
819 break;
820 }
821bad:
822 tif->tif_mode = O_RDONLY; /* XXX avoid flush */
823 TIFFCleanup(tif);
824bad2:
825 return ((TIFF *)0);
826}
827
828/*
829 * Query functions to access private data.
830 */
831
832/*
833 * Return open file's name.
834 */
835const char *TIFFFileName(TIFF *tif) { return (tif->tif_name); }
836
837/*
838 * Set the file name.
839 */
840const char *TIFFSetFileName(TIFF *tif, const char *name)
841{
842 const char *old_name = tif->tif_name;
843 tif->tif_name = (char *)name;
844 return (old_name);
845}
846
847/*
848 * Return open file's I/O descriptor.
849 */
850int TIFFFileno(TIFF *tif) { return (tif->tif_fd); }
851
852/*
853 * Set open file's I/O descriptor, and return previous value.
854 */
855int TIFFSetFileno(TIFF *tif, int fd)
856{
857 int old_fd = tif->tif_fd;
858 tif->tif_fd = fd;
859 return old_fd;
860}
861
862/*
863 * Return open file's clientdata.
864 */
866
867/*
868 * Set open file's clientdata, and return previous value.
869 */
871{
872 thandle_t m = tif->tif_clientdata;
873 tif->tif_clientdata = newvalue;
874 return m;
875}
876
877/*
878 * Return read/write mode.
879 */
880int TIFFGetMode(TIFF *tif) { return (tif->tif_mode); }
881
882/*
883 * Return read/write mode.
884 */
885int TIFFSetMode(TIFF *tif, int mode)
886{
887 int old_mode = tif->tif_mode;
888 tif->tif_mode = mode;
889 return (old_mode);
890}
891
892/*
893 * Return nonzero if file is organized in
894 * tiles; zero if organized as strips.
895 */
896int TIFFIsTiled(TIFF *tif) { return (isTiled(tif)); }
897
898/*
899 * Return current row being read/written.
900 */
901uint32_t TIFFCurrentRow(TIFF *tif) { return (tif->tif_dir.td_row); }
902
903/*
904 * Return index of the current directory.
905 */
907
908/*
909 * Return current strip.
910 */
911uint32_t TIFFCurrentStrip(TIFF *tif) { return (tif->tif_dir.td_curstrip); }
912
913/*
914 * Return current tile.
915 */
916uint32_t TIFFCurrentTile(TIFF *tif) { return (tif->tif_dir.td_curtile); }
917
918/*
919 * Return nonzero if the file has byte-swapped data.
920 */
921int TIFFIsByteSwapped(TIFF *tif) { return ((tif->tif_flags & TIFF_SWAB) != 0); }
922
923/*
924 * Return nonzero if the data is returned up-sampled.
925 */
926int TIFFIsUpSampled(TIFF *tif) { return (isUpSampled(tif)); }
927
928/*
929 * Return nonzero if the data is returned in MSB-to-LSB bit order.
930 */
931int TIFFIsMSB2LSB(TIFF *tif) { return (isFillOrder(tif, FILLORDER_MSB2LSB)); }
932
933/*
934 * Return nonzero if given file was written in big-endian order.
935 */
937{
939}
940
941/*
942 * Return nonzero if given file is BigTIFF style.
943 */
944int TIFFIsBigTIFF(TIFF *tif) { return ((tif->tif_flags & TIFF_BIGTIFF) != 0); }
945
946/*
947 * Return pointer to file read method.
948 */
950
951/*
952 * Return pointer to file write method.
953 */
955
956/*
957 * Return pointer to file seek method.
958 */
960
961/*
962 * Return pointer to file close method.
963 */
965
966/*
967 * Return pointer to file size requesting method.
968 */
970
971/*
972 * Return pointer to memory mapping method.
973 */
975
976/*
977 * Return pointer to memory unmapping method.
978 */
980{
981 return (tif->tif_unmapproc);
982}
void _TIFFSetDefaultCompressionState(TIFF *tif)
Install fallback codec callbacks and reset raw-access flags.
int TIFFDefaultDirectory(TIFF *tif)
Install the image schema, default values, and core tag methods.
Definition tif_dir.c:2316
void _TIFFResetTifDirAndInitStrileCounters(TIFFDirectory *td)
Zero directory storage and initialise traversal sentinels.
Definition tif_dir.c:2151
int _tiffDummyMapProc(thandle_t fd, void **pbase, toff_t *psize)
Decline mapping when the client supplies no mapping implementation.
Definition tif_open.c:45
void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata, const char *module, const char *fmt,...)
Report an opening error before a complete TIFF handle is available.
Definition tif_error.c:85
int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata, const char *mode, const char *module)
Translate the leading open-mode characters into OS access flags.
Definition tif_open.c:60
void _tiffDummyUnmapProc(thandle_t fd, void *base, toff_t size)
Provide a no-op unmapper when the client omits one.
Definition tif_open.c:53
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
Definition tif_open.c:301
static void _TIFFEmitErrorAboveMaxCumulatedMemAlloc(TIFF *tif, const char *pszFunction, tmsize_t s)
Report a rejected cumulative allocation-policy check.
Definition tif_open.c:166
void * _TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
Resize a handle-aware block or release it for a nonpositive size.
Definition tif_open.c:257
void * _TIFFmallocExt(TIFF *tif, tmsize_t s)
Allocate uninitialised bytes under a handle's allocation policy.
Definition tif_open.c:195
void * _TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz)
Allocate a zero-filled array under a handle's allocation policy.
Definition tif_open.c:224
static void _TIFFEmitErrorAboveMaxSingleMemAlloc(TIFF *tif, const char *pszFunction, tmsize_t s)
Report a rejected single allocation-policy check.
Definition tif_open.c:141
#define LEADING_AREA_TO_STORE_ALLOC_SIZE
Reserve two size_t widths before a cumulatively tracked payload.
Definition tif_open.c:193
#define TIFF_NON_EXISTENT_DIR_NUMBER
Mark an unknown or nonexistent directory index.
Definition tiffiop.h:95
#define isTiled(tif)
Test whether a handle uses tiled storage.
Definition tiffiop.h:833
#define WriteOK(tif, buf, size)
Test whether one client write transfers the entire requested byte count.
Definition tiffiop.h:1035
#define isUpSampled(tif)
Test whether the codec reports upsampled output.
Definition tiffiop.h:869
#define TIFF_MYBUFFER
Mark a raw buffer owned and released by the handle.
Definition tiffiop.h:451
#define ReadOK(tif, buf, size)
Test whether one client read transfers the entire requested byte count.
Definition tiffiop.h:1000
#define TIFF_HEADERONLY
Request header-only opening without reading the first IFD.
Definition tiffiop.h:491
#define TIFF_LAZYSTRILELOAD_ASKED
Record a lazy strip/tile loading request from the O open flag.
Definition tiffiop.h:552
#define TIFFMapFileContents(tif, paddr, psize)
Invoke the handle's client mapping callback.
Definition tiffiop.h:962
#define TIFF_STRIPCHOP
Enable internal chopping of a large uncompressed strip.
Definition tiffiop.h:486
#define TIFF_DEFERSTRILELOAD
Defer loading strip/tile offset and byte-count arrays.
Definition tiffiop.h:533
#define isFillOrder(tif, o)
Test whether selected bit-fill-order bits are present in a handle.
Definition tiffiop.h:858
#define FALSE
Represent the legacy internal false value.
Definition tiffiop.h:136
#define TIFFSeekFile(tif, off, whence)
Invoke the handle's client seek callback.
Definition tiffiop.h:920
#define TIFF_MAPPED
Request or record memory-mapped file access.
Definition tiffiop.h:466
#define TIFF_BIGTIFF
Mark the BigTIFF file format.
Definition tiffiop.h:508
#define TIFF_SWAB
Request swapping multibyte file values to or from host order.
Definition tiffiop.h:441
#define HOST_BIGENDIAN
Indicate native CPU byte order: 1 for big-endian, 0 for little-endian.
Definition tiffconf.h:81
#define STRIPCHOP_DEFAULT
Define the default strip-chopping flag when strip chopping is enabled.
Definition tiffconf.h:140
#define MDI_SUPPORT
Indicate support for Microsoft Document Imaging signatures when defined.
Definition tiffconf.h:163
void TIFFSwabLong8(uint64_t *lp)
Reverse the byte order of one value.
Definition tif_swab.c:66
void TIFFSwabShort(uint16_t *wp)
Reverse the byte order of one value.
Definition tif_swab.c:39
void TIFFSwabLong(uint32_t *lp)
Reverse the byte order of one value.
Definition tif_swab.c:51
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a warning diagnostic to the configured handlers.
Definition tif_warning.c:85
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
Definition tif_error.c:112
tdir_t TIFFCurrentDirectory(TIFF *tif)
Read the cached index of the current directory.
Definition tif_open.c:906
int TIFFReadDirectory(TIFF *tif)
Read and install the next image directory.
uint32_t TIFFCurrentTile(TIFF *tif)
Read the cached current tile index.
Definition tif_open.c:916
uint32_t TIFFCurrentRow(TIFF *tif)
Read the cached current scanline index.
Definition tif_open.c:901
uint32_t TIFFCurrentStrip(TIFF *tif)
Read the cached current strip index.
Definition tif_open.c:911
toff_t(* TIFFSeekProc)(thandle_t fd, toff_t off, int whence)
Change the current position of a client I/O resource.
Definition tiffio.h:933
int(* TIFFCloseProc)(thandle_t fd)
Release a client I/O resource or its adapter context.
Definition tiffio.h:951
void(* TIFFUnmapFileProc)(thandle_t fd, void *base, toff_t size)
Release a whole-file view supplied by a mapping callback.
Definition tiffio.h:1008
toff_t(* TIFFSizeProc)(thandle_t fd)
Query the byte length of a client I/O resource.
Definition tiffio.h:968
tmsize_t(* TIFFReadWriteProc)(thandle_t fd, void *buf, tmsize_t size)
Transfer bytes at the current position of a client I/O resource.
Definition tiffio.h:911
int(* TIFFMapFileProc)(thandle_t fd, void **base, toff_t *size)
Provide a readable whole-file view of a client resource.
Definition tiffio.h:989
int TIFFGetMode(TIFF *tif)
Return the stored library access mode.
Definition tif_open.c:880
int TIFFFileno(TIFF *tif)
Return the handle's file-descriptor metadata.
Definition tif_open.c:850
TIFF * TIFFClientOpenExt(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc, TIFFOpenOptions *opts)
Initialise a TIFF handle using client-supplied I/O callbacks.
Definition tif_open.c:326
TIFF * TIFFClientOpen(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc)
Initialise a TIFF handle using client-supplied I/O callbacks.
Definition tif_open.c:315
TIFFReadWriteProc TIFFGetReadProc(TIFF *tif)
Return the installed client read callback.
Definition tif_open.c:949
int TIFFSetFileno(TIFF *tif, int fd)
Replace descriptor metadata without changing client I/O routing.
Definition tif_open.c:855
TIFFCloseProc TIFFGetCloseProc(TIFF *tif)
Return the installed client close callback.
Definition tif_open.c:964
const char * TIFFFileName(TIFF *tif)
Return the handle's diagnostic filename.
Definition tif_open.c:835
TIFFSizeProc TIFFGetSizeProc(TIFF *tif)
Return the installed client file-size callback.
Definition tif_open.c:969
int TIFFSetMode(TIFF *tif, int mode)
Replace the stored library access mode without reopening the resource.
Definition tif_open.c:885
int TIFFIsMSB2LSB(TIFF *tif)
Test the selected data bit-fill-order flag.
Definition tif_open.c:931
int TIFFIsByteSwapped(TIFF *tif)
Test whether file values require byte swapping for this host.
Definition tif_open.c:921
TIFFMapFileProc TIFFGetMapFileProc(TIFF *tif)
Return the installed client mapping callback.
Definition tif_open.c:974
int TIFFIsTiled(TIFF *tif)
Test whether the current image uses tiles.
Definition tif_open.c:896
const char * TIFFSetFileName(TIFF *tif, const char *name)
Replace the diagnostic filename pointer without copying it.
Definition tif_open.c:840
void TIFFCleanup(TIFF *tif)
Release library state without invoking the client close callback.
Definition tif_close.c:40
TIFFSeekProc TIFFGetSeekProc(TIFF *tif)
Return the installed client seek callback.
Definition tif_open.c:959
int TIFFIsBigTIFF(TIFF *tif)
Test whether the handle uses the BigTIFF format.
Definition tif_open.c:944
thandle_t TIFFSetClientdata(TIFF *tif, thandle_t newvalue)
Replace the context passed to all client I/O callbacks.
Definition tif_open.c:870
TIFFUnmapFileProc TIFFGetUnmapFileProc(TIFF *tif)
Return the installed client unmapping callback.
Definition tif_open.c:979
int TIFFIsBigEndian(TIFF *tif)
Test whether the stored file signature is TIFF_BIGENDIAN.
Definition tif_open.c:936
int TIFFIsUpSampled(TIFF *tif)
Test whether the active codec supplies upsampled data.
Definition tif_open.c:926
TIFFReadWriteProc TIFFGetWriteProc(TIFF *tif)
Return the installed client write callback.
Definition tif_open.c:954
thandle_t TIFFClientdata(TIFF *tif)
Return the context passed to client I/O callbacks.
Definition tif_open.c:865
void _TIFFfree(void *p)
Release a block allocated by the public allocation family.
Definition tif_unix.c:491
void * _TIFFcalloc(tmsize_t nmemb, tmsize_t siz)
Allocate a zero-filled array through the public allocator.
Definition tif_unix.c:483
void _TIFFmemset(void *p, int v, tmsize_t c)
Fill a byte range with one repeated byte.
Definition tif_unix.c:495
void * _TIFFmalloc(tmsize_t s)
Allocate an uninitialised block through the public allocator.
Definition tif_unix.c:475
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
Definition tif_unix.c:497
void * _TIFFrealloc(void *p, tmsize_t s)
Resize a public-allocator block using platform realloc semantics.
Definition tif_unix.c:493
void TIFFOpenOptionsSetWarningHandlerExtR(TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *warnhandler_user_data)
Set the per-handle warning callback for subsequent opens.
Definition tif_open.c:120
void TIFFOpenOptionsSetErrorHandlerExtR(TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *errorhandler_user_data)
Set the per-handle error callback for subsequent opens.
Definition tif_open.c:112
void TIFFOpenOptionsSetMaxCumulatedMemAlloc(TIFFOpenOptions *opts, tmsize_t max_cumulated_mem_alloc)
Set the cumulative checked allocation limit for subsequent opens.
Definition tif_open.c:100
void TIFFOpenOptionsSetWarnAboutUnknownTags(TIFFOpenOptions *opts, int warn_about_unknown_tags)
Select whether subsequent opens warn about unknown tags.
Definition tif_open.c:106
int(* TIFFErrorHandlerExtR)(TIFF *tif, void *user_data, const char *module, const char *fmt, va_list ap)
Handle a diagnostic using a per-handle borrowed context.
Definition tiffio.h:884
TIFFOpenOptions * TIFFOpenOptionsAlloc(void)
Allocate default options for opening a TIFF handle.
Definition tif_open.c:85
void TIFFOpenOptionsSetMaxSingleMemAlloc(TIFFOpenOptions *opts, tmsize_t max_single_mem_alloc)
Set the single checked allocation limit for subsequent opens.
Definition tif_open.c:94
void TIFFOpenOptionsFree(TIFFOpenOptions *opts)
Release an open-options object.
Definition tif_open.c:92
#define FILLORDER_LSB2MSB
Least significant -> most.
Definition tiff.h:426
#define FILLORDER_MSB2LSB
Most significant -> least.
Definition tiff.h:424
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Definition tiffio.h:89
#define TIFF_TMSIZE_T_MAX
Define the largest positive size representable by tmsize_t.
Definition tiffio.h:91
#define TIFF_LITTLEENDIAN
Identify little-endian TIFF byte order (the bytes II).
Definition tiff.h:68
#define MDI_LITTLEENDIAN
Microsoft Document Imaging signature bytes (EP) read on a little-endian host.
Definition tiff.h:73
uint64_t toff_t
Represent an unsigned file byte offset independently of off_t.
Definition tiffio.h:94
#define MDI_BIGENDIAN
Microsoft Document Imaging signature bytes (EP) read on a big-endian host.
Definition tiff.h:82
uint32_t tdir_t
Represent a zero-based directory index, rather than a file offset.
Definition tiffio.h:96
#define TIFF_VERSION_BIG
Identify the BigTIFF file format in a file header.
Definition tiff.h:63
#define TIFF_VERSION_CLASSIC
Identify the classic TIFF file format in a file header.
Definition tiff.h:61
void * thandle_t
Carry an opaque client I/O context through library callbacks.
Definition tiffio.h:161
#define TIFF_BIGENDIAN
Identify big-endian TIFF byte order (the bytes MM).
Definition tiff.h:66
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
Definition tif_dir.h:240
uint32_t td_curtile
Current tile index, or NOTILE.
Definition tif_dir.h:256
uint32_t td_curstrip
Current strip index, or NOSTRIP.
Definition tif_dir.h:242
Represent a BigTIFF header with a 64-bit directory offset.
Definition tiff.h:195
uint16_t tiff_offsetsize
Offset width in bytes; must be 8.
Definition tiff.h:201
Represent a classic TIFF header with a 32-bit directory offset.
Definition tiff.h:181
uint16_t tiff_magic
File byte-order signature.
Definition tiff.h:171
uint16_t tiff_version
TIFF_VERSION_CLASSIC or TIFF_VERSION_BIG.
Definition tiff.h:173
Hold allocation limits and diagnostics used when opening a TIFF handle.
Definition tiffiop.h:791
void * errorhandler_user_data
Borrowed error-callback context, or NULL.
Definition tiffiop.h:795
tmsize_t max_cumulated_mem_alloc
Maximum tracked allocation total in bytes; zero means unlimited.
Definition tiffiop.h:805
TIFFErrorHandlerExtR errorhandler
Optional per-handle error callback, or NULL.
Definition tiffiop.h:793
int warn_about_unknown_tags
Nonzero to warn about unknown tags.
Definition tiffiop.h:807
TIFFErrorHandlerExtR warnhandler
Optional per-handle warning callback, or NULL.
Definition tiffiop.h:797
void * warnhandler_user_data
Borrowed warning-callback context, or NULL.
Definition tiffiop.h:799
tmsize_t max_single_mem_alloc
Maximum individual allocation in bytes; zero means unlimited.
Definition tiffiop.h:801
Hold private state for one open TIFF library instance.
Definition tiffiop.h:389
TIFFReadWriteProc tif_readproc
Client read callback.
Definition tiffiop.h:714
TIFFReadWriteProc tif_writeproc
Client write callback.
Definition tiffiop.h:716
tmsize_t tif_max_single_mem_alloc
Single-allocation byte limit; zero means unlimited.
Definition tiffiop.h:769
TIFFUnmapFileProc tif_unmapproc
Client callback releasing a mapped-file view.
Definition tiffiop.h:709
TIFFSeekProc tif_seekproc
Client seek callback.
Definition tiffiop.h:718
TIFFCloseProc tif_closeproc
Client I/O close callback.
Definition tiffiop.h:720
thandle_t tif_clientdata
Client I/O context passed unchanged to the I/O callbacks.
Definition tiffiop.h:712
char * tif_name
Current filename pointer; may refer to inline or client-supplied storage.
Definition tiffiop.h:394
TIFFDirectory tif_dir
Inline representation of the current image directory.
Definition tiffiop.h:572
tdir_t tif_curdir
Track the current or last-written directory index.
Definition tiffiop.h:599
tmsize_t tif_cur_cumulated_mem_alloc
Current tracked allocation total in bytes.
Definition tiffiop.h:775
int tif_fd
File-descriptor metadata; client I/O still uses tif_clientdata.
Definition tiffiop.h:398
TIFFMapFileProc tif_mapproc
Client callback providing a mapped-file view.
Definition tiffiop.h:707
TIFFHeaderUnion tif_header
Inline decoded classic TIFF or BigTIFF file header.
Definition tiffiop.h:578
tmsize_t tif_max_cumulated_mem_alloc
Cumulative tracked-allocation byte limit; zero means unlimited.
Definition tiffiop.h:773
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
Definition tiffiop.h:404
int tif_mode
Current access mode using the O_* constants.
Definition tiffiop.h:400
TIFFSizeProc tif_sizeproc
Client file-size callback.
Definition tiffiop.h:722
Declare private library state, callbacks, and implementation helpers.
Store either TIFF header layout in the library's in-memory state.
Definition tiffiop.h:361
TIFFHeaderCommon common
Shared byte-order and version fields.
Definition tiffiop.h:363
TIFFHeaderBig big
Header when version is TIFF_VERSION_BIG.
Definition tiffiop.h:367