blob: 7afe147a88aadea3a3ce79db4e9483add95354b3 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
cristy4c08aed2011-07-01 19:47:50 +000054#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000055#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000056#include "MagickCore/utility-private.h"
cristy3ed852e2009-09-05 21:47:34 +000057
58/*
cristy154fa9d2011-08-05 14:25:15 +000059 Constant declaration.
60*/
cristy3a557c02011-08-06 19:48:02 +000061static const char
cristy638895a2011-08-06 23:19:14 +000062 MogrifyBackgroundColor[] = "#ffffff", /* white */
63 MogrifyBorderColor[] = "#dfdfdf", /* gray */
64 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000065
66/*
cristy3ed852e2009-09-05 21:47:34 +000067 Define declarations.
68*/
69#define UndefinedCompressionQuality 0UL
70
71/*
cristy3ed852e2009-09-05 21:47:34 +000072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
cristy5063d812010-10-19 16:28:10 +000076% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000077% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% MagickCommandGenesis() applies image processing options to an image as
83% prescribed by command line options.
84%
85% The format of the MagickCommandGenesis method is:
86%
87% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000088% MagickCommand command,int argc,char **argv,char **metadata,
89% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000090%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
cristy5063d812010-10-19 16:28:10 +000095% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000096% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000097% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000099%
100% o argc: Specifies a pointer to an integer describing the number of
101% elements in the argument vector.
102%
103% o argv: Specifies a pointer to a text array containing the command line
104% arguments.
105%
cristy5063d812010-10-19 16:28:10 +0000106% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000107%
108% o exception: return any errors or warnings in this structure.
109%
110*/
111WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
112 MagickCommand command,int argc,char **argv,char **metadata,
113 ExceptionInfo *exception)
114{
115 char
116 *option;
117
118 double
119 duration,
cristy8ea926d2011-12-09 12:25:04 +0000120 serial;
cristy3980b0d2009-10-25 14:37:13 +0000121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristyc2e3aeb2011-12-09 11:09:38 +0000131 iterations,
132 n,
133 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000134
cristyd0a94fa2010-03-12 14:18:11 +0000135 (void) setlocale(LC_ALL,"");
136 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000137 concurrent=MagickFalse;
138 duration=(-1.0);
139 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000140 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000141 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000142 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000143 {
144 option=argv[i];
145 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
146 continue;
147 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000148 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000149 if (LocaleCompare("concurrent",option+1) == 0)
150 concurrent=MagickTrue;
151 if (LocaleCompare("debug",option+1) == 0)
152 (void) SetLogEventMask(argv[++i]);
153 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000154 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000155 if (LocaleCompare("regard-warnings",option+1) == 0)
156 regard_warnings=MagickTrue;
157 }
cristy8ea926d2011-12-09 12:25:04 +0000158 if (iterations == 1)
159 {
160 status=command(image_info,argc,argv,metadata,exception);
161 if (exception->severity != UndefinedException)
162 {
163 if ((exception->severity > ErrorException) ||
164 (regard_warnings != MagickFalse))
165 status=MagickTrue;
166 CatchException(exception);
167 }
168 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
169 {
170 (void) fputs(*metadata,stdout);
171 (void) fputc('\n',stdout);
172 *metadata=DestroyString(*metadata);
173 }
174 return(status);
175 }
cristyc2e3aeb2011-12-09 11:09:38 +0000176 number_threads=GetOpenMPMaximumThreads();
cristy8ea926d2011-12-09 12:25:04 +0000177 serial=0.0;
cristyc2e3aeb2011-12-09 11:09:38 +0000178 for (n=1; n <= number_threads; n++)
179 {
180 double
cristy8ea926d2011-12-09 12:25:04 +0000181 e,
182 parallel,
cristyc2e3aeb2011-12-09 11:09:38 +0000183 user_time;
184
185 TimerInfo
186 *timer;
187
188 SetOpenMPMaximumThreads(n);
189 timer=AcquireTimerInfo();
190 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000191 {
cristyc2e3aeb2011-12-09 11:09:38 +0000192 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000193 {
cristyc2e3aeb2011-12-09 11:09:38 +0000194 if (status != MagickFalse)
195 continue;
196 if (duration > 0)
197 {
198 if (GetElapsedTime(timer) > duration)
199 continue;
200 (void) ContinueTimer(timer);
201 }
202 status=command(image_info,argc,argv,metadata,exception);
cristyceae09d2009-10-28 17:18:47 +0000203 if (exception->severity != UndefinedException)
204 {
205 if ((exception->severity > ErrorException) ||
206 (regard_warnings != MagickFalse))
207 status=MagickTrue;
208 CatchException(exception);
209 }
210 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
211 {
212 (void) fputs(*metadata,stdout);
213 (void) fputc('\n',stdout);
214 *metadata=DestroyString(*metadata);
215 }
216 }
217 }
cristyc2e3aeb2011-12-09 11:09:38 +0000218 else
219 {
220 SetOpenMPNested(1);
221#if defined(MAGICKCORE_OPENMP_SUPPORT)
222 # pragma omp parallel for shared(status)
223#endif
224 for (i=0; i < (ssize_t) iterations; i++)
225 {
226 if (status != MagickFalse)
227 continue;
228 if (duration > 0)
229 {
230 if (GetElapsedTime(timer) > duration)
231 continue;
232 (void) ContinueTimer(timer);
233 }
234 status=command(image_info,argc,argv,metadata,exception);
235#if defined(MAGICKCORE_OPENMP_SUPPORT)
236 # pragma omp critical (MagickCore_CommandGenesis)
237#endif
238 {
239 if (exception->severity != UndefinedException)
240 {
241 if ((exception->severity > ErrorException) ||
242 (regard_warnings != MagickFalse))
243 status=MagickTrue;
244 CatchException(exception);
245 }
246 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
247 {
248 (void) fputs(*metadata,stdout);
249 (void) fputc('\n',stdout);
250 *metadata=DestroyString(*metadata);
251 }
252 }
253 }
254 }
cristyc2e3aeb2011-12-09 11:09:38 +0000255 user_time=GetUserTime(timer);
cristy8ea926d2011-12-09 12:25:04 +0000256 parallel=GetElapsedTime(timer);
257 e=1.0;
258 if (n == 1)
259 serial=parallel;
260 else
261 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
262 (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000263 (void) FormatLocaleFile(stderr,
cristy91ce84d2011-12-09 23:02:25 +0000264 "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
cristy8ea926d2011-12-09 12:25:04 +0000265 (double) n,(double) iterations,(double) iterations/parallel,e,
266 user_time,(unsigned long) (parallel/60.0),(unsigned long)
267 floor(fmod(parallel,60.0)),(unsigned long)
268 (1000.0*(parallel-floor(parallel))+0.5));
cristyc2e3aeb2011-12-09 11:09:38 +0000269 timer=DestroyTimerInfo(timer);
270 }
cristy1f9e1ed2009-11-18 04:09:38 +0000271 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000272}
273
274/*
275%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276% %
277% %
278% %
cristy3ed852e2009-09-05 21:47:34 +0000279+ M o g r i f y I m a g e %
280% %
281% %
282% %
283%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284%
anthonye9c27192011-03-27 08:07:06 +0000285% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000286% image that may be part of a large list, but also handles any 'region'
287% image handling.
anthonye9c27192011-03-27 08:07:06 +0000288%
289% The image in the list may be modified in three different ways...
290%
291% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
292% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
293% * replace by a list of images (only the -separate option!)
294%
295% In each case the result is returned into the list, and a pointer to the
296% modified image (last image added if replaced by a list of images) is
297% returned.
298%
299% ASIDE: The -crop is present but restricted to non-tile single image crops
300%
301% This means if all the images are being processed (such as by
302% MogrifyImages(), next image to be processed will be as per the pointer
303% (*image)->next. Also the image list may grow as a result of some specific
304% operations but as images are never merged or deleted, it will never shrink
305% in length. Typically the list will remain the same length.
306%
307% WARNING: As the image pointed to may be replaced, the first image in the
308% list may also change. GetFirstImageInList() should be used by caller if
309% they wish return the Image pointer to the first image in list.
310%
cristy3ed852e2009-09-05 21:47:34 +0000311%
312% The format of the MogrifyImage method is:
313%
314% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
315% const char **argv,Image **image)
316%
317% A description of each parameter follows:
318%
319% o image_info: the image info..
320%
321% o argc: Specifies a pointer to an integer describing the number of
322% elements in the argument vector.
323%
324% o argv: Specifies a pointer to a text array containing the command line
325% arguments.
326%
327% o image: the image.
328%
329% o exception: return any errors or warnings in this structure.
330%
331*/
332
anthonydf8ebac2011-04-27 09:03:19 +0000333static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
334 ExceptionInfo *exception)
335{
336 char
337 key[MaxTextExtent];
338
339 ExceptionInfo
340 *sans_exception;
341
342 Image
343 *image;
344
345 ImageInfo
346 *read_info;
347
cristyfcd785b2011-11-08 01:48:33 +0000348 /*
349 Read an image into a image cache if not already present. Return the image
350 that is in the cache under that filename.
351 */
cristyb51dff52011-05-19 16:55:47 +0000352 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000353 sans_exception=AcquireExceptionInfo();
354 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
355 sans_exception=DestroyExceptionInfo(sans_exception);
356 if (image != (Image *) NULL)
357 return(image);
358 read_info=CloneImageInfo(image_info);
359 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
360 image=ReadImage(read_info,exception);
361 read_info=DestroyImageInfo(read_info);
362 if (image != (Image *) NULL)
363 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
364 return(image);
365}
366
cristy3ed852e2009-09-05 21:47:34 +0000367static MagickBooleanType IsPathWritable(const char *path)
368{
369 if (IsPathAccessible(path) == MagickFalse)
370 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000371 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000372 return(MagickFalse);
373 return(MagickTrue);
374}
375
cristybb503372010-05-27 20:51:26 +0000376static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000377{
378 if (x > y)
379 return(x);
380 return(y);
381}
382
anthonydf8ebac2011-04-27 09:03:19 +0000383static MagickBooleanType MonitorProgress(const char *text,
384 const MagickOffsetType offset,const MagickSizeType extent,
385 void *wand_unused(client_data))
386{
387 char
388 message[MaxTextExtent],
389 tag[MaxTextExtent];
390
391 const char
392 *locale_message;
393
394 register char
395 *p;
396
397 if (extent < 2)
398 return(MagickTrue);
399 (void) CopyMagickMemory(tag,text,MaxTextExtent);
400 p=strrchr(tag,'/');
401 if (p != (char *) NULL)
402 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000403 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000404 locale_message=GetLocaleMessage(message);
405 if (locale_message == message)
406 locale_message=tag;
407 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000408 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
409 locale_message,(long) offset,(unsigned long) extent,(long)
410 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000411 else
cristyb51dff52011-05-19 16:55:47 +0000412 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000413 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
414 (100L*offset/(extent-1)));
415 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000416 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000417 (void) fflush(stderr);
418 return(MagickTrue);
419}
420
cristy3884f692011-07-08 18:00:18 +0000421static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000422 const SparseColorMethod method,const char *arguments,
423 const MagickBooleanType color_from_image,ExceptionInfo *exception)
424{
anthonydf8ebac2011-04-27 09:03:19 +0000425 char
426 token[MaxTextExtent];
427
428 const char
429 *p;
430
431 double
432 *sparse_arguments;
433
anthonydf8ebac2011-04-27 09:03:19 +0000434 Image
435 *sparse_image;
436
cristy4c08aed2011-07-01 19:47:50 +0000437 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000438 color;
439
440 MagickBooleanType
441 error;
442
cristy5f09d852011-05-29 01:39:29 +0000443 register size_t
444 x;
445
446 size_t
447 number_arguments,
448 number_colors;
449
cristyf4425a72011-11-08 01:52:04 +0000450 /*
451 SparseColorOption() parses the complex -sparse-color argument into an an
452 array of floating point values then calls SparseColorImage(). Argument is
453 a complex mix of floating-point pixel coodinates, and color specifications
454 (or direct floating point numbers). The number of floats needed to
455 represent a color varies depending on the current channel setting.
456 */
anthonydf8ebac2011-04-27 09:03:19 +0000457 assert(image != (Image *) NULL);
458 assert(image->signature == MagickSignature);
459 if (image->debug != MagickFalse)
460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
461 assert(exception != (ExceptionInfo *) NULL);
462 assert(exception->signature == MagickSignature);
463 /*
464 Limit channels according to image - and add up number of color channel.
465 */
anthonydf8ebac2011-04-27 09:03:19 +0000466 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000467 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000468 number_colors++;
cristyed231572011-07-14 02:18:59 +0000469 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000470 number_colors++;
cristyed231572011-07-14 02:18:59 +0000471 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000472 number_colors++;
cristyed231572011-07-14 02:18:59 +0000473 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000474 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000475 number_colors++;
cristyed231572011-07-14 02:18:59 +0000476 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000477 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000478 number_colors++;
479
480 /*
481 Read string, to determine number of arguments needed,
482 */
483 p=arguments;
484 x=0;
485 while( *p != '\0' )
486 {
487 GetMagickToken(p,&p,token);
488 if ( token[0] == ',' ) continue;
489 if ( isalpha((int) token[0]) || token[0] == '#' ) {
490 if ( color_from_image ) {
491 (void) ThrowMagickException(exception,GetMagickModule(),
492 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
493 "Color arg given, when colors are coming from image");
494 return( (Image *)NULL);
495 }
496 x += number_colors; /* color argument */
497 }
498 else {
499 x++; /* floating point argument */
500 }
501 }
502 error=MagickTrue;
503 if ( color_from_image ) {
504 /* just the control points are being given */
505 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
506 number_arguments=(x/2)*(2+number_colors);
507 }
508 else {
509 /* control points and color values */
510 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
511 number_arguments=x;
512 }
513 if ( error ) {
514 (void) ThrowMagickException(exception,GetMagickModule(),
515 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
516 "Invalid number of Arguments");
517 return( (Image *)NULL);
518 }
519
520 /* Allocate and fill in the floating point arguments */
521 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
522 sizeof(*sparse_arguments));
523 if (sparse_arguments == (double *) NULL) {
524 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
525 "MemoryAllocationFailed","%s","SparseColorOption");
526 return( (Image *)NULL);
527 }
528 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
529 sizeof(*sparse_arguments));
530 p=arguments;
531 x=0;
532 while( *p != '\0' && x < number_arguments ) {
533 /* X coordinate */
534 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
535 if ( token[0] == '\0' ) break;
536 if ( isalpha((int) token[0]) || token[0] == '#' ) {
537 (void) ThrowMagickException(exception,GetMagickModule(),
538 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
539 "Color found, instead of X-coord");
540 error = MagickTrue;
541 break;
542 }
cristydbdd0e32011-11-04 23:29:40 +0000543 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000544 /* Y coordinate */
545 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
546 if ( token[0] == '\0' ) break;
547 if ( isalpha((int) token[0]) || token[0] == '#' ) {
548 (void) ThrowMagickException(exception,GetMagickModule(),
549 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
550 "Color found, instead of Y-coord");
551 error = MagickTrue;
552 break;
553 }
cristydbdd0e32011-11-04 23:29:40 +0000554 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000555 /* color values for this control point */
556#if 0
557 if ( (color_from_image ) {
558 /* get color from image */
559 /* HOW??? */
560 }
561 else
562#endif
563 {
564 /* color name or function given in string argument */
565 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
566 if ( token[0] == '\0' ) break;
567 if ( isalpha((int) token[0]) || token[0] == '#' ) {
568 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000569 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000570 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000571 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000572 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000573 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000574 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000575 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000576 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000577 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000578 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000579 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000580 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000581 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000582 }
583 else {
584 /* Colors given as a set of floating point values - experimental */
585 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000586 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000587 {
anthonydf8ebac2011-04-27 09:03:19 +0000588 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
589 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
590 break;
cristydbdd0e32011-11-04 23:29:40 +0000591 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000592 token[0] = ','; /* used this token - get another */
593 }
cristyed231572011-07-14 02:18:59 +0000594 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000595 {
anthonydf8ebac2011-04-27 09:03:19 +0000596 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
597 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
598 break;
cristydbdd0e32011-11-04 23:29:40 +0000599 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000600 token[0] = ','; /* used this token - get another */
601 }
cristyed231572011-07-14 02:18:59 +0000602 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000603 {
anthonydf8ebac2011-04-27 09:03:19 +0000604 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
605 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
606 break;
cristydbdd0e32011-11-04 23:29:40 +0000607 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000608 token[0] = ','; /* used this token - get another */
609 }
cristyed231572011-07-14 02:18:59 +0000610 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000611 (image->colorspace == CMYKColorspace))
612 {
anthonydf8ebac2011-04-27 09:03:19 +0000613 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
614 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
615 break;
cristydbdd0e32011-11-04 23:29:40 +0000616 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000617 token[0] = ','; /* used this token - get another */
618 }
cristyed231572011-07-14 02:18:59 +0000619 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000620 (image->matte != MagickFalse))
621 {
anthonydf8ebac2011-04-27 09:03:19 +0000622 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
623 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
624 break;
cristydbdd0e32011-11-04 23:29:40 +0000625 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000626 token[0] = ','; /* used this token - get another */
627 }
628 }
629 }
630 }
631 if ( number_arguments != x && !error ) {
632 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
633 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
634 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
635 return( (Image *)NULL);
636 }
637 if ( error )
638 return( (Image *)NULL);
639
640 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000641 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
642 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000643 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
644 return( sparse_image );
645}
646
cristy3ed852e2009-09-05 21:47:34 +0000647WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
648 const char **argv,Image **image,ExceptionInfo *exception)
649{
anthonydf8ebac2011-04-27 09:03:19 +0000650 ChannelType
651 channel;
652
cristy633f0c62011-09-15 13:27:36 +0000653 CompositeOperator
654 compose;
655
anthonydf8ebac2011-04-27 09:03:19 +0000656 const char
657 *format,
658 *option;
659
cristy9ed1f812011-10-08 02:00:08 +0000660 double
661 attenuate;
662
anthonydf8ebac2011-04-27 09:03:19 +0000663 DrawInfo
664 *draw_info;
665
666 GeometryInfo
667 geometry_info;
668
cristy3ed852e2009-09-05 21:47:34 +0000669 Image
670 *region_image;
671
anthonydf8ebac2011-04-27 09:03:19 +0000672 ImageInfo
673 *mogrify_info;
674
cristyebbcfea2011-02-25 02:43:54 +0000675 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000676 status;
677
cristy4c08aed2011-07-01 19:47:50 +0000678 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000679 fill;
cristy3ed852e2009-09-05 21:47:34 +0000680
anthonydf8ebac2011-04-27 09:03:19 +0000681 MagickStatusType
682 flags;
683
cristy28474bf2011-09-11 23:32:52 +0000684 PixelInterpolateMethod
685 interpolate_method;
686
anthonydf8ebac2011-04-27 09:03:19 +0000687 QuantizeInfo
688 *quantize_info;
689
690 RectangleInfo
691 geometry,
692 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000693
cristybb503372010-05-27 20:51:26 +0000694 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000695 i;
696
697 /*
698 Initialize method variables.
699 */
700 assert(image_info != (const ImageInfo *) NULL);
701 assert(image_info->signature == MagickSignature);
702 assert(image != (Image **) NULL);
703 assert((*image)->signature == MagickSignature);
704 if ((*image)->debug != MagickFalse)
705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
706 if (argc < 0)
707 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000708 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000709 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
710 quantize_info=AcquireQuantizeInfo(mogrify_info);
711 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000712 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000713 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000714 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000715 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000716 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000717 channel=mogrify_info->channel;
718 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000719 SetGeometry(*image,&region_geometry);
720 region_image=NewImageList();
721 /*
722 Transmogrify the image.
723 */
cristybb503372010-05-27 20:51:26 +0000724 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000725 {
anthonydf8ebac2011-04-27 09:03:19 +0000726 Image
727 *mogrify_image;
728
anthonye9c27192011-03-27 08:07:06 +0000729 ssize_t
730 count;
731
anthonydf8ebac2011-04-27 09:03:19 +0000732 option=argv[i];
733 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000734 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000735 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
736 0L);
cristycee97112010-05-28 00:44:52 +0000737 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000738 break;
cristy6b3da3a2010-06-20 02:21:46 +0000739 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000740 mogrify_image=(Image *)NULL;
741 switch (*(option+1))
742 {
743 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000744 {
anthonydf8ebac2011-04-27 09:03:19 +0000745 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000746 {
anthonydf8ebac2011-04-27 09:03:19 +0000747 /*
748 Adaptive blur image.
749 */
cristy6fccee12011-10-20 18:43:18 +0000750 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000751 flags=ParseGeometry(argv[i+1],&geometry_info);
752 if ((flags & SigmaValue) == 0)
753 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000754 if ((flags & XiValue) == 0)
755 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000756 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000757 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000758 break;
cristy3ed852e2009-09-05 21:47:34 +0000759 }
anthonydf8ebac2011-04-27 09:03:19 +0000760 if (LocaleCompare("adaptive-resize",option+1) == 0)
761 {
762 /*
763 Adaptive resize image.
764 */
cristy6fccee12011-10-20 18:43:18 +0000765 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000766 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
767 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
anthonyfd706f92012-01-19 04:22:02 +0000768 geometry.height,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000769 break;
770 }
771 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
772 {
773 /*
774 Adaptive sharpen image.
775 */
cristy6fccee12011-10-20 18:43:18 +0000776 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000777 flags=ParseGeometry(argv[i+1],&geometry_info);
778 if ((flags & SigmaValue) == 0)
779 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000780 if ((flags & XiValue) == 0)
781 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000782 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000783 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000784 break;
785 }
786 if (LocaleCompare("affine",option+1) == 0)
787 {
788 /*
789 Affine matrix.
790 */
791 if (*option == '+')
792 {
793 GetAffineMatrix(&draw_info->affine);
794 break;
795 }
796 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
797 break;
798 }
799 if (LocaleCompare("alpha",option+1) == 0)
800 {
801 AlphaChannelType
802 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000803
cristy6fccee12011-10-20 18:43:18 +0000804 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000805 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
806 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000807 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000808 break;
809 }
810 if (LocaleCompare("annotate",option+1) == 0)
811 {
812 char
813 *text,
814 geometry[MaxTextExtent];
815
816 /*
817 Annotate image.
818 */
cristy6fccee12011-10-20 18:43:18 +0000819 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000820 SetGeometryInfo(&geometry_info);
821 flags=ParseGeometry(argv[i+1],&geometry_info);
822 if ((flags & SigmaValue) == 0)
823 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000824 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
825 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000826 if (text == (char *) NULL)
827 break;
828 (void) CloneString(&draw_info->text,text);
829 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000830 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000831 geometry_info.xi,geometry_info.psi);
832 (void) CloneString(&draw_info->geometry,geometry);
833 draw_info->affine.sx=cos(DegreesToRadians(
834 fmod(geometry_info.rho,360.0)));
835 draw_info->affine.rx=sin(DegreesToRadians(
836 fmod(geometry_info.rho,360.0)));
837 draw_info->affine.ry=(-sin(DegreesToRadians(
838 fmod(geometry_info.sigma,360.0))));
839 draw_info->affine.sy=cos(DegreesToRadians(
840 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000841 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000842 break;
843 }
844 if (LocaleCompare("antialias",option+1) == 0)
845 {
846 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
847 MagickFalse;
848 draw_info->text_antialias=(*option == '-') ? MagickTrue :
849 MagickFalse;
850 break;
851 }
cristy9ed1f812011-10-08 02:00:08 +0000852 if (LocaleCompare("attenuate",option+1) == 0)
853 {
854 if (*option == '+')
855 {
856 attenuate=1.0;
857 break;
858 }
cristydbdd0e32011-11-04 23:29:40 +0000859 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000860 break;
861 }
anthonydf8ebac2011-04-27 09:03:19 +0000862 if (LocaleCompare("auto-gamma",option+1) == 0)
863 {
864 /*
865 Auto Adjust Gamma of image based on its mean
866 */
cristy6fccee12011-10-20 18:43:18 +0000867 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000868 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000869 break;
870 }
871 if (LocaleCompare("auto-level",option+1) == 0)
872 {
873 /*
874 Perfectly Normalize (max/min stretch) the image
875 */
cristy6fccee12011-10-20 18:43:18 +0000876 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000877 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000878 break;
879 }
880 if (LocaleCompare("auto-orient",option+1) == 0)
881 {
cristy6fccee12011-10-20 18:43:18 +0000882 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000883 switch ((*image)->orientation)
884 {
885 case TopRightOrientation:
886 {
887 mogrify_image=FlopImage(*image,exception);
888 break;
889 }
890 case BottomRightOrientation:
891 {
892 mogrify_image=RotateImage(*image,180.0,exception);
893 break;
894 }
895 case BottomLeftOrientation:
896 {
897 mogrify_image=FlipImage(*image,exception);
898 break;
899 }
900 case LeftTopOrientation:
901 {
902 mogrify_image=TransposeImage(*image,exception);
903 break;
904 }
905 case RightTopOrientation:
906 {
907 mogrify_image=RotateImage(*image,90.0,exception);
908 break;
909 }
910 case RightBottomOrientation:
911 {
912 mogrify_image=TransverseImage(*image,exception);
913 break;
914 }
915 case LeftBottomOrientation:
916 {
917 mogrify_image=RotateImage(*image,270.0,exception);
918 break;
919 }
920 default:
921 break;
922 }
923 if (mogrify_image != (Image *) NULL)
924 mogrify_image->orientation=TopLeftOrientation;
925 break;
926 }
927 break;
928 }
929 case 'b':
930 {
931 if (LocaleCompare("black-threshold",option+1) == 0)
932 {
933 /*
934 Black threshold image.
935 */
cristy6fccee12011-10-20 18:43:18 +0000936 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000937 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000938 break;
939 }
940 if (LocaleCompare("blue-shift",option+1) == 0)
941 {
942 /*
943 Blue shift image.
944 */
cristy6fccee12011-10-20 18:43:18 +0000945 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000946 geometry_info.rho=1.5;
947 if (*option == '-')
948 flags=ParseGeometry(argv[i+1],&geometry_info);
949 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
950 break;
951 }
952 if (LocaleCompare("blur",option+1) == 0)
953 {
954 /*
955 Gaussian blur image.
956 */
cristy6fccee12011-10-20 18:43:18 +0000957 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000958 flags=ParseGeometry(argv[i+1],&geometry_info);
959 if ((flags & SigmaValue) == 0)
960 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000961 if ((flags & XiValue) == 0)
962 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000963 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000964 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000965 break;
966 }
967 if (LocaleCompare("border",option+1) == 0)
968 {
969 /*
970 Surround image with a border of solid color.
971 */
cristy6fccee12011-10-20 18:43:18 +0000972 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000973 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
974 if ((flags & SigmaValue) == 0)
975 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000976 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000977 break;
978 }
979 if (LocaleCompare("bordercolor",option+1) == 0)
980 {
981 if (*option == '+')
982 {
cristy9950d572011-10-01 18:22:35 +0000983 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000984 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000985 break;
986 }
cristy9950d572011-10-01 18:22:35 +0000987 (void) QueryColorCompliance(argv[i+1],AllCompliance,
988 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000989 break;
990 }
991 if (LocaleCompare("box",option+1) == 0)
992 {
cristy9950d572011-10-01 18:22:35 +0000993 (void) QueryColorCompliance(argv[i+1],AllCompliance,
994 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000995 break;
996 }
997 if (LocaleCompare("brightness-contrast",option+1) == 0)
998 {
999 double
1000 brightness,
1001 contrast;
1002
1003 GeometryInfo
1004 geometry_info;
1005
1006 MagickStatusType
1007 flags;
1008
1009 /*
1010 Brightness / contrast image.
1011 */
cristy6fccee12011-10-20 18:43:18 +00001012 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001013 flags=ParseGeometry(argv[i+1],&geometry_info);
1014 brightness=geometry_info.rho;
1015 contrast=0.0;
1016 if ((flags & SigmaValue) != 0)
1017 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001018 (void) BrightnessContrastImage(*image,brightness,contrast,
1019 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001020 break;
1021 }
1022 break;
1023 }
1024 case 'c':
1025 {
1026 if (LocaleCompare("cdl",option+1) == 0)
1027 {
1028 char
1029 *color_correction_collection;
1030
1031 /*
1032 Color correct with a color decision list.
1033 */
cristy6fccee12011-10-20 18:43:18 +00001034 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001035 color_correction_collection=FileToString(argv[i+1],~0,exception);
1036 if (color_correction_collection == (char *) NULL)
1037 break;
cristy1bfa9f02011-08-11 02:35:43 +00001038 (void) ColorDecisionListImage(*image,color_correction_collection,
1039 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001040 break;
1041 }
1042 if (LocaleCompare("channel",option+1) == 0)
1043 {
1044 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001045 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001046 else
cristyfa806a72011-07-04 02:06:13 +00001047 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00001048 SetPixelChannelMapMask(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001049 break;
1050 }
1051 if (LocaleCompare("charcoal",option+1) == 0)
1052 {
1053 /*
1054 Charcoal image.
1055 */
cristy6fccee12011-10-20 18:43:18 +00001056 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001057 flags=ParseGeometry(argv[i+1],&geometry_info);
1058 if ((flags & SigmaValue) == 0)
1059 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001060 if ((flags & XiValue) == 0)
1061 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001062 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001063 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001064 break;
1065 }
1066 if (LocaleCompare("chop",option+1) == 0)
1067 {
1068 /*
1069 Chop the image.
1070 */
cristy6fccee12011-10-20 18:43:18 +00001071 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001072 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1073 mogrify_image=ChopImage(*image,&geometry,exception);
1074 break;
1075 }
1076 if (LocaleCompare("clamp",option+1) == 0)
1077 {
1078 /*
1079 Clamp image.
1080 */
cristy6fccee12011-10-20 18:43:18 +00001081 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001082 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001083 break;
1084 }
1085 if (LocaleCompare("clip",option+1) == 0)
1086 {
cristy6fccee12011-10-20 18:43:18 +00001087 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001088 if (*option == '+')
1089 {
cristy018f07f2011-09-04 21:15:19 +00001090 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001091 break;
1092 }
cristy018f07f2011-09-04 21:15:19 +00001093 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001094 break;
1095 }
1096 if (LocaleCompare("clip-mask",option+1) == 0)
1097 {
1098 CacheView
1099 *mask_view;
1100
1101 Image
1102 *mask_image;
1103
cristy4c08aed2011-07-01 19:47:50 +00001104 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001105 *restrict q;
1106
1107 register ssize_t
1108 x;
1109
1110 ssize_t
1111 y;
1112
cristy6fccee12011-10-20 18:43:18 +00001113 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001114 if (*option == '+')
1115 {
1116 /*
1117 Remove a mask.
1118 */
cristy018f07f2011-09-04 21:15:19 +00001119 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001120 break;
1121 }
1122 /*
1123 Set the image mask.
1124 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1125 */
1126 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1127 if (mask_image == (Image *) NULL)
1128 break;
cristy574cc262011-08-05 01:23:58 +00001129 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001130 return(MagickFalse);
1131 mask_view=AcquireCacheView(mask_image);
1132 for (y=0; y < (ssize_t) mask_image->rows; y++)
1133 {
1134 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1135 exception);
cristyacd2ed22011-08-30 01:44:23 +00001136 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001137 break;
1138 for (x=0; x < (ssize_t) mask_image->columns; x++)
1139 {
1140 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001141 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1142 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1143 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1144 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001145 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001146 }
1147 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1148 break;
1149 }
1150 mask_view=DestroyCacheView(mask_view);
1151 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001152 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001153 break;
1154 }
1155 if (LocaleCompare("clip-path",option+1) == 0)
1156 {
cristy6fccee12011-10-20 18:43:18 +00001157 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001158 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001159 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001160 break;
1161 }
1162 if (LocaleCompare("colorize",option+1) == 0)
1163 {
1164 /*
1165 Colorize the image.
1166 */
cristy6fccee12011-10-20 18:43:18 +00001167 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001168 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001169 break;
1170 }
1171 if (LocaleCompare("color-matrix",option+1) == 0)
1172 {
1173 KernelInfo
1174 *kernel;
1175
cristy6fccee12011-10-20 18:43:18 +00001176 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001177 kernel=AcquireKernelInfo(argv[i+1]);
1178 if (kernel == (KernelInfo *) NULL)
1179 break;
anthonyfd706f92012-01-19 04:22:02 +00001180 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001181 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1182 kernel=DestroyKernelInfo(kernel);
1183 break;
1184 }
1185 if (LocaleCompare("colors",option+1) == 0)
1186 {
1187 /*
1188 Reduce the number of colors in the image.
1189 */
cristy6fccee12011-10-20 18:43:18 +00001190 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001191 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1192 if (quantize_info->number_colors == 0)
1193 break;
1194 if (((*image)->storage_class == DirectClass) ||
1195 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001196 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001197 else
cristy018f07f2011-09-04 21:15:19 +00001198 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001199 break;
1200 }
1201 if (LocaleCompare("colorspace",option+1) == 0)
1202 {
1203 ColorspaceType
1204 colorspace;
1205
cristy6fccee12011-10-20 18:43:18 +00001206 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001207 if (*option == '+')
1208 {
cristye941a752011-10-15 01:52:48 +00001209 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001210 break;
1211 }
1212 colorspace=(ColorspaceType) ParseCommandOption(
1213 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001214 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001215 break;
1216 }
cristy633f0c62011-09-15 13:27:36 +00001217 if (LocaleCompare("compose",option+1) == 0)
1218 {
cristy6fccee12011-10-20 18:43:18 +00001219 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001220 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1221 MagickFalse,argv[i+1]);
1222 break;
1223 }
anthonydf8ebac2011-04-27 09:03:19 +00001224 if (LocaleCompare("contrast",option+1) == 0)
1225 {
cristy6fccee12011-10-20 18:43:18 +00001226 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001227 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001228 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001229 break;
1230 }
1231 if (LocaleCompare("contrast-stretch",option+1) == 0)
1232 {
1233 double
1234 black_point,
1235 white_point;
1236
1237 MagickStatusType
1238 flags;
1239
1240 /*
1241 Contrast stretch image.
1242 */
cristy6fccee12011-10-20 18:43:18 +00001243 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001244 flags=ParseGeometry(argv[i+1],&geometry_info);
1245 black_point=geometry_info.rho;
1246 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1247 black_point;
1248 if ((flags & PercentValue) != 0)
1249 {
1250 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1251 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1252 }
1253 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1254 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001255 (void) ContrastStretchImage(*image,black_point,white_point,
1256 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001257 break;
1258 }
1259 if (LocaleCompare("convolve",option+1) == 0)
1260 {
anthonydf8ebac2011-04-27 09:03:19 +00001261 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001262 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001263
cristy6fccee12011-10-20 18:43:18 +00001264 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001265 kernel_info=AcquireKernelInfo(argv[i+1]);
1266 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001267 break;
cristy0a922382011-07-16 15:30:34 +00001268 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001269 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001270 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001271 break;
1272 }
1273 if (LocaleCompare("crop",option+1) == 0)
1274 {
1275 /*
1276 Crop a image to a smaller size
1277 */
cristy6fccee12011-10-20 18:43:18 +00001278 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001279 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001280 break;
1281 }
1282 if (LocaleCompare("cycle",option+1) == 0)
1283 {
1284 /*
1285 Cycle an image colormap.
1286 */
cristy6fccee12011-10-20 18:43:18 +00001287 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001288 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1289 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001290 break;
1291 }
1292 break;
1293 }
1294 case 'd':
1295 {
1296 if (LocaleCompare("decipher",option+1) == 0)
1297 {
1298 StringInfo
1299 *passkey;
1300
1301 /*
1302 Decipher pixels.
1303 */
cristy6fccee12011-10-20 18:43:18 +00001304 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001305 passkey=FileToStringInfo(argv[i+1],~0,exception);
1306 if (passkey != (StringInfo *) NULL)
1307 {
1308 (void) PasskeyDecipherImage(*image,passkey,exception);
1309 passkey=DestroyStringInfo(passkey);
1310 }
1311 break;
1312 }
1313 if (LocaleCompare("density",option+1) == 0)
1314 {
1315 /*
1316 Set image density.
1317 */
1318 (void) CloneString(&draw_info->density,argv[i+1]);
1319 break;
1320 }
1321 if (LocaleCompare("depth",option+1) == 0)
1322 {
cristy6fccee12011-10-20 18:43:18 +00001323 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001324 if (*option == '+')
1325 {
cristy8a11cb12011-10-19 23:53:34 +00001326 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001327 break;
1328 }
cristy8a11cb12011-10-19 23:53:34 +00001329 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1330 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001331 break;
1332 }
1333 if (LocaleCompare("deskew",option+1) == 0)
1334 {
1335 double
1336 threshold;
1337
1338 /*
1339 Straighten the image.
1340 */
cristy6fccee12011-10-20 18:43:18 +00001341 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001342 if (*option == '+')
1343 threshold=40.0*QuantumRange/100.0;
1344 else
cristy9b34e302011-11-05 02:15:45 +00001345 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1346 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001347 mogrify_image=DeskewImage(*image,threshold,exception);
1348 break;
1349 }
1350 if (LocaleCompare("despeckle",option+1) == 0)
1351 {
1352 /*
1353 Reduce the speckles within an image.
1354 */
cristy6fccee12011-10-20 18:43:18 +00001355 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001356 mogrify_image=DespeckleImage(*image,exception);
1357 break;
1358 }
1359 if (LocaleCompare("display",option+1) == 0)
1360 {
1361 (void) CloneString(&draw_info->server_name,argv[i+1]);
1362 break;
1363 }
1364 if (LocaleCompare("distort",option+1) == 0)
1365 {
1366 char
1367 *args,
1368 token[MaxTextExtent];
1369
1370 const char
1371 *p;
1372
1373 DistortImageMethod
1374 method;
1375
1376 double
1377 *arguments;
1378
1379 register ssize_t
1380 x;
1381
1382 size_t
1383 number_arguments;
1384
1385 /*
1386 Distort image.
1387 */
cristy6fccee12011-10-20 18:43:18 +00001388 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001389 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1390 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001391 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001392 {
anthonydf8ebac2011-04-27 09:03:19 +00001393 double
1394 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001395
1396 /*
1397 Special Case - Argument is actually a resize geometry!
1398 Convert that to an appropriate distortion argument array.
1399 */
anthonydf8ebac2011-04-27 09:03:19 +00001400 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001401 exception);
1402 resize_args[0]=(double) geometry.width;
1403 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001404 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001405 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001406 break;
1407 }
cristy018f07f2011-09-04 21:15:19 +00001408 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1409 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001410 if (args == (char *) NULL)
1411 break;
1412 p=(char *) args;
1413 for (x=0; *p != '\0'; x++)
1414 {
1415 GetMagickToken(p,&p,token);
1416 if (*token == ',')
1417 GetMagickToken(p,&p,token);
1418 }
1419 number_arguments=(size_t) x;
1420 arguments=(double *) AcquireQuantumMemory(number_arguments,
1421 sizeof(*arguments));
1422 if (arguments == (double *) NULL)
1423 ThrowWandFatalException(ResourceLimitFatalError,
1424 "MemoryAllocationFailed",(*image)->filename);
1425 (void) ResetMagickMemory(arguments,0,number_arguments*
1426 sizeof(*arguments));
1427 p=(char *) args;
1428 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1429 {
1430 GetMagickToken(p,&p,token);
1431 if (*token == ',')
1432 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001433 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001434 }
1435 args=DestroyString(args);
1436 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1437 (*option == '+') ? MagickTrue : MagickFalse,exception);
1438 arguments=(double *) RelinquishMagickMemory(arguments);
1439 break;
1440 }
1441 if (LocaleCompare("dither",option+1) == 0)
1442 {
1443 if (*option == '+')
1444 {
1445 quantize_info->dither=MagickFalse;
1446 break;
1447 }
1448 quantize_info->dither=MagickTrue;
1449 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1450 MagickDitherOptions,MagickFalse,argv[i+1]);
1451 if (quantize_info->dither_method == NoDitherMethod)
1452 quantize_info->dither=MagickFalse;
1453 break;
1454 }
1455 if (LocaleCompare("draw",option+1) == 0)
1456 {
1457 /*
1458 Draw image.
1459 */
cristy6fccee12011-10-20 18:43:18 +00001460 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001461 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001462 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001463 break;
1464 }
1465 break;
1466 }
1467 case 'e':
1468 {
1469 if (LocaleCompare("edge",option+1) == 0)
1470 {
1471 /*
1472 Enhance edges in the image.
1473 */
cristy6fccee12011-10-20 18:43:18 +00001474 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001475 flags=ParseGeometry(argv[i+1],&geometry_info);
1476 if ((flags & SigmaValue) == 0)
1477 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001478 mogrify_image=EdgeImage(*image,geometry_info.rho,
1479 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001480 break;
1481 }
1482 if (LocaleCompare("emboss",option+1) == 0)
1483 {
1484 /*
cristyd89705a2012-01-20 02:52:24 +00001485 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001486 */
cristy6fccee12011-10-20 18:43:18 +00001487 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001488 flags=ParseGeometry(argv[i+1],&geometry_info);
1489 if ((flags & SigmaValue) == 0)
1490 geometry_info.sigma=1.0;
1491 mogrify_image=EmbossImage(*image,geometry_info.rho,
1492 geometry_info.sigma,exception);
1493 break;
1494 }
1495 if (LocaleCompare("encipher",option+1) == 0)
1496 {
1497 StringInfo
1498 *passkey;
1499
1500 /*
1501 Encipher pixels.
1502 */
cristy6fccee12011-10-20 18:43:18 +00001503 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001504 passkey=FileToStringInfo(argv[i+1],~0,exception);
1505 if (passkey != (StringInfo *) NULL)
1506 {
1507 (void) PasskeyEncipherImage(*image,passkey,exception);
1508 passkey=DestroyStringInfo(passkey);
1509 }
1510 break;
1511 }
1512 if (LocaleCompare("encoding",option+1) == 0)
1513 {
1514 (void) CloneString(&draw_info->encoding,argv[i+1]);
1515 break;
1516 }
1517 if (LocaleCompare("enhance",option+1) == 0)
1518 {
1519 /*
1520 Enhance image.
1521 */
cristy6fccee12011-10-20 18:43:18 +00001522 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001523 mogrify_image=EnhanceImage(*image,exception);
1524 break;
1525 }
1526 if (LocaleCompare("equalize",option+1) == 0)
1527 {
1528 /*
1529 Equalize image.
1530 */
cristy6fccee12011-10-20 18:43:18 +00001531 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001532 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001533 break;
1534 }
1535 if (LocaleCompare("evaluate",option+1) == 0)
1536 {
1537 double
1538 constant;
1539
1540 MagickEvaluateOperator
1541 op;
1542
cristy6fccee12011-10-20 18:43:18 +00001543 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001544 op=(MagickEvaluateOperator) ParseCommandOption(
1545 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001546 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1547 1.0);
cristyd42d9952011-07-08 14:21:50 +00001548 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001549 break;
1550 }
1551 if (LocaleCompare("extent",option+1) == 0)
1552 {
1553 /*
1554 Set the image extent.
1555 */
cristy6fccee12011-10-20 18:43:18 +00001556 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001557 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1558 if (geometry.width == 0)
1559 geometry.width=(*image)->columns;
1560 if (geometry.height == 0)
1561 geometry.height=(*image)->rows;
1562 mogrify_image=ExtentImage(*image,&geometry,exception);
1563 break;
1564 }
1565 break;
1566 }
1567 case 'f':
1568 {
1569 if (LocaleCompare("family",option+1) == 0)
1570 {
1571 if (*option == '+')
1572 {
1573 if (draw_info->family != (char *) NULL)
1574 draw_info->family=DestroyString(draw_info->family);
1575 break;
1576 }
1577 (void) CloneString(&draw_info->family,argv[i+1]);
1578 break;
1579 }
1580 if (LocaleCompare("features",option+1) == 0)
1581 {
1582 if (*option == '+')
1583 {
1584 (void) DeleteImageArtifact(*image,"identify:features");
1585 break;
1586 }
1587 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1588 break;
1589 }
1590 if (LocaleCompare("fill",option+1) == 0)
1591 {
1592 ExceptionInfo
1593 *sans;
1594
anthonyfd706f92012-01-19 04:22:02 +00001595 PixelInfo
1596 color;
1597
cristy4c08aed2011-07-01 19:47:50 +00001598 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001599 if (*option == '+')
1600 {
cristy269c9412011-10-13 23:41:15 +00001601 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001602 exception);
anthonyfd706f92012-01-19 04:22:02 +00001603 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001604 if (draw_info->fill_pattern != (Image *) NULL)
1605 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1606 break;
1607 }
1608 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001609 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001610 sans=DestroyExceptionInfo(sans);
1611 if (status == MagickFalse)
1612 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1613 exception);
anthonyfd706f92012-01-19 04:22:02 +00001614 else
1615 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001616 break;
1617 }
1618 if (LocaleCompare("flip",option+1) == 0)
1619 {
1620 /*
1621 Flip image scanlines.
1622 */
cristy6fccee12011-10-20 18:43:18 +00001623 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001624 mogrify_image=FlipImage(*image,exception);
1625 break;
1626 }
anthonydf8ebac2011-04-27 09:03:19 +00001627 if (LocaleCompare("floodfill",option+1) == 0)
1628 {
cristy4c08aed2011-07-01 19:47:50 +00001629 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001630 target;
1631
1632 /*
1633 Floodfill image.
1634 */
cristy6fccee12011-10-20 18:43:18 +00001635 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001636 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001637 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001638 exception);
cristyd42d9952011-07-08 14:21:50 +00001639 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001640 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001641 break;
1642 }
anthony3d2f4862011-05-01 13:48:16 +00001643 if (LocaleCompare("flop",option+1) == 0)
1644 {
1645 /*
1646 Flop image scanlines.
1647 */
cristy6fccee12011-10-20 18:43:18 +00001648 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001649 mogrify_image=FlopImage(*image,exception);
1650 break;
1651 }
anthonydf8ebac2011-04-27 09:03:19 +00001652 if (LocaleCompare("font",option+1) == 0)
1653 {
1654 if (*option == '+')
1655 {
1656 if (draw_info->font != (char *) NULL)
1657 draw_info->font=DestroyString(draw_info->font);
1658 break;
1659 }
1660 (void) CloneString(&draw_info->font,argv[i+1]);
1661 break;
1662 }
1663 if (LocaleCompare("format",option+1) == 0)
1664 {
1665 format=argv[i+1];
1666 break;
1667 }
1668 if (LocaleCompare("frame",option+1) == 0)
1669 {
1670 FrameInfo
1671 frame_info;
1672
1673 /*
1674 Surround image with an ornamental border.
1675 */
cristy6fccee12011-10-20 18:43:18 +00001676 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001677 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1678 frame_info.width=geometry.width;
1679 frame_info.height=geometry.height;
1680 if ((flags & HeightValue) == 0)
1681 frame_info.height=geometry.width;
1682 frame_info.outer_bevel=geometry.x;
1683 frame_info.inner_bevel=geometry.y;
1684 frame_info.x=(ssize_t) frame_info.width;
1685 frame_info.y=(ssize_t) frame_info.height;
1686 frame_info.width=(*image)->columns+2*frame_info.width;
1687 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001688 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001689 break;
1690 }
1691 if (LocaleCompare("function",option+1) == 0)
1692 {
1693 char
1694 *arguments,
1695 token[MaxTextExtent];
1696
1697 const char
1698 *p;
1699
1700 double
1701 *parameters;
1702
1703 MagickFunction
1704 function;
1705
1706 register ssize_t
1707 x;
1708
1709 size_t
1710 number_parameters;
1711
1712 /*
1713 Function Modify Image Values
1714 */
cristy6fccee12011-10-20 18:43:18 +00001715 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001716 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1717 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001718 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1719 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001720 if (arguments == (char *) NULL)
1721 break;
1722 p=(char *) arguments;
1723 for (x=0; *p != '\0'; x++)
1724 {
1725 GetMagickToken(p,&p,token);
1726 if (*token == ',')
1727 GetMagickToken(p,&p,token);
1728 }
1729 number_parameters=(size_t) x;
1730 parameters=(double *) AcquireQuantumMemory(number_parameters,
1731 sizeof(*parameters));
1732 if (parameters == (double *) NULL)
1733 ThrowWandFatalException(ResourceLimitFatalError,
1734 "MemoryAllocationFailed",(*image)->filename);
1735 (void) ResetMagickMemory(parameters,0,number_parameters*
1736 sizeof(*parameters));
1737 p=(char *) arguments;
1738 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1739 {
1740 GetMagickToken(p,&p,token);
1741 if (*token == ',')
1742 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001743 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001744 }
1745 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001746 (void) FunctionImage(*image,function,number_parameters,parameters,
1747 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001748 parameters=(double *) RelinquishMagickMemory(parameters);
1749 break;
1750 }
1751 break;
1752 }
1753 case 'g':
1754 {
1755 if (LocaleCompare("gamma",option+1) == 0)
1756 {
1757 /*
1758 Gamma image.
1759 */
cristy6fccee12011-10-20 18:43:18 +00001760 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001761 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001762 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001763 else
cristydbdd0e32011-11-04 23:29:40 +00001764 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001765 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001766 break;
1767 }
1768 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1769 (LocaleCompare("gaussian",option+1) == 0))
1770 {
1771 /*
1772 Gaussian blur image.
1773 */
cristy6fccee12011-10-20 18:43:18 +00001774 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001775 flags=ParseGeometry(argv[i+1],&geometry_info);
1776 if ((flags & SigmaValue) == 0)
1777 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001778 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001779 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001780 break;
1781 }
1782 if (LocaleCompare("geometry",option+1) == 0)
1783 {
1784 /*
1785 Record Image offset, Resize last image.
1786 */
cristy6fccee12011-10-20 18:43:18 +00001787 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001788 if (*option == '+')
1789 {
1790 if ((*image)->geometry != (char *) NULL)
1791 (*image)->geometry=DestroyString((*image)->geometry);
1792 break;
1793 }
1794 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1795 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1796 (void) CloneString(&(*image)->geometry,argv[i+1]);
1797 else
1798 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1799 (*image)->filter,(*image)->blur,exception);
1800 break;
1801 }
1802 if (LocaleCompare("gravity",option+1) == 0)
1803 {
1804 if (*option == '+')
1805 {
1806 draw_info->gravity=UndefinedGravity;
1807 break;
1808 }
1809 draw_info->gravity=(GravityType) ParseCommandOption(
1810 MagickGravityOptions,MagickFalse,argv[i+1]);
1811 break;
1812 }
1813 break;
1814 }
1815 case 'h':
1816 {
1817 if (LocaleCompare("highlight-color",option+1) == 0)
1818 {
1819 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1820 break;
1821 }
1822 break;
1823 }
1824 case 'i':
1825 {
1826 if (LocaleCompare("identify",option+1) == 0)
1827 {
1828 char
1829 *text;
1830
cristy6fccee12011-10-20 18:43:18 +00001831 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001832 if (format == (char *) NULL)
1833 {
cristya4037272011-08-28 15:11:39 +00001834 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1835 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001836 break;
1837 }
cristy018f07f2011-09-04 21:15:19 +00001838 text=InterpretImageProperties(mogrify_info,*image,format,
1839 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001840 if (text == (char *) NULL)
1841 break;
1842 (void) fputs(text,stdout);
1843 (void) fputc('\n',stdout);
1844 text=DestroyString(text);
1845 break;
1846 }
1847 if (LocaleCompare("implode",option+1) == 0)
1848 {
1849 /*
1850 Implode image.
1851 */
cristy6fccee12011-10-20 18:43:18 +00001852 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001853 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001854 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1855 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001856 break;
1857 }
1858 if (LocaleCompare("interline-spacing",option+1) == 0)
1859 {
1860 if (*option == '+')
1861 (void) ParseGeometry("0",&geometry_info);
1862 else
1863 (void) ParseGeometry(argv[i+1],&geometry_info);
1864 draw_info->interline_spacing=geometry_info.rho;
1865 break;
1866 }
cristy28474bf2011-09-11 23:32:52 +00001867 if (LocaleCompare("interpolate",option+1) == 0)
1868 {
1869 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1870 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1871 break;
1872 }
anthonydf8ebac2011-04-27 09:03:19 +00001873 if (LocaleCompare("interword-spacing",option+1) == 0)
1874 {
1875 if (*option == '+')
1876 (void) ParseGeometry("0",&geometry_info);
1877 else
1878 (void) ParseGeometry(argv[i+1],&geometry_info);
1879 draw_info->interword_spacing=geometry_info.rho;
1880 break;
1881 }
anthonyfd706f92012-01-19 04:22:02 +00001882 if (LocaleCompare("interpolative-resize",option+1) == 0)
1883 {
1884 /*
1885 Interpolative resize image.
1886 */
1887 (void) SyncImageSettings(mogrify_info,*image,exception);
1888 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1889 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1890 geometry.height,interpolate_method,exception);
1891 break;
1892 }
anthonydf8ebac2011-04-27 09:03:19 +00001893 break;
1894 }
1895 case 'k':
1896 {
1897 if (LocaleCompare("kerning",option+1) == 0)
1898 {
1899 if (*option == '+')
1900 (void) ParseGeometry("0",&geometry_info);
1901 else
1902 (void) ParseGeometry(argv[i+1],&geometry_info);
1903 draw_info->kerning=geometry_info.rho;
1904 break;
1905 }
1906 break;
1907 }
1908 case 'l':
1909 {
1910 if (LocaleCompare("lat",option+1) == 0)
1911 {
1912 /*
1913 Local adaptive threshold image.
1914 */
cristy6fccee12011-10-20 18:43:18 +00001915 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001916 flags=ParseGeometry(argv[i+1],&geometry_info);
1917 if ((flags & PercentValue) != 0)
1918 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1919 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001920 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001921 geometry_info.xi,exception);
1922 break;
1923 }
1924 if (LocaleCompare("level",option+1) == 0)
1925 {
1926 MagickRealType
1927 black_point,
1928 gamma,
1929 white_point;
1930
1931 MagickStatusType
1932 flags;
1933
1934 /*
1935 Parse levels.
1936 */
cristy6fccee12011-10-20 18:43:18 +00001937 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001938 flags=ParseGeometry(argv[i+1],&geometry_info);
1939 black_point=geometry_info.rho;
1940 white_point=(MagickRealType) QuantumRange;
1941 if ((flags & SigmaValue) != 0)
1942 white_point=geometry_info.sigma;
1943 gamma=1.0;
1944 if ((flags & XiValue) != 0)
1945 gamma=geometry_info.xi;
1946 if ((flags & PercentValue) != 0)
1947 {
1948 black_point*=(MagickRealType) (QuantumRange/100.0);
1949 white_point*=(MagickRealType) (QuantumRange/100.0);
1950 }
1951 if ((flags & SigmaValue) == 0)
1952 white_point=(MagickRealType) QuantumRange-black_point;
1953 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001954 (void) LevelizeImage(*image,black_point,white_point,gamma,
1955 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001956 else
cristy01e9afd2011-08-10 17:38:41 +00001957 (void) LevelImage(*image,black_point,white_point,gamma,
1958 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001959 break;
1960 }
1961 if (LocaleCompare("level-colors",option+1) == 0)
1962 {
1963 char
1964 token[MaxTextExtent];
1965
1966 const char
1967 *p;
1968
cristy4c08aed2011-07-01 19:47:50 +00001969 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001970 black_point,
1971 white_point;
1972
1973 p=(const char *) argv[i+1];
1974 GetMagickToken(p,&p,token); /* get black point color */
1975 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001976 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001977 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001978 else
cristy269c9412011-10-13 23:41:15 +00001979 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001980 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001981 if (isalpha((int) token[0]) || (token[0] == '#'))
1982 GetMagickToken(p,&p,token);
1983 if (*token == '\0')
1984 white_point=black_point; /* set everything to that color */
1985 else
1986 {
1987 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1988 GetMagickToken(p,&p,token); /* Get white point color. */
1989 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001990 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001991 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001992 else
cristy269c9412011-10-13 23:41:15 +00001993 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001994 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001995 }
cristy490408a2011-07-07 14:42:05 +00001996 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001997 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001998 break;
1999 }
2000 if (LocaleCompare("linear-stretch",option+1) == 0)
2001 {
2002 double
2003 black_point,
2004 white_point;
2005
2006 MagickStatusType
2007 flags;
2008
cristy6fccee12011-10-20 18:43:18 +00002009 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002010 flags=ParseGeometry(argv[i+1],&geometry_info);
2011 black_point=geometry_info.rho;
2012 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2013 if ((flags & SigmaValue) != 0)
2014 white_point=geometry_info.sigma;
2015 if ((flags & PercentValue) != 0)
2016 {
2017 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2018 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2019 }
2020 if ((flags & SigmaValue) == 0)
2021 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2022 black_point;
cristy33bd5152011-08-24 01:42:24 +00002023 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002024 break;
2025 }
anthonydf8ebac2011-04-27 09:03:19 +00002026 if (LocaleCompare("liquid-rescale",option+1) == 0)
2027 {
2028 /*
2029 Liquid rescale image.
2030 */
cristy6fccee12011-10-20 18:43:18 +00002031 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002032 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2033 if ((flags & XValue) == 0)
2034 geometry.x=1;
2035 if ((flags & YValue) == 0)
2036 geometry.y=0;
2037 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2038 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2039 break;
2040 }
2041 if (LocaleCompare("lowlight-color",option+1) == 0)
2042 {
2043 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2044 break;
2045 }
2046 break;
2047 }
2048 case 'm':
2049 {
2050 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002051 {
cristy3ed852e2009-09-05 21:47:34 +00002052 Image
anthonydf8ebac2011-04-27 09:03:19 +00002053 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002054
anthonydf8ebac2011-04-27 09:03:19 +00002055 /*
2056 Transform image colors to match this set of colors.
2057 */
cristy6fccee12011-10-20 18:43:18 +00002058 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002059 if (*option == '+')
2060 break;
2061 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2062 if (remap_image == (Image *) NULL)
2063 break;
cristy018f07f2011-09-04 21:15:19 +00002064 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002065 remap_image=DestroyImage(remap_image);
2066 break;
2067 }
2068 if (LocaleCompare("mask",option+1) == 0)
2069 {
2070 Image
2071 *mask;
2072
cristy6fccee12011-10-20 18:43:18 +00002073 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002074 if (*option == '+')
2075 {
2076 /*
2077 Remove a mask.
2078 */
cristy018f07f2011-09-04 21:15:19 +00002079 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002080 break;
2081 }
2082 /*
2083 Set the image mask.
2084 */
2085 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2086 if (mask == (Image *) NULL)
2087 break;
cristy018f07f2011-09-04 21:15:19 +00002088 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002089 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002090 break;
2091 }
2092 if (LocaleCompare("matte",option+1) == 0)
2093 {
2094 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002095 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002096 break;
2097 }
2098 if (LocaleCompare("median",option+1) == 0)
2099 {
2100 /*
2101 Median filter image.
2102 */
cristy6fccee12011-10-20 18:43:18 +00002103 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002104 flags=ParseGeometry(argv[i+1],&geometry_info);
2105 if ((flags & SigmaValue) == 0)
2106 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002107 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002108 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002109 break;
2110 }
2111 if (LocaleCompare("mode",option+1) == 0)
2112 {
2113 /*
2114 Mode image.
2115 */
cristy6fccee12011-10-20 18:43:18 +00002116 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002117 flags=ParseGeometry(argv[i+1],&geometry_info);
2118 if ((flags & SigmaValue) == 0)
2119 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002120 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002121 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002122 break;
2123 }
2124 if (LocaleCompare("modulate",option+1) == 0)
2125 {
cristy6fccee12011-10-20 18:43:18 +00002126 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002127 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002128 break;
2129 }
2130 if (LocaleCompare("monitor",option+1) == 0)
2131 {
2132 if (*option == '+')
2133 {
2134 (void) SetImageProgressMonitor(*image,
2135 (MagickProgressMonitor) NULL,(void *) NULL);
2136 break;
2137 }
2138 (void) SetImageProgressMonitor(*image,MonitorProgress,
2139 (void *) NULL);
2140 break;
2141 }
2142 if (LocaleCompare("monochrome",option+1) == 0)
2143 {
cristy6fccee12011-10-20 18:43:18 +00002144 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002145 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002146 break;
2147 }
2148 if (LocaleCompare("morphology",option+1) == 0)
2149 {
2150 char
2151 token[MaxTextExtent];
2152
2153 const char
2154 *p;
2155
2156 KernelInfo
2157 *kernel;
2158
2159 MorphologyMethod
2160 method;
2161
2162 ssize_t
2163 iterations;
2164
2165 /*
2166 Morphological Image Operation
2167 */
cristy6fccee12011-10-20 18:43:18 +00002168 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002169 p=argv[i+1];
2170 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002171 method=(MorphologyMethod) ParseCommandOption(
2172 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002173 iterations=1L;
2174 GetMagickToken(p,&p,token);
2175 if ((*p == ':') || (*p == ','))
2176 GetMagickToken(p,&p,token);
2177 if ((*p != '\0'))
2178 iterations=(ssize_t) StringToLong(p);
2179 kernel=AcquireKernelInfo(argv[i+2]);
2180 if (kernel == (KernelInfo *) NULL)
2181 {
2182 (void) ThrowMagickException(exception,GetMagickModule(),
2183 OptionError,"UnabletoParseKernel","morphology");
2184 status=MagickFalse;
2185 break;
2186 }
cristyf4ad9df2011-07-08 16:49:03 +00002187 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2188 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002189 kernel=DestroyKernelInfo(kernel);
2190 break;
2191 }
2192 if (LocaleCompare("motion-blur",option+1) == 0)
2193 {
2194 /*
2195 Motion blur image.
2196 */
cristy6fccee12011-10-20 18:43:18 +00002197 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002198 flags=ParseGeometry(argv[i+1],&geometry_info);
2199 if ((flags & SigmaValue) == 0)
2200 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002201 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002202 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002203 break;
2204 }
2205 break;
2206 }
2207 case 'n':
2208 {
2209 if (LocaleCompare("negate",option+1) == 0)
2210 {
cristy6fccee12011-10-20 18:43:18 +00002211 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002212 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002213 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002214 break;
2215 }
2216 if (LocaleCompare("noise",option+1) == 0)
2217 {
cristy6fccee12011-10-20 18:43:18 +00002218 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002219 if (*option == '-')
2220 {
cristyf36cbcb2011-09-07 13:28:22 +00002221 flags=ParseGeometry(argv[i+1],&geometry_info);
2222 if ((flags & SigmaValue) == 0)
2223 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002224 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002225 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002226 }
2227 else
2228 {
2229 NoiseType
2230 noise;
2231
2232 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2233 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002234 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002235 }
2236 break;
2237 }
2238 if (LocaleCompare("normalize",option+1) == 0)
2239 {
cristy6fccee12011-10-20 18:43:18 +00002240 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002241 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002242 break;
2243 }
2244 break;
2245 }
2246 case 'o':
2247 {
2248 if (LocaleCompare("opaque",option+1) == 0)
2249 {
cristy4c08aed2011-07-01 19:47:50 +00002250 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002251 target;
2252
cristy6fccee12011-10-20 18:43:18 +00002253 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002254 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002255 exception);
cristyd42d9952011-07-08 14:21:50 +00002256 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002257 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002258 break;
2259 }
2260 if (LocaleCompare("ordered-dither",option+1) == 0)
2261 {
cristy6fccee12011-10-20 18:43:18 +00002262 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002263 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002264 break;
2265 }
2266 break;
2267 }
2268 case 'p':
2269 {
2270 if (LocaleCompare("paint",option+1) == 0)
2271 {
cristy6fccee12011-10-20 18:43:18 +00002272 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002273 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002274 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2275 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002276 break;
2277 }
anthonydf8ebac2011-04-27 09:03:19 +00002278 if (LocaleCompare("pointsize",option+1) == 0)
2279 {
2280 if (*option == '+')
2281 (void) ParseGeometry("12",&geometry_info);
2282 else
2283 (void) ParseGeometry(argv[i+1],&geometry_info);
2284 draw_info->pointsize=geometry_info.rho;
2285 break;
2286 }
2287 if (LocaleCompare("polaroid",option+1) == 0)
2288 {
cristye9e3d382011-12-14 01:50:13 +00002289 const char
2290 *caption;
2291
anthonydf8ebac2011-04-27 09:03:19 +00002292 double
2293 angle;
2294
2295 RandomInfo
2296 *random_info;
2297
2298 /*
2299 Simulate a Polaroid picture.
2300 */
cristy6fccee12011-10-20 18:43:18 +00002301 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002302 random_info=AcquireRandomInfo();
2303 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2304 random_info=DestroyRandomInfo(random_info);
2305 if (*option == '-')
2306 {
2307 SetGeometryInfo(&geometry_info);
2308 flags=ParseGeometry(argv[i+1],&geometry_info);
2309 angle=geometry_info.rho;
2310 }
cristye9e3d382011-12-14 01:50:13 +00002311 caption=GetImageProperty(*image,"caption",exception);
2312 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002313 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002314 break;
2315 }
2316 if (LocaleCompare("posterize",option+1) == 0)
2317 {
2318 /*
2319 Posterize image.
2320 */
cristy6fccee12011-10-20 18:43:18 +00002321 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002322 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002323 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002324 break;
2325 }
2326 if (LocaleCompare("preview",option+1) == 0)
2327 {
2328 PreviewType
2329 preview_type;
2330
2331 /*
2332 Preview image.
2333 */
cristy6fccee12011-10-20 18:43:18 +00002334 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002335 if (*option == '+')
2336 preview_type=UndefinedPreview;
2337 else
cristy28474bf2011-09-11 23:32:52 +00002338 preview_type=(PreviewType) ParseCommandOption(
2339 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002340 mogrify_image=PreviewImage(*image,preview_type,exception);
2341 break;
2342 }
2343 if (LocaleCompare("profile",option+1) == 0)
2344 {
2345 const char
2346 *name;
2347
2348 const StringInfo
2349 *profile;
2350
2351 Image
2352 *profile_image;
2353
2354 ImageInfo
2355 *profile_info;
2356
cristy6fccee12011-10-20 18:43:18 +00002357 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002358 if (*option == '+')
2359 {
2360 /*
2361 Remove a profile from the image.
2362 */
2363 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002364 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002365 break;
2366 }
2367 /*
2368 Associate a profile with the image.
2369 */
2370 profile_info=CloneImageInfo(mogrify_info);
2371 profile=GetImageProfile(*image,"iptc");
2372 if (profile != (StringInfo *) NULL)
2373 profile_info->profile=(void *) CloneStringInfo(profile);
2374 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2375 profile_info=DestroyImageInfo(profile_info);
2376 if (profile_image == (Image *) NULL)
2377 {
2378 StringInfo
2379 *profile;
2380
2381 profile_info=CloneImageInfo(mogrify_info);
2382 (void) CopyMagickString(profile_info->filename,argv[i+1],
2383 MaxTextExtent);
2384 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2385 if (profile != (StringInfo *) NULL)
2386 {
2387 (void) ProfileImage(*image,profile_info->magick,
2388 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002389 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002390 profile=DestroyStringInfo(profile);
2391 }
2392 profile_info=DestroyImageInfo(profile_info);
2393 break;
2394 }
2395 ResetImageProfileIterator(profile_image);
2396 name=GetNextImageProfile(profile_image);
2397 while (name != (const char *) NULL)
2398 {
2399 profile=GetImageProfile(profile_image,name);
2400 if (profile != (StringInfo *) NULL)
2401 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002402 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002403 name=GetNextImageProfile(profile_image);
2404 }
2405 profile_image=DestroyImage(profile_image);
2406 break;
2407 }
2408 break;
2409 }
2410 case 'q':
2411 {
2412 if (LocaleCompare("quantize",option+1) == 0)
2413 {
2414 if (*option == '+')
2415 {
2416 quantize_info->colorspace=UndefinedColorspace;
2417 break;
2418 }
2419 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2420 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2421 break;
2422 }
2423 break;
2424 }
2425 case 'r':
2426 {
2427 if (LocaleCompare("radial-blur",option+1) == 0)
2428 {
2429 /*
2430 Radial blur image.
2431 */
cristy6fccee12011-10-20 18:43:18 +00002432 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002433 flags=ParseGeometry(argv[i+1],&geometry_info);
2434 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2435 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002436 break;
2437 }
2438 if (LocaleCompare("raise",option+1) == 0)
2439 {
2440 /*
2441 Surround image with a raise of solid color.
2442 */
2443 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2444 if ((flags & SigmaValue) == 0)
2445 geometry.height=geometry.width;
2446 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002447 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002448 break;
2449 }
2450 if (LocaleCompare("random-threshold",option+1) == 0)
2451 {
2452 /*
2453 Threshold image.
2454 */
cristy6fccee12011-10-20 18:43:18 +00002455 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002456 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002457 break;
2458 }
2459 if (LocaleCompare("recolor",option+1) == 0)
2460 {
2461 KernelInfo
2462 *kernel;
2463
cristy6fccee12011-10-20 18:43:18 +00002464 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002465 kernel=AcquireKernelInfo(argv[i+1]);
2466 if (kernel == (KernelInfo *) NULL)
2467 break;
2468 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2469 kernel=DestroyKernelInfo(kernel);
2470 break;
2471 }
2472 if (LocaleCompare("region",option+1) == 0)
2473 {
cristy6fccee12011-10-20 18:43:18 +00002474 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002475 if (region_image != (Image *) NULL)
2476 {
2477 /*
2478 Composite region.
2479 */
2480 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002481 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002482 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002483 *image=DestroyImage(*image);
2484 *image=region_image;
2485 region_image = (Image *) NULL;
2486 }
2487 if (*option == '+')
2488 break;
2489 /*
2490 Apply transformations to a selected region of the image.
2491 */
cristy3ed852e2009-09-05 21:47:34 +00002492 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2493 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002494 mogrify_image=CropImage(*image,&region_geometry,exception);
2495 if (mogrify_image == (Image *) NULL)
2496 break;
2497 region_image=(*image);
2498 *image=mogrify_image;
2499 mogrify_image=(Image *) NULL;
2500 break;
cristy3ed852e2009-09-05 21:47:34 +00002501 }
anthonydf8ebac2011-04-27 09:03:19 +00002502 if (LocaleCompare("render",option+1) == 0)
2503 {
cristy6fccee12011-10-20 18:43:18 +00002504 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002505 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2506 break;
2507 }
2508 if (LocaleCompare("remap",option+1) == 0)
2509 {
2510 Image
2511 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002512
anthonydf8ebac2011-04-27 09:03:19 +00002513 /*
2514 Transform image colors to match this set of colors.
2515 */
cristy6fccee12011-10-20 18:43:18 +00002516 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002517 if (*option == '+')
2518 break;
2519 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2520 if (remap_image == (Image *) NULL)
2521 break;
cristy018f07f2011-09-04 21:15:19 +00002522 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002523 remap_image=DestroyImage(remap_image);
2524 break;
2525 }
2526 if (LocaleCompare("repage",option+1) == 0)
2527 {
2528 if (*option == '+')
2529 {
2530 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2531 break;
2532 }
2533 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002534 break;
2535 }
2536 if (LocaleCompare("resample",option+1) == 0)
2537 {
2538 /*
2539 Resample image.
2540 */
cristy6fccee12011-10-20 18:43:18 +00002541 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002542 flags=ParseGeometry(argv[i+1],&geometry_info);
2543 if ((flags & SigmaValue) == 0)
2544 geometry_info.sigma=geometry_info.rho;
2545 mogrify_image=ResampleImage(*image,geometry_info.rho,
2546 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2547 break;
2548 }
2549 if (LocaleCompare("resize",option+1) == 0)
2550 {
2551 /*
2552 Resize image.
2553 */
cristy6fccee12011-10-20 18:43:18 +00002554 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002555 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2556 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2557 (*image)->filter,(*image)->blur,exception);
2558 break;
2559 }
2560 if (LocaleCompare("roll",option+1) == 0)
2561 {
2562 /*
2563 Roll image.
2564 */
cristy6fccee12011-10-20 18:43:18 +00002565 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002566 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2567 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2568 break;
2569 }
2570 if (LocaleCompare("rotate",option+1) == 0)
2571 {
2572 char
2573 *geometry;
2574
2575 /*
2576 Check for conditional image rotation.
2577 */
cristy6fccee12011-10-20 18:43:18 +00002578 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002579 if (strchr(argv[i+1],'>') != (char *) NULL)
2580 if ((*image)->columns <= (*image)->rows)
2581 break;
2582 if (strchr(argv[i+1],'<') != (char *) NULL)
2583 if ((*image)->columns >= (*image)->rows)
2584 break;
2585 /*
2586 Rotate image.
2587 */
2588 geometry=ConstantString(argv[i+1]);
2589 (void) SubstituteString(&geometry,">","");
2590 (void) SubstituteString(&geometry,"<","");
2591 (void) ParseGeometry(geometry,&geometry_info);
2592 geometry=DestroyString(geometry);
2593 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2594 break;
2595 }
2596 break;
2597 }
2598 case 's':
2599 {
2600 if (LocaleCompare("sample",option+1) == 0)
2601 {
2602 /*
2603 Sample image with pixel replication.
2604 */
cristy6fccee12011-10-20 18:43:18 +00002605 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002606 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2607 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2608 exception);
2609 break;
2610 }
2611 if (LocaleCompare("scale",option+1) == 0)
2612 {
2613 /*
2614 Resize image.
2615 */
cristy6fccee12011-10-20 18:43:18 +00002616 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002617 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2618 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2619 exception);
2620 break;
2621 }
2622 if (LocaleCompare("selective-blur",option+1) == 0)
2623 {
2624 /*
2625 Selectively blur pixels within a contrast threshold.
2626 */
cristy6fccee12011-10-20 18:43:18 +00002627 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002628 flags=ParseGeometry(argv[i+1],&geometry_info);
2629 if ((flags & PercentValue) != 0)
2630 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002631 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002632 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002633 break;
2634 }
2635 if (LocaleCompare("separate",option+1) == 0)
2636 {
2637 /*
2638 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002639 */
cristy6fccee12011-10-20 18:43:18 +00002640 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002641 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002642 break;
2643 }
2644 if (LocaleCompare("sepia-tone",option+1) == 0)
2645 {
2646 double
2647 threshold;
2648
2649 /*
2650 Sepia-tone image.
2651 */
cristy6fccee12011-10-20 18:43:18 +00002652 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002653 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2654 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002655 mogrify_image=SepiaToneImage(*image,threshold,exception);
2656 break;
2657 }
2658 if (LocaleCompare("segment",option+1) == 0)
2659 {
2660 /*
2661 Segment image.
2662 */
cristy6fccee12011-10-20 18:43:18 +00002663 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002664 flags=ParseGeometry(argv[i+1],&geometry_info);
2665 if ((flags & SigmaValue) == 0)
2666 geometry_info.sigma=1.0;
2667 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002668 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2669 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002670 break;
2671 }
2672 if (LocaleCompare("set",option+1) == 0)
2673 {
2674 char
2675 *value;
2676
2677 /*
2678 Set image option.
2679 */
2680 if (*option == '+')
2681 {
2682 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2683 (void) DeleteImageRegistry(argv[i+1]+9);
2684 else
2685 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2686 {
2687 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2688 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2689 }
2690 else
2691 (void) DeleteImageProperty(*image,argv[i+1]);
2692 break;
2693 }
cristy018f07f2011-09-04 21:15:19 +00002694 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2695 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002696 if (value == (char *) NULL)
2697 break;
2698 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2699 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2700 exception);
2701 else
2702 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2703 {
2704 (void) SetImageOption(image_info,argv[i+1]+7,value);
2705 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2706 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2707 }
2708 else
cristyd15e6592011-10-15 00:13:06 +00002709 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002710 value=DestroyString(value);
2711 break;
2712 }
2713 if (LocaleCompare("shade",option+1) == 0)
2714 {
2715 /*
2716 Shade image.
2717 */
cristy6fccee12011-10-20 18:43:18 +00002718 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002719 flags=ParseGeometry(argv[i+1],&geometry_info);
2720 if ((flags & SigmaValue) == 0)
2721 geometry_info.sigma=1.0;
2722 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2723 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2724 break;
2725 }
2726 if (LocaleCompare("shadow",option+1) == 0)
2727 {
2728 /*
2729 Shadow image.
2730 */
cristy6fccee12011-10-20 18:43:18 +00002731 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002732 flags=ParseGeometry(argv[i+1],&geometry_info);
2733 if ((flags & SigmaValue) == 0)
2734 geometry_info.sigma=1.0;
2735 if ((flags & XiValue) == 0)
2736 geometry_info.xi=4.0;
2737 if ((flags & PsiValue) == 0)
2738 geometry_info.psi=4.0;
2739 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002740 geometry_info.sigma,(*image)->bias,(ssize_t)
2741 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2742 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002743 break;
2744 }
2745 if (LocaleCompare("sharpen",option+1) == 0)
2746 {
2747 /*
2748 Sharpen image.
2749 */
cristy6fccee12011-10-20 18:43:18 +00002750 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002751 flags=ParseGeometry(argv[i+1],&geometry_info);
2752 if ((flags & SigmaValue) == 0)
2753 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002754 if ((flags & XiValue) == 0)
2755 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002756 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002757 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002758 break;
2759 }
2760 if (LocaleCompare("shave",option+1) == 0)
2761 {
2762 /*
2763 Shave the image edges.
2764 */
cristy6fccee12011-10-20 18:43:18 +00002765 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002766 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2767 mogrify_image=ShaveImage(*image,&geometry,exception);
2768 break;
2769 }
2770 if (LocaleCompare("shear",option+1) == 0)
2771 {
2772 /*
2773 Shear image.
2774 */
cristy6fccee12011-10-20 18:43:18 +00002775 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002776 flags=ParseGeometry(argv[i+1],&geometry_info);
2777 if ((flags & SigmaValue) == 0)
2778 geometry_info.sigma=geometry_info.rho;
2779 mogrify_image=ShearImage(*image,geometry_info.rho,
2780 geometry_info.sigma,exception);
2781 break;
2782 }
2783 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2784 {
2785 /*
2786 Sigmoidal non-linearity contrast control.
2787 */
cristy6fccee12011-10-20 18:43:18 +00002788 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002789 flags=ParseGeometry(argv[i+1],&geometry_info);
2790 if ((flags & SigmaValue) == 0)
2791 geometry_info.sigma=(double) QuantumRange/2.0;
2792 if ((flags & PercentValue) != 0)
2793 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2794 100.0;
cristy9ee60942011-07-06 14:54:38 +00002795 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002796 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2797 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002798 break;
2799 }
2800 if (LocaleCompare("sketch",option+1) == 0)
2801 {
2802 /*
2803 Sketch image.
2804 */
cristy6fccee12011-10-20 18:43:18 +00002805 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002806 flags=ParseGeometry(argv[i+1],&geometry_info);
2807 if ((flags & SigmaValue) == 0)
2808 geometry_info.sigma=1.0;
2809 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002810 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002811 break;
2812 }
2813 if (LocaleCompare("solarize",option+1) == 0)
2814 {
2815 double
2816 threshold;
2817
cristy6fccee12011-10-20 18:43:18 +00002818 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002819 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2820 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002821 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002822 break;
2823 }
2824 if (LocaleCompare("sparse-color",option+1) == 0)
2825 {
2826 SparseColorMethod
2827 method;
2828
2829 char
2830 *arguments;
2831
2832 /*
2833 Sparse Color Interpolated Gradient
2834 */
cristy6fccee12011-10-20 18:43:18 +00002835 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002836 method=(SparseColorMethod) ParseCommandOption(
2837 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002838 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2839 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002840 if (arguments == (char *) NULL)
2841 break;
cristy3884f692011-07-08 18:00:18 +00002842 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002843 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2844 arguments=DestroyString(arguments);
2845 break;
2846 }
2847 if (LocaleCompare("splice",option+1) == 0)
2848 {
2849 /*
2850 Splice a solid color into the image.
2851 */
cristy6fccee12011-10-20 18:43:18 +00002852 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002853 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2854 mogrify_image=SpliceImage(*image,&geometry,exception);
2855 break;
2856 }
2857 if (LocaleCompare("spread",option+1) == 0)
2858 {
2859 /*
2860 Spread an image.
2861 */
cristy6fccee12011-10-20 18:43:18 +00002862 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002863 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002864 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002865 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002866 break;
2867 }
2868 if (LocaleCompare("statistic",option+1) == 0)
2869 {
2870 StatisticType
2871 type;
2872
cristy6fccee12011-10-20 18:43:18 +00002873 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002874 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2875 MagickFalse,argv[i+1]);
2876 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002877 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2878 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002879 break;
2880 }
2881 if (LocaleCompare("stretch",option+1) == 0)
2882 {
2883 if (*option == '+')
2884 {
2885 draw_info->stretch=UndefinedStretch;
2886 break;
2887 }
2888 draw_info->stretch=(StretchType) ParseCommandOption(
2889 MagickStretchOptions,MagickFalse,argv[i+1]);
2890 break;
2891 }
2892 if (LocaleCompare("strip",option+1) == 0)
2893 {
2894 /*
2895 Strip image of profiles and comments.
2896 */
cristy6fccee12011-10-20 18:43:18 +00002897 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002898 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002899 break;
2900 }
2901 if (LocaleCompare("stroke",option+1) == 0)
2902 {
2903 ExceptionInfo
2904 *sans;
2905
anthonyfd706f92012-01-19 04:22:02 +00002906 PixelInfo
2907 color;
2908
anthonydf8ebac2011-04-27 09:03:19 +00002909 if (*option == '+')
2910 {
cristy9950d572011-10-01 18:22:35 +00002911 (void) QueryColorCompliance("none",AllCompliance,
2912 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002913 if (draw_info->stroke_pattern != (Image *) NULL)
2914 draw_info->stroke_pattern=DestroyImage(
2915 draw_info->stroke_pattern);
2916 break;
2917 }
2918 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00002919 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002920 sans=DestroyExceptionInfo(sans);
2921 if (status == MagickFalse)
2922 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2923 exception);
anthonyfd706f92012-01-19 04:22:02 +00002924 else
2925 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00002926 break;
2927 }
2928 if (LocaleCompare("strokewidth",option+1) == 0)
2929 {
cristy9b34e302011-11-05 02:15:45 +00002930 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002931 break;
2932 }
2933 if (LocaleCompare("style",option+1) == 0)
2934 {
2935 if (*option == '+')
2936 {
2937 draw_info->style=UndefinedStyle;
2938 break;
2939 }
2940 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2941 MagickFalse,argv[i+1]);
2942 break;
2943 }
2944 if (LocaleCompare("swirl",option+1) == 0)
2945 {
2946 /*
2947 Swirl image.
2948 */
cristy6fccee12011-10-20 18:43:18 +00002949 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002950 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002951 mogrify_image=SwirlImage(*image,geometry_info.rho,
2952 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002953 break;
2954 }
2955 break;
2956 }
2957 case 't':
2958 {
2959 if (LocaleCompare("threshold",option+1) == 0)
2960 {
2961 double
2962 threshold;
2963
2964 /*
2965 Threshold image.
2966 */
cristy6fccee12011-10-20 18:43:18 +00002967 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002968 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002969 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002970 else
cristy9b34e302011-11-05 02:15:45 +00002971 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2972 1.0);
cristye941a752011-10-15 01:52:48 +00002973 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002974 break;
2975 }
2976 if (LocaleCompare("thumbnail",option+1) == 0)
2977 {
2978 /*
2979 Thumbnail image.
2980 */
cristy6fccee12011-10-20 18:43:18 +00002981 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002982 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2983 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2984 exception);
2985 break;
2986 }
2987 if (LocaleCompare("tile",option+1) == 0)
2988 {
2989 if (*option == '+')
2990 {
2991 if (draw_info->fill_pattern != (Image *) NULL)
2992 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2993 break;
2994 }
2995 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2996 exception);
2997 break;
2998 }
2999 if (LocaleCompare("tint",option+1) == 0)
3000 {
3001 /*
3002 Tint the image.
3003 */
cristy6fccee12011-10-20 18:43:18 +00003004 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00003005 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003006 break;
3007 }
3008 if (LocaleCompare("transform",option+1) == 0)
3009 {
3010 /*
3011 Affine transform image.
3012 */
cristy6fccee12011-10-20 18:43:18 +00003013 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003014 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3015 exception);
3016 break;
3017 }
3018 if (LocaleCompare("transparent",option+1) == 0)
3019 {
cristy4c08aed2011-07-01 19:47:50 +00003020 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00003021 target;
3022
cristy6fccee12011-10-20 18:43:18 +00003023 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003024 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003025 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003026 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003027 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003028 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003029 break;
3030 }
3031 if (LocaleCompare("transpose",option+1) == 0)
3032 {
3033 /*
3034 Transpose image scanlines.
3035 */
cristy6fccee12011-10-20 18:43:18 +00003036 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003037 mogrify_image=TransposeImage(*image,exception);
3038 break;
3039 }
3040 if (LocaleCompare("transverse",option+1) == 0)
3041 {
3042 /*
3043 Transverse image scanlines.
3044 */
cristy6fccee12011-10-20 18:43:18 +00003045 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003046 mogrify_image=TransverseImage(*image,exception);
3047 break;
3048 }
3049 if (LocaleCompare("treedepth",option+1) == 0)
3050 {
3051 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3052 break;
3053 }
3054 if (LocaleCompare("trim",option+1) == 0)
3055 {
3056 /*
3057 Trim image.
3058 */
cristy6fccee12011-10-20 18:43:18 +00003059 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003060 mogrify_image=TrimImage(*image,exception);
3061 break;
3062 }
3063 if (LocaleCompare("type",option+1) == 0)
3064 {
3065 ImageType
3066 type;
3067
cristy6fccee12011-10-20 18:43:18 +00003068 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003069 if (*option == '+')
3070 type=UndefinedType;
3071 else
3072 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3073 argv[i+1]);
3074 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003075 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003076 break;
3077 }
3078 break;
3079 }
3080 case 'u':
3081 {
3082 if (LocaleCompare("undercolor",option+1) == 0)
3083 {
cristy9950d572011-10-01 18:22:35 +00003084 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3085 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003086 break;
3087 }
3088 if (LocaleCompare("unique",option+1) == 0)
3089 {
3090 if (*option == '+')
3091 {
3092 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3093 break;
3094 }
3095 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3096 (void) SetImageArtifact(*image,"verbose","true");
3097 break;
3098 }
3099 if (LocaleCompare("unique-colors",option+1) == 0)
3100 {
3101 /*
3102 Unique image colors.
3103 */
cristy6fccee12011-10-20 18:43:18 +00003104 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003105 mogrify_image=UniqueImageColors(*image,exception);
3106 break;
3107 }
3108 if (LocaleCompare("unsharp",option+1) == 0)
3109 {
3110 /*
3111 Unsharp mask image.
3112 */
cristy6fccee12011-10-20 18:43:18 +00003113 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003114 flags=ParseGeometry(argv[i+1],&geometry_info);
3115 if ((flags & SigmaValue) == 0)
3116 geometry_info.sigma=1.0;
3117 if ((flags & XiValue) == 0)
3118 geometry_info.xi=1.0;
3119 if ((flags & PsiValue) == 0)
3120 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003121 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3122 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003123 break;
3124 }
3125 break;
3126 }
3127 case 'v':
3128 {
3129 if (LocaleCompare("verbose",option+1) == 0)
3130 {
3131 (void) SetImageArtifact(*image,option+1,
3132 *option == '+' ? "false" : "true");
3133 break;
3134 }
3135 if (LocaleCompare("vignette",option+1) == 0)
3136 {
3137 /*
3138 Vignette image.
3139 */
cristy6fccee12011-10-20 18:43:18 +00003140 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003141 flags=ParseGeometry(argv[i+1],&geometry_info);
3142 if ((flags & SigmaValue) == 0)
3143 geometry_info.sigma=1.0;
3144 if ((flags & XiValue) == 0)
3145 geometry_info.xi=0.1*(*image)->columns;
3146 if ((flags & PsiValue) == 0)
3147 geometry_info.psi=0.1*(*image)->rows;
3148 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003149 geometry_info.sigma,(*image)->bias,(ssize_t)
3150 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3151 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003152 break;
3153 }
3154 if (LocaleCompare("virtual-pixel",option+1) == 0)
3155 {
3156 if (*option == '+')
3157 {
3158 (void) SetImageVirtualPixelMethod(*image,
3159 UndefinedVirtualPixelMethod);
3160 break;
3161 }
3162 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3163 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3164 argv[i+1]));
3165 break;
3166 }
3167 break;
3168 }
3169 case 'w':
3170 {
3171 if (LocaleCompare("wave",option+1) == 0)
3172 {
3173 /*
3174 Wave image.
3175 */
cristy6fccee12011-10-20 18:43:18 +00003176 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003177 flags=ParseGeometry(argv[i+1],&geometry_info);
3178 if ((flags & SigmaValue) == 0)
3179 geometry_info.sigma=1.0;
3180 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003181 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003182 break;
3183 }
3184 if (LocaleCompare("weight",option+1) == 0)
3185 {
3186 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3187 if (LocaleCompare(argv[i+1],"all") == 0)
3188 draw_info->weight=0;
3189 if (LocaleCompare(argv[i+1],"bold") == 0)
3190 draw_info->weight=700;
3191 if (LocaleCompare(argv[i+1],"bolder") == 0)
3192 if (draw_info->weight <= 800)
3193 draw_info->weight+=100;
3194 if (LocaleCompare(argv[i+1],"lighter") == 0)
3195 if (draw_info->weight >= 100)
3196 draw_info->weight-=100;
3197 if (LocaleCompare(argv[i+1],"normal") == 0)
3198 draw_info->weight=400;
3199 break;
3200 }
3201 if (LocaleCompare("white-threshold",option+1) == 0)
3202 {
3203 /*
3204 White threshold image.
3205 */
cristy6fccee12011-10-20 18:43:18 +00003206 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003207 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003208 break;
3209 }
3210 break;
3211 }
3212 default:
3213 break;
3214 }
3215 /*
3216 Replace current image with any image that was generated
3217 */
3218 if (mogrify_image != (Image *) NULL)
3219 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003220 i+=count;
3221 }
3222 if (region_image != (Image *) NULL)
3223 {
anthonydf8ebac2011-04-27 09:03:19 +00003224 /*
3225 Composite transformed region onto image.
3226 */
cristy6fccee12011-10-20 18:43:18 +00003227 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003228 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003229 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003230 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003231 *image=DestroyImage(*image);
3232 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003233 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003234 }
3235 /*
3236 Free resources.
3237 */
anthonydf8ebac2011-04-27 09:03:19 +00003238 quantize_info=DestroyQuantizeInfo(quantize_info);
3239 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003240 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003241 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003242 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003243}
3244
3245/*
3246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3247% %
3248% %
3249% %
cristy5063d812010-10-19 16:28:10 +00003250+ M o g r i f y I m a g e C o m m a n d %
cristy3ed852e2009-09-05 21:47:34 +00003251% %
3252% %
3253% %
3254%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3255%
3256% MogrifyImageCommand() transforms an image or a sequence of images. These
3257% transforms include image scaling, image rotation, color reduction, and
3258% others. The transmogrified image overwrites the original image.
3259%
3260% The format of the MogrifyImageCommand method is:
3261%
3262% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3263% const char **argv,char **metadata,ExceptionInfo *exception)
3264%
3265% A description of each parameter follows:
3266%
3267% o image_info: the image info.
3268%
3269% o argc: the number of elements in the argument vector.
3270%
3271% o argv: A text array containing the command line arguments.
3272%
3273% o metadata: any metadata is returned here.
3274%
3275% o exception: return any errors or warnings in this structure.
3276%
3277*/
3278
3279static MagickBooleanType MogrifyUsage(void)
3280{
3281 static const char
3282 *miscellaneous[]=
3283 {
3284 "-debug events display copious debugging information",
3285 "-help print program options",
3286 "-list type print a list of supported option arguments",
3287 "-log format format of debugging information",
3288 "-version print version information",
3289 (char *) NULL
3290 },
3291 *operators[]=
3292 {
3293 "-adaptive-blur geometry",
3294 " adaptively blur pixels; decrease effect near edges",
3295 "-adaptive-resize geometry",
3296 " adaptively resize image using 'mesh' interpolation",
3297 "-adaptive-sharpen geometry",
3298 " adaptively sharpen pixels; increase effect near edges",
3299 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3300 " transparent, extract, background, or shape",
3301 "-annotate geometry text",
3302 " annotate the image with text",
3303 "-auto-gamma automagically adjust gamma level of image",
3304 "-auto-level automagically adjust color levels of image",
3305 "-auto-orient automagically orient (rotate) image",
3306 "-bench iterations measure performance",
3307 "-black-threshold value",
3308 " force all pixels below the threshold into black",
3309 "-blue-shift simulate a scene at nighttime in the moonlight",
3310 "-blur geometry reduce image noise and reduce detail levels",
3311 "-border geometry surround image with a border of color",
3312 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003313 "-brightness-contrast geometry",
3314 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003315 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003316 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003317 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003318 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003319 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003320 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003321 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003322 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003323 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003324 "-contrast enhance or reduce the image contrast",
3325 "-contrast-stretch geometry",
3326 " improve contrast by `stretching' the intensity range",
3327 "-convolve coefficients",
3328 " apply a convolution kernel to the image",
3329 "-cycle amount cycle the image colormap",
3330 "-decipher filename convert cipher pixels to plain pixels",
3331 "-deskew threshold straighten an image",
3332 "-despeckle reduce the speckles within an image",
3333 "-distort method args",
3334 " distort images according to given method ad args",
3335 "-draw string annotate the image with a graphic primitive",
3336 "-edge radius apply a filter to detect edges in the image",
3337 "-encipher filename convert plain pixels to cipher pixels",
3338 "-emboss radius emboss an image",
3339 "-enhance apply a digital filter to enhance a noisy image",
3340 "-equalize perform histogram equalization to an image",
3341 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003342 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-extent geometry set the image size",
3344 "-extract geometry extract area from image",
3345 "-fft implements the discrete Fourier transform (DFT)",
3346 "-flip flip image vertically",
3347 "-floodfill geometry color",
3348 " floodfill the image with color",
3349 "-flop flop image horizontally",
3350 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003351 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003352 " apply function over image values",
3353 "-gamma value level of gamma correction",
3354 "-gaussian-blur geometry",
3355 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003356 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-identify identify the format and characteristics of the image",
3358 "-ift implements the inverse discrete Fourier transform (DFT)",
3359 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003360 "-interpolative-resize geometry",
3361 " resize image using interpolation",
cristy3ed852e2009-09-05 21:47:34 +00003362 "-lat geometry local adaptive thresholding",
3363 "-layers method optimize, merge, or compare image layers",
3364 "-level value adjust the level of image contrast",
3365 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003366 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003367 "-linear-stretch geometry",
3368 " improve contrast by `stretching with saturation'",
3369 "-liquid-rescale geometry",
3370 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003371 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003372 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003373 "-modulate value vary the brightness, saturation, and hue",
3374 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003375 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003376 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-motion-blur geometry",
3378 " simulate motion blur",
3379 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003380 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-normalize transform image to span the full range of colors",
3382 "-opaque color change this color to the fill color",
3383 "-ordered-dither NxN",
3384 " add a noise pattern to the image with specific",
3385 " amplitudes",
3386 "-paint radius simulate an oil painting",
3387 "-polaroid angle simulate a Polaroid picture",
3388 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003389 "-profile filename add, delete, or apply an image profile",
3390 "-quantize colorspace reduce colors in this colorspace",
3391 "-radial-blur angle radial blur the image",
3392 "-raise value lighten/darken image edges to create a 3-D effect",
3393 "-random-threshold low,high",
3394 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003395 "-region geometry apply options to a portion of the image",
3396 "-render render vector graphics",
3397 "-repage geometry size and location of an image canvas",
3398 "-resample geometry change the resolution of an image",
3399 "-resize geometry resize the image",
3400 "-roll geometry roll an image vertically or horizontally",
3401 "-rotate degrees apply Paeth rotation to the image",
3402 "-sample geometry scale image with pixel sampling",
3403 "-scale geometry scale the image",
3404 "-segment values segment an image",
3405 "-selective-blur geometry",
3406 " selectively blur pixels within a contrast threshold",
3407 "-sepia-tone threshold",
3408 " simulate a sepia-toned photo",
3409 "-set property value set an image property",
3410 "-shade degrees shade the image using a distant light source",
3411 "-shadow geometry simulate an image shadow",
3412 "-sharpen geometry sharpen the image",
3413 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003414 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003415 "-sigmoidal-contrast geometry",
3416 " increase the contrast without saturating highlights or shadows",
3417 "-sketch geometry simulate a pencil sketch",
3418 "-solarize threshold negate all pixels above the threshold level",
3419 "-sparse-color method args",
3420 " fill in a image based on a few color points",
3421 "-splice geometry splice the background color into the image",
3422 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003423 "-statistic type radius",
3424 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003425 "-strip strip image of all profiles and comments",
3426 "-swirl degrees swirl image pixels about the center",
3427 "-threshold value threshold the image",
3428 "-thumbnail geometry create a thumbnail of the image",
3429 "-tile filename tile image when filling a graphic primitive",
3430 "-tint value tint the image with the fill color",
3431 "-transform affine transform image",
3432 "-transparent color make this color transparent within the image",
3433 "-transpose flip image vertically and rotate 90 degrees",
3434 "-transverse flop image horizontally and rotate 270 degrees",
3435 "-trim trim image edges",
3436 "-type type image type",
3437 "-unique-colors discard all but one of any pixel color",
3438 "-unsharp geometry sharpen the image",
3439 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003440 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003441 "-white-threshold value",
3442 " force all pixels above the threshold into white",
3443 (char *) NULL
3444 },
3445 *sequence_operators[]=
3446 {
cristy4285d782011-02-09 20:12:28 +00003447 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003448 "-clut apply a color lookup table to the image",
3449 "-coalesce merge a sequence of images",
3450 "-combine combine a sequence of images",
3451 "-composite composite image",
3452 "-crop geometry cut out a rectangular region of the image",
3453 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003454 "-evaluate-sequence operator",
3455 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003456 "-flatten flatten a sequence of images",
3457 "-fx expression apply mathematical expression to an image channel(s)",
3458 "-hald-clut apply a Hald color lookup table to the image",
3459 "-morph value morph an image sequence",
3460 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003461 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003462 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003463 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003464 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003465 "-write filename write images to this file",
3466 (char *) NULL
3467 },
3468 *settings[]=
3469 {
3470 "-adjoin join images into a single multi-image file",
3471 "-affine matrix affine transform matrix",
3472 "-alpha option activate, deactivate, reset, or set the alpha channel",
3473 "-antialias remove pixel-aliasing",
3474 "-authenticate password",
3475 " decipher image with this password",
3476 "-attenuate value lessen (or intensify) when adding noise to an image",
3477 "-background color background color",
3478 "-bias value add bias when convolving an image",
3479 "-black-point-compensation",
3480 " use black point compensation",
3481 "-blue-primary point chromaticity blue primary point",
3482 "-bordercolor color border color",
3483 "-caption string assign a caption to an image",
3484 "-channel type apply option to select image channels",
3485 "-colors value preferred number of colors in the image",
3486 "-colorspace type alternate image colorspace",
3487 "-comment string annotate image with comment",
3488 "-compose operator set image composite operator",
3489 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003490 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003491 " define one or more image format options",
3492 "-delay value display the next image after pausing",
3493 "-density geometry horizontal and vertical density of the image",
3494 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003495 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003496 "-display server get image or font from this X server",
3497 "-dispose method layer disposal method",
3498 "-dither method apply error diffusion to image",
3499 "-encoding type text encoding type",
3500 "-endian type endianness (MSB or LSB) of the image",
3501 "-family name render text with this font family",
3502 "-fill color color to use when filling a graphic primitive",
3503 "-filter type use this filter when resizing an image",
3504 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003505 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003506 "-fuzz distance colors within this distance are considered equal",
3507 "-gravity type horizontal and vertical text placement",
3508 "-green-primary point chromaticity green primary point",
3509 "-intent type type of rendering intent when managing the image color",
3510 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003511 "-interline-spacing value",
3512 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003513 "-interpolate method pixel color interpolation method",
3514 "-interword-spacing value",
3515 " set the space between two words",
3516 "-kerning value set the space between two letters",
3517 "-label string assign a label to an image",
3518 "-limit type value pixel cache resource limit",
3519 "-loop iterations add Netscape loop extension to your GIF animation",
3520 "-mask filename associate a mask with the image",
3521 "-mattecolor color frame color",
3522 "-monitor monitor progress",
3523 "-orient type image orientation",
3524 "-page geometry size and location of an image canvas (setting)",
3525 "-ping efficiently determine image attributes",
3526 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003527 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003528 "-preview type image preview type",
3529 "-quality value JPEG/MIFF/PNG compression level",
3530 "-quiet suppress all warning messages",
3531 "-red-primary point chromaticity red primary point",
3532 "-regard-warnings pay attention to warning messages",
3533 "-remap filename transform image colors to match this set of colors",
3534 "-respect-parentheses settings remain in effect until parenthesis boundary",
3535 "-sampling-factor geometry",
3536 " horizontal and vertical sampling factor",
3537 "-scene value image scene number",
3538 "-seed value seed a new sequence of pseudo-random numbers",
3539 "-size geometry width and height of image",
3540 "-stretch type render text with this font stretch",
3541 "-stroke color graphic primitive stroke color",
3542 "-strokewidth value graphic primitive stroke width",
3543 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003544 "-synchronize synchronize image to storage device",
3545 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003546 "-texture filename name of texture to tile onto the image background",
3547 "-tile-offset geometry",
3548 " tile offset",
3549 "-treedepth value color tree depth",
3550 "-transparent-color color",
3551 " transparent color",
3552 "-undercolor color annotation bounding box color",
3553 "-units type the units of image resolution",
3554 "-verbose print detailed information about the image",
3555 "-view FlashPix viewing transforms",
3556 "-virtual-pixel method",
3557 " virtual pixel access method",
3558 "-weight type render text with this font weight",
3559 "-white-point point chromaticity white point",
3560 (char *) NULL
3561 },
3562 *stack_operators[]=
3563 {
anthonyb69c4b32011-03-23 04:37:44 +00003564 "-delete indexes delete the image from the image sequence",
3565 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003566 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003567 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003568 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003569 "-swap indexes swap two images in the image sequence",
3570 (char *) NULL
3571 };
3572
3573 const char
3574 **p;
3575
cristybb503372010-05-27 20:51:26 +00003576 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003577 (void) printf("Copyright: %s\n",GetMagickCopyright());
3578 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003579 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3580 GetClientName());
3581 (void) printf("\nImage Settings:\n");
3582 for (p=settings; *p != (char *) NULL; p++)
3583 (void) printf(" %s\n",*p);
3584 (void) printf("\nImage Operators:\n");
3585 for (p=operators; *p != (char *) NULL; p++)
3586 (void) printf(" %s\n",*p);
3587 (void) printf("\nImage Sequence Operators:\n");
3588 for (p=sequence_operators; *p != (char *) NULL; p++)
3589 (void) printf(" %s\n",*p);
3590 (void) printf("\nImage Stack Operators:\n");
3591 for (p=stack_operators; *p != (char *) NULL; p++)
3592 (void) printf(" %s\n",*p);
3593 (void) printf("\nMiscellaneous Options:\n");
3594 for (p=miscellaneous; *p != (char *) NULL; p++)
3595 (void) printf(" %s\n",*p);
3596 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003597 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003598 (void) printf(
3599 "number. To specify a particular image format, precede the filename\n");
3600 (void) printf(
3601 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3602 (void) printf(
3603 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3604 (void) printf("'-' for standard input or output.\n");
3605 return(MagickFalse);
3606}
3607
3608WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3609 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3610{
3611#define DestroyMogrify() \
3612{ \
3613 if (format != (char *) NULL) \
3614 format=DestroyString(format); \
3615 if (path != (char *) NULL) \
3616 path=DestroyString(path); \
3617 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003618 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003619 argv[i]=DestroyString(argv[i]); \
3620 argv=(char **) RelinquishMagickMemory(argv); \
3621}
3622#define ThrowMogrifyException(asperity,tag,option) \
3623{ \
3624 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3625 option); \
3626 DestroyMogrify(); \
3627 return(MagickFalse); \
3628}
3629#define ThrowMogrifyInvalidArgumentException(option,argument) \
3630{ \
3631 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3632 "InvalidArgument","`%s': %s",argument,option); \
3633 DestroyMogrify(); \
3634 return(MagickFalse); \
3635}
3636
3637 char
3638 *format,
3639 *option,
3640 *path;
3641
3642 Image
3643 *image;
3644
3645 ImageStack
3646 image_stack[MaxImageStackDepth+1];
3647
cristy3ed852e2009-09-05 21:47:34 +00003648 MagickBooleanType
3649 global_colormap;
3650
3651 MagickBooleanType
3652 fire,
cristyebbcfea2011-02-25 02:43:54 +00003653 pend,
3654 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003655
3656 MagickStatusType
3657 status;
3658
cristyebbcfea2011-02-25 02:43:54 +00003659 register ssize_t
3660 i;
3661
3662 ssize_t
3663 j,
3664 k;
3665
cristy3ed852e2009-09-05 21:47:34 +00003666 /*
3667 Set defaults.
3668 */
3669 assert(image_info != (ImageInfo *) NULL);
3670 assert(image_info->signature == MagickSignature);
3671 if (image_info->debug != MagickFalse)
3672 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3673 assert(exception != (ExceptionInfo *) NULL);
3674 if (argc == 2)
3675 {
3676 option=argv[1];
3677 if ((LocaleCompare("version",option+1) == 0) ||
3678 (LocaleCompare("-version",option+1) == 0))
3679 {
cristyb51dff52011-05-19 16:55:47 +00003680 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003681 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003682 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3683 GetMagickCopyright());
3684 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3685 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003686 return(MagickFalse);
3687 }
3688 }
3689 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003690 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003691 format=(char *) NULL;
3692 path=(char *) NULL;
3693 global_colormap=MagickFalse;
3694 k=0;
3695 j=1;
3696 NewImageStack();
3697 option=(char *) NULL;
3698 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003699 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003700 status=MagickTrue;
3701 /*
3702 Parse command line.
3703 */
3704 ReadCommandlLine(argc,&argv);
3705 status=ExpandFilenames(&argc,&argv);
3706 if (status == MagickFalse)
3707 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3708 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003709 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003710 {
3711 option=argv[i];
3712 if (LocaleCompare(option,"(") == 0)
3713 {
3714 FireImageStack(MagickFalse,MagickTrue,pend);
3715 if (k == MaxImageStackDepth)
3716 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3717 option);
3718 PushImageStack();
3719 continue;
3720 }
3721 if (LocaleCompare(option,")") == 0)
3722 {
3723 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3724 if (k == 0)
3725 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3726 PopImageStack();
3727 continue;
3728 }
cristy042ee782011-04-22 18:48:30 +00003729 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003730 {
3731 char
3732 backup_filename[MaxTextExtent],
3733 *filename;
3734
3735 Image
3736 *images;
3737
3738 /*
3739 Option is a file name: begin by reading image from specified file.
3740 */
3741 FireImageStack(MagickFalse,MagickFalse,pend);
3742 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003743 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003744 filename=argv[++i];
3745 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3746 images=ReadImages(image_info,exception);
3747 status&=(images != (Image *) NULL) &&
3748 (exception->severity < ErrorException);
3749 if (images == (Image *) NULL)
3750 continue;
cristydaa76602010-06-30 13:05:11 +00003751 if (format != (char *) NULL)
3752 (void) CopyMagickString(images->filename,images->magick_filename,
3753 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003754 if (path != (char *) NULL)
3755 {
3756 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003757 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003758 path,*DirectorySeparator,filename);
3759 }
3760 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003761 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003762 AppendImageStack(images);
3763 FinalizeImageSettings(image_info,image,MagickFalse);
3764 if (global_colormap != MagickFalse)
3765 {
3766 QuantizeInfo
3767 *quantize_info;
3768
3769 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003770 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003771 quantize_info=DestroyQuantizeInfo(quantize_info);
3772 }
3773 *backup_filename='\0';
3774 if ((LocaleCompare(image->filename,"-") != 0) &&
3775 (IsPathWritable(image->filename) != MagickFalse))
3776 {
cristybb503372010-05-27 20:51:26 +00003777 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003778 i;
3779
3780 /*
3781 Rename image file as backup.
3782 */
3783 (void) CopyMagickString(backup_filename,image->filename,
3784 MaxTextExtent);
3785 for (i=0; i < 6; i++)
3786 {
3787 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3788 if (IsPathAccessible(backup_filename) == MagickFalse)
3789 break;
3790 }
3791 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003792 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003793 *backup_filename='\0';
3794 }
3795 /*
3796 Write transmogrified image to disk.
3797 */
3798 image_info->synchronize=MagickTrue;
3799 status&=WriteImages(image_info,image,image->filename,exception);
3800 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003801 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003802 RemoveAllImageStack();
3803 continue;
3804 }
3805 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3806 switch (*(option+1))
3807 {
3808 case 'a':
3809 {
3810 if (LocaleCompare("adaptive-blur",option+1) == 0)
3811 {
3812 i++;
cristybb503372010-05-27 20:51:26 +00003813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003814 ThrowMogrifyException(OptionError,"MissingArgument",option);
3815 if (IsGeometry(argv[i]) == MagickFalse)
3816 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3817 break;
3818 }
3819 if (LocaleCompare("adaptive-resize",option+1) == 0)
3820 {
3821 i++;
cristybb503372010-05-27 20:51:26 +00003822 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003823 ThrowMogrifyException(OptionError,"MissingArgument",option);
3824 if (IsGeometry(argv[i]) == MagickFalse)
3825 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3826 break;
3827 }
3828 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3829 {
3830 i++;
cristybb503372010-05-27 20:51:26 +00003831 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003832 ThrowMogrifyException(OptionError,"MissingArgument",option);
3833 if (IsGeometry(argv[i]) == MagickFalse)
3834 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3835 break;
3836 }
3837 if (LocaleCompare("affine",option+1) == 0)
3838 {
3839 if (*option == '+')
3840 break;
3841 i++;
cristybb503372010-05-27 20:51:26 +00003842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003843 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003844 break;
3845 }
3846 if (LocaleCompare("alpha",option+1) == 0)
3847 {
cristybb503372010-05-27 20:51:26 +00003848 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003849 type;
3850
3851 if (*option == '+')
3852 break;
3853 i++;
cristybb503372010-05-27 20:51:26 +00003854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003855 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003856 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003857 if (type < 0)
3858 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3859 argv[i]);
3860 break;
3861 }
3862 if (LocaleCompare("annotate",option+1) == 0)
3863 {
3864 if (*option == '+')
3865 break;
3866 i++;
cristybb503372010-05-27 20:51:26 +00003867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003868 ThrowMogrifyException(OptionError,"MissingArgument",option);
3869 if (IsGeometry(argv[i]) == MagickFalse)
3870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003872 ThrowMogrifyException(OptionError,"MissingArgument",option);
3873 i++;
3874 break;
3875 }
3876 if (LocaleCompare("antialias",option+1) == 0)
3877 break;
3878 if (LocaleCompare("append",option+1) == 0)
3879 break;
3880 if (LocaleCompare("attenuate",option+1) == 0)
3881 {
3882 if (*option == '+')
3883 break;
3884 i++;
cristybb503372010-05-27 20:51:26 +00003885 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003886 ThrowMogrifyException(OptionError,"MissingArgument",option);
3887 if (IsGeometry(argv[i]) == MagickFalse)
3888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3889 break;
3890 }
3891 if (LocaleCompare("authenticate",option+1) == 0)
3892 {
3893 if (*option == '+')
3894 break;
3895 i++;
cristybb503372010-05-27 20:51:26 +00003896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003897 ThrowMogrifyException(OptionError,"MissingArgument",option);
3898 break;
3899 }
3900 if (LocaleCompare("auto-gamma",option+1) == 0)
3901 break;
3902 if (LocaleCompare("auto-level",option+1) == 0)
3903 break;
3904 if (LocaleCompare("auto-orient",option+1) == 0)
3905 break;
3906 if (LocaleCompare("average",option+1) == 0)
3907 break;
3908 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3909 }
3910 case 'b':
3911 {
3912 if (LocaleCompare("background",option+1) == 0)
3913 {
3914 if (*option == '+')
3915 break;
3916 i++;
cristybb503372010-05-27 20:51:26 +00003917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003918 ThrowMogrifyException(OptionError,"MissingArgument",option);
3919 break;
3920 }
3921 if (LocaleCompare("bias",option+1) == 0)
3922 {
3923 if (*option == '+')
3924 break;
3925 i++;
cristybb503372010-05-27 20:51:26 +00003926 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003927 ThrowMogrifyException(OptionError,"MissingArgument",option);
3928 if (IsGeometry(argv[i]) == MagickFalse)
3929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3930 break;
3931 }
3932 if (LocaleCompare("black-point-compensation",option+1) == 0)
3933 break;
3934 if (LocaleCompare("black-threshold",option+1) == 0)
3935 {
3936 if (*option == '+')
3937 break;
3938 i++;
cristybb503372010-05-27 20:51:26 +00003939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003940 ThrowMogrifyException(OptionError,"MissingArgument",option);
3941 if (IsGeometry(argv[i]) == MagickFalse)
3942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3943 break;
3944 }
3945 if (LocaleCompare("blue-primary",option+1) == 0)
3946 {
3947 if (*option == '+')
3948 break;
3949 i++;
cristybb503372010-05-27 20:51:26 +00003950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003951 ThrowMogrifyException(OptionError,"MissingArgument",option);
3952 if (IsGeometry(argv[i]) == MagickFalse)
3953 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3954 break;
3955 }
3956 if (LocaleCompare("blue-shift",option+1) == 0)
3957 {
3958 i++;
cristybb503372010-05-27 20:51:26 +00003959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003960 ThrowMogrifyException(OptionError,"MissingArgument",option);
3961 if (IsGeometry(argv[i]) == MagickFalse)
3962 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3963 break;
3964 }
3965 if (LocaleCompare("blur",option+1) == 0)
3966 {
3967 i++;
cristybb503372010-05-27 20:51:26 +00003968 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003969 ThrowMogrifyException(OptionError,"MissingArgument",option);
3970 if (IsGeometry(argv[i]) == MagickFalse)
3971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3972 break;
3973 }
3974 if (LocaleCompare("border",option+1) == 0)
3975 {
3976 if (*option == '+')
3977 break;
3978 i++;
cristybb503372010-05-27 20:51:26 +00003979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003980 ThrowMogrifyException(OptionError,"MissingArgument",option);
3981 if (IsGeometry(argv[i]) == MagickFalse)
3982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3983 break;
3984 }
3985 if (LocaleCompare("bordercolor",option+1) == 0)
3986 {
3987 if (*option == '+')
3988 break;
3989 i++;
cristybb503372010-05-27 20:51:26 +00003990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003991 ThrowMogrifyException(OptionError,"MissingArgument",option);
3992 break;
3993 }
3994 if (LocaleCompare("box",option+1) == 0)
3995 {
3996 if (*option == '+')
3997 break;
3998 i++;
cristybb503372010-05-27 20:51:26 +00003999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004000 ThrowMogrifyException(OptionError,"MissingArgument",option);
4001 break;
4002 }
cristya28d6b82010-01-11 20:03:47 +00004003 if (LocaleCompare("brightness-contrast",option+1) == 0)
4004 {
4005 i++;
cristybb503372010-05-27 20:51:26 +00004006 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004007 ThrowMogrifyException(OptionError,"MissingArgument",option);
4008 if (IsGeometry(argv[i]) == MagickFalse)
4009 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4010 break;
4011 }
cristy3ed852e2009-09-05 21:47:34 +00004012 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4013 }
4014 case 'c':
4015 {
4016 if (LocaleCompare("cache",option+1) == 0)
4017 {
4018 if (*option == '+')
4019 break;
4020 i++;
cristybb503372010-05-27 20:51:26 +00004021 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004022 ThrowMogrifyException(OptionError,"MissingArgument",option);
4023 if (IsGeometry(argv[i]) == MagickFalse)
4024 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4025 break;
4026 }
4027 if (LocaleCompare("caption",option+1) == 0)
4028 {
4029 if (*option == '+')
4030 break;
4031 i++;
cristybb503372010-05-27 20:51:26 +00004032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004033 ThrowMogrifyException(OptionError,"MissingArgument",option);
4034 break;
4035 }
4036 if (LocaleCompare("channel",option+1) == 0)
4037 {
cristybb503372010-05-27 20:51:26 +00004038 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004039 channel;
4040
4041 if (*option == '+')
4042 break;
4043 i++;
cristybb503372010-05-27 20:51:26 +00004044 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004045 ThrowMogrifyException(OptionError,"MissingArgument",option);
4046 channel=ParseChannelOption(argv[i]);
4047 if (channel < 0)
4048 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4049 argv[i]);
4050 break;
4051 }
4052 if (LocaleCompare("cdl",option+1) == 0)
4053 {
4054 if (*option == '+')
4055 break;
4056 i++;
cristybb503372010-05-27 20:51:26 +00004057 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004058 ThrowMogrifyException(OptionError,"MissingArgument",option);
4059 break;
4060 }
4061 if (LocaleCompare("charcoal",option+1) == 0)
4062 {
4063 if (*option == '+')
4064 break;
4065 i++;
cristybb503372010-05-27 20:51:26 +00004066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004067 ThrowMogrifyException(OptionError,"MissingArgument",option);
4068 if (IsGeometry(argv[i]) == MagickFalse)
4069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4070 break;
4071 }
4072 if (LocaleCompare("chop",option+1) == 0)
4073 {
4074 if (*option == '+')
4075 break;
4076 i++;
cristybb503372010-05-27 20:51:26 +00004077 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004078 ThrowMogrifyException(OptionError,"MissingArgument",option);
4079 if (IsGeometry(argv[i]) == MagickFalse)
4080 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4081 break;
4082 }
cristy1eb45dd2009-09-25 16:38:06 +00004083 if (LocaleCompare("clamp",option+1) == 0)
4084 break;
4085 if (LocaleCompare("clip",option+1) == 0)
4086 break;
cristy3ed852e2009-09-05 21:47:34 +00004087 if (LocaleCompare("clip-mask",option+1) == 0)
4088 {
4089 if (*option == '+')
4090 break;
4091 i++;
cristybb503372010-05-27 20:51:26 +00004092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004093 ThrowMogrifyException(OptionError,"MissingArgument",option);
4094 break;
4095 }
4096 if (LocaleCompare("clut",option+1) == 0)
4097 break;
4098 if (LocaleCompare("coalesce",option+1) == 0)
4099 break;
4100 if (LocaleCompare("colorize",option+1) == 0)
4101 {
4102 if (*option == '+')
4103 break;
4104 i++;
cristybb503372010-05-27 20:51:26 +00004105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004106 ThrowMogrifyException(OptionError,"MissingArgument",option);
4107 if (IsGeometry(argv[i]) == MagickFalse)
4108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4109 break;
4110 }
cristye6365592010-04-02 17:31:23 +00004111 if (LocaleCompare("color-matrix",option+1) == 0)
4112 {
cristyb6bd4ad2010-08-08 01:12:27 +00004113 KernelInfo
4114 *kernel_info;
4115
cristye6365592010-04-02 17:31:23 +00004116 if (*option == '+')
4117 break;
4118 i++;
cristybb503372010-05-27 20:51:26 +00004119 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004120 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004121 kernel_info=AcquireKernelInfo(argv[i]);
4122 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004124 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004125 break;
4126 }
cristy3ed852e2009-09-05 21:47:34 +00004127 if (LocaleCompare("colors",option+1) == 0)
4128 {
4129 if (*option == '+')
4130 break;
4131 i++;
cristybb503372010-05-27 20:51:26 +00004132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004133 ThrowMogrifyException(OptionError,"MissingArgument",option);
4134 if (IsGeometry(argv[i]) == MagickFalse)
4135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4136 break;
4137 }
4138 if (LocaleCompare("colorspace",option+1) == 0)
4139 {
cristybb503372010-05-27 20:51:26 +00004140 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004141 colorspace;
4142
4143 if (*option == '+')
4144 break;
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004148 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004149 argv[i]);
4150 if (colorspace < 0)
4151 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4152 argv[i]);
4153 break;
4154 }
4155 if (LocaleCompare("combine",option+1) == 0)
4156 break;
4157 if (LocaleCompare("comment",option+1) == 0)
4158 {
4159 if (*option == '+')
4160 break;
4161 i++;
cristybb503372010-05-27 20:51:26 +00004162 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004163 ThrowMogrifyException(OptionError,"MissingArgument",option);
4164 break;
4165 }
4166 if (LocaleCompare("composite",option+1) == 0)
4167 break;
4168 if (LocaleCompare("compress",option+1) == 0)
4169 {
cristybb503372010-05-27 20:51:26 +00004170 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004171 compress;
4172
4173 if (*option == '+')
4174 break;
4175 i++;
cristybb503372010-05-27 20:51:26 +00004176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004177 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004178 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004179 argv[i]);
4180 if (compress < 0)
4181 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4182 argv[i]);
4183 break;
4184 }
cristy22879752009-10-25 23:55:40 +00004185 if (LocaleCompare("concurrent",option+1) == 0)
4186 break;
cristy3ed852e2009-09-05 21:47:34 +00004187 if (LocaleCompare("contrast",option+1) == 0)
4188 break;
4189 if (LocaleCompare("contrast-stretch",option+1) == 0)
4190 {
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
4194 if (IsGeometry(argv[i]) == MagickFalse)
4195 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4196 break;
4197 }
4198 if (LocaleCompare("convolve",option+1) == 0)
4199 {
cristyb6bd4ad2010-08-08 01:12:27 +00004200 KernelInfo
4201 *kernel_info;
4202
cristy3ed852e2009-09-05 21:47:34 +00004203 if (*option == '+')
4204 break;
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004208 kernel_info=AcquireKernelInfo(argv[i]);
4209 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004210 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004211 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004212 break;
4213 }
4214 if (LocaleCompare("crop",option+1) == 0)
4215 {
4216 if (*option == '+')
4217 break;
4218 i++;
cristybb503372010-05-27 20:51:26 +00004219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004220 ThrowMogrifyException(OptionError,"MissingArgument",option);
4221 if (IsGeometry(argv[i]) == MagickFalse)
4222 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4223 break;
4224 }
4225 if (LocaleCompare("cycle",option+1) == 0)
4226 {
4227 if (*option == '+')
4228 break;
4229 i++;
cristybb503372010-05-27 20:51:26 +00004230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004231 ThrowMogrifyException(OptionError,"MissingArgument",option);
4232 if (IsGeometry(argv[i]) == MagickFalse)
4233 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4234 break;
4235 }
4236 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4237 }
4238 case 'd':
4239 {
4240 if (LocaleCompare("decipher",option+1) == 0)
4241 {
4242 if (*option == '+')
4243 break;
4244 i++;
cristybb503372010-05-27 20:51:26 +00004245 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004246 ThrowMogrifyException(OptionError,"MissingArgument",option);
4247 break;
4248 }
4249 if (LocaleCompare("deconstruct",option+1) == 0)
4250 break;
4251 if (LocaleCompare("debug",option+1) == 0)
4252 {
cristybb503372010-05-27 20:51:26 +00004253 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004254 event;
4255
4256 if (*option == '+')
4257 break;
4258 i++;
cristybb503372010-05-27 20:51:26 +00004259 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004260 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004261 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004262 if (event < 0)
4263 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4264 argv[i]);
4265 (void) SetLogEventMask(argv[i]);
4266 break;
4267 }
4268 if (LocaleCompare("define",option+1) == 0)
4269 {
4270 i++;
cristybb503372010-05-27 20:51:26 +00004271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004272 ThrowMogrifyException(OptionError,"MissingArgument",option);
4273 if (*option == '+')
4274 {
4275 const char
4276 *define;
4277
4278 define=GetImageOption(image_info,argv[i]);
4279 if (define == (const char *) NULL)
4280 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4281 break;
4282 }
4283 break;
4284 }
4285 if (LocaleCompare("delay",option+1) == 0)
4286 {
4287 if (*option == '+')
4288 break;
4289 i++;
cristybb503372010-05-27 20:51:26 +00004290 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004291 ThrowMogrifyException(OptionError,"MissingArgument",option);
4292 if (IsGeometry(argv[i]) == MagickFalse)
4293 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4294 break;
4295 }
cristyecb10ff2011-03-22 13:14:03 +00004296 if (LocaleCompare("delete",option+1) == 0)
4297 {
4298 if (*option == '+')
4299 break;
4300 i++;
4301 if (i == (ssize_t) (argc-1))
4302 ThrowMogrifyException(OptionError,"MissingArgument",option);
4303 if (IsGeometry(argv[i]) == MagickFalse)
4304 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4305 break;
4306 }
cristy3ed852e2009-09-05 21:47:34 +00004307 if (LocaleCompare("density",option+1) == 0)
4308 {
4309 if (*option == '+')
4310 break;
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 if (IsGeometry(argv[i]) == MagickFalse)
4315 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4316 break;
4317 }
4318 if (LocaleCompare("depth",option+1) == 0)
4319 {
4320 if (*option == '+')
4321 break;
4322 i++;
cristybb503372010-05-27 20:51:26 +00004323 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004324 ThrowMogrifyException(OptionError,"MissingArgument",option);
4325 if (IsGeometry(argv[i]) == MagickFalse)
4326 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4327 break;
4328 }
4329 if (LocaleCompare("deskew",option+1) == 0)
4330 {
4331 if (*option == '+')
4332 break;
4333 i++;
cristybb503372010-05-27 20:51:26 +00004334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004335 ThrowMogrifyException(OptionError,"MissingArgument",option);
4336 if (IsGeometry(argv[i]) == MagickFalse)
4337 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4338 break;
4339 }
4340 if (LocaleCompare("despeckle",option+1) == 0)
4341 break;
4342 if (LocaleCompare("dft",option+1) == 0)
4343 break;
cristyc9b12952010-03-28 01:12:28 +00004344 if (LocaleCompare("direction",option+1) == 0)
4345 {
cristybb503372010-05-27 20:51:26 +00004346 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004347 direction;
4348
4349 if (*option == '+')
4350 break;
4351 i++;
cristybb503372010-05-27 20:51:26 +00004352 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004353 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004354 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004355 argv[i]);
4356 if (direction < 0)
4357 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4358 argv[i]);
4359 break;
4360 }
cristy3ed852e2009-09-05 21:47:34 +00004361 if (LocaleCompare("display",option+1) == 0)
4362 {
4363 if (*option == '+')
4364 break;
4365 i++;
cristybb503372010-05-27 20:51:26 +00004366 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004367 ThrowMogrifyException(OptionError,"MissingArgument",option);
4368 break;
4369 }
4370 if (LocaleCompare("dispose",option+1) == 0)
4371 {
cristybb503372010-05-27 20:51:26 +00004372 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004373 dispose;
4374
4375 if (*option == '+')
4376 break;
4377 i++;
cristybb503372010-05-27 20:51:26 +00004378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004379 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004380 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004381 if (dispose < 0)
4382 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4383 argv[i]);
4384 break;
4385 }
4386 if (LocaleCompare("distort",option+1) == 0)
4387 {
cristybb503372010-05-27 20:51:26 +00004388 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004389 op;
4390
4391 i++;
cristybb503372010-05-27 20:51:26 +00004392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004393 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004394 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004395 if (op < 0)
4396 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4397 argv[i]);
4398 i++;
cristybb503372010-05-27 20:51:26 +00004399 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004400 ThrowMogrifyException(OptionError,"MissingArgument",option);
4401 break;
4402 }
4403 if (LocaleCompare("dither",option+1) == 0)
4404 {
cristybb503372010-05-27 20:51:26 +00004405 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004406 method;
4407
4408 if (*option == '+')
4409 break;
4410 i++;
cristybb503372010-05-27 20:51:26 +00004411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004412 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004413 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004414 if (method < 0)
4415 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4416 argv[i]);
4417 break;
4418 }
4419 if (LocaleCompare("draw",option+1) == 0)
4420 {
4421 if (*option == '+')
4422 break;
4423 i++;
cristybb503372010-05-27 20:51:26 +00004424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004425 ThrowMogrifyException(OptionError,"MissingArgument",option);
4426 break;
4427 }
cristyecb10ff2011-03-22 13:14:03 +00004428 if (LocaleCompare("duplicate",option+1) == 0)
4429 {
4430 if (*option == '+')
4431 break;
4432 i++;
4433 if (i == (ssize_t) (argc-1))
4434 ThrowMogrifyException(OptionError,"MissingArgument",option);
4435 if (IsGeometry(argv[i]) == MagickFalse)
4436 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4437 break;
4438 }
cristy22879752009-10-25 23:55:40 +00004439 if (LocaleCompare("duration",option+1) == 0)
4440 {
4441 if (*option == '+')
4442 break;
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
4446 if (IsGeometry(argv[i]) == MagickFalse)
4447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4448 break;
4449 }
cristy3ed852e2009-09-05 21:47:34 +00004450 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4451 }
4452 case 'e':
4453 {
4454 if (LocaleCompare("edge",option+1) == 0)
4455 {
4456 if (*option == '+')
4457 break;
4458 i++;
cristybb503372010-05-27 20:51:26 +00004459 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004460 ThrowMogrifyException(OptionError,"MissingArgument",option);
4461 if (IsGeometry(argv[i]) == MagickFalse)
4462 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4463 break;
4464 }
4465 if (LocaleCompare("emboss",option+1) == 0)
4466 {
4467 if (*option == '+')
4468 break;
4469 i++;
cristybb503372010-05-27 20:51:26 +00004470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004471 ThrowMogrifyException(OptionError,"MissingArgument",option);
4472 if (IsGeometry(argv[i]) == MagickFalse)
4473 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4474 break;
4475 }
4476 if (LocaleCompare("encipher",option+1) == 0)
4477 {
4478 if (*option == '+')
4479 break;
4480 i++;
cristybb503372010-05-27 20:51:26 +00004481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004482 ThrowMogrifyException(OptionError,"MissingArgument",option);
4483 break;
4484 }
4485 if (LocaleCompare("encoding",option+1) == 0)
4486 {
4487 if (*option == '+')
4488 break;
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 break;
4493 }
4494 if (LocaleCompare("endian",option+1) == 0)
4495 {
cristybb503372010-05-27 20:51:26 +00004496 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004497 endian;
4498
4499 if (*option == '+')
4500 break;
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004504 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004505 if (endian < 0)
4506 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4507 argv[i]);
4508 break;
4509 }
4510 if (LocaleCompare("enhance",option+1) == 0)
4511 break;
4512 if (LocaleCompare("equalize",option+1) == 0)
4513 break;
4514 if (LocaleCompare("evaluate",option+1) == 0)
4515 {
cristybb503372010-05-27 20:51:26 +00004516 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004517 op;
4518
4519 if (*option == '+')
4520 break;
4521 i++;
cristybb503372010-05-27 20:51:26 +00004522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004523 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004524 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004525 if (op < 0)
4526 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4527 argv[i]);
4528 i++;
cristybb503372010-05-27 20:51:26 +00004529 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004530 ThrowMogrifyException(OptionError,"MissingArgument",option);
4531 if (IsGeometry(argv[i]) == MagickFalse)
4532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4533 break;
4534 }
cristyd18ae7c2010-03-07 17:39:52 +00004535 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4536 {
cristybb503372010-05-27 20:51:26 +00004537 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004538 op;
4539
4540 if (*option == '+')
4541 break;
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004545 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004546 if (op < 0)
4547 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4548 argv[i]);
4549 break;
4550 }
cristy3ed852e2009-09-05 21:47:34 +00004551 if (LocaleCompare("extent",option+1) == 0)
4552 {
4553 if (*option == '+')
4554 break;
4555 i++;
cristybb503372010-05-27 20:51:26 +00004556 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004557 ThrowMogrifyException(OptionError,"MissingArgument",option);
4558 if (IsGeometry(argv[i]) == MagickFalse)
4559 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4560 break;
4561 }
4562 if (LocaleCompare("extract",option+1) == 0)
4563 {
4564 if (*option == '+')
4565 break;
4566 i++;
cristybb503372010-05-27 20:51:26 +00004567 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004568 ThrowMogrifyException(OptionError,"MissingArgument",option);
4569 if (IsGeometry(argv[i]) == MagickFalse)
4570 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4571 break;
4572 }
4573 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4574 }
4575 case 'f':
4576 {
4577 if (LocaleCompare("family",option+1) == 0)
4578 {
4579 if (*option == '+')
4580 break;
4581 i++;
cristybb503372010-05-27 20:51:26 +00004582 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004583 ThrowMogrifyException(OptionError,"MissingArgument",option);
4584 break;
4585 }
4586 if (LocaleCompare("fill",option+1) == 0)
4587 {
4588 if (*option == '+')
4589 break;
4590 i++;
cristybb503372010-05-27 20:51:26 +00004591 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004592 ThrowMogrifyException(OptionError,"MissingArgument",option);
4593 break;
4594 }
4595 if (LocaleCompare("filter",option+1) == 0)
4596 {
cristybb503372010-05-27 20:51:26 +00004597 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004598 filter;
4599
4600 if (*option == '+')
4601 break;
4602 i++;
cristybb503372010-05-27 20:51:26 +00004603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004604 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004605 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004606 if (filter < 0)
4607 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4608 argv[i]);
4609 break;
4610 }
4611 if (LocaleCompare("flatten",option+1) == 0)
4612 break;
4613 if (LocaleCompare("flip",option+1) == 0)
4614 break;
4615 if (LocaleCompare("flop",option+1) == 0)
4616 break;
4617 if (LocaleCompare("floodfill",option+1) == 0)
4618 {
4619 if (*option == '+')
4620 break;
4621 i++;
cristybb503372010-05-27 20:51:26 +00004622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004623 ThrowMogrifyException(OptionError,"MissingArgument",option);
4624 if (IsGeometry(argv[i]) == MagickFalse)
4625 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4626 i++;
cristybb503372010-05-27 20:51:26 +00004627 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004628 ThrowMogrifyException(OptionError,"MissingArgument",option);
4629 break;
4630 }
4631 if (LocaleCompare("font",option+1) == 0)
4632 {
4633 if (*option == '+')
4634 break;
4635 i++;
cristybb503372010-05-27 20:51:26 +00004636 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004637 ThrowMogrifyException(OptionError,"MissingArgument",option);
4638 break;
4639 }
4640 if (LocaleCompare("format",option+1) == 0)
4641 {
4642 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4643 (void) CloneString(&format,(char *) NULL);
4644 if (*option == '+')
4645 break;
4646 i++;
cristybb503372010-05-27 20:51:26 +00004647 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004648 ThrowMogrifyException(OptionError,"MissingArgument",option);
4649 (void) CloneString(&format,argv[i]);
4650 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4651 (void) ConcatenateMagickString(image_info->filename,":",
4652 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004653 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004654 if (*image_info->magick == '\0')
4655 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4656 format);
4657 break;
4658 }
4659 if (LocaleCompare("frame",option+1) == 0)
4660 {
4661 if (*option == '+')
4662 break;
4663 i++;
cristybb503372010-05-27 20:51:26 +00004664 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004665 ThrowMogrifyException(OptionError,"MissingArgument",option);
4666 if (IsGeometry(argv[i]) == MagickFalse)
4667 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4668 break;
4669 }
4670 if (LocaleCompare("function",option+1) == 0)
4671 {
cristybb503372010-05-27 20:51:26 +00004672 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004673 op;
4674
4675 if (*option == '+')
4676 break;
4677 i++;
cristybb503372010-05-27 20:51:26 +00004678 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004679 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004680 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004681 if (op < 0)
4682 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4683 i++;
cristybb503372010-05-27 20:51:26 +00004684 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004685 ThrowMogrifyException(OptionError,"MissingArgument",option);
4686 break;
4687 }
4688 if (LocaleCompare("fuzz",option+1) == 0)
4689 {
4690 if (*option == '+')
4691 break;
4692 i++;
cristybb503372010-05-27 20:51:26 +00004693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004694 ThrowMogrifyException(OptionError,"MissingArgument",option);
4695 if (IsGeometry(argv[i]) == MagickFalse)
4696 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4697 break;
4698 }
4699 if (LocaleCompare("fx",option+1) == 0)
4700 {
4701 if (*option == '+')
4702 break;
4703 i++;
cristybb503372010-05-27 20:51:26 +00004704 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004705 ThrowMogrifyException(OptionError,"MissingArgument",option);
4706 break;
4707 }
4708 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4709 }
4710 case 'g':
4711 {
4712 if (LocaleCompare("gamma",option+1) == 0)
4713 {
4714 i++;
cristybb503372010-05-27 20:51:26 +00004715 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004716 ThrowMogrifyException(OptionError,"MissingArgument",option);
4717 if (IsGeometry(argv[i]) == MagickFalse)
4718 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4719 break;
4720 }
4721 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4722 (LocaleCompare("gaussian",option+1) == 0))
4723 {
4724 i++;
cristybb503372010-05-27 20:51:26 +00004725 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004726 ThrowMogrifyException(OptionError,"MissingArgument",option);
4727 if (IsGeometry(argv[i]) == MagickFalse)
4728 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4729 break;
4730 }
4731 if (LocaleCompare("geometry",option+1) == 0)
4732 {
4733 if (*option == '+')
4734 break;
4735 i++;
cristybb503372010-05-27 20:51:26 +00004736 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004737 ThrowMogrifyException(OptionError,"MissingArgument",option);
4738 if (IsGeometry(argv[i]) == MagickFalse)
4739 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4740 break;
4741 }
4742 if (LocaleCompare("gravity",option+1) == 0)
4743 {
cristybb503372010-05-27 20:51:26 +00004744 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004745 gravity;
4746
4747 if (*option == '+')
4748 break;
4749 i++;
cristybb503372010-05-27 20:51:26 +00004750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004751 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004752 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004753 if (gravity < 0)
4754 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4755 argv[i]);
4756 break;
4757 }
4758 if (LocaleCompare("green-primary",option+1) == 0)
4759 {
4760 if (*option == '+')
4761 break;
4762 i++;
cristybb503372010-05-27 20:51:26 +00004763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004764 ThrowMogrifyException(OptionError,"MissingArgument",option);
4765 if (IsGeometry(argv[i]) == MagickFalse)
4766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4767 break;
4768 }
4769 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4770 }
4771 case 'h':
4772 {
4773 if (LocaleCompare("hald-clut",option+1) == 0)
4774 break;
4775 if ((LocaleCompare("help",option+1) == 0) ||
4776 (LocaleCompare("-help",option+1) == 0))
4777 return(MogrifyUsage());
4778 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4779 }
4780 case 'i':
4781 {
4782 if (LocaleCompare("identify",option+1) == 0)
4783 break;
4784 if (LocaleCompare("idft",option+1) == 0)
4785 break;
4786 if (LocaleCompare("implode",option+1) == 0)
4787 {
4788 if (*option == '+')
4789 break;
4790 i++;
cristybb503372010-05-27 20:51:26 +00004791 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004792 ThrowMogrifyException(OptionError,"MissingArgument",option);
4793 if (IsGeometry(argv[i]) == MagickFalse)
4794 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4795 break;
4796 }
4797 if (LocaleCompare("intent",option+1) == 0)
4798 {
cristybb503372010-05-27 20:51:26 +00004799 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004800 intent;
4801
4802 if (*option == '+')
4803 break;
4804 i++;
cristybb503372010-05-27 20:51:26 +00004805 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004806 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004807 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004808 if (intent < 0)
4809 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4810 argv[i]);
4811 break;
4812 }
4813 if (LocaleCompare("interlace",option+1) == 0)
4814 {
cristybb503372010-05-27 20:51:26 +00004815 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004816 interlace;
4817
4818 if (*option == '+')
4819 break;
4820 i++;
cristybb503372010-05-27 20:51:26 +00004821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004822 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004823 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004824 argv[i]);
4825 if (interlace < 0)
4826 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4827 argv[i]);
4828 break;
4829 }
cristyb32b90a2009-09-07 21:45:48 +00004830 if (LocaleCompare("interline-spacing",option+1) == 0)
4831 {
4832 if (*option == '+')
4833 break;
4834 i++;
cristybb503372010-05-27 20:51:26 +00004835 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004836 ThrowMogrifyException(OptionError,"MissingArgument",option);
4837 if (IsGeometry(argv[i]) == MagickFalse)
4838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4839 break;
4840 }
cristy3ed852e2009-09-05 21:47:34 +00004841 if (LocaleCompare("interpolate",option+1) == 0)
4842 {
cristybb503372010-05-27 20:51:26 +00004843 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004844 interpolate;
4845
4846 if (*option == '+')
4847 break;
4848 i++;
cristybb503372010-05-27 20:51:26 +00004849 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004850 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004851 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004852 argv[i]);
4853 if (interpolate < 0)
4854 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4855 argv[i]);
4856 break;
4857 }
4858 if (LocaleCompare("interword-spacing",option+1) == 0)
4859 {
4860 if (*option == '+')
4861 break;
4862 i++;
cristybb503372010-05-27 20:51:26 +00004863 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004864 ThrowMogrifyException(OptionError,"MissingArgument",option);
4865 if (IsGeometry(argv[i]) == MagickFalse)
4866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4867 break;
4868 }
4869 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4870 }
4871 case 'k':
4872 {
4873 if (LocaleCompare("kerning",option+1) == 0)
4874 {
4875 if (*option == '+')
4876 break;
4877 i++;
cristybb503372010-05-27 20:51:26 +00004878 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004879 ThrowMogrifyException(OptionError,"MissingArgument",option);
4880 if (IsGeometry(argv[i]) == MagickFalse)
4881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4882 break;
4883 }
4884 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4885 }
4886 case 'l':
4887 {
4888 if (LocaleCompare("label",option+1) == 0)
4889 {
4890 if (*option == '+')
4891 break;
4892 i++;
cristybb503372010-05-27 20:51:26 +00004893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004894 ThrowMogrifyException(OptionError,"MissingArgument",option);
4895 break;
4896 }
4897 if (LocaleCompare("lat",option+1) == 0)
4898 {
4899 if (*option == '+')
4900 break;
4901 i++;
cristybb503372010-05-27 20:51:26 +00004902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004903 ThrowMogrifyException(OptionError,"MissingArgument",option);
4904 if (IsGeometry(argv[i]) == MagickFalse)
4905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4906 }
4907 if (LocaleCompare("layers",option+1) == 0)
4908 {
cristybb503372010-05-27 20:51:26 +00004909 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004910 type;
4911
4912 if (*option == '+')
4913 break;
4914 i++;
cristybb503372010-05-27 20:51:26 +00004915 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004916 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004917 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004918 if (type < 0)
4919 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4920 argv[i]);
4921 break;
4922 }
4923 if (LocaleCompare("level",option+1) == 0)
4924 {
4925 i++;
cristybb503372010-05-27 20:51:26 +00004926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004927 ThrowMogrifyException(OptionError,"MissingArgument",option);
4928 if (IsGeometry(argv[i]) == MagickFalse)
4929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4930 break;
4931 }
4932 if (LocaleCompare("level-colors",option+1) == 0)
4933 {
4934 i++;
cristybb503372010-05-27 20:51:26 +00004935 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004936 ThrowMogrifyException(OptionError,"MissingArgument",option);
4937 break;
4938 }
cristy3ed852e2009-09-05 21:47:34 +00004939 if (LocaleCompare("limit",option+1) == 0)
4940 {
4941 char
4942 *p;
4943
4944 double
4945 value;
4946
cristybb503372010-05-27 20:51:26 +00004947 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004948 resource;
4949
4950 if (*option == '+')
4951 break;
4952 i++;
cristybb503372010-05-27 20:51:26 +00004953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004954 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004955 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004956 argv[i]);
4957 if (resource < 0)
4958 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4959 argv[i]);
4960 i++;
cristybb503372010-05-27 20:51:26 +00004961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004962 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004963 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004964 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004965 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4967 break;
4968 }
4969 if (LocaleCompare("liquid-rescale",option+1) == 0)
4970 {
4971 i++;
cristybb503372010-05-27 20:51:26 +00004972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004973 ThrowMogrifyException(OptionError,"MissingArgument",option);
4974 if (IsGeometry(argv[i]) == MagickFalse)
4975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4976 break;
4977 }
4978 if (LocaleCompare("list",option+1) == 0)
4979 {
cristybb503372010-05-27 20:51:26 +00004980 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004981 list;
4982
4983 if (*option == '+')
4984 break;
4985 i++;
cristybb503372010-05-27 20:51:26 +00004986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004987 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004988 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004989 if (list < 0)
4990 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004991 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004992 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004993 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004994 }
4995 if (LocaleCompare("log",option+1) == 0)
4996 {
4997 if (*option == '+')
4998 break;
4999 i++;
cristybb503372010-05-27 20:51:26 +00005000 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005001 (strchr(argv[i],'%') == (char *) NULL))
5002 ThrowMogrifyException(OptionError,"MissingArgument",option);
5003 break;
5004 }
5005 if (LocaleCompare("loop",option+1) == 0)
5006 {
5007 if (*option == '+')
5008 break;
5009 i++;
cristybb503372010-05-27 20:51:26 +00005010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005011 ThrowMogrifyException(OptionError,"MissingArgument",option);
5012 if (IsGeometry(argv[i]) == MagickFalse)
5013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5014 break;
5015 }
5016 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5017 }
5018 case 'm':
5019 {
5020 if (LocaleCompare("map",option+1) == 0)
5021 {
5022 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5023 if (*option == '+')
5024 break;
5025 i++;
cristybb503372010-05-27 20:51:26 +00005026 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005027 ThrowMogrifyException(OptionError,"MissingArgument",option);
5028 break;
5029 }
5030 if (LocaleCompare("mask",option+1) == 0)
5031 {
5032 if (*option == '+')
5033 break;
5034 i++;
cristybb503372010-05-27 20:51:26 +00005035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005036 ThrowMogrifyException(OptionError,"MissingArgument",option);
5037 break;
5038 }
5039 if (LocaleCompare("matte",option+1) == 0)
5040 break;
5041 if (LocaleCompare("mattecolor",option+1) == 0)
5042 {
5043 if (*option == '+')
5044 break;
5045 i++;
cristybb503372010-05-27 20:51:26 +00005046 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005047 ThrowMogrifyException(OptionError,"MissingArgument",option);
5048 break;
5049 }
cristyf40785b2010-03-06 02:27:27 +00005050 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005051 break;
cristyf40785b2010-03-06 02:27:27 +00005052 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005053 break;
cristy3ed852e2009-09-05 21:47:34 +00005054 if (LocaleCompare("modulate",option+1) == 0)
5055 {
5056 if (*option == '+')
5057 break;
5058 i++;
cristybb503372010-05-27 20:51:26 +00005059 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005060 ThrowMogrifyException(OptionError,"MissingArgument",option);
5061 if (IsGeometry(argv[i]) == MagickFalse)
5062 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5063 break;
5064 }
5065 if (LocaleCompare("median",option+1) == 0)
5066 {
5067 if (*option == '+')
5068 break;
5069 i++;
cristybb503372010-05-27 20:51:26 +00005070 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005071 ThrowMogrifyException(OptionError,"MissingArgument",option);
5072 if (IsGeometry(argv[i]) == MagickFalse)
5073 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5074 break;
5075 }
cristy69ec32d2011-02-27 23:57:09 +00005076 if (LocaleCompare("mode",option+1) == 0)
5077 {
5078 if (*option == '+')
5079 break;
5080 i++;
5081 if (i == (ssize_t) argc)
5082 ThrowMogrifyException(OptionError,"MissingArgument",option);
5083 if (IsGeometry(argv[i]) == MagickFalse)
5084 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5085 break;
5086 }
cristy3ed852e2009-09-05 21:47:34 +00005087 if (LocaleCompare("monitor",option+1) == 0)
5088 break;
5089 if (LocaleCompare("monochrome",option+1) == 0)
5090 break;
5091 if (LocaleCompare("morph",option+1) == 0)
5092 {
5093 if (*option == '+')
5094 break;
5095 i++;
cristybb503372010-05-27 20:51:26 +00005096 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005097 ThrowMogrifyException(OptionError,"MissingArgument",option);
5098 if (IsGeometry(argv[i]) == MagickFalse)
5099 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5100 break;
5101 }
anthony29188a82010-01-22 10:12:34 +00005102 if (LocaleCompare("morphology",option+1) == 0)
5103 {
anthony29188a82010-01-22 10:12:34 +00005104 char
5105 token[MaxTextExtent];
5106
cristyb6bd4ad2010-08-08 01:12:27 +00005107 KernelInfo
5108 *kernel_info;
5109
5110 ssize_t
5111 op;
5112
anthony29188a82010-01-22 10:12:34 +00005113 i++;
cristybb503372010-05-27 20:51:26 +00005114 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005115 ThrowMogrifyException(OptionError,"MissingArgument",option);
5116 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005117 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005118 if (op < 0)
5119 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005120 token);
anthony29188a82010-01-22 10:12:34 +00005121 i++;
cristybb503372010-05-27 20:51:26 +00005122 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005123 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005124 kernel_info=AcquireKernelInfo(argv[i]);
5125 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005126 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005127 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005128 break;
5129 }
cristy3ed852e2009-09-05 21:47:34 +00005130 if (LocaleCompare("mosaic",option+1) == 0)
5131 break;
5132 if (LocaleCompare("motion-blur",option+1) == 0)
5133 {
5134 if (*option == '+')
5135 break;
5136 i++;
cristybb503372010-05-27 20:51:26 +00005137 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005138 ThrowMogrifyException(OptionError,"MissingArgument",option);
5139 if (IsGeometry(argv[i]) == MagickFalse)
5140 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5141 break;
5142 }
5143 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5144 }
5145 case 'n':
5146 {
5147 if (LocaleCompare("negate",option+1) == 0)
5148 break;
5149 if (LocaleCompare("noise",option+1) == 0)
5150 {
5151 i++;
cristybb503372010-05-27 20:51:26 +00005152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005153 ThrowMogrifyException(OptionError,"MissingArgument",option);
5154 if (*option == '+')
5155 {
cristybb503372010-05-27 20:51:26 +00005156 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005157 noise;
5158
cristy042ee782011-04-22 18:48:30 +00005159 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005160 if (noise < 0)
5161 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5162 argv[i]);
5163 break;
5164 }
5165 if (IsGeometry(argv[i]) == MagickFalse)
5166 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5167 break;
5168 }
5169 if (LocaleCompare("noop",option+1) == 0)
5170 break;
5171 if (LocaleCompare("normalize",option+1) == 0)
5172 break;
5173 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5174 }
5175 case 'o':
5176 {
5177 if (LocaleCompare("opaque",option+1) == 0)
5178 {
cristy3ed852e2009-09-05 21:47:34 +00005179 i++;
cristybb503372010-05-27 20:51:26 +00005180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005181 ThrowMogrifyException(OptionError,"MissingArgument",option);
5182 break;
5183 }
5184 if (LocaleCompare("ordered-dither",option+1) == 0)
5185 {
5186 if (*option == '+')
5187 break;
5188 i++;
cristybb503372010-05-27 20:51:26 +00005189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005190 ThrowMogrifyException(OptionError,"MissingArgument",option);
5191 break;
5192 }
5193 if (LocaleCompare("orient",option+1) == 0)
5194 {
cristybb503372010-05-27 20:51:26 +00005195 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005196 orientation;
5197
5198 orientation=UndefinedOrientation;
5199 if (*option == '+')
5200 break;
5201 i++;
cristybb503372010-05-27 20:51:26 +00005202 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005203 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005204 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005205 argv[i]);
5206 if (orientation < 0)
5207 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5208 argv[i]);
5209 break;
5210 }
5211 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5212 }
5213 case 'p':
5214 {
5215 if (LocaleCompare("page",option+1) == 0)
5216 {
5217 if (*option == '+')
5218 break;
5219 i++;
cristybb503372010-05-27 20:51:26 +00005220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005221 ThrowMogrifyException(OptionError,"MissingArgument",option);
5222 break;
5223 }
5224 if (LocaleCompare("paint",option+1) == 0)
5225 {
5226 if (*option == '+')
5227 break;
5228 i++;
cristybb503372010-05-27 20:51:26 +00005229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005230 ThrowMogrifyException(OptionError,"MissingArgument",option);
5231 if (IsGeometry(argv[i]) == MagickFalse)
5232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5233 break;
5234 }
5235 if (LocaleCompare("path",option+1) == 0)
5236 {
5237 (void) CloneString(&path,(char *) NULL);
5238 if (*option == '+')
5239 break;
5240 i++;
cristybb503372010-05-27 20:51:26 +00005241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005242 ThrowMogrifyException(OptionError,"MissingArgument",option);
5243 (void) CloneString(&path,argv[i]);
5244 break;
5245 }
5246 if (LocaleCompare("pointsize",option+1) == 0)
5247 {
5248 if (*option == '+')
5249 break;
5250 i++;
cristybb503372010-05-27 20:51:26 +00005251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005252 ThrowMogrifyException(OptionError,"MissingArgument",option);
5253 if (IsGeometry(argv[i]) == MagickFalse)
5254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5255 break;
5256 }
5257 if (LocaleCompare("polaroid",option+1) == 0)
5258 {
5259 if (*option == '+')
5260 break;
5261 i++;
cristybb503372010-05-27 20:51:26 +00005262 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005263 ThrowMogrifyException(OptionError,"MissingArgument",option);
5264 if (IsGeometry(argv[i]) == MagickFalse)
5265 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5266 break;
5267 }
5268 if (LocaleCompare("posterize",option+1) == 0)
5269 {
5270 if (*option == '+')
5271 break;
5272 i++;
cristybb503372010-05-27 20:51:26 +00005273 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005274 ThrowMogrifyException(OptionError,"MissingArgument",option);
5275 if (IsGeometry(argv[i]) == MagickFalse)
5276 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5277 break;
5278 }
cristye7f51092010-01-17 00:39:37 +00005279 if (LocaleCompare("precision",option+1) == 0)
5280 {
5281 if (*option == '+')
5282 break;
5283 i++;
cristybb503372010-05-27 20:51:26 +00005284 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005285 ThrowMogrifyException(OptionError,"MissingArgument",option);
5286 if (IsGeometry(argv[i]) == MagickFalse)
5287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5288 break;
5289 }
cristy3ed852e2009-09-05 21:47:34 +00005290 if (LocaleCompare("print",option+1) == 0)
5291 {
5292 if (*option == '+')
5293 break;
5294 i++;
cristybb503372010-05-27 20:51:26 +00005295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005296 ThrowMogrifyException(OptionError,"MissingArgument",option);
5297 break;
5298 }
5299 if (LocaleCompare("process",option+1) == 0)
5300 {
5301 if (*option == '+')
5302 break;
5303 i++;
cristybb503372010-05-27 20:51:26 +00005304 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005305 ThrowMogrifyException(OptionError,"MissingArgument",option);
5306 break;
5307 }
5308 if (LocaleCompare("profile",option+1) == 0)
5309 {
5310 i++;
cristybb503372010-05-27 20:51:26 +00005311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005312 ThrowMogrifyException(OptionError,"MissingArgument",option);
5313 break;
5314 }
5315 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5316 }
5317 case 'q':
5318 {
5319 if (LocaleCompare("quality",option+1) == 0)
5320 {
5321 if (*option == '+')
5322 break;
5323 i++;
cristybb503372010-05-27 20:51:26 +00005324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005325 ThrowMogrifyException(OptionError,"MissingArgument",option);
5326 if (IsGeometry(argv[i]) == MagickFalse)
5327 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5328 break;
5329 }
5330 if (LocaleCompare("quantize",option+1) == 0)
5331 {
cristybb503372010-05-27 20:51:26 +00005332 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005333 colorspace;
5334
5335 if (*option == '+')
5336 break;
5337 i++;
cristybb503372010-05-27 20:51:26 +00005338 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005339 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005340 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005341 argv[i]);
5342 if (colorspace < 0)
5343 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5344 argv[i]);
5345 break;
5346 }
5347 if (LocaleCompare("quiet",option+1) == 0)
5348 break;
5349 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5350 }
5351 case 'r':
5352 {
5353 if (LocaleCompare("radial-blur",option+1) == 0)
5354 {
5355 i++;
cristybb503372010-05-27 20:51:26 +00005356 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005357 ThrowMogrifyException(OptionError,"MissingArgument",option);
5358 if (IsGeometry(argv[i]) == MagickFalse)
5359 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5360 break;
5361 }
5362 if (LocaleCompare("raise",option+1) == 0)
5363 {
5364 i++;
cristybb503372010-05-27 20:51:26 +00005365 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005366 ThrowMogrifyException(OptionError,"MissingArgument",option);
5367 if (IsGeometry(argv[i]) == MagickFalse)
5368 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5369 break;
5370 }
5371 if (LocaleCompare("random-threshold",option+1) == 0)
5372 {
5373 if (*option == '+')
5374 break;
5375 i++;
cristybb503372010-05-27 20:51:26 +00005376 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005377 ThrowMogrifyException(OptionError,"MissingArgument",option);
5378 if (IsGeometry(argv[i]) == MagickFalse)
5379 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5380 break;
5381 }
cristye6365592010-04-02 17:31:23 +00005382 if (LocaleCompare("recolor",option+1) == 0)
5383 {
5384 if (*option == '+')
5385 break;
5386 i++;
cristybb503372010-05-27 20:51:26 +00005387 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005388 ThrowMogrifyException(OptionError,"MissingArgument",option);
5389 if (IsGeometry(argv[i]) == MagickFalse)
5390 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5391 break;
5392 }
cristy3ed852e2009-09-05 21:47:34 +00005393 if (LocaleCompare("red-primary",option+1) == 0)
5394 {
5395 if (*option == '+')
5396 break;
5397 i++;
cristybb503372010-05-27 20:51:26 +00005398 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005399 ThrowMogrifyException(OptionError,"MissingArgument",option);
5400 if (IsGeometry(argv[i]) == MagickFalse)
5401 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5402 }
cristy9f2083a2010-04-22 19:48:05 +00005403 if (LocaleCompare("regard-warnings",option+1) == 0)
5404 break;
cristy3ed852e2009-09-05 21:47:34 +00005405 if (LocaleCompare("region",option+1) == 0)
5406 {
5407 if (*option == '+')
5408 break;
5409 i++;
cristybb503372010-05-27 20:51:26 +00005410 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005411 ThrowMogrifyException(OptionError,"MissingArgument",option);
5412 if (IsGeometry(argv[i]) == MagickFalse)
5413 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5414 break;
5415 }
cristyf0c78232010-03-15 12:53:40 +00005416 if (LocaleCompare("remap",option+1) == 0)
5417 {
5418 if (*option == '+')
5419 break;
5420 i++;
cristybb503372010-05-27 20:51:26 +00005421 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005422 ThrowMogrifyException(OptionError,"MissingArgument",option);
5423 break;
5424 }
cristy3ed852e2009-09-05 21:47:34 +00005425 if (LocaleCompare("render",option+1) == 0)
5426 break;
5427 if (LocaleCompare("repage",option+1) == 0)
5428 {
5429 if (*option == '+')
5430 break;
5431 i++;
cristybb503372010-05-27 20:51:26 +00005432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005433 ThrowMogrifyException(OptionError,"MissingArgument",option);
5434 if (IsGeometry(argv[i]) == MagickFalse)
5435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5436 break;
5437 }
5438 if (LocaleCompare("resample",option+1) == 0)
5439 {
5440 if (*option == '+')
5441 break;
5442 i++;
cristybb503372010-05-27 20:51:26 +00005443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005444 ThrowMogrifyException(OptionError,"MissingArgument",option);
5445 if (IsGeometry(argv[i]) == MagickFalse)
5446 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5447 break;
5448 }
5449 if (LocaleCompare("resize",option+1) == 0)
5450 {
5451 if (*option == '+')
5452 break;
5453 i++;
cristybb503372010-05-27 20:51:26 +00005454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005455 ThrowMogrifyException(OptionError,"MissingArgument",option);
5456 if (IsGeometry(argv[i]) == MagickFalse)
5457 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5458 break;
5459 }
cristyebbcfea2011-02-25 02:43:54 +00005460 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5461 {
5462 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5463 break;
5464 }
cristy3ed852e2009-09-05 21:47:34 +00005465 if (LocaleCompare("reverse",option+1) == 0)
5466 break;
5467 if (LocaleCompare("roll",option+1) == 0)
5468 {
5469 if (*option == '+')
5470 break;
5471 i++;
cristybb503372010-05-27 20:51:26 +00005472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005473 ThrowMogrifyException(OptionError,"MissingArgument",option);
5474 if (IsGeometry(argv[i]) == MagickFalse)
5475 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5476 break;
5477 }
5478 if (LocaleCompare("rotate",option+1) == 0)
5479 {
5480 i++;
cristybb503372010-05-27 20:51:26 +00005481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005482 ThrowMogrifyException(OptionError,"MissingArgument",option);
5483 if (IsGeometry(argv[i]) == MagickFalse)
5484 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5485 break;
5486 }
5487 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5488 }
5489 case 's':
5490 {
5491 if (LocaleCompare("sample",option+1) == 0)
5492 {
5493 if (*option == '+')
5494 break;
5495 i++;
cristybb503372010-05-27 20:51:26 +00005496 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005497 ThrowMogrifyException(OptionError,"MissingArgument",option);
5498 if (IsGeometry(argv[i]) == MagickFalse)
5499 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5500 break;
5501 }
5502 if (LocaleCompare("sampling-factor",option+1) == 0)
5503 {
5504 if (*option == '+')
5505 break;
5506 i++;
cristybb503372010-05-27 20:51:26 +00005507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005508 ThrowMogrifyException(OptionError,"MissingArgument",option);
5509 if (IsGeometry(argv[i]) == MagickFalse)
5510 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5511 break;
5512 }
5513 if (LocaleCompare("scale",option+1) == 0)
5514 {
5515 if (*option == '+')
5516 break;
5517 i++;
cristybb503372010-05-27 20:51:26 +00005518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 if (IsGeometry(argv[i]) == MagickFalse)
5521 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5522 break;
5523 }
5524 if (LocaleCompare("scene",option+1) == 0)
5525 {
5526 if (*option == '+')
5527 break;
5528 i++;
cristybb503372010-05-27 20:51:26 +00005529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005530 ThrowMogrifyException(OptionError,"MissingArgument",option);
5531 if (IsGeometry(argv[i]) == MagickFalse)
5532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5533 break;
5534 }
5535 if (LocaleCompare("seed",option+1) == 0)
5536 {
5537 if (*option == '+')
5538 break;
5539 i++;
cristybb503372010-05-27 20:51:26 +00005540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005541 ThrowMogrifyException(OptionError,"MissingArgument",option);
5542 if (IsGeometry(argv[i]) == MagickFalse)
5543 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5544 break;
5545 }
5546 if (LocaleCompare("segment",option+1) == 0)
5547 {
5548 if (*option == '+')
5549 break;
5550 i++;
cristybb503372010-05-27 20:51:26 +00005551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005552 ThrowMogrifyException(OptionError,"MissingArgument",option);
5553 if (IsGeometry(argv[i]) == MagickFalse)
5554 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5555 break;
5556 }
5557 if (LocaleCompare("selective-blur",option+1) == 0)
5558 {
5559 i++;
cristybb503372010-05-27 20:51:26 +00005560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005561 ThrowMogrifyException(OptionError,"MissingArgument",option);
5562 if (IsGeometry(argv[i]) == MagickFalse)
5563 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5564 break;
5565 }
5566 if (LocaleCompare("separate",option+1) == 0)
5567 break;
5568 if (LocaleCompare("sepia-tone",option+1) == 0)
5569 {
5570 if (*option == '+')
5571 break;
5572 i++;
cristybb503372010-05-27 20:51:26 +00005573 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005574 ThrowMogrifyException(OptionError,"MissingArgument",option);
5575 if (IsGeometry(argv[i]) == MagickFalse)
5576 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5577 break;
5578 }
5579 if (LocaleCompare("set",option+1) == 0)
5580 {
5581 i++;
cristybb503372010-05-27 20:51:26 +00005582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005583 ThrowMogrifyException(OptionError,"MissingArgument",option);
5584 if (*option == '+')
5585 break;
5586 i++;
cristybb503372010-05-27 20:51:26 +00005587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005588 ThrowMogrifyException(OptionError,"MissingArgument",option);
5589 break;
5590 }
5591 if (LocaleCompare("shade",option+1) == 0)
5592 {
5593 i++;
cristybb503372010-05-27 20:51:26 +00005594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5598 break;
5599 }
5600 if (LocaleCompare("shadow",option+1) == 0)
5601 {
5602 if (*option == '+')
5603 break;
5604 i++;
cristybb503372010-05-27 20:51:26 +00005605 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005606 ThrowMogrifyException(OptionError,"MissingArgument",option);
5607 if (IsGeometry(argv[i]) == MagickFalse)
5608 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5609 break;
5610 }
5611 if (LocaleCompare("sharpen",option+1) == 0)
5612 {
5613 i++;
cristybb503372010-05-27 20:51:26 +00005614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005615 ThrowMogrifyException(OptionError,"MissingArgument",option);
5616 if (IsGeometry(argv[i]) == MagickFalse)
5617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5618 break;
5619 }
5620 if (LocaleCompare("shave",option+1) == 0)
5621 {
5622 if (*option == '+')
5623 break;
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 if (IsGeometry(argv[i]) == MagickFalse)
5628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5629 break;
5630 }
5631 if (LocaleCompare("shear",option+1) == 0)
5632 {
5633 i++;
cristybb503372010-05-27 20:51:26 +00005634 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005635 ThrowMogrifyException(OptionError,"MissingArgument",option);
5636 if (IsGeometry(argv[i]) == MagickFalse)
5637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5638 break;
5639 }
5640 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5641 {
5642 i++;
cristybb503372010-05-27 20:51:26 +00005643 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005644 ThrowMogrifyException(OptionError,"MissingArgument",option);
5645 if (IsGeometry(argv[i]) == MagickFalse)
5646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5647 break;
5648 }
5649 if (LocaleCompare("size",option+1) == 0)
5650 {
5651 if (*option == '+')
5652 break;
5653 i++;
cristybb503372010-05-27 20:51:26 +00005654 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005655 ThrowMogrifyException(OptionError,"MissingArgument",option);
5656 if (IsGeometry(argv[i]) == MagickFalse)
5657 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5658 break;
5659 }
5660 if (LocaleCompare("sketch",option+1) == 0)
5661 {
5662 if (*option == '+')
5663 break;
5664 i++;
cristybb503372010-05-27 20:51:26 +00005665 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005666 ThrowMogrifyException(OptionError,"MissingArgument",option);
5667 if (IsGeometry(argv[i]) == MagickFalse)
5668 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5669 break;
5670 }
cristy4285d782011-02-09 20:12:28 +00005671 if (LocaleCompare("smush",option+1) == 0)
5672 {
cristy4285d782011-02-09 20:12:28 +00005673 i++;
5674 if (i == (ssize_t) argc)
5675 ThrowMogrifyException(OptionError,"MissingArgument",option);
5676 if (IsGeometry(argv[i]) == MagickFalse)
5677 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005678 i++;
5679 break;
5680 }
cristy3ed852e2009-09-05 21:47:34 +00005681 if (LocaleCompare("solarize",option+1) == 0)
5682 {
5683 if (*option == '+')
5684 break;
5685 i++;
cristybb503372010-05-27 20:51:26 +00005686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005687 ThrowMogrifyException(OptionError,"MissingArgument",option);
5688 if (IsGeometry(argv[i]) == MagickFalse)
5689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5690 break;
5691 }
5692 if (LocaleCompare("sparse-color",option+1) == 0)
5693 {
cristybb503372010-05-27 20:51:26 +00005694 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005695 op;
5696
5697 i++;
cristybb503372010-05-27 20:51:26 +00005698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005699 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005700 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005701 if (op < 0)
5702 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5703 argv[i]);
5704 i++;
cristybb503372010-05-27 20:51:26 +00005705 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005706 ThrowMogrifyException(OptionError,"MissingArgument",option);
5707 break;
5708 }
5709 if (LocaleCompare("spread",option+1) == 0)
5710 {
5711 if (*option == '+')
5712 break;
5713 i++;
cristybb503372010-05-27 20:51:26 +00005714 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005715 ThrowMogrifyException(OptionError,"MissingArgument",option);
5716 if (IsGeometry(argv[i]) == MagickFalse)
5717 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5718 break;
5719 }
cristy0834d642011-03-18 18:26:08 +00005720 if (LocaleCompare("statistic",option+1) == 0)
5721 {
5722 ssize_t
5723 op;
5724
5725 if (*option == '+')
5726 break;
5727 i++;
5728 if (i == (ssize_t) argc)
5729 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005730 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005731 if (op < 0)
5732 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5733 argv[i]);
5734 i++;
5735 if (i == (ssize_t) (argc-1))
5736 ThrowMogrifyException(OptionError,"MissingArgument",option);
5737 if (IsGeometry(argv[i]) == MagickFalse)
5738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5739 break;
5740 }
cristy3ed852e2009-09-05 21:47:34 +00005741 if (LocaleCompare("stretch",option+1) == 0)
5742 {
cristybb503372010-05-27 20:51:26 +00005743 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005744 stretch;
5745
5746 if (*option == '+')
5747 break;
5748 i++;
cristybb503372010-05-27 20:51:26 +00005749 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005750 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005751 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005752 if (stretch < 0)
5753 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5754 argv[i]);
5755 break;
5756 }
5757 if (LocaleCompare("strip",option+1) == 0)
5758 break;
5759 if (LocaleCompare("stroke",option+1) == 0)
5760 {
5761 if (*option == '+')
5762 break;
5763 i++;
cristybb503372010-05-27 20:51:26 +00005764 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005765 ThrowMogrifyException(OptionError,"MissingArgument",option);
5766 break;
5767 }
5768 if (LocaleCompare("strokewidth",option+1) == 0)
5769 {
5770 if (*option == '+')
5771 break;
5772 i++;
cristybb503372010-05-27 20:51:26 +00005773 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005774 ThrowMogrifyException(OptionError,"MissingArgument",option);
5775 if (IsGeometry(argv[i]) == MagickFalse)
5776 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5777 break;
5778 }
5779 if (LocaleCompare("style",option+1) == 0)
5780 {
cristybb503372010-05-27 20:51:26 +00005781 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005782 style;
5783
5784 if (*option == '+')
5785 break;
5786 i++;
cristybb503372010-05-27 20:51:26 +00005787 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005788 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005789 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005790 if (style < 0)
5791 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5792 argv[i]);
5793 break;
5794 }
cristyecb10ff2011-03-22 13:14:03 +00005795 if (LocaleCompare("swap",option+1) == 0)
5796 {
5797 if (*option == '+')
5798 break;
5799 i++;
5800 if (i == (ssize_t) (argc-1))
5801 ThrowMogrifyException(OptionError,"MissingArgument",option);
5802 if (IsGeometry(argv[i]) == MagickFalse)
5803 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5804 break;
5805 }
cristy3ed852e2009-09-05 21:47:34 +00005806 if (LocaleCompare("swirl",option+1) == 0)
5807 {
5808 if (*option == '+')
5809 break;
5810 i++;
cristybb503372010-05-27 20:51:26 +00005811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005812 ThrowMogrifyException(OptionError,"MissingArgument",option);
5813 if (IsGeometry(argv[i]) == MagickFalse)
5814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5815 break;
5816 }
cristyd9a29192010-10-16 16:49:53 +00005817 if (LocaleCompare("synchronize",option+1) == 0)
5818 break;
cristy3ed852e2009-09-05 21:47:34 +00005819 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5820 }
5821 case 't':
5822 {
5823 if (LocaleCompare("taint",option+1) == 0)
5824 break;
5825 if (LocaleCompare("texture",option+1) == 0)
5826 {
5827 if (*option == '+')
5828 break;
5829 i++;
cristybb503372010-05-27 20:51:26 +00005830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005831 ThrowMogrifyException(OptionError,"MissingArgument",option);
5832 break;
5833 }
5834 if (LocaleCompare("tile",option+1) == 0)
5835 {
5836 if (*option == '+')
5837 break;
5838 i++;
cristybb503372010-05-27 20:51:26 +00005839 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005840 ThrowMogrifyException(OptionError,"MissingArgument",option);
5841 break;
5842 }
5843 if (LocaleCompare("tile-offset",option+1) == 0)
5844 {
5845 if (*option == '+')
5846 break;
5847 i++;
cristybb503372010-05-27 20:51:26 +00005848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005849 ThrowMogrifyException(OptionError,"MissingArgument",option);
5850 if (IsGeometry(argv[i]) == MagickFalse)
5851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5852 break;
5853 }
5854 if (LocaleCompare("tint",option+1) == 0)
5855 {
5856 if (*option == '+')
5857 break;
5858 i++;
cristybb503372010-05-27 20:51:26 +00005859 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005860 ThrowMogrifyException(OptionError,"MissingArgument",option);
5861 if (IsGeometry(argv[i]) == MagickFalse)
5862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5863 break;
5864 }
5865 if (LocaleCompare("transform",option+1) == 0)
5866 break;
5867 if (LocaleCompare("transpose",option+1) == 0)
5868 break;
5869 if (LocaleCompare("transverse",option+1) == 0)
5870 break;
5871 if (LocaleCompare("threshold",option+1) == 0)
5872 {
5873 if (*option == '+')
5874 break;
5875 i++;
cristybb503372010-05-27 20:51:26 +00005876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005877 ThrowMogrifyException(OptionError,"MissingArgument",option);
5878 if (IsGeometry(argv[i]) == MagickFalse)
5879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5880 break;
5881 }
5882 if (LocaleCompare("thumbnail",option+1) == 0)
5883 {
5884 if (*option == '+')
5885 break;
5886 i++;
cristybb503372010-05-27 20:51:26 +00005887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005888 ThrowMogrifyException(OptionError,"MissingArgument",option);
5889 if (IsGeometry(argv[i]) == MagickFalse)
5890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5891 break;
5892 }
5893 if (LocaleCompare("transparent",option+1) == 0)
5894 {
5895 i++;
cristybb503372010-05-27 20:51:26 +00005896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005897 ThrowMogrifyException(OptionError,"MissingArgument",option);
5898 break;
5899 }
5900 if (LocaleCompare("transparent-color",option+1) == 0)
5901 {
5902 if (*option == '+')
5903 break;
5904 i++;
cristybb503372010-05-27 20:51:26 +00005905 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005906 ThrowMogrifyException(OptionError,"MissingArgument",option);
5907 break;
5908 }
5909 if (LocaleCompare("treedepth",option+1) == 0)
5910 {
5911 if (*option == '+')
5912 break;
5913 i++;
cristybb503372010-05-27 20:51:26 +00005914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005915 ThrowMogrifyException(OptionError,"MissingArgument",option);
5916 if (IsGeometry(argv[i]) == MagickFalse)
5917 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5918 break;
5919 }
5920 if (LocaleCompare("trim",option+1) == 0)
5921 break;
5922 if (LocaleCompare("type",option+1) == 0)
5923 {
cristybb503372010-05-27 20:51:26 +00005924 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005925 type;
5926
5927 if (*option == '+')
5928 break;
5929 i++;
cristybb503372010-05-27 20:51:26 +00005930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005931 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005932 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005933 if (type < 0)
5934 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5935 argv[i]);
5936 break;
5937 }
5938 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5939 }
5940 case 'u':
5941 {
5942 if (LocaleCompare("undercolor",option+1) == 0)
5943 {
5944 if (*option == '+')
5945 break;
5946 i++;
cristybb503372010-05-27 20:51:26 +00005947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005948 ThrowMogrifyException(OptionError,"MissingArgument",option);
5949 break;
5950 }
5951 if (LocaleCompare("unique-colors",option+1) == 0)
5952 break;
5953 if (LocaleCompare("units",option+1) == 0)
5954 {
cristybb503372010-05-27 20:51:26 +00005955 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005956 units;
5957
5958 if (*option == '+')
5959 break;
5960 i++;
cristybb503372010-05-27 20:51:26 +00005961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005962 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005963 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005964 argv[i]);
5965 if (units < 0)
5966 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5967 argv[i]);
5968 break;
5969 }
5970 if (LocaleCompare("unsharp",option+1) == 0)
5971 {
5972 i++;
cristybb503372010-05-27 20:51:26 +00005973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005974 ThrowMogrifyException(OptionError,"MissingArgument",option);
5975 if (IsGeometry(argv[i]) == MagickFalse)
5976 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5977 break;
5978 }
5979 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5980 }
5981 case 'v':
5982 {
5983 if (LocaleCompare("verbose",option+1) == 0)
5984 {
5985 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5986 break;
5987 }
5988 if ((LocaleCompare("version",option+1) == 0) ||
5989 (LocaleCompare("-version",option+1) == 0))
5990 {
cristyb51dff52011-05-19 16:55:47 +00005991 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005992 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005993 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5994 GetMagickCopyright());
5995 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5996 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005997 break;
5998 }
5999 if (LocaleCompare("view",option+1) == 0)
6000 {
6001 if (*option == '+')
6002 break;
6003 i++;
cristybb503372010-05-27 20:51:26 +00006004 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006005 ThrowMogrifyException(OptionError,"MissingArgument",option);
6006 break;
6007 }
6008 if (LocaleCompare("vignette",option+1) == 0)
6009 {
6010 if (*option == '+')
6011 break;
6012 i++;
cristybb503372010-05-27 20:51:26 +00006013 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006014 ThrowMogrifyException(OptionError,"MissingArgument",option);
6015 if (IsGeometry(argv[i]) == MagickFalse)
6016 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6017 break;
6018 }
6019 if (LocaleCompare("virtual-pixel",option+1) == 0)
6020 {
cristybb503372010-05-27 20:51:26 +00006021 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006022 method;
6023
6024 if (*option == '+')
6025 break;
6026 i++;
cristybb503372010-05-27 20:51:26 +00006027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006028 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006029 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006030 argv[i]);
6031 if (method < 0)
6032 ThrowMogrifyException(OptionError,
6033 "UnrecognizedVirtualPixelMethod",argv[i]);
6034 break;
6035 }
6036 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6037 }
6038 case 'w':
6039 {
6040 if (LocaleCompare("wave",option+1) == 0)
6041 {
6042 i++;
cristybb503372010-05-27 20:51:26 +00006043 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006044 ThrowMogrifyException(OptionError,"MissingArgument",option);
6045 if (IsGeometry(argv[i]) == MagickFalse)
6046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6047 break;
6048 }
6049 if (LocaleCompare("weight",option+1) == 0)
6050 {
6051 if (*option == '+')
6052 break;
6053 i++;
cristybb503372010-05-27 20:51:26 +00006054 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006055 ThrowMogrifyException(OptionError,"MissingArgument",option);
6056 break;
6057 }
6058 if (LocaleCompare("white-point",option+1) == 0)
6059 {
6060 if (*option == '+')
6061 break;
6062 i++;
cristybb503372010-05-27 20:51:26 +00006063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006064 ThrowMogrifyException(OptionError,"MissingArgument",option);
6065 if (IsGeometry(argv[i]) == MagickFalse)
6066 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6067 break;
6068 }
6069 if (LocaleCompare("white-threshold",option+1) == 0)
6070 {
6071 if (*option == '+')
6072 break;
6073 i++;
cristybb503372010-05-27 20:51:26 +00006074 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006075 ThrowMogrifyException(OptionError,"MissingArgument",option);
6076 if (IsGeometry(argv[i]) == MagickFalse)
6077 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6078 break;
6079 }
6080 if (LocaleCompare("write",option+1) == 0)
6081 {
6082 i++;
cristybb503372010-05-27 20:51:26 +00006083 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006084 ThrowMogrifyException(OptionError,"MissingArgument",option);
6085 break;
6086 }
6087 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6088 }
6089 case '?':
6090 break;
6091 default:
6092 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6093 }
cristy042ee782011-04-22 18:48:30 +00006094 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6095 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006096 if (fire != MagickFalse)
6097 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6098 }
6099 if (k != 0)
6100 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006101 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006102 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6103 DestroyMogrify();
6104 return(status != 0 ? MagickTrue : MagickFalse);
6105}
6106
6107/*
6108%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6109% %
6110% %
6111% %
6112+ M o g r i f y I m a g e I n f o %
6113% %
6114% %
6115% %
6116%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6117%
6118% MogrifyImageInfo() applies image processing settings to the image as
6119% prescribed by command line options.
6120%
6121% The format of the MogrifyImageInfo method is:
6122%
6123% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6124% const char **argv,ExceptionInfo *exception)
6125%
6126% A description of each parameter follows:
6127%
6128% o image_info: the image info..
6129%
6130% o argc: Specifies a pointer to an integer describing the number of
6131% elements in the argument vector.
6132%
6133% o argv: Specifies a pointer to a text array containing the command line
6134% arguments.
6135%
6136% o exception: return any errors or warnings in this structure.
6137%
6138*/
6139WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6140 const int argc,const char **argv,ExceptionInfo *exception)
6141{
6142 const char
6143 *option;
6144
6145 GeometryInfo
6146 geometry_info;
6147
cristybb503372010-05-27 20:51:26 +00006148 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006149 count;
6150
cristybb503372010-05-27 20:51:26 +00006151 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006152 i;
6153
6154 /*
6155 Initialize method variables.
6156 */
6157 assert(image_info != (ImageInfo *) NULL);
6158 assert(image_info->signature == MagickSignature);
6159 if (image_info->debug != MagickFalse)
6160 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6161 image_info->filename);
6162 if (argc < 0)
6163 return(MagickTrue);
6164 /*
6165 Set the image settings.
6166 */
cristybb503372010-05-27 20:51:26 +00006167 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006168 {
6169 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006170 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006171 continue;
cristy042ee782011-04-22 18:48:30 +00006172 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006173 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006174 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006175 break;
6176 switch (*(option+1))
6177 {
6178 case 'a':
6179 {
6180 if (LocaleCompare("adjoin",option+1) == 0)
6181 {
6182 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6183 break;
6184 }
6185 if (LocaleCompare("antialias",option+1) == 0)
6186 {
6187 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6188 break;
6189 }
cristy3ed852e2009-09-05 21:47:34 +00006190 if (LocaleCompare("authenticate",option+1) == 0)
6191 {
6192 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006193 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006194 else
anthony1afdc7a2011-10-05 11:54:28 +00006195 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006196 break;
6197 }
6198 break;
6199 }
6200 case 'b':
6201 {
6202 if (LocaleCompare("background",option+1) == 0)
6203 {
6204 if (*option == '+')
6205 {
6206 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006207 (void) QueryColorCompliance(MogrifyBackgroundColor,
6208 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006209 break;
6210 }
6211 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006212 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6213 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006214 break;
6215 }
6216 if (LocaleCompare("bias",option+1) == 0)
6217 {
6218 if (*option == '+')
6219 {
6220 (void) SetImageOption(image_info,option+1,"0.0");
6221 break;
6222 }
6223 (void) SetImageOption(image_info,option+1,argv[i+1]);
6224 break;
6225 }
6226 if (LocaleCompare("black-point-compensation",option+1) == 0)
6227 {
6228 if (*option == '+')
6229 {
6230 (void) SetImageOption(image_info,option+1,"false");
6231 break;
6232 }
6233 (void) SetImageOption(image_info,option+1,"true");
6234 break;
6235 }
6236 if (LocaleCompare("blue-primary",option+1) == 0)
6237 {
6238 if (*option == '+')
6239 {
6240 (void) SetImageOption(image_info,option+1,"0.0");
6241 break;
6242 }
6243 (void) SetImageOption(image_info,option+1,argv[i+1]);
6244 break;
6245 }
6246 if (LocaleCompare("bordercolor",option+1) == 0)
6247 {
6248 if (*option == '+')
6249 {
6250 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006251 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006252 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006253 break;
6254 }
cristy9950d572011-10-01 18:22:35 +00006255 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6256 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006257 (void) SetImageOption(image_info,option+1,argv[i+1]);
6258 break;
6259 }
6260 if (LocaleCompare("box",option+1) == 0)
6261 {
6262 if (*option == '+')
6263 {
6264 (void) SetImageOption(image_info,"undercolor","none");
6265 break;
6266 }
6267 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6268 break;
6269 }
6270 break;
6271 }
6272 case 'c':
6273 {
6274 if (LocaleCompare("cache",option+1) == 0)
6275 {
6276 MagickSizeType
6277 limit;
6278
6279 limit=MagickResourceInfinity;
6280 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006281 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6282 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006283 (void) SetMagickResourceLimit(MemoryResource,limit);
6284 (void) SetMagickResourceLimit(MapResource,2*limit);
6285 break;
6286 }
6287 if (LocaleCompare("caption",option+1) == 0)
6288 {
6289 if (*option == '+')
6290 {
6291 (void) DeleteImageOption(image_info,option+1);
6292 break;
6293 }
6294 (void) SetImageOption(image_info,option+1,argv[i+1]);
6295 break;
6296 }
6297 if (LocaleCompare("channel",option+1) == 0)
6298 {
6299 if (*option == '+')
6300 {
6301 image_info->channel=DefaultChannels;
6302 break;
6303 }
6304 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6305 break;
6306 }
cristy3ed852e2009-09-05 21:47:34 +00006307 if (LocaleCompare("colorspace",option+1) == 0)
6308 {
6309 if (*option == '+')
6310 {
6311 image_info->colorspace=UndefinedColorspace;
6312 (void) SetImageOption(image_info,option+1,"undefined");
6313 break;
6314 }
cristy042ee782011-04-22 18:48:30 +00006315 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006316 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6317 (void) SetImageOption(image_info,option+1,argv[i+1]);
6318 break;
6319 }
cristy3ed852e2009-09-05 21:47:34 +00006320 if (LocaleCompare("comment",option+1) == 0)
6321 {
6322 if (*option == '+')
6323 {
6324 (void) DeleteImageOption(image_info,option+1);
6325 break;
6326 }
6327 (void) SetImageOption(image_info,option+1,argv[i+1]);
6328 break;
6329 }
6330 if (LocaleCompare("compose",option+1) == 0)
6331 {
6332 if (*option == '+')
6333 {
6334 (void) SetImageOption(image_info,option+1,"undefined");
6335 break;
6336 }
6337 (void) SetImageOption(image_info,option+1,argv[i+1]);
6338 break;
6339 }
6340 if (LocaleCompare("compress",option+1) == 0)
6341 {
6342 if (*option == '+')
6343 {
6344 image_info->compression=UndefinedCompression;
6345 (void) SetImageOption(image_info,option+1,"undefined");
6346 break;
6347 }
cristy042ee782011-04-22 18:48:30 +00006348 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006349 MagickCompressOptions,MagickFalse,argv[i+1]);
6350 (void) SetImageOption(image_info,option+1,argv[i+1]);
6351 break;
6352 }
6353 break;
6354 }
6355 case 'd':
6356 {
6357 if (LocaleCompare("debug",option+1) == 0)
6358 {
6359 if (*option == '+')
6360 (void) SetLogEventMask("none");
6361 else
6362 (void) SetLogEventMask(argv[i+1]);
6363 image_info->debug=IsEventLogging();
6364 break;
6365 }
6366 if (LocaleCompare("define",option+1) == 0)
6367 {
6368 if (*option == '+')
6369 {
6370 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6371 (void) DeleteImageRegistry(argv[i+1]+9);
6372 else
6373 (void) DeleteImageOption(image_info,argv[i+1]);
6374 break;
6375 }
6376 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6377 {
6378 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6379 exception);
6380 break;
6381 }
6382 (void) DefineImageOption(image_info,argv[i+1]);
6383 break;
6384 }
6385 if (LocaleCompare("delay",option+1) == 0)
6386 {
6387 if (*option == '+')
6388 {
6389 (void) SetImageOption(image_info,option+1,"0");
6390 break;
6391 }
6392 (void) SetImageOption(image_info,option+1,argv[i+1]);
6393 break;
6394 }
6395 if (LocaleCompare("density",option+1) == 0)
6396 {
6397 /*
6398 Set image density.
6399 */
6400 if (*option == '+')
6401 {
6402 if (image_info->density != (char *) NULL)
6403 image_info->density=DestroyString(image_info->density);
6404 (void) SetImageOption(image_info,option+1,"72");
6405 break;
6406 }
6407 (void) CloneString(&image_info->density,argv[i+1]);
6408 (void) SetImageOption(image_info,option+1,argv[i+1]);
6409 break;
6410 }
6411 if (LocaleCompare("depth",option+1) == 0)
6412 {
6413 if (*option == '+')
6414 {
6415 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6416 break;
6417 }
cristye27293e2009-12-18 02:53:20 +00006418 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006419 break;
6420 }
cristyc9b12952010-03-28 01:12:28 +00006421 if (LocaleCompare("direction",option+1) == 0)
6422 {
6423 if (*option == '+')
6424 {
6425 (void) SetImageOption(image_info,option+1,"undefined");
6426 break;
6427 }
6428 (void) SetImageOption(image_info,option+1,argv[i+1]);
6429 break;
6430 }
cristy3ed852e2009-09-05 21:47:34 +00006431 if (LocaleCompare("display",option+1) == 0)
6432 {
6433 if (*option == '+')
6434 {
6435 if (image_info->server_name != (char *) NULL)
6436 image_info->server_name=DestroyString(
6437 image_info->server_name);
6438 break;
6439 }
6440 (void) CloneString(&image_info->server_name,argv[i+1]);
6441 break;
6442 }
6443 if (LocaleCompare("dispose",option+1) == 0)
6444 {
6445 if (*option == '+')
6446 {
6447 (void) SetImageOption(image_info,option+1,"undefined");
6448 break;
6449 }
6450 (void) SetImageOption(image_info,option+1,argv[i+1]);
6451 break;
6452 }
6453 if (LocaleCompare("dither",option+1) == 0)
6454 {
6455 if (*option == '+')
6456 {
6457 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006458 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006459 break;
6460 }
6461 (void) SetImageOption(image_info,option+1,argv[i+1]);
6462 image_info->dither=MagickTrue;
6463 break;
6464 }
6465 break;
6466 }
6467 case 'e':
6468 {
6469 if (LocaleCompare("encoding",option+1) == 0)
6470 {
6471 if (*option == '+')
6472 {
6473 (void) SetImageOption(image_info,option+1,"undefined");
6474 break;
6475 }
6476 (void) SetImageOption(image_info,option+1,argv[i+1]);
6477 break;
6478 }
6479 if (LocaleCompare("endian",option+1) == 0)
6480 {
6481 if (*option == '+')
6482 {
6483 image_info->endian=UndefinedEndian;
6484 (void) SetImageOption(image_info,option+1,"undefined");
6485 break;
6486 }
cristy042ee782011-04-22 18:48:30 +00006487 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006488 MagickEndianOptions,MagickFalse,argv[i+1]);
6489 (void) SetImageOption(image_info,option+1,argv[i+1]);
6490 break;
6491 }
6492 if (LocaleCompare("extract",option+1) == 0)
6493 {
6494 /*
6495 Set image extract geometry.
6496 */
6497 if (*option == '+')
6498 {
6499 if (image_info->extract != (char *) NULL)
6500 image_info->extract=DestroyString(image_info->extract);
6501 break;
6502 }
6503 (void) CloneString(&image_info->extract,argv[i+1]);
6504 break;
6505 }
6506 break;
6507 }
6508 case 'f':
6509 {
6510 if (LocaleCompare("fill",option+1) == 0)
6511 {
6512 if (*option == '+')
6513 {
6514 (void) SetImageOption(image_info,option+1,"none");
6515 break;
6516 }
6517 (void) SetImageOption(image_info,option+1,argv[i+1]);
6518 break;
6519 }
6520 if (LocaleCompare("filter",option+1) == 0)
6521 {
6522 if (*option == '+')
6523 {
6524 (void) SetImageOption(image_info,option+1,"undefined");
6525 break;
6526 }
6527 (void) SetImageOption(image_info,option+1,argv[i+1]);
6528 break;
6529 }
6530 if (LocaleCompare("font",option+1) == 0)
6531 {
6532 if (*option == '+')
6533 {
6534 if (image_info->font != (char *) NULL)
6535 image_info->font=DestroyString(image_info->font);
6536 break;
6537 }
6538 (void) CloneString(&image_info->font,argv[i+1]);
6539 break;
6540 }
6541 if (LocaleCompare("format",option+1) == 0)
6542 {
6543 register const char
6544 *q;
6545
6546 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006547 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006548 image_info->ping=MagickFalse;
6549 (void) SetImageOption(image_info,option+1,argv[i+1]);
6550 break;
6551 }
6552 if (LocaleCompare("fuzz",option+1) == 0)
6553 {
6554 if (*option == '+')
6555 {
6556 image_info->fuzz=0.0;
6557 (void) SetImageOption(image_info,option+1,"0");
6558 break;
6559 }
cristydbdd0e32011-11-04 23:29:40 +00006560 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6561 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006562 (void) SetImageOption(image_info,option+1,argv[i+1]);
6563 break;
6564 }
6565 break;
6566 }
6567 case 'g':
6568 {
6569 if (LocaleCompare("gravity",option+1) == 0)
6570 {
6571 if (*option == '+')
6572 {
6573 (void) SetImageOption(image_info,option+1,"undefined");
6574 break;
6575 }
6576 (void) SetImageOption(image_info,option+1,argv[i+1]);
6577 break;
6578 }
6579 if (LocaleCompare("green-primary",option+1) == 0)
6580 {
6581 if (*option == '+')
6582 {
6583 (void) SetImageOption(image_info,option+1,"0.0");
6584 break;
6585 }
6586 (void) SetImageOption(image_info,option+1,argv[i+1]);
6587 break;
6588 }
6589 break;
6590 }
6591 case 'i':
6592 {
6593 if (LocaleCompare("intent",option+1) == 0)
6594 {
6595 if (*option == '+')
6596 {
6597 (void) SetImageOption(image_info,option+1,"undefined");
6598 break;
6599 }
6600 (void) SetImageOption(image_info,option+1,argv[i+1]);
6601 break;
6602 }
6603 if (LocaleCompare("interlace",option+1) == 0)
6604 {
6605 if (*option == '+')
6606 {
6607 image_info->interlace=UndefinedInterlace;
6608 (void) SetImageOption(image_info,option+1,"undefined");
6609 break;
6610 }
cristy042ee782011-04-22 18:48:30 +00006611 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006612 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6613 (void) SetImageOption(image_info,option+1,argv[i+1]);
6614 break;
6615 }
cristyb32b90a2009-09-07 21:45:48 +00006616 if (LocaleCompare("interline-spacing",option+1) == 0)
6617 {
6618 if (*option == '+')
6619 {
6620 (void) SetImageOption(image_info,option+1,"undefined");
6621 break;
6622 }
6623 (void) SetImageOption(image_info,option+1,argv[i+1]);
6624 break;
6625 }
cristy3ed852e2009-09-05 21:47:34 +00006626 if (LocaleCompare("interpolate",option+1) == 0)
6627 {
6628 if (*option == '+')
6629 {
6630 (void) SetImageOption(image_info,option+1,"undefined");
6631 break;
6632 }
6633 (void) SetImageOption(image_info,option+1,argv[i+1]);
6634 break;
6635 }
6636 if (LocaleCompare("interword-spacing",option+1) == 0)
6637 {
6638 if (*option == '+')
6639 {
6640 (void) SetImageOption(image_info,option+1,"undefined");
6641 break;
6642 }
6643 (void) SetImageOption(image_info,option+1,argv[i+1]);
6644 break;
6645 }
6646 break;
6647 }
6648 case 'k':
6649 {
6650 if (LocaleCompare("kerning",option+1) == 0)
6651 {
6652 if (*option == '+')
6653 {
6654 (void) SetImageOption(image_info,option+1,"undefined");
6655 break;
6656 }
6657 (void) SetImageOption(image_info,option+1,argv[i+1]);
6658 break;
6659 }
6660 break;
6661 }
6662 case 'l':
6663 {
6664 if (LocaleCompare("label",option+1) == 0)
6665 {
6666 if (*option == '+')
6667 {
6668 (void) DeleteImageOption(image_info,option+1);
6669 break;
6670 }
6671 (void) SetImageOption(image_info,option+1,argv[i+1]);
6672 break;
6673 }
6674 if (LocaleCompare("limit",option+1) == 0)
6675 {
6676 MagickSizeType
6677 limit;
6678
6679 ResourceType
6680 type;
6681
6682 if (*option == '+')
6683 break;
cristy042ee782011-04-22 18:48:30 +00006684 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006685 MagickFalse,argv[i+1]);
6686 limit=MagickResourceInfinity;
6687 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006688 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006689 (void) SetMagickResourceLimit(type,limit);
6690 break;
6691 }
6692 if (LocaleCompare("list",option+1) == 0)
6693 {
cristybb503372010-05-27 20:51:26 +00006694 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006695 list;
6696
6697 /*
6698 Display configuration list.
6699 */
cristy042ee782011-04-22 18:48:30 +00006700 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006701 switch (list)
6702 {
6703 case MagickCoderOptions:
6704 {
6705 (void) ListCoderInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickColorOptions:
6709 {
6710 (void) ListColorInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickConfigureOptions:
6714 {
6715 (void) ListConfigureInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickDelegateOptions:
6719 {
6720 (void) ListDelegateInfo((FILE *) NULL,exception);
6721 break;
6722 }
6723 case MagickFontOptions:
6724 {
6725 (void) ListTypeInfo((FILE *) NULL,exception);
6726 break;
6727 }
6728 case MagickFormatOptions:
6729 {
6730 (void) ListMagickInfo((FILE *) NULL,exception);
6731 break;
6732 }
6733 case MagickLocaleOptions:
6734 {
6735 (void) ListLocaleInfo((FILE *) NULL,exception);
6736 break;
6737 }
6738 case MagickLogOptions:
6739 {
6740 (void) ListLogInfo((FILE *) NULL,exception);
6741 break;
6742 }
6743 case MagickMagicOptions:
6744 {
6745 (void) ListMagicInfo((FILE *) NULL,exception);
6746 break;
6747 }
6748 case MagickMimeOptions:
6749 {
6750 (void) ListMimeInfo((FILE *) NULL,exception);
6751 break;
6752 }
6753 case MagickModuleOptions:
6754 {
6755 (void) ListModuleInfo((FILE *) NULL,exception);
6756 break;
6757 }
6758 case MagickPolicyOptions:
6759 {
6760 (void) ListPolicyInfo((FILE *) NULL,exception);
6761 break;
6762 }
6763 case MagickResourceOptions:
6764 {
6765 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6766 break;
6767 }
6768 case MagickThresholdOptions:
6769 {
6770 (void) ListThresholdMaps((FILE *) NULL,exception);
6771 break;
6772 }
6773 default:
6774 {
cristy042ee782011-04-22 18:48:30 +00006775 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006776 exception);
6777 break;
6778 }
6779 }
cristyaeb2cbc2010-05-07 13:28:58 +00006780 break;
cristy3ed852e2009-09-05 21:47:34 +00006781 }
6782 if (LocaleCompare("log",option+1) == 0)
6783 {
6784 if (*option == '+')
6785 break;
6786 (void) SetLogFormat(argv[i+1]);
6787 break;
6788 }
6789 if (LocaleCompare("loop",option+1) == 0)
6790 {
6791 if (*option == '+')
6792 {
6793 (void) SetImageOption(image_info,option+1,"0");
6794 break;
6795 }
6796 (void) SetImageOption(image_info,option+1,argv[i+1]);
6797 break;
6798 }
6799 break;
6800 }
6801 case 'm':
6802 {
6803 if (LocaleCompare("matte",option+1) == 0)
6804 {
6805 if (*option == '+')
6806 {
6807 (void) SetImageOption(image_info,option+1,"false");
6808 break;
6809 }
6810 (void) SetImageOption(image_info,option+1,"true");
6811 break;
6812 }
6813 if (LocaleCompare("mattecolor",option+1) == 0)
6814 {
6815 if (*option == '+')
6816 {
6817 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006818 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006819 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006820 break;
6821 }
6822 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006823 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6824 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006825 break;
6826 }
6827 if (LocaleCompare("monitor",option+1) == 0)
6828 {
6829 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6830 (void *) NULL);
6831 break;
6832 }
6833 if (LocaleCompare("monochrome",option+1) == 0)
6834 {
6835 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6836 break;
6837 }
6838 break;
6839 }
6840 case 'o':
6841 {
6842 if (LocaleCompare("orient",option+1) == 0)
6843 {
6844 if (*option == '+')
6845 {
6846 image_info->orientation=UndefinedOrientation;
6847 (void) SetImageOption(image_info,option+1,"undefined");
6848 break;
6849 }
cristy042ee782011-04-22 18:48:30 +00006850 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006851 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006852 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006853 break;
6854 }
6855 }
6856 case 'p':
6857 {
6858 if (LocaleCompare("page",option+1) == 0)
6859 {
6860 char
6861 *canonical_page,
6862 page[MaxTextExtent];
6863
6864 const char
6865 *image_option;
6866
6867 MagickStatusType
6868 flags;
6869
6870 RectangleInfo
6871 geometry;
6872
6873 if (*option == '+')
6874 {
6875 (void) DeleteImageOption(image_info,option+1);
6876 (void) CloneString(&image_info->page,(char *) NULL);
6877 break;
6878 }
6879 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6880 image_option=GetImageOption(image_info,"page");
6881 if (image_option != (const char *) NULL)
6882 flags=ParseAbsoluteGeometry(image_option,&geometry);
6883 canonical_page=GetPageGeometry(argv[i+1]);
6884 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6885 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006886 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006887 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006888 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006889 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006890 (unsigned long) geometry.width,(unsigned long) geometry.height,
6891 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006892 (void) SetImageOption(image_info,option+1,page);
6893 (void) CloneString(&image_info->page,page);
6894 break;
6895 }
cristy3ed852e2009-09-05 21:47:34 +00006896 if (LocaleCompare("ping",option+1) == 0)
6897 {
6898 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6899 break;
6900 }
6901 if (LocaleCompare("pointsize",option+1) == 0)
6902 {
6903 if (*option == '+')
6904 geometry_info.rho=0.0;
6905 else
6906 (void) ParseGeometry(argv[i+1],&geometry_info);
6907 image_info->pointsize=geometry_info.rho;
6908 break;
6909 }
cristye7f51092010-01-17 00:39:37 +00006910 if (LocaleCompare("precision",option+1) == 0)
6911 {
cristybf2766a2010-01-17 03:33:23 +00006912 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006913 break;
6914 }
cristy3ed852e2009-09-05 21:47:34 +00006915 if (LocaleCompare("preview",option+1) == 0)
6916 {
6917 /*
6918 Preview image.
6919 */
6920 if (*option == '+')
6921 {
6922 image_info->preview_type=UndefinedPreview;
6923 break;
6924 }
cristy042ee782011-04-22 18:48:30 +00006925 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006926 MagickPreviewOptions,MagickFalse,argv[i+1]);
6927 break;
6928 }
6929 break;
6930 }
6931 case 'q':
6932 {
6933 if (LocaleCompare("quality",option+1) == 0)
6934 {
6935 /*
6936 Set image compression quality.
6937 */
6938 if (*option == '+')
6939 {
6940 image_info->quality=UndefinedCompressionQuality;
6941 (void) SetImageOption(image_info,option+1,"0");
6942 break;
6943 }
cristye27293e2009-12-18 02:53:20 +00006944 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006945 (void) SetImageOption(image_info,option+1,argv[i+1]);
6946 break;
6947 }
6948 if (LocaleCompare("quiet",option+1) == 0)
6949 {
6950 static WarningHandler
6951 warning_handler = (WarningHandler) NULL;
6952
6953 if (*option == '+')
6954 {
6955 /*
6956 Restore error or warning messages.
6957 */
6958 warning_handler=SetWarningHandler(warning_handler);
6959 break;
6960 }
6961 /*
6962 Suppress error or warning messages.
6963 */
6964 warning_handler=SetWarningHandler((WarningHandler) NULL);
6965 break;
6966 }
6967 break;
6968 }
6969 case 'r':
6970 {
6971 if (LocaleCompare("red-primary",option+1) == 0)
6972 {
6973 if (*option == '+')
6974 {
6975 (void) SetImageOption(image_info,option+1,"0.0");
6976 break;
6977 }
6978 (void) SetImageOption(image_info,option+1,argv[i+1]);
6979 break;
6980 }
6981 break;
6982 }
6983 case 's':
6984 {
6985 if (LocaleCompare("sampling-factor",option+1) == 0)
6986 {
6987 /*
6988 Set image sampling factor.
6989 */
6990 if (*option == '+')
6991 {
6992 if (image_info->sampling_factor != (char *) NULL)
6993 image_info->sampling_factor=DestroyString(
6994 image_info->sampling_factor);
6995 break;
6996 }
6997 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6998 break;
6999 }
7000 if (LocaleCompare("scene",option+1) == 0)
7001 {
7002 /*
7003 Set image scene.
7004 */
7005 if (*option == '+')
7006 {
7007 image_info->scene=0;
7008 (void) SetImageOption(image_info,option+1,"0");
7009 break;
7010 }
cristye27293e2009-12-18 02:53:20 +00007011 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007012 (void) SetImageOption(image_info,option+1,argv[i+1]);
7013 break;
7014 }
7015 if (LocaleCompare("seed",option+1) == 0)
7016 {
cristybb503372010-05-27 20:51:26 +00007017 size_t
cristy3ed852e2009-09-05 21:47:34 +00007018 seed;
7019
7020 if (*option == '+')
7021 {
cristybb503372010-05-27 20:51:26 +00007022 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007023 SeedPseudoRandomGenerator(seed);
7024 break;
7025 }
cristye27293e2009-12-18 02:53:20 +00007026 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007027 SeedPseudoRandomGenerator(seed);
7028 break;
7029 }
7030 if (LocaleCompare("size",option+1) == 0)
7031 {
7032 if (*option == '+')
7033 {
7034 if (image_info->size != (char *) NULL)
7035 image_info->size=DestroyString(image_info->size);
7036 break;
7037 }
7038 (void) CloneString(&image_info->size,argv[i+1]);
7039 break;
7040 }
7041 if (LocaleCompare("stroke",option+1) == 0)
7042 {
7043 if (*option == '+')
7044 {
7045 (void) SetImageOption(image_info,option+1,"none");
7046 break;
7047 }
7048 (void) SetImageOption(image_info,option+1,argv[i+1]);
7049 break;
7050 }
7051 if (LocaleCompare("strokewidth",option+1) == 0)
7052 {
7053 if (*option == '+')
7054 {
7055 (void) SetImageOption(image_info,option+1,"0");
7056 break;
7057 }
7058 (void) SetImageOption(image_info,option+1,argv[i+1]);
7059 break;
7060 }
cristyd9a29192010-10-16 16:49:53 +00007061 if (LocaleCompare("synchronize",option+1) == 0)
7062 {
7063 if (*option == '+')
7064 {
7065 image_info->synchronize=MagickFalse;
7066 break;
7067 }
7068 image_info->synchronize=MagickTrue;
7069 break;
7070 }
cristy3ed852e2009-09-05 21:47:34 +00007071 break;
7072 }
7073 case 't':
7074 {
7075 if (LocaleCompare("taint",option+1) == 0)
7076 {
7077 if (*option == '+')
7078 {
7079 (void) SetImageOption(image_info,option+1,"false");
7080 break;
7081 }
7082 (void) SetImageOption(image_info,option+1,"true");
7083 break;
7084 }
7085 if (LocaleCompare("texture",option+1) == 0)
7086 {
7087 if (*option == '+')
7088 {
7089 if (image_info->texture != (char *) NULL)
7090 image_info->texture=DestroyString(image_info->texture);
7091 break;
7092 }
7093 (void) CloneString(&image_info->texture,argv[i+1]);
7094 break;
7095 }
7096 if (LocaleCompare("tile-offset",option+1) == 0)
7097 {
7098 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007099 (void) SetImageOption(image_info,option+1,"0");
7100 else
7101 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007102 break;
7103 }
7104 if (LocaleCompare("transparent-color",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
cristy9950d572011-10-01 18:22:35 +00007108 (void) QueryColorCompliance("none",AllCompliance,
7109 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007110 (void) SetImageOption(image_info,option+1,"none");
7111 break;
7112 }
cristy9950d572011-10-01 18:22:35 +00007113 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7114 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007115 (void) SetImageOption(image_info,option+1,argv[i+1]);
7116 break;
7117 }
7118 if (LocaleCompare("type",option+1) == 0)
7119 {
7120 if (*option == '+')
7121 {
cristy5f1c1ff2010-12-23 21:38:06 +00007122 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007123 (void) SetImageOption(image_info,option+1,"undefined");
7124 break;
7125 }
cristy042ee782011-04-22 18:48:30 +00007126 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007127 MagickFalse,argv[i+1]);
7128 (void) SetImageOption(image_info,option+1,argv[i+1]);
7129 break;
7130 }
7131 break;
7132 }
7133 case 'u':
7134 {
7135 if (LocaleCompare("undercolor",option+1) == 0)
7136 {
7137 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007138 (void) DeleteImageOption(image_info,option+1);
7139 else
7140 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007141 break;
7142 }
7143 if (LocaleCompare("units",option+1) == 0)
7144 {
7145 if (*option == '+')
7146 {
7147 image_info->units=UndefinedResolution;
7148 (void) SetImageOption(image_info,option+1,"undefined");
7149 break;
7150 }
cristy042ee782011-04-22 18:48:30 +00007151 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007152 MagickResolutionOptions,MagickFalse,argv[i+1]);
7153 (void) SetImageOption(image_info,option+1,argv[i+1]);
7154 break;
7155 }
7156 break;
7157 }
7158 case 'v':
7159 {
7160 if (LocaleCompare("verbose",option+1) == 0)
7161 {
7162 if (*option == '+')
7163 {
7164 image_info->verbose=MagickFalse;
7165 break;
7166 }
7167 image_info->verbose=MagickTrue;
7168 image_info->ping=MagickFalse;
7169 break;
7170 }
7171 if (LocaleCompare("view",option+1) == 0)
7172 {
7173 if (*option == '+')
7174 {
7175 if (image_info->view != (char *) NULL)
7176 image_info->view=DestroyString(image_info->view);
7177 break;
7178 }
7179 (void) CloneString(&image_info->view,argv[i+1]);
7180 break;
7181 }
7182 if (LocaleCompare("virtual-pixel",option+1) == 0)
7183 {
7184 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007185 (void) SetImageOption(image_info,option+1,"undefined");
7186 else
7187 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007188 break;
7189 }
7190 break;
7191 }
7192 case 'w':
7193 {
7194 if (LocaleCompare("white-point",option+1) == 0)
7195 {
7196 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007197 (void) SetImageOption(image_info,option+1,"0.0");
7198 else
7199 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007200 break;
7201 }
7202 break;
7203 }
7204 default:
7205 break;
7206 }
7207 i+=count;
7208 }
7209 return(MagickTrue);
7210}
7211
7212/*
7213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7214% %
7215% %
7216% %
7217+ M o g r i f y I m a g e L i s t %
7218% %
7219% %
7220% %
7221%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7222%
7223% MogrifyImageList() applies any command line options that might affect the
7224% entire image list (e.g. -append, -coalesce, etc.).
7225%
7226% The format of the MogrifyImage method is:
7227%
7228% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7229% const char **argv,Image **images,ExceptionInfo *exception)
7230%
7231% A description of each parameter follows:
7232%
7233% o image_info: the image info..
7234%
7235% o argc: Specifies a pointer to an integer describing the number of
7236% elements in the argument vector.
7237%
7238% o argv: Specifies a pointer to a text array containing the command line
7239% arguments.
7240%
anthonye9c27192011-03-27 08:07:06 +00007241% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007242%
7243% o exception: return any errors or warnings in this structure.
7244%
7245*/
7246WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7247 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7248{
cristy3ed852e2009-09-05 21:47:34 +00007249 const char
7250 *option;
7251
cristy6b3da3a2010-06-20 02:21:46 +00007252 ImageInfo
7253 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007254
7255 MagickStatusType
7256 status;
7257
cristy28474bf2011-09-11 23:32:52 +00007258 PixelInterpolateMethod
7259 interpolate_method;
7260
cristy3ed852e2009-09-05 21:47:34 +00007261 QuantizeInfo
7262 *quantize_info;
7263
cristybb503372010-05-27 20:51:26 +00007264 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007265 i;
7266
cristy6b3da3a2010-06-20 02:21:46 +00007267 ssize_t
7268 count,
7269 index;
7270
cristy3ed852e2009-09-05 21:47:34 +00007271 /*
7272 Apply options to the image list.
7273 */
7274 assert(image_info != (ImageInfo *) NULL);
7275 assert(image_info->signature == MagickSignature);
7276 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007277 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007278 assert((*images)->signature == MagickSignature);
7279 if ((*images)->debug != MagickFalse)
7280 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7281 (*images)->filename);
7282 if ((argc <= 0) || (*argv == (char *) NULL))
7283 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007284 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007285 mogrify_info=CloneImageInfo(image_info);
7286 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007287 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007288 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007289 {
cristy74fe8f12009-10-03 19:09:01 +00007290 if (*images == (Image *) NULL)
7291 break;
cristy3ed852e2009-09-05 21:47:34 +00007292 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007293 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007294 continue;
cristy042ee782011-04-22 18:48:30 +00007295 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007296 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007297 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007298 break;
cristy6b3da3a2010-06-20 02:21:46 +00007299 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007300 switch (*(option+1))
7301 {
7302 case 'a':
7303 {
7304 if (LocaleCompare("affinity",option+1) == 0)
7305 {
cristy6fccee12011-10-20 18:43:18 +00007306 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007307 if (*option == '+')
7308 {
cristy018f07f2011-09-04 21:15:19 +00007309 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7310 exception);
cristy3ed852e2009-09-05 21:47:34 +00007311 break;
7312 }
7313 i++;
7314 break;
7315 }
7316 if (LocaleCompare("append",option+1) == 0)
7317 {
7318 Image
7319 *append_image;
7320
cristy6fccee12011-10-20 18:43:18 +00007321 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007322 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7323 MagickFalse,exception);
7324 if (append_image == (Image *) NULL)
7325 {
7326 status=MagickFalse;
7327 break;
7328 }
7329 *images=DestroyImageList(*images);
7330 *images=append_image;
7331 break;
7332 }
7333 if (LocaleCompare("average",option+1) == 0)
7334 {
7335 Image
7336 *average_image;
7337
cristyd18ae7c2010-03-07 17:39:52 +00007338 /*
7339 Average an image sequence (deprecated).
7340 */
cristy6fccee12011-10-20 18:43:18 +00007341 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007342 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7343 exception);
cristy3ed852e2009-09-05 21:47:34 +00007344 if (average_image == (Image *) NULL)
7345 {
7346 status=MagickFalse;
7347 break;
7348 }
7349 *images=DestroyImageList(*images);
7350 *images=average_image;
7351 break;
7352 }
7353 break;
7354 }
7355 case 'c':
7356 {
7357 if (LocaleCompare("channel",option+1) == 0)
7358 {
cristyf4ad9df2011-07-08 16:49:03 +00007359 ChannelType
7360 channel;
7361
cristy3ed852e2009-09-05 21:47:34 +00007362 if (*option == '+')
7363 {
7364 channel=DefaultChannels;
7365 break;
7366 }
7367 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00007368 SetPixelChannelMapMask(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007369 break;
7370 }
7371 if (LocaleCompare("clut",option+1) == 0)
7372 {
7373 Image
7374 *clut_image,
7375 *image;
7376
cristy6fccee12011-10-20 18:43:18 +00007377 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007378 image=RemoveFirstImageFromList(images);
7379 clut_image=RemoveFirstImageFromList(images);
7380 if (clut_image == (Image *) NULL)
7381 {
7382 status=MagickFalse;
7383 break;
7384 }
cristy28474bf2011-09-11 23:32:52 +00007385 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007386 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007387 *images=DestroyImageList(*images);
7388 *images=image;
7389 break;
7390 }
7391 if (LocaleCompare("coalesce",option+1) == 0)
7392 {
7393 Image
7394 *coalesce_image;
7395
cristy6fccee12011-10-20 18:43:18 +00007396 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007397 coalesce_image=CoalesceImages(*images,exception);
7398 if (coalesce_image == (Image *) NULL)
7399 {
7400 status=MagickFalse;
7401 break;
7402 }
7403 *images=DestroyImageList(*images);
7404 *images=coalesce_image;
7405 break;
7406 }
7407 if (LocaleCompare("combine",option+1) == 0)
7408 {
7409 Image
7410 *combine_image;
7411
cristy6fccee12011-10-20 18:43:18 +00007412 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007413 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007414 if (combine_image == (Image *) NULL)
7415 {
7416 status=MagickFalse;
7417 break;
7418 }
7419 *images=DestroyImageList(*images);
7420 *images=combine_image;
7421 break;
7422 }
7423 if (LocaleCompare("composite",option+1) == 0)
7424 {
7425 Image
7426 *mask_image,
7427 *composite_image,
7428 *image;
7429
7430 RectangleInfo
7431 geometry;
7432
cristy6fccee12011-10-20 18:43:18 +00007433 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007434 image=RemoveFirstImageFromList(images);
7435 composite_image=RemoveFirstImageFromList(images);
7436 if (composite_image == (Image *) NULL)
7437 {
7438 status=MagickFalse;
7439 break;
7440 }
7441 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007442 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007443 SetGeometry(composite_image,&geometry);
7444 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7445 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7446 &geometry);
7447 mask_image=RemoveFirstImageFromList(images);
7448 if (mask_image != (Image *) NULL)
7449 {
7450 if ((image->compose == DisplaceCompositeOp) ||
7451 (image->compose == DistortCompositeOp))
7452 {
7453 /*
7454 Merge Y displacement into X displacement image.
7455 */
7456 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007457 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007458 mask_image=DestroyImage(mask_image);
7459 }
7460 else
7461 {
7462 /*
anthony80c37752012-01-16 01:03:11 +00007463 Set a blending mask for the composition.
7464 Possible problem, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007465 */
7466 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007467 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007468 }
7469 }
cristyf4ad9df2011-07-08 16:49:03 +00007470 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007471 geometry.x,geometry.y,exception);
anthonya129f702011-04-14 01:08:48 +00007472 if (mask_image != (Image *) NULL)
cristyd197cbb2012-01-13 02:14:12 +00007473 {
7474 image->mask=DestroyImage(image->mask);
7475 mask_image=(Image *) NULL;
7476 }
cristy3ed852e2009-09-05 21:47:34 +00007477 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007478 *images=DestroyImageList(*images);
7479 *images=image;
7480 break;
7481 }
cristy3ed852e2009-09-05 21:47:34 +00007482 break;
7483 }
7484 case 'd':
7485 {
7486 if (LocaleCompare("deconstruct",option+1) == 0)
7487 {
7488 Image
7489 *deconstruct_image;
7490
cristy6fccee12011-10-20 18:43:18 +00007491 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007492 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007493 exception);
cristy3ed852e2009-09-05 21:47:34 +00007494 if (deconstruct_image == (Image *) NULL)
7495 {
7496 status=MagickFalse;
7497 break;
7498 }
7499 *images=DestroyImageList(*images);
7500 *images=deconstruct_image;
7501 break;
7502 }
7503 if (LocaleCompare("delete",option+1) == 0)
7504 {
7505 if (*option == '+')
7506 DeleteImages(images,"-1",exception);
7507 else
7508 DeleteImages(images,argv[i+1],exception);
7509 break;
7510 }
7511 if (LocaleCompare("dither",option+1) == 0)
7512 {
7513 if (*option == '+')
7514 {
7515 quantize_info->dither=MagickFalse;
7516 break;
7517 }
7518 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007519 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007520 MagickDitherOptions,MagickFalse,argv[i+1]);
7521 break;
7522 }
cristyecb10ff2011-03-22 13:14:03 +00007523 if (LocaleCompare("duplicate",option+1) == 0)
7524 {
cristy72988482011-03-29 16:34:38 +00007525 Image
7526 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007527
anthony2b6bcae2011-03-23 13:05:34 +00007528 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007529 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7530 else
7531 {
7532 const char
7533 *p;
7534
anthony2b6bcae2011-03-23 13:05:34 +00007535 size_t
7536 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007537
anthony2b6bcae2011-03-23 13:05:34 +00007538 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007539 p=strchr(argv[i+1],',');
7540 if (p == (const char *) NULL)
7541 duplicate_images=DuplicateImages(*images,number_duplicates,
7542 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007543 else
cristy72988482011-03-29 16:34:38 +00007544 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7545 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007546 }
7547 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007548 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007549 break;
7550 }
cristy3ed852e2009-09-05 21:47:34 +00007551 break;
7552 }
cristyd18ae7c2010-03-07 17:39:52 +00007553 case 'e':
7554 {
7555 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7556 {
7557 Image
7558 *evaluate_image;
7559
7560 MagickEvaluateOperator
7561 op;
7562
cristy6fccee12011-10-20 18:43:18 +00007563 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007564 op=(MagickEvaluateOperator) ParseCommandOption(
7565 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007566 evaluate_image=EvaluateImages(*images,op,exception);
7567 if (evaluate_image == (Image *) NULL)
7568 {
7569 status=MagickFalse;
7570 break;
7571 }
7572 *images=DestroyImageList(*images);
7573 *images=evaluate_image;
7574 break;
7575 }
7576 break;
7577 }
cristy3ed852e2009-09-05 21:47:34 +00007578 case 'f':
7579 {
cristyf0a247f2009-10-04 00:20:03 +00007580 if (LocaleCompare("fft",option+1) == 0)
7581 {
7582 Image
7583 *fourier_image;
7584
7585 /*
7586 Implements the discrete Fourier transform (DFT).
7587 */
cristy6fccee12011-10-20 18:43:18 +00007588 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007589 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7590 MagickTrue : MagickFalse,exception);
7591 if (fourier_image == (Image *) NULL)
7592 break;
7593 *images=DestroyImage(*images);
7594 *images=fourier_image;
7595 break;
7596 }
cristy3ed852e2009-09-05 21:47:34 +00007597 if (LocaleCompare("flatten",option+1) == 0)
7598 {
7599 Image
7600 *flatten_image;
7601
cristy6fccee12011-10-20 18:43:18 +00007602 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007603 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7604 if (flatten_image == (Image *) NULL)
7605 break;
7606 *images=DestroyImageList(*images);
7607 *images=flatten_image;
7608 break;
7609 }
7610 if (LocaleCompare("fx",option+1) == 0)
7611 {
7612 Image
7613 *fx_image;
7614
cristy6fccee12011-10-20 18:43:18 +00007615 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007616 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007617 if (fx_image == (Image *) NULL)
7618 {
7619 status=MagickFalse;
7620 break;
7621 }
7622 *images=DestroyImageList(*images);
7623 *images=fx_image;
7624 break;
7625 }
7626 break;
7627 }
7628 case 'h':
7629 {
7630 if (LocaleCompare("hald-clut",option+1) == 0)
7631 {
7632 Image
7633 *hald_image,
7634 *image;
7635
cristy6fccee12011-10-20 18:43:18 +00007636 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007637 image=RemoveFirstImageFromList(images);
7638 hald_image=RemoveFirstImageFromList(images);
7639 if (hald_image == (Image *) NULL)
7640 {
7641 status=MagickFalse;
7642 break;
7643 }
cristy7c0a0a42011-08-23 17:57:25 +00007644 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007645 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007646 if (*images != (Image *) NULL)
7647 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007648 *images=image;
7649 break;
7650 }
7651 break;
7652 }
7653 case 'i':
7654 {
7655 if (LocaleCompare("ift",option+1) == 0)
7656 {
7657 Image
cristy8587f882009-11-13 20:28:49 +00007658 *fourier_image,
7659 *magnitude_image,
7660 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007661
7662 /*
7663 Implements the inverse fourier discrete Fourier transform (DFT).
7664 */
cristy6fccee12011-10-20 18:43:18 +00007665 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007666 magnitude_image=RemoveFirstImageFromList(images);
7667 phase_image=RemoveFirstImageFromList(images);
7668 if (phase_image == (Image *) NULL)
7669 {
7670 status=MagickFalse;
7671 break;
7672 }
7673 fourier_image=InverseFourierTransformImage(magnitude_image,
7674 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007675 if (fourier_image == (Image *) NULL)
7676 break;
cristy0aff6ea2009-11-14 01:40:53 +00007677 if (*images != (Image *) NULL)
7678 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007679 *images=fourier_image;
7680 break;
7681 }
7682 if (LocaleCompare("insert",option+1) == 0)
7683 {
7684 Image
7685 *p,
7686 *q;
7687
7688 index=0;
7689 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007690 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007691 p=RemoveLastImageFromList(images);
7692 if (p == (Image *) NULL)
7693 {
7694 (void) ThrowMagickException(exception,GetMagickModule(),
7695 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7696 status=MagickFalse;
7697 break;
7698 }
7699 q=p;
7700 if (index == 0)
7701 PrependImageToList(images,q);
7702 else
cristybb503372010-05-27 20:51:26 +00007703 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007704 AppendImageToList(images,q);
7705 else
7706 {
7707 q=GetImageFromList(*images,index-1);
7708 if (q == (Image *) NULL)
7709 {
7710 (void) ThrowMagickException(exception,GetMagickModule(),
7711 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7712 status=MagickFalse;
7713 break;
7714 }
7715 InsertImageInList(&q,p);
7716 }
7717 *images=GetFirstImageInList(q);
7718 break;
7719 }
cristy28474bf2011-09-11 23:32:52 +00007720 if (LocaleCompare("interpolate",option+1) == 0)
7721 {
7722 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7723 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7724 break;
7725 }
cristy3ed852e2009-09-05 21:47:34 +00007726 break;
7727 }
7728 case 'l':
7729 {
7730 if (LocaleCompare("layers",option+1) == 0)
7731 {
7732 Image
7733 *layers;
7734
7735 ImageLayerMethod
7736 method;
7737
cristy6fccee12011-10-20 18:43:18 +00007738 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007739 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007740 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007741 MagickFalse,argv[i+1]);
7742 switch (method)
7743 {
7744 case CoalesceLayer:
7745 {
7746 layers=CoalesceImages(*images,exception);
7747 break;
7748 }
7749 case CompareAnyLayer:
7750 case CompareClearLayer:
7751 case CompareOverlayLayer:
7752 default:
7753 {
cristy8a9106f2011-07-05 14:39:26 +00007754 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007755 break;
7756 }
7757 case MergeLayer:
7758 case FlattenLayer:
7759 case MosaicLayer:
7760 case TrimBoundsLayer:
7761 {
7762 layers=MergeImageLayers(*images,method,exception);
7763 break;
7764 }
7765 case DisposeLayer:
7766 {
7767 layers=DisposeImages(*images,exception);
7768 break;
7769 }
7770 case OptimizeImageLayer:
7771 {
7772 layers=OptimizeImageLayers(*images,exception);
7773 break;
7774 }
7775 case OptimizePlusLayer:
7776 {
7777 layers=OptimizePlusImageLayers(*images,exception);
7778 break;
7779 }
7780 case OptimizeTransLayer:
7781 {
7782 OptimizeImageTransparency(*images,exception);
7783 break;
7784 }
7785 case RemoveDupsLayer:
7786 {
7787 RemoveDuplicateLayers(images,exception);
7788 break;
7789 }
7790 case RemoveZeroLayer:
7791 {
7792 RemoveZeroDelayLayers(images,exception);
7793 break;
7794 }
7795 case OptimizeLayer:
7796 {
7797 /*
7798 General Purpose, GIF Animation Optimizer.
7799 */
7800 layers=CoalesceImages(*images,exception);
7801 if (layers == (Image *) NULL)
7802 {
7803 status=MagickFalse;
7804 break;
7805 }
cristy3ed852e2009-09-05 21:47:34 +00007806 *images=DestroyImageList(*images);
7807 *images=layers;
7808 layers=OptimizeImageLayers(*images,exception);
7809 if (layers == (Image *) NULL)
7810 {
7811 status=MagickFalse;
7812 break;
7813 }
cristy3ed852e2009-09-05 21:47:34 +00007814 *images=DestroyImageList(*images);
7815 *images=layers;
7816 layers=(Image *) NULL;
7817 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007818 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7819 exception);
cristy3ed852e2009-09-05 21:47:34 +00007820 break;
7821 }
7822 case CompositeLayer:
7823 {
7824 CompositeOperator
7825 compose;
7826
7827 Image
7828 *source;
7829
7830 RectangleInfo
7831 geometry;
7832
7833 /*
7834 Split image sequence at the first 'NULL:' image.
7835 */
7836 source=(*images);
7837 while (source != (Image *) NULL)
7838 {
7839 source=GetNextImageInList(source);
7840 if ((source != (Image *) NULL) &&
7841 (LocaleCompare(source->magick,"NULL") == 0))
7842 break;
7843 }
7844 if (source != (Image *) NULL)
7845 {
7846 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7847 (GetNextImageInList(source) == (Image *) NULL))
7848 source=(Image *) NULL;
7849 else
7850 {
7851 /*
7852 Separate the two lists, junk the null: image.
7853 */
7854 source=SplitImageList(source->previous);
7855 DeleteImageFromList(&source);
7856 }
7857 }
7858 if (source == (Image *) NULL)
7859 {
7860 (void) ThrowMagickException(exception,GetMagickModule(),
7861 OptionError,"MissingNullSeparator","layers Composite");
7862 status=MagickFalse;
7863 break;
7864 }
7865 /*
7866 Adjust offset with gravity and virtual canvas.
7867 */
7868 SetGeometry(*images,&geometry);
7869 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7870 geometry.width=source->page.width != 0 ?
7871 source->page.width : source->columns;
7872 geometry.height=source->page.height != 0 ?
7873 source->page.height : source->rows;
7874 GravityAdjustGeometry((*images)->page.width != 0 ?
7875 (*images)->page.width : (*images)->columns,
7876 (*images)->page.height != 0 ? (*images)->page.height :
7877 (*images)->rows,(*images)->gravity,&geometry);
7878 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007879 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007880 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007881 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007882 MagickComposeOptions,MagickFalse,option);
7883 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7884 exception);
7885 source=DestroyImageList(source);
7886 break;
7887 }
7888 }
7889 if (layers == (Image *) NULL)
7890 break;
cristy3ed852e2009-09-05 21:47:34 +00007891 *images=DestroyImageList(*images);
7892 *images=layers;
7893 break;
7894 }
7895 break;
7896 }
7897 case 'm':
7898 {
7899 if (LocaleCompare("map",option+1) == 0)
7900 {
cristy6fccee12011-10-20 18:43:18 +00007901 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007902 if (*option == '+')
7903 {
cristy018f07f2011-09-04 21:15:19 +00007904 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7905 exception);
cristy3ed852e2009-09-05 21:47:34 +00007906 break;
7907 }
7908 i++;
7909 break;
7910 }
cristyf40785b2010-03-06 02:27:27 +00007911 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007912 {
7913 Image
cristyf40785b2010-03-06 02:27:27 +00007914 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007915
cristyd18ae7c2010-03-07 17:39:52 +00007916 /*
7917 Maximum image sequence (deprecated).
7918 */
cristy6fccee12011-10-20 18:43:18 +00007919 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007920 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007921 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007922 {
7923 status=MagickFalse;
7924 break;
7925 }
7926 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007927 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007928 break;
7929 }
cristyf40785b2010-03-06 02:27:27 +00007930 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007931 {
7932 Image
cristyf40785b2010-03-06 02:27:27 +00007933 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007934
cristyd18ae7c2010-03-07 17:39:52 +00007935 /*
7936 Minimum image sequence (deprecated).
7937 */
cristy6fccee12011-10-20 18:43:18 +00007938 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007939 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007940 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007941 {
7942 status=MagickFalse;
7943 break;
7944 }
7945 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007946 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007947 break;
7948 }
cristy3ed852e2009-09-05 21:47:34 +00007949 if (LocaleCompare("morph",option+1) == 0)
7950 {
7951 Image
7952 *morph_image;
7953
cristy6fccee12011-10-20 18:43:18 +00007954 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007955 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007956 exception);
7957 if (morph_image == (Image *) NULL)
7958 {
7959 status=MagickFalse;
7960 break;
7961 }
7962 *images=DestroyImageList(*images);
7963 *images=morph_image;
7964 break;
7965 }
7966 if (LocaleCompare("mosaic",option+1) == 0)
7967 {
7968 Image
7969 *mosaic_image;
7970
cristy6fccee12011-10-20 18:43:18 +00007971 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007972 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7973 if (mosaic_image == (Image *) NULL)
7974 {
7975 status=MagickFalse;
7976 break;
7977 }
7978 *images=DestroyImageList(*images);
7979 *images=mosaic_image;
7980 break;
7981 }
7982 break;
7983 }
7984 case 'p':
7985 {
7986 if (LocaleCompare("print",option+1) == 0)
7987 {
7988 char
7989 *string;
7990
cristy6fccee12011-10-20 18:43:18 +00007991 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007992 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7993 exception);
cristy3ed852e2009-09-05 21:47:34 +00007994 if (string == (char *) NULL)
7995 break;
cristyb51dff52011-05-19 16:55:47 +00007996 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007997 string=DestroyString(string);
7998 }
7999 if (LocaleCompare("process",option+1) == 0)
8000 {
8001 char
8002 **arguments;
8003
8004 int
8005 j,
8006 number_arguments;
8007
cristy6fccee12011-10-20 18:43:18 +00008008 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008009 arguments=StringToArgv(argv[i+1],&number_arguments);
8010 if (arguments == (char **) NULL)
8011 break;
8012 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8013 {
8014 char
8015 breaker,
8016 quote,
8017 *token;
8018
8019 const char
8020 *arguments;
8021
8022 int
8023 next,
8024 status;
8025
8026 size_t
8027 length;
8028
8029 TokenInfo
8030 *token_info;
8031
8032 /*
8033 Support old style syntax, filter="-option arg".
8034 */
8035 length=strlen(argv[i+1]);
8036 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008037 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008038 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8039 sizeof(*token));
8040 if (token == (char *) NULL)
8041 break;
8042 next=0;
8043 arguments=argv[i+1];
8044 token_info=AcquireTokenInfo();
8045 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8046 "\"",'\0',&breaker,&next,&quote);
8047 token_info=DestroyTokenInfo(token_info);
8048 if (status == 0)
8049 {
8050 const char
8051 *argv;
8052
8053 argv=(&(arguments[next]));
8054 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8055 exception);
8056 }
8057 token=DestroyString(token);
8058 break;
8059 }
cristy91c0da22010-05-02 01:44:07 +00008060 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008061 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8062 number_arguments-2,(const char **) arguments+2,exception);
8063 for (j=0; j < number_arguments; j++)
8064 arguments[j]=DestroyString(arguments[j]);
8065 arguments=(char **) RelinquishMagickMemory(arguments);
8066 break;
8067 }
8068 break;
8069 }
8070 case 'r':
8071 {
8072 if (LocaleCompare("reverse",option+1) == 0)
8073 {
8074 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008075 break;
8076 }
8077 break;
8078 }
8079 case 's':
8080 {
cristy4285d782011-02-09 20:12:28 +00008081 if (LocaleCompare("smush",option+1) == 0)
8082 {
8083 Image
8084 *smush_image;
8085
8086 ssize_t
8087 offset;
8088
cristy6fccee12011-10-20 18:43:18 +00008089 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008090 offset=(ssize_t) StringToLong(argv[i+1]);
8091 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8092 MagickFalse,offset,exception);
8093 if (smush_image == (Image *) NULL)
8094 {
8095 status=MagickFalse;
8096 break;
8097 }
8098 *images=DestroyImageList(*images);
8099 *images=smush_image;
8100 break;
8101 }
cristy3ed852e2009-09-05 21:47:34 +00008102 if (LocaleCompare("swap",option+1) == 0)
8103 {
8104 Image
8105 *p,
8106 *q,
8107 *swap;
8108
cristybb503372010-05-27 20:51:26 +00008109 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008110 swap_index;
8111
8112 index=(-1);
8113 swap_index=(-2);
8114 if (*option != '+')
8115 {
8116 GeometryInfo
8117 geometry_info;
8118
8119 MagickStatusType
8120 flags;
8121
8122 swap_index=(-1);
8123 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008124 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008125 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008126 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008127 }
8128 p=GetImageFromList(*images,index);
8129 q=GetImageFromList(*images,swap_index);
8130 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8131 {
8132 (void) ThrowMagickException(exception,GetMagickModule(),
8133 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8134 status=MagickFalse;
8135 break;
8136 }
8137 if (p == q)
8138 break;
8139 swap=CloneImage(p,0,0,MagickTrue,exception);
8140 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8141 ReplaceImageInList(&q,swap);
8142 *images=GetFirstImageInList(q);
8143 break;
8144 }
8145 break;
8146 }
8147 case 'w':
8148 {
8149 if (LocaleCompare("write",option+1) == 0)
8150 {
cristy071dd7b2010-04-09 13:04:54 +00008151 char
cristy06609ee2010-03-17 20:21:27 +00008152 key[MaxTextExtent];
8153
cristy3ed852e2009-09-05 21:47:34 +00008154 Image
8155 *write_images;
8156
8157 ImageInfo
8158 *write_info;
8159
cristy6fccee12011-10-20 18:43:18 +00008160 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008161 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008162 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008163 write_images=(*images);
8164 if (*option == '+')
8165 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008166 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008167 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8168 write_info=DestroyImageInfo(write_info);
8169 if (*option == '+')
8170 write_images=DestroyImageList(write_images);
8171 break;
8172 }
8173 break;
8174 }
8175 default:
8176 break;
8177 }
8178 i+=count;
8179 }
8180 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008181 mogrify_info=DestroyImageInfo(mogrify_info);
8182 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008183 return(status != 0 ? MagickTrue : MagickFalse);
8184}
8185
8186/*
8187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8188% %
8189% %
8190% %
8191+ M o g r i f y I m a g e s %
8192% %
8193% %
8194% %
8195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8196%
8197% MogrifyImages() applies image processing options to a sequence of images as
8198% prescribed by command line options.
8199%
8200% The format of the MogrifyImage method is:
8201%
8202% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8203% const MagickBooleanType post,const int argc,const char **argv,
8204% Image **images,Exceptioninfo *exception)
8205%
8206% A description of each parameter follows:
8207%
8208% o image_info: the image info..
8209%
8210% o post: If true, post process image list operators otherwise pre-process.
8211%
8212% o argc: Specifies a pointer to an integer describing the number of
8213% elements in the argument vector.
8214%
8215% o argv: Specifies a pointer to a text array containing the command line
8216% arguments.
8217%
anthonye9c27192011-03-27 08:07:06 +00008218% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008219%
8220% o exception: return any errors or warnings in this structure.
8221%
8222*/
8223WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8224 const MagickBooleanType post,const int argc,const char **argv,
8225 Image **images,ExceptionInfo *exception)
8226{
8227#define MogrifyImageTag "Mogrify/Image"
8228
anthonye9c27192011-03-27 08:07:06 +00008229 MagickStatusType
8230 status;
cristy3ed852e2009-09-05 21:47:34 +00008231
cristy0e9f9c12010-02-11 03:00:47 +00008232 MagickBooleanType
8233 proceed;
8234
anthonye9c27192011-03-27 08:07:06 +00008235 size_t
8236 n;
cristy3ed852e2009-09-05 21:47:34 +00008237
cristybb503372010-05-27 20:51:26 +00008238 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008239 i;
8240
cristy3ed852e2009-09-05 21:47:34 +00008241 assert(image_info != (ImageInfo *) NULL);
8242 assert(image_info->signature == MagickSignature);
8243 if (images == (Image **) NULL)
8244 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008245 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008246 assert((*images)->signature == MagickSignature);
8247 if ((*images)->debug != MagickFalse)
8248 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8249 (*images)->filename);
8250 if ((argc <= 0) || (*argv == (char *) NULL))
8251 return(MagickTrue);
8252 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8253 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008254 status=0;
anthonye9c27192011-03-27 08:07:06 +00008255
anthonyce2716b2011-04-22 09:51:34 +00008256#if 0
cristy1e604812011-05-19 18:07:50 +00008257 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8258 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008259#endif
8260
anthonye9c27192011-03-27 08:07:06 +00008261 /*
8262 Pre-process multi-image sequence operators
8263 */
cristy3ed852e2009-09-05 21:47:34 +00008264 if (post == MagickFalse)
8265 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008266 /*
8267 For each image, process simple single image operators
8268 */
8269 i=0;
8270 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008271 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008272 {
anthonyce2716b2011-04-22 09:51:34 +00008273#if 0
cristy1e604812011-05-19 18:07:50 +00008274 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8275 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008276#endif
anthonye9c27192011-03-27 08:07:06 +00008277 status&=MogrifyImage(image_info,argc,argv,images,exception);
8278 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008279 if (proceed == MagickFalse)
8280 break;
anthonye9c27192011-03-27 08:07:06 +00008281 if ( (*images)->next == (Image *) NULL )
8282 break;
8283 *images=(*images)->next;
8284 i++;
cristy3ed852e2009-09-05 21:47:34 +00008285 }
anthonye9c27192011-03-27 08:07:06 +00008286 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008287#if 0
cristy1e604812011-05-19 18:07:50 +00008288 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8289 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008290#endif
anthonye9c27192011-03-27 08:07:06 +00008291
8292 /*
8293 Post-process, multi-image sequence operators
8294 */
8295 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008296 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008297 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008298 return(status != 0 ? MagickTrue : MagickFalse);
8299}