blob: e9853ac29f6d4548dde7da65fc85410ee9e45484 [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;
1189 (void) ContrastStretchImageChannel(*image,channel,black_point,
1190 white_point);
1191 InheritException(exception,&(*image)->exception);
1192 break;
1193 }
1194 if (LocaleCompare("convolve",option+1) == 0)
1195 {
1196 double
1197 gamma;
1198
1199 KernelInfo
1200 *kernel;
1201
1202 register ssize_t
1203 j;
1204
1205 (void) SyncImageSettings(mogrify_info,*image);
1206 kernel=AcquireKernelInfo(argv[i+1]);
1207 if (kernel == (KernelInfo *) NULL)
1208 break;
1209 gamma=0.0;
1210 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1211 gamma+=kernel->values[j];
1212 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1213 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1214 kernel->values[j]*=gamma;
1215 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
1216 kernel=DestroyKernelInfo(kernel);
1217 break;
1218 }
1219 if (LocaleCompare("crop",option+1) == 0)
1220 {
1221 /*
1222 Crop a image to a smaller size
1223 */
1224 (void) SyncImageSettings(mogrify_info,*image);
1225#if 0
1226 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1227 if (((geometry.width != 0) || (geometry.height != 0)) &&
1228 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1229 break;
1230#endif
1231#if 0
1232 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1233 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1234 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1235 InheritException(exception,&mogrify_image->exception);
1236#else
1237 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1238#endif
1239 break;
1240 }
1241 if (LocaleCompare("cycle",option+1) == 0)
1242 {
1243 /*
1244 Cycle an image colormap.
1245 */
1246 (void) SyncImageSettings(mogrify_info,*image);
1247 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1248 InheritException(exception,&(*image)->exception);
1249 break;
1250 }
1251 break;
1252 }
1253 case 'd':
1254 {
1255 if (LocaleCompare("decipher",option+1) == 0)
1256 {
1257 StringInfo
1258 *passkey;
1259
1260 /*
1261 Decipher pixels.
1262 */
1263 (void) SyncImageSettings(mogrify_info,*image);
1264 passkey=FileToStringInfo(argv[i+1],~0,exception);
1265 if (passkey != (StringInfo *) NULL)
1266 {
1267 (void) PasskeyDecipherImage(*image,passkey,exception);
1268 passkey=DestroyStringInfo(passkey);
1269 }
1270 break;
1271 }
1272 if (LocaleCompare("density",option+1) == 0)
1273 {
1274 /*
1275 Set image density.
1276 */
1277 (void) CloneString(&draw_info->density,argv[i+1]);
1278 break;
1279 }
1280 if (LocaleCompare("depth",option+1) == 0)
1281 {
1282 (void) SyncImageSettings(mogrify_info,*image);
1283 if (*option == '+')
1284 {
1285 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1286 break;
1287 }
1288 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1289 break;
1290 }
1291 if (LocaleCompare("deskew",option+1) == 0)
1292 {
1293 double
1294 threshold;
1295
1296 /*
1297 Straighten the image.
1298 */
1299 (void) SyncImageSettings(mogrify_info,*image);
1300 if (*option == '+')
1301 threshold=40.0*QuantumRange/100.0;
1302 else
1303 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1304 mogrify_image=DeskewImage(*image,threshold,exception);
1305 break;
1306 }
1307 if (LocaleCompare("despeckle",option+1) == 0)
1308 {
1309 /*
1310 Reduce the speckles within an image.
1311 */
1312 (void) SyncImageSettings(mogrify_info,*image);
1313 mogrify_image=DespeckleImage(*image,exception);
1314 break;
1315 }
1316 if (LocaleCompare("display",option+1) == 0)
1317 {
1318 (void) CloneString(&draw_info->server_name,argv[i+1]);
1319 break;
1320 }
1321 if (LocaleCompare("distort",option+1) == 0)
1322 {
1323 char
1324 *args,
1325 token[MaxTextExtent];
1326
1327 const char
1328 *p;
1329
1330 DistortImageMethod
1331 method;
1332
1333 double
1334 *arguments;
1335
1336 register ssize_t
1337 x;
1338
1339 size_t
1340 number_arguments;
1341
1342 /*
1343 Distort image.
1344 */
1345 (void) SyncImageSettings(mogrify_info,*image);
1346 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1347 MagickFalse,argv[i+1]);
1348 if ( method == ResizeDistortion )
1349 {
1350 /* Special Case - Argument is actually a resize geometry!
1351 ** Convert that to an appropriate distortion argument array.
1352 */
1353 double
1354 resize_args[2];
1355 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1356 exception);
1357 resize_args[0]=(double)geometry.width;
1358 resize_args[1]=(double)geometry.height;
1359 mogrify_image=DistortImage(*image,method,(size_t)2,
1360 resize_args,MagickTrue,exception);
1361 break;
1362 }
1363 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1364 InheritException(exception,&(*image)->exception);
1365 if (args == (char *) NULL)
1366 break;
1367 p=(char *) args;
1368 for (x=0; *p != '\0'; x++)
1369 {
1370 GetMagickToken(p,&p,token);
1371 if (*token == ',')
1372 GetMagickToken(p,&p,token);
1373 }
1374 number_arguments=(size_t) x;
1375 arguments=(double *) AcquireQuantumMemory(number_arguments,
1376 sizeof(*arguments));
1377 if (arguments == (double *) NULL)
1378 ThrowWandFatalException(ResourceLimitFatalError,
1379 "MemoryAllocationFailed",(*image)->filename);
1380 (void) ResetMagickMemory(arguments,0,number_arguments*
1381 sizeof(*arguments));
1382 p=(char *) args;
1383 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1384 {
1385 GetMagickToken(p,&p,token);
1386 if (*token == ',')
1387 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001388 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001389 }
1390 args=DestroyString(args);
1391 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1392 (*option == '+') ? MagickTrue : MagickFalse,exception);
1393 arguments=(double *) RelinquishMagickMemory(arguments);
1394 break;
1395 }
1396 if (LocaleCompare("dither",option+1) == 0)
1397 {
1398 if (*option == '+')
1399 {
1400 quantize_info->dither=MagickFalse;
1401 break;
1402 }
1403 quantize_info->dither=MagickTrue;
1404 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1405 MagickDitherOptions,MagickFalse,argv[i+1]);
1406 if (quantize_info->dither_method == NoDitherMethod)
1407 quantize_info->dither=MagickFalse;
1408 break;
1409 }
1410 if (LocaleCompare("draw",option+1) == 0)
1411 {
1412 /*
1413 Draw image.
1414 */
1415 (void) SyncImageSettings(mogrify_info,*image);
1416 (void) CloneString(&draw_info->primitive,argv[i+1]);
1417 (void) DrawImage(*image,draw_info);
1418 InheritException(exception,&(*image)->exception);
1419 break;
1420 }
1421 break;
1422 }
1423 case 'e':
1424 {
1425 if (LocaleCompare("edge",option+1) == 0)
1426 {
1427 /*
1428 Enhance edges in the image.
1429 */
1430 (void) SyncImageSettings(mogrify_info,*image);
1431 flags=ParseGeometry(argv[i+1],&geometry_info);
1432 if ((flags & SigmaValue) == 0)
1433 geometry_info.sigma=1.0;
1434 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1435 break;
1436 }
1437 if (LocaleCompare("emboss",option+1) == 0)
1438 {
1439 /*
1440 Gaussian embossen image.
1441 */
1442 (void) SyncImageSettings(mogrify_info,*image);
1443 flags=ParseGeometry(argv[i+1],&geometry_info);
1444 if ((flags & SigmaValue) == 0)
1445 geometry_info.sigma=1.0;
1446 mogrify_image=EmbossImage(*image,geometry_info.rho,
1447 geometry_info.sigma,exception);
1448 break;
1449 }
1450 if (LocaleCompare("encipher",option+1) == 0)
1451 {
1452 StringInfo
1453 *passkey;
1454
1455 /*
1456 Encipher pixels.
1457 */
1458 (void) SyncImageSettings(mogrify_info,*image);
1459 passkey=FileToStringInfo(argv[i+1],~0,exception);
1460 if (passkey != (StringInfo *) NULL)
1461 {
1462 (void) PasskeyEncipherImage(*image,passkey,exception);
1463 passkey=DestroyStringInfo(passkey);
1464 }
1465 break;
1466 }
1467 if (LocaleCompare("encoding",option+1) == 0)
1468 {
1469 (void) CloneString(&draw_info->encoding,argv[i+1]);
1470 break;
1471 }
1472 if (LocaleCompare("enhance",option+1) == 0)
1473 {
1474 /*
1475 Enhance image.
1476 */
1477 (void) SyncImageSettings(mogrify_info,*image);
1478 mogrify_image=EnhanceImage(*image,exception);
1479 break;
1480 }
1481 if (LocaleCompare("equalize",option+1) == 0)
1482 {
1483 /*
1484 Equalize image.
1485 */
1486 (void) SyncImageSettings(mogrify_info,*image);
1487 (void) EqualizeImageChannel(*image,channel);
1488 InheritException(exception,&(*image)->exception);
1489 break;
1490 }
1491 if (LocaleCompare("evaluate",option+1) == 0)
1492 {
1493 double
1494 constant;
1495
1496 MagickEvaluateOperator
1497 op;
1498
1499 (void) SyncImageSettings(mogrify_info,*image);
1500 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
1501 MagickFalse,argv[i+1]);
1502 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
1503 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1504 break;
1505 }
1506 if (LocaleCompare("extent",option+1) == 0)
1507 {
1508 /*
1509 Set the image extent.
1510 */
1511 (void) SyncImageSettings(mogrify_info,*image);
1512 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1513 if (geometry.width == 0)
1514 geometry.width=(*image)->columns;
1515 if (geometry.height == 0)
1516 geometry.height=(*image)->rows;
1517 mogrify_image=ExtentImage(*image,&geometry,exception);
1518 break;
1519 }
1520 break;
1521 }
1522 case 'f':
1523 {
1524 if (LocaleCompare("family",option+1) == 0)
1525 {
1526 if (*option == '+')
1527 {
1528 if (draw_info->family != (char *) NULL)
1529 draw_info->family=DestroyString(draw_info->family);
1530 break;
1531 }
1532 (void) CloneString(&draw_info->family,argv[i+1]);
1533 break;
1534 }
1535 if (LocaleCompare("features",option+1) == 0)
1536 {
1537 if (*option == '+')
1538 {
1539 (void) DeleteImageArtifact(*image,"identify:features");
1540 break;
1541 }
1542 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1543 break;
1544 }
1545 if (LocaleCompare("fill",option+1) == 0)
1546 {
1547 ExceptionInfo
1548 *sans;
1549
cristy4c08aed2011-07-01 19:47:50 +00001550 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001551 if (*option == '+')
1552 {
1553 (void) QueryMagickColor("none",&fill,exception);
1554 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1555 if (draw_info->fill_pattern != (Image *) NULL)
1556 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1557 break;
1558 }
1559 sans=AcquireExceptionInfo();
1560 (void) QueryMagickColor(argv[i+1],&fill,sans);
1561 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1562 sans=DestroyExceptionInfo(sans);
1563 if (status == MagickFalse)
1564 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1565 exception);
1566 break;
1567 }
1568 if (LocaleCompare("flip",option+1) == 0)
1569 {
1570 /*
1571 Flip image scanlines.
1572 */
1573 (void) SyncImageSettings(mogrify_info,*image);
1574 mogrify_image=FlipImage(*image,exception);
1575 break;
1576 }
anthonydf8ebac2011-04-27 09:03:19 +00001577 if (LocaleCompare("floodfill",option+1) == 0)
1578 {
cristy4c08aed2011-07-01 19:47:50 +00001579 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001580 target;
1581
1582 /*
1583 Floodfill image.
1584 */
1585 (void) SyncImageSettings(mogrify_info,*image);
1586 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1587 (void) QueryMagickColor(argv[i+2],&target,exception);
1588 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1589 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1590 InheritException(exception,&(*image)->exception);
1591 break;
1592 }
anthony3d2f4862011-05-01 13:48:16 +00001593 if (LocaleCompare("flop",option+1) == 0)
1594 {
1595 /*
1596 Flop image scanlines.
1597 */
1598 (void) SyncImageSettings(mogrify_info,*image);
1599 mogrify_image=FlopImage(*image,exception);
1600 break;
1601 }
anthonydf8ebac2011-04-27 09:03:19 +00001602 if (LocaleCompare("font",option+1) == 0)
1603 {
1604 if (*option == '+')
1605 {
1606 if (draw_info->font != (char *) NULL)
1607 draw_info->font=DestroyString(draw_info->font);
1608 break;
1609 }
1610 (void) CloneString(&draw_info->font,argv[i+1]);
1611 break;
1612 }
1613 if (LocaleCompare("format",option+1) == 0)
1614 {
1615 format=argv[i+1];
1616 break;
1617 }
1618 if (LocaleCompare("frame",option+1) == 0)
1619 {
1620 FrameInfo
1621 frame_info;
1622
1623 /*
1624 Surround image with an ornamental border.
1625 */
1626 (void) SyncImageSettings(mogrify_info,*image);
1627 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1628 frame_info.width=geometry.width;
1629 frame_info.height=geometry.height;
1630 if ((flags & HeightValue) == 0)
1631 frame_info.height=geometry.width;
1632 frame_info.outer_bevel=geometry.x;
1633 frame_info.inner_bevel=geometry.y;
1634 frame_info.x=(ssize_t) frame_info.width;
1635 frame_info.y=(ssize_t) frame_info.height;
1636 frame_info.width=(*image)->columns+2*frame_info.width;
1637 frame_info.height=(*image)->rows+2*frame_info.height;
1638 mogrify_image=FrameImage(*image,&frame_info,exception);
1639 break;
1640 }
1641 if (LocaleCompare("function",option+1) == 0)
1642 {
1643 char
1644 *arguments,
1645 token[MaxTextExtent];
1646
1647 const char
1648 *p;
1649
1650 double
1651 *parameters;
1652
1653 MagickFunction
1654 function;
1655
1656 register ssize_t
1657 x;
1658
1659 size_t
1660 number_parameters;
1661
1662 /*
1663 Function Modify Image Values
1664 */
1665 (void) SyncImageSettings(mogrify_info,*image);
1666 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1667 MagickFalse,argv[i+1]);
1668 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1669 InheritException(exception,&(*image)->exception);
1670 if (arguments == (char *) NULL)
1671 break;
1672 p=(char *) arguments;
1673 for (x=0; *p != '\0'; x++)
1674 {
1675 GetMagickToken(p,&p,token);
1676 if (*token == ',')
1677 GetMagickToken(p,&p,token);
1678 }
1679 number_parameters=(size_t) x;
1680 parameters=(double *) AcquireQuantumMemory(number_parameters,
1681 sizeof(*parameters));
1682 if (parameters == (double *) NULL)
1683 ThrowWandFatalException(ResourceLimitFatalError,
1684 "MemoryAllocationFailed",(*image)->filename);
1685 (void) ResetMagickMemory(parameters,0,number_parameters*
1686 sizeof(*parameters));
1687 p=(char *) arguments;
1688 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1689 {
1690 GetMagickToken(p,&p,token);
1691 if (*token == ',')
1692 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001693 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001694 }
1695 arguments=DestroyString(arguments);
1696 (void) FunctionImageChannel(*image,channel,function,
1697 number_parameters,parameters,exception);
1698 parameters=(double *) RelinquishMagickMemory(parameters);
1699 break;
1700 }
1701 break;
1702 }
1703 case 'g':
1704 {
1705 if (LocaleCompare("gamma",option+1) == 0)
1706 {
1707 /*
1708 Gamma image.
1709 */
1710 (void) SyncImageSettings(mogrify_info,*image);
1711 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001712 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001713 else
1714 {
1715 if (strchr(argv[i+1],',') != (char *) NULL)
1716 (void) GammaImage(*image,argv[i+1]);
1717 else
1718 (void) GammaImageChannel(*image,channel,
cristyc1acd842011-05-19 23:05:47 +00001719 InterpretLocaleValue(argv[i+1],(char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001720 InheritException(exception,&(*image)->exception);
1721 }
1722 break;
1723 }
1724 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1725 (LocaleCompare("gaussian",option+1) == 0))
1726 {
1727 /*
1728 Gaussian blur image.
1729 */
1730 (void) SyncImageSettings(mogrify_info,*image);
1731 flags=ParseGeometry(argv[i+1],&geometry_info);
1732 if ((flags & SigmaValue) == 0)
1733 geometry_info.sigma=1.0;
1734 mogrify_image=GaussianBlurImageChannel(*image,channel,
1735 geometry_info.rho,geometry_info.sigma,exception);
1736 break;
1737 }
1738 if (LocaleCompare("geometry",option+1) == 0)
1739 {
1740 /*
1741 Record Image offset, Resize last image.
1742 */
1743 (void) SyncImageSettings(mogrify_info,*image);
1744 if (*option == '+')
1745 {
1746 if ((*image)->geometry != (char *) NULL)
1747 (*image)->geometry=DestroyString((*image)->geometry);
1748 break;
1749 }
1750 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1751 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1752 (void) CloneString(&(*image)->geometry,argv[i+1]);
1753 else
1754 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1755 (*image)->filter,(*image)->blur,exception);
1756 break;
1757 }
1758 if (LocaleCompare("gravity",option+1) == 0)
1759 {
1760 if (*option == '+')
1761 {
1762 draw_info->gravity=UndefinedGravity;
1763 break;
1764 }
1765 draw_info->gravity=(GravityType) ParseCommandOption(
1766 MagickGravityOptions,MagickFalse,argv[i+1]);
1767 break;
1768 }
1769 break;
1770 }
1771 case 'h':
1772 {
1773 if (LocaleCompare("highlight-color",option+1) == 0)
1774 {
1775 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1776 break;
1777 }
1778 break;
1779 }
1780 case 'i':
1781 {
1782 if (LocaleCompare("identify",option+1) == 0)
1783 {
1784 char
1785 *text;
1786
1787 (void) SyncImageSettings(mogrify_info,*image);
1788 if (format == (char *) NULL)
1789 {
1790 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1791 InheritException(exception,&(*image)->exception);
1792 break;
1793 }
1794 text=InterpretImageProperties(mogrify_info,*image,format);
1795 InheritException(exception,&(*image)->exception);
1796 if (text == (char *) NULL)
1797 break;
1798 (void) fputs(text,stdout);
1799 (void) fputc('\n',stdout);
1800 text=DestroyString(text);
1801 break;
1802 }
1803 if (LocaleCompare("implode",option+1) == 0)
1804 {
1805 /*
1806 Implode image.
1807 */
1808 (void) SyncImageSettings(mogrify_info,*image);
1809 (void) ParseGeometry(argv[i+1],&geometry_info);
1810 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1811 break;
1812 }
1813 if (LocaleCompare("interline-spacing",option+1) == 0)
1814 {
1815 if (*option == '+')
1816 (void) ParseGeometry("0",&geometry_info);
1817 else
1818 (void) ParseGeometry(argv[i+1],&geometry_info);
1819 draw_info->interline_spacing=geometry_info.rho;
1820 break;
1821 }
1822 if (LocaleCompare("interword-spacing",option+1) == 0)
1823 {
1824 if (*option == '+')
1825 (void) ParseGeometry("0",&geometry_info);
1826 else
1827 (void) ParseGeometry(argv[i+1],&geometry_info);
1828 draw_info->interword_spacing=geometry_info.rho;
1829 break;
1830 }
1831 break;
1832 }
1833 case 'k':
1834 {
1835 if (LocaleCompare("kerning",option+1) == 0)
1836 {
1837 if (*option == '+')
1838 (void) ParseGeometry("0",&geometry_info);
1839 else
1840 (void) ParseGeometry(argv[i+1],&geometry_info);
1841 draw_info->kerning=geometry_info.rho;
1842 break;
1843 }
1844 break;
1845 }
1846 case 'l':
1847 {
1848 if (LocaleCompare("lat",option+1) == 0)
1849 {
1850 /*
1851 Local adaptive threshold image.
1852 */
1853 (void) SyncImageSettings(mogrify_info,*image);
1854 flags=ParseGeometry(argv[i+1],&geometry_info);
1855 if ((flags & PercentValue) != 0)
1856 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1857 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1858 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1859 geometry_info.xi,exception);
1860 break;
1861 }
1862 if (LocaleCompare("level",option+1) == 0)
1863 {
1864 MagickRealType
1865 black_point,
1866 gamma,
1867 white_point;
1868
1869 MagickStatusType
1870 flags;
1871
1872 /*
1873 Parse levels.
1874 */
1875 (void) SyncImageSettings(mogrify_info,*image);
1876 flags=ParseGeometry(argv[i+1],&geometry_info);
1877 black_point=geometry_info.rho;
1878 white_point=(MagickRealType) QuantumRange;
1879 if ((flags & SigmaValue) != 0)
1880 white_point=geometry_info.sigma;
1881 gamma=1.0;
1882 if ((flags & XiValue) != 0)
1883 gamma=geometry_info.xi;
1884 if ((flags & PercentValue) != 0)
1885 {
1886 black_point*=(MagickRealType) (QuantumRange/100.0);
1887 white_point*=(MagickRealType) (QuantumRange/100.0);
1888 }
1889 if ((flags & SigmaValue) == 0)
1890 white_point=(MagickRealType) QuantumRange-black_point;
1891 if ((*option == '+') || ((flags & AspectValue) != 0))
1892 (void) LevelizeImageChannel(*image,channel,black_point,
1893 white_point,gamma);
1894 else
1895 (void) LevelImageChannel(*image,channel,black_point,white_point,
1896 gamma);
1897 InheritException(exception,&(*image)->exception);
1898 break;
1899 }
1900 if (LocaleCompare("level-colors",option+1) == 0)
1901 {
1902 char
1903 token[MaxTextExtent];
1904
1905 const char
1906 *p;
1907
cristy4c08aed2011-07-01 19:47:50 +00001908 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001909 black_point,
1910 white_point;
1911
1912 p=(const char *) argv[i+1];
1913 GetMagickToken(p,&p,token); /* get black point color */
1914 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1915 (void) QueryMagickColor(token,&black_point,exception);
1916 else
1917 (void) QueryMagickColor("#000000",&black_point,exception);
1918 if (isalpha((int) token[0]) || (token[0] == '#'))
1919 GetMagickToken(p,&p,token);
1920 if (*token == '\0')
1921 white_point=black_point; /* set everything to that color */
1922 else
1923 {
1924 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1925 GetMagickToken(p,&p,token); /* Get white point color. */
1926 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1927 (void) QueryMagickColor(token,&white_point,exception);
1928 else
1929 (void) QueryMagickColor("#ffffff",&white_point,exception);
1930 }
1931 (void) LevelColorsImageChannel(*image,channel,&black_point,
1932 &white_point,*option == '+' ? MagickTrue : MagickFalse);
1933 break;
1934 }
1935 if (LocaleCompare("linear-stretch",option+1) == 0)
1936 {
1937 double
1938 black_point,
1939 white_point;
1940
1941 MagickStatusType
1942 flags;
1943
1944 (void) SyncImageSettings(mogrify_info,*image);
1945 flags=ParseGeometry(argv[i+1],&geometry_info);
1946 black_point=geometry_info.rho;
1947 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1948 if ((flags & SigmaValue) != 0)
1949 white_point=geometry_info.sigma;
1950 if ((flags & PercentValue) != 0)
1951 {
1952 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1953 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1954 }
1955 if ((flags & SigmaValue) == 0)
1956 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1957 black_point;
1958 (void) LinearStretchImage(*image,black_point,white_point);
1959 InheritException(exception,&(*image)->exception);
1960 break;
1961 }
1962 if (LocaleCompare("linewidth",option+1) == 0)
1963 {
cristyc1acd842011-05-19 23:05:47 +00001964 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1965 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001966 break;
1967 }
1968 if (LocaleCompare("liquid-rescale",option+1) == 0)
1969 {
1970 /*
1971 Liquid rescale image.
1972 */
1973 (void) SyncImageSettings(mogrify_info,*image);
1974 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1975 if ((flags & XValue) == 0)
1976 geometry.x=1;
1977 if ((flags & YValue) == 0)
1978 geometry.y=0;
1979 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1980 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1981 break;
1982 }
1983 if (LocaleCompare("lowlight-color",option+1) == 0)
1984 {
1985 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1986 break;
1987 }
1988 break;
1989 }
1990 case 'm':
1991 {
1992 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001993 {
cristy3ed852e2009-09-05 21:47:34 +00001994 Image
anthonydf8ebac2011-04-27 09:03:19 +00001995 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001996
anthonydf8ebac2011-04-27 09:03:19 +00001997 /*
1998 Transform image colors to match this set of colors.
1999 */
2000 (void) SyncImageSettings(mogrify_info,*image);
2001 if (*option == '+')
2002 break;
2003 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2004 if (remap_image == (Image *) NULL)
2005 break;
2006 (void) RemapImage(quantize_info,*image,remap_image);
2007 InheritException(exception,&(*image)->exception);
2008 remap_image=DestroyImage(remap_image);
2009 break;
2010 }
2011 if (LocaleCompare("mask",option+1) == 0)
2012 {
2013 Image
2014 *mask;
2015
2016 (void) SyncImageSettings(mogrify_info,*image);
2017 if (*option == '+')
2018 {
2019 /*
2020 Remove a mask.
2021 */
2022 (void) SetImageMask(*image,(Image *) NULL);
2023 InheritException(exception,&(*image)->exception);
2024 break;
2025 }
2026 /*
2027 Set the image mask.
2028 */
2029 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2030 if (mask == (Image *) NULL)
2031 break;
2032 (void) SetImageMask(*image,mask);
2033 mask=DestroyImage(mask);
2034 InheritException(exception,&(*image)->exception);
2035 break;
2036 }
2037 if (LocaleCompare("matte",option+1) == 0)
2038 {
2039 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2040 SetAlphaChannel : DeactivateAlphaChannel );
2041 InheritException(exception,&(*image)->exception);
2042 break;
2043 }
2044 if (LocaleCompare("median",option+1) == 0)
2045 {
2046 /*
2047 Median filter image.
2048 */
2049 (void) SyncImageSettings(mogrify_info,*image);
2050 (void) ParseGeometry(argv[i+1],&geometry_info);
2051 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
2052 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2053 break;
2054 }
2055 if (LocaleCompare("mode",option+1) == 0)
2056 {
2057 /*
2058 Mode image.
2059 */
2060 (void) SyncImageSettings(mogrify_info,*image);
2061 (void) ParseGeometry(argv[i+1],&geometry_info);
2062 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
2063 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2064 break;
2065 }
2066 if (LocaleCompare("modulate",option+1) == 0)
2067 {
2068 (void) SyncImageSettings(mogrify_info,*image);
2069 (void) ModulateImage(*image,argv[i+1]);
2070 InheritException(exception,&(*image)->exception);
2071 break;
2072 }
2073 if (LocaleCompare("monitor",option+1) == 0)
2074 {
2075 if (*option == '+')
2076 {
2077 (void) SetImageProgressMonitor(*image,
2078 (MagickProgressMonitor) NULL,(void *) NULL);
2079 break;
2080 }
2081 (void) SetImageProgressMonitor(*image,MonitorProgress,
2082 (void *) NULL);
2083 break;
2084 }
2085 if (LocaleCompare("monochrome",option+1) == 0)
2086 {
2087 (void) SyncImageSettings(mogrify_info,*image);
2088 (void) SetImageType(*image,BilevelType);
2089 InheritException(exception,&(*image)->exception);
2090 break;
2091 }
2092 if (LocaleCompare("morphology",option+1) == 0)
2093 {
2094 char
2095 token[MaxTextExtent];
2096
2097 const char
2098 *p;
2099
2100 KernelInfo
2101 *kernel;
2102
2103 MorphologyMethod
2104 method;
2105
2106 ssize_t
2107 iterations;
2108
2109 /*
2110 Morphological Image Operation
2111 */
2112 (void) SyncImageSettings(mogrify_info,*image);
2113 p=argv[i+1];
2114 GetMagickToken(p,&p,token);
2115 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2116 MagickFalse,token);
2117 iterations=1L;
2118 GetMagickToken(p,&p,token);
2119 if ((*p == ':') || (*p == ','))
2120 GetMagickToken(p,&p,token);
2121 if ((*p != '\0'))
2122 iterations=(ssize_t) StringToLong(p);
2123 kernel=AcquireKernelInfo(argv[i+2]);
2124 if (kernel == (KernelInfo *) NULL)
2125 {
2126 (void) ThrowMagickException(exception,GetMagickModule(),
2127 OptionError,"UnabletoParseKernel","morphology");
2128 status=MagickFalse;
2129 break;
2130 }
2131 mogrify_image=MorphologyImageChannel(*image,channel,method,
2132 iterations,kernel,exception);
2133 kernel=DestroyKernelInfo(kernel);
2134 break;
2135 }
2136 if (LocaleCompare("motion-blur",option+1) == 0)
2137 {
2138 /*
2139 Motion blur image.
2140 */
2141 (void) SyncImageSettings(mogrify_info,*image);
2142 flags=ParseGeometry(argv[i+1],&geometry_info);
2143 if ((flags & SigmaValue) == 0)
2144 geometry_info.sigma=1.0;
2145 mogrify_image=MotionBlurImageChannel(*image,channel,
2146 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2147 break;
2148 }
2149 break;
2150 }
2151 case 'n':
2152 {
2153 if (LocaleCompare("negate",option+1) == 0)
2154 {
2155 (void) SyncImageSettings(mogrify_info,*image);
2156 (void) NegateImageChannel(*image,channel,*option == '+' ?
2157 MagickTrue : MagickFalse);
2158 InheritException(exception,&(*image)->exception);
2159 break;
2160 }
2161 if (LocaleCompare("noise",option+1) == 0)
2162 {
2163 (void) SyncImageSettings(mogrify_info,*image);
2164 if (*option == '-')
2165 {
2166 (void) ParseGeometry(argv[i+1],&geometry_info);
2167 mogrify_image=StatisticImageChannel(*image,channel,
2168 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2169 geometry_info.rho,exception);
2170 }
2171 else
2172 {
2173 NoiseType
2174 noise;
2175
2176 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2177 MagickFalse,argv[i+1]);
2178 mogrify_image=AddNoiseImageChannel(*image,channel,noise,
2179 exception);
2180 }
2181 break;
2182 }
2183 if (LocaleCompare("normalize",option+1) == 0)
2184 {
2185 (void) SyncImageSettings(mogrify_info,*image);
2186 (void) NormalizeImageChannel(*image,channel);
2187 InheritException(exception,&(*image)->exception);
2188 break;
2189 }
2190 break;
2191 }
2192 case 'o':
2193 {
2194 if (LocaleCompare("opaque",option+1) == 0)
2195 {
cristy4c08aed2011-07-01 19:47:50 +00002196 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002197 target;
2198
2199 (void) SyncImageSettings(mogrify_info,*image);
2200 (void) QueryMagickColor(argv[i+1],&target,exception);
2201 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2202 *option == '-' ? MagickFalse : MagickTrue);
2203 break;
2204 }
2205 if (LocaleCompare("ordered-dither",option+1) == 0)
2206 {
2207 (void) SyncImageSettings(mogrify_info,*image);
2208 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2209 exception);
2210 break;
2211 }
2212 break;
2213 }
2214 case 'p':
2215 {
2216 if (LocaleCompare("paint",option+1) == 0)
2217 {
anthonydf8ebac2011-04-27 09:03:19 +00002218 (void) SyncImageSettings(mogrify_info,*image);
2219 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002220 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002221 break;
2222 }
2223 if (LocaleCompare("pen",option+1) == 0)
2224 {
2225 if (*option == '+')
2226 {
2227 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2228 break;
2229 }
2230 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2231 break;
2232 }
2233 if (LocaleCompare("pointsize",option+1) == 0)
2234 {
2235 if (*option == '+')
2236 (void) ParseGeometry("12",&geometry_info);
2237 else
2238 (void) ParseGeometry(argv[i+1],&geometry_info);
2239 draw_info->pointsize=geometry_info.rho;
2240 break;
2241 }
2242 if (LocaleCompare("polaroid",option+1) == 0)
2243 {
2244 double
2245 angle;
2246
2247 RandomInfo
2248 *random_info;
2249
2250 /*
2251 Simulate a Polaroid picture.
2252 */
2253 (void) SyncImageSettings(mogrify_info,*image);
2254 random_info=AcquireRandomInfo();
2255 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2256 random_info=DestroyRandomInfo(random_info);
2257 if (*option == '-')
2258 {
2259 SetGeometryInfo(&geometry_info);
2260 flags=ParseGeometry(argv[i+1],&geometry_info);
2261 angle=geometry_info.rho;
2262 }
2263 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2264 break;
2265 }
2266 if (LocaleCompare("posterize",option+1) == 0)
2267 {
2268 /*
2269 Posterize image.
2270 */
2271 (void) SyncImageSettings(mogrify_info,*image);
2272 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2273 quantize_info->dither);
2274 InheritException(exception,&(*image)->exception);
2275 break;
2276 }
2277 if (LocaleCompare("preview",option+1) == 0)
2278 {
2279 PreviewType
2280 preview_type;
2281
2282 /*
2283 Preview image.
2284 */
2285 (void) SyncImageSettings(mogrify_info,*image);
2286 if (*option == '+')
2287 preview_type=UndefinedPreview;
2288 else
2289 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2290 MagickFalse,argv[i+1]);
2291 mogrify_image=PreviewImage(*image,preview_type,exception);
2292 break;
2293 }
2294 if (LocaleCompare("profile",option+1) == 0)
2295 {
2296 const char
2297 *name;
2298
2299 const StringInfo
2300 *profile;
2301
2302 Image
2303 *profile_image;
2304
2305 ImageInfo
2306 *profile_info;
2307
2308 (void) SyncImageSettings(mogrify_info,*image);
2309 if (*option == '+')
2310 {
2311 /*
2312 Remove a profile from the image.
2313 */
2314 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2315 NULL,0,MagickTrue);
2316 InheritException(exception,&(*image)->exception);
2317 break;
2318 }
2319 /*
2320 Associate a profile with the image.
2321 */
2322 profile_info=CloneImageInfo(mogrify_info);
2323 profile=GetImageProfile(*image,"iptc");
2324 if (profile != (StringInfo *) NULL)
2325 profile_info->profile=(void *) CloneStringInfo(profile);
2326 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2327 profile_info=DestroyImageInfo(profile_info);
2328 if (profile_image == (Image *) NULL)
2329 {
2330 StringInfo
2331 *profile;
2332
2333 profile_info=CloneImageInfo(mogrify_info);
2334 (void) CopyMagickString(profile_info->filename,argv[i+1],
2335 MaxTextExtent);
2336 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2337 if (profile != (StringInfo *) NULL)
2338 {
2339 (void) ProfileImage(*image,profile_info->magick,
2340 GetStringInfoDatum(profile),(size_t)
2341 GetStringInfoLength(profile),MagickFalse);
2342 profile=DestroyStringInfo(profile);
2343 }
2344 profile_info=DestroyImageInfo(profile_info);
2345 break;
2346 }
2347 ResetImageProfileIterator(profile_image);
2348 name=GetNextImageProfile(profile_image);
2349 while (name != (const char *) NULL)
2350 {
2351 profile=GetImageProfile(profile_image,name);
2352 if (profile != (StringInfo *) NULL)
2353 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2354 (size_t) GetStringInfoLength(profile),MagickFalse);
2355 name=GetNextImageProfile(profile_image);
2356 }
2357 profile_image=DestroyImage(profile_image);
2358 break;
2359 }
2360 break;
2361 }
2362 case 'q':
2363 {
2364 if (LocaleCompare("quantize",option+1) == 0)
2365 {
2366 if (*option == '+')
2367 {
2368 quantize_info->colorspace=UndefinedColorspace;
2369 break;
2370 }
2371 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2372 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2373 break;
2374 }
2375 break;
2376 }
2377 case 'r':
2378 {
2379 if (LocaleCompare("radial-blur",option+1) == 0)
2380 {
2381 /*
2382 Radial blur image.
2383 */
2384 (void) SyncImageSettings(mogrify_info,*image);
2385 mogrify_image=RadialBlurImageChannel(*image,channel,
cristyc1acd842011-05-19 23:05:47 +00002386 InterpretLocaleValue(argv[i+1],(char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002387 break;
2388 }
2389 if (LocaleCompare("raise",option+1) == 0)
2390 {
2391 /*
2392 Surround image with a raise of solid color.
2393 */
2394 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2395 if ((flags & SigmaValue) == 0)
2396 geometry.height=geometry.width;
2397 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2398 MagickFalse);
2399 InheritException(exception,&(*image)->exception);
2400 break;
2401 }
2402 if (LocaleCompare("random-threshold",option+1) == 0)
2403 {
2404 /*
2405 Threshold image.
2406 */
2407 (void) SyncImageSettings(mogrify_info,*image);
2408 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2409 exception);
2410 break;
2411 }
2412 if (LocaleCompare("recolor",option+1) == 0)
2413 {
2414 KernelInfo
2415 *kernel;
2416
2417 (void) SyncImageSettings(mogrify_info,*image);
2418 kernel=AcquireKernelInfo(argv[i+1]);
2419 if (kernel == (KernelInfo *) NULL)
2420 break;
2421 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2422 kernel=DestroyKernelInfo(kernel);
2423 break;
2424 }
2425 if (LocaleCompare("region",option+1) == 0)
2426 {
2427 (void) SyncImageSettings(mogrify_info,*image);
2428 if (region_image != (Image *) NULL)
2429 {
2430 /*
2431 Composite region.
2432 */
2433 (void) CompositeImage(region_image,region_image->matte !=
cristyab015852011-07-06 01:03:32 +00002434 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2435 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002436 InheritException(exception,&region_image->exception);
2437 *image=DestroyImage(*image);
2438 *image=region_image;
2439 region_image = (Image *) NULL;
2440 }
2441 if (*option == '+')
2442 break;
2443 /*
2444 Apply transformations to a selected region of the image.
2445 */
cristy3ed852e2009-09-05 21:47:34 +00002446 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2447 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002448 mogrify_image=CropImage(*image,&region_geometry,exception);
2449 if (mogrify_image == (Image *) NULL)
2450 break;
2451 region_image=(*image);
2452 *image=mogrify_image;
2453 mogrify_image=(Image *) NULL;
2454 break;
cristy3ed852e2009-09-05 21:47:34 +00002455 }
anthonydf8ebac2011-04-27 09:03:19 +00002456 if (LocaleCompare("render",option+1) == 0)
2457 {
2458 (void) SyncImageSettings(mogrify_info,*image);
2459 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2460 break;
2461 }
2462 if (LocaleCompare("remap",option+1) == 0)
2463 {
2464 Image
2465 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002466
anthonydf8ebac2011-04-27 09:03:19 +00002467 /*
2468 Transform image colors to match this set of colors.
2469 */
2470 (void) SyncImageSettings(mogrify_info,*image);
2471 if (*option == '+')
2472 break;
2473 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2474 if (remap_image == (Image *) NULL)
2475 break;
2476 (void) RemapImage(quantize_info,*image,remap_image);
2477 InheritException(exception,&(*image)->exception);
2478 remap_image=DestroyImage(remap_image);
2479 break;
2480 }
2481 if (LocaleCompare("repage",option+1) == 0)
2482 {
2483 if (*option == '+')
2484 {
2485 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2486 break;
2487 }
2488 (void) ResetImagePage(*image,argv[i+1]);
2489 InheritException(exception,&(*image)->exception);
2490 break;
2491 }
2492 if (LocaleCompare("resample",option+1) == 0)
2493 {
2494 /*
2495 Resample image.
2496 */
2497 (void) SyncImageSettings(mogrify_info,*image);
2498 flags=ParseGeometry(argv[i+1],&geometry_info);
2499 if ((flags & SigmaValue) == 0)
2500 geometry_info.sigma=geometry_info.rho;
2501 mogrify_image=ResampleImage(*image,geometry_info.rho,
2502 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2503 break;
2504 }
2505 if (LocaleCompare("resize",option+1) == 0)
2506 {
2507 /*
2508 Resize image.
2509 */
2510 (void) SyncImageSettings(mogrify_info,*image);
2511 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2512 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2513 (*image)->filter,(*image)->blur,exception);
2514 break;
2515 }
2516 if (LocaleCompare("roll",option+1) == 0)
2517 {
2518 /*
2519 Roll image.
2520 */
2521 (void) SyncImageSettings(mogrify_info,*image);
2522 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2523 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2524 break;
2525 }
2526 if (LocaleCompare("rotate",option+1) == 0)
2527 {
2528 char
2529 *geometry;
2530
2531 /*
2532 Check for conditional image rotation.
2533 */
2534 (void) SyncImageSettings(mogrify_info,*image);
2535 if (strchr(argv[i+1],'>') != (char *) NULL)
2536 if ((*image)->columns <= (*image)->rows)
2537 break;
2538 if (strchr(argv[i+1],'<') != (char *) NULL)
2539 if ((*image)->columns >= (*image)->rows)
2540 break;
2541 /*
2542 Rotate image.
2543 */
2544 geometry=ConstantString(argv[i+1]);
2545 (void) SubstituteString(&geometry,">","");
2546 (void) SubstituteString(&geometry,"<","");
2547 (void) ParseGeometry(geometry,&geometry_info);
2548 geometry=DestroyString(geometry);
2549 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2550 break;
2551 }
2552 break;
2553 }
2554 case 's':
2555 {
2556 if (LocaleCompare("sample",option+1) == 0)
2557 {
2558 /*
2559 Sample image with pixel replication.
2560 */
2561 (void) SyncImageSettings(mogrify_info,*image);
2562 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2563 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2564 exception);
2565 break;
2566 }
2567 if (LocaleCompare("scale",option+1) == 0)
2568 {
2569 /*
2570 Resize image.
2571 */
2572 (void) SyncImageSettings(mogrify_info,*image);
2573 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2574 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2575 exception);
2576 break;
2577 }
2578 if (LocaleCompare("selective-blur",option+1) == 0)
2579 {
2580 /*
2581 Selectively blur pixels within a contrast threshold.
2582 */
2583 (void) SyncImageSettings(mogrify_info,*image);
2584 flags=ParseGeometry(argv[i+1],&geometry_info);
2585 if ((flags & PercentValue) != 0)
2586 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2587 mogrify_image=SelectiveBlurImageChannel(*image,channel,
2588 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2589 break;
2590 }
2591 if (LocaleCompare("separate",option+1) == 0)
2592 {
2593 /*
2594 Break channels into separate images.
2595 WARNING: This can generate multiple images!
2596 */
2597 (void) SyncImageSettings(mogrify_info,*image);
2598 mogrify_image=SeparateImages(*image,channel,exception);
2599 break;
2600 }
2601 if (LocaleCompare("sepia-tone",option+1) == 0)
2602 {
2603 double
2604 threshold;
2605
2606 /*
2607 Sepia-tone image.
2608 */
2609 (void) SyncImageSettings(mogrify_info,*image);
2610 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2611 mogrify_image=SepiaToneImage(*image,threshold,exception);
2612 break;
2613 }
2614 if (LocaleCompare("segment",option+1) == 0)
2615 {
2616 /*
2617 Segment image.
2618 */
2619 (void) SyncImageSettings(mogrify_info,*image);
2620 flags=ParseGeometry(argv[i+1],&geometry_info);
2621 if ((flags & SigmaValue) == 0)
2622 geometry_info.sigma=1.0;
2623 (void) SegmentImage(*image,(*image)->colorspace,
2624 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2625 InheritException(exception,&(*image)->exception);
2626 break;
2627 }
2628 if (LocaleCompare("set",option+1) == 0)
2629 {
2630 char
2631 *value;
2632
2633 /*
2634 Set image option.
2635 */
2636 if (*option == '+')
2637 {
2638 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2639 (void) DeleteImageRegistry(argv[i+1]+9);
2640 else
2641 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2642 {
2643 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2644 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2645 }
2646 else
2647 (void) DeleteImageProperty(*image,argv[i+1]);
2648 break;
2649 }
2650 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2651 if (value == (char *) NULL)
2652 break;
2653 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2654 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2655 exception);
2656 else
2657 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2658 {
2659 (void) SetImageOption(image_info,argv[i+1]+7,value);
2660 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2661 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2662 }
2663 else
2664 (void) SetImageProperty(*image,argv[i+1],value);
2665 value=DestroyString(value);
2666 break;
2667 }
2668 if (LocaleCompare("shade",option+1) == 0)
2669 {
2670 /*
2671 Shade image.
2672 */
2673 (void) SyncImageSettings(mogrify_info,*image);
2674 flags=ParseGeometry(argv[i+1],&geometry_info);
2675 if ((flags & SigmaValue) == 0)
2676 geometry_info.sigma=1.0;
2677 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2678 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2679 break;
2680 }
2681 if (LocaleCompare("shadow",option+1) == 0)
2682 {
2683 /*
2684 Shadow image.
2685 */
2686 (void) SyncImageSettings(mogrify_info,*image);
2687 flags=ParseGeometry(argv[i+1],&geometry_info);
2688 if ((flags & SigmaValue) == 0)
2689 geometry_info.sigma=1.0;
2690 if ((flags & XiValue) == 0)
2691 geometry_info.xi=4.0;
2692 if ((flags & PsiValue) == 0)
2693 geometry_info.psi=4.0;
2694 mogrify_image=ShadowImage(*image,geometry_info.rho,
2695 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2696 ceil(geometry_info.psi-0.5),exception);
2697 break;
2698 }
2699 if (LocaleCompare("sharpen",option+1) == 0)
2700 {
2701 /*
2702 Sharpen image.
2703 */
2704 (void) SyncImageSettings(mogrify_info,*image);
2705 flags=ParseGeometry(argv[i+1],&geometry_info);
2706 if ((flags & SigmaValue) == 0)
2707 geometry_info.sigma=1.0;
2708 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2709 geometry_info.sigma,exception);
2710 break;
2711 }
2712 if (LocaleCompare("shave",option+1) == 0)
2713 {
2714 /*
2715 Shave the image edges.
2716 */
2717 (void) SyncImageSettings(mogrify_info,*image);
2718 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2719 mogrify_image=ShaveImage(*image,&geometry,exception);
2720 break;
2721 }
2722 if (LocaleCompare("shear",option+1) == 0)
2723 {
2724 /*
2725 Shear image.
2726 */
2727 (void) SyncImageSettings(mogrify_info,*image);
2728 flags=ParseGeometry(argv[i+1],&geometry_info);
2729 if ((flags & SigmaValue) == 0)
2730 geometry_info.sigma=geometry_info.rho;
2731 mogrify_image=ShearImage(*image,geometry_info.rho,
2732 geometry_info.sigma,exception);
2733 break;
2734 }
2735 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2736 {
2737 /*
2738 Sigmoidal non-linearity contrast control.
2739 */
2740 (void) SyncImageSettings(mogrify_info,*image);
2741 flags=ParseGeometry(argv[i+1],&geometry_info);
2742 if ((flags & SigmaValue) == 0)
2743 geometry_info.sigma=(double) QuantumRange/2.0;
2744 if ((flags & PercentValue) != 0)
2745 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2746 100.0;
cristy9ee60942011-07-06 14:54:38 +00002747 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2748 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002749 InheritException(exception,&(*image)->exception);
2750 break;
2751 }
2752 if (LocaleCompare("sketch",option+1) == 0)
2753 {
2754 /*
2755 Sketch image.
2756 */
2757 (void) SyncImageSettings(mogrify_info,*image);
2758 flags=ParseGeometry(argv[i+1],&geometry_info);
2759 if ((flags & SigmaValue) == 0)
2760 geometry_info.sigma=1.0;
2761 mogrify_image=SketchImage(*image,geometry_info.rho,
2762 geometry_info.sigma,geometry_info.xi,exception);
2763 break;
2764 }
2765 if (LocaleCompare("solarize",option+1) == 0)
2766 {
2767 double
2768 threshold;
2769
2770 (void) SyncImageSettings(mogrify_info,*image);
2771 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2772 (void) SolarizeImage(*image,threshold);
2773 InheritException(exception,&(*image)->exception);
2774 break;
2775 }
2776 if (LocaleCompare("sparse-color",option+1) == 0)
2777 {
2778 SparseColorMethod
2779 method;
2780
2781 char
2782 *arguments;
2783
2784 /*
2785 Sparse Color Interpolated Gradient
2786 */
2787 (void) SyncImageSettings(mogrify_info,*image);
2788 method=(SparseColorMethod) ParseCommandOption(
2789 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2790 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2791 InheritException(exception,&(*image)->exception);
2792 if (arguments == (char *) NULL)
2793 break;
2794 mogrify_image=SparseColorOption(*image,channel,method,arguments,
2795 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2796 arguments=DestroyString(arguments);
2797 break;
2798 }
2799 if (LocaleCompare("splice",option+1) == 0)
2800 {
2801 /*
2802 Splice a solid color into the image.
2803 */
2804 (void) SyncImageSettings(mogrify_info,*image);
2805 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2806 mogrify_image=SpliceImage(*image,&geometry,exception);
2807 break;
2808 }
2809 if (LocaleCompare("spread",option+1) == 0)
2810 {
2811 /*
2812 Spread an image.
2813 */
2814 (void) SyncImageSettings(mogrify_info,*image);
2815 (void) ParseGeometry(argv[i+1],&geometry_info);
2816 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2817 break;
2818 }
2819 if (LocaleCompare("statistic",option+1) == 0)
2820 {
2821 StatisticType
2822 type;
2823
2824 (void) SyncImageSettings(mogrify_info,*image);
2825 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2826 MagickFalse,argv[i+1]);
2827 (void) ParseGeometry(argv[i+2],&geometry_info);
2828 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2829 geometry_info.rho,(size_t) geometry_info.sigma,exception);
2830 break;
2831 }
2832 if (LocaleCompare("stretch",option+1) == 0)
2833 {
2834 if (*option == '+')
2835 {
2836 draw_info->stretch=UndefinedStretch;
2837 break;
2838 }
2839 draw_info->stretch=(StretchType) ParseCommandOption(
2840 MagickStretchOptions,MagickFalse,argv[i+1]);
2841 break;
2842 }
2843 if (LocaleCompare("strip",option+1) == 0)
2844 {
2845 /*
2846 Strip image of profiles and comments.
2847 */
2848 (void) SyncImageSettings(mogrify_info,*image);
2849 (void) StripImage(*image);
2850 InheritException(exception,&(*image)->exception);
2851 break;
2852 }
2853 if (LocaleCompare("stroke",option+1) == 0)
2854 {
2855 ExceptionInfo
2856 *sans;
2857
2858 if (*option == '+')
2859 {
2860 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2861 if (draw_info->stroke_pattern != (Image *) NULL)
2862 draw_info->stroke_pattern=DestroyImage(
2863 draw_info->stroke_pattern);
2864 break;
2865 }
2866 sans=AcquireExceptionInfo();
2867 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2868 sans=DestroyExceptionInfo(sans);
2869 if (status == MagickFalse)
2870 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2871 exception);
2872 break;
2873 }
2874 if (LocaleCompare("strokewidth",option+1) == 0)
2875 {
cristyc1acd842011-05-19 23:05:47 +00002876 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2877 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002878 break;
2879 }
2880 if (LocaleCompare("style",option+1) == 0)
2881 {
2882 if (*option == '+')
2883 {
2884 draw_info->style=UndefinedStyle;
2885 break;
2886 }
2887 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2888 MagickFalse,argv[i+1]);
2889 break;
2890 }
2891 if (LocaleCompare("swirl",option+1) == 0)
2892 {
2893 /*
2894 Swirl image.
2895 */
2896 (void) SyncImageSettings(mogrify_info,*image);
2897 (void) ParseGeometry(argv[i+1],&geometry_info);
2898 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2899 break;
2900 }
2901 break;
2902 }
2903 case 't':
2904 {
2905 if (LocaleCompare("threshold",option+1) == 0)
2906 {
2907 double
2908 threshold;
2909
2910 /*
2911 Threshold image.
2912 */
2913 (void) SyncImageSettings(mogrify_info,*image);
2914 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002915 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002916 else
2917 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2918 (void) BilevelImageChannel(*image,channel,threshold);
2919 InheritException(exception,&(*image)->exception);
2920 break;
2921 }
2922 if (LocaleCompare("thumbnail",option+1) == 0)
2923 {
2924 /*
2925 Thumbnail image.
2926 */
2927 (void) SyncImageSettings(mogrify_info,*image);
2928 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2929 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2930 exception);
2931 break;
2932 }
2933 if (LocaleCompare("tile",option+1) == 0)
2934 {
2935 if (*option == '+')
2936 {
2937 if (draw_info->fill_pattern != (Image *) NULL)
2938 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2939 break;
2940 }
2941 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2942 exception);
2943 break;
2944 }
2945 if (LocaleCompare("tint",option+1) == 0)
2946 {
2947 /*
2948 Tint the image.
2949 */
2950 (void) SyncImageSettings(mogrify_info,*image);
2951 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2952 break;
2953 }
2954 if (LocaleCompare("transform",option+1) == 0)
2955 {
2956 /*
2957 Affine transform image.
2958 */
2959 (void) SyncImageSettings(mogrify_info,*image);
2960 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2961 exception);
2962 break;
2963 }
2964 if (LocaleCompare("transparent",option+1) == 0)
2965 {
cristy4c08aed2011-07-01 19:47:50 +00002966 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002967 target;
2968
2969 (void) SyncImageSettings(mogrify_info,*image);
2970 (void) QueryMagickColor(argv[i+1],&target,exception);
2971 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002972 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002973 InheritException(exception,&(*image)->exception);
2974 break;
2975 }
2976 if (LocaleCompare("transpose",option+1) == 0)
2977 {
2978 /*
2979 Transpose image scanlines.
2980 */
2981 (void) SyncImageSettings(mogrify_info,*image);
2982 mogrify_image=TransposeImage(*image,exception);
2983 break;
2984 }
2985 if (LocaleCompare("transverse",option+1) == 0)
2986 {
2987 /*
2988 Transverse image scanlines.
2989 */
2990 (void) SyncImageSettings(mogrify_info,*image);
2991 mogrify_image=TransverseImage(*image,exception);
2992 break;
2993 }
2994 if (LocaleCompare("treedepth",option+1) == 0)
2995 {
2996 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2997 break;
2998 }
2999 if (LocaleCompare("trim",option+1) == 0)
3000 {
3001 /*
3002 Trim image.
3003 */
3004 (void) SyncImageSettings(mogrify_info,*image);
3005 mogrify_image=TrimImage(*image,exception);
3006 break;
3007 }
3008 if (LocaleCompare("type",option+1) == 0)
3009 {
3010 ImageType
3011 type;
3012
3013 (void) SyncImageSettings(mogrify_info,*image);
3014 if (*option == '+')
3015 type=UndefinedType;
3016 else
3017 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3018 argv[i+1]);
3019 (*image)->type=UndefinedType;
3020 (void) SetImageType(*image,type);
3021 InheritException(exception,&(*image)->exception);
3022 break;
3023 }
3024 break;
3025 }
3026 case 'u':
3027 {
3028 if (LocaleCompare("undercolor",option+1) == 0)
3029 {
3030 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3031 exception);
3032 break;
3033 }
3034 if (LocaleCompare("unique",option+1) == 0)
3035 {
3036 if (*option == '+')
3037 {
3038 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3039 break;
3040 }
3041 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3042 (void) SetImageArtifact(*image,"verbose","true");
3043 break;
3044 }
3045 if (LocaleCompare("unique-colors",option+1) == 0)
3046 {
3047 /*
3048 Unique image colors.
3049 */
3050 (void) SyncImageSettings(mogrify_info,*image);
3051 mogrify_image=UniqueImageColors(*image,exception);
3052 break;
3053 }
3054 if (LocaleCompare("unsharp",option+1) == 0)
3055 {
3056 /*
3057 Unsharp mask image.
3058 */
3059 (void) SyncImageSettings(mogrify_info,*image);
3060 flags=ParseGeometry(argv[i+1],&geometry_info);
3061 if ((flags & SigmaValue) == 0)
3062 geometry_info.sigma=1.0;
3063 if ((flags & XiValue) == 0)
3064 geometry_info.xi=1.0;
3065 if ((flags & PsiValue) == 0)
3066 geometry_info.psi=0.05;
3067 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3068 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3069 geometry_info.psi,exception);
3070 break;
3071 }
3072 break;
3073 }
3074 case 'v':
3075 {
3076 if (LocaleCompare("verbose",option+1) == 0)
3077 {
3078 (void) SetImageArtifact(*image,option+1,
3079 *option == '+' ? "false" : "true");
3080 break;
3081 }
3082 if (LocaleCompare("vignette",option+1) == 0)
3083 {
3084 /*
3085 Vignette image.
3086 */
3087 (void) SyncImageSettings(mogrify_info,*image);
3088 flags=ParseGeometry(argv[i+1],&geometry_info);
3089 if ((flags & SigmaValue) == 0)
3090 geometry_info.sigma=1.0;
3091 if ((flags & XiValue) == 0)
3092 geometry_info.xi=0.1*(*image)->columns;
3093 if ((flags & PsiValue) == 0)
3094 geometry_info.psi=0.1*(*image)->rows;
3095 mogrify_image=VignetteImage(*image,geometry_info.rho,
3096 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3097 ceil(geometry_info.psi-0.5),exception);
3098 break;
3099 }
3100 if (LocaleCompare("virtual-pixel",option+1) == 0)
3101 {
3102 if (*option == '+')
3103 {
3104 (void) SetImageVirtualPixelMethod(*image,
3105 UndefinedVirtualPixelMethod);
3106 break;
3107 }
3108 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3109 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3110 argv[i+1]));
3111 break;
3112 }
3113 break;
3114 }
3115 case 'w':
3116 {
3117 if (LocaleCompare("wave",option+1) == 0)
3118 {
3119 /*
3120 Wave image.
3121 */
3122 (void) SyncImageSettings(mogrify_info,*image);
3123 flags=ParseGeometry(argv[i+1],&geometry_info);
3124 if ((flags & SigmaValue) == 0)
3125 geometry_info.sigma=1.0;
3126 mogrify_image=WaveImage(*image,geometry_info.rho,
3127 geometry_info.sigma,exception);
3128 break;
3129 }
3130 if (LocaleCompare("weight",option+1) == 0)
3131 {
3132 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3133 if (LocaleCompare(argv[i+1],"all") == 0)
3134 draw_info->weight=0;
3135 if (LocaleCompare(argv[i+1],"bold") == 0)
3136 draw_info->weight=700;
3137 if (LocaleCompare(argv[i+1],"bolder") == 0)
3138 if (draw_info->weight <= 800)
3139 draw_info->weight+=100;
3140 if (LocaleCompare(argv[i+1],"lighter") == 0)
3141 if (draw_info->weight >= 100)
3142 draw_info->weight-=100;
3143 if (LocaleCompare(argv[i+1],"normal") == 0)
3144 draw_info->weight=400;
3145 break;
3146 }
3147 if (LocaleCompare("white-threshold",option+1) == 0)
3148 {
3149 /*
3150 White threshold image.
3151 */
3152 (void) SyncImageSettings(mogrify_info,*image);
3153 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3154 exception);
3155 InheritException(exception,&(*image)->exception);
3156 break;
3157 }
3158 break;
3159 }
3160 default:
3161 break;
3162 }
3163 /*
3164 Replace current image with any image that was generated
3165 */
3166 if (mogrify_image != (Image *) NULL)
3167 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003168 i+=count;
3169 }
3170 if (region_image != (Image *) NULL)
3171 {
anthonydf8ebac2011-04-27 09:03:19 +00003172 /*
3173 Composite transformed region onto image.
3174 */
cristy6b3da3a2010-06-20 02:21:46 +00003175 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003176 (void) CompositeImage(region_image,region_image->matte !=
cristyab015852011-07-06 01:03:32 +00003177 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3178 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003179 InheritException(exception,&region_image->exception);
3180 *image=DestroyImage(*image);
3181 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003182 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003183 }
3184 /*
3185 Free resources.
3186 */
anthonydf8ebac2011-04-27 09:03:19 +00003187 quantize_info=DestroyQuantizeInfo(quantize_info);
3188 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003189 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003190 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003191 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003192 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003193}
3194
3195/*
3196%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3197% %
3198% %
3199% %
cristy5063d812010-10-19 16:28:10 +00003200+ 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 +00003201% %
3202% %
3203% %
3204%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3205%
3206% MogrifyImageCommand() transforms an image or a sequence of images. These
3207% transforms include image scaling, image rotation, color reduction, and
3208% others. The transmogrified image overwrites the original image.
3209%
3210% The format of the MogrifyImageCommand method is:
3211%
3212% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3213% const char **argv,char **metadata,ExceptionInfo *exception)
3214%
3215% A description of each parameter follows:
3216%
3217% o image_info: the image info.
3218%
3219% o argc: the number of elements in the argument vector.
3220%
3221% o argv: A text array containing the command line arguments.
3222%
3223% o metadata: any metadata is returned here.
3224%
3225% o exception: return any errors or warnings in this structure.
3226%
3227*/
3228
3229static MagickBooleanType MogrifyUsage(void)
3230{
3231 static const char
3232 *miscellaneous[]=
3233 {
3234 "-debug events display copious debugging information",
3235 "-help print program options",
3236 "-list type print a list of supported option arguments",
3237 "-log format format of debugging information",
3238 "-version print version information",
3239 (char *) NULL
3240 },
3241 *operators[]=
3242 {
3243 "-adaptive-blur geometry",
3244 " adaptively blur pixels; decrease effect near edges",
3245 "-adaptive-resize geometry",
3246 " adaptively resize image using 'mesh' interpolation",
3247 "-adaptive-sharpen geometry",
3248 " adaptively sharpen pixels; increase effect near edges",
3249 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3250 " transparent, extract, background, or shape",
3251 "-annotate geometry text",
3252 " annotate the image with text",
3253 "-auto-gamma automagically adjust gamma level of image",
3254 "-auto-level automagically adjust color levels of image",
3255 "-auto-orient automagically orient (rotate) image",
3256 "-bench iterations measure performance",
3257 "-black-threshold value",
3258 " force all pixels below the threshold into black",
3259 "-blue-shift simulate a scene at nighttime in the moonlight",
3260 "-blur geometry reduce image noise and reduce detail levels",
3261 "-border geometry surround image with a border of color",
3262 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003263 "-brightness-contrast geometry",
3264 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003265 "-cdl filename color correct with a color decision list",
3266 "-charcoal radius simulate a charcoal drawing",
3267 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003268 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003269 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003270 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003271 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003272 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003273 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003274 "-contrast enhance or reduce the image contrast",
3275 "-contrast-stretch geometry",
3276 " improve contrast by `stretching' the intensity range",
3277 "-convolve coefficients",
3278 " apply a convolution kernel to the image",
3279 "-cycle amount cycle the image colormap",
3280 "-decipher filename convert cipher pixels to plain pixels",
3281 "-deskew threshold straighten an image",
3282 "-despeckle reduce the speckles within an image",
3283 "-distort method args",
3284 " distort images according to given method ad args",
3285 "-draw string annotate the image with a graphic primitive",
3286 "-edge radius apply a filter to detect edges in the image",
3287 "-encipher filename convert plain pixels to cipher pixels",
3288 "-emboss radius emboss an image",
3289 "-enhance apply a digital filter to enhance a noisy image",
3290 "-equalize perform histogram equalization to an image",
3291 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003292 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003293 "-extent geometry set the image size",
3294 "-extract geometry extract area from image",
3295 "-fft implements the discrete Fourier transform (DFT)",
3296 "-flip flip image vertically",
3297 "-floodfill geometry color",
3298 " floodfill the image with color",
3299 "-flop flop image horizontally",
3300 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003301 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003302 " apply function over image values",
3303 "-gamma value level of gamma correction",
3304 "-gaussian-blur geometry",
3305 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003306 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003307 "-identify identify the format and characteristics of the image",
3308 "-ift implements the inverse discrete Fourier transform (DFT)",
3309 "-implode amount implode image pixels about the center",
3310 "-lat geometry local adaptive thresholding",
3311 "-layers method optimize, merge, or compare image layers",
3312 "-level value adjust the level of image contrast",
3313 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003314 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003315 "-linear-stretch geometry",
3316 " improve contrast by `stretching with saturation'",
3317 "-liquid-rescale geometry",
3318 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003319 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003320 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003321 "-modulate value vary the brightness, saturation, and hue",
3322 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003323 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003324 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003325 "-motion-blur geometry",
3326 " simulate motion blur",
3327 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003328 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003329 "-normalize transform image to span the full range of colors",
3330 "-opaque color change this color to the fill color",
3331 "-ordered-dither NxN",
3332 " add a noise pattern to the image with specific",
3333 " amplitudes",
3334 "-paint radius simulate an oil painting",
3335 "-polaroid angle simulate a Polaroid picture",
3336 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003337 "-profile filename add, delete, or apply an image profile",
3338 "-quantize colorspace reduce colors in this colorspace",
3339 "-radial-blur angle radial blur the image",
3340 "-raise value lighten/darken image edges to create a 3-D effect",
3341 "-random-threshold low,high",
3342 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-region geometry apply options to a portion of the image",
3344 "-render render vector graphics",
3345 "-repage geometry size and location of an image canvas",
3346 "-resample geometry change the resolution of an image",
3347 "-resize geometry resize the image",
3348 "-roll geometry roll an image vertically or horizontally",
3349 "-rotate degrees apply Paeth rotation to the image",
3350 "-sample geometry scale image with pixel sampling",
3351 "-scale geometry scale the image",
3352 "-segment values segment an image",
3353 "-selective-blur geometry",
3354 " selectively blur pixels within a contrast threshold",
3355 "-sepia-tone threshold",
3356 " simulate a sepia-toned photo",
3357 "-set property value set an image property",
3358 "-shade degrees shade the image using a distant light source",
3359 "-shadow geometry simulate an image shadow",
3360 "-sharpen geometry sharpen the image",
3361 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003362 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003363 "-sigmoidal-contrast geometry",
3364 " increase the contrast without saturating highlights or shadows",
3365 "-sketch geometry simulate a pencil sketch",
3366 "-solarize threshold negate all pixels above the threshold level",
3367 "-sparse-color method args",
3368 " fill in a image based on a few color points",
3369 "-splice geometry splice the background color into the image",
3370 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003371 "-statistic type radius",
3372 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003373 "-strip strip image of all profiles and comments",
3374 "-swirl degrees swirl image pixels about the center",
3375 "-threshold value threshold the image",
3376 "-thumbnail geometry create a thumbnail of the image",
3377 "-tile filename tile image when filling a graphic primitive",
3378 "-tint value tint the image with the fill color",
3379 "-transform affine transform image",
3380 "-transparent color make this color transparent within the image",
3381 "-transpose flip image vertically and rotate 90 degrees",
3382 "-transverse flop image horizontally and rotate 270 degrees",
3383 "-trim trim image edges",
3384 "-type type image type",
3385 "-unique-colors discard all but one of any pixel color",
3386 "-unsharp geometry sharpen the image",
3387 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003388 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003389 "-white-threshold value",
3390 " force all pixels above the threshold into white",
3391 (char *) NULL
3392 },
3393 *sequence_operators[]=
3394 {
cristy4285d782011-02-09 20:12:28 +00003395 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003396 "-clut apply a color lookup table to the image",
3397 "-coalesce merge a sequence of images",
3398 "-combine combine a sequence of images",
3399 "-composite composite image",
3400 "-crop geometry cut out a rectangular region of the image",
3401 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003402 "-evaluate-sequence operator",
3403 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003404 "-flatten flatten a sequence of images",
3405 "-fx expression apply mathematical expression to an image channel(s)",
3406 "-hald-clut apply a Hald color lookup table to the image",
3407 "-morph value morph an image sequence",
3408 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003409 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003410 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003411 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003412 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003413 "-write filename write images to this file",
3414 (char *) NULL
3415 },
3416 *settings[]=
3417 {
3418 "-adjoin join images into a single multi-image file",
3419 "-affine matrix affine transform matrix",
3420 "-alpha option activate, deactivate, reset, or set the alpha channel",
3421 "-antialias remove pixel-aliasing",
3422 "-authenticate password",
3423 " decipher image with this password",
3424 "-attenuate value lessen (or intensify) when adding noise to an image",
3425 "-background color background color",
3426 "-bias value add bias when convolving an image",
3427 "-black-point-compensation",
3428 " use black point compensation",
3429 "-blue-primary point chromaticity blue primary point",
3430 "-bordercolor color border color",
3431 "-caption string assign a caption to an image",
3432 "-channel type apply option to select image channels",
3433 "-colors value preferred number of colors in the image",
3434 "-colorspace type alternate image colorspace",
3435 "-comment string annotate image with comment",
3436 "-compose operator set image composite operator",
3437 "-compress type type of pixel compression when writing the image",
3438 "-define format:option",
3439 " define one or more image format options",
3440 "-delay value display the next image after pausing",
3441 "-density geometry horizontal and vertical density of the image",
3442 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003443 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003444 "-display server get image or font from this X server",
3445 "-dispose method layer disposal method",
3446 "-dither method apply error diffusion to image",
3447 "-encoding type text encoding type",
3448 "-endian type endianness (MSB or LSB) of the image",
3449 "-family name render text with this font family",
3450 "-fill color color to use when filling a graphic primitive",
3451 "-filter type use this filter when resizing an image",
3452 "-font name render text with this font",
3453 "-format \"string\" output formatted image characteristics",
3454 "-fuzz distance colors within this distance are considered equal",
3455 "-gravity type horizontal and vertical text placement",
3456 "-green-primary point chromaticity green primary point",
3457 "-intent type type of rendering intent when managing the image color",
3458 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003459 "-interline-spacing value",
3460 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003461 "-interpolate method pixel color interpolation method",
3462 "-interword-spacing value",
3463 " set the space between two words",
3464 "-kerning value set the space between two letters",
3465 "-label string assign a label to an image",
3466 "-limit type value pixel cache resource limit",
3467 "-loop iterations add Netscape loop extension to your GIF animation",
3468 "-mask filename associate a mask with the image",
3469 "-mattecolor color frame color",
3470 "-monitor monitor progress",
3471 "-orient type image orientation",
3472 "-page geometry size and location of an image canvas (setting)",
3473 "-ping efficiently determine image attributes",
3474 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003475 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003476 "-preview type image preview type",
3477 "-quality value JPEG/MIFF/PNG compression level",
3478 "-quiet suppress all warning messages",
3479 "-red-primary point chromaticity red primary point",
3480 "-regard-warnings pay attention to warning messages",
3481 "-remap filename transform image colors to match this set of colors",
3482 "-respect-parentheses settings remain in effect until parenthesis boundary",
3483 "-sampling-factor geometry",
3484 " horizontal and vertical sampling factor",
3485 "-scene value image scene number",
3486 "-seed value seed a new sequence of pseudo-random numbers",
3487 "-size geometry width and height of image",
3488 "-stretch type render text with this font stretch",
3489 "-stroke color graphic primitive stroke color",
3490 "-strokewidth value graphic primitive stroke width",
3491 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003492 "-synchronize synchronize image to storage device",
3493 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003494 "-texture filename name of texture to tile onto the image background",
3495 "-tile-offset geometry",
3496 " tile offset",
3497 "-treedepth value color tree depth",
3498 "-transparent-color color",
3499 " transparent color",
3500 "-undercolor color annotation bounding box color",
3501 "-units type the units of image resolution",
3502 "-verbose print detailed information about the image",
3503 "-view FlashPix viewing transforms",
3504 "-virtual-pixel method",
3505 " virtual pixel access method",
3506 "-weight type render text with this font weight",
3507 "-white-point point chromaticity white point",
3508 (char *) NULL
3509 },
3510 *stack_operators[]=
3511 {
anthonyb69c4b32011-03-23 04:37:44 +00003512 "-delete indexes delete the image from the image sequence",
3513 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003514 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003515 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003516 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003517 "-swap indexes swap two images in the image sequence",
3518 (char *) NULL
3519 };
3520
3521 const char
3522 **p;
3523
cristybb503372010-05-27 20:51:26 +00003524 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003525 (void) printf("Copyright: %s\n",GetMagickCopyright());
3526 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003527 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3528 GetClientName());
3529 (void) printf("\nImage Settings:\n");
3530 for (p=settings; *p != (char *) NULL; p++)
3531 (void) printf(" %s\n",*p);
3532 (void) printf("\nImage Operators:\n");
3533 for (p=operators; *p != (char *) NULL; p++)
3534 (void) printf(" %s\n",*p);
3535 (void) printf("\nImage Sequence Operators:\n");
3536 for (p=sequence_operators; *p != (char *) NULL; p++)
3537 (void) printf(" %s\n",*p);
3538 (void) printf("\nImage Stack Operators:\n");
3539 for (p=stack_operators; *p != (char *) NULL; p++)
3540 (void) printf(" %s\n",*p);
3541 (void) printf("\nMiscellaneous Options:\n");
3542 for (p=miscellaneous; *p != (char *) NULL; p++)
3543 (void) printf(" %s\n",*p);
3544 (void) printf(
3545 "\nBy default, the image format of `file' is determined by its magic\n");
3546 (void) printf(
3547 "number. To specify a particular image format, precede the filename\n");
3548 (void) printf(
3549 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3550 (void) printf(
3551 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3552 (void) printf("'-' for standard input or output.\n");
3553 return(MagickFalse);
3554}
3555
3556WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3557 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3558{
3559#define DestroyMogrify() \
3560{ \
3561 if (format != (char *) NULL) \
3562 format=DestroyString(format); \
3563 if (path != (char *) NULL) \
3564 path=DestroyString(path); \
3565 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003566 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003567 argv[i]=DestroyString(argv[i]); \
3568 argv=(char **) RelinquishMagickMemory(argv); \
3569}
3570#define ThrowMogrifyException(asperity,tag,option) \
3571{ \
3572 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3573 option); \
3574 DestroyMogrify(); \
3575 return(MagickFalse); \
3576}
3577#define ThrowMogrifyInvalidArgumentException(option,argument) \
3578{ \
3579 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3580 "InvalidArgument","`%s': %s",argument,option); \
3581 DestroyMogrify(); \
3582 return(MagickFalse); \
3583}
3584
3585 char
3586 *format,
3587 *option,
3588 *path;
3589
3590 Image
3591 *image;
3592
3593 ImageStack
3594 image_stack[MaxImageStackDepth+1];
3595
cristy3ed852e2009-09-05 21:47:34 +00003596 MagickBooleanType
3597 global_colormap;
3598
3599 MagickBooleanType
3600 fire,
cristyebbcfea2011-02-25 02:43:54 +00003601 pend,
3602 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003603
3604 MagickStatusType
3605 status;
3606
cristyebbcfea2011-02-25 02:43:54 +00003607 register ssize_t
3608 i;
3609
3610 ssize_t
3611 j,
3612 k;
3613
cristy3ed852e2009-09-05 21:47:34 +00003614 /*
3615 Set defaults.
3616 */
3617 assert(image_info != (ImageInfo *) NULL);
3618 assert(image_info->signature == MagickSignature);
3619 if (image_info->debug != MagickFalse)
3620 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3621 assert(exception != (ExceptionInfo *) NULL);
3622 if (argc == 2)
3623 {
3624 option=argv[1];
3625 if ((LocaleCompare("version",option+1) == 0) ||
3626 (LocaleCompare("-version",option+1) == 0))
3627 {
cristyb51dff52011-05-19 16:55:47 +00003628 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003629 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003630 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3631 GetMagickCopyright());
3632 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3633 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003634 return(MagickFalse);
3635 }
3636 }
3637 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003638 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003639 format=(char *) NULL;
3640 path=(char *) NULL;
3641 global_colormap=MagickFalse;
3642 k=0;
3643 j=1;
3644 NewImageStack();
3645 option=(char *) NULL;
3646 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003647 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003648 status=MagickTrue;
3649 /*
3650 Parse command line.
3651 */
3652 ReadCommandlLine(argc,&argv);
3653 status=ExpandFilenames(&argc,&argv);
3654 if (status == MagickFalse)
3655 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3656 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003657 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003658 {
3659 option=argv[i];
3660 if (LocaleCompare(option,"(") == 0)
3661 {
3662 FireImageStack(MagickFalse,MagickTrue,pend);
3663 if (k == MaxImageStackDepth)
3664 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3665 option);
3666 PushImageStack();
3667 continue;
3668 }
3669 if (LocaleCompare(option,")") == 0)
3670 {
3671 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3672 if (k == 0)
3673 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3674 PopImageStack();
3675 continue;
3676 }
cristy042ee782011-04-22 18:48:30 +00003677 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003678 {
3679 char
3680 backup_filename[MaxTextExtent],
3681 *filename;
3682
3683 Image
3684 *images;
3685
3686 /*
3687 Option is a file name: begin by reading image from specified file.
3688 */
3689 FireImageStack(MagickFalse,MagickFalse,pend);
3690 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003691 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003692 filename=argv[++i];
3693 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3694 images=ReadImages(image_info,exception);
3695 status&=(images != (Image *) NULL) &&
3696 (exception->severity < ErrorException);
3697 if (images == (Image *) NULL)
3698 continue;
cristydaa76602010-06-30 13:05:11 +00003699 if (format != (char *) NULL)
3700 (void) CopyMagickString(images->filename,images->magick_filename,
3701 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003702 if (path != (char *) NULL)
3703 {
3704 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003705 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003706 path,*DirectorySeparator,filename);
3707 }
3708 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003709 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003710 AppendImageStack(images);
3711 FinalizeImageSettings(image_info,image,MagickFalse);
3712 if (global_colormap != MagickFalse)
3713 {
3714 QuantizeInfo
3715 *quantize_info;
3716
3717 quantize_info=AcquireQuantizeInfo(image_info);
3718 (void) RemapImages(quantize_info,images,(Image *) NULL);
3719 quantize_info=DestroyQuantizeInfo(quantize_info);
3720 }
3721 *backup_filename='\0';
3722 if ((LocaleCompare(image->filename,"-") != 0) &&
3723 (IsPathWritable(image->filename) != MagickFalse))
3724 {
cristybb503372010-05-27 20:51:26 +00003725 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003726 i;
3727
3728 /*
3729 Rename image file as backup.
3730 */
3731 (void) CopyMagickString(backup_filename,image->filename,
3732 MaxTextExtent);
3733 for (i=0; i < 6; i++)
3734 {
3735 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3736 if (IsPathAccessible(backup_filename) == MagickFalse)
3737 break;
3738 }
3739 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3740 (rename(image->filename,backup_filename) != 0))
3741 *backup_filename='\0';
3742 }
3743 /*
3744 Write transmogrified image to disk.
3745 */
3746 image_info->synchronize=MagickTrue;
3747 status&=WriteImages(image_info,image,image->filename,exception);
3748 if ((status == MagickFalse) && (*backup_filename != '\0'))
3749 (void) remove(backup_filename);
3750 RemoveAllImageStack();
3751 continue;
3752 }
3753 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3754 switch (*(option+1))
3755 {
3756 case 'a':
3757 {
3758 if (LocaleCompare("adaptive-blur",option+1) == 0)
3759 {
3760 i++;
cristybb503372010-05-27 20:51:26 +00003761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003762 ThrowMogrifyException(OptionError,"MissingArgument",option);
3763 if (IsGeometry(argv[i]) == MagickFalse)
3764 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3765 break;
3766 }
3767 if (LocaleCompare("adaptive-resize",option+1) == 0)
3768 {
3769 i++;
cristybb503372010-05-27 20:51:26 +00003770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003771 ThrowMogrifyException(OptionError,"MissingArgument",option);
3772 if (IsGeometry(argv[i]) == MagickFalse)
3773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3774 break;
3775 }
3776 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3777 {
3778 i++;
cristybb503372010-05-27 20:51:26 +00003779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003780 ThrowMogrifyException(OptionError,"MissingArgument",option);
3781 if (IsGeometry(argv[i]) == MagickFalse)
3782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3783 break;
3784 }
3785 if (LocaleCompare("affine",option+1) == 0)
3786 {
3787 if (*option == '+')
3788 break;
3789 i++;
cristybb503372010-05-27 20:51:26 +00003790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003791 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003792 break;
3793 }
3794 if (LocaleCompare("alpha",option+1) == 0)
3795 {
cristybb503372010-05-27 20:51:26 +00003796 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003797 type;
3798
3799 if (*option == '+')
3800 break;
3801 i++;
cristybb503372010-05-27 20:51:26 +00003802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003803 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003804 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003805 if (type < 0)
3806 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3807 argv[i]);
3808 break;
3809 }
3810 if (LocaleCompare("annotate",option+1) == 0)
3811 {
3812 if (*option == '+')
3813 break;
3814 i++;
cristybb503372010-05-27 20:51:26 +00003815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003816 ThrowMogrifyException(OptionError,"MissingArgument",option);
3817 if (IsGeometry(argv[i]) == MagickFalse)
3818 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003820 ThrowMogrifyException(OptionError,"MissingArgument",option);
3821 i++;
3822 break;
3823 }
3824 if (LocaleCompare("antialias",option+1) == 0)
3825 break;
3826 if (LocaleCompare("append",option+1) == 0)
3827 break;
3828 if (LocaleCompare("attenuate",option+1) == 0)
3829 {
3830 if (*option == '+')
3831 break;
3832 i++;
cristybb503372010-05-27 20:51:26 +00003833 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003834 ThrowMogrifyException(OptionError,"MissingArgument",option);
3835 if (IsGeometry(argv[i]) == MagickFalse)
3836 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3837 break;
3838 }
3839 if (LocaleCompare("authenticate",option+1) == 0)
3840 {
3841 if (*option == '+')
3842 break;
3843 i++;
cristybb503372010-05-27 20:51:26 +00003844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003845 ThrowMogrifyException(OptionError,"MissingArgument",option);
3846 break;
3847 }
3848 if (LocaleCompare("auto-gamma",option+1) == 0)
3849 break;
3850 if (LocaleCompare("auto-level",option+1) == 0)
3851 break;
3852 if (LocaleCompare("auto-orient",option+1) == 0)
3853 break;
3854 if (LocaleCompare("average",option+1) == 0)
3855 break;
3856 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3857 }
3858 case 'b':
3859 {
3860 if (LocaleCompare("background",option+1) == 0)
3861 {
3862 if (*option == '+')
3863 break;
3864 i++;
cristybb503372010-05-27 20:51:26 +00003865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003866 ThrowMogrifyException(OptionError,"MissingArgument",option);
3867 break;
3868 }
3869 if (LocaleCompare("bias",option+1) == 0)
3870 {
3871 if (*option == '+')
3872 break;
3873 i++;
cristybb503372010-05-27 20:51:26 +00003874 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003875 ThrowMogrifyException(OptionError,"MissingArgument",option);
3876 if (IsGeometry(argv[i]) == MagickFalse)
3877 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3878 break;
3879 }
3880 if (LocaleCompare("black-point-compensation",option+1) == 0)
3881 break;
3882 if (LocaleCompare("black-threshold",option+1) == 0)
3883 {
3884 if (*option == '+')
3885 break;
3886 i++;
cristybb503372010-05-27 20:51:26 +00003887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003888 ThrowMogrifyException(OptionError,"MissingArgument",option);
3889 if (IsGeometry(argv[i]) == MagickFalse)
3890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3891 break;
3892 }
3893 if (LocaleCompare("blue-primary",option+1) == 0)
3894 {
3895 if (*option == '+')
3896 break;
3897 i++;
cristybb503372010-05-27 20:51:26 +00003898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003899 ThrowMogrifyException(OptionError,"MissingArgument",option);
3900 if (IsGeometry(argv[i]) == MagickFalse)
3901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3902 break;
3903 }
3904 if (LocaleCompare("blue-shift",option+1) == 0)
3905 {
3906 i++;
cristybb503372010-05-27 20:51:26 +00003907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003908 ThrowMogrifyException(OptionError,"MissingArgument",option);
3909 if (IsGeometry(argv[i]) == MagickFalse)
3910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3911 break;
3912 }
3913 if (LocaleCompare("blur",option+1) == 0)
3914 {
3915 i++;
cristybb503372010-05-27 20:51:26 +00003916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003917 ThrowMogrifyException(OptionError,"MissingArgument",option);
3918 if (IsGeometry(argv[i]) == MagickFalse)
3919 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3920 break;
3921 }
3922 if (LocaleCompare("border",option+1) == 0)
3923 {
3924 if (*option == '+')
3925 break;
3926 i++;
cristybb503372010-05-27 20:51:26 +00003927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003928 ThrowMogrifyException(OptionError,"MissingArgument",option);
3929 if (IsGeometry(argv[i]) == MagickFalse)
3930 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3931 break;
3932 }
3933 if (LocaleCompare("bordercolor",option+1) == 0)
3934 {
3935 if (*option == '+')
3936 break;
3937 i++;
cristybb503372010-05-27 20:51:26 +00003938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003939 ThrowMogrifyException(OptionError,"MissingArgument",option);
3940 break;
3941 }
3942 if (LocaleCompare("box",option+1) == 0)
3943 {
3944 if (*option == '+')
3945 break;
3946 i++;
cristybb503372010-05-27 20:51:26 +00003947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003948 ThrowMogrifyException(OptionError,"MissingArgument",option);
3949 break;
3950 }
cristya28d6b82010-01-11 20:03:47 +00003951 if (LocaleCompare("brightness-contrast",option+1) == 0)
3952 {
3953 i++;
cristybb503372010-05-27 20:51:26 +00003954 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003955 ThrowMogrifyException(OptionError,"MissingArgument",option);
3956 if (IsGeometry(argv[i]) == MagickFalse)
3957 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3958 break;
3959 }
cristy3ed852e2009-09-05 21:47:34 +00003960 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3961 }
3962 case 'c':
3963 {
3964 if (LocaleCompare("cache",option+1) == 0)
3965 {
3966 if (*option == '+')
3967 break;
3968 i++;
cristybb503372010-05-27 20:51:26 +00003969 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003970 ThrowMogrifyException(OptionError,"MissingArgument",option);
3971 if (IsGeometry(argv[i]) == MagickFalse)
3972 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3973 break;
3974 }
3975 if (LocaleCompare("caption",option+1) == 0)
3976 {
3977 if (*option == '+')
3978 break;
3979 i++;
cristybb503372010-05-27 20:51:26 +00003980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003981 ThrowMogrifyException(OptionError,"MissingArgument",option);
3982 break;
3983 }
3984 if (LocaleCompare("channel",option+1) == 0)
3985 {
cristybb503372010-05-27 20:51:26 +00003986 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003987 channel;
3988
3989 if (*option == '+')
3990 break;
3991 i++;
cristybb503372010-05-27 20:51:26 +00003992 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003993 ThrowMogrifyException(OptionError,"MissingArgument",option);
3994 channel=ParseChannelOption(argv[i]);
3995 if (channel < 0)
3996 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3997 argv[i]);
3998 break;
3999 }
4000 if (LocaleCompare("cdl",option+1) == 0)
4001 {
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 break;
4008 }
4009 if (LocaleCompare("charcoal",option+1) == 0)
4010 {
4011 if (*option == '+')
4012 break;
4013 i++;
cristybb503372010-05-27 20:51:26 +00004014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004015 ThrowMogrifyException(OptionError,"MissingArgument",option);
4016 if (IsGeometry(argv[i]) == MagickFalse)
4017 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4018 break;
4019 }
4020 if (LocaleCompare("chop",option+1) == 0)
4021 {
4022 if (*option == '+')
4023 break;
4024 i++;
cristybb503372010-05-27 20:51:26 +00004025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004026 ThrowMogrifyException(OptionError,"MissingArgument",option);
4027 if (IsGeometry(argv[i]) == MagickFalse)
4028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4029 break;
4030 }
cristy1eb45dd2009-09-25 16:38:06 +00004031 if (LocaleCompare("clamp",option+1) == 0)
4032 break;
4033 if (LocaleCompare("clip",option+1) == 0)
4034 break;
cristy3ed852e2009-09-05 21:47:34 +00004035 if (LocaleCompare("clip-mask",option+1) == 0)
4036 {
4037 if (*option == '+')
4038 break;
4039 i++;
cristybb503372010-05-27 20:51:26 +00004040 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004041 ThrowMogrifyException(OptionError,"MissingArgument",option);
4042 break;
4043 }
4044 if (LocaleCompare("clut",option+1) == 0)
4045 break;
4046 if (LocaleCompare("coalesce",option+1) == 0)
4047 break;
4048 if (LocaleCompare("colorize",option+1) == 0)
4049 {
4050 if (*option == '+')
4051 break;
4052 i++;
cristybb503372010-05-27 20:51:26 +00004053 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004054 ThrowMogrifyException(OptionError,"MissingArgument",option);
4055 if (IsGeometry(argv[i]) == MagickFalse)
4056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4057 break;
4058 }
cristye6365592010-04-02 17:31:23 +00004059 if (LocaleCompare("color-matrix",option+1) == 0)
4060 {
cristyb6bd4ad2010-08-08 01:12:27 +00004061 KernelInfo
4062 *kernel_info;
4063
cristye6365592010-04-02 17:31:23 +00004064 if (*option == '+')
4065 break;
4066 i++;
cristybb503372010-05-27 20:51:26 +00004067 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004068 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004069 kernel_info=AcquireKernelInfo(argv[i]);
4070 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004071 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004072 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004073 break;
4074 }
cristy3ed852e2009-09-05 21:47:34 +00004075 if (LocaleCompare("colors",option+1) == 0)
4076 {
4077 if (*option == '+')
4078 break;
4079 i++;
cristybb503372010-05-27 20:51:26 +00004080 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004081 ThrowMogrifyException(OptionError,"MissingArgument",option);
4082 if (IsGeometry(argv[i]) == MagickFalse)
4083 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4084 break;
4085 }
4086 if (LocaleCompare("colorspace",option+1) == 0)
4087 {
cristybb503372010-05-27 20:51:26 +00004088 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004089 colorspace;
4090
4091 if (*option == '+')
4092 break;
4093 i++;
cristybb503372010-05-27 20:51:26 +00004094 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004095 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004096 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004097 argv[i]);
4098 if (colorspace < 0)
4099 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4100 argv[i]);
4101 break;
4102 }
4103 if (LocaleCompare("combine",option+1) == 0)
4104 break;
4105 if (LocaleCompare("comment",option+1) == 0)
4106 {
4107 if (*option == '+')
4108 break;
4109 i++;
cristybb503372010-05-27 20:51:26 +00004110 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004111 ThrowMogrifyException(OptionError,"MissingArgument",option);
4112 break;
4113 }
4114 if (LocaleCompare("composite",option+1) == 0)
4115 break;
4116 if (LocaleCompare("compress",option+1) == 0)
4117 {
cristybb503372010-05-27 20:51:26 +00004118 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004119 compress;
4120
4121 if (*option == '+')
4122 break;
4123 i++;
cristybb503372010-05-27 20:51:26 +00004124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004125 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004126 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004127 argv[i]);
4128 if (compress < 0)
4129 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4130 argv[i]);
4131 break;
4132 }
cristy22879752009-10-25 23:55:40 +00004133 if (LocaleCompare("concurrent",option+1) == 0)
4134 break;
cristy3ed852e2009-09-05 21:47:34 +00004135 if (LocaleCompare("contrast",option+1) == 0)
4136 break;
4137 if (LocaleCompare("contrast-stretch",option+1) == 0)
4138 {
4139 i++;
cristybb503372010-05-27 20:51:26 +00004140 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004141 ThrowMogrifyException(OptionError,"MissingArgument",option);
4142 if (IsGeometry(argv[i]) == MagickFalse)
4143 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4144 break;
4145 }
4146 if (LocaleCompare("convolve",option+1) == 0)
4147 {
cristyb6bd4ad2010-08-08 01:12:27 +00004148 KernelInfo
4149 *kernel_info;
4150
cristy3ed852e2009-09-05 21:47:34 +00004151 if (*option == '+')
4152 break;
4153 i++;
cristybb503372010-05-27 20:51:26 +00004154 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004155 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004156 kernel_info=AcquireKernelInfo(argv[i]);
4157 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004158 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004159 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004160 break;
4161 }
4162 if (LocaleCompare("crop",option+1) == 0)
4163 {
4164 if (*option == '+')
4165 break;
4166 i++;
cristybb503372010-05-27 20:51:26 +00004167 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004168 ThrowMogrifyException(OptionError,"MissingArgument",option);
4169 if (IsGeometry(argv[i]) == MagickFalse)
4170 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4171 break;
4172 }
4173 if (LocaleCompare("cycle",option+1) == 0)
4174 {
4175 if (*option == '+')
4176 break;
4177 i++;
cristybb503372010-05-27 20:51:26 +00004178 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004179 ThrowMogrifyException(OptionError,"MissingArgument",option);
4180 if (IsGeometry(argv[i]) == MagickFalse)
4181 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4182 break;
4183 }
4184 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4185 }
4186 case 'd':
4187 {
4188 if (LocaleCompare("decipher",option+1) == 0)
4189 {
4190 if (*option == '+')
4191 break;
4192 i++;
cristybb503372010-05-27 20:51:26 +00004193 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004194 ThrowMogrifyException(OptionError,"MissingArgument",option);
4195 break;
4196 }
4197 if (LocaleCompare("deconstruct",option+1) == 0)
4198 break;
4199 if (LocaleCompare("debug",option+1) == 0)
4200 {
cristybb503372010-05-27 20:51:26 +00004201 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004202 event;
4203
4204 if (*option == '+')
4205 break;
4206 i++;
cristybb503372010-05-27 20:51:26 +00004207 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004208 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004209 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004210 if (event < 0)
4211 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4212 argv[i]);
4213 (void) SetLogEventMask(argv[i]);
4214 break;
4215 }
4216 if (LocaleCompare("define",option+1) == 0)
4217 {
4218 i++;
cristybb503372010-05-27 20:51:26 +00004219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004220 ThrowMogrifyException(OptionError,"MissingArgument",option);
4221 if (*option == '+')
4222 {
4223 const char
4224 *define;
4225
4226 define=GetImageOption(image_info,argv[i]);
4227 if (define == (const char *) NULL)
4228 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4229 break;
4230 }
4231 break;
4232 }
4233 if (LocaleCompare("delay",option+1) == 0)
4234 {
4235 if (*option == '+')
4236 break;
4237 i++;
cristybb503372010-05-27 20:51:26 +00004238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004239 ThrowMogrifyException(OptionError,"MissingArgument",option);
4240 if (IsGeometry(argv[i]) == MagickFalse)
4241 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4242 break;
4243 }
cristyecb10ff2011-03-22 13:14:03 +00004244 if (LocaleCompare("delete",option+1) == 0)
4245 {
4246 if (*option == '+')
4247 break;
4248 i++;
4249 if (i == (ssize_t) (argc-1))
4250 ThrowMogrifyException(OptionError,"MissingArgument",option);
4251 if (IsGeometry(argv[i]) == MagickFalse)
4252 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4253 break;
4254 }
cristy3ed852e2009-09-05 21:47:34 +00004255 if (LocaleCompare("density",option+1) == 0)
4256 {
4257 if (*option == '+')
4258 break;
4259 i++;
cristybb503372010-05-27 20:51:26 +00004260 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004261 ThrowMogrifyException(OptionError,"MissingArgument",option);
4262 if (IsGeometry(argv[i]) == MagickFalse)
4263 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4264 break;
4265 }
4266 if (LocaleCompare("depth",option+1) == 0)
4267 {
4268 if (*option == '+')
4269 break;
4270 i++;
cristybb503372010-05-27 20:51:26 +00004271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004272 ThrowMogrifyException(OptionError,"MissingArgument",option);
4273 if (IsGeometry(argv[i]) == MagickFalse)
4274 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4275 break;
4276 }
4277 if (LocaleCompare("deskew",option+1) == 0)
4278 {
4279 if (*option == '+')
4280 break;
4281 i++;
cristybb503372010-05-27 20:51:26 +00004282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004283 ThrowMogrifyException(OptionError,"MissingArgument",option);
4284 if (IsGeometry(argv[i]) == MagickFalse)
4285 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4286 break;
4287 }
4288 if (LocaleCompare("despeckle",option+1) == 0)
4289 break;
4290 if (LocaleCompare("dft",option+1) == 0)
4291 break;
cristyc9b12952010-03-28 01:12:28 +00004292 if (LocaleCompare("direction",option+1) == 0)
4293 {
cristybb503372010-05-27 20:51:26 +00004294 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004295 direction;
4296
4297 if (*option == '+')
4298 break;
4299 i++;
cristybb503372010-05-27 20:51:26 +00004300 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004301 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004302 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004303 argv[i]);
4304 if (direction < 0)
4305 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4306 argv[i]);
4307 break;
4308 }
cristy3ed852e2009-09-05 21:47:34 +00004309 if (LocaleCompare("display",option+1) == 0)
4310 {
4311 if (*option == '+')
4312 break;
4313 i++;
cristybb503372010-05-27 20:51:26 +00004314 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004315 ThrowMogrifyException(OptionError,"MissingArgument",option);
4316 break;
4317 }
4318 if (LocaleCompare("dispose",option+1) == 0)
4319 {
cristybb503372010-05-27 20:51:26 +00004320 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004321 dispose;
4322
4323 if (*option == '+')
4324 break;
4325 i++;
cristybb503372010-05-27 20:51:26 +00004326 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004327 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004328 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004329 if (dispose < 0)
4330 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4331 argv[i]);
4332 break;
4333 }
4334 if (LocaleCompare("distort",option+1) == 0)
4335 {
cristybb503372010-05-27 20:51:26 +00004336 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004337 op;
4338
4339 i++;
cristybb503372010-05-27 20:51:26 +00004340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004341 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004342 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004343 if (op < 0)
4344 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4345 argv[i]);
4346 i++;
cristybb503372010-05-27 20:51:26 +00004347 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004348 ThrowMogrifyException(OptionError,"MissingArgument",option);
4349 break;
4350 }
4351 if (LocaleCompare("dither",option+1) == 0)
4352 {
cristybb503372010-05-27 20:51:26 +00004353 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004354 method;
4355
4356 if (*option == '+')
4357 break;
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004361 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004362 if (method < 0)
4363 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4364 argv[i]);
4365 break;
4366 }
4367 if (LocaleCompare("draw",option+1) == 0)
4368 {
4369 if (*option == '+')
4370 break;
4371 i++;
cristybb503372010-05-27 20:51:26 +00004372 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004373 ThrowMogrifyException(OptionError,"MissingArgument",option);
4374 break;
4375 }
cristyecb10ff2011-03-22 13:14:03 +00004376 if (LocaleCompare("duplicate",option+1) == 0)
4377 {
4378 if (*option == '+')
4379 break;
4380 i++;
4381 if (i == (ssize_t) (argc-1))
4382 ThrowMogrifyException(OptionError,"MissingArgument",option);
4383 if (IsGeometry(argv[i]) == MagickFalse)
4384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4385 break;
4386 }
cristy22879752009-10-25 23:55:40 +00004387 if (LocaleCompare("duration",option+1) == 0)
4388 {
4389 if (*option == '+')
4390 break;
4391 i++;
cristybb503372010-05-27 20:51:26 +00004392 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004393 ThrowMogrifyException(OptionError,"MissingArgument",option);
4394 if (IsGeometry(argv[i]) == MagickFalse)
4395 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4396 break;
4397 }
cristy3ed852e2009-09-05 21:47:34 +00004398 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4399 }
4400 case 'e':
4401 {
4402 if (LocaleCompare("edge",option+1) == 0)
4403 {
4404 if (*option == '+')
4405 break;
4406 i++;
cristybb503372010-05-27 20:51:26 +00004407 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004408 ThrowMogrifyException(OptionError,"MissingArgument",option);
4409 if (IsGeometry(argv[i]) == MagickFalse)
4410 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4411 break;
4412 }
4413 if (LocaleCompare("emboss",option+1) == 0)
4414 {
4415 if (*option == '+')
4416 break;
4417 i++;
cristybb503372010-05-27 20:51:26 +00004418 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004419 ThrowMogrifyException(OptionError,"MissingArgument",option);
4420 if (IsGeometry(argv[i]) == MagickFalse)
4421 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4422 break;
4423 }
4424 if (LocaleCompare("encipher",option+1) == 0)
4425 {
4426 if (*option == '+')
4427 break;
4428 i++;
cristybb503372010-05-27 20:51:26 +00004429 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004430 ThrowMogrifyException(OptionError,"MissingArgument",option);
4431 break;
4432 }
4433 if (LocaleCompare("encoding",option+1) == 0)
4434 {
4435 if (*option == '+')
4436 break;
4437 i++;
cristybb503372010-05-27 20:51:26 +00004438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004439 ThrowMogrifyException(OptionError,"MissingArgument",option);
4440 break;
4441 }
4442 if (LocaleCompare("endian",option+1) == 0)
4443 {
cristybb503372010-05-27 20:51:26 +00004444 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004445 endian;
4446
4447 if (*option == '+')
4448 break;
4449 i++;
cristybb503372010-05-27 20:51:26 +00004450 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004451 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004452 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004453 if (endian < 0)
4454 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4455 argv[i]);
4456 break;
4457 }
4458 if (LocaleCompare("enhance",option+1) == 0)
4459 break;
4460 if (LocaleCompare("equalize",option+1) == 0)
4461 break;
4462 if (LocaleCompare("evaluate",option+1) == 0)
4463 {
cristybb503372010-05-27 20:51:26 +00004464 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004465 op;
4466
4467 if (*option == '+')
4468 break;
4469 i++;
cristybb503372010-05-27 20:51:26 +00004470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004471 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004472 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004473 if (op < 0)
4474 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4475 argv[i]);
4476 i++;
cristybb503372010-05-27 20:51:26 +00004477 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004478 ThrowMogrifyException(OptionError,"MissingArgument",option);
4479 if (IsGeometry(argv[i]) == MagickFalse)
4480 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4481 break;
4482 }
cristyd18ae7c2010-03-07 17:39:52 +00004483 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4484 {
cristybb503372010-05-27 20:51:26 +00004485 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004486 op;
4487
4488 if (*option == '+')
4489 break;
4490 i++;
cristybb503372010-05-27 20:51:26 +00004491 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004492 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004493 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004494 if (op < 0)
4495 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4496 argv[i]);
4497 break;
4498 }
cristy3ed852e2009-09-05 21:47:34 +00004499 if (LocaleCompare("extent",option+1) == 0)
4500 {
4501 if (*option == '+')
4502 break;
4503 i++;
cristybb503372010-05-27 20:51:26 +00004504 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004505 ThrowMogrifyException(OptionError,"MissingArgument",option);
4506 if (IsGeometry(argv[i]) == MagickFalse)
4507 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4508 break;
4509 }
4510 if (LocaleCompare("extract",option+1) == 0)
4511 {
4512 if (*option == '+')
4513 break;
4514 i++;
cristybb503372010-05-27 20:51:26 +00004515 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004516 ThrowMogrifyException(OptionError,"MissingArgument",option);
4517 if (IsGeometry(argv[i]) == MagickFalse)
4518 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4519 break;
4520 }
4521 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4522 }
4523 case 'f':
4524 {
4525 if (LocaleCompare("family",option+1) == 0)
4526 {
4527 if (*option == '+')
4528 break;
4529 i++;
cristybb503372010-05-27 20:51:26 +00004530 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004531 ThrowMogrifyException(OptionError,"MissingArgument",option);
4532 break;
4533 }
4534 if (LocaleCompare("fill",option+1) == 0)
4535 {
4536 if (*option == '+')
4537 break;
4538 i++;
cristybb503372010-05-27 20:51:26 +00004539 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004540 ThrowMogrifyException(OptionError,"MissingArgument",option);
4541 break;
4542 }
4543 if (LocaleCompare("filter",option+1) == 0)
4544 {
cristybb503372010-05-27 20:51:26 +00004545 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004546 filter;
4547
4548 if (*option == '+')
4549 break;
4550 i++;
cristybb503372010-05-27 20:51:26 +00004551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004552 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004553 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004554 if (filter < 0)
4555 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4556 argv[i]);
4557 break;
4558 }
4559 if (LocaleCompare("flatten",option+1) == 0)
4560 break;
4561 if (LocaleCompare("flip",option+1) == 0)
4562 break;
4563 if (LocaleCompare("flop",option+1) == 0)
4564 break;
4565 if (LocaleCompare("floodfill",option+1) == 0)
4566 {
4567 if (*option == '+')
4568 break;
4569 i++;
cristybb503372010-05-27 20:51:26 +00004570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004571 ThrowMogrifyException(OptionError,"MissingArgument",option);
4572 if (IsGeometry(argv[i]) == MagickFalse)
4573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4574 i++;
cristybb503372010-05-27 20:51:26 +00004575 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004576 ThrowMogrifyException(OptionError,"MissingArgument",option);
4577 break;
4578 }
4579 if (LocaleCompare("font",option+1) == 0)
4580 {
4581 if (*option == '+')
4582 break;
4583 i++;
cristybb503372010-05-27 20:51:26 +00004584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004585 ThrowMogrifyException(OptionError,"MissingArgument",option);
4586 break;
4587 }
4588 if (LocaleCompare("format",option+1) == 0)
4589 {
4590 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4591 (void) CloneString(&format,(char *) NULL);
4592 if (*option == '+')
4593 break;
4594 i++;
cristybb503372010-05-27 20:51:26 +00004595 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004596 ThrowMogrifyException(OptionError,"MissingArgument",option);
4597 (void) CloneString(&format,argv[i]);
4598 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4599 (void) ConcatenateMagickString(image_info->filename,":",
4600 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004601 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004602 if (*image_info->magick == '\0')
4603 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4604 format);
4605 break;
4606 }
4607 if (LocaleCompare("frame",option+1) == 0)
4608 {
4609 if (*option == '+')
4610 break;
4611 i++;
cristybb503372010-05-27 20:51:26 +00004612 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004613 ThrowMogrifyException(OptionError,"MissingArgument",option);
4614 if (IsGeometry(argv[i]) == MagickFalse)
4615 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4616 break;
4617 }
4618 if (LocaleCompare("function",option+1) == 0)
4619 {
cristybb503372010-05-27 20:51:26 +00004620 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004621 op;
4622
4623 if (*option == '+')
4624 break;
4625 i++;
cristybb503372010-05-27 20:51:26 +00004626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004627 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004628 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004629 if (op < 0)
4630 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4631 i++;
cristybb503372010-05-27 20:51:26 +00004632 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004633 ThrowMogrifyException(OptionError,"MissingArgument",option);
4634 break;
4635 }
4636 if (LocaleCompare("fuzz",option+1) == 0)
4637 {
4638 if (*option == '+')
4639 break;
4640 i++;
cristybb503372010-05-27 20:51:26 +00004641 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004642 ThrowMogrifyException(OptionError,"MissingArgument",option);
4643 if (IsGeometry(argv[i]) == MagickFalse)
4644 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4645 break;
4646 }
4647 if (LocaleCompare("fx",option+1) == 0)
4648 {
4649 if (*option == '+')
4650 break;
4651 i++;
cristybb503372010-05-27 20:51:26 +00004652 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004653 ThrowMogrifyException(OptionError,"MissingArgument",option);
4654 break;
4655 }
4656 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4657 }
4658 case 'g':
4659 {
4660 if (LocaleCompare("gamma",option+1) == 0)
4661 {
4662 i++;
cristybb503372010-05-27 20:51:26 +00004663 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004664 ThrowMogrifyException(OptionError,"MissingArgument",option);
4665 if (IsGeometry(argv[i]) == MagickFalse)
4666 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4667 break;
4668 }
4669 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4670 (LocaleCompare("gaussian",option+1) == 0))
4671 {
4672 i++;
cristybb503372010-05-27 20:51:26 +00004673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004674 ThrowMogrifyException(OptionError,"MissingArgument",option);
4675 if (IsGeometry(argv[i]) == MagickFalse)
4676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4677 break;
4678 }
4679 if (LocaleCompare("geometry",option+1) == 0)
4680 {
4681 if (*option == '+')
4682 break;
4683 i++;
cristybb503372010-05-27 20:51:26 +00004684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004685 ThrowMogrifyException(OptionError,"MissingArgument",option);
4686 if (IsGeometry(argv[i]) == MagickFalse)
4687 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4688 break;
4689 }
4690 if (LocaleCompare("gravity",option+1) == 0)
4691 {
cristybb503372010-05-27 20:51:26 +00004692 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004693 gravity;
4694
4695 if (*option == '+')
4696 break;
4697 i++;
cristybb503372010-05-27 20:51:26 +00004698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004699 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004700 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004701 if (gravity < 0)
4702 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4703 argv[i]);
4704 break;
4705 }
4706 if (LocaleCompare("green-primary",option+1) == 0)
4707 {
4708 if (*option == '+')
4709 break;
4710 i++;
cristybb503372010-05-27 20:51:26 +00004711 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004712 ThrowMogrifyException(OptionError,"MissingArgument",option);
4713 if (IsGeometry(argv[i]) == MagickFalse)
4714 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4715 break;
4716 }
4717 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4718 }
4719 case 'h':
4720 {
4721 if (LocaleCompare("hald-clut",option+1) == 0)
4722 break;
4723 if ((LocaleCompare("help",option+1) == 0) ||
4724 (LocaleCompare("-help",option+1) == 0))
4725 return(MogrifyUsage());
4726 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4727 }
4728 case 'i':
4729 {
4730 if (LocaleCompare("identify",option+1) == 0)
4731 break;
4732 if (LocaleCompare("idft",option+1) == 0)
4733 break;
4734 if (LocaleCompare("implode",option+1) == 0)
4735 {
4736 if (*option == '+')
4737 break;
4738 i++;
cristybb503372010-05-27 20:51:26 +00004739 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004740 ThrowMogrifyException(OptionError,"MissingArgument",option);
4741 if (IsGeometry(argv[i]) == MagickFalse)
4742 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4743 break;
4744 }
4745 if (LocaleCompare("intent",option+1) == 0)
4746 {
cristybb503372010-05-27 20:51:26 +00004747 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004748 intent;
4749
4750 if (*option == '+')
4751 break;
4752 i++;
cristybb503372010-05-27 20:51:26 +00004753 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004754 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004755 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004756 if (intent < 0)
4757 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4758 argv[i]);
4759 break;
4760 }
4761 if (LocaleCompare("interlace",option+1) == 0)
4762 {
cristybb503372010-05-27 20:51:26 +00004763 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004764 interlace;
4765
4766 if (*option == '+')
4767 break;
4768 i++;
cristybb503372010-05-27 20:51:26 +00004769 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004770 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004771 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004772 argv[i]);
4773 if (interlace < 0)
4774 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4775 argv[i]);
4776 break;
4777 }
cristyb32b90a2009-09-07 21:45:48 +00004778 if (LocaleCompare("interline-spacing",option+1) == 0)
4779 {
4780 if (*option == '+')
4781 break;
4782 i++;
cristybb503372010-05-27 20:51:26 +00004783 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004784 ThrowMogrifyException(OptionError,"MissingArgument",option);
4785 if (IsGeometry(argv[i]) == MagickFalse)
4786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4787 break;
4788 }
cristy3ed852e2009-09-05 21:47:34 +00004789 if (LocaleCompare("interpolate",option+1) == 0)
4790 {
cristybb503372010-05-27 20:51:26 +00004791 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004792 interpolate;
4793
4794 if (*option == '+')
4795 break;
4796 i++;
cristybb503372010-05-27 20:51:26 +00004797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004798 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004799 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004800 argv[i]);
4801 if (interpolate < 0)
4802 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4803 argv[i]);
4804 break;
4805 }
4806 if (LocaleCompare("interword-spacing",option+1) == 0)
4807 {
4808 if (*option == '+')
4809 break;
4810 i++;
cristybb503372010-05-27 20:51:26 +00004811 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004812 ThrowMogrifyException(OptionError,"MissingArgument",option);
4813 if (IsGeometry(argv[i]) == MagickFalse)
4814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4815 break;
4816 }
4817 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4818 }
4819 case 'k':
4820 {
4821 if (LocaleCompare("kerning",option+1) == 0)
4822 {
4823 if (*option == '+')
4824 break;
4825 i++;
cristybb503372010-05-27 20:51:26 +00004826 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004827 ThrowMogrifyException(OptionError,"MissingArgument",option);
4828 if (IsGeometry(argv[i]) == MagickFalse)
4829 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4830 break;
4831 }
4832 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4833 }
4834 case 'l':
4835 {
4836 if (LocaleCompare("label",option+1) == 0)
4837 {
4838 if (*option == '+')
4839 break;
4840 i++;
cristybb503372010-05-27 20:51:26 +00004841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004842 ThrowMogrifyException(OptionError,"MissingArgument",option);
4843 break;
4844 }
4845 if (LocaleCompare("lat",option+1) == 0)
4846 {
4847 if (*option == '+')
4848 break;
4849 i++;
cristybb503372010-05-27 20:51:26 +00004850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004851 ThrowMogrifyException(OptionError,"MissingArgument",option);
4852 if (IsGeometry(argv[i]) == MagickFalse)
4853 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4854 }
4855 if (LocaleCompare("layers",option+1) == 0)
4856 {
cristybb503372010-05-27 20:51:26 +00004857 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004858 type;
4859
4860 if (*option == '+')
4861 break;
4862 i++;
cristybb503372010-05-27 20:51:26 +00004863 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004864 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004865 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004866 if (type < 0)
4867 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4868 argv[i]);
4869 break;
4870 }
4871 if (LocaleCompare("level",option+1) == 0)
4872 {
4873 i++;
cristybb503372010-05-27 20:51:26 +00004874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004875 ThrowMogrifyException(OptionError,"MissingArgument",option);
4876 if (IsGeometry(argv[i]) == MagickFalse)
4877 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4878 break;
4879 }
4880 if (LocaleCompare("level-colors",option+1) == 0)
4881 {
4882 i++;
cristybb503372010-05-27 20:51:26 +00004883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004884 ThrowMogrifyException(OptionError,"MissingArgument",option);
4885 break;
4886 }
4887 if (LocaleCompare("linewidth",option+1) == 0)
4888 {
4889 if (*option == '+')
4890 break;
4891 i++;
cristybb503372010-05-27 20:51:26 +00004892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004893 ThrowMogrifyException(OptionError,"MissingArgument",option);
4894 if (IsGeometry(argv[i]) == MagickFalse)
4895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4896 break;
4897 }
4898 if (LocaleCompare("limit",option+1) == 0)
4899 {
4900 char
4901 *p;
4902
4903 double
4904 value;
4905
cristybb503372010-05-27 20:51:26 +00004906 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004907 resource;
4908
4909 if (*option == '+')
4910 break;
4911 i++;
cristybb503372010-05-27 20:51:26 +00004912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004913 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004914 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004915 argv[i]);
4916 if (resource < 0)
4917 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4918 argv[i]);
4919 i++;
cristybb503372010-05-27 20:51:26 +00004920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004921 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004922 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004923 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004924 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4926 break;
4927 }
4928 if (LocaleCompare("liquid-rescale",option+1) == 0)
4929 {
4930 i++;
cristybb503372010-05-27 20:51:26 +00004931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004932 ThrowMogrifyException(OptionError,"MissingArgument",option);
4933 if (IsGeometry(argv[i]) == MagickFalse)
4934 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4935 break;
4936 }
4937 if (LocaleCompare("list",option+1) == 0)
4938 {
cristybb503372010-05-27 20:51:26 +00004939 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004940 list;
4941
4942 if (*option == '+')
4943 break;
4944 i++;
cristybb503372010-05-27 20:51:26 +00004945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004946 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004947 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004948 if (list < 0)
4949 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004950 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004951 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004952 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004953 }
4954 if (LocaleCompare("log",option+1) == 0)
4955 {
4956 if (*option == '+')
4957 break;
4958 i++;
cristybb503372010-05-27 20:51:26 +00004959 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004960 (strchr(argv[i],'%') == (char *) NULL))
4961 ThrowMogrifyException(OptionError,"MissingArgument",option);
4962 break;
4963 }
4964 if (LocaleCompare("loop",option+1) == 0)
4965 {
4966 if (*option == '+')
4967 break;
4968 i++;
cristybb503372010-05-27 20:51:26 +00004969 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004970 ThrowMogrifyException(OptionError,"MissingArgument",option);
4971 if (IsGeometry(argv[i]) == MagickFalse)
4972 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4973 break;
4974 }
4975 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4976 }
4977 case 'm':
4978 {
4979 if (LocaleCompare("map",option+1) == 0)
4980 {
4981 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4982 if (*option == '+')
4983 break;
4984 i++;
cristybb503372010-05-27 20:51:26 +00004985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004986 ThrowMogrifyException(OptionError,"MissingArgument",option);
4987 break;
4988 }
4989 if (LocaleCompare("mask",option+1) == 0)
4990 {
4991 if (*option == '+')
4992 break;
4993 i++;
cristybb503372010-05-27 20:51:26 +00004994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004995 ThrowMogrifyException(OptionError,"MissingArgument",option);
4996 break;
4997 }
4998 if (LocaleCompare("matte",option+1) == 0)
4999 break;
5000 if (LocaleCompare("mattecolor",option+1) == 0)
5001 {
5002 if (*option == '+')
5003 break;
5004 i++;
cristybb503372010-05-27 20:51:26 +00005005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005006 ThrowMogrifyException(OptionError,"MissingArgument",option);
5007 break;
5008 }
cristyf40785b2010-03-06 02:27:27 +00005009 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005010 break;
cristyf40785b2010-03-06 02:27:27 +00005011 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005012 break;
cristy3ed852e2009-09-05 21:47:34 +00005013 if (LocaleCompare("modulate",option+1) == 0)
5014 {
5015 if (*option == '+')
5016 break;
5017 i++;
cristybb503372010-05-27 20:51:26 +00005018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005019 ThrowMogrifyException(OptionError,"MissingArgument",option);
5020 if (IsGeometry(argv[i]) == MagickFalse)
5021 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5022 break;
5023 }
5024 if (LocaleCompare("median",option+1) == 0)
5025 {
5026 if (*option == '+')
5027 break;
5028 i++;
cristybb503372010-05-27 20:51:26 +00005029 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005030 ThrowMogrifyException(OptionError,"MissingArgument",option);
5031 if (IsGeometry(argv[i]) == MagickFalse)
5032 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5033 break;
5034 }
cristy69ec32d2011-02-27 23:57:09 +00005035 if (LocaleCompare("mode",option+1) == 0)
5036 {
5037 if (*option == '+')
5038 break;
5039 i++;
5040 if (i == (ssize_t) argc)
5041 ThrowMogrifyException(OptionError,"MissingArgument",option);
5042 if (IsGeometry(argv[i]) == MagickFalse)
5043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5044 break;
5045 }
cristy3ed852e2009-09-05 21:47:34 +00005046 if (LocaleCompare("monitor",option+1) == 0)
5047 break;
5048 if (LocaleCompare("monochrome",option+1) == 0)
5049 break;
5050 if (LocaleCompare("morph",option+1) == 0)
5051 {
5052 if (*option == '+')
5053 break;
5054 i++;
cristybb503372010-05-27 20:51:26 +00005055 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005056 ThrowMogrifyException(OptionError,"MissingArgument",option);
5057 if (IsGeometry(argv[i]) == MagickFalse)
5058 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5059 break;
5060 }
anthony29188a82010-01-22 10:12:34 +00005061 if (LocaleCompare("morphology",option+1) == 0)
5062 {
anthony29188a82010-01-22 10:12:34 +00005063 char
5064 token[MaxTextExtent];
5065
cristyb6bd4ad2010-08-08 01:12:27 +00005066 KernelInfo
5067 *kernel_info;
5068
5069 ssize_t
5070 op;
5071
anthony29188a82010-01-22 10:12:34 +00005072 i++;
cristybb503372010-05-27 20:51:26 +00005073 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005074 ThrowMogrifyException(OptionError,"MissingArgument",option);
5075 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005076 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005077 if (op < 0)
5078 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005079 token);
anthony29188a82010-01-22 10:12:34 +00005080 i++;
cristybb503372010-05-27 20:51:26 +00005081 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005082 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005083 kernel_info=AcquireKernelInfo(argv[i]);
5084 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005085 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005086 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005087 break;
5088 }
cristy3ed852e2009-09-05 21:47:34 +00005089 if (LocaleCompare("mosaic",option+1) == 0)
5090 break;
5091 if (LocaleCompare("motion-blur",option+1) == 0)
5092 {
5093 if (*option == '+')
5094 break;
5095 i++;
cristybb503372010-05-27 20:51:26 +00005096 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005097 ThrowMogrifyException(OptionError,"MissingArgument",option);
5098 if (IsGeometry(argv[i]) == MagickFalse)
5099 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5100 break;
5101 }
5102 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5103 }
5104 case 'n':
5105 {
5106 if (LocaleCompare("negate",option+1) == 0)
5107 break;
5108 if (LocaleCompare("noise",option+1) == 0)
5109 {
5110 i++;
cristybb503372010-05-27 20:51:26 +00005111 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005112 ThrowMogrifyException(OptionError,"MissingArgument",option);
5113 if (*option == '+')
5114 {
cristybb503372010-05-27 20:51:26 +00005115 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005116 noise;
5117
cristy042ee782011-04-22 18:48:30 +00005118 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005119 if (noise < 0)
5120 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5121 argv[i]);
5122 break;
5123 }
5124 if (IsGeometry(argv[i]) == MagickFalse)
5125 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5126 break;
5127 }
5128 if (LocaleCompare("noop",option+1) == 0)
5129 break;
5130 if (LocaleCompare("normalize",option+1) == 0)
5131 break;
5132 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5133 }
5134 case 'o':
5135 {
5136 if (LocaleCompare("opaque",option+1) == 0)
5137 {
cristy3ed852e2009-09-05 21:47:34 +00005138 i++;
cristybb503372010-05-27 20:51:26 +00005139 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005140 ThrowMogrifyException(OptionError,"MissingArgument",option);
5141 break;
5142 }
5143 if (LocaleCompare("ordered-dither",option+1) == 0)
5144 {
5145 if (*option == '+')
5146 break;
5147 i++;
cristybb503372010-05-27 20:51:26 +00005148 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005149 ThrowMogrifyException(OptionError,"MissingArgument",option);
5150 break;
5151 }
5152 if (LocaleCompare("orient",option+1) == 0)
5153 {
cristybb503372010-05-27 20:51:26 +00005154 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005155 orientation;
5156
5157 orientation=UndefinedOrientation;
5158 if (*option == '+')
5159 break;
5160 i++;
cristybb503372010-05-27 20:51:26 +00005161 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005162 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005163 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005164 argv[i]);
5165 if (orientation < 0)
5166 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5167 argv[i]);
5168 break;
5169 }
5170 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5171 }
5172 case 'p':
5173 {
5174 if (LocaleCompare("page",option+1) == 0)
5175 {
5176 if (*option == '+')
5177 break;
5178 i++;
cristybb503372010-05-27 20:51:26 +00005179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005180 ThrowMogrifyException(OptionError,"MissingArgument",option);
5181 break;
5182 }
5183 if (LocaleCompare("paint",option+1) == 0)
5184 {
5185 if (*option == '+')
5186 break;
5187 i++;
cristybb503372010-05-27 20:51:26 +00005188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005189 ThrowMogrifyException(OptionError,"MissingArgument",option);
5190 if (IsGeometry(argv[i]) == MagickFalse)
5191 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5192 break;
5193 }
5194 if (LocaleCompare("path",option+1) == 0)
5195 {
5196 (void) CloneString(&path,(char *) NULL);
5197 if (*option == '+')
5198 break;
5199 i++;
cristybb503372010-05-27 20:51:26 +00005200 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005201 ThrowMogrifyException(OptionError,"MissingArgument",option);
5202 (void) CloneString(&path,argv[i]);
5203 break;
5204 }
5205 if (LocaleCompare("pointsize",option+1) == 0)
5206 {
5207 if (*option == '+')
5208 break;
5209 i++;
cristybb503372010-05-27 20:51:26 +00005210 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005211 ThrowMogrifyException(OptionError,"MissingArgument",option);
5212 if (IsGeometry(argv[i]) == MagickFalse)
5213 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5214 break;
5215 }
5216 if (LocaleCompare("polaroid",option+1) == 0)
5217 {
5218 if (*option == '+')
5219 break;
5220 i++;
cristybb503372010-05-27 20:51:26 +00005221 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005222 ThrowMogrifyException(OptionError,"MissingArgument",option);
5223 if (IsGeometry(argv[i]) == MagickFalse)
5224 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5225 break;
5226 }
5227 if (LocaleCompare("posterize",option+1) == 0)
5228 {
5229 if (*option == '+')
5230 break;
5231 i++;
cristybb503372010-05-27 20:51:26 +00005232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005233 ThrowMogrifyException(OptionError,"MissingArgument",option);
5234 if (IsGeometry(argv[i]) == MagickFalse)
5235 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5236 break;
5237 }
cristye7f51092010-01-17 00:39:37 +00005238 if (LocaleCompare("precision",option+1) == 0)
5239 {
5240 if (*option == '+')
5241 break;
5242 i++;
cristybb503372010-05-27 20:51:26 +00005243 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005244 ThrowMogrifyException(OptionError,"MissingArgument",option);
5245 if (IsGeometry(argv[i]) == MagickFalse)
5246 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5247 break;
5248 }
cristy3ed852e2009-09-05 21:47:34 +00005249 if (LocaleCompare("print",option+1) == 0)
5250 {
5251 if (*option == '+')
5252 break;
5253 i++;
cristybb503372010-05-27 20:51:26 +00005254 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005255 ThrowMogrifyException(OptionError,"MissingArgument",option);
5256 break;
5257 }
5258 if (LocaleCompare("process",option+1) == 0)
5259 {
5260 if (*option == '+')
5261 break;
5262 i++;
cristybb503372010-05-27 20:51:26 +00005263 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005264 ThrowMogrifyException(OptionError,"MissingArgument",option);
5265 break;
5266 }
5267 if (LocaleCompare("profile",option+1) == 0)
5268 {
5269 i++;
cristybb503372010-05-27 20:51:26 +00005270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005271 ThrowMogrifyException(OptionError,"MissingArgument",option);
5272 break;
5273 }
5274 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5275 }
5276 case 'q':
5277 {
5278 if (LocaleCompare("quality",option+1) == 0)
5279 {
5280 if (*option == '+')
5281 break;
5282 i++;
cristybb503372010-05-27 20:51:26 +00005283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005284 ThrowMogrifyException(OptionError,"MissingArgument",option);
5285 if (IsGeometry(argv[i]) == MagickFalse)
5286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5287 break;
5288 }
5289 if (LocaleCompare("quantize",option+1) == 0)
5290 {
cristybb503372010-05-27 20:51:26 +00005291 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005292 colorspace;
5293
5294 if (*option == '+')
5295 break;
5296 i++;
cristybb503372010-05-27 20:51:26 +00005297 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005298 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005299 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005300 argv[i]);
5301 if (colorspace < 0)
5302 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5303 argv[i]);
5304 break;
5305 }
5306 if (LocaleCompare("quiet",option+1) == 0)
5307 break;
5308 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5309 }
5310 case 'r':
5311 {
5312 if (LocaleCompare("radial-blur",option+1) == 0)
5313 {
5314 i++;
cristybb503372010-05-27 20:51:26 +00005315 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005316 ThrowMogrifyException(OptionError,"MissingArgument",option);
5317 if (IsGeometry(argv[i]) == MagickFalse)
5318 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5319 break;
5320 }
5321 if (LocaleCompare("raise",option+1) == 0)
5322 {
5323 i++;
cristybb503372010-05-27 20:51:26 +00005324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005325 ThrowMogrifyException(OptionError,"MissingArgument",option);
5326 if (IsGeometry(argv[i]) == MagickFalse)
5327 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5328 break;
5329 }
5330 if (LocaleCompare("random-threshold",option+1) == 0)
5331 {
5332 if (*option == '+')
5333 break;
5334 i++;
cristybb503372010-05-27 20:51:26 +00005335 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005336 ThrowMogrifyException(OptionError,"MissingArgument",option);
5337 if (IsGeometry(argv[i]) == MagickFalse)
5338 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5339 break;
5340 }
cristye6365592010-04-02 17:31:23 +00005341 if (LocaleCompare("recolor",option+1) == 0)
5342 {
5343 if (*option == '+')
5344 break;
5345 i++;
cristybb503372010-05-27 20:51:26 +00005346 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005347 ThrowMogrifyException(OptionError,"MissingArgument",option);
5348 if (IsGeometry(argv[i]) == MagickFalse)
5349 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5350 break;
5351 }
cristy3ed852e2009-09-05 21:47:34 +00005352 if (LocaleCompare("red-primary",option+1) == 0)
5353 {
5354 if (*option == '+')
5355 break;
5356 i++;
cristybb503372010-05-27 20:51:26 +00005357 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005358 ThrowMogrifyException(OptionError,"MissingArgument",option);
5359 if (IsGeometry(argv[i]) == MagickFalse)
5360 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5361 }
cristy9f2083a2010-04-22 19:48:05 +00005362 if (LocaleCompare("regard-warnings",option+1) == 0)
5363 break;
cristy3ed852e2009-09-05 21:47:34 +00005364 if (LocaleCompare("region",option+1) == 0)
5365 {
5366 if (*option == '+')
5367 break;
5368 i++;
cristybb503372010-05-27 20:51:26 +00005369 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005370 ThrowMogrifyException(OptionError,"MissingArgument",option);
5371 if (IsGeometry(argv[i]) == MagickFalse)
5372 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5373 break;
5374 }
cristyf0c78232010-03-15 12:53:40 +00005375 if (LocaleCompare("remap",option+1) == 0)
5376 {
5377 if (*option == '+')
5378 break;
5379 i++;
cristybb503372010-05-27 20:51:26 +00005380 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005381 ThrowMogrifyException(OptionError,"MissingArgument",option);
5382 break;
5383 }
cristy3ed852e2009-09-05 21:47:34 +00005384 if (LocaleCompare("render",option+1) == 0)
5385 break;
5386 if (LocaleCompare("repage",option+1) == 0)
5387 {
5388 if (*option == '+')
5389 break;
5390 i++;
cristybb503372010-05-27 20:51:26 +00005391 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005392 ThrowMogrifyException(OptionError,"MissingArgument",option);
5393 if (IsGeometry(argv[i]) == MagickFalse)
5394 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5395 break;
5396 }
5397 if (LocaleCompare("resample",option+1) == 0)
5398 {
5399 if (*option == '+')
5400 break;
5401 i++;
cristybb503372010-05-27 20:51:26 +00005402 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005403 ThrowMogrifyException(OptionError,"MissingArgument",option);
5404 if (IsGeometry(argv[i]) == MagickFalse)
5405 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5406 break;
5407 }
5408 if (LocaleCompare("resize",option+1) == 0)
5409 {
5410 if (*option == '+')
5411 break;
5412 i++;
cristybb503372010-05-27 20:51:26 +00005413 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005414 ThrowMogrifyException(OptionError,"MissingArgument",option);
5415 if (IsGeometry(argv[i]) == MagickFalse)
5416 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5417 break;
5418 }
cristyebbcfea2011-02-25 02:43:54 +00005419 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5420 {
5421 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5422 break;
5423 }
cristy3ed852e2009-09-05 21:47:34 +00005424 if (LocaleCompare("reverse",option+1) == 0)
5425 break;
5426 if (LocaleCompare("roll",option+1) == 0)
5427 {
5428 if (*option == '+')
5429 break;
5430 i++;
cristybb503372010-05-27 20:51:26 +00005431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005432 ThrowMogrifyException(OptionError,"MissingArgument",option);
5433 if (IsGeometry(argv[i]) == MagickFalse)
5434 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5435 break;
5436 }
5437 if (LocaleCompare("rotate",option+1) == 0)
5438 {
5439 i++;
cristybb503372010-05-27 20:51:26 +00005440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005441 ThrowMogrifyException(OptionError,"MissingArgument",option);
5442 if (IsGeometry(argv[i]) == MagickFalse)
5443 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5444 break;
5445 }
5446 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5447 }
5448 case 's':
5449 {
5450 if (LocaleCompare("sample",option+1) == 0)
5451 {
5452 if (*option == '+')
5453 break;
5454 i++;
cristybb503372010-05-27 20:51:26 +00005455 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005456 ThrowMogrifyException(OptionError,"MissingArgument",option);
5457 if (IsGeometry(argv[i]) == MagickFalse)
5458 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5459 break;
5460 }
5461 if (LocaleCompare("sampling-factor",option+1) == 0)
5462 {
5463 if (*option == '+')
5464 break;
5465 i++;
cristybb503372010-05-27 20:51:26 +00005466 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005467 ThrowMogrifyException(OptionError,"MissingArgument",option);
5468 if (IsGeometry(argv[i]) == MagickFalse)
5469 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5470 break;
5471 }
5472 if (LocaleCompare("scale",option+1) == 0)
5473 {
5474 if (*option == '+')
5475 break;
5476 i++;
cristybb503372010-05-27 20:51:26 +00005477 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005478 ThrowMogrifyException(OptionError,"MissingArgument",option);
5479 if (IsGeometry(argv[i]) == MagickFalse)
5480 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5481 break;
5482 }
5483 if (LocaleCompare("scene",option+1) == 0)
5484 {
5485 if (*option == '+')
5486 break;
5487 i++;
cristybb503372010-05-27 20:51:26 +00005488 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005489 ThrowMogrifyException(OptionError,"MissingArgument",option);
5490 if (IsGeometry(argv[i]) == MagickFalse)
5491 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5492 break;
5493 }
5494 if (LocaleCompare("seed",option+1) == 0)
5495 {
5496 if (*option == '+')
5497 break;
5498 i++;
cristybb503372010-05-27 20:51:26 +00005499 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005500 ThrowMogrifyException(OptionError,"MissingArgument",option);
5501 if (IsGeometry(argv[i]) == MagickFalse)
5502 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5503 break;
5504 }
5505 if (LocaleCompare("segment",option+1) == 0)
5506 {
5507 if (*option == '+')
5508 break;
5509 i++;
cristybb503372010-05-27 20:51:26 +00005510 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005511 ThrowMogrifyException(OptionError,"MissingArgument",option);
5512 if (IsGeometry(argv[i]) == MagickFalse)
5513 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5514 break;
5515 }
5516 if (LocaleCompare("selective-blur",option+1) == 0)
5517 {
5518 i++;
cristybb503372010-05-27 20:51:26 +00005519 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005520 ThrowMogrifyException(OptionError,"MissingArgument",option);
5521 if (IsGeometry(argv[i]) == MagickFalse)
5522 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5523 break;
5524 }
5525 if (LocaleCompare("separate",option+1) == 0)
5526 break;
5527 if (LocaleCompare("sepia-tone",option+1) == 0)
5528 {
5529 if (*option == '+')
5530 break;
5531 i++;
cristybb503372010-05-27 20:51:26 +00005532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005533 ThrowMogrifyException(OptionError,"MissingArgument",option);
5534 if (IsGeometry(argv[i]) == MagickFalse)
5535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5536 break;
5537 }
5538 if (LocaleCompare("set",option+1) == 0)
5539 {
5540 i++;
cristybb503372010-05-27 20:51:26 +00005541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005542 ThrowMogrifyException(OptionError,"MissingArgument",option);
5543 if (*option == '+')
5544 break;
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 break;
5549 }
5550 if (LocaleCompare("shade",option+1) == 0)
5551 {
5552 i++;
cristybb503372010-05-27 20:51:26 +00005553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005554 ThrowMogrifyException(OptionError,"MissingArgument",option);
5555 if (IsGeometry(argv[i]) == MagickFalse)
5556 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5557 break;
5558 }
5559 if (LocaleCompare("shadow",option+1) == 0)
5560 {
5561 if (*option == '+')
5562 break;
5563 i++;
cristybb503372010-05-27 20:51:26 +00005564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005565 ThrowMogrifyException(OptionError,"MissingArgument",option);
5566 if (IsGeometry(argv[i]) == MagickFalse)
5567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5568 break;
5569 }
5570 if (LocaleCompare("sharpen",option+1) == 0)
5571 {
5572 i++;
cristybb503372010-05-27 20:51:26 +00005573 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005574 ThrowMogrifyException(OptionError,"MissingArgument",option);
5575 if (IsGeometry(argv[i]) == MagickFalse)
5576 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5577 break;
5578 }
5579 if (LocaleCompare("shave",option+1) == 0)
5580 {
5581 if (*option == '+')
5582 break;
5583 i++;
cristybb503372010-05-27 20:51:26 +00005584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005585 ThrowMogrifyException(OptionError,"MissingArgument",option);
5586 if (IsGeometry(argv[i]) == MagickFalse)
5587 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5588 break;
5589 }
5590 if (LocaleCompare("shear",option+1) == 0)
5591 {
5592 i++;
cristybb503372010-05-27 20:51:26 +00005593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005594 ThrowMogrifyException(OptionError,"MissingArgument",option);
5595 if (IsGeometry(argv[i]) == MagickFalse)
5596 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5597 break;
5598 }
5599 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5600 {
5601 i++;
cristybb503372010-05-27 20:51:26 +00005602 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005603 ThrowMogrifyException(OptionError,"MissingArgument",option);
5604 if (IsGeometry(argv[i]) == MagickFalse)
5605 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5606 break;
5607 }
5608 if (LocaleCompare("size",option+1) == 0)
5609 {
5610 if (*option == '+')
5611 break;
5612 i++;
cristybb503372010-05-27 20:51:26 +00005613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005614 ThrowMogrifyException(OptionError,"MissingArgument",option);
5615 if (IsGeometry(argv[i]) == MagickFalse)
5616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5617 break;
5618 }
5619 if (LocaleCompare("sketch",option+1) == 0)
5620 {
5621 if (*option == '+')
5622 break;
5623 i++;
cristybb503372010-05-27 20:51:26 +00005624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005625 ThrowMogrifyException(OptionError,"MissingArgument",option);
5626 if (IsGeometry(argv[i]) == MagickFalse)
5627 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5628 break;
5629 }
cristy4285d782011-02-09 20:12:28 +00005630 if (LocaleCompare("smush",option+1) == 0)
5631 {
cristy4285d782011-02-09 20:12:28 +00005632 i++;
5633 if (i == (ssize_t) argc)
5634 ThrowMogrifyException(OptionError,"MissingArgument",option);
5635 if (IsGeometry(argv[i]) == MagickFalse)
5636 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005637 i++;
5638 break;
5639 }
cristy3ed852e2009-09-05 21:47:34 +00005640 if (LocaleCompare("solarize",option+1) == 0)
5641 {
5642 if (*option == '+')
5643 break;
5644 i++;
cristybb503372010-05-27 20:51:26 +00005645 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005646 ThrowMogrifyException(OptionError,"MissingArgument",option);
5647 if (IsGeometry(argv[i]) == MagickFalse)
5648 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5649 break;
5650 }
5651 if (LocaleCompare("sparse-color",option+1) == 0)
5652 {
cristybb503372010-05-27 20:51:26 +00005653 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005654 op;
5655
5656 i++;
cristybb503372010-05-27 20:51:26 +00005657 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005658 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005659 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005660 if (op < 0)
5661 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5662 argv[i]);
5663 i++;
cristybb503372010-05-27 20:51:26 +00005664 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005665 ThrowMogrifyException(OptionError,"MissingArgument",option);
5666 break;
5667 }
5668 if (LocaleCompare("spread",option+1) == 0)
5669 {
5670 if (*option == '+')
5671 break;
5672 i++;
cristybb503372010-05-27 20:51:26 +00005673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005674 ThrowMogrifyException(OptionError,"MissingArgument",option);
5675 if (IsGeometry(argv[i]) == MagickFalse)
5676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5677 break;
5678 }
cristy0834d642011-03-18 18:26:08 +00005679 if (LocaleCompare("statistic",option+1) == 0)
5680 {
5681 ssize_t
5682 op;
5683
5684 if (*option == '+')
5685 break;
5686 i++;
5687 if (i == (ssize_t) argc)
5688 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005689 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005690 if (op < 0)
5691 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5692 argv[i]);
5693 i++;
5694 if (i == (ssize_t) (argc-1))
5695 ThrowMogrifyException(OptionError,"MissingArgument",option);
5696 if (IsGeometry(argv[i]) == MagickFalse)
5697 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5698 break;
5699 }
cristy3ed852e2009-09-05 21:47:34 +00005700 if (LocaleCompare("stretch",option+1) == 0)
5701 {
cristybb503372010-05-27 20:51:26 +00005702 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005703 stretch;
5704
5705 if (*option == '+')
5706 break;
5707 i++;
cristybb503372010-05-27 20:51:26 +00005708 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005709 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005710 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005711 if (stretch < 0)
5712 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5713 argv[i]);
5714 break;
5715 }
5716 if (LocaleCompare("strip",option+1) == 0)
5717 break;
5718 if (LocaleCompare("stroke",option+1) == 0)
5719 {
5720 if (*option == '+')
5721 break;
5722 i++;
cristybb503372010-05-27 20:51:26 +00005723 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005724 ThrowMogrifyException(OptionError,"MissingArgument",option);
5725 break;
5726 }
5727 if (LocaleCompare("strokewidth",option+1) == 0)
5728 {
5729 if (*option == '+')
5730 break;
5731 i++;
cristybb503372010-05-27 20:51:26 +00005732 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005733 ThrowMogrifyException(OptionError,"MissingArgument",option);
5734 if (IsGeometry(argv[i]) == MagickFalse)
5735 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5736 break;
5737 }
5738 if (LocaleCompare("style",option+1) == 0)
5739 {
cristybb503372010-05-27 20:51:26 +00005740 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005741 style;
5742
5743 if (*option == '+')
5744 break;
5745 i++;
cristybb503372010-05-27 20:51:26 +00005746 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005747 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005748 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005749 if (style < 0)
5750 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5751 argv[i]);
5752 break;
5753 }
cristyecb10ff2011-03-22 13:14:03 +00005754 if (LocaleCompare("swap",option+1) == 0)
5755 {
5756 if (*option == '+')
5757 break;
5758 i++;
5759 if (i == (ssize_t) (argc-1))
5760 ThrowMogrifyException(OptionError,"MissingArgument",option);
5761 if (IsGeometry(argv[i]) == MagickFalse)
5762 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5763 break;
5764 }
cristy3ed852e2009-09-05 21:47:34 +00005765 if (LocaleCompare("swirl",option+1) == 0)
5766 {
5767 if (*option == '+')
5768 break;
5769 i++;
cristybb503372010-05-27 20:51:26 +00005770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005771 ThrowMogrifyException(OptionError,"MissingArgument",option);
5772 if (IsGeometry(argv[i]) == MagickFalse)
5773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5774 break;
5775 }
cristyd9a29192010-10-16 16:49:53 +00005776 if (LocaleCompare("synchronize",option+1) == 0)
5777 break;
cristy3ed852e2009-09-05 21:47:34 +00005778 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5779 }
5780 case 't':
5781 {
5782 if (LocaleCompare("taint",option+1) == 0)
5783 break;
5784 if (LocaleCompare("texture",option+1) == 0)
5785 {
5786 if (*option == '+')
5787 break;
5788 i++;
cristybb503372010-05-27 20:51:26 +00005789 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005790 ThrowMogrifyException(OptionError,"MissingArgument",option);
5791 break;
5792 }
5793 if (LocaleCompare("tile",option+1) == 0)
5794 {
5795 if (*option == '+')
5796 break;
5797 i++;
cristybb503372010-05-27 20:51:26 +00005798 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005799 ThrowMogrifyException(OptionError,"MissingArgument",option);
5800 break;
5801 }
5802 if (LocaleCompare("tile-offset",option+1) == 0)
5803 {
5804 if (*option == '+')
5805 break;
5806 i++;
cristybb503372010-05-27 20:51:26 +00005807 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005808 ThrowMogrifyException(OptionError,"MissingArgument",option);
5809 if (IsGeometry(argv[i]) == MagickFalse)
5810 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5811 break;
5812 }
5813 if (LocaleCompare("tint",option+1) == 0)
5814 {
5815 if (*option == '+')
5816 break;
5817 i++;
cristybb503372010-05-27 20:51:26 +00005818 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005819 ThrowMogrifyException(OptionError,"MissingArgument",option);
5820 if (IsGeometry(argv[i]) == MagickFalse)
5821 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5822 break;
5823 }
5824 if (LocaleCompare("transform",option+1) == 0)
5825 break;
5826 if (LocaleCompare("transpose",option+1) == 0)
5827 break;
5828 if (LocaleCompare("transverse",option+1) == 0)
5829 break;
5830 if (LocaleCompare("threshold",option+1) == 0)
5831 {
5832 if (*option == '+')
5833 break;
5834 i++;
cristybb503372010-05-27 20:51:26 +00005835 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005836 ThrowMogrifyException(OptionError,"MissingArgument",option);
5837 if (IsGeometry(argv[i]) == MagickFalse)
5838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5839 break;
5840 }
5841 if (LocaleCompare("thumbnail",option+1) == 0)
5842 {
5843 if (*option == '+')
5844 break;
5845 i++;
cristybb503372010-05-27 20:51:26 +00005846 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005847 ThrowMogrifyException(OptionError,"MissingArgument",option);
5848 if (IsGeometry(argv[i]) == MagickFalse)
5849 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5850 break;
5851 }
5852 if (LocaleCompare("transparent",option+1) == 0)
5853 {
5854 i++;
cristybb503372010-05-27 20:51:26 +00005855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005856 ThrowMogrifyException(OptionError,"MissingArgument",option);
5857 break;
5858 }
5859 if (LocaleCompare("transparent-color",option+1) == 0)
5860 {
5861 if (*option == '+')
5862 break;
5863 i++;
cristybb503372010-05-27 20:51:26 +00005864 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005865 ThrowMogrifyException(OptionError,"MissingArgument",option);
5866 break;
5867 }
5868 if (LocaleCompare("treedepth",option+1) == 0)
5869 {
5870 if (*option == '+')
5871 break;
5872 i++;
cristybb503372010-05-27 20:51:26 +00005873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005874 ThrowMogrifyException(OptionError,"MissingArgument",option);
5875 if (IsGeometry(argv[i]) == MagickFalse)
5876 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5877 break;
5878 }
5879 if (LocaleCompare("trim",option+1) == 0)
5880 break;
5881 if (LocaleCompare("type",option+1) == 0)
5882 {
cristybb503372010-05-27 20:51:26 +00005883 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005884 type;
5885
5886 if (*option == '+')
5887 break;
5888 i++;
cristybb503372010-05-27 20:51:26 +00005889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005890 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005891 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005892 if (type < 0)
5893 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5894 argv[i]);
5895 break;
5896 }
5897 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5898 }
5899 case 'u':
5900 {
5901 if (LocaleCompare("undercolor",option+1) == 0)
5902 {
5903 if (*option == '+')
5904 break;
5905 i++;
cristybb503372010-05-27 20:51:26 +00005906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005907 ThrowMogrifyException(OptionError,"MissingArgument",option);
5908 break;
5909 }
5910 if (LocaleCompare("unique-colors",option+1) == 0)
5911 break;
5912 if (LocaleCompare("units",option+1) == 0)
5913 {
cristybb503372010-05-27 20:51:26 +00005914 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005915 units;
5916
5917 if (*option == '+')
5918 break;
5919 i++;
cristybb503372010-05-27 20:51:26 +00005920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005921 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005922 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005923 argv[i]);
5924 if (units < 0)
5925 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5926 argv[i]);
5927 break;
5928 }
5929 if (LocaleCompare("unsharp",option+1) == 0)
5930 {
5931 i++;
cristybb503372010-05-27 20:51:26 +00005932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005933 ThrowMogrifyException(OptionError,"MissingArgument",option);
5934 if (IsGeometry(argv[i]) == MagickFalse)
5935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5936 break;
5937 }
5938 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5939 }
5940 case 'v':
5941 {
5942 if (LocaleCompare("verbose",option+1) == 0)
5943 {
5944 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5945 break;
5946 }
5947 if ((LocaleCompare("version",option+1) == 0) ||
5948 (LocaleCompare("-version",option+1) == 0))
5949 {
cristyb51dff52011-05-19 16:55:47 +00005950 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005951 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005952 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5953 GetMagickCopyright());
5954 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5955 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005956 break;
5957 }
5958 if (LocaleCompare("view",option+1) == 0)
5959 {
5960 if (*option == '+')
5961 break;
5962 i++;
cristybb503372010-05-27 20:51:26 +00005963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005964 ThrowMogrifyException(OptionError,"MissingArgument",option);
5965 break;
5966 }
5967 if (LocaleCompare("vignette",option+1) == 0)
5968 {
5969 if (*option == '+')
5970 break;
5971 i++;
cristybb503372010-05-27 20:51:26 +00005972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005973 ThrowMogrifyException(OptionError,"MissingArgument",option);
5974 if (IsGeometry(argv[i]) == MagickFalse)
5975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5976 break;
5977 }
5978 if (LocaleCompare("virtual-pixel",option+1) == 0)
5979 {
cristybb503372010-05-27 20:51:26 +00005980 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005981 method;
5982
5983 if (*option == '+')
5984 break;
5985 i++;
cristybb503372010-05-27 20:51:26 +00005986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005987 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005988 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005989 argv[i]);
5990 if (method < 0)
5991 ThrowMogrifyException(OptionError,
5992 "UnrecognizedVirtualPixelMethod",argv[i]);
5993 break;
5994 }
5995 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5996 }
5997 case 'w':
5998 {
5999 if (LocaleCompare("wave",option+1) == 0)
6000 {
6001 i++;
cristybb503372010-05-27 20:51:26 +00006002 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006003 ThrowMogrifyException(OptionError,"MissingArgument",option);
6004 if (IsGeometry(argv[i]) == MagickFalse)
6005 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6006 break;
6007 }
6008 if (LocaleCompare("weight",option+1) == 0)
6009 {
6010 if (*option == '+')
6011 break;
6012 i++;
cristybb503372010-05-27 20:51:26 +00006013 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006014 ThrowMogrifyException(OptionError,"MissingArgument",option);
6015 break;
6016 }
6017 if (LocaleCompare("white-point",option+1) == 0)
6018 {
6019 if (*option == '+')
6020 break;
6021 i++;
cristybb503372010-05-27 20:51:26 +00006022 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006023 ThrowMogrifyException(OptionError,"MissingArgument",option);
6024 if (IsGeometry(argv[i]) == MagickFalse)
6025 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6026 break;
6027 }
6028 if (LocaleCompare("white-threshold",option+1) == 0)
6029 {
6030 if (*option == '+')
6031 break;
6032 i++;
cristybb503372010-05-27 20:51:26 +00006033 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006034 ThrowMogrifyException(OptionError,"MissingArgument",option);
6035 if (IsGeometry(argv[i]) == MagickFalse)
6036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6037 break;
6038 }
6039 if (LocaleCompare("write",option+1) == 0)
6040 {
6041 i++;
cristybb503372010-05-27 20:51:26 +00006042 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006043 ThrowMogrifyException(OptionError,"MissingArgument",option);
6044 break;
6045 }
6046 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6047 }
6048 case '?':
6049 break;
6050 default:
6051 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6052 }
cristy042ee782011-04-22 18:48:30 +00006053 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6054 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006055 if (fire != MagickFalse)
6056 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6057 }
6058 if (k != 0)
6059 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006060 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006061 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6062 DestroyMogrify();
6063 return(status != 0 ? MagickTrue : MagickFalse);
6064}
6065
6066/*
6067%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6068% %
6069% %
6070% %
6071+ M o g r i f y I m a g e I n f o %
6072% %
6073% %
6074% %
6075%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6076%
6077% MogrifyImageInfo() applies image processing settings to the image as
6078% prescribed by command line options.
6079%
6080% The format of the MogrifyImageInfo method is:
6081%
6082% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6083% const char **argv,ExceptionInfo *exception)
6084%
6085% A description of each parameter follows:
6086%
6087% o image_info: the image info..
6088%
6089% o argc: Specifies a pointer to an integer describing the number of
6090% elements in the argument vector.
6091%
6092% o argv: Specifies a pointer to a text array containing the command line
6093% arguments.
6094%
6095% o exception: return any errors or warnings in this structure.
6096%
6097*/
6098WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6099 const int argc,const char **argv,ExceptionInfo *exception)
6100{
6101 const char
6102 *option;
6103
6104 GeometryInfo
6105 geometry_info;
6106
cristybb503372010-05-27 20:51:26 +00006107 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006108 count;
6109
cristybb503372010-05-27 20:51:26 +00006110 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006111 i;
6112
6113 /*
6114 Initialize method variables.
6115 */
6116 assert(image_info != (ImageInfo *) NULL);
6117 assert(image_info->signature == MagickSignature);
6118 if (image_info->debug != MagickFalse)
6119 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6120 image_info->filename);
6121 if (argc < 0)
6122 return(MagickTrue);
6123 /*
6124 Set the image settings.
6125 */
cristybb503372010-05-27 20:51:26 +00006126 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006127 {
6128 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006129 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006130 continue;
cristy042ee782011-04-22 18:48:30 +00006131 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006132 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006133 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006134 break;
6135 switch (*(option+1))
6136 {
6137 case 'a':
6138 {
6139 if (LocaleCompare("adjoin",option+1) == 0)
6140 {
6141 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6142 break;
6143 }
6144 if (LocaleCompare("antialias",option+1) == 0)
6145 {
6146 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6147 break;
6148 }
6149 if (LocaleCompare("attenuate",option+1) == 0)
6150 {
6151 if (*option == '+')
6152 {
6153 (void) DeleteImageOption(image_info,option+1);
6154 break;
6155 }
6156 (void) SetImageOption(image_info,option+1,argv[i+1]);
6157 break;
6158 }
6159 if (LocaleCompare("authenticate",option+1) == 0)
6160 {
6161 if (*option == '+')
6162 (void) CloneString(&image_info->authenticate,(char *) NULL);
6163 else
6164 (void) CloneString(&image_info->authenticate,argv[i+1]);
6165 break;
6166 }
6167 break;
6168 }
6169 case 'b':
6170 {
6171 if (LocaleCompare("background",option+1) == 0)
6172 {
6173 if (*option == '+')
6174 {
6175 (void) DeleteImageOption(image_info,option+1);
6176 (void) QueryColorDatabase(BackgroundColor,
6177 &image_info->background_color,exception);
6178 break;
6179 }
6180 (void) SetImageOption(image_info,option+1,argv[i+1]);
6181 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6182 exception);
6183 break;
6184 }
6185 if (LocaleCompare("bias",option+1) == 0)
6186 {
6187 if (*option == '+')
6188 {
6189 (void) SetImageOption(image_info,option+1,"0.0");
6190 break;
6191 }
6192 (void) SetImageOption(image_info,option+1,argv[i+1]);
6193 break;
6194 }
6195 if (LocaleCompare("black-point-compensation",option+1) == 0)
6196 {
6197 if (*option == '+')
6198 {
6199 (void) SetImageOption(image_info,option+1,"false");
6200 break;
6201 }
6202 (void) SetImageOption(image_info,option+1,"true");
6203 break;
6204 }
6205 if (LocaleCompare("blue-primary",option+1) == 0)
6206 {
6207 if (*option == '+')
6208 {
6209 (void) SetImageOption(image_info,option+1,"0.0");
6210 break;
6211 }
6212 (void) SetImageOption(image_info,option+1,argv[i+1]);
6213 break;
6214 }
6215 if (LocaleCompare("bordercolor",option+1) == 0)
6216 {
6217 if (*option == '+')
6218 {
6219 (void) DeleteImageOption(image_info,option+1);
6220 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6221 exception);
6222 break;
6223 }
6224 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6225 exception);
6226 (void) SetImageOption(image_info,option+1,argv[i+1]);
6227 break;
6228 }
6229 if (LocaleCompare("box",option+1) == 0)
6230 {
6231 if (*option == '+')
6232 {
6233 (void) SetImageOption(image_info,"undercolor","none");
6234 break;
6235 }
6236 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6237 break;
6238 }
6239 break;
6240 }
6241 case 'c':
6242 {
6243 if (LocaleCompare("cache",option+1) == 0)
6244 {
6245 MagickSizeType
6246 limit;
6247
6248 limit=MagickResourceInfinity;
6249 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006250 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006251 (void) SetMagickResourceLimit(MemoryResource,limit);
6252 (void) SetMagickResourceLimit(MapResource,2*limit);
6253 break;
6254 }
6255 if (LocaleCompare("caption",option+1) == 0)
6256 {
6257 if (*option == '+')
6258 {
6259 (void) DeleteImageOption(image_info,option+1);
6260 break;
6261 }
6262 (void) SetImageOption(image_info,option+1,argv[i+1]);
6263 break;
6264 }
6265 if (LocaleCompare("channel",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 {
6269 image_info->channel=DefaultChannels;
6270 break;
6271 }
6272 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6273 break;
6274 }
6275 if (LocaleCompare("colors",option+1) == 0)
6276 {
cristye27293e2009-12-18 02:53:20 +00006277 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006278 break;
6279 }
6280 if (LocaleCompare("colorspace",option+1) == 0)
6281 {
6282 if (*option == '+')
6283 {
6284 image_info->colorspace=UndefinedColorspace;
6285 (void) SetImageOption(image_info,option+1,"undefined");
6286 break;
6287 }
cristy042ee782011-04-22 18:48:30 +00006288 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006289 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6290 (void) SetImageOption(image_info,option+1,argv[i+1]);
6291 break;
6292 }
cristy3ed852e2009-09-05 21:47:34 +00006293 if (LocaleCompare("comment",option+1) == 0)
6294 {
6295 if (*option == '+')
6296 {
6297 (void) DeleteImageOption(image_info,option+1);
6298 break;
6299 }
6300 (void) SetImageOption(image_info,option+1,argv[i+1]);
6301 break;
6302 }
6303 if (LocaleCompare("compose",option+1) == 0)
6304 {
6305 if (*option == '+')
6306 {
6307 (void) SetImageOption(image_info,option+1,"undefined");
6308 break;
6309 }
6310 (void) SetImageOption(image_info,option+1,argv[i+1]);
6311 break;
6312 }
6313 if (LocaleCompare("compress",option+1) == 0)
6314 {
6315 if (*option == '+')
6316 {
6317 image_info->compression=UndefinedCompression;
6318 (void) SetImageOption(image_info,option+1,"undefined");
6319 break;
6320 }
cristy042ee782011-04-22 18:48:30 +00006321 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006322 MagickCompressOptions,MagickFalse,argv[i+1]);
6323 (void) SetImageOption(image_info,option+1,argv[i+1]);
6324 break;
6325 }
6326 break;
6327 }
6328 case 'd':
6329 {
6330 if (LocaleCompare("debug",option+1) == 0)
6331 {
6332 if (*option == '+')
6333 (void) SetLogEventMask("none");
6334 else
6335 (void) SetLogEventMask(argv[i+1]);
6336 image_info->debug=IsEventLogging();
6337 break;
6338 }
6339 if (LocaleCompare("define",option+1) == 0)
6340 {
6341 if (*option == '+')
6342 {
6343 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6344 (void) DeleteImageRegistry(argv[i+1]+9);
6345 else
6346 (void) DeleteImageOption(image_info,argv[i+1]);
6347 break;
6348 }
6349 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6350 {
6351 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6352 exception);
6353 break;
6354 }
6355 (void) DefineImageOption(image_info,argv[i+1]);
6356 break;
6357 }
6358 if (LocaleCompare("delay",option+1) == 0)
6359 {
6360 if (*option == '+')
6361 {
6362 (void) SetImageOption(image_info,option+1,"0");
6363 break;
6364 }
6365 (void) SetImageOption(image_info,option+1,argv[i+1]);
6366 break;
6367 }
6368 if (LocaleCompare("density",option+1) == 0)
6369 {
6370 /*
6371 Set image density.
6372 */
6373 if (*option == '+')
6374 {
6375 if (image_info->density != (char *) NULL)
6376 image_info->density=DestroyString(image_info->density);
6377 (void) SetImageOption(image_info,option+1,"72");
6378 break;
6379 }
6380 (void) CloneString(&image_info->density,argv[i+1]);
6381 (void) SetImageOption(image_info,option+1,argv[i+1]);
6382 break;
6383 }
6384 if (LocaleCompare("depth",option+1) == 0)
6385 {
6386 if (*option == '+')
6387 {
6388 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6389 break;
6390 }
cristye27293e2009-12-18 02:53:20 +00006391 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006392 break;
6393 }
cristyc9b12952010-03-28 01:12:28 +00006394 if (LocaleCompare("direction",option+1) == 0)
6395 {
6396 if (*option == '+')
6397 {
6398 (void) SetImageOption(image_info,option+1,"undefined");
6399 break;
6400 }
6401 (void) SetImageOption(image_info,option+1,argv[i+1]);
6402 break;
6403 }
cristy3ed852e2009-09-05 21:47:34 +00006404 if (LocaleCompare("display",option+1) == 0)
6405 {
6406 if (*option == '+')
6407 {
6408 if (image_info->server_name != (char *) NULL)
6409 image_info->server_name=DestroyString(
6410 image_info->server_name);
6411 break;
6412 }
6413 (void) CloneString(&image_info->server_name,argv[i+1]);
6414 break;
6415 }
6416 if (LocaleCompare("dispose",option+1) == 0)
6417 {
6418 if (*option == '+')
6419 {
6420 (void) SetImageOption(image_info,option+1,"undefined");
6421 break;
6422 }
6423 (void) SetImageOption(image_info,option+1,argv[i+1]);
6424 break;
6425 }
6426 if (LocaleCompare("dither",option+1) == 0)
6427 {
6428 if (*option == '+')
6429 {
6430 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006431 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006432 break;
6433 }
6434 (void) SetImageOption(image_info,option+1,argv[i+1]);
6435 image_info->dither=MagickTrue;
6436 break;
6437 }
6438 break;
6439 }
6440 case 'e':
6441 {
6442 if (LocaleCompare("encoding",option+1) == 0)
6443 {
6444 if (*option == '+')
6445 {
6446 (void) SetImageOption(image_info,option+1,"undefined");
6447 break;
6448 }
6449 (void) SetImageOption(image_info,option+1,argv[i+1]);
6450 break;
6451 }
6452 if (LocaleCompare("endian",option+1) == 0)
6453 {
6454 if (*option == '+')
6455 {
6456 image_info->endian=UndefinedEndian;
6457 (void) SetImageOption(image_info,option+1,"undefined");
6458 break;
6459 }
cristy042ee782011-04-22 18:48:30 +00006460 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006461 MagickEndianOptions,MagickFalse,argv[i+1]);
6462 (void) SetImageOption(image_info,option+1,argv[i+1]);
6463 break;
6464 }
6465 if (LocaleCompare("extract",option+1) == 0)
6466 {
6467 /*
6468 Set image extract geometry.
6469 */
6470 if (*option == '+')
6471 {
6472 if (image_info->extract != (char *) NULL)
6473 image_info->extract=DestroyString(image_info->extract);
6474 break;
6475 }
6476 (void) CloneString(&image_info->extract,argv[i+1]);
6477 break;
6478 }
6479 break;
6480 }
6481 case 'f':
6482 {
6483 if (LocaleCompare("fill",option+1) == 0)
6484 {
6485 if (*option == '+')
6486 {
6487 (void) SetImageOption(image_info,option+1,"none");
6488 break;
6489 }
6490 (void) SetImageOption(image_info,option+1,argv[i+1]);
6491 break;
6492 }
6493 if (LocaleCompare("filter",option+1) == 0)
6494 {
6495 if (*option == '+')
6496 {
6497 (void) SetImageOption(image_info,option+1,"undefined");
6498 break;
6499 }
6500 (void) SetImageOption(image_info,option+1,argv[i+1]);
6501 break;
6502 }
6503 if (LocaleCompare("font",option+1) == 0)
6504 {
6505 if (*option == '+')
6506 {
6507 if (image_info->font != (char *) NULL)
6508 image_info->font=DestroyString(image_info->font);
6509 break;
6510 }
6511 (void) CloneString(&image_info->font,argv[i+1]);
6512 break;
6513 }
6514 if (LocaleCompare("format",option+1) == 0)
6515 {
6516 register const char
6517 *q;
6518
6519 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006520 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006521 image_info->ping=MagickFalse;
6522 (void) SetImageOption(image_info,option+1,argv[i+1]);
6523 break;
6524 }
6525 if (LocaleCompare("fuzz",option+1) == 0)
6526 {
6527 if (*option == '+')
6528 {
6529 image_info->fuzz=0.0;
6530 (void) SetImageOption(image_info,option+1,"0");
6531 break;
6532 }
cristyf2f27272009-12-17 14:48:46 +00006533 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006534 1.0);
6535 (void) SetImageOption(image_info,option+1,argv[i+1]);
6536 break;
6537 }
6538 break;
6539 }
6540 case 'g':
6541 {
6542 if (LocaleCompare("gravity",option+1) == 0)
6543 {
6544 if (*option == '+')
6545 {
6546 (void) SetImageOption(image_info,option+1,"undefined");
6547 break;
6548 }
6549 (void) SetImageOption(image_info,option+1,argv[i+1]);
6550 break;
6551 }
6552 if (LocaleCompare("green-primary",option+1) == 0)
6553 {
6554 if (*option == '+')
6555 {
6556 (void) SetImageOption(image_info,option+1,"0.0");
6557 break;
6558 }
6559 (void) SetImageOption(image_info,option+1,argv[i+1]);
6560 break;
6561 }
6562 break;
6563 }
6564 case 'i':
6565 {
6566 if (LocaleCompare("intent",option+1) == 0)
6567 {
6568 if (*option == '+')
6569 {
6570 (void) SetImageOption(image_info,option+1,"undefined");
6571 break;
6572 }
6573 (void) SetImageOption(image_info,option+1,argv[i+1]);
6574 break;
6575 }
6576 if (LocaleCompare("interlace",option+1) == 0)
6577 {
6578 if (*option == '+')
6579 {
6580 image_info->interlace=UndefinedInterlace;
6581 (void) SetImageOption(image_info,option+1,"undefined");
6582 break;
6583 }
cristy042ee782011-04-22 18:48:30 +00006584 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006585 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6586 (void) SetImageOption(image_info,option+1,argv[i+1]);
6587 break;
6588 }
cristyb32b90a2009-09-07 21:45:48 +00006589 if (LocaleCompare("interline-spacing",option+1) == 0)
6590 {
6591 if (*option == '+')
6592 {
6593 (void) SetImageOption(image_info,option+1,"undefined");
6594 break;
6595 }
6596 (void) SetImageOption(image_info,option+1,argv[i+1]);
6597 break;
6598 }
cristy3ed852e2009-09-05 21:47:34 +00006599 if (LocaleCompare("interpolate",option+1) == 0)
6600 {
6601 if (*option == '+')
6602 {
6603 (void) SetImageOption(image_info,option+1,"undefined");
6604 break;
6605 }
6606 (void) SetImageOption(image_info,option+1,argv[i+1]);
6607 break;
6608 }
6609 if (LocaleCompare("interword-spacing",option+1) == 0)
6610 {
6611 if (*option == '+')
6612 {
6613 (void) SetImageOption(image_info,option+1,"undefined");
6614 break;
6615 }
6616 (void) SetImageOption(image_info,option+1,argv[i+1]);
6617 break;
6618 }
6619 break;
6620 }
6621 case 'k':
6622 {
6623 if (LocaleCompare("kerning",option+1) == 0)
6624 {
6625 if (*option == '+')
6626 {
6627 (void) SetImageOption(image_info,option+1,"undefined");
6628 break;
6629 }
6630 (void) SetImageOption(image_info,option+1,argv[i+1]);
6631 break;
6632 }
6633 break;
6634 }
6635 case 'l':
6636 {
6637 if (LocaleCompare("label",option+1) == 0)
6638 {
6639 if (*option == '+')
6640 {
6641 (void) DeleteImageOption(image_info,option+1);
6642 break;
6643 }
6644 (void) SetImageOption(image_info,option+1,argv[i+1]);
6645 break;
6646 }
6647 if (LocaleCompare("limit",option+1) == 0)
6648 {
6649 MagickSizeType
6650 limit;
6651
6652 ResourceType
6653 type;
6654
6655 if (*option == '+')
6656 break;
cristy042ee782011-04-22 18:48:30 +00006657 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006658 MagickFalse,argv[i+1]);
6659 limit=MagickResourceInfinity;
6660 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006661 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006662 (void) SetMagickResourceLimit(type,limit);
6663 break;
6664 }
6665 if (LocaleCompare("list",option+1) == 0)
6666 {
cristybb503372010-05-27 20:51:26 +00006667 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006668 list;
6669
6670 /*
6671 Display configuration list.
6672 */
cristy042ee782011-04-22 18:48:30 +00006673 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006674 switch (list)
6675 {
6676 case MagickCoderOptions:
6677 {
6678 (void) ListCoderInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickColorOptions:
6682 {
6683 (void) ListColorInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickConfigureOptions:
6687 {
6688 (void) ListConfigureInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickDelegateOptions:
6692 {
6693 (void) ListDelegateInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickFontOptions:
6697 {
6698 (void) ListTypeInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickFormatOptions:
6702 {
6703 (void) ListMagickInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickLocaleOptions:
6707 {
6708 (void) ListLocaleInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickLogOptions:
6712 {
6713 (void) ListLogInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickMagicOptions:
6717 {
6718 (void) ListMagicInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickMimeOptions:
6722 {
6723 (void) ListMimeInfo((FILE *) NULL,exception);
6724 break;
6725 }
6726 case MagickModuleOptions:
6727 {
6728 (void) ListModuleInfo((FILE *) NULL,exception);
6729 break;
6730 }
6731 case MagickPolicyOptions:
6732 {
6733 (void) ListPolicyInfo((FILE *) NULL,exception);
6734 break;
6735 }
6736 case MagickResourceOptions:
6737 {
6738 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6739 break;
6740 }
6741 case MagickThresholdOptions:
6742 {
6743 (void) ListThresholdMaps((FILE *) NULL,exception);
6744 break;
6745 }
6746 default:
6747 {
cristy042ee782011-04-22 18:48:30 +00006748 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006749 exception);
6750 break;
6751 }
6752 }
cristyaeb2cbc2010-05-07 13:28:58 +00006753 break;
cristy3ed852e2009-09-05 21:47:34 +00006754 }
6755 if (LocaleCompare("log",option+1) == 0)
6756 {
6757 if (*option == '+')
6758 break;
6759 (void) SetLogFormat(argv[i+1]);
6760 break;
6761 }
6762 if (LocaleCompare("loop",option+1) == 0)
6763 {
6764 if (*option == '+')
6765 {
6766 (void) SetImageOption(image_info,option+1,"0");
6767 break;
6768 }
6769 (void) SetImageOption(image_info,option+1,argv[i+1]);
6770 break;
6771 }
6772 break;
6773 }
6774 case 'm':
6775 {
6776 if (LocaleCompare("matte",option+1) == 0)
6777 {
6778 if (*option == '+')
6779 {
6780 (void) SetImageOption(image_info,option+1,"false");
6781 break;
6782 }
6783 (void) SetImageOption(image_info,option+1,"true");
6784 break;
6785 }
6786 if (LocaleCompare("mattecolor",option+1) == 0)
6787 {
6788 if (*option == '+')
6789 {
6790 (void) SetImageOption(image_info,option+1,argv[i+1]);
6791 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6792 exception);
6793 break;
6794 }
6795 (void) SetImageOption(image_info,option+1,argv[i+1]);
6796 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6797 exception);
6798 break;
6799 }
6800 if (LocaleCompare("monitor",option+1) == 0)
6801 {
6802 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6803 (void *) NULL);
6804 break;
6805 }
6806 if (LocaleCompare("monochrome",option+1) == 0)
6807 {
6808 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6809 break;
6810 }
6811 break;
6812 }
6813 case 'o':
6814 {
6815 if (LocaleCompare("orient",option+1) == 0)
6816 {
6817 if (*option == '+')
6818 {
6819 image_info->orientation=UndefinedOrientation;
6820 (void) SetImageOption(image_info,option+1,"undefined");
6821 break;
6822 }
cristy042ee782011-04-22 18:48:30 +00006823 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006824 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006825 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006826 break;
6827 }
6828 }
6829 case 'p':
6830 {
6831 if (LocaleCompare("page",option+1) == 0)
6832 {
6833 char
6834 *canonical_page,
6835 page[MaxTextExtent];
6836
6837 const char
6838 *image_option;
6839
6840 MagickStatusType
6841 flags;
6842
6843 RectangleInfo
6844 geometry;
6845
6846 if (*option == '+')
6847 {
6848 (void) DeleteImageOption(image_info,option+1);
6849 (void) CloneString(&image_info->page,(char *) NULL);
6850 break;
6851 }
6852 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6853 image_option=GetImageOption(image_info,"page");
6854 if (image_option != (const char *) NULL)
6855 flags=ParseAbsoluteGeometry(image_option,&geometry);
6856 canonical_page=GetPageGeometry(argv[i+1]);
6857 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6858 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006859 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006860 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006861 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006862 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006863 (unsigned long) geometry.width,(unsigned long) geometry.height,
6864 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006865 (void) SetImageOption(image_info,option+1,page);
6866 (void) CloneString(&image_info->page,page);
6867 break;
6868 }
6869 if (LocaleCompare("pen",option+1) == 0)
6870 {
6871 if (*option == '+')
6872 {
6873 (void) SetImageOption(image_info,option+1,"none");
6874 break;
6875 }
6876 (void) SetImageOption(image_info,option+1,argv[i+1]);
6877 break;
6878 }
6879 if (LocaleCompare("ping",option+1) == 0)
6880 {
6881 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6882 break;
6883 }
6884 if (LocaleCompare("pointsize",option+1) == 0)
6885 {
6886 if (*option == '+')
6887 geometry_info.rho=0.0;
6888 else
6889 (void) ParseGeometry(argv[i+1],&geometry_info);
6890 image_info->pointsize=geometry_info.rho;
6891 break;
6892 }
cristye7f51092010-01-17 00:39:37 +00006893 if (LocaleCompare("precision",option+1) == 0)
6894 {
cristybf2766a2010-01-17 03:33:23 +00006895 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006896 break;
6897 }
cristy3ed852e2009-09-05 21:47:34 +00006898 if (LocaleCompare("preview",option+1) == 0)
6899 {
6900 /*
6901 Preview image.
6902 */
6903 if (*option == '+')
6904 {
6905 image_info->preview_type=UndefinedPreview;
6906 break;
6907 }
cristy042ee782011-04-22 18:48:30 +00006908 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006909 MagickPreviewOptions,MagickFalse,argv[i+1]);
6910 break;
6911 }
6912 break;
6913 }
6914 case 'q':
6915 {
6916 if (LocaleCompare("quality",option+1) == 0)
6917 {
6918 /*
6919 Set image compression quality.
6920 */
6921 if (*option == '+')
6922 {
6923 image_info->quality=UndefinedCompressionQuality;
6924 (void) SetImageOption(image_info,option+1,"0");
6925 break;
6926 }
cristye27293e2009-12-18 02:53:20 +00006927 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006928 (void) SetImageOption(image_info,option+1,argv[i+1]);
6929 break;
6930 }
6931 if (LocaleCompare("quiet",option+1) == 0)
6932 {
6933 static WarningHandler
6934 warning_handler = (WarningHandler) NULL;
6935
6936 if (*option == '+')
6937 {
6938 /*
6939 Restore error or warning messages.
6940 */
6941 warning_handler=SetWarningHandler(warning_handler);
6942 break;
6943 }
6944 /*
6945 Suppress error or warning messages.
6946 */
6947 warning_handler=SetWarningHandler((WarningHandler) NULL);
6948 break;
6949 }
6950 break;
6951 }
6952 case 'r':
6953 {
6954 if (LocaleCompare("red-primary",option+1) == 0)
6955 {
6956 if (*option == '+')
6957 {
6958 (void) SetImageOption(image_info,option+1,"0.0");
6959 break;
6960 }
6961 (void) SetImageOption(image_info,option+1,argv[i+1]);
6962 break;
6963 }
6964 break;
6965 }
6966 case 's':
6967 {
6968 if (LocaleCompare("sampling-factor",option+1) == 0)
6969 {
6970 /*
6971 Set image sampling factor.
6972 */
6973 if (*option == '+')
6974 {
6975 if (image_info->sampling_factor != (char *) NULL)
6976 image_info->sampling_factor=DestroyString(
6977 image_info->sampling_factor);
6978 break;
6979 }
6980 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6981 break;
6982 }
6983 if (LocaleCompare("scene",option+1) == 0)
6984 {
6985 /*
6986 Set image scene.
6987 */
6988 if (*option == '+')
6989 {
6990 image_info->scene=0;
6991 (void) SetImageOption(image_info,option+1,"0");
6992 break;
6993 }
cristye27293e2009-12-18 02:53:20 +00006994 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006995 (void) SetImageOption(image_info,option+1,argv[i+1]);
6996 break;
6997 }
6998 if (LocaleCompare("seed",option+1) == 0)
6999 {
cristybb503372010-05-27 20:51:26 +00007000 size_t
cristy3ed852e2009-09-05 21:47:34 +00007001 seed;
7002
7003 if (*option == '+')
7004 {
cristybb503372010-05-27 20:51:26 +00007005 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007006 SeedPseudoRandomGenerator(seed);
7007 break;
7008 }
cristye27293e2009-12-18 02:53:20 +00007009 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007010 SeedPseudoRandomGenerator(seed);
7011 break;
7012 }
7013 if (LocaleCompare("size",option+1) == 0)
7014 {
7015 if (*option == '+')
7016 {
7017 if (image_info->size != (char *) NULL)
7018 image_info->size=DestroyString(image_info->size);
7019 break;
7020 }
7021 (void) CloneString(&image_info->size,argv[i+1]);
7022 break;
7023 }
7024 if (LocaleCompare("stroke",option+1) == 0)
7025 {
7026 if (*option == '+')
7027 {
7028 (void) SetImageOption(image_info,option+1,"none");
7029 break;
7030 }
7031 (void) SetImageOption(image_info,option+1,argv[i+1]);
7032 break;
7033 }
7034 if (LocaleCompare("strokewidth",option+1) == 0)
7035 {
7036 if (*option == '+')
7037 {
7038 (void) SetImageOption(image_info,option+1,"0");
7039 break;
7040 }
7041 (void) SetImageOption(image_info,option+1,argv[i+1]);
7042 break;
7043 }
cristyd9a29192010-10-16 16:49:53 +00007044 if (LocaleCompare("synchronize",option+1) == 0)
7045 {
7046 if (*option == '+')
7047 {
7048 image_info->synchronize=MagickFalse;
7049 break;
7050 }
7051 image_info->synchronize=MagickTrue;
7052 break;
7053 }
cristy3ed852e2009-09-05 21:47:34 +00007054 break;
7055 }
7056 case 't':
7057 {
7058 if (LocaleCompare("taint",option+1) == 0)
7059 {
7060 if (*option == '+')
7061 {
7062 (void) SetImageOption(image_info,option+1,"false");
7063 break;
7064 }
7065 (void) SetImageOption(image_info,option+1,"true");
7066 break;
7067 }
7068 if (LocaleCompare("texture",option+1) == 0)
7069 {
7070 if (*option == '+')
7071 {
7072 if (image_info->texture != (char *) NULL)
7073 image_info->texture=DestroyString(image_info->texture);
7074 break;
7075 }
7076 (void) CloneString(&image_info->texture,argv[i+1]);
7077 break;
7078 }
7079 if (LocaleCompare("tile-offset",option+1) == 0)
7080 {
7081 if (*option == '+')
7082 {
7083 (void) SetImageOption(image_info,option+1,"0");
7084 break;
7085 }
7086 (void) SetImageOption(image_info,option+1,argv[i+1]);
7087 break;
7088 }
7089 if (LocaleCompare("transparent-color",option+1) == 0)
7090 {
7091 if (*option == '+')
7092 {
7093 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7094 (void) SetImageOption(image_info,option+1,"none");
7095 break;
7096 }
7097 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7098 exception);
7099 (void) SetImageOption(image_info,option+1,argv[i+1]);
7100 break;
7101 }
7102 if (LocaleCompare("type",option+1) == 0)
7103 {
7104 if (*option == '+')
7105 {
cristy5f1c1ff2010-12-23 21:38:06 +00007106 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007107 (void) SetImageOption(image_info,option+1,"undefined");
7108 break;
7109 }
cristy042ee782011-04-22 18:48:30 +00007110 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007111 MagickFalse,argv[i+1]);
7112 (void) SetImageOption(image_info,option+1,argv[i+1]);
7113 break;
7114 }
7115 break;
7116 }
7117 case 'u':
7118 {
7119 if (LocaleCompare("undercolor",option+1) == 0)
7120 {
7121 if (*option == '+')
7122 {
7123 (void) DeleteImageOption(image_info,option+1);
7124 break;
7125 }
7126 (void) SetImageOption(image_info,option+1,argv[i+1]);
7127 break;
7128 }
7129 if (LocaleCompare("units",option+1) == 0)
7130 {
7131 if (*option == '+')
7132 {
7133 image_info->units=UndefinedResolution;
7134 (void) SetImageOption(image_info,option+1,"undefined");
7135 break;
7136 }
cristy042ee782011-04-22 18:48:30 +00007137 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007138 MagickResolutionOptions,MagickFalse,argv[i+1]);
7139 (void) SetImageOption(image_info,option+1,argv[i+1]);
7140 break;
7141 }
7142 break;
7143 }
7144 case 'v':
7145 {
7146 if (LocaleCompare("verbose",option+1) == 0)
7147 {
7148 if (*option == '+')
7149 {
7150 image_info->verbose=MagickFalse;
7151 break;
7152 }
7153 image_info->verbose=MagickTrue;
7154 image_info->ping=MagickFalse;
7155 break;
7156 }
7157 if (LocaleCompare("view",option+1) == 0)
7158 {
7159 if (*option == '+')
7160 {
7161 if (image_info->view != (char *) NULL)
7162 image_info->view=DestroyString(image_info->view);
7163 break;
7164 }
7165 (void) CloneString(&image_info->view,argv[i+1]);
7166 break;
7167 }
7168 if (LocaleCompare("virtual-pixel",option+1) == 0)
7169 {
7170 if (*option == '+')
7171 {
7172 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7173 (void) SetImageOption(image_info,option+1,"undefined");
7174 break;
7175 }
7176 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007177 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007178 argv[i+1]);
7179 (void) SetImageOption(image_info,option+1,argv[i+1]);
7180 break;
7181 }
7182 break;
7183 }
7184 case 'w':
7185 {
7186 if (LocaleCompare("white-point",option+1) == 0)
7187 {
7188 if (*option == '+')
7189 {
7190 (void) SetImageOption(image_info,option+1,"0.0");
7191 break;
7192 }
7193 (void) SetImageOption(image_info,option+1,argv[i+1]);
7194 break;
7195 }
7196 break;
7197 }
7198 default:
7199 break;
7200 }
7201 i+=count;
7202 }
7203 return(MagickTrue);
7204}
7205
7206/*
7207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7208% %
7209% %
7210% %
7211+ M o g r i f y I m a g e L i s t %
7212% %
7213% %
7214% %
7215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7216%
7217% MogrifyImageList() applies any command line options that might affect the
7218% entire image list (e.g. -append, -coalesce, etc.).
7219%
7220% The format of the MogrifyImage method is:
7221%
7222% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7223% const char **argv,Image **images,ExceptionInfo *exception)
7224%
7225% A description of each parameter follows:
7226%
7227% o image_info: the image info..
7228%
7229% o argc: Specifies a pointer to an integer describing the number of
7230% elements in the argument vector.
7231%
7232% o argv: Specifies a pointer to a text array containing the command line
7233% arguments.
7234%
anthonye9c27192011-03-27 08:07:06 +00007235% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007236%
7237% o exception: return any errors or warnings in this structure.
7238%
7239*/
7240WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7241 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7242{
7243 ChannelType
7244 channel;
7245
7246 const char
7247 *option;
7248
cristy6b3da3a2010-06-20 02:21:46 +00007249 ImageInfo
7250 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007251
7252 MagickStatusType
7253 status;
7254
7255 QuantizeInfo
7256 *quantize_info;
7257
cristybb503372010-05-27 20:51:26 +00007258 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007259 i;
7260
cristy6b3da3a2010-06-20 02:21:46 +00007261 ssize_t
7262 count,
7263 index;
7264
cristy3ed852e2009-09-05 21:47:34 +00007265 /*
7266 Apply options to the image list.
7267 */
7268 assert(image_info != (ImageInfo *) NULL);
7269 assert(image_info->signature == MagickSignature);
7270 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007271 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007272 assert((*images)->signature == MagickSignature);
7273 if ((*images)->debug != MagickFalse)
7274 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7275 (*images)->filename);
7276 if ((argc <= 0) || (*argv == (char *) NULL))
7277 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007278 mogrify_info=CloneImageInfo(image_info);
7279 quantize_info=AcquireQuantizeInfo(mogrify_info);
7280 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007281 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007282 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007283 {
cristy74fe8f12009-10-03 19:09:01 +00007284 if (*images == (Image *) NULL)
7285 break;
cristy3ed852e2009-09-05 21:47:34 +00007286 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007287 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007288 continue;
cristy042ee782011-04-22 18:48:30 +00007289 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007290 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007291 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007292 break;
cristy6b3da3a2010-06-20 02:21:46 +00007293 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007294 switch (*(option+1))
7295 {
7296 case 'a':
7297 {
7298 if (LocaleCompare("affinity",option+1) == 0)
7299 {
cristy6b3da3a2010-06-20 02:21:46 +00007300 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007301 if (*option == '+')
7302 {
7303 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7304 InheritException(exception,&(*images)->exception);
7305 break;
7306 }
7307 i++;
7308 break;
7309 }
7310 if (LocaleCompare("append",option+1) == 0)
7311 {
7312 Image
7313 *append_image;
7314
cristy6b3da3a2010-06-20 02:21:46 +00007315 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007316 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7317 MagickFalse,exception);
7318 if (append_image == (Image *) NULL)
7319 {
7320 status=MagickFalse;
7321 break;
7322 }
7323 *images=DestroyImageList(*images);
7324 *images=append_image;
7325 break;
7326 }
7327 if (LocaleCompare("average",option+1) == 0)
7328 {
7329 Image
7330 *average_image;
7331
cristyd18ae7c2010-03-07 17:39:52 +00007332 /*
7333 Average an image sequence (deprecated).
7334 */
cristy6b3da3a2010-06-20 02:21:46 +00007335 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007336 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7337 exception);
cristy3ed852e2009-09-05 21:47:34 +00007338 if (average_image == (Image *) NULL)
7339 {
7340 status=MagickFalse;
7341 break;
7342 }
7343 *images=DestroyImageList(*images);
7344 *images=average_image;
7345 break;
7346 }
7347 break;
7348 }
7349 case 'c':
7350 {
7351 if (LocaleCompare("channel",option+1) == 0)
7352 {
7353 if (*option == '+')
7354 {
7355 channel=DefaultChannels;
7356 break;
7357 }
7358 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7359 break;
7360 }
7361 if (LocaleCompare("clut",option+1) == 0)
7362 {
7363 Image
7364 *clut_image,
7365 *image;
7366
cristy6b3da3a2010-06-20 02:21:46 +00007367 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007368 image=RemoveFirstImageFromList(images);
7369 clut_image=RemoveFirstImageFromList(images);
7370 if (clut_image == (Image *) NULL)
7371 {
7372 status=MagickFalse;
7373 break;
7374 }
7375 (void) ClutImageChannel(image,channel,clut_image);
7376 clut_image=DestroyImage(clut_image);
7377 InheritException(exception,&image->exception);
7378 *images=DestroyImageList(*images);
7379 *images=image;
7380 break;
7381 }
7382 if (LocaleCompare("coalesce",option+1) == 0)
7383 {
7384 Image
7385 *coalesce_image;
7386
cristy6b3da3a2010-06-20 02:21:46 +00007387 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007388 coalesce_image=CoalesceImages(*images,exception);
7389 if (coalesce_image == (Image *) NULL)
7390 {
7391 status=MagickFalse;
7392 break;
7393 }
7394 *images=DestroyImageList(*images);
7395 *images=coalesce_image;
7396 break;
7397 }
7398 if (LocaleCompare("combine",option+1) == 0)
7399 {
7400 Image
7401 *combine_image;
7402
cristy6b3da3a2010-06-20 02:21:46 +00007403 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007404 combine_image=CombineImages(*images,channel,exception);
7405 if (combine_image == (Image *) NULL)
7406 {
7407 status=MagickFalse;
7408 break;
7409 }
7410 *images=DestroyImageList(*images);
7411 *images=combine_image;
7412 break;
7413 }
7414 if (LocaleCompare("composite",option+1) == 0)
7415 {
7416 Image
7417 *mask_image,
7418 *composite_image,
7419 *image;
7420
7421 RectangleInfo
7422 geometry;
7423
cristy6b3da3a2010-06-20 02:21:46 +00007424 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007425 image=RemoveFirstImageFromList(images);
7426 composite_image=RemoveFirstImageFromList(images);
7427 if (composite_image == (Image *) NULL)
7428 {
7429 status=MagickFalse;
7430 break;
7431 }
7432 (void) TransformImage(&composite_image,(char *) NULL,
7433 composite_image->geometry);
7434 SetGeometry(composite_image,&geometry);
7435 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7436 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7437 &geometry);
7438 mask_image=RemoveFirstImageFromList(images);
7439 if (mask_image != (Image *) NULL)
7440 {
7441 if ((image->compose == DisplaceCompositeOp) ||
7442 (image->compose == DistortCompositeOp))
7443 {
7444 /*
7445 Merge Y displacement into X displacement image.
7446 */
7447 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7448 mask_image,0,0);
7449 mask_image=DestroyImage(mask_image);
7450 }
7451 else
7452 {
7453 /*
7454 Set a blending mask for the composition.
7455 */
anthonya129f702011-04-14 01:08:48 +00007456 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007457 image->mask=mask_image;
7458 (void) NegateImage(image->mask,MagickFalse);
7459 }
7460 }
cristyab015852011-07-06 01:03:32 +00007461 (void) CompositeImageChannel(image,channel,image->compose,
7462 composite_image,geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007463 if (mask_image != (Image *) NULL)
7464 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007465 composite_image=DestroyImage(composite_image);
7466 InheritException(exception,&image->exception);
7467 *images=DestroyImageList(*images);
7468 *images=image;
7469 break;
7470 }
anthony9f4f0342011-03-28 11:47:22 +00007471#if 0
7472This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007473 if (LocaleCompare("crop",option+1) == 0)
7474 {
7475 MagickStatusType
7476 flags;
7477
7478 RectangleInfo
7479 geometry;
7480
anthonye9c27192011-03-27 08:07:06 +00007481 /*
anthony9f4f0342011-03-28 11:47:22 +00007482 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007483 */
cristy6b3da3a2010-06-20 02:21:46 +00007484 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007485 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7486 if (((geometry.width == 0) && (geometry.height == 0)) ||
7487 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7488 break;
7489 (void) TransformImages(images,argv[i+1],(char *) NULL);
7490 InheritException(exception,&(*images)->exception);
7491 break;
7492 }
anthony9f4f0342011-03-28 11:47:22 +00007493#endif
cristy3ed852e2009-09-05 21:47:34 +00007494 break;
7495 }
7496 case 'd':
7497 {
7498 if (LocaleCompare("deconstruct",option+1) == 0)
7499 {
7500 Image
7501 *deconstruct_image;
7502
cristy6b3da3a2010-06-20 02:21:46 +00007503 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007504 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007505 exception);
cristy3ed852e2009-09-05 21:47:34 +00007506 if (deconstruct_image == (Image *) NULL)
7507 {
7508 status=MagickFalse;
7509 break;
7510 }
7511 *images=DestroyImageList(*images);
7512 *images=deconstruct_image;
7513 break;
7514 }
7515 if (LocaleCompare("delete",option+1) == 0)
7516 {
7517 if (*option == '+')
7518 DeleteImages(images,"-1",exception);
7519 else
7520 DeleteImages(images,argv[i+1],exception);
7521 break;
7522 }
7523 if (LocaleCompare("dither",option+1) == 0)
7524 {
7525 if (*option == '+')
7526 {
7527 quantize_info->dither=MagickFalse;
7528 break;
7529 }
7530 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007531 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007532 MagickDitherOptions,MagickFalse,argv[i+1]);
7533 break;
7534 }
cristyecb10ff2011-03-22 13:14:03 +00007535 if (LocaleCompare("duplicate",option+1) == 0)
7536 {
cristy72988482011-03-29 16:34:38 +00007537 Image
7538 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007539
anthony2b6bcae2011-03-23 13:05:34 +00007540 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007541 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7542 else
7543 {
7544 const char
7545 *p;
7546
anthony2b6bcae2011-03-23 13:05:34 +00007547 size_t
7548 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007549
anthony2b6bcae2011-03-23 13:05:34 +00007550 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007551 p=strchr(argv[i+1],',');
7552 if (p == (const char *) NULL)
7553 duplicate_images=DuplicateImages(*images,number_duplicates,
7554 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007555 else
cristy72988482011-03-29 16:34:38 +00007556 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7557 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007558 }
7559 AppendImageToList(images, duplicate_images);
7560 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007561 break;
7562 }
cristy3ed852e2009-09-05 21:47:34 +00007563 break;
7564 }
cristyd18ae7c2010-03-07 17:39:52 +00007565 case 'e':
7566 {
7567 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7568 {
7569 Image
7570 *evaluate_image;
7571
7572 MagickEvaluateOperator
7573 op;
7574
cristy6b3da3a2010-06-20 02:21:46 +00007575 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007576 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007577 MagickFalse,argv[i+1]);
7578 evaluate_image=EvaluateImages(*images,op,exception);
7579 if (evaluate_image == (Image *) NULL)
7580 {
7581 status=MagickFalse;
7582 break;
7583 }
7584 *images=DestroyImageList(*images);
7585 *images=evaluate_image;
7586 break;
7587 }
7588 break;
7589 }
cristy3ed852e2009-09-05 21:47:34 +00007590 case 'f':
7591 {
cristyf0a247f2009-10-04 00:20:03 +00007592 if (LocaleCompare("fft",option+1) == 0)
7593 {
7594 Image
7595 *fourier_image;
7596
7597 /*
7598 Implements the discrete Fourier transform (DFT).
7599 */
cristy6b3da3a2010-06-20 02:21:46 +00007600 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007601 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7602 MagickTrue : MagickFalse,exception);
7603 if (fourier_image == (Image *) NULL)
7604 break;
7605 *images=DestroyImage(*images);
7606 *images=fourier_image;
7607 break;
7608 }
cristy3ed852e2009-09-05 21:47:34 +00007609 if (LocaleCompare("flatten",option+1) == 0)
7610 {
7611 Image
7612 *flatten_image;
7613
cristy6b3da3a2010-06-20 02:21:46 +00007614 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007615 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7616 if (flatten_image == (Image *) NULL)
7617 break;
7618 *images=DestroyImageList(*images);
7619 *images=flatten_image;
7620 break;
7621 }
7622 if (LocaleCompare("fx",option+1) == 0)
7623 {
7624 Image
7625 *fx_image;
7626
cristy6b3da3a2010-06-20 02:21:46 +00007627 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007628 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7629 if (fx_image == (Image *) NULL)
7630 {
7631 status=MagickFalse;
7632 break;
7633 }
7634 *images=DestroyImageList(*images);
7635 *images=fx_image;
7636 break;
7637 }
7638 break;
7639 }
7640 case 'h':
7641 {
7642 if (LocaleCompare("hald-clut",option+1) == 0)
7643 {
7644 Image
7645 *hald_image,
7646 *image;
7647
cristy6b3da3a2010-06-20 02:21:46 +00007648 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007649 image=RemoveFirstImageFromList(images);
7650 hald_image=RemoveFirstImageFromList(images);
7651 if (hald_image == (Image *) NULL)
7652 {
7653 status=MagickFalse;
7654 break;
7655 }
7656 (void) HaldClutImageChannel(image,channel,hald_image);
7657 hald_image=DestroyImage(hald_image);
7658 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007659 if (*images != (Image *) NULL)
7660 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007661 *images=image;
7662 break;
7663 }
7664 break;
7665 }
7666 case 'i':
7667 {
7668 if (LocaleCompare("ift",option+1) == 0)
7669 {
7670 Image
cristy8587f882009-11-13 20:28:49 +00007671 *fourier_image,
7672 *magnitude_image,
7673 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007674
7675 /*
7676 Implements the inverse fourier discrete Fourier transform (DFT).
7677 */
cristy6b3da3a2010-06-20 02:21:46 +00007678 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007679 magnitude_image=RemoveFirstImageFromList(images);
7680 phase_image=RemoveFirstImageFromList(images);
7681 if (phase_image == (Image *) NULL)
7682 {
7683 status=MagickFalse;
7684 break;
7685 }
7686 fourier_image=InverseFourierTransformImage(magnitude_image,
7687 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007688 if (fourier_image == (Image *) NULL)
7689 break;
cristy0aff6ea2009-11-14 01:40:53 +00007690 if (*images != (Image *) NULL)
7691 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007692 *images=fourier_image;
7693 break;
7694 }
7695 if (LocaleCompare("insert",option+1) == 0)
7696 {
7697 Image
7698 *p,
7699 *q;
7700
7701 index=0;
7702 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007703 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007704 p=RemoveLastImageFromList(images);
7705 if (p == (Image *) NULL)
7706 {
7707 (void) ThrowMagickException(exception,GetMagickModule(),
7708 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7709 status=MagickFalse;
7710 break;
7711 }
7712 q=p;
7713 if (index == 0)
7714 PrependImageToList(images,q);
7715 else
cristybb503372010-05-27 20:51:26 +00007716 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007717 AppendImageToList(images,q);
7718 else
7719 {
7720 q=GetImageFromList(*images,index-1);
7721 if (q == (Image *) NULL)
7722 {
7723 (void) ThrowMagickException(exception,GetMagickModule(),
7724 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7725 status=MagickFalse;
7726 break;
7727 }
7728 InsertImageInList(&q,p);
7729 }
7730 *images=GetFirstImageInList(q);
7731 break;
7732 }
7733 break;
7734 }
7735 case 'l':
7736 {
7737 if (LocaleCompare("layers",option+1) == 0)
7738 {
7739 Image
7740 *layers;
7741
7742 ImageLayerMethod
7743 method;
7744
cristy6b3da3a2010-06-20 02:21:46 +00007745 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007746 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007747 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007748 MagickFalse,argv[i+1]);
7749 switch (method)
7750 {
7751 case CoalesceLayer:
7752 {
7753 layers=CoalesceImages(*images,exception);
7754 break;
7755 }
7756 case CompareAnyLayer:
7757 case CompareClearLayer:
7758 case CompareOverlayLayer:
7759 default:
7760 {
cristy8a9106f2011-07-05 14:39:26 +00007761 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007762 break;
7763 }
7764 case MergeLayer:
7765 case FlattenLayer:
7766 case MosaicLayer:
7767 case TrimBoundsLayer:
7768 {
7769 layers=MergeImageLayers(*images,method,exception);
7770 break;
7771 }
7772 case DisposeLayer:
7773 {
7774 layers=DisposeImages(*images,exception);
7775 break;
7776 }
7777 case OptimizeImageLayer:
7778 {
7779 layers=OptimizeImageLayers(*images,exception);
7780 break;
7781 }
7782 case OptimizePlusLayer:
7783 {
7784 layers=OptimizePlusImageLayers(*images,exception);
7785 break;
7786 }
7787 case OptimizeTransLayer:
7788 {
7789 OptimizeImageTransparency(*images,exception);
7790 break;
7791 }
7792 case RemoveDupsLayer:
7793 {
7794 RemoveDuplicateLayers(images,exception);
7795 break;
7796 }
7797 case RemoveZeroLayer:
7798 {
7799 RemoveZeroDelayLayers(images,exception);
7800 break;
7801 }
7802 case OptimizeLayer:
7803 {
7804 /*
7805 General Purpose, GIF Animation Optimizer.
7806 */
7807 layers=CoalesceImages(*images,exception);
7808 if (layers == (Image *) NULL)
7809 {
7810 status=MagickFalse;
7811 break;
7812 }
7813 InheritException(exception,&layers->exception);
7814 *images=DestroyImageList(*images);
7815 *images=layers;
7816 layers=OptimizeImageLayers(*images,exception);
7817 if (layers == (Image *) NULL)
7818 {
7819 status=MagickFalse;
7820 break;
7821 }
7822 InheritException(exception,&layers->exception);
7823 *images=DestroyImageList(*images);
7824 *images=layers;
7825 layers=(Image *) NULL;
7826 OptimizeImageTransparency(*images,exception);
7827 InheritException(exception,&(*images)->exception);
7828 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7829 break;
7830 }
7831 case CompositeLayer:
7832 {
7833 CompositeOperator
7834 compose;
7835
7836 Image
7837 *source;
7838
7839 RectangleInfo
7840 geometry;
7841
7842 /*
7843 Split image sequence at the first 'NULL:' image.
7844 */
7845 source=(*images);
7846 while (source != (Image *) NULL)
7847 {
7848 source=GetNextImageInList(source);
7849 if ((source != (Image *) NULL) &&
7850 (LocaleCompare(source->magick,"NULL") == 0))
7851 break;
7852 }
7853 if (source != (Image *) NULL)
7854 {
7855 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7856 (GetNextImageInList(source) == (Image *) NULL))
7857 source=(Image *) NULL;
7858 else
7859 {
7860 /*
7861 Separate the two lists, junk the null: image.
7862 */
7863 source=SplitImageList(source->previous);
7864 DeleteImageFromList(&source);
7865 }
7866 }
7867 if (source == (Image *) NULL)
7868 {
7869 (void) ThrowMagickException(exception,GetMagickModule(),
7870 OptionError,"MissingNullSeparator","layers Composite");
7871 status=MagickFalse;
7872 break;
7873 }
7874 /*
7875 Adjust offset with gravity and virtual canvas.
7876 */
7877 SetGeometry(*images,&geometry);
7878 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7879 geometry.width=source->page.width != 0 ?
7880 source->page.width : source->columns;
7881 geometry.height=source->page.height != 0 ?
7882 source->page.height : source->rows;
7883 GravityAdjustGeometry((*images)->page.width != 0 ?
7884 (*images)->page.width : (*images)->columns,
7885 (*images)->page.height != 0 ? (*images)->page.height :
7886 (*images)->rows,(*images)->gravity,&geometry);
7887 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007888 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007889 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007890 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007891 MagickComposeOptions,MagickFalse,option);
7892 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7893 exception);
7894 source=DestroyImageList(source);
7895 break;
7896 }
7897 }
7898 if (layers == (Image *) NULL)
7899 break;
7900 InheritException(exception,&layers->exception);
7901 *images=DestroyImageList(*images);
7902 *images=layers;
7903 break;
7904 }
7905 break;
7906 }
7907 case 'm':
7908 {
7909 if (LocaleCompare("map",option+1) == 0)
7910 {
cristy6b3da3a2010-06-20 02:21:46 +00007911 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007912 if (*option == '+')
7913 {
7914 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7915 InheritException(exception,&(*images)->exception);
7916 break;
7917 }
7918 i++;
7919 break;
7920 }
cristyf40785b2010-03-06 02:27:27 +00007921 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007922 {
7923 Image
cristyf40785b2010-03-06 02:27:27 +00007924 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007925
cristyd18ae7c2010-03-07 17:39:52 +00007926 /*
7927 Maximum image sequence (deprecated).
7928 */
cristy6b3da3a2010-06-20 02:21:46 +00007929 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007930 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007931 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007932 {
7933 status=MagickFalse;
7934 break;
7935 }
7936 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007937 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007938 break;
7939 }
cristyf40785b2010-03-06 02:27:27 +00007940 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007941 {
7942 Image
cristyf40785b2010-03-06 02:27:27 +00007943 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007944
cristyd18ae7c2010-03-07 17:39:52 +00007945 /*
7946 Minimum image sequence (deprecated).
7947 */
cristy6b3da3a2010-06-20 02:21:46 +00007948 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007949 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007950 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007951 {
7952 status=MagickFalse;
7953 break;
7954 }
7955 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007956 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007957 break;
7958 }
cristy3ed852e2009-09-05 21:47:34 +00007959 if (LocaleCompare("morph",option+1) == 0)
7960 {
7961 Image
7962 *morph_image;
7963
cristy6b3da3a2010-06-20 02:21:46 +00007964 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007965 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007966 exception);
7967 if (morph_image == (Image *) NULL)
7968 {
7969 status=MagickFalse;
7970 break;
7971 }
7972 *images=DestroyImageList(*images);
7973 *images=morph_image;
7974 break;
7975 }
7976 if (LocaleCompare("mosaic",option+1) == 0)
7977 {
7978 Image
7979 *mosaic_image;
7980
cristy6b3da3a2010-06-20 02:21:46 +00007981 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007982 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7983 if (mosaic_image == (Image *) NULL)
7984 {
7985 status=MagickFalse;
7986 break;
7987 }
7988 *images=DestroyImageList(*images);
7989 *images=mosaic_image;
7990 break;
7991 }
7992 break;
7993 }
7994 case 'p':
7995 {
7996 if (LocaleCompare("print",option+1) == 0)
7997 {
7998 char
7999 *string;
8000
cristy6b3da3a2010-06-20 02:21:46 +00008001 (void) SyncImagesSettings(mogrify_info,*images);
8002 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008003 if (string == (char *) NULL)
8004 break;
8005 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00008006 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008007 string=DestroyString(string);
8008 }
8009 if (LocaleCompare("process",option+1) == 0)
8010 {
8011 char
8012 **arguments;
8013
8014 int
8015 j,
8016 number_arguments;
8017
cristy6b3da3a2010-06-20 02:21:46 +00008018 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008019 arguments=StringToArgv(argv[i+1],&number_arguments);
8020 if (arguments == (char **) NULL)
8021 break;
8022 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8023 {
8024 char
8025 breaker,
8026 quote,
8027 *token;
8028
8029 const char
8030 *arguments;
8031
8032 int
8033 next,
8034 status;
8035
8036 size_t
8037 length;
8038
8039 TokenInfo
8040 *token_info;
8041
8042 /*
8043 Support old style syntax, filter="-option arg".
8044 */
8045 length=strlen(argv[i+1]);
8046 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008047 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008048 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8049 sizeof(*token));
8050 if (token == (char *) NULL)
8051 break;
8052 next=0;
8053 arguments=argv[i+1];
8054 token_info=AcquireTokenInfo();
8055 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8056 "\"",'\0',&breaker,&next,&quote);
8057 token_info=DestroyTokenInfo(token_info);
8058 if (status == 0)
8059 {
8060 const char
8061 *argv;
8062
8063 argv=(&(arguments[next]));
8064 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8065 exception);
8066 }
8067 token=DestroyString(token);
8068 break;
8069 }
cristy91c0da22010-05-02 01:44:07 +00008070 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008071 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8072 number_arguments-2,(const char **) arguments+2,exception);
8073 for (j=0; j < number_arguments; j++)
8074 arguments[j]=DestroyString(arguments[j]);
8075 arguments=(char **) RelinquishMagickMemory(arguments);
8076 break;
8077 }
8078 break;
8079 }
8080 case 'r':
8081 {
8082 if (LocaleCompare("reverse",option+1) == 0)
8083 {
8084 ReverseImageList(images);
8085 InheritException(exception,&(*images)->exception);
8086 break;
8087 }
8088 break;
8089 }
8090 case 's':
8091 {
cristy4285d782011-02-09 20:12:28 +00008092 if (LocaleCompare("smush",option+1) == 0)
8093 {
8094 Image
8095 *smush_image;
8096
8097 ssize_t
8098 offset;
8099
8100 (void) SyncImagesSettings(mogrify_info,*images);
8101 offset=(ssize_t) StringToLong(argv[i+1]);
8102 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8103 MagickFalse,offset,exception);
8104 if (smush_image == (Image *) NULL)
8105 {
8106 status=MagickFalse;
8107 break;
8108 }
8109 *images=DestroyImageList(*images);
8110 *images=smush_image;
8111 break;
8112 }
cristy3ed852e2009-09-05 21:47:34 +00008113 if (LocaleCompare("swap",option+1) == 0)
8114 {
8115 Image
8116 *p,
8117 *q,
8118 *swap;
8119
cristybb503372010-05-27 20:51:26 +00008120 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008121 swap_index;
8122
8123 index=(-1);
8124 swap_index=(-2);
8125 if (*option != '+')
8126 {
8127 GeometryInfo
8128 geometry_info;
8129
8130 MagickStatusType
8131 flags;
8132
8133 swap_index=(-1);
8134 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008135 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008136 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008137 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008138 }
8139 p=GetImageFromList(*images,index);
8140 q=GetImageFromList(*images,swap_index);
8141 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8142 {
8143 (void) ThrowMagickException(exception,GetMagickModule(),
8144 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8145 status=MagickFalse;
8146 break;
8147 }
8148 if (p == q)
8149 break;
8150 swap=CloneImage(p,0,0,MagickTrue,exception);
8151 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8152 ReplaceImageInList(&q,swap);
8153 *images=GetFirstImageInList(q);
8154 break;
8155 }
8156 break;
8157 }
8158 case 'w':
8159 {
8160 if (LocaleCompare("write",option+1) == 0)
8161 {
cristy071dd7b2010-04-09 13:04:54 +00008162 char
cristy06609ee2010-03-17 20:21:27 +00008163 key[MaxTextExtent];
8164
cristy3ed852e2009-09-05 21:47:34 +00008165 Image
8166 *write_images;
8167
8168 ImageInfo
8169 *write_info;
8170
cristy6b3da3a2010-06-20 02:21:46 +00008171 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008172 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008173 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008174 write_images=(*images);
8175 if (*option == '+')
8176 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008177 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008178 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8179 write_info=DestroyImageInfo(write_info);
8180 if (*option == '+')
8181 write_images=DestroyImageList(write_images);
8182 break;
8183 }
8184 break;
8185 }
8186 default:
8187 break;
8188 }
8189 i+=count;
8190 }
8191 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008192 mogrify_info=DestroyImageInfo(mogrify_info);
8193 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008194 return(status != 0 ? MagickTrue : MagickFalse);
8195}
8196
8197/*
8198%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8199% %
8200% %
8201% %
8202+ M o g r i f y I m a g e s %
8203% %
8204% %
8205% %
8206%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8207%
8208% MogrifyImages() applies image processing options to a sequence of images as
8209% prescribed by command line options.
8210%
8211% The format of the MogrifyImage method is:
8212%
8213% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8214% const MagickBooleanType post,const int argc,const char **argv,
8215% Image **images,Exceptioninfo *exception)
8216%
8217% A description of each parameter follows:
8218%
8219% o image_info: the image info..
8220%
8221% o post: If true, post process image list operators otherwise pre-process.
8222%
8223% o argc: Specifies a pointer to an integer describing the number of
8224% elements in the argument vector.
8225%
8226% o argv: Specifies a pointer to a text array containing the command line
8227% arguments.
8228%
anthonye9c27192011-03-27 08:07:06 +00008229% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008230%
8231% o exception: return any errors or warnings in this structure.
8232%
8233*/
8234WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8235 const MagickBooleanType post,const int argc,const char **argv,
8236 Image **images,ExceptionInfo *exception)
8237{
8238#define MogrifyImageTag "Mogrify/Image"
8239
anthonye9c27192011-03-27 08:07:06 +00008240 MagickStatusType
8241 status;
cristy3ed852e2009-09-05 21:47:34 +00008242
cristy0e9f9c12010-02-11 03:00:47 +00008243 MagickBooleanType
8244 proceed;
8245
anthonye9c27192011-03-27 08:07:06 +00008246 size_t
8247 n;
cristy3ed852e2009-09-05 21:47:34 +00008248
cristybb503372010-05-27 20:51:26 +00008249 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008250 i;
8251
cristy3ed852e2009-09-05 21:47:34 +00008252 assert(image_info != (ImageInfo *) NULL);
8253 assert(image_info->signature == MagickSignature);
8254 if (images == (Image **) NULL)
8255 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008256 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008257 assert((*images)->signature == MagickSignature);
8258 if ((*images)->debug != MagickFalse)
8259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8260 (*images)->filename);
8261 if ((argc <= 0) || (*argv == (char *) NULL))
8262 return(MagickTrue);
8263 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8264 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008265 status=0;
anthonye9c27192011-03-27 08:07:06 +00008266
anthonyce2716b2011-04-22 09:51:34 +00008267#if 0
cristy1e604812011-05-19 18:07:50 +00008268 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8269 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008270#endif
8271
anthonye9c27192011-03-27 08:07:06 +00008272 /*
8273 Pre-process multi-image sequence operators
8274 */
cristy3ed852e2009-09-05 21:47:34 +00008275 if (post == MagickFalse)
8276 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008277 /*
8278 For each image, process simple single image operators
8279 */
8280 i=0;
8281 n=GetImageListLength(*images);
8282 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008283 {
anthonyce2716b2011-04-22 09:51:34 +00008284#if 0
cristy1e604812011-05-19 18:07:50 +00008285 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8286 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008287#endif
anthonye9c27192011-03-27 08:07:06 +00008288 status&=MogrifyImage(image_info,argc,argv,images,exception);
8289 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008290 if (proceed == MagickFalse)
8291 break;
anthonye9c27192011-03-27 08:07:06 +00008292 if ( (*images)->next == (Image *) NULL )
8293 break;
8294 *images=(*images)->next;
8295 i++;
cristy3ed852e2009-09-05 21:47:34 +00008296 }
anthonye9c27192011-03-27 08:07:06 +00008297 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008298#if 0
cristy1e604812011-05-19 18:07:50 +00008299 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8300 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008301#endif
anthonye9c27192011-03-27 08:07:06 +00008302
8303 /*
8304 Post-process, multi-image sequence operators
8305 */
8306 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008307 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008308 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008309 return(status != 0 ? MagickTrue : MagickFalse);
8310}