blob: cd98ab47b96220273d6abd886550b42d7d3dc027 [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*/
387static Image *SparseColorOption(const Image *image,const ChannelType channel,
388 const SparseColorMethod method,const char *arguments,
389 const MagickBooleanType color_from_image,ExceptionInfo *exception)
390{
391 ChannelType
392 channels;
393
394 char
395 token[MaxTextExtent];
396
397 const char
398 *p;
399
400 double
401 *sparse_arguments;
402
anthonydf8ebac2011-04-27 09:03:19 +0000403 Image
404 *sparse_image;
405
cristy4c08aed2011-07-01 19:47:50 +0000406 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000407 color;
408
409 MagickBooleanType
410 error;
411
cristy5f09d852011-05-29 01:39:29 +0000412 register size_t
413 x;
414
415 size_t
416 number_arguments,
417 number_colors;
418
anthonydf8ebac2011-04-27 09:03:19 +0000419 assert(image != (Image *) NULL);
420 assert(image->signature == MagickSignature);
421 if (image->debug != MagickFalse)
422 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
423 assert(exception != (ExceptionInfo *) NULL);
424 assert(exception->signature == MagickSignature);
425 /*
426 Limit channels according to image - and add up number of color channel.
427 */
428 channels=channel;
429 if (image->colorspace != CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +0000430 channels=(ChannelType) (channels & ~BlackChannel); /* no black channel */
anthonydf8ebac2011-04-27 09:03:19 +0000431 if (image->matte == MagickFalse)
432 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
433 number_colors=0;
434 if ((channels & RedChannel) != 0)
435 number_colors++;
436 if ((channels & GreenChannel) != 0)
437 number_colors++;
438 if ((channels & BlueChannel) != 0)
439 number_colors++;
cristy4c08aed2011-07-01 19:47:50 +0000440 if ((channels & BlackChannel) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000441 number_colors++;
442 if ((channels & OpacityChannel) != 0)
443 number_colors++;
444
445 /*
446 Read string, to determine number of arguments needed,
447 */
448 p=arguments;
449 x=0;
450 while( *p != '\0' )
451 {
452 GetMagickToken(p,&p,token);
453 if ( token[0] == ',' ) continue;
454 if ( isalpha((int) token[0]) || token[0] == '#' ) {
455 if ( color_from_image ) {
456 (void) ThrowMagickException(exception,GetMagickModule(),
457 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
458 "Color arg given, when colors are coming from image");
459 return( (Image *)NULL);
460 }
461 x += number_colors; /* color argument */
462 }
463 else {
464 x++; /* floating point argument */
465 }
466 }
467 error=MagickTrue;
468 if ( color_from_image ) {
469 /* just the control points are being given */
470 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
471 number_arguments=(x/2)*(2+number_colors);
472 }
473 else {
474 /* control points and color values */
475 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
476 number_arguments=x;
477 }
478 if ( error ) {
479 (void) ThrowMagickException(exception,GetMagickModule(),
480 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
481 "Invalid number of Arguments");
482 return( (Image *)NULL);
483 }
484
485 /* Allocate and fill in the floating point arguments */
486 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
487 sizeof(*sparse_arguments));
488 if (sparse_arguments == (double *) NULL) {
489 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
490 "MemoryAllocationFailed","%s","SparseColorOption");
491 return( (Image *)NULL);
492 }
493 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
494 sizeof(*sparse_arguments));
495 p=arguments;
496 x=0;
497 while( *p != '\0' && x < number_arguments ) {
498 /* X coordinate */
499 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
500 if ( token[0] == '\0' ) break;
501 if ( isalpha((int) token[0]) || token[0] == '#' ) {
502 (void) ThrowMagickException(exception,GetMagickModule(),
503 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
504 "Color found, instead of X-coord");
505 error = MagickTrue;
506 break;
507 }
cristyc1acd842011-05-19 23:05:47 +0000508 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000509 /* Y coordinate */
510 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
511 if ( token[0] == '\0' ) break;
512 if ( isalpha((int) token[0]) || token[0] == '#' ) {
513 (void) ThrowMagickException(exception,GetMagickModule(),
514 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
515 "Color found, instead of Y-coord");
516 error = MagickTrue;
517 break;
518 }
cristyc1acd842011-05-19 23:05:47 +0000519 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000520 /* color values for this control point */
521#if 0
522 if ( (color_from_image ) {
523 /* get color from image */
524 /* HOW??? */
525 }
526 else
527#endif
528 {
529 /* color name or function given in string argument */
530 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
531 if ( token[0] == '\0' ) break;
532 if ( isalpha((int) token[0]) || token[0] == '#' ) {
533 /* Color string given */
534 (void) QueryMagickColor(token,&color,exception);
cristy4c08aed2011-07-01 19:47:50 +0000535 if (channels & RedChannel)
anthonydf8ebac2011-04-27 09:03:19 +0000536 sparse_arguments[x++] = QuantumScale*color.red;
cristy4c08aed2011-07-01 19:47:50 +0000537 if (channels & GreenChannel)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.green;
cristy4c08aed2011-07-01 19:47:50 +0000539 if (channels & BlueChannel)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.blue;
cristy4c08aed2011-07-01 19:47:50 +0000541 if (channels & BlackChannel)
542 sparse_arguments[x++] = QuantumScale*color.black;
543 if (channels & OpacityChannel)
544 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000545 }
546 else {
547 /* Colors given as a set of floating point values - experimental */
548 /* NB: token contains the first floating point value to use! */
549 if ( channels & RedChannel ) {
550 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
551 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
552 break;
cristyc1acd842011-05-19 23:05:47 +0000553 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000554 token[0] = ','; /* used this token - get another */
555 }
556 if ( channels & GreenChannel ) {
557 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
558 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
559 break;
cristyc1acd842011-05-19 23:05:47 +0000560 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000561 token[0] = ','; /* used this token - get another */
562 }
563 if ( channels & BlueChannel ) {
564 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
565 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
566 break;
cristyc1acd842011-05-19 23:05:47 +0000567 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000568 token[0] = ','; /* used this token - get another */
569 }
cristy4c08aed2011-07-01 19:47:50 +0000570 if (channels & BlackChannel) {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
577 if ( channels & OpacityChannel ) {
578 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
579 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
580 break;
cristyc1acd842011-05-19 23:05:47 +0000581 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000582 token[0] = ','; /* used this token - get another */
583 }
584 }
585 }
586 }
587 if ( number_arguments != x && !error ) {
588 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
589 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
590 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
591 return( (Image *)NULL);
592 }
593 if ( error )
594 return( (Image *)NULL);
595
596 /* Call the Interpolation function with the parsed arguments */
597 sparse_image=SparseColorImage(image,channels,method,number_arguments,
598 sparse_arguments,exception);
599 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
600 return( sparse_image );
601}
602
cristy3ed852e2009-09-05 21:47:34 +0000603WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
604 const char **argv,Image **image,ExceptionInfo *exception)
605{
anthonydf8ebac2011-04-27 09:03:19 +0000606 ChannelType
607 channel;
608
609 const char
610 *format,
611 *option;
612
613 DrawInfo
614 *draw_info;
615
616 GeometryInfo
617 geometry_info;
618
cristy3ed852e2009-09-05 21:47:34 +0000619 Image
620 *region_image;
621
anthonydf8ebac2011-04-27 09:03:19 +0000622 ImageInfo
623 *mogrify_info;
624
cristyebbcfea2011-02-25 02:43:54 +0000625 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000626 status;
627
cristy4c08aed2011-07-01 19:47:50 +0000628 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000629 fill;
cristy3ed852e2009-09-05 21:47:34 +0000630
anthonydf8ebac2011-04-27 09:03:19 +0000631 MagickStatusType
632 flags;
633
634 QuantizeInfo
635 *quantize_info;
636
637 RectangleInfo
638 geometry,
639 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000640
cristybb503372010-05-27 20:51:26 +0000641 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000642 i;
643
644 /*
645 Initialize method variables.
646 */
647 assert(image_info != (const ImageInfo *) NULL);
648 assert(image_info->signature == MagickSignature);
649 assert(image != (Image **) NULL);
650 assert((*image)->signature == MagickSignature);
651 if ((*image)->debug != MagickFalse)
652 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
653 if (argc < 0)
654 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000655 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000656 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
657 quantize_info=AcquireQuantizeInfo(mogrify_info);
658 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000659 GetPixelInfo(*image,&fill);
660 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000661 channel=mogrify_info->channel;
662 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000663 SetGeometry(*image,&region_geometry);
664 region_image=NewImageList();
665 /*
666 Transmogrify the image.
667 */
cristybb503372010-05-27 20:51:26 +0000668 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000669 {
anthonydf8ebac2011-04-27 09:03:19 +0000670 Image
671 *mogrify_image;
672
anthonye9c27192011-03-27 08:07:06 +0000673 ssize_t
674 count;
675
anthonydf8ebac2011-04-27 09:03:19 +0000676 option=argv[i];
677 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000678 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000679 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
680 0L);
cristycee97112010-05-28 00:44:52 +0000681 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000682 break;
cristy6b3da3a2010-06-20 02:21:46 +0000683 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000684 mogrify_image=(Image *)NULL;
685 switch (*(option+1))
686 {
687 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000688 {
anthonydf8ebac2011-04-27 09:03:19 +0000689 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000690 {
anthonydf8ebac2011-04-27 09:03:19 +0000691 /*
692 Adaptive blur image.
693 */
694 (void) SyncImageSettings(mogrify_info,*image);
695 flags=ParseGeometry(argv[i+1],&geometry_info);
696 if ((flags & SigmaValue) == 0)
697 geometry_info.sigma=1.0;
698 mogrify_image=AdaptiveBlurImageChannel(*image,channel,
699 geometry_info.rho,geometry_info.sigma,exception);
700 break;
cristy3ed852e2009-09-05 21:47:34 +0000701 }
anthonydf8ebac2011-04-27 09:03:19 +0000702 if (LocaleCompare("adaptive-resize",option+1) == 0)
703 {
704 /*
705 Adaptive resize image.
706 */
707 (void) SyncImageSettings(mogrify_info,*image);
708 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
709 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
710 geometry.height,exception);
711 break;
712 }
713 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
714 {
715 /*
716 Adaptive sharpen image.
717 */
718 (void) SyncImageSettings(mogrify_info,*image);
719 flags=ParseGeometry(argv[i+1],&geometry_info);
720 if ((flags & SigmaValue) == 0)
721 geometry_info.sigma=1.0;
722 mogrify_image=AdaptiveSharpenImageChannel(*image,channel,
723 geometry_info.rho,geometry_info.sigma,exception);
724 break;
725 }
726 if (LocaleCompare("affine",option+1) == 0)
727 {
728 /*
729 Affine matrix.
730 */
731 if (*option == '+')
732 {
733 GetAffineMatrix(&draw_info->affine);
734 break;
735 }
736 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
737 break;
738 }
739 if (LocaleCompare("alpha",option+1) == 0)
740 {
741 AlphaChannelType
742 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000743
anthonydf8ebac2011-04-27 09:03:19 +0000744 (void) SyncImageSettings(mogrify_info,*image);
745 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
746 MagickFalse,argv[i+1]);
747 (void) SetImageAlphaChannel(*image,alpha_type);
748 InheritException(exception,&(*image)->exception);
749 break;
750 }
751 if (LocaleCompare("annotate",option+1) == 0)
752 {
753 char
754 *text,
755 geometry[MaxTextExtent];
756
757 /*
758 Annotate image.
759 */
760 (void) SyncImageSettings(mogrify_info,*image);
761 SetGeometryInfo(&geometry_info);
762 flags=ParseGeometry(argv[i+1],&geometry_info);
763 if ((flags & SigmaValue) == 0)
764 geometry_info.sigma=geometry_info.rho;
765 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
766 InheritException(exception,&(*image)->exception);
767 if (text == (char *) NULL)
768 break;
769 (void) CloneString(&draw_info->text,text);
770 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000771 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000772 geometry_info.xi,geometry_info.psi);
773 (void) CloneString(&draw_info->geometry,geometry);
774 draw_info->affine.sx=cos(DegreesToRadians(
775 fmod(geometry_info.rho,360.0)));
776 draw_info->affine.rx=sin(DegreesToRadians(
777 fmod(geometry_info.rho,360.0)));
778 draw_info->affine.ry=(-sin(DegreesToRadians(
779 fmod(geometry_info.sigma,360.0))));
780 draw_info->affine.sy=cos(DegreesToRadians(
781 fmod(geometry_info.sigma,360.0)));
782 (void) AnnotateImage(*image,draw_info);
783 InheritException(exception,&(*image)->exception);
784 break;
785 }
786 if (LocaleCompare("antialias",option+1) == 0)
787 {
788 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
789 MagickFalse;
790 draw_info->text_antialias=(*option == '-') ? MagickTrue :
791 MagickFalse;
792 break;
793 }
794 if (LocaleCompare("auto-gamma",option+1) == 0)
795 {
796 /*
797 Auto Adjust Gamma of image based on its mean
798 */
799 (void) SyncImageSettings(mogrify_info,*image);
cristyab015852011-07-06 01:03:32 +0000800 (void) AutoGammaImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +0000801 break;
802 }
803 if (LocaleCompare("auto-level",option+1) == 0)
804 {
805 /*
806 Perfectly Normalize (max/min stretch) the image
807 */
808 (void) SyncImageSettings(mogrify_info,*image);
cristyab015852011-07-06 01:03:32 +0000809 (void) AutoLevelImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +0000810 break;
811 }
812 if (LocaleCompare("auto-orient",option+1) == 0)
813 {
814 (void) SyncImageSettings(mogrify_info,*image);
815 switch ((*image)->orientation)
816 {
817 case TopRightOrientation:
818 {
819 mogrify_image=FlopImage(*image,exception);
820 break;
821 }
822 case BottomRightOrientation:
823 {
824 mogrify_image=RotateImage(*image,180.0,exception);
825 break;
826 }
827 case BottomLeftOrientation:
828 {
829 mogrify_image=FlipImage(*image,exception);
830 break;
831 }
832 case LeftTopOrientation:
833 {
834 mogrify_image=TransposeImage(*image,exception);
835 break;
836 }
837 case RightTopOrientation:
838 {
839 mogrify_image=RotateImage(*image,90.0,exception);
840 break;
841 }
842 case RightBottomOrientation:
843 {
844 mogrify_image=TransverseImage(*image,exception);
845 break;
846 }
847 case LeftBottomOrientation:
848 {
849 mogrify_image=RotateImage(*image,270.0,exception);
850 break;
851 }
852 default:
853 break;
854 }
855 if (mogrify_image != (Image *) NULL)
856 mogrify_image->orientation=TopLeftOrientation;
857 break;
858 }
859 break;
860 }
861 case 'b':
862 {
863 if (LocaleCompare("black-threshold",option+1) == 0)
864 {
865 /*
866 Black threshold image.
867 */
868 (void) SyncImageSettings(mogrify_info,*image);
869 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
870 exception);
871 InheritException(exception,&(*image)->exception);
872 break;
873 }
874 if (LocaleCompare("blue-shift",option+1) == 0)
875 {
876 /*
877 Blue shift image.
878 */
879 (void) SyncImageSettings(mogrify_info,*image);
880 geometry_info.rho=1.5;
881 if (*option == '-')
882 flags=ParseGeometry(argv[i+1],&geometry_info);
883 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
884 break;
885 }
886 if (LocaleCompare("blur",option+1) == 0)
887 {
888 /*
889 Gaussian blur image.
890 */
891 (void) SyncImageSettings(mogrify_info,*image);
892 flags=ParseGeometry(argv[i+1],&geometry_info);
893 if ((flags & SigmaValue) == 0)
894 geometry_info.sigma=1.0;
895 mogrify_image=BlurImageChannel(*image,channel,geometry_info.rho,
896 geometry_info.sigma,exception);
897 break;
898 }
899 if (LocaleCompare("border",option+1) == 0)
900 {
901 /*
902 Surround image with a border of solid color.
903 */
904 (void) SyncImageSettings(mogrify_info,*image);
905 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
906 if ((flags & SigmaValue) == 0)
907 geometry.height=geometry.width;
908 mogrify_image=BorderImage(*image,&geometry,exception);
909 break;
910 }
911 if (LocaleCompare("bordercolor",option+1) == 0)
912 {
913 if (*option == '+')
914 {
915 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
916 exception);
917 break;
918 }
919 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
920 exception);
921 break;
922 }
923 if (LocaleCompare("box",option+1) == 0)
924 {
925 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
926 exception);
927 break;
928 }
929 if (LocaleCompare("brightness-contrast",option+1) == 0)
930 {
931 double
932 brightness,
933 contrast;
934
935 GeometryInfo
936 geometry_info;
937
938 MagickStatusType
939 flags;
940
941 /*
942 Brightness / contrast image.
943 */
944 (void) SyncImageSettings(mogrify_info,*image);
945 flags=ParseGeometry(argv[i+1],&geometry_info);
946 brightness=geometry_info.rho;
947 contrast=0.0;
948 if ((flags & SigmaValue) != 0)
949 contrast=geometry_info.sigma;
cristy9ee60942011-07-06 14:54:38 +0000950 (void) BrightnessContrastImage(*image,brightness,contrast);
anthonydf8ebac2011-04-27 09:03:19 +0000951 InheritException(exception,&(*image)->exception);
952 break;
953 }
954 break;
955 }
956 case 'c':
957 {
958 if (LocaleCompare("cdl",option+1) == 0)
959 {
960 char
961 *color_correction_collection;
962
963 /*
964 Color correct with a color decision list.
965 */
966 (void) SyncImageSettings(mogrify_info,*image);
967 color_correction_collection=FileToString(argv[i+1],~0,exception);
968 if (color_correction_collection == (char *) NULL)
969 break;
970 (void) ColorDecisionListImage(*image,color_correction_collection);
971 InheritException(exception,&(*image)->exception);
972 break;
973 }
974 if (LocaleCompare("channel",option+1) == 0)
975 {
976 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000977 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000978 else
cristyfa806a72011-07-04 02:06:13 +0000979 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristy8a9106f2011-07-05 14:39:26 +0000980 SetPixelComponentMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000981 break;
982 }
983 if (LocaleCompare("charcoal",option+1) == 0)
984 {
985 /*
986 Charcoal image.
987 */
988 (void) SyncImageSettings(mogrify_info,*image);
989 flags=ParseGeometry(argv[i+1],&geometry_info);
990 if ((flags & SigmaValue) == 0)
991 geometry_info.sigma=1.0;
992 mogrify_image=CharcoalImage(*image,geometry_info.rho,
993 geometry_info.sigma,exception);
994 break;
995 }
996 if (LocaleCompare("chop",option+1) == 0)
997 {
998 /*
999 Chop the image.
1000 */
1001 (void) SyncImageSettings(mogrify_info,*image);
1002 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1003 mogrify_image=ChopImage(*image,&geometry,exception);
1004 break;
1005 }
1006 if (LocaleCompare("clamp",option+1) == 0)
1007 {
1008 /*
1009 Clamp image.
1010 */
1011 (void) SyncImageSettings(mogrify_info,*image);
1012 (void) ClampImageChannel(*image,channel);
1013 InheritException(exception,&(*image)->exception);
1014 break;
1015 }
1016 if (LocaleCompare("clip",option+1) == 0)
1017 {
1018 (void) SyncImageSettings(mogrify_info,*image);
1019 if (*option == '+')
1020 {
1021 (void) SetImageClipMask(*image,(Image *) NULL);
1022 InheritException(exception,&(*image)->exception);
1023 break;
1024 }
1025 (void) ClipImage(*image);
1026 InheritException(exception,&(*image)->exception);
1027 break;
1028 }
1029 if (LocaleCompare("clip-mask",option+1) == 0)
1030 {
1031 CacheView
1032 *mask_view;
1033
1034 Image
1035 *mask_image;
1036
cristy4c08aed2011-07-01 19:47:50 +00001037 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001038 *restrict q;
1039
1040 register ssize_t
1041 x;
1042
1043 ssize_t
1044 y;
1045
1046 (void) SyncImageSettings(mogrify_info,*image);
1047 if (*option == '+')
1048 {
1049 /*
1050 Remove a mask.
1051 */
1052 (void) SetImageMask(*image,(Image *) NULL);
1053 InheritException(exception,&(*image)->exception);
1054 break;
1055 }
1056 /*
1057 Set the image mask.
1058 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1059 */
1060 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1061 if (mask_image == (Image *) NULL)
1062 break;
1063 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1064 return(MagickFalse);
1065 mask_view=AcquireCacheView(mask_image);
1066 for (y=0; y < (ssize_t) mask_image->rows; y++)
1067 {
1068 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1069 exception);
cristy4c08aed2011-07-01 19:47:50 +00001070 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001071 break;
1072 for (x=0; x < (ssize_t) mask_image->columns; x++)
1073 {
1074 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001075 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1076 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1077 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1078 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
1079 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001080 }
1081 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1082 break;
1083 }
1084 mask_view=DestroyCacheView(mask_view);
1085 mask_image->matte=MagickTrue;
1086 (void) SetImageClipMask(*image,mask_image);
1087 mask_image=DestroyImage(mask_image);
1088 InheritException(exception,&(*image)->exception);
1089 break;
1090 }
1091 if (LocaleCompare("clip-path",option+1) == 0)
1092 {
1093 (void) SyncImageSettings(mogrify_info,*image);
1094 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1095 MagickFalse);
1096 InheritException(exception,&(*image)->exception);
1097 break;
1098 }
1099 if (LocaleCompare("colorize",option+1) == 0)
1100 {
1101 /*
1102 Colorize the image.
1103 */
1104 (void) SyncImageSettings(mogrify_info,*image);
1105 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1106 exception);
1107 break;
1108 }
1109 if (LocaleCompare("color-matrix",option+1) == 0)
1110 {
1111 KernelInfo
1112 *kernel;
1113
1114 (void) SyncImageSettings(mogrify_info,*image);
1115 kernel=AcquireKernelInfo(argv[i+1]);
1116 if (kernel == (KernelInfo *) NULL)
1117 break;
1118 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1119 kernel=DestroyKernelInfo(kernel);
1120 break;
1121 }
1122 if (LocaleCompare("colors",option+1) == 0)
1123 {
1124 /*
1125 Reduce the number of colors in the image.
1126 */
1127 (void) SyncImageSettings(mogrify_info,*image);
1128 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1129 if (quantize_info->number_colors == 0)
1130 break;
1131 if (((*image)->storage_class == DirectClass) ||
1132 (*image)->colors > quantize_info->number_colors)
1133 (void) QuantizeImage(quantize_info,*image);
1134 else
1135 (void) CompressImageColormap(*image);
1136 InheritException(exception,&(*image)->exception);
1137 break;
1138 }
1139 if (LocaleCompare("colorspace",option+1) == 0)
1140 {
1141 ColorspaceType
1142 colorspace;
1143
1144 (void) SyncImageSettings(mogrify_info,*image);
1145 if (*option == '+')
1146 {
1147 (void) TransformImageColorspace(*image,RGBColorspace);
1148 InheritException(exception,&(*image)->exception);
1149 break;
1150 }
1151 colorspace=(ColorspaceType) ParseCommandOption(
1152 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1153 (void) TransformImageColorspace(*image,colorspace);
1154 InheritException(exception,&(*image)->exception);
1155 break;
1156 }
1157 if (LocaleCompare("contrast",option+1) == 0)
1158 {
1159 (void) SyncImageSettings(mogrify_info,*image);
1160 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1161 MagickFalse);
1162 InheritException(exception,&(*image)->exception);
1163 break;
1164 }
1165 if (LocaleCompare("contrast-stretch",option+1) == 0)
1166 {
1167 double
1168 black_point,
1169 white_point;
1170
1171 MagickStatusType
1172 flags;
1173
1174 /*
1175 Contrast stretch image.
1176 */
1177 (void) SyncImageSettings(mogrify_info,*image);
1178 flags=ParseGeometry(argv[i+1],&geometry_info);
1179 black_point=geometry_info.rho;
1180 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1181 black_point;
1182 if ((flags & PercentValue) != 0)
1183 {
1184 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1185 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1186 }
1187 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1188 white_point;
cristy50fbc382011-07-07 02:19:17 +00001189 (void) ContrastStretchImage(*image,black_point,white_point);
anthonydf8ebac2011-04-27 09:03:19 +00001190 InheritException(exception,&(*image)->exception);
1191 break;
1192 }
1193 if (LocaleCompare("convolve",option+1) == 0)
1194 {
1195 double
1196 gamma;
1197
1198 KernelInfo
1199 *kernel;
1200
1201 register ssize_t
1202 j;
1203
1204 (void) SyncImageSettings(mogrify_info,*image);
1205 kernel=AcquireKernelInfo(argv[i+1]);
1206 if (kernel == (KernelInfo *) NULL)
1207 break;
1208 gamma=0.0;
1209 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1210 gamma+=kernel->values[j];
1211 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1212 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1213 kernel->values[j]*=gamma;
1214 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
1215 kernel=DestroyKernelInfo(kernel);
1216 break;
1217 }
1218 if (LocaleCompare("crop",option+1) == 0)
1219 {
1220 /*
1221 Crop a image to a smaller size
1222 */
1223 (void) SyncImageSettings(mogrify_info,*image);
1224#if 0
1225 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1226 if (((geometry.width != 0) || (geometry.height != 0)) &&
1227 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1228 break;
1229#endif
1230#if 0
1231 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1232 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1233 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1234 InheritException(exception,&mogrify_image->exception);
1235#else
1236 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1237#endif
1238 break;
1239 }
1240 if (LocaleCompare("cycle",option+1) == 0)
1241 {
1242 /*
1243 Cycle an image colormap.
1244 */
1245 (void) SyncImageSettings(mogrify_info,*image);
1246 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1247 InheritException(exception,&(*image)->exception);
1248 break;
1249 }
1250 break;
1251 }
1252 case 'd':
1253 {
1254 if (LocaleCompare("decipher",option+1) == 0)
1255 {
1256 StringInfo
1257 *passkey;
1258
1259 /*
1260 Decipher pixels.
1261 */
1262 (void) SyncImageSettings(mogrify_info,*image);
1263 passkey=FileToStringInfo(argv[i+1],~0,exception);
1264 if (passkey != (StringInfo *) NULL)
1265 {
1266 (void) PasskeyDecipherImage(*image,passkey,exception);
1267 passkey=DestroyStringInfo(passkey);
1268 }
1269 break;
1270 }
1271 if (LocaleCompare("density",option+1) == 0)
1272 {
1273 /*
1274 Set image density.
1275 */
1276 (void) CloneString(&draw_info->density,argv[i+1]);
1277 break;
1278 }
1279 if (LocaleCompare("depth",option+1) == 0)
1280 {
1281 (void) SyncImageSettings(mogrify_info,*image);
1282 if (*option == '+')
1283 {
1284 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1285 break;
1286 }
1287 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1288 break;
1289 }
1290 if (LocaleCompare("deskew",option+1) == 0)
1291 {
1292 double
1293 threshold;
1294
1295 /*
1296 Straighten the image.
1297 */
1298 (void) SyncImageSettings(mogrify_info,*image);
1299 if (*option == '+')
1300 threshold=40.0*QuantumRange/100.0;
1301 else
1302 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1303 mogrify_image=DeskewImage(*image,threshold,exception);
1304 break;
1305 }
1306 if (LocaleCompare("despeckle",option+1) == 0)
1307 {
1308 /*
1309 Reduce the speckles within an image.
1310 */
1311 (void) SyncImageSettings(mogrify_info,*image);
1312 mogrify_image=DespeckleImage(*image,exception);
1313 break;
1314 }
1315 if (LocaleCompare("display",option+1) == 0)
1316 {
1317 (void) CloneString(&draw_info->server_name,argv[i+1]);
1318 break;
1319 }
1320 if (LocaleCompare("distort",option+1) == 0)
1321 {
1322 char
1323 *args,
1324 token[MaxTextExtent];
1325
1326 const char
1327 *p;
1328
1329 DistortImageMethod
1330 method;
1331
1332 double
1333 *arguments;
1334
1335 register ssize_t
1336 x;
1337
1338 size_t
1339 number_arguments;
1340
1341 /*
1342 Distort image.
1343 */
1344 (void) SyncImageSettings(mogrify_info,*image);
1345 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1346 MagickFalse,argv[i+1]);
1347 if ( method == ResizeDistortion )
1348 {
1349 /* Special Case - Argument is actually a resize geometry!
1350 ** Convert that to an appropriate distortion argument array.
1351 */
1352 double
1353 resize_args[2];
1354 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1355 exception);
1356 resize_args[0]=(double)geometry.width;
1357 resize_args[1]=(double)geometry.height;
1358 mogrify_image=DistortImage(*image,method,(size_t)2,
1359 resize_args,MagickTrue,exception);
1360 break;
1361 }
1362 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1363 InheritException(exception,&(*image)->exception);
1364 if (args == (char *) NULL)
1365 break;
1366 p=(char *) args;
1367 for (x=0; *p != '\0'; x++)
1368 {
1369 GetMagickToken(p,&p,token);
1370 if (*token == ',')
1371 GetMagickToken(p,&p,token);
1372 }
1373 number_arguments=(size_t) x;
1374 arguments=(double *) AcquireQuantumMemory(number_arguments,
1375 sizeof(*arguments));
1376 if (arguments == (double *) NULL)
1377 ThrowWandFatalException(ResourceLimitFatalError,
1378 "MemoryAllocationFailed",(*image)->filename);
1379 (void) ResetMagickMemory(arguments,0,number_arguments*
1380 sizeof(*arguments));
1381 p=(char *) args;
1382 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1383 {
1384 GetMagickToken(p,&p,token);
1385 if (*token == ',')
1386 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001387 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001388 }
1389 args=DestroyString(args);
1390 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1391 (*option == '+') ? MagickTrue : MagickFalse,exception);
1392 arguments=(double *) RelinquishMagickMemory(arguments);
1393 break;
1394 }
1395 if (LocaleCompare("dither",option+1) == 0)
1396 {
1397 if (*option == '+')
1398 {
1399 quantize_info->dither=MagickFalse;
1400 break;
1401 }
1402 quantize_info->dither=MagickTrue;
1403 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1404 MagickDitherOptions,MagickFalse,argv[i+1]);
1405 if (quantize_info->dither_method == NoDitherMethod)
1406 quantize_info->dither=MagickFalse;
1407 break;
1408 }
1409 if (LocaleCompare("draw",option+1) == 0)
1410 {
1411 /*
1412 Draw image.
1413 */
1414 (void) SyncImageSettings(mogrify_info,*image);
1415 (void) CloneString(&draw_info->primitive,argv[i+1]);
1416 (void) DrawImage(*image,draw_info);
1417 InheritException(exception,&(*image)->exception);
1418 break;
1419 }
1420 break;
1421 }
1422 case 'e':
1423 {
1424 if (LocaleCompare("edge",option+1) == 0)
1425 {
1426 /*
1427 Enhance edges in the image.
1428 */
1429 (void) SyncImageSettings(mogrify_info,*image);
1430 flags=ParseGeometry(argv[i+1],&geometry_info);
1431 if ((flags & SigmaValue) == 0)
1432 geometry_info.sigma=1.0;
1433 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1434 break;
1435 }
1436 if (LocaleCompare("emboss",option+1) == 0)
1437 {
1438 /*
1439 Gaussian embossen image.
1440 */
1441 (void) SyncImageSettings(mogrify_info,*image);
1442 flags=ParseGeometry(argv[i+1],&geometry_info);
1443 if ((flags & SigmaValue) == 0)
1444 geometry_info.sigma=1.0;
1445 mogrify_image=EmbossImage(*image,geometry_info.rho,
1446 geometry_info.sigma,exception);
1447 break;
1448 }
1449 if (LocaleCompare("encipher",option+1) == 0)
1450 {
1451 StringInfo
1452 *passkey;
1453
1454 /*
1455 Encipher pixels.
1456 */
1457 (void) SyncImageSettings(mogrify_info,*image);
1458 passkey=FileToStringInfo(argv[i+1],~0,exception);
1459 if (passkey != (StringInfo *) NULL)
1460 {
1461 (void) PasskeyEncipherImage(*image,passkey,exception);
1462 passkey=DestroyStringInfo(passkey);
1463 }
1464 break;
1465 }
1466 if (LocaleCompare("encoding",option+1) == 0)
1467 {
1468 (void) CloneString(&draw_info->encoding,argv[i+1]);
1469 break;
1470 }
1471 if (LocaleCompare("enhance",option+1) == 0)
1472 {
1473 /*
1474 Enhance image.
1475 */
1476 (void) SyncImageSettings(mogrify_info,*image);
1477 mogrify_image=EnhanceImage(*image,exception);
1478 break;
1479 }
1480 if (LocaleCompare("equalize",option+1) == 0)
1481 {
1482 /*
1483 Equalize image.
1484 */
1485 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00001486 (void) EqualizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001487 InheritException(exception,&(*image)->exception);
1488 break;
1489 }
1490 if (LocaleCompare("evaluate",option+1) == 0)
1491 {
1492 double
1493 constant;
1494
1495 MagickEvaluateOperator
1496 op;
1497
1498 (void) SyncImageSettings(mogrify_info,*image);
1499 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
1500 MagickFalse,argv[i+1]);
1501 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
1502 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1503 break;
1504 }
1505 if (LocaleCompare("extent",option+1) == 0)
1506 {
1507 /*
1508 Set the image extent.
1509 */
1510 (void) SyncImageSettings(mogrify_info,*image);
1511 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1512 if (geometry.width == 0)
1513 geometry.width=(*image)->columns;
1514 if (geometry.height == 0)
1515 geometry.height=(*image)->rows;
1516 mogrify_image=ExtentImage(*image,&geometry,exception);
1517 break;
1518 }
1519 break;
1520 }
1521 case 'f':
1522 {
1523 if (LocaleCompare("family",option+1) == 0)
1524 {
1525 if (*option == '+')
1526 {
1527 if (draw_info->family != (char *) NULL)
1528 draw_info->family=DestroyString(draw_info->family);
1529 break;
1530 }
1531 (void) CloneString(&draw_info->family,argv[i+1]);
1532 break;
1533 }
1534 if (LocaleCompare("features",option+1) == 0)
1535 {
1536 if (*option == '+')
1537 {
1538 (void) DeleteImageArtifact(*image,"identify:features");
1539 break;
1540 }
1541 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1542 break;
1543 }
1544 if (LocaleCompare("fill",option+1) == 0)
1545 {
1546 ExceptionInfo
1547 *sans;
1548
cristy4c08aed2011-07-01 19:47:50 +00001549 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001550 if (*option == '+')
1551 {
1552 (void) QueryMagickColor("none",&fill,exception);
1553 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1554 if (draw_info->fill_pattern != (Image *) NULL)
1555 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1556 break;
1557 }
1558 sans=AcquireExceptionInfo();
1559 (void) QueryMagickColor(argv[i+1],&fill,sans);
1560 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1561 sans=DestroyExceptionInfo(sans);
1562 if (status == MagickFalse)
1563 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1564 exception);
1565 break;
1566 }
1567 if (LocaleCompare("flip",option+1) == 0)
1568 {
1569 /*
1570 Flip image scanlines.
1571 */
1572 (void) SyncImageSettings(mogrify_info,*image);
1573 mogrify_image=FlipImage(*image,exception);
1574 break;
1575 }
anthonydf8ebac2011-04-27 09:03:19 +00001576 if (LocaleCompare("floodfill",option+1) == 0)
1577 {
cristy4c08aed2011-07-01 19:47:50 +00001578 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001579 target;
1580
1581 /*
1582 Floodfill image.
1583 */
1584 (void) SyncImageSettings(mogrify_info,*image);
1585 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1586 (void) QueryMagickColor(argv[i+2],&target,exception);
1587 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1588 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1589 InheritException(exception,&(*image)->exception);
1590 break;
1591 }
anthony3d2f4862011-05-01 13:48:16 +00001592 if (LocaleCompare("flop",option+1) == 0)
1593 {
1594 /*
1595 Flop image scanlines.
1596 */
1597 (void) SyncImageSettings(mogrify_info,*image);
1598 mogrify_image=FlopImage(*image,exception);
1599 break;
1600 }
anthonydf8ebac2011-04-27 09:03:19 +00001601 if (LocaleCompare("font",option+1) == 0)
1602 {
1603 if (*option == '+')
1604 {
1605 if (draw_info->font != (char *) NULL)
1606 draw_info->font=DestroyString(draw_info->font);
1607 break;
1608 }
1609 (void) CloneString(&draw_info->font,argv[i+1]);
1610 break;
1611 }
1612 if (LocaleCompare("format",option+1) == 0)
1613 {
1614 format=argv[i+1];
1615 break;
1616 }
1617 if (LocaleCompare("frame",option+1) == 0)
1618 {
1619 FrameInfo
1620 frame_info;
1621
1622 /*
1623 Surround image with an ornamental border.
1624 */
1625 (void) SyncImageSettings(mogrify_info,*image);
1626 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1627 frame_info.width=geometry.width;
1628 frame_info.height=geometry.height;
1629 if ((flags & HeightValue) == 0)
1630 frame_info.height=geometry.width;
1631 frame_info.outer_bevel=geometry.x;
1632 frame_info.inner_bevel=geometry.y;
1633 frame_info.x=(ssize_t) frame_info.width;
1634 frame_info.y=(ssize_t) frame_info.height;
1635 frame_info.width=(*image)->columns+2*frame_info.width;
1636 frame_info.height=(*image)->rows+2*frame_info.height;
1637 mogrify_image=FrameImage(*image,&frame_info,exception);
1638 break;
1639 }
1640 if (LocaleCompare("function",option+1) == 0)
1641 {
1642 char
1643 *arguments,
1644 token[MaxTextExtent];
1645
1646 const char
1647 *p;
1648
1649 double
1650 *parameters;
1651
1652 MagickFunction
1653 function;
1654
1655 register ssize_t
1656 x;
1657
1658 size_t
1659 number_parameters;
1660
1661 /*
1662 Function Modify Image Values
1663 */
1664 (void) SyncImageSettings(mogrify_info,*image);
1665 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1666 MagickFalse,argv[i+1]);
1667 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1668 InheritException(exception,&(*image)->exception);
1669 if (arguments == (char *) NULL)
1670 break;
1671 p=(char *) arguments;
1672 for (x=0; *p != '\0'; x++)
1673 {
1674 GetMagickToken(p,&p,token);
1675 if (*token == ',')
1676 GetMagickToken(p,&p,token);
1677 }
1678 number_parameters=(size_t) x;
1679 parameters=(double *) AcquireQuantumMemory(number_parameters,
1680 sizeof(*parameters));
1681 if (parameters == (double *) NULL)
1682 ThrowWandFatalException(ResourceLimitFatalError,
1683 "MemoryAllocationFailed",(*image)->filename);
1684 (void) ResetMagickMemory(parameters,0,number_parameters*
1685 sizeof(*parameters));
1686 p=(char *) arguments;
1687 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1688 {
1689 GetMagickToken(p,&p,token);
1690 if (*token == ',')
1691 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001692 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001693 }
1694 arguments=DestroyString(arguments);
1695 (void) FunctionImageChannel(*image,channel,function,
1696 number_parameters,parameters,exception);
1697 parameters=(double *) RelinquishMagickMemory(parameters);
1698 break;
1699 }
1700 break;
1701 }
1702 case 'g':
1703 {
1704 if (LocaleCompare("gamma",option+1) == 0)
1705 {
1706 /*
1707 Gamma image.
1708 */
1709 (void) SyncImageSettings(mogrify_info,*image);
1710 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001711 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001712 else
1713 {
cristy50fbc382011-07-07 02:19:17 +00001714 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1715 (char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001716 InheritException(exception,&(*image)->exception);
1717 }
1718 break;
1719 }
1720 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1721 (LocaleCompare("gaussian",option+1) == 0))
1722 {
1723 /*
1724 Gaussian blur image.
1725 */
1726 (void) SyncImageSettings(mogrify_info,*image);
1727 flags=ParseGeometry(argv[i+1],&geometry_info);
1728 if ((flags & SigmaValue) == 0)
1729 geometry_info.sigma=1.0;
1730 mogrify_image=GaussianBlurImageChannel(*image,channel,
1731 geometry_info.rho,geometry_info.sigma,exception);
1732 break;
1733 }
1734 if (LocaleCompare("geometry",option+1) == 0)
1735 {
1736 /*
1737 Record Image offset, Resize last image.
1738 */
1739 (void) SyncImageSettings(mogrify_info,*image);
1740 if (*option == '+')
1741 {
1742 if ((*image)->geometry != (char *) NULL)
1743 (*image)->geometry=DestroyString((*image)->geometry);
1744 break;
1745 }
1746 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1747 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1748 (void) CloneString(&(*image)->geometry,argv[i+1]);
1749 else
1750 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1751 (*image)->filter,(*image)->blur,exception);
1752 break;
1753 }
1754 if (LocaleCompare("gravity",option+1) == 0)
1755 {
1756 if (*option == '+')
1757 {
1758 draw_info->gravity=UndefinedGravity;
1759 break;
1760 }
1761 draw_info->gravity=(GravityType) ParseCommandOption(
1762 MagickGravityOptions,MagickFalse,argv[i+1]);
1763 break;
1764 }
1765 break;
1766 }
1767 case 'h':
1768 {
1769 if (LocaleCompare("highlight-color",option+1) == 0)
1770 {
1771 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1772 break;
1773 }
1774 break;
1775 }
1776 case 'i':
1777 {
1778 if (LocaleCompare("identify",option+1) == 0)
1779 {
1780 char
1781 *text;
1782
1783 (void) SyncImageSettings(mogrify_info,*image);
1784 if (format == (char *) NULL)
1785 {
1786 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1787 InheritException(exception,&(*image)->exception);
1788 break;
1789 }
1790 text=InterpretImageProperties(mogrify_info,*image,format);
1791 InheritException(exception,&(*image)->exception);
1792 if (text == (char *) NULL)
1793 break;
1794 (void) fputs(text,stdout);
1795 (void) fputc('\n',stdout);
1796 text=DestroyString(text);
1797 break;
1798 }
1799 if (LocaleCompare("implode",option+1) == 0)
1800 {
1801 /*
1802 Implode image.
1803 */
1804 (void) SyncImageSettings(mogrify_info,*image);
1805 (void) ParseGeometry(argv[i+1],&geometry_info);
1806 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1807 break;
1808 }
1809 if (LocaleCompare("interline-spacing",option+1) == 0)
1810 {
1811 if (*option == '+')
1812 (void) ParseGeometry("0",&geometry_info);
1813 else
1814 (void) ParseGeometry(argv[i+1],&geometry_info);
1815 draw_info->interline_spacing=geometry_info.rho;
1816 break;
1817 }
1818 if (LocaleCompare("interword-spacing",option+1) == 0)
1819 {
1820 if (*option == '+')
1821 (void) ParseGeometry("0",&geometry_info);
1822 else
1823 (void) ParseGeometry(argv[i+1],&geometry_info);
1824 draw_info->interword_spacing=geometry_info.rho;
1825 break;
1826 }
1827 break;
1828 }
1829 case 'k':
1830 {
1831 if (LocaleCompare("kerning",option+1) == 0)
1832 {
1833 if (*option == '+')
1834 (void) ParseGeometry("0",&geometry_info);
1835 else
1836 (void) ParseGeometry(argv[i+1],&geometry_info);
1837 draw_info->kerning=geometry_info.rho;
1838 break;
1839 }
1840 break;
1841 }
1842 case 'l':
1843 {
1844 if (LocaleCompare("lat",option+1) == 0)
1845 {
1846 /*
1847 Local adaptive threshold image.
1848 */
1849 (void) SyncImageSettings(mogrify_info,*image);
1850 flags=ParseGeometry(argv[i+1],&geometry_info);
1851 if ((flags & PercentValue) != 0)
1852 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1853 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1854 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1855 geometry_info.xi,exception);
1856 break;
1857 }
1858 if (LocaleCompare("level",option+1) == 0)
1859 {
1860 MagickRealType
1861 black_point,
1862 gamma,
1863 white_point;
1864
1865 MagickStatusType
1866 flags;
1867
1868 /*
1869 Parse levels.
1870 */
1871 (void) SyncImageSettings(mogrify_info,*image);
1872 flags=ParseGeometry(argv[i+1],&geometry_info);
1873 black_point=geometry_info.rho;
1874 white_point=(MagickRealType) QuantumRange;
1875 if ((flags & SigmaValue) != 0)
1876 white_point=geometry_info.sigma;
1877 gamma=1.0;
1878 if ((flags & XiValue) != 0)
1879 gamma=geometry_info.xi;
1880 if ((flags & PercentValue) != 0)
1881 {
1882 black_point*=(MagickRealType) (QuantumRange/100.0);
1883 white_point*=(MagickRealType) (QuantumRange/100.0);
1884 }
1885 if ((flags & SigmaValue) == 0)
1886 white_point=(MagickRealType) QuantumRange-black_point;
1887 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy50fbc382011-07-07 02:19:17 +00001888 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001889 else
cristyf89cb1d2011-07-07 01:24:37 +00001890 (void) LevelImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001891 InheritException(exception,&(*image)->exception);
1892 break;
1893 }
1894 if (LocaleCompare("level-colors",option+1) == 0)
1895 {
1896 char
1897 token[MaxTextExtent];
1898
1899 const char
1900 *p;
1901
cristy4c08aed2011-07-01 19:47:50 +00001902 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001903 black_point,
1904 white_point;
1905
1906 p=(const char *) argv[i+1];
1907 GetMagickToken(p,&p,token); /* get black point color */
1908 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1909 (void) QueryMagickColor(token,&black_point,exception);
1910 else
1911 (void) QueryMagickColor("#000000",&black_point,exception);
1912 if (isalpha((int) token[0]) || (token[0] == '#'))
1913 GetMagickToken(p,&p,token);
1914 if (*token == '\0')
1915 white_point=black_point; /* set everything to that color */
1916 else
1917 {
1918 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1919 GetMagickToken(p,&p,token); /* Get white point color. */
1920 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1921 (void) QueryMagickColor(token,&white_point,exception);
1922 else
1923 (void) QueryMagickColor("#ffffff",&white_point,exception);
1924 }
cristy490408a2011-07-07 14:42:05 +00001925 (void) LevelImageColors(*image,&black_point,&white_point,
1926 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001927 break;
1928 }
1929 if (LocaleCompare("linear-stretch",option+1) == 0)
1930 {
1931 double
1932 black_point,
1933 white_point;
1934
1935 MagickStatusType
1936 flags;
1937
1938 (void) SyncImageSettings(mogrify_info,*image);
1939 flags=ParseGeometry(argv[i+1],&geometry_info);
1940 black_point=geometry_info.rho;
1941 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1942 if ((flags & SigmaValue) != 0)
1943 white_point=geometry_info.sigma;
1944 if ((flags & PercentValue) != 0)
1945 {
1946 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1947 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1948 }
1949 if ((flags & SigmaValue) == 0)
1950 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1951 black_point;
1952 (void) LinearStretchImage(*image,black_point,white_point);
1953 InheritException(exception,&(*image)->exception);
1954 break;
1955 }
1956 if (LocaleCompare("linewidth",option+1) == 0)
1957 {
cristyc1acd842011-05-19 23:05:47 +00001958 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1959 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001960 break;
1961 }
1962 if (LocaleCompare("liquid-rescale",option+1) == 0)
1963 {
1964 /*
1965 Liquid rescale image.
1966 */
1967 (void) SyncImageSettings(mogrify_info,*image);
1968 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1969 if ((flags & XValue) == 0)
1970 geometry.x=1;
1971 if ((flags & YValue) == 0)
1972 geometry.y=0;
1973 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1974 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1975 break;
1976 }
1977 if (LocaleCompare("lowlight-color",option+1) == 0)
1978 {
1979 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1980 break;
1981 }
1982 break;
1983 }
1984 case 'm':
1985 {
1986 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001987 {
cristy3ed852e2009-09-05 21:47:34 +00001988 Image
anthonydf8ebac2011-04-27 09:03:19 +00001989 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001990
anthonydf8ebac2011-04-27 09:03:19 +00001991 /*
1992 Transform image colors to match this set of colors.
1993 */
1994 (void) SyncImageSettings(mogrify_info,*image);
1995 if (*option == '+')
1996 break;
1997 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1998 if (remap_image == (Image *) NULL)
1999 break;
2000 (void) RemapImage(quantize_info,*image,remap_image);
2001 InheritException(exception,&(*image)->exception);
2002 remap_image=DestroyImage(remap_image);
2003 break;
2004 }
2005 if (LocaleCompare("mask",option+1) == 0)
2006 {
2007 Image
2008 *mask;
2009
2010 (void) SyncImageSettings(mogrify_info,*image);
2011 if (*option == '+')
2012 {
2013 /*
2014 Remove a mask.
2015 */
2016 (void) SetImageMask(*image,(Image *) NULL);
2017 InheritException(exception,&(*image)->exception);
2018 break;
2019 }
2020 /*
2021 Set the image mask.
2022 */
2023 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2024 if (mask == (Image *) NULL)
2025 break;
2026 (void) SetImageMask(*image,mask);
2027 mask=DestroyImage(mask);
2028 InheritException(exception,&(*image)->exception);
2029 break;
2030 }
2031 if (LocaleCompare("matte",option+1) == 0)
2032 {
2033 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2034 SetAlphaChannel : DeactivateAlphaChannel );
2035 InheritException(exception,&(*image)->exception);
2036 break;
2037 }
2038 if (LocaleCompare("median",option+1) == 0)
2039 {
2040 /*
2041 Median filter image.
2042 */
2043 (void) SyncImageSettings(mogrify_info,*image);
2044 (void) ParseGeometry(argv[i+1],&geometry_info);
2045 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
2046 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2047 break;
2048 }
2049 if (LocaleCompare("mode",option+1) == 0)
2050 {
2051 /*
2052 Mode image.
2053 */
2054 (void) SyncImageSettings(mogrify_info,*image);
2055 (void) ParseGeometry(argv[i+1],&geometry_info);
2056 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
2057 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2058 break;
2059 }
2060 if (LocaleCompare("modulate",option+1) == 0)
2061 {
2062 (void) SyncImageSettings(mogrify_info,*image);
2063 (void) ModulateImage(*image,argv[i+1]);
2064 InheritException(exception,&(*image)->exception);
2065 break;
2066 }
2067 if (LocaleCompare("monitor",option+1) == 0)
2068 {
2069 if (*option == '+')
2070 {
2071 (void) SetImageProgressMonitor(*image,
2072 (MagickProgressMonitor) NULL,(void *) NULL);
2073 break;
2074 }
2075 (void) SetImageProgressMonitor(*image,MonitorProgress,
2076 (void *) NULL);
2077 break;
2078 }
2079 if (LocaleCompare("monochrome",option+1) == 0)
2080 {
2081 (void) SyncImageSettings(mogrify_info,*image);
2082 (void) SetImageType(*image,BilevelType);
2083 InheritException(exception,&(*image)->exception);
2084 break;
2085 }
2086 if (LocaleCompare("morphology",option+1) == 0)
2087 {
2088 char
2089 token[MaxTextExtent];
2090
2091 const char
2092 *p;
2093
2094 KernelInfo
2095 *kernel;
2096
2097 MorphologyMethod
2098 method;
2099
2100 ssize_t
2101 iterations;
2102
2103 /*
2104 Morphological Image Operation
2105 */
2106 (void) SyncImageSettings(mogrify_info,*image);
2107 p=argv[i+1];
2108 GetMagickToken(p,&p,token);
2109 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2110 MagickFalse,token);
2111 iterations=1L;
2112 GetMagickToken(p,&p,token);
2113 if ((*p == ':') || (*p == ','))
2114 GetMagickToken(p,&p,token);
2115 if ((*p != '\0'))
2116 iterations=(ssize_t) StringToLong(p);
2117 kernel=AcquireKernelInfo(argv[i+2]);
2118 if (kernel == (KernelInfo *) NULL)
2119 {
2120 (void) ThrowMagickException(exception,GetMagickModule(),
2121 OptionError,"UnabletoParseKernel","morphology");
2122 status=MagickFalse;
2123 break;
2124 }
2125 mogrify_image=MorphologyImageChannel(*image,channel,method,
2126 iterations,kernel,exception);
2127 kernel=DestroyKernelInfo(kernel);
2128 break;
2129 }
2130 if (LocaleCompare("motion-blur",option+1) == 0)
2131 {
2132 /*
2133 Motion blur image.
2134 */
2135 (void) SyncImageSettings(mogrify_info,*image);
2136 flags=ParseGeometry(argv[i+1],&geometry_info);
2137 if ((flags & SigmaValue) == 0)
2138 geometry_info.sigma=1.0;
2139 mogrify_image=MotionBlurImageChannel(*image,channel,
2140 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2141 break;
2142 }
2143 break;
2144 }
2145 case 'n':
2146 {
2147 if (LocaleCompare("negate",option+1) == 0)
2148 {
2149 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002150 (void) NegateImage(*image,*option == '+' ? MagickTrue :
2151 MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00002152 InheritException(exception,&(*image)->exception);
2153 break;
2154 }
2155 if (LocaleCompare("noise",option+1) == 0)
2156 {
2157 (void) SyncImageSettings(mogrify_info,*image);
2158 if (*option == '-')
2159 {
2160 (void) ParseGeometry(argv[i+1],&geometry_info);
2161 mogrify_image=StatisticImageChannel(*image,channel,
2162 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2163 geometry_info.rho,exception);
2164 }
2165 else
2166 {
2167 NoiseType
2168 noise;
2169
2170 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2171 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002172 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002173 }
2174 break;
2175 }
2176 if (LocaleCompare("normalize",option+1) == 0)
2177 {
2178 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002179 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002180 InheritException(exception,&(*image)->exception);
2181 break;
2182 }
2183 break;
2184 }
2185 case 'o':
2186 {
2187 if (LocaleCompare("opaque",option+1) == 0)
2188 {
cristy4c08aed2011-07-01 19:47:50 +00002189 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002190 target;
2191
2192 (void) SyncImageSettings(mogrify_info,*image);
2193 (void) QueryMagickColor(argv[i+1],&target,exception);
2194 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2195 *option == '-' ? MagickFalse : MagickTrue);
2196 break;
2197 }
2198 if (LocaleCompare("ordered-dither",option+1) == 0)
2199 {
2200 (void) SyncImageSettings(mogrify_info,*image);
2201 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2202 exception);
2203 break;
2204 }
2205 break;
2206 }
2207 case 'p':
2208 {
2209 if (LocaleCompare("paint",option+1) == 0)
2210 {
anthonydf8ebac2011-04-27 09:03:19 +00002211 (void) SyncImageSettings(mogrify_info,*image);
2212 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002213 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002214 break;
2215 }
2216 if (LocaleCompare("pen",option+1) == 0)
2217 {
2218 if (*option == '+')
2219 {
2220 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2221 break;
2222 }
2223 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2224 break;
2225 }
2226 if (LocaleCompare("pointsize",option+1) == 0)
2227 {
2228 if (*option == '+')
2229 (void) ParseGeometry("12",&geometry_info);
2230 else
2231 (void) ParseGeometry(argv[i+1],&geometry_info);
2232 draw_info->pointsize=geometry_info.rho;
2233 break;
2234 }
2235 if (LocaleCompare("polaroid",option+1) == 0)
2236 {
2237 double
2238 angle;
2239
2240 RandomInfo
2241 *random_info;
2242
2243 /*
2244 Simulate a Polaroid picture.
2245 */
2246 (void) SyncImageSettings(mogrify_info,*image);
2247 random_info=AcquireRandomInfo();
2248 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2249 random_info=DestroyRandomInfo(random_info);
2250 if (*option == '-')
2251 {
2252 SetGeometryInfo(&geometry_info);
2253 flags=ParseGeometry(argv[i+1],&geometry_info);
2254 angle=geometry_info.rho;
2255 }
2256 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2257 break;
2258 }
2259 if (LocaleCompare("posterize",option+1) == 0)
2260 {
2261 /*
2262 Posterize image.
2263 */
2264 (void) SyncImageSettings(mogrify_info,*image);
2265 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2266 quantize_info->dither);
2267 InheritException(exception,&(*image)->exception);
2268 break;
2269 }
2270 if (LocaleCompare("preview",option+1) == 0)
2271 {
2272 PreviewType
2273 preview_type;
2274
2275 /*
2276 Preview image.
2277 */
2278 (void) SyncImageSettings(mogrify_info,*image);
2279 if (*option == '+')
2280 preview_type=UndefinedPreview;
2281 else
2282 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2283 MagickFalse,argv[i+1]);
2284 mogrify_image=PreviewImage(*image,preview_type,exception);
2285 break;
2286 }
2287 if (LocaleCompare("profile",option+1) == 0)
2288 {
2289 const char
2290 *name;
2291
2292 const StringInfo
2293 *profile;
2294
2295 Image
2296 *profile_image;
2297
2298 ImageInfo
2299 *profile_info;
2300
2301 (void) SyncImageSettings(mogrify_info,*image);
2302 if (*option == '+')
2303 {
2304 /*
2305 Remove a profile from the image.
2306 */
2307 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2308 NULL,0,MagickTrue);
2309 InheritException(exception,&(*image)->exception);
2310 break;
2311 }
2312 /*
2313 Associate a profile with the image.
2314 */
2315 profile_info=CloneImageInfo(mogrify_info);
2316 profile=GetImageProfile(*image,"iptc");
2317 if (profile != (StringInfo *) NULL)
2318 profile_info->profile=(void *) CloneStringInfo(profile);
2319 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2320 profile_info=DestroyImageInfo(profile_info);
2321 if (profile_image == (Image *) NULL)
2322 {
2323 StringInfo
2324 *profile;
2325
2326 profile_info=CloneImageInfo(mogrify_info);
2327 (void) CopyMagickString(profile_info->filename,argv[i+1],
2328 MaxTextExtent);
2329 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2330 if (profile != (StringInfo *) NULL)
2331 {
2332 (void) ProfileImage(*image,profile_info->magick,
2333 GetStringInfoDatum(profile),(size_t)
2334 GetStringInfoLength(profile),MagickFalse);
2335 profile=DestroyStringInfo(profile);
2336 }
2337 profile_info=DestroyImageInfo(profile_info);
2338 break;
2339 }
2340 ResetImageProfileIterator(profile_image);
2341 name=GetNextImageProfile(profile_image);
2342 while (name != (const char *) NULL)
2343 {
2344 profile=GetImageProfile(profile_image,name);
2345 if (profile != (StringInfo *) NULL)
2346 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2347 (size_t) GetStringInfoLength(profile),MagickFalse);
2348 name=GetNextImageProfile(profile_image);
2349 }
2350 profile_image=DestroyImage(profile_image);
2351 break;
2352 }
2353 break;
2354 }
2355 case 'q':
2356 {
2357 if (LocaleCompare("quantize",option+1) == 0)
2358 {
2359 if (*option == '+')
2360 {
2361 quantize_info->colorspace=UndefinedColorspace;
2362 break;
2363 }
2364 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2365 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2366 break;
2367 }
2368 break;
2369 }
2370 case 'r':
2371 {
2372 if (LocaleCompare("radial-blur",option+1) == 0)
2373 {
2374 /*
2375 Radial blur image.
2376 */
2377 (void) SyncImageSettings(mogrify_info,*image);
2378 mogrify_image=RadialBlurImageChannel(*image,channel,
cristyc1acd842011-05-19 23:05:47 +00002379 InterpretLocaleValue(argv[i+1],(char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002380 break;
2381 }
2382 if (LocaleCompare("raise",option+1) == 0)
2383 {
2384 /*
2385 Surround image with a raise of solid color.
2386 */
2387 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2388 if ((flags & SigmaValue) == 0)
2389 geometry.height=geometry.width;
2390 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2391 MagickFalse);
2392 InheritException(exception,&(*image)->exception);
2393 break;
2394 }
2395 if (LocaleCompare("random-threshold",option+1) == 0)
2396 {
2397 /*
2398 Threshold image.
2399 */
2400 (void) SyncImageSettings(mogrify_info,*image);
2401 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2402 exception);
2403 break;
2404 }
2405 if (LocaleCompare("recolor",option+1) == 0)
2406 {
2407 KernelInfo
2408 *kernel;
2409
2410 (void) SyncImageSettings(mogrify_info,*image);
2411 kernel=AcquireKernelInfo(argv[i+1]);
2412 if (kernel == (KernelInfo *) NULL)
2413 break;
2414 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2415 kernel=DestroyKernelInfo(kernel);
2416 break;
2417 }
2418 if (LocaleCompare("region",option+1) == 0)
2419 {
2420 (void) SyncImageSettings(mogrify_info,*image);
2421 if (region_image != (Image *) NULL)
2422 {
2423 /*
2424 Composite region.
2425 */
2426 (void) CompositeImage(region_image,region_image->matte !=
cristyab015852011-07-06 01:03:32 +00002427 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2428 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002429 InheritException(exception,&region_image->exception);
2430 *image=DestroyImage(*image);
2431 *image=region_image;
2432 region_image = (Image *) NULL;
2433 }
2434 if (*option == '+')
2435 break;
2436 /*
2437 Apply transformations to a selected region of the image.
2438 */
cristy3ed852e2009-09-05 21:47:34 +00002439 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2440 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002441 mogrify_image=CropImage(*image,&region_geometry,exception);
2442 if (mogrify_image == (Image *) NULL)
2443 break;
2444 region_image=(*image);
2445 *image=mogrify_image;
2446 mogrify_image=(Image *) NULL;
2447 break;
cristy3ed852e2009-09-05 21:47:34 +00002448 }
anthonydf8ebac2011-04-27 09:03:19 +00002449 if (LocaleCompare("render",option+1) == 0)
2450 {
2451 (void) SyncImageSettings(mogrify_info,*image);
2452 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2453 break;
2454 }
2455 if (LocaleCompare("remap",option+1) == 0)
2456 {
2457 Image
2458 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002459
anthonydf8ebac2011-04-27 09:03:19 +00002460 /*
2461 Transform image colors to match this set of colors.
2462 */
2463 (void) SyncImageSettings(mogrify_info,*image);
2464 if (*option == '+')
2465 break;
2466 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2467 if (remap_image == (Image *) NULL)
2468 break;
2469 (void) RemapImage(quantize_info,*image,remap_image);
2470 InheritException(exception,&(*image)->exception);
2471 remap_image=DestroyImage(remap_image);
2472 break;
2473 }
2474 if (LocaleCompare("repage",option+1) == 0)
2475 {
2476 if (*option == '+')
2477 {
2478 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2479 break;
2480 }
2481 (void) ResetImagePage(*image,argv[i+1]);
2482 InheritException(exception,&(*image)->exception);
2483 break;
2484 }
2485 if (LocaleCompare("resample",option+1) == 0)
2486 {
2487 /*
2488 Resample image.
2489 */
2490 (void) SyncImageSettings(mogrify_info,*image);
2491 flags=ParseGeometry(argv[i+1],&geometry_info);
2492 if ((flags & SigmaValue) == 0)
2493 geometry_info.sigma=geometry_info.rho;
2494 mogrify_image=ResampleImage(*image,geometry_info.rho,
2495 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2496 break;
2497 }
2498 if (LocaleCompare("resize",option+1) == 0)
2499 {
2500 /*
2501 Resize image.
2502 */
2503 (void) SyncImageSettings(mogrify_info,*image);
2504 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2505 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2506 (*image)->filter,(*image)->blur,exception);
2507 break;
2508 }
2509 if (LocaleCompare("roll",option+1) == 0)
2510 {
2511 /*
2512 Roll image.
2513 */
2514 (void) SyncImageSettings(mogrify_info,*image);
2515 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2516 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2517 break;
2518 }
2519 if (LocaleCompare("rotate",option+1) == 0)
2520 {
2521 char
2522 *geometry;
2523
2524 /*
2525 Check for conditional image rotation.
2526 */
2527 (void) SyncImageSettings(mogrify_info,*image);
2528 if (strchr(argv[i+1],'>') != (char *) NULL)
2529 if ((*image)->columns <= (*image)->rows)
2530 break;
2531 if (strchr(argv[i+1],'<') != (char *) NULL)
2532 if ((*image)->columns >= (*image)->rows)
2533 break;
2534 /*
2535 Rotate image.
2536 */
2537 geometry=ConstantString(argv[i+1]);
2538 (void) SubstituteString(&geometry,">","");
2539 (void) SubstituteString(&geometry,"<","");
2540 (void) ParseGeometry(geometry,&geometry_info);
2541 geometry=DestroyString(geometry);
2542 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2543 break;
2544 }
2545 break;
2546 }
2547 case 's':
2548 {
2549 if (LocaleCompare("sample",option+1) == 0)
2550 {
2551 /*
2552 Sample image with pixel replication.
2553 */
2554 (void) SyncImageSettings(mogrify_info,*image);
2555 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2556 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2557 exception);
2558 break;
2559 }
2560 if (LocaleCompare("scale",option+1) == 0)
2561 {
2562 /*
2563 Resize image.
2564 */
2565 (void) SyncImageSettings(mogrify_info,*image);
2566 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2567 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2568 exception);
2569 break;
2570 }
2571 if (LocaleCompare("selective-blur",option+1) == 0)
2572 {
2573 /*
2574 Selectively blur pixels within a contrast threshold.
2575 */
2576 (void) SyncImageSettings(mogrify_info,*image);
2577 flags=ParseGeometry(argv[i+1],&geometry_info);
2578 if ((flags & PercentValue) != 0)
2579 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2580 mogrify_image=SelectiveBlurImageChannel(*image,channel,
2581 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2582 break;
2583 }
2584 if (LocaleCompare("separate",option+1) == 0)
2585 {
2586 /*
2587 Break channels into separate images.
2588 WARNING: This can generate multiple images!
2589 */
2590 (void) SyncImageSettings(mogrify_info,*image);
2591 mogrify_image=SeparateImages(*image,channel,exception);
2592 break;
2593 }
2594 if (LocaleCompare("sepia-tone",option+1) == 0)
2595 {
2596 double
2597 threshold;
2598
2599 /*
2600 Sepia-tone image.
2601 */
2602 (void) SyncImageSettings(mogrify_info,*image);
2603 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2604 mogrify_image=SepiaToneImage(*image,threshold,exception);
2605 break;
2606 }
2607 if (LocaleCompare("segment",option+1) == 0)
2608 {
2609 /*
2610 Segment image.
2611 */
2612 (void) SyncImageSettings(mogrify_info,*image);
2613 flags=ParseGeometry(argv[i+1],&geometry_info);
2614 if ((flags & SigmaValue) == 0)
2615 geometry_info.sigma=1.0;
2616 (void) SegmentImage(*image,(*image)->colorspace,
2617 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2618 InheritException(exception,&(*image)->exception);
2619 break;
2620 }
2621 if (LocaleCompare("set",option+1) == 0)
2622 {
2623 char
2624 *value;
2625
2626 /*
2627 Set image option.
2628 */
2629 if (*option == '+')
2630 {
2631 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2632 (void) DeleteImageRegistry(argv[i+1]+9);
2633 else
2634 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2635 {
2636 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2637 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2638 }
2639 else
2640 (void) DeleteImageProperty(*image,argv[i+1]);
2641 break;
2642 }
2643 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2644 if (value == (char *) NULL)
2645 break;
2646 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2647 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2648 exception);
2649 else
2650 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2651 {
2652 (void) SetImageOption(image_info,argv[i+1]+7,value);
2653 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2654 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2655 }
2656 else
2657 (void) SetImageProperty(*image,argv[i+1],value);
2658 value=DestroyString(value);
2659 break;
2660 }
2661 if (LocaleCompare("shade",option+1) == 0)
2662 {
2663 /*
2664 Shade image.
2665 */
2666 (void) SyncImageSettings(mogrify_info,*image);
2667 flags=ParseGeometry(argv[i+1],&geometry_info);
2668 if ((flags & SigmaValue) == 0)
2669 geometry_info.sigma=1.0;
2670 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2671 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2672 break;
2673 }
2674 if (LocaleCompare("shadow",option+1) == 0)
2675 {
2676 /*
2677 Shadow image.
2678 */
2679 (void) SyncImageSettings(mogrify_info,*image);
2680 flags=ParseGeometry(argv[i+1],&geometry_info);
2681 if ((flags & SigmaValue) == 0)
2682 geometry_info.sigma=1.0;
2683 if ((flags & XiValue) == 0)
2684 geometry_info.xi=4.0;
2685 if ((flags & PsiValue) == 0)
2686 geometry_info.psi=4.0;
2687 mogrify_image=ShadowImage(*image,geometry_info.rho,
2688 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2689 ceil(geometry_info.psi-0.5),exception);
2690 break;
2691 }
2692 if (LocaleCompare("sharpen",option+1) == 0)
2693 {
2694 /*
2695 Sharpen image.
2696 */
2697 (void) SyncImageSettings(mogrify_info,*image);
2698 flags=ParseGeometry(argv[i+1],&geometry_info);
2699 if ((flags & SigmaValue) == 0)
2700 geometry_info.sigma=1.0;
2701 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2702 geometry_info.sigma,exception);
2703 break;
2704 }
2705 if (LocaleCompare("shave",option+1) == 0)
2706 {
2707 /*
2708 Shave the image edges.
2709 */
2710 (void) SyncImageSettings(mogrify_info,*image);
2711 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2712 mogrify_image=ShaveImage(*image,&geometry,exception);
2713 break;
2714 }
2715 if (LocaleCompare("shear",option+1) == 0)
2716 {
2717 /*
2718 Shear image.
2719 */
2720 (void) SyncImageSettings(mogrify_info,*image);
2721 flags=ParseGeometry(argv[i+1],&geometry_info);
2722 if ((flags & SigmaValue) == 0)
2723 geometry_info.sigma=geometry_info.rho;
2724 mogrify_image=ShearImage(*image,geometry_info.rho,
2725 geometry_info.sigma,exception);
2726 break;
2727 }
2728 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2729 {
2730 /*
2731 Sigmoidal non-linearity contrast control.
2732 */
2733 (void) SyncImageSettings(mogrify_info,*image);
2734 flags=ParseGeometry(argv[i+1],&geometry_info);
2735 if ((flags & SigmaValue) == 0)
2736 geometry_info.sigma=(double) QuantumRange/2.0;
2737 if ((flags & PercentValue) != 0)
2738 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2739 100.0;
cristy9ee60942011-07-06 14:54:38 +00002740 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2741 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002742 InheritException(exception,&(*image)->exception);
2743 break;
2744 }
2745 if (LocaleCompare("sketch",option+1) == 0)
2746 {
2747 /*
2748 Sketch image.
2749 */
2750 (void) SyncImageSettings(mogrify_info,*image);
2751 flags=ParseGeometry(argv[i+1],&geometry_info);
2752 if ((flags & SigmaValue) == 0)
2753 geometry_info.sigma=1.0;
2754 mogrify_image=SketchImage(*image,geometry_info.rho,
2755 geometry_info.sigma,geometry_info.xi,exception);
2756 break;
2757 }
2758 if (LocaleCompare("solarize",option+1) == 0)
2759 {
2760 double
2761 threshold;
2762
2763 (void) SyncImageSettings(mogrify_info,*image);
2764 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2765 (void) SolarizeImage(*image,threshold);
2766 InheritException(exception,&(*image)->exception);
2767 break;
2768 }
2769 if (LocaleCompare("sparse-color",option+1) == 0)
2770 {
2771 SparseColorMethod
2772 method;
2773
2774 char
2775 *arguments;
2776
2777 /*
2778 Sparse Color Interpolated Gradient
2779 */
2780 (void) SyncImageSettings(mogrify_info,*image);
2781 method=(SparseColorMethod) ParseCommandOption(
2782 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2783 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2784 InheritException(exception,&(*image)->exception);
2785 if (arguments == (char *) NULL)
2786 break;
2787 mogrify_image=SparseColorOption(*image,channel,method,arguments,
2788 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2789 arguments=DestroyString(arguments);
2790 break;
2791 }
2792 if (LocaleCompare("splice",option+1) == 0)
2793 {
2794 /*
2795 Splice a solid color into the image.
2796 */
2797 (void) SyncImageSettings(mogrify_info,*image);
2798 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2799 mogrify_image=SpliceImage(*image,&geometry,exception);
2800 break;
2801 }
2802 if (LocaleCompare("spread",option+1) == 0)
2803 {
2804 /*
2805 Spread an image.
2806 */
2807 (void) SyncImageSettings(mogrify_info,*image);
2808 (void) ParseGeometry(argv[i+1],&geometry_info);
2809 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2810 break;
2811 }
2812 if (LocaleCompare("statistic",option+1) == 0)
2813 {
2814 StatisticType
2815 type;
2816
2817 (void) SyncImageSettings(mogrify_info,*image);
2818 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2819 MagickFalse,argv[i+1]);
2820 (void) ParseGeometry(argv[i+2],&geometry_info);
2821 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2822 geometry_info.rho,(size_t) geometry_info.sigma,exception);
2823 break;
2824 }
2825 if (LocaleCompare("stretch",option+1) == 0)
2826 {
2827 if (*option == '+')
2828 {
2829 draw_info->stretch=UndefinedStretch;
2830 break;
2831 }
2832 draw_info->stretch=(StretchType) ParseCommandOption(
2833 MagickStretchOptions,MagickFalse,argv[i+1]);
2834 break;
2835 }
2836 if (LocaleCompare("strip",option+1) == 0)
2837 {
2838 /*
2839 Strip image of profiles and comments.
2840 */
2841 (void) SyncImageSettings(mogrify_info,*image);
2842 (void) StripImage(*image);
2843 InheritException(exception,&(*image)->exception);
2844 break;
2845 }
2846 if (LocaleCompare("stroke",option+1) == 0)
2847 {
2848 ExceptionInfo
2849 *sans;
2850
2851 if (*option == '+')
2852 {
2853 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2854 if (draw_info->stroke_pattern != (Image *) NULL)
2855 draw_info->stroke_pattern=DestroyImage(
2856 draw_info->stroke_pattern);
2857 break;
2858 }
2859 sans=AcquireExceptionInfo();
2860 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2861 sans=DestroyExceptionInfo(sans);
2862 if (status == MagickFalse)
2863 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2864 exception);
2865 break;
2866 }
2867 if (LocaleCompare("strokewidth",option+1) == 0)
2868 {
cristyc1acd842011-05-19 23:05:47 +00002869 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2870 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002871 break;
2872 }
2873 if (LocaleCompare("style",option+1) == 0)
2874 {
2875 if (*option == '+')
2876 {
2877 draw_info->style=UndefinedStyle;
2878 break;
2879 }
2880 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2881 MagickFalse,argv[i+1]);
2882 break;
2883 }
2884 if (LocaleCompare("swirl",option+1) == 0)
2885 {
2886 /*
2887 Swirl image.
2888 */
2889 (void) SyncImageSettings(mogrify_info,*image);
2890 (void) ParseGeometry(argv[i+1],&geometry_info);
2891 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2892 break;
2893 }
2894 break;
2895 }
2896 case 't':
2897 {
2898 if (LocaleCompare("threshold",option+1) == 0)
2899 {
2900 double
2901 threshold;
2902
2903 /*
2904 Threshold image.
2905 */
2906 (void) SyncImageSettings(mogrify_info,*image);
2907 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002908 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002909 else
2910 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2911 (void) BilevelImageChannel(*image,channel,threshold);
2912 InheritException(exception,&(*image)->exception);
2913 break;
2914 }
2915 if (LocaleCompare("thumbnail",option+1) == 0)
2916 {
2917 /*
2918 Thumbnail image.
2919 */
2920 (void) SyncImageSettings(mogrify_info,*image);
2921 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2922 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2923 exception);
2924 break;
2925 }
2926 if (LocaleCompare("tile",option+1) == 0)
2927 {
2928 if (*option == '+')
2929 {
2930 if (draw_info->fill_pattern != (Image *) NULL)
2931 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2932 break;
2933 }
2934 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2935 exception);
2936 break;
2937 }
2938 if (LocaleCompare("tint",option+1) == 0)
2939 {
2940 /*
2941 Tint the image.
2942 */
2943 (void) SyncImageSettings(mogrify_info,*image);
2944 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2945 break;
2946 }
2947 if (LocaleCompare("transform",option+1) == 0)
2948 {
2949 /*
2950 Affine transform image.
2951 */
2952 (void) SyncImageSettings(mogrify_info,*image);
2953 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2954 exception);
2955 break;
2956 }
2957 if (LocaleCompare("transparent",option+1) == 0)
2958 {
cristy4c08aed2011-07-01 19:47:50 +00002959 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002960 target;
2961
2962 (void) SyncImageSettings(mogrify_info,*image);
2963 (void) QueryMagickColor(argv[i+1],&target,exception);
2964 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002965 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002966 InheritException(exception,&(*image)->exception);
2967 break;
2968 }
2969 if (LocaleCompare("transpose",option+1) == 0)
2970 {
2971 /*
2972 Transpose image scanlines.
2973 */
2974 (void) SyncImageSettings(mogrify_info,*image);
2975 mogrify_image=TransposeImage(*image,exception);
2976 break;
2977 }
2978 if (LocaleCompare("transverse",option+1) == 0)
2979 {
2980 /*
2981 Transverse image scanlines.
2982 */
2983 (void) SyncImageSettings(mogrify_info,*image);
2984 mogrify_image=TransverseImage(*image,exception);
2985 break;
2986 }
2987 if (LocaleCompare("treedepth",option+1) == 0)
2988 {
2989 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2990 break;
2991 }
2992 if (LocaleCompare("trim",option+1) == 0)
2993 {
2994 /*
2995 Trim image.
2996 */
2997 (void) SyncImageSettings(mogrify_info,*image);
2998 mogrify_image=TrimImage(*image,exception);
2999 break;
3000 }
3001 if (LocaleCompare("type",option+1) == 0)
3002 {
3003 ImageType
3004 type;
3005
3006 (void) SyncImageSettings(mogrify_info,*image);
3007 if (*option == '+')
3008 type=UndefinedType;
3009 else
3010 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3011 argv[i+1]);
3012 (*image)->type=UndefinedType;
3013 (void) SetImageType(*image,type);
3014 InheritException(exception,&(*image)->exception);
3015 break;
3016 }
3017 break;
3018 }
3019 case 'u':
3020 {
3021 if (LocaleCompare("undercolor",option+1) == 0)
3022 {
3023 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3024 exception);
3025 break;
3026 }
3027 if (LocaleCompare("unique",option+1) == 0)
3028 {
3029 if (*option == '+')
3030 {
3031 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3032 break;
3033 }
3034 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3035 (void) SetImageArtifact(*image,"verbose","true");
3036 break;
3037 }
3038 if (LocaleCompare("unique-colors",option+1) == 0)
3039 {
3040 /*
3041 Unique image colors.
3042 */
3043 (void) SyncImageSettings(mogrify_info,*image);
3044 mogrify_image=UniqueImageColors(*image,exception);
3045 break;
3046 }
3047 if (LocaleCompare("unsharp",option+1) == 0)
3048 {
3049 /*
3050 Unsharp mask image.
3051 */
3052 (void) SyncImageSettings(mogrify_info,*image);
3053 flags=ParseGeometry(argv[i+1],&geometry_info);
3054 if ((flags & SigmaValue) == 0)
3055 geometry_info.sigma=1.0;
3056 if ((flags & XiValue) == 0)
3057 geometry_info.xi=1.0;
3058 if ((flags & PsiValue) == 0)
3059 geometry_info.psi=0.05;
3060 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3061 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3062 geometry_info.psi,exception);
3063 break;
3064 }
3065 break;
3066 }
3067 case 'v':
3068 {
3069 if (LocaleCompare("verbose",option+1) == 0)
3070 {
3071 (void) SetImageArtifact(*image,option+1,
3072 *option == '+' ? "false" : "true");
3073 break;
3074 }
3075 if (LocaleCompare("vignette",option+1) == 0)
3076 {
3077 /*
3078 Vignette image.
3079 */
3080 (void) SyncImageSettings(mogrify_info,*image);
3081 flags=ParseGeometry(argv[i+1],&geometry_info);
3082 if ((flags & SigmaValue) == 0)
3083 geometry_info.sigma=1.0;
3084 if ((flags & XiValue) == 0)
3085 geometry_info.xi=0.1*(*image)->columns;
3086 if ((flags & PsiValue) == 0)
3087 geometry_info.psi=0.1*(*image)->rows;
3088 mogrify_image=VignetteImage(*image,geometry_info.rho,
3089 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3090 ceil(geometry_info.psi-0.5),exception);
3091 break;
3092 }
3093 if (LocaleCompare("virtual-pixel",option+1) == 0)
3094 {
3095 if (*option == '+')
3096 {
3097 (void) SetImageVirtualPixelMethod(*image,
3098 UndefinedVirtualPixelMethod);
3099 break;
3100 }
3101 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3102 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3103 argv[i+1]));
3104 break;
3105 }
3106 break;
3107 }
3108 case 'w':
3109 {
3110 if (LocaleCompare("wave",option+1) == 0)
3111 {
3112 /*
3113 Wave image.
3114 */
3115 (void) SyncImageSettings(mogrify_info,*image);
3116 flags=ParseGeometry(argv[i+1],&geometry_info);
3117 if ((flags & SigmaValue) == 0)
3118 geometry_info.sigma=1.0;
3119 mogrify_image=WaveImage(*image,geometry_info.rho,
3120 geometry_info.sigma,exception);
3121 break;
3122 }
3123 if (LocaleCompare("weight",option+1) == 0)
3124 {
3125 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3126 if (LocaleCompare(argv[i+1],"all") == 0)
3127 draw_info->weight=0;
3128 if (LocaleCompare(argv[i+1],"bold") == 0)
3129 draw_info->weight=700;
3130 if (LocaleCompare(argv[i+1],"bolder") == 0)
3131 if (draw_info->weight <= 800)
3132 draw_info->weight+=100;
3133 if (LocaleCompare(argv[i+1],"lighter") == 0)
3134 if (draw_info->weight >= 100)
3135 draw_info->weight-=100;
3136 if (LocaleCompare(argv[i+1],"normal") == 0)
3137 draw_info->weight=400;
3138 break;
3139 }
3140 if (LocaleCompare("white-threshold",option+1) == 0)
3141 {
3142 /*
3143 White threshold image.
3144 */
3145 (void) SyncImageSettings(mogrify_info,*image);
3146 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3147 exception);
3148 InheritException(exception,&(*image)->exception);
3149 break;
3150 }
3151 break;
3152 }
3153 default:
3154 break;
3155 }
3156 /*
3157 Replace current image with any image that was generated
3158 */
3159 if (mogrify_image != (Image *) NULL)
3160 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003161 i+=count;
3162 }
3163 if (region_image != (Image *) NULL)
3164 {
anthonydf8ebac2011-04-27 09:03:19 +00003165 /*
3166 Composite transformed region onto image.
3167 */
cristy6b3da3a2010-06-20 02:21:46 +00003168 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003169 (void) CompositeImage(region_image,region_image->matte !=
cristyab015852011-07-06 01:03:32 +00003170 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3171 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003172 InheritException(exception,&region_image->exception);
3173 *image=DestroyImage(*image);
3174 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003175 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003176 }
3177 /*
3178 Free resources.
3179 */
anthonydf8ebac2011-04-27 09:03:19 +00003180 quantize_info=DestroyQuantizeInfo(quantize_info);
3181 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003182 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003183 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003184 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003185 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003186}
3187
3188/*
3189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3190% %
3191% %
3192% %
cristy5063d812010-10-19 16:28:10 +00003193+ 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 +00003194% %
3195% %
3196% %
3197%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3198%
3199% MogrifyImageCommand() transforms an image or a sequence of images. These
3200% transforms include image scaling, image rotation, color reduction, and
3201% others. The transmogrified image overwrites the original image.
3202%
3203% The format of the MogrifyImageCommand method is:
3204%
3205% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3206% const char **argv,char **metadata,ExceptionInfo *exception)
3207%
3208% A description of each parameter follows:
3209%
3210% o image_info: the image info.
3211%
3212% o argc: the number of elements in the argument vector.
3213%
3214% o argv: A text array containing the command line arguments.
3215%
3216% o metadata: any metadata is returned here.
3217%
3218% o exception: return any errors or warnings in this structure.
3219%
3220*/
3221
3222static MagickBooleanType MogrifyUsage(void)
3223{
3224 static const char
3225 *miscellaneous[]=
3226 {
3227 "-debug events display copious debugging information",
3228 "-help print program options",
3229 "-list type print a list of supported option arguments",
3230 "-log format format of debugging information",
3231 "-version print version information",
3232 (char *) NULL
3233 },
3234 *operators[]=
3235 {
3236 "-adaptive-blur geometry",
3237 " adaptively blur pixels; decrease effect near edges",
3238 "-adaptive-resize geometry",
3239 " adaptively resize image using 'mesh' interpolation",
3240 "-adaptive-sharpen geometry",
3241 " adaptively sharpen pixels; increase effect near edges",
3242 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3243 " transparent, extract, background, or shape",
3244 "-annotate geometry text",
3245 " annotate the image with text",
3246 "-auto-gamma automagically adjust gamma level of image",
3247 "-auto-level automagically adjust color levels of image",
3248 "-auto-orient automagically orient (rotate) image",
3249 "-bench iterations measure performance",
3250 "-black-threshold value",
3251 " force all pixels below the threshold into black",
3252 "-blue-shift simulate a scene at nighttime in the moonlight",
3253 "-blur geometry reduce image noise and reduce detail levels",
3254 "-border geometry surround image with a border of color",
3255 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003256 "-brightness-contrast geometry",
3257 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003258 "-cdl filename color correct with a color decision list",
3259 "-charcoal radius simulate a charcoal drawing",
3260 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003261 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003262 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003263 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003264 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003265 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003266 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003267 "-contrast enhance or reduce the image contrast",
3268 "-contrast-stretch geometry",
3269 " improve contrast by `stretching' the intensity range",
3270 "-convolve coefficients",
3271 " apply a convolution kernel to the image",
3272 "-cycle amount cycle the image colormap",
3273 "-decipher filename convert cipher pixels to plain pixels",
3274 "-deskew threshold straighten an image",
3275 "-despeckle reduce the speckles within an image",
3276 "-distort method args",
3277 " distort images according to given method ad args",
3278 "-draw string annotate the image with a graphic primitive",
3279 "-edge radius apply a filter to detect edges in the image",
3280 "-encipher filename convert plain pixels to cipher pixels",
3281 "-emboss radius emboss an image",
3282 "-enhance apply a digital filter to enhance a noisy image",
3283 "-equalize perform histogram equalization to an image",
3284 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003285 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003286 "-extent geometry set the image size",
3287 "-extract geometry extract area from image",
3288 "-fft implements the discrete Fourier transform (DFT)",
3289 "-flip flip image vertically",
3290 "-floodfill geometry color",
3291 " floodfill the image with color",
3292 "-flop flop image horizontally",
3293 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003294 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003295 " apply function over image values",
3296 "-gamma value level of gamma correction",
3297 "-gaussian-blur geometry",
3298 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003299 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003300 "-identify identify the format and characteristics of the image",
3301 "-ift implements the inverse discrete Fourier transform (DFT)",
3302 "-implode amount implode image pixels about the center",
3303 "-lat geometry local adaptive thresholding",
3304 "-layers method optimize, merge, or compare image layers",
3305 "-level value adjust the level of image contrast",
3306 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003307 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003308 "-linear-stretch geometry",
3309 " improve contrast by `stretching with saturation'",
3310 "-liquid-rescale geometry",
3311 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003312 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003313 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003314 "-modulate value vary the brightness, saturation, and hue",
3315 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003316 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003317 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003318 "-motion-blur geometry",
3319 " simulate motion blur",
3320 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003321 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003322 "-normalize transform image to span the full range of colors",
3323 "-opaque color change this color to the fill color",
3324 "-ordered-dither NxN",
3325 " add a noise pattern to the image with specific",
3326 " amplitudes",
3327 "-paint radius simulate an oil painting",
3328 "-polaroid angle simulate a Polaroid picture",
3329 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003330 "-profile filename add, delete, or apply an image profile",
3331 "-quantize colorspace reduce colors in this colorspace",
3332 "-radial-blur angle radial blur the image",
3333 "-raise value lighten/darken image edges to create a 3-D effect",
3334 "-random-threshold low,high",
3335 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003336 "-region geometry apply options to a portion of the image",
3337 "-render render vector graphics",
3338 "-repage geometry size and location of an image canvas",
3339 "-resample geometry change the resolution of an image",
3340 "-resize geometry resize the image",
3341 "-roll geometry roll an image vertically or horizontally",
3342 "-rotate degrees apply Paeth rotation to the image",
3343 "-sample geometry scale image with pixel sampling",
3344 "-scale geometry scale the image",
3345 "-segment values segment an image",
3346 "-selective-blur geometry",
3347 " selectively blur pixels within a contrast threshold",
3348 "-sepia-tone threshold",
3349 " simulate a sepia-toned photo",
3350 "-set property value set an image property",
3351 "-shade degrees shade the image using a distant light source",
3352 "-shadow geometry simulate an image shadow",
3353 "-sharpen geometry sharpen the image",
3354 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003355 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003356 "-sigmoidal-contrast geometry",
3357 " increase the contrast without saturating highlights or shadows",
3358 "-sketch geometry simulate a pencil sketch",
3359 "-solarize threshold negate all pixels above the threshold level",
3360 "-sparse-color method args",
3361 " fill in a image based on a few color points",
3362 "-splice geometry splice the background color into the image",
3363 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003364 "-statistic type radius",
3365 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003366 "-strip strip image of all profiles and comments",
3367 "-swirl degrees swirl image pixels about the center",
3368 "-threshold value threshold the image",
3369 "-thumbnail geometry create a thumbnail of the image",
3370 "-tile filename tile image when filling a graphic primitive",
3371 "-tint value tint the image with the fill color",
3372 "-transform affine transform image",
3373 "-transparent color make this color transparent within the image",
3374 "-transpose flip image vertically and rotate 90 degrees",
3375 "-transverse flop image horizontally and rotate 270 degrees",
3376 "-trim trim image edges",
3377 "-type type image type",
3378 "-unique-colors discard all but one of any pixel color",
3379 "-unsharp geometry sharpen the image",
3380 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003381 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003382 "-white-threshold value",
3383 " force all pixels above the threshold into white",
3384 (char *) NULL
3385 },
3386 *sequence_operators[]=
3387 {
cristy4285d782011-02-09 20:12:28 +00003388 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003389 "-clut apply a color lookup table to the image",
3390 "-coalesce merge a sequence of images",
3391 "-combine combine a sequence of images",
3392 "-composite composite image",
3393 "-crop geometry cut out a rectangular region of the image",
3394 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003395 "-evaluate-sequence operator",
3396 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003397 "-flatten flatten a sequence of images",
3398 "-fx expression apply mathematical expression to an image channel(s)",
3399 "-hald-clut apply a Hald color lookup table to the image",
3400 "-morph value morph an image sequence",
3401 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003402 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003403 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003404 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003405 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003406 "-write filename write images to this file",
3407 (char *) NULL
3408 },
3409 *settings[]=
3410 {
3411 "-adjoin join images into a single multi-image file",
3412 "-affine matrix affine transform matrix",
3413 "-alpha option activate, deactivate, reset, or set the alpha channel",
3414 "-antialias remove pixel-aliasing",
3415 "-authenticate password",
3416 " decipher image with this password",
3417 "-attenuate value lessen (or intensify) when adding noise to an image",
3418 "-background color background color",
3419 "-bias value add bias when convolving an image",
3420 "-black-point-compensation",
3421 " use black point compensation",
3422 "-blue-primary point chromaticity blue primary point",
3423 "-bordercolor color border color",
3424 "-caption string assign a caption to an image",
3425 "-channel type apply option to select image channels",
3426 "-colors value preferred number of colors in the image",
3427 "-colorspace type alternate image colorspace",
3428 "-comment string annotate image with comment",
3429 "-compose operator set image composite operator",
3430 "-compress type type of pixel compression when writing the image",
3431 "-define format:option",
3432 " define one or more image format options",
3433 "-delay value display the next image after pausing",
3434 "-density geometry horizontal and vertical density of the image",
3435 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003436 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003437 "-display server get image or font from this X server",
3438 "-dispose method layer disposal method",
3439 "-dither method apply error diffusion to image",
3440 "-encoding type text encoding type",
3441 "-endian type endianness (MSB or LSB) of the image",
3442 "-family name render text with this font family",
3443 "-fill color color to use when filling a graphic primitive",
3444 "-filter type use this filter when resizing an image",
3445 "-font name render text with this font",
3446 "-format \"string\" output formatted image characteristics",
3447 "-fuzz distance colors within this distance are considered equal",
3448 "-gravity type horizontal and vertical text placement",
3449 "-green-primary point chromaticity green primary point",
3450 "-intent type type of rendering intent when managing the image color",
3451 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003452 "-interline-spacing value",
3453 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003454 "-interpolate method pixel color interpolation method",
3455 "-interword-spacing value",
3456 " set the space between two words",
3457 "-kerning value set the space between two letters",
3458 "-label string assign a label to an image",
3459 "-limit type value pixel cache resource limit",
3460 "-loop iterations add Netscape loop extension to your GIF animation",
3461 "-mask filename associate a mask with the image",
3462 "-mattecolor color frame color",
3463 "-monitor monitor progress",
3464 "-orient type image orientation",
3465 "-page geometry size and location of an image canvas (setting)",
3466 "-ping efficiently determine image attributes",
3467 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003468 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003469 "-preview type image preview type",
3470 "-quality value JPEG/MIFF/PNG compression level",
3471 "-quiet suppress all warning messages",
3472 "-red-primary point chromaticity red primary point",
3473 "-regard-warnings pay attention to warning messages",
3474 "-remap filename transform image colors to match this set of colors",
3475 "-respect-parentheses settings remain in effect until parenthesis boundary",
3476 "-sampling-factor geometry",
3477 " horizontal and vertical sampling factor",
3478 "-scene value image scene number",
3479 "-seed value seed a new sequence of pseudo-random numbers",
3480 "-size geometry width and height of image",
3481 "-stretch type render text with this font stretch",
3482 "-stroke color graphic primitive stroke color",
3483 "-strokewidth value graphic primitive stroke width",
3484 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003485 "-synchronize synchronize image to storage device",
3486 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003487 "-texture filename name of texture to tile onto the image background",
3488 "-tile-offset geometry",
3489 " tile offset",
3490 "-treedepth value color tree depth",
3491 "-transparent-color color",
3492 " transparent color",
3493 "-undercolor color annotation bounding box color",
3494 "-units type the units of image resolution",
3495 "-verbose print detailed information about the image",
3496 "-view FlashPix viewing transforms",
3497 "-virtual-pixel method",
3498 " virtual pixel access method",
3499 "-weight type render text with this font weight",
3500 "-white-point point chromaticity white point",
3501 (char *) NULL
3502 },
3503 *stack_operators[]=
3504 {
anthonyb69c4b32011-03-23 04:37:44 +00003505 "-delete indexes delete the image from the image sequence",
3506 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003507 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003508 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003509 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003510 "-swap indexes swap two images in the image sequence",
3511 (char *) NULL
3512 };
3513
3514 const char
3515 **p;
3516
cristybb503372010-05-27 20:51:26 +00003517 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003518 (void) printf("Copyright: %s\n",GetMagickCopyright());
3519 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003520 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3521 GetClientName());
3522 (void) printf("\nImage Settings:\n");
3523 for (p=settings; *p != (char *) NULL; p++)
3524 (void) printf(" %s\n",*p);
3525 (void) printf("\nImage Operators:\n");
3526 for (p=operators; *p != (char *) NULL; p++)
3527 (void) printf(" %s\n",*p);
3528 (void) printf("\nImage Sequence Operators:\n");
3529 for (p=sequence_operators; *p != (char *) NULL; p++)
3530 (void) printf(" %s\n",*p);
3531 (void) printf("\nImage Stack Operators:\n");
3532 for (p=stack_operators; *p != (char *) NULL; p++)
3533 (void) printf(" %s\n",*p);
3534 (void) printf("\nMiscellaneous Options:\n");
3535 for (p=miscellaneous; *p != (char *) NULL; p++)
3536 (void) printf(" %s\n",*p);
3537 (void) printf(
3538 "\nBy default, the image format of `file' is determined by its magic\n");
3539 (void) printf(
3540 "number. To specify a particular image format, precede the filename\n");
3541 (void) printf(
3542 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3543 (void) printf(
3544 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3545 (void) printf("'-' for standard input or output.\n");
3546 return(MagickFalse);
3547}
3548
3549WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3550 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3551{
3552#define DestroyMogrify() \
3553{ \
3554 if (format != (char *) NULL) \
3555 format=DestroyString(format); \
3556 if (path != (char *) NULL) \
3557 path=DestroyString(path); \
3558 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003559 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003560 argv[i]=DestroyString(argv[i]); \
3561 argv=(char **) RelinquishMagickMemory(argv); \
3562}
3563#define ThrowMogrifyException(asperity,tag,option) \
3564{ \
3565 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3566 option); \
3567 DestroyMogrify(); \
3568 return(MagickFalse); \
3569}
3570#define ThrowMogrifyInvalidArgumentException(option,argument) \
3571{ \
3572 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3573 "InvalidArgument","`%s': %s",argument,option); \
3574 DestroyMogrify(); \
3575 return(MagickFalse); \
3576}
3577
3578 char
3579 *format,
3580 *option,
3581 *path;
3582
3583 Image
3584 *image;
3585
3586 ImageStack
3587 image_stack[MaxImageStackDepth+1];
3588
cristy3ed852e2009-09-05 21:47:34 +00003589 MagickBooleanType
3590 global_colormap;
3591
3592 MagickBooleanType
3593 fire,
cristyebbcfea2011-02-25 02:43:54 +00003594 pend,
3595 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003596
3597 MagickStatusType
3598 status;
3599
cristyebbcfea2011-02-25 02:43:54 +00003600 register ssize_t
3601 i;
3602
3603 ssize_t
3604 j,
3605 k;
3606
cristy3ed852e2009-09-05 21:47:34 +00003607 /*
3608 Set defaults.
3609 */
3610 assert(image_info != (ImageInfo *) NULL);
3611 assert(image_info->signature == MagickSignature);
3612 if (image_info->debug != MagickFalse)
3613 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3614 assert(exception != (ExceptionInfo *) NULL);
3615 if (argc == 2)
3616 {
3617 option=argv[1];
3618 if ((LocaleCompare("version",option+1) == 0) ||
3619 (LocaleCompare("-version",option+1) == 0))
3620 {
cristyb51dff52011-05-19 16:55:47 +00003621 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003622 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003623 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3624 GetMagickCopyright());
3625 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3626 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003627 return(MagickFalse);
3628 }
3629 }
3630 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003631 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003632 format=(char *) NULL;
3633 path=(char *) NULL;
3634 global_colormap=MagickFalse;
3635 k=0;
3636 j=1;
3637 NewImageStack();
3638 option=(char *) NULL;
3639 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003640 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003641 status=MagickTrue;
3642 /*
3643 Parse command line.
3644 */
3645 ReadCommandlLine(argc,&argv);
3646 status=ExpandFilenames(&argc,&argv);
3647 if (status == MagickFalse)
3648 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3649 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003650 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003651 {
3652 option=argv[i];
3653 if (LocaleCompare(option,"(") == 0)
3654 {
3655 FireImageStack(MagickFalse,MagickTrue,pend);
3656 if (k == MaxImageStackDepth)
3657 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3658 option);
3659 PushImageStack();
3660 continue;
3661 }
3662 if (LocaleCompare(option,")") == 0)
3663 {
3664 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3665 if (k == 0)
3666 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3667 PopImageStack();
3668 continue;
3669 }
cristy042ee782011-04-22 18:48:30 +00003670 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003671 {
3672 char
3673 backup_filename[MaxTextExtent],
3674 *filename;
3675
3676 Image
3677 *images;
3678
3679 /*
3680 Option is a file name: begin by reading image from specified file.
3681 */
3682 FireImageStack(MagickFalse,MagickFalse,pend);
3683 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003684 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003685 filename=argv[++i];
3686 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3687 images=ReadImages(image_info,exception);
3688 status&=(images != (Image *) NULL) &&
3689 (exception->severity < ErrorException);
3690 if (images == (Image *) NULL)
3691 continue;
cristydaa76602010-06-30 13:05:11 +00003692 if (format != (char *) NULL)
3693 (void) CopyMagickString(images->filename,images->magick_filename,
3694 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003695 if (path != (char *) NULL)
3696 {
3697 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003698 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003699 path,*DirectorySeparator,filename);
3700 }
3701 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003702 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003703 AppendImageStack(images);
3704 FinalizeImageSettings(image_info,image,MagickFalse);
3705 if (global_colormap != MagickFalse)
3706 {
3707 QuantizeInfo
3708 *quantize_info;
3709
3710 quantize_info=AcquireQuantizeInfo(image_info);
3711 (void) RemapImages(quantize_info,images,(Image *) NULL);
3712 quantize_info=DestroyQuantizeInfo(quantize_info);
3713 }
3714 *backup_filename='\0';
3715 if ((LocaleCompare(image->filename,"-") != 0) &&
3716 (IsPathWritable(image->filename) != MagickFalse))
3717 {
cristybb503372010-05-27 20:51:26 +00003718 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003719 i;
3720
3721 /*
3722 Rename image file as backup.
3723 */
3724 (void) CopyMagickString(backup_filename,image->filename,
3725 MaxTextExtent);
3726 for (i=0; i < 6; i++)
3727 {
3728 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3729 if (IsPathAccessible(backup_filename) == MagickFalse)
3730 break;
3731 }
3732 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3733 (rename(image->filename,backup_filename) != 0))
3734 *backup_filename='\0';
3735 }
3736 /*
3737 Write transmogrified image to disk.
3738 */
3739 image_info->synchronize=MagickTrue;
3740 status&=WriteImages(image_info,image,image->filename,exception);
3741 if ((status == MagickFalse) && (*backup_filename != '\0'))
3742 (void) remove(backup_filename);
3743 RemoveAllImageStack();
3744 continue;
3745 }
3746 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3747 switch (*(option+1))
3748 {
3749 case 'a':
3750 {
3751 if (LocaleCompare("adaptive-blur",option+1) == 0)
3752 {
3753 i++;
cristybb503372010-05-27 20:51:26 +00003754 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003755 ThrowMogrifyException(OptionError,"MissingArgument",option);
3756 if (IsGeometry(argv[i]) == MagickFalse)
3757 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3758 break;
3759 }
3760 if (LocaleCompare("adaptive-resize",option+1) == 0)
3761 {
3762 i++;
cristybb503372010-05-27 20:51:26 +00003763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003764 ThrowMogrifyException(OptionError,"MissingArgument",option);
3765 if (IsGeometry(argv[i]) == MagickFalse)
3766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3767 break;
3768 }
3769 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3770 {
3771 i++;
cristybb503372010-05-27 20:51:26 +00003772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003773 ThrowMogrifyException(OptionError,"MissingArgument",option);
3774 if (IsGeometry(argv[i]) == MagickFalse)
3775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3776 break;
3777 }
3778 if (LocaleCompare("affine",option+1) == 0)
3779 {
3780 if (*option == '+')
3781 break;
3782 i++;
cristybb503372010-05-27 20:51:26 +00003783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003784 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003785 break;
3786 }
3787 if (LocaleCompare("alpha",option+1) == 0)
3788 {
cristybb503372010-05-27 20:51:26 +00003789 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003790 type;
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);
cristy042ee782011-04-22 18:48:30 +00003797 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003798 if (type < 0)
3799 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3800 argv[i]);
3801 break;
3802 }
3803 if (LocaleCompare("annotate",option+1) == 0)
3804 {
3805 if (*option == '+')
3806 break;
3807 i++;
cristybb503372010-05-27 20:51:26 +00003808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003809 ThrowMogrifyException(OptionError,"MissingArgument",option);
3810 if (IsGeometry(argv[i]) == MagickFalse)
3811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003812 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003813 ThrowMogrifyException(OptionError,"MissingArgument",option);
3814 i++;
3815 break;
3816 }
3817 if (LocaleCompare("antialias",option+1) == 0)
3818 break;
3819 if (LocaleCompare("append",option+1) == 0)
3820 break;
3821 if (LocaleCompare("attenuate",option+1) == 0)
3822 {
3823 if (*option == '+')
3824 break;
3825 i++;
cristybb503372010-05-27 20:51:26 +00003826 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003827 ThrowMogrifyException(OptionError,"MissingArgument",option);
3828 if (IsGeometry(argv[i]) == MagickFalse)
3829 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3830 break;
3831 }
3832 if (LocaleCompare("authenticate",option+1) == 0)
3833 {
3834 if (*option == '+')
3835 break;
3836 i++;
cristybb503372010-05-27 20:51:26 +00003837 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003838 ThrowMogrifyException(OptionError,"MissingArgument",option);
3839 break;
3840 }
3841 if (LocaleCompare("auto-gamma",option+1) == 0)
3842 break;
3843 if (LocaleCompare("auto-level",option+1) == 0)
3844 break;
3845 if (LocaleCompare("auto-orient",option+1) == 0)
3846 break;
3847 if (LocaleCompare("average",option+1) == 0)
3848 break;
3849 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3850 }
3851 case 'b':
3852 {
3853 if (LocaleCompare("background",option+1) == 0)
3854 {
3855 if (*option == '+')
3856 break;
3857 i++;
cristybb503372010-05-27 20:51:26 +00003858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003859 ThrowMogrifyException(OptionError,"MissingArgument",option);
3860 break;
3861 }
3862 if (LocaleCompare("bias",option+1) == 0)
3863 {
3864 if (*option == '+')
3865 break;
3866 i++;
cristybb503372010-05-27 20:51:26 +00003867 if (i == (ssize_t) (argc-1))
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("black-point-compensation",option+1) == 0)
3874 break;
3875 if (LocaleCompare("black-threshold",option+1) == 0)
3876 {
3877 if (*option == '+')
3878 break;
3879 i++;
cristybb503372010-05-27 20:51:26 +00003880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003881 ThrowMogrifyException(OptionError,"MissingArgument",option);
3882 if (IsGeometry(argv[i]) == MagickFalse)
3883 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3884 break;
3885 }
3886 if (LocaleCompare("blue-primary",option+1) == 0)
3887 {
3888 if (*option == '+')
3889 break;
3890 i++;
cristybb503372010-05-27 20:51:26 +00003891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003892 ThrowMogrifyException(OptionError,"MissingArgument",option);
3893 if (IsGeometry(argv[i]) == MagickFalse)
3894 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3895 break;
3896 }
3897 if (LocaleCompare("blue-shift",option+1) == 0)
3898 {
3899 i++;
cristybb503372010-05-27 20:51:26 +00003900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003901 ThrowMogrifyException(OptionError,"MissingArgument",option);
3902 if (IsGeometry(argv[i]) == MagickFalse)
3903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3904 break;
3905 }
3906 if (LocaleCompare("blur",option+1) == 0)
3907 {
3908 i++;
cristybb503372010-05-27 20:51:26 +00003909 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003910 ThrowMogrifyException(OptionError,"MissingArgument",option);
3911 if (IsGeometry(argv[i]) == MagickFalse)
3912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3913 break;
3914 }
3915 if (LocaleCompare("border",option+1) == 0)
3916 {
3917 if (*option == '+')
3918 break;
3919 i++;
cristybb503372010-05-27 20:51:26 +00003920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003921 ThrowMogrifyException(OptionError,"MissingArgument",option);
3922 if (IsGeometry(argv[i]) == MagickFalse)
3923 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3924 break;
3925 }
3926 if (LocaleCompare("bordercolor",option+1) == 0)
3927 {
3928 if (*option == '+')
3929 break;
3930 i++;
cristybb503372010-05-27 20:51:26 +00003931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003932 ThrowMogrifyException(OptionError,"MissingArgument",option);
3933 break;
3934 }
3935 if (LocaleCompare("box",option+1) == 0)
3936 {
3937 if (*option == '+')
3938 break;
3939 i++;
cristybb503372010-05-27 20:51:26 +00003940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003941 ThrowMogrifyException(OptionError,"MissingArgument",option);
3942 break;
3943 }
cristya28d6b82010-01-11 20:03:47 +00003944 if (LocaleCompare("brightness-contrast",option+1) == 0)
3945 {
3946 i++;
cristybb503372010-05-27 20:51:26 +00003947 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003948 ThrowMogrifyException(OptionError,"MissingArgument",option);
3949 if (IsGeometry(argv[i]) == MagickFalse)
3950 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3951 break;
3952 }
cristy3ed852e2009-09-05 21:47:34 +00003953 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3954 }
3955 case 'c':
3956 {
3957 if (LocaleCompare("cache",option+1) == 0)
3958 {
3959 if (*option == '+')
3960 break;
3961 i++;
cristybb503372010-05-27 20:51:26 +00003962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003963 ThrowMogrifyException(OptionError,"MissingArgument",option);
3964 if (IsGeometry(argv[i]) == MagickFalse)
3965 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3966 break;
3967 }
3968 if (LocaleCompare("caption",option+1) == 0)
3969 {
3970 if (*option == '+')
3971 break;
3972 i++;
cristybb503372010-05-27 20:51:26 +00003973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003974 ThrowMogrifyException(OptionError,"MissingArgument",option);
3975 break;
3976 }
3977 if (LocaleCompare("channel",option+1) == 0)
3978 {
cristybb503372010-05-27 20:51:26 +00003979 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003980 channel;
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 channel=ParseChannelOption(argv[i]);
3988 if (channel < 0)
3989 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3990 argv[i]);
3991 break;
3992 }
3993 if (LocaleCompare("cdl",option+1) == 0)
3994 {
3995 if (*option == '+')
3996 break;
3997 i++;
cristybb503372010-05-27 20:51:26 +00003998 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003999 ThrowMogrifyException(OptionError,"MissingArgument",option);
4000 break;
4001 }
4002 if (LocaleCompare("charcoal",option+1) == 0)
4003 {
4004 if (*option == '+')
4005 break;
4006 i++;
cristybb503372010-05-27 20:51:26 +00004007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004008 ThrowMogrifyException(OptionError,"MissingArgument",option);
4009 if (IsGeometry(argv[i]) == MagickFalse)
4010 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4011 break;
4012 }
4013 if (LocaleCompare("chop",option+1) == 0)
4014 {
4015 if (*option == '+')
4016 break;
4017 i++;
cristybb503372010-05-27 20:51:26 +00004018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004019 ThrowMogrifyException(OptionError,"MissingArgument",option);
4020 if (IsGeometry(argv[i]) == MagickFalse)
4021 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4022 break;
4023 }
cristy1eb45dd2009-09-25 16:38:06 +00004024 if (LocaleCompare("clamp",option+1) == 0)
4025 break;
4026 if (LocaleCompare("clip",option+1) == 0)
4027 break;
cristy3ed852e2009-09-05 21:47:34 +00004028 if (LocaleCompare("clip-mask",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 break;
4036 }
4037 if (LocaleCompare("clut",option+1) == 0)
4038 break;
4039 if (LocaleCompare("coalesce",option+1) == 0)
4040 break;
4041 if (LocaleCompare("colorize",option+1) == 0)
4042 {
4043 if (*option == '+')
4044 break;
4045 i++;
cristybb503372010-05-27 20:51:26 +00004046 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004047 ThrowMogrifyException(OptionError,"MissingArgument",option);
4048 if (IsGeometry(argv[i]) == MagickFalse)
4049 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4050 break;
4051 }
cristye6365592010-04-02 17:31:23 +00004052 if (LocaleCompare("color-matrix",option+1) == 0)
4053 {
cristyb6bd4ad2010-08-08 01:12:27 +00004054 KernelInfo
4055 *kernel_info;
4056
cristye6365592010-04-02 17:31:23 +00004057 if (*option == '+')
4058 break;
4059 i++;
cristybb503372010-05-27 20:51:26 +00004060 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004061 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004062 kernel_info=AcquireKernelInfo(argv[i]);
4063 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004065 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004066 break;
4067 }
cristy3ed852e2009-09-05 21:47:34 +00004068 if (LocaleCompare("colors",option+1) == 0)
4069 {
4070 if (*option == '+')
4071 break;
4072 i++;
cristybb503372010-05-27 20:51:26 +00004073 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004074 ThrowMogrifyException(OptionError,"MissingArgument",option);
4075 if (IsGeometry(argv[i]) == MagickFalse)
4076 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4077 break;
4078 }
4079 if (LocaleCompare("colorspace",option+1) == 0)
4080 {
cristybb503372010-05-27 20:51:26 +00004081 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004082 colorspace;
4083
4084 if (*option == '+')
4085 break;
4086 i++;
cristybb503372010-05-27 20:51:26 +00004087 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004088 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004089 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004090 argv[i]);
4091 if (colorspace < 0)
4092 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4093 argv[i]);
4094 break;
4095 }
4096 if (LocaleCompare("combine",option+1) == 0)
4097 break;
4098 if (LocaleCompare("comment",option+1) == 0)
4099 {
4100 if (*option == '+')
4101 break;
4102 i++;
cristybb503372010-05-27 20:51:26 +00004103 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004104 ThrowMogrifyException(OptionError,"MissingArgument",option);
4105 break;
4106 }
4107 if (LocaleCompare("composite",option+1) == 0)
4108 break;
4109 if (LocaleCompare("compress",option+1) == 0)
4110 {
cristybb503372010-05-27 20:51:26 +00004111 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004112 compress;
4113
4114 if (*option == '+')
4115 break;
4116 i++;
cristybb503372010-05-27 20:51:26 +00004117 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004118 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004119 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004120 argv[i]);
4121 if (compress < 0)
4122 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4123 argv[i]);
4124 break;
4125 }
cristy22879752009-10-25 23:55:40 +00004126 if (LocaleCompare("concurrent",option+1) == 0)
4127 break;
cristy3ed852e2009-09-05 21:47:34 +00004128 if (LocaleCompare("contrast",option+1) == 0)
4129 break;
4130 if (LocaleCompare("contrast-stretch",option+1) == 0)
4131 {
4132 i++;
cristybb503372010-05-27 20:51:26 +00004133 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004134 ThrowMogrifyException(OptionError,"MissingArgument",option);
4135 if (IsGeometry(argv[i]) == MagickFalse)
4136 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4137 break;
4138 }
4139 if (LocaleCompare("convolve",option+1) == 0)
4140 {
cristyb6bd4ad2010-08-08 01:12:27 +00004141 KernelInfo
4142 *kernel_info;
4143
cristy3ed852e2009-09-05 21:47:34 +00004144 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);
cristyb6bd4ad2010-08-08 01:12:27 +00004149 kernel_info=AcquireKernelInfo(argv[i]);
4150 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004151 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004152 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004153 break;
4154 }
4155 if (LocaleCompare("crop",option+1) == 0)
4156 {
4157 if (*option == '+')
4158 break;
4159 i++;
cristybb503372010-05-27 20:51:26 +00004160 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004161 ThrowMogrifyException(OptionError,"MissingArgument",option);
4162 if (IsGeometry(argv[i]) == MagickFalse)
4163 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4164 break;
4165 }
4166 if (LocaleCompare("cycle",option+1) == 0)
4167 {
4168 if (*option == '+')
4169 break;
4170 i++;
cristybb503372010-05-27 20:51:26 +00004171 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004172 ThrowMogrifyException(OptionError,"MissingArgument",option);
4173 if (IsGeometry(argv[i]) == MagickFalse)
4174 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4175 break;
4176 }
4177 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4178 }
4179 case 'd':
4180 {
4181 if (LocaleCompare("decipher",option+1) == 0)
4182 {
4183 if (*option == '+')
4184 break;
4185 i++;
cristybb503372010-05-27 20:51:26 +00004186 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004187 ThrowMogrifyException(OptionError,"MissingArgument",option);
4188 break;
4189 }
4190 if (LocaleCompare("deconstruct",option+1) == 0)
4191 break;
4192 if (LocaleCompare("debug",option+1) == 0)
4193 {
cristybb503372010-05-27 20:51:26 +00004194 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004195 event;
4196
4197 if (*option == '+')
4198 break;
4199 i++;
cristybb503372010-05-27 20:51:26 +00004200 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004201 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004202 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004203 if (event < 0)
4204 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4205 argv[i]);
4206 (void) SetLogEventMask(argv[i]);
4207 break;
4208 }
4209 if (LocaleCompare("define",option+1) == 0)
4210 {
4211 i++;
cristybb503372010-05-27 20:51:26 +00004212 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004213 ThrowMogrifyException(OptionError,"MissingArgument",option);
4214 if (*option == '+')
4215 {
4216 const char
4217 *define;
4218
4219 define=GetImageOption(image_info,argv[i]);
4220 if (define == (const char *) NULL)
4221 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4222 break;
4223 }
4224 break;
4225 }
4226 if (LocaleCompare("delay",option+1) == 0)
4227 {
4228 if (*option == '+')
4229 break;
4230 i++;
cristybb503372010-05-27 20:51:26 +00004231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004232 ThrowMogrifyException(OptionError,"MissingArgument",option);
4233 if (IsGeometry(argv[i]) == MagickFalse)
4234 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4235 break;
4236 }
cristyecb10ff2011-03-22 13:14:03 +00004237 if (LocaleCompare("delete",option+1) == 0)
4238 {
4239 if (*option == '+')
4240 break;
4241 i++;
4242 if (i == (ssize_t) (argc-1))
4243 ThrowMogrifyException(OptionError,"MissingArgument",option);
4244 if (IsGeometry(argv[i]) == MagickFalse)
4245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4246 break;
4247 }
cristy3ed852e2009-09-05 21:47:34 +00004248 if (LocaleCompare("density",option+1) == 0)
4249 {
4250 if (*option == '+')
4251 break;
4252 i++;
cristybb503372010-05-27 20:51:26 +00004253 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004254 ThrowMogrifyException(OptionError,"MissingArgument",option);
4255 if (IsGeometry(argv[i]) == MagickFalse)
4256 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4257 break;
4258 }
4259 if (LocaleCompare("depth",option+1) == 0)
4260 {
4261 if (*option == '+')
4262 break;
4263 i++;
cristybb503372010-05-27 20:51:26 +00004264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004265 ThrowMogrifyException(OptionError,"MissingArgument",option);
4266 if (IsGeometry(argv[i]) == MagickFalse)
4267 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4268 break;
4269 }
4270 if (LocaleCompare("deskew",option+1) == 0)
4271 {
4272 if (*option == '+')
4273 break;
4274 i++;
cristybb503372010-05-27 20:51:26 +00004275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004276 ThrowMogrifyException(OptionError,"MissingArgument",option);
4277 if (IsGeometry(argv[i]) == MagickFalse)
4278 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4279 break;
4280 }
4281 if (LocaleCompare("despeckle",option+1) == 0)
4282 break;
4283 if (LocaleCompare("dft",option+1) == 0)
4284 break;
cristyc9b12952010-03-28 01:12:28 +00004285 if (LocaleCompare("direction",option+1) == 0)
4286 {
cristybb503372010-05-27 20:51:26 +00004287 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004288 direction;
4289
4290 if (*option == '+')
4291 break;
4292 i++;
cristybb503372010-05-27 20:51:26 +00004293 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004294 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004295 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004296 argv[i]);
4297 if (direction < 0)
4298 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4299 argv[i]);
4300 break;
4301 }
cristy3ed852e2009-09-05 21:47:34 +00004302 if (LocaleCompare("display",option+1) == 0)
4303 {
4304 if (*option == '+')
4305 break;
4306 i++;
cristybb503372010-05-27 20:51:26 +00004307 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004308 ThrowMogrifyException(OptionError,"MissingArgument",option);
4309 break;
4310 }
4311 if (LocaleCompare("dispose",option+1) == 0)
4312 {
cristybb503372010-05-27 20:51:26 +00004313 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004314 dispose;
4315
4316 if (*option == '+')
4317 break;
4318 i++;
cristybb503372010-05-27 20:51:26 +00004319 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004320 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004321 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004322 if (dispose < 0)
4323 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4324 argv[i]);
4325 break;
4326 }
4327 if (LocaleCompare("distort",option+1) == 0)
4328 {
cristybb503372010-05-27 20:51:26 +00004329 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004330 op;
4331
4332 i++;
cristybb503372010-05-27 20:51:26 +00004333 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004334 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004335 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004336 if (op < 0)
4337 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4338 argv[i]);
4339 i++;
cristybb503372010-05-27 20:51:26 +00004340 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004341 ThrowMogrifyException(OptionError,"MissingArgument",option);
4342 break;
4343 }
4344 if (LocaleCompare("dither",option+1) == 0)
4345 {
cristybb503372010-05-27 20:51:26 +00004346 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004347 method;
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);
cristy042ee782011-04-22 18:48:30 +00004354 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004355 if (method < 0)
4356 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4357 argv[i]);
4358 break;
4359 }
4360 if (LocaleCompare("draw",option+1) == 0)
4361 {
4362 if (*option == '+')
4363 break;
4364 i++;
cristybb503372010-05-27 20:51:26 +00004365 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004366 ThrowMogrifyException(OptionError,"MissingArgument",option);
4367 break;
4368 }
cristyecb10ff2011-03-22 13:14:03 +00004369 if (LocaleCompare("duplicate",option+1) == 0)
4370 {
4371 if (*option == '+')
4372 break;
4373 i++;
4374 if (i == (ssize_t) (argc-1))
4375 ThrowMogrifyException(OptionError,"MissingArgument",option);
4376 if (IsGeometry(argv[i]) == MagickFalse)
4377 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4378 break;
4379 }
cristy22879752009-10-25 23:55:40 +00004380 if (LocaleCompare("duration",option+1) == 0)
4381 {
4382 if (*option == '+')
4383 break;
4384 i++;
cristybb503372010-05-27 20:51:26 +00004385 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004386 ThrowMogrifyException(OptionError,"MissingArgument",option);
4387 if (IsGeometry(argv[i]) == MagickFalse)
4388 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4389 break;
4390 }
cristy3ed852e2009-09-05 21:47:34 +00004391 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4392 }
4393 case 'e':
4394 {
4395 if (LocaleCompare("edge",option+1) == 0)
4396 {
4397 if (*option == '+')
4398 break;
4399 i++;
cristybb503372010-05-27 20:51:26 +00004400 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004401 ThrowMogrifyException(OptionError,"MissingArgument",option);
4402 if (IsGeometry(argv[i]) == MagickFalse)
4403 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4404 break;
4405 }
4406 if (LocaleCompare("emboss",option+1) == 0)
4407 {
4408 if (*option == '+')
4409 break;
4410 i++;
cristybb503372010-05-27 20:51:26 +00004411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004412 ThrowMogrifyException(OptionError,"MissingArgument",option);
4413 if (IsGeometry(argv[i]) == MagickFalse)
4414 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4415 break;
4416 }
4417 if (LocaleCompare("encipher",option+1) == 0)
4418 {
4419 if (*option == '+')
4420 break;
4421 i++;
cristybb503372010-05-27 20:51:26 +00004422 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004423 ThrowMogrifyException(OptionError,"MissingArgument",option);
4424 break;
4425 }
4426 if (LocaleCompare("encoding",option+1) == 0)
4427 {
4428 if (*option == '+')
4429 break;
4430 i++;
cristybb503372010-05-27 20:51:26 +00004431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004432 ThrowMogrifyException(OptionError,"MissingArgument",option);
4433 break;
4434 }
4435 if (LocaleCompare("endian",option+1) == 0)
4436 {
cristybb503372010-05-27 20:51:26 +00004437 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004438 endian;
4439
4440 if (*option == '+')
4441 break;
4442 i++;
cristybb503372010-05-27 20:51:26 +00004443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004444 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004445 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004446 if (endian < 0)
4447 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4448 argv[i]);
4449 break;
4450 }
4451 if (LocaleCompare("enhance",option+1) == 0)
4452 break;
4453 if (LocaleCompare("equalize",option+1) == 0)
4454 break;
4455 if (LocaleCompare("evaluate",option+1) == 0)
4456 {
cristybb503372010-05-27 20:51:26 +00004457 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004458 op;
4459
4460 if (*option == '+')
4461 break;
4462 i++;
cristybb503372010-05-27 20:51:26 +00004463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004464 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004465 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004466 if (op < 0)
4467 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4468 argv[i]);
4469 i++;
cristybb503372010-05-27 20:51:26 +00004470 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004471 ThrowMogrifyException(OptionError,"MissingArgument",option);
4472 if (IsGeometry(argv[i]) == MagickFalse)
4473 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4474 break;
4475 }
cristyd18ae7c2010-03-07 17:39:52 +00004476 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4477 {
cristybb503372010-05-27 20:51:26 +00004478 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004479 op;
4480
4481 if (*option == '+')
4482 break;
4483 i++;
cristybb503372010-05-27 20:51:26 +00004484 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004485 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004486 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004487 if (op < 0)
4488 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4489 argv[i]);
4490 break;
4491 }
cristy3ed852e2009-09-05 21:47:34 +00004492 if (LocaleCompare("extent",option+1) == 0)
4493 {
4494 if (*option == '+')
4495 break;
4496 i++;
cristybb503372010-05-27 20:51:26 +00004497 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004498 ThrowMogrifyException(OptionError,"MissingArgument",option);
4499 if (IsGeometry(argv[i]) == MagickFalse)
4500 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4501 break;
4502 }
4503 if (LocaleCompare("extract",option+1) == 0)
4504 {
4505 if (*option == '+')
4506 break;
4507 i++;
cristybb503372010-05-27 20:51:26 +00004508 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004509 ThrowMogrifyException(OptionError,"MissingArgument",option);
4510 if (IsGeometry(argv[i]) == MagickFalse)
4511 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4512 break;
4513 }
4514 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4515 }
4516 case 'f':
4517 {
4518 if (LocaleCompare("family",option+1) == 0)
4519 {
4520 if (*option == '+')
4521 break;
4522 i++;
cristybb503372010-05-27 20:51:26 +00004523 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004524 ThrowMogrifyException(OptionError,"MissingArgument",option);
4525 break;
4526 }
4527 if (LocaleCompare("fill",option+1) == 0)
4528 {
4529 if (*option == '+')
4530 break;
4531 i++;
cristybb503372010-05-27 20:51:26 +00004532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004533 ThrowMogrifyException(OptionError,"MissingArgument",option);
4534 break;
4535 }
4536 if (LocaleCompare("filter",option+1) == 0)
4537 {
cristybb503372010-05-27 20:51:26 +00004538 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004539 filter;
4540
4541 if (*option == '+')
4542 break;
4543 i++;
cristybb503372010-05-27 20:51:26 +00004544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004545 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004546 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004547 if (filter < 0)
4548 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4549 argv[i]);
4550 break;
4551 }
4552 if (LocaleCompare("flatten",option+1) == 0)
4553 break;
4554 if (LocaleCompare("flip",option+1) == 0)
4555 break;
4556 if (LocaleCompare("flop",option+1) == 0)
4557 break;
4558 if (LocaleCompare("floodfill",option+1) == 0)
4559 {
4560 if (*option == '+')
4561 break;
4562 i++;
cristybb503372010-05-27 20:51:26 +00004563 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004564 ThrowMogrifyException(OptionError,"MissingArgument",option);
4565 if (IsGeometry(argv[i]) == MagickFalse)
4566 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4567 i++;
cristybb503372010-05-27 20:51:26 +00004568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004569 ThrowMogrifyException(OptionError,"MissingArgument",option);
4570 break;
4571 }
4572 if (LocaleCompare("font",option+1) == 0)
4573 {
4574 if (*option == '+')
4575 break;
4576 i++;
cristybb503372010-05-27 20:51:26 +00004577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004578 ThrowMogrifyException(OptionError,"MissingArgument",option);
4579 break;
4580 }
4581 if (LocaleCompare("format",option+1) == 0)
4582 {
4583 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4584 (void) CloneString(&format,(char *) NULL);
4585 if (*option == '+')
4586 break;
4587 i++;
cristybb503372010-05-27 20:51:26 +00004588 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004589 ThrowMogrifyException(OptionError,"MissingArgument",option);
4590 (void) CloneString(&format,argv[i]);
4591 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4592 (void) ConcatenateMagickString(image_info->filename,":",
4593 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004594 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004595 if (*image_info->magick == '\0')
4596 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4597 format);
4598 break;
4599 }
4600 if (LocaleCompare("frame",option+1) == 0)
4601 {
4602 if (*option == '+')
4603 break;
4604 i++;
cristybb503372010-05-27 20:51:26 +00004605 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004606 ThrowMogrifyException(OptionError,"MissingArgument",option);
4607 if (IsGeometry(argv[i]) == MagickFalse)
4608 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4609 break;
4610 }
4611 if (LocaleCompare("function",option+1) == 0)
4612 {
cristybb503372010-05-27 20:51:26 +00004613 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004614 op;
4615
4616 if (*option == '+')
4617 break;
4618 i++;
cristybb503372010-05-27 20:51:26 +00004619 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004620 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004621 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004622 if (op < 0)
4623 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4624 i++;
cristybb503372010-05-27 20:51:26 +00004625 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004626 ThrowMogrifyException(OptionError,"MissingArgument",option);
4627 break;
4628 }
4629 if (LocaleCompare("fuzz",option+1) == 0)
4630 {
4631 if (*option == '+')
4632 break;
4633 i++;
cristybb503372010-05-27 20:51:26 +00004634 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004635 ThrowMogrifyException(OptionError,"MissingArgument",option);
4636 if (IsGeometry(argv[i]) == MagickFalse)
4637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4638 break;
4639 }
4640 if (LocaleCompare("fx",option+1) == 0)
4641 {
4642 if (*option == '+')
4643 break;
4644 i++;
cristybb503372010-05-27 20:51:26 +00004645 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004646 ThrowMogrifyException(OptionError,"MissingArgument",option);
4647 break;
4648 }
4649 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4650 }
4651 case 'g':
4652 {
4653 if (LocaleCompare("gamma",option+1) == 0)
4654 {
4655 i++;
cristybb503372010-05-27 20:51:26 +00004656 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004657 ThrowMogrifyException(OptionError,"MissingArgument",option);
4658 if (IsGeometry(argv[i]) == MagickFalse)
4659 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4660 break;
4661 }
4662 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4663 (LocaleCompare("gaussian",option+1) == 0))
4664 {
4665 i++;
cristybb503372010-05-27 20:51:26 +00004666 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004667 ThrowMogrifyException(OptionError,"MissingArgument",option);
4668 if (IsGeometry(argv[i]) == MagickFalse)
4669 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4670 break;
4671 }
4672 if (LocaleCompare("geometry",option+1) == 0)
4673 {
4674 if (*option == '+')
4675 break;
4676 i++;
cristybb503372010-05-27 20:51:26 +00004677 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004678 ThrowMogrifyException(OptionError,"MissingArgument",option);
4679 if (IsGeometry(argv[i]) == MagickFalse)
4680 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4681 break;
4682 }
4683 if (LocaleCompare("gravity",option+1) == 0)
4684 {
cristybb503372010-05-27 20:51:26 +00004685 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004686 gravity;
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);
cristy042ee782011-04-22 18:48:30 +00004693 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004694 if (gravity < 0)
4695 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4696 argv[i]);
4697 break;
4698 }
4699 if (LocaleCompare("green-primary",option+1) == 0)
4700 {
4701 if (*option == '+')
4702 break;
4703 i++;
cristybb503372010-05-27 20:51:26 +00004704 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004705 ThrowMogrifyException(OptionError,"MissingArgument",option);
4706 if (IsGeometry(argv[i]) == MagickFalse)
4707 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4708 break;
4709 }
4710 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4711 }
4712 case 'h':
4713 {
4714 if (LocaleCompare("hald-clut",option+1) == 0)
4715 break;
4716 if ((LocaleCompare("help",option+1) == 0) ||
4717 (LocaleCompare("-help",option+1) == 0))
4718 return(MogrifyUsage());
4719 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4720 }
4721 case 'i':
4722 {
4723 if (LocaleCompare("identify",option+1) == 0)
4724 break;
4725 if (LocaleCompare("idft",option+1) == 0)
4726 break;
4727 if (LocaleCompare("implode",option+1) == 0)
4728 {
4729 if (*option == '+')
4730 break;
4731 i++;
cristybb503372010-05-27 20:51:26 +00004732 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004733 ThrowMogrifyException(OptionError,"MissingArgument",option);
4734 if (IsGeometry(argv[i]) == MagickFalse)
4735 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4736 break;
4737 }
4738 if (LocaleCompare("intent",option+1) == 0)
4739 {
cristybb503372010-05-27 20:51:26 +00004740 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004741 intent;
4742
4743 if (*option == '+')
4744 break;
4745 i++;
cristybb503372010-05-27 20:51:26 +00004746 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004747 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004748 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004749 if (intent < 0)
4750 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4751 argv[i]);
4752 break;
4753 }
4754 if (LocaleCompare("interlace",option+1) == 0)
4755 {
cristybb503372010-05-27 20:51:26 +00004756 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004757 interlace;
4758
4759 if (*option == '+')
4760 break;
4761 i++;
cristybb503372010-05-27 20:51:26 +00004762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004763 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004764 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004765 argv[i]);
4766 if (interlace < 0)
4767 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4768 argv[i]);
4769 break;
4770 }
cristyb32b90a2009-09-07 21:45:48 +00004771 if (LocaleCompare("interline-spacing",option+1) == 0)
4772 {
4773 if (*option == '+')
4774 break;
4775 i++;
cristybb503372010-05-27 20:51:26 +00004776 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004777 ThrowMogrifyException(OptionError,"MissingArgument",option);
4778 if (IsGeometry(argv[i]) == MagickFalse)
4779 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4780 break;
4781 }
cristy3ed852e2009-09-05 21:47:34 +00004782 if (LocaleCompare("interpolate",option+1) == 0)
4783 {
cristybb503372010-05-27 20:51:26 +00004784 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004785 interpolate;
4786
4787 if (*option == '+')
4788 break;
4789 i++;
cristybb503372010-05-27 20:51:26 +00004790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004791 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004792 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004793 argv[i]);
4794 if (interpolate < 0)
4795 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4796 argv[i]);
4797 break;
4798 }
4799 if (LocaleCompare("interword-spacing",option+1) == 0)
4800 {
4801 if (*option == '+')
4802 break;
4803 i++;
cristybb503372010-05-27 20:51:26 +00004804 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004805 ThrowMogrifyException(OptionError,"MissingArgument",option);
4806 if (IsGeometry(argv[i]) == MagickFalse)
4807 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4808 break;
4809 }
4810 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4811 }
4812 case 'k':
4813 {
4814 if (LocaleCompare("kerning",option+1) == 0)
4815 {
4816 if (*option == '+')
4817 break;
4818 i++;
cristybb503372010-05-27 20:51:26 +00004819 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004820 ThrowMogrifyException(OptionError,"MissingArgument",option);
4821 if (IsGeometry(argv[i]) == MagickFalse)
4822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4823 break;
4824 }
4825 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4826 }
4827 case 'l':
4828 {
4829 if (LocaleCompare("label",option+1) == 0)
4830 {
4831 if (*option == '+')
4832 break;
4833 i++;
cristybb503372010-05-27 20:51:26 +00004834 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004835 ThrowMogrifyException(OptionError,"MissingArgument",option);
4836 break;
4837 }
4838 if (LocaleCompare("lat",option+1) == 0)
4839 {
4840 if (*option == '+')
4841 break;
4842 i++;
cristybb503372010-05-27 20:51:26 +00004843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004844 ThrowMogrifyException(OptionError,"MissingArgument",option);
4845 if (IsGeometry(argv[i]) == MagickFalse)
4846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4847 }
4848 if (LocaleCompare("layers",option+1) == 0)
4849 {
cristybb503372010-05-27 20:51:26 +00004850 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004851 type;
4852
4853 if (*option == '+')
4854 break;
4855 i++;
cristybb503372010-05-27 20:51:26 +00004856 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004857 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004858 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004859 if (type < 0)
4860 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4861 argv[i]);
4862 break;
4863 }
4864 if (LocaleCompare("level",option+1) == 0)
4865 {
4866 i++;
cristybb503372010-05-27 20:51:26 +00004867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004868 ThrowMogrifyException(OptionError,"MissingArgument",option);
4869 if (IsGeometry(argv[i]) == MagickFalse)
4870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4871 break;
4872 }
4873 if (LocaleCompare("level-colors",option+1) == 0)
4874 {
4875 i++;
cristybb503372010-05-27 20:51:26 +00004876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004877 ThrowMogrifyException(OptionError,"MissingArgument",option);
4878 break;
4879 }
4880 if (LocaleCompare("linewidth",option+1) == 0)
4881 {
4882 if (*option == '+')
4883 break;
4884 i++;
cristybb503372010-05-27 20:51:26 +00004885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004886 ThrowMogrifyException(OptionError,"MissingArgument",option);
4887 if (IsGeometry(argv[i]) == MagickFalse)
4888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4889 break;
4890 }
4891 if (LocaleCompare("limit",option+1) == 0)
4892 {
4893 char
4894 *p;
4895
4896 double
4897 value;
4898
cristybb503372010-05-27 20:51:26 +00004899 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004900 resource;
4901
4902 if (*option == '+')
4903 break;
4904 i++;
cristybb503372010-05-27 20:51:26 +00004905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004906 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004907 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004908 argv[i]);
4909 if (resource < 0)
4910 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4911 argv[i]);
4912 i++;
cristybb503372010-05-27 20:51:26 +00004913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004914 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004915 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004916 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004917 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4918 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4919 break;
4920 }
4921 if (LocaleCompare("liquid-rescale",option+1) == 0)
4922 {
4923 i++;
cristybb503372010-05-27 20:51:26 +00004924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004925 ThrowMogrifyException(OptionError,"MissingArgument",option);
4926 if (IsGeometry(argv[i]) == MagickFalse)
4927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4928 break;
4929 }
4930 if (LocaleCompare("list",option+1) == 0)
4931 {
cristybb503372010-05-27 20:51:26 +00004932 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004933 list;
4934
4935 if (*option == '+')
4936 break;
4937 i++;
cristybb503372010-05-27 20:51:26 +00004938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004939 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004940 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004941 if (list < 0)
4942 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004943 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004944 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004945 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004946 }
4947 if (LocaleCompare("log",option+1) == 0)
4948 {
4949 if (*option == '+')
4950 break;
4951 i++;
cristybb503372010-05-27 20:51:26 +00004952 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004953 (strchr(argv[i],'%') == (char *) NULL))
4954 ThrowMogrifyException(OptionError,"MissingArgument",option);
4955 break;
4956 }
4957 if (LocaleCompare("loop",option+1) == 0)
4958 {
4959 if (*option == '+')
4960 break;
4961 i++;
cristybb503372010-05-27 20:51:26 +00004962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004963 ThrowMogrifyException(OptionError,"MissingArgument",option);
4964 if (IsGeometry(argv[i]) == MagickFalse)
4965 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4966 break;
4967 }
4968 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4969 }
4970 case 'm':
4971 {
4972 if (LocaleCompare("map",option+1) == 0)
4973 {
4974 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4975 if (*option == '+')
4976 break;
4977 i++;
cristybb503372010-05-27 20:51:26 +00004978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004979 ThrowMogrifyException(OptionError,"MissingArgument",option);
4980 break;
4981 }
4982 if (LocaleCompare("mask",option+1) == 0)
4983 {
4984 if (*option == '+')
4985 break;
4986 i++;
cristybb503372010-05-27 20:51:26 +00004987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004988 ThrowMogrifyException(OptionError,"MissingArgument",option);
4989 break;
4990 }
4991 if (LocaleCompare("matte",option+1) == 0)
4992 break;
4993 if (LocaleCompare("mattecolor",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 break;
5001 }
cristyf40785b2010-03-06 02:27:27 +00005002 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005003 break;
cristyf40785b2010-03-06 02:27:27 +00005004 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005005 break;
cristy3ed852e2009-09-05 21:47:34 +00005006 if (LocaleCompare("modulate",option+1) == 0)
5007 {
5008 if (*option == '+')
5009 break;
5010 i++;
cristybb503372010-05-27 20:51:26 +00005011 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005012 ThrowMogrifyException(OptionError,"MissingArgument",option);
5013 if (IsGeometry(argv[i]) == MagickFalse)
5014 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5015 break;
5016 }
5017 if (LocaleCompare("median",option+1) == 0)
5018 {
5019 if (*option == '+')
5020 break;
5021 i++;
cristybb503372010-05-27 20:51:26 +00005022 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005023 ThrowMogrifyException(OptionError,"MissingArgument",option);
5024 if (IsGeometry(argv[i]) == MagickFalse)
5025 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5026 break;
5027 }
cristy69ec32d2011-02-27 23:57:09 +00005028 if (LocaleCompare("mode",option+1) == 0)
5029 {
5030 if (*option == '+')
5031 break;
5032 i++;
5033 if (i == (ssize_t) argc)
5034 ThrowMogrifyException(OptionError,"MissingArgument",option);
5035 if (IsGeometry(argv[i]) == MagickFalse)
5036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5037 break;
5038 }
cristy3ed852e2009-09-05 21:47:34 +00005039 if (LocaleCompare("monitor",option+1) == 0)
5040 break;
5041 if (LocaleCompare("monochrome",option+1) == 0)
5042 break;
5043 if (LocaleCompare("morph",option+1) == 0)
5044 {
5045 if (*option == '+')
5046 break;
5047 i++;
cristybb503372010-05-27 20:51:26 +00005048 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005049 ThrowMogrifyException(OptionError,"MissingArgument",option);
5050 if (IsGeometry(argv[i]) == MagickFalse)
5051 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5052 break;
5053 }
anthony29188a82010-01-22 10:12:34 +00005054 if (LocaleCompare("morphology",option+1) == 0)
5055 {
anthony29188a82010-01-22 10:12:34 +00005056 char
5057 token[MaxTextExtent];
5058
cristyb6bd4ad2010-08-08 01:12:27 +00005059 KernelInfo
5060 *kernel_info;
5061
5062 ssize_t
5063 op;
5064
anthony29188a82010-01-22 10:12:34 +00005065 i++;
cristybb503372010-05-27 20:51:26 +00005066 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005067 ThrowMogrifyException(OptionError,"MissingArgument",option);
5068 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005069 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005070 if (op < 0)
5071 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005072 token);
anthony29188a82010-01-22 10:12:34 +00005073 i++;
cristybb503372010-05-27 20:51:26 +00005074 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005075 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005076 kernel_info=AcquireKernelInfo(argv[i]);
5077 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005078 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005079 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005080 break;
5081 }
cristy3ed852e2009-09-05 21:47:34 +00005082 if (LocaleCompare("mosaic",option+1) == 0)
5083 break;
5084 if (LocaleCompare("motion-blur",option+1) == 0)
5085 {
5086 if (*option == '+')
5087 break;
5088 i++;
cristybb503372010-05-27 20:51:26 +00005089 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005090 ThrowMogrifyException(OptionError,"MissingArgument",option);
5091 if (IsGeometry(argv[i]) == MagickFalse)
5092 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5093 break;
5094 }
5095 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5096 }
5097 case 'n':
5098 {
5099 if (LocaleCompare("negate",option+1) == 0)
5100 break;
5101 if (LocaleCompare("noise",option+1) == 0)
5102 {
5103 i++;
cristybb503372010-05-27 20:51:26 +00005104 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005105 ThrowMogrifyException(OptionError,"MissingArgument",option);
5106 if (*option == '+')
5107 {
cristybb503372010-05-27 20:51:26 +00005108 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005109 noise;
5110
cristy042ee782011-04-22 18:48:30 +00005111 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005112 if (noise < 0)
5113 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5114 argv[i]);
5115 break;
5116 }
5117 if (IsGeometry(argv[i]) == MagickFalse)
5118 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5119 break;
5120 }
5121 if (LocaleCompare("noop",option+1) == 0)
5122 break;
5123 if (LocaleCompare("normalize",option+1) == 0)
5124 break;
5125 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5126 }
5127 case 'o':
5128 {
5129 if (LocaleCompare("opaque",option+1) == 0)
5130 {
cristy3ed852e2009-09-05 21:47:34 +00005131 i++;
cristybb503372010-05-27 20:51:26 +00005132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005133 ThrowMogrifyException(OptionError,"MissingArgument",option);
5134 break;
5135 }
5136 if (LocaleCompare("ordered-dither",option+1) == 0)
5137 {
5138 if (*option == '+')
5139 break;
5140 i++;
cristybb503372010-05-27 20:51:26 +00005141 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005142 ThrowMogrifyException(OptionError,"MissingArgument",option);
5143 break;
5144 }
5145 if (LocaleCompare("orient",option+1) == 0)
5146 {
cristybb503372010-05-27 20:51:26 +00005147 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005148 orientation;
5149
5150 orientation=UndefinedOrientation;
5151 if (*option == '+')
5152 break;
5153 i++;
cristybb503372010-05-27 20:51:26 +00005154 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005155 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005156 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005157 argv[i]);
5158 if (orientation < 0)
5159 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5160 argv[i]);
5161 break;
5162 }
5163 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5164 }
5165 case 'p':
5166 {
5167 if (LocaleCompare("page",option+1) == 0)
5168 {
5169 if (*option == '+')
5170 break;
5171 i++;
cristybb503372010-05-27 20:51:26 +00005172 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005173 ThrowMogrifyException(OptionError,"MissingArgument",option);
5174 break;
5175 }
5176 if (LocaleCompare("paint",option+1) == 0)
5177 {
5178 if (*option == '+')
5179 break;
5180 i++;
cristybb503372010-05-27 20:51:26 +00005181 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005182 ThrowMogrifyException(OptionError,"MissingArgument",option);
5183 if (IsGeometry(argv[i]) == MagickFalse)
5184 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5185 break;
5186 }
5187 if (LocaleCompare("path",option+1) == 0)
5188 {
5189 (void) CloneString(&path,(char *) NULL);
5190 if (*option == '+')
5191 break;
5192 i++;
cristybb503372010-05-27 20:51:26 +00005193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005194 ThrowMogrifyException(OptionError,"MissingArgument",option);
5195 (void) CloneString(&path,argv[i]);
5196 break;
5197 }
5198 if (LocaleCompare("pointsize",option+1) == 0)
5199 {
5200 if (*option == '+')
5201 break;
5202 i++;
cristybb503372010-05-27 20:51:26 +00005203 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005204 ThrowMogrifyException(OptionError,"MissingArgument",option);
5205 if (IsGeometry(argv[i]) == MagickFalse)
5206 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5207 break;
5208 }
5209 if (LocaleCompare("polaroid",option+1) == 0)
5210 {
5211 if (*option == '+')
5212 break;
5213 i++;
cristybb503372010-05-27 20:51:26 +00005214 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005215 ThrowMogrifyException(OptionError,"MissingArgument",option);
5216 if (IsGeometry(argv[i]) == MagickFalse)
5217 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5218 break;
5219 }
5220 if (LocaleCompare("posterize",option+1) == 0)
5221 {
5222 if (*option == '+')
5223 break;
5224 i++;
cristybb503372010-05-27 20:51:26 +00005225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005226 ThrowMogrifyException(OptionError,"MissingArgument",option);
5227 if (IsGeometry(argv[i]) == MagickFalse)
5228 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5229 break;
5230 }
cristye7f51092010-01-17 00:39:37 +00005231 if (LocaleCompare("precision",option+1) == 0)
5232 {
5233 if (*option == '+')
5234 break;
5235 i++;
cristybb503372010-05-27 20:51:26 +00005236 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005237 ThrowMogrifyException(OptionError,"MissingArgument",option);
5238 if (IsGeometry(argv[i]) == MagickFalse)
5239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5240 break;
5241 }
cristy3ed852e2009-09-05 21:47:34 +00005242 if (LocaleCompare("print",option+1) == 0)
5243 {
5244 if (*option == '+')
5245 break;
5246 i++;
cristybb503372010-05-27 20:51:26 +00005247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005248 ThrowMogrifyException(OptionError,"MissingArgument",option);
5249 break;
5250 }
5251 if (LocaleCompare("process",option+1) == 0)
5252 {
5253 if (*option == '+')
5254 break;
5255 i++;
cristybb503372010-05-27 20:51:26 +00005256 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005257 ThrowMogrifyException(OptionError,"MissingArgument",option);
5258 break;
5259 }
5260 if (LocaleCompare("profile",option+1) == 0)
5261 {
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 break;
5266 }
5267 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5268 }
5269 case 'q':
5270 {
5271 if (LocaleCompare("quality",option+1) == 0)
5272 {
5273 if (*option == '+')
5274 break;
5275 i++;
cristybb503372010-05-27 20:51:26 +00005276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005277 ThrowMogrifyException(OptionError,"MissingArgument",option);
5278 if (IsGeometry(argv[i]) == MagickFalse)
5279 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5280 break;
5281 }
5282 if (LocaleCompare("quantize",option+1) == 0)
5283 {
cristybb503372010-05-27 20:51:26 +00005284 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005285 colorspace;
5286
5287 if (*option == '+')
5288 break;
5289 i++;
cristybb503372010-05-27 20:51:26 +00005290 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005291 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005292 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005293 argv[i]);
5294 if (colorspace < 0)
5295 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5296 argv[i]);
5297 break;
5298 }
5299 if (LocaleCompare("quiet",option+1) == 0)
5300 break;
5301 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5302 }
5303 case 'r':
5304 {
5305 if (LocaleCompare("radial-blur",option+1) == 0)
5306 {
5307 i++;
cristybb503372010-05-27 20:51:26 +00005308 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005309 ThrowMogrifyException(OptionError,"MissingArgument",option);
5310 if (IsGeometry(argv[i]) == MagickFalse)
5311 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5312 break;
5313 }
5314 if (LocaleCompare("raise",option+1) == 0)
5315 {
5316 i++;
cristybb503372010-05-27 20:51:26 +00005317 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005318 ThrowMogrifyException(OptionError,"MissingArgument",option);
5319 if (IsGeometry(argv[i]) == MagickFalse)
5320 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5321 break;
5322 }
5323 if (LocaleCompare("random-threshold",option+1) == 0)
5324 {
5325 if (*option == '+')
5326 break;
5327 i++;
cristybb503372010-05-27 20:51:26 +00005328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005329 ThrowMogrifyException(OptionError,"MissingArgument",option);
5330 if (IsGeometry(argv[i]) == MagickFalse)
5331 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5332 break;
5333 }
cristye6365592010-04-02 17:31:23 +00005334 if (LocaleCompare("recolor",option+1) == 0)
5335 {
5336 if (*option == '+')
5337 break;
5338 i++;
cristybb503372010-05-27 20:51:26 +00005339 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005340 ThrowMogrifyException(OptionError,"MissingArgument",option);
5341 if (IsGeometry(argv[i]) == MagickFalse)
5342 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5343 break;
5344 }
cristy3ed852e2009-09-05 21:47:34 +00005345 if (LocaleCompare("red-primary",option+1) == 0)
5346 {
5347 if (*option == '+')
5348 break;
5349 i++;
cristybb503372010-05-27 20:51:26 +00005350 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005351 ThrowMogrifyException(OptionError,"MissingArgument",option);
5352 if (IsGeometry(argv[i]) == MagickFalse)
5353 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5354 }
cristy9f2083a2010-04-22 19:48:05 +00005355 if (LocaleCompare("regard-warnings",option+1) == 0)
5356 break;
cristy3ed852e2009-09-05 21:47:34 +00005357 if (LocaleCompare("region",option+1) == 0)
5358 {
5359 if (*option == '+')
5360 break;
5361 i++;
cristybb503372010-05-27 20:51:26 +00005362 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005363 ThrowMogrifyException(OptionError,"MissingArgument",option);
5364 if (IsGeometry(argv[i]) == MagickFalse)
5365 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5366 break;
5367 }
cristyf0c78232010-03-15 12:53:40 +00005368 if (LocaleCompare("remap",option+1) == 0)
5369 {
5370 if (*option == '+')
5371 break;
5372 i++;
cristybb503372010-05-27 20:51:26 +00005373 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005374 ThrowMogrifyException(OptionError,"MissingArgument",option);
5375 break;
5376 }
cristy3ed852e2009-09-05 21:47:34 +00005377 if (LocaleCompare("render",option+1) == 0)
5378 break;
5379 if (LocaleCompare("repage",option+1) == 0)
5380 {
5381 if (*option == '+')
5382 break;
5383 i++;
cristybb503372010-05-27 20:51:26 +00005384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005385 ThrowMogrifyException(OptionError,"MissingArgument",option);
5386 if (IsGeometry(argv[i]) == MagickFalse)
5387 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5388 break;
5389 }
5390 if (LocaleCompare("resample",option+1) == 0)
5391 {
5392 if (*option == '+')
5393 break;
5394 i++;
cristybb503372010-05-27 20:51:26 +00005395 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005396 ThrowMogrifyException(OptionError,"MissingArgument",option);
5397 if (IsGeometry(argv[i]) == MagickFalse)
5398 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5399 break;
5400 }
5401 if (LocaleCompare("resize",option+1) == 0)
5402 {
5403 if (*option == '+')
5404 break;
5405 i++;
cristybb503372010-05-27 20:51:26 +00005406 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005407 ThrowMogrifyException(OptionError,"MissingArgument",option);
5408 if (IsGeometry(argv[i]) == MagickFalse)
5409 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5410 break;
5411 }
cristyebbcfea2011-02-25 02:43:54 +00005412 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5413 {
5414 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5415 break;
5416 }
cristy3ed852e2009-09-05 21:47:34 +00005417 if (LocaleCompare("reverse",option+1) == 0)
5418 break;
5419 if (LocaleCompare("roll",option+1) == 0)
5420 {
5421 if (*option == '+')
5422 break;
5423 i++;
cristybb503372010-05-27 20:51:26 +00005424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005425 ThrowMogrifyException(OptionError,"MissingArgument",option);
5426 if (IsGeometry(argv[i]) == MagickFalse)
5427 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5428 break;
5429 }
5430 if (LocaleCompare("rotate",option+1) == 0)
5431 {
5432 i++;
cristybb503372010-05-27 20:51:26 +00005433 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005434 ThrowMogrifyException(OptionError,"MissingArgument",option);
5435 if (IsGeometry(argv[i]) == MagickFalse)
5436 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5437 break;
5438 }
5439 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5440 }
5441 case 's':
5442 {
5443 if (LocaleCompare("sample",option+1) == 0)
5444 {
5445 if (*option == '+')
5446 break;
5447 i++;
cristybb503372010-05-27 20:51:26 +00005448 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005449 ThrowMogrifyException(OptionError,"MissingArgument",option);
5450 if (IsGeometry(argv[i]) == MagickFalse)
5451 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5452 break;
5453 }
5454 if (LocaleCompare("sampling-factor",option+1) == 0)
5455 {
5456 if (*option == '+')
5457 break;
5458 i++;
cristybb503372010-05-27 20:51:26 +00005459 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005460 ThrowMogrifyException(OptionError,"MissingArgument",option);
5461 if (IsGeometry(argv[i]) == MagickFalse)
5462 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5463 break;
5464 }
5465 if (LocaleCompare("scale",option+1) == 0)
5466 {
5467 if (*option == '+')
5468 break;
5469 i++;
cristybb503372010-05-27 20:51:26 +00005470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005471 ThrowMogrifyException(OptionError,"MissingArgument",option);
5472 if (IsGeometry(argv[i]) == MagickFalse)
5473 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5474 break;
5475 }
5476 if (LocaleCompare("scene",option+1) == 0)
5477 {
5478 if (*option == '+')
5479 break;
5480 i++;
cristybb503372010-05-27 20:51:26 +00005481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005482 ThrowMogrifyException(OptionError,"MissingArgument",option);
5483 if (IsGeometry(argv[i]) == MagickFalse)
5484 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5485 break;
5486 }
5487 if (LocaleCompare("seed",option+1) == 0)
5488 {
5489 if (*option == '+')
5490 break;
5491 i++;
cristybb503372010-05-27 20:51:26 +00005492 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005493 ThrowMogrifyException(OptionError,"MissingArgument",option);
5494 if (IsGeometry(argv[i]) == MagickFalse)
5495 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5496 break;
5497 }
5498 if (LocaleCompare("segment",option+1) == 0)
5499 {
5500 if (*option == '+')
5501 break;
5502 i++;
cristybb503372010-05-27 20:51:26 +00005503 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005504 ThrowMogrifyException(OptionError,"MissingArgument",option);
5505 if (IsGeometry(argv[i]) == MagickFalse)
5506 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5507 break;
5508 }
5509 if (LocaleCompare("selective-blur",option+1) == 0)
5510 {
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("separate",option+1) == 0)
5519 break;
5520 if (LocaleCompare("sepia-tone",option+1) == 0)
5521 {
5522 if (*option == '+')
5523 break;
5524 i++;
cristybb503372010-05-27 20:51:26 +00005525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005526 ThrowMogrifyException(OptionError,"MissingArgument",option);
5527 if (IsGeometry(argv[i]) == MagickFalse)
5528 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5529 break;
5530 }
5531 if (LocaleCompare("set",option+1) == 0)
5532 {
5533 i++;
cristybb503372010-05-27 20:51:26 +00005534 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005535 ThrowMogrifyException(OptionError,"MissingArgument",option);
5536 if (*option == '+')
5537 break;
5538 i++;
cristybb503372010-05-27 20:51:26 +00005539 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005540 ThrowMogrifyException(OptionError,"MissingArgument",option);
5541 break;
5542 }
5543 if (LocaleCompare("shade",option+1) == 0)
5544 {
5545 i++;
cristybb503372010-05-27 20:51:26 +00005546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005547 ThrowMogrifyException(OptionError,"MissingArgument",option);
5548 if (IsGeometry(argv[i]) == MagickFalse)
5549 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550 break;
5551 }
5552 if (LocaleCompare("shadow",option+1) == 0)
5553 {
5554 if (*option == '+')
5555 break;
5556 i++;
cristybb503372010-05-27 20:51:26 +00005557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005558 ThrowMogrifyException(OptionError,"MissingArgument",option);
5559 if (IsGeometry(argv[i]) == MagickFalse)
5560 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5561 break;
5562 }
5563 if (LocaleCompare("sharpen",option+1) == 0)
5564 {
5565 i++;
cristybb503372010-05-27 20:51:26 +00005566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005567 ThrowMogrifyException(OptionError,"MissingArgument",option);
5568 if (IsGeometry(argv[i]) == MagickFalse)
5569 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5570 break;
5571 }
5572 if (LocaleCompare("shave",option+1) == 0)
5573 {
5574 if (*option == '+')
5575 break;
5576 i++;
cristybb503372010-05-27 20:51:26 +00005577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005578 ThrowMogrifyException(OptionError,"MissingArgument",option);
5579 if (IsGeometry(argv[i]) == MagickFalse)
5580 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5581 break;
5582 }
5583 if (LocaleCompare("shear",option+1) == 0)
5584 {
5585 i++;
cristybb503372010-05-27 20:51:26 +00005586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 if (IsGeometry(argv[i]) == MagickFalse)
5589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5590 break;
5591 }
5592 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5593 {
5594 i++;
cristybb503372010-05-27 20:51:26 +00005595 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005596 ThrowMogrifyException(OptionError,"MissingArgument",option);
5597 if (IsGeometry(argv[i]) == MagickFalse)
5598 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5599 break;
5600 }
5601 if (LocaleCompare("size",option+1) == 0)
5602 {
5603 if (*option == '+')
5604 break;
5605 i++;
cristybb503372010-05-27 20:51:26 +00005606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 if (IsGeometry(argv[i]) == MagickFalse)
5609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5610 break;
5611 }
5612 if (LocaleCompare("sketch",option+1) == 0)
5613 {
5614 if (*option == '+')
5615 break;
5616 i++;
cristybb503372010-05-27 20:51:26 +00005617 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005618 ThrowMogrifyException(OptionError,"MissingArgument",option);
5619 if (IsGeometry(argv[i]) == MagickFalse)
5620 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5621 break;
5622 }
cristy4285d782011-02-09 20:12:28 +00005623 if (LocaleCompare("smush",option+1) == 0)
5624 {
cristy4285d782011-02-09 20:12:28 +00005625 i++;
5626 if (i == (ssize_t) argc)
5627 ThrowMogrifyException(OptionError,"MissingArgument",option);
5628 if (IsGeometry(argv[i]) == MagickFalse)
5629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005630 i++;
5631 break;
5632 }
cristy3ed852e2009-09-05 21:47:34 +00005633 if (LocaleCompare("solarize",option+1) == 0)
5634 {
5635 if (*option == '+')
5636 break;
5637 i++;
cristybb503372010-05-27 20:51:26 +00005638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 if (IsGeometry(argv[i]) == MagickFalse)
5641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5642 break;
5643 }
5644 if (LocaleCompare("sparse-color",option+1) == 0)
5645 {
cristybb503372010-05-27 20:51:26 +00005646 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005647 op;
5648
5649 i++;
cristybb503372010-05-27 20:51:26 +00005650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005651 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005652 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005653 if (op < 0)
5654 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5655 argv[i]);
5656 i++;
cristybb503372010-05-27 20:51:26 +00005657 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005658 ThrowMogrifyException(OptionError,"MissingArgument",option);
5659 break;
5660 }
5661 if (LocaleCompare("spread",option+1) == 0)
5662 {
5663 if (*option == '+')
5664 break;
5665 i++;
cristybb503372010-05-27 20:51:26 +00005666 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005667 ThrowMogrifyException(OptionError,"MissingArgument",option);
5668 if (IsGeometry(argv[i]) == MagickFalse)
5669 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5670 break;
5671 }
cristy0834d642011-03-18 18:26:08 +00005672 if (LocaleCompare("statistic",option+1) == 0)
5673 {
5674 ssize_t
5675 op;
5676
5677 if (*option == '+')
5678 break;
5679 i++;
5680 if (i == (ssize_t) argc)
5681 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005682 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005683 if (op < 0)
5684 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5685 argv[i]);
5686 i++;
5687 if (i == (ssize_t) (argc-1))
5688 ThrowMogrifyException(OptionError,"MissingArgument",option);
5689 if (IsGeometry(argv[i]) == MagickFalse)
5690 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5691 break;
5692 }
cristy3ed852e2009-09-05 21:47:34 +00005693 if (LocaleCompare("stretch",option+1) == 0)
5694 {
cristybb503372010-05-27 20:51:26 +00005695 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005696 stretch;
5697
5698 if (*option == '+')
5699 break;
5700 i++;
cristybb503372010-05-27 20:51:26 +00005701 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005702 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005703 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005704 if (stretch < 0)
5705 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5706 argv[i]);
5707 break;
5708 }
5709 if (LocaleCompare("strip",option+1) == 0)
5710 break;
5711 if (LocaleCompare("stroke",option+1) == 0)
5712 {
5713 if (*option == '+')
5714 break;
5715 i++;
cristybb503372010-05-27 20:51:26 +00005716 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005717 ThrowMogrifyException(OptionError,"MissingArgument",option);
5718 break;
5719 }
5720 if (LocaleCompare("strokewidth",option+1) == 0)
5721 {
5722 if (*option == '+')
5723 break;
5724 i++;
cristybb503372010-05-27 20:51:26 +00005725 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005726 ThrowMogrifyException(OptionError,"MissingArgument",option);
5727 if (IsGeometry(argv[i]) == MagickFalse)
5728 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5729 break;
5730 }
5731 if (LocaleCompare("style",option+1) == 0)
5732 {
cristybb503372010-05-27 20:51:26 +00005733 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005734 style;
5735
5736 if (*option == '+')
5737 break;
5738 i++;
cristybb503372010-05-27 20:51:26 +00005739 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005740 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005741 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005742 if (style < 0)
5743 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5744 argv[i]);
5745 break;
5746 }
cristyecb10ff2011-03-22 13:14:03 +00005747 if (LocaleCompare("swap",option+1) == 0)
5748 {
5749 if (*option == '+')
5750 break;
5751 i++;
5752 if (i == (ssize_t) (argc-1))
5753 ThrowMogrifyException(OptionError,"MissingArgument",option);
5754 if (IsGeometry(argv[i]) == MagickFalse)
5755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5756 break;
5757 }
cristy3ed852e2009-09-05 21:47:34 +00005758 if (LocaleCompare("swirl",option+1) == 0)
5759 {
5760 if (*option == '+')
5761 break;
5762 i++;
cristybb503372010-05-27 20:51:26 +00005763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005764 ThrowMogrifyException(OptionError,"MissingArgument",option);
5765 if (IsGeometry(argv[i]) == MagickFalse)
5766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5767 break;
5768 }
cristyd9a29192010-10-16 16:49:53 +00005769 if (LocaleCompare("synchronize",option+1) == 0)
5770 break;
cristy3ed852e2009-09-05 21:47:34 +00005771 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5772 }
5773 case 't':
5774 {
5775 if (LocaleCompare("taint",option+1) == 0)
5776 break;
5777 if (LocaleCompare("texture",option+1) == 0)
5778 {
5779 if (*option == '+')
5780 break;
5781 i++;
cristybb503372010-05-27 20:51:26 +00005782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005783 ThrowMogrifyException(OptionError,"MissingArgument",option);
5784 break;
5785 }
5786 if (LocaleCompare("tile",option+1) == 0)
5787 {
5788 if (*option == '+')
5789 break;
5790 i++;
cristybb503372010-05-27 20:51:26 +00005791 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005792 ThrowMogrifyException(OptionError,"MissingArgument",option);
5793 break;
5794 }
5795 if (LocaleCompare("tile-offset",option+1) == 0)
5796 {
5797 if (*option == '+')
5798 break;
5799 i++;
cristybb503372010-05-27 20:51:26 +00005800 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005801 ThrowMogrifyException(OptionError,"MissingArgument",option);
5802 if (IsGeometry(argv[i]) == MagickFalse)
5803 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5804 break;
5805 }
5806 if (LocaleCompare("tint",option+1) == 0)
5807 {
5808 if (*option == '+')
5809 break;
5810 i++;
cristybb503372010-05-27 20:51:26 +00005811 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005812 ThrowMogrifyException(OptionError,"MissingArgument",option);
5813 if (IsGeometry(argv[i]) == MagickFalse)
5814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5815 break;
5816 }
5817 if (LocaleCompare("transform",option+1) == 0)
5818 break;
5819 if (LocaleCompare("transpose",option+1) == 0)
5820 break;
5821 if (LocaleCompare("transverse",option+1) == 0)
5822 break;
5823 if (LocaleCompare("threshold",option+1) == 0)
5824 {
5825 if (*option == '+')
5826 break;
5827 i++;
cristybb503372010-05-27 20:51:26 +00005828 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005829 ThrowMogrifyException(OptionError,"MissingArgument",option);
5830 if (IsGeometry(argv[i]) == MagickFalse)
5831 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5832 break;
5833 }
5834 if (LocaleCompare("thumbnail",option+1) == 0)
5835 {
5836 if (*option == '+')
5837 break;
5838 i++;
cristybb503372010-05-27 20:51:26 +00005839 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005840 ThrowMogrifyException(OptionError,"MissingArgument",option);
5841 if (IsGeometry(argv[i]) == MagickFalse)
5842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5843 break;
5844 }
5845 if (LocaleCompare("transparent",option+1) == 0)
5846 {
5847 i++;
cristybb503372010-05-27 20:51:26 +00005848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005849 ThrowMogrifyException(OptionError,"MissingArgument",option);
5850 break;
5851 }
5852 if (LocaleCompare("transparent-color",option+1) == 0)
5853 {
5854 if (*option == '+')
5855 break;
5856 i++;
cristybb503372010-05-27 20:51:26 +00005857 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005858 ThrowMogrifyException(OptionError,"MissingArgument",option);
5859 break;
5860 }
5861 if (LocaleCompare("treedepth",option+1) == 0)
5862 {
5863 if (*option == '+')
5864 break;
5865 i++;
cristybb503372010-05-27 20:51:26 +00005866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005867 ThrowMogrifyException(OptionError,"MissingArgument",option);
5868 if (IsGeometry(argv[i]) == MagickFalse)
5869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5870 break;
5871 }
5872 if (LocaleCompare("trim",option+1) == 0)
5873 break;
5874 if (LocaleCompare("type",option+1) == 0)
5875 {
cristybb503372010-05-27 20:51:26 +00005876 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005877 type;
5878
5879 if (*option == '+')
5880 break;
5881 i++;
cristybb503372010-05-27 20:51:26 +00005882 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005883 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005884 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005885 if (type < 0)
5886 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5887 argv[i]);
5888 break;
5889 }
5890 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5891 }
5892 case 'u':
5893 {
5894 if (LocaleCompare("undercolor",option+1) == 0)
5895 {
5896 if (*option == '+')
5897 break;
5898 i++;
cristybb503372010-05-27 20:51:26 +00005899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005900 ThrowMogrifyException(OptionError,"MissingArgument",option);
5901 break;
5902 }
5903 if (LocaleCompare("unique-colors",option+1) == 0)
5904 break;
5905 if (LocaleCompare("units",option+1) == 0)
5906 {
cristybb503372010-05-27 20:51:26 +00005907 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005908 units;
5909
5910 if (*option == '+')
5911 break;
5912 i++;
cristybb503372010-05-27 20:51:26 +00005913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005914 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005915 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005916 argv[i]);
5917 if (units < 0)
5918 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5919 argv[i]);
5920 break;
5921 }
5922 if (LocaleCompare("unsharp",option+1) == 0)
5923 {
5924 i++;
cristybb503372010-05-27 20:51:26 +00005925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005926 ThrowMogrifyException(OptionError,"MissingArgument",option);
5927 if (IsGeometry(argv[i]) == MagickFalse)
5928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5929 break;
5930 }
5931 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5932 }
5933 case 'v':
5934 {
5935 if (LocaleCompare("verbose",option+1) == 0)
5936 {
5937 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5938 break;
5939 }
5940 if ((LocaleCompare("version",option+1) == 0) ||
5941 (LocaleCompare("-version",option+1) == 0))
5942 {
cristyb51dff52011-05-19 16:55:47 +00005943 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005944 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005945 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5946 GetMagickCopyright());
5947 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5948 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005949 break;
5950 }
5951 if (LocaleCompare("view",option+1) == 0)
5952 {
5953 if (*option == '+')
5954 break;
5955 i++;
cristybb503372010-05-27 20:51:26 +00005956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005957 ThrowMogrifyException(OptionError,"MissingArgument",option);
5958 break;
5959 }
5960 if (LocaleCompare("vignette",option+1) == 0)
5961 {
5962 if (*option == '+')
5963 break;
5964 i++;
cristybb503372010-05-27 20:51:26 +00005965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005966 ThrowMogrifyException(OptionError,"MissingArgument",option);
5967 if (IsGeometry(argv[i]) == MagickFalse)
5968 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5969 break;
5970 }
5971 if (LocaleCompare("virtual-pixel",option+1) == 0)
5972 {
cristybb503372010-05-27 20:51:26 +00005973 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005974 method;
5975
5976 if (*option == '+')
5977 break;
5978 i++;
cristybb503372010-05-27 20:51:26 +00005979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005980 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005981 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005982 argv[i]);
5983 if (method < 0)
5984 ThrowMogrifyException(OptionError,
5985 "UnrecognizedVirtualPixelMethod",argv[i]);
5986 break;
5987 }
5988 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5989 }
5990 case 'w':
5991 {
5992 if (LocaleCompare("wave",option+1) == 0)
5993 {
5994 i++;
cristybb503372010-05-27 20:51:26 +00005995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005996 ThrowMogrifyException(OptionError,"MissingArgument",option);
5997 if (IsGeometry(argv[i]) == MagickFalse)
5998 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5999 break;
6000 }
6001 if (LocaleCompare("weight",option+1) == 0)
6002 {
6003 if (*option == '+')
6004 break;
6005 i++;
cristybb503372010-05-27 20:51:26 +00006006 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006007 ThrowMogrifyException(OptionError,"MissingArgument",option);
6008 break;
6009 }
6010 if (LocaleCompare("white-point",option+1) == 0)
6011 {
6012 if (*option == '+')
6013 break;
6014 i++;
cristybb503372010-05-27 20:51:26 +00006015 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006016 ThrowMogrifyException(OptionError,"MissingArgument",option);
6017 if (IsGeometry(argv[i]) == MagickFalse)
6018 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6019 break;
6020 }
6021 if (LocaleCompare("white-threshold",option+1) == 0)
6022 {
6023 if (*option == '+')
6024 break;
6025 i++;
cristybb503372010-05-27 20:51:26 +00006026 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006027 ThrowMogrifyException(OptionError,"MissingArgument",option);
6028 if (IsGeometry(argv[i]) == MagickFalse)
6029 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6030 break;
6031 }
6032 if (LocaleCompare("write",option+1) == 0)
6033 {
6034 i++;
cristybb503372010-05-27 20:51:26 +00006035 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006036 ThrowMogrifyException(OptionError,"MissingArgument",option);
6037 break;
6038 }
6039 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6040 }
6041 case '?':
6042 break;
6043 default:
6044 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6045 }
cristy042ee782011-04-22 18:48:30 +00006046 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6047 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006048 if (fire != MagickFalse)
6049 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6050 }
6051 if (k != 0)
6052 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006053 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006054 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6055 DestroyMogrify();
6056 return(status != 0 ? MagickTrue : MagickFalse);
6057}
6058
6059/*
6060%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6061% %
6062% %
6063% %
6064+ M o g r i f y I m a g e I n f o %
6065% %
6066% %
6067% %
6068%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6069%
6070% MogrifyImageInfo() applies image processing settings to the image as
6071% prescribed by command line options.
6072%
6073% The format of the MogrifyImageInfo method is:
6074%
6075% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6076% const char **argv,ExceptionInfo *exception)
6077%
6078% A description of each parameter follows:
6079%
6080% o image_info: the image info..
6081%
6082% o argc: Specifies a pointer to an integer describing the number of
6083% elements in the argument vector.
6084%
6085% o argv: Specifies a pointer to a text array containing the command line
6086% arguments.
6087%
6088% o exception: return any errors or warnings in this structure.
6089%
6090*/
6091WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6092 const int argc,const char **argv,ExceptionInfo *exception)
6093{
6094 const char
6095 *option;
6096
6097 GeometryInfo
6098 geometry_info;
6099
cristybb503372010-05-27 20:51:26 +00006100 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006101 count;
6102
cristybb503372010-05-27 20:51:26 +00006103 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006104 i;
6105
6106 /*
6107 Initialize method variables.
6108 */
6109 assert(image_info != (ImageInfo *) NULL);
6110 assert(image_info->signature == MagickSignature);
6111 if (image_info->debug != MagickFalse)
6112 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6113 image_info->filename);
6114 if (argc < 0)
6115 return(MagickTrue);
6116 /*
6117 Set the image settings.
6118 */
cristybb503372010-05-27 20:51:26 +00006119 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006120 {
6121 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006122 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006123 continue;
cristy042ee782011-04-22 18:48:30 +00006124 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006125 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006126 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006127 break;
6128 switch (*(option+1))
6129 {
6130 case 'a':
6131 {
6132 if (LocaleCompare("adjoin",option+1) == 0)
6133 {
6134 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6135 break;
6136 }
6137 if (LocaleCompare("antialias",option+1) == 0)
6138 {
6139 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6140 break;
6141 }
6142 if (LocaleCompare("attenuate",option+1) == 0)
6143 {
6144 if (*option == '+')
6145 {
6146 (void) DeleteImageOption(image_info,option+1);
6147 break;
6148 }
6149 (void) SetImageOption(image_info,option+1,argv[i+1]);
6150 break;
6151 }
6152 if (LocaleCompare("authenticate",option+1) == 0)
6153 {
6154 if (*option == '+')
6155 (void) CloneString(&image_info->authenticate,(char *) NULL);
6156 else
6157 (void) CloneString(&image_info->authenticate,argv[i+1]);
6158 break;
6159 }
6160 break;
6161 }
6162 case 'b':
6163 {
6164 if (LocaleCompare("background",option+1) == 0)
6165 {
6166 if (*option == '+')
6167 {
6168 (void) DeleteImageOption(image_info,option+1);
6169 (void) QueryColorDatabase(BackgroundColor,
6170 &image_info->background_color,exception);
6171 break;
6172 }
6173 (void) SetImageOption(image_info,option+1,argv[i+1]);
6174 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6175 exception);
6176 break;
6177 }
6178 if (LocaleCompare("bias",option+1) == 0)
6179 {
6180 if (*option == '+')
6181 {
6182 (void) SetImageOption(image_info,option+1,"0.0");
6183 break;
6184 }
6185 (void) SetImageOption(image_info,option+1,argv[i+1]);
6186 break;
6187 }
6188 if (LocaleCompare("black-point-compensation",option+1) == 0)
6189 {
6190 if (*option == '+')
6191 {
6192 (void) SetImageOption(image_info,option+1,"false");
6193 break;
6194 }
6195 (void) SetImageOption(image_info,option+1,"true");
6196 break;
6197 }
6198 if (LocaleCompare("blue-primary",option+1) == 0)
6199 {
6200 if (*option == '+')
6201 {
6202 (void) SetImageOption(image_info,option+1,"0.0");
6203 break;
6204 }
6205 (void) SetImageOption(image_info,option+1,argv[i+1]);
6206 break;
6207 }
6208 if (LocaleCompare("bordercolor",option+1) == 0)
6209 {
6210 if (*option == '+')
6211 {
6212 (void) DeleteImageOption(image_info,option+1);
6213 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6214 exception);
6215 break;
6216 }
6217 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6218 exception);
6219 (void) SetImageOption(image_info,option+1,argv[i+1]);
6220 break;
6221 }
6222 if (LocaleCompare("box",option+1) == 0)
6223 {
6224 if (*option == '+')
6225 {
6226 (void) SetImageOption(image_info,"undercolor","none");
6227 break;
6228 }
6229 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6230 break;
6231 }
6232 break;
6233 }
6234 case 'c':
6235 {
6236 if (LocaleCompare("cache",option+1) == 0)
6237 {
6238 MagickSizeType
6239 limit;
6240
6241 limit=MagickResourceInfinity;
6242 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006243 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006244 (void) SetMagickResourceLimit(MemoryResource,limit);
6245 (void) SetMagickResourceLimit(MapResource,2*limit);
6246 break;
6247 }
6248 if (LocaleCompare("caption",option+1) == 0)
6249 {
6250 if (*option == '+')
6251 {
6252 (void) DeleteImageOption(image_info,option+1);
6253 break;
6254 }
6255 (void) SetImageOption(image_info,option+1,argv[i+1]);
6256 break;
6257 }
6258 if (LocaleCompare("channel",option+1) == 0)
6259 {
6260 if (*option == '+')
6261 {
6262 image_info->channel=DefaultChannels;
6263 break;
6264 }
6265 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6266 break;
6267 }
6268 if (LocaleCompare("colors",option+1) == 0)
6269 {
cristye27293e2009-12-18 02:53:20 +00006270 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006271 break;
6272 }
6273 if (LocaleCompare("colorspace",option+1) == 0)
6274 {
6275 if (*option == '+')
6276 {
6277 image_info->colorspace=UndefinedColorspace;
6278 (void) SetImageOption(image_info,option+1,"undefined");
6279 break;
6280 }
cristy042ee782011-04-22 18:48:30 +00006281 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006282 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6283 (void) SetImageOption(image_info,option+1,argv[i+1]);
6284 break;
6285 }
cristy3ed852e2009-09-05 21:47:34 +00006286 if (LocaleCompare("comment",option+1) == 0)
6287 {
6288 if (*option == '+')
6289 {
6290 (void) DeleteImageOption(image_info,option+1);
6291 break;
6292 }
6293 (void) SetImageOption(image_info,option+1,argv[i+1]);
6294 break;
6295 }
6296 if (LocaleCompare("compose",option+1) == 0)
6297 {
6298 if (*option == '+')
6299 {
6300 (void) SetImageOption(image_info,option+1,"undefined");
6301 break;
6302 }
6303 (void) SetImageOption(image_info,option+1,argv[i+1]);
6304 break;
6305 }
6306 if (LocaleCompare("compress",option+1) == 0)
6307 {
6308 if (*option == '+')
6309 {
6310 image_info->compression=UndefinedCompression;
6311 (void) SetImageOption(image_info,option+1,"undefined");
6312 break;
6313 }
cristy042ee782011-04-22 18:48:30 +00006314 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006315 MagickCompressOptions,MagickFalse,argv[i+1]);
6316 (void) SetImageOption(image_info,option+1,argv[i+1]);
6317 break;
6318 }
6319 break;
6320 }
6321 case 'd':
6322 {
6323 if (LocaleCompare("debug",option+1) == 0)
6324 {
6325 if (*option == '+')
6326 (void) SetLogEventMask("none");
6327 else
6328 (void) SetLogEventMask(argv[i+1]);
6329 image_info->debug=IsEventLogging();
6330 break;
6331 }
6332 if (LocaleCompare("define",option+1) == 0)
6333 {
6334 if (*option == '+')
6335 {
6336 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6337 (void) DeleteImageRegistry(argv[i+1]+9);
6338 else
6339 (void) DeleteImageOption(image_info,argv[i+1]);
6340 break;
6341 }
6342 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6343 {
6344 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6345 exception);
6346 break;
6347 }
6348 (void) DefineImageOption(image_info,argv[i+1]);
6349 break;
6350 }
6351 if (LocaleCompare("delay",option+1) == 0)
6352 {
6353 if (*option == '+')
6354 {
6355 (void) SetImageOption(image_info,option+1,"0");
6356 break;
6357 }
6358 (void) SetImageOption(image_info,option+1,argv[i+1]);
6359 break;
6360 }
6361 if (LocaleCompare("density",option+1) == 0)
6362 {
6363 /*
6364 Set image density.
6365 */
6366 if (*option == '+')
6367 {
6368 if (image_info->density != (char *) NULL)
6369 image_info->density=DestroyString(image_info->density);
6370 (void) SetImageOption(image_info,option+1,"72");
6371 break;
6372 }
6373 (void) CloneString(&image_info->density,argv[i+1]);
6374 (void) SetImageOption(image_info,option+1,argv[i+1]);
6375 break;
6376 }
6377 if (LocaleCompare("depth",option+1) == 0)
6378 {
6379 if (*option == '+')
6380 {
6381 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6382 break;
6383 }
cristye27293e2009-12-18 02:53:20 +00006384 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006385 break;
6386 }
cristyc9b12952010-03-28 01:12:28 +00006387 if (LocaleCompare("direction",option+1) == 0)
6388 {
6389 if (*option == '+')
6390 {
6391 (void) SetImageOption(image_info,option+1,"undefined");
6392 break;
6393 }
6394 (void) SetImageOption(image_info,option+1,argv[i+1]);
6395 break;
6396 }
cristy3ed852e2009-09-05 21:47:34 +00006397 if (LocaleCompare("display",option+1) == 0)
6398 {
6399 if (*option == '+')
6400 {
6401 if (image_info->server_name != (char *) NULL)
6402 image_info->server_name=DestroyString(
6403 image_info->server_name);
6404 break;
6405 }
6406 (void) CloneString(&image_info->server_name,argv[i+1]);
6407 break;
6408 }
6409 if (LocaleCompare("dispose",option+1) == 0)
6410 {
6411 if (*option == '+')
6412 {
6413 (void) SetImageOption(image_info,option+1,"undefined");
6414 break;
6415 }
6416 (void) SetImageOption(image_info,option+1,argv[i+1]);
6417 break;
6418 }
6419 if (LocaleCompare("dither",option+1) == 0)
6420 {
6421 if (*option == '+')
6422 {
6423 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006424 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006425 break;
6426 }
6427 (void) SetImageOption(image_info,option+1,argv[i+1]);
6428 image_info->dither=MagickTrue;
6429 break;
6430 }
6431 break;
6432 }
6433 case 'e':
6434 {
6435 if (LocaleCompare("encoding",option+1) == 0)
6436 {
6437 if (*option == '+')
6438 {
6439 (void) SetImageOption(image_info,option+1,"undefined");
6440 break;
6441 }
6442 (void) SetImageOption(image_info,option+1,argv[i+1]);
6443 break;
6444 }
6445 if (LocaleCompare("endian",option+1) == 0)
6446 {
6447 if (*option == '+')
6448 {
6449 image_info->endian=UndefinedEndian;
6450 (void) SetImageOption(image_info,option+1,"undefined");
6451 break;
6452 }
cristy042ee782011-04-22 18:48:30 +00006453 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006454 MagickEndianOptions,MagickFalse,argv[i+1]);
6455 (void) SetImageOption(image_info,option+1,argv[i+1]);
6456 break;
6457 }
6458 if (LocaleCompare("extract",option+1) == 0)
6459 {
6460 /*
6461 Set image extract geometry.
6462 */
6463 if (*option == '+')
6464 {
6465 if (image_info->extract != (char *) NULL)
6466 image_info->extract=DestroyString(image_info->extract);
6467 break;
6468 }
6469 (void) CloneString(&image_info->extract,argv[i+1]);
6470 break;
6471 }
6472 break;
6473 }
6474 case 'f':
6475 {
6476 if (LocaleCompare("fill",option+1) == 0)
6477 {
6478 if (*option == '+')
6479 {
6480 (void) SetImageOption(image_info,option+1,"none");
6481 break;
6482 }
6483 (void) SetImageOption(image_info,option+1,argv[i+1]);
6484 break;
6485 }
6486 if (LocaleCompare("filter",option+1) == 0)
6487 {
6488 if (*option == '+')
6489 {
6490 (void) SetImageOption(image_info,option+1,"undefined");
6491 break;
6492 }
6493 (void) SetImageOption(image_info,option+1,argv[i+1]);
6494 break;
6495 }
6496 if (LocaleCompare("font",option+1) == 0)
6497 {
6498 if (*option == '+')
6499 {
6500 if (image_info->font != (char *) NULL)
6501 image_info->font=DestroyString(image_info->font);
6502 break;
6503 }
6504 (void) CloneString(&image_info->font,argv[i+1]);
6505 break;
6506 }
6507 if (LocaleCompare("format",option+1) == 0)
6508 {
6509 register const char
6510 *q;
6511
6512 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006513 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006514 image_info->ping=MagickFalse;
6515 (void) SetImageOption(image_info,option+1,argv[i+1]);
6516 break;
6517 }
6518 if (LocaleCompare("fuzz",option+1) == 0)
6519 {
6520 if (*option == '+')
6521 {
6522 image_info->fuzz=0.0;
6523 (void) SetImageOption(image_info,option+1,"0");
6524 break;
6525 }
cristyf2f27272009-12-17 14:48:46 +00006526 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006527 1.0);
6528 (void) SetImageOption(image_info,option+1,argv[i+1]);
6529 break;
6530 }
6531 break;
6532 }
6533 case 'g':
6534 {
6535 if (LocaleCompare("gravity",option+1) == 0)
6536 {
6537 if (*option == '+')
6538 {
6539 (void) SetImageOption(image_info,option+1,"undefined");
6540 break;
6541 }
6542 (void) SetImageOption(image_info,option+1,argv[i+1]);
6543 break;
6544 }
6545 if (LocaleCompare("green-primary",option+1) == 0)
6546 {
6547 if (*option == '+')
6548 {
6549 (void) SetImageOption(image_info,option+1,"0.0");
6550 break;
6551 }
6552 (void) SetImageOption(image_info,option+1,argv[i+1]);
6553 break;
6554 }
6555 break;
6556 }
6557 case 'i':
6558 {
6559 if (LocaleCompare("intent",option+1) == 0)
6560 {
6561 if (*option == '+')
6562 {
6563 (void) SetImageOption(image_info,option+1,"undefined");
6564 break;
6565 }
6566 (void) SetImageOption(image_info,option+1,argv[i+1]);
6567 break;
6568 }
6569 if (LocaleCompare("interlace",option+1) == 0)
6570 {
6571 if (*option == '+')
6572 {
6573 image_info->interlace=UndefinedInterlace;
6574 (void) SetImageOption(image_info,option+1,"undefined");
6575 break;
6576 }
cristy042ee782011-04-22 18:48:30 +00006577 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006578 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6579 (void) SetImageOption(image_info,option+1,argv[i+1]);
6580 break;
6581 }
cristyb32b90a2009-09-07 21:45:48 +00006582 if (LocaleCompare("interline-spacing",option+1) == 0)
6583 {
6584 if (*option == '+')
6585 {
6586 (void) SetImageOption(image_info,option+1,"undefined");
6587 break;
6588 }
6589 (void) SetImageOption(image_info,option+1,argv[i+1]);
6590 break;
6591 }
cristy3ed852e2009-09-05 21:47:34 +00006592 if (LocaleCompare("interpolate",option+1) == 0)
6593 {
6594 if (*option == '+')
6595 {
6596 (void) SetImageOption(image_info,option+1,"undefined");
6597 break;
6598 }
6599 (void) SetImageOption(image_info,option+1,argv[i+1]);
6600 break;
6601 }
6602 if (LocaleCompare("interword-spacing",option+1) == 0)
6603 {
6604 if (*option == '+')
6605 {
6606 (void) SetImageOption(image_info,option+1,"undefined");
6607 break;
6608 }
6609 (void) SetImageOption(image_info,option+1,argv[i+1]);
6610 break;
6611 }
6612 break;
6613 }
6614 case 'k':
6615 {
6616 if (LocaleCompare("kerning",option+1) == 0)
6617 {
6618 if (*option == '+')
6619 {
6620 (void) SetImageOption(image_info,option+1,"undefined");
6621 break;
6622 }
6623 (void) SetImageOption(image_info,option+1,argv[i+1]);
6624 break;
6625 }
6626 break;
6627 }
6628 case 'l':
6629 {
6630 if (LocaleCompare("label",option+1) == 0)
6631 {
6632 if (*option == '+')
6633 {
6634 (void) DeleteImageOption(image_info,option+1);
6635 break;
6636 }
6637 (void) SetImageOption(image_info,option+1,argv[i+1]);
6638 break;
6639 }
6640 if (LocaleCompare("limit",option+1) == 0)
6641 {
6642 MagickSizeType
6643 limit;
6644
6645 ResourceType
6646 type;
6647
6648 if (*option == '+')
6649 break;
cristy042ee782011-04-22 18:48:30 +00006650 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006651 MagickFalse,argv[i+1]);
6652 limit=MagickResourceInfinity;
6653 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006654 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006655 (void) SetMagickResourceLimit(type,limit);
6656 break;
6657 }
6658 if (LocaleCompare("list",option+1) == 0)
6659 {
cristybb503372010-05-27 20:51:26 +00006660 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006661 list;
6662
6663 /*
6664 Display configuration list.
6665 */
cristy042ee782011-04-22 18:48:30 +00006666 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006667 switch (list)
6668 {
6669 case MagickCoderOptions:
6670 {
6671 (void) ListCoderInfo((FILE *) NULL,exception);
6672 break;
6673 }
6674 case MagickColorOptions:
6675 {
6676 (void) ListColorInfo((FILE *) NULL,exception);
6677 break;
6678 }
6679 case MagickConfigureOptions:
6680 {
6681 (void) ListConfigureInfo((FILE *) NULL,exception);
6682 break;
6683 }
6684 case MagickDelegateOptions:
6685 {
6686 (void) ListDelegateInfo((FILE *) NULL,exception);
6687 break;
6688 }
6689 case MagickFontOptions:
6690 {
6691 (void) ListTypeInfo((FILE *) NULL,exception);
6692 break;
6693 }
6694 case MagickFormatOptions:
6695 {
6696 (void) ListMagickInfo((FILE *) NULL,exception);
6697 break;
6698 }
6699 case MagickLocaleOptions:
6700 {
6701 (void) ListLocaleInfo((FILE *) NULL,exception);
6702 break;
6703 }
6704 case MagickLogOptions:
6705 {
6706 (void) ListLogInfo((FILE *) NULL,exception);
6707 break;
6708 }
6709 case MagickMagicOptions:
6710 {
6711 (void) ListMagicInfo((FILE *) NULL,exception);
6712 break;
6713 }
6714 case MagickMimeOptions:
6715 {
6716 (void) ListMimeInfo((FILE *) NULL,exception);
6717 break;
6718 }
6719 case MagickModuleOptions:
6720 {
6721 (void) ListModuleInfo((FILE *) NULL,exception);
6722 break;
6723 }
6724 case MagickPolicyOptions:
6725 {
6726 (void) ListPolicyInfo((FILE *) NULL,exception);
6727 break;
6728 }
6729 case MagickResourceOptions:
6730 {
6731 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6732 break;
6733 }
6734 case MagickThresholdOptions:
6735 {
6736 (void) ListThresholdMaps((FILE *) NULL,exception);
6737 break;
6738 }
6739 default:
6740 {
cristy042ee782011-04-22 18:48:30 +00006741 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006742 exception);
6743 break;
6744 }
6745 }
cristyaeb2cbc2010-05-07 13:28:58 +00006746 break;
cristy3ed852e2009-09-05 21:47:34 +00006747 }
6748 if (LocaleCompare("log",option+1) == 0)
6749 {
6750 if (*option == '+')
6751 break;
6752 (void) SetLogFormat(argv[i+1]);
6753 break;
6754 }
6755 if (LocaleCompare("loop",option+1) == 0)
6756 {
6757 if (*option == '+')
6758 {
6759 (void) SetImageOption(image_info,option+1,"0");
6760 break;
6761 }
6762 (void) SetImageOption(image_info,option+1,argv[i+1]);
6763 break;
6764 }
6765 break;
6766 }
6767 case 'm':
6768 {
6769 if (LocaleCompare("matte",option+1) == 0)
6770 {
6771 if (*option == '+')
6772 {
6773 (void) SetImageOption(image_info,option+1,"false");
6774 break;
6775 }
6776 (void) SetImageOption(image_info,option+1,"true");
6777 break;
6778 }
6779 if (LocaleCompare("mattecolor",option+1) == 0)
6780 {
6781 if (*option == '+')
6782 {
6783 (void) SetImageOption(image_info,option+1,argv[i+1]);
6784 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6785 exception);
6786 break;
6787 }
6788 (void) SetImageOption(image_info,option+1,argv[i+1]);
6789 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6790 exception);
6791 break;
6792 }
6793 if (LocaleCompare("monitor",option+1) == 0)
6794 {
6795 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6796 (void *) NULL);
6797 break;
6798 }
6799 if (LocaleCompare("monochrome",option+1) == 0)
6800 {
6801 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6802 break;
6803 }
6804 break;
6805 }
6806 case 'o':
6807 {
6808 if (LocaleCompare("orient",option+1) == 0)
6809 {
6810 if (*option == '+')
6811 {
6812 image_info->orientation=UndefinedOrientation;
6813 (void) SetImageOption(image_info,option+1,"undefined");
6814 break;
6815 }
cristy042ee782011-04-22 18:48:30 +00006816 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006817 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006818 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006819 break;
6820 }
6821 }
6822 case 'p':
6823 {
6824 if (LocaleCompare("page",option+1) == 0)
6825 {
6826 char
6827 *canonical_page,
6828 page[MaxTextExtent];
6829
6830 const char
6831 *image_option;
6832
6833 MagickStatusType
6834 flags;
6835
6836 RectangleInfo
6837 geometry;
6838
6839 if (*option == '+')
6840 {
6841 (void) DeleteImageOption(image_info,option+1);
6842 (void) CloneString(&image_info->page,(char *) NULL);
6843 break;
6844 }
6845 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6846 image_option=GetImageOption(image_info,"page");
6847 if (image_option != (const char *) NULL)
6848 flags=ParseAbsoluteGeometry(image_option,&geometry);
6849 canonical_page=GetPageGeometry(argv[i+1]);
6850 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6851 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006852 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006853 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006854 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006855 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006856 (unsigned long) geometry.width,(unsigned long) geometry.height,
6857 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006858 (void) SetImageOption(image_info,option+1,page);
6859 (void) CloneString(&image_info->page,page);
6860 break;
6861 }
6862 if (LocaleCompare("pen",option+1) == 0)
6863 {
6864 if (*option == '+')
6865 {
6866 (void) SetImageOption(image_info,option+1,"none");
6867 break;
6868 }
6869 (void) SetImageOption(image_info,option+1,argv[i+1]);
6870 break;
6871 }
6872 if (LocaleCompare("ping",option+1) == 0)
6873 {
6874 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6875 break;
6876 }
6877 if (LocaleCompare("pointsize",option+1) == 0)
6878 {
6879 if (*option == '+')
6880 geometry_info.rho=0.0;
6881 else
6882 (void) ParseGeometry(argv[i+1],&geometry_info);
6883 image_info->pointsize=geometry_info.rho;
6884 break;
6885 }
cristye7f51092010-01-17 00:39:37 +00006886 if (LocaleCompare("precision",option+1) == 0)
6887 {
cristybf2766a2010-01-17 03:33:23 +00006888 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006889 break;
6890 }
cristy3ed852e2009-09-05 21:47:34 +00006891 if (LocaleCompare("preview",option+1) == 0)
6892 {
6893 /*
6894 Preview image.
6895 */
6896 if (*option == '+')
6897 {
6898 image_info->preview_type=UndefinedPreview;
6899 break;
6900 }
cristy042ee782011-04-22 18:48:30 +00006901 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006902 MagickPreviewOptions,MagickFalse,argv[i+1]);
6903 break;
6904 }
6905 break;
6906 }
6907 case 'q':
6908 {
6909 if (LocaleCompare("quality",option+1) == 0)
6910 {
6911 /*
6912 Set image compression quality.
6913 */
6914 if (*option == '+')
6915 {
6916 image_info->quality=UndefinedCompressionQuality;
6917 (void) SetImageOption(image_info,option+1,"0");
6918 break;
6919 }
cristye27293e2009-12-18 02:53:20 +00006920 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006921 (void) SetImageOption(image_info,option+1,argv[i+1]);
6922 break;
6923 }
6924 if (LocaleCompare("quiet",option+1) == 0)
6925 {
6926 static WarningHandler
6927 warning_handler = (WarningHandler) NULL;
6928
6929 if (*option == '+')
6930 {
6931 /*
6932 Restore error or warning messages.
6933 */
6934 warning_handler=SetWarningHandler(warning_handler);
6935 break;
6936 }
6937 /*
6938 Suppress error or warning messages.
6939 */
6940 warning_handler=SetWarningHandler((WarningHandler) NULL);
6941 break;
6942 }
6943 break;
6944 }
6945 case 'r':
6946 {
6947 if (LocaleCompare("red-primary",option+1) == 0)
6948 {
6949 if (*option == '+')
6950 {
6951 (void) SetImageOption(image_info,option+1,"0.0");
6952 break;
6953 }
6954 (void) SetImageOption(image_info,option+1,argv[i+1]);
6955 break;
6956 }
6957 break;
6958 }
6959 case 's':
6960 {
6961 if (LocaleCompare("sampling-factor",option+1) == 0)
6962 {
6963 /*
6964 Set image sampling factor.
6965 */
6966 if (*option == '+')
6967 {
6968 if (image_info->sampling_factor != (char *) NULL)
6969 image_info->sampling_factor=DestroyString(
6970 image_info->sampling_factor);
6971 break;
6972 }
6973 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6974 break;
6975 }
6976 if (LocaleCompare("scene",option+1) == 0)
6977 {
6978 /*
6979 Set image scene.
6980 */
6981 if (*option == '+')
6982 {
6983 image_info->scene=0;
6984 (void) SetImageOption(image_info,option+1,"0");
6985 break;
6986 }
cristye27293e2009-12-18 02:53:20 +00006987 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006988 (void) SetImageOption(image_info,option+1,argv[i+1]);
6989 break;
6990 }
6991 if (LocaleCompare("seed",option+1) == 0)
6992 {
cristybb503372010-05-27 20:51:26 +00006993 size_t
cristy3ed852e2009-09-05 21:47:34 +00006994 seed;
6995
6996 if (*option == '+')
6997 {
cristybb503372010-05-27 20:51:26 +00006998 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006999 SeedPseudoRandomGenerator(seed);
7000 break;
7001 }
cristye27293e2009-12-18 02:53:20 +00007002 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007003 SeedPseudoRandomGenerator(seed);
7004 break;
7005 }
7006 if (LocaleCompare("size",option+1) == 0)
7007 {
7008 if (*option == '+')
7009 {
7010 if (image_info->size != (char *) NULL)
7011 image_info->size=DestroyString(image_info->size);
7012 break;
7013 }
7014 (void) CloneString(&image_info->size,argv[i+1]);
7015 break;
7016 }
7017 if (LocaleCompare("stroke",option+1) == 0)
7018 {
7019 if (*option == '+')
7020 {
7021 (void) SetImageOption(image_info,option+1,"none");
7022 break;
7023 }
7024 (void) SetImageOption(image_info,option+1,argv[i+1]);
7025 break;
7026 }
7027 if (LocaleCompare("strokewidth",option+1) == 0)
7028 {
7029 if (*option == '+')
7030 {
7031 (void) SetImageOption(image_info,option+1,"0");
7032 break;
7033 }
7034 (void) SetImageOption(image_info,option+1,argv[i+1]);
7035 break;
7036 }
cristyd9a29192010-10-16 16:49:53 +00007037 if (LocaleCompare("synchronize",option+1) == 0)
7038 {
7039 if (*option == '+')
7040 {
7041 image_info->synchronize=MagickFalse;
7042 break;
7043 }
7044 image_info->synchronize=MagickTrue;
7045 break;
7046 }
cristy3ed852e2009-09-05 21:47:34 +00007047 break;
7048 }
7049 case 't':
7050 {
7051 if (LocaleCompare("taint",option+1) == 0)
7052 {
7053 if (*option == '+')
7054 {
7055 (void) SetImageOption(image_info,option+1,"false");
7056 break;
7057 }
7058 (void) SetImageOption(image_info,option+1,"true");
7059 break;
7060 }
7061 if (LocaleCompare("texture",option+1) == 0)
7062 {
7063 if (*option == '+')
7064 {
7065 if (image_info->texture != (char *) NULL)
7066 image_info->texture=DestroyString(image_info->texture);
7067 break;
7068 }
7069 (void) CloneString(&image_info->texture,argv[i+1]);
7070 break;
7071 }
7072 if (LocaleCompare("tile-offset",option+1) == 0)
7073 {
7074 if (*option == '+')
7075 {
7076 (void) SetImageOption(image_info,option+1,"0");
7077 break;
7078 }
7079 (void) SetImageOption(image_info,option+1,argv[i+1]);
7080 break;
7081 }
7082 if (LocaleCompare("transparent-color",option+1) == 0)
7083 {
7084 if (*option == '+')
7085 {
7086 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7087 (void) SetImageOption(image_info,option+1,"none");
7088 break;
7089 }
7090 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7091 exception);
7092 (void) SetImageOption(image_info,option+1,argv[i+1]);
7093 break;
7094 }
7095 if (LocaleCompare("type",option+1) == 0)
7096 {
7097 if (*option == '+')
7098 {
cristy5f1c1ff2010-12-23 21:38:06 +00007099 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007100 (void) SetImageOption(image_info,option+1,"undefined");
7101 break;
7102 }
cristy042ee782011-04-22 18:48:30 +00007103 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007104 MagickFalse,argv[i+1]);
7105 (void) SetImageOption(image_info,option+1,argv[i+1]);
7106 break;
7107 }
7108 break;
7109 }
7110 case 'u':
7111 {
7112 if (LocaleCompare("undercolor",option+1) == 0)
7113 {
7114 if (*option == '+')
7115 {
7116 (void) DeleteImageOption(image_info,option+1);
7117 break;
7118 }
7119 (void) SetImageOption(image_info,option+1,argv[i+1]);
7120 break;
7121 }
7122 if (LocaleCompare("units",option+1) == 0)
7123 {
7124 if (*option == '+')
7125 {
7126 image_info->units=UndefinedResolution;
7127 (void) SetImageOption(image_info,option+1,"undefined");
7128 break;
7129 }
cristy042ee782011-04-22 18:48:30 +00007130 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007131 MagickResolutionOptions,MagickFalse,argv[i+1]);
7132 (void) SetImageOption(image_info,option+1,argv[i+1]);
7133 break;
7134 }
7135 break;
7136 }
7137 case 'v':
7138 {
7139 if (LocaleCompare("verbose",option+1) == 0)
7140 {
7141 if (*option == '+')
7142 {
7143 image_info->verbose=MagickFalse;
7144 break;
7145 }
7146 image_info->verbose=MagickTrue;
7147 image_info->ping=MagickFalse;
7148 break;
7149 }
7150 if (LocaleCompare("view",option+1) == 0)
7151 {
7152 if (*option == '+')
7153 {
7154 if (image_info->view != (char *) NULL)
7155 image_info->view=DestroyString(image_info->view);
7156 break;
7157 }
7158 (void) CloneString(&image_info->view,argv[i+1]);
7159 break;
7160 }
7161 if (LocaleCompare("virtual-pixel",option+1) == 0)
7162 {
7163 if (*option == '+')
7164 {
7165 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7166 (void) SetImageOption(image_info,option+1,"undefined");
7167 break;
7168 }
7169 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007170 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007171 argv[i+1]);
7172 (void) SetImageOption(image_info,option+1,argv[i+1]);
7173 break;
7174 }
7175 break;
7176 }
7177 case 'w':
7178 {
7179 if (LocaleCompare("white-point",option+1) == 0)
7180 {
7181 if (*option == '+')
7182 {
7183 (void) SetImageOption(image_info,option+1,"0.0");
7184 break;
7185 }
7186 (void) SetImageOption(image_info,option+1,argv[i+1]);
7187 break;
7188 }
7189 break;
7190 }
7191 default:
7192 break;
7193 }
7194 i+=count;
7195 }
7196 return(MagickTrue);
7197}
7198
7199/*
7200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7201% %
7202% %
7203% %
7204+ M o g r i f y I m a g e L i s t %
7205% %
7206% %
7207% %
7208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7209%
7210% MogrifyImageList() applies any command line options that might affect the
7211% entire image list (e.g. -append, -coalesce, etc.).
7212%
7213% The format of the MogrifyImage method is:
7214%
7215% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7216% const char **argv,Image **images,ExceptionInfo *exception)
7217%
7218% A description of each parameter follows:
7219%
7220% o image_info: the image info..
7221%
7222% o argc: Specifies a pointer to an integer describing the number of
7223% elements in the argument vector.
7224%
7225% o argv: Specifies a pointer to a text array containing the command line
7226% arguments.
7227%
anthonye9c27192011-03-27 08:07:06 +00007228% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007229%
7230% o exception: return any errors or warnings in this structure.
7231%
7232*/
7233WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7234 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7235{
7236 ChannelType
7237 channel;
7238
7239 const char
7240 *option;
7241
cristy6b3da3a2010-06-20 02:21:46 +00007242 ImageInfo
7243 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007244
7245 MagickStatusType
7246 status;
7247
7248 QuantizeInfo
7249 *quantize_info;
7250
cristybb503372010-05-27 20:51:26 +00007251 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007252 i;
7253
cristy6b3da3a2010-06-20 02:21:46 +00007254 ssize_t
7255 count,
7256 index;
7257
cristy3ed852e2009-09-05 21:47:34 +00007258 /*
7259 Apply options to the image list.
7260 */
7261 assert(image_info != (ImageInfo *) NULL);
7262 assert(image_info->signature == MagickSignature);
7263 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007264 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007265 assert((*images)->signature == MagickSignature);
7266 if ((*images)->debug != MagickFalse)
7267 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7268 (*images)->filename);
7269 if ((argc <= 0) || (*argv == (char *) NULL))
7270 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007271 mogrify_info=CloneImageInfo(image_info);
7272 quantize_info=AcquireQuantizeInfo(mogrify_info);
7273 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007274 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007275 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007276 {
cristy74fe8f12009-10-03 19:09:01 +00007277 if (*images == (Image *) NULL)
7278 break;
cristy3ed852e2009-09-05 21:47:34 +00007279 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007280 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007281 continue;
cristy042ee782011-04-22 18:48:30 +00007282 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007283 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007284 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007285 break;
cristy6b3da3a2010-06-20 02:21:46 +00007286 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007287 switch (*(option+1))
7288 {
7289 case 'a':
7290 {
7291 if (LocaleCompare("affinity",option+1) == 0)
7292 {
cristy6b3da3a2010-06-20 02:21:46 +00007293 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007294 if (*option == '+')
7295 {
7296 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7297 InheritException(exception,&(*images)->exception);
7298 break;
7299 }
7300 i++;
7301 break;
7302 }
7303 if (LocaleCompare("append",option+1) == 0)
7304 {
7305 Image
7306 *append_image;
7307
cristy6b3da3a2010-06-20 02:21:46 +00007308 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007309 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7310 MagickFalse,exception);
7311 if (append_image == (Image *) NULL)
7312 {
7313 status=MagickFalse;
7314 break;
7315 }
7316 *images=DestroyImageList(*images);
7317 *images=append_image;
7318 break;
7319 }
7320 if (LocaleCompare("average",option+1) == 0)
7321 {
7322 Image
7323 *average_image;
7324
cristyd18ae7c2010-03-07 17:39:52 +00007325 /*
7326 Average an image sequence (deprecated).
7327 */
cristy6b3da3a2010-06-20 02:21:46 +00007328 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007329 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7330 exception);
cristy3ed852e2009-09-05 21:47:34 +00007331 if (average_image == (Image *) NULL)
7332 {
7333 status=MagickFalse;
7334 break;
7335 }
7336 *images=DestroyImageList(*images);
7337 *images=average_image;
7338 break;
7339 }
7340 break;
7341 }
7342 case 'c':
7343 {
7344 if (LocaleCompare("channel",option+1) == 0)
7345 {
7346 if (*option == '+')
7347 {
7348 channel=DefaultChannels;
7349 break;
7350 }
7351 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7352 break;
7353 }
7354 if (LocaleCompare("clut",option+1) == 0)
7355 {
7356 Image
7357 *clut_image,
7358 *image;
7359
cristy6b3da3a2010-06-20 02:21:46 +00007360 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007361 image=RemoveFirstImageFromList(images);
7362 clut_image=RemoveFirstImageFromList(images);
7363 if (clut_image == (Image *) NULL)
7364 {
7365 status=MagickFalse;
7366 break;
7367 }
cristyf89cb1d2011-07-07 01:24:37 +00007368 (void) ClutImage(image,clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007369 clut_image=DestroyImage(clut_image);
7370 InheritException(exception,&image->exception);
7371 *images=DestroyImageList(*images);
7372 *images=image;
7373 break;
7374 }
7375 if (LocaleCompare("coalesce",option+1) == 0)
7376 {
7377 Image
7378 *coalesce_image;
7379
cristy6b3da3a2010-06-20 02:21:46 +00007380 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007381 coalesce_image=CoalesceImages(*images,exception);
7382 if (coalesce_image == (Image *) NULL)
7383 {
7384 status=MagickFalse;
7385 break;
7386 }
7387 *images=DestroyImageList(*images);
7388 *images=coalesce_image;
7389 break;
7390 }
7391 if (LocaleCompare("combine",option+1) == 0)
7392 {
7393 Image
7394 *combine_image;
7395
cristy6b3da3a2010-06-20 02:21:46 +00007396 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007397 combine_image=CombineImages(*images,channel,exception);
7398 if (combine_image == (Image *) NULL)
7399 {
7400 status=MagickFalse;
7401 break;
7402 }
7403 *images=DestroyImageList(*images);
7404 *images=combine_image;
7405 break;
7406 }
7407 if (LocaleCompare("composite",option+1) == 0)
7408 {
7409 Image
7410 *mask_image,
7411 *composite_image,
7412 *image;
7413
7414 RectangleInfo
7415 geometry;
7416
cristy6b3da3a2010-06-20 02:21:46 +00007417 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007418 image=RemoveFirstImageFromList(images);
7419 composite_image=RemoveFirstImageFromList(images);
7420 if (composite_image == (Image *) NULL)
7421 {
7422 status=MagickFalse;
7423 break;
7424 }
7425 (void) TransformImage(&composite_image,(char *) NULL,
7426 composite_image->geometry);
7427 SetGeometry(composite_image,&geometry);
7428 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7429 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7430 &geometry);
7431 mask_image=RemoveFirstImageFromList(images);
7432 if (mask_image != (Image *) NULL)
7433 {
7434 if ((image->compose == DisplaceCompositeOp) ||
7435 (image->compose == DistortCompositeOp))
7436 {
7437 /*
7438 Merge Y displacement into X displacement image.
7439 */
7440 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7441 mask_image,0,0);
7442 mask_image=DestroyImage(mask_image);
7443 }
7444 else
7445 {
7446 /*
7447 Set a blending mask for the composition.
7448 */
anthonya129f702011-04-14 01:08:48 +00007449 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007450 image->mask=mask_image;
7451 (void) NegateImage(image->mask,MagickFalse);
7452 }
7453 }
cristyab015852011-07-06 01:03:32 +00007454 (void) CompositeImageChannel(image,channel,image->compose,
7455 composite_image,geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007456 if (mask_image != (Image *) NULL)
7457 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007458 composite_image=DestroyImage(composite_image);
7459 InheritException(exception,&image->exception);
7460 *images=DestroyImageList(*images);
7461 *images=image;
7462 break;
7463 }
anthony9f4f0342011-03-28 11:47:22 +00007464#if 0
7465This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007466 if (LocaleCompare("crop",option+1) == 0)
7467 {
7468 MagickStatusType
7469 flags;
7470
7471 RectangleInfo
7472 geometry;
7473
anthonye9c27192011-03-27 08:07:06 +00007474 /*
anthony9f4f0342011-03-28 11:47:22 +00007475 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007476 */
cristy6b3da3a2010-06-20 02:21:46 +00007477 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007478 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7479 if (((geometry.width == 0) && (geometry.height == 0)) ||
7480 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7481 break;
7482 (void) TransformImages(images,argv[i+1],(char *) NULL);
7483 InheritException(exception,&(*images)->exception);
7484 break;
7485 }
anthony9f4f0342011-03-28 11:47:22 +00007486#endif
cristy3ed852e2009-09-05 21:47:34 +00007487 break;
7488 }
7489 case 'd':
7490 {
7491 if (LocaleCompare("deconstruct",option+1) == 0)
7492 {
7493 Image
7494 *deconstruct_image;
7495
cristy6b3da3a2010-06-20 02:21:46 +00007496 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007497 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007498 exception);
cristy3ed852e2009-09-05 21:47:34 +00007499 if (deconstruct_image == (Image *) NULL)
7500 {
7501 status=MagickFalse;
7502 break;
7503 }
7504 *images=DestroyImageList(*images);
7505 *images=deconstruct_image;
7506 break;
7507 }
7508 if (LocaleCompare("delete",option+1) == 0)
7509 {
7510 if (*option == '+')
7511 DeleteImages(images,"-1",exception);
7512 else
7513 DeleteImages(images,argv[i+1],exception);
7514 break;
7515 }
7516 if (LocaleCompare("dither",option+1) == 0)
7517 {
7518 if (*option == '+')
7519 {
7520 quantize_info->dither=MagickFalse;
7521 break;
7522 }
7523 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007524 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007525 MagickDitherOptions,MagickFalse,argv[i+1]);
7526 break;
7527 }
cristyecb10ff2011-03-22 13:14:03 +00007528 if (LocaleCompare("duplicate",option+1) == 0)
7529 {
cristy72988482011-03-29 16:34:38 +00007530 Image
7531 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007532
anthony2b6bcae2011-03-23 13:05:34 +00007533 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007534 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7535 else
7536 {
7537 const char
7538 *p;
7539
anthony2b6bcae2011-03-23 13:05:34 +00007540 size_t
7541 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007542
anthony2b6bcae2011-03-23 13:05:34 +00007543 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007544 p=strchr(argv[i+1],',');
7545 if (p == (const char *) NULL)
7546 duplicate_images=DuplicateImages(*images,number_duplicates,
7547 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007548 else
cristy72988482011-03-29 16:34:38 +00007549 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7550 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007551 }
7552 AppendImageToList(images, duplicate_images);
7553 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007554 break;
7555 }
cristy3ed852e2009-09-05 21:47:34 +00007556 break;
7557 }
cristyd18ae7c2010-03-07 17:39:52 +00007558 case 'e':
7559 {
7560 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7561 {
7562 Image
7563 *evaluate_image;
7564
7565 MagickEvaluateOperator
7566 op;
7567
cristy6b3da3a2010-06-20 02:21:46 +00007568 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007569 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007570 MagickFalse,argv[i+1]);
7571 evaluate_image=EvaluateImages(*images,op,exception);
7572 if (evaluate_image == (Image *) NULL)
7573 {
7574 status=MagickFalse;
7575 break;
7576 }
7577 *images=DestroyImageList(*images);
7578 *images=evaluate_image;
7579 break;
7580 }
7581 break;
7582 }
cristy3ed852e2009-09-05 21:47:34 +00007583 case 'f':
7584 {
cristyf0a247f2009-10-04 00:20:03 +00007585 if (LocaleCompare("fft",option+1) == 0)
7586 {
7587 Image
7588 *fourier_image;
7589
7590 /*
7591 Implements the discrete Fourier transform (DFT).
7592 */
cristy6b3da3a2010-06-20 02:21:46 +00007593 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007594 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7595 MagickTrue : MagickFalse,exception);
7596 if (fourier_image == (Image *) NULL)
7597 break;
7598 *images=DestroyImage(*images);
7599 *images=fourier_image;
7600 break;
7601 }
cristy3ed852e2009-09-05 21:47:34 +00007602 if (LocaleCompare("flatten",option+1) == 0)
7603 {
7604 Image
7605 *flatten_image;
7606
cristy6b3da3a2010-06-20 02:21:46 +00007607 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007608 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7609 if (flatten_image == (Image *) NULL)
7610 break;
7611 *images=DestroyImageList(*images);
7612 *images=flatten_image;
7613 break;
7614 }
7615 if (LocaleCompare("fx",option+1) == 0)
7616 {
7617 Image
7618 *fx_image;
7619
cristy6b3da3a2010-06-20 02:21:46 +00007620 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007621 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007622 if (fx_image == (Image *) NULL)
7623 {
7624 status=MagickFalse;
7625 break;
7626 }
7627 *images=DestroyImageList(*images);
7628 *images=fx_image;
7629 break;
7630 }
7631 break;
7632 }
7633 case 'h':
7634 {
7635 if (LocaleCompare("hald-clut",option+1) == 0)
7636 {
7637 Image
7638 *hald_image,
7639 *image;
7640
cristy6b3da3a2010-06-20 02:21:46 +00007641 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007642 image=RemoveFirstImageFromList(images);
7643 hald_image=RemoveFirstImageFromList(images);
7644 if (hald_image == (Image *) NULL)
7645 {
7646 status=MagickFalse;
7647 break;
7648 }
cristyf89cb1d2011-07-07 01:24:37 +00007649 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007650 hald_image=DestroyImage(hald_image);
7651 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007652 if (*images != (Image *) NULL)
7653 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007654 *images=image;
7655 break;
7656 }
7657 break;
7658 }
7659 case 'i':
7660 {
7661 if (LocaleCompare("ift",option+1) == 0)
7662 {
7663 Image
cristy8587f882009-11-13 20:28:49 +00007664 *fourier_image,
7665 *magnitude_image,
7666 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007667
7668 /*
7669 Implements the inverse fourier discrete Fourier transform (DFT).
7670 */
cristy6b3da3a2010-06-20 02:21:46 +00007671 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007672 magnitude_image=RemoveFirstImageFromList(images);
7673 phase_image=RemoveFirstImageFromList(images);
7674 if (phase_image == (Image *) NULL)
7675 {
7676 status=MagickFalse;
7677 break;
7678 }
7679 fourier_image=InverseFourierTransformImage(magnitude_image,
7680 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007681 if (fourier_image == (Image *) NULL)
7682 break;
cristy0aff6ea2009-11-14 01:40:53 +00007683 if (*images != (Image *) NULL)
7684 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007685 *images=fourier_image;
7686 break;
7687 }
7688 if (LocaleCompare("insert",option+1) == 0)
7689 {
7690 Image
7691 *p,
7692 *q;
7693
7694 index=0;
7695 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007696 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007697 p=RemoveLastImageFromList(images);
7698 if (p == (Image *) NULL)
7699 {
7700 (void) ThrowMagickException(exception,GetMagickModule(),
7701 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7702 status=MagickFalse;
7703 break;
7704 }
7705 q=p;
7706 if (index == 0)
7707 PrependImageToList(images,q);
7708 else
cristybb503372010-05-27 20:51:26 +00007709 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007710 AppendImageToList(images,q);
7711 else
7712 {
7713 q=GetImageFromList(*images,index-1);
7714 if (q == (Image *) NULL)
7715 {
7716 (void) ThrowMagickException(exception,GetMagickModule(),
7717 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7718 status=MagickFalse;
7719 break;
7720 }
7721 InsertImageInList(&q,p);
7722 }
7723 *images=GetFirstImageInList(q);
7724 break;
7725 }
7726 break;
7727 }
7728 case 'l':
7729 {
7730 if (LocaleCompare("layers",option+1) == 0)
7731 {
7732 Image
7733 *layers;
7734
7735 ImageLayerMethod
7736 method;
7737
cristy6b3da3a2010-06-20 02:21:46 +00007738 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007739 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007740 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007741 MagickFalse,argv[i+1]);
7742 switch (method)
7743 {
7744 case CoalesceLayer:
7745 {
7746 layers=CoalesceImages(*images,exception);
7747 break;
7748 }
7749 case CompareAnyLayer:
7750 case CompareClearLayer:
7751 case CompareOverlayLayer:
7752 default:
7753 {
cristy8a9106f2011-07-05 14:39:26 +00007754 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007755 break;
7756 }
7757 case MergeLayer:
7758 case FlattenLayer:
7759 case MosaicLayer:
7760 case TrimBoundsLayer:
7761 {
7762 layers=MergeImageLayers(*images,method,exception);
7763 break;
7764 }
7765 case DisposeLayer:
7766 {
7767 layers=DisposeImages(*images,exception);
7768 break;
7769 }
7770 case OptimizeImageLayer:
7771 {
7772 layers=OptimizeImageLayers(*images,exception);
7773 break;
7774 }
7775 case OptimizePlusLayer:
7776 {
7777 layers=OptimizePlusImageLayers(*images,exception);
7778 break;
7779 }
7780 case OptimizeTransLayer:
7781 {
7782 OptimizeImageTransparency(*images,exception);
7783 break;
7784 }
7785 case RemoveDupsLayer:
7786 {
7787 RemoveDuplicateLayers(images,exception);
7788 break;
7789 }
7790 case RemoveZeroLayer:
7791 {
7792 RemoveZeroDelayLayers(images,exception);
7793 break;
7794 }
7795 case OptimizeLayer:
7796 {
7797 /*
7798 General Purpose, GIF Animation Optimizer.
7799 */
7800 layers=CoalesceImages(*images,exception);
7801 if (layers == (Image *) NULL)
7802 {
7803 status=MagickFalse;
7804 break;
7805 }
7806 InheritException(exception,&layers->exception);
7807 *images=DestroyImageList(*images);
7808 *images=layers;
7809 layers=OptimizeImageLayers(*images,exception);
7810 if (layers == (Image *) NULL)
7811 {
7812 status=MagickFalse;
7813 break;
7814 }
7815 InheritException(exception,&layers->exception);
7816 *images=DestroyImageList(*images);
7817 *images=layers;
7818 layers=(Image *) NULL;
7819 OptimizeImageTransparency(*images,exception);
7820 InheritException(exception,&(*images)->exception);
7821 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7822 break;
7823 }
7824 case CompositeLayer:
7825 {
7826 CompositeOperator
7827 compose;
7828
7829 Image
7830 *source;
7831
7832 RectangleInfo
7833 geometry;
7834
7835 /*
7836 Split image sequence at the first 'NULL:' image.
7837 */
7838 source=(*images);
7839 while (source != (Image *) NULL)
7840 {
7841 source=GetNextImageInList(source);
7842 if ((source != (Image *) NULL) &&
7843 (LocaleCompare(source->magick,"NULL") == 0))
7844 break;
7845 }
7846 if (source != (Image *) NULL)
7847 {
7848 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7849 (GetNextImageInList(source) == (Image *) NULL))
7850 source=(Image *) NULL;
7851 else
7852 {
7853 /*
7854 Separate the two lists, junk the null: image.
7855 */
7856 source=SplitImageList(source->previous);
7857 DeleteImageFromList(&source);
7858 }
7859 }
7860 if (source == (Image *) NULL)
7861 {
7862 (void) ThrowMagickException(exception,GetMagickModule(),
7863 OptionError,"MissingNullSeparator","layers Composite");
7864 status=MagickFalse;
7865 break;
7866 }
7867 /*
7868 Adjust offset with gravity and virtual canvas.
7869 */
7870 SetGeometry(*images,&geometry);
7871 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7872 geometry.width=source->page.width != 0 ?
7873 source->page.width : source->columns;
7874 geometry.height=source->page.height != 0 ?
7875 source->page.height : source->rows;
7876 GravityAdjustGeometry((*images)->page.width != 0 ?
7877 (*images)->page.width : (*images)->columns,
7878 (*images)->page.height != 0 ? (*images)->page.height :
7879 (*images)->rows,(*images)->gravity,&geometry);
7880 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007881 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007882 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007883 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007884 MagickComposeOptions,MagickFalse,option);
7885 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7886 exception);
7887 source=DestroyImageList(source);
7888 break;
7889 }
7890 }
7891 if (layers == (Image *) NULL)
7892 break;
7893 InheritException(exception,&layers->exception);
7894 *images=DestroyImageList(*images);
7895 *images=layers;
7896 break;
7897 }
7898 break;
7899 }
7900 case 'm':
7901 {
7902 if (LocaleCompare("map",option+1) == 0)
7903 {
cristy6b3da3a2010-06-20 02:21:46 +00007904 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007905 if (*option == '+')
7906 {
7907 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7908 InheritException(exception,&(*images)->exception);
7909 break;
7910 }
7911 i++;
7912 break;
7913 }
cristyf40785b2010-03-06 02:27:27 +00007914 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007915 {
7916 Image
cristyf40785b2010-03-06 02:27:27 +00007917 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007918
cristyd18ae7c2010-03-07 17:39:52 +00007919 /*
7920 Maximum image sequence (deprecated).
7921 */
cristy6b3da3a2010-06-20 02:21:46 +00007922 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007923 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007924 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007925 {
7926 status=MagickFalse;
7927 break;
7928 }
7929 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007930 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007931 break;
7932 }
cristyf40785b2010-03-06 02:27:27 +00007933 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007934 {
7935 Image
cristyf40785b2010-03-06 02:27:27 +00007936 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007937
cristyd18ae7c2010-03-07 17:39:52 +00007938 /*
7939 Minimum image sequence (deprecated).
7940 */
cristy6b3da3a2010-06-20 02:21:46 +00007941 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007942 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007943 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007944 {
7945 status=MagickFalse;
7946 break;
7947 }
7948 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007949 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007950 break;
7951 }
cristy3ed852e2009-09-05 21:47:34 +00007952 if (LocaleCompare("morph",option+1) == 0)
7953 {
7954 Image
7955 *morph_image;
7956
cristy6b3da3a2010-06-20 02:21:46 +00007957 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007958 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007959 exception);
7960 if (morph_image == (Image *) NULL)
7961 {
7962 status=MagickFalse;
7963 break;
7964 }
7965 *images=DestroyImageList(*images);
7966 *images=morph_image;
7967 break;
7968 }
7969 if (LocaleCompare("mosaic",option+1) == 0)
7970 {
7971 Image
7972 *mosaic_image;
7973
cristy6b3da3a2010-06-20 02:21:46 +00007974 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007975 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7976 if (mosaic_image == (Image *) NULL)
7977 {
7978 status=MagickFalse;
7979 break;
7980 }
7981 *images=DestroyImageList(*images);
7982 *images=mosaic_image;
7983 break;
7984 }
7985 break;
7986 }
7987 case 'p':
7988 {
7989 if (LocaleCompare("print",option+1) == 0)
7990 {
7991 char
7992 *string;
7993
cristy6b3da3a2010-06-20 02:21:46 +00007994 (void) SyncImagesSettings(mogrify_info,*images);
7995 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007996 if (string == (char *) NULL)
7997 break;
7998 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007999 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008000 string=DestroyString(string);
8001 }
8002 if (LocaleCompare("process",option+1) == 0)
8003 {
8004 char
8005 **arguments;
8006
8007 int
8008 j,
8009 number_arguments;
8010
cristy6b3da3a2010-06-20 02:21:46 +00008011 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008012 arguments=StringToArgv(argv[i+1],&number_arguments);
8013 if (arguments == (char **) NULL)
8014 break;
8015 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8016 {
8017 char
8018 breaker,
8019 quote,
8020 *token;
8021
8022 const char
8023 *arguments;
8024
8025 int
8026 next,
8027 status;
8028
8029 size_t
8030 length;
8031
8032 TokenInfo
8033 *token_info;
8034
8035 /*
8036 Support old style syntax, filter="-option arg".
8037 */
8038 length=strlen(argv[i+1]);
8039 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008040 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008041 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8042 sizeof(*token));
8043 if (token == (char *) NULL)
8044 break;
8045 next=0;
8046 arguments=argv[i+1];
8047 token_info=AcquireTokenInfo();
8048 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8049 "\"",'\0',&breaker,&next,&quote);
8050 token_info=DestroyTokenInfo(token_info);
8051 if (status == 0)
8052 {
8053 const char
8054 *argv;
8055
8056 argv=(&(arguments[next]));
8057 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8058 exception);
8059 }
8060 token=DestroyString(token);
8061 break;
8062 }
cristy91c0da22010-05-02 01:44:07 +00008063 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008064 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8065 number_arguments-2,(const char **) arguments+2,exception);
8066 for (j=0; j < number_arguments; j++)
8067 arguments[j]=DestroyString(arguments[j]);
8068 arguments=(char **) RelinquishMagickMemory(arguments);
8069 break;
8070 }
8071 break;
8072 }
8073 case 'r':
8074 {
8075 if (LocaleCompare("reverse",option+1) == 0)
8076 {
8077 ReverseImageList(images);
8078 InheritException(exception,&(*images)->exception);
8079 break;
8080 }
8081 break;
8082 }
8083 case 's':
8084 {
cristy4285d782011-02-09 20:12:28 +00008085 if (LocaleCompare("smush",option+1) == 0)
8086 {
8087 Image
8088 *smush_image;
8089
8090 ssize_t
8091 offset;
8092
8093 (void) SyncImagesSettings(mogrify_info,*images);
8094 offset=(ssize_t) StringToLong(argv[i+1]);
8095 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8096 MagickFalse,offset,exception);
8097 if (smush_image == (Image *) NULL)
8098 {
8099 status=MagickFalse;
8100 break;
8101 }
8102 *images=DestroyImageList(*images);
8103 *images=smush_image;
8104 break;
8105 }
cristy3ed852e2009-09-05 21:47:34 +00008106 if (LocaleCompare("swap",option+1) == 0)
8107 {
8108 Image
8109 *p,
8110 *q,
8111 *swap;
8112
cristybb503372010-05-27 20:51:26 +00008113 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008114 swap_index;
8115
8116 index=(-1);
8117 swap_index=(-2);
8118 if (*option != '+')
8119 {
8120 GeometryInfo
8121 geometry_info;
8122
8123 MagickStatusType
8124 flags;
8125
8126 swap_index=(-1);
8127 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008128 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008129 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008130 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008131 }
8132 p=GetImageFromList(*images,index);
8133 q=GetImageFromList(*images,swap_index);
8134 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8135 {
8136 (void) ThrowMagickException(exception,GetMagickModule(),
8137 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8138 status=MagickFalse;
8139 break;
8140 }
8141 if (p == q)
8142 break;
8143 swap=CloneImage(p,0,0,MagickTrue,exception);
8144 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8145 ReplaceImageInList(&q,swap);
8146 *images=GetFirstImageInList(q);
8147 break;
8148 }
8149 break;
8150 }
8151 case 'w':
8152 {
8153 if (LocaleCompare("write",option+1) == 0)
8154 {
cristy071dd7b2010-04-09 13:04:54 +00008155 char
cristy06609ee2010-03-17 20:21:27 +00008156 key[MaxTextExtent];
8157
cristy3ed852e2009-09-05 21:47:34 +00008158 Image
8159 *write_images;
8160
8161 ImageInfo
8162 *write_info;
8163
cristy6b3da3a2010-06-20 02:21:46 +00008164 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008165 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008166 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008167 write_images=(*images);
8168 if (*option == '+')
8169 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008170 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008171 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8172 write_info=DestroyImageInfo(write_info);
8173 if (*option == '+')
8174 write_images=DestroyImageList(write_images);
8175 break;
8176 }
8177 break;
8178 }
8179 default:
8180 break;
8181 }
8182 i+=count;
8183 }
8184 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008185 mogrify_info=DestroyImageInfo(mogrify_info);
8186 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008187 return(status != 0 ? MagickTrue : MagickFalse);
8188}
8189
8190/*
8191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8192% %
8193% %
8194% %
8195+ M o g r i f y I m a g e s %
8196% %
8197% %
8198% %
8199%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8200%
8201% MogrifyImages() applies image processing options to a sequence of images as
8202% prescribed by command line options.
8203%
8204% The format of the MogrifyImage method is:
8205%
8206% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8207% const MagickBooleanType post,const int argc,const char **argv,
8208% Image **images,Exceptioninfo *exception)
8209%
8210% A description of each parameter follows:
8211%
8212% o image_info: the image info..
8213%
8214% o post: If true, post process image list operators otherwise pre-process.
8215%
8216% o argc: Specifies a pointer to an integer describing the number of
8217% elements in the argument vector.
8218%
8219% o argv: Specifies a pointer to a text array containing the command line
8220% arguments.
8221%
anthonye9c27192011-03-27 08:07:06 +00008222% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008223%
8224% o exception: return any errors or warnings in this structure.
8225%
8226*/
8227WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8228 const MagickBooleanType post,const int argc,const char **argv,
8229 Image **images,ExceptionInfo *exception)
8230{
8231#define MogrifyImageTag "Mogrify/Image"
8232
anthonye9c27192011-03-27 08:07:06 +00008233 MagickStatusType
8234 status;
cristy3ed852e2009-09-05 21:47:34 +00008235
cristy0e9f9c12010-02-11 03:00:47 +00008236 MagickBooleanType
8237 proceed;
8238
anthonye9c27192011-03-27 08:07:06 +00008239 size_t
8240 n;
cristy3ed852e2009-09-05 21:47:34 +00008241
cristybb503372010-05-27 20:51:26 +00008242 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008243 i;
8244
cristy3ed852e2009-09-05 21:47:34 +00008245 assert(image_info != (ImageInfo *) NULL);
8246 assert(image_info->signature == MagickSignature);
8247 if (images == (Image **) NULL)
8248 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008249 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008250 assert((*images)->signature == MagickSignature);
8251 if ((*images)->debug != MagickFalse)
8252 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8253 (*images)->filename);
8254 if ((argc <= 0) || (*argv == (char *) NULL))
8255 return(MagickTrue);
8256 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8257 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008258 status=0;
anthonye9c27192011-03-27 08:07:06 +00008259
anthonyce2716b2011-04-22 09:51:34 +00008260#if 0
cristy1e604812011-05-19 18:07:50 +00008261 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8262 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008263#endif
8264
anthonye9c27192011-03-27 08:07:06 +00008265 /*
8266 Pre-process multi-image sequence operators
8267 */
cristy3ed852e2009-09-05 21:47:34 +00008268 if (post == MagickFalse)
8269 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008270 /*
8271 For each image, process simple single image operators
8272 */
8273 i=0;
8274 n=GetImageListLength(*images);
8275 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008276 {
anthonyce2716b2011-04-22 09:51:34 +00008277#if 0
cristy1e604812011-05-19 18:07:50 +00008278 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8279 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008280#endif
anthonye9c27192011-03-27 08:07:06 +00008281 status&=MogrifyImage(image_info,argc,argv,images,exception);
8282 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008283 if (proceed == MagickFalse)
8284 break;
anthonye9c27192011-03-27 08:07:06 +00008285 if ( (*images)->next == (Image *) NULL )
8286 break;
8287 *images=(*images)->next;
8288 i++;
cristy3ed852e2009-09-05 21:47:34 +00008289 }
anthonye9c27192011-03-27 08:07:06 +00008290 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008291#if 0
cristy1e604812011-05-19 18:07:50 +00008292 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8293 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008294#endif
anthonye9c27192011-03-27 08:07:06 +00008295
8296 /*
8297 Post-process, multi-image sequence operators
8298 */
8299 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008300 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008301 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008302 return(status != 0 ? MagickTrue : MagickFalse);
8303}