blob: 7eaf1211511ce582fbef00cb0262e52b52c2d948 [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"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
58 Define declarations.
59*/
60#define UndefinedCompressionQuality 0UL
61
62/*
cristy3ed852e2009-09-05 21:47:34 +000063%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64% %
65% %
66% %
cristy5063d812010-10-19 16:28:10 +000067% 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 +000068% %
69% %
70% %
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72%
73% MagickCommandGenesis() applies image processing options to an image as
74% prescribed by command line options.
75%
76% The format of the MagickCommandGenesis method is:
77%
78% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000079% MagickCommand command,int argc,char **argv,char **metadata,
80% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000081%
82% A description of each parameter follows:
83%
84% o image_info: the image info.
85%
cristy5063d812010-10-19 16:28:10 +000086% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000087% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000088% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
89% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000090%
91% o argc: Specifies a pointer to an integer describing the number of
92% elements in the argument vector.
93%
94% o argv: Specifies a pointer to a text array containing the command line
95% arguments.
96%
cristy5063d812010-10-19 16:28:10 +000097% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o exception: return any errors or warnings in this structure.
100%
101*/
102WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
103 MagickCommand command,int argc,char **argv,char **metadata,
104 ExceptionInfo *exception)
105{
106 char
107 *option;
108
109 double
110 duration,
111 elapsed_time,
112 user_time;
113
cristy3980b0d2009-10-25 14:37:13 +0000114 MagickBooleanType
115 concurrent,
116 regard_warnings,
117 status;
118
cristybb503372010-05-27 20:51:26 +0000119 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000120 i;
121
122 TimerInfo
123 *timer;
124
cristybb503372010-05-27 20:51:26 +0000125 size_t
cristy3980b0d2009-10-25 14:37:13 +0000126 iterations;
127
cristyd0a94fa2010-03-12 14:18:11 +0000128 (void) setlocale(LC_ALL,"");
129 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000130 concurrent=MagickFalse;
131 duration=(-1.0);
132 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000133 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000134 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000135 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000136 {
137 option=argv[i];
138 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
139 continue;
140 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000141 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000142 if (LocaleCompare("concurrent",option+1) == 0)
143 concurrent=MagickTrue;
144 if (LocaleCompare("debug",option+1) == 0)
145 (void) SetLogEventMask(argv[++i]);
146 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000147 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000148 if (LocaleCompare("regard-warnings",option+1) == 0)
149 regard_warnings=MagickTrue;
150 }
151 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000152 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000153 {
cristybb503372010-05-27 20:51:26 +0000154 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000155 {
cristy33557d72009-11-06 00:54:33 +0000156 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000157 continue;
158 if (duration > 0)
159 {
160 if (GetElapsedTime(timer) > duration)
161 continue;
162 (void) ContinueTimer(timer);
163 }
164 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000165 if (exception->severity != UndefinedException)
166 {
167 if ((exception->severity > ErrorException) ||
168 (regard_warnings != MagickFalse))
169 status=MagickTrue;
170 CatchException(exception);
171 }
cristy3d1a5512009-10-25 21:23:27 +0000172 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000173 {
174 (void) fputs(*metadata,stdout);
175 (void) fputc('\n',stdout);
176 *metadata=DestroyString(*metadata);
177 }
178 }
179 }
cristyceae09d2009-10-28 17:18:47 +0000180 else
181 {
182 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000183#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000184 # pragma omp parallel for shared(status)
185#endif
cristybb503372010-05-27 20:51:26 +0000186 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000187 {
cristy33557d72009-11-06 00:54:33 +0000188 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000189 continue;
190 if (duration > 0)
191 {
192 if (GetElapsedTime(timer) > duration)
193 continue;
194 (void) ContinueTimer(timer);
195 }
196 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000197#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000198 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000199#endif
200 {
201 if (exception->severity != UndefinedException)
202 {
203 if ((exception->severity > ErrorException) ||
204 (regard_warnings != MagickFalse))
205 status=MagickTrue;
206 CatchException(exception);
207 }
208 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
209 {
210 (void) fputs(*metadata,stdout);
211 (void) fputc('\n',stdout);
212 *metadata=DestroyString(*metadata);
213 }
214 }
215 }
216 }
cristy3980b0d2009-10-25 14:37:13 +0000217 if (iterations > 1)
218 {
219 elapsed_time=GetElapsedTime(timer);
220 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000221 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000222 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
223 iterations,1.0*iterations/elapsed_time,user_time,(double)
224 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
225 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000226 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000227 }
228 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000229 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000230}
231
232/*
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234% %
235% %
236% %
cristy3ed852e2009-09-05 21:47:34 +0000237+ M o g r i f y I m a g e %
238% %
239% %
240% %
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242%
anthonye9c27192011-03-27 08:07:06 +0000243% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000244% image that may be part of a large list, but also handles any 'region'
245% image handling.
anthonye9c27192011-03-27 08:07:06 +0000246%
247% The image in the list may be modified in three different ways...
248%
249% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
250% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
251% * replace by a list of images (only the -separate option!)
252%
253% In each case the result is returned into the list, and a pointer to the
254% modified image (last image added if replaced by a list of images) is
255% returned.
256%
257% ASIDE: The -crop is present but restricted to non-tile single image crops
258%
259% This means if all the images are being processed (such as by
260% MogrifyImages(), next image to be processed will be as per the pointer
261% (*image)->next. Also the image list may grow as a result of some specific
262% operations but as images are never merged or deleted, it will never shrink
263% in length. Typically the list will remain the same length.
264%
265% WARNING: As the image pointed to may be replaced, the first image in the
266% list may also change. GetFirstImageInList() should be used by caller if
267% they wish return the Image pointer to the first image in list.
268%
cristy3ed852e2009-09-05 21:47:34 +0000269%
270% The format of the MogrifyImage method is:
271%
272% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
273% const char **argv,Image **image)
274%
275% A description of each parameter follows:
276%
277% o image_info: the image info..
278%
279% o argc: Specifies a pointer to an integer describing the number of
280% elements in the argument vector.
281%
282% o argv: Specifies a pointer to a text array containing the command line
283% arguments.
284%
285% o image: the image.
286%
287% o exception: return any errors or warnings in this structure.
288%
289*/
290
cristy4c08aed2011-07-01 19:47:50 +0000291/*
292** GetImageCache() will read an image into a image cache if not already
293** present then return the image that is in the cache under that filename.
294*/
anthonydf8ebac2011-04-27 09:03:19 +0000295static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
296 ExceptionInfo *exception)
297{
298 char
299 key[MaxTextExtent];
300
301 ExceptionInfo
302 *sans_exception;
303
304 Image
305 *image;
306
307 ImageInfo
308 *read_info;
309
cristyb51dff52011-05-19 16:55:47 +0000310 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000311 sans_exception=AcquireExceptionInfo();
312 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
313 sans_exception=DestroyExceptionInfo(sans_exception);
314 if (image != (Image *) NULL)
315 return(image);
316 read_info=CloneImageInfo(image_info);
317 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
318 image=ReadImage(read_info,exception);
319 read_info=DestroyImageInfo(read_info);
320 if (image != (Image *) NULL)
321 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
322 return(image);
323}
324
cristy3ed852e2009-09-05 21:47:34 +0000325static MagickBooleanType IsPathWritable(const char *path)
326{
327 if (IsPathAccessible(path) == MagickFalse)
328 return(MagickFalse);
329 if (access(path,W_OK) != 0)
330 return(MagickFalse);
331 return(MagickTrue);
332}
333
cristybb503372010-05-27 20:51:26 +0000334static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000335{
336 if (x > y)
337 return(x);
338 return(y);
339}
340
anthonydf8ebac2011-04-27 09:03:19 +0000341static MagickBooleanType MonitorProgress(const char *text,
342 const MagickOffsetType offset,const MagickSizeType extent,
343 void *wand_unused(client_data))
344{
345 char
346 message[MaxTextExtent],
347 tag[MaxTextExtent];
348
349 const char
350 *locale_message;
351
352 register char
353 *p;
354
355 if (extent < 2)
356 return(MagickTrue);
357 (void) CopyMagickMemory(tag,text,MaxTextExtent);
358 p=strrchr(tag,'/');
359 if (p != (char *) NULL)
360 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000361 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000362 locale_message=GetLocaleMessage(message);
363 if (locale_message == message)
364 locale_message=tag;
365 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000366 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
367 locale_message,(long) offset,(unsigned long) extent,(long)
368 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000369 else
cristyb51dff52011-05-19 16:55:47 +0000370 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000371 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
372 (100L*offset/(extent-1)));
373 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000374 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000375 (void) fflush(stderr);
376 return(MagickTrue);
377}
378
379/*
anthony3d2f4862011-05-01 13:48:16 +0000380** SparseColorOption() parses the complex -sparse-color argument into an
381** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000382** Argument is a complex mix of floating-point pixel coodinates, and color
383** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000384** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000385** setting.
386*/
cristy3884f692011-07-08 18:00:18 +0000387static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000388 const SparseColorMethod method,const char *arguments,
389 const MagickBooleanType color_from_image,ExceptionInfo *exception)
390{
anthonydf8ebac2011-04-27 09:03:19 +0000391 char
392 token[MaxTextExtent];
393
394 const char
395 *p;
396
397 double
398 *sparse_arguments;
399
anthonydf8ebac2011-04-27 09:03:19 +0000400 Image
401 *sparse_image;
402
cristy4c08aed2011-07-01 19:47:50 +0000403 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000404 color;
405
406 MagickBooleanType
407 error;
408
cristy5f09d852011-05-29 01:39:29 +0000409 register size_t
410 x;
411
412 size_t
413 number_arguments,
414 number_colors;
415
anthonydf8ebac2011-04-27 09:03:19 +0000416 assert(image != (Image *) NULL);
417 assert(image->signature == MagickSignature);
418 if (image->debug != MagickFalse)
419 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
420 assert(exception != (ExceptionInfo *) NULL);
421 assert(exception->signature == MagickSignature);
422 /*
423 Limit channels according to image - and add up number of color channel.
424 */
anthonydf8ebac2011-04-27 09:03:19 +0000425 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000426 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000427 number_colors++;
cristyed231572011-07-14 02:18:59 +0000428 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000429 number_colors++;
cristyed231572011-07-14 02:18:59 +0000430 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000431 number_colors++;
cristyed231572011-07-14 02:18:59 +0000432 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000433 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000434 number_colors++;
cristyed231572011-07-14 02:18:59 +0000435 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000436 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
438
439 /*
440 Read string, to determine number of arguments needed,
441 */
442 p=arguments;
443 x=0;
444 while( *p != '\0' )
445 {
446 GetMagickToken(p,&p,token);
447 if ( token[0] == ',' ) continue;
448 if ( isalpha((int) token[0]) || token[0] == '#' ) {
449 if ( color_from_image ) {
450 (void) ThrowMagickException(exception,GetMagickModule(),
451 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
452 "Color arg given, when colors are coming from image");
453 return( (Image *)NULL);
454 }
455 x += number_colors; /* color argument */
456 }
457 else {
458 x++; /* floating point argument */
459 }
460 }
461 error=MagickTrue;
462 if ( color_from_image ) {
463 /* just the control points are being given */
464 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
465 number_arguments=(x/2)*(2+number_colors);
466 }
467 else {
468 /* control points and color values */
469 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
470 number_arguments=x;
471 }
472 if ( error ) {
473 (void) ThrowMagickException(exception,GetMagickModule(),
474 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
475 "Invalid number of Arguments");
476 return( (Image *)NULL);
477 }
478
479 /* Allocate and fill in the floating point arguments */
480 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
481 sizeof(*sparse_arguments));
482 if (sparse_arguments == (double *) NULL) {
483 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
484 "MemoryAllocationFailed","%s","SparseColorOption");
485 return( (Image *)NULL);
486 }
487 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
488 sizeof(*sparse_arguments));
489 p=arguments;
490 x=0;
491 while( *p != '\0' && x < number_arguments ) {
492 /* X coordinate */
493 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
494 if ( token[0] == '\0' ) break;
495 if ( isalpha((int) token[0]) || token[0] == '#' ) {
496 (void) ThrowMagickException(exception,GetMagickModule(),
497 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
498 "Color found, instead of X-coord");
499 error = MagickTrue;
500 break;
501 }
cristyc1acd842011-05-19 23:05:47 +0000502 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000503 /* Y coordinate */
504 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
505 if ( token[0] == '\0' ) break;
506 if ( isalpha((int) token[0]) || token[0] == '#' ) {
507 (void) ThrowMagickException(exception,GetMagickModule(),
508 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
509 "Color found, instead of Y-coord");
510 error = MagickTrue;
511 break;
512 }
cristyc1acd842011-05-19 23:05:47 +0000513 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000514 /* color values for this control point */
515#if 0
516 if ( (color_from_image ) {
517 /* get color from image */
518 /* HOW??? */
519 }
520 else
521#endif
522 {
523 /* color name or function given in string argument */
524 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
525 if ( token[0] == '\0' ) break;
526 if ( isalpha((int) token[0]) || token[0] == '#' ) {
527 /* Color string given */
528 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000529 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000530 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000531 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000532 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000533 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000534 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000535 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000536 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000537 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000538 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000539 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000540 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000541 }
542 else {
543 /* Colors given as a set of floating point values - experimental */
544 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000545 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000546 {
anthonydf8ebac2011-04-27 09:03:19 +0000547 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
548 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
549 break;
cristyc1acd842011-05-19 23:05:47 +0000550 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000551 token[0] = ','; /* used this token - get another */
552 }
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000570 (image->colorspace == CMYKColorspace))
571 {
anthonydf8ebac2011-04-27 09:03:19 +0000572 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
573 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
574 break;
cristyc1acd842011-05-19 23:05:47 +0000575 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000576 token[0] = ','; /* used this token - get another */
577 }
cristyed231572011-07-14 02:18:59 +0000578 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000579 (image->matte != MagickFalse))
580 {
anthonydf8ebac2011-04-27 09:03:19 +0000581 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
582 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
583 break;
cristyc1acd842011-05-19 23:05:47 +0000584 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000585 token[0] = ','; /* used this token - get another */
586 }
587 }
588 }
589 }
590 if ( number_arguments != x && !error ) {
591 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
592 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
593 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
594 return( (Image *)NULL);
595 }
596 if ( error )
597 return( (Image *)NULL);
598
599 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000600 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
601 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000602 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
603 return( sparse_image );
604}
605
cristy3ed852e2009-09-05 21:47:34 +0000606WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
607 const char **argv,Image **image,ExceptionInfo *exception)
608{
anthonydf8ebac2011-04-27 09:03:19 +0000609 ChannelType
610 channel;
611
612 const char
613 *format,
614 *option;
615
616 DrawInfo
617 *draw_info;
618
619 GeometryInfo
620 geometry_info;
621
cristy3ed852e2009-09-05 21:47:34 +0000622 Image
623 *region_image;
624
anthonydf8ebac2011-04-27 09:03:19 +0000625 ImageInfo
626 *mogrify_info;
627
cristyebbcfea2011-02-25 02:43:54 +0000628 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000629 status;
630
cristy4c08aed2011-07-01 19:47:50 +0000631 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000632 fill;
cristy3ed852e2009-09-05 21:47:34 +0000633
anthonydf8ebac2011-04-27 09:03:19 +0000634 MagickStatusType
635 flags;
636
637 QuantizeInfo
638 *quantize_info;
639
640 RectangleInfo
641 geometry,
642 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000643
cristybb503372010-05-27 20:51:26 +0000644 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000645 i;
646
647 /*
648 Initialize method variables.
649 */
650 assert(image_info != (const ImageInfo *) NULL);
651 assert(image_info->signature == MagickSignature);
652 assert(image != (Image **) NULL);
653 assert((*image)->signature == MagickSignature);
654 if ((*image)->debug != MagickFalse)
655 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
656 if (argc < 0)
657 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000658 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000659 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
660 quantize_info=AcquireQuantizeInfo(mogrify_info);
661 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000662 GetPixelInfo(*image,&fill);
663 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000664 channel=mogrify_info->channel;
665 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000666 SetGeometry(*image,&region_geometry);
667 region_image=NewImageList();
668 /*
669 Transmogrify the image.
670 */
cristybb503372010-05-27 20:51:26 +0000671 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000672 {
anthonydf8ebac2011-04-27 09:03:19 +0000673 Image
674 *mogrify_image;
675
anthonye9c27192011-03-27 08:07:06 +0000676 ssize_t
677 count;
678
anthonydf8ebac2011-04-27 09:03:19 +0000679 option=argv[i];
680 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000681 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000682 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
683 0L);
cristycee97112010-05-28 00:44:52 +0000684 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000685 break;
cristy6b3da3a2010-06-20 02:21:46 +0000686 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000687 mogrify_image=(Image *)NULL;
688 switch (*(option+1))
689 {
690 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000691 {
anthonydf8ebac2011-04-27 09:03:19 +0000692 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000693 {
anthonydf8ebac2011-04-27 09:03:19 +0000694 /*
695 Adaptive blur image.
696 */
697 (void) SyncImageSettings(mogrify_info,*image);
698 flags=ParseGeometry(argv[i+1],&geometry_info);
699 if ((flags & SigmaValue) == 0)
700 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000701 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
702 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000703 break;
cristy3ed852e2009-09-05 21:47:34 +0000704 }
anthonydf8ebac2011-04-27 09:03:19 +0000705 if (LocaleCompare("adaptive-resize",option+1) == 0)
706 {
707 /*
708 Adaptive resize image.
709 */
710 (void) SyncImageSettings(mogrify_info,*image);
711 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
712 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
713 geometry.height,exception);
714 break;
715 }
716 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
717 {
718 /*
719 Adaptive sharpen image.
720 */
721 (void) SyncImageSettings(mogrify_info,*image);
722 flags=ParseGeometry(argv[i+1],&geometry_info);
723 if ((flags & SigmaValue) == 0)
724 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000725 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
726 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000727 break;
728 }
729 if (LocaleCompare("affine",option+1) == 0)
730 {
731 /*
732 Affine matrix.
733 */
734 if (*option == '+')
735 {
736 GetAffineMatrix(&draw_info->affine);
737 break;
738 }
739 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
740 break;
741 }
742 if (LocaleCompare("alpha",option+1) == 0)
743 {
744 AlphaChannelType
745 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000746
anthonydf8ebac2011-04-27 09:03:19 +0000747 (void) SyncImageSettings(mogrify_info,*image);
748 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
749 MagickFalse,argv[i+1]);
750 (void) SetImageAlphaChannel(*image,alpha_type);
751 InheritException(exception,&(*image)->exception);
752 break;
753 }
754 if (LocaleCompare("annotate",option+1) == 0)
755 {
756 char
757 *text,
758 geometry[MaxTextExtent];
759
760 /*
761 Annotate image.
762 */
763 (void) SyncImageSettings(mogrify_info,*image);
764 SetGeometryInfo(&geometry_info);
765 flags=ParseGeometry(argv[i+1],&geometry_info);
766 if ((flags & SigmaValue) == 0)
767 geometry_info.sigma=geometry_info.rho;
768 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
769 InheritException(exception,&(*image)->exception);
770 if (text == (char *) NULL)
771 break;
772 (void) CloneString(&draw_info->text,text);
773 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000774 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000775 geometry_info.xi,geometry_info.psi);
776 (void) CloneString(&draw_info->geometry,geometry);
777 draw_info->affine.sx=cos(DegreesToRadians(
778 fmod(geometry_info.rho,360.0)));
779 draw_info->affine.rx=sin(DegreesToRadians(
780 fmod(geometry_info.rho,360.0)));
781 draw_info->affine.ry=(-sin(DegreesToRadians(
782 fmod(geometry_info.sigma,360.0))));
783 draw_info->affine.sy=cos(DegreesToRadians(
784 fmod(geometry_info.sigma,360.0)));
785 (void) AnnotateImage(*image,draw_info);
786 InheritException(exception,&(*image)->exception);
787 break;
788 }
789 if (LocaleCompare("antialias",option+1) == 0)
790 {
791 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
792 MagickFalse;
793 draw_info->text_antialias=(*option == '-') ? MagickTrue :
794 MagickFalse;
795 break;
796 }
797 if (LocaleCompare("auto-gamma",option+1) == 0)
798 {
799 /*
800 Auto Adjust Gamma of image based on its mean
801 */
802 (void) SyncImageSettings(mogrify_info,*image);
cristyab015852011-07-06 01:03:32 +0000803 (void) AutoGammaImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +0000804 break;
805 }
806 if (LocaleCompare("auto-level",option+1) == 0)
807 {
808 /*
809 Perfectly Normalize (max/min stretch) the image
810 */
811 (void) SyncImageSettings(mogrify_info,*image);
cristyab015852011-07-06 01:03:32 +0000812 (void) AutoLevelImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +0000813 break;
814 }
815 if (LocaleCompare("auto-orient",option+1) == 0)
816 {
817 (void) SyncImageSettings(mogrify_info,*image);
818 switch ((*image)->orientation)
819 {
820 case TopRightOrientation:
821 {
822 mogrify_image=FlopImage(*image,exception);
823 break;
824 }
825 case BottomRightOrientation:
826 {
827 mogrify_image=RotateImage(*image,180.0,exception);
828 break;
829 }
830 case BottomLeftOrientation:
831 {
832 mogrify_image=FlipImage(*image,exception);
833 break;
834 }
835 case LeftTopOrientation:
836 {
837 mogrify_image=TransposeImage(*image,exception);
838 break;
839 }
840 case RightTopOrientation:
841 {
842 mogrify_image=RotateImage(*image,90.0,exception);
843 break;
844 }
845 case RightBottomOrientation:
846 {
847 mogrify_image=TransverseImage(*image,exception);
848 break;
849 }
850 case LeftBottomOrientation:
851 {
852 mogrify_image=RotateImage(*image,270.0,exception);
853 break;
854 }
855 default:
856 break;
857 }
858 if (mogrify_image != (Image *) NULL)
859 mogrify_image->orientation=TopLeftOrientation;
860 break;
861 }
862 break;
863 }
864 case 'b':
865 {
866 if (LocaleCompare("black-threshold",option+1) == 0)
867 {
868 /*
869 Black threshold image.
870 */
871 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000872 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000873 InheritException(exception,&(*image)->exception);
874 break;
875 }
876 if (LocaleCompare("blue-shift",option+1) == 0)
877 {
878 /*
879 Blue shift image.
880 */
881 (void) SyncImageSettings(mogrify_info,*image);
882 geometry_info.rho=1.5;
883 if (*option == '-')
884 flags=ParseGeometry(argv[i+1],&geometry_info);
885 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
886 break;
887 }
888 if (LocaleCompare("blur",option+1) == 0)
889 {
890 /*
891 Gaussian blur image.
892 */
893 (void) SyncImageSettings(mogrify_info,*image);
894 flags=ParseGeometry(argv[i+1],&geometry_info);
895 if ((flags & SigmaValue) == 0)
896 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000897 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000898 geometry_info.sigma,exception);
899 break;
900 }
901 if (LocaleCompare("border",option+1) == 0)
902 {
903 /*
904 Surround image with a border of solid color.
905 */
906 (void) SyncImageSettings(mogrify_info,*image);
907 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
908 if ((flags & SigmaValue) == 0)
909 geometry.height=geometry.width;
910 mogrify_image=BorderImage(*image,&geometry,exception);
911 break;
912 }
913 if (LocaleCompare("bordercolor",option+1) == 0)
914 {
915 if (*option == '+')
916 {
917 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
918 exception);
919 break;
920 }
921 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
922 exception);
923 break;
924 }
925 if (LocaleCompare("box",option+1) == 0)
926 {
927 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
928 exception);
929 break;
930 }
931 if (LocaleCompare("brightness-contrast",option+1) == 0)
932 {
933 double
934 brightness,
935 contrast;
936
937 GeometryInfo
938 geometry_info;
939
940 MagickStatusType
941 flags;
942
943 /*
944 Brightness / contrast image.
945 */
946 (void) SyncImageSettings(mogrify_info,*image);
947 flags=ParseGeometry(argv[i+1],&geometry_info);
948 brightness=geometry_info.rho;
949 contrast=0.0;
950 if ((flags & SigmaValue) != 0)
951 contrast=geometry_info.sigma;
cristy9ee60942011-07-06 14:54:38 +0000952 (void) BrightnessContrastImage(*image,brightness,contrast);
anthonydf8ebac2011-04-27 09:03:19 +0000953 InheritException(exception,&(*image)->exception);
954 break;
955 }
956 break;
957 }
958 case 'c':
959 {
960 if (LocaleCompare("cdl",option+1) == 0)
961 {
962 char
963 *color_correction_collection;
964
965 /*
966 Color correct with a color decision list.
967 */
968 (void) SyncImageSettings(mogrify_info,*image);
969 color_correction_collection=FileToString(argv[i+1],~0,exception);
970 if (color_correction_collection == (char *) NULL)
971 break;
972 (void) ColorDecisionListImage(*image,color_correction_collection);
973 InheritException(exception,&(*image)->exception);
974 break;
975 }
976 if (LocaleCompare("channel",option+1) == 0)
977 {
978 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000979 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000980 else
cristyfa806a72011-07-04 02:06:13 +0000981 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000982 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000983 break;
984 }
985 if (LocaleCompare("charcoal",option+1) == 0)
986 {
987 /*
988 Charcoal image.
989 */
990 (void) SyncImageSettings(mogrify_info,*image);
991 flags=ParseGeometry(argv[i+1],&geometry_info);
992 if ((flags & SigmaValue) == 0)
993 geometry_info.sigma=1.0;
994 mogrify_image=CharcoalImage(*image,geometry_info.rho,
995 geometry_info.sigma,exception);
996 break;
997 }
998 if (LocaleCompare("chop",option+1) == 0)
999 {
1000 /*
1001 Chop the image.
1002 */
1003 (void) SyncImageSettings(mogrify_info,*image);
1004 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1005 mogrify_image=ChopImage(*image,&geometry,exception);
1006 break;
1007 }
1008 if (LocaleCompare("clamp",option+1) == 0)
1009 {
1010 /*
1011 Clamp image.
1012 */
1013 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001014 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001015 InheritException(exception,&(*image)->exception);
1016 break;
1017 }
1018 if (LocaleCompare("clip",option+1) == 0)
1019 {
1020 (void) SyncImageSettings(mogrify_info,*image);
1021 if (*option == '+')
1022 {
1023 (void) SetImageClipMask(*image,(Image *) NULL);
1024 InheritException(exception,&(*image)->exception);
1025 break;
1026 }
1027 (void) ClipImage(*image);
1028 InheritException(exception,&(*image)->exception);
1029 break;
1030 }
1031 if (LocaleCompare("clip-mask",option+1) == 0)
1032 {
1033 CacheView
1034 *mask_view;
1035
1036 Image
1037 *mask_image;
1038
cristy4c08aed2011-07-01 19:47:50 +00001039 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001040 *restrict q;
1041
1042 register ssize_t
1043 x;
1044
1045 ssize_t
1046 y;
1047
1048 (void) SyncImageSettings(mogrify_info,*image);
1049 if (*option == '+')
1050 {
1051 /*
1052 Remove a mask.
1053 */
1054 (void) SetImageMask(*image,(Image *) NULL);
1055 InheritException(exception,&(*image)->exception);
1056 break;
1057 }
1058 /*
1059 Set the image mask.
1060 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1061 */
1062 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1063 if (mask_image == (Image *) NULL)
1064 break;
1065 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1066 return(MagickFalse);
1067 mask_view=AcquireCacheView(mask_image);
1068 for (y=0; y < (ssize_t) mask_image->rows; y++)
1069 {
1070 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1071 exception);
cristy4c08aed2011-07-01 19:47:50 +00001072 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001073 break;
1074 for (x=0; x < (ssize_t) mask_image->columns; x++)
1075 {
1076 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001077 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1078 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1079 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1080 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001081 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001082 }
1083 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1084 break;
1085 }
1086 mask_view=DestroyCacheView(mask_view);
1087 mask_image->matte=MagickTrue;
1088 (void) SetImageClipMask(*image,mask_image);
1089 mask_image=DestroyImage(mask_image);
1090 InheritException(exception,&(*image)->exception);
1091 break;
1092 }
1093 if (LocaleCompare("clip-path",option+1) == 0)
1094 {
1095 (void) SyncImageSettings(mogrify_info,*image);
1096 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1097 MagickFalse);
1098 InheritException(exception,&(*image)->exception);
1099 break;
1100 }
1101 if (LocaleCompare("colorize",option+1) == 0)
1102 {
1103 /*
1104 Colorize the image.
1105 */
1106 (void) SyncImageSettings(mogrify_info,*image);
1107 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1108 exception);
1109 break;
1110 }
1111 if (LocaleCompare("color-matrix",option+1) == 0)
1112 {
1113 KernelInfo
1114 *kernel;
1115
1116 (void) SyncImageSettings(mogrify_info,*image);
1117 kernel=AcquireKernelInfo(argv[i+1]);
1118 if (kernel == (KernelInfo *) NULL)
1119 break;
1120 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1121 kernel=DestroyKernelInfo(kernel);
1122 break;
1123 }
1124 if (LocaleCompare("colors",option+1) == 0)
1125 {
1126 /*
1127 Reduce the number of colors in the image.
1128 */
1129 (void) SyncImageSettings(mogrify_info,*image);
1130 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1131 if (quantize_info->number_colors == 0)
1132 break;
1133 if (((*image)->storage_class == DirectClass) ||
1134 (*image)->colors > quantize_info->number_colors)
1135 (void) QuantizeImage(quantize_info,*image);
1136 else
1137 (void) CompressImageColormap(*image);
1138 InheritException(exception,&(*image)->exception);
1139 break;
1140 }
1141 if (LocaleCompare("colorspace",option+1) == 0)
1142 {
1143 ColorspaceType
1144 colorspace;
1145
1146 (void) SyncImageSettings(mogrify_info,*image);
1147 if (*option == '+')
1148 {
1149 (void) TransformImageColorspace(*image,RGBColorspace);
1150 InheritException(exception,&(*image)->exception);
1151 break;
1152 }
1153 colorspace=(ColorspaceType) ParseCommandOption(
1154 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1155 (void) TransformImageColorspace(*image,colorspace);
1156 InheritException(exception,&(*image)->exception);
1157 break;
1158 }
1159 if (LocaleCompare("contrast",option+1) == 0)
1160 {
1161 (void) SyncImageSettings(mogrify_info,*image);
1162 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1163 MagickFalse);
1164 InheritException(exception,&(*image)->exception);
1165 break;
1166 }
1167 if (LocaleCompare("contrast-stretch",option+1) == 0)
1168 {
1169 double
1170 black_point,
1171 white_point;
1172
1173 MagickStatusType
1174 flags;
1175
1176 /*
1177 Contrast stretch image.
1178 */
1179 (void) SyncImageSettings(mogrify_info,*image);
1180 flags=ParseGeometry(argv[i+1],&geometry_info);
1181 black_point=geometry_info.rho;
1182 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1183 black_point;
1184 if ((flags & PercentValue) != 0)
1185 {
1186 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1187 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1188 }
1189 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1190 white_point;
cristy50fbc382011-07-07 02:19:17 +00001191 (void) ContrastStretchImage(*image,black_point,white_point);
anthonydf8ebac2011-04-27 09:03:19 +00001192 InheritException(exception,&(*image)->exception);
1193 break;
1194 }
1195 if (LocaleCompare("convolve",option+1) == 0)
1196 {
anthonydf8ebac2011-04-27 09:03:19 +00001197 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001198 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001199
anthonydf8ebac2011-04-27 09:03:19 +00001200 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001201 kernel_info=AcquireKernelInfo(argv[i+1]);
1202 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001203 break;
cristy0a922382011-07-16 15:30:34 +00001204 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001205 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001206 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001207 break;
1208 }
1209 if (LocaleCompare("crop",option+1) == 0)
1210 {
1211 /*
1212 Crop a image to a smaller size
1213 */
1214 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001215 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001216 break;
1217 }
1218 if (LocaleCompare("cycle",option+1) == 0)
1219 {
1220 /*
1221 Cycle an image colormap.
1222 */
1223 (void) SyncImageSettings(mogrify_info,*image);
1224 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1225 InheritException(exception,&(*image)->exception);
1226 break;
1227 }
1228 break;
1229 }
1230 case 'd':
1231 {
1232 if (LocaleCompare("decipher",option+1) == 0)
1233 {
1234 StringInfo
1235 *passkey;
1236
1237 /*
1238 Decipher pixels.
1239 */
1240 (void) SyncImageSettings(mogrify_info,*image);
1241 passkey=FileToStringInfo(argv[i+1],~0,exception);
1242 if (passkey != (StringInfo *) NULL)
1243 {
1244 (void) PasskeyDecipherImage(*image,passkey,exception);
1245 passkey=DestroyStringInfo(passkey);
1246 }
1247 break;
1248 }
1249 if (LocaleCompare("density",option+1) == 0)
1250 {
1251 /*
1252 Set image density.
1253 */
1254 (void) CloneString(&draw_info->density,argv[i+1]);
1255 break;
1256 }
1257 if (LocaleCompare("depth",option+1) == 0)
1258 {
1259 (void) SyncImageSettings(mogrify_info,*image);
1260 if (*option == '+')
1261 {
1262 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1263 break;
1264 }
1265 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1266 break;
1267 }
1268 if (LocaleCompare("deskew",option+1) == 0)
1269 {
1270 double
1271 threshold;
1272
1273 /*
1274 Straighten the image.
1275 */
1276 (void) SyncImageSettings(mogrify_info,*image);
1277 if (*option == '+')
1278 threshold=40.0*QuantumRange/100.0;
1279 else
1280 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1281 mogrify_image=DeskewImage(*image,threshold,exception);
1282 break;
1283 }
1284 if (LocaleCompare("despeckle",option+1) == 0)
1285 {
1286 /*
1287 Reduce the speckles within an image.
1288 */
1289 (void) SyncImageSettings(mogrify_info,*image);
1290 mogrify_image=DespeckleImage(*image,exception);
1291 break;
1292 }
1293 if (LocaleCompare("display",option+1) == 0)
1294 {
1295 (void) CloneString(&draw_info->server_name,argv[i+1]);
1296 break;
1297 }
1298 if (LocaleCompare("distort",option+1) == 0)
1299 {
1300 char
1301 *args,
1302 token[MaxTextExtent];
1303
1304 const char
1305 *p;
1306
1307 DistortImageMethod
1308 method;
1309
1310 double
1311 *arguments;
1312
1313 register ssize_t
1314 x;
1315
1316 size_t
1317 number_arguments;
1318
1319 /*
1320 Distort image.
1321 */
1322 (void) SyncImageSettings(mogrify_info,*image);
1323 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1324 MagickFalse,argv[i+1]);
1325 if ( method == ResizeDistortion )
1326 {
1327 /* Special Case - Argument is actually a resize geometry!
1328 ** Convert that to an appropriate distortion argument array.
1329 */
1330 double
1331 resize_args[2];
1332 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1333 exception);
1334 resize_args[0]=(double)geometry.width;
1335 resize_args[1]=(double)geometry.height;
1336 mogrify_image=DistortImage(*image,method,(size_t)2,
1337 resize_args,MagickTrue,exception);
1338 break;
1339 }
1340 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1341 InheritException(exception,&(*image)->exception);
1342 if (args == (char *) NULL)
1343 break;
1344 p=(char *) args;
1345 for (x=0; *p != '\0'; x++)
1346 {
1347 GetMagickToken(p,&p,token);
1348 if (*token == ',')
1349 GetMagickToken(p,&p,token);
1350 }
1351 number_arguments=(size_t) x;
1352 arguments=(double *) AcquireQuantumMemory(number_arguments,
1353 sizeof(*arguments));
1354 if (arguments == (double *) NULL)
1355 ThrowWandFatalException(ResourceLimitFatalError,
1356 "MemoryAllocationFailed",(*image)->filename);
1357 (void) ResetMagickMemory(arguments,0,number_arguments*
1358 sizeof(*arguments));
1359 p=(char *) args;
1360 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1361 {
1362 GetMagickToken(p,&p,token);
1363 if (*token == ',')
1364 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001365 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001366 }
1367 args=DestroyString(args);
1368 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1369 (*option == '+') ? MagickTrue : MagickFalse,exception);
1370 arguments=(double *) RelinquishMagickMemory(arguments);
1371 break;
1372 }
1373 if (LocaleCompare("dither",option+1) == 0)
1374 {
1375 if (*option == '+')
1376 {
1377 quantize_info->dither=MagickFalse;
1378 break;
1379 }
1380 quantize_info->dither=MagickTrue;
1381 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1382 MagickDitherOptions,MagickFalse,argv[i+1]);
1383 if (quantize_info->dither_method == NoDitherMethod)
1384 quantize_info->dither=MagickFalse;
1385 break;
1386 }
1387 if (LocaleCompare("draw",option+1) == 0)
1388 {
1389 /*
1390 Draw image.
1391 */
1392 (void) SyncImageSettings(mogrify_info,*image);
1393 (void) CloneString(&draw_info->primitive,argv[i+1]);
1394 (void) DrawImage(*image,draw_info);
1395 InheritException(exception,&(*image)->exception);
1396 break;
1397 }
1398 break;
1399 }
1400 case 'e':
1401 {
1402 if (LocaleCompare("edge",option+1) == 0)
1403 {
1404 /*
1405 Enhance edges in the image.
1406 */
1407 (void) SyncImageSettings(mogrify_info,*image);
1408 flags=ParseGeometry(argv[i+1],&geometry_info);
1409 if ((flags & SigmaValue) == 0)
1410 geometry_info.sigma=1.0;
1411 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1412 break;
1413 }
1414 if (LocaleCompare("emboss",option+1) == 0)
1415 {
1416 /*
1417 Gaussian embossen image.
1418 */
1419 (void) SyncImageSettings(mogrify_info,*image);
1420 flags=ParseGeometry(argv[i+1],&geometry_info);
1421 if ((flags & SigmaValue) == 0)
1422 geometry_info.sigma=1.0;
1423 mogrify_image=EmbossImage(*image,geometry_info.rho,
1424 geometry_info.sigma,exception);
1425 break;
1426 }
1427 if (LocaleCompare("encipher",option+1) == 0)
1428 {
1429 StringInfo
1430 *passkey;
1431
1432 /*
1433 Encipher pixels.
1434 */
1435 (void) SyncImageSettings(mogrify_info,*image);
1436 passkey=FileToStringInfo(argv[i+1],~0,exception);
1437 if (passkey != (StringInfo *) NULL)
1438 {
1439 (void) PasskeyEncipherImage(*image,passkey,exception);
1440 passkey=DestroyStringInfo(passkey);
1441 }
1442 break;
1443 }
1444 if (LocaleCompare("encoding",option+1) == 0)
1445 {
1446 (void) CloneString(&draw_info->encoding,argv[i+1]);
1447 break;
1448 }
1449 if (LocaleCompare("enhance",option+1) == 0)
1450 {
1451 /*
1452 Enhance image.
1453 */
1454 (void) SyncImageSettings(mogrify_info,*image);
1455 mogrify_image=EnhanceImage(*image,exception);
1456 break;
1457 }
1458 if (LocaleCompare("equalize",option+1) == 0)
1459 {
1460 /*
1461 Equalize image.
1462 */
1463 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00001464 (void) EqualizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001465 InheritException(exception,&(*image)->exception);
1466 break;
1467 }
1468 if (LocaleCompare("evaluate",option+1) == 0)
1469 {
1470 double
1471 constant;
1472
1473 MagickEvaluateOperator
1474 op;
1475
1476 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001477 op=(MagickEvaluateOperator) ParseCommandOption(
1478 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001479 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001480 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001481 break;
1482 }
1483 if (LocaleCompare("extent",option+1) == 0)
1484 {
1485 /*
1486 Set the image extent.
1487 */
1488 (void) SyncImageSettings(mogrify_info,*image);
1489 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1490 if (geometry.width == 0)
1491 geometry.width=(*image)->columns;
1492 if (geometry.height == 0)
1493 geometry.height=(*image)->rows;
1494 mogrify_image=ExtentImage(*image,&geometry,exception);
1495 break;
1496 }
1497 break;
1498 }
1499 case 'f':
1500 {
1501 if (LocaleCompare("family",option+1) == 0)
1502 {
1503 if (*option == '+')
1504 {
1505 if (draw_info->family != (char *) NULL)
1506 draw_info->family=DestroyString(draw_info->family);
1507 break;
1508 }
1509 (void) CloneString(&draw_info->family,argv[i+1]);
1510 break;
1511 }
1512 if (LocaleCompare("features",option+1) == 0)
1513 {
1514 if (*option == '+')
1515 {
1516 (void) DeleteImageArtifact(*image,"identify:features");
1517 break;
1518 }
1519 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1520 break;
1521 }
1522 if (LocaleCompare("fill",option+1) == 0)
1523 {
1524 ExceptionInfo
1525 *sans;
1526
cristy4c08aed2011-07-01 19:47:50 +00001527 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001528 if (*option == '+')
1529 {
1530 (void) QueryMagickColor("none",&fill,exception);
1531 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1532 if (draw_info->fill_pattern != (Image *) NULL)
1533 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1534 break;
1535 }
1536 sans=AcquireExceptionInfo();
1537 (void) QueryMagickColor(argv[i+1],&fill,sans);
1538 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1539 sans=DestroyExceptionInfo(sans);
1540 if (status == MagickFalse)
1541 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1542 exception);
1543 break;
1544 }
1545 if (LocaleCompare("flip",option+1) == 0)
1546 {
1547 /*
1548 Flip image scanlines.
1549 */
1550 (void) SyncImageSettings(mogrify_info,*image);
1551 mogrify_image=FlipImage(*image,exception);
1552 break;
1553 }
anthonydf8ebac2011-04-27 09:03:19 +00001554 if (LocaleCompare("floodfill",option+1) == 0)
1555 {
cristy4c08aed2011-07-01 19:47:50 +00001556 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001557 target;
1558
1559 /*
1560 Floodfill image.
1561 */
1562 (void) SyncImageSettings(mogrify_info,*image);
1563 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1564 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001565 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1566 geometry.y,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00001567 InheritException(exception,&(*image)->exception);
1568 break;
1569 }
anthony3d2f4862011-05-01 13:48:16 +00001570 if (LocaleCompare("flop",option+1) == 0)
1571 {
1572 /*
1573 Flop image scanlines.
1574 */
1575 (void) SyncImageSettings(mogrify_info,*image);
1576 mogrify_image=FlopImage(*image,exception);
1577 break;
1578 }
anthonydf8ebac2011-04-27 09:03:19 +00001579 if (LocaleCompare("font",option+1) == 0)
1580 {
1581 if (*option == '+')
1582 {
1583 if (draw_info->font != (char *) NULL)
1584 draw_info->font=DestroyString(draw_info->font);
1585 break;
1586 }
1587 (void) CloneString(&draw_info->font,argv[i+1]);
1588 break;
1589 }
1590 if (LocaleCompare("format",option+1) == 0)
1591 {
1592 format=argv[i+1];
1593 break;
1594 }
1595 if (LocaleCompare("frame",option+1) == 0)
1596 {
1597 FrameInfo
1598 frame_info;
1599
1600 /*
1601 Surround image with an ornamental border.
1602 */
1603 (void) SyncImageSettings(mogrify_info,*image);
1604 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1605 frame_info.width=geometry.width;
1606 frame_info.height=geometry.height;
1607 if ((flags & HeightValue) == 0)
1608 frame_info.height=geometry.width;
1609 frame_info.outer_bevel=geometry.x;
1610 frame_info.inner_bevel=geometry.y;
1611 frame_info.x=(ssize_t) frame_info.width;
1612 frame_info.y=(ssize_t) frame_info.height;
1613 frame_info.width=(*image)->columns+2*frame_info.width;
1614 frame_info.height=(*image)->rows+2*frame_info.height;
1615 mogrify_image=FrameImage(*image,&frame_info,exception);
1616 break;
1617 }
1618 if (LocaleCompare("function",option+1) == 0)
1619 {
1620 char
1621 *arguments,
1622 token[MaxTextExtent];
1623
1624 const char
1625 *p;
1626
1627 double
1628 *parameters;
1629
1630 MagickFunction
1631 function;
1632
1633 register ssize_t
1634 x;
1635
1636 size_t
1637 number_parameters;
1638
1639 /*
1640 Function Modify Image Values
1641 */
1642 (void) SyncImageSettings(mogrify_info,*image);
1643 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1644 MagickFalse,argv[i+1]);
1645 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1646 InheritException(exception,&(*image)->exception);
1647 if (arguments == (char *) NULL)
1648 break;
1649 p=(char *) arguments;
1650 for (x=0; *p != '\0'; x++)
1651 {
1652 GetMagickToken(p,&p,token);
1653 if (*token == ',')
1654 GetMagickToken(p,&p,token);
1655 }
1656 number_parameters=(size_t) x;
1657 parameters=(double *) AcquireQuantumMemory(number_parameters,
1658 sizeof(*parameters));
1659 if (parameters == (double *) NULL)
1660 ThrowWandFatalException(ResourceLimitFatalError,
1661 "MemoryAllocationFailed",(*image)->filename);
1662 (void) ResetMagickMemory(parameters,0,number_parameters*
1663 sizeof(*parameters));
1664 p=(char *) arguments;
1665 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1666 {
1667 GetMagickToken(p,&p,token);
1668 if (*token == ',')
1669 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001670 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001671 }
1672 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001673 (void) FunctionImage(*image,function,number_parameters,parameters,
1674 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001675 parameters=(double *) RelinquishMagickMemory(parameters);
1676 break;
1677 }
1678 break;
1679 }
1680 case 'g':
1681 {
1682 if (LocaleCompare("gamma",option+1) == 0)
1683 {
1684 /*
1685 Gamma image.
1686 */
1687 (void) SyncImageSettings(mogrify_info,*image);
1688 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001689 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001690 else
1691 {
cristy50fbc382011-07-07 02:19:17 +00001692 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1693 (char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001694 InheritException(exception,&(*image)->exception);
1695 }
1696 break;
1697 }
1698 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1699 (LocaleCompare("gaussian",option+1) == 0))
1700 {
1701 /*
1702 Gaussian blur image.
1703 */
1704 (void) SyncImageSettings(mogrify_info,*image);
1705 flags=ParseGeometry(argv[i+1],&geometry_info);
1706 if ((flags & SigmaValue) == 0)
1707 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001708 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1709 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001710 break;
1711 }
1712 if (LocaleCompare("geometry",option+1) == 0)
1713 {
1714 /*
1715 Record Image offset, Resize last image.
1716 */
1717 (void) SyncImageSettings(mogrify_info,*image);
1718 if (*option == '+')
1719 {
1720 if ((*image)->geometry != (char *) NULL)
1721 (*image)->geometry=DestroyString((*image)->geometry);
1722 break;
1723 }
1724 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1725 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1726 (void) CloneString(&(*image)->geometry,argv[i+1]);
1727 else
1728 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1729 (*image)->filter,(*image)->blur,exception);
1730 break;
1731 }
1732 if (LocaleCompare("gravity",option+1) == 0)
1733 {
1734 if (*option == '+')
1735 {
1736 draw_info->gravity=UndefinedGravity;
1737 break;
1738 }
1739 draw_info->gravity=(GravityType) ParseCommandOption(
1740 MagickGravityOptions,MagickFalse,argv[i+1]);
1741 break;
1742 }
1743 break;
1744 }
1745 case 'h':
1746 {
1747 if (LocaleCompare("highlight-color",option+1) == 0)
1748 {
1749 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1750 break;
1751 }
1752 break;
1753 }
1754 case 'i':
1755 {
1756 if (LocaleCompare("identify",option+1) == 0)
1757 {
1758 char
1759 *text;
1760
1761 (void) SyncImageSettings(mogrify_info,*image);
1762 if (format == (char *) NULL)
1763 {
1764 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1765 InheritException(exception,&(*image)->exception);
1766 break;
1767 }
1768 text=InterpretImageProperties(mogrify_info,*image,format);
1769 InheritException(exception,&(*image)->exception);
1770 if (text == (char *) NULL)
1771 break;
1772 (void) fputs(text,stdout);
1773 (void) fputc('\n',stdout);
1774 text=DestroyString(text);
1775 break;
1776 }
1777 if (LocaleCompare("implode",option+1) == 0)
1778 {
1779 /*
1780 Implode image.
1781 */
1782 (void) SyncImageSettings(mogrify_info,*image);
1783 (void) ParseGeometry(argv[i+1],&geometry_info);
1784 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1785 break;
1786 }
1787 if (LocaleCompare("interline-spacing",option+1) == 0)
1788 {
1789 if (*option == '+')
1790 (void) ParseGeometry("0",&geometry_info);
1791 else
1792 (void) ParseGeometry(argv[i+1],&geometry_info);
1793 draw_info->interline_spacing=geometry_info.rho;
1794 break;
1795 }
1796 if (LocaleCompare("interword-spacing",option+1) == 0)
1797 {
1798 if (*option == '+')
1799 (void) ParseGeometry("0",&geometry_info);
1800 else
1801 (void) ParseGeometry(argv[i+1],&geometry_info);
1802 draw_info->interword_spacing=geometry_info.rho;
1803 break;
1804 }
1805 break;
1806 }
1807 case 'k':
1808 {
1809 if (LocaleCompare("kerning",option+1) == 0)
1810 {
1811 if (*option == '+')
1812 (void) ParseGeometry("0",&geometry_info);
1813 else
1814 (void) ParseGeometry(argv[i+1],&geometry_info);
1815 draw_info->kerning=geometry_info.rho;
1816 break;
1817 }
1818 break;
1819 }
1820 case 'l':
1821 {
1822 if (LocaleCompare("lat",option+1) == 0)
1823 {
1824 /*
1825 Local adaptive threshold image.
1826 */
1827 (void) SyncImageSettings(mogrify_info,*image);
1828 flags=ParseGeometry(argv[i+1],&geometry_info);
1829 if ((flags & PercentValue) != 0)
1830 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1831 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001832 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001833 geometry_info.xi,exception);
1834 break;
1835 }
1836 if (LocaleCompare("level",option+1) == 0)
1837 {
1838 MagickRealType
1839 black_point,
1840 gamma,
1841 white_point;
1842
1843 MagickStatusType
1844 flags;
1845
1846 /*
1847 Parse levels.
1848 */
1849 (void) SyncImageSettings(mogrify_info,*image);
1850 flags=ParseGeometry(argv[i+1],&geometry_info);
1851 black_point=geometry_info.rho;
1852 white_point=(MagickRealType) QuantumRange;
1853 if ((flags & SigmaValue) != 0)
1854 white_point=geometry_info.sigma;
1855 gamma=1.0;
1856 if ((flags & XiValue) != 0)
1857 gamma=geometry_info.xi;
1858 if ((flags & PercentValue) != 0)
1859 {
1860 black_point*=(MagickRealType) (QuantumRange/100.0);
1861 white_point*=(MagickRealType) (QuantumRange/100.0);
1862 }
1863 if ((flags & SigmaValue) == 0)
1864 white_point=(MagickRealType) QuantumRange-black_point;
1865 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy50fbc382011-07-07 02:19:17 +00001866 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001867 else
cristyf89cb1d2011-07-07 01:24:37 +00001868 (void) LevelImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001869 InheritException(exception,&(*image)->exception);
1870 break;
1871 }
1872 if (LocaleCompare("level-colors",option+1) == 0)
1873 {
1874 char
1875 token[MaxTextExtent];
1876
1877 const char
1878 *p;
1879
cristy4c08aed2011-07-01 19:47:50 +00001880 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001881 black_point,
1882 white_point;
1883
1884 p=(const char *) argv[i+1];
1885 GetMagickToken(p,&p,token); /* get black point color */
1886 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1887 (void) QueryMagickColor(token,&black_point,exception);
1888 else
1889 (void) QueryMagickColor("#000000",&black_point,exception);
1890 if (isalpha((int) token[0]) || (token[0] == '#'))
1891 GetMagickToken(p,&p,token);
1892 if (*token == '\0')
1893 white_point=black_point; /* set everything to that color */
1894 else
1895 {
1896 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1897 GetMagickToken(p,&p,token); /* Get white point color. */
1898 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1899 (void) QueryMagickColor(token,&white_point,exception);
1900 else
1901 (void) QueryMagickColor("#ffffff",&white_point,exception);
1902 }
cristy490408a2011-07-07 14:42:05 +00001903 (void) LevelImageColors(*image,&black_point,&white_point,
1904 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001905 break;
1906 }
1907 if (LocaleCompare("linear-stretch",option+1) == 0)
1908 {
1909 double
1910 black_point,
1911 white_point;
1912
1913 MagickStatusType
1914 flags;
1915
1916 (void) SyncImageSettings(mogrify_info,*image);
1917 flags=ParseGeometry(argv[i+1],&geometry_info);
1918 black_point=geometry_info.rho;
1919 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1920 if ((flags & SigmaValue) != 0)
1921 white_point=geometry_info.sigma;
1922 if ((flags & PercentValue) != 0)
1923 {
1924 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1925 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1926 }
1927 if ((flags & SigmaValue) == 0)
1928 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1929 black_point;
1930 (void) LinearStretchImage(*image,black_point,white_point);
1931 InheritException(exception,&(*image)->exception);
1932 break;
1933 }
1934 if (LocaleCompare("linewidth",option+1) == 0)
1935 {
cristyc1acd842011-05-19 23:05:47 +00001936 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1937 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001938 break;
1939 }
1940 if (LocaleCompare("liquid-rescale",option+1) == 0)
1941 {
1942 /*
1943 Liquid rescale image.
1944 */
1945 (void) SyncImageSettings(mogrify_info,*image);
1946 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1947 if ((flags & XValue) == 0)
1948 geometry.x=1;
1949 if ((flags & YValue) == 0)
1950 geometry.y=0;
1951 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1952 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1953 break;
1954 }
1955 if (LocaleCompare("lowlight-color",option+1) == 0)
1956 {
1957 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1958 break;
1959 }
1960 break;
1961 }
1962 case 'm':
1963 {
1964 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001965 {
cristy3ed852e2009-09-05 21:47:34 +00001966 Image
anthonydf8ebac2011-04-27 09:03:19 +00001967 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001968
anthonydf8ebac2011-04-27 09:03:19 +00001969 /*
1970 Transform image colors to match this set of colors.
1971 */
1972 (void) SyncImageSettings(mogrify_info,*image);
1973 if (*option == '+')
1974 break;
1975 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1976 if (remap_image == (Image *) NULL)
1977 break;
1978 (void) RemapImage(quantize_info,*image,remap_image);
1979 InheritException(exception,&(*image)->exception);
1980 remap_image=DestroyImage(remap_image);
1981 break;
1982 }
1983 if (LocaleCompare("mask",option+1) == 0)
1984 {
1985 Image
1986 *mask;
1987
1988 (void) SyncImageSettings(mogrify_info,*image);
1989 if (*option == '+')
1990 {
1991 /*
1992 Remove a mask.
1993 */
1994 (void) SetImageMask(*image,(Image *) NULL);
1995 InheritException(exception,&(*image)->exception);
1996 break;
1997 }
1998 /*
1999 Set the image mask.
2000 */
2001 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2002 if (mask == (Image *) NULL)
2003 break;
2004 (void) SetImageMask(*image,mask);
2005 mask=DestroyImage(mask);
2006 InheritException(exception,&(*image)->exception);
2007 break;
2008 }
2009 if (LocaleCompare("matte",option+1) == 0)
2010 {
2011 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2012 SetAlphaChannel : DeactivateAlphaChannel );
2013 InheritException(exception,&(*image)->exception);
2014 break;
2015 }
2016 if (LocaleCompare("median",option+1) == 0)
2017 {
2018 /*
2019 Median filter image.
2020 */
2021 (void) SyncImageSettings(mogrify_info,*image);
2022 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002023 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2024 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002025 break;
2026 }
2027 if (LocaleCompare("mode",option+1) == 0)
2028 {
2029 /*
2030 Mode image.
2031 */
2032 (void) SyncImageSettings(mogrify_info,*image);
2033 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002034 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2035 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002036 break;
2037 }
2038 if (LocaleCompare("modulate",option+1) == 0)
2039 {
2040 (void) SyncImageSettings(mogrify_info,*image);
2041 (void) ModulateImage(*image,argv[i+1]);
2042 InheritException(exception,&(*image)->exception);
2043 break;
2044 }
2045 if (LocaleCompare("monitor",option+1) == 0)
2046 {
2047 if (*option == '+')
2048 {
2049 (void) SetImageProgressMonitor(*image,
2050 (MagickProgressMonitor) NULL,(void *) NULL);
2051 break;
2052 }
2053 (void) SetImageProgressMonitor(*image,MonitorProgress,
2054 (void *) NULL);
2055 break;
2056 }
2057 if (LocaleCompare("monochrome",option+1) == 0)
2058 {
2059 (void) SyncImageSettings(mogrify_info,*image);
2060 (void) SetImageType(*image,BilevelType);
2061 InheritException(exception,&(*image)->exception);
2062 break;
2063 }
2064 if (LocaleCompare("morphology",option+1) == 0)
2065 {
2066 char
2067 token[MaxTextExtent];
2068
2069 const char
2070 *p;
2071
2072 KernelInfo
2073 *kernel;
2074
2075 MorphologyMethod
2076 method;
2077
2078 ssize_t
2079 iterations;
2080
2081 /*
2082 Morphological Image Operation
2083 */
2084 (void) SyncImageSettings(mogrify_info,*image);
2085 p=argv[i+1];
2086 GetMagickToken(p,&p,token);
2087 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2088 MagickFalse,token);
2089 iterations=1L;
2090 GetMagickToken(p,&p,token);
2091 if ((*p == ':') || (*p == ','))
2092 GetMagickToken(p,&p,token);
2093 if ((*p != '\0'))
2094 iterations=(ssize_t) StringToLong(p);
2095 kernel=AcquireKernelInfo(argv[i+2]);
2096 if (kernel == (KernelInfo *) NULL)
2097 {
2098 (void) ThrowMagickException(exception,GetMagickModule(),
2099 OptionError,"UnabletoParseKernel","morphology");
2100 status=MagickFalse;
2101 break;
2102 }
cristyf4ad9df2011-07-08 16:49:03 +00002103 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2104 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002105 kernel=DestroyKernelInfo(kernel);
2106 break;
2107 }
2108 if (LocaleCompare("motion-blur",option+1) == 0)
2109 {
2110 /*
2111 Motion blur image.
2112 */
2113 (void) SyncImageSettings(mogrify_info,*image);
2114 flags=ParseGeometry(argv[i+1],&geometry_info);
2115 if ((flags & SigmaValue) == 0)
2116 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002117 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2118 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002119 break;
2120 }
2121 break;
2122 }
2123 case 'n':
2124 {
2125 if (LocaleCompare("negate",option+1) == 0)
2126 {
2127 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002128 (void) NegateImage(*image,*option == '+' ? MagickTrue :
2129 MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00002130 InheritException(exception,&(*image)->exception);
2131 break;
2132 }
2133 if (LocaleCompare("noise",option+1) == 0)
2134 {
2135 (void) SyncImageSettings(mogrify_info,*image);
2136 if (*option == '-')
2137 {
2138 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002139 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2140 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002141 }
2142 else
2143 {
2144 NoiseType
2145 noise;
2146
2147 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2148 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002149 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002150 }
2151 break;
2152 }
2153 if (LocaleCompare("normalize",option+1) == 0)
2154 {
2155 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002156 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002157 InheritException(exception,&(*image)->exception);
2158 break;
2159 }
2160 break;
2161 }
2162 case 'o':
2163 {
2164 if (LocaleCompare("opaque",option+1) == 0)
2165 {
cristy4c08aed2011-07-01 19:47:50 +00002166 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002167 target;
2168
2169 (void) SyncImageSettings(mogrify_info,*image);
2170 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002171 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2172 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002173 break;
2174 }
2175 if (LocaleCompare("ordered-dither",option+1) == 0)
2176 {
2177 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002178 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002179 break;
2180 }
2181 break;
2182 }
2183 case 'p':
2184 {
2185 if (LocaleCompare("paint",option+1) == 0)
2186 {
anthonydf8ebac2011-04-27 09:03:19 +00002187 (void) SyncImageSettings(mogrify_info,*image);
2188 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002189 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002190 break;
2191 }
2192 if (LocaleCompare("pen",option+1) == 0)
2193 {
2194 if (*option == '+')
2195 {
2196 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2197 break;
2198 }
2199 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2200 break;
2201 }
2202 if (LocaleCompare("pointsize",option+1) == 0)
2203 {
2204 if (*option == '+')
2205 (void) ParseGeometry("12",&geometry_info);
2206 else
2207 (void) ParseGeometry(argv[i+1],&geometry_info);
2208 draw_info->pointsize=geometry_info.rho;
2209 break;
2210 }
2211 if (LocaleCompare("polaroid",option+1) == 0)
2212 {
2213 double
2214 angle;
2215
2216 RandomInfo
2217 *random_info;
2218
2219 /*
2220 Simulate a Polaroid picture.
2221 */
2222 (void) SyncImageSettings(mogrify_info,*image);
2223 random_info=AcquireRandomInfo();
2224 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2225 random_info=DestroyRandomInfo(random_info);
2226 if (*option == '-')
2227 {
2228 SetGeometryInfo(&geometry_info);
2229 flags=ParseGeometry(argv[i+1],&geometry_info);
2230 angle=geometry_info.rho;
2231 }
2232 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2233 break;
2234 }
2235 if (LocaleCompare("posterize",option+1) == 0)
2236 {
2237 /*
2238 Posterize image.
2239 */
2240 (void) SyncImageSettings(mogrify_info,*image);
2241 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2242 quantize_info->dither);
2243 InheritException(exception,&(*image)->exception);
2244 break;
2245 }
2246 if (LocaleCompare("preview",option+1) == 0)
2247 {
2248 PreviewType
2249 preview_type;
2250
2251 /*
2252 Preview image.
2253 */
2254 (void) SyncImageSettings(mogrify_info,*image);
2255 if (*option == '+')
2256 preview_type=UndefinedPreview;
2257 else
2258 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2259 MagickFalse,argv[i+1]);
2260 mogrify_image=PreviewImage(*image,preview_type,exception);
2261 break;
2262 }
2263 if (LocaleCompare("profile",option+1) == 0)
2264 {
2265 const char
2266 *name;
2267
2268 const StringInfo
2269 *profile;
2270
2271 Image
2272 *profile_image;
2273
2274 ImageInfo
2275 *profile_info;
2276
2277 (void) SyncImageSettings(mogrify_info,*image);
2278 if (*option == '+')
2279 {
2280 /*
2281 Remove a profile from the image.
2282 */
2283 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2284 NULL,0,MagickTrue);
2285 InheritException(exception,&(*image)->exception);
2286 break;
2287 }
2288 /*
2289 Associate a profile with the image.
2290 */
2291 profile_info=CloneImageInfo(mogrify_info);
2292 profile=GetImageProfile(*image,"iptc");
2293 if (profile != (StringInfo *) NULL)
2294 profile_info->profile=(void *) CloneStringInfo(profile);
2295 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2296 profile_info=DestroyImageInfo(profile_info);
2297 if (profile_image == (Image *) NULL)
2298 {
2299 StringInfo
2300 *profile;
2301
2302 profile_info=CloneImageInfo(mogrify_info);
2303 (void) CopyMagickString(profile_info->filename,argv[i+1],
2304 MaxTextExtent);
2305 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2306 if (profile != (StringInfo *) NULL)
2307 {
2308 (void) ProfileImage(*image,profile_info->magick,
2309 GetStringInfoDatum(profile),(size_t)
2310 GetStringInfoLength(profile),MagickFalse);
2311 profile=DestroyStringInfo(profile);
2312 }
2313 profile_info=DestroyImageInfo(profile_info);
2314 break;
2315 }
2316 ResetImageProfileIterator(profile_image);
2317 name=GetNextImageProfile(profile_image);
2318 while (name != (const char *) NULL)
2319 {
2320 profile=GetImageProfile(profile_image,name);
2321 if (profile != (StringInfo *) NULL)
2322 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2323 (size_t) GetStringInfoLength(profile),MagickFalse);
2324 name=GetNextImageProfile(profile_image);
2325 }
2326 profile_image=DestroyImage(profile_image);
2327 break;
2328 }
2329 break;
2330 }
2331 case 'q':
2332 {
2333 if (LocaleCompare("quantize",option+1) == 0)
2334 {
2335 if (*option == '+')
2336 {
2337 quantize_info->colorspace=UndefinedColorspace;
2338 break;
2339 }
2340 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2341 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2342 break;
2343 }
2344 break;
2345 }
2346 case 'r':
2347 {
2348 if (LocaleCompare("radial-blur",option+1) == 0)
2349 {
2350 /*
2351 Radial blur image.
2352 */
2353 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002354 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2355 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002356 break;
2357 }
2358 if (LocaleCompare("raise",option+1) == 0)
2359 {
2360 /*
2361 Surround image with a raise of solid color.
2362 */
2363 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2364 if ((flags & SigmaValue) == 0)
2365 geometry.height=geometry.width;
2366 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2367 MagickFalse);
2368 InheritException(exception,&(*image)->exception);
2369 break;
2370 }
2371 if (LocaleCompare("random-threshold",option+1) == 0)
2372 {
2373 /*
2374 Threshold image.
2375 */
2376 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002377 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002378 break;
2379 }
2380 if (LocaleCompare("recolor",option+1) == 0)
2381 {
2382 KernelInfo
2383 *kernel;
2384
2385 (void) SyncImageSettings(mogrify_info,*image);
2386 kernel=AcquireKernelInfo(argv[i+1]);
2387 if (kernel == (KernelInfo *) NULL)
2388 break;
2389 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2390 kernel=DestroyKernelInfo(kernel);
2391 break;
2392 }
2393 if (LocaleCompare("region",option+1) == 0)
2394 {
2395 (void) SyncImageSettings(mogrify_info,*image);
2396 if (region_image != (Image *) NULL)
2397 {
2398 /*
2399 Composite region.
2400 */
2401 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002402 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2403 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002404 InheritException(exception,&region_image->exception);
2405 *image=DestroyImage(*image);
2406 *image=region_image;
2407 region_image = (Image *) NULL;
2408 }
2409 if (*option == '+')
2410 break;
2411 /*
2412 Apply transformations to a selected region of the image.
2413 */
cristy3ed852e2009-09-05 21:47:34 +00002414 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2415 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002416 mogrify_image=CropImage(*image,&region_geometry,exception);
2417 if (mogrify_image == (Image *) NULL)
2418 break;
2419 region_image=(*image);
2420 *image=mogrify_image;
2421 mogrify_image=(Image *) NULL;
2422 break;
cristy3ed852e2009-09-05 21:47:34 +00002423 }
anthonydf8ebac2011-04-27 09:03:19 +00002424 if (LocaleCompare("render",option+1) == 0)
2425 {
2426 (void) SyncImageSettings(mogrify_info,*image);
2427 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2428 break;
2429 }
2430 if (LocaleCompare("remap",option+1) == 0)
2431 {
2432 Image
2433 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002434
anthonydf8ebac2011-04-27 09:03:19 +00002435 /*
2436 Transform image colors to match this set of colors.
2437 */
2438 (void) SyncImageSettings(mogrify_info,*image);
2439 if (*option == '+')
2440 break;
2441 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2442 if (remap_image == (Image *) NULL)
2443 break;
2444 (void) RemapImage(quantize_info,*image,remap_image);
2445 InheritException(exception,&(*image)->exception);
2446 remap_image=DestroyImage(remap_image);
2447 break;
2448 }
2449 if (LocaleCompare("repage",option+1) == 0)
2450 {
2451 if (*option == '+')
2452 {
2453 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2454 break;
2455 }
2456 (void) ResetImagePage(*image,argv[i+1]);
2457 InheritException(exception,&(*image)->exception);
2458 break;
2459 }
2460 if (LocaleCompare("resample",option+1) == 0)
2461 {
2462 /*
2463 Resample image.
2464 */
2465 (void) SyncImageSettings(mogrify_info,*image);
2466 flags=ParseGeometry(argv[i+1],&geometry_info);
2467 if ((flags & SigmaValue) == 0)
2468 geometry_info.sigma=geometry_info.rho;
2469 mogrify_image=ResampleImage(*image,geometry_info.rho,
2470 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2471 break;
2472 }
2473 if (LocaleCompare("resize",option+1) == 0)
2474 {
2475 /*
2476 Resize image.
2477 */
2478 (void) SyncImageSettings(mogrify_info,*image);
2479 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2480 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2481 (*image)->filter,(*image)->blur,exception);
2482 break;
2483 }
2484 if (LocaleCompare("roll",option+1) == 0)
2485 {
2486 /*
2487 Roll image.
2488 */
2489 (void) SyncImageSettings(mogrify_info,*image);
2490 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2491 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2492 break;
2493 }
2494 if (LocaleCompare("rotate",option+1) == 0)
2495 {
2496 char
2497 *geometry;
2498
2499 /*
2500 Check for conditional image rotation.
2501 */
2502 (void) SyncImageSettings(mogrify_info,*image);
2503 if (strchr(argv[i+1],'>') != (char *) NULL)
2504 if ((*image)->columns <= (*image)->rows)
2505 break;
2506 if (strchr(argv[i+1],'<') != (char *) NULL)
2507 if ((*image)->columns >= (*image)->rows)
2508 break;
2509 /*
2510 Rotate image.
2511 */
2512 geometry=ConstantString(argv[i+1]);
2513 (void) SubstituteString(&geometry,">","");
2514 (void) SubstituteString(&geometry,"<","");
2515 (void) ParseGeometry(geometry,&geometry_info);
2516 geometry=DestroyString(geometry);
2517 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2518 break;
2519 }
2520 break;
2521 }
2522 case 's':
2523 {
2524 if (LocaleCompare("sample",option+1) == 0)
2525 {
2526 /*
2527 Sample image with pixel replication.
2528 */
2529 (void) SyncImageSettings(mogrify_info,*image);
2530 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2531 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2532 exception);
2533 break;
2534 }
2535 if (LocaleCompare("scale",option+1) == 0)
2536 {
2537 /*
2538 Resize image.
2539 */
2540 (void) SyncImageSettings(mogrify_info,*image);
2541 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2542 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2543 exception);
2544 break;
2545 }
2546 if (LocaleCompare("selective-blur",option+1) == 0)
2547 {
2548 /*
2549 Selectively blur pixels within a contrast threshold.
2550 */
2551 (void) SyncImageSettings(mogrify_info,*image);
2552 flags=ParseGeometry(argv[i+1],&geometry_info);
2553 if ((flags & PercentValue) != 0)
2554 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002555 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2556 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002557 break;
2558 }
2559 if (LocaleCompare("separate",option+1) == 0)
2560 {
2561 /*
2562 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002563 */
2564 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002565 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002566 break;
2567 }
2568 if (LocaleCompare("sepia-tone",option+1) == 0)
2569 {
2570 double
2571 threshold;
2572
2573 /*
2574 Sepia-tone image.
2575 */
2576 (void) SyncImageSettings(mogrify_info,*image);
2577 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2578 mogrify_image=SepiaToneImage(*image,threshold,exception);
2579 break;
2580 }
2581 if (LocaleCompare("segment",option+1) == 0)
2582 {
2583 /*
2584 Segment image.
2585 */
2586 (void) SyncImageSettings(mogrify_info,*image);
2587 flags=ParseGeometry(argv[i+1],&geometry_info);
2588 if ((flags & SigmaValue) == 0)
2589 geometry_info.sigma=1.0;
2590 (void) SegmentImage(*image,(*image)->colorspace,
2591 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2592 InheritException(exception,&(*image)->exception);
2593 break;
2594 }
2595 if (LocaleCompare("set",option+1) == 0)
2596 {
2597 char
2598 *value;
2599
2600 /*
2601 Set image option.
2602 */
2603 if (*option == '+')
2604 {
2605 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2606 (void) DeleteImageRegistry(argv[i+1]+9);
2607 else
2608 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2609 {
2610 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2611 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2612 }
2613 else
2614 (void) DeleteImageProperty(*image,argv[i+1]);
2615 break;
2616 }
2617 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2618 if (value == (char *) NULL)
2619 break;
2620 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2621 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2622 exception);
2623 else
2624 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2625 {
2626 (void) SetImageOption(image_info,argv[i+1]+7,value);
2627 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2628 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2629 }
2630 else
2631 (void) SetImageProperty(*image,argv[i+1],value);
2632 value=DestroyString(value);
2633 break;
2634 }
2635 if (LocaleCompare("shade",option+1) == 0)
2636 {
2637 /*
2638 Shade image.
2639 */
2640 (void) SyncImageSettings(mogrify_info,*image);
2641 flags=ParseGeometry(argv[i+1],&geometry_info);
2642 if ((flags & SigmaValue) == 0)
2643 geometry_info.sigma=1.0;
2644 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2645 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2646 break;
2647 }
2648 if (LocaleCompare("shadow",option+1) == 0)
2649 {
2650 /*
2651 Shadow image.
2652 */
2653 (void) SyncImageSettings(mogrify_info,*image);
2654 flags=ParseGeometry(argv[i+1],&geometry_info);
2655 if ((flags & SigmaValue) == 0)
2656 geometry_info.sigma=1.0;
2657 if ((flags & XiValue) == 0)
2658 geometry_info.xi=4.0;
2659 if ((flags & PsiValue) == 0)
2660 geometry_info.psi=4.0;
2661 mogrify_image=ShadowImage(*image,geometry_info.rho,
2662 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2663 ceil(geometry_info.psi-0.5),exception);
2664 break;
2665 }
2666 if (LocaleCompare("sharpen",option+1) == 0)
2667 {
2668 /*
2669 Sharpen image.
2670 */
2671 (void) SyncImageSettings(mogrify_info,*image);
2672 flags=ParseGeometry(argv[i+1],&geometry_info);
2673 if ((flags & SigmaValue) == 0)
2674 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002675 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002676 geometry_info.sigma,exception);
2677 break;
2678 }
2679 if (LocaleCompare("shave",option+1) == 0)
2680 {
2681 /*
2682 Shave the image edges.
2683 */
2684 (void) SyncImageSettings(mogrify_info,*image);
2685 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2686 mogrify_image=ShaveImage(*image,&geometry,exception);
2687 break;
2688 }
2689 if (LocaleCompare("shear",option+1) == 0)
2690 {
2691 /*
2692 Shear image.
2693 */
2694 (void) SyncImageSettings(mogrify_info,*image);
2695 flags=ParseGeometry(argv[i+1],&geometry_info);
2696 if ((flags & SigmaValue) == 0)
2697 geometry_info.sigma=geometry_info.rho;
2698 mogrify_image=ShearImage(*image,geometry_info.rho,
2699 geometry_info.sigma,exception);
2700 break;
2701 }
2702 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2703 {
2704 /*
2705 Sigmoidal non-linearity contrast control.
2706 */
2707 (void) SyncImageSettings(mogrify_info,*image);
2708 flags=ParseGeometry(argv[i+1],&geometry_info);
2709 if ((flags & SigmaValue) == 0)
2710 geometry_info.sigma=(double) QuantumRange/2.0;
2711 if ((flags & PercentValue) != 0)
2712 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2713 100.0;
cristy9ee60942011-07-06 14:54:38 +00002714 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2715 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002716 InheritException(exception,&(*image)->exception);
2717 break;
2718 }
2719 if (LocaleCompare("sketch",option+1) == 0)
2720 {
2721 /*
2722 Sketch image.
2723 */
2724 (void) SyncImageSettings(mogrify_info,*image);
2725 flags=ParseGeometry(argv[i+1],&geometry_info);
2726 if ((flags & SigmaValue) == 0)
2727 geometry_info.sigma=1.0;
2728 mogrify_image=SketchImage(*image,geometry_info.rho,
2729 geometry_info.sigma,geometry_info.xi,exception);
2730 break;
2731 }
2732 if (LocaleCompare("solarize",option+1) == 0)
2733 {
2734 double
2735 threshold;
2736
2737 (void) SyncImageSettings(mogrify_info,*image);
2738 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2739 (void) SolarizeImage(*image,threshold);
2740 InheritException(exception,&(*image)->exception);
2741 break;
2742 }
2743 if (LocaleCompare("sparse-color",option+1) == 0)
2744 {
2745 SparseColorMethod
2746 method;
2747
2748 char
2749 *arguments;
2750
2751 /*
2752 Sparse Color Interpolated Gradient
2753 */
2754 (void) SyncImageSettings(mogrify_info,*image);
2755 method=(SparseColorMethod) ParseCommandOption(
2756 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2757 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2758 InheritException(exception,&(*image)->exception);
2759 if (arguments == (char *) NULL)
2760 break;
cristy3884f692011-07-08 18:00:18 +00002761 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002762 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2763 arguments=DestroyString(arguments);
2764 break;
2765 }
2766 if (LocaleCompare("splice",option+1) == 0)
2767 {
2768 /*
2769 Splice a solid color into the image.
2770 */
2771 (void) SyncImageSettings(mogrify_info,*image);
2772 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2773 mogrify_image=SpliceImage(*image,&geometry,exception);
2774 break;
2775 }
2776 if (LocaleCompare("spread",option+1) == 0)
2777 {
2778 /*
2779 Spread an image.
2780 */
2781 (void) SyncImageSettings(mogrify_info,*image);
2782 (void) ParseGeometry(argv[i+1],&geometry_info);
2783 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2784 break;
2785 }
2786 if (LocaleCompare("statistic",option+1) == 0)
2787 {
2788 StatisticType
2789 type;
2790
2791 (void) SyncImageSettings(mogrify_info,*image);
2792 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2793 MagickFalse,argv[i+1]);
2794 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002795 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2796 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002797 break;
2798 }
2799 if (LocaleCompare("stretch",option+1) == 0)
2800 {
2801 if (*option == '+')
2802 {
2803 draw_info->stretch=UndefinedStretch;
2804 break;
2805 }
2806 draw_info->stretch=(StretchType) ParseCommandOption(
2807 MagickStretchOptions,MagickFalse,argv[i+1]);
2808 break;
2809 }
2810 if (LocaleCompare("strip",option+1) == 0)
2811 {
2812 /*
2813 Strip image of profiles and comments.
2814 */
2815 (void) SyncImageSettings(mogrify_info,*image);
2816 (void) StripImage(*image);
2817 InheritException(exception,&(*image)->exception);
2818 break;
2819 }
2820 if (LocaleCompare("stroke",option+1) == 0)
2821 {
2822 ExceptionInfo
2823 *sans;
2824
2825 if (*option == '+')
2826 {
2827 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2828 if (draw_info->stroke_pattern != (Image *) NULL)
2829 draw_info->stroke_pattern=DestroyImage(
2830 draw_info->stroke_pattern);
2831 break;
2832 }
2833 sans=AcquireExceptionInfo();
2834 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2835 sans=DestroyExceptionInfo(sans);
2836 if (status == MagickFalse)
2837 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2838 exception);
2839 break;
2840 }
2841 if (LocaleCompare("strokewidth",option+1) == 0)
2842 {
cristyc1acd842011-05-19 23:05:47 +00002843 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2844 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002845 break;
2846 }
2847 if (LocaleCompare("style",option+1) == 0)
2848 {
2849 if (*option == '+')
2850 {
2851 draw_info->style=UndefinedStyle;
2852 break;
2853 }
2854 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2855 MagickFalse,argv[i+1]);
2856 break;
2857 }
2858 if (LocaleCompare("swirl",option+1) == 0)
2859 {
2860 /*
2861 Swirl image.
2862 */
2863 (void) SyncImageSettings(mogrify_info,*image);
2864 (void) ParseGeometry(argv[i+1],&geometry_info);
2865 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2866 break;
2867 }
2868 break;
2869 }
2870 case 't':
2871 {
2872 if (LocaleCompare("threshold",option+1) == 0)
2873 {
2874 double
2875 threshold;
2876
2877 /*
2878 Threshold image.
2879 */
2880 (void) SyncImageSettings(mogrify_info,*image);
2881 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002882 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002883 else
2884 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002885 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002886 InheritException(exception,&(*image)->exception);
2887 break;
2888 }
2889 if (LocaleCompare("thumbnail",option+1) == 0)
2890 {
2891 /*
2892 Thumbnail image.
2893 */
2894 (void) SyncImageSettings(mogrify_info,*image);
2895 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2896 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2897 exception);
2898 break;
2899 }
2900 if (LocaleCompare("tile",option+1) == 0)
2901 {
2902 if (*option == '+')
2903 {
2904 if (draw_info->fill_pattern != (Image *) NULL)
2905 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2906 break;
2907 }
2908 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2909 exception);
2910 break;
2911 }
2912 if (LocaleCompare("tint",option+1) == 0)
2913 {
2914 /*
2915 Tint the image.
2916 */
2917 (void) SyncImageSettings(mogrify_info,*image);
2918 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2919 break;
2920 }
2921 if (LocaleCompare("transform",option+1) == 0)
2922 {
2923 /*
2924 Affine transform image.
2925 */
2926 (void) SyncImageSettings(mogrify_info,*image);
2927 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2928 exception);
2929 break;
2930 }
2931 if (LocaleCompare("transparent",option+1) == 0)
2932 {
cristy4c08aed2011-07-01 19:47:50 +00002933 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002934 target;
2935
2936 (void) SyncImageSettings(mogrify_info,*image);
2937 (void) QueryMagickColor(argv[i+1],&target,exception);
2938 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002939 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002940 InheritException(exception,&(*image)->exception);
2941 break;
2942 }
2943 if (LocaleCompare("transpose",option+1) == 0)
2944 {
2945 /*
2946 Transpose image scanlines.
2947 */
2948 (void) SyncImageSettings(mogrify_info,*image);
2949 mogrify_image=TransposeImage(*image,exception);
2950 break;
2951 }
2952 if (LocaleCompare("transverse",option+1) == 0)
2953 {
2954 /*
2955 Transverse image scanlines.
2956 */
2957 (void) SyncImageSettings(mogrify_info,*image);
2958 mogrify_image=TransverseImage(*image,exception);
2959 break;
2960 }
2961 if (LocaleCompare("treedepth",option+1) == 0)
2962 {
2963 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2964 break;
2965 }
2966 if (LocaleCompare("trim",option+1) == 0)
2967 {
2968 /*
2969 Trim image.
2970 */
2971 (void) SyncImageSettings(mogrify_info,*image);
2972 mogrify_image=TrimImage(*image,exception);
2973 break;
2974 }
2975 if (LocaleCompare("type",option+1) == 0)
2976 {
2977 ImageType
2978 type;
2979
2980 (void) SyncImageSettings(mogrify_info,*image);
2981 if (*option == '+')
2982 type=UndefinedType;
2983 else
2984 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2985 argv[i+1]);
2986 (*image)->type=UndefinedType;
2987 (void) SetImageType(*image,type);
2988 InheritException(exception,&(*image)->exception);
2989 break;
2990 }
2991 break;
2992 }
2993 case 'u':
2994 {
2995 if (LocaleCompare("undercolor",option+1) == 0)
2996 {
2997 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
2998 exception);
2999 break;
3000 }
3001 if (LocaleCompare("unique",option+1) == 0)
3002 {
3003 if (*option == '+')
3004 {
3005 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3006 break;
3007 }
3008 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3009 (void) SetImageArtifact(*image,"verbose","true");
3010 break;
3011 }
3012 if (LocaleCompare("unique-colors",option+1) == 0)
3013 {
3014 /*
3015 Unique image colors.
3016 */
3017 (void) SyncImageSettings(mogrify_info,*image);
3018 mogrify_image=UniqueImageColors(*image,exception);
3019 break;
3020 }
3021 if (LocaleCompare("unsharp",option+1) == 0)
3022 {
3023 /*
3024 Unsharp mask image.
3025 */
3026 (void) SyncImageSettings(mogrify_info,*image);
3027 flags=ParseGeometry(argv[i+1],&geometry_info);
3028 if ((flags & SigmaValue) == 0)
3029 geometry_info.sigma=1.0;
3030 if ((flags & XiValue) == 0)
3031 geometry_info.xi=1.0;
3032 if ((flags & PsiValue) == 0)
3033 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003034 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3035 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003036 break;
3037 }
3038 break;
3039 }
3040 case 'v':
3041 {
3042 if (LocaleCompare("verbose",option+1) == 0)
3043 {
3044 (void) SetImageArtifact(*image,option+1,
3045 *option == '+' ? "false" : "true");
3046 break;
3047 }
3048 if (LocaleCompare("vignette",option+1) == 0)
3049 {
3050 /*
3051 Vignette image.
3052 */
3053 (void) SyncImageSettings(mogrify_info,*image);
3054 flags=ParseGeometry(argv[i+1],&geometry_info);
3055 if ((flags & SigmaValue) == 0)
3056 geometry_info.sigma=1.0;
3057 if ((flags & XiValue) == 0)
3058 geometry_info.xi=0.1*(*image)->columns;
3059 if ((flags & PsiValue) == 0)
3060 geometry_info.psi=0.1*(*image)->rows;
3061 mogrify_image=VignetteImage(*image,geometry_info.rho,
3062 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3063 ceil(geometry_info.psi-0.5),exception);
3064 break;
3065 }
3066 if (LocaleCompare("virtual-pixel",option+1) == 0)
3067 {
3068 if (*option == '+')
3069 {
3070 (void) SetImageVirtualPixelMethod(*image,
3071 UndefinedVirtualPixelMethod);
3072 break;
3073 }
3074 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3075 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3076 argv[i+1]));
3077 break;
3078 }
3079 break;
3080 }
3081 case 'w':
3082 {
3083 if (LocaleCompare("wave",option+1) == 0)
3084 {
3085 /*
3086 Wave image.
3087 */
3088 (void) SyncImageSettings(mogrify_info,*image);
3089 flags=ParseGeometry(argv[i+1],&geometry_info);
3090 if ((flags & SigmaValue) == 0)
3091 geometry_info.sigma=1.0;
3092 mogrify_image=WaveImage(*image,geometry_info.rho,
3093 geometry_info.sigma,exception);
3094 break;
3095 }
3096 if (LocaleCompare("weight",option+1) == 0)
3097 {
3098 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3099 if (LocaleCompare(argv[i+1],"all") == 0)
3100 draw_info->weight=0;
3101 if (LocaleCompare(argv[i+1],"bold") == 0)
3102 draw_info->weight=700;
3103 if (LocaleCompare(argv[i+1],"bolder") == 0)
3104 if (draw_info->weight <= 800)
3105 draw_info->weight+=100;
3106 if (LocaleCompare(argv[i+1],"lighter") == 0)
3107 if (draw_info->weight >= 100)
3108 draw_info->weight-=100;
3109 if (LocaleCompare(argv[i+1],"normal") == 0)
3110 draw_info->weight=400;
3111 break;
3112 }
3113 if (LocaleCompare("white-threshold",option+1) == 0)
3114 {
3115 /*
3116 White threshold image.
3117 */
3118 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003119 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003120 InheritException(exception,&(*image)->exception);
3121 break;
3122 }
3123 break;
3124 }
3125 default:
3126 break;
3127 }
3128 /*
3129 Replace current image with any image that was generated
3130 */
3131 if (mogrify_image != (Image *) NULL)
3132 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003133 i+=count;
3134 }
3135 if (region_image != (Image *) NULL)
3136 {
anthonydf8ebac2011-04-27 09:03:19 +00003137 /*
3138 Composite transformed region onto image.
3139 */
cristy6b3da3a2010-06-20 02:21:46 +00003140 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003141 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003142 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3143 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003144 InheritException(exception,&region_image->exception);
3145 *image=DestroyImage(*image);
3146 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003147 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003148 }
3149 /*
3150 Free resources.
3151 */
anthonydf8ebac2011-04-27 09:03:19 +00003152 quantize_info=DestroyQuantizeInfo(quantize_info);
3153 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003154 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003155 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003156 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003157 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003158}
3159
3160/*
3161%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3162% %
3163% %
3164% %
cristy5063d812010-10-19 16:28:10 +00003165+ 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 +00003166% %
3167% %
3168% %
3169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3170%
3171% MogrifyImageCommand() transforms an image or a sequence of images. These
3172% transforms include image scaling, image rotation, color reduction, and
3173% others. The transmogrified image overwrites the original image.
3174%
3175% The format of the MogrifyImageCommand method is:
3176%
3177% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3178% const char **argv,char **metadata,ExceptionInfo *exception)
3179%
3180% A description of each parameter follows:
3181%
3182% o image_info: the image info.
3183%
3184% o argc: the number of elements in the argument vector.
3185%
3186% o argv: A text array containing the command line arguments.
3187%
3188% o metadata: any metadata is returned here.
3189%
3190% o exception: return any errors or warnings in this structure.
3191%
3192*/
3193
3194static MagickBooleanType MogrifyUsage(void)
3195{
3196 static const char
3197 *miscellaneous[]=
3198 {
3199 "-debug events display copious debugging information",
3200 "-help print program options",
3201 "-list type print a list of supported option arguments",
3202 "-log format format of debugging information",
3203 "-version print version information",
3204 (char *) NULL
3205 },
3206 *operators[]=
3207 {
3208 "-adaptive-blur geometry",
3209 " adaptively blur pixels; decrease effect near edges",
3210 "-adaptive-resize geometry",
3211 " adaptively resize image using 'mesh' interpolation",
3212 "-adaptive-sharpen geometry",
3213 " adaptively sharpen pixels; increase effect near edges",
3214 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3215 " transparent, extract, background, or shape",
3216 "-annotate geometry text",
3217 " annotate the image with text",
3218 "-auto-gamma automagically adjust gamma level of image",
3219 "-auto-level automagically adjust color levels of image",
3220 "-auto-orient automagically orient (rotate) image",
3221 "-bench iterations measure performance",
3222 "-black-threshold value",
3223 " force all pixels below the threshold into black",
3224 "-blue-shift simulate a scene at nighttime in the moonlight",
3225 "-blur geometry reduce image noise and reduce detail levels",
3226 "-border geometry surround image with a border of color",
3227 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003228 "-brightness-contrast geometry",
3229 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003230 "-cdl filename color correct with a color decision list",
3231 "-charcoal radius simulate a charcoal drawing",
3232 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003233 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003234 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003235 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003236 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003237 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003238 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003239 "-contrast enhance or reduce the image contrast",
3240 "-contrast-stretch geometry",
3241 " improve contrast by `stretching' the intensity range",
3242 "-convolve coefficients",
3243 " apply a convolution kernel to the image",
3244 "-cycle amount cycle the image colormap",
3245 "-decipher filename convert cipher pixels to plain pixels",
3246 "-deskew threshold straighten an image",
3247 "-despeckle reduce the speckles within an image",
3248 "-distort method args",
3249 " distort images according to given method ad args",
3250 "-draw string annotate the image with a graphic primitive",
3251 "-edge radius apply a filter to detect edges in the image",
3252 "-encipher filename convert plain pixels to cipher pixels",
3253 "-emboss radius emboss an image",
3254 "-enhance apply a digital filter to enhance a noisy image",
3255 "-equalize perform histogram equalization to an image",
3256 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003257 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003258 "-extent geometry set the image size",
3259 "-extract geometry extract area from image",
3260 "-fft implements the discrete Fourier transform (DFT)",
3261 "-flip flip image vertically",
3262 "-floodfill geometry color",
3263 " floodfill the image with color",
3264 "-flop flop image horizontally",
3265 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003266 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003267 " apply function over image values",
3268 "-gamma value level of gamma correction",
3269 "-gaussian-blur geometry",
3270 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003271 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003272 "-identify identify the format and characteristics of the image",
3273 "-ift implements the inverse discrete Fourier transform (DFT)",
3274 "-implode amount implode image pixels about the center",
3275 "-lat geometry local adaptive thresholding",
3276 "-layers method optimize, merge, or compare image layers",
3277 "-level value adjust the level of image contrast",
3278 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003279 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-linear-stretch geometry",
3281 " improve contrast by `stretching with saturation'",
3282 "-liquid-rescale geometry",
3283 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003284 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003285 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003286 "-modulate value vary the brightness, saturation, and hue",
3287 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003288 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003289 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003290 "-motion-blur geometry",
3291 " simulate motion blur",
3292 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003293 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003294 "-normalize transform image to span the full range of colors",
3295 "-opaque color change this color to the fill color",
3296 "-ordered-dither NxN",
3297 " add a noise pattern to the image with specific",
3298 " amplitudes",
3299 "-paint radius simulate an oil painting",
3300 "-polaroid angle simulate a Polaroid picture",
3301 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003302 "-profile filename add, delete, or apply an image profile",
3303 "-quantize colorspace reduce colors in this colorspace",
3304 "-radial-blur angle radial blur the image",
3305 "-raise value lighten/darken image edges to create a 3-D effect",
3306 "-random-threshold low,high",
3307 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003308 "-region geometry apply options to a portion of the image",
3309 "-render render vector graphics",
3310 "-repage geometry size and location of an image canvas",
3311 "-resample geometry change the resolution of an image",
3312 "-resize geometry resize the image",
3313 "-roll geometry roll an image vertically or horizontally",
3314 "-rotate degrees apply Paeth rotation to the image",
3315 "-sample geometry scale image with pixel sampling",
3316 "-scale geometry scale the image",
3317 "-segment values segment an image",
3318 "-selective-blur geometry",
3319 " selectively blur pixels within a contrast threshold",
3320 "-sepia-tone threshold",
3321 " simulate a sepia-toned photo",
3322 "-set property value set an image property",
3323 "-shade degrees shade the image using a distant light source",
3324 "-shadow geometry simulate an image shadow",
3325 "-sharpen geometry sharpen the image",
3326 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003327 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003328 "-sigmoidal-contrast geometry",
3329 " increase the contrast without saturating highlights or shadows",
3330 "-sketch geometry simulate a pencil sketch",
3331 "-solarize threshold negate all pixels above the threshold level",
3332 "-sparse-color method args",
3333 " fill in a image based on a few color points",
3334 "-splice geometry splice the background color into the image",
3335 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003336 "-statistic type radius",
3337 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003338 "-strip strip image of all profiles and comments",
3339 "-swirl degrees swirl image pixels about the center",
3340 "-threshold value threshold the image",
3341 "-thumbnail geometry create a thumbnail of the image",
3342 "-tile filename tile image when filling a graphic primitive",
3343 "-tint value tint the image with the fill color",
3344 "-transform affine transform image",
3345 "-transparent color make this color transparent within the image",
3346 "-transpose flip image vertically and rotate 90 degrees",
3347 "-transverse flop image horizontally and rotate 270 degrees",
3348 "-trim trim image edges",
3349 "-type type image type",
3350 "-unique-colors discard all but one of any pixel color",
3351 "-unsharp geometry sharpen the image",
3352 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003353 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003354 "-white-threshold value",
3355 " force all pixels above the threshold into white",
3356 (char *) NULL
3357 },
3358 *sequence_operators[]=
3359 {
cristy4285d782011-02-09 20:12:28 +00003360 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003361 "-clut apply a color lookup table to the image",
3362 "-coalesce merge a sequence of images",
3363 "-combine combine a sequence of images",
3364 "-composite composite image",
3365 "-crop geometry cut out a rectangular region of the image",
3366 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003367 "-evaluate-sequence operator",
3368 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-flatten flatten a sequence of images",
3370 "-fx expression apply mathematical expression to an image channel(s)",
3371 "-hald-clut apply a Hald color lookup table to the image",
3372 "-morph value morph an image sequence",
3373 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003374 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003375 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003376 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003377 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003378 "-write filename write images to this file",
3379 (char *) NULL
3380 },
3381 *settings[]=
3382 {
3383 "-adjoin join images into a single multi-image file",
3384 "-affine matrix affine transform matrix",
3385 "-alpha option activate, deactivate, reset, or set the alpha channel",
3386 "-antialias remove pixel-aliasing",
3387 "-authenticate password",
3388 " decipher image with this password",
3389 "-attenuate value lessen (or intensify) when adding noise to an image",
3390 "-background color background color",
3391 "-bias value add bias when convolving an image",
3392 "-black-point-compensation",
3393 " use black point compensation",
3394 "-blue-primary point chromaticity blue primary point",
3395 "-bordercolor color border color",
3396 "-caption string assign a caption to an image",
3397 "-channel type apply option to select image channels",
3398 "-colors value preferred number of colors in the image",
3399 "-colorspace type alternate image colorspace",
3400 "-comment string annotate image with comment",
3401 "-compose operator set image composite operator",
3402 "-compress type type of pixel compression when writing the image",
3403 "-define format:option",
3404 " define one or more image format options",
3405 "-delay value display the next image after pausing",
3406 "-density geometry horizontal and vertical density of the image",
3407 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003408 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003409 "-display server get image or font from this X server",
3410 "-dispose method layer disposal method",
3411 "-dither method apply error diffusion to image",
3412 "-encoding type text encoding type",
3413 "-endian type endianness (MSB or LSB) of the image",
3414 "-family name render text with this font family",
3415 "-fill color color to use when filling a graphic primitive",
3416 "-filter type use this filter when resizing an image",
3417 "-font name render text with this font",
3418 "-format \"string\" output formatted image characteristics",
3419 "-fuzz distance colors within this distance are considered equal",
3420 "-gravity type horizontal and vertical text placement",
3421 "-green-primary point chromaticity green primary point",
3422 "-intent type type of rendering intent when managing the image color",
3423 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003424 "-interline-spacing value",
3425 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003426 "-interpolate method pixel color interpolation method",
3427 "-interword-spacing value",
3428 " set the space between two words",
3429 "-kerning value set the space between two letters",
3430 "-label string assign a label to an image",
3431 "-limit type value pixel cache resource limit",
3432 "-loop iterations add Netscape loop extension to your GIF animation",
3433 "-mask filename associate a mask with the image",
3434 "-mattecolor color frame color",
3435 "-monitor monitor progress",
3436 "-orient type image orientation",
3437 "-page geometry size and location of an image canvas (setting)",
3438 "-ping efficiently determine image attributes",
3439 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003440 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003441 "-preview type image preview type",
3442 "-quality value JPEG/MIFF/PNG compression level",
3443 "-quiet suppress all warning messages",
3444 "-red-primary point chromaticity red primary point",
3445 "-regard-warnings pay attention to warning messages",
3446 "-remap filename transform image colors to match this set of colors",
3447 "-respect-parentheses settings remain in effect until parenthesis boundary",
3448 "-sampling-factor geometry",
3449 " horizontal and vertical sampling factor",
3450 "-scene value image scene number",
3451 "-seed value seed a new sequence of pseudo-random numbers",
3452 "-size geometry width and height of image",
3453 "-stretch type render text with this font stretch",
3454 "-stroke color graphic primitive stroke color",
3455 "-strokewidth value graphic primitive stroke width",
3456 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003457 "-synchronize synchronize image to storage device",
3458 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003459 "-texture filename name of texture to tile onto the image background",
3460 "-tile-offset geometry",
3461 " tile offset",
3462 "-treedepth value color tree depth",
3463 "-transparent-color color",
3464 " transparent color",
3465 "-undercolor color annotation bounding box color",
3466 "-units type the units of image resolution",
3467 "-verbose print detailed information about the image",
3468 "-view FlashPix viewing transforms",
3469 "-virtual-pixel method",
3470 " virtual pixel access method",
3471 "-weight type render text with this font weight",
3472 "-white-point point chromaticity white point",
3473 (char *) NULL
3474 },
3475 *stack_operators[]=
3476 {
anthonyb69c4b32011-03-23 04:37:44 +00003477 "-delete indexes delete the image from the image sequence",
3478 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003479 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003480 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003481 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003482 "-swap indexes swap two images in the image sequence",
3483 (char *) NULL
3484 };
3485
3486 const char
3487 **p;
3488
cristybb503372010-05-27 20:51:26 +00003489 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003490 (void) printf("Copyright: %s\n",GetMagickCopyright());
3491 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003492 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3493 GetClientName());
3494 (void) printf("\nImage Settings:\n");
3495 for (p=settings; *p != (char *) NULL; p++)
3496 (void) printf(" %s\n",*p);
3497 (void) printf("\nImage Operators:\n");
3498 for (p=operators; *p != (char *) NULL; p++)
3499 (void) printf(" %s\n",*p);
3500 (void) printf("\nImage Sequence Operators:\n");
3501 for (p=sequence_operators; *p != (char *) NULL; p++)
3502 (void) printf(" %s\n",*p);
3503 (void) printf("\nImage Stack Operators:\n");
3504 for (p=stack_operators; *p != (char *) NULL; p++)
3505 (void) printf(" %s\n",*p);
3506 (void) printf("\nMiscellaneous Options:\n");
3507 for (p=miscellaneous; *p != (char *) NULL; p++)
3508 (void) printf(" %s\n",*p);
3509 (void) printf(
3510 "\nBy default, the image format of `file' is determined by its magic\n");
3511 (void) printf(
3512 "number. To specify a particular image format, precede the filename\n");
3513 (void) printf(
3514 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3515 (void) printf(
3516 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3517 (void) printf("'-' for standard input or output.\n");
3518 return(MagickFalse);
3519}
3520
3521WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3522 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3523{
3524#define DestroyMogrify() \
3525{ \
3526 if (format != (char *) NULL) \
3527 format=DestroyString(format); \
3528 if (path != (char *) NULL) \
3529 path=DestroyString(path); \
3530 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003531 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003532 argv[i]=DestroyString(argv[i]); \
3533 argv=(char **) RelinquishMagickMemory(argv); \
3534}
3535#define ThrowMogrifyException(asperity,tag,option) \
3536{ \
3537 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3538 option); \
3539 DestroyMogrify(); \
3540 return(MagickFalse); \
3541}
3542#define ThrowMogrifyInvalidArgumentException(option,argument) \
3543{ \
3544 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3545 "InvalidArgument","`%s': %s",argument,option); \
3546 DestroyMogrify(); \
3547 return(MagickFalse); \
3548}
3549
3550 char
3551 *format,
3552 *option,
3553 *path;
3554
3555 Image
3556 *image;
3557
3558 ImageStack
3559 image_stack[MaxImageStackDepth+1];
3560
cristy3ed852e2009-09-05 21:47:34 +00003561 MagickBooleanType
3562 global_colormap;
3563
3564 MagickBooleanType
3565 fire,
cristyebbcfea2011-02-25 02:43:54 +00003566 pend,
3567 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003568
3569 MagickStatusType
3570 status;
3571
cristyebbcfea2011-02-25 02:43:54 +00003572 register ssize_t
3573 i;
3574
3575 ssize_t
3576 j,
3577 k;
3578
cristy3ed852e2009-09-05 21:47:34 +00003579 /*
3580 Set defaults.
3581 */
3582 assert(image_info != (ImageInfo *) NULL);
3583 assert(image_info->signature == MagickSignature);
3584 if (image_info->debug != MagickFalse)
3585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3586 assert(exception != (ExceptionInfo *) NULL);
3587 if (argc == 2)
3588 {
3589 option=argv[1];
3590 if ((LocaleCompare("version",option+1) == 0) ||
3591 (LocaleCompare("-version",option+1) == 0))
3592 {
cristyb51dff52011-05-19 16:55:47 +00003593 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003594 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003595 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3596 GetMagickCopyright());
3597 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3598 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003599 return(MagickFalse);
3600 }
3601 }
3602 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003603 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003604 format=(char *) NULL;
3605 path=(char *) NULL;
3606 global_colormap=MagickFalse;
3607 k=0;
3608 j=1;
3609 NewImageStack();
3610 option=(char *) NULL;
3611 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003612 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003613 status=MagickTrue;
3614 /*
3615 Parse command line.
3616 */
3617 ReadCommandlLine(argc,&argv);
3618 status=ExpandFilenames(&argc,&argv);
3619 if (status == MagickFalse)
3620 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3621 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003622 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003623 {
3624 option=argv[i];
3625 if (LocaleCompare(option,"(") == 0)
3626 {
3627 FireImageStack(MagickFalse,MagickTrue,pend);
3628 if (k == MaxImageStackDepth)
3629 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3630 option);
3631 PushImageStack();
3632 continue;
3633 }
3634 if (LocaleCompare(option,")") == 0)
3635 {
3636 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3637 if (k == 0)
3638 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3639 PopImageStack();
3640 continue;
3641 }
cristy042ee782011-04-22 18:48:30 +00003642 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003643 {
3644 char
3645 backup_filename[MaxTextExtent],
3646 *filename;
3647
3648 Image
3649 *images;
3650
3651 /*
3652 Option is a file name: begin by reading image from specified file.
3653 */
3654 FireImageStack(MagickFalse,MagickFalse,pend);
3655 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003656 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003657 filename=argv[++i];
3658 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3659 images=ReadImages(image_info,exception);
3660 status&=(images != (Image *) NULL) &&
3661 (exception->severity < ErrorException);
3662 if (images == (Image *) NULL)
3663 continue;
cristydaa76602010-06-30 13:05:11 +00003664 if (format != (char *) NULL)
3665 (void) CopyMagickString(images->filename,images->magick_filename,
3666 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003667 if (path != (char *) NULL)
3668 {
3669 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003670 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003671 path,*DirectorySeparator,filename);
3672 }
3673 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003674 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003675 AppendImageStack(images);
3676 FinalizeImageSettings(image_info,image,MagickFalse);
3677 if (global_colormap != MagickFalse)
3678 {
3679 QuantizeInfo
3680 *quantize_info;
3681
3682 quantize_info=AcquireQuantizeInfo(image_info);
3683 (void) RemapImages(quantize_info,images,(Image *) NULL);
3684 quantize_info=DestroyQuantizeInfo(quantize_info);
3685 }
3686 *backup_filename='\0';
3687 if ((LocaleCompare(image->filename,"-") != 0) &&
3688 (IsPathWritable(image->filename) != MagickFalse))
3689 {
cristybb503372010-05-27 20:51:26 +00003690 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003691 i;
3692
3693 /*
3694 Rename image file as backup.
3695 */
3696 (void) CopyMagickString(backup_filename,image->filename,
3697 MaxTextExtent);
3698 for (i=0; i < 6; i++)
3699 {
3700 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3701 if (IsPathAccessible(backup_filename) == MagickFalse)
3702 break;
3703 }
3704 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3705 (rename(image->filename,backup_filename) != 0))
3706 *backup_filename='\0';
3707 }
3708 /*
3709 Write transmogrified image to disk.
3710 */
3711 image_info->synchronize=MagickTrue;
3712 status&=WriteImages(image_info,image,image->filename,exception);
3713 if ((status == MagickFalse) && (*backup_filename != '\0'))
3714 (void) remove(backup_filename);
3715 RemoveAllImageStack();
3716 continue;
3717 }
3718 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3719 switch (*(option+1))
3720 {
3721 case 'a':
3722 {
3723 if (LocaleCompare("adaptive-blur",option+1) == 0)
3724 {
3725 i++;
cristybb503372010-05-27 20:51:26 +00003726 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003727 ThrowMogrifyException(OptionError,"MissingArgument",option);
3728 if (IsGeometry(argv[i]) == MagickFalse)
3729 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3730 break;
3731 }
3732 if (LocaleCompare("adaptive-resize",option+1) == 0)
3733 {
3734 i++;
cristybb503372010-05-27 20:51:26 +00003735 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003736 ThrowMogrifyException(OptionError,"MissingArgument",option);
3737 if (IsGeometry(argv[i]) == MagickFalse)
3738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3739 break;
3740 }
3741 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3742 {
3743 i++;
cristybb503372010-05-27 20:51:26 +00003744 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003745 ThrowMogrifyException(OptionError,"MissingArgument",option);
3746 if (IsGeometry(argv[i]) == MagickFalse)
3747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3748 break;
3749 }
3750 if (LocaleCompare("affine",option+1) == 0)
3751 {
3752 if (*option == '+')
3753 break;
3754 i++;
cristybb503372010-05-27 20:51:26 +00003755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003756 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003757 break;
3758 }
3759 if (LocaleCompare("alpha",option+1) == 0)
3760 {
cristybb503372010-05-27 20:51:26 +00003761 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003762 type;
3763
3764 if (*option == '+')
3765 break;
3766 i++;
cristybb503372010-05-27 20:51:26 +00003767 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003768 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003769 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003770 if (type < 0)
3771 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3772 argv[i]);
3773 break;
3774 }
3775 if (LocaleCompare("annotate",option+1) == 0)
3776 {
3777 if (*option == '+')
3778 break;
3779 i++;
cristybb503372010-05-27 20:51:26 +00003780 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003781 ThrowMogrifyException(OptionError,"MissingArgument",option);
3782 if (IsGeometry(argv[i]) == MagickFalse)
3783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003785 ThrowMogrifyException(OptionError,"MissingArgument",option);
3786 i++;
3787 break;
3788 }
3789 if (LocaleCompare("antialias",option+1) == 0)
3790 break;
3791 if (LocaleCompare("append",option+1) == 0)
3792 break;
3793 if (LocaleCompare("attenuate",option+1) == 0)
3794 {
3795 if (*option == '+')
3796 break;
3797 i++;
cristybb503372010-05-27 20:51:26 +00003798 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003799 ThrowMogrifyException(OptionError,"MissingArgument",option);
3800 if (IsGeometry(argv[i]) == MagickFalse)
3801 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3802 break;
3803 }
3804 if (LocaleCompare("authenticate",option+1) == 0)
3805 {
3806 if (*option == '+')
3807 break;
3808 i++;
cristybb503372010-05-27 20:51:26 +00003809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003810 ThrowMogrifyException(OptionError,"MissingArgument",option);
3811 break;
3812 }
3813 if (LocaleCompare("auto-gamma",option+1) == 0)
3814 break;
3815 if (LocaleCompare("auto-level",option+1) == 0)
3816 break;
3817 if (LocaleCompare("auto-orient",option+1) == 0)
3818 break;
3819 if (LocaleCompare("average",option+1) == 0)
3820 break;
3821 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3822 }
3823 case 'b':
3824 {
3825 if (LocaleCompare("background",option+1) == 0)
3826 {
3827 if (*option == '+')
3828 break;
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 break;
3833 }
3834 if (LocaleCompare("bias",option+1) == 0)
3835 {
3836 if (*option == '+')
3837 break;
3838 i++;
cristybb503372010-05-27 20:51:26 +00003839 if (i == (ssize_t) (argc-1))
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("black-point-compensation",option+1) == 0)
3846 break;
3847 if (LocaleCompare("black-threshold",option+1) == 0)
3848 {
3849 if (*option == '+')
3850 break;
3851 i++;
cristybb503372010-05-27 20:51:26 +00003852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003853 ThrowMogrifyException(OptionError,"MissingArgument",option);
3854 if (IsGeometry(argv[i]) == MagickFalse)
3855 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3856 break;
3857 }
3858 if (LocaleCompare("blue-primary",option+1) == 0)
3859 {
3860 if (*option == '+')
3861 break;
3862 i++;
cristybb503372010-05-27 20:51:26 +00003863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003864 ThrowMogrifyException(OptionError,"MissingArgument",option);
3865 if (IsGeometry(argv[i]) == MagickFalse)
3866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3867 break;
3868 }
3869 if (LocaleCompare("blue-shift",option+1) == 0)
3870 {
3871 i++;
cristybb503372010-05-27 20:51:26 +00003872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003873 ThrowMogrifyException(OptionError,"MissingArgument",option);
3874 if (IsGeometry(argv[i]) == MagickFalse)
3875 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3876 break;
3877 }
3878 if (LocaleCompare("blur",option+1) == 0)
3879 {
3880 i++;
cristybb503372010-05-27 20:51:26 +00003881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003882 ThrowMogrifyException(OptionError,"MissingArgument",option);
3883 if (IsGeometry(argv[i]) == MagickFalse)
3884 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3885 break;
3886 }
3887 if (LocaleCompare("border",option+1) == 0)
3888 {
3889 if (*option == '+')
3890 break;
3891 i++;
cristybb503372010-05-27 20:51:26 +00003892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003893 ThrowMogrifyException(OptionError,"MissingArgument",option);
3894 if (IsGeometry(argv[i]) == MagickFalse)
3895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3896 break;
3897 }
3898 if (LocaleCompare("bordercolor",option+1) == 0)
3899 {
3900 if (*option == '+')
3901 break;
3902 i++;
cristybb503372010-05-27 20:51:26 +00003903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003904 ThrowMogrifyException(OptionError,"MissingArgument",option);
3905 break;
3906 }
3907 if (LocaleCompare("box",option+1) == 0)
3908 {
3909 if (*option == '+')
3910 break;
3911 i++;
cristybb503372010-05-27 20:51:26 +00003912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003913 ThrowMogrifyException(OptionError,"MissingArgument",option);
3914 break;
3915 }
cristya28d6b82010-01-11 20:03:47 +00003916 if (LocaleCompare("brightness-contrast",option+1) == 0)
3917 {
3918 i++;
cristybb503372010-05-27 20:51:26 +00003919 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003920 ThrowMogrifyException(OptionError,"MissingArgument",option);
3921 if (IsGeometry(argv[i]) == MagickFalse)
3922 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3923 break;
3924 }
cristy3ed852e2009-09-05 21:47:34 +00003925 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3926 }
3927 case 'c':
3928 {
3929 if (LocaleCompare("cache",option+1) == 0)
3930 {
3931 if (*option == '+')
3932 break;
3933 i++;
cristybb503372010-05-27 20:51:26 +00003934 if (i == (ssize_t) argc)
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("caption",option+1) == 0)
3941 {
3942 if (*option == '+')
3943 break;
3944 i++;
cristybb503372010-05-27 20:51:26 +00003945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003946 ThrowMogrifyException(OptionError,"MissingArgument",option);
3947 break;
3948 }
3949 if (LocaleCompare("channel",option+1) == 0)
3950 {
cristybb503372010-05-27 20:51:26 +00003951 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003952 channel;
3953
3954 if (*option == '+')
3955 break;
3956 i++;
cristybb503372010-05-27 20:51:26 +00003957 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003958 ThrowMogrifyException(OptionError,"MissingArgument",option);
3959 channel=ParseChannelOption(argv[i]);
3960 if (channel < 0)
3961 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3962 argv[i]);
3963 break;
3964 }
3965 if (LocaleCompare("cdl",option+1) == 0)
3966 {
3967 if (*option == '+')
3968 break;
3969 i++;
cristybb503372010-05-27 20:51:26 +00003970 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003971 ThrowMogrifyException(OptionError,"MissingArgument",option);
3972 break;
3973 }
3974 if (LocaleCompare("charcoal",option+1) == 0)
3975 {
3976 if (*option == '+')
3977 break;
3978 i++;
cristybb503372010-05-27 20:51:26 +00003979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003980 ThrowMogrifyException(OptionError,"MissingArgument",option);
3981 if (IsGeometry(argv[i]) == MagickFalse)
3982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3983 break;
3984 }
3985 if (LocaleCompare("chop",option+1) == 0)
3986 {
3987 if (*option == '+')
3988 break;
3989 i++;
cristybb503372010-05-27 20:51:26 +00003990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003991 ThrowMogrifyException(OptionError,"MissingArgument",option);
3992 if (IsGeometry(argv[i]) == MagickFalse)
3993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3994 break;
3995 }
cristy1eb45dd2009-09-25 16:38:06 +00003996 if (LocaleCompare("clamp",option+1) == 0)
3997 break;
3998 if (LocaleCompare("clip",option+1) == 0)
3999 break;
cristy3ed852e2009-09-05 21:47:34 +00004000 if (LocaleCompare("clip-mask",option+1) == 0)
4001 {
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 break;
4008 }
4009 if (LocaleCompare("clut",option+1) == 0)
4010 break;
4011 if (LocaleCompare("coalesce",option+1) == 0)
4012 break;
4013 if (LocaleCompare("colorize",option+1) == 0)
4014 {
4015 if (*option == '+')
4016 break;
4017 i++;
cristybb503372010-05-27 20:51:26 +00004018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004019 ThrowMogrifyException(OptionError,"MissingArgument",option);
4020 if (IsGeometry(argv[i]) == MagickFalse)
4021 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4022 break;
4023 }
cristye6365592010-04-02 17:31:23 +00004024 if (LocaleCompare("color-matrix",option+1) == 0)
4025 {
cristyb6bd4ad2010-08-08 01:12:27 +00004026 KernelInfo
4027 *kernel_info;
4028
cristye6365592010-04-02 17:31:23 +00004029 if (*option == '+')
4030 break;
4031 i++;
cristybb503372010-05-27 20:51:26 +00004032 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004033 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004034 kernel_info=AcquireKernelInfo(argv[i]);
4035 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004037 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004038 break;
4039 }
cristy3ed852e2009-09-05 21:47:34 +00004040 if (LocaleCompare("colors",option+1) == 0)
4041 {
4042 if (*option == '+')
4043 break;
4044 i++;
cristybb503372010-05-27 20:51:26 +00004045 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004046 ThrowMogrifyException(OptionError,"MissingArgument",option);
4047 if (IsGeometry(argv[i]) == MagickFalse)
4048 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4049 break;
4050 }
4051 if (LocaleCompare("colorspace",option+1) == 0)
4052 {
cristybb503372010-05-27 20:51:26 +00004053 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004054 colorspace;
4055
4056 if (*option == '+')
4057 break;
4058 i++;
cristybb503372010-05-27 20:51:26 +00004059 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004060 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004061 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004062 argv[i]);
4063 if (colorspace < 0)
4064 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4065 argv[i]);
4066 break;
4067 }
4068 if (LocaleCompare("combine",option+1) == 0)
4069 break;
4070 if (LocaleCompare("comment",option+1) == 0)
4071 {
4072 if (*option == '+')
4073 break;
4074 i++;
cristybb503372010-05-27 20:51:26 +00004075 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004076 ThrowMogrifyException(OptionError,"MissingArgument",option);
4077 break;
4078 }
4079 if (LocaleCompare("composite",option+1) == 0)
4080 break;
4081 if (LocaleCompare("compress",option+1) == 0)
4082 {
cristybb503372010-05-27 20:51:26 +00004083 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004084 compress;
4085
4086 if (*option == '+')
4087 break;
4088 i++;
cristybb503372010-05-27 20:51:26 +00004089 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004090 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004091 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004092 argv[i]);
4093 if (compress < 0)
4094 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4095 argv[i]);
4096 break;
4097 }
cristy22879752009-10-25 23:55:40 +00004098 if (LocaleCompare("concurrent",option+1) == 0)
4099 break;
cristy3ed852e2009-09-05 21:47:34 +00004100 if (LocaleCompare("contrast",option+1) == 0)
4101 break;
4102 if (LocaleCompare("contrast-stretch",option+1) == 0)
4103 {
4104 i++;
cristybb503372010-05-27 20:51:26 +00004105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004106 ThrowMogrifyException(OptionError,"MissingArgument",option);
4107 if (IsGeometry(argv[i]) == MagickFalse)
4108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4109 break;
4110 }
4111 if (LocaleCompare("convolve",option+1) == 0)
4112 {
cristyb6bd4ad2010-08-08 01:12:27 +00004113 KernelInfo
4114 *kernel_info;
4115
cristy3ed852e2009-09-05 21:47:34 +00004116 if (*option == '+')
4117 break;
4118 i++;
cristybb503372010-05-27 20:51:26 +00004119 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004120 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004121 kernel_info=AcquireKernelInfo(argv[i]);
4122 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004124 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004125 break;
4126 }
4127 if (LocaleCompare("crop",option+1) == 0)
4128 {
4129 if (*option == '+')
4130 break;
4131 i++;
cristybb503372010-05-27 20:51:26 +00004132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004133 ThrowMogrifyException(OptionError,"MissingArgument",option);
4134 if (IsGeometry(argv[i]) == MagickFalse)
4135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4136 break;
4137 }
4138 if (LocaleCompare("cycle",option+1) == 0)
4139 {
4140 if (*option == '+')
4141 break;
4142 i++;
cristybb503372010-05-27 20:51:26 +00004143 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004144 ThrowMogrifyException(OptionError,"MissingArgument",option);
4145 if (IsGeometry(argv[i]) == MagickFalse)
4146 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4147 break;
4148 }
4149 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4150 }
4151 case 'd':
4152 {
4153 if (LocaleCompare("decipher",option+1) == 0)
4154 {
4155 if (*option == '+')
4156 break;
4157 i++;
cristybb503372010-05-27 20:51:26 +00004158 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004159 ThrowMogrifyException(OptionError,"MissingArgument",option);
4160 break;
4161 }
4162 if (LocaleCompare("deconstruct",option+1) == 0)
4163 break;
4164 if (LocaleCompare("debug",option+1) == 0)
4165 {
cristybb503372010-05-27 20:51:26 +00004166 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004167 event;
4168
4169 if (*option == '+')
4170 break;
4171 i++;
cristybb503372010-05-27 20:51:26 +00004172 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004173 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004174 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004175 if (event < 0)
4176 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4177 argv[i]);
4178 (void) SetLogEventMask(argv[i]);
4179 break;
4180 }
4181 if (LocaleCompare("define",option+1) == 0)
4182 {
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);
4186 if (*option == '+')
4187 {
4188 const char
4189 *define;
4190
4191 define=GetImageOption(image_info,argv[i]);
4192 if (define == (const char *) NULL)
4193 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4194 break;
4195 }
4196 break;
4197 }
4198 if (LocaleCompare("delay",option+1) == 0)
4199 {
4200 if (*option == '+')
4201 break;
4202 i++;
cristybb503372010-05-27 20:51:26 +00004203 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004204 ThrowMogrifyException(OptionError,"MissingArgument",option);
4205 if (IsGeometry(argv[i]) == MagickFalse)
4206 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4207 break;
4208 }
cristyecb10ff2011-03-22 13:14:03 +00004209 if (LocaleCompare("delete",option+1) == 0)
4210 {
4211 if (*option == '+')
4212 break;
4213 i++;
4214 if (i == (ssize_t) (argc-1))
4215 ThrowMogrifyException(OptionError,"MissingArgument",option);
4216 if (IsGeometry(argv[i]) == MagickFalse)
4217 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4218 break;
4219 }
cristy3ed852e2009-09-05 21:47:34 +00004220 if (LocaleCompare("density",option+1) == 0)
4221 {
4222 if (*option == '+')
4223 break;
4224 i++;
cristybb503372010-05-27 20:51:26 +00004225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004226 ThrowMogrifyException(OptionError,"MissingArgument",option);
4227 if (IsGeometry(argv[i]) == MagickFalse)
4228 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4229 break;
4230 }
4231 if (LocaleCompare("depth",option+1) == 0)
4232 {
4233 if (*option == '+')
4234 break;
4235 i++;
cristybb503372010-05-27 20:51:26 +00004236 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004237 ThrowMogrifyException(OptionError,"MissingArgument",option);
4238 if (IsGeometry(argv[i]) == MagickFalse)
4239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4240 break;
4241 }
4242 if (LocaleCompare("deskew",option+1) == 0)
4243 {
4244 if (*option == '+')
4245 break;
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (IsGeometry(argv[i]) == MagickFalse)
4250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4251 break;
4252 }
4253 if (LocaleCompare("despeckle",option+1) == 0)
4254 break;
4255 if (LocaleCompare("dft",option+1) == 0)
4256 break;
cristyc9b12952010-03-28 01:12:28 +00004257 if (LocaleCompare("direction",option+1) == 0)
4258 {
cristybb503372010-05-27 20:51:26 +00004259 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004260 direction;
4261
4262 if (*option == '+')
4263 break;
4264 i++;
cristybb503372010-05-27 20:51:26 +00004265 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004266 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004267 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004268 argv[i]);
4269 if (direction < 0)
4270 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4271 argv[i]);
4272 break;
4273 }
cristy3ed852e2009-09-05 21:47:34 +00004274 if (LocaleCompare("display",option+1) == 0)
4275 {
4276 if (*option == '+')
4277 break;
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 break;
4282 }
4283 if (LocaleCompare("dispose",option+1) == 0)
4284 {
cristybb503372010-05-27 20:51:26 +00004285 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004286 dispose;
4287
4288 if (*option == '+')
4289 break;
4290 i++;
cristybb503372010-05-27 20:51:26 +00004291 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004292 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004293 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004294 if (dispose < 0)
4295 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4296 argv[i]);
4297 break;
4298 }
4299 if (LocaleCompare("distort",option+1) == 0)
4300 {
cristybb503372010-05-27 20:51:26 +00004301 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004302 op;
4303
4304 i++;
cristybb503372010-05-27 20:51:26 +00004305 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004306 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004307 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004308 if (op < 0)
4309 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4310 argv[i]);
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 break;
4315 }
4316 if (LocaleCompare("dither",option+1) == 0)
4317 {
cristybb503372010-05-27 20:51:26 +00004318 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004319 method;
4320
4321 if (*option == '+')
4322 break;
4323 i++;
cristybb503372010-05-27 20:51:26 +00004324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004325 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004326 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004327 if (method < 0)
4328 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4329 argv[i]);
4330 break;
4331 }
4332 if (LocaleCompare("draw",option+1) == 0)
4333 {
4334 if (*option == '+')
4335 break;
4336 i++;
cristybb503372010-05-27 20:51:26 +00004337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004338 ThrowMogrifyException(OptionError,"MissingArgument",option);
4339 break;
4340 }
cristyecb10ff2011-03-22 13:14:03 +00004341 if (LocaleCompare("duplicate",option+1) == 0)
4342 {
4343 if (*option == '+')
4344 break;
4345 i++;
4346 if (i == (ssize_t) (argc-1))
4347 ThrowMogrifyException(OptionError,"MissingArgument",option);
4348 if (IsGeometry(argv[i]) == MagickFalse)
4349 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4350 break;
4351 }
cristy22879752009-10-25 23:55:40 +00004352 if (LocaleCompare("duration",option+1) == 0)
4353 {
4354 if (*option == '+')
4355 break;
4356 i++;
cristybb503372010-05-27 20:51:26 +00004357 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004358 ThrowMogrifyException(OptionError,"MissingArgument",option);
4359 if (IsGeometry(argv[i]) == MagickFalse)
4360 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4361 break;
4362 }
cristy3ed852e2009-09-05 21:47:34 +00004363 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4364 }
4365 case 'e':
4366 {
4367 if (LocaleCompare("edge",option+1) == 0)
4368 {
4369 if (*option == '+')
4370 break;
4371 i++;
cristybb503372010-05-27 20:51:26 +00004372 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004373 ThrowMogrifyException(OptionError,"MissingArgument",option);
4374 if (IsGeometry(argv[i]) == MagickFalse)
4375 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4376 break;
4377 }
4378 if (LocaleCompare("emboss",option+1) == 0)
4379 {
4380 if (*option == '+')
4381 break;
4382 i++;
cristybb503372010-05-27 20:51:26 +00004383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004384 ThrowMogrifyException(OptionError,"MissingArgument",option);
4385 if (IsGeometry(argv[i]) == MagickFalse)
4386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4387 break;
4388 }
4389 if (LocaleCompare("encipher",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
cristybb503372010-05-27 20:51:26 +00004394 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 break;
4397 }
4398 if (LocaleCompare("encoding",option+1) == 0)
4399 {
4400 if (*option == '+')
4401 break;
4402 i++;
cristybb503372010-05-27 20:51:26 +00004403 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004404 ThrowMogrifyException(OptionError,"MissingArgument",option);
4405 break;
4406 }
4407 if (LocaleCompare("endian",option+1) == 0)
4408 {
cristybb503372010-05-27 20:51:26 +00004409 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004410 endian;
4411
4412 if (*option == '+')
4413 break;
4414 i++;
cristybb503372010-05-27 20:51:26 +00004415 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004416 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004417 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004418 if (endian < 0)
4419 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4420 argv[i]);
4421 break;
4422 }
4423 if (LocaleCompare("enhance",option+1) == 0)
4424 break;
4425 if (LocaleCompare("equalize",option+1) == 0)
4426 break;
4427 if (LocaleCompare("evaluate",option+1) == 0)
4428 {
cristybb503372010-05-27 20:51:26 +00004429 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004430 op;
4431
4432 if (*option == '+')
4433 break;
4434 i++;
cristybb503372010-05-27 20:51:26 +00004435 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004436 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004437 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004438 if (op < 0)
4439 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4440 argv[i]);
4441 i++;
cristybb503372010-05-27 20:51:26 +00004442 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"MissingArgument",option);
4444 if (IsGeometry(argv[i]) == MagickFalse)
4445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4446 break;
4447 }
cristyd18ae7c2010-03-07 17:39:52 +00004448 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4449 {
cristybb503372010-05-27 20:51:26 +00004450 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004451 op;
4452
4453 if (*option == '+')
4454 break;
4455 i++;
cristybb503372010-05-27 20:51:26 +00004456 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004457 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004458 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004459 if (op < 0)
4460 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4461 argv[i]);
4462 break;
4463 }
cristy3ed852e2009-09-05 21:47:34 +00004464 if (LocaleCompare("extent",option+1) == 0)
4465 {
4466 if (*option == '+')
4467 break;
4468 i++;
cristybb503372010-05-27 20:51:26 +00004469 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004470 ThrowMogrifyException(OptionError,"MissingArgument",option);
4471 if (IsGeometry(argv[i]) == MagickFalse)
4472 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4473 break;
4474 }
4475 if (LocaleCompare("extract",option+1) == 0)
4476 {
4477 if (*option == '+')
4478 break;
4479 i++;
cristybb503372010-05-27 20:51:26 +00004480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004481 ThrowMogrifyException(OptionError,"MissingArgument",option);
4482 if (IsGeometry(argv[i]) == MagickFalse)
4483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4484 break;
4485 }
4486 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4487 }
4488 case 'f':
4489 {
4490 if (LocaleCompare("family",option+1) == 0)
4491 {
4492 if (*option == '+')
4493 break;
4494 i++;
cristybb503372010-05-27 20:51:26 +00004495 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004496 ThrowMogrifyException(OptionError,"MissingArgument",option);
4497 break;
4498 }
4499 if (LocaleCompare("fill",option+1) == 0)
4500 {
4501 if (*option == '+')
4502 break;
4503 i++;
cristybb503372010-05-27 20:51:26 +00004504 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004505 ThrowMogrifyException(OptionError,"MissingArgument",option);
4506 break;
4507 }
4508 if (LocaleCompare("filter",option+1) == 0)
4509 {
cristybb503372010-05-27 20:51:26 +00004510 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004511 filter;
4512
4513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004518 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004519 if (filter < 0)
4520 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4521 argv[i]);
4522 break;
4523 }
4524 if (LocaleCompare("flatten",option+1) == 0)
4525 break;
4526 if (LocaleCompare("flip",option+1) == 0)
4527 break;
4528 if (LocaleCompare("flop",option+1) == 0)
4529 break;
4530 if (LocaleCompare("floodfill",option+1) == 0)
4531 {
4532 if (*option == '+')
4533 break;
4534 i++;
cristybb503372010-05-27 20:51:26 +00004535 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004536 ThrowMogrifyException(OptionError,"MissingArgument",option);
4537 if (IsGeometry(argv[i]) == MagickFalse)
4538 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4539 i++;
cristybb503372010-05-27 20:51:26 +00004540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004541 ThrowMogrifyException(OptionError,"MissingArgument",option);
4542 break;
4543 }
4544 if (LocaleCompare("font",option+1) == 0)
4545 {
4546 if (*option == '+')
4547 break;
4548 i++;
cristybb503372010-05-27 20:51:26 +00004549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004550 ThrowMogrifyException(OptionError,"MissingArgument",option);
4551 break;
4552 }
4553 if (LocaleCompare("format",option+1) == 0)
4554 {
4555 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4556 (void) CloneString(&format,(char *) NULL);
4557 if (*option == '+')
4558 break;
4559 i++;
cristybb503372010-05-27 20:51:26 +00004560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004561 ThrowMogrifyException(OptionError,"MissingArgument",option);
4562 (void) CloneString(&format,argv[i]);
4563 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4564 (void) ConcatenateMagickString(image_info->filename,":",
4565 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004566 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004567 if (*image_info->magick == '\0')
4568 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4569 format);
4570 break;
4571 }
4572 if (LocaleCompare("frame",option+1) == 0)
4573 {
4574 if (*option == '+')
4575 break;
4576 i++;
cristybb503372010-05-27 20:51:26 +00004577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004578 ThrowMogrifyException(OptionError,"MissingArgument",option);
4579 if (IsGeometry(argv[i]) == MagickFalse)
4580 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4581 break;
4582 }
4583 if (LocaleCompare("function",option+1) == 0)
4584 {
cristybb503372010-05-27 20:51:26 +00004585 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004586 op;
4587
4588 if (*option == '+')
4589 break;
4590 i++;
cristybb503372010-05-27 20:51:26 +00004591 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004592 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004593 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004594 if (op < 0)
4595 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4596 i++;
cristybb503372010-05-27 20:51:26 +00004597 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004598 ThrowMogrifyException(OptionError,"MissingArgument",option);
4599 break;
4600 }
4601 if (LocaleCompare("fuzz",option+1) == 0)
4602 {
4603 if (*option == '+')
4604 break;
4605 i++;
cristybb503372010-05-27 20:51:26 +00004606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004607 ThrowMogrifyException(OptionError,"MissingArgument",option);
4608 if (IsGeometry(argv[i]) == MagickFalse)
4609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4610 break;
4611 }
4612 if (LocaleCompare("fx",option+1) == 0)
4613 {
4614 if (*option == '+')
4615 break;
4616 i++;
cristybb503372010-05-27 20:51:26 +00004617 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004618 ThrowMogrifyException(OptionError,"MissingArgument",option);
4619 break;
4620 }
4621 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4622 }
4623 case 'g':
4624 {
4625 if (LocaleCompare("gamma",option+1) == 0)
4626 {
4627 i++;
cristybb503372010-05-27 20:51:26 +00004628 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004629 ThrowMogrifyException(OptionError,"MissingArgument",option);
4630 if (IsGeometry(argv[i]) == MagickFalse)
4631 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4632 break;
4633 }
4634 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4635 (LocaleCompare("gaussian",option+1) == 0))
4636 {
4637 i++;
cristybb503372010-05-27 20:51:26 +00004638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004639 ThrowMogrifyException(OptionError,"MissingArgument",option);
4640 if (IsGeometry(argv[i]) == MagickFalse)
4641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4642 break;
4643 }
4644 if (LocaleCompare("geometry",option+1) == 0)
4645 {
4646 if (*option == '+')
4647 break;
4648 i++;
cristybb503372010-05-27 20:51:26 +00004649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004650 ThrowMogrifyException(OptionError,"MissingArgument",option);
4651 if (IsGeometry(argv[i]) == MagickFalse)
4652 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4653 break;
4654 }
4655 if (LocaleCompare("gravity",option+1) == 0)
4656 {
cristybb503372010-05-27 20:51:26 +00004657 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004658 gravity;
4659
4660 if (*option == '+')
4661 break;
4662 i++;
cristybb503372010-05-27 20:51:26 +00004663 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004664 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004665 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004666 if (gravity < 0)
4667 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4668 argv[i]);
4669 break;
4670 }
4671 if (LocaleCompare("green-primary",option+1) == 0)
4672 {
4673 if (*option == '+')
4674 break;
4675 i++;
cristybb503372010-05-27 20:51:26 +00004676 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004677 ThrowMogrifyException(OptionError,"MissingArgument",option);
4678 if (IsGeometry(argv[i]) == MagickFalse)
4679 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4680 break;
4681 }
4682 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4683 }
4684 case 'h':
4685 {
4686 if (LocaleCompare("hald-clut",option+1) == 0)
4687 break;
4688 if ((LocaleCompare("help",option+1) == 0) ||
4689 (LocaleCompare("-help",option+1) == 0))
4690 return(MogrifyUsage());
4691 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4692 }
4693 case 'i':
4694 {
4695 if (LocaleCompare("identify",option+1) == 0)
4696 break;
4697 if (LocaleCompare("idft",option+1) == 0)
4698 break;
4699 if (LocaleCompare("implode",option+1) == 0)
4700 {
4701 if (*option == '+')
4702 break;
4703 i++;
cristybb503372010-05-27 20:51:26 +00004704 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004705 ThrowMogrifyException(OptionError,"MissingArgument",option);
4706 if (IsGeometry(argv[i]) == MagickFalse)
4707 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4708 break;
4709 }
4710 if (LocaleCompare("intent",option+1) == 0)
4711 {
cristybb503372010-05-27 20:51:26 +00004712 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004713 intent;
4714
4715 if (*option == '+')
4716 break;
4717 i++;
cristybb503372010-05-27 20:51:26 +00004718 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004719 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004720 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004721 if (intent < 0)
4722 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4723 argv[i]);
4724 break;
4725 }
4726 if (LocaleCompare("interlace",option+1) == 0)
4727 {
cristybb503372010-05-27 20:51:26 +00004728 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004729 interlace;
4730
4731 if (*option == '+')
4732 break;
4733 i++;
cristybb503372010-05-27 20:51:26 +00004734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004735 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004736 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004737 argv[i]);
4738 if (interlace < 0)
4739 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4740 argv[i]);
4741 break;
4742 }
cristyb32b90a2009-09-07 21:45:48 +00004743 if (LocaleCompare("interline-spacing",option+1) == 0)
4744 {
4745 if (*option == '+')
4746 break;
4747 i++;
cristybb503372010-05-27 20:51:26 +00004748 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004749 ThrowMogrifyException(OptionError,"MissingArgument",option);
4750 if (IsGeometry(argv[i]) == MagickFalse)
4751 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4752 break;
4753 }
cristy3ed852e2009-09-05 21:47:34 +00004754 if (LocaleCompare("interpolate",option+1) == 0)
4755 {
cristybb503372010-05-27 20:51:26 +00004756 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004757 interpolate;
4758
4759 if (*option == '+')
4760 break;
4761 i++;
cristybb503372010-05-27 20:51:26 +00004762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004763 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004764 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004765 argv[i]);
4766 if (interpolate < 0)
4767 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4768 argv[i]);
4769 break;
4770 }
4771 if (LocaleCompare("interword-spacing",option+1) == 0)
4772 {
4773 if (*option == '+')
4774 break;
4775 i++;
cristybb503372010-05-27 20:51:26 +00004776 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004777 ThrowMogrifyException(OptionError,"MissingArgument",option);
4778 if (IsGeometry(argv[i]) == MagickFalse)
4779 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4780 break;
4781 }
4782 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4783 }
4784 case 'k':
4785 {
4786 if (LocaleCompare("kerning",option+1) == 0)
4787 {
4788 if (*option == '+')
4789 break;
4790 i++;
cristybb503372010-05-27 20:51:26 +00004791 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004792 ThrowMogrifyException(OptionError,"MissingArgument",option);
4793 if (IsGeometry(argv[i]) == MagickFalse)
4794 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4795 break;
4796 }
4797 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4798 }
4799 case 'l':
4800 {
4801 if (LocaleCompare("label",option+1) == 0)
4802 {
4803 if (*option == '+')
4804 break;
4805 i++;
cristybb503372010-05-27 20:51:26 +00004806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004807 ThrowMogrifyException(OptionError,"MissingArgument",option);
4808 break;
4809 }
4810 if (LocaleCompare("lat",option+1) == 0)
4811 {
4812 if (*option == '+')
4813 break;
4814 i++;
cristybb503372010-05-27 20:51:26 +00004815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004816 ThrowMogrifyException(OptionError,"MissingArgument",option);
4817 if (IsGeometry(argv[i]) == MagickFalse)
4818 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4819 }
4820 if (LocaleCompare("layers",option+1) == 0)
4821 {
cristybb503372010-05-27 20:51:26 +00004822 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004823 type;
4824
4825 if (*option == '+')
4826 break;
4827 i++;
cristybb503372010-05-27 20:51:26 +00004828 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004829 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004830 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004831 if (type < 0)
4832 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4833 argv[i]);
4834 break;
4835 }
4836 if (LocaleCompare("level",option+1) == 0)
4837 {
4838 i++;
cristybb503372010-05-27 20:51:26 +00004839 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004840 ThrowMogrifyException(OptionError,"MissingArgument",option);
4841 if (IsGeometry(argv[i]) == MagickFalse)
4842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4843 break;
4844 }
4845 if (LocaleCompare("level-colors",option+1) == 0)
4846 {
4847 i++;
cristybb503372010-05-27 20:51:26 +00004848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004849 ThrowMogrifyException(OptionError,"MissingArgument",option);
4850 break;
4851 }
4852 if (LocaleCompare("linewidth",option+1) == 0)
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);
4859 if (IsGeometry(argv[i]) == MagickFalse)
4860 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4861 break;
4862 }
4863 if (LocaleCompare("limit",option+1) == 0)
4864 {
4865 char
4866 *p;
4867
4868 double
4869 value;
4870
cristybb503372010-05-27 20:51:26 +00004871 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004872 resource;
4873
4874 if (*option == '+')
4875 break;
4876 i++;
cristybb503372010-05-27 20:51:26 +00004877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004878 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004879 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004880 argv[i]);
4881 if (resource < 0)
4882 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4883 argv[i]);
4884 i++;
cristybb503372010-05-27 20:51:26 +00004885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004886 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004887 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004888 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004889 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4891 break;
4892 }
4893 if (LocaleCompare("liquid-rescale",option+1) == 0)
4894 {
4895 i++;
cristybb503372010-05-27 20:51:26 +00004896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004897 ThrowMogrifyException(OptionError,"MissingArgument",option);
4898 if (IsGeometry(argv[i]) == MagickFalse)
4899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4900 break;
4901 }
4902 if (LocaleCompare("list",option+1) == 0)
4903 {
cristybb503372010-05-27 20:51:26 +00004904 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004905 list;
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);
cristy042ee782011-04-22 18:48:30 +00004912 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004913 if (list < 0)
4914 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004915 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004916 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004917 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004918 }
4919 if (LocaleCompare("log",option+1) == 0)
4920 {
4921 if (*option == '+')
4922 break;
4923 i++;
cristybb503372010-05-27 20:51:26 +00004924 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004925 (strchr(argv[i],'%') == (char *) NULL))
4926 ThrowMogrifyException(OptionError,"MissingArgument",option);
4927 break;
4928 }
4929 if (LocaleCompare("loop",option+1) == 0)
4930 {
4931 if (*option == '+')
4932 break;
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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4941 }
4942 case 'm':
4943 {
4944 if (LocaleCompare("map",option+1) == 0)
4945 {
4946 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4947 if (*option == '+')
4948 break;
4949 i++;
cristybb503372010-05-27 20:51:26 +00004950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004951 ThrowMogrifyException(OptionError,"MissingArgument",option);
4952 break;
4953 }
4954 if (LocaleCompare("mask",option+1) == 0)
4955 {
4956 if (*option == '+')
4957 break;
4958 i++;
cristybb503372010-05-27 20:51:26 +00004959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004960 ThrowMogrifyException(OptionError,"MissingArgument",option);
4961 break;
4962 }
4963 if (LocaleCompare("matte",option+1) == 0)
4964 break;
4965 if (LocaleCompare("mattecolor",option+1) == 0)
4966 {
4967 if (*option == '+')
4968 break;
4969 i++;
cristybb503372010-05-27 20:51:26 +00004970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004971 ThrowMogrifyException(OptionError,"MissingArgument",option);
4972 break;
4973 }
cristyf40785b2010-03-06 02:27:27 +00004974 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004975 break;
cristyf40785b2010-03-06 02:27:27 +00004976 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004977 break;
cristy3ed852e2009-09-05 21:47:34 +00004978 if (LocaleCompare("modulate",option+1) == 0)
4979 {
4980 if (*option == '+')
4981 break;
4982 i++;
cristybb503372010-05-27 20:51:26 +00004983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004984 ThrowMogrifyException(OptionError,"MissingArgument",option);
4985 if (IsGeometry(argv[i]) == MagickFalse)
4986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4987 break;
4988 }
4989 if (LocaleCompare("median",option+1) == 0)
4990 {
4991 if (*option == '+')
4992 break;
4993 i++;
cristybb503372010-05-27 20:51:26 +00004994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004995 ThrowMogrifyException(OptionError,"MissingArgument",option);
4996 if (IsGeometry(argv[i]) == MagickFalse)
4997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4998 break;
4999 }
cristy69ec32d2011-02-27 23:57:09 +00005000 if (LocaleCompare("mode",option+1) == 0)
5001 {
5002 if (*option == '+')
5003 break;
5004 i++;
5005 if (i == (ssize_t) argc)
5006 ThrowMogrifyException(OptionError,"MissingArgument",option);
5007 if (IsGeometry(argv[i]) == MagickFalse)
5008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5009 break;
5010 }
cristy3ed852e2009-09-05 21:47:34 +00005011 if (LocaleCompare("monitor",option+1) == 0)
5012 break;
5013 if (LocaleCompare("monochrome",option+1) == 0)
5014 break;
5015 if (LocaleCompare("morph",option+1) == 0)
5016 {
5017 if (*option == '+')
5018 break;
5019 i++;
cristybb503372010-05-27 20:51:26 +00005020 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005021 ThrowMogrifyException(OptionError,"MissingArgument",option);
5022 if (IsGeometry(argv[i]) == MagickFalse)
5023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5024 break;
5025 }
anthony29188a82010-01-22 10:12:34 +00005026 if (LocaleCompare("morphology",option+1) == 0)
5027 {
anthony29188a82010-01-22 10:12:34 +00005028 char
5029 token[MaxTextExtent];
5030
cristyb6bd4ad2010-08-08 01:12:27 +00005031 KernelInfo
5032 *kernel_info;
5033
5034 ssize_t
5035 op;
5036
anthony29188a82010-01-22 10:12:34 +00005037 i++;
cristybb503372010-05-27 20:51:26 +00005038 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005039 ThrowMogrifyException(OptionError,"MissingArgument",option);
5040 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005041 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005042 if (op < 0)
5043 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005044 token);
anthony29188a82010-01-22 10:12:34 +00005045 i++;
cristybb503372010-05-27 20:51:26 +00005046 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005047 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005048 kernel_info=AcquireKernelInfo(argv[i]);
5049 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005050 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005051 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005052 break;
5053 }
cristy3ed852e2009-09-05 21:47:34 +00005054 if (LocaleCompare("mosaic",option+1) == 0)
5055 break;
5056 if (LocaleCompare("motion-blur",option+1) == 0)
5057 {
5058 if (*option == '+')
5059 break;
5060 i++;
cristybb503372010-05-27 20:51:26 +00005061 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005062 ThrowMogrifyException(OptionError,"MissingArgument",option);
5063 if (IsGeometry(argv[i]) == MagickFalse)
5064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5065 break;
5066 }
5067 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5068 }
5069 case 'n':
5070 {
5071 if (LocaleCompare("negate",option+1) == 0)
5072 break;
5073 if (LocaleCompare("noise",option+1) == 0)
5074 {
5075 i++;
cristybb503372010-05-27 20:51:26 +00005076 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005077 ThrowMogrifyException(OptionError,"MissingArgument",option);
5078 if (*option == '+')
5079 {
cristybb503372010-05-27 20:51:26 +00005080 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005081 noise;
5082
cristy042ee782011-04-22 18:48:30 +00005083 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005084 if (noise < 0)
5085 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5086 argv[i]);
5087 break;
5088 }
5089 if (IsGeometry(argv[i]) == MagickFalse)
5090 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5091 break;
5092 }
5093 if (LocaleCompare("noop",option+1) == 0)
5094 break;
5095 if (LocaleCompare("normalize",option+1) == 0)
5096 break;
5097 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5098 }
5099 case 'o':
5100 {
5101 if (LocaleCompare("opaque",option+1) == 0)
5102 {
cristy3ed852e2009-09-05 21:47:34 +00005103 i++;
cristybb503372010-05-27 20:51:26 +00005104 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005105 ThrowMogrifyException(OptionError,"MissingArgument",option);
5106 break;
5107 }
5108 if (LocaleCompare("ordered-dither",option+1) == 0)
5109 {
5110 if (*option == '+')
5111 break;
5112 i++;
cristybb503372010-05-27 20:51:26 +00005113 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005114 ThrowMogrifyException(OptionError,"MissingArgument",option);
5115 break;
5116 }
5117 if (LocaleCompare("orient",option+1) == 0)
5118 {
cristybb503372010-05-27 20:51:26 +00005119 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005120 orientation;
5121
5122 orientation=UndefinedOrientation;
5123 if (*option == '+')
5124 break;
5125 i++;
cristybb503372010-05-27 20:51:26 +00005126 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005127 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005128 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005129 argv[i]);
5130 if (orientation < 0)
5131 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5132 argv[i]);
5133 break;
5134 }
5135 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5136 }
5137 case 'p':
5138 {
5139 if (LocaleCompare("page",option+1) == 0)
5140 {
5141 if (*option == '+')
5142 break;
5143 i++;
cristybb503372010-05-27 20:51:26 +00005144 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005145 ThrowMogrifyException(OptionError,"MissingArgument",option);
5146 break;
5147 }
5148 if (LocaleCompare("paint",option+1) == 0)
5149 {
5150 if (*option == '+')
5151 break;
5152 i++;
cristybb503372010-05-27 20:51:26 +00005153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005154 ThrowMogrifyException(OptionError,"MissingArgument",option);
5155 if (IsGeometry(argv[i]) == MagickFalse)
5156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5157 break;
5158 }
5159 if (LocaleCompare("path",option+1) == 0)
5160 {
5161 (void) CloneString(&path,(char *) NULL);
5162 if (*option == '+')
5163 break;
5164 i++;
cristybb503372010-05-27 20:51:26 +00005165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005166 ThrowMogrifyException(OptionError,"MissingArgument",option);
5167 (void) CloneString(&path,argv[i]);
5168 break;
5169 }
5170 if (LocaleCompare("pointsize",option+1) == 0)
5171 {
5172 if (*option == '+')
5173 break;
5174 i++;
cristybb503372010-05-27 20:51:26 +00005175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005176 ThrowMogrifyException(OptionError,"MissingArgument",option);
5177 if (IsGeometry(argv[i]) == MagickFalse)
5178 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5179 break;
5180 }
5181 if (LocaleCompare("polaroid",option+1) == 0)
5182 {
5183 if (*option == '+')
5184 break;
5185 i++;
cristybb503372010-05-27 20:51:26 +00005186 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005187 ThrowMogrifyException(OptionError,"MissingArgument",option);
5188 if (IsGeometry(argv[i]) == MagickFalse)
5189 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5190 break;
5191 }
5192 if (LocaleCompare("posterize",option+1) == 0)
5193 {
5194 if (*option == '+')
5195 break;
5196 i++;
cristybb503372010-05-27 20:51:26 +00005197 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005198 ThrowMogrifyException(OptionError,"MissingArgument",option);
5199 if (IsGeometry(argv[i]) == MagickFalse)
5200 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5201 break;
5202 }
cristye7f51092010-01-17 00:39:37 +00005203 if (LocaleCompare("precision",option+1) == 0)
5204 {
5205 if (*option == '+')
5206 break;
5207 i++;
cristybb503372010-05-27 20:51:26 +00005208 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005209 ThrowMogrifyException(OptionError,"MissingArgument",option);
5210 if (IsGeometry(argv[i]) == MagickFalse)
5211 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5212 break;
5213 }
cristy3ed852e2009-09-05 21:47:34 +00005214 if (LocaleCompare("print",option+1) == 0)
5215 {
5216 if (*option == '+')
5217 break;
5218 i++;
cristybb503372010-05-27 20:51:26 +00005219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005220 ThrowMogrifyException(OptionError,"MissingArgument",option);
5221 break;
5222 }
5223 if (LocaleCompare("process",option+1) == 0)
5224 {
5225 if (*option == '+')
5226 break;
5227 i++;
cristybb503372010-05-27 20:51:26 +00005228 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005229 ThrowMogrifyException(OptionError,"MissingArgument",option);
5230 break;
5231 }
5232 if (LocaleCompare("profile",option+1) == 0)
5233 {
5234 i++;
cristybb503372010-05-27 20:51:26 +00005235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 break;
5238 }
5239 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5240 }
5241 case 'q':
5242 {
5243 if (LocaleCompare("quality",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("quantize",option+1) == 0)
5255 {
cristybb503372010-05-27 20:51:26 +00005256 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005257 colorspace;
5258
5259 if (*option == '+')
5260 break;
5261 i++;
cristybb503372010-05-27 20:51:26 +00005262 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005263 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005264 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005265 argv[i]);
5266 if (colorspace < 0)
5267 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5268 argv[i]);
5269 break;
5270 }
5271 if (LocaleCompare("quiet",option+1) == 0)
5272 break;
5273 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5274 }
5275 case 'r':
5276 {
5277 if (LocaleCompare("radial-blur",option+1) == 0)
5278 {
5279 i++;
cristybb503372010-05-27 20:51:26 +00005280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005281 ThrowMogrifyException(OptionError,"MissingArgument",option);
5282 if (IsGeometry(argv[i]) == MagickFalse)
5283 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5284 break;
5285 }
5286 if (LocaleCompare("raise",option+1) == 0)
5287 {
5288 i++;
cristybb503372010-05-27 20:51:26 +00005289 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005290 ThrowMogrifyException(OptionError,"MissingArgument",option);
5291 if (IsGeometry(argv[i]) == MagickFalse)
5292 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5293 break;
5294 }
5295 if (LocaleCompare("random-threshold",option+1) == 0)
5296 {
5297 if (*option == '+')
5298 break;
5299 i++;
cristybb503372010-05-27 20:51:26 +00005300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005301 ThrowMogrifyException(OptionError,"MissingArgument",option);
5302 if (IsGeometry(argv[i]) == MagickFalse)
5303 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5304 break;
5305 }
cristye6365592010-04-02 17:31:23 +00005306 if (LocaleCompare("recolor",option+1) == 0)
5307 {
5308 if (*option == '+')
5309 break;
5310 i++;
cristybb503372010-05-27 20:51:26 +00005311 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005312 ThrowMogrifyException(OptionError,"MissingArgument",option);
5313 if (IsGeometry(argv[i]) == MagickFalse)
5314 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5315 break;
5316 }
cristy3ed852e2009-09-05 21:47:34 +00005317 if (LocaleCompare("red-primary",option+1) == 0)
5318 {
5319 if (*option == '+')
5320 break;
5321 i++;
cristybb503372010-05-27 20:51:26 +00005322 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005323 ThrowMogrifyException(OptionError,"MissingArgument",option);
5324 if (IsGeometry(argv[i]) == MagickFalse)
5325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5326 }
cristy9f2083a2010-04-22 19:48:05 +00005327 if (LocaleCompare("regard-warnings",option+1) == 0)
5328 break;
cristy3ed852e2009-09-05 21:47:34 +00005329 if (LocaleCompare("region",option+1) == 0)
5330 {
5331 if (*option == '+')
5332 break;
5333 i++;
cristybb503372010-05-27 20:51:26 +00005334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005335 ThrowMogrifyException(OptionError,"MissingArgument",option);
5336 if (IsGeometry(argv[i]) == MagickFalse)
5337 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5338 break;
5339 }
cristyf0c78232010-03-15 12:53:40 +00005340 if (LocaleCompare("remap",option+1) == 0)
5341 {
5342 if (*option == '+')
5343 break;
5344 i++;
cristybb503372010-05-27 20:51:26 +00005345 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005346 ThrowMogrifyException(OptionError,"MissingArgument",option);
5347 break;
5348 }
cristy3ed852e2009-09-05 21:47:34 +00005349 if (LocaleCompare("render",option+1) == 0)
5350 break;
5351 if (LocaleCompare("repage",option+1) == 0)
5352 {
5353 if (*option == '+')
5354 break;
5355 i++;
cristybb503372010-05-27 20:51:26 +00005356 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005357 ThrowMogrifyException(OptionError,"MissingArgument",option);
5358 if (IsGeometry(argv[i]) == MagickFalse)
5359 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5360 break;
5361 }
5362 if (LocaleCompare("resample",option+1) == 0)
5363 {
5364 if (*option == '+')
5365 break;
5366 i++;
cristybb503372010-05-27 20:51:26 +00005367 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005368 ThrowMogrifyException(OptionError,"MissingArgument",option);
5369 if (IsGeometry(argv[i]) == MagickFalse)
5370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5371 break;
5372 }
5373 if (LocaleCompare("resize",option+1) == 0)
5374 {
5375 if (*option == '+')
5376 break;
5377 i++;
cristybb503372010-05-27 20:51:26 +00005378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005379 ThrowMogrifyException(OptionError,"MissingArgument",option);
5380 if (IsGeometry(argv[i]) == MagickFalse)
5381 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5382 break;
5383 }
cristyebbcfea2011-02-25 02:43:54 +00005384 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5385 {
5386 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5387 break;
5388 }
cristy3ed852e2009-09-05 21:47:34 +00005389 if (LocaleCompare("reverse",option+1) == 0)
5390 break;
5391 if (LocaleCompare("roll",option+1) == 0)
5392 {
5393 if (*option == '+')
5394 break;
5395 i++;
cristybb503372010-05-27 20:51:26 +00005396 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005397 ThrowMogrifyException(OptionError,"MissingArgument",option);
5398 if (IsGeometry(argv[i]) == MagickFalse)
5399 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5400 break;
5401 }
5402 if (LocaleCompare("rotate",option+1) == 0)
5403 {
5404 i++;
cristybb503372010-05-27 20:51:26 +00005405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 if (IsGeometry(argv[i]) == MagickFalse)
5408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5409 break;
5410 }
5411 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5412 }
5413 case 's':
5414 {
5415 if (LocaleCompare("sample",option+1) == 0)
5416 {
5417 if (*option == '+')
5418 break;
5419 i++;
cristybb503372010-05-27 20:51:26 +00005420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005421 ThrowMogrifyException(OptionError,"MissingArgument",option);
5422 if (IsGeometry(argv[i]) == MagickFalse)
5423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5424 break;
5425 }
5426 if (LocaleCompare("sampling-factor",option+1) == 0)
5427 {
5428 if (*option == '+')
5429 break;
5430 i++;
cristybb503372010-05-27 20:51:26 +00005431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005432 ThrowMogrifyException(OptionError,"MissingArgument",option);
5433 if (IsGeometry(argv[i]) == MagickFalse)
5434 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5435 break;
5436 }
5437 if (LocaleCompare("scale",option+1) == 0)
5438 {
5439 if (*option == '+')
5440 break;
5441 i++;
cristybb503372010-05-27 20:51:26 +00005442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005443 ThrowMogrifyException(OptionError,"MissingArgument",option);
5444 if (IsGeometry(argv[i]) == MagickFalse)
5445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5446 break;
5447 }
5448 if (LocaleCompare("scene",option+1) == 0)
5449 {
5450 if (*option == '+')
5451 break;
5452 i++;
cristybb503372010-05-27 20:51:26 +00005453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005454 ThrowMogrifyException(OptionError,"MissingArgument",option);
5455 if (IsGeometry(argv[i]) == MagickFalse)
5456 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5457 break;
5458 }
5459 if (LocaleCompare("seed",option+1) == 0)
5460 {
5461 if (*option == '+')
5462 break;
5463 i++;
cristybb503372010-05-27 20:51:26 +00005464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005465 ThrowMogrifyException(OptionError,"MissingArgument",option);
5466 if (IsGeometry(argv[i]) == MagickFalse)
5467 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5468 break;
5469 }
5470 if (LocaleCompare("segment",option+1) == 0)
5471 {
5472 if (*option == '+')
5473 break;
5474 i++;
cristybb503372010-05-27 20:51:26 +00005475 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005476 ThrowMogrifyException(OptionError,"MissingArgument",option);
5477 if (IsGeometry(argv[i]) == MagickFalse)
5478 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5479 break;
5480 }
5481 if (LocaleCompare("selective-blur",option+1) == 0)
5482 {
5483 i++;
cristybb503372010-05-27 20:51:26 +00005484 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005485 ThrowMogrifyException(OptionError,"MissingArgument",option);
5486 if (IsGeometry(argv[i]) == MagickFalse)
5487 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5488 break;
5489 }
5490 if (LocaleCompare("separate",option+1) == 0)
5491 break;
5492 if (LocaleCompare("sepia-tone",option+1) == 0)
5493 {
5494 if (*option == '+')
5495 break;
5496 i++;
cristybb503372010-05-27 20:51:26 +00005497 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005498 ThrowMogrifyException(OptionError,"MissingArgument",option);
5499 if (IsGeometry(argv[i]) == MagickFalse)
5500 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5501 break;
5502 }
5503 if (LocaleCompare("set",option+1) == 0)
5504 {
5505 i++;
cristybb503372010-05-27 20:51:26 +00005506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005507 ThrowMogrifyException(OptionError,"MissingArgument",option);
5508 if (*option == '+')
5509 break;
5510 i++;
cristybb503372010-05-27 20:51:26 +00005511 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005512 ThrowMogrifyException(OptionError,"MissingArgument",option);
5513 break;
5514 }
5515 if (LocaleCompare("shade",option+1) == 0)
5516 {
5517 i++;
cristybb503372010-05-27 20:51:26 +00005518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 if (IsGeometry(argv[i]) == MagickFalse)
5521 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5522 break;
5523 }
5524 if (LocaleCompare("shadow",option+1) == 0)
5525 {
5526 if (*option == '+')
5527 break;
5528 i++;
cristybb503372010-05-27 20:51:26 +00005529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005530 ThrowMogrifyException(OptionError,"MissingArgument",option);
5531 if (IsGeometry(argv[i]) == MagickFalse)
5532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5533 break;
5534 }
5535 if (LocaleCompare("sharpen",option+1) == 0)
5536 {
5537 i++;
cristybb503372010-05-27 20:51:26 +00005538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005539 ThrowMogrifyException(OptionError,"MissingArgument",option);
5540 if (IsGeometry(argv[i]) == MagickFalse)
5541 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5542 break;
5543 }
5544 if (LocaleCompare("shave",option+1) == 0)
5545 {
5546 if (*option == '+')
5547 break;
5548 i++;
cristybb503372010-05-27 20:51:26 +00005549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005550 ThrowMogrifyException(OptionError,"MissingArgument",option);
5551 if (IsGeometry(argv[i]) == MagickFalse)
5552 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5553 break;
5554 }
5555 if (LocaleCompare("shear",option+1) == 0)
5556 {
5557 i++;
cristybb503372010-05-27 20:51:26 +00005558 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005559 ThrowMogrifyException(OptionError,"MissingArgument",option);
5560 if (IsGeometry(argv[i]) == MagickFalse)
5561 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5562 break;
5563 }
5564 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5565 {
5566 i++;
cristybb503372010-05-27 20:51:26 +00005567 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005568 ThrowMogrifyException(OptionError,"MissingArgument",option);
5569 if (IsGeometry(argv[i]) == MagickFalse)
5570 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5571 break;
5572 }
5573 if (LocaleCompare("size",option+1) == 0)
5574 {
5575 if (*option == '+')
5576 break;
5577 i++;
cristybb503372010-05-27 20:51:26 +00005578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005579 ThrowMogrifyException(OptionError,"MissingArgument",option);
5580 if (IsGeometry(argv[i]) == MagickFalse)
5581 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582 break;
5583 }
5584 if (LocaleCompare("sketch",option+1) == 0)
5585 {
5586 if (*option == '+')
5587 break;
5588 i++;
cristybb503372010-05-27 20:51:26 +00005589 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005590 ThrowMogrifyException(OptionError,"MissingArgument",option);
5591 if (IsGeometry(argv[i]) == MagickFalse)
5592 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5593 break;
5594 }
cristy4285d782011-02-09 20:12:28 +00005595 if (LocaleCompare("smush",option+1) == 0)
5596 {
cristy4285d782011-02-09 20:12:28 +00005597 i++;
5598 if (i == (ssize_t) argc)
5599 ThrowMogrifyException(OptionError,"MissingArgument",option);
5600 if (IsGeometry(argv[i]) == MagickFalse)
5601 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005602 i++;
5603 break;
5604 }
cristy3ed852e2009-09-05 21:47:34 +00005605 if (LocaleCompare("solarize",option+1) == 0)
5606 {
5607 if (*option == '+')
5608 break;
5609 i++;
cristybb503372010-05-27 20:51:26 +00005610 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005611 ThrowMogrifyException(OptionError,"MissingArgument",option);
5612 if (IsGeometry(argv[i]) == MagickFalse)
5613 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5614 break;
5615 }
5616 if (LocaleCompare("sparse-color",option+1) == 0)
5617 {
cristybb503372010-05-27 20:51:26 +00005618 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005619 op;
5620
5621 i++;
cristybb503372010-05-27 20:51:26 +00005622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005623 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005624 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005625 if (op < 0)
5626 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5627 argv[i]);
5628 i++;
cristybb503372010-05-27 20:51:26 +00005629 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005630 ThrowMogrifyException(OptionError,"MissingArgument",option);
5631 break;
5632 }
5633 if (LocaleCompare("spread",option+1) == 0)
5634 {
5635 if (*option == '+')
5636 break;
5637 i++;
cristybb503372010-05-27 20:51:26 +00005638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 if (IsGeometry(argv[i]) == MagickFalse)
5641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5642 break;
5643 }
cristy0834d642011-03-18 18:26:08 +00005644 if (LocaleCompare("statistic",option+1) == 0)
5645 {
5646 ssize_t
5647 op;
5648
5649 if (*option == '+')
5650 break;
5651 i++;
5652 if (i == (ssize_t) argc)
5653 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005654 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005655 if (op < 0)
5656 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5657 argv[i]);
5658 i++;
5659 if (i == (ssize_t) (argc-1))
5660 ThrowMogrifyException(OptionError,"MissingArgument",option);
5661 if (IsGeometry(argv[i]) == MagickFalse)
5662 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5663 break;
5664 }
cristy3ed852e2009-09-05 21:47:34 +00005665 if (LocaleCompare("stretch",option+1) == 0)
5666 {
cristybb503372010-05-27 20:51:26 +00005667 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005668 stretch;
5669
5670 if (*option == '+')
5671 break;
5672 i++;
cristybb503372010-05-27 20:51:26 +00005673 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005674 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005675 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005676 if (stretch < 0)
5677 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5678 argv[i]);
5679 break;
5680 }
5681 if (LocaleCompare("strip",option+1) == 0)
5682 break;
5683 if (LocaleCompare("stroke",option+1) == 0)
5684 {
5685 if (*option == '+')
5686 break;
5687 i++;
cristybb503372010-05-27 20:51:26 +00005688 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005689 ThrowMogrifyException(OptionError,"MissingArgument",option);
5690 break;
5691 }
5692 if (LocaleCompare("strokewidth",option+1) == 0)
5693 {
5694 if (*option == '+')
5695 break;
5696 i++;
cristybb503372010-05-27 20:51:26 +00005697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005698 ThrowMogrifyException(OptionError,"MissingArgument",option);
5699 if (IsGeometry(argv[i]) == MagickFalse)
5700 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5701 break;
5702 }
5703 if (LocaleCompare("style",option+1) == 0)
5704 {
cristybb503372010-05-27 20:51:26 +00005705 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005706 style;
5707
5708 if (*option == '+')
5709 break;
5710 i++;
cristybb503372010-05-27 20:51:26 +00005711 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005712 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005713 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005714 if (style < 0)
5715 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5716 argv[i]);
5717 break;
5718 }
cristyecb10ff2011-03-22 13:14:03 +00005719 if (LocaleCompare("swap",option+1) == 0)
5720 {
5721 if (*option == '+')
5722 break;
5723 i++;
5724 if (i == (ssize_t) (argc-1))
5725 ThrowMogrifyException(OptionError,"MissingArgument",option);
5726 if (IsGeometry(argv[i]) == MagickFalse)
5727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5728 break;
5729 }
cristy3ed852e2009-09-05 21:47:34 +00005730 if (LocaleCompare("swirl",option+1) == 0)
5731 {
5732 if (*option == '+')
5733 break;
5734 i++;
cristybb503372010-05-27 20:51:26 +00005735 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005736 ThrowMogrifyException(OptionError,"MissingArgument",option);
5737 if (IsGeometry(argv[i]) == MagickFalse)
5738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5739 break;
5740 }
cristyd9a29192010-10-16 16:49:53 +00005741 if (LocaleCompare("synchronize",option+1) == 0)
5742 break;
cristy3ed852e2009-09-05 21:47:34 +00005743 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5744 }
5745 case 't':
5746 {
5747 if (LocaleCompare("taint",option+1) == 0)
5748 break;
5749 if (LocaleCompare("texture",option+1) == 0)
5750 {
5751 if (*option == '+')
5752 break;
5753 i++;
cristybb503372010-05-27 20:51:26 +00005754 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005755 ThrowMogrifyException(OptionError,"MissingArgument",option);
5756 break;
5757 }
5758 if (LocaleCompare("tile",option+1) == 0)
5759 {
5760 if (*option == '+')
5761 break;
5762 i++;
cristybb503372010-05-27 20:51:26 +00005763 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005764 ThrowMogrifyException(OptionError,"MissingArgument",option);
5765 break;
5766 }
5767 if (LocaleCompare("tile-offset",option+1) == 0)
5768 {
5769 if (*option == '+')
5770 break;
5771 i++;
cristybb503372010-05-27 20:51:26 +00005772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005773 ThrowMogrifyException(OptionError,"MissingArgument",option);
5774 if (IsGeometry(argv[i]) == MagickFalse)
5775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5776 break;
5777 }
5778 if (LocaleCompare("tint",option+1) == 0)
5779 {
5780 if (*option == '+')
5781 break;
5782 i++;
cristybb503372010-05-27 20:51:26 +00005783 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 if (IsGeometry(argv[i]) == MagickFalse)
5786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5787 break;
5788 }
5789 if (LocaleCompare("transform",option+1) == 0)
5790 break;
5791 if (LocaleCompare("transpose",option+1) == 0)
5792 break;
5793 if (LocaleCompare("transverse",option+1) == 0)
5794 break;
5795 if (LocaleCompare("threshold",option+1) == 0)
5796 {
5797 if (*option == '+')
5798 break;
5799 i++;
cristybb503372010-05-27 20:51:26 +00005800 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005801 ThrowMogrifyException(OptionError,"MissingArgument",option);
5802 if (IsGeometry(argv[i]) == MagickFalse)
5803 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5804 break;
5805 }
5806 if (LocaleCompare("thumbnail",option+1) == 0)
5807 {
5808 if (*option == '+')
5809 break;
5810 i++;
cristybb503372010-05-27 20:51:26 +00005811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005812 ThrowMogrifyException(OptionError,"MissingArgument",option);
5813 if (IsGeometry(argv[i]) == MagickFalse)
5814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5815 break;
5816 }
5817 if (LocaleCompare("transparent",option+1) == 0)
5818 {
5819 i++;
cristybb503372010-05-27 20:51:26 +00005820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005821 ThrowMogrifyException(OptionError,"MissingArgument",option);
5822 break;
5823 }
5824 if (LocaleCompare("transparent-color",option+1) == 0)
5825 {
5826 if (*option == '+')
5827 break;
5828 i++;
cristybb503372010-05-27 20:51:26 +00005829 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005830 ThrowMogrifyException(OptionError,"MissingArgument",option);
5831 break;
5832 }
5833 if (LocaleCompare("treedepth",option+1) == 0)
5834 {
5835 if (*option == '+')
5836 break;
5837 i++;
cristybb503372010-05-27 20:51:26 +00005838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005839 ThrowMogrifyException(OptionError,"MissingArgument",option);
5840 if (IsGeometry(argv[i]) == MagickFalse)
5841 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5842 break;
5843 }
5844 if (LocaleCompare("trim",option+1) == 0)
5845 break;
5846 if (LocaleCompare("type",option+1) == 0)
5847 {
cristybb503372010-05-27 20:51:26 +00005848 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005849 type;
5850
5851 if (*option == '+')
5852 break;
5853 i++;
cristybb503372010-05-27 20:51:26 +00005854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005855 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005856 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005857 if (type < 0)
5858 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5859 argv[i]);
5860 break;
5861 }
5862 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5863 }
5864 case 'u':
5865 {
5866 if (LocaleCompare("undercolor",option+1) == 0)
5867 {
5868 if (*option == '+')
5869 break;
5870 i++;
cristybb503372010-05-27 20:51:26 +00005871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005872 ThrowMogrifyException(OptionError,"MissingArgument",option);
5873 break;
5874 }
5875 if (LocaleCompare("unique-colors",option+1) == 0)
5876 break;
5877 if (LocaleCompare("units",option+1) == 0)
5878 {
cristybb503372010-05-27 20:51:26 +00005879 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005880 units;
5881
5882 if (*option == '+')
5883 break;
5884 i++;
cristybb503372010-05-27 20:51:26 +00005885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005886 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005887 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005888 argv[i]);
5889 if (units < 0)
5890 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5891 argv[i]);
5892 break;
5893 }
5894 if (LocaleCompare("unsharp",option+1) == 0)
5895 {
5896 i++;
cristybb503372010-05-27 20:51:26 +00005897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005898 ThrowMogrifyException(OptionError,"MissingArgument",option);
5899 if (IsGeometry(argv[i]) == MagickFalse)
5900 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5901 break;
5902 }
5903 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5904 }
5905 case 'v':
5906 {
5907 if (LocaleCompare("verbose",option+1) == 0)
5908 {
5909 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5910 break;
5911 }
5912 if ((LocaleCompare("version",option+1) == 0) ||
5913 (LocaleCompare("-version",option+1) == 0))
5914 {
cristyb51dff52011-05-19 16:55:47 +00005915 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005916 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005917 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5918 GetMagickCopyright());
5919 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5920 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005921 break;
5922 }
5923 if (LocaleCompare("view",option+1) == 0)
5924 {
5925 if (*option == '+')
5926 break;
5927 i++;
cristybb503372010-05-27 20:51:26 +00005928 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005929 ThrowMogrifyException(OptionError,"MissingArgument",option);
5930 break;
5931 }
5932 if (LocaleCompare("vignette",option+1) == 0)
5933 {
5934 if (*option == '+')
5935 break;
5936 i++;
cristybb503372010-05-27 20:51:26 +00005937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005938 ThrowMogrifyException(OptionError,"MissingArgument",option);
5939 if (IsGeometry(argv[i]) == MagickFalse)
5940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5941 break;
5942 }
5943 if (LocaleCompare("virtual-pixel",option+1) == 0)
5944 {
cristybb503372010-05-27 20:51:26 +00005945 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005946 method;
5947
5948 if (*option == '+')
5949 break;
5950 i++;
cristybb503372010-05-27 20:51:26 +00005951 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005952 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005953 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005954 argv[i]);
5955 if (method < 0)
5956 ThrowMogrifyException(OptionError,
5957 "UnrecognizedVirtualPixelMethod",argv[i]);
5958 break;
5959 }
5960 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5961 }
5962 case 'w':
5963 {
5964 if (LocaleCompare("wave",option+1) == 0)
5965 {
5966 i++;
cristybb503372010-05-27 20:51:26 +00005967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005968 ThrowMogrifyException(OptionError,"MissingArgument",option);
5969 if (IsGeometry(argv[i]) == MagickFalse)
5970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5971 break;
5972 }
5973 if (LocaleCompare("weight",option+1) == 0)
5974 {
5975 if (*option == '+')
5976 break;
5977 i++;
cristybb503372010-05-27 20:51:26 +00005978 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005979 ThrowMogrifyException(OptionError,"MissingArgument",option);
5980 break;
5981 }
5982 if (LocaleCompare("white-point",option+1) == 0)
5983 {
5984 if (*option == '+')
5985 break;
5986 i++;
cristybb503372010-05-27 20:51:26 +00005987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005988 ThrowMogrifyException(OptionError,"MissingArgument",option);
5989 if (IsGeometry(argv[i]) == MagickFalse)
5990 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5991 break;
5992 }
5993 if (LocaleCompare("white-threshold",option+1) == 0)
5994 {
5995 if (*option == '+')
5996 break;
5997 i++;
cristybb503372010-05-27 20:51:26 +00005998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005999 ThrowMogrifyException(OptionError,"MissingArgument",option);
6000 if (IsGeometry(argv[i]) == MagickFalse)
6001 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6002 break;
6003 }
6004 if (LocaleCompare("write",option+1) == 0)
6005 {
6006 i++;
cristybb503372010-05-27 20:51:26 +00006007 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006008 ThrowMogrifyException(OptionError,"MissingArgument",option);
6009 break;
6010 }
6011 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6012 }
6013 case '?':
6014 break;
6015 default:
6016 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6017 }
cristy042ee782011-04-22 18:48:30 +00006018 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6019 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006020 if (fire != MagickFalse)
6021 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6022 }
6023 if (k != 0)
6024 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006025 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006026 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6027 DestroyMogrify();
6028 return(status != 0 ? MagickTrue : MagickFalse);
6029}
6030
6031/*
6032%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6033% %
6034% %
6035% %
6036+ M o g r i f y I m a g e I n f o %
6037% %
6038% %
6039% %
6040%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6041%
6042% MogrifyImageInfo() applies image processing settings to the image as
6043% prescribed by command line options.
6044%
6045% The format of the MogrifyImageInfo method is:
6046%
6047% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6048% const char **argv,ExceptionInfo *exception)
6049%
6050% A description of each parameter follows:
6051%
6052% o image_info: the image info..
6053%
6054% o argc: Specifies a pointer to an integer describing the number of
6055% elements in the argument vector.
6056%
6057% o argv: Specifies a pointer to a text array containing the command line
6058% arguments.
6059%
6060% o exception: return any errors or warnings in this structure.
6061%
6062*/
6063WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6064 const int argc,const char **argv,ExceptionInfo *exception)
6065{
6066 const char
6067 *option;
6068
6069 GeometryInfo
6070 geometry_info;
6071
cristybb503372010-05-27 20:51:26 +00006072 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006073 count;
6074
cristybb503372010-05-27 20:51:26 +00006075 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006076 i;
6077
6078 /*
6079 Initialize method variables.
6080 */
6081 assert(image_info != (ImageInfo *) NULL);
6082 assert(image_info->signature == MagickSignature);
6083 if (image_info->debug != MagickFalse)
6084 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6085 image_info->filename);
6086 if (argc < 0)
6087 return(MagickTrue);
6088 /*
6089 Set the image settings.
6090 */
cristybb503372010-05-27 20:51:26 +00006091 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006092 {
6093 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006094 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006095 continue;
cristy042ee782011-04-22 18:48:30 +00006096 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006097 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006098 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006099 break;
6100 switch (*(option+1))
6101 {
6102 case 'a':
6103 {
6104 if (LocaleCompare("adjoin",option+1) == 0)
6105 {
6106 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6107 break;
6108 }
6109 if (LocaleCompare("antialias",option+1) == 0)
6110 {
6111 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6112 break;
6113 }
6114 if (LocaleCompare("attenuate",option+1) == 0)
6115 {
6116 if (*option == '+')
6117 {
6118 (void) DeleteImageOption(image_info,option+1);
6119 break;
6120 }
6121 (void) SetImageOption(image_info,option+1,argv[i+1]);
6122 break;
6123 }
6124 if (LocaleCompare("authenticate",option+1) == 0)
6125 {
6126 if (*option == '+')
6127 (void) CloneString(&image_info->authenticate,(char *) NULL);
6128 else
6129 (void) CloneString(&image_info->authenticate,argv[i+1]);
6130 break;
6131 }
6132 break;
6133 }
6134 case 'b':
6135 {
6136 if (LocaleCompare("background",option+1) == 0)
6137 {
6138 if (*option == '+')
6139 {
6140 (void) DeleteImageOption(image_info,option+1);
6141 (void) QueryColorDatabase(BackgroundColor,
6142 &image_info->background_color,exception);
6143 break;
6144 }
6145 (void) SetImageOption(image_info,option+1,argv[i+1]);
6146 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6147 exception);
6148 break;
6149 }
6150 if (LocaleCompare("bias",option+1) == 0)
6151 {
6152 if (*option == '+')
6153 {
6154 (void) SetImageOption(image_info,option+1,"0.0");
6155 break;
6156 }
6157 (void) SetImageOption(image_info,option+1,argv[i+1]);
6158 break;
6159 }
6160 if (LocaleCompare("black-point-compensation",option+1) == 0)
6161 {
6162 if (*option == '+')
6163 {
6164 (void) SetImageOption(image_info,option+1,"false");
6165 break;
6166 }
6167 (void) SetImageOption(image_info,option+1,"true");
6168 break;
6169 }
6170 if (LocaleCompare("blue-primary",option+1) == 0)
6171 {
6172 if (*option == '+')
6173 {
6174 (void) SetImageOption(image_info,option+1,"0.0");
6175 break;
6176 }
6177 (void) SetImageOption(image_info,option+1,argv[i+1]);
6178 break;
6179 }
6180 if (LocaleCompare("bordercolor",option+1) == 0)
6181 {
6182 if (*option == '+')
6183 {
6184 (void) DeleteImageOption(image_info,option+1);
6185 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6186 exception);
6187 break;
6188 }
6189 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6190 exception);
6191 (void) SetImageOption(image_info,option+1,argv[i+1]);
6192 break;
6193 }
6194 if (LocaleCompare("box",option+1) == 0)
6195 {
6196 if (*option == '+')
6197 {
6198 (void) SetImageOption(image_info,"undercolor","none");
6199 break;
6200 }
6201 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6202 break;
6203 }
6204 break;
6205 }
6206 case 'c':
6207 {
6208 if (LocaleCompare("cache",option+1) == 0)
6209 {
6210 MagickSizeType
6211 limit;
6212
6213 limit=MagickResourceInfinity;
6214 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006215 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006216 (void) SetMagickResourceLimit(MemoryResource,limit);
6217 (void) SetMagickResourceLimit(MapResource,2*limit);
6218 break;
6219 }
6220 if (LocaleCompare("caption",option+1) == 0)
6221 {
6222 if (*option == '+')
6223 {
6224 (void) DeleteImageOption(image_info,option+1);
6225 break;
6226 }
6227 (void) SetImageOption(image_info,option+1,argv[i+1]);
6228 break;
6229 }
6230 if (LocaleCompare("channel",option+1) == 0)
6231 {
6232 if (*option == '+')
6233 {
6234 image_info->channel=DefaultChannels;
6235 break;
6236 }
6237 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6238 break;
6239 }
6240 if (LocaleCompare("colors",option+1) == 0)
6241 {
cristye27293e2009-12-18 02:53:20 +00006242 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006243 break;
6244 }
6245 if (LocaleCompare("colorspace",option+1) == 0)
6246 {
6247 if (*option == '+')
6248 {
6249 image_info->colorspace=UndefinedColorspace;
6250 (void) SetImageOption(image_info,option+1,"undefined");
6251 break;
6252 }
cristy042ee782011-04-22 18:48:30 +00006253 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006254 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6255 (void) SetImageOption(image_info,option+1,argv[i+1]);
6256 break;
6257 }
cristy3ed852e2009-09-05 21:47:34 +00006258 if (LocaleCompare("comment",option+1) == 0)
6259 {
6260 if (*option == '+')
6261 {
6262 (void) DeleteImageOption(image_info,option+1);
6263 break;
6264 }
6265 (void) SetImageOption(image_info,option+1,argv[i+1]);
6266 break;
6267 }
6268 if (LocaleCompare("compose",option+1) == 0)
6269 {
6270 if (*option == '+')
6271 {
6272 (void) SetImageOption(image_info,option+1,"undefined");
6273 break;
6274 }
6275 (void) SetImageOption(image_info,option+1,argv[i+1]);
6276 break;
6277 }
6278 if (LocaleCompare("compress",option+1) == 0)
6279 {
6280 if (*option == '+')
6281 {
6282 image_info->compression=UndefinedCompression;
6283 (void) SetImageOption(image_info,option+1,"undefined");
6284 break;
6285 }
cristy042ee782011-04-22 18:48:30 +00006286 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006287 MagickCompressOptions,MagickFalse,argv[i+1]);
6288 (void) SetImageOption(image_info,option+1,argv[i+1]);
6289 break;
6290 }
6291 break;
6292 }
6293 case 'd':
6294 {
6295 if (LocaleCompare("debug",option+1) == 0)
6296 {
6297 if (*option == '+')
6298 (void) SetLogEventMask("none");
6299 else
6300 (void) SetLogEventMask(argv[i+1]);
6301 image_info->debug=IsEventLogging();
6302 break;
6303 }
6304 if (LocaleCompare("define",option+1) == 0)
6305 {
6306 if (*option == '+')
6307 {
6308 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6309 (void) DeleteImageRegistry(argv[i+1]+9);
6310 else
6311 (void) DeleteImageOption(image_info,argv[i+1]);
6312 break;
6313 }
6314 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6315 {
6316 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6317 exception);
6318 break;
6319 }
6320 (void) DefineImageOption(image_info,argv[i+1]);
6321 break;
6322 }
6323 if (LocaleCompare("delay",option+1) == 0)
6324 {
6325 if (*option == '+')
6326 {
6327 (void) SetImageOption(image_info,option+1,"0");
6328 break;
6329 }
6330 (void) SetImageOption(image_info,option+1,argv[i+1]);
6331 break;
6332 }
6333 if (LocaleCompare("density",option+1) == 0)
6334 {
6335 /*
6336 Set image density.
6337 */
6338 if (*option == '+')
6339 {
6340 if (image_info->density != (char *) NULL)
6341 image_info->density=DestroyString(image_info->density);
6342 (void) SetImageOption(image_info,option+1,"72");
6343 break;
6344 }
6345 (void) CloneString(&image_info->density,argv[i+1]);
6346 (void) SetImageOption(image_info,option+1,argv[i+1]);
6347 break;
6348 }
6349 if (LocaleCompare("depth",option+1) == 0)
6350 {
6351 if (*option == '+')
6352 {
6353 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6354 break;
6355 }
cristye27293e2009-12-18 02:53:20 +00006356 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006357 break;
6358 }
cristyc9b12952010-03-28 01:12:28 +00006359 if (LocaleCompare("direction",option+1) == 0)
6360 {
6361 if (*option == '+')
6362 {
6363 (void) SetImageOption(image_info,option+1,"undefined");
6364 break;
6365 }
6366 (void) SetImageOption(image_info,option+1,argv[i+1]);
6367 break;
6368 }
cristy3ed852e2009-09-05 21:47:34 +00006369 if (LocaleCompare("display",option+1) == 0)
6370 {
6371 if (*option == '+')
6372 {
6373 if (image_info->server_name != (char *) NULL)
6374 image_info->server_name=DestroyString(
6375 image_info->server_name);
6376 break;
6377 }
6378 (void) CloneString(&image_info->server_name,argv[i+1]);
6379 break;
6380 }
6381 if (LocaleCompare("dispose",option+1) == 0)
6382 {
6383 if (*option == '+')
6384 {
6385 (void) SetImageOption(image_info,option+1,"undefined");
6386 break;
6387 }
6388 (void) SetImageOption(image_info,option+1,argv[i+1]);
6389 break;
6390 }
6391 if (LocaleCompare("dither",option+1) == 0)
6392 {
6393 if (*option == '+')
6394 {
6395 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006396 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006397 break;
6398 }
6399 (void) SetImageOption(image_info,option+1,argv[i+1]);
6400 image_info->dither=MagickTrue;
6401 break;
6402 }
6403 break;
6404 }
6405 case 'e':
6406 {
6407 if (LocaleCompare("encoding",option+1) == 0)
6408 {
6409 if (*option == '+')
6410 {
6411 (void) SetImageOption(image_info,option+1,"undefined");
6412 break;
6413 }
6414 (void) SetImageOption(image_info,option+1,argv[i+1]);
6415 break;
6416 }
6417 if (LocaleCompare("endian",option+1) == 0)
6418 {
6419 if (*option == '+')
6420 {
6421 image_info->endian=UndefinedEndian;
6422 (void) SetImageOption(image_info,option+1,"undefined");
6423 break;
6424 }
cristy042ee782011-04-22 18:48:30 +00006425 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006426 MagickEndianOptions,MagickFalse,argv[i+1]);
6427 (void) SetImageOption(image_info,option+1,argv[i+1]);
6428 break;
6429 }
6430 if (LocaleCompare("extract",option+1) == 0)
6431 {
6432 /*
6433 Set image extract geometry.
6434 */
6435 if (*option == '+')
6436 {
6437 if (image_info->extract != (char *) NULL)
6438 image_info->extract=DestroyString(image_info->extract);
6439 break;
6440 }
6441 (void) CloneString(&image_info->extract,argv[i+1]);
6442 break;
6443 }
6444 break;
6445 }
6446 case 'f':
6447 {
6448 if (LocaleCompare("fill",option+1) == 0)
6449 {
6450 if (*option == '+')
6451 {
6452 (void) SetImageOption(image_info,option+1,"none");
6453 break;
6454 }
6455 (void) SetImageOption(image_info,option+1,argv[i+1]);
6456 break;
6457 }
6458 if (LocaleCompare("filter",option+1) == 0)
6459 {
6460 if (*option == '+')
6461 {
6462 (void) SetImageOption(image_info,option+1,"undefined");
6463 break;
6464 }
6465 (void) SetImageOption(image_info,option+1,argv[i+1]);
6466 break;
6467 }
6468 if (LocaleCompare("font",option+1) == 0)
6469 {
6470 if (*option == '+')
6471 {
6472 if (image_info->font != (char *) NULL)
6473 image_info->font=DestroyString(image_info->font);
6474 break;
6475 }
6476 (void) CloneString(&image_info->font,argv[i+1]);
6477 break;
6478 }
6479 if (LocaleCompare("format",option+1) == 0)
6480 {
6481 register const char
6482 *q;
6483
6484 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006485 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006486 image_info->ping=MagickFalse;
6487 (void) SetImageOption(image_info,option+1,argv[i+1]);
6488 break;
6489 }
6490 if (LocaleCompare("fuzz",option+1) == 0)
6491 {
6492 if (*option == '+')
6493 {
6494 image_info->fuzz=0.0;
6495 (void) SetImageOption(image_info,option+1,"0");
6496 break;
6497 }
cristyf2f27272009-12-17 14:48:46 +00006498 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006499 1.0);
6500 (void) SetImageOption(image_info,option+1,argv[i+1]);
6501 break;
6502 }
6503 break;
6504 }
6505 case 'g':
6506 {
6507 if (LocaleCompare("gravity",option+1) == 0)
6508 {
6509 if (*option == '+')
6510 {
6511 (void) SetImageOption(image_info,option+1,"undefined");
6512 break;
6513 }
6514 (void) SetImageOption(image_info,option+1,argv[i+1]);
6515 break;
6516 }
6517 if (LocaleCompare("green-primary",option+1) == 0)
6518 {
6519 if (*option == '+')
6520 {
6521 (void) SetImageOption(image_info,option+1,"0.0");
6522 break;
6523 }
6524 (void) SetImageOption(image_info,option+1,argv[i+1]);
6525 break;
6526 }
6527 break;
6528 }
6529 case 'i':
6530 {
6531 if (LocaleCompare("intent",option+1) == 0)
6532 {
6533 if (*option == '+')
6534 {
6535 (void) SetImageOption(image_info,option+1,"undefined");
6536 break;
6537 }
6538 (void) SetImageOption(image_info,option+1,argv[i+1]);
6539 break;
6540 }
6541 if (LocaleCompare("interlace",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 image_info->interlace=UndefinedInterlace;
6546 (void) SetImageOption(image_info,option+1,"undefined");
6547 break;
6548 }
cristy042ee782011-04-22 18:48:30 +00006549 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006550 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6551 (void) SetImageOption(image_info,option+1,argv[i+1]);
6552 break;
6553 }
cristyb32b90a2009-09-07 21:45:48 +00006554 if (LocaleCompare("interline-spacing",option+1) == 0)
6555 {
6556 if (*option == '+')
6557 {
6558 (void) SetImageOption(image_info,option+1,"undefined");
6559 break;
6560 }
6561 (void) SetImageOption(image_info,option+1,argv[i+1]);
6562 break;
6563 }
cristy3ed852e2009-09-05 21:47:34 +00006564 if (LocaleCompare("interpolate",option+1) == 0)
6565 {
6566 if (*option == '+')
6567 {
6568 (void) SetImageOption(image_info,option+1,"undefined");
6569 break;
6570 }
6571 (void) SetImageOption(image_info,option+1,argv[i+1]);
6572 break;
6573 }
6574 if (LocaleCompare("interword-spacing",option+1) == 0)
6575 {
6576 if (*option == '+')
6577 {
6578 (void) SetImageOption(image_info,option+1,"undefined");
6579 break;
6580 }
6581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
6584 break;
6585 }
6586 case 'k':
6587 {
6588 if (LocaleCompare("kerning",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 break;
6599 }
6600 case 'l':
6601 {
6602 if (LocaleCompare("label",option+1) == 0)
6603 {
6604 if (*option == '+')
6605 {
6606 (void) DeleteImageOption(image_info,option+1);
6607 break;
6608 }
6609 (void) SetImageOption(image_info,option+1,argv[i+1]);
6610 break;
6611 }
6612 if (LocaleCompare("limit",option+1) == 0)
6613 {
6614 MagickSizeType
6615 limit;
6616
6617 ResourceType
6618 type;
6619
6620 if (*option == '+')
6621 break;
cristy042ee782011-04-22 18:48:30 +00006622 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006623 MagickFalse,argv[i+1]);
6624 limit=MagickResourceInfinity;
6625 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006626 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006627 (void) SetMagickResourceLimit(type,limit);
6628 break;
6629 }
6630 if (LocaleCompare("list",option+1) == 0)
6631 {
cristybb503372010-05-27 20:51:26 +00006632 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006633 list;
6634
6635 /*
6636 Display configuration list.
6637 */
cristy042ee782011-04-22 18:48:30 +00006638 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006639 switch (list)
6640 {
6641 case MagickCoderOptions:
6642 {
6643 (void) ListCoderInfo((FILE *) NULL,exception);
6644 break;
6645 }
6646 case MagickColorOptions:
6647 {
6648 (void) ListColorInfo((FILE *) NULL,exception);
6649 break;
6650 }
6651 case MagickConfigureOptions:
6652 {
6653 (void) ListConfigureInfo((FILE *) NULL,exception);
6654 break;
6655 }
6656 case MagickDelegateOptions:
6657 {
6658 (void) ListDelegateInfo((FILE *) NULL,exception);
6659 break;
6660 }
6661 case MagickFontOptions:
6662 {
6663 (void) ListTypeInfo((FILE *) NULL,exception);
6664 break;
6665 }
6666 case MagickFormatOptions:
6667 {
6668 (void) ListMagickInfo((FILE *) NULL,exception);
6669 break;
6670 }
6671 case MagickLocaleOptions:
6672 {
6673 (void) ListLocaleInfo((FILE *) NULL,exception);
6674 break;
6675 }
6676 case MagickLogOptions:
6677 {
6678 (void) ListLogInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickMagicOptions:
6682 {
6683 (void) ListMagicInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickMimeOptions:
6687 {
6688 (void) ListMimeInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickModuleOptions:
6692 {
6693 (void) ListModuleInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickPolicyOptions:
6697 {
6698 (void) ListPolicyInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickResourceOptions:
6702 {
6703 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickThresholdOptions:
6707 {
6708 (void) ListThresholdMaps((FILE *) NULL,exception);
6709 break;
6710 }
6711 default:
6712 {
cristy042ee782011-04-22 18:48:30 +00006713 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006714 exception);
6715 break;
6716 }
6717 }
cristyaeb2cbc2010-05-07 13:28:58 +00006718 break;
cristy3ed852e2009-09-05 21:47:34 +00006719 }
6720 if (LocaleCompare("log",option+1) == 0)
6721 {
6722 if (*option == '+')
6723 break;
6724 (void) SetLogFormat(argv[i+1]);
6725 break;
6726 }
6727 if (LocaleCompare("loop",option+1) == 0)
6728 {
6729 if (*option == '+')
6730 {
6731 (void) SetImageOption(image_info,option+1,"0");
6732 break;
6733 }
6734 (void) SetImageOption(image_info,option+1,argv[i+1]);
6735 break;
6736 }
6737 break;
6738 }
6739 case 'm':
6740 {
6741 if (LocaleCompare("matte",option+1) == 0)
6742 {
6743 if (*option == '+')
6744 {
6745 (void) SetImageOption(image_info,option+1,"false");
6746 break;
6747 }
6748 (void) SetImageOption(image_info,option+1,"true");
6749 break;
6750 }
6751 if (LocaleCompare("mattecolor",option+1) == 0)
6752 {
6753 if (*option == '+')
6754 {
6755 (void) SetImageOption(image_info,option+1,argv[i+1]);
6756 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6757 exception);
6758 break;
6759 }
6760 (void) SetImageOption(image_info,option+1,argv[i+1]);
6761 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6762 exception);
6763 break;
6764 }
6765 if (LocaleCompare("monitor",option+1) == 0)
6766 {
6767 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6768 (void *) NULL);
6769 break;
6770 }
6771 if (LocaleCompare("monochrome",option+1) == 0)
6772 {
6773 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6774 break;
6775 }
6776 break;
6777 }
6778 case 'o':
6779 {
6780 if (LocaleCompare("orient",option+1) == 0)
6781 {
6782 if (*option == '+')
6783 {
6784 image_info->orientation=UndefinedOrientation;
6785 (void) SetImageOption(image_info,option+1,"undefined");
6786 break;
6787 }
cristy042ee782011-04-22 18:48:30 +00006788 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006789 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006790 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006791 break;
6792 }
6793 }
6794 case 'p':
6795 {
6796 if (LocaleCompare("page",option+1) == 0)
6797 {
6798 char
6799 *canonical_page,
6800 page[MaxTextExtent];
6801
6802 const char
6803 *image_option;
6804
6805 MagickStatusType
6806 flags;
6807
6808 RectangleInfo
6809 geometry;
6810
6811 if (*option == '+')
6812 {
6813 (void) DeleteImageOption(image_info,option+1);
6814 (void) CloneString(&image_info->page,(char *) NULL);
6815 break;
6816 }
6817 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6818 image_option=GetImageOption(image_info,"page");
6819 if (image_option != (const char *) NULL)
6820 flags=ParseAbsoluteGeometry(image_option,&geometry);
6821 canonical_page=GetPageGeometry(argv[i+1]);
6822 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6823 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006824 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006825 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006826 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006827 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006828 (unsigned long) geometry.width,(unsigned long) geometry.height,
6829 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006830 (void) SetImageOption(image_info,option+1,page);
6831 (void) CloneString(&image_info->page,page);
6832 break;
6833 }
6834 if (LocaleCompare("pen",option+1) == 0)
6835 {
6836 if (*option == '+')
6837 {
6838 (void) SetImageOption(image_info,option+1,"none");
6839 break;
6840 }
6841 (void) SetImageOption(image_info,option+1,argv[i+1]);
6842 break;
6843 }
6844 if (LocaleCompare("ping",option+1) == 0)
6845 {
6846 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6847 break;
6848 }
6849 if (LocaleCompare("pointsize",option+1) == 0)
6850 {
6851 if (*option == '+')
6852 geometry_info.rho=0.0;
6853 else
6854 (void) ParseGeometry(argv[i+1],&geometry_info);
6855 image_info->pointsize=geometry_info.rho;
6856 break;
6857 }
cristye7f51092010-01-17 00:39:37 +00006858 if (LocaleCompare("precision",option+1) == 0)
6859 {
cristybf2766a2010-01-17 03:33:23 +00006860 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006861 break;
6862 }
cristy3ed852e2009-09-05 21:47:34 +00006863 if (LocaleCompare("preview",option+1) == 0)
6864 {
6865 /*
6866 Preview image.
6867 */
6868 if (*option == '+')
6869 {
6870 image_info->preview_type=UndefinedPreview;
6871 break;
6872 }
cristy042ee782011-04-22 18:48:30 +00006873 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006874 MagickPreviewOptions,MagickFalse,argv[i+1]);
6875 break;
6876 }
6877 break;
6878 }
6879 case 'q':
6880 {
6881 if (LocaleCompare("quality",option+1) == 0)
6882 {
6883 /*
6884 Set image compression quality.
6885 */
6886 if (*option == '+')
6887 {
6888 image_info->quality=UndefinedCompressionQuality;
6889 (void) SetImageOption(image_info,option+1,"0");
6890 break;
6891 }
cristye27293e2009-12-18 02:53:20 +00006892 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006893 (void) SetImageOption(image_info,option+1,argv[i+1]);
6894 break;
6895 }
6896 if (LocaleCompare("quiet",option+1) == 0)
6897 {
6898 static WarningHandler
6899 warning_handler = (WarningHandler) NULL;
6900
6901 if (*option == '+')
6902 {
6903 /*
6904 Restore error or warning messages.
6905 */
6906 warning_handler=SetWarningHandler(warning_handler);
6907 break;
6908 }
6909 /*
6910 Suppress error or warning messages.
6911 */
6912 warning_handler=SetWarningHandler((WarningHandler) NULL);
6913 break;
6914 }
6915 break;
6916 }
6917 case 'r':
6918 {
6919 if (LocaleCompare("red-primary",option+1) == 0)
6920 {
6921 if (*option == '+')
6922 {
6923 (void) SetImageOption(image_info,option+1,"0.0");
6924 break;
6925 }
6926 (void) SetImageOption(image_info,option+1,argv[i+1]);
6927 break;
6928 }
6929 break;
6930 }
6931 case 's':
6932 {
6933 if (LocaleCompare("sampling-factor",option+1) == 0)
6934 {
6935 /*
6936 Set image sampling factor.
6937 */
6938 if (*option == '+')
6939 {
6940 if (image_info->sampling_factor != (char *) NULL)
6941 image_info->sampling_factor=DestroyString(
6942 image_info->sampling_factor);
6943 break;
6944 }
6945 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6946 break;
6947 }
6948 if (LocaleCompare("scene",option+1) == 0)
6949 {
6950 /*
6951 Set image scene.
6952 */
6953 if (*option == '+')
6954 {
6955 image_info->scene=0;
6956 (void) SetImageOption(image_info,option+1,"0");
6957 break;
6958 }
cristye27293e2009-12-18 02:53:20 +00006959 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006960 (void) SetImageOption(image_info,option+1,argv[i+1]);
6961 break;
6962 }
6963 if (LocaleCompare("seed",option+1) == 0)
6964 {
cristybb503372010-05-27 20:51:26 +00006965 size_t
cristy3ed852e2009-09-05 21:47:34 +00006966 seed;
6967
6968 if (*option == '+')
6969 {
cristybb503372010-05-27 20:51:26 +00006970 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006971 SeedPseudoRandomGenerator(seed);
6972 break;
6973 }
cristye27293e2009-12-18 02:53:20 +00006974 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006975 SeedPseudoRandomGenerator(seed);
6976 break;
6977 }
6978 if (LocaleCompare("size",option+1) == 0)
6979 {
6980 if (*option == '+')
6981 {
6982 if (image_info->size != (char *) NULL)
6983 image_info->size=DestroyString(image_info->size);
6984 break;
6985 }
6986 (void) CloneString(&image_info->size,argv[i+1]);
6987 break;
6988 }
6989 if (LocaleCompare("stroke",option+1) == 0)
6990 {
6991 if (*option == '+')
6992 {
6993 (void) SetImageOption(image_info,option+1,"none");
6994 break;
6995 }
6996 (void) SetImageOption(image_info,option+1,argv[i+1]);
6997 break;
6998 }
6999 if (LocaleCompare("strokewidth",option+1) == 0)
7000 {
7001 if (*option == '+')
7002 {
7003 (void) SetImageOption(image_info,option+1,"0");
7004 break;
7005 }
7006 (void) SetImageOption(image_info,option+1,argv[i+1]);
7007 break;
7008 }
cristyd9a29192010-10-16 16:49:53 +00007009 if (LocaleCompare("synchronize",option+1) == 0)
7010 {
7011 if (*option == '+')
7012 {
7013 image_info->synchronize=MagickFalse;
7014 break;
7015 }
7016 image_info->synchronize=MagickTrue;
7017 break;
7018 }
cristy3ed852e2009-09-05 21:47:34 +00007019 break;
7020 }
7021 case 't':
7022 {
7023 if (LocaleCompare("taint",option+1) == 0)
7024 {
7025 if (*option == '+')
7026 {
7027 (void) SetImageOption(image_info,option+1,"false");
7028 break;
7029 }
7030 (void) SetImageOption(image_info,option+1,"true");
7031 break;
7032 }
7033 if (LocaleCompare("texture",option+1) == 0)
7034 {
7035 if (*option == '+')
7036 {
7037 if (image_info->texture != (char *) NULL)
7038 image_info->texture=DestroyString(image_info->texture);
7039 break;
7040 }
7041 (void) CloneString(&image_info->texture,argv[i+1]);
7042 break;
7043 }
7044 if (LocaleCompare("tile-offset",option+1) == 0)
7045 {
7046 if (*option == '+')
7047 {
7048 (void) SetImageOption(image_info,option+1,"0");
7049 break;
7050 }
7051 (void) SetImageOption(image_info,option+1,argv[i+1]);
7052 break;
7053 }
7054 if (LocaleCompare("transparent-color",option+1) == 0)
7055 {
7056 if (*option == '+')
7057 {
7058 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7059 (void) SetImageOption(image_info,option+1,"none");
7060 break;
7061 }
7062 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7063 exception);
7064 (void) SetImageOption(image_info,option+1,argv[i+1]);
7065 break;
7066 }
7067 if (LocaleCompare("type",option+1) == 0)
7068 {
7069 if (*option == '+')
7070 {
cristy5f1c1ff2010-12-23 21:38:06 +00007071 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007072 (void) SetImageOption(image_info,option+1,"undefined");
7073 break;
7074 }
cristy042ee782011-04-22 18:48:30 +00007075 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007076 MagickFalse,argv[i+1]);
7077 (void) SetImageOption(image_info,option+1,argv[i+1]);
7078 break;
7079 }
7080 break;
7081 }
7082 case 'u':
7083 {
7084 if (LocaleCompare("undercolor",option+1) == 0)
7085 {
7086 if (*option == '+')
7087 {
7088 (void) DeleteImageOption(image_info,option+1);
7089 break;
7090 }
7091 (void) SetImageOption(image_info,option+1,argv[i+1]);
7092 break;
7093 }
7094 if (LocaleCompare("units",option+1) == 0)
7095 {
7096 if (*option == '+')
7097 {
7098 image_info->units=UndefinedResolution;
7099 (void) SetImageOption(image_info,option+1,"undefined");
7100 break;
7101 }
cristy042ee782011-04-22 18:48:30 +00007102 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007103 MagickResolutionOptions,MagickFalse,argv[i+1]);
7104 (void) SetImageOption(image_info,option+1,argv[i+1]);
7105 break;
7106 }
7107 break;
7108 }
7109 case 'v':
7110 {
7111 if (LocaleCompare("verbose",option+1) == 0)
7112 {
7113 if (*option == '+')
7114 {
7115 image_info->verbose=MagickFalse;
7116 break;
7117 }
7118 image_info->verbose=MagickTrue;
7119 image_info->ping=MagickFalse;
7120 break;
7121 }
7122 if (LocaleCompare("view",option+1) == 0)
7123 {
7124 if (*option == '+')
7125 {
7126 if (image_info->view != (char *) NULL)
7127 image_info->view=DestroyString(image_info->view);
7128 break;
7129 }
7130 (void) CloneString(&image_info->view,argv[i+1]);
7131 break;
7132 }
7133 if (LocaleCompare("virtual-pixel",option+1) == 0)
7134 {
7135 if (*option == '+')
7136 {
7137 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7138 (void) SetImageOption(image_info,option+1,"undefined");
7139 break;
7140 }
7141 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007142 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007143 argv[i+1]);
7144 (void) SetImageOption(image_info,option+1,argv[i+1]);
7145 break;
7146 }
7147 break;
7148 }
7149 case 'w':
7150 {
7151 if (LocaleCompare("white-point",option+1) == 0)
7152 {
7153 if (*option == '+')
7154 {
7155 (void) SetImageOption(image_info,option+1,"0.0");
7156 break;
7157 }
7158 (void) SetImageOption(image_info,option+1,argv[i+1]);
7159 break;
7160 }
7161 break;
7162 }
7163 default:
7164 break;
7165 }
7166 i+=count;
7167 }
7168 return(MagickTrue);
7169}
7170
7171/*
7172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7173% %
7174% %
7175% %
7176+ M o g r i f y I m a g e L i s t %
7177% %
7178% %
7179% %
7180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7181%
7182% MogrifyImageList() applies any command line options that might affect the
7183% entire image list (e.g. -append, -coalesce, etc.).
7184%
7185% The format of the MogrifyImage method is:
7186%
7187% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7188% const char **argv,Image **images,ExceptionInfo *exception)
7189%
7190% A description of each parameter follows:
7191%
7192% o image_info: the image info..
7193%
7194% o argc: Specifies a pointer to an integer describing the number of
7195% elements in the argument vector.
7196%
7197% o argv: Specifies a pointer to a text array containing the command line
7198% arguments.
7199%
anthonye9c27192011-03-27 08:07:06 +00007200% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007201%
7202% o exception: return any errors or warnings in this structure.
7203%
7204*/
7205WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7206 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7207{
cristy3ed852e2009-09-05 21:47:34 +00007208 const char
7209 *option;
7210
cristy6b3da3a2010-06-20 02:21:46 +00007211 ImageInfo
7212 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007213
7214 MagickStatusType
7215 status;
7216
7217 QuantizeInfo
7218 *quantize_info;
7219
cristybb503372010-05-27 20:51:26 +00007220 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007221 i;
7222
cristy6b3da3a2010-06-20 02:21:46 +00007223 ssize_t
7224 count,
7225 index;
7226
cristy3ed852e2009-09-05 21:47:34 +00007227 /*
7228 Apply options to the image list.
7229 */
7230 assert(image_info != (ImageInfo *) NULL);
7231 assert(image_info->signature == MagickSignature);
7232 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007233 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007234 assert((*images)->signature == MagickSignature);
7235 if ((*images)->debug != MagickFalse)
7236 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7237 (*images)->filename);
7238 if ((argc <= 0) || (*argv == (char *) NULL))
7239 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007240 mogrify_info=CloneImageInfo(image_info);
7241 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007242 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007243 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007244 {
cristy74fe8f12009-10-03 19:09:01 +00007245 if (*images == (Image *) NULL)
7246 break;
cristy3ed852e2009-09-05 21:47:34 +00007247 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007248 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007249 continue;
cristy042ee782011-04-22 18:48:30 +00007250 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007251 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007252 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007253 break;
cristy6b3da3a2010-06-20 02:21:46 +00007254 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007255 switch (*(option+1))
7256 {
7257 case 'a':
7258 {
7259 if (LocaleCompare("affinity",option+1) == 0)
7260 {
cristy6b3da3a2010-06-20 02:21:46 +00007261 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007262 if (*option == '+')
7263 {
7264 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7265 InheritException(exception,&(*images)->exception);
7266 break;
7267 }
7268 i++;
7269 break;
7270 }
7271 if (LocaleCompare("append",option+1) == 0)
7272 {
7273 Image
7274 *append_image;
7275
cristy6b3da3a2010-06-20 02:21:46 +00007276 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007277 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7278 MagickFalse,exception);
7279 if (append_image == (Image *) NULL)
7280 {
7281 status=MagickFalse;
7282 break;
7283 }
7284 *images=DestroyImageList(*images);
7285 *images=append_image;
7286 break;
7287 }
7288 if (LocaleCompare("average",option+1) == 0)
7289 {
7290 Image
7291 *average_image;
7292
cristyd18ae7c2010-03-07 17:39:52 +00007293 /*
7294 Average an image sequence (deprecated).
7295 */
cristy6b3da3a2010-06-20 02:21:46 +00007296 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007297 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7298 exception);
cristy3ed852e2009-09-05 21:47:34 +00007299 if (average_image == (Image *) NULL)
7300 {
7301 status=MagickFalse;
7302 break;
7303 }
7304 *images=DestroyImageList(*images);
7305 *images=average_image;
7306 break;
7307 }
7308 break;
7309 }
7310 case 'c':
7311 {
7312 if (LocaleCompare("channel",option+1) == 0)
7313 {
cristyf4ad9df2011-07-08 16:49:03 +00007314 ChannelType
7315 channel;
7316
cristy3ed852e2009-09-05 21:47:34 +00007317 if (*option == '+')
7318 {
7319 channel=DefaultChannels;
7320 break;
7321 }
7322 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007323 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007324 break;
7325 }
7326 if (LocaleCompare("clut",option+1) == 0)
7327 {
7328 Image
7329 *clut_image,
7330 *image;
7331
cristy6b3da3a2010-06-20 02:21:46 +00007332 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007333 image=RemoveFirstImageFromList(images);
7334 clut_image=RemoveFirstImageFromList(images);
7335 if (clut_image == (Image *) NULL)
7336 {
7337 status=MagickFalse;
7338 break;
7339 }
cristyf89cb1d2011-07-07 01:24:37 +00007340 (void) ClutImage(image,clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007341 clut_image=DestroyImage(clut_image);
7342 InheritException(exception,&image->exception);
7343 *images=DestroyImageList(*images);
7344 *images=image;
7345 break;
7346 }
7347 if (LocaleCompare("coalesce",option+1) == 0)
7348 {
7349 Image
7350 *coalesce_image;
7351
cristy6b3da3a2010-06-20 02:21:46 +00007352 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007353 coalesce_image=CoalesceImages(*images,exception);
7354 if (coalesce_image == (Image *) NULL)
7355 {
7356 status=MagickFalse;
7357 break;
7358 }
7359 *images=DestroyImageList(*images);
7360 *images=coalesce_image;
7361 break;
7362 }
7363 if (LocaleCompare("combine",option+1) == 0)
7364 {
7365 Image
7366 *combine_image;
7367
cristy6b3da3a2010-06-20 02:21:46 +00007368 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007369 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007370 if (combine_image == (Image *) NULL)
7371 {
7372 status=MagickFalse;
7373 break;
7374 }
7375 *images=DestroyImageList(*images);
7376 *images=combine_image;
7377 break;
7378 }
7379 if (LocaleCompare("composite",option+1) == 0)
7380 {
7381 Image
7382 *mask_image,
7383 *composite_image,
7384 *image;
7385
7386 RectangleInfo
7387 geometry;
7388
cristy6b3da3a2010-06-20 02:21:46 +00007389 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007390 image=RemoveFirstImageFromList(images);
7391 composite_image=RemoveFirstImageFromList(images);
7392 if (composite_image == (Image *) NULL)
7393 {
7394 status=MagickFalse;
7395 break;
7396 }
7397 (void) TransformImage(&composite_image,(char *) NULL,
7398 composite_image->geometry);
7399 SetGeometry(composite_image,&geometry);
7400 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7401 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7402 &geometry);
7403 mask_image=RemoveFirstImageFromList(images);
7404 if (mask_image != (Image *) NULL)
7405 {
7406 if ((image->compose == DisplaceCompositeOp) ||
7407 (image->compose == DistortCompositeOp))
7408 {
7409 /*
7410 Merge Y displacement into X displacement image.
7411 */
7412 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7413 mask_image,0,0);
7414 mask_image=DestroyImage(mask_image);
7415 }
7416 else
7417 {
7418 /*
7419 Set a blending mask for the composition.
7420 */
anthonya129f702011-04-14 01:08:48 +00007421 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007422 image->mask=mask_image;
7423 (void) NegateImage(image->mask,MagickFalse);
7424 }
7425 }
cristyf4ad9df2011-07-08 16:49:03 +00007426 (void) CompositeImage(image,image->compose,composite_image,
7427 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007428 if (mask_image != (Image *) NULL)
7429 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007430 composite_image=DestroyImage(composite_image);
7431 InheritException(exception,&image->exception);
7432 *images=DestroyImageList(*images);
7433 *images=image;
7434 break;
7435 }
anthony9f4f0342011-03-28 11:47:22 +00007436#if 0
7437This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007438 if (LocaleCompare("crop",option+1) == 0)
7439 {
7440 MagickStatusType
7441 flags;
7442
7443 RectangleInfo
7444 geometry;
7445
anthonye9c27192011-03-27 08:07:06 +00007446 /*
anthony9f4f0342011-03-28 11:47:22 +00007447 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007448 */
cristy6b3da3a2010-06-20 02:21:46 +00007449 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007450 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7451 if (((geometry.width == 0) && (geometry.height == 0)) ||
7452 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7453 break;
7454 (void) TransformImages(images,argv[i+1],(char *) NULL);
7455 InheritException(exception,&(*images)->exception);
7456 break;
7457 }
anthony9f4f0342011-03-28 11:47:22 +00007458#endif
cristy3ed852e2009-09-05 21:47:34 +00007459 break;
7460 }
7461 case 'd':
7462 {
7463 if (LocaleCompare("deconstruct",option+1) == 0)
7464 {
7465 Image
7466 *deconstruct_image;
7467
cristy6b3da3a2010-06-20 02:21:46 +00007468 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007469 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007470 exception);
cristy3ed852e2009-09-05 21:47:34 +00007471 if (deconstruct_image == (Image *) NULL)
7472 {
7473 status=MagickFalse;
7474 break;
7475 }
7476 *images=DestroyImageList(*images);
7477 *images=deconstruct_image;
7478 break;
7479 }
7480 if (LocaleCompare("delete",option+1) == 0)
7481 {
7482 if (*option == '+')
7483 DeleteImages(images,"-1",exception);
7484 else
7485 DeleteImages(images,argv[i+1],exception);
7486 break;
7487 }
7488 if (LocaleCompare("dither",option+1) == 0)
7489 {
7490 if (*option == '+')
7491 {
7492 quantize_info->dither=MagickFalse;
7493 break;
7494 }
7495 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007496 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007497 MagickDitherOptions,MagickFalse,argv[i+1]);
7498 break;
7499 }
cristyecb10ff2011-03-22 13:14:03 +00007500 if (LocaleCompare("duplicate",option+1) == 0)
7501 {
cristy72988482011-03-29 16:34:38 +00007502 Image
7503 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007504
anthony2b6bcae2011-03-23 13:05:34 +00007505 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007506 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7507 else
7508 {
7509 const char
7510 *p;
7511
anthony2b6bcae2011-03-23 13:05:34 +00007512 size_t
7513 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007514
anthony2b6bcae2011-03-23 13:05:34 +00007515 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007516 p=strchr(argv[i+1],',');
7517 if (p == (const char *) NULL)
7518 duplicate_images=DuplicateImages(*images,number_duplicates,
7519 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007520 else
cristy72988482011-03-29 16:34:38 +00007521 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7522 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007523 }
7524 AppendImageToList(images, duplicate_images);
7525 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007526 break;
7527 }
cristy3ed852e2009-09-05 21:47:34 +00007528 break;
7529 }
cristyd18ae7c2010-03-07 17:39:52 +00007530 case 'e':
7531 {
7532 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7533 {
7534 Image
7535 *evaluate_image;
7536
7537 MagickEvaluateOperator
7538 op;
7539
cristy6b3da3a2010-06-20 02:21:46 +00007540 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007541 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007542 MagickFalse,argv[i+1]);
7543 evaluate_image=EvaluateImages(*images,op,exception);
7544 if (evaluate_image == (Image *) NULL)
7545 {
7546 status=MagickFalse;
7547 break;
7548 }
7549 *images=DestroyImageList(*images);
7550 *images=evaluate_image;
7551 break;
7552 }
7553 break;
7554 }
cristy3ed852e2009-09-05 21:47:34 +00007555 case 'f':
7556 {
cristyf0a247f2009-10-04 00:20:03 +00007557 if (LocaleCompare("fft",option+1) == 0)
7558 {
7559 Image
7560 *fourier_image;
7561
7562 /*
7563 Implements the discrete Fourier transform (DFT).
7564 */
cristy6b3da3a2010-06-20 02:21:46 +00007565 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007566 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7567 MagickTrue : MagickFalse,exception);
7568 if (fourier_image == (Image *) NULL)
7569 break;
7570 *images=DestroyImage(*images);
7571 *images=fourier_image;
7572 break;
7573 }
cristy3ed852e2009-09-05 21:47:34 +00007574 if (LocaleCompare("flatten",option+1) == 0)
7575 {
7576 Image
7577 *flatten_image;
7578
cristy6b3da3a2010-06-20 02:21:46 +00007579 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007580 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7581 if (flatten_image == (Image *) NULL)
7582 break;
7583 *images=DestroyImageList(*images);
7584 *images=flatten_image;
7585 break;
7586 }
7587 if (LocaleCompare("fx",option+1) == 0)
7588 {
7589 Image
7590 *fx_image;
7591
cristy6b3da3a2010-06-20 02:21:46 +00007592 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007593 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007594 if (fx_image == (Image *) NULL)
7595 {
7596 status=MagickFalse;
7597 break;
7598 }
7599 *images=DestroyImageList(*images);
7600 *images=fx_image;
7601 break;
7602 }
7603 break;
7604 }
7605 case 'h':
7606 {
7607 if (LocaleCompare("hald-clut",option+1) == 0)
7608 {
7609 Image
7610 *hald_image,
7611 *image;
7612
cristy6b3da3a2010-06-20 02:21:46 +00007613 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007614 image=RemoveFirstImageFromList(images);
7615 hald_image=RemoveFirstImageFromList(images);
7616 if (hald_image == (Image *) NULL)
7617 {
7618 status=MagickFalse;
7619 break;
7620 }
cristyf89cb1d2011-07-07 01:24:37 +00007621 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007622 hald_image=DestroyImage(hald_image);
7623 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007624 if (*images != (Image *) NULL)
7625 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007626 *images=image;
7627 break;
7628 }
7629 break;
7630 }
7631 case 'i':
7632 {
7633 if (LocaleCompare("ift",option+1) == 0)
7634 {
7635 Image
cristy8587f882009-11-13 20:28:49 +00007636 *fourier_image,
7637 *magnitude_image,
7638 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007639
7640 /*
7641 Implements the inverse fourier discrete Fourier transform (DFT).
7642 */
cristy6b3da3a2010-06-20 02:21:46 +00007643 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007644 magnitude_image=RemoveFirstImageFromList(images);
7645 phase_image=RemoveFirstImageFromList(images);
7646 if (phase_image == (Image *) NULL)
7647 {
7648 status=MagickFalse;
7649 break;
7650 }
7651 fourier_image=InverseFourierTransformImage(magnitude_image,
7652 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007653 if (fourier_image == (Image *) NULL)
7654 break;
cristy0aff6ea2009-11-14 01:40:53 +00007655 if (*images != (Image *) NULL)
7656 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007657 *images=fourier_image;
7658 break;
7659 }
7660 if (LocaleCompare("insert",option+1) == 0)
7661 {
7662 Image
7663 *p,
7664 *q;
7665
7666 index=0;
7667 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007668 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007669 p=RemoveLastImageFromList(images);
7670 if (p == (Image *) NULL)
7671 {
7672 (void) ThrowMagickException(exception,GetMagickModule(),
7673 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7674 status=MagickFalse;
7675 break;
7676 }
7677 q=p;
7678 if (index == 0)
7679 PrependImageToList(images,q);
7680 else
cristybb503372010-05-27 20:51:26 +00007681 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007682 AppendImageToList(images,q);
7683 else
7684 {
7685 q=GetImageFromList(*images,index-1);
7686 if (q == (Image *) NULL)
7687 {
7688 (void) ThrowMagickException(exception,GetMagickModule(),
7689 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7690 status=MagickFalse;
7691 break;
7692 }
7693 InsertImageInList(&q,p);
7694 }
7695 *images=GetFirstImageInList(q);
7696 break;
7697 }
7698 break;
7699 }
7700 case 'l':
7701 {
7702 if (LocaleCompare("layers",option+1) == 0)
7703 {
7704 Image
7705 *layers;
7706
7707 ImageLayerMethod
7708 method;
7709
cristy6b3da3a2010-06-20 02:21:46 +00007710 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007711 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007712 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007713 MagickFalse,argv[i+1]);
7714 switch (method)
7715 {
7716 case CoalesceLayer:
7717 {
7718 layers=CoalesceImages(*images,exception);
7719 break;
7720 }
7721 case CompareAnyLayer:
7722 case CompareClearLayer:
7723 case CompareOverlayLayer:
7724 default:
7725 {
cristy8a9106f2011-07-05 14:39:26 +00007726 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007727 break;
7728 }
7729 case MergeLayer:
7730 case FlattenLayer:
7731 case MosaicLayer:
7732 case TrimBoundsLayer:
7733 {
7734 layers=MergeImageLayers(*images,method,exception);
7735 break;
7736 }
7737 case DisposeLayer:
7738 {
7739 layers=DisposeImages(*images,exception);
7740 break;
7741 }
7742 case OptimizeImageLayer:
7743 {
7744 layers=OptimizeImageLayers(*images,exception);
7745 break;
7746 }
7747 case OptimizePlusLayer:
7748 {
7749 layers=OptimizePlusImageLayers(*images,exception);
7750 break;
7751 }
7752 case OptimizeTransLayer:
7753 {
7754 OptimizeImageTransparency(*images,exception);
7755 break;
7756 }
7757 case RemoveDupsLayer:
7758 {
7759 RemoveDuplicateLayers(images,exception);
7760 break;
7761 }
7762 case RemoveZeroLayer:
7763 {
7764 RemoveZeroDelayLayers(images,exception);
7765 break;
7766 }
7767 case OptimizeLayer:
7768 {
7769 /*
7770 General Purpose, GIF Animation Optimizer.
7771 */
7772 layers=CoalesceImages(*images,exception);
7773 if (layers == (Image *) NULL)
7774 {
7775 status=MagickFalse;
7776 break;
7777 }
7778 InheritException(exception,&layers->exception);
7779 *images=DestroyImageList(*images);
7780 *images=layers;
7781 layers=OptimizeImageLayers(*images,exception);
7782 if (layers == (Image *) NULL)
7783 {
7784 status=MagickFalse;
7785 break;
7786 }
7787 InheritException(exception,&layers->exception);
7788 *images=DestroyImageList(*images);
7789 *images=layers;
7790 layers=(Image *) NULL;
7791 OptimizeImageTransparency(*images,exception);
7792 InheritException(exception,&(*images)->exception);
7793 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7794 break;
7795 }
7796 case CompositeLayer:
7797 {
7798 CompositeOperator
7799 compose;
7800
7801 Image
7802 *source;
7803
7804 RectangleInfo
7805 geometry;
7806
7807 /*
7808 Split image sequence at the first 'NULL:' image.
7809 */
7810 source=(*images);
7811 while (source != (Image *) NULL)
7812 {
7813 source=GetNextImageInList(source);
7814 if ((source != (Image *) NULL) &&
7815 (LocaleCompare(source->magick,"NULL") == 0))
7816 break;
7817 }
7818 if (source != (Image *) NULL)
7819 {
7820 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7821 (GetNextImageInList(source) == (Image *) NULL))
7822 source=(Image *) NULL;
7823 else
7824 {
7825 /*
7826 Separate the two lists, junk the null: image.
7827 */
7828 source=SplitImageList(source->previous);
7829 DeleteImageFromList(&source);
7830 }
7831 }
7832 if (source == (Image *) NULL)
7833 {
7834 (void) ThrowMagickException(exception,GetMagickModule(),
7835 OptionError,"MissingNullSeparator","layers Composite");
7836 status=MagickFalse;
7837 break;
7838 }
7839 /*
7840 Adjust offset with gravity and virtual canvas.
7841 */
7842 SetGeometry(*images,&geometry);
7843 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7844 geometry.width=source->page.width != 0 ?
7845 source->page.width : source->columns;
7846 geometry.height=source->page.height != 0 ?
7847 source->page.height : source->rows;
7848 GravityAdjustGeometry((*images)->page.width != 0 ?
7849 (*images)->page.width : (*images)->columns,
7850 (*images)->page.height != 0 ? (*images)->page.height :
7851 (*images)->rows,(*images)->gravity,&geometry);
7852 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007853 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007854 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007855 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007856 MagickComposeOptions,MagickFalse,option);
7857 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7858 exception);
7859 source=DestroyImageList(source);
7860 break;
7861 }
7862 }
7863 if (layers == (Image *) NULL)
7864 break;
7865 InheritException(exception,&layers->exception);
7866 *images=DestroyImageList(*images);
7867 *images=layers;
7868 break;
7869 }
7870 break;
7871 }
7872 case 'm':
7873 {
7874 if (LocaleCompare("map",option+1) == 0)
7875 {
cristy6b3da3a2010-06-20 02:21:46 +00007876 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007877 if (*option == '+')
7878 {
7879 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7880 InheritException(exception,&(*images)->exception);
7881 break;
7882 }
7883 i++;
7884 break;
7885 }
cristyf40785b2010-03-06 02:27:27 +00007886 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007887 {
7888 Image
cristyf40785b2010-03-06 02:27:27 +00007889 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007890
cristyd18ae7c2010-03-07 17:39:52 +00007891 /*
7892 Maximum image sequence (deprecated).
7893 */
cristy6b3da3a2010-06-20 02:21:46 +00007894 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007895 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007896 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007897 {
7898 status=MagickFalse;
7899 break;
7900 }
7901 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007902 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007903 break;
7904 }
cristyf40785b2010-03-06 02:27:27 +00007905 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007906 {
7907 Image
cristyf40785b2010-03-06 02:27:27 +00007908 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007909
cristyd18ae7c2010-03-07 17:39:52 +00007910 /*
7911 Minimum image sequence (deprecated).
7912 */
cristy6b3da3a2010-06-20 02:21:46 +00007913 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007914 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007915 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007916 {
7917 status=MagickFalse;
7918 break;
7919 }
7920 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007921 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007922 break;
7923 }
cristy3ed852e2009-09-05 21:47:34 +00007924 if (LocaleCompare("morph",option+1) == 0)
7925 {
7926 Image
7927 *morph_image;
7928
cristy6b3da3a2010-06-20 02:21:46 +00007929 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007930 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007931 exception);
7932 if (morph_image == (Image *) NULL)
7933 {
7934 status=MagickFalse;
7935 break;
7936 }
7937 *images=DestroyImageList(*images);
7938 *images=morph_image;
7939 break;
7940 }
7941 if (LocaleCompare("mosaic",option+1) == 0)
7942 {
7943 Image
7944 *mosaic_image;
7945
cristy6b3da3a2010-06-20 02:21:46 +00007946 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007947 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7948 if (mosaic_image == (Image *) NULL)
7949 {
7950 status=MagickFalse;
7951 break;
7952 }
7953 *images=DestroyImageList(*images);
7954 *images=mosaic_image;
7955 break;
7956 }
7957 break;
7958 }
7959 case 'p':
7960 {
7961 if (LocaleCompare("print",option+1) == 0)
7962 {
7963 char
7964 *string;
7965
cristy6b3da3a2010-06-20 02:21:46 +00007966 (void) SyncImagesSettings(mogrify_info,*images);
7967 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007968 if (string == (char *) NULL)
7969 break;
7970 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007971 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007972 string=DestroyString(string);
7973 }
7974 if (LocaleCompare("process",option+1) == 0)
7975 {
7976 char
7977 **arguments;
7978
7979 int
7980 j,
7981 number_arguments;
7982
cristy6b3da3a2010-06-20 02:21:46 +00007983 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007984 arguments=StringToArgv(argv[i+1],&number_arguments);
7985 if (arguments == (char **) NULL)
7986 break;
7987 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7988 {
7989 char
7990 breaker,
7991 quote,
7992 *token;
7993
7994 const char
7995 *arguments;
7996
7997 int
7998 next,
7999 status;
8000
8001 size_t
8002 length;
8003
8004 TokenInfo
8005 *token_info;
8006
8007 /*
8008 Support old style syntax, filter="-option arg".
8009 */
8010 length=strlen(argv[i+1]);
8011 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008012 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008013 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8014 sizeof(*token));
8015 if (token == (char *) NULL)
8016 break;
8017 next=0;
8018 arguments=argv[i+1];
8019 token_info=AcquireTokenInfo();
8020 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8021 "\"",'\0',&breaker,&next,&quote);
8022 token_info=DestroyTokenInfo(token_info);
8023 if (status == 0)
8024 {
8025 const char
8026 *argv;
8027
8028 argv=(&(arguments[next]));
8029 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8030 exception);
8031 }
8032 token=DestroyString(token);
8033 break;
8034 }
cristy91c0da22010-05-02 01:44:07 +00008035 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008036 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8037 number_arguments-2,(const char **) arguments+2,exception);
8038 for (j=0; j < number_arguments; j++)
8039 arguments[j]=DestroyString(arguments[j]);
8040 arguments=(char **) RelinquishMagickMemory(arguments);
8041 break;
8042 }
8043 break;
8044 }
8045 case 'r':
8046 {
8047 if (LocaleCompare("reverse",option+1) == 0)
8048 {
8049 ReverseImageList(images);
8050 InheritException(exception,&(*images)->exception);
8051 break;
8052 }
8053 break;
8054 }
8055 case 's':
8056 {
cristy4285d782011-02-09 20:12:28 +00008057 if (LocaleCompare("smush",option+1) == 0)
8058 {
8059 Image
8060 *smush_image;
8061
8062 ssize_t
8063 offset;
8064
8065 (void) SyncImagesSettings(mogrify_info,*images);
8066 offset=(ssize_t) StringToLong(argv[i+1]);
8067 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8068 MagickFalse,offset,exception);
8069 if (smush_image == (Image *) NULL)
8070 {
8071 status=MagickFalse;
8072 break;
8073 }
8074 *images=DestroyImageList(*images);
8075 *images=smush_image;
8076 break;
8077 }
cristy3ed852e2009-09-05 21:47:34 +00008078 if (LocaleCompare("swap",option+1) == 0)
8079 {
8080 Image
8081 *p,
8082 *q,
8083 *swap;
8084
cristybb503372010-05-27 20:51:26 +00008085 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008086 swap_index;
8087
8088 index=(-1);
8089 swap_index=(-2);
8090 if (*option != '+')
8091 {
8092 GeometryInfo
8093 geometry_info;
8094
8095 MagickStatusType
8096 flags;
8097
8098 swap_index=(-1);
8099 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008100 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008101 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008102 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008103 }
8104 p=GetImageFromList(*images,index);
8105 q=GetImageFromList(*images,swap_index);
8106 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8107 {
8108 (void) ThrowMagickException(exception,GetMagickModule(),
8109 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8110 status=MagickFalse;
8111 break;
8112 }
8113 if (p == q)
8114 break;
8115 swap=CloneImage(p,0,0,MagickTrue,exception);
8116 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8117 ReplaceImageInList(&q,swap);
8118 *images=GetFirstImageInList(q);
8119 break;
8120 }
8121 break;
8122 }
8123 case 'w':
8124 {
8125 if (LocaleCompare("write",option+1) == 0)
8126 {
cristy071dd7b2010-04-09 13:04:54 +00008127 char
cristy06609ee2010-03-17 20:21:27 +00008128 key[MaxTextExtent];
8129
cristy3ed852e2009-09-05 21:47:34 +00008130 Image
8131 *write_images;
8132
8133 ImageInfo
8134 *write_info;
8135
cristy6b3da3a2010-06-20 02:21:46 +00008136 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008137 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008138 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008139 write_images=(*images);
8140 if (*option == '+')
8141 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008142 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008143 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8144 write_info=DestroyImageInfo(write_info);
8145 if (*option == '+')
8146 write_images=DestroyImageList(write_images);
8147 break;
8148 }
8149 break;
8150 }
8151 default:
8152 break;
8153 }
8154 i+=count;
8155 }
8156 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008157 mogrify_info=DestroyImageInfo(mogrify_info);
8158 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008159 return(status != 0 ? MagickTrue : MagickFalse);
8160}
8161
8162/*
8163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8164% %
8165% %
8166% %
8167+ M o g r i f y I m a g e s %
8168% %
8169% %
8170% %
8171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8172%
8173% MogrifyImages() applies image processing options to a sequence of images as
8174% prescribed by command line options.
8175%
8176% The format of the MogrifyImage method is:
8177%
8178% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8179% const MagickBooleanType post,const int argc,const char **argv,
8180% Image **images,Exceptioninfo *exception)
8181%
8182% A description of each parameter follows:
8183%
8184% o image_info: the image info..
8185%
8186% o post: If true, post process image list operators otherwise pre-process.
8187%
8188% o argc: Specifies a pointer to an integer describing the number of
8189% elements in the argument vector.
8190%
8191% o argv: Specifies a pointer to a text array containing the command line
8192% arguments.
8193%
anthonye9c27192011-03-27 08:07:06 +00008194% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008195%
8196% o exception: return any errors or warnings in this structure.
8197%
8198*/
8199WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8200 const MagickBooleanType post,const int argc,const char **argv,
8201 Image **images,ExceptionInfo *exception)
8202{
8203#define MogrifyImageTag "Mogrify/Image"
8204
anthonye9c27192011-03-27 08:07:06 +00008205 MagickStatusType
8206 status;
cristy3ed852e2009-09-05 21:47:34 +00008207
cristy0e9f9c12010-02-11 03:00:47 +00008208 MagickBooleanType
8209 proceed;
8210
anthonye9c27192011-03-27 08:07:06 +00008211 size_t
8212 n;
cristy3ed852e2009-09-05 21:47:34 +00008213
cristybb503372010-05-27 20:51:26 +00008214 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008215 i;
8216
cristy3ed852e2009-09-05 21:47:34 +00008217 assert(image_info != (ImageInfo *) NULL);
8218 assert(image_info->signature == MagickSignature);
8219 if (images == (Image **) NULL)
8220 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008221 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008222 assert((*images)->signature == MagickSignature);
8223 if ((*images)->debug != MagickFalse)
8224 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8225 (*images)->filename);
8226 if ((argc <= 0) || (*argv == (char *) NULL))
8227 return(MagickTrue);
8228 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8229 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008230 status=0;
anthonye9c27192011-03-27 08:07:06 +00008231
anthonyce2716b2011-04-22 09:51:34 +00008232#if 0
cristy1e604812011-05-19 18:07:50 +00008233 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8234 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008235#endif
8236
anthonye9c27192011-03-27 08:07:06 +00008237 /*
8238 Pre-process multi-image sequence operators
8239 */
cristy3ed852e2009-09-05 21:47:34 +00008240 if (post == MagickFalse)
8241 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008242 /*
8243 For each image, process simple single image operators
8244 */
8245 i=0;
8246 n=GetImageListLength(*images);
8247 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008248 {
anthonyce2716b2011-04-22 09:51:34 +00008249#if 0
cristy1e604812011-05-19 18:07:50 +00008250 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8251 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008252#endif
anthonye9c27192011-03-27 08:07:06 +00008253 status&=MogrifyImage(image_info,argc,argv,images,exception);
8254 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008255 if (proceed == MagickFalse)
8256 break;
anthonye9c27192011-03-27 08:07:06 +00008257 if ( (*images)->next == (Image *) NULL )
8258 break;
8259 *images=(*images)->next;
8260 i++;
cristy3ed852e2009-09-05 21:47:34 +00008261 }
anthonye9c27192011-03-27 08:07:06 +00008262 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008263#if 0
cristy1e604812011-05-19 18:07:50 +00008264 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8265 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008266#endif
anthonye9c27192011-03-27 08:07:06 +00008267
8268 /*
8269 Post-process, multi-image sequence operators
8270 */
8271 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008272 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008273 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008274 return(status != 0 ? MagickTrue : MagickFalse);
8275}