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 / convert.c < prev    next >
Text File  |  1998-05-12  |  56KB  |  1,456 lines

  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %                                                                             %
  4. %                                                                             %
  5. %                                                                             %
  6. %                CCCC   OOO   N   N  V   V  EEEEE  RRRR   TTTTT               %
  7. %               C      O   O  NN  N  V   V  E      R   R    T                 %
  8. %               C      O   O  N N N  V   V  EEE    RRRR     T                 %
  9. %               C      O   O  N  NN   V V   E      R R      T                 %
  10. %                CCCC   OOO   N   N    V    EEEEE  R  R     T                 %
  11. %                                                                             %
  12. %                                                                             %
  13. %                Convert an image from one format to another.                 %
  14. %                                                                             %
  15. %                                                                             %
  16. %                                                                             %
  17. %                              Software Design                                %
  18. %                                John Cristy                                  %
  19. %                                April 1992                                   %
  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. %  Convert converts an input file using one image format to an output file
  50. %  with a differing image format.
  51. %
  52. %  The convert program syntax is:
  53. %
  54. %  Usage: convert [options ...] file [ files... ] output_file
  55. %
  56. %  Where options include:
  57. %    -adjoin              join images into a single multi-image file
  58. %    -align type          Left, Center, Right
  59. %    -average             average a set of images
  60. %    -blur factor         apply a filter to blur the image
  61. %    -border geometry     surround image with a border of color
  62. %    -box color           color for annotation bounding box
  63. %    -charcoal factor     simulate a charcoal drawing
  64. %    -colorize value      colorize the image with the pen color
  65. %    -colors value        preferred number of colors in the image
  66. %    -colorspace type     alternate image colorspace
  67. %    -comment string      annotate image with comment
  68. %    -compress type       None, JPEG, LZW, RunlengthEncoded, or Zip
  69. %    -contrast            enhance or reduce the image contrast
  70. %    -crop geometry       preferred size and location of the cropped image
  71. %    -cycle amount        cycle the image colormap
  72. %    -delay value         display the next image after pausing
  73. %    -density geometry    vertical and horizontal density of the image
  74. %    -despeckle           reduce the speckles within an image"
  75. %    -display server      obtain image or font from this X server
  76. %    -dispose method      GIF disposal method
  77. %    -dither              apply Floyd/Steinberg error diffusion to image
  78. %    -draw string         annotate the image with a graphic primitive
  79. %    -edge factor         apply a filter to detect edges in the image
  80. %    -emboss              emboss an image
  81. %    -enhance             apply a digital filter to enhance a noisy image
  82. %    -equalize            perform histogram equalization to an image
  83. %    -flip                flip image in the vertical direction
  84. %    -flop                flop image in the horizontal direction
  85. %    -font name           X11 font for displaying text
  86. %    -frame geometry      surround image with an ornamental border
  87. %    -gamma value         level of gamma correction
  88. %    -geometry geometry   perferred size or location of the image
  89. %    -implode amount      implode image pixels about the center
  90. %    -interlace type      None, Line, Plane, or Partition
  91. %    -label name          assign a label to an image
  92. %    -layer type          Red, Green, Blue, Matte
  93. %    -linewidth value     width of line in pixels
  94. %    -loop iterations     add Netscape loop extension to your GIF animation
  95. %    -map filename        transform image colors to match this set of colors
  96. %    -matte               store matte channel if the image has one
  97. %    -modulate value      vary the brightness, saturation and hue
  98. %    -monochrome          transform image to black and white
  99. %    -negate              apply color inversion to image
  100. %    -noise               add or reduce noise in an image
  101. %    -normalize           transform image to span the full range of colors
  102. %    -opaque color        change this color to the pen color
  103. %    -page geometry       size and location of an image canvas
  104. %    -paint radius        simulate an oil painting
  105. %    -pen color           color for annotating or changing opaque color
  106. %    -pointsize value     pointsize of Postscript font
  107. %    -quality value       JPEG/MIFF/PNG compression level
  108. %    -raise value         lighten/darken image edges to create a 3-D effect
  109. %    -region geometry     apply options to a portion of the image
  110. %    -roll geometry       roll an image vertically or horizontally
  111. %    -rotate degrees      apply Paeth rotation to the image
  112. %    -sample geometry     scale image with pixel sampling
  113. %    -scene value         image scene number
  114. %    -seed value          pseudo-random number generator seed value
  115. %    -segment values      segment an image
  116. %    -shade degrees       shade the image using a distant light source
  117. %    -sharpen factor      apply a filter to sharpen the image
  118. %    -shear geometry      slide one edge of the image along the X or Y axis
  119. %    -size geometry       width and height of image
  120. %    -solarize thresold   negate all pixels above the threshold level
  121. %    -spread amount       displace image pixels by a random amount
  122. %    -swirl degrees       swirl image pixels about the center
  123. %    -texture filename    name of texture to tile onto the image background
  124. %    -threshold value     threshold the image
  125. %    -transparent color   make this color transparent within the image
  126. %    -treedepth value     depth of the color classification tree
  127. %    -undercolor geometry control undercolor removal and black generation
  128. %    -verbose             print detailed information about the image
  129. %    -view                FlashPix viewing transforms
  130. %    -wave geometry       alter an image along a sine wave
  131. %
  132. %  By default, the image format of `file' is determined by its magic
  133. %  number.  To specify a particular image format, precede the filename
  134. %  with an image format name and a colon (i.e. ps:image) or specify the
  135. %  image type as the filename suffix (i.e. image.ps).  Specify 'file' as
  136. %  '-' for standard input or output.
  137. %
  138. %  Convert recognizes the following image formats:
  139. %
  140. %    Tag   Description
  141. %    ---------------------------------------------------
  142. %    AVS   AVS X image file.
  143. %    BMP   Microsoft Windows bitmap image file.
  144. %    BMP24 Microsoft Windows 24-bit bitmap image file.
  145. %    CMYK  Raw cyan, magenta, yellow, and black bytes.
  146. %    DCX   ZSoft IBM PC multi-page Paintbrush file
  147. %    DIB   Microsoft Windows bitmap image file.
  148. %    EPS   Adobe Encapsulated PostScript file.
  149. %    EPS2  Adobe Level II Encapsulated PostScript file.
  150. %    EPSF  Adobe Encapsulated PostScript file.
  151. %    EPSI  Adobe Encapsulated PostScript Interchange format.
  152. %    FAX   Group 3.
  153. %    FIG   TransFig image format.
  154. %    FITS  Flexible Image Transport System.
  155. %    FPX   FlashPix Format.
  156. %    GIF   CompuServe graphics interchange format; 8-bit color.
  157. %    GIF87 CompuServe graphics interchange format; 8-bit color (version 87a).
  158. %    GRADATION gradual passing from one shade to another.
  159. %    GRANITE granite texture
  160. %    GRAY  Raw gray bytes.
  161. %    HDF   Hierarchical Data Format.
  162. %    HISTOGRAM
  163. %    HTML  Hypertext Markup Language with a client-side image map
  164. %    JBIG  Joint Bi-level Image experts Group file interchange format.
  165. %    JPEG  Joint Photographic Experts Group JFIF format; compressed 24-bit color.
  166. %    MAP   colormap intensities and indices.
  167. %    MATTE Raw matte bytes.
  168. %    MIFF  Magick image file format.
  169. %    MONO  Bi-level bitmap in least-significant-byte (LSB) first order.
  170. %    MPEG  Motion Picture Experts Group file interchange format.
  171. %    MTV   MTV Raytracing image format
  172. %    NETSCAPE
  173. %          Netscape 216 color cube.
  174. %    NULL  NULL image.
  175. %    PBM   Portable bitmap format (black and white).
  176. %    PCD   Photo CD.
  177. %    PCX   ZSoft IBM PC Paintbrush file.
  178. %    PDF   Portable Document Format.
  179. %    PGM   Portable graymap format (gray scale).
  180. %    PICT  Apple Macintosh QuickDraw/PICT file.
  181. %    PLASMA plasma fractal image.
  182. %    PNG   Portable Network Graphics.
  183. %    PNM   Portable anymap.
  184. %    PPM   Portable pixmap format (color).
  185. %    PREVIEW
  186. %    PS    Adobe PostScript file.
  187. %    PSD   Adobe Photoshop bitmap file.
  188. %    PS2   Adobe Level II PostScript file.
  189. %    RAD   Radiance image file.
  190. %    RGB   Raw red, green, and blue bytes.
  191. %    RGBA  Raw red, green, blue, and matte bytes.
  192. %    RLA   Alias/Wavefront image file; read only
  193. %    RLE   Utah Run length encoded image file; read only.
  194. %    SGI   Irix RGB image file.
  195. %    SHTML Hypertext Markup Language with a client-side image map
  196. %    SUN   SUN Rasterfile.
  197. %    TEXT  raw text file; read only.
  198. %    TGA   Truevision Targa image file.
  199. %    TIFF  Tagged Image File Format.
  200. %    TIFF24
  201. %          24-bit Tagged Image File Format.
  202. %    UYVY  16bit/pixel interleaved YUV (e.g. used by AccomWSD)
  203. %    TILE  tile image with a texture.
  204. %    UIL   X-Motif UIL table.
  205. %    VICAR read only.
  206. %    VID   Visual Image Directory.
  207. %    VIFF  Khoros Visualization image file.
  208. %    X     select image from X server screen.
  209. %    XC    constant image of X server color.
  210. %    XBM   X Windows system bitmap, black and white only.
  211. %    XPM   X Windows system pixmap file (color).
  212. %    XWD   X Windows system window dump file (color).
  213. %    YUV   CCIR 601 4:1:1 file.
  214. %
  215. %
  216. */
  217.  
  218. /*
  219.   Include declarations.
  220. */
  221. #include "magick.h"
  222. #include "version.h"
  223.  
  224. /*
  225. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  226. %                                                                             %
  227. %                                                                             %
  228. %                                                                             %
  229. %   U s a g e                                                                 %
  230. %                                                                             %
  231. %                                                                             %
  232. %                                                                             %
  233. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  234. %
  235. %  Procedure Usage displays the program usage;
  236. %
  237. %  The format of the Usage routine is:
  238. %
  239. %      Usage(client_name)
  240. %
  241. %    o client_name: a character string representing the name of the client
  242. %      program.
  243. %
  244. %
  245. */
  246. static void Usage(const char *client_name)
  247. {
  248.   char
  249.     **p;
  250.  
  251.   static char
  252.     *ImageTypes[]=
  253.     {
  254.       "Tag   Description",
  255.       "------------------------------------------------------------",
  256.       "AVS   AVS X image file.",
  257.       "BMP   Microsoft Windows bitmap image file.",
  258.       "BMP24 Microsoft Windows 24-bit bitmap image file.",
  259.       "CMYK  Raw cyan, magenta, yellow, and black bytes.",
  260.       "DCX   ZSoft IBM PC multi-page Paintbrush file",
  261.       "DIB   Microsoft Windows bitmap image file.",
  262.       "EPS   Adobe Encapsulated PostScript file.",
  263.       "EPS2  Adobe Level II Encapsulated PostScript file.",
  264.       "EPSF  Adobe Encapsulated PostScript file.",
  265.       "EPSI  Adobe Encapsulated PostScript Interchange format.",
  266.       "FAX   Group 3.",
  267.       "FIG   TransFig image format.",
  268.       "FITS  Flexible Image Transport System.",
  269.       "FPX   FlashPix Format.",
  270.       "GIF   CompuServe graphics interchange format; 8-bit color.",
  271.       "GIF87 CompuServe graphics interchange format; 8-bit color (version 87a).",
  272.       "GRADATION gradual passing from one shade to another.",
  273.       "GRANITE granite texture.",
  274.       "GRAY  Raw gray bytes.",
  275.       "HDF   Hierarchical Data Format.",
  276.       "HISTOGRAM",
  277.       "HTML  Hypertext Markup Language with a client-side image map",
  278.       "JBIG  Joint Bi-level Image experts Group file interchange format.",
  279.       "JPEG  Joint Photographic Experts Group JFIF format; compressed 24-bit color.",
  280.       "MAP   colormap intensities and indices.",
  281.       "MATTE Raw matte bytes.",
  282.       "MIFF  Magick image file format.",
  283.       "MONO  Bi-level bitmap in least-significant-byte (LSB) first order.",
  284.       "MPEG  Motion Picture Experts Group file interchange format.",
  285.       "MTV   MTV Raytracing image format.",
  286.       "NETSCAPE  Netscape 216 color cube.",
  287.       "NULL  NULL image.",
  288.       "PBM   Portable bitmap format (black and white).",
  289.       "PCD   Photo CD.",
  290.       "PCX   ZSoft IBM PC Paintbrush file.",
  291.       "PDF   Portable Document Format.",
  292.       "PGM   Portable graymap format (gray scale).",
  293.       "PICT  Apple Macintosh QuickDraw/PICT file.",
  294.       "PLASMA plasma fractal image.",
  295.       "PNG   Portable Network Graphics.",
  296.       "PNM   Portable anymap.",
  297.       "PPM   Portable pixmap format (color).",
  298.       "PREVIEW",
  299.       "PS    Adobe PostScript file.",
  300.       "PSD   Adobe Photoshop bitmap file.",
  301.       "PS2   Adobe Level II PostScript file.",
  302.       "RAD   Radiance image file.",
  303.       "RGB   Raw red, green, and blue bytes.",
  304.       "RGBA  Raw red, green, blue, and matte bytes.",
  305.       "RLA   Alias/Wavefront image file; read only.",
  306.       "RLE   Utah Run length encoded image file; read only.",
  307.       "SGI   Irix RGB image file.",
  308.       "SUN   SUN Rasterfile.",
  309.       "TEXT  raw text file; read only.",
  310.       "TGA   Truevision Targa image file.",
  311.       "TIFF  Tagged Image File Format.",
  312.       "TIFF24",
  313.       "      24-bit Tagged Image File Format.",
  314.       "UYVY  16bit/pixel interleaved YUV.",
  315.       "TILE  tile image with a texture.",
  316.       "UIL   X-Motif UIL table.",
  317.       "VICAR read only.",
  318.       "VID   Visual Image Directory.",
  319.       "VIFF  Khoros Visualization image file.",
  320.       "X     select image from X server screen.",
  321.       "XC    constant image of X server color.",
  322.       "XBM   X Windows system bitmap, black and white only.",
  323.       "XPM   X Windows system pixmap file (color).",
  324.       "XWD   X Windows system window dump file (color).",
  325.       "YUV   CCIR 601 4:1:1 file.",
  326.       (char *) NULL,
  327.     },
  328.     *options[]=
  329.     {
  330.       "-adjoin              join images into a single multi-image file",
  331.       "-align type          Left, Center, Right",
  332.       "-average             average a set of images",
  333.       "-blur factor         apply a filter to blur the image",
  334.       "-border geometry     surround image with a border of color",
  335.       "-box color           color for annotation bounding box",
  336.       "-charcoal factor     simulate a charcoal drawing",
  337.       "-colorize value      colorize the image with the pen color",
  338.       "-colors value        preferred number of colors in the image",
  339.       "-colorspace type     alternate image colorspace",
  340.       "-comment string      annotate image with comment",
  341.       "-compress type       None, JPEG, LZW, RunlengthEncoded, or Zip",
  342.       "-contrast            enhance or reduce the image contrast",
  343.       "-crop geometry       preferred size and location of the cropped image",
  344.       "-cycle amount        cycle the image colormap",
  345.       "-delay value         display the next image after pausing",
  346.       "-density geometry    vertical and horizontal density of the image",
  347.       "-despeckle           reduce the speckles within an image",
  348.       "-display server      obtain image or font from this X server",
  349.       "-dispose method      GIF disposal method",
  350.       "-dither              apply Floyd/Steinberg error diffusion to image",
  351.       "-draw string         annotate the image with a graphic primitive",
  352.       "-edge factor         apply a filter to detect edges in the image",
  353.       "-emboss              emboss an image",
  354.       "-enhance             apply a digital filter to enhance a noisy image",
  355.       "-equalize            perform histogram equalization to an image",
  356.       "-flip                flip image in the vertical direction",
  357.       "-flop                flop image in the horizontal direction",
  358.       "-font name           X11 font for displaying text",
  359.       "-frame geometry      surround image with an ornamental border",
  360.       "-gamma value         level of gamma correction",
  361.       "-geometry geometry   perferred size or location of the image",
  362.       "-implode amount      implode image pixels about the center",
  363.       "-interlace type      None, Line, Plane, or Partition",
  364.       "-label name          assign a label to an image",
  365.       "-layer type          Red, Green, Blue, Matte",
  366.       "-linewidth value     width of line in pixels",
  367.       "-label name          assign a label to an image",
  368.       "-loop iterations     add Netscape loop extension to your GIF animation",
  369.       "-map filename        transform image colors to match this set of colors",
  370.       "-matte               store matte channel if the image has one",
  371.       "-modulate value      vary the brightness, saturation, and hue",
  372.       "-monochrome          transform image to black and white",
  373.       "-negate              apply color inversion to image",
  374.       "-noise               add or reduce noise in an image",
  375.       "-normalize           transform image to span the full range of colors",
  376.       "-opaque color        change this color to the pen color",
  377.       "-page geometry       size and location of an image canvas",
  378.       "-paint radius        simulate an oil painting",
  379.       "-pen color           color for annotating or changing opaque color",
  380.       "-pointsize value     pointsize of Postscript font",
  381.       "-quality value       JPEG/MIFF/PNG compression level",
  382.       "-raise value         lighten/darken image edges to create a 3-D effect",
  383.       "-region geometry     apply options to a portion of the image",
  384.       "-roll geometry       roll an image vertically or horizontally",
  385.       "-rotate degrees      apply Paeth rotation to the image",
  386.       "-sample geometry     scale image with pixel sampling",
  387.       "-scene value         image scene number",
  388.       "-segment values      segment an image",
  389.       "-seed value          pseudo-random number generator seed value",
  390.       "-shade degrees       shade the image using a distant light source",
  391.       "-sharpen factor      apply a filter to sharpen the image",
  392.       "-shear geometry      slide one edge of the image along the X or Y axis",
  393.       "-size geometry       width and height of image",
  394.       "-solarize thresold   negate all pixels above the threshold level",
  395.       "-spread amount       displace image pixels by a random amount",
  396.       "-swirl degrees       swirl image pixels about the center",
  397.       "-texture filename    name of texture to tile onto the image background",
  398.       "-threshold value     threshold the image",
  399.       "-transparent color   make this color transparent within the image",
  400.       "-treedepth value     depth of the color classification tree",
  401.       "-undercolor geometry control undercolor removal and black generation",
  402.       "-verbose             print detailed information about the image",
  403.       "-view                FlashPix viewing transforms",
  404.       "-wave geometry       alter an image along a sine wave",
  405.       (char *) NULL
  406.     };
  407.  
  408.   (void) printf("Version: %s\n",Version);
  409.   (void) printf("Copyright: %s\n\n",Copyright);
  410.   (void) printf("Usage: %s [options ...] file [ files... ] output_file\n",
  411.     client_name);
  412.   (void) printf("\nWhere options include:\n");
  413.   for (p=options; *p != (char *) NULL; p++)
  414.     (void) printf("  %s\n",*p);
  415.   (void) printf(
  416.     "\nBy default, the image format of `file' is determined by its magic\n");
  417.   (void) printf(
  418.     "number.  To specify a particular image format, precede the filename\n");
  419.   (void) printf(
  420.     "with an image format name and a colon (i.e. ps:image) or specify the\n");
  421.   (void) printf(
  422.     "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
  423.   (void) printf("'-' for standard input or output.\n");
  424.   (void) printf("\nThe following image formats are recognized: \n\n");
  425.   for (p=ImageTypes; *p != (char *) NULL; p++)
  426.     (void) printf("  %s\n",*p);
  427.   Exit(0);
  428. }
  429.  
  430. /*
  431. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  432. %                                                                             %
  433. %                                                                             %
  434. %                                                                             %
  435. %  M a i n                                                                    %
  436. %                                                                             %
  437. %                                                                             %
  438. %                                                                             %
  439. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  440. %
  441. %
  442. */
  443. int main(int argc,char **argv)
  444. {
  445. #define NotInitialized  (unsigned int) (~0)
  446.  
  447.   char
  448.     *client_name,
  449.     *filename,
  450.     *option;
  451.  
  452.   Image
  453.     *image,
  454.     *next_image,
  455.     *p;
  456.  
  457.   ImageInfo
  458.     image_info;
  459.  
  460.   int
  461.     x;
  462.  
  463.   register int
  464.     i;
  465.  
  466.   unsigned int
  467.     average,
  468.     global_colormap,
  469.     scene;
  470.  
  471.   /*
  472.     Initialize program variables.
  473.   */
  474.   ReadCommandlLine(argc,&argv);
  475.   client_name=SetClientName(*argv);
  476.   if (argc < 3)
  477.     Usage(client_name);
  478.   /*
  479.     Read image and convert to MIFF format.
  480.   */
  481.   average=False;
  482.   filename=(char *) NULL;
  483.   image=(Image *) NULL;
  484.   global_colormap=False;
  485.   GetImageInfo(&image_info);
  486.   scene=0;
  487.   /*
  488.     Parse command-line arguments.
  489.   */
  490.   ExpandFilenames(&argc,&argv);
  491.   for (i=1; i < (argc-1); i++)
  492.   {
  493.     option=argv[i];
  494.     if ((Extent(option) < 2) || ((*option != '-') && (*option != '+')))
  495.       {
  496.         /*
  497.           Read input image.
  498.         */
  499.         filename=argv[i];
  500.         (void) strcpy(image_info.filename,filename);
  501.         next_image=ReadImage(&image_info);
  502.         if (next_image == (Image *) NULL)
  503.           continue;
  504.         MogrifyImages(&image_info,i,argv,&next_image);
  505.         if (image == (Image *) NULL)
  506.           image=next_image;
  507.         else
  508.           {
  509.             /*
  510.               Link image into image list.
  511.             */
  512.             for (p=image; p->next != (Image *) NULL; p=p->next);
  513.             next_image->previous=p;
  514.             p->next=next_image;
  515.           }
  516.       }
  517.     else
  518.       switch(*(option+1))
  519.       {
  520.         case 'a':
  521.         {
  522.           if (strncmp("adjoin",option+1,2) == 0)
  523.             {
  524.               image_info.adjoin=(*option == '-');
  525.               break;
  526.             }
  527.           if (strncmp("align",option+1,2) == 0)
  528.             {
  529.               int
  530.                 alignment;
  531.  
  532.               alignment=UndefinedAlignment;
  533.               if (*option == '-')
  534.                 {
  535.                   i++;
  536.                   if (i == argc)
  537.                     MagickError(OptionError,"Missing type",option);
  538.                   option=argv[i];
  539.                   alignment=UndefinedAlignment;
  540.                   if (Latin1Compare("Left",option) == 0)
  541.                     alignment=LeftAlignment;
  542.                   if (Latin1Compare("Center",option) == 0)
  543.                     alignment=CenterAlignment;
  544.                   if (Latin1Compare("Right",option) == 0)
  545.                     alignment=RightAlignment;
  546.                   if (alignment == UndefinedAlignment)
  547.                     MagickError(OptionError,"Invalid alignment type",option);
  548.                 }
  549.               break;
  550.             }
  551.           if (strncmp("average",option+1,2) == 0)
  552.             {
  553.               average=(*option == '-');
  554.               break;
  555.             }
  556.           MagickError(OptionError,"Unrecognized option",option);
  557.           break;
  558.         }
  559.         case 'b':
  560.         {
  561.           if (strncmp("blur",option+1,3) == 0)
  562.             {
  563.               if (*option == '-')
  564.                 {
  565.                   i++;
  566.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  567.                     MagickError(OptionError,"Missing factor",option);
  568.                 }
  569.               break;
  570.             }
  571.           if (strncmp("border",option+1,7) == 0)
  572.             {
  573.               if (*option == '-')
  574.                 {
  575.                   i++;
  576.                   if ((i == argc) || !IsGeometry(argv[i]))
  577.                     MagickError(OptionError,"Missing geometry",option);
  578.                 }
  579.               break;
  580.             }
  581.           if (strncmp("bordercolor",option+1,7) == 0)
  582.             {
  583.               if ((i == argc) || !sscanf(argv[i],"%d",&x))
  584.                 {
  585.                   i++;
  586.                   if (i == argc)
  587.                     MagickError(OptionError,"Missing border color",option);
  588.                 }
  589.               break;
  590.             }
  591.           if (strncmp("box",option+1,3) == 0)
  592.             {
  593.               image_info.box=(char *) NULL;
  594.               if (*option == '-')
  595.                 {
  596.                   i++;
  597.                   if (i == argc)
  598.                     MagickError(OptionError,"Missing box color",option);
  599.                   image_info.box=argv[i];
  600.                 }
  601.               break;
  602.             }
  603.           MagickError(OptionError,"Unrecognized option",option);
  604.           break;
  605.         }
  606.         case 'c':
  607.         {
  608.           if (strncmp("charcoal",option+1,2) == 0)
  609.             {
  610.               if (*option == '-')
  611.                 {
  612.                   i++;
  613.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  614.                     MagickError(OptionError,"Missing factor",option);
  615.                 }
  616.               break;
  617.             }
  618.           if (strncmp("colorize",option+1,7) == 0)
  619.             {
  620.               if (*option == '-')
  621.                 {
  622.                   i++;
  623.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  624.                     MagickError(OptionError,"Missing value",option);
  625.                 }
  626.               break;
  627.             }
  628.           if (strncmp("colors",option+1,7) == 0)
  629.             {
  630.               if (*option == '-')
  631.                 {
  632.                   i++;
  633.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  634.                     MagickError(OptionError,"Missing colors",option);
  635.                 }
  636.               break;
  637.             }
  638.           if (strncmp("colorspace",option+1,7) == 0)
  639.             {
  640.               if (*option == '-')
  641.                 {
  642.                   i++;
  643.                   if (i == argc)
  644.                     MagickError(OptionError,"Missing type",option);
  645.                   option=argv[i];
  646.                   image_info.colorspace=UndefinedColorspace;
  647.                   if (Latin1Compare("cmyk",option) == 0)
  648.                     image_info.colorspace=CMYKColorspace;
  649.                   if (Latin1Compare("gray",option) == 0)
  650.                     image_info.colorspace=GRAYColorspace;
  651.                   if (Latin1Compare("ohta",option) == 0)
  652.                     image_info.colorspace=OHTAColorspace;
  653.                   if (Latin1Compare("rgb",option) == 0)
  654.                     image_info.colorspace=RGBColorspace;
  655.                   if (Latin1Compare("transparent",option) == 0)
  656.                     image_info.colorspace=TransparentColorspace;
  657.                   if (Latin1Compare("xyz",option) == 0)
  658.                     image_info.colorspace=XYZColorspace;
  659.                   if (Latin1Compare("ycbcr",option) == 0)
  660.                     image_info.colorspace=YCbCrColorspace;
  661.                   if (Latin1Compare("yiq",option) == 0)
  662.                     image_info.colorspace=YIQColorspace;
  663.                   if (Latin1Compare("ypbpr",option) == 0)
  664.                     image_info.colorspace=YPbPrColorspace;
  665.                   if (Latin1Compare("yuv",option) == 0)
  666.                     image_info.colorspace=YUVColorspace;
  667.                   if (image_info.colorspace == UndefinedColorspace)
  668.                     MagickError(OptionError,"Invalid colorspace type",option);
  669.                 }
  670.               break;
  671.             }
  672.           if (strncmp("comment",option+1,4) == 0)
  673.             {
  674.               if (*option == '-')
  675.                 {
  676.                   i++;
  677.                   if (i == argc)
  678.                     MagickError(OptionError,"Missing comment",option);
  679.                 }
  680.               break;
  681.             }
  682.           if (strncmp("compress",option+1,5) == 0)
  683.             {
  684.               image_info.compression=NoCompression;
  685.               if (*option == '-')
  686.                 {
  687.                   i++;
  688.                   if (i == argc)
  689.                     MagickError(OptionError,"Missing type",option);
  690.                   option=argv[i];
  691.                   image_info.compression=UndefinedCompression;
  692.                   if (Latin1Compare("None",option) == 0)
  693.                     image_info.compression=NoCompression;
  694.                   if (Latin1Compare("JPEG",option) == 0)
  695.                     image_info.compression=JPEGCompression;
  696.                   if (Latin1Compare("LZW",option) == 0)
  697.                     image_info.compression=LZWCompression;
  698.                   if (Latin1Compare("RunlengthEncoded",option) == 0)
  699.                     image_info.compression=RunlengthEncodedCompression;
  700.                   if (Latin1Compare("Zip",option) == 0)
  701.                     image_info.compression=ZipCompression;
  702.                   if (image_info.compression == UndefinedCompression)
  703.                     MagickError(OptionError,"Invalid compression type",option);
  704.                 }
  705.               break;
  706.             }
  707.           if (strncmp("contrast",option+1,3) == 0)
  708.             break;
  709.           if (strncmp("crop",option+1,2) == 0)
  710.             {
  711.               if (*option == '-')
  712.                 {
  713.                   i++;
  714.                   if ((i == argc) || !IsGeometry(argv[i]))
  715.                     MagickError(OptionError,"Missing geometry",option);
  716.                 }
  717.               break;
  718.             }
  719.           if (strncmp("cycle",option+1,2) == 0)
  720.             {
  721.               if (*option == '-')
  722.                 {
  723.                   i++;
  724.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  725.                     MagickError(OptionError,"Missing amount",option);
  726.                 }
  727.               break;
  728.             }
  729.           MagickError(OptionError,"Unrecognized option",option);
  730.           break;
  731.         }
  732.         case 'd':
  733.         {
  734.           if (strncmp("delay",option+1,3) == 0)
  735.             {
  736.               image_info.delay=(char *) NULL;
  737.               if (*option == '-')
  738.                 {
  739.                   i++;
  740.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  741.                     MagickError(OptionError,"Missing delay",option);
  742.                   image_info.delay=PostscriptGeometry(argv[i]);
  743.                 }
  744.               break;
  745.             }
  746.           if (strncmp("density",option+1,3) == 0)
  747.             {
  748.               image_info.density=(char *) NULL;
  749.               if (*option == '-')
  750.                 {
  751.                   i++;
  752.                   if ((i == argc) || !IsGeometry(argv[i]))
  753.                     MagickError(OptionError,"Missing geometry",option);
  754.                   image_info.density=argv[i];
  755.                 }
  756.               break;
  757.             }
  758.           if (strncmp("despeckle",option+1,3) == 0)
  759.             break;
  760.           if (strcmp("display",option+1) == 0)
  761.             {
  762.               image_info.server_name=(char *) NULL;
  763.               if (*option == '-')
  764.                 {
  765.                   i++;
  766.                   if (i == argc)
  767.                     MagickError(OptionError,"Missing server name",option);
  768.                   image_info.server_name=argv[i];
  769.                 }
  770.               break;
  771.             }
  772.           if (strncmp("dispose",option+1,5) == 0)
  773.             {
  774.               image_info.dispose=(char *) NULL;
  775.               if (*option == '-')
  776.                 {
  777.                   i++;
  778.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  779.                     MagickError(OptionError,"Missing method",option);
  780.                   image_info.dispose=PostscriptGeometry(argv[i]);
  781.                 }
  782.               break;
  783.             }
  784.           if (strncmp("dither",option+1,3) == 0)
  785.             {
  786.               image_info.dither=(*option == '-');
  787.               break;
  788.             }
  789.           if (strncmp("draw",option+1,2) == 0)
  790.             {
  791.               if (*option == '-')
  792.                 {
  793.                   i++;
  794.                   if (i == argc)
  795.                     MagickError(OptionError,"Missing primitive",option);
  796.                 }
  797.               break;
  798.             }
  799.           MagickError(OptionError,"Unrecognized option",option);
  800.           break;
  801.         }
  802.         case 'e':
  803.         {
  804.           if (strncmp("edge",option+1,2) == 0)
  805.             {
  806.               if (*option == '-')
  807.                 {
  808.                   i++;
  809.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  810.                     MagickError(OptionError,"Missing factor",option);
  811.                 }
  812.               break;
  813.             }
  814.           if (strncmp("emboss",option+1,2) == 0)
  815.             break;
  816.           if (strncmp("enhance",option+1,2) == 0)
  817.             break;
  818.           if (strncmp("equalize",option+1,2) == 0)
  819.             break;
  820.           MagickError(OptionError,"Unrecognized option",option);
  821.           break;
  822.         }
  823.         case 'f':
  824.         {
  825.           if (strncmp("flip",option+1,3) == 0)
  826.             break;
  827.           if (strncmp("flop",option+1,3) == 0)
  828.             break;
  829.           if (strncmp("font",option+1,2) == 0)
  830.             {
  831.               image_info.font=(char *) NULL;
  832.               if (*option == '-')
  833.                 {
  834.                   i++;
  835.                   if (i == argc)
  836.                     MagickError(OptionError,"Missing font name",option);
  837.                   image_info.font=argv[i];
  838.                 }
  839.               break;
  840.             }
  841.           if (strncmp("frame",option+1,2) == 0)
  842.             {
  843.               if (*option == '-')
  844.                 {
  845.                   i++;
  846.                   if ((i == argc) || !IsGeometry(argv[i]))
  847.                     MagickError(OptionError,"Missing geometry",option);
  848.                 }
  849.               break;
  850.             }
  851.           MagickError(OptionError,"Unrecognized option",option);
  852.           break;
  853.         }
  854.         case 'g':
  855.         {
  856.           if (strncmp("gamma",option+1,2) == 0)
  857.             {
  858.               i++;
  859.               if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  860.                 MagickError(OptionError,"Missing value",option);
  861.               break;
  862.             }
  863.           if (strncmp("geometry",option+1,2) == 0)
  864.             {
  865.               if (*option == '-')
  866.                 {
  867.                   i++;
  868.                   if ((i == argc) || !IsGeometry(argv[i]))
  869.                     MagickError(OptionError,"Missing geometry",option);
  870.                 }
  871.               break;
  872.             }
  873.           MagickError(OptionError,"Unrecognized option",option);
  874.           break;
  875.         }
  876.         case 'h':
  877.         {
  878.           if (strncmp("help",option+1,2) == 0)
  879.             {
  880.               Usage(client_name);
  881.               break;
  882.             }
  883.           MagickError(OptionError,"Unrecognized option",option);
  884.           break;
  885.         }
  886.         case 'i':
  887.         {
  888.           if (strncmp("implode",option+1,2) == 0)
  889.             {
  890.               if (*option == '-')
  891.                 {
  892.                   i++;
  893.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  894.                     MagickError(OptionError,"Missing amount",option);
  895.                 }
  896.               break;
  897.             }
  898.           if (strncmp("interlace",option+1,3) == 0)
  899.             {
  900.               image_info.interlace=NoInterlace;
  901.               if (*option == '-')
  902.                 {
  903.                   i++;
  904.                   if (i == argc)
  905.                     MagickError(OptionError,"Missing type",option);
  906.                   option=argv[i];
  907.                   image_info.interlace=UndefinedInterlace;
  908.                   if (Latin1Compare("None",option) == 0)
  909.                     image_info.interlace=NoInterlace;
  910.                   if (Latin1Compare("Line",option) == 0)
  911.                     image_info.interlace=LineInterlace;
  912.                   if (Latin1Compare("Plane",option) == 0)
  913.                     image_info.interlace=PlaneInterlace;
  914.                   if (Latin1Compare("Partition",option) == 0)
  915.                     image_info.interlace=PartitionInterlace;
  916.                   if (image_info.interlace == UndefinedInterlace)
  917.                     MagickError(OptionError,"Invalid interlace type",option);
  918.                 }
  919.               break;
  920.             }
  921.           MagickError(OptionError,"Unrecognized option",option);
  922.         }
  923.         case 'l':
  924.         {
  925.           if (strncmp("label",option+1,3) == 0)
  926.             {
  927.               if (*option == '-')
  928.                 {
  929.                   i++;
  930.                   if (i == argc)
  931.                     MagickError(OptionError,"Missing label name",option);
  932.                 }
  933.               break;
  934.             }
  935.           if (strncmp("layer",option+1,3) == 0)
  936.             {
  937.               if (*option == '-')
  938.                 {
  939.                   LayerType
  940.                     layer;
  941.  
  942.                   i++;
  943.                   if (i == argc)
  944.                     MagickError(OptionError,"Missing type",option);
  945.                   option=argv[i];
  946.                   layer=UndefinedLayer;
  947.                   if (Latin1Compare("Red",option) == 0)
  948.                     layer=RedLayer;
  949.                   if (Latin1Compare("Green",option) == 0)
  950.                     layer=GreenLayer;
  951.                   if (Latin1Compare("Blue",option) == 0)
  952.                     layer=BlueLayer;
  953.                   if (Latin1Compare("Matte",option) == 0)
  954.                     layer=MatteLayer;
  955.                   if (layer == UndefinedLayer)
  956.                     MagickError(OptionError,"Invalid layer type",option);
  957.                 }
  958.               break;
  959.             }
  960.           if (strncmp("linewidth",option+1,2) == 0)
  961.             {
  962.               if (*option == '-')
  963.                 {
  964.                   i++;
  965.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  966.                     MagickError(OptionError,"Missing size",option);
  967.                 }
  968.               break;
  969.             }
  970.           if (strncmp("loop",option+1,2) == 0)
  971.             {
  972.               image_info.iterations=(char *) NULL;
  973.               if (*option == '-')
  974.                 {
  975.                   i++;
  976.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  977.                     MagickError(OptionError,"Missing iterations",option);
  978.                   image_info.iterations=PostscriptGeometry(argv[i]);
  979.                 }
  980.               break;
  981.             }
  982.           MagickError(OptionError,"Unrecognized option",option);
  983.           break;
  984.         }
  985.         case 'm':
  986.         {
  987.           if (strncmp("map",option+1,3) == 0)
  988.             {
  989.               global_colormap=(*option == '+');
  990.               if (*option == '-')
  991.                 {
  992.                   i++;
  993.                   if (i == argc)
  994.                     MagickError(OptionError,"Missing file name",option);
  995.                 }
  996.               break;
  997.             }
  998.           if (strcmp("matte",option+1) == 0)
  999.             break;
  1000.           if (strncmp("mattecolor",option+1,6) == 0)
  1001.             {
  1002.               if (*option == '-')
  1003.                 {
  1004.                   i++;
  1005.                   if (i == argc)
  1006.                     MagickError(OptionError,"Missing matte color",option);
  1007.                 }
  1008.               break;
  1009.             }
  1010.           if (strncmp("modulate",option+1,3) == 0)
  1011.             {
  1012.               if (*option == '-')
  1013.                 {
  1014.                   i++;
  1015.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1016.                     MagickError(OptionError,"Missing value",option);
  1017.                 }
  1018.               break;
  1019.             }
  1020.           if (strncmp("monochrome",option+1,4) == 0)
  1021.             {
  1022.               image_info.monochrome=(*option == '-');
  1023.               break;
  1024.             }
  1025.           MagickError(OptionError,"Unrecognized option",option);
  1026.         }
  1027.         case 'n':
  1028.         {
  1029.           if (strncmp("negate",option+1,3) == 0)
  1030.             break;
  1031.           if (strncmp("noise",option+1,3) == 0)
  1032.             {
  1033.               if (*option == '+')
  1034.                 {
  1035.                   i++;
  1036.                   if (i == argc)
  1037.                     MagickError(OptionError,"Missing type",option);
  1038.                   option=argv[i];
  1039.                   if ((Latin1Compare("uniform",option) != 0) &&
  1040.                       (Latin1Compare("gaussian",option) != 0) &&
  1041.                       (Latin1Compare("multiplicative",option) != 0) &&
  1042.                       (Latin1Compare("impulse",option) != 0) &&
  1043.                       (Latin1Compare("laplacian",option) != 0) &&
  1044.                       (Latin1Compare("poisson",option) != 0))
  1045.                     MagickError(OptionError,"Invalid noise type",option);
  1046.                 }
  1047.               break;
  1048.             }
  1049.           if (strncmp("normalize",option+1,3) == 0)
  1050.             break;
  1051.           MagickError(OptionError,"Unrecognized option",option);
  1052.           break;
  1053.         }
  1054.         case 'o':
  1055.         {
  1056.           if (strncmp("opaque",option+1,2) == 0)
  1057.             {
  1058.               if (*option == '-')
  1059.                 {
  1060.                   i++;
  1061.                   if (i == argc)
  1062.                     MagickError(OptionError,"Missing opaque color",option);
  1063.                 }
  1064.               break;
  1065.             }
  1066.           MagickError(OptionError,"Unrecognized option",option);
  1067.           break;
  1068.         }
  1069.         case 'p':
  1070.         {
  1071.           if (strncmp("page",option+1,3) == 0)
  1072.             {
  1073.               image_info.page=(char *) NULL;
  1074.               if (*option == '-')
  1075.                 {
  1076.                   i++;
  1077.                   if (i == argc)
  1078.                     MagickError(OptionError,"Missing page geometry",option);
  1079.                   image_info.page=PostscriptGeometry(argv[i]);
  1080.                 }
  1081.               break;
  1082.             }
  1083.           if (strncmp("paint",option+1,3) == 0)
  1084.             {
  1085.               if (*option == '-')
  1086.                 {
  1087.                   i++;
  1088.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1089.                     MagickError(OptionError,"Missing radius",option);
  1090.                 }
  1091.               break;
  1092.             }
  1093.           if (strncmp("pen",option+1,2) == 0)
  1094.             {
  1095.               image_info.pen=(char *) NULL;
  1096.               if (*option == '-')
  1097.                 {
  1098.                   i++;
  1099.                   if (i == argc)
  1100.                     MagickError(OptionError,"Missing pen color",option);
  1101.                   image_info.pen=argv[i];
  1102.                 }
  1103.               break;
  1104.             }
  1105.           if (strncmp("pointsize",option+1,2) == 0)
  1106.             {
  1107.               image_info.pointsize=atoi(DefaultPointSize);
  1108.               if (*option == '-')
  1109.                 {
  1110.                   i++;
  1111.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1112.                     MagickError(OptionError,"Missing size",option);
  1113.                   image_info.pointsize=atoi(argv[i]);
  1114.                 }
  1115.               break;
  1116.             }
  1117.           MagickError(OptionError,"Unrecognized option",option);
  1118.           break;
  1119.         }
  1120.         case 'q':
  1121.         {
  1122.           if (strncmp("quality",option+1,2) == 0)
  1123.             {
  1124.               image_info.quality=atoi(DefaultImageQuality);
  1125.               if (*option == '-')
  1126.                 {
  1127.                   i++;
  1128.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1129.                     MagickError(OptionError,"Missing quality",option);
  1130.                   image_info.quality=atoi(argv[i]);
  1131.                 }
  1132.               break;
  1133.             }
  1134.           MagickError(OptionError,"Unrecognized option",option);
  1135.           break;
  1136.         }
  1137.         case 'r':
  1138.         {
  1139.           if (strncmp("raise",option+1,2) == 0)
  1140.             {
  1141.               i++;
  1142.               if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1143.                 MagickError(OptionError,"Missing bevel width",option);
  1144.               break;
  1145.             }
  1146.           if (strncmp("region",option+1,3) == 0)
  1147.             {
  1148.               if (*option == '-')
  1149.                 {
  1150.                   i++;
  1151.                   if ((i == argc) || !IsGeometry(argv[i]))
  1152.                     MagickError(OptionError,"Missing geometry",option);
  1153.                 }
  1154.               break;
  1155.             }
  1156.           if (strncmp("roll",option+1,3) == 0)
  1157.             {
  1158.               if (*option == '-')
  1159.                 {
  1160.                   i++;
  1161.                   if ((i == argc) || !IsGeometry(argv[i]))
  1162.                     MagickError(OptionError,"Missing geometry",option);
  1163.                 }
  1164.               break;
  1165.             }
  1166.           if (strncmp("rotate",option+1,3) == 0)
  1167.             {
  1168.               if (*option == '-')
  1169.                 {
  1170.                   i++;
  1171.                   if ((i == argc) || !IsGeometry(argv[i]))
  1172.                     MagickError(OptionError,"Missing degrees",option);
  1173.                 }
  1174.               break;
  1175.             }
  1176.           MagickError(OptionError,"Unrecognized option",option);
  1177.           break;
  1178.         }
  1179.         case 's':
  1180.         {
  1181.           if (strncmp("sample",option+1,2) == 0)
  1182.             {
  1183.               if (*option == '-')
  1184.                 {
  1185.                   i++;
  1186.                   if ((i == argc) || !IsGeometry(argv[i]))
  1187.                     MagickError(OptionError,"Missing geometry",option);
  1188.                 }
  1189.               break;
  1190.             }
  1191.           if (strncmp("scene",option+1,3) == 0)
  1192.             {
  1193.               scene=0;
  1194.               if (*option == '-')
  1195.                 {
  1196.                   i++;
  1197.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1198.                     MagickError(OptionError,"Missing scene number",option);
  1199.                 }
  1200.               scene=atoi(argv[i]);
  1201.               break;
  1202.             }
  1203.           if (strncmp("seed",option+1,3) == 0)
  1204.             {
  1205.               if (*option == '-')
  1206.                 {
  1207.                   i++;
  1208.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1209.                     MagickError(OptionError,"Missing value",option);
  1210.                 }
  1211.               srand((unsigned int) atoi(argv[i]));
  1212.               break;
  1213.             }
  1214.           if (strncmp("segment",option+1,3) == 0)
  1215.             {
  1216.               if (*option == '-')
  1217.                 {
  1218.                   i++;
  1219.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1220.                     MagickError(OptionError,"Missing threshold",option);
  1221.                 }
  1222.               break;
  1223.             }
  1224.           if (strncmp("shade",option+1,5) == 0)
  1225.             {
  1226.               i++;
  1227.               if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1228.                 MagickError(OptionError,"Missing azimuth",option);
  1229.               break;
  1230.             }
  1231.           if (strncmp("sharpen",option+1,5) == 0)
  1232.             {
  1233.               if (*option == '-')
  1234.                 {
  1235.                   i++;
  1236.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1237.                     MagickError(OptionError,"Missing factor",option);
  1238.                 }
  1239.               break;
  1240.             }
  1241.           if (strncmp("shear",option+1,3) == 0)
  1242.             {
  1243.               if (*option == '-')
  1244.                 {
  1245.                   i++;
  1246.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1247.                     MagickError(OptionError,"Missing geometry",option);
  1248.                 }
  1249.               break;
  1250.             }
  1251.           if (strncmp("size",option+1,2) == 0)
  1252.             {
  1253.               image_info.size=(char *) NULL;
  1254.               if (*option == '-')
  1255.                 {
  1256.                   i++;
  1257.                   if ((i == argc) || !IsGeometry(argv[i]))
  1258.                     MagickError(OptionError,"Missing geometry",option);
  1259.                   image_info.size=argv[i];
  1260.                 }
  1261.               break;
  1262.             }
  1263.           if (strncmp("solarize",option+1,2) == 0)
  1264.             {
  1265.               if (*option == '-')
  1266.                 {
  1267.                   i++;
  1268.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1269.                     MagickError(OptionError,"Missing threshold",option);
  1270.                 }
  1271.               break;
  1272.             }
  1273.           if (strncmp("spread",option+1,2) == 0)
  1274.             {
  1275.               if (*option == '-')
  1276.                 {
  1277.                   i++;
  1278.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1279.                     MagickError(OptionError,"Missing amount",option);
  1280.                 }
  1281.               break;
  1282.             }
  1283.           if (strncmp("swirl",option+1,2) == 0)
  1284.             {
  1285.               if (*option == '-')
  1286.                 {
  1287.                   i++;
  1288.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1289.                     MagickError(OptionError,"Missing degrees",option);
  1290.                 }
  1291.               break;
  1292.             }
  1293.           MagickError(OptionError,"Unrecognized option",option);
  1294.           break;
  1295.         }
  1296.         case 't':
  1297.         {
  1298.           if (strncmp("texture",option+1,5) == 0)
  1299.             {
  1300.               image_info.texture=(char *) NULL;
  1301.               if (*option == '-')
  1302.                 {
  1303.                   i++;
  1304.                   if (i == argc)
  1305.                     MagickError(OptionError,"Missing filename",option);
  1306.                   image_info.texture=argv[i];
  1307.                 }
  1308.               break;
  1309.             }
  1310.           if (strncmp("threshold",option+1,2) == 0)
  1311.             {
  1312.               if (*option == '-')
  1313.                 {
  1314.                   i++;
  1315.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1316.                     MagickError(OptionError,"Missing value",option);
  1317.                 }
  1318.               break;
  1319.             }
  1320.           if (strncmp("transparent",option+1,3) == 0)
  1321.             {
  1322.               if (*option == '-')
  1323.                 {
  1324.                   i++;
  1325.                   if (i == argc)
  1326.                     MagickError(OptionError,"Missing transparent color",option);
  1327.                 }
  1328.               break;
  1329.             }
  1330.           if (strncmp("treedepth",option+1,3) == 0)
  1331.             {
  1332.               if (*option == '-')
  1333.                 {
  1334.                   i++;
  1335.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1336.                     MagickError(OptionError,"Missing depth",option);
  1337.                 }
  1338.               break;
  1339.             }
  1340.           MagickError(OptionError,"Unrecognized option",option);
  1341.           break;
  1342.         }
  1343.         case 'u':
  1344.         {
  1345.           if (strncmp("undercolor",option+1,2) == 0)
  1346.             {
  1347.               image_info.undercolor=(char *) NULL;
  1348.               if (*option == '-')
  1349.                 {
  1350.                   i++;
  1351.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1352.                     MagickError(OptionError,"Missing undercolor geometry",
  1353.                       option);
  1354.                   image_info.undercolor=argv[i];
  1355.                 }
  1356.               break;
  1357.             }
  1358.           MagickError(OptionError,"Unrecognized option",option);
  1359.           break;
  1360.         }
  1361.         case 'v':
  1362.         {
  1363.           if (strncmp("verbose",option+1,2) == 0)
  1364.             {
  1365.               image_info.verbose=(*option == '-');
  1366.               break;
  1367.             }
  1368.           if (strncmp("view",option+1,3) == 0)
  1369.             {
  1370.               image_info.view=(char *) NULL;
  1371.               if (*option == '-')
  1372.                 {
  1373.                   i++;
  1374.                   if (i == argc)
  1375.                     MagickError(OptionError,"Missing view transform",option);
  1376.                   image_info.view=argv[i];
  1377.                 }
  1378.               break;
  1379.             }
  1380.           MagickError(OptionError,"Unrecognized option",option);
  1381.           break;
  1382.         }
  1383.         case 'w':
  1384.         {
  1385.           if (strcmp("wave",option+1) == 0)
  1386.             {
  1387.               i++;
  1388.               if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1389.                 MagickError(OptionError,"Missing amplitude",option);
  1390.               break;
  1391.             }
  1392.           MagickError(OptionError,"Unrecognized option",option);
  1393.           break;
  1394.         }
  1395.         case '?':
  1396.         {
  1397.           Usage(client_name);
  1398.           break;
  1399.         }
  1400.         default:
  1401.         {
  1402.           MagickError(OptionError,"Unrecognized option",option);
  1403.           break;
  1404.         }
  1405.       }
  1406.   }
  1407.   if (image == (Image *) NULL)
  1408.     MagickError(OptionError,"Missing an image file name",(char *) NULL);
  1409.   /*
  1410.     Write images.
  1411.   */
  1412.   if ((Extent(option) > 2) && ((*option == '-') || (*option == '+')))
  1413.     MogrifyImages(&image_info,i,argv,&image);
  1414.   while (image->previous != (Image *) NULL)
  1415.     image=image->previous;
  1416.   if (average)
  1417.     {
  1418.       Image
  1419.         *averaged_image;
  1420.  
  1421.       /*
  1422.         Average a set of images.
  1423.       */
  1424.       averaged_image=AverageImages(image);
  1425.       if (averaged_image != (Image *) NULL)
  1426.         {
  1427.           DestroyImages(image);
  1428.           image=averaged_image;
  1429.         }
  1430.     }
  1431.   if (global_colormap)
  1432.     MapImages(image,(Image *) NULL,image_info.dither);
  1433.   /*
  1434.     Transmogrify image as defined by the image processing options.
  1435.   */
  1436.   (void) strcpy(image_info.filename,argv[i]);
  1437.   SetImageInfo(&image_info,True);
  1438.   for (p=image; p != (Image *) NULL; p=p->next)
  1439.   {
  1440.     (void) strcpy(p->filename,argv[i]);
  1441.     p->scene=scene++;
  1442.   }
  1443.   for (p=image; p != (Image *) NULL; p=p->next)
  1444.   {
  1445.     (void) WriteImage(&image_info,p);
  1446.     if (image_info.adjoin)
  1447.       break;
  1448.   }
  1449.   if (image_info.verbose)
  1450.     DescribeImage(image,stdout,False);
  1451.   DestroyImage(image);
  1452.   DestroyImageInfo(&image_info);
  1453.   Exit(0);
  1454.   return(False);
  1455. }
  1456.