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