home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / grfx_snd / tifflib / source / tiffinfo.c < prev    next >
C/C++ Source or Header  |  1993-02-28  |  4KB  |  185 lines

  1. #pragma warn -use
  2. static char     *sccsid = "@(#)TIFF/tiffinfo.c 1.30, Copyright (c) Sam Leffler, Dieter Linde, "__DATE__;
  3. #pragma warn .use
  4. /*
  5.  * Copyright (c) 1988 by Sam Leffler, Apr 25 1989
  6.  * All rights reserved.
  7.  *
  8.  * This file is provided for unrestricted use provided that this legend is included on all tape media and as a part of the
  9.  * software program in whole or part.  Users may copy, modify or distribute this file at will.
  10.  */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <lin.h>
  14. #include "tiffio.h"
  15.  
  16. static char    *progname;
  17. static int    showcolormap = 0;        /* show colormap entries if present */
  18. static int    showresponsecurves = 0;        /* show response curve[s] if present */
  19. static int    showstrips = 0;            /* show strip offsets and sizes */
  20. static int    showdata = 0;            /* show data */
  21. static int    readdata = 0;            /* read data in file */
  22.  
  23. /****************************************************************************
  24.  *
  25.  */
  26. static void
  27. usage(
  28.     int     code
  29.     )
  30. {
  31.     fprintf(stderr, "usage: %s [-Ddcs] [-<n>] <tifffiles>\n", progname);
  32.     fputs("\t-D   read data\n", stderr);
  33.     fputs("\t-d   show data\n", stderr);
  34.     fputs("\t-c   show color/gray response curves and colormap\n", stderr);
  35.     fputs("\t-s   show data strip offsets and byte counts\n", stderr);
  36.     fputs("\t-<n> show directory number <n>\n", stderr);
  37.     exit(code);
  38. }
  39.  
  40. /****************************************************************************
  41.  *
  42.  */
  43. static void
  44. Show(
  45.     int        row,
  46.          int        sample,
  47.          u_char    *pp,
  48.          int        scanline
  49.          )
  50. {
  51.     register int    cc;
  52.  
  53.     printf("[%3d", row);
  54.     if (sample > 0)
  55.         printf(",%d", sample);
  56.     printf("]");
  57.     for (cc = 0; cc < scanline; cc++) {
  58.         printf(" %02x", *pp++);
  59.         if (((cc + 1) % 24) == 0)
  60.             putchar('\n');
  61.     }
  62.     putchar('\n');
  63. }
  64.  
  65. /****************************************************************************
  66.  *
  67.  */
  68. static void
  69. TIFFInfo(
  70.     TIFF     *tif
  71.     )
  72. {
  73.     u_char     *scanbuf;
  74.     u_short    config, h;
  75.     int     s, row, scanline;
  76.  
  77.     TIFFPrintDirectory(tif, stdout, showstrips, showcolormap, showresponsecurves);
  78.     if (!readdata)
  79.         return;
  80.     TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &config);
  81.     if ((scanbuf = (u_char *)malloc(scanline = TIFFScanlineSize(tif))) == NULL) {
  82.         fprintf(stderr, "%s: out of memory allocating scanline buffer\n", progname);
  83.         return;
  84.     }
  85.     TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
  86.     if (config == PLANARCONFIG_CONTIG) {
  87.         for (row = 0; row < h; row++) {
  88.             if (TIFFReadScanline(tif, scanbuf, row, 0) < 0)
  89.                 break;
  90.             if (showdata)
  91.                 Show(row, -1, scanbuf, scanline);
  92.         }
  93.     }
  94.     else {
  95.         u_short    samplesperpixel;
  96.  
  97.         TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
  98.         for (s = 0; s < samplesperpixel; s++)
  99.             for (row = 0; row < h; row++) {
  100.                 if (TIFFReadScanline(tif, scanbuf, row, s) < 0)
  101.                     goto done;
  102.                 if (showdata)
  103.                     Show(row, s, scanbuf, scanline);
  104.             }
  105. done:
  106.         ;
  107.     }
  108.     free(scanbuf);
  109. }
  110.  
  111. /****************************************************************************
  112.  *
  113.  */
  114. void
  115. main(
  116.     int      argc,
  117.          char     *argv[]
  118.          )
  119. {
  120.     int     dirnum = -1;
  121.     int    multiplefiles;
  122.     char     *cp;
  123.     TIFF     *tif;
  124.  
  125.         progname = ((int)strlen(argv[0]) == 0) ? "tiffinfo" : argv[0];
  126.  
  127.     argc--;
  128.     argv++;
  129.     while (argc > 0 && argv[0][0] == '-') {
  130.         for (cp = &argv[0][1]; *cp; cp++)
  131.             switch (*cp) {
  132.                 case '0':
  133.                 case '1':
  134.                 case '2':
  135.                 case '3':
  136.                 case '4':
  137.                 case '5':
  138.                 case '6':
  139.                 case '7':
  140.                 case '8':
  141.                 case '9':
  142.                     dirnum = atoi(cp);
  143.                     goto next;
  144.                 case 'd':
  145.                     showdata++;
  146.                 case 'D':
  147.                     readdata++;
  148.                     break;
  149.                 case 'c':
  150.                     showcolormap++;
  151.                     showresponsecurves++;
  152.                     break;
  153.                 case 's':
  154.                     showstrips++;
  155.                     break;
  156.                 default:
  157.                     usage(-1);
  158.                 /* NOTREACHED */
  159.             }
  160. next:
  161.         argc--;
  162.         argv++;
  163.     }
  164.     if (argc <= 0)
  165.         usage(-2);
  166.     for (multiplefiles = argc > 1; argc > 0; argc--, argv++) {
  167.         if (multiplefiles)
  168.             printf("%s:\n", argv[0]);
  169.         tif = TIFFOpen(argv[0], "r");
  170.         if (tif != NULL) {
  171.             if (dirnum == -1) {
  172.                 do
  173.                     TIFFInfo(tif);
  174.                 while (TIFFReadDirectory(tif));
  175.             }
  176.             else {
  177.                 if (TIFFSetDirectory(tif, dirnum))
  178.                     TIFFInfo(tif);
  179.             }
  180.             TIFFClose(tif);
  181.         }
  182.     }
  183.     exit(0);
  184. }
  185.