blob: f01b3ed3273a9ece8091657c00fcad000130bf4d [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;
cristy574cc262011-08-05 01:23:58 +00001065 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001066 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
cristyb3e7c6c2011-07-24 01:43:55 +00001691 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1692 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001693 break;
1694 }
1695 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1696 (LocaleCompare("gaussian",option+1) == 0))
1697 {
1698 /*
1699 Gaussian blur image.
1700 */
1701 (void) SyncImageSettings(mogrify_info,*image);
1702 flags=ParseGeometry(argv[i+1],&geometry_info);
1703 if ((flags & SigmaValue) == 0)
1704 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001705 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1706 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001707 break;
1708 }
1709 if (LocaleCompare("geometry",option+1) == 0)
1710 {
1711 /*
1712 Record Image offset, Resize last image.
1713 */
1714 (void) SyncImageSettings(mogrify_info,*image);
1715 if (*option == '+')
1716 {
1717 if ((*image)->geometry != (char *) NULL)
1718 (*image)->geometry=DestroyString((*image)->geometry);
1719 break;
1720 }
1721 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1722 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1723 (void) CloneString(&(*image)->geometry,argv[i+1]);
1724 else
1725 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1726 (*image)->filter,(*image)->blur,exception);
1727 break;
1728 }
1729 if (LocaleCompare("gravity",option+1) == 0)
1730 {
1731 if (*option == '+')
1732 {
1733 draw_info->gravity=UndefinedGravity;
1734 break;
1735 }
1736 draw_info->gravity=(GravityType) ParseCommandOption(
1737 MagickGravityOptions,MagickFalse,argv[i+1]);
1738 break;
1739 }
1740 break;
1741 }
1742 case 'h':
1743 {
1744 if (LocaleCompare("highlight-color",option+1) == 0)
1745 {
1746 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1747 break;
1748 }
1749 break;
1750 }
1751 case 'i':
1752 {
1753 if (LocaleCompare("identify",option+1) == 0)
1754 {
1755 char
1756 *text;
1757
1758 (void) SyncImageSettings(mogrify_info,*image);
1759 if (format == (char *) NULL)
1760 {
1761 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1762 InheritException(exception,&(*image)->exception);
1763 break;
1764 }
1765 text=InterpretImageProperties(mogrify_info,*image,format);
1766 InheritException(exception,&(*image)->exception);
1767 if (text == (char *) NULL)
1768 break;
1769 (void) fputs(text,stdout);
1770 (void) fputc('\n',stdout);
1771 text=DestroyString(text);
1772 break;
1773 }
1774 if (LocaleCompare("implode",option+1) == 0)
1775 {
1776 /*
1777 Implode image.
1778 */
1779 (void) SyncImageSettings(mogrify_info,*image);
1780 (void) ParseGeometry(argv[i+1],&geometry_info);
1781 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1782 break;
1783 }
1784 if (LocaleCompare("interline-spacing",option+1) == 0)
1785 {
1786 if (*option == '+')
1787 (void) ParseGeometry("0",&geometry_info);
1788 else
1789 (void) ParseGeometry(argv[i+1],&geometry_info);
1790 draw_info->interline_spacing=geometry_info.rho;
1791 break;
1792 }
1793 if (LocaleCompare("interword-spacing",option+1) == 0)
1794 {
1795 if (*option == '+')
1796 (void) ParseGeometry("0",&geometry_info);
1797 else
1798 (void) ParseGeometry(argv[i+1],&geometry_info);
1799 draw_info->interword_spacing=geometry_info.rho;
1800 break;
1801 }
1802 break;
1803 }
1804 case 'k':
1805 {
1806 if (LocaleCompare("kerning",option+1) == 0)
1807 {
1808 if (*option == '+')
1809 (void) ParseGeometry("0",&geometry_info);
1810 else
1811 (void) ParseGeometry(argv[i+1],&geometry_info);
1812 draw_info->kerning=geometry_info.rho;
1813 break;
1814 }
1815 break;
1816 }
1817 case 'l':
1818 {
1819 if (LocaleCompare("lat",option+1) == 0)
1820 {
1821 /*
1822 Local adaptive threshold image.
1823 */
1824 (void) SyncImageSettings(mogrify_info,*image);
1825 flags=ParseGeometry(argv[i+1],&geometry_info);
1826 if ((flags & PercentValue) != 0)
1827 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1828 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001829 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001830 geometry_info.xi,exception);
1831 break;
1832 }
1833 if (LocaleCompare("level",option+1) == 0)
1834 {
1835 MagickRealType
1836 black_point,
1837 gamma,
1838 white_point;
1839
1840 MagickStatusType
1841 flags;
1842
1843 /*
1844 Parse levels.
1845 */
1846 (void) SyncImageSettings(mogrify_info,*image);
1847 flags=ParseGeometry(argv[i+1],&geometry_info);
1848 black_point=geometry_info.rho;
1849 white_point=(MagickRealType) QuantumRange;
1850 if ((flags & SigmaValue) != 0)
1851 white_point=geometry_info.sigma;
1852 gamma=1.0;
1853 if ((flags & XiValue) != 0)
1854 gamma=geometry_info.xi;
1855 if ((flags & PercentValue) != 0)
1856 {
1857 black_point*=(MagickRealType) (QuantumRange/100.0);
1858 white_point*=(MagickRealType) (QuantumRange/100.0);
1859 }
1860 if ((flags & SigmaValue) == 0)
1861 white_point=(MagickRealType) QuantumRange-black_point;
1862 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy50fbc382011-07-07 02:19:17 +00001863 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001864 else
cristyf89cb1d2011-07-07 01:24:37 +00001865 (void) LevelImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001866 InheritException(exception,&(*image)->exception);
1867 break;
1868 }
1869 if (LocaleCompare("level-colors",option+1) == 0)
1870 {
1871 char
1872 token[MaxTextExtent];
1873
1874 const char
1875 *p;
1876
cristy4c08aed2011-07-01 19:47:50 +00001877 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001878 black_point,
1879 white_point;
1880
1881 p=(const char *) argv[i+1];
1882 GetMagickToken(p,&p,token); /* get black point color */
1883 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1884 (void) QueryMagickColor(token,&black_point,exception);
1885 else
1886 (void) QueryMagickColor("#000000",&black_point,exception);
1887 if (isalpha((int) token[0]) || (token[0] == '#'))
1888 GetMagickToken(p,&p,token);
1889 if (*token == '\0')
1890 white_point=black_point; /* set everything to that color */
1891 else
1892 {
1893 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1894 GetMagickToken(p,&p,token); /* Get white point color. */
1895 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1896 (void) QueryMagickColor(token,&white_point,exception);
1897 else
1898 (void) QueryMagickColor("#ffffff",&white_point,exception);
1899 }
cristy490408a2011-07-07 14:42:05 +00001900 (void) LevelImageColors(*image,&black_point,&white_point,
1901 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001902 break;
1903 }
1904 if (LocaleCompare("linear-stretch",option+1) == 0)
1905 {
1906 double
1907 black_point,
1908 white_point;
1909
1910 MagickStatusType
1911 flags;
1912
1913 (void) SyncImageSettings(mogrify_info,*image);
1914 flags=ParseGeometry(argv[i+1],&geometry_info);
1915 black_point=geometry_info.rho;
1916 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1917 if ((flags & SigmaValue) != 0)
1918 white_point=geometry_info.sigma;
1919 if ((flags & PercentValue) != 0)
1920 {
1921 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1922 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1923 }
1924 if ((flags & SigmaValue) == 0)
1925 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1926 black_point;
1927 (void) LinearStretchImage(*image,black_point,white_point);
1928 InheritException(exception,&(*image)->exception);
1929 break;
1930 }
1931 if (LocaleCompare("linewidth",option+1) == 0)
1932 {
cristyc1acd842011-05-19 23:05:47 +00001933 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1934 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001935 break;
1936 }
1937 if (LocaleCompare("liquid-rescale",option+1) == 0)
1938 {
1939 /*
1940 Liquid rescale image.
1941 */
1942 (void) SyncImageSettings(mogrify_info,*image);
1943 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1944 if ((flags & XValue) == 0)
1945 geometry.x=1;
1946 if ((flags & YValue) == 0)
1947 geometry.y=0;
1948 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1949 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1950 break;
1951 }
1952 if (LocaleCompare("lowlight-color",option+1) == 0)
1953 {
1954 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1955 break;
1956 }
1957 break;
1958 }
1959 case 'm':
1960 {
1961 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001962 {
cristy3ed852e2009-09-05 21:47:34 +00001963 Image
anthonydf8ebac2011-04-27 09:03:19 +00001964 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001965
anthonydf8ebac2011-04-27 09:03:19 +00001966 /*
1967 Transform image colors to match this set of colors.
1968 */
1969 (void) SyncImageSettings(mogrify_info,*image);
1970 if (*option == '+')
1971 break;
1972 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1973 if (remap_image == (Image *) NULL)
1974 break;
1975 (void) RemapImage(quantize_info,*image,remap_image);
1976 InheritException(exception,&(*image)->exception);
1977 remap_image=DestroyImage(remap_image);
1978 break;
1979 }
1980 if (LocaleCompare("mask",option+1) == 0)
1981 {
1982 Image
1983 *mask;
1984
1985 (void) SyncImageSettings(mogrify_info,*image);
1986 if (*option == '+')
1987 {
1988 /*
1989 Remove a mask.
1990 */
1991 (void) SetImageMask(*image,(Image *) NULL);
1992 InheritException(exception,&(*image)->exception);
1993 break;
1994 }
1995 /*
1996 Set the image mask.
1997 */
1998 mask=GetImageCache(mogrify_info,argv[i+1],exception);
1999 if (mask == (Image *) NULL)
2000 break;
2001 (void) SetImageMask(*image,mask);
2002 mask=DestroyImage(mask);
2003 InheritException(exception,&(*image)->exception);
2004 break;
2005 }
2006 if (LocaleCompare("matte",option+1) == 0)
2007 {
2008 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2009 SetAlphaChannel : DeactivateAlphaChannel );
2010 InheritException(exception,&(*image)->exception);
2011 break;
2012 }
2013 if (LocaleCompare("median",option+1) == 0)
2014 {
2015 /*
2016 Median filter image.
2017 */
2018 (void) SyncImageSettings(mogrify_info,*image);
2019 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002020 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2021 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002022 break;
2023 }
2024 if (LocaleCompare("mode",option+1) == 0)
2025 {
2026 /*
2027 Mode image.
2028 */
2029 (void) SyncImageSettings(mogrify_info,*image);
2030 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002031 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2032 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002033 break;
2034 }
2035 if (LocaleCompare("modulate",option+1) == 0)
2036 {
2037 (void) SyncImageSettings(mogrify_info,*image);
2038 (void) ModulateImage(*image,argv[i+1]);
2039 InheritException(exception,&(*image)->exception);
2040 break;
2041 }
2042 if (LocaleCompare("monitor",option+1) == 0)
2043 {
2044 if (*option == '+')
2045 {
2046 (void) SetImageProgressMonitor(*image,
2047 (MagickProgressMonitor) NULL,(void *) NULL);
2048 break;
2049 }
2050 (void) SetImageProgressMonitor(*image,MonitorProgress,
2051 (void *) NULL);
2052 break;
2053 }
2054 if (LocaleCompare("monochrome",option+1) == 0)
2055 {
2056 (void) SyncImageSettings(mogrify_info,*image);
2057 (void) SetImageType(*image,BilevelType);
2058 InheritException(exception,&(*image)->exception);
2059 break;
2060 }
2061 if (LocaleCompare("morphology",option+1) == 0)
2062 {
2063 char
2064 token[MaxTextExtent];
2065
2066 const char
2067 *p;
2068
2069 KernelInfo
2070 *kernel;
2071
2072 MorphologyMethod
2073 method;
2074
2075 ssize_t
2076 iterations;
2077
2078 /*
2079 Morphological Image Operation
2080 */
2081 (void) SyncImageSettings(mogrify_info,*image);
2082 p=argv[i+1];
2083 GetMagickToken(p,&p,token);
2084 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2085 MagickFalse,token);
2086 iterations=1L;
2087 GetMagickToken(p,&p,token);
2088 if ((*p == ':') || (*p == ','))
2089 GetMagickToken(p,&p,token);
2090 if ((*p != '\0'))
2091 iterations=(ssize_t) StringToLong(p);
2092 kernel=AcquireKernelInfo(argv[i+2]);
2093 if (kernel == (KernelInfo *) NULL)
2094 {
2095 (void) ThrowMagickException(exception,GetMagickModule(),
2096 OptionError,"UnabletoParseKernel","morphology");
2097 status=MagickFalse;
2098 break;
2099 }
cristyf4ad9df2011-07-08 16:49:03 +00002100 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2101 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002102 kernel=DestroyKernelInfo(kernel);
2103 break;
2104 }
2105 if (LocaleCompare("motion-blur",option+1) == 0)
2106 {
2107 /*
2108 Motion blur image.
2109 */
2110 (void) SyncImageSettings(mogrify_info,*image);
2111 flags=ParseGeometry(argv[i+1],&geometry_info);
2112 if ((flags & SigmaValue) == 0)
2113 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002114 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2115 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002116 break;
2117 }
2118 break;
2119 }
2120 case 'n':
2121 {
2122 if (LocaleCompare("negate",option+1) == 0)
2123 {
2124 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002125 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002126 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002127 break;
2128 }
2129 if (LocaleCompare("noise",option+1) == 0)
2130 {
2131 (void) SyncImageSettings(mogrify_info,*image);
2132 if (*option == '-')
2133 {
2134 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002135 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2136 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002137 }
2138 else
2139 {
2140 NoiseType
2141 noise;
2142
2143 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2144 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002145 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002146 }
2147 break;
2148 }
2149 if (LocaleCompare("normalize",option+1) == 0)
2150 {
2151 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002152 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002153 InheritException(exception,&(*image)->exception);
2154 break;
2155 }
2156 break;
2157 }
2158 case 'o':
2159 {
2160 if (LocaleCompare("opaque",option+1) == 0)
2161 {
cristy4c08aed2011-07-01 19:47:50 +00002162 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002163 target;
2164
2165 (void) SyncImageSettings(mogrify_info,*image);
2166 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002167 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2168 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002169 break;
2170 }
2171 if (LocaleCompare("ordered-dither",option+1) == 0)
2172 {
2173 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002174 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002175 break;
2176 }
2177 break;
2178 }
2179 case 'p':
2180 {
2181 if (LocaleCompare("paint",option+1) == 0)
2182 {
anthonydf8ebac2011-04-27 09:03:19 +00002183 (void) SyncImageSettings(mogrify_info,*image);
2184 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002185 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002186 break;
2187 }
2188 if (LocaleCompare("pen",option+1) == 0)
2189 {
2190 if (*option == '+')
2191 {
2192 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2193 break;
2194 }
2195 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2196 break;
2197 }
2198 if (LocaleCompare("pointsize",option+1) == 0)
2199 {
2200 if (*option == '+')
2201 (void) ParseGeometry("12",&geometry_info);
2202 else
2203 (void) ParseGeometry(argv[i+1],&geometry_info);
2204 draw_info->pointsize=geometry_info.rho;
2205 break;
2206 }
2207 if (LocaleCompare("polaroid",option+1) == 0)
2208 {
2209 double
2210 angle;
2211
2212 RandomInfo
2213 *random_info;
2214
2215 /*
2216 Simulate a Polaroid picture.
2217 */
2218 (void) SyncImageSettings(mogrify_info,*image);
2219 random_info=AcquireRandomInfo();
2220 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2221 random_info=DestroyRandomInfo(random_info);
2222 if (*option == '-')
2223 {
2224 SetGeometryInfo(&geometry_info);
2225 flags=ParseGeometry(argv[i+1],&geometry_info);
2226 angle=geometry_info.rho;
2227 }
2228 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2229 break;
2230 }
2231 if (LocaleCompare("posterize",option+1) == 0)
2232 {
2233 /*
2234 Posterize image.
2235 */
2236 (void) SyncImageSettings(mogrify_info,*image);
2237 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2238 quantize_info->dither);
2239 InheritException(exception,&(*image)->exception);
2240 break;
2241 }
2242 if (LocaleCompare("preview",option+1) == 0)
2243 {
2244 PreviewType
2245 preview_type;
2246
2247 /*
2248 Preview image.
2249 */
2250 (void) SyncImageSettings(mogrify_info,*image);
2251 if (*option == '+')
2252 preview_type=UndefinedPreview;
2253 else
2254 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2255 MagickFalse,argv[i+1]);
2256 mogrify_image=PreviewImage(*image,preview_type,exception);
2257 break;
2258 }
2259 if (LocaleCompare("profile",option+1) == 0)
2260 {
2261 const char
2262 *name;
2263
2264 const StringInfo
2265 *profile;
2266
2267 Image
2268 *profile_image;
2269
2270 ImageInfo
2271 *profile_info;
2272
2273 (void) SyncImageSettings(mogrify_info,*image);
2274 if (*option == '+')
2275 {
2276 /*
2277 Remove a profile from the image.
2278 */
2279 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2280 NULL,0,MagickTrue);
2281 InheritException(exception,&(*image)->exception);
2282 break;
2283 }
2284 /*
2285 Associate a profile with the image.
2286 */
2287 profile_info=CloneImageInfo(mogrify_info);
2288 profile=GetImageProfile(*image,"iptc");
2289 if (profile != (StringInfo *) NULL)
2290 profile_info->profile=(void *) CloneStringInfo(profile);
2291 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2292 profile_info=DestroyImageInfo(profile_info);
2293 if (profile_image == (Image *) NULL)
2294 {
2295 StringInfo
2296 *profile;
2297
2298 profile_info=CloneImageInfo(mogrify_info);
2299 (void) CopyMagickString(profile_info->filename,argv[i+1],
2300 MaxTextExtent);
2301 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2302 if (profile != (StringInfo *) NULL)
2303 {
2304 (void) ProfileImage(*image,profile_info->magick,
2305 GetStringInfoDatum(profile),(size_t)
2306 GetStringInfoLength(profile),MagickFalse);
2307 profile=DestroyStringInfo(profile);
2308 }
2309 profile_info=DestroyImageInfo(profile_info);
2310 break;
2311 }
2312 ResetImageProfileIterator(profile_image);
2313 name=GetNextImageProfile(profile_image);
2314 while (name != (const char *) NULL)
2315 {
2316 profile=GetImageProfile(profile_image,name);
2317 if (profile != (StringInfo *) NULL)
2318 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2319 (size_t) GetStringInfoLength(profile),MagickFalse);
2320 name=GetNextImageProfile(profile_image);
2321 }
2322 profile_image=DestroyImage(profile_image);
2323 break;
2324 }
2325 break;
2326 }
2327 case 'q':
2328 {
2329 if (LocaleCompare("quantize",option+1) == 0)
2330 {
2331 if (*option == '+')
2332 {
2333 quantize_info->colorspace=UndefinedColorspace;
2334 break;
2335 }
2336 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2337 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2338 break;
2339 }
2340 break;
2341 }
2342 case 'r':
2343 {
2344 if (LocaleCompare("radial-blur",option+1) == 0)
2345 {
2346 /*
2347 Radial blur image.
2348 */
2349 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002350 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2351 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002352 break;
2353 }
2354 if (LocaleCompare("raise",option+1) == 0)
2355 {
2356 /*
2357 Surround image with a raise of solid color.
2358 */
2359 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2360 if ((flags & SigmaValue) == 0)
2361 geometry.height=geometry.width;
2362 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2363 MagickFalse);
2364 InheritException(exception,&(*image)->exception);
2365 break;
2366 }
2367 if (LocaleCompare("random-threshold",option+1) == 0)
2368 {
2369 /*
2370 Threshold image.
2371 */
2372 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002373 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002374 break;
2375 }
2376 if (LocaleCompare("recolor",option+1) == 0)
2377 {
2378 KernelInfo
2379 *kernel;
2380
2381 (void) SyncImageSettings(mogrify_info,*image);
2382 kernel=AcquireKernelInfo(argv[i+1]);
2383 if (kernel == (KernelInfo *) NULL)
2384 break;
2385 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2386 kernel=DestroyKernelInfo(kernel);
2387 break;
2388 }
2389 if (LocaleCompare("region",option+1) == 0)
2390 {
2391 (void) SyncImageSettings(mogrify_info,*image);
2392 if (region_image != (Image *) NULL)
2393 {
2394 /*
2395 Composite region.
2396 */
2397 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002398 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2399 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002400 InheritException(exception,&region_image->exception);
2401 *image=DestroyImage(*image);
2402 *image=region_image;
2403 region_image = (Image *) NULL;
2404 }
2405 if (*option == '+')
2406 break;
2407 /*
2408 Apply transformations to a selected region of the image.
2409 */
cristy3ed852e2009-09-05 21:47:34 +00002410 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2411 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002412 mogrify_image=CropImage(*image,&region_geometry,exception);
2413 if (mogrify_image == (Image *) NULL)
2414 break;
2415 region_image=(*image);
2416 *image=mogrify_image;
2417 mogrify_image=(Image *) NULL;
2418 break;
cristy3ed852e2009-09-05 21:47:34 +00002419 }
anthonydf8ebac2011-04-27 09:03:19 +00002420 if (LocaleCompare("render",option+1) == 0)
2421 {
2422 (void) SyncImageSettings(mogrify_info,*image);
2423 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2424 break;
2425 }
2426 if (LocaleCompare("remap",option+1) == 0)
2427 {
2428 Image
2429 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002430
anthonydf8ebac2011-04-27 09:03:19 +00002431 /*
2432 Transform image colors to match this set of colors.
2433 */
2434 (void) SyncImageSettings(mogrify_info,*image);
2435 if (*option == '+')
2436 break;
2437 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2438 if (remap_image == (Image *) NULL)
2439 break;
2440 (void) RemapImage(quantize_info,*image,remap_image);
2441 InheritException(exception,&(*image)->exception);
2442 remap_image=DestroyImage(remap_image);
2443 break;
2444 }
2445 if (LocaleCompare("repage",option+1) == 0)
2446 {
2447 if (*option == '+')
2448 {
2449 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2450 break;
2451 }
2452 (void) ResetImagePage(*image,argv[i+1]);
2453 InheritException(exception,&(*image)->exception);
2454 break;
2455 }
2456 if (LocaleCompare("resample",option+1) == 0)
2457 {
2458 /*
2459 Resample image.
2460 */
2461 (void) SyncImageSettings(mogrify_info,*image);
2462 flags=ParseGeometry(argv[i+1],&geometry_info);
2463 if ((flags & SigmaValue) == 0)
2464 geometry_info.sigma=geometry_info.rho;
2465 mogrify_image=ResampleImage(*image,geometry_info.rho,
2466 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2467 break;
2468 }
2469 if (LocaleCompare("resize",option+1) == 0)
2470 {
2471 /*
2472 Resize image.
2473 */
2474 (void) SyncImageSettings(mogrify_info,*image);
2475 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2476 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2477 (*image)->filter,(*image)->blur,exception);
2478 break;
2479 }
2480 if (LocaleCompare("roll",option+1) == 0)
2481 {
2482 /*
2483 Roll image.
2484 */
2485 (void) SyncImageSettings(mogrify_info,*image);
2486 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2487 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2488 break;
2489 }
2490 if (LocaleCompare("rotate",option+1) == 0)
2491 {
2492 char
2493 *geometry;
2494
2495 /*
2496 Check for conditional image rotation.
2497 */
2498 (void) SyncImageSettings(mogrify_info,*image);
2499 if (strchr(argv[i+1],'>') != (char *) NULL)
2500 if ((*image)->columns <= (*image)->rows)
2501 break;
2502 if (strchr(argv[i+1],'<') != (char *) NULL)
2503 if ((*image)->columns >= (*image)->rows)
2504 break;
2505 /*
2506 Rotate image.
2507 */
2508 geometry=ConstantString(argv[i+1]);
2509 (void) SubstituteString(&geometry,">","");
2510 (void) SubstituteString(&geometry,"<","");
2511 (void) ParseGeometry(geometry,&geometry_info);
2512 geometry=DestroyString(geometry);
2513 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2514 break;
2515 }
2516 break;
2517 }
2518 case 's':
2519 {
2520 if (LocaleCompare("sample",option+1) == 0)
2521 {
2522 /*
2523 Sample image with pixel replication.
2524 */
2525 (void) SyncImageSettings(mogrify_info,*image);
2526 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2527 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2528 exception);
2529 break;
2530 }
2531 if (LocaleCompare("scale",option+1) == 0)
2532 {
2533 /*
2534 Resize image.
2535 */
2536 (void) SyncImageSettings(mogrify_info,*image);
2537 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2538 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2539 exception);
2540 break;
2541 }
2542 if (LocaleCompare("selective-blur",option+1) == 0)
2543 {
2544 /*
2545 Selectively blur pixels within a contrast threshold.
2546 */
2547 (void) SyncImageSettings(mogrify_info,*image);
2548 flags=ParseGeometry(argv[i+1],&geometry_info);
2549 if ((flags & PercentValue) != 0)
2550 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002551 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2552 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002553 break;
2554 }
2555 if (LocaleCompare("separate",option+1) == 0)
2556 {
2557 /*
2558 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002559 */
2560 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002561 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002562 break;
2563 }
2564 if (LocaleCompare("sepia-tone",option+1) == 0)
2565 {
2566 double
2567 threshold;
2568
2569 /*
2570 Sepia-tone image.
2571 */
2572 (void) SyncImageSettings(mogrify_info,*image);
2573 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2574 mogrify_image=SepiaToneImage(*image,threshold,exception);
2575 break;
2576 }
2577 if (LocaleCompare("segment",option+1) == 0)
2578 {
2579 /*
2580 Segment image.
2581 */
2582 (void) SyncImageSettings(mogrify_info,*image);
2583 flags=ParseGeometry(argv[i+1],&geometry_info);
2584 if ((flags & SigmaValue) == 0)
2585 geometry_info.sigma=1.0;
2586 (void) SegmentImage(*image,(*image)->colorspace,
2587 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2588 InheritException(exception,&(*image)->exception);
2589 break;
2590 }
2591 if (LocaleCompare("set",option+1) == 0)
2592 {
2593 char
2594 *value;
2595
2596 /*
2597 Set image option.
2598 */
2599 if (*option == '+')
2600 {
2601 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2602 (void) DeleteImageRegistry(argv[i+1]+9);
2603 else
2604 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2605 {
2606 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2607 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2608 }
2609 else
2610 (void) DeleteImageProperty(*image,argv[i+1]);
2611 break;
2612 }
2613 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2614 if (value == (char *) NULL)
2615 break;
2616 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2617 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2618 exception);
2619 else
2620 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2621 {
2622 (void) SetImageOption(image_info,argv[i+1]+7,value);
2623 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2624 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2625 }
2626 else
2627 (void) SetImageProperty(*image,argv[i+1],value);
2628 value=DestroyString(value);
2629 break;
2630 }
2631 if (LocaleCompare("shade",option+1) == 0)
2632 {
2633 /*
2634 Shade image.
2635 */
2636 (void) SyncImageSettings(mogrify_info,*image);
2637 flags=ParseGeometry(argv[i+1],&geometry_info);
2638 if ((flags & SigmaValue) == 0)
2639 geometry_info.sigma=1.0;
2640 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2641 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2642 break;
2643 }
2644 if (LocaleCompare("shadow",option+1) == 0)
2645 {
2646 /*
2647 Shadow image.
2648 */
2649 (void) SyncImageSettings(mogrify_info,*image);
2650 flags=ParseGeometry(argv[i+1],&geometry_info);
2651 if ((flags & SigmaValue) == 0)
2652 geometry_info.sigma=1.0;
2653 if ((flags & XiValue) == 0)
2654 geometry_info.xi=4.0;
2655 if ((flags & PsiValue) == 0)
2656 geometry_info.psi=4.0;
2657 mogrify_image=ShadowImage(*image,geometry_info.rho,
2658 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2659 ceil(geometry_info.psi-0.5),exception);
2660 break;
2661 }
2662 if (LocaleCompare("sharpen",option+1) == 0)
2663 {
2664 /*
2665 Sharpen image.
2666 */
2667 (void) SyncImageSettings(mogrify_info,*image);
2668 flags=ParseGeometry(argv[i+1],&geometry_info);
2669 if ((flags & SigmaValue) == 0)
2670 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002671 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002672 geometry_info.sigma,exception);
2673 break;
2674 }
2675 if (LocaleCompare("shave",option+1) == 0)
2676 {
2677 /*
2678 Shave the image edges.
2679 */
2680 (void) SyncImageSettings(mogrify_info,*image);
2681 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2682 mogrify_image=ShaveImage(*image,&geometry,exception);
2683 break;
2684 }
2685 if (LocaleCompare("shear",option+1) == 0)
2686 {
2687 /*
2688 Shear image.
2689 */
2690 (void) SyncImageSettings(mogrify_info,*image);
2691 flags=ParseGeometry(argv[i+1],&geometry_info);
2692 if ((flags & SigmaValue) == 0)
2693 geometry_info.sigma=geometry_info.rho;
2694 mogrify_image=ShearImage(*image,geometry_info.rho,
2695 geometry_info.sigma,exception);
2696 break;
2697 }
2698 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2699 {
2700 /*
2701 Sigmoidal non-linearity contrast control.
2702 */
2703 (void) SyncImageSettings(mogrify_info,*image);
2704 flags=ParseGeometry(argv[i+1],&geometry_info);
2705 if ((flags & SigmaValue) == 0)
2706 geometry_info.sigma=(double) QuantumRange/2.0;
2707 if ((flags & PercentValue) != 0)
2708 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2709 100.0;
cristy9ee60942011-07-06 14:54:38 +00002710 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2711 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002712 InheritException(exception,&(*image)->exception);
2713 break;
2714 }
2715 if (LocaleCompare("sketch",option+1) == 0)
2716 {
2717 /*
2718 Sketch image.
2719 */
2720 (void) SyncImageSettings(mogrify_info,*image);
2721 flags=ParseGeometry(argv[i+1],&geometry_info);
2722 if ((flags & SigmaValue) == 0)
2723 geometry_info.sigma=1.0;
2724 mogrify_image=SketchImage(*image,geometry_info.rho,
2725 geometry_info.sigma,geometry_info.xi,exception);
2726 break;
2727 }
2728 if (LocaleCompare("solarize",option+1) == 0)
2729 {
2730 double
2731 threshold;
2732
2733 (void) SyncImageSettings(mogrify_info,*image);
2734 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2735 (void) SolarizeImage(*image,threshold);
2736 InheritException(exception,&(*image)->exception);
2737 break;
2738 }
2739 if (LocaleCompare("sparse-color",option+1) == 0)
2740 {
2741 SparseColorMethod
2742 method;
2743
2744 char
2745 *arguments;
2746
2747 /*
2748 Sparse Color Interpolated Gradient
2749 */
2750 (void) SyncImageSettings(mogrify_info,*image);
2751 method=(SparseColorMethod) ParseCommandOption(
2752 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2753 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2754 InheritException(exception,&(*image)->exception);
2755 if (arguments == (char *) NULL)
2756 break;
cristy3884f692011-07-08 18:00:18 +00002757 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002758 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2759 arguments=DestroyString(arguments);
2760 break;
2761 }
2762 if (LocaleCompare("splice",option+1) == 0)
2763 {
2764 /*
2765 Splice a solid color into the image.
2766 */
2767 (void) SyncImageSettings(mogrify_info,*image);
2768 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2769 mogrify_image=SpliceImage(*image,&geometry,exception);
2770 break;
2771 }
2772 if (LocaleCompare("spread",option+1) == 0)
2773 {
2774 /*
2775 Spread an image.
2776 */
2777 (void) SyncImageSettings(mogrify_info,*image);
2778 (void) ParseGeometry(argv[i+1],&geometry_info);
2779 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2780 break;
2781 }
2782 if (LocaleCompare("statistic",option+1) == 0)
2783 {
2784 StatisticType
2785 type;
2786
2787 (void) SyncImageSettings(mogrify_info,*image);
2788 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2789 MagickFalse,argv[i+1]);
2790 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002791 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2792 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002793 break;
2794 }
2795 if (LocaleCompare("stretch",option+1) == 0)
2796 {
2797 if (*option == '+')
2798 {
2799 draw_info->stretch=UndefinedStretch;
2800 break;
2801 }
2802 draw_info->stretch=(StretchType) ParseCommandOption(
2803 MagickStretchOptions,MagickFalse,argv[i+1]);
2804 break;
2805 }
2806 if (LocaleCompare("strip",option+1) == 0)
2807 {
2808 /*
2809 Strip image of profiles and comments.
2810 */
2811 (void) SyncImageSettings(mogrify_info,*image);
2812 (void) StripImage(*image);
2813 InheritException(exception,&(*image)->exception);
2814 break;
2815 }
2816 if (LocaleCompare("stroke",option+1) == 0)
2817 {
2818 ExceptionInfo
2819 *sans;
2820
2821 if (*option == '+')
2822 {
2823 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2824 if (draw_info->stroke_pattern != (Image *) NULL)
2825 draw_info->stroke_pattern=DestroyImage(
2826 draw_info->stroke_pattern);
2827 break;
2828 }
2829 sans=AcquireExceptionInfo();
2830 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2831 sans=DestroyExceptionInfo(sans);
2832 if (status == MagickFalse)
2833 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2834 exception);
2835 break;
2836 }
2837 if (LocaleCompare("strokewidth",option+1) == 0)
2838 {
cristyc1acd842011-05-19 23:05:47 +00002839 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2840 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002841 break;
2842 }
2843 if (LocaleCompare("style",option+1) == 0)
2844 {
2845 if (*option == '+')
2846 {
2847 draw_info->style=UndefinedStyle;
2848 break;
2849 }
2850 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2851 MagickFalse,argv[i+1]);
2852 break;
2853 }
2854 if (LocaleCompare("swirl",option+1) == 0)
2855 {
2856 /*
2857 Swirl image.
2858 */
2859 (void) SyncImageSettings(mogrify_info,*image);
2860 (void) ParseGeometry(argv[i+1],&geometry_info);
2861 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2862 break;
2863 }
2864 break;
2865 }
2866 case 't':
2867 {
2868 if (LocaleCompare("threshold",option+1) == 0)
2869 {
2870 double
2871 threshold;
2872
2873 /*
2874 Threshold image.
2875 */
2876 (void) SyncImageSettings(mogrify_info,*image);
2877 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002878 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002879 else
2880 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002881 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002882 InheritException(exception,&(*image)->exception);
2883 break;
2884 }
2885 if (LocaleCompare("thumbnail",option+1) == 0)
2886 {
2887 /*
2888 Thumbnail image.
2889 */
2890 (void) SyncImageSettings(mogrify_info,*image);
2891 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2892 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2893 exception);
2894 break;
2895 }
2896 if (LocaleCompare("tile",option+1) == 0)
2897 {
2898 if (*option == '+')
2899 {
2900 if (draw_info->fill_pattern != (Image *) NULL)
2901 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2902 break;
2903 }
2904 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2905 exception);
2906 break;
2907 }
2908 if (LocaleCompare("tint",option+1) == 0)
2909 {
2910 /*
2911 Tint the image.
2912 */
2913 (void) SyncImageSettings(mogrify_info,*image);
2914 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2915 break;
2916 }
2917 if (LocaleCompare("transform",option+1) == 0)
2918 {
2919 /*
2920 Affine transform image.
2921 */
2922 (void) SyncImageSettings(mogrify_info,*image);
2923 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2924 exception);
2925 break;
2926 }
2927 if (LocaleCompare("transparent",option+1) == 0)
2928 {
cristy4c08aed2011-07-01 19:47:50 +00002929 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002930 target;
2931
2932 (void) SyncImageSettings(mogrify_info,*image);
2933 (void) QueryMagickColor(argv[i+1],&target,exception);
2934 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002935 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002936 InheritException(exception,&(*image)->exception);
2937 break;
2938 }
2939 if (LocaleCompare("transpose",option+1) == 0)
2940 {
2941 /*
2942 Transpose image scanlines.
2943 */
2944 (void) SyncImageSettings(mogrify_info,*image);
2945 mogrify_image=TransposeImage(*image,exception);
2946 break;
2947 }
2948 if (LocaleCompare("transverse",option+1) == 0)
2949 {
2950 /*
2951 Transverse image scanlines.
2952 */
2953 (void) SyncImageSettings(mogrify_info,*image);
2954 mogrify_image=TransverseImage(*image,exception);
2955 break;
2956 }
2957 if (LocaleCompare("treedepth",option+1) == 0)
2958 {
2959 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2960 break;
2961 }
2962 if (LocaleCompare("trim",option+1) == 0)
2963 {
2964 /*
2965 Trim image.
2966 */
2967 (void) SyncImageSettings(mogrify_info,*image);
2968 mogrify_image=TrimImage(*image,exception);
2969 break;
2970 }
2971 if (LocaleCompare("type",option+1) == 0)
2972 {
2973 ImageType
2974 type;
2975
2976 (void) SyncImageSettings(mogrify_info,*image);
2977 if (*option == '+')
2978 type=UndefinedType;
2979 else
2980 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2981 argv[i+1]);
2982 (*image)->type=UndefinedType;
2983 (void) SetImageType(*image,type);
2984 InheritException(exception,&(*image)->exception);
2985 break;
2986 }
2987 break;
2988 }
2989 case 'u':
2990 {
2991 if (LocaleCompare("undercolor",option+1) == 0)
2992 {
2993 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
2994 exception);
2995 break;
2996 }
2997 if (LocaleCompare("unique",option+1) == 0)
2998 {
2999 if (*option == '+')
3000 {
3001 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3002 break;
3003 }
3004 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3005 (void) SetImageArtifact(*image,"verbose","true");
3006 break;
3007 }
3008 if (LocaleCompare("unique-colors",option+1) == 0)
3009 {
3010 /*
3011 Unique image colors.
3012 */
3013 (void) SyncImageSettings(mogrify_info,*image);
3014 mogrify_image=UniqueImageColors(*image,exception);
3015 break;
3016 }
3017 if (LocaleCompare("unsharp",option+1) == 0)
3018 {
3019 /*
3020 Unsharp mask image.
3021 */
3022 (void) SyncImageSettings(mogrify_info,*image);
3023 flags=ParseGeometry(argv[i+1],&geometry_info);
3024 if ((flags & SigmaValue) == 0)
3025 geometry_info.sigma=1.0;
3026 if ((flags & XiValue) == 0)
3027 geometry_info.xi=1.0;
3028 if ((flags & PsiValue) == 0)
3029 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003030 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3031 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003032 break;
3033 }
3034 break;
3035 }
3036 case 'v':
3037 {
3038 if (LocaleCompare("verbose",option+1) == 0)
3039 {
3040 (void) SetImageArtifact(*image,option+1,
3041 *option == '+' ? "false" : "true");
3042 break;
3043 }
3044 if (LocaleCompare("vignette",option+1) == 0)
3045 {
3046 /*
3047 Vignette image.
3048 */
3049 (void) SyncImageSettings(mogrify_info,*image);
3050 flags=ParseGeometry(argv[i+1],&geometry_info);
3051 if ((flags & SigmaValue) == 0)
3052 geometry_info.sigma=1.0;
3053 if ((flags & XiValue) == 0)
3054 geometry_info.xi=0.1*(*image)->columns;
3055 if ((flags & PsiValue) == 0)
3056 geometry_info.psi=0.1*(*image)->rows;
3057 mogrify_image=VignetteImage(*image,geometry_info.rho,
3058 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3059 ceil(geometry_info.psi-0.5),exception);
3060 break;
3061 }
3062 if (LocaleCompare("virtual-pixel",option+1) == 0)
3063 {
3064 if (*option == '+')
3065 {
3066 (void) SetImageVirtualPixelMethod(*image,
3067 UndefinedVirtualPixelMethod);
3068 break;
3069 }
3070 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3071 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3072 argv[i+1]));
3073 break;
3074 }
3075 break;
3076 }
3077 case 'w':
3078 {
3079 if (LocaleCompare("wave",option+1) == 0)
3080 {
3081 /*
3082 Wave image.
3083 */
3084 (void) SyncImageSettings(mogrify_info,*image);
3085 flags=ParseGeometry(argv[i+1],&geometry_info);
3086 if ((flags & SigmaValue) == 0)
3087 geometry_info.sigma=1.0;
3088 mogrify_image=WaveImage(*image,geometry_info.rho,
3089 geometry_info.sigma,exception);
3090 break;
3091 }
3092 if (LocaleCompare("weight",option+1) == 0)
3093 {
3094 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3095 if (LocaleCompare(argv[i+1],"all") == 0)
3096 draw_info->weight=0;
3097 if (LocaleCompare(argv[i+1],"bold") == 0)
3098 draw_info->weight=700;
3099 if (LocaleCompare(argv[i+1],"bolder") == 0)
3100 if (draw_info->weight <= 800)
3101 draw_info->weight+=100;
3102 if (LocaleCompare(argv[i+1],"lighter") == 0)
3103 if (draw_info->weight >= 100)
3104 draw_info->weight-=100;
3105 if (LocaleCompare(argv[i+1],"normal") == 0)
3106 draw_info->weight=400;
3107 break;
3108 }
3109 if (LocaleCompare("white-threshold",option+1) == 0)
3110 {
3111 /*
3112 White threshold image.
3113 */
3114 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003115 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003116 InheritException(exception,&(*image)->exception);
3117 break;
3118 }
3119 break;
3120 }
3121 default:
3122 break;
3123 }
3124 /*
3125 Replace current image with any image that was generated
3126 */
3127 if (mogrify_image != (Image *) NULL)
3128 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003129 i+=count;
3130 }
3131 if (region_image != (Image *) NULL)
3132 {
anthonydf8ebac2011-04-27 09:03:19 +00003133 /*
3134 Composite transformed region onto image.
3135 */
cristy6b3da3a2010-06-20 02:21:46 +00003136 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003137 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003138 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3139 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003140 InheritException(exception,&region_image->exception);
3141 *image=DestroyImage(*image);
3142 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003143 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003144 }
3145 /*
3146 Free resources.
3147 */
anthonydf8ebac2011-04-27 09:03:19 +00003148 quantize_info=DestroyQuantizeInfo(quantize_info);
3149 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003150 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003151 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003152 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003153 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003154}
3155
3156/*
3157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3158% %
3159% %
3160% %
cristy5063d812010-10-19 16:28:10 +00003161+ 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 +00003162% %
3163% %
3164% %
3165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3166%
3167% MogrifyImageCommand() transforms an image or a sequence of images. These
3168% transforms include image scaling, image rotation, color reduction, and
3169% others. The transmogrified image overwrites the original image.
3170%
3171% The format of the MogrifyImageCommand method is:
3172%
3173% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3174% const char **argv,char **metadata,ExceptionInfo *exception)
3175%
3176% A description of each parameter follows:
3177%
3178% o image_info: the image info.
3179%
3180% o argc: the number of elements in the argument vector.
3181%
3182% o argv: A text array containing the command line arguments.
3183%
3184% o metadata: any metadata is returned here.
3185%
3186% o exception: return any errors or warnings in this structure.
3187%
3188*/
3189
3190static MagickBooleanType MogrifyUsage(void)
3191{
3192 static const char
3193 *miscellaneous[]=
3194 {
3195 "-debug events display copious debugging information",
3196 "-help print program options",
3197 "-list type print a list of supported option arguments",
3198 "-log format format of debugging information",
3199 "-version print version information",
3200 (char *) NULL
3201 },
3202 *operators[]=
3203 {
3204 "-adaptive-blur geometry",
3205 " adaptively blur pixels; decrease effect near edges",
3206 "-adaptive-resize geometry",
3207 " adaptively resize image using 'mesh' interpolation",
3208 "-adaptive-sharpen geometry",
3209 " adaptively sharpen pixels; increase effect near edges",
3210 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3211 " transparent, extract, background, or shape",
3212 "-annotate geometry text",
3213 " annotate the image with text",
3214 "-auto-gamma automagically adjust gamma level of image",
3215 "-auto-level automagically adjust color levels of image",
3216 "-auto-orient automagically orient (rotate) image",
3217 "-bench iterations measure performance",
3218 "-black-threshold value",
3219 " force all pixels below the threshold into black",
3220 "-blue-shift simulate a scene at nighttime in the moonlight",
3221 "-blur geometry reduce image noise and reduce detail levels",
3222 "-border geometry surround image with a border of color",
3223 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003224 "-brightness-contrast geometry",
3225 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003226 "-cdl filename color correct with a color decision list",
3227 "-charcoal radius simulate a charcoal drawing",
3228 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003229 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003230 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003231 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003232 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003233 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003234 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003235 "-contrast enhance or reduce the image contrast",
3236 "-contrast-stretch geometry",
3237 " improve contrast by `stretching' the intensity range",
3238 "-convolve coefficients",
3239 " apply a convolution kernel to the image",
3240 "-cycle amount cycle the image colormap",
3241 "-decipher filename convert cipher pixels to plain pixels",
3242 "-deskew threshold straighten an image",
3243 "-despeckle reduce the speckles within an image",
3244 "-distort method args",
3245 " distort images according to given method ad args",
3246 "-draw string annotate the image with a graphic primitive",
3247 "-edge radius apply a filter to detect edges in the image",
3248 "-encipher filename convert plain pixels to cipher pixels",
3249 "-emboss radius emboss an image",
3250 "-enhance apply a digital filter to enhance a noisy image",
3251 "-equalize perform histogram equalization to an image",
3252 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003253 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003254 "-extent geometry set the image size",
3255 "-extract geometry extract area from image",
3256 "-fft implements the discrete Fourier transform (DFT)",
3257 "-flip flip image vertically",
3258 "-floodfill geometry color",
3259 " floodfill the image with color",
3260 "-flop flop image horizontally",
3261 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003262 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003263 " apply function over image values",
3264 "-gamma value level of gamma correction",
3265 "-gaussian-blur geometry",
3266 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003267 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003268 "-identify identify the format and characteristics of the image",
3269 "-ift implements the inverse discrete Fourier transform (DFT)",
3270 "-implode amount implode image pixels about the center",
3271 "-lat geometry local adaptive thresholding",
3272 "-layers method optimize, merge, or compare image layers",
3273 "-level value adjust the level of image contrast",
3274 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003275 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003276 "-linear-stretch geometry",
3277 " improve contrast by `stretching with saturation'",
3278 "-liquid-rescale geometry",
3279 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003280 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003281 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003282 "-modulate value vary the brightness, saturation, and hue",
3283 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003284 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003285 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003286 "-motion-blur geometry",
3287 " simulate motion blur",
3288 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003289 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003290 "-normalize transform image to span the full range of colors",
3291 "-opaque color change this color to the fill color",
3292 "-ordered-dither NxN",
3293 " add a noise pattern to the image with specific",
3294 " amplitudes",
3295 "-paint radius simulate an oil painting",
3296 "-polaroid angle simulate a Polaroid picture",
3297 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003298 "-profile filename add, delete, or apply an image profile",
3299 "-quantize colorspace reduce colors in this colorspace",
3300 "-radial-blur angle radial blur the image",
3301 "-raise value lighten/darken image edges to create a 3-D effect",
3302 "-random-threshold low,high",
3303 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003304 "-region geometry apply options to a portion of the image",
3305 "-render render vector graphics",
3306 "-repage geometry size and location of an image canvas",
3307 "-resample geometry change the resolution of an image",
3308 "-resize geometry resize the image",
3309 "-roll geometry roll an image vertically or horizontally",
3310 "-rotate degrees apply Paeth rotation to the image",
3311 "-sample geometry scale image with pixel sampling",
3312 "-scale geometry scale the image",
3313 "-segment values segment an image",
3314 "-selective-blur geometry",
3315 " selectively blur pixels within a contrast threshold",
3316 "-sepia-tone threshold",
3317 " simulate a sepia-toned photo",
3318 "-set property value set an image property",
3319 "-shade degrees shade the image using a distant light source",
3320 "-shadow geometry simulate an image shadow",
3321 "-sharpen geometry sharpen the image",
3322 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003323 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003324 "-sigmoidal-contrast geometry",
3325 " increase the contrast without saturating highlights or shadows",
3326 "-sketch geometry simulate a pencil sketch",
3327 "-solarize threshold negate all pixels above the threshold level",
3328 "-sparse-color method args",
3329 " fill in a image based on a few color points",
3330 "-splice geometry splice the background color into the image",
3331 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003332 "-statistic type radius",
3333 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003334 "-strip strip image of all profiles and comments",
3335 "-swirl degrees swirl image pixels about the center",
3336 "-threshold value threshold the image",
3337 "-thumbnail geometry create a thumbnail of the image",
3338 "-tile filename tile image when filling a graphic primitive",
3339 "-tint value tint the image with the fill color",
3340 "-transform affine transform image",
3341 "-transparent color make this color transparent within the image",
3342 "-transpose flip image vertically and rotate 90 degrees",
3343 "-transverse flop image horizontally and rotate 270 degrees",
3344 "-trim trim image edges",
3345 "-type type image type",
3346 "-unique-colors discard all but one of any pixel color",
3347 "-unsharp geometry sharpen the image",
3348 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003349 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003350 "-white-threshold value",
3351 " force all pixels above the threshold into white",
3352 (char *) NULL
3353 },
3354 *sequence_operators[]=
3355 {
cristy4285d782011-02-09 20:12:28 +00003356 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-clut apply a color lookup table to the image",
3358 "-coalesce merge a sequence of images",
3359 "-combine combine a sequence of images",
3360 "-composite composite image",
3361 "-crop geometry cut out a rectangular region of the image",
3362 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003363 "-evaluate-sequence operator",
3364 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-flatten flatten a sequence of images",
3366 "-fx expression apply mathematical expression to an image channel(s)",
3367 "-hald-clut apply a Hald color lookup table to the image",
3368 "-morph value morph an image sequence",
3369 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003370 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003371 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003372 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003373 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003374 "-write filename write images to this file",
3375 (char *) NULL
3376 },
3377 *settings[]=
3378 {
3379 "-adjoin join images into a single multi-image file",
3380 "-affine matrix affine transform matrix",
3381 "-alpha option activate, deactivate, reset, or set the alpha channel",
3382 "-antialias remove pixel-aliasing",
3383 "-authenticate password",
3384 " decipher image with this password",
3385 "-attenuate value lessen (or intensify) when adding noise to an image",
3386 "-background color background color",
3387 "-bias value add bias when convolving an image",
3388 "-black-point-compensation",
3389 " use black point compensation",
3390 "-blue-primary point chromaticity blue primary point",
3391 "-bordercolor color border color",
3392 "-caption string assign a caption to an image",
3393 "-channel type apply option to select image channels",
3394 "-colors value preferred number of colors in the image",
3395 "-colorspace type alternate image colorspace",
3396 "-comment string annotate image with comment",
3397 "-compose operator set image composite operator",
3398 "-compress type type of pixel compression when writing the image",
3399 "-define format:option",
3400 " define one or more image format options",
3401 "-delay value display the next image after pausing",
3402 "-density geometry horizontal and vertical density of the image",
3403 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003404 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003405 "-display server get image or font from this X server",
3406 "-dispose method layer disposal method",
3407 "-dither method apply error diffusion to image",
3408 "-encoding type text encoding type",
3409 "-endian type endianness (MSB or LSB) of the image",
3410 "-family name render text with this font family",
3411 "-fill color color to use when filling a graphic primitive",
3412 "-filter type use this filter when resizing an image",
3413 "-font name render text with this font",
3414 "-format \"string\" output formatted image characteristics",
3415 "-fuzz distance colors within this distance are considered equal",
3416 "-gravity type horizontal and vertical text placement",
3417 "-green-primary point chromaticity green primary point",
3418 "-intent type type of rendering intent when managing the image color",
3419 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003420 "-interline-spacing value",
3421 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003422 "-interpolate method pixel color interpolation method",
3423 "-interword-spacing value",
3424 " set the space between two words",
3425 "-kerning value set the space between two letters",
3426 "-label string assign a label to an image",
3427 "-limit type value pixel cache resource limit",
3428 "-loop iterations add Netscape loop extension to your GIF animation",
3429 "-mask filename associate a mask with the image",
3430 "-mattecolor color frame color",
3431 "-monitor monitor progress",
3432 "-orient type image orientation",
3433 "-page geometry size and location of an image canvas (setting)",
3434 "-ping efficiently determine image attributes",
3435 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003436 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003437 "-preview type image preview type",
3438 "-quality value JPEG/MIFF/PNG compression level",
3439 "-quiet suppress all warning messages",
3440 "-red-primary point chromaticity red primary point",
3441 "-regard-warnings pay attention to warning messages",
3442 "-remap filename transform image colors to match this set of colors",
3443 "-respect-parentheses settings remain in effect until parenthesis boundary",
3444 "-sampling-factor geometry",
3445 " horizontal and vertical sampling factor",
3446 "-scene value image scene number",
3447 "-seed value seed a new sequence of pseudo-random numbers",
3448 "-size geometry width and height of image",
3449 "-stretch type render text with this font stretch",
3450 "-stroke color graphic primitive stroke color",
3451 "-strokewidth value graphic primitive stroke width",
3452 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003453 "-synchronize synchronize image to storage device",
3454 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003455 "-texture filename name of texture to tile onto the image background",
3456 "-tile-offset geometry",
3457 " tile offset",
3458 "-treedepth value color tree depth",
3459 "-transparent-color color",
3460 " transparent color",
3461 "-undercolor color annotation bounding box color",
3462 "-units type the units of image resolution",
3463 "-verbose print detailed information about the image",
3464 "-view FlashPix viewing transforms",
3465 "-virtual-pixel method",
3466 " virtual pixel access method",
3467 "-weight type render text with this font weight",
3468 "-white-point point chromaticity white point",
3469 (char *) NULL
3470 },
3471 *stack_operators[]=
3472 {
anthonyb69c4b32011-03-23 04:37:44 +00003473 "-delete indexes delete the image from the image sequence",
3474 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003475 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003476 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003477 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003478 "-swap indexes swap two images in the image sequence",
3479 (char *) NULL
3480 };
3481
3482 const char
3483 **p;
3484
cristybb503372010-05-27 20:51:26 +00003485 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003486 (void) printf("Copyright: %s\n",GetMagickCopyright());
3487 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003488 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3489 GetClientName());
3490 (void) printf("\nImage Settings:\n");
3491 for (p=settings; *p != (char *) NULL; p++)
3492 (void) printf(" %s\n",*p);
3493 (void) printf("\nImage Operators:\n");
3494 for (p=operators; *p != (char *) NULL; p++)
3495 (void) printf(" %s\n",*p);
3496 (void) printf("\nImage Sequence Operators:\n");
3497 for (p=sequence_operators; *p != (char *) NULL; p++)
3498 (void) printf(" %s\n",*p);
3499 (void) printf("\nImage Stack Operators:\n");
3500 for (p=stack_operators; *p != (char *) NULL; p++)
3501 (void) printf(" %s\n",*p);
3502 (void) printf("\nMiscellaneous Options:\n");
3503 for (p=miscellaneous; *p != (char *) NULL; p++)
3504 (void) printf(" %s\n",*p);
3505 (void) printf(
3506 "\nBy default, the image format of `file' is determined by its magic\n");
3507 (void) printf(
3508 "number. To specify a particular image format, precede the filename\n");
3509 (void) printf(
3510 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3511 (void) printf(
3512 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3513 (void) printf("'-' for standard input or output.\n");
3514 return(MagickFalse);
3515}
3516
3517WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3518 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3519{
3520#define DestroyMogrify() \
3521{ \
3522 if (format != (char *) NULL) \
3523 format=DestroyString(format); \
3524 if (path != (char *) NULL) \
3525 path=DestroyString(path); \
3526 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003527 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003528 argv[i]=DestroyString(argv[i]); \
3529 argv=(char **) RelinquishMagickMemory(argv); \
3530}
3531#define ThrowMogrifyException(asperity,tag,option) \
3532{ \
3533 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3534 option); \
3535 DestroyMogrify(); \
3536 return(MagickFalse); \
3537}
3538#define ThrowMogrifyInvalidArgumentException(option,argument) \
3539{ \
3540 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3541 "InvalidArgument","`%s': %s",argument,option); \
3542 DestroyMogrify(); \
3543 return(MagickFalse); \
3544}
3545
3546 char
3547 *format,
3548 *option,
3549 *path;
3550
3551 Image
3552 *image;
3553
3554 ImageStack
3555 image_stack[MaxImageStackDepth+1];
3556
cristy3ed852e2009-09-05 21:47:34 +00003557 MagickBooleanType
3558 global_colormap;
3559
3560 MagickBooleanType
3561 fire,
cristyebbcfea2011-02-25 02:43:54 +00003562 pend,
3563 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003564
3565 MagickStatusType
3566 status;
3567
cristyebbcfea2011-02-25 02:43:54 +00003568 register ssize_t
3569 i;
3570
3571 ssize_t
3572 j,
3573 k;
3574
cristy3ed852e2009-09-05 21:47:34 +00003575 /*
3576 Set defaults.
3577 */
3578 assert(image_info != (ImageInfo *) NULL);
3579 assert(image_info->signature == MagickSignature);
3580 if (image_info->debug != MagickFalse)
3581 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3582 assert(exception != (ExceptionInfo *) NULL);
3583 if (argc == 2)
3584 {
3585 option=argv[1];
3586 if ((LocaleCompare("version",option+1) == 0) ||
3587 (LocaleCompare("-version",option+1) == 0))
3588 {
cristyb51dff52011-05-19 16:55:47 +00003589 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003590 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003591 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3592 GetMagickCopyright());
3593 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3594 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003595 return(MagickFalse);
3596 }
3597 }
3598 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003599 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003600 format=(char *) NULL;
3601 path=(char *) NULL;
3602 global_colormap=MagickFalse;
3603 k=0;
3604 j=1;
3605 NewImageStack();
3606 option=(char *) NULL;
3607 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003608 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003609 status=MagickTrue;
3610 /*
3611 Parse command line.
3612 */
3613 ReadCommandlLine(argc,&argv);
3614 status=ExpandFilenames(&argc,&argv);
3615 if (status == MagickFalse)
3616 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3617 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003618 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003619 {
3620 option=argv[i];
3621 if (LocaleCompare(option,"(") == 0)
3622 {
3623 FireImageStack(MagickFalse,MagickTrue,pend);
3624 if (k == MaxImageStackDepth)
3625 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3626 option);
3627 PushImageStack();
3628 continue;
3629 }
3630 if (LocaleCompare(option,")") == 0)
3631 {
3632 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3633 if (k == 0)
3634 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3635 PopImageStack();
3636 continue;
3637 }
cristy042ee782011-04-22 18:48:30 +00003638 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003639 {
3640 char
3641 backup_filename[MaxTextExtent],
3642 *filename;
3643
3644 Image
3645 *images;
3646
3647 /*
3648 Option is a file name: begin by reading image from specified file.
3649 */
3650 FireImageStack(MagickFalse,MagickFalse,pend);
3651 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003652 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003653 filename=argv[++i];
3654 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3655 images=ReadImages(image_info,exception);
3656 status&=(images != (Image *) NULL) &&
3657 (exception->severity < ErrorException);
3658 if (images == (Image *) NULL)
3659 continue;
cristydaa76602010-06-30 13:05:11 +00003660 if (format != (char *) NULL)
3661 (void) CopyMagickString(images->filename,images->magick_filename,
3662 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003663 if (path != (char *) NULL)
3664 {
3665 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003666 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003667 path,*DirectorySeparator,filename);
3668 }
3669 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003670 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003671 AppendImageStack(images);
3672 FinalizeImageSettings(image_info,image,MagickFalse);
3673 if (global_colormap != MagickFalse)
3674 {
3675 QuantizeInfo
3676 *quantize_info;
3677
3678 quantize_info=AcquireQuantizeInfo(image_info);
3679 (void) RemapImages(quantize_info,images,(Image *) NULL);
3680 quantize_info=DestroyQuantizeInfo(quantize_info);
3681 }
3682 *backup_filename='\0';
3683 if ((LocaleCompare(image->filename,"-") != 0) &&
3684 (IsPathWritable(image->filename) != MagickFalse))
3685 {
cristybb503372010-05-27 20:51:26 +00003686 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003687 i;
3688
3689 /*
3690 Rename image file as backup.
3691 */
3692 (void) CopyMagickString(backup_filename,image->filename,
3693 MaxTextExtent);
3694 for (i=0; i < 6; i++)
3695 {
3696 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3697 if (IsPathAccessible(backup_filename) == MagickFalse)
3698 break;
3699 }
3700 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3701 (rename(image->filename,backup_filename) != 0))
3702 *backup_filename='\0';
3703 }
3704 /*
3705 Write transmogrified image to disk.
3706 */
3707 image_info->synchronize=MagickTrue;
3708 status&=WriteImages(image_info,image,image->filename,exception);
3709 if ((status == MagickFalse) && (*backup_filename != '\0'))
3710 (void) remove(backup_filename);
3711 RemoveAllImageStack();
3712 continue;
3713 }
3714 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3715 switch (*(option+1))
3716 {
3717 case 'a':
3718 {
3719 if (LocaleCompare("adaptive-blur",option+1) == 0)
3720 {
3721 i++;
cristybb503372010-05-27 20:51:26 +00003722 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003723 ThrowMogrifyException(OptionError,"MissingArgument",option);
3724 if (IsGeometry(argv[i]) == MagickFalse)
3725 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3726 break;
3727 }
3728 if (LocaleCompare("adaptive-resize",option+1) == 0)
3729 {
3730 i++;
cristybb503372010-05-27 20:51:26 +00003731 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003732 ThrowMogrifyException(OptionError,"MissingArgument",option);
3733 if (IsGeometry(argv[i]) == MagickFalse)
3734 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3735 break;
3736 }
3737 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3738 {
3739 i++;
cristybb503372010-05-27 20:51:26 +00003740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003741 ThrowMogrifyException(OptionError,"MissingArgument",option);
3742 if (IsGeometry(argv[i]) == MagickFalse)
3743 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3744 break;
3745 }
3746 if (LocaleCompare("affine",option+1) == 0)
3747 {
3748 if (*option == '+')
3749 break;
3750 i++;
cristybb503372010-05-27 20:51:26 +00003751 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003752 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003753 break;
3754 }
3755 if (LocaleCompare("alpha",option+1) == 0)
3756 {
cristybb503372010-05-27 20:51:26 +00003757 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003758 type;
3759
3760 if (*option == '+')
3761 break;
3762 i++;
cristybb503372010-05-27 20:51:26 +00003763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003764 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003765 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003766 if (type < 0)
3767 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3768 argv[i]);
3769 break;
3770 }
3771 if (LocaleCompare("annotate",option+1) == 0)
3772 {
3773 if (*option == '+')
3774 break;
3775 i++;
cristybb503372010-05-27 20:51:26 +00003776 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003777 ThrowMogrifyException(OptionError,"MissingArgument",option);
3778 if (IsGeometry(argv[i]) == MagickFalse)
3779 ThrowMogrifyInvalidArgumentException(option,argv[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 i++;
3783 break;
3784 }
3785 if (LocaleCompare("antialias",option+1) == 0)
3786 break;
3787 if (LocaleCompare("append",option+1) == 0)
3788 break;
3789 if (LocaleCompare("attenuate",option+1) == 0)
3790 {
3791 if (*option == '+')
3792 break;
3793 i++;
cristybb503372010-05-27 20:51:26 +00003794 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003795 ThrowMogrifyException(OptionError,"MissingArgument",option);
3796 if (IsGeometry(argv[i]) == MagickFalse)
3797 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3798 break;
3799 }
3800 if (LocaleCompare("authenticate",option+1) == 0)
3801 {
3802 if (*option == '+')
3803 break;
3804 i++;
cristybb503372010-05-27 20:51:26 +00003805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003806 ThrowMogrifyException(OptionError,"MissingArgument",option);
3807 break;
3808 }
3809 if (LocaleCompare("auto-gamma",option+1) == 0)
3810 break;
3811 if (LocaleCompare("auto-level",option+1) == 0)
3812 break;
3813 if (LocaleCompare("auto-orient",option+1) == 0)
3814 break;
3815 if (LocaleCompare("average",option+1) == 0)
3816 break;
3817 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3818 }
3819 case 'b':
3820 {
3821 if (LocaleCompare("background",option+1) == 0)
3822 {
3823 if (*option == '+')
3824 break;
3825 i++;
cristybb503372010-05-27 20:51:26 +00003826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003827 ThrowMogrifyException(OptionError,"MissingArgument",option);
3828 break;
3829 }
3830 if (LocaleCompare("bias",option+1) == 0)
3831 {
3832 if (*option == '+')
3833 break;
3834 i++;
cristybb503372010-05-27 20:51:26 +00003835 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003836 ThrowMogrifyException(OptionError,"MissingArgument",option);
3837 if (IsGeometry(argv[i]) == MagickFalse)
3838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3839 break;
3840 }
3841 if (LocaleCompare("black-point-compensation",option+1) == 0)
3842 break;
3843 if (LocaleCompare("black-threshold",option+1) == 0)
3844 {
3845 if (*option == '+')
3846 break;
3847 i++;
cristybb503372010-05-27 20:51:26 +00003848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003849 ThrowMogrifyException(OptionError,"MissingArgument",option);
3850 if (IsGeometry(argv[i]) == MagickFalse)
3851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3852 break;
3853 }
3854 if (LocaleCompare("blue-primary",option+1) == 0)
3855 {
3856 if (*option == '+')
3857 break;
3858 i++;
cristybb503372010-05-27 20:51:26 +00003859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003860 ThrowMogrifyException(OptionError,"MissingArgument",option);
3861 if (IsGeometry(argv[i]) == MagickFalse)
3862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3863 break;
3864 }
3865 if (LocaleCompare("blue-shift",option+1) == 0)
3866 {
3867 i++;
cristybb503372010-05-27 20:51:26 +00003868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003869 ThrowMogrifyException(OptionError,"MissingArgument",option);
3870 if (IsGeometry(argv[i]) == MagickFalse)
3871 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3872 break;
3873 }
3874 if (LocaleCompare("blur",option+1) == 0)
3875 {
3876 i++;
cristybb503372010-05-27 20:51:26 +00003877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003878 ThrowMogrifyException(OptionError,"MissingArgument",option);
3879 if (IsGeometry(argv[i]) == MagickFalse)
3880 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3881 break;
3882 }
3883 if (LocaleCompare("border",option+1) == 0)
3884 {
3885 if (*option == '+')
3886 break;
3887 i++;
cristybb503372010-05-27 20:51:26 +00003888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003889 ThrowMogrifyException(OptionError,"MissingArgument",option);
3890 if (IsGeometry(argv[i]) == MagickFalse)
3891 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3892 break;
3893 }
3894 if (LocaleCompare("bordercolor",option+1) == 0)
3895 {
3896 if (*option == '+')
3897 break;
3898 i++;
cristybb503372010-05-27 20:51:26 +00003899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003900 ThrowMogrifyException(OptionError,"MissingArgument",option);
3901 break;
3902 }
3903 if (LocaleCompare("box",option+1) == 0)
3904 {
3905 if (*option == '+')
3906 break;
3907 i++;
cristybb503372010-05-27 20:51:26 +00003908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003909 ThrowMogrifyException(OptionError,"MissingArgument",option);
3910 break;
3911 }
cristya28d6b82010-01-11 20:03:47 +00003912 if (LocaleCompare("brightness-contrast",option+1) == 0)
3913 {
3914 i++;
cristybb503372010-05-27 20:51:26 +00003915 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003916 ThrowMogrifyException(OptionError,"MissingArgument",option);
3917 if (IsGeometry(argv[i]) == MagickFalse)
3918 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3919 break;
3920 }
cristy3ed852e2009-09-05 21:47:34 +00003921 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3922 }
3923 case 'c':
3924 {
3925 if (LocaleCompare("cache",option+1) == 0)
3926 {
3927 if (*option == '+')
3928 break;
3929 i++;
cristybb503372010-05-27 20:51:26 +00003930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003931 ThrowMogrifyException(OptionError,"MissingArgument",option);
3932 if (IsGeometry(argv[i]) == MagickFalse)
3933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3934 break;
3935 }
3936 if (LocaleCompare("caption",option+1) == 0)
3937 {
3938 if (*option == '+')
3939 break;
3940 i++;
cristybb503372010-05-27 20:51:26 +00003941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003942 ThrowMogrifyException(OptionError,"MissingArgument",option);
3943 break;
3944 }
3945 if (LocaleCompare("channel",option+1) == 0)
3946 {
cristybb503372010-05-27 20:51:26 +00003947 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003948 channel;
3949
3950 if (*option == '+')
3951 break;
3952 i++;
cristybb503372010-05-27 20:51:26 +00003953 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003954 ThrowMogrifyException(OptionError,"MissingArgument",option);
3955 channel=ParseChannelOption(argv[i]);
3956 if (channel < 0)
3957 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3958 argv[i]);
3959 break;
3960 }
3961 if (LocaleCompare("cdl",option+1) == 0)
3962 {
3963 if (*option == '+')
3964 break;
3965 i++;
cristybb503372010-05-27 20:51:26 +00003966 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003967 ThrowMogrifyException(OptionError,"MissingArgument",option);
3968 break;
3969 }
3970 if (LocaleCompare("charcoal",option+1) == 0)
3971 {
3972 if (*option == '+')
3973 break;
3974 i++;
cristybb503372010-05-27 20:51:26 +00003975 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003976 ThrowMogrifyException(OptionError,"MissingArgument",option);
3977 if (IsGeometry(argv[i]) == MagickFalse)
3978 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3979 break;
3980 }
3981 if (LocaleCompare("chop",option+1) == 0)
3982 {
3983 if (*option == '+')
3984 break;
3985 i++;
cristybb503372010-05-27 20:51:26 +00003986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003987 ThrowMogrifyException(OptionError,"MissingArgument",option);
3988 if (IsGeometry(argv[i]) == MagickFalse)
3989 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3990 break;
3991 }
cristy1eb45dd2009-09-25 16:38:06 +00003992 if (LocaleCompare("clamp",option+1) == 0)
3993 break;
3994 if (LocaleCompare("clip",option+1) == 0)
3995 break;
cristy3ed852e2009-09-05 21:47:34 +00003996 if (LocaleCompare("clip-mask",option+1) == 0)
3997 {
3998 if (*option == '+')
3999 break;
4000 i++;
cristybb503372010-05-27 20:51:26 +00004001 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004002 ThrowMogrifyException(OptionError,"MissingArgument",option);
4003 break;
4004 }
4005 if (LocaleCompare("clut",option+1) == 0)
4006 break;
4007 if (LocaleCompare("coalesce",option+1) == 0)
4008 break;
4009 if (LocaleCompare("colorize",option+1) == 0)
4010 {
4011 if (*option == '+')
4012 break;
4013 i++;
cristybb503372010-05-27 20:51:26 +00004014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004015 ThrowMogrifyException(OptionError,"MissingArgument",option);
4016 if (IsGeometry(argv[i]) == MagickFalse)
4017 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4018 break;
4019 }
cristye6365592010-04-02 17:31:23 +00004020 if (LocaleCompare("color-matrix",option+1) == 0)
4021 {
cristyb6bd4ad2010-08-08 01:12:27 +00004022 KernelInfo
4023 *kernel_info;
4024
cristye6365592010-04-02 17:31:23 +00004025 if (*option == '+')
4026 break;
4027 i++;
cristybb503372010-05-27 20:51:26 +00004028 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004029 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004030 kernel_info=AcquireKernelInfo(argv[i]);
4031 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004032 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004033 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004034 break;
4035 }
cristy3ed852e2009-09-05 21:47:34 +00004036 if (LocaleCompare("colors",option+1) == 0)
4037 {
4038 if (*option == '+')
4039 break;
4040 i++;
cristybb503372010-05-27 20:51:26 +00004041 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004042 ThrowMogrifyException(OptionError,"MissingArgument",option);
4043 if (IsGeometry(argv[i]) == MagickFalse)
4044 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4045 break;
4046 }
4047 if (LocaleCompare("colorspace",option+1) == 0)
4048 {
cristybb503372010-05-27 20:51:26 +00004049 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004050 colorspace;
4051
4052 if (*option == '+')
4053 break;
4054 i++;
cristybb503372010-05-27 20:51:26 +00004055 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004056 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004057 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004058 argv[i]);
4059 if (colorspace < 0)
4060 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4061 argv[i]);
4062 break;
4063 }
4064 if (LocaleCompare("combine",option+1) == 0)
4065 break;
4066 if (LocaleCompare("comment",option+1) == 0)
4067 {
4068 if (*option == '+')
4069 break;
4070 i++;
cristybb503372010-05-27 20:51:26 +00004071 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004072 ThrowMogrifyException(OptionError,"MissingArgument",option);
4073 break;
4074 }
4075 if (LocaleCompare("composite",option+1) == 0)
4076 break;
4077 if (LocaleCompare("compress",option+1) == 0)
4078 {
cristybb503372010-05-27 20:51:26 +00004079 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004080 compress;
4081
4082 if (*option == '+')
4083 break;
4084 i++;
cristybb503372010-05-27 20:51:26 +00004085 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004086 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004087 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004088 argv[i]);
4089 if (compress < 0)
4090 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4091 argv[i]);
4092 break;
4093 }
cristy22879752009-10-25 23:55:40 +00004094 if (LocaleCompare("concurrent",option+1) == 0)
4095 break;
cristy3ed852e2009-09-05 21:47:34 +00004096 if (LocaleCompare("contrast",option+1) == 0)
4097 break;
4098 if (LocaleCompare("contrast-stretch",option+1) == 0)
4099 {
4100 i++;
cristybb503372010-05-27 20:51:26 +00004101 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004102 ThrowMogrifyException(OptionError,"MissingArgument",option);
4103 if (IsGeometry(argv[i]) == MagickFalse)
4104 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4105 break;
4106 }
4107 if (LocaleCompare("convolve",option+1) == 0)
4108 {
cristyb6bd4ad2010-08-08 01:12:27 +00004109 KernelInfo
4110 *kernel_info;
4111
cristy3ed852e2009-09-05 21:47:34 +00004112 if (*option == '+')
4113 break;
4114 i++;
cristybb503372010-05-27 20:51:26 +00004115 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004116 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004117 kernel_info=AcquireKernelInfo(argv[i]);
4118 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004119 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004120 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004121 break;
4122 }
4123 if (LocaleCompare("crop",option+1) == 0)
4124 {
4125 if (*option == '+')
4126 break;
4127 i++;
cristybb503372010-05-27 20:51:26 +00004128 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004129 ThrowMogrifyException(OptionError,"MissingArgument",option);
4130 if (IsGeometry(argv[i]) == MagickFalse)
4131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4132 break;
4133 }
4134 if (LocaleCompare("cycle",option+1) == 0)
4135 {
4136 if (*option == '+')
4137 break;
4138 i++;
cristybb503372010-05-27 20:51:26 +00004139 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004140 ThrowMogrifyException(OptionError,"MissingArgument",option);
4141 if (IsGeometry(argv[i]) == MagickFalse)
4142 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4143 break;
4144 }
4145 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4146 }
4147 case 'd':
4148 {
4149 if (LocaleCompare("decipher",option+1) == 0)
4150 {
4151 if (*option == '+')
4152 break;
4153 i++;
cristybb503372010-05-27 20:51:26 +00004154 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004155 ThrowMogrifyException(OptionError,"MissingArgument",option);
4156 break;
4157 }
4158 if (LocaleCompare("deconstruct",option+1) == 0)
4159 break;
4160 if (LocaleCompare("debug",option+1) == 0)
4161 {
cristybb503372010-05-27 20:51:26 +00004162 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004163 event;
4164
4165 if (*option == '+')
4166 break;
4167 i++;
cristybb503372010-05-27 20:51:26 +00004168 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004169 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004170 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004171 if (event < 0)
4172 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4173 argv[i]);
4174 (void) SetLogEventMask(argv[i]);
4175 break;
4176 }
4177 if (LocaleCompare("define",option+1) == 0)
4178 {
4179 i++;
cristybb503372010-05-27 20:51:26 +00004180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004181 ThrowMogrifyException(OptionError,"MissingArgument",option);
4182 if (*option == '+')
4183 {
4184 const char
4185 *define;
4186
4187 define=GetImageOption(image_info,argv[i]);
4188 if (define == (const char *) NULL)
4189 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4190 break;
4191 }
4192 break;
4193 }
4194 if (LocaleCompare("delay",option+1) == 0)
4195 {
4196 if (*option == '+')
4197 break;
4198 i++;
cristybb503372010-05-27 20:51:26 +00004199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004200 ThrowMogrifyException(OptionError,"MissingArgument",option);
4201 if (IsGeometry(argv[i]) == MagickFalse)
4202 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4203 break;
4204 }
cristyecb10ff2011-03-22 13:14:03 +00004205 if (LocaleCompare("delete",option+1) == 0)
4206 {
4207 if (*option == '+')
4208 break;
4209 i++;
4210 if (i == (ssize_t) (argc-1))
4211 ThrowMogrifyException(OptionError,"MissingArgument",option);
4212 if (IsGeometry(argv[i]) == MagickFalse)
4213 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4214 break;
4215 }
cristy3ed852e2009-09-05 21:47:34 +00004216 if (LocaleCompare("density",option+1) == 0)
4217 {
4218 if (*option == '+')
4219 break;
4220 i++;
cristybb503372010-05-27 20:51:26 +00004221 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004222 ThrowMogrifyException(OptionError,"MissingArgument",option);
4223 if (IsGeometry(argv[i]) == MagickFalse)
4224 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4225 break;
4226 }
4227 if (LocaleCompare("depth",option+1) == 0)
4228 {
4229 if (*option == '+')
4230 break;
4231 i++;
cristybb503372010-05-27 20:51:26 +00004232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004233 ThrowMogrifyException(OptionError,"MissingArgument",option);
4234 if (IsGeometry(argv[i]) == MagickFalse)
4235 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4236 break;
4237 }
4238 if (LocaleCompare("deskew",option+1) == 0)
4239 {
4240 if (*option == '+')
4241 break;
4242 i++;
cristybb503372010-05-27 20:51:26 +00004243 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004244 ThrowMogrifyException(OptionError,"MissingArgument",option);
4245 if (IsGeometry(argv[i]) == MagickFalse)
4246 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4247 break;
4248 }
4249 if (LocaleCompare("despeckle",option+1) == 0)
4250 break;
4251 if (LocaleCompare("dft",option+1) == 0)
4252 break;
cristyc9b12952010-03-28 01:12:28 +00004253 if (LocaleCompare("direction",option+1) == 0)
4254 {
cristybb503372010-05-27 20:51:26 +00004255 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004256 direction;
4257
4258 if (*option == '+')
4259 break;
4260 i++;
cristybb503372010-05-27 20:51:26 +00004261 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004262 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004263 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004264 argv[i]);
4265 if (direction < 0)
4266 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4267 argv[i]);
4268 break;
4269 }
cristy3ed852e2009-09-05 21:47:34 +00004270 if (LocaleCompare("display",option+1) == 0)
4271 {
4272 if (*option == '+')
4273 break;
4274 i++;
cristybb503372010-05-27 20:51:26 +00004275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004276 ThrowMogrifyException(OptionError,"MissingArgument",option);
4277 break;
4278 }
4279 if (LocaleCompare("dispose",option+1) == 0)
4280 {
cristybb503372010-05-27 20:51:26 +00004281 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004282 dispose;
4283
4284 if (*option == '+')
4285 break;
4286 i++;
cristybb503372010-05-27 20:51:26 +00004287 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004288 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004289 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004290 if (dispose < 0)
4291 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4292 argv[i]);
4293 break;
4294 }
4295 if (LocaleCompare("distort",option+1) == 0)
4296 {
cristybb503372010-05-27 20:51:26 +00004297 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004298 op;
4299
4300 i++;
cristybb503372010-05-27 20:51:26 +00004301 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004302 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004303 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004304 if (op < 0)
4305 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4306 argv[i]);
4307 i++;
cristybb503372010-05-27 20:51:26 +00004308 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004309 ThrowMogrifyException(OptionError,"MissingArgument",option);
4310 break;
4311 }
4312 if (LocaleCompare("dither",option+1) == 0)
4313 {
cristybb503372010-05-27 20:51:26 +00004314 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004315 method;
4316
4317 if (*option == '+')
4318 break;
4319 i++;
cristybb503372010-05-27 20:51:26 +00004320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004321 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004322 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004323 if (method < 0)
4324 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4325 argv[i]);
4326 break;
4327 }
4328 if (LocaleCompare("draw",option+1) == 0)
4329 {
4330 if (*option == '+')
4331 break;
4332 i++;
cristybb503372010-05-27 20:51:26 +00004333 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004334 ThrowMogrifyException(OptionError,"MissingArgument",option);
4335 break;
4336 }
cristyecb10ff2011-03-22 13:14:03 +00004337 if (LocaleCompare("duplicate",option+1) == 0)
4338 {
4339 if (*option == '+')
4340 break;
4341 i++;
4342 if (i == (ssize_t) (argc-1))
4343 ThrowMogrifyException(OptionError,"MissingArgument",option);
4344 if (IsGeometry(argv[i]) == MagickFalse)
4345 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4346 break;
4347 }
cristy22879752009-10-25 23:55:40 +00004348 if (LocaleCompare("duration",option+1) == 0)
4349 {
4350 if (*option == '+')
4351 break;
4352 i++;
cristybb503372010-05-27 20:51:26 +00004353 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004354 ThrowMogrifyException(OptionError,"MissingArgument",option);
4355 if (IsGeometry(argv[i]) == MagickFalse)
4356 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4357 break;
4358 }
cristy3ed852e2009-09-05 21:47:34 +00004359 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4360 }
4361 case 'e':
4362 {
4363 if (LocaleCompare("edge",option+1) == 0)
4364 {
4365 if (*option == '+')
4366 break;
4367 i++;
cristybb503372010-05-27 20:51:26 +00004368 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004369 ThrowMogrifyException(OptionError,"MissingArgument",option);
4370 if (IsGeometry(argv[i]) == MagickFalse)
4371 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4372 break;
4373 }
4374 if (LocaleCompare("emboss",option+1) == 0)
4375 {
4376 if (*option == '+')
4377 break;
4378 i++;
cristybb503372010-05-27 20:51:26 +00004379 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004380 ThrowMogrifyException(OptionError,"MissingArgument",option);
4381 if (IsGeometry(argv[i]) == MagickFalse)
4382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4383 break;
4384 }
4385 if (LocaleCompare("encipher",option+1) == 0)
4386 {
4387 if (*option == '+')
4388 break;
4389 i++;
cristybb503372010-05-27 20:51:26 +00004390 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004391 ThrowMogrifyException(OptionError,"MissingArgument",option);
4392 break;
4393 }
4394 if (LocaleCompare("encoding",option+1) == 0)
4395 {
4396 if (*option == '+')
4397 break;
4398 i++;
cristybb503372010-05-27 20:51:26 +00004399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004400 ThrowMogrifyException(OptionError,"MissingArgument",option);
4401 break;
4402 }
4403 if (LocaleCompare("endian",option+1) == 0)
4404 {
cristybb503372010-05-27 20:51:26 +00004405 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004406 endian;
4407
4408 if (*option == '+')
4409 break;
4410 i++;
cristybb503372010-05-27 20:51:26 +00004411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004412 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004413 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004414 if (endian < 0)
4415 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4416 argv[i]);
4417 break;
4418 }
4419 if (LocaleCompare("enhance",option+1) == 0)
4420 break;
4421 if (LocaleCompare("equalize",option+1) == 0)
4422 break;
4423 if (LocaleCompare("evaluate",option+1) == 0)
4424 {
cristybb503372010-05-27 20:51:26 +00004425 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004426 op;
4427
4428 if (*option == '+')
4429 break;
4430 i++;
cristybb503372010-05-27 20:51:26 +00004431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004432 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004433 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004434 if (op < 0)
4435 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4436 argv[i]);
4437 i++;
cristybb503372010-05-27 20:51:26 +00004438 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004439 ThrowMogrifyException(OptionError,"MissingArgument",option);
4440 if (IsGeometry(argv[i]) == MagickFalse)
4441 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4442 break;
4443 }
cristyd18ae7c2010-03-07 17:39:52 +00004444 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4445 {
cristybb503372010-05-27 20:51:26 +00004446 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004447 op;
4448
4449 if (*option == '+')
4450 break;
4451 i++;
cristybb503372010-05-27 20:51:26 +00004452 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004453 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004454 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004455 if (op < 0)
4456 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4457 argv[i]);
4458 break;
4459 }
cristy3ed852e2009-09-05 21:47:34 +00004460 if (LocaleCompare("extent",option+1) == 0)
4461 {
4462 if (*option == '+')
4463 break;
4464 i++;
cristybb503372010-05-27 20:51:26 +00004465 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004466 ThrowMogrifyException(OptionError,"MissingArgument",option);
4467 if (IsGeometry(argv[i]) == MagickFalse)
4468 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4469 break;
4470 }
4471 if (LocaleCompare("extract",option+1) == 0)
4472 {
4473 if (*option == '+')
4474 break;
4475 i++;
cristybb503372010-05-27 20:51:26 +00004476 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004477 ThrowMogrifyException(OptionError,"MissingArgument",option);
4478 if (IsGeometry(argv[i]) == MagickFalse)
4479 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4480 break;
4481 }
4482 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4483 }
4484 case 'f':
4485 {
4486 if (LocaleCompare("family",option+1) == 0)
4487 {
4488 if (*option == '+')
4489 break;
4490 i++;
cristybb503372010-05-27 20:51:26 +00004491 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004492 ThrowMogrifyException(OptionError,"MissingArgument",option);
4493 break;
4494 }
4495 if (LocaleCompare("fill",option+1) == 0)
4496 {
4497 if (*option == '+')
4498 break;
4499 i++;
cristybb503372010-05-27 20:51:26 +00004500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004501 ThrowMogrifyException(OptionError,"MissingArgument",option);
4502 break;
4503 }
4504 if (LocaleCompare("filter",option+1) == 0)
4505 {
cristybb503372010-05-27 20:51:26 +00004506 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004507 filter;
4508
4509 if (*option == '+')
4510 break;
4511 i++;
cristybb503372010-05-27 20:51:26 +00004512 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004513 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004514 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004515 if (filter < 0)
4516 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4517 argv[i]);
4518 break;
4519 }
4520 if (LocaleCompare("flatten",option+1) == 0)
4521 break;
4522 if (LocaleCompare("flip",option+1) == 0)
4523 break;
4524 if (LocaleCompare("flop",option+1) == 0)
4525 break;
4526 if (LocaleCompare("floodfill",option+1) == 0)
4527 {
4528 if (*option == '+')
4529 break;
4530 i++;
cristybb503372010-05-27 20:51:26 +00004531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004532 ThrowMogrifyException(OptionError,"MissingArgument",option);
4533 if (IsGeometry(argv[i]) == MagickFalse)
4534 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4535 i++;
cristybb503372010-05-27 20:51:26 +00004536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004537 ThrowMogrifyException(OptionError,"MissingArgument",option);
4538 break;
4539 }
4540 if (LocaleCompare("font",option+1) == 0)
4541 {
4542 if (*option == '+')
4543 break;
4544 i++;
cristybb503372010-05-27 20:51:26 +00004545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004546 ThrowMogrifyException(OptionError,"MissingArgument",option);
4547 break;
4548 }
4549 if (LocaleCompare("format",option+1) == 0)
4550 {
4551 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4552 (void) CloneString(&format,(char *) NULL);
4553 if (*option == '+')
4554 break;
4555 i++;
cristybb503372010-05-27 20:51:26 +00004556 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004557 ThrowMogrifyException(OptionError,"MissingArgument",option);
4558 (void) CloneString(&format,argv[i]);
4559 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4560 (void) ConcatenateMagickString(image_info->filename,":",
4561 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004562 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004563 if (*image_info->magick == '\0')
4564 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4565 format);
4566 break;
4567 }
4568 if (LocaleCompare("frame",option+1) == 0)
4569 {
4570 if (*option == '+')
4571 break;
4572 i++;
cristybb503372010-05-27 20:51:26 +00004573 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004574 ThrowMogrifyException(OptionError,"MissingArgument",option);
4575 if (IsGeometry(argv[i]) == MagickFalse)
4576 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4577 break;
4578 }
4579 if (LocaleCompare("function",option+1) == 0)
4580 {
cristybb503372010-05-27 20:51:26 +00004581 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004582 op;
4583
4584 if (*option == '+')
4585 break;
4586 i++;
cristybb503372010-05-27 20:51:26 +00004587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004588 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004589 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004590 if (op < 0)
4591 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4592 i++;
cristybb503372010-05-27 20:51:26 +00004593 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004594 ThrowMogrifyException(OptionError,"MissingArgument",option);
4595 break;
4596 }
4597 if (LocaleCompare("fuzz",option+1) == 0)
4598 {
4599 if (*option == '+')
4600 break;
4601 i++;
cristybb503372010-05-27 20:51:26 +00004602 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004603 ThrowMogrifyException(OptionError,"MissingArgument",option);
4604 if (IsGeometry(argv[i]) == MagickFalse)
4605 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4606 break;
4607 }
4608 if (LocaleCompare("fx",option+1) == 0)
4609 {
4610 if (*option == '+')
4611 break;
4612 i++;
cristybb503372010-05-27 20:51:26 +00004613 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004614 ThrowMogrifyException(OptionError,"MissingArgument",option);
4615 break;
4616 }
4617 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4618 }
4619 case 'g':
4620 {
4621 if (LocaleCompare("gamma",option+1) == 0)
4622 {
4623 i++;
cristybb503372010-05-27 20:51:26 +00004624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004625 ThrowMogrifyException(OptionError,"MissingArgument",option);
4626 if (IsGeometry(argv[i]) == MagickFalse)
4627 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4628 break;
4629 }
4630 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4631 (LocaleCompare("gaussian",option+1) == 0))
4632 {
4633 i++;
cristybb503372010-05-27 20:51:26 +00004634 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004635 ThrowMogrifyException(OptionError,"MissingArgument",option);
4636 if (IsGeometry(argv[i]) == MagickFalse)
4637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4638 break;
4639 }
4640 if (LocaleCompare("geometry",option+1) == 0)
4641 {
4642 if (*option == '+')
4643 break;
4644 i++;
cristybb503372010-05-27 20:51:26 +00004645 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004646 ThrowMogrifyException(OptionError,"MissingArgument",option);
4647 if (IsGeometry(argv[i]) == MagickFalse)
4648 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4649 break;
4650 }
4651 if (LocaleCompare("gravity",option+1) == 0)
4652 {
cristybb503372010-05-27 20:51:26 +00004653 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004654 gravity;
4655
4656 if (*option == '+')
4657 break;
4658 i++;
cristybb503372010-05-27 20:51:26 +00004659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004660 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004661 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004662 if (gravity < 0)
4663 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4664 argv[i]);
4665 break;
4666 }
4667 if (LocaleCompare("green-primary",option+1) == 0)
4668 {
4669 if (*option == '+')
4670 break;
4671 i++;
cristybb503372010-05-27 20:51:26 +00004672 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 if (IsGeometry(argv[i]) == MagickFalse)
4675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676 break;
4677 }
4678 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4679 }
4680 case 'h':
4681 {
4682 if (LocaleCompare("hald-clut",option+1) == 0)
4683 break;
4684 if ((LocaleCompare("help",option+1) == 0) ||
4685 (LocaleCompare("-help",option+1) == 0))
4686 return(MogrifyUsage());
4687 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4688 }
4689 case 'i':
4690 {
4691 if (LocaleCompare("identify",option+1) == 0)
4692 break;
4693 if (LocaleCompare("idft",option+1) == 0)
4694 break;
4695 if (LocaleCompare("implode",option+1) == 0)
4696 {
4697 if (*option == '+')
4698 break;
4699 i++;
cristybb503372010-05-27 20:51:26 +00004700 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004701 ThrowMogrifyException(OptionError,"MissingArgument",option);
4702 if (IsGeometry(argv[i]) == MagickFalse)
4703 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4704 break;
4705 }
4706 if (LocaleCompare("intent",option+1) == 0)
4707 {
cristybb503372010-05-27 20:51:26 +00004708 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004709 intent;
4710
4711 if (*option == '+')
4712 break;
4713 i++;
cristybb503372010-05-27 20:51:26 +00004714 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004715 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004716 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004717 if (intent < 0)
4718 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4719 argv[i]);
4720 break;
4721 }
4722 if (LocaleCompare("interlace",option+1) == 0)
4723 {
cristybb503372010-05-27 20:51:26 +00004724 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004725 interlace;
4726
4727 if (*option == '+')
4728 break;
4729 i++;
cristybb503372010-05-27 20:51:26 +00004730 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004731 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004732 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004733 argv[i]);
4734 if (interlace < 0)
4735 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4736 argv[i]);
4737 break;
4738 }
cristyb32b90a2009-09-07 21:45:48 +00004739 if (LocaleCompare("interline-spacing",option+1) == 0)
4740 {
4741 if (*option == '+')
4742 break;
4743 i++;
cristybb503372010-05-27 20:51:26 +00004744 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004745 ThrowMogrifyException(OptionError,"MissingArgument",option);
4746 if (IsGeometry(argv[i]) == MagickFalse)
4747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4748 break;
4749 }
cristy3ed852e2009-09-05 21:47:34 +00004750 if (LocaleCompare("interpolate",option+1) == 0)
4751 {
cristybb503372010-05-27 20:51:26 +00004752 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004753 interpolate;
4754
4755 if (*option == '+')
4756 break;
4757 i++;
cristybb503372010-05-27 20:51:26 +00004758 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004759 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004760 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004761 argv[i]);
4762 if (interpolate < 0)
4763 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4764 argv[i]);
4765 break;
4766 }
4767 if (LocaleCompare("interword-spacing",option+1) == 0)
4768 {
4769 if (*option == '+')
4770 break;
4771 i++;
cristybb503372010-05-27 20:51:26 +00004772 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004773 ThrowMogrifyException(OptionError,"MissingArgument",option);
4774 if (IsGeometry(argv[i]) == MagickFalse)
4775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4776 break;
4777 }
4778 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4779 }
4780 case 'k':
4781 {
4782 if (LocaleCompare("kerning",option+1) == 0)
4783 {
4784 if (*option == '+')
4785 break;
4786 i++;
cristybb503372010-05-27 20:51:26 +00004787 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004788 ThrowMogrifyException(OptionError,"MissingArgument",option);
4789 if (IsGeometry(argv[i]) == MagickFalse)
4790 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4791 break;
4792 }
4793 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4794 }
4795 case 'l':
4796 {
4797 if (LocaleCompare("label",option+1) == 0)
4798 {
4799 if (*option == '+')
4800 break;
4801 i++;
cristybb503372010-05-27 20:51:26 +00004802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004803 ThrowMogrifyException(OptionError,"MissingArgument",option);
4804 break;
4805 }
4806 if (LocaleCompare("lat",option+1) == 0)
4807 {
4808 if (*option == '+')
4809 break;
4810 i++;
cristybb503372010-05-27 20:51:26 +00004811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004812 ThrowMogrifyException(OptionError,"MissingArgument",option);
4813 if (IsGeometry(argv[i]) == MagickFalse)
4814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4815 }
4816 if (LocaleCompare("layers",option+1) == 0)
4817 {
cristybb503372010-05-27 20:51:26 +00004818 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004819 type;
4820
4821 if (*option == '+')
4822 break;
4823 i++;
cristybb503372010-05-27 20:51:26 +00004824 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004825 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004826 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004827 if (type < 0)
4828 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4829 argv[i]);
4830 break;
4831 }
4832 if (LocaleCompare("level",option+1) == 0)
4833 {
4834 i++;
cristybb503372010-05-27 20:51:26 +00004835 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004836 ThrowMogrifyException(OptionError,"MissingArgument",option);
4837 if (IsGeometry(argv[i]) == MagickFalse)
4838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4839 break;
4840 }
4841 if (LocaleCompare("level-colors",option+1) == 0)
4842 {
4843 i++;
cristybb503372010-05-27 20:51:26 +00004844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004845 ThrowMogrifyException(OptionError,"MissingArgument",option);
4846 break;
4847 }
4848 if (LocaleCompare("linewidth",option+1) == 0)
4849 {
4850 if (*option == '+')
4851 break;
4852 i++;
cristybb503372010-05-27 20:51:26 +00004853 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004854 ThrowMogrifyException(OptionError,"MissingArgument",option);
4855 if (IsGeometry(argv[i]) == MagickFalse)
4856 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4857 break;
4858 }
4859 if (LocaleCompare("limit",option+1) == 0)
4860 {
4861 char
4862 *p;
4863
4864 double
4865 value;
4866
cristybb503372010-05-27 20:51:26 +00004867 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004868 resource;
4869
4870 if (*option == '+')
4871 break;
4872 i++;
cristybb503372010-05-27 20:51:26 +00004873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004874 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004875 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004876 argv[i]);
4877 if (resource < 0)
4878 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4879 argv[i]);
4880 i++;
cristybb503372010-05-27 20:51:26 +00004881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004882 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004883 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004884 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004885 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4887 break;
4888 }
4889 if (LocaleCompare("liquid-rescale",option+1) == 0)
4890 {
4891 i++;
cristybb503372010-05-27 20:51:26 +00004892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004893 ThrowMogrifyException(OptionError,"MissingArgument",option);
4894 if (IsGeometry(argv[i]) == MagickFalse)
4895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4896 break;
4897 }
4898 if (LocaleCompare("list",option+1) == 0)
4899 {
cristybb503372010-05-27 20:51:26 +00004900 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004901 list;
4902
4903 if (*option == '+')
4904 break;
4905 i++;
cristybb503372010-05-27 20:51:26 +00004906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004907 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004908 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004909 if (list < 0)
4910 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004911 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004912 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004913 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004914 }
4915 if (LocaleCompare("log",option+1) == 0)
4916 {
4917 if (*option == '+')
4918 break;
4919 i++;
cristybb503372010-05-27 20:51:26 +00004920 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004921 (strchr(argv[i],'%') == (char *) NULL))
4922 ThrowMogrifyException(OptionError,"MissingArgument",option);
4923 break;
4924 }
4925 if (LocaleCompare("loop",option+1) == 0)
4926 {
4927 if (*option == '+')
4928 break;
4929 i++;
cristybb503372010-05-27 20:51:26 +00004930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004931 ThrowMogrifyException(OptionError,"MissingArgument",option);
4932 if (IsGeometry(argv[i]) == MagickFalse)
4933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4934 break;
4935 }
4936 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4937 }
4938 case 'm':
4939 {
4940 if (LocaleCompare("map",option+1) == 0)
4941 {
4942 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4943 if (*option == '+')
4944 break;
4945 i++;
cristybb503372010-05-27 20:51:26 +00004946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004947 ThrowMogrifyException(OptionError,"MissingArgument",option);
4948 break;
4949 }
4950 if (LocaleCompare("mask",option+1) == 0)
4951 {
4952 if (*option == '+')
4953 break;
4954 i++;
cristybb503372010-05-27 20:51:26 +00004955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004956 ThrowMogrifyException(OptionError,"MissingArgument",option);
4957 break;
4958 }
4959 if (LocaleCompare("matte",option+1) == 0)
4960 break;
4961 if (LocaleCompare("mattecolor",option+1) == 0)
4962 {
4963 if (*option == '+')
4964 break;
4965 i++;
cristybb503372010-05-27 20:51:26 +00004966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004967 ThrowMogrifyException(OptionError,"MissingArgument",option);
4968 break;
4969 }
cristyf40785b2010-03-06 02:27:27 +00004970 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004971 break;
cristyf40785b2010-03-06 02:27:27 +00004972 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004973 break;
cristy3ed852e2009-09-05 21:47:34 +00004974 if (LocaleCompare("modulate",option+1) == 0)
4975 {
4976 if (*option == '+')
4977 break;
4978 i++;
cristybb503372010-05-27 20:51:26 +00004979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004980 ThrowMogrifyException(OptionError,"MissingArgument",option);
4981 if (IsGeometry(argv[i]) == MagickFalse)
4982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4983 break;
4984 }
4985 if (LocaleCompare("median",option+1) == 0)
4986 {
4987 if (*option == '+')
4988 break;
4989 i++;
cristybb503372010-05-27 20:51:26 +00004990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004991 ThrowMogrifyException(OptionError,"MissingArgument",option);
4992 if (IsGeometry(argv[i]) == MagickFalse)
4993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4994 break;
4995 }
cristy69ec32d2011-02-27 23:57:09 +00004996 if (LocaleCompare("mode",option+1) == 0)
4997 {
4998 if (*option == '+')
4999 break;
5000 i++;
5001 if (i == (ssize_t) argc)
5002 ThrowMogrifyException(OptionError,"MissingArgument",option);
5003 if (IsGeometry(argv[i]) == MagickFalse)
5004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5005 break;
5006 }
cristy3ed852e2009-09-05 21:47:34 +00005007 if (LocaleCompare("monitor",option+1) == 0)
5008 break;
5009 if (LocaleCompare("monochrome",option+1) == 0)
5010 break;
5011 if (LocaleCompare("morph",option+1) == 0)
5012 {
5013 if (*option == '+')
5014 break;
5015 i++;
cristybb503372010-05-27 20:51:26 +00005016 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005017 ThrowMogrifyException(OptionError,"MissingArgument",option);
5018 if (IsGeometry(argv[i]) == MagickFalse)
5019 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5020 break;
5021 }
anthony29188a82010-01-22 10:12:34 +00005022 if (LocaleCompare("morphology",option+1) == 0)
5023 {
anthony29188a82010-01-22 10:12:34 +00005024 char
5025 token[MaxTextExtent];
5026
cristyb6bd4ad2010-08-08 01:12:27 +00005027 KernelInfo
5028 *kernel_info;
5029
5030 ssize_t
5031 op;
5032
anthony29188a82010-01-22 10:12:34 +00005033 i++;
cristybb503372010-05-27 20:51:26 +00005034 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005035 ThrowMogrifyException(OptionError,"MissingArgument",option);
5036 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005037 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005038 if (op < 0)
5039 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005040 token);
anthony29188a82010-01-22 10:12:34 +00005041 i++;
cristybb503372010-05-27 20:51:26 +00005042 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005043 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005044 kernel_info=AcquireKernelInfo(argv[i]);
5045 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005047 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005048 break;
5049 }
cristy3ed852e2009-09-05 21:47:34 +00005050 if (LocaleCompare("mosaic",option+1) == 0)
5051 break;
5052 if (LocaleCompare("motion-blur",option+1) == 0)
5053 {
5054 if (*option == '+')
5055 break;
5056 i++;
cristybb503372010-05-27 20:51:26 +00005057 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005058 ThrowMogrifyException(OptionError,"MissingArgument",option);
5059 if (IsGeometry(argv[i]) == MagickFalse)
5060 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5061 break;
5062 }
5063 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5064 }
5065 case 'n':
5066 {
5067 if (LocaleCompare("negate",option+1) == 0)
5068 break;
5069 if (LocaleCompare("noise",option+1) == 0)
5070 {
5071 i++;
cristybb503372010-05-27 20:51:26 +00005072 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005073 ThrowMogrifyException(OptionError,"MissingArgument",option);
5074 if (*option == '+')
5075 {
cristybb503372010-05-27 20:51:26 +00005076 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005077 noise;
5078
cristy042ee782011-04-22 18:48:30 +00005079 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005080 if (noise < 0)
5081 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5082 argv[i]);
5083 break;
5084 }
5085 if (IsGeometry(argv[i]) == MagickFalse)
5086 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5087 break;
5088 }
5089 if (LocaleCompare("noop",option+1) == 0)
5090 break;
5091 if (LocaleCompare("normalize",option+1) == 0)
5092 break;
5093 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5094 }
5095 case 'o':
5096 {
5097 if (LocaleCompare("opaque",option+1) == 0)
5098 {
cristy3ed852e2009-09-05 21:47:34 +00005099 i++;
cristybb503372010-05-27 20:51:26 +00005100 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005101 ThrowMogrifyException(OptionError,"MissingArgument",option);
5102 break;
5103 }
5104 if (LocaleCompare("ordered-dither",option+1) == 0)
5105 {
5106 if (*option == '+')
5107 break;
5108 i++;
cristybb503372010-05-27 20:51:26 +00005109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005110 ThrowMogrifyException(OptionError,"MissingArgument",option);
5111 break;
5112 }
5113 if (LocaleCompare("orient",option+1) == 0)
5114 {
cristybb503372010-05-27 20:51:26 +00005115 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005116 orientation;
5117
5118 orientation=UndefinedOrientation;
5119 if (*option == '+')
5120 break;
5121 i++;
cristybb503372010-05-27 20:51:26 +00005122 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005123 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005124 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005125 argv[i]);
5126 if (orientation < 0)
5127 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5128 argv[i]);
5129 break;
5130 }
5131 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5132 }
5133 case 'p':
5134 {
5135 if (LocaleCompare("page",option+1) == 0)
5136 {
5137 if (*option == '+')
5138 break;
5139 i++;
cristybb503372010-05-27 20:51:26 +00005140 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005141 ThrowMogrifyException(OptionError,"MissingArgument",option);
5142 break;
5143 }
5144 if (LocaleCompare("paint",option+1) == 0)
5145 {
5146 if (*option == '+')
5147 break;
5148 i++;
cristybb503372010-05-27 20:51:26 +00005149 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005150 ThrowMogrifyException(OptionError,"MissingArgument",option);
5151 if (IsGeometry(argv[i]) == MagickFalse)
5152 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5153 break;
5154 }
5155 if (LocaleCompare("path",option+1) == 0)
5156 {
5157 (void) CloneString(&path,(char *) NULL);
5158 if (*option == '+')
5159 break;
5160 i++;
cristybb503372010-05-27 20:51:26 +00005161 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005162 ThrowMogrifyException(OptionError,"MissingArgument",option);
5163 (void) CloneString(&path,argv[i]);
5164 break;
5165 }
5166 if (LocaleCompare("pointsize",option+1) == 0)
5167 {
5168 if (*option == '+')
5169 break;
5170 i++;
cristybb503372010-05-27 20:51:26 +00005171 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005172 ThrowMogrifyException(OptionError,"MissingArgument",option);
5173 if (IsGeometry(argv[i]) == MagickFalse)
5174 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5175 break;
5176 }
5177 if (LocaleCompare("polaroid",option+1) == 0)
5178 {
5179 if (*option == '+')
5180 break;
5181 i++;
cristybb503372010-05-27 20:51:26 +00005182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005183 ThrowMogrifyException(OptionError,"MissingArgument",option);
5184 if (IsGeometry(argv[i]) == MagickFalse)
5185 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5186 break;
5187 }
5188 if (LocaleCompare("posterize",option+1) == 0)
5189 {
5190 if (*option == '+')
5191 break;
5192 i++;
cristybb503372010-05-27 20:51:26 +00005193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005194 ThrowMogrifyException(OptionError,"MissingArgument",option);
5195 if (IsGeometry(argv[i]) == MagickFalse)
5196 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5197 break;
5198 }
cristye7f51092010-01-17 00:39:37 +00005199 if (LocaleCompare("precision",option+1) == 0)
5200 {
5201 if (*option == '+')
5202 break;
5203 i++;
cristybb503372010-05-27 20:51:26 +00005204 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005205 ThrowMogrifyException(OptionError,"MissingArgument",option);
5206 if (IsGeometry(argv[i]) == MagickFalse)
5207 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5208 break;
5209 }
cristy3ed852e2009-09-05 21:47:34 +00005210 if (LocaleCompare("print",option+1) == 0)
5211 {
5212 if (*option == '+')
5213 break;
5214 i++;
cristybb503372010-05-27 20:51:26 +00005215 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005216 ThrowMogrifyException(OptionError,"MissingArgument",option);
5217 break;
5218 }
5219 if (LocaleCompare("process",option+1) == 0)
5220 {
5221 if (*option == '+')
5222 break;
5223 i++;
cristybb503372010-05-27 20:51:26 +00005224 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005225 ThrowMogrifyException(OptionError,"MissingArgument",option);
5226 break;
5227 }
5228 if (LocaleCompare("profile",option+1) == 0)
5229 {
5230 i++;
cristybb503372010-05-27 20:51:26 +00005231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005232 ThrowMogrifyException(OptionError,"MissingArgument",option);
5233 break;
5234 }
5235 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5236 }
5237 case 'q':
5238 {
5239 if (LocaleCompare("quality",option+1) == 0)
5240 {
5241 if (*option == '+')
5242 break;
5243 i++;
cristybb503372010-05-27 20:51:26 +00005244 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005245 ThrowMogrifyException(OptionError,"MissingArgument",option);
5246 if (IsGeometry(argv[i]) == MagickFalse)
5247 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5248 break;
5249 }
5250 if (LocaleCompare("quantize",option+1) == 0)
5251 {
cristybb503372010-05-27 20:51:26 +00005252 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005253 colorspace;
5254
5255 if (*option == '+')
5256 break;
5257 i++;
cristybb503372010-05-27 20:51:26 +00005258 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005259 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005260 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005261 argv[i]);
5262 if (colorspace < 0)
5263 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5264 argv[i]);
5265 break;
5266 }
5267 if (LocaleCompare("quiet",option+1) == 0)
5268 break;
5269 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5270 }
5271 case 'r':
5272 {
5273 if (LocaleCompare("radial-blur",option+1) == 0)
5274 {
5275 i++;
cristybb503372010-05-27 20:51:26 +00005276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005277 ThrowMogrifyException(OptionError,"MissingArgument",option);
5278 if (IsGeometry(argv[i]) == MagickFalse)
5279 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5280 break;
5281 }
5282 if (LocaleCompare("raise",option+1) == 0)
5283 {
5284 i++;
cristybb503372010-05-27 20:51:26 +00005285 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005286 ThrowMogrifyException(OptionError,"MissingArgument",option);
5287 if (IsGeometry(argv[i]) == MagickFalse)
5288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5289 break;
5290 }
5291 if (LocaleCompare("random-threshold",option+1) == 0)
5292 {
5293 if (*option == '+')
5294 break;
5295 i++;
cristybb503372010-05-27 20:51:26 +00005296 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005297 ThrowMogrifyException(OptionError,"MissingArgument",option);
5298 if (IsGeometry(argv[i]) == MagickFalse)
5299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5300 break;
5301 }
cristye6365592010-04-02 17:31:23 +00005302 if (LocaleCompare("recolor",option+1) == 0)
5303 {
5304 if (*option == '+')
5305 break;
5306 i++;
cristybb503372010-05-27 20:51:26 +00005307 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005308 ThrowMogrifyException(OptionError,"MissingArgument",option);
5309 if (IsGeometry(argv[i]) == MagickFalse)
5310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5311 break;
5312 }
cristy3ed852e2009-09-05 21:47:34 +00005313 if (LocaleCompare("red-primary",option+1) == 0)
5314 {
5315 if (*option == '+')
5316 break;
5317 i++;
cristybb503372010-05-27 20:51:26 +00005318 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005319 ThrowMogrifyException(OptionError,"MissingArgument",option);
5320 if (IsGeometry(argv[i]) == MagickFalse)
5321 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5322 }
cristy9f2083a2010-04-22 19:48:05 +00005323 if (LocaleCompare("regard-warnings",option+1) == 0)
5324 break;
cristy3ed852e2009-09-05 21:47:34 +00005325 if (LocaleCompare("region",option+1) == 0)
5326 {
5327 if (*option == '+')
5328 break;
5329 i++;
cristybb503372010-05-27 20:51:26 +00005330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 if (IsGeometry(argv[i]) == MagickFalse)
5333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5334 break;
5335 }
cristyf0c78232010-03-15 12:53:40 +00005336 if (LocaleCompare("remap",option+1) == 0)
5337 {
5338 if (*option == '+')
5339 break;
5340 i++;
cristybb503372010-05-27 20:51:26 +00005341 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005342 ThrowMogrifyException(OptionError,"MissingArgument",option);
5343 break;
5344 }
cristy3ed852e2009-09-05 21:47:34 +00005345 if (LocaleCompare("render",option+1) == 0)
5346 break;
5347 if (LocaleCompare("repage",option+1) == 0)
5348 {
5349 if (*option == '+')
5350 break;
5351 i++;
cristybb503372010-05-27 20:51:26 +00005352 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005353 ThrowMogrifyException(OptionError,"MissingArgument",option);
5354 if (IsGeometry(argv[i]) == MagickFalse)
5355 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5356 break;
5357 }
5358 if (LocaleCompare("resample",option+1) == 0)
5359 {
5360 if (*option == '+')
5361 break;
5362 i++;
cristybb503372010-05-27 20:51:26 +00005363 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005364 ThrowMogrifyException(OptionError,"MissingArgument",option);
5365 if (IsGeometry(argv[i]) == MagickFalse)
5366 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5367 break;
5368 }
5369 if (LocaleCompare("resize",option+1) == 0)
5370 {
5371 if (*option == '+')
5372 break;
5373 i++;
cristybb503372010-05-27 20:51:26 +00005374 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005375 ThrowMogrifyException(OptionError,"MissingArgument",option);
5376 if (IsGeometry(argv[i]) == MagickFalse)
5377 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5378 break;
5379 }
cristyebbcfea2011-02-25 02:43:54 +00005380 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5381 {
5382 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5383 break;
5384 }
cristy3ed852e2009-09-05 21:47:34 +00005385 if (LocaleCompare("reverse",option+1) == 0)
5386 break;
5387 if (LocaleCompare("roll",option+1) == 0)
5388 {
5389 if (*option == '+')
5390 break;
5391 i++;
cristybb503372010-05-27 20:51:26 +00005392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005393 ThrowMogrifyException(OptionError,"MissingArgument",option);
5394 if (IsGeometry(argv[i]) == MagickFalse)
5395 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5396 break;
5397 }
5398 if (LocaleCompare("rotate",option+1) == 0)
5399 {
5400 i++;
cristybb503372010-05-27 20:51:26 +00005401 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005402 ThrowMogrifyException(OptionError,"MissingArgument",option);
5403 if (IsGeometry(argv[i]) == MagickFalse)
5404 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5405 break;
5406 }
5407 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5408 }
5409 case 's':
5410 {
5411 if (LocaleCompare("sample",option+1) == 0)
5412 {
5413 if (*option == '+')
5414 break;
5415 i++;
cristybb503372010-05-27 20:51:26 +00005416 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005417 ThrowMogrifyException(OptionError,"MissingArgument",option);
5418 if (IsGeometry(argv[i]) == MagickFalse)
5419 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5420 break;
5421 }
5422 if (LocaleCompare("sampling-factor",option+1) == 0)
5423 {
5424 if (*option == '+')
5425 break;
5426 i++;
cristybb503372010-05-27 20:51:26 +00005427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005428 ThrowMogrifyException(OptionError,"MissingArgument",option);
5429 if (IsGeometry(argv[i]) == MagickFalse)
5430 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5431 break;
5432 }
5433 if (LocaleCompare("scale",option+1) == 0)
5434 {
5435 if (*option == '+')
5436 break;
5437 i++;
cristybb503372010-05-27 20:51:26 +00005438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005439 ThrowMogrifyException(OptionError,"MissingArgument",option);
5440 if (IsGeometry(argv[i]) == MagickFalse)
5441 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5442 break;
5443 }
5444 if (LocaleCompare("scene",option+1) == 0)
5445 {
5446 if (*option == '+')
5447 break;
5448 i++;
cristybb503372010-05-27 20:51:26 +00005449 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005450 ThrowMogrifyException(OptionError,"MissingArgument",option);
5451 if (IsGeometry(argv[i]) == MagickFalse)
5452 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5453 break;
5454 }
5455 if (LocaleCompare("seed",option+1) == 0)
5456 {
5457 if (*option == '+')
5458 break;
5459 i++;
cristybb503372010-05-27 20:51:26 +00005460 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005461 ThrowMogrifyException(OptionError,"MissingArgument",option);
5462 if (IsGeometry(argv[i]) == MagickFalse)
5463 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5464 break;
5465 }
5466 if (LocaleCompare("segment",option+1) == 0)
5467 {
5468 if (*option == '+')
5469 break;
5470 i++;
cristybb503372010-05-27 20:51:26 +00005471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005472 ThrowMogrifyException(OptionError,"MissingArgument",option);
5473 if (IsGeometry(argv[i]) == MagickFalse)
5474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5475 break;
5476 }
5477 if (LocaleCompare("selective-blur",option+1) == 0)
5478 {
5479 i++;
cristybb503372010-05-27 20:51:26 +00005480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005481 ThrowMogrifyException(OptionError,"MissingArgument",option);
5482 if (IsGeometry(argv[i]) == MagickFalse)
5483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484 break;
5485 }
5486 if (LocaleCompare("separate",option+1) == 0)
5487 break;
5488 if (LocaleCompare("sepia-tone",option+1) == 0)
5489 {
5490 if (*option == '+')
5491 break;
5492 i++;
cristybb503372010-05-27 20:51:26 +00005493 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005494 ThrowMogrifyException(OptionError,"MissingArgument",option);
5495 if (IsGeometry(argv[i]) == MagickFalse)
5496 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5497 break;
5498 }
5499 if (LocaleCompare("set",option+1) == 0)
5500 {
5501 i++;
cristybb503372010-05-27 20:51:26 +00005502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005503 ThrowMogrifyException(OptionError,"MissingArgument",option);
5504 if (*option == '+')
5505 break;
5506 i++;
cristybb503372010-05-27 20:51:26 +00005507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005508 ThrowMogrifyException(OptionError,"MissingArgument",option);
5509 break;
5510 }
5511 if (LocaleCompare("shade",option+1) == 0)
5512 {
5513 i++;
cristybb503372010-05-27 20:51:26 +00005514 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005515 ThrowMogrifyException(OptionError,"MissingArgument",option);
5516 if (IsGeometry(argv[i]) == MagickFalse)
5517 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5518 break;
5519 }
5520 if (LocaleCompare("shadow",option+1) == 0)
5521 {
5522 if (*option == '+')
5523 break;
5524 i++;
cristybb503372010-05-27 20:51:26 +00005525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005526 ThrowMogrifyException(OptionError,"MissingArgument",option);
5527 if (IsGeometry(argv[i]) == MagickFalse)
5528 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5529 break;
5530 }
5531 if (LocaleCompare("sharpen",option+1) == 0)
5532 {
5533 i++;
cristybb503372010-05-27 20:51:26 +00005534 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005535 ThrowMogrifyException(OptionError,"MissingArgument",option);
5536 if (IsGeometry(argv[i]) == MagickFalse)
5537 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5538 break;
5539 }
5540 if (LocaleCompare("shave",option+1) == 0)
5541 {
5542 if (*option == '+')
5543 break;
5544 i++;
cristybb503372010-05-27 20:51:26 +00005545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 if (IsGeometry(argv[i]) == MagickFalse)
5548 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5549 break;
5550 }
5551 if (LocaleCompare("shear",option+1) == 0)
5552 {
5553 i++;
cristybb503372010-05-27 20:51:26 +00005554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 if (IsGeometry(argv[i]) == MagickFalse)
5557 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5558 break;
5559 }
5560 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5561 {
5562 i++;
cristybb503372010-05-27 20:51:26 +00005563 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005564 ThrowMogrifyException(OptionError,"MissingArgument",option);
5565 if (IsGeometry(argv[i]) == MagickFalse)
5566 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5567 break;
5568 }
5569 if (LocaleCompare("size",option+1) == 0)
5570 {
5571 if (*option == '+')
5572 break;
5573 i++;
cristybb503372010-05-27 20:51:26 +00005574 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005575 ThrowMogrifyException(OptionError,"MissingArgument",option);
5576 if (IsGeometry(argv[i]) == MagickFalse)
5577 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5578 break;
5579 }
5580 if (LocaleCompare("sketch",option+1) == 0)
5581 {
5582 if (*option == '+')
5583 break;
5584 i++;
cristybb503372010-05-27 20:51:26 +00005585 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 if (IsGeometry(argv[i]) == MagickFalse)
5588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5589 break;
5590 }
cristy4285d782011-02-09 20:12:28 +00005591 if (LocaleCompare("smush",option+1) == 0)
5592 {
cristy4285d782011-02-09 20:12:28 +00005593 i++;
5594 if (i == (ssize_t) argc)
5595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005598 i++;
5599 break;
5600 }
cristy3ed852e2009-09-05 21:47:34 +00005601 if (LocaleCompare("solarize",option+1) == 0)
5602 {
5603 if (*option == '+')
5604 break;
5605 i++;
cristybb503372010-05-27 20:51:26 +00005606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 if (IsGeometry(argv[i]) == MagickFalse)
5609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5610 break;
5611 }
5612 if (LocaleCompare("sparse-color",option+1) == 0)
5613 {
cristybb503372010-05-27 20:51:26 +00005614 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005615 op;
5616
5617 i++;
cristybb503372010-05-27 20:51:26 +00005618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005619 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005620 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005621 if (op < 0)
5622 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5623 argv[i]);
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 break;
5628 }
5629 if (LocaleCompare("spread",option+1) == 0)
5630 {
5631 if (*option == '+')
5632 break;
5633 i++;
cristybb503372010-05-27 20:51:26 +00005634 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005635 ThrowMogrifyException(OptionError,"MissingArgument",option);
5636 if (IsGeometry(argv[i]) == MagickFalse)
5637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5638 break;
5639 }
cristy0834d642011-03-18 18:26:08 +00005640 if (LocaleCompare("statistic",option+1) == 0)
5641 {
5642 ssize_t
5643 op;
5644
5645 if (*option == '+')
5646 break;
5647 i++;
5648 if (i == (ssize_t) argc)
5649 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005650 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005651 if (op < 0)
5652 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5653 argv[i]);
5654 i++;
5655 if (i == (ssize_t) (argc-1))
5656 ThrowMogrifyException(OptionError,"MissingArgument",option);
5657 if (IsGeometry(argv[i]) == MagickFalse)
5658 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5659 break;
5660 }
cristy3ed852e2009-09-05 21:47:34 +00005661 if (LocaleCompare("stretch",option+1) == 0)
5662 {
cristybb503372010-05-27 20:51:26 +00005663 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005664 stretch;
5665
5666 if (*option == '+')
5667 break;
5668 i++;
cristybb503372010-05-27 20:51:26 +00005669 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005670 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005671 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005672 if (stretch < 0)
5673 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5674 argv[i]);
5675 break;
5676 }
5677 if (LocaleCompare("strip",option+1) == 0)
5678 break;
5679 if (LocaleCompare("stroke",option+1) == 0)
5680 {
5681 if (*option == '+')
5682 break;
5683 i++;
cristybb503372010-05-27 20:51:26 +00005684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005685 ThrowMogrifyException(OptionError,"MissingArgument",option);
5686 break;
5687 }
5688 if (LocaleCompare("strokewidth",option+1) == 0)
5689 {
5690 if (*option == '+')
5691 break;
5692 i++;
cristybb503372010-05-27 20:51:26 +00005693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005694 ThrowMogrifyException(OptionError,"MissingArgument",option);
5695 if (IsGeometry(argv[i]) == MagickFalse)
5696 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5697 break;
5698 }
5699 if (LocaleCompare("style",option+1) == 0)
5700 {
cristybb503372010-05-27 20:51:26 +00005701 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005702 style;
5703
5704 if (*option == '+')
5705 break;
5706 i++;
cristybb503372010-05-27 20:51:26 +00005707 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005708 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005709 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005710 if (style < 0)
5711 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5712 argv[i]);
5713 break;
5714 }
cristyecb10ff2011-03-22 13:14:03 +00005715 if (LocaleCompare("swap",option+1) == 0)
5716 {
5717 if (*option == '+')
5718 break;
5719 i++;
5720 if (i == (ssize_t) (argc-1))
5721 ThrowMogrifyException(OptionError,"MissingArgument",option);
5722 if (IsGeometry(argv[i]) == MagickFalse)
5723 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5724 break;
5725 }
cristy3ed852e2009-09-05 21:47:34 +00005726 if (LocaleCompare("swirl",option+1) == 0)
5727 {
5728 if (*option == '+')
5729 break;
5730 i++;
cristybb503372010-05-27 20:51:26 +00005731 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005732 ThrowMogrifyException(OptionError,"MissingArgument",option);
5733 if (IsGeometry(argv[i]) == MagickFalse)
5734 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5735 break;
5736 }
cristyd9a29192010-10-16 16:49:53 +00005737 if (LocaleCompare("synchronize",option+1) == 0)
5738 break;
cristy3ed852e2009-09-05 21:47:34 +00005739 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5740 }
5741 case 't':
5742 {
5743 if (LocaleCompare("taint",option+1) == 0)
5744 break;
5745 if (LocaleCompare("texture",option+1) == 0)
5746 {
5747 if (*option == '+')
5748 break;
5749 i++;
cristybb503372010-05-27 20:51:26 +00005750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005751 ThrowMogrifyException(OptionError,"MissingArgument",option);
5752 break;
5753 }
5754 if (LocaleCompare("tile",option+1) == 0)
5755 {
5756 if (*option == '+')
5757 break;
5758 i++;
cristybb503372010-05-27 20:51:26 +00005759 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005760 ThrowMogrifyException(OptionError,"MissingArgument",option);
5761 break;
5762 }
5763 if (LocaleCompare("tile-offset",option+1) == 0)
5764 {
5765 if (*option == '+')
5766 break;
5767 i++;
cristybb503372010-05-27 20:51:26 +00005768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005769 ThrowMogrifyException(OptionError,"MissingArgument",option);
5770 if (IsGeometry(argv[i]) == MagickFalse)
5771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5772 break;
5773 }
5774 if (LocaleCompare("tint",option+1) == 0)
5775 {
5776 if (*option == '+')
5777 break;
5778 i++;
cristybb503372010-05-27 20:51:26 +00005779 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005780 ThrowMogrifyException(OptionError,"MissingArgument",option);
5781 if (IsGeometry(argv[i]) == MagickFalse)
5782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5783 break;
5784 }
5785 if (LocaleCompare("transform",option+1) == 0)
5786 break;
5787 if (LocaleCompare("transpose",option+1) == 0)
5788 break;
5789 if (LocaleCompare("transverse",option+1) == 0)
5790 break;
5791 if (LocaleCompare("threshold",option+1) == 0)
5792 {
5793 if (*option == '+')
5794 break;
5795 i++;
cristybb503372010-05-27 20:51:26 +00005796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005797 ThrowMogrifyException(OptionError,"MissingArgument",option);
5798 if (IsGeometry(argv[i]) == MagickFalse)
5799 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5800 break;
5801 }
5802 if (LocaleCompare("thumbnail",option+1) == 0)
5803 {
5804 if (*option == '+')
5805 break;
5806 i++;
cristybb503372010-05-27 20:51:26 +00005807 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005808 ThrowMogrifyException(OptionError,"MissingArgument",option);
5809 if (IsGeometry(argv[i]) == MagickFalse)
5810 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5811 break;
5812 }
5813 if (LocaleCompare("transparent",option+1) == 0)
5814 {
5815 i++;
cristybb503372010-05-27 20:51:26 +00005816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005817 ThrowMogrifyException(OptionError,"MissingArgument",option);
5818 break;
5819 }
5820 if (LocaleCompare("transparent-color",option+1) == 0)
5821 {
5822 if (*option == '+')
5823 break;
5824 i++;
cristybb503372010-05-27 20:51:26 +00005825 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005826 ThrowMogrifyException(OptionError,"MissingArgument",option);
5827 break;
5828 }
5829 if (LocaleCompare("treedepth",option+1) == 0)
5830 {
5831 if (*option == '+')
5832 break;
5833 i++;
cristybb503372010-05-27 20:51:26 +00005834 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005835 ThrowMogrifyException(OptionError,"MissingArgument",option);
5836 if (IsGeometry(argv[i]) == MagickFalse)
5837 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5838 break;
5839 }
5840 if (LocaleCompare("trim",option+1) == 0)
5841 break;
5842 if (LocaleCompare("type",option+1) == 0)
5843 {
cristybb503372010-05-27 20:51:26 +00005844 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005845 type;
5846
5847 if (*option == '+')
5848 break;
5849 i++;
cristybb503372010-05-27 20:51:26 +00005850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005851 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005852 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005853 if (type < 0)
5854 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5855 argv[i]);
5856 break;
5857 }
5858 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5859 }
5860 case 'u':
5861 {
5862 if (LocaleCompare("undercolor",option+1) == 0)
5863 {
5864 if (*option == '+')
5865 break;
5866 i++;
cristybb503372010-05-27 20:51:26 +00005867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005868 ThrowMogrifyException(OptionError,"MissingArgument",option);
5869 break;
5870 }
5871 if (LocaleCompare("unique-colors",option+1) == 0)
5872 break;
5873 if (LocaleCompare("units",option+1) == 0)
5874 {
cristybb503372010-05-27 20:51:26 +00005875 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005876 units;
5877
5878 if (*option == '+')
5879 break;
5880 i++;
cristybb503372010-05-27 20:51:26 +00005881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005882 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005883 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005884 argv[i]);
5885 if (units < 0)
5886 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5887 argv[i]);
5888 break;
5889 }
5890 if (LocaleCompare("unsharp",option+1) == 0)
5891 {
5892 i++;
cristybb503372010-05-27 20:51:26 +00005893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005894 ThrowMogrifyException(OptionError,"MissingArgument",option);
5895 if (IsGeometry(argv[i]) == MagickFalse)
5896 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5897 break;
5898 }
5899 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5900 }
5901 case 'v':
5902 {
5903 if (LocaleCompare("verbose",option+1) == 0)
5904 {
5905 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5906 break;
5907 }
5908 if ((LocaleCompare("version",option+1) == 0) ||
5909 (LocaleCompare("-version",option+1) == 0))
5910 {
cristyb51dff52011-05-19 16:55:47 +00005911 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005912 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005913 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5914 GetMagickCopyright());
5915 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5916 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005917 break;
5918 }
5919 if (LocaleCompare("view",option+1) == 0)
5920 {
5921 if (*option == '+')
5922 break;
5923 i++;
cristybb503372010-05-27 20:51:26 +00005924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005925 ThrowMogrifyException(OptionError,"MissingArgument",option);
5926 break;
5927 }
5928 if (LocaleCompare("vignette",option+1) == 0)
5929 {
5930 if (*option == '+')
5931 break;
5932 i++;
cristybb503372010-05-27 20:51:26 +00005933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005934 ThrowMogrifyException(OptionError,"MissingArgument",option);
5935 if (IsGeometry(argv[i]) == MagickFalse)
5936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5937 break;
5938 }
5939 if (LocaleCompare("virtual-pixel",option+1) == 0)
5940 {
cristybb503372010-05-27 20:51:26 +00005941 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005942 method;
5943
5944 if (*option == '+')
5945 break;
5946 i++;
cristybb503372010-05-27 20:51:26 +00005947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005948 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005949 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005950 argv[i]);
5951 if (method < 0)
5952 ThrowMogrifyException(OptionError,
5953 "UnrecognizedVirtualPixelMethod",argv[i]);
5954 break;
5955 }
5956 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5957 }
5958 case 'w':
5959 {
5960 if (LocaleCompare("wave",option+1) == 0)
5961 {
5962 i++;
cristybb503372010-05-27 20:51:26 +00005963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005964 ThrowMogrifyException(OptionError,"MissingArgument",option);
5965 if (IsGeometry(argv[i]) == MagickFalse)
5966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5967 break;
5968 }
5969 if (LocaleCompare("weight",option+1) == 0)
5970 {
5971 if (*option == '+')
5972 break;
5973 i++;
cristybb503372010-05-27 20:51:26 +00005974 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005975 ThrowMogrifyException(OptionError,"MissingArgument",option);
5976 break;
5977 }
5978 if (LocaleCompare("white-point",option+1) == 0)
5979 {
5980 if (*option == '+')
5981 break;
5982 i++;
cristybb503372010-05-27 20:51:26 +00005983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005984 ThrowMogrifyException(OptionError,"MissingArgument",option);
5985 if (IsGeometry(argv[i]) == MagickFalse)
5986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5987 break;
5988 }
5989 if (LocaleCompare("white-threshold",option+1) == 0)
5990 {
5991 if (*option == '+')
5992 break;
5993 i++;
cristybb503372010-05-27 20:51:26 +00005994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005995 ThrowMogrifyException(OptionError,"MissingArgument",option);
5996 if (IsGeometry(argv[i]) == MagickFalse)
5997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5998 break;
5999 }
6000 if (LocaleCompare("write",option+1) == 0)
6001 {
6002 i++;
cristybb503372010-05-27 20:51:26 +00006003 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006004 ThrowMogrifyException(OptionError,"MissingArgument",option);
6005 break;
6006 }
6007 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6008 }
6009 case '?':
6010 break;
6011 default:
6012 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6013 }
cristy042ee782011-04-22 18:48:30 +00006014 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6015 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006016 if (fire != MagickFalse)
6017 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6018 }
6019 if (k != 0)
6020 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006021 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006022 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6023 DestroyMogrify();
6024 return(status != 0 ? MagickTrue : MagickFalse);
6025}
6026
6027/*
6028%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6029% %
6030% %
6031% %
6032+ M o g r i f y I m a g e I n f o %
6033% %
6034% %
6035% %
6036%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6037%
6038% MogrifyImageInfo() applies image processing settings to the image as
6039% prescribed by command line options.
6040%
6041% The format of the MogrifyImageInfo method is:
6042%
6043% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6044% const char **argv,ExceptionInfo *exception)
6045%
6046% A description of each parameter follows:
6047%
6048% o image_info: the image info..
6049%
6050% o argc: Specifies a pointer to an integer describing the number of
6051% elements in the argument vector.
6052%
6053% o argv: Specifies a pointer to a text array containing the command line
6054% arguments.
6055%
6056% o exception: return any errors or warnings in this structure.
6057%
6058*/
6059WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6060 const int argc,const char **argv,ExceptionInfo *exception)
6061{
6062 const char
6063 *option;
6064
6065 GeometryInfo
6066 geometry_info;
6067
cristybb503372010-05-27 20:51:26 +00006068 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006069 count;
6070
cristybb503372010-05-27 20:51:26 +00006071 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006072 i;
6073
6074 /*
6075 Initialize method variables.
6076 */
6077 assert(image_info != (ImageInfo *) NULL);
6078 assert(image_info->signature == MagickSignature);
6079 if (image_info->debug != MagickFalse)
6080 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6081 image_info->filename);
6082 if (argc < 0)
6083 return(MagickTrue);
6084 /*
6085 Set the image settings.
6086 */
cristybb503372010-05-27 20:51:26 +00006087 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006088 {
6089 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006090 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006091 continue;
cristy042ee782011-04-22 18:48:30 +00006092 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006093 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006094 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006095 break;
6096 switch (*(option+1))
6097 {
6098 case 'a':
6099 {
6100 if (LocaleCompare("adjoin",option+1) == 0)
6101 {
6102 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6103 break;
6104 }
6105 if (LocaleCompare("antialias",option+1) == 0)
6106 {
6107 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6108 break;
6109 }
6110 if (LocaleCompare("attenuate",option+1) == 0)
6111 {
6112 if (*option == '+')
6113 {
6114 (void) DeleteImageOption(image_info,option+1);
6115 break;
6116 }
6117 (void) SetImageOption(image_info,option+1,argv[i+1]);
6118 break;
6119 }
6120 if (LocaleCompare("authenticate",option+1) == 0)
6121 {
6122 if (*option == '+')
6123 (void) CloneString(&image_info->authenticate,(char *) NULL);
6124 else
6125 (void) CloneString(&image_info->authenticate,argv[i+1]);
6126 break;
6127 }
6128 break;
6129 }
6130 case 'b':
6131 {
6132 if (LocaleCompare("background",option+1) == 0)
6133 {
6134 if (*option == '+')
6135 {
6136 (void) DeleteImageOption(image_info,option+1);
6137 (void) QueryColorDatabase(BackgroundColor,
6138 &image_info->background_color,exception);
6139 break;
6140 }
6141 (void) SetImageOption(image_info,option+1,argv[i+1]);
6142 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6143 exception);
6144 break;
6145 }
6146 if (LocaleCompare("bias",option+1) == 0)
6147 {
6148 if (*option == '+')
6149 {
6150 (void) SetImageOption(image_info,option+1,"0.0");
6151 break;
6152 }
6153 (void) SetImageOption(image_info,option+1,argv[i+1]);
6154 break;
6155 }
6156 if (LocaleCompare("black-point-compensation",option+1) == 0)
6157 {
6158 if (*option == '+')
6159 {
6160 (void) SetImageOption(image_info,option+1,"false");
6161 break;
6162 }
6163 (void) SetImageOption(image_info,option+1,"true");
6164 break;
6165 }
6166 if (LocaleCompare("blue-primary",option+1) == 0)
6167 {
6168 if (*option == '+')
6169 {
6170 (void) SetImageOption(image_info,option+1,"0.0");
6171 break;
6172 }
6173 (void) SetImageOption(image_info,option+1,argv[i+1]);
6174 break;
6175 }
6176 if (LocaleCompare("bordercolor",option+1) == 0)
6177 {
6178 if (*option == '+')
6179 {
6180 (void) DeleteImageOption(image_info,option+1);
6181 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6182 exception);
6183 break;
6184 }
6185 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6186 exception);
6187 (void) SetImageOption(image_info,option+1,argv[i+1]);
6188 break;
6189 }
6190 if (LocaleCompare("box",option+1) == 0)
6191 {
6192 if (*option == '+')
6193 {
6194 (void) SetImageOption(image_info,"undercolor","none");
6195 break;
6196 }
6197 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6198 break;
6199 }
6200 break;
6201 }
6202 case 'c':
6203 {
6204 if (LocaleCompare("cache",option+1) == 0)
6205 {
6206 MagickSizeType
6207 limit;
6208
6209 limit=MagickResourceInfinity;
6210 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006211 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006212 (void) SetMagickResourceLimit(MemoryResource,limit);
6213 (void) SetMagickResourceLimit(MapResource,2*limit);
6214 break;
6215 }
6216 if (LocaleCompare("caption",option+1) == 0)
6217 {
6218 if (*option == '+')
6219 {
6220 (void) DeleteImageOption(image_info,option+1);
6221 break;
6222 }
6223 (void) SetImageOption(image_info,option+1,argv[i+1]);
6224 break;
6225 }
6226 if (LocaleCompare("channel",option+1) == 0)
6227 {
6228 if (*option == '+')
6229 {
6230 image_info->channel=DefaultChannels;
6231 break;
6232 }
6233 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6234 break;
6235 }
6236 if (LocaleCompare("colors",option+1) == 0)
6237 {
cristye27293e2009-12-18 02:53:20 +00006238 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006239 break;
6240 }
6241 if (LocaleCompare("colorspace",option+1) == 0)
6242 {
6243 if (*option == '+')
6244 {
6245 image_info->colorspace=UndefinedColorspace;
6246 (void) SetImageOption(image_info,option+1,"undefined");
6247 break;
6248 }
cristy042ee782011-04-22 18:48:30 +00006249 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006250 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6251 (void) SetImageOption(image_info,option+1,argv[i+1]);
6252 break;
6253 }
cristy3ed852e2009-09-05 21:47:34 +00006254 if (LocaleCompare("comment",option+1) == 0)
6255 {
6256 if (*option == '+')
6257 {
6258 (void) DeleteImageOption(image_info,option+1);
6259 break;
6260 }
6261 (void) SetImageOption(image_info,option+1,argv[i+1]);
6262 break;
6263 }
6264 if (LocaleCompare("compose",option+1) == 0)
6265 {
6266 if (*option == '+')
6267 {
6268 (void) SetImageOption(image_info,option+1,"undefined");
6269 break;
6270 }
6271 (void) SetImageOption(image_info,option+1,argv[i+1]);
6272 break;
6273 }
6274 if (LocaleCompare("compress",option+1) == 0)
6275 {
6276 if (*option == '+')
6277 {
6278 image_info->compression=UndefinedCompression;
6279 (void) SetImageOption(image_info,option+1,"undefined");
6280 break;
6281 }
cristy042ee782011-04-22 18:48:30 +00006282 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006283 MagickCompressOptions,MagickFalse,argv[i+1]);
6284 (void) SetImageOption(image_info,option+1,argv[i+1]);
6285 break;
6286 }
6287 break;
6288 }
6289 case 'd':
6290 {
6291 if (LocaleCompare("debug",option+1) == 0)
6292 {
6293 if (*option == '+')
6294 (void) SetLogEventMask("none");
6295 else
6296 (void) SetLogEventMask(argv[i+1]);
6297 image_info->debug=IsEventLogging();
6298 break;
6299 }
6300 if (LocaleCompare("define",option+1) == 0)
6301 {
6302 if (*option == '+')
6303 {
6304 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6305 (void) DeleteImageRegistry(argv[i+1]+9);
6306 else
6307 (void) DeleteImageOption(image_info,argv[i+1]);
6308 break;
6309 }
6310 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6311 {
6312 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6313 exception);
6314 break;
6315 }
6316 (void) DefineImageOption(image_info,argv[i+1]);
6317 break;
6318 }
6319 if (LocaleCompare("delay",option+1) == 0)
6320 {
6321 if (*option == '+')
6322 {
6323 (void) SetImageOption(image_info,option+1,"0");
6324 break;
6325 }
6326 (void) SetImageOption(image_info,option+1,argv[i+1]);
6327 break;
6328 }
6329 if (LocaleCompare("density",option+1) == 0)
6330 {
6331 /*
6332 Set image density.
6333 */
6334 if (*option == '+')
6335 {
6336 if (image_info->density != (char *) NULL)
6337 image_info->density=DestroyString(image_info->density);
6338 (void) SetImageOption(image_info,option+1,"72");
6339 break;
6340 }
6341 (void) CloneString(&image_info->density,argv[i+1]);
6342 (void) SetImageOption(image_info,option+1,argv[i+1]);
6343 break;
6344 }
6345 if (LocaleCompare("depth",option+1) == 0)
6346 {
6347 if (*option == '+')
6348 {
6349 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6350 break;
6351 }
cristye27293e2009-12-18 02:53:20 +00006352 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006353 break;
6354 }
cristyc9b12952010-03-28 01:12:28 +00006355 if (LocaleCompare("direction",option+1) == 0)
6356 {
6357 if (*option == '+')
6358 {
6359 (void) SetImageOption(image_info,option+1,"undefined");
6360 break;
6361 }
6362 (void) SetImageOption(image_info,option+1,argv[i+1]);
6363 break;
6364 }
cristy3ed852e2009-09-05 21:47:34 +00006365 if (LocaleCompare("display",option+1) == 0)
6366 {
6367 if (*option == '+')
6368 {
6369 if (image_info->server_name != (char *) NULL)
6370 image_info->server_name=DestroyString(
6371 image_info->server_name);
6372 break;
6373 }
6374 (void) CloneString(&image_info->server_name,argv[i+1]);
6375 break;
6376 }
6377 if (LocaleCompare("dispose",option+1) == 0)
6378 {
6379 if (*option == '+')
6380 {
6381 (void) SetImageOption(image_info,option+1,"undefined");
6382 break;
6383 }
6384 (void) SetImageOption(image_info,option+1,argv[i+1]);
6385 break;
6386 }
6387 if (LocaleCompare("dither",option+1) == 0)
6388 {
6389 if (*option == '+')
6390 {
6391 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006392 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006393 break;
6394 }
6395 (void) SetImageOption(image_info,option+1,argv[i+1]);
6396 image_info->dither=MagickTrue;
6397 break;
6398 }
6399 break;
6400 }
6401 case 'e':
6402 {
6403 if (LocaleCompare("encoding",option+1) == 0)
6404 {
6405 if (*option == '+')
6406 {
6407 (void) SetImageOption(image_info,option+1,"undefined");
6408 break;
6409 }
6410 (void) SetImageOption(image_info,option+1,argv[i+1]);
6411 break;
6412 }
6413 if (LocaleCompare("endian",option+1) == 0)
6414 {
6415 if (*option == '+')
6416 {
6417 image_info->endian=UndefinedEndian;
6418 (void) SetImageOption(image_info,option+1,"undefined");
6419 break;
6420 }
cristy042ee782011-04-22 18:48:30 +00006421 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006422 MagickEndianOptions,MagickFalse,argv[i+1]);
6423 (void) SetImageOption(image_info,option+1,argv[i+1]);
6424 break;
6425 }
6426 if (LocaleCompare("extract",option+1) == 0)
6427 {
6428 /*
6429 Set image extract geometry.
6430 */
6431 if (*option == '+')
6432 {
6433 if (image_info->extract != (char *) NULL)
6434 image_info->extract=DestroyString(image_info->extract);
6435 break;
6436 }
6437 (void) CloneString(&image_info->extract,argv[i+1]);
6438 break;
6439 }
6440 break;
6441 }
6442 case 'f':
6443 {
6444 if (LocaleCompare("fill",option+1) == 0)
6445 {
6446 if (*option == '+')
6447 {
6448 (void) SetImageOption(image_info,option+1,"none");
6449 break;
6450 }
6451 (void) SetImageOption(image_info,option+1,argv[i+1]);
6452 break;
6453 }
6454 if (LocaleCompare("filter",option+1) == 0)
6455 {
6456 if (*option == '+')
6457 {
6458 (void) SetImageOption(image_info,option+1,"undefined");
6459 break;
6460 }
6461 (void) SetImageOption(image_info,option+1,argv[i+1]);
6462 break;
6463 }
6464 if (LocaleCompare("font",option+1) == 0)
6465 {
6466 if (*option == '+')
6467 {
6468 if (image_info->font != (char *) NULL)
6469 image_info->font=DestroyString(image_info->font);
6470 break;
6471 }
6472 (void) CloneString(&image_info->font,argv[i+1]);
6473 break;
6474 }
6475 if (LocaleCompare("format",option+1) == 0)
6476 {
6477 register const char
6478 *q;
6479
6480 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006481 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006482 image_info->ping=MagickFalse;
6483 (void) SetImageOption(image_info,option+1,argv[i+1]);
6484 break;
6485 }
6486 if (LocaleCompare("fuzz",option+1) == 0)
6487 {
6488 if (*option == '+')
6489 {
6490 image_info->fuzz=0.0;
6491 (void) SetImageOption(image_info,option+1,"0");
6492 break;
6493 }
cristyf2f27272009-12-17 14:48:46 +00006494 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006495 1.0);
6496 (void) SetImageOption(image_info,option+1,argv[i+1]);
6497 break;
6498 }
6499 break;
6500 }
6501 case 'g':
6502 {
6503 if (LocaleCompare("gravity",option+1) == 0)
6504 {
6505 if (*option == '+')
6506 {
6507 (void) SetImageOption(image_info,option+1,"undefined");
6508 break;
6509 }
6510 (void) SetImageOption(image_info,option+1,argv[i+1]);
6511 break;
6512 }
6513 if (LocaleCompare("green-primary",option+1) == 0)
6514 {
6515 if (*option == '+')
6516 {
6517 (void) SetImageOption(image_info,option+1,"0.0");
6518 break;
6519 }
6520 (void) SetImageOption(image_info,option+1,argv[i+1]);
6521 break;
6522 }
6523 break;
6524 }
6525 case 'i':
6526 {
6527 if (LocaleCompare("intent",option+1) == 0)
6528 {
6529 if (*option == '+')
6530 {
6531 (void) SetImageOption(image_info,option+1,"undefined");
6532 break;
6533 }
6534 (void) SetImageOption(image_info,option+1,argv[i+1]);
6535 break;
6536 }
6537 if (LocaleCompare("interlace",option+1) == 0)
6538 {
6539 if (*option == '+')
6540 {
6541 image_info->interlace=UndefinedInterlace;
6542 (void) SetImageOption(image_info,option+1,"undefined");
6543 break;
6544 }
cristy042ee782011-04-22 18:48:30 +00006545 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006546 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6547 (void) SetImageOption(image_info,option+1,argv[i+1]);
6548 break;
6549 }
cristyb32b90a2009-09-07 21:45:48 +00006550 if (LocaleCompare("interline-spacing",option+1) == 0)
6551 {
6552 if (*option == '+')
6553 {
6554 (void) SetImageOption(image_info,option+1,"undefined");
6555 break;
6556 }
6557 (void) SetImageOption(image_info,option+1,argv[i+1]);
6558 break;
6559 }
cristy3ed852e2009-09-05 21:47:34 +00006560 if (LocaleCompare("interpolate",option+1) == 0)
6561 {
6562 if (*option == '+')
6563 {
6564 (void) SetImageOption(image_info,option+1,"undefined");
6565 break;
6566 }
6567 (void) SetImageOption(image_info,option+1,argv[i+1]);
6568 break;
6569 }
6570 if (LocaleCompare("interword-spacing",option+1) == 0)
6571 {
6572 if (*option == '+')
6573 {
6574 (void) SetImageOption(image_info,option+1,"undefined");
6575 break;
6576 }
6577 (void) SetImageOption(image_info,option+1,argv[i+1]);
6578 break;
6579 }
6580 break;
6581 }
6582 case 'k':
6583 {
6584 if (LocaleCompare("kerning",option+1) == 0)
6585 {
6586 if (*option == '+')
6587 {
6588 (void) SetImageOption(image_info,option+1,"undefined");
6589 break;
6590 }
6591 (void) SetImageOption(image_info,option+1,argv[i+1]);
6592 break;
6593 }
6594 break;
6595 }
6596 case 'l':
6597 {
6598 if (LocaleCompare("label",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 (void) DeleteImageOption(image_info,option+1);
6603 break;
6604 }
6605 (void) SetImageOption(image_info,option+1,argv[i+1]);
6606 break;
6607 }
6608 if (LocaleCompare("limit",option+1) == 0)
6609 {
6610 MagickSizeType
6611 limit;
6612
6613 ResourceType
6614 type;
6615
6616 if (*option == '+')
6617 break;
cristy042ee782011-04-22 18:48:30 +00006618 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006619 MagickFalse,argv[i+1]);
6620 limit=MagickResourceInfinity;
6621 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006622 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006623 (void) SetMagickResourceLimit(type,limit);
6624 break;
6625 }
6626 if (LocaleCompare("list",option+1) == 0)
6627 {
cristybb503372010-05-27 20:51:26 +00006628 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006629 list;
6630
6631 /*
6632 Display configuration list.
6633 */
cristy042ee782011-04-22 18:48:30 +00006634 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006635 switch (list)
6636 {
6637 case MagickCoderOptions:
6638 {
6639 (void) ListCoderInfo((FILE *) NULL,exception);
6640 break;
6641 }
6642 case MagickColorOptions:
6643 {
6644 (void) ListColorInfo((FILE *) NULL,exception);
6645 break;
6646 }
6647 case MagickConfigureOptions:
6648 {
6649 (void) ListConfigureInfo((FILE *) NULL,exception);
6650 break;
6651 }
6652 case MagickDelegateOptions:
6653 {
6654 (void) ListDelegateInfo((FILE *) NULL,exception);
6655 break;
6656 }
6657 case MagickFontOptions:
6658 {
6659 (void) ListTypeInfo((FILE *) NULL,exception);
6660 break;
6661 }
6662 case MagickFormatOptions:
6663 {
6664 (void) ListMagickInfo((FILE *) NULL,exception);
6665 break;
6666 }
6667 case MagickLocaleOptions:
6668 {
6669 (void) ListLocaleInfo((FILE *) NULL,exception);
6670 break;
6671 }
6672 case MagickLogOptions:
6673 {
6674 (void) ListLogInfo((FILE *) NULL,exception);
6675 break;
6676 }
6677 case MagickMagicOptions:
6678 {
6679 (void) ListMagicInfo((FILE *) NULL,exception);
6680 break;
6681 }
6682 case MagickMimeOptions:
6683 {
6684 (void) ListMimeInfo((FILE *) NULL,exception);
6685 break;
6686 }
6687 case MagickModuleOptions:
6688 {
6689 (void) ListModuleInfo((FILE *) NULL,exception);
6690 break;
6691 }
6692 case MagickPolicyOptions:
6693 {
6694 (void) ListPolicyInfo((FILE *) NULL,exception);
6695 break;
6696 }
6697 case MagickResourceOptions:
6698 {
6699 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6700 break;
6701 }
6702 case MagickThresholdOptions:
6703 {
6704 (void) ListThresholdMaps((FILE *) NULL,exception);
6705 break;
6706 }
6707 default:
6708 {
cristy042ee782011-04-22 18:48:30 +00006709 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006710 exception);
6711 break;
6712 }
6713 }
cristyaeb2cbc2010-05-07 13:28:58 +00006714 break;
cristy3ed852e2009-09-05 21:47:34 +00006715 }
6716 if (LocaleCompare("log",option+1) == 0)
6717 {
6718 if (*option == '+')
6719 break;
6720 (void) SetLogFormat(argv[i+1]);
6721 break;
6722 }
6723 if (LocaleCompare("loop",option+1) == 0)
6724 {
6725 if (*option == '+')
6726 {
6727 (void) SetImageOption(image_info,option+1,"0");
6728 break;
6729 }
6730 (void) SetImageOption(image_info,option+1,argv[i+1]);
6731 break;
6732 }
6733 break;
6734 }
6735 case 'm':
6736 {
6737 if (LocaleCompare("matte",option+1) == 0)
6738 {
6739 if (*option == '+')
6740 {
6741 (void) SetImageOption(image_info,option+1,"false");
6742 break;
6743 }
6744 (void) SetImageOption(image_info,option+1,"true");
6745 break;
6746 }
6747 if (LocaleCompare("mattecolor",option+1) == 0)
6748 {
6749 if (*option == '+')
6750 {
6751 (void) SetImageOption(image_info,option+1,argv[i+1]);
6752 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6753 exception);
6754 break;
6755 }
6756 (void) SetImageOption(image_info,option+1,argv[i+1]);
6757 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6758 exception);
6759 break;
6760 }
6761 if (LocaleCompare("monitor",option+1) == 0)
6762 {
6763 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6764 (void *) NULL);
6765 break;
6766 }
6767 if (LocaleCompare("monochrome",option+1) == 0)
6768 {
6769 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6770 break;
6771 }
6772 break;
6773 }
6774 case 'o':
6775 {
6776 if (LocaleCompare("orient",option+1) == 0)
6777 {
6778 if (*option == '+')
6779 {
6780 image_info->orientation=UndefinedOrientation;
6781 (void) SetImageOption(image_info,option+1,"undefined");
6782 break;
6783 }
cristy042ee782011-04-22 18:48:30 +00006784 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006785 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006786 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006787 break;
6788 }
6789 }
6790 case 'p':
6791 {
6792 if (LocaleCompare("page",option+1) == 0)
6793 {
6794 char
6795 *canonical_page,
6796 page[MaxTextExtent];
6797
6798 const char
6799 *image_option;
6800
6801 MagickStatusType
6802 flags;
6803
6804 RectangleInfo
6805 geometry;
6806
6807 if (*option == '+')
6808 {
6809 (void) DeleteImageOption(image_info,option+1);
6810 (void) CloneString(&image_info->page,(char *) NULL);
6811 break;
6812 }
6813 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6814 image_option=GetImageOption(image_info,"page");
6815 if (image_option != (const char *) NULL)
6816 flags=ParseAbsoluteGeometry(image_option,&geometry);
6817 canonical_page=GetPageGeometry(argv[i+1]);
6818 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6819 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006820 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006821 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006822 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006823 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006824 (unsigned long) geometry.width,(unsigned long) geometry.height,
6825 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006826 (void) SetImageOption(image_info,option+1,page);
6827 (void) CloneString(&image_info->page,page);
6828 break;
6829 }
6830 if (LocaleCompare("pen",option+1) == 0)
6831 {
6832 if (*option == '+')
6833 {
6834 (void) SetImageOption(image_info,option+1,"none");
6835 break;
6836 }
6837 (void) SetImageOption(image_info,option+1,argv[i+1]);
6838 break;
6839 }
6840 if (LocaleCompare("ping",option+1) == 0)
6841 {
6842 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6843 break;
6844 }
6845 if (LocaleCompare("pointsize",option+1) == 0)
6846 {
6847 if (*option == '+')
6848 geometry_info.rho=0.0;
6849 else
6850 (void) ParseGeometry(argv[i+1],&geometry_info);
6851 image_info->pointsize=geometry_info.rho;
6852 break;
6853 }
cristye7f51092010-01-17 00:39:37 +00006854 if (LocaleCompare("precision",option+1) == 0)
6855 {
cristybf2766a2010-01-17 03:33:23 +00006856 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006857 break;
6858 }
cristy3ed852e2009-09-05 21:47:34 +00006859 if (LocaleCompare("preview",option+1) == 0)
6860 {
6861 /*
6862 Preview image.
6863 */
6864 if (*option == '+')
6865 {
6866 image_info->preview_type=UndefinedPreview;
6867 break;
6868 }
cristy042ee782011-04-22 18:48:30 +00006869 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006870 MagickPreviewOptions,MagickFalse,argv[i+1]);
6871 break;
6872 }
6873 break;
6874 }
6875 case 'q':
6876 {
6877 if (LocaleCompare("quality",option+1) == 0)
6878 {
6879 /*
6880 Set image compression quality.
6881 */
6882 if (*option == '+')
6883 {
6884 image_info->quality=UndefinedCompressionQuality;
6885 (void) SetImageOption(image_info,option+1,"0");
6886 break;
6887 }
cristye27293e2009-12-18 02:53:20 +00006888 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006889 (void) SetImageOption(image_info,option+1,argv[i+1]);
6890 break;
6891 }
6892 if (LocaleCompare("quiet",option+1) == 0)
6893 {
6894 static WarningHandler
6895 warning_handler = (WarningHandler) NULL;
6896
6897 if (*option == '+')
6898 {
6899 /*
6900 Restore error or warning messages.
6901 */
6902 warning_handler=SetWarningHandler(warning_handler);
6903 break;
6904 }
6905 /*
6906 Suppress error or warning messages.
6907 */
6908 warning_handler=SetWarningHandler((WarningHandler) NULL);
6909 break;
6910 }
6911 break;
6912 }
6913 case 'r':
6914 {
6915 if (LocaleCompare("red-primary",option+1) == 0)
6916 {
6917 if (*option == '+')
6918 {
6919 (void) SetImageOption(image_info,option+1,"0.0");
6920 break;
6921 }
6922 (void) SetImageOption(image_info,option+1,argv[i+1]);
6923 break;
6924 }
6925 break;
6926 }
6927 case 's':
6928 {
6929 if (LocaleCompare("sampling-factor",option+1) == 0)
6930 {
6931 /*
6932 Set image sampling factor.
6933 */
6934 if (*option == '+')
6935 {
6936 if (image_info->sampling_factor != (char *) NULL)
6937 image_info->sampling_factor=DestroyString(
6938 image_info->sampling_factor);
6939 break;
6940 }
6941 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6942 break;
6943 }
6944 if (LocaleCompare("scene",option+1) == 0)
6945 {
6946 /*
6947 Set image scene.
6948 */
6949 if (*option == '+')
6950 {
6951 image_info->scene=0;
6952 (void) SetImageOption(image_info,option+1,"0");
6953 break;
6954 }
cristye27293e2009-12-18 02:53:20 +00006955 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006956 (void) SetImageOption(image_info,option+1,argv[i+1]);
6957 break;
6958 }
6959 if (LocaleCompare("seed",option+1) == 0)
6960 {
cristybb503372010-05-27 20:51:26 +00006961 size_t
cristy3ed852e2009-09-05 21:47:34 +00006962 seed;
6963
6964 if (*option == '+')
6965 {
cristybb503372010-05-27 20:51:26 +00006966 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006967 SeedPseudoRandomGenerator(seed);
6968 break;
6969 }
cristye27293e2009-12-18 02:53:20 +00006970 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006971 SeedPseudoRandomGenerator(seed);
6972 break;
6973 }
6974 if (LocaleCompare("size",option+1) == 0)
6975 {
6976 if (*option == '+')
6977 {
6978 if (image_info->size != (char *) NULL)
6979 image_info->size=DestroyString(image_info->size);
6980 break;
6981 }
6982 (void) CloneString(&image_info->size,argv[i+1]);
6983 break;
6984 }
6985 if (LocaleCompare("stroke",option+1) == 0)
6986 {
6987 if (*option == '+')
6988 {
6989 (void) SetImageOption(image_info,option+1,"none");
6990 break;
6991 }
6992 (void) SetImageOption(image_info,option+1,argv[i+1]);
6993 break;
6994 }
6995 if (LocaleCompare("strokewidth",option+1) == 0)
6996 {
6997 if (*option == '+')
6998 {
6999 (void) SetImageOption(image_info,option+1,"0");
7000 break;
7001 }
7002 (void) SetImageOption(image_info,option+1,argv[i+1]);
7003 break;
7004 }
cristyd9a29192010-10-16 16:49:53 +00007005 if (LocaleCompare("synchronize",option+1) == 0)
7006 {
7007 if (*option == '+')
7008 {
7009 image_info->synchronize=MagickFalse;
7010 break;
7011 }
7012 image_info->synchronize=MagickTrue;
7013 break;
7014 }
cristy3ed852e2009-09-05 21:47:34 +00007015 break;
7016 }
7017 case 't':
7018 {
7019 if (LocaleCompare("taint",option+1) == 0)
7020 {
7021 if (*option == '+')
7022 {
7023 (void) SetImageOption(image_info,option+1,"false");
7024 break;
7025 }
7026 (void) SetImageOption(image_info,option+1,"true");
7027 break;
7028 }
7029 if (LocaleCompare("texture",option+1) == 0)
7030 {
7031 if (*option == '+')
7032 {
7033 if (image_info->texture != (char *) NULL)
7034 image_info->texture=DestroyString(image_info->texture);
7035 break;
7036 }
7037 (void) CloneString(&image_info->texture,argv[i+1]);
7038 break;
7039 }
7040 if (LocaleCompare("tile-offset",option+1) == 0)
7041 {
7042 if (*option == '+')
7043 {
7044 (void) SetImageOption(image_info,option+1,"0");
7045 break;
7046 }
7047 (void) SetImageOption(image_info,option+1,argv[i+1]);
7048 break;
7049 }
7050 if (LocaleCompare("transparent-color",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 {
7054 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7055 (void) SetImageOption(image_info,option+1,"none");
7056 break;
7057 }
7058 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7059 exception);
7060 (void) SetImageOption(image_info,option+1,argv[i+1]);
7061 break;
7062 }
7063 if (LocaleCompare("type",option+1) == 0)
7064 {
7065 if (*option == '+')
7066 {
cristy5f1c1ff2010-12-23 21:38:06 +00007067 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007068 (void) SetImageOption(image_info,option+1,"undefined");
7069 break;
7070 }
cristy042ee782011-04-22 18:48:30 +00007071 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007072 MagickFalse,argv[i+1]);
7073 (void) SetImageOption(image_info,option+1,argv[i+1]);
7074 break;
7075 }
7076 break;
7077 }
7078 case 'u':
7079 {
7080 if (LocaleCompare("undercolor",option+1) == 0)
7081 {
7082 if (*option == '+')
7083 {
7084 (void) DeleteImageOption(image_info,option+1);
7085 break;
7086 }
7087 (void) SetImageOption(image_info,option+1,argv[i+1]);
7088 break;
7089 }
7090 if (LocaleCompare("units",option+1) == 0)
7091 {
7092 if (*option == '+')
7093 {
7094 image_info->units=UndefinedResolution;
7095 (void) SetImageOption(image_info,option+1,"undefined");
7096 break;
7097 }
cristy042ee782011-04-22 18:48:30 +00007098 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007099 MagickResolutionOptions,MagickFalse,argv[i+1]);
7100 (void) SetImageOption(image_info,option+1,argv[i+1]);
7101 break;
7102 }
7103 break;
7104 }
7105 case 'v':
7106 {
7107 if (LocaleCompare("verbose",option+1) == 0)
7108 {
7109 if (*option == '+')
7110 {
7111 image_info->verbose=MagickFalse;
7112 break;
7113 }
7114 image_info->verbose=MagickTrue;
7115 image_info->ping=MagickFalse;
7116 break;
7117 }
7118 if (LocaleCompare("view",option+1) == 0)
7119 {
7120 if (*option == '+')
7121 {
7122 if (image_info->view != (char *) NULL)
7123 image_info->view=DestroyString(image_info->view);
7124 break;
7125 }
7126 (void) CloneString(&image_info->view,argv[i+1]);
7127 break;
7128 }
7129 if (LocaleCompare("virtual-pixel",option+1) == 0)
7130 {
7131 if (*option == '+')
7132 {
7133 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7134 (void) SetImageOption(image_info,option+1,"undefined");
7135 break;
7136 }
7137 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007138 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007139 argv[i+1]);
7140 (void) SetImageOption(image_info,option+1,argv[i+1]);
7141 break;
7142 }
7143 break;
7144 }
7145 case 'w':
7146 {
7147 if (LocaleCompare("white-point",option+1) == 0)
7148 {
7149 if (*option == '+')
7150 {
7151 (void) SetImageOption(image_info,option+1,"0.0");
7152 break;
7153 }
7154 (void) SetImageOption(image_info,option+1,argv[i+1]);
7155 break;
7156 }
7157 break;
7158 }
7159 default:
7160 break;
7161 }
7162 i+=count;
7163 }
7164 return(MagickTrue);
7165}
7166
7167/*
7168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7169% %
7170% %
7171% %
7172+ M o g r i f y I m a g e L i s t %
7173% %
7174% %
7175% %
7176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7177%
7178% MogrifyImageList() applies any command line options that might affect the
7179% entire image list (e.g. -append, -coalesce, etc.).
7180%
7181% The format of the MogrifyImage method is:
7182%
7183% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7184% const char **argv,Image **images,ExceptionInfo *exception)
7185%
7186% A description of each parameter follows:
7187%
7188% o image_info: the image info..
7189%
7190% o argc: Specifies a pointer to an integer describing the number of
7191% elements in the argument vector.
7192%
7193% o argv: Specifies a pointer to a text array containing the command line
7194% arguments.
7195%
anthonye9c27192011-03-27 08:07:06 +00007196% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007197%
7198% o exception: return any errors or warnings in this structure.
7199%
7200*/
7201WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7202 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7203{
cristy3ed852e2009-09-05 21:47:34 +00007204 const char
7205 *option;
7206
cristy6b3da3a2010-06-20 02:21:46 +00007207 ImageInfo
7208 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007209
7210 MagickStatusType
7211 status;
7212
7213 QuantizeInfo
7214 *quantize_info;
7215
cristybb503372010-05-27 20:51:26 +00007216 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007217 i;
7218
cristy6b3da3a2010-06-20 02:21:46 +00007219 ssize_t
7220 count,
7221 index;
7222
cristy3ed852e2009-09-05 21:47:34 +00007223 /*
7224 Apply options to the image list.
7225 */
7226 assert(image_info != (ImageInfo *) NULL);
7227 assert(image_info->signature == MagickSignature);
7228 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007229 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007230 assert((*images)->signature == MagickSignature);
7231 if ((*images)->debug != MagickFalse)
7232 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7233 (*images)->filename);
7234 if ((argc <= 0) || (*argv == (char *) NULL))
7235 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007236 mogrify_info=CloneImageInfo(image_info);
7237 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007238 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007239 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007240 {
cristy74fe8f12009-10-03 19:09:01 +00007241 if (*images == (Image *) NULL)
7242 break;
cristy3ed852e2009-09-05 21:47:34 +00007243 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007244 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007245 continue;
cristy042ee782011-04-22 18:48:30 +00007246 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007247 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007248 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007249 break;
cristy6b3da3a2010-06-20 02:21:46 +00007250 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007251 switch (*(option+1))
7252 {
7253 case 'a':
7254 {
7255 if (LocaleCompare("affinity",option+1) == 0)
7256 {
cristy6b3da3a2010-06-20 02:21:46 +00007257 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007258 if (*option == '+')
7259 {
7260 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7261 InheritException(exception,&(*images)->exception);
7262 break;
7263 }
7264 i++;
7265 break;
7266 }
7267 if (LocaleCompare("append",option+1) == 0)
7268 {
7269 Image
7270 *append_image;
7271
cristy6b3da3a2010-06-20 02:21:46 +00007272 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007273 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7274 MagickFalse,exception);
7275 if (append_image == (Image *) NULL)
7276 {
7277 status=MagickFalse;
7278 break;
7279 }
7280 *images=DestroyImageList(*images);
7281 *images=append_image;
7282 break;
7283 }
7284 if (LocaleCompare("average",option+1) == 0)
7285 {
7286 Image
7287 *average_image;
7288
cristyd18ae7c2010-03-07 17:39:52 +00007289 /*
7290 Average an image sequence (deprecated).
7291 */
cristy6b3da3a2010-06-20 02:21:46 +00007292 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007293 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7294 exception);
cristy3ed852e2009-09-05 21:47:34 +00007295 if (average_image == (Image *) NULL)
7296 {
7297 status=MagickFalse;
7298 break;
7299 }
7300 *images=DestroyImageList(*images);
7301 *images=average_image;
7302 break;
7303 }
7304 break;
7305 }
7306 case 'c':
7307 {
7308 if (LocaleCompare("channel",option+1) == 0)
7309 {
cristyf4ad9df2011-07-08 16:49:03 +00007310 ChannelType
7311 channel;
7312
cristy3ed852e2009-09-05 21:47:34 +00007313 if (*option == '+')
7314 {
7315 channel=DefaultChannels;
7316 break;
7317 }
7318 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007319 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007320 break;
7321 }
7322 if (LocaleCompare("clut",option+1) == 0)
7323 {
7324 Image
7325 *clut_image,
7326 *image;
7327
cristy6b3da3a2010-06-20 02:21:46 +00007328 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007329 image=RemoveFirstImageFromList(images);
7330 clut_image=RemoveFirstImageFromList(images);
7331 if (clut_image == (Image *) NULL)
7332 {
7333 status=MagickFalse;
7334 break;
7335 }
cristyf89cb1d2011-07-07 01:24:37 +00007336 (void) ClutImage(image,clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007337 clut_image=DestroyImage(clut_image);
7338 InheritException(exception,&image->exception);
7339 *images=DestroyImageList(*images);
7340 *images=image;
7341 break;
7342 }
7343 if (LocaleCompare("coalesce",option+1) == 0)
7344 {
7345 Image
7346 *coalesce_image;
7347
cristy6b3da3a2010-06-20 02:21:46 +00007348 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007349 coalesce_image=CoalesceImages(*images,exception);
7350 if (coalesce_image == (Image *) NULL)
7351 {
7352 status=MagickFalse;
7353 break;
7354 }
7355 *images=DestroyImageList(*images);
7356 *images=coalesce_image;
7357 break;
7358 }
7359 if (LocaleCompare("combine",option+1) == 0)
7360 {
7361 Image
7362 *combine_image;
7363
cristy6b3da3a2010-06-20 02:21:46 +00007364 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007365 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007366 if (combine_image == (Image *) NULL)
7367 {
7368 status=MagickFalse;
7369 break;
7370 }
7371 *images=DestroyImageList(*images);
7372 *images=combine_image;
7373 break;
7374 }
7375 if (LocaleCompare("composite",option+1) == 0)
7376 {
7377 Image
7378 *mask_image,
7379 *composite_image,
7380 *image;
7381
7382 RectangleInfo
7383 geometry;
7384
cristy6b3da3a2010-06-20 02:21:46 +00007385 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007386 image=RemoveFirstImageFromList(images);
7387 composite_image=RemoveFirstImageFromList(images);
7388 if (composite_image == (Image *) NULL)
7389 {
7390 status=MagickFalse;
7391 break;
7392 }
7393 (void) TransformImage(&composite_image,(char *) NULL,
7394 composite_image->geometry);
7395 SetGeometry(composite_image,&geometry);
7396 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7397 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7398 &geometry);
7399 mask_image=RemoveFirstImageFromList(images);
7400 if (mask_image != (Image *) NULL)
7401 {
7402 if ((image->compose == DisplaceCompositeOp) ||
7403 (image->compose == DistortCompositeOp))
7404 {
7405 /*
7406 Merge Y displacement into X displacement image.
7407 */
7408 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7409 mask_image,0,0);
7410 mask_image=DestroyImage(mask_image);
7411 }
7412 else
7413 {
7414 /*
7415 Set a blending mask for the composition.
7416 */
anthonya129f702011-04-14 01:08:48 +00007417 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007418 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007419 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007420 }
7421 }
cristyf4ad9df2011-07-08 16:49:03 +00007422 (void) CompositeImage(image,image->compose,composite_image,
7423 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007424 if (mask_image != (Image *) NULL)
7425 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007426 composite_image=DestroyImage(composite_image);
7427 InheritException(exception,&image->exception);
7428 *images=DestroyImageList(*images);
7429 *images=image;
7430 break;
7431 }
anthony9f4f0342011-03-28 11:47:22 +00007432#if 0
7433This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007434 if (LocaleCompare("crop",option+1) == 0)
7435 {
7436 MagickStatusType
7437 flags;
7438
7439 RectangleInfo
7440 geometry;
7441
anthonye9c27192011-03-27 08:07:06 +00007442 /*
anthony9f4f0342011-03-28 11:47:22 +00007443 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007444 */
cristy6b3da3a2010-06-20 02:21:46 +00007445 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007446 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7447 if (((geometry.width == 0) && (geometry.height == 0)) ||
7448 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7449 break;
7450 (void) TransformImages(images,argv[i+1],(char *) NULL);
7451 InheritException(exception,&(*images)->exception);
7452 break;
7453 }
anthony9f4f0342011-03-28 11:47:22 +00007454#endif
cristy3ed852e2009-09-05 21:47:34 +00007455 break;
7456 }
7457 case 'd':
7458 {
7459 if (LocaleCompare("deconstruct",option+1) == 0)
7460 {
7461 Image
7462 *deconstruct_image;
7463
cristy6b3da3a2010-06-20 02:21:46 +00007464 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007465 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007466 exception);
cristy3ed852e2009-09-05 21:47:34 +00007467 if (deconstruct_image == (Image *) NULL)
7468 {
7469 status=MagickFalse;
7470 break;
7471 }
7472 *images=DestroyImageList(*images);
7473 *images=deconstruct_image;
7474 break;
7475 }
7476 if (LocaleCompare("delete",option+1) == 0)
7477 {
7478 if (*option == '+')
7479 DeleteImages(images,"-1",exception);
7480 else
7481 DeleteImages(images,argv[i+1],exception);
7482 break;
7483 }
7484 if (LocaleCompare("dither",option+1) == 0)
7485 {
7486 if (*option == '+')
7487 {
7488 quantize_info->dither=MagickFalse;
7489 break;
7490 }
7491 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007492 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007493 MagickDitherOptions,MagickFalse,argv[i+1]);
7494 break;
7495 }
cristyecb10ff2011-03-22 13:14:03 +00007496 if (LocaleCompare("duplicate",option+1) == 0)
7497 {
cristy72988482011-03-29 16:34:38 +00007498 Image
7499 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007500
anthony2b6bcae2011-03-23 13:05:34 +00007501 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007502 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7503 else
7504 {
7505 const char
7506 *p;
7507
anthony2b6bcae2011-03-23 13:05:34 +00007508 size_t
7509 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007510
anthony2b6bcae2011-03-23 13:05:34 +00007511 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007512 p=strchr(argv[i+1],',');
7513 if (p == (const char *) NULL)
7514 duplicate_images=DuplicateImages(*images,number_duplicates,
7515 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007516 else
cristy72988482011-03-29 16:34:38 +00007517 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7518 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007519 }
7520 AppendImageToList(images, duplicate_images);
7521 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007522 break;
7523 }
cristy3ed852e2009-09-05 21:47:34 +00007524 break;
7525 }
cristyd18ae7c2010-03-07 17:39:52 +00007526 case 'e':
7527 {
7528 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7529 {
7530 Image
7531 *evaluate_image;
7532
7533 MagickEvaluateOperator
7534 op;
7535
cristy6b3da3a2010-06-20 02:21:46 +00007536 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007537 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007538 MagickFalse,argv[i+1]);
7539 evaluate_image=EvaluateImages(*images,op,exception);
7540 if (evaluate_image == (Image *) NULL)
7541 {
7542 status=MagickFalse;
7543 break;
7544 }
7545 *images=DestroyImageList(*images);
7546 *images=evaluate_image;
7547 break;
7548 }
7549 break;
7550 }
cristy3ed852e2009-09-05 21:47:34 +00007551 case 'f':
7552 {
cristyf0a247f2009-10-04 00:20:03 +00007553 if (LocaleCompare("fft",option+1) == 0)
7554 {
7555 Image
7556 *fourier_image;
7557
7558 /*
7559 Implements the discrete Fourier transform (DFT).
7560 */
cristy6b3da3a2010-06-20 02:21:46 +00007561 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007562 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7563 MagickTrue : MagickFalse,exception);
7564 if (fourier_image == (Image *) NULL)
7565 break;
7566 *images=DestroyImage(*images);
7567 *images=fourier_image;
7568 break;
7569 }
cristy3ed852e2009-09-05 21:47:34 +00007570 if (LocaleCompare("flatten",option+1) == 0)
7571 {
7572 Image
7573 *flatten_image;
7574
cristy6b3da3a2010-06-20 02:21:46 +00007575 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007576 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7577 if (flatten_image == (Image *) NULL)
7578 break;
7579 *images=DestroyImageList(*images);
7580 *images=flatten_image;
7581 break;
7582 }
7583 if (LocaleCompare("fx",option+1) == 0)
7584 {
7585 Image
7586 *fx_image;
7587
cristy6b3da3a2010-06-20 02:21:46 +00007588 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007589 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007590 if (fx_image == (Image *) NULL)
7591 {
7592 status=MagickFalse;
7593 break;
7594 }
7595 *images=DestroyImageList(*images);
7596 *images=fx_image;
7597 break;
7598 }
7599 break;
7600 }
7601 case 'h':
7602 {
7603 if (LocaleCompare("hald-clut",option+1) == 0)
7604 {
7605 Image
7606 *hald_image,
7607 *image;
7608
cristy6b3da3a2010-06-20 02:21:46 +00007609 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007610 image=RemoveFirstImageFromList(images);
7611 hald_image=RemoveFirstImageFromList(images);
7612 if (hald_image == (Image *) NULL)
7613 {
7614 status=MagickFalse;
7615 break;
7616 }
cristyf89cb1d2011-07-07 01:24:37 +00007617 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007618 hald_image=DestroyImage(hald_image);
7619 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007620 if (*images != (Image *) NULL)
7621 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007622 *images=image;
7623 break;
7624 }
7625 break;
7626 }
7627 case 'i':
7628 {
7629 if (LocaleCompare("ift",option+1) == 0)
7630 {
7631 Image
cristy8587f882009-11-13 20:28:49 +00007632 *fourier_image,
7633 *magnitude_image,
7634 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007635
7636 /*
7637 Implements the inverse fourier discrete Fourier transform (DFT).
7638 */
cristy6b3da3a2010-06-20 02:21:46 +00007639 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007640 magnitude_image=RemoveFirstImageFromList(images);
7641 phase_image=RemoveFirstImageFromList(images);
7642 if (phase_image == (Image *) NULL)
7643 {
7644 status=MagickFalse;
7645 break;
7646 }
7647 fourier_image=InverseFourierTransformImage(magnitude_image,
7648 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007649 if (fourier_image == (Image *) NULL)
7650 break;
cristy0aff6ea2009-11-14 01:40:53 +00007651 if (*images != (Image *) NULL)
7652 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007653 *images=fourier_image;
7654 break;
7655 }
7656 if (LocaleCompare("insert",option+1) == 0)
7657 {
7658 Image
7659 *p,
7660 *q;
7661
7662 index=0;
7663 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007664 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007665 p=RemoveLastImageFromList(images);
7666 if (p == (Image *) NULL)
7667 {
7668 (void) ThrowMagickException(exception,GetMagickModule(),
7669 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7670 status=MagickFalse;
7671 break;
7672 }
7673 q=p;
7674 if (index == 0)
7675 PrependImageToList(images,q);
7676 else
cristybb503372010-05-27 20:51:26 +00007677 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007678 AppendImageToList(images,q);
7679 else
7680 {
7681 q=GetImageFromList(*images,index-1);
7682 if (q == (Image *) NULL)
7683 {
7684 (void) ThrowMagickException(exception,GetMagickModule(),
7685 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7686 status=MagickFalse;
7687 break;
7688 }
7689 InsertImageInList(&q,p);
7690 }
7691 *images=GetFirstImageInList(q);
7692 break;
7693 }
7694 break;
7695 }
7696 case 'l':
7697 {
7698 if (LocaleCompare("layers",option+1) == 0)
7699 {
7700 Image
7701 *layers;
7702
7703 ImageLayerMethod
7704 method;
7705
cristy6b3da3a2010-06-20 02:21:46 +00007706 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007707 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007708 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007709 MagickFalse,argv[i+1]);
7710 switch (method)
7711 {
7712 case CoalesceLayer:
7713 {
7714 layers=CoalesceImages(*images,exception);
7715 break;
7716 }
7717 case CompareAnyLayer:
7718 case CompareClearLayer:
7719 case CompareOverlayLayer:
7720 default:
7721 {
cristy8a9106f2011-07-05 14:39:26 +00007722 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007723 break;
7724 }
7725 case MergeLayer:
7726 case FlattenLayer:
7727 case MosaicLayer:
7728 case TrimBoundsLayer:
7729 {
7730 layers=MergeImageLayers(*images,method,exception);
7731 break;
7732 }
7733 case DisposeLayer:
7734 {
7735 layers=DisposeImages(*images,exception);
7736 break;
7737 }
7738 case OptimizeImageLayer:
7739 {
7740 layers=OptimizeImageLayers(*images,exception);
7741 break;
7742 }
7743 case OptimizePlusLayer:
7744 {
7745 layers=OptimizePlusImageLayers(*images,exception);
7746 break;
7747 }
7748 case OptimizeTransLayer:
7749 {
7750 OptimizeImageTransparency(*images,exception);
7751 break;
7752 }
7753 case RemoveDupsLayer:
7754 {
7755 RemoveDuplicateLayers(images,exception);
7756 break;
7757 }
7758 case RemoveZeroLayer:
7759 {
7760 RemoveZeroDelayLayers(images,exception);
7761 break;
7762 }
7763 case OptimizeLayer:
7764 {
7765 /*
7766 General Purpose, GIF Animation Optimizer.
7767 */
7768 layers=CoalesceImages(*images,exception);
7769 if (layers == (Image *) NULL)
7770 {
7771 status=MagickFalse;
7772 break;
7773 }
7774 InheritException(exception,&layers->exception);
7775 *images=DestroyImageList(*images);
7776 *images=layers;
7777 layers=OptimizeImageLayers(*images,exception);
7778 if (layers == (Image *) NULL)
7779 {
7780 status=MagickFalse;
7781 break;
7782 }
7783 InheritException(exception,&layers->exception);
7784 *images=DestroyImageList(*images);
7785 *images=layers;
7786 layers=(Image *) NULL;
7787 OptimizeImageTransparency(*images,exception);
7788 InheritException(exception,&(*images)->exception);
7789 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7790 break;
7791 }
7792 case CompositeLayer:
7793 {
7794 CompositeOperator
7795 compose;
7796
7797 Image
7798 *source;
7799
7800 RectangleInfo
7801 geometry;
7802
7803 /*
7804 Split image sequence at the first 'NULL:' image.
7805 */
7806 source=(*images);
7807 while (source != (Image *) NULL)
7808 {
7809 source=GetNextImageInList(source);
7810 if ((source != (Image *) NULL) &&
7811 (LocaleCompare(source->magick,"NULL") == 0))
7812 break;
7813 }
7814 if (source != (Image *) NULL)
7815 {
7816 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7817 (GetNextImageInList(source) == (Image *) NULL))
7818 source=(Image *) NULL;
7819 else
7820 {
7821 /*
7822 Separate the two lists, junk the null: image.
7823 */
7824 source=SplitImageList(source->previous);
7825 DeleteImageFromList(&source);
7826 }
7827 }
7828 if (source == (Image *) NULL)
7829 {
7830 (void) ThrowMagickException(exception,GetMagickModule(),
7831 OptionError,"MissingNullSeparator","layers Composite");
7832 status=MagickFalse;
7833 break;
7834 }
7835 /*
7836 Adjust offset with gravity and virtual canvas.
7837 */
7838 SetGeometry(*images,&geometry);
7839 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7840 geometry.width=source->page.width != 0 ?
7841 source->page.width : source->columns;
7842 geometry.height=source->page.height != 0 ?
7843 source->page.height : source->rows;
7844 GravityAdjustGeometry((*images)->page.width != 0 ?
7845 (*images)->page.width : (*images)->columns,
7846 (*images)->page.height != 0 ? (*images)->page.height :
7847 (*images)->rows,(*images)->gravity,&geometry);
7848 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007849 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007850 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007851 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007852 MagickComposeOptions,MagickFalse,option);
7853 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7854 exception);
7855 source=DestroyImageList(source);
7856 break;
7857 }
7858 }
7859 if (layers == (Image *) NULL)
7860 break;
7861 InheritException(exception,&layers->exception);
7862 *images=DestroyImageList(*images);
7863 *images=layers;
7864 break;
7865 }
7866 break;
7867 }
7868 case 'm':
7869 {
7870 if (LocaleCompare("map",option+1) == 0)
7871 {
cristy6b3da3a2010-06-20 02:21:46 +00007872 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007873 if (*option == '+')
7874 {
7875 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7876 InheritException(exception,&(*images)->exception);
7877 break;
7878 }
7879 i++;
7880 break;
7881 }
cristyf40785b2010-03-06 02:27:27 +00007882 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007883 {
7884 Image
cristyf40785b2010-03-06 02:27:27 +00007885 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007886
cristyd18ae7c2010-03-07 17:39:52 +00007887 /*
7888 Maximum image sequence (deprecated).
7889 */
cristy6b3da3a2010-06-20 02:21:46 +00007890 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007891 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007892 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007893 {
7894 status=MagickFalse;
7895 break;
7896 }
7897 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007898 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007899 break;
7900 }
cristyf40785b2010-03-06 02:27:27 +00007901 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007902 {
7903 Image
cristyf40785b2010-03-06 02:27:27 +00007904 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007905
cristyd18ae7c2010-03-07 17:39:52 +00007906 /*
7907 Minimum image sequence (deprecated).
7908 */
cristy6b3da3a2010-06-20 02:21:46 +00007909 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007910 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007911 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007912 {
7913 status=MagickFalse;
7914 break;
7915 }
7916 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007917 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007918 break;
7919 }
cristy3ed852e2009-09-05 21:47:34 +00007920 if (LocaleCompare("morph",option+1) == 0)
7921 {
7922 Image
7923 *morph_image;
7924
cristy6b3da3a2010-06-20 02:21:46 +00007925 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007926 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007927 exception);
7928 if (morph_image == (Image *) NULL)
7929 {
7930 status=MagickFalse;
7931 break;
7932 }
7933 *images=DestroyImageList(*images);
7934 *images=morph_image;
7935 break;
7936 }
7937 if (LocaleCompare("mosaic",option+1) == 0)
7938 {
7939 Image
7940 *mosaic_image;
7941
cristy6b3da3a2010-06-20 02:21:46 +00007942 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007943 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7944 if (mosaic_image == (Image *) NULL)
7945 {
7946 status=MagickFalse;
7947 break;
7948 }
7949 *images=DestroyImageList(*images);
7950 *images=mosaic_image;
7951 break;
7952 }
7953 break;
7954 }
7955 case 'p':
7956 {
7957 if (LocaleCompare("print",option+1) == 0)
7958 {
7959 char
7960 *string;
7961
cristy6b3da3a2010-06-20 02:21:46 +00007962 (void) SyncImagesSettings(mogrify_info,*images);
7963 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007964 if (string == (char *) NULL)
7965 break;
7966 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007967 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007968 string=DestroyString(string);
7969 }
7970 if (LocaleCompare("process",option+1) == 0)
7971 {
7972 char
7973 **arguments;
7974
7975 int
7976 j,
7977 number_arguments;
7978
cristy6b3da3a2010-06-20 02:21:46 +00007979 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007980 arguments=StringToArgv(argv[i+1],&number_arguments);
7981 if (arguments == (char **) NULL)
7982 break;
7983 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7984 {
7985 char
7986 breaker,
7987 quote,
7988 *token;
7989
7990 const char
7991 *arguments;
7992
7993 int
7994 next,
7995 status;
7996
7997 size_t
7998 length;
7999
8000 TokenInfo
8001 *token_info;
8002
8003 /*
8004 Support old style syntax, filter="-option arg".
8005 */
8006 length=strlen(argv[i+1]);
8007 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008008 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008009 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8010 sizeof(*token));
8011 if (token == (char *) NULL)
8012 break;
8013 next=0;
8014 arguments=argv[i+1];
8015 token_info=AcquireTokenInfo();
8016 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8017 "\"",'\0',&breaker,&next,&quote);
8018 token_info=DestroyTokenInfo(token_info);
8019 if (status == 0)
8020 {
8021 const char
8022 *argv;
8023
8024 argv=(&(arguments[next]));
8025 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8026 exception);
8027 }
8028 token=DestroyString(token);
8029 break;
8030 }
cristy91c0da22010-05-02 01:44:07 +00008031 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008032 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8033 number_arguments-2,(const char **) arguments+2,exception);
8034 for (j=0; j < number_arguments; j++)
8035 arguments[j]=DestroyString(arguments[j]);
8036 arguments=(char **) RelinquishMagickMemory(arguments);
8037 break;
8038 }
8039 break;
8040 }
8041 case 'r':
8042 {
8043 if (LocaleCompare("reverse",option+1) == 0)
8044 {
8045 ReverseImageList(images);
8046 InheritException(exception,&(*images)->exception);
8047 break;
8048 }
8049 break;
8050 }
8051 case 's':
8052 {
cristy4285d782011-02-09 20:12:28 +00008053 if (LocaleCompare("smush",option+1) == 0)
8054 {
8055 Image
8056 *smush_image;
8057
8058 ssize_t
8059 offset;
8060
8061 (void) SyncImagesSettings(mogrify_info,*images);
8062 offset=(ssize_t) StringToLong(argv[i+1]);
8063 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8064 MagickFalse,offset,exception);
8065 if (smush_image == (Image *) NULL)
8066 {
8067 status=MagickFalse;
8068 break;
8069 }
8070 *images=DestroyImageList(*images);
8071 *images=smush_image;
8072 break;
8073 }
cristy3ed852e2009-09-05 21:47:34 +00008074 if (LocaleCompare("swap",option+1) == 0)
8075 {
8076 Image
8077 *p,
8078 *q,
8079 *swap;
8080
cristybb503372010-05-27 20:51:26 +00008081 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008082 swap_index;
8083
8084 index=(-1);
8085 swap_index=(-2);
8086 if (*option != '+')
8087 {
8088 GeometryInfo
8089 geometry_info;
8090
8091 MagickStatusType
8092 flags;
8093
8094 swap_index=(-1);
8095 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008096 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008097 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008098 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008099 }
8100 p=GetImageFromList(*images,index);
8101 q=GetImageFromList(*images,swap_index);
8102 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8103 {
8104 (void) ThrowMagickException(exception,GetMagickModule(),
8105 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8106 status=MagickFalse;
8107 break;
8108 }
8109 if (p == q)
8110 break;
8111 swap=CloneImage(p,0,0,MagickTrue,exception);
8112 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8113 ReplaceImageInList(&q,swap);
8114 *images=GetFirstImageInList(q);
8115 break;
8116 }
8117 break;
8118 }
8119 case 'w':
8120 {
8121 if (LocaleCompare("write",option+1) == 0)
8122 {
cristy071dd7b2010-04-09 13:04:54 +00008123 char
cristy06609ee2010-03-17 20:21:27 +00008124 key[MaxTextExtent];
8125
cristy3ed852e2009-09-05 21:47:34 +00008126 Image
8127 *write_images;
8128
8129 ImageInfo
8130 *write_info;
8131
cristy6b3da3a2010-06-20 02:21:46 +00008132 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008133 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008134 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008135 write_images=(*images);
8136 if (*option == '+')
8137 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008138 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008139 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8140 write_info=DestroyImageInfo(write_info);
8141 if (*option == '+')
8142 write_images=DestroyImageList(write_images);
8143 break;
8144 }
8145 break;
8146 }
8147 default:
8148 break;
8149 }
8150 i+=count;
8151 }
8152 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008153 mogrify_info=DestroyImageInfo(mogrify_info);
8154 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008155 return(status != 0 ? MagickTrue : MagickFalse);
8156}
8157
8158/*
8159%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8160% %
8161% %
8162% %
8163+ M o g r i f y I m a g e s %
8164% %
8165% %
8166% %
8167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8168%
8169% MogrifyImages() applies image processing options to a sequence of images as
8170% prescribed by command line options.
8171%
8172% The format of the MogrifyImage method is:
8173%
8174% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8175% const MagickBooleanType post,const int argc,const char **argv,
8176% Image **images,Exceptioninfo *exception)
8177%
8178% A description of each parameter follows:
8179%
8180% o image_info: the image info..
8181%
8182% o post: If true, post process image list operators otherwise pre-process.
8183%
8184% o argc: Specifies a pointer to an integer describing the number of
8185% elements in the argument vector.
8186%
8187% o argv: Specifies a pointer to a text array containing the command line
8188% arguments.
8189%
anthonye9c27192011-03-27 08:07:06 +00008190% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008191%
8192% o exception: return any errors or warnings in this structure.
8193%
8194*/
8195WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8196 const MagickBooleanType post,const int argc,const char **argv,
8197 Image **images,ExceptionInfo *exception)
8198{
8199#define MogrifyImageTag "Mogrify/Image"
8200
anthonye9c27192011-03-27 08:07:06 +00008201 MagickStatusType
8202 status;
cristy3ed852e2009-09-05 21:47:34 +00008203
cristy0e9f9c12010-02-11 03:00:47 +00008204 MagickBooleanType
8205 proceed;
8206
anthonye9c27192011-03-27 08:07:06 +00008207 size_t
8208 n;
cristy3ed852e2009-09-05 21:47:34 +00008209
cristybb503372010-05-27 20:51:26 +00008210 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008211 i;
8212
cristy3ed852e2009-09-05 21:47:34 +00008213 assert(image_info != (ImageInfo *) NULL);
8214 assert(image_info->signature == MagickSignature);
8215 if (images == (Image **) NULL)
8216 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008217 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008218 assert((*images)->signature == MagickSignature);
8219 if ((*images)->debug != MagickFalse)
8220 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8221 (*images)->filename);
8222 if ((argc <= 0) || (*argv == (char *) NULL))
8223 return(MagickTrue);
8224 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8225 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008226 status=0;
anthonye9c27192011-03-27 08:07:06 +00008227
anthonyce2716b2011-04-22 09:51:34 +00008228#if 0
cristy1e604812011-05-19 18:07:50 +00008229 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8230 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008231#endif
8232
anthonye9c27192011-03-27 08:07:06 +00008233 /*
8234 Pre-process multi-image sequence operators
8235 */
cristy3ed852e2009-09-05 21:47:34 +00008236 if (post == MagickFalse)
8237 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008238 /*
8239 For each image, process simple single image operators
8240 */
8241 i=0;
8242 n=GetImageListLength(*images);
8243 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008244 {
anthonyce2716b2011-04-22 09:51:34 +00008245#if 0
cristy1e604812011-05-19 18:07:50 +00008246 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8247 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008248#endif
anthonye9c27192011-03-27 08:07:06 +00008249 status&=MogrifyImage(image_info,argc,argv,images,exception);
8250 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008251 if (proceed == MagickFalse)
8252 break;
anthonye9c27192011-03-27 08:07:06 +00008253 if ( (*images)->next == (Image *) NULL )
8254 break;
8255 *images=(*images)->next;
8256 i++;
cristy3ed852e2009-09-05 21:47:34 +00008257 }
anthonye9c27192011-03-27 08:07:06 +00008258 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008259#if 0
cristy1e604812011-05-19 18:07:50 +00008260 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8261 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008262#endif
anthonye9c27192011-03-27 08:07:06 +00008263
8264 /*
8265 Post-process, multi-image sequence operators
8266 */
8267 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008268 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008269 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008270 return(status != 0 ? MagickTrue : MagickFalse);
8271}