PageRenderTime 125ms CodeModel.GetById 2ms app.highlight 109ms RepoModel.GetById 1ms app.codeStats 1ms

/MagickWand/display.c

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