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