2
0

tif_print.c 21 KB

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