blob: 2275532f18e8548eab4a925845cc4f0ef0e3f5f0 [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% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 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% %
cristy3980b0d2009-10-25 14:37:13 +000072+ M a g i c k C o m m a n d G e n e s i s %
73% %
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,
84% MagickCommand command,const int argc,const char **argv,Image **image)
85%
86% A description of each parameter follows:
87%
88% o image_info: the image info.
89%
90% o command: the magick command.
91%
92% o argc: Specifies a pointer to an integer describing the number of
93% elements in the argument vector.
94%
95% o argv: Specifies a pointer to a text array containing the command line
96% arguments.
97%
98% o image: the image.
99%
100% o exception: return any errors or warnings in this structure.
101%
102*/
103WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
104 MagickCommand command,int argc,char **argv,char **metadata,
105 ExceptionInfo *exception)
106{
107 char
108 *option;
109
110 double
111 duration,
112 elapsed_time,
113 user_time;
114
cristy3980b0d2009-10-25 14:37:13 +0000115 MagickBooleanType
116 concurrent,
117 regard_warnings,
118 status;
119
120 register long
121 i;
122
123 TimerInfo
124 *timer;
125
126 unsigned long
127 iterations;
128
cristyd0a94fa2010-03-12 14:18:11 +0000129 (void) setlocale(LC_ALL,"");
130 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000131 concurrent=MagickFalse;
132 duration=(-1.0);
133 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000134 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000135 regard_warnings=MagickFalse;
136 for (i=1; i < (long) (argc-1); i++)
137 {
138 option=argv[i];
139 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
140 continue;
141 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000142 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000143 if (LocaleCompare("concurrent",option+1) == 0)
144 concurrent=MagickTrue;
145 if (LocaleCompare("debug",option+1) == 0)
146 (void) SetLogEventMask(argv[++i]);
147 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000148 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000149 if (LocaleCompare("regard-warnings",option+1) == 0)
150 regard_warnings=MagickTrue;
151 }
152 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000153 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000154 {
cristyceae09d2009-10-28 17:18:47 +0000155 for (i=0; i < (long) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000156 {
cristy33557d72009-11-06 00:54:33 +0000157 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000158 continue;
159 if (duration > 0)
160 {
161 if (GetElapsedTime(timer) > duration)
162 continue;
163 (void) ContinueTimer(timer);
164 }
165 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000166 if (exception->severity != UndefinedException)
167 {
168 if ((exception->severity > ErrorException) ||
169 (regard_warnings != MagickFalse))
170 status=MagickTrue;
171 CatchException(exception);
172 }
cristy3d1a5512009-10-25 21:23:27 +0000173 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000174 {
175 (void) fputs(*metadata,stdout);
176 (void) fputc('\n',stdout);
177 *metadata=DestroyString(*metadata);
178 }
179 }
180 }
cristyceae09d2009-10-28 17:18:47 +0000181 else
182 {
183 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000184#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000185 # pragma omp parallel for shared(status)
186#endif
187 for (i=0; i < (long) iterations; i++)
188 {
cristy33557d72009-11-06 00:54:33 +0000189 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000190 continue;
191 if (duration > 0)
192 {
193 if (GetElapsedTime(timer) > duration)
194 continue;
195 (void) ContinueTimer(timer);
196 }
197 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000198#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000199 # pragma omp critical (MagickCore_Launch_Command)
200#endif
201 {
202 if (exception->severity != UndefinedException)
203 {
204 if ((exception->severity > ErrorException) ||
205 (regard_warnings != MagickFalse))
206 status=MagickTrue;
207 CatchException(exception);
208 }
209 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
210 {
211 (void) fputs(*metadata,stdout);
212 (void) fputc('\n',stdout);
213 *metadata=DestroyString(*metadata);
214 }
215 }
216 }
217 }
cristy3980b0d2009-10-25 14:37:13 +0000218 if (iterations > 1)
219 {
220 elapsed_time=GetElapsedTime(timer);
221 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000222 (void) fprintf(stderr,
cristye7f51092010-01-17 00:39:37 +0000223 "Performance: %lui %gips %0.3fu %ld:%02ld.%03ld\n",
cristy3980b0d2009-10-25 14:37:13 +0000224 iterations,1.0*iterations/elapsed_time,user_time,(long)
225 (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
226 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
227 }
228 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000229 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000230}
231
232/*
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234% %
235% %
236% %
cristy3ed852e2009-09-05 21:47:34 +0000237+ M o g r i f y I m a g e %
238% %
239% %
240% %
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242%
243% MogrifyImage() applies image processing options to an image as prescribed
244% by command line options.
245%
246% The format of the MogrifyImage method is:
247%
248% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
249% const char **argv,Image **image)
250%
251% A description of each parameter follows:
252%
253% o image_info: the image info..
254%
255% o argc: Specifies a pointer to an integer describing the number of
256% elements in the argument vector.
257%
258% o argv: Specifies a pointer to a text array containing the command line
259% arguments.
260%
261% o image: the image.
262%
263% o exception: return any errors or warnings in this structure.
264%
265*/
266
267static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
268 ExceptionInfo *exception)
269{
270 char
271 key[MaxTextExtent];
272
273 ExceptionInfo
274 *sans_exception;
275
276 Image
277 *image;
278
279 ImageInfo
280 *read_info;
281
282 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
283 sans_exception=AcquireExceptionInfo();
284 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
285 sans_exception=DestroyExceptionInfo(sans_exception);
286 if (image != (Image *) NULL)
287 return(image);
288 read_info=CloneImageInfo(image_info);
289 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
290 image=ReadImage(read_info,exception);
291 read_info=DestroyImageInfo(read_info);
292 if (image != (Image *) NULL)
293 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
294 return(image);
295}
296
297static int IsPathDirectory(const char *path)
298{
299 MagickBooleanType
300 status;
301
302 struct stat
303 attributes;
304
305 if ((path == (const char *) NULL) || (*path == '\0'))
306 return(MagickFalse);
307 status=GetPathAttributes(path,&attributes);
308 if (status == MagickFalse)
309 return(-1);
310 if (S_ISDIR(attributes.st_mode) == 0)
311 return(0);
312 return(1);
313}
314
315static MagickBooleanType IsPathWritable(const char *path)
316{
317 if (IsPathAccessible(path) == MagickFalse)
318 return(MagickFalse);
319 if (access(path,W_OK) != 0)
320 return(MagickFalse);
321 return(MagickTrue);
322}
323
324static inline long MagickMax(const long x,const long y)
325{
326 if (x > y)
327 return(x);
328 return(y);
329}
330
331static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000332 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000333 void *wand_unused(client_data))
334{
335 char
336 message[MaxTextExtent],
337 tag[MaxTextExtent];
338
339 const char
340 *locale_message;
341
342 register char
343 *p;
344
cristyb32b90a2009-09-07 21:45:48 +0000345 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000346 return(MagickTrue);
347 (void) CopyMagickMemory(tag,text,MaxTextExtent);
348 p=strrchr(tag,'/');
349 if (p != (char *) NULL)
350 *p='\0';
351 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
352 locale_message=GetLocaleMessage(message);
353 if (locale_message == message)
354 locale_message=tag;
355 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000356 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
357 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000358 else
cristyb32b90a2009-09-07 21:45:48 +0000359 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
360 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
361 (100L*offset/(extent-1)));
362 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000363 (void) fprintf(stderr,"\n");
364 (void) fflush(stderr);
365 return(MagickTrue);
366}
367
368static Image *SparseColorOption(const Image *image,const ChannelType channel,
369 const SparseColorMethod method,const char *arguments,
370 const MagickBooleanType color_from_image,ExceptionInfo *exception)
371{
372 ChannelType
373 channels;
374
375 char
376 token[MaxTextExtent];
377
378 const char
379 *p;
380
381 double
382 *sparse_arguments;
383
384 register unsigned long
385 x;
386
387 unsigned long
388 number_arguments;
389
390 unsigned long
391 number_colors;
392
393 Image
394 *sparse_image;
395
396 MagickPixelPacket
397 color;
398
399 MagickBooleanType
400 error;
401
402 assert(image != (Image *) NULL);
403 assert(image->signature == MagickSignature);
404 if (image->debug != MagickFalse)
405 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
406 assert(exception != (ExceptionInfo *) NULL);
407 assert(exception->signature == MagickSignature);
408 /*
409 Limit channels according to image - and add up number of color channel.
410 */
411 channels=channel;
412 if (image->colorspace != CMYKColorspace)
413 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
414 if (image->matte == MagickFalse)
415 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
416 number_colors=0;
417 if ((channels & RedChannel) != 0)
418 number_colors++;
419 if ((channels & GreenChannel) != 0)
420 number_colors++;
421 if ((channels & BlueChannel) != 0)
422 number_colors++;
423 if ((channels & IndexChannel) != 0)
424 number_colors++;
425 if ((channels & OpacityChannel) != 0)
426 number_colors++;
427 /*
428 Read string, to determine number of arguments needed,
429 */
430 p=arguments;
431 x=0;
432 while( *p != '\0' )
433 {
434 GetMagickToken(p,&p,token);
435 if ( token[0] == ',' ) continue;
436 if ( isalpha((int) token[0]) || token[0] == '#' ) {
437 if ( color_from_image ) {
438 (void) ThrowMagickException(exception,GetMagickModule(),
439 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
440 "Color arg given, when colors are coming from image");
441 return( (Image *)NULL);
442 }
443 x += number_colors; /* color argument */
444 }
445 else {
446 x++; /* floating point argument */
447 }
448 }
449 error=MagickTrue;
450 if ( color_from_image ) {
451 /* just the control points are being given */
452 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
453 number_arguments=(x/2)*(2+number_colors);
454 }
455 else {
456 /* control points and color values */
457 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
458 number_arguments=x;
459 }
460 if ( error ) {
461 (void) ThrowMagickException(exception,GetMagickModule(),
462 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
463 "Invalid number of Arguments");
464 return( (Image *)NULL);
465 }
466
467 /* Allocate and fill in the floating point arguments */
468 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
469 sizeof(*sparse_arguments));
470 if (sparse_arguments == (double *) NULL) {
471 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
472 "MemoryAllocationFailed","%s","SparseColorOption");
473 return( (Image *)NULL);
474 }
475 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
476 sizeof(*sparse_arguments));
477 p=arguments;
478 x=0;
479 while( *p != '\0' && x < number_arguments ) {
480 /* X coordinate */
481 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
482 if ( token[0] == '\0' ) break;
483 if ( isalpha((int) token[0]) || token[0] == '#' ) {
484 (void) ThrowMagickException(exception,GetMagickModule(),
485 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
486 "Color found, instead of X-coord");
487 error = MagickTrue;
488 break;
489 }
cristyf2f27272009-12-17 14:48:46 +0000490 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000491 /* Y coordinate */
492 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
493 if ( token[0] == '\0' ) break;
494 if ( isalpha((int) token[0]) || token[0] == '#' ) {
495 (void) ThrowMagickException(exception,GetMagickModule(),
496 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
497 "Color found, instead of Y-coord");
498 error = MagickTrue;
499 break;
500 }
cristyf2f27272009-12-17 14:48:46 +0000501 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000502 /* color values for this control point */
503#if 0
504 if ( (color_from_image ) {
505 /* get color from image */
506 /* HOW??? */
507 }
508 else
509#endif
510 {
511 /* color name or function given in string argument */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 /* Color string given */
516 (void) QueryMagickColor(token,&color,exception);
517 if ( channels & RedChannel )
518 sparse_arguments[x++] = QuantumScale*color.red;
519 if ( channels & GreenChannel )
520 sparse_arguments[x++] = QuantumScale*color.green;
521 if ( channels & BlueChannel )
522 sparse_arguments[x++] = QuantumScale*color.blue;
523 if ( channels & IndexChannel )
524 sparse_arguments[x++] = QuantumScale*color.index;
525 if ( channels & OpacityChannel )
526 sparse_arguments[x++] = QuantumScale*color.opacity;
527 }
528 else {
529#if 0
530 /* the color name/function/value was not found - error */
531 break;
532#else
533 /* Colors given as a set of floating point values - experimental */
534 /* NB: token contains the first floating point value to use! */
535 if ( channels & RedChannel ) {
536 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
537 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
538 break;
cristy0f19e682009-12-17 14:55:51 +0000539 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000540 token[0] = ','; /* used this token - get another */
541 }
542 if ( channels & GreenChannel ) {
543 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
544 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
545 break;
cristy0f19e682009-12-17 14:55:51 +0000546 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000547 token[0] = ','; /* used this token - get another */
548 }
549 if ( channels & BlueChannel ) {
550 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
551 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
552 break;
cristy0f19e682009-12-17 14:55:51 +0000553 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000554 token[0] = ','; /* used this token - get another */
555 }
556 if ( channels & IndexChannel ) {
557 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
558 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
559 break;
cristy0f19e682009-12-17 14:55:51 +0000560 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000561 token[0] = ','; /* used this token - get another */
562 }
563 if ( channels & OpacityChannel ) {
564 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
565 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
566 break;
cristy0f19e682009-12-17 14:55:51 +0000567 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000568 token[0] = ','; /* used this token - get another */
569 }
570#endif
571 }
572 }
573 }
574 if ( number_arguments != x && !error ) {
575 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
576 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
577 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
578 return( (Image *)NULL);
579 }
580 if ( error )
581 return( (Image *)NULL);
582
583 /* Call the Interpolation function with the parsed arguments */
584 sparse_image=SparseColorImage(image,channels,method,number_arguments,
585 sparse_arguments,exception);
586 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
587 return( sparse_image );
588}
589
590WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
591 const char **argv,Image **image,ExceptionInfo *exception)
592{
593 ChannelType
594 channel;
595
596 const char
597 *format,
598 *option;
599
600 DrawInfo
601 *draw_info;
602
603 GeometryInfo
604 geometry_info;
605
606 Image
607 *region_image;
608
609 long
610 count;
611
612 MagickBooleanType
613 status;
614
615 MagickPixelPacket
616 fill;
617
618 MagickStatusType
619 flags;
620
621 QuantizeInfo
622 *quantize_info;
623
624 RectangleInfo
625 geometry,
626 region_geometry;
627
628 register long
629 i;
630
631 /*
632 Initialize method variables.
633 */
634 assert(image_info != (const ImageInfo *) NULL);
635 assert(image_info->signature == MagickSignature);
636 assert(image != (Image **) NULL);
637 assert((*image)->signature == MagickSignature);
638 if ((*image)->debug != MagickFalse)
639 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
640 if (argc < 0)
641 return(MagickTrue);
642 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
643 quantize_info=AcquireQuantizeInfo(image_info);
644 SetGeometryInfo(&geometry_info);
645 GetMagickPixelPacket(*image,&fill);
646 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
647 &fill);
648 channel=image_info->channel;
649 format=GetImageOption(image_info,"format");
650 SetGeometry(*image,&region_geometry);
651 region_image=NewImageList();
652 /*
653 Transmogrify the image.
654 */
655 for (i=0; i < (long) argc; i++)
656 {
657 option=argv[i];
658 if (IsMagickOption(option) == MagickFalse)
659 continue;
660 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
661 0L);
662 if ((i+count) >= argc)
663 break;
664 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
665 switch (*(option+1))
666 {
667 case 'a':
668 {
669 if (LocaleCompare("adaptive-blur",option+1) == 0)
670 {
671 Image
672 *blur_image;
673
674 /*
675 Adaptive blur image.
676 */
677 (void) SyncImageSettings(image_info,*image);
678 flags=ParseGeometry(argv[i+1],&geometry_info);
679 if ((flags & SigmaValue) == 0)
680 geometry_info.sigma=1.0;
681 blur_image=AdaptiveBlurImageChannel(*image,channel,
682 geometry_info.rho,geometry_info.sigma,exception);
683 if (blur_image == (Image *) NULL)
684 break;
685 *image=DestroyImage(*image);
686 *image=blur_image;
687 break;
688 }
689 if (LocaleCompare("adaptive-resize",option+1) == 0)
690 {
691 Image
692 *resize_image;
693
694 /*
695 Adaptive resize image.
696 */
697 (void) SyncImageSettings(image_info,*image);
698 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
699 resize_image=AdaptiveResizeImage(*image,geometry.width,
700 geometry.height,exception);
701 if (resize_image == (Image *) NULL)
702 break;
703 *image=DestroyImage(*image);
704 *image=resize_image;
705 break;
706 }
707 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
708 {
709 Image
710 *sharp_image;
711
712 /*
713 Adaptive sharpen image.
714 */
715 (void) SyncImageSettings(image_info,*image);
716 flags=ParseGeometry(argv[i+1],&geometry_info);
717 if ((flags & SigmaValue) == 0)
718 geometry_info.sigma=1.0;
719 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
720 geometry_info.rho,geometry_info.sigma,exception);
721 if (sharp_image == (Image *) NULL)
722 break;
723 *image=DestroyImage(*image);
724 *image=sharp_image;
725 break;
726 }
727 if (LocaleCompare("affine",option+1) == 0)
728 {
729 /*
730 Affine matrix.
731 */
732 if (*option == '+')
733 {
734 GetAffineMatrix(&draw_info->affine);
735 break;
736 }
737 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
738 break;
739 }
740 if (LocaleCompare("alpha",option+1) == 0)
741 {
742 AlphaChannelType
743 alpha_type;
744
745 (void) SyncImageSettings(image_info,*image);
746 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
747 MagickFalse,argv[i+1]);
748 (void) SetImageAlphaChannel(*image,alpha_type);
749 InheritException(exception,&(*image)->exception);
750 break;
751 }
752 if (LocaleCompare("annotate",option+1) == 0)
753 {
754 char
755 *text,
756 geometry[MaxTextExtent];
757
758 /*
759 Annotate image.
760 */
761 (void) SyncImageSettings(image_info,*image);
762 SetGeometryInfo(&geometry_info);
763 flags=ParseGeometry(argv[i+1],&geometry_info);
764 if ((flags & SigmaValue) == 0)
765 geometry_info.sigma=geometry_info.rho;
766 text=InterpretImageProperties(image_info,*image,argv[i+2]);
767 InheritException(exception,&(*image)->exception);
768 if (text == (char *) NULL)
769 break;
770 (void) CloneString(&draw_info->text,text);
771 text=DestroyString(text);
772 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
773 geometry_info.xi,geometry_info.psi);
774 (void) CloneString(&draw_info->geometry,geometry);
775 draw_info->affine.sx=cos(DegreesToRadians(
776 fmod(geometry_info.rho,360.0)));
777 draw_info->affine.rx=sin(DegreesToRadians(
778 fmod(geometry_info.rho,360.0)));
779 draw_info->affine.ry=(-sin(DegreesToRadians(
780 fmod(geometry_info.sigma,360.0))));
781 draw_info->affine.sy=cos(DegreesToRadians(
782 fmod(geometry_info.sigma,360.0)));
783 (void) AnnotateImage(*image,draw_info);
784 InheritException(exception,&(*image)->exception);
785 break;
786 }
787 if (LocaleCompare("antialias",option+1) == 0)
788 {
789 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
790 MagickFalse;
791 draw_info->text_antialias=(*option == '-') ? MagickTrue :
792 MagickFalse;
793 break;
794 }
795 if (LocaleCompare("auto-gamma",option+1) == 0)
796 {
797 /*
798 Auto Adjust Gamma of image based on its mean
799 */
800 (void) SyncImageSettings(image_info,*image);
801 (void) AutoGammaImageChannel(*image,channel);
802 break;
803 }
804 if (LocaleCompare("auto-level",option+1) == 0)
805 {
806 /*
807 Perfectly Normalize (max/min stretch) the image
808 */
809 (void) SyncImageSettings(image_info,*image);
810 (void) AutoLevelImageChannel(*image,channel);
811 break;
812 }
813 if (LocaleCompare("auto-orient",option+1) == 0)
814 {
815 Image
816 *orient_image;
817
818 (void) SyncImageSettings(image_info,*image);
819 orient_image=NewImageList();
820 switch ((*image)->orientation)
821 {
822 case TopRightOrientation:
823 {
824 orient_image=FlopImage(*image,exception);
825 break;
826 }
827 case BottomRightOrientation:
828 {
829 orient_image=RotateImage(*image,180.0,exception);
830 break;
831 }
832 case BottomLeftOrientation:
833 {
834 orient_image=FlipImage(*image,exception);
835 break;
836 }
837 case LeftTopOrientation:
838 {
839 orient_image=TransposeImage(*image,exception);
840 break;
841 }
842 case RightTopOrientation:
843 {
844 orient_image=RotateImage(*image,90.0,exception);
845 break;
846 }
847 case RightBottomOrientation:
848 {
849 orient_image=TransverseImage(*image,exception);
850 break;
851 }
852 case LeftBottomOrientation:
853 {
854 orient_image=RotateImage(*image,270.0,exception);
855 break;
856 }
857 default:
858 break;
859 }
860 if (orient_image == (Image *) NULL)
861 break;
862 orient_image->orientation=TopLeftOrientation;
863 *image=DestroyImage(*image);
864 *image=orient_image;
865 break;
866 }
867 break;
868 }
869 case 'b':
870 {
871 if (LocaleCompare("black-threshold",option+1) == 0)
872 {
873 /*
874 Black threshold image.
875 */
876 (void) SyncImageSettings(image_info,*image);
877 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
878 exception);
879 InheritException(exception,&(*image)->exception);
880 break;
881 }
882 if (LocaleCompare("blue-shift",option+1) == 0)
883 {
884 Image
885 *shift_image;
886
887 /*
888 Blue shift image.
889 */
890 (void) SyncImageSettings(image_info,*image);
891 geometry_info.rho=1.5;
892 if (*option == '-')
893 flags=ParseGeometry(argv[i+1],&geometry_info);
894 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
895 if (shift_image == (Image *) NULL)
896 break;
897 *image=DestroyImage(*image);
898 *image=shift_image;
899 break;
900 }
901 if (LocaleCompare("blur",option+1) == 0)
902 {
903 Image
904 *blur_image;
905
906 /*
907 Gaussian blur image.
908 */
909 (void) SyncImageSettings(image_info,*image);
910 flags=ParseGeometry(argv[i+1],&geometry_info);
911 if ((flags & SigmaValue) == 0)
912 geometry_info.sigma=1.0;
913 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
914 geometry_info.sigma,exception);
915 if (blur_image == (Image *) NULL)
916 break;
917 *image=DestroyImage(*image);
918 *image=blur_image;
919 break;
920 }
921 if (LocaleCompare("border",option+1) == 0)
922 {
923 Image
924 *border_image;
925
926 /*
927 Surround image with a border of solid color.
928 */
929 (void) SyncImageSettings(image_info,*image);
930 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
931 if ((flags & SigmaValue) == 0)
932 geometry.height=geometry.width;
933 border_image=BorderImage(*image,&geometry,exception);
934 if (border_image == (Image *) NULL)
935 break;
936 *image=DestroyImage(*image);
937 *image=border_image;
938 break;
939 }
940 if (LocaleCompare("bordercolor",option+1) == 0)
941 {
942 if (*option == '+')
943 {
944 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
945 exception);
946 break;
947 }
948 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
949 exception);
950 break;
951 }
952 if (LocaleCompare("box",option+1) == 0)
953 {
954 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
955 exception);
956 break;
957 }
cristya28d6b82010-01-11 20:03:47 +0000958 if (LocaleCompare("brightness-contrast",option+1) == 0)
959 {
960 double
961 brightness,
962 contrast;
963
964 GeometryInfo
965 geometry_info;
966
967 MagickStatusType
968 flags;
969
970 /*
971 Brightness / contrast image.
972 */
973 (void) SyncImageSettings(image_info,*image);
974 flags=ParseGeometry(argv[i+1],&geometry_info);
975 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000976 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000977 if ((flags & SigmaValue) != 0)
978 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000979 (void) BrightnessContrastImageChannel(*image,channel,brightness,
980 contrast);
cristya28d6b82010-01-11 20:03:47 +0000981 InheritException(exception,&(*image)->exception);
982 break;
983 }
cristy3ed852e2009-09-05 21:47:34 +0000984 break;
985 }
986 case 'c':
987 {
988 if (LocaleCompare("cdl",option+1) == 0)
989 {
990 char
991 *color_correction_collection;
992
993 /*
994 Color correct with a color decision list.
995 */
996 (void) SyncImageSettings(image_info,*image);
997 color_correction_collection=FileToString(argv[i+1],~0,exception);
998 if (color_correction_collection == (char *) NULL)
999 break;
1000 (void) ColorDecisionListImage(*image,color_correction_collection);
1001 InheritException(exception,&(*image)->exception);
1002 break;
1003 }
1004 if (LocaleCompare("channel",option+1) == 0)
1005 {
1006 if (*option == '+')
1007 {
1008 channel=DefaultChannels;
1009 break;
1010 }
1011 channel=(ChannelType) ParseChannelOption(argv[i+1]);
1012 break;
1013 }
1014 if (LocaleCompare("charcoal",option+1) == 0)
1015 {
1016 Image
1017 *charcoal_image;
1018
1019 /*
1020 Charcoal image.
1021 */
1022 (void) SyncImageSettings(image_info,*image);
1023 flags=ParseGeometry(argv[i+1],&geometry_info);
1024 if ((flags & SigmaValue) == 0)
1025 geometry_info.sigma=1.0;
1026 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1027 geometry_info.sigma,exception);
1028 if (charcoal_image == (Image *) NULL)
1029 break;
1030 *image=DestroyImage(*image);
1031 *image=charcoal_image;
1032 break;
1033 }
1034 if (LocaleCompare("chop",option+1) == 0)
1035 {
1036 Image
1037 *chop_image;
1038
1039 /*
1040 Chop the image.
1041 */
1042 (void) SyncImageSettings(image_info,*image);
1043 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1044 chop_image=ChopImage(*image,&geometry,exception);
1045 if (chop_image == (Image *) NULL)
1046 break;
1047 *image=DestroyImage(*image);
1048 *image=chop_image;
1049 break;
1050 }
cristy1eb45dd2009-09-25 16:38:06 +00001051 if (LocaleCompare("clamp",option+1) == 0)
1052 {
1053 /*
1054 Clamp image.
1055 */
1056 (void) SyncImageSettings(image_info,*image);
1057 (void) ClampImageChannel(*image,channel);
1058 InheritException(exception,&(*image)->exception);
1059 break;
1060 }
cristy3ed852e2009-09-05 21:47:34 +00001061 if (LocaleCompare("clip",option+1) == 0)
1062 {
1063 (void) SyncImageSettings(image_info,*image);
1064 if (*option == '+')
1065 {
1066 (void) SetImageClipMask(*image,(Image *) NULL);
1067 InheritException(exception,&(*image)->exception);
1068 break;
1069 }
1070 (void) ClipImage(*image);
1071 InheritException(exception,&(*image)->exception);
1072 break;
1073 }
1074 if (LocaleCompare("clip-mask",option+1) == 0)
1075 {
1076 Image
1077 *mask;
1078
1079 long
1080 y;
1081
1082 register long
1083 x;
1084
1085 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001086 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001087
1088 (void) SyncImageSettings(image_info,*image);
1089 if (*option == '+')
1090 {
1091 /*
1092 Remove a mask.
1093 */
1094 (void) SetImageMask(*image,(Image *) NULL);
1095 InheritException(exception,&(*image)->exception);
1096 break;
1097 }
1098 /*
1099 Set the image mask.
1100 */
1101 mask=GetImageCache(image_info,argv[i+1],exception);
1102 if (mask == (Image *) NULL)
1103 break;
1104 for (y=0; y < (long) mask->rows; y++)
1105 {
1106 q=GetAuthenticPixels(mask,0,y,mask->columns,1,exception);
1107 if (q == (PixelPacket *) NULL)
1108 break;
1109 for (x=0; x < (long) mask->columns; x++)
1110 {
1111 if (mask->matte == MagickFalse)
1112 q->opacity=PixelIntensityToQuantum(q);
1113 q->red=q->opacity;
1114 q->green=q->opacity;
1115 q->blue=q->opacity;
1116 q++;
1117 }
1118 if (SyncAuthenticPixels(mask,exception) == MagickFalse)
1119 break;
1120 }
1121 if (SetImageStorageClass(mask,DirectClass) == MagickFalse)
1122 return(MagickFalse);
1123 mask->matte=MagickTrue;
1124 (void) SetImageClipMask(*image,mask);
1125 mask=DestroyImage(mask);
1126 InheritException(exception,&(*image)->exception);
1127 break;
1128 }
1129 if (LocaleCompare("clip-path",option+1) == 0)
1130 {
1131 (void) SyncImageSettings(image_info,*image);
1132 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1133 MagickFalse);
1134 InheritException(exception,&(*image)->exception);
1135 break;
1136 }
1137 if (LocaleCompare("colorize",option+1) == 0)
1138 {
1139 Image
1140 *colorize_image;
1141
1142 /*
1143 Colorize the image.
1144 */
1145 (void) SyncImageSettings(image_info,*image);
1146 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1147 exception);
1148 if (colorize_image == (Image *) NULL)
1149 break;
1150 *image=DestroyImage(*image);
1151 *image=colorize_image;
1152 break;
1153 }
1154 if (LocaleCompare("colors",option+1) == 0)
1155 {
1156 /*
1157 Reduce the number of colors in the image.
1158 */
1159 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00001160 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001161 if (quantize_info->number_colors == 0)
1162 break;
1163 if (((*image)->storage_class == DirectClass) ||
1164 (*image)->colors > quantize_info->number_colors)
1165 (void) QuantizeImage(quantize_info,*image);
1166 else
1167 (void) CompressImageColormap(*image);
1168 InheritException(exception,&(*image)->exception);
1169 break;
1170 }
1171 if (LocaleCompare("colorspace",option+1) == 0)
1172 {
1173 ColorspaceType
1174 colorspace;
1175
1176 (void) SyncImageSettings(image_info,*image);
1177 if (*option == '+')
1178 {
1179 (void) TransformImageColorspace(*image,RGBColorspace);
1180 InheritException(exception,&(*image)->exception);
1181 break;
1182 }
1183 colorspace=(ColorspaceType) ParseMagickOption(
1184 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1185 (void) TransformImageColorspace(*image,colorspace);
1186 InheritException(exception,&(*image)->exception);
1187 break;
1188 }
1189 if (LocaleCompare("contrast",option+1) == 0)
1190 {
1191 (void) SyncImageSettings(image_info,*image);
1192 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1193 MagickFalse);
1194 InheritException(exception,&(*image)->exception);
1195 break;
1196 }
1197 if (LocaleCompare("contrast-stretch",option+1) == 0)
1198 {
1199 double
1200 black_point,
1201 white_point;
1202
cristy3ed852e2009-09-05 21:47:34 +00001203 MagickStatusType
1204 flags;
1205
1206 /*
1207 Contrast stretch image.
1208 */
1209 (void) SyncImageSettings(image_info,*image);
1210 flags=ParseGeometry(argv[i+1],&geometry_info);
1211 black_point=geometry_info.rho;
1212 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1213 black_point;
1214 if ((flags & PercentValue) != 0)
1215 {
1216 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1217 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1218 }
1219 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1220 white_point;
1221 (void) ContrastStretchImageChannel(*image,channel,black_point,
1222 white_point);
1223 InheritException(exception,&(*image)->exception);
1224 break;
1225 }
1226 if (LocaleCompare("convolve",option+1) == 0)
1227 {
cristy36826ab2010-03-06 01:29:30 +00001228 double
1229 gamma;
1230
cristy3ed852e2009-09-05 21:47:34 +00001231 Image
1232 *convolve_image;
1233
cristy2be15382010-01-21 02:38:03 +00001234 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001235 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001236
cristy36826ab2010-03-06 01:29:30 +00001237 register long
1238 j;
1239
cristya6510532010-03-06 13:09:30 +00001240 (void) SyncImageSettings(image_info,*image);
cristy2be15382010-01-21 02:38:03 +00001241 kernel=AcquireKernelInfo(argv[i+1]);
1242 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001243 break;
cristy36826ab2010-03-06 01:29:30 +00001244 gamma=0.0;
1245 for (j=0; j < (long) (kernel->width*kernel->height); j++)
1246 gamma+=kernel->values[j];
1247 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristyd2baf7d2010-03-06 04:26:44 +00001248 for (j=0; j < (long) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001249 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001250 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001251 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001252 if (convolve_image == (Image *) NULL)
1253 break;
1254 *image=DestroyImage(*image);
1255 *image=convolve_image;
1256 break;
1257 }
1258 if (LocaleCompare("crop",option+1) == 0)
1259 {
1260 (void) SyncImageSettings(image_info,*image);
1261 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1262 if (((geometry.width != 0) || (geometry.height != 0)) &&
1263 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1264 break;
1265 (void) TransformImage(image,argv[i+1],(char *) NULL);
1266 InheritException(exception,&(*image)->exception);
1267 break;
1268 }
1269 if (LocaleCompare("cycle",option+1) == 0)
1270 {
1271 /*
1272 Cycle an image colormap.
1273 */
1274 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00001275 (void) CycleColormapImage(*image,StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001276 InheritException(exception,&(*image)->exception);
1277 break;
1278 }
1279 break;
1280 }
1281 case 'd':
1282 {
1283 if (LocaleCompare("decipher",option+1) == 0)
1284 {
1285 StringInfo
1286 *passkey;
1287
1288 /*
1289 Decipher pixels.
1290 */
1291 (void) SyncImageSettings(image_info,*image);
1292 passkey=FileToStringInfo(argv[i+1],~0,exception);
1293 if (passkey != (StringInfo *) NULL)
1294 {
1295 (void) PasskeyDecipherImage(*image,passkey,exception);
1296 passkey=DestroyStringInfo(passkey);
1297 }
1298 break;
1299 }
1300 if (LocaleCompare("density",option+1) == 0)
1301 {
1302 /*
1303 Set image density.
1304 */
1305 (void) CloneString(&draw_info->density,argv[i+1]);
1306 break;
1307 }
1308 if (LocaleCompare("depth",option+1) == 0)
1309 {
1310 (void) SyncImageSettings(image_info,*image);
1311 if (*option == '+')
1312 {
1313 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1314 break;
1315 }
cristye27293e2009-12-18 02:53:20 +00001316 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001317 break;
1318 }
1319 if (LocaleCompare("deskew",option+1) == 0)
1320 {
1321 double
1322 threshold;
1323
1324 Image
1325 *deskew_image;
1326
1327 /*
1328 Straighten the image.
1329 */
1330 (void) SyncImageSettings(image_info,*image);
1331 if (*option == '+')
1332 threshold=40.0*QuantumRange/100.0;
1333 else
cristyf2f27272009-12-17 14:48:46 +00001334 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001335 deskew_image=DeskewImage(*image,threshold,exception);
1336 if (deskew_image == (Image *) NULL)
1337 break;
1338 *image=DestroyImage(*image);
1339 *image=deskew_image;
1340 break;
1341 }
1342 if (LocaleCompare("despeckle",option+1) == 0)
1343 {
1344 Image
1345 *despeckle_image;
1346
1347 /*
1348 Reduce the speckles within an image.
1349 */
1350 (void) SyncImageSettings(image_info,*image);
1351 despeckle_image=DespeckleImage(*image,exception);
1352 if (despeckle_image == (Image *) NULL)
1353 break;
1354 *image=DestroyImage(*image);
1355 *image=despeckle_image;
1356 break;
1357 }
1358 if (LocaleCompare("display",option+1) == 0)
1359 {
1360 (void) CloneString(&draw_info->server_name,argv[i+1]);
1361 break;
1362 }
cristy3ed852e2009-09-05 21:47:34 +00001363 if (LocaleCompare("distort",option+1) == 0)
1364 {
1365 char
1366 *args,
1367 token[MaxTextExtent];
1368
1369 const char
1370 *p;
1371
1372 DistortImageMethod
1373 method;
1374
1375 double
1376 *arguments;
1377
1378 Image
1379 *distort_image;
1380
1381 register long
1382 x;
1383
1384 unsigned long
1385 number_arguments;
1386
1387 /*
1388 Distort image.
1389 */
1390 (void) SyncImageSettings(image_info,*image);
1391 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1392 MagickFalse,argv[i+1]);
1393 args=InterpretImageProperties(image_info,*image,argv[i+2]);
1394 InheritException(exception,&(*image)->exception);
1395 if (args == (char *) NULL)
1396 break;
1397 p=(char *) args;
1398 for (x=0; *p != '\0'; x++)
1399 {
1400 GetMagickToken(p,&p,token);
1401 if (*token == ',')
1402 GetMagickToken(p,&p,token);
1403 }
1404 number_arguments=(unsigned long) x;
1405 arguments=(double *) AcquireQuantumMemory(number_arguments,
1406 sizeof(*arguments));
1407 if (arguments == (double *) NULL)
1408 ThrowWandFatalException(ResourceLimitFatalError,
1409 "MemoryAllocationFailed",(*image)->filename);
1410 (void) ResetMagickMemory(arguments,0,number_arguments*
1411 sizeof(*arguments));
1412 p=(char *) args;
1413 for (x=0; (x < (long) number_arguments) && (*p != '\0'); x++)
1414 {
1415 GetMagickToken(p,&p,token);
1416 if (*token == ',')
1417 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001418 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001419 }
1420 args=DestroyString(args);
1421 distort_image=DistortImage(*image,method,number_arguments,arguments,
1422 (*option == '+') ? MagickTrue : MagickFalse,exception);
1423 arguments=(double *) RelinquishMagickMemory(arguments);
1424 if (distort_image == (Image *) NULL)
1425 break;
1426 *image=DestroyImage(*image);
1427 *image=distort_image;
1428 break;
1429 }
1430 if (LocaleCompare("dither",option+1) == 0)
1431 {
1432 if (*option == '+')
1433 {
1434 quantize_info->dither=MagickFalse;
1435 break;
1436 }
1437 quantize_info->dither=MagickTrue;
1438 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1439 MagickDitherOptions,MagickFalse,argv[i+1]);
1440 if (quantize_info->dither_method == NoDitherMethod)
1441 quantize_info->dither=MagickFalse;
1442 break;
1443 }
1444 if (LocaleCompare("draw",option+1) == 0)
1445 {
1446 /*
1447 Draw image.
1448 */
1449 (void) SyncImageSettings(image_info,*image);
1450 (void) CloneString(&draw_info->primitive,argv[i+1]);
1451 (void) DrawImage(*image,draw_info);
1452 InheritException(exception,&(*image)->exception);
1453 break;
1454 }
1455 break;
1456 }
1457 case 'e':
1458 {
1459 if (LocaleCompare("edge",option+1) == 0)
1460 {
1461 Image
1462 *edge_image;
1463
1464 /*
1465 Enhance edges in the image.
1466 */
1467 (void) SyncImageSettings(image_info,*image);
1468 flags=ParseGeometry(argv[i+1],&geometry_info);
1469 if ((flags & SigmaValue) == 0)
1470 geometry_info.sigma=1.0;
1471 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1472 if (edge_image == (Image *) NULL)
1473 break;
1474 *image=DestroyImage(*image);
1475 *image=edge_image;
1476 break;
1477 }
1478 if (LocaleCompare("emboss",option+1) == 0)
1479 {
1480 Image
1481 *emboss_image;
1482
1483 /*
1484 Gaussian embossen image.
1485 */
1486 (void) SyncImageSettings(image_info,*image);
1487 flags=ParseGeometry(argv[i+1],&geometry_info);
1488 if ((flags & SigmaValue) == 0)
1489 geometry_info.sigma=1.0;
1490 emboss_image=EmbossImage(*image,geometry_info.rho,
1491 geometry_info.sigma,exception);
1492 if (emboss_image == (Image *) NULL)
1493 break;
1494 *image=DestroyImage(*image);
1495 *image=emboss_image;
1496 break;
1497 }
1498 if (LocaleCompare("encipher",option+1) == 0)
1499 {
1500 StringInfo
1501 *passkey;
1502
1503 /*
1504 Encipher pixels.
1505 */
1506 (void) SyncImageSettings(image_info,*image);
1507 passkey=FileToStringInfo(argv[i+1],~0,exception);
1508 if (passkey != (StringInfo *) NULL)
1509 {
1510 (void) PasskeyEncipherImage(*image,passkey,exception);
1511 passkey=DestroyStringInfo(passkey);
1512 }
1513 break;
1514 }
1515 if (LocaleCompare("encoding",option+1) == 0)
1516 {
1517 (void) CloneString(&draw_info->encoding,argv[i+1]);
1518 break;
1519 }
1520 if (LocaleCompare("enhance",option+1) == 0)
1521 {
1522 Image
1523 *enhance_image;
1524
1525 /*
1526 Enhance image.
1527 */
1528 (void) SyncImageSettings(image_info,*image);
1529 enhance_image=EnhanceImage(*image,exception);
1530 if (enhance_image == (Image *) NULL)
1531 break;
1532 *image=DestroyImage(*image);
1533 *image=enhance_image;
1534 break;
1535 }
1536 if (LocaleCompare("equalize",option+1) == 0)
1537 {
1538 /*
1539 Equalize image.
1540 */
1541 (void) SyncImageSettings(image_info,*image);
1542 (void) EqualizeImageChannel(*image,channel);
1543 InheritException(exception,&(*image)->exception);
1544 break;
1545 }
1546 if (LocaleCompare("evaluate",option+1) == 0)
1547 {
1548 double
1549 constant;
1550
1551 MagickEvaluateOperator
1552 op;
1553
1554 (void) SyncImageSettings(image_info,*image);
1555 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1556 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001557 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001558 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1559 break;
1560 }
1561 if (LocaleCompare("extent",option+1) == 0)
1562 {
1563 Image
1564 *extent_image;
1565
1566 /*
1567 Set the image extent.
1568 */
1569 (void) SyncImageSettings(image_info,*image);
1570 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001571 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001572 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001573 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001574 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001575 geometry.x=(-geometry.x);
1576 geometry.y=(-geometry.y);
1577 extent_image=ExtentImage(*image,&geometry,exception);
1578 if (extent_image == (Image *) NULL)
1579 break;
1580 *image=DestroyImage(*image);
1581 *image=extent_image;
1582 break;
1583 }
1584 break;
1585 }
1586 case 'f':
1587 {
1588 if (LocaleCompare("family",option+1) == 0)
1589 {
1590 if (*option == '+')
1591 {
1592 if (draw_info->family != (char *) NULL)
1593 draw_info->family=DestroyString(draw_info->family);
1594 break;
1595 }
1596 (void) CloneString(&draw_info->family,argv[i+1]);
1597 break;
1598 }
cristy0fe961c2010-01-30 03:09:54 +00001599 if (LocaleCompare("features",option+1) == 0)
1600 {
1601 if (*option == '+')
1602 {
1603 (void) DeleteImageArtifact(*image,"identify:features");
1604 break;
1605 }
1606 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1607 break;
1608 }
cristy3ed852e2009-09-05 21:47:34 +00001609 if (LocaleCompare("fill",option+1) == 0)
1610 {
1611 ExceptionInfo
1612 *sans;
1613
1614 GetMagickPixelPacket(*image,&fill);
1615 if (*option == '+')
1616 {
1617 (void) QueryMagickColor("none",&fill,exception);
1618 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1619 if (draw_info->fill_pattern != (Image *) NULL)
1620 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1621 break;
1622 }
1623 sans=AcquireExceptionInfo();
1624 (void) QueryMagickColor(argv[i+1],&fill,sans);
1625 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1626 sans=DestroyExceptionInfo(sans);
1627 if (status == MagickFalse)
1628 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
1629 exception);
1630 break;
1631 }
1632 if (LocaleCompare("flip",option+1) == 0)
1633 {
1634 Image
1635 *flip_image;
1636
1637 /*
1638 Flip image scanlines.
1639 */
1640 (void) SyncImageSettings(image_info,*image);
1641 flip_image=FlipImage(*image,exception);
1642 if (flip_image == (Image *) NULL)
1643 break;
1644 *image=DestroyImage(*image);
1645 *image=flip_image;
1646 break;
1647 }
1648 if (LocaleCompare("flop",option+1) == 0)
1649 {
1650 Image
1651 *flop_image;
1652
1653 /*
1654 Flop image scanlines.
1655 */
1656 (void) SyncImageSettings(image_info,*image);
1657 flop_image=FlopImage(*image,exception);
1658 if (flop_image == (Image *) NULL)
1659 break;
1660 *image=DestroyImage(*image);
1661 *image=flop_image;
1662 break;
1663 }
1664 if (LocaleCompare("floodfill",option+1) == 0)
1665 {
1666 MagickPixelPacket
1667 target;
1668
1669 /*
1670 Floodfill image.
1671 */
1672 (void) SyncImageSettings(image_info,*image);
1673 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1674 (void) QueryMagickColor(argv[i+2],&target,exception);
1675 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1676 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1677 InheritException(exception,&(*image)->exception);
1678 break;
1679 }
1680 if (LocaleCompare("font",option+1) == 0)
1681 {
1682 if (*option == '+')
1683 {
1684 if (draw_info->font != (char *) NULL)
1685 draw_info->font=DestroyString(draw_info->font);
1686 break;
1687 }
1688 (void) CloneString(&draw_info->font,argv[i+1]);
1689 break;
1690 }
1691 if (LocaleCompare("format",option+1) == 0)
1692 {
1693 format=argv[i+1];
1694 break;
1695 }
1696 if (LocaleCompare("frame",option+1) == 0)
1697 {
1698 FrameInfo
1699 frame_info;
1700
1701 Image
1702 *frame_image;
1703
1704 /*
1705 Surround image with an ornamental border.
1706 */
1707 (void) SyncImageSettings(image_info,*image);
1708 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1709 frame_info.width=geometry.width;
1710 frame_info.height=geometry.height;
1711 if ((flags & HeightValue) == 0)
1712 frame_info.height=geometry.width;
1713 frame_info.outer_bevel=geometry.x;
1714 frame_info.inner_bevel=geometry.y;
1715 frame_info.x=(long) frame_info.width;
1716 frame_info.y=(long) frame_info.height;
1717 frame_info.width=(*image)->columns+2*frame_info.width;
1718 frame_info.height=(*image)->rows+2*frame_info.height;
1719 frame_image=FrameImage(*image,&frame_info,exception);
1720 if (frame_image == (Image *) NULL)
1721 break;
1722 *image=DestroyImage(*image);
1723 *image=frame_image;
1724 break;
1725 }
1726 if (LocaleCompare("function",option+1) == 0)
1727 {
1728 char
1729 *arguments,
1730 token[MaxTextExtent];
1731
1732 const char
1733 *p;
1734
1735 double
1736 *parameters;
1737
1738 MagickFunction
1739 function;
1740
1741 register long
1742 x;
1743
1744 unsigned long
1745 number_parameters;
1746
1747 /*
1748 Function Modify Image Values
1749 */
1750 (void) SyncImageSettings(image_info,*image);
1751 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1752 MagickFalse,argv[i+1]);
1753 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
1754 InheritException(exception,&(*image)->exception);
1755 if (arguments == (char *) NULL)
1756 break;
1757 p=(char *) arguments;
1758 for (x=0; *p != '\0'; x++)
1759 {
1760 GetMagickToken(p,&p,token);
1761 if (*token == ',')
1762 GetMagickToken(p,&p,token);
1763 }
1764 number_parameters=(unsigned long) x;
1765 parameters=(double *) AcquireQuantumMemory(number_parameters,
1766 sizeof(*parameters));
1767 if (parameters == (double *) NULL)
1768 ThrowWandFatalException(ResourceLimitFatalError,
1769 "MemoryAllocationFailed",(*image)->filename);
1770 (void) ResetMagickMemory(parameters,0,number_parameters*
1771 sizeof(*parameters));
1772 p=(char *) arguments;
1773 for (x=0; (x < (long) number_parameters) && (*p != '\0'); x++)
1774 {
1775 GetMagickToken(p,&p,token);
1776 if (*token == ',')
1777 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001778 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001779 }
1780 arguments=DestroyString(arguments);
1781 (void) FunctionImageChannel(*image,channel,function,
1782 number_parameters,parameters,exception);
1783 parameters=(double *) RelinquishMagickMemory(parameters);
1784 break;
1785 }
1786 break;
1787 }
1788 case 'g':
1789 {
1790 if (LocaleCompare("gamma",option+1) == 0)
1791 {
1792 /*
1793 Gamma image.
1794 */
1795 (void) SyncImageSettings(image_info,*image);
1796 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001797 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001798 else
1799 {
1800 if (strchr(argv[i+1],',') != (char *) NULL)
1801 (void) GammaImage(*image,argv[i+1]);
1802 else
cristya5447be2010-01-11 00:20:51 +00001803 (void) GammaImageChannel(*image,channel,
1804 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001805 InheritException(exception,&(*image)->exception);
1806 }
1807 break;
1808 }
1809 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1810 (LocaleCompare("gaussian",option+1) == 0))
1811 {
1812 Image
1813 *gaussian_image;
1814
1815 /*
1816 Gaussian blur image.
1817 */
1818 (void) SyncImageSettings(image_info,*image);
1819 flags=ParseGeometry(argv[i+1],&geometry_info);
1820 if ((flags & SigmaValue) == 0)
1821 geometry_info.sigma=1.0;
1822 gaussian_image=GaussianBlurImageChannel(*image,channel,
1823 geometry_info.rho,geometry_info.sigma,exception);
1824 if (gaussian_image == (Image *) NULL)
1825 break;
1826 *image=DestroyImage(*image);
1827 *image=gaussian_image;
1828 break;
1829 }
1830 if (LocaleCompare("geometry",option+1) == 0)
1831 {
1832 (void) SyncImageSettings(image_info,*image);
1833 if (*option == '+')
1834 {
1835 if ((*image)->geometry != (char *) NULL)
1836 (*image)->geometry=DestroyString((*image)->geometry);
1837 break;
1838 }
1839 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1840 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1841 (void) CloneString(&(*image)->geometry,argv[i+1]);
1842 else
1843 {
1844 Image
1845 *zoom_image;
1846
1847 /*
1848 Resize image.
1849 */
1850 zoom_image=ZoomImage(*image,geometry.width,geometry.height,
1851 exception);
1852 if (zoom_image == (Image *) NULL)
1853 break;
1854 *image=DestroyImage(*image);
1855 *image=zoom_image;
1856 }
1857 break;
1858 }
1859 if (LocaleCompare("gravity",option+1) == 0)
1860 {
1861 if (*option == '+')
1862 {
1863 draw_info->gravity=UndefinedGravity;
1864 break;
1865 }
1866 draw_info->gravity=(GravityType) ParseMagickOption(
1867 MagickGravityOptions,MagickFalse,argv[i+1]);
1868 break;
1869 }
1870 break;
1871 }
1872 case 'h':
1873 {
1874 if (LocaleCompare("highlight-color",option+1) == 0)
1875 {
1876 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1877 break;
1878 }
1879 break;
1880 }
1881 case 'i':
1882 {
1883 if (LocaleCompare("identify",option+1) == 0)
1884 {
1885 char
1886 *text;
1887
1888 (void) SyncImageSettings(image_info,*image);
1889 if (format == (char *) NULL)
1890 {
1891 (void) IdentifyImage(*image,stdout,image_info->verbose);
1892 InheritException(exception,&(*image)->exception);
1893 break;
1894 }
1895 text=InterpretImageProperties(image_info,*image,format);
1896 InheritException(exception,&(*image)->exception);
1897 if (text == (char *) NULL)
1898 break;
1899 (void) fputs(text,stdout);
1900 (void) fputc('\n',stdout);
1901 text=DestroyString(text);
1902 break;
1903 }
1904 if (LocaleCompare("implode",option+1) == 0)
1905 {
1906 Image
1907 *implode_image;
1908
1909 /*
1910 Implode image.
1911 */
1912 (void) SyncImageSettings(image_info,*image);
1913 (void) ParseGeometry(argv[i+1],&geometry_info);
1914 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1915 if (implode_image == (Image *) NULL)
1916 break;
1917 *image=DestroyImage(*image);
1918 *image=implode_image;
1919 break;
1920 }
cristyb32b90a2009-09-07 21:45:48 +00001921 if (LocaleCompare("interline-spacing",option+1) == 0)
1922 {
1923 if (*option == '+')
1924 (void) ParseGeometry("0",&geometry_info);
1925 else
1926 (void) ParseGeometry(argv[i+1],&geometry_info);
1927 draw_info->interline_spacing=geometry_info.rho;
1928 break;
1929 }
cristy3ed852e2009-09-05 21:47:34 +00001930 if (LocaleCompare("interword-spacing",option+1) == 0)
1931 {
1932 if (*option == '+')
1933 (void) ParseGeometry("0",&geometry_info);
1934 else
1935 (void) ParseGeometry(argv[i+1],&geometry_info);
1936 draw_info->interword_spacing=geometry_info.rho;
1937 break;
1938 }
1939 break;
1940 }
1941 case 'k':
1942 {
1943 if (LocaleCompare("kerning",option+1) == 0)
1944 {
1945 if (*option == '+')
1946 (void) ParseGeometry("0",&geometry_info);
1947 else
1948 (void) ParseGeometry(argv[i+1],&geometry_info);
1949 draw_info->kerning=geometry_info.rho;
1950 break;
1951 }
1952 break;
1953 }
1954 case 'l':
1955 {
1956 if (LocaleCompare("lat",option+1) == 0)
1957 {
1958 Image
1959 *threshold_image;
1960
1961 /*
1962 Local adaptive threshold image.
1963 */
1964 (void) SyncImageSettings(image_info,*image);
1965 flags=ParseGeometry(argv[i+1],&geometry_info);
1966 if ((flags & PercentValue) != 0)
1967 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1968 threshold_image=AdaptiveThresholdImage(*image,(unsigned long)
1969 geometry_info.rho,(unsigned long) geometry_info.sigma,
1970 (long) geometry_info.xi,exception);
1971 if (threshold_image == (Image *) NULL)
1972 break;
1973 *image=DestroyImage(*image);
1974 *image=threshold_image;
1975 break;
1976 }
1977 if (LocaleCompare("level",option+1) == 0)
1978 {
cristy3ed852e2009-09-05 21:47:34 +00001979 MagickRealType
1980 black_point,
1981 gamma,
1982 white_point;
1983
1984 MagickStatusType
1985 flags;
1986
1987 /*
1988 Parse levels.
1989 */
1990 (void) SyncImageSettings(image_info,*image);
1991 flags=ParseGeometry(argv[i+1],&geometry_info);
1992 black_point=geometry_info.rho;
1993 white_point=(MagickRealType) QuantumRange;
1994 if ((flags & SigmaValue) != 0)
1995 white_point=geometry_info.sigma;
1996 gamma=1.0;
1997 if ((flags & XiValue) != 0)
1998 gamma=geometry_info.xi;
1999 if ((flags & PercentValue) != 0)
2000 {
2001 black_point*=(MagickRealType) (QuantumRange/100.0);
2002 white_point*=(MagickRealType) (QuantumRange/100.0);
2003 }
2004 if ((flags & SigmaValue) == 0)
2005 white_point=(MagickRealType) QuantumRange-black_point;
2006 if ((*option == '+') || ((flags & AspectValue) != 0))
2007 (void) LevelizeImageChannel(*image,channel,black_point,
2008 white_point,gamma);
2009 else
2010 (void) LevelImageChannel(*image,channel,black_point,white_point,
2011 gamma);
2012 InheritException(exception,&(*image)->exception);
2013 break;
2014 }
2015 if (LocaleCompare("level-colors",option+1) == 0)
2016 {
2017 char
2018 token[MaxTextExtent];
2019
2020 const char
2021 *p;
2022
2023 MagickPixelPacket
2024 black_point,
2025 white_point;
2026
2027 p=(const char *) argv[i+1];
2028 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002029 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002030 (void) QueryMagickColor(token,&black_point,exception);
2031 else
cristyee0f8d72009-09-19 00:58:29 +00002032 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002033 if (isalpha((int) token[0]) || (token[0] == '#'))
2034 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002035 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002036 white_point=black_point; /* set everything to that color */
2037 else
2038 {
2039 /*
2040 Get white point color.
2041 */
cristyee0f8d72009-09-19 00:58:29 +00002042 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002043 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002044 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002045 (void) QueryMagickColor(token,&white_point,exception);
2046 else
cristyee0f8d72009-09-19 00:58:29 +00002047 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002048 }
cristy74fe8f12009-10-03 19:09:01 +00002049 (void) LevelColorsImageChannel(*image,channel,&black_point,
2050 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002051 break;
2052 }
2053 if (LocaleCompare("linear-stretch",option+1) == 0)
2054 {
2055 double
2056 black_point,
2057 white_point;
2058
cristy3ed852e2009-09-05 21:47:34 +00002059 MagickStatusType
2060 flags;
2061
2062 (void) SyncImageSettings(image_info,*image);
2063 flags=ParseGeometry(argv[i+1],&geometry_info);
2064 black_point=geometry_info.rho;
2065 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2066 if ((flags & SigmaValue) != 0)
2067 white_point=geometry_info.sigma;
2068 if ((flags & PercentValue) != 0)
2069 {
2070 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2071 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2072 }
2073 if ((flags & SigmaValue) == 0)
2074 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2075 black_point;
2076 (void) LinearStretchImage(*image,black_point,white_point);
2077 InheritException(exception,&(*image)->exception);
2078 break;
2079 }
2080 if (LocaleCompare("linewidth",option+1) == 0)
2081 {
cristyf2f27272009-12-17 14:48:46 +00002082 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002083 break;
2084 }
2085 if (LocaleCompare("liquid-rescale",option+1) == 0)
2086 {
2087 Image
2088 *resize_image;
2089
2090 /*
2091 Liquid rescale image.
2092 */
2093 (void) SyncImageSettings(image_info,*image);
2094 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2095 if ((flags & XValue) == 0)
2096 geometry.x=1;
2097 if ((flags & YValue) == 0)
2098 geometry.y=0;
2099 resize_image=LiquidRescaleImage(*image,geometry.width,
2100 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2101 if (resize_image == (Image *) NULL)
2102 break;
2103 *image=DestroyImage(*image);
2104 *image=resize_image;
2105 break;
2106 }
2107 if (LocaleCompare("lowlight-color",option+1) == 0)
2108 {
2109 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2110 break;
2111 }
2112 break;
2113 }
2114 case 'm':
2115 {
2116 if (LocaleCompare("map",option+1) == 0)
2117 {
2118 Image
2119 *remap_image;
2120
2121 /*
2122 Transform image colors to match this set of colors.
2123 */
2124 (void) SyncImageSettings(image_info,*image);
2125 if (*option == '+')
2126 break;
2127 remap_image=GetImageCache(image_info,argv[i+1],exception);
2128 if (remap_image == (Image *) NULL)
2129 break;
2130 (void) RemapImage(quantize_info,*image,remap_image);
2131 InheritException(exception,&(*image)->exception);
2132 remap_image=DestroyImage(remap_image);
2133 break;
2134 }
2135 if (LocaleCompare("mask",option+1) == 0)
2136 {
2137 Image
2138 *mask;
2139
2140 (void) SyncImageSettings(image_info,*image);
2141 if (*option == '+')
2142 {
2143 /*
2144 Remove a mask.
2145 */
2146 (void) SetImageMask(*image,(Image *) NULL);
2147 InheritException(exception,&(*image)->exception);
2148 break;
2149 }
2150 /*
2151 Set the image mask.
2152 */
2153 mask=GetImageCache(image_info,argv[i+1],exception);
2154 if (mask == (Image *) NULL)
2155 break;
2156 (void) SetImageMask(*image,mask);
2157 mask=DestroyImage(mask);
2158 InheritException(exception,&(*image)->exception);
2159 break;
2160 }
2161 if (LocaleCompare("matte",option+1) == 0)
2162 {
2163 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2164 SetAlphaChannel : DeactivateAlphaChannel );
2165 InheritException(exception,&(*image)->exception);
2166 break;
2167 }
2168 if (LocaleCompare("median",option+1) == 0)
2169 {
2170 Image
2171 *median_image;
2172
2173 /*
2174 Median filter image.
2175 */
2176 (void) SyncImageSettings(image_info,*image);
2177 (void) ParseGeometry(argv[i+1],&geometry_info);
2178 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2179 if (median_image == (Image *) NULL)
2180 break;
2181 *image=DestroyImage(*image);
2182 *image=median_image;
2183 break;
2184 }
2185 if (LocaleCompare("modulate",option+1) == 0)
2186 {
2187 (void) SyncImageSettings(image_info,*image);
2188 (void) ModulateImage(*image,argv[i+1]);
2189 InheritException(exception,&(*image)->exception);
2190 break;
2191 }
2192 if (LocaleCompare("monitor",option+1) == 0)
2193 {
2194 (void) SetImageProgressMonitor(*image,MonitorProgress,
2195 (void *) NULL);
2196 break;
2197 }
2198 if (LocaleCompare("monochrome",option+1) == 0)
2199 {
2200 (void) SyncImageSettings(image_info,*image);
2201 (void) SetImageType(*image,BilevelType);
2202 InheritException(exception,&(*image)->exception);
2203 break;
2204 }
anthony29188a82010-01-22 10:12:34 +00002205 if (LocaleCompare("morphology",option+1) == 0)
2206 {
2207 MorphologyMethod
2208 method;
2209
2210 KernelInfo
2211 *kernel;
2212
2213 char
2214 token[MaxTextExtent];
2215
2216 const char
2217 *p;
2218
cristyef656912010-03-05 19:54:59 +00002219 long
anthony29188a82010-01-22 10:12:34 +00002220 iterations;
2221
2222 Image
2223 *morphology_image;
2224 /*
2225 Morphological Image Operation
2226 */
2227 (void) SyncImageSettings(image_info,*image);
2228 p=argv[i+1];
2229 GetMagickToken(p,&p,token);
2230 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
2231 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002232 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002233 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002234 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002235 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002236 if ((*p != '\0'))
2237 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002238 kernel=AcquireKernelInfo(argv[i+2]);
2239 if (kernel == (KernelInfo *) NULL)
2240 ThrowWandFatalException(ResourceLimitFatalError,
2241 "MemoryAllocationFailed",(*image)->filename);
anthony930be612010-02-08 04:26:15 +00002242 if ( GetImageArtifact(*image,"showkernel") != (const char *) NULL)
2243 ShowKernelInfo(kernel); /* display the kernel to stderr */
anthony29188a82010-01-22 10:12:34 +00002244 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002245 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002246 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002247 if (morphology_image == (Image *) NULL)
2248 break;
2249 *image=DestroyImage(*image);
2250 *image=morphology_image;
2251 break;
2252 }
cristy3ed852e2009-09-05 21:47:34 +00002253 if (LocaleCompare("motion-blur",option+1) == 0)
2254 {
2255 Image
2256 *blur_image;
2257
2258 /*
2259 Motion blur image.
2260 */
2261 (void) SyncImageSettings(image_info,*image);
2262 flags=ParseGeometry(argv[i+1],&geometry_info);
2263 if ((flags & SigmaValue) == 0)
2264 geometry_info.sigma=1.0;
2265 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2266 geometry_info.sigma,geometry_info.xi,exception);
2267 if (blur_image == (Image *) NULL)
2268 break;
2269 *image=DestroyImage(*image);
2270 *image=blur_image;
2271 break;
2272 }
2273 break;
2274 }
2275 case 'n':
2276 {
2277 if (LocaleCompare("negate",option+1) == 0)
2278 {
2279 (void) SyncImageSettings(image_info,*image);
2280 (void) NegateImageChannel(*image,channel,*option == '+' ?
2281 MagickTrue : MagickFalse);
2282 InheritException(exception,&(*image)->exception);
2283 break;
2284 }
2285 if (LocaleCompare("noise",option+1) == 0)
2286 {
2287 Image
2288 *noisy_image;
2289
2290 (void) SyncImageSettings(image_info,*image);
2291 if (*option == '-')
2292 {
2293 (void) ParseGeometry(argv[i+1],&geometry_info);
2294 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2295 exception);
2296 }
2297 else
2298 {
2299 NoiseType
2300 noise;
2301
2302 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2303 MagickFalse,argv[i+1]);
2304 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2305 exception);
2306 }
2307 if (noisy_image == (Image *) NULL)
2308 break;
2309 *image=DestroyImage(*image);
2310 *image=noisy_image;
2311 break;
2312 }
2313 if (LocaleCompare("normalize",option+1) == 0)
2314 {
2315 (void) SyncImageSettings(image_info,*image);
2316 (void) NormalizeImageChannel(*image,channel);
2317 InheritException(exception,&(*image)->exception);
2318 break;
2319 }
2320 break;
2321 }
2322 case 'o':
2323 {
2324 if (LocaleCompare("opaque",option+1) == 0)
2325 {
2326 MagickPixelPacket
2327 target;
2328
2329 (void) SyncImageSettings(image_info,*image);
2330 (void) QueryMagickColor(argv[i+1],&target,exception);
2331 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2332 *option == '-' ? MagickFalse : MagickTrue);
2333 break;
2334 }
2335 if (LocaleCompare("ordered-dither",option+1) == 0)
2336 {
2337 (void) SyncImageSettings(image_info,*image);
2338 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2339 exception);
2340 break;
2341 }
2342 break;
2343 }
2344 case 'p':
2345 {
2346 if (LocaleCompare("paint",option+1) == 0)
2347 {
2348 Image
2349 *paint_image;
2350
2351 /*
2352 Oil paint image.
2353 */
2354 (void) SyncImageSettings(image_info,*image);
2355 (void) ParseGeometry(argv[i+1],&geometry_info);
2356 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2357 if (paint_image == (Image *) NULL)
2358 break;
2359 *image=DestroyImage(*image);
2360 *image=paint_image;
2361 break;
2362 }
2363 if (LocaleCompare("pen",option+1) == 0)
2364 {
2365 if (*option == '+')
2366 {
2367 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2368 break;
2369 }
2370 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2371 break;
2372 }
2373 if (LocaleCompare("pointsize",option+1) == 0)
2374 {
2375 if (*option == '+')
2376 (void) ParseGeometry("12",&geometry_info);
2377 else
2378 (void) ParseGeometry(argv[i+1],&geometry_info);
2379 draw_info->pointsize=geometry_info.rho;
2380 break;
2381 }
2382 if (LocaleCompare("polaroid",option+1) == 0)
2383 {
2384 double
2385 angle;
2386
2387 Image
2388 *polaroid_image;
2389
2390 RandomInfo
2391 *random_info;
2392
2393 /*
2394 Simulate a Polaroid picture.
2395 */
2396 (void) SyncImageSettings(image_info,*image);
2397 random_info=AcquireRandomInfo();
2398 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2399 random_info=DestroyRandomInfo(random_info);
2400 if (*option == '-')
2401 {
2402 SetGeometryInfo(&geometry_info);
2403 flags=ParseGeometry(argv[i+1],&geometry_info);
2404 angle=geometry_info.rho;
2405 }
2406 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2407 if (polaroid_image == (Image *) NULL)
2408 break;
2409 *image=DestroyImage(*image);
2410 *image=polaroid_image;
2411 break;
2412 }
2413 if (LocaleCompare("posterize",option+1) == 0)
2414 {
2415 /*
2416 Posterize image.
2417 */
2418 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00002419 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002420 quantize_info->dither);
2421 InheritException(exception,&(*image)->exception);
2422 break;
2423 }
2424 if (LocaleCompare("preview",option+1) == 0)
2425 {
2426 Image
2427 *preview_image;
2428
2429 PreviewType
2430 preview_type;
2431
2432 /*
2433 Preview image.
2434 */
2435 (void) SyncImageSettings(image_info,*image);
2436 if (*option == '+')
2437 preview_type=UndefinedPreview;
2438 else
2439 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2440 MagickFalse,argv[i+1]);
2441 preview_image=PreviewImage(*image,preview_type,exception);
2442 if (preview_image == (Image *) NULL)
2443 break;
2444 *image=DestroyImage(*image);
2445 *image=preview_image;
2446 break;
2447 }
2448 if (LocaleCompare("profile",option+1) == 0)
2449 {
2450 const char
2451 *name;
2452
2453 const StringInfo
2454 *profile;
2455
2456 Image
2457 *profile_image;
2458
2459 ImageInfo
2460 *profile_info;
2461
2462 (void) SyncImageSettings(image_info,*image);
2463 if (*option == '+')
2464 {
2465 /*
2466 Remove a profile from the image.
2467 */
2468 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2469 NULL,0,MagickTrue);
2470 InheritException(exception,&(*image)->exception);
2471 break;
2472 }
2473 /*
2474 Associate a profile with the image.
2475 */
2476 profile_info=CloneImageInfo(image_info);
2477 profile=GetImageProfile(*image,"iptc");
2478 if (profile != (StringInfo *) NULL)
2479 profile_info->profile=(void *) CloneStringInfo(profile);
2480 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2481 profile_info=DestroyImageInfo(profile_info);
2482 if (profile_image == (Image *) NULL)
2483 {
2484 char
2485 name[MaxTextExtent],
2486 filename[MaxTextExtent];
2487
2488 register char
2489 *p;
2490
2491 StringInfo
2492 *profile;
2493
2494 (void) CopyMagickString(filename,argv[i+1],MaxTextExtent);
2495 (void) CopyMagickString(name,argv[i+1],MaxTextExtent);
2496 for (p=filename; *p != '\0'; p++)
2497 if ((*p == ':') && (IsPathDirectory(argv[i+1]) < 0) &&
2498 (IsPathAccessible(argv[i+1]) == MagickFalse))
2499 {
2500 register char
2501 *q;
2502
2503 /*
2504 Look for profile name (e.g. name:profile).
2505 */
2506 (void) CopyMagickString(name,filename,(size_t)
2507 (p-filename+1));
2508 for (q=filename; *q != '\0'; q++)
2509 *q=(*++p);
2510 break;
2511 }
2512 profile=FileToStringInfo(filename,~0UL,exception);
2513 if (profile != (StringInfo *) NULL)
2514 {
2515 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2516 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2517 profile=DestroyStringInfo(profile);
2518 }
2519 break;
2520 }
2521 ResetImageProfileIterator(profile_image);
2522 name=GetNextImageProfile(profile_image);
2523 while (name != (const char *) NULL)
2524 {
2525 profile=GetImageProfile(profile_image,name);
2526 if (profile != (StringInfo *) NULL)
2527 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2528 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2529 name=GetNextImageProfile(profile_image);
2530 }
2531 profile_image=DestroyImage(profile_image);
2532 break;
2533 }
2534 break;
2535 }
2536 case 'q':
2537 {
2538 if (LocaleCompare("quantize",option+1) == 0)
2539 {
2540 if (*option == '+')
2541 {
2542 quantize_info->colorspace=UndefinedColorspace;
2543 break;
2544 }
2545 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2546 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2547 break;
2548 }
2549 break;
2550 }
2551 case 'r':
2552 {
2553 if (LocaleCompare("radial-blur",option+1) == 0)
2554 {
2555 Image
2556 *blur_image;
2557
2558 /*
2559 Radial blur image.
2560 */
2561 (void) SyncImageSettings(image_info,*image);
cristya5447be2010-01-11 00:20:51 +00002562 blur_image=RadialBlurImageChannel(*image,channel,
2563 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002564 if (blur_image == (Image *) NULL)
2565 break;
2566 *image=DestroyImage(*image);
2567 *image=blur_image;
2568 break;
2569 }
2570 if (LocaleCompare("raise",option+1) == 0)
2571 {
2572 /*
2573 Surround image with a raise of solid color.
2574 */
2575 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2576 if ((flags & SigmaValue) == 0)
2577 geometry.height=geometry.width;
2578 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2579 MagickFalse);
2580 InheritException(exception,&(*image)->exception);
2581 break;
2582 }
2583 if (LocaleCompare("random-threshold",option+1) == 0)
2584 {
2585 /*
2586 Threshold image.
2587 */
2588 (void) SyncImageSettings(image_info,*image);
2589 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2590 exception);
2591 break;
2592 }
2593 if (LocaleCompare("recolor",option+1) == 0)
2594 {
2595 char
2596 token[MaxTextExtent];
2597
2598 const char
2599 *p;
2600
2601 double
2602 *color_matrix;
2603
2604 Image
2605 *recolor_image;
2606
2607 register long
2608 x;
2609
2610 unsigned long
2611 order;
2612
2613 /*
2614 Transform color image.
2615 */
2616 (void) SyncImageSettings(image_info,*image);
2617 p=argv[i+1];
2618 for (x=0; *p != '\0'; x++)
2619 {
2620 GetMagickToken(p,&p,token);
2621 if (*token == ',')
2622 GetMagickToken(p,&p,token);
2623 }
2624 order=(unsigned long) sqrt((double) x+1.0);
2625 color_matrix=(double *) AcquireQuantumMemory(order,order*
2626 sizeof(*color_matrix));
2627 if (color_matrix == (double *) NULL)
2628 ThrowWandFatalException(ResourceLimitFatalError,
2629 "MemoryAllocationFailed",(*image)->filename);
2630 p=argv[i+1];
2631 for (x=0; (x < (long) (order*order)) && (*p != '\0'); x++)
2632 {
2633 GetMagickToken(p,&p,token);
2634 if (*token == ',')
2635 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00002636 color_matrix[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00002637 }
2638 for ( ; x < (long) (order*order); x++)
2639 color_matrix[x]=0.0;
2640 recolor_image=RecolorImage(*image,order,color_matrix,exception);
2641 color_matrix=(double *) RelinquishMagickMemory(color_matrix);
2642 if (recolor_image == (Image *) NULL)
2643 break;
2644 *image=DestroyImage(*image);
2645 *image=recolor_image;
2646 break;
2647 }
2648 if (LocaleCompare("region",option+1) == 0)
2649 {
2650 Image
2651 *crop_image;
2652
2653 (void) SyncImageSettings(image_info,*image);
2654 if (region_image != (Image *) NULL)
2655 {
2656 /*
2657 Composite region.
2658 */
2659 (void) CompositeImage(region_image,(*image)->matte !=
2660 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2661 region_geometry.x,region_geometry.y);
2662 InheritException(exception,&region_image->exception);
2663 *image=DestroyImage(*image);
2664 *image=region_image;
2665 }
2666 if (*option == '+')
2667 {
2668 if (region_image != (Image *) NULL)
2669 region_image=DestroyImage(region_image);
2670 break;
2671 }
2672 /*
2673 Apply transformations to a selected region of the image.
2674 */
2675 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2676 exception);
2677 crop_image=CropImage(*image,&region_geometry,exception);
2678 if (crop_image == (Image *) NULL)
2679 break;
2680 region_image=(*image);
2681 *image=crop_image;
2682 break;
2683 }
2684 if (LocaleCompare("render",option+1) == 0)
2685 {
2686 (void) SyncImageSettings(image_info,*image);
2687 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2688 break;
2689 }
2690 if (LocaleCompare("remap",option+1) == 0)
2691 {
2692 Image
2693 *remap_image;
2694
2695 /*
2696 Transform image colors to match this set of colors.
2697 */
2698 (void) SyncImageSettings(image_info,*image);
2699 if (*option == '+')
2700 break;
2701 remap_image=GetImageCache(image_info,argv[i+1],exception);
2702 if (remap_image == (Image *) NULL)
2703 break;
2704 (void) RemapImage(quantize_info,*image,remap_image);
2705 InheritException(exception,&(*image)->exception);
2706 remap_image=DestroyImage(remap_image);
2707 break;
2708 }
2709 if (LocaleCompare("repage",option+1) == 0)
2710 {
2711 if (*option == '+')
2712 {
2713 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2714 break;
2715 }
2716 (void) ResetImagePage(*image,argv[i+1]);
2717 InheritException(exception,&(*image)->exception);
2718 break;
2719 }
2720 if (LocaleCompare("resample",option+1) == 0)
2721 {
2722 Image
2723 *resample_image;
2724
2725 /*
2726 Resample image.
2727 */
2728 (void) SyncImageSettings(image_info,*image);
2729 flags=ParseGeometry(argv[i+1],&geometry_info);
2730 if ((flags & SigmaValue) == 0)
2731 geometry_info.sigma=geometry_info.rho;
2732 resample_image=ResampleImage(*image,geometry_info.rho,
2733 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2734 if (resample_image == (Image *) NULL)
2735 break;
2736 *image=DestroyImage(*image);
2737 *image=resample_image;
2738 break;
2739 }
2740 if (LocaleCompare("resize",option+1) == 0)
2741 {
2742 Image
2743 *resize_image;
2744
2745 /*
2746 Resize image.
2747 */
2748 (void) SyncImageSettings(image_info,*image);
2749 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2750 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2751 (*image)->filter,(*image)->blur,exception);
2752 if (resize_image == (Image *) NULL)
2753 break;
2754 *image=DestroyImage(*image);
2755 *image=resize_image;
2756 break;
2757 }
2758 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2759 {
2760 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2761 break;
2762 }
2763 if (LocaleCompare("roll",option+1) == 0)
2764 {
2765 Image
2766 *roll_image;
2767
2768 /*
2769 Roll image.
2770 */
2771 (void) SyncImageSettings(image_info,*image);
2772 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2773 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2774 if (roll_image == (Image *) NULL)
2775 break;
2776 *image=DestroyImage(*image);
2777 *image=roll_image;
2778 break;
2779 }
2780 if (LocaleCompare("rotate",option+1) == 0)
2781 {
2782 char
2783 *geometry;
2784
2785 Image
2786 *rotate_image;
2787
2788 /*
2789 Check for conditional image rotation.
2790 */
2791 (void) SyncImageSettings(image_info,*image);
2792 if (strchr(argv[i+1],'>') != (char *) NULL)
2793 if ((*image)->columns <= (*image)->rows)
2794 break;
2795 if (strchr(argv[i+1],'<') != (char *) NULL)
2796 if ((*image)->columns >= (*image)->rows)
2797 break;
2798 /*
2799 Rotate image.
2800 */
2801 geometry=ConstantString(argv[i+1]);
2802 (void) SubstituteString(&geometry,">","");
2803 (void) SubstituteString(&geometry,"<","");
2804 (void) ParseGeometry(geometry,&geometry_info);
2805 geometry=DestroyString(geometry);
2806 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2807 if (rotate_image == (Image *) NULL)
2808 break;
2809 *image=DestroyImage(*image);
2810 *image=rotate_image;
2811 break;
2812 }
2813 break;
2814 }
2815 case 's':
2816 {
2817 if (LocaleCompare("sample",option+1) == 0)
2818 {
2819 Image
2820 *sample_image;
2821
2822 /*
2823 Sample image with pixel replication.
2824 */
2825 (void) SyncImageSettings(image_info,*image);
2826 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2827 sample_image=SampleImage(*image,geometry.width,geometry.height,
2828 exception);
2829 if (sample_image == (Image *) NULL)
2830 break;
2831 *image=DestroyImage(*image);
2832 *image=sample_image;
2833 break;
2834 }
2835 if (LocaleCompare("scale",option+1) == 0)
2836 {
2837 Image
2838 *scale_image;
2839
2840 /*
2841 Resize image.
2842 */
2843 (void) SyncImageSettings(image_info,*image);
2844 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2845 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2846 exception);
2847 if (scale_image == (Image *) NULL)
2848 break;
2849 *image=DestroyImage(*image);
2850 *image=scale_image;
2851 break;
2852 }
2853 if (LocaleCompare("selective-blur",option+1) == 0)
2854 {
2855 Image
2856 *blur_image;
2857
2858 /*
2859 Selectively blur pixels within a contrast threshold.
2860 */
2861 (void) SyncImageSettings(image_info,*image);
2862 flags=ParseGeometry(argv[i+1],&geometry_info);
2863 if ((flags & PercentValue) != 0)
2864 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2865 blur_image=SelectiveBlurImageChannel(*image,channel,
2866 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2867 if (blur_image == (Image *) NULL)
2868 break;
2869 *image=DestroyImage(*image);
2870 *image=blur_image;
2871 break;
2872 }
2873 if (LocaleCompare("separate",option+1) == 0)
2874 {
2875 Image
2876 *separate_images;
2877
2878 /*
2879 Break channels into separate images.
2880 */
2881 (void) SyncImageSettings(image_info,*image);
2882 separate_images=SeparateImages(*image,channel,exception);
2883 if (separate_images == (Image *) NULL)
2884 break;
2885 *image=DestroyImage(*image);
2886 *image=separate_images;
2887 break;
2888 }
2889 if (LocaleCompare("sepia-tone",option+1) == 0)
2890 {
2891 double
2892 threshold;
2893
2894 Image
2895 *sepia_image;
2896
2897 /*
2898 Sepia-tone image.
2899 */
2900 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002901 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002902 sepia_image=SepiaToneImage(*image,threshold,exception);
2903 if (sepia_image == (Image *) NULL)
2904 break;
2905 *image=DestroyImage(*image);
2906 *image=sepia_image;
2907 break;
2908 }
2909 if (LocaleCompare("segment",option+1) == 0)
2910 {
2911 /*
2912 Segment image.
2913 */
2914 (void) SyncImageSettings(image_info,*image);
2915 flags=ParseGeometry(argv[i+1],&geometry_info);
2916 if ((flags & SigmaValue) == 0)
2917 geometry_info.sigma=1.0;
2918 (void) SegmentImage(*image,(*image)->colorspace,image_info->verbose,
2919 geometry_info.rho,geometry_info.sigma);
2920 InheritException(exception,&(*image)->exception);
2921 break;
2922 }
2923 if (LocaleCompare("set",option+1) == 0)
2924 {
2925 /*
2926 Set image option.
2927 */
2928 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2929 (void) DeleteImageRegistry(argv[i+1]+9);
2930 else
2931 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2932 (void) DeleteImageOption(image_info,argv[i+1]+7);
2933 else
2934 (void) DeleteImageProperty(*image,argv[i+1]);
2935 if (*option == '-')
2936 {
2937 char
2938 *value;
2939
2940 value=InterpretImageProperties(image_info,*image,argv[i+2]);
2941 if (value != (char *) NULL)
2942 {
2943 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2944 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,
2945 value,exception);
2946 else
2947 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2948 {
2949 (void) SetImageOption(image_info,argv[i+1]+7,value);
2950 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2951 }
2952 else
2953 (void) SetImageProperty(*image,argv[i+1],value);
2954 value=DestroyString(value);
2955 }
2956 }
2957 break;
2958 }
2959 if (LocaleCompare("shade",option+1) == 0)
2960 {
2961 Image
2962 *shade_image;
2963
2964 /*
2965 Shade image.
2966 */
2967 (void) SyncImageSettings(image_info,*image);
2968 flags=ParseGeometry(argv[i+1],&geometry_info);
2969 if ((flags & SigmaValue) == 0)
2970 geometry_info.sigma=1.0;
2971 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2972 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2973 if (shade_image == (Image *) NULL)
2974 break;
2975 *image=DestroyImage(*image);
2976 *image=shade_image;
2977 break;
2978 }
2979 if (LocaleCompare("shadow",option+1) == 0)
2980 {
2981 Image
2982 *shadow_image;
2983
2984 /*
2985 Shadow image.
2986 */
2987 (void) SyncImageSettings(image_info,*image);
2988 flags=ParseGeometry(argv[i+1],&geometry_info);
2989 if ((flags & SigmaValue) == 0)
2990 geometry_info.sigma=1.0;
2991 if ((flags & XiValue) == 0)
2992 geometry_info.xi=4.0;
2993 if ((flags & PsiValue) == 0)
2994 geometry_info.psi=4.0;
2995 shadow_image=ShadowImage(*image,geometry_info.rho,
cristy06609ee2010-03-17 20:21:27 +00002996 geometry_info.sigma,(long) floor(geometry_info.xi+0.5),(long)
2997 floor(geometry_info.psi+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002998 if (shadow_image == (Image *) NULL)
2999 break;
3000 *image=DestroyImage(*image);
3001 *image=shadow_image;
3002 break;
3003 }
3004 if (LocaleCompare("sharpen",option+1) == 0)
3005 {
3006 Image
3007 *sharp_image;
3008
3009 /*
3010 Sharpen image.
3011 */
3012 (void) SyncImageSettings(image_info,*image);
3013 flags=ParseGeometry(argv[i+1],&geometry_info);
3014 if ((flags & SigmaValue) == 0)
3015 geometry_info.sigma=1.0;
3016 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
3017 geometry_info.sigma,exception);
3018 if (sharp_image == (Image *) NULL)
3019 break;
3020 *image=DestroyImage(*image);
3021 *image=sharp_image;
3022 break;
3023 }
3024 if (LocaleCompare("shave",option+1) == 0)
3025 {
3026 Image
3027 *shave_image;
3028
3029 /*
3030 Shave the image edges.
3031 */
3032 (void) SyncImageSettings(image_info,*image);
3033 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3034 shave_image=ShaveImage(*image,&geometry,exception);
3035 if (shave_image == (Image *) NULL)
3036 break;
3037 *image=DestroyImage(*image);
3038 *image=shave_image;
3039 break;
3040 }
3041 if (LocaleCompare("shear",option+1) == 0)
3042 {
3043 Image
3044 *shear_image;
3045
3046 /*
3047 Shear image.
3048 */
3049 (void) SyncImageSettings(image_info,*image);
3050 flags=ParseGeometry(argv[i+1],&geometry_info);
3051 if ((flags & SigmaValue) == 0)
3052 geometry_info.sigma=geometry_info.rho;
3053 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3054 exception);
3055 if (shear_image == (Image *) NULL)
3056 break;
3057 *image=DestroyImage(*image);
3058 *image=shear_image;
3059 break;
3060 }
3061 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3062 {
3063 /*
3064 Sigmoidal non-linearity contrast control.
3065 */
3066 (void) SyncImageSettings(image_info,*image);
3067 flags=ParseGeometry(argv[i+1],&geometry_info);
3068 if ((flags & SigmaValue) == 0)
3069 geometry_info.sigma=(double) QuantumRange/2.0;
3070 if ((flags & PercentValue) != 0)
3071 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3072 100.0;
3073 (void) SigmoidalContrastImageChannel(*image,channel,
3074 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3075 geometry_info.sigma);
3076 InheritException(exception,&(*image)->exception);
3077 break;
3078 }
3079 if (LocaleCompare("sketch",option+1) == 0)
3080 {
3081 Image
3082 *sketch_image;
3083
3084 /*
3085 Sketch image.
3086 */
3087 (void) SyncImageSettings(image_info,*image);
3088 flags=ParseGeometry(argv[i+1],&geometry_info);
3089 if ((flags & SigmaValue) == 0)
3090 geometry_info.sigma=1.0;
3091 sketch_image=SketchImage(*image,geometry_info.rho,
3092 geometry_info.sigma,geometry_info.xi,exception);
3093 if (sketch_image == (Image *) NULL)
3094 break;
3095 *image=DestroyImage(*image);
3096 *image=sketch_image;
3097 break;
3098 }
3099 if (LocaleCompare("solarize",option+1) == 0)
3100 {
3101 double
3102 threshold;
3103
3104 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003105 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003106 (void) SolarizeImage(*image,threshold);
3107 InheritException(exception,&(*image)->exception);
3108 break;
3109 }
3110 if (LocaleCompare("sparse-color",option+1) == 0)
3111 {
3112 Image
3113 *sparse_image;
3114
3115 SparseColorMethod
3116 method;
3117
3118 char
3119 *arguments;
3120
3121 /*
3122 Sparse Color Interpolated Gradient
3123 */
3124 (void) SyncImageSettings(image_info,*image);
3125 method=(SparseColorMethod) ParseMagickOption(
3126 MagickSparseColorOptions,MagickFalse,argv[i+1]);
3127 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
3128 InheritException(exception,&(*image)->exception);
3129 if (arguments == (char *) NULL)
3130 break;
3131 sparse_image=SparseColorOption(*image,channel,method,arguments,
3132 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3133 arguments=DestroyString(arguments);
3134 if (sparse_image == (Image *) NULL)
3135 break;
3136 *image=DestroyImage(*image);
3137 *image=sparse_image;
3138 break;
3139 }
3140 if (LocaleCompare("splice",option+1) == 0)
3141 {
3142 Image
3143 *splice_image;
3144
3145 /*
3146 Splice a solid color into the image.
3147 */
3148 (void) SyncImageSettings(image_info,*image);
3149 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3150 splice_image=SpliceImage(*image,&geometry,exception);
3151 if (splice_image == (Image *) NULL)
3152 break;
3153 *image=DestroyImage(*image);
3154 *image=splice_image;
3155 break;
3156 }
3157 if (LocaleCompare("spread",option+1) == 0)
3158 {
3159 Image
3160 *spread_image;
3161
3162 /*
3163 Spread an image.
3164 */
3165 (void) SyncImageSettings(image_info,*image);
3166 (void) ParseGeometry(argv[i+1],&geometry_info);
3167 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3168 if (spread_image == (Image *) NULL)
3169 break;
3170 *image=DestroyImage(*image);
3171 *image=spread_image;
3172 break;
3173 }
3174 if (LocaleCompare("stretch",option+1) == 0)
3175 {
3176 if (*option == '+')
3177 {
3178 draw_info->stretch=UndefinedStretch;
3179 break;
3180 }
3181 draw_info->stretch=(StretchType) ParseMagickOption(
3182 MagickStretchOptions,MagickFalse,argv[i+1]);
3183 break;
3184 }
3185 if (LocaleCompare("strip",option+1) == 0)
3186 {
3187 /*
3188 Strip image of profiles and comments.
3189 */
3190 (void) SyncImageSettings(image_info,*image);
3191 (void) StripImage(*image);
3192 InheritException(exception,&(*image)->exception);
3193 break;
3194 }
3195 if (LocaleCompare("stroke",option+1) == 0)
3196 {
3197 ExceptionInfo
3198 *sans;
3199
3200 if (*option == '+')
3201 {
3202 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3203 if (draw_info->stroke_pattern != (Image *) NULL)
3204 draw_info->stroke_pattern=DestroyImage(
3205 draw_info->stroke_pattern);
3206 break;
3207 }
3208 sans=AcquireExceptionInfo();
3209 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3210 sans=DestroyExceptionInfo(sans);
3211 if (status == MagickFalse)
3212 draw_info->stroke_pattern=GetImageCache(image_info,argv[i+1],
3213 exception);
3214 break;
3215 }
3216 if (LocaleCompare("strokewidth",option+1) == 0)
3217 {
cristyf2f27272009-12-17 14:48:46 +00003218 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003219 break;
3220 }
3221 if (LocaleCompare("style",option+1) == 0)
3222 {
3223 if (*option == '+')
3224 {
3225 draw_info->style=UndefinedStyle;
3226 break;
3227 }
3228 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3229 MagickFalse,argv[i+1]);
3230 break;
3231 }
3232 if (LocaleCompare("swirl",option+1) == 0)
3233 {
3234 Image
3235 *swirl_image;
3236
3237 /*
3238 Swirl image.
3239 */
3240 (void) SyncImageSettings(image_info,*image);
3241 (void) ParseGeometry(argv[i+1],&geometry_info);
3242 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3243 if (swirl_image == (Image *) NULL)
3244 break;
3245 *image=DestroyImage(*image);
3246 *image=swirl_image;
3247 break;
3248 }
3249 break;
3250 }
3251 case 't':
3252 {
3253 if (LocaleCompare("threshold",option+1) == 0)
3254 {
3255 double
3256 threshold;
3257
3258 /*
3259 Threshold image.
3260 */
3261 (void) SyncImageSettings(image_info,*image);
3262 if (*option == '+')
3263 threshold=(double) QuantumRange/2.5;
3264 else
cristyf2f27272009-12-17 14:48:46 +00003265 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003266 (void) BilevelImageChannel(*image,channel,threshold);
3267 InheritException(exception,&(*image)->exception);
3268 break;
3269 }
3270 if (LocaleCompare("thumbnail",option+1) == 0)
3271 {
3272 Image
3273 *thumbnail_image;
3274
3275 /*
3276 Thumbnail image.
3277 */
3278 (void) SyncImageSettings(image_info,*image);
3279 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3280 thumbnail_image=ThumbnailImage(*image,geometry.width,
3281 geometry.height,exception);
3282 if (thumbnail_image == (Image *) NULL)
3283 break;
3284 *image=DestroyImage(*image);
3285 *image=thumbnail_image;
3286 break;
3287 }
3288 if (LocaleCompare("tile",option+1) == 0)
3289 {
3290 if (*option == '+')
3291 {
3292 if (draw_info->fill_pattern != (Image *) NULL)
3293 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3294 break;
3295 }
3296 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
3297 exception);
3298 break;
3299 }
3300 if (LocaleCompare("tint",option+1) == 0)
3301 {
3302 Image
3303 *tint_image;
3304
3305 /*
3306 Tint the image.
3307 */
3308 (void) SyncImageSettings(image_info,*image);
3309 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3310 if (tint_image == (Image *) NULL)
3311 break;
3312 *image=DestroyImage(*image);
3313 *image=tint_image;
3314 break;
3315 }
3316 if (LocaleCompare("transform",option+1) == 0)
3317 {
3318 Image
3319 *transform_image;
3320
3321 /*
3322 Affine transform image.
3323 */
3324 (void) SyncImageSettings(image_info,*image);
3325 transform_image=AffineTransformImage(*image,&draw_info->affine,
3326 exception);
3327 if (transform_image == (Image *) NULL)
3328 break;
3329 *image=DestroyImage(*image);
3330 *image=transform_image;
3331 break;
3332 }
3333 if (LocaleCompare("transparent",option+1) == 0)
3334 {
3335 MagickPixelPacket
3336 target;
3337
3338 (void) SyncImageSettings(image_info,*image);
3339 (void) QueryMagickColor(argv[i+1],&target,exception);
3340 (void) TransparentPaintImage(*image,&target,(Quantum)
3341 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3342 InheritException(exception,&(*image)->exception);
3343 break;
3344 }
3345 if (LocaleCompare("transpose",option+1) == 0)
3346 {
3347 Image
3348 *transpose_image;
3349
3350 /*
3351 Transpose image scanlines.
3352 */
3353 (void) SyncImageSettings(image_info,*image);
3354 transpose_image=TransposeImage(*image,exception);
3355 if (transpose_image == (Image *) NULL)
3356 break;
3357 *image=DestroyImage(*image);
3358 *image=transpose_image;
3359 break;
3360 }
3361 if (LocaleCompare("transverse",option+1) == 0)
3362 {
3363 Image
3364 *transverse_image;
3365
3366 /*
3367 Transverse image scanlines.
3368 */
3369 (void) SyncImageSettings(image_info,*image);
3370 transverse_image=TransverseImage(*image,exception);
3371 if (transverse_image == (Image *) NULL)
3372 break;
3373 *image=DestroyImage(*image);
3374 *image=transverse_image;
3375 break;
3376 }
3377 if (LocaleCompare("treedepth",option+1) == 0)
3378 {
cristye27293e2009-12-18 02:53:20 +00003379 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003380 break;
3381 }
3382 if (LocaleCompare("trim",option+1) == 0)
3383 {
3384 Image
3385 *trim_image;
3386
3387 /*
3388 Trim image.
3389 */
3390 (void) SyncImageSettings(image_info,*image);
3391 trim_image=TrimImage(*image,exception);
3392 if (trim_image == (Image *) NULL)
3393 break;
3394 *image=DestroyImage(*image);
3395 *image=trim_image;
3396 break;
3397 }
3398 if (LocaleCompare("type",option+1) == 0)
3399 {
3400 ImageType
3401 type;
3402
3403 (void) SyncImageSettings(image_info,*image);
3404 if (*option == '+')
3405 type=UndefinedType;
3406 else
3407 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3408 argv[i+1]);
3409 (*image)->type=UndefinedType;
3410 (void) SetImageType(*image,type);
3411 InheritException(exception,&(*image)->exception);
3412 break;
3413 }
3414 break;
3415 }
3416 case 'u':
3417 {
3418 if (LocaleCompare("undercolor",option+1) == 0)
3419 {
3420 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3421 exception);
3422 break;
3423 }
cristy045bd902010-01-30 18:56:24 +00003424 if (LocaleCompare("unique",option+1) == 0)
3425 {
3426 if (*option == '+')
3427 {
3428 (void) DeleteImageArtifact(*image,"identify:unique");
3429 break;
3430 }
3431 (void) SetImageArtifact(*image,"identify:unique","true");
3432 break;
3433 }
cristy3ed852e2009-09-05 21:47:34 +00003434 if (LocaleCompare("unique-colors",option+1) == 0)
3435 {
3436 Image
3437 *unique_image;
3438
3439 /*
3440 Unique image colors.
3441 */
3442 (void) SyncImageSettings(image_info,*image);
3443 unique_image=UniqueImageColors(*image,exception);
3444 if (unique_image == (Image *) NULL)
3445 break;
3446 *image=DestroyImage(*image);
3447 *image=unique_image;
3448 break;
3449 }
3450 if (LocaleCompare("unsharp",option+1) == 0)
3451 {
3452 Image
3453 *unsharp_image;
3454
3455 /*
3456 Unsharp mask image.
3457 */
3458 (void) SyncImageSettings(image_info,*image);
3459 flags=ParseGeometry(argv[i+1],&geometry_info);
3460 if ((flags & SigmaValue) == 0)
3461 geometry_info.sigma=1.0;
3462 if ((flags & XiValue) == 0)
3463 geometry_info.xi=1.0;
3464 if ((flags & PsiValue) == 0)
3465 geometry_info.psi=0.05;
3466 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3467 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3468 geometry_info.psi,exception);
3469 if (unsharp_image == (Image *) NULL)
3470 break;
3471 *image=DestroyImage(*image);
3472 *image=unsharp_image;
3473 break;
3474 }
3475 break;
3476 }
3477 case 'v':
3478 {
3479 if (LocaleCompare("verbose",option+1) == 0)
3480 {
3481 (void) SetImageArtifact(*image,option+1,
3482 *option == '+' ? "false" : "true");
3483 break;
3484 }
3485 if (LocaleCompare("vignette",option+1) == 0)
3486 {
3487 Image
3488 *vignette_image;
3489
3490 /*
3491 Vignette image.
3492 */
3493 (void) SyncImageSettings(image_info,*image);
3494 flags=ParseGeometry(argv[i+1],&geometry_info);
3495 if ((flags & SigmaValue) == 0)
3496 geometry_info.sigma=1.0;
3497 if ((flags & XiValue) == 0)
3498 geometry_info.xi=0.1*(*image)->columns;
3499 if ((flags & PsiValue) == 0)
3500 geometry_info.psi=0.1*(*image)->rows;
3501 vignette_image=VignetteImage(*image,geometry_info.rho,
cristy06609ee2010-03-17 20:21:27 +00003502 geometry_info.sigma,(long) floor(geometry_info.xi+0.5),(long)
3503 floor(geometry_info.psi+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003504 if (vignette_image == (Image *) NULL)
3505 break;
3506 *image=DestroyImage(*image);
3507 *image=vignette_image;
3508 break;
3509 }
3510 if (LocaleCompare("virtual-pixel",option+1) == 0)
3511 {
3512 if (*option == '+')
3513 {
3514 (void) SetImageVirtualPixelMethod(*image,
3515 UndefinedVirtualPixelMethod);
3516 break;
3517 }
3518 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3519 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3520 argv[i+1]));
3521 break;
3522 }
3523 break;
3524 }
3525 case 'w':
3526 {
3527 if (LocaleCompare("wave",option+1) == 0)
3528 {
3529 Image
3530 *wave_image;
3531
3532 /*
3533 Wave image.
3534 */
3535 (void) SyncImageSettings(image_info,*image);
3536 flags=ParseGeometry(argv[i+1],&geometry_info);
3537 if ((flags & SigmaValue) == 0)
3538 geometry_info.sigma=1.0;
3539 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3540 exception);
3541 if (wave_image == (Image *) NULL)
3542 break;
3543 *image=DestroyImage(*image);
3544 *image=wave_image;
3545 break;
3546 }
3547 if (LocaleCompare("weight",option+1) == 0)
3548 {
cristye27293e2009-12-18 02:53:20 +00003549 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003550 if (LocaleCompare(argv[i+1],"all") == 0)
3551 draw_info->weight=0;
3552 if (LocaleCompare(argv[i+1],"bold") == 0)
3553 draw_info->weight=700;
3554 if (LocaleCompare(argv[i+1],"bolder") == 0)
3555 if (draw_info->weight <= 800)
3556 draw_info->weight+=100;
3557 if (LocaleCompare(argv[i+1],"lighter") == 0)
3558 if (draw_info->weight >= 100)
3559 draw_info->weight-=100;
3560 if (LocaleCompare(argv[i+1],"normal") == 0)
3561 draw_info->weight=400;
3562 break;
3563 }
3564 if (LocaleCompare("white-threshold",option+1) == 0)
3565 {
3566 /*
3567 White threshold image.
3568 */
3569 (void) SyncImageSettings(image_info,*image);
3570 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3571 exception);
3572 InheritException(exception,&(*image)->exception);
3573 break;
3574 }
3575 break;
3576 }
3577 default:
3578 break;
3579 }
3580 i+=count;
3581 }
3582 if (region_image != (Image *) NULL)
3583 {
3584 /*
3585 Composite transformed region onto image.
3586 */
3587 (void) SyncImageSettings(image_info,*image);
3588 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3589 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3590 region_geometry.y);
3591 InheritException(exception,&region_image->exception);
3592 *image=DestroyImage(*image);
3593 *image=region_image;
3594 }
3595 /*
3596 Free resources.
3597 */
3598 quantize_info=DestroyQuantizeInfo(quantize_info);
3599 draw_info=DestroyDrawInfo(draw_info);
3600 status=(*image)->exception.severity == UndefinedException ?
3601 MagickTrue : MagickFalse;
3602 return(status);
3603}
3604
3605/*
3606%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3607% %
3608% %
3609% %
3610% M o g r i f y I m a g e C o m m a n d %
3611% %
3612% %
3613% %
3614%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3615%
3616% MogrifyImageCommand() transforms an image or a sequence of images. These
3617% transforms include image scaling, image rotation, color reduction, and
3618% others. The transmogrified image overwrites the original image.
3619%
3620% The format of the MogrifyImageCommand method is:
3621%
3622% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3623% const char **argv,char **metadata,ExceptionInfo *exception)
3624%
3625% A description of each parameter follows:
3626%
3627% o image_info: the image info.
3628%
3629% o argc: the number of elements in the argument vector.
3630%
3631% o argv: A text array containing the command line arguments.
3632%
3633% o metadata: any metadata is returned here.
3634%
3635% o exception: return any errors or warnings in this structure.
3636%
3637*/
3638
3639static MagickBooleanType MogrifyUsage(void)
3640{
3641 static const char
3642 *miscellaneous[]=
3643 {
3644 "-debug events display copious debugging information",
3645 "-help print program options",
3646 "-list type print a list of supported option arguments",
3647 "-log format format of debugging information",
3648 "-version print version information",
3649 (char *) NULL
3650 },
3651 *operators[]=
3652 {
3653 "-adaptive-blur geometry",
3654 " adaptively blur pixels; decrease effect near edges",
3655 "-adaptive-resize geometry",
3656 " adaptively resize image using 'mesh' interpolation",
3657 "-adaptive-sharpen geometry",
3658 " adaptively sharpen pixels; increase effect near edges",
3659 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3660 " transparent, extract, background, or shape",
3661 "-annotate geometry text",
3662 " annotate the image with text",
3663 "-auto-gamma automagically adjust gamma level of image",
3664 "-auto-level automagically adjust color levels of image",
3665 "-auto-orient automagically orient (rotate) image",
3666 "-bench iterations measure performance",
3667 "-black-threshold value",
3668 " force all pixels below the threshold into black",
3669 "-blue-shift simulate a scene at nighttime in the moonlight",
3670 "-blur geometry reduce image noise and reduce detail levels",
3671 "-border geometry surround image with a border of color",
3672 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003673 "-brightness-contrast geometry",
3674 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003675 "-cdl filename color correct with a color decision list",
3676 "-charcoal radius simulate a charcoal drawing",
3677 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003678 "-clamp restrict pixel range from 0 to the quantum depth",
cristy3ed852e2009-09-05 21:47:34 +00003679 "-clip clip along the first path from the 8BIM profile",
3680 "-clip-mask filename associate a clip mask with the image",
3681 "-clip-path id clip along a named path from the 8BIM profile",
3682 "-colorize value colorize the image with the fill color",
3683 "-contrast enhance or reduce the image contrast",
3684 "-contrast-stretch geometry",
3685 " improve contrast by `stretching' the intensity range",
3686 "-convolve coefficients",
3687 " apply a convolution kernel to the image",
3688 "-cycle amount cycle the image colormap",
3689 "-decipher filename convert cipher pixels to plain pixels",
3690 "-deskew threshold straighten an image",
3691 "-despeckle reduce the speckles within an image",
3692 "-distort method args",
3693 " distort images according to given method ad args",
3694 "-draw string annotate the image with a graphic primitive",
3695 "-edge radius apply a filter to detect edges in the image",
3696 "-encipher filename convert plain pixels to cipher pixels",
3697 "-emboss radius emboss an image",
3698 "-enhance apply a digital filter to enhance a noisy image",
3699 "-equalize perform histogram equalization to an image",
3700 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003701 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003702 "-extent geometry set the image size",
3703 "-extract geometry extract area from image",
3704 "-fft implements the discrete Fourier transform (DFT)",
3705 "-flip flip image vertically",
3706 "-floodfill geometry color",
3707 " floodfill the image with color",
3708 "-flop flop image horizontally",
3709 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003710 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003711 " apply function over image values",
3712 "-gamma value level of gamma correction",
3713 "-gaussian-blur geometry",
3714 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003715 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003716 "-identify identify the format and characteristics of the image",
3717 "-ift implements the inverse discrete Fourier transform (DFT)",
3718 "-implode amount implode image pixels about the center",
3719 "-lat geometry local adaptive thresholding",
3720 "-layers method optimize, merge, or compare image layers",
3721 "-level value adjust the level of image contrast",
3722 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003723 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003724 "-linear-stretch geometry",
3725 " improve contrast by `stretching with saturation'",
3726 "-liquid-rescale geometry",
3727 " rescale image with seam-carving",
3728 "-median radius apply a median filter to the image",
3729 "-modulate value vary the brightness, saturation, and hue",
3730 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003731 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003732 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003733 "-motion-blur geometry",
3734 " simulate motion blur",
3735 "-negate replace every pixel with its complementary color ",
3736 "-noise radius add or reduce noise in an image",
3737 "-normalize transform image to span the full range of colors",
3738 "-opaque color change this color to the fill color",
3739 "-ordered-dither NxN",
3740 " add a noise pattern to the image with specific",
3741 " amplitudes",
3742 "-paint radius simulate an oil painting",
3743 "-polaroid angle simulate a Polaroid picture",
3744 "-posterize levels reduce the image to a limited number of color levels",
3745 "-print string interpret string and print to console",
3746 "-profile filename add, delete, or apply an image profile",
3747 "-quantize colorspace reduce colors in this colorspace",
3748 "-radial-blur angle radial blur the image",
3749 "-raise value lighten/darken image edges to create a 3-D effect",
3750 "-random-threshold low,high",
3751 " random threshold the image",
3752 "-recolor matrix translate, scale, shear, or rotate image colors",
3753 "-region geometry apply options to a portion of the image",
3754 "-render render vector graphics",
3755 "-repage geometry size and location of an image canvas",
3756 "-resample geometry change the resolution of an image",
3757 "-resize geometry resize the image",
3758 "-roll geometry roll an image vertically or horizontally",
3759 "-rotate degrees apply Paeth rotation to the image",
3760 "-sample geometry scale image with pixel sampling",
3761 "-scale geometry scale the image",
3762 "-segment values segment an image",
3763 "-selective-blur geometry",
3764 " selectively blur pixels within a contrast threshold",
3765 "-sepia-tone threshold",
3766 " simulate a sepia-toned photo",
3767 "-set property value set an image property",
3768 "-shade degrees shade the image using a distant light source",
3769 "-shadow geometry simulate an image shadow",
3770 "-sharpen geometry sharpen the image",
3771 "-shave geometry shave pixels from the image edges",
3772 "-shear geometry slide one edge of the image along the X or Y axis",
3773 "-sigmoidal-contrast geometry",
3774 " increase the contrast without saturating highlights or shadows",
3775 "-sketch geometry simulate a pencil sketch",
3776 "-solarize threshold negate all pixels above the threshold level",
3777 "-sparse-color method args",
3778 " fill in a image based on a few color points",
3779 "-splice geometry splice the background color into the image",
3780 "-spread radius displace image pixels by a random amount",
3781 "-strip strip image of all profiles and comments",
3782 "-swirl degrees swirl image pixels about the center",
3783 "-threshold value threshold the image",
3784 "-thumbnail geometry create a thumbnail of the image",
3785 "-tile filename tile image when filling a graphic primitive",
3786 "-tint value tint the image with the fill color",
3787 "-transform affine transform image",
3788 "-transparent color make this color transparent within the image",
3789 "-transpose flip image vertically and rotate 90 degrees",
3790 "-transverse flop image horizontally and rotate 270 degrees",
3791 "-trim trim image edges",
3792 "-type type image type",
3793 "-unique-colors discard all but one of any pixel color",
3794 "-unsharp geometry sharpen the image",
3795 "-vignette geometry soften the edges of the image in vignette style",
3796 "-wave geometry alter an image along a sine wave",
3797 "-white-threshold value",
3798 " force all pixels above the threshold into white",
3799 (char *) NULL
3800 },
3801 *sequence_operators[]=
3802 {
3803 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003804 "-clut apply a color lookup table to the image",
3805 "-coalesce merge a sequence of images",
3806 "-combine combine a sequence of images",
3807 "-composite composite image",
3808 "-crop geometry cut out a rectangular region of the image",
3809 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003810 "-evaluate-sequence operator",
3811 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003812 "-flatten flatten a sequence of images",
3813 "-fx expression apply mathematical expression to an image channel(s)",
3814 "-hald-clut apply a Hald color lookup table to the image",
3815 "-morph value morph an image sequence",
3816 "-mosaic create a mosaic from an image sequence",
3817 "-process arguments process the image with a custom image filter",
3818 "-reverse reverse image sequence",
3819 "-separate separate an image channel into a grayscale image",
3820 "-write filename write images to this file",
3821 (char *) NULL
3822 },
3823 *settings[]=
3824 {
3825 "-adjoin join images into a single multi-image file",
3826 "-affine matrix affine transform matrix",
3827 "-alpha option activate, deactivate, reset, or set the alpha channel",
3828 "-antialias remove pixel-aliasing",
3829 "-authenticate password",
3830 " decipher image with this password",
3831 "-attenuate value lessen (or intensify) when adding noise to an image",
3832 "-background color background color",
3833 "-bias value add bias when convolving an image",
3834 "-black-point-compensation",
3835 " use black point compensation",
3836 "-blue-primary point chromaticity blue primary point",
3837 "-bordercolor color border color",
3838 "-caption string assign a caption to an image",
3839 "-channel type apply option to select image channels",
3840 "-colors value preferred number of colors in the image",
3841 "-colorspace type alternate image colorspace",
3842 "-comment string annotate image with comment",
3843 "-compose operator set image composite operator",
3844 "-compress type type of pixel compression when writing the image",
3845 "-define format:option",
3846 " define one or more image format options",
3847 "-delay value display the next image after pausing",
3848 "-density geometry horizontal and vertical density of the image",
3849 "-depth value image depth",
3850 "-display server get image or font from this X server",
3851 "-dispose method layer disposal method",
3852 "-dither method apply error diffusion to image",
3853 "-encoding type text encoding type",
3854 "-endian type endianness (MSB or LSB) of the image",
3855 "-family name render text with this font family",
3856 "-fill color color to use when filling a graphic primitive",
3857 "-filter type use this filter when resizing an image",
3858 "-font name render text with this font",
3859 "-format \"string\" output formatted image characteristics",
3860 "-fuzz distance colors within this distance are considered equal",
3861 "-gravity type horizontal and vertical text placement",
3862 "-green-primary point chromaticity green primary point",
3863 "-intent type type of rendering intent when managing the image color",
3864 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003865 "-interline-spacing value",
3866 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003867 "-interpolate method pixel color interpolation method",
3868 "-interword-spacing value",
3869 " set the space between two words",
3870 "-kerning value set the space between two letters",
3871 "-label string assign a label to an image",
3872 "-limit type value pixel cache resource limit",
3873 "-loop iterations add Netscape loop extension to your GIF animation",
3874 "-mask filename associate a mask with the image",
3875 "-mattecolor color frame color",
3876 "-monitor monitor progress",
3877 "-orient type image orientation",
3878 "-page geometry size and location of an image canvas (setting)",
3879 "-ping efficiently determine image attributes",
3880 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003881 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003882 "-preview type image preview type",
3883 "-quality value JPEG/MIFF/PNG compression level",
3884 "-quiet suppress all warning messages",
3885 "-red-primary point chromaticity red primary point",
3886 "-regard-warnings pay attention to warning messages",
3887 "-remap filename transform image colors to match this set of colors",
3888 "-respect-parentheses settings remain in effect until parenthesis boundary",
3889 "-sampling-factor geometry",
3890 " horizontal and vertical sampling factor",
3891 "-scene value image scene number",
3892 "-seed value seed a new sequence of pseudo-random numbers",
3893 "-size geometry width and height of image",
3894 "-stretch type render text with this font stretch",
3895 "-stroke color graphic primitive stroke color",
3896 "-strokewidth value graphic primitive stroke width",
3897 "-style type render text with this font style",
3898 "-taint image as ineligible for bi-modal delegate",
3899 "-texture filename name of texture to tile onto the image background",
3900 "-tile-offset geometry",
3901 " tile offset",
3902 "-treedepth value color tree depth",
3903 "-transparent-color color",
3904 " transparent color",
3905 "-undercolor color annotation bounding box color",
3906 "-units type the units of image resolution",
3907 "-verbose print detailed information about the image",
3908 "-view FlashPix viewing transforms",
3909 "-virtual-pixel method",
3910 " virtual pixel access method",
3911 "-weight type render text with this font weight",
3912 "-white-point point chromaticity white point",
3913 (char *) NULL
3914 },
3915 *stack_operators[]=
3916 {
3917 "-clone index clone an image",
3918 "-delete index delete the image from the image sequence",
3919 "-insert index insert last image into the image sequence",
3920 "-swap indexes swap two images in the image sequence",
3921 (char *) NULL
3922 };
3923
3924 const char
3925 **p;
3926
3927 (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003928 (void) printf("Copyright: %s\n",GetMagickCopyright());
3929 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003930 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3931 GetClientName());
3932 (void) printf("\nImage Settings:\n");
3933 for (p=settings; *p != (char *) NULL; p++)
3934 (void) printf(" %s\n",*p);
3935 (void) printf("\nImage Operators:\n");
3936 for (p=operators; *p != (char *) NULL; p++)
3937 (void) printf(" %s\n",*p);
3938 (void) printf("\nImage Sequence Operators:\n");
3939 for (p=sequence_operators; *p != (char *) NULL; p++)
3940 (void) printf(" %s\n",*p);
3941 (void) printf("\nImage Stack Operators:\n");
3942 for (p=stack_operators; *p != (char *) NULL; p++)
3943 (void) printf(" %s\n",*p);
3944 (void) printf("\nMiscellaneous Options:\n");
3945 for (p=miscellaneous; *p != (char *) NULL; p++)
3946 (void) printf(" %s\n",*p);
3947 (void) printf(
3948 "\nBy default, the image format of `file' is determined by its magic\n");
3949 (void) printf(
3950 "number. To specify a particular image format, precede the filename\n");
3951 (void) printf(
3952 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3953 (void) printf(
3954 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3955 (void) printf("'-' for standard input or output.\n");
3956 return(MagickFalse);
3957}
3958
3959WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3960 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3961{
3962#define DestroyMogrify() \
3963{ \
3964 if (format != (char *) NULL) \
3965 format=DestroyString(format); \
3966 if (path != (char *) NULL) \
3967 path=DestroyString(path); \
3968 DestroyImageStack(); \
3969 for (i=0; i < (long) argc; i++) \
3970 argv[i]=DestroyString(argv[i]); \
3971 argv=(char **) RelinquishMagickMemory(argv); \
3972}
3973#define ThrowMogrifyException(asperity,tag,option) \
3974{ \
3975 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3976 option); \
3977 DestroyMogrify(); \
3978 return(MagickFalse); \
3979}
3980#define ThrowMogrifyInvalidArgumentException(option,argument) \
3981{ \
3982 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3983 "InvalidArgument","`%s': %s",argument,option); \
3984 DestroyMogrify(); \
3985 return(MagickFalse); \
3986}
3987
3988 char
3989 *format,
3990 *option,
3991 *path;
3992
3993 Image
3994 *image;
3995
3996 ImageStack
3997 image_stack[MaxImageStackDepth+1];
3998
3999 long
4000 j,
4001 k;
4002
4003 register long
4004 i;
4005
4006 MagickBooleanType
4007 global_colormap;
4008
4009 MagickBooleanType
4010 fire,
4011 pend;
4012
4013 MagickStatusType
4014 status;
4015
4016 /*
4017 Set defaults.
4018 */
4019 assert(image_info != (ImageInfo *) NULL);
4020 assert(image_info->signature == MagickSignature);
4021 if (image_info->debug != MagickFalse)
4022 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4023 assert(exception != (ExceptionInfo *) NULL);
4024 if (argc == 2)
4025 {
4026 option=argv[1];
4027 if ((LocaleCompare("version",option+1) == 0) ||
4028 (LocaleCompare("-version",option+1) == 0))
4029 {
4030 (void) fprintf(stdout,"Version: %s\n",
4031 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004032 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4033 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004034 return(MagickFalse);
4035 }
4036 }
4037 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004038 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004039 format=(char *) NULL;
4040 path=(char *) NULL;
4041 global_colormap=MagickFalse;
4042 k=0;
4043 j=1;
4044 NewImageStack();
4045 option=(char *) NULL;
4046 pend=MagickFalse;
4047 status=MagickTrue;
4048 /*
4049 Parse command line.
4050 */
4051 ReadCommandlLine(argc,&argv);
4052 status=ExpandFilenames(&argc,&argv);
4053 if (status == MagickFalse)
4054 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4055 GetExceptionMessage(errno));
4056 for (i=1; i < (long) argc; i++)
4057 {
4058 option=argv[i];
4059 if (LocaleCompare(option,"(") == 0)
4060 {
4061 FireImageStack(MagickFalse,MagickTrue,pend);
4062 if (k == MaxImageStackDepth)
4063 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4064 option);
4065 PushImageStack();
4066 continue;
4067 }
4068 if (LocaleCompare(option,")") == 0)
4069 {
4070 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4071 if (k == 0)
4072 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4073 PopImageStack();
4074 continue;
4075 }
4076 if (IsMagickOption(option) == MagickFalse)
4077 {
4078 char
4079 backup_filename[MaxTextExtent],
4080 *filename;
4081
4082 Image
4083 *images;
4084
4085 /*
4086 Option is a file name: begin by reading image from specified file.
4087 */
4088 FireImageStack(MagickFalse,MagickFalse,pend);
4089 filename=argv[i];
4090 if ((LocaleCompare(filename,"--") == 0) && (i < (argc-1)))
4091 filename=argv[++i];
4092 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4093 images=ReadImages(image_info,exception);
4094 status&=(images != (Image *) NULL) &&
4095 (exception->severity < ErrorException);
4096 if (images == (Image *) NULL)
4097 continue;
4098 if (path != (char *) NULL)
4099 {
4100 GetPathComponent(option,TailPath,filename);
4101 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4102 path,*DirectorySeparator,filename);
4103 }
4104 if (format != (char *) NULL)
4105 AppendImageFormat(format,images->filename);
4106 AppendImageStack(images);
4107 FinalizeImageSettings(image_info,image,MagickFalse);
4108 if (global_colormap != MagickFalse)
4109 {
4110 QuantizeInfo
4111 *quantize_info;
4112
4113 quantize_info=AcquireQuantizeInfo(image_info);
4114 (void) RemapImages(quantize_info,images,(Image *) NULL);
4115 quantize_info=DestroyQuantizeInfo(quantize_info);
4116 }
4117 *backup_filename='\0';
4118 if ((LocaleCompare(image->filename,"-") != 0) &&
4119 (IsPathWritable(image->filename) != MagickFalse))
4120 {
4121 register long
4122 i;
4123
4124 /*
4125 Rename image file as backup.
4126 */
4127 (void) CopyMagickString(backup_filename,image->filename,
4128 MaxTextExtent);
4129 for (i=0; i < 6; i++)
4130 {
4131 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4132 if (IsPathAccessible(backup_filename) == MagickFalse)
4133 break;
4134 }
4135 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4136 (rename(image->filename,backup_filename) != 0))
4137 *backup_filename='\0';
4138 }
4139 /*
4140 Write transmogrified image to disk.
4141 */
4142 image_info->synchronize=MagickTrue;
4143 status&=WriteImages(image_info,image,image->filename,exception);
4144 if ((status == MagickFalse) && (*backup_filename != '\0'))
4145 (void) remove(backup_filename);
4146 RemoveAllImageStack();
4147 continue;
4148 }
4149 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4150 switch (*(option+1))
4151 {
4152 case 'a':
4153 {
4154 if (LocaleCompare("adaptive-blur",option+1) == 0)
4155 {
4156 i++;
4157 if (i == (long) argc)
4158 ThrowMogrifyException(OptionError,"MissingArgument",option);
4159 if (IsGeometry(argv[i]) == MagickFalse)
4160 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4161 break;
4162 }
4163 if (LocaleCompare("adaptive-resize",option+1) == 0)
4164 {
4165 i++;
4166 if (i == (long) argc)
4167 ThrowMogrifyException(OptionError,"MissingArgument",option);
4168 if (IsGeometry(argv[i]) == MagickFalse)
4169 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4170 break;
4171 }
4172 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4173 {
4174 i++;
4175 if (i == (long) argc)
4176 ThrowMogrifyException(OptionError,"MissingArgument",option);
4177 if (IsGeometry(argv[i]) == MagickFalse)
4178 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4179 break;
4180 }
4181 if (LocaleCompare("affine",option+1) == 0)
4182 {
4183 if (*option == '+')
4184 break;
4185 i++;
4186 if (i == (long) argc)
4187 ThrowMogrifyException(OptionError,"MissingArgument",option);
4188 if (IsGeometry(argv[i]) == MagickFalse)
4189 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4190 break;
4191 }
4192 if (LocaleCompare("alpha",option+1) == 0)
4193 {
4194 long
4195 type;
4196
4197 if (*option == '+')
4198 break;
4199 i++;
4200 if (i == (long) argc)
4201 ThrowMogrifyException(OptionError,"MissingArgument",option);
4202 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4203 if (type < 0)
4204 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4205 argv[i]);
4206 break;
4207 }
4208 if (LocaleCompare("annotate",option+1) == 0)
4209 {
4210 if (*option == '+')
4211 break;
4212 i++;
4213 if (i == (long) argc)
4214 ThrowMogrifyException(OptionError,"MissingArgument",option);
4215 if (IsGeometry(argv[i]) == MagickFalse)
4216 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4217 if (i == (long) argc)
4218 ThrowMogrifyException(OptionError,"MissingArgument",option);
4219 i++;
4220 break;
4221 }
4222 if (LocaleCompare("antialias",option+1) == 0)
4223 break;
4224 if (LocaleCompare("append",option+1) == 0)
4225 break;
4226 if (LocaleCompare("attenuate",option+1) == 0)
4227 {
4228 if (*option == '+')
4229 break;
4230 i++;
4231 if (i == (long) (argc-1))
4232 ThrowMogrifyException(OptionError,"MissingArgument",option);
4233 if (IsGeometry(argv[i]) == MagickFalse)
4234 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4235 break;
4236 }
4237 if (LocaleCompare("authenticate",option+1) == 0)
4238 {
4239 if (*option == '+')
4240 break;
4241 i++;
4242 if (i == (long) argc)
4243 ThrowMogrifyException(OptionError,"MissingArgument",option);
4244 break;
4245 }
4246 if (LocaleCompare("auto-gamma",option+1) == 0)
4247 break;
4248 if (LocaleCompare("auto-level",option+1) == 0)
4249 break;
4250 if (LocaleCompare("auto-orient",option+1) == 0)
4251 break;
4252 if (LocaleCompare("average",option+1) == 0)
4253 break;
4254 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4255 }
4256 case 'b':
4257 {
4258 if (LocaleCompare("background",option+1) == 0)
4259 {
4260 if (*option == '+')
4261 break;
4262 i++;
4263 if (i == (long) argc)
4264 ThrowMogrifyException(OptionError,"MissingArgument",option);
4265 break;
4266 }
4267 if (LocaleCompare("bias",option+1) == 0)
4268 {
4269 if (*option == '+')
4270 break;
4271 i++;
4272 if (i == (long) (argc-1))
4273 ThrowMogrifyException(OptionError,"MissingArgument",option);
4274 if (IsGeometry(argv[i]) == MagickFalse)
4275 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4276 break;
4277 }
4278 if (LocaleCompare("black-point-compensation",option+1) == 0)
4279 break;
4280 if (LocaleCompare("black-threshold",option+1) == 0)
4281 {
4282 if (*option == '+')
4283 break;
4284 i++;
4285 if (i == (long) argc)
4286 ThrowMogrifyException(OptionError,"MissingArgument",option);
4287 if (IsGeometry(argv[i]) == MagickFalse)
4288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4289 break;
4290 }
4291 if (LocaleCompare("blue-primary",option+1) == 0)
4292 {
4293 if (*option == '+')
4294 break;
4295 i++;
4296 if (i == (long) argc)
4297 ThrowMogrifyException(OptionError,"MissingArgument",option);
4298 if (IsGeometry(argv[i]) == MagickFalse)
4299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4300 break;
4301 }
4302 if (LocaleCompare("blue-shift",option+1) == 0)
4303 {
4304 i++;
4305 if (i == (long) argc)
4306 ThrowMogrifyException(OptionError,"MissingArgument",option);
4307 if (IsGeometry(argv[i]) == MagickFalse)
4308 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4309 break;
4310 }
4311 if (LocaleCompare("blur",option+1) == 0)
4312 {
4313 i++;
4314 if (i == (long) argc)
4315 ThrowMogrifyException(OptionError,"MissingArgument",option);
4316 if (IsGeometry(argv[i]) == MagickFalse)
4317 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4318 break;
4319 }
4320 if (LocaleCompare("border",option+1) == 0)
4321 {
4322 if (*option == '+')
4323 break;
4324 i++;
4325 if (i == (long) argc)
4326 ThrowMogrifyException(OptionError,"MissingArgument",option);
4327 if (IsGeometry(argv[i]) == MagickFalse)
4328 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4329 break;
4330 }
4331 if (LocaleCompare("bordercolor",option+1) == 0)
4332 {
4333 if (*option == '+')
4334 break;
4335 i++;
4336 if (i == (long) argc)
4337 ThrowMogrifyException(OptionError,"MissingArgument",option);
4338 break;
4339 }
4340 if (LocaleCompare("box",option+1) == 0)
4341 {
4342 if (*option == '+')
4343 break;
4344 i++;
4345 if (i == (long) argc)
4346 ThrowMogrifyException(OptionError,"MissingArgument",option);
4347 break;
4348 }
cristya28d6b82010-01-11 20:03:47 +00004349 if (LocaleCompare("brightness-contrast",option+1) == 0)
4350 {
4351 i++;
4352 if (i == (long) argc)
4353 ThrowMogrifyException(OptionError,"MissingArgument",option);
4354 if (IsGeometry(argv[i]) == MagickFalse)
4355 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4356 break;
4357 }
cristy3ed852e2009-09-05 21:47:34 +00004358 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4359 }
4360 case 'c':
4361 {
4362 if (LocaleCompare("cache",option+1) == 0)
4363 {
4364 if (*option == '+')
4365 break;
4366 i++;
4367 if (i == (long) argc)
4368 ThrowMogrifyException(OptionError,"MissingArgument",option);
4369 if (IsGeometry(argv[i]) == MagickFalse)
4370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4371 break;
4372 }
4373 if (LocaleCompare("caption",option+1) == 0)
4374 {
4375 if (*option == '+')
4376 break;
4377 i++;
4378 if (i == (long) argc)
4379 ThrowMogrifyException(OptionError,"MissingArgument",option);
4380 break;
4381 }
4382 if (LocaleCompare("channel",option+1) == 0)
4383 {
4384 long
4385 channel;
4386
4387 if (*option == '+')
4388 break;
4389 i++;
4390 if (i == (long) (argc-1))
4391 ThrowMogrifyException(OptionError,"MissingArgument",option);
4392 channel=ParseChannelOption(argv[i]);
4393 if (channel < 0)
4394 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4395 argv[i]);
4396 break;
4397 }
4398 if (LocaleCompare("cdl",option+1) == 0)
4399 {
4400 if (*option == '+')
4401 break;
4402 i++;
4403 if (i == (long) (argc-1))
4404 ThrowMogrifyException(OptionError,"MissingArgument",option);
4405 break;
4406 }
4407 if (LocaleCompare("charcoal",option+1) == 0)
4408 {
4409 if (*option == '+')
4410 break;
4411 i++;
4412 if (i == (long) argc)
4413 ThrowMogrifyException(OptionError,"MissingArgument",option);
4414 if (IsGeometry(argv[i]) == MagickFalse)
4415 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4416 break;
4417 }
4418 if (LocaleCompare("chop",option+1) == 0)
4419 {
4420 if (*option == '+')
4421 break;
4422 i++;
4423 if (i == (long) argc)
4424 ThrowMogrifyException(OptionError,"MissingArgument",option);
4425 if (IsGeometry(argv[i]) == MagickFalse)
4426 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4427 break;
4428 }
cristy1eb45dd2009-09-25 16:38:06 +00004429 if (LocaleCompare("clamp",option+1) == 0)
4430 break;
4431 if (LocaleCompare("clip",option+1) == 0)
4432 break;
cristy3ed852e2009-09-05 21:47:34 +00004433 if (LocaleCompare("clip-mask",option+1) == 0)
4434 {
4435 if (*option == '+')
4436 break;
4437 i++;
4438 if (i == (long) argc)
4439 ThrowMogrifyException(OptionError,"MissingArgument",option);
4440 break;
4441 }
4442 if (LocaleCompare("clut",option+1) == 0)
4443 break;
4444 if (LocaleCompare("coalesce",option+1) == 0)
4445 break;
4446 if (LocaleCompare("colorize",option+1) == 0)
4447 {
4448 if (*option == '+')
4449 break;
4450 i++;
4451 if (i == (long) argc)
4452 ThrowMogrifyException(OptionError,"MissingArgument",option);
4453 if (IsGeometry(argv[i]) == MagickFalse)
4454 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4455 break;
4456 }
4457 if (LocaleCompare("colors",option+1) == 0)
4458 {
4459 if (*option == '+')
4460 break;
4461 i++;
4462 if (i == (long) argc)
4463 ThrowMogrifyException(OptionError,"MissingArgument",option);
4464 if (IsGeometry(argv[i]) == MagickFalse)
4465 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4466 break;
4467 }
4468 if (LocaleCompare("colorspace",option+1) == 0)
4469 {
4470 long
4471 colorspace;
4472
4473 if (*option == '+')
4474 break;
4475 i++;
4476 if (i == (long) argc)
4477 ThrowMogrifyException(OptionError,"MissingArgument",option);
4478 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4479 argv[i]);
4480 if (colorspace < 0)
4481 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4482 argv[i]);
4483 break;
4484 }
4485 if (LocaleCompare("combine",option+1) == 0)
4486 break;
4487 if (LocaleCompare("comment",option+1) == 0)
4488 {
4489 if (*option == '+')
4490 break;
4491 i++;
4492 if (i == (long) argc)
4493 ThrowMogrifyException(OptionError,"MissingArgument",option);
4494 break;
4495 }
4496 if (LocaleCompare("composite",option+1) == 0)
4497 break;
4498 if (LocaleCompare("compress",option+1) == 0)
4499 {
4500 long
4501 compress;
4502
4503 if (*option == '+')
4504 break;
4505 i++;
4506 if (i == (long) argc)
4507 ThrowMogrifyException(OptionError,"MissingArgument",option);
4508 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4509 argv[i]);
4510 if (compress < 0)
4511 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4512 argv[i]);
4513 break;
4514 }
cristy22879752009-10-25 23:55:40 +00004515 if (LocaleCompare("concurrent",option+1) == 0)
4516 break;
cristy3ed852e2009-09-05 21:47:34 +00004517 if (LocaleCompare("contrast",option+1) == 0)
4518 break;
4519 if (LocaleCompare("contrast-stretch",option+1) == 0)
4520 {
4521 i++;
4522 if (i == (long) argc)
4523 ThrowMogrifyException(OptionError,"MissingArgument",option);
4524 if (IsGeometry(argv[i]) == MagickFalse)
4525 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4526 break;
4527 }
4528 if (LocaleCompare("convolve",option+1) == 0)
4529 {
anthony29188a82010-01-22 10:12:34 +00004530 char
4531 token[MaxTextExtent];
4532
cristy3ed852e2009-09-05 21:47:34 +00004533 if (*option == '+')
4534 break;
4535 i++;
4536 if (i == (long) argc)
4537 ThrowMogrifyException(OptionError,"MissingArgument",option);
anthony29188a82010-01-22 10:12:34 +00004538#if 1
cristydfbe6ca2010-03-12 14:08:17 +00004539 (void) token;
cristy3ed852e2009-09-05 21:47:34 +00004540 if (IsGeometry(argv[i]) == MagickFalse)
4541 ThrowMogrifyInvalidArgumentException(option,argv[i]);
anthony29188a82010-01-22 10:12:34 +00004542#else
4543 /* Allow the use of built-in kernels like 'gaussian'
4544 * These may not work for kernels with 'nan' values, like 'diamond'
4545 */
4546 GetMagickToken(argv[i],NULL,token);
4547 if ( isalpha((int)token[0]) )
4548 {
4549 long
4550 op;
4551
4552 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
4553 if (op < 0)
4554 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
4555 token);
4556 }
4557 /* geometry current returns invalid if 'nan' values are used */
4558 else if (IsGeometry(argv[i]) == MagickFalse)
4559 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4560#endif
cristy3ed852e2009-09-05 21:47:34 +00004561 break;
4562 }
4563 if (LocaleCompare("crop",option+1) == 0)
4564 {
4565 if (*option == '+')
4566 break;
4567 i++;
4568 if (i == (long) argc)
4569 ThrowMogrifyException(OptionError,"MissingArgument",option);
4570 if (IsGeometry(argv[i]) == MagickFalse)
4571 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4572 break;
4573 }
4574 if (LocaleCompare("cycle",option+1) == 0)
4575 {
4576 if (*option == '+')
4577 break;
4578 i++;
4579 if (i == (long) argc)
4580 ThrowMogrifyException(OptionError,"MissingArgument",option);
4581 if (IsGeometry(argv[i]) == MagickFalse)
4582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4583 break;
4584 }
4585 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4586 }
4587 case 'd':
4588 {
4589 if (LocaleCompare("decipher",option+1) == 0)
4590 {
4591 if (*option == '+')
4592 break;
4593 i++;
4594 if (i == (long) (argc-1))
4595 ThrowMogrifyException(OptionError,"MissingArgument",option);
4596 break;
4597 }
4598 if (LocaleCompare("deconstruct",option+1) == 0)
4599 break;
4600 if (LocaleCompare("debug",option+1) == 0)
4601 {
4602 long
4603 event;
4604
4605 if (*option == '+')
4606 break;
4607 i++;
4608 if (i == (long) argc)
4609 ThrowMogrifyException(OptionError,"MissingArgument",option);
4610 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4611 if (event < 0)
4612 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4613 argv[i]);
4614 (void) SetLogEventMask(argv[i]);
4615 break;
4616 }
4617 if (LocaleCompare("define",option+1) == 0)
4618 {
4619 i++;
4620 if (i == (long) argc)
4621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 if (*option == '+')
4623 {
4624 const char
4625 *define;
4626
4627 define=GetImageOption(image_info,argv[i]);
4628 if (define == (const char *) NULL)
4629 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4630 break;
4631 }
4632 break;
4633 }
4634 if (LocaleCompare("delay",option+1) == 0)
4635 {
4636 if (*option == '+')
4637 break;
4638 i++;
4639 if (i == (long) argc)
4640 ThrowMogrifyException(OptionError,"MissingArgument",option);
4641 if (IsGeometry(argv[i]) == MagickFalse)
4642 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4643 break;
4644 }
4645 if (LocaleCompare("density",option+1) == 0)
4646 {
4647 if (*option == '+')
4648 break;
4649 i++;
4650 if (i == (long) argc)
4651 ThrowMogrifyException(OptionError,"MissingArgument",option);
4652 if (IsGeometry(argv[i]) == MagickFalse)
4653 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4654 break;
4655 }
4656 if (LocaleCompare("depth",option+1) == 0)
4657 {
4658 if (*option == '+')
4659 break;
4660 i++;
4661 if (i == (long) argc)
4662 ThrowMogrifyException(OptionError,"MissingArgument",option);
4663 if (IsGeometry(argv[i]) == MagickFalse)
4664 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4665 break;
4666 }
4667 if (LocaleCompare("deskew",option+1) == 0)
4668 {
4669 if (*option == '+')
4670 break;
4671 i++;
4672 if (i == (long) argc)
4673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 if (IsGeometry(argv[i]) == MagickFalse)
4675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676 break;
4677 }
4678 if (LocaleCompare("despeckle",option+1) == 0)
4679 break;
4680 if (LocaleCompare("dft",option+1) == 0)
4681 break;
4682 if (LocaleCompare("display",option+1) == 0)
4683 {
4684 if (*option == '+')
4685 break;
4686 i++;
4687 if (i == (long) argc)
4688 ThrowMogrifyException(OptionError,"MissingArgument",option);
4689 break;
4690 }
4691 if (LocaleCompare("dispose",option+1) == 0)
4692 {
4693 long
4694 dispose;
4695
4696 if (*option == '+')
4697 break;
4698 i++;
4699 if (i == (long) argc)
4700 ThrowMogrifyException(OptionError,"MissingArgument",option);
4701 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4702 if (dispose < 0)
4703 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4704 argv[i]);
4705 break;
4706 }
4707 if (LocaleCompare("distort",option+1) == 0)
4708 {
4709 long
4710 op;
4711
4712 i++;
4713 if (i == (long) argc)
4714 ThrowMogrifyException(OptionError,"MissingArgument",option);
4715 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4716 if (op < 0)
4717 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4718 argv[i]);
4719 i++;
4720 if (i == (long) (argc-1))
4721 ThrowMogrifyException(OptionError,"MissingArgument",option);
4722 break;
4723 }
4724 if (LocaleCompare("dither",option+1) == 0)
4725 {
4726 long
4727 method;
4728
4729 if (*option == '+')
4730 break;
4731 i++;
4732 if (i == (long) argc)
4733 ThrowMogrifyException(OptionError,"MissingArgument",option);
4734 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4735 if (method < 0)
4736 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4737 argv[i]);
4738 break;
4739 }
4740 if (LocaleCompare("draw",option+1) == 0)
4741 {
4742 if (*option == '+')
4743 break;
4744 i++;
4745 if (i == (long) argc)
4746 ThrowMogrifyException(OptionError,"MissingArgument",option);
4747 break;
4748 }
cristy22879752009-10-25 23:55:40 +00004749 if (LocaleCompare("duration",option+1) == 0)
4750 {
4751 if (*option == '+')
4752 break;
4753 i++;
4754 if (i == (long) (argc-1))
4755 ThrowMogrifyException(OptionError,"MissingArgument",option);
4756 if (IsGeometry(argv[i]) == MagickFalse)
4757 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4758 break;
4759 }
cristy3ed852e2009-09-05 21:47:34 +00004760 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4761 }
4762 case 'e':
4763 {
4764 if (LocaleCompare("edge",option+1) == 0)
4765 {
4766 if (*option == '+')
4767 break;
4768 i++;
4769 if (i == (long) argc)
4770 ThrowMogrifyException(OptionError,"MissingArgument",option);
4771 if (IsGeometry(argv[i]) == MagickFalse)
4772 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4773 break;
4774 }
4775 if (LocaleCompare("emboss",option+1) == 0)
4776 {
4777 if (*option == '+')
4778 break;
4779 i++;
4780 if (i == (long) argc)
4781 ThrowMogrifyException(OptionError,"MissingArgument",option);
4782 if (IsGeometry(argv[i]) == MagickFalse)
4783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4784 break;
4785 }
4786 if (LocaleCompare("encipher",option+1) == 0)
4787 {
4788 if (*option == '+')
4789 break;
4790 i++;
4791 if (i == (long) argc)
4792 ThrowMogrifyException(OptionError,"MissingArgument",option);
4793 break;
4794 }
4795 if (LocaleCompare("encoding",option+1) == 0)
4796 {
4797 if (*option == '+')
4798 break;
4799 i++;
4800 if (i == (long) argc)
4801 ThrowMogrifyException(OptionError,"MissingArgument",option);
4802 break;
4803 }
4804 if (LocaleCompare("endian",option+1) == 0)
4805 {
4806 long
4807 endian;
4808
4809 if (*option == '+')
4810 break;
4811 i++;
4812 if (i == (long) argc)
4813 ThrowMogrifyException(OptionError,"MissingArgument",option);
4814 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4815 if (endian < 0)
4816 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4817 argv[i]);
4818 break;
4819 }
4820 if (LocaleCompare("enhance",option+1) == 0)
4821 break;
4822 if (LocaleCompare("equalize",option+1) == 0)
4823 break;
4824 if (LocaleCompare("evaluate",option+1) == 0)
4825 {
4826 long
4827 op;
4828
4829 if (*option == '+')
4830 break;
4831 i++;
4832 if (i == (long) argc)
4833 ThrowMogrifyException(OptionError,"MissingArgument",option);
4834 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4835 if (op < 0)
4836 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4837 argv[i]);
4838 i++;
4839 if (i == (long) (argc-1))
4840 ThrowMogrifyException(OptionError,"MissingArgument",option);
4841 if (IsGeometry(argv[i]) == MagickFalse)
4842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4843 break;
4844 }
cristyd18ae7c2010-03-07 17:39:52 +00004845 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4846 {
4847 long
4848 op;
4849
4850 if (*option == '+')
4851 break;
4852 i++;
4853 if (i == (long) argc)
4854 ThrowMogrifyException(OptionError,"MissingArgument",option);
4855 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4856 if (op < 0)
4857 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4858 argv[i]);
4859 break;
4860 }
cristy3ed852e2009-09-05 21:47:34 +00004861 if (LocaleCompare("extent",option+1) == 0)
4862 {
4863 if (*option == '+')
4864 break;
4865 i++;
4866 if (i == (long) argc)
4867 ThrowMogrifyException(OptionError,"MissingArgument",option);
4868 if (IsGeometry(argv[i]) == MagickFalse)
4869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4870 break;
4871 }
4872 if (LocaleCompare("extract",option+1) == 0)
4873 {
4874 if (*option == '+')
4875 break;
4876 i++;
4877 if (i == (long) argc)
4878 ThrowMogrifyException(OptionError,"MissingArgument",option);
4879 if (IsGeometry(argv[i]) == MagickFalse)
4880 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4881 break;
4882 }
4883 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4884 }
4885 case 'f':
4886 {
4887 if (LocaleCompare("family",option+1) == 0)
4888 {
4889 if (*option == '+')
4890 break;
4891 i++;
4892 if (i == (long) (argc-1))
4893 ThrowMogrifyException(OptionError,"MissingArgument",option);
4894 break;
4895 }
4896 if (LocaleCompare("fill",option+1) == 0)
4897 {
4898 if (*option == '+')
4899 break;
4900 i++;
4901 if (i == (long) argc)
4902 ThrowMogrifyException(OptionError,"MissingArgument",option);
4903 break;
4904 }
4905 if (LocaleCompare("filter",option+1) == 0)
4906 {
4907 long
4908 filter;
4909
4910 if (*option == '+')
4911 break;
4912 i++;
4913 if (i == (long) argc)
4914 ThrowMogrifyException(OptionError,"MissingArgument",option);
4915 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4916 if (filter < 0)
4917 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4918 argv[i]);
4919 break;
4920 }
4921 if (LocaleCompare("flatten",option+1) == 0)
4922 break;
4923 if (LocaleCompare("flip",option+1) == 0)
4924 break;
4925 if (LocaleCompare("flop",option+1) == 0)
4926 break;
4927 if (LocaleCompare("floodfill",option+1) == 0)
4928 {
4929 if (*option == '+')
4930 break;
4931 i++;
4932 if (i == (long) argc)
4933 ThrowMogrifyException(OptionError,"MissingArgument",option);
4934 if (IsGeometry(argv[i]) == MagickFalse)
4935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4936 i++;
4937 if (i == (long) argc)
4938 ThrowMogrifyException(OptionError,"MissingArgument",option);
4939 break;
4940 }
4941 if (LocaleCompare("font",option+1) == 0)
4942 {
4943 if (*option == '+')
4944 break;
4945 i++;
4946 if (i == (long) argc)
4947 ThrowMogrifyException(OptionError,"MissingArgument",option);
4948 break;
4949 }
4950 if (LocaleCompare("format",option+1) == 0)
4951 {
4952 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4953 (void) CloneString(&format,(char *) NULL);
4954 if (*option == '+')
4955 break;
4956 i++;
4957 if (i == (long) argc)
4958 ThrowMogrifyException(OptionError,"MissingArgument",option);
4959 (void) CloneString(&format,argv[i]);
4960 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4961 (void) ConcatenateMagickString(image_info->filename,":",
4962 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004963 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004964 if (*image_info->magick == '\0')
4965 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4966 format);
4967 break;
4968 }
4969 if (LocaleCompare("frame",option+1) == 0)
4970 {
4971 if (*option == '+')
4972 break;
4973 i++;
4974 if (i == (long) argc)
4975 ThrowMogrifyException(OptionError,"MissingArgument",option);
4976 if (IsGeometry(argv[i]) == MagickFalse)
4977 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4978 break;
4979 }
4980 if (LocaleCompare("function",option+1) == 0)
4981 {
4982 long
4983 op;
4984
4985 if (*option == '+')
4986 break;
4987 i++;
4988 if (i == (long) argc)
4989 ThrowMogrifyException(OptionError,"MissingArgument",option);
4990 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4991 if (op < 0)
4992 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4993 i++;
4994 if (i == (long) (argc-1))
4995 ThrowMogrifyException(OptionError,"MissingArgument",option);
4996 break;
4997 }
4998 if (LocaleCompare("fuzz",option+1) == 0)
4999 {
5000 if (*option == '+')
5001 break;
5002 i++;
5003 if (i == (long) argc)
5004 ThrowMogrifyException(OptionError,"MissingArgument",option);
5005 if (IsGeometry(argv[i]) == MagickFalse)
5006 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5007 break;
5008 }
5009 if (LocaleCompare("fx",option+1) == 0)
5010 {
5011 if (*option == '+')
5012 break;
5013 i++;
5014 if (i == (long) (argc-1))
5015 ThrowMogrifyException(OptionError,"MissingArgument",option);
5016 break;
5017 }
5018 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5019 }
5020 case 'g':
5021 {
5022 if (LocaleCompare("gamma",option+1) == 0)
5023 {
5024 i++;
5025 if (i == (long) argc)
5026 ThrowMogrifyException(OptionError,"MissingArgument",option);
5027 if (IsGeometry(argv[i]) == MagickFalse)
5028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5029 break;
5030 }
5031 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5032 (LocaleCompare("gaussian",option+1) == 0))
5033 {
5034 i++;
5035 if (i == (long) argc)
5036 ThrowMogrifyException(OptionError,"MissingArgument",option);
5037 if (IsGeometry(argv[i]) == MagickFalse)
5038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5039 break;
5040 }
5041 if (LocaleCompare("geometry",option+1) == 0)
5042 {
5043 if (*option == '+')
5044 break;
5045 i++;
5046 if (i == (long) argc)
5047 ThrowMogrifyException(OptionError,"MissingArgument",option);
5048 if (IsGeometry(argv[i]) == MagickFalse)
5049 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5050 break;
5051 }
5052 if (LocaleCompare("gravity",option+1) == 0)
5053 {
5054 long
5055 gravity;
5056
5057 if (*option == '+')
5058 break;
5059 i++;
5060 if (i == (long) argc)
5061 ThrowMogrifyException(OptionError,"MissingArgument",option);
5062 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5063 if (gravity < 0)
5064 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5065 argv[i]);
5066 break;
5067 }
5068 if (LocaleCompare("green-primary",option+1) == 0)
5069 {
5070 if (*option == '+')
5071 break;
5072 i++;
5073 if (i == (long) argc)
5074 ThrowMogrifyException(OptionError,"MissingArgument",option);
5075 if (IsGeometry(argv[i]) == MagickFalse)
5076 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5077 break;
5078 }
5079 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5080 }
5081 case 'h':
5082 {
5083 if (LocaleCompare("hald-clut",option+1) == 0)
5084 break;
5085 if ((LocaleCompare("help",option+1) == 0) ||
5086 (LocaleCompare("-help",option+1) == 0))
5087 return(MogrifyUsage());
5088 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5089 }
5090 case 'i':
5091 {
5092 if (LocaleCompare("identify",option+1) == 0)
5093 break;
5094 if (LocaleCompare("idft",option+1) == 0)
5095 break;
5096 if (LocaleCompare("implode",option+1) == 0)
5097 {
5098 if (*option == '+')
5099 break;
5100 i++;
5101 if (i == (long) argc)
5102 ThrowMogrifyException(OptionError,"MissingArgument",option);
5103 if (IsGeometry(argv[i]) == MagickFalse)
5104 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5105 break;
5106 }
5107 if (LocaleCompare("intent",option+1) == 0)
5108 {
5109 long
5110 intent;
5111
5112 if (*option == '+')
5113 break;
5114 i++;
5115 if (i == (long) (argc-1))
5116 ThrowMogrifyException(OptionError,"MissingArgument",option);
5117 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5118 if (intent < 0)
5119 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5120 argv[i]);
5121 break;
5122 }
5123 if (LocaleCompare("interlace",option+1) == 0)
5124 {
5125 long
5126 interlace;
5127
5128 if (*option == '+')
5129 break;
5130 i++;
5131 if (i == (long) argc)
5132 ThrowMogrifyException(OptionError,"MissingArgument",option);
5133 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5134 argv[i]);
5135 if (interlace < 0)
5136 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5137 argv[i]);
5138 break;
5139 }
cristyb32b90a2009-09-07 21:45:48 +00005140 if (LocaleCompare("interline-spacing",option+1) == 0)
5141 {
5142 if (*option == '+')
5143 break;
5144 i++;
5145 if (i == (long) (argc-1))
5146 ThrowMogrifyException(OptionError,"MissingArgument",option);
5147 if (IsGeometry(argv[i]) == MagickFalse)
5148 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5149 break;
5150 }
cristy3ed852e2009-09-05 21:47:34 +00005151 if (LocaleCompare("interpolate",option+1) == 0)
5152 {
5153 long
5154 interpolate;
5155
5156 if (*option == '+')
5157 break;
5158 i++;
5159 if (i == (long) argc)
5160 ThrowMogrifyException(OptionError,"MissingArgument",option);
5161 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5162 argv[i]);
5163 if (interpolate < 0)
5164 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5165 argv[i]);
5166 break;
5167 }
5168 if (LocaleCompare("interword-spacing",option+1) == 0)
5169 {
5170 if (*option == '+')
5171 break;
5172 i++;
5173 if (i == (long) (argc-1))
5174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 if (IsGeometry(argv[i]) == MagickFalse)
5176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5177 break;
5178 }
5179 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5180 }
5181 case 'k':
5182 {
5183 if (LocaleCompare("kerning",option+1) == 0)
5184 {
5185 if (*option == '+')
5186 break;
5187 i++;
5188 if (i == (long) (argc-1))
5189 ThrowMogrifyException(OptionError,"MissingArgument",option);
5190 if (IsGeometry(argv[i]) == MagickFalse)
5191 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5192 break;
5193 }
5194 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5195 }
5196 case 'l':
5197 {
5198 if (LocaleCompare("label",option+1) == 0)
5199 {
5200 if (*option == '+')
5201 break;
5202 i++;
5203 if (i == (long) argc)
5204 ThrowMogrifyException(OptionError,"MissingArgument",option);
5205 break;
5206 }
5207 if (LocaleCompare("lat",option+1) == 0)
5208 {
5209 if (*option == '+')
5210 break;
5211 i++;
5212 if (i == (long) argc)
5213 ThrowMogrifyException(OptionError,"MissingArgument",option);
5214 if (IsGeometry(argv[i]) == MagickFalse)
5215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5216 }
5217 if (LocaleCompare("layers",option+1) == 0)
5218 {
5219 long
5220 type;
5221
5222 if (*option == '+')
5223 break;
5224 i++;
5225 if (i == (long) (argc-1))
5226 ThrowMogrifyException(OptionError,"MissingArgument",option);
5227 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5228 if (type < 0)
5229 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5230 argv[i]);
5231 break;
5232 }
5233 if (LocaleCompare("level",option+1) == 0)
5234 {
5235 i++;
5236 if (i == (long) argc)
5237 ThrowMogrifyException(OptionError,"MissingArgument",option);
5238 if (IsGeometry(argv[i]) == MagickFalse)
5239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5240 break;
5241 }
5242 if (LocaleCompare("level-colors",option+1) == 0)
5243 {
5244 i++;
5245 if (i == (long) argc)
5246 ThrowMogrifyException(OptionError,"MissingArgument",option);
5247 break;
5248 }
5249 if (LocaleCompare("linewidth",option+1) == 0)
5250 {
5251 if (*option == '+')
5252 break;
5253 i++;
5254 if (i == (long) argc)
5255 ThrowMogrifyException(OptionError,"MissingArgument",option);
5256 if (IsGeometry(argv[i]) == MagickFalse)
5257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5258 break;
5259 }
5260 if (LocaleCompare("limit",option+1) == 0)
5261 {
5262 char
5263 *p;
5264
5265 double
5266 value;
5267
5268 long
5269 resource;
5270
5271 if (*option == '+')
5272 break;
5273 i++;
5274 if (i == (long) argc)
5275 ThrowMogrifyException(OptionError,"MissingArgument",option);
5276 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5277 argv[i]);
5278 if (resource < 0)
5279 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5280 argv[i]);
5281 i++;
5282 if (i == (long) argc)
5283 ThrowMogrifyException(OptionError,"MissingArgument",option);
5284 value=strtod(argv[i],&p);
5285 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5287 break;
5288 }
5289 if (LocaleCompare("liquid-rescale",option+1) == 0)
5290 {
5291 i++;
5292 if (i == (long) argc)
5293 ThrowMogrifyException(OptionError,"MissingArgument",option);
5294 if (IsGeometry(argv[i]) == MagickFalse)
5295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5296 break;
5297 }
5298 if (LocaleCompare("list",option+1) == 0)
5299 {
5300 long
5301 list;
5302
5303 if (*option == '+')
5304 break;
5305 i++;
5306 if (i == (long) argc)
5307 ThrowMogrifyException(OptionError,"MissingArgument",option);
5308 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5309 if (list < 0)
5310 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5311 (void) MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5312 argv+j,exception);
5313 return(MagickTrue);
5314 }
5315 if (LocaleCompare("log",option+1) == 0)
5316 {
5317 if (*option == '+')
5318 break;
5319 i++;
5320 if ((i == (long) argc) ||
5321 (strchr(argv[i],'%') == (char *) NULL))
5322 ThrowMogrifyException(OptionError,"MissingArgument",option);
5323 break;
5324 }
5325 if (LocaleCompare("loop",option+1) == 0)
5326 {
5327 if (*option == '+')
5328 break;
5329 i++;
5330 if (i == (long) argc)
5331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 if (IsGeometry(argv[i]) == MagickFalse)
5333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5334 break;
5335 }
5336 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5337 }
5338 case 'm':
5339 {
5340 if (LocaleCompare("map",option+1) == 0)
5341 {
5342 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5343 if (*option == '+')
5344 break;
5345 i++;
5346 if (i == (long) argc)
5347 ThrowMogrifyException(OptionError,"MissingArgument",option);
5348 break;
5349 }
5350 if (LocaleCompare("mask",option+1) == 0)
5351 {
5352 if (*option == '+')
5353 break;
5354 i++;
5355 if (i == (long) argc)
5356 ThrowMogrifyException(OptionError,"MissingArgument",option);
5357 break;
5358 }
5359 if (LocaleCompare("matte",option+1) == 0)
5360 break;
5361 if (LocaleCompare("mattecolor",option+1) == 0)
5362 {
5363 if (*option == '+')
5364 break;
5365 i++;
5366 if (i == (long) argc)
5367 ThrowMogrifyException(OptionError,"MissingArgument",option);
5368 break;
5369 }
cristyf40785b2010-03-06 02:27:27 +00005370 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005371 break;
cristyf40785b2010-03-06 02:27:27 +00005372 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005373 break;
cristy3ed852e2009-09-05 21:47:34 +00005374 if (LocaleCompare("modulate",option+1) == 0)
5375 {
5376 if (*option == '+')
5377 break;
5378 i++;
5379 if (i == (long) argc)
5380 ThrowMogrifyException(OptionError,"MissingArgument",option);
5381 if (IsGeometry(argv[i]) == MagickFalse)
5382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5383 break;
5384 }
5385 if (LocaleCompare("median",option+1) == 0)
5386 {
5387 if (*option == '+')
5388 break;
5389 i++;
5390 if (i == (long) argc)
5391 ThrowMogrifyException(OptionError,"MissingArgument",option);
5392 if (IsGeometry(argv[i]) == MagickFalse)
5393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5394 break;
5395 }
5396 if (LocaleCompare("monitor",option+1) == 0)
5397 break;
5398 if (LocaleCompare("monochrome",option+1) == 0)
5399 break;
5400 if (LocaleCompare("morph",option+1) == 0)
5401 {
5402 if (*option == '+')
5403 break;
5404 i++;
5405 if (i == (long) (argc-1))
5406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 if (IsGeometry(argv[i]) == MagickFalse)
5408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5409 break;
5410 }
anthony29188a82010-01-22 10:12:34 +00005411 if (LocaleCompare("morphology",option+1) == 0)
5412 {
5413 long
5414 op;
5415
5416 char
5417 token[MaxTextExtent];
5418
5419 i++;
5420 if (i == (long) argc)
5421 ThrowMogrifyException(OptionError,"MissingArgument",option);
5422 GetMagickToken(argv[i],NULL,token);
5423 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5424 if (op < 0)
5425 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005426 token);
anthony29188a82010-01-22 10:12:34 +00005427 i++;
5428 if (i == (long) (argc-1))
5429 ThrowMogrifyException(OptionError,"MissingArgument",option);
5430 GetMagickToken(argv[i],NULL,token);
cristyf0c78232010-03-15 12:53:40 +00005431 if (isalpha((int) ((unsigned char) *token)) != 0)
anthony29188a82010-01-22 10:12:34 +00005432 {
5433 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
5434 if (op < 0)
5435 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
cristyf0c78232010-03-15 12:53:40 +00005436 token);
anthony29188a82010-01-22 10:12:34 +00005437 }
anthony29188a82010-01-22 10:12:34 +00005438 break;
5439 }
cristy3ed852e2009-09-05 21:47:34 +00005440 if (LocaleCompare("mosaic",option+1) == 0)
5441 break;
5442 if (LocaleCompare("motion-blur",option+1) == 0)
5443 {
5444 if (*option == '+')
5445 break;
5446 i++;
5447 if (i == (long) argc)
5448 ThrowMogrifyException(OptionError,"MissingArgument",option);
5449 if (IsGeometry(argv[i]) == MagickFalse)
5450 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5451 break;
5452 }
5453 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5454 }
5455 case 'n':
5456 {
5457 if (LocaleCompare("negate",option+1) == 0)
5458 break;
5459 if (LocaleCompare("noise",option+1) == 0)
5460 {
5461 i++;
5462 if (i == (long) argc)
5463 ThrowMogrifyException(OptionError,"MissingArgument",option);
5464 if (*option == '+')
5465 {
5466 long
5467 noise;
5468
5469 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5470 if (noise < 0)
5471 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5472 argv[i]);
5473 break;
5474 }
5475 if (IsGeometry(argv[i]) == MagickFalse)
5476 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5477 break;
5478 }
5479 if (LocaleCompare("noop",option+1) == 0)
5480 break;
5481 if (LocaleCompare("normalize",option+1) == 0)
5482 break;
5483 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5484 }
5485 case 'o':
5486 {
5487 if (LocaleCompare("opaque",option+1) == 0)
5488 {
cristy3ed852e2009-09-05 21:47:34 +00005489 i++;
5490 if (i == (long) argc)
5491 ThrowMogrifyException(OptionError,"MissingArgument",option);
5492 break;
5493 }
5494 if (LocaleCompare("ordered-dither",option+1) == 0)
5495 {
5496 if (*option == '+')
5497 break;
5498 i++;
5499 if (i == (long) argc)
5500 ThrowMogrifyException(OptionError,"MissingArgument",option);
5501 break;
5502 }
5503 if (LocaleCompare("orient",option+1) == 0)
5504 {
5505 long
5506 orientation;
5507
5508 orientation=UndefinedOrientation;
5509 if (*option == '+')
5510 break;
5511 i++;
5512 if (i == (long) (argc-1))
5513 ThrowMogrifyException(OptionError,"MissingArgument",option);
5514 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5515 argv[i]);
5516 if (orientation < 0)
5517 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5518 argv[i]);
5519 break;
5520 }
5521 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5522 }
5523 case 'p':
5524 {
5525 if (LocaleCompare("page",option+1) == 0)
5526 {
5527 if (*option == '+')
5528 break;
5529 i++;
5530 if (i == (long) argc)
5531 ThrowMogrifyException(OptionError,"MissingArgument",option);
5532 break;
5533 }
5534 if (LocaleCompare("paint",option+1) == 0)
5535 {
5536 if (*option == '+')
5537 break;
5538 i++;
5539 if (i == (long) argc)
5540 ThrowMogrifyException(OptionError,"MissingArgument",option);
5541 if (IsGeometry(argv[i]) == MagickFalse)
5542 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5543 break;
5544 }
5545 if (LocaleCompare("path",option+1) == 0)
5546 {
5547 (void) CloneString(&path,(char *) NULL);
5548 if (*option == '+')
5549 break;
5550 i++;
5551 if (i == (long) argc)
5552 ThrowMogrifyException(OptionError,"MissingArgument",option);
5553 (void) CloneString(&path,argv[i]);
5554 break;
5555 }
5556 if (LocaleCompare("pointsize",option+1) == 0)
5557 {
5558 if (*option == '+')
5559 break;
5560 i++;
5561 if (i == (long) argc)
5562 ThrowMogrifyException(OptionError,"MissingArgument",option);
5563 if (IsGeometry(argv[i]) == MagickFalse)
5564 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5565 break;
5566 }
5567 if (LocaleCompare("polaroid",option+1) == 0)
5568 {
5569 if (*option == '+')
5570 break;
5571 i++;
5572 if (i == (long) argc)
5573 ThrowMogrifyException(OptionError,"MissingArgument",option);
5574 if (IsGeometry(argv[i]) == MagickFalse)
5575 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5576 break;
5577 }
5578 if (LocaleCompare("posterize",option+1) == 0)
5579 {
5580 if (*option == '+')
5581 break;
5582 i++;
5583 if (i == (long) argc)
5584 ThrowMogrifyException(OptionError,"MissingArgument",option);
5585 if (IsGeometry(argv[i]) == MagickFalse)
5586 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5587 break;
5588 }
cristye7f51092010-01-17 00:39:37 +00005589 if (LocaleCompare("precision",option+1) == 0)
5590 {
5591 if (*option == '+')
5592 break;
5593 i++;
5594 if (i == (long) argc)
5595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5598 break;
5599 }
cristy3ed852e2009-09-05 21:47:34 +00005600 if (LocaleCompare("print",option+1) == 0)
5601 {
5602 if (*option == '+')
5603 break;
5604 i++;
5605 if (i == (long) argc)
5606 ThrowMogrifyException(OptionError,"MissingArgument",option);
5607 break;
5608 }
5609 if (LocaleCompare("process",option+1) == 0)
5610 {
5611 if (*option == '+')
5612 break;
5613 i++;
5614 if (i == (long) (argc-1))
5615 ThrowMogrifyException(OptionError,"MissingArgument",option);
5616 break;
5617 }
5618 if (LocaleCompare("profile",option+1) == 0)
5619 {
5620 i++;
5621 if (i == (long) argc)
5622 ThrowMogrifyException(OptionError,"MissingArgument",option);
5623 break;
5624 }
5625 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5626 }
5627 case 'q':
5628 {
5629 if (LocaleCompare("quality",option+1) == 0)
5630 {
5631 if (*option == '+')
5632 break;
5633 i++;
5634 if (i == (long) argc)
5635 ThrowMogrifyException(OptionError,"MissingArgument",option);
5636 if (IsGeometry(argv[i]) == MagickFalse)
5637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5638 break;
5639 }
5640 if (LocaleCompare("quantize",option+1) == 0)
5641 {
5642 long
5643 colorspace;
5644
5645 if (*option == '+')
5646 break;
5647 i++;
5648 if (i == (long) (argc-1))
5649 ThrowMogrifyException(OptionError,"MissingArgument",option);
5650 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5651 argv[i]);
5652 if (colorspace < 0)
5653 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5654 argv[i]);
5655 break;
5656 }
5657 if (LocaleCompare("quiet",option+1) == 0)
5658 break;
5659 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5660 }
5661 case 'r':
5662 {
5663 if (LocaleCompare("radial-blur",option+1) == 0)
5664 {
5665 i++;
5666 if (i == (long) argc)
5667 ThrowMogrifyException(OptionError,"MissingArgument",option);
5668 if (IsGeometry(argv[i]) == MagickFalse)
5669 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5670 break;
5671 }
5672 if (LocaleCompare("raise",option+1) == 0)
5673 {
5674 i++;
5675 if (i == (long) argc)
5676 ThrowMogrifyException(OptionError,"MissingArgument",option);
5677 if (IsGeometry(argv[i]) == MagickFalse)
5678 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5679 break;
5680 }
5681 if (LocaleCompare("random-threshold",option+1) == 0)
5682 {
5683 if (*option == '+')
5684 break;
5685 i++;
5686 if (i == (long) argc)
5687 ThrowMogrifyException(OptionError,"MissingArgument",option);
5688 if (IsGeometry(argv[i]) == MagickFalse)
5689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5690 break;
5691 }
5692 if (LocaleCompare("red-primary",option+1) == 0)
5693 {
5694 if (*option == '+')
5695 break;
5696 i++;
5697 if (i == (long) argc)
5698 ThrowMogrifyException(OptionError,"MissingArgument",option);
5699 if (IsGeometry(argv[i]) == MagickFalse)
5700 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5701 }
5702 if (LocaleCompare("region",option+1) == 0)
5703 {
5704 if (*option == '+')
5705 break;
5706 i++;
5707 if (i == (long) argc)
5708 ThrowMogrifyException(OptionError,"MissingArgument",option);
5709 if (IsGeometry(argv[i]) == MagickFalse)
5710 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5711 break;
5712 }
cristyf0c78232010-03-15 12:53:40 +00005713 if (LocaleCompare("remap",option+1) == 0)
5714 {
5715 if (*option == '+')
5716 break;
5717 i++;
5718 if (i == (long) (argc-1))
5719 ThrowMogrifyException(OptionError,"MissingArgument",option);
5720 break;
5721 }
cristy3ed852e2009-09-05 21:47:34 +00005722 if (LocaleCompare("render",option+1) == 0)
5723 break;
5724 if (LocaleCompare("repage",option+1) == 0)
5725 {
5726 if (*option == '+')
5727 break;
5728 i++;
5729 if (i == (long) argc)
5730 ThrowMogrifyException(OptionError,"MissingArgument",option);
5731 if (IsGeometry(argv[i]) == MagickFalse)
5732 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5733 break;
5734 }
5735 if (LocaleCompare("resample",option+1) == 0)
5736 {
5737 if (*option == '+')
5738 break;
5739 i++;
5740 if (i == (long) argc)
5741 ThrowMogrifyException(OptionError,"MissingArgument",option);
5742 if (IsGeometry(argv[i]) == MagickFalse)
5743 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5744 break;
5745 }
5746 if (LocaleCompare("resize",option+1) == 0)
5747 {
5748 if (*option == '+')
5749 break;
5750 i++;
5751 if (i == (long) argc)
5752 ThrowMogrifyException(OptionError,"MissingArgument",option);
5753 if (IsGeometry(argv[i]) == MagickFalse)
5754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5755 break;
5756 }
5757 if (LocaleCompare("reverse",option+1) == 0)
5758 break;
5759 if (LocaleCompare("roll",option+1) == 0)
5760 {
5761 if (*option == '+')
5762 break;
5763 i++;
5764 if (i == (long) argc)
5765 ThrowMogrifyException(OptionError,"MissingArgument",option);
5766 if (IsGeometry(argv[i]) == MagickFalse)
5767 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5768 break;
5769 }
5770 if (LocaleCompare("rotate",option+1) == 0)
5771 {
5772 i++;
5773 if (i == (long) argc)
5774 ThrowMogrifyException(OptionError,"MissingArgument",option);
5775 if (IsGeometry(argv[i]) == MagickFalse)
5776 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5777 break;
5778 }
5779 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5780 }
5781 case 's':
5782 {
5783 if (LocaleCompare("sample",option+1) == 0)
5784 {
5785 if (*option == '+')
5786 break;
5787 i++;
5788 if (i == (long) argc)
5789 ThrowMogrifyException(OptionError,"MissingArgument",option);
5790 if (IsGeometry(argv[i]) == MagickFalse)
5791 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5792 break;
5793 }
5794 if (LocaleCompare("sampling-factor",option+1) == 0)
5795 {
5796 if (*option == '+')
5797 break;
5798 i++;
5799 if (i == (long) argc)
5800 ThrowMogrifyException(OptionError,"MissingArgument",option);
5801 if (IsGeometry(argv[i]) == MagickFalse)
5802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5803 break;
5804 }
5805 if (LocaleCompare("scale",option+1) == 0)
5806 {
5807 if (*option == '+')
5808 break;
5809 i++;
5810 if (i == (long) argc)
5811 ThrowMogrifyException(OptionError,"MissingArgument",option);
5812 if (IsGeometry(argv[i]) == MagickFalse)
5813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5814 break;
5815 }
5816 if (LocaleCompare("scene",option+1) == 0)
5817 {
5818 if (*option == '+')
5819 break;
5820 i++;
5821 if (i == (long) argc)
5822 ThrowMogrifyException(OptionError,"MissingArgument",option);
5823 if (IsGeometry(argv[i]) == MagickFalse)
5824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5825 break;
5826 }
5827 if (LocaleCompare("seed",option+1) == 0)
5828 {
5829 if (*option == '+')
5830 break;
5831 i++;
5832 if (i == (long) argc)
5833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 if (IsGeometry(argv[i]) == MagickFalse)
5835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5836 break;
5837 }
5838 if (LocaleCompare("segment",option+1) == 0)
5839 {
5840 if (*option == '+')
5841 break;
5842 i++;
5843 if (i == (long) argc)
5844 ThrowMogrifyException(OptionError,"MissingArgument",option);
5845 if (IsGeometry(argv[i]) == MagickFalse)
5846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5847 break;
5848 }
5849 if (LocaleCompare("selective-blur",option+1) == 0)
5850 {
5851 i++;
5852 if (i == (long) argc)
5853 ThrowMogrifyException(OptionError,"MissingArgument",option);
5854 if (IsGeometry(argv[i]) == MagickFalse)
5855 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5856 break;
5857 }
5858 if (LocaleCompare("separate",option+1) == 0)
5859 break;
5860 if (LocaleCompare("sepia-tone",option+1) == 0)
5861 {
5862 if (*option == '+')
5863 break;
5864 i++;
5865 if (i == (long) argc)
5866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 if (IsGeometry(argv[i]) == MagickFalse)
5868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5869 break;
5870 }
5871 if (LocaleCompare("set",option+1) == 0)
5872 {
5873 i++;
5874 if (i == (long) argc)
5875 ThrowMogrifyException(OptionError,"MissingArgument",option);
5876 if (*option == '+')
5877 break;
5878 i++;
5879 if (i == (long) argc)
5880 ThrowMogrifyException(OptionError,"MissingArgument",option);
5881 break;
5882 }
5883 if (LocaleCompare("shade",option+1) == 0)
5884 {
5885 i++;
5886 if (i == (long) argc)
5887 ThrowMogrifyException(OptionError,"MissingArgument",option);
5888 if (IsGeometry(argv[i]) == MagickFalse)
5889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5890 break;
5891 }
5892 if (LocaleCompare("shadow",option+1) == 0)
5893 {
5894 if (*option == '+')
5895 break;
5896 i++;
5897 if (i == (long) argc)
5898 ThrowMogrifyException(OptionError,"MissingArgument",option);
5899 if (IsGeometry(argv[i]) == MagickFalse)
5900 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5901 break;
5902 }
5903 if (LocaleCompare("sharpen",option+1) == 0)
5904 {
5905 i++;
5906 if (i == (long) argc)
5907 ThrowMogrifyException(OptionError,"MissingArgument",option);
5908 if (IsGeometry(argv[i]) == MagickFalse)
5909 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5910 break;
5911 }
5912 if (LocaleCompare("shave",option+1) == 0)
5913 {
5914 if (*option == '+')
5915 break;
5916 i++;
5917 if (i == (long) argc)
5918 ThrowMogrifyException(OptionError,"MissingArgument",option);
5919 if (IsGeometry(argv[i]) == MagickFalse)
5920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5921 break;
5922 }
5923 if (LocaleCompare("shear",option+1) == 0)
5924 {
5925 i++;
5926 if (i == (long) argc)
5927 ThrowMogrifyException(OptionError,"MissingArgument",option);
5928 if (IsGeometry(argv[i]) == MagickFalse)
5929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5930 break;
5931 }
5932 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5933 {
5934 i++;
5935 if (i == (long) (argc-1))
5936 ThrowMogrifyException(OptionError,"MissingArgument",option);
5937 if (IsGeometry(argv[i]) == MagickFalse)
5938 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5939 break;
5940 }
5941 if (LocaleCompare("size",option+1) == 0)
5942 {
5943 if (*option == '+')
5944 break;
5945 i++;
5946 if (i == (long) argc)
5947 ThrowMogrifyException(OptionError,"MissingArgument",option);
5948 if (IsGeometry(argv[i]) == MagickFalse)
5949 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5950 break;
5951 }
5952 if (LocaleCompare("sketch",option+1) == 0)
5953 {
5954 if (*option == '+')
5955 break;
5956 i++;
5957 if (i == (long) argc)
5958 ThrowMogrifyException(OptionError,"MissingArgument",option);
5959 if (IsGeometry(argv[i]) == MagickFalse)
5960 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5961 break;
5962 }
5963 if (LocaleCompare("solarize",option+1) == 0)
5964 {
5965 if (*option == '+')
5966 break;
5967 i++;
5968 if (i == (long) argc)
5969 ThrowMogrifyException(OptionError,"MissingArgument",option);
5970 if (IsGeometry(argv[i]) == MagickFalse)
5971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5972 break;
5973 }
5974 if (LocaleCompare("sparse-color",option+1) == 0)
5975 {
5976 long
5977 op;
5978
5979 i++;
5980 if (i == (long) argc)
5981 ThrowMogrifyException(OptionError,"MissingArgument",option);
5982 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5983 if (op < 0)
5984 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5985 argv[i]);
5986 i++;
5987 if (i == (long) (argc-1))
5988 ThrowMogrifyException(OptionError,"MissingArgument",option);
5989 break;
5990 }
5991 if (LocaleCompare("spread",option+1) == 0)
5992 {
5993 if (*option == '+')
5994 break;
5995 i++;
5996 if (i == (long) argc)
5997 ThrowMogrifyException(OptionError,"MissingArgument",option);
5998 if (IsGeometry(argv[i]) == MagickFalse)
5999 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6000 break;
6001 }
6002 if (LocaleCompare("stretch",option+1) == 0)
6003 {
6004 long
6005 stretch;
6006
6007 if (*option == '+')
6008 break;
6009 i++;
6010 if (i == (long) (argc-1))
6011 ThrowMogrifyException(OptionError,"MissingArgument",option);
6012 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6013 if (stretch < 0)
6014 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6015 argv[i]);
6016 break;
6017 }
6018 if (LocaleCompare("strip",option+1) == 0)
6019 break;
6020 if (LocaleCompare("stroke",option+1) == 0)
6021 {
6022 if (*option == '+')
6023 break;
6024 i++;
6025 if (i == (long) argc)
6026 ThrowMogrifyException(OptionError,"MissingArgument",option);
6027 break;
6028 }
6029 if (LocaleCompare("strokewidth",option+1) == 0)
6030 {
6031 if (*option == '+')
6032 break;
6033 i++;
6034 if (i == (long) argc)
6035 ThrowMogrifyException(OptionError,"MissingArgument",option);
6036 if (IsGeometry(argv[i]) == MagickFalse)
6037 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6038 break;
6039 }
6040 if (LocaleCompare("style",option+1) == 0)
6041 {
6042 long
6043 style;
6044
6045 if (*option == '+')
6046 break;
6047 i++;
6048 if (i == (long) (argc-1))
6049 ThrowMogrifyException(OptionError,"MissingArgument",option);
6050 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6051 if (style < 0)
6052 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6053 argv[i]);
6054 break;
6055 }
6056 if (LocaleCompare("swirl",option+1) == 0)
6057 {
6058 if (*option == '+')
6059 break;
6060 i++;
6061 if (i == (long) argc)
6062 ThrowMogrifyException(OptionError,"MissingArgument",option);
6063 if (IsGeometry(argv[i]) == MagickFalse)
6064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6065 break;
6066 }
6067 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6068 }
6069 case 't':
6070 {
6071 if (LocaleCompare("taint",option+1) == 0)
6072 break;
6073 if (LocaleCompare("texture",option+1) == 0)
6074 {
6075 if (*option == '+')
6076 break;
6077 i++;
6078 if (i == (long) argc)
6079 ThrowMogrifyException(OptionError,"MissingArgument",option);
6080 break;
6081 }
6082 if (LocaleCompare("tile",option+1) == 0)
6083 {
6084 if (*option == '+')
6085 break;
6086 i++;
6087 if (i == (long) (argc-1))
6088 ThrowMogrifyException(OptionError,"MissingArgument",option);
6089 break;
6090 }
6091 if (LocaleCompare("tile-offset",option+1) == 0)
6092 {
6093 if (*option == '+')
6094 break;
6095 i++;
6096 if (i == (long) argc)
6097 ThrowMogrifyException(OptionError,"MissingArgument",option);
6098 if (IsGeometry(argv[i]) == MagickFalse)
6099 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6100 break;
6101 }
6102 if (LocaleCompare("tint",option+1) == 0)
6103 {
6104 if (*option == '+')
6105 break;
6106 i++;
6107 if (i == (long) (argc-1))
6108 ThrowMogrifyException(OptionError,"MissingArgument",option);
6109 if (IsGeometry(argv[i]) == MagickFalse)
6110 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6111 break;
6112 }
6113 if (LocaleCompare("transform",option+1) == 0)
6114 break;
6115 if (LocaleCompare("transpose",option+1) == 0)
6116 break;
6117 if (LocaleCompare("transverse",option+1) == 0)
6118 break;
6119 if (LocaleCompare("threshold",option+1) == 0)
6120 {
6121 if (*option == '+')
6122 break;
6123 i++;
6124 if (i == (long) argc)
6125 ThrowMogrifyException(OptionError,"MissingArgument",option);
6126 if (IsGeometry(argv[i]) == MagickFalse)
6127 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6128 break;
6129 }
6130 if (LocaleCompare("thumbnail",option+1) == 0)
6131 {
6132 if (*option == '+')
6133 break;
6134 i++;
6135 if (i == (long) argc)
6136 ThrowMogrifyException(OptionError,"MissingArgument",option);
6137 if (IsGeometry(argv[i]) == MagickFalse)
6138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6139 break;
6140 }
6141 if (LocaleCompare("transparent",option+1) == 0)
6142 {
6143 i++;
6144 if (i == (long) argc)
6145 ThrowMogrifyException(OptionError,"MissingArgument",option);
6146 break;
6147 }
6148 if (LocaleCompare("transparent-color",option+1) == 0)
6149 {
6150 if (*option == '+')
6151 break;
6152 i++;
6153 if (i == (long) (argc-1))
6154 ThrowMogrifyException(OptionError,"MissingArgument",option);
6155 break;
6156 }
6157 if (LocaleCompare("treedepth",option+1) == 0)
6158 {
6159 if (*option == '+')
6160 break;
6161 i++;
6162 if (i == (long) argc)
6163 ThrowMogrifyException(OptionError,"MissingArgument",option);
6164 if (IsGeometry(argv[i]) == MagickFalse)
6165 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6166 break;
6167 }
6168 if (LocaleCompare("trim",option+1) == 0)
6169 break;
6170 if (LocaleCompare("type",option+1) == 0)
6171 {
6172 long
6173 type;
6174
6175 if (*option == '+')
6176 break;
6177 i++;
6178 if (i == (long) argc)
6179 ThrowMogrifyException(OptionError,"MissingArgument",option);
6180 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6181 if (type < 0)
6182 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6183 argv[i]);
6184 break;
6185 }
6186 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6187 }
6188 case 'u':
6189 {
6190 if (LocaleCompare("undercolor",option+1) == 0)
6191 {
6192 if (*option == '+')
6193 break;
6194 i++;
6195 if (i == (long) argc)
6196 ThrowMogrifyException(OptionError,"MissingArgument",option);
6197 break;
6198 }
6199 if (LocaleCompare("unique-colors",option+1) == 0)
6200 break;
6201 if (LocaleCompare("units",option+1) == 0)
6202 {
6203 long
6204 units;
6205
6206 if (*option == '+')
6207 break;
6208 i++;
6209 if (i == (long) argc)
6210 ThrowMogrifyException(OptionError,"MissingArgument",option);
6211 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6212 argv[i]);
6213 if (units < 0)
6214 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6215 argv[i]);
6216 break;
6217 }
6218 if (LocaleCompare("unsharp",option+1) == 0)
6219 {
6220 i++;
6221 if (i == (long) argc)
6222 ThrowMogrifyException(OptionError,"MissingArgument",option);
6223 if (IsGeometry(argv[i]) == MagickFalse)
6224 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6225 break;
6226 }
6227 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6228 }
6229 case 'v':
6230 {
6231 if (LocaleCompare("verbose",option+1) == 0)
6232 {
6233 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6234 break;
6235 }
6236 if ((LocaleCompare("version",option+1) == 0) ||
6237 (LocaleCompare("-version",option+1) == 0))
6238 {
6239 (void) fprintf(stdout,"Version: %s\n",
6240 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006241 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6242 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006243 break;
6244 }
6245 if (LocaleCompare("view",option+1) == 0)
6246 {
6247 if (*option == '+')
6248 break;
6249 i++;
6250 if (i == (long) argc)
6251 ThrowMogrifyException(OptionError,"MissingArgument",option);
6252 break;
6253 }
6254 if (LocaleCompare("vignette",option+1) == 0)
6255 {
6256 if (*option == '+')
6257 break;
6258 i++;
6259 if (i == (long) argc)
6260 ThrowMogrifyException(OptionError,"MissingArgument",option);
6261 if (IsGeometry(argv[i]) == MagickFalse)
6262 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6263 break;
6264 }
6265 if (LocaleCompare("virtual-pixel",option+1) == 0)
6266 {
6267 long
6268 method;
6269
6270 if (*option == '+')
6271 break;
6272 i++;
6273 if (i == (long) argc)
6274 ThrowMogrifyException(OptionError,"MissingArgument",option);
6275 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6276 argv[i]);
6277 if (method < 0)
6278 ThrowMogrifyException(OptionError,
6279 "UnrecognizedVirtualPixelMethod",argv[i]);
6280 break;
6281 }
6282 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6283 }
6284 case 'w':
6285 {
6286 if (LocaleCompare("wave",option+1) == 0)
6287 {
6288 i++;
6289 if (i == (long) argc)
6290 ThrowMogrifyException(OptionError,"MissingArgument",option);
6291 if (IsGeometry(argv[i]) == MagickFalse)
6292 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6293 break;
6294 }
6295 if (LocaleCompare("weight",option+1) == 0)
6296 {
6297 if (*option == '+')
6298 break;
6299 i++;
6300 if (i == (long) (argc-1))
6301 ThrowMogrifyException(OptionError,"MissingArgument",option);
6302 break;
6303 }
6304 if (LocaleCompare("white-point",option+1) == 0)
6305 {
6306 if (*option == '+')
6307 break;
6308 i++;
6309 if (i == (long) argc)
6310 ThrowMogrifyException(OptionError,"MissingArgument",option);
6311 if (IsGeometry(argv[i]) == MagickFalse)
6312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6313 break;
6314 }
6315 if (LocaleCompare("white-threshold",option+1) == 0)
6316 {
6317 if (*option == '+')
6318 break;
6319 i++;
6320 if (i == (long) argc)
6321 ThrowMogrifyException(OptionError,"MissingArgument",option);
6322 if (IsGeometry(argv[i]) == MagickFalse)
6323 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6324 break;
6325 }
6326 if (LocaleCompare("write",option+1) == 0)
6327 {
6328 i++;
6329 if (i == (long) (argc-1))
6330 ThrowMogrifyException(OptionError,"MissingArgument",option);
6331 break;
6332 }
6333 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6334 }
6335 case '?':
6336 break;
6337 default:
6338 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6339 }
6340 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6341 MagickFalse : MagickTrue;
6342 if (fire != MagickFalse)
6343 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6344 }
6345 if (k != 0)
6346 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6347 if (i != argc)
6348 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6349 DestroyMogrify();
6350 return(status != 0 ? MagickTrue : MagickFalse);
6351}
6352
6353/*
6354%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6355% %
6356% %
6357% %
6358+ M o g r i f y I m a g e I n f o %
6359% %
6360% %
6361% %
6362%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6363%
6364% MogrifyImageInfo() applies image processing settings to the image as
6365% prescribed by command line options.
6366%
6367% The format of the MogrifyImageInfo method is:
6368%
6369% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6370% const char **argv,ExceptionInfo *exception)
6371%
6372% A description of each parameter follows:
6373%
6374% o image_info: the image info..
6375%
6376% o argc: Specifies a pointer to an integer describing the number of
6377% elements in the argument vector.
6378%
6379% o argv: Specifies a pointer to a text array containing the command line
6380% arguments.
6381%
6382% o exception: return any errors or warnings in this structure.
6383%
6384*/
6385WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6386 const int argc,const char **argv,ExceptionInfo *exception)
6387{
6388 const char
6389 *option;
6390
6391 GeometryInfo
6392 geometry_info;
6393
6394 long
6395 count;
6396
6397 register long
6398 i;
6399
6400 /*
6401 Initialize method variables.
6402 */
6403 assert(image_info != (ImageInfo *) NULL);
6404 assert(image_info->signature == MagickSignature);
6405 if (image_info->debug != MagickFalse)
6406 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6407 image_info->filename);
6408 if (argc < 0)
6409 return(MagickTrue);
6410 /*
6411 Set the image settings.
6412 */
6413 for (i=0; i < (long) argc; i++)
6414 {
6415 option=argv[i];
6416 if (IsMagickOption(option) == MagickFalse)
6417 continue;
6418 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6419 0L);
6420 if ((i+count) >= argc)
6421 break;
6422 switch (*(option+1))
6423 {
6424 case 'a':
6425 {
6426 if (LocaleCompare("adjoin",option+1) == 0)
6427 {
6428 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6429 break;
6430 }
6431 if (LocaleCompare("antialias",option+1) == 0)
6432 {
6433 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6434 break;
6435 }
6436 if (LocaleCompare("attenuate",option+1) == 0)
6437 {
6438 if (*option == '+')
6439 {
6440 (void) DeleteImageOption(image_info,option+1);
6441 break;
6442 }
6443 (void) SetImageOption(image_info,option+1,argv[i+1]);
6444 break;
6445 }
6446 if (LocaleCompare("authenticate",option+1) == 0)
6447 {
6448 if (*option == '+')
6449 (void) CloneString(&image_info->authenticate,(char *) NULL);
6450 else
6451 (void) CloneString(&image_info->authenticate,argv[i+1]);
6452 break;
6453 }
6454 break;
6455 }
6456 case 'b':
6457 {
6458 if (LocaleCompare("background",option+1) == 0)
6459 {
6460 if (*option == '+')
6461 {
6462 (void) DeleteImageOption(image_info,option+1);
6463 (void) QueryColorDatabase(BackgroundColor,
6464 &image_info->background_color,exception);
6465 break;
6466 }
6467 (void) SetImageOption(image_info,option+1,argv[i+1]);
6468 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6469 exception);
6470 break;
6471 }
6472 if (LocaleCompare("bias",option+1) == 0)
6473 {
6474 if (*option == '+')
6475 {
6476 (void) SetImageOption(image_info,option+1,"0.0");
6477 break;
6478 }
6479 (void) SetImageOption(image_info,option+1,argv[i+1]);
6480 break;
6481 }
6482 if (LocaleCompare("black-point-compensation",option+1) == 0)
6483 {
6484 if (*option == '+')
6485 {
6486 (void) SetImageOption(image_info,option+1,"false");
6487 break;
6488 }
6489 (void) SetImageOption(image_info,option+1,"true");
6490 break;
6491 }
6492 if (LocaleCompare("blue-primary",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("bordercolor",option+1) == 0)
6503 {
6504 if (*option == '+')
6505 {
6506 (void) DeleteImageOption(image_info,option+1);
6507 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6508 exception);
6509 break;
6510 }
6511 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6512 exception);
6513 (void) SetImageOption(image_info,option+1,argv[i+1]);
6514 break;
6515 }
6516 if (LocaleCompare("box",option+1) == 0)
6517 {
6518 if (*option == '+')
6519 {
6520 (void) SetImageOption(image_info,"undercolor","none");
6521 break;
6522 }
6523 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6524 break;
6525 }
6526 break;
6527 }
6528 case 'c':
6529 {
6530 if (LocaleCompare("cache",option+1) == 0)
6531 {
6532 MagickSizeType
6533 limit;
6534
6535 limit=MagickResourceInfinity;
6536 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006537 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006538 (void) SetMagickResourceLimit(MemoryResource,limit);
6539 (void) SetMagickResourceLimit(MapResource,2*limit);
6540 break;
6541 }
6542 if (LocaleCompare("caption",option+1) == 0)
6543 {
6544 if (*option == '+')
6545 {
6546 (void) DeleteImageOption(image_info,option+1);
6547 break;
6548 }
6549 (void) SetImageOption(image_info,option+1,argv[i+1]);
6550 break;
6551 }
6552 if (LocaleCompare("channel",option+1) == 0)
6553 {
6554 if (*option == '+')
6555 {
6556 image_info->channel=DefaultChannels;
6557 break;
6558 }
6559 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6560 break;
6561 }
6562 if (LocaleCompare("colors",option+1) == 0)
6563 {
cristye27293e2009-12-18 02:53:20 +00006564 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006565 break;
6566 }
6567 if (LocaleCompare("colorspace",option+1) == 0)
6568 {
6569 if (*option == '+')
6570 {
6571 image_info->colorspace=UndefinedColorspace;
6572 (void) SetImageOption(image_info,option+1,"undefined");
6573 break;
6574 }
6575 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6576 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6577 (void) SetImageOption(image_info,option+1,argv[i+1]);
6578 break;
6579 }
6580 if (LocaleCompare("compress",option+1) == 0)
6581 {
6582 if (*option == '+')
6583 {
6584 image_info->compression=UndefinedCompression;
6585 (void) SetImageOption(image_info,option+1,"undefined");
6586 break;
6587 }
6588 image_info->compression=(CompressionType) ParseMagickOption(
6589 MagickCompressOptions,MagickFalse,argv[i+1]);
6590 (void) SetImageOption(image_info,option+1,argv[i+1]);
6591 break;
6592 }
6593 if (LocaleCompare("comment",option+1) == 0)
6594 {
6595 if (*option == '+')
6596 {
6597 (void) DeleteImageOption(image_info,option+1);
6598 break;
6599 }
6600 (void) SetImageOption(image_info,option+1,argv[i+1]);
6601 break;
6602 }
6603 if (LocaleCompare("compose",option+1) == 0)
6604 {
6605 if (*option == '+')
6606 {
6607 (void) SetImageOption(image_info,option+1,"undefined");
6608 break;
6609 }
6610 (void) SetImageOption(image_info,option+1,argv[i+1]);
6611 break;
6612 }
6613 if (LocaleCompare("compress",option+1) == 0)
6614 {
6615 if (*option == '+')
6616 {
6617 image_info->compression=UndefinedCompression;
6618 (void) SetImageOption(image_info,option+1,"undefined");
6619 break;
6620 }
6621 image_info->compression=(CompressionType) ParseMagickOption(
6622 MagickCompressOptions,MagickFalse,argv[i+1]);
6623 (void) SetImageOption(image_info,option+1,argv[i+1]);
6624 break;
6625 }
6626 break;
6627 }
6628 case 'd':
6629 {
6630 if (LocaleCompare("debug",option+1) == 0)
6631 {
6632 if (*option == '+')
6633 (void) SetLogEventMask("none");
6634 else
6635 (void) SetLogEventMask(argv[i+1]);
6636 image_info->debug=IsEventLogging();
6637 break;
6638 }
6639 if (LocaleCompare("define",option+1) == 0)
6640 {
6641 if (*option == '+')
6642 {
6643 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6644 (void) DeleteImageRegistry(argv[i+1]+9);
6645 else
6646 (void) DeleteImageOption(image_info,argv[i+1]);
6647 break;
6648 }
6649 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6650 {
6651 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6652 exception);
6653 break;
6654 }
6655 (void) DefineImageOption(image_info,argv[i+1]);
6656 break;
6657 }
6658 if (LocaleCompare("delay",option+1) == 0)
6659 {
6660 if (*option == '+')
6661 {
6662 (void) SetImageOption(image_info,option+1,"0");
6663 break;
6664 }
6665 (void) SetImageOption(image_info,option+1,argv[i+1]);
6666 break;
6667 }
6668 if (LocaleCompare("density",option+1) == 0)
6669 {
6670 /*
6671 Set image density.
6672 */
6673 if (*option == '+')
6674 {
6675 if (image_info->density != (char *) NULL)
6676 image_info->density=DestroyString(image_info->density);
6677 (void) SetImageOption(image_info,option+1,"72");
6678 break;
6679 }
6680 (void) CloneString(&image_info->density,argv[i+1]);
6681 (void) SetImageOption(image_info,option+1,argv[i+1]);
6682 break;
6683 }
6684 if (LocaleCompare("depth",option+1) == 0)
6685 {
6686 if (*option == '+')
6687 {
6688 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6689 break;
6690 }
cristye27293e2009-12-18 02:53:20 +00006691 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006692 break;
6693 }
6694 if (LocaleCompare("display",option+1) == 0)
6695 {
6696 if (*option == '+')
6697 {
6698 if (image_info->server_name != (char *) NULL)
6699 image_info->server_name=DestroyString(
6700 image_info->server_name);
6701 break;
6702 }
6703 (void) CloneString(&image_info->server_name,argv[i+1]);
6704 break;
6705 }
6706 if (LocaleCompare("dispose",option+1) == 0)
6707 {
6708 if (*option == '+')
6709 {
6710 (void) SetImageOption(image_info,option+1,"undefined");
6711 break;
6712 }
6713 (void) SetImageOption(image_info,option+1,argv[i+1]);
6714 break;
6715 }
6716 if (LocaleCompare("dither",option+1) == 0)
6717 {
6718 if (*option == '+')
6719 {
6720 image_info->dither=MagickFalse;
6721 (void) SetImageOption(image_info,option+1,"undefined");
6722 break;
6723 }
6724 (void) SetImageOption(image_info,option+1,argv[i+1]);
6725 image_info->dither=MagickTrue;
6726 break;
6727 }
6728 break;
6729 }
6730 case 'e':
6731 {
6732 if (LocaleCompare("encoding",option+1) == 0)
6733 {
6734 if (*option == '+')
6735 {
6736 (void) SetImageOption(image_info,option+1,"undefined");
6737 break;
6738 }
6739 (void) SetImageOption(image_info,option+1,argv[i+1]);
6740 break;
6741 }
6742 if (LocaleCompare("endian",option+1) == 0)
6743 {
6744 if (*option == '+')
6745 {
6746 image_info->endian=UndefinedEndian;
6747 (void) SetImageOption(image_info,option+1,"undefined");
6748 break;
6749 }
6750 image_info->endian=(EndianType) ParseMagickOption(
6751 MagickEndianOptions,MagickFalse,argv[i+1]);
6752 (void) SetImageOption(image_info,option+1,argv[i+1]);
6753 break;
6754 }
6755 if (LocaleCompare("extract",option+1) == 0)
6756 {
6757 /*
6758 Set image extract geometry.
6759 */
6760 if (*option == '+')
6761 {
6762 if (image_info->extract != (char *) NULL)
6763 image_info->extract=DestroyString(image_info->extract);
6764 break;
6765 }
6766 (void) CloneString(&image_info->extract,argv[i+1]);
6767 break;
6768 }
6769 break;
6770 }
6771 case 'f':
6772 {
6773 if (LocaleCompare("fill",option+1) == 0)
6774 {
6775 if (*option == '+')
6776 {
6777 (void) SetImageOption(image_info,option+1,"none");
6778 break;
6779 }
6780 (void) SetImageOption(image_info,option+1,argv[i+1]);
6781 break;
6782 }
6783 if (LocaleCompare("filter",option+1) == 0)
6784 {
6785 if (*option == '+')
6786 {
6787 (void) SetImageOption(image_info,option+1,"undefined");
6788 break;
6789 }
6790 (void) SetImageOption(image_info,option+1,argv[i+1]);
6791 break;
6792 }
6793 if (LocaleCompare("font",option+1) == 0)
6794 {
6795 if (*option == '+')
6796 {
6797 if (image_info->font != (char *) NULL)
6798 image_info->font=DestroyString(image_info->font);
6799 break;
6800 }
6801 (void) CloneString(&image_info->font,argv[i+1]);
6802 break;
6803 }
6804 if (LocaleCompare("format",option+1) == 0)
6805 {
6806 register const char
6807 *q;
6808
6809 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6810 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6811 image_info->ping=MagickFalse;
6812 (void) SetImageOption(image_info,option+1,argv[i+1]);
6813 break;
6814 }
6815 if (LocaleCompare("fuzz",option+1) == 0)
6816 {
6817 if (*option == '+')
6818 {
6819 image_info->fuzz=0.0;
6820 (void) SetImageOption(image_info,option+1,"0");
6821 break;
6822 }
cristyf2f27272009-12-17 14:48:46 +00006823 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006824 1.0);
6825 (void) SetImageOption(image_info,option+1,argv[i+1]);
6826 break;
6827 }
6828 break;
6829 }
6830 case 'g':
6831 {
6832 if (LocaleCompare("gravity",option+1) == 0)
6833 {
6834 if (*option == '+')
6835 {
6836 (void) SetImageOption(image_info,option+1,"undefined");
6837 break;
6838 }
6839 (void) SetImageOption(image_info,option+1,argv[i+1]);
6840 break;
6841 }
6842 if (LocaleCompare("green-primary",option+1) == 0)
6843 {
6844 if (*option == '+')
6845 {
6846 (void) SetImageOption(image_info,option+1,"0.0");
6847 break;
6848 }
6849 (void) SetImageOption(image_info,option+1,argv[i+1]);
6850 break;
6851 }
6852 break;
6853 }
6854 case 'i':
6855 {
6856 if (LocaleCompare("intent",option+1) == 0)
6857 {
6858 if (*option == '+')
6859 {
6860 (void) SetImageOption(image_info,option+1,"undefined");
6861 break;
6862 }
6863 (void) SetImageOption(image_info,option+1,argv[i+1]);
6864 break;
6865 }
6866 if (LocaleCompare("interlace",option+1) == 0)
6867 {
6868 if (*option == '+')
6869 {
6870 image_info->interlace=UndefinedInterlace;
6871 (void) SetImageOption(image_info,option+1,"undefined");
6872 break;
6873 }
6874 image_info->interlace=(InterlaceType) ParseMagickOption(
6875 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6876 (void) SetImageOption(image_info,option+1,argv[i+1]);
6877 break;
6878 }
cristyb32b90a2009-09-07 21:45:48 +00006879 if (LocaleCompare("interline-spacing",option+1) == 0)
6880 {
6881 if (*option == '+')
6882 {
6883 (void) SetImageOption(image_info,option+1,"undefined");
6884 break;
6885 }
6886 (void) SetImageOption(image_info,option+1,argv[i+1]);
6887 break;
6888 }
cristy3ed852e2009-09-05 21:47:34 +00006889 if (LocaleCompare("interpolate",option+1) == 0)
6890 {
6891 if (*option == '+')
6892 {
6893 (void) SetImageOption(image_info,option+1,"undefined");
6894 break;
6895 }
6896 (void) SetImageOption(image_info,option+1,argv[i+1]);
6897 break;
6898 }
6899 if (LocaleCompare("interword-spacing",option+1) == 0)
6900 {
6901 if (*option == '+')
6902 {
6903 (void) SetImageOption(image_info,option+1,"undefined");
6904 break;
6905 }
6906 (void) SetImageOption(image_info,option+1,argv[i+1]);
6907 break;
6908 }
6909 break;
6910 }
6911 case 'k':
6912 {
6913 if (LocaleCompare("kerning",option+1) == 0)
6914 {
6915 if (*option == '+')
6916 {
6917 (void) SetImageOption(image_info,option+1,"undefined");
6918 break;
6919 }
6920 (void) SetImageOption(image_info,option+1,argv[i+1]);
6921 break;
6922 }
6923 break;
6924 }
6925 case 'l':
6926 {
6927 if (LocaleCompare("label",option+1) == 0)
6928 {
6929 if (*option == '+')
6930 {
6931 (void) DeleteImageOption(image_info,option+1);
6932 break;
6933 }
6934 (void) SetImageOption(image_info,option+1,argv[i+1]);
6935 break;
6936 }
6937 if (LocaleCompare("limit",option+1) == 0)
6938 {
6939 MagickSizeType
6940 limit;
6941
6942 ResourceType
6943 type;
6944
6945 if (*option == '+')
6946 break;
6947 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6948 MagickFalse,argv[i+1]);
6949 limit=MagickResourceInfinity;
6950 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006951 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006952 (void) SetMagickResourceLimit(type,limit);
6953 break;
6954 }
6955 if (LocaleCompare("list",option+1) == 0)
6956 {
6957 long
6958 list;
6959
6960 /*
6961 Display configuration list.
6962 */
6963 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6964 switch (list)
6965 {
6966 case MagickCoderOptions:
6967 {
6968 (void) ListCoderInfo((FILE *) NULL,exception);
6969 break;
6970 }
6971 case MagickColorOptions:
6972 {
6973 (void) ListColorInfo((FILE *) NULL,exception);
6974 break;
6975 }
6976 case MagickConfigureOptions:
6977 {
6978 (void) ListConfigureInfo((FILE *) NULL,exception);
6979 break;
6980 }
6981 case MagickDelegateOptions:
6982 {
6983 (void) ListDelegateInfo((FILE *) NULL,exception);
6984 break;
6985 }
6986 case MagickFontOptions:
6987 {
6988 (void) ListTypeInfo((FILE *) NULL,exception);
6989 break;
6990 }
6991 case MagickFormatOptions:
6992 {
6993 (void) ListMagickInfo((FILE *) NULL,exception);
6994 break;
6995 }
6996 case MagickLocaleOptions:
6997 {
6998 (void) ListLocaleInfo((FILE *) NULL,exception);
6999 break;
7000 }
7001 case MagickLogOptions:
7002 {
7003 (void) ListLogInfo((FILE *) NULL,exception);
7004 break;
7005 }
7006 case MagickMagicOptions:
7007 {
7008 (void) ListMagicInfo((FILE *) NULL,exception);
7009 break;
7010 }
7011 case MagickMimeOptions:
7012 {
7013 (void) ListMimeInfo((FILE *) NULL,exception);
7014 break;
7015 }
7016 case MagickModuleOptions:
7017 {
7018 (void) ListModuleInfo((FILE *) NULL,exception);
7019 break;
7020 }
7021 case MagickPolicyOptions:
7022 {
7023 (void) ListPolicyInfo((FILE *) NULL,exception);
7024 break;
7025 }
7026 case MagickResourceOptions:
7027 {
7028 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7029 break;
7030 }
7031 case MagickThresholdOptions:
7032 {
7033 (void) ListThresholdMaps((FILE *) NULL,exception);
7034 break;
7035 }
7036 default:
7037 {
7038 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7039 exception);
7040 break;
7041 }
7042 }
7043 }
7044 if (LocaleCompare("log",option+1) == 0)
7045 {
7046 if (*option == '+')
7047 break;
7048 (void) SetLogFormat(argv[i+1]);
7049 break;
7050 }
7051 if (LocaleCompare("loop",option+1) == 0)
7052 {
7053 if (*option == '+')
7054 {
7055 (void) SetImageOption(image_info,option+1,"0");
7056 break;
7057 }
7058 (void) SetImageOption(image_info,option+1,argv[i+1]);
7059 break;
7060 }
7061 break;
7062 }
7063 case 'm':
7064 {
7065 if (LocaleCompare("matte",option+1) == 0)
7066 {
7067 if (*option == '+')
7068 {
7069 (void) SetImageOption(image_info,option+1,"false");
7070 break;
7071 }
7072 (void) SetImageOption(image_info,option+1,"true");
7073 break;
7074 }
7075 if (LocaleCompare("mattecolor",option+1) == 0)
7076 {
7077 if (*option == '+')
7078 {
7079 (void) SetImageOption(image_info,option+1,argv[i+1]);
7080 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7081 exception);
7082 break;
7083 }
7084 (void) SetImageOption(image_info,option+1,argv[i+1]);
7085 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7086 exception);
7087 break;
7088 }
7089 if (LocaleCompare("monitor",option+1) == 0)
7090 {
7091 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7092 (void *) NULL);
7093 break;
7094 }
7095 if (LocaleCompare("monochrome",option+1) == 0)
7096 {
7097 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7098 break;
7099 }
7100 break;
7101 }
7102 case 'o':
7103 {
7104 if (LocaleCompare("orient",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
7108 image_info->orientation=UndefinedOrientation;
7109 (void) SetImageOption(image_info,option+1,"undefined");
7110 break;
7111 }
7112 image_info->orientation=(OrientationType) ParseMagickOption(
7113 MagickOrientationOptions,MagickFalse,argv[i+1]);
7114 (void) SetImageOption(image_info,option+1,"undefined");
7115 break;
7116 }
7117 }
7118 case 'p':
7119 {
7120 if (LocaleCompare("page",option+1) == 0)
7121 {
7122 char
7123 *canonical_page,
7124 page[MaxTextExtent];
7125
7126 const char
7127 *image_option;
7128
7129 MagickStatusType
7130 flags;
7131
7132 RectangleInfo
7133 geometry;
7134
7135 if (*option == '+')
7136 {
7137 (void) DeleteImageOption(image_info,option+1);
7138 (void) CloneString(&image_info->page,(char *) NULL);
7139 break;
7140 }
7141 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7142 image_option=GetImageOption(image_info,"page");
7143 if (image_option != (const char *) NULL)
7144 flags=ParseAbsoluteGeometry(image_option,&geometry);
7145 canonical_page=GetPageGeometry(argv[i+1]);
7146 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7147 canonical_page=DestroyString(canonical_page);
7148 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
7149 geometry.width,geometry.height);
7150 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7151 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7152 geometry.width,geometry.height,geometry.x,geometry.y);
7153 (void) SetImageOption(image_info,option+1,page);
7154 (void) CloneString(&image_info->page,page);
7155 break;
7156 }
7157 if (LocaleCompare("pen",option+1) == 0)
7158 {
7159 if (*option == '+')
7160 {
7161 (void) SetImageOption(image_info,option+1,"none");
7162 break;
7163 }
7164 (void) SetImageOption(image_info,option+1,argv[i+1]);
7165 break;
7166 }
7167 if (LocaleCompare("ping",option+1) == 0)
7168 {
7169 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7170 break;
7171 }
7172 if (LocaleCompare("pointsize",option+1) == 0)
7173 {
7174 if (*option == '+')
7175 geometry_info.rho=0.0;
7176 else
7177 (void) ParseGeometry(argv[i+1],&geometry_info);
7178 image_info->pointsize=geometry_info.rho;
7179 break;
7180 }
cristye7f51092010-01-17 00:39:37 +00007181 if (LocaleCompare("precision",option+1) == 0)
7182 {
cristybf2766a2010-01-17 03:33:23 +00007183 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007184 break;
7185 }
cristy3ed852e2009-09-05 21:47:34 +00007186 if (LocaleCompare("preview",option+1) == 0)
7187 {
7188 /*
7189 Preview image.
7190 */
7191 if (*option == '+')
7192 {
7193 image_info->preview_type=UndefinedPreview;
7194 break;
7195 }
7196 image_info->preview_type=(PreviewType) ParseMagickOption(
7197 MagickPreviewOptions,MagickFalse,argv[i+1]);
7198 break;
7199 }
7200 break;
7201 }
7202 case 'q':
7203 {
7204 if (LocaleCompare("quality",option+1) == 0)
7205 {
7206 /*
7207 Set image compression quality.
7208 */
7209 if (*option == '+')
7210 {
7211 image_info->quality=UndefinedCompressionQuality;
7212 (void) SetImageOption(image_info,option+1,"0");
7213 break;
7214 }
cristye27293e2009-12-18 02:53:20 +00007215 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007216 (void) SetImageOption(image_info,option+1,argv[i+1]);
7217 break;
7218 }
7219 if (LocaleCompare("quiet",option+1) == 0)
7220 {
7221 static WarningHandler
7222 warning_handler = (WarningHandler) NULL;
7223
7224 if (*option == '+')
7225 {
7226 /*
7227 Restore error or warning messages.
7228 */
7229 warning_handler=SetWarningHandler(warning_handler);
7230 break;
7231 }
7232 /*
7233 Suppress error or warning messages.
7234 */
7235 warning_handler=SetWarningHandler((WarningHandler) NULL);
7236 break;
7237 }
7238 break;
7239 }
7240 case 'r':
7241 {
7242 if (LocaleCompare("red-primary",option+1) == 0)
7243 {
7244 if (*option == '+')
7245 {
7246 (void) SetImageOption(image_info,option+1,"0.0");
7247 break;
7248 }
7249 (void) SetImageOption(image_info,option+1,argv[i+1]);
7250 break;
7251 }
7252 break;
7253 }
7254 case 's':
7255 {
7256 if (LocaleCompare("sampling-factor",option+1) == 0)
7257 {
7258 /*
7259 Set image sampling factor.
7260 */
7261 if (*option == '+')
7262 {
7263 if (image_info->sampling_factor != (char *) NULL)
7264 image_info->sampling_factor=DestroyString(
7265 image_info->sampling_factor);
7266 break;
7267 }
7268 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7269 break;
7270 }
7271 if (LocaleCompare("scene",option+1) == 0)
7272 {
7273 /*
7274 Set image scene.
7275 */
7276 if (*option == '+')
7277 {
7278 image_info->scene=0;
7279 (void) SetImageOption(image_info,option+1,"0");
7280 break;
7281 }
cristye27293e2009-12-18 02:53:20 +00007282 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007283 (void) SetImageOption(image_info,option+1,argv[i+1]);
7284 break;
7285 }
7286 if (LocaleCompare("seed",option+1) == 0)
7287 {
7288 unsigned long
7289 seed;
7290
7291 if (*option == '+')
7292 {
7293 seed=(unsigned long) time((time_t *) NULL);
7294 SeedPseudoRandomGenerator(seed);
7295 break;
7296 }
cristye27293e2009-12-18 02:53:20 +00007297 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007298 SeedPseudoRandomGenerator(seed);
7299 break;
7300 }
7301 if (LocaleCompare("size",option+1) == 0)
7302 {
7303 if (*option == '+')
7304 {
7305 if (image_info->size != (char *) NULL)
7306 image_info->size=DestroyString(image_info->size);
7307 break;
7308 }
7309 (void) CloneString(&image_info->size,argv[i+1]);
7310 break;
7311 }
7312 if (LocaleCompare("stroke",option+1) == 0)
7313 {
7314 if (*option == '+')
7315 {
7316 (void) SetImageOption(image_info,option+1,"none");
7317 break;
7318 }
7319 (void) SetImageOption(image_info,option+1,argv[i+1]);
7320 break;
7321 }
7322 if (LocaleCompare("strokewidth",option+1) == 0)
7323 {
7324 if (*option == '+')
7325 {
7326 (void) SetImageOption(image_info,option+1,"0");
7327 break;
7328 }
7329 (void) SetImageOption(image_info,option+1,argv[i+1]);
7330 break;
7331 }
7332 break;
7333 }
7334 case 't':
7335 {
7336 if (LocaleCompare("taint",option+1) == 0)
7337 {
7338 if (*option == '+')
7339 {
7340 (void) SetImageOption(image_info,option+1,"false");
7341 break;
7342 }
7343 (void) SetImageOption(image_info,option+1,"true");
7344 break;
7345 }
7346 if (LocaleCompare("texture",option+1) == 0)
7347 {
7348 if (*option == '+')
7349 {
7350 if (image_info->texture != (char *) NULL)
7351 image_info->texture=DestroyString(image_info->texture);
7352 break;
7353 }
7354 (void) CloneString(&image_info->texture,argv[i+1]);
7355 break;
7356 }
7357 if (LocaleCompare("tile-offset",option+1) == 0)
7358 {
7359 if (*option == '+')
7360 {
7361 (void) SetImageOption(image_info,option+1,"0");
7362 break;
7363 }
7364 (void) SetImageOption(image_info,option+1,argv[i+1]);
7365 break;
7366 }
7367 if (LocaleCompare("transparent-color",option+1) == 0)
7368 {
7369 if (*option == '+')
7370 {
7371 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7372 (void) SetImageOption(image_info,option+1,"none");
7373 break;
7374 }
7375 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7376 exception);
7377 (void) SetImageOption(image_info,option+1,argv[i+1]);
7378 break;
7379 }
7380 if (LocaleCompare("type",option+1) == 0)
7381 {
7382 if (*option == '+')
7383 {
7384 image_info->type=UndefinedType;
7385 (void) SetImageOption(image_info,option+1,"undefined");
7386 break;
7387 }
7388 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7389 MagickFalse,argv[i+1]);
7390 (void) SetImageOption(image_info,option+1,argv[i+1]);
7391 break;
7392 }
7393 break;
7394 }
7395 case 'u':
7396 {
7397 if (LocaleCompare("undercolor",option+1) == 0)
7398 {
7399 if (*option == '+')
7400 {
7401 (void) DeleteImageOption(image_info,option+1);
7402 break;
7403 }
7404 (void) SetImageOption(image_info,option+1,argv[i+1]);
7405 break;
7406 }
7407 if (LocaleCompare("units",option+1) == 0)
7408 {
7409 if (*option == '+')
7410 {
7411 image_info->units=UndefinedResolution;
7412 (void) SetImageOption(image_info,option+1,"undefined");
7413 break;
7414 }
7415 image_info->units=(ResolutionType) ParseMagickOption(
7416 MagickResolutionOptions,MagickFalse,argv[i+1]);
7417 (void) SetImageOption(image_info,option+1,argv[i+1]);
7418 break;
7419 }
7420 break;
7421 }
7422 case 'v':
7423 {
7424 if (LocaleCompare("verbose",option+1) == 0)
7425 {
7426 if (*option == '+')
7427 {
7428 image_info->verbose=MagickFalse;
7429 break;
7430 }
7431 image_info->verbose=MagickTrue;
7432 image_info->ping=MagickFalse;
7433 break;
7434 }
7435 if (LocaleCompare("view",option+1) == 0)
7436 {
7437 if (*option == '+')
7438 {
7439 if (image_info->view != (char *) NULL)
7440 image_info->view=DestroyString(image_info->view);
7441 break;
7442 }
7443 (void) CloneString(&image_info->view,argv[i+1]);
7444 break;
7445 }
7446 if (LocaleCompare("virtual-pixel",option+1) == 0)
7447 {
7448 if (*option == '+')
7449 {
7450 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7451 (void) SetImageOption(image_info,option+1,"undefined");
7452 break;
7453 }
7454 image_info->virtual_pixel_method=(VirtualPixelMethod)
7455 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7456 argv[i+1]);
7457 (void) SetImageOption(image_info,option+1,argv[i+1]);
7458 break;
7459 }
7460 break;
7461 }
7462 case 'w':
7463 {
7464 if (LocaleCompare("white-point",option+1) == 0)
7465 {
7466 if (*option == '+')
7467 {
7468 (void) SetImageOption(image_info,option+1,"0.0");
7469 break;
7470 }
7471 (void) SetImageOption(image_info,option+1,argv[i+1]);
7472 break;
7473 }
7474 break;
7475 }
7476 default:
7477 break;
7478 }
7479 i+=count;
7480 }
7481 return(MagickTrue);
7482}
7483
7484/*
7485%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7486% %
7487% %
7488% %
7489+ M o g r i f y I m a g e L i s t %
7490% %
7491% %
7492% %
7493%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7494%
7495% MogrifyImageList() applies any command line options that might affect the
7496% entire image list (e.g. -append, -coalesce, etc.).
7497%
7498% The format of the MogrifyImage method is:
7499%
7500% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7501% const char **argv,Image **images,ExceptionInfo *exception)
7502%
7503% A description of each parameter follows:
7504%
7505% o image_info: the image info..
7506%
7507% o argc: Specifies a pointer to an integer describing the number of
7508% elements in the argument vector.
7509%
7510% o argv: Specifies a pointer to a text array containing the command line
7511% arguments.
7512%
7513% o images: the images.
7514%
7515% o exception: return any errors or warnings in this structure.
7516%
7517*/
7518WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7519 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7520{
7521 ChannelType
7522 channel;
7523
7524 const char
7525 *option;
7526
7527 long
7528 count,
7529 index;
7530
7531 MagickStatusType
7532 status;
7533
7534 QuantizeInfo
7535 *quantize_info;
7536
7537 register long
7538 i;
7539
7540 /*
7541 Apply options to the image list.
7542 */
7543 assert(image_info != (ImageInfo *) NULL);
7544 assert(image_info->signature == MagickSignature);
7545 assert(images != (Image **) NULL);
7546 assert((*images)->signature == MagickSignature);
7547 if ((*images)->debug != MagickFalse)
7548 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7549 (*images)->filename);
7550 if ((argc <= 0) || (*argv == (char *) NULL))
7551 return(MagickTrue);
7552 quantize_info=AcquireQuantizeInfo(image_info);
7553 channel=image_info->channel;
7554 status=MagickTrue;
7555 for (i=0; i < (long) argc; i++)
7556 {
cristy74fe8f12009-10-03 19:09:01 +00007557 if (*images == (Image *) NULL)
7558 break;
cristy3ed852e2009-09-05 21:47:34 +00007559 option=argv[i];
7560 if (IsMagickOption(option) == MagickFalse)
7561 continue;
7562 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7563 0L);
7564 if ((i+count) >= argc)
7565 break;
7566 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
7567 switch (*(option+1))
7568 {
7569 case 'a':
7570 {
7571 if (LocaleCompare("affinity",option+1) == 0)
7572 {
7573 (void) SyncImagesSettings(image_info,*images);
7574 if (*option == '+')
7575 {
7576 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7577 InheritException(exception,&(*images)->exception);
7578 break;
7579 }
7580 i++;
7581 break;
7582 }
7583 if (LocaleCompare("append",option+1) == 0)
7584 {
7585 Image
7586 *append_image;
7587
7588 (void) SyncImagesSettings(image_info,*images);
7589 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7590 MagickFalse,exception);
7591 if (append_image == (Image *) NULL)
7592 {
7593 status=MagickFalse;
7594 break;
7595 }
7596 *images=DestroyImageList(*images);
7597 *images=append_image;
7598 break;
7599 }
7600 if (LocaleCompare("average",option+1) == 0)
7601 {
7602 Image
7603 *average_image;
7604
cristyd18ae7c2010-03-07 17:39:52 +00007605 /*
7606 Average an image sequence (deprecated).
7607 */
cristy3ed852e2009-09-05 21:47:34 +00007608 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007609 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7610 exception);
cristy3ed852e2009-09-05 21:47:34 +00007611 if (average_image == (Image *) NULL)
7612 {
7613 status=MagickFalse;
7614 break;
7615 }
7616 *images=DestroyImageList(*images);
7617 *images=average_image;
7618 break;
7619 }
7620 break;
7621 }
7622 case 'c':
7623 {
7624 if (LocaleCompare("channel",option+1) == 0)
7625 {
7626 if (*option == '+')
7627 {
7628 channel=DefaultChannels;
7629 break;
7630 }
7631 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7632 break;
7633 }
7634 if (LocaleCompare("clut",option+1) == 0)
7635 {
7636 Image
7637 *clut_image,
7638 *image;
7639
7640 (void) SyncImagesSettings(image_info,*images);
7641 image=RemoveFirstImageFromList(images);
7642 clut_image=RemoveFirstImageFromList(images);
7643 if (clut_image == (Image *) NULL)
7644 {
7645 status=MagickFalse;
7646 break;
7647 }
7648 (void) ClutImageChannel(image,channel,clut_image);
7649 clut_image=DestroyImage(clut_image);
7650 InheritException(exception,&image->exception);
7651 *images=DestroyImageList(*images);
7652 *images=image;
7653 break;
7654 }
7655 if (LocaleCompare("coalesce",option+1) == 0)
7656 {
7657 Image
7658 *coalesce_image;
7659
7660 (void) SyncImagesSettings(image_info,*images);
7661 coalesce_image=CoalesceImages(*images,exception);
7662 if (coalesce_image == (Image *) NULL)
7663 {
7664 status=MagickFalse;
7665 break;
7666 }
7667 *images=DestroyImageList(*images);
7668 *images=coalesce_image;
7669 break;
7670 }
7671 if (LocaleCompare("combine",option+1) == 0)
7672 {
7673 Image
7674 *combine_image;
7675
7676 (void) SyncImagesSettings(image_info,*images);
7677 combine_image=CombineImages(*images,channel,exception);
7678 if (combine_image == (Image *) NULL)
7679 {
7680 status=MagickFalse;
7681 break;
7682 }
7683 *images=DestroyImageList(*images);
7684 *images=combine_image;
7685 break;
7686 }
7687 if (LocaleCompare("composite",option+1) == 0)
7688 {
7689 Image
7690 *mask_image,
7691 *composite_image,
7692 *image;
7693
7694 RectangleInfo
7695 geometry;
7696
7697 (void) SyncImagesSettings(image_info,*images);
7698 image=RemoveFirstImageFromList(images);
7699 composite_image=RemoveFirstImageFromList(images);
7700 if (composite_image == (Image *) NULL)
7701 {
7702 status=MagickFalse;
7703 break;
7704 }
7705 (void) TransformImage(&composite_image,(char *) NULL,
7706 composite_image->geometry);
7707 SetGeometry(composite_image,&geometry);
7708 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7709 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7710 &geometry);
7711 mask_image=RemoveFirstImageFromList(images);
7712 if (mask_image != (Image *) NULL)
7713 {
7714 if ((image->compose == DisplaceCompositeOp) ||
7715 (image->compose == DistortCompositeOp))
7716 {
7717 /*
7718 Merge Y displacement into X displacement image.
7719 */
7720 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7721 mask_image,0,0);
7722 mask_image=DestroyImage(mask_image);
7723 }
7724 else
7725 {
7726 /*
7727 Set a blending mask for the composition.
7728 */
7729 image->mask=mask_image;
7730 (void) NegateImage(image->mask,MagickFalse);
7731 }
7732 }
7733 (void) CompositeImageChannel(image,channel,image->compose,
7734 composite_image,geometry.x,geometry.y);
7735 if (image->mask != (Image *) NULL)
7736 image->mask=DestroyImage(image->mask);
7737 composite_image=DestroyImage(composite_image);
7738 InheritException(exception,&image->exception);
7739 *images=DestroyImageList(*images);
7740 *images=image;
7741 break;
7742 }
7743 if (LocaleCompare("crop",option+1) == 0)
7744 {
7745 MagickStatusType
7746 flags;
7747
7748 RectangleInfo
7749 geometry;
7750
7751 (void) SyncImagesSettings(image_info,*images);
7752 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7753 if (((geometry.width == 0) && (geometry.height == 0)) ||
7754 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7755 break;
7756 (void) TransformImages(images,argv[i+1],(char *) NULL);
7757 InheritException(exception,&(*images)->exception);
7758 break;
7759 }
7760 break;
7761 }
7762 case 'd':
7763 {
7764 if (LocaleCompare("deconstruct",option+1) == 0)
7765 {
7766 Image
7767 *deconstruct_image;
7768
7769 (void) SyncImagesSettings(image_info,*images);
7770 deconstruct_image=DeconstructImages(*images,exception);
7771 if (deconstruct_image == (Image *) NULL)
7772 {
7773 status=MagickFalse;
7774 break;
7775 }
7776 *images=DestroyImageList(*images);
7777 *images=deconstruct_image;
7778 break;
7779 }
7780 if (LocaleCompare("delete",option+1) == 0)
7781 {
7782 if (*option == '+')
7783 DeleteImages(images,"-1",exception);
7784 else
7785 DeleteImages(images,argv[i+1],exception);
7786 break;
7787 }
7788 if (LocaleCompare("dither",option+1) == 0)
7789 {
7790 if (*option == '+')
7791 {
7792 quantize_info->dither=MagickFalse;
7793 break;
7794 }
7795 quantize_info->dither=MagickTrue;
7796 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7797 MagickDitherOptions,MagickFalse,argv[i+1]);
7798 break;
7799 }
7800 break;
7801 }
cristyd18ae7c2010-03-07 17:39:52 +00007802 case 'e':
7803 {
7804 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7805 {
7806 Image
7807 *evaluate_image;
7808
7809 MagickEvaluateOperator
7810 op;
7811
7812 (void) SyncImageSettings(image_info,*images);
7813 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7814 MagickFalse,argv[i+1]);
7815 evaluate_image=EvaluateImages(*images,op,exception);
7816 if (evaluate_image == (Image *) NULL)
7817 {
7818 status=MagickFalse;
7819 break;
7820 }
7821 *images=DestroyImageList(*images);
7822 *images=evaluate_image;
7823 break;
7824 }
7825 break;
7826 }
cristy3ed852e2009-09-05 21:47:34 +00007827 case 'f':
7828 {
cristyf0a247f2009-10-04 00:20:03 +00007829 if (LocaleCompare("fft",option+1) == 0)
7830 {
7831 Image
7832 *fourier_image;
7833
7834 /*
7835 Implements the discrete Fourier transform (DFT).
7836 */
7837 (void) SyncImageSettings(image_info,*images);
7838 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7839 MagickTrue : MagickFalse,exception);
7840 if (fourier_image == (Image *) NULL)
7841 break;
7842 *images=DestroyImage(*images);
7843 *images=fourier_image;
7844 break;
7845 }
cristy3ed852e2009-09-05 21:47:34 +00007846 if (LocaleCompare("flatten",option+1) == 0)
7847 {
7848 Image
7849 *flatten_image;
7850
7851 (void) SyncImagesSettings(image_info,*images);
7852 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7853 if (flatten_image == (Image *) NULL)
7854 break;
7855 *images=DestroyImageList(*images);
7856 *images=flatten_image;
7857 break;
7858 }
7859 if (LocaleCompare("fx",option+1) == 0)
7860 {
7861 Image
7862 *fx_image;
7863
7864 (void) SyncImagesSettings(image_info,*images);
7865 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7866 if (fx_image == (Image *) NULL)
7867 {
7868 status=MagickFalse;
7869 break;
7870 }
7871 *images=DestroyImageList(*images);
7872 *images=fx_image;
7873 break;
7874 }
7875 break;
7876 }
7877 case 'h':
7878 {
7879 if (LocaleCompare("hald-clut",option+1) == 0)
7880 {
7881 Image
7882 *hald_image,
7883 *image;
7884
7885 (void) SyncImagesSettings(image_info,*images);
7886 image=RemoveFirstImageFromList(images);
7887 hald_image=RemoveFirstImageFromList(images);
7888 if (hald_image == (Image *) NULL)
7889 {
7890 status=MagickFalse;
7891 break;
7892 }
7893 (void) HaldClutImageChannel(image,channel,hald_image);
7894 hald_image=DestroyImage(hald_image);
7895 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007896 if (*images != (Image *) NULL)
7897 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007898 *images=image;
7899 break;
7900 }
7901 break;
7902 }
7903 case 'i':
7904 {
7905 if (LocaleCompare("ift",option+1) == 0)
7906 {
7907 Image
cristy8587f882009-11-13 20:28:49 +00007908 *fourier_image,
7909 *magnitude_image,
7910 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007911
7912 /*
7913 Implements the inverse fourier discrete Fourier transform (DFT).
7914 */
7915 (void) SyncImagesSettings(image_info,*images);
cristy8587f882009-11-13 20:28:49 +00007916 magnitude_image=RemoveFirstImageFromList(images);
7917 phase_image=RemoveFirstImageFromList(images);
7918 if (phase_image == (Image *) NULL)
7919 {
7920 status=MagickFalse;
7921 break;
7922 }
7923 fourier_image=InverseFourierTransformImage(magnitude_image,
7924 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007925 if (fourier_image == (Image *) NULL)
7926 break;
cristy0aff6ea2009-11-14 01:40:53 +00007927 if (*images != (Image *) NULL)
7928 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007929 *images=fourier_image;
7930 break;
7931 }
7932 if (LocaleCompare("insert",option+1) == 0)
7933 {
7934 Image
7935 *p,
7936 *q;
7937
7938 index=0;
7939 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007940 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007941 p=RemoveLastImageFromList(images);
7942 if (p == (Image *) NULL)
7943 {
7944 (void) ThrowMagickException(exception,GetMagickModule(),
7945 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7946 status=MagickFalse;
7947 break;
7948 }
7949 q=p;
7950 if (index == 0)
7951 PrependImageToList(images,q);
7952 else
7953 if (index == (long) GetImageListLength(*images))
7954 AppendImageToList(images,q);
7955 else
7956 {
7957 q=GetImageFromList(*images,index-1);
7958 if (q == (Image *) NULL)
7959 {
7960 (void) ThrowMagickException(exception,GetMagickModule(),
7961 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7962 status=MagickFalse;
7963 break;
7964 }
7965 InsertImageInList(&q,p);
7966 }
7967 *images=GetFirstImageInList(q);
7968 break;
7969 }
7970 break;
7971 }
7972 case 'l':
7973 {
7974 if (LocaleCompare("layers",option+1) == 0)
7975 {
7976 Image
7977 *layers;
7978
7979 ImageLayerMethod
7980 method;
7981
7982 (void) SyncImagesSettings(image_info,*images);
7983 layers=(Image *) NULL;
7984 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7985 MagickFalse,argv[i+1]);
7986 switch (method)
7987 {
7988 case CoalesceLayer:
7989 {
7990 layers=CoalesceImages(*images,exception);
7991 break;
7992 }
7993 case CompareAnyLayer:
7994 case CompareClearLayer:
7995 case CompareOverlayLayer:
7996 default:
7997 {
7998 layers=CompareImageLayers(*images,method,exception);
7999 break;
8000 }
8001 case MergeLayer:
8002 case FlattenLayer:
8003 case MosaicLayer:
8004 case TrimBoundsLayer:
8005 {
8006 layers=MergeImageLayers(*images,method,exception);
8007 break;
8008 }
8009 case DisposeLayer:
8010 {
8011 layers=DisposeImages(*images,exception);
8012 break;
8013 }
8014 case OptimizeImageLayer:
8015 {
8016 layers=OptimizeImageLayers(*images,exception);
8017 break;
8018 }
8019 case OptimizePlusLayer:
8020 {
8021 layers=OptimizePlusImageLayers(*images,exception);
8022 break;
8023 }
8024 case OptimizeTransLayer:
8025 {
8026 OptimizeImageTransparency(*images,exception);
8027 break;
8028 }
8029 case RemoveDupsLayer:
8030 {
8031 RemoveDuplicateLayers(images,exception);
8032 break;
8033 }
8034 case RemoveZeroLayer:
8035 {
8036 RemoveZeroDelayLayers(images,exception);
8037 break;
8038 }
8039 case OptimizeLayer:
8040 {
8041 /*
8042 General Purpose, GIF Animation Optimizer.
8043 */
8044 layers=CoalesceImages(*images,exception);
8045 if (layers == (Image *) NULL)
8046 {
8047 status=MagickFalse;
8048 break;
8049 }
8050 InheritException(exception,&layers->exception);
8051 *images=DestroyImageList(*images);
8052 *images=layers;
8053 layers=OptimizeImageLayers(*images,exception);
8054 if (layers == (Image *) NULL)
8055 {
8056 status=MagickFalse;
8057 break;
8058 }
8059 InheritException(exception,&layers->exception);
8060 *images=DestroyImageList(*images);
8061 *images=layers;
8062 layers=(Image *) NULL;
8063 OptimizeImageTransparency(*images,exception);
8064 InheritException(exception,&(*images)->exception);
8065 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8066 break;
8067 }
8068 case CompositeLayer:
8069 {
8070 CompositeOperator
8071 compose;
8072
8073 Image
8074 *source;
8075
8076 RectangleInfo
8077 geometry;
8078
8079 /*
8080 Split image sequence at the first 'NULL:' image.
8081 */
8082 source=(*images);
8083 while (source != (Image *) NULL)
8084 {
8085 source=GetNextImageInList(source);
8086 if ((source != (Image *) NULL) &&
8087 (LocaleCompare(source->magick,"NULL") == 0))
8088 break;
8089 }
8090 if (source != (Image *) NULL)
8091 {
8092 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8093 (GetNextImageInList(source) == (Image *) NULL))
8094 source=(Image *) NULL;
8095 else
8096 {
8097 /*
8098 Separate the two lists, junk the null: image.
8099 */
8100 source=SplitImageList(source->previous);
8101 DeleteImageFromList(&source);
8102 }
8103 }
8104 if (source == (Image *) NULL)
8105 {
8106 (void) ThrowMagickException(exception,GetMagickModule(),
8107 OptionError,"MissingNullSeparator","layers Composite");
8108 status=MagickFalse;
8109 break;
8110 }
8111 /*
8112 Adjust offset with gravity and virtual canvas.
8113 */
8114 SetGeometry(*images,&geometry);
8115 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8116 geometry.width=source->page.width != 0 ?
8117 source->page.width : source->columns;
8118 geometry.height=source->page.height != 0 ?
8119 source->page.height : source->rows;
8120 GravityAdjustGeometry((*images)->page.width != 0 ?
8121 (*images)->page.width : (*images)->columns,
8122 (*images)->page.height != 0 ? (*images)->page.height :
8123 (*images)->rows,(*images)->gravity,&geometry);
8124 compose=OverCompositeOp;
8125 option=GetImageOption(image_info,"compose");
8126 if (option != (const char *) NULL)
8127 compose=(CompositeOperator) ParseMagickOption(
8128 MagickComposeOptions,MagickFalse,option);
8129 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8130 exception);
8131 source=DestroyImageList(source);
8132 break;
8133 }
8134 }
8135 if (layers == (Image *) NULL)
8136 break;
8137 InheritException(exception,&layers->exception);
8138 *images=DestroyImageList(*images);
8139 *images=layers;
8140 break;
8141 }
8142 break;
8143 }
8144 case 'm':
8145 {
8146 if (LocaleCompare("map",option+1) == 0)
8147 {
8148 (void) SyncImagesSettings(image_info,*images);
8149 if (*option == '+')
8150 {
8151 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8152 InheritException(exception,&(*images)->exception);
8153 break;
8154 }
8155 i++;
8156 break;
8157 }
cristyf40785b2010-03-06 02:27:27 +00008158 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008159 {
8160 Image
cristyf40785b2010-03-06 02:27:27 +00008161 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008162
cristyd18ae7c2010-03-07 17:39:52 +00008163 /*
8164 Maximum image sequence (deprecated).
8165 */
cristy1c274c92010-03-06 02:06:45 +00008166 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008167 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008168 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008169 {
8170 status=MagickFalse;
8171 break;
8172 }
8173 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008174 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008175 break;
8176 }
cristyf40785b2010-03-06 02:27:27 +00008177 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008178 {
8179 Image
cristyf40785b2010-03-06 02:27:27 +00008180 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008181
cristyd18ae7c2010-03-07 17:39:52 +00008182 /*
8183 Minimum image sequence (deprecated).
8184 */
cristy1c274c92010-03-06 02:06:45 +00008185 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008186 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008187 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008188 {
8189 status=MagickFalse;
8190 break;
8191 }
8192 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008193 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008194 break;
8195 }
cristy3ed852e2009-09-05 21:47:34 +00008196 if (LocaleCompare("morph",option+1) == 0)
8197 {
8198 Image
8199 *morph_image;
8200
8201 (void) SyncImagesSettings(image_info,*images);
cristye27293e2009-12-18 02:53:20 +00008202 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008203 exception);
8204 if (morph_image == (Image *) NULL)
8205 {
8206 status=MagickFalse;
8207 break;
8208 }
8209 *images=DestroyImageList(*images);
8210 *images=morph_image;
8211 break;
8212 }
8213 if (LocaleCompare("mosaic",option+1) == 0)
8214 {
8215 Image
8216 *mosaic_image;
8217
8218 (void) SyncImagesSettings(image_info,*images);
8219 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8220 if (mosaic_image == (Image *) NULL)
8221 {
8222 status=MagickFalse;
8223 break;
8224 }
8225 *images=DestroyImageList(*images);
8226 *images=mosaic_image;
8227 break;
8228 }
8229 break;
8230 }
8231 case 'p':
8232 {
8233 if (LocaleCompare("print",option+1) == 0)
8234 {
8235 char
8236 *string;
8237
8238 (void) SyncImagesSettings(image_info,*images);
8239 string=InterpretImageProperties(image_info,*images,argv[i+1]);
8240 if (string == (char *) NULL)
8241 break;
8242 InheritException(exception,&(*images)->exception);
8243 (void) fprintf(stdout,"%s",string);
8244 string=DestroyString(string);
8245 }
8246 if (LocaleCompare("process",option+1) == 0)
8247 {
8248 char
8249 **arguments;
8250
8251 int
8252 j,
8253 number_arguments;
8254
8255 (void) SyncImagesSettings(image_info,*images);
8256 arguments=StringToArgv(argv[i+1],&number_arguments);
8257 if (arguments == (char **) NULL)
8258 break;
8259 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8260 {
8261 char
8262 breaker,
8263 quote,
8264 *token;
8265
8266 const char
8267 *arguments;
8268
8269 int
8270 next,
8271 status;
8272
8273 size_t
8274 length;
8275
8276 TokenInfo
8277 *token_info;
8278
8279 /*
8280 Support old style syntax, filter="-option arg".
8281 */
8282 length=strlen(argv[i+1]);
8283 token=(char *) NULL;
8284 if (~length >= MaxTextExtent)
8285 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8286 sizeof(*token));
8287 if (token == (char *) NULL)
8288 break;
8289 next=0;
8290 arguments=argv[i+1];
8291 token_info=AcquireTokenInfo();
8292 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8293 "\"",'\0',&breaker,&next,&quote);
8294 token_info=DestroyTokenInfo(token_info);
8295 if (status == 0)
8296 {
8297 const char
8298 *argv;
8299
8300 argv=(&(arguments[next]));
8301 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8302 exception);
8303 }
8304 token=DestroyString(token);
8305 break;
8306 }
8307 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8308 number_arguments-2,(const char **) arguments+2,exception);
8309 for (j=0; j < number_arguments; j++)
8310 arguments[j]=DestroyString(arguments[j]);
8311 arguments=(char **) RelinquishMagickMemory(arguments);
8312 break;
8313 }
8314 break;
8315 }
8316 case 'r':
8317 {
8318 if (LocaleCompare("reverse",option+1) == 0)
8319 {
8320 ReverseImageList(images);
8321 InheritException(exception,&(*images)->exception);
8322 break;
8323 }
8324 break;
8325 }
8326 case 's':
8327 {
8328 if (LocaleCompare("swap",option+1) == 0)
8329 {
8330 Image
8331 *p,
8332 *q,
8333 *swap;
8334
8335 long
8336 swap_index;
8337
8338 index=(-1);
8339 swap_index=(-2);
8340 if (*option != '+')
8341 {
8342 GeometryInfo
8343 geometry_info;
8344
8345 MagickStatusType
8346 flags;
8347
8348 swap_index=(-1);
8349 flags=ParseGeometry(argv[i+1],&geometry_info);
8350 index=(long) geometry_info.rho;
8351 if ((flags & SigmaValue) != 0)
8352 swap_index=(long) geometry_info.sigma;
8353 }
8354 p=GetImageFromList(*images,index);
8355 q=GetImageFromList(*images,swap_index);
8356 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8357 {
8358 (void) ThrowMagickException(exception,GetMagickModule(),
8359 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8360 status=MagickFalse;
8361 break;
8362 }
8363 if (p == q)
8364 break;
8365 swap=CloneImage(p,0,0,MagickTrue,exception);
8366 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8367 ReplaceImageInList(&q,swap);
8368 *images=GetFirstImageInList(q);
8369 break;
8370 }
8371 break;
8372 }
8373 case 'w':
8374 {
8375 if (LocaleCompare("write",option+1) == 0)
8376 {
cristy06609ee2010-03-17 20:21:27 +00008377 char
8378 key[MaxTextExtent];
8379
cristy3ed852e2009-09-05 21:47:34 +00008380 Image
8381 *write_images;
8382
8383 ImageInfo
8384 *write_info;
8385
8386 (void) SyncImagesSettings(image_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008387 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8388 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008389 write_images=(*images);
8390 if (*option == '+')
8391 write_images=CloneImageList(*images,exception);
8392 write_info=CloneImageInfo(image_info);
8393 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8394 write_info=DestroyImageInfo(write_info);
8395 if (*option == '+')
8396 write_images=DestroyImageList(write_images);
8397 break;
8398 }
8399 break;
8400 }
8401 default:
8402 break;
8403 }
8404 i+=count;
8405 }
8406 quantize_info=DestroyQuantizeInfo(quantize_info);
8407 return(status != 0 ? MagickTrue : MagickFalse);
8408}
8409
8410/*
8411%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8412% %
8413% %
8414% %
8415+ M o g r i f y I m a g e s %
8416% %
8417% %
8418% %
8419%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8420%
8421% MogrifyImages() applies image processing options to a sequence of images as
8422% prescribed by command line options.
8423%
8424% The format of the MogrifyImage method is:
8425%
8426% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8427% const MagickBooleanType post,const int argc,const char **argv,
8428% Image **images,Exceptioninfo *exception)
8429%
8430% A description of each parameter follows:
8431%
8432% o image_info: the image info..
8433%
8434% o post: If true, post process image list operators otherwise pre-process.
8435%
8436% o argc: Specifies a pointer to an integer describing the number of
8437% elements in the argument vector.
8438%
8439% o argv: Specifies a pointer to a text array containing the command line
8440% arguments.
8441%
8442% o images: the images.
8443%
8444% o exception: return any errors or warnings in this structure.
8445%
8446*/
8447WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8448 const MagickBooleanType post,const int argc,const char **argv,
8449 Image **images,ExceptionInfo *exception)
8450{
8451#define MogrifyImageTag "Mogrify/Image"
8452
8453 Image
8454 *image,
8455 *mogrify_images;
8456
cristy0e9f9c12010-02-11 03:00:47 +00008457 MagickBooleanType
8458 proceed;
8459
8460 MagickSizeType
8461 number_images;
8462
cristy3ed852e2009-09-05 21:47:34 +00008463 MagickStatusType
8464 status;
8465
8466 register long
8467 i;
8468
cristy3ed852e2009-09-05 21:47:34 +00008469 /*
8470 Apply options to individual images in the list.
8471 */
8472 assert(image_info != (ImageInfo *) NULL);
8473 assert(image_info->signature == MagickSignature);
8474 if (images == (Image **) NULL)
8475 return(MogrifyImage(image_info,argc,argv,images,exception));
8476 assert((*images)->signature == MagickSignature);
8477 if ((*images)->debug != MagickFalse)
8478 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8479 (*images)->filename);
8480 if ((argc <= 0) || (*argv == (char *) NULL))
8481 return(MagickTrue);
8482 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8483 (void *) NULL);
8484 mogrify_images=NewImageList();
8485 number_images=GetImageListLength(*images);
8486 status=0;
8487 if (post == MagickFalse)
8488 status&=MogrifyImageList(image_info,argc,argv,images,exception);
8489 for (i=0; i < (long) number_images; i++)
8490 {
8491 image=RemoveFirstImageFromList(images);
8492 if (image == (Image *) NULL)
8493 continue;
8494 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8495 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008496 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8497 number_images);
8498 if (proceed == MagickFalse)
8499 break;
cristy3ed852e2009-09-05 21:47:34 +00008500 }
8501 if (post != MagickFalse)
8502 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8503 *images=mogrify_images;
8504 return(status != 0 ? MagickTrue : MagickFalse);
8505}