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