tif_print.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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. * Directory Printing Support
  28. */
  29. #include "tiffiop.h"
  30. #include <stdio.h>
  31. #include <ctype.h>
  32. static void
  33. _TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars);
  34. static const char * const photoNames[] = {
  35. "min-is-white", /* PHOTOMETRIC_MINISWHITE */
  36. "min-is-black", /* PHOTOMETRIC_MINISBLACK */
  37. "RGB color", /* PHOTOMETRIC_RGB */
  38. "palette color (RGB from colormap)", /* PHOTOMETRIC_PALETTE */
  39. "transparency mask", /* PHOTOMETRIC_MASK */
  40. "separated", /* PHOTOMETRIC_SEPARATED */
  41. "YCbCr", /* PHOTOMETRIC_YCBCR */
  42. "7 (0x7)",
  43. "CIE L*a*b*", /* PHOTOMETRIC_CIELAB */
  44. "ICC L*a*b*", /* PHOTOMETRIC_ICCLAB */
  45. "ITU L*a*b*" /* PHOTOMETRIC_ITULAB */
  46. };
  47. #define NPHOTONAMES (sizeof (photoNames) / sizeof (photoNames[0]))
  48. static const char * const orientNames[] = {
  49. "0 (0x0)",
  50. "row 0 top, col 0 lhs", /* ORIENTATION_TOPLEFT */
  51. "row 0 top, col 0 rhs", /* ORIENTATION_TOPRIGHT */
  52. "row 0 bottom, col 0 rhs", /* ORIENTATION_BOTRIGHT */
  53. "row 0 bottom, col 0 lhs", /* ORIENTATION_BOTLEFT */
  54. "row 0 lhs, col 0 top", /* ORIENTATION_LEFTTOP */
  55. "row 0 rhs, col 0 top", /* ORIENTATION_RIGHTTOP */
  56. "row 0 rhs, col 0 bottom", /* ORIENTATION_RIGHTBOT */
  57. "row 0 lhs, col 0 bottom", /* ORIENTATION_LEFTBOT */
  58. };
  59. #define NORIENTNAMES (sizeof (orientNames) / sizeof (orientNames[0]))
  60. static void
  61. _TIFFPrintField(FILE* fd, const TIFFField *fip,
  62. uint32 value_count, void *raw_data)
  63. {
  64. uint32 j;
  65. fprintf(fd, " %s: ", fip->field_name);
  66. for(j = 0; j < value_count; j++) {
  67. if(fip->field_type == TIFF_BYTE)
  68. fprintf(fd, "%u", ((uint8 *) raw_data)[j]);
  69. else if(fip->field_type == TIFF_UNDEFINED)
  70. fprintf(fd, "0x%x",
  71. (unsigned int) ((unsigned char *) raw_data)[j]);
  72. else if(fip->field_type == TIFF_SBYTE)
  73. fprintf(fd, "%d", ((int8 *) raw_data)[j]);
  74. else if(fip->field_type == TIFF_SHORT)
  75. fprintf(fd, "%u", ((uint16 *) raw_data)[j]);
  76. else if(fip->field_type == TIFF_SSHORT)
  77. fprintf(fd, "%d", ((int16 *) raw_data)[j]);
  78. else if(fip->field_type == TIFF_LONG)
  79. fprintf(fd, "%lu",
  80. (unsigned long)((uint32 *) raw_data)[j]);
  81. else if(fip->field_type == TIFF_SLONG)
  82. fprintf(fd, "%ld", (long)((int32 *) raw_data)[j]);
  83. else if(fip->field_type == TIFF_IFD)
  84. fprintf(fd, "0x%lx",
  85. (unsigned long)((uint32 *) raw_data)[j]);
  86. else if(fip->field_type == TIFF_RATIONAL
  87. || fip->field_type == TIFF_SRATIONAL
  88. || fip->field_type == TIFF_FLOAT)
  89. fprintf(fd, "%f", ((float *) raw_data)[j]);
  90. else if(fip->field_type == TIFF_LONG8)
  91. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  92. fprintf(fd, "%I64u",
  93. (unsigned __int64)((uint64 *) raw_data)[j]);
  94. #else
  95. fprintf(fd, "%llu",
  96. (unsigned long long)((uint64 *) raw_data)[j]);
  97. #endif
  98. else if(fip->field_type == TIFF_SLONG8)
  99. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  100. fprintf(fd, "%I64d", (__int64)((int64 *) raw_data)[j]);
  101. #else
  102. fprintf(fd, "%lld", (long long)((int64 *) raw_data)[j]);
  103. #endif
  104. else if(fip->field_type == TIFF_IFD8)
  105. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  106. fprintf(fd, "0x%I64x",
  107. (unsigned __int64)((uint64 *) raw_data)[j]);
  108. #else
  109. fprintf(fd, "0x%llx",
  110. (unsigned long long)((uint64 *) raw_data)[j]);
  111. #endif
  112. else if(fip->field_type == TIFF_FLOAT)
  113. fprintf(fd, "%f", ((float *)raw_data)[j]);
  114. else if(fip->field_type == TIFF_DOUBLE)
  115. fprintf(fd, "%f", ((double *) raw_data)[j]);
  116. else if(fip->field_type == TIFF_ASCII) {
  117. fprintf(fd, "%s", (char *) raw_data);
  118. break;
  119. }
  120. else {
  121. fprintf(fd, "<unsupported data type in TIFFPrint>");
  122. break;
  123. }
  124. if(j < value_count - 1)
  125. fprintf(fd, ",");
  126. }
  127. fprintf(fd, "\n");
  128. }
  129. static int
  130. _TIFFPrettyPrintField(TIFF* tif, const TIFFField *fip, FILE* fd, uint32 tag,
  131. uint32 value_count, void *raw_data)
  132. {
  133. (void) tif;
  134. /* do not try to pretty print auto-defined fields */
  135. if (strncmp(fip->field_name,"Tag ", 4) == 0) {
  136. return 0;
  137. }
  138. switch (tag)
  139. {
  140. case TIFFTAG_INKSET:
  141. if (value_count == 2 && fip->field_type == TIFF_SHORT) {
  142. fprintf(fd, " Ink Set: ");
  143. switch (*((uint16*)raw_data)) {
  144. case INKSET_CMYK:
  145. fprintf(fd, "CMYK\n");
  146. break;
  147. default:
  148. fprintf(fd, "%u (0x%x)\n",
  149. *((uint16*)raw_data),
  150. *((uint16*)raw_data));
  151. break;
  152. }
  153. return 1;
  154. }
  155. return 0;
  156. case TIFFTAG_DOTRANGE:
  157. if (value_count == 2 && fip->field_type == TIFF_SHORT) {
  158. fprintf(fd, " Dot Range: %u-%u\n",
  159. ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]);
  160. return 1;
  161. }
  162. return 0;
  163. case TIFFTAG_WHITEPOINT:
  164. if (value_count == 2 && fip->field_type == TIFF_RATIONAL) {
  165. fprintf(fd, " White Point: %g-%g\n",
  166. ((float *)raw_data)[0], ((float *)raw_data)[1]);
  167. return 1;
  168. }
  169. return 0;
  170. case TIFFTAG_XMLPACKET:
  171. {
  172. uint32 i;
  173. fprintf(fd, " XMLPacket (XMP Metadata):\n" );
  174. for(i = 0; i < value_count; i++)
  175. fputc(((char *)raw_data)[i], fd);
  176. fprintf( fd, "\n" );
  177. return 1;
  178. }
  179. case TIFFTAG_RICHTIFFIPTC:
  180. /*
  181. * XXX: for some weird reason RichTIFFIPTC tag
  182. * defined as array of LONG values.
  183. */
  184. fprintf(fd,
  185. " RichTIFFIPTC Data: <present>, %lu bytes\n",
  186. (unsigned long) value_count * 4);
  187. return 1;
  188. case TIFFTAG_PHOTOSHOP:
  189. fprintf(fd, " Photoshop Data: <present>, %lu bytes\n",
  190. (unsigned long) value_count);
  191. return 1;
  192. case TIFFTAG_ICCPROFILE:
  193. fprintf(fd, " ICC Profile: <present>, %lu bytes\n",
  194. (unsigned long) value_count);
  195. return 1;
  196. case TIFFTAG_STONITS:
  197. if (value_count == 1 && fip->field_type == TIFF_DOUBLE) {
  198. fprintf(fd,
  199. " Sample to Nits conversion factor: %.4e\n",
  200. *((double*)raw_data));
  201. return 1;
  202. }
  203. return 0;
  204. }
  205. return 0;
  206. }
  207. /*
  208. * Print the contents of the current directory
  209. * to the specified stdio file stream.
  210. */
  211. void
  212. TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
  213. {
  214. TIFFDirectory *td = &tif->tif_dir;
  215. char *sep;
  216. long l, n;
  217. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  218. fprintf(fd, "TIFF Directory at offset 0x%I64x (%I64u)\n",
  219. (unsigned __int64) tif->tif_diroff,
  220. (unsigned __int64) tif->tif_diroff);
  221. #else
  222. fprintf(fd, "TIFF Directory at offset 0x%llx (%llu)\n",
  223. (unsigned long long) tif->tif_diroff,
  224. (unsigned long long) tif->tif_diroff);
  225. #endif
  226. if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
  227. fprintf(fd, " Subfile Type:");
  228. sep = " ";
  229. if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) {
  230. fprintf(fd, "%sreduced-resolution image", sep);
  231. sep = "/";
  232. }
  233. if (td->td_subfiletype & FILETYPE_PAGE) {
  234. fprintf(fd, "%smulti-page document", sep);
  235. sep = "/";
  236. }
  237. if (td->td_subfiletype & FILETYPE_MASK)
  238. fprintf(fd, "%stransparency mask", sep);
  239. fprintf(fd, " (%lu = 0x%lx)\n",
  240. (unsigned long) td->td_subfiletype, (long) td->td_subfiletype);
  241. }
  242. if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) {
  243. fprintf(fd, " Image Width: %lu Image Length: %lu",
  244. (unsigned long) td->td_imagewidth, (unsigned long) td->td_imagelength);
  245. if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))
  246. fprintf(fd, " Image Depth: %lu",
  247. (unsigned long) td->td_imagedepth);
  248. fprintf(fd, "\n");
  249. }
  250. if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
  251. fprintf(fd, " Tile Width: %lu Tile Length: %lu",
  252. (unsigned long) td->td_tilewidth, (unsigned long) td->td_tilelength);
  253. if (TIFFFieldSet(tif,FIELD_TILEDEPTH))
  254. fprintf(fd, " Tile Depth: %lu",
  255. (unsigned long) td->td_tiledepth);
  256. fprintf(fd, "\n");
  257. }
  258. if (TIFFFieldSet(tif,FIELD_RESOLUTION)) {
  259. fprintf(fd, " Resolution: %g, %g",
  260. td->td_xresolution, td->td_yresolution);
  261. if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) {
  262. switch (td->td_resolutionunit) {
  263. case RESUNIT_NONE:
  264. fprintf(fd, " (unitless)");
  265. break;
  266. case RESUNIT_INCH:
  267. fprintf(fd, " pixels/inch");
  268. break;
  269. case RESUNIT_CENTIMETER:
  270. fprintf(fd, " pixels/cm");
  271. break;
  272. default:
  273. fprintf(fd, " (unit %u = 0x%x)",
  274. td->td_resolutionunit,
  275. td->td_resolutionunit);
  276. break;
  277. }
  278. }
  279. fprintf(fd, "\n");
  280. }
  281. if (TIFFFieldSet(tif,FIELD_POSITION))
  282. fprintf(fd, " Position: %g, %g\n",
  283. td->td_xposition, td->td_yposition);
  284. if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))
  285. fprintf(fd, " Bits/Sample: %u\n", td->td_bitspersample);
  286. if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) {
  287. fprintf(fd, " Sample Format: ");
  288. switch (td->td_sampleformat) {
  289. case SAMPLEFORMAT_VOID:
  290. fprintf(fd, "void\n");
  291. break;
  292. case SAMPLEFORMAT_INT:
  293. fprintf(fd, "signed integer\n");
  294. break;
  295. case SAMPLEFORMAT_UINT:
  296. fprintf(fd, "unsigned integer\n");
  297. break;
  298. case SAMPLEFORMAT_IEEEFP:
  299. fprintf(fd, "IEEE floating point\n");
  300. break;
  301. case SAMPLEFORMAT_COMPLEXINT:
  302. fprintf(fd, "complex signed integer\n");
  303. break;
  304. case SAMPLEFORMAT_COMPLEXIEEEFP:
  305. fprintf(fd, "complex IEEE floating point\n");
  306. break;
  307. default:
  308. fprintf(fd, "%u (0x%x)\n",
  309. td->td_sampleformat, td->td_sampleformat);
  310. break;
  311. }
  312. }
  313. if (TIFFFieldSet(tif,FIELD_COMPRESSION)) {
  314. const TIFFCodec* c = TIFFFindCODEC(td->td_compression);
  315. fprintf(fd, " Compression Scheme: ");
  316. if (c)
  317. fprintf(fd, "%s\n", c->name);
  318. else
  319. fprintf(fd, "%u (0x%x)\n",
  320. td->td_compression, td->td_compression);
  321. }
  322. if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) {
  323. fprintf(fd, " Photometric Interpretation: ");
  324. if (td->td_photometric < NPHOTONAMES)
  325. fprintf(fd, "%s\n", photoNames[td->td_photometric]);
  326. else {
  327. switch (td->td_photometric) {
  328. case PHOTOMETRIC_LOGL:
  329. fprintf(fd, "CIE Log2(L)\n");
  330. break;
  331. case PHOTOMETRIC_LOGLUV:
  332. fprintf(fd, "CIE Log2(L) (u',v')\n");
  333. break;
  334. default:
  335. fprintf(fd, "%u (0x%x)\n",
  336. td->td_photometric, td->td_photometric);
  337. break;
  338. }
  339. }
  340. }
  341. if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) {
  342. uint16 i;
  343. fprintf(fd, " Extra Samples: %u<", td->td_extrasamples);
  344. sep = "";
  345. for (i = 0; i < td->td_extrasamples; i++) {
  346. switch (td->td_sampleinfo[i]) {
  347. case EXTRASAMPLE_UNSPECIFIED:
  348. fprintf(fd, "%sunspecified", sep);
  349. break;
  350. case EXTRASAMPLE_ASSOCALPHA:
  351. fprintf(fd, "%sassoc-alpha", sep);
  352. break;
  353. case EXTRASAMPLE_UNASSALPHA:
  354. fprintf(fd, "%sunassoc-alpha", sep);
  355. break;
  356. default:
  357. fprintf(fd, "%s%u (0x%x)", sep,
  358. td->td_sampleinfo[i], td->td_sampleinfo[i]);
  359. break;
  360. }
  361. sep = ", ";
  362. }
  363. fprintf(fd, ">\n");
  364. }
  365. if (TIFFFieldSet(tif,FIELD_INKNAMES)) {
  366. char* cp;
  367. uint16 i;
  368. fprintf(fd, " Ink Names: ");
  369. i = td->td_samplesperpixel;
  370. sep = "";
  371. for (cp = td->td_inknames;
  372. i > 0 && cp < td->td_inknames + td->td_inknameslen;
  373. cp = strchr(cp,'\0')+1, i--) {
  374. size_t max_chars =
  375. td->td_inknameslen - (cp - td->td_inknames);
  376. fputs(sep, fd);
  377. _TIFFprintAsciiBounded(fd, cp, max_chars);
  378. sep = ", ";
  379. }
  380. fputs("\n", fd);
  381. }
  382. if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) {
  383. fprintf(fd, " Thresholding: ");
  384. switch (td->td_threshholding) {
  385. case THRESHHOLD_BILEVEL:
  386. fprintf(fd, "bilevel art scan\n");
  387. break;
  388. case THRESHHOLD_HALFTONE:
  389. fprintf(fd, "halftone or dithered scan\n");
  390. break;
  391. case THRESHHOLD_ERRORDIFFUSE:
  392. fprintf(fd, "error diffused\n");
  393. break;
  394. default:
  395. fprintf(fd, "%u (0x%x)\n",
  396. td->td_threshholding, td->td_threshholding);
  397. break;
  398. }
  399. }
  400. if (TIFFFieldSet(tif,FIELD_FILLORDER)) {
  401. fprintf(fd, " FillOrder: ");
  402. switch (td->td_fillorder) {
  403. case FILLORDER_MSB2LSB:
  404. fprintf(fd, "msb-to-lsb\n");
  405. break;
  406. case FILLORDER_LSB2MSB:
  407. fprintf(fd, "lsb-to-msb\n");
  408. break;
  409. default:
  410. fprintf(fd, "%u (0x%x)\n",
  411. td->td_fillorder, td->td_fillorder);
  412. break;
  413. }
  414. }
  415. if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
  416. {
  417. fprintf(fd, " YCbCr Subsampling: %u, %u\n",
  418. td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1] );
  419. }
  420. if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
  421. fprintf(fd, " YCbCr Positioning: ");
  422. switch (td->td_ycbcrpositioning) {
  423. case YCBCRPOSITION_CENTERED:
  424. fprintf(fd, "centered\n");
  425. break;
  426. case YCBCRPOSITION_COSITED:
  427. fprintf(fd, "cosited\n");
  428. break;
  429. default:
  430. fprintf(fd, "%u (0x%x)\n",
  431. td->td_ycbcrpositioning, td->td_ycbcrpositioning);
  432. break;
  433. }
  434. }
  435. if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))
  436. fprintf(fd, " Halftone Hints: light %u dark %u\n",
  437. td->td_halftonehints[0], td->td_halftonehints[1]);
  438. if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {
  439. fprintf(fd, " Orientation: ");
  440. if (td->td_orientation < NORIENTNAMES)
  441. fprintf(fd, "%s\n", orientNames[td->td_orientation]);
  442. else
  443. fprintf(fd, "%u (0x%x)\n",
  444. td->td_orientation, td->td_orientation);
  445. }
  446. if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))
  447. fprintf(fd, " Samples/Pixel: %u\n", td->td_samplesperpixel);
  448. if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) {
  449. fprintf(fd, " Rows/Strip: ");
  450. if (td->td_rowsperstrip == (uint32) -1)
  451. fprintf(fd, "(infinite)\n");
  452. else
  453. fprintf(fd, "%lu\n", (unsigned long) td->td_rowsperstrip);
  454. }
  455. if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))
  456. fprintf(fd, " Min Sample Value: %u\n", td->td_minsamplevalue);
  457. if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
  458. fprintf(fd, " Max Sample Value: %u\n", td->td_maxsamplevalue);
  459. if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) {
  460. int i;
  461. int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
  462. fprintf(fd, " SMin Sample Value:");
  463. for (i = 0; i < count; ++i)
  464. fprintf(fd, " %g", td->td_sminsamplevalue[i]);
  465. fprintf(fd, "\n");
  466. }
  467. if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) {
  468. int i;
  469. int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
  470. fprintf(fd, " SMax Sample Value:");
  471. for (i = 0; i < count; ++i)
  472. fprintf(fd, " %g", td->td_smaxsamplevalue[i]);
  473. fprintf(fd, "\n");
  474. }
  475. if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) {
  476. fprintf(fd, " Planar Configuration: ");
  477. switch (td->td_planarconfig) {
  478. case PLANARCONFIG_CONTIG:
  479. fprintf(fd, "single image plane\n");
  480. break;
  481. case PLANARCONFIG_SEPARATE:
  482. fprintf(fd, "separate image planes\n");
  483. break;
  484. default:
  485. fprintf(fd, "%u (0x%x)\n",
  486. td->td_planarconfig, td->td_planarconfig);
  487. break;
  488. }
  489. }
  490. if (TIFFFieldSet(tif,FIELD_PAGENUMBER))
  491. fprintf(fd, " Page Number: %u-%u\n",
  492. td->td_pagenumber[0], td->td_pagenumber[1]);
  493. if (TIFFFieldSet(tif,FIELD_COLORMAP)) {
  494. fprintf(fd, " Color Map: ");
  495. if (flags & TIFFPRINT_COLORMAP) {
  496. fprintf(fd, "\n");
  497. n = 1L<<td->td_bitspersample;
  498. for (l = 0; l < n; l++)
  499. fprintf(fd, " %5ld: %5u %5u %5u\n",
  500. l,
  501. td->td_colormap[0][l],
  502. td->td_colormap[1][l],
  503. td->td_colormap[2][l]);
  504. } else
  505. fprintf(fd, "(present)\n");
  506. }
  507. if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) {
  508. int i;
  509. fprintf(fd, " Reference Black/White:\n");
  510. for (i = 0; i < 3; i++)
  511. fprintf(fd, " %2d: %5g %5g\n", i,
  512. td->td_refblackwhite[2*i+0],
  513. td->td_refblackwhite[2*i+1]);
  514. }
  515. if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {
  516. fprintf(fd, " Transfer Function: ");
  517. if (flags & TIFFPRINT_CURVES) {
  518. fprintf(fd, "\n");
  519. n = 1L<<td->td_bitspersample;
  520. for (l = 0; l < n; l++) {
  521. uint16 i;
  522. fprintf(fd, " %2ld: %5u",
  523. l, td->td_transferfunction[0][l]);
  524. for (i = 1; i < td->td_samplesperpixel - td->td_extrasamples && i < 3; i++)
  525. fprintf(fd, " %5u",
  526. td->td_transferfunction[i][l]);
  527. fputc('\n', fd);
  528. }
  529. } else
  530. fprintf(fd, "(present)\n");
  531. }
  532. if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) {
  533. uint16 i;
  534. fprintf(fd, " SubIFD Offsets:");
  535. for (i = 0; i < td->td_nsubifd; i++)
  536. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  537. fprintf(fd, " %5I64u",
  538. (unsigned __int64) td->td_subifd[i]);
  539. #else
  540. fprintf(fd, " %5llu",
  541. (unsigned long long) td->td_subifd[i]);
  542. #endif
  543. fputc('\n', fd);
  544. }
  545. /*
  546. ** Custom tag support.
  547. */
  548. {
  549. int i;
  550. short count;
  551. count = (short) TIFFGetTagListCount(tif);
  552. for(i = 0; i < count; i++) {
  553. uint32 tag = TIFFGetTagListEntry(tif, i);
  554. const TIFFField *fip;
  555. uint32 value_count;
  556. int mem_alloc = 0;
  557. void *raw_data;
  558. fip = TIFFFieldWithTag(tif, tag);
  559. if(fip == NULL)
  560. continue;
  561. if(fip->field_passcount) {
  562. if (fip->field_readcount == TIFF_VARIABLE2 ) {
  563. if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
  564. continue;
  565. } else if (fip->field_readcount == TIFF_VARIABLE ) {
  566. uint16 small_value_count;
  567. if(TIFFGetField(tif, tag, &small_value_count, &raw_data) != 1)
  568. continue;
  569. value_count = small_value_count;
  570. } else {
  571. assert (fip->field_readcount == TIFF_VARIABLE
  572. || fip->field_readcount == TIFF_VARIABLE2);
  573. continue;
  574. }
  575. } else {
  576. if (fip->field_readcount == TIFF_VARIABLE
  577. || fip->field_readcount == TIFF_VARIABLE2)
  578. value_count = 1;
  579. else if (fip->field_readcount == TIFF_SPP)
  580. value_count = td->td_samplesperpixel;
  581. else
  582. value_count = fip->field_readcount;
  583. if (fip->field_tag == TIFFTAG_DOTRANGE
  584. && strcmp(fip->field_name,"DotRange") == 0) {
  585. /* TODO: This is an evil exception and should not have been
  586. handled this way ... likely best if we move it into
  587. the directory structure with an explicit field in
  588. libtiff 4.1 and assign it a FIELD_ value */
  589. static uint16 dotrange[2];
  590. raw_data = dotrange;
  591. TIFFGetField(tif, tag, dotrange+0, dotrange+1);
  592. } else if (fip->field_type == TIFF_ASCII
  593. || fip->field_readcount == TIFF_VARIABLE
  594. || fip->field_readcount == TIFF_VARIABLE2
  595. || fip->field_readcount == TIFF_SPP
  596. || value_count > 1) {
  597. if(TIFFGetField(tif, tag, &raw_data) != 1)
  598. continue;
  599. } else {
  600. raw_data = _TIFFmalloc(
  601. _TIFFDataSize(fip->field_type)
  602. * value_count);
  603. mem_alloc = 1;
  604. if(TIFFGetField(tif, tag, raw_data) != 1) {
  605. _TIFFfree(raw_data);
  606. continue;
  607. }
  608. }
  609. }
  610. /*
  611. * Catch the tags which needs to be specially handled
  612. * and pretty print them. If tag not handled in
  613. * _TIFFPrettyPrintField() fall down and print it as
  614. * any other tag.
  615. */
  616. if (!_TIFFPrettyPrintField(tif, fip, fd, tag, value_count, raw_data))
  617. _TIFFPrintField(fd, fip, value_count, raw_data);
  618. if(mem_alloc)
  619. _TIFFfree(raw_data);
  620. }
  621. }
  622. if (tif->tif_tagmethods.printdir)
  623. (*tif->tif_tagmethods.printdir)(tif, fd, flags);
  624. if ((flags & TIFFPRINT_STRIPS) &&
  625. TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
  626. uint32 s;
  627. fprintf(fd, " %lu %s:\n",
  628. (unsigned long) td->td_nstrips,
  629. isTiled(tif) ? "Tiles" : "Strips");
  630. for (s = 0; s < td->td_nstrips; s++)
  631. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  632. fprintf(fd, " %3lu: [%8I64u, %8I64u]\n",
  633. (unsigned long) s,
  634. (unsigned __int64) TIFFGetStrileOffset(tif, s),
  635. (unsigned __int64) TIFFGetStrileByteCount(tif, s));
  636. #else
  637. fprintf(fd, " %3lu: [%8llu, %8llu]\n",
  638. (unsigned long) s,
  639. (unsigned long long) TIFFGetStrileOffset(tif, s),
  640. (unsigned long long) TIFFGetStrileByteCount(tif, s));
  641. #endif
  642. }
  643. }
  644. void
  645. _TIFFprintAscii(FILE* fd, const char* cp)
  646. {
  647. _TIFFprintAsciiBounded( fd, cp, strlen(cp));
  648. }
  649. static void
  650. _TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars)
  651. {
  652. for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) {
  653. const char* tp;
  654. if (isprint((int)*cp)) {
  655. fputc(*cp, fd);
  656. continue;
  657. }
  658. for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
  659. if (*tp++ == *cp)
  660. break;
  661. if (*tp)
  662. fprintf(fd, "\\%c", *tp);
  663. else
  664. fprintf(fd, "\\%03o", *cp & 0xff);
  665. }
  666. }
  667. void
  668. _TIFFprintAsciiTag(FILE* fd, const char* name, const char* value)
  669. {
  670. fprintf(fd, " %s: \"", name);
  671. _TIFFprintAscii(fd, value);
  672. fprintf(fd, "\"\n");
  673. }
  674. /* vim: set ts=8 sts=8 sw=8 noet: */
  675. /*
  676. * Local Variables:
  677. * mode: c
  678. * c-basic-offset: 8
  679. * fill-column: 78
  680. * End:
  681. */