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