home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / ImageMagick-4.0.6.tar.gz / ImageMagick-4.0.6.tar / ImageMagick-4.0.6 / identify.c < prev    next >
C/C++ Source or Header  |  1998-04-22  |  10KB  |  265 lines

  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %                                                                             %
  4. %                                                                             %
  5. %                                                                             %
  6. %           IIIII  DDDD   EEEEE  N   N  TTTTT  IIIII  FFFFF  Y   Y            %
  7. %             I    D   D  E      NN  N    T      I    F       Y Y             %
  8. %             I    D   D  EEE    N N N    T      I    FFF      Y              %
  9. %             I    D   D  E      N  NN    T      I    F        Y              %
  10. %           IIIII  DDDD   EEEEE  N   N    T    IIIII  F        Y              %
  11. %                                                                             %
  12. %                                                                             %
  13. %               Identify an Image Format and Characteristics.                 %
  14. %                                                                             %
  15. %                                                                             %
  16. %                                                                             %
  17. %                           Software Design                                   %
  18. %                             John Cristy                                     %
  19. %                            September 1994                                   %
  20. %                                                                             %
  21. %                                                                             %
  22. %  Copyright 1998 E. I. du Pont de Nemours and Company                        %
  23. %                                                                             %
  24. %  Permission is hereby granted, free of charge, to any person obtaining a    %
  25. %  copy of this software and associated documentation files ("ImageMagick"),  %
  26. %  to deal in ImageMagick without restriction, including without limitation   %
  27. %  the rights to use, copy, modify, merge, publish, distribute, sublicense,   %
  28. %  and/or sell copies of ImageMagick, and to permit persons to whom the       %
  29. %  ImageMagick is furnished to do so, subject to the following conditions:    %
  30. %                                                                             %
  31. %  The above copyright notice and this permission notice shall be included in %
  32. %  all copies or substantial portions of ImageMagick.                         %
  33. %                                                                             %
  34. %  The software is provided "as is", without warranty of any kind, express or %
  35. %  implied, including but not limited to the warranties of merchantability,   %
  36. %  fitness for a particular purpose and noninfringement.  In no event shall   %
  37. %  E. I. du Pont de Nemours and Company be liable for any claim, damages or   %
  38. %  other liability, whether in an action of contract, tort or otherwise,      %
  39. %  arising from, out of or in connection with ImageMagick or the use or other %
  40. %  dealings in ImageMagick.                                                   %
  41. %                                                                             %
  42. %  Except as contained in this notice, the name of the E. I. du Pont de       %
  43. %  Nemours and Company shall not be used in advertising or otherwise to       %
  44. %  promote the sale, use or other dealings in ImageMagick without prior       %
  45. %  written authorization from the E. I. du Pont de Nemours and Company.       %
  46. %                                                                             %
  47. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  48. %
  49. %  Identify describes the format and characteristics of one or more image
  50. %  files.  It will also report if an image is incomplete or corrupt.
  51. %
  52. %  The identify program syntax is:
  53. %
  54. %  Usage: identify [options ...] file [ files... ]
  55. %
  56. %  Where options include:
  57. %    -ping           efficiently determine image characteristics
  58. %    -size geometry  width and height of image
  59. %    -verbose        print detailed information about the image
  60. %
  61. %
  62. */
  63.  
  64. /*
  65.   Include declarations.
  66. */
  67. #include "magick.h"
  68. #include "version.h"
  69.  
  70. /*
  71. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  72. %                                                                             %
  73. %                                                                             %
  74. %                                                                             %
  75. %   U s a g e                                                                 %
  76. %                                                                             %
  77. %                                                                             %
  78. %                                                                             %
  79. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. %
  81. %  Procedure Usage displays the program usage;
  82. %
  83. %  The format of the Usage routine is:
  84. %
  85. %      Usage(client_name)
  86. %
  87. %    o client_name: a character string representing the name of the client
  88. %      program.
  89. %
  90. %
  91. */
  92. static void Usage(const char *client_name)
  93. {
  94.   char
  95.     **p;
  96.  
  97.   static char
  98.     *options[]=
  99.     {
  100.       "-ping           efficiently determine image characteristics",
  101.       "-size geometry  width and height of image",
  102.       "-verbose        print detailed information about the image",
  103.       (char *) NULL
  104.     };
  105.  
  106.   (void) printf("Version: %s\n",Version);
  107.   (void) printf("Copyright: %s\n\n",Copyright);
  108.   (void) printf("Usage: %s [ options ... ] file [ file ... ]\n",client_name);
  109.   (void) printf("\nWhere options include:\n");
  110.   for (p=options; *p != (char *) NULL; p++)
  111.     (void) printf("  %s\n",*p);
  112.   Exit(0);
  113. }
  114.  
  115. /*
  116. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  117. %                                                                             %
  118. %                                                                             %
  119. %                                                                             %
  120. %    M a i n                                                                  %
  121. %                                                                             %
  122. %                                                                             %
  123. %                                                                             %
  124. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  125. %
  126. %
  127. */
  128. int main(int argc,char **argv)
  129. {
  130.   char
  131.     *client_name,
  132.     *option;
  133.  
  134.   Image
  135.     *image,
  136.     *p;
  137.  
  138.   ImageInfo
  139.     image_info;
  140.  
  141.   int
  142.     number_images;
  143.  
  144.   register int
  145.     i;
  146.  
  147.   unsigned int
  148.     count;
  149.  
  150.   /*
  151.     Initialize program variables.
  152.   */
  153.   ReadCommandlLine(argc,&argv);
  154.   client_name=SetClientName(*argv);
  155.   if (argc < 2)
  156.     Usage(client_name);
  157.   count=0;
  158.   number_images=0;
  159.   /*
  160.     Identify an image.
  161.   */
  162.   GetImageInfo(&image_info);
  163.   ExpandFilenames(&argc,&argv);
  164.   for (i=1; i < argc; i++)
  165.   {
  166.     option=argv[i];
  167.     if ((Extent(option) >= 2) && ((*option == '-') || (*option == '+')))
  168.       {
  169.         switch(*(option+1))
  170.         {
  171.           case 'h':
  172.           {
  173.             if (strncmp("help",option+1,2) == 0)
  174.               {
  175.                 Usage(client_name);
  176.                 break;
  177.               }
  178.             MagickError(OptionError,"Unrecognized option",option);
  179.             break;
  180.           }
  181.           case 'p':
  182.           {
  183.             if (strncmp("ping",option+1,2) == 0)
  184.               {
  185.                 image_info.ping=(*option == '-');
  186.                 break;
  187.               }
  188.             MagickError(OptionError,"Unrecognized option",option);
  189.             break;
  190.           }
  191.           case 's':
  192.           {
  193.             if (strncmp("size",option+1,2) == 0)
  194.               {
  195.                 image_info.size=(char *) NULL;
  196.                 if (*option == '-')
  197.                   {
  198.                     i++;
  199.                     if ((i == argc) || !IsGeometry(argv[i]))
  200.                       MagickError(OptionError,"Missing geometry",option);
  201.                     image_info.size=argv[i];
  202.                   }
  203.                 break;
  204.               }
  205.             MagickError(OptionError,"Unrecognized option",option);
  206.             break;
  207.           }
  208.           case 'v':
  209.           {
  210.             if (strncmp("verbose",option+1,2) == 0)
  211.               {
  212.                 image_info.verbose=(*option == '-');
  213.                 break;
  214.               }
  215.             MagickError(OptionError,"Unrecognized option",option);
  216.             break;
  217.           }
  218.           case '?':
  219.           {
  220.             Usage(client_name);
  221.             break;
  222.           }
  223.           default:
  224.           {
  225.             MagickError(OptionError,"Unrecognized option",option);
  226.             break;
  227.           }
  228.         }
  229.         continue;
  230.       }
  231.     /*
  232.       Identify image.
  233.     */
  234.     (void) strcpy(image_info.filename,argv[i]);
  235.     if (image_info.ping)
  236.       {
  237.         unsigned int
  238.           columns,
  239.           rows;
  240.  
  241.         image_info.verbose=True;
  242.         (void) PingImage(&image_info,&columns,&rows);
  243.          number_images++;
  244.         continue;
  245.       }
  246.     image=ReadImage(&image_info);
  247.     if (image == (Image *) NULL)
  248.       continue;
  249.     for (p=image; p != (Image *) NULL; p=p->next)
  250.     {
  251.       if (p->scene == 0)
  252.         p->scene=count++;
  253.       if (image_info.verbose)
  254.         NumberColors(p,(FILE *) NULL);
  255.       DescribeImage(p,stdout,image_info.verbose);
  256.     }
  257.     DestroyImages(image);
  258.     number_images++;
  259.   }
  260.   if (number_images == 0)
  261.     MagickError(OptionError,"Missing an image file name",(char *) NULL);
  262.   Exit(0);
  263.   return(False);
  264. }
  265.