blob: aa29b8914602e65874d2cef1dbd1542f16798560 [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);
800 (void) AutoGammaImageChannel(*image,channel);
801 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);
809 (void) AutoLevelImageChannel(*image,channel);
810 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;
950 (void) BrightnessContrastImageChannel(*image,channel,brightness,
951 contrast);
952 InheritException(exception,&(*image)->exception);
953 break;
954 }
955 break;
956 }
957 case 'c':
958 {
959 if (LocaleCompare("cdl",option+1) == 0)
960 {
961 char
962 *color_correction_collection;
963
964 /*
965 Color correct with a color decision list.
966 */
967 (void) SyncImageSettings(mogrify_info,*image);
968 color_correction_collection=FileToString(argv[i+1],~0,exception);
969 if (color_correction_collection == (char *) NULL)
970 break;
971 (void) ColorDecisionListImage(*image,color_correction_collection);
972 InheritException(exception,&(*image)->exception);
973 break;
974 }
975 if (LocaleCompare("channel",option+1) == 0)
976 {
977 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000978 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000979 else
cristyfa806a72011-07-04 02:06:13 +0000980 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristy8a9106f2011-07-05 14:39:26 +0000981 SetPixelComponentMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000982 break;
983 }
984 if (LocaleCompare("charcoal",option+1) == 0)
985 {
986 /*
987 Charcoal image.
988 */
989 (void) SyncImageSettings(mogrify_info,*image);
990 flags=ParseGeometry(argv[i+1],&geometry_info);
991 if ((flags & SigmaValue) == 0)
992 geometry_info.sigma=1.0;
993 mogrify_image=CharcoalImage(*image,geometry_info.rho,
994 geometry_info.sigma,exception);
995 break;
996 }
997 if (LocaleCompare("chop",option+1) == 0)
998 {
999 /*
1000 Chop the image.
1001 */
1002 (void) SyncImageSettings(mogrify_info,*image);
1003 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1004 mogrify_image=ChopImage(*image,&geometry,exception);
1005 break;
1006 }
1007 if (LocaleCompare("clamp",option+1) == 0)
1008 {
1009 /*
1010 Clamp image.
1011 */
1012 (void) SyncImageSettings(mogrify_info,*image);
1013 (void) ClampImageChannel(*image,channel);
1014 InheritException(exception,&(*image)->exception);
1015 break;
1016 }
1017 if (LocaleCompare("clip",option+1) == 0)
1018 {
1019 (void) SyncImageSettings(mogrify_info,*image);
1020 if (*option == '+')
1021 {
1022 (void) SetImageClipMask(*image,(Image *) NULL);
1023 InheritException(exception,&(*image)->exception);
1024 break;
1025 }
1026 (void) ClipImage(*image);
1027 InheritException(exception,&(*image)->exception);
1028 break;
1029 }
1030 if (LocaleCompare("clip-mask",option+1) == 0)
1031 {
1032 CacheView
1033 *mask_view;
1034
1035 Image
1036 *mask_image;
1037
cristy4c08aed2011-07-01 19:47:50 +00001038 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001039 *restrict q;
1040
1041 register ssize_t
1042 x;
1043
1044 ssize_t
1045 y;
1046
1047 (void) SyncImageSettings(mogrify_info,*image);
1048 if (*option == '+')
1049 {
1050 /*
1051 Remove a mask.
1052 */
1053 (void) SetImageMask(*image,(Image *) NULL);
1054 InheritException(exception,&(*image)->exception);
1055 break;
1056 }
1057 /*
1058 Set the image mask.
1059 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1060 */
1061 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1062 if (mask_image == (Image *) NULL)
1063 break;
1064 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1065 return(MagickFalse);
1066 mask_view=AcquireCacheView(mask_image);
1067 for (y=0; y < (ssize_t) mask_image->rows; y++)
1068 {
1069 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1070 exception);
cristy4c08aed2011-07-01 19:47:50 +00001071 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001072 break;
1073 for (x=0; x < (ssize_t) mask_image->columns; x++)
1074 {
1075 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001076 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1077 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1078 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1079 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
1080 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001081 }
1082 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1083 break;
1084 }
1085 mask_view=DestroyCacheView(mask_view);
1086 mask_image->matte=MagickTrue;
1087 (void) SetImageClipMask(*image,mask_image);
1088 mask_image=DestroyImage(mask_image);
1089 InheritException(exception,&(*image)->exception);
1090 break;
1091 }
1092 if (LocaleCompare("clip-path",option+1) == 0)
1093 {
1094 (void) SyncImageSettings(mogrify_info,*image);
1095 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1096 MagickFalse);
1097 InheritException(exception,&(*image)->exception);
1098 break;
1099 }
1100 if (LocaleCompare("colorize",option+1) == 0)
1101 {
1102 /*
1103 Colorize the image.
1104 */
1105 (void) SyncImageSettings(mogrify_info,*image);
1106 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1107 exception);
1108 break;
1109 }
1110 if (LocaleCompare("color-matrix",option+1) == 0)
1111 {
1112 KernelInfo
1113 *kernel;
1114
1115 (void) SyncImageSettings(mogrify_info,*image);
1116 kernel=AcquireKernelInfo(argv[i+1]);
1117 if (kernel == (KernelInfo *) NULL)
1118 break;
1119 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1120 kernel=DestroyKernelInfo(kernel);
1121 break;
1122 }
1123 if (LocaleCompare("colors",option+1) == 0)
1124 {
1125 /*
1126 Reduce the number of colors in the image.
1127 */
1128 (void) SyncImageSettings(mogrify_info,*image);
1129 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1130 if (quantize_info->number_colors == 0)
1131 break;
1132 if (((*image)->storage_class == DirectClass) ||
1133 (*image)->colors > quantize_info->number_colors)
1134 (void) QuantizeImage(quantize_info,*image);
1135 else
1136 (void) CompressImageColormap(*image);
1137 InheritException(exception,&(*image)->exception);
1138 break;
1139 }
1140 if (LocaleCompare("colorspace",option+1) == 0)
1141 {
1142 ColorspaceType
1143 colorspace;
1144
1145 (void) SyncImageSettings(mogrify_info,*image);
1146 if (*option == '+')
1147 {
1148 (void) TransformImageColorspace(*image,RGBColorspace);
1149 InheritException(exception,&(*image)->exception);
1150 break;
1151 }
1152 colorspace=(ColorspaceType) ParseCommandOption(
1153 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1154 (void) TransformImageColorspace(*image,colorspace);
1155 InheritException(exception,&(*image)->exception);
1156 break;
1157 }
1158 if (LocaleCompare("contrast",option+1) == 0)
1159 {
1160 (void) SyncImageSettings(mogrify_info,*image);
1161 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1162 MagickFalse);
1163 InheritException(exception,&(*image)->exception);
1164 break;
1165 }
1166 if (LocaleCompare("contrast-stretch",option+1) == 0)
1167 {
1168 double
1169 black_point,
1170 white_point;
1171
1172 MagickStatusType
1173 flags;
1174
1175 /*
1176 Contrast stretch image.
1177 */
1178 (void) SyncImageSettings(mogrify_info,*image);
1179 flags=ParseGeometry(argv[i+1],&geometry_info);
1180 black_point=geometry_info.rho;
1181 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1182 black_point;
1183 if ((flags & PercentValue) != 0)
1184 {
1185 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1186 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1187 }
1188 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1189 white_point;
1190 (void) ContrastStretchImageChannel(*image,channel,black_point,
1191 white_point);
1192 InheritException(exception,&(*image)->exception);
1193 break;
1194 }
1195 if (LocaleCompare("convolve",option+1) == 0)
1196 {
1197 double
1198 gamma;
1199
1200 KernelInfo
1201 *kernel;
1202
1203 register ssize_t
1204 j;
1205
1206 (void) SyncImageSettings(mogrify_info,*image);
1207 kernel=AcquireKernelInfo(argv[i+1]);
1208 if (kernel == (KernelInfo *) NULL)
1209 break;
1210 gamma=0.0;
1211 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1212 gamma+=kernel->values[j];
1213 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1214 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1215 kernel->values[j]*=gamma;
1216 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
1217 kernel=DestroyKernelInfo(kernel);
1218 break;
1219 }
1220 if (LocaleCompare("crop",option+1) == 0)
1221 {
1222 /*
1223 Crop a image to a smaller size
1224 */
1225 (void) SyncImageSettings(mogrify_info,*image);
1226#if 0
1227 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1228 if (((geometry.width != 0) || (geometry.height != 0)) &&
1229 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1230 break;
1231#endif
1232#if 0
1233 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1234 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1235 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1236 InheritException(exception,&mogrify_image->exception);
1237#else
1238 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1239#endif
1240 break;
1241 }
1242 if (LocaleCompare("cycle",option+1) == 0)
1243 {
1244 /*
1245 Cycle an image colormap.
1246 */
1247 (void) SyncImageSettings(mogrify_info,*image);
1248 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1249 InheritException(exception,&(*image)->exception);
1250 break;
1251 }
1252 break;
1253 }
1254 case 'd':
1255 {
1256 if (LocaleCompare("decipher",option+1) == 0)
1257 {
1258 StringInfo
1259 *passkey;
1260
1261 /*
1262 Decipher pixels.
1263 */
1264 (void) SyncImageSettings(mogrify_info,*image);
1265 passkey=FileToStringInfo(argv[i+1],~0,exception);
1266 if (passkey != (StringInfo *) NULL)
1267 {
1268 (void) PasskeyDecipherImage(*image,passkey,exception);
1269 passkey=DestroyStringInfo(passkey);
1270 }
1271 break;
1272 }
1273 if (LocaleCompare("density",option+1) == 0)
1274 {
1275 /*
1276 Set image density.
1277 */
1278 (void) CloneString(&draw_info->density,argv[i+1]);
1279 break;
1280 }
1281 if (LocaleCompare("depth",option+1) == 0)
1282 {
1283 (void) SyncImageSettings(mogrify_info,*image);
1284 if (*option == '+')
1285 {
1286 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1287 break;
1288 }
1289 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1290 break;
1291 }
1292 if (LocaleCompare("deskew",option+1) == 0)
1293 {
1294 double
1295 threshold;
1296
1297 /*
1298 Straighten the image.
1299 */
1300 (void) SyncImageSettings(mogrify_info,*image);
1301 if (*option == '+')
1302 threshold=40.0*QuantumRange/100.0;
1303 else
1304 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1305 mogrify_image=DeskewImage(*image,threshold,exception);
1306 break;
1307 }
1308 if (LocaleCompare("despeckle",option+1) == 0)
1309 {
1310 /*
1311 Reduce the speckles within an image.
1312 */
1313 (void) SyncImageSettings(mogrify_info,*image);
1314 mogrify_image=DespeckleImage(*image,exception);
1315 break;
1316 }
1317 if (LocaleCompare("display",option+1) == 0)
1318 {
1319 (void) CloneString(&draw_info->server_name,argv[i+1]);
1320 break;
1321 }
1322 if (LocaleCompare("distort",option+1) == 0)
1323 {
1324 char
1325 *args,
1326 token[MaxTextExtent];
1327
1328 const char
1329 *p;
1330
1331 DistortImageMethod
1332 method;
1333
1334 double
1335 *arguments;
1336
1337 register ssize_t
1338 x;
1339
1340 size_t
1341 number_arguments;
1342
1343 /*
1344 Distort image.
1345 */
1346 (void) SyncImageSettings(mogrify_info,*image);
1347 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1348 MagickFalse,argv[i+1]);
1349 if ( method == ResizeDistortion )
1350 {
1351 /* Special Case - Argument is actually a resize geometry!
1352 ** Convert that to an appropriate distortion argument array.
1353 */
1354 double
1355 resize_args[2];
1356 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1357 exception);
1358 resize_args[0]=(double)geometry.width;
1359 resize_args[1]=(double)geometry.height;
1360 mogrify_image=DistortImage(*image,method,(size_t)2,
1361 resize_args,MagickTrue,exception);
1362 break;
1363 }
1364 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1365 InheritException(exception,&(*image)->exception);
1366 if (args == (char *) NULL)
1367 break;
1368 p=(char *) args;
1369 for (x=0; *p != '\0'; x++)
1370 {
1371 GetMagickToken(p,&p,token);
1372 if (*token == ',')
1373 GetMagickToken(p,&p,token);
1374 }
1375 number_arguments=(size_t) x;
1376 arguments=(double *) AcquireQuantumMemory(number_arguments,
1377 sizeof(*arguments));
1378 if (arguments == (double *) NULL)
1379 ThrowWandFatalException(ResourceLimitFatalError,
1380 "MemoryAllocationFailed",(*image)->filename);
1381 (void) ResetMagickMemory(arguments,0,number_arguments*
1382 sizeof(*arguments));
1383 p=(char *) args;
1384 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1385 {
1386 GetMagickToken(p,&p,token);
1387 if (*token == ',')
1388 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001389 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001390 }
1391 args=DestroyString(args);
1392 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1393 (*option == '+') ? MagickTrue : MagickFalse,exception);
1394 arguments=(double *) RelinquishMagickMemory(arguments);
1395 break;
1396 }
1397 if (LocaleCompare("dither",option+1) == 0)
1398 {
1399 if (*option == '+')
1400 {
1401 quantize_info->dither=MagickFalse;
1402 break;
1403 }
1404 quantize_info->dither=MagickTrue;
1405 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1406 MagickDitherOptions,MagickFalse,argv[i+1]);
1407 if (quantize_info->dither_method == NoDitherMethod)
1408 quantize_info->dither=MagickFalse;
1409 break;
1410 }
1411 if (LocaleCompare("draw",option+1) == 0)
1412 {
1413 /*
1414 Draw image.
1415 */
1416 (void) SyncImageSettings(mogrify_info,*image);
1417 (void) CloneString(&draw_info->primitive,argv[i+1]);
1418 (void) DrawImage(*image,draw_info);
1419 InheritException(exception,&(*image)->exception);
1420 break;
1421 }
1422 break;
1423 }
1424 case 'e':
1425 {
1426 if (LocaleCompare("edge",option+1) == 0)
1427 {
1428 /*
1429 Enhance edges in the image.
1430 */
1431 (void) SyncImageSettings(mogrify_info,*image);
1432 flags=ParseGeometry(argv[i+1],&geometry_info);
1433 if ((flags & SigmaValue) == 0)
1434 geometry_info.sigma=1.0;
1435 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1436 break;
1437 }
1438 if (LocaleCompare("emboss",option+1) == 0)
1439 {
1440 /*
1441 Gaussian embossen image.
1442 */
1443 (void) SyncImageSettings(mogrify_info,*image);
1444 flags=ParseGeometry(argv[i+1],&geometry_info);
1445 if ((flags & SigmaValue) == 0)
1446 geometry_info.sigma=1.0;
1447 mogrify_image=EmbossImage(*image,geometry_info.rho,
1448 geometry_info.sigma,exception);
1449 break;
1450 }
1451 if (LocaleCompare("encipher",option+1) == 0)
1452 {
1453 StringInfo
1454 *passkey;
1455
1456 /*
1457 Encipher pixels.
1458 */
1459 (void) SyncImageSettings(mogrify_info,*image);
1460 passkey=FileToStringInfo(argv[i+1],~0,exception);
1461 if (passkey != (StringInfo *) NULL)
1462 {
1463 (void) PasskeyEncipherImage(*image,passkey,exception);
1464 passkey=DestroyStringInfo(passkey);
1465 }
1466 break;
1467 }
1468 if (LocaleCompare("encoding",option+1) == 0)
1469 {
1470 (void) CloneString(&draw_info->encoding,argv[i+1]);
1471 break;
1472 }
1473 if (LocaleCompare("enhance",option+1) == 0)
1474 {
1475 /*
1476 Enhance image.
1477 */
1478 (void) SyncImageSettings(mogrify_info,*image);
1479 mogrify_image=EnhanceImage(*image,exception);
1480 break;
1481 }
1482 if (LocaleCompare("equalize",option+1) == 0)
1483 {
1484 /*
1485 Equalize image.
1486 */
1487 (void) SyncImageSettings(mogrify_info,*image);
1488 (void) EqualizeImageChannel(*image,channel);
1489 InheritException(exception,&(*image)->exception);
1490 break;
1491 }
1492 if (LocaleCompare("evaluate",option+1) == 0)
1493 {
1494 double
1495 constant;
1496
1497 MagickEvaluateOperator
1498 op;
1499
1500 (void) SyncImageSettings(mogrify_info,*image);
1501 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
1502 MagickFalse,argv[i+1]);
1503 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
1504 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1505 break;
1506 }
1507 if (LocaleCompare("extent",option+1) == 0)
1508 {
1509 /*
1510 Set the image extent.
1511 */
1512 (void) SyncImageSettings(mogrify_info,*image);
1513 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1514 if (geometry.width == 0)
1515 geometry.width=(*image)->columns;
1516 if (geometry.height == 0)
1517 geometry.height=(*image)->rows;
1518 mogrify_image=ExtentImage(*image,&geometry,exception);
1519 break;
1520 }
1521 break;
1522 }
1523 case 'f':
1524 {
1525 if (LocaleCompare("family",option+1) == 0)
1526 {
1527 if (*option == '+')
1528 {
1529 if (draw_info->family != (char *) NULL)
1530 draw_info->family=DestroyString(draw_info->family);
1531 break;
1532 }
1533 (void) CloneString(&draw_info->family,argv[i+1]);
1534 break;
1535 }
1536 if (LocaleCompare("features",option+1) == 0)
1537 {
1538 if (*option == '+')
1539 {
1540 (void) DeleteImageArtifact(*image,"identify:features");
1541 break;
1542 }
1543 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1544 break;
1545 }
1546 if (LocaleCompare("fill",option+1) == 0)
1547 {
1548 ExceptionInfo
1549 *sans;
1550
cristy4c08aed2011-07-01 19:47:50 +00001551 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001552 if (*option == '+')
1553 {
1554 (void) QueryMagickColor("none",&fill,exception);
1555 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1556 if (draw_info->fill_pattern != (Image *) NULL)
1557 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1558 break;
1559 }
1560 sans=AcquireExceptionInfo();
1561 (void) QueryMagickColor(argv[i+1],&fill,sans);
1562 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1563 sans=DestroyExceptionInfo(sans);
1564 if (status == MagickFalse)
1565 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1566 exception);
1567 break;
1568 }
1569 if (LocaleCompare("flip",option+1) == 0)
1570 {
1571 /*
1572 Flip image scanlines.
1573 */
1574 (void) SyncImageSettings(mogrify_info,*image);
1575 mogrify_image=FlipImage(*image,exception);
1576 break;
1577 }
anthonydf8ebac2011-04-27 09:03:19 +00001578 if (LocaleCompare("floodfill",option+1) == 0)
1579 {
cristy4c08aed2011-07-01 19:47:50 +00001580 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001581 target;
1582
1583 /*
1584 Floodfill image.
1585 */
1586 (void) SyncImageSettings(mogrify_info,*image);
1587 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1588 (void) QueryMagickColor(argv[i+2],&target,exception);
1589 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1590 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1591 InheritException(exception,&(*image)->exception);
1592 break;
1593 }
anthony3d2f4862011-05-01 13:48:16 +00001594 if (LocaleCompare("flop",option+1) == 0)
1595 {
1596 /*
1597 Flop image scanlines.
1598 */
1599 (void) SyncImageSettings(mogrify_info,*image);
1600 mogrify_image=FlopImage(*image,exception);
1601 break;
1602 }
anthonydf8ebac2011-04-27 09:03:19 +00001603 if (LocaleCompare("font",option+1) == 0)
1604 {
1605 if (*option == '+')
1606 {
1607 if (draw_info->font != (char *) NULL)
1608 draw_info->font=DestroyString(draw_info->font);
1609 break;
1610 }
1611 (void) CloneString(&draw_info->font,argv[i+1]);
1612 break;
1613 }
1614 if (LocaleCompare("format",option+1) == 0)
1615 {
1616 format=argv[i+1];
1617 break;
1618 }
1619 if (LocaleCompare("frame",option+1) == 0)
1620 {
1621 FrameInfo
1622 frame_info;
1623
1624 /*
1625 Surround image with an ornamental border.
1626 */
1627 (void) SyncImageSettings(mogrify_info,*image);
1628 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1629 frame_info.width=geometry.width;
1630 frame_info.height=geometry.height;
1631 if ((flags & HeightValue) == 0)
1632 frame_info.height=geometry.width;
1633 frame_info.outer_bevel=geometry.x;
1634 frame_info.inner_bevel=geometry.y;
1635 frame_info.x=(ssize_t) frame_info.width;
1636 frame_info.y=(ssize_t) frame_info.height;
1637 frame_info.width=(*image)->columns+2*frame_info.width;
1638 frame_info.height=(*image)->rows+2*frame_info.height;
1639 mogrify_image=FrameImage(*image,&frame_info,exception);
1640 break;
1641 }
1642 if (LocaleCompare("function",option+1) == 0)
1643 {
1644 char
1645 *arguments,
1646 token[MaxTextExtent];
1647
1648 const char
1649 *p;
1650
1651 double
1652 *parameters;
1653
1654 MagickFunction
1655 function;
1656
1657 register ssize_t
1658 x;
1659
1660 size_t
1661 number_parameters;
1662
1663 /*
1664 Function Modify Image Values
1665 */
1666 (void) SyncImageSettings(mogrify_info,*image);
1667 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1668 MagickFalse,argv[i+1]);
1669 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1670 InheritException(exception,&(*image)->exception);
1671 if (arguments == (char *) NULL)
1672 break;
1673 p=(char *) arguments;
1674 for (x=0; *p != '\0'; x++)
1675 {
1676 GetMagickToken(p,&p,token);
1677 if (*token == ',')
1678 GetMagickToken(p,&p,token);
1679 }
1680 number_parameters=(size_t) x;
1681 parameters=(double *) AcquireQuantumMemory(number_parameters,
1682 sizeof(*parameters));
1683 if (parameters == (double *) NULL)
1684 ThrowWandFatalException(ResourceLimitFatalError,
1685 "MemoryAllocationFailed",(*image)->filename);
1686 (void) ResetMagickMemory(parameters,0,number_parameters*
1687 sizeof(*parameters));
1688 p=(char *) arguments;
1689 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1690 {
1691 GetMagickToken(p,&p,token);
1692 if (*token == ',')
1693 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001694 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001695 }
1696 arguments=DestroyString(arguments);
1697 (void) FunctionImageChannel(*image,channel,function,
1698 number_parameters,parameters,exception);
1699 parameters=(double *) RelinquishMagickMemory(parameters);
1700 break;
1701 }
1702 break;
1703 }
1704 case 'g':
1705 {
1706 if (LocaleCompare("gamma",option+1) == 0)
1707 {
1708 /*
1709 Gamma image.
1710 */
1711 (void) SyncImageSettings(mogrify_info,*image);
1712 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001713 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001714 else
1715 {
1716 if (strchr(argv[i+1],',') != (char *) NULL)
1717 (void) GammaImage(*image,argv[i+1]);
1718 else
1719 (void) GammaImageChannel(*image,channel,
cristyc1acd842011-05-19 23:05:47 +00001720 InterpretLocaleValue(argv[i+1],(char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001721 InheritException(exception,&(*image)->exception);
1722 }
1723 break;
1724 }
1725 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1726 (LocaleCompare("gaussian",option+1) == 0))
1727 {
1728 /*
1729 Gaussian blur image.
1730 */
1731 (void) SyncImageSettings(mogrify_info,*image);
1732 flags=ParseGeometry(argv[i+1],&geometry_info);
1733 if ((flags & SigmaValue) == 0)
1734 geometry_info.sigma=1.0;
1735 mogrify_image=GaussianBlurImageChannel(*image,channel,
1736 geometry_info.rho,geometry_info.sigma,exception);
1737 break;
1738 }
1739 if (LocaleCompare("geometry",option+1) == 0)
1740 {
1741 /*
1742 Record Image offset, Resize last image.
1743 */
1744 (void) SyncImageSettings(mogrify_info,*image);
1745 if (*option == '+')
1746 {
1747 if ((*image)->geometry != (char *) NULL)
1748 (*image)->geometry=DestroyString((*image)->geometry);
1749 break;
1750 }
1751 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1752 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1753 (void) CloneString(&(*image)->geometry,argv[i+1]);
1754 else
1755 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1756 (*image)->filter,(*image)->blur,exception);
1757 break;
1758 }
1759 if (LocaleCompare("gravity",option+1) == 0)
1760 {
1761 if (*option == '+')
1762 {
1763 draw_info->gravity=UndefinedGravity;
1764 break;
1765 }
1766 draw_info->gravity=(GravityType) ParseCommandOption(
1767 MagickGravityOptions,MagickFalse,argv[i+1]);
1768 break;
1769 }
1770 break;
1771 }
1772 case 'h':
1773 {
1774 if (LocaleCompare("highlight-color",option+1) == 0)
1775 {
1776 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1777 break;
1778 }
1779 break;
1780 }
1781 case 'i':
1782 {
1783 if (LocaleCompare("identify",option+1) == 0)
1784 {
1785 char
1786 *text;
1787
1788 (void) SyncImageSettings(mogrify_info,*image);
1789 if (format == (char *) NULL)
1790 {
1791 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1792 InheritException(exception,&(*image)->exception);
1793 break;
1794 }
1795 text=InterpretImageProperties(mogrify_info,*image,format);
1796 InheritException(exception,&(*image)->exception);
1797 if (text == (char *) NULL)
1798 break;
1799 (void) fputs(text,stdout);
1800 (void) fputc('\n',stdout);
1801 text=DestroyString(text);
1802 break;
1803 }
1804 if (LocaleCompare("implode",option+1) == 0)
1805 {
1806 /*
1807 Implode image.
1808 */
1809 (void) SyncImageSettings(mogrify_info,*image);
1810 (void) ParseGeometry(argv[i+1],&geometry_info);
1811 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1812 break;
1813 }
1814 if (LocaleCompare("interline-spacing",option+1) == 0)
1815 {
1816 if (*option == '+')
1817 (void) ParseGeometry("0",&geometry_info);
1818 else
1819 (void) ParseGeometry(argv[i+1],&geometry_info);
1820 draw_info->interline_spacing=geometry_info.rho;
1821 break;
1822 }
1823 if (LocaleCompare("interword-spacing",option+1) == 0)
1824 {
1825 if (*option == '+')
1826 (void) ParseGeometry("0",&geometry_info);
1827 else
1828 (void) ParseGeometry(argv[i+1],&geometry_info);
1829 draw_info->interword_spacing=geometry_info.rho;
1830 break;
1831 }
1832 break;
1833 }
1834 case 'k':
1835 {
1836 if (LocaleCompare("kerning",option+1) == 0)
1837 {
1838 if (*option == '+')
1839 (void) ParseGeometry("0",&geometry_info);
1840 else
1841 (void) ParseGeometry(argv[i+1],&geometry_info);
1842 draw_info->kerning=geometry_info.rho;
1843 break;
1844 }
1845 break;
1846 }
1847 case 'l':
1848 {
1849 if (LocaleCompare("lat",option+1) == 0)
1850 {
1851 /*
1852 Local adaptive threshold image.
1853 */
1854 (void) SyncImageSettings(mogrify_info,*image);
1855 flags=ParseGeometry(argv[i+1],&geometry_info);
1856 if ((flags & PercentValue) != 0)
1857 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1858 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1859 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1860 geometry_info.xi,exception);
1861 break;
1862 }
1863 if (LocaleCompare("level",option+1) == 0)
1864 {
1865 MagickRealType
1866 black_point,
1867 gamma,
1868 white_point;
1869
1870 MagickStatusType
1871 flags;
1872
1873 /*
1874 Parse levels.
1875 */
1876 (void) SyncImageSettings(mogrify_info,*image);
1877 flags=ParseGeometry(argv[i+1],&geometry_info);
1878 black_point=geometry_info.rho;
1879 white_point=(MagickRealType) QuantumRange;
1880 if ((flags & SigmaValue) != 0)
1881 white_point=geometry_info.sigma;
1882 gamma=1.0;
1883 if ((flags & XiValue) != 0)
1884 gamma=geometry_info.xi;
1885 if ((flags & PercentValue) != 0)
1886 {
1887 black_point*=(MagickRealType) (QuantumRange/100.0);
1888 white_point*=(MagickRealType) (QuantumRange/100.0);
1889 }
1890 if ((flags & SigmaValue) == 0)
1891 white_point=(MagickRealType) QuantumRange-black_point;
1892 if ((*option == '+') || ((flags & AspectValue) != 0))
1893 (void) LevelizeImageChannel(*image,channel,black_point,
1894 white_point,gamma);
1895 else
1896 (void) LevelImageChannel(*image,channel,black_point,white_point,
1897 gamma);
1898 InheritException(exception,&(*image)->exception);
1899 break;
1900 }
1901 if (LocaleCompare("level-colors",option+1) == 0)
1902 {
1903 char
1904 token[MaxTextExtent];
1905
1906 const char
1907 *p;
1908
cristy4c08aed2011-07-01 19:47:50 +00001909 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001910 black_point,
1911 white_point;
1912
1913 p=(const char *) argv[i+1];
1914 GetMagickToken(p,&p,token); /* get black point color */
1915 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1916 (void) QueryMagickColor(token,&black_point,exception);
1917 else
1918 (void) QueryMagickColor("#000000",&black_point,exception);
1919 if (isalpha((int) token[0]) || (token[0] == '#'))
1920 GetMagickToken(p,&p,token);
1921 if (*token == '\0')
1922 white_point=black_point; /* set everything to that color */
1923 else
1924 {
1925 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1926 GetMagickToken(p,&p,token); /* Get white point color. */
1927 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1928 (void) QueryMagickColor(token,&white_point,exception);
1929 else
1930 (void) QueryMagickColor("#ffffff",&white_point,exception);
1931 }
1932 (void) LevelColorsImageChannel(*image,channel,&black_point,
1933 &white_point,*option == '+' ? MagickTrue : MagickFalse);
1934 break;
1935 }
1936 if (LocaleCompare("linear-stretch",option+1) == 0)
1937 {
1938 double
1939 black_point,
1940 white_point;
1941
1942 MagickStatusType
1943 flags;
1944
1945 (void) SyncImageSettings(mogrify_info,*image);
1946 flags=ParseGeometry(argv[i+1],&geometry_info);
1947 black_point=geometry_info.rho;
1948 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1949 if ((flags & SigmaValue) != 0)
1950 white_point=geometry_info.sigma;
1951 if ((flags & PercentValue) != 0)
1952 {
1953 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1954 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1955 }
1956 if ((flags & SigmaValue) == 0)
1957 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1958 black_point;
1959 (void) LinearStretchImage(*image,black_point,white_point);
1960 InheritException(exception,&(*image)->exception);
1961 break;
1962 }
1963 if (LocaleCompare("linewidth",option+1) == 0)
1964 {
cristyc1acd842011-05-19 23:05:47 +00001965 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1966 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001967 break;
1968 }
1969 if (LocaleCompare("liquid-rescale",option+1) == 0)
1970 {
1971 /*
1972 Liquid rescale image.
1973 */
1974 (void) SyncImageSettings(mogrify_info,*image);
1975 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1976 if ((flags & XValue) == 0)
1977 geometry.x=1;
1978 if ((flags & YValue) == 0)
1979 geometry.y=0;
1980 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1981 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1982 break;
1983 }
1984 if (LocaleCompare("lowlight-color",option+1) == 0)
1985 {
1986 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1987 break;
1988 }
1989 break;
1990 }
1991 case 'm':
1992 {
1993 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001994 {
cristy3ed852e2009-09-05 21:47:34 +00001995 Image
anthonydf8ebac2011-04-27 09:03:19 +00001996 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001997
anthonydf8ebac2011-04-27 09:03:19 +00001998 /*
1999 Transform image colors to match this set of colors.
2000 */
2001 (void) SyncImageSettings(mogrify_info,*image);
2002 if (*option == '+')
2003 break;
2004 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2005 if (remap_image == (Image *) NULL)
2006 break;
2007 (void) RemapImage(quantize_info,*image,remap_image);
2008 InheritException(exception,&(*image)->exception);
2009 remap_image=DestroyImage(remap_image);
2010 break;
2011 }
2012 if (LocaleCompare("mask",option+1) == 0)
2013 {
2014 Image
2015 *mask;
2016
2017 (void) SyncImageSettings(mogrify_info,*image);
2018 if (*option == '+')
2019 {
2020 /*
2021 Remove a mask.
2022 */
2023 (void) SetImageMask(*image,(Image *) NULL);
2024 InheritException(exception,&(*image)->exception);
2025 break;
2026 }
2027 /*
2028 Set the image mask.
2029 */
2030 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2031 if (mask == (Image *) NULL)
2032 break;
2033 (void) SetImageMask(*image,mask);
2034 mask=DestroyImage(mask);
2035 InheritException(exception,&(*image)->exception);
2036 break;
2037 }
2038 if (LocaleCompare("matte",option+1) == 0)
2039 {
2040 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2041 SetAlphaChannel : DeactivateAlphaChannel );
2042 InheritException(exception,&(*image)->exception);
2043 break;
2044 }
2045 if (LocaleCompare("median",option+1) == 0)
2046 {
2047 /*
2048 Median filter image.
2049 */
2050 (void) SyncImageSettings(mogrify_info,*image);
2051 (void) ParseGeometry(argv[i+1],&geometry_info);
2052 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
2053 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2054 break;
2055 }
2056 if (LocaleCompare("mode",option+1) == 0)
2057 {
2058 /*
2059 Mode image.
2060 */
2061 (void) SyncImageSettings(mogrify_info,*image);
2062 (void) ParseGeometry(argv[i+1],&geometry_info);
2063 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
2064 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2065 break;
2066 }
2067 if (LocaleCompare("modulate",option+1) == 0)
2068 {
2069 (void) SyncImageSettings(mogrify_info,*image);
2070 (void) ModulateImage(*image,argv[i+1]);
2071 InheritException(exception,&(*image)->exception);
2072 break;
2073 }
2074 if (LocaleCompare("monitor",option+1) == 0)
2075 {
2076 if (*option == '+')
2077 {
2078 (void) SetImageProgressMonitor(*image,
2079 (MagickProgressMonitor) NULL,(void *) NULL);
2080 break;
2081 }
2082 (void) SetImageProgressMonitor(*image,MonitorProgress,
2083 (void *) NULL);
2084 break;
2085 }
2086 if (LocaleCompare("monochrome",option+1) == 0)
2087 {
2088 (void) SyncImageSettings(mogrify_info,*image);
2089 (void) SetImageType(*image,BilevelType);
2090 InheritException(exception,&(*image)->exception);
2091 break;
2092 }
2093 if (LocaleCompare("morphology",option+1) == 0)
2094 {
2095 char
2096 token[MaxTextExtent];
2097
2098 const char
2099 *p;
2100
2101 KernelInfo
2102 *kernel;
2103
2104 MorphologyMethod
2105 method;
2106
2107 ssize_t
2108 iterations;
2109
2110 /*
2111 Morphological Image Operation
2112 */
2113 (void) SyncImageSettings(mogrify_info,*image);
2114 p=argv[i+1];
2115 GetMagickToken(p,&p,token);
2116 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2117 MagickFalse,token);
2118 iterations=1L;
2119 GetMagickToken(p,&p,token);
2120 if ((*p == ':') || (*p == ','))
2121 GetMagickToken(p,&p,token);
2122 if ((*p != '\0'))
2123 iterations=(ssize_t) StringToLong(p);
2124 kernel=AcquireKernelInfo(argv[i+2]);
2125 if (kernel == (KernelInfo *) NULL)
2126 {
2127 (void) ThrowMagickException(exception,GetMagickModule(),
2128 OptionError,"UnabletoParseKernel","morphology");
2129 status=MagickFalse;
2130 break;
2131 }
2132 mogrify_image=MorphologyImageChannel(*image,channel,method,
2133 iterations,kernel,exception);
2134 kernel=DestroyKernelInfo(kernel);
2135 break;
2136 }
2137 if (LocaleCompare("motion-blur",option+1) == 0)
2138 {
2139 /*
2140 Motion blur image.
2141 */
2142 (void) SyncImageSettings(mogrify_info,*image);
2143 flags=ParseGeometry(argv[i+1],&geometry_info);
2144 if ((flags & SigmaValue) == 0)
2145 geometry_info.sigma=1.0;
2146 mogrify_image=MotionBlurImageChannel(*image,channel,
2147 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2148 break;
2149 }
2150 break;
2151 }
2152 case 'n':
2153 {
2154 if (LocaleCompare("negate",option+1) == 0)
2155 {
2156 (void) SyncImageSettings(mogrify_info,*image);
2157 (void) NegateImageChannel(*image,channel,*option == '+' ?
2158 MagickTrue : MagickFalse);
2159 InheritException(exception,&(*image)->exception);
2160 break;
2161 }
2162 if (LocaleCompare("noise",option+1) == 0)
2163 {
2164 (void) SyncImageSettings(mogrify_info,*image);
2165 if (*option == '-')
2166 {
2167 (void) ParseGeometry(argv[i+1],&geometry_info);
2168 mogrify_image=StatisticImageChannel(*image,channel,
2169 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2170 geometry_info.rho,exception);
2171 }
2172 else
2173 {
2174 NoiseType
2175 noise;
2176
2177 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2178 MagickFalse,argv[i+1]);
2179 mogrify_image=AddNoiseImageChannel(*image,channel,noise,
2180 exception);
2181 }
2182 break;
2183 }
2184 if (LocaleCompare("normalize",option+1) == 0)
2185 {
2186 (void) SyncImageSettings(mogrify_info,*image);
2187 (void) NormalizeImageChannel(*image,channel);
2188 InheritException(exception,&(*image)->exception);
2189 break;
2190 }
2191 break;
2192 }
2193 case 'o':
2194 {
2195 if (LocaleCompare("opaque",option+1) == 0)
2196 {
cristy4c08aed2011-07-01 19:47:50 +00002197 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002198 target;
2199
2200 (void) SyncImageSettings(mogrify_info,*image);
2201 (void) QueryMagickColor(argv[i+1],&target,exception);
2202 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2203 *option == '-' ? MagickFalse : MagickTrue);
2204 break;
2205 }
2206 if (LocaleCompare("ordered-dither",option+1) == 0)
2207 {
2208 (void) SyncImageSettings(mogrify_info,*image);
2209 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2210 exception);
2211 break;
2212 }
2213 break;
2214 }
2215 case 'p':
2216 {
2217 if (LocaleCompare("paint",option+1) == 0)
2218 {
anthonydf8ebac2011-04-27 09:03:19 +00002219 (void) SyncImageSettings(mogrify_info,*image);
2220 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002221 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002222 break;
2223 }
2224 if (LocaleCompare("pen",option+1) == 0)
2225 {
2226 if (*option == '+')
2227 {
2228 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2229 break;
2230 }
2231 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2232 break;
2233 }
2234 if (LocaleCompare("pointsize",option+1) == 0)
2235 {
2236 if (*option == '+')
2237 (void) ParseGeometry("12",&geometry_info);
2238 else
2239 (void) ParseGeometry(argv[i+1],&geometry_info);
2240 draw_info->pointsize=geometry_info.rho;
2241 break;
2242 }
2243 if (LocaleCompare("polaroid",option+1) == 0)
2244 {
2245 double
2246 angle;
2247
2248 RandomInfo
2249 *random_info;
2250
2251 /*
2252 Simulate a Polaroid picture.
2253 */
2254 (void) SyncImageSettings(mogrify_info,*image);
2255 random_info=AcquireRandomInfo();
2256 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2257 random_info=DestroyRandomInfo(random_info);
2258 if (*option == '-')
2259 {
2260 SetGeometryInfo(&geometry_info);
2261 flags=ParseGeometry(argv[i+1],&geometry_info);
2262 angle=geometry_info.rho;
2263 }
2264 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2265 break;
2266 }
2267 if (LocaleCompare("posterize",option+1) == 0)
2268 {
2269 /*
2270 Posterize image.
2271 */
2272 (void) SyncImageSettings(mogrify_info,*image);
2273 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2274 quantize_info->dither);
2275 InheritException(exception,&(*image)->exception);
2276 break;
2277 }
2278 if (LocaleCompare("preview",option+1) == 0)
2279 {
2280 PreviewType
2281 preview_type;
2282
2283 /*
2284 Preview image.
2285 */
2286 (void) SyncImageSettings(mogrify_info,*image);
2287 if (*option == '+')
2288 preview_type=UndefinedPreview;
2289 else
2290 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2291 MagickFalse,argv[i+1]);
2292 mogrify_image=PreviewImage(*image,preview_type,exception);
2293 break;
2294 }
2295 if (LocaleCompare("profile",option+1) == 0)
2296 {
2297 const char
2298 *name;
2299
2300 const StringInfo
2301 *profile;
2302
2303 Image
2304 *profile_image;
2305
2306 ImageInfo
2307 *profile_info;
2308
2309 (void) SyncImageSettings(mogrify_info,*image);
2310 if (*option == '+')
2311 {
2312 /*
2313 Remove a profile from the image.
2314 */
2315 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2316 NULL,0,MagickTrue);
2317 InheritException(exception,&(*image)->exception);
2318 break;
2319 }
2320 /*
2321 Associate a profile with the image.
2322 */
2323 profile_info=CloneImageInfo(mogrify_info);
2324 profile=GetImageProfile(*image,"iptc");
2325 if (profile != (StringInfo *) NULL)
2326 profile_info->profile=(void *) CloneStringInfo(profile);
2327 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2328 profile_info=DestroyImageInfo(profile_info);
2329 if (profile_image == (Image *) NULL)
2330 {
2331 StringInfo
2332 *profile;
2333
2334 profile_info=CloneImageInfo(mogrify_info);
2335 (void) CopyMagickString(profile_info->filename,argv[i+1],
2336 MaxTextExtent);
2337 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2338 if (profile != (StringInfo *) NULL)
2339 {
2340 (void) ProfileImage(*image,profile_info->magick,
2341 GetStringInfoDatum(profile),(size_t)
2342 GetStringInfoLength(profile),MagickFalse);
2343 profile=DestroyStringInfo(profile);
2344 }
2345 profile_info=DestroyImageInfo(profile_info);
2346 break;
2347 }
2348 ResetImageProfileIterator(profile_image);
2349 name=GetNextImageProfile(profile_image);
2350 while (name != (const char *) NULL)
2351 {
2352 profile=GetImageProfile(profile_image,name);
2353 if (profile != (StringInfo *) NULL)
2354 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2355 (size_t) GetStringInfoLength(profile),MagickFalse);
2356 name=GetNextImageProfile(profile_image);
2357 }
2358 profile_image=DestroyImage(profile_image);
2359 break;
2360 }
2361 break;
2362 }
2363 case 'q':
2364 {
2365 if (LocaleCompare("quantize",option+1) == 0)
2366 {
2367 if (*option == '+')
2368 {
2369 quantize_info->colorspace=UndefinedColorspace;
2370 break;
2371 }
2372 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2373 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2374 break;
2375 }
2376 break;
2377 }
2378 case 'r':
2379 {
2380 if (LocaleCompare("radial-blur",option+1) == 0)
2381 {
2382 /*
2383 Radial blur image.
2384 */
2385 (void) SyncImageSettings(mogrify_info,*image);
2386 mogrify_image=RadialBlurImageChannel(*image,channel,
cristyc1acd842011-05-19 23:05:47 +00002387 InterpretLocaleValue(argv[i+1],(char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002388 break;
2389 }
2390 if (LocaleCompare("raise",option+1) == 0)
2391 {
2392 /*
2393 Surround image with a raise of solid color.
2394 */
2395 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2396 if ((flags & SigmaValue) == 0)
2397 geometry.height=geometry.width;
2398 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2399 MagickFalse);
2400 InheritException(exception,&(*image)->exception);
2401 break;
2402 }
2403 if (LocaleCompare("random-threshold",option+1) == 0)
2404 {
2405 /*
2406 Threshold image.
2407 */
2408 (void) SyncImageSettings(mogrify_info,*image);
2409 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2410 exception);
2411 break;
2412 }
2413 if (LocaleCompare("recolor",option+1) == 0)
2414 {
2415 KernelInfo
2416 *kernel;
2417
2418 (void) SyncImageSettings(mogrify_info,*image);
2419 kernel=AcquireKernelInfo(argv[i+1]);
2420 if (kernel == (KernelInfo *) NULL)
2421 break;
2422 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2423 kernel=DestroyKernelInfo(kernel);
2424 break;
2425 }
2426 if (LocaleCompare("region",option+1) == 0)
2427 {
2428 (void) SyncImageSettings(mogrify_info,*image);
2429 if (region_image != (Image *) NULL)
2430 {
2431 /*
2432 Composite region.
2433 */
2434 (void) CompositeImage(region_image,region_image->matte !=
2435 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2436 region_geometry.x,region_geometry.y);
2437 InheritException(exception,&region_image->exception);
2438 *image=DestroyImage(*image);
2439 *image=region_image;
2440 region_image = (Image *) NULL;
2441 }
2442 if (*option == '+')
2443 break;
2444 /*
2445 Apply transformations to a selected region of the image.
2446 */
cristy3ed852e2009-09-05 21:47:34 +00002447 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2448 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002449 mogrify_image=CropImage(*image,&region_geometry,exception);
2450 if (mogrify_image == (Image *) NULL)
2451 break;
2452 region_image=(*image);
2453 *image=mogrify_image;
2454 mogrify_image=(Image *) NULL;
2455 break;
cristy3ed852e2009-09-05 21:47:34 +00002456 }
anthonydf8ebac2011-04-27 09:03:19 +00002457 if (LocaleCompare("render",option+1) == 0)
2458 {
2459 (void) SyncImageSettings(mogrify_info,*image);
2460 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2461 break;
2462 }
2463 if (LocaleCompare("remap",option+1) == 0)
2464 {
2465 Image
2466 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002467
anthonydf8ebac2011-04-27 09:03:19 +00002468 /*
2469 Transform image colors to match this set of colors.
2470 */
2471 (void) SyncImageSettings(mogrify_info,*image);
2472 if (*option == '+')
2473 break;
2474 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2475 if (remap_image == (Image *) NULL)
2476 break;
2477 (void) RemapImage(quantize_info,*image,remap_image);
2478 InheritException(exception,&(*image)->exception);
2479 remap_image=DestroyImage(remap_image);
2480 break;
2481 }
2482 if (LocaleCompare("repage",option+1) == 0)
2483 {
2484 if (*option == '+')
2485 {
2486 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2487 break;
2488 }
2489 (void) ResetImagePage(*image,argv[i+1]);
2490 InheritException(exception,&(*image)->exception);
2491 break;
2492 }
2493 if (LocaleCompare("resample",option+1) == 0)
2494 {
2495 /*
2496 Resample image.
2497 */
2498 (void) SyncImageSettings(mogrify_info,*image);
2499 flags=ParseGeometry(argv[i+1],&geometry_info);
2500 if ((flags & SigmaValue) == 0)
2501 geometry_info.sigma=geometry_info.rho;
2502 mogrify_image=ResampleImage(*image,geometry_info.rho,
2503 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2504 break;
2505 }
2506 if (LocaleCompare("resize",option+1) == 0)
2507 {
2508 /*
2509 Resize image.
2510 */
2511 (void) SyncImageSettings(mogrify_info,*image);
2512 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2513 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2514 (*image)->filter,(*image)->blur,exception);
2515 break;
2516 }
2517 if (LocaleCompare("roll",option+1) == 0)
2518 {
2519 /*
2520 Roll image.
2521 */
2522 (void) SyncImageSettings(mogrify_info,*image);
2523 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2524 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2525 break;
2526 }
2527 if (LocaleCompare("rotate",option+1) == 0)
2528 {
2529 char
2530 *geometry;
2531
2532 /*
2533 Check for conditional image rotation.
2534 */
2535 (void) SyncImageSettings(mogrify_info,*image);
2536 if (strchr(argv[i+1],'>') != (char *) NULL)
2537 if ((*image)->columns <= (*image)->rows)
2538 break;
2539 if (strchr(argv[i+1],'<') != (char *) NULL)
2540 if ((*image)->columns >= (*image)->rows)
2541 break;
2542 /*
2543 Rotate image.
2544 */
2545 geometry=ConstantString(argv[i+1]);
2546 (void) SubstituteString(&geometry,">","");
2547 (void) SubstituteString(&geometry,"<","");
2548 (void) ParseGeometry(geometry,&geometry_info);
2549 geometry=DestroyString(geometry);
2550 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2551 break;
2552 }
2553 break;
2554 }
2555 case 's':
2556 {
2557 if (LocaleCompare("sample",option+1) == 0)
2558 {
2559 /*
2560 Sample image with pixel replication.
2561 */
2562 (void) SyncImageSettings(mogrify_info,*image);
2563 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2564 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2565 exception);
2566 break;
2567 }
2568 if (LocaleCompare("scale",option+1) == 0)
2569 {
2570 /*
2571 Resize image.
2572 */
2573 (void) SyncImageSettings(mogrify_info,*image);
2574 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2575 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2576 exception);
2577 break;
2578 }
2579 if (LocaleCompare("selective-blur",option+1) == 0)
2580 {
2581 /*
2582 Selectively blur pixels within a contrast threshold.
2583 */
2584 (void) SyncImageSettings(mogrify_info,*image);
2585 flags=ParseGeometry(argv[i+1],&geometry_info);
2586 if ((flags & PercentValue) != 0)
2587 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2588 mogrify_image=SelectiveBlurImageChannel(*image,channel,
2589 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2590 break;
2591 }
2592 if (LocaleCompare("separate",option+1) == 0)
2593 {
2594 /*
2595 Break channels into separate images.
2596 WARNING: This can generate multiple images!
2597 */
2598 (void) SyncImageSettings(mogrify_info,*image);
2599 mogrify_image=SeparateImages(*image,channel,exception);
2600 break;
2601 }
2602 if (LocaleCompare("sepia-tone",option+1) == 0)
2603 {
2604 double
2605 threshold;
2606
2607 /*
2608 Sepia-tone image.
2609 */
2610 (void) SyncImageSettings(mogrify_info,*image);
2611 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2612 mogrify_image=SepiaToneImage(*image,threshold,exception);
2613 break;
2614 }
2615 if (LocaleCompare("segment",option+1) == 0)
2616 {
2617 /*
2618 Segment image.
2619 */
2620 (void) SyncImageSettings(mogrify_info,*image);
2621 flags=ParseGeometry(argv[i+1],&geometry_info);
2622 if ((flags & SigmaValue) == 0)
2623 geometry_info.sigma=1.0;
2624 (void) SegmentImage(*image,(*image)->colorspace,
2625 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2626 InheritException(exception,&(*image)->exception);
2627 break;
2628 }
2629 if (LocaleCompare("set",option+1) == 0)
2630 {
2631 char
2632 *value;
2633
2634 /*
2635 Set image option.
2636 */
2637 if (*option == '+')
2638 {
2639 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2640 (void) DeleteImageRegistry(argv[i+1]+9);
2641 else
2642 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2643 {
2644 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2645 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2646 }
2647 else
2648 (void) DeleteImageProperty(*image,argv[i+1]);
2649 break;
2650 }
2651 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2652 if (value == (char *) NULL)
2653 break;
2654 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2655 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2656 exception);
2657 else
2658 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2659 {
2660 (void) SetImageOption(image_info,argv[i+1]+7,value);
2661 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2662 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2663 }
2664 else
2665 (void) SetImageProperty(*image,argv[i+1],value);
2666 value=DestroyString(value);
2667 break;
2668 }
2669 if (LocaleCompare("shade",option+1) == 0)
2670 {
2671 /*
2672 Shade image.
2673 */
2674 (void) SyncImageSettings(mogrify_info,*image);
2675 flags=ParseGeometry(argv[i+1],&geometry_info);
2676 if ((flags & SigmaValue) == 0)
2677 geometry_info.sigma=1.0;
2678 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2679 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2680 break;
2681 }
2682 if (LocaleCompare("shadow",option+1) == 0)
2683 {
2684 /*
2685 Shadow image.
2686 */
2687 (void) SyncImageSettings(mogrify_info,*image);
2688 flags=ParseGeometry(argv[i+1],&geometry_info);
2689 if ((flags & SigmaValue) == 0)
2690 geometry_info.sigma=1.0;
2691 if ((flags & XiValue) == 0)
2692 geometry_info.xi=4.0;
2693 if ((flags & PsiValue) == 0)
2694 geometry_info.psi=4.0;
2695 mogrify_image=ShadowImage(*image,geometry_info.rho,
2696 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2697 ceil(geometry_info.psi-0.5),exception);
2698 break;
2699 }
2700 if (LocaleCompare("sharpen",option+1) == 0)
2701 {
2702 /*
2703 Sharpen image.
2704 */
2705 (void) SyncImageSettings(mogrify_info,*image);
2706 flags=ParseGeometry(argv[i+1],&geometry_info);
2707 if ((flags & SigmaValue) == 0)
2708 geometry_info.sigma=1.0;
2709 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2710 geometry_info.sigma,exception);
2711 break;
2712 }
2713 if (LocaleCompare("shave",option+1) == 0)
2714 {
2715 /*
2716 Shave the image edges.
2717 */
2718 (void) SyncImageSettings(mogrify_info,*image);
2719 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2720 mogrify_image=ShaveImage(*image,&geometry,exception);
2721 break;
2722 }
2723 if (LocaleCompare("shear",option+1) == 0)
2724 {
2725 /*
2726 Shear image.
2727 */
2728 (void) SyncImageSettings(mogrify_info,*image);
2729 flags=ParseGeometry(argv[i+1],&geometry_info);
2730 if ((flags & SigmaValue) == 0)
2731 geometry_info.sigma=geometry_info.rho;
2732 mogrify_image=ShearImage(*image,geometry_info.rho,
2733 geometry_info.sigma,exception);
2734 break;
2735 }
2736 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2737 {
2738 /*
2739 Sigmoidal non-linearity contrast control.
2740 */
2741 (void) SyncImageSettings(mogrify_info,*image);
2742 flags=ParseGeometry(argv[i+1],&geometry_info);
2743 if ((flags & SigmaValue) == 0)
2744 geometry_info.sigma=(double) QuantumRange/2.0;
2745 if ((flags & PercentValue) != 0)
2746 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2747 100.0;
2748 (void) SigmoidalContrastImageChannel(*image,channel,
2749 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2750 geometry_info.sigma);
2751 InheritException(exception,&(*image)->exception);
2752 break;
2753 }
2754 if (LocaleCompare("sketch",option+1) == 0)
2755 {
2756 /*
2757 Sketch image.
2758 */
2759 (void) SyncImageSettings(mogrify_info,*image);
2760 flags=ParseGeometry(argv[i+1],&geometry_info);
2761 if ((flags & SigmaValue) == 0)
2762 geometry_info.sigma=1.0;
2763 mogrify_image=SketchImage(*image,geometry_info.rho,
2764 geometry_info.sigma,geometry_info.xi,exception);
2765 break;
2766 }
2767 if (LocaleCompare("solarize",option+1) == 0)
2768 {
2769 double
2770 threshold;
2771
2772 (void) SyncImageSettings(mogrify_info,*image);
2773 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2774 (void) SolarizeImage(*image,threshold);
2775 InheritException(exception,&(*image)->exception);
2776 break;
2777 }
2778 if (LocaleCompare("sparse-color",option+1) == 0)
2779 {
2780 SparseColorMethod
2781 method;
2782
2783 char
2784 *arguments;
2785
2786 /*
2787 Sparse Color Interpolated Gradient
2788 */
2789 (void) SyncImageSettings(mogrify_info,*image);
2790 method=(SparseColorMethod) ParseCommandOption(
2791 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2792 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2793 InheritException(exception,&(*image)->exception);
2794 if (arguments == (char *) NULL)
2795 break;
2796 mogrify_image=SparseColorOption(*image,channel,method,arguments,
2797 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2798 arguments=DestroyString(arguments);
2799 break;
2800 }
2801 if (LocaleCompare("splice",option+1) == 0)
2802 {
2803 /*
2804 Splice a solid color into the image.
2805 */
2806 (void) SyncImageSettings(mogrify_info,*image);
2807 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2808 mogrify_image=SpliceImage(*image,&geometry,exception);
2809 break;
2810 }
2811 if (LocaleCompare("spread",option+1) == 0)
2812 {
2813 /*
2814 Spread an image.
2815 */
2816 (void) SyncImageSettings(mogrify_info,*image);
2817 (void) ParseGeometry(argv[i+1],&geometry_info);
2818 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2819 break;
2820 }
2821 if (LocaleCompare("statistic",option+1) == 0)
2822 {
2823 StatisticType
2824 type;
2825
2826 (void) SyncImageSettings(mogrify_info,*image);
2827 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2828 MagickFalse,argv[i+1]);
2829 (void) ParseGeometry(argv[i+2],&geometry_info);
2830 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2831 geometry_info.rho,(size_t) geometry_info.sigma,exception);
2832 break;
2833 }
2834 if (LocaleCompare("stretch",option+1) == 0)
2835 {
2836 if (*option == '+')
2837 {
2838 draw_info->stretch=UndefinedStretch;
2839 break;
2840 }
2841 draw_info->stretch=(StretchType) ParseCommandOption(
2842 MagickStretchOptions,MagickFalse,argv[i+1]);
2843 break;
2844 }
2845 if (LocaleCompare("strip",option+1) == 0)
2846 {
2847 /*
2848 Strip image of profiles and comments.
2849 */
2850 (void) SyncImageSettings(mogrify_info,*image);
2851 (void) StripImage(*image);
2852 InheritException(exception,&(*image)->exception);
2853 break;
2854 }
2855 if (LocaleCompare("stroke",option+1) == 0)
2856 {
2857 ExceptionInfo
2858 *sans;
2859
2860 if (*option == '+')
2861 {
2862 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2863 if (draw_info->stroke_pattern != (Image *) NULL)
2864 draw_info->stroke_pattern=DestroyImage(
2865 draw_info->stroke_pattern);
2866 break;
2867 }
2868 sans=AcquireExceptionInfo();
2869 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2870 sans=DestroyExceptionInfo(sans);
2871 if (status == MagickFalse)
2872 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2873 exception);
2874 break;
2875 }
2876 if (LocaleCompare("strokewidth",option+1) == 0)
2877 {
cristyc1acd842011-05-19 23:05:47 +00002878 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2879 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002880 break;
2881 }
2882 if (LocaleCompare("style",option+1) == 0)
2883 {
2884 if (*option == '+')
2885 {
2886 draw_info->style=UndefinedStyle;
2887 break;
2888 }
2889 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2890 MagickFalse,argv[i+1]);
2891 break;
2892 }
2893 if (LocaleCompare("swirl",option+1) == 0)
2894 {
2895 /*
2896 Swirl image.
2897 */
2898 (void) SyncImageSettings(mogrify_info,*image);
2899 (void) ParseGeometry(argv[i+1],&geometry_info);
2900 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2901 break;
2902 }
2903 break;
2904 }
2905 case 't':
2906 {
2907 if (LocaleCompare("threshold",option+1) == 0)
2908 {
2909 double
2910 threshold;
2911
2912 /*
2913 Threshold image.
2914 */
2915 (void) SyncImageSettings(mogrify_info,*image);
2916 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002917 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002918 else
2919 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2920 (void) BilevelImageChannel(*image,channel,threshold);
2921 InheritException(exception,&(*image)->exception);
2922 break;
2923 }
2924 if (LocaleCompare("thumbnail",option+1) == 0)
2925 {
2926 /*
2927 Thumbnail image.
2928 */
2929 (void) SyncImageSettings(mogrify_info,*image);
2930 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2931 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2932 exception);
2933 break;
2934 }
2935 if (LocaleCompare("tile",option+1) == 0)
2936 {
2937 if (*option == '+')
2938 {
2939 if (draw_info->fill_pattern != (Image *) NULL)
2940 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2941 break;
2942 }
2943 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2944 exception);
2945 break;
2946 }
2947 if (LocaleCompare("tint",option+1) == 0)
2948 {
2949 /*
2950 Tint the image.
2951 */
2952 (void) SyncImageSettings(mogrify_info,*image);
2953 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2954 break;
2955 }
2956 if (LocaleCompare("transform",option+1) == 0)
2957 {
2958 /*
2959 Affine transform image.
2960 */
2961 (void) SyncImageSettings(mogrify_info,*image);
2962 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2963 exception);
2964 break;
2965 }
2966 if (LocaleCompare("transparent",option+1) == 0)
2967 {
cristy4c08aed2011-07-01 19:47:50 +00002968 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002969 target;
2970
2971 (void) SyncImageSettings(mogrify_info,*image);
2972 (void) QueryMagickColor(argv[i+1],&target,exception);
2973 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002974 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002975 InheritException(exception,&(*image)->exception);
2976 break;
2977 }
2978 if (LocaleCompare("transpose",option+1) == 0)
2979 {
2980 /*
2981 Transpose image scanlines.
2982 */
2983 (void) SyncImageSettings(mogrify_info,*image);
2984 mogrify_image=TransposeImage(*image,exception);
2985 break;
2986 }
2987 if (LocaleCompare("transverse",option+1) == 0)
2988 {
2989 /*
2990 Transverse image scanlines.
2991 */
2992 (void) SyncImageSettings(mogrify_info,*image);
2993 mogrify_image=TransverseImage(*image,exception);
2994 break;
2995 }
2996 if (LocaleCompare("treedepth",option+1) == 0)
2997 {
2998 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2999 break;
3000 }
3001 if (LocaleCompare("trim",option+1) == 0)
3002 {
3003 /*
3004 Trim image.
3005 */
3006 (void) SyncImageSettings(mogrify_info,*image);
3007 mogrify_image=TrimImage(*image,exception);
3008 break;
3009 }
3010 if (LocaleCompare("type",option+1) == 0)
3011 {
3012 ImageType
3013 type;
3014
3015 (void) SyncImageSettings(mogrify_info,*image);
3016 if (*option == '+')
3017 type=UndefinedType;
3018 else
3019 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3020 argv[i+1]);
3021 (*image)->type=UndefinedType;
3022 (void) SetImageType(*image,type);
3023 InheritException(exception,&(*image)->exception);
3024 break;
3025 }
3026 break;
3027 }
3028 case 'u':
3029 {
3030 if (LocaleCompare("undercolor",option+1) == 0)
3031 {
3032 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3033 exception);
3034 break;
3035 }
3036 if (LocaleCompare("unique",option+1) == 0)
3037 {
3038 if (*option == '+')
3039 {
3040 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3041 break;
3042 }
3043 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3044 (void) SetImageArtifact(*image,"verbose","true");
3045 break;
3046 }
3047 if (LocaleCompare("unique-colors",option+1) == 0)
3048 {
3049 /*
3050 Unique image colors.
3051 */
3052 (void) SyncImageSettings(mogrify_info,*image);
3053 mogrify_image=UniqueImageColors(*image,exception);
3054 break;
3055 }
3056 if (LocaleCompare("unsharp",option+1) == 0)
3057 {
3058 /*
3059 Unsharp mask image.
3060 */
3061 (void) SyncImageSettings(mogrify_info,*image);
3062 flags=ParseGeometry(argv[i+1],&geometry_info);
3063 if ((flags & SigmaValue) == 0)
3064 geometry_info.sigma=1.0;
3065 if ((flags & XiValue) == 0)
3066 geometry_info.xi=1.0;
3067 if ((flags & PsiValue) == 0)
3068 geometry_info.psi=0.05;
3069 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3070 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3071 geometry_info.psi,exception);
3072 break;
3073 }
3074 break;
3075 }
3076 case 'v':
3077 {
3078 if (LocaleCompare("verbose",option+1) == 0)
3079 {
3080 (void) SetImageArtifact(*image,option+1,
3081 *option == '+' ? "false" : "true");
3082 break;
3083 }
3084 if (LocaleCompare("vignette",option+1) == 0)
3085 {
3086 /*
3087 Vignette image.
3088 */
3089 (void) SyncImageSettings(mogrify_info,*image);
3090 flags=ParseGeometry(argv[i+1],&geometry_info);
3091 if ((flags & SigmaValue) == 0)
3092 geometry_info.sigma=1.0;
3093 if ((flags & XiValue) == 0)
3094 geometry_info.xi=0.1*(*image)->columns;
3095 if ((flags & PsiValue) == 0)
3096 geometry_info.psi=0.1*(*image)->rows;
3097 mogrify_image=VignetteImage(*image,geometry_info.rho,
3098 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3099 ceil(geometry_info.psi-0.5),exception);
3100 break;
3101 }
3102 if (LocaleCompare("virtual-pixel",option+1) == 0)
3103 {
3104 if (*option == '+')
3105 {
3106 (void) SetImageVirtualPixelMethod(*image,
3107 UndefinedVirtualPixelMethod);
3108 break;
3109 }
3110 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3111 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3112 argv[i+1]));
3113 break;
3114 }
3115 break;
3116 }
3117 case 'w':
3118 {
3119 if (LocaleCompare("wave",option+1) == 0)
3120 {
3121 /*
3122 Wave image.
3123 */
3124 (void) SyncImageSettings(mogrify_info,*image);
3125 flags=ParseGeometry(argv[i+1],&geometry_info);
3126 if ((flags & SigmaValue) == 0)
3127 geometry_info.sigma=1.0;
3128 mogrify_image=WaveImage(*image,geometry_info.rho,
3129 geometry_info.sigma,exception);
3130 break;
3131 }
3132 if (LocaleCompare("weight",option+1) == 0)
3133 {
3134 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3135 if (LocaleCompare(argv[i+1],"all") == 0)
3136 draw_info->weight=0;
3137 if (LocaleCompare(argv[i+1],"bold") == 0)
3138 draw_info->weight=700;
3139 if (LocaleCompare(argv[i+1],"bolder") == 0)
3140 if (draw_info->weight <= 800)
3141 draw_info->weight+=100;
3142 if (LocaleCompare(argv[i+1],"lighter") == 0)
3143 if (draw_info->weight >= 100)
3144 draw_info->weight-=100;
3145 if (LocaleCompare(argv[i+1],"normal") == 0)
3146 draw_info->weight=400;
3147 break;
3148 }
3149 if (LocaleCompare("white-threshold",option+1) == 0)
3150 {
3151 /*
3152 White threshold image.
3153 */
3154 (void) SyncImageSettings(mogrify_info,*image);
3155 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3156 exception);
3157 InheritException(exception,&(*image)->exception);
3158 break;
3159 }
3160 break;
3161 }
3162 default:
3163 break;
3164 }
3165 /*
3166 Replace current image with any image that was generated
3167 */
3168 if (mogrify_image != (Image *) NULL)
3169 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003170 i+=count;
3171 }
3172 if (region_image != (Image *) NULL)
3173 {
anthonydf8ebac2011-04-27 09:03:19 +00003174 /*
3175 Composite transformed region onto image.
3176 */
cristy6b3da3a2010-06-20 02:21:46 +00003177 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003178 (void) CompositeImage(region_image,region_image->matte !=
3179 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
anthonye9c27192011-03-27 08:07:06 +00003180 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003181 InheritException(exception,&region_image->exception);
3182 *image=DestroyImage(*image);
3183 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003184 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003185 }
3186 /*
3187 Free resources.
3188 */
anthonydf8ebac2011-04-27 09:03:19 +00003189 quantize_info=DestroyQuantizeInfo(quantize_info);
3190 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003191 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003192 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003193 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003194 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003195}
3196
3197/*
3198%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3199% %
3200% %
3201% %
cristy5063d812010-10-19 16:28:10 +00003202+ 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 +00003203% %
3204% %
3205% %
3206%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3207%
3208% MogrifyImageCommand() transforms an image or a sequence of images. These
3209% transforms include image scaling, image rotation, color reduction, and
3210% others. The transmogrified image overwrites the original image.
3211%
3212% The format of the MogrifyImageCommand method is:
3213%
3214% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3215% const char **argv,char **metadata,ExceptionInfo *exception)
3216%
3217% A description of each parameter follows:
3218%
3219% o image_info: the image info.
3220%
3221% o argc: the number of elements in the argument vector.
3222%
3223% o argv: A text array containing the command line arguments.
3224%
3225% o metadata: any metadata is returned here.
3226%
3227% o exception: return any errors or warnings in this structure.
3228%
3229*/
3230
3231static MagickBooleanType MogrifyUsage(void)
3232{
3233 static const char
3234 *miscellaneous[]=
3235 {
3236 "-debug events display copious debugging information",
3237 "-help print program options",
3238 "-list type print a list of supported option arguments",
3239 "-log format format of debugging information",
3240 "-version print version information",
3241 (char *) NULL
3242 },
3243 *operators[]=
3244 {
3245 "-adaptive-blur geometry",
3246 " adaptively blur pixels; decrease effect near edges",
3247 "-adaptive-resize geometry",
3248 " adaptively resize image using 'mesh' interpolation",
3249 "-adaptive-sharpen geometry",
3250 " adaptively sharpen pixels; increase effect near edges",
3251 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3252 " transparent, extract, background, or shape",
3253 "-annotate geometry text",
3254 " annotate the image with text",
3255 "-auto-gamma automagically adjust gamma level of image",
3256 "-auto-level automagically adjust color levels of image",
3257 "-auto-orient automagically orient (rotate) image",
3258 "-bench iterations measure performance",
3259 "-black-threshold value",
3260 " force all pixels below the threshold into black",
3261 "-blue-shift simulate a scene at nighttime in the moonlight",
3262 "-blur geometry reduce image noise and reduce detail levels",
3263 "-border geometry surround image with a border of color",
3264 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003265 "-brightness-contrast geometry",
3266 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003267 "-cdl filename color correct with a color decision list",
3268 "-charcoal radius simulate a charcoal drawing",
3269 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003270 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003271 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003272 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003273 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003274 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003275 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003276 "-contrast enhance or reduce the image contrast",
3277 "-contrast-stretch geometry",
3278 " improve contrast by `stretching' the intensity range",
3279 "-convolve coefficients",
3280 " apply a convolution kernel to the image",
3281 "-cycle amount cycle the image colormap",
3282 "-decipher filename convert cipher pixels to plain pixels",
3283 "-deskew threshold straighten an image",
3284 "-despeckle reduce the speckles within an image",
3285 "-distort method args",
3286 " distort images according to given method ad args",
3287 "-draw string annotate the image with a graphic primitive",
3288 "-edge radius apply a filter to detect edges in the image",
3289 "-encipher filename convert plain pixels to cipher pixels",
3290 "-emboss radius emboss an image",
3291 "-enhance apply a digital filter to enhance a noisy image",
3292 "-equalize perform histogram equalization to an image",
3293 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003294 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003295 "-extent geometry set the image size",
3296 "-extract geometry extract area from image",
3297 "-fft implements the discrete Fourier transform (DFT)",
3298 "-flip flip image vertically",
3299 "-floodfill geometry color",
3300 " floodfill the image with color",
3301 "-flop flop image horizontally",
3302 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003303 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003304 " apply function over image values",
3305 "-gamma value level of gamma correction",
3306 "-gaussian-blur geometry",
3307 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003308 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003309 "-identify identify the format and characteristics of the image",
3310 "-ift implements the inverse discrete Fourier transform (DFT)",
3311 "-implode amount implode image pixels about the center",
3312 "-lat geometry local adaptive thresholding",
3313 "-layers method optimize, merge, or compare image layers",
3314 "-level value adjust the level of image contrast",
3315 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003316 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003317 "-linear-stretch geometry",
3318 " improve contrast by `stretching with saturation'",
3319 "-liquid-rescale geometry",
3320 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003321 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003322 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003323 "-modulate value vary the brightness, saturation, and hue",
3324 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003325 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003326 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003327 "-motion-blur geometry",
3328 " simulate motion blur",
3329 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003330 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003331 "-normalize transform image to span the full range of colors",
3332 "-opaque color change this color to the fill color",
3333 "-ordered-dither NxN",
3334 " add a noise pattern to the image with specific",
3335 " amplitudes",
3336 "-paint radius simulate an oil painting",
3337 "-polaroid angle simulate a Polaroid picture",
3338 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003339 "-profile filename add, delete, or apply an image profile",
3340 "-quantize colorspace reduce colors in this colorspace",
3341 "-radial-blur angle radial blur the image",
3342 "-raise value lighten/darken image edges to create a 3-D effect",
3343 "-random-threshold low,high",
3344 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003345 "-region geometry apply options to a portion of the image",
3346 "-render render vector graphics",
3347 "-repage geometry size and location of an image canvas",
3348 "-resample geometry change the resolution of an image",
3349 "-resize geometry resize the image",
3350 "-roll geometry roll an image vertically or horizontally",
3351 "-rotate degrees apply Paeth rotation to the image",
3352 "-sample geometry scale image with pixel sampling",
3353 "-scale geometry scale the image",
3354 "-segment values segment an image",
3355 "-selective-blur geometry",
3356 " selectively blur pixels within a contrast threshold",
3357 "-sepia-tone threshold",
3358 " simulate a sepia-toned photo",
3359 "-set property value set an image property",
3360 "-shade degrees shade the image using a distant light source",
3361 "-shadow geometry simulate an image shadow",
3362 "-sharpen geometry sharpen the image",
3363 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003364 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-sigmoidal-contrast geometry",
3366 " increase the contrast without saturating highlights or shadows",
3367 "-sketch geometry simulate a pencil sketch",
3368 "-solarize threshold negate all pixels above the threshold level",
3369 "-sparse-color method args",
3370 " fill in a image based on a few color points",
3371 "-splice geometry splice the background color into the image",
3372 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003373 "-statistic type radius",
3374 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003375 "-strip strip image of all profiles and comments",
3376 "-swirl degrees swirl image pixels about the center",
3377 "-threshold value threshold the image",
3378 "-thumbnail geometry create a thumbnail of the image",
3379 "-tile filename tile image when filling a graphic primitive",
3380 "-tint value tint the image with the fill color",
3381 "-transform affine transform image",
3382 "-transparent color make this color transparent within the image",
3383 "-transpose flip image vertically and rotate 90 degrees",
3384 "-transverse flop image horizontally and rotate 270 degrees",
3385 "-trim trim image edges",
3386 "-type type image type",
3387 "-unique-colors discard all but one of any pixel color",
3388 "-unsharp geometry sharpen the image",
3389 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003390 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003391 "-white-threshold value",
3392 " force all pixels above the threshold into white",
3393 (char *) NULL
3394 },
3395 *sequence_operators[]=
3396 {
cristy4285d782011-02-09 20:12:28 +00003397 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003398 "-clut apply a color lookup table to the image",
3399 "-coalesce merge a sequence of images",
3400 "-combine combine a sequence of images",
3401 "-composite composite image",
3402 "-crop geometry cut out a rectangular region of the image",
3403 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003404 "-evaluate-sequence operator",
3405 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003406 "-flatten flatten a sequence of images",
3407 "-fx expression apply mathematical expression to an image channel(s)",
3408 "-hald-clut apply a Hald color lookup table to the image",
3409 "-morph value morph an image sequence",
3410 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003411 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003412 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003413 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003414 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003415 "-write filename write images to this file",
3416 (char *) NULL
3417 },
3418 *settings[]=
3419 {
3420 "-adjoin join images into a single multi-image file",
3421 "-affine matrix affine transform matrix",
3422 "-alpha option activate, deactivate, reset, or set the alpha channel",
3423 "-antialias remove pixel-aliasing",
3424 "-authenticate password",
3425 " decipher image with this password",
3426 "-attenuate value lessen (or intensify) when adding noise to an image",
3427 "-background color background color",
3428 "-bias value add bias when convolving an image",
3429 "-black-point-compensation",
3430 " use black point compensation",
3431 "-blue-primary point chromaticity blue primary point",
3432 "-bordercolor color border color",
3433 "-caption string assign a caption to an image",
3434 "-channel type apply option to select image channels",
3435 "-colors value preferred number of colors in the image",
3436 "-colorspace type alternate image colorspace",
3437 "-comment string annotate image with comment",
3438 "-compose operator set image composite operator",
3439 "-compress type type of pixel compression when writing the image",
3440 "-define format:option",
3441 " define one or more image format options",
3442 "-delay value display the next image after pausing",
3443 "-density geometry horizontal and vertical density of the image",
3444 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003445 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003446 "-display server get image or font from this X server",
3447 "-dispose method layer disposal method",
3448 "-dither method apply error diffusion to image",
3449 "-encoding type text encoding type",
3450 "-endian type endianness (MSB or LSB) of the image",
3451 "-family name render text with this font family",
3452 "-fill color color to use when filling a graphic primitive",
3453 "-filter type use this filter when resizing an image",
3454 "-font name render text with this font",
3455 "-format \"string\" output formatted image characteristics",
3456 "-fuzz distance colors within this distance are considered equal",
3457 "-gravity type horizontal and vertical text placement",
3458 "-green-primary point chromaticity green primary point",
3459 "-intent type type of rendering intent when managing the image color",
3460 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003461 "-interline-spacing value",
3462 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003463 "-interpolate method pixel color interpolation method",
3464 "-interword-spacing value",
3465 " set the space between two words",
3466 "-kerning value set the space between two letters",
3467 "-label string assign a label to an image",
3468 "-limit type value pixel cache resource limit",
3469 "-loop iterations add Netscape loop extension to your GIF animation",
3470 "-mask filename associate a mask with the image",
3471 "-mattecolor color frame color",
3472 "-monitor monitor progress",
3473 "-orient type image orientation",
3474 "-page geometry size and location of an image canvas (setting)",
3475 "-ping efficiently determine image attributes",
3476 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003477 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003478 "-preview type image preview type",
3479 "-quality value JPEG/MIFF/PNG compression level",
3480 "-quiet suppress all warning messages",
3481 "-red-primary point chromaticity red primary point",
3482 "-regard-warnings pay attention to warning messages",
3483 "-remap filename transform image colors to match this set of colors",
3484 "-respect-parentheses settings remain in effect until parenthesis boundary",
3485 "-sampling-factor geometry",
3486 " horizontal and vertical sampling factor",
3487 "-scene value image scene number",
3488 "-seed value seed a new sequence of pseudo-random numbers",
3489 "-size geometry width and height of image",
3490 "-stretch type render text with this font stretch",
3491 "-stroke color graphic primitive stroke color",
3492 "-strokewidth value graphic primitive stroke width",
3493 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003494 "-synchronize synchronize image to storage device",
3495 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003496 "-texture filename name of texture to tile onto the image background",
3497 "-tile-offset geometry",
3498 " tile offset",
3499 "-treedepth value color tree depth",
3500 "-transparent-color color",
3501 " transparent color",
3502 "-undercolor color annotation bounding box color",
3503 "-units type the units of image resolution",
3504 "-verbose print detailed information about the image",
3505 "-view FlashPix viewing transforms",
3506 "-virtual-pixel method",
3507 " virtual pixel access method",
3508 "-weight type render text with this font weight",
3509 "-white-point point chromaticity white point",
3510 (char *) NULL
3511 },
3512 *stack_operators[]=
3513 {
anthonyb69c4b32011-03-23 04:37:44 +00003514 "-delete indexes delete the image from the image sequence",
3515 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003516 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003517 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003518 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003519 "-swap indexes swap two images in the image sequence",
3520 (char *) NULL
3521 };
3522
3523 const char
3524 **p;
3525
cristybb503372010-05-27 20:51:26 +00003526 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003527 (void) printf("Copyright: %s\n",GetMagickCopyright());
3528 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003529 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3530 GetClientName());
3531 (void) printf("\nImage Settings:\n");
3532 for (p=settings; *p != (char *) NULL; p++)
3533 (void) printf(" %s\n",*p);
3534 (void) printf("\nImage Operators:\n");
3535 for (p=operators; *p != (char *) NULL; p++)
3536 (void) printf(" %s\n",*p);
3537 (void) printf("\nImage Sequence Operators:\n");
3538 for (p=sequence_operators; *p != (char *) NULL; p++)
3539 (void) printf(" %s\n",*p);
3540 (void) printf("\nImage Stack Operators:\n");
3541 for (p=stack_operators; *p != (char *) NULL; p++)
3542 (void) printf(" %s\n",*p);
3543 (void) printf("\nMiscellaneous Options:\n");
3544 for (p=miscellaneous; *p != (char *) NULL; p++)
3545 (void) printf(" %s\n",*p);
3546 (void) printf(
3547 "\nBy default, the image format of `file' is determined by its magic\n");
3548 (void) printf(
3549 "number. To specify a particular image format, precede the filename\n");
3550 (void) printf(
3551 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3552 (void) printf(
3553 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3554 (void) printf("'-' for standard input or output.\n");
3555 return(MagickFalse);
3556}
3557
3558WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3559 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3560{
3561#define DestroyMogrify() \
3562{ \
3563 if (format != (char *) NULL) \
3564 format=DestroyString(format); \
3565 if (path != (char *) NULL) \
3566 path=DestroyString(path); \
3567 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003568 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003569 argv[i]=DestroyString(argv[i]); \
3570 argv=(char **) RelinquishMagickMemory(argv); \
3571}
3572#define ThrowMogrifyException(asperity,tag,option) \
3573{ \
3574 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3575 option); \
3576 DestroyMogrify(); \
3577 return(MagickFalse); \
3578}
3579#define ThrowMogrifyInvalidArgumentException(option,argument) \
3580{ \
3581 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3582 "InvalidArgument","`%s': %s",argument,option); \
3583 DestroyMogrify(); \
3584 return(MagickFalse); \
3585}
3586
3587 char
3588 *format,
3589 *option,
3590 *path;
3591
3592 Image
3593 *image;
3594
3595 ImageStack
3596 image_stack[MaxImageStackDepth+1];
3597
cristy3ed852e2009-09-05 21:47:34 +00003598 MagickBooleanType
3599 global_colormap;
3600
3601 MagickBooleanType
3602 fire,
cristyebbcfea2011-02-25 02:43:54 +00003603 pend,
3604 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003605
3606 MagickStatusType
3607 status;
3608
cristyebbcfea2011-02-25 02:43:54 +00003609 register ssize_t
3610 i;
3611
3612 ssize_t
3613 j,
3614 k;
3615
cristy3ed852e2009-09-05 21:47:34 +00003616 /*
3617 Set defaults.
3618 */
3619 assert(image_info != (ImageInfo *) NULL);
3620 assert(image_info->signature == MagickSignature);
3621 if (image_info->debug != MagickFalse)
3622 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3623 assert(exception != (ExceptionInfo *) NULL);
3624 if (argc == 2)
3625 {
3626 option=argv[1];
3627 if ((LocaleCompare("version",option+1) == 0) ||
3628 (LocaleCompare("-version",option+1) == 0))
3629 {
cristyb51dff52011-05-19 16:55:47 +00003630 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003631 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003632 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3633 GetMagickCopyright());
3634 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3635 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003636 return(MagickFalse);
3637 }
3638 }
3639 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003640 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003641 format=(char *) NULL;
3642 path=(char *) NULL;
3643 global_colormap=MagickFalse;
3644 k=0;
3645 j=1;
3646 NewImageStack();
3647 option=(char *) NULL;
3648 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003649 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003650 status=MagickTrue;
3651 /*
3652 Parse command line.
3653 */
3654 ReadCommandlLine(argc,&argv);
3655 status=ExpandFilenames(&argc,&argv);
3656 if (status == MagickFalse)
3657 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3658 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003659 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003660 {
3661 option=argv[i];
3662 if (LocaleCompare(option,"(") == 0)
3663 {
3664 FireImageStack(MagickFalse,MagickTrue,pend);
3665 if (k == MaxImageStackDepth)
3666 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3667 option);
3668 PushImageStack();
3669 continue;
3670 }
3671 if (LocaleCompare(option,")") == 0)
3672 {
3673 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3674 if (k == 0)
3675 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3676 PopImageStack();
3677 continue;
3678 }
cristy042ee782011-04-22 18:48:30 +00003679 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003680 {
3681 char
3682 backup_filename[MaxTextExtent],
3683 *filename;
3684
3685 Image
3686 *images;
3687
3688 /*
3689 Option is a file name: begin by reading image from specified file.
3690 */
3691 FireImageStack(MagickFalse,MagickFalse,pend);
3692 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003693 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003694 filename=argv[++i];
3695 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3696 images=ReadImages(image_info,exception);
3697 status&=(images != (Image *) NULL) &&
3698 (exception->severity < ErrorException);
3699 if (images == (Image *) NULL)
3700 continue;
cristydaa76602010-06-30 13:05:11 +00003701 if (format != (char *) NULL)
3702 (void) CopyMagickString(images->filename,images->magick_filename,
3703 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003704 if (path != (char *) NULL)
3705 {
3706 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003707 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003708 path,*DirectorySeparator,filename);
3709 }
3710 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003711 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003712 AppendImageStack(images);
3713 FinalizeImageSettings(image_info,image,MagickFalse);
3714 if (global_colormap != MagickFalse)
3715 {
3716 QuantizeInfo
3717 *quantize_info;
3718
3719 quantize_info=AcquireQuantizeInfo(image_info);
3720 (void) RemapImages(quantize_info,images,(Image *) NULL);
3721 quantize_info=DestroyQuantizeInfo(quantize_info);
3722 }
3723 *backup_filename='\0';
3724 if ((LocaleCompare(image->filename,"-") != 0) &&
3725 (IsPathWritable(image->filename) != MagickFalse))
3726 {
cristybb503372010-05-27 20:51:26 +00003727 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003728 i;
3729
3730 /*
3731 Rename image file as backup.
3732 */
3733 (void) CopyMagickString(backup_filename,image->filename,
3734 MaxTextExtent);
3735 for (i=0; i < 6; i++)
3736 {
3737 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3738 if (IsPathAccessible(backup_filename) == MagickFalse)
3739 break;
3740 }
3741 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3742 (rename(image->filename,backup_filename) != 0))
3743 *backup_filename='\0';
3744 }
3745 /*
3746 Write transmogrified image to disk.
3747 */
3748 image_info->synchronize=MagickTrue;
3749 status&=WriteImages(image_info,image,image->filename,exception);
3750 if ((status == MagickFalse) && (*backup_filename != '\0'))
3751 (void) remove(backup_filename);
3752 RemoveAllImageStack();
3753 continue;
3754 }
3755 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3756 switch (*(option+1))
3757 {
3758 case 'a':
3759 {
3760 if (LocaleCompare("adaptive-blur",option+1) == 0)
3761 {
3762 i++;
cristybb503372010-05-27 20:51:26 +00003763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003764 ThrowMogrifyException(OptionError,"MissingArgument",option);
3765 if (IsGeometry(argv[i]) == MagickFalse)
3766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3767 break;
3768 }
3769 if (LocaleCompare("adaptive-resize",option+1) == 0)
3770 {
3771 i++;
cristybb503372010-05-27 20:51:26 +00003772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003773 ThrowMogrifyException(OptionError,"MissingArgument",option);
3774 if (IsGeometry(argv[i]) == MagickFalse)
3775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3776 break;
3777 }
3778 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3779 {
3780 i++;
cristybb503372010-05-27 20:51:26 +00003781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003782 ThrowMogrifyException(OptionError,"MissingArgument",option);
3783 if (IsGeometry(argv[i]) == MagickFalse)
3784 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3785 break;
3786 }
3787 if (LocaleCompare("affine",option+1) == 0)
3788 {
3789 if (*option == '+')
3790 break;
3791 i++;
cristybb503372010-05-27 20:51:26 +00003792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003793 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003794 break;
3795 }
3796 if (LocaleCompare("alpha",option+1) == 0)
3797 {
cristybb503372010-05-27 20:51:26 +00003798 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003799 type;
3800
3801 if (*option == '+')
3802 break;
3803 i++;
cristybb503372010-05-27 20:51:26 +00003804 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003805 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003806 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003807 if (type < 0)
3808 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3809 argv[i]);
3810 break;
3811 }
3812 if (LocaleCompare("annotate",option+1) == 0)
3813 {
3814 if (*option == '+')
3815 break;
3816 i++;
cristybb503372010-05-27 20:51:26 +00003817 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003818 ThrowMogrifyException(OptionError,"MissingArgument",option);
3819 if (IsGeometry(argv[i]) == MagickFalse)
3820 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003822 ThrowMogrifyException(OptionError,"MissingArgument",option);
3823 i++;
3824 break;
3825 }
3826 if (LocaleCompare("antialias",option+1) == 0)
3827 break;
3828 if (LocaleCompare("append",option+1) == 0)
3829 break;
3830 if (LocaleCompare("attenuate",option+1) == 0)
3831 {
3832 if (*option == '+')
3833 break;
3834 i++;
cristybb503372010-05-27 20:51:26 +00003835 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003836 ThrowMogrifyException(OptionError,"MissingArgument",option);
3837 if (IsGeometry(argv[i]) == MagickFalse)
3838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3839 break;
3840 }
3841 if (LocaleCompare("authenticate",option+1) == 0)
3842 {
3843 if (*option == '+')
3844 break;
3845 i++;
cristybb503372010-05-27 20:51:26 +00003846 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003847 ThrowMogrifyException(OptionError,"MissingArgument",option);
3848 break;
3849 }
3850 if (LocaleCompare("auto-gamma",option+1) == 0)
3851 break;
3852 if (LocaleCompare("auto-level",option+1) == 0)
3853 break;
3854 if (LocaleCompare("auto-orient",option+1) == 0)
3855 break;
3856 if (LocaleCompare("average",option+1) == 0)
3857 break;
3858 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3859 }
3860 case 'b':
3861 {
3862 if (LocaleCompare("background",option+1) == 0)
3863 {
3864 if (*option == '+')
3865 break;
3866 i++;
cristybb503372010-05-27 20:51:26 +00003867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003868 ThrowMogrifyException(OptionError,"MissingArgument",option);
3869 break;
3870 }
3871 if (LocaleCompare("bias",option+1) == 0)
3872 {
3873 if (*option == '+')
3874 break;
3875 i++;
cristybb503372010-05-27 20:51:26 +00003876 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003877 ThrowMogrifyException(OptionError,"MissingArgument",option);
3878 if (IsGeometry(argv[i]) == MagickFalse)
3879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3880 break;
3881 }
3882 if (LocaleCompare("black-point-compensation",option+1) == 0)
3883 break;
3884 if (LocaleCompare("black-threshold",option+1) == 0)
3885 {
3886 if (*option == '+')
3887 break;
3888 i++;
cristybb503372010-05-27 20:51:26 +00003889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003890 ThrowMogrifyException(OptionError,"MissingArgument",option);
3891 if (IsGeometry(argv[i]) == MagickFalse)
3892 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3893 break;
3894 }
3895 if (LocaleCompare("blue-primary",option+1) == 0)
3896 {
3897 if (*option == '+')
3898 break;
3899 i++;
cristybb503372010-05-27 20:51:26 +00003900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003901 ThrowMogrifyException(OptionError,"MissingArgument",option);
3902 if (IsGeometry(argv[i]) == MagickFalse)
3903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3904 break;
3905 }
3906 if (LocaleCompare("blue-shift",option+1) == 0)
3907 {
3908 i++;
cristybb503372010-05-27 20:51:26 +00003909 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003910 ThrowMogrifyException(OptionError,"MissingArgument",option);
3911 if (IsGeometry(argv[i]) == MagickFalse)
3912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3913 break;
3914 }
3915 if (LocaleCompare("blur",option+1) == 0)
3916 {
3917 i++;
cristybb503372010-05-27 20:51:26 +00003918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003919 ThrowMogrifyException(OptionError,"MissingArgument",option);
3920 if (IsGeometry(argv[i]) == MagickFalse)
3921 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3922 break;
3923 }
3924 if (LocaleCompare("border",option+1) == 0)
3925 {
3926 if (*option == '+')
3927 break;
3928 i++;
cristybb503372010-05-27 20:51:26 +00003929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003930 ThrowMogrifyException(OptionError,"MissingArgument",option);
3931 if (IsGeometry(argv[i]) == MagickFalse)
3932 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3933 break;
3934 }
3935 if (LocaleCompare("bordercolor",option+1) == 0)
3936 {
3937 if (*option == '+')
3938 break;
3939 i++;
cristybb503372010-05-27 20:51:26 +00003940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003941 ThrowMogrifyException(OptionError,"MissingArgument",option);
3942 break;
3943 }
3944 if (LocaleCompare("box",option+1) == 0)
3945 {
3946 if (*option == '+')
3947 break;
3948 i++;
cristybb503372010-05-27 20:51:26 +00003949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003950 ThrowMogrifyException(OptionError,"MissingArgument",option);
3951 break;
3952 }
cristya28d6b82010-01-11 20:03:47 +00003953 if (LocaleCompare("brightness-contrast",option+1) == 0)
3954 {
3955 i++;
cristybb503372010-05-27 20:51:26 +00003956 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003957 ThrowMogrifyException(OptionError,"MissingArgument",option);
3958 if (IsGeometry(argv[i]) == MagickFalse)
3959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3960 break;
3961 }
cristy3ed852e2009-09-05 21:47:34 +00003962 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3963 }
3964 case 'c':
3965 {
3966 if (LocaleCompare("cache",option+1) == 0)
3967 {
3968 if (*option == '+')
3969 break;
3970 i++;
cristybb503372010-05-27 20:51:26 +00003971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003972 ThrowMogrifyException(OptionError,"MissingArgument",option);
3973 if (IsGeometry(argv[i]) == MagickFalse)
3974 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3975 break;
3976 }
3977 if (LocaleCompare("caption",option+1) == 0)
3978 {
3979 if (*option == '+')
3980 break;
3981 i++;
cristybb503372010-05-27 20:51:26 +00003982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003983 ThrowMogrifyException(OptionError,"MissingArgument",option);
3984 break;
3985 }
3986 if (LocaleCompare("channel",option+1) == 0)
3987 {
cristybb503372010-05-27 20:51:26 +00003988 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003989 channel;
3990
3991 if (*option == '+')
3992 break;
3993 i++;
cristybb503372010-05-27 20:51:26 +00003994 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003995 ThrowMogrifyException(OptionError,"MissingArgument",option);
3996 channel=ParseChannelOption(argv[i]);
3997 if (channel < 0)
3998 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3999 argv[i]);
4000 break;
4001 }
4002 if (LocaleCompare("cdl",option+1) == 0)
4003 {
4004 if (*option == '+')
4005 break;
4006 i++;
cristybb503372010-05-27 20:51:26 +00004007 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004008 ThrowMogrifyException(OptionError,"MissingArgument",option);
4009 break;
4010 }
4011 if (LocaleCompare("charcoal",option+1) == 0)
4012 {
4013 if (*option == '+')
4014 break;
4015 i++;
cristybb503372010-05-27 20:51:26 +00004016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004017 ThrowMogrifyException(OptionError,"MissingArgument",option);
4018 if (IsGeometry(argv[i]) == MagickFalse)
4019 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4020 break;
4021 }
4022 if (LocaleCompare("chop",option+1) == 0)
4023 {
4024 if (*option == '+')
4025 break;
4026 i++;
cristybb503372010-05-27 20:51:26 +00004027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004028 ThrowMogrifyException(OptionError,"MissingArgument",option);
4029 if (IsGeometry(argv[i]) == MagickFalse)
4030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4031 break;
4032 }
cristy1eb45dd2009-09-25 16:38:06 +00004033 if (LocaleCompare("clamp",option+1) == 0)
4034 break;
4035 if (LocaleCompare("clip",option+1) == 0)
4036 break;
cristy3ed852e2009-09-05 21:47:34 +00004037 if (LocaleCompare("clip-mask",option+1) == 0)
4038 {
4039 if (*option == '+')
4040 break;
4041 i++;
cristybb503372010-05-27 20:51:26 +00004042 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004043 ThrowMogrifyException(OptionError,"MissingArgument",option);
4044 break;
4045 }
4046 if (LocaleCompare("clut",option+1) == 0)
4047 break;
4048 if (LocaleCompare("coalesce",option+1) == 0)
4049 break;
4050 if (LocaleCompare("colorize",option+1) == 0)
4051 {
4052 if (*option == '+')
4053 break;
4054 i++;
cristybb503372010-05-27 20:51:26 +00004055 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004056 ThrowMogrifyException(OptionError,"MissingArgument",option);
4057 if (IsGeometry(argv[i]) == MagickFalse)
4058 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4059 break;
4060 }
cristye6365592010-04-02 17:31:23 +00004061 if (LocaleCompare("color-matrix",option+1) == 0)
4062 {
cristyb6bd4ad2010-08-08 01:12:27 +00004063 KernelInfo
4064 *kernel_info;
4065
cristye6365592010-04-02 17:31:23 +00004066 if (*option == '+')
4067 break;
4068 i++;
cristybb503372010-05-27 20:51:26 +00004069 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004070 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004071 kernel_info=AcquireKernelInfo(argv[i]);
4072 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004073 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004074 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004075 break;
4076 }
cristy3ed852e2009-09-05 21:47:34 +00004077 if (LocaleCompare("colors",option+1) == 0)
4078 {
4079 if (*option == '+')
4080 break;
4081 i++;
cristybb503372010-05-27 20:51:26 +00004082 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004083 ThrowMogrifyException(OptionError,"MissingArgument",option);
4084 if (IsGeometry(argv[i]) == MagickFalse)
4085 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4086 break;
4087 }
4088 if (LocaleCompare("colorspace",option+1) == 0)
4089 {
cristybb503372010-05-27 20:51:26 +00004090 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004091 colorspace;
4092
4093 if (*option == '+')
4094 break;
4095 i++;
cristybb503372010-05-27 20:51:26 +00004096 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004097 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004098 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004099 argv[i]);
4100 if (colorspace < 0)
4101 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4102 argv[i]);
4103 break;
4104 }
4105 if (LocaleCompare("combine",option+1) == 0)
4106 break;
4107 if (LocaleCompare("comment",option+1) == 0)
4108 {
4109 if (*option == '+')
4110 break;
4111 i++;
cristybb503372010-05-27 20:51:26 +00004112 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004113 ThrowMogrifyException(OptionError,"MissingArgument",option);
4114 break;
4115 }
4116 if (LocaleCompare("composite",option+1) == 0)
4117 break;
4118 if (LocaleCompare("compress",option+1) == 0)
4119 {
cristybb503372010-05-27 20:51:26 +00004120 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004121 compress;
4122
4123 if (*option == '+')
4124 break;
4125 i++;
cristybb503372010-05-27 20:51:26 +00004126 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004127 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004128 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004129 argv[i]);
4130 if (compress < 0)
4131 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4132 argv[i]);
4133 break;
4134 }
cristy22879752009-10-25 23:55:40 +00004135 if (LocaleCompare("concurrent",option+1) == 0)
4136 break;
cristy3ed852e2009-09-05 21:47:34 +00004137 if (LocaleCompare("contrast",option+1) == 0)
4138 break;
4139 if (LocaleCompare("contrast-stretch",option+1) == 0)
4140 {
4141 i++;
cristybb503372010-05-27 20:51:26 +00004142 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004143 ThrowMogrifyException(OptionError,"MissingArgument",option);
4144 if (IsGeometry(argv[i]) == MagickFalse)
4145 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4146 break;
4147 }
4148 if (LocaleCompare("convolve",option+1) == 0)
4149 {
cristyb6bd4ad2010-08-08 01:12:27 +00004150 KernelInfo
4151 *kernel_info;
4152
cristy3ed852e2009-09-05 21:47:34 +00004153 if (*option == '+')
4154 break;
4155 i++;
cristybb503372010-05-27 20:51:26 +00004156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004157 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004158 kernel_info=AcquireKernelInfo(argv[i]);
4159 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004160 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004161 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004162 break;
4163 }
4164 if (LocaleCompare("crop",option+1) == 0)
4165 {
4166 if (*option == '+')
4167 break;
4168 i++;
cristybb503372010-05-27 20:51:26 +00004169 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004170 ThrowMogrifyException(OptionError,"MissingArgument",option);
4171 if (IsGeometry(argv[i]) == MagickFalse)
4172 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4173 break;
4174 }
4175 if (LocaleCompare("cycle",option+1) == 0)
4176 {
4177 if (*option == '+')
4178 break;
4179 i++;
cristybb503372010-05-27 20:51:26 +00004180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004181 ThrowMogrifyException(OptionError,"MissingArgument",option);
4182 if (IsGeometry(argv[i]) == MagickFalse)
4183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4184 break;
4185 }
4186 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4187 }
4188 case 'd':
4189 {
4190 if (LocaleCompare("decipher",option+1) == 0)
4191 {
4192 if (*option == '+')
4193 break;
4194 i++;
cristybb503372010-05-27 20:51:26 +00004195 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004196 ThrowMogrifyException(OptionError,"MissingArgument",option);
4197 break;
4198 }
4199 if (LocaleCompare("deconstruct",option+1) == 0)
4200 break;
4201 if (LocaleCompare("debug",option+1) == 0)
4202 {
cristybb503372010-05-27 20:51:26 +00004203 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004204 event;
4205
4206 if (*option == '+')
4207 break;
4208 i++;
cristybb503372010-05-27 20:51:26 +00004209 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004210 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004211 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004212 if (event < 0)
4213 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4214 argv[i]);
4215 (void) SetLogEventMask(argv[i]);
4216 break;
4217 }
4218 if (LocaleCompare("define",option+1) == 0)
4219 {
4220 i++;
cristybb503372010-05-27 20:51:26 +00004221 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004222 ThrowMogrifyException(OptionError,"MissingArgument",option);
4223 if (*option == '+')
4224 {
4225 const char
4226 *define;
4227
4228 define=GetImageOption(image_info,argv[i]);
4229 if (define == (const char *) NULL)
4230 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4231 break;
4232 }
4233 break;
4234 }
4235 if (LocaleCompare("delay",option+1) == 0)
4236 {
4237 if (*option == '+')
4238 break;
4239 i++;
cristybb503372010-05-27 20:51:26 +00004240 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004241 ThrowMogrifyException(OptionError,"MissingArgument",option);
4242 if (IsGeometry(argv[i]) == MagickFalse)
4243 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4244 break;
4245 }
cristyecb10ff2011-03-22 13:14:03 +00004246 if (LocaleCompare("delete",option+1) == 0)
4247 {
4248 if (*option == '+')
4249 break;
4250 i++;
4251 if (i == (ssize_t) (argc-1))
4252 ThrowMogrifyException(OptionError,"MissingArgument",option);
4253 if (IsGeometry(argv[i]) == MagickFalse)
4254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4255 break;
4256 }
cristy3ed852e2009-09-05 21:47:34 +00004257 if (LocaleCompare("density",option+1) == 0)
4258 {
4259 if (*option == '+')
4260 break;
4261 i++;
cristybb503372010-05-27 20:51:26 +00004262 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004263 ThrowMogrifyException(OptionError,"MissingArgument",option);
4264 if (IsGeometry(argv[i]) == MagickFalse)
4265 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4266 break;
4267 }
4268 if (LocaleCompare("depth",option+1) == 0)
4269 {
4270 if (*option == '+')
4271 break;
4272 i++;
cristybb503372010-05-27 20:51:26 +00004273 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004274 ThrowMogrifyException(OptionError,"MissingArgument",option);
4275 if (IsGeometry(argv[i]) == MagickFalse)
4276 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4277 break;
4278 }
4279 if (LocaleCompare("deskew",option+1) == 0)
4280 {
4281 if (*option == '+')
4282 break;
4283 i++;
cristybb503372010-05-27 20:51:26 +00004284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004285 ThrowMogrifyException(OptionError,"MissingArgument",option);
4286 if (IsGeometry(argv[i]) == MagickFalse)
4287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4288 break;
4289 }
4290 if (LocaleCompare("despeckle",option+1) == 0)
4291 break;
4292 if (LocaleCompare("dft",option+1) == 0)
4293 break;
cristyc9b12952010-03-28 01:12:28 +00004294 if (LocaleCompare("direction",option+1) == 0)
4295 {
cristybb503372010-05-27 20:51:26 +00004296 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004297 direction;
4298
4299 if (*option == '+')
4300 break;
4301 i++;
cristybb503372010-05-27 20:51:26 +00004302 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004303 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004304 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004305 argv[i]);
4306 if (direction < 0)
4307 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4308 argv[i]);
4309 break;
4310 }
cristy3ed852e2009-09-05 21:47:34 +00004311 if (LocaleCompare("display",option+1) == 0)
4312 {
4313 if (*option == '+')
4314 break;
4315 i++;
cristybb503372010-05-27 20:51:26 +00004316 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004317 ThrowMogrifyException(OptionError,"MissingArgument",option);
4318 break;
4319 }
4320 if (LocaleCompare("dispose",option+1) == 0)
4321 {
cristybb503372010-05-27 20:51:26 +00004322 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004323 dispose;
4324
4325 if (*option == '+')
4326 break;
4327 i++;
cristybb503372010-05-27 20:51:26 +00004328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004329 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004330 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004331 if (dispose < 0)
4332 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4333 argv[i]);
4334 break;
4335 }
4336 if (LocaleCompare("distort",option+1) == 0)
4337 {
cristybb503372010-05-27 20:51:26 +00004338 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004339 op;
4340
4341 i++;
cristybb503372010-05-27 20:51:26 +00004342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004343 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004344 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004345 if (op < 0)
4346 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4347 argv[i]);
4348 i++;
cristybb503372010-05-27 20:51:26 +00004349 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004350 ThrowMogrifyException(OptionError,"MissingArgument",option);
4351 break;
4352 }
4353 if (LocaleCompare("dither",option+1) == 0)
4354 {
cristybb503372010-05-27 20:51:26 +00004355 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004356 method;
4357
4358 if (*option == '+')
4359 break;
4360 i++;
cristybb503372010-05-27 20:51:26 +00004361 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004362 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004363 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004364 if (method < 0)
4365 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4366 argv[i]);
4367 break;
4368 }
4369 if (LocaleCompare("draw",option+1) == 0)
4370 {
4371 if (*option == '+')
4372 break;
4373 i++;
cristybb503372010-05-27 20:51:26 +00004374 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004375 ThrowMogrifyException(OptionError,"MissingArgument",option);
4376 break;
4377 }
cristyecb10ff2011-03-22 13:14:03 +00004378 if (LocaleCompare("duplicate",option+1) == 0)
4379 {
4380 if (*option == '+')
4381 break;
4382 i++;
4383 if (i == (ssize_t) (argc-1))
4384 ThrowMogrifyException(OptionError,"MissingArgument",option);
4385 if (IsGeometry(argv[i]) == MagickFalse)
4386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4387 break;
4388 }
cristy22879752009-10-25 23:55:40 +00004389 if (LocaleCompare("duration",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
cristybb503372010-05-27 20:51:26 +00004394 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 if (IsGeometry(argv[i]) == MagickFalse)
4397 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4398 break;
4399 }
cristy3ed852e2009-09-05 21:47:34 +00004400 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4401 }
4402 case 'e':
4403 {
4404 if (LocaleCompare("edge",option+1) == 0)
4405 {
4406 if (*option == '+')
4407 break;
4408 i++;
cristybb503372010-05-27 20:51:26 +00004409 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004410 ThrowMogrifyException(OptionError,"MissingArgument",option);
4411 if (IsGeometry(argv[i]) == MagickFalse)
4412 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4413 break;
4414 }
4415 if (LocaleCompare("emboss",option+1) == 0)
4416 {
4417 if (*option == '+')
4418 break;
4419 i++;
cristybb503372010-05-27 20:51:26 +00004420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004421 ThrowMogrifyException(OptionError,"MissingArgument",option);
4422 if (IsGeometry(argv[i]) == MagickFalse)
4423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4424 break;
4425 }
4426 if (LocaleCompare("encipher",option+1) == 0)
4427 {
4428 if (*option == '+')
4429 break;
4430 i++;
cristybb503372010-05-27 20:51:26 +00004431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004432 ThrowMogrifyException(OptionError,"MissingArgument",option);
4433 break;
4434 }
4435 if (LocaleCompare("encoding",option+1) == 0)
4436 {
4437 if (*option == '+')
4438 break;
4439 i++;
cristybb503372010-05-27 20:51:26 +00004440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004441 ThrowMogrifyException(OptionError,"MissingArgument",option);
4442 break;
4443 }
4444 if (LocaleCompare("endian",option+1) == 0)
4445 {
cristybb503372010-05-27 20:51:26 +00004446 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004447 endian;
4448
4449 if (*option == '+')
4450 break;
4451 i++;
cristybb503372010-05-27 20:51:26 +00004452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004453 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004454 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004455 if (endian < 0)
4456 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4457 argv[i]);
4458 break;
4459 }
4460 if (LocaleCompare("enhance",option+1) == 0)
4461 break;
4462 if (LocaleCompare("equalize",option+1) == 0)
4463 break;
4464 if (LocaleCompare("evaluate",option+1) == 0)
4465 {
cristybb503372010-05-27 20:51:26 +00004466 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004467 op;
4468
4469 if (*option == '+')
4470 break;
4471 i++;
cristybb503372010-05-27 20:51:26 +00004472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004473 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004474 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004475 if (op < 0)
4476 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4477 argv[i]);
4478 i++;
cristybb503372010-05-27 20:51:26 +00004479 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004480 ThrowMogrifyException(OptionError,"MissingArgument",option);
4481 if (IsGeometry(argv[i]) == MagickFalse)
4482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4483 break;
4484 }
cristyd18ae7c2010-03-07 17:39:52 +00004485 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4486 {
cristybb503372010-05-27 20:51:26 +00004487 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004488 op;
4489
4490 if (*option == '+')
4491 break;
4492 i++;
cristybb503372010-05-27 20:51:26 +00004493 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004494 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004495 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004496 if (op < 0)
4497 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4498 argv[i]);
4499 break;
4500 }
cristy3ed852e2009-09-05 21:47:34 +00004501 if (LocaleCompare("extent",option+1) == 0)
4502 {
4503 if (*option == '+')
4504 break;
4505 i++;
cristybb503372010-05-27 20:51:26 +00004506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004507 ThrowMogrifyException(OptionError,"MissingArgument",option);
4508 if (IsGeometry(argv[i]) == MagickFalse)
4509 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4510 break;
4511 }
4512 if (LocaleCompare("extract",option+1) == 0)
4513 {
4514 if (*option == '+')
4515 break;
4516 i++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
4519 if (IsGeometry(argv[i]) == MagickFalse)
4520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4521 break;
4522 }
4523 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4524 }
4525 case 'f':
4526 {
4527 if (LocaleCompare("family",option+1) == 0)
4528 {
4529 if (*option == '+')
4530 break;
4531 i++;
cristybb503372010-05-27 20:51:26 +00004532 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004533 ThrowMogrifyException(OptionError,"MissingArgument",option);
4534 break;
4535 }
4536 if (LocaleCompare("fill",option+1) == 0)
4537 {
4538 if (*option == '+')
4539 break;
4540 i++;
cristybb503372010-05-27 20:51:26 +00004541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004542 ThrowMogrifyException(OptionError,"MissingArgument",option);
4543 break;
4544 }
4545 if (LocaleCompare("filter",option+1) == 0)
4546 {
cristybb503372010-05-27 20:51:26 +00004547 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004548 filter;
4549
4550 if (*option == '+')
4551 break;
4552 i++;
cristybb503372010-05-27 20:51:26 +00004553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004554 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004555 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004556 if (filter < 0)
4557 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4558 argv[i]);
4559 break;
4560 }
4561 if (LocaleCompare("flatten",option+1) == 0)
4562 break;
4563 if (LocaleCompare("flip",option+1) == 0)
4564 break;
4565 if (LocaleCompare("flop",option+1) == 0)
4566 break;
4567 if (LocaleCompare("floodfill",option+1) == 0)
4568 {
4569 if (*option == '+')
4570 break;
4571 i++;
cristybb503372010-05-27 20:51:26 +00004572 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004573 ThrowMogrifyException(OptionError,"MissingArgument",option);
4574 if (IsGeometry(argv[i]) == MagickFalse)
4575 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4576 i++;
cristybb503372010-05-27 20:51:26 +00004577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004578 ThrowMogrifyException(OptionError,"MissingArgument",option);
4579 break;
4580 }
4581 if (LocaleCompare("font",option+1) == 0)
4582 {
4583 if (*option == '+')
4584 break;
4585 i++;
cristybb503372010-05-27 20:51:26 +00004586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004587 ThrowMogrifyException(OptionError,"MissingArgument",option);
4588 break;
4589 }
4590 if (LocaleCompare("format",option+1) == 0)
4591 {
4592 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4593 (void) CloneString(&format,(char *) NULL);
4594 if (*option == '+')
4595 break;
4596 i++;
cristybb503372010-05-27 20:51:26 +00004597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004598 ThrowMogrifyException(OptionError,"MissingArgument",option);
4599 (void) CloneString(&format,argv[i]);
4600 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4601 (void) ConcatenateMagickString(image_info->filename,":",
4602 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004603 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004604 if (*image_info->magick == '\0')
4605 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4606 format);
4607 break;
4608 }
4609 if (LocaleCompare("frame",option+1) == 0)
4610 {
4611 if (*option == '+')
4612 break;
4613 i++;
cristybb503372010-05-27 20:51:26 +00004614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004615 ThrowMogrifyException(OptionError,"MissingArgument",option);
4616 if (IsGeometry(argv[i]) == MagickFalse)
4617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4618 break;
4619 }
4620 if (LocaleCompare("function",option+1) == 0)
4621 {
cristybb503372010-05-27 20:51:26 +00004622 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004623 op;
4624
4625 if (*option == '+')
4626 break;
4627 i++;
cristybb503372010-05-27 20:51:26 +00004628 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004629 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004630 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004631 if (op < 0)
4632 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4633 i++;
cristybb503372010-05-27 20:51:26 +00004634 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004635 ThrowMogrifyException(OptionError,"MissingArgument",option);
4636 break;
4637 }
4638 if (LocaleCompare("fuzz",option+1) == 0)
4639 {
4640 if (*option == '+')
4641 break;
4642 i++;
cristybb503372010-05-27 20:51:26 +00004643 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004644 ThrowMogrifyException(OptionError,"MissingArgument",option);
4645 if (IsGeometry(argv[i]) == MagickFalse)
4646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4647 break;
4648 }
4649 if (LocaleCompare("fx",option+1) == 0)
4650 {
4651 if (*option == '+')
4652 break;
4653 i++;
cristybb503372010-05-27 20:51:26 +00004654 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004655 ThrowMogrifyException(OptionError,"MissingArgument",option);
4656 break;
4657 }
4658 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4659 }
4660 case 'g':
4661 {
4662 if (LocaleCompare("gamma",option+1) == 0)
4663 {
4664 i++;
cristybb503372010-05-27 20:51:26 +00004665 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004666 ThrowMogrifyException(OptionError,"MissingArgument",option);
4667 if (IsGeometry(argv[i]) == MagickFalse)
4668 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4669 break;
4670 }
4671 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4672 (LocaleCompare("gaussian",option+1) == 0))
4673 {
4674 i++;
cristybb503372010-05-27 20:51:26 +00004675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004676 ThrowMogrifyException(OptionError,"MissingArgument",option);
4677 if (IsGeometry(argv[i]) == MagickFalse)
4678 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4679 break;
4680 }
4681 if (LocaleCompare("geometry",option+1) == 0)
4682 {
4683 if (*option == '+')
4684 break;
4685 i++;
cristybb503372010-05-27 20:51:26 +00004686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004687 ThrowMogrifyException(OptionError,"MissingArgument",option);
4688 if (IsGeometry(argv[i]) == MagickFalse)
4689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4690 break;
4691 }
4692 if (LocaleCompare("gravity",option+1) == 0)
4693 {
cristybb503372010-05-27 20:51:26 +00004694 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004695 gravity;
4696
4697 if (*option == '+')
4698 break;
4699 i++;
cristybb503372010-05-27 20:51:26 +00004700 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004701 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004702 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004703 if (gravity < 0)
4704 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4705 argv[i]);
4706 break;
4707 }
4708 if (LocaleCompare("green-primary",option+1) == 0)
4709 {
4710 if (*option == '+')
4711 break;
4712 i++;
cristybb503372010-05-27 20:51:26 +00004713 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004714 ThrowMogrifyException(OptionError,"MissingArgument",option);
4715 if (IsGeometry(argv[i]) == MagickFalse)
4716 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4717 break;
4718 }
4719 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4720 }
4721 case 'h':
4722 {
4723 if (LocaleCompare("hald-clut",option+1) == 0)
4724 break;
4725 if ((LocaleCompare("help",option+1) == 0) ||
4726 (LocaleCompare("-help",option+1) == 0))
4727 return(MogrifyUsage());
4728 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4729 }
4730 case 'i':
4731 {
4732 if (LocaleCompare("identify",option+1) == 0)
4733 break;
4734 if (LocaleCompare("idft",option+1) == 0)
4735 break;
4736 if (LocaleCompare("implode",option+1) == 0)
4737 {
4738 if (*option == '+')
4739 break;
4740 i++;
cristybb503372010-05-27 20:51:26 +00004741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004742 ThrowMogrifyException(OptionError,"MissingArgument",option);
4743 if (IsGeometry(argv[i]) == MagickFalse)
4744 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4745 break;
4746 }
4747 if (LocaleCompare("intent",option+1) == 0)
4748 {
cristybb503372010-05-27 20:51:26 +00004749 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004750 intent;
4751
4752 if (*option == '+')
4753 break;
4754 i++;
cristybb503372010-05-27 20:51:26 +00004755 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004756 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004757 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004758 if (intent < 0)
4759 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4760 argv[i]);
4761 break;
4762 }
4763 if (LocaleCompare("interlace",option+1) == 0)
4764 {
cristybb503372010-05-27 20:51:26 +00004765 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004766 interlace;
4767
4768 if (*option == '+')
4769 break;
4770 i++;
cristybb503372010-05-27 20:51:26 +00004771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004772 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004773 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004774 argv[i]);
4775 if (interlace < 0)
4776 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4777 argv[i]);
4778 break;
4779 }
cristyb32b90a2009-09-07 21:45:48 +00004780 if (LocaleCompare("interline-spacing",option+1) == 0)
4781 {
4782 if (*option == '+')
4783 break;
4784 i++;
cristybb503372010-05-27 20:51:26 +00004785 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004786 ThrowMogrifyException(OptionError,"MissingArgument",option);
4787 if (IsGeometry(argv[i]) == MagickFalse)
4788 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4789 break;
4790 }
cristy3ed852e2009-09-05 21:47:34 +00004791 if (LocaleCompare("interpolate",option+1) == 0)
4792 {
cristybb503372010-05-27 20:51:26 +00004793 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004794 interpolate;
4795
4796 if (*option == '+')
4797 break;
4798 i++;
cristybb503372010-05-27 20:51:26 +00004799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004800 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004801 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004802 argv[i]);
4803 if (interpolate < 0)
4804 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4805 argv[i]);
4806 break;
4807 }
4808 if (LocaleCompare("interword-spacing",option+1) == 0)
4809 {
4810 if (*option == '+')
4811 break;
4812 i++;
cristybb503372010-05-27 20:51:26 +00004813 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004814 ThrowMogrifyException(OptionError,"MissingArgument",option);
4815 if (IsGeometry(argv[i]) == MagickFalse)
4816 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4817 break;
4818 }
4819 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4820 }
4821 case 'k':
4822 {
4823 if (LocaleCompare("kerning",option+1) == 0)
4824 {
4825 if (*option == '+')
4826 break;
4827 i++;
cristybb503372010-05-27 20:51:26 +00004828 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004829 ThrowMogrifyException(OptionError,"MissingArgument",option);
4830 if (IsGeometry(argv[i]) == MagickFalse)
4831 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4832 break;
4833 }
4834 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4835 }
4836 case 'l':
4837 {
4838 if (LocaleCompare("label",option+1) == 0)
4839 {
4840 if (*option == '+')
4841 break;
4842 i++;
cristybb503372010-05-27 20:51:26 +00004843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004844 ThrowMogrifyException(OptionError,"MissingArgument",option);
4845 break;
4846 }
4847 if (LocaleCompare("lat",option+1) == 0)
4848 {
4849 if (*option == '+')
4850 break;
4851 i++;
cristybb503372010-05-27 20:51:26 +00004852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004853 ThrowMogrifyException(OptionError,"MissingArgument",option);
4854 if (IsGeometry(argv[i]) == MagickFalse)
4855 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4856 }
4857 if (LocaleCompare("layers",option+1) == 0)
4858 {
cristybb503372010-05-27 20:51:26 +00004859 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004860 type;
4861
4862 if (*option == '+')
4863 break;
4864 i++;
cristybb503372010-05-27 20:51:26 +00004865 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004866 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004867 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004868 if (type < 0)
4869 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4870 argv[i]);
4871 break;
4872 }
4873 if (LocaleCompare("level",option+1) == 0)
4874 {
4875 i++;
cristybb503372010-05-27 20:51:26 +00004876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004877 ThrowMogrifyException(OptionError,"MissingArgument",option);
4878 if (IsGeometry(argv[i]) == MagickFalse)
4879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4880 break;
4881 }
4882 if (LocaleCompare("level-colors",option+1) == 0)
4883 {
4884 i++;
cristybb503372010-05-27 20:51:26 +00004885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004886 ThrowMogrifyException(OptionError,"MissingArgument",option);
4887 break;
4888 }
4889 if (LocaleCompare("linewidth",option+1) == 0)
4890 {
4891 if (*option == '+')
4892 break;
4893 i++;
cristybb503372010-05-27 20:51:26 +00004894 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004895 ThrowMogrifyException(OptionError,"MissingArgument",option);
4896 if (IsGeometry(argv[i]) == MagickFalse)
4897 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4898 break;
4899 }
4900 if (LocaleCompare("limit",option+1) == 0)
4901 {
4902 char
4903 *p;
4904
4905 double
4906 value;
4907
cristybb503372010-05-27 20:51:26 +00004908 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004909 resource;
4910
4911 if (*option == '+')
4912 break;
4913 i++;
cristybb503372010-05-27 20:51:26 +00004914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004915 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004916 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004917 argv[i]);
4918 if (resource < 0)
4919 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4920 argv[i]);
4921 i++;
cristybb503372010-05-27 20:51:26 +00004922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004923 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004924 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004925 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004926 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4928 break;
4929 }
4930 if (LocaleCompare("liquid-rescale",option+1) == 0)
4931 {
4932 i++;
cristybb503372010-05-27 20:51:26 +00004933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004934 ThrowMogrifyException(OptionError,"MissingArgument",option);
4935 if (IsGeometry(argv[i]) == MagickFalse)
4936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4937 break;
4938 }
4939 if (LocaleCompare("list",option+1) == 0)
4940 {
cristybb503372010-05-27 20:51:26 +00004941 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004942 list;
4943
4944 if (*option == '+')
4945 break;
4946 i++;
cristybb503372010-05-27 20:51:26 +00004947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004948 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004949 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004950 if (list < 0)
4951 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004952 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004953 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004954 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004955 }
4956 if (LocaleCompare("log",option+1) == 0)
4957 {
4958 if (*option == '+')
4959 break;
4960 i++;
cristybb503372010-05-27 20:51:26 +00004961 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004962 (strchr(argv[i],'%') == (char *) NULL))
4963 ThrowMogrifyException(OptionError,"MissingArgument",option);
4964 break;
4965 }
4966 if (LocaleCompare("loop",option+1) == 0)
4967 {
4968 if (*option == '+')
4969 break;
4970 i++;
cristybb503372010-05-27 20:51:26 +00004971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004972 ThrowMogrifyException(OptionError,"MissingArgument",option);
4973 if (IsGeometry(argv[i]) == MagickFalse)
4974 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4975 break;
4976 }
4977 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4978 }
4979 case 'm':
4980 {
4981 if (LocaleCompare("map",option+1) == 0)
4982 {
4983 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4984 if (*option == '+')
4985 break;
4986 i++;
cristybb503372010-05-27 20:51:26 +00004987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004988 ThrowMogrifyException(OptionError,"MissingArgument",option);
4989 break;
4990 }
4991 if (LocaleCompare("mask",option+1) == 0)
4992 {
4993 if (*option == '+')
4994 break;
4995 i++;
cristybb503372010-05-27 20:51:26 +00004996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004997 ThrowMogrifyException(OptionError,"MissingArgument",option);
4998 break;
4999 }
5000 if (LocaleCompare("matte",option+1) == 0)
5001 break;
5002 if (LocaleCompare("mattecolor",option+1) == 0)
5003 {
5004 if (*option == '+')
5005 break;
5006 i++;
cristybb503372010-05-27 20:51:26 +00005007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005008 ThrowMogrifyException(OptionError,"MissingArgument",option);
5009 break;
5010 }
cristyf40785b2010-03-06 02:27:27 +00005011 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005012 break;
cristyf40785b2010-03-06 02:27:27 +00005013 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005014 break;
cristy3ed852e2009-09-05 21:47:34 +00005015 if (LocaleCompare("modulate",option+1) == 0)
5016 {
5017 if (*option == '+')
5018 break;
5019 i++;
cristybb503372010-05-27 20:51:26 +00005020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005021 ThrowMogrifyException(OptionError,"MissingArgument",option);
5022 if (IsGeometry(argv[i]) == MagickFalse)
5023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5024 break;
5025 }
5026 if (LocaleCompare("median",option+1) == 0)
5027 {
5028 if (*option == '+')
5029 break;
5030 i++;
cristybb503372010-05-27 20:51:26 +00005031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005032 ThrowMogrifyException(OptionError,"MissingArgument",option);
5033 if (IsGeometry(argv[i]) == MagickFalse)
5034 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5035 break;
5036 }
cristy69ec32d2011-02-27 23:57:09 +00005037 if (LocaleCompare("mode",option+1) == 0)
5038 {
5039 if (*option == '+')
5040 break;
5041 i++;
5042 if (i == (ssize_t) argc)
5043 ThrowMogrifyException(OptionError,"MissingArgument",option);
5044 if (IsGeometry(argv[i]) == MagickFalse)
5045 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5046 break;
5047 }
cristy3ed852e2009-09-05 21:47:34 +00005048 if (LocaleCompare("monitor",option+1) == 0)
5049 break;
5050 if (LocaleCompare("monochrome",option+1) == 0)
5051 break;
5052 if (LocaleCompare("morph",option+1) == 0)
5053 {
5054 if (*option == '+')
5055 break;
5056 i++;
cristybb503372010-05-27 20:51:26 +00005057 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005058 ThrowMogrifyException(OptionError,"MissingArgument",option);
5059 if (IsGeometry(argv[i]) == MagickFalse)
5060 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5061 break;
5062 }
anthony29188a82010-01-22 10:12:34 +00005063 if (LocaleCompare("morphology",option+1) == 0)
5064 {
anthony29188a82010-01-22 10:12:34 +00005065 char
5066 token[MaxTextExtent];
5067
cristyb6bd4ad2010-08-08 01:12:27 +00005068 KernelInfo
5069 *kernel_info;
5070
5071 ssize_t
5072 op;
5073
anthony29188a82010-01-22 10:12:34 +00005074 i++;
cristybb503372010-05-27 20:51:26 +00005075 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005076 ThrowMogrifyException(OptionError,"MissingArgument",option);
5077 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005078 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005079 if (op < 0)
5080 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005081 token);
anthony29188a82010-01-22 10:12:34 +00005082 i++;
cristybb503372010-05-27 20:51:26 +00005083 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005084 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005085 kernel_info=AcquireKernelInfo(argv[i]);
5086 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005087 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005088 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005089 break;
5090 }
cristy3ed852e2009-09-05 21:47:34 +00005091 if (LocaleCompare("mosaic",option+1) == 0)
5092 break;
5093 if (LocaleCompare("motion-blur",option+1) == 0)
5094 {
5095 if (*option == '+')
5096 break;
5097 i++;
cristybb503372010-05-27 20:51:26 +00005098 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005099 ThrowMogrifyException(OptionError,"MissingArgument",option);
5100 if (IsGeometry(argv[i]) == MagickFalse)
5101 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5102 break;
5103 }
5104 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5105 }
5106 case 'n':
5107 {
5108 if (LocaleCompare("negate",option+1) == 0)
5109 break;
5110 if (LocaleCompare("noise",option+1) == 0)
5111 {
5112 i++;
cristybb503372010-05-27 20:51:26 +00005113 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005114 ThrowMogrifyException(OptionError,"MissingArgument",option);
5115 if (*option == '+')
5116 {
cristybb503372010-05-27 20:51:26 +00005117 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005118 noise;
5119
cristy042ee782011-04-22 18:48:30 +00005120 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005121 if (noise < 0)
5122 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5123 argv[i]);
5124 break;
5125 }
5126 if (IsGeometry(argv[i]) == MagickFalse)
5127 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5128 break;
5129 }
5130 if (LocaleCompare("noop",option+1) == 0)
5131 break;
5132 if (LocaleCompare("normalize",option+1) == 0)
5133 break;
5134 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5135 }
5136 case 'o':
5137 {
5138 if (LocaleCompare("opaque",option+1) == 0)
5139 {
cristy3ed852e2009-09-05 21:47:34 +00005140 i++;
cristybb503372010-05-27 20:51:26 +00005141 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005142 ThrowMogrifyException(OptionError,"MissingArgument",option);
5143 break;
5144 }
5145 if (LocaleCompare("ordered-dither",option+1) == 0)
5146 {
5147 if (*option == '+')
5148 break;
5149 i++;
cristybb503372010-05-27 20:51:26 +00005150 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005151 ThrowMogrifyException(OptionError,"MissingArgument",option);
5152 break;
5153 }
5154 if (LocaleCompare("orient",option+1) == 0)
5155 {
cristybb503372010-05-27 20:51:26 +00005156 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005157 orientation;
5158
5159 orientation=UndefinedOrientation;
5160 if (*option == '+')
5161 break;
5162 i++;
cristybb503372010-05-27 20:51:26 +00005163 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005164 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005165 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005166 argv[i]);
5167 if (orientation < 0)
5168 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5169 argv[i]);
5170 break;
5171 }
5172 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5173 }
5174 case 'p':
5175 {
5176 if (LocaleCompare("page",option+1) == 0)
5177 {
5178 if (*option == '+')
5179 break;
5180 i++;
cristybb503372010-05-27 20:51:26 +00005181 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005182 ThrowMogrifyException(OptionError,"MissingArgument",option);
5183 break;
5184 }
5185 if (LocaleCompare("paint",option+1) == 0)
5186 {
5187 if (*option == '+')
5188 break;
5189 i++;
cristybb503372010-05-27 20:51:26 +00005190 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005191 ThrowMogrifyException(OptionError,"MissingArgument",option);
5192 if (IsGeometry(argv[i]) == MagickFalse)
5193 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5194 break;
5195 }
5196 if (LocaleCompare("path",option+1) == 0)
5197 {
5198 (void) CloneString(&path,(char *) NULL);
5199 if (*option == '+')
5200 break;
5201 i++;
cristybb503372010-05-27 20:51:26 +00005202 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005203 ThrowMogrifyException(OptionError,"MissingArgument",option);
5204 (void) CloneString(&path,argv[i]);
5205 break;
5206 }
5207 if (LocaleCompare("pointsize",option+1) == 0)
5208 {
5209 if (*option == '+')
5210 break;
5211 i++;
cristybb503372010-05-27 20:51:26 +00005212 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005213 ThrowMogrifyException(OptionError,"MissingArgument",option);
5214 if (IsGeometry(argv[i]) == MagickFalse)
5215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5216 break;
5217 }
5218 if (LocaleCompare("polaroid",option+1) == 0)
5219 {
5220 if (*option == '+')
5221 break;
5222 i++;
cristybb503372010-05-27 20:51:26 +00005223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005224 ThrowMogrifyException(OptionError,"MissingArgument",option);
5225 if (IsGeometry(argv[i]) == MagickFalse)
5226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5227 break;
5228 }
5229 if (LocaleCompare("posterize",option+1) == 0)
5230 {
5231 if (*option == '+')
5232 break;
5233 i++;
cristybb503372010-05-27 20:51:26 +00005234 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005235 ThrowMogrifyException(OptionError,"MissingArgument",option);
5236 if (IsGeometry(argv[i]) == MagickFalse)
5237 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5238 break;
5239 }
cristye7f51092010-01-17 00:39:37 +00005240 if (LocaleCompare("precision",option+1) == 0)
5241 {
5242 if (*option == '+')
5243 break;
5244 i++;
cristybb503372010-05-27 20:51:26 +00005245 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005246 ThrowMogrifyException(OptionError,"MissingArgument",option);
5247 if (IsGeometry(argv[i]) == MagickFalse)
5248 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5249 break;
5250 }
cristy3ed852e2009-09-05 21:47:34 +00005251 if (LocaleCompare("print",option+1) == 0)
5252 {
5253 if (*option == '+')
5254 break;
5255 i++;
cristybb503372010-05-27 20:51:26 +00005256 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005257 ThrowMogrifyException(OptionError,"MissingArgument",option);
5258 break;
5259 }
5260 if (LocaleCompare("process",option+1) == 0)
5261 {
5262 if (*option == '+')
5263 break;
5264 i++;
cristybb503372010-05-27 20:51:26 +00005265 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005266 ThrowMogrifyException(OptionError,"MissingArgument",option);
5267 break;
5268 }
5269 if (LocaleCompare("profile",option+1) == 0)
5270 {
5271 i++;
cristybb503372010-05-27 20:51:26 +00005272 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005273 ThrowMogrifyException(OptionError,"MissingArgument",option);
5274 break;
5275 }
5276 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5277 }
5278 case 'q':
5279 {
5280 if (LocaleCompare("quality",option+1) == 0)
5281 {
5282 if (*option == '+')
5283 break;
5284 i++;
cristybb503372010-05-27 20:51:26 +00005285 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005286 ThrowMogrifyException(OptionError,"MissingArgument",option);
5287 if (IsGeometry(argv[i]) == MagickFalse)
5288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5289 break;
5290 }
5291 if (LocaleCompare("quantize",option+1) == 0)
5292 {
cristybb503372010-05-27 20:51:26 +00005293 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005294 colorspace;
5295
5296 if (*option == '+')
5297 break;
5298 i++;
cristybb503372010-05-27 20:51:26 +00005299 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005300 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005301 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005302 argv[i]);
5303 if (colorspace < 0)
5304 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5305 argv[i]);
5306 break;
5307 }
5308 if (LocaleCompare("quiet",option+1) == 0)
5309 break;
5310 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5311 }
5312 case 'r':
5313 {
5314 if (LocaleCompare("radial-blur",option+1) == 0)
5315 {
5316 i++;
cristybb503372010-05-27 20:51:26 +00005317 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005318 ThrowMogrifyException(OptionError,"MissingArgument",option);
5319 if (IsGeometry(argv[i]) == MagickFalse)
5320 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5321 break;
5322 }
5323 if (LocaleCompare("raise",option+1) == 0)
5324 {
5325 i++;
cristybb503372010-05-27 20:51:26 +00005326 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005327 ThrowMogrifyException(OptionError,"MissingArgument",option);
5328 if (IsGeometry(argv[i]) == MagickFalse)
5329 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5330 break;
5331 }
5332 if (LocaleCompare("random-threshold",option+1) == 0)
5333 {
5334 if (*option == '+')
5335 break;
5336 i++;
cristybb503372010-05-27 20:51:26 +00005337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005338 ThrowMogrifyException(OptionError,"MissingArgument",option);
5339 if (IsGeometry(argv[i]) == MagickFalse)
5340 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5341 break;
5342 }
cristye6365592010-04-02 17:31:23 +00005343 if (LocaleCompare("recolor",option+1) == 0)
5344 {
5345 if (*option == '+')
5346 break;
5347 i++;
cristybb503372010-05-27 20:51:26 +00005348 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005349 ThrowMogrifyException(OptionError,"MissingArgument",option);
5350 if (IsGeometry(argv[i]) == MagickFalse)
5351 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5352 break;
5353 }
cristy3ed852e2009-09-05 21:47:34 +00005354 if (LocaleCompare("red-primary",option+1) == 0)
5355 {
5356 if (*option == '+')
5357 break;
5358 i++;
cristybb503372010-05-27 20:51:26 +00005359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005360 ThrowMogrifyException(OptionError,"MissingArgument",option);
5361 if (IsGeometry(argv[i]) == MagickFalse)
5362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5363 }
cristy9f2083a2010-04-22 19:48:05 +00005364 if (LocaleCompare("regard-warnings",option+1) == 0)
5365 break;
cristy3ed852e2009-09-05 21:47:34 +00005366 if (LocaleCompare("region",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
cristybb503372010-05-27 20:51:26 +00005371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 break;
5376 }
cristyf0c78232010-03-15 12:53:40 +00005377 if (LocaleCompare("remap",option+1) == 0)
5378 {
5379 if (*option == '+')
5380 break;
5381 i++;
cristybb503372010-05-27 20:51:26 +00005382 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005383 ThrowMogrifyException(OptionError,"MissingArgument",option);
5384 break;
5385 }
cristy3ed852e2009-09-05 21:47:34 +00005386 if (LocaleCompare("render",option+1) == 0)
5387 break;
5388 if (LocaleCompare("repage",option+1) == 0)
5389 {
5390 if (*option == '+')
5391 break;
5392 i++;
cristybb503372010-05-27 20:51:26 +00005393 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005394 ThrowMogrifyException(OptionError,"MissingArgument",option);
5395 if (IsGeometry(argv[i]) == MagickFalse)
5396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5397 break;
5398 }
5399 if (LocaleCompare("resample",option+1) == 0)
5400 {
5401 if (*option == '+')
5402 break;
5403 i++;
cristybb503372010-05-27 20:51:26 +00005404 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005405 ThrowMogrifyException(OptionError,"MissingArgument",option);
5406 if (IsGeometry(argv[i]) == MagickFalse)
5407 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5408 break;
5409 }
5410 if (LocaleCompare("resize",option+1) == 0)
5411 {
5412 if (*option == '+')
5413 break;
5414 i++;
cristybb503372010-05-27 20:51:26 +00005415 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005416 ThrowMogrifyException(OptionError,"MissingArgument",option);
5417 if (IsGeometry(argv[i]) == MagickFalse)
5418 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5419 break;
5420 }
cristyebbcfea2011-02-25 02:43:54 +00005421 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5422 {
5423 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5424 break;
5425 }
cristy3ed852e2009-09-05 21:47:34 +00005426 if (LocaleCompare("reverse",option+1) == 0)
5427 break;
5428 if (LocaleCompare("roll",option+1) == 0)
5429 {
5430 if (*option == '+')
5431 break;
5432 i++;
cristybb503372010-05-27 20:51:26 +00005433 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005434 ThrowMogrifyException(OptionError,"MissingArgument",option);
5435 if (IsGeometry(argv[i]) == MagickFalse)
5436 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5437 break;
5438 }
5439 if (LocaleCompare("rotate",option+1) == 0)
5440 {
5441 i++;
cristybb503372010-05-27 20:51:26 +00005442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005443 ThrowMogrifyException(OptionError,"MissingArgument",option);
5444 if (IsGeometry(argv[i]) == MagickFalse)
5445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5446 break;
5447 }
5448 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5449 }
5450 case 's':
5451 {
5452 if (LocaleCompare("sample",option+1) == 0)
5453 {
5454 if (*option == '+')
5455 break;
5456 i++;
cristybb503372010-05-27 20:51:26 +00005457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005458 ThrowMogrifyException(OptionError,"MissingArgument",option);
5459 if (IsGeometry(argv[i]) == MagickFalse)
5460 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5461 break;
5462 }
5463 if (LocaleCompare("sampling-factor",option+1) == 0)
5464 {
5465 if (*option == '+')
5466 break;
5467 i++;
cristybb503372010-05-27 20:51:26 +00005468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005469 ThrowMogrifyException(OptionError,"MissingArgument",option);
5470 if (IsGeometry(argv[i]) == MagickFalse)
5471 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5472 break;
5473 }
5474 if (LocaleCompare("scale",option+1) == 0)
5475 {
5476 if (*option == '+')
5477 break;
5478 i++;
cristybb503372010-05-27 20:51:26 +00005479 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005480 ThrowMogrifyException(OptionError,"MissingArgument",option);
5481 if (IsGeometry(argv[i]) == MagickFalse)
5482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5483 break;
5484 }
5485 if (LocaleCompare("scene",option+1) == 0)
5486 {
5487 if (*option == '+')
5488 break;
5489 i++;
cristybb503372010-05-27 20:51:26 +00005490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005491 ThrowMogrifyException(OptionError,"MissingArgument",option);
5492 if (IsGeometry(argv[i]) == MagickFalse)
5493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5494 break;
5495 }
5496 if (LocaleCompare("seed",option+1) == 0)
5497 {
5498 if (*option == '+')
5499 break;
5500 i++;
cristybb503372010-05-27 20:51:26 +00005501 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005502 ThrowMogrifyException(OptionError,"MissingArgument",option);
5503 if (IsGeometry(argv[i]) == MagickFalse)
5504 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5505 break;
5506 }
5507 if (LocaleCompare("segment",option+1) == 0)
5508 {
5509 if (*option == '+')
5510 break;
5511 i++;
cristybb503372010-05-27 20:51:26 +00005512 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005513 ThrowMogrifyException(OptionError,"MissingArgument",option);
5514 if (IsGeometry(argv[i]) == MagickFalse)
5515 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5516 break;
5517 }
5518 if (LocaleCompare("selective-blur",option+1) == 0)
5519 {
5520 i++;
cristybb503372010-05-27 20:51:26 +00005521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005522 ThrowMogrifyException(OptionError,"MissingArgument",option);
5523 if (IsGeometry(argv[i]) == MagickFalse)
5524 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5525 break;
5526 }
5527 if (LocaleCompare("separate",option+1) == 0)
5528 break;
5529 if (LocaleCompare("sepia-tone",option+1) == 0)
5530 {
5531 if (*option == '+')
5532 break;
5533 i++;
cristybb503372010-05-27 20:51:26 +00005534 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005535 ThrowMogrifyException(OptionError,"MissingArgument",option);
5536 if (IsGeometry(argv[i]) == MagickFalse)
5537 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5538 break;
5539 }
5540 if (LocaleCompare("set",option+1) == 0)
5541 {
5542 i++;
cristybb503372010-05-27 20:51:26 +00005543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005544 ThrowMogrifyException(OptionError,"MissingArgument",option);
5545 if (*option == '+')
5546 break;
5547 i++;
cristybb503372010-05-27 20:51:26 +00005548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005549 ThrowMogrifyException(OptionError,"MissingArgument",option);
5550 break;
5551 }
5552 if (LocaleCompare("shade",option+1) == 0)
5553 {
5554 i++;
cristybb503372010-05-27 20:51:26 +00005555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005556 ThrowMogrifyException(OptionError,"MissingArgument",option);
5557 if (IsGeometry(argv[i]) == MagickFalse)
5558 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5559 break;
5560 }
5561 if (LocaleCompare("shadow",option+1) == 0)
5562 {
5563 if (*option == '+')
5564 break;
5565 i++;
cristybb503372010-05-27 20:51:26 +00005566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005567 ThrowMogrifyException(OptionError,"MissingArgument",option);
5568 if (IsGeometry(argv[i]) == MagickFalse)
5569 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5570 break;
5571 }
5572 if (LocaleCompare("sharpen",option+1) == 0)
5573 {
5574 i++;
cristybb503372010-05-27 20:51:26 +00005575 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005576 ThrowMogrifyException(OptionError,"MissingArgument",option);
5577 if (IsGeometry(argv[i]) == MagickFalse)
5578 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5579 break;
5580 }
5581 if (LocaleCompare("shave",option+1) == 0)
5582 {
5583 if (*option == '+')
5584 break;
5585 i++;
cristybb503372010-05-27 20:51:26 +00005586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 if (IsGeometry(argv[i]) == MagickFalse)
5589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5590 break;
5591 }
5592 if (LocaleCompare("shear",option+1) == 0)
5593 {
5594 i++;
cristybb503372010-05-27 20:51:26 +00005595 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005596 ThrowMogrifyException(OptionError,"MissingArgument",option);
5597 if (IsGeometry(argv[i]) == MagickFalse)
5598 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5599 break;
5600 }
5601 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5602 {
5603 i++;
cristybb503372010-05-27 20:51:26 +00005604 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005605 ThrowMogrifyException(OptionError,"MissingArgument",option);
5606 if (IsGeometry(argv[i]) == MagickFalse)
5607 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5608 break;
5609 }
5610 if (LocaleCompare("size",option+1) == 0)
5611 {
5612 if (*option == '+')
5613 break;
5614 i++;
cristybb503372010-05-27 20:51:26 +00005615 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005616 ThrowMogrifyException(OptionError,"MissingArgument",option);
5617 if (IsGeometry(argv[i]) == MagickFalse)
5618 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5619 break;
5620 }
5621 if (LocaleCompare("sketch",option+1) == 0)
5622 {
5623 if (*option == '+')
5624 break;
5625 i++;
cristybb503372010-05-27 20:51:26 +00005626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005627 ThrowMogrifyException(OptionError,"MissingArgument",option);
5628 if (IsGeometry(argv[i]) == MagickFalse)
5629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5630 break;
5631 }
cristy4285d782011-02-09 20:12:28 +00005632 if (LocaleCompare("smush",option+1) == 0)
5633 {
cristy4285d782011-02-09 20:12:28 +00005634 i++;
5635 if (i == (ssize_t) argc)
5636 ThrowMogrifyException(OptionError,"MissingArgument",option);
5637 if (IsGeometry(argv[i]) == MagickFalse)
5638 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005639 i++;
5640 break;
5641 }
cristy3ed852e2009-09-05 21:47:34 +00005642 if (LocaleCompare("solarize",option+1) == 0)
5643 {
5644 if (*option == '+')
5645 break;
5646 i++;
cristybb503372010-05-27 20:51:26 +00005647 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005648 ThrowMogrifyException(OptionError,"MissingArgument",option);
5649 if (IsGeometry(argv[i]) == MagickFalse)
5650 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5651 break;
5652 }
5653 if (LocaleCompare("sparse-color",option+1) == 0)
5654 {
cristybb503372010-05-27 20:51:26 +00005655 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005656 op;
5657
5658 i++;
cristybb503372010-05-27 20:51:26 +00005659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005660 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005661 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005662 if (op < 0)
5663 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5664 argv[i]);
5665 i++;
cristybb503372010-05-27 20:51:26 +00005666 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005667 ThrowMogrifyException(OptionError,"MissingArgument",option);
5668 break;
5669 }
5670 if (LocaleCompare("spread",option+1) == 0)
5671 {
5672 if (*option == '+')
5673 break;
5674 i++;
cristybb503372010-05-27 20:51:26 +00005675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005676 ThrowMogrifyException(OptionError,"MissingArgument",option);
5677 if (IsGeometry(argv[i]) == MagickFalse)
5678 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5679 break;
5680 }
cristy0834d642011-03-18 18:26:08 +00005681 if (LocaleCompare("statistic",option+1) == 0)
5682 {
5683 ssize_t
5684 op;
5685
5686 if (*option == '+')
5687 break;
5688 i++;
5689 if (i == (ssize_t) argc)
5690 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005691 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005692 if (op < 0)
5693 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5694 argv[i]);
5695 i++;
5696 if (i == (ssize_t) (argc-1))
5697 ThrowMogrifyException(OptionError,"MissingArgument",option);
5698 if (IsGeometry(argv[i]) == MagickFalse)
5699 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5700 break;
5701 }
cristy3ed852e2009-09-05 21:47:34 +00005702 if (LocaleCompare("stretch",option+1) == 0)
5703 {
cristybb503372010-05-27 20:51:26 +00005704 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005705 stretch;
5706
5707 if (*option == '+')
5708 break;
5709 i++;
cristybb503372010-05-27 20:51:26 +00005710 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005711 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005712 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005713 if (stretch < 0)
5714 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5715 argv[i]);
5716 break;
5717 }
5718 if (LocaleCompare("strip",option+1) == 0)
5719 break;
5720 if (LocaleCompare("stroke",option+1) == 0)
5721 {
5722 if (*option == '+')
5723 break;
5724 i++;
cristybb503372010-05-27 20:51:26 +00005725 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005726 ThrowMogrifyException(OptionError,"MissingArgument",option);
5727 break;
5728 }
5729 if (LocaleCompare("strokewidth",option+1) == 0)
5730 {
5731 if (*option == '+')
5732 break;
5733 i++;
cristybb503372010-05-27 20:51:26 +00005734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005735 ThrowMogrifyException(OptionError,"MissingArgument",option);
5736 if (IsGeometry(argv[i]) == MagickFalse)
5737 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5738 break;
5739 }
5740 if (LocaleCompare("style",option+1) == 0)
5741 {
cristybb503372010-05-27 20:51:26 +00005742 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005743 style;
5744
5745 if (*option == '+')
5746 break;
5747 i++;
cristybb503372010-05-27 20:51:26 +00005748 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005749 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005750 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005751 if (style < 0)
5752 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5753 argv[i]);
5754 break;
5755 }
cristyecb10ff2011-03-22 13:14:03 +00005756 if (LocaleCompare("swap",option+1) == 0)
5757 {
5758 if (*option == '+')
5759 break;
5760 i++;
5761 if (i == (ssize_t) (argc-1))
5762 ThrowMogrifyException(OptionError,"MissingArgument",option);
5763 if (IsGeometry(argv[i]) == MagickFalse)
5764 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5765 break;
5766 }
cristy3ed852e2009-09-05 21:47:34 +00005767 if (LocaleCompare("swirl",option+1) == 0)
5768 {
5769 if (*option == '+')
5770 break;
5771 i++;
cristybb503372010-05-27 20:51:26 +00005772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005773 ThrowMogrifyException(OptionError,"MissingArgument",option);
5774 if (IsGeometry(argv[i]) == MagickFalse)
5775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5776 break;
5777 }
cristyd9a29192010-10-16 16:49:53 +00005778 if (LocaleCompare("synchronize",option+1) == 0)
5779 break;
cristy3ed852e2009-09-05 21:47:34 +00005780 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5781 }
5782 case 't':
5783 {
5784 if (LocaleCompare("taint",option+1) == 0)
5785 break;
5786 if (LocaleCompare("texture",option+1) == 0)
5787 {
5788 if (*option == '+')
5789 break;
5790 i++;
cristybb503372010-05-27 20:51:26 +00005791 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005792 ThrowMogrifyException(OptionError,"MissingArgument",option);
5793 break;
5794 }
5795 if (LocaleCompare("tile",option+1) == 0)
5796 {
5797 if (*option == '+')
5798 break;
5799 i++;
cristybb503372010-05-27 20:51:26 +00005800 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005801 ThrowMogrifyException(OptionError,"MissingArgument",option);
5802 break;
5803 }
5804 if (LocaleCompare("tile-offset",option+1) == 0)
5805 {
5806 if (*option == '+')
5807 break;
5808 i++;
cristybb503372010-05-27 20:51:26 +00005809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005810 ThrowMogrifyException(OptionError,"MissingArgument",option);
5811 if (IsGeometry(argv[i]) == MagickFalse)
5812 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5813 break;
5814 }
5815 if (LocaleCompare("tint",option+1) == 0)
5816 {
5817 if (*option == '+')
5818 break;
5819 i++;
cristybb503372010-05-27 20:51:26 +00005820 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005821 ThrowMogrifyException(OptionError,"MissingArgument",option);
5822 if (IsGeometry(argv[i]) == MagickFalse)
5823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5824 break;
5825 }
5826 if (LocaleCompare("transform",option+1) == 0)
5827 break;
5828 if (LocaleCompare("transpose",option+1) == 0)
5829 break;
5830 if (LocaleCompare("transverse",option+1) == 0)
5831 break;
5832 if (LocaleCompare("threshold",option+1) == 0)
5833 {
5834 if (*option == '+')
5835 break;
5836 i++;
cristybb503372010-05-27 20:51:26 +00005837 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005838 ThrowMogrifyException(OptionError,"MissingArgument",option);
5839 if (IsGeometry(argv[i]) == MagickFalse)
5840 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5841 break;
5842 }
5843 if (LocaleCompare("thumbnail",option+1) == 0)
5844 {
5845 if (*option == '+')
5846 break;
5847 i++;
cristybb503372010-05-27 20:51:26 +00005848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005849 ThrowMogrifyException(OptionError,"MissingArgument",option);
5850 if (IsGeometry(argv[i]) == MagickFalse)
5851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5852 break;
5853 }
5854 if (LocaleCompare("transparent",option+1) == 0)
5855 {
5856 i++;
cristybb503372010-05-27 20:51:26 +00005857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005858 ThrowMogrifyException(OptionError,"MissingArgument",option);
5859 break;
5860 }
5861 if (LocaleCompare("transparent-color",option+1) == 0)
5862 {
5863 if (*option == '+')
5864 break;
5865 i++;
cristybb503372010-05-27 20:51:26 +00005866 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005867 ThrowMogrifyException(OptionError,"MissingArgument",option);
5868 break;
5869 }
5870 if (LocaleCompare("treedepth",option+1) == 0)
5871 {
5872 if (*option == '+')
5873 break;
5874 i++;
cristybb503372010-05-27 20:51:26 +00005875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005876 ThrowMogrifyException(OptionError,"MissingArgument",option);
5877 if (IsGeometry(argv[i]) == MagickFalse)
5878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5879 break;
5880 }
5881 if (LocaleCompare("trim",option+1) == 0)
5882 break;
5883 if (LocaleCompare("type",option+1) == 0)
5884 {
cristybb503372010-05-27 20:51:26 +00005885 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005886 type;
5887
5888 if (*option == '+')
5889 break;
5890 i++;
cristybb503372010-05-27 20:51:26 +00005891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005892 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005893 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005894 if (type < 0)
5895 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5896 argv[i]);
5897 break;
5898 }
5899 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5900 }
5901 case 'u':
5902 {
5903 if (LocaleCompare("undercolor",option+1) == 0)
5904 {
5905 if (*option == '+')
5906 break;
5907 i++;
cristybb503372010-05-27 20:51:26 +00005908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005909 ThrowMogrifyException(OptionError,"MissingArgument",option);
5910 break;
5911 }
5912 if (LocaleCompare("unique-colors",option+1) == 0)
5913 break;
5914 if (LocaleCompare("units",option+1) == 0)
5915 {
cristybb503372010-05-27 20:51:26 +00005916 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005917 units;
5918
5919 if (*option == '+')
5920 break;
5921 i++;
cristybb503372010-05-27 20:51:26 +00005922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005923 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005924 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005925 argv[i]);
5926 if (units < 0)
5927 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5928 argv[i]);
5929 break;
5930 }
5931 if (LocaleCompare("unsharp",option+1) == 0)
5932 {
5933 i++;
cristybb503372010-05-27 20:51:26 +00005934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005935 ThrowMogrifyException(OptionError,"MissingArgument",option);
5936 if (IsGeometry(argv[i]) == MagickFalse)
5937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5938 break;
5939 }
5940 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5941 }
5942 case 'v':
5943 {
5944 if (LocaleCompare("verbose",option+1) == 0)
5945 {
5946 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5947 break;
5948 }
5949 if ((LocaleCompare("version",option+1) == 0) ||
5950 (LocaleCompare("-version",option+1) == 0))
5951 {
cristyb51dff52011-05-19 16:55:47 +00005952 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005953 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005954 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5955 GetMagickCopyright());
5956 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5957 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005958 break;
5959 }
5960 if (LocaleCompare("view",option+1) == 0)
5961 {
5962 if (*option == '+')
5963 break;
5964 i++;
cristybb503372010-05-27 20:51:26 +00005965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005966 ThrowMogrifyException(OptionError,"MissingArgument",option);
5967 break;
5968 }
5969 if (LocaleCompare("vignette",option+1) == 0)
5970 {
5971 if (*option == '+')
5972 break;
5973 i++;
cristybb503372010-05-27 20:51:26 +00005974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005975 ThrowMogrifyException(OptionError,"MissingArgument",option);
5976 if (IsGeometry(argv[i]) == MagickFalse)
5977 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5978 break;
5979 }
5980 if (LocaleCompare("virtual-pixel",option+1) == 0)
5981 {
cristybb503372010-05-27 20:51:26 +00005982 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005983 method;
5984
5985 if (*option == '+')
5986 break;
5987 i++;
cristybb503372010-05-27 20:51:26 +00005988 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005989 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005990 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005991 argv[i]);
5992 if (method < 0)
5993 ThrowMogrifyException(OptionError,
5994 "UnrecognizedVirtualPixelMethod",argv[i]);
5995 break;
5996 }
5997 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5998 }
5999 case 'w':
6000 {
6001 if (LocaleCompare("wave",option+1) == 0)
6002 {
6003 i++;
cristybb503372010-05-27 20:51:26 +00006004 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006005 ThrowMogrifyException(OptionError,"MissingArgument",option);
6006 if (IsGeometry(argv[i]) == MagickFalse)
6007 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6008 break;
6009 }
6010 if (LocaleCompare("weight",option+1) == 0)
6011 {
6012 if (*option == '+')
6013 break;
6014 i++;
cristybb503372010-05-27 20:51:26 +00006015 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006016 ThrowMogrifyException(OptionError,"MissingArgument",option);
6017 break;
6018 }
6019 if (LocaleCompare("white-point",option+1) == 0)
6020 {
6021 if (*option == '+')
6022 break;
6023 i++;
cristybb503372010-05-27 20:51:26 +00006024 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006025 ThrowMogrifyException(OptionError,"MissingArgument",option);
6026 if (IsGeometry(argv[i]) == MagickFalse)
6027 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6028 break;
6029 }
6030 if (LocaleCompare("white-threshold",option+1) == 0)
6031 {
6032 if (*option == '+')
6033 break;
6034 i++;
cristybb503372010-05-27 20:51:26 +00006035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006036 ThrowMogrifyException(OptionError,"MissingArgument",option);
6037 if (IsGeometry(argv[i]) == MagickFalse)
6038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6039 break;
6040 }
6041 if (LocaleCompare("write",option+1) == 0)
6042 {
6043 i++;
cristybb503372010-05-27 20:51:26 +00006044 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006045 ThrowMogrifyException(OptionError,"MissingArgument",option);
6046 break;
6047 }
6048 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6049 }
6050 case '?':
6051 break;
6052 default:
6053 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6054 }
cristy042ee782011-04-22 18:48:30 +00006055 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6056 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006057 if (fire != MagickFalse)
6058 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6059 }
6060 if (k != 0)
6061 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006062 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006063 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6064 DestroyMogrify();
6065 return(status != 0 ? MagickTrue : MagickFalse);
6066}
6067
6068/*
6069%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6070% %
6071% %
6072% %
6073+ M o g r i f y I m a g e I n f o %
6074% %
6075% %
6076% %
6077%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6078%
6079% MogrifyImageInfo() applies image processing settings to the image as
6080% prescribed by command line options.
6081%
6082% The format of the MogrifyImageInfo method is:
6083%
6084% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6085% const char **argv,ExceptionInfo *exception)
6086%
6087% A description of each parameter follows:
6088%
6089% o image_info: the image info..
6090%
6091% o argc: Specifies a pointer to an integer describing the number of
6092% elements in the argument vector.
6093%
6094% o argv: Specifies a pointer to a text array containing the command line
6095% arguments.
6096%
6097% o exception: return any errors or warnings in this structure.
6098%
6099*/
6100WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6101 const int argc,const char **argv,ExceptionInfo *exception)
6102{
6103 const char
6104 *option;
6105
6106 GeometryInfo
6107 geometry_info;
6108
cristybb503372010-05-27 20:51:26 +00006109 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006110 count;
6111
cristybb503372010-05-27 20:51:26 +00006112 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006113 i;
6114
6115 /*
6116 Initialize method variables.
6117 */
6118 assert(image_info != (ImageInfo *) NULL);
6119 assert(image_info->signature == MagickSignature);
6120 if (image_info->debug != MagickFalse)
6121 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6122 image_info->filename);
6123 if (argc < 0)
6124 return(MagickTrue);
6125 /*
6126 Set the image settings.
6127 */
cristybb503372010-05-27 20:51:26 +00006128 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006129 {
6130 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006131 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006132 continue;
cristy042ee782011-04-22 18:48:30 +00006133 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006134 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006135 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006136 break;
6137 switch (*(option+1))
6138 {
6139 case 'a':
6140 {
6141 if (LocaleCompare("adjoin",option+1) == 0)
6142 {
6143 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6144 break;
6145 }
6146 if (LocaleCompare("antialias",option+1) == 0)
6147 {
6148 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6149 break;
6150 }
6151 if (LocaleCompare("attenuate",option+1) == 0)
6152 {
6153 if (*option == '+')
6154 {
6155 (void) DeleteImageOption(image_info,option+1);
6156 break;
6157 }
6158 (void) SetImageOption(image_info,option+1,argv[i+1]);
6159 break;
6160 }
6161 if (LocaleCompare("authenticate",option+1) == 0)
6162 {
6163 if (*option == '+')
6164 (void) CloneString(&image_info->authenticate,(char *) NULL);
6165 else
6166 (void) CloneString(&image_info->authenticate,argv[i+1]);
6167 break;
6168 }
6169 break;
6170 }
6171 case 'b':
6172 {
6173 if (LocaleCompare("background",option+1) == 0)
6174 {
6175 if (*option == '+')
6176 {
6177 (void) DeleteImageOption(image_info,option+1);
6178 (void) QueryColorDatabase(BackgroundColor,
6179 &image_info->background_color,exception);
6180 break;
6181 }
6182 (void) SetImageOption(image_info,option+1,argv[i+1]);
6183 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6184 exception);
6185 break;
6186 }
6187 if (LocaleCompare("bias",option+1) == 0)
6188 {
6189 if (*option == '+')
6190 {
6191 (void) SetImageOption(image_info,option+1,"0.0");
6192 break;
6193 }
6194 (void) SetImageOption(image_info,option+1,argv[i+1]);
6195 break;
6196 }
6197 if (LocaleCompare("black-point-compensation",option+1) == 0)
6198 {
6199 if (*option == '+')
6200 {
6201 (void) SetImageOption(image_info,option+1,"false");
6202 break;
6203 }
6204 (void) SetImageOption(image_info,option+1,"true");
6205 break;
6206 }
6207 if (LocaleCompare("blue-primary",option+1) == 0)
6208 {
6209 if (*option == '+')
6210 {
6211 (void) SetImageOption(image_info,option+1,"0.0");
6212 break;
6213 }
6214 (void) SetImageOption(image_info,option+1,argv[i+1]);
6215 break;
6216 }
6217 if (LocaleCompare("bordercolor",option+1) == 0)
6218 {
6219 if (*option == '+')
6220 {
6221 (void) DeleteImageOption(image_info,option+1);
6222 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6223 exception);
6224 break;
6225 }
6226 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6227 exception);
6228 (void) SetImageOption(image_info,option+1,argv[i+1]);
6229 break;
6230 }
6231 if (LocaleCompare("box",option+1) == 0)
6232 {
6233 if (*option == '+')
6234 {
6235 (void) SetImageOption(image_info,"undercolor","none");
6236 break;
6237 }
6238 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6239 break;
6240 }
6241 break;
6242 }
6243 case 'c':
6244 {
6245 if (LocaleCompare("cache",option+1) == 0)
6246 {
6247 MagickSizeType
6248 limit;
6249
6250 limit=MagickResourceInfinity;
6251 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006252 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006253 (void) SetMagickResourceLimit(MemoryResource,limit);
6254 (void) SetMagickResourceLimit(MapResource,2*limit);
6255 break;
6256 }
6257 if (LocaleCompare("caption",option+1) == 0)
6258 {
6259 if (*option == '+')
6260 {
6261 (void) DeleteImageOption(image_info,option+1);
6262 break;
6263 }
6264 (void) SetImageOption(image_info,option+1,argv[i+1]);
6265 break;
6266 }
6267 if (LocaleCompare("channel",option+1) == 0)
6268 {
6269 if (*option == '+')
6270 {
6271 image_info->channel=DefaultChannels;
6272 break;
6273 }
6274 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6275 break;
6276 }
6277 if (LocaleCompare("colors",option+1) == 0)
6278 {
cristye27293e2009-12-18 02:53:20 +00006279 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006280 break;
6281 }
6282 if (LocaleCompare("colorspace",option+1) == 0)
6283 {
6284 if (*option == '+')
6285 {
6286 image_info->colorspace=UndefinedColorspace;
6287 (void) SetImageOption(image_info,option+1,"undefined");
6288 break;
6289 }
cristy042ee782011-04-22 18:48:30 +00006290 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006291 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6292 (void) SetImageOption(image_info,option+1,argv[i+1]);
6293 break;
6294 }
cristy3ed852e2009-09-05 21:47:34 +00006295 if (LocaleCompare("comment",option+1) == 0)
6296 {
6297 if (*option == '+')
6298 {
6299 (void) DeleteImageOption(image_info,option+1);
6300 break;
6301 }
6302 (void) SetImageOption(image_info,option+1,argv[i+1]);
6303 break;
6304 }
6305 if (LocaleCompare("compose",option+1) == 0)
6306 {
6307 if (*option == '+')
6308 {
6309 (void) SetImageOption(image_info,option+1,"undefined");
6310 break;
6311 }
6312 (void) SetImageOption(image_info,option+1,argv[i+1]);
6313 break;
6314 }
6315 if (LocaleCompare("compress",option+1) == 0)
6316 {
6317 if (*option == '+')
6318 {
6319 image_info->compression=UndefinedCompression;
6320 (void) SetImageOption(image_info,option+1,"undefined");
6321 break;
6322 }
cristy042ee782011-04-22 18:48:30 +00006323 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006324 MagickCompressOptions,MagickFalse,argv[i+1]);
6325 (void) SetImageOption(image_info,option+1,argv[i+1]);
6326 break;
6327 }
6328 break;
6329 }
6330 case 'd':
6331 {
6332 if (LocaleCompare("debug",option+1) == 0)
6333 {
6334 if (*option == '+')
6335 (void) SetLogEventMask("none");
6336 else
6337 (void) SetLogEventMask(argv[i+1]);
6338 image_info->debug=IsEventLogging();
6339 break;
6340 }
6341 if (LocaleCompare("define",option+1) == 0)
6342 {
6343 if (*option == '+')
6344 {
6345 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6346 (void) DeleteImageRegistry(argv[i+1]+9);
6347 else
6348 (void) DeleteImageOption(image_info,argv[i+1]);
6349 break;
6350 }
6351 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6352 {
6353 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6354 exception);
6355 break;
6356 }
6357 (void) DefineImageOption(image_info,argv[i+1]);
6358 break;
6359 }
6360 if (LocaleCompare("delay",option+1) == 0)
6361 {
6362 if (*option == '+')
6363 {
6364 (void) SetImageOption(image_info,option+1,"0");
6365 break;
6366 }
6367 (void) SetImageOption(image_info,option+1,argv[i+1]);
6368 break;
6369 }
6370 if (LocaleCompare("density",option+1) == 0)
6371 {
6372 /*
6373 Set image density.
6374 */
6375 if (*option == '+')
6376 {
6377 if (image_info->density != (char *) NULL)
6378 image_info->density=DestroyString(image_info->density);
6379 (void) SetImageOption(image_info,option+1,"72");
6380 break;
6381 }
6382 (void) CloneString(&image_info->density,argv[i+1]);
6383 (void) SetImageOption(image_info,option+1,argv[i+1]);
6384 break;
6385 }
6386 if (LocaleCompare("depth",option+1) == 0)
6387 {
6388 if (*option == '+')
6389 {
6390 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6391 break;
6392 }
cristye27293e2009-12-18 02:53:20 +00006393 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006394 break;
6395 }
cristyc9b12952010-03-28 01:12:28 +00006396 if (LocaleCompare("direction",option+1) == 0)
6397 {
6398 if (*option == '+')
6399 {
6400 (void) SetImageOption(image_info,option+1,"undefined");
6401 break;
6402 }
6403 (void) SetImageOption(image_info,option+1,argv[i+1]);
6404 break;
6405 }
cristy3ed852e2009-09-05 21:47:34 +00006406 if (LocaleCompare("display",option+1) == 0)
6407 {
6408 if (*option == '+')
6409 {
6410 if (image_info->server_name != (char *) NULL)
6411 image_info->server_name=DestroyString(
6412 image_info->server_name);
6413 break;
6414 }
6415 (void) CloneString(&image_info->server_name,argv[i+1]);
6416 break;
6417 }
6418 if (LocaleCompare("dispose",option+1) == 0)
6419 {
6420 if (*option == '+')
6421 {
6422 (void) SetImageOption(image_info,option+1,"undefined");
6423 break;
6424 }
6425 (void) SetImageOption(image_info,option+1,argv[i+1]);
6426 break;
6427 }
6428 if (LocaleCompare("dither",option+1) == 0)
6429 {
6430 if (*option == '+')
6431 {
6432 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006433 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006434 break;
6435 }
6436 (void) SetImageOption(image_info,option+1,argv[i+1]);
6437 image_info->dither=MagickTrue;
6438 break;
6439 }
6440 break;
6441 }
6442 case 'e':
6443 {
6444 if (LocaleCompare("encoding",option+1) == 0)
6445 {
6446 if (*option == '+')
6447 {
6448 (void) SetImageOption(image_info,option+1,"undefined");
6449 break;
6450 }
6451 (void) SetImageOption(image_info,option+1,argv[i+1]);
6452 break;
6453 }
6454 if (LocaleCompare("endian",option+1) == 0)
6455 {
6456 if (*option == '+')
6457 {
6458 image_info->endian=UndefinedEndian;
6459 (void) SetImageOption(image_info,option+1,"undefined");
6460 break;
6461 }
cristy042ee782011-04-22 18:48:30 +00006462 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006463 MagickEndianOptions,MagickFalse,argv[i+1]);
6464 (void) SetImageOption(image_info,option+1,argv[i+1]);
6465 break;
6466 }
6467 if (LocaleCompare("extract",option+1) == 0)
6468 {
6469 /*
6470 Set image extract geometry.
6471 */
6472 if (*option == '+')
6473 {
6474 if (image_info->extract != (char *) NULL)
6475 image_info->extract=DestroyString(image_info->extract);
6476 break;
6477 }
6478 (void) CloneString(&image_info->extract,argv[i+1]);
6479 break;
6480 }
6481 break;
6482 }
6483 case 'f':
6484 {
6485 if (LocaleCompare("fill",option+1) == 0)
6486 {
6487 if (*option == '+')
6488 {
6489 (void) SetImageOption(image_info,option+1,"none");
6490 break;
6491 }
6492 (void) SetImageOption(image_info,option+1,argv[i+1]);
6493 break;
6494 }
6495 if (LocaleCompare("filter",option+1) == 0)
6496 {
6497 if (*option == '+')
6498 {
6499 (void) SetImageOption(image_info,option+1,"undefined");
6500 break;
6501 }
6502 (void) SetImageOption(image_info,option+1,argv[i+1]);
6503 break;
6504 }
6505 if (LocaleCompare("font",option+1) == 0)
6506 {
6507 if (*option == '+')
6508 {
6509 if (image_info->font != (char *) NULL)
6510 image_info->font=DestroyString(image_info->font);
6511 break;
6512 }
6513 (void) CloneString(&image_info->font,argv[i+1]);
6514 break;
6515 }
6516 if (LocaleCompare("format",option+1) == 0)
6517 {
6518 register const char
6519 *q;
6520
6521 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006522 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006523 image_info->ping=MagickFalse;
6524 (void) SetImageOption(image_info,option+1,argv[i+1]);
6525 break;
6526 }
6527 if (LocaleCompare("fuzz",option+1) == 0)
6528 {
6529 if (*option == '+')
6530 {
6531 image_info->fuzz=0.0;
6532 (void) SetImageOption(image_info,option+1,"0");
6533 break;
6534 }
cristyf2f27272009-12-17 14:48:46 +00006535 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006536 1.0);
6537 (void) SetImageOption(image_info,option+1,argv[i+1]);
6538 break;
6539 }
6540 break;
6541 }
6542 case 'g':
6543 {
6544 if (LocaleCompare("gravity",option+1) == 0)
6545 {
6546 if (*option == '+')
6547 {
6548 (void) SetImageOption(image_info,option+1,"undefined");
6549 break;
6550 }
6551 (void) SetImageOption(image_info,option+1,argv[i+1]);
6552 break;
6553 }
6554 if (LocaleCompare("green-primary",option+1) == 0)
6555 {
6556 if (*option == '+')
6557 {
6558 (void) SetImageOption(image_info,option+1,"0.0");
6559 break;
6560 }
6561 (void) SetImageOption(image_info,option+1,argv[i+1]);
6562 break;
6563 }
6564 break;
6565 }
6566 case 'i':
6567 {
6568 if (LocaleCompare("intent",option+1) == 0)
6569 {
6570 if (*option == '+')
6571 {
6572 (void) SetImageOption(image_info,option+1,"undefined");
6573 break;
6574 }
6575 (void) SetImageOption(image_info,option+1,argv[i+1]);
6576 break;
6577 }
6578 if (LocaleCompare("interlace",option+1) == 0)
6579 {
6580 if (*option == '+')
6581 {
6582 image_info->interlace=UndefinedInterlace;
6583 (void) SetImageOption(image_info,option+1,"undefined");
6584 break;
6585 }
cristy042ee782011-04-22 18:48:30 +00006586 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006587 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6588 (void) SetImageOption(image_info,option+1,argv[i+1]);
6589 break;
6590 }
cristyb32b90a2009-09-07 21:45:48 +00006591 if (LocaleCompare("interline-spacing",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 (void) SetImageOption(image_info,option+1,"undefined");
6596 break;
6597 }
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
cristy3ed852e2009-09-05 21:47:34 +00006601 if (LocaleCompare("interpolate",option+1) == 0)
6602 {
6603 if (*option == '+')
6604 {
6605 (void) SetImageOption(image_info,option+1,"undefined");
6606 break;
6607 }
6608 (void) SetImageOption(image_info,option+1,argv[i+1]);
6609 break;
6610 }
6611 if (LocaleCompare("interword-spacing",option+1) == 0)
6612 {
6613 if (*option == '+')
6614 {
6615 (void) SetImageOption(image_info,option+1,"undefined");
6616 break;
6617 }
6618 (void) SetImageOption(image_info,option+1,argv[i+1]);
6619 break;
6620 }
6621 break;
6622 }
6623 case 'k':
6624 {
6625 if (LocaleCompare("kerning",option+1) == 0)
6626 {
6627 if (*option == '+')
6628 {
6629 (void) SetImageOption(image_info,option+1,"undefined");
6630 break;
6631 }
6632 (void) SetImageOption(image_info,option+1,argv[i+1]);
6633 break;
6634 }
6635 break;
6636 }
6637 case 'l':
6638 {
6639 if (LocaleCompare("label",option+1) == 0)
6640 {
6641 if (*option == '+')
6642 {
6643 (void) DeleteImageOption(image_info,option+1);
6644 break;
6645 }
6646 (void) SetImageOption(image_info,option+1,argv[i+1]);
6647 break;
6648 }
6649 if (LocaleCompare("limit",option+1) == 0)
6650 {
6651 MagickSizeType
6652 limit;
6653
6654 ResourceType
6655 type;
6656
6657 if (*option == '+')
6658 break;
cristy042ee782011-04-22 18:48:30 +00006659 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006660 MagickFalse,argv[i+1]);
6661 limit=MagickResourceInfinity;
6662 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006663 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006664 (void) SetMagickResourceLimit(type,limit);
6665 break;
6666 }
6667 if (LocaleCompare("list",option+1) == 0)
6668 {
cristybb503372010-05-27 20:51:26 +00006669 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006670 list;
6671
6672 /*
6673 Display configuration list.
6674 */
cristy042ee782011-04-22 18:48:30 +00006675 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006676 switch (list)
6677 {
6678 case MagickCoderOptions:
6679 {
6680 (void) ListCoderInfo((FILE *) NULL,exception);
6681 break;
6682 }
6683 case MagickColorOptions:
6684 {
6685 (void) ListColorInfo((FILE *) NULL,exception);
6686 break;
6687 }
6688 case MagickConfigureOptions:
6689 {
6690 (void) ListConfigureInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickDelegateOptions:
6694 {
6695 (void) ListDelegateInfo((FILE *) NULL,exception);
6696 break;
6697 }
6698 case MagickFontOptions:
6699 {
6700 (void) ListTypeInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickFormatOptions:
6704 {
6705 (void) ListMagickInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickLocaleOptions:
6709 {
6710 (void) ListLocaleInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickLogOptions:
6714 {
6715 (void) ListLogInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickMagicOptions:
6719 {
6720 (void) ListMagicInfo((FILE *) NULL,exception);
6721 break;
6722 }
6723 case MagickMimeOptions:
6724 {
6725 (void) ListMimeInfo((FILE *) NULL,exception);
6726 break;
6727 }
6728 case MagickModuleOptions:
6729 {
6730 (void) ListModuleInfo((FILE *) NULL,exception);
6731 break;
6732 }
6733 case MagickPolicyOptions:
6734 {
6735 (void) ListPolicyInfo((FILE *) NULL,exception);
6736 break;
6737 }
6738 case MagickResourceOptions:
6739 {
6740 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6741 break;
6742 }
6743 case MagickThresholdOptions:
6744 {
6745 (void) ListThresholdMaps((FILE *) NULL,exception);
6746 break;
6747 }
6748 default:
6749 {
cristy042ee782011-04-22 18:48:30 +00006750 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006751 exception);
6752 break;
6753 }
6754 }
cristyaeb2cbc2010-05-07 13:28:58 +00006755 break;
cristy3ed852e2009-09-05 21:47:34 +00006756 }
6757 if (LocaleCompare("log",option+1) == 0)
6758 {
6759 if (*option == '+')
6760 break;
6761 (void) SetLogFormat(argv[i+1]);
6762 break;
6763 }
6764 if (LocaleCompare("loop",option+1) == 0)
6765 {
6766 if (*option == '+')
6767 {
6768 (void) SetImageOption(image_info,option+1,"0");
6769 break;
6770 }
6771 (void) SetImageOption(image_info,option+1,argv[i+1]);
6772 break;
6773 }
6774 break;
6775 }
6776 case 'm':
6777 {
6778 if (LocaleCompare("matte",option+1) == 0)
6779 {
6780 if (*option == '+')
6781 {
6782 (void) SetImageOption(image_info,option+1,"false");
6783 break;
6784 }
6785 (void) SetImageOption(image_info,option+1,"true");
6786 break;
6787 }
6788 if (LocaleCompare("mattecolor",option+1) == 0)
6789 {
6790 if (*option == '+')
6791 {
6792 (void) SetImageOption(image_info,option+1,argv[i+1]);
6793 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6794 exception);
6795 break;
6796 }
6797 (void) SetImageOption(image_info,option+1,argv[i+1]);
6798 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6799 exception);
6800 break;
6801 }
6802 if (LocaleCompare("monitor",option+1) == 0)
6803 {
6804 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6805 (void *) NULL);
6806 break;
6807 }
6808 if (LocaleCompare("monochrome",option+1) == 0)
6809 {
6810 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6811 break;
6812 }
6813 break;
6814 }
6815 case 'o':
6816 {
6817 if (LocaleCompare("orient",option+1) == 0)
6818 {
6819 if (*option == '+')
6820 {
6821 image_info->orientation=UndefinedOrientation;
6822 (void) SetImageOption(image_info,option+1,"undefined");
6823 break;
6824 }
cristy042ee782011-04-22 18:48:30 +00006825 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006826 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006827 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006828 break;
6829 }
6830 }
6831 case 'p':
6832 {
6833 if (LocaleCompare("page",option+1) == 0)
6834 {
6835 char
6836 *canonical_page,
6837 page[MaxTextExtent];
6838
6839 const char
6840 *image_option;
6841
6842 MagickStatusType
6843 flags;
6844
6845 RectangleInfo
6846 geometry;
6847
6848 if (*option == '+')
6849 {
6850 (void) DeleteImageOption(image_info,option+1);
6851 (void) CloneString(&image_info->page,(char *) NULL);
6852 break;
6853 }
6854 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6855 image_option=GetImageOption(image_info,"page");
6856 if (image_option != (const char *) NULL)
6857 flags=ParseAbsoluteGeometry(image_option,&geometry);
6858 canonical_page=GetPageGeometry(argv[i+1]);
6859 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6860 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006861 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006862 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006863 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006864 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006865 (unsigned long) geometry.width,(unsigned long) geometry.height,
6866 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006867 (void) SetImageOption(image_info,option+1,page);
6868 (void) CloneString(&image_info->page,page);
6869 break;
6870 }
6871 if (LocaleCompare("pen",option+1) == 0)
6872 {
6873 if (*option == '+')
6874 {
6875 (void) SetImageOption(image_info,option+1,"none");
6876 break;
6877 }
6878 (void) SetImageOption(image_info,option+1,argv[i+1]);
6879 break;
6880 }
6881 if (LocaleCompare("ping",option+1) == 0)
6882 {
6883 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6884 break;
6885 }
6886 if (LocaleCompare("pointsize",option+1) == 0)
6887 {
6888 if (*option == '+')
6889 geometry_info.rho=0.0;
6890 else
6891 (void) ParseGeometry(argv[i+1],&geometry_info);
6892 image_info->pointsize=geometry_info.rho;
6893 break;
6894 }
cristye7f51092010-01-17 00:39:37 +00006895 if (LocaleCompare("precision",option+1) == 0)
6896 {
cristybf2766a2010-01-17 03:33:23 +00006897 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006898 break;
6899 }
cristy3ed852e2009-09-05 21:47:34 +00006900 if (LocaleCompare("preview",option+1) == 0)
6901 {
6902 /*
6903 Preview image.
6904 */
6905 if (*option == '+')
6906 {
6907 image_info->preview_type=UndefinedPreview;
6908 break;
6909 }
cristy042ee782011-04-22 18:48:30 +00006910 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006911 MagickPreviewOptions,MagickFalse,argv[i+1]);
6912 break;
6913 }
6914 break;
6915 }
6916 case 'q':
6917 {
6918 if (LocaleCompare("quality",option+1) == 0)
6919 {
6920 /*
6921 Set image compression quality.
6922 */
6923 if (*option == '+')
6924 {
6925 image_info->quality=UndefinedCompressionQuality;
6926 (void) SetImageOption(image_info,option+1,"0");
6927 break;
6928 }
cristye27293e2009-12-18 02:53:20 +00006929 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006930 (void) SetImageOption(image_info,option+1,argv[i+1]);
6931 break;
6932 }
6933 if (LocaleCompare("quiet",option+1) == 0)
6934 {
6935 static WarningHandler
6936 warning_handler = (WarningHandler) NULL;
6937
6938 if (*option == '+')
6939 {
6940 /*
6941 Restore error or warning messages.
6942 */
6943 warning_handler=SetWarningHandler(warning_handler);
6944 break;
6945 }
6946 /*
6947 Suppress error or warning messages.
6948 */
6949 warning_handler=SetWarningHandler((WarningHandler) NULL);
6950 break;
6951 }
6952 break;
6953 }
6954 case 'r':
6955 {
6956 if (LocaleCompare("red-primary",option+1) == 0)
6957 {
6958 if (*option == '+')
6959 {
6960 (void) SetImageOption(image_info,option+1,"0.0");
6961 break;
6962 }
6963 (void) SetImageOption(image_info,option+1,argv[i+1]);
6964 break;
6965 }
6966 break;
6967 }
6968 case 's':
6969 {
6970 if (LocaleCompare("sampling-factor",option+1) == 0)
6971 {
6972 /*
6973 Set image sampling factor.
6974 */
6975 if (*option == '+')
6976 {
6977 if (image_info->sampling_factor != (char *) NULL)
6978 image_info->sampling_factor=DestroyString(
6979 image_info->sampling_factor);
6980 break;
6981 }
6982 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6983 break;
6984 }
6985 if (LocaleCompare("scene",option+1) == 0)
6986 {
6987 /*
6988 Set image scene.
6989 */
6990 if (*option == '+')
6991 {
6992 image_info->scene=0;
6993 (void) SetImageOption(image_info,option+1,"0");
6994 break;
6995 }
cristye27293e2009-12-18 02:53:20 +00006996 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006997 (void) SetImageOption(image_info,option+1,argv[i+1]);
6998 break;
6999 }
7000 if (LocaleCompare("seed",option+1) == 0)
7001 {
cristybb503372010-05-27 20:51:26 +00007002 size_t
cristy3ed852e2009-09-05 21:47:34 +00007003 seed;
7004
7005 if (*option == '+')
7006 {
cristybb503372010-05-27 20:51:26 +00007007 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007008 SeedPseudoRandomGenerator(seed);
7009 break;
7010 }
cristye27293e2009-12-18 02:53:20 +00007011 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007012 SeedPseudoRandomGenerator(seed);
7013 break;
7014 }
7015 if (LocaleCompare("size",option+1) == 0)
7016 {
7017 if (*option == '+')
7018 {
7019 if (image_info->size != (char *) NULL)
7020 image_info->size=DestroyString(image_info->size);
7021 break;
7022 }
7023 (void) CloneString(&image_info->size,argv[i+1]);
7024 break;
7025 }
7026 if (LocaleCompare("stroke",option+1) == 0)
7027 {
7028 if (*option == '+')
7029 {
7030 (void) SetImageOption(image_info,option+1,"none");
7031 break;
7032 }
7033 (void) SetImageOption(image_info,option+1,argv[i+1]);
7034 break;
7035 }
7036 if (LocaleCompare("strokewidth",option+1) == 0)
7037 {
7038 if (*option == '+')
7039 {
7040 (void) SetImageOption(image_info,option+1,"0");
7041 break;
7042 }
7043 (void) SetImageOption(image_info,option+1,argv[i+1]);
7044 break;
7045 }
cristyd9a29192010-10-16 16:49:53 +00007046 if (LocaleCompare("synchronize",option+1) == 0)
7047 {
7048 if (*option == '+')
7049 {
7050 image_info->synchronize=MagickFalse;
7051 break;
7052 }
7053 image_info->synchronize=MagickTrue;
7054 break;
7055 }
cristy3ed852e2009-09-05 21:47:34 +00007056 break;
7057 }
7058 case 't':
7059 {
7060 if (LocaleCompare("taint",option+1) == 0)
7061 {
7062 if (*option == '+')
7063 {
7064 (void) SetImageOption(image_info,option+1,"false");
7065 break;
7066 }
7067 (void) SetImageOption(image_info,option+1,"true");
7068 break;
7069 }
7070 if (LocaleCompare("texture",option+1) == 0)
7071 {
7072 if (*option == '+')
7073 {
7074 if (image_info->texture != (char *) NULL)
7075 image_info->texture=DestroyString(image_info->texture);
7076 break;
7077 }
7078 (void) CloneString(&image_info->texture,argv[i+1]);
7079 break;
7080 }
7081 if (LocaleCompare("tile-offset",option+1) == 0)
7082 {
7083 if (*option == '+')
7084 {
7085 (void) SetImageOption(image_info,option+1,"0");
7086 break;
7087 }
7088 (void) SetImageOption(image_info,option+1,argv[i+1]);
7089 break;
7090 }
7091 if (LocaleCompare("transparent-color",option+1) == 0)
7092 {
7093 if (*option == '+')
7094 {
7095 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7096 (void) SetImageOption(image_info,option+1,"none");
7097 break;
7098 }
7099 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7100 exception);
7101 (void) SetImageOption(image_info,option+1,argv[i+1]);
7102 break;
7103 }
7104 if (LocaleCompare("type",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
cristy5f1c1ff2010-12-23 21:38:06 +00007108 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007109 (void) SetImageOption(image_info,option+1,"undefined");
7110 break;
7111 }
cristy042ee782011-04-22 18:48:30 +00007112 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007113 MagickFalse,argv[i+1]);
7114 (void) SetImageOption(image_info,option+1,argv[i+1]);
7115 break;
7116 }
7117 break;
7118 }
7119 case 'u':
7120 {
7121 if (LocaleCompare("undercolor",option+1) == 0)
7122 {
7123 if (*option == '+')
7124 {
7125 (void) DeleteImageOption(image_info,option+1);
7126 break;
7127 }
7128 (void) SetImageOption(image_info,option+1,argv[i+1]);
7129 break;
7130 }
7131 if (LocaleCompare("units",option+1) == 0)
7132 {
7133 if (*option == '+')
7134 {
7135 image_info->units=UndefinedResolution;
7136 (void) SetImageOption(image_info,option+1,"undefined");
7137 break;
7138 }
cristy042ee782011-04-22 18:48:30 +00007139 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007140 MagickResolutionOptions,MagickFalse,argv[i+1]);
7141 (void) SetImageOption(image_info,option+1,argv[i+1]);
7142 break;
7143 }
7144 break;
7145 }
7146 case 'v':
7147 {
7148 if (LocaleCompare("verbose",option+1) == 0)
7149 {
7150 if (*option == '+')
7151 {
7152 image_info->verbose=MagickFalse;
7153 break;
7154 }
7155 image_info->verbose=MagickTrue;
7156 image_info->ping=MagickFalse;
7157 break;
7158 }
7159 if (LocaleCompare("view",option+1) == 0)
7160 {
7161 if (*option == '+')
7162 {
7163 if (image_info->view != (char *) NULL)
7164 image_info->view=DestroyString(image_info->view);
7165 break;
7166 }
7167 (void) CloneString(&image_info->view,argv[i+1]);
7168 break;
7169 }
7170 if (LocaleCompare("virtual-pixel",option+1) == 0)
7171 {
7172 if (*option == '+')
7173 {
7174 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7175 (void) SetImageOption(image_info,option+1,"undefined");
7176 break;
7177 }
7178 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007179 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007180 argv[i+1]);
7181 (void) SetImageOption(image_info,option+1,argv[i+1]);
7182 break;
7183 }
7184 break;
7185 }
7186 case 'w':
7187 {
7188 if (LocaleCompare("white-point",option+1) == 0)
7189 {
7190 if (*option == '+')
7191 {
7192 (void) SetImageOption(image_info,option+1,"0.0");
7193 break;
7194 }
7195 (void) SetImageOption(image_info,option+1,argv[i+1]);
7196 break;
7197 }
7198 break;
7199 }
7200 default:
7201 break;
7202 }
7203 i+=count;
7204 }
7205 return(MagickTrue);
7206}
7207
7208/*
7209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7210% %
7211% %
7212% %
7213+ M o g r i f y I m a g e L i s t %
7214% %
7215% %
7216% %
7217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7218%
7219% MogrifyImageList() applies any command line options that might affect the
7220% entire image list (e.g. -append, -coalesce, etc.).
7221%
7222% The format of the MogrifyImage method is:
7223%
7224% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7225% const char **argv,Image **images,ExceptionInfo *exception)
7226%
7227% A description of each parameter follows:
7228%
7229% o image_info: the image info..
7230%
7231% o argc: Specifies a pointer to an integer describing the number of
7232% elements in the argument vector.
7233%
7234% o argv: Specifies a pointer to a text array containing the command line
7235% arguments.
7236%
anthonye9c27192011-03-27 08:07:06 +00007237% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007238%
7239% o exception: return any errors or warnings in this structure.
7240%
7241*/
7242WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7243 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7244{
7245 ChannelType
7246 channel;
7247
7248 const char
7249 *option;
7250
cristy6b3da3a2010-06-20 02:21:46 +00007251 ImageInfo
7252 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007253
7254 MagickStatusType
7255 status;
7256
7257 QuantizeInfo
7258 *quantize_info;
7259
cristybb503372010-05-27 20:51:26 +00007260 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007261 i;
7262
cristy6b3da3a2010-06-20 02:21:46 +00007263 ssize_t
7264 count,
7265 index;
7266
cristy3ed852e2009-09-05 21:47:34 +00007267 /*
7268 Apply options to the image list.
7269 */
7270 assert(image_info != (ImageInfo *) NULL);
7271 assert(image_info->signature == MagickSignature);
7272 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007273 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007274 assert((*images)->signature == MagickSignature);
7275 if ((*images)->debug != MagickFalse)
7276 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7277 (*images)->filename);
7278 if ((argc <= 0) || (*argv == (char *) NULL))
7279 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007280 mogrify_info=CloneImageInfo(image_info);
7281 quantize_info=AcquireQuantizeInfo(mogrify_info);
7282 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007283 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007284 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007285 {
cristy74fe8f12009-10-03 19:09:01 +00007286 if (*images == (Image *) NULL)
7287 break;
cristy3ed852e2009-09-05 21:47:34 +00007288 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007289 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007290 continue;
cristy042ee782011-04-22 18:48:30 +00007291 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007292 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007293 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007294 break;
cristy6b3da3a2010-06-20 02:21:46 +00007295 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007296 switch (*(option+1))
7297 {
7298 case 'a':
7299 {
7300 if (LocaleCompare("affinity",option+1) == 0)
7301 {
cristy6b3da3a2010-06-20 02:21:46 +00007302 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007303 if (*option == '+')
7304 {
7305 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7306 InheritException(exception,&(*images)->exception);
7307 break;
7308 }
7309 i++;
7310 break;
7311 }
7312 if (LocaleCompare("append",option+1) == 0)
7313 {
7314 Image
7315 *append_image;
7316
cristy6b3da3a2010-06-20 02:21:46 +00007317 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007318 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7319 MagickFalse,exception);
7320 if (append_image == (Image *) NULL)
7321 {
7322 status=MagickFalse;
7323 break;
7324 }
7325 *images=DestroyImageList(*images);
7326 *images=append_image;
7327 break;
7328 }
7329 if (LocaleCompare("average",option+1) == 0)
7330 {
7331 Image
7332 *average_image;
7333
cristyd18ae7c2010-03-07 17:39:52 +00007334 /*
7335 Average an image sequence (deprecated).
7336 */
cristy6b3da3a2010-06-20 02:21:46 +00007337 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007338 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7339 exception);
cristy3ed852e2009-09-05 21:47:34 +00007340 if (average_image == (Image *) NULL)
7341 {
7342 status=MagickFalse;
7343 break;
7344 }
7345 *images=DestroyImageList(*images);
7346 *images=average_image;
7347 break;
7348 }
7349 break;
7350 }
7351 case 'c':
7352 {
7353 if (LocaleCompare("channel",option+1) == 0)
7354 {
7355 if (*option == '+')
7356 {
7357 channel=DefaultChannels;
7358 break;
7359 }
7360 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7361 break;
7362 }
7363 if (LocaleCompare("clut",option+1) == 0)
7364 {
7365 Image
7366 *clut_image,
7367 *image;
7368
cristy6b3da3a2010-06-20 02:21:46 +00007369 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007370 image=RemoveFirstImageFromList(images);
7371 clut_image=RemoveFirstImageFromList(images);
7372 if (clut_image == (Image *) NULL)
7373 {
7374 status=MagickFalse;
7375 break;
7376 }
7377 (void) ClutImageChannel(image,channel,clut_image);
7378 clut_image=DestroyImage(clut_image);
7379 InheritException(exception,&image->exception);
7380 *images=DestroyImageList(*images);
7381 *images=image;
7382 break;
7383 }
7384 if (LocaleCompare("coalesce",option+1) == 0)
7385 {
7386 Image
7387 *coalesce_image;
7388
cristy6b3da3a2010-06-20 02:21:46 +00007389 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007390 coalesce_image=CoalesceImages(*images,exception);
7391 if (coalesce_image == (Image *) NULL)
7392 {
7393 status=MagickFalse;
7394 break;
7395 }
7396 *images=DestroyImageList(*images);
7397 *images=coalesce_image;
7398 break;
7399 }
7400 if (LocaleCompare("combine",option+1) == 0)
7401 {
7402 Image
7403 *combine_image;
7404
cristy6b3da3a2010-06-20 02:21:46 +00007405 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007406 combine_image=CombineImages(*images,channel,exception);
7407 if (combine_image == (Image *) NULL)
7408 {
7409 status=MagickFalse;
7410 break;
7411 }
7412 *images=DestroyImageList(*images);
7413 *images=combine_image;
7414 break;
7415 }
7416 if (LocaleCompare("composite",option+1) == 0)
7417 {
7418 Image
7419 *mask_image,
7420 *composite_image,
7421 *image;
7422
7423 RectangleInfo
7424 geometry;
7425
cristy6b3da3a2010-06-20 02:21:46 +00007426 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007427 image=RemoveFirstImageFromList(images);
7428 composite_image=RemoveFirstImageFromList(images);
7429 if (composite_image == (Image *) NULL)
7430 {
7431 status=MagickFalse;
7432 break;
7433 }
7434 (void) TransformImage(&composite_image,(char *) NULL,
7435 composite_image->geometry);
7436 SetGeometry(composite_image,&geometry);
7437 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7438 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7439 &geometry);
7440 mask_image=RemoveFirstImageFromList(images);
7441 if (mask_image != (Image *) NULL)
7442 {
7443 if ((image->compose == DisplaceCompositeOp) ||
7444 (image->compose == DistortCompositeOp))
7445 {
7446 /*
7447 Merge Y displacement into X displacement image.
7448 */
7449 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7450 mask_image,0,0);
7451 mask_image=DestroyImage(mask_image);
7452 }
7453 else
7454 {
7455 /*
7456 Set a blending mask for the composition.
7457 */
anthonya129f702011-04-14 01:08:48 +00007458 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007459 image->mask=mask_image;
7460 (void) NegateImage(image->mask,MagickFalse);
7461 }
7462 }
7463 (void) CompositeImageChannel(image,channel,image->compose,
7464 composite_image,geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007465 if (mask_image != (Image *) NULL)
7466 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007467 composite_image=DestroyImage(composite_image);
7468 InheritException(exception,&image->exception);
7469 *images=DestroyImageList(*images);
7470 *images=image;
7471 break;
7472 }
anthony9f4f0342011-03-28 11:47:22 +00007473#if 0
7474This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007475 if (LocaleCompare("crop",option+1) == 0)
7476 {
7477 MagickStatusType
7478 flags;
7479
7480 RectangleInfo
7481 geometry;
7482
anthonye9c27192011-03-27 08:07:06 +00007483 /*
anthony9f4f0342011-03-28 11:47:22 +00007484 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007485 */
cristy6b3da3a2010-06-20 02:21:46 +00007486 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007487 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7488 if (((geometry.width == 0) && (geometry.height == 0)) ||
7489 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7490 break;
7491 (void) TransformImages(images,argv[i+1],(char *) NULL);
7492 InheritException(exception,&(*images)->exception);
7493 break;
7494 }
anthony9f4f0342011-03-28 11:47:22 +00007495#endif
cristy3ed852e2009-09-05 21:47:34 +00007496 break;
7497 }
7498 case 'd':
7499 {
7500 if (LocaleCompare("deconstruct",option+1) == 0)
7501 {
7502 Image
7503 *deconstruct_image;
7504
cristy6b3da3a2010-06-20 02:21:46 +00007505 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007506 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007507 exception);
cristy3ed852e2009-09-05 21:47:34 +00007508 if (deconstruct_image == (Image *) NULL)
7509 {
7510 status=MagickFalse;
7511 break;
7512 }
7513 *images=DestroyImageList(*images);
7514 *images=deconstruct_image;
7515 break;
7516 }
7517 if (LocaleCompare("delete",option+1) == 0)
7518 {
7519 if (*option == '+')
7520 DeleteImages(images,"-1",exception);
7521 else
7522 DeleteImages(images,argv[i+1],exception);
7523 break;
7524 }
7525 if (LocaleCompare("dither",option+1) == 0)
7526 {
7527 if (*option == '+')
7528 {
7529 quantize_info->dither=MagickFalse;
7530 break;
7531 }
7532 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007533 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007534 MagickDitherOptions,MagickFalse,argv[i+1]);
7535 break;
7536 }
cristyecb10ff2011-03-22 13:14:03 +00007537 if (LocaleCompare("duplicate",option+1) == 0)
7538 {
cristy72988482011-03-29 16:34:38 +00007539 Image
7540 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007541
anthony2b6bcae2011-03-23 13:05:34 +00007542 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007543 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7544 else
7545 {
7546 const char
7547 *p;
7548
anthony2b6bcae2011-03-23 13:05:34 +00007549 size_t
7550 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007551
anthony2b6bcae2011-03-23 13:05:34 +00007552 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007553 p=strchr(argv[i+1],',');
7554 if (p == (const char *) NULL)
7555 duplicate_images=DuplicateImages(*images,number_duplicates,
7556 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007557 else
cristy72988482011-03-29 16:34:38 +00007558 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7559 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007560 }
7561 AppendImageToList(images, duplicate_images);
7562 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007563 break;
7564 }
cristy3ed852e2009-09-05 21:47:34 +00007565 break;
7566 }
cristyd18ae7c2010-03-07 17:39:52 +00007567 case 'e':
7568 {
7569 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7570 {
7571 Image
7572 *evaluate_image;
7573
7574 MagickEvaluateOperator
7575 op;
7576
cristy6b3da3a2010-06-20 02:21:46 +00007577 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007578 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007579 MagickFalse,argv[i+1]);
7580 evaluate_image=EvaluateImages(*images,op,exception);
7581 if (evaluate_image == (Image *) NULL)
7582 {
7583 status=MagickFalse;
7584 break;
7585 }
7586 *images=DestroyImageList(*images);
7587 *images=evaluate_image;
7588 break;
7589 }
7590 break;
7591 }
cristy3ed852e2009-09-05 21:47:34 +00007592 case 'f':
7593 {
cristyf0a247f2009-10-04 00:20:03 +00007594 if (LocaleCompare("fft",option+1) == 0)
7595 {
7596 Image
7597 *fourier_image;
7598
7599 /*
7600 Implements the discrete Fourier transform (DFT).
7601 */
cristy6b3da3a2010-06-20 02:21:46 +00007602 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007603 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7604 MagickTrue : MagickFalse,exception);
7605 if (fourier_image == (Image *) NULL)
7606 break;
7607 *images=DestroyImage(*images);
7608 *images=fourier_image;
7609 break;
7610 }
cristy3ed852e2009-09-05 21:47:34 +00007611 if (LocaleCompare("flatten",option+1) == 0)
7612 {
7613 Image
7614 *flatten_image;
7615
cristy6b3da3a2010-06-20 02:21:46 +00007616 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007617 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7618 if (flatten_image == (Image *) NULL)
7619 break;
7620 *images=DestroyImageList(*images);
7621 *images=flatten_image;
7622 break;
7623 }
7624 if (LocaleCompare("fx",option+1) == 0)
7625 {
7626 Image
7627 *fx_image;
7628
cristy6b3da3a2010-06-20 02:21:46 +00007629 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007630 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7631 if (fx_image == (Image *) NULL)
7632 {
7633 status=MagickFalse;
7634 break;
7635 }
7636 *images=DestroyImageList(*images);
7637 *images=fx_image;
7638 break;
7639 }
7640 break;
7641 }
7642 case 'h':
7643 {
7644 if (LocaleCompare("hald-clut",option+1) == 0)
7645 {
7646 Image
7647 *hald_image,
7648 *image;
7649
cristy6b3da3a2010-06-20 02:21:46 +00007650 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007651 image=RemoveFirstImageFromList(images);
7652 hald_image=RemoveFirstImageFromList(images);
7653 if (hald_image == (Image *) NULL)
7654 {
7655 status=MagickFalse;
7656 break;
7657 }
7658 (void) HaldClutImageChannel(image,channel,hald_image);
7659 hald_image=DestroyImage(hald_image);
7660 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007661 if (*images != (Image *) NULL)
7662 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007663 *images=image;
7664 break;
7665 }
7666 break;
7667 }
7668 case 'i':
7669 {
7670 if (LocaleCompare("ift",option+1) == 0)
7671 {
7672 Image
cristy8587f882009-11-13 20:28:49 +00007673 *fourier_image,
7674 *magnitude_image,
7675 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007676
7677 /*
7678 Implements the inverse fourier discrete Fourier transform (DFT).
7679 */
cristy6b3da3a2010-06-20 02:21:46 +00007680 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007681 magnitude_image=RemoveFirstImageFromList(images);
7682 phase_image=RemoveFirstImageFromList(images);
7683 if (phase_image == (Image *) NULL)
7684 {
7685 status=MagickFalse;
7686 break;
7687 }
7688 fourier_image=InverseFourierTransformImage(magnitude_image,
7689 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007690 if (fourier_image == (Image *) NULL)
7691 break;
cristy0aff6ea2009-11-14 01:40:53 +00007692 if (*images != (Image *) NULL)
7693 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007694 *images=fourier_image;
7695 break;
7696 }
7697 if (LocaleCompare("insert",option+1) == 0)
7698 {
7699 Image
7700 *p,
7701 *q;
7702
7703 index=0;
7704 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007705 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007706 p=RemoveLastImageFromList(images);
7707 if (p == (Image *) NULL)
7708 {
7709 (void) ThrowMagickException(exception,GetMagickModule(),
7710 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7711 status=MagickFalse;
7712 break;
7713 }
7714 q=p;
7715 if (index == 0)
7716 PrependImageToList(images,q);
7717 else
cristybb503372010-05-27 20:51:26 +00007718 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007719 AppendImageToList(images,q);
7720 else
7721 {
7722 q=GetImageFromList(*images,index-1);
7723 if (q == (Image *) NULL)
7724 {
7725 (void) ThrowMagickException(exception,GetMagickModule(),
7726 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7727 status=MagickFalse;
7728 break;
7729 }
7730 InsertImageInList(&q,p);
7731 }
7732 *images=GetFirstImageInList(q);
7733 break;
7734 }
7735 break;
7736 }
7737 case 'l':
7738 {
7739 if (LocaleCompare("layers",option+1) == 0)
7740 {
7741 Image
7742 *layers;
7743
7744 ImageLayerMethod
7745 method;
7746
cristy6b3da3a2010-06-20 02:21:46 +00007747 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007748 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007749 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007750 MagickFalse,argv[i+1]);
7751 switch (method)
7752 {
7753 case CoalesceLayer:
7754 {
7755 layers=CoalesceImages(*images,exception);
7756 break;
7757 }
7758 case CompareAnyLayer:
7759 case CompareClearLayer:
7760 case CompareOverlayLayer:
7761 default:
7762 {
cristy8a9106f2011-07-05 14:39:26 +00007763 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007764 break;
7765 }
7766 case MergeLayer:
7767 case FlattenLayer:
7768 case MosaicLayer:
7769 case TrimBoundsLayer:
7770 {
7771 layers=MergeImageLayers(*images,method,exception);
7772 break;
7773 }
7774 case DisposeLayer:
7775 {
7776 layers=DisposeImages(*images,exception);
7777 break;
7778 }
7779 case OptimizeImageLayer:
7780 {
7781 layers=OptimizeImageLayers(*images,exception);
7782 break;
7783 }
7784 case OptimizePlusLayer:
7785 {
7786 layers=OptimizePlusImageLayers(*images,exception);
7787 break;
7788 }
7789 case OptimizeTransLayer:
7790 {
7791 OptimizeImageTransparency(*images,exception);
7792 break;
7793 }
7794 case RemoveDupsLayer:
7795 {
7796 RemoveDuplicateLayers(images,exception);
7797 break;
7798 }
7799 case RemoveZeroLayer:
7800 {
7801 RemoveZeroDelayLayers(images,exception);
7802 break;
7803 }
7804 case OptimizeLayer:
7805 {
7806 /*
7807 General Purpose, GIF Animation Optimizer.
7808 */
7809 layers=CoalesceImages(*images,exception);
7810 if (layers == (Image *) NULL)
7811 {
7812 status=MagickFalse;
7813 break;
7814 }
7815 InheritException(exception,&layers->exception);
7816 *images=DestroyImageList(*images);
7817 *images=layers;
7818 layers=OptimizeImageLayers(*images,exception);
7819 if (layers == (Image *) NULL)
7820 {
7821 status=MagickFalse;
7822 break;
7823 }
7824 InheritException(exception,&layers->exception);
7825 *images=DestroyImageList(*images);
7826 *images=layers;
7827 layers=(Image *) NULL;
7828 OptimizeImageTransparency(*images,exception);
7829 InheritException(exception,&(*images)->exception);
7830 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7831 break;
7832 }
7833 case CompositeLayer:
7834 {
7835 CompositeOperator
7836 compose;
7837
7838 Image
7839 *source;
7840
7841 RectangleInfo
7842 geometry;
7843
7844 /*
7845 Split image sequence at the first 'NULL:' image.
7846 */
7847 source=(*images);
7848 while (source != (Image *) NULL)
7849 {
7850 source=GetNextImageInList(source);
7851 if ((source != (Image *) NULL) &&
7852 (LocaleCompare(source->magick,"NULL") == 0))
7853 break;
7854 }
7855 if (source != (Image *) NULL)
7856 {
7857 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7858 (GetNextImageInList(source) == (Image *) NULL))
7859 source=(Image *) NULL;
7860 else
7861 {
7862 /*
7863 Separate the two lists, junk the null: image.
7864 */
7865 source=SplitImageList(source->previous);
7866 DeleteImageFromList(&source);
7867 }
7868 }
7869 if (source == (Image *) NULL)
7870 {
7871 (void) ThrowMagickException(exception,GetMagickModule(),
7872 OptionError,"MissingNullSeparator","layers Composite");
7873 status=MagickFalse;
7874 break;
7875 }
7876 /*
7877 Adjust offset with gravity and virtual canvas.
7878 */
7879 SetGeometry(*images,&geometry);
7880 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7881 geometry.width=source->page.width != 0 ?
7882 source->page.width : source->columns;
7883 geometry.height=source->page.height != 0 ?
7884 source->page.height : source->rows;
7885 GravityAdjustGeometry((*images)->page.width != 0 ?
7886 (*images)->page.width : (*images)->columns,
7887 (*images)->page.height != 0 ? (*images)->page.height :
7888 (*images)->rows,(*images)->gravity,&geometry);
7889 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007890 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007891 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007892 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007893 MagickComposeOptions,MagickFalse,option);
7894 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7895 exception);
7896 source=DestroyImageList(source);
7897 break;
7898 }
7899 }
7900 if (layers == (Image *) NULL)
7901 break;
7902 InheritException(exception,&layers->exception);
7903 *images=DestroyImageList(*images);
7904 *images=layers;
7905 break;
7906 }
7907 break;
7908 }
7909 case 'm':
7910 {
7911 if (LocaleCompare("map",option+1) == 0)
7912 {
cristy6b3da3a2010-06-20 02:21:46 +00007913 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007914 if (*option == '+')
7915 {
7916 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7917 InheritException(exception,&(*images)->exception);
7918 break;
7919 }
7920 i++;
7921 break;
7922 }
cristyf40785b2010-03-06 02:27:27 +00007923 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007924 {
7925 Image
cristyf40785b2010-03-06 02:27:27 +00007926 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007927
cristyd18ae7c2010-03-07 17:39:52 +00007928 /*
7929 Maximum image sequence (deprecated).
7930 */
cristy6b3da3a2010-06-20 02:21:46 +00007931 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007932 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007933 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007934 {
7935 status=MagickFalse;
7936 break;
7937 }
7938 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007939 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007940 break;
7941 }
cristyf40785b2010-03-06 02:27:27 +00007942 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007943 {
7944 Image
cristyf40785b2010-03-06 02:27:27 +00007945 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007946
cristyd18ae7c2010-03-07 17:39:52 +00007947 /*
7948 Minimum image sequence (deprecated).
7949 */
cristy6b3da3a2010-06-20 02:21:46 +00007950 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007951 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007952 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007953 {
7954 status=MagickFalse;
7955 break;
7956 }
7957 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007958 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007959 break;
7960 }
cristy3ed852e2009-09-05 21:47:34 +00007961 if (LocaleCompare("morph",option+1) == 0)
7962 {
7963 Image
7964 *morph_image;
7965
cristy6b3da3a2010-06-20 02:21:46 +00007966 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007967 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007968 exception);
7969 if (morph_image == (Image *) NULL)
7970 {
7971 status=MagickFalse;
7972 break;
7973 }
7974 *images=DestroyImageList(*images);
7975 *images=morph_image;
7976 break;
7977 }
7978 if (LocaleCompare("mosaic",option+1) == 0)
7979 {
7980 Image
7981 *mosaic_image;
7982
cristy6b3da3a2010-06-20 02:21:46 +00007983 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007984 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7985 if (mosaic_image == (Image *) NULL)
7986 {
7987 status=MagickFalse;
7988 break;
7989 }
7990 *images=DestroyImageList(*images);
7991 *images=mosaic_image;
7992 break;
7993 }
7994 break;
7995 }
7996 case 'p':
7997 {
7998 if (LocaleCompare("print",option+1) == 0)
7999 {
8000 char
8001 *string;
8002
cristy6b3da3a2010-06-20 02:21:46 +00008003 (void) SyncImagesSettings(mogrify_info,*images);
8004 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008005 if (string == (char *) NULL)
8006 break;
8007 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00008008 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008009 string=DestroyString(string);
8010 }
8011 if (LocaleCompare("process",option+1) == 0)
8012 {
8013 char
8014 **arguments;
8015
8016 int
8017 j,
8018 number_arguments;
8019
cristy6b3da3a2010-06-20 02:21:46 +00008020 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008021 arguments=StringToArgv(argv[i+1],&number_arguments);
8022 if (arguments == (char **) NULL)
8023 break;
8024 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8025 {
8026 char
8027 breaker,
8028 quote,
8029 *token;
8030
8031 const char
8032 *arguments;
8033
8034 int
8035 next,
8036 status;
8037
8038 size_t
8039 length;
8040
8041 TokenInfo
8042 *token_info;
8043
8044 /*
8045 Support old style syntax, filter="-option arg".
8046 */
8047 length=strlen(argv[i+1]);
8048 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008049 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008050 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8051 sizeof(*token));
8052 if (token == (char *) NULL)
8053 break;
8054 next=0;
8055 arguments=argv[i+1];
8056 token_info=AcquireTokenInfo();
8057 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8058 "\"",'\0',&breaker,&next,&quote);
8059 token_info=DestroyTokenInfo(token_info);
8060 if (status == 0)
8061 {
8062 const char
8063 *argv;
8064
8065 argv=(&(arguments[next]));
8066 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8067 exception);
8068 }
8069 token=DestroyString(token);
8070 break;
8071 }
cristy91c0da22010-05-02 01:44:07 +00008072 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008073 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8074 number_arguments-2,(const char **) arguments+2,exception);
8075 for (j=0; j < number_arguments; j++)
8076 arguments[j]=DestroyString(arguments[j]);
8077 arguments=(char **) RelinquishMagickMemory(arguments);
8078 break;
8079 }
8080 break;
8081 }
8082 case 'r':
8083 {
8084 if (LocaleCompare("reverse",option+1) == 0)
8085 {
8086 ReverseImageList(images);
8087 InheritException(exception,&(*images)->exception);
8088 break;
8089 }
8090 break;
8091 }
8092 case 's':
8093 {
cristy4285d782011-02-09 20:12:28 +00008094 if (LocaleCompare("smush",option+1) == 0)
8095 {
8096 Image
8097 *smush_image;
8098
8099 ssize_t
8100 offset;
8101
8102 (void) SyncImagesSettings(mogrify_info,*images);
8103 offset=(ssize_t) StringToLong(argv[i+1]);
8104 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8105 MagickFalse,offset,exception);
8106 if (smush_image == (Image *) NULL)
8107 {
8108 status=MagickFalse;
8109 break;
8110 }
8111 *images=DestroyImageList(*images);
8112 *images=smush_image;
8113 break;
8114 }
cristy3ed852e2009-09-05 21:47:34 +00008115 if (LocaleCompare("swap",option+1) == 0)
8116 {
8117 Image
8118 *p,
8119 *q,
8120 *swap;
8121
cristybb503372010-05-27 20:51:26 +00008122 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008123 swap_index;
8124
8125 index=(-1);
8126 swap_index=(-2);
8127 if (*option != '+')
8128 {
8129 GeometryInfo
8130 geometry_info;
8131
8132 MagickStatusType
8133 flags;
8134
8135 swap_index=(-1);
8136 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008137 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008138 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008139 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008140 }
8141 p=GetImageFromList(*images,index);
8142 q=GetImageFromList(*images,swap_index);
8143 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8144 {
8145 (void) ThrowMagickException(exception,GetMagickModule(),
8146 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8147 status=MagickFalse;
8148 break;
8149 }
8150 if (p == q)
8151 break;
8152 swap=CloneImage(p,0,0,MagickTrue,exception);
8153 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8154 ReplaceImageInList(&q,swap);
8155 *images=GetFirstImageInList(q);
8156 break;
8157 }
8158 break;
8159 }
8160 case 'w':
8161 {
8162 if (LocaleCompare("write",option+1) == 0)
8163 {
cristy071dd7b2010-04-09 13:04:54 +00008164 char
cristy06609ee2010-03-17 20:21:27 +00008165 key[MaxTextExtent];
8166
cristy3ed852e2009-09-05 21:47:34 +00008167 Image
8168 *write_images;
8169
8170 ImageInfo
8171 *write_info;
8172
cristy6b3da3a2010-06-20 02:21:46 +00008173 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008174 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008175 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008176 write_images=(*images);
8177 if (*option == '+')
8178 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008179 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008180 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8181 write_info=DestroyImageInfo(write_info);
8182 if (*option == '+')
8183 write_images=DestroyImageList(write_images);
8184 break;
8185 }
8186 break;
8187 }
8188 default:
8189 break;
8190 }
8191 i+=count;
8192 }
8193 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008194 mogrify_info=DestroyImageInfo(mogrify_info);
8195 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008196 return(status != 0 ? MagickTrue : MagickFalse);
8197}
8198
8199/*
8200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8201% %
8202% %
8203% %
8204+ M o g r i f y I m a g e s %
8205% %
8206% %
8207% %
8208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8209%
8210% MogrifyImages() applies image processing options to a sequence of images as
8211% prescribed by command line options.
8212%
8213% The format of the MogrifyImage method is:
8214%
8215% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8216% const MagickBooleanType post,const int argc,const char **argv,
8217% Image **images,Exceptioninfo *exception)
8218%
8219% A description of each parameter follows:
8220%
8221% o image_info: the image info..
8222%
8223% o post: If true, post process image list operators otherwise pre-process.
8224%
8225% o argc: Specifies a pointer to an integer describing the number of
8226% elements in the argument vector.
8227%
8228% o argv: Specifies a pointer to a text array containing the command line
8229% arguments.
8230%
anthonye9c27192011-03-27 08:07:06 +00008231% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008232%
8233% o exception: return any errors or warnings in this structure.
8234%
8235*/
8236WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8237 const MagickBooleanType post,const int argc,const char **argv,
8238 Image **images,ExceptionInfo *exception)
8239{
8240#define MogrifyImageTag "Mogrify/Image"
8241
anthonye9c27192011-03-27 08:07:06 +00008242 MagickStatusType
8243 status;
cristy3ed852e2009-09-05 21:47:34 +00008244
cristy0e9f9c12010-02-11 03:00:47 +00008245 MagickBooleanType
8246 proceed;
8247
anthonye9c27192011-03-27 08:07:06 +00008248 size_t
8249 n;
cristy3ed852e2009-09-05 21:47:34 +00008250
cristybb503372010-05-27 20:51:26 +00008251 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008252 i;
8253
cristy3ed852e2009-09-05 21:47:34 +00008254 assert(image_info != (ImageInfo *) NULL);
8255 assert(image_info->signature == MagickSignature);
8256 if (images == (Image **) NULL)
8257 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008258 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008259 assert((*images)->signature == MagickSignature);
8260 if ((*images)->debug != MagickFalse)
8261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8262 (*images)->filename);
8263 if ((argc <= 0) || (*argv == (char *) NULL))
8264 return(MagickTrue);
8265 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8266 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008267 status=0;
anthonye9c27192011-03-27 08:07:06 +00008268
anthonyce2716b2011-04-22 09:51:34 +00008269#if 0
cristy1e604812011-05-19 18:07:50 +00008270 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8271 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008272#endif
8273
anthonye9c27192011-03-27 08:07:06 +00008274 /*
8275 Pre-process multi-image sequence operators
8276 */
cristy3ed852e2009-09-05 21:47:34 +00008277 if (post == MagickFalse)
8278 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008279 /*
8280 For each image, process simple single image operators
8281 */
8282 i=0;
8283 n=GetImageListLength(*images);
8284 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008285 {
anthonyce2716b2011-04-22 09:51:34 +00008286#if 0
cristy1e604812011-05-19 18:07:50 +00008287 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8288 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008289#endif
anthonye9c27192011-03-27 08:07:06 +00008290 status&=MogrifyImage(image_info,argc,argv,images,exception);
8291 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008292 if (proceed == MagickFalse)
8293 break;
anthonye9c27192011-03-27 08:07:06 +00008294 if ( (*images)->next == (Image *) NULL )
8295 break;
8296 *images=(*images)->next;
8297 i++;
cristy3ed852e2009-09-05 21:47:34 +00008298 }
anthonye9c27192011-03-27 08:07:06 +00008299 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008300#if 0
cristy1e604812011-05-19 18:07:50 +00008301 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8302 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008303#endif
anthonye9c27192011-03-27 08:07:06 +00008304
8305 /*
8306 Post-process, multi-image sequence operators
8307 */
8308 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008309 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008310 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008311 return(status != 0 ? MagickTrue : MagickFalse);
8312}