]> granicus.if.org Git - imagemagick/blob - MagickWand/display.c
Added checks for exceptions.
[imagemagick] / MagickWand / display.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %               DDDD   IIIII  SSSSS  PPPP   L       AAA   Y   Y               %
7 %               D   D    I    SS     P   P  L      A   A   Y Y                %
8 %               D   D    I     SSS   PPPP   L      AAAAA    Y                 %
9 %               D   D    I       SS  P      L      A   A    Y                 %
10 %               DDDD   IIIII  SSSSS  P      LLLLL  A   A    Y                 %
11 %                                                                             %
12 %                                                                             %
13 %              Methods to Interactively Display and Edit an Image             %
14 %                                                                             %
15 %                             Software Design                                 %
16 %                                  Cristy                                     %
17 %                                July 1992                                    %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2014 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 %  Use the display program to display an image or image sequence on any X
37 %  server.
38 %
39 */
40 \f
41 /*
42   Include declarations.
43 */
44 #include "MagickWand/studio.h"
45 #include "MagickWand/MagickWand.h"
46 #include "MagickWand/mogrify-private.h"
47 #include "MagickCore/display-private.h"
48 #include "MagickCore/string-private.h"
49 \f
50 /*
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %                                                                             %
53 %                                                                             %
54 %                                                                             %
55 +   D i s p l a y I m a g e C o m m a n d                                     %
56 %                                                                             %
57 %                                                                             %
58 %                                                                             %
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %
61 %  DisplayImageCommand() displays a sequence of images on any workstation
62 %  display running an X server.  Display first determines the hardware
63 %  capabilities of the workstation. If the number of unique colors in an image
64 %  is less than or equal to the number the workstation can support, the image
65 %  is displayed in an X window. Otherwise the number of colors in the image is
66 %  first reduced to match the color resolution of the workstation before it is
67 %  displayed.
68 %
69 %  This means that a continuous-tone 24 bits/pixel image can display on a 8
70 %  bit pseudo-color device or monochrome device. In most instances the reduced
71 %  color image closely resembles the original. Alternatively, a monochrome or
72 %  pseudo-color image sequence can display on a continuous-tone 24 bits/pixels
73 %  device.
74 %
75 %  The format of the DisplayImageCommand method is:
76 %
77 %      MagickBooleanType DisplayImageCommand(ImageInfo *image_info,int argc,
78 %        char **argv,char **metadata,ExceptionInfo *exception)
79 %
80 %  A description of each parameter follows:
81 %
82 %    o image_info: the image info.
83 %
84 %    o argc: the number of elements in the argument vector.
85 %
86 %    o argv: A text array containing the command line arguments.
87 %
88 %    o metadata: any metadata is returned here.
89 %
90 %    o exception: return any errors or warnings in this structure.
91 %
92 */
93
94 static MagickBooleanType DisplayUsage(void)
95 {
96   const char
97     **p;
98
99   static const char
100     *buttons[]=
101     {
102       "1    press to map or unmap the Command widget",
103       "2    press and drag to magnify a region of an image",
104       "3    press to load an image from a visual image directory",
105       (char *) NULL
106     },
107     *miscellaneous[]=
108     {
109       "-debug events        display copious debugging information",
110       "-help                print program options",
111       "-list type           print a list of supported option arguments",
112       "-log format          format of debugging information",
113       "-version             print version information",
114       (char *) NULL
115     },
116     *operators[]=
117     {
118       "-auto-orient         automagically orient image",
119       "-border geometry     surround image with a border of color",
120       "-clip                clip along the first path from the 8BIM profile",
121       "-clip-path id        clip along a named path from the 8BIM profile",
122       "-colors value        preferred number of colors in the image",
123       "-contrast            enhance or reduce the image contrast",
124       "-crop geometry       preferred size and location of the cropped image",
125       "-decipher filename   convert cipher pixels to plain pixels",
126       "-deskew threshold    straighten an image",
127       "-despeckle           reduce the speckles within an image",
128       "-edge factor         apply a filter to detect edges in the image",
129       "-enhance             apply a digital filter to enhance a noisy image",
130       "-equalize            perform histogram equalization to an image",
131       "-extract geometry    extract area from image",
132       "-flip                flip image in the vertical direction",
133       "-flop                flop image in the horizontal direction",
134       "-frame geometry      surround image with an ornamental border",
135       "-fuzz distance       colors within this distance are considered equal",
136       "-gamma value         level of gamma correction",
137       "-monochrome          transform image to black and white",
138       "-negate              replace every pixel with its complementary color",
139       "-normalize           transform image to span the full range of colors",
140       "-raise value         lighten/darken image edges to create a 3-D effect",
141       "-resample geometry   change the resolution of an image",
142       "-resize geometry     resize the image",
143       "-roll geometry       roll an image vertically or horizontally",
144       "-rotate degrees      apply Paeth rotation to the image",
145       "-sample geometry     scale image with pixel sampling",
146       "-segment value       segment an image",
147       "-sharpen geometry    sharpen the image",
148       "-strip               strip image of all profiles and comments",
149       "-threshold value     threshold the image",
150       "-thumbnail geometry  create a thumbnail of the image",
151       "-trim                trim image edges",
152       (char *) NULL
153     },
154     *settings[]=
155     {
156       "-alpha option        on, activate, off, deactivate, set, opaque, copy",
157       "                     transparent, extract, background, or shape",
158       "-antialias           remove pixel-aliasing",
159       "-authenticate password",
160       "                     decipher image with this password",
161       "-backdrop            display image centered on a backdrop",
162       "-channel type        apply option to select image channels",
163       "-colormap type       Shared or Private",
164       "-colorspace type     alternate image colorspace",
165       "-comment string      annotate image with comment",
166       "-compress type       type of pixel compression when writing the image",
167       "-define format:option",
168       "                     define one or more image format options",
169       "-delay value         display the next image after pausing",
170       "-density geometry    horizontal and vertical density of the image",
171       "-depth value         image depth",
172       "-display server      display image to this X server",
173       "-dispose method      layer disposal method",
174       "-dither method       apply error diffusion to image",
175       "-endian type         endianness (MSB or LSB) of the image",
176       "-filter type         use this filter when resizing an image",
177       "-format string     output formatted image characteristics",
178       "-geometry geometry   preferred size and location of the Image window",
179       "-gravity type        horizontal and vertical backdrop placement",
180       "-identify            identify the format and characteristics of the image",
181       "-immutable           displayed image cannot be modified",
182       "-interlace type      type of image interlacing scheme",
183       "-interpolate method  pixel color interpolation method",
184       "-label string        assign a label to an image",
185       "-limit type value    pixel cache resource limit",
186       "-loop iterations     loop images then exit",
187       "-map type            display image using this Standard Colormap",
188       "-matte               store matte channel if the image has one",
189       "-monitor             monitor progress",
190       "-page geometry       size and location of an image canvas",
191       "-profile filename    add, delete, or apply an image profile",
192       "-quality value       JPEG/MIFF/PNG compression level",
193       "-quantize colorspace reduce colors in this colorspace",
194       "-quiet               suppress all warning messages",
195       "-regard-warnings     pay attention to warning messages",
196       "-remote command      execute a command in an remote display process",
197       "-repage geometry     size and location of an image canvas (operator)",
198       "-respect-parentheses settings remain in effect until parenthesis boundary",
199       "-sampling-factor geometry",
200       "                     horizontal and vertical sampling factor",
201       "-scenes range        image scene range",
202       "-seed value          seed a new sequence of pseudo-random numbers",
203       "-set property value  set an image property",
204       "-size geometry       width and height of image",
205       "-support factor      resize support: > 1.0 is blurry, < 1.0 is sharp",
206       "-texture filename    name of texture to tile onto the image background",
207       "-transparent-color color",
208       "                     transparent color",
209       "-treedepth value     color tree depth",
210       "-update seconds      detect when image file is modified and redisplay",
211       "-verbose             print detailed information about the image",
212       "-visual type         display image using this visual type",
213       "-virtual-pixel method",
214       "                     virtual pixel access method",
215       "-window id           display image to background of this window",
216       "-window-group id     exit program when this window id is destroyed",
217       "-write filename      write image to a file",
218       (char *) NULL
219     },
220     *sequence_operators[]=
221     {
222       "-coalesce            merge a sequence of images",
223       "-flatten             flatten a sequence of images",
224       (char *) NULL
225     };
226
227   ListMagickVersion(stdout);
228   (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
229     GetClientName());
230   (void) printf("\nImage Settings:\n");
231   for (p=settings; *p != (char *) NULL; p++)
232     (void) printf("  %s\n",*p);
233   (void) printf("\nImage Operators:\n");
234   for (p=operators; *p != (char *) NULL; p++)
235     (void) printf("  %s\n",*p);
236   (void) printf("\nImage Sequence Operators:\n");
237   for (p=sequence_operators; *p != (char *) NULL; p++)
238     (void) printf("  %s\n",*p);
239   (void) printf("\nMiscellaneous Options:\n");
240   for (p=miscellaneous; *p != (char *) NULL; p++)
241     (void) printf("  %s\n",*p);
242   (void) printf(
243     "\nIn addition to those listed above, you can specify these standard X\n");
244   (void) printf(
245     "resources as command line options:  -background, -bordercolor,\n");
246   (void) printf(
247     "-borderwidth, -font, -foreground, -iconGeometry, -iconic, -mattecolor,\n");
248   (void) printf("-name, -shared-memory, -usePixmap, or -title.\n");
249   (void) printf(
250     "\nBy default, the image format of 'file' is determined by its magic\n");
251   (void) printf(
252     "number.  To specify a particular image format, precede the filename\n");
253   (void) printf(
254     "with an image format name and a colon (i.e. ps:image) or specify the\n");
255   (void) printf(
256     "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
257   (void) printf("'-' for standard input or output.\n");
258   (void) printf("\nButtons: \n");
259   for (p=buttons; *p != (char *) NULL; p++)
260     (void) printf("  %s\n",*p);
261   return(MagickFalse);
262 }
263
264 WandExport MagickBooleanType DisplayImageCommand(ImageInfo *image_info,
265   int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
266 {
267 #if defined(MAGICKCORE_X11_DELEGATE)
268 #define DestroyDisplay() \
269 { \
270   if ((state & ExitState) == 0) \
271     DestroyXResources(); \
272   if (display != (Display *) NULL) \
273     { \
274       XCloseDisplay(display); \
275       display=(Display *) NULL; \
276     } \
277   XDestroyResourceInfo(&resource_info); \
278   DestroyImageStack(); \
279   if (image_marker != (size_t *) NULL) \
280     image_marker=(size_t *) RelinquishMagickMemory(image_marker); \
281   for (i=0; i < (ssize_t) argc; i++) \
282     argv[i]=DestroyString(argv[i]); \
283   argv=(char **) RelinquishMagickMemory(argv); \
284 }
285 #define ThrowDisplayException(asperity,tag,option) \
286 { \
287   (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
288     option); \
289   DestroyDisplay(); \
290   return(MagickFalse); \
291 }
292 #define ThrowDisplayInvalidArgumentException(option,argument) \
293 { \
294   (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
295     "InvalidArgument","'%s': %s",option,argument); \
296   DestroyDisplay(); \
297   return(MagickFalse); \
298 }
299
300   char
301     *resource_value,
302     *server_name;
303
304   const char
305     *option;
306
307   Display
308     *display;
309
310   Image
311     *image;
312
313   ImageStack
314     image_stack[MaxImageStackDepth+1];
315
316   MagickBooleanType
317     fire,
318     pend,
319     respect_parenthesis;
320
321   MagickStatusType
322     status;
323
324   QuantizeInfo
325     *quantize_info;
326
327   register ssize_t
328     i;
329
330   size_t
331     *image_marker,
332     iterations,
333     last_image,
334     state;
335
336   ssize_t
337     image_number,
338     iteration,
339     j,
340     k,
341     l;
342
343   XResourceInfo
344     resource_info;
345
346   XrmDatabase
347     resource_database;
348
349   /*
350     Set defaults.
351   */
352   assert(image_info != (ImageInfo *) NULL);
353   assert(image_info->signature == MagickSignature);
354   if (image_info->debug != MagickFalse)
355     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
356   assert(exception != (ExceptionInfo *) NULL);
357   if (argc == 2)
358     {
359       option=argv[1];
360       if ((LocaleCompare("version",option+1) == 0) ||
361           (LocaleCompare("-version",option+1) == 0))
362         {
363           ListMagickVersion(stdout);
364           return(MagickFalse);
365         }
366     }
367   SetNotifyHandlers;
368   display=(Display *) NULL;
369   j=1;
370   k=0;
371   image_marker=(size_t *) NULL;
372   image_number=0;
373   last_image=0;
374   NewImageStack();
375   option=(char *) NULL;
376   pend=MagickFalse;
377   respect_parenthesis=MagickFalse;
378   resource_database=(XrmDatabase) NULL;
379   (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info));
380   server_name=(char *) NULL;
381   state=0;
382   status=MagickTrue;
383   ReadCommandlLine(argc,&argv);
384   status=ExpandFilenames(&argc,&argv);
385   if (status == MagickFalse)
386     ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
387       GetExceptionMessage(errno));
388   image_marker=(size_t *) AcquireQuantumMemory((size_t) argc+1UL,
389     sizeof(*image_marker));
390   if (image_marker == (size_t *) NULL)
391     ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
392       GetExceptionMessage(errno));
393   for (i=0; i <= (ssize_t) argc; i++)
394     image_marker[i]=(size_t) argc;
395   /*
396     Check for server name specified on the command line.
397   */
398   for (i=1; i < (ssize_t) argc; i++)
399   {
400     /*
401       Check command line for server name.
402     */
403     option=argv[i];
404     if (LocaleCompare("display",option+1) == 0)
405       {
406         /*
407           User specified server name.
408         */
409         i++;
410         if (i == (ssize_t) argc)
411           ThrowDisplayException(OptionError,"MissingArgument",option);
412         server_name=argv[i];
413       }
414     if ((LocaleCompare("help",option+1) == 0) ||
415         (LocaleCompare("-help",option+1) == 0))
416       return(DisplayUsage());
417   }
418   /*
419     Get user defaults from X resource database.
420   */
421   display=XOpenDisplay(server_name);
422   if (display == (Display *) NULL)
423     ThrowDisplayException(XServerError,"UnableToOpenXServer",
424       XDisplayName(server_name));
425   (void) XSetErrorHandler(XError);
426   resource_database=XGetResourceDatabase(display,GetClientName());
427   XGetResourceInfo(image_info,resource_database,GetClientName(),
428     &resource_info);
429   quantize_info=resource_info.quantize_info;
430   image_info->density=XGetResourceInstance(resource_database,GetClientName(),
431     "density",(char *) NULL);
432   if (image_info->density == (char *) NULL)
433     image_info->density=XGetScreenDensity(display);
434   resource_value=XGetResourceInstance(resource_database,GetClientName(),
435     "interlace","none");
436   image_info->interlace=(InterlaceType)
437     ParseCommandOption(MagickInterlaceOptions,MagickFalse,resource_value);
438   image_info->page=XGetResourceInstance(resource_database,GetClientName(),
439     "pageGeometry",(char *) NULL);
440   resource_value=XGetResourceInstance(resource_database,GetClientName(),
441     "quality","75");
442   image_info->quality=StringToUnsignedLong(resource_value);
443   resource_value=XGetResourceInstance(resource_database,GetClientName(),
444     "verbose","False");
445   image_info->verbose=IsStringTrue(resource_value);
446   resource_value=XGetResourceInstance(resource_database,GetClientName(),
447     "dither","True");
448   quantize_info->dither_method=IsStringTrue(resource_value) != MagickFalse ?
449     RiemersmaDitherMethod : NoDitherMethod;
450   /*
451     Parse command line.
452   */
453   iteration=0;
454   for (i=1; ((i <= (ssize_t) argc) && ((state & ExitState) == 0)); i++)
455   {
456     if (i < (ssize_t) argc)
457       option=argv[i];
458     else
459       if (image != (Image *) NULL)
460         break;
461       else
462         if (isatty(STDIN_FILENO) != MagickFalse)
463           option="logo:";
464         else
465           {
466             int
467               c;
468
469             c=getc(stdin);
470             if (c == EOF)
471               option="logo:";
472             else
473               {
474                 c=ungetc(c,stdin);
475                 option="-";
476               }
477           }
478     if (LocaleCompare(option,"(") == 0)
479       {
480         FireImageStack(MagickFalse,MagickTrue,pend);
481         if (k == MaxImageStackDepth)
482           ThrowDisplayException(OptionError,"ParenthesisNestedTooDeeply",
483             option);
484         PushImageStack();
485         continue;
486       }
487     if (LocaleCompare(option,")") == 0)
488       {
489         FireImageStack(MagickFalse,MagickTrue,MagickTrue);
490         if (k == 0)
491           ThrowDisplayException(OptionError,"UnableToParseExpression",option);
492         PopImageStack();
493         continue;
494       }
495     if (IsCommandOption(option) == MagickFalse)
496       {
497         const char
498           *filename;
499
500         Image
501           *display_image,
502           *image_list,
503           *images;
504
505         /*
506           Option is a file name.
507         */
508         FireImageStack(MagickFalse,MagickFalse,pend);
509         filename=option;
510         if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
511           {
512             option=argv[++i];
513             filename=option;
514           }
515         (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
516         images=ReadImage(image_info,exception);
517         CatchException(exception);
518         status&=(images != (Image *) NULL) &&
519           (exception->severity < ErrorException);
520         if (images == (Image *) NULL)
521           continue;
522         AppendImageStack(images);
523         FinalizeImageSettings(image_info,image,MagickFalse);
524         iterations=0;
525         if (i == (ssize_t) argc)
526           iterations=image->iterations;
527         image_list=CloneImageList(image,exception);
528         if (image_list == (Image *) NULL)
529           ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
530             GetExceptionMessage(errno));
531         display_image=image_list;
532         do
533         {
534           /*
535             Transmogrify image as defined by the image processing options.
536           */
537           resource_info.quantum=1;
538           if (resource_info.window_id != (char *) NULL)
539             {
540               /*
541                 Display image to a specified X window.
542               */
543               status=XDisplayBackgroundImage(display,&resource_info,
544                 display_image,exception);
545               if (status != MagickFalse)
546                 {
547                   state|=RetainColorsState;
548                   status=MagickFalse;
549                 }
550               if (GetNextImageInList(display_image) == (Image *) NULL)
551                 state|=ExitState;
552             }
553           else
554             do
555             {
556               Image
557                 *nexus;
558
559               /*
560                 Display image to X server.
561               */
562               if (resource_info.delay != 1)
563                 display_image->delay=resource_info.delay;
564               nexus=XDisplayImage(display,&resource_info,argv,argc,
565                 &display_image,&state,exception);
566               status&=nexus != (Image *) NULL;
567               if (nexus == (Image *) NULL)
568                 break;
569               while ((nexus != (Image *) NULL) && ((state & ExitState) == 0))
570               {
571                 Image
572                   *next;
573
574                 if (nexus->montage != (char *) NULL)
575                   {
576                     /*
577                       User selected a visual directory image (montage).
578                     */
579                     display_image=nexus;
580                     break;
581                   }
582                 next=XDisplayImage(display,&resource_info,argv,argc,&nexus,
583                   &state,exception);
584                 if ((next == (Image *) NULL) &&
585                     (GetNextImageInList(nexus) != (Image *) NULL))
586                   {
587                     display_image=GetNextImageInList(nexus);
588                     nexus=NewImageList();
589                   }
590                 else
591                   {
592                     if (nexus != display_image)
593                       nexus=DestroyImageList(nexus);
594                     nexus=next;
595                   }
596               }
597             } while ((state & ExitState) == 0);
598           if (resource_info.write_filename != (char *) NULL)
599             {
600               /*
601                 Write image.
602               */
603               (void) CopyMagickString(display_image->filename,
604                 resource_info.write_filename,MaxTextExtent);
605               (void) SetImageInfo(image_info,1,exception);
606               status&=WriteImage(image_info,display_image,exception);
607             }
608           /*
609             Proceed to next/previous image.
610           */
611           if ((state & FormerImageState) != 0)
612             for (l=0; l < (ssize_t) resource_info.quantum; l++)
613             {
614               if (GetPreviousImageInList(display_image) == (Image *) NULL)
615                 break;
616               display_image=GetPreviousImageInList(display_image);
617             }
618           else
619             for (l=0; l < (ssize_t) resource_info.quantum; l++)
620             {
621               if (GetNextImageInList(display_image) == (Image *) NULL)
622                 break;
623               display_image=GetNextImageInList(display_image);
624             }
625           if (l < (ssize_t) resource_info.quantum)
626             break;
627         } while ((display_image != (Image *) NULL) && ((state & ExitState) == 0));
628         /*
629           Free image resources.
630         */
631         display_image=DestroyImageList(display_image);
632         if ((state & FormerImageState) == 0)
633           {
634             last_image=(size_t) image_number;
635             image_marker[i]=(size_t) image_number++;
636           }
637         else
638           {
639             /*
640               Proceed to previous image.
641             */
642             for (i--; i > 0; i--)
643               if (image_marker[i] == (size_t) (image_number-2))
644                 break;
645             image_number--;
646           }
647         if ((i == (ssize_t) argc) && ((state & ExitState) == 0))
648           i=0;
649         if ((state & ExitState) != 0)
650           break;
651         /*
652           Determine if we should proceed to the first image.
653         */
654         if (image_number < 0)
655           {
656             if ((state & FormerImageState) != 0)
657               {
658
659                 for (i=1; i < (ssize_t) (argc-2); i++)
660                   if (last_image == image_marker[i])
661                     break;
662                 image_number=(ssize_t) image_marker[i]+1;
663               }
664             continue;
665           }
666         if (resource_info.window_id != (char *) NULL)
667           state|=ExitState;
668         if ((iterations != 0) && (++iteration == (ssize_t) iterations))
669           state|=ExitState;
670         if (LocaleCompare(filename,"-") == 0)
671           state|=ExitState;
672         RemoveAllImageStack();
673         continue;
674       }
675     pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
676     switch (*(option+1))
677     {
678       case 'a':
679       {
680         if (LocaleCompare("alpha",option+1) == 0)
681           {
682             ssize_t
683               type;
684
685             if (*option == '+')
686               break;
687             i++;
688             if (i == (ssize_t) argc)
689               ThrowDisplayException(OptionError,"MissingArgument",option);
690             type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
691             if (type < 0)
692               ThrowDisplayException(OptionError,"UnrecognizedAlphaChannelOption",
693                 argv[i]);
694             break;
695           }
696         if (LocaleCompare("antialias",option+1) == 0)
697           break;
698         if (LocaleCompare("authenticate",option+1) == 0)
699           {
700             if (*option == '+')
701               break;
702             i++;
703             if (i == (ssize_t) argc)
704               ThrowDisplayException(OptionError,"MissingArgument",option);
705             break;
706           }
707         if (LocaleCompare("auto-orient",option+1) == 0)
708           break;
709         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
710       }
711       case 'b':
712       {
713         if (LocaleCompare("backdrop",option+1) == 0)
714           {
715             resource_info.backdrop=(*option == '-') ? MagickTrue : MagickFalse;
716             break;
717           }
718         if (LocaleCompare("background",option+1) == 0)
719           {
720             if (*option == '+')
721               break;
722             i++;
723             if (i == (ssize_t) argc)
724               ThrowDisplayException(OptionError,"MissingArgument",option);
725             resource_info.background_color=argv[i];
726             break;
727           }
728         if (LocaleCompare("border",option+1) == 0)
729           {
730             if (*option == '+')
731               break;
732             i++;
733             if (i == (ssize_t) argc)
734               ThrowDisplayException(OptionError,"MissingArgument",option);
735             if (IsGeometry(argv[i]) == MagickFalse)
736               ThrowDisplayInvalidArgumentException(option,argv[i]);
737             break;
738           }
739         if (LocaleCompare("bordercolor",option+1) == 0)
740           {
741             if (*option == '+')
742               break;
743             i++;
744             if (i == (ssize_t) argc)
745               ThrowDisplayException(OptionError,"MissingArgument",option);
746             resource_info.border_color=argv[i];
747             break;
748           }
749         if (LocaleCompare("borderwidth",option+1) == 0)
750           {
751             resource_info.border_width=0;
752             if (*option == '+')
753               break;
754             i++;
755             if (i == (ssize_t) argc)
756               ThrowDisplayException(OptionError,"MissingArgument",option);
757             if (IsGeometry(argv[i]) == MagickFalse)
758               ThrowDisplayInvalidArgumentException(option,argv[i]);
759             resource_info.border_width=(unsigned int)
760               StringToUnsignedLong(argv[i]);
761             break;
762           }
763         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
764       }
765       case 'c':
766       {
767         if (LocaleCompare("cache",option+1) == 0)
768           {
769             if (*option == '+')
770               break;
771             i++;
772             if (i == (ssize_t) argc)
773               ThrowDisplayException(OptionError,"MissingArgument",option);
774             if (IsGeometry(argv[i]) == MagickFalse)
775               ThrowDisplayInvalidArgumentException(option,argv[i]);
776             break;
777           }
778         if (LocaleCompare("channel",option+1) == 0)
779           {
780             ssize_t
781               channel;
782
783             if (*option == '+')
784               break;
785             i++;
786             if (i == (ssize_t) argc)
787               ThrowDisplayException(OptionError,"MissingArgument",option);
788             channel=ParseChannelOption(argv[i]);
789             if (channel < 0)
790               ThrowDisplayException(OptionError,"UnrecognizedChannelType",
791                 argv[i]);
792             break;
793           }
794         if (LocaleCompare("clip",option+1) == 0)
795           break;
796         if (LocaleCompare("clip-path",option+1) == 0)
797           {
798             i++;
799             if (i == (ssize_t) argc)
800               ThrowDisplayException(OptionError,"MissingArgument",option);
801             break;
802           }
803         if (LocaleCompare("coalesce",option+1) == 0)
804           break;
805         if (LocaleCompare("colormap",option+1) == 0)
806           {
807             resource_info.colormap=PrivateColormap;
808             if (*option == '+')
809               break;
810             i++;
811             if (i == (ssize_t) argc)
812               ThrowDisplayException(OptionError,"MissingArgument",option);
813             resource_info.colormap=UndefinedColormap;
814             if (LocaleCompare("private",argv[i]) == 0)
815               resource_info.colormap=PrivateColormap;
816             if (LocaleCompare("shared",argv[i]) == 0)
817               resource_info.colormap=SharedColormap;
818             if (resource_info.colormap == UndefinedColormap)
819               ThrowDisplayException(OptionError,"UnrecognizedColormapType",
820                 argv[i]);
821             break;
822           }
823         if (LocaleCompare("colors",option+1) == 0)
824           {
825             quantize_info->number_colors=0;
826             if (*option == '+')
827               break;
828             i++;
829             if (i == (ssize_t) argc)
830               ThrowDisplayException(OptionError,"MissingArgument",option);
831             if (IsGeometry(argv[i]) == MagickFalse)
832               ThrowDisplayInvalidArgumentException(option,argv[i]);
833             quantize_info->number_colors=StringToUnsignedLong(argv[i]);
834             break;
835           }
836         if (LocaleCompare("colorspace",option+1) == 0)
837           {
838             ssize_t
839               colorspace;
840
841             if (*option == '+')
842               break;
843             i++;
844             if (i == (ssize_t) argc)
845               ThrowDisplayException(OptionError,"MissingArgument",option);
846             colorspace=ParseCommandOption(MagickColorspaceOptions,
847               MagickFalse,argv[i]);
848             if (colorspace < 0)
849               ThrowDisplayException(OptionError,"UnrecognizedColorspace",
850                 argv[i]);
851             break;
852           }
853         if (LocaleCompare("comment",option+1) == 0)
854           {
855             if (*option == '+')
856               break;
857             i++;
858             if (i == (ssize_t) argc)
859               ThrowDisplayException(OptionError,"MissingArgument",option);
860             break;
861           }
862         if (LocaleCompare("compress",option+1) == 0)
863           {
864             ssize_t
865               compress;
866
867             if (*option == '+')
868               break;
869             i++;
870             if (i == (ssize_t) argc)
871               ThrowDisplayException(OptionError,"MissingArgument",option);
872             compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
873               argv[i]);
874             if (compress < 0)
875               ThrowDisplayException(OptionError,"UnrecognizedImageCompression",
876                 argv[i]);
877             break;
878           }
879         if (LocaleCompare("concurrent",option+1) == 0)
880           break;
881         if (LocaleCompare("contrast",option+1) == 0)
882           break;
883         if (LocaleCompare("crop",option+1) == 0)
884           {
885             if (*option == '+')
886               break;
887             i++;
888             if (i == (ssize_t) argc)
889               ThrowDisplayException(OptionError,"MissingArgument",option);
890             if (IsGeometry(argv[i]) == MagickFalse)
891               ThrowDisplayInvalidArgumentException(option,argv[i]);
892             break;
893           }
894         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
895       }
896       case 'd':
897       {
898         if (LocaleCompare("debug",option+1) == 0)
899           {
900             ssize_t
901               event;
902
903             if (*option == '+')
904               break;
905             i++;
906             if (i == (ssize_t) argc)
907               ThrowDisplayException(OptionError,"MissingArgument",option);
908             event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
909             if (event < 0)
910               ThrowDisplayException(OptionError,"UnrecognizedEventType",
911                 argv[i]);
912             (void) SetLogEventMask(argv[i]);
913             break;
914           }
915         if (LocaleCompare("decipher",option+1) == 0)
916           {
917             if (*option == '+')
918               break;
919             i++;
920             if (i == (ssize_t) argc)
921               ThrowDisplayException(OptionError,"MissingArgument",option);
922             break;
923           }
924         if (LocaleCompare("define",option+1) == 0)
925           {
926             i++;
927             if (i == (ssize_t) argc)
928               ThrowDisplayException(OptionError,"MissingArgument",option);
929             if (*option == '+')
930               {
931                 const char
932                   *define;
933
934                 define=GetImageOption(image_info,argv[i]);
935                 if (define == (const char *) NULL)
936                   ThrowDisplayException(OptionError,"NoSuchOption",argv[i]);
937                 break;
938               }
939             break;
940           }
941         if (LocaleCompare("delay",option+1) == 0)
942           {
943             if (*option == '+')
944               break;
945             i++;
946             if (i == (ssize_t) argc)
947               ThrowDisplayException(OptionError,"MissingArgument",option);
948             if (IsGeometry(argv[i]) == MagickFalse)
949               ThrowDisplayInvalidArgumentException(option,argv[i]);
950             break;
951           }
952         if (LocaleCompare("density",option+1) == 0)
953           {
954             if (*option == '+')
955               break;
956             i++;
957             if (i == (ssize_t) argc)
958               ThrowDisplayException(OptionError,"MissingArgument",option);
959             if (IsGeometry(argv[i]) == MagickFalse)
960               ThrowDisplayInvalidArgumentException(option,argv[i]);
961             break;
962           }
963         if (LocaleCompare("depth",option+1) == 0)
964           {
965             if (*option == '+')
966               break;
967             i++;
968             if (i == (ssize_t) argc)
969               ThrowDisplayException(OptionError,"MissingArgument",option);
970             if (IsGeometry(argv[i]) == MagickFalse)
971               ThrowDisplayInvalidArgumentException(option,argv[i]);
972             break;
973           }
974         if (LocaleCompare("deskew",option+1) == 0)
975           {
976             if (*option == '+')
977               break;
978             i++;
979             if (i == (ssize_t) argc)
980               ThrowDisplayException(OptionError,"MissingArgument",option);
981             if (IsGeometry(argv[i]) == MagickFalse)
982               ThrowDisplayInvalidArgumentException(option,argv[i]);
983             break;
984           }
985         if (LocaleCompare("despeckle",option+1) == 0)
986           break;
987         if (LocaleCompare("display",option+1) == 0)
988           {
989             if (*option == '+')
990               break;
991             i++;
992             if (i == (ssize_t) argc)
993               ThrowDisplayException(OptionError,"MissingArgument",option);
994             break;
995           }
996         if (LocaleCompare("dispose",option+1) == 0)
997           {
998             ssize_t
999               dispose;
1000
1001             if (*option == '+')
1002               break;
1003             i++;
1004             if (i == (ssize_t) argc)
1005               ThrowDisplayException(OptionError,"MissingArgument",option);
1006             dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
1007             if (dispose < 0)
1008               ThrowDisplayException(OptionError,"UnrecognizedDisposeMethod",
1009                 argv[i]);
1010             break;
1011           }
1012         if (LocaleCompare("dither",option+1) == 0)
1013           {
1014             ssize_t
1015               method;
1016
1017             quantize_info->dither_method=NoDitherMethod;
1018             if (*option == '+')
1019               break;
1020             i++;
1021             if (i == (ssize_t) argc)
1022               ThrowDisplayException(OptionError,"MissingArgument",option);
1023             method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
1024             if (method < 0)
1025               ThrowDisplayException(OptionError,"UnrecognizedDitherMethod",
1026                 argv[i]);
1027             quantize_info->dither_method=(DitherMethod) method;
1028             break;
1029           }
1030         if (LocaleCompare("duration",option+1) == 0)
1031           {
1032             if (*option == '+')
1033               break;
1034             i++;
1035             if (i == (ssize_t) argc)
1036               ThrowDisplayException(OptionError,"MissingArgument",option);
1037             if (IsGeometry(argv[i]) == MagickFalse)
1038               ThrowDisplayInvalidArgumentException(option,argv[i]);
1039             break;
1040           }
1041         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1042       }
1043       case 'e':
1044       {
1045         if (LocaleCompare("edge",option+1) == 0)
1046           {
1047             if (*option == '+')
1048               break;
1049             i++;
1050             if (i == (ssize_t) argc)
1051               ThrowDisplayException(OptionError,"MissingArgument",option);
1052             if (IsGeometry(argv[i]) == MagickFalse)
1053               ThrowDisplayInvalidArgumentException(option,argv[i]);
1054             break;
1055           }
1056         if (LocaleCompare("endian",option+1) == 0)
1057           {
1058             ssize_t
1059               endian;
1060
1061             if (*option == '+')
1062               break;
1063             i++;
1064             if (i == (ssize_t) argc)
1065               ThrowDisplayException(OptionError,"MissingArgument",option);
1066             endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
1067               argv[i]);
1068             if (endian < 0)
1069               ThrowDisplayException(OptionError,"UnrecognizedEndianType",
1070                 argv[i]);
1071             break;
1072           }
1073         if (LocaleCompare("enhance",option+1) == 0)
1074           break;
1075         if (LocaleCompare("equalize",option+1) == 0)
1076           break;
1077         if (LocaleCompare("extract",option+1) == 0)
1078           {
1079             if (*option == '+')
1080               break;
1081             i++;
1082             if (i == (ssize_t) argc)
1083               ThrowDisplayException(OptionError,"MissingArgument",option);
1084             if (IsGeometry(argv[i]) == MagickFalse)
1085               ThrowDisplayInvalidArgumentException(option,argv[i]);
1086             break;
1087           }
1088         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1089       }
1090       case 'f':
1091       {
1092         if (LocaleCompare("filter",option+1) == 0)
1093           {
1094             ssize_t
1095               filter;
1096
1097             if (*option == '+')
1098               break;
1099             i++;
1100             if (i == (ssize_t) argc)
1101               ThrowDisplayException(OptionError,"MissingArgument",option);
1102             filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
1103             if (filter < 0)
1104               ThrowDisplayException(OptionError,"UnrecognizedImageFilter",
1105                 argv[i]);
1106             break;
1107           }
1108         if (LocaleCompare("flatten",option+1) == 0)
1109           break;
1110         if (LocaleCompare("flip",option+1) == 0)
1111           break;
1112         if (LocaleCompare("flop",option+1) == 0)
1113           break;
1114         if (LocaleCompare("font",option+1) == 0)
1115           {
1116             if (*option == '+')
1117               break;
1118             i++;
1119             if (i == (ssize_t) argc)
1120               ThrowDisplayException(OptionError,"MissingArgument",option);
1121             resource_info.font=XGetResourceClass(resource_database,
1122               GetClientName(),"font",argv[i]);
1123             break;
1124           }
1125         if (LocaleCompare("foreground",option+1) == 0)
1126           {
1127             if (*option == '+')
1128               break;
1129             i++;
1130             if (i == (ssize_t) argc)
1131               ThrowDisplayException(OptionError,"MissingArgument",option);
1132             resource_info.foreground_color=argv[i];
1133             break;
1134           }
1135         if (LocaleCompare("format",option+1) == 0)
1136           {
1137             if (*option == '+')
1138               break;
1139             i++;
1140             if (i == (ssize_t) argc)
1141               ThrowDisplayException(OptionError,"MissingArgument",option);
1142             break;
1143           }
1144         if (LocaleCompare("frame",option+1) == 0)
1145           {
1146             if (*option == '+')
1147               break;
1148             i++;
1149             if (i == (ssize_t) argc)
1150               ThrowDisplayException(OptionError,"MissingArgument",option);
1151             if (IsGeometry(argv[i]) == MagickFalse)
1152               ThrowDisplayInvalidArgumentException(option,argv[i]);
1153             break;
1154           }
1155         if (LocaleCompare("fuzz",option+1) == 0)
1156           {
1157             if (*option == '+')
1158               break;
1159             i++;
1160             if (i == (ssize_t) argc)
1161               ThrowDisplayException(OptionError,"MissingArgument",option);
1162             if (IsGeometry(argv[i]) == MagickFalse)
1163               ThrowDisplayInvalidArgumentException(option,argv[i]);
1164             break;
1165           }
1166         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1167       }
1168       case 'g':
1169       {
1170         if (LocaleCompare("gamma",option+1) == 0)
1171           {
1172             i++;
1173             if (i == (ssize_t) argc)
1174               ThrowDisplayException(OptionError,"MissingArgument",option);
1175             if (IsGeometry(argv[i]) == MagickFalse)
1176               ThrowDisplayInvalidArgumentException(option,argv[i]);
1177             break;
1178           }
1179         if (LocaleCompare("geometry",option+1) == 0)
1180           {
1181             resource_info.image_geometry=(char *) NULL;
1182             if (*option == '+')
1183               break;
1184             (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
1185             i++;
1186             if (i == (ssize_t) argc)
1187               ThrowDisplayException(OptionError,"MissingArgument",option);
1188             if (IsGeometry(argv[i]) == MagickFalse)
1189               ThrowDisplayInvalidArgumentException(option,argv[i]);
1190             resource_info.image_geometry=ConstantString(argv[i]);
1191             break;
1192           }
1193         if (LocaleCompare("gravity",option+1) == 0)
1194           {
1195             ssize_t
1196               gravity;
1197
1198             if (*option == '+')
1199               break;
1200             i++;
1201             if (i == (ssize_t) argc)
1202               ThrowDisplayException(OptionError,"MissingArgument",option);
1203             gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
1204               argv[i]);
1205             if (gravity < 0)
1206               ThrowDisplayException(OptionError,"UnrecognizedGravityType",
1207                 argv[i]);
1208             break;
1209           }
1210         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1211       }
1212       case 'h':
1213       {
1214         if ((LocaleCompare("help",option+1) == 0) ||
1215             (LocaleCompare("-help",option+1) == 0))
1216           break;
1217         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1218       }
1219       case 'i':
1220       {
1221         if (LocaleCompare("identify",option+1) == 0)
1222           break;
1223         if (LocaleCompare("iconGeometry",option+1) == 0)
1224           {
1225             resource_info.icon_geometry=(char *) NULL;
1226             if (*option == '+')
1227               break;
1228             i++;
1229             if (i == (ssize_t) argc)
1230               ThrowDisplayException(OptionError,"MissingArgument",option);
1231             if (IsGeometry(argv[i]) == MagickFalse)
1232               ThrowDisplayInvalidArgumentException(option,argv[i]);
1233             resource_info.icon_geometry=argv[i];
1234             break;
1235           }
1236         if (LocaleCompare("iconic",option+1) == 0)
1237           {
1238             resource_info.iconic=(*option == '-') ? MagickTrue : MagickFalse;
1239             break;
1240           }
1241         if (LocaleCompare("immutable",option+1) == 0)
1242           {
1243             resource_info.immutable=(*option == '-') ? MagickTrue : MagickFalse;
1244             break;
1245           }
1246         if (LocaleCompare("interlace",option+1) == 0)
1247           {
1248             ssize_t
1249               interlace;
1250
1251             if (*option == '+')
1252               break;
1253             i++;
1254             if (i == (ssize_t) argc)
1255               ThrowDisplayException(OptionError,"MissingArgument",option);
1256             interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
1257               argv[i]);
1258             if (interlace < 0)
1259               ThrowDisplayException(OptionError,"UnrecognizedInterlaceType",
1260                 argv[i]);
1261             break;
1262           }
1263         if (LocaleCompare("interpolate",option+1) == 0)
1264           {
1265             ssize_t
1266               interpolate;
1267
1268             if (*option == '+')
1269               break;
1270             i++;
1271             if (i == (ssize_t) argc)
1272               ThrowDisplayException(OptionError,"MissingArgument",option);
1273             interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
1274               argv[i]);
1275             if (interpolate < 0)
1276               ThrowDisplayException(OptionError,"UnrecognizedInterpolateMethod",
1277                 argv[i]);
1278             break;
1279           }
1280         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1281       }
1282       case 'l':
1283       {
1284         if (LocaleCompare("label",option+1) == 0)
1285           {
1286             if (*option == '+')
1287               break;
1288             i++;
1289             if (i == (ssize_t) argc)
1290               ThrowDisplayException(OptionError,"MissingArgument",option);
1291             break;
1292           }
1293         if (LocaleCompare("limit",option+1) == 0)
1294           {
1295             char
1296               *p;
1297
1298             double
1299               value;
1300
1301             ssize_t
1302               resource;
1303
1304             if (*option == '+')
1305               break;
1306             i++;
1307             if (i == (ssize_t) argc)
1308               ThrowDisplayException(OptionError,"MissingArgument",option);
1309             resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
1310               argv[i]);
1311             if (resource < 0)
1312               ThrowDisplayException(OptionError,"UnrecognizedResourceType",
1313                 argv[i]);
1314             i++;
1315             if (i == (ssize_t) argc)
1316               ThrowDisplayException(OptionError,"MissingArgument",option);
1317             value=StringToDouble(argv[i],&p);
1318             (void) value;
1319             if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
1320               ThrowDisplayInvalidArgumentException(option,argv[i]);
1321             break;
1322           }
1323         if (LocaleCompare("list",option+1) == 0)
1324           {
1325             ssize_t
1326               list;
1327
1328             if (*option == '+')
1329               break;
1330             i++;
1331             if (i == (ssize_t) argc)
1332               ThrowDisplayException(OptionError,"MissingArgument",option);
1333             list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
1334             if (list < 0)
1335               ThrowDisplayException(OptionError,"UnrecognizedListType",argv[i]);
1336             status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
1337               argv+j,exception);
1338             DestroyDisplay();
1339             return(status != 0 ? MagickFalse : MagickTrue);
1340           }
1341         if (LocaleCompare("log",option+1) == 0)
1342           {
1343             if (*option == '+')
1344               break;
1345             i++;
1346             if ((i == (ssize_t) argc) ||
1347                 (strchr(argv[i],'%') == (char *) NULL))
1348               ThrowDisplayException(OptionError,"MissingArgument",option);
1349             break;
1350           }
1351         if (LocaleCompare("loop",option+1) == 0)
1352           {
1353             if (*option == '+')
1354               break;
1355             i++;
1356             if (i == (ssize_t) argc)
1357               ThrowDisplayException(OptionError,"MissingArgument",option);
1358             if (IsGeometry(argv[i]) == MagickFalse)
1359               ThrowDisplayInvalidArgumentException(option,argv[i]);
1360             iterations=StringToUnsignedLong(argv[i]);
1361             break;
1362           }
1363         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1364       }
1365       case 'm':
1366       {
1367         if (LocaleCompare("magnify",option+1) == 0)
1368           {
1369             resource_info.magnify=2;
1370             if (*option == '+')
1371               break;
1372             i++;
1373             if (i == (ssize_t) argc)
1374               ThrowDisplayException(OptionError,"MissingArgument",option);
1375             if (IsGeometry(argv[i]) == MagickFalse)
1376               ThrowDisplayInvalidArgumentException(option,argv[i]);
1377             resource_info.magnify=(unsigned int) StringToUnsignedLong(argv[i]);
1378             break;
1379           }
1380         if (LocaleCompare("map",option+1) == 0)
1381           {
1382             resource_info.map_type=(char *) NULL;
1383             if (*option == '+')
1384               break;
1385             (void) strcpy(argv[i]+1,"san");
1386             i++;
1387             if (i == (ssize_t) argc)
1388               ThrowDisplayException(OptionError,"MissingArgument",option);
1389             resource_info.map_type=argv[i];
1390             break;
1391           }
1392         if (LocaleCompare("matte",option+1) == 0)
1393           break;
1394         if (LocaleCompare("mattecolor",option+1) == 0)
1395           {
1396             if (*option == '+')
1397               break;
1398             i++;
1399             if (i == (ssize_t) argc)
1400               ThrowDisplayException(OptionError,"MissingArgument",option);
1401             resource_info.matte_color=argv[i];
1402             break;
1403           }
1404         if (LocaleCompare("monitor",option+1) == 0)
1405           break;
1406         if (LocaleCompare("monochrome",option+1) == 0)
1407           {
1408             if (*option == '+')
1409               break;
1410             quantize_info->number_colors=2;
1411             quantize_info->colorspace=GRAYColorspace;
1412             break;
1413           }
1414         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1415       }
1416       case 'n':
1417       {
1418         if (LocaleCompare("name",option+1) == 0)
1419           {
1420             resource_info.name=(char *) NULL;
1421             if (*option == '+')
1422               break;
1423             i++;
1424             if (i == (ssize_t) argc)
1425               ThrowDisplayException(OptionError,"MissingArgument",option);
1426             resource_info.name=ConstantString(argv[i]);
1427             break;
1428           }
1429         if (LocaleCompare("negate",option+1) == 0)
1430           break;
1431         if (LocaleCompare("noop",option+1) == 0)
1432           break;
1433         if (LocaleCompare("normalize",option+1) == 0)
1434           break;
1435         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1436       }
1437       case 'p':
1438       {
1439         if (LocaleCompare("page",option+1) == 0)
1440           {
1441             resource_info.image_geometry=(char *) NULL;
1442             if (*option == '+')
1443               break;
1444             i++;
1445             if (i == (ssize_t) argc)
1446               ThrowDisplayException(OptionError,"MissingArgument",option);
1447             resource_info.image_geometry=ConstantString(argv[i]);
1448             break;
1449           }
1450         if (LocaleCompare("profile",option+1) == 0)
1451           {
1452             i++;
1453             if (i == (ssize_t) argc)
1454               ThrowDisplayException(OptionError,"MissingArgument",option);
1455             break;
1456           }
1457         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1458       }
1459       case 'q':
1460       {
1461         if (LocaleCompare("quality",option+1) == 0)
1462           {
1463             if (*option == '+')
1464               break;
1465             i++;
1466             if (i == (ssize_t) argc)
1467               ThrowDisplayException(OptionError,"MissingArgument",option);
1468             if (IsGeometry(argv[i]) == MagickFalse)
1469               ThrowDisplayInvalidArgumentException(option,argv[i]);
1470             break;
1471           }
1472         if (LocaleCompare("quantize",option+1) == 0)
1473           {
1474             ssize_t
1475               colorspace;
1476
1477             if (*option == '+')
1478               break;
1479             i++;
1480             if (i == (ssize_t) argc)
1481               ThrowDisplayException(OptionError,"MissingArgument",option);
1482             colorspace=ParseCommandOption(MagickColorspaceOptions,
1483               MagickFalse,argv[i]);
1484             if (colorspace < 0)
1485               ThrowDisplayException(OptionError,"UnrecognizedColorspace",
1486                 argv[i]);
1487             break;
1488           }
1489         if (LocaleCompare("quiet",option+1) == 0)
1490           break;
1491         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1492       }
1493       case 'r':
1494       {
1495         if (LocaleCompare("raise",option+1) == 0)
1496           {
1497             i++;
1498             if (i == (ssize_t) argc)
1499               ThrowDisplayException(OptionError,"MissingArgument",option);
1500             if (IsGeometry(argv[i]) == MagickFalse)
1501               ThrowDisplayInvalidArgumentException(option,argv[i]);
1502             break;
1503           }
1504         if (LocaleCompare("regard-warnings",option+1) == 0)
1505           break;
1506         if (LocaleCompare("remote",option+1) == 0)
1507           {
1508             i++;
1509             if (i == (ssize_t) argc)
1510               ThrowDisplayException(OptionError,"MissingArgument",option);
1511             if (XRemoteCommand(display,resource_info.window_id,argv[i]) != 0)
1512               return(MagickFalse);
1513             i--;
1514             break;
1515           }
1516         if (LocaleCompare("repage",option+1) == 0)
1517           {
1518             if (*option == '+')
1519               break;
1520             i++;
1521             if (i == (ssize_t) argc)
1522               ThrowDisplayException(OptionError,"MissingArgument",option);
1523             if (IsGeometry(argv[i]) == MagickFalse)
1524               ThrowDisplayInvalidArgumentException(option,argv[i]);
1525             break;
1526           }
1527         if (LocaleCompare("resample",option+1) == 0)
1528           {
1529             if (*option == '+')
1530               break;
1531             i++;
1532             if (i == (ssize_t) argc)
1533               ThrowDisplayException(OptionError,"MissingArgument",option);
1534             if (IsGeometry(argv[i]) == MagickFalse)
1535               ThrowDisplayInvalidArgumentException(option,argv[i]);
1536             break;
1537           }
1538         if (LocaleCompare("resize",option+1) == 0)
1539           {
1540             if (*option == '+')
1541               break;
1542             i++;
1543             if (i == (ssize_t) argc)
1544               ThrowDisplayException(OptionError,"MissingArgument",option);
1545             if (IsGeometry(argv[i]) == MagickFalse)
1546               ThrowDisplayInvalidArgumentException(option,argv[i]);
1547             break;
1548           }
1549         if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1550           {
1551             respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1552             break;
1553           }
1554         if (LocaleCompare("roll",option+1) == 0)
1555           {
1556             if (*option == '+')
1557               break;
1558             i++;
1559             if (i == (ssize_t) argc)
1560               ThrowDisplayException(OptionError,"MissingArgument",option);
1561             if (IsGeometry(argv[i]) == MagickFalse)
1562               ThrowDisplayInvalidArgumentException(option,argv[i]);
1563             break;
1564           }
1565         if (LocaleCompare("rotate",option+1) == 0)
1566           {
1567             i++;
1568             if (i == (ssize_t) argc)
1569               ThrowDisplayException(OptionError,"MissingArgument",option);
1570             if (IsGeometry(argv[i]) == MagickFalse)
1571               ThrowDisplayInvalidArgumentException(option,argv[i]);
1572             break;
1573           }
1574         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1575       }
1576       case 's':
1577       {
1578         if (LocaleCompare("sample",option+1) == 0)
1579           {
1580             if (*option == '+')
1581               break;
1582             i++;
1583             if (i == (ssize_t) argc)
1584               ThrowDisplayException(OptionError,"MissingArgument",option);
1585             if (IsGeometry(argv[i]) == MagickFalse)
1586               ThrowDisplayInvalidArgumentException(option,argv[i]);
1587             break;
1588           }
1589         if (LocaleCompare("sampling-factor",option+1) == 0)
1590           {
1591             if (*option == '+')
1592               break;
1593             i++;
1594             if (i == (ssize_t) argc)
1595               ThrowDisplayException(OptionError,"MissingArgument",option);
1596             if (IsGeometry(argv[i]) == MagickFalse)
1597               ThrowDisplayInvalidArgumentException(option,argv[i]);
1598             break;
1599           }
1600         if (LocaleCompare("scenes",option+1) == 0)
1601           {
1602             if (*option == '+')
1603               break;
1604             i++;
1605             if (i == (ssize_t) argc)
1606               ThrowDisplayException(OptionError,"MissingArgument",option);
1607             if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
1608               ThrowDisplayInvalidArgumentException(option,argv[i]);
1609             break;
1610           }
1611         if (LocaleCompare("seed",option+1) == 0)
1612           {
1613             if (*option == '+')
1614               break;
1615             i++;
1616             if (i == (ssize_t) argc)
1617               ThrowDisplayException(OptionError,"MissingArgument",option);
1618             if (IsGeometry(argv[i]) == MagickFalse)
1619               ThrowDisplayInvalidArgumentException(option,argv[i]);
1620             break;
1621           }
1622         if (LocaleCompare("segment",option+1) == 0)
1623           {
1624             if (*option == '+')
1625               break;
1626             i++;
1627             if (i == (ssize_t) argc)
1628               ThrowDisplayException(OptionError,"MissingArgument",option);
1629             if (IsGeometry(argv[i]) == MagickFalse)
1630               ThrowDisplayInvalidArgumentException(option,argv[i]);
1631             break;
1632           }
1633         if (LocaleCompare("set",option+1) == 0)
1634           {
1635             i++;
1636             if (i == (ssize_t) argc)
1637               ThrowDisplayException(OptionError,"MissingArgument",option);
1638             if (*option == '+')
1639               break;
1640             i++;
1641             if (i == (ssize_t) argc)
1642               ThrowDisplayException(OptionError,"MissingArgument",option);
1643             break;
1644           }
1645         if (LocaleCompare("sharpen",option+1) == 0)
1646           {
1647             if (*option == '+')
1648               break;
1649             i++;
1650             if (i == (ssize_t) argc)
1651               ThrowDisplayException(OptionError,"MissingArgument",option);
1652             if (IsGeometry(argv[i]) == MagickFalse)
1653               ThrowDisplayInvalidArgumentException(option,argv[i]);
1654             break;
1655           }
1656         if (LocaleCompare("shared-memory",option+1) == 0)
1657           {
1658             resource_info.use_shared_memory= (*option == '-') ? MagickTrue :
1659               MagickFalse;
1660             break;
1661           }
1662         if (LocaleCompare("size",option+1) == 0)
1663           {
1664             if (*option == '+')
1665               break;
1666             i++;
1667             if (i == (ssize_t) argc)
1668               ThrowDisplayException(OptionError,"MissingArgument",option);
1669             if (IsGeometry(argv[i]) == MagickFalse)
1670               ThrowDisplayInvalidArgumentException(option,argv[i]);
1671             break;
1672           }
1673         if (LocaleCompare("strip",option+1) == 0)
1674           break;
1675         if (LocaleCompare("support",option+1) == 0)
1676           {
1677             i++;  /* deprecated */
1678             break;
1679           }
1680         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1681       }
1682       case 't':
1683       {
1684         if (LocaleCompare("text-font",option+1) == 0)
1685           {
1686             resource_info.text_font=(char *) NULL;
1687             if (*option == '+')
1688               break;
1689             i++;
1690             if (i == (ssize_t) argc)
1691               ThrowDisplayException(OptionError,"MissingArgument",option);
1692             resource_info.text_font=XGetResourceClass(resource_database,
1693               GetClientName(),"font",argv[i]);
1694             break;
1695           }
1696         if (LocaleCompare("texture",option+1) == 0)
1697           {
1698             if (*option == '+')
1699               break;
1700             i++;
1701             if (i == (ssize_t) argc)
1702               ThrowDisplayException(OptionError,"MissingArgument",option);
1703             break;
1704           }
1705         if (LocaleCompare("threshold",option+1) == 0)
1706           {
1707             if (*option == '+')
1708               break;
1709             i++;
1710             if (i == (ssize_t) argc)
1711               ThrowDisplayException(OptionError,"MissingArgument",option);
1712             if (IsGeometry(argv[i]) == MagickFalse)
1713               ThrowDisplayInvalidArgumentException(option,argv[i]);
1714             break;
1715           }
1716         if (LocaleCompare("thumbnail",option+1) == 0)
1717           {
1718             if (*option == '+')
1719               break;
1720             i++;
1721             if (i == (ssize_t) argc)
1722               ThrowDisplayException(OptionError,"MissingArgument",option);
1723             if (IsGeometry(argv[i]) == MagickFalse)
1724               ThrowDisplayInvalidArgumentException(option,argv[i]);
1725             break;
1726           }
1727         if (LocaleCompare("title",option+1) == 0)
1728           {
1729             resource_info.title=(char *) NULL;
1730             if (*option == '+')
1731               break;
1732             i++;
1733             if (i == (ssize_t) argc)
1734               ThrowDisplayException(OptionError,"MissingArgument",option);
1735             resource_info.title=argv[i];
1736             break;
1737           }
1738         if (LocaleCompare("transparent-color",option+1) == 0)
1739           {
1740             if (*option == '+')
1741               break;
1742             i++;
1743             if (i == (ssize_t) argc)
1744               ThrowDisplayException(OptionError,"MissingArgument",option);
1745             break;
1746           }
1747         if (LocaleCompare("treedepth",option+1) == 0)
1748           {
1749             quantize_info->tree_depth=0;
1750             if (*option == '+')
1751               break;
1752             i++;
1753             if (i == (ssize_t) argc)
1754               ThrowDisplayException(OptionError,"MissingArgument",option);
1755             if (IsGeometry(argv[i]) == MagickFalse)
1756               ThrowDisplayInvalidArgumentException(option,argv[i]);
1757             quantize_info->tree_depth=StringToUnsignedLong(argv[i]);
1758             break;
1759           }
1760         if (LocaleCompare("trim",option+1) == 0)
1761           break;
1762         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1763       }
1764       case 'u':
1765       {
1766         if (LocaleCompare("update",option+1) == 0)
1767           {
1768             resource_info.update=(unsigned int) (*option == '-');
1769             if (*option == '+')
1770               break;
1771             i++;
1772             if (i == (ssize_t) argc)
1773               ThrowDisplayException(OptionError,"MissingArgument",option);
1774             if (IsGeometry(argv[i]) == MagickFalse)
1775               ThrowDisplayInvalidArgumentException(option,argv[i]);
1776             resource_info.update=(unsigned int) StringToUnsignedLong(argv[i]);
1777             break;
1778           }
1779         if (LocaleCompare("use-pixmap",option+1) == 0)
1780           {
1781             resource_info.use_pixmap=(*option == '-') ? MagickTrue :
1782               MagickFalse;
1783             break;
1784           }
1785         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1786       }
1787       case 'v':
1788       {
1789         if (LocaleCompare("verbose",option+1) == 0)
1790           break;
1791         if ((LocaleCompare("version",option+1) == 0) ||
1792             (LocaleCompare("-version",option+1) == 0))
1793           {
1794             ListMagickVersion(stdout);
1795             break;
1796           }
1797         if (LocaleCompare("visual",option+1) == 0)
1798           {
1799             resource_info.visual_type=(char *) NULL;
1800             if (*option == '+')
1801               break;
1802             i++;
1803             if (i == (ssize_t) argc)
1804               ThrowDisplayException(OptionError,"MissingArgument",option);
1805             resource_info.visual_type=argv[i];
1806             break;
1807           }
1808         if (LocaleCompare("virtual-pixel",option+1) == 0)
1809           {
1810             ssize_t
1811               method;
1812
1813             if (*option == '+')
1814               break;
1815             i++;
1816             if (i == (ssize_t) argc)
1817               ThrowDisplayException(OptionError,"MissingArgument",option);
1818             method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
1819               argv[i]);
1820             if (method < 0)
1821               ThrowDisplayException(OptionError,
1822                 "UnrecognizedVirtualPixelMethod",argv[i]);
1823             break;
1824           }
1825         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1826       }
1827       case 'w':
1828       {
1829         if (LocaleCompare("window",option+1) == 0)
1830           {
1831             resource_info.window_id=(char *) NULL;
1832             if (*option == '+')
1833               break;
1834             i++;
1835             if (i == (ssize_t) argc)
1836               ThrowDisplayException(OptionError,"MissingArgument",option);
1837             resource_info.window_id=argv[i];
1838             break;
1839           }
1840         if (LocaleCompare("window-group",option+1) == 0)
1841           {
1842             resource_info.window_group=(char *) NULL;
1843             if (*option == '+')
1844               break;
1845             i++;
1846             if (i == (ssize_t) argc)
1847               ThrowDisplayException(OptionError,"MissingArgument",option);
1848             if (StringToDouble(argv[i],(char **) NULL) != 0)
1849               resource_info.window_group=argv[i];
1850             break;
1851           }
1852         if (LocaleCompare("write",option+1) == 0)
1853           {
1854             resource_info.write_filename=(char *) NULL;
1855             if (*option == '+')
1856               break;
1857             i++;
1858             if (i == (ssize_t) argc)
1859               ThrowDisplayException(OptionError,"MissingArgument",option);
1860             resource_info.write_filename=argv[i];
1861             if (IsPathAccessible(resource_info.write_filename) != MagickFalse)
1862               {
1863                 char
1864                   answer[2],
1865                   *p;
1866
1867                 (void) FormatLocaleFile(stderr,"Overwrite %s? ",
1868                   resource_info.write_filename);
1869                 p=fgets(answer,(int) sizeof(answer),stdin);
1870                 (void) p;
1871                 if (((*answer != 'y') && (*answer != 'Y')))
1872                   return(MagickFalse);
1873               }
1874             break;
1875           }
1876         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1877       }
1878       case '?':
1879         break;
1880       default:
1881         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1882     }
1883     fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1884       FireOptionFlag) == 0 ?  MagickFalse : MagickTrue;
1885     if (fire != MagickFalse)
1886       FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1887   }
1888   if (k != 0)
1889     ThrowDisplayException(OptionError,"UnbalancedParenthesis",argv[i]);
1890   if (state & RetainColorsState)
1891     {
1892       XRetainWindowColors(display,XRootWindow(display,XDefaultScreen(display)));
1893       (void) XSync(display,MagickFalse);
1894     }
1895   DestroyDisplay();
1896   return(status != 0 ? MagickTrue : MagickFalse);
1897 #else
1898   (void) argc;
1899   (void) argv;
1900   (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
1901     "DelegateLibrarySupportNotBuiltIn","'%s' (X11)",image_info->filename);
1902   return(DisplayUsage());
1903 #endif
1904 }