PageRenderTime 62ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/wand/import.c

http://github.com/idaunis/binarytiers
C | 1310 lines | 1167 code | 38 blank | 105 comment | 496 complexity | 92b0d29fea7b5f4cea572c9169665de5 MD5 | raw file
  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % %
  4. % %
  5. % %
  6. % IIIII M M PPPP OOO RRRR TTTTT %
  7. % I MM MM P P O O R R T %
  8. % I M M M PPPP O O RRRR T %
  9. % I M M P O O R R T %
  10. % IIIII M M P OOO R R T %
  11. % %
  12. % %
  13. % Import Image from X11 Screen %
  14. % %
  15. % Software Design %
  16. % John Cristy %
  17. % July 1992 %
  18. % %
  19. % %
  20. % Copyright 1999-2011 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. % Use the import program to capture some or all of an X server screen and
  37. % save the image to a file.
  38. %
  39. */
  40. /*
  41. Include declarations.
  42. */
  43. #include "wand/studio.h"
  44. #include "wand/MagickWand.h"
  45. #include "wand/mogrify-private.h"
  46. #include "magick/xwindow-private.h"
  47. #include "magick/string-private.h"
  48. /*
  49. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  50. % %
  51. % %
  52. % %
  53. + I m p o r t I m a g e C o m m a n d %
  54. % %
  55. % %
  56. % %
  57. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  58. %
  59. % ImportImageCommand() reads an image from any visible window on an X server
  60. % and outputs it as an image file. You can capture a single window, the
  61. % entire screen, or any rectangular portion of the screen. You can use the
  62. % display utility for redisplay, printing, editing, formatting, archiving,
  63. % image processing, etc. of the captured image.</dd>
  64. %
  65. % The target window can be specified by id, name, or may be selected by
  66. % clicking the mouse in the desired window. If you press a button and then
  67. % drag, a rectangle will form which expands and contracts as the mouse moves.
  68. % To save the portion of the screen defined by the rectangle, just release
  69. % the button. The keyboard bell is rung once at the beginning of the screen
  70. % capture and twice when it completes.
  71. %
  72. % The format of the ImportImageCommand method is:
  73. %
  74. % MagickBooleanType ImportImageCommand(ImageInfo *image_info,int argc,
  75. % char **argv,char **metadata,ExceptionInfo *exception)
  76. %
  77. % A description of each parameter follows:
  78. %
  79. % o image_info: the image info.
  80. %
  81. % o argc: the number of elements in the argument vector.
  82. %
  83. % o argv: A text array containing the command line arguments.
  84. %
  85. % o metadata: any metadata is returned here.
  86. %
  87. % o exception: return any errors or warnings in this structure.
  88. %
  89. */
  90. static MagickBooleanType ImportUsage(void)
  91. {
  92. const char
  93. **p;
  94. static const char
  95. *miscellaneous[]=
  96. {
  97. "-debug events display copious debugging information",
  98. "-help print program options",
  99. "-list type print a list of supported option arguments",
  100. "-log format format of debugging information",
  101. "-version print version information",
  102. (char *) NULL
  103. },
  104. *operators[]=
  105. {
  106. "-annotate geometry text",
  107. " annotate the image with text",
  108. "-colors value preferred number of colors in the image",
  109. "-crop geometry preferred size and location of the cropped image",
  110. "-encipher filename convert plain pixels to cipher pixels",
  111. "-geometry geometry preferred size or location of the image",
  112. "-help print program options",
  113. "-monochrome transform image to black and white",
  114. "-negate replace every pixel with its complementary color ",
  115. "-repage geometry size and location of an image canvas",
  116. "-quantize colorspace reduce colors in this colorspace",
  117. "-resize geometry resize the image",
  118. "-rotate degrees apply Paeth rotation to the image",
  119. "-strip strip image of all profiles and comments",
  120. "-thumbnail geometry create a thumbnail of the image",
  121. "-transparent color make this color transparent within the image",
  122. "-trim trim image edges",
  123. "-type type image type",
  124. (char *) NULL
  125. },
  126. *settings[]=
  127. {
  128. "-adjoin join images into a single multi-image file",
  129. "-border include window border in the output image",
  130. "-channel type apply option to select image channels",
  131. "-colorspace type alternate image colorspace",
  132. "-comment string annotate image with comment",
  133. "-compress type type of pixel compression when writing the image",
  134. "-define format:option",
  135. " define one or more image format options",
  136. "-density geometry horizontal and vertical density of the image",
  137. "-depth value image depth",
  138. "-descend obtain image by descending window hierarchy",
  139. "-display server X server to contact",
  140. "-dispose method layer disposal method",
  141. "-dither method apply error diffusion to image",
  142. "-delay value display the next image after pausing",
  143. "-encipher filename convert plain pixels to cipher pixels",
  144. "-endian type endianness (MSB or LSB) of the image",
  145. "-encoding type text encoding type",
  146. "-filter type use this filter when resizing an image",
  147. "-format \"string\" output formatted image characteristics",
  148. "-frame include window manager frame",
  149. "-gravity direction which direction to gravitate towards",
  150. "-identify identify the format and characteristics of the image",
  151. "-interlace type None, Line, Plane, or Partition",
  152. "-interpolate method pixel color interpolation method",
  153. "-label string assign a label to an image",
  154. "-limit type value Area, Disk, Map, or Memory resource limit",
  155. "-monitor monitor progress",
  156. "-page geometry size and location of an image canvas",
  157. "-pause value seconds delay between snapshots",
  158. "-pointsize value font point size",
  159. "-quality value JPEG/MIFF/PNG compression level",
  160. "-quiet suppress all warning messages",
  161. "-regard-warnings pay attention to warning messages",
  162. "-respect-parentheses settings remain in effect until parenthesis boundary",
  163. "-sampling-factor geometry",
  164. " horizontal and vertical sampling factor",
  165. "-scene value image scene number",
  166. "-screen select image from root window",
  167. "-seed value seed a new sequence of pseudo-random numbers",
  168. "-set property value set an image property",
  169. "-silent operate silently, i.e. don't ring any bells ",
  170. "-snaps value number of screen snapshots",
  171. "-synchronize synchronize image to storage device",
  172. "-taint declare the image as modified",
  173. "-transparent-color color",
  174. " transparent color",
  175. "-treedepth value color tree depth",
  176. "-verbose print detailed information about the image",
  177. "-virtual-pixel method",
  178. " Constant, Edge, Mirror, or Tile",
  179. "-window id select window with this id or name",
  180. (char *) NULL
  181. };
  182. (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
  183. (void) printf("Copyright: %s\n",GetMagickCopyright());
  184. (void) printf("Features: %s\n\n",GetMagickFeatures());
  185. (void) printf("Usage: %s [options ...] [ file ]\n",
  186. GetClientName());
  187. (void) printf("\nImage Settings:\n");
  188. for (p=settings; *p != (char *) NULL; p++)
  189. (void) printf(" %s\n",*p);
  190. (void) printf("\nImage Operators:\n");
  191. for (p=operators; *p != (char *) NULL; p++)
  192. (void) printf(" %s\n",*p);
  193. (void) printf("\nMiscellaneous Options:\n");
  194. for (p=miscellaneous; *p != (char *) NULL; p++)
  195. (void) printf(" %s\n",*p);
  196. (void) printf(
  197. "\nBy default, 'file' is written in the MIFF image format. To\n");
  198. (void) printf(
  199. "specify a particular image format, precede the filename with an image\n");
  200. (void) printf(
  201. "format name and a colon (i.e. ps:image) or specify the image type as\n");
  202. (void) printf(
  203. "the filename suffix (i.e. image.ps). Specify 'file' as '-' for\n");
  204. (void) printf("standard input or output.\n");
  205. return(MagickFalse);
  206. }
  207. static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
  208. {
  209. if (x > y)
  210. return(x);
  211. return(y);
  212. }
  213. WandExport MagickBooleanType ImportImageCommand(ImageInfo *image_info,
  214. int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
  215. {
  216. #if defined(MAGICKCORE_X11_DELEGATE)
  217. #define DestroyImport() \
  218. { \
  219. XDestroyResourceInfo(&resource_info); \
  220. if (display != (Display *) NULL) \
  221. { \
  222. XCloseDisplay(display); \
  223. display=(Display *) NULL; \
  224. } \
  225. DestroyImageStack(); \
  226. if (target_window != (char *) NULL) \
  227. target_window=DestroyString(target_window); \
  228. for (i=0; i < (ssize_t) argc; i++) \
  229. argv[i]=DestroyString(argv[i]); \
  230. argv=(char **) RelinquishMagickMemory(argv); \
  231. }
  232. #define ThrowImportException(asperity,tag,option) \
  233. { \
  234. (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
  235. option); \
  236. DestroyImport(); \
  237. return(MagickFalse); \
  238. }
  239. #define ThrowImportInvalidArgumentException(option,argument) \
  240. { \
  241. (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
  242. "InvalidArgument","`%s': %s",option,argument); \
  243. DestroyImport(); \
  244. return(MagickFalse); \
  245. }
  246. char
  247. *filename,
  248. *option,
  249. *resource_value,
  250. *server_name,
  251. *target_window;
  252. Display
  253. *display;
  254. Image
  255. *image;
  256. ImageStack
  257. image_stack[MaxImageStackDepth+1];
  258. ssize_t
  259. j,
  260. k,
  261. snapshots;
  262. MagickBooleanType
  263. fire,
  264. pend,
  265. respect_parenthesis;
  266. MagickStatusType
  267. status;
  268. QuantizeInfo
  269. *quantize_info;
  270. register ssize_t
  271. i;
  272. XImportInfo
  273. ximage_info;
  274. XResourceInfo
  275. resource_info;
  276. XrmDatabase
  277. resource_database;
  278. /*
  279. Set defaults.
  280. */
  281. assert(image_info != (ImageInfo *) NULL);
  282. assert(image_info->signature == MagickSignature);
  283. if (image_info->debug != MagickFalse)
  284. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  285. assert(exception != (ExceptionInfo *) NULL);
  286. if (argc == 2)
  287. {
  288. option=argv[1];
  289. if ((LocaleCompare("version",option+1) == 0) ||
  290. (LocaleCompare("-version",option+1) == 0))
  291. {
  292. (void) fprintf(stdout,"Version: %s\n",
  293. GetMagickVersion((size_t *) NULL));
  294. (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
  295. (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
  296. return(MagickFalse);
  297. }
  298. }
  299. display=(Display *) NULL;
  300. j=1;
  301. k=0;
  302. NewImageStack();
  303. option=(char *) NULL;
  304. pend=MagickFalse;
  305. resource_database=(XrmDatabase) NULL;
  306. respect_parenthesis=MagickFalse;
  307. (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info));
  308. server_name=(char *) NULL;
  309. status=MagickTrue;
  310. SetNotifyHandlers;
  311. target_window=(char *) NULL;
  312. /*
  313. Check for server name specified on the command line.
  314. */
  315. ReadCommandlLine(argc,&argv);
  316. status=ExpandFilenames(&argc,&argv);
  317. if (status == MagickFalse)
  318. ThrowImportException(ResourceLimitError,"MemoryAllocationFailed",
  319. GetExceptionMessage(errno));
  320. for (i=1; i < (ssize_t) argc; i++)
  321. {
  322. /*
  323. Check command line for server name.
  324. */
  325. option=argv[i];
  326. if (LocaleCompare("display",option+1) == 0)
  327. {
  328. /*
  329. User specified server name.
  330. */
  331. i++;
  332. if (i == (ssize_t) argc)
  333. ThrowImportException(OptionError,"MissingArgument",option);
  334. server_name=argv[i];
  335. }
  336. if ((LocaleCompare("help",option+1) == 0) ||
  337. (LocaleCompare("-help",option+1) == 0))
  338. return(ImportUsage());
  339. }
  340. /*
  341. Get user defaults from X resource database.
  342. */
  343. display=XOpenDisplay(server_name);
  344. if (display == (Display *) NULL)
  345. ThrowImportException(XServerError,"UnableToOpenXServer",
  346. XDisplayName(server_name));
  347. (void) XSetErrorHandler(XError);
  348. resource_database=XGetResourceDatabase(display,GetClientName());
  349. XGetImportInfo(&ximage_info);
  350. XGetResourceInfo(image_info,resource_database,GetClientName(),
  351. &resource_info);
  352. quantize_info=resource_info.quantize_info;
  353. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  354. "border","False");
  355. ximage_info.borders=IsMagickTrue(resource_value);
  356. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  357. "delay","0");
  358. resource_info.delay=(unsigned int) StringToUnsignedLong(resource_value);
  359. image_info->density=XGetResourceInstance(resource_database,GetClientName(),
  360. "density",(char *) NULL);
  361. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  362. "descend","True");
  363. ximage_info.descend=IsMagickTrue(resource_value);
  364. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  365. "frame","False");
  366. ximage_info.frame=IsMagickTrue(resource_value);
  367. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  368. "interlace","none");
  369. image_info->interlace=UndefinedInterlace;
  370. if (LocaleCompare("None",resource_value) == 0)
  371. image_info->interlace=NoInterlace;
  372. if (LocaleCompare("Line",resource_value) == 0)
  373. image_info->interlace=LineInterlace;
  374. if (LocaleCompare("Plane",resource_value) == 0)
  375. image_info->interlace=PlaneInterlace;
  376. if (LocaleCompare("Partition",resource_value) == 0)
  377. image_info->interlace=PartitionInterlace;
  378. if (image_info->interlace == UndefinedInterlace)
  379. ThrowImportException(OptionError,"Unrecognized interlace type",
  380. resource_value);
  381. image_info->page=XGetResourceInstance(resource_database,GetClientName(),
  382. "pageGeometry",(char *) NULL);
  383. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  384. "pause","0");
  385. resource_info.pause=(unsigned int) StringToUnsignedLong(resource_value);
  386. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  387. "quality","85");
  388. image_info->quality=StringToUnsignedLong(resource_value);
  389. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  390. "screen","False");
  391. ximage_info.screen=IsMagickTrue(resource_value);
  392. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  393. "silent","False");
  394. ximage_info.silent=IsMagickTrue(resource_value);
  395. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  396. "verbose","False");
  397. image_info->verbose=IsMagickTrue(resource_value);
  398. resource_value=XGetResourceInstance(resource_database,GetClientName(),
  399. "dither","True");
  400. quantize_info->dither=IsMagickTrue(resource_value);
  401. snapshots=1;
  402. status=MagickTrue;
  403. filename=(char *) NULL;
  404. /*
  405. Check command syntax.
  406. */
  407. for (i=1; i < (ssize_t) argc; i++)
  408. {
  409. option=argv[i];
  410. if (LocaleCompare(option,"(") == 0)
  411. {
  412. FireImageStack(MagickFalse,MagickTrue,pend);
  413. if (k == MaxImageStackDepth)
  414. ThrowImportException(OptionError,"ParenthesisNestedTooDeeply",
  415. option);
  416. PushImageStack();
  417. continue;
  418. }
  419. if (LocaleCompare(option,")") == 0)
  420. {
  421. FireImageStack(MagickFalse,MagickTrue,MagickTrue);
  422. if (k == 0)
  423. ThrowImportException(OptionError,"UnableToParseExpression",option);
  424. PopImageStack();
  425. continue;
  426. }
  427. if (IsMagickOption(option) == MagickFalse)
  428. {
  429. Image
  430. *images;
  431. size_t
  432. scene;
  433. /*
  434. Read image from X server.
  435. */
  436. FireImageStack(MagickFalse,MagickFalse,pend);
  437. filename=argv[i];
  438. if (target_window != (char *) NULL)
  439. (void) CopyMagickString(image_info->filename,target_window,
  440. MaxTextExtent);
  441. for (scene=0; scene < (size_t) MagickMax(snapshots,1); scene++)
  442. {
  443. (void) sleep(resource_info.pause);
  444. images=XImportImage(image_info,&ximage_info);
  445. status&=(images != (Image *) NULL) &&
  446. (exception->severity < ErrorException);
  447. if (images == (Image *) NULL)
  448. continue;
  449. (void) CopyMagickString(images->filename,filename,MaxTextExtent);
  450. (void) CopyMagickString(images->magick,"PS",MaxTextExtent);
  451. images->scene=scene;
  452. AppendImageStack(images);
  453. }
  454. continue;
  455. }
  456. pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
  457. switch(*(option+1))
  458. {
  459. case 'a':
  460. {
  461. if (LocaleCompare("adjoin",option+1) == 0)
  462. break;
  463. if (LocaleCompare("annotate",option+1) == 0)
  464. {
  465. if (*option == '+')
  466. break;
  467. i++;
  468. if (i == (ssize_t) (argc-1))
  469. ThrowImportException(OptionError,"MissingArgument",option);
  470. if (IsGeometry(argv[i]) == MagickFalse)
  471. ThrowImportInvalidArgumentException(option,argv[i]);
  472. if (i == (ssize_t) (argc-1))
  473. ThrowImportException(OptionError,"MissingArgument",option);
  474. i++;
  475. break;
  476. }
  477. ThrowImportException(OptionError,"UnrecognizedOption",option);
  478. }
  479. case 'b':
  480. {
  481. if (LocaleCompare("border",option+1) == 0)
  482. {
  483. (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
  484. ximage_info.borders=(*option == '-') ? MagickTrue : MagickFalse;
  485. break;
  486. }
  487. if (LocaleCompare("bordercolor",option+1) == 0)
  488. {
  489. if (*option == '+')
  490. break;
  491. i++;
  492. if (i == (ssize_t) argc)
  493. ThrowImportException(OptionError,"MissingArgument",option);
  494. break;
  495. }
  496. ThrowImportException(OptionError,"UnrecognizedOption",option);
  497. }
  498. case 'c':
  499. {
  500. if (LocaleCompare("cache",option+1) == 0)
  501. {
  502. if (*option == '+')
  503. break;
  504. i++;
  505. if (i == (ssize_t) argc)
  506. ThrowImportException(OptionError,"MissingArgument",option);
  507. if (IsGeometry(argv[i]) == MagickFalse)
  508. ThrowImportInvalidArgumentException(option,argv[i]);
  509. break;
  510. }
  511. if (LocaleCompare("channel",option+1) == 0)
  512. {
  513. ssize_t
  514. channel;
  515. if (*option == '+')
  516. break;
  517. i++;
  518. if (i == (ssize_t) (argc-1))
  519. ThrowImportException(OptionError,"MissingArgument",option);
  520. channel=ParseChannelOption(argv[i]);
  521. if (channel < 0)
  522. ThrowImportException(OptionError,"UnrecognizedChannelType",
  523. argv[i]);
  524. break;
  525. }
  526. if (LocaleCompare("colors",option+1) == 0)
  527. {
  528. quantize_info->number_colors=0;
  529. if (*option == '+')
  530. break;
  531. i++;
  532. if (i == (ssize_t) argc)
  533. ThrowImportException(OptionError,"MissingArgument",option);
  534. if (IsGeometry(argv[i]) == MagickFalse)
  535. ThrowImportInvalidArgumentException(option,argv[i]);
  536. quantize_info->number_colors=StringToUnsignedLong(argv[i]);
  537. break;
  538. }
  539. if (LocaleCompare("colorspace",option+1) == 0)
  540. {
  541. ssize_t
  542. colorspace;
  543. if (*option == '+')
  544. break;
  545. i++;
  546. if (i == (ssize_t) argc)
  547. ThrowImportException(OptionError,"MissingArgument",option);
  548. colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
  549. argv[i]);
  550. if (colorspace < 0)
  551. ThrowImportException(OptionError,"UnrecognizedColorspace",
  552. argv[i]);
  553. break;
  554. }
  555. if (LocaleCompare("comment",option+1) == 0)
  556. {
  557. if (*option == '+')
  558. break;
  559. i++;
  560. if (i == (ssize_t) argc)
  561. ThrowImportException(OptionError,"MissingArgument",option);
  562. status=SetImageOption(image_info,"comment",argv[i]);
  563. if (status == MagickFalse)
  564. ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
  565. break;
  566. }
  567. if (LocaleCompare("compress",option+1) == 0)
  568. {
  569. ssize_t
  570. compress;
  571. if (*option == '+')
  572. break;
  573. i++;
  574. if (i == (ssize_t) argc)
  575. ThrowImportException(OptionError,"MissingArgument",option);
  576. compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
  577. argv[i]);
  578. if (compress < 0)
  579. ThrowImportException(OptionError,"UnrecognizedImageCompression",
  580. argv[i]);
  581. break;
  582. }
  583. if (LocaleCompare("concurrent",option+1) == 0)
  584. break;
  585. if (LocaleCompare("crop",option+1) == 0)
  586. {
  587. if (*option == '+')
  588. break;
  589. i++;
  590. if (i == (ssize_t) argc)
  591. ThrowImportException(OptionError,"MissingArgument",option);
  592. if (IsGeometry(argv[i]) == MagickFalse)
  593. ThrowImportInvalidArgumentException(option,argv[i]);
  594. break;
  595. }
  596. ThrowImportException(OptionError,"UnrecognizedOption",option);
  597. }
  598. case 'd':
  599. {
  600. if (LocaleCompare("debug",option+1) == 0)
  601. {
  602. ssize_t
  603. event;
  604. if (*option == '+')
  605. break;
  606. i++;
  607. if (i == (ssize_t) argc)
  608. ThrowImportException(OptionError,"MissingArgument",option);
  609. event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
  610. if (event < 0)
  611. ThrowImportException(OptionError,"UnrecognizedEventType",argv[i]);
  612. (void) SetLogEventMask(argv[i]);
  613. break;
  614. }
  615. if (LocaleCompare("define",option+1) == 0)
  616. {
  617. i++;
  618. if (i == (ssize_t) argc)
  619. ThrowImportException(OptionError,"MissingArgument",option);
  620. if (*option == '+')
  621. {
  622. const char
  623. *define;
  624. define=GetImageOption(image_info,argv[i]);
  625. if (define == (char *) NULL)
  626. ThrowImportException(OptionError,"NoSuchOption",argv[i]);
  627. break;
  628. }
  629. break;
  630. }
  631. if (LocaleCompare("delay",option+1) == 0)
  632. {
  633. if (*option == '+')
  634. break;
  635. i++;
  636. if (i == (ssize_t) argc)
  637. ThrowImportException(OptionError,"MissingArgument",option);
  638. if (IsGeometry(argv[i]) == MagickFalse)
  639. ThrowImportInvalidArgumentException(option,argv[i]);
  640. status=SetImageOption(image_info,"delay",argv[i]);
  641. if (status == MagickFalse)
  642. ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
  643. break;
  644. }
  645. if (LocaleCompare("density",option+1) == 0)
  646. {
  647. if (*option == '+')
  648. break;
  649. i++;
  650. if (i == (ssize_t) argc)
  651. ThrowImportException(OptionError,"MissingArgument",option);
  652. if (IsGeometry(argv[i]) == MagickFalse)
  653. ThrowImportInvalidArgumentException(option,argv[i]);
  654. break;
  655. }
  656. if (LocaleCompare("depth",option+1) == 0)
  657. {
  658. if (*option == '+')
  659. break;
  660. i++;
  661. if (i == (ssize_t) argc)
  662. ThrowImportException(OptionError,"MissingArgument",option);
  663. if (IsGeometry(argv[i]) == MagickFalse)
  664. ThrowImportInvalidArgumentException(option,argv[i]);
  665. break;
  666. }
  667. if (LocaleCompare("descend",option+1) == 0)
  668. {
  669. ximage_info.descend=(*option == '-') ? MagickTrue : MagickFalse;
  670. break;
  671. }
  672. if (LocaleCompare("display",option+1) == 0)
  673. {
  674. if (*option == '+')
  675. break;
  676. i++;
  677. if (i == (ssize_t) argc)
  678. ThrowImportException(OptionError,"MissingArgument",option);
  679. break;
  680. }
  681. if (LocaleCompare("dispose",option+1) == 0)
  682. {
  683. ssize_t
  684. dispose;
  685. if (*option == '+')
  686. break;
  687. i++;
  688. if (i == (ssize_t) argc)
  689. ThrowImportException(OptionError,"MissingArgument",option);
  690. dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
  691. if (dispose < 0)
  692. ThrowImportException(OptionError,"UnrecognizedDisposeMethod",
  693. argv[i]);
  694. break;
  695. }
  696. if (LocaleCompare("dither",option+1) == 0)
  697. {
  698. ssize_t
  699. method;
  700. quantize_info->dither=MagickFalse;
  701. if (*option == '+')
  702. break;
  703. i++;
  704. if (i == (ssize_t) argc)
  705. ThrowImportException(OptionError,"MissingArgument",option);
  706. method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
  707. if (method < 0)
  708. ThrowImportException(OptionError,"UnrecognizedDitherMethod",
  709. argv[i]);
  710. quantize_info->dither=MagickTrue;
  711. quantize_info->dither_method=(DitherMethod) method;
  712. break;
  713. }
  714. if (LocaleCompare("duration",option+1) == 0)
  715. {
  716. if (*option == '+')
  717. break;
  718. i++;
  719. if (i == (ssize_t) (argc-1))
  720. ThrowImportException(OptionError,"MissingArgument",option);
  721. if (IsGeometry(argv[i]) == MagickFalse)
  722. ThrowImportInvalidArgumentException(option,argv[i]);
  723. break;
  724. }
  725. ThrowImportException(OptionError,"UnrecognizedOption",option);
  726. }
  727. case 'e':
  728. {
  729. if (LocaleCompare("encipher",option+1) == 0)
  730. {
  731. if (*option == '+')
  732. break;
  733. i++;
  734. if (i == (ssize_t) (argc-1))
  735. ThrowImportException(OptionError,"MissingArgument",option);
  736. break;
  737. }
  738. if (LocaleCompare("encoding",option+1) == 0)
  739. {
  740. if (*option == '+')
  741. break;
  742. i++;
  743. if (i == (ssize_t) argc)
  744. ThrowImportException(OptionError,"MissingArgument",option);
  745. break;
  746. }
  747. if (LocaleCompare("endian",option+1) == 0)
  748. {
  749. ssize_t
  750. endian;
  751. if (*option == '+')
  752. break;
  753. i++;
  754. if (i == (ssize_t) argc)
  755. ThrowImportException(OptionError,"MissingArgument",option);
  756. endian=ParseMagickOption(MagickEndianOptions,MagickFalse,
  757. argv[i]);
  758. if (endian < 0)
  759. ThrowImportException(OptionError,"UnrecognizedEndianType",
  760. argv[i]);
  761. break;
  762. }
  763. ThrowImportException(OptionError,"UnrecognizedOption",option);
  764. }
  765. case 'f':
  766. {
  767. if (LocaleCompare("filter",option+1) == 0)
  768. {
  769. ssize_t
  770. filter;
  771. if (*option == '+')
  772. break;
  773. i++;
  774. if (i == (ssize_t) (argc-1))
  775. ThrowImportException(OptionError,"MissingArgument",option);
  776. filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
  777. if (filter < 0)
  778. ThrowImportException(OptionError,"UnrecognizedImageFilter",
  779. argv[i]);
  780. break;
  781. }
  782. if (LocaleCompare("frame",option+1) == 0)
  783. {
  784. (void) CopyMagickString(argv[i]+1,"sans0",MaxTextExtent);
  785. ximage_info.frame=(*option == '-') ? MagickTrue : MagickFalse;
  786. break;
  787. }
  788. if (LocaleCompare("format",option+1) == 0)
  789. {
  790. if (*option == '+')
  791. break;
  792. i++;
  793. if (i == (ssize_t) (argc-1))
  794. ThrowImportException(OptionError,"MissingArgument",option);
  795. break;
  796. }
  797. ThrowImportException(OptionError,"UnrecognizedOption",option);
  798. }
  799. case 'g':
  800. {
  801. if (LocaleCompare("geometry",option+1) == 0)
  802. {
  803. if (*option == '+')
  804. break;
  805. i++;
  806. if (i == (ssize_t) argc)
  807. ThrowImportException(OptionError,"MissingArgument",option);
  808. if (IsGeometry(argv[i]) == MagickFalse)
  809. ThrowImportInvalidArgumentException(option,argv[i]);
  810. break;
  811. }
  812. if (LocaleCompare("gravity",option+1) == 0)
  813. {
  814. ssize_t
  815. gravity;
  816. if (*option == '+')
  817. break;
  818. i++;
  819. if (i == (ssize_t) argc)
  820. ThrowImportException(OptionError,"MissingArgument",option);
  821. gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
  822. if (gravity < 0)
  823. ThrowImportException(OptionError,"UnrecognizedGravityType",
  824. argv[i]);
  825. break;
  826. }
  827. ThrowImportException(OptionError,"UnrecognizedOption",option);
  828. }
  829. case 'h':
  830. {
  831. if (LocaleCompare("help",option+1) == 0)
  832. break;
  833. ThrowImportException(OptionError,"UnrecognizedOption",option);
  834. }
  835. case 'i':
  836. {
  837. if (LocaleCompare("identify",option+1) == 0)
  838. break;
  839. if (LocaleCompare("interlace",option+1) == 0)
  840. {
  841. ssize_t
  842. interlace;
  843. if (*option == '+')
  844. break;
  845. i++;
  846. if (i == (ssize_t) argc)
  847. ThrowImportException(OptionError,"MissingArgument",option);
  848. interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
  849. argv[i]);
  850. if (interlace < 0)
  851. ThrowImportException(OptionError,"UnrecognizedInterlaceType",
  852. argv[i]);
  853. break;
  854. }
  855. if (LocaleCompare("interpolate",option+1) == 0)
  856. {
  857. ssize_t
  858. interpolate;
  859. if (*option == '+')
  860. break;
  861. i++;
  862. if (i == (ssize_t) argc)
  863. ThrowImportException(OptionError,"MissingArgument",option);
  864. interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
  865. argv[i]);
  866. if (interpolate < 0)
  867. ThrowImportException(OptionError,"UnrecognizedInterpolateMethod",
  868. argv[i]);
  869. break;
  870. }
  871. ThrowImportException(OptionError,"UnrecognizedOption",option);
  872. }
  873. case 'l':
  874. {
  875. if (LocaleCompare("label",option+1) == 0)
  876. {
  877. if (*option == '+')
  878. break;
  879. i++;
  880. if (i == (ssize_t) argc)
  881. ThrowImportException(OptionError,"MissingArgument",option);
  882. status=SetImageOption(image_info,"label",argv[i]);
  883. if (status == MagickFalse)
  884. ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
  885. break;
  886. }
  887. if (LocaleCompare("limit",option+1) == 0)
  888. {
  889. char
  890. *p;
  891. double
  892. value;
  893. ssize_t
  894. resource;
  895. if (*option == '+')
  896. break;
  897. i++;
  898. if (i == (ssize_t) argc)
  899. ThrowImportException(OptionError,"MissingArgument",option);
  900. resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
  901. argv[i]);
  902. if (resource < 0)
  903. ThrowImportException(OptionError,"UnrecognizedResourceType",
  904. argv[i]);
  905. i++;
  906. if (i == (ssize_t) argc)
  907. ThrowImportException(OptionError,"MissingArgument",option);
  908. value=strtod(argv[i],&p);
  909. (void) value;
  910. if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
  911. ThrowImportInvalidArgumentException(option,argv[i]);
  912. break;
  913. }
  914. if (LocaleCompare("list",option+1) == 0)
  915. {
  916. ssize_t
  917. list;
  918. if (*option == '+')
  919. break;
  920. i++;
  921. if (i == (ssize_t) argc)
  922. ThrowImportException(OptionError,"MissingArgument",option);
  923. list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
  924. if (list < 0)
  925. ThrowImportException(OptionError,"UnrecognizedListType",argv[i]);
  926. status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
  927. argv+j,exception);
  928. DestroyImport();
  929. return(status != 0 ? MagickFalse : MagickTrue);
  930. }
  931. if (LocaleCompare("log",option+1) == 0)
  932. {
  933. if (*option == '+')
  934. break;
  935. i++;
  936. if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
  937. ThrowImportException(OptionError,"MissingArgument",option);
  938. break;
  939. }
  940. ThrowImportException(OptionError,"UnrecognizedOption",option);
  941. }
  942. case 'm':
  943. {
  944. if (LocaleCompare("monitor",option+1) == 0)
  945. break;
  946. if (LocaleCompare("monochrome",option+1) == 0)
  947. {
  948. if (*option == '+')
  949. break;
  950. quantize_info->number_colors=2;
  951. quantize_info->colorspace=GRAYColorspace;
  952. break;
  953. }
  954. ThrowImportException(OptionError,"UnrecognizedOption",option);
  955. }
  956. case 'n':
  957. {
  958. if (LocaleCompare("negate",option+1) == 0)
  959. break;
  960. ThrowImportException(OptionError,"UnrecognizedOption",option);
  961. }
  962. case 'p':
  963. {
  964. if (LocaleCompare("page",option+1) == 0)
  965. {
  966. if (*option == '+')
  967. break;
  968. i++;
  969. if (i == (ssize_t) argc)
  970. ThrowImportException(OptionError,"MissingArgument",option);
  971. status=SetImageOption(image_info,"page",argv[i]);
  972. if (status == MagickFalse)
  973. ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
  974. break;
  975. }
  976. if (LocaleCompare("pause",option+1) == 0)
  977. {
  978. resource_info.pause=0;
  979. if (*option == '+')
  980. break;
  981. i++;
  982. if (i == (ssize_t) argc)
  983. ThrowImportException(OptionError,"MissingArgument",option);
  984. if (IsGeometry(argv[i]) == MagickFalse)
  985. ThrowImportInvalidArgumentException(option,argv[i]);
  986. resource_info.pause=(unsigned int) StringToUnsignedLong(argv[i]);
  987. break;
  988. }
  989. if (LocaleCompare("ping",option+1) == 0)
  990. break; /* deprecated option */
  991. if (LocaleCompare("pointsize",option+1) == 0)
  992. {
  993. if (*option == '+')
  994. break;
  995. i++;
  996. if (i == (ssize_t) argc)
  997. ThrowImportException(OptionError,"MissingArgument",option);
  998. if (IsGeometry(argv[i]) == MagickFalse)
  999. ThrowImportInvalidArgumentException(option,argv[i]);
  1000. break;
  1001. }
  1002. ThrowImportException(OptionError,"UnrecognizedOption",option);
  1003. }
  1004. case 'q':
  1005. {
  1006. if (LocaleCompare("quality",option+1) == 0)
  1007. {
  1008. if (*option == '+')
  1009. break;
  1010. i++;
  1011. if (i == (ssize_t) argc)
  1012. ThrowImportException(OptionError,"MissingArgument",option);
  1013. if (IsGeometry(argv[i]) == MagickFalse)
  1014. ThrowImportInvalidArgumentException(option,argv[i]);
  1015. break;
  1016. }
  1017. if (LocaleCompare("quantize",option+1) == 0)
  1018. {
  1019. ssize_t
  1020. colorspace;
  1021. if (*option == '+')
  1022. break;
  1023. i++;
  1024. if (i == (ssize_t) (argc-1))
  1025. ThrowImportException(OptionError,"MissingArgument",option);
  1026. colorspace=ParseMagickOption(MagickColorspaceOptions,
  1027. MagickFalse,argv[i]);
  1028. if (colorspace < 0)
  1029. ThrowImportException(OptionError,"UnrecognizedColorspace",
  1030. argv[i]);
  1031. break;
  1032. }
  1033. if (LocaleCompare("quiet",option+1) == 0)
  1034. break;
  1035. ThrowImportException(OptionError,"UnrecognizedOption",option);
  1036. }
  1037. case 'r':
  1038. {
  1039. if (LocaleCompare("regard-warnings",option+1) == 0)
  1040. break;
  1041. if (LocaleCompare("repage",option+1) == 0)
  1042. {
  1043. if (*option == '+')
  1044. break;
  1045. i++;
  1046. if (i == (ssize_t) (argc-1))
  1047. ThrowImportException(OptionError,"MissingArgument",option);
  1048. if (IsGeometry(argv[i]) == MagickFalse)
  1049. ThrowImportInvalidArgumentException(option,argv[i]);
  1050. break;
  1051. }
  1052. if (LocaleCompare("resize",option+1) == 0)
  1053. {
  1054. if (*option == '+')
  1055. break;
  1056. i++;
  1057. if (i == (ssize_t) argc)
  1058. ThrowImportException(OptionError,"MissingArgument",option);
  1059. if (IsGeometry(argv[i]) == MagickFalse)
  1060. ThrowImportInvalidArgumentException(option,argv[i]);
  1061. break;
  1062. }
  1063. if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
  1064. {
  1065. respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
  1066. break;
  1067. }
  1068. if (LocaleCompare("rotate",option+1) == 0)
  1069. {
  1070. i++;
  1071. if (i == (ssize_t) argc)
  1072. ThrowImportException(OptionError,"MissingArgument",option);
  1073. if (IsGeometry(argv[i]) == MagickFalse)
  1074. ThrowImportInvalidArgumentException(option,argv[i]);
  1075. break;
  1076. }
  1077. ThrowImportException(OptionError,"UnrecognizedOption",option);
  1078. }
  1079. case 's':
  1080. {
  1081. if (LocaleCompare("sampling-factor",option+1) == 0)
  1082. {
  1083. if (*option == '+')
  1084. break;
  1085. i++;
  1086. if (i == (ssize_t) argc)
  1087. ThrowImportException(OptionError,"MissingArgument",option);
  1088. if (IsGeometry(argv[i]) == MagickFalse)
  1089. ThrowImportInvalidArgumentException(option,argv[i]);
  1090. break;
  1091. }
  1092. if (LocaleCompare("scene",option+1) == 0)
  1093. {
  1094. if (*option == '+')
  1095. break;
  1096. i++;
  1097. if (i == (ssize_t) argc)
  1098. ThrowImportException(OptionError,"MissingArgument",option);
  1099. if (IsGeometry(argv[i]) == MagickFalse)
  1100. ThrowImportInvalidArgumentException(option,argv[i]);
  1101. break;
  1102. }
  1103. if (LocaleCompare("set",option+1) == 0)
  1104. {
  1105. i++;
  1106. if (i == (ssize_t) argc)
  1107. ThrowImportException(OptionError,"MissingArgument",option);
  1108. if (*option == '+')
  1109. break;
  1110. i++;
  1111. if (i == (ssize_t) argc)
  1112. ThrowImportException(OptionError,"MissingArgument",option);
  1113. break;
  1114. }
  1115. if (LocaleCompare("screen",option+1) == 0)
  1116. {
  1117. ximage_info.screen=(*option == '-') ? MagickTrue : MagickFalse;
  1118. break;
  1119. }
  1120. if (LocaleCompare("seed",option+1) == 0)
  1121. {
  1122. if (*option == '+')
  1123. break;
  1124. i++;
  1125. if (i == (ssize_t) (argc-1))
  1126. ThrowImportException(OptionError,"MissingArgument",option);
  1127. if (IsGeometry(argv[i]) == MagickFalse)
  1128. ThrowImportInvalidArgumentException(option,argv[i]);
  1129. break;
  1130. }
  1131. if (LocaleCompare("silent",option+1) == 0)
  1132. {
  1133. ximage_info.silent=(*option == '-') ? MagickTrue : MagickFalse;
  1134. break;
  1135. }
  1136. if (LocaleCompare("snaps",option+1) == 0)
  1137. {
  1138. (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
  1139. i++;
  1140. if (i == (ssize_t) argc)
  1141. ThrowImportException(OptionError,"MissingArgument",option);
  1142. if (IsGeometry(argv[i]) == MagickFalse)
  1143. ThrowImportInvalidArgumentException(option,argv[i]);
  1144. snapshots=(ssize_t) StringToLong(argv[i]);
  1145. break;
  1146. }
  1147. if (LocaleCompare("strip",option+1) == 0)
  1148. break;
  1149. if (LocaleCompare("support",option+1) == 0)
  1150. {
  1151. i++; /* deprecated */
  1152. break;
  1153. }
  1154. if (LocaleCompare("synchronize",option+1) == 0)
  1155. break;
  1156. ThrowImportException(OptionError,"UnrecognizedOption",option);
  1157. }
  1158. case 't':
  1159. {
  1160. if (LocaleCompare("taint",option+1) == 0)
  1161. break;
  1162. if (LocaleCompare("thumnail",option+1) == 0)
  1163. {
  1164. if (*option == '+')
  1165. break;
  1166. i++;
  1167. if (i == (ssize_t) argc)
  1168. ThrowImportException(OptionError,"MissingArgument",option);
  1169. if (IsGeometry(argv[i]) == MagickFalse)
  1170. ThrowImportInvalidArgumentException(option,argv[i]);
  1171. break;
  1172. }
  1173. if (LocaleCompare("transparent",option+1) == 0)
  1174. {
  1175. i++;
  1176. if (i == (ssize_t) argc)
  1177. ThrowImportException(OptionError,"MissingArgument",option);
  1178. break;
  1179. }
  1180. if (LocaleCompare("transparent-color",option+1) == 0)
  1181. {
  1182. if (*option == '+')
  1183. break;
  1184. i++;
  1185. if (i == (ssize_t) (argc-1))
  1186. ThrowImportException(OptionError,"MissingArgument",option);
  1187. break;
  1188. }
  1189. if (LocaleCompare("treedepth",option+1) == 0)
  1190. {
  1191. quantize_info->tree_depth=0;
  1192. if (*option == '+')
  1193. break;
  1194. i++;
  1195. if (i == (ssize_t) argc)
  1196. ThrowImportException(OptionError,"MissingArgument",option);
  1197. if (IsGeometry(argv[i]) == MagickFalse)
  1198. ThrowImportInvalidArgumentException(option,argv[i]);
  1199. quantize_info->tree_depth=StringToUnsignedLong(argv[i]);
  1200. break;
  1201. }
  1202. if (LocaleCompare("trim",option+1) == 0)
  1203. break;
  1204. if (LocaleCompare("type",option+1) == 0)
  1205. {
  1206. ssize_t
  1207. type;
  1208. if (*option == '+')
  1209. break;
  1210. i++;
  1211. if (i == (ssize_t) argc)
  1212. ThrowImportException(OptionError,"MissingArgument",option);
  1213. type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
  1214. if (type < 0)
  1215. ThrowImportException(OptionError,"UnrecognizedImageType",argv[i]);
  1216. break;
  1217. }
  1218. ThrowImportException(OptionError,"UnrecognizedOption",option);
  1219. }
  1220. case 'w':
  1221. {
  1222. i++;
  1223. if (i == (ssize_t) argc)
  1224. ThrowImportException(OptionError,"MissingArgument",option);
  1225. (void) CloneString(&target_window,argv[i]);
  1226. break;
  1227. }
  1228. case 'v':
  1229. {
  1230. if (LocaleCompare("verbose",option+1) == 0)
  1231. break;
  1232. if ((LocaleCompare("version",option+1) == 0) ||
  1233. (LocaleCompare("-version",option+1) == 0))
  1234. {
  1235. (void) fprintf(stdout,"Version: %s\n",
  1236. GetMagickVersion((size_t *) NULL));
  1237. (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
  1238. (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
  1239. break;
  1240. }
  1241. ThrowImportException(OptionError,"UnrecognizedOption",option);
  1242. }
  1243. case '?':
  1244. break;
  1245. default:
  1246. ThrowImportException(OptionError,"UnrecognizedOption",option);
  1247. }
  1248. fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
  1249. MagickFalse : MagickTrue;
  1250. if (fire != MagickFalse)
  1251. FireImageStack(MagickFalse,MagickTrue,MagickTrue);
  1252. }
  1253. if (k != 0)
  1254. ThrowImportException(OptionError,"UnbalancedParenthesis",argv[i]);
  1255. if (i-- != (ssize_t) argc)
  1256. ThrowImportException(OptionError,"MissingAnImageFilename",argv[i]);
  1257. if (image == (Image *) NULL)
  1258. ThrowImportException(OptionError,"MissingAnImageFilename",argv[argc-1]);
  1259. FinalizeImageSettings(image_info,image,MagickTrue);
  1260. status&=WriteImages(image_info,image,filename,exception);
  1261. DestroyImport();
  1262. return(status != 0 ? MagickTrue : MagickFalse);
  1263. #else
  1264. (void) argc;
  1265. (void) argv;
  1266. (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
  1267. "DelegateLibrarySupportNotBuiltIn","`%s' (X11)",image_info->filename);
  1268. return(ImportUsage());
  1269. #endif
  1270. }