/src/FreeImage/Source/LibTIFF/tif_print.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 642 lines · 548 code · 29 blank · 65 comment · 164 complexity · 36513a040e97d7c0211f80c728187f00 MD5 · raw file

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