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