2
0

tif_open.c 18 KB

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