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