blob: d6d5302535a9529088dbd114cf8ac05f7c911b43 [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
1200 register ssize_t
1201 j;
1202
1203 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001204 kernel_info=AcquireKernelInfo(argv[i+1]);
1205 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001206 break;
cristy41cbe682011-07-15 19:12:37 +00001207 mogrify_image=FilterImage(*image,kernel_info,exception);
1208 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001209 break;
1210 }
1211 if (LocaleCompare("crop",option+1) == 0)
1212 {
1213 /*
1214 Crop a image to a smaller size
1215 */
1216 (void) SyncImageSettings(mogrify_info,*image);
1217#if 0
1218 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1219 if (((geometry.width != 0) || (geometry.height != 0)) &&
1220 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1221 break;
1222#endif
1223#if 0
1224 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1225 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1226 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1227 InheritException(exception,&mogrify_image->exception);
1228#else
1229 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1230#endif
1231 break;
1232 }
1233 if (LocaleCompare("cycle",option+1) == 0)
1234 {
1235 /*
1236 Cycle an image colormap.
1237 */
1238 (void) SyncImageSettings(mogrify_info,*image);
1239 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1240 InheritException(exception,&(*image)->exception);
1241 break;
1242 }
1243 break;
1244 }
1245 case 'd':
1246 {
1247 if (LocaleCompare("decipher",option+1) == 0)
1248 {
1249 StringInfo
1250 *passkey;
1251
1252 /*
1253 Decipher pixels.
1254 */
1255 (void) SyncImageSettings(mogrify_info,*image);
1256 passkey=FileToStringInfo(argv[i+1],~0,exception);
1257 if (passkey != (StringInfo *) NULL)
1258 {
1259 (void) PasskeyDecipherImage(*image,passkey,exception);
1260 passkey=DestroyStringInfo(passkey);
1261 }
1262 break;
1263 }
1264 if (LocaleCompare("density",option+1) == 0)
1265 {
1266 /*
1267 Set image density.
1268 */
1269 (void) CloneString(&draw_info->density,argv[i+1]);
1270 break;
1271 }
1272 if (LocaleCompare("depth",option+1) == 0)
1273 {
1274 (void) SyncImageSettings(mogrify_info,*image);
1275 if (*option == '+')
1276 {
1277 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1278 break;
1279 }
1280 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1281 break;
1282 }
1283 if (LocaleCompare("deskew",option+1) == 0)
1284 {
1285 double
1286 threshold;
1287
1288 /*
1289 Straighten the image.
1290 */
1291 (void) SyncImageSettings(mogrify_info,*image);
1292 if (*option == '+')
1293 threshold=40.0*QuantumRange/100.0;
1294 else
1295 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1296 mogrify_image=DeskewImage(*image,threshold,exception);
1297 break;
1298 }
1299 if (LocaleCompare("despeckle",option+1) == 0)
1300 {
1301 /*
1302 Reduce the speckles within an image.
1303 */
1304 (void) SyncImageSettings(mogrify_info,*image);
1305 mogrify_image=DespeckleImage(*image,exception);
1306 break;
1307 }
1308 if (LocaleCompare("display",option+1) == 0)
1309 {
1310 (void) CloneString(&draw_info->server_name,argv[i+1]);
1311 break;
1312 }
1313 if (LocaleCompare("distort",option+1) == 0)
1314 {
1315 char
1316 *args,
1317 token[MaxTextExtent];
1318
1319 const char
1320 *p;
1321
1322 DistortImageMethod
1323 method;
1324
1325 double
1326 *arguments;
1327
1328 register ssize_t
1329 x;
1330
1331 size_t
1332 number_arguments;
1333
1334 /*
1335 Distort image.
1336 */
1337 (void) SyncImageSettings(mogrify_info,*image);
1338 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1339 MagickFalse,argv[i+1]);
1340 if ( method == ResizeDistortion )
1341 {
1342 /* Special Case - Argument is actually a resize geometry!
1343 ** Convert that to an appropriate distortion argument array.
1344 */
1345 double
1346 resize_args[2];
1347 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1348 exception);
1349 resize_args[0]=(double)geometry.width;
1350 resize_args[1]=(double)geometry.height;
1351 mogrify_image=DistortImage(*image,method,(size_t)2,
1352 resize_args,MagickTrue,exception);
1353 break;
1354 }
1355 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1356 InheritException(exception,&(*image)->exception);
1357 if (args == (char *) NULL)
1358 break;
1359 p=(char *) args;
1360 for (x=0; *p != '\0'; x++)
1361 {
1362 GetMagickToken(p,&p,token);
1363 if (*token == ',')
1364 GetMagickToken(p,&p,token);
1365 }
1366 number_arguments=(size_t) x;
1367 arguments=(double *) AcquireQuantumMemory(number_arguments,
1368 sizeof(*arguments));
1369 if (arguments == (double *) NULL)
1370 ThrowWandFatalException(ResourceLimitFatalError,
1371 "MemoryAllocationFailed",(*image)->filename);
1372 (void) ResetMagickMemory(arguments,0,number_arguments*
1373 sizeof(*arguments));
1374 p=(char *) args;
1375 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1376 {
1377 GetMagickToken(p,&p,token);
1378 if (*token == ',')
1379 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001380 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001381 }
1382 args=DestroyString(args);
1383 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1384 (*option == '+') ? MagickTrue : MagickFalse,exception);
1385 arguments=(double *) RelinquishMagickMemory(arguments);
1386 break;
1387 }
1388 if (LocaleCompare("dither",option+1) == 0)
1389 {
1390 if (*option == '+')
1391 {
1392 quantize_info->dither=MagickFalse;
1393 break;
1394 }
1395 quantize_info->dither=MagickTrue;
1396 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1397 MagickDitherOptions,MagickFalse,argv[i+1]);
1398 if (quantize_info->dither_method == NoDitherMethod)
1399 quantize_info->dither=MagickFalse;
1400 break;
1401 }
1402 if (LocaleCompare("draw",option+1) == 0)
1403 {
1404 /*
1405 Draw image.
1406 */
1407 (void) SyncImageSettings(mogrify_info,*image);
1408 (void) CloneString(&draw_info->primitive,argv[i+1]);
1409 (void) DrawImage(*image,draw_info);
1410 InheritException(exception,&(*image)->exception);
1411 break;
1412 }
1413 break;
1414 }
1415 case 'e':
1416 {
1417 if (LocaleCompare("edge",option+1) == 0)
1418 {
1419 /*
1420 Enhance edges in the image.
1421 */
1422 (void) SyncImageSettings(mogrify_info,*image);
1423 flags=ParseGeometry(argv[i+1],&geometry_info);
1424 if ((flags & SigmaValue) == 0)
1425 geometry_info.sigma=1.0;
1426 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1427 break;
1428 }
1429 if (LocaleCompare("emboss",option+1) == 0)
1430 {
1431 /*
1432 Gaussian embossen image.
1433 */
1434 (void) SyncImageSettings(mogrify_info,*image);
1435 flags=ParseGeometry(argv[i+1],&geometry_info);
1436 if ((flags & SigmaValue) == 0)
1437 geometry_info.sigma=1.0;
1438 mogrify_image=EmbossImage(*image,geometry_info.rho,
1439 geometry_info.sigma,exception);
1440 break;
1441 }
1442 if (LocaleCompare("encipher",option+1) == 0)
1443 {
1444 StringInfo
1445 *passkey;
1446
1447 /*
1448 Encipher pixels.
1449 */
1450 (void) SyncImageSettings(mogrify_info,*image);
1451 passkey=FileToStringInfo(argv[i+1],~0,exception);
1452 if (passkey != (StringInfo *) NULL)
1453 {
1454 (void) PasskeyEncipherImage(*image,passkey,exception);
1455 passkey=DestroyStringInfo(passkey);
1456 }
1457 break;
1458 }
1459 if (LocaleCompare("encoding",option+1) == 0)
1460 {
1461 (void) CloneString(&draw_info->encoding,argv[i+1]);
1462 break;
1463 }
1464 if (LocaleCompare("enhance",option+1) == 0)
1465 {
1466 /*
1467 Enhance image.
1468 */
1469 (void) SyncImageSettings(mogrify_info,*image);
1470 mogrify_image=EnhanceImage(*image,exception);
1471 break;
1472 }
1473 if (LocaleCompare("equalize",option+1) == 0)
1474 {
1475 /*
1476 Equalize image.
1477 */
1478 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00001479 (void) EqualizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001480 InheritException(exception,&(*image)->exception);
1481 break;
1482 }
1483 if (LocaleCompare("evaluate",option+1) == 0)
1484 {
1485 double
1486 constant;
1487
1488 MagickEvaluateOperator
1489 op;
1490
1491 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001492 op=(MagickEvaluateOperator) ParseCommandOption(
1493 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001494 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001495 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001496 break;
1497 }
1498 if (LocaleCompare("extent",option+1) == 0)
1499 {
1500 /*
1501 Set the image extent.
1502 */
1503 (void) SyncImageSettings(mogrify_info,*image);
1504 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1505 if (geometry.width == 0)
1506 geometry.width=(*image)->columns;
1507 if (geometry.height == 0)
1508 geometry.height=(*image)->rows;
1509 mogrify_image=ExtentImage(*image,&geometry,exception);
1510 break;
1511 }
1512 break;
1513 }
1514 case 'f':
1515 {
1516 if (LocaleCompare("family",option+1) == 0)
1517 {
1518 if (*option == '+')
1519 {
1520 if (draw_info->family != (char *) NULL)
1521 draw_info->family=DestroyString(draw_info->family);
1522 break;
1523 }
1524 (void) CloneString(&draw_info->family,argv[i+1]);
1525 break;
1526 }
1527 if (LocaleCompare("features",option+1) == 0)
1528 {
1529 if (*option == '+')
1530 {
1531 (void) DeleteImageArtifact(*image,"identify:features");
1532 break;
1533 }
1534 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1535 break;
1536 }
1537 if (LocaleCompare("fill",option+1) == 0)
1538 {
1539 ExceptionInfo
1540 *sans;
1541
cristy4c08aed2011-07-01 19:47:50 +00001542 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001543 if (*option == '+')
1544 {
1545 (void) QueryMagickColor("none",&fill,exception);
1546 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1547 if (draw_info->fill_pattern != (Image *) NULL)
1548 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1549 break;
1550 }
1551 sans=AcquireExceptionInfo();
1552 (void) QueryMagickColor(argv[i+1],&fill,sans);
1553 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1554 sans=DestroyExceptionInfo(sans);
1555 if (status == MagickFalse)
1556 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1557 exception);
1558 break;
1559 }
1560 if (LocaleCompare("flip",option+1) == 0)
1561 {
1562 /*
1563 Flip image scanlines.
1564 */
1565 (void) SyncImageSettings(mogrify_info,*image);
1566 mogrify_image=FlipImage(*image,exception);
1567 break;
1568 }
anthonydf8ebac2011-04-27 09:03:19 +00001569 if (LocaleCompare("floodfill",option+1) == 0)
1570 {
cristy4c08aed2011-07-01 19:47:50 +00001571 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001572 target;
1573
1574 /*
1575 Floodfill image.
1576 */
1577 (void) SyncImageSettings(mogrify_info,*image);
1578 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1579 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001580 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1581 geometry.y,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00001582 InheritException(exception,&(*image)->exception);
1583 break;
1584 }
anthony3d2f4862011-05-01 13:48:16 +00001585 if (LocaleCompare("flop",option+1) == 0)
1586 {
1587 /*
1588 Flop image scanlines.
1589 */
1590 (void) SyncImageSettings(mogrify_info,*image);
1591 mogrify_image=FlopImage(*image,exception);
1592 break;
1593 }
anthonydf8ebac2011-04-27 09:03:19 +00001594 if (LocaleCompare("font",option+1) == 0)
1595 {
1596 if (*option == '+')
1597 {
1598 if (draw_info->font != (char *) NULL)
1599 draw_info->font=DestroyString(draw_info->font);
1600 break;
1601 }
1602 (void) CloneString(&draw_info->font,argv[i+1]);
1603 break;
1604 }
1605 if (LocaleCompare("format",option+1) == 0)
1606 {
1607 format=argv[i+1];
1608 break;
1609 }
1610 if (LocaleCompare("frame",option+1) == 0)
1611 {
1612 FrameInfo
1613 frame_info;
1614
1615 /*
1616 Surround image with an ornamental border.
1617 */
1618 (void) SyncImageSettings(mogrify_info,*image);
1619 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1620 frame_info.width=geometry.width;
1621 frame_info.height=geometry.height;
1622 if ((flags & HeightValue) == 0)
1623 frame_info.height=geometry.width;
1624 frame_info.outer_bevel=geometry.x;
1625 frame_info.inner_bevel=geometry.y;
1626 frame_info.x=(ssize_t) frame_info.width;
1627 frame_info.y=(ssize_t) frame_info.height;
1628 frame_info.width=(*image)->columns+2*frame_info.width;
1629 frame_info.height=(*image)->rows+2*frame_info.height;
1630 mogrify_image=FrameImage(*image,&frame_info,exception);
1631 break;
1632 }
1633 if (LocaleCompare("function",option+1) == 0)
1634 {
1635 char
1636 *arguments,
1637 token[MaxTextExtent];
1638
1639 const char
1640 *p;
1641
1642 double
1643 *parameters;
1644
1645 MagickFunction
1646 function;
1647
1648 register ssize_t
1649 x;
1650
1651 size_t
1652 number_parameters;
1653
1654 /*
1655 Function Modify Image Values
1656 */
1657 (void) SyncImageSettings(mogrify_info,*image);
1658 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1659 MagickFalse,argv[i+1]);
1660 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1661 InheritException(exception,&(*image)->exception);
1662 if (arguments == (char *) NULL)
1663 break;
1664 p=(char *) arguments;
1665 for (x=0; *p != '\0'; x++)
1666 {
1667 GetMagickToken(p,&p,token);
1668 if (*token == ',')
1669 GetMagickToken(p,&p,token);
1670 }
1671 number_parameters=(size_t) x;
1672 parameters=(double *) AcquireQuantumMemory(number_parameters,
1673 sizeof(*parameters));
1674 if (parameters == (double *) NULL)
1675 ThrowWandFatalException(ResourceLimitFatalError,
1676 "MemoryAllocationFailed",(*image)->filename);
1677 (void) ResetMagickMemory(parameters,0,number_parameters*
1678 sizeof(*parameters));
1679 p=(char *) arguments;
1680 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1681 {
1682 GetMagickToken(p,&p,token);
1683 if (*token == ',')
1684 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001685 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001686 }
1687 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001688 (void) FunctionImage(*image,function,number_parameters,parameters,
1689 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001690 parameters=(double *) RelinquishMagickMemory(parameters);
1691 break;
1692 }
1693 break;
1694 }
1695 case 'g':
1696 {
1697 if (LocaleCompare("gamma",option+1) == 0)
1698 {
1699 /*
1700 Gamma image.
1701 */
1702 (void) SyncImageSettings(mogrify_info,*image);
1703 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001704 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001705 else
1706 {
cristy50fbc382011-07-07 02:19:17 +00001707 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1708 (char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001709 InheritException(exception,&(*image)->exception);
1710 }
1711 break;
1712 }
1713 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1714 (LocaleCompare("gaussian",option+1) == 0))
1715 {
1716 /*
1717 Gaussian blur image.
1718 */
1719 (void) SyncImageSettings(mogrify_info,*image);
1720 flags=ParseGeometry(argv[i+1],&geometry_info);
1721 if ((flags & SigmaValue) == 0)
1722 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001723 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1724 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001725 break;
1726 }
1727 if (LocaleCompare("geometry",option+1) == 0)
1728 {
1729 /*
1730 Record Image offset, Resize last image.
1731 */
1732 (void) SyncImageSettings(mogrify_info,*image);
1733 if (*option == '+')
1734 {
1735 if ((*image)->geometry != (char *) NULL)
1736 (*image)->geometry=DestroyString((*image)->geometry);
1737 break;
1738 }
1739 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1740 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1741 (void) CloneString(&(*image)->geometry,argv[i+1]);
1742 else
1743 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1744 (*image)->filter,(*image)->blur,exception);
1745 break;
1746 }
1747 if (LocaleCompare("gravity",option+1) == 0)
1748 {
1749 if (*option == '+')
1750 {
1751 draw_info->gravity=UndefinedGravity;
1752 break;
1753 }
1754 draw_info->gravity=(GravityType) ParseCommandOption(
1755 MagickGravityOptions,MagickFalse,argv[i+1]);
1756 break;
1757 }
1758 break;
1759 }
1760 case 'h':
1761 {
1762 if (LocaleCompare("highlight-color",option+1) == 0)
1763 {
1764 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1765 break;
1766 }
1767 break;
1768 }
1769 case 'i':
1770 {
1771 if (LocaleCompare("identify",option+1) == 0)
1772 {
1773 char
1774 *text;
1775
1776 (void) SyncImageSettings(mogrify_info,*image);
1777 if (format == (char *) NULL)
1778 {
1779 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1780 InheritException(exception,&(*image)->exception);
1781 break;
1782 }
1783 text=InterpretImageProperties(mogrify_info,*image,format);
1784 InheritException(exception,&(*image)->exception);
1785 if (text == (char *) NULL)
1786 break;
1787 (void) fputs(text,stdout);
1788 (void) fputc('\n',stdout);
1789 text=DestroyString(text);
1790 break;
1791 }
1792 if (LocaleCompare("implode",option+1) == 0)
1793 {
1794 /*
1795 Implode image.
1796 */
1797 (void) SyncImageSettings(mogrify_info,*image);
1798 (void) ParseGeometry(argv[i+1],&geometry_info);
1799 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1800 break;
1801 }
1802 if (LocaleCompare("interline-spacing",option+1) == 0)
1803 {
1804 if (*option == '+')
1805 (void) ParseGeometry("0",&geometry_info);
1806 else
1807 (void) ParseGeometry(argv[i+1],&geometry_info);
1808 draw_info->interline_spacing=geometry_info.rho;
1809 break;
1810 }
1811 if (LocaleCompare("interword-spacing",option+1) == 0)
1812 {
1813 if (*option == '+')
1814 (void) ParseGeometry("0",&geometry_info);
1815 else
1816 (void) ParseGeometry(argv[i+1],&geometry_info);
1817 draw_info->interword_spacing=geometry_info.rho;
1818 break;
1819 }
1820 break;
1821 }
1822 case 'k':
1823 {
1824 if (LocaleCompare("kerning",option+1) == 0)
1825 {
1826 if (*option == '+')
1827 (void) ParseGeometry("0",&geometry_info);
1828 else
1829 (void) ParseGeometry(argv[i+1],&geometry_info);
1830 draw_info->kerning=geometry_info.rho;
1831 break;
1832 }
1833 break;
1834 }
1835 case 'l':
1836 {
1837 if (LocaleCompare("lat",option+1) == 0)
1838 {
1839 /*
1840 Local adaptive threshold image.
1841 */
1842 (void) SyncImageSettings(mogrify_info,*image);
1843 flags=ParseGeometry(argv[i+1],&geometry_info);
1844 if ((flags & PercentValue) != 0)
1845 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1846 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1847 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1848 geometry_info.xi,exception);
1849 break;
1850 }
1851 if (LocaleCompare("level",option+1) == 0)
1852 {
1853 MagickRealType
1854 black_point,
1855 gamma,
1856 white_point;
1857
1858 MagickStatusType
1859 flags;
1860
1861 /*
1862 Parse levels.
1863 */
1864 (void) SyncImageSettings(mogrify_info,*image);
1865 flags=ParseGeometry(argv[i+1],&geometry_info);
1866 black_point=geometry_info.rho;
1867 white_point=(MagickRealType) QuantumRange;
1868 if ((flags & SigmaValue) != 0)
1869 white_point=geometry_info.sigma;
1870 gamma=1.0;
1871 if ((flags & XiValue) != 0)
1872 gamma=geometry_info.xi;
1873 if ((flags & PercentValue) != 0)
1874 {
1875 black_point*=(MagickRealType) (QuantumRange/100.0);
1876 white_point*=(MagickRealType) (QuantumRange/100.0);
1877 }
1878 if ((flags & SigmaValue) == 0)
1879 white_point=(MagickRealType) QuantumRange-black_point;
1880 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy50fbc382011-07-07 02:19:17 +00001881 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001882 else
cristyf89cb1d2011-07-07 01:24:37 +00001883 (void) LevelImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001884 InheritException(exception,&(*image)->exception);
1885 break;
1886 }
1887 if (LocaleCompare("level-colors",option+1) == 0)
1888 {
1889 char
1890 token[MaxTextExtent];
1891
1892 const char
1893 *p;
1894
cristy4c08aed2011-07-01 19:47:50 +00001895 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001896 black_point,
1897 white_point;
1898
1899 p=(const char *) argv[i+1];
1900 GetMagickToken(p,&p,token); /* get black point color */
1901 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1902 (void) QueryMagickColor(token,&black_point,exception);
1903 else
1904 (void) QueryMagickColor("#000000",&black_point,exception);
1905 if (isalpha((int) token[0]) || (token[0] == '#'))
1906 GetMagickToken(p,&p,token);
1907 if (*token == '\0')
1908 white_point=black_point; /* set everything to that color */
1909 else
1910 {
1911 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1912 GetMagickToken(p,&p,token); /* Get white point color. */
1913 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1914 (void) QueryMagickColor(token,&white_point,exception);
1915 else
1916 (void) QueryMagickColor("#ffffff",&white_point,exception);
1917 }
cristy490408a2011-07-07 14:42:05 +00001918 (void) LevelImageColors(*image,&black_point,&white_point,
1919 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001920 break;
1921 }
1922 if (LocaleCompare("linear-stretch",option+1) == 0)
1923 {
1924 double
1925 black_point,
1926 white_point;
1927
1928 MagickStatusType
1929 flags;
1930
1931 (void) SyncImageSettings(mogrify_info,*image);
1932 flags=ParseGeometry(argv[i+1],&geometry_info);
1933 black_point=geometry_info.rho;
1934 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1935 if ((flags & SigmaValue) != 0)
1936 white_point=geometry_info.sigma;
1937 if ((flags & PercentValue) != 0)
1938 {
1939 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1940 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1941 }
1942 if ((flags & SigmaValue) == 0)
1943 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1944 black_point;
1945 (void) LinearStretchImage(*image,black_point,white_point);
1946 InheritException(exception,&(*image)->exception);
1947 break;
1948 }
1949 if (LocaleCompare("linewidth",option+1) == 0)
1950 {
cristyc1acd842011-05-19 23:05:47 +00001951 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1952 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001953 break;
1954 }
1955 if (LocaleCompare("liquid-rescale",option+1) == 0)
1956 {
1957 /*
1958 Liquid rescale image.
1959 */
1960 (void) SyncImageSettings(mogrify_info,*image);
1961 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1962 if ((flags & XValue) == 0)
1963 geometry.x=1;
1964 if ((flags & YValue) == 0)
1965 geometry.y=0;
1966 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1967 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1968 break;
1969 }
1970 if (LocaleCompare("lowlight-color",option+1) == 0)
1971 {
1972 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1973 break;
1974 }
1975 break;
1976 }
1977 case 'm':
1978 {
1979 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001980 {
cristy3ed852e2009-09-05 21:47:34 +00001981 Image
anthonydf8ebac2011-04-27 09:03:19 +00001982 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001983
anthonydf8ebac2011-04-27 09:03:19 +00001984 /*
1985 Transform image colors to match this set of colors.
1986 */
1987 (void) SyncImageSettings(mogrify_info,*image);
1988 if (*option == '+')
1989 break;
1990 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1991 if (remap_image == (Image *) NULL)
1992 break;
1993 (void) RemapImage(quantize_info,*image,remap_image);
1994 InheritException(exception,&(*image)->exception);
1995 remap_image=DestroyImage(remap_image);
1996 break;
1997 }
1998 if (LocaleCompare("mask",option+1) == 0)
1999 {
2000 Image
2001 *mask;
2002
2003 (void) SyncImageSettings(mogrify_info,*image);
2004 if (*option == '+')
2005 {
2006 /*
2007 Remove a mask.
2008 */
2009 (void) SetImageMask(*image,(Image *) NULL);
2010 InheritException(exception,&(*image)->exception);
2011 break;
2012 }
2013 /*
2014 Set the image mask.
2015 */
2016 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2017 if (mask == (Image *) NULL)
2018 break;
2019 (void) SetImageMask(*image,mask);
2020 mask=DestroyImage(mask);
2021 InheritException(exception,&(*image)->exception);
2022 break;
2023 }
2024 if (LocaleCompare("matte",option+1) == 0)
2025 {
2026 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2027 SetAlphaChannel : DeactivateAlphaChannel );
2028 InheritException(exception,&(*image)->exception);
2029 break;
2030 }
2031 if (LocaleCompare("median",option+1) == 0)
2032 {
2033 /*
2034 Median filter image.
2035 */
2036 (void) SyncImageSettings(mogrify_info,*image);
2037 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002038 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2039 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002040 break;
2041 }
2042 if (LocaleCompare("mode",option+1) == 0)
2043 {
2044 /*
2045 Mode image.
2046 */
2047 (void) SyncImageSettings(mogrify_info,*image);
2048 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002049 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2050 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002051 break;
2052 }
2053 if (LocaleCompare("modulate",option+1) == 0)
2054 {
2055 (void) SyncImageSettings(mogrify_info,*image);
2056 (void) ModulateImage(*image,argv[i+1]);
2057 InheritException(exception,&(*image)->exception);
2058 break;
2059 }
2060 if (LocaleCompare("monitor",option+1) == 0)
2061 {
2062 if (*option == '+')
2063 {
2064 (void) SetImageProgressMonitor(*image,
2065 (MagickProgressMonitor) NULL,(void *) NULL);
2066 break;
2067 }
2068 (void) SetImageProgressMonitor(*image,MonitorProgress,
2069 (void *) NULL);
2070 break;
2071 }
2072 if (LocaleCompare("monochrome",option+1) == 0)
2073 {
2074 (void) SyncImageSettings(mogrify_info,*image);
2075 (void) SetImageType(*image,BilevelType);
2076 InheritException(exception,&(*image)->exception);
2077 break;
2078 }
2079 if (LocaleCompare("morphology",option+1) == 0)
2080 {
2081 char
2082 token[MaxTextExtent];
2083
2084 const char
2085 *p;
2086
2087 KernelInfo
2088 *kernel;
2089
2090 MorphologyMethod
2091 method;
2092
2093 ssize_t
2094 iterations;
2095
2096 /*
2097 Morphological Image Operation
2098 */
2099 (void) SyncImageSettings(mogrify_info,*image);
2100 p=argv[i+1];
2101 GetMagickToken(p,&p,token);
2102 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2103 MagickFalse,token);
2104 iterations=1L;
2105 GetMagickToken(p,&p,token);
2106 if ((*p == ':') || (*p == ','))
2107 GetMagickToken(p,&p,token);
2108 if ((*p != '\0'))
2109 iterations=(ssize_t) StringToLong(p);
2110 kernel=AcquireKernelInfo(argv[i+2]);
2111 if (kernel == (KernelInfo *) NULL)
2112 {
2113 (void) ThrowMagickException(exception,GetMagickModule(),
2114 OptionError,"UnabletoParseKernel","morphology");
2115 status=MagickFalse;
2116 break;
2117 }
cristyf4ad9df2011-07-08 16:49:03 +00002118 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2119 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002120 kernel=DestroyKernelInfo(kernel);
2121 break;
2122 }
2123 if (LocaleCompare("motion-blur",option+1) == 0)
2124 {
2125 /*
2126 Motion blur image.
2127 */
2128 (void) SyncImageSettings(mogrify_info,*image);
2129 flags=ParseGeometry(argv[i+1],&geometry_info);
2130 if ((flags & SigmaValue) == 0)
2131 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002132 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2133 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002134 break;
2135 }
2136 break;
2137 }
2138 case 'n':
2139 {
2140 if (LocaleCompare("negate",option+1) == 0)
2141 {
2142 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002143 (void) NegateImage(*image,*option == '+' ? MagickTrue :
2144 MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00002145 InheritException(exception,&(*image)->exception);
2146 break;
2147 }
2148 if (LocaleCompare("noise",option+1) == 0)
2149 {
2150 (void) SyncImageSettings(mogrify_info,*image);
2151 if (*option == '-')
2152 {
2153 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002154 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2155 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002156 }
2157 else
2158 {
2159 NoiseType
2160 noise;
2161
2162 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2163 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002164 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002165 }
2166 break;
2167 }
2168 if (LocaleCompare("normalize",option+1) == 0)
2169 {
2170 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002171 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002172 InheritException(exception,&(*image)->exception);
2173 break;
2174 }
2175 break;
2176 }
2177 case 'o':
2178 {
2179 if (LocaleCompare("opaque",option+1) == 0)
2180 {
cristy4c08aed2011-07-01 19:47:50 +00002181 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002182 target;
2183
2184 (void) SyncImageSettings(mogrify_info,*image);
2185 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002186 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2187 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002188 break;
2189 }
2190 if (LocaleCompare("ordered-dither",option+1) == 0)
2191 {
2192 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002193 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002194 break;
2195 }
2196 break;
2197 }
2198 case 'p':
2199 {
2200 if (LocaleCompare("paint",option+1) == 0)
2201 {
anthonydf8ebac2011-04-27 09:03:19 +00002202 (void) SyncImageSettings(mogrify_info,*image);
2203 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002204 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002205 break;
2206 }
2207 if (LocaleCompare("pen",option+1) == 0)
2208 {
2209 if (*option == '+')
2210 {
2211 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2212 break;
2213 }
2214 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2215 break;
2216 }
2217 if (LocaleCompare("pointsize",option+1) == 0)
2218 {
2219 if (*option == '+')
2220 (void) ParseGeometry("12",&geometry_info);
2221 else
2222 (void) ParseGeometry(argv[i+1],&geometry_info);
2223 draw_info->pointsize=geometry_info.rho;
2224 break;
2225 }
2226 if (LocaleCompare("polaroid",option+1) == 0)
2227 {
2228 double
2229 angle;
2230
2231 RandomInfo
2232 *random_info;
2233
2234 /*
2235 Simulate a Polaroid picture.
2236 */
2237 (void) SyncImageSettings(mogrify_info,*image);
2238 random_info=AcquireRandomInfo();
2239 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2240 random_info=DestroyRandomInfo(random_info);
2241 if (*option == '-')
2242 {
2243 SetGeometryInfo(&geometry_info);
2244 flags=ParseGeometry(argv[i+1],&geometry_info);
2245 angle=geometry_info.rho;
2246 }
2247 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2248 break;
2249 }
2250 if (LocaleCompare("posterize",option+1) == 0)
2251 {
2252 /*
2253 Posterize image.
2254 */
2255 (void) SyncImageSettings(mogrify_info,*image);
2256 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2257 quantize_info->dither);
2258 InheritException(exception,&(*image)->exception);
2259 break;
2260 }
2261 if (LocaleCompare("preview",option+1) == 0)
2262 {
2263 PreviewType
2264 preview_type;
2265
2266 /*
2267 Preview image.
2268 */
2269 (void) SyncImageSettings(mogrify_info,*image);
2270 if (*option == '+')
2271 preview_type=UndefinedPreview;
2272 else
2273 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2274 MagickFalse,argv[i+1]);
2275 mogrify_image=PreviewImage(*image,preview_type,exception);
2276 break;
2277 }
2278 if (LocaleCompare("profile",option+1) == 0)
2279 {
2280 const char
2281 *name;
2282
2283 const StringInfo
2284 *profile;
2285
2286 Image
2287 *profile_image;
2288
2289 ImageInfo
2290 *profile_info;
2291
2292 (void) SyncImageSettings(mogrify_info,*image);
2293 if (*option == '+')
2294 {
2295 /*
2296 Remove a profile from the image.
2297 */
2298 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2299 NULL,0,MagickTrue);
2300 InheritException(exception,&(*image)->exception);
2301 break;
2302 }
2303 /*
2304 Associate a profile with the image.
2305 */
2306 profile_info=CloneImageInfo(mogrify_info);
2307 profile=GetImageProfile(*image,"iptc");
2308 if (profile != (StringInfo *) NULL)
2309 profile_info->profile=(void *) CloneStringInfo(profile);
2310 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2311 profile_info=DestroyImageInfo(profile_info);
2312 if (profile_image == (Image *) NULL)
2313 {
2314 StringInfo
2315 *profile;
2316
2317 profile_info=CloneImageInfo(mogrify_info);
2318 (void) CopyMagickString(profile_info->filename,argv[i+1],
2319 MaxTextExtent);
2320 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2321 if (profile != (StringInfo *) NULL)
2322 {
2323 (void) ProfileImage(*image,profile_info->magick,
2324 GetStringInfoDatum(profile),(size_t)
2325 GetStringInfoLength(profile),MagickFalse);
2326 profile=DestroyStringInfo(profile);
2327 }
2328 profile_info=DestroyImageInfo(profile_info);
2329 break;
2330 }
2331 ResetImageProfileIterator(profile_image);
2332 name=GetNextImageProfile(profile_image);
2333 while (name != (const char *) NULL)
2334 {
2335 profile=GetImageProfile(profile_image,name);
2336 if (profile != (StringInfo *) NULL)
2337 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2338 (size_t) GetStringInfoLength(profile),MagickFalse);
2339 name=GetNextImageProfile(profile_image);
2340 }
2341 profile_image=DestroyImage(profile_image);
2342 break;
2343 }
2344 break;
2345 }
2346 case 'q':
2347 {
2348 if (LocaleCompare("quantize",option+1) == 0)
2349 {
2350 if (*option == '+')
2351 {
2352 quantize_info->colorspace=UndefinedColorspace;
2353 break;
2354 }
2355 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2356 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2357 break;
2358 }
2359 break;
2360 }
2361 case 'r':
2362 {
2363 if (LocaleCompare("radial-blur",option+1) == 0)
2364 {
2365 /*
2366 Radial blur image.
2367 */
2368 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002369 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2370 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002371 break;
2372 }
2373 if (LocaleCompare("raise",option+1) == 0)
2374 {
2375 /*
2376 Surround image with a raise of solid color.
2377 */
2378 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2379 if ((flags & SigmaValue) == 0)
2380 geometry.height=geometry.width;
2381 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2382 MagickFalse);
2383 InheritException(exception,&(*image)->exception);
2384 break;
2385 }
2386 if (LocaleCompare("random-threshold",option+1) == 0)
2387 {
2388 /*
2389 Threshold image.
2390 */
2391 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002392 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002393 break;
2394 }
2395 if (LocaleCompare("recolor",option+1) == 0)
2396 {
2397 KernelInfo
2398 *kernel;
2399
2400 (void) SyncImageSettings(mogrify_info,*image);
2401 kernel=AcquireKernelInfo(argv[i+1]);
2402 if (kernel == (KernelInfo *) NULL)
2403 break;
2404 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2405 kernel=DestroyKernelInfo(kernel);
2406 break;
2407 }
2408 if (LocaleCompare("region",option+1) == 0)
2409 {
2410 (void) SyncImageSettings(mogrify_info,*image);
2411 if (region_image != (Image *) NULL)
2412 {
2413 /*
2414 Composite region.
2415 */
2416 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002417 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2418 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002419 InheritException(exception,&region_image->exception);
2420 *image=DestroyImage(*image);
2421 *image=region_image;
2422 region_image = (Image *) NULL;
2423 }
2424 if (*option == '+')
2425 break;
2426 /*
2427 Apply transformations to a selected region of the image.
2428 */
cristy3ed852e2009-09-05 21:47:34 +00002429 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2430 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002431 mogrify_image=CropImage(*image,&region_geometry,exception);
2432 if (mogrify_image == (Image *) NULL)
2433 break;
2434 region_image=(*image);
2435 *image=mogrify_image;
2436 mogrify_image=(Image *) NULL;
2437 break;
cristy3ed852e2009-09-05 21:47:34 +00002438 }
anthonydf8ebac2011-04-27 09:03:19 +00002439 if (LocaleCompare("render",option+1) == 0)
2440 {
2441 (void) SyncImageSettings(mogrify_info,*image);
2442 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2443 break;
2444 }
2445 if (LocaleCompare("remap",option+1) == 0)
2446 {
2447 Image
2448 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002449
anthonydf8ebac2011-04-27 09:03:19 +00002450 /*
2451 Transform image colors to match this set of colors.
2452 */
2453 (void) SyncImageSettings(mogrify_info,*image);
2454 if (*option == '+')
2455 break;
2456 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2457 if (remap_image == (Image *) NULL)
2458 break;
2459 (void) RemapImage(quantize_info,*image,remap_image);
2460 InheritException(exception,&(*image)->exception);
2461 remap_image=DestroyImage(remap_image);
2462 break;
2463 }
2464 if (LocaleCompare("repage",option+1) == 0)
2465 {
2466 if (*option == '+')
2467 {
2468 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2469 break;
2470 }
2471 (void) ResetImagePage(*image,argv[i+1]);
2472 InheritException(exception,&(*image)->exception);
2473 break;
2474 }
2475 if (LocaleCompare("resample",option+1) == 0)
2476 {
2477 /*
2478 Resample image.
2479 */
2480 (void) SyncImageSettings(mogrify_info,*image);
2481 flags=ParseGeometry(argv[i+1],&geometry_info);
2482 if ((flags & SigmaValue) == 0)
2483 geometry_info.sigma=geometry_info.rho;
2484 mogrify_image=ResampleImage(*image,geometry_info.rho,
2485 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2486 break;
2487 }
2488 if (LocaleCompare("resize",option+1) == 0)
2489 {
2490 /*
2491 Resize image.
2492 */
2493 (void) SyncImageSettings(mogrify_info,*image);
2494 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2495 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2496 (*image)->filter,(*image)->blur,exception);
2497 break;
2498 }
2499 if (LocaleCompare("roll",option+1) == 0)
2500 {
2501 /*
2502 Roll image.
2503 */
2504 (void) SyncImageSettings(mogrify_info,*image);
2505 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2506 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2507 break;
2508 }
2509 if (LocaleCompare("rotate",option+1) == 0)
2510 {
2511 char
2512 *geometry;
2513
2514 /*
2515 Check for conditional image rotation.
2516 */
2517 (void) SyncImageSettings(mogrify_info,*image);
2518 if (strchr(argv[i+1],'>') != (char *) NULL)
2519 if ((*image)->columns <= (*image)->rows)
2520 break;
2521 if (strchr(argv[i+1],'<') != (char *) NULL)
2522 if ((*image)->columns >= (*image)->rows)
2523 break;
2524 /*
2525 Rotate image.
2526 */
2527 geometry=ConstantString(argv[i+1]);
2528 (void) SubstituteString(&geometry,">","");
2529 (void) SubstituteString(&geometry,"<","");
2530 (void) ParseGeometry(geometry,&geometry_info);
2531 geometry=DestroyString(geometry);
2532 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2533 break;
2534 }
2535 break;
2536 }
2537 case 's':
2538 {
2539 if (LocaleCompare("sample",option+1) == 0)
2540 {
2541 /*
2542 Sample image with pixel replication.
2543 */
2544 (void) SyncImageSettings(mogrify_info,*image);
2545 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2546 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2547 exception);
2548 break;
2549 }
2550 if (LocaleCompare("scale",option+1) == 0)
2551 {
2552 /*
2553 Resize image.
2554 */
2555 (void) SyncImageSettings(mogrify_info,*image);
2556 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2557 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2558 exception);
2559 break;
2560 }
2561 if (LocaleCompare("selective-blur",option+1) == 0)
2562 {
2563 /*
2564 Selectively blur pixels within a contrast threshold.
2565 */
2566 (void) SyncImageSettings(mogrify_info,*image);
2567 flags=ParseGeometry(argv[i+1],&geometry_info);
2568 if ((flags & PercentValue) != 0)
2569 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002570 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2571 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002572 break;
2573 }
2574 if (LocaleCompare("separate",option+1) == 0)
2575 {
2576 /*
2577 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002578 */
2579 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002580 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002581 break;
2582 }
2583 if (LocaleCompare("sepia-tone",option+1) == 0)
2584 {
2585 double
2586 threshold;
2587
2588 /*
2589 Sepia-tone image.
2590 */
2591 (void) SyncImageSettings(mogrify_info,*image);
2592 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2593 mogrify_image=SepiaToneImage(*image,threshold,exception);
2594 break;
2595 }
2596 if (LocaleCompare("segment",option+1) == 0)
2597 {
2598 /*
2599 Segment image.
2600 */
2601 (void) SyncImageSettings(mogrify_info,*image);
2602 flags=ParseGeometry(argv[i+1],&geometry_info);
2603 if ((flags & SigmaValue) == 0)
2604 geometry_info.sigma=1.0;
2605 (void) SegmentImage(*image,(*image)->colorspace,
2606 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2607 InheritException(exception,&(*image)->exception);
2608 break;
2609 }
2610 if (LocaleCompare("set",option+1) == 0)
2611 {
2612 char
2613 *value;
2614
2615 /*
2616 Set image option.
2617 */
2618 if (*option == '+')
2619 {
2620 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2621 (void) DeleteImageRegistry(argv[i+1]+9);
2622 else
2623 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2624 {
2625 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2626 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2627 }
2628 else
2629 (void) DeleteImageProperty(*image,argv[i+1]);
2630 break;
2631 }
2632 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2633 if (value == (char *) NULL)
2634 break;
2635 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2636 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2637 exception);
2638 else
2639 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2640 {
2641 (void) SetImageOption(image_info,argv[i+1]+7,value);
2642 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2643 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2644 }
2645 else
2646 (void) SetImageProperty(*image,argv[i+1],value);
2647 value=DestroyString(value);
2648 break;
2649 }
2650 if (LocaleCompare("shade",option+1) == 0)
2651 {
2652 /*
2653 Shade image.
2654 */
2655 (void) SyncImageSettings(mogrify_info,*image);
2656 flags=ParseGeometry(argv[i+1],&geometry_info);
2657 if ((flags & SigmaValue) == 0)
2658 geometry_info.sigma=1.0;
2659 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2660 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2661 break;
2662 }
2663 if (LocaleCompare("shadow",option+1) == 0)
2664 {
2665 /*
2666 Shadow image.
2667 */
2668 (void) SyncImageSettings(mogrify_info,*image);
2669 flags=ParseGeometry(argv[i+1],&geometry_info);
2670 if ((flags & SigmaValue) == 0)
2671 geometry_info.sigma=1.0;
2672 if ((flags & XiValue) == 0)
2673 geometry_info.xi=4.0;
2674 if ((flags & PsiValue) == 0)
2675 geometry_info.psi=4.0;
2676 mogrify_image=ShadowImage(*image,geometry_info.rho,
2677 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2678 ceil(geometry_info.psi-0.5),exception);
2679 break;
2680 }
2681 if (LocaleCompare("sharpen",option+1) == 0)
2682 {
2683 /*
2684 Sharpen image.
2685 */
2686 (void) SyncImageSettings(mogrify_info,*image);
2687 flags=ParseGeometry(argv[i+1],&geometry_info);
2688 if ((flags & SigmaValue) == 0)
2689 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002690 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002691 geometry_info.sigma,exception);
2692 break;
2693 }
2694 if (LocaleCompare("shave",option+1) == 0)
2695 {
2696 /*
2697 Shave the image edges.
2698 */
2699 (void) SyncImageSettings(mogrify_info,*image);
2700 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2701 mogrify_image=ShaveImage(*image,&geometry,exception);
2702 break;
2703 }
2704 if (LocaleCompare("shear",option+1) == 0)
2705 {
2706 /*
2707 Shear image.
2708 */
2709 (void) SyncImageSettings(mogrify_info,*image);
2710 flags=ParseGeometry(argv[i+1],&geometry_info);
2711 if ((flags & SigmaValue) == 0)
2712 geometry_info.sigma=geometry_info.rho;
2713 mogrify_image=ShearImage(*image,geometry_info.rho,
2714 geometry_info.sigma,exception);
2715 break;
2716 }
2717 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2718 {
2719 /*
2720 Sigmoidal non-linearity contrast control.
2721 */
2722 (void) SyncImageSettings(mogrify_info,*image);
2723 flags=ParseGeometry(argv[i+1],&geometry_info);
2724 if ((flags & SigmaValue) == 0)
2725 geometry_info.sigma=(double) QuantumRange/2.0;
2726 if ((flags & PercentValue) != 0)
2727 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2728 100.0;
cristy9ee60942011-07-06 14:54:38 +00002729 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2730 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002731 InheritException(exception,&(*image)->exception);
2732 break;
2733 }
2734 if (LocaleCompare("sketch",option+1) == 0)
2735 {
2736 /*
2737 Sketch image.
2738 */
2739 (void) SyncImageSettings(mogrify_info,*image);
2740 flags=ParseGeometry(argv[i+1],&geometry_info);
2741 if ((flags & SigmaValue) == 0)
2742 geometry_info.sigma=1.0;
2743 mogrify_image=SketchImage(*image,geometry_info.rho,
2744 geometry_info.sigma,geometry_info.xi,exception);
2745 break;
2746 }
2747 if (LocaleCompare("solarize",option+1) == 0)
2748 {
2749 double
2750 threshold;
2751
2752 (void) SyncImageSettings(mogrify_info,*image);
2753 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2754 (void) SolarizeImage(*image,threshold);
2755 InheritException(exception,&(*image)->exception);
2756 break;
2757 }
2758 if (LocaleCompare("sparse-color",option+1) == 0)
2759 {
2760 SparseColorMethod
2761 method;
2762
2763 char
2764 *arguments;
2765
2766 /*
2767 Sparse Color Interpolated Gradient
2768 */
2769 (void) SyncImageSettings(mogrify_info,*image);
2770 method=(SparseColorMethod) ParseCommandOption(
2771 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2772 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2773 InheritException(exception,&(*image)->exception);
2774 if (arguments == (char *) NULL)
2775 break;
cristy3884f692011-07-08 18:00:18 +00002776 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002777 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2778 arguments=DestroyString(arguments);
2779 break;
2780 }
2781 if (LocaleCompare("splice",option+1) == 0)
2782 {
2783 /*
2784 Splice a solid color into the image.
2785 */
2786 (void) SyncImageSettings(mogrify_info,*image);
2787 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2788 mogrify_image=SpliceImage(*image,&geometry,exception);
2789 break;
2790 }
2791 if (LocaleCompare("spread",option+1) == 0)
2792 {
2793 /*
2794 Spread an image.
2795 */
2796 (void) SyncImageSettings(mogrify_info,*image);
2797 (void) ParseGeometry(argv[i+1],&geometry_info);
2798 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2799 break;
2800 }
2801 if (LocaleCompare("statistic",option+1) == 0)
2802 {
2803 StatisticType
2804 type;
2805
2806 (void) SyncImageSettings(mogrify_info,*image);
2807 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2808 MagickFalse,argv[i+1]);
2809 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002810 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2811 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002812 break;
2813 }
2814 if (LocaleCompare("stretch",option+1) == 0)
2815 {
2816 if (*option == '+')
2817 {
2818 draw_info->stretch=UndefinedStretch;
2819 break;
2820 }
2821 draw_info->stretch=(StretchType) ParseCommandOption(
2822 MagickStretchOptions,MagickFalse,argv[i+1]);
2823 break;
2824 }
2825 if (LocaleCompare("strip",option+1) == 0)
2826 {
2827 /*
2828 Strip image of profiles and comments.
2829 */
2830 (void) SyncImageSettings(mogrify_info,*image);
2831 (void) StripImage(*image);
2832 InheritException(exception,&(*image)->exception);
2833 break;
2834 }
2835 if (LocaleCompare("stroke",option+1) == 0)
2836 {
2837 ExceptionInfo
2838 *sans;
2839
2840 if (*option == '+')
2841 {
2842 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2843 if (draw_info->stroke_pattern != (Image *) NULL)
2844 draw_info->stroke_pattern=DestroyImage(
2845 draw_info->stroke_pattern);
2846 break;
2847 }
2848 sans=AcquireExceptionInfo();
2849 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2850 sans=DestroyExceptionInfo(sans);
2851 if (status == MagickFalse)
2852 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2853 exception);
2854 break;
2855 }
2856 if (LocaleCompare("strokewidth",option+1) == 0)
2857 {
cristyc1acd842011-05-19 23:05:47 +00002858 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2859 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002860 break;
2861 }
2862 if (LocaleCompare("style",option+1) == 0)
2863 {
2864 if (*option == '+')
2865 {
2866 draw_info->style=UndefinedStyle;
2867 break;
2868 }
2869 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2870 MagickFalse,argv[i+1]);
2871 break;
2872 }
2873 if (LocaleCompare("swirl",option+1) == 0)
2874 {
2875 /*
2876 Swirl image.
2877 */
2878 (void) SyncImageSettings(mogrify_info,*image);
2879 (void) ParseGeometry(argv[i+1],&geometry_info);
2880 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2881 break;
2882 }
2883 break;
2884 }
2885 case 't':
2886 {
2887 if (LocaleCompare("threshold",option+1) == 0)
2888 {
2889 double
2890 threshold;
2891
2892 /*
2893 Threshold image.
2894 */
2895 (void) SyncImageSettings(mogrify_info,*image);
2896 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002897 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002898 else
2899 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002900 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002901 InheritException(exception,&(*image)->exception);
2902 break;
2903 }
2904 if (LocaleCompare("thumbnail",option+1) == 0)
2905 {
2906 /*
2907 Thumbnail image.
2908 */
2909 (void) SyncImageSettings(mogrify_info,*image);
2910 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2911 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2912 exception);
2913 break;
2914 }
2915 if (LocaleCompare("tile",option+1) == 0)
2916 {
2917 if (*option == '+')
2918 {
2919 if (draw_info->fill_pattern != (Image *) NULL)
2920 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2921 break;
2922 }
2923 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2924 exception);
2925 break;
2926 }
2927 if (LocaleCompare("tint",option+1) == 0)
2928 {
2929 /*
2930 Tint the image.
2931 */
2932 (void) SyncImageSettings(mogrify_info,*image);
2933 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2934 break;
2935 }
2936 if (LocaleCompare("transform",option+1) == 0)
2937 {
2938 /*
2939 Affine transform image.
2940 */
2941 (void) SyncImageSettings(mogrify_info,*image);
2942 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2943 exception);
2944 break;
2945 }
2946 if (LocaleCompare("transparent",option+1) == 0)
2947 {
cristy4c08aed2011-07-01 19:47:50 +00002948 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002949 target;
2950
2951 (void) SyncImageSettings(mogrify_info,*image);
2952 (void) QueryMagickColor(argv[i+1],&target,exception);
2953 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002954 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002955 InheritException(exception,&(*image)->exception);
2956 break;
2957 }
2958 if (LocaleCompare("transpose",option+1) == 0)
2959 {
2960 /*
2961 Transpose image scanlines.
2962 */
2963 (void) SyncImageSettings(mogrify_info,*image);
2964 mogrify_image=TransposeImage(*image,exception);
2965 break;
2966 }
2967 if (LocaleCompare("transverse",option+1) == 0)
2968 {
2969 /*
2970 Transverse image scanlines.
2971 */
2972 (void) SyncImageSettings(mogrify_info,*image);
2973 mogrify_image=TransverseImage(*image,exception);
2974 break;
2975 }
2976 if (LocaleCompare("treedepth",option+1) == 0)
2977 {
2978 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2979 break;
2980 }
2981 if (LocaleCompare("trim",option+1) == 0)
2982 {
2983 /*
2984 Trim image.
2985 */
2986 (void) SyncImageSettings(mogrify_info,*image);
2987 mogrify_image=TrimImage(*image,exception);
2988 break;
2989 }
2990 if (LocaleCompare("type",option+1) == 0)
2991 {
2992 ImageType
2993 type;
2994
2995 (void) SyncImageSettings(mogrify_info,*image);
2996 if (*option == '+')
2997 type=UndefinedType;
2998 else
2999 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3000 argv[i+1]);
3001 (*image)->type=UndefinedType;
3002 (void) SetImageType(*image,type);
3003 InheritException(exception,&(*image)->exception);
3004 break;
3005 }
3006 break;
3007 }
3008 case 'u':
3009 {
3010 if (LocaleCompare("undercolor",option+1) == 0)
3011 {
3012 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3013 exception);
3014 break;
3015 }
3016 if (LocaleCompare("unique",option+1) == 0)
3017 {
3018 if (*option == '+')
3019 {
3020 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3021 break;
3022 }
3023 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3024 (void) SetImageArtifact(*image,"verbose","true");
3025 break;
3026 }
3027 if (LocaleCompare("unique-colors",option+1) == 0)
3028 {
3029 /*
3030 Unique image colors.
3031 */
3032 (void) SyncImageSettings(mogrify_info,*image);
3033 mogrify_image=UniqueImageColors(*image,exception);
3034 break;
3035 }
3036 if (LocaleCompare("unsharp",option+1) == 0)
3037 {
3038 /*
3039 Unsharp mask image.
3040 */
3041 (void) SyncImageSettings(mogrify_info,*image);
3042 flags=ParseGeometry(argv[i+1],&geometry_info);
3043 if ((flags & SigmaValue) == 0)
3044 geometry_info.sigma=1.0;
3045 if ((flags & XiValue) == 0)
3046 geometry_info.xi=1.0;
3047 if ((flags & PsiValue) == 0)
3048 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003049 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3050 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003051 break;
3052 }
3053 break;
3054 }
3055 case 'v':
3056 {
3057 if (LocaleCompare("verbose",option+1) == 0)
3058 {
3059 (void) SetImageArtifact(*image,option+1,
3060 *option == '+' ? "false" : "true");
3061 break;
3062 }
3063 if (LocaleCompare("vignette",option+1) == 0)
3064 {
3065 /*
3066 Vignette image.
3067 */
3068 (void) SyncImageSettings(mogrify_info,*image);
3069 flags=ParseGeometry(argv[i+1],&geometry_info);
3070 if ((flags & SigmaValue) == 0)
3071 geometry_info.sigma=1.0;
3072 if ((flags & XiValue) == 0)
3073 geometry_info.xi=0.1*(*image)->columns;
3074 if ((flags & PsiValue) == 0)
3075 geometry_info.psi=0.1*(*image)->rows;
3076 mogrify_image=VignetteImage(*image,geometry_info.rho,
3077 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3078 ceil(geometry_info.psi-0.5),exception);
3079 break;
3080 }
3081 if (LocaleCompare("virtual-pixel",option+1) == 0)
3082 {
3083 if (*option == '+')
3084 {
3085 (void) SetImageVirtualPixelMethod(*image,
3086 UndefinedVirtualPixelMethod);
3087 break;
3088 }
3089 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3090 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3091 argv[i+1]));
3092 break;
3093 }
3094 break;
3095 }
3096 case 'w':
3097 {
3098 if (LocaleCompare("wave",option+1) == 0)
3099 {
3100 /*
3101 Wave image.
3102 */
3103 (void) SyncImageSettings(mogrify_info,*image);
3104 flags=ParseGeometry(argv[i+1],&geometry_info);
3105 if ((flags & SigmaValue) == 0)
3106 geometry_info.sigma=1.0;
3107 mogrify_image=WaveImage(*image,geometry_info.rho,
3108 geometry_info.sigma,exception);
3109 break;
3110 }
3111 if (LocaleCompare("weight",option+1) == 0)
3112 {
3113 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3114 if (LocaleCompare(argv[i+1],"all") == 0)
3115 draw_info->weight=0;
3116 if (LocaleCompare(argv[i+1],"bold") == 0)
3117 draw_info->weight=700;
3118 if (LocaleCompare(argv[i+1],"bolder") == 0)
3119 if (draw_info->weight <= 800)
3120 draw_info->weight+=100;
3121 if (LocaleCompare(argv[i+1],"lighter") == 0)
3122 if (draw_info->weight >= 100)
3123 draw_info->weight-=100;
3124 if (LocaleCompare(argv[i+1],"normal") == 0)
3125 draw_info->weight=400;
3126 break;
3127 }
3128 if (LocaleCompare("white-threshold",option+1) == 0)
3129 {
3130 /*
3131 White threshold image.
3132 */
3133 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003134 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003135 InheritException(exception,&(*image)->exception);
3136 break;
3137 }
3138 break;
3139 }
3140 default:
3141 break;
3142 }
3143 /*
3144 Replace current image with any image that was generated
3145 */
3146 if (mogrify_image != (Image *) NULL)
3147 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003148 i+=count;
3149 }
3150 if (region_image != (Image *) NULL)
3151 {
anthonydf8ebac2011-04-27 09:03:19 +00003152 /*
3153 Composite transformed region onto image.
3154 */
cristy6b3da3a2010-06-20 02:21:46 +00003155 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003156 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003157 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3158 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003159 InheritException(exception,&region_image->exception);
3160 *image=DestroyImage(*image);
3161 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003162 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003163 }
3164 /*
3165 Free resources.
3166 */
anthonydf8ebac2011-04-27 09:03:19 +00003167 quantize_info=DestroyQuantizeInfo(quantize_info);
3168 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003169 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003170 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003171 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003172 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003173}
3174
3175/*
3176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3177% %
3178% %
3179% %
cristy5063d812010-10-19 16:28:10 +00003180+ 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 +00003181% %
3182% %
3183% %
3184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3185%
3186% MogrifyImageCommand() transforms an image or a sequence of images. These
3187% transforms include image scaling, image rotation, color reduction, and
3188% others. The transmogrified image overwrites the original image.
3189%
3190% The format of the MogrifyImageCommand method is:
3191%
3192% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3193% const char **argv,char **metadata,ExceptionInfo *exception)
3194%
3195% A description of each parameter follows:
3196%
3197% o image_info: the image info.
3198%
3199% o argc: the number of elements in the argument vector.
3200%
3201% o argv: A text array containing the command line arguments.
3202%
3203% o metadata: any metadata is returned here.
3204%
3205% o exception: return any errors or warnings in this structure.
3206%
3207*/
3208
3209static MagickBooleanType MogrifyUsage(void)
3210{
3211 static const char
3212 *miscellaneous[]=
3213 {
3214 "-debug events display copious debugging information",
3215 "-help print program options",
3216 "-list type print a list of supported option arguments",
3217 "-log format format of debugging information",
3218 "-version print version information",
3219 (char *) NULL
3220 },
3221 *operators[]=
3222 {
3223 "-adaptive-blur geometry",
3224 " adaptively blur pixels; decrease effect near edges",
3225 "-adaptive-resize geometry",
3226 " adaptively resize image using 'mesh' interpolation",
3227 "-adaptive-sharpen geometry",
3228 " adaptively sharpen pixels; increase effect near edges",
3229 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3230 " transparent, extract, background, or shape",
3231 "-annotate geometry text",
3232 " annotate the image with text",
3233 "-auto-gamma automagically adjust gamma level of image",
3234 "-auto-level automagically adjust color levels of image",
3235 "-auto-orient automagically orient (rotate) image",
3236 "-bench iterations measure performance",
3237 "-black-threshold value",
3238 " force all pixels below the threshold into black",
3239 "-blue-shift simulate a scene at nighttime in the moonlight",
3240 "-blur geometry reduce image noise and reduce detail levels",
3241 "-border geometry surround image with a border of color",
3242 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003243 "-brightness-contrast geometry",
3244 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003245 "-cdl filename color correct with a color decision list",
3246 "-charcoal radius simulate a charcoal drawing",
3247 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003248 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003249 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003250 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003251 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003252 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003253 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003254 "-contrast enhance or reduce the image contrast",
3255 "-contrast-stretch geometry",
3256 " improve contrast by `stretching' the intensity range",
3257 "-convolve coefficients",
3258 " apply a convolution kernel to the image",
3259 "-cycle amount cycle the image colormap",
3260 "-decipher filename convert cipher pixels to plain pixels",
3261 "-deskew threshold straighten an image",
3262 "-despeckle reduce the speckles within an image",
3263 "-distort method args",
3264 " distort images according to given method ad args",
3265 "-draw string annotate the image with a graphic primitive",
3266 "-edge radius apply a filter to detect edges in the image",
3267 "-encipher filename convert plain pixels to cipher pixels",
3268 "-emboss radius emboss an image",
3269 "-enhance apply a digital filter to enhance a noisy image",
3270 "-equalize perform histogram equalization to an image",
3271 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003272 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003273 "-extent geometry set the image size",
3274 "-extract geometry extract area from image",
3275 "-fft implements the discrete Fourier transform (DFT)",
3276 "-flip flip image vertically",
3277 "-floodfill geometry color",
3278 " floodfill the image with color",
3279 "-flop flop image horizontally",
3280 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003281 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003282 " apply function over image values",
3283 "-gamma value level of gamma correction",
3284 "-gaussian-blur geometry",
3285 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003286 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003287 "-identify identify the format and characteristics of the image",
3288 "-ift implements the inverse discrete Fourier transform (DFT)",
3289 "-implode amount implode image pixels about the center",
3290 "-lat geometry local adaptive thresholding",
3291 "-layers method optimize, merge, or compare image layers",
3292 "-level value adjust the level of image contrast",
3293 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003294 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003295 "-linear-stretch geometry",
3296 " improve contrast by `stretching with saturation'",
3297 "-liquid-rescale geometry",
3298 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003299 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003300 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003301 "-modulate value vary the brightness, saturation, and hue",
3302 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003303 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003304 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003305 "-motion-blur geometry",
3306 " simulate motion blur",
3307 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003308 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003309 "-normalize transform image to span the full range of colors",
3310 "-opaque color change this color to the fill color",
3311 "-ordered-dither NxN",
3312 " add a noise pattern to the image with specific",
3313 " amplitudes",
3314 "-paint radius simulate an oil painting",
3315 "-polaroid angle simulate a Polaroid picture",
3316 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003317 "-profile filename add, delete, or apply an image profile",
3318 "-quantize colorspace reduce colors in this colorspace",
3319 "-radial-blur angle radial blur the image",
3320 "-raise value lighten/darken image edges to create a 3-D effect",
3321 "-random-threshold low,high",
3322 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003323 "-region geometry apply options to a portion of the image",
3324 "-render render vector graphics",
3325 "-repage geometry size and location of an image canvas",
3326 "-resample geometry change the resolution of an image",
3327 "-resize geometry resize the image",
3328 "-roll geometry roll an image vertically or horizontally",
3329 "-rotate degrees apply Paeth rotation to the image",
3330 "-sample geometry scale image with pixel sampling",
3331 "-scale geometry scale the image",
3332 "-segment values segment an image",
3333 "-selective-blur geometry",
3334 " selectively blur pixels within a contrast threshold",
3335 "-sepia-tone threshold",
3336 " simulate a sepia-toned photo",
3337 "-set property value set an image property",
3338 "-shade degrees shade the image using a distant light source",
3339 "-shadow geometry simulate an image shadow",
3340 "-sharpen geometry sharpen the image",
3341 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003342 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-sigmoidal-contrast geometry",
3344 " increase the contrast without saturating highlights or shadows",
3345 "-sketch geometry simulate a pencil sketch",
3346 "-solarize threshold negate all pixels above the threshold level",
3347 "-sparse-color method args",
3348 " fill in a image based on a few color points",
3349 "-splice geometry splice the background color into the image",
3350 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003351 "-statistic type radius",
3352 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003353 "-strip strip image of all profiles and comments",
3354 "-swirl degrees swirl image pixels about the center",
3355 "-threshold value threshold the image",
3356 "-thumbnail geometry create a thumbnail of the image",
3357 "-tile filename tile image when filling a graphic primitive",
3358 "-tint value tint the image with the fill color",
3359 "-transform affine transform image",
3360 "-transparent color make this color transparent within the image",
3361 "-transpose flip image vertically and rotate 90 degrees",
3362 "-transverse flop image horizontally and rotate 270 degrees",
3363 "-trim trim image edges",
3364 "-type type image type",
3365 "-unique-colors discard all but one of any pixel color",
3366 "-unsharp geometry sharpen the image",
3367 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003368 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-white-threshold value",
3370 " force all pixels above the threshold into white",
3371 (char *) NULL
3372 },
3373 *sequence_operators[]=
3374 {
cristy4285d782011-02-09 20:12:28 +00003375 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003376 "-clut apply a color lookup table to the image",
3377 "-coalesce merge a sequence of images",
3378 "-combine combine a sequence of images",
3379 "-composite composite image",
3380 "-crop geometry cut out a rectangular region of the image",
3381 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003382 "-evaluate-sequence operator",
3383 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003384 "-flatten flatten a sequence of images",
3385 "-fx expression apply mathematical expression to an image channel(s)",
3386 "-hald-clut apply a Hald color lookup table to the image",
3387 "-morph value morph an image sequence",
3388 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003389 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003390 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003391 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003392 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003393 "-write filename write images to this file",
3394 (char *) NULL
3395 },
3396 *settings[]=
3397 {
3398 "-adjoin join images into a single multi-image file",
3399 "-affine matrix affine transform matrix",
3400 "-alpha option activate, deactivate, reset, or set the alpha channel",
3401 "-antialias remove pixel-aliasing",
3402 "-authenticate password",
3403 " decipher image with this password",
3404 "-attenuate value lessen (or intensify) when adding noise to an image",
3405 "-background color background color",
3406 "-bias value add bias when convolving an image",
3407 "-black-point-compensation",
3408 " use black point compensation",
3409 "-blue-primary point chromaticity blue primary point",
3410 "-bordercolor color border color",
3411 "-caption string assign a caption to an image",
3412 "-channel type apply option to select image channels",
3413 "-colors value preferred number of colors in the image",
3414 "-colorspace type alternate image colorspace",
3415 "-comment string annotate image with comment",
3416 "-compose operator set image composite operator",
3417 "-compress type type of pixel compression when writing the image",
3418 "-define format:option",
3419 " define one or more image format options",
3420 "-delay value display the next image after pausing",
3421 "-density geometry horizontal and vertical density of the image",
3422 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003423 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003424 "-display server get image or font from this X server",
3425 "-dispose method layer disposal method",
3426 "-dither method apply error diffusion to image",
3427 "-encoding type text encoding type",
3428 "-endian type endianness (MSB or LSB) of the image",
3429 "-family name render text with this font family",
3430 "-fill color color to use when filling a graphic primitive",
3431 "-filter type use this filter when resizing an image",
3432 "-font name render text with this font",
3433 "-format \"string\" output formatted image characteristics",
3434 "-fuzz distance colors within this distance are considered equal",
3435 "-gravity type horizontal and vertical text placement",
3436 "-green-primary point chromaticity green primary point",
3437 "-intent type type of rendering intent when managing the image color",
3438 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003439 "-interline-spacing value",
3440 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003441 "-interpolate method pixel color interpolation method",
3442 "-interword-spacing value",
3443 " set the space between two words",
3444 "-kerning value set the space between two letters",
3445 "-label string assign a label to an image",
3446 "-limit type value pixel cache resource limit",
3447 "-loop iterations add Netscape loop extension to your GIF animation",
3448 "-mask filename associate a mask with the image",
3449 "-mattecolor color frame color",
3450 "-monitor monitor progress",
3451 "-orient type image orientation",
3452 "-page geometry size and location of an image canvas (setting)",
3453 "-ping efficiently determine image attributes",
3454 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003455 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003456 "-preview type image preview type",
3457 "-quality value JPEG/MIFF/PNG compression level",
3458 "-quiet suppress all warning messages",
3459 "-red-primary point chromaticity red primary point",
3460 "-regard-warnings pay attention to warning messages",
3461 "-remap filename transform image colors to match this set of colors",
3462 "-respect-parentheses settings remain in effect until parenthesis boundary",
3463 "-sampling-factor geometry",
3464 " horizontal and vertical sampling factor",
3465 "-scene value image scene number",
3466 "-seed value seed a new sequence of pseudo-random numbers",
3467 "-size geometry width and height of image",
3468 "-stretch type render text with this font stretch",
3469 "-stroke color graphic primitive stroke color",
3470 "-strokewidth value graphic primitive stroke width",
3471 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003472 "-synchronize synchronize image to storage device",
3473 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003474 "-texture filename name of texture to tile onto the image background",
3475 "-tile-offset geometry",
3476 " tile offset",
3477 "-treedepth value color tree depth",
3478 "-transparent-color color",
3479 " transparent color",
3480 "-undercolor color annotation bounding box color",
3481 "-units type the units of image resolution",
3482 "-verbose print detailed information about the image",
3483 "-view FlashPix viewing transforms",
3484 "-virtual-pixel method",
3485 " virtual pixel access method",
3486 "-weight type render text with this font weight",
3487 "-white-point point chromaticity white point",
3488 (char *) NULL
3489 },
3490 *stack_operators[]=
3491 {
anthonyb69c4b32011-03-23 04:37:44 +00003492 "-delete indexes delete the image from the image sequence",
3493 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003494 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003495 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003496 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003497 "-swap indexes swap two images in the image sequence",
3498 (char *) NULL
3499 };
3500
3501 const char
3502 **p;
3503
cristybb503372010-05-27 20:51:26 +00003504 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003505 (void) printf("Copyright: %s\n",GetMagickCopyright());
3506 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003507 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3508 GetClientName());
3509 (void) printf("\nImage Settings:\n");
3510 for (p=settings; *p != (char *) NULL; p++)
3511 (void) printf(" %s\n",*p);
3512 (void) printf("\nImage Operators:\n");
3513 for (p=operators; *p != (char *) NULL; p++)
3514 (void) printf(" %s\n",*p);
3515 (void) printf("\nImage Sequence Operators:\n");
3516 for (p=sequence_operators; *p != (char *) NULL; p++)
3517 (void) printf(" %s\n",*p);
3518 (void) printf("\nImage Stack Operators:\n");
3519 for (p=stack_operators; *p != (char *) NULL; p++)
3520 (void) printf(" %s\n",*p);
3521 (void) printf("\nMiscellaneous Options:\n");
3522 for (p=miscellaneous; *p != (char *) NULL; p++)
3523 (void) printf(" %s\n",*p);
3524 (void) printf(
3525 "\nBy default, the image format of `file' is determined by its magic\n");
3526 (void) printf(
3527 "number. To specify a particular image format, precede the filename\n");
3528 (void) printf(
3529 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3530 (void) printf(
3531 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3532 (void) printf("'-' for standard input or output.\n");
3533 return(MagickFalse);
3534}
3535
3536WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3537 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3538{
3539#define DestroyMogrify() \
3540{ \
3541 if (format != (char *) NULL) \
3542 format=DestroyString(format); \
3543 if (path != (char *) NULL) \
3544 path=DestroyString(path); \
3545 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003546 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003547 argv[i]=DestroyString(argv[i]); \
3548 argv=(char **) RelinquishMagickMemory(argv); \
3549}
3550#define ThrowMogrifyException(asperity,tag,option) \
3551{ \
3552 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3553 option); \
3554 DestroyMogrify(); \
3555 return(MagickFalse); \
3556}
3557#define ThrowMogrifyInvalidArgumentException(option,argument) \
3558{ \
3559 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3560 "InvalidArgument","`%s': %s",argument,option); \
3561 DestroyMogrify(); \
3562 return(MagickFalse); \
3563}
3564
3565 char
3566 *format,
3567 *option,
3568 *path;
3569
3570 Image
3571 *image;
3572
3573 ImageStack
3574 image_stack[MaxImageStackDepth+1];
3575
cristy3ed852e2009-09-05 21:47:34 +00003576 MagickBooleanType
3577 global_colormap;
3578
3579 MagickBooleanType
3580 fire,
cristyebbcfea2011-02-25 02:43:54 +00003581 pend,
3582 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003583
3584 MagickStatusType
3585 status;
3586
cristyebbcfea2011-02-25 02:43:54 +00003587 register ssize_t
3588 i;
3589
3590 ssize_t
3591 j,
3592 k;
3593
cristy3ed852e2009-09-05 21:47:34 +00003594 /*
3595 Set defaults.
3596 */
3597 assert(image_info != (ImageInfo *) NULL);
3598 assert(image_info->signature == MagickSignature);
3599 if (image_info->debug != MagickFalse)
3600 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3601 assert(exception != (ExceptionInfo *) NULL);
3602 if (argc == 2)
3603 {
3604 option=argv[1];
3605 if ((LocaleCompare("version",option+1) == 0) ||
3606 (LocaleCompare("-version",option+1) == 0))
3607 {
cristyb51dff52011-05-19 16:55:47 +00003608 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003609 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003610 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3611 GetMagickCopyright());
3612 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3613 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003614 return(MagickFalse);
3615 }
3616 }
3617 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003618 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003619 format=(char *) NULL;
3620 path=(char *) NULL;
3621 global_colormap=MagickFalse;
3622 k=0;
3623 j=1;
3624 NewImageStack();
3625 option=(char *) NULL;
3626 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003627 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003628 status=MagickTrue;
3629 /*
3630 Parse command line.
3631 */
3632 ReadCommandlLine(argc,&argv);
3633 status=ExpandFilenames(&argc,&argv);
3634 if (status == MagickFalse)
3635 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3636 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003637 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003638 {
3639 option=argv[i];
3640 if (LocaleCompare(option,"(") == 0)
3641 {
3642 FireImageStack(MagickFalse,MagickTrue,pend);
3643 if (k == MaxImageStackDepth)
3644 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3645 option);
3646 PushImageStack();
3647 continue;
3648 }
3649 if (LocaleCompare(option,")") == 0)
3650 {
3651 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3652 if (k == 0)
3653 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3654 PopImageStack();
3655 continue;
3656 }
cristy042ee782011-04-22 18:48:30 +00003657 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003658 {
3659 char
3660 backup_filename[MaxTextExtent],
3661 *filename;
3662
3663 Image
3664 *images;
3665
3666 /*
3667 Option is a file name: begin by reading image from specified file.
3668 */
3669 FireImageStack(MagickFalse,MagickFalse,pend);
3670 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003671 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003672 filename=argv[++i];
3673 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3674 images=ReadImages(image_info,exception);
3675 status&=(images != (Image *) NULL) &&
3676 (exception->severity < ErrorException);
3677 if (images == (Image *) NULL)
3678 continue;
cristydaa76602010-06-30 13:05:11 +00003679 if (format != (char *) NULL)
3680 (void) CopyMagickString(images->filename,images->magick_filename,
3681 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003682 if (path != (char *) NULL)
3683 {
3684 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003685 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003686 path,*DirectorySeparator,filename);
3687 }
3688 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003689 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003690 AppendImageStack(images);
3691 FinalizeImageSettings(image_info,image,MagickFalse);
3692 if (global_colormap != MagickFalse)
3693 {
3694 QuantizeInfo
3695 *quantize_info;
3696
3697 quantize_info=AcquireQuantizeInfo(image_info);
3698 (void) RemapImages(quantize_info,images,(Image *) NULL);
3699 quantize_info=DestroyQuantizeInfo(quantize_info);
3700 }
3701 *backup_filename='\0';
3702 if ((LocaleCompare(image->filename,"-") != 0) &&
3703 (IsPathWritable(image->filename) != MagickFalse))
3704 {
cristybb503372010-05-27 20:51:26 +00003705 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003706 i;
3707
3708 /*
3709 Rename image file as backup.
3710 */
3711 (void) CopyMagickString(backup_filename,image->filename,
3712 MaxTextExtent);
3713 for (i=0; i < 6; i++)
3714 {
3715 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3716 if (IsPathAccessible(backup_filename) == MagickFalse)
3717 break;
3718 }
3719 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3720 (rename(image->filename,backup_filename) != 0))
3721 *backup_filename='\0';
3722 }
3723 /*
3724 Write transmogrified image to disk.
3725 */
3726 image_info->synchronize=MagickTrue;
3727 status&=WriteImages(image_info,image,image->filename,exception);
3728 if ((status == MagickFalse) && (*backup_filename != '\0'))
3729 (void) remove(backup_filename);
3730 RemoveAllImageStack();
3731 continue;
3732 }
3733 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3734 switch (*(option+1))
3735 {
3736 case 'a':
3737 {
3738 if (LocaleCompare("adaptive-blur",option+1) == 0)
3739 {
3740 i++;
cristybb503372010-05-27 20:51:26 +00003741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003742 ThrowMogrifyException(OptionError,"MissingArgument",option);
3743 if (IsGeometry(argv[i]) == MagickFalse)
3744 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3745 break;
3746 }
3747 if (LocaleCompare("adaptive-resize",option+1) == 0)
3748 {
3749 i++;
cristybb503372010-05-27 20:51:26 +00003750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003751 ThrowMogrifyException(OptionError,"MissingArgument",option);
3752 if (IsGeometry(argv[i]) == MagickFalse)
3753 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3754 break;
3755 }
3756 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3757 {
3758 i++;
cristybb503372010-05-27 20:51:26 +00003759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003760 ThrowMogrifyException(OptionError,"MissingArgument",option);
3761 if (IsGeometry(argv[i]) == MagickFalse)
3762 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3763 break;
3764 }
3765 if (LocaleCompare("affine",option+1) == 0)
3766 {
3767 if (*option == '+')
3768 break;
3769 i++;
cristybb503372010-05-27 20:51:26 +00003770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003771 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003772 break;
3773 }
3774 if (LocaleCompare("alpha",option+1) == 0)
3775 {
cristybb503372010-05-27 20:51:26 +00003776 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003777 type;
3778
3779 if (*option == '+')
3780 break;
3781 i++;
cristybb503372010-05-27 20:51:26 +00003782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003783 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003784 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003785 if (type < 0)
3786 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3787 argv[i]);
3788 break;
3789 }
3790 if (LocaleCompare("annotate",option+1) == 0)
3791 {
3792 if (*option == '+')
3793 break;
3794 i++;
cristybb503372010-05-27 20:51:26 +00003795 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003796 ThrowMogrifyException(OptionError,"MissingArgument",option);
3797 if (IsGeometry(argv[i]) == MagickFalse)
3798 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003800 ThrowMogrifyException(OptionError,"MissingArgument",option);
3801 i++;
3802 break;
3803 }
3804 if (LocaleCompare("antialias",option+1) == 0)
3805 break;
3806 if (LocaleCompare("append",option+1) == 0)
3807 break;
3808 if (LocaleCompare("attenuate",option+1) == 0)
3809 {
3810 if (*option == '+')
3811 break;
3812 i++;
cristybb503372010-05-27 20:51:26 +00003813 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003814 ThrowMogrifyException(OptionError,"MissingArgument",option);
3815 if (IsGeometry(argv[i]) == MagickFalse)
3816 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3817 break;
3818 }
3819 if (LocaleCompare("authenticate",option+1) == 0)
3820 {
3821 if (*option == '+')
3822 break;
3823 i++;
cristybb503372010-05-27 20:51:26 +00003824 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003825 ThrowMogrifyException(OptionError,"MissingArgument",option);
3826 break;
3827 }
3828 if (LocaleCompare("auto-gamma",option+1) == 0)
3829 break;
3830 if (LocaleCompare("auto-level",option+1) == 0)
3831 break;
3832 if (LocaleCompare("auto-orient",option+1) == 0)
3833 break;
3834 if (LocaleCompare("average",option+1) == 0)
3835 break;
3836 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3837 }
3838 case 'b':
3839 {
3840 if (LocaleCompare("background",option+1) == 0)
3841 {
3842 if (*option == '+')
3843 break;
3844 i++;
cristybb503372010-05-27 20:51:26 +00003845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003846 ThrowMogrifyException(OptionError,"MissingArgument",option);
3847 break;
3848 }
3849 if (LocaleCompare("bias",option+1) == 0)
3850 {
3851 if (*option == '+')
3852 break;
3853 i++;
cristybb503372010-05-27 20:51:26 +00003854 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003855 ThrowMogrifyException(OptionError,"MissingArgument",option);
3856 if (IsGeometry(argv[i]) == MagickFalse)
3857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3858 break;
3859 }
3860 if (LocaleCompare("black-point-compensation",option+1) == 0)
3861 break;
3862 if (LocaleCompare("black-threshold",option+1) == 0)
3863 {
3864 if (*option == '+')
3865 break;
3866 i++;
cristybb503372010-05-27 20:51:26 +00003867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003868 ThrowMogrifyException(OptionError,"MissingArgument",option);
3869 if (IsGeometry(argv[i]) == MagickFalse)
3870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3871 break;
3872 }
3873 if (LocaleCompare("blue-primary",option+1) == 0)
3874 {
3875 if (*option == '+')
3876 break;
3877 i++;
cristybb503372010-05-27 20:51:26 +00003878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003879 ThrowMogrifyException(OptionError,"MissingArgument",option);
3880 if (IsGeometry(argv[i]) == MagickFalse)
3881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3882 break;
3883 }
3884 if (LocaleCompare("blue-shift",option+1) == 0)
3885 {
3886 i++;
cristybb503372010-05-27 20:51:26 +00003887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003888 ThrowMogrifyException(OptionError,"MissingArgument",option);
3889 if (IsGeometry(argv[i]) == MagickFalse)
3890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3891 break;
3892 }
3893 if (LocaleCompare("blur",option+1) == 0)
3894 {
3895 i++;
cristybb503372010-05-27 20:51:26 +00003896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003897 ThrowMogrifyException(OptionError,"MissingArgument",option);
3898 if (IsGeometry(argv[i]) == MagickFalse)
3899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3900 break;
3901 }
3902 if (LocaleCompare("border",option+1) == 0)
3903 {
3904 if (*option == '+')
3905 break;
3906 i++;
cristybb503372010-05-27 20:51:26 +00003907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003908 ThrowMogrifyException(OptionError,"MissingArgument",option);
3909 if (IsGeometry(argv[i]) == MagickFalse)
3910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3911 break;
3912 }
3913 if (LocaleCompare("bordercolor",option+1) == 0)
3914 {
3915 if (*option == '+')
3916 break;
3917 i++;
cristybb503372010-05-27 20:51:26 +00003918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003919 ThrowMogrifyException(OptionError,"MissingArgument",option);
3920 break;
3921 }
3922 if (LocaleCompare("box",option+1) == 0)
3923 {
3924 if (*option == '+')
3925 break;
3926 i++;
cristybb503372010-05-27 20:51:26 +00003927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003928 ThrowMogrifyException(OptionError,"MissingArgument",option);
3929 break;
3930 }
cristya28d6b82010-01-11 20:03:47 +00003931 if (LocaleCompare("brightness-contrast",option+1) == 0)
3932 {
3933 i++;
cristybb503372010-05-27 20:51:26 +00003934 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003935 ThrowMogrifyException(OptionError,"MissingArgument",option);
3936 if (IsGeometry(argv[i]) == MagickFalse)
3937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3938 break;
3939 }
cristy3ed852e2009-09-05 21:47:34 +00003940 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3941 }
3942 case 'c':
3943 {
3944 if (LocaleCompare("cache",option+1) == 0)
3945 {
3946 if (*option == '+')
3947 break;
3948 i++;
cristybb503372010-05-27 20:51:26 +00003949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003950 ThrowMogrifyException(OptionError,"MissingArgument",option);
3951 if (IsGeometry(argv[i]) == MagickFalse)
3952 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3953 break;
3954 }
3955 if (LocaleCompare("caption",option+1) == 0)
3956 {
3957 if (*option == '+')
3958 break;
3959 i++;
cristybb503372010-05-27 20:51:26 +00003960 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003961 ThrowMogrifyException(OptionError,"MissingArgument",option);
3962 break;
3963 }
3964 if (LocaleCompare("channel",option+1) == 0)
3965 {
cristybb503372010-05-27 20:51:26 +00003966 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003967 channel;
3968
3969 if (*option == '+')
3970 break;
3971 i++;
cristybb503372010-05-27 20:51:26 +00003972 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003973 ThrowMogrifyException(OptionError,"MissingArgument",option);
3974 channel=ParseChannelOption(argv[i]);
3975 if (channel < 0)
3976 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3977 argv[i]);
3978 break;
3979 }
3980 if (LocaleCompare("cdl",option+1) == 0)
3981 {
3982 if (*option == '+')
3983 break;
3984 i++;
cristybb503372010-05-27 20:51:26 +00003985 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003986 ThrowMogrifyException(OptionError,"MissingArgument",option);
3987 break;
3988 }
3989 if (LocaleCompare("charcoal",option+1) == 0)
3990 {
3991 if (*option == '+')
3992 break;
3993 i++;
cristybb503372010-05-27 20:51:26 +00003994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003995 ThrowMogrifyException(OptionError,"MissingArgument",option);
3996 if (IsGeometry(argv[i]) == MagickFalse)
3997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3998 break;
3999 }
4000 if (LocaleCompare("chop",option+1) == 0)
4001 {
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 if (IsGeometry(argv[i]) == MagickFalse)
4008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4009 break;
4010 }
cristy1eb45dd2009-09-25 16:38:06 +00004011 if (LocaleCompare("clamp",option+1) == 0)
4012 break;
4013 if (LocaleCompare("clip",option+1) == 0)
4014 break;
cristy3ed852e2009-09-05 21:47:34 +00004015 if (LocaleCompare("clip-mask",option+1) == 0)
4016 {
4017 if (*option == '+')
4018 break;
4019 i++;
cristybb503372010-05-27 20:51:26 +00004020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004021 ThrowMogrifyException(OptionError,"MissingArgument",option);
4022 break;
4023 }
4024 if (LocaleCompare("clut",option+1) == 0)
4025 break;
4026 if (LocaleCompare("coalesce",option+1) == 0)
4027 break;
4028 if (LocaleCompare("colorize",option+1) == 0)
4029 {
4030 if (*option == '+')
4031 break;
4032 i++;
cristybb503372010-05-27 20:51:26 +00004033 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004034 ThrowMogrifyException(OptionError,"MissingArgument",option);
4035 if (IsGeometry(argv[i]) == MagickFalse)
4036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4037 break;
4038 }
cristye6365592010-04-02 17:31:23 +00004039 if (LocaleCompare("color-matrix",option+1) == 0)
4040 {
cristyb6bd4ad2010-08-08 01:12:27 +00004041 KernelInfo
4042 *kernel_info;
4043
cristye6365592010-04-02 17:31:23 +00004044 if (*option == '+')
4045 break;
4046 i++;
cristybb503372010-05-27 20:51:26 +00004047 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004048 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004049 kernel_info=AcquireKernelInfo(argv[i]);
4050 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004051 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004052 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004053 break;
4054 }
cristy3ed852e2009-09-05 21:47:34 +00004055 if (LocaleCompare("colors",option+1) == 0)
4056 {
4057 if (*option == '+')
4058 break;
4059 i++;
cristybb503372010-05-27 20:51:26 +00004060 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004061 ThrowMogrifyException(OptionError,"MissingArgument",option);
4062 if (IsGeometry(argv[i]) == MagickFalse)
4063 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4064 break;
4065 }
4066 if (LocaleCompare("colorspace",option+1) == 0)
4067 {
cristybb503372010-05-27 20:51:26 +00004068 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004069 colorspace;
4070
4071 if (*option == '+')
4072 break;
4073 i++;
cristybb503372010-05-27 20:51:26 +00004074 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004075 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004076 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004077 argv[i]);
4078 if (colorspace < 0)
4079 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4080 argv[i]);
4081 break;
4082 }
4083 if (LocaleCompare("combine",option+1) == 0)
4084 break;
4085 if (LocaleCompare("comment",option+1) == 0)
4086 {
4087 if (*option == '+')
4088 break;
4089 i++;
cristybb503372010-05-27 20:51:26 +00004090 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004091 ThrowMogrifyException(OptionError,"MissingArgument",option);
4092 break;
4093 }
4094 if (LocaleCompare("composite",option+1) == 0)
4095 break;
4096 if (LocaleCompare("compress",option+1) == 0)
4097 {
cristybb503372010-05-27 20:51:26 +00004098 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004099 compress;
4100
4101 if (*option == '+')
4102 break;
4103 i++;
cristybb503372010-05-27 20:51:26 +00004104 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004105 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004106 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004107 argv[i]);
4108 if (compress < 0)
4109 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4110 argv[i]);
4111 break;
4112 }
cristy22879752009-10-25 23:55:40 +00004113 if (LocaleCompare("concurrent",option+1) == 0)
4114 break;
cristy3ed852e2009-09-05 21:47:34 +00004115 if (LocaleCompare("contrast",option+1) == 0)
4116 break;
4117 if (LocaleCompare("contrast-stretch",option+1) == 0)
4118 {
4119 i++;
cristybb503372010-05-27 20:51:26 +00004120 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004121 ThrowMogrifyException(OptionError,"MissingArgument",option);
4122 if (IsGeometry(argv[i]) == MagickFalse)
4123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4124 break;
4125 }
4126 if (LocaleCompare("convolve",option+1) == 0)
4127 {
cristyb6bd4ad2010-08-08 01:12:27 +00004128 KernelInfo
4129 *kernel_info;
4130
cristy3ed852e2009-09-05 21:47:34 +00004131 if (*option == '+')
4132 break;
4133 i++;
cristybb503372010-05-27 20:51:26 +00004134 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004135 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004136 kernel_info=AcquireKernelInfo(argv[i]);
4137 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004139 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004140 break;
4141 }
4142 if (LocaleCompare("crop",option+1) == 0)
4143 {
4144 if (*option == '+')
4145 break;
4146 i++;
cristybb503372010-05-27 20:51:26 +00004147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004148 ThrowMogrifyException(OptionError,"MissingArgument",option);
4149 if (IsGeometry(argv[i]) == MagickFalse)
4150 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4151 break;
4152 }
4153 if (LocaleCompare("cycle",option+1) == 0)
4154 {
4155 if (*option == '+')
4156 break;
4157 i++;
cristybb503372010-05-27 20:51:26 +00004158 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004159 ThrowMogrifyException(OptionError,"MissingArgument",option);
4160 if (IsGeometry(argv[i]) == MagickFalse)
4161 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4162 break;
4163 }
4164 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4165 }
4166 case 'd':
4167 {
4168 if (LocaleCompare("decipher",option+1) == 0)
4169 {
4170 if (*option == '+')
4171 break;
4172 i++;
cristybb503372010-05-27 20:51:26 +00004173 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004174 ThrowMogrifyException(OptionError,"MissingArgument",option);
4175 break;
4176 }
4177 if (LocaleCompare("deconstruct",option+1) == 0)
4178 break;
4179 if (LocaleCompare("debug",option+1) == 0)
4180 {
cristybb503372010-05-27 20:51:26 +00004181 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004182 event;
4183
4184 if (*option == '+')
4185 break;
4186 i++;
cristybb503372010-05-27 20:51:26 +00004187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004188 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004189 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004190 if (event < 0)
4191 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4192 argv[i]);
4193 (void) SetLogEventMask(argv[i]);
4194 break;
4195 }
4196 if (LocaleCompare("define",option+1) == 0)
4197 {
4198 i++;
cristybb503372010-05-27 20:51:26 +00004199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004200 ThrowMogrifyException(OptionError,"MissingArgument",option);
4201 if (*option == '+')
4202 {
4203 const char
4204 *define;
4205
4206 define=GetImageOption(image_info,argv[i]);
4207 if (define == (const char *) NULL)
4208 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4209 break;
4210 }
4211 break;
4212 }
4213 if (LocaleCompare("delay",option+1) == 0)
4214 {
4215 if (*option == '+')
4216 break;
4217 i++;
cristybb503372010-05-27 20:51:26 +00004218 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004219 ThrowMogrifyException(OptionError,"MissingArgument",option);
4220 if (IsGeometry(argv[i]) == MagickFalse)
4221 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4222 break;
4223 }
cristyecb10ff2011-03-22 13:14:03 +00004224 if (LocaleCompare("delete",option+1) == 0)
4225 {
4226 if (*option == '+')
4227 break;
4228 i++;
4229 if (i == (ssize_t) (argc-1))
4230 ThrowMogrifyException(OptionError,"MissingArgument",option);
4231 if (IsGeometry(argv[i]) == MagickFalse)
4232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4233 break;
4234 }
cristy3ed852e2009-09-05 21:47:34 +00004235 if (LocaleCompare("density",option+1) == 0)
4236 {
4237 if (*option == '+')
4238 break;
4239 i++;
cristybb503372010-05-27 20:51:26 +00004240 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004241 ThrowMogrifyException(OptionError,"MissingArgument",option);
4242 if (IsGeometry(argv[i]) == MagickFalse)
4243 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4244 break;
4245 }
4246 if (LocaleCompare("depth",option+1) == 0)
4247 {
4248 if (*option == '+')
4249 break;
4250 i++;
cristybb503372010-05-27 20:51:26 +00004251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004252 ThrowMogrifyException(OptionError,"MissingArgument",option);
4253 if (IsGeometry(argv[i]) == MagickFalse)
4254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4255 break;
4256 }
4257 if (LocaleCompare("deskew",option+1) == 0)
4258 {
4259 if (*option == '+')
4260 break;
4261 i++;
cristybb503372010-05-27 20:51:26 +00004262 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004263 ThrowMogrifyException(OptionError,"MissingArgument",option);
4264 if (IsGeometry(argv[i]) == MagickFalse)
4265 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4266 break;
4267 }
4268 if (LocaleCompare("despeckle",option+1) == 0)
4269 break;
4270 if (LocaleCompare("dft",option+1) == 0)
4271 break;
cristyc9b12952010-03-28 01:12:28 +00004272 if (LocaleCompare("direction",option+1) == 0)
4273 {
cristybb503372010-05-27 20:51:26 +00004274 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004275 direction;
4276
4277 if (*option == '+')
4278 break;
4279 i++;
cristybb503372010-05-27 20:51:26 +00004280 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004281 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004282 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004283 argv[i]);
4284 if (direction < 0)
4285 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4286 argv[i]);
4287 break;
4288 }
cristy3ed852e2009-09-05 21:47:34 +00004289 if (LocaleCompare("display",option+1) == 0)
4290 {
4291 if (*option == '+')
4292 break;
4293 i++;
cristybb503372010-05-27 20:51:26 +00004294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004295 ThrowMogrifyException(OptionError,"MissingArgument",option);
4296 break;
4297 }
4298 if (LocaleCompare("dispose",option+1) == 0)
4299 {
cristybb503372010-05-27 20:51:26 +00004300 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004301 dispose;
4302
4303 if (*option == '+')
4304 break;
4305 i++;
cristybb503372010-05-27 20:51:26 +00004306 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004307 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004308 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004309 if (dispose < 0)
4310 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4311 argv[i]);
4312 break;
4313 }
4314 if (LocaleCompare("distort",option+1) == 0)
4315 {
cristybb503372010-05-27 20:51:26 +00004316 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004317 op;
4318
4319 i++;
cristybb503372010-05-27 20:51:26 +00004320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004321 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004322 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004323 if (op < 0)
4324 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4325 argv[i]);
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
4329 break;
4330 }
4331 if (LocaleCompare("dither",option+1) == 0)
4332 {
cristybb503372010-05-27 20:51:26 +00004333 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004334 method;
4335
4336 if (*option == '+')
4337 break;
4338 i++;
cristybb503372010-05-27 20:51:26 +00004339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004340 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004341 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004342 if (method < 0)
4343 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4344 argv[i]);
4345 break;
4346 }
4347 if (LocaleCompare("draw",option+1) == 0)
4348 {
4349 if (*option == '+')
4350 break;
4351 i++;
cristybb503372010-05-27 20:51:26 +00004352 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004353 ThrowMogrifyException(OptionError,"MissingArgument",option);
4354 break;
4355 }
cristyecb10ff2011-03-22 13:14:03 +00004356 if (LocaleCompare("duplicate",option+1) == 0)
4357 {
4358 if (*option == '+')
4359 break;
4360 i++;
4361 if (i == (ssize_t) (argc-1))
4362 ThrowMogrifyException(OptionError,"MissingArgument",option);
4363 if (IsGeometry(argv[i]) == MagickFalse)
4364 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4365 break;
4366 }
cristy22879752009-10-25 23:55:40 +00004367 if (LocaleCompare("duration",option+1) == 0)
4368 {
4369 if (*option == '+')
4370 break;
4371 i++;
cristybb503372010-05-27 20:51:26 +00004372 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004373 ThrowMogrifyException(OptionError,"MissingArgument",option);
4374 if (IsGeometry(argv[i]) == MagickFalse)
4375 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4376 break;
4377 }
cristy3ed852e2009-09-05 21:47:34 +00004378 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4379 }
4380 case 'e':
4381 {
4382 if (LocaleCompare("edge",option+1) == 0)
4383 {
4384 if (*option == '+')
4385 break;
4386 i++;
cristybb503372010-05-27 20:51:26 +00004387 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004388 ThrowMogrifyException(OptionError,"MissingArgument",option);
4389 if (IsGeometry(argv[i]) == MagickFalse)
4390 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4391 break;
4392 }
4393 if (LocaleCompare("emboss",option+1) == 0)
4394 {
4395 if (*option == '+')
4396 break;
4397 i++;
cristybb503372010-05-27 20:51:26 +00004398 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004399 ThrowMogrifyException(OptionError,"MissingArgument",option);
4400 if (IsGeometry(argv[i]) == MagickFalse)
4401 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4402 break;
4403 }
4404 if (LocaleCompare("encipher",option+1) == 0)
4405 {
4406 if (*option == '+')
4407 break;
4408 i++;
cristybb503372010-05-27 20:51:26 +00004409 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004410 ThrowMogrifyException(OptionError,"MissingArgument",option);
4411 break;
4412 }
4413 if (LocaleCompare("encoding",option+1) == 0)
4414 {
4415 if (*option == '+')
4416 break;
4417 i++;
cristybb503372010-05-27 20:51:26 +00004418 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004419 ThrowMogrifyException(OptionError,"MissingArgument",option);
4420 break;
4421 }
4422 if (LocaleCompare("endian",option+1) == 0)
4423 {
cristybb503372010-05-27 20:51:26 +00004424 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004425 endian;
4426
4427 if (*option == '+')
4428 break;
4429 i++;
cristybb503372010-05-27 20:51:26 +00004430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004431 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004432 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004433 if (endian < 0)
4434 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4435 argv[i]);
4436 break;
4437 }
4438 if (LocaleCompare("enhance",option+1) == 0)
4439 break;
4440 if (LocaleCompare("equalize",option+1) == 0)
4441 break;
4442 if (LocaleCompare("evaluate",option+1) == 0)
4443 {
cristybb503372010-05-27 20:51:26 +00004444 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004445 op;
4446
4447 if (*option == '+')
4448 break;
4449 i++;
cristybb503372010-05-27 20:51:26 +00004450 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004451 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004452 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004453 if (op < 0)
4454 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4455 argv[i]);
4456 i++;
cristybb503372010-05-27 20:51:26 +00004457 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004458 ThrowMogrifyException(OptionError,"MissingArgument",option);
4459 if (IsGeometry(argv[i]) == MagickFalse)
4460 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4461 break;
4462 }
cristyd18ae7c2010-03-07 17:39:52 +00004463 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4464 {
cristybb503372010-05-27 20:51:26 +00004465 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004466 op;
4467
4468 if (*option == '+')
4469 break;
4470 i++;
cristybb503372010-05-27 20:51:26 +00004471 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004472 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004473 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004474 if (op < 0)
4475 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4476 argv[i]);
4477 break;
4478 }
cristy3ed852e2009-09-05 21:47:34 +00004479 if (LocaleCompare("extent",option+1) == 0)
4480 {
4481 if (*option == '+')
4482 break;
4483 i++;
cristybb503372010-05-27 20:51:26 +00004484 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004485 ThrowMogrifyException(OptionError,"MissingArgument",option);
4486 if (IsGeometry(argv[i]) == MagickFalse)
4487 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4488 break;
4489 }
4490 if (LocaleCompare("extract",option+1) == 0)
4491 {
4492 if (*option == '+')
4493 break;
4494 i++;
cristybb503372010-05-27 20:51:26 +00004495 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004496 ThrowMogrifyException(OptionError,"MissingArgument",option);
4497 if (IsGeometry(argv[i]) == MagickFalse)
4498 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4499 break;
4500 }
4501 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4502 }
4503 case 'f':
4504 {
4505 if (LocaleCompare("family",option+1) == 0)
4506 {
4507 if (*option == '+')
4508 break;
4509 i++;
cristybb503372010-05-27 20:51:26 +00004510 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004511 ThrowMogrifyException(OptionError,"MissingArgument",option);
4512 break;
4513 }
4514 if (LocaleCompare("fill",option+1) == 0)
4515 {
4516 if (*option == '+')
4517 break;
4518 i++;
cristybb503372010-05-27 20:51:26 +00004519 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004520 ThrowMogrifyException(OptionError,"MissingArgument",option);
4521 break;
4522 }
4523 if (LocaleCompare("filter",option+1) == 0)
4524 {
cristybb503372010-05-27 20:51:26 +00004525 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004526 filter;
4527
4528 if (*option == '+')
4529 break;
4530 i++;
cristybb503372010-05-27 20:51:26 +00004531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004532 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004533 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004534 if (filter < 0)
4535 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4536 argv[i]);
4537 break;
4538 }
4539 if (LocaleCompare("flatten",option+1) == 0)
4540 break;
4541 if (LocaleCompare("flip",option+1) == 0)
4542 break;
4543 if (LocaleCompare("flop",option+1) == 0)
4544 break;
4545 if (LocaleCompare("floodfill",option+1) == 0)
4546 {
4547 if (*option == '+')
4548 break;
4549 i++;
cristybb503372010-05-27 20:51:26 +00004550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004551 ThrowMogrifyException(OptionError,"MissingArgument",option);
4552 if (IsGeometry(argv[i]) == MagickFalse)
4553 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4554 i++;
cristybb503372010-05-27 20:51:26 +00004555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004556 ThrowMogrifyException(OptionError,"MissingArgument",option);
4557 break;
4558 }
4559 if (LocaleCompare("font",option+1) == 0)
4560 {
4561 if (*option == '+')
4562 break;
4563 i++;
cristybb503372010-05-27 20:51:26 +00004564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004565 ThrowMogrifyException(OptionError,"MissingArgument",option);
4566 break;
4567 }
4568 if (LocaleCompare("format",option+1) == 0)
4569 {
4570 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4571 (void) CloneString(&format,(char *) NULL);
4572 if (*option == '+')
4573 break;
4574 i++;
cristybb503372010-05-27 20:51:26 +00004575 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004576 ThrowMogrifyException(OptionError,"MissingArgument",option);
4577 (void) CloneString(&format,argv[i]);
4578 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4579 (void) ConcatenateMagickString(image_info->filename,":",
4580 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004581 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004582 if (*image_info->magick == '\0')
4583 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4584 format);
4585 break;
4586 }
4587 if (LocaleCompare("frame",option+1) == 0)
4588 {
4589 if (*option == '+')
4590 break;
4591 i++;
cristybb503372010-05-27 20:51:26 +00004592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004593 ThrowMogrifyException(OptionError,"MissingArgument",option);
4594 if (IsGeometry(argv[i]) == MagickFalse)
4595 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4596 break;
4597 }
4598 if (LocaleCompare("function",option+1) == 0)
4599 {
cristybb503372010-05-27 20:51:26 +00004600 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004601 op;
4602
4603 if (*option == '+')
4604 break;
4605 i++;
cristybb503372010-05-27 20:51:26 +00004606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004607 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004608 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004609 if (op < 0)
4610 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4611 i++;
cristybb503372010-05-27 20:51:26 +00004612 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004613 ThrowMogrifyException(OptionError,"MissingArgument",option);
4614 break;
4615 }
4616 if (LocaleCompare("fuzz",option+1) == 0)
4617 {
4618 if (*option == '+')
4619 break;
4620 i++;
cristybb503372010-05-27 20:51:26 +00004621 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004622 ThrowMogrifyException(OptionError,"MissingArgument",option);
4623 if (IsGeometry(argv[i]) == MagickFalse)
4624 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4625 break;
4626 }
4627 if (LocaleCompare("fx",option+1) == 0)
4628 {
4629 if (*option == '+')
4630 break;
4631 i++;
cristybb503372010-05-27 20:51:26 +00004632 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004633 ThrowMogrifyException(OptionError,"MissingArgument",option);
4634 break;
4635 }
4636 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4637 }
4638 case 'g':
4639 {
4640 if (LocaleCompare("gamma",option+1) == 0)
4641 {
4642 i++;
cristybb503372010-05-27 20:51:26 +00004643 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004644 ThrowMogrifyException(OptionError,"MissingArgument",option);
4645 if (IsGeometry(argv[i]) == MagickFalse)
4646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4647 break;
4648 }
4649 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4650 (LocaleCompare("gaussian",option+1) == 0))
4651 {
4652 i++;
cristybb503372010-05-27 20:51:26 +00004653 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004654 ThrowMogrifyException(OptionError,"MissingArgument",option);
4655 if (IsGeometry(argv[i]) == MagickFalse)
4656 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4657 break;
4658 }
4659 if (LocaleCompare("geometry",option+1) == 0)
4660 {
4661 if (*option == '+')
4662 break;
4663 i++;
cristybb503372010-05-27 20:51:26 +00004664 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004665 ThrowMogrifyException(OptionError,"MissingArgument",option);
4666 if (IsGeometry(argv[i]) == MagickFalse)
4667 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4668 break;
4669 }
4670 if (LocaleCompare("gravity",option+1) == 0)
4671 {
cristybb503372010-05-27 20:51:26 +00004672 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004673 gravity;
4674
4675 if (*option == '+')
4676 break;
4677 i++;
cristybb503372010-05-27 20:51:26 +00004678 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004679 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004680 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004681 if (gravity < 0)
4682 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4683 argv[i]);
4684 break;
4685 }
4686 if (LocaleCompare("green-primary",option+1) == 0)
4687 {
4688 if (*option == '+')
4689 break;
4690 i++;
cristybb503372010-05-27 20:51:26 +00004691 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004692 ThrowMogrifyException(OptionError,"MissingArgument",option);
4693 if (IsGeometry(argv[i]) == MagickFalse)
4694 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4695 break;
4696 }
4697 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4698 }
4699 case 'h':
4700 {
4701 if (LocaleCompare("hald-clut",option+1) == 0)
4702 break;
4703 if ((LocaleCompare("help",option+1) == 0) ||
4704 (LocaleCompare("-help",option+1) == 0))
4705 return(MogrifyUsage());
4706 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4707 }
4708 case 'i':
4709 {
4710 if (LocaleCompare("identify",option+1) == 0)
4711 break;
4712 if (LocaleCompare("idft",option+1) == 0)
4713 break;
4714 if (LocaleCompare("implode",option+1) == 0)
4715 {
4716 if (*option == '+')
4717 break;
4718 i++;
cristybb503372010-05-27 20:51:26 +00004719 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004720 ThrowMogrifyException(OptionError,"MissingArgument",option);
4721 if (IsGeometry(argv[i]) == MagickFalse)
4722 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4723 break;
4724 }
4725 if (LocaleCompare("intent",option+1) == 0)
4726 {
cristybb503372010-05-27 20:51:26 +00004727 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004728 intent;
4729
4730 if (*option == '+')
4731 break;
4732 i++;
cristybb503372010-05-27 20:51:26 +00004733 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004734 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004735 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004736 if (intent < 0)
4737 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4738 argv[i]);
4739 break;
4740 }
4741 if (LocaleCompare("interlace",option+1) == 0)
4742 {
cristybb503372010-05-27 20:51:26 +00004743 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004744 interlace;
4745
4746 if (*option == '+')
4747 break;
4748 i++;
cristybb503372010-05-27 20:51:26 +00004749 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004750 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004751 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004752 argv[i]);
4753 if (interlace < 0)
4754 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4755 argv[i]);
4756 break;
4757 }
cristyb32b90a2009-09-07 21:45:48 +00004758 if (LocaleCompare("interline-spacing",option+1) == 0)
4759 {
4760 if (*option == '+')
4761 break;
4762 i++;
cristybb503372010-05-27 20:51:26 +00004763 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004764 ThrowMogrifyException(OptionError,"MissingArgument",option);
4765 if (IsGeometry(argv[i]) == MagickFalse)
4766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4767 break;
4768 }
cristy3ed852e2009-09-05 21:47:34 +00004769 if (LocaleCompare("interpolate",option+1) == 0)
4770 {
cristybb503372010-05-27 20:51:26 +00004771 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004772 interpolate;
4773
4774 if (*option == '+')
4775 break;
4776 i++;
cristybb503372010-05-27 20:51:26 +00004777 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004778 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004779 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004780 argv[i]);
4781 if (interpolate < 0)
4782 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4783 argv[i]);
4784 break;
4785 }
4786 if (LocaleCompare("interword-spacing",option+1) == 0)
4787 {
4788 if (*option == '+')
4789 break;
4790 i++;
cristybb503372010-05-27 20:51:26 +00004791 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004792 ThrowMogrifyException(OptionError,"MissingArgument",option);
4793 if (IsGeometry(argv[i]) == MagickFalse)
4794 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4795 break;
4796 }
4797 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4798 }
4799 case 'k':
4800 {
4801 if (LocaleCompare("kerning",option+1) == 0)
4802 {
4803 if (*option == '+')
4804 break;
4805 i++;
cristybb503372010-05-27 20:51:26 +00004806 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004807 ThrowMogrifyException(OptionError,"MissingArgument",option);
4808 if (IsGeometry(argv[i]) == MagickFalse)
4809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4810 break;
4811 }
4812 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4813 }
4814 case 'l':
4815 {
4816 if (LocaleCompare("label",option+1) == 0)
4817 {
4818 if (*option == '+')
4819 break;
4820 i++;
cristybb503372010-05-27 20:51:26 +00004821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004822 ThrowMogrifyException(OptionError,"MissingArgument",option);
4823 break;
4824 }
4825 if (LocaleCompare("lat",option+1) == 0)
4826 {
4827 if (*option == '+')
4828 break;
4829 i++;
cristybb503372010-05-27 20:51:26 +00004830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004831 ThrowMogrifyException(OptionError,"MissingArgument",option);
4832 if (IsGeometry(argv[i]) == MagickFalse)
4833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4834 }
4835 if (LocaleCompare("layers",option+1) == 0)
4836 {
cristybb503372010-05-27 20:51:26 +00004837 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004838 type;
4839
4840 if (*option == '+')
4841 break;
4842 i++;
cristybb503372010-05-27 20:51:26 +00004843 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004844 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004845 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004846 if (type < 0)
4847 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4848 argv[i]);
4849 break;
4850 }
4851 if (LocaleCompare("level",option+1) == 0)
4852 {
4853 i++;
cristybb503372010-05-27 20:51:26 +00004854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004855 ThrowMogrifyException(OptionError,"MissingArgument",option);
4856 if (IsGeometry(argv[i]) == MagickFalse)
4857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4858 break;
4859 }
4860 if (LocaleCompare("level-colors",option+1) == 0)
4861 {
4862 i++;
cristybb503372010-05-27 20:51:26 +00004863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004864 ThrowMogrifyException(OptionError,"MissingArgument",option);
4865 break;
4866 }
4867 if (LocaleCompare("linewidth",option+1) == 0)
4868 {
4869 if (*option == '+')
4870 break;
4871 i++;
cristybb503372010-05-27 20:51:26 +00004872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004873 ThrowMogrifyException(OptionError,"MissingArgument",option);
4874 if (IsGeometry(argv[i]) == MagickFalse)
4875 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4876 break;
4877 }
4878 if (LocaleCompare("limit",option+1) == 0)
4879 {
4880 char
4881 *p;
4882
4883 double
4884 value;
4885
cristybb503372010-05-27 20:51:26 +00004886 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004887 resource;
4888
4889 if (*option == '+')
4890 break;
4891 i++;
cristybb503372010-05-27 20:51:26 +00004892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004893 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004894 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004895 argv[i]);
4896 if (resource < 0)
4897 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4898 argv[i]);
4899 i++;
cristybb503372010-05-27 20:51:26 +00004900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004901 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004902 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004903 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004904 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4906 break;
4907 }
4908 if (LocaleCompare("liquid-rescale",option+1) == 0)
4909 {
4910 i++;
cristybb503372010-05-27 20:51:26 +00004911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004912 ThrowMogrifyException(OptionError,"MissingArgument",option);
4913 if (IsGeometry(argv[i]) == MagickFalse)
4914 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4915 break;
4916 }
4917 if (LocaleCompare("list",option+1) == 0)
4918 {
cristybb503372010-05-27 20:51:26 +00004919 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004920 list;
4921
4922 if (*option == '+')
4923 break;
4924 i++;
cristybb503372010-05-27 20:51:26 +00004925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004926 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004927 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004928 if (list < 0)
4929 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004930 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004931 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004932 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004933 }
4934 if (LocaleCompare("log",option+1) == 0)
4935 {
4936 if (*option == '+')
4937 break;
4938 i++;
cristybb503372010-05-27 20:51:26 +00004939 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004940 (strchr(argv[i],'%') == (char *) NULL))
4941 ThrowMogrifyException(OptionError,"MissingArgument",option);
4942 break;
4943 }
4944 if (LocaleCompare("loop",option+1) == 0)
4945 {
4946 if (*option == '+')
4947 break;
4948 i++;
cristybb503372010-05-27 20:51:26 +00004949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004950 ThrowMogrifyException(OptionError,"MissingArgument",option);
4951 if (IsGeometry(argv[i]) == MagickFalse)
4952 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4953 break;
4954 }
4955 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4956 }
4957 case 'm':
4958 {
4959 if (LocaleCompare("map",option+1) == 0)
4960 {
4961 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4962 if (*option == '+')
4963 break;
4964 i++;
cristybb503372010-05-27 20:51:26 +00004965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004966 ThrowMogrifyException(OptionError,"MissingArgument",option);
4967 break;
4968 }
4969 if (LocaleCompare("mask",option+1) == 0)
4970 {
4971 if (*option == '+')
4972 break;
4973 i++;
cristybb503372010-05-27 20:51:26 +00004974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004975 ThrowMogrifyException(OptionError,"MissingArgument",option);
4976 break;
4977 }
4978 if (LocaleCompare("matte",option+1) == 0)
4979 break;
4980 if (LocaleCompare("mattecolor",option+1) == 0)
4981 {
4982 if (*option == '+')
4983 break;
4984 i++;
cristybb503372010-05-27 20:51:26 +00004985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004986 ThrowMogrifyException(OptionError,"MissingArgument",option);
4987 break;
4988 }
cristyf40785b2010-03-06 02:27:27 +00004989 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004990 break;
cristyf40785b2010-03-06 02:27:27 +00004991 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004992 break;
cristy3ed852e2009-09-05 21:47:34 +00004993 if (LocaleCompare("modulate",option+1) == 0)
4994 {
4995 if (*option == '+')
4996 break;
4997 i++;
cristybb503372010-05-27 20:51:26 +00004998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004999 ThrowMogrifyException(OptionError,"MissingArgument",option);
5000 if (IsGeometry(argv[i]) == MagickFalse)
5001 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5002 break;
5003 }
5004 if (LocaleCompare("median",option+1) == 0)
5005 {
5006 if (*option == '+')
5007 break;
5008 i++;
cristybb503372010-05-27 20:51:26 +00005009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005010 ThrowMogrifyException(OptionError,"MissingArgument",option);
5011 if (IsGeometry(argv[i]) == MagickFalse)
5012 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5013 break;
5014 }
cristy69ec32d2011-02-27 23:57:09 +00005015 if (LocaleCompare("mode",option+1) == 0)
5016 {
5017 if (*option == '+')
5018 break;
5019 i++;
5020 if (i == (ssize_t) argc)
5021 ThrowMogrifyException(OptionError,"MissingArgument",option);
5022 if (IsGeometry(argv[i]) == MagickFalse)
5023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5024 break;
5025 }
cristy3ed852e2009-09-05 21:47:34 +00005026 if (LocaleCompare("monitor",option+1) == 0)
5027 break;
5028 if (LocaleCompare("monochrome",option+1) == 0)
5029 break;
5030 if (LocaleCompare("morph",option+1) == 0)
5031 {
5032 if (*option == '+')
5033 break;
5034 i++;
cristybb503372010-05-27 20:51:26 +00005035 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005036 ThrowMogrifyException(OptionError,"MissingArgument",option);
5037 if (IsGeometry(argv[i]) == MagickFalse)
5038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5039 break;
5040 }
anthony29188a82010-01-22 10:12:34 +00005041 if (LocaleCompare("morphology",option+1) == 0)
5042 {
anthony29188a82010-01-22 10:12:34 +00005043 char
5044 token[MaxTextExtent];
5045
cristyb6bd4ad2010-08-08 01:12:27 +00005046 KernelInfo
5047 *kernel_info;
5048
5049 ssize_t
5050 op;
5051
anthony29188a82010-01-22 10:12:34 +00005052 i++;
cristybb503372010-05-27 20:51:26 +00005053 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005054 ThrowMogrifyException(OptionError,"MissingArgument",option);
5055 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005056 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005057 if (op < 0)
5058 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005059 token);
anthony29188a82010-01-22 10:12:34 +00005060 i++;
cristybb503372010-05-27 20:51:26 +00005061 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005062 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005063 kernel_info=AcquireKernelInfo(argv[i]);
5064 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005065 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005066 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005067 break;
5068 }
cristy3ed852e2009-09-05 21:47:34 +00005069 if (LocaleCompare("mosaic",option+1) == 0)
5070 break;
5071 if (LocaleCompare("motion-blur",option+1) == 0)
5072 {
5073 if (*option == '+')
5074 break;
5075 i++;
cristybb503372010-05-27 20:51:26 +00005076 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005077 ThrowMogrifyException(OptionError,"MissingArgument",option);
5078 if (IsGeometry(argv[i]) == MagickFalse)
5079 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5080 break;
5081 }
5082 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5083 }
5084 case 'n':
5085 {
5086 if (LocaleCompare("negate",option+1) == 0)
5087 break;
5088 if (LocaleCompare("noise",option+1) == 0)
5089 {
5090 i++;
cristybb503372010-05-27 20:51:26 +00005091 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005092 ThrowMogrifyException(OptionError,"MissingArgument",option);
5093 if (*option == '+')
5094 {
cristybb503372010-05-27 20:51:26 +00005095 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005096 noise;
5097
cristy042ee782011-04-22 18:48:30 +00005098 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005099 if (noise < 0)
5100 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5101 argv[i]);
5102 break;
5103 }
5104 if (IsGeometry(argv[i]) == MagickFalse)
5105 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5106 break;
5107 }
5108 if (LocaleCompare("noop",option+1) == 0)
5109 break;
5110 if (LocaleCompare("normalize",option+1) == 0)
5111 break;
5112 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5113 }
5114 case 'o':
5115 {
5116 if (LocaleCompare("opaque",option+1) == 0)
5117 {
cristy3ed852e2009-09-05 21:47:34 +00005118 i++;
cristybb503372010-05-27 20:51:26 +00005119 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005120 ThrowMogrifyException(OptionError,"MissingArgument",option);
5121 break;
5122 }
5123 if (LocaleCompare("ordered-dither",option+1) == 0)
5124 {
5125 if (*option == '+')
5126 break;
5127 i++;
cristybb503372010-05-27 20:51:26 +00005128 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005129 ThrowMogrifyException(OptionError,"MissingArgument",option);
5130 break;
5131 }
5132 if (LocaleCompare("orient",option+1) == 0)
5133 {
cristybb503372010-05-27 20:51:26 +00005134 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005135 orientation;
5136
5137 orientation=UndefinedOrientation;
5138 if (*option == '+')
5139 break;
5140 i++;
cristybb503372010-05-27 20:51:26 +00005141 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005142 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005143 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005144 argv[i]);
5145 if (orientation < 0)
5146 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5147 argv[i]);
5148 break;
5149 }
5150 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5151 }
5152 case 'p':
5153 {
5154 if (LocaleCompare("page",option+1) == 0)
5155 {
5156 if (*option == '+')
5157 break;
5158 i++;
cristybb503372010-05-27 20:51:26 +00005159 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005160 ThrowMogrifyException(OptionError,"MissingArgument",option);
5161 break;
5162 }
5163 if (LocaleCompare("paint",option+1) == 0)
5164 {
5165 if (*option == '+')
5166 break;
5167 i++;
cristybb503372010-05-27 20:51:26 +00005168 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005169 ThrowMogrifyException(OptionError,"MissingArgument",option);
5170 if (IsGeometry(argv[i]) == MagickFalse)
5171 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5172 break;
5173 }
5174 if (LocaleCompare("path",option+1) == 0)
5175 {
5176 (void) CloneString(&path,(char *) NULL);
5177 if (*option == '+')
5178 break;
5179 i++;
cristybb503372010-05-27 20:51:26 +00005180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005181 ThrowMogrifyException(OptionError,"MissingArgument",option);
5182 (void) CloneString(&path,argv[i]);
5183 break;
5184 }
5185 if (LocaleCompare("pointsize",option+1) == 0)
5186 {
5187 if (*option == '+')
5188 break;
5189 i++;
cristybb503372010-05-27 20:51:26 +00005190 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005191 ThrowMogrifyException(OptionError,"MissingArgument",option);
5192 if (IsGeometry(argv[i]) == MagickFalse)
5193 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5194 break;
5195 }
5196 if (LocaleCompare("polaroid",option+1) == 0)
5197 {
5198 if (*option == '+')
5199 break;
5200 i++;
cristybb503372010-05-27 20:51:26 +00005201 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005202 ThrowMogrifyException(OptionError,"MissingArgument",option);
5203 if (IsGeometry(argv[i]) == MagickFalse)
5204 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5205 break;
5206 }
5207 if (LocaleCompare("posterize",option+1) == 0)
5208 {
5209 if (*option == '+')
5210 break;
5211 i++;
cristybb503372010-05-27 20:51:26 +00005212 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005213 ThrowMogrifyException(OptionError,"MissingArgument",option);
5214 if (IsGeometry(argv[i]) == MagickFalse)
5215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5216 break;
5217 }
cristye7f51092010-01-17 00:39:37 +00005218 if (LocaleCompare("precision",option+1) == 0)
5219 {
5220 if (*option == '+')
5221 break;
5222 i++;
cristybb503372010-05-27 20:51:26 +00005223 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005224 ThrowMogrifyException(OptionError,"MissingArgument",option);
5225 if (IsGeometry(argv[i]) == MagickFalse)
5226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5227 break;
5228 }
cristy3ed852e2009-09-05 21:47:34 +00005229 if (LocaleCompare("print",option+1) == 0)
5230 {
5231 if (*option == '+')
5232 break;
5233 i++;
cristybb503372010-05-27 20:51:26 +00005234 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005235 ThrowMogrifyException(OptionError,"MissingArgument",option);
5236 break;
5237 }
5238 if (LocaleCompare("process",option+1) == 0)
5239 {
5240 if (*option == '+')
5241 break;
5242 i++;
cristybb503372010-05-27 20:51:26 +00005243 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005244 ThrowMogrifyException(OptionError,"MissingArgument",option);
5245 break;
5246 }
5247 if (LocaleCompare("profile",option+1) == 0)
5248 {
5249 i++;
cristybb503372010-05-27 20:51:26 +00005250 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005251 ThrowMogrifyException(OptionError,"MissingArgument",option);
5252 break;
5253 }
5254 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5255 }
5256 case 'q':
5257 {
5258 if (LocaleCompare("quality",option+1) == 0)
5259 {
5260 if (*option == '+')
5261 break;
5262 i++;
cristybb503372010-05-27 20:51:26 +00005263 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005264 ThrowMogrifyException(OptionError,"MissingArgument",option);
5265 if (IsGeometry(argv[i]) == MagickFalse)
5266 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5267 break;
5268 }
5269 if (LocaleCompare("quantize",option+1) == 0)
5270 {
cristybb503372010-05-27 20:51:26 +00005271 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005272 colorspace;
5273
5274 if (*option == '+')
5275 break;
5276 i++;
cristybb503372010-05-27 20:51:26 +00005277 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005278 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005279 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005280 argv[i]);
5281 if (colorspace < 0)
5282 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5283 argv[i]);
5284 break;
5285 }
5286 if (LocaleCompare("quiet",option+1) == 0)
5287 break;
5288 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5289 }
5290 case 'r':
5291 {
5292 if (LocaleCompare("radial-blur",option+1) == 0)
5293 {
5294 i++;
cristybb503372010-05-27 20:51:26 +00005295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005296 ThrowMogrifyException(OptionError,"MissingArgument",option);
5297 if (IsGeometry(argv[i]) == MagickFalse)
5298 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5299 break;
5300 }
5301 if (LocaleCompare("raise",option+1) == 0)
5302 {
5303 i++;
cristybb503372010-05-27 20:51:26 +00005304 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005305 ThrowMogrifyException(OptionError,"MissingArgument",option);
5306 if (IsGeometry(argv[i]) == MagickFalse)
5307 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5308 break;
5309 }
5310 if (LocaleCompare("random-threshold",option+1) == 0)
5311 {
5312 if (*option == '+')
5313 break;
5314 i++;
cristybb503372010-05-27 20:51:26 +00005315 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005316 ThrowMogrifyException(OptionError,"MissingArgument",option);
5317 if (IsGeometry(argv[i]) == MagickFalse)
5318 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5319 break;
5320 }
cristye6365592010-04-02 17:31:23 +00005321 if (LocaleCompare("recolor",option+1) == 0)
5322 {
5323 if (*option == '+')
5324 break;
5325 i++;
cristybb503372010-05-27 20:51:26 +00005326 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005327 ThrowMogrifyException(OptionError,"MissingArgument",option);
5328 if (IsGeometry(argv[i]) == MagickFalse)
5329 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5330 break;
5331 }
cristy3ed852e2009-09-05 21:47:34 +00005332 if (LocaleCompare("red-primary",option+1) == 0)
5333 {
5334 if (*option == '+')
5335 break;
5336 i++;
cristybb503372010-05-27 20:51:26 +00005337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005338 ThrowMogrifyException(OptionError,"MissingArgument",option);
5339 if (IsGeometry(argv[i]) == MagickFalse)
5340 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5341 }
cristy9f2083a2010-04-22 19:48:05 +00005342 if (LocaleCompare("regard-warnings",option+1) == 0)
5343 break;
cristy3ed852e2009-09-05 21:47:34 +00005344 if (LocaleCompare("region",option+1) == 0)
5345 {
5346 if (*option == '+')
5347 break;
5348 i++;
cristybb503372010-05-27 20:51:26 +00005349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005350 ThrowMogrifyException(OptionError,"MissingArgument",option);
5351 if (IsGeometry(argv[i]) == MagickFalse)
5352 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5353 break;
5354 }
cristyf0c78232010-03-15 12:53:40 +00005355 if (LocaleCompare("remap",option+1) == 0)
5356 {
5357 if (*option == '+')
5358 break;
5359 i++;
cristybb503372010-05-27 20:51:26 +00005360 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005361 ThrowMogrifyException(OptionError,"MissingArgument",option);
5362 break;
5363 }
cristy3ed852e2009-09-05 21:47:34 +00005364 if (LocaleCompare("render",option+1) == 0)
5365 break;
5366 if (LocaleCompare("repage",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
cristybb503372010-05-27 20:51:26 +00005371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 break;
5376 }
5377 if (LocaleCompare("resample",option+1) == 0)
5378 {
5379 if (*option == '+')
5380 break;
5381 i++;
cristybb503372010-05-27 20:51:26 +00005382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005383 ThrowMogrifyException(OptionError,"MissingArgument",option);
5384 if (IsGeometry(argv[i]) == MagickFalse)
5385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5386 break;
5387 }
5388 if (LocaleCompare("resize",option+1) == 0)
5389 {
5390 if (*option == '+')
5391 break;
5392 i++;
cristybb503372010-05-27 20:51:26 +00005393 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005394 ThrowMogrifyException(OptionError,"MissingArgument",option);
5395 if (IsGeometry(argv[i]) == MagickFalse)
5396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5397 break;
5398 }
cristyebbcfea2011-02-25 02:43:54 +00005399 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5400 {
5401 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5402 break;
5403 }
cristy3ed852e2009-09-05 21:47:34 +00005404 if (LocaleCompare("reverse",option+1) == 0)
5405 break;
5406 if (LocaleCompare("roll",option+1) == 0)
5407 {
5408 if (*option == '+')
5409 break;
5410 i++;
cristybb503372010-05-27 20:51:26 +00005411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005412 ThrowMogrifyException(OptionError,"MissingArgument",option);
5413 if (IsGeometry(argv[i]) == MagickFalse)
5414 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5415 break;
5416 }
5417 if (LocaleCompare("rotate",option+1) == 0)
5418 {
5419 i++;
cristybb503372010-05-27 20:51:26 +00005420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005421 ThrowMogrifyException(OptionError,"MissingArgument",option);
5422 if (IsGeometry(argv[i]) == MagickFalse)
5423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5424 break;
5425 }
5426 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5427 }
5428 case 's':
5429 {
5430 if (LocaleCompare("sample",option+1) == 0)
5431 {
5432 if (*option == '+')
5433 break;
5434 i++;
cristybb503372010-05-27 20:51:26 +00005435 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005436 ThrowMogrifyException(OptionError,"MissingArgument",option);
5437 if (IsGeometry(argv[i]) == MagickFalse)
5438 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5439 break;
5440 }
5441 if (LocaleCompare("sampling-factor",option+1) == 0)
5442 {
5443 if (*option == '+')
5444 break;
5445 i++;
cristybb503372010-05-27 20:51:26 +00005446 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005447 ThrowMogrifyException(OptionError,"MissingArgument",option);
5448 if (IsGeometry(argv[i]) == MagickFalse)
5449 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5450 break;
5451 }
5452 if (LocaleCompare("scale",option+1) == 0)
5453 {
5454 if (*option == '+')
5455 break;
5456 i++;
cristybb503372010-05-27 20:51:26 +00005457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005458 ThrowMogrifyException(OptionError,"MissingArgument",option);
5459 if (IsGeometry(argv[i]) == MagickFalse)
5460 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5461 break;
5462 }
5463 if (LocaleCompare("scene",option+1) == 0)
5464 {
5465 if (*option == '+')
5466 break;
5467 i++;
cristybb503372010-05-27 20:51:26 +00005468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005469 ThrowMogrifyException(OptionError,"MissingArgument",option);
5470 if (IsGeometry(argv[i]) == MagickFalse)
5471 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5472 break;
5473 }
5474 if (LocaleCompare("seed",option+1) == 0)
5475 {
5476 if (*option == '+')
5477 break;
5478 i++;
cristybb503372010-05-27 20:51:26 +00005479 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005480 ThrowMogrifyException(OptionError,"MissingArgument",option);
5481 if (IsGeometry(argv[i]) == MagickFalse)
5482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5483 break;
5484 }
5485 if (LocaleCompare("segment",option+1) == 0)
5486 {
5487 if (*option == '+')
5488 break;
5489 i++;
cristybb503372010-05-27 20:51:26 +00005490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005491 ThrowMogrifyException(OptionError,"MissingArgument",option);
5492 if (IsGeometry(argv[i]) == MagickFalse)
5493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5494 break;
5495 }
5496 if (LocaleCompare("selective-blur",option+1) == 0)
5497 {
5498 i++;
cristybb503372010-05-27 20:51:26 +00005499 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005500 ThrowMogrifyException(OptionError,"MissingArgument",option);
5501 if (IsGeometry(argv[i]) == MagickFalse)
5502 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5503 break;
5504 }
5505 if (LocaleCompare("separate",option+1) == 0)
5506 break;
5507 if (LocaleCompare("sepia-tone",option+1) == 0)
5508 {
5509 if (*option == '+')
5510 break;
5511 i++;
cristybb503372010-05-27 20:51:26 +00005512 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005513 ThrowMogrifyException(OptionError,"MissingArgument",option);
5514 if (IsGeometry(argv[i]) == MagickFalse)
5515 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5516 break;
5517 }
5518 if (LocaleCompare("set",option+1) == 0)
5519 {
5520 i++;
cristybb503372010-05-27 20:51:26 +00005521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005522 ThrowMogrifyException(OptionError,"MissingArgument",option);
5523 if (*option == '+')
5524 break;
5525 i++;
cristybb503372010-05-27 20:51:26 +00005526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005527 ThrowMogrifyException(OptionError,"MissingArgument",option);
5528 break;
5529 }
5530 if (LocaleCompare("shade",option+1) == 0)
5531 {
5532 i++;
cristybb503372010-05-27 20:51:26 +00005533 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005534 ThrowMogrifyException(OptionError,"MissingArgument",option);
5535 if (IsGeometry(argv[i]) == MagickFalse)
5536 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5537 break;
5538 }
5539 if (LocaleCompare("shadow",option+1) == 0)
5540 {
5541 if (*option == '+')
5542 break;
5543 i++;
cristybb503372010-05-27 20:51:26 +00005544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005545 ThrowMogrifyException(OptionError,"MissingArgument",option);
5546 if (IsGeometry(argv[i]) == MagickFalse)
5547 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5548 break;
5549 }
5550 if (LocaleCompare("sharpen",option+1) == 0)
5551 {
5552 i++;
cristybb503372010-05-27 20:51:26 +00005553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005554 ThrowMogrifyException(OptionError,"MissingArgument",option);
5555 if (IsGeometry(argv[i]) == MagickFalse)
5556 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5557 break;
5558 }
5559 if (LocaleCompare("shave",option+1) == 0)
5560 {
5561 if (*option == '+')
5562 break;
5563 i++;
cristybb503372010-05-27 20:51:26 +00005564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005565 ThrowMogrifyException(OptionError,"MissingArgument",option);
5566 if (IsGeometry(argv[i]) == MagickFalse)
5567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5568 break;
5569 }
5570 if (LocaleCompare("shear",option+1) == 0)
5571 {
5572 i++;
cristybb503372010-05-27 20:51:26 +00005573 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005574 ThrowMogrifyException(OptionError,"MissingArgument",option);
5575 if (IsGeometry(argv[i]) == MagickFalse)
5576 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5577 break;
5578 }
5579 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5580 {
5581 i++;
cristybb503372010-05-27 20:51:26 +00005582 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005583 ThrowMogrifyException(OptionError,"MissingArgument",option);
5584 if (IsGeometry(argv[i]) == MagickFalse)
5585 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5586 break;
5587 }
5588 if (LocaleCompare("size",option+1) == 0)
5589 {
5590 if (*option == '+')
5591 break;
5592 i++;
cristybb503372010-05-27 20:51:26 +00005593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005594 ThrowMogrifyException(OptionError,"MissingArgument",option);
5595 if (IsGeometry(argv[i]) == MagickFalse)
5596 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5597 break;
5598 }
5599 if (LocaleCompare("sketch",option+1) == 0)
5600 {
5601 if (*option == '+')
5602 break;
5603 i++;
cristybb503372010-05-27 20:51:26 +00005604 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005605 ThrowMogrifyException(OptionError,"MissingArgument",option);
5606 if (IsGeometry(argv[i]) == MagickFalse)
5607 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5608 break;
5609 }
cristy4285d782011-02-09 20:12:28 +00005610 if (LocaleCompare("smush",option+1) == 0)
5611 {
cristy4285d782011-02-09 20:12:28 +00005612 i++;
5613 if (i == (ssize_t) argc)
5614 ThrowMogrifyException(OptionError,"MissingArgument",option);
5615 if (IsGeometry(argv[i]) == MagickFalse)
5616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005617 i++;
5618 break;
5619 }
cristy3ed852e2009-09-05 21:47:34 +00005620 if (LocaleCompare("solarize",option+1) == 0)
5621 {
5622 if (*option == '+')
5623 break;
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 if (IsGeometry(argv[i]) == MagickFalse)
5628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5629 break;
5630 }
5631 if (LocaleCompare("sparse-color",option+1) == 0)
5632 {
cristybb503372010-05-27 20:51:26 +00005633 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005634 op;
5635
5636 i++;
cristybb503372010-05-27 20:51:26 +00005637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005638 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005639 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005640 if (op < 0)
5641 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5642 argv[i]);
5643 i++;
cristybb503372010-05-27 20:51:26 +00005644 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005645 ThrowMogrifyException(OptionError,"MissingArgument",option);
5646 break;
5647 }
5648 if (LocaleCompare("spread",option+1) == 0)
5649 {
5650 if (*option == '+')
5651 break;
5652 i++;
cristybb503372010-05-27 20:51:26 +00005653 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005654 ThrowMogrifyException(OptionError,"MissingArgument",option);
5655 if (IsGeometry(argv[i]) == MagickFalse)
5656 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5657 break;
5658 }
cristy0834d642011-03-18 18:26:08 +00005659 if (LocaleCompare("statistic",option+1) == 0)
5660 {
5661 ssize_t
5662 op;
5663
5664 if (*option == '+')
5665 break;
5666 i++;
5667 if (i == (ssize_t) argc)
5668 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005669 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005670 if (op < 0)
5671 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5672 argv[i]);
5673 i++;
5674 if (i == (ssize_t) (argc-1))
5675 ThrowMogrifyException(OptionError,"MissingArgument",option);
5676 if (IsGeometry(argv[i]) == MagickFalse)
5677 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5678 break;
5679 }
cristy3ed852e2009-09-05 21:47:34 +00005680 if (LocaleCompare("stretch",option+1) == 0)
5681 {
cristybb503372010-05-27 20:51:26 +00005682 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005683 stretch;
5684
5685 if (*option == '+')
5686 break;
5687 i++;
cristybb503372010-05-27 20:51:26 +00005688 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005689 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005690 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005691 if (stretch < 0)
5692 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5693 argv[i]);
5694 break;
5695 }
5696 if (LocaleCompare("strip",option+1) == 0)
5697 break;
5698 if (LocaleCompare("stroke",option+1) == 0)
5699 {
5700 if (*option == '+')
5701 break;
5702 i++;
cristybb503372010-05-27 20:51:26 +00005703 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005704 ThrowMogrifyException(OptionError,"MissingArgument",option);
5705 break;
5706 }
5707 if (LocaleCompare("strokewidth",option+1) == 0)
5708 {
5709 if (*option == '+')
5710 break;
5711 i++;
cristybb503372010-05-27 20:51:26 +00005712 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005713 ThrowMogrifyException(OptionError,"MissingArgument",option);
5714 if (IsGeometry(argv[i]) == MagickFalse)
5715 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5716 break;
5717 }
5718 if (LocaleCompare("style",option+1) == 0)
5719 {
cristybb503372010-05-27 20:51:26 +00005720 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005721 style;
5722
5723 if (*option == '+')
5724 break;
5725 i++;
cristybb503372010-05-27 20:51:26 +00005726 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005727 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005728 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005729 if (style < 0)
5730 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5731 argv[i]);
5732 break;
5733 }
cristyecb10ff2011-03-22 13:14:03 +00005734 if (LocaleCompare("swap",option+1) == 0)
5735 {
5736 if (*option == '+')
5737 break;
5738 i++;
5739 if (i == (ssize_t) (argc-1))
5740 ThrowMogrifyException(OptionError,"MissingArgument",option);
5741 if (IsGeometry(argv[i]) == MagickFalse)
5742 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5743 break;
5744 }
cristy3ed852e2009-09-05 21:47:34 +00005745 if (LocaleCompare("swirl",option+1) == 0)
5746 {
5747 if (*option == '+')
5748 break;
5749 i++;
cristybb503372010-05-27 20:51:26 +00005750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005751 ThrowMogrifyException(OptionError,"MissingArgument",option);
5752 if (IsGeometry(argv[i]) == MagickFalse)
5753 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5754 break;
5755 }
cristyd9a29192010-10-16 16:49:53 +00005756 if (LocaleCompare("synchronize",option+1) == 0)
5757 break;
cristy3ed852e2009-09-05 21:47:34 +00005758 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5759 }
5760 case 't':
5761 {
5762 if (LocaleCompare("taint",option+1) == 0)
5763 break;
5764 if (LocaleCompare("texture",option+1) == 0)
5765 {
5766 if (*option == '+')
5767 break;
5768 i++;
cristybb503372010-05-27 20:51:26 +00005769 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005770 ThrowMogrifyException(OptionError,"MissingArgument",option);
5771 break;
5772 }
5773 if (LocaleCompare("tile",option+1) == 0)
5774 {
5775 if (*option == '+')
5776 break;
5777 i++;
cristybb503372010-05-27 20:51:26 +00005778 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005779 ThrowMogrifyException(OptionError,"MissingArgument",option);
5780 break;
5781 }
5782 if (LocaleCompare("tile-offset",option+1) == 0)
5783 {
5784 if (*option == '+')
5785 break;
5786 i++;
cristybb503372010-05-27 20:51:26 +00005787 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005788 ThrowMogrifyException(OptionError,"MissingArgument",option);
5789 if (IsGeometry(argv[i]) == MagickFalse)
5790 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5791 break;
5792 }
5793 if (LocaleCompare("tint",option+1) == 0)
5794 {
5795 if (*option == '+')
5796 break;
5797 i++;
cristybb503372010-05-27 20:51:26 +00005798 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005799 ThrowMogrifyException(OptionError,"MissingArgument",option);
5800 if (IsGeometry(argv[i]) == MagickFalse)
5801 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5802 break;
5803 }
5804 if (LocaleCompare("transform",option+1) == 0)
5805 break;
5806 if (LocaleCompare("transpose",option+1) == 0)
5807 break;
5808 if (LocaleCompare("transverse",option+1) == 0)
5809 break;
5810 if (LocaleCompare("threshold",option+1) == 0)
5811 {
5812 if (*option == '+')
5813 break;
5814 i++;
cristybb503372010-05-27 20:51:26 +00005815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005816 ThrowMogrifyException(OptionError,"MissingArgument",option);
5817 if (IsGeometry(argv[i]) == MagickFalse)
5818 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5819 break;
5820 }
5821 if (LocaleCompare("thumbnail",option+1) == 0)
5822 {
5823 if (*option == '+')
5824 break;
5825 i++;
cristybb503372010-05-27 20:51:26 +00005826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005827 ThrowMogrifyException(OptionError,"MissingArgument",option);
5828 if (IsGeometry(argv[i]) == MagickFalse)
5829 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5830 break;
5831 }
5832 if (LocaleCompare("transparent",option+1) == 0)
5833 {
5834 i++;
cristybb503372010-05-27 20:51:26 +00005835 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005836 ThrowMogrifyException(OptionError,"MissingArgument",option);
5837 break;
5838 }
5839 if (LocaleCompare("transparent-color",option+1) == 0)
5840 {
5841 if (*option == '+')
5842 break;
5843 i++;
cristybb503372010-05-27 20:51:26 +00005844 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005845 ThrowMogrifyException(OptionError,"MissingArgument",option);
5846 break;
5847 }
5848 if (LocaleCompare("treedepth",option+1) == 0)
5849 {
5850 if (*option == '+')
5851 break;
5852 i++;
cristybb503372010-05-27 20:51:26 +00005853 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005854 ThrowMogrifyException(OptionError,"MissingArgument",option);
5855 if (IsGeometry(argv[i]) == MagickFalse)
5856 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5857 break;
5858 }
5859 if (LocaleCompare("trim",option+1) == 0)
5860 break;
5861 if (LocaleCompare("type",option+1) == 0)
5862 {
cristybb503372010-05-27 20:51:26 +00005863 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005864 type;
5865
5866 if (*option == '+')
5867 break;
5868 i++;
cristybb503372010-05-27 20:51:26 +00005869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005870 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005871 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005872 if (type < 0)
5873 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5874 argv[i]);
5875 break;
5876 }
5877 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5878 }
5879 case 'u':
5880 {
5881 if (LocaleCompare("undercolor",option+1) == 0)
5882 {
5883 if (*option == '+')
5884 break;
5885 i++;
cristybb503372010-05-27 20:51:26 +00005886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005887 ThrowMogrifyException(OptionError,"MissingArgument",option);
5888 break;
5889 }
5890 if (LocaleCompare("unique-colors",option+1) == 0)
5891 break;
5892 if (LocaleCompare("units",option+1) == 0)
5893 {
cristybb503372010-05-27 20:51:26 +00005894 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005895 units;
5896
5897 if (*option == '+')
5898 break;
5899 i++;
cristybb503372010-05-27 20:51:26 +00005900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005901 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005902 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005903 argv[i]);
5904 if (units < 0)
5905 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5906 argv[i]);
5907 break;
5908 }
5909 if (LocaleCompare("unsharp",option+1) == 0)
5910 {
5911 i++;
cristybb503372010-05-27 20:51:26 +00005912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005913 ThrowMogrifyException(OptionError,"MissingArgument",option);
5914 if (IsGeometry(argv[i]) == MagickFalse)
5915 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5916 break;
5917 }
5918 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5919 }
5920 case 'v':
5921 {
5922 if (LocaleCompare("verbose",option+1) == 0)
5923 {
5924 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5925 break;
5926 }
5927 if ((LocaleCompare("version",option+1) == 0) ||
5928 (LocaleCompare("-version",option+1) == 0))
5929 {
cristyb51dff52011-05-19 16:55:47 +00005930 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005931 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005932 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5933 GetMagickCopyright());
5934 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5935 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005936 break;
5937 }
5938 if (LocaleCompare("view",option+1) == 0)
5939 {
5940 if (*option == '+')
5941 break;
5942 i++;
cristybb503372010-05-27 20:51:26 +00005943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005944 ThrowMogrifyException(OptionError,"MissingArgument",option);
5945 break;
5946 }
5947 if (LocaleCompare("vignette",option+1) == 0)
5948 {
5949 if (*option == '+')
5950 break;
5951 i++;
cristybb503372010-05-27 20:51:26 +00005952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005953 ThrowMogrifyException(OptionError,"MissingArgument",option);
5954 if (IsGeometry(argv[i]) == MagickFalse)
5955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5956 break;
5957 }
5958 if (LocaleCompare("virtual-pixel",option+1) == 0)
5959 {
cristybb503372010-05-27 20:51:26 +00005960 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005961 method;
5962
5963 if (*option == '+')
5964 break;
5965 i++;
cristybb503372010-05-27 20:51:26 +00005966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005967 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005968 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005969 argv[i]);
5970 if (method < 0)
5971 ThrowMogrifyException(OptionError,
5972 "UnrecognizedVirtualPixelMethod",argv[i]);
5973 break;
5974 }
5975 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5976 }
5977 case 'w':
5978 {
5979 if (LocaleCompare("wave",option+1) == 0)
5980 {
5981 i++;
cristybb503372010-05-27 20:51:26 +00005982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005983 ThrowMogrifyException(OptionError,"MissingArgument",option);
5984 if (IsGeometry(argv[i]) == MagickFalse)
5985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5986 break;
5987 }
5988 if (LocaleCompare("weight",option+1) == 0)
5989 {
5990 if (*option == '+')
5991 break;
5992 i++;
cristybb503372010-05-27 20:51:26 +00005993 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005994 ThrowMogrifyException(OptionError,"MissingArgument",option);
5995 break;
5996 }
5997 if (LocaleCompare("white-point",option+1) == 0)
5998 {
5999 if (*option == '+')
6000 break;
6001 i++;
cristybb503372010-05-27 20:51:26 +00006002 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006003 ThrowMogrifyException(OptionError,"MissingArgument",option);
6004 if (IsGeometry(argv[i]) == MagickFalse)
6005 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6006 break;
6007 }
6008 if (LocaleCompare("white-threshold",option+1) == 0)
6009 {
6010 if (*option == '+')
6011 break;
6012 i++;
cristybb503372010-05-27 20:51:26 +00006013 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006014 ThrowMogrifyException(OptionError,"MissingArgument",option);
6015 if (IsGeometry(argv[i]) == MagickFalse)
6016 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6017 break;
6018 }
6019 if (LocaleCompare("write",option+1) == 0)
6020 {
6021 i++;
cristybb503372010-05-27 20:51:26 +00006022 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006023 ThrowMogrifyException(OptionError,"MissingArgument",option);
6024 break;
6025 }
6026 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6027 }
6028 case '?':
6029 break;
6030 default:
6031 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6032 }
cristy042ee782011-04-22 18:48:30 +00006033 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6034 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006035 if (fire != MagickFalse)
6036 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6037 }
6038 if (k != 0)
6039 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006040 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006041 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6042 DestroyMogrify();
6043 return(status != 0 ? MagickTrue : MagickFalse);
6044}
6045
6046/*
6047%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6048% %
6049% %
6050% %
6051+ M o g r i f y I m a g e I n f o %
6052% %
6053% %
6054% %
6055%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6056%
6057% MogrifyImageInfo() applies image processing settings to the image as
6058% prescribed by command line options.
6059%
6060% The format of the MogrifyImageInfo method is:
6061%
6062% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6063% const char **argv,ExceptionInfo *exception)
6064%
6065% A description of each parameter follows:
6066%
6067% o image_info: the image info..
6068%
6069% o argc: Specifies a pointer to an integer describing the number of
6070% elements in the argument vector.
6071%
6072% o argv: Specifies a pointer to a text array containing the command line
6073% arguments.
6074%
6075% o exception: return any errors or warnings in this structure.
6076%
6077*/
6078WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6079 const int argc,const char **argv,ExceptionInfo *exception)
6080{
6081 const char
6082 *option;
6083
6084 GeometryInfo
6085 geometry_info;
6086
cristybb503372010-05-27 20:51:26 +00006087 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006088 count;
6089
cristybb503372010-05-27 20:51:26 +00006090 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006091 i;
6092
6093 /*
6094 Initialize method variables.
6095 */
6096 assert(image_info != (ImageInfo *) NULL);
6097 assert(image_info->signature == MagickSignature);
6098 if (image_info->debug != MagickFalse)
6099 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6100 image_info->filename);
6101 if (argc < 0)
6102 return(MagickTrue);
6103 /*
6104 Set the image settings.
6105 */
cristybb503372010-05-27 20:51:26 +00006106 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006107 {
6108 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006109 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006110 continue;
cristy042ee782011-04-22 18:48:30 +00006111 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006112 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006113 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006114 break;
6115 switch (*(option+1))
6116 {
6117 case 'a':
6118 {
6119 if (LocaleCompare("adjoin",option+1) == 0)
6120 {
6121 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6122 break;
6123 }
6124 if (LocaleCompare("antialias",option+1) == 0)
6125 {
6126 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6127 break;
6128 }
6129 if (LocaleCompare("attenuate",option+1) == 0)
6130 {
6131 if (*option == '+')
6132 {
6133 (void) DeleteImageOption(image_info,option+1);
6134 break;
6135 }
6136 (void) SetImageOption(image_info,option+1,argv[i+1]);
6137 break;
6138 }
6139 if (LocaleCompare("authenticate",option+1) == 0)
6140 {
6141 if (*option == '+')
6142 (void) CloneString(&image_info->authenticate,(char *) NULL);
6143 else
6144 (void) CloneString(&image_info->authenticate,argv[i+1]);
6145 break;
6146 }
6147 break;
6148 }
6149 case 'b':
6150 {
6151 if (LocaleCompare("background",option+1) == 0)
6152 {
6153 if (*option == '+')
6154 {
6155 (void) DeleteImageOption(image_info,option+1);
6156 (void) QueryColorDatabase(BackgroundColor,
6157 &image_info->background_color,exception);
6158 break;
6159 }
6160 (void) SetImageOption(image_info,option+1,argv[i+1]);
6161 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6162 exception);
6163 break;
6164 }
6165 if (LocaleCompare("bias",option+1) == 0)
6166 {
6167 if (*option == '+')
6168 {
6169 (void) SetImageOption(image_info,option+1,"0.0");
6170 break;
6171 }
6172 (void) SetImageOption(image_info,option+1,argv[i+1]);
6173 break;
6174 }
6175 if (LocaleCompare("black-point-compensation",option+1) == 0)
6176 {
6177 if (*option == '+')
6178 {
6179 (void) SetImageOption(image_info,option+1,"false");
6180 break;
6181 }
6182 (void) SetImageOption(image_info,option+1,"true");
6183 break;
6184 }
6185 if (LocaleCompare("blue-primary",option+1) == 0)
6186 {
6187 if (*option == '+')
6188 {
6189 (void) SetImageOption(image_info,option+1,"0.0");
6190 break;
6191 }
6192 (void) SetImageOption(image_info,option+1,argv[i+1]);
6193 break;
6194 }
6195 if (LocaleCompare("bordercolor",option+1) == 0)
6196 {
6197 if (*option == '+')
6198 {
6199 (void) DeleteImageOption(image_info,option+1);
6200 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6201 exception);
6202 break;
6203 }
6204 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6205 exception);
6206 (void) SetImageOption(image_info,option+1,argv[i+1]);
6207 break;
6208 }
6209 if (LocaleCompare("box",option+1) == 0)
6210 {
6211 if (*option == '+')
6212 {
6213 (void) SetImageOption(image_info,"undercolor","none");
6214 break;
6215 }
6216 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6217 break;
6218 }
6219 break;
6220 }
6221 case 'c':
6222 {
6223 if (LocaleCompare("cache",option+1) == 0)
6224 {
6225 MagickSizeType
6226 limit;
6227
6228 limit=MagickResourceInfinity;
6229 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006230 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006231 (void) SetMagickResourceLimit(MemoryResource,limit);
6232 (void) SetMagickResourceLimit(MapResource,2*limit);
6233 break;
6234 }
6235 if (LocaleCompare("caption",option+1) == 0)
6236 {
6237 if (*option == '+')
6238 {
6239 (void) DeleteImageOption(image_info,option+1);
6240 break;
6241 }
6242 (void) SetImageOption(image_info,option+1,argv[i+1]);
6243 break;
6244 }
6245 if (LocaleCompare("channel",option+1) == 0)
6246 {
6247 if (*option == '+')
6248 {
6249 image_info->channel=DefaultChannels;
6250 break;
6251 }
6252 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6253 break;
6254 }
6255 if (LocaleCompare("colors",option+1) == 0)
6256 {
cristye27293e2009-12-18 02:53:20 +00006257 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006258 break;
6259 }
6260 if (LocaleCompare("colorspace",option+1) == 0)
6261 {
6262 if (*option == '+')
6263 {
6264 image_info->colorspace=UndefinedColorspace;
6265 (void) SetImageOption(image_info,option+1,"undefined");
6266 break;
6267 }
cristy042ee782011-04-22 18:48:30 +00006268 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006269 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6270 (void) SetImageOption(image_info,option+1,argv[i+1]);
6271 break;
6272 }
cristy3ed852e2009-09-05 21:47:34 +00006273 if (LocaleCompare("comment",option+1) == 0)
6274 {
6275 if (*option == '+')
6276 {
6277 (void) DeleteImageOption(image_info,option+1);
6278 break;
6279 }
6280 (void) SetImageOption(image_info,option+1,argv[i+1]);
6281 break;
6282 }
6283 if (LocaleCompare("compose",option+1) == 0)
6284 {
6285 if (*option == '+')
6286 {
6287 (void) SetImageOption(image_info,option+1,"undefined");
6288 break;
6289 }
6290 (void) SetImageOption(image_info,option+1,argv[i+1]);
6291 break;
6292 }
6293 if (LocaleCompare("compress",option+1) == 0)
6294 {
6295 if (*option == '+')
6296 {
6297 image_info->compression=UndefinedCompression;
6298 (void) SetImageOption(image_info,option+1,"undefined");
6299 break;
6300 }
cristy042ee782011-04-22 18:48:30 +00006301 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006302 MagickCompressOptions,MagickFalse,argv[i+1]);
6303 (void) SetImageOption(image_info,option+1,argv[i+1]);
6304 break;
6305 }
6306 break;
6307 }
6308 case 'd':
6309 {
6310 if (LocaleCompare("debug",option+1) == 0)
6311 {
6312 if (*option == '+')
6313 (void) SetLogEventMask("none");
6314 else
6315 (void) SetLogEventMask(argv[i+1]);
6316 image_info->debug=IsEventLogging();
6317 break;
6318 }
6319 if (LocaleCompare("define",option+1) == 0)
6320 {
6321 if (*option == '+')
6322 {
6323 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6324 (void) DeleteImageRegistry(argv[i+1]+9);
6325 else
6326 (void) DeleteImageOption(image_info,argv[i+1]);
6327 break;
6328 }
6329 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6330 {
6331 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6332 exception);
6333 break;
6334 }
6335 (void) DefineImageOption(image_info,argv[i+1]);
6336 break;
6337 }
6338 if (LocaleCompare("delay",option+1) == 0)
6339 {
6340 if (*option == '+')
6341 {
6342 (void) SetImageOption(image_info,option+1,"0");
6343 break;
6344 }
6345 (void) SetImageOption(image_info,option+1,argv[i+1]);
6346 break;
6347 }
6348 if (LocaleCompare("density",option+1) == 0)
6349 {
6350 /*
6351 Set image density.
6352 */
6353 if (*option == '+')
6354 {
6355 if (image_info->density != (char *) NULL)
6356 image_info->density=DestroyString(image_info->density);
6357 (void) SetImageOption(image_info,option+1,"72");
6358 break;
6359 }
6360 (void) CloneString(&image_info->density,argv[i+1]);
6361 (void) SetImageOption(image_info,option+1,argv[i+1]);
6362 break;
6363 }
6364 if (LocaleCompare("depth",option+1) == 0)
6365 {
6366 if (*option == '+')
6367 {
6368 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6369 break;
6370 }
cristye27293e2009-12-18 02:53:20 +00006371 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006372 break;
6373 }
cristyc9b12952010-03-28 01:12:28 +00006374 if (LocaleCompare("direction",option+1) == 0)
6375 {
6376 if (*option == '+')
6377 {
6378 (void) SetImageOption(image_info,option+1,"undefined");
6379 break;
6380 }
6381 (void) SetImageOption(image_info,option+1,argv[i+1]);
6382 break;
6383 }
cristy3ed852e2009-09-05 21:47:34 +00006384 if (LocaleCompare("display",option+1) == 0)
6385 {
6386 if (*option == '+')
6387 {
6388 if (image_info->server_name != (char *) NULL)
6389 image_info->server_name=DestroyString(
6390 image_info->server_name);
6391 break;
6392 }
6393 (void) CloneString(&image_info->server_name,argv[i+1]);
6394 break;
6395 }
6396 if (LocaleCompare("dispose",option+1) == 0)
6397 {
6398 if (*option == '+')
6399 {
6400 (void) SetImageOption(image_info,option+1,"undefined");
6401 break;
6402 }
6403 (void) SetImageOption(image_info,option+1,argv[i+1]);
6404 break;
6405 }
6406 if (LocaleCompare("dither",option+1) == 0)
6407 {
6408 if (*option == '+')
6409 {
6410 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006411 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006412 break;
6413 }
6414 (void) SetImageOption(image_info,option+1,argv[i+1]);
6415 image_info->dither=MagickTrue;
6416 break;
6417 }
6418 break;
6419 }
6420 case 'e':
6421 {
6422 if (LocaleCompare("encoding",option+1) == 0)
6423 {
6424 if (*option == '+')
6425 {
6426 (void) SetImageOption(image_info,option+1,"undefined");
6427 break;
6428 }
6429 (void) SetImageOption(image_info,option+1,argv[i+1]);
6430 break;
6431 }
6432 if (LocaleCompare("endian",option+1) == 0)
6433 {
6434 if (*option == '+')
6435 {
6436 image_info->endian=UndefinedEndian;
6437 (void) SetImageOption(image_info,option+1,"undefined");
6438 break;
6439 }
cristy042ee782011-04-22 18:48:30 +00006440 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006441 MagickEndianOptions,MagickFalse,argv[i+1]);
6442 (void) SetImageOption(image_info,option+1,argv[i+1]);
6443 break;
6444 }
6445 if (LocaleCompare("extract",option+1) == 0)
6446 {
6447 /*
6448 Set image extract geometry.
6449 */
6450 if (*option == '+')
6451 {
6452 if (image_info->extract != (char *) NULL)
6453 image_info->extract=DestroyString(image_info->extract);
6454 break;
6455 }
6456 (void) CloneString(&image_info->extract,argv[i+1]);
6457 break;
6458 }
6459 break;
6460 }
6461 case 'f':
6462 {
6463 if (LocaleCompare("fill",option+1) == 0)
6464 {
6465 if (*option == '+')
6466 {
6467 (void) SetImageOption(image_info,option+1,"none");
6468 break;
6469 }
6470 (void) SetImageOption(image_info,option+1,argv[i+1]);
6471 break;
6472 }
6473 if (LocaleCompare("filter",option+1) == 0)
6474 {
6475 if (*option == '+')
6476 {
6477 (void) SetImageOption(image_info,option+1,"undefined");
6478 break;
6479 }
6480 (void) SetImageOption(image_info,option+1,argv[i+1]);
6481 break;
6482 }
6483 if (LocaleCompare("font",option+1) == 0)
6484 {
6485 if (*option == '+')
6486 {
6487 if (image_info->font != (char *) NULL)
6488 image_info->font=DestroyString(image_info->font);
6489 break;
6490 }
6491 (void) CloneString(&image_info->font,argv[i+1]);
6492 break;
6493 }
6494 if (LocaleCompare("format",option+1) == 0)
6495 {
6496 register const char
6497 *q;
6498
6499 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006500 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006501 image_info->ping=MagickFalse;
6502 (void) SetImageOption(image_info,option+1,argv[i+1]);
6503 break;
6504 }
6505 if (LocaleCompare("fuzz",option+1) == 0)
6506 {
6507 if (*option == '+')
6508 {
6509 image_info->fuzz=0.0;
6510 (void) SetImageOption(image_info,option+1,"0");
6511 break;
6512 }
cristyf2f27272009-12-17 14:48:46 +00006513 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006514 1.0);
6515 (void) SetImageOption(image_info,option+1,argv[i+1]);
6516 break;
6517 }
6518 break;
6519 }
6520 case 'g':
6521 {
6522 if (LocaleCompare("gravity",option+1) == 0)
6523 {
6524 if (*option == '+')
6525 {
6526 (void) SetImageOption(image_info,option+1,"undefined");
6527 break;
6528 }
6529 (void) SetImageOption(image_info,option+1,argv[i+1]);
6530 break;
6531 }
6532 if (LocaleCompare("green-primary",option+1) == 0)
6533 {
6534 if (*option == '+')
6535 {
6536 (void) SetImageOption(image_info,option+1,"0.0");
6537 break;
6538 }
6539 (void) SetImageOption(image_info,option+1,argv[i+1]);
6540 break;
6541 }
6542 break;
6543 }
6544 case 'i':
6545 {
6546 if (LocaleCompare("intent",option+1) == 0)
6547 {
6548 if (*option == '+')
6549 {
6550 (void) SetImageOption(image_info,option+1,"undefined");
6551 break;
6552 }
6553 (void) SetImageOption(image_info,option+1,argv[i+1]);
6554 break;
6555 }
6556 if (LocaleCompare("interlace",option+1) == 0)
6557 {
6558 if (*option == '+')
6559 {
6560 image_info->interlace=UndefinedInterlace;
6561 (void) SetImageOption(image_info,option+1,"undefined");
6562 break;
6563 }
cristy042ee782011-04-22 18:48:30 +00006564 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006565 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6566 (void) SetImageOption(image_info,option+1,argv[i+1]);
6567 break;
6568 }
cristyb32b90a2009-09-07 21:45:48 +00006569 if (LocaleCompare("interline-spacing",option+1) == 0)
6570 {
6571 if (*option == '+')
6572 {
6573 (void) SetImageOption(image_info,option+1,"undefined");
6574 break;
6575 }
6576 (void) SetImageOption(image_info,option+1,argv[i+1]);
6577 break;
6578 }
cristy3ed852e2009-09-05 21:47:34 +00006579 if (LocaleCompare("interpolate",option+1) == 0)
6580 {
6581 if (*option == '+')
6582 {
6583 (void) SetImageOption(image_info,option+1,"undefined");
6584 break;
6585 }
6586 (void) SetImageOption(image_info,option+1,argv[i+1]);
6587 break;
6588 }
6589 if (LocaleCompare("interword-spacing",option+1) == 0)
6590 {
6591 if (*option == '+')
6592 {
6593 (void) SetImageOption(image_info,option+1,"undefined");
6594 break;
6595 }
6596 (void) SetImageOption(image_info,option+1,argv[i+1]);
6597 break;
6598 }
6599 break;
6600 }
6601 case 'k':
6602 {
6603 if (LocaleCompare("kerning",option+1) == 0)
6604 {
6605 if (*option == '+')
6606 {
6607 (void) SetImageOption(image_info,option+1,"undefined");
6608 break;
6609 }
6610 (void) SetImageOption(image_info,option+1,argv[i+1]);
6611 break;
6612 }
6613 break;
6614 }
6615 case 'l':
6616 {
6617 if (LocaleCompare("label",option+1) == 0)
6618 {
6619 if (*option == '+')
6620 {
6621 (void) DeleteImageOption(image_info,option+1);
6622 break;
6623 }
6624 (void) SetImageOption(image_info,option+1,argv[i+1]);
6625 break;
6626 }
6627 if (LocaleCompare("limit",option+1) == 0)
6628 {
6629 MagickSizeType
6630 limit;
6631
6632 ResourceType
6633 type;
6634
6635 if (*option == '+')
6636 break;
cristy042ee782011-04-22 18:48:30 +00006637 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006638 MagickFalse,argv[i+1]);
6639 limit=MagickResourceInfinity;
6640 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006641 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006642 (void) SetMagickResourceLimit(type,limit);
6643 break;
6644 }
6645 if (LocaleCompare("list",option+1) == 0)
6646 {
cristybb503372010-05-27 20:51:26 +00006647 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006648 list;
6649
6650 /*
6651 Display configuration list.
6652 */
cristy042ee782011-04-22 18:48:30 +00006653 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006654 switch (list)
6655 {
6656 case MagickCoderOptions:
6657 {
6658 (void) ListCoderInfo((FILE *) NULL,exception);
6659 break;
6660 }
6661 case MagickColorOptions:
6662 {
6663 (void) ListColorInfo((FILE *) NULL,exception);
6664 break;
6665 }
6666 case MagickConfigureOptions:
6667 {
6668 (void) ListConfigureInfo((FILE *) NULL,exception);
6669 break;
6670 }
6671 case MagickDelegateOptions:
6672 {
6673 (void) ListDelegateInfo((FILE *) NULL,exception);
6674 break;
6675 }
6676 case MagickFontOptions:
6677 {
6678 (void) ListTypeInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickFormatOptions:
6682 {
6683 (void) ListMagickInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickLocaleOptions:
6687 {
6688 (void) ListLocaleInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickLogOptions:
6692 {
6693 (void) ListLogInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickMagicOptions:
6697 {
6698 (void) ListMagicInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickMimeOptions:
6702 {
6703 (void) ListMimeInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickModuleOptions:
6707 {
6708 (void) ListModuleInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickPolicyOptions:
6712 {
6713 (void) ListPolicyInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickResourceOptions:
6717 {
6718 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickThresholdOptions:
6722 {
6723 (void) ListThresholdMaps((FILE *) NULL,exception);
6724 break;
6725 }
6726 default:
6727 {
cristy042ee782011-04-22 18:48:30 +00006728 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006729 exception);
6730 break;
6731 }
6732 }
cristyaeb2cbc2010-05-07 13:28:58 +00006733 break;
cristy3ed852e2009-09-05 21:47:34 +00006734 }
6735 if (LocaleCompare("log",option+1) == 0)
6736 {
6737 if (*option == '+')
6738 break;
6739 (void) SetLogFormat(argv[i+1]);
6740 break;
6741 }
6742 if (LocaleCompare("loop",option+1) == 0)
6743 {
6744 if (*option == '+')
6745 {
6746 (void) SetImageOption(image_info,option+1,"0");
6747 break;
6748 }
6749 (void) SetImageOption(image_info,option+1,argv[i+1]);
6750 break;
6751 }
6752 break;
6753 }
6754 case 'm':
6755 {
6756 if (LocaleCompare("matte",option+1) == 0)
6757 {
6758 if (*option == '+')
6759 {
6760 (void) SetImageOption(image_info,option+1,"false");
6761 break;
6762 }
6763 (void) SetImageOption(image_info,option+1,"true");
6764 break;
6765 }
6766 if (LocaleCompare("mattecolor",option+1) == 0)
6767 {
6768 if (*option == '+')
6769 {
6770 (void) SetImageOption(image_info,option+1,argv[i+1]);
6771 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6772 exception);
6773 break;
6774 }
6775 (void) SetImageOption(image_info,option+1,argv[i+1]);
6776 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6777 exception);
6778 break;
6779 }
6780 if (LocaleCompare("monitor",option+1) == 0)
6781 {
6782 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6783 (void *) NULL);
6784 break;
6785 }
6786 if (LocaleCompare("monochrome",option+1) == 0)
6787 {
6788 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6789 break;
6790 }
6791 break;
6792 }
6793 case 'o':
6794 {
6795 if (LocaleCompare("orient",option+1) == 0)
6796 {
6797 if (*option == '+')
6798 {
6799 image_info->orientation=UndefinedOrientation;
6800 (void) SetImageOption(image_info,option+1,"undefined");
6801 break;
6802 }
cristy042ee782011-04-22 18:48:30 +00006803 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006804 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006805 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006806 break;
6807 }
6808 }
6809 case 'p':
6810 {
6811 if (LocaleCompare("page",option+1) == 0)
6812 {
6813 char
6814 *canonical_page,
6815 page[MaxTextExtent];
6816
6817 const char
6818 *image_option;
6819
6820 MagickStatusType
6821 flags;
6822
6823 RectangleInfo
6824 geometry;
6825
6826 if (*option == '+')
6827 {
6828 (void) DeleteImageOption(image_info,option+1);
6829 (void) CloneString(&image_info->page,(char *) NULL);
6830 break;
6831 }
6832 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6833 image_option=GetImageOption(image_info,"page");
6834 if (image_option != (const char *) NULL)
6835 flags=ParseAbsoluteGeometry(image_option,&geometry);
6836 canonical_page=GetPageGeometry(argv[i+1]);
6837 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6838 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006839 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006840 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006841 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006842 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006843 (unsigned long) geometry.width,(unsigned long) geometry.height,
6844 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006845 (void) SetImageOption(image_info,option+1,page);
6846 (void) CloneString(&image_info->page,page);
6847 break;
6848 }
6849 if (LocaleCompare("pen",option+1) == 0)
6850 {
6851 if (*option == '+')
6852 {
6853 (void) SetImageOption(image_info,option+1,"none");
6854 break;
6855 }
6856 (void) SetImageOption(image_info,option+1,argv[i+1]);
6857 break;
6858 }
6859 if (LocaleCompare("ping",option+1) == 0)
6860 {
6861 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6862 break;
6863 }
6864 if (LocaleCompare("pointsize",option+1) == 0)
6865 {
6866 if (*option == '+')
6867 geometry_info.rho=0.0;
6868 else
6869 (void) ParseGeometry(argv[i+1],&geometry_info);
6870 image_info->pointsize=geometry_info.rho;
6871 break;
6872 }
cristye7f51092010-01-17 00:39:37 +00006873 if (LocaleCompare("precision",option+1) == 0)
6874 {
cristybf2766a2010-01-17 03:33:23 +00006875 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006876 break;
6877 }
cristy3ed852e2009-09-05 21:47:34 +00006878 if (LocaleCompare("preview",option+1) == 0)
6879 {
6880 /*
6881 Preview image.
6882 */
6883 if (*option == '+')
6884 {
6885 image_info->preview_type=UndefinedPreview;
6886 break;
6887 }
cristy042ee782011-04-22 18:48:30 +00006888 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006889 MagickPreviewOptions,MagickFalse,argv[i+1]);
6890 break;
6891 }
6892 break;
6893 }
6894 case 'q':
6895 {
6896 if (LocaleCompare("quality",option+1) == 0)
6897 {
6898 /*
6899 Set image compression quality.
6900 */
6901 if (*option == '+')
6902 {
6903 image_info->quality=UndefinedCompressionQuality;
6904 (void) SetImageOption(image_info,option+1,"0");
6905 break;
6906 }
cristye27293e2009-12-18 02:53:20 +00006907 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006908 (void) SetImageOption(image_info,option+1,argv[i+1]);
6909 break;
6910 }
6911 if (LocaleCompare("quiet",option+1) == 0)
6912 {
6913 static WarningHandler
6914 warning_handler = (WarningHandler) NULL;
6915
6916 if (*option == '+')
6917 {
6918 /*
6919 Restore error or warning messages.
6920 */
6921 warning_handler=SetWarningHandler(warning_handler);
6922 break;
6923 }
6924 /*
6925 Suppress error or warning messages.
6926 */
6927 warning_handler=SetWarningHandler((WarningHandler) NULL);
6928 break;
6929 }
6930 break;
6931 }
6932 case 'r':
6933 {
6934 if (LocaleCompare("red-primary",option+1) == 0)
6935 {
6936 if (*option == '+')
6937 {
6938 (void) SetImageOption(image_info,option+1,"0.0");
6939 break;
6940 }
6941 (void) SetImageOption(image_info,option+1,argv[i+1]);
6942 break;
6943 }
6944 break;
6945 }
6946 case 's':
6947 {
6948 if (LocaleCompare("sampling-factor",option+1) == 0)
6949 {
6950 /*
6951 Set image sampling factor.
6952 */
6953 if (*option == '+')
6954 {
6955 if (image_info->sampling_factor != (char *) NULL)
6956 image_info->sampling_factor=DestroyString(
6957 image_info->sampling_factor);
6958 break;
6959 }
6960 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6961 break;
6962 }
6963 if (LocaleCompare("scene",option+1) == 0)
6964 {
6965 /*
6966 Set image scene.
6967 */
6968 if (*option == '+')
6969 {
6970 image_info->scene=0;
6971 (void) SetImageOption(image_info,option+1,"0");
6972 break;
6973 }
cristye27293e2009-12-18 02:53:20 +00006974 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006975 (void) SetImageOption(image_info,option+1,argv[i+1]);
6976 break;
6977 }
6978 if (LocaleCompare("seed",option+1) == 0)
6979 {
cristybb503372010-05-27 20:51:26 +00006980 size_t
cristy3ed852e2009-09-05 21:47:34 +00006981 seed;
6982
6983 if (*option == '+')
6984 {
cristybb503372010-05-27 20:51:26 +00006985 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006986 SeedPseudoRandomGenerator(seed);
6987 break;
6988 }
cristye27293e2009-12-18 02:53:20 +00006989 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006990 SeedPseudoRandomGenerator(seed);
6991 break;
6992 }
6993 if (LocaleCompare("size",option+1) == 0)
6994 {
6995 if (*option == '+')
6996 {
6997 if (image_info->size != (char *) NULL)
6998 image_info->size=DestroyString(image_info->size);
6999 break;
7000 }
7001 (void) CloneString(&image_info->size,argv[i+1]);
7002 break;
7003 }
7004 if (LocaleCompare("stroke",option+1) == 0)
7005 {
7006 if (*option == '+')
7007 {
7008 (void) SetImageOption(image_info,option+1,"none");
7009 break;
7010 }
7011 (void) SetImageOption(image_info,option+1,argv[i+1]);
7012 break;
7013 }
7014 if (LocaleCompare("strokewidth",option+1) == 0)
7015 {
7016 if (*option == '+')
7017 {
7018 (void) SetImageOption(image_info,option+1,"0");
7019 break;
7020 }
7021 (void) SetImageOption(image_info,option+1,argv[i+1]);
7022 break;
7023 }
cristyd9a29192010-10-16 16:49:53 +00007024 if (LocaleCompare("synchronize",option+1) == 0)
7025 {
7026 if (*option == '+')
7027 {
7028 image_info->synchronize=MagickFalse;
7029 break;
7030 }
7031 image_info->synchronize=MagickTrue;
7032 break;
7033 }
cristy3ed852e2009-09-05 21:47:34 +00007034 break;
7035 }
7036 case 't':
7037 {
7038 if (LocaleCompare("taint",option+1) == 0)
7039 {
7040 if (*option == '+')
7041 {
7042 (void) SetImageOption(image_info,option+1,"false");
7043 break;
7044 }
7045 (void) SetImageOption(image_info,option+1,"true");
7046 break;
7047 }
7048 if (LocaleCompare("texture",option+1) == 0)
7049 {
7050 if (*option == '+')
7051 {
7052 if (image_info->texture != (char *) NULL)
7053 image_info->texture=DestroyString(image_info->texture);
7054 break;
7055 }
7056 (void) CloneString(&image_info->texture,argv[i+1]);
7057 break;
7058 }
7059 if (LocaleCompare("tile-offset",option+1) == 0)
7060 {
7061 if (*option == '+')
7062 {
7063 (void) SetImageOption(image_info,option+1,"0");
7064 break;
7065 }
7066 (void) SetImageOption(image_info,option+1,argv[i+1]);
7067 break;
7068 }
7069 if (LocaleCompare("transparent-color",option+1) == 0)
7070 {
7071 if (*option == '+')
7072 {
7073 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7074 (void) SetImageOption(image_info,option+1,"none");
7075 break;
7076 }
7077 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7078 exception);
7079 (void) SetImageOption(image_info,option+1,argv[i+1]);
7080 break;
7081 }
7082 if (LocaleCompare("type",option+1) == 0)
7083 {
7084 if (*option == '+')
7085 {
cristy5f1c1ff2010-12-23 21:38:06 +00007086 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007087 (void) SetImageOption(image_info,option+1,"undefined");
7088 break;
7089 }
cristy042ee782011-04-22 18:48:30 +00007090 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007091 MagickFalse,argv[i+1]);
7092 (void) SetImageOption(image_info,option+1,argv[i+1]);
7093 break;
7094 }
7095 break;
7096 }
7097 case 'u':
7098 {
7099 if (LocaleCompare("undercolor",option+1) == 0)
7100 {
7101 if (*option == '+')
7102 {
7103 (void) DeleteImageOption(image_info,option+1);
7104 break;
7105 }
7106 (void) SetImageOption(image_info,option+1,argv[i+1]);
7107 break;
7108 }
7109 if (LocaleCompare("units",option+1) == 0)
7110 {
7111 if (*option == '+')
7112 {
7113 image_info->units=UndefinedResolution;
7114 (void) SetImageOption(image_info,option+1,"undefined");
7115 break;
7116 }
cristy042ee782011-04-22 18:48:30 +00007117 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007118 MagickResolutionOptions,MagickFalse,argv[i+1]);
7119 (void) SetImageOption(image_info,option+1,argv[i+1]);
7120 break;
7121 }
7122 break;
7123 }
7124 case 'v':
7125 {
7126 if (LocaleCompare("verbose",option+1) == 0)
7127 {
7128 if (*option == '+')
7129 {
7130 image_info->verbose=MagickFalse;
7131 break;
7132 }
7133 image_info->verbose=MagickTrue;
7134 image_info->ping=MagickFalse;
7135 break;
7136 }
7137 if (LocaleCompare("view",option+1) == 0)
7138 {
7139 if (*option == '+')
7140 {
7141 if (image_info->view != (char *) NULL)
7142 image_info->view=DestroyString(image_info->view);
7143 break;
7144 }
7145 (void) CloneString(&image_info->view,argv[i+1]);
7146 break;
7147 }
7148 if (LocaleCompare("virtual-pixel",option+1) == 0)
7149 {
7150 if (*option == '+')
7151 {
7152 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7153 (void) SetImageOption(image_info,option+1,"undefined");
7154 break;
7155 }
7156 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007157 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007158 argv[i+1]);
7159 (void) SetImageOption(image_info,option+1,argv[i+1]);
7160 break;
7161 }
7162 break;
7163 }
7164 case 'w':
7165 {
7166 if (LocaleCompare("white-point",option+1) == 0)
7167 {
7168 if (*option == '+')
7169 {
7170 (void) SetImageOption(image_info,option+1,"0.0");
7171 break;
7172 }
7173 (void) SetImageOption(image_info,option+1,argv[i+1]);
7174 break;
7175 }
7176 break;
7177 }
7178 default:
7179 break;
7180 }
7181 i+=count;
7182 }
7183 return(MagickTrue);
7184}
7185
7186/*
7187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7188% %
7189% %
7190% %
7191+ M o g r i f y I m a g e L i s t %
7192% %
7193% %
7194% %
7195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7196%
7197% MogrifyImageList() applies any command line options that might affect the
7198% entire image list (e.g. -append, -coalesce, etc.).
7199%
7200% The format of the MogrifyImage method is:
7201%
7202% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7203% const char **argv,Image **images,ExceptionInfo *exception)
7204%
7205% A description of each parameter follows:
7206%
7207% o image_info: the image info..
7208%
7209% o argc: Specifies a pointer to an integer describing the number of
7210% elements in the argument vector.
7211%
7212% o argv: Specifies a pointer to a text array containing the command line
7213% arguments.
7214%
anthonye9c27192011-03-27 08:07:06 +00007215% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007216%
7217% o exception: return any errors or warnings in this structure.
7218%
7219*/
7220WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7221 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7222{
cristy3ed852e2009-09-05 21:47:34 +00007223 const char
7224 *option;
7225
cristy6b3da3a2010-06-20 02:21:46 +00007226 ImageInfo
7227 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007228
7229 MagickStatusType
7230 status;
7231
7232 QuantizeInfo
7233 *quantize_info;
7234
cristybb503372010-05-27 20:51:26 +00007235 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007236 i;
7237
cristy6b3da3a2010-06-20 02:21:46 +00007238 ssize_t
7239 count,
7240 index;
7241
cristy3ed852e2009-09-05 21:47:34 +00007242 /*
7243 Apply options to the image list.
7244 */
7245 assert(image_info != (ImageInfo *) NULL);
7246 assert(image_info->signature == MagickSignature);
7247 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007248 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007249 assert((*images)->signature == MagickSignature);
7250 if ((*images)->debug != MagickFalse)
7251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7252 (*images)->filename);
7253 if ((argc <= 0) || (*argv == (char *) NULL))
7254 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007255 mogrify_info=CloneImageInfo(image_info);
7256 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007257 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007258 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007259 {
cristy74fe8f12009-10-03 19:09:01 +00007260 if (*images == (Image *) NULL)
7261 break;
cristy3ed852e2009-09-05 21:47:34 +00007262 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007263 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007264 continue;
cristy042ee782011-04-22 18:48:30 +00007265 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007266 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007267 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007268 break;
cristy6b3da3a2010-06-20 02:21:46 +00007269 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007270 switch (*(option+1))
7271 {
7272 case 'a':
7273 {
7274 if (LocaleCompare("affinity",option+1) == 0)
7275 {
cristy6b3da3a2010-06-20 02:21:46 +00007276 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007277 if (*option == '+')
7278 {
7279 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7280 InheritException(exception,&(*images)->exception);
7281 break;
7282 }
7283 i++;
7284 break;
7285 }
7286 if (LocaleCompare("append",option+1) == 0)
7287 {
7288 Image
7289 *append_image;
7290
cristy6b3da3a2010-06-20 02:21:46 +00007291 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007292 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7293 MagickFalse,exception);
7294 if (append_image == (Image *) NULL)
7295 {
7296 status=MagickFalse;
7297 break;
7298 }
7299 *images=DestroyImageList(*images);
7300 *images=append_image;
7301 break;
7302 }
7303 if (LocaleCompare("average",option+1) == 0)
7304 {
7305 Image
7306 *average_image;
7307
cristyd18ae7c2010-03-07 17:39:52 +00007308 /*
7309 Average an image sequence (deprecated).
7310 */
cristy6b3da3a2010-06-20 02:21:46 +00007311 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007312 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7313 exception);
cristy3ed852e2009-09-05 21:47:34 +00007314 if (average_image == (Image *) NULL)
7315 {
7316 status=MagickFalse;
7317 break;
7318 }
7319 *images=DestroyImageList(*images);
7320 *images=average_image;
7321 break;
7322 }
7323 break;
7324 }
7325 case 'c':
7326 {
7327 if (LocaleCompare("channel",option+1) == 0)
7328 {
cristyf4ad9df2011-07-08 16:49:03 +00007329 ChannelType
7330 channel;
7331
cristy3ed852e2009-09-05 21:47:34 +00007332 if (*option == '+')
7333 {
7334 channel=DefaultChannels;
7335 break;
7336 }
7337 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007338 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007339 break;
7340 }
7341 if (LocaleCompare("clut",option+1) == 0)
7342 {
7343 Image
7344 *clut_image,
7345 *image;
7346
cristy6b3da3a2010-06-20 02:21:46 +00007347 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007348 image=RemoveFirstImageFromList(images);
7349 clut_image=RemoveFirstImageFromList(images);
7350 if (clut_image == (Image *) NULL)
7351 {
7352 status=MagickFalse;
7353 break;
7354 }
cristyf89cb1d2011-07-07 01:24:37 +00007355 (void) ClutImage(image,clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007356 clut_image=DestroyImage(clut_image);
7357 InheritException(exception,&image->exception);
7358 *images=DestroyImageList(*images);
7359 *images=image;
7360 break;
7361 }
7362 if (LocaleCompare("coalesce",option+1) == 0)
7363 {
7364 Image
7365 *coalesce_image;
7366
cristy6b3da3a2010-06-20 02:21:46 +00007367 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007368 coalesce_image=CoalesceImages(*images,exception);
7369 if (coalesce_image == (Image *) NULL)
7370 {
7371 status=MagickFalse;
7372 break;
7373 }
7374 *images=DestroyImageList(*images);
7375 *images=coalesce_image;
7376 break;
7377 }
7378 if (LocaleCompare("combine",option+1) == 0)
7379 {
7380 Image
7381 *combine_image;
7382
cristy6b3da3a2010-06-20 02:21:46 +00007383 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007384 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007385 if (combine_image == (Image *) NULL)
7386 {
7387 status=MagickFalse;
7388 break;
7389 }
7390 *images=DestroyImageList(*images);
7391 *images=combine_image;
7392 break;
7393 }
7394 if (LocaleCompare("composite",option+1) == 0)
7395 {
7396 Image
7397 *mask_image,
7398 *composite_image,
7399 *image;
7400
7401 RectangleInfo
7402 geometry;
7403
cristy6b3da3a2010-06-20 02:21:46 +00007404 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007405 image=RemoveFirstImageFromList(images);
7406 composite_image=RemoveFirstImageFromList(images);
7407 if (composite_image == (Image *) NULL)
7408 {
7409 status=MagickFalse;
7410 break;
7411 }
7412 (void) TransformImage(&composite_image,(char *) NULL,
7413 composite_image->geometry);
7414 SetGeometry(composite_image,&geometry);
7415 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7416 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7417 &geometry);
7418 mask_image=RemoveFirstImageFromList(images);
7419 if (mask_image != (Image *) NULL)
7420 {
7421 if ((image->compose == DisplaceCompositeOp) ||
7422 (image->compose == DistortCompositeOp))
7423 {
7424 /*
7425 Merge Y displacement into X displacement image.
7426 */
7427 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7428 mask_image,0,0);
7429 mask_image=DestroyImage(mask_image);
7430 }
7431 else
7432 {
7433 /*
7434 Set a blending mask for the composition.
7435 */
anthonya129f702011-04-14 01:08:48 +00007436 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007437 image->mask=mask_image;
7438 (void) NegateImage(image->mask,MagickFalse);
7439 }
7440 }
cristyf4ad9df2011-07-08 16:49:03 +00007441 (void) CompositeImage(image,image->compose,composite_image,
7442 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007443 if (mask_image != (Image *) NULL)
7444 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007445 composite_image=DestroyImage(composite_image);
7446 InheritException(exception,&image->exception);
7447 *images=DestroyImageList(*images);
7448 *images=image;
7449 break;
7450 }
anthony9f4f0342011-03-28 11:47:22 +00007451#if 0
7452This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007453 if (LocaleCompare("crop",option+1) == 0)
7454 {
7455 MagickStatusType
7456 flags;
7457
7458 RectangleInfo
7459 geometry;
7460
anthonye9c27192011-03-27 08:07:06 +00007461 /*
anthony9f4f0342011-03-28 11:47:22 +00007462 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007463 */
cristy6b3da3a2010-06-20 02:21:46 +00007464 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007465 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7466 if (((geometry.width == 0) && (geometry.height == 0)) ||
7467 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7468 break;
7469 (void) TransformImages(images,argv[i+1],(char *) NULL);
7470 InheritException(exception,&(*images)->exception);
7471 break;
7472 }
anthony9f4f0342011-03-28 11:47:22 +00007473#endif
cristy3ed852e2009-09-05 21:47:34 +00007474 break;
7475 }
7476 case 'd':
7477 {
7478 if (LocaleCompare("deconstruct",option+1) == 0)
7479 {
7480 Image
7481 *deconstruct_image;
7482
cristy6b3da3a2010-06-20 02:21:46 +00007483 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007484 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007485 exception);
cristy3ed852e2009-09-05 21:47:34 +00007486 if (deconstruct_image == (Image *) NULL)
7487 {
7488 status=MagickFalse;
7489 break;
7490 }
7491 *images=DestroyImageList(*images);
7492 *images=deconstruct_image;
7493 break;
7494 }
7495 if (LocaleCompare("delete",option+1) == 0)
7496 {
7497 if (*option == '+')
7498 DeleteImages(images,"-1",exception);
7499 else
7500 DeleteImages(images,argv[i+1],exception);
7501 break;
7502 }
7503 if (LocaleCompare("dither",option+1) == 0)
7504 {
7505 if (*option == '+')
7506 {
7507 quantize_info->dither=MagickFalse;
7508 break;
7509 }
7510 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007511 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007512 MagickDitherOptions,MagickFalse,argv[i+1]);
7513 break;
7514 }
cristyecb10ff2011-03-22 13:14:03 +00007515 if (LocaleCompare("duplicate",option+1) == 0)
7516 {
cristy72988482011-03-29 16:34:38 +00007517 Image
7518 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007519
anthony2b6bcae2011-03-23 13:05:34 +00007520 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007521 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7522 else
7523 {
7524 const char
7525 *p;
7526
anthony2b6bcae2011-03-23 13:05:34 +00007527 size_t
7528 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007529
anthony2b6bcae2011-03-23 13:05:34 +00007530 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007531 p=strchr(argv[i+1],',');
7532 if (p == (const char *) NULL)
7533 duplicate_images=DuplicateImages(*images,number_duplicates,
7534 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007535 else
cristy72988482011-03-29 16:34:38 +00007536 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7537 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007538 }
7539 AppendImageToList(images, duplicate_images);
7540 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007541 break;
7542 }
cristy3ed852e2009-09-05 21:47:34 +00007543 break;
7544 }
cristyd18ae7c2010-03-07 17:39:52 +00007545 case 'e':
7546 {
7547 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7548 {
7549 Image
7550 *evaluate_image;
7551
7552 MagickEvaluateOperator
7553 op;
7554
cristy6b3da3a2010-06-20 02:21:46 +00007555 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007556 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007557 MagickFalse,argv[i+1]);
7558 evaluate_image=EvaluateImages(*images,op,exception);
7559 if (evaluate_image == (Image *) NULL)
7560 {
7561 status=MagickFalse;
7562 break;
7563 }
7564 *images=DestroyImageList(*images);
7565 *images=evaluate_image;
7566 break;
7567 }
7568 break;
7569 }
cristy3ed852e2009-09-05 21:47:34 +00007570 case 'f':
7571 {
cristyf0a247f2009-10-04 00:20:03 +00007572 if (LocaleCompare("fft",option+1) == 0)
7573 {
7574 Image
7575 *fourier_image;
7576
7577 /*
7578 Implements the discrete Fourier transform (DFT).
7579 */
cristy6b3da3a2010-06-20 02:21:46 +00007580 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007581 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7582 MagickTrue : MagickFalse,exception);
7583 if (fourier_image == (Image *) NULL)
7584 break;
7585 *images=DestroyImage(*images);
7586 *images=fourier_image;
7587 break;
7588 }
cristy3ed852e2009-09-05 21:47:34 +00007589 if (LocaleCompare("flatten",option+1) == 0)
7590 {
7591 Image
7592 *flatten_image;
7593
cristy6b3da3a2010-06-20 02:21:46 +00007594 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007595 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7596 if (flatten_image == (Image *) NULL)
7597 break;
7598 *images=DestroyImageList(*images);
7599 *images=flatten_image;
7600 break;
7601 }
7602 if (LocaleCompare("fx",option+1) == 0)
7603 {
7604 Image
7605 *fx_image;
7606
cristy6b3da3a2010-06-20 02:21:46 +00007607 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007608 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007609 if (fx_image == (Image *) NULL)
7610 {
7611 status=MagickFalse;
7612 break;
7613 }
7614 *images=DestroyImageList(*images);
7615 *images=fx_image;
7616 break;
7617 }
7618 break;
7619 }
7620 case 'h':
7621 {
7622 if (LocaleCompare("hald-clut",option+1) == 0)
7623 {
7624 Image
7625 *hald_image,
7626 *image;
7627
cristy6b3da3a2010-06-20 02:21:46 +00007628 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007629 image=RemoveFirstImageFromList(images);
7630 hald_image=RemoveFirstImageFromList(images);
7631 if (hald_image == (Image *) NULL)
7632 {
7633 status=MagickFalse;
7634 break;
7635 }
cristyf89cb1d2011-07-07 01:24:37 +00007636 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007637 hald_image=DestroyImage(hald_image);
7638 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007639 if (*images != (Image *) NULL)
7640 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007641 *images=image;
7642 break;
7643 }
7644 break;
7645 }
7646 case 'i':
7647 {
7648 if (LocaleCompare("ift",option+1) == 0)
7649 {
7650 Image
cristy8587f882009-11-13 20:28:49 +00007651 *fourier_image,
7652 *magnitude_image,
7653 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007654
7655 /*
7656 Implements the inverse fourier discrete Fourier transform (DFT).
7657 */
cristy6b3da3a2010-06-20 02:21:46 +00007658 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007659 magnitude_image=RemoveFirstImageFromList(images);
7660 phase_image=RemoveFirstImageFromList(images);
7661 if (phase_image == (Image *) NULL)
7662 {
7663 status=MagickFalse;
7664 break;
7665 }
7666 fourier_image=InverseFourierTransformImage(magnitude_image,
7667 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007668 if (fourier_image == (Image *) NULL)
7669 break;
cristy0aff6ea2009-11-14 01:40:53 +00007670 if (*images != (Image *) NULL)
7671 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007672 *images=fourier_image;
7673 break;
7674 }
7675 if (LocaleCompare("insert",option+1) == 0)
7676 {
7677 Image
7678 *p,
7679 *q;
7680
7681 index=0;
7682 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007683 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007684 p=RemoveLastImageFromList(images);
7685 if (p == (Image *) NULL)
7686 {
7687 (void) ThrowMagickException(exception,GetMagickModule(),
7688 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7689 status=MagickFalse;
7690 break;
7691 }
7692 q=p;
7693 if (index == 0)
7694 PrependImageToList(images,q);
7695 else
cristybb503372010-05-27 20:51:26 +00007696 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007697 AppendImageToList(images,q);
7698 else
7699 {
7700 q=GetImageFromList(*images,index-1);
7701 if (q == (Image *) NULL)
7702 {
7703 (void) ThrowMagickException(exception,GetMagickModule(),
7704 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7705 status=MagickFalse;
7706 break;
7707 }
7708 InsertImageInList(&q,p);
7709 }
7710 *images=GetFirstImageInList(q);
7711 break;
7712 }
7713 break;
7714 }
7715 case 'l':
7716 {
7717 if (LocaleCompare("layers",option+1) == 0)
7718 {
7719 Image
7720 *layers;
7721
7722 ImageLayerMethod
7723 method;
7724
cristy6b3da3a2010-06-20 02:21:46 +00007725 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007726 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007727 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007728 MagickFalse,argv[i+1]);
7729 switch (method)
7730 {
7731 case CoalesceLayer:
7732 {
7733 layers=CoalesceImages(*images,exception);
7734 break;
7735 }
7736 case CompareAnyLayer:
7737 case CompareClearLayer:
7738 case CompareOverlayLayer:
7739 default:
7740 {
cristy8a9106f2011-07-05 14:39:26 +00007741 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007742 break;
7743 }
7744 case MergeLayer:
7745 case FlattenLayer:
7746 case MosaicLayer:
7747 case TrimBoundsLayer:
7748 {
7749 layers=MergeImageLayers(*images,method,exception);
7750 break;
7751 }
7752 case DisposeLayer:
7753 {
7754 layers=DisposeImages(*images,exception);
7755 break;
7756 }
7757 case OptimizeImageLayer:
7758 {
7759 layers=OptimizeImageLayers(*images,exception);
7760 break;
7761 }
7762 case OptimizePlusLayer:
7763 {
7764 layers=OptimizePlusImageLayers(*images,exception);
7765 break;
7766 }
7767 case OptimizeTransLayer:
7768 {
7769 OptimizeImageTransparency(*images,exception);
7770 break;
7771 }
7772 case RemoveDupsLayer:
7773 {
7774 RemoveDuplicateLayers(images,exception);
7775 break;
7776 }
7777 case RemoveZeroLayer:
7778 {
7779 RemoveZeroDelayLayers(images,exception);
7780 break;
7781 }
7782 case OptimizeLayer:
7783 {
7784 /*
7785 General Purpose, GIF Animation Optimizer.
7786 */
7787 layers=CoalesceImages(*images,exception);
7788 if (layers == (Image *) NULL)
7789 {
7790 status=MagickFalse;
7791 break;
7792 }
7793 InheritException(exception,&layers->exception);
7794 *images=DestroyImageList(*images);
7795 *images=layers;
7796 layers=OptimizeImageLayers(*images,exception);
7797 if (layers == (Image *) NULL)
7798 {
7799 status=MagickFalse;
7800 break;
7801 }
7802 InheritException(exception,&layers->exception);
7803 *images=DestroyImageList(*images);
7804 *images=layers;
7805 layers=(Image *) NULL;
7806 OptimizeImageTransparency(*images,exception);
7807 InheritException(exception,&(*images)->exception);
7808 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7809 break;
7810 }
7811 case CompositeLayer:
7812 {
7813 CompositeOperator
7814 compose;
7815
7816 Image
7817 *source;
7818
7819 RectangleInfo
7820 geometry;
7821
7822 /*
7823 Split image sequence at the first 'NULL:' image.
7824 */
7825 source=(*images);
7826 while (source != (Image *) NULL)
7827 {
7828 source=GetNextImageInList(source);
7829 if ((source != (Image *) NULL) &&
7830 (LocaleCompare(source->magick,"NULL") == 0))
7831 break;
7832 }
7833 if (source != (Image *) NULL)
7834 {
7835 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7836 (GetNextImageInList(source) == (Image *) NULL))
7837 source=(Image *) NULL;
7838 else
7839 {
7840 /*
7841 Separate the two lists, junk the null: image.
7842 */
7843 source=SplitImageList(source->previous);
7844 DeleteImageFromList(&source);
7845 }
7846 }
7847 if (source == (Image *) NULL)
7848 {
7849 (void) ThrowMagickException(exception,GetMagickModule(),
7850 OptionError,"MissingNullSeparator","layers Composite");
7851 status=MagickFalse;
7852 break;
7853 }
7854 /*
7855 Adjust offset with gravity and virtual canvas.
7856 */
7857 SetGeometry(*images,&geometry);
7858 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7859 geometry.width=source->page.width != 0 ?
7860 source->page.width : source->columns;
7861 geometry.height=source->page.height != 0 ?
7862 source->page.height : source->rows;
7863 GravityAdjustGeometry((*images)->page.width != 0 ?
7864 (*images)->page.width : (*images)->columns,
7865 (*images)->page.height != 0 ? (*images)->page.height :
7866 (*images)->rows,(*images)->gravity,&geometry);
7867 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007868 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007869 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007870 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007871 MagickComposeOptions,MagickFalse,option);
7872 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7873 exception);
7874 source=DestroyImageList(source);
7875 break;
7876 }
7877 }
7878 if (layers == (Image *) NULL)
7879 break;
7880 InheritException(exception,&layers->exception);
7881 *images=DestroyImageList(*images);
7882 *images=layers;
7883 break;
7884 }
7885 break;
7886 }
7887 case 'm':
7888 {
7889 if (LocaleCompare("map",option+1) == 0)
7890 {
cristy6b3da3a2010-06-20 02:21:46 +00007891 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007892 if (*option == '+')
7893 {
7894 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7895 InheritException(exception,&(*images)->exception);
7896 break;
7897 }
7898 i++;
7899 break;
7900 }
cristyf40785b2010-03-06 02:27:27 +00007901 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007902 {
7903 Image
cristyf40785b2010-03-06 02:27:27 +00007904 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007905
cristyd18ae7c2010-03-07 17:39:52 +00007906 /*
7907 Maximum image sequence (deprecated).
7908 */
cristy6b3da3a2010-06-20 02:21:46 +00007909 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007910 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007911 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007912 {
7913 status=MagickFalse;
7914 break;
7915 }
7916 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007917 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007918 break;
7919 }
cristyf40785b2010-03-06 02:27:27 +00007920 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007921 {
7922 Image
cristyf40785b2010-03-06 02:27:27 +00007923 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007924
cristyd18ae7c2010-03-07 17:39:52 +00007925 /*
7926 Minimum image sequence (deprecated).
7927 */
cristy6b3da3a2010-06-20 02:21:46 +00007928 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007929 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007930 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007931 {
7932 status=MagickFalse;
7933 break;
7934 }
7935 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007936 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007937 break;
7938 }
cristy3ed852e2009-09-05 21:47:34 +00007939 if (LocaleCompare("morph",option+1) == 0)
7940 {
7941 Image
7942 *morph_image;
7943
cristy6b3da3a2010-06-20 02:21:46 +00007944 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007945 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007946 exception);
7947 if (morph_image == (Image *) NULL)
7948 {
7949 status=MagickFalse;
7950 break;
7951 }
7952 *images=DestroyImageList(*images);
7953 *images=morph_image;
7954 break;
7955 }
7956 if (LocaleCompare("mosaic",option+1) == 0)
7957 {
7958 Image
7959 *mosaic_image;
7960
cristy6b3da3a2010-06-20 02:21:46 +00007961 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007962 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7963 if (mosaic_image == (Image *) NULL)
7964 {
7965 status=MagickFalse;
7966 break;
7967 }
7968 *images=DestroyImageList(*images);
7969 *images=mosaic_image;
7970 break;
7971 }
7972 break;
7973 }
7974 case 'p':
7975 {
7976 if (LocaleCompare("print",option+1) == 0)
7977 {
7978 char
7979 *string;
7980
cristy6b3da3a2010-06-20 02:21:46 +00007981 (void) SyncImagesSettings(mogrify_info,*images);
7982 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007983 if (string == (char *) NULL)
7984 break;
7985 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007986 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007987 string=DestroyString(string);
7988 }
7989 if (LocaleCompare("process",option+1) == 0)
7990 {
7991 char
7992 **arguments;
7993
7994 int
7995 j,
7996 number_arguments;
7997
cristy6b3da3a2010-06-20 02:21:46 +00007998 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007999 arguments=StringToArgv(argv[i+1],&number_arguments);
8000 if (arguments == (char **) NULL)
8001 break;
8002 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8003 {
8004 char
8005 breaker,
8006 quote,
8007 *token;
8008
8009 const char
8010 *arguments;
8011
8012 int
8013 next,
8014 status;
8015
8016 size_t
8017 length;
8018
8019 TokenInfo
8020 *token_info;
8021
8022 /*
8023 Support old style syntax, filter="-option arg".
8024 */
8025 length=strlen(argv[i+1]);
8026 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008027 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008028 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8029 sizeof(*token));
8030 if (token == (char *) NULL)
8031 break;
8032 next=0;
8033 arguments=argv[i+1];
8034 token_info=AcquireTokenInfo();
8035 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8036 "\"",'\0',&breaker,&next,&quote);
8037 token_info=DestroyTokenInfo(token_info);
8038 if (status == 0)
8039 {
8040 const char
8041 *argv;
8042
8043 argv=(&(arguments[next]));
8044 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8045 exception);
8046 }
8047 token=DestroyString(token);
8048 break;
8049 }
cristy91c0da22010-05-02 01:44:07 +00008050 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008051 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8052 number_arguments-2,(const char **) arguments+2,exception);
8053 for (j=0; j < number_arguments; j++)
8054 arguments[j]=DestroyString(arguments[j]);
8055 arguments=(char **) RelinquishMagickMemory(arguments);
8056 break;
8057 }
8058 break;
8059 }
8060 case 'r':
8061 {
8062 if (LocaleCompare("reverse",option+1) == 0)
8063 {
8064 ReverseImageList(images);
8065 InheritException(exception,&(*images)->exception);
8066 break;
8067 }
8068 break;
8069 }
8070 case 's':
8071 {
cristy4285d782011-02-09 20:12:28 +00008072 if (LocaleCompare("smush",option+1) == 0)
8073 {
8074 Image
8075 *smush_image;
8076
8077 ssize_t
8078 offset;
8079
8080 (void) SyncImagesSettings(mogrify_info,*images);
8081 offset=(ssize_t) StringToLong(argv[i+1]);
8082 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8083 MagickFalse,offset,exception);
8084 if (smush_image == (Image *) NULL)
8085 {
8086 status=MagickFalse;
8087 break;
8088 }
8089 *images=DestroyImageList(*images);
8090 *images=smush_image;
8091 break;
8092 }
cristy3ed852e2009-09-05 21:47:34 +00008093 if (LocaleCompare("swap",option+1) == 0)
8094 {
8095 Image
8096 *p,
8097 *q,
8098 *swap;
8099
cristybb503372010-05-27 20:51:26 +00008100 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008101 swap_index;
8102
8103 index=(-1);
8104 swap_index=(-2);
8105 if (*option != '+')
8106 {
8107 GeometryInfo
8108 geometry_info;
8109
8110 MagickStatusType
8111 flags;
8112
8113 swap_index=(-1);
8114 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008115 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008116 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008117 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008118 }
8119 p=GetImageFromList(*images,index);
8120 q=GetImageFromList(*images,swap_index);
8121 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8122 {
8123 (void) ThrowMagickException(exception,GetMagickModule(),
8124 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8125 status=MagickFalse;
8126 break;
8127 }
8128 if (p == q)
8129 break;
8130 swap=CloneImage(p,0,0,MagickTrue,exception);
8131 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8132 ReplaceImageInList(&q,swap);
8133 *images=GetFirstImageInList(q);
8134 break;
8135 }
8136 break;
8137 }
8138 case 'w':
8139 {
8140 if (LocaleCompare("write",option+1) == 0)
8141 {
cristy071dd7b2010-04-09 13:04:54 +00008142 char
cristy06609ee2010-03-17 20:21:27 +00008143 key[MaxTextExtent];
8144
cristy3ed852e2009-09-05 21:47:34 +00008145 Image
8146 *write_images;
8147
8148 ImageInfo
8149 *write_info;
8150
cristy6b3da3a2010-06-20 02:21:46 +00008151 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008152 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008153 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008154 write_images=(*images);
8155 if (*option == '+')
8156 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008157 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008158 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8159 write_info=DestroyImageInfo(write_info);
8160 if (*option == '+')
8161 write_images=DestroyImageList(write_images);
8162 break;
8163 }
8164 break;
8165 }
8166 default:
8167 break;
8168 }
8169 i+=count;
8170 }
8171 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008172 mogrify_info=DestroyImageInfo(mogrify_info);
8173 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008174 return(status != 0 ? MagickTrue : MagickFalse);
8175}
8176
8177/*
8178%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8179% %
8180% %
8181% %
8182+ M o g r i f y I m a g e s %
8183% %
8184% %
8185% %
8186%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8187%
8188% MogrifyImages() applies image processing options to a sequence of images as
8189% prescribed by command line options.
8190%
8191% The format of the MogrifyImage method is:
8192%
8193% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8194% const MagickBooleanType post,const int argc,const char **argv,
8195% Image **images,Exceptioninfo *exception)
8196%
8197% A description of each parameter follows:
8198%
8199% o image_info: the image info..
8200%
8201% o post: If true, post process image list operators otherwise pre-process.
8202%
8203% o argc: Specifies a pointer to an integer describing the number of
8204% elements in the argument vector.
8205%
8206% o argv: Specifies a pointer to a text array containing the command line
8207% arguments.
8208%
anthonye9c27192011-03-27 08:07:06 +00008209% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008210%
8211% o exception: return any errors or warnings in this structure.
8212%
8213*/
8214WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8215 const MagickBooleanType post,const int argc,const char **argv,
8216 Image **images,ExceptionInfo *exception)
8217{
8218#define MogrifyImageTag "Mogrify/Image"
8219
anthonye9c27192011-03-27 08:07:06 +00008220 MagickStatusType
8221 status;
cristy3ed852e2009-09-05 21:47:34 +00008222
cristy0e9f9c12010-02-11 03:00:47 +00008223 MagickBooleanType
8224 proceed;
8225
anthonye9c27192011-03-27 08:07:06 +00008226 size_t
8227 n;
cristy3ed852e2009-09-05 21:47:34 +00008228
cristybb503372010-05-27 20:51:26 +00008229 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008230 i;
8231
cristy3ed852e2009-09-05 21:47:34 +00008232 assert(image_info != (ImageInfo *) NULL);
8233 assert(image_info->signature == MagickSignature);
8234 if (images == (Image **) NULL)
8235 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008236 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008237 assert((*images)->signature == MagickSignature);
8238 if ((*images)->debug != MagickFalse)
8239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8240 (*images)->filename);
8241 if ((argc <= 0) || (*argv == (char *) NULL))
8242 return(MagickTrue);
8243 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8244 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008245 status=0;
anthonye9c27192011-03-27 08:07:06 +00008246
anthonyce2716b2011-04-22 09:51:34 +00008247#if 0
cristy1e604812011-05-19 18:07:50 +00008248 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8249 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008250#endif
8251
anthonye9c27192011-03-27 08:07:06 +00008252 /*
8253 Pre-process multi-image sequence operators
8254 */
cristy3ed852e2009-09-05 21:47:34 +00008255 if (post == MagickFalse)
8256 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008257 /*
8258 For each image, process simple single image operators
8259 */
8260 i=0;
8261 n=GetImageListLength(*images);
8262 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008263 {
anthonyce2716b2011-04-22 09:51:34 +00008264#if 0
cristy1e604812011-05-19 18:07:50 +00008265 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8266 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008267#endif
anthonye9c27192011-03-27 08:07:06 +00008268 status&=MogrifyImage(image_info,argc,argv,images,exception);
8269 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008270 if (proceed == MagickFalse)
8271 break;
anthonye9c27192011-03-27 08:07:06 +00008272 if ( (*images)->next == (Image *) NULL )
8273 break;
8274 *images=(*images)->next;
8275 i++;
cristy3ed852e2009-09-05 21:47:34 +00008276 }
anthonye9c27192011-03-27 08:07:06 +00008277 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008278#if 0
cristy1e604812011-05-19 18:07:50 +00008279 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8280 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008281#endif
anthonye9c27192011-03-27 08:07:06 +00008282
8283 /*
8284 Post-process, multi-image sequence operators
8285 */
8286 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008287 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008288 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008289 return(status != 0 ? MagickTrue : MagickFalse);
8290}