root / ImageMagick / trunk / wand / convert.c

Revision 12114, 97.2 kB (checked in by cristy, 38 hours ago)
Line 
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%                              Software Design                                %
16%                                John Cristy                                  %
17%                                April 1992                                   %
18%                                                                             %
19%                                                                             %
20%  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
21%  dedicated to making software imaging solutions freely available.           %
22%                                                                             %
23%  You may not use this file except in compliance with the License.  You may  %
24%  obtain a copy of the License at                                            %
25%                                                                             %
26%    http://www.imagemagick.org/script/license.php                            %
27%                                                                             %
28%  Unless required by applicable law or agreed to in writing, software        %
29%  distributed under the License is distributed on an "AS IS" BASIS,          %
30%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31%  See the License for the specific language governing permissions and        %
32%  limitations under the License.                                             %
33%                                                                             %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%  Convert converts an input file using one image format to an output file
37%  with a differing image format. By default, the image format is determined
38%  by its magic number. To specify a particular image format, precede the
39%  filename with an image format name and a colon (i.e. ps:image) or specify
40%  the image type as the filename suffix (i.e. image.ps). Specify file as -
41%  for standard input or output. If file has the extension .Z, the file is
42%  decoded with uncompress.
43%
44%
45*/
46
47/*
48  Include declarations.
49*/
50#include "wand/studio.h"
51#include "wand/MagickWand.h"
52#include "wand/mogrify-private.h"
53
54/*
55  Define declarations.
56*/
57#define ThrowFileException(exception,severity,tag,context) \
58{ \
59  (void) ThrowMagickException(exception,GetMagickModule(),severity, \
60    tag == (const char *) NULL ? "unknown" : tag,"`%s': %s",context, \
61    strerror(errno)); \
62}
63
64/*
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66%                                                                             %
67%                                                                             %
68%                                                                             %
69+   C o n v e r t I m a g e C o m m a n d                                     %
70%                                                                             %
71%                                                                             %
72%                                                                             %
73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74%
75%  ConvertImageCommand() reads one or more images, applies one or more image
76%  processing operations, and writes out the image in the same or differing
77%  format.
78%
79%  The format of the ConvertImageCommand method is:
80%
81%      MagickBooleanType ConvertImageCommand(ImageInfo *image_info,int argc,
82%        char **argv,char **metadata,ExceptionInfo *exception)
83%
84%  A description of each parameter follows:
85%
86%    o image_info: the image info.
87%
88%    o argc: the number of elements in the argument vector.
89%
90%    o argv: A text array containing the command line arguments.
91%
92%    o metadata: any metadata is returned here.
93%
94%    o exception: Return any errors or warnings in this structure.
95%
96*/
97
98static MagickBooleanType ConcatenateImages(int argc,char **argv,
99  ExceptionInfo *exception)
100{
101  FILE
102    *input,
103    *output;
104
105  int
106    c;
107
108  register long
109    i;
110
111  /*
112    Open output file.
113  */
114  output=MagickOpenStream(argv[argc-1],"wb");
115  if (output == (FILE *) NULL)
116    {
117      ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
118        argv[argc-1]);
119      return(MagickFalse);
120    }
121  for (i=2; i < (long) (argc-1); i++)
122  {
123    input=MagickOpenStream(argv[i],"rb");
124    if (input == (FILE *) NULL)
125      ThrowFileException(exception,FileOpenError,"UnableToOpenFile",argv[i]);
126    for (c=fgetc(input); c != EOF; c=fgetc(input))
127      (void) fputc((char) c,output);
128    (void) fclose(input);
129    (void) remove(argv[i]);
130  }
131  (void) fclose(output);
132  return(MagickTrue);
133}
134
135static void ConvertUsage(void)
136{
137  static const char
138    *miscellaneous[]=
139    {
140      "-debug events        display copious debugging information",
141      "-help                print program options",
142      "-list type           print a list of supported option arguments",
143      "-log format          format of debugging information",
144      "-version             print version information",
145      (char *) NULL
146    },
147    *operators[]=
148    {
149      "-adaptive-blur geometry",
150      "                     adaptively blur pixels; decrease effect near edges",
151      "-adaptive-resize geometry",
152      "                     adaptively resize image using 'mesh' interpolation",
153      "-adaptive-sharpen geometry",
154      "                     adaptively sharpen pixels; increase effect near edges",
155      "-alpha option        activate, deactivate, reset, or set the alpha channel",
156      "-annotate geometry text",
157      "                     annotate the image with text",
158      "-auto-orient         automatically orient image",
159      "-bench iterations    measure performance",
160      "-black-threshold value",
161      "                     force all pixels below the threshold into black",
162      "-blur geometry       reduce image noise and reduce detail levels",
163      "-border geometry     surround image with a border of color",
164      "-bordercolor color   border color",
165      "-charcoal radius     simulate a charcoal drawing",
166      "-chop geometry       remove pixels from the image interior",
167      "-clip                clip along the first path from the 8BIM profile",
168      "-clip-mask filename  associate a clip mask with the image",
169      "-clip-path id        clip along a named path from the 8BIM profile",
170      "-colorize value      colorize the image with the fill color",
171      "-contrast            enhance or reduce the image contrast",
172      "-contrast-stretch geometry",
173      "                     improve contrast by `stretching' the intensity range",
174      "-convolve coefficients",
175      "                     apply a convolution kernel to the image",
176      "-cycle amount        cycle the image colormap",
177      "-decipher filename   convert cipher pixels to plain pixels",
178      "-deskew threshold    straighten an image",
179      "-despeckle           reduce the speckles within an image",
180      "-distort method args",
181      "                     distort images according to given method ad args",
182      "-draw string         annotate the image with a graphic primitive",
183      "-edge radius         apply a filter to detect edges in the image",
184      "-encipher filename   convert plain pixels to cipher pixels",
185      "-emboss radius       emboss an image",
186      "-enhance             apply a digital filter to enhance a noisy image",
187      "-equalize            perform histogram equalization to an image",
188      "-evaluate operator value",
189      "                     evaluate an arithmetic, relational, or logical",
190      "                     expression",
191      "-extent geometry     set the image size",
192      "-extract geometry    extract area from image",
193      "-flip                flip image vertically",
194      "-floodfill geometry color",
195      "                     floodfill the image with color",
196      "-flop                flop image horizontally",
197      "-frame geometry      surround image with an ornamental border",
198      "-gamma value         level of gamma correction",
199      "-gaussian-blur geometry",
200      "                     reduce image noise and reduce detail levels",
201      "-geometry geometry   perferred size or location of the image",
202      "-identify            identify the format and characteristics of the image",
203      "-implode amount      implode image pixels about the center",
204      "-lat geometry        local adaptive thresholding",
205      "-layers method       optimize, merge,  or compare image layers",
206      "-level value         adjust the level of image contrast",
207      "-level-colors color,color",
208      "                     level image using given colors",
209      "-linear-stretch geometry",
210      "                     improve contrast by `stretching with saturation'",
211      "-liquid-rescale geometry",
212      "                     rescale image with seam-carving",
213      "-median radius       apply a median filter to the image",
214      "-modulate value      vary the brightness, saturation, and hue",
215      "-monochrome          transform image to black and white",
216      "-motion-blur geometry",
217      "                     simulate motion blur",
218      "-negate              replace every pixel with its complementary color ",
219      "-noise radius        add or reduce noise in an image",
220      "-normalize           transform image to span the full range of colors",
221      "-opaque color        change this color to the fill color",
222      "-ordered-dither NxN",
223      "                     add a noise pattern to the image with specific",
224      "                     amplitudes",
225      "-paint radius        simulate an oil painting",
226      "-polaroid angle      simulate a Polaroid picture",
227      "-posterize levels    reduce the image to a limited number of color levels",
228      "-print string        interpret string and print to console",
229      "-profile filename    add, delete, or apply an image profile",
230      "-quantize colorspace reduce colors in this colorspace",
231      "-radial-blur angle   radial blur the image",
232      "-raise value         lighten/darken image edges to create a 3-D effect",
233      "-random-threshold low,high",
234      "                     random threshold the image",
235      "-recolor matrix      translate, scale, shear, or rotate image colors",
236      "-region geometry     apply options to a portion of the image",
237      "-render              render vector graphics",
238      "-repage geometry     size and location of an image canvas",
239      "-resample geometry   change the resolution of an image",
240      "-resize geometry     resize the image",
241      "-roll geometry       roll an image vertically or horizontally",
242      "-rotate degrees      apply Paeth rotation to the image",
243      "-sample geometry     scale image with pixel sampling",
244      "-scale geometry      scale the image",
245      "-segment values      segment an image",
246      "-sepia-tone threshold",
247      "                     simulate a sepia-toned photo",
248      "-set property value  set an image property",
249      "-shade degrees       shade the image using a distant light source",
250      "-shadow geometry     simulate an image shadow",
251      "-sharpen geometry    sharpen the image",
252      "-shave geometry      shave pixels from the image edges",
253      "-shear geometry      slide one edge of the image along the X or Y axis",
254      "-sigmoidal-contrast geometry",
255      "                     increase the contrast without saturating highlights or shadows",
256      "-sketch geometry     simulate a pencil sketch",
257      "-solarize threshold  negate all pixels above the threshold level",
258      "-sparse-color method args",
259      "                     fill in a image based on a few color points",
260      "-splice geometry     splice the background color into the image",
261      "-spread radius       displace image pixels by a random amount",
262      "-strip               strip image of all profiles and comments",
263      "-swirl degrees       swirl image pixels about the center",
264      "-threshold value     threshold the image",
265      "-thumbnail geometry  create a thumbnail of the image",
266      "-tile filename       tile image when filling a graphic primitive",
267      "-tint value          tint the image with the fill color",
268      "-transform           affine transform image",
269      "-transparent color   make this color transparent within the image",
270      "-transpose           flip image vertically and rotate 90 degrees",
271      "-transverse          flop image horizontally and rotate 270 degrees",
272      "-trim                trim image edges",
273      "-type type           image type",
274      "-unique-colors       discard all but one of any pixel color",
275      "-unsharp geometry    sharpen the image",
276      "-vignette geometry   soften the edges of the image in vignette style",
277      "-wave geometry       alter an image along a sine wave",
278      "-white-threshold value",
279      "                     force all pixels above the threshold into white",
280      (char *) NULL
281    },
282    *sequence_operators[]=
283    {
284      "-affinity filename   transform image colors to match this set of colors",
285      "-append              append an image sequence",
286      "-average             average an image sequence",
287      "-clut                apply a color lookup table to the image",
288      "-coalesce            merge a sequence of images",
289      "-combine             combine a sequence of images",
290      "-composite           composite image",
291      "-crop geometry       cut out a rectangular region of the image",
292      "-deconstruct         break down an image sequence into constituent parts",
293      "-flatten             flatten a sequence of images",
294      "-fx expression       apply mathematical expression to an image channel(s)",
295      "-morph value         morph an image sequence",
296      "-mosaic              create a mosaic from an image sequence",
297      "-process arguments   process the image with a custom image filter",
298      "-reverse             reverse image sequence",
299      "-separate            separate an image channel into a grayscale image",
300      "-write filename      write images to this file",
301      (char *) NULL
302    },
303    *settings[]=
304    {
305      "-adjoin              join images into a single multi-image file",
306      "-affine matrix       affine transform matrix",
307      "-alpha option        activate, deactivate, reset, or set the alpha channel",
308      "-antialias           remove pixel-aliasing",
309      "-authenticate password",
310      "                     decipher image with this password",
311      "-attenuate value     lessen (or intensify) when adding noise to an image",
312      "-background color    background color",
313      "-bias value          add bias when convolving an image",
314      "-black-point-compensation",
315      "                     use black point compensation",
316      "-blue-primary point  chromaticity blue primary point",
317      "-bordercolor color   border color",
318      "-caption string      assign a caption to an image",
319      "-channel type        apply option to select image channels",
320      "-colors value        preferred number of colors in the image",
321      "-colorspace type     alternate image colorspace",
322      "-comment string      annotate image with comment",
323      "-compose operator    set image composite operator",
324      "-compress type       type of pixel compression when writing the image",
325      "-define format:option",
326      "                     define one or more image format options",
327      "-delay value         display the next image after pausing",
328      "-density geometry    horizontal and vertical density of the image",
329      "-depth value         image depth",
330      "-display server      get image or font from this X server",
331      "-dispose method      layer disposal method",
332      "-dither method       apply error diffusion to image",
333      "-encoding type       text encoding type",
334      "-endian type         endianness (MSB or LSB) of the image",
335      "-family name         render text with this font family",
336      "-fill color          color to use when filling a graphic primitive",
337      "-filter type         use this filter when resizing an image",
338      "-font name           render text with this font",
339      "-format \"string\"     output formatted image characteristics",
340      "-fuzz distance       colors within this distance are considered equal",
341      "-gravity type        horizontal and vertical text placement",
342      "-green-primary point chromaticity green primary point",
343      "-intent type         type of rendering intent when managing the image color",
344      "-interlace type      type of image interlacing scheme",
345      "-interpolate method  pixel color interpolation method",
346      "-label string        assign a label to an image",
347      "-limit type value    pixel cache resource limit",
348      "-loop iterations     add Netscape loop extension to your GIF animation",
349      "-mask filename       associate a mask with the image",
350      "-mattecolor color    frame color",
351      "-monitor             monitor progress",
352      "-orient type         image orientation",
353      "-page geometry       size and location of an image canvas (setting)",
354      "-ping                efficiently determine image attributes",
355      "-pointsize value     font point size",
356      "-preview type        image preview type",
357      "-quality value       JPEG/MIFF/PNG compression level",
358      "-quiet               suppress all warning messages",
359      "-red-primary point   chromaticity red primary point",
360      "-regard-warnings     pay attention to warning messages",
361      "-respect-parenthesis settings remain in effect until parenthesis boundary",
362      "-sampling-factor geometry",
363      "                     horizontal and vertical sampling factor",
364      "-scene value         image scene number",
365      "-seed value          seed a new sequence of pseudo-random numbers",
366      "-size geometry       width and height of image",
367      "-stretch type        render text with this font stretch",
368      "-stroke color        graphic primitive stroke color",
369      "-strokewidth value   graphic primitive stroke width",
370      "-style type          render text with this font style",
371      "-taint               image as ineligible for bi-modal delegate",
372      "-texture filename    name of texture to tile onto the image background",
373      "-tile-offset geometry",
374      "                     tile offset",
375      "-treedepth value     color tree depth",
376      "-transparent-color color",
377      "                     transparent color",
378      "-undercolor color    annotation bounding box color",
379      "-units type          the units of image resolution",
380      "-verbose             print detailed information about the image",
381      "-view                FlashPix viewing transforms",
382      "-virtual-pixel method",
383      "                     virtual pixel access method",
384      "-weight type         render text with this font weight",
385      "-white-point point   chromaticity white point",
386      (char *) NULL
387    },
388    *stack_operators[]=
389    {
390      "-clone index         clone an image",
391      "-delete index        delete the image from the image sequence",
392      "-insert index        insert last image into the image sequence",
393      "-swap indexes        swap two images in the image sequence",
394      (char *) NULL
395    };
396
397  const char
398    **p;
399
400  (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
401  (void) printf("Copyright: %s\n\n",GetMagickCopyright());
402  (void) printf("Usage: %s [options ...] file [ [options ...] "
403    "file ...] [options ...] file\n",GetClientName());
404  (void) printf("\nImage Settings:\n");
405  for (p=settings; *p != (char *) NULL; p++)
406    (void) printf("  %s\n",*p);
407  (void) printf("\nImage Operators:\n");
408  for (p=operators; *p != (char *) NULL; p++)
409    (void) printf("  %s\n",*p);
410  (void) printf("\nImage Sequence Operators:\n");
411  for (p=sequence_operators; *p != (char *) NULL; p++)
412    (void) printf("  %s\n",*p);
413  (void) printf("\nImage Stack Operators:\n");
414  for (p=stack_operators; *p != (char *) NULL; p++)
415    (void) printf("  %s\n",*p);
416  (void) printf("\nMiscellaneous Options:\n");
417  for (p=miscellaneous; *p != (char *) NULL; p++)
418    (void) printf("  %s\n",*p);
419  (void) printf(
420    "\nBy default, the image format of `file' is determined by its magic\n");
421  (void) printf(
422    "number.  To specify a particular image format, precede the filename\n");
423  (void) printf(
424    "with an image format name and a colon (i.e. ps:image) or specify the\n");
425  (void) printf(
426    "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
427  (void) printf("'-' for standard input or output.\n");
428  exit(0);
429}
430
431WandExport MagickBooleanType ConvertImageCommand(ImageInfo *image_info,
432  int argc,char **argv,char **metadata,ExceptionInfo *exception)
433{
434#define NotInitialized  (unsigned int) (~0)
435#define DestroyConvert() \
436{ \
437  DestroyImageStack(); \
438  for (i=0; i < (long) argc; i++) \
439    argv[i]=DestroyString(argv[i]); \
440  argv=(char **) RelinquishMagickMemory(argv); \
441}
442#define ThrowConvertException(asperity,tag,option) \
443{ \
444  (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
445    option); \
446  DestroyConvert(); \
447  return(MagickFalse); \
448}
449#define ThrowConvertInvalidArgumentException(option,argument) \
450{ \
451  (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
452    "InvalidArgument","`%s': %s",argument,option); \
453  DestroyConvert(); \
454  return(MagickFalse); \
455}
456
457  char
458    *filename,
459    *option;
460
461  const char
462    *format;
463
464  Image
465    *image;
466
467  ImageStack
468    image_stack[MaxImageStackDepth+1];
469
470  long
471    j,
472    k;
473
474  MagickBooleanType
475    fire,
476    pend;
477
478  MagickStatusType
479    status;
480
481  register long
482    i;
483
484  /*
485    Set defaults.
486  */
487  assert(image_info != (ImageInfo *) NULL);
488  assert(image_info->signature == MagickSignature);
489  if (image_info->debug != MagickFalse)
490    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
491  assert(exception != (ExceptionInfo *) NULL);
492  if (argc == 2)
493    {
494      option=argv[1];
495      if ((LocaleCompare("version",option+1) == 0) ||
496          (LocaleCompare("-version",option+1) == 0))
497        {
498          (void) fprintf(stdout,"Version: %s\n",
499            GetMagickVersion((unsigned long *) NULL));
500          (void) fprintf(stdout,"Copyright: %s\n\n",GetMagickCopyright());
501          return(MagickTrue);
502        }
503    }
504  if (argc < 3)
505    ConvertUsage();
506  filename=(char *) NULL;
507  format="%w,%h,%m";
508  j=1;
509  k=0;
510  NewImageStack();
511  option=(char *) NULL;
512  pend=MagickFalse;
513  status=MagickTrue;
514  /*
515    Parse command-line arguments.
516  */
517  ReadCommandlLine(argc,&argv);
518  status=ExpandFilenames(&argc,&argv);
519  if (status == MagickFalse)
520    ThrowConvertException(ResourceLimitError,"MemoryAllocationFailed",
521      strerror(errno));
522  if ((argc > 2) && (LocaleCompare("-concatenate",argv[1]) == 0))
523    return(ConcatenateImages(argc,argv,exception));
524  for (i=1; i < (long) (argc-1); i++)
525  {
526    option=argv[i];
527    if (LocaleCompare(option,"(") == 0)
528      {
529        FireImageStack(MagickTrue,MagickTrue,pend);
530        if (k == MaxImageStackDepth)
531          ThrowConvertException(OptionError,"ParenthesisNestedTooDeeply",
532            option);
533        PushImageStack();
534        continue;
535      }
536    if (LocaleCompare(option,")") == 0)
537      {
538        FireImageStack(MagickTrue,MagickTrue,MagickTrue);
539        if (k == 0)
540          ThrowConvertException(OptionError,"UnableToParseExpression",option);
541        PopImageStack();
542        continue;
543      }
544    if (IsMagickOption(option) == MagickFalse)
545      {
546        Image
547          *images;
548
549        /*
550          Read input image.
551        */
552        FireImageStack(MagickTrue,MagickTrue,pend);
553        filename=argv[i];
554        if ((LocaleCompare(filename,"--") == 0) && (i < (argc-1)))
555          filename=argv[++i];
556        (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
557        if (image_info->ping != MagickFalse)
558          images=PingImage(image_info,exception);
559        else
560          images=ReadImage(image_info,exception);
561        status&=(images != (Image *) NULL) &&
562          (exception->severity < ErrorException);
563        if (images == (Image *) NULL)
564          continue;
565        AppendImageStack(images);
566        continue;
567      }
568    pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
569    switch (*(option+1))
570    {
571      case 'a':
572      {
573        if (LocaleCompare("adaptive-blur",option+1) == 0)
574          {
575            i++;
576            if (i == (long) (argc-1))
577              ThrowConvertException(OptionError,"MissingArgument",option);
578            if (IsGeometry(argv[i]) == MagickFalse)
579              ThrowConvertInvalidArgumentException(option,argv[i]);
580            break;
581          }
582        if (LocaleCompare("adaptive-resize",option+1) == 0)
583          {
584            i++;
585            if (i == (long) (argc-1))
586              ThrowConvertException(OptionError,"MissingArgument",option);
587            if (IsGeometry(argv[i]) == MagickFalse)
588              ThrowConvertInvalidArgumentException(option,argv[i]);
589            break;
590          }
591        if (LocaleCompare("adaptive-sharpen",option+1) == 0)
592          {
593            i++;
594            if (i == (long) (argc-1))
595              ThrowConvertException(OptionError,"MissingArgument",option);
596            if (IsGeometry(argv[i]) == MagickFalse)
597              ThrowConvertInvalidArgumentException(option,argv[i]);
598            break;
599          }
600        if (LocaleCompare("adjoin",option+1) == 0)
601          break;
602        if (LocaleCompare("affine",option+1) == 0)
603          {
604            if (*option == '+')
605              break;
606            i++;
607            if (i == (long) (argc-1))
608              ThrowConvertException(OptionError,"MissingArgument",option);
609            if (IsGeometry(argv[i]) == MagickFalse)
610              ThrowConvertInvalidArgumentException(option,argv[i]);
611            break;
612          }
613        if (LocaleCompare("alpha",option+1) == 0)
614          {
615            long
616              type;
617
618            if (*option == '+')
619              break;
620            i++;
621            if (i == (long) argc)
622              ThrowConvertException(OptionError,"MissingArgument",option);
623            type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
624            if (type < 0)
625              ThrowConvertException(OptionError,"UnrecognizedAlphaChannelType",
626                argv[i]);
627            break;
628          }
629        if (LocaleCompare("annotate",option+1) == 0)
630          {
631            if (*option == '+')
632              break;
633            i++;
634            if (i == (long) (argc-1))
635              ThrowConvertException(OptionError,"MissingArgument",option);
636            if (IsGeometry(argv[i]) == MagickFalse)
637              ThrowConvertInvalidArgumentException(option,argv[i]);
638            if (i == (long) (argc-1))
639              ThrowConvertException(OptionError,"MissingArgument",option);
640            i++;
641            break;
642          }
643        if (LocaleCompare("antialias",option+1) == 0)
644          break;
645        if (LocaleCompare("append",option+1) == 0)
646          break;
647        if (LocaleCompare("authenticate",option+1) == 0)
648          {
649            if (*option == '+')
650              break;
651            i++;
652            if (i == (long) (argc-1))
653              ThrowConvertException(OptionError,"MissingArgument",option);
654            break;
655          }
656        if (LocaleCompare("auto-orient",option+1) == 0)
657          break;
658        if (LocaleCompare("average",option+1) == 0)
659          break;
660        ThrowConvertException(OptionError,"UnrecognizedOption",option)
661      }
662      case 'b':
663      {
664        if (LocaleCompare("background",option+1) == 0)
665          {
666            if (*option == '+')
667              break;
668            i++;
669            if (i == (long) (argc-1))
670              ThrowConvertException(OptionError,"MissingArgument",option);
671            break;
672          }
673        if (LocaleCompare("bench",option+1) == 0)
674          {
675            if (*option == '+')
676              break;
677            i++;
678            if (i == (long) (argc-1))
679              ThrowConvertException(OptionError,"MissingArgument",option);
680            if (IsGeometry(argv[i]) == MagickFalse)
681              ThrowConvertInvalidArgumentException(option,argv[i]);
682            break;
683          }
684        if (LocaleCompare("bias",option+1) == 0)
685          {
686            if (*option == '+')
687              break;
688            i++;
689            if (i == (long) (argc-1))
690              ThrowConvertException(OptionError,"MissingArgument",option);
691            if (IsGeometry(argv[i]) == MagickFalse)
692              ThrowConvertInvalidArgumentException(option,argv[i]);
693            break;
694          }
695        if (LocaleCompare("black-point-compensation",option+1) == 0)
696          break;
697        if (LocaleCompare("black-threshold",option+1) == 0)
698          {
699            if (*option == '+')
700              break;
701            i++;
702            if (i == (long) (argc-1))
703              ThrowConvertException(OptionError,"MissingArgument",option);
704            if (IsGeometry(argv[i]) == MagickFalse)
705              ThrowConvertInvalidArgumentException(option,argv[i]);
706            break;
707          }
708        if (LocaleCompare("blue-primary",option+1) == 0)
709          {
710            if (*option == '+')
711              break;
712            i++;
713            if (i == (long) (argc-1))
714              ThrowConvertException(OptionError,"MissingArgument",option);
715            if (IsGeometry(argv[i]) == MagickFalse)
716              ThrowConvertInvalidArgumentException(option,argv[i]);
717            break;
718          }
719        if (LocaleCompare("blur",option+1) == 0)
720          {
721            if (*option == '+')
722              break;
723            i++;
724            if (i == (long) (argc-1))
725              ThrowConvertException(OptionError,"MissingArgument",option);
726            if (IsGeometry(argv[i]) == MagickFalse)
727              ThrowConvertInvalidArgumentException(option,argv[i]);
728            break;
729          }
730        if (LocaleCompare("border",option+1) == 0)
731          {
732            if (*option == '+')
733              break;
734            i++;
735            if (i == (long) (argc-1))
736              ThrowConvertException(OptionError,"MissingArgument",option);
737            if (IsGeometry(argv[i]) == MagickFalse)
738              ThrowConvertInvalidArgumentException(option,argv[i]);
739            break;
740          }
741        if (LocaleCompare("bordercolor",option+1) == 0)
742          {
743            if (*option == '+')
744              break;
745            i++;
746            if (i == (long) (argc-1))
747              ThrowConvertException(OptionError,"MissingArgument",option);
748            break;
749          }
750        if (LocaleCompare("box",option+1) == 0)
751          {
752            if (*option == '+')
753              break;
754            i++;
755            if (i == (long) (argc-1))
756              ThrowConvertException(OptionError,"MissingArgument",option);
757            break;
758          }
759        ThrowConvertException(OptionError,"UnrecognizedOption",option)
760      }
761      case 'c':
762      {
763        if (LocaleCompare("cache",option+1) == 0)
764          {
765            if (*option == '+')
766              break;
767            i++;
768            if (i == (long) (argc-1))
769              ThrowConvertException(OptionError,"MissingArgument",option);
770            if (IsGeometry(argv[i]) == MagickFalse)
771              ThrowConvertInvalidArgumentException(option,argv[i]);
772            break;
773          }
774        if (LocaleCompare("caption",option+1) == 0)
775          {
776            if (*option == '+')
777              break;
778            i++;
779            if (i == (long) argc)
780              ThrowConvertException(OptionError,"MissingArgument",option);
781            break;
782          }
783        if (LocaleCompare("channel",option+1) == 0)
784          {
785            long
786              channel;
787
788            if (*option == '+')
789              break;
790            i++;
791            if (i == (long) (argc-1))
792              ThrowConvertException(OptionError,"MissingArgument",option);
793            channel=ParseChannelOption(argv[i]);
794            if (channel < 0)
795              ThrowConvertException(OptionError,"UnrecognizedChannelType",
796                argv[i]);
797            break;
798          }
799        if (LocaleCompare("charcoal",option+1) == 0)
800          {
801            if (*option == '+')
802              break;
803            i++;
804            if (i == (long) (argc-1))
805              ThrowConvertException(OptionError,"MissingArgument",option);
806            if (IsGeometry(argv[i]) == MagickFalse)
807              ThrowConvertInvalidArgumentException(option,argv[i]);
808            break;
809          }
810        if (LocaleCompare("chop",option+1) == 0)
811          {
812            if (*option == '+')
813              break;
814            i++;
815            if (i == (long) (argc-1))
816              ThrowConvertException(OptionError,"MissingArgument",option);
817            if (IsGeometry(argv[i]) == MagickFalse)
818              ThrowConvertInvalidArgumentException(option,argv[i]);
819            break;
820          }
821        if (LocaleCompare("clip",option+1) == 0)
822          break;
823        if (LocaleCompare("clip-mask",option+1) == 0)
824          {
825            if (*option == '+')
826              break;
827            i++;
828            if (i == (long) (argc-1))
829              ThrowConvertException(OptionError,"MissingArgument",option);
830            break;
831          }
832        if (LocaleCompare("clip-path",option+1) == 0)
833          {
834            i++;
835            if (i == (long) (argc-1))
836              ThrowConvertException(OptionError,"MissingArgument",option);
837            break;
838          }
839        if (LocaleCompare("clone",option+1) == 0)
840          {
841            Image
842              *clone_images;
843
844            clone_images=image;
845            if (k != 0)
846              clone_images=image_stack[k-1].image;
847            if (clone_images == (Image *) NULL)
848              ThrowConvertException(ImageError,"ImageSequenceRequired",option);
849            if (*option == '+')
850              clone_images=CloneImages(clone_images,"-1",exception);
851            else
852              {
853                i++;
854                if (i == (long) (argc-1))
855                  ThrowConvertException(OptionError,"MissingArgument",option);
856                if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
857                  ThrowConvertInvalidArgumentException(option,argv[i]);
858                clone_images=CloneImages(clone_images,argv[i],exception);
859              }
860            if (clone_images == (Image *) NULL)
861              ThrowConvertException(OptionError,"NoSuchImage",option);
862            FireImageStack(MagickTrue,MagickTrue,MagickTrue);
863            AppendImageStack(clone_images);
864            break;
865          }
866        if (LocaleCompare("clut",option+1) == 0)
867          break;
868        if (LocaleCompare("coalesce",option+1) == 0)
869          break;
870        if (LocaleCompare("colorize",option+1) == 0)
871          {
872            if (*option == '+')
873              break;
874            i++;
875            if (i == (long) (argc-1))
876              ThrowConvertException(OptionError,"MissingArgument",option);
877            if (IsGeometry(argv[i]) == MagickFalse)
878              ThrowConvertInvalidArgumentException(option,argv[i]);
879            break;
880          }
881        if (LocaleCompare("colors",option+1) == 0)
882          {
883            if (*option == '+')
884              break;
885            i++;
886            if ((i == (long) (argc-1)) ||
887                (IsGeometry(argv[i]) == MagickFalse))
888              ThrowConvertException(OptionError,"MissingArgument",option);
889            break;