tif_open.c 18 KB

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