blob: e0c288c54bb4fcd7d99b01c9acbb390e0a232403 [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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*/
cristyc2e3aeb2011-12-09 11:09:38 +0000111
112static inline double MagickMin(const double x,const double y)
113{
114 if (x < y)
115 return(x);
116 return(y);
117}
118
cristy3980b0d2009-10-25 14:37:13 +0000119WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
120 MagickCommand command,int argc,char **argv,char **metadata,
121 ExceptionInfo *exception)
122{
123 char
124 *option;
125
126 double
127 duration,
cristy8ea926d2011-12-09 12:25:04 +0000128 serial;
cristy3980b0d2009-10-25 14:37:13 +0000129
cristy3980b0d2009-10-25 14:37:13 +0000130 MagickBooleanType
131 concurrent,
132 regard_warnings,
133 status;
134
cristybb503372010-05-27 20:51:26 +0000135 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000136 i;
137
cristybb503372010-05-27 20:51:26 +0000138 size_t
cristyc2e3aeb2011-12-09 11:09:38 +0000139 iterations,
140 n,
141 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000142
cristyd0a94fa2010-03-12 14:18:11 +0000143 (void) setlocale(LC_ALL,"");
144 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000145 concurrent=MagickFalse;
146 duration=(-1.0);
147 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000148 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000149 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000150 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000151 {
152 option=argv[i];
153 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
154 continue;
155 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000156 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000157 if (LocaleCompare("concurrent",option+1) == 0)
158 concurrent=MagickTrue;
159 if (LocaleCompare("debug",option+1) == 0)
160 (void) SetLogEventMask(argv[++i]);
161 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000162 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000163 if (LocaleCompare("regard-warnings",option+1) == 0)
164 regard_warnings=MagickTrue;
165 }
cristy8ea926d2011-12-09 12:25:04 +0000166 if (iterations == 1)
167 {
168 status=command(image_info,argc,argv,metadata,exception);
169 if (exception->severity != UndefinedException)
170 {
171 if ((exception->severity > ErrorException) ||
172 (regard_warnings != MagickFalse))
173 status=MagickTrue;
174 CatchException(exception);
175 }
176 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
177 {
178 (void) fputs(*metadata,stdout);
179 (void) fputc('\n',stdout);
180 *metadata=DestroyString(*metadata);
181 }
182 return(status);
183 }
cristyc2e3aeb2011-12-09 11:09:38 +0000184 number_threads=GetOpenMPMaximumThreads();
cristy8ea926d2011-12-09 12:25:04 +0000185 serial=0.0;
cristyc2e3aeb2011-12-09 11:09:38 +0000186 for (n=1; n <= number_threads; n++)
187 {
188 double
cristy8ea926d2011-12-09 12:25:04 +0000189 e,
190 parallel,
cristyc2e3aeb2011-12-09 11:09:38 +0000191 user_time;
192
193 TimerInfo
194 *timer;
195
196 SetOpenMPMaximumThreads(n);
197 timer=AcquireTimerInfo();
198 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000199 {
cristyc2e3aeb2011-12-09 11:09:38 +0000200 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000201 {
cristyc2e3aeb2011-12-09 11:09:38 +0000202 if (status != MagickFalse)
203 continue;
204 if (duration > 0)
205 {
206 if (GetElapsedTime(timer) > duration)
207 continue;
208 (void) ContinueTimer(timer);
209 }
210 status=command(image_info,argc,argv,metadata,exception);
cristyceae09d2009-10-28 17:18:47 +0000211 if (exception->severity != UndefinedException)
212 {
213 if ((exception->severity > ErrorException) ||
214 (regard_warnings != MagickFalse))
215 status=MagickTrue;
216 CatchException(exception);
217 }
218 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
219 {
220 (void) fputs(*metadata,stdout);
221 (void) fputc('\n',stdout);
222 *metadata=DestroyString(*metadata);
223 }
224 }
225 }
cristyc2e3aeb2011-12-09 11:09:38 +0000226 else
227 {
228 SetOpenMPNested(1);
229#if defined(MAGICKCORE_OPENMP_SUPPORT)
230 # pragma omp parallel for shared(status)
231#endif
232 for (i=0; i < (ssize_t) iterations; i++)
233 {
234 if (status != MagickFalse)
235 continue;
236 if (duration > 0)
237 {
238 if (GetElapsedTime(timer) > duration)
239 continue;
240 (void) ContinueTimer(timer);
241 }
242 status=command(image_info,argc,argv,metadata,exception);
243#if defined(MAGICKCORE_OPENMP_SUPPORT)
244 # pragma omp critical (MagickCore_CommandGenesis)
245#endif
246 {
247 if (exception->severity != UndefinedException)
248 {
249 if ((exception->severity > ErrorException) ||
250 (regard_warnings != MagickFalse))
251 status=MagickTrue;
252 CatchException(exception);
253 }
254 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
255 {
256 (void) fputs(*metadata,stdout);
257 (void) fputc('\n',stdout);
258 *metadata=DestroyString(*metadata);
259 }
260 }
261 }
262 }
cristyc2e3aeb2011-12-09 11:09:38 +0000263 user_time=GetUserTime(timer);
cristy8ea926d2011-12-09 12:25:04 +0000264 parallel=GetElapsedTime(timer);
265 e=1.0;
266 if (n == 1)
267 serial=parallel;
268 else
269 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
270 (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000271 (void) FormatLocaleFile(stderr,
cristy91ce84d2011-12-09 23:02:25 +0000272 "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
cristy8ea926d2011-12-09 12:25:04 +0000273 (double) n,(double) iterations,(double) iterations/parallel,e,
274 user_time,(unsigned long) (parallel/60.0),(unsigned long)
275 floor(fmod(parallel,60.0)),(unsigned long)
276 (1000.0*(parallel-floor(parallel))+0.5));
cristyc2e3aeb2011-12-09 11:09:38 +0000277 timer=DestroyTimerInfo(timer);
278 }
cristy1f9e1ed2009-11-18 04:09:38 +0000279 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000280}
281
282/*
283%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284% %
285% %
286% %
cristy3ed852e2009-09-05 21:47:34 +0000287+ M o g r i f y I m a g e %
288% %
289% %
290% %
291%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292%
anthonye9c27192011-03-27 08:07:06 +0000293% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000294% image that may be part of a large list, but also handles any 'region'
295% image handling.
anthonye9c27192011-03-27 08:07:06 +0000296%
297% The image in the list may be modified in three different ways...
298%
299% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
300% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
301% * replace by a list of images (only the -separate option!)
302%
303% In each case the result is returned into the list, and a pointer to the
304% modified image (last image added if replaced by a list of images) is
305% returned.
306%
307% ASIDE: The -crop is present but restricted to non-tile single image crops
308%
309% This means if all the images are being processed (such as by
310% MogrifyImages(), next image to be processed will be as per the pointer
311% (*image)->next. Also the image list may grow as a result of some specific
312% operations but as images are never merged or deleted, it will never shrink
313% in length. Typically the list will remain the same length.
314%
315% WARNING: As the image pointed to may be replaced, the first image in the
316% list may also change. GetFirstImageInList() should be used by caller if
317% they wish return the Image pointer to the first image in list.
318%
cristy3ed852e2009-09-05 21:47:34 +0000319%
320% The format of the MogrifyImage method is:
321%
322% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
323% const char **argv,Image **image)
324%
325% A description of each parameter follows:
326%
327% o image_info: the image info..
328%
329% o argc: Specifies a pointer to an integer describing the number of
330% elements in the argument vector.
331%
332% o argv: Specifies a pointer to a text array containing the command line
333% arguments.
334%
335% o image: the image.
336%
337% o exception: return any errors or warnings in this structure.
338%
339*/
340
anthonydf8ebac2011-04-27 09:03:19 +0000341static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
342 ExceptionInfo *exception)
343{
344 char
345 key[MaxTextExtent];
346
347 ExceptionInfo
348 *sans_exception;
349
350 Image
351 *image;
352
353 ImageInfo
354 *read_info;
355
cristyfcd785b2011-11-08 01:48:33 +0000356 /*
357 Read an image into a image cache if not already present. Return the image
358 that is in the cache under that filename.
359 */
cristyb51dff52011-05-19 16:55:47 +0000360 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000361 sans_exception=AcquireExceptionInfo();
362 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
363 sans_exception=DestroyExceptionInfo(sans_exception);
364 if (image != (Image *) NULL)
365 return(image);
366 read_info=CloneImageInfo(image_info);
367 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
368 image=ReadImage(read_info,exception);
369 read_info=DestroyImageInfo(read_info);
370 if (image != (Image *) NULL)
371 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
372 return(image);
373}
374
cristy3ed852e2009-09-05 21:47:34 +0000375static MagickBooleanType IsPathWritable(const char *path)
376{
377 if (IsPathAccessible(path) == MagickFalse)
378 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000379 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000380 return(MagickFalse);
381 return(MagickTrue);
382}
383
cristybb503372010-05-27 20:51:26 +0000384static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000385{
386 if (x > y)
387 return(x);
388 return(y);
389}
390
anthonydf8ebac2011-04-27 09:03:19 +0000391static MagickBooleanType MonitorProgress(const char *text,
392 const MagickOffsetType offset,const MagickSizeType extent,
393 void *wand_unused(client_data))
394{
395 char
396 message[MaxTextExtent],
397 tag[MaxTextExtent];
398
399 const char
400 *locale_message;
401
402 register char
403 *p;
404
405 if (extent < 2)
406 return(MagickTrue);
407 (void) CopyMagickMemory(tag,text,MaxTextExtent);
408 p=strrchr(tag,'/');
409 if (p != (char *) NULL)
410 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000411 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000412 locale_message=GetLocaleMessage(message);
413 if (locale_message == message)
414 locale_message=tag;
415 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000416 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
417 locale_message,(long) offset,(unsigned long) extent,(long)
418 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000419 else
cristyb51dff52011-05-19 16:55:47 +0000420 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000421 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
422 (100L*offset/(extent-1)));
423 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000424 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000425 (void) fflush(stderr);
426 return(MagickTrue);
427}
428
cristy3884f692011-07-08 18:00:18 +0000429static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000430 const SparseColorMethod method,const char *arguments,
431 const MagickBooleanType color_from_image,ExceptionInfo *exception)
432{
anthonydf8ebac2011-04-27 09:03:19 +0000433 char
434 token[MaxTextExtent];
435
436 const char
437 *p;
438
439 double
440 *sparse_arguments;
441
anthonydf8ebac2011-04-27 09:03:19 +0000442 Image
443 *sparse_image;
444
cristy4c08aed2011-07-01 19:47:50 +0000445 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000446 color;
447
448 MagickBooleanType
449 error;
450
cristy5f09d852011-05-29 01:39:29 +0000451 register size_t
452 x;
453
454 size_t
455 number_arguments,
456 number_colors;
457
cristyf4425a72011-11-08 01:52:04 +0000458 /*
459 SparseColorOption() parses the complex -sparse-color argument into an an
460 array of floating point values then calls SparseColorImage(). Argument is
461 a complex mix of floating-point pixel coodinates, and color specifications
462 (or direct floating point numbers). The number of floats needed to
463 represent a color varies depending on the current channel setting.
464 */
anthonydf8ebac2011-04-27 09:03:19 +0000465 assert(image != (Image *) NULL);
466 assert(image->signature == MagickSignature);
467 if (image->debug != MagickFalse)
468 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
469 assert(exception != (ExceptionInfo *) NULL);
470 assert(exception->signature == MagickSignature);
471 /*
472 Limit channels according to image - and add up number of color channel.
473 */
anthonydf8ebac2011-04-27 09:03:19 +0000474 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000475 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000476 number_colors++;
cristyed231572011-07-14 02:18:59 +0000477 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000478 number_colors++;
cristyed231572011-07-14 02:18:59 +0000479 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000480 number_colors++;
cristyed231572011-07-14 02:18:59 +0000481 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000482 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000483 number_colors++;
cristyed231572011-07-14 02:18:59 +0000484 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000485 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000486 number_colors++;
487
488 /*
489 Read string, to determine number of arguments needed,
490 */
491 p=arguments;
492 x=0;
493 while( *p != '\0' )
494 {
495 GetMagickToken(p,&p,token);
496 if ( token[0] == ',' ) continue;
497 if ( isalpha((int) token[0]) || token[0] == '#' ) {
498 if ( color_from_image ) {
499 (void) ThrowMagickException(exception,GetMagickModule(),
500 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
501 "Color arg given, when colors are coming from image");
502 return( (Image *)NULL);
503 }
504 x += number_colors; /* color argument */
505 }
506 else {
507 x++; /* floating point argument */
508 }
509 }
510 error=MagickTrue;
511 if ( color_from_image ) {
512 /* just the control points are being given */
513 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
514 number_arguments=(x/2)*(2+number_colors);
515 }
516 else {
517 /* control points and color values */
518 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
519 number_arguments=x;
520 }
521 if ( error ) {
522 (void) ThrowMagickException(exception,GetMagickModule(),
523 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
524 "Invalid number of Arguments");
525 return( (Image *)NULL);
526 }
527
528 /* Allocate and fill in the floating point arguments */
529 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
530 sizeof(*sparse_arguments));
531 if (sparse_arguments == (double *) NULL) {
532 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
533 "MemoryAllocationFailed","%s","SparseColorOption");
534 return( (Image *)NULL);
535 }
536 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
537 sizeof(*sparse_arguments));
538 p=arguments;
539 x=0;
540 while( *p != '\0' && x < number_arguments ) {
541 /* X coordinate */
542 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
543 if ( token[0] == '\0' ) break;
544 if ( isalpha((int) token[0]) || token[0] == '#' ) {
545 (void) ThrowMagickException(exception,GetMagickModule(),
546 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
547 "Color found, instead of X-coord");
548 error = MagickTrue;
549 break;
550 }
cristydbdd0e32011-11-04 23:29:40 +0000551 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000552 /* Y coordinate */
553 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
554 if ( token[0] == '\0' ) break;
555 if ( isalpha((int) token[0]) || token[0] == '#' ) {
556 (void) ThrowMagickException(exception,GetMagickModule(),
557 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
558 "Color found, instead of Y-coord");
559 error = MagickTrue;
560 break;
561 }
cristydbdd0e32011-11-04 23:29:40 +0000562 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000563 /* color values for this control point */
564#if 0
565 if ( (color_from_image ) {
566 /* get color from image */
567 /* HOW??? */
568 }
569 else
570#endif
571 {
572 /* color name or function given in string argument */
573 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
574 if ( token[0] == '\0' ) break;
575 if ( isalpha((int) token[0]) || token[0] == '#' ) {
576 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000577 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000578 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000579 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000580 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000581 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000582 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000583 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000584 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000585 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000586 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000587 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000588 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000589 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000590 }
591 else {
592 /* Colors given as a set of floating point values - experimental */
593 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000594 if ((GetPixelRedTraits(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 ((GetPixelGreenTraits(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 ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000611 {
anthonydf8ebac2011-04-27 09:03:19 +0000612 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
613 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
614 break;
cristydbdd0e32011-11-04 23:29:40 +0000615 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000616 token[0] = ','; /* used this token - get another */
617 }
cristyed231572011-07-14 02:18:59 +0000618 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000619 (image->colorspace == CMYKColorspace))
620 {
anthonydf8ebac2011-04-27 09:03:19 +0000621 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
622 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
623 break;
cristydbdd0e32011-11-04 23:29:40 +0000624 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000625 token[0] = ','; /* used this token - get another */
626 }
cristyed231572011-07-14 02:18:59 +0000627 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000628 (image->matte != MagickFalse))
629 {
anthonydf8ebac2011-04-27 09:03:19 +0000630 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
631 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
632 break;
cristydbdd0e32011-11-04 23:29:40 +0000633 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000634 token[0] = ','; /* used this token - get another */
635 }
636 }
637 }
638 }
639 if ( number_arguments != x && !error ) {
640 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
641 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
642 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
643 return( (Image *)NULL);
644 }
645 if ( error )
646 return( (Image *)NULL);
647
648 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000649 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
650 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000651 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
652 return( sparse_image );
653}
654
cristy3ed852e2009-09-05 21:47:34 +0000655WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
656 const char **argv,Image **image,ExceptionInfo *exception)
657{
anthonydf8ebac2011-04-27 09:03:19 +0000658 ChannelType
659 channel;
660
cristy633f0c62011-09-15 13:27:36 +0000661 CompositeOperator
662 compose;
663
anthonydf8ebac2011-04-27 09:03:19 +0000664 const char
665 *format,
666 *option;
667
cristy9ed1f812011-10-08 02:00:08 +0000668 double
669 attenuate;
670
anthonydf8ebac2011-04-27 09:03:19 +0000671 DrawInfo
672 *draw_info;
673
674 GeometryInfo
675 geometry_info;
676
cristy3ed852e2009-09-05 21:47:34 +0000677 Image
678 *region_image;
679
anthonydf8ebac2011-04-27 09:03:19 +0000680 ImageInfo
681 *mogrify_info;
682
cristyebbcfea2011-02-25 02:43:54 +0000683 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000684 status;
685
cristy4c08aed2011-07-01 19:47:50 +0000686 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000687 fill;
cristy3ed852e2009-09-05 21:47:34 +0000688
anthonydf8ebac2011-04-27 09:03:19 +0000689 MagickStatusType
690 flags;
691
cristy28474bf2011-09-11 23:32:52 +0000692 PixelInterpolateMethod
693 interpolate_method;
694
anthonydf8ebac2011-04-27 09:03:19 +0000695 QuantizeInfo
696 *quantize_info;
697
698 RectangleInfo
699 geometry,
700 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000701
cristybb503372010-05-27 20:51:26 +0000702 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000703 i;
704
705 /*
706 Initialize method variables.
707 */
708 assert(image_info != (const ImageInfo *) NULL);
709 assert(image_info->signature == MagickSignature);
710 assert(image != (Image **) NULL);
711 assert((*image)->signature == MagickSignature);
712 if ((*image)->debug != MagickFalse)
713 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
714 if (argc < 0)
715 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000716 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000717 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
718 quantize_info=AcquireQuantizeInfo(mogrify_info);
719 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000720 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000721 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000722 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000723 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000724 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000725 channel=mogrify_info->channel;
726 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000727 SetGeometry(*image,&region_geometry);
728 region_image=NewImageList();
729 /*
730 Transmogrify the image.
731 */
cristybb503372010-05-27 20:51:26 +0000732 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000733 {
anthonydf8ebac2011-04-27 09:03:19 +0000734 Image
735 *mogrify_image;
736
anthonye9c27192011-03-27 08:07:06 +0000737 ssize_t
738 count;
739
anthonydf8ebac2011-04-27 09:03:19 +0000740 option=argv[i];
741 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000742 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000743 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
744 0L);
cristycee97112010-05-28 00:44:52 +0000745 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000746 break;
cristy6b3da3a2010-06-20 02:21:46 +0000747 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000748 mogrify_image=(Image *)NULL;
749 switch (*(option+1))
750 {
751 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000752 {
anthonydf8ebac2011-04-27 09:03:19 +0000753 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000754 {
anthonydf8ebac2011-04-27 09:03:19 +0000755 /*
756 Adaptive blur image.
757 */
cristy6fccee12011-10-20 18:43:18 +0000758 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000759 flags=ParseGeometry(argv[i+1],&geometry_info);
760 if ((flags & SigmaValue) == 0)
761 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000762 if ((flags & XiValue) == 0)
763 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000764 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000765 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000766 break;
cristy3ed852e2009-09-05 21:47:34 +0000767 }
anthonydf8ebac2011-04-27 09:03:19 +0000768 if (LocaleCompare("adaptive-resize",option+1) == 0)
769 {
770 /*
771 Adaptive resize image.
772 */
cristy6fccee12011-10-20 18:43:18 +0000773 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000774 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
775 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000776 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000777 break;
778 }
779 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
780 {
781 /*
782 Adaptive sharpen image.
783 */
cristy6fccee12011-10-20 18:43:18 +0000784 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000785 flags=ParseGeometry(argv[i+1],&geometry_info);
786 if ((flags & SigmaValue) == 0)
787 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000788 if ((flags & XiValue) == 0)
789 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000790 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000791 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000792 break;
793 }
794 if (LocaleCompare("affine",option+1) == 0)
795 {
796 /*
797 Affine matrix.
798 */
799 if (*option == '+')
800 {
801 GetAffineMatrix(&draw_info->affine);
802 break;
803 }
804 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
805 break;
806 }
807 if (LocaleCompare("alpha",option+1) == 0)
808 {
809 AlphaChannelType
810 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000811
cristy6fccee12011-10-20 18:43:18 +0000812 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000813 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
814 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000815 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000816 break;
817 }
818 if (LocaleCompare("annotate",option+1) == 0)
819 {
820 char
821 *text,
822 geometry[MaxTextExtent];
823
824 /*
825 Annotate image.
826 */
cristy6fccee12011-10-20 18:43:18 +0000827 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000828 SetGeometryInfo(&geometry_info);
829 flags=ParseGeometry(argv[i+1],&geometry_info);
830 if ((flags & SigmaValue) == 0)
831 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000832 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
833 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000834 if (text == (char *) NULL)
835 break;
836 (void) CloneString(&draw_info->text,text);
837 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000838 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000839 geometry_info.xi,geometry_info.psi);
840 (void) CloneString(&draw_info->geometry,geometry);
841 draw_info->affine.sx=cos(DegreesToRadians(
842 fmod(geometry_info.rho,360.0)));
843 draw_info->affine.rx=sin(DegreesToRadians(
844 fmod(geometry_info.rho,360.0)));
845 draw_info->affine.ry=(-sin(DegreesToRadians(
846 fmod(geometry_info.sigma,360.0))));
847 draw_info->affine.sy=cos(DegreesToRadians(
848 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000849 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000850 break;
851 }
852 if (LocaleCompare("antialias",option+1) == 0)
853 {
854 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
855 MagickFalse;
856 draw_info->text_antialias=(*option == '-') ? MagickTrue :
857 MagickFalse;
858 break;
859 }
cristy9ed1f812011-10-08 02:00:08 +0000860 if (LocaleCompare("attenuate",option+1) == 0)
861 {
862 if (*option == '+')
863 {
864 attenuate=1.0;
865 break;
866 }
cristydbdd0e32011-11-04 23:29:40 +0000867 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000868 break;
869 }
anthonydf8ebac2011-04-27 09:03:19 +0000870 if (LocaleCompare("auto-gamma",option+1) == 0)
871 {
872 /*
873 Auto Adjust Gamma of image based on its mean
874 */
cristy6fccee12011-10-20 18:43:18 +0000875 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000876 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000877 break;
878 }
879 if (LocaleCompare("auto-level",option+1) == 0)
880 {
881 /*
882 Perfectly Normalize (max/min stretch) the image
883 */
cristy6fccee12011-10-20 18:43:18 +0000884 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000885 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000886 break;
887 }
888 if (LocaleCompare("auto-orient",option+1) == 0)
889 {
cristy6fccee12011-10-20 18:43:18 +0000890 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000891 switch ((*image)->orientation)
892 {
893 case TopRightOrientation:
894 {
895 mogrify_image=FlopImage(*image,exception);
896 break;
897 }
898 case BottomRightOrientation:
899 {
900 mogrify_image=RotateImage(*image,180.0,exception);
901 break;
902 }
903 case BottomLeftOrientation:
904 {
905 mogrify_image=FlipImage(*image,exception);
906 break;
907 }
908 case LeftTopOrientation:
909 {
910 mogrify_image=TransposeImage(*image,exception);
911 break;
912 }
913 case RightTopOrientation:
914 {
915 mogrify_image=RotateImage(*image,90.0,exception);
916 break;
917 }
918 case RightBottomOrientation:
919 {
920 mogrify_image=TransverseImage(*image,exception);
921 break;
922 }
923 case LeftBottomOrientation:
924 {
925 mogrify_image=RotateImage(*image,270.0,exception);
926 break;
927 }
928 default:
929 break;
930 }
931 if (mogrify_image != (Image *) NULL)
932 mogrify_image->orientation=TopLeftOrientation;
933 break;
934 }
935 break;
936 }
937 case 'b':
938 {
939 if (LocaleCompare("black-threshold",option+1) == 0)
940 {
941 /*
942 Black threshold image.
943 */
cristy6fccee12011-10-20 18:43:18 +0000944 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000945 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000946 break;
947 }
948 if (LocaleCompare("blue-shift",option+1) == 0)
949 {
950 /*
951 Blue shift image.
952 */
cristy6fccee12011-10-20 18:43:18 +0000953 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000954 geometry_info.rho=1.5;
955 if (*option == '-')
956 flags=ParseGeometry(argv[i+1],&geometry_info);
957 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
958 break;
959 }
960 if (LocaleCompare("blur",option+1) == 0)
961 {
962 /*
963 Gaussian blur image.
964 */
cristy6fccee12011-10-20 18:43:18 +0000965 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000966 flags=ParseGeometry(argv[i+1],&geometry_info);
967 if ((flags & SigmaValue) == 0)
968 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000969 if ((flags & XiValue) == 0)
970 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000971 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000972 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000973 break;
974 }
975 if (LocaleCompare("border",option+1) == 0)
976 {
977 /*
978 Surround image with a border of solid color.
979 */
cristy6fccee12011-10-20 18:43:18 +0000980 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000981 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
982 if ((flags & SigmaValue) == 0)
983 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000984 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000985 break;
986 }
987 if (LocaleCompare("bordercolor",option+1) == 0)
988 {
989 if (*option == '+')
990 {
cristy9950d572011-10-01 18:22:35 +0000991 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000992 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000993 break;
994 }
cristy9950d572011-10-01 18:22:35 +0000995 (void) QueryColorCompliance(argv[i+1],AllCompliance,
996 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000997 break;
998 }
999 if (LocaleCompare("box",option+1) == 0)
1000 {
cristy9950d572011-10-01 18:22:35 +00001001 (void) QueryColorCompliance(argv[i+1],AllCompliance,
1002 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001003 break;
1004 }
1005 if (LocaleCompare("brightness-contrast",option+1) == 0)
1006 {
1007 double
1008 brightness,
1009 contrast;
1010
1011 GeometryInfo
1012 geometry_info;
1013
1014 MagickStatusType
1015 flags;
1016
1017 /*
1018 Brightness / contrast image.
1019 */
cristy6fccee12011-10-20 18:43:18 +00001020 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001021 flags=ParseGeometry(argv[i+1],&geometry_info);
1022 brightness=geometry_info.rho;
1023 contrast=0.0;
1024 if ((flags & SigmaValue) != 0)
1025 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001026 (void) BrightnessContrastImage(*image,brightness,contrast,
1027 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001028 break;
1029 }
1030 break;
1031 }
1032 case 'c':
1033 {
1034 if (LocaleCompare("cdl",option+1) == 0)
1035 {
1036 char
1037 *color_correction_collection;
1038
1039 /*
1040 Color correct with a color decision list.
1041 */
cristy6fccee12011-10-20 18:43:18 +00001042 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001043 color_correction_collection=FileToString(argv[i+1],~0,exception);
1044 if (color_correction_collection == (char *) NULL)
1045 break;
cristy1bfa9f02011-08-11 02:35:43 +00001046 (void) ColorDecisionListImage(*image,color_correction_collection,
1047 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001048 break;
1049 }
1050 if (LocaleCompare("channel",option+1) == 0)
1051 {
1052 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001053 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001054 else
cristyfa806a72011-07-04 02:06:13 +00001055 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00001056 SetPixelChannelMapMask(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001057 break;
1058 }
1059 if (LocaleCompare("charcoal",option+1) == 0)
1060 {
1061 /*
1062 Charcoal image.
1063 */
cristy6fccee12011-10-20 18:43:18 +00001064 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001065 flags=ParseGeometry(argv[i+1],&geometry_info);
1066 if ((flags & SigmaValue) == 0)
1067 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001068 if ((flags & XiValue) == 0)
1069 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001070 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001071 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001072 break;
1073 }
1074 if (LocaleCompare("chop",option+1) == 0)
1075 {
1076 /*
1077 Chop the image.
1078 */
cristy6fccee12011-10-20 18:43:18 +00001079 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001080 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1081 mogrify_image=ChopImage(*image,&geometry,exception);
1082 break;
1083 }
1084 if (LocaleCompare("clamp",option+1) == 0)
1085 {
1086 /*
1087 Clamp image.
1088 */
cristy6fccee12011-10-20 18:43:18 +00001089 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001090 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001091 break;
1092 }
1093 if (LocaleCompare("clip",option+1) == 0)
1094 {
cristy6fccee12011-10-20 18:43:18 +00001095 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001096 if (*option == '+')
1097 {
cristy018f07f2011-09-04 21:15:19 +00001098 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001099 break;
1100 }
cristy018f07f2011-09-04 21:15:19 +00001101 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001102 break;
1103 }
1104 if (LocaleCompare("clip-mask",option+1) == 0)
1105 {
1106 CacheView
1107 *mask_view;
1108
1109 Image
1110 *mask_image;
1111
cristy4c08aed2011-07-01 19:47:50 +00001112 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001113 *restrict q;
1114
1115 register ssize_t
1116 x;
1117
1118 ssize_t
1119 y;
1120
cristy6fccee12011-10-20 18:43:18 +00001121 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001122 if (*option == '+')
1123 {
1124 /*
1125 Remove a mask.
1126 */
cristy018f07f2011-09-04 21:15:19 +00001127 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001128 break;
1129 }
1130 /*
1131 Set the image mask.
1132 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1133 */
1134 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1135 if (mask_image == (Image *) NULL)
1136 break;
cristy574cc262011-08-05 01:23:58 +00001137 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001138 return(MagickFalse);
1139 mask_view=AcquireCacheView(mask_image);
1140 for (y=0; y < (ssize_t) mask_image->rows; y++)
1141 {
1142 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1143 exception);
cristyacd2ed22011-08-30 01:44:23 +00001144 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001145 break;
1146 for (x=0; x < (ssize_t) mask_image->columns; x++)
1147 {
1148 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001149 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1150 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1151 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1152 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001153 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001154 }
1155 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1156 break;
1157 }
1158 mask_view=DestroyCacheView(mask_view);
1159 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001160 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001161 break;
1162 }
1163 if (LocaleCompare("clip-path",option+1) == 0)
1164 {
cristy6fccee12011-10-20 18:43:18 +00001165 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001166 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001167 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001168 break;
1169 }
1170 if (LocaleCompare("colorize",option+1) == 0)
1171 {
1172 /*
1173 Colorize the image.
1174 */
cristy6fccee12011-10-20 18:43:18 +00001175 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001176 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001177 break;
1178 }
1179 if (LocaleCompare("color-matrix",option+1) == 0)
1180 {
1181 KernelInfo
1182 *kernel;
1183
cristy6fccee12011-10-20 18:43:18 +00001184 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001185 kernel=AcquireKernelInfo(argv[i+1]);
1186 if (kernel == (KernelInfo *) NULL)
1187 break;
1188 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1189 kernel=DestroyKernelInfo(kernel);
1190 break;
1191 }
1192 if (LocaleCompare("colors",option+1) == 0)
1193 {
1194 /*
1195 Reduce the number of colors in the image.
1196 */
cristy6fccee12011-10-20 18:43:18 +00001197 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001198 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1199 if (quantize_info->number_colors == 0)
1200 break;
1201 if (((*image)->storage_class == DirectClass) ||
1202 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001203 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001204 else
cristy018f07f2011-09-04 21:15:19 +00001205 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001206 break;
1207 }
1208 if (LocaleCompare("colorspace",option+1) == 0)
1209 {
1210 ColorspaceType
1211 colorspace;
1212
cristy6fccee12011-10-20 18:43:18 +00001213 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001214 if (*option == '+')
1215 {
cristye941a752011-10-15 01:52:48 +00001216 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001217 break;
1218 }
1219 colorspace=(ColorspaceType) ParseCommandOption(
1220 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001221 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001222 break;
1223 }
cristy633f0c62011-09-15 13:27:36 +00001224 if (LocaleCompare("compose",option+1) == 0)
1225 {
cristy6fccee12011-10-20 18:43:18 +00001226 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001227 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1228 MagickFalse,argv[i+1]);
1229 break;
1230 }
anthonydf8ebac2011-04-27 09:03:19 +00001231 if (LocaleCompare("contrast",option+1) == 0)
1232 {
cristy6fccee12011-10-20 18:43:18 +00001233 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001234 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001235 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001236 break;
1237 }
1238 if (LocaleCompare("contrast-stretch",option+1) == 0)
1239 {
1240 double
1241 black_point,
1242 white_point;
1243
1244 MagickStatusType
1245 flags;
1246
1247 /*
1248 Contrast stretch image.
1249 */
cristy6fccee12011-10-20 18:43:18 +00001250 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001251 flags=ParseGeometry(argv[i+1],&geometry_info);
1252 black_point=geometry_info.rho;
1253 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1254 black_point;
1255 if ((flags & PercentValue) != 0)
1256 {
1257 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1258 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1259 }
1260 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1261 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001262 (void) ContrastStretchImage(*image,black_point,white_point,
1263 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001264 break;
1265 }
1266 if (LocaleCompare("convolve",option+1) == 0)
1267 {
anthonydf8ebac2011-04-27 09:03:19 +00001268 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001269 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001270
cristy6fccee12011-10-20 18:43:18 +00001271 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001272 kernel_info=AcquireKernelInfo(argv[i+1]);
1273 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001274 break;
cristy0a922382011-07-16 15:30:34 +00001275 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001276 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001277 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001278 break;
1279 }
1280 if (LocaleCompare("crop",option+1) == 0)
1281 {
1282 /*
1283 Crop a image to a smaller size
1284 */
cristy6fccee12011-10-20 18:43:18 +00001285 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001286 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001287 break;
1288 }
1289 if (LocaleCompare("cycle",option+1) == 0)
1290 {
1291 /*
1292 Cycle an image colormap.
1293 */
cristy6fccee12011-10-20 18:43:18 +00001294 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001295 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1296 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001297 break;
1298 }
1299 break;
1300 }
1301 case 'd':
1302 {
1303 if (LocaleCompare("decipher",option+1) == 0)
1304 {
1305 StringInfo
1306 *passkey;
1307
1308 /*
1309 Decipher pixels.
1310 */
cristy6fccee12011-10-20 18:43:18 +00001311 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001312 passkey=FileToStringInfo(argv[i+1],~0,exception);
1313 if (passkey != (StringInfo *) NULL)
1314 {
1315 (void) PasskeyDecipherImage(*image,passkey,exception);
1316 passkey=DestroyStringInfo(passkey);
1317 }
1318 break;
1319 }
1320 if (LocaleCompare("density",option+1) == 0)
1321 {
1322 /*
1323 Set image density.
1324 */
1325 (void) CloneString(&draw_info->density,argv[i+1]);
1326 break;
1327 }
1328 if (LocaleCompare("depth",option+1) == 0)
1329 {
cristy6fccee12011-10-20 18:43:18 +00001330 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001331 if (*option == '+')
1332 {
cristy8a11cb12011-10-19 23:53:34 +00001333 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001334 break;
1335 }
cristy8a11cb12011-10-19 23:53:34 +00001336 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1337 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001338 break;
1339 }
1340 if (LocaleCompare("deskew",option+1) == 0)
1341 {
1342 double
1343 threshold;
1344
1345 /*
1346 Straighten the image.
1347 */
cristy6fccee12011-10-20 18:43:18 +00001348 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001349 if (*option == '+')
1350 threshold=40.0*QuantumRange/100.0;
1351 else
cristy9b34e302011-11-05 02:15:45 +00001352 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1353 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001354 mogrify_image=DeskewImage(*image,threshold,exception);
1355 break;
1356 }
1357 if (LocaleCompare("despeckle",option+1) == 0)
1358 {
1359 /*
1360 Reduce the speckles within an image.
1361 */
cristy6fccee12011-10-20 18:43:18 +00001362 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001363 mogrify_image=DespeckleImage(*image,exception);
1364 break;
1365 }
1366 if (LocaleCompare("display",option+1) == 0)
1367 {
1368 (void) CloneString(&draw_info->server_name,argv[i+1]);
1369 break;
1370 }
1371 if (LocaleCompare("distort",option+1) == 0)
1372 {
1373 char
1374 *args,
1375 token[MaxTextExtent];
1376
1377 const char
1378 *p;
1379
1380 DistortImageMethod
1381 method;
1382
1383 double
1384 *arguments;
1385
1386 register ssize_t
1387 x;
1388
1389 size_t
1390 number_arguments;
1391
1392 /*
1393 Distort image.
1394 */
cristy6fccee12011-10-20 18:43:18 +00001395 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001396 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1397 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001398 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001399 {
anthonydf8ebac2011-04-27 09:03:19 +00001400 double
1401 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001402
1403 /*
1404 Special Case - Argument is actually a resize geometry!
1405 Convert that to an appropriate distortion argument array.
1406 */
anthonydf8ebac2011-04-27 09:03:19 +00001407 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001408 exception);
1409 resize_args[0]=(double) geometry.width;
1410 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001411 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001412 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001413 break;
1414 }
cristy018f07f2011-09-04 21:15:19 +00001415 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1416 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001417 if (args == (char *) NULL)
1418 break;
1419 p=(char *) args;
1420 for (x=0; *p != '\0'; x++)
1421 {
1422 GetMagickToken(p,&p,token);
1423 if (*token == ',')
1424 GetMagickToken(p,&p,token);
1425 }
1426 number_arguments=(size_t) x;
1427 arguments=(double *) AcquireQuantumMemory(number_arguments,
1428 sizeof(*arguments));
1429 if (arguments == (double *) NULL)
1430 ThrowWandFatalException(ResourceLimitFatalError,
1431 "MemoryAllocationFailed",(*image)->filename);
1432 (void) ResetMagickMemory(arguments,0,number_arguments*
1433 sizeof(*arguments));
1434 p=(char *) args;
1435 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1436 {
1437 GetMagickToken(p,&p,token);
1438 if (*token == ',')
1439 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001440 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001441 }
1442 args=DestroyString(args);
1443 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1444 (*option == '+') ? MagickTrue : MagickFalse,exception);
1445 arguments=(double *) RelinquishMagickMemory(arguments);
1446 break;
1447 }
1448 if (LocaleCompare("dither",option+1) == 0)
1449 {
1450 if (*option == '+')
1451 {
1452 quantize_info->dither=MagickFalse;
1453 break;
1454 }
1455 quantize_info->dither=MagickTrue;
1456 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1457 MagickDitherOptions,MagickFalse,argv[i+1]);
1458 if (quantize_info->dither_method == NoDitherMethod)
1459 quantize_info->dither=MagickFalse;
1460 break;
1461 }
1462 if (LocaleCompare("draw",option+1) == 0)
1463 {
1464 /*
1465 Draw image.
1466 */
cristy6fccee12011-10-20 18:43:18 +00001467 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001468 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001469 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001470 break;
1471 }
1472 break;
1473 }
1474 case 'e':
1475 {
1476 if (LocaleCompare("edge",option+1) == 0)
1477 {
1478 /*
1479 Enhance edges in the image.
1480 */
cristy6fccee12011-10-20 18:43:18 +00001481 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001482 flags=ParseGeometry(argv[i+1],&geometry_info);
1483 if ((flags & SigmaValue) == 0)
1484 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001485 mogrify_image=EdgeImage(*image,geometry_info.rho,
1486 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001487 break;
1488 }
1489 if (LocaleCompare("emboss",option+1) == 0)
1490 {
1491 /*
1492 Gaussian embossen image.
1493 */
cristy6fccee12011-10-20 18:43:18 +00001494 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001495 flags=ParseGeometry(argv[i+1],&geometry_info);
1496 if ((flags & SigmaValue) == 0)
1497 geometry_info.sigma=1.0;
1498 mogrify_image=EmbossImage(*image,geometry_info.rho,
1499 geometry_info.sigma,exception);
1500 break;
1501 }
1502 if (LocaleCompare("encipher",option+1) == 0)
1503 {
1504 StringInfo
1505 *passkey;
1506
1507 /*
1508 Encipher pixels.
1509 */
cristy6fccee12011-10-20 18:43:18 +00001510 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001511 passkey=FileToStringInfo(argv[i+1],~0,exception);
1512 if (passkey != (StringInfo *) NULL)
1513 {
1514 (void) PasskeyEncipherImage(*image,passkey,exception);
1515 passkey=DestroyStringInfo(passkey);
1516 }
1517 break;
1518 }
1519 if (LocaleCompare("encoding",option+1) == 0)
1520 {
1521 (void) CloneString(&draw_info->encoding,argv[i+1]);
1522 break;
1523 }
1524 if (LocaleCompare("enhance",option+1) == 0)
1525 {
1526 /*
1527 Enhance image.
1528 */
cristy6fccee12011-10-20 18:43:18 +00001529 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001530 mogrify_image=EnhanceImage(*image,exception);
1531 break;
1532 }
1533 if (LocaleCompare("equalize",option+1) == 0)
1534 {
1535 /*
1536 Equalize image.
1537 */
cristy6fccee12011-10-20 18:43:18 +00001538 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001539 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001540 break;
1541 }
1542 if (LocaleCompare("evaluate",option+1) == 0)
1543 {
1544 double
1545 constant;
1546
1547 MagickEvaluateOperator
1548 op;
1549
cristy6fccee12011-10-20 18:43:18 +00001550 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001551 op=(MagickEvaluateOperator) ParseCommandOption(
1552 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001553 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1554 1.0);
cristyd42d9952011-07-08 14:21:50 +00001555 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001556 break;
1557 }
1558 if (LocaleCompare("extent",option+1) == 0)
1559 {
1560 /*
1561 Set the image extent.
1562 */
cristy6fccee12011-10-20 18:43:18 +00001563 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001564 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1565 if (geometry.width == 0)
1566 geometry.width=(*image)->columns;
1567 if (geometry.height == 0)
1568 geometry.height=(*image)->rows;
1569 mogrify_image=ExtentImage(*image,&geometry,exception);
1570 break;
1571 }
1572 break;
1573 }
1574 case 'f':
1575 {
1576 if (LocaleCompare("family",option+1) == 0)
1577 {
1578 if (*option == '+')
1579 {
1580 if (draw_info->family != (char *) NULL)
1581 draw_info->family=DestroyString(draw_info->family);
1582 break;
1583 }
1584 (void) CloneString(&draw_info->family,argv[i+1]);
1585 break;
1586 }
1587 if (LocaleCompare("features",option+1) == 0)
1588 {
1589 if (*option == '+')
1590 {
1591 (void) DeleteImageArtifact(*image,"identify:features");
1592 break;
1593 }
1594 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1595 break;
1596 }
1597 if (LocaleCompare("fill",option+1) == 0)
1598 {
1599 ExceptionInfo
1600 *sans;
1601
cristy4c08aed2011-07-01 19:47:50 +00001602 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001603 if (*option == '+')
1604 {
cristy269c9412011-10-13 23:41:15 +00001605 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001606 exception);
1607 (void) QueryColorCompliance("none",AllCompliance,
1608 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001609 if (draw_info->fill_pattern != (Image *) NULL)
1610 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1611 break;
1612 }
1613 sans=AcquireExceptionInfo();
cristy269c9412011-10-13 23:41:15 +00001614 (void) QueryColorCompliance(argv[i+1],AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001615 sans);
1616 status=QueryColorCompliance(argv[i+1],AllCompliance,
1617 &draw_info->fill,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001618 sans=DestroyExceptionInfo(sans);
1619 if (status == MagickFalse)
1620 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1621 exception);
1622 break;
1623 }
1624 if (LocaleCompare("flip",option+1) == 0)
1625 {
1626 /*
1627 Flip image scanlines.
1628 */
cristy6fccee12011-10-20 18:43:18 +00001629 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001630 mogrify_image=FlipImage(*image,exception);
1631 break;
1632 }
anthonydf8ebac2011-04-27 09:03:19 +00001633 if (LocaleCompare("floodfill",option+1) == 0)
1634 {
cristy4c08aed2011-07-01 19:47:50 +00001635 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001636 target;
1637
1638 /*
1639 Floodfill image.
1640 */
cristy6fccee12011-10-20 18:43:18 +00001641 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001642 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001643 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001644 exception);
cristyd42d9952011-07-08 14:21:50 +00001645 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001646 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001647 break;
1648 }
anthony3d2f4862011-05-01 13:48:16 +00001649 if (LocaleCompare("flop",option+1) == 0)
1650 {
1651 /*
1652 Flop image scanlines.
1653 */
cristy6fccee12011-10-20 18:43:18 +00001654 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001655 mogrify_image=FlopImage(*image,exception);
1656 break;
1657 }
anthonydf8ebac2011-04-27 09:03:19 +00001658 if (LocaleCompare("font",option+1) == 0)
1659 {
1660 if (*option == '+')
1661 {
1662 if (draw_info->font != (char *) NULL)
1663 draw_info->font=DestroyString(draw_info->font);
1664 break;
1665 }
1666 (void) CloneString(&draw_info->font,argv[i+1]);
1667 break;
1668 }
1669 if (LocaleCompare("format",option+1) == 0)
1670 {
1671 format=argv[i+1];
1672 break;
1673 }
1674 if (LocaleCompare("frame",option+1) == 0)
1675 {
1676 FrameInfo
1677 frame_info;
1678
1679 /*
1680 Surround image with an ornamental border.
1681 */
cristy6fccee12011-10-20 18:43:18 +00001682 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001683 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1684 frame_info.width=geometry.width;
1685 frame_info.height=geometry.height;
1686 if ((flags & HeightValue) == 0)
1687 frame_info.height=geometry.width;
1688 frame_info.outer_bevel=geometry.x;
1689 frame_info.inner_bevel=geometry.y;
1690 frame_info.x=(ssize_t) frame_info.width;
1691 frame_info.y=(ssize_t) frame_info.height;
1692 frame_info.width=(*image)->columns+2*frame_info.width;
1693 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001694 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001695 break;
1696 }
1697 if (LocaleCompare("function",option+1) == 0)
1698 {
1699 char
1700 *arguments,
1701 token[MaxTextExtent];
1702
1703 const char
1704 *p;
1705
1706 double
1707 *parameters;
1708
1709 MagickFunction
1710 function;
1711
1712 register ssize_t
1713 x;
1714
1715 size_t
1716 number_parameters;
1717
1718 /*
1719 Function Modify Image Values
1720 */
cristy6fccee12011-10-20 18:43:18 +00001721 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001722 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1723 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001724 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1725 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001726 if (arguments == (char *) NULL)
1727 break;
1728 p=(char *) arguments;
1729 for (x=0; *p != '\0'; x++)
1730 {
1731 GetMagickToken(p,&p,token);
1732 if (*token == ',')
1733 GetMagickToken(p,&p,token);
1734 }
1735 number_parameters=(size_t) x;
1736 parameters=(double *) AcquireQuantumMemory(number_parameters,
1737 sizeof(*parameters));
1738 if (parameters == (double *) NULL)
1739 ThrowWandFatalException(ResourceLimitFatalError,
1740 "MemoryAllocationFailed",(*image)->filename);
1741 (void) ResetMagickMemory(parameters,0,number_parameters*
1742 sizeof(*parameters));
1743 p=(char *) arguments;
1744 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1745 {
1746 GetMagickToken(p,&p,token);
1747 if (*token == ',')
1748 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001749 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001750 }
1751 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001752 (void) FunctionImage(*image,function,number_parameters,parameters,
1753 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001754 parameters=(double *) RelinquishMagickMemory(parameters);
1755 break;
1756 }
1757 break;
1758 }
1759 case 'g':
1760 {
1761 if (LocaleCompare("gamma",option+1) == 0)
1762 {
1763 /*
1764 Gamma image.
1765 */
cristy6fccee12011-10-20 18:43:18 +00001766 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001767 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001768 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001769 else
cristydbdd0e32011-11-04 23:29:40 +00001770 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001771 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001772 break;
1773 }
1774 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1775 (LocaleCompare("gaussian",option+1) == 0))
1776 {
1777 /*
1778 Gaussian blur image.
1779 */
cristy6fccee12011-10-20 18:43:18 +00001780 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001781 flags=ParseGeometry(argv[i+1],&geometry_info);
1782 if ((flags & SigmaValue) == 0)
1783 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001784 if ((flags & XiValue) == 0)
1785 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001786 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001787 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001788 break;
1789 }
1790 if (LocaleCompare("geometry",option+1) == 0)
1791 {
1792 /*
1793 Record Image offset, Resize last image.
1794 */
cristy6fccee12011-10-20 18:43:18 +00001795 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001796 if (*option == '+')
1797 {
1798 if ((*image)->geometry != (char *) NULL)
1799 (*image)->geometry=DestroyString((*image)->geometry);
1800 break;
1801 }
1802 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1803 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1804 (void) CloneString(&(*image)->geometry,argv[i+1]);
1805 else
1806 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1807 (*image)->filter,(*image)->blur,exception);
1808 break;
1809 }
1810 if (LocaleCompare("gravity",option+1) == 0)
1811 {
1812 if (*option == '+')
1813 {
1814 draw_info->gravity=UndefinedGravity;
1815 break;
1816 }
1817 draw_info->gravity=(GravityType) ParseCommandOption(
1818 MagickGravityOptions,MagickFalse,argv[i+1]);
1819 break;
1820 }
1821 break;
1822 }
1823 case 'h':
1824 {
1825 if (LocaleCompare("highlight-color",option+1) == 0)
1826 {
1827 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1828 break;
1829 }
1830 break;
1831 }
1832 case 'i':
1833 {
1834 if (LocaleCompare("identify",option+1) == 0)
1835 {
1836 char
1837 *text;
1838
cristy6fccee12011-10-20 18:43:18 +00001839 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001840 if (format == (char *) NULL)
1841 {
cristya4037272011-08-28 15:11:39 +00001842 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1843 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001844 break;
1845 }
cristy018f07f2011-09-04 21:15:19 +00001846 text=InterpretImageProperties(mogrify_info,*image,format,
1847 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001848 if (text == (char *) NULL)
1849 break;
1850 (void) fputs(text,stdout);
1851 (void) fputc('\n',stdout);
1852 text=DestroyString(text);
1853 break;
1854 }
1855 if (LocaleCompare("implode",option+1) == 0)
1856 {
1857 /*
1858 Implode image.
1859 */
cristy6fccee12011-10-20 18:43:18 +00001860 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001861 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001862 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1863 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001864 break;
1865 }
1866 if (LocaleCompare("interline-spacing",option+1) == 0)
1867 {
1868 if (*option == '+')
1869 (void) ParseGeometry("0",&geometry_info);
1870 else
1871 (void) ParseGeometry(argv[i+1],&geometry_info);
1872 draw_info->interline_spacing=geometry_info.rho;
1873 break;
1874 }
cristy28474bf2011-09-11 23:32:52 +00001875 if (LocaleCompare("interpolate",option+1) == 0)
1876 {
1877 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1878 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1879 break;
1880 }
anthonydf8ebac2011-04-27 09:03:19 +00001881 if (LocaleCompare("interword-spacing",option+1) == 0)
1882 {
1883 if (*option == '+')
1884 (void) ParseGeometry("0",&geometry_info);
1885 else
1886 (void) ParseGeometry(argv[i+1],&geometry_info);
1887 draw_info->interword_spacing=geometry_info.rho;
1888 break;
1889 }
1890 break;
1891 }
1892 case 'k':
1893 {
1894 if (LocaleCompare("kerning",option+1) == 0)
1895 {
1896 if (*option == '+')
1897 (void) ParseGeometry("0",&geometry_info);
1898 else
1899 (void) ParseGeometry(argv[i+1],&geometry_info);
1900 draw_info->kerning=geometry_info.rho;
1901 break;
1902 }
1903 break;
1904 }
1905 case 'l':
1906 {
1907 if (LocaleCompare("lat",option+1) == 0)
1908 {
1909 /*
1910 Local adaptive threshold image.
1911 */
cristy6fccee12011-10-20 18:43:18 +00001912 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001913 flags=ParseGeometry(argv[i+1],&geometry_info);
1914 if ((flags & PercentValue) != 0)
1915 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1916 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001917 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001918 geometry_info.xi,exception);
1919 break;
1920 }
1921 if (LocaleCompare("level",option+1) == 0)
1922 {
1923 MagickRealType
1924 black_point,
1925 gamma,
1926 white_point;
1927
1928 MagickStatusType
1929 flags;
1930
1931 /*
1932 Parse levels.
1933 */
cristy6fccee12011-10-20 18:43:18 +00001934 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001935 flags=ParseGeometry(argv[i+1],&geometry_info);
1936 black_point=geometry_info.rho;
1937 white_point=(MagickRealType) QuantumRange;
1938 if ((flags & SigmaValue) != 0)
1939 white_point=geometry_info.sigma;
1940 gamma=1.0;
1941 if ((flags & XiValue) != 0)
1942 gamma=geometry_info.xi;
1943 if ((flags & PercentValue) != 0)
1944 {
1945 black_point*=(MagickRealType) (QuantumRange/100.0);
1946 white_point*=(MagickRealType) (QuantumRange/100.0);
1947 }
1948 if ((flags & SigmaValue) == 0)
1949 white_point=(MagickRealType) QuantumRange-black_point;
1950 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001951 (void) LevelizeImage(*image,black_point,white_point,gamma,
1952 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001953 else
cristy01e9afd2011-08-10 17:38:41 +00001954 (void) LevelImage(*image,black_point,white_point,gamma,
1955 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001956 break;
1957 }
1958 if (LocaleCompare("level-colors",option+1) == 0)
1959 {
1960 char
1961 token[MaxTextExtent];
1962
1963 const char
1964 *p;
1965
cristy4c08aed2011-07-01 19:47:50 +00001966 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001967 black_point,
1968 white_point;
1969
1970 p=(const char *) argv[i+1];
1971 GetMagickToken(p,&p,token); /* get black point color */
1972 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001973 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001974 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001975 else
cristy269c9412011-10-13 23:41:15 +00001976 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001977 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001978 if (isalpha((int) token[0]) || (token[0] == '#'))
1979 GetMagickToken(p,&p,token);
1980 if (*token == '\0')
1981 white_point=black_point; /* set everything to that color */
1982 else
1983 {
1984 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1985 GetMagickToken(p,&p,token); /* Get white point color. */
1986 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001987 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001988 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001989 else
cristy269c9412011-10-13 23:41:15 +00001990 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001991 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001992 }
cristy490408a2011-07-07 14:42:05 +00001993 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001994 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001995 break;
1996 }
1997 if (LocaleCompare("linear-stretch",option+1) == 0)
1998 {
1999 double
2000 black_point,
2001 white_point;
2002
2003 MagickStatusType
2004 flags;
2005
cristy6fccee12011-10-20 18:43:18 +00002006 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002007 flags=ParseGeometry(argv[i+1],&geometry_info);
2008 black_point=geometry_info.rho;
2009 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2010 if ((flags & SigmaValue) != 0)
2011 white_point=geometry_info.sigma;
2012 if ((flags & PercentValue) != 0)
2013 {
2014 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2015 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2016 }
2017 if ((flags & SigmaValue) == 0)
2018 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2019 black_point;
cristy33bd5152011-08-24 01:42:24 +00002020 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002021 break;
2022 }
2023 if (LocaleCompare("linewidth",option+1) == 0)
2024 {
cristy9b34e302011-11-05 02:15:45 +00002025 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002026 break;
2027 }
2028 if (LocaleCompare("liquid-rescale",option+1) == 0)
2029 {
2030 /*
2031 Liquid rescale image.
2032 */
cristy6fccee12011-10-20 18:43:18 +00002033 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002034 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2035 if ((flags & XValue) == 0)
2036 geometry.x=1;
2037 if ((flags & YValue) == 0)
2038 geometry.y=0;
2039 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2040 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2041 break;
2042 }
2043 if (LocaleCompare("lowlight-color",option+1) == 0)
2044 {
2045 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2046 break;
2047 }
2048 break;
2049 }
2050 case 'm':
2051 {
2052 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002053 {
cristy3ed852e2009-09-05 21:47:34 +00002054 Image
anthonydf8ebac2011-04-27 09:03:19 +00002055 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002056
anthonydf8ebac2011-04-27 09:03:19 +00002057 /*
2058 Transform image colors to match this set of colors.
2059 */
cristy6fccee12011-10-20 18:43:18 +00002060 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002061 if (*option == '+')
2062 break;
2063 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2064 if (remap_image == (Image *) NULL)
2065 break;
cristy018f07f2011-09-04 21:15:19 +00002066 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002067 remap_image=DestroyImage(remap_image);
2068 break;
2069 }
2070 if (LocaleCompare("mask",option+1) == 0)
2071 {
2072 Image
2073 *mask;
2074
cristy6fccee12011-10-20 18:43:18 +00002075 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002076 if (*option == '+')
2077 {
2078 /*
2079 Remove a mask.
2080 */
cristy018f07f2011-09-04 21:15:19 +00002081 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002082 break;
2083 }
2084 /*
2085 Set the image mask.
2086 */
2087 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2088 if (mask == (Image *) NULL)
2089 break;
cristy018f07f2011-09-04 21:15:19 +00002090 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002091 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002092 break;
2093 }
2094 if (LocaleCompare("matte",option+1) == 0)
2095 {
2096 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002097 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002098 break;
2099 }
2100 if (LocaleCompare("median",option+1) == 0)
2101 {
2102 /*
2103 Median filter image.
2104 */
cristy6fccee12011-10-20 18:43:18 +00002105 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002106 flags=ParseGeometry(argv[i+1],&geometry_info);
2107 if ((flags & SigmaValue) == 0)
2108 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002109 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002110 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002111 break;
2112 }
2113 if (LocaleCompare("mode",option+1) == 0)
2114 {
2115 /*
2116 Mode image.
2117 */
cristy6fccee12011-10-20 18:43:18 +00002118 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002119 flags=ParseGeometry(argv[i+1],&geometry_info);
2120 if ((flags & SigmaValue) == 0)
2121 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002122 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002123 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002124 break;
2125 }
2126 if (LocaleCompare("modulate",option+1) == 0)
2127 {
cristy6fccee12011-10-20 18:43:18 +00002128 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002129 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002130 break;
2131 }
2132 if (LocaleCompare("monitor",option+1) == 0)
2133 {
2134 if (*option == '+')
2135 {
2136 (void) SetImageProgressMonitor(*image,
2137 (MagickProgressMonitor) NULL,(void *) NULL);
2138 break;
2139 }
2140 (void) SetImageProgressMonitor(*image,MonitorProgress,
2141 (void *) NULL);
2142 break;
2143 }
2144 if (LocaleCompare("monochrome",option+1) == 0)
2145 {
cristy6fccee12011-10-20 18:43:18 +00002146 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002147 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002148 break;
2149 }
2150 if (LocaleCompare("morphology",option+1) == 0)
2151 {
2152 char
2153 token[MaxTextExtent];
2154
2155 const char
2156 *p;
2157
2158 KernelInfo
2159 *kernel;
2160
2161 MorphologyMethod
2162 method;
2163
2164 ssize_t
2165 iterations;
2166
2167 /*
2168 Morphological Image Operation
2169 */
cristy6fccee12011-10-20 18:43:18 +00002170 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002171 p=argv[i+1];
2172 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002173 method=(MorphologyMethod) ParseCommandOption(
2174 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002175 iterations=1L;
2176 GetMagickToken(p,&p,token);
2177 if ((*p == ':') || (*p == ','))
2178 GetMagickToken(p,&p,token);
2179 if ((*p != '\0'))
2180 iterations=(ssize_t) StringToLong(p);
2181 kernel=AcquireKernelInfo(argv[i+2]);
2182 if (kernel == (KernelInfo *) NULL)
2183 {
2184 (void) ThrowMagickException(exception,GetMagickModule(),
2185 OptionError,"UnabletoParseKernel","morphology");
2186 status=MagickFalse;
2187 break;
2188 }
cristyf4ad9df2011-07-08 16:49:03 +00002189 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2190 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002191 kernel=DestroyKernelInfo(kernel);
2192 break;
2193 }
2194 if (LocaleCompare("motion-blur",option+1) == 0)
2195 {
2196 /*
2197 Motion blur image.
2198 */
cristy6fccee12011-10-20 18:43:18 +00002199 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002200 flags=ParseGeometry(argv[i+1],&geometry_info);
2201 if ((flags & SigmaValue) == 0)
2202 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002203 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002204 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002205 break;
2206 }
2207 break;
2208 }
2209 case 'n':
2210 {
2211 if (LocaleCompare("negate",option+1) == 0)
2212 {
cristy6fccee12011-10-20 18:43:18 +00002213 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002214 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002215 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002216 break;
2217 }
2218 if (LocaleCompare("noise",option+1) == 0)
2219 {
cristy6fccee12011-10-20 18:43:18 +00002220 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002221 if (*option == '-')
2222 {
cristyf36cbcb2011-09-07 13:28:22 +00002223 flags=ParseGeometry(argv[i+1],&geometry_info);
2224 if ((flags & SigmaValue) == 0)
2225 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002226 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002227 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002228 }
2229 else
2230 {
2231 NoiseType
2232 noise;
2233
2234 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2235 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002236 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002237 }
2238 break;
2239 }
2240 if (LocaleCompare("normalize",option+1) == 0)
2241 {
cristy6fccee12011-10-20 18:43:18 +00002242 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002243 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002244 break;
2245 }
2246 break;
2247 }
2248 case 'o':
2249 {
2250 if (LocaleCompare("opaque",option+1) == 0)
2251 {
cristy4c08aed2011-07-01 19:47:50 +00002252 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002253 target;
2254
cristy6fccee12011-10-20 18:43:18 +00002255 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002256 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002257 exception);
cristyd42d9952011-07-08 14:21:50 +00002258 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002259 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002260 break;
2261 }
2262 if (LocaleCompare("ordered-dither",option+1) == 0)
2263 {
cristy6fccee12011-10-20 18:43:18 +00002264 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002265 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002266 break;
2267 }
2268 break;
2269 }
2270 case 'p':
2271 {
2272 if (LocaleCompare("paint",option+1) == 0)
2273 {
cristy6fccee12011-10-20 18:43:18 +00002274 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002275 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002276 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2277 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002278 break;
2279 }
2280 if (LocaleCompare("pen",option+1) == 0)
2281 {
2282 if (*option == '+')
2283 {
cristy9950d572011-10-01 18:22:35 +00002284 (void) QueryColorCompliance("none",AllCompliance,
2285 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002286 break;
2287 }
cristy9950d572011-10-01 18:22:35 +00002288 (void) QueryColorCompliance(argv[i+1],AllCompliance,
2289 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002290 break;
2291 }
2292 if (LocaleCompare("pointsize",option+1) == 0)
2293 {
2294 if (*option == '+')
2295 (void) ParseGeometry("12",&geometry_info);
2296 else
2297 (void) ParseGeometry(argv[i+1],&geometry_info);
2298 draw_info->pointsize=geometry_info.rho;
2299 break;
2300 }
2301 if (LocaleCompare("polaroid",option+1) == 0)
2302 {
cristye9e3d382011-12-14 01:50:13 +00002303 const char
2304 *caption;
2305
anthonydf8ebac2011-04-27 09:03:19 +00002306 double
2307 angle;
2308
2309 RandomInfo
2310 *random_info;
2311
2312 /*
2313 Simulate a Polaroid picture.
2314 */
cristy6fccee12011-10-20 18:43:18 +00002315 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002316 random_info=AcquireRandomInfo();
2317 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2318 random_info=DestroyRandomInfo(random_info);
2319 if (*option == '-')
2320 {
2321 SetGeometryInfo(&geometry_info);
2322 flags=ParseGeometry(argv[i+1],&geometry_info);
2323 angle=geometry_info.rho;
2324 }
cristye9e3d382011-12-14 01:50:13 +00002325 caption=GetImageProperty(*image,"caption",exception);
2326 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002327 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002328 break;
2329 }
2330 if (LocaleCompare("posterize",option+1) == 0)
2331 {
2332 /*
2333 Posterize image.
2334 */
cristy6fccee12011-10-20 18:43:18 +00002335 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002336 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002337 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002338 break;
2339 }
2340 if (LocaleCompare("preview",option+1) == 0)
2341 {
2342 PreviewType
2343 preview_type;
2344
2345 /*
2346 Preview image.
2347 */
cristy6fccee12011-10-20 18:43:18 +00002348 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002349 if (*option == '+')
2350 preview_type=UndefinedPreview;
2351 else
cristy28474bf2011-09-11 23:32:52 +00002352 preview_type=(PreviewType) ParseCommandOption(
2353 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002354 mogrify_image=PreviewImage(*image,preview_type,exception);
2355 break;
2356 }
2357 if (LocaleCompare("profile",option+1) == 0)
2358 {
2359 const char
2360 *name;
2361
2362 const StringInfo
2363 *profile;
2364
2365 Image
2366 *profile_image;
2367
2368 ImageInfo
2369 *profile_info;
2370
cristy6fccee12011-10-20 18:43:18 +00002371 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002372 if (*option == '+')
2373 {
2374 /*
2375 Remove a profile from the image.
2376 */
2377 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002378 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002379 break;
2380 }
2381 /*
2382 Associate a profile with the image.
2383 */
2384 profile_info=CloneImageInfo(mogrify_info);
2385 profile=GetImageProfile(*image,"iptc");
2386 if (profile != (StringInfo *) NULL)
2387 profile_info->profile=(void *) CloneStringInfo(profile);
2388 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2389 profile_info=DestroyImageInfo(profile_info);
2390 if (profile_image == (Image *) NULL)
2391 {
2392 StringInfo
2393 *profile;
2394
2395 profile_info=CloneImageInfo(mogrify_info);
2396 (void) CopyMagickString(profile_info->filename,argv[i+1],
2397 MaxTextExtent);
2398 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2399 if (profile != (StringInfo *) NULL)
2400 {
2401 (void) ProfileImage(*image,profile_info->magick,
2402 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002403 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002404 profile=DestroyStringInfo(profile);
2405 }
2406 profile_info=DestroyImageInfo(profile_info);
2407 break;
2408 }
2409 ResetImageProfileIterator(profile_image);
2410 name=GetNextImageProfile(profile_image);
2411 while (name != (const char *) NULL)
2412 {
2413 profile=GetImageProfile(profile_image,name);
2414 if (profile != (StringInfo *) NULL)
2415 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002416 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002417 name=GetNextImageProfile(profile_image);
2418 }
2419 profile_image=DestroyImage(profile_image);
2420 break;
2421 }
2422 break;
2423 }
2424 case 'q':
2425 {
2426 if (LocaleCompare("quantize",option+1) == 0)
2427 {
2428 if (*option == '+')
2429 {
2430 quantize_info->colorspace=UndefinedColorspace;
2431 break;
2432 }
2433 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2434 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2435 break;
2436 }
2437 break;
2438 }
2439 case 'r':
2440 {
2441 if (LocaleCompare("radial-blur",option+1) == 0)
2442 {
2443 /*
2444 Radial blur image.
2445 */
cristy6fccee12011-10-20 18:43:18 +00002446 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002447 flags=ParseGeometry(argv[i+1],&geometry_info);
2448 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2449 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002450 break;
2451 }
2452 if (LocaleCompare("raise",option+1) == 0)
2453 {
2454 /*
2455 Surround image with a raise of solid color.
2456 */
2457 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2458 if ((flags & SigmaValue) == 0)
2459 geometry.height=geometry.width;
2460 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002461 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002462 break;
2463 }
2464 if (LocaleCompare("random-threshold",option+1) == 0)
2465 {
2466 /*
2467 Threshold image.
2468 */
cristy6fccee12011-10-20 18:43:18 +00002469 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002470 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002471 break;
2472 }
2473 if (LocaleCompare("recolor",option+1) == 0)
2474 {
2475 KernelInfo
2476 *kernel;
2477
cristy6fccee12011-10-20 18:43:18 +00002478 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002479 kernel=AcquireKernelInfo(argv[i+1]);
2480 if (kernel == (KernelInfo *) NULL)
2481 break;
2482 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2483 kernel=DestroyKernelInfo(kernel);
2484 break;
2485 }
2486 if (LocaleCompare("region",option+1) == 0)
2487 {
cristy6fccee12011-10-20 18:43:18 +00002488 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002489 if (region_image != (Image *) NULL)
2490 {
2491 /*
2492 Composite region.
2493 */
2494 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002495 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002496 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002497 *image=DestroyImage(*image);
2498 *image=region_image;
2499 region_image = (Image *) NULL;
2500 }
2501 if (*option == '+')
2502 break;
2503 /*
2504 Apply transformations to a selected region of the image.
2505 */
cristy3ed852e2009-09-05 21:47:34 +00002506 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2507 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002508 mogrify_image=CropImage(*image,&region_geometry,exception);
2509 if (mogrify_image == (Image *) NULL)
2510 break;
2511 region_image=(*image);
2512 *image=mogrify_image;
2513 mogrify_image=(Image *) NULL;
2514 break;
cristy3ed852e2009-09-05 21:47:34 +00002515 }
anthonydf8ebac2011-04-27 09:03:19 +00002516 if (LocaleCompare("render",option+1) == 0)
2517 {
cristy6fccee12011-10-20 18:43:18 +00002518 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002519 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2520 break;
2521 }
2522 if (LocaleCompare("remap",option+1) == 0)
2523 {
2524 Image
2525 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002526
anthonydf8ebac2011-04-27 09:03:19 +00002527 /*
2528 Transform image colors to match this set of colors.
2529 */
cristy6fccee12011-10-20 18:43:18 +00002530 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002531 if (*option == '+')
2532 break;
2533 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2534 if (remap_image == (Image *) NULL)
2535 break;
cristy018f07f2011-09-04 21:15:19 +00002536 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002537 remap_image=DestroyImage(remap_image);
2538 break;
2539 }
2540 if (LocaleCompare("repage",option+1) == 0)
2541 {
2542 if (*option == '+')
2543 {
2544 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2545 break;
2546 }
2547 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002548 break;
2549 }
2550 if (LocaleCompare("resample",option+1) == 0)
2551 {
2552 /*
2553 Resample image.
2554 */
cristy6fccee12011-10-20 18:43:18 +00002555 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002556 flags=ParseGeometry(argv[i+1],&geometry_info);
2557 if ((flags & SigmaValue) == 0)
2558 geometry_info.sigma=geometry_info.rho;
2559 mogrify_image=ResampleImage(*image,geometry_info.rho,
2560 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2561 break;
2562 }
2563 if (LocaleCompare("resize",option+1) == 0)
2564 {
2565 /*
2566 Resize image.
2567 */
cristy6fccee12011-10-20 18:43:18 +00002568 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002569 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2570 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2571 (*image)->filter,(*image)->blur,exception);
2572 break;
2573 }
2574 if (LocaleCompare("roll",option+1) == 0)
2575 {
2576 /*
2577 Roll image.
2578 */
cristy6fccee12011-10-20 18:43:18 +00002579 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002580 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2581 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2582 break;
2583 }
2584 if (LocaleCompare("rotate",option+1) == 0)
2585 {
2586 char
2587 *geometry;
2588
2589 /*
2590 Check for conditional image rotation.
2591 */
cristy6fccee12011-10-20 18:43:18 +00002592 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002593 if (strchr(argv[i+1],'>') != (char *) NULL)
2594 if ((*image)->columns <= (*image)->rows)
2595 break;
2596 if (strchr(argv[i+1],'<') != (char *) NULL)
2597 if ((*image)->columns >= (*image)->rows)
2598 break;
2599 /*
2600 Rotate image.
2601 */
2602 geometry=ConstantString(argv[i+1]);
2603 (void) SubstituteString(&geometry,">","");
2604 (void) SubstituteString(&geometry,"<","");
2605 (void) ParseGeometry(geometry,&geometry_info);
2606 geometry=DestroyString(geometry);
2607 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2608 break;
2609 }
2610 break;
2611 }
2612 case 's':
2613 {
2614 if (LocaleCompare("sample",option+1) == 0)
2615 {
2616 /*
2617 Sample image with pixel replication.
2618 */
cristy6fccee12011-10-20 18:43:18 +00002619 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002620 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2621 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2622 exception);
2623 break;
2624 }
2625 if (LocaleCompare("scale",option+1) == 0)
2626 {
2627 /*
2628 Resize image.
2629 */
cristy6fccee12011-10-20 18:43:18 +00002630 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002631 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2632 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2633 exception);
2634 break;
2635 }
2636 if (LocaleCompare("selective-blur",option+1) == 0)
2637 {
2638 /*
2639 Selectively blur pixels within a contrast threshold.
2640 */
cristy6fccee12011-10-20 18:43:18 +00002641 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002642 flags=ParseGeometry(argv[i+1],&geometry_info);
2643 if ((flags & PercentValue) != 0)
2644 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002645 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002646 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002647 break;
2648 }
2649 if (LocaleCompare("separate",option+1) == 0)
2650 {
2651 /*
2652 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002653 */
cristy6fccee12011-10-20 18:43:18 +00002654 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002655 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002656 break;
2657 }
2658 if (LocaleCompare("sepia-tone",option+1) == 0)
2659 {
2660 double
2661 threshold;
2662
2663 /*
2664 Sepia-tone image.
2665 */
cristy6fccee12011-10-20 18:43:18 +00002666 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002667 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2668 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002669 mogrify_image=SepiaToneImage(*image,threshold,exception);
2670 break;
2671 }
2672 if (LocaleCompare("segment",option+1) == 0)
2673 {
2674 /*
2675 Segment image.
2676 */
cristy6fccee12011-10-20 18:43:18 +00002677 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002678 flags=ParseGeometry(argv[i+1],&geometry_info);
2679 if ((flags & SigmaValue) == 0)
2680 geometry_info.sigma=1.0;
2681 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002682 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2683 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002684 break;
2685 }
2686 if (LocaleCompare("set",option+1) == 0)
2687 {
2688 char
2689 *value;
2690
2691 /*
2692 Set image option.
2693 */
2694 if (*option == '+')
2695 {
2696 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2697 (void) DeleteImageRegistry(argv[i+1]+9);
2698 else
2699 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2700 {
2701 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2702 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2703 }
2704 else
2705 (void) DeleteImageProperty(*image,argv[i+1]);
2706 break;
2707 }
cristy018f07f2011-09-04 21:15:19 +00002708 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2709 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002710 if (value == (char *) NULL)
2711 break;
2712 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2713 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2714 exception);
2715 else
2716 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2717 {
2718 (void) SetImageOption(image_info,argv[i+1]+7,value);
2719 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2720 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2721 }
2722 else
cristyd15e6592011-10-15 00:13:06 +00002723 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002724 value=DestroyString(value);
2725 break;
2726 }
2727 if (LocaleCompare("shade",option+1) == 0)
2728 {
2729 /*
2730 Shade image.
2731 */
cristy6fccee12011-10-20 18:43:18 +00002732 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002733 flags=ParseGeometry(argv[i+1],&geometry_info);
2734 if ((flags & SigmaValue) == 0)
2735 geometry_info.sigma=1.0;
2736 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2737 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2738 break;
2739 }
2740 if (LocaleCompare("shadow",option+1) == 0)
2741 {
2742 /*
2743 Shadow image.
2744 */
cristy6fccee12011-10-20 18:43:18 +00002745 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002746 flags=ParseGeometry(argv[i+1],&geometry_info);
2747 if ((flags & SigmaValue) == 0)
2748 geometry_info.sigma=1.0;
2749 if ((flags & XiValue) == 0)
2750 geometry_info.xi=4.0;
2751 if ((flags & PsiValue) == 0)
2752 geometry_info.psi=4.0;
2753 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002754 geometry_info.sigma,(*image)->bias,(ssize_t)
2755 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2756 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002757 break;
2758 }
2759 if (LocaleCompare("sharpen",option+1) == 0)
2760 {
2761 /*
2762 Sharpen image.
2763 */
cristy6fccee12011-10-20 18:43:18 +00002764 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002765 flags=ParseGeometry(argv[i+1],&geometry_info);
2766 if ((flags & SigmaValue) == 0)
2767 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002768 if ((flags & XiValue) == 0)
2769 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002770 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002771 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002772 break;
2773 }
2774 if (LocaleCompare("shave",option+1) == 0)
2775 {
2776 /*
2777 Shave the image edges.
2778 */
cristy6fccee12011-10-20 18:43:18 +00002779 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002780 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2781 mogrify_image=ShaveImage(*image,&geometry,exception);
2782 break;
2783 }
2784 if (LocaleCompare("shear",option+1) == 0)
2785 {
2786 /*
2787 Shear image.
2788 */
cristy6fccee12011-10-20 18:43:18 +00002789 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002790 flags=ParseGeometry(argv[i+1],&geometry_info);
2791 if ((flags & SigmaValue) == 0)
2792 geometry_info.sigma=geometry_info.rho;
2793 mogrify_image=ShearImage(*image,geometry_info.rho,
2794 geometry_info.sigma,exception);
2795 break;
2796 }
2797 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2798 {
2799 /*
2800 Sigmoidal non-linearity contrast control.
2801 */
cristy6fccee12011-10-20 18:43:18 +00002802 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002803 flags=ParseGeometry(argv[i+1],&geometry_info);
2804 if ((flags & SigmaValue) == 0)
2805 geometry_info.sigma=(double) QuantumRange/2.0;
2806 if ((flags & PercentValue) != 0)
2807 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2808 100.0;
cristy9ee60942011-07-06 14:54:38 +00002809 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002810 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2811 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002812 break;
2813 }
2814 if (LocaleCompare("sketch",option+1) == 0)
2815 {
2816 /*
2817 Sketch image.
2818 */
cristy6fccee12011-10-20 18:43:18 +00002819 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002820 flags=ParseGeometry(argv[i+1],&geometry_info);
2821 if ((flags & SigmaValue) == 0)
2822 geometry_info.sigma=1.0;
2823 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002824 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002825 break;
2826 }
2827 if (LocaleCompare("solarize",option+1) == 0)
2828 {
2829 double
2830 threshold;
2831
cristy6fccee12011-10-20 18:43:18 +00002832 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002833 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2834 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002835 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002836 break;
2837 }
2838 if (LocaleCompare("sparse-color",option+1) == 0)
2839 {
2840 SparseColorMethod
2841 method;
2842
2843 char
2844 *arguments;
2845
2846 /*
2847 Sparse Color Interpolated Gradient
2848 */
cristy6fccee12011-10-20 18:43:18 +00002849 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002850 method=(SparseColorMethod) ParseCommandOption(
2851 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002852 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2853 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002854 if (arguments == (char *) NULL)
2855 break;
cristy3884f692011-07-08 18:00:18 +00002856 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002857 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2858 arguments=DestroyString(arguments);
2859 break;
2860 }
2861 if (LocaleCompare("splice",option+1) == 0)
2862 {
2863 /*
2864 Splice a solid color into the image.
2865 */
cristy6fccee12011-10-20 18:43:18 +00002866 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002867 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2868 mogrify_image=SpliceImage(*image,&geometry,exception);
2869 break;
2870 }
2871 if (LocaleCompare("spread",option+1) == 0)
2872 {
2873 /*
2874 Spread an image.
2875 */
cristy6fccee12011-10-20 18:43:18 +00002876 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002877 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002878 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002879 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002880 break;
2881 }
2882 if (LocaleCompare("statistic",option+1) == 0)
2883 {
2884 StatisticType
2885 type;
2886
cristy6fccee12011-10-20 18:43:18 +00002887 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002888 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2889 MagickFalse,argv[i+1]);
2890 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002891 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2892 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002893 break;
2894 }
2895 if (LocaleCompare("stretch",option+1) == 0)
2896 {
2897 if (*option == '+')
2898 {
2899 draw_info->stretch=UndefinedStretch;
2900 break;
2901 }
2902 draw_info->stretch=(StretchType) ParseCommandOption(
2903 MagickStretchOptions,MagickFalse,argv[i+1]);
2904 break;
2905 }
2906 if (LocaleCompare("strip",option+1) == 0)
2907 {
2908 /*
2909 Strip image of profiles and comments.
2910 */
cristy6fccee12011-10-20 18:43:18 +00002911 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002912 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002913 break;
2914 }
2915 if (LocaleCompare("stroke",option+1) == 0)
2916 {
2917 ExceptionInfo
2918 *sans;
2919
2920 if (*option == '+')
2921 {
cristy9950d572011-10-01 18:22:35 +00002922 (void) QueryColorCompliance("none",AllCompliance,
2923 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002924 if (draw_info->stroke_pattern != (Image *) NULL)
2925 draw_info->stroke_pattern=DestroyImage(
2926 draw_info->stroke_pattern);
2927 break;
2928 }
2929 sans=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00002930 status=QueryColorCompliance(argv[i+1],AllCompliance,
2931 &draw_info->stroke,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002932 sans=DestroyExceptionInfo(sans);
2933 if (status == MagickFalse)
2934 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2935 exception);
2936 break;
2937 }
2938 if (LocaleCompare("strokewidth",option+1) == 0)
2939 {
cristy9b34e302011-11-05 02:15:45 +00002940 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002941 break;
2942 }
2943 if (LocaleCompare("style",option+1) == 0)
2944 {
2945 if (*option == '+')
2946 {
2947 draw_info->style=UndefinedStyle;
2948 break;
2949 }
2950 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2951 MagickFalse,argv[i+1]);
2952 break;
2953 }
2954 if (LocaleCompare("swirl",option+1) == 0)
2955 {
2956 /*
2957 Swirl image.
2958 */
cristy6fccee12011-10-20 18:43:18 +00002959 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002960 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002961 mogrify_image=SwirlImage(*image,geometry_info.rho,
2962 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002963 break;
2964 }
2965 break;
2966 }
2967 case 't':
2968 {
2969 if (LocaleCompare("threshold",option+1) == 0)
2970 {
2971 double
2972 threshold;
2973
2974 /*
2975 Threshold image.
2976 */
cristy6fccee12011-10-20 18:43:18 +00002977 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002978 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002979 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002980 else
cristy9b34e302011-11-05 02:15:45 +00002981 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2982 1.0);
cristye941a752011-10-15 01:52:48 +00002983 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002984 break;
2985 }
2986 if (LocaleCompare("thumbnail",option+1) == 0)
2987 {
2988 /*
2989 Thumbnail image.
2990 */
cristy6fccee12011-10-20 18:43:18 +00002991 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002992 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2993 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2994 exception);
2995 break;
2996 }
2997 if (LocaleCompare("tile",option+1) == 0)
2998 {
2999 if (*option == '+')
3000 {
3001 if (draw_info->fill_pattern != (Image *) NULL)
3002 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3003 break;
3004 }
3005 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
3006 exception);
3007 break;
3008 }
3009 if (LocaleCompare("tint",option+1) == 0)
3010 {
3011 /*
3012 Tint the image.
3013 */
cristy6fccee12011-10-20 18:43:18 +00003014 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00003015 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003016 break;
3017 }
3018 if (LocaleCompare("transform",option+1) == 0)
3019 {
3020 /*
3021 Affine transform image.
3022 */
cristy6fccee12011-10-20 18:43:18 +00003023 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003024 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3025 exception);
3026 break;
3027 }
3028 if (LocaleCompare("transparent",option+1) == 0)
3029 {
cristy4c08aed2011-07-01 19:47:50 +00003030 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00003031 target;
3032
cristy6fccee12011-10-20 18:43:18 +00003033 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003034 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003035 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003036 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003037 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003038 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003039 break;
3040 }
3041 if (LocaleCompare("transpose",option+1) == 0)
3042 {
3043 /*
3044 Transpose image scanlines.
3045 */
cristy6fccee12011-10-20 18:43:18 +00003046 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003047 mogrify_image=TransposeImage(*image,exception);
3048 break;
3049 }
3050 if (LocaleCompare("transverse",option+1) == 0)
3051 {
3052 /*
3053 Transverse image scanlines.
3054 */
cristy6fccee12011-10-20 18:43:18 +00003055 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003056 mogrify_image=TransverseImage(*image,exception);
3057 break;
3058 }
3059 if (LocaleCompare("treedepth",option+1) == 0)
3060 {
3061 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3062 break;
3063 }
3064 if (LocaleCompare("trim",option+1) == 0)
3065 {
3066 /*
3067 Trim image.
3068 */
cristy6fccee12011-10-20 18:43:18 +00003069 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003070 mogrify_image=TrimImage(*image,exception);
3071 break;
3072 }
3073 if (LocaleCompare("type",option+1) == 0)
3074 {
3075 ImageType
3076 type;
3077
cristy6fccee12011-10-20 18:43:18 +00003078 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003079 if (*option == '+')
3080 type=UndefinedType;
3081 else
3082 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3083 argv[i+1]);
3084 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003085 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003086 break;
3087 }
3088 break;
3089 }
3090 case 'u':
3091 {
3092 if (LocaleCompare("undercolor",option+1) == 0)
3093 {
cristy9950d572011-10-01 18:22:35 +00003094 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3095 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003096 break;
3097 }
3098 if (LocaleCompare("unique",option+1) == 0)
3099 {
3100 if (*option == '+')
3101 {
3102 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3103 break;
3104 }
3105 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3106 (void) SetImageArtifact(*image,"verbose","true");
3107 break;
3108 }
3109 if (LocaleCompare("unique-colors",option+1) == 0)
3110 {
3111 /*
3112 Unique image colors.
3113 */
cristy6fccee12011-10-20 18:43:18 +00003114 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003115 mogrify_image=UniqueImageColors(*image,exception);
3116 break;
3117 }
3118 if (LocaleCompare("unsharp",option+1) == 0)
3119 {
3120 /*
3121 Unsharp mask image.
3122 */
cristy6fccee12011-10-20 18:43:18 +00003123 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003124 flags=ParseGeometry(argv[i+1],&geometry_info);
3125 if ((flags & SigmaValue) == 0)
3126 geometry_info.sigma=1.0;
3127 if ((flags & XiValue) == 0)
3128 geometry_info.xi=1.0;
3129 if ((flags & PsiValue) == 0)
3130 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003131 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3132 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003133 break;
3134 }
3135 break;
3136 }
3137 case 'v':
3138 {
3139 if (LocaleCompare("verbose",option+1) == 0)
3140 {
3141 (void) SetImageArtifact(*image,option+1,
3142 *option == '+' ? "false" : "true");
3143 break;
3144 }
3145 if (LocaleCompare("vignette",option+1) == 0)
3146 {
3147 /*
3148 Vignette image.
3149 */
cristy6fccee12011-10-20 18:43:18 +00003150 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003151 flags=ParseGeometry(argv[i+1],&geometry_info);
3152 if ((flags & SigmaValue) == 0)
3153 geometry_info.sigma=1.0;
3154 if ((flags & XiValue) == 0)
3155 geometry_info.xi=0.1*(*image)->columns;
3156 if ((flags & PsiValue) == 0)
3157 geometry_info.psi=0.1*(*image)->rows;
3158 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003159 geometry_info.sigma,(*image)->bias,(ssize_t)
3160 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3161 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003162 break;
3163 }
3164 if (LocaleCompare("virtual-pixel",option+1) == 0)
3165 {
3166 if (*option == '+')
3167 {
3168 (void) SetImageVirtualPixelMethod(*image,
3169 UndefinedVirtualPixelMethod);
3170 break;
3171 }
3172 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3173 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3174 argv[i+1]));
3175 break;
3176 }
3177 break;
3178 }
3179 case 'w':
3180 {
3181 if (LocaleCompare("wave",option+1) == 0)
3182 {
3183 /*
3184 Wave image.
3185 */
cristy6fccee12011-10-20 18:43:18 +00003186 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003187 flags=ParseGeometry(argv[i+1],&geometry_info);
3188 if ((flags & SigmaValue) == 0)
3189 geometry_info.sigma=1.0;
3190 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003191 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003192 break;
3193 }
3194 if (LocaleCompare("weight",option+1) == 0)
3195 {
3196 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3197 if (LocaleCompare(argv[i+1],"all") == 0)
3198 draw_info->weight=0;
3199 if (LocaleCompare(argv[i+1],"bold") == 0)
3200 draw_info->weight=700;
3201 if (LocaleCompare(argv[i+1],"bolder") == 0)
3202 if (draw_info->weight <= 800)
3203 draw_info->weight+=100;
3204 if (LocaleCompare(argv[i+1],"lighter") == 0)
3205 if (draw_info->weight >= 100)
3206 draw_info->weight-=100;
3207 if (LocaleCompare(argv[i+1],"normal") == 0)
3208 draw_info->weight=400;
3209 break;
3210 }
3211 if (LocaleCompare("white-threshold",option+1) == 0)
3212 {
3213 /*
3214 White threshold image.
3215 */
cristy6fccee12011-10-20 18:43:18 +00003216 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003217 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003218 break;
3219 }
3220 break;
3221 }
3222 default:
3223 break;
3224 }
3225 /*
3226 Replace current image with any image that was generated
3227 */
3228 if (mogrify_image != (Image *) NULL)
3229 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003230 i+=count;
3231 }
3232 if (region_image != (Image *) NULL)
3233 {
anthonydf8ebac2011-04-27 09:03:19 +00003234 /*
3235 Composite transformed region onto image.
3236 */
cristy6fccee12011-10-20 18:43:18 +00003237 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003238 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003239 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003240 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003241 *image=DestroyImage(*image);
3242 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003243 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003244 }
3245 /*
3246 Free resources.
3247 */
anthonydf8ebac2011-04-27 09:03:19 +00003248 quantize_info=DestroyQuantizeInfo(quantize_info);
3249 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003250 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003251 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003252 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003253}
3254
3255/*
3256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3257% %
3258% %
3259% %
cristy5063d812010-10-19 16:28:10 +00003260+ 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 +00003261% %
3262% %
3263% %
3264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3265%
3266% MogrifyImageCommand() transforms an image or a sequence of images. These
3267% transforms include image scaling, image rotation, color reduction, and
3268% others. The transmogrified image overwrites the original image.
3269%
3270% The format of the MogrifyImageCommand method is:
3271%
3272% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3273% const char **argv,char **metadata,ExceptionInfo *exception)
3274%
3275% A description of each parameter follows:
3276%
3277% o image_info: the image info.
3278%
3279% o argc: the number of elements in the argument vector.
3280%
3281% o argv: A text array containing the command line arguments.
3282%
3283% o metadata: any metadata is returned here.
3284%
3285% o exception: return any errors or warnings in this structure.
3286%
3287*/
3288
3289static MagickBooleanType MogrifyUsage(void)
3290{
3291 static const char
3292 *miscellaneous[]=
3293 {
3294 "-debug events display copious debugging information",
3295 "-help print program options",
3296 "-list type print a list of supported option arguments",
3297 "-log format format of debugging information",
3298 "-version print version information",
3299 (char *) NULL
3300 },
3301 *operators[]=
3302 {
3303 "-adaptive-blur geometry",
3304 " adaptively blur pixels; decrease effect near edges",
3305 "-adaptive-resize geometry",
3306 " adaptively resize image using 'mesh' interpolation",
3307 "-adaptive-sharpen geometry",
3308 " adaptively sharpen pixels; increase effect near edges",
3309 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3310 " transparent, extract, background, or shape",
3311 "-annotate geometry text",
3312 " annotate the image with text",
3313 "-auto-gamma automagically adjust gamma level of image",
3314 "-auto-level automagically adjust color levels of image",
3315 "-auto-orient automagically orient (rotate) image",
3316 "-bench iterations measure performance",
3317 "-black-threshold value",
3318 " force all pixels below the threshold into black",
3319 "-blue-shift simulate a scene at nighttime in the moonlight",
3320 "-blur geometry reduce image noise and reduce detail levels",
3321 "-border geometry surround image with a border of color",
3322 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003323 "-brightness-contrast geometry",
3324 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003325 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003326 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003327 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003328 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003329 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003330 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003331 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003332 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003333 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003334 "-contrast enhance or reduce the image contrast",
3335 "-contrast-stretch geometry",
3336 " improve contrast by `stretching' the intensity range",
3337 "-convolve coefficients",
3338 " apply a convolution kernel to the image",
3339 "-cycle amount cycle the image colormap",
3340 "-decipher filename convert cipher pixels to plain pixels",
3341 "-deskew threshold straighten an image",
3342 "-despeckle reduce the speckles within an image",
3343 "-distort method args",
3344 " distort images according to given method ad args",
3345 "-draw string annotate the image with a graphic primitive",
3346 "-edge radius apply a filter to detect edges in the image",
3347 "-encipher filename convert plain pixels to cipher pixels",
3348 "-emboss radius emboss an image",
3349 "-enhance apply a digital filter to enhance a noisy image",
3350 "-equalize perform histogram equalization to an image",
3351 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003352 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003353 "-extent geometry set the image size",
3354 "-extract geometry extract area from image",
3355 "-fft implements the discrete Fourier transform (DFT)",
3356 "-flip flip image vertically",
3357 "-floodfill geometry color",
3358 " floodfill the image with color",
3359 "-flop flop image horizontally",
3360 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003361 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003362 " apply function over image values",
3363 "-gamma value level of gamma correction",
3364 "-gaussian-blur geometry",
3365 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003366 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003367 "-identify identify the format and characteristics of the image",
3368 "-ift implements the inverse discrete Fourier transform (DFT)",
3369 "-implode amount implode image pixels about the center",
3370 "-lat geometry local adaptive thresholding",
3371 "-layers method optimize, merge, or compare image layers",
3372 "-level value adjust the level of image contrast",
3373 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003374 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003375 "-linear-stretch geometry",
3376 " improve contrast by `stretching with saturation'",
3377 "-liquid-rescale geometry",
3378 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003379 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003380 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-modulate value vary the brightness, saturation, and hue",
3382 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003383 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003384 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003385 "-motion-blur geometry",
3386 " simulate motion blur",
3387 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003388 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003389 "-normalize transform image to span the full range of colors",
3390 "-opaque color change this color to the fill color",
3391 "-ordered-dither NxN",
3392 " add a noise pattern to the image with specific",
3393 " amplitudes",
3394 "-paint radius simulate an oil painting",
3395 "-polaroid angle simulate a Polaroid picture",
3396 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003397 "-profile filename add, delete, or apply an image profile",
3398 "-quantize colorspace reduce colors in this colorspace",
3399 "-radial-blur angle radial blur the image",
3400 "-raise value lighten/darken image edges to create a 3-D effect",
3401 "-random-threshold low,high",
3402 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003403 "-region geometry apply options to a portion of the image",
3404 "-render render vector graphics",
3405 "-repage geometry size and location of an image canvas",
3406 "-resample geometry change the resolution of an image",
3407 "-resize geometry resize the image",
3408 "-roll geometry roll an image vertically or horizontally",
3409 "-rotate degrees apply Paeth rotation to the image",
3410 "-sample geometry scale image with pixel sampling",
3411 "-scale geometry scale the image",
3412 "-segment values segment an image",
3413 "-selective-blur geometry",
3414 " selectively blur pixels within a contrast threshold",
3415 "-sepia-tone threshold",
3416 " simulate a sepia-toned photo",
3417 "-set property value set an image property",
3418 "-shade degrees shade the image using a distant light source",
3419 "-shadow geometry simulate an image shadow",
3420 "-sharpen geometry sharpen the image",
3421 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003422 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003423 "-sigmoidal-contrast geometry",
3424 " increase the contrast without saturating highlights or shadows",
3425 "-sketch geometry simulate a pencil sketch",
3426 "-solarize threshold negate all pixels above the threshold level",
3427 "-sparse-color method args",
3428 " fill in a image based on a few color points",
3429 "-splice geometry splice the background color into the image",
3430 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003431 "-statistic type radius",
3432 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003433 "-strip strip image of all profiles and comments",
3434 "-swirl degrees swirl image pixels about the center",
3435 "-threshold value threshold the image",
3436 "-thumbnail geometry create a thumbnail of the image",
3437 "-tile filename tile image when filling a graphic primitive",
3438 "-tint value tint the image with the fill color",
3439 "-transform affine transform image",
3440 "-transparent color make this color transparent within the image",
3441 "-transpose flip image vertically and rotate 90 degrees",
3442 "-transverse flop image horizontally and rotate 270 degrees",
3443 "-trim trim image edges",
3444 "-type type image type",
3445 "-unique-colors discard all but one of any pixel color",
3446 "-unsharp geometry sharpen the image",
3447 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003448 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003449 "-white-threshold value",
3450 " force all pixels above the threshold into white",
3451 (char *) NULL
3452 },
3453 *sequence_operators[]=
3454 {
cristy4285d782011-02-09 20:12:28 +00003455 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003456 "-clut apply a color lookup table to the image",
3457 "-coalesce merge a sequence of images",
3458 "-combine combine a sequence of images",
3459 "-composite composite image",
3460 "-crop geometry cut out a rectangular region of the image",
3461 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003462 "-evaluate-sequence operator",
3463 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003464 "-flatten flatten a sequence of images",
3465 "-fx expression apply mathematical expression to an image channel(s)",
3466 "-hald-clut apply a Hald color lookup table to the image",
3467 "-morph value morph an image sequence",
3468 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003469 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003470 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003471 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003472 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003473 "-write filename write images to this file",
3474 (char *) NULL
3475 },
3476 *settings[]=
3477 {
3478 "-adjoin join images into a single multi-image file",
3479 "-affine matrix affine transform matrix",
3480 "-alpha option activate, deactivate, reset, or set the alpha channel",
3481 "-antialias remove pixel-aliasing",
3482 "-authenticate password",
3483 " decipher image with this password",
3484 "-attenuate value lessen (or intensify) when adding noise to an image",
3485 "-background color background color",
3486 "-bias value add bias when convolving an image",
3487 "-black-point-compensation",
3488 " use black point compensation",
3489 "-blue-primary point chromaticity blue primary point",
3490 "-bordercolor color border color",
3491 "-caption string assign a caption to an image",
3492 "-channel type apply option to select image channels",
3493 "-colors value preferred number of colors in the image",
3494 "-colorspace type alternate image colorspace",
3495 "-comment string annotate image with comment",
3496 "-compose operator set image composite operator",
3497 "-compress type type of pixel compression when writing the image",
3498 "-define format:option",
3499 " define one or more image format options",
3500 "-delay value display the next image after pausing",
3501 "-density geometry horizontal and vertical density of the image",
3502 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003503 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003504 "-display server get image or font from this X server",
3505 "-dispose method layer disposal method",
3506 "-dither method apply error diffusion to image",
3507 "-encoding type text encoding type",
3508 "-endian type endianness (MSB or LSB) of the image",
3509 "-family name render text with this font family",
3510 "-fill color color to use when filling a graphic primitive",
3511 "-filter type use this filter when resizing an image",
3512 "-font name render text with this font",
3513 "-format \"string\" output formatted image characteristics",
3514 "-fuzz distance colors within this distance are considered equal",
3515 "-gravity type horizontal and vertical text placement",
3516 "-green-primary point chromaticity green primary point",
3517 "-intent type type of rendering intent when managing the image color",
3518 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003519 "-interline-spacing value",
3520 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003521 "-interpolate method pixel color interpolation method",
3522 "-interword-spacing value",
3523 " set the space between two words",
3524 "-kerning value set the space between two letters",
3525 "-label string assign a label to an image",
3526 "-limit type value pixel cache resource limit",
3527 "-loop iterations add Netscape loop extension to your GIF animation",
3528 "-mask filename associate a mask with the image",
3529 "-mattecolor color frame color",
3530 "-monitor monitor progress",
3531 "-orient type image orientation",
3532 "-page geometry size and location of an image canvas (setting)",
3533 "-ping efficiently determine image attributes",
3534 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003535 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003536 "-preview type image preview type",
3537 "-quality value JPEG/MIFF/PNG compression level",
3538 "-quiet suppress all warning messages",
3539 "-red-primary point chromaticity red primary point",
3540 "-regard-warnings pay attention to warning messages",
3541 "-remap filename transform image colors to match this set of colors",
3542 "-respect-parentheses settings remain in effect until parenthesis boundary",
3543 "-sampling-factor geometry",
3544 " horizontal and vertical sampling factor",
3545 "-scene value image scene number",
3546 "-seed value seed a new sequence of pseudo-random numbers",
3547 "-size geometry width and height of image",
3548 "-stretch type render text with this font stretch",
3549 "-stroke color graphic primitive stroke color",
3550 "-strokewidth value graphic primitive stroke width",
3551 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003552 "-synchronize synchronize image to storage device",
3553 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003554 "-texture filename name of texture to tile onto the image background",
3555 "-tile-offset geometry",
3556 " tile offset",
3557 "-treedepth value color tree depth",
3558 "-transparent-color color",
3559 " transparent color",
3560 "-undercolor color annotation bounding box color",
3561 "-units type the units of image resolution",
3562 "-verbose print detailed information about the image",
3563 "-view FlashPix viewing transforms",
3564 "-virtual-pixel method",
3565 " virtual pixel access method",
3566 "-weight type render text with this font weight",
3567 "-white-point point chromaticity white point",
3568 (char *) NULL
3569 },
3570 *stack_operators[]=
3571 {
anthonyb69c4b32011-03-23 04:37:44 +00003572 "-delete indexes delete the image from the image sequence",
3573 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003574 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003575 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003576 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003577 "-swap indexes swap two images in the image sequence",
3578 (char *) NULL
3579 };
3580
3581 const char
3582 **p;
3583
cristybb503372010-05-27 20:51:26 +00003584 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003585 (void) printf("Copyright: %s\n",GetMagickCopyright());
3586 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003587 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3588 GetClientName());
3589 (void) printf("\nImage Settings:\n");
3590 for (p=settings; *p != (char *) NULL; p++)
3591 (void) printf(" %s\n",*p);
3592 (void) printf("\nImage Operators:\n");
3593 for (p=operators; *p != (char *) NULL; p++)
3594 (void) printf(" %s\n",*p);
3595 (void) printf("\nImage Sequence Operators:\n");
3596 for (p=sequence_operators; *p != (char *) NULL; p++)
3597 (void) printf(" %s\n",*p);
3598 (void) printf("\nImage Stack Operators:\n");
3599 for (p=stack_operators; *p != (char *) NULL; p++)
3600 (void) printf(" %s\n",*p);
3601 (void) printf("\nMiscellaneous Options:\n");
3602 for (p=miscellaneous; *p != (char *) NULL; p++)
3603 (void) printf(" %s\n",*p);
3604 (void) printf(
3605 "\nBy default, the image format of `file' is determined by its magic\n");
3606 (void) printf(
3607 "number. To specify a particular image format, precede the filename\n");
3608 (void) printf(
3609 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3610 (void) printf(
3611 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3612 (void) printf("'-' for standard input or output.\n");
3613 return(MagickFalse);
3614}
3615
3616WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3617 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3618{
3619#define DestroyMogrify() \
3620{ \
3621 if (format != (char *) NULL) \
3622 format=DestroyString(format); \
3623 if (path != (char *) NULL) \
3624 path=DestroyString(path); \
3625 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003626 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003627 argv[i]=DestroyString(argv[i]); \
3628 argv=(char **) RelinquishMagickMemory(argv); \
3629}
3630#define ThrowMogrifyException(asperity,tag,option) \
3631{ \
3632 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3633 option); \
3634 DestroyMogrify(); \
3635 return(MagickFalse); \
3636}
3637#define ThrowMogrifyInvalidArgumentException(option,argument) \
3638{ \
3639 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3640 "InvalidArgument","`%s': %s",argument,option); \
3641 DestroyMogrify(); \
3642 return(MagickFalse); \
3643}
3644
3645 char
3646 *format,
3647 *option,
3648 *path;
3649
3650 Image
3651 *image;
3652
3653 ImageStack
3654 image_stack[MaxImageStackDepth+1];
3655
cristy3ed852e2009-09-05 21:47:34 +00003656 MagickBooleanType
3657 global_colormap;
3658
3659 MagickBooleanType
3660 fire,
cristyebbcfea2011-02-25 02:43:54 +00003661 pend,
3662 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003663
3664 MagickStatusType
3665 status;
3666
cristyebbcfea2011-02-25 02:43:54 +00003667 register ssize_t
3668 i;
3669
3670 ssize_t
3671 j,
3672 k;
3673
cristy3ed852e2009-09-05 21:47:34 +00003674 /*
3675 Set defaults.
3676 */
3677 assert(image_info != (ImageInfo *) NULL);
3678 assert(image_info->signature == MagickSignature);
3679 if (image_info->debug != MagickFalse)
3680 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3681 assert(exception != (ExceptionInfo *) NULL);
3682 if (argc == 2)
3683 {
3684 option=argv[1];
3685 if ((LocaleCompare("version",option+1) == 0) ||
3686 (LocaleCompare("-version",option+1) == 0))
3687 {
cristyb51dff52011-05-19 16:55:47 +00003688 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003689 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003690 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3691 GetMagickCopyright());
3692 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3693 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003694 return(MagickFalse);
3695 }
3696 }
3697 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003698 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003699 format=(char *) NULL;
3700 path=(char *) NULL;
3701 global_colormap=MagickFalse;
3702 k=0;
3703 j=1;
3704 NewImageStack();
3705 option=(char *) NULL;
3706 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003707 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003708 status=MagickTrue;
3709 /*
3710 Parse command line.
3711 */
3712 ReadCommandlLine(argc,&argv);
3713 status=ExpandFilenames(&argc,&argv);
3714 if (status == MagickFalse)
3715 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3716 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003717 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003718 {
3719 option=argv[i];
3720 if (LocaleCompare(option,"(") == 0)
3721 {
3722 FireImageStack(MagickFalse,MagickTrue,pend);
3723 if (k == MaxImageStackDepth)
3724 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3725 option);
3726 PushImageStack();
3727 continue;
3728 }
3729 if (LocaleCompare(option,")") == 0)
3730 {
3731 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3732 if (k == 0)
3733 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3734 PopImageStack();
3735 continue;
3736 }
cristy042ee782011-04-22 18:48:30 +00003737 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003738 {
3739 char
3740 backup_filename[MaxTextExtent],
3741 *filename;
3742
3743 Image
3744 *images;
3745
3746 /*
3747 Option is a file name: begin by reading image from specified file.
3748 */
3749 FireImageStack(MagickFalse,MagickFalse,pend);
3750 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003751 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003752 filename=argv[++i];
3753 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3754 images=ReadImages(image_info,exception);
3755 status&=(images != (Image *) NULL) &&
3756 (exception->severity < ErrorException);
3757 if (images == (Image *) NULL)
3758 continue;
cristydaa76602010-06-30 13:05:11 +00003759 if (format != (char *) NULL)
3760 (void) CopyMagickString(images->filename,images->magick_filename,
3761 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003762 if (path != (char *) NULL)
3763 {
3764 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003765 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003766 path,*DirectorySeparator,filename);
3767 }
3768 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003769 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003770 AppendImageStack(images);
3771 FinalizeImageSettings(image_info,image,MagickFalse);
3772 if (global_colormap != MagickFalse)
3773 {
3774 QuantizeInfo
3775 *quantize_info;
3776
3777 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003778 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003779 quantize_info=DestroyQuantizeInfo(quantize_info);
3780 }
3781 *backup_filename='\0';
3782 if ((LocaleCompare(image->filename,"-") != 0) &&
3783 (IsPathWritable(image->filename) != MagickFalse))
3784 {
cristybb503372010-05-27 20:51:26 +00003785 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003786 i;
3787
3788 /*
3789 Rename image file as backup.
3790 */
3791 (void) CopyMagickString(backup_filename,image->filename,
3792 MaxTextExtent);
3793 for (i=0; i < 6; i++)
3794 {
3795 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3796 if (IsPathAccessible(backup_filename) == MagickFalse)
3797 break;
3798 }
3799 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003800 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003801 *backup_filename='\0';
3802 }
3803 /*
3804 Write transmogrified image to disk.
3805 */
3806 image_info->synchronize=MagickTrue;
3807 status&=WriteImages(image_info,image,image->filename,exception);
3808 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003809 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003810 RemoveAllImageStack();
3811 continue;
3812 }
3813 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3814 switch (*(option+1))
3815 {
3816 case 'a':
3817 {
3818 if (LocaleCompare("adaptive-blur",option+1) == 0)
3819 {
3820 i++;
cristybb503372010-05-27 20:51:26 +00003821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003822 ThrowMogrifyException(OptionError,"MissingArgument",option);
3823 if (IsGeometry(argv[i]) == MagickFalse)
3824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3825 break;
3826 }
3827 if (LocaleCompare("adaptive-resize",option+1) == 0)
3828 {
3829 i++;
cristybb503372010-05-27 20:51:26 +00003830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003831 ThrowMogrifyException(OptionError,"MissingArgument",option);
3832 if (IsGeometry(argv[i]) == MagickFalse)
3833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3834 break;
3835 }
3836 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3837 {
3838 i++;
cristybb503372010-05-27 20:51:26 +00003839 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003840 ThrowMogrifyException(OptionError,"MissingArgument",option);
3841 if (IsGeometry(argv[i]) == MagickFalse)
3842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3843 break;
3844 }
3845 if (LocaleCompare("affine",option+1) == 0)
3846 {
3847 if (*option == '+')
3848 break;
3849 i++;
cristybb503372010-05-27 20:51:26 +00003850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003851 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003852 break;
3853 }
3854 if (LocaleCompare("alpha",option+1) == 0)
3855 {
cristybb503372010-05-27 20:51:26 +00003856 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003857 type;
3858
3859 if (*option == '+')
3860 break;
3861 i++;
cristybb503372010-05-27 20:51:26 +00003862 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003863 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003864 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003865 if (type < 0)
3866 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3867 argv[i]);
3868 break;
3869 }
3870 if (LocaleCompare("annotate",option+1) == 0)
3871 {
3872 if (*option == '+')
3873 break;
3874 i++;
cristybb503372010-05-27 20:51:26 +00003875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003876 ThrowMogrifyException(OptionError,"MissingArgument",option);
3877 if (IsGeometry(argv[i]) == MagickFalse)
3878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003880 ThrowMogrifyException(OptionError,"MissingArgument",option);
3881 i++;
3882 break;
3883 }
3884 if (LocaleCompare("antialias",option+1) == 0)
3885 break;
3886 if (LocaleCompare("append",option+1) == 0)
3887 break;
3888 if (LocaleCompare("attenuate",option+1) == 0)
3889 {
3890 if (*option == '+')
3891 break;
3892 i++;
cristybb503372010-05-27 20:51:26 +00003893 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003894 ThrowMogrifyException(OptionError,"MissingArgument",option);
3895 if (IsGeometry(argv[i]) == MagickFalse)
3896 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3897 break;
3898 }
3899 if (LocaleCompare("authenticate",option+1) == 0)
3900 {
3901 if (*option == '+')
3902 break;
3903 i++;
cristybb503372010-05-27 20:51:26 +00003904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003905 ThrowMogrifyException(OptionError,"MissingArgument",option);
3906 break;
3907 }
3908 if (LocaleCompare("auto-gamma",option+1) == 0)
3909 break;
3910 if (LocaleCompare("auto-level",option+1) == 0)
3911 break;
3912 if (LocaleCompare("auto-orient",option+1) == 0)
3913 break;
3914 if (LocaleCompare("average",option+1) == 0)
3915 break;
3916 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3917 }
3918 case 'b':
3919 {
3920 if (LocaleCompare("background",option+1) == 0)
3921 {
3922 if (*option == '+')
3923 break;
3924 i++;
cristybb503372010-05-27 20:51:26 +00003925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003926 ThrowMogrifyException(OptionError,"MissingArgument",option);
3927 break;
3928 }
3929 if (LocaleCompare("bias",option+1) == 0)
3930 {
3931 if (*option == '+')
3932 break;
3933 i++;
cristybb503372010-05-27 20:51:26 +00003934 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003935 ThrowMogrifyException(OptionError,"MissingArgument",option);
3936 if (IsGeometry(argv[i]) == MagickFalse)
3937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3938 break;
3939 }
3940 if (LocaleCompare("black-point-compensation",option+1) == 0)
3941 break;
3942 if (LocaleCompare("black-threshold",option+1) == 0)
3943 {
3944 if (*option == '+')
3945 break;
3946 i++;
cristybb503372010-05-27 20:51:26 +00003947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003948 ThrowMogrifyException(OptionError,"MissingArgument",option);
3949 if (IsGeometry(argv[i]) == MagickFalse)
3950 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3951 break;
3952 }
3953 if (LocaleCompare("blue-primary",option+1) == 0)
3954 {
3955 if (*option == '+')
3956 break;
3957 i++;
cristybb503372010-05-27 20:51:26 +00003958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003959 ThrowMogrifyException(OptionError,"MissingArgument",option);
3960 if (IsGeometry(argv[i]) == MagickFalse)
3961 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3962 break;
3963 }
3964 if (LocaleCompare("blue-shift",option+1) == 0)
3965 {
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 if (IsGeometry(argv[i]) == MagickFalse)
3970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3971 break;
3972 }
3973 if (LocaleCompare("blur",option+1) == 0)
3974 {
3975 i++;
cristybb503372010-05-27 20:51:26 +00003976 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003977 ThrowMogrifyException(OptionError,"MissingArgument",option);
3978 if (IsGeometry(argv[i]) == MagickFalse)
3979 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3980 break;
3981 }
3982 if (LocaleCompare("border",option+1) == 0)
3983 {
3984 if (*option == '+')
3985 break;
3986 i++;
cristybb503372010-05-27 20:51:26 +00003987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003988 ThrowMogrifyException(OptionError,"MissingArgument",option);
3989 if (IsGeometry(argv[i]) == MagickFalse)
3990 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3991 break;
3992 }
3993 if (LocaleCompare("bordercolor",option+1) == 0)
3994 {
3995 if (*option == '+')
3996 break;
3997 i++;
cristybb503372010-05-27 20:51:26 +00003998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003999 ThrowMogrifyException(OptionError,"MissingArgument",option);
4000 break;
4001 }
4002 if (LocaleCompare("box",option+1) == 0)
4003 {
4004 if (*option == '+')
4005 break;
4006 i++;
cristybb503372010-05-27 20:51:26 +00004007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004008 ThrowMogrifyException(OptionError,"MissingArgument",option);
4009 break;
4010 }
cristya28d6b82010-01-11 20:03:47 +00004011 if (LocaleCompare("brightness-contrast",option+1) == 0)
4012 {
4013 i++;
cristybb503372010-05-27 20:51:26 +00004014 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004015 ThrowMogrifyException(OptionError,"MissingArgument",option);
4016 if (IsGeometry(argv[i]) == MagickFalse)
4017 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4018 break;
4019 }
cristy3ed852e2009-09-05 21:47:34 +00004020 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4021 }
4022 case 'c':
4023 {
4024 if (LocaleCompare("cache",option+1) == 0)
4025 {
4026 if (*option == '+')
4027 break;
4028 i++;
cristybb503372010-05-27 20:51:26 +00004029 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004030 ThrowMogrifyException(OptionError,"MissingArgument",option);
4031 if (IsGeometry(argv[i]) == MagickFalse)
4032 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4033 break;
4034 }
4035 if (LocaleCompare("caption",option+1) == 0)
4036 {
4037 if (*option == '+')
4038 break;
4039 i++;
cristybb503372010-05-27 20:51:26 +00004040 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004041 ThrowMogrifyException(OptionError,"MissingArgument",option);
4042 break;
4043 }
4044 if (LocaleCompare("channel",option+1) == 0)
4045 {
cristybb503372010-05-27 20:51:26 +00004046 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004047 channel;
4048
4049 if (*option == '+')
4050 break;
4051 i++;
cristybb503372010-05-27 20:51:26 +00004052 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004053 ThrowMogrifyException(OptionError,"MissingArgument",option);
4054 channel=ParseChannelOption(argv[i]);
4055 if (channel < 0)
4056 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4057 argv[i]);
4058 break;
4059 }
4060 if (LocaleCompare("cdl",option+1) == 0)
4061 {
4062 if (*option == '+')
4063 break;
4064 i++;
cristybb503372010-05-27 20:51:26 +00004065 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004066 ThrowMogrifyException(OptionError,"MissingArgument",option);
4067 break;
4068 }
4069 if (LocaleCompare("charcoal",option+1) == 0)
4070 {
4071 if (*option == '+')
4072 break;
4073 i++;
cristybb503372010-05-27 20:51:26 +00004074 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004075 ThrowMogrifyException(OptionError,"MissingArgument",option);
4076 if (IsGeometry(argv[i]) == MagickFalse)
4077 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4078 break;
4079 }
4080 if (LocaleCompare("chop",option+1) == 0)
4081 {
4082 if (*option == '+')
4083 break;
4084 i++;
cristybb503372010-05-27 20:51:26 +00004085 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004086 ThrowMogrifyException(OptionError,"MissingArgument",option);
4087 if (IsGeometry(argv[i]) == MagickFalse)
4088 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4089 break;
4090 }
cristy1eb45dd2009-09-25 16:38:06 +00004091 if (LocaleCompare("clamp",option+1) == 0)
4092 break;
4093 if (LocaleCompare("clip",option+1) == 0)
4094 break;
cristy3ed852e2009-09-05 21:47:34 +00004095 if (LocaleCompare("clip-mask",option+1) == 0)
4096 {
4097 if (*option == '+')
4098 break;
4099 i++;
cristybb503372010-05-27 20:51:26 +00004100 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004101 ThrowMogrifyException(OptionError,"MissingArgument",option);
4102 break;
4103 }
4104 if (LocaleCompare("clut",option+1) == 0)
4105 break;
4106 if (LocaleCompare("coalesce",option+1) == 0)
4107 break;
4108 if (LocaleCompare("colorize",option+1) == 0)
4109 {
4110 if (*option == '+')
4111 break;
4112 i++;
cristybb503372010-05-27 20:51:26 +00004113 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004114 ThrowMogrifyException(OptionError,"MissingArgument",option);
4115 if (IsGeometry(argv[i]) == MagickFalse)
4116 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4117 break;
4118 }
cristye6365592010-04-02 17:31:23 +00004119 if (LocaleCompare("color-matrix",option+1) == 0)
4120 {
cristyb6bd4ad2010-08-08 01:12:27 +00004121 KernelInfo
4122 *kernel_info;
4123
cristye6365592010-04-02 17:31:23 +00004124 if (*option == '+')
4125 break;
4126 i++;
cristybb503372010-05-27 20:51:26 +00004127 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004128 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004129 kernel_info=AcquireKernelInfo(argv[i]);
4130 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004132 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004133 break;
4134 }
cristy3ed852e2009-09-05 21:47:34 +00004135 if (LocaleCompare("colors",option+1) == 0)
4136 {
4137 if (*option == '+')
4138 break;
4139 i++;
cristybb503372010-05-27 20:51:26 +00004140 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004141 ThrowMogrifyException(OptionError,"MissingArgument",option);
4142 if (IsGeometry(argv[i]) == MagickFalse)
4143 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4144 break;
4145 }
4146 if (LocaleCompare("colorspace",option+1) == 0)
4147 {
cristybb503372010-05-27 20:51:26 +00004148 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004149 colorspace;
4150
4151 if (*option == '+')
4152 break;
4153 i++;
cristybb503372010-05-27 20:51:26 +00004154 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004155 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004156 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004157 argv[i]);
4158 if (colorspace < 0)
4159 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4160 argv[i]);
4161 break;
4162 }
4163 if (LocaleCompare("combine",option+1) == 0)
4164 break;
4165 if (LocaleCompare("comment",option+1) == 0)
4166 {
4167 if (*option == '+')
4168 break;
4169 i++;
cristybb503372010-05-27 20:51:26 +00004170 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004171 ThrowMogrifyException(OptionError,"MissingArgument",option);
4172 break;
4173 }
4174 if (LocaleCompare("composite",option+1) == 0)
4175 break;
4176 if (LocaleCompare("compress",option+1) == 0)
4177 {
cristybb503372010-05-27 20:51:26 +00004178 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004179 compress;
4180
4181 if (*option == '+')
4182 break;
4183 i++;
cristybb503372010-05-27 20:51:26 +00004184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004185 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004186 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004187 argv[i]);
4188 if (compress < 0)
4189 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4190 argv[i]);
4191 break;
4192 }
cristy22879752009-10-25 23:55:40 +00004193 if (LocaleCompare("concurrent",option+1) == 0)
4194 break;
cristy3ed852e2009-09-05 21:47:34 +00004195 if (LocaleCompare("contrast",option+1) == 0)
4196 break;
4197 if (LocaleCompare("contrast-stretch",option+1) == 0)
4198 {
4199 i++;
cristybb503372010-05-27 20:51:26 +00004200 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004201 ThrowMogrifyException(OptionError,"MissingArgument",option);
4202 if (IsGeometry(argv[i]) == MagickFalse)
4203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4204 break;
4205 }
4206 if (LocaleCompare("convolve",option+1) == 0)
4207 {
cristyb6bd4ad2010-08-08 01:12:27 +00004208 KernelInfo
4209 *kernel_info;
4210
cristy3ed852e2009-09-05 21:47:34 +00004211 if (*option == '+')
4212 break;
4213 i++;
cristybb503372010-05-27 20:51:26 +00004214 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004215 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004216 kernel_info=AcquireKernelInfo(argv[i]);
4217 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004218 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004219 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004220 break;
4221 }
4222 if (LocaleCompare("crop",option+1) == 0)
4223 {
4224 if (*option == '+')
4225 break;
4226 i++;
cristybb503372010-05-27 20:51:26 +00004227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004228 ThrowMogrifyException(OptionError,"MissingArgument",option);
4229 if (IsGeometry(argv[i]) == MagickFalse)
4230 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4231 break;
4232 }
4233 if (LocaleCompare("cycle",option+1) == 0)
4234 {
4235 if (*option == '+')
4236 break;
4237 i++;
cristybb503372010-05-27 20:51:26 +00004238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004239 ThrowMogrifyException(OptionError,"MissingArgument",option);
4240 if (IsGeometry(argv[i]) == MagickFalse)
4241 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4242 break;
4243 }
4244 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4245 }
4246 case 'd':
4247 {
4248 if (LocaleCompare("decipher",option+1) == 0)
4249 {
4250 if (*option == '+')
4251 break;
4252 i++;
cristybb503372010-05-27 20:51:26 +00004253 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004254 ThrowMogrifyException(OptionError,"MissingArgument",option);
4255 break;
4256 }
4257 if (LocaleCompare("deconstruct",option+1) == 0)
4258 break;
4259 if (LocaleCompare("debug",option+1) == 0)
4260 {
cristybb503372010-05-27 20:51:26 +00004261 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004262 event;
4263
4264 if (*option == '+')
4265 break;
4266 i++;
cristybb503372010-05-27 20:51:26 +00004267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004268 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004269 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004270 if (event < 0)
4271 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4272 argv[i]);
4273 (void) SetLogEventMask(argv[i]);
4274 break;
4275 }
4276 if (LocaleCompare("define",option+1) == 0)
4277 {
4278 i++;
cristybb503372010-05-27 20:51:26 +00004279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004280 ThrowMogrifyException(OptionError,"MissingArgument",option);
4281 if (*option == '+')
4282 {
4283 const char
4284 *define;
4285
4286 define=GetImageOption(image_info,argv[i]);
4287 if (define == (const char *) NULL)
4288 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4289 break;
4290 }
4291 break;
4292 }
4293 if (LocaleCompare("delay",option+1) == 0)
4294 {
4295 if (*option == '+')
4296 break;
4297 i++;
cristybb503372010-05-27 20:51:26 +00004298 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004299 ThrowMogrifyException(OptionError,"MissingArgument",option);
4300 if (IsGeometry(argv[i]) == MagickFalse)
4301 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4302 break;
4303 }
cristyecb10ff2011-03-22 13:14:03 +00004304 if (LocaleCompare("delete",option+1) == 0)
4305 {
4306 if (*option == '+')
4307 break;
4308 i++;
4309 if (i == (ssize_t) (argc-1))
4310 ThrowMogrifyException(OptionError,"MissingArgument",option);
4311 if (IsGeometry(argv[i]) == MagickFalse)
4312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4313 break;
4314 }
cristy3ed852e2009-09-05 21:47:34 +00004315 if (LocaleCompare("density",option+1) == 0)
4316 {
4317 if (*option == '+')
4318 break;
4319 i++;
cristybb503372010-05-27 20:51:26 +00004320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004321 ThrowMogrifyException(OptionError,"MissingArgument",option);
4322 if (IsGeometry(argv[i]) == MagickFalse)
4323 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4324 break;
4325 }
4326 if (LocaleCompare("depth",option+1) == 0)
4327 {
4328 if (*option == '+')
4329 break;
4330 i++;
cristybb503372010-05-27 20:51:26 +00004331 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004332 ThrowMogrifyException(OptionError,"MissingArgument",option);
4333 if (IsGeometry(argv[i]) == MagickFalse)
4334 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4335 break;
4336 }
4337 if (LocaleCompare("deskew",option+1) == 0)
4338 {
4339 if (*option == '+')
4340 break;
4341 i++;
cristybb503372010-05-27 20:51:26 +00004342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004343 ThrowMogrifyException(OptionError,"MissingArgument",option);
4344 if (IsGeometry(argv[i]) == MagickFalse)
4345 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4346 break;
4347 }
4348 if (LocaleCompare("despeckle",option+1) == 0)
4349 break;
4350 if (LocaleCompare("dft",option+1) == 0)
4351 break;
cristyc9b12952010-03-28 01:12:28 +00004352 if (LocaleCompare("direction",option+1) == 0)
4353 {
cristybb503372010-05-27 20:51:26 +00004354 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004355 direction;
4356
4357 if (*option == '+')
4358 break;
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004362 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004363 argv[i]);
4364 if (direction < 0)
4365 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4366 argv[i]);
4367 break;
4368 }
cristy3ed852e2009-09-05 21:47:34 +00004369 if (LocaleCompare("display",option+1) == 0)
4370 {
4371 if (*option == '+')
4372 break;
4373 i++;
cristybb503372010-05-27 20:51:26 +00004374 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004375 ThrowMogrifyException(OptionError,"MissingArgument",option);
4376 break;
4377 }
4378 if (LocaleCompare("dispose",option+1) == 0)
4379 {
cristybb503372010-05-27 20:51:26 +00004380 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004381 dispose;
4382
4383 if (*option == '+')
4384 break;
4385 i++;
cristybb503372010-05-27 20:51:26 +00004386 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004387 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004388 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004389 if (dispose < 0)
4390 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4391 argv[i]);
4392 break;
4393 }
4394 if (LocaleCompare("distort",option+1) == 0)
4395 {
cristybb503372010-05-27 20:51:26 +00004396 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004397 op;
4398
4399 i++;
cristybb503372010-05-27 20:51:26 +00004400 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004401 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004402 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004403 if (op < 0)
4404 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4405 argv[i]);
4406 i++;
cristybb503372010-05-27 20:51:26 +00004407 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004408 ThrowMogrifyException(OptionError,"MissingArgument",option);
4409 break;
4410 }
4411 if (LocaleCompare("dither",option+1) == 0)
4412 {
cristybb503372010-05-27 20:51:26 +00004413 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004414 method;
4415
4416 if (*option == '+')
4417 break;
4418 i++;
cristybb503372010-05-27 20:51:26 +00004419 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004420 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004421 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004422 if (method < 0)
4423 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4424 argv[i]);
4425 break;
4426 }
4427 if (LocaleCompare("draw",option+1) == 0)
4428 {
4429 if (*option == '+')
4430 break;
4431 i++;
cristybb503372010-05-27 20:51:26 +00004432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004433 ThrowMogrifyException(OptionError,"MissingArgument",option);
4434 break;
4435 }
cristyecb10ff2011-03-22 13:14:03 +00004436 if (LocaleCompare("duplicate",option+1) == 0)
4437 {
4438 if (*option == '+')
4439 break;
4440 i++;
4441 if (i == (ssize_t) (argc-1))
4442 ThrowMogrifyException(OptionError,"MissingArgument",option);
4443 if (IsGeometry(argv[i]) == MagickFalse)
4444 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4445 break;
4446 }
cristy22879752009-10-25 23:55:40 +00004447 if (LocaleCompare("duration",option+1) == 0)
4448 {
4449 if (*option == '+')
4450 break;
4451 i++;
cristybb503372010-05-27 20:51:26 +00004452 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004453 ThrowMogrifyException(OptionError,"MissingArgument",option);
4454 if (IsGeometry(argv[i]) == MagickFalse)
4455 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4456 break;
4457 }
cristy3ed852e2009-09-05 21:47:34 +00004458 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4459 }
4460 case 'e':
4461 {
4462 if (LocaleCompare("edge",option+1) == 0)
4463 {
4464 if (*option == '+')
4465 break;
4466 i++;
cristybb503372010-05-27 20:51:26 +00004467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004468 ThrowMogrifyException(OptionError,"MissingArgument",option);
4469 if (IsGeometry(argv[i]) == MagickFalse)
4470 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4471 break;
4472 }
4473 if (LocaleCompare("emboss",option+1) == 0)
4474 {
4475 if (*option == '+')
4476 break;
4477 i++;
cristybb503372010-05-27 20:51:26 +00004478 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004479 ThrowMogrifyException(OptionError,"MissingArgument",option);
4480 if (IsGeometry(argv[i]) == MagickFalse)
4481 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4482 break;
4483 }
4484 if (LocaleCompare("encipher",option+1) == 0)
4485 {
4486 if (*option == '+')
4487 break;
4488 i++;
cristybb503372010-05-27 20:51:26 +00004489 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004490 ThrowMogrifyException(OptionError,"MissingArgument",option);
4491 break;
4492 }
4493 if (LocaleCompare("encoding",option+1) == 0)
4494 {
4495 if (*option == '+')
4496 break;
4497 i++;
cristybb503372010-05-27 20:51:26 +00004498 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004499 ThrowMogrifyException(OptionError,"MissingArgument",option);
4500 break;
4501 }
4502 if (LocaleCompare("endian",option+1) == 0)
4503 {
cristybb503372010-05-27 20:51:26 +00004504 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004505 endian;
4506
4507 if (*option == '+')
4508 break;
4509 i++;
cristybb503372010-05-27 20:51:26 +00004510 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004511 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004512 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004513 if (endian < 0)
4514 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4515 argv[i]);
4516 break;
4517 }
4518 if (LocaleCompare("enhance",option+1) == 0)
4519 break;
4520 if (LocaleCompare("equalize",option+1) == 0)
4521 break;
4522 if (LocaleCompare("evaluate",option+1) == 0)
4523 {
cristybb503372010-05-27 20:51:26 +00004524 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004525 op;
4526
4527 if (*option == '+')
4528 break;
4529 i++;
cristybb503372010-05-27 20:51:26 +00004530 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004531 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004532 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004533 if (op < 0)
4534 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4535 argv[i]);
4536 i++;
cristybb503372010-05-27 20:51:26 +00004537 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004538 ThrowMogrifyException(OptionError,"MissingArgument",option);
4539 if (IsGeometry(argv[i]) == MagickFalse)
4540 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4541 break;
4542 }
cristyd18ae7c2010-03-07 17:39:52 +00004543 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4544 {
cristybb503372010-05-27 20:51:26 +00004545 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004546 op;
4547
4548 if (*option == '+')
4549 break;
4550 i++;
cristybb503372010-05-27 20:51:26 +00004551 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004552 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004553 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004554 if (op < 0)
4555 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4556 argv[i]);
4557 break;
4558 }
cristy3ed852e2009-09-05 21:47:34 +00004559 if (LocaleCompare("extent",option+1) == 0)
4560 {
4561 if (*option == '+')
4562 break;
4563 i++;
cristybb503372010-05-27 20:51:26 +00004564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004565 ThrowMogrifyException(OptionError,"MissingArgument",option);
4566 if (IsGeometry(argv[i]) == MagickFalse)
4567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4568 break;
4569 }
4570 if (LocaleCompare("extract",option+1) == 0)
4571 {
4572 if (*option == '+')
4573 break;
4574 i++;
cristybb503372010-05-27 20:51:26 +00004575 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004576 ThrowMogrifyException(OptionError,"MissingArgument",option);
4577 if (IsGeometry(argv[i]) == MagickFalse)
4578 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4579 break;
4580 }
4581 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4582 }
4583 case 'f':
4584 {
4585 if (LocaleCompare("family",option+1) == 0)
4586 {
4587 if (*option == '+')
4588 break;
4589 i++;
cristybb503372010-05-27 20:51:26 +00004590 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004591 ThrowMogrifyException(OptionError,"MissingArgument",option);
4592 break;
4593 }
4594 if (LocaleCompare("fill",option+1) == 0)
4595 {
4596 if (*option == '+')
4597 break;
4598 i++;
cristybb503372010-05-27 20:51:26 +00004599 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004600 ThrowMogrifyException(OptionError,"MissingArgument",option);
4601 break;
4602 }
4603 if (LocaleCompare("filter",option+1) == 0)
4604 {
cristybb503372010-05-27 20:51:26 +00004605 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004606 filter;
4607
4608 if (*option == '+')
4609 break;
4610 i++;
cristybb503372010-05-27 20:51:26 +00004611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004612 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004613 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004614 if (filter < 0)
4615 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4616 argv[i]);
4617 break;
4618 }
4619 if (LocaleCompare("flatten",option+1) == 0)
4620 break;
4621 if (LocaleCompare("flip",option+1) == 0)
4622 break;
4623 if (LocaleCompare("flop",option+1) == 0)
4624 break;
4625 if (LocaleCompare("floodfill",option+1) == 0)
4626 {
4627 if (*option == '+')
4628 break;
4629 i++;
cristybb503372010-05-27 20:51:26 +00004630 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004631 ThrowMogrifyException(OptionError,"MissingArgument",option);
4632 if (IsGeometry(argv[i]) == MagickFalse)
4633 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4634 i++;
cristybb503372010-05-27 20:51:26 +00004635 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004636 ThrowMogrifyException(OptionError,"MissingArgument",option);
4637 break;
4638 }
4639 if (LocaleCompare("font",option+1) == 0)
4640 {
4641 if (*option == '+')
4642 break;
4643 i++;
cristybb503372010-05-27 20:51:26 +00004644 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004645 ThrowMogrifyException(OptionError,"MissingArgument",option);
4646 break;
4647 }
4648 if (LocaleCompare("format",option+1) == 0)
4649 {
4650 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4651 (void) CloneString(&format,(char *) NULL);
4652 if (*option == '+')
4653 break;
4654 i++;
cristybb503372010-05-27 20:51:26 +00004655 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004656 ThrowMogrifyException(OptionError,"MissingArgument",option);
4657 (void) CloneString(&format,argv[i]);
4658 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4659 (void) ConcatenateMagickString(image_info->filename,":",
4660 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004661 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004662 if (*image_info->magick == '\0')
4663 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4664 format);
4665 break;
4666 }
4667 if (LocaleCompare("frame",option+1) == 0)
4668 {
4669 if (*option == '+')
4670 break;
4671 i++;
cristybb503372010-05-27 20:51:26 +00004672 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 if (IsGeometry(argv[i]) == MagickFalse)
4675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676 break;
4677 }
4678 if (LocaleCompare("function",option+1) == 0)
4679 {
cristybb503372010-05-27 20:51:26 +00004680 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004681 op;
4682
4683 if (*option == '+')
4684 break;
4685 i++;
cristybb503372010-05-27 20:51:26 +00004686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004687 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004688 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004689 if (op < 0)
4690 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4691 i++;
cristybb503372010-05-27 20:51:26 +00004692 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004693 ThrowMogrifyException(OptionError,"MissingArgument",option);
4694 break;
4695 }
4696 if (LocaleCompare("fuzz",option+1) == 0)
4697 {
4698 if (*option == '+')
4699 break;
4700 i++;
cristybb503372010-05-27 20:51:26 +00004701 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004702 ThrowMogrifyException(OptionError,"MissingArgument",option);
4703 if (IsGeometry(argv[i]) == MagickFalse)
4704 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4705 break;
4706 }
4707 if (LocaleCompare("fx",option+1) == 0)
4708 {
4709 if (*option == '+')
4710 break;
4711 i++;
cristybb503372010-05-27 20:51:26 +00004712 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004713 ThrowMogrifyException(OptionError,"MissingArgument",option);
4714 break;
4715 }
4716 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4717 }
4718 case 'g':
4719 {
4720 if (LocaleCompare("gamma",option+1) == 0)
4721 {
4722 i++;
cristybb503372010-05-27 20:51:26 +00004723 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004724 ThrowMogrifyException(OptionError,"MissingArgument",option);
4725 if (IsGeometry(argv[i]) == MagickFalse)
4726 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4727 break;
4728 }
4729 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4730 (LocaleCompare("gaussian",option+1) == 0))
4731 {
4732 i++;
cristybb503372010-05-27 20:51:26 +00004733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004734 ThrowMogrifyException(OptionError,"MissingArgument",option);
4735 if (IsGeometry(argv[i]) == MagickFalse)
4736 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4737 break;
4738 }
4739 if (LocaleCompare("geometry",option+1) == 0)
4740 {
4741 if (*option == '+')
4742 break;
4743 i++;
cristybb503372010-05-27 20:51:26 +00004744 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004745 ThrowMogrifyException(OptionError,"MissingArgument",option);
4746 if (IsGeometry(argv[i]) == MagickFalse)
4747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4748 break;
4749 }
4750 if (LocaleCompare("gravity",option+1) == 0)
4751 {
cristybb503372010-05-27 20:51:26 +00004752 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004753 gravity;
4754
4755 if (*option == '+')
4756 break;
4757 i++;
cristybb503372010-05-27 20:51:26 +00004758 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004759 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004760 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004761 if (gravity < 0)
4762 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4763 argv[i]);
4764 break;
4765 }
4766 if (LocaleCompare("green-primary",option+1) == 0)
4767 {
4768 if (*option == '+')
4769 break;
4770 i++;
cristybb503372010-05-27 20:51:26 +00004771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004772 ThrowMogrifyException(OptionError,"MissingArgument",option);
4773 if (IsGeometry(argv[i]) == MagickFalse)
4774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4775 break;
4776 }
4777 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4778 }
4779 case 'h':
4780 {
4781 if (LocaleCompare("hald-clut",option+1) == 0)
4782 break;
4783 if ((LocaleCompare("help",option+1) == 0) ||
4784 (LocaleCompare("-help",option+1) == 0))
4785 return(MogrifyUsage());
4786 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4787 }
4788 case 'i':
4789 {
4790 if (LocaleCompare("identify",option+1) == 0)
4791 break;
4792 if (LocaleCompare("idft",option+1) == 0)
4793 break;
4794 if (LocaleCompare("implode",option+1) == 0)
4795 {
4796 if (*option == '+')
4797 break;
4798 i++;
cristybb503372010-05-27 20:51:26 +00004799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004800 ThrowMogrifyException(OptionError,"MissingArgument",option);
4801 if (IsGeometry(argv[i]) == MagickFalse)
4802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4803 break;
4804 }
4805 if (LocaleCompare("intent",option+1) == 0)
4806 {
cristybb503372010-05-27 20:51:26 +00004807 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004808 intent;
4809
4810 if (*option == '+')
4811 break;
4812 i++;
cristybb503372010-05-27 20:51:26 +00004813 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004814 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004815 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004816 if (intent < 0)
4817 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4818 argv[i]);
4819 break;
4820 }
4821 if (LocaleCompare("interlace",option+1) == 0)
4822 {
cristybb503372010-05-27 20:51:26 +00004823 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004824 interlace;
4825
4826 if (*option == '+')
4827 break;
4828 i++;
cristybb503372010-05-27 20:51:26 +00004829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004830 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004831 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004832 argv[i]);
4833 if (interlace < 0)
4834 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4835 argv[i]);
4836 break;
4837 }
cristyb32b90a2009-09-07 21:45:48 +00004838 if (LocaleCompare("interline-spacing",option+1) == 0)
4839 {
4840 if (*option == '+')
4841 break;
4842 i++;
cristybb503372010-05-27 20:51:26 +00004843 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004844 ThrowMogrifyException(OptionError,"MissingArgument",option);
4845 if (IsGeometry(argv[i]) == MagickFalse)
4846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4847 break;
4848 }
cristy3ed852e2009-09-05 21:47:34 +00004849 if (LocaleCompare("interpolate",option+1) == 0)
4850 {
cristybb503372010-05-27 20:51:26 +00004851 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004852 interpolate;
4853
4854 if (*option == '+')
4855 break;
4856 i++;
cristybb503372010-05-27 20:51:26 +00004857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004858 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004859 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004860 argv[i]);
4861 if (interpolate < 0)
4862 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4863 argv[i]);
4864 break;
4865 }
4866 if (LocaleCompare("interword-spacing",option+1) == 0)
4867 {
4868 if (*option == '+')
4869 break;
4870 i++;
cristybb503372010-05-27 20:51:26 +00004871 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004872 ThrowMogrifyException(OptionError,"MissingArgument",option);
4873 if (IsGeometry(argv[i]) == MagickFalse)
4874 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4875 break;
4876 }
4877 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4878 }
4879 case 'k':
4880 {
4881 if (LocaleCompare("kerning",option+1) == 0)
4882 {
4883 if (*option == '+')
4884 break;
4885 i++;
cristybb503372010-05-27 20:51:26 +00004886 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004887 ThrowMogrifyException(OptionError,"MissingArgument",option);
4888 if (IsGeometry(argv[i]) == MagickFalse)
4889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4890 break;
4891 }
4892 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4893 }
4894 case 'l':
4895 {
4896 if (LocaleCompare("label",option+1) == 0)
4897 {
4898 if (*option == '+')
4899 break;
4900 i++;
cristybb503372010-05-27 20:51:26 +00004901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004902 ThrowMogrifyException(OptionError,"MissingArgument",option);
4903 break;
4904 }
4905 if (LocaleCompare("lat",option+1) == 0)
4906 {
4907 if (*option == '+')
4908 break;
4909 i++;
cristybb503372010-05-27 20:51:26 +00004910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004911 ThrowMogrifyException(OptionError,"MissingArgument",option);
4912 if (IsGeometry(argv[i]) == MagickFalse)
4913 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4914 }
4915 if (LocaleCompare("layers",option+1) == 0)
4916 {
cristybb503372010-05-27 20:51:26 +00004917 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004918 type;
4919
4920 if (*option == '+')
4921 break;
4922 i++;
cristybb503372010-05-27 20:51:26 +00004923 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004924 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004925 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004926 if (type < 0)
4927 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4928 argv[i]);
4929 break;
4930 }
4931 if (LocaleCompare("level",option+1) == 0)
4932 {
4933 i++;
cristybb503372010-05-27 20:51:26 +00004934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004935 ThrowMogrifyException(OptionError,"MissingArgument",option);
4936 if (IsGeometry(argv[i]) == MagickFalse)
4937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4938 break;
4939 }
4940 if (LocaleCompare("level-colors",option+1) == 0)
4941 {
4942 i++;
cristybb503372010-05-27 20:51:26 +00004943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004944 ThrowMogrifyException(OptionError,"MissingArgument",option);
4945 break;
4946 }
4947 if (LocaleCompare("linewidth",option+1) == 0)
4948 {
4949 if (*option == '+')
4950 break;
4951 i++;
cristybb503372010-05-27 20:51:26 +00004952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004953 ThrowMogrifyException(OptionError,"MissingArgument",option);
4954 if (IsGeometry(argv[i]) == MagickFalse)
4955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4956 break;
4957 }
4958 if (LocaleCompare("limit",option+1) == 0)
4959 {
4960 char
4961 *p;
4962
4963 double
4964 value;
4965
cristybb503372010-05-27 20:51:26 +00004966 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004967 resource;
4968
4969 if (*option == '+')
4970 break;
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);
cristy042ee782011-04-22 18:48:30 +00004974 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004975 argv[i]);
4976 if (resource < 0)
4977 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4978 argv[i]);
4979 i++;
cristybb503372010-05-27 20:51:26 +00004980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004981 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004982 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004983 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004984 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4986 break;
4987 }
4988 if (LocaleCompare("liquid-rescale",option+1) == 0)
4989 {
4990 i++;
cristybb503372010-05-27 20:51:26 +00004991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004992 ThrowMogrifyException(OptionError,"MissingArgument",option);
4993 if (IsGeometry(argv[i]) == MagickFalse)
4994 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4995 break;
4996 }
4997 if (LocaleCompare("list",option+1) == 0)
4998 {
cristybb503372010-05-27 20:51:26 +00004999 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005000 list;
5001
5002 if (*option == '+')
5003 break;
5004 i++;
cristybb503372010-05-27 20:51:26 +00005005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005006 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005007 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005008 if (list < 0)
5009 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005010 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005011 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005012 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005013 }
5014 if (LocaleCompare("log",option+1) == 0)
5015 {
5016 if (*option == '+')
5017 break;
5018 i++;
cristybb503372010-05-27 20:51:26 +00005019 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005020 (strchr(argv[i],'%') == (char *) NULL))
5021 ThrowMogrifyException(OptionError,"MissingArgument",option);
5022 break;
5023 }
5024 if (LocaleCompare("loop",option+1) == 0)
5025 {
5026 if (*option == '+')
5027 break;
5028 i++;
cristybb503372010-05-27 20:51:26 +00005029 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005030 ThrowMogrifyException(OptionError,"MissingArgument",option);
5031 if (IsGeometry(argv[i]) == MagickFalse)
5032 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5033 break;
5034 }
5035 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5036 }
5037 case 'm':
5038 {
5039 if (LocaleCompare("map",option+1) == 0)
5040 {
5041 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5042 if (*option == '+')
5043 break;
5044 i++;
cristybb503372010-05-27 20:51:26 +00005045 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005046 ThrowMogrifyException(OptionError,"MissingArgument",option);
5047 break;
5048 }
5049 if (LocaleCompare("mask",option+1) == 0)
5050 {
5051 if (*option == '+')
5052 break;
5053 i++;
cristybb503372010-05-27 20:51:26 +00005054 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005055 ThrowMogrifyException(OptionError,"MissingArgument",option);
5056 break;
5057 }
5058 if (LocaleCompare("matte",option+1) == 0)
5059 break;
5060 if (LocaleCompare("mattecolor",option+1) == 0)
5061 {
5062 if (*option == '+')
5063 break;
5064 i++;
cristybb503372010-05-27 20:51:26 +00005065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005066 ThrowMogrifyException(OptionError,"MissingArgument",option);
5067 break;
5068 }
cristyf40785b2010-03-06 02:27:27 +00005069 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005070 break;
cristyf40785b2010-03-06 02:27:27 +00005071 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005072 break;
cristy3ed852e2009-09-05 21:47:34 +00005073 if (LocaleCompare("modulate",option+1) == 0)
5074 {
5075 if (*option == '+')
5076 break;
5077 i++;
cristybb503372010-05-27 20:51:26 +00005078 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005079 ThrowMogrifyException(OptionError,"MissingArgument",option);
5080 if (IsGeometry(argv[i]) == MagickFalse)
5081 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5082 break;
5083 }
5084 if (LocaleCompare("median",option+1) == 0)
5085 {
5086 if (*option == '+')
5087 break;
5088 i++;
cristybb503372010-05-27 20:51:26 +00005089 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005090 ThrowMogrifyException(OptionError,"MissingArgument",option);
5091 if (IsGeometry(argv[i]) == MagickFalse)
5092 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5093 break;
5094 }
cristy69ec32d2011-02-27 23:57:09 +00005095 if (LocaleCompare("mode",option+1) == 0)
5096 {
5097 if (*option == '+')
5098 break;
5099 i++;
5100 if (i == (ssize_t) argc)
5101 ThrowMogrifyException(OptionError,"MissingArgument",option);
5102 if (IsGeometry(argv[i]) == MagickFalse)
5103 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5104 break;
5105 }
cristy3ed852e2009-09-05 21:47:34 +00005106 if (LocaleCompare("monitor",option+1) == 0)
5107 break;
5108 if (LocaleCompare("monochrome",option+1) == 0)
5109 break;
5110 if (LocaleCompare("morph",option+1) == 0)
5111 {
5112 if (*option == '+')
5113 break;
5114 i++;
cristybb503372010-05-27 20:51:26 +00005115 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005116 ThrowMogrifyException(OptionError,"MissingArgument",option);
5117 if (IsGeometry(argv[i]) == MagickFalse)
5118 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5119 break;
5120 }
anthony29188a82010-01-22 10:12:34 +00005121 if (LocaleCompare("morphology",option+1) == 0)
5122 {
anthony29188a82010-01-22 10:12:34 +00005123 char
5124 token[MaxTextExtent];
5125
cristyb6bd4ad2010-08-08 01:12:27 +00005126 KernelInfo
5127 *kernel_info;
5128
5129 ssize_t
5130 op;
5131
anthony29188a82010-01-22 10:12:34 +00005132 i++;
cristybb503372010-05-27 20:51:26 +00005133 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005134 ThrowMogrifyException(OptionError,"MissingArgument",option);
5135 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005136 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005137 if (op < 0)
5138 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005139 token);
anthony29188a82010-01-22 10:12:34 +00005140 i++;
cristybb503372010-05-27 20:51:26 +00005141 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005142 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005143 kernel_info=AcquireKernelInfo(argv[i]);
5144 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005145 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005146 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005147 break;
5148 }
cristy3ed852e2009-09-05 21:47:34 +00005149 if (LocaleCompare("mosaic",option+1) == 0)
5150 break;
5151 if (LocaleCompare("motion-blur",option+1) == 0)
5152 {
5153 if (*option == '+')
5154 break;
5155 i++;
cristybb503372010-05-27 20:51:26 +00005156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005157 ThrowMogrifyException(OptionError,"MissingArgument",option);
5158 if (IsGeometry(argv[i]) == MagickFalse)
5159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5160 break;
5161 }
5162 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5163 }
5164 case 'n':
5165 {
5166 if (LocaleCompare("negate",option+1) == 0)
5167 break;
5168 if (LocaleCompare("noise",option+1) == 0)
5169 {
5170 i++;
cristybb503372010-05-27 20:51:26 +00005171 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005172 ThrowMogrifyException(OptionError,"MissingArgument",option);
5173 if (*option == '+')
5174 {
cristybb503372010-05-27 20:51:26 +00005175 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005176 noise;
5177
cristy042ee782011-04-22 18:48:30 +00005178 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005179 if (noise < 0)
5180 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5181 argv[i]);
5182 break;
5183 }
5184 if (IsGeometry(argv[i]) == MagickFalse)
5185 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5186 break;
5187 }
5188 if (LocaleCompare("noop",option+1) == 0)
5189 break;
5190 if (LocaleCompare("normalize",option+1) == 0)
5191 break;
5192 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5193 }
5194 case 'o':
5195 {
5196 if (LocaleCompare("opaque",option+1) == 0)
5197 {
cristy3ed852e2009-09-05 21:47:34 +00005198 i++;
cristybb503372010-05-27 20:51:26 +00005199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005200 ThrowMogrifyException(OptionError,"MissingArgument",option);
5201 break;
5202 }
5203 if (LocaleCompare("ordered-dither",option+1) == 0)
5204 {
5205 if (*option == '+')
5206 break;
5207 i++;
cristybb503372010-05-27 20:51:26 +00005208 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005209 ThrowMogrifyException(OptionError,"MissingArgument",option);
5210 break;
5211 }
5212 if (LocaleCompare("orient",option+1) == 0)
5213 {
cristybb503372010-05-27 20:51:26 +00005214 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005215 orientation;
5216
5217 orientation=UndefinedOrientation;
5218 if (*option == '+')
5219 break;
5220 i++;
cristybb503372010-05-27 20:51:26 +00005221 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005222 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005223 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005224 argv[i]);
5225 if (orientation < 0)
5226 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5227 argv[i]);
5228 break;
5229 }
5230 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5231 }
5232 case 'p':
5233 {
5234 if (LocaleCompare("page",option+1) == 0)
5235 {
5236 if (*option == '+')
5237 break;
5238 i++;
cristybb503372010-05-27 20:51:26 +00005239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005240 ThrowMogrifyException(OptionError,"MissingArgument",option);
5241 break;
5242 }
5243 if (LocaleCompare("paint",option+1) == 0)
5244 {
5245 if (*option == '+')
5246 break;
5247 i++;
cristybb503372010-05-27 20:51:26 +00005248 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005249 ThrowMogrifyException(OptionError,"MissingArgument",option);
5250 if (IsGeometry(argv[i]) == MagickFalse)
5251 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5252 break;
5253 }
5254 if (LocaleCompare("path",option+1) == 0)
5255 {
5256 (void) CloneString(&path,(char *) NULL);
5257 if (*option == '+')
5258 break;
5259 i++;
cristybb503372010-05-27 20:51:26 +00005260 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005261 ThrowMogrifyException(OptionError,"MissingArgument",option);
5262 (void) CloneString(&path,argv[i]);
5263 break;
5264 }
5265 if (LocaleCompare("pointsize",option+1) == 0)
5266 {
5267 if (*option == '+')
5268 break;
5269 i++;
cristybb503372010-05-27 20:51:26 +00005270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005271 ThrowMogrifyException(OptionError,"MissingArgument",option);
5272 if (IsGeometry(argv[i]) == MagickFalse)
5273 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5274 break;
5275 }
5276 if (LocaleCompare("polaroid",option+1) == 0)
5277 {
5278 if (*option == '+')
5279 break;
5280 i++;
cristybb503372010-05-27 20:51:26 +00005281 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005282 ThrowMogrifyException(OptionError,"MissingArgument",option);
5283 if (IsGeometry(argv[i]) == MagickFalse)
5284 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5285 break;
5286 }
5287 if (LocaleCompare("posterize",option+1) == 0)
5288 {
5289 if (*option == '+')
5290 break;
5291 i++;
cristybb503372010-05-27 20:51:26 +00005292 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005293 ThrowMogrifyException(OptionError,"MissingArgument",option);
5294 if (IsGeometry(argv[i]) == MagickFalse)
5295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5296 break;
5297 }
cristye7f51092010-01-17 00:39:37 +00005298 if (LocaleCompare("precision",option+1) == 0)
5299 {
5300 if (*option == '+')
5301 break;
5302 i++;
cristybb503372010-05-27 20:51:26 +00005303 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005304 ThrowMogrifyException(OptionError,"MissingArgument",option);
5305 if (IsGeometry(argv[i]) == MagickFalse)
5306 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5307 break;
5308 }
cristy3ed852e2009-09-05 21:47:34 +00005309 if (LocaleCompare("print",option+1) == 0)
5310 {
5311 if (*option == '+')
5312 break;
5313 i++;
cristybb503372010-05-27 20:51:26 +00005314 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005315 ThrowMogrifyException(OptionError,"MissingArgument",option);
5316 break;
5317 }
5318 if (LocaleCompare("process",option+1) == 0)
5319 {
5320 if (*option == '+')
5321 break;
5322 i++;
cristybb503372010-05-27 20:51:26 +00005323 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005324 ThrowMogrifyException(OptionError,"MissingArgument",option);
5325 break;
5326 }
5327 if (LocaleCompare("profile",option+1) == 0)
5328 {
5329 i++;
cristybb503372010-05-27 20:51:26 +00005330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 break;
5333 }
5334 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5335 }
5336 case 'q':
5337 {
5338 if (LocaleCompare("quality",option+1) == 0)
5339 {
5340 if (*option == '+')
5341 break;
5342 i++;
cristybb503372010-05-27 20:51:26 +00005343 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005344 ThrowMogrifyException(OptionError,"MissingArgument",option);
5345 if (IsGeometry(argv[i]) == MagickFalse)
5346 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5347 break;
5348 }
5349 if (LocaleCompare("quantize",option+1) == 0)
5350 {
cristybb503372010-05-27 20:51:26 +00005351 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005352 colorspace;
5353
5354 if (*option == '+')
5355 break;
5356 i++;
cristybb503372010-05-27 20:51:26 +00005357 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005358 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005359 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005360 argv[i]);
5361 if (colorspace < 0)
5362 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5363 argv[i]);
5364 break;
5365 }
5366 if (LocaleCompare("quiet",option+1) == 0)
5367 break;
5368 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5369 }
5370 case 'r':
5371 {
5372 if (LocaleCompare("radial-blur",option+1) == 0)
5373 {
5374 i++;
cristybb503372010-05-27 20:51:26 +00005375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005376 ThrowMogrifyException(OptionError,"MissingArgument",option);
5377 if (IsGeometry(argv[i]) == MagickFalse)
5378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5379 break;
5380 }
5381 if (LocaleCompare("raise",option+1) == 0)
5382 {
5383 i++;
cristybb503372010-05-27 20:51:26 +00005384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005385 ThrowMogrifyException(OptionError,"MissingArgument",option);
5386 if (IsGeometry(argv[i]) == MagickFalse)
5387 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5388 break;
5389 }
5390 if (LocaleCompare("random-threshold",option+1) == 0)
5391 {
5392 if (*option == '+')
5393 break;
5394 i++;
cristybb503372010-05-27 20:51:26 +00005395 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005396 ThrowMogrifyException(OptionError,"MissingArgument",option);
5397 if (IsGeometry(argv[i]) == MagickFalse)
5398 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5399 break;
5400 }
cristye6365592010-04-02 17:31:23 +00005401 if (LocaleCompare("recolor",option+1) == 0)
5402 {
5403 if (*option == '+')
5404 break;
5405 i++;
cristybb503372010-05-27 20:51:26 +00005406 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005407 ThrowMogrifyException(OptionError,"MissingArgument",option);
5408 if (IsGeometry(argv[i]) == MagickFalse)
5409 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5410 break;
5411 }
cristy3ed852e2009-09-05 21:47:34 +00005412 if (LocaleCompare("red-primary",option+1) == 0)
5413 {
5414 if (*option == '+')
5415 break;
5416 i++;
cristybb503372010-05-27 20:51:26 +00005417 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005418 ThrowMogrifyException(OptionError,"MissingArgument",option);
5419 if (IsGeometry(argv[i]) == MagickFalse)
5420 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5421 }
cristy9f2083a2010-04-22 19:48:05 +00005422 if (LocaleCompare("regard-warnings",option+1) == 0)
5423 break;
cristy3ed852e2009-09-05 21:47:34 +00005424 if (LocaleCompare("region",option+1) == 0)
5425 {
5426 if (*option == '+')
5427 break;
5428 i++;
cristybb503372010-05-27 20:51:26 +00005429 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005430 ThrowMogrifyException(OptionError,"MissingArgument",option);
5431 if (IsGeometry(argv[i]) == MagickFalse)
5432 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5433 break;
5434 }
cristyf0c78232010-03-15 12:53:40 +00005435 if (LocaleCompare("remap",option+1) == 0)
5436 {
5437 if (*option == '+')
5438 break;
5439 i++;
cristybb503372010-05-27 20:51:26 +00005440 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005441 ThrowMogrifyException(OptionError,"MissingArgument",option);
5442 break;
5443 }
cristy3ed852e2009-09-05 21:47:34 +00005444 if (LocaleCompare("render",option+1) == 0)
5445 break;
5446 if (LocaleCompare("repage",option+1) == 0)
5447 {
5448 if (*option == '+')
5449 break;
5450 i++;
cristybb503372010-05-27 20:51:26 +00005451 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005452 ThrowMogrifyException(OptionError,"MissingArgument",option);
5453 if (IsGeometry(argv[i]) == MagickFalse)
5454 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5455 break;
5456 }
5457 if (LocaleCompare("resample",option+1) == 0)
5458 {
5459 if (*option == '+')
5460 break;
5461 i++;
cristybb503372010-05-27 20:51:26 +00005462 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005463 ThrowMogrifyException(OptionError,"MissingArgument",option);
5464 if (IsGeometry(argv[i]) == MagickFalse)
5465 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5466 break;
5467 }
5468 if (LocaleCompare("resize",option+1) == 0)
5469 {
5470 if (*option == '+')
5471 break;
5472 i++;
cristybb503372010-05-27 20:51:26 +00005473 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005474 ThrowMogrifyException(OptionError,"MissingArgument",option);
5475 if (IsGeometry(argv[i]) == MagickFalse)
5476 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5477 break;
5478 }
cristyebbcfea2011-02-25 02:43:54 +00005479 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5480 {
5481 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5482 break;
5483 }
cristy3ed852e2009-09-05 21:47:34 +00005484 if (LocaleCompare("reverse",option+1) == 0)
5485 break;
5486 if (LocaleCompare("roll",option+1) == 0)
5487 {
5488 if (*option == '+')
5489 break;
5490 i++;
cristybb503372010-05-27 20:51:26 +00005491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005492 ThrowMogrifyException(OptionError,"MissingArgument",option);
5493 if (IsGeometry(argv[i]) == MagickFalse)
5494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5495 break;
5496 }
5497 if (LocaleCompare("rotate",option+1) == 0)
5498 {
5499 i++;
cristybb503372010-05-27 20:51:26 +00005500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005501 ThrowMogrifyException(OptionError,"MissingArgument",option);
5502 if (IsGeometry(argv[i]) == MagickFalse)
5503 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5504 break;
5505 }
5506 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5507 }
5508 case 's':
5509 {
5510 if (LocaleCompare("sample",option+1) == 0)
5511 {
5512 if (*option == '+')
5513 break;
5514 i++;
cristybb503372010-05-27 20:51:26 +00005515 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005516 ThrowMogrifyException(OptionError,"MissingArgument",option);
5517 if (IsGeometry(argv[i]) == MagickFalse)
5518 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5519 break;
5520 }
5521 if (LocaleCompare("sampling-factor",option+1) == 0)
5522 {
5523 if (*option == '+')
5524 break;
5525 i++;
cristybb503372010-05-27 20:51:26 +00005526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005527 ThrowMogrifyException(OptionError,"MissingArgument",option);
5528 if (IsGeometry(argv[i]) == MagickFalse)
5529 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5530 break;
5531 }
5532 if (LocaleCompare("scale",option+1) == 0)
5533 {
5534 if (*option == '+')
5535 break;
5536 i++;
cristybb503372010-05-27 20:51:26 +00005537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005538 ThrowMogrifyException(OptionError,"MissingArgument",option);
5539 if (IsGeometry(argv[i]) == MagickFalse)
5540 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5541 break;
5542 }
5543 if (LocaleCompare("scene",option+1) == 0)
5544 {
5545 if (*option == '+')
5546 break;
5547 i++;
cristybb503372010-05-27 20:51:26 +00005548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005549 ThrowMogrifyException(OptionError,"MissingArgument",option);
5550 if (IsGeometry(argv[i]) == MagickFalse)
5551 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5552 break;
5553 }
5554 if (LocaleCompare("seed",option+1) == 0)
5555 {
5556 if (*option == '+')
5557 break;
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 if (IsGeometry(argv[i]) == MagickFalse)
5562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563 break;
5564 }
5565 if (LocaleCompare("segment",option+1) == 0)
5566 {
5567 if (*option == '+')
5568 break;
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005571 ThrowMogrifyException(OptionError,"MissingArgument",option);
5572 if (IsGeometry(argv[i]) == MagickFalse)
5573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574 break;
5575 }
5576 if (LocaleCompare("selective-blur",option+1) == 0)
5577 {
5578 i++;
cristybb503372010-05-27 20:51:26 +00005579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005580 ThrowMogrifyException(OptionError,"MissingArgument",option);
5581 if (IsGeometry(argv[i]) == MagickFalse)
5582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5583 break;
5584 }
5585 if (LocaleCompare("separate",option+1) == 0)
5586 break;
5587 if (LocaleCompare("sepia-tone",option+1) == 0)
5588 {
5589 if (*option == '+')
5590 break;
5591 i++;
cristybb503372010-05-27 20:51:26 +00005592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005593 ThrowMogrifyException(OptionError,"MissingArgument",option);
5594 if (IsGeometry(argv[i]) == MagickFalse)
5595 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5596 break;
5597 }
5598 if (LocaleCompare("set",option+1) == 0)
5599 {
5600 i++;
cristybb503372010-05-27 20:51:26 +00005601 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005602 ThrowMogrifyException(OptionError,"MissingArgument",option);
5603 if (*option == '+')
5604 break;
5605 i++;
cristybb503372010-05-27 20:51:26 +00005606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 break;
5609 }
5610 if (LocaleCompare("shade",option+1) == 0)
5611 {
5612 i++;
cristybb503372010-05-27 20:51:26 +00005613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005614 ThrowMogrifyException(OptionError,"MissingArgument",option);
5615 if (IsGeometry(argv[i]) == MagickFalse)
5616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5617 break;
5618 }
5619 if (LocaleCompare("shadow",option+1) == 0)
5620 {
5621 if (*option == '+')
5622 break;
5623 i++;
cristybb503372010-05-27 20:51:26 +00005624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005625 ThrowMogrifyException(OptionError,"MissingArgument",option);
5626 if (IsGeometry(argv[i]) == MagickFalse)
5627 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5628 break;
5629 }
5630 if (LocaleCompare("sharpen",option+1) == 0)
5631 {
5632 i++;
cristybb503372010-05-27 20:51:26 +00005633 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005634 ThrowMogrifyException(OptionError,"MissingArgument",option);
5635 if (IsGeometry(argv[i]) == MagickFalse)
5636 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5637 break;
5638 }
5639 if (LocaleCompare("shave",option+1) == 0)
5640 {
5641 if (*option == '+')
5642 break;
5643 i++;
cristybb503372010-05-27 20:51:26 +00005644 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005645 ThrowMogrifyException(OptionError,"MissingArgument",option);
5646 if (IsGeometry(argv[i]) == MagickFalse)
5647 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5648 break;
5649 }
5650 if (LocaleCompare("shear",option+1) == 0)
5651 {
5652 i++;
cristybb503372010-05-27 20:51:26 +00005653 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005654 ThrowMogrifyException(OptionError,"MissingArgument",option);
5655 if (IsGeometry(argv[i]) == MagickFalse)
5656 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5657 break;
5658 }
5659 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5660 {
5661 i++;
cristybb503372010-05-27 20:51:26 +00005662 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005663 ThrowMogrifyException(OptionError,"MissingArgument",option);
5664 if (IsGeometry(argv[i]) == MagickFalse)
5665 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5666 break;
5667 }
5668 if (LocaleCompare("size",option+1) == 0)
5669 {
5670 if (*option == '+')
5671 break;
5672 i++;
cristybb503372010-05-27 20:51:26 +00005673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005674 ThrowMogrifyException(OptionError,"MissingArgument",option);
5675 if (IsGeometry(argv[i]) == MagickFalse)
5676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5677 break;
5678 }
5679 if (LocaleCompare("sketch",option+1) == 0)
5680 {
5681 if (*option == '+')
5682 break;
5683 i++;
cristybb503372010-05-27 20:51:26 +00005684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005685 ThrowMogrifyException(OptionError,"MissingArgument",option);
5686 if (IsGeometry(argv[i]) == MagickFalse)
5687 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5688 break;
5689 }
cristy4285d782011-02-09 20:12:28 +00005690 if (LocaleCompare("smush",option+1) == 0)
5691 {
cristy4285d782011-02-09 20:12:28 +00005692 i++;
5693 if (i == (ssize_t) argc)
5694 ThrowMogrifyException(OptionError,"MissingArgument",option);
5695 if (IsGeometry(argv[i]) == MagickFalse)
5696 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005697 i++;
5698 break;
5699 }
cristy3ed852e2009-09-05 21:47:34 +00005700 if (LocaleCompare("solarize",option+1) == 0)
5701 {
5702 if (*option == '+')
5703 break;
5704 i++;
cristybb503372010-05-27 20:51:26 +00005705 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005706 ThrowMogrifyException(OptionError,"MissingArgument",option);
5707 if (IsGeometry(argv[i]) == MagickFalse)
5708 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5709 break;
5710 }
5711 if (LocaleCompare("sparse-color",option+1) == 0)
5712 {
cristybb503372010-05-27 20:51:26 +00005713 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005714 op;
5715
5716 i++;
cristybb503372010-05-27 20:51:26 +00005717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005718 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005719 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005720 if (op < 0)
5721 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5722 argv[i]);
5723 i++;
cristybb503372010-05-27 20:51:26 +00005724 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005725 ThrowMogrifyException(OptionError,"MissingArgument",option);
5726 break;
5727 }
5728 if (LocaleCompare("spread",option+1) == 0)
5729 {
5730 if (*option == '+')
5731 break;
5732 i++;
cristybb503372010-05-27 20:51:26 +00005733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005734 ThrowMogrifyException(OptionError,"MissingArgument",option);
5735 if (IsGeometry(argv[i]) == MagickFalse)
5736 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5737 break;
5738 }
cristy0834d642011-03-18 18:26:08 +00005739 if (LocaleCompare("statistic",option+1) == 0)
5740 {
5741 ssize_t
5742 op;
5743
5744 if (*option == '+')
5745 break;
5746 i++;
5747 if (i == (ssize_t) argc)
5748 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005749 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005750 if (op < 0)
5751 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5752 argv[i]);
5753 i++;
5754 if (i == (ssize_t) (argc-1))
5755 ThrowMogrifyException(OptionError,"MissingArgument",option);
5756 if (IsGeometry(argv[i]) == MagickFalse)
5757 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5758 break;
5759 }
cristy3ed852e2009-09-05 21:47:34 +00005760 if (LocaleCompare("stretch",option+1) == 0)
5761 {
cristybb503372010-05-27 20:51:26 +00005762 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005763 stretch;
5764
5765 if (*option == '+')
5766 break;
5767 i++;
cristybb503372010-05-27 20:51:26 +00005768 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005769 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005770 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005771 if (stretch < 0)
5772 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5773 argv[i]);
5774 break;
5775 }
5776 if (LocaleCompare("strip",option+1) == 0)
5777 break;
5778 if (LocaleCompare("stroke",option+1) == 0)
5779 {
5780 if (*option == '+')
5781 break;
5782 i++;
cristybb503372010-05-27 20:51:26 +00005783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 break;
5786 }
5787 if (LocaleCompare("strokewidth",option+1) == 0)
5788 {
5789 if (*option == '+')
5790 break;
5791 i++;
cristybb503372010-05-27 20:51:26 +00005792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005793 ThrowMogrifyException(OptionError,"MissingArgument",option);
5794 if (IsGeometry(argv[i]) == MagickFalse)
5795 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5796 break;
5797 }
5798 if (LocaleCompare("style",option+1) == 0)
5799 {
cristybb503372010-05-27 20:51:26 +00005800 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005801 style;
5802
5803 if (*option == '+')
5804 break;
5805 i++;
cristybb503372010-05-27 20:51:26 +00005806 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005807 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005808 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005809 if (style < 0)
5810 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5811 argv[i]);
5812 break;
5813 }
cristyecb10ff2011-03-22 13:14:03 +00005814 if (LocaleCompare("swap",option+1) == 0)
5815 {
5816 if (*option == '+')
5817 break;
5818 i++;
5819 if (i == (ssize_t) (argc-1))
5820 ThrowMogrifyException(OptionError,"MissingArgument",option);
5821 if (IsGeometry(argv[i]) == MagickFalse)
5822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5823 break;
5824 }
cristy3ed852e2009-09-05 21:47:34 +00005825 if (LocaleCompare("swirl",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 if (IsGeometry(argv[i]) == MagickFalse)
5833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834 break;
5835 }
cristyd9a29192010-10-16 16:49:53 +00005836 if (LocaleCompare("synchronize",option+1) == 0)
5837 break;
cristy3ed852e2009-09-05 21:47:34 +00005838 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5839 }
5840 case 't':
5841 {
5842 if (LocaleCompare("taint",option+1) == 0)
5843 break;
5844 if (LocaleCompare("texture",option+1) == 0)
5845 {
5846 if (*option == '+')
5847 break;
5848 i++;
cristybb503372010-05-27 20:51:26 +00005849 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005850 ThrowMogrifyException(OptionError,"MissingArgument",option);
5851 break;
5852 }
5853 if (LocaleCompare("tile",option+1) == 0)
5854 {
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 break;
5861 }
5862 if (LocaleCompare("tile-offset",option+1) == 0)
5863 {
5864 if (*option == '+')
5865 break;
5866 i++;
cristybb503372010-05-27 20:51:26 +00005867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005868 ThrowMogrifyException(OptionError,"MissingArgument",option);
5869 if (IsGeometry(argv[i]) == MagickFalse)
5870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5871 break;
5872 }
5873 if (LocaleCompare("tint",option+1) == 0)
5874 {
5875 if (*option == '+')
5876 break;
5877 i++;
cristybb503372010-05-27 20:51:26 +00005878 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005879 ThrowMogrifyException(OptionError,"MissingArgument",option);
5880 if (IsGeometry(argv[i]) == MagickFalse)
5881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5882 break;
5883 }
5884 if (LocaleCompare("transform",option+1) == 0)
5885 break;
5886 if (LocaleCompare("transpose",option+1) == 0)
5887 break;
5888 if (LocaleCompare("transverse",option+1) == 0)
5889 break;
5890 if (LocaleCompare("threshold",option+1) == 0)
5891 {
5892 if (*option == '+')
5893 break;
5894 i++;
cristybb503372010-05-27 20:51:26 +00005895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005896 ThrowMogrifyException(OptionError,"MissingArgument",option);
5897 if (IsGeometry(argv[i]) == MagickFalse)
5898 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5899 break;
5900 }
5901 if (LocaleCompare("thumbnail",option+1) == 0)
5902 {
5903 if (*option == '+')
5904 break;
5905 i++;
cristybb503372010-05-27 20:51:26 +00005906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005907 ThrowMogrifyException(OptionError,"MissingArgument",option);
5908 if (IsGeometry(argv[i]) == MagickFalse)
5909 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5910 break;
5911 }
5912 if (LocaleCompare("transparent",option+1) == 0)
5913 {
5914 i++;
cristybb503372010-05-27 20:51:26 +00005915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005916 ThrowMogrifyException(OptionError,"MissingArgument",option);
5917 break;
5918 }
5919 if (LocaleCompare("transparent-color",option+1) == 0)
5920 {
5921 if (*option == '+')
5922 break;
5923 i++;
cristybb503372010-05-27 20:51:26 +00005924 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005925 ThrowMogrifyException(OptionError,"MissingArgument",option);
5926 break;
5927 }
5928 if (LocaleCompare("treedepth",option+1) == 0)
5929 {
5930 if (*option == '+')
5931 break;
5932 i++;
cristybb503372010-05-27 20:51:26 +00005933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005934 ThrowMogrifyException(OptionError,"MissingArgument",option);
5935 if (IsGeometry(argv[i]) == MagickFalse)
5936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5937 break;
5938 }
5939 if (LocaleCompare("trim",option+1) == 0)
5940 break;
5941 if (LocaleCompare("type",option+1) == 0)
5942 {
cristybb503372010-05-27 20:51:26 +00005943 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005944 type;
5945
5946 if (*option == '+')
5947 break;
5948 i++;
cristybb503372010-05-27 20:51:26 +00005949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005950 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005951 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005952 if (type < 0)
5953 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5954 argv[i]);
5955 break;
5956 }
5957 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5958 }
5959 case 'u':
5960 {
5961 if (LocaleCompare("undercolor",option+1) == 0)
5962 {
5963 if (*option == '+')
5964 break;
5965 i++;
cristybb503372010-05-27 20:51:26 +00005966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005967 ThrowMogrifyException(OptionError,"MissingArgument",option);
5968 break;
5969 }
5970 if (LocaleCompare("unique-colors",option+1) == 0)
5971 break;
5972 if (LocaleCompare("units",option+1) == 0)
5973 {
cristybb503372010-05-27 20:51:26 +00005974 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005975 units;
5976
5977 if (*option == '+')
5978 break;
5979 i++;
cristybb503372010-05-27 20:51:26 +00005980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005981 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005982 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005983 argv[i]);
5984 if (units < 0)
5985 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5986 argv[i]);
5987 break;
5988 }
5989 if (LocaleCompare("unsharp",option+1) == 0)
5990 {
5991 i++;
cristybb503372010-05-27 20:51:26 +00005992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005993 ThrowMogrifyException(OptionError,"MissingArgument",option);
5994 if (IsGeometry(argv[i]) == MagickFalse)
5995 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5996 break;
5997 }
5998 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5999 }
6000 case 'v':
6001 {
6002 if (LocaleCompare("verbose",option+1) == 0)
6003 {
6004 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6005 break;
6006 }
6007 if ((LocaleCompare("version",option+1) == 0) ||
6008 (LocaleCompare("-version",option+1) == 0))
6009 {
cristyb51dff52011-05-19 16:55:47 +00006010 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006011 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00006012 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
6013 GetMagickCopyright());
6014 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
6015 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006016 break;
6017 }
6018 if (LocaleCompare("view",option+1) == 0)
6019 {
6020 if (*option == '+')
6021 break;
6022 i++;
cristybb503372010-05-27 20:51:26 +00006023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006024 ThrowMogrifyException(OptionError,"MissingArgument",option);
6025 break;
6026 }
6027 if (LocaleCompare("vignette",option+1) == 0)
6028 {
6029 if (*option == '+')
6030 break;
6031 i++;
cristybb503372010-05-27 20:51:26 +00006032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006033 ThrowMogrifyException(OptionError,"MissingArgument",option);
6034 if (IsGeometry(argv[i]) == MagickFalse)
6035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036 break;
6037 }
6038 if (LocaleCompare("virtual-pixel",option+1) == 0)
6039 {
cristybb503372010-05-27 20:51:26 +00006040 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006041 method;
6042
6043 if (*option == '+')
6044 break;
6045 i++;
cristybb503372010-05-27 20:51:26 +00006046 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006047 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006048 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006049 argv[i]);
6050 if (method < 0)
6051 ThrowMogrifyException(OptionError,
6052 "UnrecognizedVirtualPixelMethod",argv[i]);
6053 break;
6054 }
6055 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6056 }
6057 case 'w':
6058 {
6059 if (LocaleCompare("wave",option+1) == 0)
6060 {
6061 i++;
cristybb503372010-05-27 20:51:26 +00006062 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006063 ThrowMogrifyException(OptionError,"MissingArgument",option);
6064 if (IsGeometry(argv[i]) == MagickFalse)
6065 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6066 break;
6067 }
6068 if (LocaleCompare("weight",option+1) == 0)
6069 {
6070 if (*option == '+')
6071 break;
6072 i++;
cristybb503372010-05-27 20:51:26 +00006073 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006074 ThrowMogrifyException(OptionError,"MissingArgument",option);
6075 break;
6076 }
6077 if (LocaleCompare("white-point",option+1) == 0)
6078 {
6079 if (*option == '+')
6080 break;
6081 i++;
cristybb503372010-05-27 20:51:26 +00006082 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006083 ThrowMogrifyException(OptionError,"MissingArgument",option);
6084 if (IsGeometry(argv[i]) == MagickFalse)
6085 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6086 break;
6087 }
6088 if (LocaleCompare("white-threshold",option+1) == 0)
6089 {
6090 if (*option == '+')
6091 break;
6092 i++;
cristybb503372010-05-27 20:51:26 +00006093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006094 ThrowMogrifyException(OptionError,"MissingArgument",option);
6095 if (IsGeometry(argv[i]) == MagickFalse)
6096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6097 break;
6098 }
6099 if (LocaleCompare("write",option+1) == 0)
6100 {
6101 i++;
cristybb503372010-05-27 20:51:26 +00006102 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006103 ThrowMogrifyException(OptionError,"MissingArgument",option);
6104 break;
6105 }
6106 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6107 }
6108 case '?':
6109 break;
6110 default:
6111 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6112 }
cristy042ee782011-04-22 18:48:30 +00006113 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6114 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006115 if (fire != MagickFalse)
6116 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6117 }
6118 if (k != 0)
6119 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006120 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006121 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6122 DestroyMogrify();
6123 return(status != 0 ? MagickTrue : MagickFalse);
6124}
6125
6126/*
6127%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6128% %
6129% %
6130% %
6131+ M o g r i f y I m a g e I n f o %
6132% %
6133% %
6134% %
6135%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6136%
6137% MogrifyImageInfo() applies image processing settings to the image as
6138% prescribed by command line options.
6139%
6140% The format of the MogrifyImageInfo method is:
6141%
6142% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6143% const char **argv,ExceptionInfo *exception)
6144%
6145% A description of each parameter follows:
6146%
6147% o image_info: the image info..
6148%
6149% o argc: Specifies a pointer to an integer describing the number of
6150% elements in the argument vector.
6151%
6152% o argv: Specifies a pointer to a text array containing the command line
6153% arguments.
6154%
6155% o exception: return any errors or warnings in this structure.
6156%
6157*/
6158WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6159 const int argc,const char **argv,ExceptionInfo *exception)
6160{
6161 const char
6162 *option;
6163
6164 GeometryInfo
6165 geometry_info;
6166
cristybb503372010-05-27 20:51:26 +00006167 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006168 count;
6169
cristybb503372010-05-27 20:51:26 +00006170 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006171 i;
6172
6173 /*
6174 Initialize method variables.
6175 */
6176 assert(image_info != (ImageInfo *) NULL);
6177 assert(image_info->signature == MagickSignature);
6178 if (image_info->debug != MagickFalse)
6179 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6180 image_info->filename);
6181 if (argc < 0)
6182 return(MagickTrue);
6183 /*
6184 Set the image settings.
6185 */
cristybb503372010-05-27 20:51:26 +00006186 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006187 {
6188 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006189 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006190 continue;
cristy042ee782011-04-22 18:48:30 +00006191 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006192 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006193 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006194 break;
6195 switch (*(option+1))
6196 {
6197 case 'a':
6198 {
6199 if (LocaleCompare("adjoin",option+1) == 0)
6200 {
6201 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6202 break;
6203 }
6204 if (LocaleCompare("antialias",option+1) == 0)
6205 {
6206 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6207 break;
6208 }
cristy3ed852e2009-09-05 21:47:34 +00006209 if (LocaleCompare("authenticate",option+1) == 0)
6210 {
6211 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006212 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006213 else
anthony1afdc7a2011-10-05 11:54:28 +00006214 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006215 break;
6216 }
6217 break;
6218 }
6219 case 'b':
6220 {
6221 if (LocaleCompare("background",option+1) == 0)
6222 {
6223 if (*option == '+')
6224 {
6225 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006226 (void) QueryColorCompliance(MogrifyBackgroundColor,
6227 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006228 break;
6229 }
6230 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006231 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6232 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006233 break;
6234 }
6235 if (LocaleCompare("bias",option+1) == 0)
6236 {
6237 if (*option == '+')
6238 {
6239 (void) SetImageOption(image_info,option+1,"0.0");
6240 break;
6241 }
6242 (void) SetImageOption(image_info,option+1,argv[i+1]);
6243 break;
6244 }
6245 if (LocaleCompare("black-point-compensation",option+1) == 0)
6246 {
6247 if (*option == '+')
6248 {
6249 (void) SetImageOption(image_info,option+1,"false");
6250 break;
6251 }
6252 (void) SetImageOption(image_info,option+1,"true");
6253 break;
6254 }
6255 if (LocaleCompare("blue-primary",option+1) == 0)
6256 {
6257 if (*option == '+')
6258 {
6259 (void) SetImageOption(image_info,option+1,"0.0");
6260 break;
6261 }
6262 (void) SetImageOption(image_info,option+1,argv[i+1]);
6263 break;
6264 }
6265 if (LocaleCompare("bordercolor",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 {
6269 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006270 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006271 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006272 break;
6273 }
cristy9950d572011-10-01 18:22:35 +00006274 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6275 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006276 (void) SetImageOption(image_info,option+1,argv[i+1]);
6277 break;
6278 }
6279 if (LocaleCompare("box",option+1) == 0)
6280 {
6281 if (*option == '+')
6282 {
6283 (void) SetImageOption(image_info,"undercolor","none");
6284 break;
6285 }
6286 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6287 break;
6288 }
6289 break;
6290 }
6291 case 'c':
6292 {
6293 if (LocaleCompare("cache",option+1) == 0)
6294 {
6295 MagickSizeType
6296 limit;
6297
6298 limit=MagickResourceInfinity;
6299 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006300 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6301 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006302 (void) SetMagickResourceLimit(MemoryResource,limit);
6303 (void) SetMagickResourceLimit(MapResource,2*limit);
6304 break;
6305 }
6306 if (LocaleCompare("caption",option+1) == 0)
6307 {
6308 if (*option == '+')
6309 {
6310 (void) DeleteImageOption(image_info,option+1);
6311 break;
6312 }
6313 (void) SetImageOption(image_info,option+1,argv[i+1]);
6314 break;
6315 }
6316 if (LocaleCompare("channel",option+1) == 0)
6317 {
6318 if (*option == '+')
6319 {
6320 image_info->channel=DefaultChannels;
6321 break;
6322 }
6323 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6324 break;
6325 }
cristy3ed852e2009-09-05 21:47:34 +00006326 if (LocaleCompare("colorspace",option+1) == 0)
6327 {
6328 if (*option == '+')
6329 {
6330 image_info->colorspace=UndefinedColorspace;
6331 (void) SetImageOption(image_info,option+1,"undefined");
6332 break;
6333 }
cristy042ee782011-04-22 18:48:30 +00006334 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006335 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6336 (void) SetImageOption(image_info,option+1,argv[i+1]);
6337 break;
6338 }
cristy3ed852e2009-09-05 21:47:34 +00006339 if (LocaleCompare("comment",option+1) == 0)
6340 {
6341 if (*option == '+')
6342 {
6343 (void) DeleteImageOption(image_info,option+1);
6344 break;
6345 }
6346 (void) SetImageOption(image_info,option+1,argv[i+1]);
6347 break;
6348 }
6349 if (LocaleCompare("compose",option+1) == 0)
6350 {
6351 if (*option == '+')
6352 {
6353 (void) SetImageOption(image_info,option+1,"undefined");
6354 break;
6355 }
6356 (void) SetImageOption(image_info,option+1,argv[i+1]);
6357 break;
6358 }
6359 if (LocaleCompare("compress",option+1) == 0)
6360 {
6361 if (*option == '+')
6362 {
6363 image_info->compression=UndefinedCompression;
6364 (void) SetImageOption(image_info,option+1,"undefined");
6365 break;
6366 }
cristy042ee782011-04-22 18:48:30 +00006367 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006368 MagickCompressOptions,MagickFalse,argv[i+1]);
6369 (void) SetImageOption(image_info,option+1,argv[i+1]);
6370 break;
6371 }
6372 break;
6373 }
6374 case 'd':
6375 {
6376 if (LocaleCompare("debug",option+1) == 0)
6377 {
6378 if (*option == '+')
6379 (void) SetLogEventMask("none");
6380 else
6381 (void) SetLogEventMask(argv[i+1]);
6382 image_info->debug=IsEventLogging();
6383 break;
6384 }
6385 if (LocaleCompare("define",option+1) == 0)
6386 {
6387 if (*option == '+')
6388 {
6389 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6390 (void) DeleteImageRegistry(argv[i+1]+9);
6391 else
6392 (void) DeleteImageOption(image_info,argv[i+1]);
6393 break;
6394 }
6395 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6396 {
6397 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6398 exception);
6399 break;
6400 }
6401 (void) DefineImageOption(image_info,argv[i+1]);
6402 break;
6403 }
6404 if (LocaleCompare("delay",option+1) == 0)
6405 {
6406 if (*option == '+')
6407 {
6408 (void) SetImageOption(image_info,option+1,"0");
6409 break;
6410 }
6411 (void) SetImageOption(image_info,option+1,argv[i+1]);
6412 break;
6413 }
6414 if (LocaleCompare("density",option+1) == 0)
6415 {
6416 /*
6417 Set image density.
6418 */
6419 if (*option == '+')
6420 {
6421 if (image_info->density != (char *) NULL)
6422 image_info->density=DestroyString(image_info->density);
6423 (void) SetImageOption(image_info,option+1,"72");
6424 break;
6425 }
6426 (void) CloneString(&image_info->density,argv[i+1]);
6427 (void) SetImageOption(image_info,option+1,argv[i+1]);
6428 break;
6429 }
6430 if (LocaleCompare("depth",option+1) == 0)
6431 {
6432 if (*option == '+')
6433 {
6434 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6435 break;
6436 }
cristye27293e2009-12-18 02:53:20 +00006437 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006438 break;
6439 }
cristyc9b12952010-03-28 01:12:28 +00006440 if (LocaleCompare("direction",option+1) == 0)
6441 {
6442 if (*option == '+')
6443 {
6444 (void) SetImageOption(image_info,option+1,"undefined");
6445 break;
6446 }
6447 (void) SetImageOption(image_info,option+1,argv[i+1]);
6448 break;
6449 }
cristy3ed852e2009-09-05 21:47:34 +00006450 if (LocaleCompare("display",option+1) == 0)
6451 {
6452 if (*option == '+')
6453 {
6454 if (image_info->server_name != (char *) NULL)
6455 image_info->server_name=DestroyString(
6456 image_info->server_name);
6457 break;
6458 }
6459 (void) CloneString(&image_info->server_name,argv[i+1]);
6460 break;
6461 }
6462 if (LocaleCompare("dispose",option+1) == 0)
6463 {
6464 if (*option == '+')
6465 {
6466 (void) SetImageOption(image_info,option+1,"undefined");
6467 break;
6468 }
6469 (void) SetImageOption(image_info,option+1,argv[i+1]);
6470 break;
6471 }
6472 if (LocaleCompare("dither",option+1) == 0)
6473 {
6474 if (*option == '+')
6475 {
6476 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006477 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006478 break;
6479 }
6480 (void) SetImageOption(image_info,option+1,argv[i+1]);
6481 image_info->dither=MagickTrue;
6482 break;
6483 }
6484 break;
6485 }
6486 case 'e':
6487 {
6488 if (LocaleCompare("encoding",option+1) == 0)
6489 {
6490 if (*option == '+')
6491 {
6492 (void) SetImageOption(image_info,option+1,"undefined");
6493 break;
6494 }
6495 (void) SetImageOption(image_info,option+1,argv[i+1]);
6496 break;
6497 }
6498 if (LocaleCompare("endian",option+1) == 0)
6499 {
6500 if (*option == '+')
6501 {
6502 image_info->endian=UndefinedEndian;
6503 (void) SetImageOption(image_info,option+1,"undefined");
6504 break;
6505 }
cristy042ee782011-04-22 18:48:30 +00006506 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006507 MagickEndianOptions,MagickFalse,argv[i+1]);
6508 (void) SetImageOption(image_info,option+1,argv[i+1]);
6509 break;
6510 }
6511 if (LocaleCompare("extract",option+1) == 0)
6512 {
6513 /*
6514 Set image extract geometry.
6515 */
6516 if (*option == '+')
6517 {
6518 if (image_info->extract != (char *) NULL)
6519 image_info->extract=DestroyString(image_info->extract);
6520 break;
6521 }
6522 (void) CloneString(&image_info->extract,argv[i+1]);
6523 break;
6524 }
6525 break;
6526 }
6527 case 'f':
6528 {
6529 if (LocaleCompare("fill",option+1) == 0)
6530 {
6531 if (*option == '+')
6532 {
6533 (void) SetImageOption(image_info,option+1,"none");
6534 break;
6535 }
6536 (void) SetImageOption(image_info,option+1,argv[i+1]);
6537 break;
6538 }
6539 if (LocaleCompare("filter",option+1) == 0)
6540 {
6541 if (*option == '+')
6542 {
6543 (void) SetImageOption(image_info,option+1,"undefined");
6544 break;
6545 }
6546 (void) SetImageOption(image_info,option+1,argv[i+1]);
6547 break;
6548 }
6549 if (LocaleCompare("font",option+1) == 0)
6550 {
6551 if (*option == '+')
6552 {
6553 if (image_info->font != (char *) NULL)
6554 image_info->font=DestroyString(image_info->font);
6555 break;
6556 }
6557 (void) CloneString(&image_info->font,argv[i+1]);
6558 break;
6559 }
6560 if (LocaleCompare("format",option+1) == 0)
6561 {
6562 register const char
6563 *q;
6564
6565 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006566 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006567 image_info->ping=MagickFalse;
6568 (void) SetImageOption(image_info,option+1,argv[i+1]);
6569 break;
6570 }
6571 if (LocaleCompare("fuzz",option+1) == 0)
6572 {
6573 if (*option == '+')
6574 {
6575 image_info->fuzz=0.0;
6576 (void) SetImageOption(image_info,option+1,"0");
6577 break;
6578 }
cristydbdd0e32011-11-04 23:29:40 +00006579 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6580 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
6584 break;
6585 }
6586 case 'g':
6587 {
6588 if (LocaleCompare("gravity",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 (void) SetImageOption(image_info,option+1,"undefined");
6593 break;
6594 }
6595 (void) SetImageOption(image_info,option+1,argv[i+1]);
6596 break;
6597 }
6598 if (LocaleCompare("green-primary",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 (void) SetImageOption(image_info,option+1,"0.0");
6603 break;
6604 }
6605 (void) SetImageOption(image_info,option+1,argv[i+1]);
6606 break;
6607 }
6608 break;
6609 }
6610 case 'i':
6611 {
6612 if (LocaleCompare("intent",option+1) == 0)
6613 {
6614 if (*option == '+')
6615 {
6616 (void) SetImageOption(image_info,option+1,"undefined");
6617 break;
6618 }
6619 (void) SetImageOption(image_info,option+1,argv[i+1]);
6620 break;
6621 }
6622 if (LocaleCompare("interlace",option+1) == 0)
6623 {
6624 if (*option == '+')
6625 {
6626 image_info->interlace=UndefinedInterlace;
6627 (void) SetImageOption(image_info,option+1,"undefined");
6628 break;
6629 }
cristy042ee782011-04-22 18:48:30 +00006630 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006631 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6632 (void) SetImageOption(image_info,option+1,argv[i+1]);
6633 break;
6634 }
cristyb32b90a2009-09-07 21:45:48 +00006635 if (LocaleCompare("interline-spacing",option+1) == 0)
6636 {
6637 if (*option == '+')
6638 {
6639 (void) SetImageOption(image_info,option+1,"undefined");
6640 break;
6641 }
6642 (void) SetImageOption(image_info,option+1,argv[i+1]);
6643 break;
6644 }
cristy3ed852e2009-09-05 21:47:34 +00006645 if (LocaleCompare("interpolate",option+1) == 0)
6646 {
6647 if (*option == '+')
6648 {
6649 (void) SetImageOption(image_info,option+1,"undefined");
6650 break;
6651 }
6652 (void) SetImageOption(image_info,option+1,argv[i+1]);
6653 break;
6654 }
6655 if (LocaleCompare("interword-spacing",option+1) == 0)
6656 {
6657 if (*option == '+')
6658 {
6659 (void) SetImageOption(image_info,option+1,"undefined");
6660 break;
6661 }
6662 (void) SetImageOption(image_info,option+1,argv[i+1]);
6663 break;
6664 }
6665 break;
6666 }
6667 case 'k':
6668 {
6669 if (LocaleCompare("kerning",option+1) == 0)
6670 {
6671 if (*option == '+')
6672 {
6673 (void) SetImageOption(image_info,option+1,"undefined");
6674 break;
6675 }
6676 (void) SetImageOption(image_info,option+1,argv[i+1]);
6677 break;
6678 }
6679 break;
6680 }
6681 case 'l':
6682 {
6683 if (LocaleCompare("label",option+1) == 0)
6684 {
6685 if (*option == '+')
6686 {
6687 (void) DeleteImageOption(image_info,option+1);
6688 break;
6689 }
6690 (void) SetImageOption(image_info,option+1,argv[i+1]);
6691 break;
6692 }
6693 if (LocaleCompare("limit",option+1) == 0)
6694 {
6695 MagickSizeType
6696 limit;
6697
6698 ResourceType
6699 type;
6700
6701 if (*option == '+')
6702 break;
cristy042ee782011-04-22 18:48:30 +00006703 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006704 MagickFalse,argv[i+1]);
6705 limit=MagickResourceInfinity;
6706 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006707 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006708 (void) SetMagickResourceLimit(type,limit);
6709 break;
6710 }
6711 if (LocaleCompare("list",option+1) == 0)
6712 {
cristybb503372010-05-27 20:51:26 +00006713 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006714 list;
6715
6716 /*
6717 Display configuration list.
6718 */
cristy042ee782011-04-22 18:48:30 +00006719 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006720 switch (list)
6721 {
6722 case MagickCoderOptions:
6723 {
6724 (void) ListCoderInfo((FILE *) NULL,exception);
6725 break;
6726 }
6727 case MagickColorOptions:
6728 {
6729 (void) ListColorInfo((FILE *) NULL,exception);
6730 break;
6731 }
6732 case MagickConfigureOptions:
6733 {
6734 (void) ListConfigureInfo((FILE *) NULL,exception);
6735 break;
6736 }
6737 case MagickDelegateOptions:
6738 {
6739 (void) ListDelegateInfo((FILE *) NULL,exception);
6740 break;
6741 }
6742 case MagickFontOptions:
6743 {
6744 (void) ListTypeInfo((FILE *) NULL,exception);
6745 break;
6746 }
6747 case MagickFormatOptions:
6748 {
6749 (void) ListMagickInfo((FILE *) NULL,exception);
6750 break;
6751 }
6752 case MagickLocaleOptions:
6753 {
6754 (void) ListLocaleInfo((FILE *) NULL,exception);
6755 break;
6756 }
6757 case MagickLogOptions:
6758 {
6759 (void) ListLogInfo((FILE *) NULL,exception);
6760 break;
6761 }
6762 case MagickMagicOptions:
6763 {
6764 (void) ListMagicInfo((FILE *) NULL,exception);
6765 break;
6766 }
6767 case MagickMimeOptions:
6768 {
6769 (void) ListMimeInfo((FILE *) NULL,exception);
6770 break;
6771 }
6772 case MagickModuleOptions:
6773 {
6774 (void) ListModuleInfo((FILE *) NULL,exception);
6775 break;
6776 }
6777 case MagickPolicyOptions:
6778 {
6779 (void) ListPolicyInfo((FILE *) NULL,exception);
6780 break;
6781 }
6782 case MagickResourceOptions:
6783 {
6784 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6785 break;
6786 }
6787 case MagickThresholdOptions:
6788 {
6789 (void) ListThresholdMaps((FILE *) NULL,exception);
6790 break;
6791 }
6792 default:
6793 {
cristy042ee782011-04-22 18:48:30 +00006794 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006795 exception);
6796 break;
6797 }
6798 }
cristyaeb2cbc2010-05-07 13:28:58 +00006799 break;
cristy3ed852e2009-09-05 21:47:34 +00006800 }
6801 if (LocaleCompare("log",option+1) == 0)
6802 {
6803 if (*option == '+')
6804 break;
6805 (void) SetLogFormat(argv[i+1]);
6806 break;
6807 }
6808 if (LocaleCompare("loop",option+1) == 0)
6809 {
6810 if (*option == '+')
6811 {
6812 (void) SetImageOption(image_info,option+1,"0");
6813 break;
6814 }
6815 (void) SetImageOption(image_info,option+1,argv[i+1]);
6816 break;
6817 }
6818 break;
6819 }
6820 case 'm':
6821 {
6822 if (LocaleCompare("matte",option+1) == 0)
6823 {
6824 if (*option == '+')
6825 {
6826 (void) SetImageOption(image_info,option+1,"false");
6827 break;
6828 }
6829 (void) SetImageOption(image_info,option+1,"true");
6830 break;
6831 }
6832 if (LocaleCompare("mattecolor",option+1) == 0)
6833 {
6834 if (*option == '+')
6835 {
6836 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006837 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006838 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006839 break;
6840 }
6841 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006842 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6843 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006844 break;
6845 }
6846 if (LocaleCompare("monitor",option+1) == 0)
6847 {
6848 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6849 (void *) NULL);
6850 break;
6851 }
6852 if (LocaleCompare("monochrome",option+1) == 0)
6853 {
6854 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6855 break;
6856 }
6857 break;
6858 }
6859 case 'o':
6860 {
6861 if (LocaleCompare("orient",option+1) == 0)
6862 {
6863 if (*option == '+')
6864 {
6865 image_info->orientation=UndefinedOrientation;
6866 (void) SetImageOption(image_info,option+1,"undefined");
6867 break;
6868 }
cristy042ee782011-04-22 18:48:30 +00006869 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006870 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006871 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006872 break;
6873 }
6874 }
6875 case 'p':
6876 {
6877 if (LocaleCompare("page",option+1) == 0)
6878 {
6879 char
6880 *canonical_page,
6881 page[MaxTextExtent];
6882
6883 const char
6884 *image_option;
6885
6886 MagickStatusType
6887 flags;
6888
6889 RectangleInfo
6890 geometry;
6891
6892 if (*option == '+')
6893 {
6894 (void) DeleteImageOption(image_info,option+1);
6895 (void) CloneString(&image_info->page,(char *) NULL);
6896 break;
6897 }
6898 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6899 image_option=GetImageOption(image_info,"page");
6900 if (image_option != (const char *) NULL)
6901 flags=ParseAbsoluteGeometry(image_option,&geometry);
6902 canonical_page=GetPageGeometry(argv[i+1]);
6903 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6904 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006905 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006906 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006907 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006908 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006909 (unsigned long) geometry.width,(unsigned long) geometry.height,
6910 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006911 (void) SetImageOption(image_info,option+1,page);
6912 (void) CloneString(&image_info->page,page);
6913 break;
6914 }
6915 if (LocaleCompare("pen",option+1) == 0)
6916 {
6917 if (*option == '+')
6918 {
6919 (void) SetImageOption(image_info,option+1,"none");
6920 break;
6921 }
6922 (void) SetImageOption(image_info,option+1,argv[i+1]);
6923 break;
6924 }
6925 if (LocaleCompare("ping",option+1) == 0)
6926 {
6927 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6928 break;
6929 }
6930 if (LocaleCompare("pointsize",option+1) == 0)
6931 {
6932 if (*option == '+')
6933 geometry_info.rho=0.0;
6934 else
6935 (void) ParseGeometry(argv[i+1],&geometry_info);
6936 image_info->pointsize=geometry_info.rho;
6937 break;
6938 }
cristye7f51092010-01-17 00:39:37 +00006939 if (LocaleCompare("precision",option+1) == 0)
6940 {
cristybf2766a2010-01-17 03:33:23 +00006941 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006942 break;
6943 }
cristy3ed852e2009-09-05 21:47:34 +00006944 if (LocaleCompare("preview",option+1) == 0)
6945 {
6946 /*
6947 Preview image.
6948 */
6949 if (*option == '+')
6950 {
6951 image_info->preview_type=UndefinedPreview;
6952 break;
6953 }
cristy042ee782011-04-22 18:48:30 +00006954 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006955 MagickPreviewOptions,MagickFalse,argv[i+1]);
6956 break;
6957 }
6958 break;
6959 }
6960 case 'q':
6961 {
6962 if (LocaleCompare("quality",option+1) == 0)
6963 {
6964 /*
6965 Set image compression quality.
6966 */
6967 if (*option == '+')
6968 {
6969 image_info->quality=UndefinedCompressionQuality;
6970 (void) SetImageOption(image_info,option+1,"0");
6971 break;
6972 }
cristye27293e2009-12-18 02:53:20 +00006973 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006974 (void) SetImageOption(image_info,option+1,argv[i+1]);
6975 break;
6976 }
6977 if (LocaleCompare("quiet",option+1) == 0)
6978 {
6979 static WarningHandler
6980 warning_handler = (WarningHandler) NULL;
6981
6982 if (*option == '+')
6983 {
6984 /*
6985 Restore error or warning messages.
6986 */
6987 warning_handler=SetWarningHandler(warning_handler);
6988 break;
6989 }
6990 /*
6991 Suppress error or warning messages.
6992 */
6993 warning_handler=SetWarningHandler((WarningHandler) NULL);
6994 break;
6995 }
6996 break;
6997 }
6998 case 'r':
6999 {
7000 if (LocaleCompare("red-primary",option+1) == 0)
7001 {
7002 if (*option == '+')
7003 {
7004 (void) SetImageOption(image_info,option+1,"0.0");
7005 break;
7006 }
7007 (void) SetImageOption(image_info,option+1,argv[i+1]);
7008 break;
7009 }
7010 break;
7011 }
7012 case 's':
7013 {
7014 if (LocaleCompare("sampling-factor",option+1) == 0)
7015 {
7016 /*
7017 Set image sampling factor.
7018 */
7019 if (*option == '+')
7020 {
7021 if (image_info->sampling_factor != (char *) NULL)
7022 image_info->sampling_factor=DestroyString(
7023 image_info->sampling_factor);
7024 break;
7025 }
7026 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7027 break;
7028 }
7029 if (LocaleCompare("scene",option+1) == 0)
7030 {
7031 /*
7032 Set image scene.
7033 */
7034 if (*option == '+')
7035 {
7036 image_info->scene=0;
7037 (void) SetImageOption(image_info,option+1,"0");
7038 break;
7039 }
cristye27293e2009-12-18 02:53:20 +00007040 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007041 (void) SetImageOption(image_info,option+1,argv[i+1]);
7042 break;
7043 }
7044 if (LocaleCompare("seed",option+1) == 0)
7045 {
cristybb503372010-05-27 20:51:26 +00007046 size_t
cristy3ed852e2009-09-05 21:47:34 +00007047 seed;
7048
7049 if (*option == '+')
7050 {
cristybb503372010-05-27 20:51:26 +00007051 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007052 SeedPseudoRandomGenerator(seed);
7053 break;
7054 }
cristye27293e2009-12-18 02:53:20 +00007055 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007056 SeedPseudoRandomGenerator(seed);
7057 break;
7058 }
7059 if (LocaleCompare("size",option+1) == 0)
7060 {
7061 if (*option == '+')
7062 {
7063 if (image_info->size != (char *) NULL)
7064 image_info->size=DestroyString(image_info->size);
7065 break;
7066 }
7067 (void) CloneString(&image_info->size,argv[i+1]);
7068 break;
7069 }
7070 if (LocaleCompare("stroke",option+1) == 0)
7071 {
7072 if (*option == '+')
7073 {
7074 (void) SetImageOption(image_info,option+1,"none");
7075 break;
7076 }
7077 (void) SetImageOption(image_info,option+1,argv[i+1]);
7078 break;
7079 }
7080 if (LocaleCompare("strokewidth",option+1) == 0)
7081 {
7082 if (*option == '+')
7083 {
7084 (void) SetImageOption(image_info,option+1,"0");
7085 break;
7086 }
7087 (void) SetImageOption(image_info,option+1,argv[i+1]);
7088 break;
7089 }
cristyd9a29192010-10-16 16:49:53 +00007090 if (LocaleCompare("synchronize",option+1) == 0)
7091 {
7092 if (*option == '+')
7093 {
7094 image_info->synchronize=MagickFalse;
7095 break;
7096 }
7097 image_info->synchronize=MagickTrue;
7098 break;
7099 }
cristy3ed852e2009-09-05 21:47:34 +00007100 break;
7101 }
7102 case 't':
7103 {
7104 if (LocaleCompare("taint",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
7108 (void) SetImageOption(image_info,option+1,"false");
7109 break;
7110 }
7111 (void) SetImageOption(image_info,option+1,"true");
7112 break;
7113 }
7114 if (LocaleCompare("texture",option+1) == 0)
7115 {
7116 if (*option == '+')
7117 {
7118 if (image_info->texture != (char *) NULL)
7119 image_info->texture=DestroyString(image_info->texture);
7120 break;
7121 }
7122 (void) CloneString(&image_info->texture,argv[i+1]);
7123 break;
7124 }
7125 if (LocaleCompare("tile-offset",option+1) == 0)
7126 {
7127 if (*option == '+')
7128 {
7129 (void) SetImageOption(image_info,option+1,"0");
7130 break;
7131 }
7132 (void) SetImageOption(image_info,option+1,argv[i+1]);
7133 break;
7134 }
7135 if (LocaleCompare("transparent-color",option+1) == 0)
7136 {
7137 if (*option == '+')
7138 {
cristy9950d572011-10-01 18:22:35 +00007139 (void) QueryColorCompliance("none",AllCompliance,
7140 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007141 (void) SetImageOption(image_info,option+1,"none");
7142 break;
7143 }
cristy9950d572011-10-01 18:22:35 +00007144 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7145 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007146 (void) SetImageOption(image_info,option+1,argv[i+1]);
7147 break;
7148 }
7149 if (LocaleCompare("type",option+1) == 0)
7150 {
7151 if (*option == '+')
7152 {
cristy5f1c1ff2010-12-23 21:38:06 +00007153 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007154 (void) SetImageOption(image_info,option+1,"undefined");
7155 break;
7156 }
cristy042ee782011-04-22 18:48:30 +00007157 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007158 MagickFalse,argv[i+1]);
7159 (void) SetImageOption(image_info,option+1,argv[i+1]);
7160 break;
7161 }
7162 break;
7163 }
7164 case 'u':
7165 {
7166 if (LocaleCompare("undercolor",option+1) == 0)
7167 {
7168 if (*option == '+')
7169 {
7170 (void) DeleteImageOption(image_info,option+1);
7171 break;
7172 }
7173 (void) SetImageOption(image_info,option+1,argv[i+1]);
7174 break;
7175 }
7176 if (LocaleCompare("units",option+1) == 0)
7177 {
7178 if (*option == '+')
7179 {
7180 image_info->units=UndefinedResolution;
7181 (void) SetImageOption(image_info,option+1,"undefined");
7182 break;
7183 }
cristy042ee782011-04-22 18:48:30 +00007184 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007185 MagickResolutionOptions,MagickFalse,argv[i+1]);
7186 (void) SetImageOption(image_info,option+1,argv[i+1]);
7187 break;
7188 }
7189 break;
7190 }
7191 case 'v':
7192 {
7193 if (LocaleCompare("verbose",option+1) == 0)
7194 {
7195 if (*option == '+')
7196 {
7197 image_info->verbose=MagickFalse;
7198 break;
7199 }
7200 image_info->verbose=MagickTrue;
7201 image_info->ping=MagickFalse;
7202 break;
7203 }
7204 if (LocaleCompare("view",option+1) == 0)
7205 {
7206 if (*option == '+')
7207 {
7208 if (image_info->view != (char *) NULL)
7209 image_info->view=DestroyString(image_info->view);
7210 break;
7211 }
7212 (void) CloneString(&image_info->view,argv[i+1]);
7213 break;
7214 }
7215 if (LocaleCompare("virtual-pixel",option+1) == 0)
7216 {
7217 if (*option == '+')
7218 {
7219 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7220 (void) SetImageOption(image_info,option+1,"undefined");
7221 break;
7222 }
7223 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007224 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007225 argv[i+1]);
7226 (void) SetImageOption(image_info,option+1,argv[i+1]);
7227 break;
7228 }
7229 break;
7230 }
7231 case 'w':
7232 {
7233 if (LocaleCompare("white-point",option+1) == 0)
7234 {
7235 if (*option == '+')
7236 {
7237 (void) SetImageOption(image_info,option+1,"0.0");
7238 break;
7239 }
7240 (void) SetImageOption(image_info,option+1,argv[i+1]);
7241 break;
7242 }
7243 break;
7244 }
7245 default:
7246 break;
7247 }
7248 i+=count;
7249 }
7250 return(MagickTrue);
7251}
7252
7253/*
7254%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7255% %
7256% %
7257% %
7258+ M o g r i f y I m a g e L i s t %
7259% %
7260% %
7261% %
7262%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7263%
7264% MogrifyImageList() applies any command line options that might affect the
7265% entire image list (e.g. -append, -coalesce, etc.).
7266%
7267% The format of the MogrifyImage method is:
7268%
7269% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7270% const char **argv,Image **images,ExceptionInfo *exception)
7271%
7272% A description of each parameter follows:
7273%
7274% o image_info: the image info..
7275%
7276% o argc: Specifies a pointer to an integer describing the number of
7277% elements in the argument vector.
7278%
7279% o argv: Specifies a pointer to a text array containing the command line
7280% arguments.
7281%
anthonye9c27192011-03-27 08:07:06 +00007282% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007283%
7284% o exception: return any errors or warnings in this structure.
7285%
7286*/
7287WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7288 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7289{
cristy3ed852e2009-09-05 21:47:34 +00007290 const char
7291 *option;
7292
cristy6b3da3a2010-06-20 02:21:46 +00007293 ImageInfo
7294 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007295
7296 MagickStatusType
7297 status;
7298
cristy28474bf2011-09-11 23:32:52 +00007299 PixelInterpolateMethod
7300 interpolate_method;
7301
cristy3ed852e2009-09-05 21:47:34 +00007302 QuantizeInfo
7303 *quantize_info;
7304
cristybb503372010-05-27 20:51:26 +00007305 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007306 i;
7307
cristy6b3da3a2010-06-20 02:21:46 +00007308 ssize_t
7309 count,
7310 index;
7311
cristy3ed852e2009-09-05 21:47:34 +00007312 /*
7313 Apply options to the image list.
7314 */
7315 assert(image_info != (ImageInfo *) NULL);
7316 assert(image_info->signature == MagickSignature);
7317 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007318 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007319 assert((*images)->signature == MagickSignature);
7320 if ((*images)->debug != MagickFalse)
7321 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7322 (*images)->filename);
7323 if ((argc <= 0) || (*argv == (char *) NULL))
7324 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007325 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007326 mogrify_info=CloneImageInfo(image_info);
7327 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007328 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007329 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007330 {
cristy74fe8f12009-10-03 19:09:01 +00007331 if (*images == (Image *) NULL)
7332 break;
cristy3ed852e2009-09-05 21:47:34 +00007333 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007334 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007335 continue;
cristy042ee782011-04-22 18:48:30 +00007336 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007337 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007338 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007339 break;
cristy6b3da3a2010-06-20 02:21:46 +00007340 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007341 switch (*(option+1))
7342 {
7343 case 'a':
7344 {
7345 if (LocaleCompare("affinity",option+1) == 0)
7346 {
cristy6fccee12011-10-20 18:43:18 +00007347 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007348 if (*option == '+')
7349 {
cristy018f07f2011-09-04 21:15:19 +00007350 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7351 exception);
cristy3ed852e2009-09-05 21:47:34 +00007352 break;
7353 }
7354 i++;
7355 break;
7356 }
7357 if (LocaleCompare("append",option+1) == 0)
7358 {
7359 Image
7360 *append_image;
7361
cristy6fccee12011-10-20 18:43:18 +00007362 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007363 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7364 MagickFalse,exception);
7365 if (append_image == (Image *) NULL)
7366 {
7367 status=MagickFalse;
7368 break;
7369 }
7370 *images=DestroyImageList(*images);
7371 *images=append_image;
7372 break;
7373 }
7374 if (LocaleCompare("average",option+1) == 0)
7375 {
7376 Image
7377 *average_image;
7378
cristyd18ae7c2010-03-07 17:39:52 +00007379 /*
7380 Average an image sequence (deprecated).
7381 */
cristy6fccee12011-10-20 18:43:18 +00007382 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007383 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7384 exception);
cristy3ed852e2009-09-05 21:47:34 +00007385 if (average_image == (Image *) NULL)
7386 {
7387 status=MagickFalse;
7388 break;
7389 }
7390 *images=DestroyImageList(*images);
7391 *images=average_image;
7392 break;
7393 }
7394 break;
7395 }
7396 case 'c':
7397 {
7398 if (LocaleCompare("channel",option+1) == 0)
7399 {
cristyf4ad9df2011-07-08 16:49:03 +00007400 ChannelType
7401 channel;
7402
cristy3ed852e2009-09-05 21:47:34 +00007403 if (*option == '+')
7404 {
7405 channel=DefaultChannels;
7406 break;
7407 }
7408 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00007409 SetPixelChannelMapMask(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007410 break;
7411 }
7412 if (LocaleCompare("clut",option+1) == 0)
7413 {
7414 Image
7415 *clut_image,
7416 *image;
7417
cristy6fccee12011-10-20 18:43:18 +00007418 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007419 image=RemoveFirstImageFromList(images);
7420 clut_image=RemoveFirstImageFromList(images);
7421 if (clut_image == (Image *) NULL)
7422 {
7423 status=MagickFalse;
7424 break;
7425 }
cristy28474bf2011-09-11 23:32:52 +00007426 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007427 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007428 *images=DestroyImageList(*images);
7429 *images=image;
7430 break;
7431 }
7432 if (LocaleCompare("coalesce",option+1) == 0)
7433 {
7434 Image
7435 *coalesce_image;
7436
cristy6fccee12011-10-20 18:43:18 +00007437 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007438 coalesce_image=CoalesceImages(*images,exception);
7439 if (coalesce_image == (Image *) NULL)
7440 {
7441 status=MagickFalse;
7442 break;
7443 }
7444 *images=DestroyImageList(*images);
7445 *images=coalesce_image;
7446 break;
7447 }
7448 if (LocaleCompare("combine",option+1) == 0)
7449 {
7450 Image
7451 *combine_image;
7452
cristy6fccee12011-10-20 18:43:18 +00007453 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007454 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007455 if (combine_image == (Image *) NULL)
7456 {
7457 status=MagickFalse;
7458 break;
7459 }
7460 *images=DestroyImageList(*images);
7461 *images=combine_image;
7462 break;
7463 }
7464 if (LocaleCompare("composite",option+1) == 0)
7465 {
7466 Image
7467 *mask_image,
7468 *composite_image,
7469 *image;
7470
7471 RectangleInfo
7472 geometry;
7473
cristy6fccee12011-10-20 18:43:18 +00007474 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007475 image=RemoveFirstImageFromList(images);
7476 composite_image=RemoveFirstImageFromList(images);
7477 if (composite_image == (Image *) NULL)
7478 {
7479 status=MagickFalse;
7480 break;
7481 }
7482 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007483 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007484 SetGeometry(composite_image,&geometry);
7485 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7486 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7487 &geometry);
7488 mask_image=RemoveFirstImageFromList(images);
7489 if (mask_image != (Image *) NULL)
7490 {
7491 if ((image->compose == DisplaceCompositeOp) ||
7492 (image->compose == DistortCompositeOp))
7493 {
7494 /*
7495 Merge Y displacement into X displacement image.
7496 */
7497 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007498 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007499 mask_image=DestroyImage(mask_image);
7500 }
7501 else
7502 {
7503 /*
7504 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007505 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007506 */
7507 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007508 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007509 }
7510 }
cristyf4ad9df2011-07-08 16:49:03 +00007511 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007512 geometry.x,geometry.y,exception);
anthonya129f702011-04-14 01:08:48 +00007513 if (mask_image != (Image *) NULL)
7514 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007515 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007516 *images=DestroyImageList(*images);
7517 *images=image;
7518 break;
7519 }
cristy3ed852e2009-09-05 21:47:34 +00007520 break;
7521 }
7522 case 'd':
7523 {
7524 if (LocaleCompare("deconstruct",option+1) == 0)
7525 {
7526 Image
7527 *deconstruct_image;
7528
cristy6fccee12011-10-20 18:43:18 +00007529 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007530 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007531 exception);
cristy3ed852e2009-09-05 21:47:34 +00007532 if (deconstruct_image == (Image *) NULL)
7533 {
7534 status=MagickFalse;
7535 break;
7536 }
7537 *images=DestroyImageList(*images);
7538 *images=deconstruct_image;
7539 break;
7540 }
7541 if (LocaleCompare("delete",option+1) == 0)
7542 {
7543 if (*option == '+')
7544 DeleteImages(images,"-1",exception);
7545 else
7546 DeleteImages(images,argv[i+1],exception);
7547 break;
7548 }
7549 if (LocaleCompare("dither",option+1) == 0)
7550 {
7551 if (*option == '+')
7552 {
7553 quantize_info->dither=MagickFalse;
7554 break;
7555 }
7556 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007557 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007558 MagickDitherOptions,MagickFalse,argv[i+1]);
7559 break;
7560 }
cristyecb10ff2011-03-22 13:14:03 +00007561 if (LocaleCompare("duplicate",option+1) == 0)
7562 {
cristy72988482011-03-29 16:34:38 +00007563 Image
7564 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007565
anthony2b6bcae2011-03-23 13:05:34 +00007566 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007567 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7568 else
7569 {
7570 const char
7571 *p;
7572
anthony2b6bcae2011-03-23 13:05:34 +00007573 size_t
7574 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007575
anthony2b6bcae2011-03-23 13:05:34 +00007576 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007577 p=strchr(argv[i+1],',');
7578 if (p == (const char *) NULL)
7579 duplicate_images=DuplicateImages(*images,number_duplicates,
7580 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007581 else
cristy72988482011-03-29 16:34:38 +00007582 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7583 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007584 }
7585 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007586 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007587 break;
7588 }
cristy3ed852e2009-09-05 21:47:34 +00007589 break;
7590 }
cristyd18ae7c2010-03-07 17:39:52 +00007591 case 'e':
7592 {
7593 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7594 {
7595 Image
7596 *evaluate_image;
7597
7598 MagickEvaluateOperator
7599 op;
7600
cristy6fccee12011-10-20 18:43:18 +00007601 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007602 op=(MagickEvaluateOperator) ParseCommandOption(
7603 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007604 evaluate_image=EvaluateImages(*images,op,exception);
7605 if (evaluate_image == (Image *) NULL)
7606 {
7607 status=MagickFalse;
7608 break;
7609 }
7610 *images=DestroyImageList(*images);
7611 *images=evaluate_image;
7612 break;
7613 }
7614 break;
7615 }
cristy3ed852e2009-09-05 21:47:34 +00007616 case 'f':
7617 {
cristyf0a247f2009-10-04 00:20:03 +00007618 if (LocaleCompare("fft",option+1) == 0)
7619 {
7620 Image
7621 *fourier_image;
7622
7623 /*
7624 Implements the discrete Fourier transform (DFT).
7625 */
cristy6fccee12011-10-20 18:43:18 +00007626 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007627 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7628 MagickTrue : MagickFalse,exception);
7629 if (fourier_image == (Image *) NULL)
7630 break;
7631 *images=DestroyImage(*images);
7632 *images=fourier_image;
7633 break;
7634 }
cristy3ed852e2009-09-05 21:47:34 +00007635 if (LocaleCompare("flatten",option+1) == 0)
7636 {
7637 Image
7638 *flatten_image;
7639
cristy6fccee12011-10-20 18:43:18 +00007640 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007641 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7642 if (flatten_image == (Image *) NULL)
7643 break;
7644 *images=DestroyImageList(*images);
7645 *images=flatten_image;
7646 break;
7647 }
7648 if (LocaleCompare("fx",option+1) == 0)
7649 {
7650 Image
7651 *fx_image;
7652
cristy6fccee12011-10-20 18:43:18 +00007653 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007654 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007655 if (fx_image == (Image *) NULL)
7656 {
7657 status=MagickFalse;
7658 break;
7659 }
7660 *images=DestroyImageList(*images);
7661 *images=fx_image;
7662 break;
7663 }
7664 break;
7665 }
7666 case 'h':
7667 {
7668 if (LocaleCompare("hald-clut",option+1) == 0)
7669 {
7670 Image
7671 *hald_image,
7672 *image;
7673
cristy6fccee12011-10-20 18:43:18 +00007674 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007675 image=RemoveFirstImageFromList(images);
7676 hald_image=RemoveFirstImageFromList(images);
7677 if (hald_image == (Image *) NULL)
7678 {
7679 status=MagickFalse;
7680 break;
7681 }
cristy7c0a0a42011-08-23 17:57:25 +00007682 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007683 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007684 if (*images != (Image *) NULL)
7685 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007686 *images=image;
7687 break;
7688 }
7689 break;
7690 }
7691 case 'i':
7692 {
7693 if (LocaleCompare("ift",option+1) == 0)
7694 {
7695 Image
cristy8587f882009-11-13 20:28:49 +00007696 *fourier_image,
7697 *magnitude_image,
7698 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007699
7700 /*
7701 Implements the inverse fourier discrete Fourier transform (DFT).
7702 */
cristy6fccee12011-10-20 18:43:18 +00007703 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007704 magnitude_image=RemoveFirstImageFromList(images);
7705 phase_image=RemoveFirstImageFromList(images);
7706 if (phase_image == (Image *) NULL)
7707 {
7708 status=MagickFalse;
7709 break;
7710 }
7711 fourier_image=InverseFourierTransformImage(magnitude_image,
7712 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007713 if (fourier_image == (Image *) NULL)
7714 break;
cristy0aff6ea2009-11-14 01:40:53 +00007715 if (*images != (Image *) NULL)
7716 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007717 *images=fourier_image;
7718 break;
7719 }
7720 if (LocaleCompare("insert",option+1) == 0)
7721 {
7722 Image
7723 *p,
7724 *q;
7725
7726 index=0;
7727 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007728 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007729 p=RemoveLastImageFromList(images);
7730 if (p == (Image *) NULL)
7731 {
7732 (void) ThrowMagickException(exception,GetMagickModule(),
7733 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7734 status=MagickFalse;
7735 break;
7736 }
7737 q=p;
7738 if (index == 0)
7739 PrependImageToList(images,q);
7740 else
cristybb503372010-05-27 20:51:26 +00007741 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007742 AppendImageToList(images,q);
7743 else
7744 {
7745 q=GetImageFromList(*images,index-1);
7746 if (q == (Image *) NULL)
7747 {
7748 (void) ThrowMagickException(exception,GetMagickModule(),
7749 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7750 status=MagickFalse;
7751 break;
7752 }
7753 InsertImageInList(&q,p);
7754 }
7755 *images=GetFirstImageInList(q);
7756 break;
7757 }
cristy28474bf2011-09-11 23:32:52 +00007758 if (LocaleCompare("interpolate",option+1) == 0)
7759 {
7760 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7761 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7762 break;
7763 }
cristy3ed852e2009-09-05 21:47:34 +00007764 break;
7765 }
7766 case 'l':
7767 {
7768 if (LocaleCompare("layers",option+1) == 0)
7769 {
7770 Image
7771 *layers;
7772
7773 ImageLayerMethod
7774 method;
7775
cristy6fccee12011-10-20 18:43:18 +00007776 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007777 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007778 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007779 MagickFalse,argv[i+1]);
7780 switch (method)
7781 {
7782 case CoalesceLayer:
7783 {
7784 layers=CoalesceImages(*images,exception);
7785 break;
7786 }
7787 case CompareAnyLayer:
7788 case CompareClearLayer:
7789 case CompareOverlayLayer:
7790 default:
7791 {
cristy8a9106f2011-07-05 14:39:26 +00007792 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007793 break;
7794 }
7795 case MergeLayer:
7796 case FlattenLayer:
7797 case MosaicLayer:
7798 case TrimBoundsLayer:
7799 {
7800 layers=MergeImageLayers(*images,method,exception);
7801 break;
7802 }
7803 case DisposeLayer:
7804 {
7805 layers=DisposeImages(*images,exception);
7806 break;
7807 }
7808 case OptimizeImageLayer:
7809 {
7810 layers=OptimizeImageLayers(*images,exception);
7811 break;
7812 }
7813 case OptimizePlusLayer:
7814 {
7815 layers=OptimizePlusImageLayers(*images,exception);
7816 break;
7817 }
7818 case OptimizeTransLayer:
7819 {
7820 OptimizeImageTransparency(*images,exception);
7821 break;
7822 }
7823 case RemoveDupsLayer:
7824 {
7825 RemoveDuplicateLayers(images,exception);
7826 break;
7827 }
7828 case RemoveZeroLayer:
7829 {
7830 RemoveZeroDelayLayers(images,exception);
7831 break;
7832 }
7833 case OptimizeLayer:
7834 {
7835 /*
7836 General Purpose, GIF Animation Optimizer.
7837 */
7838 layers=CoalesceImages(*images,exception);
7839 if (layers == (Image *) NULL)
7840 {
7841 status=MagickFalse;
7842 break;
7843 }
cristy3ed852e2009-09-05 21:47:34 +00007844 *images=DestroyImageList(*images);
7845 *images=layers;
7846 layers=OptimizeImageLayers(*images,exception);
7847 if (layers == (Image *) NULL)
7848 {
7849 status=MagickFalse;
7850 break;
7851 }
cristy3ed852e2009-09-05 21:47:34 +00007852 *images=DestroyImageList(*images);
7853 *images=layers;
7854 layers=(Image *) NULL;
7855 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007856 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7857 exception);
cristy3ed852e2009-09-05 21:47:34 +00007858 break;
7859 }
7860 case CompositeLayer:
7861 {
7862 CompositeOperator
7863 compose;
7864
7865 Image
7866 *source;
7867
7868 RectangleInfo
7869 geometry;
7870
7871 /*
7872 Split image sequence at the first 'NULL:' image.
7873 */
7874 source=(*images);
7875 while (source != (Image *) NULL)
7876 {
7877 source=GetNextImageInList(source);
7878 if ((source != (Image *) NULL) &&
7879 (LocaleCompare(source->magick,"NULL") == 0))
7880 break;
7881 }
7882 if (source != (Image *) NULL)
7883 {
7884 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7885 (GetNextImageInList(source) == (Image *) NULL))
7886 source=(Image *) NULL;
7887 else
7888 {
7889 /*
7890 Separate the two lists, junk the null: image.
7891 */
7892 source=SplitImageList(source->previous);
7893 DeleteImageFromList(&source);
7894 }
7895 }
7896 if (source == (Image *) NULL)
7897 {
7898 (void) ThrowMagickException(exception,GetMagickModule(),
7899 OptionError,"MissingNullSeparator","layers Composite");
7900 status=MagickFalse;
7901 break;
7902 }
7903 /*
7904 Adjust offset with gravity and virtual canvas.
7905 */
7906 SetGeometry(*images,&geometry);
7907 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7908 geometry.width=source->page.width != 0 ?
7909 source->page.width : source->columns;
7910 geometry.height=source->page.height != 0 ?
7911 source->page.height : source->rows;
7912 GravityAdjustGeometry((*images)->page.width != 0 ?
7913 (*images)->page.width : (*images)->columns,
7914 (*images)->page.height != 0 ? (*images)->page.height :
7915 (*images)->rows,(*images)->gravity,&geometry);
7916 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007917 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007918 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007919 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007920 MagickComposeOptions,MagickFalse,option);
7921 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7922 exception);
7923 source=DestroyImageList(source);
7924 break;
7925 }
7926 }
7927 if (layers == (Image *) NULL)
7928 break;
cristy3ed852e2009-09-05 21:47:34 +00007929 *images=DestroyImageList(*images);
7930 *images=layers;
7931 break;
7932 }
7933 break;
7934 }
7935 case 'm':
7936 {
7937 if (LocaleCompare("map",option+1) == 0)
7938 {
cristy6fccee12011-10-20 18:43:18 +00007939 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007940 if (*option == '+')
7941 {
cristy018f07f2011-09-04 21:15:19 +00007942 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7943 exception);
cristy3ed852e2009-09-05 21:47:34 +00007944 break;
7945 }
7946 i++;
7947 break;
7948 }
cristyf40785b2010-03-06 02:27:27 +00007949 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007950 {
7951 Image
cristyf40785b2010-03-06 02:27:27 +00007952 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007953
cristyd18ae7c2010-03-07 17:39:52 +00007954 /*
7955 Maximum image sequence (deprecated).
7956 */
cristy6fccee12011-10-20 18:43:18 +00007957 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007958 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007959 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007960 {
7961 status=MagickFalse;
7962 break;
7963 }
7964 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007965 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007966 break;
7967 }
cristyf40785b2010-03-06 02:27:27 +00007968 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007969 {
7970 Image
cristyf40785b2010-03-06 02:27:27 +00007971 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007972
cristyd18ae7c2010-03-07 17:39:52 +00007973 /*
7974 Minimum image sequence (deprecated).
7975 */
cristy6fccee12011-10-20 18:43:18 +00007976 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007977 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007978 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007979 {
7980 status=MagickFalse;
7981 break;
7982 }
7983 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007984 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007985 break;
7986 }
cristy3ed852e2009-09-05 21:47:34 +00007987 if (LocaleCompare("morph",option+1) == 0)
7988 {
7989 Image
7990 *morph_image;
7991
cristy6fccee12011-10-20 18:43:18 +00007992 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007993 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007994 exception);
7995 if (morph_image == (Image *) NULL)
7996 {
7997 status=MagickFalse;
7998 break;
7999 }
8000 *images=DestroyImageList(*images);
8001 *images=morph_image;
8002 break;
8003 }
8004 if (LocaleCompare("mosaic",option+1) == 0)
8005 {
8006 Image
8007 *mosaic_image;
8008
cristy6fccee12011-10-20 18:43:18 +00008009 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008010 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8011 if (mosaic_image == (Image *) NULL)
8012 {
8013 status=MagickFalse;
8014 break;
8015 }
8016 *images=DestroyImageList(*images);
8017 *images=mosaic_image;
8018 break;
8019 }
8020 break;
8021 }
8022 case 'p':
8023 {
8024 if (LocaleCompare("print",option+1) == 0)
8025 {
8026 char
8027 *string;
8028
cristy6fccee12011-10-20 18:43:18 +00008029 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00008030 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8031 exception);
cristy3ed852e2009-09-05 21:47:34 +00008032 if (string == (char *) NULL)
8033 break;
cristyb51dff52011-05-19 16:55:47 +00008034 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008035 string=DestroyString(string);
8036 }
8037 if (LocaleCompare("process",option+1) == 0)
8038 {
8039 char
8040 **arguments;
8041
8042 int
8043 j,
8044 number_arguments;
8045
cristy6fccee12011-10-20 18:43:18 +00008046 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008047 arguments=StringToArgv(argv[i+1],&number_arguments);
8048 if (arguments == (char **) NULL)
8049 break;
8050 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8051 {
8052 char
8053 breaker,
8054 quote,
8055 *token;
8056
8057 const char
8058 *arguments;
8059
8060 int
8061 next,
8062 status;
8063
8064 size_t
8065 length;
8066
8067 TokenInfo
8068 *token_info;
8069
8070 /*
8071 Support old style syntax, filter="-option arg".
8072 */
8073 length=strlen(argv[i+1]);
8074 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008075 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008076 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8077 sizeof(*token));
8078 if (token == (char *) NULL)
8079 break;
8080 next=0;
8081 arguments=argv[i+1];
8082 token_info=AcquireTokenInfo();
8083 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8084 "\"",'\0',&breaker,&next,&quote);
8085 token_info=DestroyTokenInfo(token_info);
8086 if (status == 0)
8087 {
8088 const char
8089 *argv;
8090
8091 argv=(&(arguments[next]));
8092 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8093 exception);
8094 }
8095 token=DestroyString(token);
8096 break;
8097 }
cristy91c0da22010-05-02 01:44:07 +00008098 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008099 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8100 number_arguments-2,(const char **) arguments+2,exception);
8101 for (j=0; j < number_arguments; j++)
8102 arguments[j]=DestroyString(arguments[j]);
8103 arguments=(char **) RelinquishMagickMemory(arguments);
8104 break;
8105 }
8106 break;
8107 }
8108 case 'r':
8109 {
8110 if (LocaleCompare("reverse",option+1) == 0)
8111 {
8112 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008113 break;
8114 }
8115 break;
8116 }
8117 case 's':
8118 {
cristy4285d782011-02-09 20:12:28 +00008119 if (LocaleCompare("smush",option+1) == 0)
8120 {
8121 Image
8122 *smush_image;
8123
8124 ssize_t
8125 offset;
8126
cristy6fccee12011-10-20 18:43:18 +00008127 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008128 offset=(ssize_t) StringToLong(argv[i+1]);
8129 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8130 MagickFalse,offset,exception);
8131 if (smush_image == (Image *) NULL)
8132 {
8133 status=MagickFalse;
8134 break;
8135 }
8136 *images=DestroyImageList(*images);
8137 *images=smush_image;
8138 break;
8139 }
cristy3ed852e2009-09-05 21:47:34 +00008140 if (LocaleCompare("swap",option+1) == 0)
8141 {
8142 Image
8143 *p,
8144 *q,
8145 *swap;
8146
cristybb503372010-05-27 20:51:26 +00008147 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008148 swap_index;
8149
8150 index=(-1);
8151 swap_index=(-2);
8152 if (*option != '+')
8153 {
8154 GeometryInfo
8155 geometry_info;
8156
8157 MagickStatusType
8158 flags;
8159
8160 swap_index=(-1);
8161 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008162 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008163 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008164 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008165 }
8166 p=GetImageFromList(*images,index);
8167 q=GetImageFromList(*images,swap_index);
8168 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8169 {
8170 (void) ThrowMagickException(exception,GetMagickModule(),
8171 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8172 status=MagickFalse;
8173 break;
8174 }
8175 if (p == q)
8176 break;
8177 swap=CloneImage(p,0,0,MagickTrue,exception);
8178 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8179 ReplaceImageInList(&q,swap);
8180 *images=GetFirstImageInList(q);
8181 break;
8182 }
8183 break;
8184 }
8185 case 'w':
8186 {
8187 if (LocaleCompare("write",option+1) == 0)
8188 {
cristy071dd7b2010-04-09 13:04:54 +00008189 char
cristy06609ee2010-03-17 20:21:27 +00008190 key[MaxTextExtent];
8191
cristy3ed852e2009-09-05 21:47:34 +00008192 Image
8193 *write_images;
8194
8195 ImageInfo
8196 *write_info;
8197
cristy6fccee12011-10-20 18:43:18 +00008198 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008199 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008200 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008201 write_images=(*images);
8202 if (*option == '+')
8203 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008204 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008205 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8206 write_info=DestroyImageInfo(write_info);
8207 if (*option == '+')
8208 write_images=DestroyImageList(write_images);
8209 break;
8210 }
8211 break;
8212 }
8213 default:
8214 break;
8215 }
8216 i+=count;
8217 }
8218 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008219 mogrify_info=DestroyImageInfo(mogrify_info);
8220 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008221 return(status != 0 ? MagickTrue : MagickFalse);
8222}
8223
8224/*
8225%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8226% %
8227% %
8228% %
8229+ M o g r i f y I m a g e s %
8230% %
8231% %
8232% %
8233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8234%
8235% MogrifyImages() applies image processing options to a sequence of images as
8236% prescribed by command line options.
8237%
8238% The format of the MogrifyImage method is:
8239%
8240% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8241% const MagickBooleanType post,const int argc,const char **argv,
8242% Image **images,Exceptioninfo *exception)
8243%
8244% A description of each parameter follows:
8245%
8246% o image_info: the image info..
8247%
8248% o post: If true, post process image list operators otherwise pre-process.
8249%
8250% o argc: Specifies a pointer to an integer describing the number of
8251% elements in the argument vector.
8252%
8253% o argv: Specifies a pointer to a text array containing the command line
8254% arguments.
8255%
anthonye9c27192011-03-27 08:07:06 +00008256% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008257%
8258% o exception: return any errors or warnings in this structure.
8259%
8260*/
8261WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8262 const MagickBooleanType post,const int argc,const char **argv,
8263 Image **images,ExceptionInfo *exception)
8264{
8265#define MogrifyImageTag "Mogrify/Image"
8266
anthonye9c27192011-03-27 08:07:06 +00008267 MagickStatusType
8268 status;
cristy3ed852e2009-09-05 21:47:34 +00008269
cristy0e9f9c12010-02-11 03:00:47 +00008270 MagickBooleanType
8271 proceed;
8272
anthonye9c27192011-03-27 08:07:06 +00008273 size_t
8274 n;
cristy3ed852e2009-09-05 21:47:34 +00008275
cristybb503372010-05-27 20:51:26 +00008276 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008277 i;
8278
cristy3ed852e2009-09-05 21:47:34 +00008279 assert(image_info != (ImageInfo *) NULL);
8280 assert(image_info->signature == MagickSignature);
8281 if (images == (Image **) NULL)
8282 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008283 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008284 assert((*images)->signature == MagickSignature);
8285 if ((*images)->debug != MagickFalse)
8286 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8287 (*images)->filename);
8288 if ((argc <= 0) || (*argv == (char *) NULL))
8289 return(MagickTrue);
8290 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8291 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008292 status=0;
anthonye9c27192011-03-27 08:07:06 +00008293
anthonyce2716b2011-04-22 09:51:34 +00008294#if 0
cristy1e604812011-05-19 18:07:50 +00008295 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8296 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008297#endif
8298
anthonye9c27192011-03-27 08:07:06 +00008299 /*
8300 Pre-process multi-image sequence operators
8301 */
cristy3ed852e2009-09-05 21:47:34 +00008302 if (post == MagickFalse)
8303 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008304 /*
8305 For each image, process simple single image operators
8306 */
8307 i=0;
8308 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008309 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008310 {
anthonyce2716b2011-04-22 09:51:34 +00008311#if 0
cristy1e604812011-05-19 18:07:50 +00008312 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8313 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008314#endif
anthonye9c27192011-03-27 08:07:06 +00008315 status&=MogrifyImage(image_info,argc,argv,images,exception);
8316 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008317 if (proceed == MagickFalse)
8318 break;
anthonye9c27192011-03-27 08:07:06 +00008319 if ( (*images)->next == (Image *) NULL )
8320 break;
8321 *images=(*images)->next;
8322 i++;
cristy3ed852e2009-09-05 21:47:34 +00008323 }
anthonye9c27192011-03-27 08:07:06 +00008324 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008325#if 0
cristy1e604812011-05-19 18:07:50 +00008326 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8327 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008328#endif
anthonye9c27192011-03-27 08:07:06 +00008329
8330 /*
8331 Post-process, multi-image sequence operators
8332 */
8333 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008334 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008335 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008336 return(status != 0 ? MagickTrue : MagickFalse);
8337}