]> 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-2013 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/nt-base-private.h"
49 #include "MagickCore/string-private.h"
50 #include "MagickCore/xwindow-private.h"
51 \f
52 /*
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %                                                                             %
55 %                                                                             %
56 %                                                                             %
57 +   D i s p l a y I m a g e C o m m a n d                                     %
58 %                                                                             %
59 %                                                                             %
60 %                                                                             %
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %
63 %  DisplayImageCommand() displays a sequence of images on any workstation
64 %  display running an X server.  Display first determines the hardware
65 %  capabilities of the workstation. If the number of unique colors in an image
66 %  is less than or equal to the number the workstation can support, the image
67 %  is displayed in an X window. Otherwise the number of colors in the image is
68 %  first reduced to match the color resolution of the workstation before it is
69 %  displayed.
70 %
71 %  This means that a continuous-tone 24 bits/pixel image can display on a 8
72 %  bit pseudo-color device or monochrome device. In most instances the reduced
73 %  color image closely resembles the original. Alternatively, a monochrome or
74 %  pseudo-color image sequence can display on a continuous-tone 24 bits/pixels
75 %  device.
76 %
77 %  The format of the DisplayImageCommand method is:
78 %
79 %      MagickBooleanType DisplayImageCommand(ImageInfo *image_info,int argc,
80 %        char **argv,char **metadata,ExceptionInfo *exception)
81 %
82 %  A description of each parameter follows:
83 %
84 %    o image_info: the image info.
85 %
86 %    o argc: the number of elements in the argument vector.
87 %
88 %    o argv: A text array containing the command line arguments.
89 %
90 %    o metadata: any metadata is returned here.
91 %
92 %    o exception: return any errors or warnings in this structure.
93 %
94 */
95
96 static MagickBooleanType DisplayUsage(void)
97 {
98   const char
99     **p;
100
101   static const char
102     *buttons[]=
103     {
104       "1    press to map or unmap the Command widget",
105       "2    press and drag to magnify a region of an image",
106       "3    press to load an image from a visual image directory",
107       (char *) NULL
108     },
109     *miscellaneous[]=
110     {
111       "-debug events        display copious debugging information",
112       "-help                print program options",
113       "-list type           print a list of supported option arguments",
114       "-log format          format of debugging information",
115       "-version             print version information",
116       (char *) NULL
117     },
118     *operators[]=
119     {
120       "-auto-orient         automagically orient image",
121       "-border geometry     surround image with a border of color",
122       "-clip                clip along the first path from the 8BIM profile",
123       "-clip-path id        clip along a named path from the 8BIM profile",
124       "-colors value        preferred number of colors in the image",
125       "-contrast            enhance or reduce the image contrast",
126       "-crop geometry       preferred size and location of the cropped image",
127       "-decipher filename   convert cipher pixels to plain pixels",
128       "-deskew threshold    straighten an image",
129       "-despeckle           reduce the speckles within an image",
130       "-edge factor         apply a filter to detect edges in the image",
131       "-enhance             apply a digital filter to enhance a noisy image",
132       "-equalize            perform histogram equalization to an image",
133       "-extract geometry    extract area from image",
134       "-flip                flip image in the vertical direction",
135       "-flop                flop image in the horizontal direction",
136       "-frame geometry      surround image with an ornamental border",
137       "-fuzz distance       colors within this distance are considered equal",
138       "-gamma value         level of gamma correction",
139       "-monochrome          transform image to black and white",
140       "-negate              replace every pixel with its complementary color",
141       "-normalize           transform image to span the full range of colors",
142       "-raise value         lighten/darken image edges to create a 3-D effect",
143       "-resample geometry   change the resolution of an image",
144       "-resize geometry     resize the image",
145       "-roll geometry       roll an image vertically or horizontally",
146       "-rotate degrees      apply Paeth rotation to the image",
147       "-sample geometry     scale image with pixel sampling",
148       "-segment value       segment an image",
149       "-sharpen geometry    sharpen the image",
150       "-strip               strip image of all profiles and comments",
151       "-threshold value     threshold the image",
152       "-thumbnail geometry  create a thumbnail of the image",
153       "-trim                trim image edges",
154       (char *) NULL
155     },
156     *settings[]=
157     {
158       "-alpha option        on, activate, off, deactivate, set, opaque, copy",
159       "                     transparent, extract, background, or shape",
160       "-antialias           remove pixel-aliasing",
161       "-authenticate password",
162       "                     decipher image with this password",
163       "-backdrop            display image centered on a backdrop",
164       "-channel type        apply option to select image channels",
165       "-colormap type       Shared or Private",
166       "-colorspace type     alternate image colorspace",
167       "-comment string      annotate image with comment",
168       "-compress type       type of pixel compression when writing the image",
169       "-define format:option",
170       "                     define one or more image format options",
171       "-delay value         display the next image after pausing",
172       "-density geometry    horizontal and vertical density of the image",
173       "-depth value         image depth",
174       "-display server      display image to this X server",
175       "-dispose method      layer disposal method",
176       "-dither method       apply error diffusion to image",
177       "-endian type         endianness (MSB or LSB) of the image",
178       "-filter type         use this filter when resizing an image",
179       "-format string     output formatted image characteristics",
180       "-geometry geometry   preferred size and location of the Image window",
181       "-gravity type        horizontal and vertical backdrop placement",
182       "-identify            identify the format and characteristics of the image",
183       "-immutable           displayed image cannot be modified",
184       "-interlace type      type of image interlacing scheme",
185       "-interpolate method  pixel color interpolation method",
186       "-label string        assign a label to an image",
187       "-limit type value    pixel cache resource limit",
188       "-loop iterations     loop images then exit",
189       "-map type            display image using this Standard Colormap",
190       "-monitor             monitor progress",
191       "-page geometry       size and location of an image canvas",
192       "-profile filename    add, delete, or apply an image profile",
193       "-quality value       JPEG/MIFF/PNG compression level",
194       "-quantize colorspace reduce colors in this colorspace",
195       "-quiet               suppress all warning messages",
196       "-regard-warnings     pay attention to warning messages",
197       "-remote command      execute a command in an remote display process",
198       "-repage geometry     size and location of an image canvas (operator)",
199       "-respect-parentheses settings remain in effect until parenthesis boundary",
200       "-sampling-factor geometry",
201       "                     horizontal and vertical sampling factor",
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       "-texture filename    name of texture to tile onto the image background",
206       "-transparent-color color",
207       "                     transparent color",
208       "-treedepth value     color tree depth",
209       "-update seconds      detect when image file is modified and redisplay",
210       "-verbose             print detailed information about the image",
211       "-visual type         display image using this visual type",
212       "-virtual-pixel method",
213       "                     virtual pixel access method",
214       "-window id           display image to background of this window",
215       "-window-group id     exit program when this window id is destroyed",
216       "-write filename      write image to a file",
217       (char *) NULL
218     },
219     *sequence_operators[]=
220     {
221       "-coalesce            merge a sequence of images",
222       "-flatten             flatten a sequence of images",
223       (char *) NULL
224     };
225
226   ListMagickVersion(stdout);
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           ListMagickVersion(stdout);
363           return(MagickFalse);
364         }
365     }
366   SetNotifyHandlers;
367   display=(Display *) NULL;
368   j=1;
369   k=0;
370   image_marker=(size_t *) NULL;
371   image_number=0;
372   last_image=0;
373   NewImageStack();
374   option=(char *) NULL;
375   pend=MagickFalse;
376   respect_parenthesis=MagickFalse;
377   resource_database=(XrmDatabase) NULL;
378   (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info));
379   server_name=(char *) NULL;
380   state=0;
381   status=MagickTrue;
382   ReadCommandlLine(argc,&argv);
383   status=ExpandFilenames(&argc,&argv);
384   if (status == MagickFalse)
385     ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
386       GetExceptionMessage(errno));
387   image_marker=(size_t *) AcquireQuantumMemory((size_t) argc+1UL,
388     sizeof(*image_marker));
389   if (image_marker == (size_t *) NULL)
390     ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
391       GetExceptionMessage(errno));
392   for (i=0; i <= (ssize_t) argc; i++)
393     image_marker[i]=(size_t) argc;
394   /*
395     Check for server name specified on the command line.
396   */
397   for (i=1; i < (ssize_t) argc; i++)
398   {
399     /*
400       Check command line for server name.
401     */
402     option=argv[i];
403     if (LocaleCompare("display",option+1) == 0)
404       {
405         /*
406           User specified server name.
407         */
408         i++;
409         if (i == (ssize_t) argc)
410           ThrowDisplayException(OptionError,"MissingArgument",option);
411         server_name=argv[i];
412       }
413     if ((LocaleCompare("help",option+1) == 0) ||
414         (LocaleCompare("-help",option+1) == 0))
415       return(DisplayUsage());
416   }
417   /*
418     Get user defaults from X resource database.
419   */
420   display=XOpenDisplay(server_name);
421   if (display == (Display *) NULL)
422     ThrowDisplayException(XServerError,"UnableToOpenXServer",
423       XDisplayName(server_name));
424   (void) XSetErrorHandler(XError);
425   resource_database=XGetResourceDatabase(display,GetClientName());
426   XGetResourceInfo(image_info,resource_database,GetClientName(),
427     &resource_info);
428   quantize_info=resource_info.quantize_info;
429   image_info->density=XGetResourceInstance(resource_database,GetClientName(),
430     "density",(char *) NULL);
431   if (image_info->density == (char *) NULL)
432     image_info->density=XGetScreenDensity(display);
433   resource_value=XGetResourceInstance(resource_database,GetClientName(),
434     "interlace","none");
435   image_info->interlace=(InterlaceType)
436     ParseCommandOption(MagickInterlaceOptions,MagickFalse,resource_value);
437   image_info->page=XGetResourceInstance(resource_database,GetClientName(),
438     "pageGeometry",(char *) NULL);
439   resource_value=XGetResourceInstance(resource_database,GetClientName(),
440     "quality","75");
441   image_info->quality=StringToUnsignedLong(resource_value);
442   resource_value=XGetResourceInstance(resource_database,GetClientName(),
443     "verbose","False");
444   image_info->verbose=IsStringTrue(resource_value);
445   resource_value=XGetResourceInstance(resource_database,GetClientName(),
446     "dither","True");
447   quantize_info->dither_method=IsStringTrue(resource_value) != MagickFalse ?
448     RiemersmaDitherMethod : NoDitherMethod;
449   /*
450     Parse command line.
451   */
452   iteration=0;
453   for (i=1; ((i <= (ssize_t) argc) && ((state & ExitState) == 0)); i++)
454   {
455     if (i < (ssize_t) argc)
456       option=argv[i];
457     else
458       if (image != (Image *) NULL)
459         break;
460       else
461         if (isatty(STDIN_FILENO) != MagickFalse)
462           option="logo:";
463         else
464           {
465             int
466               c;
467
468             c=getc(stdin);
469             if (c == EOF)
470               option="logo:";
471             else
472               {
473                 c=ungetc(c,stdin);
474                 option="-";
475               }
476           }
477     if (LocaleCompare(option,"(") == 0)
478       {
479         FireImageStack(MagickFalse,MagickTrue,pend);
480         if (k == MaxImageStackDepth)
481           ThrowDisplayException(OptionError,"ParenthesisNestedTooDeeply",
482             option);
483         PushImageStack();
484         continue;
485       }
486     if (LocaleCompare(option,")") == 0)
487       {
488         FireImageStack(MagickFalse,MagickTrue,MagickTrue);
489         if (k == 0)
490           ThrowDisplayException(OptionError,"UnableToParseExpression",option);
491         PopImageStack();
492         continue;
493       }
494     if (IsCommandOption(option) == MagickFalse)
495       {
496         const char
497           *filename;
498
499         Image
500           *display_image,
501           *image_list,
502           *images;
503
504         /*
505           Option is a file name.
506         */
507         FireImageStack(MagickFalse,MagickFalse,pend);
508         filename=option;
509         if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
510           {
511             option=argv[++i];
512             filename=option;
513           }
514         (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
515         images=ReadImage(image_info,exception);
516         CatchException(exception);
517         status&=(images != (Image *) NULL) &&
518           (exception->severity < ErrorException);
519         if (images == (Image *) NULL)
520           continue;
521         AppendImageStack(images);
522         FinalizeImageSettings(image_info,image,MagickFalse);
523         iterations=0;
524         if (i == (ssize_t) (argc-1))
525           iterations=image->iterations;
526         image_list=CloneImageList(image,exception);
527         if (image_list == (Image *) NULL)
528           ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
529             GetExceptionMessage(errno));
530         display_image=image_list;
531         do
532         {
533           /*
534             Transmogrify image as defined by the image processing options.
535           */
536           resource_info.quantum=1;
537           if (resource_info.window_id != (char *) NULL)
538             {
539               /*
540                 Display image to a specified X window.
541               */
542               status=XDisplayBackgroundImage(display,&resource_info,
543                 display_image,exception);
544               if (status != MagickFalse)
545                 {
546                   state|=RetainColorsState;
547                   status=MagickFalse;
548                 }
549             }
550           else
551             do
552             {
553               Image
554                 *nexus;
555
556               /*
557                 Display image to X server.
558               */
559               if (resource_info.delay != 1)
560                 display_image->delay=resource_info.delay;
561               nexus=XDisplayImage(display,&resource_info,argv,argc,
562                 &display_image,&state,exception);
563               status&=nexus != (Image *) NULL;
564               if (nexus == (Image *) NULL)
565                 break;
566               while ((nexus != (Image *) NULL) && ((state & ExitState) == 0))
567               {
568                 Image
569                   *next;
570
571                 if (nexus->montage != (char *) NULL)
572                   {
573                     /*
574                       User selected a visual directory image (montage).
575                     */
576                     display_image=nexus;
577                     break;
578                   }
579                 next=XDisplayImage(display,&resource_info,argv,argc,&nexus,
580                   &state,exception);
581                 if ((next == (Image *) NULL) &&
582                     (GetNextImageInList(nexus) != (Image *) NULL))
583                   {
584                     display_image=GetNextImageInList(nexus);
585                     nexus=NewImageList();
586                   }
587                 else
588                   {
589                     if (nexus != display_image)
590                       nexus=DestroyImageList(nexus);
591                     nexus=next;
592                   }
593               }
594             } while ((state & ExitState) == 0);
595           if (resource_info.write_filename != (char *) NULL)
596             {
597               /*
598                 Write image.
599               */
600               (void) CopyMagickString(display_image->filename,
601                 resource_info.write_filename,MaxTextExtent);
602               (void) SetImageInfo(image_info,1,exception);
603               status&=WriteImage(image_info,display_image,exception);
604             }
605           /*
606             Proceed to next/previous image.
607           */
608           if ((state & FormerImageState) != 0)
609             for (l=0; l < (ssize_t) resource_info.quantum; l++)
610             {
611               display_image=GetPreviousImageInList(display_image);
612               if (display_image == (Image *) NULL)
613                 break;
614             }
615           else
616             for (l=0; l < (ssize_t) resource_info.quantum; l++)
617             {
618               display_image=GetNextImageInList(display_image);
619               if (display_image == (Image *) NULL)
620                 break;
621             }
622         } while ((display_image != (Image *) NULL) && ((state & ExitState) == 0));
623         /*
624           Free image resources.
625         */
626         display_image=GetFirstImageInList(display_image);
627         if (image_list != display_image)
628           image_list=DestroyImageList(image_list);
629         display_image=DestroyImageList(display_image);
630         if ((state & FormerImageState) == 0)
631           {
632             last_image=(size_t) image_number;
633             image_marker[i]=(size_t) image_number++;
634           }
635         else
636           {
637             /*
638               Proceed to previous image.
639             */
640             for (i--; i > 0; i--)
641               if (image_marker[i] == (size_t) (image_number-2))
642                 break;
643             image_number--;
644           }
645         if ((i == (ssize_t) (argc-1)) && ((state & ExitState) == 0))
646           i=0;
647         if ((state & ExitState) != 0)
648           break;
649         /*
650           Determine if we should proceed to the first image.
651         */
652         if (image_number < 0)
653           {
654             if ((state & FormerImageState) != 0)
655               {
656
657                 for (i=1; i < (ssize_t) (argc-2); i++)
658                   if (last_image == image_marker[i])
659                     break;
660                 image_number=(ssize_t) image_marker[i]+1;
661               }
662             continue;
663           }
664         if (resource_info.window_id != (char *) NULL)
665           state|=ExitState;
666         if ((iterations != 0) && (++iteration == (ssize_t) iterations))
667           state|=ExitState;
668         if (LocaleCompare(filename,"-") == 0)
669           state|=ExitState;
670         RemoveAllImageStack();
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(MagickAlphaChannelOptions,MagickFalse,argv[i]);
689             if (type < 0)
690               ThrowDisplayException(OptionError,"UnrecognizedAlphaChannelOption",
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_method=NoDitherMethod;
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_method=(DitherMethod) method;
1026             break;
1027           }
1028         if (LocaleCompare("duration",option+1) == 0)
1029           {
1030             if (*option == '+')
1031               break;
1032             i++;
1033             if (i == (ssize_t) (argc-1))
1034               ThrowDisplayException(OptionError,"MissingArgument",option);
1035             if (IsGeometry(argv[i]) == MagickFalse)
1036               ThrowDisplayInvalidArgumentException(option,argv[i]);
1037             break;
1038           }
1039         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1040       }
1041       case 'e':
1042       {
1043         if (LocaleCompare("edge",option+1) == 0)
1044           {
1045             if (*option == '+')
1046               break;
1047             i++;
1048             if (i == (ssize_t) argc)
1049               ThrowDisplayException(OptionError,"MissingArgument",option);
1050             if (IsGeometry(argv[i]) == MagickFalse)
1051               ThrowDisplayInvalidArgumentException(option,argv[i]);
1052             break;
1053           }
1054         if (LocaleCompare("endian",option+1) == 0)
1055           {
1056             ssize_t
1057               endian;
1058
1059             if (*option == '+')
1060               break;
1061             i++;
1062             if (i == (ssize_t) argc)
1063               ThrowDisplayException(OptionError,"MissingArgument",option);
1064             endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
1065               argv[i]);
1066             if (endian < 0)
1067               ThrowDisplayException(OptionError,"UnrecognizedEndianType",
1068                 argv[i]);
1069             break;
1070           }
1071         if (LocaleCompare("enhance",option+1) == 0)
1072           break;
1073         if (LocaleCompare("equalize",option+1) == 0)
1074           break;
1075         if (LocaleCompare("extract",option+1) == 0)
1076           {
1077             if (*option == '+')
1078               break;
1079             i++;
1080             if (i == (ssize_t) argc)
1081               ThrowDisplayException(OptionError,"MissingArgument",option);
1082             if (IsGeometry(argv[i]) == MagickFalse)
1083               ThrowDisplayInvalidArgumentException(option,argv[i]);
1084             break;
1085           }
1086         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1087       }
1088       case 'f':
1089       {
1090         if (LocaleCompare("filter",option+1) == 0)
1091           {
1092             ssize_t
1093               filter;
1094
1095             if (*option == '+')
1096               break;
1097             i++;
1098             if (i == (ssize_t) argc)
1099               ThrowDisplayException(OptionError,"MissingArgument",option);
1100             filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
1101             if (filter < 0)
1102               ThrowDisplayException(OptionError,"UnrecognizedImageFilter",
1103                 argv[i]);
1104             break;
1105           }
1106         if (LocaleCompare("flatten",option+1) == 0)
1107           break;
1108         if (LocaleCompare("flip",option+1) == 0)
1109           break;
1110         if (LocaleCompare("flop",option+1) == 0)
1111           break;
1112         if (LocaleCompare("font",option+1) == 0)
1113           {
1114             if (*option == '+')
1115               break;
1116             i++;
1117             if (i == (ssize_t) argc)
1118               ThrowDisplayException(OptionError,"MissingArgument",option);
1119             resource_info.font=XGetResourceClass(resource_database,
1120               GetClientName(),"font",argv[i]);
1121             break;
1122           }
1123         if (LocaleCompare("foreground",option+1) == 0)
1124           {
1125             if (*option == '+')
1126               break;
1127             i++;
1128             if (i == (ssize_t) argc)
1129               ThrowDisplayException(OptionError,"MissingArgument",option);
1130             resource_info.foreground_color=argv[i];
1131             break;
1132           }
1133         if (LocaleCompare("format",option+1) == 0)
1134           {
1135             if (*option == '+')
1136               break;
1137             i++;
1138             if (i == (ssize_t) (argc-1))
1139               ThrowDisplayException(OptionError,"MissingArgument",option);
1140             break;
1141           }
1142         if (LocaleCompare("frame",option+1) == 0)
1143           {
1144             if (*option == '+')
1145               break;
1146             i++;
1147             if (i == (ssize_t) argc)
1148               ThrowDisplayException(OptionError,"MissingArgument",option);
1149             if (IsGeometry(argv[i]) == MagickFalse)
1150               ThrowDisplayInvalidArgumentException(option,argv[i]);
1151             break;
1152           }
1153         if (LocaleCompare("fuzz",option+1) == 0)
1154           {
1155             if (*option == '+')
1156               break;
1157             i++;
1158             if (i == (ssize_t) (argc-1))
1159               ThrowDisplayException(OptionError,"MissingArgument",option);
1160             if (IsGeometry(argv[i]) == MagickFalse)
1161               ThrowDisplayInvalidArgumentException(option,argv[i]);
1162             break;
1163           }
1164         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1165       }
1166       case 'g':
1167       {
1168         if (LocaleCompare("gamma",option+1) == 0)
1169           {
1170             i++;
1171             if (i == (ssize_t) argc)
1172               ThrowDisplayException(OptionError,"MissingArgument",option);
1173             if (IsGeometry(argv[i]) == MagickFalse)
1174               ThrowDisplayInvalidArgumentException(option,argv[i]);
1175             break;
1176           }
1177         if (LocaleCompare("geometry",option+1) == 0)
1178           {
1179             resource_info.image_geometry=(char *) NULL;
1180             if (*option == '+')
1181               break;
1182             (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
1183             i++;
1184             if (i == (ssize_t) argc)
1185               ThrowDisplayException(OptionError,"MissingArgument",option);
1186             if (IsGeometry(argv[i]) == MagickFalse)
1187               ThrowDisplayInvalidArgumentException(option,argv[i]);
1188             resource_info.image_geometry=ConstantString(argv[i]);
1189             break;
1190           }
1191         if (LocaleCompare("gravity",option+1) == 0)
1192           {
1193             ssize_t
1194               gravity;
1195
1196             if (*option == '+')
1197               break;
1198             i++;
1199             if (i == (ssize_t) (argc-1))
1200               ThrowDisplayException(OptionError,"MissingArgument",option);
1201             gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
1202               argv[i]);
1203             if (gravity < 0)
1204               ThrowDisplayException(OptionError,"UnrecognizedGravityType",
1205                 argv[i]);
1206             break;
1207           }
1208         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1209       }
1210       case 'h':
1211       {
1212         if ((LocaleCompare("help",option+1) == 0) ||
1213             (LocaleCompare("-help",option+1) == 0))
1214           break;
1215         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1216       }
1217       case 'i':
1218       {
1219         if (LocaleCompare("identify",option+1) == 0)
1220           break;
1221         if (LocaleCompare("iconGeometry",option+1) == 0)
1222           {
1223             resource_info.icon_geometry=(char *) NULL;
1224             if (*option == '+')
1225               break;
1226             i++;
1227             if (i == (ssize_t) argc)
1228               ThrowDisplayException(OptionError,"MissingArgument",option);
1229             if (IsGeometry(argv[i]) == MagickFalse)
1230               ThrowDisplayInvalidArgumentException(option,argv[i]);
1231             resource_info.icon_geometry=argv[i];
1232             break;
1233           }
1234         if (LocaleCompare("iconic",option+1) == 0)
1235           {
1236             resource_info.iconic=(*option == '-') ? MagickTrue : MagickFalse;
1237             break;
1238           }
1239         if (LocaleCompare("immutable",option+1) == 0)
1240           {
1241             resource_info.immutable=(*option == '-') ? MagickTrue : MagickFalse;
1242             break;
1243           }
1244         if (LocaleCompare("interlace",option+1) == 0)
1245           {
1246             ssize_t
1247               interlace;
1248
1249             if (*option == '+')
1250               break;
1251             i++;
1252             if (i == (ssize_t) argc)
1253               ThrowDisplayException(OptionError,"MissingArgument",option);
1254             interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
1255               argv[i]);
1256             if (interlace < 0)
1257               ThrowDisplayException(OptionError,"UnrecognizedInterlaceType",
1258                 argv[i]);
1259             break;
1260           }
1261         if (LocaleCompare("interpolate",option+1) == 0)
1262           {
1263             ssize_t
1264               interpolate;
1265
1266             if (*option == '+')
1267               break;
1268             i++;
1269             if (i == (ssize_t) argc)
1270               ThrowDisplayException(OptionError,"MissingArgument",option);
1271             interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
1272               argv[i]);
1273             if (interpolate < 0)
1274               ThrowDisplayException(OptionError,"UnrecognizedInterpolateMethod",
1275                 argv[i]);
1276             break;
1277           }
1278         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1279       }
1280       case 'l':
1281       {
1282         if (LocaleCompare("label",option+1) == 0)
1283           {
1284             if (*option == '+')
1285               break;
1286             i++;
1287             if (i == (ssize_t) argc)
1288               ThrowDisplayException(OptionError,"MissingArgument",option);
1289             break;
1290           }
1291         if (LocaleCompare("limit",option+1) == 0)
1292           {
1293             char
1294               *p;
1295
1296             double
1297               value;
1298
1299             ssize_t
1300               resource;
1301
1302             if (*option == '+')
1303               break;
1304             i++;
1305             if (i == (ssize_t) argc)
1306               ThrowDisplayException(OptionError,"MissingArgument",option);
1307             resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
1308               argv[i]);
1309             if (resource < 0)
1310               ThrowDisplayException(OptionError,"UnrecognizedResourceType",
1311                 argv[i]);
1312             i++;
1313             if (i == (ssize_t) argc)
1314               ThrowDisplayException(OptionError,"MissingArgument",option);
1315             value=StringToDouble(argv[i],&p);
1316             (void) value;
1317             if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
1318               ThrowDisplayInvalidArgumentException(option,argv[i]);
1319             break;
1320           }
1321         if (LocaleCompare("list",option+1) == 0)
1322           {
1323             ssize_t
1324               list;
1325
1326             if (*option == '+')
1327               break;
1328             i++;
1329             if (i == (ssize_t) argc)
1330               ThrowDisplayException(OptionError,"MissingArgument",option);
1331             list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
1332             if (list < 0)
1333               ThrowDisplayException(OptionError,"UnrecognizedListType",argv[i]);
1334             status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
1335               argv+j,exception);
1336             DestroyDisplay();
1337             return(status != 0 ? MagickFalse : MagickTrue);
1338           }
1339         if (LocaleCompare("log",option+1) == 0)
1340           {
1341             if (*option == '+')
1342               break;
1343             i++;
1344             if ((i == (ssize_t) argc) ||
1345                 (strchr(argv[i],'%') == (char *) NULL))
1346               ThrowDisplayException(OptionError,"MissingArgument",option);
1347             break;
1348           }
1349         if (LocaleCompare("loop",option+1) == 0)
1350           {
1351             if (*option == '+')
1352               break;
1353             i++;
1354             if (i == (ssize_t) (argc-1))
1355               ThrowDisplayException(OptionError,"MissingArgument",option);
1356             if (IsGeometry(argv[i]) == MagickFalse)
1357               ThrowDisplayInvalidArgumentException(option,argv[i]);
1358             iterations=StringToUnsignedLong(argv[i]);
1359             break;
1360           }
1361         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1362       }
1363       case 'm':
1364       {
1365         if (LocaleCompare("magnify",option+1) == 0)
1366           {
1367             resource_info.magnify=2;
1368             if (*option == '+')
1369               break;
1370             i++;
1371             if (i == (ssize_t) argc)
1372               ThrowDisplayException(OptionError,"MissingArgument",option);
1373             if (IsGeometry(argv[i]) == MagickFalse)
1374               ThrowDisplayInvalidArgumentException(option,argv[i]);
1375             resource_info.magnify=(unsigned int) StringToUnsignedLong(argv[i]);
1376             break;
1377           }
1378         if (LocaleCompare("map",option+1) == 0)
1379           {
1380             resource_info.map_type=(char *) NULL;
1381             if (*option == '+')
1382               break;
1383             (void) strcpy(argv[i]+1,"san");
1384             i++;
1385             if (i == (ssize_t) argc)
1386               ThrowDisplayException(OptionError,"MissingArgument",option);
1387             resource_info.map_type=argv[i];
1388             break;
1389           }
1390         if (LocaleCompare("matte",option+1) == 0)
1391           break;
1392         if (LocaleCompare("mattecolor",option+1) == 0)
1393           {
1394             if (*option == '+')
1395               break;
1396             i++;
1397             if (i == (ssize_t) argc)
1398               ThrowDisplayException(OptionError,"MissingArgument",option);
1399             resource_info.matte_color=argv[i];
1400             break;
1401           }
1402         if (LocaleCompare("monitor",option+1) == 0)
1403           break;
1404         if (LocaleCompare("monochrome",option+1) == 0)
1405           {
1406             if (*option == '+')
1407               break;
1408             quantize_info->number_colors=2;
1409             quantize_info->colorspace=GRAYColorspace;
1410             break;
1411           }
1412         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1413       }
1414       case 'n':
1415       {
1416         if (LocaleCompare("name",option+1) == 0)
1417           {
1418             resource_info.name=(char *) NULL;
1419             if (*option == '+')
1420               break;
1421             i++;
1422             if (i == (ssize_t) argc)
1423               ThrowDisplayException(OptionError,"MissingArgument",option);
1424             resource_info.name=ConstantString(argv[i]);
1425             break;
1426           }
1427         if (LocaleCompare("negate",option+1) == 0)
1428           break;
1429         if (LocaleCompare("noop",option+1) == 0)
1430           break;
1431         if (LocaleCompare("normalize",option+1) == 0)
1432           break;
1433         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1434       }
1435       case 'p':
1436       {
1437         if (LocaleCompare("page",option+1) == 0)
1438           {
1439             resource_info.image_geometry=(char *) NULL;
1440             if (*option == '+')
1441               break;
1442             i++;
1443             if (i == (ssize_t) argc)
1444               ThrowDisplayException(OptionError,"MissingArgument",option);
1445             resource_info.image_geometry=ConstantString(argv[i]);
1446             break;
1447           }
1448         if (LocaleCompare("profile",option+1) == 0)
1449           {
1450             i++;
1451             if (i == (ssize_t) argc)
1452               ThrowDisplayException(OptionError,"MissingArgument",option);
1453             break;
1454           }
1455         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1456       }
1457       case 'q':
1458       {
1459         if (LocaleCompare("quality",option+1) == 0)
1460           {
1461             if (*option == '+')
1462               break;
1463             i++;
1464             if (i == (ssize_t) argc)
1465               ThrowDisplayException(OptionError,"MissingArgument",option);
1466             if (IsGeometry(argv[i]) == MagickFalse)
1467               ThrowDisplayInvalidArgumentException(option,argv[i]);
1468             break;
1469           }
1470         if (LocaleCompare("quantize",option+1) == 0)
1471           {
1472             ssize_t
1473               colorspace;
1474
1475             if (*option == '+')
1476               break;
1477             i++;
1478             if (i == (ssize_t) (argc-1))
1479               ThrowDisplayException(OptionError,"MissingArgument",option);
1480             colorspace=ParseCommandOption(MagickColorspaceOptions,
1481               MagickFalse,argv[i]);
1482             if (colorspace < 0)
1483               ThrowDisplayException(OptionError,"UnrecognizedColorspace",
1484                 argv[i]);
1485             break;
1486           }
1487         if (LocaleCompare("quiet",option+1) == 0)
1488           break;
1489         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1490       }
1491       case 'r':
1492       {
1493         if (LocaleCompare("raise",option+1) == 0)
1494           {
1495             i++;
1496             if (i == (ssize_t) argc)
1497               ThrowDisplayException(OptionError,"MissingArgument",option);
1498             if (IsGeometry(argv[i]) == MagickFalse)
1499               ThrowDisplayInvalidArgumentException(option,argv[i]);
1500             break;
1501           }
1502         if (LocaleCompare("regard-warnings",option+1) == 0)
1503           break;
1504         if (LocaleCompare("remote",option+1) == 0)
1505           {
1506             i++;
1507             if (i == (ssize_t) argc)
1508               ThrowDisplayException(OptionError,"MissingArgument",option);
1509             if (XRemoteCommand(display,resource_info.window_id,argv[i]) != 0)
1510               return(MagickFalse);
1511             i--;
1512             break;
1513           }
1514         if (LocaleCompare("repage",option+1) == 0)
1515           {
1516             if (*option == '+')
1517               break;
1518             i++;
1519             if (i == (ssize_t) argc)
1520               ThrowDisplayException(OptionError,"MissingArgument",option);
1521             if (IsGeometry(argv[i]) == MagickFalse)
1522               ThrowDisplayInvalidArgumentException(option,argv[i]);
1523             break;
1524           }
1525         if (LocaleCompare("resample",option+1) == 0)
1526           {
1527             if (*option == '+')
1528               break;
1529             i++;
1530             if (i == (ssize_t) (argc-1))
1531               ThrowDisplayException(OptionError,"MissingArgument",option);
1532             if (IsGeometry(argv[i]) == MagickFalse)
1533               ThrowDisplayInvalidArgumentException(option,argv[i]);
1534             break;
1535           }
1536         if (LocaleCompare("resize",option+1) == 0)
1537           {
1538             if (*option == '+')
1539               break;
1540             i++;
1541             if (i == (ssize_t) argc)
1542               ThrowDisplayException(OptionError,"MissingArgument",option);
1543             if (IsGeometry(argv[i]) == MagickFalse)
1544               ThrowDisplayInvalidArgumentException(option,argv[i]);
1545             break;
1546           }
1547         if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1548           {
1549             respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1550             break;
1551           }
1552         if (LocaleCompare("roll",option+1) == 0)
1553           {
1554             if (*option == '+')
1555               break;
1556             i++;
1557             if (i == (ssize_t) argc)
1558               ThrowDisplayException(OptionError,"MissingArgument",option);
1559             if (IsGeometry(argv[i]) == MagickFalse)
1560               ThrowDisplayInvalidArgumentException(option,argv[i]);
1561             break;
1562           }
1563         if (LocaleCompare("rotate",option+1) == 0)
1564           {
1565             i++;
1566             if (i == (ssize_t) argc)
1567               ThrowDisplayException(OptionError,"MissingArgument",option);
1568             if (IsGeometry(argv[i]) == MagickFalse)
1569               ThrowDisplayInvalidArgumentException(option,argv[i]);
1570             break;
1571           }
1572         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1573       }
1574       case 's':
1575       {
1576         if (LocaleCompare("sample",option+1) == 0)
1577           {
1578             if (*option == '+')
1579               break;
1580             i++;
1581             if (i == (ssize_t) argc)
1582               ThrowDisplayException(OptionError,"MissingArgument",option);
1583             if (IsGeometry(argv[i]) == MagickFalse)
1584               ThrowDisplayInvalidArgumentException(option,argv[i]);
1585             break;
1586           }
1587         if (LocaleCompare("sampling-factor",option+1) == 0)
1588           {
1589             if (*option == '+')
1590               break;
1591             i++;
1592             if (i == (ssize_t) argc)
1593               ThrowDisplayException(OptionError,"MissingArgument",option);
1594             if (IsGeometry(argv[i]) == MagickFalse)
1595               ThrowDisplayInvalidArgumentException(option,argv[i]);
1596             break;
1597           }
1598         if (LocaleCompare("scenes",option+1) == 0)
1599           {
1600             if (*option == '+')
1601               break;
1602             i++;
1603             if (i == (ssize_t) argc)
1604               ThrowDisplayException(OptionError,"MissingArgument",option);
1605             if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
1606               ThrowDisplayInvalidArgumentException(option,argv[i]);
1607             break;
1608           }
1609         if (LocaleCompare("seed",option+1) == 0)
1610           {
1611             if (*option == '+')
1612               break;
1613             i++;
1614             if (i == (ssize_t) (argc-1))
1615               ThrowDisplayException(OptionError,"MissingArgument",option);
1616             if (IsGeometry(argv[i]) == MagickFalse)
1617               ThrowDisplayInvalidArgumentException(option,argv[i]);
1618             break;
1619           }
1620         if (LocaleCompare("segment",option+1) == 0)
1621           {
1622             if (*option == '+')
1623               break;
1624             i++;
1625             if (i == (ssize_t) argc)
1626               ThrowDisplayException(OptionError,"MissingArgument",option);
1627             if (IsGeometry(argv[i]) == MagickFalse)
1628               ThrowDisplayInvalidArgumentException(option,argv[i]);
1629             break;
1630           }
1631         if (LocaleCompare("set",option+1) == 0)
1632           {
1633             i++;
1634             if (i == (ssize_t) argc)
1635               ThrowDisplayException(OptionError,"MissingArgument",option);
1636             if (*option == '+')
1637               break;
1638             i++;
1639             if (i == (ssize_t) argc)
1640               ThrowDisplayException(OptionError,"MissingArgument",option);
1641             break;
1642           }
1643         if (LocaleCompare("sharpen",option+1) == 0)
1644           {
1645             if (*option == '+')
1646               break;
1647             i++;
1648             if (i == (ssize_t) argc)
1649               ThrowDisplayException(OptionError,"MissingArgument",option);
1650             if (IsGeometry(argv[i]) == MagickFalse)
1651               ThrowDisplayInvalidArgumentException(option,argv[i]);
1652             break;
1653           }
1654         if (LocaleCompare("shared-memory",option+1) == 0)
1655           {
1656             resource_info.use_shared_memory= (*option == '-') ? MagickTrue :
1657               MagickFalse;
1658             break;
1659           }
1660         if (LocaleCompare("size",option+1) == 0)
1661           {
1662             if (*option == '+')
1663               break;
1664             i++;
1665             if (i == (ssize_t) argc)
1666               ThrowDisplayException(OptionError,"MissingArgument",option);
1667             if (IsGeometry(argv[i]) == MagickFalse)
1668               ThrowDisplayInvalidArgumentException(option,argv[i]);
1669             break;
1670           }
1671         if (LocaleCompare("strip",option+1) == 0)
1672           break;
1673         if (LocaleCompare("support",option+1) == 0)
1674           {
1675             i++;  /* deprecated */
1676             break;
1677           }
1678         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1679       }
1680       case 't':
1681       {
1682         if (LocaleCompare("text-font",option+1) == 0)
1683           {
1684             resource_info.text_font=(char *) NULL;
1685             if (*option == '+')
1686               break;
1687             i++;
1688             if (i == (ssize_t) argc)
1689               ThrowDisplayException(OptionError,"MissingArgument",option);
1690             resource_info.text_font=XGetResourceClass(resource_database,
1691               GetClientName(),"font",argv[i]);
1692             break;
1693           }
1694         if (LocaleCompare("texture",option+1) == 0)
1695           {
1696             if (*option == '+')
1697               break;
1698             i++;
1699             if (i == (ssize_t) argc)
1700               ThrowDisplayException(OptionError,"MissingArgument",option);
1701             break;
1702           }
1703         if (LocaleCompare("threshold",option+1) == 0)
1704           {
1705             if (*option == '+')
1706               break;
1707             i++;
1708             if (i == (ssize_t) argc)
1709               ThrowDisplayException(OptionError,"MissingArgument",option);
1710             if (IsGeometry(argv[i]) == MagickFalse)
1711               ThrowDisplayInvalidArgumentException(option,argv[i]);
1712             break;
1713           }
1714         if (LocaleCompare("thumbnail",option+1) == 0)
1715           {
1716             if (*option == '+')
1717               break;
1718             i++;
1719             if (i == (ssize_t) argc)
1720               ThrowDisplayException(OptionError,"MissingArgument",option);
1721             if (IsGeometry(argv[i]) == MagickFalse)
1722               ThrowDisplayInvalidArgumentException(option,argv[i]);
1723             break;
1724           }
1725         if (LocaleCompare("title",option+1) == 0)
1726           {
1727             resource_info.title=(char *) NULL;
1728             if (*option == '+')
1729               break;
1730             i++;
1731             if (i == (ssize_t) argc)
1732               ThrowDisplayException(OptionError,"MissingArgument",option);
1733             resource_info.title=argv[i];
1734             break;
1735           }
1736         if (LocaleCompare("transparent-color",option+1) == 0)
1737           {
1738             if (*option == '+')
1739               break;
1740             i++;
1741             if (i == (ssize_t) (argc-1))
1742               ThrowDisplayException(OptionError,"MissingArgument",option);
1743             break;
1744           }
1745         if (LocaleCompare("treedepth",option+1) == 0)
1746           {
1747             quantize_info->tree_depth=0;
1748             if (*option == '+')
1749               break;
1750             i++;
1751             if (i == (ssize_t) argc)
1752               ThrowDisplayException(OptionError,"MissingArgument",option);
1753             if (IsGeometry(argv[i]) == MagickFalse)
1754               ThrowDisplayInvalidArgumentException(option,argv[i]);
1755             quantize_info->tree_depth=StringToUnsignedLong(argv[i]);
1756             break;
1757           }
1758         if (LocaleCompare("trim",option+1) == 0)
1759           break;
1760         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1761       }
1762       case 'u':
1763       {
1764         if (LocaleCompare("update",option+1) == 0)
1765           {
1766             resource_info.update=(unsigned int) (*option == '-');
1767             if (*option == '+')
1768               break;
1769             i++;
1770             if (i == (ssize_t) argc)
1771               ThrowDisplayException(OptionError,"MissingArgument",option);
1772             if (IsGeometry(argv[i]) == MagickFalse)
1773               ThrowDisplayInvalidArgumentException(option,argv[i]);
1774             resource_info.update=(unsigned int) StringToUnsignedLong(argv[i]);
1775             break;
1776           }
1777         if (LocaleCompare("use-pixmap",option+1) == 0)
1778           {
1779             resource_info.use_pixmap=(*option == '-') ? MagickTrue :
1780               MagickFalse;
1781             break;
1782           }
1783         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1784       }
1785       case 'v':
1786       {
1787         if (LocaleCompare("verbose",option+1) == 0)
1788           break;
1789         if ((LocaleCompare("version",option+1) == 0) ||
1790             (LocaleCompare("-version",option+1) == 0))
1791           {
1792             ListMagickVersion(stdout);
1793             break;
1794           }
1795         if (LocaleCompare("visual",option+1) == 0)
1796           {
1797             resource_info.visual_type=(char *) NULL;
1798             if (*option == '+')
1799               break;
1800             i++;
1801             if (i == (ssize_t) argc)
1802               ThrowDisplayException(OptionError,"MissingArgument",option);
1803             resource_info.visual_type=argv[i];
1804             break;
1805           }
1806         if (LocaleCompare("virtual-pixel",option+1) == 0)
1807           {
1808             ssize_t
1809               method;
1810
1811             if (*option == '+')
1812               break;
1813             i++;
1814             if (i == (ssize_t) (argc-1))
1815               ThrowDisplayException(OptionError,"MissingArgument",option);
1816             method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
1817               argv[i]);
1818             if (method < 0)
1819               ThrowDisplayException(OptionError,
1820                 "UnrecognizedVirtualPixelMethod",argv[i]);
1821             break;
1822           }
1823         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1824       }
1825       case 'w':
1826       {
1827         if (LocaleCompare("window",option+1) == 0)
1828           {
1829             resource_info.window_id=(char *) NULL;
1830             if (*option == '+')
1831               break;
1832             i++;
1833             if (i == (ssize_t) argc)
1834               ThrowDisplayException(OptionError,"MissingArgument",option);
1835             resource_info.window_id=argv[i];
1836             break;
1837           }
1838         if (LocaleCompare("window-group",option+1) == 0)
1839           {
1840             resource_info.window_group=(char *) NULL;
1841             if (*option == '+')
1842               break;
1843             i++;
1844             if (i == (ssize_t) argc)
1845               ThrowDisplayException(OptionError,"MissingArgument",option);
1846             if (StringToDouble(argv[i],(char **) NULL) != 0)
1847               resource_info.window_group=argv[i];
1848             break;
1849           }
1850         if (LocaleCompare("write",option+1) == 0)
1851           {
1852             resource_info.write_filename=(char *) NULL;
1853             if (*option == '+')
1854               break;
1855             i++;
1856             if (i == (ssize_t) argc)
1857               ThrowDisplayException(OptionError,"MissingArgument",option);
1858             resource_info.write_filename=argv[i];
1859             if (IsPathAccessible(resource_info.write_filename) != MagickFalse)
1860               {
1861                 char
1862                   answer[2],
1863                   *p;
1864
1865                 (void) FormatLocaleFile(stderr,"Overwrite %s? ",
1866                   resource_info.write_filename);
1867                 p=fgets(answer,(int) sizeof(answer),stdin);
1868                 (void) p;
1869                 if (((*answer != 'y') && (*answer != 'Y')))
1870                   return(MagickFalse);
1871               }
1872             break;
1873           }
1874         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1875       }
1876       case '?':
1877         break;
1878       default:
1879         ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1880     }
1881     fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1882       FireOptionFlag) == 0 ?  MagickFalse : MagickTrue;
1883     if (fire != MagickFalse)
1884       FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1885   }
1886   if (k != 0)
1887     ThrowDisplayException(OptionError,"UnbalancedParenthesis",argv[i]);
1888   if (state & RetainColorsState)
1889     {
1890       XRetainWindowColors(display,XRootWindow(display,XDefaultScreen(display)));
1891       (void) XSync(display,MagickFalse);
1892     }
1893   DestroyDisplay();
1894   return(status != 0 ? MagickTrue : MagickFalse);
1895 #else
1896   (void) argc;
1897   (void) argv;
1898   (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
1899     "DelegateLibrarySupportNotBuiltIn","'%s' (X11)",image_info->filename);
1900   return(DisplayUsage());
1901 #endif
1902 }