home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C6TIFF.ZIP / PRINT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-30  |  10.8 KB  |  317 lines

  1. /*
  2.  * Copyright (c) 1988 by Sam Leffler.
  3.  * All rights reserved.
  4.  *
  5.  * This file is provided for unrestricted use provided that this
  6.  * legend is included on all tape media and as a part of the
  7.  * software program in whole or part.  Users may copy, modify or
  8.  * distribute this file at will.
  9.  */
  10.  
  11. /*
  12. Directory Printing Support
  13. */
  14.  
  15. #include <stdio.h>
  16. #include "tiffio.h"
  17.  
  18. static char *ResponseUnitNames[] = {
  19.         "#0",
  20.         "10ths",
  21.         "100ths",
  22.         "1,000ths",
  23.         "10,000ths",
  24.         "100,000ths",
  25. };
  26. static  float ResponseUnit[] = { 1., .1, .01, .001, .0001, .00001 };
  27. #define MAXRESPONSEUNIT \
  28.     (sizeof (ResponseUnitNames) / sizeof (ResponseUnitNames[0]))
  29.  
  30. /*
  31. Print the contents of the current directory
  32. to the specified stdio file stream.
  33. */
  34. void TIFFPrintDirectory(TIFF *tif, FILE *fd, unsigned showstrips,
  35.                         unsigned showresponsecurve, unsigned showcolormap)
  36. {
  37.    register TIFFDirectory *td;
  38.    unsigned i,n;
  39.    float unit;
  40.  
  41.    fprintf(fd, "TIFF Directory at offset 0x%X\n", tif->tif_diroff);
  42.    td = &tif->tif_dir;
  43.    if (TIFFFieldSet(tif, FIELD_SUBFILETYPE))
  44.    {
  45.       fprintf(fd, "  Subfile Type: ");
  46.       if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE)
  47.          fprintf(fd, "reduced-resolution image");
  48.       if (td->td_subfiletype & FILETYPE_PAGE)
  49.          fprintf(fd, "multi-page document");
  50.       if (td->td_subfiletype & FILETYPE_MASK)
  51.          fprintf(fd, "transparency mask");
  52.       fprintf(fd, " %ld\n",td->td_subfiletype);
  53.    }
  54.    if (TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS))
  55.       fprintf(fd, "  Image Width: %ld Image Length: %ld\n",
  56.               td->td_imagewidth, td->td_imagelength);
  57.    if (TIFFFieldSet(tif, FIELD_RESOLUTION))
  58.       fprintf(fd, "  Resolution: %g, %g\n",
  59.               td->td_xresolution, td->td_yresolution);
  60.    if (TIFFFieldSet(tif, FIELD_POSITION))
  61.       fprintf(fd, "  Position: %g, %g\n",
  62.               td->td_xposition, td->td_yposition);
  63.    if (TIFFFieldSet(tif, FIELD_BITSPERSAMPLE))
  64.       fprintf(fd, "  Bits/Sample: %d\n", td->td_bitspersample);
  65.    if (TIFFFieldSet(tif, FIELD_COMPRESSION))
  66.    {
  67.       fprintf(fd, "  Compression Scheme: ");
  68.       switch (td->td_compression)
  69.       {
  70.          case COMPRESSION_NONE:
  71.             fprintf(fd, "none\n");
  72.             break;
  73.          case COMPRESSION_CCITTRLE:
  74.             fprintf(fd, "CCITT modified Huffman encoding\n");
  75.             break;
  76.          case COMPRESSION_CCITTFAX3:
  77.             fprintf(fd, "CCITT Group 3 facsimile encoding\n");
  78.             break;
  79.          case COMPRESSION_CCITTFAX4:
  80.             fprintf(fd, "CCITT Group 4 facsimile encoding\n");
  81.             break;
  82.          case COMPRESSION_CCITTRLEW:
  83.             fprintf(fd, "CCITT modified Huffman encoding %s\n",
  84.                         "w/ word alignment");
  85.             break;
  86.          case COMPRESSION_PACKBITS:
  87.             fprintf(fd, "Macintosh PackBits encoding\n");
  88.             break;
  89.          case COMPRESSION_LZW:
  90.             fprintf(fd, "Lempel-Ziv & Welch encoding\n");
  91.             break;
  92.          default:
  93.         fprintf(fd, "%d\n",td->td_compression);
  94.             break;
  95.       }
  96.    }
  97.    if (TIFFFieldSet(tif, FIELD_PHOTOMETRIC))
  98.    {
  99.       fprintf(fd, "  Photometric Interpretation: ");
  100.       switch (td->td_photometric)
  101.       {
  102.          case PHOTOMETRIC_MINISWHITE:
  103.             fprintf(fd, "\"min-is-white\"\n");
  104.             break;
  105.          case PHOTOMETRIC_MINISBLACK:
  106.             fprintf(fd, "\"min-is-black\"\n");
  107.             break;
  108.          case PHOTOMETRIC_RGB:
  109.             fprintf(fd, "RGB color\n");
  110.             break;
  111.          case PHOTOMETRIC_PALETTE:
  112.             fprintf(fd, "palette color (RGB from colormap)\n");
  113.             break;
  114.          case PHOTOMETRIC_MASK:
  115.             fprintf(fd, "transparency mask\n");
  116.             break;
  117.          default:
  118.         fprintf(fd, "%d (0x%X)\n",td->td_photometric, td->td_photometric);
  119.             break;
  120.       }
  121.    }
  122.    if (TIFFFieldSet(tif, FIELD_THRESHHOLDING))
  123.    {
  124.       fprintf(fd, "  Thresholding: ");
  125.       switch (td->td_threshholding)
  126.       {
  127.          case THRESHHOLD_BILEVEL:
  128.             fprintf(fd, "bilevel art scan\n");
  129.             break;
  130.          case THRESHHOLD_HALFTONE:
  131.             fprintf(fd, "halftone or dithered scan\n");
  132.             break;
  133.          case THRESHHOLD_ERRORDIFFUSE:
  134.             fprintf(fd, "error diffused\n");
  135.             break;
  136.          default:
  137.         fprintf(fd, "%d\n",td->td_threshholding);
  138.             break;
  139.       }
  140.    }
  141.    if (TIFFFieldSet(tif, FIELD_PREDICTOR))
  142.       fprintf(fd, "  Predictor: %d\n", td->td_predictor);
  143.    if (TIFFFieldSet(tif, FIELD_ARTIST))
  144.       fprintf(fd, "  Artist: %s\n", td->td_artist);
  145.    if (TIFFFieldSet(tif, FIELD_DATETIME))
  146.       fprintf(fd, "  Date & Time: %s\n", td->td_datetime);
  147.    if (TIFFFieldSet(tif, FIELD_HOSTCOMPUTER))
  148.       fprintf(fd, "  Host Computer: %s\n", td->td_hostcomputer);
  149.    if (TIFFFieldSet(tif, FIELD_SOFTWARE))
  150.       fprintf(fd, "  Software: %s\n", td->td_software);
  151.    if (TIFFFieldSet(tif, FIELD_DOCUMENTNAME))
  152.       fprintf(fd, "  Document Name: %s\n", td->td_documentname);
  153.    if (TIFFFieldSet(tif, FIELD_IMAGEDESCRIPTION))
  154.       fprintf(fd, "  Image Description: %s\n",td->td_imagedescription);
  155.    if (TIFFFieldSet(tif, FIELD_MAKE))
  156.       fprintf(fd, "  Make: %s\n", td->td_make);
  157.    if (TIFFFieldSet(tif, FIELD_MODEL))
  158.       fprintf(fd, "  Model: %s\n", td->td_model);
  159.    if (TIFFFieldSet(tif, FIELD_ORIENTATION))
  160.    {
  161.       fprintf(fd, "  Orientation: ");
  162.       switch (td->td_orientation)
  163.       {
  164.          case ORIENTATION_TOPLEFT:
  165.             fprintf(fd, "row 0 top, col 0 lhs\n");
  166.             break;
  167.          case ORIENTATION_TOPRIGHT:
  168.             fprintf(fd, "row 0 top, col 0 rhs\n");
  169.             break;
  170.          case ORIENTATION_BOTRIGHT:
  171.             fprintf(fd, "row 0 bottom, col 0 rhs\n");
  172.             break;
  173.          case ORIENTATION_BOTLEFT:
  174.             fprintf(fd, "row 0 bottom, col 0 lhs\n");
  175.             break;
  176.          case ORIENTATION_LEFTTOP:
  177.             fprintf(fd, "row 0 lhs, col 0 top\n");
  178.             break;
  179.          case ORIENTATION_RIGHTTOP:
  180.             fprintf(fd, "row 0 rhs, col 0 top\n");
  181.             break;
  182.          case ORIENTATION_RIGHTBOT:
  183.             fprintf(fd, "row 0 rhs, col 0 bottom\n");
  184.             break;
  185.          case ORIENTATION_LEFTBOT:
  186.             fprintf(fd, "row 0 lhs, col 0 bottom\n");
  187.             break;
  188.          default:
  189.         fprintf(fd, "%d\n",td->td_orientation);
  190.             break;
  191.       }
  192.    }
  193.    if (TIFFFieldSet(tif, FIELD_SAMPLESPERPIXEL))
  194.       fprintf(fd, "  Samples/Pixel: %d\n", td->td_samplesperpixel);
  195.    if (TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
  196.       fprintf(fd, "  Rows/Strip: %ld\n", td->td_rowsperstrip);
  197.    if (TIFFFieldSet(tif, FIELD_MINSAMPLEVALUE))
  198.       fprintf(fd, "  Min Sample Value: %d\n", td->td_minsamplevalue);
  199.    if (TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))
  200.       fprintf(fd, "  Max Sample Value: %d\n", td->td_maxsamplevalue);
  201.    if (TIFFFieldSet(tif, FIELD_PLANARCONFIG))
  202.    {
  203.       fprintf(fd, "  Planar Configuration: ");
  204.       switch (td->td_planarconfig)
  205.       {
  206.          case PLANARCONFIG_CONTIG:
  207.             fprintf(fd, "single image plane\n");
  208.             break;
  209.          case PLANARCONFIG_SEPARATE:
  210.             fprintf(fd, "separate image planes\n");
  211.             break;
  212.          default:
  213.         fprintf(fd, "%d\n",td->td_planarconfig);
  214.             break;
  215.       }
  216.    }
  217.    if (TIFFFieldSet(tif, FIELD_PAGENAME))
  218.       fprintf(fd, "  Page Name: %s\n", td->td_pagename);
  219.    if (TIFFFieldSet(tif, FIELD_GRAYRESPONSEUNIT))
  220.    {
  221.       fprintf(fd, "  Gray Response Unit: ");
  222.       if (td->td_grayresponseunit < MAXRESPONSEUNIT)
  223.          fprintf(fd, "%s\n",ResponseUnitNames[td->td_grayresponseunit]);
  224.       else
  225.      fprintf(fd, "%d\n",td->td_grayresponseunit);
  226.    }
  227.    if (TIFFFieldSet(tif, FIELD_GRAYRESPONSECURVE))
  228.    {
  229.       fprintf(fd, "  Gray Response Curve: ");
  230.       if (showresponsecurve)
  231.       {
  232.          fprintf(fd, "\n");
  233.          unit = ResponseUnit[td->td_grayresponseunit];
  234.      n = 1 << (td->td_bitspersample * td->td_samplesperpixel);
  235.          for (i = 0; i < n; i++)
  236.             fprintf(fd, "    %2d: %g (%d)\n",i,
  237.                     td->td_grayresponsecurve[i] * unit,
  238.                     td->td_grayresponsecurve[i]);
  239.       }
  240.       else
  241.          fprintf(fd, "(present)\n");
  242.    }
  243.    if (TIFFFieldSet(tif, FIELD_GROUP3OPTIONS))
  244.       fprintf(fd, "  Group 3 Options: 0x%X\n", td->td_group3options);
  245.    if (TIFFFieldSet(tif, FIELD_GROUP4OPTIONS))
  246.       fprintf(fd, "  Group 4 Options: 0x%X\n", td->td_group4options);
  247.    if (TIFFFieldSet(tif, FIELD_RESOLUTIONUNIT))
  248.    {
  249.       fprintf(fd, "  Resolution Unit: ");
  250.       switch (td->td_resolutionunit)
  251.       {
  252.          case RESUNIT_NONE:
  253.             fprintf(fd, "no meaningful units\n");
  254.             break;
  255.          case RESUNIT_INCH:
  256.             fprintf(fd, "inches\n");
  257.             break;
  258.          case RESUNIT_CENTIMETER:
  259.             fprintf(fd, "centimeters\n");
  260.             break;
  261.          default:
  262.         fprintf(fd, "%d\n",td->td_resolutionunit);
  263.             break;
  264.       }
  265.    }
  266.    if (TIFFFieldSet(tif, FIELD_PAGENUMBER))
  267.       fprintf(fd, "  Page Number: %d\n", td->td_pagenumber);
  268.    if (TIFFFieldSet(tif, FIELD_COLORRESPONSEUNIT))
  269.    {
  270.       fprintf(fd, "  Color Response Unit: ");
  271.       if (td->td_colorresponseunit < MAXRESPONSEUNIT)
  272.          fprintf(fd, "%s\n",ResponseUnitNames[td->td_colorresponseunit]);
  273.       else
  274.      fprintf(fd, "%d\n",td->td_colorresponseunit);
  275.    }
  276.    if (TIFFFieldSet(tif, FIELD_COLORMAP))
  277.    {
  278.       fprintf(fd, "  Color Map: ");
  279.       if (showcolormap)
  280.       {
  281.          fprintf(fd, "\n");
  282.      n = 1 << (td->td_bitspersample * td->td_samplesperpixel);
  283.          for (i = 0; i < n; i++)
  284.         fprintf(fd, "    %3d: %5u %5u %5u\n",i,
  285.                     td->td_redcolormap[i],
  286.                     td->td_greencolormap[i],
  287.                     td->td_bluecolormap[i]);
  288.       }
  289.       else
  290.          fprintf(fd, "(present)\n");
  291.    }
  292.    if (TIFFFieldSet(tif, FIELD_COLORRESPONSECURVE))
  293.    {
  294.       fprintf(fd, "  Color Response Curve: ");
  295.       if (showresponsecurve)
  296.       {
  297.          fprintf(fd, "\n");
  298.          unit = ResponseUnit[td->td_colorresponseunit];
  299.      n = 1 << (td->td_bitspersample * td->td_samplesperpixel);
  300.          for (i = 0; i < n; i++)
  301.             fprintf(fd, "    %2d: %6.4f %6.4f %6.4f\n",i,
  302.                     td->td_redresponsecurve[i] * unit,
  303.                     td->td_greenresponsecurve[i] * unit,
  304.                     td->td_blueresponsecurve[i] * unit);
  305.       }
  306.       else
  307.          fprintf(fd, "(present)\n");
  308.    }
  309.    if (showstrips && TIFFFieldSet(tif, FIELD_STRIPOFFSETS))
  310.    {
  311.       fprintf(fd, "  %d Strips:\n", td->td_nstrips);
  312.       for (i = 0; i < td->td_nstrips; i++)
  313.          fprintf(fd, "    %3d: [%8lu, %8lu]\n",i,
  314.                  td->td_stripoffset[i], td->td_stripbytecount[i]);
  315.    }
  316. }
  317.