PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/MagickWand/convert.c

https://gitlab.com/ImageMagick/ImageMagick
C | 3293 lines | 3135 code | 67 blank | 91 comment | 1668 complexity | 2267b8dde6ff052fd3545ba4758fbf97 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % %
  4. % %
  5. % %
  6. % CCCC OOO N N V V EEEEE RRRR TTTTT %
  7. % C O O NN N V V E R R T %
  8. % C O O N N N V V EEE RRRR T %
  9. % C O O N NN V V E R R T %
  10. % CCCC OOO N N V EEEEE R R T %
  11. % %
  12. % %
  13. % Convert an image from one format to another. %
  14. % %
  15. % Software Design %
  16. % Cristy %
  17. % April 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 convert program to convert between image formats as well as resize
  37. % an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample,
  38. % and much more.
  39. %
  40. */
  41. /*
  42. Include declarations.
  43. */
  44. #include "MagickWand/studio.h"
  45. #include "MagickWand/MagickWand.h"
  46. #include "MagickWand/mogrify-private.h"
  47. #include "MagickCore/string-private.h"
  48. #include "MagickCore/utility-private.h"
  49. /*
  50. Define declarations.
  51. */
  52. #define ThrowFileException(exception,severity,tag,context) \
  53. { \
  54. char \
  55. *message; \
  56. \
  57. message=GetExceptionMessage(errno); \
  58. (void) ThrowMagickException(exception,GetMagickModule(),severity, \
  59. tag == (const char *) NULL ? "unknown" : tag,"'%s': %s",context,message); \
  60. message=DestroyString(message); \
  61. }
  62. /*
  63. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  64. % %
  65. % %
  66. % %
  67. + C o n v e r t I m a g e C o m m a n d %
  68. % %
  69. % %
  70. % %
  71. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  72. %
  73. % ConvertImageCommand() reads one or more images, applies one or more image
  74. % processing operations, and writes out the image in the same or differing
  75. % format.
  76. %
  77. % The format of the ConvertImageCommand method is:
  78. %
  79. % MagickBooleanType ConvertImageCommand(ImageInfo *image_info,int argc,
  80. % char **argv,char **metadata,ExceptionInfo *exception)
  81. %
  82. % A description of each parameter follows:
  83. %
  84. % o image_info: the image info.
  85. %
  86. % o argc: the number of elements in the argument vector.
  87. %
  88. % o argv: A text array containing the command line arguments.
  89. %
  90. % o metadata: any metadata is returned here.
  91. %
  92. % o exception: return any errors or warnings in this structure.
  93. %
  94. */
  95. static MagickBooleanType ConcatenateImages(int argc,char **argv,
  96. ExceptionInfo *exception)
  97. {
  98. FILE
  99. *input,
  100. *output;
  101. int
  102. c;
  103. MagickBooleanType
  104. status;
  105. register ssize_t
  106. i;
  107. /*
  108. Open output file.
  109. */
  110. output=fopen_utf8(argv[argc-1],"wb");
  111. if (output == (FILE *) NULL)
  112. {
  113. ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
  114. argv[argc-1]);
  115. return(MagickFalse);
  116. }
  117. status=MagickTrue;
  118. for (i=2; i < (ssize_t) (argc-1); i++)
  119. {
  120. input=fopen_utf8(argv[i],"rb");
  121. if (input == (FILE *) NULL)
  122. {
  123. ThrowFileException(exception,FileOpenError,"UnableToOpenFile",argv[i]);
  124. continue;
  125. }
  126. for (c=fgetc(input); c != EOF; c=fgetc(input))
  127. if (fputc((char) c,output) != c)
  128. status=MagickFalse;
  129. (void) fclose(input);
  130. (void) remove_utf8(argv[i]);
  131. }
  132. (void) fclose(output);
  133. return(status);
  134. }
  135. static MagickBooleanType ConvertUsage(void)
  136. {
  137. static const char
  138. channel_operators[] =
  139. " -channel-fx expression\n"
  140. " exchange, extract, or transfer one or more image channels\n"
  141. " -separate separate an image channel into a grayscale image",
  142. miscellaneous[] =
  143. " -debug events display copious debugging information\n"
  144. " -distribute-cache port\n"
  145. " distributed pixel cache spanning one or more servers\n"
  146. " -help print program options\n"
  147. " -list type print a list of supported option arguments\n"
  148. " -log format format of debugging information\n"
  149. " -version print version information",
  150. operators[] =
  151. " -adaptive-blur geometry\n"
  152. " adaptively blur pixels; decrease effect near edges\n"
  153. " -adaptive-resize geometry\n"
  154. " adaptively resize image using 'mesh' interpolation\n"
  155. " -adaptive-sharpen geometry\n"
  156. " adaptively sharpen pixels; increase effect near edges\n"
  157. " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
  158. " transparent, extract, background, or shape\n"
  159. " -annotate geometry text\n"
  160. " annotate the image with text\n"
  161. " -auto-gamma automagically adjust gamma level of image\n"
  162. " -auto-level automagically adjust color levels of image\n"
  163. " -auto-orient automagically orient (rotate) image\n"
  164. " -auto-threshold method\n"
  165. " automatically perform image thresholding\n"
  166. " -bench iterations measure performance\n"
  167. " -black-threshold value\n"
  168. " force all pixels below the threshold into black\n"
  169. " -blue-shift factor simulate a scene at nighttime in the moonlight\n"
  170. " -blur geometry reduce image noise and reduce detail levels\n"
  171. " -border geometry surround image with a border of color\n"
  172. " -bordercolor color border color\n"
  173. " -brightness-contrast geometry\n"
  174. " improve brightness / contrast of the image\n"
  175. " -canny geometry detect edges in the image\n"
  176. " -cdl filename color correct with a color decision list\n"
  177. " -channel mask set the image channel mask\n"
  178. " -charcoal radius simulate a charcoal drawing\n"
  179. " -chop geometry remove pixels from the image interior\n"
  180. " -clahe geometry contrast limited adaptive histogram equalization\n"
  181. " -clamp keep pixel values in range (0-QuantumRange)\n"
  182. " -colorize value colorize the image with the fill color\n"
  183. " -color-matrix matrix apply color correction to the image\n"
  184. " -connected-components connectivity\n"
  185. " connected-components uniquely labeled\n"
  186. " -contrast enhance or reduce the image contrast\n"
  187. " -contrast-stretch geometry\n"
  188. " improve contrast by 'stretching' the intensity range\n"
  189. " -convolve coefficients\n"
  190. " apply a convolution kernel to the image\n"
  191. " -cycle amount cycle the image colormap\n"
  192. " -decipher filename convert cipher pixels to plain pixels\n"
  193. " -deskew threshold straighten an image\n"
  194. " -despeckle reduce the speckles within an image\n"
  195. " -distort method args\n"
  196. " distort images according to given method ad args\n"
  197. " -draw string annotate the image with a graphic primitive\n"
  198. " -edge radius apply a filter to detect edges in the image\n"
  199. " -encipher filename convert plain pixels to cipher pixels\n"
  200. " -emboss radius emboss an image\n"
  201. " -enhance apply a digital filter to enhance a noisy image\n"
  202. " -equalize perform histogram equalization to an image\n"
  203. " -evaluate operator value\n"
  204. " evaluate an arithmetic, relational, or logical expression\n"
  205. " -extent geometry set the image size\n"
  206. " -extract geometry extract area from image\n"
  207. " -fft implements the discrete Fourier transform (DFT)\n"
  208. " -flip flip image vertically\n"
  209. " -floodfill geometry color\n"
  210. " floodfill the image with color\n"
  211. " -flop flop image horizontally\n"
  212. " -frame geometry surround image with an ornamental border\n"
  213. " -function name parameters\n"
  214. " apply function over image values\n"
  215. " -gamma value level of gamma correction\n"
  216. " -gaussian-blur geometry\n"
  217. " reduce image noise and reduce detail levels\n"
  218. " -geometry geometry preferred size or location of the image\n"
  219. " -grayscale method convert image to grayscale\n"
  220. " -hough-lines geometry\n"
  221. " identify lines in the image\n"
  222. " -identify identify the format and characteristics of the image\n"
  223. " -ift implements the inverse discrete Fourier transform (DFT)\n"
  224. " -implode amount implode image pixels about the center\n"
  225. " -kuwahara geometry edge preserving noise reduction filter\n"
  226. " -lat geometry local adaptive thresholding\n"
  227. " -level value adjust the level of image contrast\n"
  228. " -level-colors color,color\n"
  229. " level image with the given colors\n"
  230. " -linear-stretch geometry\n"
  231. " improve contrast by 'stretching with saturation'\n"
  232. " -liquid-rescale geometry\n"
  233. " rescale image with seam-carving\n"
  234. " -local-contrast geometry\n"
  235. " enhance local contrast\n"
  236. " -mean-shift geometry delineate arbitrarily shaped clusters in the image\n"
  237. " -median geometry apply a median filter to the image\n"
  238. " -mode geometry make each pixel the 'predominant color' of the\n"
  239. " neighborhood\n"
  240. " -modulate value vary the brightness, saturation, and hue\n"
  241. " -monochrome transform image to black and white\n"
  242. " -morphology method kernel\n"
  243. " apply a morphology method to the image\n"
  244. " -motion-blur geometry\n"
  245. " simulate motion blur\n"
  246. " -negate replace every pixel with its complementary color \n"
  247. " -noise geometry add or reduce noise in an image\n"
  248. " -normalize transform image to span the full range of colors\n"
  249. " -opaque color change this color to the fill color\n"
  250. " -ordered-dither NxN\n"
  251. " add a noise pattern to the image with specific\n"
  252. " amplitudes\n"
  253. " -paint radius simulate an oil painting\n"
  254. " -perceptible epsilon\n"
  255. " pixel value less than |epsilon| become epsilon or\n"
  256. " -epsilon\n"
  257. " -polaroid angle simulate a Polaroid picture\n"
  258. " -posterize levels reduce the image to a limited number of color levels\n"
  259. " -profile filename add, delete, or apply an image profile\n"
  260. " -quantize colorspace reduce colors in this colorspace\n"
  261. " -raise value lighten/darken image edges to create a 3-D effect\n"
  262. " -random-threshold low,high\n"
  263. " random threshold the image\n"
  264. " -range-threshold values\n"
  265. " perform either hard or soft thresholding within some range of values in an image\n"
  266. " -region geometry apply options to a portion of the image\n"
  267. " -render render vector graphics\n"
  268. " -resample geometry change the resolution of an image\n"
  269. " -resize geometry resize the image\n"
  270. " -roll geometry roll an image vertically or horizontally\n"
  271. " -rotate degrees apply Paeth rotation to the image\n"
  272. " -rotational-blur angle\n"
  273. " rotational blur the image\n"
  274. " -sample geometry scale image with pixel sampling\n"
  275. " -scale geometry scale the image\n"
  276. " -segment values segment an image\n"
  277. " -selective-blur geometry\n"
  278. " selectively blur pixels within a contrast threshold\n"
  279. " -sepia-tone threshold\n"
  280. " simulate a sepia-toned photo\n"
  281. " -set property value set an image property\n"
  282. " -shade degrees shade the image using a distant light source\n"
  283. " -shadow geometry simulate an image shadow\n"
  284. " -sharpen geometry sharpen the image\n"
  285. " -shave geometry shave pixels from the image edges\n"
  286. " -shear geometry slide one edge of the image along the X or Y axis\n"
  287. " -sigmoidal-contrast geometry\n"
  288. " increase the contrast without saturating highlights or\n"
  289. " shadows\n"
  290. " -sketch geometry simulate a pencil sketch\n"
  291. " -solarize threshold negate all pixels above the threshold level\n"
  292. " -sparse-color method args\n"
  293. " fill in a image based on a few color points\n"
  294. " -splice geometry splice the background color into the image\n"
  295. " -spread radius displace image pixels by a random amount\n"
  296. " -statistic type geometry\n"
  297. " replace each pixel with corresponding statistic from the\n"
  298. " neighborhood\n"
  299. " -strip strip image of all profiles and comments\n"
  300. " -swirl degrees swirl image pixels about the center\n"
  301. " -threshold value threshold the image\n"
  302. " -thumbnail geometry create a thumbnail of the image\n"
  303. " -tile filename tile image when filling a graphic primitive\n"
  304. " -tint value tint the image with the fill color\n"
  305. " -transform affine transform image\n"
  306. " -transparent color make this color transparent within the image\n"
  307. " -transpose flip image vertically and rotate 90 degrees\n"
  308. " -transverse flop image horizontally and rotate 270 degrees\n"
  309. " -trim trim image edges\n"
  310. " -type type image type\n"
  311. " -unique-colors discard all but one of any pixel color\n"
  312. " -unsharp geometry sharpen the image\n"
  313. " -vignette geometry soften the edges of the image in vignette style\n"
  314. " -wave geometry alter an image along a sine wave\n"
  315. " -wavelet-denoise threshold\n"
  316. " removes noise from the image using a wavelet transform\n"
  317. " -white-threshold value\n"
  318. " force all pixels above the threshold into white",
  319. sequence_operators[] =
  320. " -append append an image sequence\n"
  321. " -clut apply a color lookup table to the image\n"
  322. " -coalesce merge a sequence of images\n"
  323. " -combine combine a sequence of images\n"
  324. " -compare mathematically and visually annotate the difference between an image and its reconstruction\n"
  325. " -complex operator perform complex mathematics on an image sequence\n"
  326. " -composite composite image\n"
  327. " -copy geometry offset\n"
  328. " copy pixels from one area of an image to another\n"
  329. " -crop geometry cut out a rectangular region of the image\n"
  330. " -deconstruct break down an image sequence into constituent parts\n"
  331. " -evaluate-sequence operator\n"
  332. " evaluate an arithmetic, relational, or logical expression\n"
  333. " -flatten flatten a sequence of images\n"
  334. " -fx expression apply mathematical expression to an image channel(s)\n"
  335. " -hald-clut apply a Hald color lookup table to the image\n"
  336. " -layers method optimize, merge, or compare image layers\n"
  337. " -morph value morph an image sequence\n"
  338. " -mosaic create a mosaic from an image sequence\n"
  339. " -poly terms build a polynomial from the image sequence and the corresponding\n"
  340. " terms (coefficients and degree pairs).\n"
  341. " -print string interpret string and print to console\n"
  342. " -process arguments process the image with a custom image filter\n"
  343. " -smush geometry smush an image sequence together\n"
  344. " -write filename write images to this file",
  345. settings[] =
  346. " -adjoin join images into a single multi-image file\n"
  347. " -affine matrix affine transform matrix\n"
  348. " -alpha option activate, deactivate, reset, or set the alpha channel\n"
  349. " -antialias remove pixel-aliasing\n"
  350. " -authenticate password\n"
  351. " decipher image with this password\n"
  352. " -attenuate value lessen (or intensify) when adding noise to an image\n"
  353. " -background color background color\n"
  354. " -bias value add bias when convolving an image\n"
  355. " -black-point-compensation\n"
  356. " use black point compensation\n"
  357. " -blue-primary point chromaticity blue primary point\n"
  358. " -bordercolor color border color\n"
  359. " -caption string assign a caption to an image\n"
  360. " -clip clip along the first path from the 8BIM profile\n"
  361. " -clip-mask filename associate a clip mask with the image\n"
  362. " -clip-path id clip along a named path from the 8BIM profile\n"
  363. " -colors value preferred number of colors in the image\n"
  364. " -colorspace type alternate image colorspace\n"
  365. " -comment string annotate image with comment\n"
  366. " -compose operator set image composite operator\n"
  367. " -compress type type of pixel compression when writing the image\n"
  368. " -define format:option\n"
  369. " define one or more image format options\n"
  370. " -delay value display the next image after pausing\n"
  371. " -density geometry horizontal and vertical density of the image\n"
  372. " -depth value image depth\n"
  373. " -direction type render text right-to-left or left-to-right\n"
  374. " -display server get image or font from this X server\n"
  375. " -dispose method layer disposal method\n"
  376. " -dither method apply error diffusion to image\n"
  377. " -encoding type text encoding type\n"
  378. " -endian type endianness (MSB or LSB) of the image\n"
  379. " -family name render text with this font family\n"
  380. " -features distance analyze image features (e.g. contrast, correlation)\n"
  381. " -fill color color to use when filling a graphic primitive\n"
  382. " -filter type use this filter when resizing an image\n"
  383. " -font name render text with this font\n"
  384. " -format \"string\" output formatted image characteristics\n"
  385. " -fuzz distance colors within this distance are considered equal\n"
  386. " -gravity type horizontal and vertical text placement\n"
  387. " -green-primary point chromaticity green primary point\n"
  388. " -intensity method method to generate an intensity value from a pixel\n"
  389. " -intent type type of rendering intent when managing the image color\n"
  390. " -interlace type type of image interlacing scheme\n"
  391. " -interline-spacing value\n"
  392. " set the space between two text lines\n"
  393. " -interpolate method pixel color interpolation method\n"
  394. " -interword-spacing value\n"
  395. " set the space between two words\n"
  396. " -kerning value set the space between two letters\n"
  397. " -label string assign a label to an image\n"
  398. " -limit type value pixel cache resource limit\n"
  399. " -loop iterations add Netscape loop extension to your GIF animation\n"
  400. " -matte store matte channel if the image has one\n"
  401. " -mattecolor color frame color\n"
  402. " -moments report image moments\n"
  403. " -monitor monitor progress\n"
  404. " -orient type image orientation\n"
  405. " -page geometry size and location of an image canvas (setting)\n"
  406. " -ping efficiently determine image attributes\n"
  407. " -pointsize value font point size\n"
  408. " -precision value maximum number of significant digits to print\n"
  409. " -preview type image preview type\n"
  410. " -quality value JPEG/MIFF/PNG compression level\n"
  411. " -quiet suppress all warning messages\n"
  412. " -read-mask filename associate a read mask with the image\n"
  413. " -red-primary point chromaticity red primary point\n"
  414. " -regard-warnings pay attention to warning messages\n"
  415. " -remap filename transform image colors to match this set of colors\n"
  416. " -repage geometry size and location of an image canvas\n"
  417. " -respect-parentheses settings remain in effect until parenthesis boundary\n"
  418. " -sampling-factor geometry\n"
  419. " horizontal and vertical sampling factor\n"
  420. " -scene value image scene number\n"
  421. " -seed value seed a new sequence of pseudo-random numbers\n"
  422. " -size geometry width and height of image\n"
  423. " -stretch type render text with this font stretch\n"
  424. " -stroke color graphic primitive stroke color\n"
  425. " -strokewidth value graphic primitive stroke width\n"
  426. " -style type render text with this font style\n"
  427. " -support factor resize support: > 1.0 is blurry, < 1.0 is sharp\n"
  428. " -synchronize synchronize image to storage device\n"
  429. " -taint declare the image as modified\n"
  430. " -texture filename name of texture to tile onto the image background\n"
  431. " -tile-offset geometry\n"
  432. " tile offset\n"
  433. " -treedepth value color tree depth\n"
  434. " -transparent-color color\n"
  435. " transparent color\n"
  436. " -undercolor color annotation bounding box color\n"
  437. " -units type the units of image resolution\n"
  438. " -verbose print detailed information about the image\n"
  439. " -view FlashPix viewing transforms\n"
  440. " -virtual-pixel method\n"
  441. " virtual pixel access method\n"
  442. " -weight type render text with this font weight\n"
  443. " -white-point point chromaticity white point\n"
  444. " -write-mask filename associate a write mask with the image",
  445. stack_operators[] =
  446. " -clone indexes clone an image\n"
  447. " -delete indexes delete the image from the image sequence\n"
  448. " -duplicate count,indexes\n"
  449. " duplicate an image one or more times\n"
  450. " -insert index insert last image into the image sequence\n"
  451. " -reverse reverse image sequence\n"
  452. " -swap indexes swap two images in the image sequence";
  453. ListMagickVersion(stdout);
  454. (void) printf("Usage: %s [options ...] file [ [options ...] "
  455. "file ...] [options ...] file\n",GetClientName());
  456. (void) printf("\nImage Settings:\n");
  457. (void) puts(settings);
  458. (void) printf("\nImage Operators:\n");
  459. (void) puts(operators);
  460. (void) printf("\nImage Channel Operators:\n");
  461. (void) puts(channel_operators);
  462. (void) printf("\nImage Sequence Operators:\n");
  463. (void) puts(sequence_operators);
  464. (void) printf("\nImage Stack Operators:\n");
  465. (void) puts(stack_operators);
  466. (void) printf("\nMiscellaneous Options:\n");
  467. (void) puts(miscellaneous);
  468. (void) printf(
  469. "\nBy default, the image format of 'file' is determined by its magic\n");
  470. (void) printf(
  471. "number. To specify a particular image format, precede the filename\n");
  472. (void) printf(
  473. "with an image format name and a colon (i.e. ps:image) or specify the\n");
  474. (void) printf(
  475. "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
  476. (void) printf("'-' for standard input or output.\n");
  477. return(MagickFalse);
  478. }
  479. WandExport MagickBooleanType ConvertImageCommand(ImageInfo *image_info,
  480. int argc,char **argv,char **metadata,ExceptionInfo *exception)
  481. {
  482. #define NotInitialized (unsigned int) (~0)
  483. #define DestroyConvert() \
  484. { \
  485. DestroyImageStack(); \
  486. for (i=0; i < (ssize_t) argc; i++) \
  487. argv[i]=DestroyString(argv[i]); \
  488. argv=(char **) RelinquishMagickMemory(argv); \
  489. }
  490. #define ThrowConvertException(asperity,tag,option) \
  491. { \
  492. (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
  493. option); \
  494. DestroyConvert(); \
  495. return(MagickFalse); \
  496. }
  497. #define ThrowConvertInvalidArgumentException(option,argument) \
  498. { \
  499. (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
  500. "InvalidArgument","'%s': %s",option,argument); \
  501. DestroyConvert(); \
  502. return(MagickFalse); \
  503. }
  504. char
  505. *filename,
  506. *option;
  507. const char
  508. *format;
  509. Image
  510. *image;
  511. ImageStack
  512. image_stack[MaxImageStackDepth+1];
  513. MagickBooleanType
  514. fire,
  515. pend,
  516. respect_parenthesis;
  517. MagickStatusType
  518. status;
  519. register ssize_t
  520. i;
  521. ssize_t
  522. j,
  523. k;
  524. /*
  525. Set defaults.
  526. */
  527. assert(image_info != (ImageInfo *) NULL);
  528. assert(image_info->signature == MagickCoreSignature);
  529. if (image_info->debug != MagickFalse)
  530. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  531. assert(exception != (ExceptionInfo *) NULL);
  532. if (argc == 2)
  533. {
  534. option=argv[1];
  535. if ((LocaleCompare("version",option+1) == 0) ||
  536. (LocaleCompare("-version",option+1) == 0))
  537. {
  538. ListMagickVersion(stdout);
  539. return(MagickTrue);
  540. }
  541. }
  542. if (argc < 3)
  543. return(ConvertUsage());
  544. filename=(char *) NULL;
  545. format="%w,%h,%m";
  546. j=1;
  547. k=0;
  548. NewImageStack();
  549. option=(char *) NULL;
  550. pend=MagickFalse;
  551. respect_parenthesis=MagickFalse;
  552. status=MagickTrue;
  553. /*
  554. Parse command-line arguments.
  555. */
  556. ReadCommandlLine(argc,&argv);
  557. status=ExpandFilenames(&argc,&argv);
  558. if (status == MagickFalse)
  559. ThrowConvertException(ResourceLimitError,"MemoryAllocationFailed",
  560. GetExceptionMessage(errno));
  561. if ((argc > 2) && (LocaleCompare("-concatenate",argv[1]) == 0))
  562. return(ConcatenateImages(argc,argv,exception));
  563. for (i=1; i < (ssize_t) (argc-1); i++)
  564. {
  565. option=argv[i];
  566. if (LocaleCompare(option,"(") == 0)
  567. {
  568. FireImageStack(MagickTrue,MagickTrue,pend);
  569. if (k == MaxImageStackDepth)
  570. ThrowConvertException(OptionError,"ParenthesisNestedTooDeeply",
  571. option);
  572. PushImageStack();
  573. continue;
  574. }
  575. if (LocaleCompare(option,")") == 0)
  576. {
  577. FireImageStack(MagickTrue,MagickTrue,MagickTrue);
  578. if (k == 0)
  579. ThrowConvertException(OptionError,"UnableToParseExpression",option);
  580. PopImageStack();
  581. continue;
  582. }
  583. if (IsCommandOption(option) == MagickFalse)
  584. {
  585. Image
  586. *images;
  587. /*
  588. Read input image.
  589. */
  590. FireImageStack(MagickTrue,MagickTrue,pend);
  591. filename=argv[i];
  592. if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
  593. filename=argv[++i];
  594. if (image_info->ping != MagickFalse)
  595. images=PingImages(image_info,filename,exception);
  596. else
  597. images=ReadImages(image_info,filename,exception);
  598. status&=(images != (Image *) NULL) &&
  599. (exception->severity < ErrorException);
  600. if (images == (Image *) NULL)
  601. continue;
  602. AppendImageStack(images);
  603. continue;
  604. }
  605. pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
  606. switch (*(option+1))
  607. {
  608. case 'a':
  609. {
  610. if (LocaleCompare("adaptive-blur",option+1) == 0)
  611. {
  612. i++;
  613. if (i == (ssize_t) argc)
  614. ThrowConvertException(OptionError,"MissingArgument",option);
  615. if (IsGeometry(argv[i]) == MagickFalse)
  616. ThrowConvertInvalidArgumentException(option,argv[i]);
  617. break;
  618. }
  619. if (LocaleCompare("adaptive-resize",option+1) == 0)
  620. {
  621. i++;
  622. if (i == (ssize_t) argc)
  623. ThrowConvertException(OptionError,"MissingArgument",option);
  624. if (IsGeometry(argv[i]) == MagickFalse)
  625. ThrowConvertInvalidArgumentException(option,argv[i]);
  626. break;
  627. }
  628. if (LocaleCompare("adaptive-sharpen",option+1) == 0)
  629. {
  630. i++;
  631. if (i == (ssize_t) argc)
  632. ThrowConvertException(OptionError,"MissingArgument",option);
  633. if (IsGeometry(argv[i]) == MagickFalse)
  634. ThrowConvertInvalidArgumentException(option,argv[i]);
  635. break;
  636. }
  637. if (LocaleCompare("adjoin",option+1) == 0)
  638. break;
  639. if (LocaleCompare("affine",option+1) == 0)
  640. {
  641. if (*option == '+')
  642. break;
  643. i++;
  644. if (i == (ssize_t) argc)
  645. ThrowConvertException(OptionError,"MissingArgument",option);
  646. if (IsGeometry(argv[i]) == MagickFalse)
  647. ThrowConvertInvalidArgumentException(option,argv[i]);
  648. break;
  649. }
  650. if (LocaleCompare("alpha",option+1) == 0)
  651. {
  652. ssize_t
  653. type;
  654. if (*option == '+')
  655. break;
  656. i++;
  657. if (i == (ssize_t) argc)
  658. ThrowConvertException(OptionError,"MissingArgument",option);
  659. type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,
  660. argv[i]);
  661. if (type < 0)
  662. ThrowConvertException(OptionError,
  663. "UnrecognizedAlphaChannelOption",argv[i]);
  664. break;
  665. }
  666. if (LocaleCompare("annotate",option+1) == 0)
  667. {
  668. if (*option == '+')
  669. break;
  670. i++;
  671. if (i == (ssize_t) argc)
  672. ThrowConvertException(OptionError,"MissingArgument",option);
  673. if (IsGeometry(argv[i]) == MagickFalse)
  674. ThrowConvertInvalidArgumentException(option,argv[i]);
  675. i++;
  676. if (i == (ssize_t) argc)
  677. ThrowConvertException(OptionError,"MissingArgument",option);
  678. break;
  679. }
  680. if (LocaleCompare("antialias",option+1) == 0)
  681. break;
  682. if (LocaleCompare("append",option+1) == 0)
  683. break;
  684. if (LocaleCompare("attenuate",option+1) == 0)
  685. {
  686. if (*option == '+')
  687. break;
  688. i++;
  689. if (i == (ssize_t) argc)
  690. ThrowConvertException(OptionError,"MissingArgument",option);
  691. if (IsGeometry(argv[i]) == MagickFalse)
  692. ThrowConvertInvalidArgumentException(option,argv[i]);
  693. break;
  694. }
  695. if (LocaleCompare("authenticate",option+1) == 0)
  696. {
  697. if (*option == '+')
  698. break;
  699. i++;
  700. if (i == (ssize_t) argc)
  701. ThrowConvertException(OptionError,"MissingArgument",option);
  702. break;
  703. }
  704. if (LocaleCompare("auto-gamma",option+1) == 0)
  705. break;
  706. if (LocaleCompare("auto-level",option+1) == 0)
  707. break;
  708. if (LocaleCompare("auto-orient",option+1) == 0)
  709. break;
  710. if (LocaleCompare("auto-threshold",option+1) == 0)
  711. {
  712. ssize_t
  713. method;
  714. if (*option == '+')
  715. break;
  716. i++;
  717. if (i == (ssize_t) argc)
  718. ThrowConvertException(OptionError,"MissingArgument",option);
  719. method=ParseCommandOption(MagickAutoThresholdOptions,MagickFalse,
  720. argv[i]);
  721. if (method < 0)
  722. ThrowConvertException(OptionError,"UnrecognizedThresholdMethod",
  723. argv[i]);
  724. break;
  725. }
  726. if (LocaleCompare("average",option+1) == 0)
  727. break;
  728. ThrowConvertException(OptionError,"UnrecognizedOption",option)
  729. }
  730. case 'b':
  731. {
  732. if (LocaleCompare("background",option+1) == 0)
  733. {
  734. if (*option == '+')
  735. break;
  736. i++;
  737. if (i == (ssize_t) argc)
  738. ThrowConvertException(OptionError,"MissingArgument",option);
  739. break;
  740. }
  741. if (LocaleCompare("bench",option+1) == 0)
  742. {
  743. if (*option == '+')
  744. break;
  745. i++;
  746. if (i == (ssize_t) argc)
  747. ThrowConvertException(OptionError,"MissingArgument",option);
  748. if (IsGeometry(argv[i]) == MagickFalse)
  749. ThrowConvertInvalidArgumentException(option,argv[i]);
  750. break;
  751. }
  752. if (LocaleCompare("bias",option+1) == 0)
  753. {
  754. if (*option == '+')
  755. break;
  756. i++;
  757. if (i == (ssize_t) argc)
  758. ThrowConvertException(OptionError,"MissingArgument",option);
  759. if (IsGeometry(argv[i]) == MagickFalse)
  760. ThrowConvertInvalidArgumentException(option,argv[i]);
  761. break;
  762. }
  763. if (LocaleCompare("black-point-compensation",option+1) == 0)
  764. break;
  765. if (LocaleCompare("black-threshold",option+1) == 0)
  766. {
  767. if (*option == '+')
  768. break;
  769. i++;
  770. if (i == (ssize_t) argc)
  771. ThrowConvertException(OptionError,"MissingArgument",option);
  772. if (IsGeometry(argv[i]) == MagickFalse)
  773. ThrowConvertInvalidArgumentException(option,argv[i]);
  774. break;
  775. }
  776. if (LocaleCompare("blue-primary",option+1) == 0)
  777. {
  778. if (*option == '+')
  779. break;
  780. i++;
  781. if (i == (ssize_t) argc)
  782. ThrowConvertException(OptionError,"MissingArgument",option);
  783. if (IsGeometry(argv[i]) == MagickFalse)
  784. ThrowConvertInvalidArgumentException(option,argv[i]);
  785. break;
  786. }
  787. if (LocaleCompare("blue-shift",option+1) == 0)
  788. {
  789. if (*option == '+')
  790. break;
  791. i++;
  792. if (i == (ssize_t) argc)
  793. ThrowConvertException(OptionError,"MissingArgument",option);
  794. if (IsGeometry(argv[i]) == MagickFalse)
  795. ThrowConvertInvalidArgumentException(option,argv[i]);
  796. break;
  797. }
  798. if (LocaleCompare("blur",option+1) == 0)
  799. {
  800. if (*option == '+')
  801. break;
  802. i++;
  803. if (i == (ssize_t) argc)
  804. ThrowConvertException(OptionError,"MissingArgument",option);
  805. if (IsGeometry(argv[i]) == MagickFalse)
  806. ThrowConvertInvalidArgumentException(option,argv[i]);
  807. break;
  808. }
  809. if (LocaleCompare("border",option+1) == 0)
  810. {
  811. if (*option == '+')
  812. break;
  813. i++;
  814. if (i == (ssize_t) argc)
  815. ThrowConvertException(OptionError,"MissingArgument",option);
  816. if (IsGeometry(argv[i]) == MagickFalse)
  817. ThrowConvertInvalidArgumentException(option,argv[i]);
  818. break;
  819. }
  820. if (LocaleCompare("bordercolor",option+1) == 0)
  821. {
  822. if (*option == '+')
  823. break;
  824. i++;
  825. if (i == (ssize_t) argc)
  826. ThrowConvertException(OptionError,"MissingArgument",option);
  827. break;
  828. }
  829. if (LocaleCompare("box",option+1) == 0)
  830. {
  831. if (*option == '+')
  832. break;
  833. i++;
  834. if (i == (ssize_t) argc)
  835. ThrowConvertException(OptionError,"MissingArgument",option);
  836. break;
  837. }
  838. if (LocaleCompare("brightness-contrast",option+1) == 0)
  839. {
  840. i++;
  841. if (i == (ssize_t) argc)
  842. ThrowConvertException(OptionError,"MissingArgument",option);
  843. if (IsGeometry(argv[i]) == MagickFalse)
  844. ThrowConvertInvalidArgumentException(option,argv[i]);
  845. break;
  846. }
  847. ThrowConvertException(OptionError,"UnrecognizedOption",option)
  848. }
  849. case 'c':
  850. {
  851. if (LocaleCompare("cache",option+1) == 0)
  852. {
  853. if (*option == '+')
  854. break;
  855. i++;
  856. if (i == (ssize_t) argc)
  857. ThrowConvertException(OptionError,"MissingArgument",option);
  858. if (IsGeometry(argv[i]) == MagickFalse)
  859. ThrowConvertInvalidArgumentException(option,argv[i]);
  860. break;
  861. }
  862. if (LocaleCompare("canny",option+1) == 0)
  863. {
  864. if (*option == '+')
  865. break;
  866. i++;
  867. if (i == (ssize_t) argc)
  868. ThrowConvertException(OptionError,"MissingArgument",option);
  869. if (IsGeometry(argv[i]) == MagickFalse)
  870. ThrowConvertInvalidArgumentException(option,argv[i]);
  871. break;
  872. }
  873. if (LocaleCompare("caption",option+1) == 0)
  874. {
  875. if (*option == '+')
  876. break;
  877. i++;
  878. if (i == (ssize_t) argc)
  879. ThrowConvertException(OptionError,"MissingArgument",option);
  880. break;
  881. }
  882. if (LocaleCompare("cdl",option+1) == 0)
  883. {
  884. if (*option == '+')
  885. break;
  886. i++;
  887. if (i == (ssize_t) argc)
  888. ThrowConvertException(OptionError,"MissingArgument",option);
  889. break;
  890. }
  891. if (LocaleCompare("channel",option+1) == 0)
  892. {
  893. ssize_t
  894. channel;
  895. if (*option == '+')
  896. break;
  897. i++;
  898. if (i == (ssize_t) argc)
  899. ThrowConvertException(OptionError,"MissingArgument",option);
  900. channel=ParseChannelOption(argv[i]);
  901. if (channel < 0)
  902. ThrowConvertException(OptionError,"UnrecognizedChannelType",
  903. argv[i]);
  904. break;
  905. }
  906. if (LocaleCompare("channel-fx",option+1) == 0)
  907. {
  908. ssize_t
  909. channel;
  910. if (*option == '+')
  911. break;
  912. i++;
  913. if (i == (ssize_t) argc)
  914. ThrowConvertException(OptionError,"MissingArgument",option);
  915. channel=ParsePixelChannelOption(argv[i]);
  916. if (channel < 0)
  917. ThrowConvertException(OptionError,"UnrecognizedChannelType",
  918. argv[i]);
  919. break;
  920. }
  921. if (LocaleCompare("charcoal",option+1) == 0)
  922. {
  923. if (*option == '+')
  924. break;
  925. i++;
  926. if (i == (ssize_t) argc)
  927. ThrowConvertException(OptionError,"MissingArgument",option);
  928. if (IsGeometry(argv[i]) == MagickFalse)
  929. ThrowConvertInvalidArgumentException(option,argv[i]);
  930. break;
  931. }
  932. if (LocaleCompare("chop",option+1) == 0)
  933. {
  934. if (*option == '+')
  935. break;
  936. i++;
  937. if (i == (ssize_t) argc)
  938. ThrowConvertException(OptionError,"MissingArgument",option);
  939. if (IsGeometry(argv[i]) == MagickFalse)
  940. ThrowConvertInvalidArgumentException(option,argv[i]);
  941. break;
  942. }
  943. if (LocaleCompare("clahe",option+1) == 0)
  944. {
  945. if (*option == '+')
  946. break;
  947. i++;
  948. if (i == (ssize_t) argc)
  949. ThrowConvertException(OptionError,"MissingArgument",option);
  950. if (IsGeometry(argv[i]) == MagickFalse)
  951. ThrowConvertInvalidArgumentException(option,argv[i]);
  952. break;
  953. }
  954. if (LocaleCompare("clamp",option+1) == 0)
  955. break;
  956. if (LocaleCompare("clip",option+1) == 0)
  957. break;
  958. if (LocaleCompare("clip-mask",option+1) == 0)
  959. {
  960. if (*option == '+')
  961. break;
  962. i++;
  963. if (i == (ssize_t) argc)
  964. ThrowConvertException(OptionError,"MissingArgument",option);
  965. break;
  966. }
  967. if (LocaleCompare("clip-path",option+1) == 0)
  968. {
  969. i++;
  970. if (i == (ssize_t) argc)
  971. ThrowConvertException(OptionError,"MissingArgument",option);
  972. break;
  973. }
  974. if (LocaleCompare("clone",option+1) == 0)
  975. {
  976. Image
  977. *clone_images,
  978. *clone_list;
  979. clone_list=CloneImageList(image,exception);
  980. if (k != 0)
  981. clone_list=CloneImageList(image_stack[k-1].image,exception);
  982. if (clone_list == (Image *) NULL)
  983. ThrowConvertException(ImageError,"ImageSequenceRequired",option);
  984. FireImageStack(MagickTrue,MagickTrue,MagickTrue);
  985. if (*option == '+')
  986. clone_images=CloneImages(clone_list,"-1",exception);
  987. else
  988. {
  989. i++;
  990. if (i == (ssize_t) argc)
  991. ThrowConvertException(OptionError,"MissingArgument",option);
  992. if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
  993. ThrowConvertInvalidArgumentException(option,argv[i]);
  994. clone_images=CloneImages(clone_list,argv[i],exception);
  995. }
  996. if (clone_images == (Image *) NULL)
  997. ThrowConvertException(OptionError,"NoSuchImage",option);
  998. AppendImageStack(clone_images);
  999. clone_list=DestroyImageList(clone_list);
  1000. break;
  1001. }
  1002. if (LocaleCompare("clut",option+1) == 0)
  1003. break;
  1004. if (LocaleCompare("coalesce",option+1) == 0)
  1005. break;
  1006. if (LocaleCompare("colorize",option+1) == 0)
  1007. {
  1008. if (*option == '+')
  1009. break;
  1010. i++;
  1011. if (i == (ssize_t) argc)
  1012. ThrowConvertException(OptionError,"MissingArgument",option);
  1013. if (IsGeometry(argv[i]) == MagickFalse)
  1014. ThrowConvertInvalidArgumentException(option,argv[i]);
  1015. break;
  1016. }
  1017. if (LocaleCompare("color-matrix",option+1) == 0)
  1018. {
  1019. KernelInfo
  1020. *kernel_info;
  1021. if (*option == '+')
  1022. break;
  1023. i++;
  1024. if (i == (ssize_t) argc)
  1025. ThrowConvertException(OptionError,"MissingArgument",option);
  1026. kernel_info=AcquireKernelInfo(argv[i],exception);
  1027. if (kernel_info == (KernelInfo *) NULL)
  1028. ThrowConvertInvalidArgumentException(option,argv[i]);
  1029. kernel_info=DestroyKernelInfo(kernel_info);
  1030. break;
  1031. }
  1032. if (LocaleCompare("colors",option+1) == 0)
  1033. {
  1034. if (*option == '+')
  1035. break;
  1036. i++;
  1037. if ((i == (ssize_t) argc) ||
  1038. (IsGeometry(argv[i]) == MagickFalse))
  1039. ThrowConvertException(OptionError,"MissingArgument",option);
  1040. break;
  1041. }
  1042. if (LocaleCompare("colorspace",option+1) == 0)
  1043. {
  1044. ssize_t
  1045. colorspace;
  1046. if (*option == '+')
  1047. break;
  1048. i++;
  1049. if (i == (ssize_t) argc)
  1050. ThrowConvertException(OptionError,"MissingArgument",option);
  1051. colorspace=ParseCommandOption(MagickColorspaceOptions,
  1052. MagickFalse,argv[i]);
  1053. if (colorspace < 0)
  1054. ThrowConvertException(OptionError,"UnrecognizedColorspace",
  1055. argv[i]);
  1056. break;
  1057. }
  1058. if (LocaleCompare("combine",option+1) == 0)
  1059. break;
  1060. if (LocaleCompare("comment",option+1) == 0)
  1061. {
  1062. if (*option == '+')
  1063. break;
  1064. i++;
  1065. if (i == (ssize_t) argc)
  1066. ThrowConvertException(OptionError,"MissingArgument",option);
  1067. break;
  1068. }
  1069. if (LocaleCompare("compare",option+1) == 0)
  1070. break;
  1071. if (LocaleCompare("complex",option+1) == 0)
  1072. {
  1073. ssize_t
  1074. op;
  1075. if (*option == '+')
  1076. break;
  1077. i++;
  1078. if (i == (ssize_t) argc)
  1079. ThrowConvertException(OptionError,"MissingArgument",option);
  1080. op=ParseCommandOption(MagickComplexOptions,MagickFalse,argv[i]);
  1081. if (op < 0)
  1082. ThrowConvertException(OptionError,"UnrecognizedComplexOperator",
  1083. argv[i]);
  1084. break;
  1085. }
  1086. if (LocaleCompare("compose",option+1) == 0)
  1087. {
  1088. ssize_t
  1089. compose;
  1090. if (*option == '+')
  1091. break;
  1092. i++;
  1093. if (i == (ssize_t) argc)
  1094. ThrowConvertException(OptionError,"MissingArgument",option);
  1095. compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
  1096. argv[i]);
  1097. if (compose < 0)
  1098. ThrowConvertException(OptionError,"UnrecognizedComposeOperator",
  1099. argv[i]);
  1100. break;
  1101. }
  1102. if (LocaleCompare("composite",option+1) == 0)
  1103. break;
  1104. if (LocaleCompare("compress",option+1) == 0)
  1105. {
  1106. ssize_t
  1107. compress;
  1108. if (*option == '+')
  1109. break;
  1110. i++;
  1111. if (i == (ssize_t) argc)
  1112. ThrowConvertException(OptionError,"MissingArgument",option);
  1113. compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
  1114. argv[i]);
  1115. if (compress < 0)
  1116. ThrowConvertException(OptionError,"UnrecognizedImageCompression",
  1117. argv[i]);
  1118. break;
  1119. }
  1120. if (LocaleCompare("concurrent",option+1) == 0)
  1121. break;
  1122. if (LocaleCompare("connected-components",option+1) == 0)
  1123. {
  1124. i++;
  1125. if (i == (ssize_t) argc)
  1126. ThrowConvertException(OptionError,"MissingArgument",option);
  1127. if (IsGeometry(argv[i]) == MagickFalse)
  1128. ThrowConvertInvalidArgumentException(option,argv[i]);
  1129. break;
  1130. }
  1131. if (LocaleCompare("contrast",option+1) == 0)
  1132. break;
  1133. if (LocaleCompare("contrast-stretch",option+1) == 0)
  1134. {
  1135. i++;
  1136. if (i == (ssize_t) argc)
  1137. ThrowConvertException(OptionError,"MissingArgument",option);
  1138. if (IsGeometry(argv[i]) == MagickFalse)
  1139. ThrowConvertInvalidArgumentException(option,argv[i]);
  1140. break;
  1141. }
  1142. if (LocaleCompare("convolve",option+1) == 0)
  1143. {
  1144. KernelInfo
  1145. *kernel_info;
  1146. if (*option == '+')
  1147. break;
  1148. i++;
  1149. if (i == (ssize_t) argc)
  1150. ThrowConvertException(OptionError,"MissingArgument",option);
  1151. kernel_info=AcquireKernelInfo(argv[i],exception);
  1152. if (kernel_info == (KernelInfo *) NULL)
  1153. ThrowConvertInvalidArgumentException(option,argv[i]);
  1154. kernel_info=DestroyKernelInfo(kernel_info);
  1155. break;
  1156. }
  1157. if (LocaleCompare("copy",option+1) == 0)
  1158. {
  1159. if (*option == '+')
  1160. break;

Large files files are truncated, but you can click here to view the full file