blob: fd3db40374ca20f7c7469cc4bac7030c63aad280 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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 %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the display program to display an image or image sequence on any X
37% server.
38%
39*/
40
41/*
42 Include declarations.
43*/
cristy4c08aed2011-07-01 19:47:50 +000044#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"
cristy3ed852e2009-09-05 21:47:34 +000049
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 const char
97 **p;
98
99 static const char
100 *buttons[]=
101 {
102 "1 press to map or unmap the Command widget",
103 "2 press and drag to magnify a region of an image",
104 "3 press to load an image from a visual image directory",
105 (char *) NULL
106 },
107 *miscellaneous[]=
108 {
109 "-debug events display copious debugging information",
110 "-help print program options",
111 "-list type print a list of supported option arguments",
112 "-log format format of debugging information",
113 "-version print version information",
114 (char *) NULL
115 },
116 *operators[]=
117 {
118 "-auto-orient automagically orient image",
119 "-border geometry surround image with a border of color",
cristycee97112010-05-28 00:44:52 +0000120 "-clip clip along the first path from the 8BIM profile",
121 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +0000122 "-colors value preferred number of colors in the image",
123 "-contrast enhance or reduce the image contrast",
124 "-crop geometry preferred size and location of the cropped image",
125 "-decipher filename convert cipher pixels to plain pixels",
126 "-deskew threshold straighten an image",
127 "-despeckle reduce the speckles within an image",
128 "-edge factor apply a filter to detect edges in the image",
129 "-enhance apply a digital filter to enhance a noisy image",
130 "-equalize perform histogram equalization to an image",
131 "-extract geometry extract area from image",
132 "-flip flip image in the vertical direction",
133 "-flop flop image in the horizontal direction",
134 "-frame geometry surround image with an ornamental border",
135 "-fuzz distance colors within this distance are considered equal",
136 "-gamma value level of gamma correction",
137 "-monochrome transform image to black and white",
138 "-negate replace every pixel with its complementary color",
139 "-normalize transform image to span the full range of colors",
140 "-raise value lighten/darken image edges to create a 3-D effect",
141 "-resample geometry change the resolution of an image",
142 "-resize geometry resize the image",
143 "-roll geometry roll an image vertically or horizontally",
144 "-rotate degrees apply Paeth rotation to the image",
145 "-sample geometry scale image with pixel sampling",
146 "-segment value segment an image",
147 "-sharpen geometry sharpen the image",
148 "-strip strip image of all profiles and comments",
149 "-threshold value threshold the image",
cristye4cbe742010-02-18 22:19:38 +0000150 "-thumbnail geometry create a thumbnail of the image",
cristy3ed852e2009-09-05 21:47:34 +0000151 "-trim trim image edges",
152 (char *) NULL
153 },
154 *settings[]=
155 {
156 "-alpha option on, activate, off, deactivate, set, opaque, copy",
157 " transparent, extract, background, or shape",
158 "-antialias remove pixel-aliasing",
159 "-authenticate password",
160 " decipher image with this password",
161 "-backdrop display image centered on a backdrop",
162 "-channel type apply option to select image channels",
163 "-colormap type Shared or Private",
164 "-colorspace type alternate image colorspace",
165 "-comment string annotate image with comment",
166 "-compress type type of pixel compression when writing the image",
167 "-define format:option",
168 " define one or more image format options",
169 "-delay value display the next image after pausing",
170 "-density geometry horizontal and vertical density of the image",
171 "-depth value image depth",
172 "-display server display image to this X server",
173 "-dispose method layer disposal method",
174 "-dither method apply error diffusion to image",
175 "-endian type endianness (MSB or LSB) of the image",
176 "-filter type use this filter when resizing an image",
177 "-format string output formatted image characteristics",
178 "-geometry geometry preferred size and location of the Image window",
179 "-gravity type horizontal and vertical backdrop placement",
180 "-identify identify the format and characteristics of the image",
181 "-immutable displayed image cannot be modified",
182 "-interlace type type of image interlacing scheme",
183 "-interpolate method pixel color interpolation method",
184 "-label string assign a label to an image",
185 "-limit type value pixel cache resource limit",
186 "-loop iterations loop images then exit",
187 "-map type display image using this Standard Colormap",
cristye9252c22013-07-30 15:43:21 +0000188 "-matte store matte channel if the image has one",
cristy3ed852e2009-09-05 21:47:34 +0000189 "-monitor monitor progress",
190 "-page geometry size and location of an image canvas",
191 "-profile filename add, delete, or apply an image profile",
192 "-quality value JPEG/MIFF/PNG compression level",
193 "-quantize colorspace reduce colors in this colorspace",
194 "-quiet suppress all warning messages",
195 "-regard-warnings pay attention to warning messages",
196 "-remote command execute a command in an remote display process",
197 "-repage geometry size and location of an image canvas (operator)",
198 "-respect-parentheses settings remain in effect until parenthesis boundary",
199 "-sampling-factor geometry",
200 " horizontal and vertical sampling factor",
cristye9252c22013-07-30 15:43:21 +0000201 "-scenes range image scene range",
cristy3ed852e2009-09-05 21:47:34 +0000202 "-seed value seed a new sequence of pseudo-random numbers",
203 "-set property value set an image property",
204 "-size geometry width and height of image",
cristye9252c22013-07-30 15:43:21 +0000205 "-support factor resize support: > 1.0 is blurry, < 1.0 is sharp",
cristy3ed852e2009-09-05 21:47:34 +0000206 "-texture filename name of texture to tile onto the image background",
207 "-transparent-color color",
208 " transparent color",
209 "-treedepth value color tree depth",
210 "-update seconds detect when image file is modified and redisplay",
211 "-verbose print detailed information about the image",
212 "-visual type display image using this visual type",
213 "-virtual-pixel method",
214 " virtual pixel access method",
215 "-window id display image to background of this window",
216 "-window-group id exit program when this window id is destroyed",
217 "-write filename write image to a file",
218 (char *) NULL
219 },
220 *sequence_operators[]=
221 {
222 "-coalesce merge a sequence of images",
223 "-flatten flatten a sequence of images",
224 (char *) NULL
225 };
226
cristy4f7a6132012-12-23 00:35:19 +0000227 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +0000228 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
229 GetClientName());
230 (void) printf("\nImage Settings:\n");
231 for (p=settings; *p != (char *) NULL; p++)
232 (void) printf(" %s\n",*p);
233 (void) printf("\nImage Operators:\n");
234 for (p=operators; *p != (char *) NULL; p++)
235 (void) printf(" %s\n",*p);
236 (void) printf("\nImage Sequence Operators:\n");
237 for (p=sequence_operators; *p != (char *) NULL; p++)
238 (void) printf(" %s\n",*p);
239 (void) printf("\nMiscellaneous Options:\n");
240 for (p=miscellaneous; *p != (char *) NULL; p++)
241 (void) printf(" %s\n",*p);
242 (void) printf(
243 "\nIn addition to those listed above, you can specify these standard X\n");
244 (void) printf(
245 "resources as command line options: -background, -bordercolor,\n");
246 (void) printf(
247 "-borderwidth, -font, -foreground, -iconGeometry, -iconic, -mattecolor,\n");
248 (void) printf("-name, -shared-memory, -usePixmap, or -title.\n");
249 (void) printf(
anthonye5b39652012-04-21 05:37:29 +0000250 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +0000251 (void) printf(
252 "number. To specify a particular image format, precede the filename\n");
253 (void) printf(
254 "with an image format name and a colon (i.e. ps:image) or specify the\n");
255 (void) printf(
256 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
257 (void) printf("'-' for standard input or output.\n");
258 (void) printf("\nButtons: \n");
259 for (p=buttons; *p != (char *) NULL; p++)
260 (void) printf(" %s\n",*p);
261 return(MagickFalse);
262}
263
264WandExport MagickBooleanType DisplayImageCommand(ImageInfo *image_info,
265 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
266{
267#if defined(MAGICKCORE_X11_DELEGATE)
268#define DestroyDisplay() \
269{ \
270 if ((state & ExitState) == 0) \
271 DestroyXResources(); \
272 if (display != (Display *) NULL) \
273 { \
274 XCloseDisplay(display); \
275 display=(Display *) NULL; \
276 } \
277 XDestroyResourceInfo(&resource_info); \
278 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +0000279 if (image_marker != (size_t *) NULL) \
280 image_marker=(size_t *) RelinquishMagickMemory(image_marker); \
281 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +0000282 argv[i]=DestroyString(argv[i]); \
283 argv=(char **) RelinquishMagickMemory(argv); \
284}
285#define ThrowDisplayException(asperity,tag,option) \
286{ \
cristyefe601c2013-01-05 17:51:12 +0000287 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
cristy3ed852e2009-09-05 21:47:34 +0000288 option); \
289 DestroyDisplay(); \
290 return(MagickFalse); \
291}
292#define ThrowDisplayInvalidArgumentException(option,argument) \
293{ \
294 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
anthonye5b39652012-04-21 05:37:29 +0000295 "InvalidArgument","'%s': %s",option,argument); \
cristy3ed852e2009-09-05 21:47:34 +0000296 DestroyDisplay(); \
297 return(MagickFalse); \
298}
299
300 char
301 *resource_value,
302 *server_name;
303
304 const char
305 *option;
306
307 Display
308 *display;
309
310 Image
311 *image;
312
313 ImageStack
314 image_stack[MaxImageStackDepth+1];
315
cristy3ed852e2009-09-05 21:47:34 +0000316 MagickBooleanType
cristyebbcfea2011-02-25 02:43:54 +0000317 fire,
318 pend,
319 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +0000320
321 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000322 status;
323
324 QuantizeInfo
325 *quantize_info;
326
cristybb503372010-05-27 20:51:26 +0000327 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000328 i;
329
cristybb503372010-05-27 20:51:26 +0000330 size_t
cristy3ed852e2009-09-05 21:47:34 +0000331 *image_marker,
332 iterations,
333 last_image,
334 state;
335
cristy9d314ff2011-03-09 01:30:28 +0000336 ssize_t
337 image_number,
338 iteration,
339 j,
340 k,
341 l;
342
cristy3ed852e2009-09-05 21:47:34 +0000343 XResourceInfo
344 resource_info;
345
346 XrmDatabase
347 resource_database;
348
349 /*
350 Set defaults.
351 */
352 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000353 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000354 if (image_info->debug != MagickFalse)
355 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
356 assert(exception != (ExceptionInfo *) NULL);
357 if (argc == 2)
358 {
359 option=argv[1];
360 if ((LocaleCompare("version",option+1) == 0) ||
361 (LocaleCompare("-version",option+1) == 0))
362 {
cristy4f7a6132012-12-23 00:35:19 +0000363 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +0000364 return(MagickFalse);
365 }
366 }
367 SetNotifyHandlers;
368 display=(Display *) NULL;
369 j=1;
370 k=0;
cristybb503372010-05-27 20:51:26 +0000371 image_marker=(size_t *) NULL;
cristy3ed852e2009-09-05 21:47:34 +0000372 image_number=0;
373 last_image=0;
374 NewImageStack();
375 option=(char *) NULL;
376 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +0000377 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000378 resource_database=(XrmDatabase) NULL;
379 (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info));
380 server_name=(char *) NULL;
381 state=0;
382 status=MagickTrue;
383 ReadCommandlLine(argc,&argv);
384 status=ExpandFilenames(&argc,&argv);
385 if (status == MagickFalse)
386 ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
387 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +0000388 image_marker=(size_t *) AcquireQuantumMemory((size_t) argc+1UL,
cristy3ed852e2009-09-05 21:47:34 +0000389 sizeof(*image_marker));
cristybb503372010-05-27 20:51:26 +0000390 if (image_marker == (size_t *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000391 ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
392 GetExceptionMessage(errno));
cristycee97112010-05-28 00:44:52 +0000393 for (i=0; i <= (ssize_t) argc; i++)
cristybb503372010-05-27 20:51:26 +0000394 image_marker[i]=(size_t) argc;
cristy3ed852e2009-09-05 21:47:34 +0000395 /*
396 Check for server name specified on the command line.
397 */
cristybb503372010-05-27 20:51:26 +0000398 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000399 {
400 /*
401 Check command line for server name.
402 */
403 option=argv[i];
404 if (LocaleCompare("display",option+1) == 0)
405 {
406 /*
407 User specified server name.
408 */
409 i++;
cristybb503372010-05-27 20:51:26 +0000410 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000411 ThrowDisplayException(OptionError,"MissingArgument",option);
412 server_name=argv[i];
413 }
414 if ((LocaleCompare("help",option+1) == 0) ||
415 (LocaleCompare("-help",option+1) == 0))
416 return(DisplayUsage());
417 }
418 /*
419 Get user defaults from X resource database.
420 */
421 display=XOpenDisplay(server_name);
422 if (display == (Display *) NULL)
423 ThrowDisplayException(XServerError,"UnableToOpenXServer",
424 XDisplayName(server_name));
425 (void) XSetErrorHandler(XError);
426 resource_database=XGetResourceDatabase(display,GetClientName());
427 XGetResourceInfo(image_info,resource_database,GetClientName(),
428 &resource_info);
429 quantize_info=resource_info.quantize_info;
430 image_info->density=XGetResourceInstance(resource_database,GetClientName(),
431 "density",(char *) NULL);
432 if (image_info->density == (char *) NULL)
433 image_info->density=XGetScreenDensity(display);
434 resource_value=XGetResourceInstance(resource_database,GetClientName(),
435 "interlace","none");
436 image_info->interlace=(InterlaceType)
cristy042ee782011-04-22 18:48:30 +0000437 ParseCommandOption(MagickInterlaceOptions,MagickFalse,resource_value);
cristy3ed852e2009-09-05 21:47:34 +0000438 image_info->page=XGetResourceInstance(resource_database,GetClientName(),
439 "pageGeometry",(char *) NULL);
440 resource_value=XGetResourceInstance(resource_database,GetClientName(),
441 "quality","75");
cristye27293e2009-12-18 02:53:20 +0000442 image_info->quality=StringToUnsignedLong(resource_value);
cristy3ed852e2009-09-05 21:47:34 +0000443 resource_value=XGetResourceInstance(resource_database,GetClientName(),
444 "verbose","False");
anthony2e4501b2012-03-30 04:41:54 +0000445 image_info->verbose=IsStringTrue(resource_value);
cristy3ed852e2009-09-05 21:47:34 +0000446 resource_value=XGetResourceInstance(resource_database,GetClientName(),
447 "dither","True");
cristycbda6112012-05-27 20:57:16 +0000448 quantize_info->dither_method=IsStringTrue(resource_value) != MagickFalse ?
449 RiemersmaDitherMethod : NoDitherMethod;
cristy3ed852e2009-09-05 21:47:34 +0000450 /*
451 Parse command line.
452 */
453 iteration=0;
cristybb503372010-05-27 20:51:26 +0000454 for (i=1; ((i <= (ssize_t) argc) && ((state & ExitState) == 0)); i++)
cristy3ed852e2009-09-05 21:47:34 +0000455 {
cristybb503372010-05-27 20:51:26 +0000456 if (i < (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000457 option=argv[i];
458 else
459 if (image != (Image *) NULL)
460 break;
461 else
462 if (isatty(STDIN_FILENO) != MagickFalse)
463 option="logo:";
464 else
cristyb3ed35e2014-06-17 22:48:41 +0000465 option="-";
cristy3ed852e2009-09-05 21:47:34 +0000466 if (LocaleCompare(option,"(") == 0)
467 {
468 FireImageStack(MagickFalse,MagickTrue,pend);
469 if (k == MaxImageStackDepth)
470 ThrowDisplayException(OptionError,"ParenthesisNestedTooDeeply",
471 option);
472 PushImageStack();
473 continue;
474 }
475 if (LocaleCompare(option,")") == 0)
476 {
477 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
478 if (k == 0)
479 ThrowDisplayException(OptionError,"UnableToParseExpression",option);
480 PopImageStack();
481 continue;
482 }
cristy042ee782011-04-22 18:48:30 +0000483 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000484 {
485 const char
486 *filename;
487
488 Image
cristy5ca51572011-03-24 02:00:31 +0000489 *display_image,
cristy0d2c4ce2012-03-07 02:19:41 +0000490 *image_list,
cristy3ed852e2009-09-05 21:47:34 +0000491 *images;
492
493 /*
494 Option is a file name.
495 */
496 FireImageStack(MagickFalse,MagickFalse,pend);
497 filename=option;
cristycee97112010-05-28 00:44:52 +0000498 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +0000499 {
500 option=argv[++i];
501 filename=option;
502 }
cristy151b66d2015-04-15 10:50:31 +0000503 (void) CopyMagickString(image_info->filename,filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000504 images=ReadImage(image_info,exception);
505 CatchException(exception);
506 status&=(images != (Image *) NULL) &&
507 (exception->severity < ErrorException);
508 if (images == (Image *) NULL)
509 continue;
510 AppendImageStack(images);
511 FinalizeImageSettings(image_info,image,MagickFalse);
cristyf3816382009-11-26 14:57:01 +0000512 iterations=0;
cristye81f5522014-05-07 01:25:59 +0000513 if (i == (ssize_t) argc)
cristyf3816382009-11-26 14:57:01 +0000514 iterations=image->iterations;
cristy0d2c4ce2012-03-07 02:19:41 +0000515 image_list=CloneImageList(image,exception);
516 if (image_list == (Image *) NULL)
cristy5ca51572011-03-24 02:00:31 +0000517 ThrowDisplayException(ResourceLimitError,"MemoryAllocationFailed",
518 GetExceptionMessage(errno));
cristy0d2c4ce2012-03-07 02:19:41 +0000519 display_image=image_list;
cristy3ed852e2009-09-05 21:47:34 +0000520 do
521 {
522 /*
523 Transmogrify image as defined by the image processing options.
524 */
525 resource_info.quantum=1;
526 if (resource_info.window_id != (char *) NULL)
527 {
528 /*
529 Display image to a specified X window.
530 */
cristy5ca51572011-03-24 02:00:31 +0000531 status=XDisplayBackgroundImage(display,&resource_info,
cristy051718b2011-08-28 22:49:25 +0000532 display_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000533 if (status != MagickFalse)
534 {
535 state|=RetainColorsState;
536 status=MagickFalse;
537 }
cristyf023f7e2013-03-23 23:13:26 +0000538 if (GetNextImageInList(display_image) == (Image *) NULL)
539 state|=ExitState;
cristy3ed852e2009-09-05 21:47:34 +0000540 }
541 else
542 do
543 {
544 Image
545 *nexus;
546
547 /*
548 Display image to X server.
549 */
cristy588e8b92010-06-27 13:45:22 +0000550 if (resource_info.delay != 1)
cristy5ca51572011-03-24 02:00:31 +0000551 display_image->delay=resource_info.delay;
552 nexus=XDisplayImage(display,&resource_info,argv,argc,
cristy051718b2011-08-28 22:49:25 +0000553 &display_image,&state,exception);
cristy3ed852e2009-09-05 21:47:34 +0000554 if (nexus == (Image *) NULL)
555 break;
556 while ((nexus != (Image *) NULL) && ((state & ExitState) == 0))
557 {
558 Image
559 *next;
560
561 if (nexus->montage != (char *) NULL)
562 {
563 /*
564 User selected a visual directory image (montage).
565 */
cristy5ca51572011-03-24 02:00:31 +0000566 display_image=nexus;
cristy3ed852e2009-09-05 21:47:34 +0000567 break;
568 }
569 next=XDisplayImage(display,&resource_info,argv,argc,&nexus,
cristy051718b2011-08-28 22:49:25 +0000570 &state,exception);
cristy3ed852e2009-09-05 21:47:34 +0000571 if ((next == (Image *) NULL) &&
572 (GetNextImageInList(nexus) != (Image *) NULL))
573 {
cristy5ca51572011-03-24 02:00:31 +0000574 display_image=GetNextImageInList(nexus);
cristy3ed852e2009-09-05 21:47:34 +0000575 nexus=NewImageList();
576 }
577 else
578 {
cristy5ca51572011-03-24 02:00:31 +0000579 if (nexus != display_image)
cristy3ed852e2009-09-05 21:47:34 +0000580 nexus=DestroyImageList(nexus);
581 nexus=next;
582 }
583 }
584 } while ((state & ExitState) == 0);
585 if (resource_info.write_filename != (char *) NULL)
586 {
587 /*
588 Write image.
589 */
cristy5ca51572011-03-24 02:00:31 +0000590 (void) CopyMagickString(display_image->filename,
cristy151b66d2015-04-15 10:50:31 +0000591 resource_info.write_filename,MagickPathExtent);
cristyc82a27b2011-10-21 01:07:16 +0000592 (void) SetImageInfo(image_info,1,exception);
593 status&=WriteImage(image_info,display_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000594 }
595 /*
596 Proceed to next/previous image.
597 */
598 if ((state & FormerImageState) != 0)
cristycee97112010-05-28 00:44:52 +0000599 for (l=0; l < (ssize_t) resource_info.quantum; l++)
cristy3ed852e2009-09-05 21:47:34 +0000600 {
cristy7f504032013-02-07 12:20:42 +0000601 if (GetPreviousImageInList(display_image) == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000602 break;
cristy7f504032013-02-07 12:20:42 +0000603 display_image=GetPreviousImageInList(display_image);
cristy3ed852e2009-09-05 21:47:34 +0000604 }
605 else
cristycee97112010-05-28 00:44:52 +0000606 for (l=0; l < (ssize_t) resource_info.quantum; l++)
cristy3ed852e2009-09-05 21:47:34 +0000607 {
cristy7f504032013-02-07 12:20:42 +0000608 if (GetNextImageInList(display_image) == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000609 break;
cristy7f504032013-02-07 12:20:42 +0000610 display_image=GetNextImageInList(display_image);
cristy3ed852e2009-09-05 21:47:34 +0000611 }
cristya97d2c22013-04-23 14:30:37 +0000612 if (l < (ssize_t) resource_info.quantum)
613 break;
cristy5ca51572011-03-24 02:00:31 +0000614 } while ((display_image != (Image *) NULL) && ((state & ExitState) == 0));
cristy3ed852e2009-09-05 21:47:34 +0000615 /*
616 Free image resources.
617 */
cristyc1a5c902012-04-28 17:31:37 +0000618 display_image=DestroyImageList(display_image);
cristy3ed852e2009-09-05 21:47:34 +0000619 if ((state & FormerImageState) == 0)
620 {
cristybb503372010-05-27 20:51:26 +0000621 last_image=(size_t) image_number;
622 image_marker[i]=(size_t) image_number++;
cristy3ed852e2009-09-05 21:47:34 +0000623 }
624 else
625 {
626 /*
627 Proceed to previous image.
628 */
629 for (i--; i > 0; i--)
cristybb503372010-05-27 20:51:26 +0000630 if (image_marker[i] == (size_t) (image_number-2))
cristy3ed852e2009-09-05 21:47:34 +0000631 break;
632 image_number--;
633 }
cristye81f5522014-05-07 01:25:59 +0000634 if ((i == (ssize_t) argc) && ((state & ExitState) == 0))
cristy3ed852e2009-09-05 21:47:34 +0000635 i=0;
636 if ((state & ExitState) != 0)
637 break;
638 /*
639 Determine if we should proceed to the first image.
640 */
641 if (image_number < 0)
642 {
643 if ((state & FormerImageState) != 0)
644 {
645
cristycee97112010-05-28 00:44:52 +0000646 for (i=1; i < (ssize_t) (argc-2); i++)
cristy3ed852e2009-09-05 21:47:34 +0000647 if (last_image == image_marker[i])
648 break;
cristybb503372010-05-27 20:51:26 +0000649 image_number=(ssize_t) image_marker[i]+1;
cristy3ed852e2009-09-05 21:47:34 +0000650 }
651 continue;
652 }
653 if (resource_info.window_id != (char *) NULL)
654 state|=ExitState;
cristybb503372010-05-27 20:51:26 +0000655 if ((iterations != 0) && (++iteration == (ssize_t) iterations))
cristy3ed852e2009-09-05 21:47:34 +0000656 state|=ExitState;
657 if (LocaleCompare(filename,"-") == 0)
658 state|=ExitState;
cristy9a48b172011-09-20 17:41:05 +0000659 RemoveAllImageStack();
cristy3ed852e2009-09-05 21:47:34 +0000660 continue;
661 }
662 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
663 switch (*(option+1))
664 {
665 case 'a':
666 {
667 if (LocaleCompare("alpha",option+1) == 0)
668 {
cristybb503372010-05-27 20:51:26 +0000669 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000670 type;
671
672 if (*option == '+')
673 break;
674 i++;
cristybb503372010-05-27 20:51:26 +0000675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000676 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy288a3532012-08-28 00:19:44 +0000677 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000678 if (type < 0)
cristyb15b06c2012-08-28 11:36:48 +0000679 ThrowDisplayException(OptionError,"UnrecognizedAlphaChannelOption",
cristy3ed852e2009-09-05 21:47:34 +0000680 argv[i]);
681 break;
682 }
683 if (LocaleCompare("antialias",option+1) == 0)
684 break;
685 if (LocaleCompare("authenticate",option+1) == 0)
686 {
687 if (*option == '+')
688 break;
689 i++;
cristybb503372010-05-27 20:51:26 +0000690 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000691 ThrowDisplayException(OptionError,"MissingArgument",option);
692 break;
693 }
694 if (LocaleCompare("auto-orient",option+1) == 0)
695 break;
696 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
697 }
698 case 'b':
699 {
700 if (LocaleCompare("backdrop",option+1) == 0)
701 {
702 resource_info.backdrop=(*option == '-') ? MagickTrue : MagickFalse;
703 break;
704 }
705 if (LocaleCompare("background",option+1) == 0)
706 {
707 if (*option == '+')
708 break;
709 i++;
cristybb503372010-05-27 20:51:26 +0000710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000711 ThrowDisplayException(OptionError,"MissingArgument",option);
712 resource_info.background_color=argv[i];
713 break;
714 }
715 if (LocaleCompare("border",option+1) == 0)
716 {
717 if (*option == '+')
718 break;
719 i++;
cristybb503372010-05-27 20:51:26 +0000720 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000721 ThrowDisplayException(OptionError,"MissingArgument",option);
722 if (IsGeometry(argv[i]) == MagickFalse)
723 ThrowDisplayInvalidArgumentException(option,argv[i]);
724 break;
725 }
726 if (LocaleCompare("bordercolor",option+1) == 0)
727 {
728 if (*option == '+')
729 break;
730 i++;
cristybb503372010-05-27 20:51:26 +0000731 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000732 ThrowDisplayException(OptionError,"MissingArgument",option);
733 resource_info.border_color=argv[i];
734 break;
735 }
736 if (LocaleCompare("borderwidth",option+1) == 0)
737 {
738 resource_info.border_width=0;
739 if (*option == '+')
740 break;
741 i++;
cristybb503372010-05-27 20:51:26 +0000742 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000743 ThrowDisplayException(OptionError,"MissingArgument",option);
744 if (IsGeometry(argv[i]) == MagickFalse)
745 ThrowDisplayInvalidArgumentException(option,argv[i]);
cristyb70a4862010-06-18 01:18:44 +0000746 resource_info.border_width=(unsigned int)
747 StringToUnsignedLong(argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000748 break;
749 }
750 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
751 }
752 case 'c':
753 {
754 if (LocaleCompare("cache",option+1) == 0)
755 {
756 if (*option == '+')
757 break;
758 i++;
cristybb503372010-05-27 20:51:26 +0000759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000760 ThrowDisplayException(OptionError,"MissingArgument",option);
761 if (IsGeometry(argv[i]) == MagickFalse)
762 ThrowDisplayInvalidArgumentException(option,argv[i]);
763 break;
764 }
765 if (LocaleCompare("channel",option+1) == 0)
766 {
cristybb503372010-05-27 20:51:26 +0000767 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000768 channel;
769
770 if (*option == '+')
771 break;
772 i++;
cristye81f5522014-05-07 01:25:59 +0000773 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000774 ThrowDisplayException(OptionError,"MissingArgument",option);
775 channel=ParseChannelOption(argv[i]);
776 if (channel < 0)
777 ThrowDisplayException(OptionError,"UnrecognizedChannelType",
778 argv[i]);
779 break;
780 }
781 if (LocaleCompare("clip",option+1) == 0)
782 break;
783 if (LocaleCompare("clip-path",option+1) == 0)
784 {
785 i++;
cristybb503372010-05-27 20:51:26 +0000786 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000787 ThrowDisplayException(OptionError,"MissingArgument",option);
788 break;
789 }
790 if (LocaleCompare("coalesce",option+1) == 0)
791 break;
792 if (LocaleCompare("colormap",option+1) == 0)
793 {
794 resource_info.colormap=PrivateColormap;
795 if (*option == '+')
796 break;
797 i++;
cristybb503372010-05-27 20:51:26 +0000798 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000799 ThrowDisplayException(OptionError,"MissingArgument",option);
800 resource_info.colormap=UndefinedColormap;
801 if (LocaleCompare("private",argv[i]) == 0)
802 resource_info.colormap=PrivateColormap;
803 if (LocaleCompare("shared",argv[i]) == 0)
804 resource_info.colormap=SharedColormap;
805 if (resource_info.colormap == UndefinedColormap)
806 ThrowDisplayException(OptionError,"UnrecognizedColormapType",
807 argv[i]);
808 break;
809 }
810 if (LocaleCompare("colors",option+1) == 0)
811 {
812 quantize_info->number_colors=0;
813 if (*option == '+')
814 break;
815 i++;
cristybb503372010-05-27 20:51:26 +0000816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000817 ThrowDisplayException(OptionError,"MissingArgument",option);
818 if (IsGeometry(argv[i]) == MagickFalse)
819 ThrowDisplayInvalidArgumentException(option,argv[i]);
cristye27293e2009-12-18 02:53:20 +0000820 quantize_info->number_colors=StringToUnsignedLong(argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000821 break;
822 }
823 if (LocaleCompare("colorspace",option+1) == 0)
824 {
cristybb503372010-05-27 20:51:26 +0000825 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000826 colorspace;
827
828 if (*option == '+')
829 break;
830 i++;
cristybb503372010-05-27 20:51:26 +0000831 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000832 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000833 colorspace=ParseCommandOption(MagickColorspaceOptions,
cristy3ed852e2009-09-05 21:47:34 +0000834 MagickFalse,argv[i]);
835 if (colorspace < 0)
836 ThrowDisplayException(OptionError,"UnrecognizedColorspace",
837 argv[i]);
838 break;
839 }
840 if (LocaleCompare("comment",option+1) == 0)
841 {
842 if (*option == '+')
843 break;
844 i++;
cristybb503372010-05-27 20:51:26 +0000845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000846 ThrowDisplayException(OptionError,"MissingArgument",option);
847 break;
848 }
849 if (LocaleCompare("compress",option+1) == 0)
850 {
cristybb503372010-05-27 20:51:26 +0000851 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000852 compress;
853
854 if (*option == '+')
855 break;
856 i++;
cristybb503372010-05-27 20:51:26 +0000857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000858 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000859 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +0000860 argv[i]);
861 if (compress < 0)
862 ThrowDisplayException(OptionError,"UnrecognizedImageCompression",
863 argv[i]);
864 break;
865 }
cristy22879752009-10-25 23:55:40 +0000866 if (LocaleCompare("concurrent",option+1) == 0)
867 break;
cristy3ed852e2009-09-05 21:47:34 +0000868 if (LocaleCompare("contrast",option+1) == 0)
869 break;
870 if (LocaleCompare("crop",option+1) == 0)
871 {
872 if (*option == '+')
873 break;
874 i++;
cristybb503372010-05-27 20:51:26 +0000875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000876 ThrowDisplayException(OptionError,"MissingArgument",option);
877 if (IsGeometry(argv[i]) == MagickFalse)
878 ThrowDisplayInvalidArgumentException(option,argv[i]);
879 break;
880 }
881 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
882 }
883 case 'd':
884 {
885 if (LocaleCompare("debug",option+1) == 0)
886 {
cristybb503372010-05-27 20:51:26 +0000887 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000888 event;
889
890 if (*option == '+')
891 break;
892 i++;
cristybb503372010-05-27 20:51:26 +0000893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000894 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000895 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000896 if (event < 0)
897 ThrowDisplayException(OptionError,"UnrecognizedEventType",
898 argv[i]);
899 (void) SetLogEventMask(argv[i]);
900 break;
901 }
902 if (LocaleCompare("decipher",option+1) == 0)
903 {
904 if (*option == '+')
905 break;
906 i++;
cristye81f5522014-05-07 01:25:59 +0000907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000908 ThrowDisplayException(OptionError,"MissingArgument",option);
909 break;
910 }
911 if (LocaleCompare("define",option+1) == 0)
912 {
913 i++;
cristybb503372010-05-27 20:51:26 +0000914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000915 ThrowDisplayException(OptionError,"MissingArgument",option);
916 if (*option == '+')
917 {
918 const char
919 *define;
920
921 define=GetImageOption(image_info,argv[i]);
922 if (define == (const char *) NULL)
923 ThrowDisplayException(OptionError,"NoSuchOption",argv[i]);
924 break;
925 }
926 break;
927 }
928 if (LocaleCompare("delay",option+1) == 0)
929 {
930 if (*option == '+')
931 break;
932 i++;
cristybb503372010-05-27 20:51:26 +0000933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000934 ThrowDisplayException(OptionError,"MissingArgument",option);
935 if (IsGeometry(argv[i]) == MagickFalse)
936 ThrowDisplayInvalidArgumentException(option,argv[i]);
937 break;
938 }
939 if (LocaleCompare("density",option+1) == 0)
940 {
941 if (*option == '+')
942 break;
943 i++;
cristybb503372010-05-27 20:51:26 +0000944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000945 ThrowDisplayException(OptionError,"MissingArgument",option);
946 if (IsGeometry(argv[i]) == MagickFalse)
947 ThrowDisplayInvalidArgumentException(option,argv[i]);
948 break;
949 }
950 if (LocaleCompare("depth",option+1) == 0)
951 {
952 if (*option == '+')
953 break;
954 i++;
cristybb503372010-05-27 20:51:26 +0000955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000956 ThrowDisplayException(OptionError,"MissingArgument",option);
957 if (IsGeometry(argv[i]) == MagickFalse)
958 ThrowDisplayInvalidArgumentException(option,argv[i]);
959 break;
960 }
961 if (LocaleCompare("deskew",option+1) == 0)
962 {
963 if (*option == '+')
964 break;
965 i++;
cristye81f5522014-05-07 01:25:59 +0000966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000967 ThrowDisplayException(OptionError,"MissingArgument",option);
968 if (IsGeometry(argv[i]) == MagickFalse)
969 ThrowDisplayInvalidArgumentException(option,argv[i]);
970 break;
971 }
972 if (LocaleCompare("despeckle",option+1) == 0)
973 break;
974 if (LocaleCompare("display",option+1) == 0)
975 {
976 if (*option == '+')
977 break;
978 i++;
cristybb503372010-05-27 20:51:26 +0000979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000980 ThrowDisplayException(OptionError,"MissingArgument",option);
981 break;
982 }
983 if (LocaleCompare("dispose",option+1) == 0)
984 {
cristybb503372010-05-27 20:51:26 +0000985 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000986 dispose;
987
988 if (*option == '+')
989 break;
990 i++;
cristybb503372010-05-27 20:51:26 +0000991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000992 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +0000993 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +0000994 if (dispose < 0)
995 ThrowDisplayException(OptionError,"UnrecognizedDisposeMethod",
996 argv[i]);
997 break;
998 }
999 if (LocaleCompare("dither",option+1) == 0)
1000 {
cristybb503372010-05-27 20:51:26 +00001001 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001002 method;
1003
cristycbda6112012-05-27 20:57:16 +00001004 quantize_info->dither_method=NoDitherMethod;
cristy3ed852e2009-09-05 21:47:34 +00001005 if (*option == '+')
1006 break;
1007 i++;
cristybb503372010-05-27 20:51:26 +00001008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001009 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001010 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00001011 if (method < 0)
1012 ThrowDisplayException(OptionError,"UnrecognizedDitherMethod",
1013 argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00001014 quantize_info->dither_method=(DitherMethod) method;
1015 break;
1016 }
cristy22879752009-10-25 23:55:40 +00001017 if (LocaleCompare("duration",option+1) == 0)
1018 {
1019 if (*option == '+')
1020 break;
1021 i++;
cristye81f5522014-05-07 01:25:59 +00001022 if (i == (ssize_t) argc)
cristy22879752009-10-25 23:55:40 +00001023 ThrowDisplayException(OptionError,"MissingArgument",option);
1024 if (IsGeometry(argv[i]) == MagickFalse)
1025 ThrowDisplayInvalidArgumentException(option,argv[i]);
1026 break;
1027 }
cristy3ed852e2009-09-05 21:47:34 +00001028 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1029 }
1030 case 'e':
1031 {
1032 if (LocaleCompare("edge",option+1) == 0)
1033 {
1034 if (*option == '+')
1035 break;
1036 i++;
cristybb503372010-05-27 20:51:26 +00001037 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001038 ThrowDisplayException(OptionError,"MissingArgument",option);
1039 if (IsGeometry(argv[i]) == MagickFalse)
1040 ThrowDisplayInvalidArgumentException(option,argv[i]);
1041 break;
1042 }
1043 if (LocaleCompare("endian",option+1) == 0)
1044 {
cristybb503372010-05-27 20:51:26 +00001045 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001046 endian;
1047
1048 if (*option == '+')
1049 break;
1050 i++;
cristybb503372010-05-27 20:51:26 +00001051 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001052 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001053 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00001054 argv[i]);
1055 if (endian < 0)
1056 ThrowDisplayException(OptionError,"UnrecognizedEndianType",
1057 argv[i]);
1058 break;
1059 }
1060 if (LocaleCompare("enhance",option+1) == 0)
1061 break;
1062 if (LocaleCompare("equalize",option+1) == 0)
1063 break;
1064 if (LocaleCompare("extract",option+1) == 0)
1065 {
1066 if (*option == '+')
1067 break;
1068 i++;
cristybb503372010-05-27 20:51:26 +00001069 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001070 ThrowDisplayException(OptionError,"MissingArgument",option);
1071 if (IsGeometry(argv[i]) == MagickFalse)
1072 ThrowDisplayInvalidArgumentException(option,argv[i]);
1073 break;
1074 }
1075 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1076 }
1077 case 'f':
1078 {
1079 if (LocaleCompare("filter",option+1) == 0)
1080 {
cristybb503372010-05-27 20:51:26 +00001081 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001082 filter;
1083
1084 if (*option == '+')
1085 break;
1086 i++;
cristybb503372010-05-27 20:51:26 +00001087 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001088 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001089 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00001090 if (filter < 0)
1091 ThrowDisplayException(OptionError,"UnrecognizedImageFilter",
1092 argv[i]);
1093 break;
1094 }
1095 if (LocaleCompare("flatten",option+1) == 0)
1096 break;
1097 if (LocaleCompare("flip",option+1) == 0)
1098 break;
1099 if (LocaleCompare("flop",option+1) == 0)
1100 break;
1101 if (LocaleCompare("font",option+1) == 0)
1102 {
1103 if (*option == '+')
1104 break;
1105 i++;
cristybb503372010-05-27 20:51:26 +00001106 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001107 ThrowDisplayException(OptionError,"MissingArgument",option);
1108 resource_info.font=XGetResourceClass(resource_database,
1109 GetClientName(),"font",argv[i]);
1110 break;
1111 }
1112 if (LocaleCompare("foreground",option+1) == 0)
1113 {
1114 if (*option == '+')
1115 break;
1116 i++;
cristybb503372010-05-27 20:51:26 +00001117 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001118 ThrowDisplayException(OptionError,"MissingArgument",option);
1119 resource_info.foreground_color=argv[i];
1120 break;
1121 }
1122 if (LocaleCompare("format",option+1) == 0)
1123 {
1124 if (*option == '+')
1125 break;
1126 i++;
cristye81f5522014-05-07 01:25:59 +00001127 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001128 ThrowDisplayException(OptionError,"MissingArgument",option);
1129 break;
1130 }
1131 if (LocaleCompare("frame",option+1) == 0)
1132 {
1133 if (*option == '+')
1134 break;
1135 i++;
cristybb503372010-05-27 20:51:26 +00001136 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001137 ThrowDisplayException(OptionError,"MissingArgument",option);
1138 if (IsGeometry(argv[i]) == MagickFalse)
1139 ThrowDisplayInvalidArgumentException(option,argv[i]);
1140 break;
1141 }
1142 if (LocaleCompare("fuzz",option+1) == 0)
1143 {
1144 if (*option == '+')
1145 break;
1146 i++;
cristye81f5522014-05-07 01:25:59 +00001147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001148 ThrowDisplayException(OptionError,"MissingArgument",option);
1149 if (IsGeometry(argv[i]) == MagickFalse)
1150 ThrowDisplayInvalidArgumentException(option,argv[i]);
1151 break;
1152 }
1153 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1154 }
1155 case 'g':
1156 {
1157 if (LocaleCompare("gamma",option+1) == 0)
1158 {
1159 i++;
cristybb503372010-05-27 20:51:26 +00001160 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001161 ThrowDisplayException(OptionError,"MissingArgument",option);
1162 if (IsGeometry(argv[i]) == MagickFalse)
1163 ThrowDisplayInvalidArgumentException(option,argv[i]);
1164 break;
1165 }
1166 if (LocaleCompare("geometry",option+1) == 0)
1167 {
1168 resource_info.image_geometry=(char *) NULL;
1169 if (*option == '+')
1170 break;
cristy151b66d2015-04-15 10:50:31 +00001171 (void) CopyMagickString(argv[i]+1,"sans",MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001172 i++;
cristybb503372010-05-27 20:51:26 +00001173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001174 ThrowDisplayException(OptionError,"MissingArgument",option);
1175 if (IsGeometry(argv[i]) == MagickFalse)
1176 ThrowDisplayInvalidArgumentException(option,argv[i]);
1177 resource_info.image_geometry=ConstantString(argv[i]);
1178 break;
1179 }
1180 if (LocaleCompare("gravity",option+1) == 0)
1181 {
cristybb503372010-05-27 20:51:26 +00001182 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001183 gravity;
1184
1185 if (*option == '+')
1186 break;
1187 i++;
cristye81f5522014-05-07 01:25:59 +00001188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001189 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001190 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00001191 argv[i]);
1192 if (gravity < 0)
1193 ThrowDisplayException(OptionError,"UnrecognizedGravityType",
1194 argv[i]);
1195 break;
1196 }
1197 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1198 }
1199 case 'h':
1200 {
1201 if ((LocaleCompare("help",option+1) == 0) ||
1202 (LocaleCompare("-help",option+1) == 0))
1203 break;
1204 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1205 }
1206 case 'i':
1207 {
1208 if (LocaleCompare("identify",option+1) == 0)
1209 break;
1210 if (LocaleCompare("iconGeometry",option+1) == 0)
1211 {
1212 resource_info.icon_geometry=(char *) NULL;
1213 if (*option == '+')
1214 break;
1215 i++;
cristybb503372010-05-27 20:51:26 +00001216 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001217 ThrowDisplayException(OptionError,"MissingArgument",option);
1218 if (IsGeometry(argv[i]) == MagickFalse)
1219 ThrowDisplayInvalidArgumentException(option,argv[i]);
1220 resource_info.icon_geometry=argv[i];
1221 break;
1222 }
1223 if (LocaleCompare("iconic",option+1) == 0)
1224 {
1225 resource_info.iconic=(*option == '-') ? MagickTrue : MagickFalse;
1226 break;
1227 }
1228 if (LocaleCompare("immutable",option+1) == 0)
1229 {
1230 resource_info.immutable=(*option == '-') ? MagickTrue : MagickFalse;
1231 break;
1232 }
1233 if (LocaleCompare("interlace",option+1) == 0)
1234 {
cristybb503372010-05-27 20:51:26 +00001235 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001236 interlace;
1237
1238 if (*option == '+')
1239 break;
1240 i++;
cristybb503372010-05-27 20:51:26 +00001241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001242 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001243 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00001244 argv[i]);
1245 if (interlace < 0)
1246 ThrowDisplayException(OptionError,"UnrecognizedInterlaceType",
1247 argv[i]);
1248 break;
1249 }
1250 if (LocaleCompare("interpolate",option+1) == 0)
1251 {
cristybb503372010-05-27 20:51:26 +00001252 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001253 interpolate;
1254
1255 if (*option == '+')
1256 break;
1257 i++;
cristybb503372010-05-27 20:51:26 +00001258 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001259 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001260 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00001261 argv[i]);
1262 if (interpolate < 0)
1263 ThrowDisplayException(OptionError,"UnrecognizedInterpolateMethod",
1264 argv[i]);
1265 break;
1266 }
1267 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1268 }
1269 case 'l':
1270 {
1271 if (LocaleCompare("label",option+1) == 0)
1272 {
1273 if (*option == '+')
1274 break;
1275 i++;
cristybb503372010-05-27 20:51:26 +00001276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001277 ThrowDisplayException(OptionError,"MissingArgument",option);
1278 break;
1279 }
1280 if (LocaleCompare("limit",option+1) == 0)
1281 {
1282 char
1283 *p;
1284
1285 double
1286 value;
1287
cristybb503372010-05-27 20:51:26 +00001288 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001289 resource;
1290
1291 if (*option == '+')
1292 break;
1293 i++;
cristybb503372010-05-27 20:51:26 +00001294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001295 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001296 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00001297 argv[i]);
1298 if (resource < 0)
1299 ThrowDisplayException(OptionError,"UnrecognizedResourceType",
1300 argv[i]);
1301 i++;
cristybb503372010-05-27 20:51:26 +00001302 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001303 ThrowDisplayException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00001304 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00001305 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00001306 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
1307 ThrowDisplayInvalidArgumentException(option,argv[i]);
1308 break;
1309 }
1310 if (LocaleCompare("list",option+1) == 0)
1311 {
cristybb503372010-05-27 20:51:26 +00001312 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001313 list;
1314
1315 if (*option == '+')
1316 break;
1317 i++;
cristybb503372010-05-27 20:51:26 +00001318 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001319 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001320 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00001321 if (list < 0)
1322 ThrowDisplayException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00001323 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00001324 argv+j,exception);
1325 DestroyDisplay();
cristy32ce2392014-09-24 19:08:53 +00001326 return(status == 0 ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001327 }
1328 if (LocaleCompare("log",option+1) == 0)
1329 {
1330 if (*option == '+')
1331 break;
1332 i++;
cristybb503372010-05-27 20:51:26 +00001333 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00001334 (strchr(argv[i],'%') == (char *) NULL))
1335 ThrowDisplayException(OptionError,"MissingArgument",option);
1336 break;
1337 }
1338 if (LocaleCompare("loop",option+1) == 0)
1339 {
1340 if (*option == '+')
1341 break;
1342 i++;
cristye81f5522014-05-07 01:25:59 +00001343 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001344 ThrowDisplayException(OptionError,"MissingArgument",option);
1345 if (IsGeometry(argv[i]) == MagickFalse)
1346 ThrowDisplayInvalidArgumentException(option,argv[i]);
cristye27293e2009-12-18 02:53:20 +00001347 iterations=StringToUnsignedLong(argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00001348 break;
1349 }
1350 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1351 }
1352 case 'm':
1353 {
1354 if (LocaleCompare("magnify",option+1) == 0)
1355 {
1356 resource_info.magnify=2;
1357 if (*option == '+')
1358 break;
1359 i++;
cristybb503372010-05-27 20:51:26 +00001360 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001361 ThrowDisplayException(OptionError,"MissingArgument",option);
1362 if (IsGeometry(argv[i]) == MagickFalse)
1363 ThrowDisplayInvalidArgumentException(option,argv[i]);
cristye27293e2009-12-18 02:53:20 +00001364 resource_info.magnify=(unsigned int) StringToUnsignedLong(argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00001365 break;
1366 }
1367 if (LocaleCompare("map",option+1) == 0)
1368 {
1369 resource_info.map_type=(char *) NULL;
1370 if (*option == '+')
1371 break;
1372 (void) strcpy(argv[i]+1,"san");
1373 i++;
cristybb503372010-05-27 20:51:26 +00001374 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001375 ThrowDisplayException(OptionError,"MissingArgument",option);
1376 resource_info.map_type=argv[i];
1377 break;
1378 }
1379 if (LocaleCompare("matte",option+1) == 0)
1380 break;
1381 if (LocaleCompare("mattecolor",option+1) == 0)
1382 {
1383 if (*option == '+')
1384 break;
1385 i++;
cristybb503372010-05-27 20:51:26 +00001386 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001387 ThrowDisplayException(OptionError,"MissingArgument",option);
1388 resource_info.matte_color=argv[i];
1389 break;
1390 }
1391 if (LocaleCompare("monitor",option+1) == 0)
1392 break;
1393 if (LocaleCompare("monochrome",option+1) == 0)
1394 {
1395 if (*option == '+')
1396 break;
1397 quantize_info->number_colors=2;
1398 quantize_info->colorspace=GRAYColorspace;
1399 break;
1400 }
1401 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1402 }
1403 case 'n':
1404 {
1405 if (LocaleCompare("name",option+1) == 0)
1406 {
1407 resource_info.name=(char *) NULL;
1408 if (*option == '+')
1409 break;
1410 i++;
cristybb503372010-05-27 20:51:26 +00001411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001412 ThrowDisplayException(OptionError,"MissingArgument",option);
1413 resource_info.name=ConstantString(argv[i]);
1414 break;
1415 }
1416 if (LocaleCompare("negate",option+1) == 0)
1417 break;
1418 if (LocaleCompare("noop",option+1) == 0)
1419 break;
1420 if (LocaleCompare("normalize",option+1) == 0)
1421 break;
1422 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1423 }
1424 case 'p':
1425 {
1426 if (LocaleCompare("page",option+1) == 0)
1427 {
1428 resource_info.image_geometry=(char *) NULL;
1429 if (*option == '+')
1430 break;
1431 i++;
cristybb503372010-05-27 20:51:26 +00001432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001433 ThrowDisplayException(OptionError,"MissingArgument",option);
1434 resource_info.image_geometry=ConstantString(argv[i]);
1435 break;
1436 }
1437 if (LocaleCompare("profile",option+1) == 0)
1438 {
1439 i++;
cristybb503372010-05-27 20:51:26 +00001440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001441 ThrowDisplayException(OptionError,"MissingArgument",option);
1442 break;
1443 }
1444 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1445 }
1446 case 'q':
1447 {
1448 if (LocaleCompare("quality",option+1) == 0)
1449 {
1450 if (*option == '+')
1451 break;
1452 i++;
cristybb503372010-05-27 20:51:26 +00001453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001454 ThrowDisplayException(OptionError,"MissingArgument",option);
1455 if (IsGeometry(argv[i]) == MagickFalse)
1456 ThrowDisplayInvalidArgumentException(option,argv[i]);
1457 break;
1458 }
1459 if (LocaleCompare("quantize",option+1) == 0)
1460 {
cristybb503372010-05-27 20:51:26 +00001461 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001462 colorspace;
1463
1464 if (*option == '+')
1465 break;
1466 i++;
cristye81f5522014-05-07 01:25:59 +00001467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001468 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001469 colorspace=ParseCommandOption(MagickColorspaceOptions,
cristy3ed852e2009-09-05 21:47:34 +00001470 MagickFalse,argv[i]);
1471 if (colorspace < 0)
1472 ThrowDisplayException(OptionError,"UnrecognizedColorspace",
1473 argv[i]);
1474 break;
1475 }
1476 if (LocaleCompare("quiet",option+1) == 0)
1477 break;
1478 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1479 }
1480 case 'r':
1481 {
1482 if (LocaleCompare("raise",option+1) == 0)
1483 {
1484 i++;
cristybb503372010-05-27 20:51:26 +00001485 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001486 ThrowDisplayException(OptionError,"MissingArgument",option);
1487 if (IsGeometry(argv[i]) == MagickFalse)
1488 ThrowDisplayInvalidArgumentException(option,argv[i]);
1489 break;
1490 }
1491 if (LocaleCompare("regard-warnings",option+1) == 0)
1492 break;
1493 if (LocaleCompare("remote",option+1) == 0)
1494 {
1495 i++;
cristybb503372010-05-27 20:51:26 +00001496 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001497 ThrowDisplayException(OptionError,"MissingArgument",option);
1498 if (XRemoteCommand(display,resource_info.window_id,argv[i]) != 0)
1499 return(MagickFalse);
1500 i--;
1501 break;
1502 }
1503 if (LocaleCompare("repage",option+1) == 0)
1504 {
1505 if (*option == '+')
1506 break;
1507 i++;
cristybb503372010-05-27 20:51:26 +00001508 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001509 ThrowDisplayException(OptionError,"MissingArgument",option);
1510 if (IsGeometry(argv[i]) == MagickFalse)
1511 ThrowDisplayInvalidArgumentException(option,argv[i]);
1512 break;
1513 }
1514 if (LocaleCompare("resample",option+1) == 0)
1515 {
1516 if (*option == '+')
1517 break;
1518 i++;
cristye81f5522014-05-07 01:25:59 +00001519 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001520 ThrowDisplayException(OptionError,"MissingArgument",option);
1521 if (IsGeometry(argv[i]) == MagickFalse)
1522 ThrowDisplayInvalidArgumentException(option,argv[i]);
1523 break;
1524 }
1525 if (LocaleCompare("resize",option+1) == 0)
1526 {
1527 if (*option == '+')
1528 break;
1529 i++;
cristybb503372010-05-27 20:51:26 +00001530 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001531 ThrowDisplayException(OptionError,"MissingArgument",option);
1532 if (IsGeometry(argv[i]) == MagickFalse)
1533 ThrowDisplayInvalidArgumentException(option,argv[i]);
1534 break;
1535 }
1536 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1537 {
1538 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1539 break;
1540 }
1541 if (LocaleCompare("roll",option+1) == 0)
1542 {
1543 if (*option == '+')
1544 break;
1545 i++;
cristybb503372010-05-27 20:51:26 +00001546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001547 ThrowDisplayException(OptionError,"MissingArgument",option);
1548 if (IsGeometry(argv[i]) == MagickFalse)
1549 ThrowDisplayInvalidArgumentException(option,argv[i]);
1550 break;
1551 }
1552 if (LocaleCompare("rotate",option+1) == 0)
1553 {
1554 i++;
cristybb503372010-05-27 20:51:26 +00001555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001556 ThrowDisplayException(OptionError,"MissingArgument",option);
1557 if (IsGeometry(argv[i]) == MagickFalse)
1558 ThrowDisplayInvalidArgumentException(option,argv[i]);
1559 break;
1560 }
1561 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1562 }
1563 case 's':
1564 {
1565 if (LocaleCompare("sample",option+1) == 0)
1566 {
1567 if (*option == '+')
1568 break;
1569 i++;
cristybb503372010-05-27 20:51:26 +00001570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001571 ThrowDisplayException(OptionError,"MissingArgument",option);
1572 if (IsGeometry(argv[i]) == MagickFalse)
1573 ThrowDisplayInvalidArgumentException(option,argv[i]);
1574 break;
1575 }
1576 if (LocaleCompare("sampling-factor",option+1) == 0)
1577 {
1578 if (*option == '+')
1579 break;
1580 i++;
cristybb503372010-05-27 20:51:26 +00001581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001582 ThrowDisplayException(OptionError,"MissingArgument",option);
1583 if (IsGeometry(argv[i]) == MagickFalse)
1584 ThrowDisplayInvalidArgumentException(option,argv[i]);
1585 break;
1586 }
1587 if (LocaleCompare("scenes",option+1) == 0)
1588 {
1589 if (*option == '+')
1590 break;
1591 i++;
cristybb503372010-05-27 20:51:26 +00001592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001593 ThrowDisplayException(OptionError,"MissingArgument",option);
1594 if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
1595 ThrowDisplayInvalidArgumentException(option,argv[i]);
1596 break;
1597 }
1598 if (LocaleCompare("seed",option+1) == 0)
1599 {
1600 if (*option == '+')
1601 break;
1602 i++;
cristye81f5522014-05-07 01:25:59 +00001603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001604 ThrowDisplayException(OptionError,"MissingArgument",option);
1605 if (IsGeometry(argv[i]) == MagickFalse)
1606 ThrowDisplayInvalidArgumentException(option,argv[i]);
1607 break;
1608 }
1609 if (LocaleCompare("segment",option+1) == 0)
1610 {
1611 if (*option == '+')
1612 break;
1613 i++;
cristybb503372010-05-27 20:51:26 +00001614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001615 ThrowDisplayException(OptionError,"MissingArgument",option);
1616 if (IsGeometry(argv[i]) == MagickFalse)
1617 ThrowDisplayInvalidArgumentException(option,argv[i]);
1618 break;
1619 }
1620 if (LocaleCompare("set",option+1) == 0)
1621 {
1622 i++;
cristybb503372010-05-27 20:51:26 +00001623 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001624 ThrowDisplayException(OptionError,"MissingArgument",option);
1625 if (*option == '+')
1626 break;
1627 i++;
cristybb503372010-05-27 20:51:26 +00001628 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001629 ThrowDisplayException(OptionError,"MissingArgument",option);
1630 break;
1631 }
1632 if (LocaleCompare("sharpen",option+1) == 0)
1633 {
1634 if (*option == '+')
1635 break;
1636 i++;
cristybb503372010-05-27 20:51:26 +00001637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001638 ThrowDisplayException(OptionError,"MissingArgument",option);
1639 if (IsGeometry(argv[i]) == MagickFalse)
1640 ThrowDisplayInvalidArgumentException(option,argv[i]);
1641 break;
1642 }
1643 if (LocaleCompare("shared-memory",option+1) == 0)
1644 {
1645 resource_info.use_shared_memory= (*option == '-') ? MagickTrue :
1646 MagickFalse;
1647 break;
1648 }
1649 if (LocaleCompare("size",option+1) == 0)
1650 {
1651 if (*option == '+')
1652 break;
1653 i++;
cristybb503372010-05-27 20:51:26 +00001654 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001655 ThrowDisplayException(OptionError,"MissingArgument",option);
1656 if (IsGeometry(argv[i]) == MagickFalse)
1657 ThrowDisplayInvalidArgumentException(option,argv[i]);
1658 break;
1659 }
1660 if (LocaleCompare("strip",option+1) == 0)
1661 break;
1662 if (LocaleCompare("support",option+1) == 0)
1663 {
1664 i++; /* deprecated */
1665 break;
1666 }
1667 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1668 }
1669 case 't':
1670 {
1671 if (LocaleCompare("text-font",option+1) == 0)
1672 {
1673 resource_info.text_font=(char *) NULL;
1674 if (*option == '+')
1675 break;
1676 i++;
cristybb503372010-05-27 20:51:26 +00001677 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001678 ThrowDisplayException(OptionError,"MissingArgument",option);
1679 resource_info.text_font=XGetResourceClass(resource_database,
1680 GetClientName(),"font",argv[i]);
1681 break;
1682 }
1683 if (LocaleCompare("texture",option+1) == 0)
1684 {
1685 if (*option == '+')
1686 break;
1687 i++;
cristybb503372010-05-27 20:51:26 +00001688 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001689 ThrowDisplayException(OptionError,"MissingArgument",option);
1690 break;
1691 }
1692 if (LocaleCompare("threshold",option+1) == 0)
1693 {
1694 if (*option == '+')
1695 break;
1696 i++;
cristybb503372010-05-27 20:51:26 +00001697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001698 ThrowDisplayException(OptionError,"MissingArgument",option);
1699 if (IsGeometry(argv[i]) == MagickFalse)
1700 ThrowDisplayInvalidArgumentException(option,argv[i]);
1701 break;
1702 }
1703 if (LocaleCompare("thumbnail",option+1) == 0)
1704 {
1705 if (*option == '+')
1706 break;
1707 i++;
cristybb503372010-05-27 20:51:26 +00001708 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001709 ThrowDisplayException(OptionError,"MissingArgument",option);
1710 if (IsGeometry(argv[i]) == MagickFalse)
1711 ThrowDisplayInvalidArgumentException(option,argv[i]);
1712 break;
1713 }
1714 if (LocaleCompare("title",option+1) == 0)
1715 {
1716 resource_info.title=(char *) NULL;
1717 if (*option == '+')
1718 break;
1719 i++;
cristybb503372010-05-27 20:51:26 +00001720 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001721 ThrowDisplayException(OptionError,"MissingArgument",option);
1722 resource_info.title=argv[i];
1723 break;
1724 }
1725 if (LocaleCompare("transparent-color",option+1) == 0)
1726 {
1727 if (*option == '+')
1728 break;
1729 i++;
cristye81f5522014-05-07 01:25:59 +00001730 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001731 ThrowDisplayException(OptionError,"MissingArgument",option);
1732 break;
1733 }
1734 if (LocaleCompare("treedepth",option+1) == 0)
1735 {
1736 quantize_info->tree_depth=0;
1737 if (*option == '+')
1738 break;
1739 i++;
cristybb503372010-05-27 20:51:26 +00001740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001741 ThrowDisplayException(OptionError,"MissingArgument",option);
1742 if (IsGeometry(argv[i]) == MagickFalse)
1743 ThrowDisplayInvalidArgumentException(option,argv[i]);
cristye27293e2009-12-18 02:53:20 +00001744 quantize_info->tree_depth=StringToUnsignedLong(argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00001745 break;
1746 }
1747 if (LocaleCompare("trim",option+1) == 0)
1748 break;
1749 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1750 }
1751 case 'u':
1752 {
1753 if (LocaleCompare("update",option+1) == 0)
1754 {
1755 resource_info.update=(unsigned int) (*option == '-');
1756 if (*option == '+')
1757 break;
1758 i++;
cristybb503372010-05-27 20:51:26 +00001759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001760 ThrowDisplayException(OptionError,"MissingArgument",option);
1761 if (IsGeometry(argv[i]) == MagickFalse)
1762 ThrowDisplayInvalidArgumentException(option,argv[i]);
cristye27293e2009-12-18 02:53:20 +00001763 resource_info.update=(unsigned int) StringToUnsignedLong(argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00001764 break;
1765 }
1766 if (LocaleCompare("use-pixmap",option+1) == 0)
1767 {
1768 resource_info.use_pixmap=(*option == '-') ? MagickTrue :
1769 MagickFalse;
1770 break;
1771 }
1772 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1773 }
1774 case 'v':
1775 {
1776 if (LocaleCompare("verbose",option+1) == 0)
1777 break;
1778 if ((LocaleCompare("version",option+1) == 0) ||
1779 (LocaleCompare("-version",option+1) == 0))
1780 {
cristy4f7a6132012-12-23 00:35:19 +00001781 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +00001782 break;
1783 }
1784 if (LocaleCompare("visual",option+1) == 0)
1785 {
1786 resource_info.visual_type=(char *) NULL;
1787 if (*option == '+')
1788 break;
1789 i++;
cristybb503372010-05-27 20:51:26 +00001790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001791 ThrowDisplayException(OptionError,"MissingArgument",option);
1792 resource_info.visual_type=argv[i];
1793 break;
1794 }
1795 if (LocaleCompare("virtual-pixel",option+1) == 0)
1796 {
cristybb503372010-05-27 20:51:26 +00001797 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001798 method;
1799
1800 if (*option == '+')
1801 break;
1802 i++;
cristye81f5522014-05-07 01:25:59 +00001803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001804 ThrowDisplayException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00001805 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00001806 argv[i]);
1807 if (method < 0)
1808 ThrowDisplayException(OptionError,
1809 "UnrecognizedVirtualPixelMethod",argv[i]);
1810 break;
1811 }
1812 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1813 }
1814 case 'w':
1815 {
1816 if (LocaleCompare("window",option+1) == 0)
1817 {
1818 resource_info.window_id=(char *) NULL;
1819 if (*option == '+')
1820 break;
1821 i++;
cristybb503372010-05-27 20:51:26 +00001822 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001823 ThrowDisplayException(OptionError,"MissingArgument",option);
1824 resource_info.window_id=argv[i];
1825 break;
1826 }
1827 if (LocaleCompare("window-group",option+1) == 0)
1828 {
1829 resource_info.window_group=(char *) NULL;
1830 if (*option == '+')
1831 break;
1832 i++;
cristybb503372010-05-27 20:51:26 +00001833 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001834 ThrowDisplayException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00001835 if (StringToDouble(argv[i],(char **) NULL) != 0)
cristy3ed852e2009-09-05 21:47:34 +00001836 resource_info.window_group=argv[i];
1837 break;
1838 }
1839 if (LocaleCompare("write",option+1) == 0)
1840 {
1841 resource_info.write_filename=(char *) NULL;
1842 if (*option == '+')
1843 break;
1844 i++;
cristybb503372010-05-27 20:51:26 +00001845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00001846 ThrowDisplayException(OptionError,"MissingArgument",option);
1847 resource_info.write_filename=argv[i];
1848 if (IsPathAccessible(resource_info.write_filename) != MagickFalse)
1849 {
1850 char
1851 answer[2],
1852 *p;
1853
cristyb51dff52011-05-19 16:55:47 +00001854 (void) FormatLocaleFile(stderr,"Overwrite %s? ",
cristy3ed852e2009-09-05 21:47:34 +00001855 resource_info.write_filename);
1856 p=fgets(answer,(int) sizeof(answer),stdin);
cristyda16f162011-02-19 23:52:17 +00001857 (void) p;
cristy3ed852e2009-09-05 21:47:34 +00001858 if (((*answer != 'y') && (*answer != 'Y')))
1859 return(MagickFalse);
1860 }
1861 break;
1862 }
1863 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1864 }
1865 case '?':
1866 break;
1867 default:
1868 ThrowDisplayException(OptionError,"UnrecognizedOption",option);
1869 }
cristy042ee782011-04-22 18:48:30 +00001870 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1871 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00001872 if (fire != MagickFalse)
1873 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1874 }
1875 if (k != 0)
1876 ThrowDisplayException(OptionError,"UnbalancedParenthesis",argv[i]);
1877 if (state & RetainColorsState)
1878 {
1879 XRetainWindowColors(display,XRootWindow(display,XDefaultScreen(display)));
1880 (void) XSync(display,MagickFalse);
1881 }
1882 DestroyDisplay();
1883 return(status != 0 ? MagickTrue : MagickFalse);
1884#else
1885 (void) argc;
1886 (void) argv;
1887 (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
anthonye5b39652012-04-21 05:37:29 +00001888 "DelegateLibrarySupportNotBuiltIn","'%s' (X11)",image_info->filename);
cristy3ed852e2009-09-05 21:47:34 +00001889 return(DisplayUsage());
1890#endif
1891}