blob: 104b299250012902e851bec73e809ca319a0284a [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
58 Define declarations.
59*/
60#define UndefinedCompressionQuality 0UL
61
62/*
cristy3ed852e2009-09-05 21:47:34 +000063%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64% %
65% %
66% %
cristy5063d812010-10-19 16:28:10 +000067% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000068% %
69% %
70% %
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72%
73% MagickCommandGenesis() applies image processing options to an image as
74% prescribed by command line options.
75%
76% The format of the MagickCommandGenesis method is:
77%
78% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000079% MagickCommand command,int argc,char **argv,char **metadata,
80% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000081%
82% A description of each parameter follows:
83%
84% o image_info: the image info.
85%
cristy5063d812010-10-19 16:28:10 +000086% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000087% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000088% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
89% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000090%
91% o argc: Specifies a pointer to an integer describing the number of
92% elements in the argument vector.
93%
94% o argv: Specifies a pointer to a text array containing the command line
95% arguments.
96%
cristy5063d812010-10-19 16:28:10 +000097% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o exception: return any errors or warnings in this structure.
100%
101*/
102WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
103 MagickCommand command,int argc,char **argv,char **metadata,
104 ExceptionInfo *exception)
105{
106 char
107 *option;
108
109 double
110 duration,
111 elapsed_time,
112 user_time;
113
cristy3980b0d2009-10-25 14:37:13 +0000114 MagickBooleanType
115 concurrent,
116 regard_warnings,
117 status;
118
cristybb503372010-05-27 20:51:26 +0000119 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000120 i;
121
122 TimerInfo
123 *timer;
124
cristybb503372010-05-27 20:51:26 +0000125 size_t
cristy3980b0d2009-10-25 14:37:13 +0000126 iterations;
127
cristyd0a94fa2010-03-12 14:18:11 +0000128 (void) setlocale(LC_ALL,"");
129 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000130 concurrent=MagickFalse;
131 duration=(-1.0);
132 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000133 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000134 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000135 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000136 {
137 option=argv[i];
138 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
139 continue;
140 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000141 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000142 if (LocaleCompare("concurrent",option+1) == 0)
143 concurrent=MagickTrue;
144 if (LocaleCompare("debug",option+1) == 0)
145 (void) SetLogEventMask(argv[++i]);
146 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000147 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000148 if (LocaleCompare("regard-warnings",option+1) == 0)
149 regard_warnings=MagickTrue;
150 }
151 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000152 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000153 {
cristybb503372010-05-27 20:51:26 +0000154 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000155 {
cristy33557d72009-11-06 00:54:33 +0000156 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000157 continue;
158 if (duration > 0)
159 {
160 if (GetElapsedTime(timer) > duration)
161 continue;
162 (void) ContinueTimer(timer);
163 }
164 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000165 if (exception->severity != UndefinedException)
166 {
167 if ((exception->severity > ErrorException) ||
168 (regard_warnings != MagickFalse))
169 status=MagickTrue;
170 CatchException(exception);
171 }
cristy3d1a5512009-10-25 21:23:27 +0000172 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000173 {
174 (void) fputs(*metadata,stdout);
175 (void) fputc('\n',stdout);
176 *metadata=DestroyString(*metadata);
177 }
178 }
179 }
cristyceae09d2009-10-28 17:18:47 +0000180 else
181 {
182 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000183#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000184 # pragma omp parallel for shared(status)
185#endif
cristybb503372010-05-27 20:51:26 +0000186 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000187 {
cristy33557d72009-11-06 00:54:33 +0000188 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000189 continue;
190 if (duration > 0)
191 {
192 if (GetElapsedTime(timer) > duration)
193 continue;
194 (void) ContinueTimer(timer);
195 }
196 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000197#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000198 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000199#endif
200 {
201 if (exception->severity != UndefinedException)
202 {
203 if ((exception->severity > ErrorException) ||
204 (regard_warnings != MagickFalse))
205 status=MagickTrue;
206 CatchException(exception);
207 }
208 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
209 {
210 (void) fputs(*metadata,stdout);
211 (void) fputc('\n',stdout);
212 *metadata=DestroyString(*metadata);
213 }
214 }
215 }
216 }
cristy3980b0d2009-10-25 14:37:13 +0000217 if (iterations > 1)
218 {
219 elapsed_time=GetElapsedTime(timer);
220 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000221 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000222 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
223 iterations,1.0*iterations/elapsed_time,user_time,(double)
224 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
225 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000226 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000227 }
228 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000229 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000230}
231
232/*
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234% %
235% %
236% %
cristy3ed852e2009-09-05 21:47:34 +0000237+ M o g r i f y I m a g e %
238% %
239% %
240% %
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242%
anthonye9c27192011-03-27 08:07:06 +0000243% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000244% image that may be part of a large list, but also handles any 'region'
245% image handling.
anthonye9c27192011-03-27 08:07:06 +0000246%
247% The image in the list may be modified in three different ways...
248%
249% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
250% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
251% * replace by a list of images (only the -separate option!)
252%
253% In each case the result is returned into the list, and a pointer to the
254% modified image (last image added if replaced by a list of images) is
255% returned.
256%
257% ASIDE: The -crop is present but restricted to non-tile single image crops
258%
259% This means if all the images are being processed (such as by
260% MogrifyImages(), next image to be processed will be as per the pointer
261% (*image)->next. Also the image list may grow as a result of some specific
262% operations but as images are never merged or deleted, it will never shrink
263% in length. Typically the list will remain the same length.
264%
265% WARNING: As the image pointed to may be replaced, the first image in the
266% list may also change. GetFirstImageInList() should be used by caller if
267% they wish return the Image pointer to the first image in list.
268%
cristy3ed852e2009-09-05 21:47:34 +0000269%
270% The format of the MogrifyImage method is:
271%
272% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
273% const char **argv,Image **image)
274%
275% A description of each parameter follows:
276%
277% o image_info: the image info..
278%
279% o argc: Specifies a pointer to an integer describing the number of
280% elements in the argument vector.
281%
282% o argv: Specifies a pointer to a text array containing the command line
283% arguments.
284%
285% o image: the image.
286%
287% o exception: return any errors or warnings in this structure.
288%
289*/
290
cristy4c08aed2011-07-01 19:47:50 +0000291/*
292** GetImageCache() will read an image into a image cache if not already
293** present then return the image that is in the cache under that filename.
294*/
anthonydf8ebac2011-04-27 09:03:19 +0000295static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
296 ExceptionInfo *exception)
297{
298 char
299 key[MaxTextExtent];
300
301 ExceptionInfo
302 *sans_exception;
303
304 Image
305 *image;
306
307 ImageInfo
308 *read_info;
309
cristyb51dff52011-05-19 16:55:47 +0000310 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000311 sans_exception=AcquireExceptionInfo();
312 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
313 sans_exception=DestroyExceptionInfo(sans_exception);
314 if (image != (Image *) NULL)
315 return(image);
316 read_info=CloneImageInfo(image_info);
317 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
318 image=ReadImage(read_info,exception);
319 read_info=DestroyImageInfo(read_info);
320 if (image != (Image *) NULL)
321 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
322 return(image);
323}
324
cristy3ed852e2009-09-05 21:47:34 +0000325static MagickBooleanType IsPathWritable(const char *path)
326{
327 if (IsPathAccessible(path) == MagickFalse)
328 return(MagickFalse);
329 if (access(path,W_OK) != 0)
330 return(MagickFalse);
331 return(MagickTrue);
332}
333
cristybb503372010-05-27 20:51:26 +0000334static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000335{
336 if (x > y)
337 return(x);
338 return(y);
339}
340
anthonydf8ebac2011-04-27 09:03:19 +0000341static MagickBooleanType MonitorProgress(const char *text,
342 const MagickOffsetType offset,const MagickSizeType extent,
343 void *wand_unused(client_data))
344{
345 char
346 message[MaxTextExtent],
347 tag[MaxTextExtent];
348
349 const char
350 *locale_message;
351
352 register char
353 *p;
354
355 if (extent < 2)
356 return(MagickTrue);
357 (void) CopyMagickMemory(tag,text,MaxTextExtent);
358 p=strrchr(tag,'/');
359 if (p != (char *) NULL)
360 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000361 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000362 locale_message=GetLocaleMessage(message);
363 if (locale_message == message)
364 locale_message=tag;
365 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000366 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
367 locale_message,(long) offset,(unsigned long) extent,(long)
368 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000369 else
cristyb51dff52011-05-19 16:55:47 +0000370 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000371 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
372 (100L*offset/(extent-1)));
373 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000374 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000375 (void) fflush(stderr);
376 return(MagickTrue);
377}
378
379/*
anthony3d2f4862011-05-01 13:48:16 +0000380** SparseColorOption() parses the complex -sparse-color argument into an
381** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000382** Argument is a complex mix of floating-point pixel coodinates, and color
383** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000384** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000385** setting.
386*/
cristy3884f692011-07-08 18:00:18 +0000387static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000388 const SparseColorMethod method,const char *arguments,
389 const MagickBooleanType color_from_image,ExceptionInfo *exception)
390{
anthonydf8ebac2011-04-27 09:03:19 +0000391 char
392 token[MaxTextExtent];
393
394 const char
395 *p;
396
397 double
398 *sparse_arguments;
399
anthonydf8ebac2011-04-27 09:03:19 +0000400 Image
401 *sparse_image;
402
cristy4c08aed2011-07-01 19:47:50 +0000403 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000404 color;
405
406 MagickBooleanType
407 error;
408
cristy5f09d852011-05-29 01:39:29 +0000409 register size_t
410 x;
411
412 size_t
413 number_arguments,
414 number_colors;
415
anthonydf8ebac2011-04-27 09:03:19 +0000416 assert(image != (Image *) NULL);
417 assert(image->signature == MagickSignature);
418 if (image->debug != MagickFalse)
419 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
420 assert(exception != (ExceptionInfo *) NULL);
421 assert(exception->signature == MagickSignature);
422 /*
423 Limit channels according to image - and add up number of color channel.
424 */
anthonydf8ebac2011-04-27 09:03:19 +0000425 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000426 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000427 number_colors++;
cristyed231572011-07-14 02:18:59 +0000428 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000429 number_colors++;
cristyed231572011-07-14 02:18:59 +0000430 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000431 number_colors++;
cristyed231572011-07-14 02:18:59 +0000432 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000433 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000434 number_colors++;
cristyed231572011-07-14 02:18:59 +0000435 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000436 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
438
439 /*
440 Read string, to determine number of arguments needed,
441 */
442 p=arguments;
443 x=0;
444 while( *p != '\0' )
445 {
446 GetMagickToken(p,&p,token);
447 if ( token[0] == ',' ) continue;
448 if ( isalpha((int) token[0]) || token[0] == '#' ) {
449 if ( color_from_image ) {
450 (void) ThrowMagickException(exception,GetMagickModule(),
451 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
452 "Color arg given, when colors are coming from image");
453 return( (Image *)NULL);
454 }
455 x += number_colors; /* color argument */
456 }
457 else {
458 x++; /* floating point argument */
459 }
460 }
461 error=MagickTrue;
462 if ( color_from_image ) {
463 /* just the control points are being given */
464 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
465 number_arguments=(x/2)*(2+number_colors);
466 }
467 else {
468 /* control points and color values */
469 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
470 number_arguments=x;
471 }
472 if ( error ) {
473 (void) ThrowMagickException(exception,GetMagickModule(),
474 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
475 "Invalid number of Arguments");
476 return( (Image *)NULL);
477 }
478
479 /* Allocate and fill in the floating point arguments */
480 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
481 sizeof(*sparse_arguments));
482 if (sparse_arguments == (double *) NULL) {
483 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
484 "MemoryAllocationFailed","%s","SparseColorOption");
485 return( (Image *)NULL);
486 }
487 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
488 sizeof(*sparse_arguments));
489 p=arguments;
490 x=0;
491 while( *p != '\0' && x < number_arguments ) {
492 /* X coordinate */
493 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
494 if ( token[0] == '\0' ) break;
495 if ( isalpha((int) token[0]) || token[0] == '#' ) {
496 (void) ThrowMagickException(exception,GetMagickModule(),
497 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
498 "Color found, instead of X-coord");
499 error = MagickTrue;
500 break;
501 }
cristyc1acd842011-05-19 23:05:47 +0000502 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000503 /* Y coordinate */
504 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
505 if ( token[0] == '\0' ) break;
506 if ( isalpha((int) token[0]) || token[0] == '#' ) {
507 (void) ThrowMagickException(exception,GetMagickModule(),
508 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
509 "Color found, instead of Y-coord");
510 error = MagickTrue;
511 break;
512 }
cristyc1acd842011-05-19 23:05:47 +0000513 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000514 /* color values for this control point */
515#if 0
516 if ( (color_from_image ) {
517 /* get color from image */
518 /* HOW??? */
519 }
520 else
521#endif
522 {
523 /* color name or function given in string argument */
524 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
525 if ( token[0] == '\0' ) break;
526 if ( isalpha((int) token[0]) || token[0] == '#' ) {
527 /* Color string given */
528 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000529 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000530 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000531 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000532 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000533 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000534 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000535 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000536 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000537 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000538 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000539 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000540 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000541 }
542 else {
543 /* Colors given as a set of floating point values - experimental */
544 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000545 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000546 {
anthonydf8ebac2011-04-27 09:03:19 +0000547 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
548 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
549 break;
cristyc1acd842011-05-19 23:05:47 +0000550 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000551 token[0] = ','; /* used this token - get another */
552 }
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000570 (image->colorspace == CMYKColorspace))
571 {
anthonydf8ebac2011-04-27 09:03:19 +0000572 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
573 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
574 break;
cristyc1acd842011-05-19 23:05:47 +0000575 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000576 token[0] = ','; /* used this token - get another */
577 }
cristyed231572011-07-14 02:18:59 +0000578 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000579 (image->matte != MagickFalse))
580 {
anthonydf8ebac2011-04-27 09:03:19 +0000581 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
582 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
583 break;
cristyc1acd842011-05-19 23:05:47 +0000584 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000585 token[0] = ','; /* used this token - get another */
586 }
587 }
588 }
589 }
590 if ( number_arguments != x && !error ) {
591 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
592 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
593 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
594 return( (Image *)NULL);
595 }
596 if ( error )
597 return( (Image *)NULL);
598
599 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000600 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
601 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000602 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
603 return( sparse_image );
604}
605
cristy3ed852e2009-09-05 21:47:34 +0000606WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
607 const char **argv,Image **image,ExceptionInfo *exception)
608{
anthonydf8ebac2011-04-27 09:03:19 +0000609 ChannelType
610 channel;
611
612 const char
613 *format,
614 *option;
615
616 DrawInfo
617 *draw_info;
618
619 GeometryInfo
620 geometry_info;
621
cristy3ed852e2009-09-05 21:47:34 +0000622 Image
623 *region_image;
624
anthonydf8ebac2011-04-27 09:03:19 +0000625 ImageInfo
626 *mogrify_info;
627
cristyebbcfea2011-02-25 02:43:54 +0000628 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000629 status;
630
cristy4c08aed2011-07-01 19:47:50 +0000631 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000632 fill;
cristy3ed852e2009-09-05 21:47:34 +0000633
anthonydf8ebac2011-04-27 09:03:19 +0000634 MagickStatusType
635 flags;
636
637 QuantizeInfo
638 *quantize_info;
639
640 RectangleInfo
641 geometry,
642 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000643
cristybb503372010-05-27 20:51:26 +0000644 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000645 i;
646
647 /*
648 Initialize method variables.
649 */
650 assert(image_info != (const ImageInfo *) NULL);
651 assert(image_info->signature == MagickSignature);
652 assert(image != (Image **) NULL);
653 assert((*image)->signature == MagickSignature);
654 if ((*image)->debug != MagickFalse)
655 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
656 if (argc < 0)
657 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000658 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000659 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
660 quantize_info=AcquireQuantizeInfo(mogrify_info);
661 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000662 GetPixelInfo(*image,&fill);
663 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000664 channel=mogrify_info->channel;
665 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000666 SetGeometry(*image,&region_geometry);
667 region_image=NewImageList();
668 /*
669 Transmogrify the image.
670 */
cristybb503372010-05-27 20:51:26 +0000671 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000672 {
anthonydf8ebac2011-04-27 09:03:19 +0000673 Image
674 *mogrify_image;
675
anthonye9c27192011-03-27 08:07:06 +0000676 ssize_t
677 count;
678
anthonydf8ebac2011-04-27 09:03:19 +0000679 option=argv[i];
680 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000681 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000682 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
683 0L);
cristycee97112010-05-28 00:44:52 +0000684 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000685 break;
cristy6b3da3a2010-06-20 02:21:46 +0000686 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000687 mogrify_image=(Image *)NULL;
688 switch (*(option+1))
689 {
690 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000691 {
anthonydf8ebac2011-04-27 09:03:19 +0000692 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000693 {
anthonydf8ebac2011-04-27 09:03:19 +0000694 /*
695 Adaptive blur image.
696 */
697 (void) SyncImageSettings(mogrify_info,*image);
698 flags=ParseGeometry(argv[i+1],&geometry_info);
699 if ((flags & SigmaValue) == 0)
700 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000701 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
702 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000703 break;
cristy3ed852e2009-09-05 21:47:34 +0000704 }
anthonydf8ebac2011-04-27 09:03:19 +0000705 if (LocaleCompare("adaptive-resize",option+1) == 0)
706 {
707 /*
708 Adaptive resize image.
709 */
710 (void) SyncImageSettings(mogrify_info,*image);
711 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
712 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
713 geometry.height,exception);
714 break;
715 }
716 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
717 {
718 /*
719 Adaptive sharpen image.
720 */
721 (void) SyncImageSettings(mogrify_info,*image);
722 flags=ParseGeometry(argv[i+1],&geometry_info);
723 if ((flags & SigmaValue) == 0)
724 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000725 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
726 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000727 break;
728 }
729 if (LocaleCompare("affine",option+1) == 0)
730 {
731 /*
732 Affine matrix.
733 */
734 if (*option == '+')
735 {
736 GetAffineMatrix(&draw_info->affine);
737 break;
738 }
739 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
740 break;
741 }
742 if (LocaleCompare("alpha",option+1) == 0)
743 {
744 AlphaChannelType
745 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000746
anthonydf8ebac2011-04-27 09:03:19 +0000747 (void) SyncImageSettings(mogrify_info,*image);
748 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
749 MagickFalse,argv[i+1]);
750 (void) SetImageAlphaChannel(*image,alpha_type);
751 InheritException(exception,&(*image)->exception);
752 break;
753 }
754 if (LocaleCompare("annotate",option+1) == 0)
755 {
756 char
757 *text,
758 geometry[MaxTextExtent];
759
760 /*
761 Annotate image.
762 */
763 (void) SyncImageSettings(mogrify_info,*image);
764 SetGeometryInfo(&geometry_info);
765 flags=ParseGeometry(argv[i+1],&geometry_info);
766 if ((flags & SigmaValue) == 0)
767 geometry_info.sigma=geometry_info.rho;
768 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
769 InheritException(exception,&(*image)->exception);
770 if (text == (char *) NULL)
771 break;
772 (void) CloneString(&draw_info->text,text);
773 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000774 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000775 geometry_info.xi,geometry_info.psi);
776 (void) CloneString(&draw_info->geometry,geometry);
777 draw_info->affine.sx=cos(DegreesToRadians(
778 fmod(geometry_info.rho,360.0)));
779 draw_info->affine.rx=sin(DegreesToRadians(
780 fmod(geometry_info.rho,360.0)));
781 draw_info->affine.ry=(-sin(DegreesToRadians(
782 fmod(geometry_info.sigma,360.0))));
783 draw_info->affine.sy=cos(DegreesToRadians(
784 fmod(geometry_info.sigma,360.0)));
785 (void) AnnotateImage(*image,draw_info);
786 InheritException(exception,&(*image)->exception);
787 break;
788 }
789 if (LocaleCompare("antialias",option+1) == 0)
790 {
791 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
792 MagickFalse;
793 draw_info->text_antialias=(*option == '-') ? MagickTrue :
794 MagickFalse;
795 break;
796 }
797 if (LocaleCompare("auto-gamma",option+1) == 0)
798 {
799 /*
800 Auto Adjust Gamma of image based on its mean
801 */
802 (void) SyncImageSettings(mogrify_info,*image);
cristyab015852011-07-06 01:03:32 +0000803 (void) AutoGammaImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +0000804 break;
805 }
806 if (LocaleCompare("auto-level",option+1) == 0)
807 {
808 /*
809 Perfectly Normalize (max/min stretch) the image
810 */
811 (void) SyncImageSettings(mogrify_info,*image);
cristyab015852011-07-06 01:03:32 +0000812 (void) AutoLevelImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +0000813 break;
814 }
815 if (LocaleCompare("auto-orient",option+1) == 0)
816 {
817 (void) SyncImageSettings(mogrify_info,*image);
818 switch ((*image)->orientation)
819 {
820 case TopRightOrientation:
821 {
822 mogrify_image=FlopImage(*image,exception);
823 break;
824 }
825 case BottomRightOrientation:
826 {
827 mogrify_image=RotateImage(*image,180.0,exception);
828 break;
829 }
830 case BottomLeftOrientation:
831 {
832 mogrify_image=FlipImage(*image,exception);
833 break;
834 }
835 case LeftTopOrientation:
836 {
837 mogrify_image=TransposeImage(*image,exception);
838 break;
839 }
840 case RightTopOrientation:
841 {
842 mogrify_image=RotateImage(*image,90.0,exception);
843 break;
844 }
845 case RightBottomOrientation:
846 {
847 mogrify_image=TransverseImage(*image,exception);
848 break;
849 }
850 case LeftBottomOrientation:
851 {
852 mogrify_image=RotateImage(*image,270.0,exception);
853 break;
854 }
855 default:
856 break;
857 }
858 if (mogrify_image != (Image *) NULL)
859 mogrify_image->orientation=TopLeftOrientation;
860 break;
861 }
862 break;
863 }
864 case 'b':
865 {
866 if (LocaleCompare("black-threshold",option+1) == 0)
867 {
868 /*
869 Black threshold image.
870 */
871 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000872 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000873 InheritException(exception,&(*image)->exception);
874 break;
875 }
876 if (LocaleCompare("blue-shift",option+1) == 0)
877 {
878 /*
879 Blue shift image.
880 */
881 (void) SyncImageSettings(mogrify_info,*image);
882 geometry_info.rho=1.5;
883 if (*option == '-')
884 flags=ParseGeometry(argv[i+1],&geometry_info);
885 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
886 break;
887 }
888 if (LocaleCompare("blur",option+1) == 0)
889 {
890 /*
891 Gaussian blur image.
892 */
893 (void) SyncImageSettings(mogrify_info,*image);
894 flags=ParseGeometry(argv[i+1],&geometry_info);
895 if ((flags & SigmaValue) == 0)
896 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000897 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000898 geometry_info.sigma,exception);
899 break;
900 }
901 if (LocaleCompare("border",option+1) == 0)
902 {
903 /*
904 Surround image with a border of solid color.
905 */
906 (void) SyncImageSettings(mogrify_info,*image);
907 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
908 if ((flags & SigmaValue) == 0)
909 geometry.height=geometry.width;
910 mogrify_image=BorderImage(*image,&geometry,exception);
911 break;
912 }
913 if (LocaleCompare("bordercolor",option+1) == 0)
914 {
915 if (*option == '+')
916 {
917 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
918 exception);
919 break;
920 }
921 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
922 exception);
923 break;
924 }
925 if (LocaleCompare("box",option+1) == 0)
926 {
927 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
928 exception);
929 break;
930 }
931 if (LocaleCompare("brightness-contrast",option+1) == 0)
932 {
933 double
934 brightness,
935 contrast;
936
937 GeometryInfo
938 geometry_info;
939
940 MagickStatusType
941 flags;
942
943 /*
944 Brightness / contrast image.
945 */
946 (void) SyncImageSettings(mogrify_info,*image);
947 flags=ParseGeometry(argv[i+1],&geometry_info);
948 brightness=geometry_info.rho;
949 contrast=0.0;
950 if ((flags & SigmaValue) != 0)
951 contrast=geometry_info.sigma;
cristy9ee60942011-07-06 14:54:38 +0000952 (void) BrightnessContrastImage(*image,brightness,contrast);
anthonydf8ebac2011-04-27 09:03:19 +0000953 InheritException(exception,&(*image)->exception);
954 break;
955 }
956 break;
957 }
958 case 'c':
959 {
960 if (LocaleCompare("cdl",option+1) == 0)
961 {
962 char
963 *color_correction_collection;
964
965 /*
966 Color correct with a color decision list.
967 */
968 (void) SyncImageSettings(mogrify_info,*image);
969 color_correction_collection=FileToString(argv[i+1],~0,exception);
970 if (color_correction_collection == (char *) NULL)
971 break;
972 (void) ColorDecisionListImage(*image,color_correction_collection);
973 InheritException(exception,&(*image)->exception);
974 break;
975 }
976 if (LocaleCompare("channel",option+1) == 0)
977 {
978 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000979 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000980 else
cristyfa806a72011-07-04 02:06:13 +0000981 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000982 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000983 break;
984 }
985 if (LocaleCompare("charcoal",option+1) == 0)
986 {
987 /*
988 Charcoal image.
989 */
990 (void) SyncImageSettings(mogrify_info,*image);
991 flags=ParseGeometry(argv[i+1],&geometry_info);
992 if ((flags & SigmaValue) == 0)
993 geometry_info.sigma=1.0;
994 mogrify_image=CharcoalImage(*image,geometry_info.rho,
995 geometry_info.sigma,exception);
996 break;
997 }
998 if (LocaleCompare("chop",option+1) == 0)
999 {
1000 /*
1001 Chop the image.
1002 */
1003 (void) SyncImageSettings(mogrify_info,*image);
1004 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1005 mogrify_image=ChopImage(*image,&geometry,exception);
1006 break;
1007 }
1008 if (LocaleCompare("clamp",option+1) == 0)
1009 {
1010 /*
1011 Clamp image.
1012 */
1013 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001014 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001015 InheritException(exception,&(*image)->exception);
1016 break;
1017 }
1018 if (LocaleCompare("clip",option+1) == 0)
1019 {
1020 (void) SyncImageSettings(mogrify_info,*image);
1021 if (*option == '+')
1022 {
1023 (void) SetImageClipMask(*image,(Image *) NULL);
1024 InheritException(exception,&(*image)->exception);
1025 break;
1026 }
1027 (void) ClipImage(*image);
1028 InheritException(exception,&(*image)->exception);
1029 break;
1030 }
1031 if (LocaleCompare("clip-mask",option+1) == 0)
1032 {
1033 CacheView
1034 *mask_view;
1035
1036 Image
1037 *mask_image;
1038
cristy4c08aed2011-07-01 19:47:50 +00001039 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001040 *restrict q;
1041
1042 register ssize_t
1043 x;
1044
1045 ssize_t
1046 y;
1047
1048 (void) SyncImageSettings(mogrify_info,*image);
1049 if (*option == '+')
1050 {
1051 /*
1052 Remove a mask.
1053 */
1054 (void) SetImageMask(*image,(Image *) NULL);
1055 InheritException(exception,&(*image)->exception);
1056 break;
1057 }
1058 /*
1059 Set the image mask.
1060 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1061 */
1062 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1063 if (mask_image == (Image *) NULL)
1064 break;
1065 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1066 return(MagickFalse);
1067 mask_view=AcquireCacheView(mask_image);
1068 for (y=0; y < (ssize_t) mask_image->rows; y++)
1069 {
1070 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1071 exception);
cristy4c08aed2011-07-01 19:47:50 +00001072 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001073 break;
1074 for (x=0; x < (ssize_t) mask_image->columns; x++)
1075 {
1076 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001077 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1078 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1079 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1080 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001081 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001082 }
1083 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1084 break;
1085 }
1086 mask_view=DestroyCacheView(mask_view);
1087 mask_image->matte=MagickTrue;
1088 (void) SetImageClipMask(*image,mask_image);
1089 mask_image=DestroyImage(mask_image);
1090 InheritException(exception,&(*image)->exception);
1091 break;
1092 }
1093 if (LocaleCompare("clip-path",option+1) == 0)
1094 {
1095 (void) SyncImageSettings(mogrify_info,*image);
1096 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1097 MagickFalse);
1098 InheritException(exception,&(*image)->exception);
1099 break;
1100 }
1101 if (LocaleCompare("colorize",option+1) == 0)
1102 {
1103 /*
1104 Colorize the image.
1105 */
1106 (void) SyncImageSettings(mogrify_info,*image);
1107 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1108 exception);
1109 break;
1110 }
1111 if (LocaleCompare("color-matrix",option+1) == 0)
1112 {
1113 KernelInfo
1114 *kernel;
1115
1116 (void) SyncImageSettings(mogrify_info,*image);
1117 kernel=AcquireKernelInfo(argv[i+1]);
1118 if (kernel == (KernelInfo *) NULL)
1119 break;
1120 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1121 kernel=DestroyKernelInfo(kernel);
1122 break;
1123 }
1124 if (LocaleCompare("colors",option+1) == 0)
1125 {
1126 /*
1127 Reduce the number of colors in the image.
1128 */
1129 (void) SyncImageSettings(mogrify_info,*image);
1130 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1131 if (quantize_info->number_colors == 0)
1132 break;
1133 if (((*image)->storage_class == DirectClass) ||
1134 (*image)->colors > quantize_info->number_colors)
1135 (void) QuantizeImage(quantize_info,*image);
1136 else
1137 (void) CompressImageColormap(*image);
1138 InheritException(exception,&(*image)->exception);
1139 break;
1140 }
1141 if (LocaleCompare("colorspace",option+1) == 0)
1142 {
1143 ColorspaceType
1144 colorspace;
1145
1146 (void) SyncImageSettings(mogrify_info,*image);
1147 if (*option == '+')
1148 {
1149 (void) TransformImageColorspace(*image,RGBColorspace);
1150 InheritException(exception,&(*image)->exception);
1151 break;
1152 }
1153 colorspace=(ColorspaceType) ParseCommandOption(
1154 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1155 (void) TransformImageColorspace(*image,colorspace);
1156 InheritException(exception,&(*image)->exception);
1157 break;
1158 }
1159 if (LocaleCompare("contrast",option+1) == 0)
1160 {
1161 (void) SyncImageSettings(mogrify_info,*image);
1162 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1163 MagickFalse);
1164 InheritException(exception,&(*image)->exception);
1165 break;
1166 }
1167 if (LocaleCompare("contrast-stretch",option+1) == 0)
1168 {
1169 double
1170 black_point,
1171 white_point;
1172
1173 MagickStatusType
1174 flags;
1175
1176 /*
1177 Contrast stretch image.
1178 */
1179 (void) SyncImageSettings(mogrify_info,*image);
1180 flags=ParseGeometry(argv[i+1],&geometry_info);
1181 black_point=geometry_info.rho;
1182 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1183 black_point;
1184 if ((flags & PercentValue) != 0)
1185 {
1186 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1187 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1188 }
1189 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1190 white_point;
cristy50fbc382011-07-07 02:19:17 +00001191 (void) ContrastStretchImage(*image,black_point,white_point);
anthonydf8ebac2011-04-27 09:03:19 +00001192 InheritException(exception,&(*image)->exception);
1193 break;
1194 }
1195 if (LocaleCompare("convolve",option+1) == 0)
1196 {
anthonydf8ebac2011-04-27 09:03:19 +00001197 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001198 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001199
anthonydf8ebac2011-04-27 09:03:19 +00001200 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001201 kernel_info=AcquireKernelInfo(argv[i+1]);
1202 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001203 break;
cristy5e6be1e2011-07-16 01:23:39 +00001204 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001205 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001206 break;
1207 }
1208 if (LocaleCompare("crop",option+1) == 0)
1209 {
1210 /*
1211 Crop a image to a smaller size
1212 */
1213 (void) SyncImageSettings(mogrify_info,*image);
1214#if 0
1215 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1216 if (((geometry.width != 0) || (geometry.height != 0)) &&
1217 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1218 break;
1219#endif
1220#if 0
1221 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1222 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1223 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1224 InheritException(exception,&mogrify_image->exception);
1225#else
1226 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1227#endif
1228 break;
1229 }
1230 if (LocaleCompare("cycle",option+1) == 0)
1231 {
1232 /*
1233 Cycle an image colormap.
1234 */
1235 (void) SyncImageSettings(mogrify_info,*image);
1236 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1237 InheritException(exception,&(*image)->exception);
1238 break;
1239 }
1240 break;
1241 }
1242 case 'd':
1243 {
1244 if (LocaleCompare("decipher",option+1) == 0)
1245 {
1246 StringInfo
1247 *passkey;
1248
1249 /*
1250 Decipher pixels.
1251 */
1252 (void) SyncImageSettings(mogrify_info,*image);
1253 passkey=FileToStringInfo(argv[i+1],~0,exception);
1254 if (passkey != (StringInfo *) NULL)
1255 {
1256 (void) PasskeyDecipherImage(*image,passkey,exception);
1257 passkey=DestroyStringInfo(passkey);
1258 }
1259 break;
1260 }
1261 if (LocaleCompare("density",option+1) == 0)
1262 {
1263 /*
1264 Set image density.
1265 */
1266 (void) CloneString(&draw_info->density,argv[i+1]);
1267 break;
1268 }
1269 if (LocaleCompare("depth",option+1) == 0)
1270 {
1271 (void) SyncImageSettings(mogrify_info,*image);
1272 if (*option == '+')
1273 {
1274 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1275 break;
1276 }
1277 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1278 break;
1279 }
1280 if (LocaleCompare("deskew",option+1) == 0)
1281 {
1282 double
1283 threshold;
1284
1285 /*
1286 Straighten the image.
1287 */
1288 (void) SyncImageSettings(mogrify_info,*image);
1289 if (*option == '+')
1290 threshold=40.0*QuantumRange/100.0;
1291 else
1292 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1293 mogrify_image=DeskewImage(*image,threshold,exception);
1294 break;
1295 }
1296 if (LocaleCompare("despeckle",option+1) == 0)
1297 {
1298 /*
1299 Reduce the speckles within an image.
1300 */
1301 (void) SyncImageSettings(mogrify_info,*image);
1302 mogrify_image=DespeckleImage(*image,exception);
1303 break;
1304 }
1305 if (LocaleCompare("display",option+1) == 0)
1306 {
1307 (void) CloneString(&draw_info->server_name,argv[i+1]);
1308 break;
1309 }
1310 if (LocaleCompare("distort",option+1) == 0)
1311 {
1312 char
1313 *args,
1314 token[MaxTextExtent];
1315
1316 const char
1317 *p;
1318
1319 DistortImageMethod
1320 method;
1321
1322 double
1323 *arguments;
1324
1325 register ssize_t
1326 x;
1327
1328 size_t
1329 number_arguments;
1330
1331 /*
1332 Distort image.
1333 */
1334 (void) SyncImageSettings(mogrify_info,*image);
1335 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1336 MagickFalse,argv[i+1]);
1337 if ( method == ResizeDistortion )
1338 {
1339 /* Special Case - Argument is actually a resize geometry!
1340 ** Convert that to an appropriate distortion argument array.
1341 */
1342 double
1343 resize_args[2];
1344 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1345 exception);
1346 resize_args[0]=(double)geometry.width;
1347 resize_args[1]=(double)geometry.height;
1348 mogrify_image=DistortImage(*image,method,(size_t)2,
1349 resize_args,MagickTrue,exception);
1350 break;
1351 }
1352 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1353 InheritException(exception,&(*image)->exception);
1354 if (args == (char *) NULL)
1355 break;
1356 p=(char *) args;
1357 for (x=0; *p != '\0'; x++)
1358 {
1359 GetMagickToken(p,&p,token);
1360 if (*token == ',')
1361 GetMagickToken(p,&p,token);
1362 }
1363 number_arguments=(size_t) x;
1364 arguments=(double *) AcquireQuantumMemory(number_arguments,
1365 sizeof(*arguments));
1366 if (arguments == (double *) NULL)
1367 ThrowWandFatalException(ResourceLimitFatalError,
1368 "MemoryAllocationFailed",(*image)->filename);
1369 (void) ResetMagickMemory(arguments,0,number_arguments*
1370 sizeof(*arguments));
1371 p=(char *) args;
1372 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1373 {
1374 GetMagickToken(p,&p,token);
1375 if (*token == ',')
1376 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001377 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001378 }
1379 args=DestroyString(args);
1380 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1381 (*option == '+') ? MagickTrue : MagickFalse,exception);
1382 arguments=(double *) RelinquishMagickMemory(arguments);
1383 break;
1384 }
1385 if (LocaleCompare("dither",option+1) == 0)
1386 {
1387 if (*option == '+')
1388 {
1389 quantize_info->dither=MagickFalse;
1390 break;
1391 }
1392 quantize_info->dither=MagickTrue;
1393 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1394 MagickDitherOptions,MagickFalse,argv[i+1]);
1395 if (quantize_info->dither_method == NoDitherMethod)
1396 quantize_info->dither=MagickFalse;
1397 break;
1398 }
1399 if (LocaleCompare("draw",option+1) == 0)
1400 {
1401 /*
1402 Draw image.
1403 */
1404 (void) SyncImageSettings(mogrify_info,*image);
1405 (void) CloneString(&draw_info->primitive,argv[i+1]);
1406 (void) DrawImage(*image,draw_info);
1407 InheritException(exception,&(*image)->exception);
1408 break;
1409 }
1410 break;
1411 }
1412 case 'e':
1413 {
1414 if (LocaleCompare("edge",option+1) == 0)
1415 {
1416 /*
1417 Enhance edges in the 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=EdgeImage(*image,geometry_info.rho,exception);
1424 break;
1425 }
1426 if (LocaleCompare("emboss",option+1) == 0)
1427 {
1428 /*
1429 Gaussian embossen image.
1430 */
1431 (void) SyncImageSettings(mogrify_info,*image);
1432 flags=ParseGeometry(argv[i+1],&geometry_info);
1433 if ((flags & SigmaValue) == 0)
1434 geometry_info.sigma=1.0;
1435 mogrify_image=EmbossImage(*image,geometry_info.rho,
1436 geometry_info.sigma,exception);
1437 break;
1438 }
1439 if (LocaleCompare("encipher",option+1) == 0)
1440 {
1441 StringInfo
1442 *passkey;
1443
1444 /*
1445 Encipher pixels.
1446 */
1447 (void) SyncImageSettings(mogrify_info,*image);
1448 passkey=FileToStringInfo(argv[i+1],~0,exception);
1449 if (passkey != (StringInfo *) NULL)
1450 {
1451 (void) PasskeyEncipherImage(*image,passkey,exception);
1452 passkey=DestroyStringInfo(passkey);
1453 }
1454 break;
1455 }
1456 if (LocaleCompare("encoding",option+1) == 0)
1457 {
1458 (void) CloneString(&draw_info->encoding,argv[i+1]);
1459 break;
1460 }
1461 if (LocaleCompare("enhance",option+1) == 0)
1462 {
1463 /*
1464 Enhance image.
1465 */
1466 (void) SyncImageSettings(mogrify_info,*image);
1467 mogrify_image=EnhanceImage(*image,exception);
1468 break;
1469 }
1470 if (LocaleCompare("equalize",option+1) == 0)
1471 {
1472 /*
1473 Equalize image.
1474 */
1475 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00001476 (void) EqualizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001477 InheritException(exception,&(*image)->exception);
1478 break;
1479 }
1480 if (LocaleCompare("evaluate",option+1) == 0)
1481 {
1482 double
1483 constant;
1484
1485 MagickEvaluateOperator
1486 op;
1487
1488 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001489 op=(MagickEvaluateOperator) ParseCommandOption(
1490 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001491 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001492 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001493 break;
1494 }
1495 if (LocaleCompare("extent",option+1) == 0)
1496 {
1497 /*
1498 Set the image extent.
1499 */
1500 (void) SyncImageSettings(mogrify_info,*image);
1501 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1502 if (geometry.width == 0)
1503 geometry.width=(*image)->columns;
1504 if (geometry.height == 0)
1505 geometry.height=(*image)->rows;
1506 mogrify_image=ExtentImage(*image,&geometry,exception);
1507 break;
1508 }
1509 break;
1510 }
1511 case 'f':
1512 {
1513 if (LocaleCompare("family",option+1) == 0)
1514 {
1515 if (*option == '+')
1516 {
1517 if (draw_info->family != (char *) NULL)
1518 draw_info->family=DestroyString(draw_info->family);
1519 break;
1520 }
1521 (void) CloneString(&draw_info->family,argv[i+1]);
1522 break;
1523 }
1524 if (LocaleCompare("features",option+1) == 0)
1525 {
1526 if (*option == '+')
1527 {
1528 (void) DeleteImageArtifact(*image,"identify:features");
1529 break;
1530 }
1531 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1532 break;
1533 }
1534 if (LocaleCompare("fill",option+1) == 0)
1535 {
1536 ExceptionInfo
1537 *sans;
1538
cristy4c08aed2011-07-01 19:47:50 +00001539 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001540 if (*option == '+')
1541 {
1542 (void) QueryMagickColor("none",&fill,exception);
1543 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1544 if (draw_info->fill_pattern != (Image *) NULL)
1545 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1546 break;
1547 }
1548 sans=AcquireExceptionInfo();
1549 (void) QueryMagickColor(argv[i+1],&fill,sans);
1550 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1551 sans=DestroyExceptionInfo(sans);
1552 if (status == MagickFalse)
1553 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1554 exception);
1555 break;
1556 }
1557 if (LocaleCompare("flip",option+1) == 0)
1558 {
1559 /*
1560 Flip image scanlines.
1561 */
1562 (void) SyncImageSettings(mogrify_info,*image);
1563 mogrify_image=FlipImage(*image,exception);
1564 break;
1565 }
anthonydf8ebac2011-04-27 09:03:19 +00001566 if (LocaleCompare("floodfill",option+1) == 0)
1567 {
cristy4c08aed2011-07-01 19:47:50 +00001568 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001569 target;
1570
1571 /*
1572 Floodfill image.
1573 */
1574 (void) SyncImageSettings(mogrify_info,*image);
1575 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1576 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001577 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1578 geometry.y,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00001579 InheritException(exception,&(*image)->exception);
1580 break;
1581 }
anthony3d2f4862011-05-01 13:48:16 +00001582 if (LocaleCompare("flop",option+1) == 0)
1583 {
1584 /*
1585 Flop image scanlines.
1586 */
1587 (void) SyncImageSettings(mogrify_info,*image);
1588 mogrify_image=FlopImage(*image,exception);
1589 break;
1590 }
anthonydf8ebac2011-04-27 09:03:19 +00001591 if (LocaleCompare("font",option+1) == 0)
1592 {
1593 if (*option == '+')
1594 {
1595 if (draw_info->font != (char *) NULL)
1596 draw_info->font=DestroyString(draw_info->font);
1597 break;
1598 }
1599 (void) CloneString(&draw_info->font,argv[i+1]);
1600 break;
1601 }
1602 if (LocaleCompare("format",option+1) == 0)
1603 {
1604 format=argv[i+1];
1605 break;
1606 }
1607 if (LocaleCompare("frame",option+1) == 0)
1608 {
1609 FrameInfo
1610 frame_info;
1611
1612 /*
1613 Surround image with an ornamental border.
1614 */
1615 (void) SyncImageSettings(mogrify_info,*image);
1616 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1617 frame_info.width=geometry.width;
1618 frame_info.height=geometry.height;
1619 if ((flags & HeightValue) == 0)
1620 frame_info.height=geometry.width;
1621 frame_info.outer_bevel=geometry.x;
1622 frame_info.inner_bevel=geometry.y;
1623 frame_info.x=(ssize_t) frame_info.width;
1624 frame_info.y=(ssize_t) frame_info.height;
1625 frame_info.width=(*image)->columns+2*frame_info.width;
1626 frame_info.height=(*image)->rows+2*frame_info.height;
1627 mogrify_image=FrameImage(*image,&frame_info,exception);
1628 break;
1629 }
1630 if (LocaleCompare("function",option+1) == 0)
1631 {
1632 char
1633 *arguments,
1634 token[MaxTextExtent];
1635
1636 const char
1637 *p;
1638
1639 double
1640 *parameters;
1641
1642 MagickFunction
1643 function;
1644
1645 register ssize_t
1646 x;
1647
1648 size_t
1649 number_parameters;
1650
1651 /*
1652 Function Modify Image Values
1653 */
1654 (void) SyncImageSettings(mogrify_info,*image);
1655 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1656 MagickFalse,argv[i+1]);
1657 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1658 InheritException(exception,&(*image)->exception);
1659 if (arguments == (char *) NULL)
1660 break;
1661 p=(char *) arguments;
1662 for (x=0; *p != '\0'; x++)
1663 {
1664 GetMagickToken(p,&p,token);
1665 if (*token == ',')
1666 GetMagickToken(p,&p,token);
1667 }
1668 number_parameters=(size_t) x;
1669 parameters=(double *) AcquireQuantumMemory(number_parameters,
1670 sizeof(*parameters));
1671 if (parameters == (double *) NULL)
1672 ThrowWandFatalException(ResourceLimitFatalError,
1673 "MemoryAllocationFailed",(*image)->filename);
1674 (void) ResetMagickMemory(parameters,0,number_parameters*
1675 sizeof(*parameters));
1676 p=(char *) arguments;
1677 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1678 {
1679 GetMagickToken(p,&p,token);
1680 if (*token == ',')
1681 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001682 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001683 }
1684 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001685 (void) FunctionImage(*image,function,number_parameters,parameters,
1686 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001687 parameters=(double *) RelinquishMagickMemory(parameters);
1688 break;
1689 }
1690 break;
1691 }
1692 case 'g':
1693 {
1694 if (LocaleCompare("gamma",option+1) == 0)
1695 {
1696 /*
1697 Gamma image.
1698 */
1699 (void) SyncImageSettings(mogrify_info,*image);
1700 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001701 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001702 else
1703 {
cristy50fbc382011-07-07 02:19:17 +00001704 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1705 (char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001706 InheritException(exception,&(*image)->exception);
1707 }
1708 break;
1709 }
1710 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1711 (LocaleCompare("gaussian",option+1) == 0))
1712 {
1713 /*
1714 Gaussian blur image.
1715 */
1716 (void) SyncImageSettings(mogrify_info,*image);
1717 flags=ParseGeometry(argv[i+1],&geometry_info);
1718 if ((flags & SigmaValue) == 0)
1719 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001720 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1721 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001722 break;
1723 }
1724 if (LocaleCompare("geometry",option+1) == 0)
1725 {
1726 /*
1727 Record Image offset, Resize last image.
1728 */
1729 (void) SyncImageSettings(mogrify_info,*image);
1730 if (*option == '+')
1731 {
1732 if ((*image)->geometry != (char *) NULL)
1733 (*image)->geometry=DestroyString((*image)->geometry);
1734 break;
1735 }
1736 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1737 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1738 (void) CloneString(&(*image)->geometry,argv[i+1]);
1739 else
1740 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1741 (*image)->filter,(*image)->blur,exception);
1742 break;
1743 }
1744 if (LocaleCompare("gravity",option+1) == 0)
1745 {
1746 if (*option == '+')
1747 {
1748 draw_info->gravity=UndefinedGravity;
1749 break;
1750 }
1751 draw_info->gravity=(GravityType) ParseCommandOption(
1752 MagickGravityOptions,MagickFalse,argv[i+1]);
1753 break;
1754 }
1755 break;
1756 }
1757 case 'h':
1758 {
1759 if (LocaleCompare("highlight-color",option+1) == 0)
1760 {
1761 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1762 break;
1763 }
1764 break;
1765 }
1766 case 'i':
1767 {
1768 if (LocaleCompare("identify",option+1) == 0)
1769 {
1770 char
1771 *text;
1772
1773 (void) SyncImageSettings(mogrify_info,*image);
1774 if (format == (char *) NULL)
1775 {
1776 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1777 InheritException(exception,&(*image)->exception);
1778 break;
1779 }
1780 text=InterpretImageProperties(mogrify_info,*image,format);
1781 InheritException(exception,&(*image)->exception);
1782 if (text == (char *) NULL)
1783 break;
1784 (void) fputs(text,stdout);
1785 (void) fputc('\n',stdout);
1786 text=DestroyString(text);
1787 break;
1788 }
1789 if (LocaleCompare("implode",option+1) == 0)
1790 {
1791 /*
1792 Implode image.
1793 */
1794 (void) SyncImageSettings(mogrify_info,*image);
1795 (void) ParseGeometry(argv[i+1],&geometry_info);
1796 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1797 break;
1798 }
1799 if (LocaleCompare("interline-spacing",option+1) == 0)
1800 {
1801 if (*option == '+')
1802 (void) ParseGeometry("0",&geometry_info);
1803 else
1804 (void) ParseGeometry(argv[i+1],&geometry_info);
1805 draw_info->interline_spacing=geometry_info.rho;
1806 break;
1807 }
1808 if (LocaleCompare("interword-spacing",option+1) == 0)
1809 {
1810 if (*option == '+')
1811 (void) ParseGeometry("0",&geometry_info);
1812 else
1813 (void) ParseGeometry(argv[i+1],&geometry_info);
1814 draw_info->interword_spacing=geometry_info.rho;
1815 break;
1816 }
1817 break;
1818 }
1819 case 'k':
1820 {
1821 if (LocaleCompare("kerning",option+1) == 0)
1822 {
1823 if (*option == '+')
1824 (void) ParseGeometry("0",&geometry_info);
1825 else
1826 (void) ParseGeometry(argv[i+1],&geometry_info);
1827 draw_info->kerning=geometry_info.rho;
1828 break;
1829 }
1830 break;
1831 }
1832 case 'l':
1833 {
1834 if (LocaleCompare("lat",option+1) == 0)
1835 {
1836 /*
1837 Local adaptive threshold image.
1838 */
1839 (void) SyncImageSettings(mogrify_info,*image);
1840 flags=ParseGeometry(argv[i+1],&geometry_info);
1841 if ((flags & PercentValue) != 0)
1842 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1843 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1844 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1845 geometry_info.xi,exception);
1846 break;
1847 }
1848 if (LocaleCompare("level",option+1) == 0)
1849 {
1850 MagickRealType
1851 black_point,
1852 gamma,
1853 white_point;
1854
1855 MagickStatusType
1856 flags;
1857
1858 /*
1859 Parse levels.
1860 */
1861 (void) SyncImageSettings(mogrify_info,*image);
1862 flags=ParseGeometry(argv[i+1],&geometry_info);
1863 black_point=geometry_info.rho;
1864 white_point=(MagickRealType) QuantumRange;
1865 if ((flags & SigmaValue) != 0)
1866 white_point=geometry_info.sigma;
1867 gamma=1.0;
1868 if ((flags & XiValue) != 0)
1869 gamma=geometry_info.xi;
1870 if ((flags & PercentValue) != 0)
1871 {
1872 black_point*=(MagickRealType) (QuantumRange/100.0);
1873 white_point*=(MagickRealType) (QuantumRange/100.0);
1874 }
1875 if ((flags & SigmaValue) == 0)
1876 white_point=(MagickRealType) QuantumRange-black_point;
1877 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy50fbc382011-07-07 02:19:17 +00001878 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001879 else
cristyf89cb1d2011-07-07 01:24:37 +00001880 (void) LevelImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001881 InheritException(exception,&(*image)->exception);
1882 break;
1883 }
1884 if (LocaleCompare("level-colors",option+1) == 0)
1885 {
1886 char
1887 token[MaxTextExtent];
1888
1889 const char
1890 *p;
1891
cristy4c08aed2011-07-01 19:47:50 +00001892 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001893 black_point,
1894 white_point;
1895
1896 p=(const char *) argv[i+1];
1897 GetMagickToken(p,&p,token); /* get black point color */
1898 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1899 (void) QueryMagickColor(token,&black_point,exception);
1900 else
1901 (void) QueryMagickColor("#000000",&black_point,exception);
1902 if (isalpha((int) token[0]) || (token[0] == '#'))
1903 GetMagickToken(p,&p,token);
1904 if (*token == '\0')
1905 white_point=black_point; /* set everything to that color */
1906 else
1907 {
1908 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1909 GetMagickToken(p,&p,token); /* Get white point color. */
1910 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1911 (void) QueryMagickColor(token,&white_point,exception);
1912 else
1913 (void) QueryMagickColor("#ffffff",&white_point,exception);
1914 }
cristy490408a2011-07-07 14:42:05 +00001915 (void) LevelImageColors(*image,&black_point,&white_point,
1916 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001917 break;
1918 }
1919 if (LocaleCompare("linear-stretch",option+1) == 0)
1920 {
1921 double
1922 black_point,
1923 white_point;
1924
1925 MagickStatusType
1926 flags;
1927
1928 (void) SyncImageSettings(mogrify_info,*image);
1929 flags=ParseGeometry(argv[i+1],&geometry_info);
1930 black_point=geometry_info.rho;
1931 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1932 if ((flags & SigmaValue) != 0)
1933 white_point=geometry_info.sigma;
1934 if ((flags & PercentValue) != 0)
1935 {
1936 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1937 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1938 }
1939 if ((flags & SigmaValue) == 0)
1940 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1941 black_point;
1942 (void) LinearStretchImage(*image,black_point,white_point);
1943 InheritException(exception,&(*image)->exception);
1944 break;
1945 }
1946 if (LocaleCompare("linewidth",option+1) == 0)
1947 {
cristyc1acd842011-05-19 23:05:47 +00001948 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1949 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001950 break;
1951 }
1952 if (LocaleCompare("liquid-rescale",option+1) == 0)
1953 {
1954 /*
1955 Liquid rescale image.
1956 */
1957 (void) SyncImageSettings(mogrify_info,*image);
1958 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1959 if ((flags & XValue) == 0)
1960 geometry.x=1;
1961 if ((flags & YValue) == 0)
1962 geometry.y=0;
1963 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1964 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1965 break;
1966 }
1967 if (LocaleCompare("lowlight-color",option+1) == 0)
1968 {
1969 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1970 break;
1971 }
1972 break;
1973 }
1974 case 'm':
1975 {
1976 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001977 {
cristy3ed852e2009-09-05 21:47:34 +00001978 Image
anthonydf8ebac2011-04-27 09:03:19 +00001979 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001980
anthonydf8ebac2011-04-27 09:03:19 +00001981 /*
1982 Transform image colors to match this set of colors.
1983 */
1984 (void) SyncImageSettings(mogrify_info,*image);
1985 if (*option == '+')
1986 break;
1987 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1988 if (remap_image == (Image *) NULL)
1989 break;
1990 (void) RemapImage(quantize_info,*image,remap_image);
1991 InheritException(exception,&(*image)->exception);
1992 remap_image=DestroyImage(remap_image);
1993 break;
1994 }
1995 if (LocaleCompare("mask",option+1) == 0)
1996 {
1997 Image
1998 *mask;
1999
2000 (void) SyncImageSettings(mogrify_info,*image);
2001 if (*option == '+')
2002 {
2003 /*
2004 Remove a mask.
2005 */
2006 (void) SetImageMask(*image,(Image *) NULL);
2007 InheritException(exception,&(*image)->exception);
2008 break;
2009 }
2010 /*
2011 Set the image mask.
2012 */
2013 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2014 if (mask == (Image *) NULL)
2015 break;
2016 (void) SetImageMask(*image,mask);
2017 mask=DestroyImage(mask);
2018 InheritException(exception,&(*image)->exception);
2019 break;
2020 }
2021 if (LocaleCompare("matte",option+1) == 0)
2022 {
2023 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2024 SetAlphaChannel : DeactivateAlphaChannel );
2025 InheritException(exception,&(*image)->exception);
2026 break;
2027 }
2028 if (LocaleCompare("median",option+1) == 0)
2029 {
2030 /*
2031 Median filter image.
2032 */
2033 (void) SyncImageSettings(mogrify_info,*image);
2034 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002035 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2036 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002037 break;
2038 }
2039 if (LocaleCompare("mode",option+1) == 0)
2040 {
2041 /*
2042 Mode image.
2043 */
2044 (void) SyncImageSettings(mogrify_info,*image);
2045 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002046 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2047 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002048 break;
2049 }
2050 if (LocaleCompare("modulate",option+1) == 0)
2051 {
2052 (void) SyncImageSettings(mogrify_info,*image);
2053 (void) ModulateImage(*image,argv[i+1]);
2054 InheritException(exception,&(*image)->exception);
2055 break;
2056 }
2057 if (LocaleCompare("monitor",option+1) == 0)
2058 {
2059 if (*option == '+')
2060 {
2061 (void) SetImageProgressMonitor(*image,
2062 (MagickProgressMonitor) NULL,(void *) NULL);
2063 break;
2064 }
2065 (void) SetImageProgressMonitor(*image,MonitorProgress,
2066 (void *) NULL);
2067 break;
2068 }
2069 if (LocaleCompare("monochrome",option+1) == 0)
2070 {
2071 (void) SyncImageSettings(mogrify_info,*image);
2072 (void) SetImageType(*image,BilevelType);
2073 InheritException(exception,&(*image)->exception);
2074 break;
2075 }
2076 if (LocaleCompare("morphology",option+1) == 0)
2077 {
2078 char
2079 token[MaxTextExtent];
2080
2081 const char
2082 *p;
2083
2084 KernelInfo
2085 *kernel;
2086
2087 MorphologyMethod
2088 method;
2089
2090 ssize_t
2091 iterations;
2092
2093 /*
2094 Morphological Image Operation
2095 */
2096 (void) SyncImageSettings(mogrify_info,*image);
2097 p=argv[i+1];
2098 GetMagickToken(p,&p,token);
2099 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2100 MagickFalse,token);
2101 iterations=1L;
2102 GetMagickToken(p,&p,token);
2103 if ((*p == ':') || (*p == ','))
2104 GetMagickToken(p,&p,token);
2105 if ((*p != '\0'))
2106 iterations=(ssize_t) StringToLong(p);
2107 kernel=AcquireKernelInfo(argv[i+2]);
2108 if (kernel == (KernelInfo *) NULL)
2109 {
2110 (void) ThrowMagickException(exception,GetMagickModule(),
2111 OptionError,"UnabletoParseKernel","morphology");
2112 status=MagickFalse;
2113 break;
2114 }
cristyf4ad9df2011-07-08 16:49:03 +00002115 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2116 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002117 kernel=DestroyKernelInfo(kernel);
2118 break;
2119 }
2120 if (LocaleCompare("motion-blur",option+1) == 0)
2121 {
2122 /*
2123 Motion blur image.
2124 */
2125 (void) SyncImageSettings(mogrify_info,*image);
2126 flags=ParseGeometry(argv[i+1],&geometry_info);
2127 if ((flags & SigmaValue) == 0)
2128 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002129 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2130 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002131 break;
2132 }
2133 break;
2134 }
2135 case 'n':
2136 {
2137 if (LocaleCompare("negate",option+1) == 0)
2138 {
2139 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002140 (void) NegateImage(*image,*option == '+' ? MagickTrue :
2141 MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00002142 InheritException(exception,&(*image)->exception);
2143 break;
2144 }
2145 if (LocaleCompare("noise",option+1) == 0)
2146 {
2147 (void) SyncImageSettings(mogrify_info,*image);
2148 if (*option == '-')
2149 {
2150 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002151 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2152 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002153 }
2154 else
2155 {
2156 NoiseType
2157 noise;
2158
2159 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2160 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002161 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002162 }
2163 break;
2164 }
2165 if (LocaleCompare("normalize",option+1) == 0)
2166 {
2167 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002168 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002169 InheritException(exception,&(*image)->exception);
2170 break;
2171 }
2172 break;
2173 }
2174 case 'o':
2175 {
2176 if (LocaleCompare("opaque",option+1) == 0)
2177 {
cristy4c08aed2011-07-01 19:47:50 +00002178 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002179 target;
2180
2181 (void) SyncImageSettings(mogrify_info,*image);
2182 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002183 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2184 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002185 break;
2186 }
2187 if (LocaleCompare("ordered-dither",option+1) == 0)
2188 {
2189 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002190 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002191 break;
2192 }
2193 break;
2194 }
2195 case 'p':
2196 {
2197 if (LocaleCompare("paint",option+1) == 0)
2198 {
anthonydf8ebac2011-04-27 09:03:19 +00002199 (void) SyncImageSettings(mogrify_info,*image);
2200 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002201 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002202 break;
2203 }
2204 if (LocaleCompare("pen",option+1) == 0)
2205 {
2206 if (*option == '+')
2207 {
2208 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2209 break;
2210 }
2211 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2212 break;
2213 }
2214 if (LocaleCompare("pointsize",option+1) == 0)
2215 {
2216 if (*option == '+')
2217 (void) ParseGeometry("12",&geometry_info);
2218 else
2219 (void) ParseGeometry(argv[i+1],&geometry_info);
2220 draw_info->pointsize=geometry_info.rho;
2221 break;
2222 }
2223 if (LocaleCompare("polaroid",option+1) == 0)
2224 {
2225 double
2226 angle;
2227
2228 RandomInfo
2229 *random_info;
2230
2231 /*
2232 Simulate a Polaroid picture.
2233 */
2234 (void) SyncImageSettings(mogrify_info,*image);
2235 random_info=AcquireRandomInfo();
2236 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2237 random_info=DestroyRandomInfo(random_info);
2238 if (*option == '-')
2239 {
2240 SetGeometryInfo(&geometry_info);
2241 flags=ParseGeometry(argv[i+1],&geometry_info);
2242 angle=geometry_info.rho;
2243 }
2244 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2245 break;
2246 }
2247 if (LocaleCompare("posterize",option+1) == 0)
2248 {
2249 /*
2250 Posterize image.
2251 */
2252 (void) SyncImageSettings(mogrify_info,*image);
2253 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2254 quantize_info->dither);
2255 InheritException(exception,&(*image)->exception);
2256 break;
2257 }
2258 if (LocaleCompare("preview",option+1) == 0)
2259 {
2260 PreviewType
2261 preview_type;
2262
2263 /*
2264 Preview image.
2265 */
2266 (void) SyncImageSettings(mogrify_info,*image);
2267 if (*option == '+')
2268 preview_type=UndefinedPreview;
2269 else
2270 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2271 MagickFalse,argv[i+1]);
2272 mogrify_image=PreviewImage(*image,preview_type,exception);
2273 break;
2274 }
2275 if (LocaleCompare("profile",option+1) == 0)
2276 {
2277 const char
2278 *name;
2279
2280 const StringInfo
2281 *profile;
2282
2283 Image
2284 *profile_image;
2285
2286 ImageInfo
2287 *profile_info;
2288
2289 (void) SyncImageSettings(mogrify_info,*image);
2290 if (*option == '+')
2291 {
2292 /*
2293 Remove a profile from the image.
2294 */
2295 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2296 NULL,0,MagickTrue);
2297 InheritException(exception,&(*image)->exception);
2298 break;
2299 }
2300 /*
2301 Associate a profile with the image.
2302 */
2303 profile_info=CloneImageInfo(mogrify_info);
2304 profile=GetImageProfile(*image,"iptc");
2305 if (profile != (StringInfo *) NULL)
2306 profile_info->profile=(void *) CloneStringInfo(profile);
2307 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2308 profile_info=DestroyImageInfo(profile_info);
2309 if (profile_image == (Image *) NULL)
2310 {
2311 StringInfo
2312 *profile;
2313
2314 profile_info=CloneImageInfo(mogrify_info);
2315 (void) CopyMagickString(profile_info->filename,argv[i+1],
2316 MaxTextExtent);
2317 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2318 if (profile != (StringInfo *) NULL)
2319 {
2320 (void) ProfileImage(*image,profile_info->magick,
2321 GetStringInfoDatum(profile),(size_t)
2322 GetStringInfoLength(profile),MagickFalse);
2323 profile=DestroyStringInfo(profile);
2324 }
2325 profile_info=DestroyImageInfo(profile_info);
2326 break;
2327 }
2328 ResetImageProfileIterator(profile_image);
2329 name=GetNextImageProfile(profile_image);
2330 while (name != (const char *) NULL)
2331 {
2332 profile=GetImageProfile(profile_image,name);
2333 if (profile != (StringInfo *) NULL)
2334 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2335 (size_t) GetStringInfoLength(profile),MagickFalse);
2336 name=GetNextImageProfile(profile_image);
2337 }
2338 profile_image=DestroyImage(profile_image);
2339 break;
2340 }
2341 break;
2342 }
2343 case 'q':
2344 {
2345 if (LocaleCompare("quantize",option+1) == 0)
2346 {
2347 if (*option == '+')
2348 {
2349 quantize_info->colorspace=UndefinedColorspace;
2350 break;
2351 }
2352 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2353 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2354 break;
2355 }
2356 break;
2357 }
2358 case 'r':
2359 {
2360 if (LocaleCompare("radial-blur",option+1) == 0)
2361 {
2362 /*
2363 Radial blur image.
2364 */
2365 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002366 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2367 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002368 break;
2369 }
2370 if (LocaleCompare("raise",option+1) == 0)
2371 {
2372 /*
2373 Surround image with a raise of solid color.
2374 */
2375 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2376 if ((flags & SigmaValue) == 0)
2377 geometry.height=geometry.width;
2378 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2379 MagickFalse);
2380 InheritException(exception,&(*image)->exception);
2381 break;
2382 }
2383 if (LocaleCompare("random-threshold",option+1) == 0)
2384 {
2385 /*
2386 Threshold image.
2387 */
2388 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002389 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002390 break;
2391 }
2392 if (LocaleCompare("recolor",option+1) == 0)
2393 {
2394 KernelInfo
2395 *kernel;
2396
2397 (void) SyncImageSettings(mogrify_info,*image);
2398 kernel=AcquireKernelInfo(argv[i+1]);
2399 if (kernel == (KernelInfo *) NULL)
2400 break;
2401 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2402 kernel=DestroyKernelInfo(kernel);
2403 break;
2404 }
2405 if (LocaleCompare("region",option+1) == 0)
2406 {
2407 (void) SyncImageSettings(mogrify_info,*image);
2408 if (region_image != (Image *) NULL)
2409 {
2410 /*
2411 Composite region.
2412 */
2413 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002414 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2415 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002416 InheritException(exception,&region_image->exception);
2417 *image=DestroyImage(*image);
2418 *image=region_image;
2419 region_image = (Image *) NULL;
2420 }
2421 if (*option == '+')
2422 break;
2423 /*
2424 Apply transformations to a selected region of the image.
2425 */
cristy3ed852e2009-09-05 21:47:34 +00002426 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2427 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002428 mogrify_image=CropImage(*image,&region_geometry,exception);
2429 if (mogrify_image == (Image *) NULL)
2430 break;
2431 region_image=(*image);
2432 *image=mogrify_image;
2433 mogrify_image=(Image *) NULL;
2434 break;
cristy3ed852e2009-09-05 21:47:34 +00002435 }
anthonydf8ebac2011-04-27 09:03:19 +00002436 if (LocaleCompare("render",option+1) == 0)
2437 {
2438 (void) SyncImageSettings(mogrify_info,*image);
2439 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2440 break;
2441 }
2442 if (LocaleCompare("remap",option+1) == 0)
2443 {
2444 Image
2445 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002446
anthonydf8ebac2011-04-27 09:03:19 +00002447 /*
2448 Transform image colors to match this set of colors.
2449 */
2450 (void) SyncImageSettings(mogrify_info,*image);
2451 if (*option == '+')
2452 break;
2453 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2454 if (remap_image == (Image *) NULL)
2455 break;
2456 (void) RemapImage(quantize_info,*image,remap_image);
2457 InheritException(exception,&(*image)->exception);
2458 remap_image=DestroyImage(remap_image);
2459 break;
2460 }
2461 if (LocaleCompare("repage",option+1) == 0)
2462 {
2463 if (*option == '+')
2464 {
2465 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2466 break;
2467 }
2468 (void) ResetImagePage(*image,argv[i+1]);
2469 InheritException(exception,&(*image)->exception);
2470 break;
2471 }
2472 if (LocaleCompare("resample",option+1) == 0)
2473 {
2474 /*
2475 Resample image.
2476 */
2477 (void) SyncImageSettings(mogrify_info,*image);
2478 flags=ParseGeometry(argv[i+1],&geometry_info);
2479 if ((flags & SigmaValue) == 0)
2480 geometry_info.sigma=geometry_info.rho;
2481 mogrify_image=ResampleImage(*image,geometry_info.rho,
2482 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2483 break;
2484 }
2485 if (LocaleCompare("resize",option+1) == 0)
2486 {
2487 /*
2488 Resize image.
2489 */
2490 (void) SyncImageSettings(mogrify_info,*image);
2491 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2492 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2493 (*image)->filter,(*image)->blur,exception);
2494 break;
2495 }
2496 if (LocaleCompare("roll",option+1) == 0)
2497 {
2498 /*
2499 Roll image.
2500 */
2501 (void) SyncImageSettings(mogrify_info,*image);
2502 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2503 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2504 break;
2505 }
2506 if (LocaleCompare("rotate",option+1) == 0)
2507 {
2508 char
2509 *geometry;
2510
2511 /*
2512 Check for conditional image rotation.
2513 */
2514 (void) SyncImageSettings(mogrify_info,*image);
2515 if (strchr(argv[i+1],'>') != (char *) NULL)
2516 if ((*image)->columns <= (*image)->rows)
2517 break;
2518 if (strchr(argv[i+1],'<') != (char *) NULL)
2519 if ((*image)->columns >= (*image)->rows)
2520 break;
2521 /*
2522 Rotate image.
2523 */
2524 geometry=ConstantString(argv[i+1]);
2525 (void) SubstituteString(&geometry,">","");
2526 (void) SubstituteString(&geometry,"<","");
2527 (void) ParseGeometry(geometry,&geometry_info);
2528 geometry=DestroyString(geometry);
2529 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2530 break;
2531 }
2532 break;
2533 }
2534 case 's':
2535 {
2536 if (LocaleCompare("sample",option+1) == 0)
2537 {
2538 /*
2539 Sample image with pixel replication.
2540 */
2541 (void) SyncImageSettings(mogrify_info,*image);
2542 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2543 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2544 exception);
2545 break;
2546 }
2547 if (LocaleCompare("scale",option+1) == 0)
2548 {
2549 /*
2550 Resize image.
2551 */
2552 (void) SyncImageSettings(mogrify_info,*image);
2553 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2554 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2555 exception);
2556 break;
2557 }
2558 if (LocaleCompare("selective-blur",option+1) == 0)
2559 {
2560 /*
2561 Selectively blur pixels within a contrast threshold.
2562 */
2563 (void) SyncImageSettings(mogrify_info,*image);
2564 flags=ParseGeometry(argv[i+1],&geometry_info);
2565 if ((flags & PercentValue) != 0)
2566 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002567 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2568 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002569 break;
2570 }
2571 if (LocaleCompare("separate",option+1) == 0)
2572 {
2573 /*
2574 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002575 */
2576 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002577 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002578 break;
2579 }
2580 if (LocaleCompare("sepia-tone",option+1) == 0)
2581 {
2582 double
2583 threshold;
2584
2585 /*
2586 Sepia-tone image.
2587 */
2588 (void) SyncImageSettings(mogrify_info,*image);
2589 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2590 mogrify_image=SepiaToneImage(*image,threshold,exception);
2591 break;
2592 }
2593 if (LocaleCompare("segment",option+1) == 0)
2594 {
2595 /*
2596 Segment image.
2597 */
2598 (void) SyncImageSettings(mogrify_info,*image);
2599 flags=ParseGeometry(argv[i+1],&geometry_info);
2600 if ((flags & SigmaValue) == 0)
2601 geometry_info.sigma=1.0;
2602 (void) SegmentImage(*image,(*image)->colorspace,
2603 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2604 InheritException(exception,&(*image)->exception);
2605 break;
2606 }
2607 if (LocaleCompare("set",option+1) == 0)
2608 {
2609 char
2610 *value;
2611
2612 /*
2613 Set image option.
2614 */
2615 if (*option == '+')
2616 {
2617 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2618 (void) DeleteImageRegistry(argv[i+1]+9);
2619 else
2620 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2621 {
2622 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2623 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2624 }
2625 else
2626 (void) DeleteImageProperty(*image,argv[i+1]);
2627 break;
2628 }
2629 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2630 if (value == (char *) NULL)
2631 break;
2632 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2633 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2634 exception);
2635 else
2636 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2637 {
2638 (void) SetImageOption(image_info,argv[i+1]+7,value);
2639 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2640 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2641 }
2642 else
2643 (void) SetImageProperty(*image,argv[i+1],value);
2644 value=DestroyString(value);
2645 break;
2646 }
2647 if (LocaleCompare("shade",option+1) == 0)
2648 {
2649 /*
2650 Shade image.
2651 */
2652 (void) SyncImageSettings(mogrify_info,*image);
2653 flags=ParseGeometry(argv[i+1],&geometry_info);
2654 if ((flags & SigmaValue) == 0)
2655 geometry_info.sigma=1.0;
2656 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2657 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2658 break;
2659 }
2660 if (LocaleCompare("shadow",option+1) == 0)
2661 {
2662 /*
2663 Shadow image.
2664 */
2665 (void) SyncImageSettings(mogrify_info,*image);
2666 flags=ParseGeometry(argv[i+1],&geometry_info);
2667 if ((flags & SigmaValue) == 0)
2668 geometry_info.sigma=1.0;
2669 if ((flags & XiValue) == 0)
2670 geometry_info.xi=4.0;
2671 if ((flags & PsiValue) == 0)
2672 geometry_info.psi=4.0;
2673 mogrify_image=ShadowImage(*image,geometry_info.rho,
2674 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2675 ceil(geometry_info.psi-0.5),exception);
2676 break;
2677 }
2678 if (LocaleCompare("sharpen",option+1) == 0)
2679 {
2680 /*
2681 Sharpen image.
2682 */
2683 (void) SyncImageSettings(mogrify_info,*image);
2684 flags=ParseGeometry(argv[i+1],&geometry_info);
2685 if ((flags & SigmaValue) == 0)
2686 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002687 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002688 geometry_info.sigma,exception);
2689 break;
2690 }
2691 if (LocaleCompare("shave",option+1) == 0)
2692 {
2693 /*
2694 Shave the image edges.
2695 */
2696 (void) SyncImageSettings(mogrify_info,*image);
2697 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2698 mogrify_image=ShaveImage(*image,&geometry,exception);
2699 break;
2700 }
2701 if (LocaleCompare("shear",option+1) == 0)
2702 {
2703 /*
2704 Shear image.
2705 */
2706 (void) SyncImageSettings(mogrify_info,*image);
2707 flags=ParseGeometry(argv[i+1],&geometry_info);
2708 if ((flags & SigmaValue) == 0)
2709 geometry_info.sigma=geometry_info.rho;
2710 mogrify_image=ShearImage(*image,geometry_info.rho,
2711 geometry_info.sigma,exception);
2712 break;
2713 }
2714 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2715 {
2716 /*
2717 Sigmoidal non-linearity contrast control.
2718 */
2719 (void) SyncImageSettings(mogrify_info,*image);
2720 flags=ParseGeometry(argv[i+1],&geometry_info);
2721 if ((flags & SigmaValue) == 0)
2722 geometry_info.sigma=(double) QuantumRange/2.0;
2723 if ((flags & PercentValue) != 0)
2724 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2725 100.0;
cristy9ee60942011-07-06 14:54:38 +00002726 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2727 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002728 InheritException(exception,&(*image)->exception);
2729 break;
2730 }
2731 if (LocaleCompare("sketch",option+1) == 0)
2732 {
2733 /*
2734 Sketch image.
2735 */
2736 (void) SyncImageSettings(mogrify_info,*image);
2737 flags=ParseGeometry(argv[i+1],&geometry_info);
2738 if ((flags & SigmaValue) == 0)
2739 geometry_info.sigma=1.0;
2740 mogrify_image=SketchImage(*image,geometry_info.rho,
2741 geometry_info.sigma,geometry_info.xi,exception);
2742 break;
2743 }
2744 if (LocaleCompare("solarize",option+1) == 0)
2745 {
2746 double
2747 threshold;
2748
2749 (void) SyncImageSettings(mogrify_info,*image);
2750 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2751 (void) SolarizeImage(*image,threshold);
2752 InheritException(exception,&(*image)->exception);
2753 break;
2754 }
2755 if (LocaleCompare("sparse-color",option+1) == 0)
2756 {
2757 SparseColorMethod
2758 method;
2759
2760 char
2761 *arguments;
2762
2763 /*
2764 Sparse Color Interpolated Gradient
2765 */
2766 (void) SyncImageSettings(mogrify_info,*image);
2767 method=(SparseColorMethod) ParseCommandOption(
2768 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2769 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2770 InheritException(exception,&(*image)->exception);
2771 if (arguments == (char *) NULL)
2772 break;
cristy3884f692011-07-08 18:00:18 +00002773 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002774 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2775 arguments=DestroyString(arguments);
2776 break;
2777 }
2778 if (LocaleCompare("splice",option+1) == 0)
2779 {
2780 /*
2781 Splice a solid color into the image.
2782 */
2783 (void) SyncImageSettings(mogrify_info,*image);
2784 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2785 mogrify_image=SpliceImage(*image,&geometry,exception);
2786 break;
2787 }
2788 if (LocaleCompare("spread",option+1) == 0)
2789 {
2790 /*
2791 Spread an image.
2792 */
2793 (void) SyncImageSettings(mogrify_info,*image);
2794 (void) ParseGeometry(argv[i+1],&geometry_info);
2795 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2796 break;
2797 }
2798 if (LocaleCompare("statistic",option+1) == 0)
2799 {
2800 StatisticType
2801 type;
2802
2803 (void) SyncImageSettings(mogrify_info,*image);
2804 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2805 MagickFalse,argv[i+1]);
2806 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002807 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2808 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002809 break;
2810 }
2811 if (LocaleCompare("stretch",option+1) == 0)
2812 {
2813 if (*option == '+')
2814 {
2815 draw_info->stretch=UndefinedStretch;
2816 break;
2817 }
2818 draw_info->stretch=(StretchType) ParseCommandOption(
2819 MagickStretchOptions,MagickFalse,argv[i+1]);
2820 break;
2821 }
2822 if (LocaleCompare("strip",option+1) == 0)
2823 {
2824 /*
2825 Strip image of profiles and comments.
2826 */
2827 (void) SyncImageSettings(mogrify_info,*image);
2828 (void) StripImage(*image);
2829 InheritException(exception,&(*image)->exception);
2830 break;
2831 }
2832 if (LocaleCompare("stroke",option+1) == 0)
2833 {
2834 ExceptionInfo
2835 *sans;
2836
2837 if (*option == '+')
2838 {
2839 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2840 if (draw_info->stroke_pattern != (Image *) NULL)
2841 draw_info->stroke_pattern=DestroyImage(
2842 draw_info->stroke_pattern);
2843 break;
2844 }
2845 sans=AcquireExceptionInfo();
2846 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2847 sans=DestroyExceptionInfo(sans);
2848 if (status == MagickFalse)
2849 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2850 exception);
2851 break;
2852 }
2853 if (LocaleCompare("strokewidth",option+1) == 0)
2854 {
cristyc1acd842011-05-19 23:05:47 +00002855 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2856 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002857 break;
2858 }
2859 if (LocaleCompare("style",option+1) == 0)
2860 {
2861 if (*option == '+')
2862 {
2863 draw_info->style=UndefinedStyle;
2864 break;
2865 }
2866 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2867 MagickFalse,argv[i+1]);
2868 break;
2869 }
2870 if (LocaleCompare("swirl",option+1) == 0)
2871 {
2872 /*
2873 Swirl image.
2874 */
2875 (void) SyncImageSettings(mogrify_info,*image);
2876 (void) ParseGeometry(argv[i+1],&geometry_info);
2877 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2878 break;
2879 }
2880 break;
2881 }
2882 case 't':
2883 {
2884 if (LocaleCompare("threshold",option+1) == 0)
2885 {
2886 double
2887 threshold;
2888
2889 /*
2890 Threshold image.
2891 */
2892 (void) SyncImageSettings(mogrify_info,*image);
2893 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002894 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002895 else
2896 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002897 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002898 InheritException(exception,&(*image)->exception);
2899 break;
2900 }
2901 if (LocaleCompare("thumbnail",option+1) == 0)
2902 {
2903 /*
2904 Thumbnail image.
2905 */
2906 (void) SyncImageSettings(mogrify_info,*image);
2907 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2908 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2909 exception);
2910 break;
2911 }
2912 if (LocaleCompare("tile",option+1) == 0)
2913 {
2914 if (*option == '+')
2915 {
2916 if (draw_info->fill_pattern != (Image *) NULL)
2917 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2918 break;
2919 }
2920 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2921 exception);
2922 break;
2923 }
2924 if (LocaleCompare("tint",option+1) == 0)
2925 {
2926 /*
2927 Tint the image.
2928 */
2929 (void) SyncImageSettings(mogrify_info,*image);
2930 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2931 break;
2932 }
2933 if (LocaleCompare("transform",option+1) == 0)
2934 {
2935 /*
2936 Affine transform image.
2937 */
2938 (void) SyncImageSettings(mogrify_info,*image);
2939 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2940 exception);
2941 break;
2942 }
2943 if (LocaleCompare("transparent",option+1) == 0)
2944 {
cristy4c08aed2011-07-01 19:47:50 +00002945 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002946 target;
2947
2948 (void) SyncImageSettings(mogrify_info,*image);
2949 (void) QueryMagickColor(argv[i+1],&target,exception);
2950 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002951 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002952 InheritException(exception,&(*image)->exception);
2953 break;
2954 }
2955 if (LocaleCompare("transpose",option+1) == 0)
2956 {
2957 /*
2958 Transpose image scanlines.
2959 */
2960 (void) SyncImageSettings(mogrify_info,*image);
2961 mogrify_image=TransposeImage(*image,exception);
2962 break;
2963 }
2964 if (LocaleCompare("transverse",option+1) == 0)
2965 {
2966 /*
2967 Transverse image scanlines.
2968 */
2969 (void) SyncImageSettings(mogrify_info,*image);
2970 mogrify_image=TransverseImage(*image,exception);
2971 break;
2972 }
2973 if (LocaleCompare("treedepth",option+1) == 0)
2974 {
2975 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2976 break;
2977 }
2978 if (LocaleCompare("trim",option+1) == 0)
2979 {
2980 /*
2981 Trim image.
2982 */
2983 (void) SyncImageSettings(mogrify_info,*image);
2984 mogrify_image=TrimImage(*image,exception);
2985 break;
2986 }
2987 if (LocaleCompare("type",option+1) == 0)
2988 {
2989 ImageType
2990 type;
2991
2992 (void) SyncImageSettings(mogrify_info,*image);
2993 if (*option == '+')
2994 type=UndefinedType;
2995 else
2996 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2997 argv[i+1]);
2998 (*image)->type=UndefinedType;
2999 (void) SetImageType(*image,type);
3000 InheritException(exception,&(*image)->exception);
3001 break;
3002 }
3003 break;
3004 }
3005 case 'u':
3006 {
3007 if (LocaleCompare("undercolor",option+1) == 0)
3008 {
3009 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3010 exception);
3011 break;
3012 }
3013 if (LocaleCompare("unique",option+1) == 0)
3014 {
3015 if (*option == '+')
3016 {
3017 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3018 break;
3019 }
3020 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3021 (void) SetImageArtifact(*image,"verbose","true");
3022 break;
3023 }
3024 if (LocaleCompare("unique-colors",option+1) == 0)
3025 {
3026 /*
3027 Unique image colors.
3028 */
3029 (void) SyncImageSettings(mogrify_info,*image);
3030 mogrify_image=UniqueImageColors(*image,exception);
3031 break;
3032 }
3033 if (LocaleCompare("unsharp",option+1) == 0)
3034 {
3035 /*
3036 Unsharp mask image.
3037 */
3038 (void) SyncImageSettings(mogrify_info,*image);
3039 flags=ParseGeometry(argv[i+1],&geometry_info);
3040 if ((flags & SigmaValue) == 0)
3041 geometry_info.sigma=1.0;
3042 if ((flags & XiValue) == 0)
3043 geometry_info.xi=1.0;
3044 if ((flags & PsiValue) == 0)
3045 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003046 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3047 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003048 break;
3049 }
3050 break;
3051 }
3052 case 'v':
3053 {
3054 if (LocaleCompare("verbose",option+1) == 0)
3055 {
3056 (void) SetImageArtifact(*image,option+1,
3057 *option == '+' ? "false" : "true");
3058 break;
3059 }
3060 if (LocaleCompare("vignette",option+1) == 0)
3061 {
3062 /*
3063 Vignette image.
3064 */
3065 (void) SyncImageSettings(mogrify_info,*image);
3066 flags=ParseGeometry(argv[i+1],&geometry_info);
3067 if ((flags & SigmaValue) == 0)
3068 geometry_info.sigma=1.0;
3069 if ((flags & XiValue) == 0)
3070 geometry_info.xi=0.1*(*image)->columns;
3071 if ((flags & PsiValue) == 0)
3072 geometry_info.psi=0.1*(*image)->rows;
3073 mogrify_image=VignetteImage(*image,geometry_info.rho,
3074 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3075 ceil(geometry_info.psi-0.5),exception);
3076 break;
3077 }
3078 if (LocaleCompare("virtual-pixel",option+1) == 0)
3079 {
3080 if (*option == '+')
3081 {
3082 (void) SetImageVirtualPixelMethod(*image,
3083 UndefinedVirtualPixelMethod);
3084 break;
3085 }
3086 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3087 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3088 argv[i+1]));
3089 break;
3090 }
3091 break;
3092 }
3093 case 'w':
3094 {
3095 if (LocaleCompare("wave",option+1) == 0)
3096 {
3097 /*
3098 Wave image.
3099 */
3100 (void) SyncImageSettings(mogrify_info,*image);
3101 flags=ParseGeometry(argv[i+1],&geometry_info);
3102 if ((flags & SigmaValue) == 0)
3103 geometry_info.sigma=1.0;
3104 mogrify_image=WaveImage(*image,geometry_info.rho,
3105 geometry_info.sigma,exception);
3106 break;
3107 }
3108 if (LocaleCompare("weight",option+1) == 0)
3109 {
3110 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3111 if (LocaleCompare(argv[i+1],"all") == 0)
3112 draw_info->weight=0;
3113 if (LocaleCompare(argv[i+1],"bold") == 0)
3114 draw_info->weight=700;
3115 if (LocaleCompare(argv[i+1],"bolder") == 0)
3116 if (draw_info->weight <= 800)
3117 draw_info->weight+=100;
3118 if (LocaleCompare(argv[i+1],"lighter") == 0)
3119 if (draw_info->weight >= 100)
3120 draw_info->weight-=100;
3121 if (LocaleCompare(argv[i+1],"normal") == 0)
3122 draw_info->weight=400;
3123 break;
3124 }
3125 if (LocaleCompare("white-threshold",option+1) == 0)
3126 {
3127 /*
3128 White threshold image.
3129 */
3130 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003131 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003132 InheritException(exception,&(*image)->exception);
3133 break;
3134 }
3135 break;
3136 }
3137 default:
3138 break;
3139 }
3140 /*
3141 Replace current image with any image that was generated
3142 */
3143 if (mogrify_image != (Image *) NULL)
3144 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003145 i+=count;
3146 }
3147 if (region_image != (Image *) NULL)
3148 {
anthonydf8ebac2011-04-27 09:03:19 +00003149 /*
3150 Composite transformed region onto image.
3151 */
cristy6b3da3a2010-06-20 02:21:46 +00003152 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003153 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003154 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3155 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003156 InheritException(exception,&region_image->exception);
3157 *image=DestroyImage(*image);
3158 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003159 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003160 }
3161 /*
3162 Free resources.
3163 */
anthonydf8ebac2011-04-27 09:03:19 +00003164 quantize_info=DestroyQuantizeInfo(quantize_info);
3165 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003166 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003167 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003168 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003169 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003170}
3171
3172/*
3173%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3174% %
3175% %
3176% %
cristy5063d812010-10-19 16:28:10 +00003177+ 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 +00003178% %
3179% %
3180% %
3181%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3182%
3183% MogrifyImageCommand() transforms an image or a sequence of images. These
3184% transforms include image scaling, image rotation, color reduction, and
3185% others. The transmogrified image overwrites the original image.
3186%
3187% The format of the MogrifyImageCommand method is:
3188%
3189% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3190% const char **argv,char **metadata,ExceptionInfo *exception)
3191%
3192% A description of each parameter follows:
3193%
3194% o image_info: the image info.
3195%
3196% o argc: the number of elements in the argument vector.
3197%
3198% o argv: A text array containing the command line arguments.
3199%
3200% o metadata: any metadata is returned here.
3201%
3202% o exception: return any errors or warnings in this structure.
3203%
3204*/
3205
3206static MagickBooleanType MogrifyUsage(void)
3207{
3208 static const char
3209 *miscellaneous[]=
3210 {
3211 "-debug events display copious debugging information",
3212 "-help print program options",
3213 "-list type print a list of supported option arguments",
3214 "-log format format of debugging information",
3215 "-version print version information",
3216 (char *) NULL
3217 },
3218 *operators[]=
3219 {
3220 "-adaptive-blur geometry",
3221 " adaptively blur pixels; decrease effect near edges",
3222 "-adaptive-resize geometry",
3223 " adaptively resize image using 'mesh' interpolation",
3224 "-adaptive-sharpen geometry",
3225 " adaptively sharpen pixels; increase effect near edges",
3226 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3227 " transparent, extract, background, or shape",
3228 "-annotate geometry text",
3229 " annotate the image with text",
3230 "-auto-gamma automagically adjust gamma level of image",
3231 "-auto-level automagically adjust color levels of image",
3232 "-auto-orient automagically orient (rotate) image",
3233 "-bench iterations measure performance",
3234 "-black-threshold value",
3235 " force all pixels below the threshold into black",
3236 "-blue-shift simulate a scene at nighttime in the moonlight",
3237 "-blur geometry reduce image noise and reduce detail levels",
3238 "-border geometry surround image with a border of color",
3239 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003240 "-brightness-contrast geometry",
3241 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003242 "-cdl filename color correct with a color decision list",
3243 "-charcoal radius simulate a charcoal drawing",
3244 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003245 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003246 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003247 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003248 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003249 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003250 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003251 "-contrast enhance or reduce the image contrast",
3252 "-contrast-stretch geometry",
3253 " improve contrast by `stretching' the intensity range",
3254 "-convolve coefficients",
3255 " apply a convolution kernel to the image",
3256 "-cycle amount cycle the image colormap",
3257 "-decipher filename convert cipher pixels to plain pixels",
3258 "-deskew threshold straighten an image",
3259 "-despeckle reduce the speckles within an image",
3260 "-distort method args",
3261 " distort images according to given method ad args",
3262 "-draw string annotate the image with a graphic primitive",
3263 "-edge radius apply a filter to detect edges in the image",
3264 "-encipher filename convert plain pixels to cipher pixels",
3265 "-emboss radius emboss an image",
3266 "-enhance apply a digital filter to enhance a noisy image",
3267 "-equalize perform histogram equalization to an image",
3268 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003269 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003270 "-extent geometry set the image size",
3271 "-extract geometry extract area from image",
3272 "-fft implements the discrete Fourier transform (DFT)",
3273 "-flip flip image vertically",
3274 "-floodfill geometry color",
3275 " floodfill the image with color",
3276 "-flop flop image horizontally",
3277 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003278 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003279 " apply function over image values",
3280 "-gamma value level of gamma correction",
3281 "-gaussian-blur geometry",
3282 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003283 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003284 "-identify identify the format and characteristics of the image",
3285 "-ift implements the inverse discrete Fourier transform (DFT)",
3286 "-implode amount implode image pixels about the center",
3287 "-lat geometry local adaptive thresholding",
3288 "-layers method optimize, merge, or compare image layers",
3289 "-level value adjust the level of image contrast",
3290 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003291 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003292 "-linear-stretch geometry",
3293 " improve contrast by `stretching with saturation'",
3294 "-liquid-rescale geometry",
3295 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003296 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003297 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003298 "-modulate value vary the brightness, saturation, and hue",
3299 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003300 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003301 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003302 "-motion-blur geometry",
3303 " simulate motion blur",
3304 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003305 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-normalize transform image to span the full range of colors",
3307 "-opaque color change this color to the fill color",
3308 "-ordered-dither NxN",
3309 " add a noise pattern to the image with specific",
3310 " amplitudes",
3311 "-paint radius simulate an oil painting",
3312 "-polaroid angle simulate a Polaroid picture",
3313 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003314 "-profile filename add, delete, or apply an image profile",
3315 "-quantize colorspace reduce colors in this colorspace",
3316 "-radial-blur angle radial blur the image",
3317 "-raise value lighten/darken image edges to create a 3-D effect",
3318 "-random-threshold low,high",
3319 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003320 "-region geometry apply options to a portion of the image",
3321 "-render render vector graphics",
3322 "-repage geometry size and location of an image canvas",
3323 "-resample geometry change the resolution of an image",
3324 "-resize geometry resize the image",
3325 "-roll geometry roll an image vertically or horizontally",
3326 "-rotate degrees apply Paeth rotation to the image",
3327 "-sample geometry scale image with pixel sampling",
3328 "-scale geometry scale the image",
3329 "-segment values segment an image",
3330 "-selective-blur geometry",
3331 " selectively blur pixels within a contrast threshold",
3332 "-sepia-tone threshold",
3333 " simulate a sepia-toned photo",
3334 "-set property value set an image property",
3335 "-shade degrees shade the image using a distant light source",
3336 "-shadow geometry simulate an image shadow",
3337 "-sharpen geometry sharpen the image",
3338 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003339 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003340 "-sigmoidal-contrast geometry",
3341 " increase the contrast without saturating highlights or shadows",
3342 "-sketch geometry simulate a pencil sketch",
3343 "-solarize threshold negate all pixels above the threshold level",
3344 "-sparse-color method args",
3345 " fill in a image based on a few color points",
3346 "-splice geometry splice the background color into the image",
3347 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003348 "-statistic type radius",
3349 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003350 "-strip strip image of all profiles and comments",
3351 "-swirl degrees swirl image pixels about the center",
3352 "-threshold value threshold the image",
3353 "-thumbnail geometry create a thumbnail of the image",
3354 "-tile filename tile image when filling a graphic primitive",
3355 "-tint value tint the image with the fill color",
3356 "-transform affine transform image",
3357 "-transparent color make this color transparent within the image",
3358 "-transpose flip image vertically and rotate 90 degrees",
3359 "-transverse flop image horizontally and rotate 270 degrees",
3360 "-trim trim image edges",
3361 "-type type image type",
3362 "-unique-colors discard all but one of any pixel color",
3363 "-unsharp geometry sharpen the image",
3364 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003365 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003366 "-white-threshold value",
3367 " force all pixels above the threshold into white",
3368 (char *) NULL
3369 },
3370 *sequence_operators[]=
3371 {
cristy4285d782011-02-09 20:12:28 +00003372 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003373 "-clut apply a color lookup table to the image",
3374 "-coalesce merge a sequence of images",
3375 "-combine combine a sequence of images",
3376 "-composite composite image",
3377 "-crop geometry cut out a rectangular region of the image",
3378 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003379 "-evaluate-sequence operator",
3380 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-flatten flatten a sequence of images",
3382 "-fx expression apply mathematical expression to an image channel(s)",
3383 "-hald-clut apply a Hald color lookup table to the image",
3384 "-morph value morph an image sequence",
3385 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003386 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003387 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003388 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003389 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003390 "-write filename write images to this file",
3391 (char *) NULL
3392 },
3393 *settings[]=
3394 {
3395 "-adjoin join images into a single multi-image file",
3396 "-affine matrix affine transform matrix",
3397 "-alpha option activate, deactivate, reset, or set the alpha channel",
3398 "-antialias remove pixel-aliasing",
3399 "-authenticate password",
3400 " decipher image with this password",
3401 "-attenuate value lessen (or intensify) when adding noise to an image",
3402 "-background color background color",
3403 "-bias value add bias when convolving an image",
3404 "-black-point-compensation",
3405 " use black point compensation",
3406 "-blue-primary point chromaticity blue primary point",
3407 "-bordercolor color border color",
3408 "-caption string assign a caption to an image",
3409 "-channel type apply option to select image channels",
3410 "-colors value preferred number of colors in the image",
3411 "-colorspace type alternate image colorspace",
3412 "-comment string annotate image with comment",
3413 "-compose operator set image composite operator",
3414 "-compress type type of pixel compression when writing the image",
3415 "-define format:option",
3416 " define one or more image format options",
3417 "-delay value display the next image after pausing",
3418 "-density geometry horizontal and vertical density of the image",
3419 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003420 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003421 "-display server get image or font from this X server",
3422 "-dispose method layer disposal method",
3423 "-dither method apply error diffusion to image",
3424 "-encoding type text encoding type",
3425 "-endian type endianness (MSB or LSB) of the image",
3426 "-family name render text with this font family",
3427 "-fill color color to use when filling a graphic primitive",
3428 "-filter type use this filter when resizing an image",
3429 "-font name render text with this font",
3430 "-format \"string\" output formatted image characteristics",
3431 "-fuzz distance colors within this distance are considered equal",
3432 "-gravity type horizontal and vertical text placement",
3433 "-green-primary point chromaticity green primary point",
3434 "-intent type type of rendering intent when managing the image color",
3435 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003436 "-interline-spacing value",
3437 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003438 "-interpolate method pixel color interpolation method",
3439 "-interword-spacing value",
3440 " set the space between two words",
3441 "-kerning value set the space between two letters",
3442 "-label string assign a label to an image",
3443 "-limit type value pixel cache resource limit",
3444 "-loop iterations add Netscape loop extension to your GIF animation",
3445 "-mask filename associate a mask with the image",
3446 "-mattecolor color frame color",
3447 "-monitor monitor progress",
3448 "-orient type image orientation",
3449 "-page geometry size and location of an image canvas (setting)",
3450 "-ping efficiently determine image attributes",
3451 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003452 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003453 "-preview type image preview type",
3454 "-quality value JPEG/MIFF/PNG compression level",
3455 "-quiet suppress all warning messages",
3456 "-red-primary point chromaticity red primary point",
3457 "-regard-warnings pay attention to warning messages",
3458 "-remap filename transform image colors to match this set of colors",
3459 "-respect-parentheses settings remain in effect until parenthesis boundary",
3460 "-sampling-factor geometry",
3461 " horizontal and vertical sampling factor",
3462 "-scene value image scene number",
3463 "-seed value seed a new sequence of pseudo-random numbers",
3464 "-size geometry width and height of image",
3465 "-stretch type render text with this font stretch",
3466 "-stroke color graphic primitive stroke color",
3467 "-strokewidth value graphic primitive stroke width",
3468 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003469 "-synchronize synchronize image to storage device",
3470 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003471 "-texture filename name of texture to tile onto the image background",
3472 "-tile-offset geometry",
3473 " tile offset",
3474 "-treedepth value color tree depth",
3475 "-transparent-color color",
3476 " transparent color",
3477 "-undercolor color annotation bounding box color",
3478 "-units type the units of image resolution",
3479 "-verbose print detailed information about the image",
3480 "-view FlashPix viewing transforms",
3481 "-virtual-pixel method",
3482 " virtual pixel access method",
3483 "-weight type render text with this font weight",
3484 "-white-point point chromaticity white point",
3485 (char *) NULL
3486 },
3487 *stack_operators[]=
3488 {
anthonyb69c4b32011-03-23 04:37:44 +00003489 "-delete indexes delete the image from the image sequence",
3490 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003491 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003492 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003493 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003494 "-swap indexes swap two images in the image sequence",
3495 (char *) NULL
3496 };
3497
3498 const char
3499 **p;
3500
cristybb503372010-05-27 20:51:26 +00003501 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003502 (void) printf("Copyright: %s\n",GetMagickCopyright());
3503 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003504 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3505 GetClientName());
3506 (void) printf("\nImage Settings:\n");
3507 for (p=settings; *p != (char *) NULL; p++)
3508 (void) printf(" %s\n",*p);
3509 (void) printf("\nImage Operators:\n");
3510 for (p=operators; *p != (char *) NULL; p++)
3511 (void) printf(" %s\n",*p);
3512 (void) printf("\nImage Sequence Operators:\n");
3513 for (p=sequence_operators; *p != (char *) NULL; p++)
3514 (void) printf(" %s\n",*p);
3515 (void) printf("\nImage Stack Operators:\n");
3516 for (p=stack_operators; *p != (char *) NULL; p++)
3517 (void) printf(" %s\n",*p);
3518 (void) printf("\nMiscellaneous Options:\n");
3519 for (p=miscellaneous; *p != (char *) NULL; p++)
3520 (void) printf(" %s\n",*p);
3521 (void) printf(
3522 "\nBy default, the image format of `file' is determined by its magic\n");
3523 (void) printf(
3524 "number. To specify a particular image format, precede the filename\n");
3525 (void) printf(
3526 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3527 (void) printf(
3528 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3529 (void) printf("'-' for standard input or output.\n");
3530 return(MagickFalse);
3531}
3532
3533WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3534 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3535{
3536#define DestroyMogrify() \
3537{ \
3538 if (format != (char *) NULL) \
3539 format=DestroyString(format); \
3540 if (path != (char *) NULL) \
3541 path=DestroyString(path); \
3542 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003543 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003544 argv[i]=DestroyString(argv[i]); \
3545 argv=(char **) RelinquishMagickMemory(argv); \
3546}
3547#define ThrowMogrifyException(asperity,tag,option) \
3548{ \
3549 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3550 option); \
3551 DestroyMogrify(); \
3552 return(MagickFalse); \
3553}
3554#define ThrowMogrifyInvalidArgumentException(option,argument) \
3555{ \
3556 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3557 "InvalidArgument","`%s': %s",argument,option); \
3558 DestroyMogrify(); \
3559 return(MagickFalse); \
3560}
3561
3562 char
3563 *format,
3564 *option,
3565 *path;
3566
3567 Image
3568 *image;
3569
3570 ImageStack
3571 image_stack[MaxImageStackDepth+1];
3572
cristy3ed852e2009-09-05 21:47:34 +00003573 MagickBooleanType
3574 global_colormap;
3575
3576 MagickBooleanType
3577 fire,
cristyebbcfea2011-02-25 02:43:54 +00003578 pend,
3579 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003580
3581 MagickStatusType
3582 status;
3583
cristyebbcfea2011-02-25 02:43:54 +00003584 register ssize_t
3585 i;
3586
3587 ssize_t
3588 j,
3589 k;
3590
cristy3ed852e2009-09-05 21:47:34 +00003591 /*
3592 Set defaults.
3593 */
3594 assert(image_info != (ImageInfo *) NULL);
3595 assert(image_info->signature == MagickSignature);
3596 if (image_info->debug != MagickFalse)
3597 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3598 assert(exception != (ExceptionInfo *) NULL);
3599 if (argc == 2)
3600 {
3601 option=argv[1];
3602 if ((LocaleCompare("version",option+1) == 0) ||
3603 (LocaleCompare("-version",option+1) == 0))
3604 {
cristyb51dff52011-05-19 16:55:47 +00003605 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003606 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003607 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3608 GetMagickCopyright());
3609 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3610 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003611 return(MagickFalse);
3612 }
3613 }
3614 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003615 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003616 format=(char *) NULL;
3617 path=(char *) NULL;
3618 global_colormap=MagickFalse;
3619 k=0;
3620 j=1;
3621 NewImageStack();
3622 option=(char *) NULL;
3623 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003624 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003625 status=MagickTrue;
3626 /*
3627 Parse command line.
3628 */
3629 ReadCommandlLine(argc,&argv);
3630 status=ExpandFilenames(&argc,&argv);
3631 if (status == MagickFalse)
3632 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3633 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003634 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003635 {
3636 option=argv[i];
3637 if (LocaleCompare(option,"(") == 0)
3638 {
3639 FireImageStack(MagickFalse,MagickTrue,pend);
3640 if (k == MaxImageStackDepth)
3641 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3642 option);
3643 PushImageStack();
3644 continue;
3645 }
3646 if (LocaleCompare(option,")") == 0)
3647 {
3648 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3649 if (k == 0)
3650 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3651 PopImageStack();
3652 continue;
3653 }
cristy042ee782011-04-22 18:48:30 +00003654 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003655 {
3656 char
3657 backup_filename[MaxTextExtent],
3658 *filename;
3659
3660 Image
3661 *images;
3662
3663 /*
3664 Option is a file name: begin by reading image from specified file.
3665 */
3666 FireImageStack(MagickFalse,MagickFalse,pend);
3667 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003668 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003669 filename=argv[++i];
3670 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3671 images=ReadImages(image_info,exception);
3672 status&=(images != (Image *) NULL) &&
3673 (exception->severity < ErrorException);
3674 if (images == (Image *) NULL)
3675 continue;
cristydaa76602010-06-30 13:05:11 +00003676 if (format != (char *) NULL)
3677 (void) CopyMagickString(images->filename,images->magick_filename,
3678 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003679 if (path != (char *) NULL)
3680 {
3681 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003682 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003683 path,*DirectorySeparator,filename);
3684 }
3685 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003686 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003687 AppendImageStack(images);
3688 FinalizeImageSettings(image_info,image,MagickFalse);
3689 if (global_colormap != MagickFalse)
3690 {
3691 QuantizeInfo
3692 *quantize_info;
3693
3694 quantize_info=AcquireQuantizeInfo(image_info);
3695 (void) RemapImages(quantize_info,images,(Image *) NULL);
3696 quantize_info=DestroyQuantizeInfo(quantize_info);
3697 }
3698 *backup_filename='\0';
3699 if ((LocaleCompare(image->filename,"-") != 0) &&
3700 (IsPathWritable(image->filename) != MagickFalse))
3701 {
cristybb503372010-05-27 20:51:26 +00003702 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003703 i;
3704
3705 /*
3706 Rename image file as backup.
3707 */
3708 (void) CopyMagickString(backup_filename,image->filename,
3709 MaxTextExtent);
3710 for (i=0; i < 6; i++)
3711 {
3712 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3713 if (IsPathAccessible(backup_filename) == MagickFalse)
3714 break;
3715 }
3716 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3717 (rename(image->filename,backup_filename) != 0))
3718 *backup_filename='\0';
3719 }
3720 /*
3721 Write transmogrified image to disk.
3722 */
3723 image_info->synchronize=MagickTrue;
3724 status&=WriteImages(image_info,image,image->filename,exception);
3725 if ((status == MagickFalse) && (*backup_filename != '\0'))
3726 (void) remove(backup_filename);
3727 RemoveAllImageStack();
3728 continue;
3729 }
3730 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3731 switch (*(option+1))
3732 {
3733 case 'a':
3734 {
3735 if (LocaleCompare("adaptive-blur",option+1) == 0)
3736 {
3737 i++;
cristybb503372010-05-27 20:51:26 +00003738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003739 ThrowMogrifyException(OptionError,"MissingArgument",option);
3740 if (IsGeometry(argv[i]) == MagickFalse)
3741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3742 break;
3743 }
3744 if (LocaleCompare("adaptive-resize",option+1) == 0)
3745 {
3746 i++;
cristybb503372010-05-27 20:51:26 +00003747 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003748 ThrowMogrifyException(OptionError,"MissingArgument",option);
3749 if (IsGeometry(argv[i]) == MagickFalse)
3750 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3751 break;
3752 }
3753 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3754 {
3755 i++;
cristybb503372010-05-27 20:51:26 +00003756 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003757 ThrowMogrifyException(OptionError,"MissingArgument",option);
3758 if (IsGeometry(argv[i]) == MagickFalse)
3759 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3760 break;
3761 }
3762 if (LocaleCompare("affine",option+1) == 0)
3763 {
3764 if (*option == '+')
3765 break;
3766 i++;
cristybb503372010-05-27 20:51:26 +00003767 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003768 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003769 break;
3770 }
3771 if (LocaleCompare("alpha",option+1) == 0)
3772 {
cristybb503372010-05-27 20:51:26 +00003773 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003774 type;
3775
3776 if (*option == '+')
3777 break;
3778 i++;
cristybb503372010-05-27 20:51:26 +00003779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003780 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003781 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003782 if (type < 0)
3783 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3784 argv[i]);
3785 break;
3786 }
3787 if (LocaleCompare("annotate",option+1) == 0)
3788 {
3789 if (*option == '+')
3790 break;
3791 i++;
cristybb503372010-05-27 20:51:26 +00003792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003793 ThrowMogrifyException(OptionError,"MissingArgument",option);
3794 if (IsGeometry(argv[i]) == MagickFalse)
3795 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003797 ThrowMogrifyException(OptionError,"MissingArgument",option);
3798 i++;
3799 break;
3800 }
3801 if (LocaleCompare("antialias",option+1) == 0)
3802 break;
3803 if (LocaleCompare("append",option+1) == 0)
3804 break;
3805 if (LocaleCompare("attenuate",option+1) == 0)
3806 {
3807 if (*option == '+')
3808 break;
3809 i++;
cristybb503372010-05-27 20:51:26 +00003810 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003811 ThrowMogrifyException(OptionError,"MissingArgument",option);
3812 if (IsGeometry(argv[i]) == MagickFalse)
3813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3814 break;
3815 }
3816 if (LocaleCompare("authenticate",option+1) == 0)
3817 {
3818 if (*option == '+')
3819 break;
3820 i++;
cristybb503372010-05-27 20:51:26 +00003821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003822 ThrowMogrifyException(OptionError,"MissingArgument",option);
3823 break;
3824 }
3825 if (LocaleCompare("auto-gamma",option+1) == 0)
3826 break;
3827 if (LocaleCompare("auto-level",option+1) == 0)
3828 break;
3829 if (LocaleCompare("auto-orient",option+1) == 0)
3830 break;
3831 if (LocaleCompare("average",option+1) == 0)
3832 break;
3833 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3834 }
3835 case 'b':
3836 {
3837 if (LocaleCompare("background",option+1) == 0)
3838 {
3839 if (*option == '+')
3840 break;
3841 i++;
cristybb503372010-05-27 20:51:26 +00003842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003843 ThrowMogrifyException(OptionError,"MissingArgument",option);
3844 break;
3845 }
3846 if (LocaleCompare("bias",option+1) == 0)
3847 {
3848 if (*option == '+')
3849 break;
3850 i++;
cristybb503372010-05-27 20:51:26 +00003851 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003852 ThrowMogrifyException(OptionError,"MissingArgument",option);
3853 if (IsGeometry(argv[i]) == MagickFalse)
3854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3855 break;
3856 }
3857 if (LocaleCompare("black-point-compensation",option+1) == 0)
3858 break;
3859 if (LocaleCompare("black-threshold",option+1) == 0)
3860 {
3861 if (*option == '+')
3862 break;
3863 i++;
cristybb503372010-05-27 20:51:26 +00003864 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003865 ThrowMogrifyException(OptionError,"MissingArgument",option);
3866 if (IsGeometry(argv[i]) == MagickFalse)
3867 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3868 break;
3869 }
3870 if (LocaleCompare("blue-primary",option+1) == 0)
3871 {
3872 if (*option == '+')
3873 break;
3874 i++;
cristybb503372010-05-27 20:51:26 +00003875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003876 ThrowMogrifyException(OptionError,"MissingArgument",option);
3877 if (IsGeometry(argv[i]) == MagickFalse)
3878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3879 break;
3880 }
3881 if (LocaleCompare("blue-shift",option+1) == 0)
3882 {
3883 i++;
cristybb503372010-05-27 20:51:26 +00003884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003885 ThrowMogrifyException(OptionError,"MissingArgument",option);
3886 if (IsGeometry(argv[i]) == MagickFalse)
3887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3888 break;
3889 }
3890 if (LocaleCompare("blur",option+1) == 0)
3891 {
3892 i++;
cristybb503372010-05-27 20:51:26 +00003893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003894 ThrowMogrifyException(OptionError,"MissingArgument",option);
3895 if (IsGeometry(argv[i]) == MagickFalse)
3896 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3897 break;
3898 }
3899 if (LocaleCompare("border",option+1) == 0)
3900 {
3901 if (*option == '+')
3902 break;
3903 i++;
cristybb503372010-05-27 20:51:26 +00003904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003905 ThrowMogrifyException(OptionError,"MissingArgument",option);
3906 if (IsGeometry(argv[i]) == MagickFalse)
3907 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3908 break;
3909 }
3910 if (LocaleCompare("bordercolor",option+1) == 0)
3911 {
3912 if (*option == '+')
3913 break;
3914 i++;
cristybb503372010-05-27 20:51:26 +00003915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003916 ThrowMogrifyException(OptionError,"MissingArgument",option);
3917 break;
3918 }
3919 if (LocaleCompare("box",option+1) == 0)
3920 {
3921 if (*option == '+')
3922 break;
3923 i++;
cristybb503372010-05-27 20:51:26 +00003924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003925 ThrowMogrifyException(OptionError,"MissingArgument",option);
3926 break;
3927 }
cristya28d6b82010-01-11 20:03:47 +00003928 if (LocaleCompare("brightness-contrast",option+1) == 0)
3929 {
3930 i++;
cristybb503372010-05-27 20:51:26 +00003931 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003932 ThrowMogrifyException(OptionError,"MissingArgument",option);
3933 if (IsGeometry(argv[i]) == MagickFalse)
3934 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3935 break;
3936 }
cristy3ed852e2009-09-05 21:47:34 +00003937 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3938 }
3939 case 'c':
3940 {
3941 if (LocaleCompare("cache",option+1) == 0)
3942 {
3943 if (*option == '+')
3944 break;
3945 i++;
cristybb503372010-05-27 20:51:26 +00003946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003947 ThrowMogrifyException(OptionError,"MissingArgument",option);
3948 if (IsGeometry(argv[i]) == MagickFalse)
3949 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3950 break;
3951 }
3952 if (LocaleCompare("caption",option+1) == 0)
3953 {
3954 if (*option == '+')
3955 break;
3956 i++;
cristybb503372010-05-27 20:51:26 +00003957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003958 ThrowMogrifyException(OptionError,"MissingArgument",option);
3959 break;
3960 }
3961 if (LocaleCompare("channel",option+1) == 0)
3962 {
cristybb503372010-05-27 20:51:26 +00003963 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003964 channel;
3965
3966 if (*option == '+')
3967 break;
3968 i++;
cristybb503372010-05-27 20:51:26 +00003969 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003970 ThrowMogrifyException(OptionError,"MissingArgument",option);
3971 channel=ParseChannelOption(argv[i]);
3972 if (channel < 0)
3973 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3974 argv[i]);
3975 break;
3976 }
3977 if (LocaleCompare("cdl",option+1) == 0)
3978 {
3979 if (*option == '+')
3980 break;
3981 i++;
cristybb503372010-05-27 20:51:26 +00003982 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003983 ThrowMogrifyException(OptionError,"MissingArgument",option);
3984 break;
3985 }
3986 if (LocaleCompare("charcoal",option+1) == 0)
3987 {
3988 if (*option == '+')
3989 break;
3990 i++;
cristybb503372010-05-27 20:51:26 +00003991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003992 ThrowMogrifyException(OptionError,"MissingArgument",option);
3993 if (IsGeometry(argv[i]) == MagickFalse)
3994 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3995 break;
3996 }
3997 if (LocaleCompare("chop",option+1) == 0)
3998 {
3999 if (*option == '+')
4000 break;
4001 i++;
cristybb503372010-05-27 20:51:26 +00004002 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004003 ThrowMogrifyException(OptionError,"MissingArgument",option);
4004 if (IsGeometry(argv[i]) == MagickFalse)
4005 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4006 break;
4007 }
cristy1eb45dd2009-09-25 16:38:06 +00004008 if (LocaleCompare("clamp",option+1) == 0)
4009 break;
4010 if (LocaleCompare("clip",option+1) == 0)
4011 break;
cristy3ed852e2009-09-05 21:47:34 +00004012 if (LocaleCompare("clip-mask",option+1) == 0)
4013 {
4014 if (*option == '+')
4015 break;
4016 i++;
cristybb503372010-05-27 20:51:26 +00004017 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004018 ThrowMogrifyException(OptionError,"MissingArgument",option);
4019 break;
4020 }
4021 if (LocaleCompare("clut",option+1) == 0)
4022 break;
4023 if (LocaleCompare("coalesce",option+1) == 0)
4024 break;
4025 if (LocaleCompare("colorize",option+1) == 0)
4026 {
4027 if (*option == '+')
4028 break;
4029 i++;
cristybb503372010-05-27 20:51:26 +00004030 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004031 ThrowMogrifyException(OptionError,"MissingArgument",option);
4032 if (IsGeometry(argv[i]) == MagickFalse)
4033 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4034 break;
4035 }
cristye6365592010-04-02 17:31:23 +00004036 if (LocaleCompare("color-matrix",option+1) == 0)
4037 {
cristyb6bd4ad2010-08-08 01:12:27 +00004038 KernelInfo
4039 *kernel_info;
4040
cristye6365592010-04-02 17:31:23 +00004041 if (*option == '+')
4042 break;
4043 i++;
cristybb503372010-05-27 20:51:26 +00004044 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004045 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004046 kernel_info=AcquireKernelInfo(argv[i]);
4047 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004048 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004049 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004050 break;
4051 }
cristy3ed852e2009-09-05 21:47:34 +00004052 if (LocaleCompare("colors",option+1) == 0)
4053 {
4054 if (*option == '+')
4055 break;
4056 i++;
cristybb503372010-05-27 20:51:26 +00004057 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004058 ThrowMogrifyException(OptionError,"MissingArgument",option);
4059 if (IsGeometry(argv[i]) == MagickFalse)
4060 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4061 break;
4062 }
4063 if (LocaleCompare("colorspace",option+1) == 0)
4064 {
cristybb503372010-05-27 20:51:26 +00004065 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004066 colorspace;
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);
cristy042ee782011-04-22 18:48:30 +00004073 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004074 argv[i]);
4075 if (colorspace < 0)
4076 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4077 argv[i]);
4078 break;
4079 }
4080 if (LocaleCompare("combine",option+1) == 0)
4081 break;
4082 if (LocaleCompare("comment",option+1) == 0)
4083 {
4084 if (*option == '+')
4085 break;
4086 i++;
cristybb503372010-05-27 20:51:26 +00004087 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004088 ThrowMogrifyException(OptionError,"MissingArgument",option);
4089 break;
4090 }
4091 if (LocaleCompare("composite",option+1) == 0)
4092 break;
4093 if (LocaleCompare("compress",option+1) == 0)
4094 {
cristybb503372010-05-27 20:51:26 +00004095 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004096 compress;
4097
4098 if (*option == '+')
4099 break;
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);
cristy042ee782011-04-22 18:48:30 +00004103 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004104 argv[i]);
4105 if (compress < 0)
4106 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4107 argv[i]);
4108 break;
4109 }
cristy22879752009-10-25 23:55:40 +00004110 if (LocaleCompare("concurrent",option+1) == 0)
4111 break;
cristy3ed852e2009-09-05 21:47:34 +00004112 if (LocaleCompare("contrast",option+1) == 0)
4113 break;
4114 if (LocaleCompare("contrast-stretch",option+1) == 0)
4115 {
4116 i++;
cristybb503372010-05-27 20:51:26 +00004117 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004118 ThrowMogrifyException(OptionError,"MissingArgument",option);
4119 if (IsGeometry(argv[i]) == MagickFalse)
4120 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4121 break;
4122 }
4123 if (LocaleCompare("convolve",option+1) == 0)
4124 {
cristyb6bd4ad2010-08-08 01:12:27 +00004125 KernelInfo
4126 *kernel_info;
4127
cristy3ed852e2009-09-05 21:47:34 +00004128 if (*option == '+')
4129 break;
4130 i++;
cristybb503372010-05-27 20:51:26 +00004131 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004132 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004133 kernel_info=AcquireKernelInfo(argv[i]);
4134 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004136 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004137 break;
4138 }
4139 if (LocaleCompare("crop",option+1) == 0)
4140 {
4141 if (*option == '+')
4142 break;
4143 i++;
cristybb503372010-05-27 20:51:26 +00004144 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004145 ThrowMogrifyException(OptionError,"MissingArgument",option);
4146 if (IsGeometry(argv[i]) == MagickFalse)
4147 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4148 break;
4149 }
4150 if (LocaleCompare("cycle",option+1) == 0)
4151 {
4152 if (*option == '+')
4153 break;
4154 i++;
cristybb503372010-05-27 20:51:26 +00004155 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004156 ThrowMogrifyException(OptionError,"MissingArgument",option);
4157 if (IsGeometry(argv[i]) == MagickFalse)
4158 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4159 break;
4160 }
4161 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4162 }
4163 case 'd':
4164 {
4165 if (LocaleCompare("decipher",option+1) == 0)
4166 {
4167 if (*option == '+')
4168 break;
4169 i++;
cristybb503372010-05-27 20:51:26 +00004170 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004171 ThrowMogrifyException(OptionError,"MissingArgument",option);
4172 break;
4173 }
4174 if (LocaleCompare("deconstruct",option+1) == 0)
4175 break;
4176 if (LocaleCompare("debug",option+1) == 0)
4177 {
cristybb503372010-05-27 20:51:26 +00004178 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004179 event;
4180
4181 if (*option == '+')
4182 break;
4183 i++;
cristybb503372010-05-27 20:51:26 +00004184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004185 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004186 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004187 if (event < 0)
4188 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4189 argv[i]);
4190 (void) SetLogEventMask(argv[i]);
4191 break;
4192 }
4193 if (LocaleCompare("define",option+1) == 0)
4194 {
4195 i++;
cristybb503372010-05-27 20:51:26 +00004196 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004197 ThrowMogrifyException(OptionError,"MissingArgument",option);
4198 if (*option == '+')
4199 {
4200 const char
4201 *define;
4202
4203 define=GetImageOption(image_info,argv[i]);
4204 if (define == (const char *) NULL)
4205 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4206 break;
4207 }
4208 break;
4209 }
4210 if (LocaleCompare("delay",option+1) == 0)
4211 {
4212 if (*option == '+')
4213 break;
4214 i++;
cristybb503372010-05-27 20:51:26 +00004215 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004216 ThrowMogrifyException(OptionError,"MissingArgument",option);
4217 if (IsGeometry(argv[i]) == MagickFalse)
4218 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4219 break;
4220 }
cristyecb10ff2011-03-22 13:14:03 +00004221 if (LocaleCompare("delete",option+1) == 0)
4222 {
4223 if (*option == '+')
4224 break;
4225 i++;
4226 if (i == (ssize_t) (argc-1))
4227 ThrowMogrifyException(OptionError,"MissingArgument",option);
4228 if (IsGeometry(argv[i]) == MagickFalse)
4229 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4230 break;
4231 }
cristy3ed852e2009-09-05 21:47:34 +00004232 if (LocaleCompare("density",option+1) == 0)
4233 {
4234 if (*option == '+')
4235 break;
4236 i++;
cristybb503372010-05-27 20:51:26 +00004237 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004238 ThrowMogrifyException(OptionError,"MissingArgument",option);
4239 if (IsGeometry(argv[i]) == MagickFalse)
4240 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4241 break;
4242 }
4243 if (LocaleCompare("depth",option+1) == 0)
4244 {
4245 if (*option == '+')
4246 break;
4247 i++;
cristybb503372010-05-27 20:51:26 +00004248 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004249 ThrowMogrifyException(OptionError,"MissingArgument",option);
4250 if (IsGeometry(argv[i]) == MagickFalse)
4251 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4252 break;
4253 }
4254 if (LocaleCompare("deskew",option+1) == 0)
4255 {
4256 if (*option == '+')
4257 break;
4258 i++;
cristybb503372010-05-27 20:51:26 +00004259 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004260 ThrowMogrifyException(OptionError,"MissingArgument",option);
4261 if (IsGeometry(argv[i]) == MagickFalse)
4262 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4263 break;
4264 }
4265 if (LocaleCompare("despeckle",option+1) == 0)
4266 break;
4267 if (LocaleCompare("dft",option+1) == 0)
4268 break;
cristyc9b12952010-03-28 01:12:28 +00004269 if (LocaleCompare("direction",option+1) == 0)
4270 {
cristybb503372010-05-27 20:51:26 +00004271 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004272 direction;
4273
4274 if (*option == '+')
4275 break;
4276 i++;
cristybb503372010-05-27 20:51:26 +00004277 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004278 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004279 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004280 argv[i]);
4281 if (direction < 0)
4282 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4283 argv[i]);
4284 break;
4285 }
cristy3ed852e2009-09-05 21:47:34 +00004286 if (LocaleCompare("display",option+1) == 0)
4287 {
4288 if (*option == '+')
4289 break;
4290 i++;
cristybb503372010-05-27 20:51:26 +00004291 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004292 ThrowMogrifyException(OptionError,"MissingArgument",option);
4293 break;
4294 }
4295 if (LocaleCompare("dispose",option+1) == 0)
4296 {
cristybb503372010-05-27 20:51:26 +00004297 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004298 dispose;
4299
4300 if (*option == '+')
4301 break;
4302 i++;
cristybb503372010-05-27 20:51:26 +00004303 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004304 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004305 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004306 if (dispose < 0)
4307 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4308 argv[i]);
4309 break;
4310 }
4311 if (LocaleCompare("distort",option+1) == 0)
4312 {
cristybb503372010-05-27 20:51:26 +00004313 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004314 op;
4315
4316 i++;
cristybb503372010-05-27 20:51:26 +00004317 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004318 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004319 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004320 if (op < 0)
4321 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4322 argv[i]);
4323 i++;
cristybb503372010-05-27 20:51:26 +00004324 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004325 ThrowMogrifyException(OptionError,"MissingArgument",option);
4326 break;
4327 }
4328 if (LocaleCompare("dither",option+1) == 0)
4329 {
cristybb503372010-05-27 20:51:26 +00004330 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004331 method;
4332
4333 if (*option == '+')
4334 break;
4335 i++;
cristybb503372010-05-27 20:51:26 +00004336 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004337 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004338 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004339 if (method < 0)
4340 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4341 argv[i]);
4342 break;
4343 }
4344 if (LocaleCompare("draw",option+1) == 0)
4345 {
4346 if (*option == '+')
4347 break;
4348 i++;
cristybb503372010-05-27 20:51:26 +00004349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004350 ThrowMogrifyException(OptionError,"MissingArgument",option);
4351 break;
4352 }
cristyecb10ff2011-03-22 13:14:03 +00004353 if (LocaleCompare("duplicate",option+1) == 0)
4354 {
4355 if (*option == '+')
4356 break;
4357 i++;
4358 if (i == (ssize_t) (argc-1))
4359 ThrowMogrifyException(OptionError,"MissingArgument",option);
4360 if (IsGeometry(argv[i]) == MagickFalse)
4361 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4362 break;
4363 }
cristy22879752009-10-25 23:55:40 +00004364 if (LocaleCompare("duration",option+1) == 0)
4365 {
4366 if (*option == '+')
4367 break;
4368 i++;
cristybb503372010-05-27 20:51:26 +00004369 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004370 ThrowMogrifyException(OptionError,"MissingArgument",option);
4371 if (IsGeometry(argv[i]) == MagickFalse)
4372 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4373 break;
4374 }
cristy3ed852e2009-09-05 21:47:34 +00004375 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4376 }
4377 case 'e':
4378 {
4379 if (LocaleCompare("edge",option+1) == 0)
4380 {
4381 if (*option == '+')
4382 break;
4383 i++;
cristybb503372010-05-27 20:51:26 +00004384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004385 ThrowMogrifyException(OptionError,"MissingArgument",option);
4386 if (IsGeometry(argv[i]) == MagickFalse)
4387 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4388 break;
4389 }
4390 if (LocaleCompare("emboss",option+1) == 0)
4391 {
4392 if (*option == '+')
4393 break;
4394 i++;
cristybb503372010-05-27 20:51:26 +00004395 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004396 ThrowMogrifyException(OptionError,"MissingArgument",option);
4397 if (IsGeometry(argv[i]) == MagickFalse)
4398 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4399 break;
4400 }
4401 if (LocaleCompare("encipher",option+1) == 0)
4402 {
4403 if (*option == '+')
4404 break;
4405 i++;
cristybb503372010-05-27 20:51:26 +00004406 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004407 ThrowMogrifyException(OptionError,"MissingArgument",option);
4408 break;
4409 }
4410 if (LocaleCompare("encoding",option+1) == 0)
4411 {
4412 if (*option == '+')
4413 break;
4414 i++;
cristybb503372010-05-27 20:51:26 +00004415 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004416 ThrowMogrifyException(OptionError,"MissingArgument",option);
4417 break;
4418 }
4419 if (LocaleCompare("endian",option+1) == 0)
4420 {
cristybb503372010-05-27 20:51:26 +00004421 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004422 endian;
4423
4424 if (*option == '+')
4425 break;
4426 i++;
cristybb503372010-05-27 20:51:26 +00004427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004428 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004429 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004430 if (endian < 0)
4431 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4432 argv[i]);
4433 break;
4434 }
4435 if (LocaleCompare("enhance",option+1) == 0)
4436 break;
4437 if (LocaleCompare("equalize",option+1) == 0)
4438 break;
4439 if (LocaleCompare("evaluate",option+1) == 0)
4440 {
cristybb503372010-05-27 20:51:26 +00004441 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004442 op;
4443
4444 if (*option == '+')
4445 break;
4446 i++;
cristybb503372010-05-27 20:51:26 +00004447 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004448 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004449 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004450 if (op < 0)
4451 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4452 argv[i]);
4453 i++;
cristybb503372010-05-27 20:51:26 +00004454 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004455 ThrowMogrifyException(OptionError,"MissingArgument",option);
4456 if (IsGeometry(argv[i]) == MagickFalse)
4457 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4458 break;
4459 }
cristyd18ae7c2010-03-07 17:39:52 +00004460 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4461 {
cristybb503372010-05-27 20:51:26 +00004462 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004463 op;
4464
4465 if (*option == '+')
4466 break;
4467 i++;
cristybb503372010-05-27 20:51:26 +00004468 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004469 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004470 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004471 if (op < 0)
4472 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4473 argv[i]);
4474 break;
4475 }
cristy3ed852e2009-09-05 21:47:34 +00004476 if (LocaleCompare("extent",option+1) == 0)
4477 {
4478 if (*option == '+')
4479 break;
4480 i++;
cristybb503372010-05-27 20:51:26 +00004481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004482 ThrowMogrifyException(OptionError,"MissingArgument",option);
4483 if (IsGeometry(argv[i]) == MagickFalse)
4484 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4485 break;
4486 }
4487 if (LocaleCompare("extract",option+1) == 0)
4488 {
4489 if (*option == '+')
4490 break;
4491 i++;
cristybb503372010-05-27 20:51:26 +00004492 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004493 ThrowMogrifyException(OptionError,"MissingArgument",option);
4494 if (IsGeometry(argv[i]) == MagickFalse)
4495 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4496 break;
4497 }
4498 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4499 }
4500 case 'f':
4501 {
4502 if (LocaleCompare("family",option+1) == 0)
4503 {
4504 if (*option == '+')
4505 break;
4506 i++;
cristybb503372010-05-27 20:51:26 +00004507 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004508 ThrowMogrifyException(OptionError,"MissingArgument",option);
4509 break;
4510 }
4511 if (LocaleCompare("fill",option+1) == 0)
4512 {
4513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
4518 break;
4519 }
4520 if (LocaleCompare("filter",option+1) == 0)
4521 {
cristybb503372010-05-27 20:51:26 +00004522 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004523 filter;
4524
4525 if (*option == '+')
4526 break;
4527 i++;
cristybb503372010-05-27 20:51:26 +00004528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004529 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004530 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004531 if (filter < 0)
4532 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4533 argv[i]);
4534 break;
4535 }
4536 if (LocaleCompare("flatten",option+1) == 0)
4537 break;
4538 if (LocaleCompare("flip",option+1) == 0)
4539 break;
4540 if (LocaleCompare("flop",option+1) == 0)
4541 break;
4542 if (LocaleCompare("floodfill",option+1) == 0)
4543 {
4544 if (*option == '+')
4545 break;
4546 i++;
cristybb503372010-05-27 20:51:26 +00004547 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004548 ThrowMogrifyException(OptionError,"MissingArgument",option);
4549 if (IsGeometry(argv[i]) == MagickFalse)
4550 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 break;
4555 }
4556 if (LocaleCompare("font",option+1) == 0)
4557 {
4558 if (*option == '+')
4559 break;
4560 i++;
cristybb503372010-05-27 20:51:26 +00004561 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004562 ThrowMogrifyException(OptionError,"MissingArgument",option);
4563 break;
4564 }
4565 if (LocaleCompare("format",option+1) == 0)
4566 {
4567 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4568 (void) CloneString(&format,(char *) NULL);
4569 if (*option == '+')
4570 break;
4571 i++;
cristybb503372010-05-27 20:51:26 +00004572 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004573 ThrowMogrifyException(OptionError,"MissingArgument",option);
4574 (void) CloneString(&format,argv[i]);
4575 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4576 (void) ConcatenateMagickString(image_info->filename,":",
4577 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004578 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004579 if (*image_info->magick == '\0')
4580 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4581 format);
4582 break;
4583 }
4584 if (LocaleCompare("frame",option+1) == 0)
4585 {
4586 if (*option == '+')
4587 break;
4588 i++;
cristybb503372010-05-27 20:51:26 +00004589 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004590 ThrowMogrifyException(OptionError,"MissingArgument",option);
4591 if (IsGeometry(argv[i]) == MagickFalse)
4592 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4593 break;
4594 }
4595 if (LocaleCompare("function",option+1) == 0)
4596 {
cristybb503372010-05-27 20:51:26 +00004597 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004598 op;
4599
4600 if (*option == '+')
4601 break;
4602 i++;
cristybb503372010-05-27 20:51:26 +00004603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004604 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004605 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004606 if (op < 0)
4607 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4608 i++;
cristybb503372010-05-27 20:51:26 +00004609 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004610 ThrowMogrifyException(OptionError,"MissingArgument",option);
4611 break;
4612 }
4613 if (LocaleCompare("fuzz",option+1) == 0)
4614 {
4615 if (*option == '+')
4616 break;
4617 i++;
cristybb503372010-05-27 20:51:26 +00004618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004619 ThrowMogrifyException(OptionError,"MissingArgument",option);
4620 if (IsGeometry(argv[i]) == MagickFalse)
4621 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4622 break;
4623 }
4624 if (LocaleCompare("fx",option+1) == 0)
4625 {
4626 if (*option == '+')
4627 break;
4628 i++;
cristybb503372010-05-27 20:51:26 +00004629 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004630 ThrowMogrifyException(OptionError,"MissingArgument",option);
4631 break;
4632 }
4633 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4634 }
4635 case 'g':
4636 {
4637 if (LocaleCompare("gamma",option+1) == 0)
4638 {
4639 i++;
cristybb503372010-05-27 20:51:26 +00004640 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004641 ThrowMogrifyException(OptionError,"MissingArgument",option);
4642 if (IsGeometry(argv[i]) == MagickFalse)
4643 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4644 break;
4645 }
4646 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4647 (LocaleCompare("gaussian",option+1) == 0))
4648 {
4649 i++;
cristybb503372010-05-27 20:51:26 +00004650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004651 ThrowMogrifyException(OptionError,"MissingArgument",option);
4652 if (IsGeometry(argv[i]) == MagickFalse)
4653 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4654 break;
4655 }
4656 if (LocaleCompare("geometry",option+1) == 0)
4657 {
4658 if (*option == '+')
4659 break;
4660 i++;
cristybb503372010-05-27 20:51:26 +00004661 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004662 ThrowMogrifyException(OptionError,"MissingArgument",option);
4663 if (IsGeometry(argv[i]) == MagickFalse)
4664 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4665 break;
4666 }
4667 if (LocaleCompare("gravity",option+1) == 0)
4668 {
cristybb503372010-05-27 20:51:26 +00004669 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004670 gravity;
4671
4672 if (*option == '+')
4673 break;
4674 i++;
cristybb503372010-05-27 20:51:26 +00004675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004676 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004677 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004678 if (gravity < 0)
4679 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4680 argv[i]);
4681 break;
4682 }
4683 if (LocaleCompare("green-primary",option+1) == 0)
4684 {
4685 if (*option == '+')
4686 break;
4687 i++;
cristybb503372010-05-27 20:51:26 +00004688 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004689 ThrowMogrifyException(OptionError,"MissingArgument",option);
4690 if (IsGeometry(argv[i]) == MagickFalse)
4691 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4692 break;
4693 }
4694 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4695 }
4696 case 'h':
4697 {
4698 if (LocaleCompare("hald-clut",option+1) == 0)
4699 break;
4700 if ((LocaleCompare("help",option+1) == 0) ||
4701 (LocaleCompare("-help",option+1) == 0))
4702 return(MogrifyUsage());
4703 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4704 }
4705 case 'i':
4706 {
4707 if (LocaleCompare("identify",option+1) == 0)
4708 break;
4709 if (LocaleCompare("idft",option+1) == 0)
4710 break;
4711 if (LocaleCompare("implode",option+1) == 0)
4712 {
4713 if (*option == '+')
4714 break;
4715 i++;
cristybb503372010-05-27 20:51:26 +00004716 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004717 ThrowMogrifyException(OptionError,"MissingArgument",option);
4718 if (IsGeometry(argv[i]) == MagickFalse)
4719 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4720 break;
4721 }
4722 if (LocaleCompare("intent",option+1) == 0)
4723 {
cristybb503372010-05-27 20:51:26 +00004724 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004725 intent;
4726
4727 if (*option == '+')
4728 break;
4729 i++;
cristybb503372010-05-27 20:51:26 +00004730 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004731 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004732 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004733 if (intent < 0)
4734 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4735 argv[i]);
4736 break;
4737 }
4738 if (LocaleCompare("interlace",option+1) == 0)
4739 {
cristybb503372010-05-27 20:51:26 +00004740 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004741 interlace;
4742
4743 if (*option == '+')
4744 break;
4745 i++;
cristybb503372010-05-27 20:51:26 +00004746 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004747 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004748 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004749 argv[i]);
4750 if (interlace < 0)
4751 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4752 argv[i]);
4753 break;
4754 }
cristyb32b90a2009-09-07 21:45:48 +00004755 if (LocaleCompare("interline-spacing",option+1) == 0)
4756 {
4757 if (*option == '+')
4758 break;
4759 i++;
cristybb503372010-05-27 20:51:26 +00004760 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004761 ThrowMogrifyException(OptionError,"MissingArgument",option);
4762 if (IsGeometry(argv[i]) == MagickFalse)
4763 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4764 break;
4765 }
cristy3ed852e2009-09-05 21:47:34 +00004766 if (LocaleCompare("interpolate",option+1) == 0)
4767 {
cristybb503372010-05-27 20:51:26 +00004768 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004769 interpolate;
4770
4771 if (*option == '+')
4772 break;
4773 i++;
cristybb503372010-05-27 20:51:26 +00004774 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004775 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004776 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004777 argv[i]);
4778 if (interpolate < 0)
4779 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4780 argv[i]);
4781 break;
4782 }
4783 if (LocaleCompare("interword-spacing",option+1) == 0)
4784 {
4785 if (*option == '+')
4786 break;
4787 i++;
cristybb503372010-05-27 20:51:26 +00004788 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004789 ThrowMogrifyException(OptionError,"MissingArgument",option);
4790 if (IsGeometry(argv[i]) == MagickFalse)
4791 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4792 break;
4793 }
4794 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4795 }
4796 case 'k':
4797 {
4798 if (LocaleCompare("kerning",option+1) == 0)
4799 {
4800 if (*option == '+')
4801 break;
4802 i++;
cristybb503372010-05-27 20:51:26 +00004803 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004804 ThrowMogrifyException(OptionError,"MissingArgument",option);
4805 if (IsGeometry(argv[i]) == MagickFalse)
4806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4807 break;
4808 }
4809 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4810 }
4811 case 'l':
4812 {
4813 if (LocaleCompare("label",option+1) == 0)
4814 {
4815 if (*option == '+')
4816 break;
4817 i++;
cristybb503372010-05-27 20:51:26 +00004818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004819 ThrowMogrifyException(OptionError,"MissingArgument",option);
4820 break;
4821 }
4822 if (LocaleCompare("lat",option+1) == 0)
4823 {
4824 if (*option == '+')
4825 break;
4826 i++;
cristybb503372010-05-27 20:51:26 +00004827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004828 ThrowMogrifyException(OptionError,"MissingArgument",option);
4829 if (IsGeometry(argv[i]) == MagickFalse)
4830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4831 }
4832 if (LocaleCompare("layers",option+1) == 0)
4833 {
cristybb503372010-05-27 20:51:26 +00004834 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004835 type;
4836
4837 if (*option == '+')
4838 break;
4839 i++;
cristybb503372010-05-27 20:51:26 +00004840 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004841 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004842 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004843 if (type < 0)
4844 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4845 argv[i]);
4846 break;
4847 }
4848 if (LocaleCompare("level",option+1) == 0)
4849 {
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 if (IsGeometry(argv[i]) == MagickFalse)
4854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4855 break;
4856 }
4857 if (LocaleCompare("level-colors",option+1) == 0)
4858 {
4859 i++;
cristybb503372010-05-27 20:51:26 +00004860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004861 ThrowMogrifyException(OptionError,"MissingArgument",option);
4862 break;
4863 }
4864 if (LocaleCompare("linewidth",option+1) == 0)
4865 {
4866 if (*option == '+')
4867 break;
4868 i++;
cristybb503372010-05-27 20:51:26 +00004869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004870 ThrowMogrifyException(OptionError,"MissingArgument",option);
4871 if (IsGeometry(argv[i]) == MagickFalse)
4872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4873 break;
4874 }
4875 if (LocaleCompare("limit",option+1) == 0)
4876 {
4877 char
4878 *p;
4879
4880 double
4881 value;
4882
cristybb503372010-05-27 20:51:26 +00004883 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004884 resource;
4885
4886 if (*option == '+')
4887 break;
4888 i++;
cristybb503372010-05-27 20:51:26 +00004889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004890 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004891 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004892 argv[i]);
4893 if (resource < 0)
4894 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4895 argv[i]);
4896 i++;
cristybb503372010-05-27 20:51:26 +00004897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004898 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004899 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004900 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004901 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4903 break;
4904 }
4905 if (LocaleCompare("liquid-rescale",option+1) == 0)
4906 {
4907 i++;
cristybb503372010-05-27 20:51:26 +00004908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004909 ThrowMogrifyException(OptionError,"MissingArgument",option);
4910 if (IsGeometry(argv[i]) == MagickFalse)
4911 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4912 break;
4913 }
4914 if (LocaleCompare("list",option+1) == 0)
4915 {
cristybb503372010-05-27 20:51:26 +00004916 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004917 list;
4918
4919 if (*option == '+')
4920 break;
4921 i++;
cristybb503372010-05-27 20:51:26 +00004922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004923 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004924 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004925 if (list < 0)
4926 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004927 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004928 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004929 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004930 }
4931 if (LocaleCompare("log",option+1) == 0)
4932 {
4933 if (*option == '+')
4934 break;
4935 i++;
cristybb503372010-05-27 20:51:26 +00004936 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004937 (strchr(argv[i],'%') == (char *) NULL))
4938 ThrowMogrifyException(OptionError,"MissingArgument",option);
4939 break;
4940 }
4941 if (LocaleCompare("loop",option+1) == 0)
4942 {
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 if (IsGeometry(argv[i]) == MagickFalse)
4949 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4950 break;
4951 }
4952 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4953 }
4954 case 'm':
4955 {
4956 if (LocaleCompare("map",option+1) == 0)
4957 {
4958 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4959 if (*option == '+')
4960 break;
4961 i++;
cristybb503372010-05-27 20:51:26 +00004962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004963 ThrowMogrifyException(OptionError,"MissingArgument",option);
4964 break;
4965 }
4966 if (LocaleCompare("mask",option+1) == 0)
4967 {
4968 if (*option == '+')
4969 break;
4970 i++;
cristybb503372010-05-27 20:51:26 +00004971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004972 ThrowMogrifyException(OptionError,"MissingArgument",option);
4973 break;
4974 }
4975 if (LocaleCompare("matte",option+1) == 0)
4976 break;
4977 if (LocaleCompare("mattecolor",option+1) == 0)
4978 {
4979 if (*option == '+')
4980 break;
4981 i++;
cristybb503372010-05-27 20:51:26 +00004982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004983 ThrowMogrifyException(OptionError,"MissingArgument",option);
4984 break;
4985 }
cristyf40785b2010-03-06 02:27:27 +00004986 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004987 break;
cristyf40785b2010-03-06 02:27:27 +00004988 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004989 break;
cristy3ed852e2009-09-05 21:47:34 +00004990 if (LocaleCompare("modulate",option+1) == 0)
4991 {
4992 if (*option == '+')
4993 break;
4994 i++;
cristybb503372010-05-27 20:51:26 +00004995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004996 ThrowMogrifyException(OptionError,"MissingArgument",option);
4997 if (IsGeometry(argv[i]) == MagickFalse)
4998 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4999 break;
5000 }
5001 if (LocaleCompare("median",option+1) == 0)
5002 {
5003 if (*option == '+')
5004 break;
5005 i++;
cristybb503372010-05-27 20:51:26 +00005006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005007 ThrowMogrifyException(OptionError,"MissingArgument",option);
5008 if (IsGeometry(argv[i]) == MagickFalse)
5009 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5010 break;
5011 }
cristy69ec32d2011-02-27 23:57:09 +00005012 if (LocaleCompare("mode",option+1) == 0)
5013 {
5014 if (*option == '+')
5015 break;
5016 i++;
5017 if (i == (ssize_t) argc)
5018 ThrowMogrifyException(OptionError,"MissingArgument",option);
5019 if (IsGeometry(argv[i]) == MagickFalse)
5020 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5021 break;
5022 }
cristy3ed852e2009-09-05 21:47:34 +00005023 if (LocaleCompare("monitor",option+1) == 0)
5024 break;
5025 if (LocaleCompare("monochrome",option+1) == 0)
5026 break;
5027 if (LocaleCompare("morph",option+1) == 0)
5028 {
5029 if (*option == '+')
5030 break;
5031 i++;
cristybb503372010-05-27 20:51:26 +00005032 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005033 ThrowMogrifyException(OptionError,"MissingArgument",option);
5034 if (IsGeometry(argv[i]) == MagickFalse)
5035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5036 break;
5037 }
anthony29188a82010-01-22 10:12:34 +00005038 if (LocaleCompare("morphology",option+1) == 0)
5039 {
anthony29188a82010-01-22 10:12:34 +00005040 char
5041 token[MaxTextExtent];
5042
cristyb6bd4ad2010-08-08 01:12:27 +00005043 KernelInfo
5044 *kernel_info;
5045
5046 ssize_t
5047 op;
5048
anthony29188a82010-01-22 10:12:34 +00005049 i++;
cristybb503372010-05-27 20:51:26 +00005050 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005051 ThrowMogrifyException(OptionError,"MissingArgument",option);
5052 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005053 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005054 if (op < 0)
5055 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005056 token);
anthony29188a82010-01-22 10:12:34 +00005057 i++;
cristybb503372010-05-27 20:51:26 +00005058 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005059 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005060 kernel_info=AcquireKernelInfo(argv[i]);
5061 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005062 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005063 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005064 break;
5065 }
cristy3ed852e2009-09-05 21:47:34 +00005066 if (LocaleCompare("mosaic",option+1) == 0)
5067 break;
5068 if (LocaleCompare("motion-blur",option+1) == 0)
5069 {
5070 if (*option == '+')
5071 break;
5072 i++;
cristybb503372010-05-27 20:51:26 +00005073 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005074 ThrowMogrifyException(OptionError,"MissingArgument",option);
5075 if (IsGeometry(argv[i]) == MagickFalse)
5076 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5077 break;
5078 }
5079 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5080 }
5081 case 'n':
5082 {
5083 if (LocaleCompare("negate",option+1) == 0)
5084 break;
5085 if (LocaleCompare("noise",option+1) == 0)
5086 {
5087 i++;
cristybb503372010-05-27 20:51:26 +00005088 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005089 ThrowMogrifyException(OptionError,"MissingArgument",option);
5090 if (*option == '+')
5091 {
cristybb503372010-05-27 20:51:26 +00005092 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005093 noise;
5094
cristy042ee782011-04-22 18:48:30 +00005095 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005096 if (noise < 0)
5097 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5098 argv[i]);
5099 break;
5100 }
5101 if (IsGeometry(argv[i]) == MagickFalse)
5102 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5103 break;
5104 }
5105 if (LocaleCompare("noop",option+1) == 0)
5106 break;
5107 if (LocaleCompare("normalize",option+1) == 0)
5108 break;
5109 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5110 }
5111 case 'o':
5112 {
5113 if (LocaleCompare("opaque",option+1) == 0)
5114 {
cristy3ed852e2009-09-05 21:47:34 +00005115 i++;
cristybb503372010-05-27 20:51:26 +00005116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005117 ThrowMogrifyException(OptionError,"MissingArgument",option);
5118 break;
5119 }
5120 if (LocaleCompare("ordered-dither",option+1) == 0)
5121 {
5122 if (*option == '+')
5123 break;
5124 i++;
cristybb503372010-05-27 20:51:26 +00005125 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005126 ThrowMogrifyException(OptionError,"MissingArgument",option);
5127 break;
5128 }
5129 if (LocaleCompare("orient",option+1) == 0)
5130 {
cristybb503372010-05-27 20:51:26 +00005131 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005132 orientation;
5133
5134 orientation=UndefinedOrientation;
5135 if (*option == '+')
5136 break;
5137 i++;
cristybb503372010-05-27 20:51:26 +00005138 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005139 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005140 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005141 argv[i]);
5142 if (orientation < 0)
5143 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5144 argv[i]);
5145 break;
5146 }
5147 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5148 }
5149 case 'p':
5150 {
5151 if (LocaleCompare("page",option+1) == 0)
5152 {
5153 if (*option == '+')
5154 break;
5155 i++;
cristybb503372010-05-27 20:51:26 +00005156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005157 ThrowMogrifyException(OptionError,"MissingArgument",option);
5158 break;
5159 }
5160 if (LocaleCompare("paint",option+1) == 0)
5161 {
5162 if (*option == '+')
5163 break;
5164 i++;
cristybb503372010-05-27 20:51:26 +00005165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005166 ThrowMogrifyException(OptionError,"MissingArgument",option);
5167 if (IsGeometry(argv[i]) == MagickFalse)
5168 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5169 break;
5170 }
5171 if (LocaleCompare("path",option+1) == 0)
5172 {
5173 (void) CloneString(&path,(char *) NULL);
5174 if (*option == '+')
5175 break;
5176 i++;
cristybb503372010-05-27 20:51:26 +00005177 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005178 ThrowMogrifyException(OptionError,"MissingArgument",option);
5179 (void) CloneString(&path,argv[i]);
5180 break;
5181 }
5182 if (LocaleCompare("pointsize",option+1) == 0)
5183 {
5184 if (*option == '+')
5185 break;
5186 i++;
cristybb503372010-05-27 20:51:26 +00005187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005188 ThrowMogrifyException(OptionError,"MissingArgument",option);
5189 if (IsGeometry(argv[i]) == MagickFalse)
5190 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5191 break;
5192 }
5193 if (LocaleCompare("polaroid",option+1) == 0)
5194 {
5195 if (*option == '+')
5196 break;
5197 i++;
cristybb503372010-05-27 20:51:26 +00005198 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005199 ThrowMogrifyException(OptionError,"MissingArgument",option);
5200 if (IsGeometry(argv[i]) == MagickFalse)
5201 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5202 break;
5203 }
5204 if (LocaleCompare("posterize",option+1) == 0)
5205 {
5206 if (*option == '+')
5207 break;
5208 i++;
cristybb503372010-05-27 20:51:26 +00005209 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005210 ThrowMogrifyException(OptionError,"MissingArgument",option);
5211 if (IsGeometry(argv[i]) == MagickFalse)
5212 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5213 break;
5214 }
cristye7f51092010-01-17 00:39:37 +00005215 if (LocaleCompare("precision",option+1) == 0)
5216 {
5217 if (*option == '+')
5218 break;
5219 i++;
cristybb503372010-05-27 20:51:26 +00005220 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005221 ThrowMogrifyException(OptionError,"MissingArgument",option);
5222 if (IsGeometry(argv[i]) == MagickFalse)
5223 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5224 break;
5225 }
cristy3ed852e2009-09-05 21:47:34 +00005226 if (LocaleCompare("print",option+1) == 0)
5227 {
5228 if (*option == '+')
5229 break;
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 if (LocaleCompare("process",option+1) == 0)
5236 {
5237 if (*option == '+')
5238 break;
5239 i++;
cristybb503372010-05-27 20:51:26 +00005240 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005241 ThrowMogrifyException(OptionError,"MissingArgument",option);
5242 break;
5243 }
5244 if (LocaleCompare("profile",option+1) == 0)
5245 {
5246 i++;
cristybb503372010-05-27 20:51:26 +00005247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005248 ThrowMogrifyException(OptionError,"MissingArgument",option);
5249 break;
5250 }
5251 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5252 }
5253 case 'q':
5254 {
5255 if (LocaleCompare("quality",option+1) == 0)
5256 {
5257 if (*option == '+')
5258 break;
5259 i++;
cristybb503372010-05-27 20:51:26 +00005260 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005261 ThrowMogrifyException(OptionError,"MissingArgument",option);
5262 if (IsGeometry(argv[i]) == MagickFalse)
5263 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5264 break;
5265 }
5266 if (LocaleCompare("quantize",option+1) == 0)
5267 {
cristybb503372010-05-27 20:51:26 +00005268 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005269 colorspace;
5270
5271 if (*option == '+')
5272 break;
5273 i++;
cristybb503372010-05-27 20:51:26 +00005274 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005275 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005276 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005277 argv[i]);
5278 if (colorspace < 0)
5279 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5280 argv[i]);
5281 break;
5282 }
5283 if (LocaleCompare("quiet",option+1) == 0)
5284 break;
5285 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5286 }
5287 case 'r':
5288 {
5289 if (LocaleCompare("radial-blur",option+1) == 0)
5290 {
5291 i++;
cristybb503372010-05-27 20:51:26 +00005292 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005293 ThrowMogrifyException(OptionError,"MissingArgument",option);
5294 if (IsGeometry(argv[i]) == MagickFalse)
5295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5296 break;
5297 }
5298 if (LocaleCompare("raise",option+1) == 0)
5299 {
5300 i++;
cristybb503372010-05-27 20:51:26 +00005301 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005302 ThrowMogrifyException(OptionError,"MissingArgument",option);
5303 if (IsGeometry(argv[i]) == MagickFalse)
5304 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5305 break;
5306 }
5307 if (LocaleCompare("random-threshold",option+1) == 0)
5308 {
5309 if (*option == '+')
5310 break;
5311 i++;
cristybb503372010-05-27 20:51:26 +00005312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005313 ThrowMogrifyException(OptionError,"MissingArgument",option);
5314 if (IsGeometry(argv[i]) == MagickFalse)
5315 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5316 break;
5317 }
cristye6365592010-04-02 17:31:23 +00005318 if (LocaleCompare("recolor",option+1) == 0)
5319 {
5320 if (*option == '+')
5321 break;
5322 i++;
cristybb503372010-05-27 20:51:26 +00005323 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005324 ThrowMogrifyException(OptionError,"MissingArgument",option);
5325 if (IsGeometry(argv[i]) == MagickFalse)
5326 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5327 break;
5328 }
cristy3ed852e2009-09-05 21:47:34 +00005329 if (LocaleCompare("red-primary",option+1) == 0)
5330 {
5331 if (*option == '+')
5332 break;
5333 i++;
cristybb503372010-05-27 20:51:26 +00005334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005335 ThrowMogrifyException(OptionError,"MissingArgument",option);
5336 if (IsGeometry(argv[i]) == MagickFalse)
5337 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5338 }
cristy9f2083a2010-04-22 19:48:05 +00005339 if (LocaleCompare("regard-warnings",option+1) == 0)
5340 break;
cristy3ed852e2009-09-05 21:47:34 +00005341 if (LocaleCompare("region",option+1) == 0)
5342 {
5343 if (*option == '+')
5344 break;
5345 i++;
cristybb503372010-05-27 20:51:26 +00005346 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005347 ThrowMogrifyException(OptionError,"MissingArgument",option);
5348 if (IsGeometry(argv[i]) == MagickFalse)
5349 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5350 break;
5351 }
cristyf0c78232010-03-15 12:53:40 +00005352 if (LocaleCompare("remap",option+1) == 0)
5353 {
5354 if (*option == '+')
5355 break;
5356 i++;
cristybb503372010-05-27 20:51:26 +00005357 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005358 ThrowMogrifyException(OptionError,"MissingArgument",option);
5359 break;
5360 }
cristy3ed852e2009-09-05 21:47:34 +00005361 if (LocaleCompare("render",option+1) == 0)
5362 break;
5363 if (LocaleCompare("repage",option+1) == 0)
5364 {
5365 if (*option == '+')
5366 break;
5367 i++;
cristybb503372010-05-27 20:51:26 +00005368 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005369 ThrowMogrifyException(OptionError,"MissingArgument",option);
5370 if (IsGeometry(argv[i]) == MagickFalse)
5371 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5372 break;
5373 }
5374 if (LocaleCompare("resample",option+1) == 0)
5375 {
5376 if (*option == '+')
5377 break;
5378 i++;
cristybb503372010-05-27 20:51:26 +00005379 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005380 ThrowMogrifyException(OptionError,"MissingArgument",option);
5381 if (IsGeometry(argv[i]) == MagickFalse)
5382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5383 break;
5384 }
5385 if (LocaleCompare("resize",option+1) == 0)
5386 {
5387 if (*option == '+')
5388 break;
5389 i++;
cristybb503372010-05-27 20:51:26 +00005390 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005391 ThrowMogrifyException(OptionError,"MissingArgument",option);
5392 if (IsGeometry(argv[i]) == MagickFalse)
5393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5394 break;
5395 }
cristyebbcfea2011-02-25 02:43:54 +00005396 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5397 {
5398 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5399 break;
5400 }
cristy3ed852e2009-09-05 21:47:34 +00005401 if (LocaleCompare("reverse",option+1) == 0)
5402 break;
5403 if (LocaleCompare("roll",option+1) == 0)
5404 {
5405 if (*option == '+')
5406 break;
5407 i++;
cristybb503372010-05-27 20:51:26 +00005408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005409 ThrowMogrifyException(OptionError,"MissingArgument",option);
5410 if (IsGeometry(argv[i]) == MagickFalse)
5411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5412 break;
5413 }
5414 if (LocaleCompare("rotate",option+1) == 0)
5415 {
5416 i++;
cristybb503372010-05-27 20:51:26 +00005417 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005418 ThrowMogrifyException(OptionError,"MissingArgument",option);
5419 if (IsGeometry(argv[i]) == MagickFalse)
5420 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5421 break;
5422 }
5423 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5424 }
5425 case 's':
5426 {
5427 if (LocaleCompare("sample",option+1) == 0)
5428 {
5429 if (*option == '+')
5430 break;
5431 i++;
cristybb503372010-05-27 20:51:26 +00005432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005433 ThrowMogrifyException(OptionError,"MissingArgument",option);
5434 if (IsGeometry(argv[i]) == MagickFalse)
5435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5436 break;
5437 }
5438 if (LocaleCompare("sampling-factor",option+1) == 0)
5439 {
5440 if (*option == '+')
5441 break;
5442 i++;
cristybb503372010-05-27 20:51:26 +00005443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005444 ThrowMogrifyException(OptionError,"MissingArgument",option);
5445 if (IsGeometry(argv[i]) == MagickFalse)
5446 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5447 break;
5448 }
5449 if (LocaleCompare("scale",option+1) == 0)
5450 {
5451 if (*option == '+')
5452 break;
5453 i++;
cristybb503372010-05-27 20:51:26 +00005454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005455 ThrowMogrifyException(OptionError,"MissingArgument",option);
5456 if (IsGeometry(argv[i]) == MagickFalse)
5457 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5458 break;
5459 }
5460 if (LocaleCompare("scene",option+1) == 0)
5461 {
5462 if (*option == '+')
5463 break;
5464 i++;
cristybb503372010-05-27 20:51:26 +00005465 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005466 ThrowMogrifyException(OptionError,"MissingArgument",option);
5467 if (IsGeometry(argv[i]) == MagickFalse)
5468 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5469 break;
5470 }
5471 if (LocaleCompare("seed",option+1) == 0)
5472 {
5473 if (*option == '+')
5474 break;
5475 i++;
cristybb503372010-05-27 20:51:26 +00005476 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005477 ThrowMogrifyException(OptionError,"MissingArgument",option);
5478 if (IsGeometry(argv[i]) == MagickFalse)
5479 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5480 break;
5481 }
5482 if (LocaleCompare("segment",option+1) == 0)
5483 {
5484 if (*option == '+')
5485 break;
5486 i++;
cristybb503372010-05-27 20:51:26 +00005487 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005488 ThrowMogrifyException(OptionError,"MissingArgument",option);
5489 if (IsGeometry(argv[i]) == MagickFalse)
5490 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5491 break;
5492 }
5493 if (LocaleCompare("selective-blur",option+1) == 0)
5494 {
5495 i++;
cristybb503372010-05-27 20:51:26 +00005496 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005497 ThrowMogrifyException(OptionError,"MissingArgument",option);
5498 if (IsGeometry(argv[i]) == MagickFalse)
5499 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5500 break;
5501 }
5502 if (LocaleCompare("separate",option+1) == 0)
5503 break;
5504 if (LocaleCompare("sepia-tone",option+1) == 0)
5505 {
5506 if (*option == '+')
5507 break;
5508 i++;
cristybb503372010-05-27 20:51:26 +00005509 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005510 ThrowMogrifyException(OptionError,"MissingArgument",option);
5511 if (IsGeometry(argv[i]) == MagickFalse)
5512 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5513 break;
5514 }
5515 if (LocaleCompare("set",option+1) == 0)
5516 {
5517 i++;
cristybb503372010-05-27 20:51:26 +00005518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 if (*option == '+')
5521 break;
5522 i++;
cristybb503372010-05-27 20:51:26 +00005523 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005524 ThrowMogrifyException(OptionError,"MissingArgument",option);
5525 break;
5526 }
5527 if (LocaleCompare("shade",option+1) == 0)
5528 {
5529 i++;
cristybb503372010-05-27 20:51:26 +00005530 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005531 ThrowMogrifyException(OptionError,"MissingArgument",option);
5532 if (IsGeometry(argv[i]) == MagickFalse)
5533 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5534 break;
5535 }
5536 if (LocaleCompare("shadow",option+1) == 0)
5537 {
5538 if (*option == '+')
5539 break;
5540 i++;
cristybb503372010-05-27 20:51:26 +00005541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005542 ThrowMogrifyException(OptionError,"MissingArgument",option);
5543 if (IsGeometry(argv[i]) == MagickFalse)
5544 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5545 break;
5546 }
5547 if (LocaleCompare("sharpen",option+1) == 0)
5548 {
5549 i++;
cristybb503372010-05-27 20:51:26 +00005550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005551 ThrowMogrifyException(OptionError,"MissingArgument",option);
5552 if (IsGeometry(argv[i]) == MagickFalse)
5553 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5554 break;
5555 }
5556 if (LocaleCompare("shave",option+1) == 0)
5557 {
5558 if (*option == '+')
5559 break;
5560 i++;
cristybb503372010-05-27 20:51:26 +00005561 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005562 ThrowMogrifyException(OptionError,"MissingArgument",option);
5563 if (IsGeometry(argv[i]) == MagickFalse)
5564 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5565 break;
5566 }
5567 if (LocaleCompare("shear",option+1) == 0)
5568 {
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005571 ThrowMogrifyException(OptionError,"MissingArgument",option);
5572 if (IsGeometry(argv[i]) == MagickFalse)
5573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574 break;
5575 }
5576 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5577 {
5578 i++;
cristybb503372010-05-27 20:51:26 +00005579 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005580 ThrowMogrifyException(OptionError,"MissingArgument",option);
5581 if (IsGeometry(argv[i]) == MagickFalse)
5582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5583 break;
5584 }
5585 if (LocaleCompare("size",option+1) == 0)
5586 {
5587 if (*option == '+')
5588 break;
5589 i++;
cristybb503372010-05-27 20:51:26 +00005590 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005591 ThrowMogrifyException(OptionError,"MissingArgument",option);
5592 if (IsGeometry(argv[i]) == MagickFalse)
5593 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5594 break;
5595 }
5596 if (LocaleCompare("sketch",option+1) == 0)
5597 {
5598 if (*option == '+')
5599 break;
5600 i++;
cristybb503372010-05-27 20:51:26 +00005601 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005602 ThrowMogrifyException(OptionError,"MissingArgument",option);
5603 if (IsGeometry(argv[i]) == MagickFalse)
5604 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5605 break;
5606 }
cristy4285d782011-02-09 20:12:28 +00005607 if (LocaleCompare("smush",option+1) == 0)
5608 {
cristy4285d782011-02-09 20:12:28 +00005609 i++;
5610 if (i == (ssize_t) argc)
5611 ThrowMogrifyException(OptionError,"MissingArgument",option);
5612 if (IsGeometry(argv[i]) == MagickFalse)
5613 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005614 i++;
5615 break;
5616 }
cristy3ed852e2009-09-05 21:47:34 +00005617 if (LocaleCompare("solarize",option+1) == 0)
5618 {
5619 if (*option == '+')
5620 break;
5621 i++;
cristybb503372010-05-27 20:51:26 +00005622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005623 ThrowMogrifyException(OptionError,"MissingArgument",option);
5624 if (IsGeometry(argv[i]) == MagickFalse)
5625 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5626 break;
5627 }
5628 if (LocaleCompare("sparse-color",option+1) == 0)
5629 {
cristybb503372010-05-27 20:51:26 +00005630 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005631 op;
5632
5633 i++;
cristybb503372010-05-27 20:51:26 +00005634 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005635 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005636 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005637 if (op < 0)
5638 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5639 argv[i]);
5640 i++;
cristybb503372010-05-27 20:51:26 +00005641 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005642 ThrowMogrifyException(OptionError,"MissingArgument",option);
5643 break;
5644 }
5645 if (LocaleCompare("spread",option+1) == 0)
5646 {
5647 if (*option == '+')
5648 break;
5649 i++;
cristybb503372010-05-27 20:51:26 +00005650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005651 ThrowMogrifyException(OptionError,"MissingArgument",option);
5652 if (IsGeometry(argv[i]) == MagickFalse)
5653 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5654 break;
5655 }
cristy0834d642011-03-18 18:26:08 +00005656 if (LocaleCompare("statistic",option+1) == 0)
5657 {
5658 ssize_t
5659 op;
5660
5661 if (*option == '+')
5662 break;
5663 i++;
5664 if (i == (ssize_t) argc)
5665 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005666 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005667 if (op < 0)
5668 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5669 argv[i]);
5670 i++;
5671 if (i == (ssize_t) (argc-1))
5672 ThrowMogrifyException(OptionError,"MissingArgument",option);
5673 if (IsGeometry(argv[i]) == MagickFalse)
5674 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5675 break;
5676 }
cristy3ed852e2009-09-05 21:47:34 +00005677 if (LocaleCompare("stretch",option+1) == 0)
5678 {
cristybb503372010-05-27 20:51:26 +00005679 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005680 stretch;
5681
5682 if (*option == '+')
5683 break;
5684 i++;
cristybb503372010-05-27 20:51:26 +00005685 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005686 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005687 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005688 if (stretch < 0)
5689 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5690 argv[i]);
5691 break;
5692 }
5693 if (LocaleCompare("strip",option+1) == 0)
5694 break;
5695 if (LocaleCompare("stroke",option+1) == 0)
5696 {
5697 if (*option == '+')
5698 break;
5699 i++;
cristybb503372010-05-27 20:51:26 +00005700 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 break;
5703 }
5704 if (LocaleCompare("strokewidth",option+1) == 0)
5705 {
5706 if (*option == '+')
5707 break;
5708 i++;
cristybb503372010-05-27 20:51:26 +00005709 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005710 ThrowMogrifyException(OptionError,"MissingArgument",option);
5711 if (IsGeometry(argv[i]) == MagickFalse)
5712 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5713 break;
5714 }
5715 if (LocaleCompare("style",option+1) == 0)
5716 {
cristybb503372010-05-27 20:51:26 +00005717 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005718 style;
5719
5720 if (*option == '+')
5721 break;
5722 i++;
cristybb503372010-05-27 20:51:26 +00005723 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005724 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005725 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005726 if (style < 0)
5727 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5728 argv[i]);
5729 break;
5730 }
cristyecb10ff2011-03-22 13:14:03 +00005731 if (LocaleCompare("swap",option+1) == 0)
5732 {
5733 if (*option == '+')
5734 break;
5735 i++;
5736 if (i == (ssize_t) (argc-1))
5737 ThrowMogrifyException(OptionError,"MissingArgument",option);
5738 if (IsGeometry(argv[i]) == MagickFalse)
5739 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5740 break;
5741 }
cristy3ed852e2009-09-05 21:47:34 +00005742 if (LocaleCompare("swirl",option+1) == 0)
5743 {
5744 if (*option == '+')
5745 break;
5746 i++;
cristybb503372010-05-27 20:51:26 +00005747 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005748 ThrowMogrifyException(OptionError,"MissingArgument",option);
5749 if (IsGeometry(argv[i]) == MagickFalse)
5750 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5751 break;
5752 }
cristyd9a29192010-10-16 16:49:53 +00005753 if (LocaleCompare("synchronize",option+1) == 0)
5754 break;
cristy3ed852e2009-09-05 21:47:34 +00005755 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5756 }
5757 case 't':
5758 {
5759 if (LocaleCompare("taint",option+1) == 0)
5760 break;
5761 if (LocaleCompare("texture",option+1) == 0)
5762 {
5763 if (*option == '+')
5764 break;
5765 i++;
cristybb503372010-05-27 20:51:26 +00005766 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005767 ThrowMogrifyException(OptionError,"MissingArgument",option);
5768 break;
5769 }
5770 if (LocaleCompare("tile",option+1) == 0)
5771 {
5772 if (*option == '+')
5773 break;
5774 i++;
cristybb503372010-05-27 20:51:26 +00005775 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005776 ThrowMogrifyException(OptionError,"MissingArgument",option);
5777 break;
5778 }
5779 if (LocaleCompare("tile-offset",option+1) == 0)
5780 {
5781 if (*option == '+')
5782 break;
5783 i++;
cristybb503372010-05-27 20:51:26 +00005784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005785 ThrowMogrifyException(OptionError,"MissingArgument",option);
5786 if (IsGeometry(argv[i]) == MagickFalse)
5787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5788 break;
5789 }
5790 if (LocaleCompare("tint",option+1) == 0)
5791 {
5792 if (*option == '+')
5793 break;
5794 i++;
cristybb503372010-05-27 20:51:26 +00005795 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005796 ThrowMogrifyException(OptionError,"MissingArgument",option);
5797 if (IsGeometry(argv[i]) == MagickFalse)
5798 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5799 break;
5800 }
5801 if (LocaleCompare("transform",option+1) == 0)
5802 break;
5803 if (LocaleCompare("transpose",option+1) == 0)
5804 break;
5805 if (LocaleCompare("transverse",option+1) == 0)
5806 break;
5807 if (LocaleCompare("threshold",option+1) == 0)
5808 {
5809 if (*option == '+')
5810 break;
5811 i++;
cristybb503372010-05-27 20:51:26 +00005812 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005813 ThrowMogrifyException(OptionError,"MissingArgument",option);
5814 if (IsGeometry(argv[i]) == MagickFalse)
5815 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5816 break;
5817 }
5818 if (LocaleCompare("thumbnail",option+1) == 0)
5819 {
5820 if (*option == '+')
5821 break;
5822 i++;
cristybb503372010-05-27 20:51:26 +00005823 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005824 ThrowMogrifyException(OptionError,"MissingArgument",option);
5825 if (IsGeometry(argv[i]) == MagickFalse)
5826 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5827 break;
5828 }
5829 if (LocaleCompare("transparent",option+1) == 0)
5830 {
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 break;
5835 }
5836 if (LocaleCompare("transparent-color",option+1) == 0)
5837 {
5838 if (*option == '+')
5839 break;
5840 i++;
cristybb503372010-05-27 20:51:26 +00005841 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005842 ThrowMogrifyException(OptionError,"MissingArgument",option);
5843 break;
5844 }
5845 if (LocaleCompare("treedepth",option+1) == 0)
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);
5852 if (IsGeometry(argv[i]) == MagickFalse)
5853 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5854 break;
5855 }
5856 if (LocaleCompare("trim",option+1) == 0)
5857 break;
5858 if (LocaleCompare("type",option+1) == 0)
5859 {
cristybb503372010-05-27 20:51:26 +00005860 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005861 type;
5862
5863 if (*option == '+')
5864 break;
5865 i++;
cristybb503372010-05-27 20:51:26 +00005866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005867 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005868 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005869 if (type < 0)
5870 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5871 argv[i]);
5872 break;
5873 }
5874 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5875 }
5876 case 'u':
5877 {
5878 if (LocaleCompare("undercolor",option+1) == 0)
5879 {
5880 if (*option == '+')
5881 break;
5882 i++;
cristybb503372010-05-27 20:51:26 +00005883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005884 ThrowMogrifyException(OptionError,"MissingArgument",option);
5885 break;
5886 }
5887 if (LocaleCompare("unique-colors",option+1) == 0)
5888 break;
5889 if (LocaleCompare("units",option+1) == 0)
5890 {
cristybb503372010-05-27 20:51:26 +00005891 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005892 units;
5893
5894 if (*option == '+')
5895 break;
5896 i++;
cristybb503372010-05-27 20:51:26 +00005897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005898 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005899 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005900 argv[i]);
5901 if (units < 0)
5902 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5903 argv[i]);
5904 break;
5905 }
5906 if (LocaleCompare("unsharp",option+1) == 0)
5907 {
5908 i++;
cristybb503372010-05-27 20:51:26 +00005909 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005910 ThrowMogrifyException(OptionError,"MissingArgument",option);
5911 if (IsGeometry(argv[i]) == MagickFalse)
5912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5913 break;
5914 }
5915 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5916 }
5917 case 'v':
5918 {
5919 if (LocaleCompare("verbose",option+1) == 0)
5920 {
5921 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5922 break;
5923 }
5924 if ((LocaleCompare("version",option+1) == 0) ||
5925 (LocaleCompare("-version",option+1) == 0))
5926 {
cristyb51dff52011-05-19 16:55:47 +00005927 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005928 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005929 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5930 GetMagickCopyright());
5931 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5932 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005933 break;
5934 }
5935 if (LocaleCompare("view",option+1) == 0)
5936 {
5937 if (*option == '+')
5938 break;
5939 i++;
cristybb503372010-05-27 20:51:26 +00005940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005941 ThrowMogrifyException(OptionError,"MissingArgument",option);
5942 break;
5943 }
5944 if (LocaleCompare("vignette",option+1) == 0)
5945 {
5946 if (*option == '+')
5947 break;
5948 i++;
cristybb503372010-05-27 20:51:26 +00005949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005950 ThrowMogrifyException(OptionError,"MissingArgument",option);
5951 if (IsGeometry(argv[i]) == MagickFalse)
5952 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5953 break;
5954 }
5955 if (LocaleCompare("virtual-pixel",option+1) == 0)
5956 {
cristybb503372010-05-27 20:51:26 +00005957 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005958 method;
5959
5960 if (*option == '+')
5961 break;
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);
cristy042ee782011-04-22 18:48:30 +00005965 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005966 argv[i]);
5967 if (method < 0)
5968 ThrowMogrifyException(OptionError,
5969 "UnrecognizedVirtualPixelMethod",argv[i]);
5970 break;
5971 }
5972 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5973 }
5974 case 'w':
5975 {
5976 if (LocaleCompare("wave",option+1) == 0)
5977 {
5978 i++;
cristybb503372010-05-27 20:51:26 +00005979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005980 ThrowMogrifyException(OptionError,"MissingArgument",option);
5981 if (IsGeometry(argv[i]) == MagickFalse)
5982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5983 break;
5984 }
5985 if (LocaleCompare("weight",option+1) == 0)
5986 {
5987 if (*option == '+')
5988 break;
5989 i++;
cristybb503372010-05-27 20:51:26 +00005990 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005991 ThrowMogrifyException(OptionError,"MissingArgument",option);
5992 break;
5993 }
5994 if (LocaleCompare("white-point",option+1) == 0)
5995 {
5996 if (*option == '+')
5997 break;
5998 i++;
cristybb503372010-05-27 20:51:26 +00005999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006000 ThrowMogrifyException(OptionError,"MissingArgument",option);
6001 if (IsGeometry(argv[i]) == MagickFalse)
6002 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6003 break;
6004 }
6005 if (LocaleCompare("white-threshold",option+1) == 0)
6006 {
6007 if (*option == '+')
6008 break;
6009 i++;
cristybb503372010-05-27 20:51:26 +00006010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006011 ThrowMogrifyException(OptionError,"MissingArgument",option);
6012 if (IsGeometry(argv[i]) == MagickFalse)
6013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6014 break;
6015 }
6016 if (LocaleCompare("write",option+1) == 0)
6017 {
6018 i++;
cristybb503372010-05-27 20:51:26 +00006019 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006020 ThrowMogrifyException(OptionError,"MissingArgument",option);
6021 break;
6022 }
6023 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6024 }
6025 case '?':
6026 break;
6027 default:
6028 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6029 }
cristy042ee782011-04-22 18:48:30 +00006030 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6031 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006032 if (fire != MagickFalse)
6033 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6034 }
6035 if (k != 0)
6036 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006037 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006038 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6039 DestroyMogrify();
6040 return(status != 0 ? MagickTrue : MagickFalse);
6041}
6042
6043/*
6044%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6045% %
6046% %
6047% %
6048+ M o g r i f y I m a g e I n f o %
6049% %
6050% %
6051% %
6052%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6053%
6054% MogrifyImageInfo() applies image processing settings to the image as
6055% prescribed by command line options.
6056%
6057% The format of the MogrifyImageInfo method is:
6058%
6059% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6060% const char **argv,ExceptionInfo *exception)
6061%
6062% A description of each parameter follows:
6063%
6064% o image_info: the image info..
6065%
6066% o argc: Specifies a pointer to an integer describing the number of
6067% elements in the argument vector.
6068%
6069% o argv: Specifies a pointer to a text array containing the command line
6070% arguments.
6071%
6072% o exception: return any errors or warnings in this structure.
6073%
6074*/
6075WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6076 const int argc,const char **argv,ExceptionInfo *exception)
6077{
6078 const char
6079 *option;
6080
6081 GeometryInfo
6082 geometry_info;
6083
cristybb503372010-05-27 20:51:26 +00006084 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006085 count;
6086
cristybb503372010-05-27 20:51:26 +00006087 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006088 i;
6089
6090 /*
6091 Initialize method variables.
6092 */
6093 assert(image_info != (ImageInfo *) NULL);
6094 assert(image_info->signature == MagickSignature);
6095 if (image_info->debug != MagickFalse)
6096 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6097 image_info->filename);
6098 if (argc < 0)
6099 return(MagickTrue);
6100 /*
6101 Set the image settings.
6102 */
cristybb503372010-05-27 20:51:26 +00006103 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006104 {
6105 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006106 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006107 continue;
cristy042ee782011-04-22 18:48:30 +00006108 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006109 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006110 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006111 break;
6112 switch (*(option+1))
6113 {
6114 case 'a':
6115 {
6116 if (LocaleCompare("adjoin",option+1) == 0)
6117 {
6118 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6119 break;
6120 }
6121 if (LocaleCompare("antialias",option+1) == 0)
6122 {
6123 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6124 break;
6125 }
6126 if (LocaleCompare("attenuate",option+1) == 0)
6127 {
6128 if (*option == '+')
6129 {
6130 (void) DeleteImageOption(image_info,option+1);
6131 break;
6132 }
6133 (void) SetImageOption(image_info,option+1,argv[i+1]);
6134 break;
6135 }
6136 if (LocaleCompare("authenticate",option+1) == 0)
6137 {
6138 if (*option == '+')
6139 (void) CloneString(&image_info->authenticate,(char *) NULL);
6140 else
6141 (void) CloneString(&image_info->authenticate,argv[i+1]);
6142 break;
6143 }
6144 break;
6145 }
6146 case 'b':
6147 {
6148 if (LocaleCompare("background",option+1) == 0)
6149 {
6150 if (*option == '+')
6151 {
6152 (void) DeleteImageOption(image_info,option+1);
6153 (void) QueryColorDatabase(BackgroundColor,
6154 &image_info->background_color,exception);
6155 break;
6156 }
6157 (void) SetImageOption(image_info,option+1,argv[i+1]);
6158 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6159 exception);
6160 break;
6161 }
6162 if (LocaleCompare("bias",option+1) == 0)
6163 {
6164 if (*option == '+')
6165 {
6166 (void) SetImageOption(image_info,option+1,"0.0");
6167 break;
6168 }
6169 (void) SetImageOption(image_info,option+1,argv[i+1]);
6170 break;
6171 }
6172 if (LocaleCompare("black-point-compensation",option+1) == 0)
6173 {
6174 if (*option == '+')
6175 {
6176 (void) SetImageOption(image_info,option+1,"false");
6177 break;
6178 }
6179 (void) SetImageOption(image_info,option+1,"true");
6180 break;
6181 }
6182 if (LocaleCompare("blue-primary",option+1) == 0)
6183 {
6184 if (*option == '+')
6185 {
6186 (void) SetImageOption(image_info,option+1,"0.0");
6187 break;
6188 }
6189 (void) SetImageOption(image_info,option+1,argv[i+1]);
6190 break;
6191 }
6192 if (LocaleCompare("bordercolor",option+1) == 0)
6193 {
6194 if (*option == '+')
6195 {
6196 (void) DeleteImageOption(image_info,option+1);
6197 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6198 exception);
6199 break;
6200 }
6201 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6202 exception);
6203 (void) SetImageOption(image_info,option+1,argv[i+1]);
6204 break;
6205 }
6206 if (LocaleCompare("box",option+1) == 0)
6207 {
6208 if (*option == '+')
6209 {
6210 (void) SetImageOption(image_info,"undercolor","none");
6211 break;
6212 }
6213 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6214 break;
6215 }
6216 break;
6217 }
6218 case 'c':
6219 {
6220 if (LocaleCompare("cache",option+1) == 0)
6221 {
6222 MagickSizeType
6223 limit;
6224
6225 limit=MagickResourceInfinity;
6226 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006227 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006228 (void) SetMagickResourceLimit(MemoryResource,limit);
6229 (void) SetMagickResourceLimit(MapResource,2*limit);
6230 break;
6231 }
6232 if (LocaleCompare("caption",option+1) == 0)
6233 {
6234 if (*option == '+')
6235 {
6236 (void) DeleteImageOption(image_info,option+1);
6237 break;
6238 }
6239 (void) SetImageOption(image_info,option+1,argv[i+1]);
6240 break;
6241 }
6242 if (LocaleCompare("channel",option+1) == 0)
6243 {
6244 if (*option == '+')
6245 {
6246 image_info->channel=DefaultChannels;
6247 break;
6248 }
6249 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6250 break;
6251 }
6252 if (LocaleCompare("colors",option+1) == 0)
6253 {
cristye27293e2009-12-18 02:53:20 +00006254 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006255 break;
6256 }
6257 if (LocaleCompare("colorspace",option+1) == 0)
6258 {
6259 if (*option == '+')
6260 {
6261 image_info->colorspace=UndefinedColorspace;
6262 (void) SetImageOption(image_info,option+1,"undefined");
6263 break;
6264 }
cristy042ee782011-04-22 18:48:30 +00006265 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006266 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6267 (void) SetImageOption(image_info,option+1,argv[i+1]);
6268 break;
6269 }
cristy3ed852e2009-09-05 21:47:34 +00006270 if (LocaleCompare("comment",option+1) == 0)
6271 {
6272 if (*option == '+')
6273 {
6274 (void) DeleteImageOption(image_info,option+1);
6275 break;
6276 }
6277 (void) SetImageOption(image_info,option+1,argv[i+1]);
6278 break;
6279 }
6280 if (LocaleCompare("compose",option+1) == 0)
6281 {
6282 if (*option == '+')
6283 {
6284 (void) SetImageOption(image_info,option+1,"undefined");
6285 break;
6286 }
6287 (void) SetImageOption(image_info,option+1,argv[i+1]);
6288 break;
6289 }
6290 if (LocaleCompare("compress",option+1) == 0)
6291 {
6292 if (*option == '+')
6293 {
6294 image_info->compression=UndefinedCompression;
6295 (void) SetImageOption(image_info,option+1,"undefined");
6296 break;
6297 }
cristy042ee782011-04-22 18:48:30 +00006298 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006299 MagickCompressOptions,MagickFalse,argv[i+1]);
6300 (void) SetImageOption(image_info,option+1,argv[i+1]);
6301 break;
6302 }
6303 break;
6304 }
6305 case 'd':
6306 {
6307 if (LocaleCompare("debug",option+1) == 0)
6308 {
6309 if (*option == '+')
6310 (void) SetLogEventMask("none");
6311 else
6312 (void) SetLogEventMask(argv[i+1]);
6313 image_info->debug=IsEventLogging();
6314 break;
6315 }
6316 if (LocaleCompare("define",option+1) == 0)
6317 {
6318 if (*option == '+')
6319 {
6320 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6321 (void) DeleteImageRegistry(argv[i+1]+9);
6322 else
6323 (void) DeleteImageOption(image_info,argv[i+1]);
6324 break;
6325 }
6326 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6327 {
6328 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6329 exception);
6330 break;
6331 }
6332 (void) DefineImageOption(image_info,argv[i+1]);
6333 break;
6334 }
6335 if (LocaleCompare("delay",option+1) == 0)
6336 {
6337 if (*option == '+')
6338 {
6339 (void) SetImageOption(image_info,option+1,"0");
6340 break;
6341 }
6342 (void) SetImageOption(image_info,option+1,argv[i+1]);
6343 break;
6344 }
6345 if (LocaleCompare("density",option+1) == 0)
6346 {
6347 /*
6348 Set image density.
6349 */
6350 if (*option == '+')
6351 {
6352 if (image_info->density != (char *) NULL)
6353 image_info->density=DestroyString(image_info->density);
6354 (void) SetImageOption(image_info,option+1,"72");
6355 break;
6356 }
6357 (void) CloneString(&image_info->density,argv[i+1]);
6358 (void) SetImageOption(image_info,option+1,argv[i+1]);
6359 break;
6360 }
6361 if (LocaleCompare("depth",option+1) == 0)
6362 {
6363 if (*option == '+')
6364 {
6365 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6366 break;
6367 }
cristye27293e2009-12-18 02:53:20 +00006368 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006369 break;
6370 }
cristyc9b12952010-03-28 01:12:28 +00006371 if (LocaleCompare("direction",option+1) == 0)
6372 {
6373 if (*option == '+')
6374 {
6375 (void) SetImageOption(image_info,option+1,"undefined");
6376 break;
6377 }
6378 (void) SetImageOption(image_info,option+1,argv[i+1]);
6379 break;
6380 }
cristy3ed852e2009-09-05 21:47:34 +00006381 if (LocaleCompare("display",option+1) == 0)
6382 {
6383 if (*option == '+')
6384 {
6385 if (image_info->server_name != (char *) NULL)
6386 image_info->server_name=DestroyString(
6387 image_info->server_name);
6388 break;
6389 }
6390 (void) CloneString(&image_info->server_name,argv[i+1]);
6391 break;
6392 }
6393 if (LocaleCompare("dispose",option+1) == 0)
6394 {
6395 if (*option == '+')
6396 {
6397 (void) SetImageOption(image_info,option+1,"undefined");
6398 break;
6399 }
6400 (void) SetImageOption(image_info,option+1,argv[i+1]);
6401 break;
6402 }
6403 if (LocaleCompare("dither",option+1) == 0)
6404 {
6405 if (*option == '+')
6406 {
6407 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006408 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006409 break;
6410 }
6411 (void) SetImageOption(image_info,option+1,argv[i+1]);
6412 image_info->dither=MagickTrue;
6413 break;
6414 }
6415 break;
6416 }
6417 case 'e':
6418 {
6419 if (LocaleCompare("encoding",option+1) == 0)
6420 {
6421 if (*option == '+')
6422 {
6423 (void) SetImageOption(image_info,option+1,"undefined");
6424 break;
6425 }
6426 (void) SetImageOption(image_info,option+1,argv[i+1]);
6427 break;
6428 }
6429 if (LocaleCompare("endian",option+1) == 0)
6430 {
6431 if (*option == '+')
6432 {
6433 image_info->endian=UndefinedEndian;
6434 (void) SetImageOption(image_info,option+1,"undefined");
6435 break;
6436 }
cristy042ee782011-04-22 18:48:30 +00006437 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006438 MagickEndianOptions,MagickFalse,argv[i+1]);
6439 (void) SetImageOption(image_info,option+1,argv[i+1]);
6440 break;
6441 }
6442 if (LocaleCompare("extract",option+1) == 0)
6443 {
6444 /*
6445 Set image extract geometry.
6446 */
6447 if (*option == '+')
6448 {
6449 if (image_info->extract != (char *) NULL)
6450 image_info->extract=DestroyString(image_info->extract);
6451 break;
6452 }
6453 (void) CloneString(&image_info->extract,argv[i+1]);
6454 break;
6455 }
6456 break;
6457 }
6458 case 'f':
6459 {
6460 if (LocaleCompare("fill",option+1) == 0)
6461 {
6462 if (*option == '+')
6463 {
6464 (void) SetImageOption(image_info,option+1,"none");
6465 break;
6466 }
6467 (void) SetImageOption(image_info,option+1,argv[i+1]);
6468 break;
6469 }
6470 if (LocaleCompare("filter",option+1) == 0)
6471 {
6472 if (*option == '+')
6473 {
6474 (void) SetImageOption(image_info,option+1,"undefined");
6475 break;
6476 }
6477 (void) SetImageOption(image_info,option+1,argv[i+1]);
6478 break;
6479 }
6480 if (LocaleCompare("font",option+1) == 0)
6481 {
6482 if (*option == '+')
6483 {
6484 if (image_info->font != (char *) NULL)
6485 image_info->font=DestroyString(image_info->font);
6486 break;
6487 }
6488 (void) CloneString(&image_info->font,argv[i+1]);
6489 break;
6490 }
6491 if (LocaleCompare("format",option+1) == 0)
6492 {
6493 register const char
6494 *q;
6495
6496 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006497 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006498 image_info->ping=MagickFalse;
6499 (void) SetImageOption(image_info,option+1,argv[i+1]);
6500 break;
6501 }
6502 if (LocaleCompare("fuzz",option+1) == 0)
6503 {
6504 if (*option == '+')
6505 {
6506 image_info->fuzz=0.0;
6507 (void) SetImageOption(image_info,option+1,"0");
6508 break;
6509 }
cristyf2f27272009-12-17 14:48:46 +00006510 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006511 1.0);
6512 (void) SetImageOption(image_info,option+1,argv[i+1]);
6513 break;
6514 }
6515 break;
6516 }
6517 case 'g':
6518 {
6519 if (LocaleCompare("gravity",option+1) == 0)
6520 {
6521 if (*option == '+')
6522 {
6523 (void) SetImageOption(image_info,option+1,"undefined");
6524 break;
6525 }
6526 (void) SetImageOption(image_info,option+1,argv[i+1]);
6527 break;
6528 }
6529 if (LocaleCompare("green-primary",option+1) == 0)
6530 {
6531 if (*option == '+')
6532 {
6533 (void) SetImageOption(image_info,option+1,"0.0");
6534 break;
6535 }
6536 (void) SetImageOption(image_info,option+1,argv[i+1]);
6537 break;
6538 }
6539 break;
6540 }
6541 case 'i':
6542 {
6543 if (LocaleCompare("intent",option+1) == 0)
6544 {
6545 if (*option == '+')
6546 {
6547 (void) SetImageOption(image_info,option+1,"undefined");
6548 break;
6549 }
6550 (void) SetImageOption(image_info,option+1,argv[i+1]);
6551 break;
6552 }
6553 if (LocaleCompare("interlace",option+1) == 0)
6554 {
6555 if (*option == '+')
6556 {
6557 image_info->interlace=UndefinedInterlace;
6558 (void) SetImageOption(image_info,option+1,"undefined");
6559 break;
6560 }
cristy042ee782011-04-22 18:48:30 +00006561 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006562 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6563 (void) SetImageOption(image_info,option+1,argv[i+1]);
6564 break;
6565 }
cristyb32b90a2009-09-07 21:45:48 +00006566 if (LocaleCompare("interline-spacing",option+1) == 0)
6567 {
6568 if (*option == '+')
6569 {
6570 (void) SetImageOption(image_info,option+1,"undefined");
6571 break;
6572 }
6573 (void) SetImageOption(image_info,option+1,argv[i+1]);
6574 break;
6575 }
cristy3ed852e2009-09-05 21:47:34 +00006576 if (LocaleCompare("interpolate",option+1) == 0)
6577 {
6578 if (*option == '+')
6579 {
6580 (void) SetImageOption(image_info,option+1,"undefined");
6581 break;
6582 }
6583 (void) SetImageOption(image_info,option+1,argv[i+1]);
6584 break;
6585 }
6586 if (LocaleCompare("interword-spacing",option+1) == 0)
6587 {
6588 if (*option == '+')
6589 {
6590 (void) SetImageOption(image_info,option+1,"undefined");
6591 break;
6592 }
6593 (void) SetImageOption(image_info,option+1,argv[i+1]);
6594 break;
6595 }
6596 break;
6597 }
6598 case 'k':
6599 {
6600 if (LocaleCompare("kerning",option+1) == 0)
6601 {
6602 if (*option == '+')
6603 {
6604 (void) SetImageOption(image_info,option+1,"undefined");
6605 break;
6606 }
6607 (void) SetImageOption(image_info,option+1,argv[i+1]);
6608 break;
6609 }
6610 break;
6611 }
6612 case 'l':
6613 {
6614 if (LocaleCompare("label",option+1) == 0)
6615 {
6616 if (*option == '+')
6617 {
6618 (void) DeleteImageOption(image_info,option+1);
6619 break;
6620 }
6621 (void) SetImageOption(image_info,option+1,argv[i+1]);
6622 break;
6623 }
6624 if (LocaleCompare("limit",option+1) == 0)
6625 {
6626 MagickSizeType
6627 limit;
6628
6629 ResourceType
6630 type;
6631
6632 if (*option == '+')
6633 break;
cristy042ee782011-04-22 18:48:30 +00006634 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006635 MagickFalse,argv[i+1]);
6636 limit=MagickResourceInfinity;
6637 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006638 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006639 (void) SetMagickResourceLimit(type,limit);
6640 break;
6641 }
6642 if (LocaleCompare("list",option+1) == 0)
6643 {
cristybb503372010-05-27 20:51:26 +00006644 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006645 list;
6646
6647 /*
6648 Display configuration list.
6649 */
cristy042ee782011-04-22 18:48:30 +00006650 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006651 switch (list)
6652 {
6653 case MagickCoderOptions:
6654 {
6655 (void) ListCoderInfo((FILE *) NULL,exception);
6656 break;
6657 }
6658 case MagickColorOptions:
6659 {
6660 (void) ListColorInfo((FILE *) NULL,exception);
6661 break;
6662 }
6663 case MagickConfigureOptions:
6664 {
6665 (void) ListConfigureInfo((FILE *) NULL,exception);
6666 break;
6667 }
6668 case MagickDelegateOptions:
6669 {
6670 (void) ListDelegateInfo((FILE *) NULL,exception);
6671 break;
6672 }
6673 case MagickFontOptions:
6674 {
6675 (void) ListTypeInfo((FILE *) NULL,exception);
6676 break;
6677 }
6678 case MagickFormatOptions:
6679 {
6680 (void) ListMagickInfo((FILE *) NULL,exception);
6681 break;
6682 }
6683 case MagickLocaleOptions:
6684 {
6685 (void) ListLocaleInfo((FILE *) NULL,exception);
6686 break;
6687 }
6688 case MagickLogOptions:
6689 {
6690 (void) ListLogInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickMagicOptions:
6694 {
6695 (void) ListMagicInfo((FILE *) NULL,exception);
6696 break;
6697 }
6698 case MagickMimeOptions:
6699 {
6700 (void) ListMimeInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickModuleOptions:
6704 {
6705 (void) ListModuleInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickPolicyOptions:
6709 {
6710 (void) ListPolicyInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickResourceOptions:
6714 {
6715 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickThresholdOptions:
6719 {
6720 (void) ListThresholdMaps((FILE *) NULL,exception);
6721 break;
6722 }
6723 default:
6724 {
cristy042ee782011-04-22 18:48:30 +00006725 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006726 exception);
6727 break;
6728 }
6729 }
cristyaeb2cbc2010-05-07 13:28:58 +00006730 break;
cristy3ed852e2009-09-05 21:47:34 +00006731 }
6732 if (LocaleCompare("log",option+1) == 0)
6733 {
6734 if (*option == '+')
6735 break;
6736 (void) SetLogFormat(argv[i+1]);
6737 break;
6738 }
6739 if (LocaleCompare("loop",option+1) == 0)
6740 {
6741 if (*option == '+')
6742 {
6743 (void) SetImageOption(image_info,option+1,"0");
6744 break;
6745 }
6746 (void) SetImageOption(image_info,option+1,argv[i+1]);
6747 break;
6748 }
6749 break;
6750 }
6751 case 'm':
6752 {
6753 if (LocaleCompare("matte",option+1) == 0)
6754 {
6755 if (*option == '+')
6756 {
6757 (void) SetImageOption(image_info,option+1,"false");
6758 break;
6759 }
6760 (void) SetImageOption(image_info,option+1,"true");
6761 break;
6762 }
6763 if (LocaleCompare("mattecolor",option+1) == 0)
6764 {
6765 if (*option == '+')
6766 {
6767 (void) SetImageOption(image_info,option+1,argv[i+1]);
6768 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6769 exception);
6770 break;
6771 }
6772 (void) SetImageOption(image_info,option+1,argv[i+1]);
6773 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6774 exception);
6775 break;
6776 }
6777 if (LocaleCompare("monitor",option+1) == 0)
6778 {
6779 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6780 (void *) NULL);
6781 break;
6782 }
6783 if (LocaleCompare("monochrome",option+1) == 0)
6784 {
6785 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6786 break;
6787 }
6788 break;
6789 }
6790 case 'o':
6791 {
6792 if (LocaleCompare("orient",option+1) == 0)
6793 {
6794 if (*option == '+')
6795 {
6796 image_info->orientation=UndefinedOrientation;
6797 (void) SetImageOption(image_info,option+1,"undefined");
6798 break;
6799 }
cristy042ee782011-04-22 18:48:30 +00006800 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006801 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006802 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006803 break;
6804 }
6805 }
6806 case 'p':
6807 {
6808 if (LocaleCompare("page",option+1) == 0)
6809 {
6810 char
6811 *canonical_page,
6812 page[MaxTextExtent];
6813
6814 const char
6815 *image_option;
6816
6817 MagickStatusType
6818 flags;
6819
6820 RectangleInfo
6821 geometry;
6822
6823 if (*option == '+')
6824 {
6825 (void) DeleteImageOption(image_info,option+1);
6826 (void) CloneString(&image_info->page,(char *) NULL);
6827 break;
6828 }
6829 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6830 image_option=GetImageOption(image_info,"page");
6831 if (image_option != (const char *) NULL)
6832 flags=ParseAbsoluteGeometry(image_option,&geometry);
6833 canonical_page=GetPageGeometry(argv[i+1]);
6834 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6835 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006836 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006837 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006838 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006839 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006840 (unsigned long) geometry.width,(unsigned long) geometry.height,
6841 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006842 (void) SetImageOption(image_info,option+1,page);
6843 (void) CloneString(&image_info->page,page);
6844 break;
6845 }
6846 if (LocaleCompare("pen",option+1) == 0)
6847 {
6848 if (*option == '+')
6849 {
6850 (void) SetImageOption(image_info,option+1,"none");
6851 break;
6852 }
6853 (void) SetImageOption(image_info,option+1,argv[i+1]);
6854 break;
6855 }
6856 if (LocaleCompare("ping",option+1) == 0)
6857 {
6858 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6859 break;
6860 }
6861 if (LocaleCompare("pointsize",option+1) == 0)
6862 {
6863 if (*option == '+')
6864 geometry_info.rho=0.0;
6865 else
6866 (void) ParseGeometry(argv[i+1],&geometry_info);
6867 image_info->pointsize=geometry_info.rho;
6868 break;
6869 }
cristye7f51092010-01-17 00:39:37 +00006870 if (LocaleCompare("precision",option+1) == 0)
6871 {
cristybf2766a2010-01-17 03:33:23 +00006872 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006873 break;
6874 }
cristy3ed852e2009-09-05 21:47:34 +00006875 if (LocaleCompare("preview",option+1) == 0)
6876 {
6877 /*
6878 Preview image.
6879 */
6880 if (*option == '+')
6881 {
6882 image_info->preview_type=UndefinedPreview;
6883 break;
6884 }
cristy042ee782011-04-22 18:48:30 +00006885 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006886 MagickPreviewOptions,MagickFalse,argv[i+1]);
6887 break;
6888 }
6889 break;
6890 }
6891 case 'q':
6892 {
6893 if (LocaleCompare("quality",option+1) == 0)
6894 {
6895 /*
6896 Set image compression quality.
6897 */
6898 if (*option == '+')
6899 {
6900 image_info->quality=UndefinedCompressionQuality;
6901 (void) SetImageOption(image_info,option+1,"0");
6902 break;
6903 }
cristye27293e2009-12-18 02:53:20 +00006904 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006905 (void) SetImageOption(image_info,option+1,argv[i+1]);
6906 break;
6907 }
6908 if (LocaleCompare("quiet",option+1) == 0)
6909 {
6910 static WarningHandler
6911 warning_handler = (WarningHandler) NULL;
6912
6913 if (*option == '+')
6914 {
6915 /*
6916 Restore error or warning messages.
6917 */
6918 warning_handler=SetWarningHandler(warning_handler);
6919 break;
6920 }
6921 /*
6922 Suppress error or warning messages.
6923 */
6924 warning_handler=SetWarningHandler((WarningHandler) NULL);
6925 break;
6926 }
6927 break;
6928 }
6929 case 'r':
6930 {
6931 if (LocaleCompare("red-primary",option+1) == 0)
6932 {
6933 if (*option == '+')
6934 {
6935 (void) SetImageOption(image_info,option+1,"0.0");
6936 break;
6937 }
6938 (void) SetImageOption(image_info,option+1,argv[i+1]);
6939 break;
6940 }
6941 break;
6942 }
6943 case 's':
6944 {
6945 if (LocaleCompare("sampling-factor",option+1) == 0)
6946 {
6947 /*
6948 Set image sampling factor.
6949 */
6950 if (*option == '+')
6951 {
6952 if (image_info->sampling_factor != (char *) NULL)
6953 image_info->sampling_factor=DestroyString(
6954 image_info->sampling_factor);
6955 break;
6956 }
6957 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6958 break;
6959 }
6960 if (LocaleCompare("scene",option+1) == 0)
6961 {
6962 /*
6963 Set image scene.
6964 */
6965 if (*option == '+')
6966 {
6967 image_info->scene=0;
6968 (void) SetImageOption(image_info,option+1,"0");
6969 break;
6970 }
cristye27293e2009-12-18 02:53:20 +00006971 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006972 (void) SetImageOption(image_info,option+1,argv[i+1]);
6973 break;
6974 }
6975 if (LocaleCompare("seed",option+1) == 0)
6976 {
cristybb503372010-05-27 20:51:26 +00006977 size_t
cristy3ed852e2009-09-05 21:47:34 +00006978 seed;
6979
6980 if (*option == '+')
6981 {
cristybb503372010-05-27 20:51:26 +00006982 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006983 SeedPseudoRandomGenerator(seed);
6984 break;
6985 }
cristye27293e2009-12-18 02:53:20 +00006986 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006987 SeedPseudoRandomGenerator(seed);
6988 break;
6989 }
6990 if (LocaleCompare("size",option+1) == 0)
6991 {
6992 if (*option == '+')
6993 {
6994 if (image_info->size != (char *) NULL)
6995 image_info->size=DestroyString(image_info->size);
6996 break;
6997 }
6998 (void) CloneString(&image_info->size,argv[i+1]);
6999 break;
7000 }
7001 if (LocaleCompare("stroke",option+1) == 0)
7002 {
7003 if (*option == '+')
7004 {
7005 (void) SetImageOption(image_info,option+1,"none");
7006 break;
7007 }
7008 (void) SetImageOption(image_info,option+1,argv[i+1]);
7009 break;
7010 }
7011 if (LocaleCompare("strokewidth",option+1) == 0)
7012 {
7013 if (*option == '+')
7014 {
7015 (void) SetImageOption(image_info,option+1,"0");
7016 break;
7017 }
7018 (void) SetImageOption(image_info,option+1,argv[i+1]);
7019 break;
7020 }
cristyd9a29192010-10-16 16:49:53 +00007021 if (LocaleCompare("synchronize",option+1) == 0)
7022 {
7023 if (*option == '+')
7024 {
7025 image_info->synchronize=MagickFalse;
7026 break;
7027 }
7028 image_info->synchronize=MagickTrue;
7029 break;
7030 }
cristy3ed852e2009-09-05 21:47:34 +00007031 break;
7032 }
7033 case 't':
7034 {
7035 if (LocaleCompare("taint",option+1) == 0)
7036 {
7037 if (*option == '+')
7038 {
7039 (void) SetImageOption(image_info,option+1,"false");
7040 break;
7041 }
7042 (void) SetImageOption(image_info,option+1,"true");
7043 break;
7044 }
7045 if (LocaleCompare("texture",option+1) == 0)
7046 {
7047 if (*option == '+')
7048 {
7049 if (image_info->texture != (char *) NULL)
7050 image_info->texture=DestroyString(image_info->texture);
7051 break;
7052 }
7053 (void) CloneString(&image_info->texture,argv[i+1]);
7054 break;
7055 }
7056 if (LocaleCompare("tile-offset",option+1) == 0)
7057 {
7058 if (*option == '+')
7059 {
7060 (void) SetImageOption(image_info,option+1,"0");
7061 break;
7062 }
7063 (void) SetImageOption(image_info,option+1,argv[i+1]);
7064 break;
7065 }
7066 if (LocaleCompare("transparent-color",option+1) == 0)
7067 {
7068 if (*option == '+')
7069 {
7070 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7071 (void) SetImageOption(image_info,option+1,"none");
7072 break;
7073 }
7074 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7075 exception);
7076 (void) SetImageOption(image_info,option+1,argv[i+1]);
7077 break;
7078 }
7079 if (LocaleCompare("type",option+1) == 0)
7080 {
7081 if (*option == '+')
7082 {
cristy5f1c1ff2010-12-23 21:38:06 +00007083 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007084 (void) SetImageOption(image_info,option+1,"undefined");
7085 break;
7086 }
cristy042ee782011-04-22 18:48:30 +00007087 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007088 MagickFalse,argv[i+1]);
7089 (void) SetImageOption(image_info,option+1,argv[i+1]);
7090 break;
7091 }
7092 break;
7093 }
7094 case 'u':
7095 {
7096 if (LocaleCompare("undercolor",option+1) == 0)
7097 {
7098 if (*option == '+')
7099 {
7100 (void) DeleteImageOption(image_info,option+1);
7101 break;
7102 }
7103 (void) SetImageOption(image_info,option+1,argv[i+1]);
7104 break;
7105 }
7106 if (LocaleCompare("units",option+1) == 0)
7107 {
7108 if (*option == '+')
7109 {
7110 image_info->units=UndefinedResolution;
7111 (void) SetImageOption(image_info,option+1,"undefined");
7112 break;
7113 }
cristy042ee782011-04-22 18:48:30 +00007114 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007115 MagickResolutionOptions,MagickFalse,argv[i+1]);
7116 (void) SetImageOption(image_info,option+1,argv[i+1]);
7117 break;
7118 }
7119 break;
7120 }
7121 case 'v':
7122 {
7123 if (LocaleCompare("verbose",option+1) == 0)
7124 {
7125 if (*option == '+')
7126 {
7127 image_info->verbose=MagickFalse;
7128 break;
7129 }
7130 image_info->verbose=MagickTrue;
7131 image_info->ping=MagickFalse;
7132 break;
7133 }
7134 if (LocaleCompare("view",option+1) == 0)
7135 {
7136 if (*option == '+')
7137 {
7138 if (image_info->view != (char *) NULL)
7139 image_info->view=DestroyString(image_info->view);
7140 break;
7141 }
7142 (void) CloneString(&image_info->view,argv[i+1]);
7143 break;
7144 }
7145 if (LocaleCompare("virtual-pixel",option+1) == 0)
7146 {
7147 if (*option == '+')
7148 {
7149 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7150 (void) SetImageOption(image_info,option+1,"undefined");
7151 break;
7152 }
7153 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007154 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007155 argv[i+1]);
7156 (void) SetImageOption(image_info,option+1,argv[i+1]);
7157 break;
7158 }
7159 break;
7160 }
7161 case 'w':
7162 {
7163 if (LocaleCompare("white-point",option+1) == 0)
7164 {
7165 if (*option == '+')
7166 {
7167 (void) SetImageOption(image_info,option+1,"0.0");
7168 break;
7169 }
7170 (void) SetImageOption(image_info,option+1,argv[i+1]);
7171 break;
7172 }
7173 break;
7174 }
7175 default:
7176 break;
7177 }
7178 i+=count;
7179 }
7180 return(MagickTrue);
7181}
7182
7183/*
7184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7185% %
7186% %
7187% %
7188+ M o g r i f y I m a g e L i s t %
7189% %
7190% %
7191% %
7192%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7193%
7194% MogrifyImageList() applies any command line options that might affect the
7195% entire image list (e.g. -append, -coalesce, etc.).
7196%
7197% The format of the MogrifyImage method is:
7198%
7199% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7200% const char **argv,Image **images,ExceptionInfo *exception)
7201%
7202% A description of each parameter follows:
7203%
7204% o image_info: the image info..
7205%
7206% o argc: Specifies a pointer to an integer describing the number of
7207% elements in the argument vector.
7208%
7209% o argv: Specifies a pointer to a text array containing the command line
7210% arguments.
7211%
anthonye9c27192011-03-27 08:07:06 +00007212% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007213%
7214% o exception: return any errors or warnings in this structure.
7215%
7216*/
7217WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7218 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7219{
cristy3ed852e2009-09-05 21:47:34 +00007220 const char
7221 *option;
7222
cristy6b3da3a2010-06-20 02:21:46 +00007223 ImageInfo
7224 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007225
7226 MagickStatusType
7227 status;
7228
7229 QuantizeInfo
7230 *quantize_info;
7231
cristybb503372010-05-27 20:51:26 +00007232 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007233 i;
7234
cristy6b3da3a2010-06-20 02:21:46 +00007235 ssize_t
7236 count,
7237 index;
7238
cristy3ed852e2009-09-05 21:47:34 +00007239 /*
7240 Apply options to the image list.
7241 */
7242 assert(image_info != (ImageInfo *) NULL);
7243 assert(image_info->signature == MagickSignature);
7244 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007245 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007246 assert((*images)->signature == MagickSignature);
7247 if ((*images)->debug != MagickFalse)
7248 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7249 (*images)->filename);
7250 if ((argc <= 0) || (*argv == (char *) NULL))
7251 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007252 mogrify_info=CloneImageInfo(image_info);
7253 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007254 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007255 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007256 {
cristy74fe8f12009-10-03 19:09:01 +00007257 if (*images == (Image *) NULL)
7258 break;
cristy3ed852e2009-09-05 21:47:34 +00007259 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007260 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007261 continue;
cristy042ee782011-04-22 18:48:30 +00007262 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007263 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007264 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007265 break;
cristy6b3da3a2010-06-20 02:21:46 +00007266 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007267 switch (*(option+1))
7268 {
7269 case 'a':
7270 {
7271 if (LocaleCompare("affinity",option+1) == 0)
7272 {
cristy6b3da3a2010-06-20 02:21:46 +00007273 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007274 if (*option == '+')
7275 {
7276 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7277 InheritException(exception,&(*images)->exception);
7278 break;
7279 }
7280 i++;
7281 break;
7282 }
7283 if (LocaleCompare("append",option+1) == 0)
7284 {
7285 Image
7286 *append_image;
7287
cristy6b3da3a2010-06-20 02:21:46 +00007288 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007289 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7290 MagickFalse,exception);
7291 if (append_image == (Image *) NULL)
7292 {
7293 status=MagickFalse;
7294 break;
7295 }
7296 *images=DestroyImageList(*images);
7297 *images=append_image;
7298 break;
7299 }
7300 if (LocaleCompare("average",option+1) == 0)
7301 {
7302 Image
7303 *average_image;
7304
cristyd18ae7c2010-03-07 17:39:52 +00007305 /*
7306 Average an image sequence (deprecated).
7307 */
cristy6b3da3a2010-06-20 02:21:46 +00007308 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007309 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7310 exception);
cristy3ed852e2009-09-05 21:47:34 +00007311 if (average_image == (Image *) NULL)
7312 {
7313 status=MagickFalse;
7314 break;
7315 }
7316 *images=DestroyImageList(*images);
7317 *images=average_image;
7318 break;
7319 }
7320 break;
7321 }
7322 case 'c':
7323 {
7324 if (LocaleCompare("channel",option+1) == 0)
7325 {
cristyf4ad9df2011-07-08 16:49:03 +00007326 ChannelType
7327 channel;
7328
cristy3ed852e2009-09-05 21:47:34 +00007329 if (*option == '+')
7330 {
7331 channel=DefaultChannels;
7332 break;
7333 }
7334 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007335 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007336 break;
7337 }
7338 if (LocaleCompare("clut",option+1) == 0)
7339 {
7340 Image
7341 *clut_image,
7342 *image;
7343
cristy6b3da3a2010-06-20 02:21:46 +00007344 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007345 image=RemoveFirstImageFromList(images);
7346 clut_image=RemoveFirstImageFromList(images);
7347 if (clut_image == (Image *) NULL)
7348 {
7349 status=MagickFalse;
7350 break;
7351 }
cristyf89cb1d2011-07-07 01:24:37 +00007352 (void) ClutImage(image,clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007353 clut_image=DestroyImage(clut_image);
7354 InheritException(exception,&image->exception);
7355 *images=DestroyImageList(*images);
7356 *images=image;
7357 break;
7358 }
7359 if (LocaleCompare("coalesce",option+1) == 0)
7360 {
7361 Image
7362 *coalesce_image;
7363
cristy6b3da3a2010-06-20 02:21:46 +00007364 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007365 coalesce_image=CoalesceImages(*images,exception);
7366 if (coalesce_image == (Image *) NULL)
7367 {
7368 status=MagickFalse;
7369 break;
7370 }
7371 *images=DestroyImageList(*images);
7372 *images=coalesce_image;
7373 break;
7374 }
7375 if (LocaleCompare("combine",option+1) == 0)
7376 {
7377 Image
7378 *combine_image;
7379
cristy6b3da3a2010-06-20 02:21:46 +00007380 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007381 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007382 if (combine_image == (Image *) NULL)
7383 {
7384 status=MagickFalse;
7385 break;
7386 }
7387 *images=DestroyImageList(*images);
7388 *images=combine_image;
7389 break;
7390 }
7391 if (LocaleCompare("composite",option+1) == 0)
7392 {
7393 Image
7394 *mask_image,
7395 *composite_image,
7396 *image;
7397
7398 RectangleInfo
7399 geometry;
7400
cristy6b3da3a2010-06-20 02:21:46 +00007401 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007402 image=RemoveFirstImageFromList(images);
7403 composite_image=RemoveFirstImageFromList(images);
7404 if (composite_image == (Image *) NULL)
7405 {
7406 status=MagickFalse;
7407 break;
7408 }
7409 (void) TransformImage(&composite_image,(char *) NULL,
7410 composite_image->geometry);
7411 SetGeometry(composite_image,&geometry);
7412 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7413 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7414 &geometry);
7415 mask_image=RemoveFirstImageFromList(images);
7416 if (mask_image != (Image *) NULL)
7417 {
7418 if ((image->compose == DisplaceCompositeOp) ||
7419 (image->compose == DistortCompositeOp))
7420 {
7421 /*
7422 Merge Y displacement into X displacement image.
7423 */
7424 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7425 mask_image,0,0);
7426 mask_image=DestroyImage(mask_image);
7427 }
7428 else
7429 {
7430 /*
7431 Set a blending mask for the composition.
7432 */
anthonya129f702011-04-14 01:08:48 +00007433 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007434 image->mask=mask_image;
7435 (void) NegateImage(image->mask,MagickFalse);
7436 }
7437 }
cristyf4ad9df2011-07-08 16:49:03 +00007438 (void) CompositeImage(image,image->compose,composite_image,
7439 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007440 if (mask_image != (Image *) NULL)
7441 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007442 composite_image=DestroyImage(composite_image);
7443 InheritException(exception,&image->exception);
7444 *images=DestroyImageList(*images);
7445 *images=image;
7446 break;
7447 }
anthony9f4f0342011-03-28 11:47:22 +00007448#if 0
7449This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007450 if (LocaleCompare("crop",option+1) == 0)
7451 {
7452 MagickStatusType
7453 flags;
7454
7455 RectangleInfo
7456 geometry;
7457
anthonye9c27192011-03-27 08:07:06 +00007458 /*
anthony9f4f0342011-03-28 11:47:22 +00007459 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007460 */
cristy6b3da3a2010-06-20 02:21:46 +00007461 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007462 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7463 if (((geometry.width == 0) && (geometry.height == 0)) ||
7464 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7465 break;
7466 (void) TransformImages(images,argv[i+1],(char *) NULL);
7467 InheritException(exception,&(*images)->exception);
7468 break;
7469 }
anthony9f4f0342011-03-28 11:47:22 +00007470#endif
cristy3ed852e2009-09-05 21:47:34 +00007471 break;
7472 }
7473 case 'd':
7474 {
7475 if (LocaleCompare("deconstruct",option+1) == 0)
7476 {
7477 Image
7478 *deconstruct_image;
7479
cristy6b3da3a2010-06-20 02:21:46 +00007480 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007481 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007482 exception);
cristy3ed852e2009-09-05 21:47:34 +00007483 if (deconstruct_image == (Image *) NULL)
7484 {
7485 status=MagickFalse;
7486 break;
7487 }
7488 *images=DestroyImageList(*images);
7489 *images=deconstruct_image;
7490 break;
7491 }
7492 if (LocaleCompare("delete",option+1) == 0)
7493 {
7494 if (*option == '+')
7495 DeleteImages(images,"-1",exception);
7496 else
7497 DeleteImages(images,argv[i+1],exception);
7498 break;
7499 }
7500 if (LocaleCompare("dither",option+1) == 0)
7501 {
7502 if (*option == '+')
7503 {
7504 quantize_info->dither=MagickFalse;
7505 break;
7506 }
7507 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007508 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007509 MagickDitherOptions,MagickFalse,argv[i+1]);
7510 break;
7511 }
cristyecb10ff2011-03-22 13:14:03 +00007512 if (LocaleCompare("duplicate",option+1) == 0)
7513 {
cristy72988482011-03-29 16:34:38 +00007514 Image
7515 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007516
anthony2b6bcae2011-03-23 13:05:34 +00007517 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007518 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7519 else
7520 {
7521 const char
7522 *p;
7523
anthony2b6bcae2011-03-23 13:05:34 +00007524 size_t
7525 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007526
anthony2b6bcae2011-03-23 13:05:34 +00007527 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007528 p=strchr(argv[i+1],',');
7529 if (p == (const char *) NULL)
7530 duplicate_images=DuplicateImages(*images,number_duplicates,
7531 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007532 else
cristy72988482011-03-29 16:34:38 +00007533 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7534 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007535 }
7536 AppendImageToList(images, duplicate_images);
7537 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007538 break;
7539 }
cristy3ed852e2009-09-05 21:47:34 +00007540 break;
7541 }
cristyd18ae7c2010-03-07 17:39:52 +00007542 case 'e':
7543 {
7544 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7545 {
7546 Image
7547 *evaluate_image;
7548
7549 MagickEvaluateOperator
7550 op;
7551
cristy6b3da3a2010-06-20 02:21:46 +00007552 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007553 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007554 MagickFalse,argv[i+1]);
7555 evaluate_image=EvaluateImages(*images,op,exception);
7556 if (evaluate_image == (Image *) NULL)
7557 {
7558 status=MagickFalse;
7559 break;
7560 }
7561 *images=DestroyImageList(*images);
7562 *images=evaluate_image;
7563 break;
7564 }
7565 break;
7566 }
cristy3ed852e2009-09-05 21:47:34 +00007567 case 'f':
7568 {
cristyf0a247f2009-10-04 00:20:03 +00007569 if (LocaleCompare("fft",option+1) == 0)
7570 {
7571 Image
7572 *fourier_image;
7573
7574 /*
7575 Implements the discrete Fourier transform (DFT).
7576 */
cristy6b3da3a2010-06-20 02:21:46 +00007577 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007578 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7579 MagickTrue : MagickFalse,exception);
7580 if (fourier_image == (Image *) NULL)
7581 break;
7582 *images=DestroyImage(*images);
7583 *images=fourier_image;
7584 break;
7585 }
cristy3ed852e2009-09-05 21:47:34 +00007586 if (LocaleCompare("flatten",option+1) == 0)
7587 {
7588 Image
7589 *flatten_image;
7590
cristy6b3da3a2010-06-20 02:21:46 +00007591 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007592 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7593 if (flatten_image == (Image *) NULL)
7594 break;
7595 *images=DestroyImageList(*images);
7596 *images=flatten_image;
7597 break;
7598 }
7599 if (LocaleCompare("fx",option+1) == 0)
7600 {
7601 Image
7602 *fx_image;
7603
cristy6b3da3a2010-06-20 02:21:46 +00007604 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007605 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007606 if (fx_image == (Image *) NULL)
7607 {
7608 status=MagickFalse;
7609 break;
7610 }
7611 *images=DestroyImageList(*images);
7612 *images=fx_image;
7613 break;
7614 }
7615 break;
7616 }
7617 case 'h':
7618 {
7619 if (LocaleCompare("hald-clut",option+1) == 0)
7620 {
7621 Image
7622 *hald_image,
7623 *image;
7624
cristy6b3da3a2010-06-20 02:21:46 +00007625 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007626 image=RemoveFirstImageFromList(images);
7627 hald_image=RemoveFirstImageFromList(images);
7628 if (hald_image == (Image *) NULL)
7629 {
7630 status=MagickFalse;
7631 break;
7632 }
cristyf89cb1d2011-07-07 01:24:37 +00007633 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007634 hald_image=DestroyImage(hald_image);
7635 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007636 if (*images != (Image *) NULL)
7637 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007638 *images=image;
7639 break;
7640 }
7641 break;
7642 }
7643 case 'i':
7644 {
7645 if (LocaleCompare("ift",option+1) == 0)
7646 {
7647 Image
cristy8587f882009-11-13 20:28:49 +00007648 *fourier_image,
7649 *magnitude_image,
7650 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007651
7652 /*
7653 Implements the inverse fourier discrete Fourier transform (DFT).
7654 */
cristy6b3da3a2010-06-20 02:21:46 +00007655 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007656 magnitude_image=RemoveFirstImageFromList(images);
7657 phase_image=RemoveFirstImageFromList(images);
7658 if (phase_image == (Image *) NULL)
7659 {
7660 status=MagickFalse;
7661 break;
7662 }
7663 fourier_image=InverseFourierTransformImage(magnitude_image,
7664 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007665 if (fourier_image == (Image *) NULL)
7666 break;
cristy0aff6ea2009-11-14 01:40:53 +00007667 if (*images != (Image *) NULL)
7668 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007669 *images=fourier_image;
7670 break;
7671 }
7672 if (LocaleCompare("insert",option+1) == 0)
7673 {
7674 Image
7675 *p,
7676 *q;
7677
7678 index=0;
7679 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007680 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007681 p=RemoveLastImageFromList(images);
7682 if (p == (Image *) NULL)
7683 {
7684 (void) ThrowMagickException(exception,GetMagickModule(),
7685 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7686 status=MagickFalse;
7687 break;
7688 }
7689 q=p;
7690 if (index == 0)
7691 PrependImageToList(images,q);
7692 else
cristybb503372010-05-27 20:51:26 +00007693 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007694 AppendImageToList(images,q);
7695 else
7696 {
7697 q=GetImageFromList(*images,index-1);
7698 if (q == (Image *) NULL)
7699 {
7700 (void) ThrowMagickException(exception,GetMagickModule(),
7701 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7702 status=MagickFalse;
7703 break;
7704 }
7705 InsertImageInList(&q,p);
7706 }
7707 *images=GetFirstImageInList(q);
7708 break;
7709 }
7710 break;
7711 }
7712 case 'l':
7713 {
7714 if (LocaleCompare("layers",option+1) == 0)
7715 {
7716 Image
7717 *layers;
7718
7719 ImageLayerMethod
7720 method;
7721
cristy6b3da3a2010-06-20 02:21:46 +00007722 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007723 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007724 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007725 MagickFalse,argv[i+1]);
7726 switch (method)
7727 {
7728 case CoalesceLayer:
7729 {
7730 layers=CoalesceImages(*images,exception);
7731 break;
7732 }
7733 case CompareAnyLayer:
7734 case CompareClearLayer:
7735 case CompareOverlayLayer:
7736 default:
7737 {
cristy8a9106f2011-07-05 14:39:26 +00007738 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007739 break;
7740 }
7741 case MergeLayer:
7742 case FlattenLayer:
7743 case MosaicLayer:
7744 case TrimBoundsLayer:
7745 {
7746 layers=MergeImageLayers(*images,method,exception);
7747 break;
7748 }
7749 case DisposeLayer:
7750 {
7751 layers=DisposeImages(*images,exception);
7752 break;
7753 }
7754 case OptimizeImageLayer:
7755 {
7756 layers=OptimizeImageLayers(*images,exception);
7757 break;
7758 }
7759 case OptimizePlusLayer:
7760 {
7761 layers=OptimizePlusImageLayers(*images,exception);
7762 break;
7763 }
7764 case OptimizeTransLayer:
7765 {
7766 OptimizeImageTransparency(*images,exception);
7767 break;
7768 }
7769 case RemoveDupsLayer:
7770 {
7771 RemoveDuplicateLayers(images,exception);
7772 break;
7773 }
7774 case RemoveZeroLayer:
7775 {
7776 RemoveZeroDelayLayers(images,exception);
7777 break;
7778 }
7779 case OptimizeLayer:
7780 {
7781 /*
7782 General Purpose, GIF Animation Optimizer.
7783 */
7784 layers=CoalesceImages(*images,exception);
7785 if (layers == (Image *) NULL)
7786 {
7787 status=MagickFalse;
7788 break;
7789 }
7790 InheritException(exception,&layers->exception);
7791 *images=DestroyImageList(*images);
7792 *images=layers;
7793 layers=OptimizeImageLayers(*images,exception);
7794 if (layers == (Image *) NULL)
7795 {
7796 status=MagickFalse;
7797 break;
7798 }
7799 InheritException(exception,&layers->exception);
7800 *images=DestroyImageList(*images);
7801 *images=layers;
7802 layers=(Image *) NULL;
7803 OptimizeImageTransparency(*images,exception);
7804 InheritException(exception,&(*images)->exception);
7805 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7806 break;
7807 }
7808 case CompositeLayer:
7809 {
7810 CompositeOperator
7811 compose;
7812
7813 Image
7814 *source;
7815
7816 RectangleInfo
7817 geometry;
7818
7819 /*
7820 Split image sequence at the first 'NULL:' image.
7821 */
7822 source=(*images);
7823 while (source != (Image *) NULL)
7824 {
7825 source=GetNextImageInList(source);
7826 if ((source != (Image *) NULL) &&
7827 (LocaleCompare(source->magick,"NULL") == 0))
7828 break;
7829 }
7830 if (source != (Image *) NULL)
7831 {
7832 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7833 (GetNextImageInList(source) == (Image *) NULL))
7834 source=(Image *) NULL;
7835 else
7836 {
7837 /*
7838 Separate the two lists, junk the null: image.
7839 */
7840 source=SplitImageList(source->previous);
7841 DeleteImageFromList(&source);
7842 }
7843 }
7844 if (source == (Image *) NULL)
7845 {
7846 (void) ThrowMagickException(exception,GetMagickModule(),
7847 OptionError,"MissingNullSeparator","layers Composite");
7848 status=MagickFalse;
7849 break;
7850 }
7851 /*
7852 Adjust offset with gravity and virtual canvas.
7853 */
7854 SetGeometry(*images,&geometry);
7855 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7856 geometry.width=source->page.width != 0 ?
7857 source->page.width : source->columns;
7858 geometry.height=source->page.height != 0 ?
7859 source->page.height : source->rows;
7860 GravityAdjustGeometry((*images)->page.width != 0 ?
7861 (*images)->page.width : (*images)->columns,
7862 (*images)->page.height != 0 ? (*images)->page.height :
7863 (*images)->rows,(*images)->gravity,&geometry);
7864 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007865 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007866 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007867 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007868 MagickComposeOptions,MagickFalse,option);
7869 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7870 exception);
7871 source=DestroyImageList(source);
7872 break;
7873 }
7874 }
7875 if (layers == (Image *) NULL)
7876 break;
7877 InheritException(exception,&layers->exception);
7878 *images=DestroyImageList(*images);
7879 *images=layers;
7880 break;
7881 }
7882 break;
7883 }
7884 case 'm':
7885 {
7886 if (LocaleCompare("map",option+1) == 0)
7887 {
cristy6b3da3a2010-06-20 02:21:46 +00007888 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007889 if (*option == '+')
7890 {
7891 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7892 InheritException(exception,&(*images)->exception);
7893 break;
7894 }
7895 i++;
7896 break;
7897 }
cristyf40785b2010-03-06 02:27:27 +00007898 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007899 {
7900 Image
cristyf40785b2010-03-06 02:27:27 +00007901 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007902
cristyd18ae7c2010-03-07 17:39:52 +00007903 /*
7904 Maximum image sequence (deprecated).
7905 */
cristy6b3da3a2010-06-20 02:21:46 +00007906 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007907 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007908 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007909 {
7910 status=MagickFalse;
7911 break;
7912 }
7913 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007914 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007915 break;
7916 }
cristyf40785b2010-03-06 02:27:27 +00007917 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007918 {
7919 Image
cristyf40785b2010-03-06 02:27:27 +00007920 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007921
cristyd18ae7c2010-03-07 17:39:52 +00007922 /*
7923 Minimum image sequence (deprecated).
7924 */
cristy6b3da3a2010-06-20 02:21:46 +00007925 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007926 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007927 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007928 {
7929 status=MagickFalse;
7930 break;
7931 }
7932 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007933 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007934 break;
7935 }
cristy3ed852e2009-09-05 21:47:34 +00007936 if (LocaleCompare("morph",option+1) == 0)
7937 {
7938 Image
7939 *morph_image;
7940
cristy6b3da3a2010-06-20 02:21:46 +00007941 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007942 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007943 exception);
7944 if (morph_image == (Image *) NULL)
7945 {
7946 status=MagickFalse;
7947 break;
7948 }
7949 *images=DestroyImageList(*images);
7950 *images=morph_image;
7951 break;
7952 }
7953 if (LocaleCompare("mosaic",option+1) == 0)
7954 {
7955 Image
7956 *mosaic_image;
7957
cristy6b3da3a2010-06-20 02:21:46 +00007958 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007959 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7960 if (mosaic_image == (Image *) NULL)
7961 {
7962 status=MagickFalse;
7963 break;
7964 }
7965 *images=DestroyImageList(*images);
7966 *images=mosaic_image;
7967 break;
7968 }
7969 break;
7970 }
7971 case 'p':
7972 {
7973 if (LocaleCompare("print",option+1) == 0)
7974 {
7975 char
7976 *string;
7977
cristy6b3da3a2010-06-20 02:21:46 +00007978 (void) SyncImagesSettings(mogrify_info,*images);
7979 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007980 if (string == (char *) NULL)
7981 break;
7982 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007983 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007984 string=DestroyString(string);
7985 }
7986 if (LocaleCompare("process",option+1) == 0)
7987 {
7988 char
7989 **arguments;
7990
7991 int
7992 j,
7993 number_arguments;
7994
cristy6b3da3a2010-06-20 02:21:46 +00007995 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007996 arguments=StringToArgv(argv[i+1],&number_arguments);
7997 if (arguments == (char **) NULL)
7998 break;
7999 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8000 {
8001 char
8002 breaker,
8003 quote,
8004 *token;
8005
8006 const char
8007 *arguments;
8008
8009 int
8010 next,
8011 status;
8012
8013 size_t
8014 length;
8015
8016 TokenInfo
8017 *token_info;
8018
8019 /*
8020 Support old style syntax, filter="-option arg".
8021 */
8022 length=strlen(argv[i+1]);
8023 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008024 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008025 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8026 sizeof(*token));
8027 if (token == (char *) NULL)
8028 break;
8029 next=0;
8030 arguments=argv[i+1];
8031 token_info=AcquireTokenInfo();
8032 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8033 "\"",'\0',&breaker,&next,&quote);
8034 token_info=DestroyTokenInfo(token_info);
8035 if (status == 0)
8036 {
8037 const char
8038 *argv;
8039
8040 argv=(&(arguments[next]));
8041 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8042 exception);
8043 }
8044 token=DestroyString(token);
8045 break;
8046 }
cristy91c0da22010-05-02 01:44:07 +00008047 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008048 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8049 number_arguments-2,(const char **) arguments+2,exception);
8050 for (j=0; j < number_arguments; j++)
8051 arguments[j]=DestroyString(arguments[j]);
8052 arguments=(char **) RelinquishMagickMemory(arguments);
8053 break;
8054 }
8055 break;
8056 }
8057 case 'r':
8058 {
8059 if (LocaleCompare("reverse",option+1) == 0)
8060 {
8061 ReverseImageList(images);
8062 InheritException(exception,&(*images)->exception);
8063 break;
8064 }
8065 break;
8066 }
8067 case 's':
8068 {
cristy4285d782011-02-09 20:12:28 +00008069 if (LocaleCompare("smush",option+1) == 0)
8070 {
8071 Image
8072 *smush_image;
8073
8074 ssize_t
8075 offset;
8076
8077 (void) SyncImagesSettings(mogrify_info,*images);
8078 offset=(ssize_t) StringToLong(argv[i+1]);
8079 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8080 MagickFalse,offset,exception);
8081 if (smush_image == (Image *) NULL)
8082 {
8083 status=MagickFalse;
8084 break;
8085 }
8086 *images=DestroyImageList(*images);
8087 *images=smush_image;
8088 break;
8089 }
cristy3ed852e2009-09-05 21:47:34 +00008090 if (LocaleCompare("swap",option+1) == 0)
8091 {
8092 Image
8093 *p,
8094 *q,
8095 *swap;
8096
cristybb503372010-05-27 20:51:26 +00008097 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008098 swap_index;
8099
8100 index=(-1);
8101 swap_index=(-2);
8102 if (*option != '+')
8103 {
8104 GeometryInfo
8105 geometry_info;
8106
8107 MagickStatusType
8108 flags;
8109
8110 swap_index=(-1);
8111 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008112 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008113 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008114 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008115 }
8116 p=GetImageFromList(*images,index);
8117 q=GetImageFromList(*images,swap_index);
8118 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8119 {
8120 (void) ThrowMagickException(exception,GetMagickModule(),
8121 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8122 status=MagickFalse;
8123 break;
8124 }
8125 if (p == q)
8126 break;
8127 swap=CloneImage(p,0,0,MagickTrue,exception);
8128 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8129 ReplaceImageInList(&q,swap);
8130 *images=GetFirstImageInList(q);
8131 break;
8132 }
8133 break;
8134 }
8135 case 'w':
8136 {
8137 if (LocaleCompare("write",option+1) == 0)
8138 {
cristy071dd7b2010-04-09 13:04:54 +00008139 char
cristy06609ee2010-03-17 20:21:27 +00008140 key[MaxTextExtent];
8141
cristy3ed852e2009-09-05 21:47:34 +00008142 Image
8143 *write_images;
8144
8145 ImageInfo
8146 *write_info;
8147
cristy6b3da3a2010-06-20 02:21:46 +00008148 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008149 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008150 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008151 write_images=(*images);
8152 if (*option == '+')
8153 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008154 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008155 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8156 write_info=DestroyImageInfo(write_info);
8157 if (*option == '+')
8158 write_images=DestroyImageList(write_images);
8159 break;
8160 }
8161 break;
8162 }
8163 default:
8164 break;
8165 }
8166 i+=count;
8167 }
8168 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008169 mogrify_info=DestroyImageInfo(mogrify_info);
8170 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008171 return(status != 0 ? MagickTrue : MagickFalse);
8172}
8173
8174/*
8175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8176% %
8177% %
8178% %
8179+ M o g r i f y I m a g e s %
8180% %
8181% %
8182% %
8183%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8184%
8185% MogrifyImages() applies image processing options to a sequence of images as
8186% prescribed by command line options.
8187%
8188% The format of the MogrifyImage method is:
8189%
8190% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8191% const MagickBooleanType post,const int argc,const char **argv,
8192% Image **images,Exceptioninfo *exception)
8193%
8194% A description of each parameter follows:
8195%
8196% o image_info: the image info..
8197%
8198% o post: If true, post process image list operators otherwise pre-process.
8199%
8200% o argc: Specifies a pointer to an integer describing the number of
8201% elements in the argument vector.
8202%
8203% o argv: Specifies a pointer to a text array containing the command line
8204% arguments.
8205%
anthonye9c27192011-03-27 08:07:06 +00008206% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008207%
8208% o exception: return any errors or warnings in this structure.
8209%
8210*/
8211WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8212 const MagickBooleanType post,const int argc,const char **argv,
8213 Image **images,ExceptionInfo *exception)
8214{
8215#define MogrifyImageTag "Mogrify/Image"
8216
anthonye9c27192011-03-27 08:07:06 +00008217 MagickStatusType
8218 status;
cristy3ed852e2009-09-05 21:47:34 +00008219
cristy0e9f9c12010-02-11 03:00:47 +00008220 MagickBooleanType
8221 proceed;
8222
anthonye9c27192011-03-27 08:07:06 +00008223 size_t
8224 n;
cristy3ed852e2009-09-05 21:47:34 +00008225
cristybb503372010-05-27 20:51:26 +00008226 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008227 i;
8228
cristy3ed852e2009-09-05 21:47:34 +00008229 assert(image_info != (ImageInfo *) NULL);
8230 assert(image_info->signature == MagickSignature);
8231 if (images == (Image **) NULL)
8232 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008233 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008234 assert((*images)->signature == MagickSignature);
8235 if ((*images)->debug != MagickFalse)
8236 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8237 (*images)->filename);
8238 if ((argc <= 0) || (*argv == (char *) NULL))
8239 return(MagickTrue);
8240 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8241 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008242 status=0;
anthonye9c27192011-03-27 08:07:06 +00008243
anthonyce2716b2011-04-22 09:51:34 +00008244#if 0
cristy1e604812011-05-19 18:07:50 +00008245 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8246 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008247#endif
8248
anthonye9c27192011-03-27 08:07:06 +00008249 /*
8250 Pre-process multi-image sequence operators
8251 */
cristy3ed852e2009-09-05 21:47:34 +00008252 if (post == MagickFalse)
8253 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008254 /*
8255 For each image, process simple single image operators
8256 */
8257 i=0;
8258 n=GetImageListLength(*images);
8259 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008260 {
anthonyce2716b2011-04-22 09:51:34 +00008261#if 0
cristy1e604812011-05-19 18:07:50 +00008262 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8263 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008264#endif
anthonye9c27192011-03-27 08:07:06 +00008265 status&=MogrifyImage(image_info,argc,argv,images,exception);
8266 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008267 if (proceed == MagickFalse)
8268 break;
anthonye9c27192011-03-27 08:07:06 +00008269 if ( (*images)->next == (Image *) NULL )
8270 break;
8271 *images=(*images)->next;
8272 i++;
cristy3ed852e2009-09-05 21:47:34 +00008273 }
anthonye9c27192011-03-27 08:07:06 +00008274 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008275#if 0
cristy1e604812011-05-19 18:07:50 +00008276 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8277 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008278#endif
anthonye9c27192011-03-27 08:07:06 +00008279
8280 /*
8281 Post-process, multi-image sequence operators
8282 */
8283 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008284 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008285 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008286 return(status != 0 ? MagickTrue : MagickFalse);
8287}