PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/ImageMagick-6.3.2/wand/animate.c

https://bitbucket.org/sisko/operation-caribou
C | 1317 lines | 1172 code | 31 blank | 114 comment | 523 complexity | 4ecc9c2b6629dd21d3bf1a2fb744a02d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1
  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % %
  4. % %
  5. % %
  6. % AAA N N IIIII M M AAA TTTTT EEEEE %
  7. % A A NN N I MM MM A A T E %
  8. % AAAAA N N N I M M M AAAAA T EEE %
  9. % A A N NN I M M A A T E %
  10. % A A N N IIIII M M A A T EEEEE %
  11. % %
  12. % %
  13. % Methods to Interactively Animate an Image Sequence %
  14. % %
  15. % Software Design %
  16. % John Cristy %
  17. % July 1992 %
  18. % %
  19. % %
  20. % Copyright 1999-2006 ImageMagick Studio LLC, a non-profit organization %
  21. % dedicated to making software imaging solutions freely available. %
  22. % %
  23. % You may not use this file except in compliance with the License. You may %
  24. % obtain a copy of the License at %
  25. % %
  26. % http://www.imagemagick.org/script/license.php %
  27. % %
  28. % Unless required by applicable law or agreed to in writing, software %
  29. % distributed under the License is distributed on an "AS IS" BASIS, %
  30. % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
  31. % See the License for the specific language governing permissions and %
  32. % limitations under the License. %
  33. % %
  34. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  35. %
  36. %
  37. */
  38. /*
  39. Include declarations.
  40. */
  41. #include "wand/studio.h"
  42. #include "wand/MagickWand.h"
  43. #include "wand/mogrify-private.h"
  44. #include "magick/animate-private.h"
  45. /*
  46. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47. % %
  48. % %
  49. % %
  50. + A n i m a t e I m a g e C o m m a n d %
  51. % %
  52. % %
  53. % %
  54. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  55. %
  56. % AnimateImageCommand() displays a sequence of images on any workstation
  57. % display running an X server. Animate first determines the hardware
  58. % capabilities of the workstation. If the number of unique colors in an image
  59. % is less than or equal to the number the workstation can support, the image
  60. % is displayed in an X window. Otherwise the number of colors in the image is
  61. % first reduced to match the color resolution of the workstation before it is
  62. % displayed.
  63. %
  64. % This means that a continuous-tone 24 bits/pixel image can display on a 8
  65. % bit pseudo-color device or monochrome device. In most instances the reduced
  66. % color image closely resembles the original. Alternatively, a monochrome or
  67. % pseudo-color image sequence can display on a continuous-tone 24 bits/pixels
  68. % device.
  69. %
  70. % The format of the AnimateImageCommand method is:
  71. %
  72. % MagickBooleanType AnimateImageCommand(ImageInfo *image_info,int argc,
  73. % char **argv,char **metadata,ExceptionInfo *exception)
  74. %
  75. % A description of each parameter follows:
  76. %
  77. % o image_info: The image info.
  78. %
  79. % o argc: The number of elements in the argument vector.
  80. %
  81. % o argv: A text array containing the command line arguments.
  82. %
  83. % o metadata: any metadata is returned here.
  84. %
  85. % o exception: Return any errors or warnings in this structure.
  86. %
  87. %
  88. */
  89. static void AnimateUsage(void)
  90. {
  91. const char
  92. **p;
  93. static const char
  94. *buttons[]=
  95. {
  96. "Press any button to map or unmap the Command widget",
  97. (char *) NULL
  98. },
  99. *operators[]=
  100. {
  101. "-colors value preferred number of colors in the image",
  102. "-crop geometry preferred size and location of the cropped image",
  103. "-extract geometry extract area from image",
  104. "-monochrome transform image to black and white",
  105. "-repage geometry size and location of an image canvas (operator)",
  106. "-resample geometry change the resolution of an image",
  107. "-resize geometry resize the image",
  108. "-rotate degrees apply Paeth rotation to the image",
  109. "-strip strip image of all profiles and comments",
  110. "-trim trim image edges",
  111. (char *) NULL
  112. },
  113. *settings[]=
  114. {
  115. "-authenticate value decrypt image with this password",
  116. "-backdrop display image centered on a backdrop",
  117. "-channel type apply option to select image channels",
  118. "-colormap type Shared or Private",
  119. "-colorspace type alternate image colorspace",
  120. "-debug events display copious debugging information",
  121. "-define format:option",
  122. " define one or more image format options",
  123. "-delay value display the next image after pausing",
  124. "-density geometry horizontal and vertical density of the image",
  125. "-depth value image depth",
  126. "-display server display image to this X server",
  127. "-dither apply Floyd/Steinberg error diffusion to image",
  128. "-format \"string\" output formatted image characteristics",
  129. "-gamma value level of gamma correction",
  130. "-geometry geometry preferred size and location of the Image window",
  131. "-help print program options",
  132. "-identify identify the format and characteristics of the image",
  133. "-interlace type type of image interlacing scheme",
  134. "-interpolate method pixel color interpolation method",
  135. "-limit type value pixel cache resource limit",
  136. "-log format format of debugging information",
  137. "-loop iterations loop images then exit",
  138. "-matte store matte channel if the image has one",
  139. "-map type display image using this Standard Colormap",
  140. "-monitor monitor progress",
  141. "-pause seconds to pause before reanimating",
  142. "-page geometry size and location of an image canvas (setting)",
  143. "-quantize colorspace reduce colors in this colorspace",
  144. "-quiet suppress all error or warning messages",
  145. "-regard-warnings pay attention to warning messages",
  146. "-remote command execute a command in an remote display process",
  147. "-sampling-factor geometry",
  148. " horizontal and vertical sampling factor",
  149. "-scenes range image scene range",
  150. "-set attribute value set an image attribute",
  151. "-size geometry width and height of image",
  152. "-support factor resize support: > 1.0 is blurry, < 1.0 is sharp",
  153. "-transparent-color color",
  154. " transparent color",
  155. "-treedepth value color tree depth",
  156. "-verbose print detailed information about the image",
  157. "-version print version information",
  158. "-visual type display image using this visual type",
  159. "-virtual-pixel method",
  160. " virtual pixel access method",
  161. "-window id display image to background of this window",
  162. (char *) NULL
  163. },
  164. *sequence_operators[]=
  165. {
  166. "-coalesce merge a sequence of images",
  167. "-flatten flatten a sequence of images",
  168. (char *) NULL
  169. };
  170. (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
  171. (void) printf("Copyright: %s\n\n",GetMagickCopyright());
  172. (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
  173. GetClientName());
  174. (void) printf("\nImage Settings:\n");
  175. for (p=settings; *p != (char *) NULL; p++)
  176. (void) printf(" %s\n",*p);
  177. (void) printf("\nImage Operators:\n");
  178. for (p=operators; *p != (char *) NULL; p++)
  179. (void) printf(" %s\n",*p);
  180. (void) printf("\nImage Sequence Operators:\n");
  181. for (p=sequence_operators; *p != (char *) NULL; p++)
  182. (void) printf(" %s\n",*p);
  183. (void) printf(
  184. "\nIn addition to those listed above, you can specify these standard X\n");
  185. (void) printf(
  186. "resources as command line options: -background, -bordercolor,\n");
  187. (void) printf(
  188. "-borderwidth, -font, -foreground, -iconGeometry, -iconic, -name,\n");
  189. (void) printf("-mattecolor, -shared-memory, or -title.\n");
  190. (void) printf(
  191. "\nBy default, the image format of `file' is determined by its magic\n");
  192. (void) printf(
  193. "number. To specify a particular image format, precede the filename\n");
  194. (void) printf(
  195. "with an image format name and a colon (i.e. ps:image) or specify the\n");
  196. (void) printf(
  197. "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
  198. (void) printf("'-' for standard input or output.\n");
  199. (void) printf("\nButtons: \n");
  200. for (p=buttons; *p != (char *) NULL; p++)
  201. (void) printf(" %s\n",*p);
  202. exit(0);
  203. }
  204. WandExport MagickBooleanType AnimateImageCommand(ImageInfo *image_info,
  205. int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
  206. {
  207. #if defined(HasX11)
  208. #define DestroyAnimate() \
  209. { \
  210. XDestroyResourceInfo(&resource_info); \
  211. if (display != (Display *) NULL) \
  212. { \
  213. XCloseDisplay(display); \
  214. display=(Display *) NULL; \
  215. } \
  216. XDestroyResourceInfo(&resource_info); \
  217. for ( ; k >= 0; k--) \
  218. image_stack[k]=DestroyImageList(image_stack[k]); \
  219. for (i=0; i < (long) argc; i++) \
  220. argv[i]=(char *) RelinquishMagickMemory(argv[i]); \
  221. argv=(char **) RelinquishMagickMemory(argv); \
  222. }
  223. #define ThrowAnimateException(asperity,tag,option) \
  224. { \
  225. (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
  226. option); \
  227. DestroyAnimate(); \
  228. return(MagickFalse); \
  229. }
  230. #define ThrowAnimateInvalidArgumentException(option,argument) \
  231. { \
  232. (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
  233. "InvalidArgument","`%s': %s",argument,option); \
  234. DestroyAnimate(); \
  235. return(MagickFalse); \
  236. }
  237. char
  238. *resource_value,
  239. *server_name;
  240. const char
  241. *option;
  242. Display
  243. *display;
  244. Image
  245. *image_stack[MaxImageStackDepth+1];
  246. long
  247. first_scene,
  248. j,
  249. k,
  250. last_scene,
  251. scene;
  252. MagickBooleanType
  253. fire,
  254. pend;
  255. MagickStatusType
  256. status;
  257. QuantizeInfo
  258. *quantize_info;
  259. register long
  260. i;
  261. XResourceInfo
  262. resource_info;
  263. XrmDatabase
  264. resource_database;
  265. /*
  266. Set defaults.
  267. */
  268. assert(image_info != (ImageInfo *) NULL);
  269. assert(image_info->signature == MagickSignature);
  270. if (image_info->debug != MagickFalse)
  271. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  272. assert(exception != (ExceptionInfo *) NULL);
  273. status=MagickTrue;
  274. SetNotifyHandlers;
  275. display=(Display *) NULL;
  276. first_scene=0;
  277. j=1;
  278. k=0;
  279. image_stack[k]=NewImageList();
  280. last_scene=0;
  281. option=(char *) NULL;
  282. pend=MagickFalse;
  283. resource_database=(XrmDatabase) NULL;
  284. (void) ResetMagickMemory(&resource_info,0,sizeof(XResourceInfo));
  285. server_name=(char *) NULL;
  286. status=MagickTrue;
  287. /*
  288. Check for server name specified on the command line.
  289. */
  290. ReadCommandlLine(argc,&argv);
  291. status=ExpandFilenames(&argc,&argv);
  292. if (status == MagickFalse)
  293. ThrowAnimateException(ResourceLimitError,"MemoryAllocationFailed",
  294. image_info->filename);
  295. for (i=1; i < (long) argc; i++)
  296. {
  297. /*
  298. Check command line for server name.
  299. */
  300. option=argv[i];
  301. if (IsMagickOption(option) == MagickFalse)
  302. continue;
  303. if (LocaleCompare("display",option+1) == 0)
  304. {
  305. /*
  306. User specified server name.
  307. */
  308. i++;
  309. if (i == (long) argc)
  310. ThrowAnimateException(OptionError,"MissingArgument",option);
  311. server_name=argv[i];
  312. }
  313. if ((LocaleCompare("help",option+1) == 0) ||
  314. (LocaleCompare("-help",option+1) == 0))
  315. AnimateUsage();
  316. }
  317. /*
  318. Get user defaults from X resource database.
  319. */
  320. display=XOpenDisplay(server_name);
  321. if (display == (Display *) NULL)
  322. ThrowAnimateException(XServerError,"UnableToOpenXServer",
  323. XDisplayName(server_name));
  324. (void) XSetErrorHandler(XError);
  325. resource_database=XGetResourceDatabase(display,GetClientName());
  326. XGetResourceInfo(resource_database,GetClientName(),&resource_info);
  327. image_info=resource_info.image_info;
  328. quantize_info=resource_info.quantize_info;
  329. image_info->density=XGetResourceInstance(resource_database,GetClientName(),
  330. "density",(char *) NULL);
  331. if (image_info->density == (char *) NULL)
  332. image_info->density=XGetScreenDensity(display);
  333. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  334. "interlace","none");
  335. image_info->interlace=(InterlaceType)
  336. ParseMagickOption(MagickInterlaceOptions,MagickFalse,resource_value);
  337. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  338. "verbose","False");
  339. image_info->verbose=IsMagickTrue(resource_value);
  340. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  341. "dither","True");
  342. quantize_info->dither=IsMagickTrue(resource_value);
  343. /*
  344. Parse command line.
  345. */
  346. for (i=1; i <= (long) argc; i++)
  347. {
  348. if (i < (long) argc)
  349. option=argv[i];
  350. else
  351. if (image_stack[k] != (Image *) NULL)
  352. break;
  353. else
  354. if (isatty(STDIN_FILENO) != MagickFalse)
  355. option="logo:";
  356. else
  357. {
  358. int
  359. c;
  360. c=getc(stdin);
  361. if (c == EOF)
  362. option="logo:";
  363. else
  364. {
  365. c=ungetc(c,stdin);
  366. option="-";
  367. }
  368. }
  369. if (LocaleCompare(option,"(") == 0)
  370. {
  371. MogrifyImageStack(image_stack[k],MagickTrue,pend);
  372. if (k == MaxImageStackDepth)
  373. ThrowAnimateException(OptionError,"ParenthesisNestedTooDeeply",
  374. option);
  375. k++;
  376. image_stack[k]=NewImageList();
  377. continue;
  378. }
  379. if (LocaleCompare(option,")") == 0)
  380. {
  381. if (k == 0)
  382. ThrowAnimateException(OptionError,"UnableToParseExpression",option);
  383. if (image_stack[k] != (Image *) NULL)
  384. {
  385. MogrifyImageStack(image_stack[k],MagickTrue,MagickTrue);
  386. AppendImageToList(&image_stack[k-1],image_stack[k]);
  387. }
  388. k--;
  389. continue;
  390. }
  391. if (IsMagickOption(option) == MagickFalse)
  392. {
  393. Image
  394. *image;
  395. /*
  396. Option is a file name.
  397. */
  398. MogrifyImageStack(image_stack[k],MagickTrue,pend);
  399. for (scene=first_scene; scene <= last_scene ; scene++)
  400. {
  401. const char
  402. *filename;
  403. /*
  404. Read image.
  405. */
  406. filename=option;
  407. if ((LocaleCompare(filename,"--") == 0) && (i < (argc-1)))
  408. {
  409. option=argv[++i];
  410. filename=option;
  411. }
  412. (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
  413. if (first_scene != last_scene)
  414. {
  415. char
  416. filename[MaxTextExtent];
  417. /*
  418. Form filename for multi-part images.
  419. */
  420. (void) InterpretImageFilename(filename,MaxTextExtent,
  421. image_info->filename,(int) scene);
  422. if (LocaleCompare(filename,image_info->filename) == 0)
  423. (void) FormatMagickString(filename,MaxTextExtent,"%s[%lu]",
  424. image_info->filename,scene);
  425. (void) CopyMagickString(image_info->filename,filename,
  426. MaxTextExtent);
  427. }
  428. image=ReadImage(image_info,exception);
  429. status&=(image != (Image *) NULL) &&
  430. (exception->severity < ErrorException);
  431. if (image == (Image *) NULL)
  432. continue;
  433. AppendImageToList(&image_stack[k],image);
  434. }
  435. continue;
  436. }
  437. pend=image_stack[k] != (Image *) NULL ? MagickTrue : MagickFalse;
  438. switch (*(option+1))
  439. {
  440. case 'a':
  441. {
  442. if (LocaleCompare("authenticate",option+1) == 0)
  443. {
  444. if (*option == '+')
  445. break;
  446. i++;
  447. if (i == (long) argc)
  448. ThrowAnimateException(OptionError,"MissingArgument",option);
  449. break;
  450. }
  451. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  452. }
  453. case 'b':
  454. {
  455. if (LocaleCompare("backdrop",option+1) == 0)
  456. {
  457. resource_info.backdrop=(*option == '-') ? MagickTrue : MagickFalse;
  458. break;
  459. }
  460. if (LocaleCompare("background",option+1) == 0)
  461. {
  462. if (*option == '+')
  463. break;
  464. i++;
  465. if (i == (long) argc)
  466. ThrowAnimateException(OptionError,"MissingArgument",option);
  467. resource_info.background_color=argv[i];
  468. break;
  469. }
  470. if (LocaleCompare("bordercolor",option+1) == 0)
  471. {
  472. if (*option == '+')
  473. break;
  474. i++;
  475. if (i == (long) argc)
  476. ThrowAnimateException(OptionError,"MissingArgument",option);
  477. resource_info.border_color=argv[i];
  478. break;
  479. }
  480. if (LocaleCompare("borderwidth",option+1) == 0)
  481. {
  482. resource_info.border_width=0;
  483. if (*option == '+')
  484. break;
  485. i++;
  486. if ((i == (long) argc) || (IsGeometry(argv[i]) == MagickFalse))
  487. ThrowAnimateException(OptionError,"MissingArgument",option);
  488. resource_info.border_width=(unsigned int) atoi(argv[i]);
  489. break;
  490. }
  491. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  492. }
  493. case 'c':
  494. {
  495. if (LocaleCompare("cache",option+1) == 0)
  496. {
  497. if (*option == '+')
  498. break;
  499. i++;
  500. if (i == (long) argc)
  501. ThrowAnimateException(OptionError,"MissingArgument",option);
  502. if (IsGeometry(argv[i]) == MagickFalse)
  503. ThrowAnimateInvalidArgumentException(option,argv[i]);
  504. break;
  505. }
  506. if (LocaleCompare("channel",option+1) == 0)
  507. {
  508. long
  509. channel;
  510. if (*option == '+')
  511. break;
  512. i++;
  513. if (i == (long) (argc-1))
  514. ThrowAnimateException(OptionError,"MissingArgument",option);
  515. channel=ParseChannelOption(argv[i]);
  516. if (channel < 0)
  517. ThrowAnimateException(OptionError,"UnrecognizedChannelType",
  518. argv[i]);
  519. break;
  520. }
  521. if (LocaleCompare("clone",option+1) == 0)
  522. {
  523. Image
  524. *clone_images;
  525. clone_images=image_stack[k];
  526. if (k != 0)
  527. clone_images=image_stack[k-1];
  528. if (clone_images == (Image *) NULL)
  529. ThrowAnimateException(ImageError,"ImageSequenceRequired",option);
  530. if (*option == '+')
  531. clone_images=CloneImages(clone_images,"-1",exception);
  532. else
  533. {
  534. i++;
  535. if (i == (long) (argc-1))
  536. ThrowAnimateException(OptionError,"MissingArgument",option);
  537. if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
  538. ThrowAnimateInvalidArgumentException(option,argv[i]);
  539. clone_images=CloneImages(clone_images,argv[i],exception);
  540. }
  541. if (clone_images == (Image *) NULL)
  542. ThrowAnimateException(OptionError,"NoSuchImage",option);
  543. MogrifyImageStack(image_stack[k],MagickTrue,MagickTrue);
  544. AppendImageToList(&image_stack[k],clone_images);
  545. break;
  546. }
  547. if (LocaleCompare("coalesce",option+1) == 0)
  548. break;
  549. if (LocaleCompare("colormap",option+1) == 0)
  550. {
  551. resource_info.colormap=PrivateColormap;
  552. if (*option == '+')
  553. break;
  554. i++;
  555. if (i == (long) argc)
  556. ThrowAnimateException(OptionError,"MissingArgument",option);
  557. resource_info.colormap=UndefinedColormap;
  558. if (LocaleCompare("private",argv[i]) == 0)
  559. resource_info.colormap=PrivateColormap;
  560. if (LocaleCompare("shared",argv[i]) == 0)
  561. resource_info.colormap=SharedColormap;
  562. if (resource_info.colormap == UndefinedColormap)
  563. ThrowAnimateException(OptionError,"UnrecognizedColormapType",
  564. argv[i]);
  565. break;
  566. }
  567. if (LocaleCompare("colors",option+1) == 0)
  568. {
  569. quantize_info->number_colors=0;
  570. if (*option == '+')
  571. break;
  572. i++;
  573. if (i == (long) argc)
  574. ThrowAnimateException(OptionError,"MissingArgument",option);
  575. if (IsGeometry(argv[i]) == MagickFalse)
  576. ThrowAnimateInvalidArgumentException(option,argv[i]);
  577. quantize_info->number_colors=(unsigned long) atol(argv[i]);
  578. break;
  579. }
  580. if (LocaleCompare("colorspace",option+1) == 0)
  581. {
  582. long
  583. colorspace;
  584. if (*option == '+')
  585. break;
  586. i++;
  587. if (i == (long) argc)
  588. ThrowAnimateException(OptionError,"MissingArgument",option);
  589. colorspace=ParseMagickOption(MagickColorspaceOptions,
  590. MagickFalse,argv[i]);
  591. if (colorspace < 0)
  592. ThrowAnimateException(OptionError,"UnrecognizedColorspace",
  593. argv[i]);
  594. break;
  595. }
  596. if (LocaleCompare("crop",option+1) == 0)
  597. {
  598. if (*option == '+')
  599. break;
  600. i++;
  601. if (i == (long) argc)
  602. ThrowAnimateException(OptionError,"MissingArgument",option);
  603. if (IsGeometry(argv[i]) == MagickFalse)
  604. ThrowAnimateInvalidArgumentException(option,argv[i]);
  605. break;
  606. }
  607. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  608. }
  609. case 'd':
  610. {
  611. if (LocaleCompare("debug",option+1) == 0)
  612. {
  613. long
  614. event;
  615. if (*option == '+')
  616. break;
  617. i++;
  618. if (i == (long) argc)
  619. ThrowAnimateException(OptionError,"MissingArgument",option);
  620. event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
  621. if (event < 0)
  622. ThrowAnimateException(OptionError,"UnrecognizedEventType",
  623. argv[i]);
  624. (void) SetLogEventMask(argv[i]);
  625. break;
  626. }
  627. if (LocaleCompare("define",option+1) == 0)
  628. {
  629. i++;
  630. if (i == (long) argc)
  631. ThrowAnimateException(OptionError,"MissingArgument",option);
  632. if (*option == '+')
  633. {
  634. const char
  635. *define;
  636. define=GetImageOption(image_info,argv[i]);
  637. if (define == (const char *) NULL)
  638. ThrowAnimateException(OptionError,"NoSuchOption",argv[i]);
  639. break;
  640. }
  641. break;
  642. }
  643. if (LocaleCompare("delay",option+1) == 0)
  644. {
  645. if (*option == '+')
  646. break;
  647. i++;
  648. if (i == (long) argc)
  649. ThrowAnimateException(OptionError,"MissingArgument",option);
  650. if (IsGeometry(argv[i]) == MagickFalse)
  651. ThrowAnimateInvalidArgumentException(option,argv[i]);
  652. break;
  653. }
  654. if (LocaleCompare("density",option+1) == 0)
  655. {
  656. if (*option == '+')
  657. break;
  658. i++;
  659. if (i == (long) argc)
  660. ThrowAnimateException(OptionError,"MissingArgument",option);
  661. if (IsGeometry(argv[i]) == MagickFalse)
  662. ThrowAnimateInvalidArgumentException(option,argv[i]);
  663. break;
  664. }
  665. if (LocaleCompare("depth",option+1) == 0)
  666. {
  667. if (*option == '+')
  668. break;
  669. i++;
  670. if (i == (long) argc)
  671. ThrowAnimateException(OptionError,"MissingArgument",option);
  672. if (IsGeometry(argv[i]) == MagickFalse)
  673. ThrowAnimateInvalidArgumentException(option,argv[i]);
  674. break;
  675. }
  676. if (LocaleCompare("display",option+1) == 0)
  677. {
  678. if (*option == '+')
  679. break;
  680. i++;
  681. if (i == (long) argc)
  682. ThrowAnimateException(OptionError,"MissingArgument",option);
  683. break;
  684. }
  685. if (LocaleCompare("dither",option+1) == 0)
  686. {
  687. quantize_info->dither=(*option == '-') ? MagickTrue : MagickFalse;
  688. break;
  689. }
  690. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  691. }
  692. case 'e':
  693. {
  694. if (LocaleCompare("extract",option+1) == 0)
  695. {
  696. if (*option == '+')
  697. break;
  698. i++;
  699. if (i == (long) argc)
  700. ThrowAnimateException(OptionError,"MissingArgument",option);
  701. if (IsGeometry(argv[i]) == MagickFalse)
  702. ThrowAnimateInvalidArgumentException(option,argv[i]);
  703. break;
  704. }
  705. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  706. }
  707. case 'f':
  708. {
  709. if (LocaleCompare("flatten",option+1) == 0)
  710. break;
  711. if (LocaleCompare("font",option+1) == 0)
  712. {
  713. if (*option == '+')
  714. break;
  715. i++;
  716. if (i == (long) argc)
  717. ThrowAnimateException(OptionError,"MissingArgument",option);
  718. resource_info.font=XGetResourceClass(resource_database,
  719. GetClientName(),"font",argv[i]);
  720. break;
  721. }
  722. if (LocaleCompare("foreground",option+1) == 0)
  723. {
  724. if (*option == '+')
  725. break;
  726. i++;
  727. if (i == (long) argc)
  728. ThrowAnimateException(OptionError,"MissingArgument",option);
  729. resource_info.foreground_color=argv[i];
  730. break;
  731. }
  732. if (LocaleCompare("format",option+1) == 0)
  733. {
  734. if (*option == '+')
  735. break;
  736. i++;
  737. if (i == (long) (argc-1))
  738. ThrowAnimateException(OptionError,"MissingArgument",option);
  739. break;
  740. }
  741. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  742. }
  743. case 'g':
  744. {
  745. if (LocaleCompare("gamma",option+1) == 0)
  746. {
  747. i++;
  748. if (i == (long) argc)
  749. ThrowAnimateException(OptionError,"MissingArgument",option);
  750. if (IsGeometry(argv[i]) == MagickFalse)
  751. ThrowAnimateInvalidArgumentException(option,argv[i]);
  752. break;
  753. }
  754. if (LocaleCompare("geometry",option+1) == 0)
  755. {
  756. resource_info.image_geometry=(char *) NULL;
  757. if (*option == '+')
  758. break;
  759. i++;
  760. if (i == (long) argc)
  761. ThrowAnimateException(OptionError,"MissingArgument",option);
  762. if (IsGeometry(argv[i]) == MagickFalse)
  763. ThrowAnimateInvalidArgumentException(option,argv[i]);
  764. resource_info.image_geometry=ConstantString(argv[i]);
  765. break;
  766. }
  767. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  768. }
  769. case 'h':
  770. {
  771. if ((LocaleCompare("help",option+1) == 0) ||
  772. (LocaleCompare("-help",option+1) == 0))
  773. break;
  774. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  775. }
  776. case 'i':
  777. {
  778. if (LocaleCompare("identify",option+1) == 0)
  779. break;
  780. if (LocaleCompare("iconGeometry",option+1) == 0)
  781. {
  782. resource_info.icon_geometry=(char *) NULL;
  783. if (*option == '+')
  784. break;
  785. i++;
  786. if (i == (long) argc)
  787. ThrowAnimateException(OptionError,"MissingArgument",option);
  788. if (IsGeometry(argv[i]) == MagickFalse)
  789. ThrowAnimateInvalidArgumentException(option,argv[i]);
  790. resource_info.icon_geometry=argv[i];
  791. break;
  792. }
  793. if (LocaleCompare("iconic",option+1) == 0)
  794. {
  795. resource_info.iconic=(*option == '-') ? MagickTrue : MagickFalse;
  796. break;
  797. }
  798. if (LocaleCompare("interlace",option+1) == 0)
  799. {
  800. long
  801. interlace;
  802. if (*option == '+')
  803. break;
  804. i++;
  805. if (i == (long) argc)
  806. ThrowAnimateException(OptionError,"MissingArgument",option);
  807. interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
  808. argv[i]);
  809. if (interlace < 0)
  810. ThrowAnimateException(OptionError,"UnrecognizedInterlaceType",
  811. argv[i]);
  812. break;
  813. }
  814. if (LocaleCompare("interpolate",option+1) == 0)
  815. {
  816. long
  817. interpolate;
  818. if (*option == '+')
  819. break;
  820. i++;
  821. if (i == (long) argc)
  822. ThrowAnimateException(OptionError,"MissingArgument",option);
  823. interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
  824. argv[i]);
  825. if (interpolate < 0)
  826. ThrowAnimateException(OptionError,"UnrecognizedInterpolateMethod",
  827. argv[i]);
  828. break;
  829. }
  830. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  831. }
  832. case 'l':
  833. {
  834. if (LocaleCompare("label",option+1) == 0)
  835. {
  836. if (*option == '+')
  837. break;
  838. i++;
  839. if (i == (long) argc)
  840. ThrowAnimateException(OptionError,"MissingArgument",option);
  841. break;
  842. }
  843. if (LocaleCompare("limit",option+1) == 0)
  844. {
  845. long
  846. resource;
  847. if (*option == '+')
  848. break;
  849. i++;
  850. if (i == (long) argc)
  851. ThrowAnimateException(OptionError,"MissingArgument",option);
  852. resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
  853. argv[i]);
  854. if (resource < 0)
  855. ThrowAnimateException(OptionError,"UnrecognizedResourceType",
  856. argv[i]);
  857. i++;
  858. if (i == (long) argc)
  859. ThrowAnimateException(OptionError,"MissingArgument",option);
  860. if ((LocaleCompare("unlimited",argv[i]) != 0) &&
  861. (IsGeometry(argv[i]) == MagickFalse))
  862. ThrowAnimateInvalidArgumentException(option,argv[i]);
  863. break;
  864. }
  865. if (LocaleCompare("log",option+1) == 0)
  866. {
  867. if (*option == '+')
  868. break;
  869. i++;
  870. if ((i == (long) argc) ||
  871. (strchr(argv[i],'%') == (char *) NULL))
  872. ThrowAnimateException(OptionError,"MissingArgument",option);
  873. break;
  874. }
  875. if (LocaleCompare("loop",option+1) == 0)
  876. {
  877. if (*option == '+')
  878. break;
  879. i++;
  880. if (i == (long) (argc-1))
  881. ThrowAnimateException(OptionError,"MissingArgument",option);
  882. if (IsGeometry(argv[i]) == MagickFalse)
  883. ThrowAnimateInvalidArgumentException(option,argv[i]);
  884. break;
  885. }
  886. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  887. }
  888. case 'm':
  889. {
  890. if (LocaleCompare("map",option+1) == 0)
  891. {
  892. resource_info.map_type=(char *) NULL;
  893. if (*option == '+')
  894. break;
  895. (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
  896. i++;
  897. if (i == (long) argc)
  898. ThrowAnimateException(OptionError,"MissingArgument",option);
  899. resource_info.map_type=argv[i];
  900. break;
  901. }
  902. if (LocaleCompare("matte",option+1) == 0)
  903. break;
  904. if (LocaleCompare("mattecolor",option+1) == 0)
  905. {
  906. if (*option == '+')
  907. break;
  908. i++;
  909. if (i == (long) argc)
  910. ThrowAnimateException(OptionError,"MissingArgument",option);
  911. resource_info.matte_color=argv[i];
  912. break;
  913. }
  914. if (LocaleCompare("monitor",option+1) == 0)
  915. break;
  916. if (LocaleCompare("monochrome",option+1) == 0)
  917. {
  918. if (*option == '+')
  919. break;
  920. quantize_info->number_colors=2;
  921. quantize_info->colorspace=GRAYColorspace;
  922. break;
  923. }
  924. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  925. }
  926. case 'n':
  927. {
  928. if (LocaleCompare("name",option+1) == 0)
  929. {
  930. resource_info.name=(char *) NULL;
  931. if (*option == '+')
  932. break;
  933. i++;
  934. if (i == (long) argc)
  935. ThrowAnimateException(OptionError,"MissingArgument",option);
  936. resource_info.name=argv[i];
  937. break;
  938. }
  939. if (LocaleCompare("noop",option+1) == 0)
  940. break;
  941. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  942. }
  943. case 'p':
  944. {
  945. if (LocaleCompare("pause",option+1) == 0)
  946. {
  947. resource_info.pause=0;
  948. if (*option == '+')
  949. break;
  950. i++;
  951. if (i == (long) argc)
  952. ThrowAnimateException(OptionError,"MissingArgument",option);
  953. if (IsGeometry(argv[i]) == MagickFalse)
  954. ThrowAnimateInvalidArgumentException(option,argv[i]);
  955. resource_info.pause=(unsigned int) atoi(argv[i]);
  956. break;
  957. }
  958. if (LocaleCompare("page",option+1) == 0)
  959. {
  960. if (*option == '+')
  961. break;
  962. i++;
  963. if (i == (long) argc)
  964. ThrowAnimateException(OptionError,"MissingArgument",option);
  965. break;
  966. }
  967. if (LocaleCompare("profile",option+1) == 0)
  968. {
  969. i++;
  970. if (i == (long) argc)
  971. ThrowAnimateException(OptionError,"MissingArgument",option);
  972. break;
  973. }
  974. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  975. }
  976. case 'q':
  977. {
  978. if (LocaleCompare("quantize",option+1) == 0)
  979. {
  980. long
  981. colorspace;
  982. if (*option == '+')
  983. break;
  984. i++;
  985. if (i == (long) (argc-1))
  986. ThrowAnimateException(OptionError,"MissingArgument",option);
  987. colorspace=ParseMagickOption(MagickColorspaceOptions,
  988. MagickFalse,argv[i]);
  989. if (colorspace < 0)
  990. ThrowAnimateException(OptionError,"UnrecognizedColorspace",
  991. argv[i]);
  992. break;
  993. }
  994. if (LocaleCompare("quiet",option+1) == 0)
  995. break;
  996. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  997. }
  998. case 'r':
  999. {
  1000. if (LocaleCompare("regard-warnings",option+1) == 0)
  1001. break;
  1002. if (LocaleCompare("remote",option+1) == 0)
  1003. {
  1004. i++;
  1005. if (i == (long) argc)
  1006. ThrowAnimateException(OptionError,"MissingArgument",option);
  1007. if (XRemoteCommand(display,resource_info.window_id,argv[i]) != 0)
  1008. return(MagickFalse);
  1009. i--;
  1010. break;
  1011. }
  1012. if (LocaleCompare("repage",option+1) == 0)
  1013. {
  1014. if (*option == '+')
  1015. break;
  1016. i++;
  1017. if (i == (long) argc)
  1018. ThrowAnimateException(OptionError,"MissingArgument",option);
  1019. if (IsGeometry(argv[i]) == MagickFalse)
  1020. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1021. break;
  1022. }
  1023. if (LocaleCompare("resample",option+1) == 0)
  1024. {
  1025. if (*option == '+')
  1026. break;
  1027. i++;
  1028. if (i == (long) (argc-1))
  1029. ThrowAnimateException(OptionError,"MissingArgument",option);
  1030. if (IsGeometry(argv[i]) == MagickFalse)
  1031. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1032. break;
  1033. }
  1034. if (LocaleCompare("resize",option+1) == 0)
  1035. {
  1036. if (*option == '+')
  1037. break;
  1038. i++;
  1039. if (i == (long) argc)
  1040. ThrowAnimateException(OptionError,"MissingArgument",option);
  1041. if (IsGeometry(argv[i]) == MagickFalse)
  1042. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1043. break;
  1044. }
  1045. if (LocaleCompare("rotate",option+1) == 0)
  1046. {
  1047. i++;
  1048. if (i == (long) argc)
  1049. ThrowAnimateException(OptionError,"MissingArgument",option);
  1050. if (IsGeometry(argv[i]) == MagickFalse)
  1051. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1052. break;
  1053. }
  1054. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  1055. }
  1056. case 's':
  1057. {
  1058. if (LocaleCompare("sampling-factor",option+1) == 0)
  1059. {
  1060. if (*option == '+')
  1061. break;
  1062. i++;
  1063. if (i == (long) argc)
  1064. ThrowAnimateException(OptionError,"MissingArgument",option);
  1065. if (IsGeometry(argv[i]) == MagickFalse)
  1066. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1067. break;
  1068. }
  1069. if (LocaleCompare("scenes",option+1) == 0)
  1070. {
  1071. first_scene=0;
  1072. last_scene=0;
  1073. if (*option == '+')
  1074. break;
  1075. i++;
  1076. if (i == (long) argc)
  1077. ThrowAnimateException(OptionError,"MissingArgument",option);
  1078. if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
  1079. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1080. first_scene=atol(argv[i]);
  1081. last_scene=first_scene;
  1082. (void) sscanf(argv[i],"%ld-%ld",&first_scene,&last_scene);
  1083. break;
  1084. }
  1085. if (LocaleCompare("set",option+1) == 0)
  1086. {
  1087. i++;
  1088. if (i == (long) argc)
  1089. ThrowAnimateException(OptionError,"MissingArgument",option);
  1090. if (*option == '+')
  1091. break;
  1092. i++;
  1093. if (i == (long) argc)
  1094. ThrowAnimateException(OptionError,"MissingArgument",option);
  1095. break;
  1096. }
  1097. if (LocaleCompare("shared-memory",option+1) == 0)
  1098. {
  1099. resource_info.use_shared_memory=(*option == '-') ? MagickTrue :
  1100. MagickFalse;
  1101. break;
  1102. }
  1103. if (LocaleCompare("size",option+1) == 0)
  1104. {
  1105. if (*option == '+')
  1106. break;
  1107. i++;
  1108. if (i == (long) argc)
  1109. ThrowAnimateException(OptionError,"MissingArgument",option);
  1110. if (IsGeometry(argv[i]) == MagickFalse)
  1111. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1112. break;
  1113. }
  1114. if (LocaleCompare("strip",option+1) == 0)
  1115. break;
  1116. if (LocaleCompare("support",option+1) == 0)
  1117. {
  1118. if (*option == '+')
  1119. break;
  1120. i++;
  1121. if (i == (long) argc)
  1122. ThrowAnimateException(OptionError,"MissingArgument",option);
  1123. if (IsGeometry(argv[i]) == MagickFalse)
  1124. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1125. break;
  1126. }
  1127. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  1128. }
  1129. case 't':
  1130. {
  1131. if (LocaleCompare("text-font",option+1) == 0)
  1132. {
  1133. resource_info.text_font=(char *) NULL;
  1134. if (*option == '+')
  1135. break;
  1136. i++;
  1137. if (i == (long) argc)
  1138. ThrowAnimateException(OptionError,"MissingArgument",option);
  1139. resource_info.text_font=XGetResourceClass(resource_database,
  1140. GetClientName(),"font",argv[i]);
  1141. break;
  1142. }
  1143. if (LocaleCompare("thumbnail",option+1) == 0)
  1144. {
  1145. if (*option == '+')
  1146. break;
  1147. i++;
  1148. if (i == (long) argc)
  1149. ThrowAnimateException(OptionError,"MissingArgument",option);
  1150. if (IsGeometry(argv[i]) == MagickFalse)
  1151. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1152. break;
  1153. }
  1154. if (LocaleCompare("title",option+1) == 0)
  1155. {
  1156. resource_info.title=(char *) NULL;
  1157. if (*option == '+')
  1158. break;
  1159. i++;
  1160. if (i == (long) argc)
  1161. ThrowAnimateException(OptionError,"MissingArgument",option);
  1162. resource_info.title=argv[i];
  1163. break;
  1164. }
  1165. if (LocaleCompare("transparent-color",option+1) == 0)
  1166. {
  1167. if (*option == '+')
  1168. break;
  1169. i++;
  1170. if (i == (long) (argc-1))
  1171. ThrowAnimateException(OptionError,"MissingArgument",option);
  1172. break;
  1173. }
  1174. if (LocaleCompare("treedepth",option+1) == 0)
  1175. {
  1176. quantize_info->tree_depth=0;
  1177. if (*option == '+')
  1178. break;
  1179. i++;
  1180. if (i == (long) argc)
  1181. ThrowAnimateException(OptionError,"MissingArgument",option);
  1182. if (IsGeometry(argv[i]) == MagickFalse)
  1183. ThrowAnimateInvalidArgumentException(option,argv[i]);
  1184. quantize_info->tree_depth=(unsigned long) atol(argv[i]);
  1185. break;
  1186. }
  1187. if (LocaleCompare("trim",option+1) == 0)
  1188. break;
  1189. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  1190. }
  1191. case 'v':
  1192. {
  1193. if (LocaleCompare("verbose",option+1) == 0)
  1194. break;
  1195. if ((LocaleCompare("version",option+1) == 0) ||
  1196. (LocaleCompare("-version",option+1) == 0))
  1197. break;
  1198. if (LocaleCompare("virtual-pixel",option+1) == 0)
  1199. {
  1200. long
  1201. method;
  1202. if (*option == '+')
  1203. break;
  1204. i++;
  1205. if (i == (long) argc)
  1206. ThrowAnimateException(OptionError,"MissingArgument",option);
  1207. method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
  1208. argv[i]);
  1209. if (method < 0)
  1210. ThrowAnimateException(OptionError,
  1211. "UnrecognizedVirtualPixelMethod",argv[i]);
  1212. break;
  1213. }
  1214. if (LocaleCompare("visual",option+1) == 0)
  1215. {
  1216. resource_info.visual_type=(char *) NULL;
  1217. if (*option == '+')
  1218. break;
  1219. i++;
  1220. if (i == (long) argc)
  1221. ThrowAnimateException(OptionError,"MissingArgument",option);
  1222. resource_info.visual_type=argv[i];
  1223. break;
  1224. }
  1225. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  1226. }
  1227. case 'w':
  1228. {
  1229. if (LocaleCompare("window",option+1) == 0)
  1230. {
  1231. resource_info.window_id=(char *) NULL;
  1232. if (*option == '+')
  1233. break;
  1234. i++;
  1235. if (i == (long) argc)
  1236. ThrowAnimateException(OptionError,"MissingArgument",option);
  1237. resource_info.window_id=argv[i];
  1238. break;
  1239. }
  1240. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  1241. }
  1242. case '?':
  1243. break;
  1244. default:
  1245. ThrowAnimateException(OptionError,"UnrecognizedOption",option);
  1246. }
  1247. fire=(MagickBooleanType) ParseMagickOption(MagickMogrifyOptions,
  1248. MagickFalse,option+1);
  1249. if (fire == MagickTrue)
  1250. MogrifyImageStack(image_stack[k],MagickTrue,MagickTrue);
  1251. }
  1252. i--;
  1253. if (k != 0)
  1254. ThrowAnimateException(OptionError,"UnbalancedParenthesis",argv[i]);
  1255. if (image_stack[k] == (Image *) NULL)
  1256. ThrowAnimateException(OptionError,"MissingAnImageFilename",argv[argc-1])
  1257. MogrifyImageStack(image_stack[k],MagickTrue,MagickTrue);
  1258. if (resource_info.window_id != (char *) NULL)
  1259. XAnimateBackgroundImage(display,&resource_info,image_stack[k]);
  1260. else
  1261. {
  1262. Image
  1263. *animate_image;
  1264. /*
  1265. Animate image to X server.
  1266. */
  1267. animate_image=XAnimateImages(display,&resource_info,argv,argc,
  1268. image_stack[k]);
  1269. while (animate_image != (Image *) NULL)
  1270. {
  1271. image_stack[k]=animate_image;
  1272. animate_image=XAnimateImages(display,&resource_info,argv,argc,
  1273. image_stack[k]);
  1274. }
  1275. }
  1276. DestroyAnimate();
  1277. return(status != 0 ? MagickTrue : MagickFalse);
  1278. #else
  1279. (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
  1280. "XWindowLibraryIsNotAvailable","`%s'",image_info->filename);
  1281. AnimateUsage();
  1282. return(MagickFalse);
  1283. #endif
  1284. }