blob: 9084b82048688a26649ee03f6d313dc65d0f2731 [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*/
47#include "wand/studio.h"
48#include "wand/MagickWand.h"
49#include "wand/mogrify-private.h"
cristy0e9f9c12010-02-11 03:00:47 +000050#include "magick/monitor-private.h"
cristy3980b0d2009-10-25 14:37:13 +000051#include "magick/thread-private.h"
cristyf2f27272009-12-17 14:48:46 +000052#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define UndefinedCompressionQuality 0UL
58
59/*
60 Constant declaration.
61*/
62static const char
cristy7138c592009-09-08 13:58:52 +000063 BackgroundColor[] = "#fff", /* white */
64 BorderColor[] = "#dfdfdf", /* gray */
65 MatteColor[] = "#bdbdbd"; /* gray */
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
cristy5063d812010-10-19 16:28:10 +000072% 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 +000073% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78% MagickCommandGenesis() applies image processing options to an image as
79% prescribed by command line options.
80%
81% The format of the MagickCommandGenesis method is:
82%
83% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000084% MagickCommand command,int argc,char **argv,char **metadata,
85% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000086%
87% A description of each parameter follows:
88%
89% o image_info: the image info.
90%
cristy5063d812010-10-19 16:28:10 +000091% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
92% MogrifyImageCommand, CompositeImageCommand, CompareImageCommand,
93% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
94% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000095%
96% o argc: Specifies a pointer to an integer describing the number of
97% elements in the argument vector.
98%
99% o argv: Specifies a pointer to a text array containing the command line
100% arguments.
101%
cristy5063d812010-10-19 16:28:10 +0000102% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000103%
104% o exception: return any errors or warnings in this structure.
105%
106*/
107WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
108 MagickCommand command,int argc,char **argv,char **metadata,
109 ExceptionInfo *exception)
110{
111 char
112 *option;
113
114 double
115 duration,
116 elapsed_time,
117 user_time;
118
cristy3980b0d2009-10-25 14:37:13 +0000119 MagickBooleanType
120 concurrent,
121 regard_warnings,
122 status;
123
cristybb503372010-05-27 20:51:26 +0000124 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000125 i;
126
127 TimerInfo
128 *timer;
129
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristy3980b0d2009-10-25 14:37:13 +0000131 iterations;
132
cristyd0a94fa2010-03-12 14:18:11 +0000133 (void) setlocale(LC_ALL,"");
134 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000135 concurrent=MagickFalse;
136 duration=(-1.0);
137 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000138 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000139 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000140 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000141 {
142 option=argv[i];
143 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
144 continue;
145 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000146 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000147 if (LocaleCompare("concurrent",option+1) == 0)
148 concurrent=MagickTrue;
149 if (LocaleCompare("debug",option+1) == 0)
150 (void) SetLogEventMask(argv[++i]);
151 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000152 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000153 if (LocaleCompare("regard-warnings",option+1) == 0)
154 regard_warnings=MagickTrue;
155 }
156 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000157 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000158 {
cristybb503372010-05-27 20:51:26 +0000159 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000160 {
cristy33557d72009-11-06 00:54:33 +0000161 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000162 continue;
163 if (duration > 0)
164 {
165 if (GetElapsedTime(timer) > duration)
166 continue;
167 (void) ContinueTimer(timer);
168 }
169 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000170 if (exception->severity != UndefinedException)
171 {
172 if ((exception->severity > ErrorException) ||
173 (regard_warnings != MagickFalse))
174 status=MagickTrue;
175 CatchException(exception);
176 }
cristy3d1a5512009-10-25 21:23:27 +0000177 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000178 {
179 (void) fputs(*metadata,stdout);
180 (void) fputc('\n',stdout);
181 *metadata=DestroyString(*metadata);
182 }
183 }
184 }
cristyceae09d2009-10-28 17:18:47 +0000185 else
186 {
187 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000188#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000189 # pragma omp parallel for shared(status)
190#endif
cristybb503372010-05-27 20:51:26 +0000191 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000192 {
cristy33557d72009-11-06 00:54:33 +0000193 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000194 continue;
195 if (duration > 0)
196 {
197 if (GetElapsedTime(timer) > duration)
198 continue;
199 (void) ContinueTimer(timer);
200 }
201 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000202#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000203 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000204#endif
205 {
206 if (exception->severity != UndefinedException)
207 {
208 if ((exception->severity > ErrorException) ||
209 (regard_warnings != MagickFalse))
210 status=MagickTrue;
211 CatchException(exception);
212 }
213 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
214 {
215 (void) fputs(*metadata,stdout);
216 (void) fputc('\n',stdout);
217 *metadata=DestroyString(*metadata);
218 }
219 }
220 }
221 }
cristy3980b0d2009-10-25 14:37:13 +0000222 if (iterations > 1)
223 {
224 elapsed_time=GetElapsedTime(timer);
225 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000226 (void) fprintf(stderr,
cristye8c25f92010-06-03 00:53:06 +0000227 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
228 iterations,1.0*iterations/elapsed_time,user_time,(double)
229 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
230 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000231 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000232 }
233 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000234 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000235}
236
237/*
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239% %
240% %
241% %
cristy3ed852e2009-09-05 21:47:34 +0000242+ M o g r i f y I m a g e %
243% %
244% %
245% %
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247%
248% MogrifyImage() applies image processing options to an image as prescribed
249% by command line options.
250%
251% The format of the MogrifyImage method is:
252%
253% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
254% const char **argv,Image **image)
255%
256% A description of each parameter follows:
257%
258% o image_info: the image info..
259%
260% o argc: Specifies a pointer to an integer describing the number of
261% elements in the argument vector.
262%
263% o argv: Specifies a pointer to a text array containing the command line
264% arguments.
265%
266% o image: the image.
267%
268% o exception: return any errors or warnings in this structure.
269%
270*/
271
272static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
273 ExceptionInfo *exception)
274{
275 char
276 key[MaxTextExtent];
277
278 ExceptionInfo
279 *sans_exception;
280
281 Image
282 *image;
283
284 ImageInfo
285 *read_info;
286
287 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
288 sans_exception=AcquireExceptionInfo();
289 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
290 sans_exception=DestroyExceptionInfo(sans_exception);
291 if (image != (Image *) NULL)
292 return(image);
293 read_info=CloneImageInfo(image_info);
294 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
295 image=ReadImage(read_info,exception);
296 read_info=DestroyImageInfo(read_info);
297 if (image != (Image *) NULL)
298 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
299 return(image);
300}
301
cristy3ed852e2009-09-05 21:47:34 +0000302static MagickBooleanType IsPathWritable(const char *path)
303{
304 if (IsPathAccessible(path) == MagickFalse)
305 return(MagickFalse);
306 if (access(path,W_OK) != 0)
307 return(MagickFalse);
308 return(MagickTrue);
309}
310
cristybb503372010-05-27 20:51:26 +0000311static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000312{
313 if (x > y)
314 return(x);
315 return(y);
316}
317
318static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000319 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000320 void *wand_unused(client_data))
321{
322 char
323 message[MaxTextExtent],
324 tag[MaxTextExtent];
325
326 const char
327 *locale_message;
328
329 register char
330 *p;
331
cristyb32b90a2009-09-07 21:45:48 +0000332 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000333 return(MagickTrue);
334 (void) CopyMagickMemory(tag,text,MaxTextExtent);
335 p=strrchr(tag,'/');
336 if (p != (char *) NULL)
337 *p='\0';
338 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
339 locale_message=GetLocaleMessage(message);
340 if (locale_message == message)
341 locale_message=tag;
342 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000343 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
cristyf2faecf2010-05-28 19:19:36 +0000344 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000345 else
cristyb32b90a2009-09-07 21:45:48 +0000346 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
cristyf2faecf2010-05-28 19:19:36 +0000347 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
cristyb32b90a2009-09-07 21:45:48 +0000348 (100L*offset/(extent-1)));
349 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000350 (void) fprintf(stderr,"\n");
351 (void) fflush(stderr);
352 return(MagickTrue);
353}
354
355static Image *SparseColorOption(const Image *image,const ChannelType channel,
356 const SparseColorMethod method,const char *arguments,
357 const MagickBooleanType color_from_image,ExceptionInfo *exception)
358{
359 ChannelType
360 channels;
361
362 char
363 token[MaxTextExtent];
364
365 const char
366 *p;
367
368 double
369 *sparse_arguments;
370
cristybb503372010-05-27 20:51:26 +0000371 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000372 x;
373
cristybb503372010-05-27 20:51:26 +0000374 size_t
cristy3ed852e2009-09-05 21:47:34 +0000375 number_arguments;
376
cristybb503372010-05-27 20:51:26 +0000377 size_t
cristy3ed852e2009-09-05 21:47:34 +0000378 number_colors;
379
380 Image
381 *sparse_image;
382
383 MagickPixelPacket
384 color;
385
386 MagickBooleanType
387 error;
388
389 assert(image != (Image *) NULL);
390 assert(image->signature == MagickSignature);
391 if (image->debug != MagickFalse)
392 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
393 assert(exception != (ExceptionInfo *) NULL);
394 assert(exception->signature == MagickSignature);
395 /*
396 Limit channels according to image - and add up number of color channel.
397 */
398 channels=channel;
399 if (image->colorspace != CMYKColorspace)
400 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
401 if (image->matte == MagickFalse)
402 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
403 number_colors=0;
404 if ((channels & RedChannel) != 0)
405 number_colors++;
406 if ((channels & GreenChannel) != 0)
407 number_colors++;
408 if ((channels & BlueChannel) != 0)
409 number_colors++;
410 if ((channels & IndexChannel) != 0)
411 number_colors++;
412 if ((channels & OpacityChannel) != 0)
413 number_colors++;
414 /*
415 Read string, to determine number of arguments needed,
416 */
417 p=arguments;
418 x=0;
419 while( *p != '\0' )
420 {
421 GetMagickToken(p,&p,token);
422 if ( token[0] == ',' ) continue;
423 if ( isalpha((int) token[0]) || token[0] == '#' ) {
424 if ( color_from_image ) {
425 (void) ThrowMagickException(exception,GetMagickModule(),
426 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
427 "Color arg given, when colors are coming from image");
428 return( (Image *)NULL);
429 }
430 x += number_colors; /* color argument */
431 }
432 else {
433 x++; /* floating point argument */
434 }
435 }
436 error=MagickTrue;
437 if ( color_from_image ) {
438 /* just the control points are being given */
439 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
440 number_arguments=(x/2)*(2+number_colors);
441 }
442 else {
443 /* control points and color values */
444 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
445 number_arguments=x;
446 }
447 if ( error ) {
448 (void) ThrowMagickException(exception,GetMagickModule(),
449 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
450 "Invalid number of Arguments");
451 return( (Image *)NULL);
452 }
453
454 /* Allocate and fill in the floating point arguments */
455 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
456 sizeof(*sparse_arguments));
457 if (sparse_arguments == (double *) NULL) {
458 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
459 "MemoryAllocationFailed","%s","SparseColorOption");
460 return( (Image *)NULL);
461 }
462 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
463 sizeof(*sparse_arguments));
464 p=arguments;
465 x=0;
466 while( *p != '\0' && x < number_arguments ) {
467 /* X coordinate */
468 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
469 if ( token[0] == '\0' ) break;
470 if ( isalpha((int) token[0]) || token[0] == '#' ) {
471 (void) ThrowMagickException(exception,GetMagickModule(),
472 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
473 "Color found, instead of X-coord");
474 error = MagickTrue;
475 break;
476 }
cristyf2f27272009-12-17 14:48:46 +0000477 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000478 /* Y coordinate */
479 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
480 if ( token[0] == '\0' ) break;
481 if ( isalpha((int) token[0]) || token[0] == '#' ) {
482 (void) ThrowMagickException(exception,GetMagickModule(),
483 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
484 "Color found, instead of Y-coord");
485 error = MagickTrue;
486 break;
487 }
cristyf2f27272009-12-17 14:48:46 +0000488 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000489 /* color values for this control point */
490#if 0
491 if ( (color_from_image ) {
492 /* get color from image */
493 /* HOW??? */
494 }
495 else
496#endif
497 {
498 /* color name or function given in string argument */
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 /* Color string given */
503 (void) QueryMagickColor(token,&color,exception);
504 if ( channels & RedChannel )
505 sparse_arguments[x++] = QuantumScale*color.red;
506 if ( channels & GreenChannel )
507 sparse_arguments[x++] = QuantumScale*color.green;
508 if ( channels & BlueChannel )
509 sparse_arguments[x++] = QuantumScale*color.blue;
510 if ( channels & IndexChannel )
511 sparse_arguments[x++] = QuantumScale*color.index;
512 if ( channels & OpacityChannel )
513 sparse_arguments[x++] = QuantumScale*color.opacity;
514 }
515 else {
516#if 0
517 /* the color name/function/value was not found - error */
518 break;
519#else
520 /* Colors given as a set of floating point values - experimental */
521 /* NB: token contains the first floating point value to use! */
522 if ( channels & RedChannel ) {
523 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
524 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
525 break;
cristy0f19e682009-12-17 14:55:51 +0000526 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000527 token[0] = ','; /* used this token - get another */
528 }
529 if ( channels & GreenChannel ) {
530 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
531 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
532 break;
cristy0f19e682009-12-17 14:55:51 +0000533 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000534 token[0] = ','; /* used this token - get another */
535 }
536 if ( channels & BlueChannel ) {
537 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
538 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
539 break;
cristy0f19e682009-12-17 14:55:51 +0000540 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000541 token[0] = ','; /* used this token - get another */
542 }
543 if ( channels & IndexChannel ) {
544 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
545 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
546 break;
cristy0f19e682009-12-17 14:55:51 +0000547 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000548 token[0] = ','; /* used this token - get another */
549 }
550 if ( channels & OpacityChannel ) {
551 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
552 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
553 break;
cristy0f19e682009-12-17 14:55:51 +0000554 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000555 token[0] = ','; /* used this token - get another */
556 }
557#endif
558 }
559 }
560 }
561 if ( number_arguments != x && !error ) {
562 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
563 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
564 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
565 return( (Image *)NULL);
566 }
567 if ( error )
568 return( (Image *)NULL);
569
570 /* Call the Interpolation function with the parsed arguments */
571 sparse_image=SparseColorImage(image,channels,method,number_arguments,
572 sparse_arguments,exception);
573 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
574 return( sparse_image );
575}
576
577WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
578 const char **argv,Image **image,ExceptionInfo *exception)
579{
580 ChannelType
581 channel;
582
583 const char
584 *format,
585 *option;
586
587 DrawInfo
588 *draw_info;
589
590 GeometryInfo
591 geometry_info;
592
593 Image
594 *region_image;
595
cristy6b3da3a2010-06-20 02:21:46 +0000596 ImageInfo
597 *mogrify_info;
598
cristyebbcfea2011-02-25 02:43:54 +0000599 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000600 status;
601
602 MagickPixelPacket
603 fill;
604
605 MagickStatusType
606 flags;
607
608 QuantizeInfo
609 *quantize_info;
610
611 RectangleInfo
612 geometry,
613 region_geometry;
614
cristybb503372010-05-27 20:51:26 +0000615 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000616 i;
617
cristyebbcfea2011-02-25 02:43:54 +0000618 ssize_t
619 count;
620
cristy3ed852e2009-09-05 21:47:34 +0000621 /*
622 Initialize method variables.
623 */
624 assert(image_info != (const ImageInfo *) NULL);
625 assert(image_info->signature == MagickSignature);
626 assert(image != (Image **) NULL);
627 assert((*image)->signature == MagickSignature);
628 if ((*image)->debug != MagickFalse)
629 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
630 if (argc < 0)
631 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000632 mogrify_info=CloneImageInfo(image_info);
633 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
634 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +0000635 SetGeometryInfo(&geometry_info);
636 GetMagickPixelPacket(*image,&fill);
637 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
638 &fill);
cristy6b3da3a2010-06-20 02:21:46 +0000639 channel=mogrify_info->channel;
640 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000641 SetGeometry(*image,&region_geometry);
642 region_image=NewImageList();
643 /*
644 Transmogrify the image.
645 */
cristybb503372010-05-27 20:51:26 +0000646 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000647 {
648 option=argv[i];
649 if (IsMagickOption(option) == MagickFalse)
650 continue;
651 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
652 0L);
cristycee97112010-05-28 00:44:52 +0000653 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000654 break;
cristy6b3da3a2010-06-20 02:21:46 +0000655 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +0000656 switch (*(option+1))
657 {
658 case 'a':
659 {
660 if (LocaleCompare("adaptive-blur",option+1) == 0)
661 {
662 Image
663 *blur_image;
664
665 /*
666 Adaptive blur image.
667 */
cristy6b3da3a2010-06-20 02:21:46 +0000668 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000669 flags=ParseGeometry(argv[i+1],&geometry_info);
670 if ((flags & SigmaValue) == 0)
671 geometry_info.sigma=1.0;
672 blur_image=AdaptiveBlurImageChannel(*image,channel,
673 geometry_info.rho,geometry_info.sigma,exception);
674 if (blur_image == (Image *) NULL)
675 break;
676 *image=DestroyImage(*image);
677 *image=blur_image;
678 break;
679 }
680 if (LocaleCompare("adaptive-resize",option+1) == 0)
681 {
682 Image
683 *resize_image;
684
685 /*
686 Adaptive resize image.
687 */
cristy6b3da3a2010-06-20 02:21:46 +0000688 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000689 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
690 resize_image=AdaptiveResizeImage(*image,geometry.width,
691 geometry.height,exception);
692 if (resize_image == (Image *) NULL)
693 break;
694 *image=DestroyImage(*image);
695 *image=resize_image;
696 break;
697 }
698 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
699 {
700 Image
701 *sharp_image;
702
703 /*
704 Adaptive sharpen image.
705 */
cristy6b3da3a2010-06-20 02:21:46 +0000706 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000707 flags=ParseGeometry(argv[i+1],&geometry_info);
708 if ((flags & SigmaValue) == 0)
709 geometry_info.sigma=1.0;
710 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
711 geometry_info.rho,geometry_info.sigma,exception);
712 if (sharp_image == (Image *) NULL)
713 break;
714 *image=DestroyImage(*image);
715 *image=sharp_image;
716 break;
717 }
718 if (LocaleCompare("affine",option+1) == 0)
719 {
720 /*
721 Affine matrix.
722 */
723 if (*option == '+')
724 {
725 GetAffineMatrix(&draw_info->affine);
726 break;
727 }
728 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
729 break;
730 }
731 if (LocaleCompare("alpha",option+1) == 0)
732 {
733 AlphaChannelType
734 alpha_type;
735
cristy6b3da3a2010-06-20 02:21:46 +0000736 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000737 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
738 MagickFalse,argv[i+1]);
739 (void) SetImageAlphaChannel(*image,alpha_type);
740 InheritException(exception,&(*image)->exception);
741 break;
742 }
743 if (LocaleCompare("annotate",option+1) == 0)
744 {
745 char
746 *text,
747 geometry[MaxTextExtent];
748
749 /*
750 Annotate image.
751 */
cristy6b3da3a2010-06-20 02:21:46 +0000752 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000753 SetGeometryInfo(&geometry_info);
754 flags=ParseGeometry(argv[i+1],&geometry_info);
755 if ((flags & SigmaValue) == 0)
756 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000757 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000758 InheritException(exception,&(*image)->exception);
759 if (text == (char *) NULL)
760 break;
761 (void) CloneString(&draw_info->text,text);
762 text=DestroyString(text);
763 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
764 geometry_info.xi,geometry_info.psi);
765 (void) CloneString(&draw_info->geometry,geometry);
766 draw_info->affine.sx=cos(DegreesToRadians(
767 fmod(geometry_info.rho,360.0)));
768 draw_info->affine.rx=sin(DegreesToRadians(
769 fmod(geometry_info.rho,360.0)));
770 draw_info->affine.ry=(-sin(DegreesToRadians(
771 fmod(geometry_info.sigma,360.0))));
772 draw_info->affine.sy=cos(DegreesToRadians(
773 fmod(geometry_info.sigma,360.0)));
774 (void) AnnotateImage(*image,draw_info);
775 InheritException(exception,&(*image)->exception);
776 break;
777 }
778 if (LocaleCompare("antialias",option+1) == 0)
779 {
780 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
781 MagickFalse;
782 draw_info->text_antialias=(*option == '-') ? MagickTrue :
783 MagickFalse;
784 break;
785 }
786 if (LocaleCompare("auto-gamma",option+1) == 0)
787 {
788 /*
789 Auto Adjust Gamma of image based on its mean
790 */
cristy6b3da3a2010-06-20 02:21:46 +0000791 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000792 (void) AutoGammaImageChannel(*image,channel);
793 break;
794 }
795 if (LocaleCompare("auto-level",option+1) == 0)
796 {
797 /*
798 Perfectly Normalize (max/min stretch) the image
799 */
cristy6b3da3a2010-06-20 02:21:46 +0000800 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000801 (void) AutoLevelImageChannel(*image,channel);
802 break;
803 }
804 if (LocaleCompare("auto-orient",option+1) == 0)
805 {
806 Image
807 *orient_image;
808
cristy6b3da3a2010-06-20 02:21:46 +0000809 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000810 orient_image=NewImageList();
811 switch ((*image)->orientation)
812 {
813 case TopRightOrientation:
814 {
815 orient_image=FlopImage(*image,exception);
816 break;
817 }
818 case BottomRightOrientation:
819 {
820 orient_image=RotateImage(*image,180.0,exception);
821 break;
822 }
823 case BottomLeftOrientation:
824 {
825 orient_image=FlipImage(*image,exception);
826 break;
827 }
828 case LeftTopOrientation:
829 {
830 orient_image=TransposeImage(*image,exception);
831 break;
832 }
833 case RightTopOrientation:
834 {
835 orient_image=RotateImage(*image,90.0,exception);
836 break;
837 }
838 case RightBottomOrientation:
839 {
840 orient_image=TransverseImage(*image,exception);
841 break;
842 }
843 case LeftBottomOrientation:
844 {
845 orient_image=RotateImage(*image,270.0,exception);
846 break;
847 }
848 default:
849 break;
850 }
851 if (orient_image == (Image *) NULL)
852 break;
853 orient_image->orientation=TopLeftOrientation;
854 *image=DestroyImage(*image);
855 *image=orient_image;
856 break;
857 }
858 break;
859 }
860 case 'b':
861 {
862 if (LocaleCompare("black-threshold",option+1) == 0)
863 {
864 /*
865 Black threshold image.
866 */
cristy6b3da3a2010-06-20 02:21:46 +0000867 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000868 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
869 exception);
870 InheritException(exception,&(*image)->exception);
871 break;
872 }
873 if (LocaleCompare("blue-shift",option+1) == 0)
874 {
875 Image
876 *shift_image;
877
878 /*
879 Blue shift image.
880 */
cristy6b3da3a2010-06-20 02:21:46 +0000881 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000882 geometry_info.rho=1.5;
883 if (*option == '-')
884 flags=ParseGeometry(argv[i+1],&geometry_info);
885 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
886 if (shift_image == (Image *) NULL)
887 break;
888 *image=DestroyImage(*image);
889 *image=shift_image;
890 break;
891 }
892 if (LocaleCompare("blur",option+1) == 0)
893 {
894 Image
895 *blur_image;
896
897 /*
898 Gaussian blur image.
899 */
cristy6b3da3a2010-06-20 02:21:46 +0000900 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000901 flags=ParseGeometry(argv[i+1],&geometry_info);
902 if ((flags & SigmaValue) == 0)
903 geometry_info.sigma=1.0;
904 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
905 geometry_info.sigma,exception);
906 if (blur_image == (Image *) NULL)
907 break;
908 *image=DestroyImage(*image);
909 *image=blur_image;
910 break;
911 }
912 if (LocaleCompare("border",option+1) == 0)
913 {
914 Image
915 *border_image;
916
917 /*
918 Surround image with a border of solid color.
919 */
cristy6b3da3a2010-06-20 02:21:46 +0000920 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000921 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
922 if ((flags & SigmaValue) == 0)
923 geometry.height=geometry.width;
924 border_image=BorderImage(*image,&geometry,exception);
925 if (border_image == (Image *) NULL)
926 break;
927 *image=DestroyImage(*image);
928 *image=border_image;
929 break;
930 }
931 if (LocaleCompare("bordercolor",option+1) == 0)
932 {
933 if (*option == '+')
934 {
935 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
936 exception);
937 break;
938 }
939 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
940 exception);
941 break;
942 }
943 if (LocaleCompare("box",option+1) == 0)
944 {
945 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
946 exception);
947 break;
948 }
cristya28d6b82010-01-11 20:03:47 +0000949 if (LocaleCompare("brightness-contrast",option+1) == 0)
950 {
951 double
952 brightness,
953 contrast;
954
955 GeometryInfo
956 geometry_info;
957
958 MagickStatusType
959 flags;
960
961 /*
962 Brightness / contrast image.
963 */
cristy6b3da3a2010-06-20 02:21:46 +0000964 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000965 flags=ParseGeometry(argv[i+1],&geometry_info);
966 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000967 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000968 if ((flags & SigmaValue) != 0)
969 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000970 (void) BrightnessContrastImageChannel(*image,channel,brightness,
971 contrast);
cristya28d6b82010-01-11 20:03:47 +0000972 InheritException(exception,&(*image)->exception);
973 break;
974 }
cristy3ed852e2009-09-05 21:47:34 +0000975 break;
976 }
977 case 'c':
978 {
979 if (LocaleCompare("cdl",option+1) == 0)
980 {
981 char
982 *color_correction_collection;
983
984 /*
985 Color correct with a color decision list.
986 */
cristy6b3da3a2010-06-20 02:21:46 +0000987 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000988 color_correction_collection=FileToString(argv[i+1],~0,exception);
989 if (color_correction_collection == (char *) NULL)
990 break;
991 (void) ColorDecisionListImage(*image,color_correction_collection);
992 InheritException(exception,&(*image)->exception);
993 break;
994 }
995 if (LocaleCompare("channel",option+1) == 0)
996 {
997 if (*option == '+')
998 {
999 channel=DefaultChannels;
1000 break;
1001 }
1002 channel=(ChannelType) ParseChannelOption(argv[i+1]);
1003 break;
1004 }
1005 if (LocaleCompare("charcoal",option+1) == 0)
1006 {
1007 Image
1008 *charcoal_image;
1009
1010 /*
1011 Charcoal image.
1012 */
cristy6b3da3a2010-06-20 02:21:46 +00001013 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001014 flags=ParseGeometry(argv[i+1],&geometry_info);
1015 if ((flags & SigmaValue) == 0)
1016 geometry_info.sigma=1.0;
1017 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1018 geometry_info.sigma,exception);
1019 if (charcoal_image == (Image *) NULL)
1020 break;
1021 *image=DestroyImage(*image);
1022 *image=charcoal_image;
1023 break;
1024 }
1025 if (LocaleCompare("chop",option+1) == 0)
1026 {
1027 Image
1028 *chop_image;
1029
1030 /*
1031 Chop the image.
1032 */
cristy6b3da3a2010-06-20 02:21:46 +00001033 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001034 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1035 chop_image=ChopImage(*image,&geometry,exception);
1036 if (chop_image == (Image *) NULL)
1037 break;
1038 *image=DestroyImage(*image);
1039 *image=chop_image;
1040 break;
1041 }
cristy1eb45dd2009-09-25 16:38:06 +00001042 if (LocaleCompare("clamp",option+1) == 0)
1043 {
1044 /*
1045 Clamp image.
1046 */
cristy6b3da3a2010-06-20 02:21:46 +00001047 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001048 (void) ClampImageChannel(*image,channel);
1049 InheritException(exception,&(*image)->exception);
1050 break;
1051 }
cristy3ed852e2009-09-05 21:47:34 +00001052 if (LocaleCompare("clip",option+1) == 0)
1053 {
cristy6b3da3a2010-06-20 02:21:46 +00001054 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001055 if (*option == '+')
1056 {
1057 (void) SetImageClipMask(*image,(Image *) NULL);
1058 InheritException(exception,&(*image)->exception);
1059 break;
1060 }
1061 (void) ClipImage(*image);
1062 InheritException(exception,&(*image)->exception);
1063 break;
1064 }
1065 if (LocaleCompare("clip-mask",option+1) == 0)
1066 {
cristyb0d3bb92010-09-22 14:37:58 +00001067 CacheView
1068 *mask_view;
cristya01cbea2010-11-03 16:33:33 +00001069
cristy3ed852e2009-09-05 21:47:34 +00001070 Image
cristyb0d3bb92010-09-22 14:37:58 +00001071 *mask_image;
cristy3ed852e2009-09-05 21:47:34 +00001072
cristybb503372010-05-27 20:51:26 +00001073 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001074 y;
1075
cristybb503372010-05-27 20:51:26 +00001076 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001077 x;
1078
1079 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001080 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001081
cristy6b3da3a2010-06-20 02:21:46 +00001082 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001083 if (*option == '+')
1084 {
1085 /*
1086 Remove a mask.
1087 */
1088 (void) SetImageMask(*image,(Image *) NULL);
1089 InheritException(exception,&(*image)->exception);
1090 break;
1091 }
1092 /*
1093 Set the image mask.
1094 */
cristyb0d3bb92010-09-22 14:37:58 +00001095 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1096 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001097 break;
cristyb0d3bb92010-09-22 14:37:58 +00001098 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1099 return(MagickFalse);
1100 mask_view=AcquireCacheView(mask_image);
1101 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001102 {
cristyb0d3bb92010-09-22 14:37:58 +00001103 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1104 exception);
cristy3ed852e2009-09-05 21:47:34 +00001105 if (q == (PixelPacket *) NULL)
1106 break;
cristyb0d3bb92010-09-22 14:37:58 +00001107 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001108 {
cristyb0d3bb92010-09-22 14:37:58 +00001109 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001110 q->opacity=PixelIntensityToQuantum(q);
1111 q->red=q->opacity;
1112 q->green=q->opacity;
1113 q->blue=q->opacity;
1114 q++;
1115 }
cristyb0d3bb92010-09-22 14:37:58 +00001116 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001117 break;
1118 }
cristyb0d3bb92010-09-22 14:37:58 +00001119 mask_view=DestroyCacheView(mask_view);
1120 mask_image->matte=MagickTrue;
1121 (void) SetImageClipMask(*image,mask_image);
1122 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001123 InheritException(exception,&(*image)->exception);
1124 break;
1125 }
1126 if (LocaleCompare("clip-path",option+1) == 0)
1127 {
cristy6b3da3a2010-06-20 02:21:46 +00001128 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001129 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1130 MagickFalse);
1131 InheritException(exception,&(*image)->exception);
1132 break;
1133 }
1134 if (LocaleCompare("colorize",option+1) == 0)
1135 {
1136 Image
1137 *colorize_image;
1138
1139 /*
1140 Colorize the image.
1141 */
cristy6b3da3a2010-06-20 02:21:46 +00001142 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001143 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1144 exception);
1145 if (colorize_image == (Image *) NULL)
1146 break;
1147 *image=DestroyImage(*image);
1148 *image=colorize_image;
1149 break;
1150 }
cristye6365592010-04-02 17:31:23 +00001151 if (LocaleCompare("color-matrix",option+1) == 0)
1152 {
1153 Image
1154 *color_image;
1155
1156 KernelInfo
1157 *kernel;
1158
cristy6b3da3a2010-06-20 02:21:46 +00001159 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001160 kernel=AcquireKernelInfo(argv[i+1]);
1161 if (kernel == (KernelInfo *) NULL)
1162 break;
1163 color_image=ColorMatrixImage(*image,kernel,exception);
1164 kernel=DestroyKernelInfo(kernel);
1165 if (color_image == (Image *) NULL)
1166 break;
1167 *image=DestroyImage(*image);
1168 *image=color_image;
1169 break;
1170 }
cristy3ed852e2009-09-05 21:47:34 +00001171 if (LocaleCompare("colors",option+1) == 0)
1172 {
1173 /*
1174 Reduce the number of colors in the image.
1175 */
cristy6b3da3a2010-06-20 02:21:46 +00001176 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001177 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001178 if (quantize_info->number_colors == 0)
1179 break;
1180 if (((*image)->storage_class == DirectClass) ||
1181 (*image)->colors > quantize_info->number_colors)
1182 (void) QuantizeImage(quantize_info,*image);
1183 else
1184 (void) CompressImageColormap(*image);
1185 InheritException(exception,&(*image)->exception);
1186 break;
1187 }
1188 if (LocaleCompare("colorspace",option+1) == 0)
1189 {
1190 ColorspaceType
1191 colorspace;
1192
cristy6b3da3a2010-06-20 02:21:46 +00001193 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001194 if (*option == '+')
1195 {
1196 (void) TransformImageColorspace(*image,RGBColorspace);
1197 InheritException(exception,&(*image)->exception);
1198 break;
1199 }
1200 colorspace=(ColorspaceType) ParseMagickOption(
1201 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1202 (void) TransformImageColorspace(*image,colorspace);
1203 InheritException(exception,&(*image)->exception);
1204 break;
1205 }
1206 if (LocaleCompare("contrast",option+1) == 0)
1207 {
cristy6b3da3a2010-06-20 02:21:46 +00001208 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001209 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1210 MagickFalse);
1211 InheritException(exception,&(*image)->exception);
1212 break;
1213 }
1214 if (LocaleCompare("contrast-stretch",option+1) == 0)
1215 {
1216 double
1217 black_point,
1218 white_point;
1219
cristy3ed852e2009-09-05 21:47:34 +00001220 MagickStatusType
1221 flags;
1222
1223 /*
1224 Contrast stretch image.
1225 */
cristy6b3da3a2010-06-20 02:21:46 +00001226 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001227 flags=ParseGeometry(argv[i+1],&geometry_info);
1228 black_point=geometry_info.rho;
1229 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1230 black_point;
1231 if ((flags & PercentValue) != 0)
1232 {
1233 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1234 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1235 }
1236 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1237 white_point;
1238 (void) ContrastStretchImageChannel(*image,channel,black_point,
1239 white_point);
1240 InheritException(exception,&(*image)->exception);
1241 break;
1242 }
1243 if (LocaleCompare("convolve",option+1) == 0)
1244 {
cristy36826ab2010-03-06 01:29:30 +00001245 double
1246 gamma;
1247
cristy3ed852e2009-09-05 21:47:34 +00001248 Image
1249 *convolve_image;
1250
cristy2be15382010-01-21 02:38:03 +00001251 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001252 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001253
cristybb503372010-05-27 20:51:26 +00001254 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001255 j;
1256
cristy6b3da3a2010-06-20 02:21:46 +00001257 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001258 kernel=AcquireKernelInfo(argv[i+1]);
1259 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001260 break;
cristy36826ab2010-03-06 01:29:30 +00001261 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001262 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001263 gamma+=kernel->values[j];
1264 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001265 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001266 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001267 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001268 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001269 if (convolve_image == (Image *) NULL)
1270 break;
1271 *image=DestroyImage(*image);
1272 *image=convolve_image;
1273 break;
1274 }
1275 if (LocaleCompare("crop",option+1) == 0)
1276 {
cristy6b3da3a2010-06-20 02:21:46 +00001277 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001278 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1279 if (((geometry.width != 0) || (geometry.height != 0)) &&
1280 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1281 break;
1282 (void) TransformImage(image,argv[i+1],(char *) NULL);
1283 InheritException(exception,&(*image)->exception);
1284 break;
1285 }
1286 if (LocaleCompare("cycle",option+1) == 0)
1287 {
1288 /*
1289 Cycle an image colormap.
1290 */
cristy6b3da3a2010-06-20 02:21:46 +00001291 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001292 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001293 InheritException(exception,&(*image)->exception);
1294 break;
1295 }
1296 break;
1297 }
1298 case 'd':
1299 {
1300 if (LocaleCompare("decipher",option+1) == 0)
1301 {
1302 StringInfo
1303 *passkey;
1304
1305 /*
1306 Decipher pixels.
1307 */
cristy6b3da3a2010-06-20 02:21:46 +00001308 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001309 passkey=FileToStringInfo(argv[i+1],~0,exception);
1310 if (passkey != (StringInfo *) NULL)
1311 {
1312 (void) PasskeyDecipherImage(*image,passkey,exception);
1313 passkey=DestroyStringInfo(passkey);
1314 }
1315 break;
1316 }
1317 if (LocaleCompare("density",option+1) == 0)
1318 {
1319 /*
1320 Set image density.
1321 */
1322 (void) CloneString(&draw_info->density,argv[i+1]);
1323 break;
1324 }
1325 if (LocaleCompare("depth",option+1) == 0)
1326 {
cristy6b3da3a2010-06-20 02:21:46 +00001327 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001328 if (*option == '+')
1329 {
1330 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1331 break;
1332 }
cristye27293e2009-12-18 02:53:20 +00001333 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001334 break;
1335 }
1336 if (LocaleCompare("deskew",option+1) == 0)
1337 {
1338 double
1339 threshold;
1340
1341 Image
1342 *deskew_image;
1343
1344 /*
1345 Straighten the image.
1346 */
cristy6b3da3a2010-06-20 02:21:46 +00001347 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001348 if (*option == '+')
1349 threshold=40.0*QuantumRange/100.0;
1350 else
cristyf2f27272009-12-17 14:48:46 +00001351 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001352 deskew_image=DeskewImage(*image,threshold,exception);
1353 if (deskew_image == (Image *) NULL)
1354 break;
1355 *image=DestroyImage(*image);
1356 *image=deskew_image;
1357 break;
1358 }
1359 if (LocaleCompare("despeckle",option+1) == 0)
1360 {
1361 Image
1362 *despeckle_image;
1363
1364 /*
1365 Reduce the speckles within an image.
1366 */
cristy6b3da3a2010-06-20 02:21:46 +00001367 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001368 despeckle_image=DespeckleImage(*image,exception);
1369 if (despeckle_image == (Image *) NULL)
1370 break;
1371 *image=DestroyImage(*image);
1372 *image=despeckle_image;
1373 break;
1374 }
1375 if (LocaleCompare("display",option+1) == 0)
1376 {
1377 (void) CloneString(&draw_info->server_name,argv[i+1]);
1378 break;
1379 }
cristy3ed852e2009-09-05 21:47:34 +00001380 if (LocaleCompare("distort",option+1) == 0)
1381 {
1382 char
1383 *args,
1384 token[MaxTextExtent];
1385
1386 const char
1387 *p;
1388
1389 DistortImageMethod
1390 method;
1391
1392 double
1393 *arguments;
1394
1395 Image
1396 *distort_image;
1397
cristybb503372010-05-27 20:51:26 +00001398 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001399 x;
1400
cristybb503372010-05-27 20:51:26 +00001401 size_t
cristy3ed852e2009-09-05 21:47:34 +00001402 number_arguments;
1403
1404 /*
1405 Distort image.
1406 */
cristy6b3da3a2010-06-20 02:21:46 +00001407 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001408 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1409 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001410 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001411 InheritException(exception,&(*image)->exception);
1412 if (args == (char *) NULL)
1413 break;
1414 p=(char *) args;
1415 for (x=0; *p != '\0'; x++)
1416 {
1417 GetMagickToken(p,&p,token);
1418 if (*token == ',')
1419 GetMagickToken(p,&p,token);
1420 }
cristybb503372010-05-27 20:51:26 +00001421 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001422 arguments=(double *) AcquireQuantumMemory(number_arguments,
1423 sizeof(*arguments));
1424 if (arguments == (double *) NULL)
1425 ThrowWandFatalException(ResourceLimitFatalError,
1426 "MemoryAllocationFailed",(*image)->filename);
1427 (void) ResetMagickMemory(arguments,0,number_arguments*
1428 sizeof(*arguments));
1429 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001430 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001431 {
1432 GetMagickToken(p,&p,token);
1433 if (*token == ',')
1434 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001435 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001436 }
1437 args=DestroyString(args);
1438 distort_image=DistortImage(*image,method,number_arguments,arguments,
1439 (*option == '+') ? MagickTrue : MagickFalse,exception);
1440 arguments=(double *) RelinquishMagickMemory(arguments);
1441 if (distort_image == (Image *) NULL)
1442 break;
1443 *image=DestroyImage(*image);
1444 *image=distort_image;
1445 break;
1446 }
1447 if (LocaleCompare("dither",option+1) == 0)
1448 {
1449 if (*option == '+')
1450 {
1451 quantize_info->dither=MagickFalse;
1452 break;
1453 }
1454 quantize_info->dither=MagickTrue;
1455 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1456 MagickDitherOptions,MagickFalse,argv[i+1]);
1457 if (quantize_info->dither_method == NoDitherMethod)
1458 quantize_info->dither=MagickFalse;
1459 break;
1460 }
1461 if (LocaleCompare("draw",option+1) == 0)
1462 {
1463 /*
1464 Draw image.
1465 */
cristy6b3da3a2010-06-20 02:21:46 +00001466 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001467 (void) CloneString(&draw_info->primitive,argv[i+1]);
1468 (void) DrawImage(*image,draw_info);
1469 InheritException(exception,&(*image)->exception);
1470 break;
1471 }
1472 break;
1473 }
1474 case 'e':
1475 {
1476 if (LocaleCompare("edge",option+1) == 0)
1477 {
1478 Image
1479 *edge_image;
1480
1481 /*
1482 Enhance edges in the image.
1483 */
cristy6b3da3a2010-06-20 02:21:46 +00001484 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001485 flags=ParseGeometry(argv[i+1],&geometry_info);
1486 if ((flags & SigmaValue) == 0)
1487 geometry_info.sigma=1.0;
1488 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1489 if (edge_image == (Image *) NULL)
1490 break;
1491 *image=DestroyImage(*image);
1492 *image=edge_image;
1493 break;
1494 }
1495 if (LocaleCompare("emboss",option+1) == 0)
1496 {
1497 Image
1498 *emboss_image;
1499
1500 /*
1501 Gaussian embossen image.
1502 */
cristy6b3da3a2010-06-20 02:21:46 +00001503 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001504 flags=ParseGeometry(argv[i+1],&geometry_info);
1505 if ((flags & SigmaValue) == 0)
1506 geometry_info.sigma=1.0;
1507 emboss_image=EmbossImage(*image,geometry_info.rho,
1508 geometry_info.sigma,exception);
1509 if (emboss_image == (Image *) NULL)
1510 break;
1511 *image=DestroyImage(*image);
1512 *image=emboss_image;
1513 break;
1514 }
1515 if (LocaleCompare("encipher",option+1) == 0)
1516 {
1517 StringInfo
1518 *passkey;
1519
1520 /*
1521 Encipher pixels.
1522 */
cristy6b3da3a2010-06-20 02:21:46 +00001523 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001524 passkey=FileToStringInfo(argv[i+1],~0,exception);
1525 if (passkey != (StringInfo *) NULL)
1526 {
1527 (void) PasskeyEncipherImage(*image,passkey,exception);
1528 passkey=DestroyStringInfo(passkey);
1529 }
1530 break;
1531 }
1532 if (LocaleCompare("encoding",option+1) == 0)
1533 {
1534 (void) CloneString(&draw_info->encoding,argv[i+1]);
1535 break;
1536 }
1537 if (LocaleCompare("enhance",option+1) == 0)
1538 {
1539 Image
1540 *enhance_image;
1541
1542 /*
1543 Enhance image.
1544 */
cristy6b3da3a2010-06-20 02:21:46 +00001545 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001546 enhance_image=EnhanceImage(*image,exception);
1547 if (enhance_image == (Image *) NULL)
1548 break;
1549 *image=DestroyImage(*image);
1550 *image=enhance_image;
1551 break;
1552 }
1553 if (LocaleCompare("equalize",option+1) == 0)
1554 {
1555 /*
1556 Equalize image.
1557 */
cristy6b3da3a2010-06-20 02:21:46 +00001558 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001559 (void) EqualizeImageChannel(*image,channel);
1560 InheritException(exception,&(*image)->exception);
1561 break;
1562 }
1563 if (LocaleCompare("evaluate",option+1) == 0)
1564 {
1565 double
1566 constant;
1567
1568 MagickEvaluateOperator
1569 op;
1570
cristy6b3da3a2010-06-20 02:21:46 +00001571 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001572 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1573 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001574 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001575 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1576 break;
1577 }
1578 if (LocaleCompare("extent",option+1) == 0)
1579 {
1580 Image
1581 *extent_image;
1582
1583 /*
1584 Set the image extent.
1585 */
cristy6b3da3a2010-06-20 02:21:46 +00001586 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001587 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001588 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001589 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001590 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001591 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001592 extent_image=ExtentImage(*image,&geometry,exception);
1593 if (extent_image == (Image *) NULL)
1594 break;
1595 *image=DestroyImage(*image);
1596 *image=extent_image;
1597 break;
1598 }
1599 break;
1600 }
1601 case 'f':
1602 {
1603 if (LocaleCompare("family",option+1) == 0)
1604 {
1605 if (*option == '+')
1606 {
1607 if (draw_info->family != (char *) NULL)
1608 draw_info->family=DestroyString(draw_info->family);
1609 break;
1610 }
1611 (void) CloneString(&draw_info->family,argv[i+1]);
1612 break;
1613 }
cristy0fe961c2010-01-30 03:09:54 +00001614 if (LocaleCompare("features",option+1) == 0)
1615 {
1616 if (*option == '+')
1617 {
1618 (void) DeleteImageArtifact(*image,"identify:features");
1619 break;
1620 }
1621 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1622 break;
1623 }
cristy3ed852e2009-09-05 21:47:34 +00001624 if (LocaleCompare("fill",option+1) == 0)
1625 {
1626 ExceptionInfo
1627 *sans;
1628
1629 GetMagickPixelPacket(*image,&fill);
1630 if (*option == '+')
1631 {
1632 (void) QueryMagickColor("none",&fill,exception);
1633 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1634 if (draw_info->fill_pattern != (Image *) NULL)
1635 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1636 break;
1637 }
1638 sans=AcquireExceptionInfo();
1639 (void) QueryMagickColor(argv[i+1],&fill,sans);
1640 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1641 sans=DestroyExceptionInfo(sans);
1642 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001643 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001644 exception);
1645 break;
1646 }
1647 if (LocaleCompare("flip",option+1) == 0)
1648 {
1649 Image
1650 *flip_image;
1651
1652 /*
1653 Flip image scanlines.
1654 */
cristy6b3da3a2010-06-20 02:21:46 +00001655 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001656 flip_image=FlipImage(*image,exception);
1657 if (flip_image == (Image *) NULL)
1658 break;
1659 *image=DestroyImage(*image);
1660 *image=flip_image;
1661 break;
1662 }
1663 if (LocaleCompare("flop",option+1) == 0)
1664 {
1665 Image
1666 *flop_image;
1667
1668 /*
1669 Flop image scanlines.
1670 */
cristy6b3da3a2010-06-20 02:21:46 +00001671 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001672 flop_image=FlopImage(*image,exception);
1673 if (flop_image == (Image *) NULL)
1674 break;
1675 *image=DestroyImage(*image);
1676 *image=flop_image;
1677 break;
1678 }
1679 if (LocaleCompare("floodfill",option+1) == 0)
1680 {
1681 MagickPixelPacket
1682 target;
1683
1684 /*
1685 Floodfill image.
1686 */
cristy6b3da3a2010-06-20 02:21:46 +00001687 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001688 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1689 (void) QueryMagickColor(argv[i+2],&target,exception);
1690 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1691 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1692 InheritException(exception,&(*image)->exception);
1693 break;
1694 }
1695 if (LocaleCompare("font",option+1) == 0)
1696 {
1697 if (*option == '+')
1698 {
1699 if (draw_info->font != (char *) NULL)
1700 draw_info->font=DestroyString(draw_info->font);
1701 break;
1702 }
1703 (void) CloneString(&draw_info->font,argv[i+1]);
1704 break;
1705 }
1706 if (LocaleCompare("format",option+1) == 0)
1707 {
1708 format=argv[i+1];
1709 break;
1710 }
1711 if (LocaleCompare("frame",option+1) == 0)
1712 {
1713 FrameInfo
1714 frame_info;
1715
1716 Image
1717 *frame_image;
1718
1719 /*
1720 Surround image with an ornamental border.
1721 */
cristy6b3da3a2010-06-20 02:21:46 +00001722 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001723 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1724 frame_info.width=geometry.width;
1725 frame_info.height=geometry.height;
1726 if ((flags & HeightValue) == 0)
1727 frame_info.height=geometry.width;
1728 frame_info.outer_bevel=geometry.x;
1729 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001730 frame_info.x=(ssize_t) frame_info.width;
1731 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001732 frame_info.width=(*image)->columns+2*frame_info.width;
1733 frame_info.height=(*image)->rows+2*frame_info.height;
1734 frame_image=FrameImage(*image,&frame_info,exception);
1735 if (frame_image == (Image *) NULL)
1736 break;
1737 *image=DestroyImage(*image);
1738 *image=frame_image;
1739 break;
1740 }
1741 if (LocaleCompare("function",option+1) == 0)
1742 {
1743 char
1744 *arguments,
1745 token[MaxTextExtent];
1746
1747 const char
1748 *p;
1749
1750 double
1751 *parameters;
1752
1753 MagickFunction
1754 function;
1755
cristybb503372010-05-27 20:51:26 +00001756 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001757 x;
1758
cristybb503372010-05-27 20:51:26 +00001759 size_t
cristy3ed852e2009-09-05 21:47:34 +00001760 number_parameters;
1761
1762 /*
1763 Function Modify Image Values
1764 */
cristy6b3da3a2010-06-20 02:21:46 +00001765 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001766 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1767 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001768 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001769 InheritException(exception,&(*image)->exception);
1770 if (arguments == (char *) NULL)
1771 break;
1772 p=(char *) arguments;
1773 for (x=0; *p != '\0'; x++)
1774 {
1775 GetMagickToken(p,&p,token);
1776 if (*token == ',')
1777 GetMagickToken(p,&p,token);
1778 }
cristybb503372010-05-27 20:51:26 +00001779 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001780 parameters=(double *) AcquireQuantumMemory(number_parameters,
1781 sizeof(*parameters));
1782 if (parameters == (double *) NULL)
1783 ThrowWandFatalException(ResourceLimitFatalError,
1784 "MemoryAllocationFailed",(*image)->filename);
1785 (void) ResetMagickMemory(parameters,0,number_parameters*
1786 sizeof(*parameters));
1787 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001788 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001789 {
1790 GetMagickToken(p,&p,token);
1791 if (*token == ',')
1792 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001793 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001794 }
1795 arguments=DestroyString(arguments);
1796 (void) FunctionImageChannel(*image,channel,function,
1797 number_parameters,parameters,exception);
1798 parameters=(double *) RelinquishMagickMemory(parameters);
1799 break;
1800 }
1801 break;
1802 }
1803 case 'g':
1804 {
1805 if (LocaleCompare("gamma",option+1) == 0)
1806 {
1807 /*
1808 Gamma image.
1809 */
cristy6b3da3a2010-06-20 02:21:46 +00001810 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001811 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001812 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001813 else
1814 {
1815 if (strchr(argv[i+1],',') != (char *) NULL)
1816 (void) GammaImage(*image,argv[i+1]);
1817 else
cristya5447be2010-01-11 00:20:51 +00001818 (void) GammaImageChannel(*image,channel,
1819 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001820 InheritException(exception,&(*image)->exception);
1821 }
1822 break;
1823 }
1824 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1825 (LocaleCompare("gaussian",option+1) == 0))
1826 {
1827 Image
1828 *gaussian_image;
1829
1830 /*
1831 Gaussian blur image.
1832 */
cristy6b3da3a2010-06-20 02:21:46 +00001833 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001834 flags=ParseGeometry(argv[i+1],&geometry_info);
1835 if ((flags & SigmaValue) == 0)
1836 geometry_info.sigma=1.0;
1837 gaussian_image=GaussianBlurImageChannel(*image,channel,
1838 geometry_info.rho,geometry_info.sigma,exception);
1839 if (gaussian_image == (Image *) NULL)
1840 break;
1841 *image=DestroyImage(*image);
1842 *image=gaussian_image;
1843 break;
1844 }
1845 if (LocaleCompare("geometry",option+1) == 0)
1846 {
cristy6b3da3a2010-06-20 02:21:46 +00001847 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001848 if (*option == '+')
1849 {
1850 if ((*image)->geometry != (char *) NULL)
1851 (*image)->geometry=DestroyString((*image)->geometry);
1852 break;
1853 }
1854 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1855 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1856 (void) CloneString(&(*image)->geometry,argv[i+1]);
1857 else
1858 {
1859 Image
cristy15b98cd2010-09-12 19:42:50 +00001860 *resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001861
1862 /*
1863 Resize image.
1864 */
cristy15b98cd2010-09-12 19:42:50 +00001865 resize_image=ResizeImage(*image,geometry.width,geometry.height,
1866 (*image)->filter,(*image)->blur,exception);
1867 if (resize_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001868 break;
1869 *image=DestroyImage(*image);
cristy15b98cd2010-09-12 19:42:50 +00001870 *image=resize_image;
cristy3ed852e2009-09-05 21:47:34 +00001871 }
1872 break;
1873 }
1874 if (LocaleCompare("gravity",option+1) == 0)
1875 {
1876 if (*option == '+')
1877 {
1878 draw_info->gravity=UndefinedGravity;
1879 break;
1880 }
1881 draw_info->gravity=(GravityType) ParseMagickOption(
1882 MagickGravityOptions,MagickFalse,argv[i+1]);
1883 break;
1884 }
1885 break;
1886 }
1887 case 'h':
1888 {
1889 if (LocaleCompare("highlight-color",option+1) == 0)
1890 {
1891 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1892 break;
1893 }
1894 break;
1895 }
1896 case 'i':
1897 {
1898 if (LocaleCompare("identify",option+1) == 0)
1899 {
1900 char
1901 *text;
1902
cristy6b3da3a2010-06-20 02:21:46 +00001903 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001904 if (format == (char *) NULL)
1905 {
cristy6b3da3a2010-06-20 02:21:46 +00001906 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001907 InheritException(exception,&(*image)->exception);
1908 break;
1909 }
cristy6b3da3a2010-06-20 02:21:46 +00001910 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001911 InheritException(exception,&(*image)->exception);
1912 if (text == (char *) NULL)
1913 break;
1914 (void) fputs(text,stdout);
1915 (void) fputc('\n',stdout);
1916 text=DestroyString(text);
1917 break;
1918 }
1919 if (LocaleCompare("implode",option+1) == 0)
1920 {
1921 Image
1922 *implode_image;
1923
1924 /*
1925 Implode image.
1926 */
cristy6b3da3a2010-06-20 02:21:46 +00001927 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001928 (void) ParseGeometry(argv[i+1],&geometry_info);
1929 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1930 if (implode_image == (Image *) NULL)
1931 break;
1932 *image=DestroyImage(*image);
1933 *image=implode_image;
1934 break;
1935 }
cristyb32b90a2009-09-07 21:45:48 +00001936 if (LocaleCompare("interline-spacing",option+1) == 0)
1937 {
1938 if (*option == '+')
1939 (void) ParseGeometry("0",&geometry_info);
1940 else
1941 (void) ParseGeometry(argv[i+1],&geometry_info);
1942 draw_info->interline_spacing=geometry_info.rho;
1943 break;
1944 }
cristy3ed852e2009-09-05 21:47:34 +00001945 if (LocaleCompare("interword-spacing",option+1) == 0)
1946 {
1947 if (*option == '+')
1948 (void) ParseGeometry("0",&geometry_info);
1949 else
1950 (void) ParseGeometry(argv[i+1],&geometry_info);
1951 draw_info->interword_spacing=geometry_info.rho;
1952 break;
1953 }
1954 break;
1955 }
1956 case 'k':
1957 {
1958 if (LocaleCompare("kerning",option+1) == 0)
1959 {
1960 if (*option == '+')
1961 (void) ParseGeometry("0",&geometry_info);
1962 else
1963 (void) ParseGeometry(argv[i+1],&geometry_info);
1964 draw_info->kerning=geometry_info.rho;
1965 break;
1966 }
1967 break;
1968 }
1969 case 'l':
1970 {
1971 if (LocaleCompare("lat",option+1) == 0)
1972 {
1973 Image
1974 *threshold_image;
1975
1976 /*
1977 Local adaptive threshold image.
1978 */
cristy6b3da3a2010-06-20 02:21:46 +00001979 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001980 flags=ParseGeometry(argv[i+1],&geometry_info);
1981 if ((flags & PercentValue) != 0)
1982 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristybb503372010-05-27 20:51:26 +00001983 threshold_image=AdaptiveThresholdImage(*image,(size_t)
1984 geometry_info.rho,(size_t) geometry_info.sigma,
1985 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001986 if (threshold_image == (Image *) NULL)
1987 break;
1988 *image=DestroyImage(*image);
1989 *image=threshold_image;
1990 break;
1991 }
1992 if (LocaleCompare("level",option+1) == 0)
1993 {
cristy3ed852e2009-09-05 21:47:34 +00001994 MagickRealType
1995 black_point,
1996 gamma,
1997 white_point;
1998
1999 MagickStatusType
2000 flags;
2001
2002 /*
2003 Parse levels.
2004 */
cristy6b3da3a2010-06-20 02:21:46 +00002005 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002006 flags=ParseGeometry(argv[i+1],&geometry_info);
2007 black_point=geometry_info.rho;
2008 white_point=(MagickRealType) QuantumRange;
2009 if ((flags & SigmaValue) != 0)
2010 white_point=geometry_info.sigma;
2011 gamma=1.0;
2012 if ((flags & XiValue) != 0)
2013 gamma=geometry_info.xi;
2014 if ((flags & PercentValue) != 0)
2015 {
2016 black_point*=(MagickRealType) (QuantumRange/100.0);
2017 white_point*=(MagickRealType) (QuantumRange/100.0);
2018 }
2019 if ((flags & SigmaValue) == 0)
2020 white_point=(MagickRealType) QuantumRange-black_point;
2021 if ((*option == '+') || ((flags & AspectValue) != 0))
2022 (void) LevelizeImageChannel(*image,channel,black_point,
2023 white_point,gamma);
2024 else
2025 (void) LevelImageChannel(*image,channel,black_point,white_point,
2026 gamma);
2027 InheritException(exception,&(*image)->exception);
2028 break;
2029 }
2030 if (LocaleCompare("level-colors",option+1) == 0)
2031 {
2032 char
2033 token[MaxTextExtent];
2034
2035 const char
2036 *p;
2037
2038 MagickPixelPacket
2039 black_point,
2040 white_point;
2041
2042 p=(const char *) argv[i+1];
2043 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002044 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002045 (void) QueryMagickColor(token,&black_point,exception);
2046 else
cristyee0f8d72009-09-19 00:58:29 +00002047 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002048 if (isalpha((int) token[0]) || (token[0] == '#'))
2049 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002050 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002051 white_point=black_point; /* set everything to that color */
2052 else
2053 {
2054 /*
2055 Get white point color.
2056 */
cristyee0f8d72009-09-19 00:58:29 +00002057 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002058 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002059 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002060 (void) QueryMagickColor(token,&white_point,exception);
2061 else
cristyee0f8d72009-09-19 00:58:29 +00002062 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002063 }
cristy74fe8f12009-10-03 19:09:01 +00002064 (void) LevelColorsImageChannel(*image,channel,&black_point,
2065 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002066 break;
2067 }
2068 if (LocaleCompare("linear-stretch",option+1) == 0)
2069 {
2070 double
2071 black_point,
2072 white_point;
2073
cristy3ed852e2009-09-05 21:47:34 +00002074 MagickStatusType
2075 flags;
2076
cristy6b3da3a2010-06-20 02:21:46 +00002077 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002078 flags=ParseGeometry(argv[i+1],&geometry_info);
2079 black_point=geometry_info.rho;
2080 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2081 if ((flags & SigmaValue) != 0)
2082 white_point=geometry_info.sigma;
2083 if ((flags & PercentValue) != 0)
2084 {
2085 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2086 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2087 }
2088 if ((flags & SigmaValue) == 0)
2089 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2090 black_point;
2091 (void) LinearStretchImage(*image,black_point,white_point);
2092 InheritException(exception,&(*image)->exception);
2093 break;
2094 }
2095 if (LocaleCompare("linewidth",option+1) == 0)
2096 {
cristyf2f27272009-12-17 14:48:46 +00002097 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002098 break;
2099 }
2100 if (LocaleCompare("liquid-rescale",option+1) == 0)
2101 {
2102 Image
2103 *resize_image;
2104
2105 /*
2106 Liquid rescale image.
2107 */
cristy6b3da3a2010-06-20 02:21:46 +00002108 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002109 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2110 if ((flags & XValue) == 0)
2111 geometry.x=1;
2112 if ((flags & YValue) == 0)
2113 geometry.y=0;
2114 resize_image=LiquidRescaleImage(*image,geometry.width,
2115 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2116 if (resize_image == (Image *) NULL)
2117 break;
2118 *image=DestroyImage(*image);
2119 *image=resize_image;
2120 break;
2121 }
2122 if (LocaleCompare("lowlight-color",option+1) == 0)
2123 {
2124 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2125 break;
2126 }
2127 break;
2128 }
2129 case 'm':
2130 {
2131 if (LocaleCompare("map",option+1) == 0)
2132 {
2133 Image
2134 *remap_image;
2135
2136 /*
2137 Transform image colors to match this set of colors.
2138 */
cristy6b3da3a2010-06-20 02:21:46 +00002139 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002140 if (*option == '+')
2141 break;
cristy6b3da3a2010-06-20 02:21:46 +00002142 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002143 if (remap_image == (Image *) NULL)
2144 break;
2145 (void) RemapImage(quantize_info,*image,remap_image);
2146 InheritException(exception,&(*image)->exception);
2147 remap_image=DestroyImage(remap_image);
2148 break;
2149 }
2150 if (LocaleCompare("mask",option+1) == 0)
2151 {
2152 Image
2153 *mask;
2154
cristy6b3da3a2010-06-20 02:21:46 +00002155 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002156 if (*option == '+')
2157 {
2158 /*
2159 Remove a mask.
2160 */
2161 (void) SetImageMask(*image,(Image *) NULL);
2162 InheritException(exception,&(*image)->exception);
2163 break;
2164 }
2165 /*
2166 Set the image mask.
2167 */
cristy6b3da3a2010-06-20 02:21:46 +00002168 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002169 if (mask == (Image *) NULL)
2170 break;
2171 (void) SetImageMask(*image,mask);
2172 mask=DestroyImage(mask);
2173 InheritException(exception,&(*image)->exception);
2174 break;
2175 }
2176 if (LocaleCompare("matte",option+1) == 0)
2177 {
2178 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2179 SetAlphaChannel : DeactivateAlphaChannel );
2180 InheritException(exception,&(*image)->exception);
2181 break;
2182 }
2183 if (LocaleCompare("median",option+1) == 0)
2184 {
2185 Image
2186 *median_image;
2187
2188 /*
2189 Median filter image.
2190 */
cristy6b3da3a2010-06-20 02:21:46 +00002191 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002192 (void) ParseGeometry(argv[i+1],&geometry_info);
2193 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2194 if (median_image == (Image *) NULL)
2195 break;
2196 *image=DestroyImage(*image);
2197 *image=median_image;
2198 break;
2199 }
2200 if (LocaleCompare("modulate",option+1) == 0)
2201 {
cristy6b3da3a2010-06-20 02:21:46 +00002202 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002203 (void) ModulateImage(*image,argv[i+1]);
2204 InheritException(exception,&(*image)->exception);
2205 break;
2206 }
2207 if (LocaleCompare("monitor",option+1) == 0)
2208 {
cristy7d34ef22010-03-25 01:11:22 +00002209 if (*option == '+')
2210 {
2211 (void) SetImageProgressMonitor(*image,
2212 (MagickProgressMonitor) NULL,(void *) NULL);
2213 break;
2214 }
cristy3ed852e2009-09-05 21:47:34 +00002215 (void) SetImageProgressMonitor(*image,MonitorProgress,
2216 (void *) NULL);
2217 break;
2218 }
2219 if (LocaleCompare("monochrome",option+1) == 0)
2220 {
cristy6b3da3a2010-06-20 02:21:46 +00002221 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002222 (void) SetImageType(*image,BilevelType);
2223 InheritException(exception,&(*image)->exception);
2224 break;
2225 }
anthony29188a82010-01-22 10:12:34 +00002226 if (LocaleCompare("morphology",option+1) == 0)
2227 {
anthony29188a82010-01-22 10:12:34 +00002228 char
2229 token[MaxTextExtent];
2230
2231 const char
2232 *p;
2233
cristye96405a2010-05-19 02:24:31 +00002234 Image
2235 *morphology_image;
2236
2237 KernelInfo
2238 *kernel;
2239
cristybb503372010-05-27 20:51:26 +00002240 ssize_t
anthony29188a82010-01-22 10:12:34 +00002241 iterations;
2242
cristye96405a2010-05-19 02:24:31 +00002243 MorphologyMethod
2244 method;
2245
anthony29188a82010-01-22 10:12:34 +00002246 /*
2247 Morphological Image Operation
2248 */
cristy6b3da3a2010-06-20 02:21:46 +00002249 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002250 p=argv[i+1];
2251 GetMagickToken(p,&p,token);
2252 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002253 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002254 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002255 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002256 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002257 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002258 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002259 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002260 kernel=AcquireKernelInfo(argv[i+2]);
2261 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002262 {
2263 (void) ThrowMagickException(exception,GetMagickModule(),
2264 OptionError,"UnabletoParseKernel","morphology");
2265 status=MagickFalse;
2266 break;
2267 }
anthony29188a82010-01-22 10:12:34 +00002268 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002269 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002270 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002271 if (morphology_image == (Image *) NULL)
2272 break;
2273 *image=DestroyImage(*image);
2274 *image=morphology_image;
2275 break;
2276 }
cristy3ed852e2009-09-05 21:47:34 +00002277 if (LocaleCompare("motion-blur",option+1) == 0)
2278 {
2279 Image
2280 *blur_image;
2281
2282 /*
2283 Motion blur image.
2284 */
cristy6b3da3a2010-06-20 02:21:46 +00002285 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002286 flags=ParseGeometry(argv[i+1],&geometry_info);
2287 if ((flags & SigmaValue) == 0)
2288 geometry_info.sigma=1.0;
2289 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2290 geometry_info.sigma,geometry_info.xi,exception);
2291 if (blur_image == (Image *) NULL)
2292 break;
2293 *image=DestroyImage(*image);
2294 *image=blur_image;
2295 break;
2296 }
2297 break;
2298 }
2299 case 'n':
2300 {
2301 if (LocaleCompare("negate",option+1) == 0)
2302 {
cristy6b3da3a2010-06-20 02:21:46 +00002303 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002304 (void) NegateImageChannel(*image,channel,*option == '+' ?
2305 MagickTrue : MagickFalse);
2306 InheritException(exception,&(*image)->exception);
2307 break;
2308 }
2309 if (LocaleCompare("noise",option+1) == 0)
2310 {
2311 Image
2312 *noisy_image;
2313
cristy6b3da3a2010-06-20 02:21:46 +00002314 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002315 if (*option == '-')
2316 {
2317 (void) ParseGeometry(argv[i+1],&geometry_info);
2318 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2319 exception);
2320 }
2321 else
2322 {
2323 NoiseType
2324 noise;
2325
2326 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2327 MagickFalse,argv[i+1]);
2328 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2329 exception);
2330 }
2331 if (noisy_image == (Image *) NULL)
2332 break;
2333 *image=DestroyImage(*image);
2334 *image=noisy_image;
2335 break;
2336 }
2337 if (LocaleCompare("normalize",option+1) == 0)
2338 {
cristy6b3da3a2010-06-20 02:21:46 +00002339 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002340 (void) NormalizeImageChannel(*image,channel);
2341 InheritException(exception,&(*image)->exception);
2342 break;
2343 }
2344 break;
2345 }
2346 case 'o':
2347 {
2348 if (LocaleCompare("opaque",option+1) == 0)
2349 {
2350 MagickPixelPacket
2351 target;
2352
cristy6b3da3a2010-06-20 02:21:46 +00002353 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002354 (void) QueryMagickColor(argv[i+1],&target,exception);
2355 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2356 *option == '-' ? MagickFalse : MagickTrue);
2357 break;
2358 }
2359 if (LocaleCompare("ordered-dither",option+1) == 0)
2360 {
cristy6b3da3a2010-06-20 02:21:46 +00002361 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002362 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2363 exception);
2364 break;
2365 }
2366 break;
2367 }
2368 case 'p':
2369 {
2370 if (LocaleCompare("paint",option+1) == 0)
2371 {
2372 Image
2373 *paint_image;
2374
2375 /*
2376 Oil paint image.
2377 */
cristy6b3da3a2010-06-20 02:21:46 +00002378 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002379 (void) ParseGeometry(argv[i+1],&geometry_info);
2380 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2381 if (paint_image == (Image *) NULL)
2382 break;
2383 *image=DestroyImage(*image);
2384 *image=paint_image;
2385 break;
2386 }
2387 if (LocaleCompare("pen",option+1) == 0)
2388 {
2389 if (*option == '+')
2390 {
2391 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2392 break;
2393 }
2394 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2395 break;
2396 }
2397 if (LocaleCompare("pointsize",option+1) == 0)
2398 {
2399 if (*option == '+')
2400 (void) ParseGeometry("12",&geometry_info);
2401 else
2402 (void) ParseGeometry(argv[i+1],&geometry_info);
2403 draw_info->pointsize=geometry_info.rho;
2404 break;
2405 }
2406 if (LocaleCompare("polaroid",option+1) == 0)
2407 {
2408 double
2409 angle;
2410
2411 Image
2412 *polaroid_image;
2413
2414 RandomInfo
2415 *random_info;
2416
2417 /*
2418 Simulate a Polaroid picture.
2419 */
cristy6b3da3a2010-06-20 02:21:46 +00002420 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002421 random_info=AcquireRandomInfo();
2422 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2423 random_info=DestroyRandomInfo(random_info);
2424 if (*option == '-')
2425 {
2426 SetGeometryInfo(&geometry_info);
2427 flags=ParseGeometry(argv[i+1],&geometry_info);
2428 angle=geometry_info.rho;
2429 }
2430 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2431 if (polaroid_image == (Image *) NULL)
2432 break;
2433 *image=DestroyImage(*image);
2434 *image=polaroid_image;
2435 break;
2436 }
2437 if (LocaleCompare("posterize",option+1) == 0)
2438 {
2439 /*
2440 Posterize image.
2441 */
cristy6b3da3a2010-06-20 02:21:46 +00002442 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002443 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002444 quantize_info->dither);
2445 InheritException(exception,&(*image)->exception);
2446 break;
2447 }
2448 if (LocaleCompare("preview",option+1) == 0)
2449 {
2450 Image
2451 *preview_image;
2452
2453 PreviewType
2454 preview_type;
2455
2456 /*
2457 Preview image.
2458 */
cristy6b3da3a2010-06-20 02:21:46 +00002459 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002460 if (*option == '+')
2461 preview_type=UndefinedPreview;
2462 else
2463 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2464 MagickFalse,argv[i+1]);
2465 preview_image=PreviewImage(*image,preview_type,exception);
2466 if (preview_image == (Image *) NULL)
2467 break;
2468 *image=DestroyImage(*image);
2469 *image=preview_image;
2470 break;
2471 }
2472 if (LocaleCompare("profile",option+1) == 0)
2473 {
2474 const char
2475 *name;
2476
2477 const StringInfo
2478 *profile;
2479
2480 Image
2481 *profile_image;
2482
2483 ImageInfo
2484 *profile_info;
2485
cristy6b3da3a2010-06-20 02:21:46 +00002486 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002487 if (*option == '+')
2488 {
2489 /*
2490 Remove a profile from the image.
2491 */
2492 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2493 NULL,0,MagickTrue);
2494 InheritException(exception,&(*image)->exception);
2495 break;
2496 }
2497 /*
2498 Associate a profile with the image.
2499 */
cristy6b3da3a2010-06-20 02:21:46 +00002500 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002501 profile=GetImageProfile(*image,"iptc");
2502 if (profile != (StringInfo *) NULL)
2503 profile_info->profile=(void *) CloneStringInfo(profile);
2504 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2505 profile_info=DestroyImageInfo(profile_info);
2506 if (profile_image == (Image *) NULL)
2507 {
cristy3ed852e2009-09-05 21:47:34 +00002508 StringInfo
2509 *profile;
2510
cristy6b3da3a2010-06-20 02:21:46 +00002511 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002512 (void) CopyMagickString(profile_info->filename,argv[i+1],
2513 MaxTextExtent);
2514 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002515 if (profile != (StringInfo *) NULL)
2516 {
cristy071dd7b2010-04-09 13:04:54 +00002517 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002518 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002519 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002520 profile=DestroyStringInfo(profile);
2521 }
cristy071dd7b2010-04-09 13:04:54 +00002522 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002523 break;
2524 }
2525 ResetImageProfileIterator(profile_image);
2526 name=GetNextImageProfile(profile_image);
2527 while (name != (const char *) NULL)
2528 {
2529 profile=GetImageProfile(profile_image,name);
2530 if (profile != (StringInfo *) NULL)
2531 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002532 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002533 name=GetNextImageProfile(profile_image);
2534 }
2535 profile_image=DestroyImage(profile_image);
2536 break;
2537 }
2538 break;
2539 }
2540 case 'q':
2541 {
2542 if (LocaleCompare("quantize",option+1) == 0)
2543 {
2544 if (*option == '+')
2545 {
2546 quantize_info->colorspace=UndefinedColorspace;
2547 break;
2548 }
2549 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2550 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2551 break;
2552 }
2553 break;
2554 }
2555 case 'r':
2556 {
2557 if (LocaleCompare("radial-blur",option+1) == 0)
2558 {
2559 Image
2560 *blur_image;
2561
2562 /*
2563 Radial blur image.
2564 */
cristy6b3da3a2010-06-20 02:21:46 +00002565 (void) SyncImageSettings(mogrify_info,*image);
cristya5447be2010-01-11 00:20:51 +00002566 blur_image=RadialBlurImageChannel(*image,channel,
2567 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002568 if (blur_image == (Image *) NULL)
2569 break;
2570 *image=DestroyImage(*image);
2571 *image=blur_image;
2572 break;
2573 }
2574 if (LocaleCompare("raise",option+1) == 0)
2575 {
2576 /*
2577 Surround image with a raise of solid color.
2578 */
2579 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2580 if ((flags & SigmaValue) == 0)
2581 geometry.height=geometry.width;
2582 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2583 MagickFalse);
2584 InheritException(exception,&(*image)->exception);
2585 break;
2586 }
2587 if (LocaleCompare("random-threshold",option+1) == 0)
2588 {
2589 /*
2590 Threshold image.
2591 */
cristy6b3da3a2010-06-20 02:21:46 +00002592 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002593 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2594 exception);
2595 break;
2596 }
2597 if (LocaleCompare("recolor",option+1) == 0)
2598 {
cristy3ed852e2009-09-05 21:47:34 +00002599 Image
cristyf055ae42010-04-02 23:01:38 +00002600 *color_image;
cristy3ed852e2009-09-05 21:47:34 +00002601
cristyf055ae42010-04-02 23:01:38 +00002602 KernelInfo
2603 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002604
cristy6b3da3a2010-06-20 02:21:46 +00002605 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002606 kernel=AcquireKernelInfo(argv[i+1]);
2607 if (kernel == (KernelInfo *) NULL)
2608 break;
2609 color_image=ColorMatrixImage(*image,kernel,exception);
2610 kernel=DestroyKernelInfo(kernel);
2611 if (color_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002612 break;
2613 *image=DestroyImage(*image);
cristyf055ae42010-04-02 23:01:38 +00002614 *image=color_image;
cristy3ed852e2009-09-05 21:47:34 +00002615 break;
2616 }
2617 if (LocaleCompare("region",option+1) == 0)
2618 {
2619 Image
2620 *crop_image;
2621
cristy6b3da3a2010-06-20 02:21:46 +00002622 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002623 if (region_image != (Image *) NULL)
2624 {
2625 /*
2626 Composite region.
2627 */
2628 (void) CompositeImage(region_image,(*image)->matte !=
2629 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2630 region_geometry.x,region_geometry.y);
2631 InheritException(exception,&region_image->exception);
2632 *image=DestroyImage(*image);
2633 *image=region_image;
2634 }
2635 if (*option == '+')
2636 {
2637 if (region_image != (Image *) NULL)
cristyb0a6e432010-10-09 13:26:15 +00002638 region_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002639 break;
2640 }
2641 /*
2642 Apply transformations to a selected region of the image.
2643 */
2644 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2645 exception);
2646 crop_image=CropImage(*image,&region_geometry,exception);
2647 if (crop_image == (Image *) NULL)
2648 break;
2649 region_image=(*image);
2650 *image=crop_image;
2651 break;
2652 }
2653 if (LocaleCompare("render",option+1) == 0)
2654 {
cristy6b3da3a2010-06-20 02:21:46 +00002655 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002656 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2657 break;
2658 }
2659 if (LocaleCompare("remap",option+1) == 0)
2660 {
2661 Image
2662 *remap_image;
2663
2664 /*
2665 Transform image colors to match this set of colors.
2666 */
cristy6b3da3a2010-06-20 02:21:46 +00002667 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002668 if (*option == '+')
2669 break;
cristy6b3da3a2010-06-20 02:21:46 +00002670 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002671 if (remap_image == (Image *) NULL)
2672 break;
2673 (void) RemapImage(quantize_info,*image,remap_image);
2674 InheritException(exception,&(*image)->exception);
2675 remap_image=DestroyImage(remap_image);
2676 break;
2677 }
2678 if (LocaleCompare("repage",option+1) == 0)
2679 {
2680 if (*option == '+')
2681 {
2682 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2683 break;
2684 }
2685 (void) ResetImagePage(*image,argv[i+1]);
2686 InheritException(exception,&(*image)->exception);
2687 break;
2688 }
2689 if (LocaleCompare("resample",option+1) == 0)
2690 {
2691 Image
2692 *resample_image;
2693
2694 /*
2695 Resample image.
2696 */
cristy6b3da3a2010-06-20 02:21:46 +00002697 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002698 flags=ParseGeometry(argv[i+1],&geometry_info);
2699 if ((flags & SigmaValue) == 0)
2700 geometry_info.sigma=geometry_info.rho;
2701 resample_image=ResampleImage(*image,geometry_info.rho,
2702 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2703 if (resample_image == (Image *) NULL)
2704 break;
2705 *image=DestroyImage(*image);
2706 *image=resample_image;
2707 break;
2708 }
2709 if (LocaleCompare("resize",option+1) == 0)
2710 {
2711 Image
2712 *resize_image;
2713
2714 /*
2715 Resize image.
2716 */
cristy6b3da3a2010-06-20 02:21:46 +00002717 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002718 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2719 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2720 (*image)->filter,(*image)->blur,exception);
2721 if (resize_image == (Image *) NULL)
2722 break;
2723 *image=DestroyImage(*image);
2724 *image=resize_image;
2725 break;
2726 }
cristy3ed852e2009-09-05 21:47:34 +00002727 if (LocaleCompare("roll",option+1) == 0)
2728 {
2729 Image
2730 *roll_image;
2731
2732 /*
2733 Roll image.
2734 */
cristy6b3da3a2010-06-20 02:21:46 +00002735 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002736 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2737 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2738 if (roll_image == (Image *) NULL)
2739 break;
2740 *image=DestroyImage(*image);
2741 *image=roll_image;
2742 break;
2743 }
2744 if (LocaleCompare("rotate",option+1) == 0)
2745 {
2746 char
2747 *geometry;
2748
2749 Image
2750 *rotate_image;
2751
2752 /*
2753 Check for conditional image rotation.
2754 */
cristy6b3da3a2010-06-20 02:21:46 +00002755 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002756 if (strchr(argv[i+1],'>') != (char *) NULL)
2757 if ((*image)->columns <= (*image)->rows)
2758 break;
2759 if (strchr(argv[i+1],'<') != (char *) NULL)
2760 if ((*image)->columns >= (*image)->rows)
2761 break;
2762 /*
2763 Rotate image.
2764 */
2765 geometry=ConstantString(argv[i+1]);
2766 (void) SubstituteString(&geometry,">","");
2767 (void) SubstituteString(&geometry,"<","");
2768 (void) ParseGeometry(geometry,&geometry_info);
2769 geometry=DestroyString(geometry);
2770 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2771 if (rotate_image == (Image *) NULL)
2772 break;
2773 *image=DestroyImage(*image);
2774 *image=rotate_image;
2775 break;
2776 }
2777 break;
2778 }
2779 case 's':
2780 {
2781 if (LocaleCompare("sample",option+1) == 0)
2782 {
2783 Image
2784 *sample_image;
2785
2786 /*
2787 Sample image with pixel replication.
2788 */
cristy6b3da3a2010-06-20 02:21:46 +00002789 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002790 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2791 sample_image=SampleImage(*image,geometry.width,geometry.height,
2792 exception);
2793 if (sample_image == (Image *) NULL)
2794 break;
2795 *image=DestroyImage(*image);
2796 *image=sample_image;
2797 break;
2798 }
2799 if (LocaleCompare("scale",option+1) == 0)
2800 {
2801 Image
2802 *scale_image;
2803
2804 /*
2805 Resize image.
2806 */
cristy6b3da3a2010-06-20 02:21:46 +00002807 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002808 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2809 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2810 exception);
2811 if (scale_image == (Image *) NULL)
2812 break;
2813 *image=DestroyImage(*image);
2814 *image=scale_image;
2815 break;
2816 }
2817 if (LocaleCompare("selective-blur",option+1) == 0)
2818 {
2819 Image
2820 *blur_image;
2821
2822 /*
2823 Selectively blur pixels within a contrast threshold.
2824 */
cristy6b3da3a2010-06-20 02:21:46 +00002825 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002826 flags=ParseGeometry(argv[i+1],&geometry_info);
2827 if ((flags & PercentValue) != 0)
2828 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2829 blur_image=SelectiveBlurImageChannel(*image,channel,
2830 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2831 if (blur_image == (Image *) NULL)
2832 break;
2833 *image=DestroyImage(*image);
2834 *image=blur_image;
2835 break;
2836 }
2837 if (LocaleCompare("separate",option+1) == 0)
2838 {
2839 Image
2840 *separate_images;
2841
2842 /*
2843 Break channels into separate images.
2844 */
cristy6b3da3a2010-06-20 02:21:46 +00002845 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002846 separate_images=SeparateImages(*image,channel,exception);
2847 if (separate_images == (Image *) NULL)
2848 break;
2849 *image=DestroyImage(*image);
2850 *image=separate_images;
2851 break;
2852 }
2853 if (LocaleCompare("sepia-tone",option+1) == 0)
2854 {
2855 double
2856 threshold;
2857
2858 Image
2859 *sepia_image;
2860
2861 /*
2862 Sepia-tone image.
2863 */
cristy6b3da3a2010-06-20 02:21:46 +00002864 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002865 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002866 sepia_image=SepiaToneImage(*image,threshold,exception);
2867 if (sepia_image == (Image *) NULL)
2868 break;
2869 *image=DestroyImage(*image);
2870 *image=sepia_image;
2871 break;
2872 }
2873 if (LocaleCompare("segment",option+1) == 0)
2874 {
2875 /*
2876 Segment image.
2877 */
cristy6b3da3a2010-06-20 02:21:46 +00002878 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002879 flags=ParseGeometry(argv[i+1],&geometry_info);
2880 if ((flags & SigmaValue) == 0)
2881 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002882 (void) SegmentImage(*image,(*image)->colorspace,
2883 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002884 InheritException(exception,&(*image)->exception);
2885 break;
2886 }
2887 if (LocaleCompare("set",option+1) == 0)
2888 {
cristy6d9a1292010-05-31 14:17:06 +00002889 char
2890 *value;
2891
cristy3ed852e2009-09-05 21:47:34 +00002892 /*
2893 Set image option.
2894 */
cristy6d9a1292010-05-31 14:17:06 +00002895 if (*option == '+')
2896 {
2897 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2898 (void) DeleteImageRegistry(argv[i+1]+9);
2899 else
2900 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002901 {
cristy6b3da3a2010-06-20 02:21:46 +00002902 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002903 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2904 }
cristy6d9a1292010-05-31 14:17:06 +00002905 else
2906 (void) DeleteImageProperty(*image,argv[i+1]);
2907 break;
2908 }
cristy6b3da3a2010-06-20 02:21:46 +00002909 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002910 if (value == (char *) NULL)
2911 break;
cristy3ed852e2009-09-05 21:47:34 +00002912 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002913 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2914 exception);
cristy3ed852e2009-09-05 21:47:34 +00002915 else
2916 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002917 {
cristy7f02ba12010-09-21 12:39:28 +00002918 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002919 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002920 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2921 }
cristy3ed852e2009-09-05 21:47:34 +00002922 else
cristy6d9a1292010-05-31 14:17:06 +00002923 (void) SetImageProperty(*image,argv[i+1],value);
2924 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002925 break;
2926 }
2927 if (LocaleCompare("shade",option+1) == 0)
2928 {
2929 Image
2930 *shade_image;
2931
2932 /*
2933 Shade image.
2934 */
cristy6b3da3a2010-06-20 02:21:46 +00002935 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002936 flags=ParseGeometry(argv[i+1],&geometry_info);
2937 if ((flags & SigmaValue) == 0)
2938 geometry_info.sigma=1.0;
2939 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2940 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2941 if (shade_image == (Image *) NULL)
2942 break;
2943 *image=DestroyImage(*image);
2944 *image=shade_image;
2945 break;
2946 }
2947 if (LocaleCompare("shadow",option+1) == 0)
2948 {
2949 Image
2950 *shadow_image;
2951
2952 /*
2953 Shadow image.
2954 */
cristy6b3da3a2010-06-20 02:21:46 +00002955 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002956 flags=ParseGeometry(argv[i+1],&geometry_info);
2957 if ((flags & SigmaValue) == 0)
2958 geometry_info.sigma=1.0;
2959 if ((flags & XiValue) == 0)
2960 geometry_info.xi=4.0;
2961 if ((flags & PsiValue) == 0)
2962 geometry_info.psi=4.0;
2963 shadow_image=ShadowImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00002964 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00002965 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002966 if (shadow_image == (Image *) NULL)
2967 break;
2968 *image=DestroyImage(*image);
2969 *image=shadow_image;
2970 break;
2971 }
2972 if (LocaleCompare("sharpen",option+1) == 0)
2973 {
2974 Image
2975 *sharp_image;
2976
2977 /*
2978 Sharpen image.
2979 */
cristy6b3da3a2010-06-20 02:21:46 +00002980 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002981 flags=ParseGeometry(argv[i+1],&geometry_info);
2982 if ((flags & SigmaValue) == 0)
2983 geometry_info.sigma=1.0;
2984 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2985 geometry_info.sigma,exception);
2986 if (sharp_image == (Image *) NULL)
2987 break;
2988 *image=DestroyImage(*image);
2989 *image=sharp_image;
2990 break;
2991 }
2992 if (LocaleCompare("shave",option+1) == 0)
2993 {
2994 Image
2995 *shave_image;
2996
2997 /*
2998 Shave the image edges.
2999 */
cristy6b3da3a2010-06-20 02:21:46 +00003000 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003001 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3002 shave_image=ShaveImage(*image,&geometry,exception);
3003 if (shave_image == (Image *) NULL)
3004 break;
3005 *image=DestroyImage(*image);
3006 *image=shave_image;
3007 break;
3008 }
3009 if (LocaleCompare("shear",option+1) == 0)
3010 {
3011 Image
3012 *shear_image;
3013
3014 /*
3015 Shear image.
3016 */
cristy6b3da3a2010-06-20 02:21:46 +00003017 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003018 flags=ParseGeometry(argv[i+1],&geometry_info);
3019 if ((flags & SigmaValue) == 0)
3020 geometry_info.sigma=geometry_info.rho;
3021 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3022 exception);
3023 if (shear_image == (Image *) NULL)
3024 break;
3025 *image=DestroyImage(*image);
3026 *image=shear_image;
3027 break;
3028 }
3029 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3030 {
3031 /*
3032 Sigmoidal non-linearity contrast control.
3033 */
cristy6b3da3a2010-06-20 02:21:46 +00003034 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003035 flags=ParseGeometry(argv[i+1],&geometry_info);
3036 if ((flags & SigmaValue) == 0)
3037 geometry_info.sigma=(double) QuantumRange/2.0;
3038 if ((flags & PercentValue) != 0)
3039 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3040 100.0;
3041 (void) SigmoidalContrastImageChannel(*image,channel,
3042 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3043 geometry_info.sigma);
3044 InheritException(exception,&(*image)->exception);
3045 break;
3046 }
3047 if (LocaleCompare("sketch",option+1) == 0)
3048 {
3049 Image
3050 *sketch_image;
3051
3052 /*
3053 Sketch image.
3054 */
cristy6b3da3a2010-06-20 02:21:46 +00003055 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003056 flags=ParseGeometry(argv[i+1],&geometry_info);
3057 if ((flags & SigmaValue) == 0)
3058 geometry_info.sigma=1.0;
3059 sketch_image=SketchImage(*image,geometry_info.rho,
3060 geometry_info.sigma,geometry_info.xi,exception);
3061 if (sketch_image == (Image *) NULL)
3062 break;
3063 *image=DestroyImage(*image);
3064 *image=sketch_image;
3065 break;
3066 }
3067 if (LocaleCompare("solarize",option+1) == 0)
3068 {
3069 double
3070 threshold;
3071
cristy6b3da3a2010-06-20 02:21:46 +00003072 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003073 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003074 (void) SolarizeImage(*image,threshold);
3075 InheritException(exception,&(*image)->exception);
3076 break;
3077 }
3078 if (LocaleCompare("sparse-color",option+1) == 0)
3079 {
3080 Image
3081 *sparse_image;
3082
3083 SparseColorMethod
3084 method;
3085
3086 char
3087 *arguments;
3088
3089 /*
3090 Sparse Color Interpolated Gradient
3091 */
cristy6b3da3a2010-06-20 02:21:46 +00003092 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003093 method=(SparseColorMethod) ParseMagickOption(
3094 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00003095 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00003096 InheritException(exception,&(*image)->exception);
3097 if (arguments == (char *) NULL)
3098 break;
3099 sparse_image=SparseColorOption(*image,channel,method,arguments,
3100 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3101 arguments=DestroyString(arguments);
3102 if (sparse_image == (Image *) NULL)
3103 break;
3104 *image=DestroyImage(*image);
3105 *image=sparse_image;
3106 break;
3107 }
3108 if (LocaleCompare("splice",option+1) == 0)
3109 {
3110 Image
3111 *splice_image;
3112
3113 /*
3114 Splice a solid color into the image.
3115 */
cristy6b3da3a2010-06-20 02:21:46 +00003116 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003117 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3118 splice_image=SpliceImage(*image,&geometry,exception);
3119 if (splice_image == (Image *) NULL)
3120 break;
3121 *image=DestroyImage(*image);
3122 *image=splice_image;
3123 break;
3124 }
3125 if (LocaleCompare("spread",option+1) == 0)
3126 {
3127 Image
3128 *spread_image;
3129
3130 /*
3131 Spread an image.
3132 */
cristy6b3da3a2010-06-20 02:21:46 +00003133 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003134 (void) ParseGeometry(argv[i+1],&geometry_info);
3135 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3136 if (spread_image == (Image *) NULL)
3137 break;
3138 *image=DestroyImage(*image);
3139 *image=spread_image;
3140 break;
3141 }
3142 if (LocaleCompare("stretch",option+1) == 0)
3143 {
3144 if (*option == '+')
3145 {
3146 draw_info->stretch=UndefinedStretch;
3147 break;
3148 }
3149 draw_info->stretch=(StretchType) ParseMagickOption(
3150 MagickStretchOptions,MagickFalse,argv[i+1]);
3151 break;
3152 }
3153 if (LocaleCompare("strip",option+1) == 0)
3154 {
3155 /*
3156 Strip image of profiles and comments.
3157 */
cristy6b3da3a2010-06-20 02:21:46 +00003158 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00003159 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00003160 InheritException(exception,&(*image)->exception);
3161 break;
3162 }
3163 if (LocaleCompare("stroke",option+1) == 0)
3164 {
3165 ExceptionInfo
3166 *sans;
3167
3168 if (*option == '+')
3169 {
3170 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3171 if (draw_info->stroke_pattern != (Image *) NULL)
3172 draw_info->stroke_pattern=DestroyImage(
3173 draw_info->stroke_pattern);
3174 break;
3175 }
3176 sans=AcquireExceptionInfo();
3177 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3178 sans=DestroyExceptionInfo(sans);
3179 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00003180 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003181 exception);
3182 break;
3183 }
3184 if (LocaleCompare("strokewidth",option+1) == 0)
3185 {
cristyf2f27272009-12-17 14:48:46 +00003186 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003187 break;
3188 }
3189 if (LocaleCompare("style",option+1) == 0)
3190 {
3191 if (*option == '+')
3192 {
3193 draw_info->style=UndefinedStyle;
3194 break;
3195 }
3196 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3197 MagickFalse,argv[i+1]);
3198 break;
3199 }
3200 if (LocaleCompare("swirl",option+1) == 0)
3201 {
3202 Image
3203 *swirl_image;
3204
3205 /*
3206 Swirl image.
3207 */
cristy6b3da3a2010-06-20 02:21:46 +00003208 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003209 (void) ParseGeometry(argv[i+1],&geometry_info);
3210 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3211 if (swirl_image == (Image *) NULL)
3212 break;
3213 *image=DestroyImage(*image);
3214 *image=swirl_image;
3215 break;
3216 }
3217 break;
3218 }
3219 case 't':
3220 {
3221 if (LocaleCompare("threshold",option+1) == 0)
3222 {
3223 double
3224 threshold;
3225
3226 /*
3227 Threshold image.
3228 */
cristy6b3da3a2010-06-20 02:21:46 +00003229 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003230 if (*option == '+')
3231 threshold=(double) QuantumRange/2.5;
3232 else
cristyf2f27272009-12-17 14:48:46 +00003233 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003234 (void) BilevelImageChannel(*image,channel,threshold);
3235 InheritException(exception,&(*image)->exception);
3236 break;
3237 }
3238 if (LocaleCompare("thumbnail",option+1) == 0)
3239 {
3240 Image
3241 *thumbnail_image;
3242
3243 /*
3244 Thumbnail image.
3245 */
cristy6b3da3a2010-06-20 02:21:46 +00003246 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003247 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3248 thumbnail_image=ThumbnailImage(*image,geometry.width,
3249 geometry.height,exception);
3250 if (thumbnail_image == (Image *) NULL)
3251 break;
3252 *image=DestroyImage(*image);
3253 *image=thumbnail_image;
3254 break;
3255 }
3256 if (LocaleCompare("tile",option+1) == 0)
3257 {
3258 if (*option == '+')
3259 {
3260 if (draw_info->fill_pattern != (Image *) NULL)
3261 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3262 break;
3263 }
cristy6b3da3a2010-06-20 02:21:46 +00003264 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00003265 exception);
3266 break;
3267 }
3268 if (LocaleCompare("tint",option+1) == 0)
3269 {
3270 Image
3271 *tint_image;
3272
3273 /*
3274 Tint the image.
3275 */
cristy6b3da3a2010-06-20 02:21:46 +00003276 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003277 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3278 if (tint_image == (Image *) NULL)
3279 break;
3280 *image=DestroyImage(*image);
3281 *image=tint_image;
3282 break;
3283 }
3284 if (LocaleCompare("transform",option+1) == 0)
3285 {
3286 Image
3287 *transform_image;
3288
3289 /*
3290 Affine transform image.
3291 */
cristy6b3da3a2010-06-20 02:21:46 +00003292 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003293 transform_image=AffineTransformImage(*image,&draw_info->affine,
3294 exception);
3295 if (transform_image == (Image *) NULL)
3296 break;
3297 *image=DestroyImage(*image);
3298 *image=transform_image;
3299 break;
3300 }
3301 if (LocaleCompare("transparent",option+1) == 0)
3302 {
3303 MagickPixelPacket
3304 target;
3305
cristy6b3da3a2010-06-20 02:21:46 +00003306 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003307 (void) QueryMagickColor(argv[i+1],&target,exception);
3308 (void) TransparentPaintImage(*image,&target,(Quantum)
3309 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3310 InheritException(exception,&(*image)->exception);
3311 break;
3312 }
3313 if (LocaleCompare("transpose",option+1) == 0)
3314 {
3315 Image
3316 *transpose_image;
3317
3318 /*
3319 Transpose image scanlines.
3320 */
cristy6b3da3a2010-06-20 02:21:46 +00003321 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003322 transpose_image=TransposeImage(*image,exception);
3323 if (transpose_image == (Image *) NULL)
3324 break;
3325 *image=DestroyImage(*image);
3326 *image=transpose_image;
3327 break;
3328 }
3329 if (LocaleCompare("transverse",option+1) == 0)
3330 {
3331 Image
3332 *transverse_image;
3333
3334 /*
3335 Transverse image scanlines.
3336 */
cristy6b3da3a2010-06-20 02:21:46 +00003337 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003338 transverse_image=TransverseImage(*image,exception);
3339 if (transverse_image == (Image *) NULL)
3340 break;
3341 *image=DestroyImage(*image);
3342 *image=transverse_image;
3343 break;
3344 }
3345 if (LocaleCompare("treedepth",option+1) == 0)
3346 {
cristye27293e2009-12-18 02:53:20 +00003347 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003348 break;
3349 }
3350 if (LocaleCompare("trim",option+1) == 0)
3351 {
3352 Image
3353 *trim_image;
3354
3355 /*
3356 Trim image.
3357 */
cristy6b3da3a2010-06-20 02:21:46 +00003358 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003359 trim_image=TrimImage(*image,exception);
3360 if (trim_image == (Image *) NULL)
3361 break;
3362 *image=DestroyImage(*image);
3363 *image=trim_image;
3364 break;
3365 }
3366 if (LocaleCompare("type",option+1) == 0)
3367 {
3368 ImageType
3369 type;
3370
cristy6b3da3a2010-06-20 02:21:46 +00003371 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003372 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003373 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003374 else
3375 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3376 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003377 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003378 (void) SetImageType(*image,type);
3379 InheritException(exception,&(*image)->exception);
3380 break;
3381 }
3382 break;
3383 }
3384 case 'u':
3385 {
3386 if (LocaleCompare("undercolor",option+1) == 0)
3387 {
3388 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3389 exception);
3390 break;
3391 }
cristy045bd902010-01-30 18:56:24 +00003392 if (LocaleCompare("unique",option+1) == 0)
3393 {
3394 if (*option == '+')
3395 {
cristy83fae872010-04-22 15:04:16 +00003396 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003397 break;
3398 }
cristy83fae872010-04-22 15:04:16 +00003399 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003400 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003401 break;
3402 }
cristy3ed852e2009-09-05 21:47:34 +00003403 if (LocaleCompare("unique-colors",option+1) == 0)
3404 {
3405 Image
3406 *unique_image;
3407
3408 /*
3409 Unique image colors.
3410 */
cristy6b3da3a2010-06-20 02:21:46 +00003411 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003412 unique_image=UniqueImageColors(*image,exception);
3413 if (unique_image == (Image *) NULL)
3414 break;
3415 *image=DestroyImage(*image);
3416 *image=unique_image;
3417 break;
3418 }
3419 if (LocaleCompare("unsharp",option+1) == 0)
3420 {
3421 Image
3422 *unsharp_image;
3423
3424 /*
3425 Unsharp mask image.
3426 */
cristy6b3da3a2010-06-20 02:21:46 +00003427 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003428 flags=ParseGeometry(argv[i+1],&geometry_info);
3429 if ((flags & SigmaValue) == 0)
3430 geometry_info.sigma=1.0;
3431 if ((flags & XiValue) == 0)
3432 geometry_info.xi=1.0;
3433 if ((flags & PsiValue) == 0)
3434 geometry_info.psi=0.05;
3435 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3436 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3437 geometry_info.psi,exception);
3438 if (unsharp_image == (Image *) NULL)
3439 break;
3440 *image=DestroyImage(*image);
3441 *image=unsharp_image;
3442 break;
3443 }
3444 break;
3445 }
3446 case 'v':
3447 {
3448 if (LocaleCompare("verbose",option+1) == 0)
3449 {
3450 (void) SetImageArtifact(*image,option+1,
3451 *option == '+' ? "false" : "true");
3452 break;
3453 }
3454 if (LocaleCompare("vignette",option+1) == 0)
3455 {
3456 Image
3457 *vignette_image;
3458
3459 /*
3460 Vignette image.
3461 */
cristy6b3da3a2010-06-20 02:21:46 +00003462 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003463 flags=ParseGeometry(argv[i+1],&geometry_info);
3464 if ((flags & SigmaValue) == 0)
3465 geometry_info.sigma=1.0;
3466 if ((flags & XiValue) == 0)
3467 geometry_info.xi=0.1*(*image)->columns;
3468 if ((flags & PsiValue) == 0)
3469 geometry_info.psi=0.1*(*image)->rows;
3470 vignette_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003471 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003472 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003473 if (vignette_image == (Image *) NULL)
3474 break;
3475 *image=DestroyImage(*image);
3476 *image=vignette_image;
3477 break;
3478 }
3479 if (LocaleCompare("virtual-pixel",option+1) == 0)
3480 {
3481 if (*option == '+')
3482 {
3483 (void) SetImageVirtualPixelMethod(*image,
3484 UndefinedVirtualPixelMethod);
3485 break;
3486 }
3487 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3488 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3489 argv[i+1]));
3490 break;
3491 }
3492 break;
3493 }
3494 case 'w':
3495 {
3496 if (LocaleCompare("wave",option+1) == 0)
3497 {
3498 Image
3499 *wave_image;
3500
3501 /*
3502 Wave image.
3503 */
cristy6b3da3a2010-06-20 02:21:46 +00003504 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003505 flags=ParseGeometry(argv[i+1],&geometry_info);
3506 if ((flags & SigmaValue) == 0)
3507 geometry_info.sigma=1.0;
3508 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3509 exception);
3510 if (wave_image == (Image *) NULL)
3511 break;
3512 *image=DestroyImage(*image);
3513 *image=wave_image;
3514 break;
3515 }
3516 if (LocaleCompare("weight",option+1) == 0)
3517 {
cristye27293e2009-12-18 02:53:20 +00003518 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003519 if (LocaleCompare(argv[i+1],"all") == 0)
3520 draw_info->weight=0;
3521 if (LocaleCompare(argv[i+1],"bold") == 0)
3522 draw_info->weight=700;
3523 if (LocaleCompare(argv[i+1],"bolder") == 0)
3524 if (draw_info->weight <= 800)
3525 draw_info->weight+=100;
3526 if (LocaleCompare(argv[i+1],"lighter") == 0)
3527 if (draw_info->weight >= 100)
3528 draw_info->weight-=100;
3529 if (LocaleCompare(argv[i+1],"normal") == 0)
3530 draw_info->weight=400;
3531 break;
3532 }
3533 if (LocaleCompare("white-threshold",option+1) == 0)
3534 {
3535 /*
3536 White threshold image.
3537 */
cristy6b3da3a2010-06-20 02:21:46 +00003538 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003539 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3540 exception);
3541 InheritException(exception,&(*image)->exception);
3542 break;
3543 }
3544 break;
3545 }
3546 default:
3547 break;
3548 }
3549 i+=count;
3550 }
3551 if (region_image != (Image *) NULL)
3552 {
3553 /*
3554 Composite transformed region onto image.
3555 */
cristy6b3da3a2010-06-20 02:21:46 +00003556 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003557 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3558 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3559 region_geometry.y);
3560 InheritException(exception,&region_image->exception);
3561 *image=DestroyImage(*image);
3562 *image=region_image;
3563 }
3564 /*
3565 Free resources.
3566 */
3567 quantize_info=DestroyQuantizeInfo(quantize_info);
3568 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003569 mogrify_info=DestroyImageInfo(mogrify_info);
3570 status=(*image)->exception.severity == UndefinedException ? MagickTrue :
3571 MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003572 return(status);
3573}
3574
3575/*
3576%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3577% %
3578% %
3579% %
cristy5063d812010-10-19 16:28:10 +00003580+ 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 +00003581% %
3582% %
3583% %
3584%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3585%
3586% MogrifyImageCommand() transforms an image or a sequence of images. These
3587% transforms include image scaling, image rotation, color reduction, and
3588% others. The transmogrified image overwrites the original image.
3589%
3590% The format of the MogrifyImageCommand method is:
3591%
3592% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3593% const char **argv,char **metadata,ExceptionInfo *exception)
3594%
3595% A description of each parameter follows:
3596%
3597% o image_info: the image info.
3598%
3599% o argc: the number of elements in the argument vector.
3600%
3601% o argv: A text array containing the command line arguments.
3602%
3603% o metadata: any metadata is returned here.
3604%
3605% o exception: return any errors or warnings in this structure.
3606%
3607*/
3608
3609static MagickBooleanType MogrifyUsage(void)
3610{
3611 static const char
3612 *miscellaneous[]=
3613 {
3614 "-debug events display copious debugging information",
3615 "-help print program options",
3616 "-list type print a list of supported option arguments",
3617 "-log format format of debugging information",
3618 "-version print version information",
3619 (char *) NULL
3620 },
3621 *operators[]=
3622 {
3623 "-adaptive-blur geometry",
3624 " adaptively blur pixels; decrease effect near edges",
3625 "-adaptive-resize geometry",
3626 " adaptively resize image using 'mesh' interpolation",
3627 "-adaptive-sharpen geometry",
3628 " adaptively sharpen pixels; increase effect near edges",
3629 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3630 " transparent, extract, background, or shape",
3631 "-annotate geometry text",
3632 " annotate the image with text",
3633 "-auto-gamma automagically adjust gamma level of image",
3634 "-auto-level automagically adjust color levels of image",
3635 "-auto-orient automagically orient (rotate) image",
3636 "-bench iterations measure performance",
3637 "-black-threshold value",
3638 " force all pixels below the threshold into black",
3639 "-blue-shift simulate a scene at nighttime in the moonlight",
3640 "-blur geometry reduce image noise and reduce detail levels",
3641 "-border geometry surround image with a border of color",
3642 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003643 "-brightness-contrast geometry",
3644 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003645 "-cdl filename color correct with a color decision list",
3646 "-charcoal radius simulate a charcoal drawing",
3647 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003648 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003649 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003650 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003651 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003652 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003653 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003654 "-contrast enhance or reduce the image contrast",
3655 "-contrast-stretch geometry",
3656 " improve contrast by `stretching' the intensity range",
3657 "-convolve coefficients",
3658 " apply a convolution kernel to the image",
3659 "-cycle amount cycle the image colormap",
3660 "-decipher filename convert cipher pixels to plain pixels",
3661 "-deskew threshold straighten an image",
3662 "-despeckle reduce the speckles within an image",
3663 "-distort method args",
3664 " distort images according to given method ad args",
3665 "-draw string annotate the image with a graphic primitive",
3666 "-edge radius apply a filter to detect edges in the image",
3667 "-encipher filename convert plain pixels to cipher pixels",
3668 "-emboss radius emboss an image",
3669 "-enhance apply a digital filter to enhance a noisy image",
3670 "-equalize perform histogram equalization to an image",
3671 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003672 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003673 "-extent geometry set the image size",
3674 "-extract geometry extract area from image",
3675 "-fft implements the discrete Fourier transform (DFT)",
3676 "-flip flip image vertically",
3677 "-floodfill geometry color",
3678 " floodfill the image with color",
3679 "-flop flop image horizontally",
3680 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003681 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003682 " apply function over image values",
3683 "-gamma value level of gamma correction",
3684 "-gaussian-blur geometry",
3685 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003686 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003687 "-identify identify the format and characteristics of the image",
3688 "-ift implements the inverse discrete Fourier transform (DFT)",
3689 "-implode amount implode image pixels about the center",
3690 "-lat geometry local adaptive thresholding",
3691 "-layers method optimize, merge, or compare image layers",
3692 "-level value adjust the level of image contrast",
3693 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003694 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003695 "-linear-stretch geometry",
3696 " improve contrast by `stretching with saturation'",
3697 "-liquid-rescale geometry",
3698 " rescale image with seam-carving",
3699 "-median radius apply a median filter to the image",
3700 "-modulate value vary the brightness, saturation, and hue",
3701 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003702 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003703 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003704 "-motion-blur geometry",
3705 " simulate motion blur",
3706 "-negate replace every pixel with its complementary color ",
3707 "-noise radius add or reduce noise in an image",
3708 "-normalize transform image to span the full range of colors",
3709 "-opaque color change this color to the fill color",
3710 "-ordered-dither NxN",
3711 " add a noise pattern to the image with specific",
3712 " amplitudes",
3713 "-paint radius simulate an oil painting",
3714 "-polaroid angle simulate a Polaroid picture",
3715 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003716 "-profile filename add, delete, or apply an image profile",
3717 "-quantize colorspace reduce colors in this colorspace",
3718 "-radial-blur angle radial blur the image",
3719 "-raise value lighten/darken image edges to create a 3-D effect",
3720 "-random-threshold low,high",
3721 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003722 "-region geometry apply options to a portion of the image",
3723 "-render render vector graphics",
3724 "-repage geometry size and location of an image canvas",
3725 "-resample geometry change the resolution of an image",
3726 "-resize geometry resize the image",
3727 "-roll geometry roll an image vertically or horizontally",
3728 "-rotate degrees apply Paeth rotation to the image",
3729 "-sample geometry scale image with pixel sampling",
3730 "-scale geometry scale the image",
3731 "-segment values segment an image",
3732 "-selective-blur geometry",
3733 " selectively blur pixels within a contrast threshold",
3734 "-sepia-tone threshold",
3735 " simulate a sepia-toned photo",
3736 "-set property value set an image property",
3737 "-shade degrees shade the image using a distant light source",
3738 "-shadow geometry simulate an image shadow",
3739 "-sharpen geometry sharpen the image",
3740 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003741 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003742 "-sigmoidal-contrast geometry",
3743 " increase the contrast without saturating highlights or shadows",
3744 "-sketch geometry simulate a pencil sketch",
3745 "-solarize threshold negate all pixels above the threshold level",
3746 "-sparse-color method args",
3747 " fill in a image based on a few color points",
3748 "-splice geometry splice the background color into the image",
3749 "-spread radius displace image pixels by a random amount",
3750 "-strip strip image of all profiles and comments",
3751 "-swirl degrees swirl image pixels about the center",
3752 "-threshold value threshold the image",
3753 "-thumbnail geometry create a thumbnail of the image",
3754 "-tile filename tile image when filling a graphic primitive",
3755 "-tint value tint the image with the fill color",
3756 "-transform affine transform image",
3757 "-transparent color make this color transparent within the image",
3758 "-transpose flip image vertically and rotate 90 degrees",
3759 "-transverse flop image horizontally and rotate 270 degrees",
3760 "-trim trim image edges",
3761 "-type type image type",
3762 "-unique-colors discard all but one of any pixel color",
3763 "-unsharp geometry sharpen the image",
3764 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003765 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003766 "-white-threshold value",
3767 " force all pixels above the threshold into white",
3768 (char *) NULL
3769 },
3770 *sequence_operators[]=
3771 {
cristy4285d782011-02-09 20:12:28 +00003772 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003773 "-clut apply a color lookup table to the image",
3774 "-coalesce merge a sequence of images",
3775 "-combine combine a sequence of images",
3776 "-composite composite image",
3777 "-crop geometry cut out a rectangular region of the image",
3778 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003779 "-evaluate-sequence operator",
3780 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003781 "-flatten flatten a sequence of images",
3782 "-fx expression apply mathematical expression to an image channel(s)",
3783 "-hald-clut apply a Hald color lookup table to the image",
3784 "-morph value morph an image sequence",
3785 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003786 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003787 "-process arguments process the image with a custom image filter",
3788 "-reverse reverse image sequence",
3789 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003790 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003791 "-write filename write images to this file",
3792 (char *) NULL
3793 },
3794 *settings[]=
3795 {
3796 "-adjoin join images into a single multi-image file",
3797 "-affine matrix affine transform matrix",
3798 "-alpha option activate, deactivate, reset, or set the alpha channel",
3799 "-antialias remove pixel-aliasing",
3800 "-authenticate password",
3801 " decipher image with this password",
3802 "-attenuate value lessen (or intensify) when adding noise to an image",
3803 "-background color background color",
3804 "-bias value add bias when convolving an image",
3805 "-black-point-compensation",
3806 " use black point compensation",
3807 "-blue-primary point chromaticity blue primary point",
3808 "-bordercolor color border color",
3809 "-caption string assign a caption to an image",
3810 "-channel type apply option to select image channels",
3811 "-colors value preferred number of colors in the image",
3812 "-colorspace type alternate image colorspace",
3813 "-comment string annotate image with comment",
3814 "-compose operator set image composite operator",
3815 "-compress type type of pixel compression when writing the image",
3816 "-define format:option",
3817 " define one or more image format options",
3818 "-delay value display the next image after pausing",
3819 "-density geometry horizontal and vertical density of the image",
3820 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003821 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003822 "-display server get image or font from this X server",
3823 "-dispose method layer disposal method",
3824 "-dither method apply error diffusion to image",
3825 "-encoding type text encoding type",
3826 "-endian type endianness (MSB or LSB) of the image",
3827 "-family name render text with this font family",
3828 "-fill color color to use when filling a graphic primitive",
3829 "-filter type use this filter when resizing an image",
3830 "-font name render text with this font",
3831 "-format \"string\" output formatted image characteristics",
3832 "-fuzz distance colors within this distance are considered equal",
3833 "-gravity type horizontal and vertical text placement",
3834 "-green-primary point chromaticity green primary point",
3835 "-intent type type of rendering intent when managing the image color",
3836 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003837 "-interline-spacing value",
3838 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003839 "-interpolate method pixel color interpolation method",
3840 "-interword-spacing value",
3841 " set the space between two words",
3842 "-kerning value set the space between two letters",
3843 "-label string assign a label to an image",
3844 "-limit type value pixel cache resource limit",
3845 "-loop iterations add Netscape loop extension to your GIF animation",
3846 "-mask filename associate a mask with the image",
3847 "-mattecolor color frame color",
3848 "-monitor monitor progress",
3849 "-orient type image orientation",
3850 "-page geometry size and location of an image canvas (setting)",
3851 "-ping efficiently determine image attributes",
3852 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003853 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003854 "-preview type image preview type",
3855 "-quality value JPEG/MIFF/PNG compression level",
3856 "-quiet suppress all warning messages",
3857 "-red-primary point chromaticity red primary point",
3858 "-regard-warnings pay attention to warning messages",
3859 "-remap filename transform image colors to match this set of colors",
3860 "-respect-parentheses settings remain in effect until parenthesis boundary",
3861 "-sampling-factor geometry",
3862 " horizontal and vertical sampling factor",
3863 "-scene value image scene number",
3864 "-seed value seed a new sequence of pseudo-random numbers",
3865 "-size geometry width and height of image",
3866 "-stretch type render text with this font stretch",
3867 "-stroke color graphic primitive stroke color",
3868 "-strokewidth value graphic primitive stroke width",
3869 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003870 "-synchronize synchronize image to storage device",
3871 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003872 "-texture filename name of texture to tile onto the image background",
3873 "-tile-offset geometry",
3874 " tile offset",
3875 "-treedepth value color tree depth",
3876 "-transparent-color color",
3877 " transparent color",
3878 "-undercolor color annotation bounding box color",
3879 "-units type the units of image resolution",
3880 "-verbose print detailed information about the image",
3881 "-view FlashPix viewing transforms",
3882 "-virtual-pixel method",
3883 " virtual pixel access method",
3884 "-weight type render text with this font weight",
3885 "-white-point point chromaticity white point",
3886 (char *) NULL
3887 },
3888 *stack_operators[]=
3889 {
3890 "-clone index clone an image",
3891 "-delete index delete the image from the image sequence",
3892 "-insert index insert last image into the image sequence",
3893 "-swap indexes swap two images in the image sequence",
3894 (char *) NULL
3895 };
3896
3897 const char
3898 **p;
3899
cristybb503372010-05-27 20:51:26 +00003900 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003901 (void) printf("Copyright: %s\n",GetMagickCopyright());
3902 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003903 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3904 GetClientName());
3905 (void) printf("\nImage Settings:\n");
3906 for (p=settings; *p != (char *) NULL; p++)
3907 (void) printf(" %s\n",*p);
3908 (void) printf("\nImage Operators:\n");
3909 for (p=operators; *p != (char *) NULL; p++)
3910 (void) printf(" %s\n",*p);
3911 (void) printf("\nImage Sequence Operators:\n");
3912 for (p=sequence_operators; *p != (char *) NULL; p++)
3913 (void) printf(" %s\n",*p);
3914 (void) printf("\nImage Stack Operators:\n");
3915 for (p=stack_operators; *p != (char *) NULL; p++)
3916 (void) printf(" %s\n",*p);
3917 (void) printf("\nMiscellaneous Options:\n");
3918 for (p=miscellaneous; *p != (char *) NULL; p++)
3919 (void) printf(" %s\n",*p);
3920 (void) printf(
3921 "\nBy default, the image format of `file' is determined by its magic\n");
3922 (void) printf(
3923 "number. To specify a particular image format, precede the filename\n");
3924 (void) printf(
3925 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3926 (void) printf(
3927 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3928 (void) printf("'-' for standard input or output.\n");
3929 return(MagickFalse);
3930}
3931
3932WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3933 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3934{
3935#define DestroyMogrify() \
3936{ \
3937 if (format != (char *) NULL) \
3938 format=DestroyString(format); \
3939 if (path != (char *) NULL) \
3940 path=DestroyString(path); \
3941 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003942 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003943 argv[i]=DestroyString(argv[i]); \
3944 argv=(char **) RelinquishMagickMemory(argv); \
3945}
3946#define ThrowMogrifyException(asperity,tag,option) \
3947{ \
3948 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3949 option); \
3950 DestroyMogrify(); \
3951 return(MagickFalse); \
3952}
3953#define ThrowMogrifyInvalidArgumentException(option,argument) \
3954{ \
3955 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3956 "InvalidArgument","`%s': %s",argument,option); \
3957 DestroyMogrify(); \
3958 return(MagickFalse); \
3959}
3960
3961 char
3962 *format,
3963 *option,
3964 *path;
3965
3966 Image
3967 *image;
3968
3969 ImageStack
3970 image_stack[MaxImageStackDepth+1];
3971
cristy3ed852e2009-09-05 21:47:34 +00003972 MagickBooleanType
3973 global_colormap;
3974
3975 MagickBooleanType
3976 fire,
cristyebbcfea2011-02-25 02:43:54 +00003977 pend,
3978 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003979
3980 MagickStatusType
3981 status;
3982
cristyebbcfea2011-02-25 02:43:54 +00003983 register ssize_t
3984 i;
3985
3986 ssize_t
3987 j,
3988 k;
3989
cristy3ed852e2009-09-05 21:47:34 +00003990 /*
3991 Set defaults.
3992 */
3993 assert(image_info != (ImageInfo *) NULL);
3994 assert(image_info->signature == MagickSignature);
3995 if (image_info->debug != MagickFalse)
3996 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3997 assert(exception != (ExceptionInfo *) NULL);
3998 if (argc == 2)
3999 {
4000 option=argv[1];
4001 if ((LocaleCompare("version",option+1) == 0) ||
4002 (LocaleCompare("-version",option+1) == 0))
4003 {
4004 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00004005 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004006 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4007 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004008 return(MagickFalse);
4009 }
4010 }
4011 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004012 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004013 format=(char *) NULL;
4014 path=(char *) NULL;
4015 global_colormap=MagickFalse;
4016 k=0;
4017 j=1;
4018 NewImageStack();
4019 option=(char *) NULL;
4020 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00004021 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004022 status=MagickTrue;
4023 /*
4024 Parse command line.
4025 */
4026 ReadCommandlLine(argc,&argv);
4027 status=ExpandFilenames(&argc,&argv);
4028 if (status == MagickFalse)
4029 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4030 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00004031 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00004032 {
4033 option=argv[i];
4034 if (LocaleCompare(option,"(") == 0)
4035 {
4036 FireImageStack(MagickFalse,MagickTrue,pend);
4037 if (k == MaxImageStackDepth)
4038 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4039 option);
4040 PushImageStack();
4041 continue;
4042 }
4043 if (LocaleCompare(option,")") == 0)
4044 {
4045 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4046 if (k == 0)
4047 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4048 PopImageStack();
4049 continue;
4050 }
4051 if (IsMagickOption(option) == MagickFalse)
4052 {
4053 char
4054 backup_filename[MaxTextExtent],
4055 *filename;
4056
4057 Image
4058 *images;
4059
4060 /*
4061 Option is a file name: begin by reading image from specified file.
4062 */
4063 FireImageStack(MagickFalse,MagickFalse,pend);
4064 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00004065 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00004066 filename=argv[++i];
4067 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4068 images=ReadImages(image_info,exception);
4069 status&=(images != (Image *) NULL) &&
4070 (exception->severity < ErrorException);
4071 if (images == (Image *) NULL)
4072 continue;
cristydaa76602010-06-30 13:05:11 +00004073 if (format != (char *) NULL)
4074 (void) CopyMagickString(images->filename,images->magick_filename,
4075 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00004076 if (path != (char *) NULL)
4077 {
4078 GetPathComponent(option,TailPath,filename);
4079 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4080 path,*DirectorySeparator,filename);
4081 }
4082 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00004083 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00004084 AppendImageStack(images);
4085 FinalizeImageSettings(image_info,image,MagickFalse);
4086 if (global_colormap != MagickFalse)
4087 {
4088 QuantizeInfo
4089 *quantize_info;
4090
4091 quantize_info=AcquireQuantizeInfo(image_info);
4092 (void) RemapImages(quantize_info,images,(Image *) NULL);
4093 quantize_info=DestroyQuantizeInfo(quantize_info);
4094 }
4095 *backup_filename='\0';
4096 if ((LocaleCompare(image->filename,"-") != 0) &&
4097 (IsPathWritable(image->filename) != MagickFalse))
4098 {
cristybb503372010-05-27 20:51:26 +00004099 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004100 i;
4101
4102 /*
4103 Rename image file as backup.
4104 */
4105 (void) CopyMagickString(backup_filename,image->filename,
4106 MaxTextExtent);
4107 for (i=0; i < 6; i++)
4108 {
4109 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4110 if (IsPathAccessible(backup_filename) == MagickFalse)
4111 break;
4112 }
4113 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4114 (rename(image->filename,backup_filename) != 0))
4115 *backup_filename='\0';
4116 }
4117 /*
4118 Write transmogrified image to disk.
4119 */
4120 image_info->synchronize=MagickTrue;
4121 status&=WriteImages(image_info,image,image->filename,exception);
4122 if ((status == MagickFalse) && (*backup_filename != '\0'))
4123 (void) remove(backup_filename);
4124 RemoveAllImageStack();
4125 continue;
4126 }
4127 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4128 switch (*(option+1))
4129 {
4130 case 'a':
4131 {
4132 if (LocaleCompare("adaptive-blur",option+1) == 0)
4133 {
4134 i++;
cristybb503372010-05-27 20:51:26 +00004135 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004136 ThrowMogrifyException(OptionError,"MissingArgument",option);
4137 if (IsGeometry(argv[i]) == MagickFalse)
4138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4139 break;
4140 }
4141 if (LocaleCompare("adaptive-resize",option+1) == 0)
4142 {
4143 i++;
cristybb503372010-05-27 20:51:26 +00004144 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004145 ThrowMogrifyException(OptionError,"MissingArgument",option);
4146 if (IsGeometry(argv[i]) == MagickFalse)
4147 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4148 break;
4149 }
4150 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4151 {
4152 i++;
cristybb503372010-05-27 20:51:26 +00004153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004154 ThrowMogrifyException(OptionError,"MissingArgument",option);
4155 if (IsGeometry(argv[i]) == MagickFalse)
4156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4157 break;
4158 }
4159 if (LocaleCompare("affine",option+1) == 0)
4160 {
4161 if (*option == '+')
4162 break;
4163 i++;
cristybb503372010-05-27 20:51:26 +00004164 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004165 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00004166 break;
4167 }
4168 if (LocaleCompare("alpha",option+1) == 0)
4169 {
cristybb503372010-05-27 20:51:26 +00004170 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004171 type;
4172
4173 if (*option == '+')
4174 break;
4175 i++;
cristybb503372010-05-27 20:51:26 +00004176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004177 ThrowMogrifyException(OptionError,"MissingArgument",option);
4178 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4179 if (type < 0)
4180 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4181 argv[i]);
4182 break;
4183 }
4184 if (LocaleCompare("annotate",option+1) == 0)
4185 {
4186 if (*option == '+')
4187 break;
4188 i++;
cristybb503372010-05-27 20:51:26 +00004189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004190 ThrowMogrifyException(OptionError,"MissingArgument",option);
4191 if (IsGeometry(argv[i]) == MagickFalse)
4192 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00004193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004194 ThrowMogrifyException(OptionError,"MissingArgument",option);
4195 i++;
4196 break;
4197 }
4198 if (LocaleCompare("antialias",option+1) == 0)
4199 break;
4200 if (LocaleCompare("append",option+1) == 0)
4201 break;
4202 if (LocaleCompare("attenuate",option+1) == 0)
4203 {
4204 if (*option == '+')
4205 break;
4206 i++;
cristybb503372010-05-27 20:51:26 +00004207 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004208 ThrowMogrifyException(OptionError,"MissingArgument",option);
4209 if (IsGeometry(argv[i]) == MagickFalse)
4210 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4211 break;
4212 }
4213 if (LocaleCompare("authenticate",option+1) == 0)
4214 {
4215 if (*option == '+')
4216 break;
4217 i++;
cristybb503372010-05-27 20:51:26 +00004218 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004219 ThrowMogrifyException(OptionError,"MissingArgument",option);
4220 break;
4221 }
4222 if (LocaleCompare("auto-gamma",option+1) == 0)
4223 break;
4224 if (LocaleCompare("auto-level",option+1) == 0)
4225 break;
4226 if (LocaleCompare("auto-orient",option+1) == 0)
4227 break;
4228 if (LocaleCompare("average",option+1) == 0)
4229 break;
4230 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4231 }
4232 case 'b':
4233 {
4234 if (LocaleCompare("background",option+1) == 0)
4235 {
4236 if (*option == '+')
4237 break;
4238 i++;
cristybb503372010-05-27 20:51:26 +00004239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004240 ThrowMogrifyException(OptionError,"MissingArgument",option);
4241 break;
4242 }
4243 if (LocaleCompare("bias",option+1) == 0)
4244 {
4245 if (*option == '+')
4246 break;
4247 i++;
cristybb503372010-05-27 20:51:26 +00004248 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004249 ThrowMogrifyException(OptionError,"MissingArgument",option);
4250 if (IsGeometry(argv[i]) == MagickFalse)
4251 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4252 break;
4253 }
4254 if (LocaleCompare("black-point-compensation",option+1) == 0)
4255 break;
4256 if (LocaleCompare("black-threshold",option+1) == 0)
4257 {
4258 if (*option == '+')
4259 break;
4260 i++;
cristybb503372010-05-27 20:51:26 +00004261 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004262 ThrowMogrifyException(OptionError,"MissingArgument",option);
4263 if (IsGeometry(argv[i]) == MagickFalse)
4264 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4265 break;
4266 }
4267 if (LocaleCompare("blue-primary",option+1) == 0)
4268 {
4269 if (*option == '+')
4270 break;
4271 i++;
cristybb503372010-05-27 20:51:26 +00004272 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004273 ThrowMogrifyException(OptionError,"MissingArgument",option);
4274 if (IsGeometry(argv[i]) == MagickFalse)
4275 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4276 break;
4277 }
4278 if (LocaleCompare("blue-shift",option+1) == 0)
4279 {
4280 i++;
cristybb503372010-05-27 20:51:26 +00004281 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004282 ThrowMogrifyException(OptionError,"MissingArgument",option);
4283 if (IsGeometry(argv[i]) == MagickFalse)
4284 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4285 break;
4286 }
4287 if (LocaleCompare("blur",option+1) == 0)
4288 {
4289 i++;
cristybb503372010-05-27 20:51:26 +00004290 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004291 ThrowMogrifyException(OptionError,"MissingArgument",option);
4292 if (IsGeometry(argv[i]) == MagickFalse)
4293 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4294 break;
4295 }
4296 if (LocaleCompare("border",option+1) == 0)
4297 {
4298 if (*option == '+')
4299 break;
4300 i++;
cristybb503372010-05-27 20:51:26 +00004301 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004302 ThrowMogrifyException(OptionError,"MissingArgument",option);
4303 if (IsGeometry(argv[i]) == MagickFalse)
4304 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4305 break;
4306 }
4307 if (LocaleCompare("bordercolor",option+1) == 0)
4308 {
4309 if (*option == '+')
4310 break;
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 break;
4315 }
4316 if (LocaleCompare("box",option+1) == 0)
4317 {
4318 if (*option == '+')
4319 break;
4320 i++;
cristybb503372010-05-27 20:51:26 +00004321 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004322 ThrowMogrifyException(OptionError,"MissingArgument",option);
4323 break;
4324 }
cristya28d6b82010-01-11 20:03:47 +00004325 if (LocaleCompare("brightness-contrast",option+1) == 0)
4326 {
4327 i++;
cristybb503372010-05-27 20:51:26 +00004328 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004329 ThrowMogrifyException(OptionError,"MissingArgument",option);
4330 if (IsGeometry(argv[i]) == MagickFalse)
4331 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4332 break;
4333 }
cristy3ed852e2009-09-05 21:47:34 +00004334 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4335 }
4336 case 'c':
4337 {
4338 if (LocaleCompare("cache",option+1) == 0)
4339 {
4340 if (*option == '+')
4341 break;
4342 i++;
cristybb503372010-05-27 20:51:26 +00004343 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004344 ThrowMogrifyException(OptionError,"MissingArgument",option);
4345 if (IsGeometry(argv[i]) == MagickFalse)
4346 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4347 break;
4348 }
4349 if (LocaleCompare("caption",option+1) == 0)
4350 {
4351 if (*option == '+')
4352 break;
4353 i++;
cristybb503372010-05-27 20:51:26 +00004354 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004355 ThrowMogrifyException(OptionError,"MissingArgument",option);
4356 break;
4357 }
4358 if (LocaleCompare("channel",option+1) == 0)
4359 {
cristybb503372010-05-27 20:51:26 +00004360 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004361 channel;
4362
4363 if (*option == '+')
4364 break;
4365 i++;
cristybb503372010-05-27 20:51:26 +00004366 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004367 ThrowMogrifyException(OptionError,"MissingArgument",option);
4368 channel=ParseChannelOption(argv[i]);
4369 if (channel < 0)
4370 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4371 argv[i]);
4372 break;
4373 }
4374 if (LocaleCompare("cdl",option+1) == 0)
4375 {
4376 if (*option == '+')
4377 break;
4378 i++;
cristybb503372010-05-27 20:51:26 +00004379 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004380 ThrowMogrifyException(OptionError,"MissingArgument",option);
4381 break;
4382 }
4383 if (LocaleCompare("charcoal",option+1) == 0)
4384 {
4385 if (*option == '+')
4386 break;
4387 i++;
cristybb503372010-05-27 20:51:26 +00004388 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004389 ThrowMogrifyException(OptionError,"MissingArgument",option);
4390 if (IsGeometry(argv[i]) == MagickFalse)
4391 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4392 break;
4393 }
4394 if (LocaleCompare("chop",option+1) == 0)
4395 {
4396 if (*option == '+')
4397 break;
4398 i++;
cristybb503372010-05-27 20:51:26 +00004399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004400 ThrowMogrifyException(OptionError,"MissingArgument",option);
4401 if (IsGeometry(argv[i]) == MagickFalse)
4402 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4403 break;
4404 }
cristy1eb45dd2009-09-25 16:38:06 +00004405 if (LocaleCompare("clamp",option+1) == 0)
4406 break;
4407 if (LocaleCompare("clip",option+1) == 0)
4408 break;
cristy3ed852e2009-09-05 21:47:34 +00004409 if (LocaleCompare("clip-mask",option+1) == 0)
4410 {
4411 if (*option == '+')
4412 break;
4413 i++;
cristybb503372010-05-27 20:51:26 +00004414 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004415 ThrowMogrifyException(OptionError,"MissingArgument",option);
4416 break;
4417 }
4418 if (LocaleCompare("clut",option+1) == 0)
4419 break;
4420 if (LocaleCompare("coalesce",option+1) == 0)
4421 break;
4422 if (LocaleCompare("colorize",option+1) == 0)
4423 {
4424 if (*option == '+')
4425 break;
4426 i++;
cristybb503372010-05-27 20:51:26 +00004427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004428 ThrowMogrifyException(OptionError,"MissingArgument",option);
4429 if (IsGeometry(argv[i]) == MagickFalse)
4430 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4431 break;
4432 }
cristye6365592010-04-02 17:31:23 +00004433 if (LocaleCompare("color-matrix",option+1) == 0)
4434 {
cristyb6bd4ad2010-08-08 01:12:27 +00004435 KernelInfo
4436 *kernel_info;
4437
cristye6365592010-04-02 17:31:23 +00004438 if (*option == '+')
4439 break;
4440 i++;
cristybb503372010-05-27 20:51:26 +00004441 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004442 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004443 kernel_info=AcquireKernelInfo(argv[i]);
4444 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004446 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004447 break;
4448 }
cristy3ed852e2009-09-05 21:47:34 +00004449 if (LocaleCompare("colors",option+1) == 0)
4450 {
4451 if (*option == '+')
4452 break;
4453 i++;
cristybb503372010-05-27 20:51:26 +00004454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004455 ThrowMogrifyException(OptionError,"MissingArgument",option);
4456 if (IsGeometry(argv[i]) == MagickFalse)
4457 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4458 break;
4459 }
4460 if (LocaleCompare("colorspace",option+1) == 0)
4461 {
cristybb503372010-05-27 20:51:26 +00004462 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004463 colorspace;
4464
4465 if (*option == '+')
4466 break;
4467 i++;
cristybb503372010-05-27 20:51:26 +00004468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004469 ThrowMogrifyException(OptionError,"MissingArgument",option);
4470 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4471 argv[i]);
4472 if (colorspace < 0)
4473 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4474 argv[i]);
4475 break;
4476 }
4477 if (LocaleCompare("combine",option+1) == 0)
4478 break;
4479 if (LocaleCompare("comment",option+1) == 0)
4480 {
4481 if (*option == '+')
4482 break;
4483 i++;
cristybb503372010-05-27 20:51:26 +00004484 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004485 ThrowMogrifyException(OptionError,"MissingArgument",option);
4486 break;
4487 }
4488 if (LocaleCompare("composite",option+1) == 0)
4489 break;
4490 if (LocaleCompare("compress",option+1) == 0)
4491 {
cristybb503372010-05-27 20:51:26 +00004492 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004493 compress;
4494
4495 if (*option == '+')
4496 break;
4497 i++;
cristybb503372010-05-27 20:51:26 +00004498 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004499 ThrowMogrifyException(OptionError,"MissingArgument",option);
4500 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4501 argv[i]);
4502 if (compress < 0)
4503 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4504 argv[i]);
4505 break;
4506 }
cristy22879752009-10-25 23:55:40 +00004507 if (LocaleCompare("concurrent",option+1) == 0)
4508 break;
cristy3ed852e2009-09-05 21:47:34 +00004509 if (LocaleCompare("contrast",option+1) == 0)
4510 break;
4511 if (LocaleCompare("contrast-stretch",option+1) == 0)
4512 {
4513 i++;
cristybb503372010-05-27 20:51:26 +00004514 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004515 ThrowMogrifyException(OptionError,"MissingArgument",option);
4516 if (IsGeometry(argv[i]) == MagickFalse)
4517 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4518 break;
4519 }
4520 if (LocaleCompare("convolve",option+1) == 0)
4521 {
cristyb6bd4ad2010-08-08 01:12:27 +00004522 KernelInfo
4523 *kernel_info;
4524
cristy3ed852e2009-09-05 21:47:34 +00004525 if (*option == '+')
4526 break;
4527 i++;
cristybb503372010-05-27 20:51:26 +00004528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004529 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004530 kernel_info=AcquireKernelInfo(argv[i]);
4531 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004533 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004534 break;
4535 }
4536 if (LocaleCompare("crop",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 if (IsGeometry(argv[i]) == MagickFalse)
4544 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4545 break;
4546 }
4547 if (LocaleCompare("cycle",option+1) == 0)
4548 {
4549 if (*option == '+')
4550 break;
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 if (IsGeometry(argv[i]) == MagickFalse)
4555 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4556 break;
4557 }
4558 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4559 }
4560 case 'd':
4561 {
4562 if (LocaleCompare("decipher",option+1) == 0)
4563 {
4564 if (*option == '+')
4565 break;
4566 i++;
cristybb503372010-05-27 20:51:26 +00004567 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004568 ThrowMogrifyException(OptionError,"MissingArgument",option);
4569 break;
4570 }
4571 if (LocaleCompare("deconstruct",option+1) == 0)
4572 break;
4573 if (LocaleCompare("debug",option+1) == 0)
4574 {
cristybb503372010-05-27 20:51:26 +00004575 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004576 event;
4577
4578 if (*option == '+')
4579 break;
4580 i++;
cristybb503372010-05-27 20:51:26 +00004581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004582 ThrowMogrifyException(OptionError,"MissingArgument",option);
4583 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4584 if (event < 0)
4585 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4586 argv[i]);
4587 (void) SetLogEventMask(argv[i]);
4588 break;
4589 }
4590 if (LocaleCompare("define",option+1) == 0)
4591 {
4592 i++;
cristybb503372010-05-27 20:51:26 +00004593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004594 ThrowMogrifyException(OptionError,"MissingArgument",option);
4595 if (*option == '+')
4596 {
4597 const char
4598 *define;
4599
4600 define=GetImageOption(image_info,argv[i]);
4601 if (define == (const char *) NULL)
4602 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4603 break;
4604 }
4605 break;
4606 }
4607 if (LocaleCompare("delay",option+1) == 0)
4608 {
4609 if (*option == '+')
4610 break;
4611 i++;
cristybb503372010-05-27 20:51:26 +00004612 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004613 ThrowMogrifyException(OptionError,"MissingArgument",option);
4614 if (IsGeometry(argv[i]) == MagickFalse)
4615 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4616 break;
4617 }
4618 if (LocaleCompare("density",option+1) == 0)
4619 {
4620 if (*option == '+')
4621 break;
4622 i++;
cristybb503372010-05-27 20:51:26 +00004623 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004624 ThrowMogrifyException(OptionError,"MissingArgument",option);
4625 if (IsGeometry(argv[i]) == MagickFalse)
4626 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4627 break;
4628 }
4629 if (LocaleCompare("depth",option+1) == 0)
4630 {
4631 if (*option == '+')
4632 break;
4633 i++;
cristybb503372010-05-27 20:51:26 +00004634 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004635 ThrowMogrifyException(OptionError,"MissingArgument",option);
4636 if (IsGeometry(argv[i]) == MagickFalse)
4637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4638 break;
4639 }
4640 if (LocaleCompare("deskew",option+1) == 0)
4641 {
4642 if (*option == '+')
4643 break;
4644 i++;
cristybb503372010-05-27 20:51:26 +00004645 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004646 ThrowMogrifyException(OptionError,"MissingArgument",option);
4647 if (IsGeometry(argv[i]) == MagickFalse)
4648 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4649 break;
4650 }
4651 if (LocaleCompare("despeckle",option+1) == 0)
4652 break;
4653 if (LocaleCompare("dft",option+1) == 0)
4654 break;
cristyc9b12952010-03-28 01:12:28 +00004655 if (LocaleCompare("direction",option+1) == 0)
4656 {
cristybb503372010-05-27 20:51:26 +00004657 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004658 direction;
4659
4660 if (*option == '+')
4661 break;
4662 i++;
cristybb503372010-05-27 20:51:26 +00004663 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004664 ThrowMogrifyException(OptionError,"MissingArgument",option);
4665 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4666 argv[i]);
4667 if (direction < 0)
4668 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4669 argv[i]);
4670 break;
4671 }
cristy3ed852e2009-09-05 21:47:34 +00004672 if (LocaleCompare("display",option+1) == 0)
4673 {
4674 if (*option == '+')
4675 break;
4676 i++;
cristybb503372010-05-27 20:51:26 +00004677 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004678 ThrowMogrifyException(OptionError,"MissingArgument",option);
4679 break;
4680 }
4681 if (LocaleCompare("dispose",option+1) == 0)
4682 {
cristybb503372010-05-27 20:51:26 +00004683 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004684 dispose;
4685
4686 if (*option == '+')
4687 break;
4688 i++;
cristybb503372010-05-27 20:51:26 +00004689 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004690 ThrowMogrifyException(OptionError,"MissingArgument",option);
4691 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4692 if (dispose < 0)
4693 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4694 argv[i]);
4695 break;
4696 }
4697 if (LocaleCompare("distort",option+1) == 0)
4698 {
cristybb503372010-05-27 20:51:26 +00004699 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004700 op;
4701
4702 i++;
cristybb503372010-05-27 20:51:26 +00004703 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004704 ThrowMogrifyException(OptionError,"MissingArgument",option);
4705 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4706 if (op < 0)
4707 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4708 argv[i]);
4709 i++;
cristybb503372010-05-27 20:51:26 +00004710 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004711 ThrowMogrifyException(OptionError,"MissingArgument",option);
4712 break;
4713 }
4714 if (LocaleCompare("dither",option+1) == 0)
4715 {
cristybb503372010-05-27 20:51:26 +00004716 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004717 method;
4718
4719 if (*option == '+')
4720 break;
4721 i++;
cristybb503372010-05-27 20:51:26 +00004722 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004723 ThrowMogrifyException(OptionError,"MissingArgument",option);
4724 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4725 if (method < 0)
4726 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4727 argv[i]);
4728 break;
4729 }
4730 if (LocaleCompare("draw",option+1) == 0)
4731 {
4732 if (*option == '+')
4733 break;
4734 i++;
cristybb503372010-05-27 20:51:26 +00004735 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004736 ThrowMogrifyException(OptionError,"MissingArgument",option);
4737 break;
4738 }
cristy22879752009-10-25 23:55:40 +00004739 if (LocaleCompare("duration",option+1) == 0)
4740 {
4741 if (*option == '+')
4742 break;
4743 i++;
cristybb503372010-05-27 20:51:26 +00004744 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004745 ThrowMogrifyException(OptionError,"MissingArgument",option);
4746 if (IsGeometry(argv[i]) == MagickFalse)
4747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4748 break;
4749 }
cristy3ed852e2009-09-05 21:47:34 +00004750 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4751 }
4752 case 'e':
4753 {
4754 if (LocaleCompare("edge",option+1) == 0)
4755 {
4756 if (*option == '+')
4757 break;
4758 i++;
cristybb503372010-05-27 20:51:26 +00004759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004760 ThrowMogrifyException(OptionError,"MissingArgument",option);
4761 if (IsGeometry(argv[i]) == MagickFalse)
4762 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4763 break;
4764 }
4765 if (LocaleCompare("emboss",option+1) == 0)
4766 {
4767 if (*option == '+')
4768 break;
4769 i++;
cristybb503372010-05-27 20:51:26 +00004770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004771 ThrowMogrifyException(OptionError,"MissingArgument",option);
4772 if (IsGeometry(argv[i]) == MagickFalse)
4773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4774 break;
4775 }
4776 if (LocaleCompare("encipher",option+1) == 0)
4777 {
4778 if (*option == '+')
4779 break;
4780 i++;
cristybb503372010-05-27 20:51:26 +00004781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004782 ThrowMogrifyException(OptionError,"MissingArgument",option);
4783 break;
4784 }
4785 if (LocaleCompare("encoding",option+1) == 0)
4786 {
4787 if (*option == '+')
4788 break;
4789 i++;
cristybb503372010-05-27 20:51:26 +00004790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004791 ThrowMogrifyException(OptionError,"MissingArgument",option);
4792 break;
4793 }
4794 if (LocaleCompare("endian",option+1) == 0)
4795 {
cristybb503372010-05-27 20:51:26 +00004796 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004797 endian;
4798
4799 if (*option == '+')
4800 break;
4801 i++;
cristybb503372010-05-27 20:51:26 +00004802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004803 ThrowMogrifyException(OptionError,"MissingArgument",option);
4804 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4805 if (endian < 0)
4806 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4807 argv[i]);
4808 break;
4809 }
4810 if (LocaleCompare("enhance",option+1) == 0)
4811 break;
4812 if (LocaleCompare("equalize",option+1) == 0)
4813 break;
4814 if (LocaleCompare("evaluate",option+1) == 0)
4815 {
cristybb503372010-05-27 20:51:26 +00004816 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004817 op;
4818
4819 if (*option == '+')
4820 break;
4821 i++;
cristybb503372010-05-27 20:51:26 +00004822 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004823 ThrowMogrifyException(OptionError,"MissingArgument",option);
4824 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4825 if (op < 0)
4826 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4827 argv[i]);
4828 i++;
cristybb503372010-05-27 20:51:26 +00004829 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004830 ThrowMogrifyException(OptionError,"MissingArgument",option);
4831 if (IsGeometry(argv[i]) == MagickFalse)
4832 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4833 break;
4834 }
cristyd18ae7c2010-03-07 17:39:52 +00004835 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4836 {
cristybb503372010-05-27 20:51:26 +00004837 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004838 op;
4839
4840 if (*option == '+')
4841 break;
4842 i++;
cristybb503372010-05-27 20:51:26 +00004843 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004844 ThrowMogrifyException(OptionError,"MissingArgument",option);
4845 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4846 if (op < 0)
4847 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4848 argv[i]);
4849 break;
4850 }
cristy3ed852e2009-09-05 21:47:34 +00004851 if (LocaleCompare("extent",option+1) == 0)
4852 {
4853 if (*option == '+')
4854 break;
4855 i++;
cristybb503372010-05-27 20:51:26 +00004856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004857 ThrowMogrifyException(OptionError,"MissingArgument",option);
4858 if (IsGeometry(argv[i]) == MagickFalse)
4859 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4860 break;
4861 }
4862 if (LocaleCompare("extract",option+1) == 0)
4863 {
4864 if (*option == '+')
4865 break;
4866 i++;
cristybb503372010-05-27 20:51:26 +00004867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004868 ThrowMogrifyException(OptionError,"MissingArgument",option);
4869 if (IsGeometry(argv[i]) == MagickFalse)
4870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4871 break;
4872 }
4873 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4874 }
4875 case 'f':
4876 {
4877 if (LocaleCompare("family",option+1) == 0)
4878 {
4879 if (*option == '+')
4880 break;
4881 i++;
cristybb503372010-05-27 20:51:26 +00004882 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004883 ThrowMogrifyException(OptionError,"MissingArgument",option);
4884 break;
4885 }
4886 if (LocaleCompare("fill",option+1) == 0)
4887 {
4888 if (*option == '+')
4889 break;
4890 i++;
cristybb503372010-05-27 20:51:26 +00004891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004892 ThrowMogrifyException(OptionError,"MissingArgument",option);
4893 break;
4894 }
4895 if (LocaleCompare("filter",option+1) == 0)
4896 {
cristybb503372010-05-27 20:51:26 +00004897 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004898 filter;
4899
4900 if (*option == '+')
4901 break;
4902 i++;
cristybb503372010-05-27 20:51:26 +00004903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004904 ThrowMogrifyException(OptionError,"MissingArgument",option);
4905 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4906 if (filter < 0)
4907 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4908 argv[i]);
4909 break;
4910 }
4911 if (LocaleCompare("flatten",option+1) == 0)
4912 break;
4913 if (LocaleCompare("flip",option+1) == 0)
4914 break;
4915 if (LocaleCompare("flop",option+1) == 0)
4916 break;
4917 if (LocaleCompare("floodfill",option+1) == 0)
4918 {
4919 if (*option == '+')
4920 break;
4921 i++;
cristybb503372010-05-27 20:51:26 +00004922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004923 ThrowMogrifyException(OptionError,"MissingArgument",option);
4924 if (IsGeometry(argv[i]) == MagickFalse)
4925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4926 i++;
cristybb503372010-05-27 20:51:26 +00004927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004928 ThrowMogrifyException(OptionError,"MissingArgument",option);
4929 break;
4930 }
4931 if (LocaleCompare("font",option+1) == 0)
4932 {
4933 if (*option == '+')
4934 break;
4935 i++;
cristybb503372010-05-27 20:51:26 +00004936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004937 ThrowMogrifyException(OptionError,"MissingArgument",option);
4938 break;
4939 }
4940 if (LocaleCompare("format",option+1) == 0)
4941 {
4942 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4943 (void) CloneString(&format,(char *) NULL);
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);
4949 (void) CloneString(&format,argv[i]);
4950 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4951 (void) ConcatenateMagickString(image_info->filename,":",
4952 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004953 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004954 if (*image_info->magick == '\0')
4955 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4956 format);
4957 break;
4958 }
4959 if (LocaleCompare("frame",option+1) == 0)
4960 {
4961 if (*option == '+')
4962 break;
4963 i++;
cristybb503372010-05-27 20:51:26 +00004964 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004965 ThrowMogrifyException(OptionError,"MissingArgument",option);
4966 if (IsGeometry(argv[i]) == MagickFalse)
4967 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4968 break;
4969 }
4970 if (LocaleCompare("function",option+1) == 0)
4971 {
cristybb503372010-05-27 20:51:26 +00004972 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004973 op;
4974
4975 if (*option == '+')
4976 break;
4977 i++;
cristybb503372010-05-27 20:51:26 +00004978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004979 ThrowMogrifyException(OptionError,"MissingArgument",option);
4980 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4981 if (op < 0)
4982 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4983 i++;
cristybb503372010-05-27 20:51:26 +00004984 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004985 ThrowMogrifyException(OptionError,"MissingArgument",option);
4986 break;
4987 }
4988 if (LocaleCompare("fuzz",option+1) == 0)
4989 {
4990 if (*option == '+')
4991 break;
4992 i++;
cristybb503372010-05-27 20:51:26 +00004993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004994 ThrowMogrifyException(OptionError,"MissingArgument",option);
4995 if (IsGeometry(argv[i]) == MagickFalse)
4996 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4997 break;
4998 }
4999 if (LocaleCompare("fx",option+1) == 0)
5000 {
5001 if (*option == '+')
5002 break;
5003 i++;
cristybb503372010-05-27 20:51:26 +00005004 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005005 ThrowMogrifyException(OptionError,"MissingArgument",option);
5006 break;
5007 }
5008 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5009 }
5010 case 'g':
5011 {
5012 if (LocaleCompare("gamma",option+1) == 0)
5013 {
5014 i++;
cristybb503372010-05-27 20:51:26 +00005015 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005016 ThrowMogrifyException(OptionError,"MissingArgument",option);
5017 if (IsGeometry(argv[i]) == MagickFalse)
5018 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5019 break;
5020 }
5021 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5022 (LocaleCompare("gaussian",option+1) == 0))
5023 {
5024 i++;
cristybb503372010-05-27 20:51:26 +00005025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005026 ThrowMogrifyException(OptionError,"MissingArgument",option);
5027 if (IsGeometry(argv[i]) == MagickFalse)
5028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5029 break;
5030 }
5031 if (LocaleCompare("geometry",option+1) == 0)
5032 {
5033 if (*option == '+')
5034 break;
5035 i++;
cristybb503372010-05-27 20:51:26 +00005036 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005037 ThrowMogrifyException(OptionError,"MissingArgument",option);
5038 if (IsGeometry(argv[i]) == MagickFalse)
5039 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5040 break;
5041 }
5042 if (LocaleCompare("gravity",option+1) == 0)
5043 {
cristybb503372010-05-27 20:51:26 +00005044 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005045 gravity;
5046
5047 if (*option == '+')
5048 break;
5049 i++;
cristybb503372010-05-27 20:51:26 +00005050 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005051 ThrowMogrifyException(OptionError,"MissingArgument",option);
5052 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5053 if (gravity < 0)
5054 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5055 argv[i]);
5056 break;
5057 }
5058 if (LocaleCompare("green-primary",option+1) == 0)
5059 {
5060 if (*option == '+')
5061 break;
5062 i++;
cristybb503372010-05-27 20:51:26 +00005063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005064 ThrowMogrifyException(OptionError,"MissingArgument",option);
5065 if (IsGeometry(argv[i]) == MagickFalse)
5066 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5067 break;
5068 }
5069 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5070 }
5071 case 'h':
5072 {
5073 if (LocaleCompare("hald-clut",option+1) == 0)
5074 break;
5075 if ((LocaleCompare("help",option+1) == 0) ||
5076 (LocaleCompare("-help",option+1) == 0))
5077 return(MogrifyUsage());
5078 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5079 }
5080 case 'i':
5081 {
5082 if (LocaleCompare("identify",option+1) == 0)
5083 break;
5084 if (LocaleCompare("idft",option+1) == 0)
5085 break;
5086 if (LocaleCompare("implode",option+1) == 0)
5087 {
5088 if (*option == '+')
5089 break;
5090 i++;
cristybb503372010-05-27 20:51:26 +00005091 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005092 ThrowMogrifyException(OptionError,"MissingArgument",option);
5093 if (IsGeometry(argv[i]) == MagickFalse)
5094 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5095 break;
5096 }
5097 if (LocaleCompare("intent",option+1) == 0)
5098 {
cristybb503372010-05-27 20:51:26 +00005099 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005100 intent;
5101
5102 if (*option == '+')
5103 break;
5104 i++;
cristybb503372010-05-27 20:51:26 +00005105 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005106 ThrowMogrifyException(OptionError,"MissingArgument",option);
5107 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5108 if (intent < 0)
5109 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5110 argv[i]);
5111 break;
5112 }
5113 if (LocaleCompare("interlace",option+1) == 0)
5114 {
cristybb503372010-05-27 20:51:26 +00005115 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005116 interlace;
5117
5118 if (*option == '+')
5119 break;
5120 i++;
cristybb503372010-05-27 20:51:26 +00005121 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005122 ThrowMogrifyException(OptionError,"MissingArgument",option);
5123 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5124 argv[i]);
5125 if (interlace < 0)
5126 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5127 argv[i]);
5128 break;
5129 }
cristyb32b90a2009-09-07 21:45:48 +00005130 if (LocaleCompare("interline-spacing",option+1) == 0)
5131 {
5132 if (*option == '+')
5133 break;
5134 i++;
cristybb503372010-05-27 20:51:26 +00005135 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00005136 ThrowMogrifyException(OptionError,"MissingArgument",option);
5137 if (IsGeometry(argv[i]) == MagickFalse)
5138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5139 break;
5140 }
cristy3ed852e2009-09-05 21:47:34 +00005141 if (LocaleCompare("interpolate",option+1) == 0)
5142 {
cristybb503372010-05-27 20:51:26 +00005143 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005144 interpolate;
5145
5146 if (*option == '+')
5147 break;
5148 i++;
cristybb503372010-05-27 20:51:26 +00005149 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005150 ThrowMogrifyException(OptionError,"MissingArgument",option);
5151 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5152 argv[i]);
5153 if (interpolate < 0)
5154 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5155 argv[i]);
5156 break;
5157 }
5158 if (LocaleCompare("interword-spacing",option+1) == 0)
5159 {
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);
5165 if (IsGeometry(argv[i]) == MagickFalse)
5166 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5167 break;
5168 }
5169 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5170 }
5171 case 'k':
5172 {
5173 if (LocaleCompare("kerning",option+1) == 0)
5174 {
5175 if (*option == '+')
5176 break;
5177 i++;
cristybb503372010-05-27 20:51:26 +00005178 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005179 ThrowMogrifyException(OptionError,"MissingArgument",option);
5180 if (IsGeometry(argv[i]) == MagickFalse)
5181 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5182 break;
5183 }
5184 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5185 }
5186 case 'l':
5187 {
5188 if (LocaleCompare("label",option+1) == 0)
5189 {
5190 if (*option == '+')
5191 break;
5192 i++;
cristybb503372010-05-27 20:51:26 +00005193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005194 ThrowMogrifyException(OptionError,"MissingArgument",option);
5195 break;
5196 }
5197 if (LocaleCompare("lat",option+1) == 0)
5198 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5205 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5206 }
5207 if (LocaleCompare("layers",option+1) == 0)
5208 {
cristybb503372010-05-27 20:51:26 +00005209 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005210 type;
5211
5212 if (*option == '+')
5213 break;
5214 i++;
cristybb503372010-05-27 20:51:26 +00005215 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005216 ThrowMogrifyException(OptionError,"MissingArgument",option);
5217 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5218 if (type < 0)
5219 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5220 argv[i]);
5221 break;
5222 }
5223 if (LocaleCompare("level",option+1) == 0)
5224 {
5225 i++;
cristybb503372010-05-27 20:51:26 +00005226 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005227 ThrowMogrifyException(OptionError,"MissingArgument",option);
5228 if (IsGeometry(argv[i]) == MagickFalse)
5229 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5230 break;
5231 }
5232 if (LocaleCompare("level-colors",option+1) == 0)
5233 {
5234 i++;
cristybb503372010-05-27 20:51:26 +00005235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 break;
5238 }
5239 if (LocaleCompare("linewidth",option+1) == 0)
5240 {
5241 if (*option == '+')
5242 break;
5243 i++;
cristybb503372010-05-27 20:51:26 +00005244 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005245 ThrowMogrifyException(OptionError,"MissingArgument",option);
5246 if (IsGeometry(argv[i]) == MagickFalse)
5247 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5248 break;
5249 }
5250 if (LocaleCompare("limit",option+1) == 0)
5251 {
5252 char
5253 *p;
5254
5255 double
5256 value;
5257
cristybb503372010-05-27 20:51:26 +00005258 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005259 resource;
5260
5261 if (*option == '+')
5262 break;
5263 i++;
cristybb503372010-05-27 20:51:26 +00005264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005265 ThrowMogrifyException(OptionError,"MissingArgument",option);
5266 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5267 argv[i]);
5268 if (resource < 0)
5269 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5270 argv[i]);
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 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00005275 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00005276 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5277 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5278 break;
5279 }
5280 if (LocaleCompare("liquid-rescale",option+1) == 0)
5281 {
5282 i++;
cristybb503372010-05-27 20:51:26 +00005283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005284 ThrowMogrifyException(OptionError,"MissingArgument",option);
5285 if (IsGeometry(argv[i]) == MagickFalse)
5286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5287 break;
5288 }
5289 if (LocaleCompare("list",option+1) == 0)
5290 {
cristybb503372010-05-27 20:51:26 +00005291 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005292 list;
5293
5294 if (*option == '+')
5295 break;
5296 i++;
cristybb503372010-05-27 20:51:26 +00005297 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005298 ThrowMogrifyException(OptionError,"MissingArgument",option);
5299 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5300 if (list < 0)
5301 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005302 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005303 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005304 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005305 }
5306 if (LocaleCompare("log",option+1) == 0)
5307 {
5308 if (*option == '+')
5309 break;
5310 i++;
cristybb503372010-05-27 20:51:26 +00005311 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005312 (strchr(argv[i],'%') == (char *) NULL))
5313 ThrowMogrifyException(OptionError,"MissingArgument",option);
5314 break;
5315 }
5316 if (LocaleCompare("loop",option+1) == 0)
5317 {
5318 if (*option == '+')
5319 break;
5320 i++;
cristybb503372010-05-27 20:51:26 +00005321 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005322 ThrowMogrifyException(OptionError,"MissingArgument",option);
5323 if (IsGeometry(argv[i]) == MagickFalse)
5324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5325 break;
5326 }
5327 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5328 }
5329 case 'm':
5330 {
5331 if (LocaleCompare("map",option+1) == 0)
5332 {
5333 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
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 break;
5340 }
5341 if (LocaleCompare("mask",option+1) == 0)
5342 {
5343 if (*option == '+')
5344 break;
5345 i++;
cristybb503372010-05-27 20:51:26 +00005346 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005347 ThrowMogrifyException(OptionError,"MissingArgument",option);
5348 break;
5349 }
5350 if (LocaleCompare("matte",option+1) == 0)
5351 break;
5352 if (LocaleCompare("mattecolor",option+1) == 0)
5353 {
5354 if (*option == '+')
5355 break;
5356 i++;
cristybb503372010-05-27 20:51:26 +00005357 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005358 ThrowMogrifyException(OptionError,"MissingArgument",option);
5359 break;
5360 }
cristyf40785b2010-03-06 02:27:27 +00005361 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005362 break;
cristyf40785b2010-03-06 02:27:27 +00005363 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005364 break;
cristy3ed852e2009-09-05 21:47:34 +00005365 if (LocaleCompare("modulate",option+1) == 0)
5366 {
5367 if (*option == '+')
5368 break;
5369 i++;
cristybb503372010-05-27 20:51:26 +00005370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005371 ThrowMogrifyException(OptionError,"MissingArgument",option);
5372 if (IsGeometry(argv[i]) == MagickFalse)
5373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5374 break;
5375 }
5376 if (LocaleCompare("median",option+1) == 0)
5377 {
5378 if (*option == '+')
5379 break;
5380 i++;
cristybb503372010-05-27 20:51:26 +00005381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005382 ThrowMogrifyException(OptionError,"MissingArgument",option);
5383 if (IsGeometry(argv[i]) == MagickFalse)
5384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5385 break;
5386 }
5387 if (LocaleCompare("monitor",option+1) == 0)
5388 break;
5389 if (LocaleCompare("monochrome",option+1) == 0)
5390 break;
5391 if (LocaleCompare("morph",option+1) == 0)
5392 {
5393 if (*option == '+')
5394 break;
5395 i++;
cristybb503372010-05-27 20:51:26 +00005396 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005397 ThrowMogrifyException(OptionError,"MissingArgument",option);
5398 if (IsGeometry(argv[i]) == MagickFalse)
5399 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5400 break;
5401 }
anthony29188a82010-01-22 10:12:34 +00005402 if (LocaleCompare("morphology",option+1) == 0)
5403 {
anthony29188a82010-01-22 10:12:34 +00005404 char
5405 token[MaxTextExtent];
5406
cristyb6bd4ad2010-08-08 01:12:27 +00005407 KernelInfo
5408 *kernel_info;
5409
5410 ssize_t
5411 op;
5412
anthony29188a82010-01-22 10:12:34 +00005413 i++;
cristybb503372010-05-27 20:51:26 +00005414 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005415 ThrowMogrifyException(OptionError,"MissingArgument",option);
5416 GetMagickToken(argv[i],NULL,token);
5417 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5418 if (op < 0)
5419 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005420 token);
anthony29188a82010-01-22 10:12:34 +00005421 i++;
cristybb503372010-05-27 20:51:26 +00005422 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005423 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005424 kernel_info=AcquireKernelInfo(argv[i]);
5425 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005426 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005427 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005428 break;
5429 }
cristy3ed852e2009-09-05 21:47:34 +00005430 if (LocaleCompare("mosaic",option+1) == 0)
5431 break;
5432 if (LocaleCompare("motion-blur",option+1) == 0)
5433 {
5434 if (*option == '+')
5435 break;
5436 i++;
cristybb503372010-05-27 20:51:26 +00005437 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005438 ThrowMogrifyException(OptionError,"MissingArgument",option);
5439 if (IsGeometry(argv[i]) == MagickFalse)
5440 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5441 break;
5442 }
5443 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5444 }
5445 case 'n':
5446 {
5447 if (LocaleCompare("negate",option+1) == 0)
5448 break;
5449 if (LocaleCompare("noise",option+1) == 0)
5450 {
5451 i++;
cristybb503372010-05-27 20:51:26 +00005452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005453 ThrowMogrifyException(OptionError,"MissingArgument",option);
5454 if (*option == '+')
5455 {
cristybb503372010-05-27 20:51:26 +00005456 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005457 noise;
5458
5459 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5460 if (noise < 0)
5461 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5462 argv[i]);
5463 break;
5464 }
5465 if (IsGeometry(argv[i]) == MagickFalse)
5466 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5467 break;
5468 }
5469 if (LocaleCompare("noop",option+1) == 0)
5470 break;
5471 if (LocaleCompare("normalize",option+1) == 0)
5472 break;
5473 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5474 }
5475 case 'o':
5476 {
5477 if (LocaleCompare("opaque",option+1) == 0)
5478 {
cristy3ed852e2009-09-05 21:47:34 +00005479 i++;
cristybb503372010-05-27 20:51:26 +00005480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005481 ThrowMogrifyException(OptionError,"MissingArgument",option);
5482 break;
5483 }
5484 if (LocaleCompare("ordered-dither",option+1) == 0)
5485 {
5486 if (*option == '+')
5487 break;
5488 i++;
cristybb503372010-05-27 20:51:26 +00005489 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005490 ThrowMogrifyException(OptionError,"MissingArgument",option);
5491 break;
5492 }
5493 if (LocaleCompare("orient",option+1) == 0)
5494 {
cristybb503372010-05-27 20:51:26 +00005495 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005496 orientation;
5497
5498 orientation=UndefinedOrientation;
5499 if (*option == '+')
5500 break;
5501 i++;
cristybb503372010-05-27 20:51:26 +00005502 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005503 ThrowMogrifyException(OptionError,"MissingArgument",option);
5504 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5505 argv[i]);
5506 if (orientation < 0)
5507 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5508 argv[i]);
5509 break;
5510 }
5511 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5512 }
5513 case 'p':
5514 {
5515 if (LocaleCompare("page",option+1) == 0)
5516 {
5517 if (*option == '+')
5518 break;
5519 i++;
cristybb503372010-05-27 20:51:26 +00005520 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005521 ThrowMogrifyException(OptionError,"MissingArgument",option);
5522 break;
5523 }
5524 if (LocaleCompare("paint",option+1) == 0)
5525 {
5526 if (*option == '+')
5527 break;
5528 i++;
cristybb503372010-05-27 20:51:26 +00005529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005530 ThrowMogrifyException(OptionError,"MissingArgument",option);
5531 if (IsGeometry(argv[i]) == MagickFalse)
5532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5533 break;
5534 }
5535 if (LocaleCompare("path",option+1) == 0)
5536 {
5537 (void) CloneString(&path,(char *) NULL);
5538 if (*option == '+')
5539 break;
5540 i++;
cristybb503372010-05-27 20:51:26 +00005541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005542 ThrowMogrifyException(OptionError,"MissingArgument",option);
5543 (void) CloneString(&path,argv[i]);
5544 break;
5545 }
5546 if (LocaleCompare("pointsize",option+1) == 0)
5547 {
5548 if (*option == '+')
5549 break;
5550 i++;
cristybb503372010-05-27 20:51:26 +00005551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005552 ThrowMogrifyException(OptionError,"MissingArgument",option);
5553 if (IsGeometry(argv[i]) == MagickFalse)
5554 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5555 break;
5556 }
5557 if (LocaleCompare("polaroid",option+1) == 0)
5558 {
5559 if (*option == '+')
5560 break;
5561 i++;
cristybb503372010-05-27 20:51:26 +00005562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005563 ThrowMogrifyException(OptionError,"MissingArgument",option);
5564 if (IsGeometry(argv[i]) == MagickFalse)
5565 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5566 break;
5567 }
5568 if (LocaleCompare("posterize",option+1) == 0)
5569 {
5570 if (*option == '+')
5571 break;
5572 i++;
cristybb503372010-05-27 20:51:26 +00005573 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005574 ThrowMogrifyException(OptionError,"MissingArgument",option);
5575 if (IsGeometry(argv[i]) == MagickFalse)
5576 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5577 break;
5578 }
cristye7f51092010-01-17 00:39:37 +00005579 if (LocaleCompare("precision",option+1) == 0)
5580 {
5581 if (*option == '+')
5582 break;
5583 i++;
cristybb503372010-05-27 20:51:26 +00005584 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005585 ThrowMogrifyException(OptionError,"MissingArgument",option);
5586 if (IsGeometry(argv[i]) == MagickFalse)
5587 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5588 break;
5589 }
cristy3ed852e2009-09-05 21:47:34 +00005590 if (LocaleCompare("print",option+1) == 0)
5591 {
5592 if (*option == '+')
5593 break;
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 break;
5598 }
5599 if (LocaleCompare("process",option+1) == 0)
5600 {
5601 if (*option == '+')
5602 break;
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 break;
5607 }
5608 if (LocaleCompare("profile",option+1) == 0)
5609 {
5610 i++;
cristybb503372010-05-27 20:51:26 +00005611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005612 ThrowMogrifyException(OptionError,"MissingArgument",option);
5613 break;
5614 }
5615 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5616 }
5617 case 'q':
5618 {
5619 if (LocaleCompare("quality",option+1) == 0)
5620 {
5621 if (*option == '+')
5622 break;
5623 i++;
cristybb503372010-05-27 20:51:26 +00005624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005625 ThrowMogrifyException(OptionError,"MissingArgument",option);
5626 if (IsGeometry(argv[i]) == MagickFalse)
5627 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5628 break;
5629 }
5630 if (LocaleCompare("quantize",option+1) == 0)
5631 {
cristybb503372010-05-27 20:51:26 +00005632 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005633 colorspace;
5634
5635 if (*option == '+')
5636 break;
5637 i++;
cristybb503372010-05-27 20:51:26 +00005638 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5641 argv[i]);
5642 if (colorspace < 0)
5643 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5644 argv[i]);
5645 break;
5646 }
5647 if (LocaleCompare("quiet",option+1) == 0)
5648 break;
5649 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5650 }
5651 case 'r':
5652 {
5653 if (LocaleCompare("radial-blur",option+1) == 0)
5654 {
5655 i++;
cristybb503372010-05-27 20:51:26 +00005656 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005657 ThrowMogrifyException(OptionError,"MissingArgument",option);
5658 if (IsGeometry(argv[i]) == MagickFalse)
5659 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5660 break;
5661 }
5662 if (LocaleCompare("raise",option+1) == 0)
5663 {
5664 i++;
cristybb503372010-05-27 20:51:26 +00005665 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005666 ThrowMogrifyException(OptionError,"MissingArgument",option);
5667 if (IsGeometry(argv[i]) == MagickFalse)
5668 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5669 break;
5670 }
5671 if (LocaleCompare("random-threshold",option+1) == 0)
5672 {
5673 if (*option == '+')
5674 break;
5675 i++;
cristybb503372010-05-27 20:51:26 +00005676 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005677 ThrowMogrifyException(OptionError,"MissingArgument",option);
5678 if (IsGeometry(argv[i]) == MagickFalse)
5679 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5680 break;
5681 }
cristye6365592010-04-02 17:31:23 +00005682 if (LocaleCompare("recolor",option+1) == 0)
5683 {
5684 if (*option == '+')
5685 break;
5686 i++;
cristybb503372010-05-27 20:51:26 +00005687 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005688 ThrowMogrifyException(OptionError,"MissingArgument",option);
5689 if (IsGeometry(argv[i]) == MagickFalse)
5690 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5691 break;
5692 }
cristy3ed852e2009-09-05 21:47:34 +00005693 if (LocaleCompare("red-primary",option+1) == 0)
5694 {
5695 if (*option == '+')
5696 break;
5697 i++;
cristybb503372010-05-27 20:51:26 +00005698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005699 ThrowMogrifyException(OptionError,"MissingArgument",option);
5700 if (IsGeometry(argv[i]) == MagickFalse)
5701 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5702 }
cristy9f2083a2010-04-22 19:48:05 +00005703 if (LocaleCompare("regard-warnings",option+1) == 0)
5704 break;
cristy3ed852e2009-09-05 21:47:34 +00005705 if (LocaleCompare("region",option+1) == 0)
5706 {
5707 if (*option == '+')
5708 break;
5709 i++;
cristybb503372010-05-27 20:51:26 +00005710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005711 ThrowMogrifyException(OptionError,"MissingArgument",option);
5712 if (IsGeometry(argv[i]) == MagickFalse)
5713 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5714 break;
5715 }
cristyf0c78232010-03-15 12:53:40 +00005716 if (LocaleCompare("remap",option+1) == 0)
5717 {
5718 if (*option == '+')
5719 break;
5720 i++;
cristybb503372010-05-27 20:51:26 +00005721 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005722 ThrowMogrifyException(OptionError,"MissingArgument",option);
5723 break;
5724 }
cristy3ed852e2009-09-05 21:47:34 +00005725 if (LocaleCompare("render",option+1) == 0)
5726 break;
5727 if (LocaleCompare("repage",option+1) == 0)
5728 {
5729 if (*option == '+')
5730 break;
5731 i++;
cristybb503372010-05-27 20:51:26 +00005732 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005733 ThrowMogrifyException(OptionError,"MissingArgument",option);
5734 if (IsGeometry(argv[i]) == MagickFalse)
5735 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5736 break;
5737 }
5738 if (LocaleCompare("resample",option+1) == 0)
5739 {
5740 if (*option == '+')
5741 break;
5742 i++;
cristybb503372010-05-27 20:51:26 +00005743 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005744 ThrowMogrifyException(OptionError,"MissingArgument",option);
5745 if (IsGeometry(argv[i]) == MagickFalse)
5746 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5747 break;
5748 }
5749 if (LocaleCompare("resize",option+1) == 0)
5750 {
5751 if (*option == '+')
5752 break;
5753 i++;
cristybb503372010-05-27 20:51:26 +00005754 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005755 ThrowMogrifyException(OptionError,"MissingArgument",option);
5756 if (IsGeometry(argv[i]) == MagickFalse)
5757 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5758 break;
5759 }
cristyebbcfea2011-02-25 02:43:54 +00005760 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5761 {
5762 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5763 break;
5764 }
cristy3ed852e2009-09-05 21:47:34 +00005765 if (LocaleCompare("reverse",option+1) == 0)
5766 break;
5767 if (LocaleCompare("roll",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 }
5778 if (LocaleCompare("rotate",option+1) == 0)
5779 {
5780 i++;
cristybb503372010-05-27 20:51:26 +00005781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005782 ThrowMogrifyException(OptionError,"MissingArgument",option);
5783 if (IsGeometry(argv[i]) == MagickFalse)
5784 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5785 break;
5786 }
5787 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5788 }
5789 case 's':
5790 {
5791 if (LocaleCompare("sample",option+1) == 0)
5792 {
5793 if (*option == '+')
5794 break;
5795 i++;
cristybb503372010-05-27 20:51:26 +00005796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005797 ThrowMogrifyException(OptionError,"MissingArgument",option);
5798 if (IsGeometry(argv[i]) == MagickFalse)
5799 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5800 break;
5801 }
5802 if (LocaleCompare("sampling-factor",option+1) == 0)
5803 {
5804 if (*option == '+')
5805 break;
5806 i++;
cristybb503372010-05-27 20:51:26 +00005807 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005808 ThrowMogrifyException(OptionError,"MissingArgument",option);
5809 if (IsGeometry(argv[i]) == MagickFalse)
5810 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5811 break;
5812 }
5813 if (LocaleCompare("scale",option+1) == 0)
5814 {
5815 if (*option == '+')
5816 break;
5817 i++;
cristybb503372010-05-27 20:51:26 +00005818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005819 ThrowMogrifyException(OptionError,"MissingArgument",option);
5820 if (IsGeometry(argv[i]) == MagickFalse)
5821 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5822 break;
5823 }
5824 if (LocaleCompare("scene",option+1) == 0)
5825 {
5826 if (*option == '+')
5827 break;
5828 i++;
cristybb503372010-05-27 20:51:26 +00005829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005830 ThrowMogrifyException(OptionError,"MissingArgument",option);
5831 if (IsGeometry(argv[i]) == MagickFalse)
5832 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5833 break;
5834 }
5835 if (LocaleCompare("seed",option+1) == 0)
5836 {
5837 if (*option == '+')
5838 break;
5839 i++;
cristybb503372010-05-27 20:51:26 +00005840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005841 ThrowMogrifyException(OptionError,"MissingArgument",option);
5842 if (IsGeometry(argv[i]) == MagickFalse)
5843 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5844 break;
5845 }
5846 if (LocaleCompare("segment",option+1) == 0)
5847 {
5848 if (*option == '+')
5849 break;
5850 i++;
cristybb503372010-05-27 20:51:26 +00005851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005852 ThrowMogrifyException(OptionError,"MissingArgument",option);
5853 if (IsGeometry(argv[i]) == MagickFalse)
5854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5855 break;
5856 }
5857 if (LocaleCompare("selective-blur",option+1) == 0)
5858 {
5859 i++;
cristybb503372010-05-27 20:51:26 +00005860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005861 ThrowMogrifyException(OptionError,"MissingArgument",option);
5862 if (IsGeometry(argv[i]) == MagickFalse)
5863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5864 break;
5865 }
5866 if (LocaleCompare("separate",option+1) == 0)
5867 break;
5868 if (LocaleCompare("sepia-tone",option+1) == 0)
5869 {
5870 if (*option == '+')
5871 break;
5872 i++;
cristybb503372010-05-27 20:51:26 +00005873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005874 ThrowMogrifyException(OptionError,"MissingArgument",option);
5875 if (IsGeometry(argv[i]) == MagickFalse)
5876 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5877 break;
5878 }
5879 if (LocaleCompare("set",option+1) == 0)
5880 {
5881 i++;
cristybb503372010-05-27 20:51:26 +00005882 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005883 ThrowMogrifyException(OptionError,"MissingArgument",option);
5884 if (*option == '+')
5885 break;
5886 i++;
cristybb503372010-05-27 20:51:26 +00005887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005888 ThrowMogrifyException(OptionError,"MissingArgument",option);
5889 break;
5890 }
5891 if (LocaleCompare("shade",option+1) == 0)
5892 {
5893 i++;
cristybb503372010-05-27 20:51:26 +00005894 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005895 ThrowMogrifyException(OptionError,"MissingArgument",option);
5896 if (IsGeometry(argv[i]) == MagickFalse)
5897 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5898 break;
5899 }
5900 if (LocaleCompare("shadow",option+1) == 0)
5901 {
5902 if (*option == '+')
5903 break;
5904 i++;
cristybb503372010-05-27 20:51:26 +00005905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005906 ThrowMogrifyException(OptionError,"MissingArgument",option);
5907 if (IsGeometry(argv[i]) == MagickFalse)
5908 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5909 break;
5910 }
5911 if (LocaleCompare("sharpen",option+1) == 0)
5912 {
5913 i++;
cristybb503372010-05-27 20:51:26 +00005914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005915 ThrowMogrifyException(OptionError,"MissingArgument",option);
5916 if (IsGeometry(argv[i]) == MagickFalse)
5917 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5918 break;
5919 }
5920 if (LocaleCompare("shave",option+1) == 0)
5921 {
5922 if (*option == '+')
5923 break;
5924 i++;
cristybb503372010-05-27 20:51:26 +00005925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005926 ThrowMogrifyException(OptionError,"MissingArgument",option);
5927 if (IsGeometry(argv[i]) == MagickFalse)
5928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5929 break;
5930 }
5931 if (LocaleCompare("shear",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 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5941 {
5942 i++;
cristybb503372010-05-27 20:51:26 +00005943 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005944 ThrowMogrifyException(OptionError,"MissingArgument",option);
5945 if (IsGeometry(argv[i]) == MagickFalse)
5946 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5947 break;
5948 }
5949 if (LocaleCompare("size",option+1) == 0)
5950 {
5951 if (*option == '+')
5952 break;
5953 i++;
cristybb503372010-05-27 20:51:26 +00005954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005955 ThrowMogrifyException(OptionError,"MissingArgument",option);
5956 if (IsGeometry(argv[i]) == MagickFalse)
5957 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5958 break;
5959 }
5960 if (LocaleCompare("sketch",option+1) == 0)
5961 {
5962 if (*option == '+')
5963 break;
5964 i++;
cristybb503372010-05-27 20:51:26 +00005965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005966 ThrowMogrifyException(OptionError,"MissingArgument",option);
5967 if (IsGeometry(argv[i]) == MagickFalse)
5968 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5969 break;
5970 }
cristy4285d782011-02-09 20:12:28 +00005971 if (LocaleCompare("smush",option+1) == 0)
5972 {
cristy4285d782011-02-09 20:12:28 +00005973 i++;
5974 if (i == (ssize_t) argc)
5975 ThrowMogrifyException(OptionError,"MissingArgument",option);
5976 if (IsGeometry(argv[i]) == MagickFalse)
5977 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005978 i++;
5979 break;
5980 }
cristy3ed852e2009-09-05 21:47:34 +00005981 if (LocaleCompare("solarize",option+1) == 0)
5982 {
5983 if (*option == '+')
5984 break;
5985 i++;
cristybb503372010-05-27 20:51:26 +00005986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005987 ThrowMogrifyException(OptionError,"MissingArgument",option);
5988 if (IsGeometry(argv[i]) == MagickFalse)
5989 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5990 break;
5991 }
5992 if (LocaleCompare("sparse-color",option+1) == 0)
5993 {
cristybb503372010-05-27 20:51:26 +00005994 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005995 op;
5996
5997 i++;
cristybb503372010-05-27 20:51:26 +00005998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005999 ThrowMogrifyException(OptionError,"MissingArgument",option);
6000 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6001 if (op < 0)
6002 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6003 argv[i]);
6004 i++;
cristybb503372010-05-27 20:51:26 +00006005 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006006 ThrowMogrifyException(OptionError,"MissingArgument",option);
6007 break;
6008 }
6009 if (LocaleCompare("spread",option+1) == 0)
6010 {
6011 if (*option == '+')
6012 break;
6013 i++;
cristybb503372010-05-27 20:51:26 +00006014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006015 ThrowMogrifyException(OptionError,"MissingArgument",option);
6016 if (IsGeometry(argv[i]) == MagickFalse)
6017 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6018 break;
6019 }
6020 if (LocaleCompare("stretch",option+1) == 0)
6021 {
cristybb503372010-05-27 20:51:26 +00006022 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006023 stretch;
6024
6025 if (*option == '+')
6026 break;
6027 i++;
cristybb503372010-05-27 20:51:26 +00006028 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006029 ThrowMogrifyException(OptionError,"MissingArgument",option);
6030 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6031 if (stretch < 0)
6032 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6033 argv[i]);
6034 break;
6035 }
6036 if (LocaleCompare("strip",option+1) == 0)
6037 break;
6038 if (LocaleCompare("stroke",option+1) == 0)
6039 {
6040 if (*option == '+')
6041 break;
6042 i++;
cristybb503372010-05-27 20:51:26 +00006043 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006044 ThrowMogrifyException(OptionError,"MissingArgument",option);
6045 break;
6046 }
6047 if (LocaleCompare("strokewidth",option+1) == 0)
6048 {
6049 if (*option == '+')
6050 break;
6051 i++;
cristybb503372010-05-27 20:51:26 +00006052 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006053 ThrowMogrifyException(OptionError,"MissingArgument",option);
6054 if (IsGeometry(argv[i]) == MagickFalse)
6055 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6056 break;
6057 }
6058 if (LocaleCompare("style",option+1) == 0)
6059 {
cristybb503372010-05-27 20:51:26 +00006060 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006061 style;
6062
6063 if (*option == '+')
6064 break;
6065 i++;
cristybb503372010-05-27 20:51:26 +00006066 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006067 ThrowMogrifyException(OptionError,"MissingArgument",option);
6068 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6069 if (style < 0)
6070 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6071 argv[i]);
6072 break;
6073 }
6074 if (LocaleCompare("swirl",option+1) == 0)
6075 {
6076 if (*option == '+')
6077 break;
6078 i++;
cristybb503372010-05-27 20:51:26 +00006079 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006080 ThrowMogrifyException(OptionError,"MissingArgument",option);
6081 if (IsGeometry(argv[i]) == MagickFalse)
6082 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6083 break;
6084 }
cristyd9a29192010-10-16 16:49:53 +00006085 if (LocaleCompare("synchronize",option+1) == 0)
6086 break;
cristy3ed852e2009-09-05 21:47:34 +00006087 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6088 }
6089 case 't':
6090 {
6091 if (LocaleCompare("taint",option+1) == 0)
6092 break;
6093 if (LocaleCompare("texture",option+1) == 0)
6094 {
6095 if (*option == '+')
6096 break;
6097 i++;
cristybb503372010-05-27 20:51:26 +00006098 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006099 ThrowMogrifyException(OptionError,"MissingArgument",option);
6100 break;
6101 }
6102 if (LocaleCompare("tile",option+1) == 0)
6103 {
6104 if (*option == '+')
6105 break;
6106 i++;
cristybb503372010-05-27 20:51:26 +00006107 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006108 ThrowMogrifyException(OptionError,"MissingArgument",option);
6109 break;
6110 }
6111 if (LocaleCompare("tile-offset",option+1) == 0)
6112 {
6113 if (*option == '+')
6114 break;
6115 i++;
cristybb503372010-05-27 20:51:26 +00006116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006117 ThrowMogrifyException(OptionError,"MissingArgument",option);
6118 if (IsGeometry(argv[i]) == MagickFalse)
6119 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6120 break;
6121 }
6122 if (LocaleCompare("tint",option+1) == 0)
6123 {
6124 if (*option == '+')
6125 break;
6126 i++;
cristybb503372010-05-27 20:51:26 +00006127 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006128 ThrowMogrifyException(OptionError,"MissingArgument",option);
6129 if (IsGeometry(argv[i]) == MagickFalse)
6130 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6131 break;
6132 }
6133 if (LocaleCompare("transform",option+1) == 0)
6134 break;
6135 if (LocaleCompare("transpose",option+1) == 0)
6136 break;
6137 if (LocaleCompare("transverse",option+1) == 0)
6138 break;
6139 if (LocaleCompare("threshold",option+1) == 0)
6140 {
6141 if (*option == '+')
6142 break;
6143 i++;
cristybb503372010-05-27 20:51:26 +00006144 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006145 ThrowMogrifyException(OptionError,"MissingArgument",option);
6146 if (IsGeometry(argv[i]) == MagickFalse)
6147 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6148 break;
6149 }
6150 if (LocaleCompare("thumbnail",option+1) == 0)
6151 {
6152 if (*option == '+')
6153 break;
6154 i++;
cristybb503372010-05-27 20:51:26 +00006155 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006156 ThrowMogrifyException(OptionError,"MissingArgument",option);
6157 if (IsGeometry(argv[i]) == MagickFalse)
6158 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6159 break;
6160 }
6161 if (LocaleCompare("transparent",option+1) == 0)
6162 {
6163 i++;
cristybb503372010-05-27 20:51:26 +00006164 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006165 ThrowMogrifyException(OptionError,"MissingArgument",option);
6166 break;
6167 }
6168 if (LocaleCompare("transparent-color",option+1) == 0)
6169 {
6170 if (*option == '+')
6171 break;
6172 i++;
cristybb503372010-05-27 20:51:26 +00006173 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006174 ThrowMogrifyException(OptionError,"MissingArgument",option);
6175 break;
6176 }
6177 if (LocaleCompare("treedepth",option+1) == 0)
6178 {
6179 if (*option == '+')
6180 break;
6181 i++;
cristybb503372010-05-27 20:51:26 +00006182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006183 ThrowMogrifyException(OptionError,"MissingArgument",option);
6184 if (IsGeometry(argv[i]) == MagickFalse)
6185 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6186 break;
6187 }
6188 if (LocaleCompare("trim",option+1) == 0)
6189 break;
6190 if (LocaleCompare("type",option+1) == 0)
6191 {
cristybb503372010-05-27 20:51:26 +00006192 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006193 type;
6194
6195 if (*option == '+')
6196 break;
6197 i++;
cristybb503372010-05-27 20:51:26 +00006198 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006199 ThrowMogrifyException(OptionError,"MissingArgument",option);
6200 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6201 if (type < 0)
6202 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6203 argv[i]);
6204 break;
6205 }
6206 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6207 }
6208 case 'u':
6209 {
6210 if (LocaleCompare("undercolor",option+1) == 0)
6211 {
6212 if (*option == '+')
6213 break;
6214 i++;
cristybb503372010-05-27 20:51:26 +00006215 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006216 ThrowMogrifyException(OptionError,"MissingArgument",option);
6217 break;
6218 }
6219 if (LocaleCompare("unique-colors",option+1) == 0)
6220 break;
6221 if (LocaleCompare("units",option+1) == 0)
6222 {
cristybb503372010-05-27 20:51:26 +00006223 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006224 units;
6225
6226 if (*option == '+')
6227 break;
6228 i++;
cristybb503372010-05-27 20:51:26 +00006229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006230 ThrowMogrifyException(OptionError,"MissingArgument",option);
6231 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6232 argv[i]);
6233 if (units < 0)
6234 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6235 argv[i]);
6236 break;
6237 }
6238 if (LocaleCompare("unsharp",option+1) == 0)
6239 {
6240 i++;
cristybb503372010-05-27 20:51:26 +00006241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006242 ThrowMogrifyException(OptionError,"MissingArgument",option);
6243 if (IsGeometry(argv[i]) == MagickFalse)
6244 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6245 break;
6246 }
6247 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6248 }
6249 case 'v':
6250 {
6251 if (LocaleCompare("verbose",option+1) == 0)
6252 {
6253 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6254 break;
6255 }
6256 if ((LocaleCompare("version",option+1) == 0) ||
6257 (LocaleCompare("-version",option+1) == 0))
6258 {
6259 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006260 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006261 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6262 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006263 break;
6264 }
6265 if (LocaleCompare("view",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 break;
6269 i++;
cristybb503372010-05-27 20:51:26 +00006270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006271 ThrowMogrifyException(OptionError,"MissingArgument",option);
6272 break;
6273 }
6274 if (LocaleCompare("vignette",option+1) == 0)
6275 {
6276 if (*option == '+')
6277 break;
6278 i++;
cristybb503372010-05-27 20:51:26 +00006279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006280 ThrowMogrifyException(OptionError,"MissingArgument",option);
6281 if (IsGeometry(argv[i]) == MagickFalse)
6282 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6283 break;
6284 }
6285 if (LocaleCompare("virtual-pixel",option+1) == 0)
6286 {
cristybb503372010-05-27 20:51:26 +00006287 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006288 method;
6289
6290 if (*option == '+')
6291 break;
6292 i++;
cristybb503372010-05-27 20:51:26 +00006293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006294 ThrowMogrifyException(OptionError,"MissingArgument",option);
6295 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6296 argv[i]);
6297 if (method < 0)
6298 ThrowMogrifyException(OptionError,
6299 "UnrecognizedVirtualPixelMethod",argv[i]);
6300 break;
6301 }
6302 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6303 }
6304 case 'w':
6305 {
6306 if (LocaleCompare("wave",option+1) == 0)
6307 {
6308 i++;
cristybb503372010-05-27 20:51:26 +00006309 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006310 ThrowMogrifyException(OptionError,"MissingArgument",option);
6311 if (IsGeometry(argv[i]) == MagickFalse)
6312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6313 break;
6314 }
6315 if (LocaleCompare("weight",option+1) == 0)
6316 {
6317 if (*option == '+')
6318 break;
6319 i++;
cristybb503372010-05-27 20:51:26 +00006320 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006321 ThrowMogrifyException(OptionError,"MissingArgument",option);
6322 break;
6323 }
6324 if (LocaleCompare("white-point",option+1) == 0)
6325 {
6326 if (*option == '+')
6327 break;
6328 i++;
cristybb503372010-05-27 20:51:26 +00006329 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006330 ThrowMogrifyException(OptionError,"MissingArgument",option);
6331 if (IsGeometry(argv[i]) == MagickFalse)
6332 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6333 break;
6334 }
6335 if (LocaleCompare("white-threshold",option+1) == 0)
6336 {
6337 if (*option == '+')
6338 break;
6339 i++;
cristybb503372010-05-27 20:51:26 +00006340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006341 ThrowMogrifyException(OptionError,"MissingArgument",option);
6342 if (IsGeometry(argv[i]) == MagickFalse)
6343 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6344 break;
6345 }
6346 if (LocaleCompare("write",option+1) == 0)
6347 {
6348 i++;
cristybb503372010-05-27 20:51:26 +00006349 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006350 ThrowMogrifyException(OptionError,"MissingArgument",option);
6351 break;
6352 }
6353 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6354 }
6355 case '?':
6356 break;
6357 default:
6358 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6359 }
6360 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6361 MagickFalse : MagickTrue;
6362 if (fire != MagickFalse)
6363 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6364 }
6365 if (k != 0)
6366 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006367 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006368 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6369 DestroyMogrify();
6370 return(status != 0 ? MagickTrue : MagickFalse);
6371}
6372
6373/*
6374%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6375% %
6376% %
6377% %
6378+ M o g r i f y I m a g e I n f o %
6379% %
6380% %
6381% %
6382%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6383%
6384% MogrifyImageInfo() applies image processing settings to the image as
6385% prescribed by command line options.
6386%
6387% The format of the MogrifyImageInfo method is:
6388%
6389% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6390% const char **argv,ExceptionInfo *exception)
6391%
6392% A description of each parameter follows:
6393%
6394% o image_info: the image info..
6395%
6396% o argc: Specifies a pointer to an integer describing the number of
6397% elements in the argument vector.
6398%
6399% o argv: Specifies a pointer to a text array containing the command line
6400% arguments.
6401%
6402% o exception: return any errors or warnings in this structure.
6403%
6404*/
6405WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6406 const int argc,const char **argv,ExceptionInfo *exception)
6407{
6408 const char
6409 *option;
6410
6411 GeometryInfo
6412 geometry_info;
6413
cristybb503372010-05-27 20:51:26 +00006414 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006415 count;
6416
cristybb503372010-05-27 20:51:26 +00006417 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006418 i;
6419
6420 /*
6421 Initialize method variables.
6422 */
6423 assert(image_info != (ImageInfo *) NULL);
6424 assert(image_info->signature == MagickSignature);
6425 if (image_info->debug != MagickFalse)
6426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6427 image_info->filename);
6428 if (argc < 0)
6429 return(MagickTrue);
6430 /*
6431 Set the image settings.
6432 */
cristybb503372010-05-27 20:51:26 +00006433 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006434 {
6435 option=argv[i];
6436 if (IsMagickOption(option) == MagickFalse)
6437 continue;
6438 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6439 0L);
cristycee97112010-05-28 00:44:52 +00006440 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006441 break;
6442 switch (*(option+1))
6443 {
6444 case 'a':
6445 {
6446 if (LocaleCompare("adjoin",option+1) == 0)
6447 {
6448 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6449 break;
6450 }
6451 if (LocaleCompare("antialias",option+1) == 0)
6452 {
6453 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6454 break;
6455 }
6456 if (LocaleCompare("attenuate",option+1) == 0)
6457 {
6458 if (*option == '+')
6459 {
6460 (void) DeleteImageOption(image_info,option+1);
6461 break;
6462 }
6463 (void) SetImageOption(image_info,option+1,argv[i+1]);
6464 break;
6465 }
6466 if (LocaleCompare("authenticate",option+1) == 0)
6467 {
6468 if (*option == '+')
6469 (void) CloneString(&image_info->authenticate,(char *) NULL);
6470 else
6471 (void) CloneString(&image_info->authenticate,argv[i+1]);
6472 break;
6473 }
6474 break;
6475 }
6476 case 'b':
6477 {
6478 if (LocaleCompare("background",option+1) == 0)
6479 {
6480 if (*option == '+')
6481 {
6482 (void) DeleteImageOption(image_info,option+1);
6483 (void) QueryColorDatabase(BackgroundColor,
6484 &image_info->background_color,exception);
6485 break;
6486 }
6487 (void) SetImageOption(image_info,option+1,argv[i+1]);
6488 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6489 exception);
6490 break;
6491 }
6492 if (LocaleCompare("bias",option+1) == 0)
6493 {
6494 if (*option == '+')
6495 {
6496 (void) SetImageOption(image_info,option+1,"0.0");
6497 break;
6498 }
6499 (void) SetImageOption(image_info,option+1,argv[i+1]);
6500 break;
6501 }
6502 if (LocaleCompare("black-point-compensation",option+1) == 0)
6503 {
6504 if (*option == '+')
6505 {
6506 (void) SetImageOption(image_info,option+1,"false");
6507 break;
6508 }
6509 (void) SetImageOption(image_info,option+1,"true");
6510 break;
6511 }
6512 if (LocaleCompare("blue-primary",option+1) == 0)
6513 {
6514 if (*option == '+')
6515 {
6516 (void) SetImageOption(image_info,option+1,"0.0");
6517 break;
6518 }
6519 (void) SetImageOption(image_info,option+1,argv[i+1]);
6520 break;
6521 }
6522 if (LocaleCompare("bordercolor",option+1) == 0)
6523 {
6524 if (*option == '+')
6525 {
6526 (void) DeleteImageOption(image_info,option+1);
6527 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6528 exception);
6529 break;
6530 }
6531 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6532 exception);
6533 (void) SetImageOption(image_info,option+1,argv[i+1]);
6534 break;
6535 }
6536 if (LocaleCompare("box",option+1) == 0)
6537 {
6538 if (*option == '+')
6539 {
6540 (void) SetImageOption(image_info,"undercolor","none");
6541 break;
6542 }
6543 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6544 break;
6545 }
6546 break;
6547 }
6548 case 'c':
6549 {
6550 if (LocaleCompare("cache",option+1) == 0)
6551 {
6552 MagickSizeType
6553 limit;
6554
6555 limit=MagickResourceInfinity;
6556 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006557 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006558 (void) SetMagickResourceLimit(MemoryResource,limit);
6559 (void) SetMagickResourceLimit(MapResource,2*limit);
6560 break;
6561 }
6562 if (LocaleCompare("caption",option+1) == 0)
6563 {
6564 if (*option == '+')
6565 {
6566 (void) DeleteImageOption(image_info,option+1);
6567 break;
6568 }
6569 (void) SetImageOption(image_info,option+1,argv[i+1]);
6570 break;
6571 }
6572 if (LocaleCompare("channel",option+1) == 0)
6573 {
6574 if (*option == '+')
6575 {
6576 image_info->channel=DefaultChannels;
6577 break;
6578 }
6579 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6580 break;
6581 }
6582 if (LocaleCompare("colors",option+1) == 0)
6583 {
cristye27293e2009-12-18 02:53:20 +00006584 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006585 break;
6586 }
6587 if (LocaleCompare("colorspace",option+1) == 0)
6588 {
6589 if (*option == '+')
6590 {
6591 image_info->colorspace=UndefinedColorspace;
6592 (void) SetImageOption(image_info,option+1,"undefined");
6593 break;
6594 }
6595 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6596 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6597 (void) SetImageOption(image_info,option+1,argv[i+1]);
6598 break;
6599 }
6600 if (LocaleCompare("compress",option+1) == 0)
6601 {
6602 if (*option == '+')
6603 {
6604 image_info->compression=UndefinedCompression;
6605 (void) SetImageOption(image_info,option+1,"undefined");
6606 break;
6607 }
6608 image_info->compression=(CompressionType) ParseMagickOption(
6609 MagickCompressOptions,MagickFalse,argv[i+1]);
6610 (void) SetImageOption(image_info,option+1,argv[i+1]);
6611 break;
6612 }
6613 if (LocaleCompare("comment",option+1) == 0)
6614 {
6615 if (*option == '+')
6616 {
6617 (void) DeleteImageOption(image_info,option+1);
6618 break;
6619 }
6620 (void) SetImageOption(image_info,option+1,argv[i+1]);
6621 break;
6622 }
6623 if (LocaleCompare("compose",option+1) == 0)
6624 {
6625 if (*option == '+')
6626 {
6627 (void) SetImageOption(image_info,option+1,"undefined");
6628 break;
6629 }
6630 (void) SetImageOption(image_info,option+1,argv[i+1]);
6631 break;
6632 }
6633 if (LocaleCompare("compress",option+1) == 0)
6634 {
6635 if (*option == '+')
6636 {
6637 image_info->compression=UndefinedCompression;
6638 (void) SetImageOption(image_info,option+1,"undefined");
6639 break;
6640 }
6641 image_info->compression=(CompressionType) ParseMagickOption(
6642 MagickCompressOptions,MagickFalse,argv[i+1]);
6643 (void) SetImageOption(image_info,option+1,argv[i+1]);
6644 break;
6645 }
6646 break;
6647 }
6648 case 'd':
6649 {
6650 if (LocaleCompare("debug",option+1) == 0)
6651 {
6652 if (*option == '+')
6653 (void) SetLogEventMask("none");
6654 else
6655 (void) SetLogEventMask(argv[i+1]);
6656 image_info->debug=IsEventLogging();
6657 break;
6658 }
6659 if (LocaleCompare("define",option+1) == 0)
6660 {
6661 if (*option == '+')
6662 {
6663 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6664 (void) DeleteImageRegistry(argv[i+1]+9);
6665 else
6666 (void) DeleteImageOption(image_info,argv[i+1]);
6667 break;
6668 }
6669 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6670 {
6671 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6672 exception);
6673 break;
6674 }
6675 (void) DefineImageOption(image_info,argv[i+1]);
6676 break;
6677 }
6678 if (LocaleCompare("delay",option+1) == 0)
6679 {
6680 if (*option == '+')
6681 {
6682 (void) SetImageOption(image_info,option+1,"0");
6683 break;
6684 }
6685 (void) SetImageOption(image_info,option+1,argv[i+1]);
6686 break;
6687 }
6688 if (LocaleCompare("density",option+1) == 0)
6689 {
6690 /*
6691 Set image density.
6692 */
6693 if (*option == '+')
6694 {
6695 if (image_info->density != (char *) NULL)
6696 image_info->density=DestroyString(image_info->density);
6697 (void) SetImageOption(image_info,option+1,"72");
6698 break;
6699 }
6700 (void) CloneString(&image_info->density,argv[i+1]);
6701 (void) SetImageOption(image_info,option+1,argv[i+1]);
6702 break;
6703 }
6704 if (LocaleCompare("depth",option+1) == 0)
6705 {
6706 if (*option == '+')
6707 {
6708 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6709 break;
6710 }
cristye27293e2009-12-18 02:53:20 +00006711 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006712 break;
6713 }
cristyc9b12952010-03-28 01:12:28 +00006714 if (LocaleCompare("direction",option+1) == 0)
6715 {
6716 if (*option == '+')
6717 {
6718 (void) SetImageOption(image_info,option+1,"undefined");
6719 break;
6720 }
6721 (void) SetImageOption(image_info,option+1,argv[i+1]);
6722 break;
6723 }
cristy3ed852e2009-09-05 21:47:34 +00006724 if (LocaleCompare("display",option+1) == 0)
6725 {
6726 if (*option == '+')
6727 {
6728 if (image_info->server_name != (char *) NULL)
6729 image_info->server_name=DestroyString(
6730 image_info->server_name);
6731 break;
6732 }
6733 (void) CloneString(&image_info->server_name,argv[i+1]);
6734 break;
6735 }
6736 if (LocaleCompare("dispose",option+1) == 0)
6737 {
6738 if (*option == '+')
6739 {
6740 (void) SetImageOption(image_info,option+1,"undefined");
6741 break;
6742 }
6743 (void) SetImageOption(image_info,option+1,argv[i+1]);
6744 break;
6745 }
6746 if (LocaleCompare("dither",option+1) == 0)
6747 {
6748 if (*option == '+')
6749 {
6750 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006751 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006752 break;
6753 }
6754 (void) SetImageOption(image_info,option+1,argv[i+1]);
6755 image_info->dither=MagickTrue;
6756 break;
6757 }
6758 break;
6759 }
6760 case 'e':
6761 {
6762 if (LocaleCompare("encoding",option+1) == 0)
6763 {
6764 if (*option == '+')
6765 {
6766 (void) SetImageOption(image_info,option+1,"undefined");
6767 break;
6768 }
6769 (void) SetImageOption(image_info,option+1,argv[i+1]);
6770 break;
6771 }
6772 if (LocaleCompare("endian",option+1) == 0)
6773 {
6774 if (*option == '+')
6775 {
6776 image_info->endian=UndefinedEndian;
6777 (void) SetImageOption(image_info,option+1,"undefined");
6778 break;
6779 }
6780 image_info->endian=(EndianType) ParseMagickOption(
6781 MagickEndianOptions,MagickFalse,argv[i+1]);
6782 (void) SetImageOption(image_info,option+1,argv[i+1]);
6783 break;
6784 }
6785 if (LocaleCompare("extract",option+1) == 0)
6786 {
6787 /*
6788 Set image extract geometry.
6789 */
6790 if (*option == '+')
6791 {
6792 if (image_info->extract != (char *) NULL)
6793 image_info->extract=DestroyString(image_info->extract);
6794 break;
6795 }
6796 (void) CloneString(&image_info->extract,argv[i+1]);
6797 break;
6798 }
6799 break;
6800 }
6801 case 'f':
6802 {
6803 if (LocaleCompare("fill",option+1) == 0)
6804 {
6805 if (*option == '+')
6806 {
6807 (void) SetImageOption(image_info,option+1,"none");
6808 break;
6809 }
6810 (void) SetImageOption(image_info,option+1,argv[i+1]);
6811 break;
6812 }
6813 if (LocaleCompare("filter",option+1) == 0)
6814 {
6815 if (*option == '+')
6816 {
6817 (void) SetImageOption(image_info,option+1,"undefined");
6818 break;
6819 }
6820 (void) SetImageOption(image_info,option+1,argv[i+1]);
6821 break;
6822 }
6823 if (LocaleCompare("font",option+1) == 0)
6824 {
6825 if (*option == '+')
6826 {
6827 if (image_info->font != (char *) NULL)
6828 image_info->font=DestroyString(image_info->font);
6829 break;
6830 }
6831 (void) CloneString(&image_info->font,argv[i+1]);
6832 break;
6833 }
6834 if (LocaleCompare("format",option+1) == 0)
6835 {
6836 register const char
6837 *q;
6838
6839 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6840 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6841 image_info->ping=MagickFalse;
6842 (void) SetImageOption(image_info,option+1,argv[i+1]);
6843 break;
6844 }
6845 if (LocaleCompare("fuzz",option+1) == 0)
6846 {
6847 if (*option == '+')
6848 {
6849 image_info->fuzz=0.0;
6850 (void) SetImageOption(image_info,option+1,"0");
6851 break;
6852 }
cristyf2f27272009-12-17 14:48:46 +00006853 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006854 1.0);
6855 (void) SetImageOption(image_info,option+1,argv[i+1]);
6856 break;
6857 }
6858 break;
6859 }
6860 case 'g':
6861 {
6862 if (LocaleCompare("gravity",option+1) == 0)
6863 {
6864 if (*option == '+')
6865 {
6866 (void) SetImageOption(image_info,option+1,"undefined");
6867 break;
6868 }
6869 (void) SetImageOption(image_info,option+1,argv[i+1]);
6870 break;
6871 }
6872 if (LocaleCompare("green-primary",option+1) == 0)
6873 {
6874 if (*option == '+')
6875 {
6876 (void) SetImageOption(image_info,option+1,"0.0");
6877 break;
6878 }
6879 (void) SetImageOption(image_info,option+1,argv[i+1]);
6880 break;
6881 }
6882 break;
6883 }
6884 case 'i':
6885 {
6886 if (LocaleCompare("intent",option+1) == 0)
6887 {
6888 if (*option == '+')
6889 {
6890 (void) SetImageOption(image_info,option+1,"undefined");
6891 break;
6892 }
6893 (void) SetImageOption(image_info,option+1,argv[i+1]);
6894 break;
6895 }
6896 if (LocaleCompare("interlace",option+1) == 0)
6897 {
6898 if (*option == '+')
6899 {
6900 image_info->interlace=UndefinedInterlace;
6901 (void) SetImageOption(image_info,option+1,"undefined");
6902 break;
6903 }
6904 image_info->interlace=(InterlaceType) ParseMagickOption(
6905 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6906 (void) SetImageOption(image_info,option+1,argv[i+1]);
6907 break;
6908 }
cristyb32b90a2009-09-07 21:45:48 +00006909 if (LocaleCompare("interline-spacing",option+1) == 0)
6910 {
6911 if (*option == '+')
6912 {
6913 (void) SetImageOption(image_info,option+1,"undefined");
6914 break;
6915 }
6916 (void) SetImageOption(image_info,option+1,argv[i+1]);
6917 break;
6918 }
cristy3ed852e2009-09-05 21:47:34 +00006919 if (LocaleCompare("interpolate",option+1) == 0)
6920 {
6921 if (*option == '+')
6922 {
6923 (void) SetImageOption(image_info,option+1,"undefined");
6924 break;
6925 }
6926 (void) SetImageOption(image_info,option+1,argv[i+1]);
6927 break;
6928 }
6929 if (LocaleCompare("interword-spacing",option+1) == 0)
6930 {
6931 if (*option == '+')
6932 {
6933 (void) SetImageOption(image_info,option+1,"undefined");
6934 break;
6935 }
6936 (void) SetImageOption(image_info,option+1,argv[i+1]);
6937 break;
6938 }
6939 break;
6940 }
6941 case 'k':
6942 {
6943 if (LocaleCompare("kerning",option+1) == 0)
6944 {
6945 if (*option == '+')
6946 {
6947 (void) SetImageOption(image_info,option+1,"undefined");
6948 break;
6949 }
6950 (void) SetImageOption(image_info,option+1,argv[i+1]);
6951 break;
6952 }
6953 break;
6954 }
6955 case 'l':
6956 {
6957 if (LocaleCompare("label",option+1) == 0)
6958 {
6959 if (*option == '+')
6960 {
6961 (void) DeleteImageOption(image_info,option+1);
6962 break;
6963 }
6964 (void) SetImageOption(image_info,option+1,argv[i+1]);
6965 break;
6966 }
6967 if (LocaleCompare("limit",option+1) == 0)
6968 {
6969 MagickSizeType
6970 limit;
6971
6972 ResourceType
6973 type;
6974
6975 if (*option == '+')
6976 break;
6977 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6978 MagickFalse,argv[i+1]);
6979 limit=MagickResourceInfinity;
6980 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006981 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006982 (void) SetMagickResourceLimit(type,limit);
6983 break;
6984 }
6985 if (LocaleCompare("list",option+1) == 0)
6986 {
cristybb503372010-05-27 20:51:26 +00006987 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006988 list;
6989
6990 /*
6991 Display configuration list.
6992 */
6993 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6994 switch (list)
6995 {
6996 case MagickCoderOptions:
6997 {
6998 (void) ListCoderInfo((FILE *) NULL,exception);
6999 break;
7000 }
7001 case MagickColorOptions:
7002 {
7003 (void) ListColorInfo((FILE *) NULL,exception);
7004 break;
7005 }
7006 case MagickConfigureOptions:
7007 {
7008 (void) ListConfigureInfo((FILE *) NULL,exception);
7009 break;
7010 }
7011 case MagickDelegateOptions:
7012 {
7013 (void) ListDelegateInfo((FILE *) NULL,exception);
7014 break;
7015 }
7016 case MagickFontOptions:
7017 {
7018 (void) ListTypeInfo((FILE *) NULL,exception);
7019 break;
7020 }
7021 case MagickFormatOptions:
7022 {
7023 (void) ListMagickInfo((FILE *) NULL,exception);
7024 break;
7025 }
7026 case MagickLocaleOptions:
7027 {
7028 (void) ListLocaleInfo((FILE *) NULL,exception);
7029 break;
7030 }
7031 case MagickLogOptions:
7032 {
7033 (void) ListLogInfo((FILE *) NULL,exception);
7034 break;
7035 }
7036 case MagickMagicOptions:
7037 {
7038 (void) ListMagicInfo((FILE *) NULL,exception);
7039 break;
7040 }
7041 case MagickMimeOptions:
7042 {
7043 (void) ListMimeInfo((FILE *) NULL,exception);
7044 break;
7045 }
7046 case MagickModuleOptions:
7047 {
7048 (void) ListModuleInfo((FILE *) NULL,exception);
7049 break;
7050 }
7051 case MagickPolicyOptions:
7052 {
7053 (void) ListPolicyInfo((FILE *) NULL,exception);
7054 break;
7055 }
7056 case MagickResourceOptions:
7057 {
7058 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7059 break;
7060 }
7061 case MagickThresholdOptions:
7062 {
7063 (void) ListThresholdMaps((FILE *) NULL,exception);
7064 break;
7065 }
7066 default:
7067 {
7068 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7069 exception);
7070 break;
7071 }
7072 }
cristyaeb2cbc2010-05-07 13:28:58 +00007073 break;
cristy3ed852e2009-09-05 21:47:34 +00007074 }
7075 if (LocaleCompare("log",option+1) == 0)
7076 {
7077 if (*option == '+')
7078 break;
7079 (void) SetLogFormat(argv[i+1]);
7080 break;
7081 }
7082 if (LocaleCompare("loop",option+1) == 0)
7083 {
7084 if (*option == '+')
7085 {
7086 (void) SetImageOption(image_info,option+1,"0");
7087 break;
7088 }
7089 (void) SetImageOption(image_info,option+1,argv[i+1]);
7090 break;
7091 }
7092 break;
7093 }
7094 case 'm':
7095 {
7096 if (LocaleCompare("matte",option+1) == 0)
7097 {
7098 if (*option == '+')
7099 {
7100 (void) SetImageOption(image_info,option+1,"false");
7101 break;
7102 }
7103 (void) SetImageOption(image_info,option+1,"true");
7104 break;
7105 }
7106 if (LocaleCompare("mattecolor",option+1) == 0)
7107 {
7108 if (*option == '+')
7109 {
7110 (void) SetImageOption(image_info,option+1,argv[i+1]);
7111 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7112 exception);
7113 break;
7114 }
7115 (void) SetImageOption(image_info,option+1,argv[i+1]);
7116 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7117 exception);
7118 break;
7119 }
7120 if (LocaleCompare("monitor",option+1) == 0)
7121 {
7122 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7123 (void *) NULL);
7124 break;
7125 }
7126 if (LocaleCompare("monochrome",option+1) == 0)
7127 {
7128 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7129 break;
7130 }
7131 break;
7132 }
7133 case 'o':
7134 {
7135 if (LocaleCompare("orient",option+1) == 0)
7136 {
7137 if (*option == '+')
7138 {
7139 image_info->orientation=UndefinedOrientation;
7140 (void) SetImageOption(image_info,option+1,"undefined");
7141 break;
7142 }
7143 image_info->orientation=(OrientationType) ParseMagickOption(
7144 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00007145 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007146 break;
7147 }
7148 }
7149 case 'p':
7150 {
7151 if (LocaleCompare("page",option+1) == 0)
7152 {
7153 char
7154 *canonical_page,
7155 page[MaxTextExtent];
7156
7157 const char
7158 *image_option;
7159
7160 MagickStatusType
7161 flags;
7162
7163 RectangleInfo
7164 geometry;
7165
7166 if (*option == '+')
7167 {
7168 (void) DeleteImageOption(image_info,option+1);
7169 (void) CloneString(&image_info->page,(char *) NULL);
7170 break;
7171 }
7172 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7173 image_option=GetImageOption(image_info,"page");
7174 if (image_option != (const char *) NULL)
7175 flags=ParseAbsoluteGeometry(image_option,&geometry);
7176 canonical_page=GetPageGeometry(argv[i+1]);
7177 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7178 canonical_page=DestroyString(canonical_page);
7179 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00007180 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00007181 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7182 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00007183 (unsigned long) geometry.width,(unsigned long) geometry.height,
7184 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00007185 (void) SetImageOption(image_info,option+1,page);
7186 (void) CloneString(&image_info->page,page);
7187 break;
7188 }
7189 if (LocaleCompare("pen",option+1) == 0)
7190 {
7191 if (*option == '+')
7192 {
7193 (void) SetImageOption(image_info,option+1,"none");
7194 break;
7195 }
7196 (void) SetImageOption(image_info,option+1,argv[i+1]);
7197 break;
7198 }
7199 if (LocaleCompare("ping",option+1) == 0)
7200 {
7201 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7202 break;
7203 }
7204 if (LocaleCompare("pointsize",option+1) == 0)
7205 {
7206 if (*option == '+')
7207 geometry_info.rho=0.0;
7208 else
7209 (void) ParseGeometry(argv[i+1],&geometry_info);
7210 image_info->pointsize=geometry_info.rho;
7211 break;
7212 }
cristye7f51092010-01-17 00:39:37 +00007213 if (LocaleCompare("precision",option+1) == 0)
7214 {
cristybf2766a2010-01-17 03:33:23 +00007215 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007216 break;
7217 }
cristy3ed852e2009-09-05 21:47:34 +00007218 if (LocaleCompare("preview",option+1) == 0)
7219 {
7220 /*
7221 Preview image.
7222 */
7223 if (*option == '+')
7224 {
7225 image_info->preview_type=UndefinedPreview;
7226 break;
7227 }
7228 image_info->preview_type=(PreviewType) ParseMagickOption(
7229 MagickPreviewOptions,MagickFalse,argv[i+1]);
7230 break;
7231 }
7232 break;
7233 }
7234 case 'q':
7235 {
7236 if (LocaleCompare("quality",option+1) == 0)
7237 {
7238 /*
7239 Set image compression quality.
7240 */
7241 if (*option == '+')
7242 {
7243 image_info->quality=UndefinedCompressionQuality;
7244 (void) SetImageOption(image_info,option+1,"0");
7245 break;
7246 }
cristye27293e2009-12-18 02:53:20 +00007247 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007248 (void) SetImageOption(image_info,option+1,argv[i+1]);
7249 break;
7250 }
7251 if (LocaleCompare("quiet",option+1) == 0)
7252 {
7253 static WarningHandler
7254 warning_handler = (WarningHandler) NULL;
7255
7256 if (*option == '+')
7257 {
7258 /*
7259 Restore error or warning messages.
7260 */
7261 warning_handler=SetWarningHandler(warning_handler);
7262 break;
7263 }
7264 /*
7265 Suppress error or warning messages.
7266 */
7267 warning_handler=SetWarningHandler((WarningHandler) NULL);
7268 break;
7269 }
7270 break;
7271 }
7272 case 'r':
7273 {
7274 if (LocaleCompare("red-primary",option+1) == 0)
7275 {
7276 if (*option == '+')
7277 {
7278 (void) SetImageOption(image_info,option+1,"0.0");
7279 break;
7280 }
7281 (void) SetImageOption(image_info,option+1,argv[i+1]);
7282 break;
7283 }
7284 break;
7285 }
7286 case 's':
7287 {
7288 if (LocaleCompare("sampling-factor",option+1) == 0)
7289 {
7290 /*
7291 Set image sampling factor.
7292 */
7293 if (*option == '+')
7294 {
7295 if (image_info->sampling_factor != (char *) NULL)
7296 image_info->sampling_factor=DestroyString(
7297 image_info->sampling_factor);
7298 break;
7299 }
7300 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7301 break;
7302 }
7303 if (LocaleCompare("scene",option+1) == 0)
7304 {
7305 /*
7306 Set image scene.
7307 */
7308 if (*option == '+')
7309 {
7310 image_info->scene=0;
7311 (void) SetImageOption(image_info,option+1,"0");
7312 break;
7313 }
cristye27293e2009-12-18 02:53:20 +00007314 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007315 (void) SetImageOption(image_info,option+1,argv[i+1]);
7316 break;
7317 }
7318 if (LocaleCompare("seed",option+1) == 0)
7319 {
cristybb503372010-05-27 20:51:26 +00007320 size_t
cristy3ed852e2009-09-05 21:47:34 +00007321 seed;
7322
7323 if (*option == '+')
7324 {
cristybb503372010-05-27 20:51:26 +00007325 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007326 SeedPseudoRandomGenerator(seed);
7327 break;
7328 }
cristye27293e2009-12-18 02:53:20 +00007329 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007330 SeedPseudoRandomGenerator(seed);
7331 break;
7332 }
7333 if (LocaleCompare("size",option+1) == 0)
7334 {
7335 if (*option == '+')
7336 {
7337 if (image_info->size != (char *) NULL)
7338 image_info->size=DestroyString(image_info->size);
7339 break;
7340 }
7341 (void) CloneString(&image_info->size,argv[i+1]);
7342 break;
7343 }
7344 if (LocaleCompare("stroke",option+1) == 0)
7345 {
7346 if (*option == '+')
7347 {
7348 (void) SetImageOption(image_info,option+1,"none");
7349 break;
7350 }
7351 (void) SetImageOption(image_info,option+1,argv[i+1]);
7352 break;
7353 }
7354 if (LocaleCompare("strokewidth",option+1) == 0)
7355 {
7356 if (*option == '+')
7357 {
7358 (void) SetImageOption(image_info,option+1,"0");
7359 break;
7360 }
7361 (void) SetImageOption(image_info,option+1,argv[i+1]);
7362 break;
7363 }
cristyd9a29192010-10-16 16:49:53 +00007364 if (LocaleCompare("synchronize",option+1) == 0)
7365 {
7366 if (*option == '+')
7367 {
7368 image_info->synchronize=MagickFalse;
7369 break;
7370 }
7371 image_info->synchronize=MagickTrue;
7372 break;
7373 }
cristy3ed852e2009-09-05 21:47:34 +00007374 break;
7375 }
7376 case 't':
7377 {
7378 if (LocaleCompare("taint",option+1) == 0)
7379 {
7380 if (*option == '+')
7381 {
7382 (void) SetImageOption(image_info,option+1,"false");
7383 break;
7384 }
7385 (void) SetImageOption(image_info,option+1,"true");
7386 break;
7387 }
7388 if (LocaleCompare("texture",option+1) == 0)
7389 {
7390 if (*option == '+')
7391 {
7392 if (image_info->texture != (char *) NULL)
7393 image_info->texture=DestroyString(image_info->texture);
7394 break;
7395 }
7396 (void) CloneString(&image_info->texture,argv[i+1]);
7397 break;
7398 }
7399 if (LocaleCompare("tile-offset",option+1) == 0)
7400 {
7401 if (*option == '+')
7402 {
7403 (void) SetImageOption(image_info,option+1,"0");
7404 break;
7405 }
7406 (void) SetImageOption(image_info,option+1,argv[i+1]);
7407 break;
7408 }
7409 if (LocaleCompare("transparent-color",option+1) == 0)
7410 {
7411 if (*option == '+')
7412 {
7413 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7414 (void) SetImageOption(image_info,option+1,"none");
7415 break;
7416 }
7417 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7418 exception);
7419 (void) SetImageOption(image_info,option+1,argv[i+1]);
7420 break;
7421 }
7422 if (LocaleCompare("type",option+1) == 0)
7423 {
7424 if (*option == '+')
7425 {
cristy5f1c1ff2010-12-23 21:38:06 +00007426 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007427 (void) SetImageOption(image_info,option+1,"undefined");
7428 break;
7429 }
7430 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7431 MagickFalse,argv[i+1]);
7432 (void) SetImageOption(image_info,option+1,argv[i+1]);
7433 break;
7434 }
7435 break;
7436 }
7437 case 'u':
7438 {
7439 if (LocaleCompare("undercolor",option+1) == 0)
7440 {
7441 if (*option == '+')
7442 {
7443 (void) DeleteImageOption(image_info,option+1);
7444 break;
7445 }
7446 (void) SetImageOption(image_info,option+1,argv[i+1]);
7447 break;
7448 }
7449 if (LocaleCompare("units",option+1) == 0)
7450 {
7451 if (*option == '+')
7452 {
7453 image_info->units=UndefinedResolution;
7454 (void) SetImageOption(image_info,option+1,"undefined");
7455 break;
7456 }
7457 image_info->units=(ResolutionType) ParseMagickOption(
7458 MagickResolutionOptions,MagickFalse,argv[i+1]);
7459 (void) SetImageOption(image_info,option+1,argv[i+1]);
7460 break;
7461 }
7462 break;
7463 }
7464 case 'v':
7465 {
7466 if (LocaleCompare("verbose",option+1) == 0)
7467 {
7468 if (*option == '+')
7469 {
7470 image_info->verbose=MagickFalse;
7471 break;
7472 }
7473 image_info->verbose=MagickTrue;
7474 image_info->ping=MagickFalse;
7475 break;
7476 }
7477 if (LocaleCompare("view",option+1) == 0)
7478 {
7479 if (*option == '+')
7480 {
7481 if (image_info->view != (char *) NULL)
7482 image_info->view=DestroyString(image_info->view);
7483 break;
7484 }
7485 (void) CloneString(&image_info->view,argv[i+1]);
7486 break;
7487 }
7488 if (LocaleCompare("virtual-pixel",option+1) == 0)
7489 {
7490 if (*option == '+')
7491 {
7492 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7493 (void) SetImageOption(image_info,option+1,"undefined");
7494 break;
7495 }
7496 image_info->virtual_pixel_method=(VirtualPixelMethod)
7497 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7498 argv[i+1]);
7499 (void) SetImageOption(image_info,option+1,argv[i+1]);
7500 break;
7501 }
7502 break;
7503 }
7504 case 'w':
7505 {
7506 if (LocaleCompare("white-point",option+1) == 0)
7507 {
7508 if (*option == '+')
7509 {
7510 (void) SetImageOption(image_info,option+1,"0.0");
7511 break;
7512 }
7513 (void) SetImageOption(image_info,option+1,argv[i+1]);
7514 break;
7515 }
7516 break;
7517 }
7518 default:
7519 break;
7520 }
7521 i+=count;
7522 }
7523 return(MagickTrue);
7524}
7525
7526/*
7527%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7528% %
7529% %
7530% %
7531+ M o g r i f y I m a g e L i s t %
7532% %
7533% %
7534% %
7535%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7536%
7537% MogrifyImageList() applies any command line options that might affect the
7538% entire image list (e.g. -append, -coalesce, etc.).
7539%
7540% The format of the MogrifyImage method is:
7541%
7542% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7543% const char **argv,Image **images,ExceptionInfo *exception)
7544%
7545% A description of each parameter follows:
7546%
7547% o image_info: the image info..
7548%
7549% o argc: Specifies a pointer to an integer describing the number of
7550% elements in the argument vector.
7551%
7552% o argv: Specifies a pointer to a text array containing the command line
7553% arguments.
7554%
7555% o images: the images.
7556%
7557% o exception: return any errors or warnings in this structure.
7558%
7559*/
7560WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7561 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7562{
7563 ChannelType
7564 channel;
7565
7566 const char
7567 *option;
7568
cristy6b3da3a2010-06-20 02:21:46 +00007569 ImageInfo
7570 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007571
7572 MagickStatusType
7573 status;
7574
7575 QuantizeInfo
7576 *quantize_info;
7577
cristybb503372010-05-27 20:51:26 +00007578 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007579 i;
7580
cristy6b3da3a2010-06-20 02:21:46 +00007581 ssize_t
7582 count,
7583 index;
7584
cristy3ed852e2009-09-05 21:47:34 +00007585 /*
7586 Apply options to the image list.
7587 */
7588 assert(image_info != (ImageInfo *) NULL);
7589 assert(image_info->signature == MagickSignature);
7590 assert(images != (Image **) NULL);
7591 assert((*images)->signature == MagickSignature);
7592 if ((*images)->debug != MagickFalse)
7593 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7594 (*images)->filename);
7595 if ((argc <= 0) || (*argv == (char *) NULL))
7596 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007597 mogrify_info=CloneImageInfo(image_info);
7598 quantize_info=AcquireQuantizeInfo(mogrify_info);
7599 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007600 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007601 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007602 {
cristy74fe8f12009-10-03 19:09:01 +00007603 if (*images == (Image *) NULL)
7604 break;
cristy3ed852e2009-09-05 21:47:34 +00007605 option=argv[i];
7606 if (IsMagickOption(option) == MagickFalse)
7607 continue;
7608 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7609 0L);
cristycee97112010-05-28 00:44:52 +00007610 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007611 break;
cristy6b3da3a2010-06-20 02:21:46 +00007612 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007613 switch (*(option+1))
7614 {
7615 case 'a':
7616 {
7617 if (LocaleCompare("affinity",option+1) == 0)
7618 {
cristy6b3da3a2010-06-20 02:21:46 +00007619 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007620 if (*option == '+')
7621 {
7622 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7623 InheritException(exception,&(*images)->exception);
7624 break;
7625 }
7626 i++;
7627 break;
7628 }
7629 if (LocaleCompare("append",option+1) == 0)
7630 {
7631 Image
7632 *append_image;
7633
cristy6b3da3a2010-06-20 02:21:46 +00007634 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007635 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7636 MagickFalse,exception);
7637 if (append_image == (Image *) NULL)
7638 {
7639 status=MagickFalse;
7640 break;
7641 }
7642 *images=DestroyImageList(*images);
7643 *images=append_image;
7644 break;
7645 }
7646 if (LocaleCompare("average",option+1) == 0)
7647 {
7648 Image
7649 *average_image;
7650
cristyd18ae7c2010-03-07 17:39:52 +00007651 /*
7652 Average an image sequence (deprecated).
7653 */
cristy6b3da3a2010-06-20 02:21:46 +00007654 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007655 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7656 exception);
cristy3ed852e2009-09-05 21:47:34 +00007657 if (average_image == (Image *) NULL)
7658 {
7659 status=MagickFalse;
7660 break;
7661 }
7662 *images=DestroyImageList(*images);
7663 *images=average_image;
7664 break;
7665 }
7666 break;
7667 }
7668 case 'c':
7669 {
7670 if (LocaleCompare("channel",option+1) == 0)
7671 {
7672 if (*option == '+')
7673 {
7674 channel=DefaultChannels;
7675 break;
7676 }
7677 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7678 break;
7679 }
7680 if (LocaleCompare("clut",option+1) == 0)
7681 {
7682 Image
7683 *clut_image,
7684 *image;
7685
cristy6b3da3a2010-06-20 02:21:46 +00007686 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007687 image=RemoveFirstImageFromList(images);
7688 clut_image=RemoveFirstImageFromList(images);
7689 if (clut_image == (Image *) NULL)
7690 {
7691 status=MagickFalse;
7692 break;
7693 }
7694 (void) ClutImageChannel(image,channel,clut_image);
7695 clut_image=DestroyImage(clut_image);
7696 InheritException(exception,&image->exception);
7697 *images=DestroyImageList(*images);
7698 *images=image;
7699 break;
7700 }
7701 if (LocaleCompare("coalesce",option+1) == 0)
7702 {
7703 Image
7704 *coalesce_image;
7705
cristy6b3da3a2010-06-20 02:21:46 +00007706 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007707 coalesce_image=CoalesceImages(*images,exception);
7708 if (coalesce_image == (Image *) NULL)
7709 {
7710 status=MagickFalse;
7711 break;
7712 }
7713 *images=DestroyImageList(*images);
7714 *images=coalesce_image;
7715 break;
7716 }
7717 if (LocaleCompare("combine",option+1) == 0)
7718 {
7719 Image
7720 *combine_image;
7721
cristy6b3da3a2010-06-20 02:21:46 +00007722 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007723 combine_image=CombineImages(*images,channel,exception);
7724 if (combine_image == (Image *) NULL)
7725 {
7726 status=MagickFalse;
7727 break;
7728 }
7729 *images=DestroyImageList(*images);
7730 *images=combine_image;
7731 break;
7732 }
7733 if (LocaleCompare("composite",option+1) == 0)
7734 {
7735 Image
7736 *mask_image,
7737 *composite_image,
7738 *image;
7739
7740 RectangleInfo
7741 geometry;
7742
cristy6b3da3a2010-06-20 02:21:46 +00007743 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007744 image=RemoveFirstImageFromList(images);
7745 composite_image=RemoveFirstImageFromList(images);
7746 if (composite_image == (Image *) NULL)
7747 {
7748 status=MagickFalse;
7749 break;
7750 }
7751 (void) TransformImage(&composite_image,(char *) NULL,
7752 composite_image->geometry);
7753 SetGeometry(composite_image,&geometry);
7754 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7755 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7756 &geometry);
7757 mask_image=RemoveFirstImageFromList(images);
7758 if (mask_image != (Image *) NULL)
7759 {
7760 if ((image->compose == DisplaceCompositeOp) ||
7761 (image->compose == DistortCompositeOp))
7762 {
7763 /*
7764 Merge Y displacement into X displacement image.
7765 */
7766 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7767 mask_image,0,0);
7768 mask_image=DestroyImage(mask_image);
7769 }
7770 else
7771 {
7772 /*
7773 Set a blending mask for the composition.
7774 */
7775 image->mask=mask_image;
7776 (void) NegateImage(image->mask,MagickFalse);
7777 }
7778 }
7779 (void) CompositeImageChannel(image,channel,image->compose,
7780 composite_image,geometry.x,geometry.y);
7781 if (image->mask != (Image *) NULL)
7782 image->mask=DestroyImage(image->mask);
7783 composite_image=DestroyImage(composite_image);
7784 InheritException(exception,&image->exception);
7785 *images=DestroyImageList(*images);
7786 *images=image;
7787 break;
7788 }
7789 if (LocaleCompare("crop",option+1) == 0)
7790 {
7791 MagickStatusType
7792 flags;
7793
7794 RectangleInfo
7795 geometry;
7796
cristy6b3da3a2010-06-20 02:21:46 +00007797 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007798 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7799 if (((geometry.width == 0) && (geometry.height == 0)) ||
7800 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7801 break;
7802 (void) TransformImages(images,argv[i+1],(char *) NULL);
7803 InheritException(exception,&(*images)->exception);
7804 break;
7805 }
7806 break;
7807 }
7808 case 'd':
7809 {
7810 if (LocaleCompare("deconstruct",option+1) == 0)
7811 {
7812 Image
7813 *deconstruct_image;
7814
cristy6b3da3a2010-06-20 02:21:46 +00007815 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007816 deconstruct_image=DeconstructImages(*images,exception);
7817 if (deconstruct_image == (Image *) NULL)
7818 {
7819 status=MagickFalse;
7820 break;
7821 }
7822 *images=DestroyImageList(*images);
7823 *images=deconstruct_image;
7824 break;
7825 }
7826 if (LocaleCompare("delete",option+1) == 0)
7827 {
7828 if (*option == '+')
7829 DeleteImages(images,"-1",exception);
7830 else
7831 DeleteImages(images,argv[i+1],exception);
7832 break;
7833 }
7834 if (LocaleCompare("dither",option+1) == 0)
7835 {
7836 if (*option == '+')
7837 {
7838 quantize_info->dither=MagickFalse;
7839 break;
7840 }
7841 quantize_info->dither=MagickTrue;
7842 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7843 MagickDitherOptions,MagickFalse,argv[i+1]);
7844 break;
7845 }
7846 break;
7847 }
cristyd18ae7c2010-03-07 17:39:52 +00007848 case 'e':
7849 {
7850 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7851 {
7852 Image
7853 *evaluate_image;
7854
7855 MagickEvaluateOperator
7856 op;
7857
cristy6b3da3a2010-06-20 02:21:46 +00007858 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007859 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7860 MagickFalse,argv[i+1]);
7861 evaluate_image=EvaluateImages(*images,op,exception);
7862 if (evaluate_image == (Image *) NULL)
7863 {
7864 status=MagickFalse;
7865 break;
7866 }
7867 *images=DestroyImageList(*images);
7868 *images=evaluate_image;
7869 break;
7870 }
7871 break;
7872 }
cristy3ed852e2009-09-05 21:47:34 +00007873 case 'f':
7874 {
cristyf0a247f2009-10-04 00:20:03 +00007875 if (LocaleCompare("fft",option+1) == 0)
7876 {
7877 Image
7878 *fourier_image;
7879
7880 /*
7881 Implements the discrete Fourier transform (DFT).
7882 */
cristy6b3da3a2010-06-20 02:21:46 +00007883 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007884 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7885 MagickTrue : MagickFalse,exception);
7886 if (fourier_image == (Image *) NULL)
7887 break;
7888 *images=DestroyImage(*images);
7889 *images=fourier_image;
7890 break;
7891 }
cristy3ed852e2009-09-05 21:47:34 +00007892 if (LocaleCompare("flatten",option+1) == 0)
7893 {
7894 Image
7895 *flatten_image;
7896
cristy6b3da3a2010-06-20 02:21:46 +00007897 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007898 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7899 if (flatten_image == (Image *) NULL)
7900 break;
7901 *images=DestroyImageList(*images);
7902 *images=flatten_image;
7903 break;
7904 }
7905 if (LocaleCompare("fx",option+1) == 0)
7906 {
7907 Image
7908 *fx_image;
7909
cristy6b3da3a2010-06-20 02:21:46 +00007910 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007911 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7912 if (fx_image == (Image *) NULL)
7913 {
7914 status=MagickFalse;
7915 break;
7916 }
7917 *images=DestroyImageList(*images);
7918 *images=fx_image;
7919 break;
7920 }
7921 break;
7922 }
7923 case 'h':
7924 {
7925 if (LocaleCompare("hald-clut",option+1) == 0)
7926 {
7927 Image
7928 *hald_image,
7929 *image;
7930
cristy6b3da3a2010-06-20 02:21:46 +00007931 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007932 image=RemoveFirstImageFromList(images);
7933 hald_image=RemoveFirstImageFromList(images);
7934 if (hald_image == (Image *) NULL)
7935 {
7936 status=MagickFalse;
7937 break;
7938 }
7939 (void) HaldClutImageChannel(image,channel,hald_image);
7940 hald_image=DestroyImage(hald_image);
7941 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007942 if (*images != (Image *) NULL)
7943 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007944 *images=image;
7945 break;
7946 }
7947 break;
7948 }
7949 case 'i':
7950 {
7951 if (LocaleCompare("ift",option+1) == 0)
7952 {
7953 Image
cristy8587f882009-11-13 20:28:49 +00007954 *fourier_image,
7955 *magnitude_image,
7956 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007957
7958 /*
7959 Implements the inverse fourier discrete Fourier transform (DFT).
7960 */
cristy6b3da3a2010-06-20 02:21:46 +00007961 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007962 magnitude_image=RemoveFirstImageFromList(images);
7963 phase_image=RemoveFirstImageFromList(images);
7964 if (phase_image == (Image *) NULL)
7965 {
7966 status=MagickFalse;
7967 break;
7968 }
7969 fourier_image=InverseFourierTransformImage(magnitude_image,
7970 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007971 if (fourier_image == (Image *) NULL)
7972 break;
cristy0aff6ea2009-11-14 01:40:53 +00007973 if (*images != (Image *) NULL)
7974 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007975 *images=fourier_image;
7976 break;
7977 }
7978 if (LocaleCompare("insert",option+1) == 0)
7979 {
7980 Image
7981 *p,
7982 *q;
7983
7984 index=0;
7985 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007986 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007987 p=RemoveLastImageFromList(images);
7988 if (p == (Image *) NULL)
7989 {
7990 (void) ThrowMagickException(exception,GetMagickModule(),
7991 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7992 status=MagickFalse;
7993 break;
7994 }
7995 q=p;
7996 if (index == 0)
7997 PrependImageToList(images,q);
7998 else
cristybb503372010-05-27 20:51:26 +00007999 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00008000 AppendImageToList(images,q);
8001 else
8002 {
8003 q=GetImageFromList(*images,index-1);
8004 if (q == (Image *) NULL)
8005 {
8006 (void) ThrowMagickException(exception,GetMagickModule(),
8007 OptionError,"NoSuchImage","`%s'",argv[i+1]);
8008 status=MagickFalse;
8009 break;
8010 }
8011 InsertImageInList(&q,p);
8012 }
8013 *images=GetFirstImageInList(q);
8014 break;
8015 }
8016 break;
8017 }
8018 case 'l':
8019 {
8020 if (LocaleCompare("layers",option+1) == 0)
8021 {
8022 Image
8023 *layers;
8024
8025 ImageLayerMethod
8026 method;
8027
cristy6b3da3a2010-06-20 02:21:46 +00008028 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008029 layers=(Image *) NULL;
8030 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8031 MagickFalse,argv[i+1]);
8032 switch (method)
8033 {
8034 case CoalesceLayer:
8035 {
8036 layers=CoalesceImages(*images,exception);
8037 break;
8038 }
8039 case CompareAnyLayer:
8040 case CompareClearLayer:
8041 case CompareOverlayLayer:
8042 default:
8043 {
8044 layers=CompareImageLayers(*images,method,exception);
8045 break;
8046 }
8047 case MergeLayer:
8048 case FlattenLayer:
8049 case MosaicLayer:
8050 case TrimBoundsLayer:
8051 {
8052 layers=MergeImageLayers(*images,method,exception);
8053 break;
8054 }
8055 case DisposeLayer:
8056 {
8057 layers=DisposeImages(*images,exception);
8058 break;
8059 }
8060 case OptimizeImageLayer:
8061 {
8062 layers=OptimizeImageLayers(*images,exception);
8063 break;
8064 }
8065 case OptimizePlusLayer:
8066 {
8067 layers=OptimizePlusImageLayers(*images,exception);
8068 break;
8069 }
8070 case OptimizeTransLayer:
8071 {
8072 OptimizeImageTransparency(*images,exception);
8073 break;
8074 }
8075 case RemoveDupsLayer:
8076 {
8077 RemoveDuplicateLayers(images,exception);
8078 break;
8079 }
8080 case RemoveZeroLayer:
8081 {
8082 RemoveZeroDelayLayers(images,exception);
8083 break;
8084 }
8085 case OptimizeLayer:
8086 {
8087 /*
8088 General Purpose, GIF Animation Optimizer.
8089 */
8090 layers=CoalesceImages(*images,exception);
8091 if (layers == (Image *) NULL)
8092 {
8093 status=MagickFalse;
8094 break;
8095 }
8096 InheritException(exception,&layers->exception);
8097 *images=DestroyImageList(*images);
8098 *images=layers;
8099 layers=OptimizeImageLayers(*images,exception);
8100 if (layers == (Image *) NULL)
8101 {
8102 status=MagickFalse;
8103 break;
8104 }
8105 InheritException(exception,&layers->exception);
8106 *images=DestroyImageList(*images);
8107 *images=layers;
8108 layers=(Image *) NULL;
8109 OptimizeImageTransparency(*images,exception);
8110 InheritException(exception,&(*images)->exception);
8111 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8112 break;
8113 }
8114 case CompositeLayer:
8115 {
8116 CompositeOperator
8117 compose;
8118
8119 Image
8120 *source;
8121
8122 RectangleInfo
8123 geometry;
8124
8125 /*
8126 Split image sequence at the first 'NULL:' image.
8127 */
8128 source=(*images);
8129 while (source != (Image *) NULL)
8130 {
8131 source=GetNextImageInList(source);
8132 if ((source != (Image *) NULL) &&
8133 (LocaleCompare(source->magick,"NULL") == 0))
8134 break;
8135 }
8136 if (source != (Image *) NULL)
8137 {
8138 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8139 (GetNextImageInList(source) == (Image *) NULL))
8140 source=(Image *) NULL;
8141 else
8142 {
8143 /*
8144 Separate the two lists, junk the null: image.
8145 */
8146 source=SplitImageList(source->previous);
8147 DeleteImageFromList(&source);
8148 }
8149 }
8150 if (source == (Image *) NULL)
8151 {
8152 (void) ThrowMagickException(exception,GetMagickModule(),
8153 OptionError,"MissingNullSeparator","layers Composite");
8154 status=MagickFalse;
8155 break;
8156 }
8157 /*
8158 Adjust offset with gravity and virtual canvas.
8159 */
8160 SetGeometry(*images,&geometry);
8161 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8162 geometry.width=source->page.width != 0 ?
8163 source->page.width : source->columns;
8164 geometry.height=source->page.height != 0 ?
8165 source->page.height : source->rows;
8166 GravityAdjustGeometry((*images)->page.width != 0 ?
8167 (*images)->page.width : (*images)->columns,
8168 (*images)->page.height != 0 ? (*images)->page.height :
8169 (*images)->rows,(*images)->gravity,&geometry);
8170 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00008171 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00008172 if (option != (const char *) NULL)
8173 compose=(CompositeOperator) ParseMagickOption(
8174 MagickComposeOptions,MagickFalse,option);
8175 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8176 exception);
8177 source=DestroyImageList(source);
8178 break;
8179 }
8180 }
8181 if (layers == (Image *) NULL)
8182 break;
8183 InheritException(exception,&layers->exception);
8184 *images=DestroyImageList(*images);
8185 *images=layers;
8186 break;
8187 }
8188 break;
8189 }
8190 case 'm':
8191 {
8192 if (LocaleCompare("map",option+1) == 0)
8193 {
cristy6b3da3a2010-06-20 02:21:46 +00008194 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008195 if (*option == '+')
8196 {
8197 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8198 InheritException(exception,&(*images)->exception);
8199 break;
8200 }
8201 i++;
8202 break;
8203 }
cristyf40785b2010-03-06 02:27:27 +00008204 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008205 {
8206 Image
cristyf40785b2010-03-06 02:27:27 +00008207 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008208
cristyd18ae7c2010-03-07 17:39:52 +00008209 /*
8210 Maximum image sequence (deprecated).
8211 */
cristy6b3da3a2010-06-20 02:21:46 +00008212 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008213 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008214 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008215 {
8216 status=MagickFalse;
8217 break;
8218 }
8219 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008220 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008221 break;
8222 }
cristyf40785b2010-03-06 02:27:27 +00008223 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008224 {
8225 Image
cristyf40785b2010-03-06 02:27:27 +00008226 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008227
cristyd18ae7c2010-03-07 17:39:52 +00008228 /*
8229 Minimum image sequence (deprecated).
8230 */
cristy6b3da3a2010-06-20 02:21:46 +00008231 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008232 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008233 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008234 {
8235 status=MagickFalse;
8236 break;
8237 }
8238 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008239 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008240 break;
8241 }
cristy3ed852e2009-09-05 21:47:34 +00008242 if (LocaleCompare("morph",option+1) == 0)
8243 {
8244 Image
8245 *morph_image;
8246
cristy6b3da3a2010-06-20 02:21:46 +00008247 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00008248 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008249 exception);
8250 if (morph_image == (Image *) NULL)
8251 {
8252 status=MagickFalse;
8253 break;
8254 }
8255 *images=DestroyImageList(*images);
8256 *images=morph_image;
8257 break;
8258 }
8259 if (LocaleCompare("mosaic",option+1) == 0)
8260 {
8261 Image
8262 *mosaic_image;
8263
cristy6b3da3a2010-06-20 02:21:46 +00008264 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008265 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8266 if (mosaic_image == (Image *) NULL)
8267 {
8268 status=MagickFalse;
8269 break;
8270 }
8271 *images=DestroyImageList(*images);
8272 *images=mosaic_image;
8273 break;
8274 }
8275 break;
8276 }
8277 case 'p':
8278 {
8279 if (LocaleCompare("print",option+1) == 0)
8280 {
8281 char
8282 *string;
8283
cristy6b3da3a2010-06-20 02:21:46 +00008284 (void) SyncImagesSettings(mogrify_info,*images);
8285 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008286 if (string == (char *) NULL)
8287 break;
8288 InheritException(exception,&(*images)->exception);
8289 (void) fprintf(stdout,"%s",string);
8290 string=DestroyString(string);
8291 }
8292 if (LocaleCompare("process",option+1) == 0)
8293 {
8294 char
8295 **arguments;
8296
8297 int
8298 j,
8299 number_arguments;
8300
cristy6b3da3a2010-06-20 02:21:46 +00008301 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008302 arguments=StringToArgv(argv[i+1],&number_arguments);
8303 if (arguments == (char **) NULL)
8304 break;
8305 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8306 {
8307 char
8308 breaker,
8309 quote,
8310 *token;
8311
8312 const char
8313 *arguments;
8314
8315 int
8316 next,
8317 status;
8318
8319 size_t
8320 length;
8321
8322 TokenInfo
8323 *token_info;
8324
8325 /*
8326 Support old style syntax, filter="-option arg".
8327 */
8328 length=strlen(argv[i+1]);
8329 token=(char *) NULL;
8330 if (~length >= MaxTextExtent)
8331 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8332 sizeof(*token));
8333 if (token == (char *) NULL)
8334 break;
8335 next=0;
8336 arguments=argv[i+1];
8337 token_info=AcquireTokenInfo();
8338 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8339 "\"",'\0',&breaker,&next,&quote);
8340 token_info=DestroyTokenInfo(token_info);
8341 if (status == 0)
8342 {
8343 const char
8344 *argv;
8345
8346 argv=(&(arguments[next]));
8347 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8348 exception);
8349 }
8350 token=DestroyString(token);
8351 break;
8352 }
cristy91c0da22010-05-02 01:44:07 +00008353 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008354 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8355 number_arguments-2,(const char **) arguments+2,exception);
8356 for (j=0; j < number_arguments; j++)
8357 arguments[j]=DestroyString(arguments[j]);
8358 arguments=(char **) RelinquishMagickMemory(arguments);
8359 break;
8360 }
8361 break;
8362 }
8363 case 'r':
8364 {
8365 if (LocaleCompare("reverse",option+1) == 0)
8366 {
8367 ReverseImageList(images);
8368 InheritException(exception,&(*images)->exception);
8369 break;
8370 }
8371 break;
8372 }
8373 case 's':
8374 {
cristy4285d782011-02-09 20:12:28 +00008375 if (LocaleCompare("smush",option+1) == 0)
8376 {
8377 Image
8378 *smush_image;
8379
8380 ssize_t
8381 offset;
8382
8383 (void) SyncImagesSettings(mogrify_info,*images);
8384 offset=(ssize_t) StringToLong(argv[i+1]);
8385 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8386 MagickFalse,offset,exception);
8387 if (smush_image == (Image *) NULL)
8388 {
8389 status=MagickFalse;
8390 break;
8391 }
8392 *images=DestroyImageList(*images);
8393 *images=smush_image;
8394 break;
8395 }
cristy3ed852e2009-09-05 21:47:34 +00008396 if (LocaleCompare("swap",option+1) == 0)
8397 {
8398 Image
8399 *p,
8400 *q,
8401 *swap;
8402
cristybb503372010-05-27 20:51:26 +00008403 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008404 swap_index;
8405
8406 index=(-1);
8407 swap_index=(-2);
8408 if (*option != '+')
8409 {
8410 GeometryInfo
8411 geometry_info;
8412
8413 MagickStatusType
8414 flags;
8415
8416 swap_index=(-1);
8417 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008418 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008419 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008420 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008421 }
8422 p=GetImageFromList(*images,index);
8423 q=GetImageFromList(*images,swap_index);
8424 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8425 {
8426 (void) ThrowMagickException(exception,GetMagickModule(),
8427 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8428 status=MagickFalse;
8429 break;
8430 }
8431 if (p == q)
8432 break;
8433 swap=CloneImage(p,0,0,MagickTrue,exception);
8434 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8435 ReplaceImageInList(&q,swap);
8436 *images=GetFirstImageInList(q);
8437 break;
8438 }
8439 break;
8440 }
8441 case 'w':
8442 {
8443 if (LocaleCompare("write",option+1) == 0)
8444 {
cristy071dd7b2010-04-09 13:04:54 +00008445 char
cristy06609ee2010-03-17 20:21:27 +00008446 key[MaxTextExtent];
8447
cristy3ed852e2009-09-05 21:47:34 +00008448 Image
8449 *write_images;
8450
8451 ImageInfo
8452 *write_info;
8453
cristy6b3da3a2010-06-20 02:21:46 +00008454 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008455 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8456 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008457 write_images=(*images);
8458 if (*option == '+')
8459 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008460 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008461 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8462 write_info=DestroyImageInfo(write_info);
8463 if (*option == '+')
8464 write_images=DestroyImageList(write_images);
8465 break;
8466 }
8467 break;
8468 }
8469 default:
8470 break;
8471 }
8472 i+=count;
8473 }
8474 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008475 mogrify_info=DestroyImageInfo(mogrify_info);
8476 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008477 return(status != 0 ? MagickTrue : MagickFalse);
8478}
8479
8480/*
8481%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8482% %
8483% %
8484% %
8485+ M o g r i f y I m a g e s %
8486% %
8487% %
8488% %
8489%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8490%
8491% MogrifyImages() applies image processing options to a sequence of images as
8492% prescribed by command line options.
8493%
8494% The format of the MogrifyImage method is:
8495%
8496% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8497% const MagickBooleanType post,const int argc,const char **argv,
8498% Image **images,Exceptioninfo *exception)
8499%
8500% A description of each parameter follows:
8501%
8502% o image_info: the image info..
8503%
8504% o post: If true, post process image list operators otherwise pre-process.
8505%
8506% o argc: Specifies a pointer to an integer describing the number of
8507% elements in the argument vector.
8508%
8509% o argv: Specifies a pointer to a text array containing the command line
8510% arguments.
8511%
8512% o images: the images.
8513%
8514% o exception: return any errors or warnings in this structure.
8515%
8516*/
8517WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8518 const MagickBooleanType post,const int argc,const char **argv,
8519 Image **images,ExceptionInfo *exception)
8520{
8521#define MogrifyImageTag "Mogrify/Image"
8522
8523 Image
8524 *image,
8525 *mogrify_images;
8526
cristy0e9f9c12010-02-11 03:00:47 +00008527 MagickBooleanType
8528 proceed;
8529
8530 MagickSizeType
8531 number_images;
8532
cristy3ed852e2009-09-05 21:47:34 +00008533 MagickStatusType
8534 status;
8535
cristybb503372010-05-27 20:51:26 +00008536 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008537 i;
8538
cristy3ed852e2009-09-05 21:47:34 +00008539 /*
8540 Apply options to individual images in the list.
8541 */
8542 assert(image_info != (ImageInfo *) NULL);
8543 assert(image_info->signature == MagickSignature);
8544 if (images == (Image **) NULL)
8545 return(MogrifyImage(image_info,argc,argv,images,exception));
8546 assert((*images)->signature == MagickSignature);
8547 if ((*images)->debug != MagickFalse)
8548 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8549 (*images)->filename);
8550 if ((argc <= 0) || (*argv == (char *) NULL))
8551 return(MagickTrue);
8552 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8553 (void *) NULL);
8554 mogrify_images=NewImageList();
8555 number_images=GetImageListLength(*images);
8556 status=0;
8557 if (post == MagickFalse)
8558 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristybb503372010-05-27 20:51:26 +00008559 for (i=0; i < (ssize_t) number_images; i++)
cristy3ed852e2009-09-05 21:47:34 +00008560 {
8561 image=RemoveFirstImageFromList(images);
8562 if (image == (Image *) NULL)
8563 continue;
8564 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8565 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008566 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8567 number_images);
8568 if (proceed == MagickFalse)
8569 break;
cristy3ed852e2009-09-05 21:47:34 +00008570 }
8571 if (post != MagickFalse)
8572 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8573 *images=mogrify_images;
8574 return(status != 0 ? MagickTrue : MagickFalse);
8575}