PageRenderTime 65ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/MagickWand/display.c

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