root / ImageMagick / trunk / wand / display.c

Revision 11956, 64.9 kB (checked in by cristy, 11 days ago)
Line 
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-2008 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%
37*/
38
39/*
40  Include declarations.
41*/
42#include "wand/studio.h"
43#include "wand/MagickWand.h"
44#include "wand/mogrify-private.h"
45#include "magick/display-private.h"
46
47/*
48%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49%                                                                             %
50%                                                                             %
51%                                                                             %
52+   D i s p l a y I m a g e C o m m a n d                                     %
53%                                                                             %
54%                                                                             %
55%                                                                             %
56%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57%
58%  DisplayImageCommand() displays a sequence of images on any workstation
59%  display running an X server.  Display first determines the hardware
60%  capabilities of the workstation. If the number of unique colors in an image
61%  is less than or equal to the number the workstation can support, the image
62%  is displayed in an X window. Otherwise the number of colors in the image is
63%  first reduced to match the color resolution of the workstation before it is
64%  displayed.
65%
66%  This means that a continuous-tone 24 bits/pixel image can display on a 8
67%  bit pseudo-color device or monochrome device. In most instances the reduced
68%  color image closely resembles the original. Alternatively, a monochrome or
69%  pseudo-color image sequence can display on a continuous-tone 24 bits/pixels
70%  device.
71%
72%  The format of the DisplayImageCommand method is:
73%
74%      MagickBooleanType DisplayImageCommand(ImageInfo *image_info,int argc,
75%        char **argv,char **metadata,ExceptionInfo *exception)
76%
77%  A description of each parameter follows:
78%
79%    o image_info: the image info.
80%
81%    o argc: the number of elements in the argument vector.
82%
83%    o argv: A text array containing the command line arguments.
84%
85%    o metadata: any metadata is returned here.
86%
87%    o exception: Return any errors or warnings in this structure.
88%
89*/
90
91static void DisplayUsage(void)
92{
93  const char
94    **p;
95
96  static const char
97    *buttons[]=
98    {
99      "1    press to map or unmap the Command widget",
100      "2    press and drag to magnify a region of an image",
101      "3    press to load an image from a visual image directory",
102      (char *) NULL
103    },
104    *miscellaneous[]=
105    {
106      "-debug events        display copious debugging information",
107      "-help                print program options",
108      "-list type           print a list of supported option arguments",
109      "-log format          format of debugging information",
110      "-version             print version information",
111      (char *) NULL
112    },
113    *operators[]=
114    {
115      "-auto-orient         automatically orient image",
116      "-border geometry     surround image with a border of color",
117      "-clip                clip along the first path from the 8BIM profile",
118      "-clip-path id        clip along a named path from the 8BIM profile",
119      "-colors value        preferred number of colors in the image",
120      "-contrast            enhance or reduce the image contrast",
121      "-crop geometry       preferred size and location of the cropped image",
122      "-decipher filename   convert cipher pixels to plain pixels",
123      "-deskew threshold    straighten an image",
124      "-despeckle           reduce the speckles within an image",
125      "-edge factor         apply a filter to detect edges in the image",
126      "-enhance             apply a digital filter to enhance a noisy image",
127      "-extract geometry    extract area from image",
128      "-flip                flip image in the vertical direction",
129      "-flop                flop image in the horizontal direction",
130      "-frame geometry      surround image with an ornamental border",
131      "-fuzz distance       colors within this distance are considered equal",
132      "-gamma value         level of gamma correction",
133      "-monochrome          transform image to black and white",
134      "-negate              replace every pixel with its complementary color",
135      "-raise value         lighten/darken image edges to create a 3-D effect",
136      "-resample geometry   change the resolution of an image",
137      "-resize geometry     resize the image",
138      "-roll geometry       roll an image vertically or horizontally",
139      "-rotate degrees      apply Paeth rotation to the image",
140      "-sample geometry     scale image with pixel sampling",
141      "-segment value       segment an image",
142      "-sharpen geometry    sharpen the image",
143      "-strip               strip image of all profiles and comments",
144      "-threshold value     threshold the image",
145      "-trim                trim image edges",
146      (char *) NULL
147    },
148    *settings[]=
149    {
150      "-alpha option        activate, deactivate, reset, or set the alpha channel",
151      "-antialias           remove pixel-aliasing",
152      "-authenticate password",
153      "                     decipher image with this password",
154      "-backdrop            display image centered on a backdrop",
155      "-channel type        apply option to select image channels",
156      "-colormap type       Shared or Private",
157      "-colorspace type     alternate image colorspace",
158      "-comment string      annotate image with comment",
159      "-compress type       type of pixel compression when writing the image",
160      "-define format:option",
161      "                     define one or more image format options",
162      "-delay value         display the next image after pausing",
163      "-density geometry    horizontal and vertical density of the image",
164      "-depth value         image depth",
165      "-display server      display image to this X server",
166      "-dispose method      layer disposal method",
167      "-dither method       apply error diffusion to image",
168      "-endian type         endianness (MSB or LSB) of the image",
169      "-filter type         use this filter when resizing an image",
170      "-format \"string\"     output formatted image characteristics",
171      "-geometry geometry   preferred size and location of the Image window",
172      "-identify            identify the format and characteristics of the image",
173      "-immutable           displayed image cannot be modified",
174      "-interlace type      type of image interlacing scheme",
175      "-interpolate method  pixel color interpolation method",
176      "-label string        assign a label to an image",
177      "-limit type value    pixel cache resource limit",
178      "-loop iterations     loop images then exit",
179      "-map type            display image using this Standard Colormap",
180      "-monitor             monitor progress",
181      "-page geometry       size and location of an image canvas",
182      "-profile filename    add, delete, or apply an image profile",
183      "-quality value       JPEG/MIFF/PNG compression level",
184      "-quantize colorspace reduce colors in this colorspace",
185      "-quiet               suppress all warning messages",
186      "-regard-warnings     pay attention to warning messages",
187      "-remote command      execute a command in an remote display process",
188      "-repage geometry     size and location of an image canvas (operator)",
189      "-respect-parenthesis settings remain in effect until parenthesis boundary",
190      "-sampling-factor geometry",
191      "                     horizontal and vertical sampling factor",
192      "-scenes range        image scene range",
193      "-seed value          seed a new sequence of pseudo-random numbers",
194      "-set property value  set an image property",
195      "-size geometry       width and height of image",
196      "-texture filename    name of texture to tile onto the image background",
197      "-transparent-color color",
198      "                     transparent color",
199      "-treedepth value     color tree depth",
200      "-update seconds      detect when image file is modified and redisplay",
201      "-verbose             print detailed information about the image",
202      "-visual type         display image using this visual type",
203      "-virtual-pixel method",
204      "                     virtual pixel access method",
205      "-window id           display image to background of this window",
206      "-window-group id     exit program when this window id is destroyed",
207      "-write filename      write image to a file",
208      (char *) NULL
209    },
210    *sequence_operators[]=
211    {
212      "-coalesce            merge a sequence of images",
213      "-flatten             flatten a sequence of images",
214      (char *) NULL
215    };
216
217  (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
218  (void) printf("Copyright: %s\n\n",GetMagickCopyright());
219  (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
220    GetClientName());
221  (void) printf("\nImage Settings:\n");
222  for (p=settings; *p != (char *) NULL; p++)
223    (void) printf("  %s\n",*p);
224  (void) printf("\nImage Operators:\n");
225  for (p=operators; *p != (char *) NULL; p++)
226    (void) printf("  %s\n",*p);
227  (void) printf("\nImage Sequence Operators:\n");
228  for (p=sequence_operators; *p != (char *) NULL; p++)
229    (void) printf("  %s\n",*p);
230  (void) printf("\nMiscellaneous Options:\n");
231  for (p=miscellaneous; *p != (char *) NULL; p++)
232    (void) printf("  %s\n",*p);
233  (void) printf(
234    "\nIn addition to those listed above, you can specify these standard X\n");
235  (void) printf(
236    "resources as command line options:  -background, -bordercolor,\n");
237  (void) printf(
238    "-borderwidth, -font, -foreground, -iconGeometry, -iconic, -mattecolor,\n");
239  (void) printf("-name, -shared-memory, -usePixmap, or -title.\n");
240  (void) printf(
241    "\nBy default, the image format of `file' is determined by its magic\n");
242  (void) printf(
243    "number.  To specify a particular image format, precede the filename\n");
244  (void) printf(
245    "with an image format name and a colon (i.e. ps:image) or specify the\n");
246  (void) printf(
247    "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
248  (void) printf("'-' for standard input or output.\n");
249  (void) printf("\nButtons: \n");
250  for (p=buttons; *p != (char *) NULL; p++)
251    (void) printf("  %s\n",*p);
252  exit(0);
253}
254
255WandExport MagickBooleanType DisplayImageCommand(ImageInfo *image_info,
256  int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
257{
258#if defined(MAGICKCORE_X11_DELEGATE)
259#define DestroyDisplay() \
260{ \
261  if ((state & ExitState) == 0) \
262    DestroyXResources(); \
263  if (display != (Display *) NULL) \
264    { \
265      XCloseDisplay(display); \
266      display=(Display *) NULL; \
267    } \
268  XDestroyResourceInfo(&resource_info); \
269  DestroyImageStack(); \
270  if (image_marker != (unsigned long *) NULL) \
271    image_marker=(unsigned long *) RelinquishMagickMemory(image_marker); \
272  for (i=0; i < (long) argc; i++) \
273    argv[i]=DestroyString(argv[i]); \
274  argv=(char **) RelinquishMagickMemory(argv); \
275}
276#define ThrowDisplayException(asperity,tag,option) \
277{ \
278  (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
279    option); \
280  DestroyDisplay(); \
281  return(MagickFalse); \
282}
283#define ThrowDisplayInvalidArgumentException(option,argument) \
284{ \
285  (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
286    "InvalidArgument","`%s': %s",argument,option); \
287  DestroyDisplay(); \
288  return(MagickFalse); \
289}
290
291  char
292    *resource_value,
293    *server_name;
294
295  const char
296    *option;
297
298  Display
299    *display;
300
301  Image
302    *image;
303
304  ImageStack
305    image_stack[MaxImageStackDepth+1];
306
307  long
308    first_scene,
309    image_number,
310    iteration,
311    j,
312    k,
313    l,
314    last_scene,
315    scene;
316
317  MagickBooleanType
318    fire;
319
320  MagickStatusType
321    pend,
322    status;
323
324  QuantizeInfo
325    *quantize_info;
326
327  register long
328    i;
329
330  unsigned long
331    *image_marker,
332    iterations,
333    last_image,
334    state;
335
336  XResourceInfo
337    resource_info;
338
339  XrmDatabase
340    resource_database;
341
342  /*
343    Set defaults.
344  */
345  assert(image_info != (ImageInfo *) NULL);
346  assert(image_info->signature == MagickSignature);
347  if (image_info->debug != MagickFalse)
348    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
349  assert(exception != (ExceptionInfo *) NULL);
350  if (argc == 2)
351    {
352      option=argv[1];
353      if ((LocaleCompare("version",option+1) == 0) ||
354          (LocaleCompare("-version",option+1) == 0))
355        {
356          (void) fprintf(stdout,"Version: %s\n",
357            GetMagickVersion((unsigned long *) NULL));
358          (void) fprintf(stdout,"Copyright: %s\n\n",GetMagickCopyright());
359          return(MagickFalse);
360        }
361    }
362  SetNotifyHandlers;
363  display=(Display *) NULL;
364  first_scene=0;
365  j=1;
366  k=0;
367  image_marker=(unsigned long *) NULL;
368  image_number=0;
369  last_image=0;
370  last_scene=0;
371  NewImageStack();
372  option=(char *) NULL;
373  pend=MagickFalse;
374  resource_database=(XrmDatabase) NULL;
375  (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info));
376  server_name=(char *) NULL;
377  state=0;
378  status=MagickTrue;
379  ReadCommandlLine(argc,&argv);
380  status=ExpandFilenames(&argc,&argv);
381  if (status == MagickFalse)
382    ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
383      strerror(errno));
384  image_marker=(unsigned long *) AcquireQuantumMemory((size_t) argc+1UL,
385    sizeof(*image_marker));
386  if (image_marker == (unsigned long *) NULL)
387    ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
388      strerror(errno));
389  for (i=0; i <= argc; i++)
390    image_marker[i]=(unsigned long) argc;
391  /*
392    Check for server name specified on the command line.
393  */
394  for (i=1; i < (long) argc; i++)
395  {
396    /*
397      Check command line for server name.
398    */
399    option=argv[i];
400    if (IsMagickOption(option) == MagickFalse)
401      continue;
402    if (LocaleCompare("display",option+1) == 0)
403      {
404        /*
405          User specified server name.
406        */
407        i++;
408        if (i == (long) argc)
409          ThrowDisplayException(OptionError,"MissingArgument",option);
410        server_name=argv[i];
411      }
412    if ((LocaleCompare("help",option+1) == 0) ||
413        (LocaleCompare("-help",option+1) == 0))
414      DisplayUsage();
415  }
416  /*
417    Get user defaults from X resource database.
418  */
419  display=XOpenDisplay(server_name);
420  if (display == (Display *) NULL)
421    ThrowDisplayException(XServerError,"UnableToOpenXServer",
422      XDisplayName(server_name));
423  (void) XSetErrorHandler(XError);
424  resource_database=XGetResourceDatabase(display,GetClientName());
425  XGetResourceInfo(image_info,resource_database,GetClientName(),
426    &resource_info);
427  quantize_info=resource_info.quantize_info;
428  image_info->density=XGetResourceInstance(resource_database,GetClientName(),
429    "density",(char *) NULL);
430  if (image_info->density == (char *) NULL)
431    image_info->density=XGetScreenDensity(display);
432  resource_value=XGetResourceInstance(resource_database,GetClientName(),
433    "interlace","none");
434  image_info->interlace=(InterlaceType)
435    ParseMagickOption(MagickInterlaceOptions,MagickFalse,resource_value);
436  image_info->page=XGetResourceInstance(resource_database,GetClientName(),
437    "pageGeometry",(char *) NULL);
438  resource_value=XGetResourceInstance(resource_database,GetClientName(),
439    "quality","75");
440  image_info->quality=(unsigned long) atol(resource_value);
441  resource_value=XGetResourceInstance(resource_database,GetClientName(),
442    "verbose","False");
443  image_info->verbose=IsMagickTrue(resource_value);
444  resource_value=XGetResourceInstance(resource_database,GetClientName(),
445    "dither","True");
446  quantize_info->dither=IsMagickTrue(resource_value);
447  /*
448    Parse command line.
449  */
450  iteration=0;
451  iterations=0;
452  for (i=1; ((i <= (long) argc) && ((state & ExitState) == 0)); i++)
453  {
454    if (i < (long) argc)
455      option=argv[i];
456    else
457      if (image != (Image *) NULL)
458        break;
459      else
460        if (isatty(STDIN_FILENO) != MagickFalse)
461          option="logo:";
462        else
463          {
464            int
465              c;
466
467            c=getc(stdin);
468            if (c == EOF)
469              break;
470            else
471              {
472                c=ungetc(c,stdin);
473                option="-";
474              }
475          }
476    if (LocaleCompare(option,"(") == 0)
477      {
478        FireImageStack(MagickFalse,MagickTrue,pend);
479        if (k == MaxImageStackDepth)
480          ThrowDisplayException(OptionError,"ParenthesisNestedTooDeeply",
481            option);
482        PushImageStack();
483        continue;
484      }
485    if (LocaleCompare(option,")") == 0)
486      {
487        FireImageStack(MagickFalse,MagickTrue,MagickTrue);
488        if (k == 0)
489          ThrowDisplayException(OptionError,"UnableToParseExpression",option);
490        PopImageStack();
491        continue;
492      }
493    if (IsMagickOption(option) == MagickFalse)
494      {
495        /*
496          Option is a file name.
497        */
498        FireImageStack(MagickFalse,MagickFalse,pend);
499        for (scene=first_scene; scene <= last_scene ; scene++)
500        {
501          const char
502            *filename;
503
504          Image
505            *images;
506
507          /*
508            Read image.
509          */
510          filename=option;
511          if ((LocaleCompare(filename,"--") == 0) && (i < (argc-1)))
512            {
513              option=argv[++i];
514              filename=option;
515            }
516          (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
517          if (first_scene != last_scene)
518            {
519              char
520                filename[MaxTextExtent];
521
522              /*
523                Form filename for multi-part images.
524              */
525              (void) InterpretImageFilename(filename,MaxTextExtent,
526                image_info->filename,(int) scene);
527              if (LocaleCompare(filename,image_info->filename) == 0)
528                (void) FormatMagickString(filename,MaxTextExtent,"%s.%lu",
529                  image_info->filename,scene);
530              (void) CopyMagickString(image_info->filename,filename,
531                MaxTextExtent);
532            }
533          images=ReadImage(image_info,exception);
534          CatchException(exception);
535          status&=(images != (Image *) NULL) &&
536            (exception->severity < ErrorException);
537          if (images == (Image *) NULL)
538            continue;
539          AppendImageStack(images);
540          FireImageStack(MagickFalse,MagickFalse,MagickTrue);
541          do
542          {
543            /*
544              Transmogrify image as defined by the image processing options.
545            */
546            resource_info.quantum=1;
547            if (first_scene != last_scene)
548              image->scene=(unsigned long) scene;
549            if (resource_info.window_id != (char *) NULL)
550              {
551                /*
552                  Display image to a specified X window.
553                */
554                status=XDisplayBackgroundImage(display,&resource_info,
555                  image);
556                if (status != MagickFalse)
557                  state|=RetainColorsState;
558              }
559            else
560              do
561              {
562                Image
563                  *nexus;
564
565                /*
566                  Display image to X server.
567                */
568                nexus=XDisplayImage(display,&resource_info,argv,argc,
569                  &image,&state);
570                if (nexus == (Image *) NULL)
571                  break;
572                while ((nexus != (Image *) NULL) && ((state & ExitState) == 0))
573                {
574                  if (nexus->montage != (char *) NULL)
575                    {
576                      /*
577                        User selected a visual directory image (montage).
578                      */
579                      RemoveAllImageStack()
580                      image=nexus;
581                      break;
582                    }
583                  if (first_scene != last_scene)
584                    image->scene=(unsigned long) scene;
585                  image=XDisplayImage(display,&resource_info,argv,argc,&nexus,
586                    &state);
587                  if ((image == (Image *) NULL) &&
588                      (GetNextImageInList(nexus) != (Image *) NULL))
589                    {
590                      RemoveAllImageStack()
591                      image=GetNextImageInList(nexus);
592                      nexus=NewImageList();
593                    }
594                  else
595                    {
596                      if (nexus != image)
597                        nexus=DestroyImageList(nexus);
598                      nexus=image;
599                    }
600                }
601              } while ((state & ExitState) == 0);
602            if (resource_info.write_filename != (char *) NULL)
603              {
604                /*
605                  Write image.
606                */
607                (void) CopyMagickString(image->filename,
608                  resource_info.write_filename,MaxTextExtent);
609                (void) SetImageInfo(image_info,MagickTrue,
610                  &image->exception);
611                status&=WriteImage(image_info,image);
612                GetImageException(image,exception);
613              }
614            /*
615              Proceed to next/previous image.
616            */
617            image=image;
618            if ((state & FormerImageState) != 0)
619              for (l=0; l < resource_info.quantum; l++)
620              {
621                image=GetPreviousImageInList(image);
622                if (image == (Image *) NULL)
623                  break;
624              }
625            else
626              for (l=0; l < resource_info.quantum; l++)
627              {
628                image=GetNextImageInList(image);
629                if (image == (Image *) NULL)
630                  break;
631              }
632            if (image != (Image *) NULL)
633              image=image;
634          } while ((image != (Image *) NULL) && ((state & ExitState) == 0));
635          /*
636            Free image resources.
637          */
638          RemoveAllImageStack()
639          if ((state & FormerImageState) == 0)
640            {
641              last_image=(unsigned long) image_number;
642              image_marker[i]=(unsigned long) image_number++;
643            }
644          else
645            {
646              /*
647                Proceed to previous image.
648              */
649              for (i--; i > 0; i--)
650                if (image_marker[i] == (unsigned long) (image_number-2))
651                  break;
652              image_number--;
653            }
654          if ((i == (long) (argc-1)) && ((state & ExitState) == 0))
655            i=0;
656          if ((state & ExitState) != 0)
657            break;
658        }
659        /*
660          Determine if we should proceed to the first image.
661        */
662        if (image_number < 0)
663          {
664            if ((state & FormerImageState) != 0)
665              {
666
667                for (i=1; i < (argc-2); i++)
668                  if (last_image == image_marker[i])
669                    break;
670                image_number=(long) image_marker[i]+1;
671              }
672            continue;
673          }
674        if (resource_info.window_id != (char *) NULL)
675          state|=ExitState;
676        if (iterations != 0)
677          if (iteration == (long) iterations)
678            state|=ExitState;
679        iteration++;
680        continue;
681      }
682    pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
683    switch (*(option+1))
684    {
685      case 'a':
686      {
687        if (LocaleCompare("alpha",option+1) == 0)
688          {
689            long
690              type;
691
692            if (*option == '+')
693              break;
694            i++;
695            if (i == (long) argc)
696              ThrowDisplayException(OptionError,"MissingArgument",option);
697            type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
698            if (type < 0)
699              ThrowDisplayException(OptionError,"UnrecognizedAlphaChannelType",
700                argv[i]);
701            break;
702          }
703        if (LocaleCompare("antialias",option+1) == 0)
704          break;
705        if (LocaleCompare("authenticate",option+1) == 0)
706          {
707            if (*option == '+')
708              break;
709            i++;
710            if (i == (long) argc)
711              ThrowDisplayException(OptionError,"MissingArgument",option);
712            break;
713          }
714        if (LocaleCompare("auto-orient",option+1) == 0)
715          break;
716        ThrowDisplayException(OptionError,"UnrecognizedOption",option);
717      }
718      case 'b':
719      {
720        if (LocaleCompare("backdrop",option+1) == 0)
721          {
722            resource_info.backdrop=(*option == '-') ? MagickTrue : MagickFalse;
723            break;
724          }
725        if (LocaleCompare("background",option+1) == 0)
726          {
727            if (*option == '+')
728              break;
729            i++;
730            if (i == (long) argc)
731              ThrowDisplayException(OptionError,"MissingArgument",option);
732            resource_info.background_color=argv[i];
733            break;
734          }
735        if (LocaleCompare("border",option+1) == 0)
736          {
737            if (*option == '+')
738              break;
739            i++;
740            if (i == (long) argc)
741              ThrowDisplayException(OptionError,"MissingArgument",option);
742            if (IsGeometry(argv[i]) == MagickFalse)
743              ThrowDisplayInvalidArgumentException(option,argv[i]);
744            break;
745          }
746        if (LocaleCompare("bordercolor",option+1) == 0)
747          {
748            if (*option == '+')
749              break;
750            i++;
751            if (i == (long) argc)
752              ThrowDisplayException(OptionError,"MissingArgument",option);
753            resource_info.border_color=argv[i];
754            break;
755          }
756        if (LocaleCompare("borderwidth",option+1) == 0)
757          {
758            resource_info.border_width=0;
759            if (*option == '+')
760              break;
761            i++;
762            if (i == (long) argc)
763              ThrowDisplayException(OptionError,"MissingArgument",option);
764            if (IsGeometry(argv[i]) == MagickFalse)
765              ThrowDisplayInvalidArgumentException(option,argv[i]);
766            resource_info.border_width=(unsigned int) atoi(argv[i]);
767            break;
768          }
769        ThrowDisplayException(OptionError,"UnrecognizedOption",option);
770      }
771      case 'c':
772      {
773        if (LocaleCompare("cache",option+1) == 0)
774          {
775            if (*option == '+')
776              break;
777            i++;
778            if (i == (long) argc)
779              ThrowDisplayException(OptionError,"MissingArgument",option);
780            if (IsGeometry(argv[i]) == MagickFalse)
781              ThrowDisplayInvalidArgumentException(option,argv[i]);
782            break;
783          }
784        if (LocaleCompare("channel",option+1) == 0)
785          {
786            long
787              channel;
788
789            if (*option == '+')
790              break;
791            i++;
792            if (i == (long) (argc-1))
793              ThrowDisplayException(OptionError,"MissingArgument",option);
794            channel=ParseChannelOption(argv[i]);
795            if (channel < 0)
796              ThrowDisplayException(OptionError,"UnrecognizedChannelType",
797                argv[i]);
798            break;
799          }
800        if (LocaleCompare("clip",option+1) == 0)
801          break;
802        if (LocaleCompare("clip-path",option+1) == 0)
803          {
804            i++;
805            if (i == (long) argc)
806              ThrowDisplayException(OptionError,"MissingArgument",option);
807            break;
808          }
809        if (LocaleCompare("coalesce",option+1) == 0)
810          break;
811        if (LocaleCompare("colormap",option+1) == 0)
812          {
813            resource_info.colormap=PrivateColormap;
814            if (*option == '+')
815              break;
816            i++;
817            if (i == (long) argc)
818              ThrowDisplayException(OptionError,"MissingArgument",option);
819            resource_info.colormap=UndefinedColormap;
820            if (LocaleCompare("private",argv[i]) == 0)
821              resource_info.colormap=PrivateColormap;
822            if (LocaleCompare("shared",argv[i]) == 0)
823              resource_info.colormap=SharedColormap;
824            if (resource_info.colormap == UndefinedColormap)
825              ThrowDisplayException(OptionError,"UnrecognizedColormapType",
826                argv[i]);
827            break;
828          }
829        if (LocaleCompare("colors",option+1) == 0)
830          {
831            quantize_info->number_colors=0;
832            if (*option == '+')
833              break;
834            i++;
835            if (i == (long) argc)
836              ThrowDisplayException(OptionError,"MissingArgument",option);
837            if (IsGeometry(argv[i]) == MagickFalse)
838              ThrowDisplayInvalidArgumentException(option,argv[i]);
839            quantize_info->number_colors=(unsigned long) atol(argv[i]);
840            break;
841          }
842        if (LocaleCompare("colorspace",option+1) == 0)
843          {
844            long
845              colorspace;
846
847            if (*option == '+')
848              break;
849            i++;
850            if (i == (long) argc)
851              ThrowDisplayException(OptionError,"MissingArgument",option);
852            colorspace=ParseMagickOption(MagickColorspaceOptions,
853              MagickFalse,argv[i]);
854            if (colorspace < 0)
855              ThrowDisplayException(OptionError,"UnrecognizedColorspace",
856                argv[i]);
857            break;
858          }
859        if (LocaleCompare("comment",option+1) == 0)
860          {
861            if (*option == '+')
862              break;
863            i++;
864            if (i == (long) argc)
865              ThrowDisplayException(OptionError,"MissingArgument",option);
866            break;
867          }
868        if (LocaleCompare("compress",option+1) == 0)
869          {
870            long
871              compress;
872
873            if (*option == '+')
874              break;
875            i++;
876            if (i == (long) argc)
877              ThrowDisplayException(OptionError,"MissingArgument",option);
878            compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
879              argv[i]);
880            if (compress < 0)
881              ThrowDisplayException(OptionError,"UnrecognizedImageCompression",
882                argv[i]);
883            break;
884          }
885        if (LocaleCompare("contrast",option+1) == 0)
886          break;
887        if (LocaleCompare("crop",option+1) == 0)
888          {
889            if (*option == '+')
890              break;
891            i++;
892            if (i == (long) argc)
893              ThrowDisplayException(OptionError,"MissingArgument",option);
894            if (IsGeometry(argv[i]) == MagickFalse)
895              ThrowDisplayInvalidArgumentException(option,argv[i]);
896            break;
897          }
898        ThrowDisplayException(OptionError,"UnrecognizedOption",option);
899      }
900      case 'd':
901      {
902        if (LocaleCompare("debug",option+1) == 0)
903          {
904            long
905              event;
906
907            if (*option == '+')
908              break;
909            i++;
910            if (i == (long) argc)
911              ThrowDisplayException(OptionError,"MissingArgument",option);
912            event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
913            if (event < 0)
914              ThrowDisplayException(OptionError,"UnrecognizedEventType",
915                argv[i]);
916            (void) SetLogEventMask(argv[i]);
917            break;
918          }
919        if (LocaleCompare("decipher",option+1) == 0)
920          {
921            if (*option == '+')
922              break;
923            i++;
924            if (i == (long) (argc-1))
925              ThrowDisplayException(OptionError,"MissingArgument",option);
926            break;
927          }
928        if (LocaleCompare("define",option+1) == 0)
929          {
930            i++;
931            if (i == (long) argc)
932              ThrowDisplayException(OptionError,"MissingArgument",option);
933            if (*option == '+')
934              {
935                const char
936                  *define;
937
938                define=GetImageOption(image_info,argv[i]);
939                if (define == (const char *) NULL)
940                  ThrowDisplayException(OptionError,"NoSuchOption",argv[i]);
941                break;
942              }
943            break;
944          }
945        if (LocaleCompare("delay",option+1) == 0)
946          {