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