PageRenderTime 64ms CodeModel.GetById 6ms app.highlight 47ms RepoModel.GetById 1ms 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

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

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