1 /* PDFlib GmbH cvsid:
2  * $Id: tif_open.c,v 1.26.2.1 2006/12/27 15:03:32 rjs Exp $ */
3 
4 /*
5  * Copyright (c) 1988-1997 Sam Leffler
6  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7  *
8  * Permission to use, copy, modify, distribute, and sell this software and
9  * its documentation for any purpose is hereby granted without fee, provided
10  * that (i) the above copyright notices and this permission notice appear in
11  * all copies of the software and related documentation, and (ii) the names of
12  * Sam Leffler and Silicon Graphics may not be used in any advertising or
13  * publicity relating to the software without the specific, prior written
14  * permission of Sam Leffler and Silicon Graphics.
15  *
16  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
21  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
22  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
24  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25  * OF THIS SOFTWARE.
26  */
27 
28 /*
29  * TIFF Library.
30  */
31 #include "tiffiop.h"
32 
33 static const long typemask[13] = {
34 	(long)0L,		/* TIFF_NOTYPE */
35 	(long)0x000000ffL,	/* TIFF_BYTE */
36 	(long)0xffffffffL,	/* TIFF_ASCII */
37 	(long)0x0000ffffL,	/* TIFF_SHORT */
38 	(long)0xffffffffL,	/* TIFF_LONG */
39 	(long)0xffffffffL,	/* TIFF_RATIONAL */
40 	(long)0x000000ffL,	/* TIFF_SBYTE */
41 	(long)0x000000ffL,	/* TIFF_UNDEFINED */
42 	(long)0x0000ffffL,	/* TIFF_SSHORT */
43 	(long)0xffffffffL,	/* TIFF_SLONG */
44 	(long)0xffffffffL,	/* TIFF_SRATIONAL */
45 	(long)0xffffffffL,	/* TIFF_FLOAT */
46 	(long)0xffffffffL,	/* TIFF_DOUBLE */
47 };
48 static const int bigTypeshift[13] = {
49 	0,		/* TIFF_NOTYPE */
50 	24,		/* TIFF_BYTE */
51 	0,		/* TIFF_ASCII */
52 	16,		/* TIFF_SHORT */
53 	0,		/* TIFF_LONG */
54 	0,		/* TIFF_RATIONAL */
55 	24,		/* TIFF_SBYTE */
56 	24,		/* TIFF_UNDEFINED */
57 	16,		/* TIFF_SSHORT */
58 	0,		/* TIFF_SLONG */
59 	0,		/* TIFF_SRATIONAL */
60 	0,		/* TIFF_FLOAT */
61 	0,		/* TIFF_DOUBLE */
62 };
63 static const int litTypeshift[13] = {
64 	0,		/* TIFF_NOTYPE */
65 	0,		/* TIFF_BYTE */
66 	0,		/* TIFF_ASCII */
67 	0,		/* TIFF_SHORT */
68 	0,		/* TIFF_LONG */
69 	0,		/* TIFF_RATIONAL */
70 	0,		/* TIFF_SBYTE */
71 	0,		/* TIFF_UNDEFINED */
72 	0,		/* TIFF_SSHORT */
73 	0,		/* TIFF_SLONG */
74 	0,		/* TIFF_SRATIONAL */
75 	0,		/* TIFF_FLOAT */
76 	0,		/* TIFF_DOUBLE */
77 };
78 
79 #ifdef PDFlib_NOT_USED
80 /*
81  * Dummy functions to fill the omitted client procedures.
82  */
83 static int
_tiffDummyMapProc(FILE * fd,tdata_t * pbase,toff_t * psize)84 _tiffDummyMapProc(FILE * fd, tdata_t* pbase, toff_t* psize)
85 {
86 	return (0);
87 }
88 
89 static void
_tiffDummyUnmapProc(FILE * fd,tdata_t base,toff_t size)90 _tiffDummyUnmapProc(FILE * fd, tdata_t base, toff_t size)
91 {
92 }
93 #endif
94 
95 /*
96  * Initialize the shift & mask tables, and the
97  * byte swapping state according to the file
98  * contents and the machine architecture.
99  */
100 static void
TIFFInitOrder(TIFF * tif,int magic,int bigendian)101 TIFFInitOrder(TIFF* tif, int magic, int bigendian)
102 {
103 	tif->tif_typemask = typemask;
104 	if (magic == TIFF_BIGENDIAN) {
105 		tif->tif_typeshift = bigTypeshift;
106 	    if (!bigendian)
107 		tif->tif_flags |= TIFF_SWAB;
108 	} else {
109 		tif->tif_typeshift = litTypeshift;
110 	    if (bigendian)
111 		tif->tif_flags |= TIFF_SWAB;
112 	}
113 }
114 
115 int
_TIFFgetMode(const char * mode,const char * module)116 _TIFFgetMode(const char* mode, const char* module)
117 {
118 	/* PDFlib GmbH  we support only r or w */
119 	int m = -1;
120 	TIFF* tif = NULL;
121 
122 	switch (mode[0]) {
123 	case 'r':
124 		m = O_RDONLY;
125 		if (mode[1] == '+') {
126 			m = O_RDWR;
127 			_TIFFError(tif, module,
128 				"\"%s\": Bad mode (PDFlib)", mode);
129 		}
130 		break;
131 	case 'w':
132 	case 'a':
133 		m = O_RDWR|O_CREAT;
134 		if (mode[0] == 'w') {
135 			m |= O_TRUNC;
136 		}
137 		break;
138 	default:
139 		_TIFFError(tif, module, "\"%s\": Bad mode", mode);
140 		break;
141 	}
142 	return (m);
143 }
144 
145 TIFF*
TIFFClientOpen(const char * name,const char * mode,void * clientdata,TIFFReadWriteProc readproc,TIFFReadWriteProc writeproc,TIFFSeekProc seekproc,TIFFCloseProc closeproc,TIFFSizeProc sizeproc,TIFFMapFileProc mapproc,TIFFUnmapFileProc unmapproc,void * pdflib_opaque,TIFFmallocHandler malloc_h,TIFFreallocHandler realloc_h,TIFFfreeHandler free_h,TIFFErrorHandler error_h,TIFFErrorHandler warn_h)146 TIFFClientOpen(
147 	const char* name, const char* mode,
148 	void* clientdata,
149 	TIFFReadWriteProc readproc,
150 	TIFFReadWriteProc writeproc,
151 	TIFFSeekProc seekproc,
152 	TIFFCloseProc closeproc,
153 	TIFFSizeProc sizeproc,
154 	TIFFMapFileProc mapproc,
155         TIFFUnmapFileProc unmapproc,
156         void* pdflib_opaque,
157         TIFFmallocHandler malloc_h,
158         TIFFreallocHandler realloc_h,
159         TIFFfreeHandler free_h,
160         TIFFErrorHandler error_h,
161         TIFFErrorHandler warn_h
162 )
163 {
164 	static const char module[] = "TIFFClientOpen";
165 	TIFF pdftiff;
166         TIFF *tif = &pdftiff;
167 	int m;
168 	int bigendian;
169 	const char* cp;
170 
171 	(void) mapproc;
172         (void) unmapproc;
173 
174 	{ union { int32 i; char c[4]; } u; u.i = 1; bigendian = u.c[0] == 0; }
175 	m = _TIFFgetMode(mode, module);
176 	if (m == -1)
177 		goto bad2;
178         /* PDFlib: preset tiff structure so that the first malloc works */
179         tif->pdflib_opaque = pdflib_opaque;
180         tif->pdflib_malloc = malloc_h;
181         tif->pdflib_realloc = realloc_h;
182         tif->pdflib_free = free_h;
183         tif->pdflib_error = error_h;
184         tif->pdflib_warn = warn_h;
185 
186 	tif = (TIFF *)_TIFFmalloc(sizeof (TIFF) + strlen(name) + 1);
187 	if (tif == NULL) {
188 		_TIFFError(tif, module,
189 			"%s: Out of memory (TIFF structure)", name);
190 		goto bad2;
191 	}
192 	_TIFFmemset(tif, 0, sizeof (*tif));
193 
194         /* PDFlib: add own mallochandling */
195         tif->pdflib_opaque = pdflib_opaque;
196         tif->pdflib_malloc = malloc_h;
197         tif->pdflib_realloc = realloc_h;
198         tif->pdflib_free = free_h;
199         tif->pdflib_error = error_h;
200         tif->pdflib_warn = warn_h;
201 
202 	tif->tif_name = (char *)tif + sizeof (TIFF);
203 	strcpy(tif->tif_name, name);
204 	tif->tif_mode = m &~ (O_CREAT|O_TRUNC);
205 	tif->tif_curdir = (tdir_t) -1;		/* non-existent directory */
206 	tif->tif_curoff = 0;
207 	tif->tif_curstrip = (tstrip_t) -1;	/* invalid strip */
208 	tif->tif_row = (uint32) -1;		/* read/write pre-increment */
209 	tif->tif_clientdata = clientdata;
210 #ifdef PDFlib_NOT_USED
211 	if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) {
212 		_TIFFError(tif, module,
213 			  "One of the client procedures is NULL pointer.");
214 		goto bad2;
215 	}
216 #endif /* PDFLIB_TIFFWRITE_SUPPORT */
217 	tif->tif_readproc = readproc;
218 	tif->tif_writeproc = writeproc;
219 	tif->tif_seekproc = seekproc;
220 	tif->tif_closeproc = closeproc;
221 	tif->tif_sizeproc = sizeproc;
222 #ifdef HAVE_MMAP
223         if (mapproc)
224 		tif->tif_mapproc = mapproc;
225 	else
226 		tif->tif_mapproc = _tiffDummyMapProc;
227 	if (unmapproc)
228 		tif->tif_unmapproc = unmapproc;
229 	else
230 		tif->tif_unmapproc = _tiffDummyUnmapProc;
231 #endif
232 	_TIFFSetDefaultCompressionState(tif);	/* setup default state */
233 	/*
234 	 * Default is to return data MSB2LSB and enable the
235 	 * use of memory-mapped files and strip chopping when
236 	 * a file is opened read-only.
237 	 */
238 	tif->tif_flags = FILLORDER_MSB2LSB;
239 #ifdef HAVE_MMAP
240 	if (m == O_RDONLY )
241             tif->tif_flags |= TIFF_MAPPED;
242 #endif
243 
244 #ifdef STRIPCHOP_DEFAULT
245 	if (m == O_RDONLY || m == O_RDWR)
246 		tif->tif_flags |= STRIPCHOP_DEFAULT;
247 #endif
248 
249 	/*
250 	 * Process library-specific flags in the open mode string.
251 	 * The following flags may be used to control intrinsic library
252 	 * behaviour that may or may not be desirable (usually for
253 	 * compatibility with some application that claims to support
254 	 * TIFF but only supports some braindead idea of what the
255 	 * vendor thinks TIFF is):
256 	 *
257 	 * 'l'		use little-endian byte order for creating a file
258 	 * 'b'		use big-endian byte order for creating a file
259 	 * 'L'		read/write information using LSB2MSB bit order
260 	 * 'B'		read/write information using MSB2LSB bit order
261 	 * 'H'		read/write information using host bit order
262 	 * 'M'		enable use of memory-mapped files when supported
263 	 * 'm'		disable use of memory-mapped files
264 	 * 'C'		enable strip chopping support when reading
265 	 * 'c'		disable strip chopping support
266 	 * 'h'		read TIFF header only, do not load the first IFD
267 	 *
268 	 * The use of the 'l' and 'b' flags is strongly discouraged.
269 	 * These flags are provided solely because numerous vendors,
270 	 * typically on the PC, do not correctly support TIFF; they
271 	 * only support the Intel little-endian byte order.  This
272 	 * support is not configured by default because it supports
273 	 * the violation of the TIFF spec that says that readers *MUST*
274 	 * support both byte orders.  It is strongly recommended that
275 	 * you not use this feature except to deal with busted apps
276 	 * that write invalid TIFF.  And even in those cases you should
277 	 * bang on the vendors to fix their software.
278 	 *
279 	 * The 'L', 'B', and 'H' flags are intended for applications
280 	 * that can optimize operations on data by using a particular
281 	 * bit order.  By default the library returns data in MSB2LSB
282 	 * bit order for compatibiltiy with older versions of this
283 	 * library.  Returning data in the bit order of the native cpu
284 	 * makes the most sense but also requires applications to check
285 	 * the value of the FillOrder tag; something they probably do
286 	 * not do right now.
287 	 *
288 	 * The 'M' and 'm' flags are provided because some virtual memory
289 	 * systems exhibit poor behaviour when large images are mapped.
290 	 * These options permit clients to control the use of memory-mapped
291 	 * files on a per-file basis.
292 	 *
293 	 * The 'C' and 'c' flags are provided because the library support
294 	 * for chopping up large strips into multiple smaller strips is not
295 	 * application-transparent and as such can cause problems.  The 'c'
296 	 * option permits applications that only want to look at the tags,
297 	 * for example, to get the unadulterated TIFF tag information.
298 	 */
299 	for (cp = mode; *cp; cp++)
300 		switch (*cp) {
301 		case 'b':
302 		    if ((m&O_CREAT) && !bigendian)
303 				tif->tif_flags |= TIFF_SWAB;
304 			break;
305 		case 'l':
306 			if ((m&O_CREAT) && bigendian)
307 				tif->tif_flags |= TIFF_SWAB;
308 			break;
309 		case 'B':
310 			tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) |
311 			    FILLORDER_MSB2LSB;
312 			break;
313 		case 'L':
314 			tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) |
315 			    FILLORDER_LSB2MSB;
316 			break;
317 #ifdef PDFlib_NOT_USED       /* PDFlib GmbH */
318 		case 'H':
319 			tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) |
320 			    HOST_FILLORDER;
321 			break;
322 #endif
323 #ifdef HAVE_MMAP
324 		case 'M':
325 			if (m == O_RDONLY)
326 				tif->tif_flags |= TIFF_MAPPED;
327 			break;
328 		case 'm':
329 			if (m == O_RDONLY)
330 				tif->tif_flags &= ~TIFF_MAPPED;
331 			break;
332 #endif
333 		case 'C':
334 			if (m == O_RDONLY)
335 				tif->tif_flags |= TIFF_STRIPCHOP;
336 			break;
337 		case 'c':
338 			if (m == O_RDONLY)
339 				tif->tif_flags &= ~TIFF_STRIPCHOP;
340 			break;
341 		case 'h':
342 			tif->tif_flags |= TIFF_HEADERONLY;
343 			break;
344 		}
345 	/*
346 	 * Read in TIFF header.
347 	 */
348 	if (tif->tif_mode & O_TRUNC ||
349 	    !ReadOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
350 		if (tif->tif_mode == O_RDONLY) {
351 			_TIFFError(tif, name, "Cannot read TIFF header");
352 			goto bad;
353 		}
354 		/*
355 		 * Setup header and write.
356 		 */
357 		tif->tif_header.tiff_magic = tif->tif_flags & TIFF_SWAB
358                    ? (bigendian ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN)
359                    : (bigendian ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN);
360 
361 		tif->tif_header.tiff_version = TIFF_VERSION;
362 		if (tif->tif_flags & TIFF_SWAB)
363 			TIFFSwabShort(&tif->tif_header.tiff_version);
364 		tif->tif_header.tiff_diroff = 0;	/* filled in later */
365 
366 
367                 /*
368                  * The doc for "fopen" for some STD_C_LIBs says that if you
369                  * open a file for modify ("+"), then you must fseek (or
370                  * fflush?) between any freads and fwrites.  This is not
371                  * necessary on most systems, but has been shown to be needed
372                  * on Solaris.
373                  */
374                 TIFFSeekFile( tif, 0, SEEK_SET );
375 
376 		if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
377 			_TIFFError(tif, name, "Error writing TIFF header");
378 			goto bad;
379 		}
380 		/*
381 		 * Setup the byte order handling.
382 		 */
383 		TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
384 		/*
385 		 * Setup default directory.
386 		 */
387 		if (!TIFFDefaultDirectory(tif))
388 			goto bad;
389 		tif->tif_diroff = 0;
390 		tif->tif_dirlist = NULL;
391 		tif->tif_dirnumber = 0;
392 		return (tif);
393 	}
394 	/*
395 	 * Setup the byte order handling.
396 	 */
397 	if (tif->tif_header.tiff_magic != TIFF_BIGENDIAN &&
398 	    tif->tif_header.tiff_magic != TIFF_LITTLEENDIAN) {
399 		_TIFFError(tif, name,
400 			"Not a TIFF file, bad magic number %d (0x%x)",
401 		    tif->tif_header.tiff_magic,
402 		    tif->tif_header.tiff_magic);
403 		goto bad;
404 	}
405 	TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
406 	/*
407 	 * Swap header if required.
408 	 */
409 	if (tif->tif_flags & TIFF_SWAB) {
410 		TIFFSwabShort(&tif->tif_header.tiff_version);
411 		TIFFSwabLong(&tif->tif_header.tiff_diroff);
412 	}
413 	/*
414 	 * Now check version (if needed, it's been byte-swapped).
415 	 * Note that this isn't actually a version number, it's a
416 	 * magic number that doesn't change (stupid).
417 	 */
418 	if (tif->tif_header.tiff_version == TIFF_BIGTIFF_VERSION) {
419 		_TIFFError(tif, name,
420                           "This is a BigTIFF file.  This format not supported\n"
421                           "by this version of libtiff." );
422 		goto bad;
423 	}
424 	if (tif->tif_header.tiff_version != TIFF_VERSION) {
425 		_TIFFError(tif, name,
426 		    "Not a TIFF file, bad version number %d (0x%x)",
427 		    tif->tif_header.tiff_version,
428 		    tif->tif_header.tiff_version);
429 		goto bad;
430 	}
431 	tif->tif_flags |= TIFF_MYBUFFER;
432 	tif->tif_rawcp = tif->tif_rawdata = 0;
433 	tif->tif_rawdatasize = 0;
434 
435 	/*
436 	 * Sometimes we do not want to read the first directory (for example,
437 	 * it may be broken) and want to proceed to other directories. I this
438 	 * case we use the TIFF_HEADERONLY flag to open file and return
439 	 * immediately after reading TIFF header.
440 	 */
441 	if (tif->tif_flags & TIFF_HEADERONLY)
442 		return (tif);
443 
444 	/*
445 	 * Setup initial directory.
446 	 */
447 	switch (mode[0]) {
448 	case 'r':
449 		tif->tif_nextdiroff = tif->tif_header.tiff_diroff;
450 #ifdef HAVE_MMAP
451 		/*
452 		 * Try to use a memory-mapped file if the client
453 		 * has not explicitly suppressed usage with the
454 		 * 'm' flag in the open mode (see above).
455 		 */
456 		if ((tif->tif_flags & TIFF_MAPPED) &&
457 	!TIFFMapFileContents(tif, (tdata_t*) &tif->tif_base, &tif->tif_size))
458 			tif->tif_flags &= ~TIFF_MAPPED;
459 #endif
460 		if (TIFFReadDirectory(tif)) {
461 			tif->tif_rawcc = -1;
462 			tif->tif_flags |= TIFF_BUFFERSETUP;
463 			return (tif);
464 		}
465 		break;
466 	case 'a':
467 		/*
468 		 * New directories are automatically append
469 		 * to the end of the directory chain when they
470 		 * are written out (see TIFFWriteDirectory).
471 		 */
472 		if (!TIFFDefaultDirectory(tif))
473 			goto bad;
474 		return (tif);
475 	}
476 bad:
477 	tif->tif_mode = O_RDONLY;	/* XXX avoid flush */
478         TIFFCleanup(tif);
479 bad2:
480 	return ((TIFF*)0);
481 }
482 
483 /*
484  * Query functions to access private data.
485  */
486 
487 /*
488  * Return open file's name.
489  */
490 const char *
TIFFFileName(TIFF * tif)491 TIFFFileName(TIFF* tif)
492 {
493 	return (tif->tif_name);
494 }
495 
496 /*
497  * Set the file name.
498  */
499 const char *
TIFFSetFileName(TIFF * tif,const char * name)500 TIFFSetFileName(TIFF* tif, const char *name)
501 {
502 	const char* old_name = tif->tif_name;
503 	tif->tif_name = (char *)name;
504 	return (old_name);
505 }
506 
507 /*
508  * Return open file's I/O descriptor.
509  */
510 FILE *
TIFFFileno(TIFF * tif)511 TIFFFileno(TIFF* tif)
512 {
513 	return (tif->tif_fd);
514 }
515 
516 /*
517  * Set open file's I/O descriptor, and return previous value.
518  */
519 FILE *
TIFFSetFileno(TIFF * tif,FILE * fd)520 TIFFSetFileno(TIFF* tif, FILE* fd)
521 {
522         FILE* old_fd = tif->tif_fd;
523 	tif->tif_fd = fd;
524 	return old_fd;
525 }
526 
527 /*
528  * Return open file's clientdata.
529  */
530 FILE *
TIFFClientdata(TIFF * tif)531 TIFFClientdata(TIFF* tif)
532 {
533 	return ((FILE *)tif->tif_clientdata);
534 }
535 
536 /*
537  * Set open file's clientdata, and return previous value.
538  */
539 FILE *
TIFFSetClientdata(TIFF * tif,FILE * newvalue)540 TIFFSetClientdata(TIFF* tif, FILE * newvalue)
541 {
542 	FILE * m = (FILE *)tif->tif_clientdata;
543 	tif->tif_clientdata = newvalue;
544 	return m;
545 }
546 
547 /*
548  * Return read/write mode.
549  */
550 int
TIFFGetMode(TIFF * tif)551 TIFFGetMode(TIFF* tif)
552 {
553 	return (tif->tif_mode);
554 }
555 
556 /*
557  * Return read/write mode.
558  */
559 int
TIFFSetMode(TIFF * tif,int mode)560 TIFFSetMode(TIFF* tif, int mode)
561 {
562 	int old_mode = tif->tif_mode;
563 	tif->tif_mode = mode;
564 	return (old_mode);
565 }
566 
567 /*
568  * Return nonzero if file is organized in
569  * tiles; zero if organized as strips.
570  */
571 int
TIFFIsTiled(TIFF * tif)572 TIFFIsTiled(TIFF* tif)
573 {
574 	return (isTiled(tif));
575 }
576 
577 /*
578  * Return current row being read/written.
579  */
580 uint32
TIFFCurrentRow(TIFF * tif)581 TIFFCurrentRow(TIFF* tif)
582 {
583 	return (tif->tif_row);
584 }
585 
586 /*
587  * Return index of the current directory.
588  */
589 tdir_t
TIFFCurrentDirectory(TIFF * tif)590 TIFFCurrentDirectory(TIFF* tif)
591 {
592 	return (tif->tif_curdir);
593 }
594 
595 /*
596  * Return current strip.
597  */
598 tstrip_t
TIFFCurrentStrip(TIFF * tif)599 TIFFCurrentStrip(TIFF* tif)
600 {
601 	return (tif->tif_curstrip);
602 }
603 
604 /*
605  * Return current tile.
606  */
607 ttile_t
TIFFCurrentTile(TIFF * tif)608 TIFFCurrentTile(TIFF* tif)
609 {
610 	return (tif->tif_curtile);
611 }
612 
613 /*
614  * Return nonzero if the file has byte-swapped data.
615  */
616 int
TIFFIsByteSwapped(TIFF * tif)617 TIFFIsByteSwapped(TIFF* tif)
618 {
619 	return ((tif->tif_flags & TIFF_SWAB) != 0);
620 }
621 
622 /*
623  * Return nonzero if the data is returned up-sampled.
624  */
625 int
TIFFIsUpSampled(TIFF * tif)626 TIFFIsUpSampled(TIFF* tif)
627 {
628 	return (isUpSampled(tif));
629 }
630 
631 /*
632  * Return nonzero if the data is returned in MSB-to-LSB bit order.
633  */
634 int
TIFFIsMSB2LSB(TIFF * tif)635 TIFFIsMSB2LSB(TIFF* tif)
636 {
637 	return (isFillOrder(tif, FILLORDER_MSB2LSB));
638 }
639 
640 /*
641  * Return nonzero if given file was written in big-endian order.
642  */
643 int
TIFFIsBigEndian(TIFF * tif)644 TIFFIsBigEndian(TIFF* tif)
645 {
646 	return (tif->tif_header.tiff_magic == TIFF_BIGENDIAN);
647 }
648 
649 /*
650  * Return pointer to file read method.
651  */
652 TIFFReadWriteProc
TIFFGetReadProc(TIFF * tif)653 TIFFGetReadProc(TIFF* tif)
654 {
655 	return (tif->tif_readproc);
656 }
657 
658 /*
659  * Return pointer to file write method.
660  */
661 TIFFReadWriteProc
TIFFGetWriteProc(TIFF * tif)662 TIFFGetWriteProc(TIFF* tif)
663 {
664 	return (tif->tif_writeproc);
665 }
666 
667 /*
668  * Return pointer to file seek method.
669  */
670 TIFFSeekProc
TIFFGetSeekProc(TIFF * tif)671 TIFFGetSeekProc(TIFF* tif)
672 {
673 	return (tif->tif_seekproc);
674 }
675 
676 /*
677  * Return pointer to file close method.
678  */
679 TIFFCloseProc
TIFFGetCloseProc(TIFF * tif)680 TIFFGetCloseProc(TIFF* tif)
681 {
682 	return (tif->tif_closeproc);
683 }
684 
685 /*
686  * Return pointer to file size requesting method.
687  */
688 TIFFSizeProc
TIFFGetSizeProc(TIFF * tif)689 TIFFGetSizeProc(TIFF* tif)
690 {
691 	return (tif->tif_sizeproc);
692 }
693 
694 /*
695  * Return pointer to memory mapping method.
696  */
697 TIFFMapFileProc
TIFFGetMapFileProc(TIFF * tif)698 TIFFGetMapFileProc(TIFF* tif)
699 {
700 	return (tif->tif_mapproc);
701 }
702 
703 /*
704  * Return pointer to memory unmapping method.
705  */
706 TIFFUnmapFileProc
TIFFGetUnmapFileProc(TIFF * tif)707 TIFFGetUnmapFileProc(TIFF* tif)
708 {
709 	return (tif->tif_unmapproc);
710 }
711 
712 /* vim: set ts=8 sts=8 sw=8 noet: */
713