blob: 88cb1afa8f53fb207a26990ac86c41871e57176c [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 {
cristy7d34ef22010-03-25 01:11:22 +00002194 if (*option == '+')
2195 {
2196 (void) SetImageProgressMonitor(*image,
2197 (MagickProgressMonitor) NULL,(void *) NULL);
2198 break;
2199 }
cristy3ed852e2009-09-05 21:47:34 +00002200 (void) SetImageProgressMonitor(*image,MonitorProgress,
2201 (void *) NULL);
2202 break;
2203 }
2204 if (LocaleCompare("monochrome",option+1) == 0)
2205 {
2206 (void) SyncImageSettings(image_info,*image);
2207 (void) SetImageType(*image,BilevelType);
2208 InheritException(exception,&(*image)->exception);
2209 break;
2210 }
anthony29188a82010-01-22 10:12:34 +00002211 if (LocaleCompare("morphology",option+1) == 0)
2212 {
2213 MorphologyMethod
2214 method;
2215
2216 KernelInfo
2217 *kernel;
2218
2219 char
2220 token[MaxTextExtent];
2221
2222 const char
2223 *p;
2224
cristyef656912010-03-05 19:54:59 +00002225 long
anthony29188a82010-01-22 10:12:34 +00002226 iterations;
2227
2228 Image
2229 *morphology_image;
2230 /*
2231 Morphological Image Operation
2232 */
2233 (void) SyncImageSettings(image_info,*image);
2234 p=argv[i+1];
2235 GetMagickToken(p,&p,token);
2236 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
2237 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002238 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002239 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002240 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002241 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002242 if ((*p != '\0'))
2243 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002244 kernel=AcquireKernelInfo(argv[i+2]);
2245 if (kernel == (KernelInfo *) NULL)
2246 ThrowWandFatalException(ResourceLimitFatalError,
2247 "MemoryAllocationFailed",(*image)->filename);
anthony930be612010-02-08 04:26:15 +00002248 if ( GetImageArtifact(*image,"showkernel") != (const char *) NULL)
2249 ShowKernelInfo(kernel); /* display the kernel to stderr */
anthony29188a82010-01-22 10:12:34 +00002250 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002251 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002252 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002253 if (morphology_image == (Image *) NULL)
2254 break;
2255 *image=DestroyImage(*image);
2256 *image=morphology_image;
2257 break;
2258 }
cristy3ed852e2009-09-05 21:47:34 +00002259 if (LocaleCompare("motion-blur",option+1) == 0)
2260 {
2261 Image
2262 *blur_image;
2263
2264 /*
2265 Motion blur image.
2266 */
2267 (void) SyncImageSettings(image_info,*image);
2268 flags=ParseGeometry(argv[i+1],&geometry_info);
2269 if ((flags & SigmaValue) == 0)
2270 geometry_info.sigma=1.0;
2271 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2272 geometry_info.sigma,geometry_info.xi,exception);
2273 if (blur_image == (Image *) NULL)
2274 break;
2275 *image=DestroyImage(*image);
2276 *image=blur_image;
2277 break;
2278 }
2279 break;
2280 }
2281 case 'n':
2282 {
2283 if (LocaleCompare("negate",option+1) == 0)
2284 {
2285 (void) SyncImageSettings(image_info,*image);
2286 (void) NegateImageChannel(*image,channel,*option == '+' ?
2287 MagickTrue : MagickFalse);
2288 InheritException(exception,&(*image)->exception);
2289 break;
2290 }
2291 if (LocaleCompare("noise",option+1) == 0)
2292 {
2293 Image
2294 *noisy_image;
2295
2296 (void) SyncImageSettings(image_info,*image);
2297 if (*option == '-')
2298 {
2299 (void) ParseGeometry(argv[i+1],&geometry_info);
2300 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2301 exception);
2302 }
2303 else
2304 {
2305 NoiseType
2306 noise;
2307
2308 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2309 MagickFalse,argv[i+1]);
2310 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2311 exception);
2312 }
2313 if (noisy_image == (Image *) NULL)
2314 break;
2315 *image=DestroyImage(*image);
2316 *image=noisy_image;
2317 break;
2318 }
2319 if (LocaleCompare("normalize",option+1) == 0)
2320 {
2321 (void) SyncImageSettings(image_info,*image);
2322 (void) NormalizeImageChannel(*image,channel);
2323 InheritException(exception,&(*image)->exception);
2324 break;
2325 }
2326 break;
2327 }
2328 case 'o':
2329 {
2330 if (LocaleCompare("opaque",option+1) == 0)
2331 {
2332 MagickPixelPacket
2333 target;
2334
2335 (void) SyncImageSettings(image_info,*image);
2336 (void) QueryMagickColor(argv[i+1],&target,exception);
2337 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2338 *option == '-' ? MagickFalse : MagickTrue);
2339 break;
2340 }
2341 if (LocaleCompare("ordered-dither",option+1) == 0)
2342 {
2343 (void) SyncImageSettings(image_info,*image);
2344 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2345 exception);
2346 break;
2347 }
2348 break;
2349 }
2350 case 'p':
2351 {
2352 if (LocaleCompare("paint",option+1) == 0)
2353 {
2354 Image
2355 *paint_image;
2356
2357 /*
2358 Oil paint image.
2359 */
2360 (void) SyncImageSettings(image_info,*image);
2361 (void) ParseGeometry(argv[i+1],&geometry_info);
2362 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2363 if (paint_image == (Image *) NULL)
2364 break;
2365 *image=DestroyImage(*image);
2366 *image=paint_image;
2367 break;
2368 }
2369 if (LocaleCompare("pen",option+1) == 0)
2370 {
2371 if (*option == '+')
2372 {
2373 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2374 break;
2375 }
2376 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2377 break;
2378 }
2379 if (LocaleCompare("pointsize",option+1) == 0)
2380 {
2381 if (*option == '+')
2382 (void) ParseGeometry("12",&geometry_info);
2383 else
2384 (void) ParseGeometry(argv[i+1],&geometry_info);
2385 draw_info->pointsize=geometry_info.rho;
2386 break;
2387 }
2388 if (LocaleCompare("polaroid",option+1) == 0)
2389 {
2390 double
2391 angle;
2392
2393 Image
2394 *polaroid_image;
2395
2396 RandomInfo
2397 *random_info;
2398
2399 /*
2400 Simulate a Polaroid picture.
2401 */
2402 (void) SyncImageSettings(image_info,*image);
2403 random_info=AcquireRandomInfo();
2404 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2405 random_info=DestroyRandomInfo(random_info);
2406 if (*option == '-')
2407 {
2408 SetGeometryInfo(&geometry_info);
2409 flags=ParseGeometry(argv[i+1],&geometry_info);
2410 angle=geometry_info.rho;
2411 }
2412 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2413 if (polaroid_image == (Image *) NULL)
2414 break;
2415 *image=DestroyImage(*image);
2416 *image=polaroid_image;
2417 break;
2418 }
2419 if (LocaleCompare("posterize",option+1) == 0)
2420 {
2421 /*
2422 Posterize image.
2423 */
2424 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00002425 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002426 quantize_info->dither);
2427 InheritException(exception,&(*image)->exception);
2428 break;
2429 }
2430 if (LocaleCompare("preview",option+1) == 0)
2431 {
2432 Image
2433 *preview_image;
2434
2435 PreviewType
2436 preview_type;
2437
2438 /*
2439 Preview image.
2440 */
2441 (void) SyncImageSettings(image_info,*image);
2442 if (*option == '+')
2443 preview_type=UndefinedPreview;
2444 else
2445 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2446 MagickFalse,argv[i+1]);
2447 preview_image=PreviewImage(*image,preview_type,exception);
2448 if (preview_image == (Image *) NULL)
2449 break;
2450 *image=DestroyImage(*image);
2451 *image=preview_image;
2452 break;
2453 }
2454 if (LocaleCompare("profile",option+1) == 0)
2455 {
2456 const char
2457 *name;
2458
2459 const StringInfo
2460 *profile;
2461
2462 Image
2463 *profile_image;
2464
2465 ImageInfo
2466 *profile_info;
2467
2468 (void) SyncImageSettings(image_info,*image);
2469 if (*option == '+')
2470 {
2471 /*
2472 Remove a profile from the image.
2473 */
2474 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2475 NULL,0,MagickTrue);
2476 InheritException(exception,&(*image)->exception);
2477 break;
2478 }
2479 /*
2480 Associate a profile with the image.
2481 */
2482 profile_info=CloneImageInfo(image_info);
2483 profile=GetImageProfile(*image,"iptc");
2484 if (profile != (StringInfo *) NULL)
2485 profile_info->profile=(void *) CloneStringInfo(profile);
2486 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2487 profile_info=DestroyImageInfo(profile_info);
2488 if (profile_image == (Image *) NULL)
2489 {
2490 char
2491 name[MaxTextExtent],
2492 filename[MaxTextExtent];
2493
2494 register char
2495 *p;
2496
2497 StringInfo
2498 *profile;
2499
2500 (void) CopyMagickString(filename,argv[i+1],MaxTextExtent);
2501 (void) CopyMagickString(name,argv[i+1],MaxTextExtent);
2502 for (p=filename; *p != '\0'; p++)
2503 if ((*p == ':') && (IsPathDirectory(argv[i+1]) < 0) &&
2504 (IsPathAccessible(argv[i+1]) == MagickFalse))
2505 {
2506 register char
2507 *q;
2508
2509 /*
2510 Look for profile name (e.g. name:profile).
2511 */
2512 (void) CopyMagickString(name,filename,(size_t)
2513 (p-filename+1));
2514 for (q=filename; *q != '\0'; q++)
2515 *q=(*++p);
2516 break;
2517 }
2518 profile=FileToStringInfo(filename,~0UL,exception);
2519 if (profile != (StringInfo *) NULL)
2520 {
2521 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2522 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2523 profile=DestroyStringInfo(profile);
2524 }
2525 break;
2526 }
2527 ResetImageProfileIterator(profile_image);
2528 name=GetNextImageProfile(profile_image);
2529 while (name != (const char *) NULL)
2530 {
2531 profile=GetImageProfile(profile_image,name);
2532 if (profile != (StringInfo *) NULL)
2533 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2534 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2535 name=GetNextImageProfile(profile_image);
2536 }
2537 profile_image=DestroyImage(profile_image);
2538 break;
2539 }
2540 break;
2541 }
2542 case 'q':
2543 {
2544 if (LocaleCompare("quantize",option+1) == 0)
2545 {
2546 if (*option == '+')
2547 {
2548 quantize_info->colorspace=UndefinedColorspace;
2549 break;
2550 }
2551 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2552 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2553 break;
2554 }
2555 break;
2556 }
2557 case 'r':
2558 {
2559 if (LocaleCompare("radial-blur",option+1) == 0)
2560 {
2561 Image
2562 *blur_image;
2563
2564 /*
2565 Radial blur image.
2566 */
2567 (void) SyncImageSettings(image_info,*image);
cristya5447be2010-01-11 00:20:51 +00002568 blur_image=RadialBlurImageChannel(*image,channel,
2569 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002570 if (blur_image == (Image *) NULL)
2571 break;
2572 *image=DestroyImage(*image);
2573 *image=blur_image;
2574 break;
2575 }
2576 if (LocaleCompare("raise",option+1) == 0)
2577 {
2578 /*
2579 Surround image with a raise of solid color.
2580 */
2581 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2582 if ((flags & SigmaValue) == 0)
2583 geometry.height=geometry.width;
2584 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2585 MagickFalse);
2586 InheritException(exception,&(*image)->exception);
2587 break;
2588 }
2589 if (LocaleCompare("random-threshold",option+1) == 0)
2590 {
2591 /*
2592 Threshold image.
2593 */
2594 (void) SyncImageSettings(image_info,*image);
2595 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2596 exception);
2597 break;
2598 }
2599 if (LocaleCompare("recolor",option+1) == 0)
2600 {
2601 char
2602 token[MaxTextExtent];
2603
2604 const char
2605 *p;
2606
2607 double
2608 *color_matrix;
2609
2610 Image
2611 *recolor_image;
2612
2613 register long
2614 x;
2615
2616 unsigned long
2617 order;
2618
2619 /*
2620 Transform color image.
2621 */
2622 (void) SyncImageSettings(image_info,*image);
2623 p=argv[i+1];
2624 for (x=0; *p != '\0'; x++)
2625 {
2626 GetMagickToken(p,&p,token);
2627 if (*token == ',')
2628 GetMagickToken(p,&p,token);
2629 }
2630 order=(unsigned long) sqrt((double) x+1.0);
2631 color_matrix=(double *) AcquireQuantumMemory(order,order*
2632 sizeof(*color_matrix));
2633 if (color_matrix == (double *) NULL)
2634 ThrowWandFatalException(ResourceLimitFatalError,
2635 "MemoryAllocationFailed",(*image)->filename);
2636 p=argv[i+1];
2637 for (x=0; (x < (long) (order*order)) && (*p != '\0'); x++)
2638 {
2639 GetMagickToken(p,&p,token);
2640 if (*token == ',')
2641 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00002642 color_matrix[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00002643 }
2644 for ( ; x < (long) (order*order); x++)
2645 color_matrix[x]=0.0;
2646 recolor_image=RecolorImage(*image,order,color_matrix,exception);
2647 color_matrix=(double *) RelinquishMagickMemory(color_matrix);
2648 if (recolor_image == (Image *) NULL)
2649 break;
2650 *image=DestroyImage(*image);
2651 *image=recolor_image;
2652 break;
2653 }
2654 if (LocaleCompare("region",option+1) == 0)
2655 {
2656 Image
2657 *crop_image;
2658
2659 (void) SyncImageSettings(image_info,*image);
2660 if (region_image != (Image *) NULL)
2661 {
2662 /*
2663 Composite region.
2664 */
2665 (void) CompositeImage(region_image,(*image)->matte !=
2666 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2667 region_geometry.x,region_geometry.y);
2668 InheritException(exception,&region_image->exception);
2669 *image=DestroyImage(*image);
2670 *image=region_image;
2671 }
2672 if (*option == '+')
2673 {
2674 if (region_image != (Image *) NULL)
2675 region_image=DestroyImage(region_image);
2676 break;
2677 }
2678 /*
2679 Apply transformations to a selected region of the image.
2680 */
2681 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2682 exception);
2683 crop_image=CropImage(*image,&region_geometry,exception);
2684 if (crop_image == (Image *) NULL)
2685 break;
2686 region_image=(*image);
2687 *image=crop_image;
2688 break;
2689 }
2690 if (LocaleCompare("render",option+1) == 0)
2691 {
2692 (void) SyncImageSettings(image_info,*image);
2693 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2694 break;
2695 }
2696 if (LocaleCompare("remap",option+1) == 0)
2697 {
2698 Image
2699 *remap_image;
2700
2701 /*
2702 Transform image colors to match this set of colors.
2703 */
2704 (void) SyncImageSettings(image_info,*image);
2705 if (*option == '+')
2706 break;
2707 remap_image=GetImageCache(image_info,argv[i+1],exception);
2708 if (remap_image == (Image *) NULL)
2709 break;
2710 (void) RemapImage(quantize_info,*image,remap_image);
2711 InheritException(exception,&(*image)->exception);
2712 remap_image=DestroyImage(remap_image);
2713 break;
2714 }
2715 if (LocaleCompare("repage",option+1) == 0)
2716 {
2717 if (*option == '+')
2718 {
2719 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2720 break;
2721 }
2722 (void) ResetImagePage(*image,argv[i+1]);
2723 InheritException(exception,&(*image)->exception);
2724 break;
2725 }
2726 if (LocaleCompare("resample",option+1) == 0)
2727 {
2728 Image
2729 *resample_image;
2730
2731 /*
2732 Resample image.
2733 */
2734 (void) SyncImageSettings(image_info,*image);
2735 flags=ParseGeometry(argv[i+1],&geometry_info);
2736 if ((flags & SigmaValue) == 0)
2737 geometry_info.sigma=geometry_info.rho;
2738 resample_image=ResampleImage(*image,geometry_info.rho,
2739 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2740 if (resample_image == (Image *) NULL)
2741 break;
2742 *image=DestroyImage(*image);
2743 *image=resample_image;
2744 break;
2745 }
2746 if (LocaleCompare("resize",option+1) == 0)
2747 {
2748 Image
2749 *resize_image;
2750
2751 /*
2752 Resize image.
2753 */
2754 (void) SyncImageSettings(image_info,*image);
2755 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2756 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2757 (*image)->filter,(*image)->blur,exception);
2758 if (resize_image == (Image *) NULL)
2759 break;
2760 *image=DestroyImage(*image);
2761 *image=resize_image;
2762 break;
2763 }
2764 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2765 {
2766 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2767 break;
2768 }
2769 if (LocaleCompare("roll",option+1) == 0)
2770 {
2771 Image
2772 *roll_image;
2773
2774 /*
2775 Roll image.
2776 */
2777 (void) SyncImageSettings(image_info,*image);
2778 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2779 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2780 if (roll_image == (Image *) NULL)
2781 break;
2782 *image=DestroyImage(*image);
2783 *image=roll_image;
2784 break;
2785 }
2786 if (LocaleCompare("rotate",option+1) == 0)
2787 {
2788 char
2789 *geometry;
2790
2791 Image
2792 *rotate_image;
2793
2794 /*
2795 Check for conditional image rotation.
2796 */
2797 (void) SyncImageSettings(image_info,*image);
2798 if (strchr(argv[i+1],'>') != (char *) NULL)
2799 if ((*image)->columns <= (*image)->rows)
2800 break;
2801 if (strchr(argv[i+1],'<') != (char *) NULL)
2802 if ((*image)->columns >= (*image)->rows)
2803 break;
2804 /*
2805 Rotate image.
2806 */
2807 geometry=ConstantString(argv[i+1]);
2808 (void) SubstituteString(&geometry,">","");
2809 (void) SubstituteString(&geometry,"<","");
2810 (void) ParseGeometry(geometry,&geometry_info);
2811 geometry=DestroyString(geometry);
2812 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2813 if (rotate_image == (Image *) NULL)
2814 break;
2815 *image=DestroyImage(*image);
2816 *image=rotate_image;
2817 break;
2818 }
2819 break;
2820 }
2821 case 's':
2822 {
2823 if (LocaleCompare("sample",option+1) == 0)
2824 {
2825 Image
2826 *sample_image;
2827
2828 /*
2829 Sample image with pixel replication.
2830 */
2831 (void) SyncImageSettings(image_info,*image);
2832 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2833 sample_image=SampleImage(*image,geometry.width,geometry.height,
2834 exception);
2835 if (sample_image == (Image *) NULL)
2836 break;
2837 *image=DestroyImage(*image);
2838 *image=sample_image;
2839 break;
2840 }
2841 if (LocaleCompare("scale",option+1) == 0)
2842 {
2843 Image
2844 *scale_image;
2845
2846 /*
2847 Resize image.
2848 */
2849 (void) SyncImageSettings(image_info,*image);
2850 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2851 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2852 exception);
2853 if (scale_image == (Image *) NULL)
2854 break;
2855 *image=DestroyImage(*image);
2856 *image=scale_image;
2857 break;
2858 }
2859 if (LocaleCompare("selective-blur",option+1) == 0)
2860 {
2861 Image
2862 *blur_image;
2863
2864 /*
2865 Selectively blur pixels within a contrast threshold.
2866 */
2867 (void) SyncImageSettings(image_info,*image);
2868 flags=ParseGeometry(argv[i+1],&geometry_info);
2869 if ((flags & PercentValue) != 0)
2870 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2871 blur_image=SelectiveBlurImageChannel(*image,channel,
2872 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2873 if (blur_image == (Image *) NULL)
2874 break;
2875 *image=DestroyImage(*image);
2876 *image=blur_image;
2877 break;
2878 }
2879 if (LocaleCompare("separate",option+1) == 0)
2880 {
2881 Image
2882 *separate_images;
2883
2884 /*
2885 Break channels into separate images.
2886 */
2887 (void) SyncImageSettings(image_info,*image);
2888 separate_images=SeparateImages(*image,channel,exception);
2889 if (separate_images == (Image *) NULL)
2890 break;
2891 *image=DestroyImage(*image);
2892 *image=separate_images;
2893 break;
2894 }
2895 if (LocaleCompare("sepia-tone",option+1) == 0)
2896 {
2897 double
2898 threshold;
2899
2900 Image
2901 *sepia_image;
2902
2903 /*
2904 Sepia-tone image.
2905 */
2906 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002907 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002908 sepia_image=SepiaToneImage(*image,threshold,exception);
2909 if (sepia_image == (Image *) NULL)
2910 break;
2911 *image=DestroyImage(*image);
2912 *image=sepia_image;
2913 break;
2914 }
2915 if (LocaleCompare("segment",option+1) == 0)
2916 {
2917 /*
2918 Segment image.
2919 */
2920 (void) SyncImageSettings(image_info,*image);
2921 flags=ParseGeometry(argv[i+1],&geometry_info);
2922 if ((flags & SigmaValue) == 0)
2923 geometry_info.sigma=1.0;
2924 (void) SegmentImage(*image,(*image)->colorspace,image_info->verbose,
2925 geometry_info.rho,geometry_info.sigma);
2926 InheritException(exception,&(*image)->exception);
2927 break;
2928 }
2929 if (LocaleCompare("set",option+1) == 0)
2930 {
2931 /*
2932 Set image option.
2933 */
2934 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2935 (void) DeleteImageRegistry(argv[i+1]+9);
2936 else
2937 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2938 (void) DeleteImageOption(image_info,argv[i+1]+7);
2939 else
2940 (void) DeleteImageProperty(*image,argv[i+1]);
2941 if (*option == '-')
2942 {
2943 char
2944 *value;
2945
2946 value=InterpretImageProperties(image_info,*image,argv[i+2]);
2947 if (value != (char *) NULL)
2948 {
2949 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2950 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,
2951 value,exception);
2952 else
2953 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2954 {
2955 (void) SetImageOption(image_info,argv[i+1]+7,value);
2956 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2957 }
2958 else
2959 (void) SetImageProperty(*image,argv[i+1],value);
2960 value=DestroyString(value);
2961 }
2962 }
2963 break;
2964 }
2965 if (LocaleCompare("shade",option+1) == 0)
2966 {
2967 Image
2968 *shade_image;
2969
2970 /*
2971 Shade image.
2972 */
2973 (void) SyncImageSettings(image_info,*image);
2974 flags=ParseGeometry(argv[i+1],&geometry_info);
2975 if ((flags & SigmaValue) == 0)
2976 geometry_info.sigma=1.0;
2977 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2978 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2979 if (shade_image == (Image *) NULL)
2980 break;
2981 *image=DestroyImage(*image);
2982 *image=shade_image;
2983 break;
2984 }
2985 if (LocaleCompare("shadow",option+1) == 0)
2986 {
2987 Image
2988 *shadow_image;
2989
2990 /*
2991 Shadow image.
2992 */
2993 (void) SyncImageSettings(image_info,*image);
2994 flags=ParseGeometry(argv[i+1],&geometry_info);
2995 if ((flags & SigmaValue) == 0)
2996 geometry_info.sigma=1.0;
2997 if ((flags & XiValue) == 0)
2998 geometry_info.xi=4.0;
2999 if ((flags & PsiValue) == 0)
3000 geometry_info.psi=4.0;
3001 shadow_image=ShadowImage(*image,geometry_info.rho,
cristy0534a6b2010-03-18 01:19:38 +00003002 geometry_info.sigma,(long) ceil(geometry_info.xi-0.5),(long)
3003 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003004 if (shadow_image == (Image *) NULL)
3005 break;
3006 *image=DestroyImage(*image);
3007 *image=shadow_image;
3008 break;
3009 }
3010 if (LocaleCompare("sharpen",option+1) == 0)
3011 {
3012 Image
3013 *sharp_image;
3014
3015 /*
3016 Sharpen image.
3017 */
3018 (void) SyncImageSettings(image_info,*image);
3019 flags=ParseGeometry(argv[i+1],&geometry_info);
3020 if ((flags & SigmaValue) == 0)
3021 geometry_info.sigma=1.0;
3022 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
3023 geometry_info.sigma,exception);
3024 if (sharp_image == (Image *) NULL)
3025 break;
3026 *image=DestroyImage(*image);
3027 *image=sharp_image;
3028 break;
3029 }
3030 if (LocaleCompare("shave",option+1) == 0)
3031 {
3032 Image
3033 *shave_image;
3034
3035 /*
3036 Shave the image edges.
3037 */
3038 (void) SyncImageSettings(image_info,*image);
3039 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3040 shave_image=ShaveImage(*image,&geometry,exception);
3041 if (shave_image == (Image *) NULL)
3042 break;
3043 *image=DestroyImage(*image);
3044 *image=shave_image;
3045 break;
3046 }
3047 if (LocaleCompare("shear",option+1) == 0)
3048 {
3049 Image
3050 *shear_image;
3051
3052 /*
3053 Shear image.
3054 */
3055 (void) SyncImageSettings(image_info,*image);
3056 flags=ParseGeometry(argv[i+1],&geometry_info);
3057 if ((flags & SigmaValue) == 0)
3058 geometry_info.sigma=geometry_info.rho;
3059 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3060 exception);
3061 if (shear_image == (Image *) NULL)
3062 break;
3063 *image=DestroyImage(*image);
3064 *image=shear_image;
3065 break;
3066 }
3067 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3068 {
3069 /*
3070 Sigmoidal non-linearity contrast control.
3071 */
3072 (void) SyncImageSettings(image_info,*image);
3073 flags=ParseGeometry(argv[i+1],&geometry_info);
3074 if ((flags & SigmaValue) == 0)
3075 geometry_info.sigma=(double) QuantumRange/2.0;
3076 if ((flags & PercentValue) != 0)
3077 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3078 100.0;
3079 (void) SigmoidalContrastImageChannel(*image,channel,
3080 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3081 geometry_info.sigma);
3082 InheritException(exception,&(*image)->exception);
3083 break;
3084 }
3085 if (LocaleCompare("sketch",option+1) == 0)
3086 {
3087 Image
3088 *sketch_image;
3089
3090 /*
3091 Sketch image.
3092 */
3093 (void) SyncImageSettings(image_info,*image);
3094 flags=ParseGeometry(argv[i+1],&geometry_info);
3095 if ((flags & SigmaValue) == 0)
3096 geometry_info.sigma=1.0;
3097 sketch_image=SketchImage(*image,geometry_info.rho,
3098 geometry_info.sigma,geometry_info.xi,exception);
3099 if (sketch_image == (Image *) NULL)
3100 break;
3101 *image=DestroyImage(*image);
3102 *image=sketch_image;
3103 break;
3104 }
3105 if (LocaleCompare("solarize",option+1) == 0)
3106 {
3107 double
3108 threshold;
3109
3110 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003111 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003112 (void) SolarizeImage(*image,threshold);
3113 InheritException(exception,&(*image)->exception);
3114 break;
3115 }
3116 if (LocaleCompare("sparse-color",option+1) == 0)
3117 {
3118 Image
3119 *sparse_image;
3120
3121 SparseColorMethod
3122 method;
3123
3124 char
3125 *arguments;
3126
3127 /*
3128 Sparse Color Interpolated Gradient
3129 */
3130 (void) SyncImageSettings(image_info,*image);
3131 method=(SparseColorMethod) ParseMagickOption(
3132 MagickSparseColorOptions,MagickFalse,argv[i+1]);
3133 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
3134 InheritException(exception,&(*image)->exception);
3135 if (arguments == (char *) NULL)
3136 break;
3137 sparse_image=SparseColorOption(*image,channel,method,arguments,
3138 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3139 arguments=DestroyString(arguments);
3140 if (sparse_image == (Image *) NULL)
3141 break;
3142 *image=DestroyImage(*image);
3143 *image=sparse_image;
3144 break;
3145 }
3146 if (LocaleCompare("splice",option+1) == 0)
3147 {
3148 Image
3149 *splice_image;
3150
3151 /*
3152 Splice a solid color into the image.
3153 */
3154 (void) SyncImageSettings(image_info,*image);
3155 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3156 splice_image=SpliceImage(*image,&geometry,exception);
3157 if (splice_image == (Image *) NULL)
3158 break;
3159 *image=DestroyImage(*image);
3160 *image=splice_image;
3161 break;
3162 }
3163 if (LocaleCompare("spread",option+1) == 0)
3164 {
3165 Image
3166 *spread_image;
3167
3168 /*
3169 Spread an image.
3170 */
3171 (void) SyncImageSettings(image_info,*image);
3172 (void) ParseGeometry(argv[i+1],&geometry_info);
3173 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3174 if (spread_image == (Image *) NULL)
3175 break;
3176 *image=DestroyImage(*image);
3177 *image=spread_image;
3178 break;
3179 }
3180 if (LocaleCompare("stretch",option+1) == 0)
3181 {
3182 if (*option == '+')
3183 {
3184 draw_info->stretch=UndefinedStretch;
3185 break;
3186 }
3187 draw_info->stretch=(StretchType) ParseMagickOption(
3188 MagickStretchOptions,MagickFalse,argv[i+1]);
3189 break;
3190 }
3191 if (LocaleCompare("strip",option+1) == 0)
3192 {
3193 /*
3194 Strip image of profiles and comments.
3195 */
3196 (void) SyncImageSettings(image_info,*image);
3197 (void) StripImage(*image);
3198 InheritException(exception,&(*image)->exception);
3199 break;
3200 }
3201 if (LocaleCompare("stroke",option+1) == 0)
3202 {
3203 ExceptionInfo
3204 *sans;
3205
3206 if (*option == '+')
3207 {
3208 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3209 if (draw_info->stroke_pattern != (Image *) NULL)
3210 draw_info->stroke_pattern=DestroyImage(
3211 draw_info->stroke_pattern);
3212 break;
3213 }
3214 sans=AcquireExceptionInfo();
3215 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3216 sans=DestroyExceptionInfo(sans);
3217 if (status == MagickFalse)
3218 draw_info->stroke_pattern=GetImageCache(image_info,argv[i+1],
3219 exception);
3220 break;
3221 }
3222 if (LocaleCompare("strokewidth",option+1) == 0)
3223 {
cristyf2f27272009-12-17 14:48:46 +00003224 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003225 break;
3226 }
3227 if (LocaleCompare("style",option+1) == 0)
3228 {
3229 if (*option == '+')
3230 {
3231 draw_info->style=UndefinedStyle;
3232 break;
3233 }
3234 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3235 MagickFalse,argv[i+1]);
3236 break;
3237 }
3238 if (LocaleCompare("swirl",option+1) == 0)
3239 {
3240 Image
3241 *swirl_image;
3242
3243 /*
3244 Swirl image.
3245 */
3246 (void) SyncImageSettings(image_info,*image);
3247 (void) ParseGeometry(argv[i+1],&geometry_info);
3248 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3249 if (swirl_image == (Image *) NULL)
3250 break;
3251 *image=DestroyImage(*image);
3252 *image=swirl_image;
3253 break;
3254 }
3255 break;
3256 }
3257 case 't':
3258 {
3259 if (LocaleCompare("threshold",option+1) == 0)
3260 {
3261 double
3262 threshold;
3263
3264 /*
3265 Threshold image.
3266 */
3267 (void) SyncImageSettings(image_info,*image);
3268 if (*option == '+')
3269 threshold=(double) QuantumRange/2.5;
3270 else
cristyf2f27272009-12-17 14:48:46 +00003271 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003272 (void) BilevelImageChannel(*image,channel,threshold);
3273 InheritException(exception,&(*image)->exception);
3274 break;
3275 }
3276 if (LocaleCompare("thumbnail",option+1) == 0)
3277 {
3278 Image
3279 *thumbnail_image;
3280
3281 /*
3282 Thumbnail image.
3283 */
3284 (void) SyncImageSettings(image_info,*image);
3285 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3286 thumbnail_image=ThumbnailImage(*image,geometry.width,
3287 geometry.height,exception);
3288 if (thumbnail_image == (Image *) NULL)
3289 break;
3290 *image=DestroyImage(*image);
3291 *image=thumbnail_image;
3292 break;
3293 }
3294 if (LocaleCompare("tile",option+1) == 0)
3295 {
3296 if (*option == '+')
3297 {
3298 if (draw_info->fill_pattern != (Image *) NULL)
3299 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3300 break;
3301 }
3302 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
3303 exception);
3304 break;
3305 }
3306 if (LocaleCompare("tint",option+1) == 0)
3307 {
3308 Image
3309 *tint_image;
3310
3311 /*
3312 Tint the image.
3313 */
3314 (void) SyncImageSettings(image_info,*image);
3315 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3316 if (tint_image == (Image *) NULL)
3317 break;
3318 *image=DestroyImage(*image);
3319 *image=tint_image;
3320 break;
3321 }
3322 if (LocaleCompare("transform",option+1) == 0)
3323 {
3324 Image
3325 *transform_image;
3326
3327 /*
3328 Affine transform image.
3329 */
3330 (void) SyncImageSettings(image_info,*image);
3331 transform_image=AffineTransformImage(*image,&draw_info->affine,
3332 exception);
3333 if (transform_image == (Image *) NULL)
3334 break;
3335 *image=DestroyImage(*image);
3336 *image=transform_image;
3337 break;
3338 }
3339 if (LocaleCompare("transparent",option+1) == 0)
3340 {
3341 MagickPixelPacket
3342 target;
3343
3344 (void) SyncImageSettings(image_info,*image);
3345 (void) QueryMagickColor(argv[i+1],&target,exception);
3346 (void) TransparentPaintImage(*image,&target,(Quantum)
3347 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3348 InheritException(exception,&(*image)->exception);
3349 break;
3350 }
3351 if (LocaleCompare("transpose",option+1) == 0)
3352 {
3353 Image
3354 *transpose_image;
3355
3356 /*
3357 Transpose image scanlines.
3358 */
3359 (void) SyncImageSettings(image_info,*image);
3360 transpose_image=TransposeImage(*image,exception);
3361 if (transpose_image == (Image *) NULL)
3362 break;
3363 *image=DestroyImage(*image);
3364 *image=transpose_image;
3365 break;
3366 }
3367 if (LocaleCompare("transverse",option+1) == 0)
3368 {
3369 Image
3370 *transverse_image;
3371
3372 /*
3373 Transverse image scanlines.
3374 */
3375 (void) SyncImageSettings(image_info,*image);
3376 transverse_image=TransverseImage(*image,exception);
3377 if (transverse_image == (Image *) NULL)
3378 break;
3379 *image=DestroyImage(*image);
3380 *image=transverse_image;
3381 break;
3382 }
3383 if (LocaleCompare("treedepth",option+1) == 0)
3384 {
cristye27293e2009-12-18 02:53:20 +00003385 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003386 break;
3387 }
3388 if (LocaleCompare("trim",option+1) == 0)
3389 {
3390 Image
3391 *trim_image;
3392
3393 /*
3394 Trim image.
3395 */
3396 (void) SyncImageSettings(image_info,*image);
3397 trim_image=TrimImage(*image,exception);
3398 if (trim_image == (Image *) NULL)
3399 break;
3400 *image=DestroyImage(*image);
3401 *image=trim_image;
3402 break;
3403 }
3404 if (LocaleCompare("type",option+1) == 0)
3405 {
3406 ImageType
3407 type;
3408
3409 (void) SyncImageSettings(image_info,*image);
3410 if (*option == '+')
3411 type=UndefinedType;
3412 else
3413 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3414 argv[i+1]);
3415 (*image)->type=UndefinedType;
3416 (void) SetImageType(*image,type);
3417 InheritException(exception,&(*image)->exception);
3418 break;
3419 }
3420 break;
3421 }
3422 case 'u':
3423 {
3424 if (LocaleCompare("undercolor",option+1) == 0)
3425 {
3426 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3427 exception);
3428 break;
3429 }
cristy045bd902010-01-30 18:56:24 +00003430 if (LocaleCompare("unique",option+1) == 0)
3431 {
3432 if (*option == '+')
3433 {
3434 (void) DeleteImageArtifact(*image,"identify:unique");
3435 break;
3436 }
3437 (void) SetImageArtifact(*image,"identify:unique","true");
3438 break;
3439 }
cristy3ed852e2009-09-05 21:47:34 +00003440 if (LocaleCompare("unique-colors",option+1) == 0)
3441 {
3442 Image
3443 *unique_image;
3444
3445 /*
3446 Unique image colors.
3447 */
3448 (void) SyncImageSettings(image_info,*image);
3449 unique_image=UniqueImageColors(*image,exception);
3450 if (unique_image == (Image *) NULL)
3451 break;
3452 *image=DestroyImage(*image);
3453 *image=unique_image;
3454 break;
3455 }
3456 if (LocaleCompare("unsharp",option+1) == 0)
3457 {
3458 Image
3459 *unsharp_image;
3460
3461 /*
3462 Unsharp mask image.
3463 */
3464 (void) SyncImageSettings(image_info,*image);
3465 flags=ParseGeometry(argv[i+1],&geometry_info);
3466 if ((flags & SigmaValue) == 0)
3467 geometry_info.sigma=1.0;
3468 if ((flags & XiValue) == 0)
3469 geometry_info.xi=1.0;
3470 if ((flags & PsiValue) == 0)
3471 geometry_info.psi=0.05;
3472 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3473 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3474 geometry_info.psi,exception);
3475 if (unsharp_image == (Image *) NULL)
3476 break;
3477 *image=DestroyImage(*image);
3478 *image=unsharp_image;
3479 break;
3480 }
3481 break;
3482 }
3483 case 'v':
3484 {
3485 if (LocaleCompare("verbose",option+1) == 0)
3486 {
3487 (void) SetImageArtifact(*image,option+1,
3488 *option == '+' ? "false" : "true");
3489 break;
3490 }
3491 if (LocaleCompare("vignette",option+1) == 0)
3492 {
3493 Image
3494 *vignette_image;
3495
3496 /*
3497 Vignette image.
3498 */
3499 (void) SyncImageSettings(image_info,*image);
3500 flags=ParseGeometry(argv[i+1],&geometry_info);
3501 if ((flags & SigmaValue) == 0)
3502 geometry_info.sigma=1.0;
3503 if ((flags & XiValue) == 0)
3504 geometry_info.xi=0.1*(*image)->columns;
3505 if ((flags & PsiValue) == 0)
3506 geometry_info.psi=0.1*(*image)->rows;
3507 vignette_image=VignetteImage(*image,geometry_info.rho,
cristy0534a6b2010-03-18 01:19:38 +00003508 geometry_info.sigma,(long) ceil(geometry_info.xi-0.5),(long)
3509 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003510 if (vignette_image == (Image *) NULL)
3511 break;
3512 *image=DestroyImage(*image);
3513 *image=vignette_image;
3514 break;
3515 }
3516 if (LocaleCompare("virtual-pixel",option+1) == 0)
3517 {
3518 if (*option == '+')
3519 {
3520 (void) SetImageVirtualPixelMethod(*image,
3521 UndefinedVirtualPixelMethod);
3522 break;
3523 }
3524 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3525 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3526 argv[i+1]));
3527 break;
3528 }
3529 break;
3530 }
3531 case 'w':
3532 {
3533 if (LocaleCompare("wave",option+1) == 0)
3534 {
3535 Image
3536 *wave_image;
3537
3538 /*
3539 Wave image.
3540 */
3541 (void) SyncImageSettings(image_info,*image);
3542 flags=ParseGeometry(argv[i+1],&geometry_info);
3543 if ((flags & SigmaValue) == 0)
3544 geometry_info.sigma=1.0;
3545 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3546 exception);
3547 if (wave_image == (Image *) NULL)
3548 break;
3549 *image=DestroyImage(*image);
3550 *image=wave_image;
3551 break;
3552 }
3553 if (LocaleCompare("weight",option+1) == 0)
3554 {
cristye27293e2009-12-18 02:53:20 +00003555 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003556 if (LocaleCompare(argv[i+1],"all") == 0)
3557 draw_info->weight=0;
3558 if (LocaleCompare(argv[i+1],"bold") == 0)
3559 draw_info->weight=700;
3560 if (LocaleCompare(argv[i+1],"bolder") == 0)
3561 if (draw_info->weight <= 800)
3562 draw_info->weight+=100;
3563 if (LocaleCompare(argv[i+1],"lighter") == 0)
3564 if (draw_info->weight >= 100)
3565 draw_info->weight-=100;
3566 if (LocaleCompare(argv[i+1],"normal") == 0)
3567 draw_info->weight=400;
3568 break;
3569 }
3570 if (LocaleCompare("white-threshold",option+1) == 0)
3571 {
3572 /*
3573 White threshold image.
3574 */
3575 (void) SyncImageSettings(image_info,*image);
3576 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3577 exception);
3578 InheritException(exception,&(*image)->exception);
3579 break;
3580 }
3581 break;
3582 }
3583 default:
3584 break;
3585 }
3586 i+=count;
3587 }
3588 if (region_image != (Image *) NULL)
3589 {
3590 /*
3591 Composite transformed region onto image.
3592 */
3593 (void) SyncImageSettings(image_info,*image);
3594 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3595 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3596 region_geometry.y);
3597 InheritException(exception,&region_image->exception);
3598 *image=DestroyImage(*image);
3599 *image=region_image;
3600 }
3601 /*
3602 Free resources.
3603 */
3604 quantize_info=DestroyQuantizeInfo(quantize_info);
3605 draw_info=DestroyDrawInfo(draw_info);
3606 status=(*image)->exception.severity == UndefinedException ?
3607 MagickTrue : MagickFalse;
3608 return(status);
3609}
3610
3611/*
3612%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3613% %
3614% %
3615% %
3616% M o g r i f y I m a g e C o m m a n d %
3617% %
3618% %
3619% %
3620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3621%
3622% MogrifyImageCommand() transforms an image or a sequence of images. These
3623% transforms include image scaling, image rotation, color reduction, and
3624% others. The transmogrified image overwrites the original image.
3625%
3626% The format of the MogrifyImageCommand method is:
3627%
3628% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3629% const char **argv,char **metadata,ExceptionInfo *exception)
3630%
3631% A description of each parameter follows:
3632%
3633% o image_info: the image info.
3634%
3635% o argc: the number of elements in the argument vector.
3636%
3637% o argv: A text array containing the command line arguments.
3638%
3639% o metadata: any metadata is returned here.
3640%
3641% o exception: return any errors or warnings in this structure.
3642%
3643*/
3644
3645static MagickBooleanType MogrifyUsage(void)
3646{
3647 static const char
3648 *miscellaneous[]=
3649 {
3650 "-debug events display copious debugging information",
3651 "-help print program options",
3652 "-list type print a list of supported option arguments",
3653 "-log format format of debugging information",
3654 "-version print version information",
3655 (char *) NULL
3656 },
3657 *operators[]=
3658 {
3659 "-adaptive-blur geometry",
3660 " adaptively blur pixels; decrease effect near edges",
3661 "-adaptive-resize geometry",
3662 " adaptively resize image using 'mesh' interpolation",
3663 "-adaptive-sharpen geometry",
3664 " adaptively sharpen pixels; increase effect near edges",
3665 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3666 " transparent, extract, background, or shape",
3667 "-annotate geometry text",
3668 " annotate the image with text",
3669 "-auto-gamma automagically adjust gamma level of image",
3670 "-auto-level automagically adjust color levels of image",
3671 "-auto-orient automagically orient (rotate) image",
3672 "-bench iterations measure performance",
3673 "-black-threshold value",
3674 " force all pixels below the threshold into black",
3675 "-blue-shift simulate a scene at nighttime in the moonlight",
3676 "-blur geometry reduce image noise and reduce detail levels",
3677 "-border geometry surround image with a border of color",
3678 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003679 "-brightness-contrast geometry",
3680 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003681 "-cdl filename color correct with a color decision list",
3682 "-charcoal radius simulate a charcoal drawing",
3683 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003684 "-clamp restrict pixel range from 0 to the quantum depth",
cristy3ed852e2009-09-05 21:47:34 +00003685 "-clip clip along the first path from the 8BIM profile",
3686 "-clip-mask filename associate a clip mask with the image",
3687 "-clip-path id clip along a named path from the 8BIM profile",
3688 "-colorize value colorize the image with the fill color",
3689 "-contrast enhance or reduce the image contrast",
3690 "-contrast-stretch geometry",
3691 " improve contrast by `stretching' the intensity range",
3692 "-convolve coefficients",
3693 " apply a convolution kernel to the image",
3694 "-cycle amount cycle the image colormap",
3695 "-decipher filename convert cipher pixels to plain pixels",
3696 "-deskew threshold straighten an image",
3697 "-despeckle reduce the speckles within an image",
3698 "-distort method args",
3699 " distort images according to given method ad args",
3700 "-draw string annotate the image with a graphic primitive",
3701 "-edge radius apply a filter to detect edges in the image",
3702 "-encipher filename convert plain pixels to cipher pixels",
3703 "-emboss radius emboss an image",
3704 "-enhance apply a digital filter to enhance a noisy image",
3705 "-equalize perform histogram equalization to an image",
3706 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003707 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003708 "-extent geometry set the image size",
3709 "-extract geometry extract area from image",
3710 "-fft implements the discrete Fourier transform (DFT)",
3711 "-flip flip image vertically",
3712 "-floodfill geometry color",
3713 " floodfill the image with color",
3714 "-flop flop image horizontally",
3715 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003716 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003717 " apply function over image values",
3718 "-gamma value level of gamma correction",
3719 "-gaussian-blur geometry",
3720 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003721 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003722 "-identify identify the format and characteristics of the image",
3723 "-ift implements the inverse discrete Fourier transform (DFT)",
3724 "-implode amount implode image pixels about the center",
3725 "-lat geometry local adaptive thresholding",
3726 "-layers method optimize, merge, or compare image layers",
3727 "-level value adjust the level of image contrast",
3728 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003729 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003730 "-linear-stretch geometry",
3731 " improve contrast by `stretching with saturation'",
3732 "-liquid-rescale geometry",
3733 " rescale image with seam-carving",
3734 "-median radius apply a median filter to the image",
3735 "-modulate value vary the brightness, saturation, and hue",
3736 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003737 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003738 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003739 "-motion-blur geometry",
3740 " simulate motion blur",
3741 "-negate replace every pixel with its complementary color ",
3742 "-noise radius add or reduce noise in an image",
3743 "-normalize transform image to span the full range of colors",
3744 "-opaque color change this color to the fill color",
3745 "-ordered-dither NxN",
3746 " add a noise pattern to the image with specific",
3747 " amplitudes",
3748 "-paint radius simulate an oil painting",
3749 "-polaroid angle simulate a Polaroid picture",
3750 "-posterize levels reduce the image to a limited number of color levels",
3751 "-print string interpret string and print to console",
3752 "-profile filename add, delete, or apply an image profile",
3753 "-quantize colorspace reduce colors in this colorspace",
3754 "-radial-blur angle radial blur the image",
3755 "-raise value lighten/darken image edges to create a 3-D effect",
3756 "-random-threshold low,high",
3757 " random threshold the image",
3758 "-recolor matrix translate, scale, shear, or rotate image colors",
3759 "-region geometry apply options to a portion of the image",
3760 "-render render vector graphics",
3761 "-repage geometry size and location of an image canvas",
3762 "-resample geometry change the resolution of an image",
3763 "-resize geometry resize the image",
3764 "-roll geometry roll an image vertically or horizontally",
3765 "-rotate degrees apply Paeth rotation to the image",
3766 "-sample geometry scale image with pixel sampling",
3767 "-scale geometry scale the image",
3768 "-segment values segment an image",
3769 "-selective-blur geometry",
3770 " selectively blur pixels within a contrast threshold",
3771 "-sepia-tone threshold",
3772 " simulate a sepia-toned photo",
3773 "-set property value set an image property",
3774 "-shade degrees shade the image using a distant light source",
3775 "-shadow geometry simulate an image shadow",
3776 "-sharpen geometry sharpen the image",
3777 "-shave geometry shave pixels from the image edges",
3778 "-shear geometry slide one edge of the image along the X or Y axis",
3779 "-sigmoidal-contrast geometry",
3780 " increase the contrast without saturating highlights or shadows",
3781 "-sketch geometry simulate a pencil sketch",
3782 "-solarize threshold negate all pixels above the threshold level",
3783 "-sparse-color method args",
3784 " fill in a image based on a few color points",
3785 "-splice geometry splice the background color into the image",
3786 "-spread radius displace image pixels by a random amount",
3787 "-strip strip image of all profiles and comments",
3788 "-swirl degrees swirl image pixels about the center",
3789 "-threshold value threshold the image",
3790 "-thumbnail geometry create a thumbnail of the image",
3791 "-tile filename tile image when filling a graphic primitive",
3792 "-tint value tint the image with the fill color",
3793 "-transform affine transform image",
3794 "-transparent color make this color transparent within the image",
3795 "-transpose flip image vertically and rotate 90 degrees",
3796 "-transverse flop image horizontally and rotate 270 degrees",
3797 "-trim trim image edges",
3798 "-type type image type",
3799 "-unique-colors discard all but one of any pixel color",
3800 "-unsharp geometry sharpen the image",
3801 "-vignette geometry soften the edges of the image in vignette style",
3802 "-wave geometry alter an image along a sine wave",
3803 "-white-threshold value",
3804 " force all pixels above the threshold into white",
3805 (char *) NULL
3806 },
3807 *sequence_operators[]=
3808 {
3809 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003810 "-clut apply a color lookup table to the image",
3811 "-coalesce merge a sequence of images",
3812 "-combine combine a sequence of images",
3813 "-composite composite image",
3814 "-crop geometry cut out a rectangular region of the image",
3815 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003816 "-evaluate-sequence operator",
3817 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003818 "-flatten flatten a sequence of images",
3819 "-fx expression apply mathematical expression to an image channel(s)",
3820 "-hald-clut apply a Hald color lookup table to the image",
3821 "-morph value morph an image sequence",
3822 "-mosaic create a mosaic from an image sequence",
3823 "-process arguments process the image with a custom image filter",
3824 "-reverse reverse image sequence",
3825 "-separate separate an image channel into a grayscale image",
3826 "-write filename write images to this file",
3827 (char *) NULL
3828 },
3829 *settings[]=
3830 {
3831 "-adjoin join images into a single multi-image file",
3832 "-affine matrix affine transform matrix",
3833 "-alpha option activate, deactivate, reset, or set the alpha channel",
3834 "-antialias remove pixel-aliasing",
3835 "-authenticate password",
3836 " decipher image with this password",
3837 "-attenuate value lessen (or intensify) when adding noise to an image",
3838 "-background color background color",
3839 "-bias value add bias when convolving an image",
3840 "-black-point-compensation",
3841 " use black point compensation",
3842 "-blue-primary point chromaticity blue primary point",
3843 "-bordercolor color border color",
3844 "-caption string assign a caption to an image",
3845 "-channel type apply option to select image channels",
3846 "-colors value preferred number of colors in the image",
3847 "-colorspace type alternate image colorspace",
3848 "-comment string annotate image with comment",
3849 "-compose operator set image composite operator",
3850 "-compress type type of pixel compression when writing the image",
3851 "-define format:option",
3852 " define one or more image format options",
3853 "-delay value display the next image after pausing",
3854 "-density geometry horizontal and vertical density of the image",
3855 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003856 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003857 "-display server get image or font from this X server",
3858 "-dispose method layer disposal method",
3859 "-dither method apply error diffusion to image",
3860 "-encoding type text encoding type",
3861 "-endian type endianness (MSB or LSB) of the image",
3862 "-family name render text with this font family",
3863 "-fill color color to use when filling a graphic primitive",
3864 "-filter type use this filter when resizing an image",
3865 "-font name render text with this font",
3866 "-format \"string\" output formatted image characteristics",
3867 "-fuzz distance colors within this distance are considered equal",
3868 "-gravity type horizontal and vertical text placement",
3869 "-green-primary point chromaticity green primary point",
3870 "-intent type type of rendering intent when managing the image color",
3871 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003872 "-interline-spacing value",
3873 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003874 "-interpolate method pixel color interpolation method",
3875 "-interword-spacing value",
3876 " set the space between two words",
3877 "-kerning value set the space between two letters",
3878 "-label string assign a label to an image",
3879 "-limit type value pixel cache resource limit",
3880 "-loop iterations add Netscape loop extension to your GIF animation",
3881 "-mask filename associate a mask with the image",
3882 "-mattecolor color frame color",
3883 "-monitor monitor progress",
3884 "-orient type image orientation",
3885 "-page geometry size and location of an image canvas (setting)",
3886 "-ping efficiently determine image attributes",
3887 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003888 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003889 "-preview type image preview type",
3890 "-quality value JPEG/MIFF/PNG compression level",
3891 "-quiet suppress all warning messages",
3892 "-red-primary point chromaticity red primary point",
3893 "-regard-warnings pay attention to warning messages",
3894 "-remap filename transform image colors to match this set of colors",
3895 "-respect-parentheses settings remain in effect until parenthesis boundary",
3896 "-sampling-factor geometry",
3897 " horizontal and vertical sampling factor",
3898 "-scene value image scene number",
3899 "-seed value seed a new sequence of pseudo-random numbers",
3900 "-size geometry width and height of image",
3901 "-stretch type render text with this font stretch",
3902 "-stroke color graphic primitive stroke color",
3903 "-strokewidth value graphic primitive stroke width",
3904 "-style type render text with this font style",
3905 "-taint image as ineligible for bi-modal delegate",
3906 "-texture filename name of texture to tile onto the image background",
3907 "-tile-offset geometry",
3908 " tile offset",
3909 "-treedepth value color tree depth",
3910 "-transparent-color color",
3911 " transparent color",
3912 "-undercolor color annotation bounding box color",
3913 "-units type the units of image resolution",
3914 "-verbose print detailed information about the image",
3915 "-view FlashPix viewing transforms",
3916 "-virtual-pixel method",
3917 " virtual pixel access method",
3918 "-weight type render text with this font weight",
3919 "-white-point point chromaticity white point",
3920 (char *) NULL
3921 },
3922 *stack_operators[]=
3923 {
3924 "-clone index clone an image",
3925 "-delete index delete the image from the image sequence",
3926 "-insert index insert last image into the image sequence",
3927 "-swap indexes swap two images in the image sequence",
3928 (char *) NULL
3929 };
3930
3931 const char
3932 **p;
3933
3934 (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003935 (void) printf("Copyright: %s\n",GetMagickCopyright());
3936 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003937 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3938 GetClientName());
3939 (void) printf("\nImage Settings:\n");
3940 for (p=settings; *p != (char *) NULL; p++)
3941 (void) printf(" %s\n",*p);
3942 (void) printf("\nImage Operators:\n");
3943 for (p=operators; *p != (char *) NULL; p++)
3944 (void) printf(" %s\n",*p);
3945 (void) printf("\nImage Sequence Operators:\n");
3946 for (p=sequence_operators; *p != (char *) NULL; p++)
3947 (void) printf(" %s\n",*p);
3948 (void) printf("\nImage Stack Operators:\n");
3949 for (p=stack_operators; *p != (char *) NULL; p++)
3950 (void) printf(" %s\n",*p);
3951 (void) printf("\nMiscellaneous Options:\n");
3952 for (p=miscellaneous; *p != (char *) NULL; p++)
3953 (void) printf(" %s\n",*p);
3954 (void) printf(
3955 "\nBy default, the image format of `file' is determined by its magic\n");
3956 (void) printf(
3957 "number. To specify a particular image format, precede the filename\n");
3958 (void) printf(
3959 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3960 (void) printf(
3961 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3962 (void) printf("'-' for standard input or output.\n");
3963 return(MagickFalse);
3964}
3965
3966WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3967 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3968{
3969#define DestroyMogrify() \
3970{ \
3971 if (format != (char *) NULL) \
3972 format=DestroyString(format); \
3973 if (path != (char *) NULL) \
3974 path=DestroyString(path); \
3975 DestroyImageStack(); \
3976 for (i=0; i < (long) argc; i++) \
3977 argv[i]=DestroyString(argv[i]); \
3978 argv=(char **) RelinquishMagickMemory(argv); \
3979}
3980#define ThrowMogrifyException(asperity,tag,option) \
3981{ \
3982 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3983 option); \
3984 DestroyMogrify(); \
3985 return(MagickFalse); \
3986}
3987#define ThrowMogrifyInvalidArgumentException(option,argument) \
3988{ \
3989 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3990 "InvalidArgument","`%s': %s",argument,option); \
3991 DestroyMogrify(); \
3992 return(MagickFalse); \
3993}
3994
3995 char
3996 *format,
3997 *option,
3998 *path;
3999
4000 Image
4001 *image;
4002
4003 ImageStack
4004 image_stack[MaxImageStackDepth+1];
4005
4006 long
4007 j,
4008 k;
4009
4010 register long
4011 i;
4012
4013 MagickBooleanType
4014 global_colormap;
4015
4016 MagickBooleanType
4017 fire,
4018 pend;
4019
4020 MagickStatusType
4021 status;
4022
4023 /*
4024 Set defaults.
4025 */
4026 assert(image_info != (ImageInfo *) NULL);
4027 assert(image_info->signature == MagickSignature);
4028 if (image_info->debug != MagickFalse)
4029 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4030 assert(exception != (ExceptionInfo *) NULL);
4031 if (argc == 2)
4032 {
4033 option=argv[1];
4034 if ((LocaleCompare("version",option+1) == 0) ||
4035 (LocaleCompare("-version",option+1) == 0))
4036 {
4037 (void) fprintf(stdout,"Version: %s\n",
4038 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004039 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4040 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004041 return(MagickFalse);
4042 }
4043 }
4044 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004045 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004046 format=(char *) NULL;
4047 path=(char *) NULL;
4048 global_colormap=MagickFalse;
4049 k=0;
4050 j=1;
4051 NewImageStack();
4052 option=(char *) NULL;
4053 pend=MagickFalse;
4054 status=MagickTrue;
4055 /*
4056 Parse command line.
4057 */
4058 ReadCommandlLine(argc,&argv);
4059 status=ExpandFilenames(&argc,&argv);
4060 if (status == MagickFalse)
4061 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4062 GetExceptionMessage(errno));
4063 for (i=1; i < (long) argc; i++)
4064 {
4065 option=argv[i];
4066 if (LocaleCompare(option,"(") == 0)
4067 {
4068 FireImageStack(MagickFalse,MagickTrue,pend);
4069 if (k == MaxImageStackDepth)
4070 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4071 option);
4072 PushImageStack();
4073 continue;
4074 }
4075 if (LocaleCompare(option,")") == 0)
4076 {
4077 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4078 if (k == 0)
4079 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4080 PopImageStack();
4081 continue;
4082 }
4083 if (IsMagickOption(option) == MagickFalse)
4084 {
4085 char
4086 backup_filename[MaxTextExtent],
4087 *filename;
4088
4089 Image
4090 *images;
4091
4092 /*
4093 Option is a file name: begin by reading image from specified file.
4094 */
4095 FireImageStack(MagickFalse,MagickFalse,pend);
4096 filename=argv[i];
4097 if ((LocaleCompare(filename,"--") == 0) && (i < (argc-1)))
4098 filename=argv[++i];
4099 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4100 images=ReadImages(image_info,exception);
4101 status&=(images != (Image *) NULL) &&
4102 (exception->severity < ErrorException);
4103 if (images == (Image *) NULL)
4104 continue;
4105 if (path != (char *) NULL)
4106 {
4107 GetPathComponent(option,TailPath,filename);
4108 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4109 path,*DirectorySeparator,filename);
4110 }
4111 if (format != (char *) NULL)
4112 AppendImageFormat(format,images->filename);
4113 AppendImageStack(images);
4114 FinalizeImageSettings(image_info,image,MagickFalse);
4115 if (global_colormap != MagickFalse)
4116 {
4117 QuantizeInfo
4118 *quantize_info;
4119
4120 quantize_info=AcquireQuantizeInfo(image_info);
4121 (void) RemapImages(quantize_info,images,(Image *) NULL);
4122 quantize_info=DestroyQuantizeInfo(quantize_info);
4123 }
4124 *backup_filename='\0';
4125 if ((LocaleCompare(image->filename,"-") != 0) &&
4126 (IsPathWritable(image->filename) != MagickFalse))
4127 {
4128 register long
4129 i;
4130
4131 /*
4132 Rename image file as backup.
4133 */
4134 (void) CopyMagickString(backup_filename,image->filename,
4135 MaxTextExtent);
4136 for (i=0; i < 6; i++)
4137 {
4138 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4139 if (IsPathAccessible(backup_filename) == MagickFalse)
4140 break;
4141 }
4142 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4143 (rename(image->filename,backup_filename) != 0))
4144 *backup_filename='\0';
4145 }
4146 /*
4147 Write transmogrified image to disk.
4148 */
4149 image_info->synchronize=MagickTrue;
4150 status&=WriteImages(image_info,image,image->filename,exception);
4151 if ((status == MagickFalse) && (*backup_filename != '\0'))
4152 (void) remove(backup_filename);
4153 RemoveAllImageStack();
4154 continue;
4155 }
4156 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4157 switch (*(option+1))
4158 {
4159 case 'a':
4160 {
4161 if (LocaleCompare("adaptive-blur",option+1) == 0)
4162 {
4163 i++;
4164 if (i == (long) argc)
4165 ThrowMogrifyException(OptionError,"MissingArgument",option);
4166 if (IsGeometry(argv[i]) == MagickFalse)
4167 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4168 break;
4169 }
4170 if (LocaleCompare("adaptive-resize",option+1) == 0)
4171 {
4172 i++;
4173 if (i == (long) argc)
4174 ThrowMogrifyException(OptionError,"MissingArgument",option);
4175 if (IsGeometry(argv[i]) == MagickFalse)
4176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4177 break;
4178 }
4179 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4180 {
4181 i++;
4182 if (i == (long) argc)
4183 ThrowMogrifyException(OptionError,"MissingArgument",option);
4184 if (IsGeometry(argv[i]) == MagickFalse)
4185 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4186 break;
4187 }
4188 if (LocaleCompare("affine",option+1) == 0)
4189 {
4190 if (*option == '+')
4191 break;
4192 i++;
4193 if (i == (long) argc)
4194 ThrowMogrifyException(OptionError,"MissingArgument",option);
4195 if (IsGeometry(argv[i]) == MagickFalse)
4196 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4197 break;
4198 }
4199 if (LocaleCompare("alpha",option+1) == 0)
4200 {
4201 long
4202 type;
4203
4204 if (*option == '+')
4205 break;
4206 i++;
4207 if (i == (long) argc)
4208 ThrowMogrifyException(OptionError,"MissingArgument",option);
4209 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4210 if (type < 0)
4211 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4212 argv[i]);
4213 break;
4214 }
4215 if (LocaleCompare("annotate",option+1) == 0)
4216 {
4217 if (*option == '+')
4218 break;
4219 i++;
4220 if (i == (long) argc)
4221 ThrowMogrifyException(OptionError,"MissingArgument",option);
4222 if (IsGeometry(argv[i]) == MagickFalse)
4223 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4224 if (i == (long) argc)
4225 ThrowMogrifyException(OptionError,"MissingArgument",option);
4226 i++;
4227 break;
4228 }
4229 if (LocaleCompare("antialias",option+1) == 0)
4230 break;
4231 if (LocaleCompare("append",option+1) == 0)
4232 break;
4233 if (LocaleCompare("attenuate",option+1) == 0)
4234 {
4235 if (*option == '+')
4236 break;
4237 i++;
4238 if (i == (long) (argc-1))
4239 ThrowMogrifyException(OptionError,"MissingArgument",option);
4240 if (IsGeometry(argv[i]) == MagickFalse)
4241 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4242 break;
4243 }
4244 if (LocaleCompare("authenticate",option+1) == 0)
4245 {
4246 if (*option == '+')
4247 break;
4248 i++;
4249 if (i == (long) argc)
4250 ThrowMogrifyException(OptionError,"MissingArgument",option);
4251 break;
4252 }
4253 if (LocaleCompare("auto-gamma",option+1) == 0)
4254 break;
4255 if (LocaleCompare("auto-level",option+1) == 0)
4256 break;
4257 if (LocaleCompare("auto-orient",option+1) == 0)
4258 break;
4259 if (LocaleCompare("average",option+1) == 0)
4260 break;
4261 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4262 }
4263 case 'b':
4264 {
4265 if (LocaleCompare("background",option+1) == 0)
4266 {
4267 if (*option == '+')
4268 break;
4269 i++;
4270 if (i == (long) argc)
4271 ThrowMogrifyException(OptionError,"MissingArgument",option);
4272 break;
4273 }
4274 if (LocaleCompare("bias",option+1) == 0)
4275 {
4276 if (*option == '+')
4277 break;
4278 i++;
4279 if (i == (long) (argc-1))
4280 ThrowMogrifyException(OptionError,"MissingArgument",option);
4281 if (IsGeometry(argv[i]) == MagickFalse)
4282 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4283 break;
4284 }
4285 if (LocaleCompare("black-point-compensation",option+1) == 0)
4286 break;
4287 if (LocaleCompare("black-threshold",option+1) == 0)
4288 {
4289 if (*option == '+')
4290 break;
4291 i++;
4292 if (i == (long) argc)
4293 ThrowMogrifyException(OptionError,"MissingArgument",option);
4294 if (IsGeometry(argv[i]) == MagickFalse)
4295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4296 break;
4297 }
4298 if (LocaleCompare("blue-primary",option+1) == 0)
4299 {
4300 if (*option == '+')
4301 break;
4302 i++;
4303 if (i == (long) argc)
4304 ThrowMogrifyException(OptionError,"MissingArgument",option);
4305 if (IsGeometry(argv[i]) == MagickFalse)
4306 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4307 break;
4308 }
4309 if (LocaleCompare("blue-shift",option+1) == 0)
4310 {
4311 i++;
4312 if (i == (long) argc)
4313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 if (IsGeometry(argv[i]) == MagickFalse)
4315 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4316 break;
4317 }
4318 if (LocaleCompare("blur",option+1) == 0)
4319 {
4320 i++;
4321 if (i == (long) argc)
4322 ThrowMogrifyException(OptionError,"MissingArgument",option);
4323 if (IsGeometry(argv[i]) == MagickFalse)
4324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4325 break;
4326 }
4327 if (LocaleCompare("border",option+1) == 0)
4328 {
4329 if (*option == '+')
4330 break;
4331 i++;
4332 if (i == (long) argc)
4333 ThrowMogrifyException(OptionError,"MissingArgument",option);
4334 if (IsGeometry(argv[i]) == MagickFalse)
4335 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4336 break;
4337 }
4338 if (LocaleCompare("bordercolor",option+1) == 0)
4339 {
4340 if (*option == '+')
4341 break;
4342 i++;
4343 if (i == (long) argc)
4344 ThrowMogrifyException(OptionError,"MissingArgument",option);
4345 break;
4346 }
4347 if (LocaleCompare("box",option+1) == 0)
4348 {
4349 if (*option == '+')
4350 break;
4351 i++;
4352 if (i == (long) argc)
4353 ThrowMogrifyException(OptionError,"MissingArgument",option);
4354 break;
4355 }
cristya28d6b82010-01-11 20:03:47 +00004356 if (LocaleCompare("brightness-contrast",option+1) == 0)
4357 {
4358 i++;
4359 if (i == (long) argc)
4360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 if (IsGeometry(argv[i]) == MagickFalse)
4362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4363 break;
4364 }
cristy3ed852e2009-09-05 21:47:34 +00004365 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4366 }
4367 case 'c':
4368 {
4369 if (LocaleCompare("cache",option+1) == 0)
4370 {
4371 if (*option == '+')
4372 break;
4373 i++;
4374 if (i == (long) argc)
4375 ThrowMogrifyException(OptionError,"MissingArgument",option);
4376 if (IsGeometry(argv[i]) == MagickFalse)
4377 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4378 break;
4379 }
4380 if (LocaleCompare("caption",option+1) == 0)
4381 {
4382 if (*option == '+')
4383 break;
4384 i++;
4385 if (i == (long) argc)
4386 ThrowMogrifyException(OptionError,"MissingArgument",option);
4387 break;
4388 }
4389 if (LocaleCompare("channel",option+1) == 0)
4390 {
4391 long
4392 channel;
4393
4394 if (*option == '+')
4395 break;
4396 i++;
4397 if (i == (long) (argc-1))
4398 ThrowMogrifyException(OptionError,"MissingArgument",option);
4399 channel=ParseChannelOption(argv[i]);
4400 if (channel < 0)
4401 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4402 argv[i]);
4403 break;
4404 }
4405 if (LocaleCompare("cdl",option+1) == 0)
4406 {
4407 if (*option == '+')
4408 break;
4409 i++;
4410 if (i == (long) (argc-1))
4411 ThrowMogrifyException(OptionError,"MissingArgument",option);
4412 break;
4413 }
4414 if (LocaleCompare("charcoal",option+1) == 0)
4415 {
4416 if (*option == '+')
4417 break;
4418 i++;
4419 if (i == (long) argc)
4420 ThrowMogrifyException(OptionError,"MissingArgument",option);
4421 if (IsGeometry(argv[i]) == MagickFalse)
4422 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4423 break;
4424 }
4425 if (LocaleCompare("chop",option+1) == 0)
4426 {
4427 if (*option == '+')
4428 break;
4429 i++;
4430 if (i == (long) argc)
4431 ThrowMogrifyException(OptionError,"MissingArgument",option);
4432 if (IsGeometry(argv[i]) == MagickFalse)
4433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4434 break;
4435 }
cristy1eb45dd2009-09-25 16:38:06 +00004436 if (LocaleCompare("clamp",option+1) == 0)
4437 break;
4438 if (LocaleCompare("clip",option+1) == 0)
4439 break;
cristy3ed852e2009-09-05 21:47:34 +00004440 if (LocaleCompare("clip-mask",option+1) == 0)
4441 {
4442 if (*option == '+')
4443 break;
4444 i++;
4445 if (i == (long) argc)
4446 ThrowMogrifyException(OptionError,"MissingArgument",option);
4447 break;
4448 }
4449 if (LocaleCompare("clut",option+1) == 0)
4450 break;
4451 if (LocaleCompare("coalesce",option+1) == 0)
4452 break;
4453 if (LocaleCompare("colorize",option+1) == 0)
4454 {
4455 if (*option == '+')
4456 break;
4457 i++;
4458 if (i == (long) argc)
4459 ThrowMogrifyException(OptionError,"MissingArgument",option);
4460 if (IsGeometry(argv[i]) == MagickFalse)
4461 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4462 break;
4463 }
4464 if (LocaleCompare("colors",option+1) == 0)
4465 {
4466 if (*option == '+')
4467 break;
4468 i++;
4469 if (i == (long) argc)
4470 ThrowMogrifyException(OptionError,"MissingArgument",option);
4471 if (IsGeometry(argv[i]) == MagickFalse)
4472 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4473 break;
4474 }
4475 if (LocaleCompare("colorspace",option+1) == 0)
4476 {
4477 long
4478 colorspace;
4479
4480 if (*option == '+')
4481 break;
4482 i++;
4483 if (i == (long) argc)
4484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4486 argv[i]);
4487 if (colorspace < 0)
4488 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4489 argv[i]);
4490 break;
4491 }
4492 if (LocaleCompare("combine",option+1) == 0)
4493 break;
4494 if (LocaleCompare("comment",option+1) == 0)
4495 {
4496 if (*option == '+')
4497 break;
4498 i++;
4499 if (i == (long) argc)
4500 ThrowMogrifyException(OptionError,"MissingArgument",option);
4501 break;
4502 }
4503 if (LocaleCompare("composite",option+1) == 0)
4504 break;
4505 if (LocaleCompare("compress",option+1) == 0)
4506 {
4507 long
4508 compress;
4509
4510 if (*option == '+')
4511 break;
4512 i++;
4513 if (i == (long) argc)
4514 ThrowMogrifyException(OptionError,"MissingArgument",option);
4515 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4516 argv[i]);
4517 if (compress < 0)
4518 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4519 argv[i]);
4520 break;
4521 }
cristy22879752009-10-25 23:55:40 +00004522 if (LocaleCompare("concurrent",option+1) == 0)
4523 break;
cristy3ed852e2009-09-05 21:47:34 +00004524 if (LocaleCompare("contrast",option+1) == 0)
4525 break;
4526 if (LocaleCompare("contrast-stretch",option+1) == 0)
4527 {
4528 i++;
4529 if (i == (long) argc)
4530 ThrowMogrifyException(OptionError,"MissingArgument",option);
4531 if (IsGeometry(argv[i]) == MagickFalse)
4532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4533 break;
4534 }
4535 if (LocaleCompare("convolve",option+1) == 0)
4536 {
anthony29188a82010-01-22 10:12:34 +00004537 char
4538 token[MaxTextExtent];
4539
cristy3ed852e2009-09-05 21:47:34 +00004540 if (*option == '+')
4541 break;
4542 i++;
4543 if (i == (long) argc)
4544 ThrowMogrifyException(OptionError,"MissingArgument",option);
anthony29188a82010-01-22 10:12:34 +00004545#if 1
cristydfbe6ca2010-03-12 14:08:17 +00004546 (void) token;
cristy3ed852e2009-09-05 21:47:34 +00004547 if (IsGeometry(argv[i]) == MagickFalse)
4548 ThrowMogrifyInvalidArgumentException(option,argv[i]);
anthony29188a82010-01-22 10:12:34 +00004549#else
4550 /* Allow the use of built-in kernels like 'gaussian'
4551 * These may not work for kernels with 'nan' values, like 'diamond'
4552 */
4553 GetMagickToken(argv[i],NULL,token);
4554 if ( isalpha((int)token[0]) )
4555 {
4556 long
4557 op;
4558
4559 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
4560 if (op < 0)
4561 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
4562 token);
4563 }
4564 /* geometry current returns invalid if 'nan' values are used */
4565 else if (IsGeometry(argv[i]) == MagickFalse)
4566 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4567#endif
cristy3ed852e2009-09-05 21:47:34 +00004568 break;
4569 }
4570 if (LocaleCompare("crop",option+1) == 0)
4571 {
4572 if (*option == '+')
4573 break;
4574 i++;
4575 if (i == (long) argc)
4576 ThrowMogrifyException(OptionError,"MissingArgument",option);
4577 if (IsGeometry(argv[i]) == MagickFalse)
4578 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4579 break;
4580 }
4581 if (LocaleCompare("cycle",option+1) == 0)
4582 {
4583 if (*option == '+')
4584 break;
4585 i++;
4586 if (i == (long) argc)
4587 ThrowMogrifyException(OptionError,"MissingArgument",option);
4588 if (IsGeometry(argv[i]) == MagickFalse)
4589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4590 break;
4591 }
4592 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4593 }
4594 case 'd':
4595 {
4596 if (LocaleCompare("decipher",option+1) == 0)
4597 {
4598 if (*option == '+')
4599 break;
4600 i++;
4601 if (i == (long) (argc-1))
4602 ThrowMogrifyException(OptionError,"MissingArgument",option);
4603 break;
4604 }
4605 if (LocaleCompare("deconstruct",option+1) == 0)
4606 break;
4607 if (LocaleCompare("debug",option+1) == 0)
4608 {
4609 long
4610 event;
4611
4612 if (*option == '+')
4613 break;
4614 i++;
4615 if (i == (long) argc)
4616 ThrowMogrifyException(OptionError,"MissingArgument",option);
4617 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4618 if (event < 0)
4619 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4620 argv[i]);
4621 (void) SetLogEventMask(argv[i]);
4622 break;
4623 }
4624 if (LocaleCompare("define",option+1) == 0)
4625 {
4626 i++;
4627 if (i == (long) argc)
4628 ThrowMogrifyException(OptionError,"MissingArgument",option);
4629 if (*option == '+')
4630 {
4631 const char
4632 *define;
4633
4634 define=GetImageOption(image_info,argv[i]);
4635 if (define == (const char *) NULL)
4636 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4637 break;
4638 }
4639 break;
4640 }
4641 if (LocaleCompare("delay",option+1) == 0)
4642 {
4643 if (*option == '+')
4644 break;
4645 i++;
4646 if (i == (long) argc)
4647 ThrowMogrifyException(OptionError,"MissingArgument",option);
4648 if (IsGeometry(argv[i]) == MagickFalse)
4649 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4650 break;
4651 }
4652 if (LocaleCompare("density",option+1) == 0)
4653 {
4654 if (*option == '+')
4655 break;
4656 i++;
4657 if (i == (long) argc)
4658 ThrowMogrifyException(OptionError,"MissingArgument",option);
4659 if (IsGeometry(argv[i]) == MagickFalse)
4660 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4661 break;
4662 }
4663 if (LocaleCompare("depth",option+1) == 0)
4664 {
4665 if (*option == '+')
4666 break;
4667 i++;
4668 if (i == (long) argc)
4669 ThrowMogrifyException(OptionError,"MissingArgument",option);
4670 if (IsGeometry(argv[i]) == MagickFalse)
4671 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4672 break;
4673 }
4674 if (LocaleCompare("deskew",option+1) == 0)
4675 {
4676 if (*option == '+')
4677 break;
4678 i++;
4679 if (i == (long) argc)
4680 ThrowMogrifyException(OptionError,"MissingArgument",option);
4681 if (IsGeometry(argv[i]) == MagickFalse)
4682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4683 break;
4684 }
4685 if (LocaleCompare("despeckle",option+1) == 0)
4686 break;
4687 if (LocaleCompare("dft",option+1) == 0)
4688 break;
cristyc9b12952010-03-28 01:12:28 +00004689 if (LocaleCompare("direction",option+1) == 0)
4690 {
4691 long
4692 direction;
4693
4694 if (*option == '+')
4695 break;
4696 i++;
4697 if (i == (long) argc)
4698 ThrowMogrifyException(OptionError,"MissingArgument",option);
4699 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4700 argv[i]);
4701 if (direction < 0)
4702 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4703 argv[i]);
4704 break;
4705 }
cristy3ed852e2009-09-05 21:47:34 +00004706 if (LocaleCompare("display",option+1) == 0)
4707 {
4708 if (*option == '+')
4709 break;
4710 i++;
4711 if (i == (long) argc)
4712 ThrowMogrifyException(OptionError,"MissingArgument",option);
4713 break;
4714 }
4715 if (LocaleCompare("dispose",option+1) == 0)
4716 {
4717 long
4718 dispose;
4719
4720 if (*option == '+')
4721 break;
4722 i++;
4723 if (i == (long) argc)
4724 ThrowMogrifyException(OptionError,"MissingArgument",option);
4725 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4726 if (dispose < 0)
4727 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4728 argv[i]);
4729 break;
4730 }
4731 if (LocaleCompare("distort",option+1) == 0)
4732 {
4733 long
4734 op;
4735
4736 i++;
4737 if (i == (long) argc)
4738 ThrowMogrifyException(OptionError,"MissingArgument",option);
4739 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4740 if (op < 0)
4741 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4742 argv[i]);
4743 i++;
4744 if (i == (long) (argc-1))
4745 ThrowMogrifyException(OptionError,"MissingArgument",option);
4746 break;
4747 }
4748 if (LocaleCompare("dither",option+1) == 0)
4749 {
4750 long
4751 method;
4752
4753 if (*option == '+')
4754 break;
4755 i++;
4756 if (i == (long) argc)
4757 ThrowMogrifyException(OptionError,"MissingArgument",option);
4758 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4759 if (method < 0)
4760 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4761 argv[i]);
4762 break;
4763 }
4764 if (LocaleCompare("draw",option+1) == 0)
4765 {
4766 if (*option == '+')
4767 break;
4768 i++;
4769 if (i == (long) argc)
4770 ThrowMogrifyException(OptionError,"MissingArgument",option);
4771 break;
4772 }
cristy22879752009-10-25 23:55:40 +00004773 if (LocaleCompare("duration",option+1) == 0)
4774 {
4775 if (*option == '+')
4776 break;
4777 i++;
4778 if (i == (long) (argc-1))
4779 ThrowMogrifyException(OptionError,"MissingArgument",option);
4780 if (IsGeometry(argv[i]) == MagickFalse)
4781 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4782 break;
4783 }
cristy3ed852e2009-09-05 21:47:34 +00004784 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4785 }
4786 case 'e':
4787 {
4788 if (LocaleCompare("edge",option+1) == 0)
4789 {
4790 if (*option == '+')
4791 break;
4792 i++;
4793 if (i == (long) argc)
4794 ThrowMogrifyException(OptionError,"MissingArgument",option);
4795 if (IsGeometry(argv[i]) == MagickFalse)
4796 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4797 break;
4798 }
4799 if (LocaleCompare("emboss",option+1) == 0)
4800 {
4801 if (*option == '+')
4802 break;
4803 i++;
4804 if (i == (long) argc)
4805 ThrowMogrifyException(OptionError,"MissingArgument",option);
4806 if (IsGeometry(argv[i]) == MagickFalse)
4807 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4808 break;
4809 }
4810 if (LocaleCompare("encipher",option+1) == 0)
4811 {
4812 if (*option == '+')
4813 break;
4814 i++;
4815 if (i == (long) argc)
4816 ThrowMogrifyException(OptionError,"MissingArgument",option);
4817 break;
4818 }
4819 if (LocaleCompare("encoding",option+1) == 0)
4820 {
4821 if (*option == '+')
4822 break;
4823 i++;
4824 if (i == (long) argc)
4825 ThrowMogrifyException(OptionError,"MissingArgument",option);
4826 break;
4827 }
4828 if (LocaleCompare("endian",option+1) == 0)
4829 {
4830 long
4831 endian;
4832
4833 if (*option == '+')
4834 break;
4835 i++;
4836 if (i == (long) argc)
4837 ThrowMogrifyException(OptionError,"MissingArgument",option);
4838 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4839 if (endian < 0)
4840 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4841 argv[i]);
4842 break;
4843 }
4844 if (LocaleCompare("enhance",option+1) == 0)
4845 break;
4846 if (LocaleCompare("equalize",option+1) == 0)
4847 break;
4848 if (LocaleCompare("evaluate",option+1) == 0)
4849 {
4850 long
4851 op;
4852
4853 if (*option == '+')
4854 break;
4855 i++;
4856 if (i == (long) argc)
4857 ThrowMogrifyException(OptionError,"MissingArgument",option);
4858 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4859 if (op < 0)
4860 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4861 argv[i]);
4862 i++;
4863 if (i == (long) (argc-1))
4864 ThrowMogrifyException(OptionError,"MissingArgument",option);
4865 if (IsGeometry(argv[i]) == MagickFalse)
4866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4867 break;
4868 }
cristyd18ae7c2010-03-07 17:39:52 +00004869 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4870 {
4871 long
4872 op;
4873
4874 if (*option == '+')
4875 break;
4876 i++;
4877 if (i == (long) argc)
4878 ThrowMogrifyException(OptionError,"MissingArgument",option);
4879 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4880 if (op < 0)
4881 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4882 argv[i]);
4883 break;
4884 }
cristy3ed852e2009-09-05 21:47:34 +00004885 if (LocaleCompare("extent",option+1) == 0)
4886 {
4887 if (*option == '+')
4888 break;
4889 i++;
4890 if (i == (long) argc)
4891 ThrowMogrifyException(OptionError,"MissingArgument",option);
4892 if (IsGeometry(argv[i]) == MagickFalse)
4893 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4894 break;
4895 }
4896 if (LocaleCompare("extract",option+1) == 0)
4897 {
4898 if (*option == '+')
4899 break;
4900 i++;
4901 if (i == (long) argc)
4902 ThrowMogrifyException(OptionError,"MissingArgument",option);
4903 if (IsGeometry(argv[i]) == MagickFalse)
4904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4905 break;
4906 }
4907 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4908 }
4909 case 'f':
4910 {
4911 if (LocaleCompare("family",option+1) == 0)
4912 {
4913 if (*option == '+')
4914 break;
4915 i++;
4916 if (i == (long) (argc-1))
4917 ThrowMogrifyException(OptionError,"MissingArgument",option);
4918 break;
4919 }
4920 if (LocaleCompare("fill",option+1) == 0)
4921 {
4922 if (*option == '+')
4923 break;
4924 i++;
4925 if (i == (long) argc)
4926 ThrowMogrifyException(OptionError,"MissingArgument",option);
4927 break;
4928 }
4929 if (LocaleCompare("filter",option+1) == 0)
4930 {
4931 long
4932 filter;
4933
4934 if (*option == '+')
4935 break;
4936 i++;
4937 if (i == (long) argc)
4938 ThrowMogrifyException(OptionError,"MissingArgument",option);
4939 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4940 if (filter < 0)
4941 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4942 argv[i]);
4943 break;
4944 }
4945 if (LocaleCompare("flatten",option+1) == 0)
4946 break;
4947 if (LocaleCompare("flip",option+1) == 0)
4948 break;
4949 if (LocaleCompare("flop",option+1) == 0)
4950 break;
4951 if (LocaleCompare("floodfill",option+1) == 0)
4952 {
4953 if (*option == '+')
4954 break;
4955 i++;
4956 if (i == (long) argc)
4957 ThrowMogrifyException(OptionError,"MissingArgument",option);
4958 if (IsGeometry(argv[i]) == MagickFalse)
4959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4960 i++;
4961 if (i == (long) argc)
4962 ThrowMogrifyException(OptionError,"MissingArgument",option);
4963 break;
4964 }
4965 if (LocaleCompare("font",option+1) == 0)
4966 {
4967 if (*option == '+')
4968 break;
4969 i++;
4970 if (i == (long) argc)
4971 ThrowMogrifyException(OptionError,"MissingArgument",option);
4972 break;
4973 }
4974 if (LocaleCompare("format",option+1) == 0)
4975 {
4976 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4977 (void) CloneString(&format,(char *) NULL);
4978 if (*option == '+')
4979 break;
4980 i++;
4981 if (i == (long) argc)
4982 ThrowMogrifyException(OptionError,"MissingArgument",option);
4983 (void) CloneString(&format,argv[i]);
4984 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4985 (void) ConcatenateMagickString(image_info->filename,":",
4986 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004987 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004988 if (*image_info->magick == '\0')
4989 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4990 format);
4991 break;
4992 }
4993 if (LocaleCompare("frame",option+1) == 0)
4994 {
4995 if (*option == '+')
4996 break;
4997 i++;
4998 if (i == (long) argc)
4999 ThrowMogrifyException(OptionError,"MissingArgument",option);
5000 if (IsGeometry(argv[i]) == MagickFalse)
5001 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5002 break;
5003 }
5004 if (LocaleCompare("function",option+1) == 0)
5005 {
5006 long
5007 op;
5008
5009 if (*option == '+')
5010 break;
5011 i++;
5012 if (i == (long) argc)
5013 ThrowMogrifyException(OptionError,"MissingArgument",option);
5014 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
5015 if (op < 0)
5016 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
5017 i++;
5018 if (i == (long) (argc-1))
5019 ThrowMogrifyException(OptionError,"MissingArgument",option);
5020 break;
5021 }
5022 if (LocaleCompare("fuzz",option+1) == 0)
5023 {
5024 if (*option == '+')
5025 break;
5026 i++;
5027 if (i == (long) argc)
5028 ThrowMogrifyException(OptionError,"MissingArgument",option);
5029 if (IsGeometry(argv[i]) == MagickFalse)
5030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5031 break;
5032 }
5033 if (LocaleCompare("fx",option+1) == 0)
5034 {
5035 if (*option == '+')
5036 break;
5037 i++;
5038 if (i == (long) (argc-1))
5039 ThrowMogrifyException(OptionError,"MissingArgument",option);
5040 break;
5041 }
5042 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5043 }
5044 case 'g':
5045 {
5046 if (LocaleCompare("gamma",option+1) == 0)
5047 {
5048 i++;
5049 if (i == (long) argc)
5050 ThrowMogrifyException(OptionError,"MissingArgument",option);
5051 if (IsGeometry(argv[i]) == MagickFalse)
5052 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5053 break;
5054 }
5055 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5056 (LocaleCompare("gaussian",option+1) == 0))
5057 {
5058 i++;
5059 if (i == (long) argc)
5060 ThrowMogrifyException(OptionError,"MissingArgument",option);
5061 if (IsGeometry(argv[i]) == MagickFalse)
5062 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5063 break;
5064 }
5065 if (LocaleCompare("geometry",option+1) == 0)
5066 {
5067 if (*option == '+')
5068 break;
5069 i++;
5070 if (i == (long) argc)
5071 ThrowMogrifyException(OptionError,"MissingArgument",option);
5072 if (IsGeometry(argv[i]) == MagickFalse)
5073 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5074 break;
5075 }
5076 if (LocaleCompare("gravity",option+1) == 0)
5077 {
5078 long
5079 gravity;
5080
5081 if (*option == '+')
5082 break;
5083 i++;
5084 if (i == (long) argc)
5085 ThrowMogrifyException(OptionError,"MissingArgument",option);
5086 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5087 if (gravity < 0)
5088 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5089 argv[i]);
5090 break;
5091 }
5092 if (LocaleCompare("green-primary",option+1) == 0)
5093 {
5094 if (*option == '+')
5095 break;
5096 i++;
5097 if (i == (long) argc)
5098 ThrowMogrifyException(OptionError,"MissingArgument",option);
5099 if (IsGeometry(argv[i]) == MagickFalse)
5100 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5101 break;
5102 }
5103 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5104 }
5105 case 'h':
5106 {
5107 if (LocaleCompare("hald-clut",option+1) == 0)
5108 break;
5109 if ((LocaleCompare("help",option+1) == 0) ||
5110 (LocaleCompare("-help",option+1) == 0))
5111 return(MogrifyUsage());
5112 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5113 }
5114 case 'i':
5115 {
5116 if (LocaleCompare("identify",option+1) == 0)
5117 break;
5118 if (LocaleCompare("idft",option+1) == 0)
5119 break;
5120 if (LocaleCompare("implode",option+1) == 0)
5121 {
5122 if (*option == '+')
5123 break;
5124 i++;
5125 if (i == (long) argc)
5126 ThrowMogrifyException(OptionError,"MissingArgument",option);
5127 if (IsGeometry(argv[i]) == MagickFalse)
5128 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5129 break;
5130 }
5131 if (LocaleCompare("intent",option+1) == 0)
5132 {
5133 long
5134 intent;
5135
5136 if (*option == '+')
5137 break;
5138 i++;
5139 if (i == (long) (argc-1))
5140 ThrowMogrifyException(OptionError,"MissingArgument",option);
5141 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5142 if (intent < 0)
5143 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5144 argv[i]);
5145 break;
5146 }
5147 if (LocaleCompare("interlace",option+1) == 0)
5148 {
5149 long
5150 interlace;
5151
5152 if (*option == '+')
5153 break;
5154 i++;
5155 if (i == (long) argc)
5156 ThrowMogrifyException(OptionError,"MissingArgument",option);
5157 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5158 argv[i]);
5159 if (interlace < 0)
5160 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5161 argv[i]);
5162 break;
5163 }
cristyb32b90a2009-09-07 21:45:48 +00005164 if (LocaleCompare("interline-spacing",option+1) == 0)
5165 {
5166 if (*option == '+')
5167 break;
5168 i++;
5169 if (i == (long) (argc-1))
5170 ThrowMogrifyException(OptionError,"MissingArgument",option);
5171 if (IsGeometry(argv[i]) == MagickFalse)
5172 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5173 break;
5174 }
cristy3ed852e2009-09-05 21:47:34 +00005175 if (LocaleCompare("interpolate",option+1) == 0)
5176 {
5177 long
5178 interpolate;
5179
5180 if (*option == '+')
5181 break;
5182 i++;
5183 if (i == (long) argc)
5184 ThrowMogrifyException(OptionError,"MissingArgument",option);
5185 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5186 argv[i]);
5187 if (interpolate < 0)
5188 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5189 argv[i]);
5190 break;
5191 }
5192 if (LocaleCompare("interword-spacing",option+1) == 0)
5193 {
5194 if (*option == '+')
5195 break;
5196 i++;
5197 if (i == (long) (argc-1))
5198 ThrowMogrifyException(OptionError,"MissingArgument",option);
5199 if (IsGeometry(argv[i]) == MagickFalse)
5200 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5201 break;
5202 }
5203 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5204 }
5205 case 'k':
5206 {
5207 if (LocaleCompare("kerning",option+1) == 0)
5208 {
5209 if (*option == '+')
5210 break;
5211 i++;
5212 if (i == (long) (argc-1))
5213 ThrowMogrifyException(OptionError,"MissingArgument",option);
5214 if (IsGeometry(argv[i]) == MagickFalse)
5215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5216 break;
5217 }
5218 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5219 }
5220 case 'l':
5221 {
5222 if (LocaleCompare("label",option+1) == 0)
5223 {
5224 if (*option == '+')
5225 break;
5226 i++;
5227 if (i == (long) argc)
5228 ThrowMogrifyException(OptionError,"MissingArgument",option);
5229 break;
5230 }
5231 if (LocaleCompare("lat",option+1) == 0)
5232 {
5233 if (*option == '+')
5234 break;
5235 i++;
5236 if (i == (long) argc)
5237 ThrowMogrifyException(OptionError,"MissingArgument",option);
5238 if (IsGeometry(argv[i]) == MagickFalse)
5239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5240 }
5241 if (LocaleCompare("layers",option+1) == 0)
5242 {
5243 long
5244 type;
5245
5246 if (*option == '+')
5247 break;
5248 i++;
5249 if (i == (long) (argc-1))
5250 ThrowMogrifyException(OptionError,"MissingArgument",option);
5251 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5252 if (type < 0)
5253 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5254 argv[i]);
5255 break;
5256 }
5257 if (LocaleCompare("level",option+1) == 0)
5258 {
5259 i++;
5260 if (i == (long) argc)
5261 ThrowMogrifyException(OptionError,"MissingArgument",option);
5262 if (IsGeometry(argv[i]) == MagickFalse)
5263 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5264 break;
5265 }
5266 if (LocaleCompare("level-colors",option+1) == 0)
5267 {
5268 i++;
5269 if (i == (long) argc)
5270 ThrowMogrifyException(OptionError,"MissingArgument",option);
5271 break;
5272 }
5273 if (LocaleCompare("linewidth",option+1) == 0)
5274 {
5275 if (*option == '+')
5276 break;
5277 i++;
5278 if (i == (long) argc)
5279 ThrowMogrifyException(OptionError,"MissingArgument",option);
5280 if (IsGeometry(argv[i]) == MagickFalse)
5281 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5282 break;
5283 }
5284 if (LocaleCompare("limit",option+1) == 0)
5285 {
5286 char
5287 *p;
5288
5289 double
5290 value;
5291
5292 long
5293 resource;
5294
5295 if (*option == '+')
5296 break;
5297 i++;
5298 if (i == (long) argc)
5299 ThrowMogrifyException(OptionError,"MissingArgument",option);
5300 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5301 argv[i]);
5302 if (resource < 0)
5303 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5304 argv[i]);
5305 i++;
5306 if (i == (long) argc)
5307 ThrowMogrifyException(OptionError,"MissingArgument",option);
5308 value=strtod(argv[i],&p);
5309 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5311 break;
5312 }
5313 if (LocaleCompare("liquid-rescale",option+1) == 0)
5314 {
5315 i++;
5316 if (i == (long) argc)
5317 ThrowMogrifyException(OptionError,"MissingArgument",option);
5318 if (IsGeometry(argv[i]) == MagickFalse)
5319 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5320 break;
5321 }
5322 if (LocaleCompare("list",option+1) == 0)
5323 {
5324 long
5325 list;
5326
5327 if (*option == '+')
5328 break;
5329 i++;
5330 if (i == (long) argc)
5331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5333 if (list < 0)
5334 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5335 (void) MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5336 argv+j,exception);
5337 return(MagickTrue);
5338 }
5339 if (LocaleCompare("log",option+1) == 0)
5340 {
5341 if (*option == '+')
5342 break;
5343 i++;
5344 if ((i == (long) argc) ||
5345 (strchr(argv[i],'%') == (char *) NULL))
5346 ThrowMogrifyException(OptionError,"MissingArgument",option);
5347 break;
5348 }
5349 if (LocaleCompare("loop",option+1) == 0)
5350 {
5351 if (*option == '+')
5352 break;
5353 i++;
5354 if (i == (long) argc)
5355 ThrowMogrifyException(OptionError,"MissingArgument",option);
5356 if (IsGeometry(argv[i]) == MagickFalse)
5357 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5358 break;
5359 }
5360 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5361 }
5362 case 'm':
5363 {
5364 if (LocaleCompare("map",option+1) == 0)
5365 {
5366 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5367 if (*option == '+')
5368 break;
5369 i++;
5370 if (i == (long) argc)
5371 ThrowMogrifyException(OptionError,"MissingArgument",option);
5372 break;
5373 }
5374 if (LocaleCompare("mask",option+1) == 0)
5375 {
5376 if (*option == '+')
5377 break;
5378 i++;
5379 if (i == (long) argc)
5380 ThrowMogrifyException(OptionError,"MissingArgument",option);
5381 break;
5382 }
5383 if (LocaleCompare("matte",option+1) == 0)
5384 break;
5385 if (LocaleCompare("mattecolor",option+1) == 0)
5386 {
5387 if (*option == '+')
5388 break;
5389 i++;
5390 if (i == (long) argc)
5391 ThrowMogrifyException(OptionError,"MissingArgument",option);
5392 break;
5393 }
cristyf40785b2010-03-06 02:27:27 +00005394 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005395 break;
cristyf40785b2010-03-06 02:27:27 +00005396 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005397 break;
cristy3ed852e2009-09-05 21:47:34 +00005398 if (LocaleCompare("modulate",option+1) == 0)
5399 {
5400 if (*option == '+')
5401 break;
5402 i++;
5403 if (i == (long) argc)
5404 ThrowMogrifyException(OptionError,"MissingArgument",option);
5405 if (IsGeometry(argv[i]) == MagickFalse)
5406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5407 break;
5408 }
5409 if (LocaleCompare("median",option+1) == 0)
5410 {
5411 if (*option == '+')
5412 break;
5413 i++;
5414 if (i == (long) argc)
5415 ThrowMogrifyException(OptionError,"MissingArgument",option);
5416 if (IsGeometry(argv[i]) == MagickFalse)
5417 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5418 break;
5419 }
5420 if (LocaleCompare("monitor",option+1) == 0)
5421 break;
5422 if (LocaleCompare("monochrome",option+1) == 0)
5423 break;
5424 if (LocaleCompare("morph",option+1) == 0)
5425 {
5426 if (*option == '+')
5427 break;
5428 i++;
5429 if (i == (long) (argc-1))
5430 ThrowMogrifyException(OptionError,"MissingArgument",option);
5431 if (IsGeometry(argv[i]) == MagickFalse)
5432 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5433 break;
5434 }
anthony29188a82010-01-22 10:12:34 +00005435 if (LocaleCompare("morphology",option+1) == 0)
5436 {
5437 long
5438 op;
5439
5440 char
5441 token[MaxTextExtent];
5442
5443 i++;
5444 if (i == (long) argc)
5445 ThrowMogrifyException(OptionError,"MissingArgument",option);
5446 GetMagickToken(argv[i],NULL,token);
5447 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5448 if (op < 0)
5449 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005450 token);
anthony29188a82010-01-22 10:12:34 +00005451 i++;
5452 if (i == (long) (argc-1))
5453 ThrowMogrifyException(OptionError,"MissingArgument",option);
5454 GetMagickToken(argv[i],NULL,token);
cristyf0c78232010-03-15 12:53:40 +00005455 if (isalpha((int) ((unsigned char) *token)) != 0)
anthony29188a82010-01-22 10:12:34 +00005456 {
5457 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
5458 if (op < 0)
5459 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
cristyf0c78232010-03-15 12:53:40 +00005460 token);
anthony29188a82010-01-22 10:12:34 +00005461 }
anthony29188a82010-01-22 10:12:34 +00005462 break;
5463 }
cristy3ed852e2009-09-05 21:47:34 +00005464 if (LocaleCompare("mosaic",option+1) == 0)
5465 break;
5466 if (LocaleCompare("motion-blur",option+1) == 0)
5467 {
5468 if (*option == '+')
5469 break;
5470 i++;
5471 if (i == (long) argc)
5472 ThrowMogrifyException(OptionError,"MissingArgument",option);
5473 if (IsGeometry(argv[i]) == MagickFalse)
5474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5475 break;
5476 }
5477 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5478 }
5479 case 'n':
5480 {
5481 if (LocaleCompare("negate",option+1) == 0)
5482 break;
5483 if (LocaleCompare("noise",option+1) == 0)
5484 {
5485 i++;
5486 if (i == (long) argc)
5487 ThrowMogrifyException(OptionError,"MissingArgument",option);
5488 if (*option == '+')
5489 {
5490 long
5491 noise;
5492
5493 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5494 if (noise < 0)
5495 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5496 argv[i]);
5497 break;
5498 }
5499 if (IsGeometry(argv[i]) == MagickFalse)
5500 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5501 break;
5502 }
5503 if (LocaleCompare("noop",option+1) == 0)
5504 break;
5505 if (LocaleCompare("normalize",option+1) == 0)
5506 break;
5507 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5508 }
5509 case 'o':
5510 {
5511 if (LocaleCompare("opaque",option+1) == 0)
5512 {
cristy3ed852e2009-09-05 21:47:34 +00005513 i++;
5514 if (i == (long) argc)
5515 ThrowMogrifyException(OptionError,"MissingArgument",option);
5516 break;
5517 }
5518 if (LocaleCompare("ordered-dither",option+1) == 0)
5519 {
5520 if (*option == '+')
5521 break;
5522 i++;
5523 if (i == (long) argc)
5524 ThrowMogrifyException(OptionError,"MissingArgument",option);
5525 break;
5526 }
5527 if (LocaleCompare("orient",option+1) == 0)
5528 {
5529 long
5530 orientation;
5531
5532 orientation=UndefinedOrientation;
5533 if (*option == '+')
5534 break;
5535 i++;
5536 if (i == (long) (argc-1))
5537 ThrowMogrifyException(OptionError,"MissingArgument",option);
5538 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5539 argv[i]);
5540 if (orientation < 0)
5541 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5542 argv[i]);
5543 break;
5544 }
5545 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5546 }
5547 case 'p':
5548 {
5549 if (LocaleCompare("page",option+1) == 0)
5550 {
5551 if (*option == '+')
5552 break;
5553 i++;
5554 if (i == (long) argc)
5555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 break;
5557 }
5558 if (LocaleCompare("paint",option+1) == 0)
5559 {
5560 if (*option == '+')
5561 break;
5562 i++;
5563 if (i == (long) argc)
5564 ThrowMogrifyException(OptionError,"MissingArgument",option);
5565 if (IsGeometry(argv[i]) == MagickFalse)
5566 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5567 break;
5568 }
5569 if (LocaleCompare("path",option+1) == 0)
5570 {
5571 (void) CloneString(&path,(char *) NULL);
5572 if (*option == '+')
5573 break;
5574 i++;
5575 if (i == (long) argc)
5576 ThrowMogrifyException(OptionError,"MissingArgument",option);
5577 (void) CloneString(&path,argv[i]);
5578 break;
5579 }
5580 if (LocaleCompare("pointsize",option+1) == 0)
5581 {
5582 if (*option == '+')
5583 break;
5584 i++;
5585 if (i == (long) argc)
5586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 if (IsGeometry(argv[i]) == MagickFalse)
5588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5589 break;
5590 }
5591 if (LocaleCompare("polaroid",option+1) == 0)
5592 {
5593 if (*option == '+')
5594 break;
5595 i++;
5596 if (i == (long) argc)
5597 ThrowMogrifyException(OptionError,"MissingArgument",option);
5598 if (IsGeometry(argv[i]) == MagickFalse)
5599 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5600 break;
5601 }
5602 if (LocaleCompare("posterize",option+1) == 0)
5603 {
5604 if (*option == '+')
5605 break;
5606 i++;
5607 if (i == (long) argc)
5608 ThrowMogrifyException(OptionError,"MissingArgument",option);
5609 if (IsGeometry(argv[i]) == MagickFalse)
5610 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5611 break;
5612 }
cristye7f51092010-01-17 00:39:37 +00005613 if (LocaleCompare("precision",option+1) == 0)
5614 {
5615 if (*option == '+')
5616 break;
5617 i++;
5618 if (i == (long) argc)
5619 ThrowMogrifyException(OptionError,"MissingArgument",option);
5620 if (IsGeometry(argv[i]) == MagickFalse)
5621 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5622 break;
5623 }
cristy3ed852e2009-09-05 21:47:34 +00005624 if (LocaleCompare("print",option+1) == 0)
5625 {
5626 if (*option == '+')
5627 break;
5628 i++;
5629 if (i == (long) argc)
5630 ThrowMogrifyException(OptionError,"MissingArgument",option);
5631 break;
5632 }
5633 if (LocaleCompare("process",option+1) == 0)
5634 {
5635 if (*option == '+')
5636 break;
5637 i++;
5638 if (i == (long) (argc-1))
5639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 break;
5641 }
5642 if (LocaleCompare("profile",option+1) == 0)
5643 {
5644 i++;
5645 if (i == (long) argc)
5646 ThrowMogrifyException(OptionError,"MissingArgument",option);
5647 break;
5648 }
5649 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5650 }
5651 case 'q':
5652 {
5653 if (LocaleCompare("quality",option+1) == 0)
5654 {
5655 if (*option == '+')
5656 break;
5657 i++;
5658 if (i == (long) argc)
5659 ThrowMogrifyException(OptionError,"MissingArgument",option);
5660 if (IsGeometry(argv[i]) == MagickFalse)
5661 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5662 break;
5663 }
5664 if (LocaleCompare("quantize",option+1) == 0)
5665 {
5666 long
5667 colorspace;
5668
5669 if (*option == '+')
5670 break;
5671 i++;
5672 if (i == (long) (argc-1))
5673 ThrowMogrifyException(OptionError,"MissingArgument",option);
5674 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5675 argv[i]);
5676 if (colorspace < 0)
5677 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5678 argv[i]);
5679 break;
5680 }
5681 if (LocaleCompare("quiet",option+1) == 0)
5682 break;
5683 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5684 }
5685 case 'r':
5686 {
5687 if (LocaleCompare("radial-blur",option+1) == 0)
5688 {
5689 i++;
5690 if (i == (long) argc)
5691 ThrowMogrifyException(OptionError,"MissingArgument",option);
5692 if (IsGeometry(argv[i]) == MagickFalse)
5693 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5694 break;
5695 }
5696 if (LocaleCompare("raise",option+1) == 0)
5697 {
5698 i++;
5699 if (i == (long) argc)
5700 ThrowMogrifyException(OptionError,"MissingArgument",option);
5701 if (IsGeometry(argv[i]) == MagickFalse)
5702 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5703 break;
5704 }
5705 if (LocaleCompare("random-threshold",option+1) == 0)
5706 {
5707 if (*option == '+')
5708 break;
5709 i++;
5710 if (i == (long) argc)
5711 ThrowMogrifyException(OptionError,"MissingArgument",option);
5712 if (IsGeometry(argv[i]) == MagickFalse)
5713 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5714 break;
5715 }
5716 if (LocaleCompare("red-primary",option+1) == 0)
5717 {
5718 if (*option == '+')
5719 break;
5720 i++;
5721 if (i == (long) argc)
5722 ThrowMogrifyException(OptionError,"MissingArgument",option);
5723 if (IsGeometry(argv[i]) == MagickFalse)
5724 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5725 }
5726 if (LocaleCompare("region",option+1) == 0)
5727 {
5728 if (*option == '+')
5729 break;
5730 i++;
5731 if (i == (long) argc)
5732 ThrowMogrifyException(OptionError,"MissingArgument",option);
5733 if (IsGeometry(argv[i]) == MagickFalse)
5734 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5735 break;
5736 }
cristyf0c78232010-03-15 12:53:40 +00005737 if (LocaleCompare("remap",option+1) == 0)
5738 {
5739 if (*option == '+')
5740 break;
5741 i++;
5742 if (i == (long) (argc-1))
5743 ThrowMogrifyException(OptionError,"MissingArgument",option);
5744 break;
5745 }
cristy3ed852e2009-09-05 21:47:34 +00005746 if (LocaleCompare("render",option+1) == 0)
5747 break;
5748 if (LocaleCompare("repage",option+1) == 0)
5749 {
5750 if (*option == '+')
5751 break;
5752 i++;
5753 if (i == (long) argc)
5754 ThrowMogrifyException(OptionError,"MissingArgument",option);
5755 if (IsGeometry(argv[i]) == MagickFalse)
5756 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5757 break;
5758 }
5759 if (LocaleCompare("resample",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("resize",option+1) == 0)
5771 {
5772 if (*option == '+')
5773 break;
5774 i++;
5775 if (i == (long) argc)
5776 ThrowMogrifyException(OptionError,"MissingArgument",option);
5777 if (IsGeometry(argv[i]) == MagickFalse)
5778 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5779 break;
5780 }
5781 if (LocaleCompare("reverse",option+1) == 0)
5782 break;
5783 if (LocaleCompare("roll",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("rotate",option+1) == 0)
5795 {
5796 i++;
5797 if (i == (long) argc)
5798 ThrowMogrifyException(OptionError,"MissingArgument",option);
5799 if (IsGeometry(argv[i]) == MagickFalse)
5800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5801 break;
5802 }
5803 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5804 }
5805 case 's':
5806 {
5807 if (LocaleCompare("sample",option+1) == 0)
5808 {
5809 if (*option == '+')
5810 break;
5811 i++;
5812 if (i == (long) argc)
5813 ThrowMogrifyException(OptionError,"MissingArgument",option);
5814 if (IsGeometry(argv[i]) == MagickFalse)
5815 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5816 break;
5817 }
5818 if (LocaleCompare("sampling-factor",option+1) == 0)
5819 {
5820 if (*option == '+')
5821 break;
5822 i++;
5823 if (i == (long) argc)
5824 ThrowMogrifyException(OptionError,"MissingArgument",option);
5825 if (IsGeometry(argv[i]) == MagickFalse)
5826 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5827 break;
5828 }
5829 if (LocaleCompare("scale",option+1) == 0)
5830 {
5831 if (*option == '+')
5832 break;
5833 i++;
5834 if (i == (long) argc)
5835 ThrowMogrifyException(OptionError,"MissingArgument",option);
5836 if (IsGeometry(argv[i]) == MagickFalse)
5837 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5838 break;
5839 }
5840 if (LocaleCompare("scene",option+1) == 0)
5841 {
5842 if (*option == '+')
5843 break;
5844 i++;
5845 if (i == (long) argc)
5846 ThrowMogrifyException(OptionError,"MissingArgument",option);
5847 if (IsGeometry(argv[i]) == MagickFalse)
5848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5849 break;
5850 }
5851 if (LocaleCompare("seed",option+1) == 0)
5852 {
5853 if (*option == '+')
5854 break;
5855 i++;
5856 if (i == (long) argc)
5857 ThrowMogrifyException(OptionError,"MissingArgument",option);
5858 if (IsGeometry(argv[i]) == MagickFalse)
5859 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5860 break;
5861 }
5862 if (LocaleCompare("segment",option+1) == 0)
5863 {
5864 if (*option == '+')
5865 break;
5866 i++;
5867 if (i == (long) argc)
5868 ThrowMogrifyException(OptionError,"MissingArgument",option);
5869 if (IsGeometry(argv[i]) == MagickFalse)
5870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5871 break;
5872 }
5873 if (LocaleCompare("selective-blur",option+1) == 0)
5874 {
5875 i++;
5876 if (i == (long) argc)
5877 ThrowMogrifyException(OptionError,"MissingArgument",option);
5878 if (IsGeometry(argv[i]) == MagickFalse)
5879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5880 break;
5881 }
5882 if (LocaleCompare("separate",option+1) == 0)
5883 break;
5884 if (LocaleCompare("sepia-tone",option+1) == 0)
5885 {
5886 if (*option == '+')
5887 break;
5888 i++;
5889 if (i == (long) argc)
5890 ThrowMogrifyException(OptionError,"MissingArgument",option);
5891 if (IsGeometry(argv[i]) == MagickFalse)
5892 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5893 break;
5894 }
5895 if (LocaleCompare("set",option+1) == 0)
5896 {
5897 i++;
5898 if (i == (long) argc)
5899 ThrowMogrifyException(OptionError,"MissingArgument",option);
5900 if (*option == '+')
5901 break;
5902 i++;
5903 if (i == (long) argc)
5904 ThrowMogrifyException(OptionError,"MissingArgument",option);
5905 break;
5906 }
5907 if (LocaleCompare("shade",option+1) == 0)
5908 {
5909 i++;
5910 if (i == (long) argc)
5911 ThrowMogrifyException(OptionError,"MissingArgument",option);
5912 if (IsGeometry(argv[i]) == MagickFalse)
5913 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5914 break;
5915 }
5916 if (LocaleCompare("shadow",option+1) == 0)
5917 {
5918 if (*option == '+')
5919 break;
5920 i++;
5921 if (i == (long) argc)
5922 ThrowMogrifyException(OptionError,"MissingArgument",option);
5923 if (IsGeometry(argv[i]) == MagickFalse)
5924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5925 break;
5926 }
5927 if (LocaleCompare("sharpen",option+1) == 0)
5928 {
5929 i++;
5930 if (i == (long) argc)
5931 ThrowMogrifyException(OptionError,"MissingArgument",option);
5932 if (IsGeometry(argv[i]) == MagickFalse)
5933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5934 break;
5935 }
5936 if (LocaleCompare("shave",option+1) == 0)
5937 {
5938 if (*option == '+')
5939 break;
5940 i++;
5941 if (i == (long) argc)
5942 ThrowMogrifyException(OptionError,"MissingArgument",option);
5943 if (IsGeometry(argv[i]) == MagickFalse)
5944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5945 break;
5946 }
5947 if (LocaleCompare("shear",option+1) == 0)
5948 {
5949 i++;
5950 if (i == (long) argc)
5951 ThrowMogrifyException(OptionError,"MissingArgument",option);
5952 if (IsGeometry(argv[i]) == MagickFalse)
5953 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5954 break;
5955 }
5956 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5957 {
5958 i++;
5959 if (i == (long) (argc-1))
5960 ThrowMogrifyException(OptionError,"MissingArgument",option);
5961 if (IsGeometry(argv[i]) == MagickFalse)
5962 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5963 break;
5964 }
5965 if (LocaleCompare("size",option+1) == 0)
5966 {
5967 if (*option == '+')
5968 break;
5969 i++;
5970 if (i == (long) argc)
5971 ThrowMogrifyException(OptionError,"MissingArgument",option);
5972 if (IsGeometry(argv[i]) == MagickFalse)
5973 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5974 break;
5975 }
5976 if (LocaleCompare("sketch",option+1) == 0)
5977 {
5978 if (*option == '+')
5979 break;
5980 i++;
5981 if (i == (long) argc)
5982 ThrowMogrifyException(OptionError,"MissingArgument",option);
5983 if (IsGeometry(argv[i]) == MagickFalse)
5984 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5985 break;
5986 }
5987 if (LocaleCompare("solarize",option+1) == 0)
5988 {
5989 if (*option == '+')
5990 break;
5991 i++;
5992 if (i == (long) argc)
5993 ThrowMogrifyException(OptionError,"MissingArgument",option);
5994 if (IsGeometry(argv[i]) == MagickFalse)
5995 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5996 break;
5997 }
5998 if (LocaleCompare("sparse-color",option+1) == 0)
5999 {
6000 long
6001 op;
6002
6003 i++;
6004 if (i == (long) argc)
6005 ThrowMogrifyException(OptionError,"MissingArgument",option);
6006 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6007 if (op < 0)
6008 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6009 argv[i]);
6010 i++;
6011 if (i == (long) (argc-1))
6012 ThrowMogrifyException(OptionError,"MissingArgument",option);
6013 break;
6014 }
6015 if (LocaleCompare("spread",option+1) == 0)
6016 {
6017 if (*option == '+')
6018 break;
6019 i++;
6020 if (i == (long) argc)
6021 ThrowMogrifyException(OptionError,"MissingArgument",option);
6022 if (IsGeometry(argv[i]) == MagickFalse)
6023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6024 break;
6025 }
6026 if (LocaleCompare("stretch",option+1) == 0)
6027 {
6028 long
6029 stretch;
6030
6031 if (*option == '+')
6032 break;
6033 i++;
6034 if (i == (long) (argc-1))
6035 ThrowMogrifyException(OptionError,"MissingArgument",option);
6036 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6037 if (stretch < 0)
6038 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6039 argv[i]);
6040 break;
6041 }
6042 if (LocaleCompare("strip",option+1) == 0)
6043 break;
6044 if (LocaleCompare("stroke",option+1) == 0)
6045 {
6046 if (*option == '+')
6047 break;
6048 i++;
6049 if (i == (long) argc)
6050 ThrowMogrifyException(OptionError,"MissingArgument",option);
6051 break;
6052 }
6053 if (LocaleCompare("strokewidth",option+1) == 0)
6054 {
6055 if (*option == '+')
6056 break;
6057 i++;
6058 if (i == (long) argc)
6059 ThrowMogrifyException(OptionError,"MissingArgument",option);
6060 if (IsGeometry(argv[i]) == MagickFalse)
6061 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6062 break;
6063 }
6064 if (LocaleCompare("style",option+1) == 0)
6065 {
6066 long
6067 style;
6068
6069 if (*option == '+')
6070 break;
6071 i++;
6072 if (i == (long) (argc-1))
6073 ThrowMogrifyException(OptionError,"MissingArgument",option);
6074 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6075 if (style < 0)
6076 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6077 argv[i]);
6078 break;
6079 }
6080 if (LocaleCompare("swirl",option+1) == 0)
6081 {
6082 if (*option == '+')
6083 break;
6084 i++;
6085 if (i == (long) argc)
6086 ThrowMogrifyException(OptionError,"MissingArgument",option);
6087 if (IsGeometry(argv[i]) == MagickFalse)
6088 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6089 break;
6090 }
6091 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6092 }
6093 case 't':
6094 {
6095 if (LocaleCompare("taint",option+1) == 0)
6096 break;
6097 if (LocaleCompare("texture",option+1) == 0)
6098 {
6099 if (*option == '+')
6100 break;
6101 i++;
6102 if (i == (long) argc)
6103 ThrowMogrifyException(OptionError,"MissingArgument",option);
6104 break;
6105 }
6106 if (LocaleCompare("tile",option+1) == 0)
6107 {
6108 if (*option == '+')
6109 break;
6110 i++;
6111 if (i == (long) (argc-1))
6112 ThrowMogrifyException(OptionError,"MissingArgument",option);
6113 break;
6114 }
6115 if (LocaleCompare("tile-offset",option+1) == 0)
6116 {
6117 if (*option == '+')
6118 break;
6119 i++;
6120 if (i == (long) argc)
6121 ThrowMogrifyException(OptionError,"MissingArgument",option);
6122 if (IsGeometry(argv[i]) == MagickFalse)
6123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6124 break;
6125 }
6126 if (LocaleCompare("tint",option+1) == 0)
6127 {
6128 if (*option == '+')
6129 break;
6130 i++;
6131 if (i == (long) (argc-1))
6132 ThrowMogrifyException(OptionError,"MissingArgument",option);
6133 if (IsGeometry(argv[i]) == MagickFalse)
6134 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6135 break;
6136 }
6137 if (LocaleCompare("transform",option+1) == 0)
6138 break;
6139 if (LocaleCompare("transpose",option+1) == 0)
6140 break;
6141 if (LocaleCompare("transverse",option+1) == 0)
6142 break;
6143 if (LocaleCompare("threshold",option+1) == 0)
6144 {
6145 if (*option == '+')
6146 break;
6147 i++;
6148 if (i == (long) argc)
6149 ThrowMogrifyException(OptionError,"MissingArgument",option);
6150 if (IsGeometry(argv[i]) == MagickFalse)
6151 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6152 break;
6153 }
6154 if (LocaleCompare("thumbnail",option+1) == 0)
6155 {
6156 if (*option == '+')
6157 break;
6158 i++;
6159 if (i == (long) argc)
6160 ThrowMogrifyException(OptionError,"MissingArgument",option);
6161 if (IsGeometry(argv[i]) == MagickFalse)
6162 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6163 break;
6164 }
6165 if (LocaleCompare("transparent",option+1) == 0)
6166 {
6167 i++;
6168 if (i == (long) argc)
6169 ThrowMogrifyException(OptionError,"MissingArgument",option);
6170 break;
6171 }
6172 if (LocaleCompare("transparent-color",option+1) == 0)
6173 {
6174 if (*option == '+')
6175 break;
6176 i++;
6177 if (i == (long) (argc-1))
6178 ThrowMogrifyException(OptionError,"MissingArgument",option);
6179 break;
6180 }
6181 if (LocaleCompare("treedepth",option+1) == 0)
6182 {
6183 if (*option == '+')
6184 break;
6185 i++;
6186 if (i == (long) argc)
6187 ThrowMogrifyException(OptionError,"MissingArgument",option);
6188 if (IsGeometry(argv[i]) == MagickFalse)
6189 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6190 break;
6191 }
6192 if (LocaleCompare("trim",option+1) == 0)
6193 break;
6194 if (LocaleCompare("type",option+1) == 0)
6195 {
6196 long
6197 type;
6198
6199 if (*option == '+')
6200 break;
6201 i++;
6202 if (i == (long) argc)
6203 ThrowMogrifyException(OptionError,"MissingArgument",option);
6204 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6205 if (type < 0)
6206 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6207 argv[i]);
6208 break;
6209 }
6210 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6211 }
6212 case 'u':
6213 {
6214 if (LocaleCompare("undercolor",option+1) == 0)
6215 {
6216 if (*option == '+')
6217 break;
6218 i++;
6219 if (i == (long) argc)
6220 ThrowMogrifyException(OptionError,"MissingArgument",option);
6221 break;
6222 }
6223 if (LocaleCompare("unique-colors",option+1) == 0)
6224 break;
6225 if (LocaleCompare("units",option+1) == 0)
6226 {
6227 long
6228 units;
6229
6230 if (*option == '+')
6231 break;
6232 i++;
6233 if (i == (long) argc)
6234 ThrowMogrifyException(OptionError,"MissingArgument",option);
6235 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6236 argv[i]);
6237 if (units < 0)
6238 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6239 argv[i]);
6240 break;
6241 }
6242 if (LocaleCompare("unsharp",option+1) == 0)
6243 {
6244 i++;
6245 if (i == (long) argc)
6246 ThrowMogrifyException(OptionError,"MissingArgument",option);
6247 if (IsGeometry(argv[i]) == MagickFalse)
6248 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6249 break;
6250 }
6251 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6252 }
6253 case 'v':
6254 {
6255 if (LocaleCompare("verbose",option+1) == 0)
6256 {
6257 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6258 break;
6259 }
6260 if ((LocaleCompare("version",option+1) == 0) ||
6261 (LocaleCompare("-version",option+1) == 0))
6262 {
6263 (void) fprintf(stdout,"Version: %s\n",
6264 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006265 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6266 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006267 break;
6268 }
6269 if (LocaleCompare("view",option+1) == 0)
6270 {
6271 if (*option == '+')
6272 break;
6273 i++;
6274 if (i == (long) argc)
6275 ThrowMogrifyException(OptionError,"MissingArgument",option);
6276 break;
6277 }
6278 if (LocaleCompare("vignette",option+1) == 0)
6279 {
6280 if (*option == '+')
6281 break;
6282 i++;
6283 if (i == (long) argc)
6284 ThrowMogrifyException(OptionError,"MissingArgument",option);
6285 if (IsGeometry(argv[i]) == MagickFalse)
6286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6287 break;
6288 }
6289 if (LocaleCompare("virtual-pixel",option+1) == 0)
6290 {
6291 long
6292 method;
6293
6294 if (*option == '+')
6295 break;
6296 i++;
6297 if (i == (long) argc)
6298 ThrowMogrifyException(OptionError,"MissingArgument",option);
6299 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6300 argv[i]);
6301 if (method < 0)
6302 ThrowMogrifyException(OptionError,
6303 "UnrecognizedVirtualPixelMethod",argv[i]);
6304 break;
6305 }
6306 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6307 }
6308 case 'w':
6309 {
6310 if (LocaleCompare("wave",option+1) == 0)
6311 {
6312 i++;
6313 if (i == (long) argc)
6314 ThrowMogrifyException(OptionError,"MissingArgument",option);
6315 if (IsGeometry(argv[i]) == MagickFalse)
6316 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6317 break;
6318 }
6319 if (LocaleCompare("weight",option+1) == 0)
6320 {
6321 if (*option == '+')
6322 break;
6323 i++;
6324 if (i == (long) (argc-1))
6325 ThrowMogrifyException(OptionError,"MissingArgument",option);
6326 break;
6327 }
6328 if (LocaleCompare("white-point",option+1) == 0)
6329 {
6330 if (*option == '+')
6331 break;
6332 i++;
6333 if (i == (long) argc)
6334 ThrowMogrifyException(OptionError,"MissingArgument",option);
6335 if (IsGeometry(argv[i]) == MagickFalse)
6336 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6337 break;
6338 }
6339 if (LocaleCompare("white-threshold",option+1) == 0)
6340 {
6341 if (*option == '+')
6342 break;
6343 i++;
6344 if (i == (long) argc)
6345 ThrowMogrifyException(OptionError,"MissingArgument",option);
6346 if (IsGeometry(argv[i]) == MagickFalse)
6347 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6348 break;
6349 }
6350 if (LocaleCompare("write",option+1) == 0)
6351 {
6352 i++;
6353 if (i == (long) (argc-1))
6354 ThrowMogrifyException(OptionError,"MissingArgument",option);
6355 break;
6356 }
6357 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6358 }
6359 case '?':
6360 break;
6361 default:
6362 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6363 }
6364 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6365 MagickFalse : MagickTrue;
6366 if (fire != MagickFalse)
6367 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6368 }
6369 if (k != 0)
6370 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6371 if (i != argc)
6372 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6373 DestroyMogrify();
6374 return(status != 0 ? MagickTrue : MagickFalse);
6375}
6376
6377/*
6378%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6379% %
6380% %
6381% %
6382+ M o g r i f y I m a g e I n f o %
6383% %
6384% %
6385% %
6386%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6387%
6388% MogrifyImageInfo() applies image processing settings to the image as
6389% prescribed by command line options.
6390%
6391% The format of the MogrifyImageInfo method is:
6392%
6393% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6394% const char **argv,ExceptionInfo *exception)
6395%
6396% A description of each parameter follows:
6397%
6398% o image_info: the image info..
6399%
6400% o argc: Specifies a pointer to an integer describing the number of
6401% elements in the argument vector.
6402%
6403% o argv: Specifies a pointer to a text array containing the command line
6404% arguments.
6405%
6406% o exception: return any errors or warnings in this structure.
6407%
6408*/
6409WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6410 const int argc,const char **argv,ExceptionInfo *exception)
6411{
6412 const char
6413 *option;
6414
6415 GeometryInfo
6416 geometry_info;
6417
6418 long
6419 count;
6420
6421 register long
6422 i;
6423
6424 /*
6425 Initialize method variables.
6426 */
6427 assert(image_info != (ImageInfo *) NULL);
6428 assert(image_info->signature == MagickSignature);
6429 if (image_info->debug != MagickFalse)
6430 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6431 image_info->filename);
6432 if (argc < 0)
6433 return(MagickTrue);
6434 /*
6435 Set the image settings.
6436 */
6437 for (i=0; i < (long) argc; i++)
6438 {
6439 option=argv[i];
6440 if (IsMagickOption(option) == MagickFalse)
6441 continue;
6442 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6443 0L);
6444 if ((i+count) >= argc)
6445 break;
6446 switch (*(option+1))
6447 {
6448 case 'a':
6449 {
6450 if (LocaleCompare("adjoin",option+1) == 0)
6451 {
6452 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6453 break;
6454 }
6455 if (LocaleCompare("antialias",option+1) == 0)
6456 {
6457 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6458 break;
6459 }
6460 if (LocaleCompare("attenuate",option+1) == 0)
6461 {
6462 if (*option == '+')
6463 {
6464 (void) DeleteImageOption(image_info,option+1);
6465 break;
6466 }
6467 (void) SetImageOption(image_info,option+1,argv[i+1]);
6468 break;
6469 }
6470 if (LocaleCompare("authenticate",option+1) == 0)
6471 {
6472 if (*option == '+')
6473 (void) CloneString(&image_info->authenticate,(char *) NULL);
6474 else
6475 (void) CloneString(&image_info->authenticate,argv[i+1]);
6476 break;
6477 }
6478 break;
6479 }
6480 case 'b':
6481 {
6482 if (LocaleCompare("background",option+1) == 0)
6483 {
6484 if (*option == '+')
6485 {
6486 (void) DeleteImageOption(image_info,option+1);
6487 (void) QueryColorDatabase(BackgroundColor,
6488 &image_info->background_color,exception);
6489 break;
6490 }
6491 (void) SetImageOption(image_info,option+1,argv[i+1]);
6492 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6493 exception);
6494 break;
6495 }
6496 if (LocaleCompare("bias",option+1) == 0)
6497 {
6498 if (*option == '+')
6499 {
6500 (void) SetImageOption(image_info,option+1,"0.0");
6501 break;
6502 }
6503 (void) SetImageOption(image_info,option+1,argv[i+1]);
6504 break;
6505 }
6506 if (LocaleCompare("black-point-compensation",option+1) == 0)
6507 {
6508 if (*option == '+')
6509 {
6510 (void) SetImageOption(image_info,option+1,"false");
6511 break;
6512 }
6513 (void) SetImageOption(image_info,option+1,"true");
6514 break;
6515 }
6516 if (LocaleCompare("blue-primary",option+1) == 0)
6517 {
6518 if (*option == '+')
6519 {
6520 (void) SetImageOption(image_info,option+1,"0.0");
6521 break;
6522 }
6523 (void) SetImageOption(image_info,option+1,argv[i+1]);
6524 break;
6525 }
6526 if (LocaleCompare("bordercolor",option+1) == 0)
6527 {
6528 if (*option == '+')
6529 {
6530 (void) DeleteImageOption(image_info,option+1);
6531 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6532 exception);
6533 break;
6534 }
6535 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6536 exception);
6537 (void) SetImageOption(image_info,option+1,argv[i+1]);
6538 break;
6539 }
6540 if (LocaleCompare("box",option+1) == 0)
6541 {
6542 if (*option == '+')
6543 {
6544 (void) SetImageOption(image_info,"undercolor","none");
6545 break;
6546 }
6547 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6548 break;
6549 }
6550 break;
6551 }
6552 case 'c':
6553 {
6554 if (LocaleCompare("cache",option+1) == 0)
6555 {
6556 MagickSizeType
6557 limit;
6558
6559 limit=MagickResourceInfinity;
6560 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006561 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006562 (void) SetMagickResourceLimit(MemoryResource,limit);
6563 (void) SetMagickResourceLimit(MapResource,2*limit);
6564 break;
6565 }
6566 if (LocaleCompare("caption",option+1) == 0)
6567 {
6568 if (*option == '+')
6569 {
6570 (void) DeleteImageOption(image_info,option+1);
6571 break;
6572 }
6573 (void) SetImageOption(image_info,option+1,argv[i+1]);
6574 break;
6575 }
6576 if (LocaleCompare("channel",option+1) == 0)
6577 {
6578 if (*option == '+')
6579 {
6580 image_info->channel=DefaultChannels;
6581 break;
6582 }
6583 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6584 break;
6585 }
6586 if (LocaleCompare("colors",option+1) == 0)
6587 {
cristye27293e2009-12-18 02:53:20 +00006588 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006589 break;
6590 }
6591 if (LocaleCompare("colorspace",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 image_info->colorspace=UndefinedColorspace;
6596 (void) SetImageOption(image_info,option+1,"undefined");
6597 break;
6598 }
6599 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6600 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6601 (void) SetImageOption(image_info,option+1,argv[i+1]);
6602 break;
6603 }
6604 if (LocaleCompare("compress",option+1) == 0)
6605 {
6606 if (*option == '+')
6607 {
6608 image_info->compression=UndefinedCompression;
6609 (void) SetImageOption(image_info,option+1,"undefined");
6610 break;
6611 }
6612 image_info->compression=(CompressionType) ParseMagickOption(
6613 MagickCompressOptions,MagickFalse,argv[i+1]);
6614 (void) SetImageOption(image_info,option+1,argv[i+1]);
6615 break;
6616 }
6617 if (LocaleCompare("comment",option+1) == 0)
6618 {
6619 if (*option == '+')
6620 {
6621 (void) DeleteImageOption(image_info,option+1);
6622 break;
6623 }
6624 (void) SetImageOption(image_info,option+1,argv[i+1]);
6625 break;
6626 }
6627 if (LocaleCompare("compose",option+1) == 0)
6628 {
6629 if (*option == '+')
6630 {
6631 (void) SetImageOption(image_info,option+1,"undefined");
6632 break;
6633 }
6634 (void) SetImageOption(image_info,option+1,argv[i+1]);
6635 break;
6636 }
6637 if (LocaleCompare("compress",option+1) == 0)
6638 {
6639 if (*option == '+')
6640 {
6641 image_info->compression=UndefinedCompression;
6642 (void) SetImageOption(image_info,option+1,"undefined");
6643 break;
6644 }
6645 image_info->compression=(CompressionType) ParseMagickOption(
6646 MagickCompressOptions,MagickFalse,argv[i+1]);
6647 (void) SetImageOption(image_info,option+1,argv[i+1]);
6648 break;
6649 }
6650 break;
6651 }
6652 case 'd':
6653 {
6654 if (LocaleCompare("debug",option+1) == 0)
6655 {
6656 if (*option == '+')
6657 (void) SetLogEventMask("none");
6658 else
6659 (void) SetLogEventMask(argv[i+1]);
6660 image_info->debug=IsEventLogging();
6661 break;
6662 }
6663 if (LocaleCompare("define",option+1) == 0)
6664 {
6665 if (*option == '+')
6666 {
6667 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6668 (void) DeleteImageRegistry(argv[i+1]+9);
6669 else
6670 (void) DeleteImageOption(image_info,argv[i+1]);
6671 break;
6672 }
6673 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6674 {
6675 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6676 exception);
6677 break;
6678 }
6679 (void) DefineImageOption(image_info,argv[i+1]);
6680 break;
6681 }
6682 if (LocaleCompare("delay",option+1) == 0)
6683 {
6684 if (*option == '+')
6685 {
6686 (void) SetImageOption(image_info,option+1,"0");
6687 break;
6688 }
6689 (void) SetImageOption(image_info,option+1,argv[i+1]);
6690 break;
6691 }
6692 if (LocaleCompare("density",option+1) == 0)
6693 {
6694 /*
6695 Set image density.
6696 */
6697 if (*option == '+')
6698 {
6699 if (image_info->density != (char *) NULL)
6700 image_info->density=DestroyString(image_info->density);
6701 (void) SetImageOption(image_info,option+1,"72");
6702 break;
6703 }
6704 (void) CloneString(&image_info->density,argv[i+1]);
6705 (void) SetImageOption(image_info,option+1,argv[i+1]);
6706 break;
6707 }
6708 if (LocaleCompare("depth",option+1) == 0)
6709 {
6710 if (*option == '+')
6711 {
6712 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6713 break;
6714 }
cristye27293e2009-12-18 02:53:20 +00006715 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006716 break;
6717 }
cristyc9b12952010-03-28 01:12:28 +00006718 if (LocaleCompare("direction",option+1) == 0)
6719 {
6720 if (*option == '+')
6721 {
6722 (void) SetImageOption(image_info,option+1,"undefined");
6723 break;
6724 }
6725 (void) SetImageOption(image_info,option+1,argv[i+1]);
6726 break;
6727 }
cristy3ed852e2009-09-05 21:47:34 +00006728 if (LocaleCompare("display",option+1) == 0)
6729 {
6730 if (*option == '+')
6731 {
6732 if (image_info->server_name != (char *) NULL)
6733 image_info->server_name=DestroyString(
6734 image_info->server_name);
6735 break;
6736 }
6737 (void) CloneString(&image_info->server_name,argv[i+1]);
6738 break;
6739 }
6740 if (LocaleCompare("dispose",option+1) == 0)
6741 {
6742 if (*option == '+')
6743 {
6744 (void) SetImageOption(image_info,option+1,"undefined");
6745 break;
6746 }
6747 (void) SetImageOption(image_info,option+1,argv[i+1]);
6748 break;
6749 }
6750 if (LocaleCompare("dither",option+1) == 0)
6751 {
6752 if (*option == '+')
6753 {
6754 image_info->dither=MagickFalse;
6755 (void) SetImageOption(image_info,option+1,"undefined");
6756 break;
6757 }
6758 (void) SetImageOption(image_info,option+1,argv[i+1]);
6759 image_info->dither=MagickTrue;
6760 break;
6761 }
6762 break;
6763 }
6764 case 'e':
6765 {
6766 if (LocaleCompare("encoding",option+1) == 0)
6767 {
6768 if (*option == '+')
6769 {
6770 (void) SetImageOption(image_info,option+1,"undefined");
6771 break;
6772 }
6773 (void) SetImageOption(image_info,option+1,argv[i+1]);
6774 break;
6775 }
6776 if (LocaleCompare("endian",option+1) == 0)
6777 {
6778 if (*option == '+')
6779 {
6780 image_info->endian=UndefinedEndian;
6781 (void) SetImageOption(image_info,option+1,"undefined");
6782 break;
6783 }
6784 image_info->endian=(EndianType) ParseMagickOption(
6785 MagickEndianOptions,MagickFalse,argv[i+1]);
6786 (void) SetImageOption(image_info,option+1,argv[i+1]);
6787 break;
6788 }
6789 if (LocaleCompare("extract",option+1) == 0)
6790 {
6791 /*
6792 Set image extract geometry.
6793 */
6794 if (*option == '+')
6795 {
6796 if (image_info->extract != (char *) NULL)
6797 image_info->extract=DestroyString(image_info->extract);
6798 break;
6799 }
6800 (void) CloneString(&image_info->extract,argv[i+1]);
6801 break;
6802 }
6803 break;
6804 }
6805 case 'f':
6806 {
6807 if (LocaleCompare("fill",option+1) == 0)
6808 {
6809 if (*option == '+')
6810 {
6811 (void) SetImageOption(image_info,option+1,"none");
6812 break;
6813 }
6814 (void) SetImageOption(image_info,option+1,argv[i+1]);
6815 break;
6816 }
6817 if (LocaleCompare("filter",option+1) == 0)
6818 {
6819 if (*option == '+')
6820 {
6821 (void) SetImageOption(image_info,option+1,"undefined");
6822 break;
6823 }
6824 (void) SetImageOption(image_info,option+1,argv[i+1]);
6825 break;
6826 }
6827 if (LocaleCompare("font",option+1) == 0)
6828 {
6829 if (*option == '+')
6830 {
6831 if (image_info->font != (char *) NULL)
6832 image_info->font=DestroyString(image_info->font);
6833 break;
6834 }
6835 (void) CloneString(&image_info->font,argv[i+1]);
6836 break;
6837 }
6838 if (LocaleCompare("format",option+1) == 0)
6839 {
6840 register const char
6841 *q;
6842
6843 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6844 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6845 image_info->ping=MagickFalse;
6846 (void) SetImageOption(image_info,option+1,argv[i+1]);
6847 break;
6848 }
6849 if (LocaleCompare("fuzz",option+1) == 0)
6850 {
6851 if (*option == '+')
6852 {
6853 image_info->fuzz=0.0;
6854 (void) SetImageOption(image_info,option+1,"0");
6855 break;
6856 }
cristyf2f27272009-12-17 14:48:46 +00006857 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006858 1.0);
6859 (void) SetImageOption(image_info,option+1,argv[i+1]);
6860 break;
6861 }
6862 break;
6863 }
6864 case 'g':
6865 {
6866 if (LocaleCompare("gravity",option+1) == 0)
6867 {
6868 if (*option == '+')
6869 {
6870 (void) SetImageOption(image_info,option+1,"undefined");
6871 break;
6872 }
6873 (void) SetImageOption(image_info,option+1,argv[i+1]);
6874 break;
6875 }
6876 if (LocaleCompare("green-primary",option+1) == 0)
6877 {
6878 if (*option == '+')
6879 {
6880 (void) SetImageOption(image_info,option+1,"0.0");
6881 break;
6882 }
6883 (void) SetImageOption(image_info,option+1,argv[i+1]);
6884 break;
6885 }
6886 break;
6887 }
6888 case 'i':
6889 {
6890 if (LocaleCompare("intent",option+1) == 0)
6891 {
6892 if (*option == '+')
6893 {
6894 (void) SetImageOption(image_info,option+1,"undefined");
6895 break;
6896 }
6897 (void) SetImageOption(image_info,option+1,argv[i+1]);
6898 break;
6899 }
6900 if (LocaleCompare("interlace",option+1) == 0)
6901 {
6902 if (*option == '+')
6903 {
6904 image_info->interlace=UndefinedInterlace;
6905 (void) SetImageOption(image_info,option+1,"undefined");
6906 break;
6907 }
6908 image_info->interlace=(InterlaceType) ParseMagickOption(
6909 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6910 (void) SetImageOption(image_info,option+1,argv[i+1]);
6911 break;
6912 }
cristyb32b90a2009-09-07 21:45:48 +00006913 if (LocaleCompare("interline-spacing",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 }
cristy3ed852e2009-09-05 21:47:34 +00006923 if (LocaleCompare("interpolate",option+1) == 0)
6924 {
6925 if (*option == '+')
6926 {
6927 (void) SetImageOption(image_info,option+1,"undefined");
6928 break;
6929 }
6930 (void) SetImageOption(image_info,option+1,argv[i+1]);
6931 break;
6932 }
6933 if (LocaleCompare("interword-spacing",option+1) == 0)
6934 {
6935 if (*option == '+')
6936 {
6937 (void) SetImageOption(image_info,option+1,"undefined");
6938 break;
6939 }
6940 (void) SetImageOption(image_info,option+1,argv[i+1]);
6941 break;
6942 }
6943 break;
6944 }
6945 case 'k':
6946 {
6947 if (LocaleCompare("kerning",option+1) == 0)
6948 {
6949 if (*option == '+')
6950 {
6951 (void) SetImageOption(image_info,option+1,"undefined");
6952 break;
6953 }
6954 (void) SetImageOption(image_info,option+1,argv[i+1]);
6955 break;
6956 }
6957 break;
6958 }
6959 case 'l':
6960 {
6961 if (LocaleCompare("label",option+1) == 0)
6962 {
6963 if (*option == '+')
6964 {
6965 (void) DeleteImageOption(image_info,option+1);
6966 break;
6967 }
6968 (void) SetImageOption(image_info,option+1,argv[i+1]);
6969 break;
6970 }
6971 if (LocaleCompare("limit",option+1) == 0)
6972 {
6973 MagickSizeType
6974 limit;
6975
6976 ResourceType
6977 type;
6978
6979 if (*option == '+')
6980 break;
6981 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6982 MagickFalse,argv[i+1]);
6983 limit=MagickResourceInfinity;
6984 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006985 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006986 (void) SetMagickResourceLimit(type,limit);
6987 break;
6988 }
6989 if (LocaleCompare("list",option+1) == 0)
6990 {
6991 long
6992 list;
6993
6994 /*
6995 Display configuration list.
6996 */
6997 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6998 switch (list)
6999 {
7000 case MagickCoderOptions:
7001 {
7002 (void) ListCoderInfo((FILE *) NULL,exception);
7003 break;
7004 }
7005 case MagickColorOptions:
7006 {
7007 (void) ListColorInfo((FILE *) NULL,exception);
7008 break;
7009 }
7010 case MagickConfigureOptions:
7011 {
7012 (void) ListConfigureInfo((FILE *) NULL,exception);
7013 break;
7014 }
7015 case MagickDelegateOptions:
7016 {
7017 (void) ListDelegateInfo((FILE *) NULL,exception);
7018 break;
7019 }
7020 case MagickFontOptions:
7021 {
7022 (void) ListTypeInfo((FILE *) NULL,exception);
7023 break;
7024 }
7025 case MagickFormatOptions:
7026 {
7027 (void) ListMagickInfo((FILE *) NULL,exception);
7028 break;
7029 }
7030 case MagickLocaleOptions:
7031 {
7032 (void) ListLocaleInfo((FILE *) NULL,exception);
7033 break;
7034 }
7035 case MagickLogOptions:
7036 {
7037 (void) ListLogInfo((FILE *) NULL,exception);
7038 break;
7039 }
7040 case MagickMagicOptions:
7041 {
7042 (void) ListMagicInfo((FILE *) NULL,exception);
7043 break;
7044 }
7045 case MagickMimeOptions:
7046 {
7047 (void) ListMimeInfo((FILE *) NULL,exception);
7048 break;
7049 }
7050 case MagickModuleOptions:
7051 {
7052 (void) ListModuleInfo((FILE *) NULL,exception);
7053 break;
7054 }
7055 case MagickPolicyOptions:
7056 {
7057 (void) ListPolicyInfo((FILE *) NULL,exception);
7058 break;
7059 }
7060 case MagickResourceOptions:
7061 {
7062 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7063 break;
7064 }
7065 case MagickThresholdOptions:
7066 {
7067 (void) ListThresholdMaps((FILE *) NULL,exception);
7068 break;
7069 }
7070 default:
7071 {
7072 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7073 exception);
7074 break;
7075 }
7076 }
7077 }
7078 if (LocaleCompare("log",option+1) == 0)
7079 {
7080 if (*option == '+')
7081 break;
7082 (void) SetLogFormat(argv[i+1]);
7083 break;
7084 }
7085 if (LocaleCompare("loop",option+1) == 0)
7086 {
7087 if (*option == '+')
7088 {
7089 (void) SetImageOption(image_info,option+1,"0");
7090 break;
7091 }
7092 (void) SetImageOption(image_info,option+1,argv[i+1]);
7093 break;
7094 }
7095 break;
7096 }
7097 case 'm':
7098 {
7099 if (LocaleCompare("matte",option+1) == 0)
7100 {
7101 if (*option == '+')
7102 {
7103 (void) SetImageOption(image_info,option+1,"false");
7104 break;
7105 }
7106 (void) SetImageOption(image_info,option+1,"true");
7107 break;
7108 }
7109 if (LocaleCompare("mattecolor",option+1) == 0)
7110 {
7111 if (*option == '+')
7112 {
7113 (void) SetImageOption(image_info,option+1,argv[i+1]);
7114 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7115 exception);
7116 break;
7117 }
7118 (void) SetImageOption(image_info,option+1,argv[i+1]);
7119 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7120 exception);
7121 break;
7122 }
7123 if (LocaleCompare("monitor",option+1) == 0)
7124 {
7125 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7126 (void *) NULL);
7127 break;
7128 }
7129 if (LocaleCompare("monochrome",option+1) == 0)
7130 {
7131 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7132 break;
7133 }
7134 break;
7135 }
7136 case 'o':
7137 {
7138 if (LocaleCompare("orient",option+1) == 0)
7139 {
7140 if (*option == '+')
7141 {
7142 image_info->orientation=UndefinedOrientation;
7143 (void) SetImageOption(image_info,option+1,"undefined");
7144 break;
7145 }
7146 image_info->orientation=(OrientationType) ParseMagickOption(
7147 MagickOrientationOptions,MagickFalse,argv[i+1]);
7148 (void) SetImageOption(image_info,option+1,"undefined");
7149 break;
7150 }
7151 }
7152 case 'p':
7153 {
7154 if (LocaleCompare("page",option+1) == 0)
7155 {
7156 char
7157 *canonical_page,
7158 page[MaxTextExtent];
7159
7160 const char
7161 *image_option;
7162
7163 MagickStatusType
7164 flags;
7165
7166 RectangleInfo
7167 geometry;
7168
7169 if (*option == '+')
7170 {
7171 (void) DeleteImageOption(image_info,option+1);
7172 (void) CloneString(&image_info->page,(char *) NULL);
7173 break;
7174 }
7175 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7176 image_option=GetImageOption(image_info,"page");
7177 if (image_option != (const char *) NULL)
7178 flags=ParseAbsoluteGeometry(image_option,&geometry);
7179 canonical_page=GetPageGeometry(argv[i+1]);
7180 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7181 canonical_page=DestroyString(canonical_page);
7182 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
7183 geometry.width,geometry.height);
7184 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7185 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7186 geometry.width,geometry.height,geometry.x,geometry.y);
7187 (void) SetImageOption(image_info,option+1,page);
7188 (void) CloneString(&image_info->page,page);
7189 break;
7190 }
7191 if (LocaleCompare("pen",option+1) == 0)
7192 {
7193 if (*option == '+')
7194 {
7195 (void) SetImageOption(image_info,option+1,"none");
7196 break;
7197 }
7198 (void) SetImageOption(image_info,option+1,argv[i+1]);
7199 break;
7200 }
7201 if (LocaleCompare("ping",option+1) == 0)
7202 {
7203 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7204 break;
7205 }
7206 if (LocaleCompare("pointsize",option+1) == 0)
7207 {
7208 if (*option == '+')
7209 geometry_info.rho=0.0;
7210 else
7211 (void) ParseGeometry(argv[i+1],&geometry_info);
7212 image_info->pointsize=geometry_info.rho;
7213 break;
7214 }
cristye7f51092010-01-17 00:39:37 +00007215 if (LocaleCompare("precision",option+1) == 0)
7216 {
cristybf2766a2010-01-17 03:33:23 +00007217 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007218 break;
7219 }
cristy3ed852e2009-09-05 21:47:34 +00007220 if (LocaleCompare("preview",option+1) == 0)
7221 {
7222 /*
7223 Preview image.
7224 */
7225 if (*option == '+')
7226 {
7227 image_info->preview_type=UndefinedPreview;
7228 break;
7229 }
7230 image_info->preview_type=(PreviewType) ParseMagickOption(
7231 MagickPreviewOptions,MagickFalse,argv[i+1]);
7232 break;
7233 }
7234 break;
7235 }
7236 case 'q':
7237 {
7238 if (LocaleCompare("quality",option+1) == 0)
7239 {
7240 /*
7241 Set image compression quality.
7242 */
7243 if (*option == '+')
7244 {
7245 image_info->quality=UndefinedCompressionQuality;
7246 (void) SetImageOption(image_info,option+1,"0");
7247 break;
7248 }
cristye27293e2009-12-18 02:53:20 +00007249 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007250 (void) SetImageOption(image_info,option+1,argv[i+1]);
7251 break;
7252 }
7253 if (LocaleCompare("quiet",option+1) == 0)
7254 {
7255 static WarningHandler
7256 warning_handler = (WarningHandler) NULL;
7257
7258 if (*option == '+')
7259 {
7260 /*
7261 Restore error or warning messages.
7262 */
7263 warning_handler=SetWarningHandler(warning_handler);
7264 break;
7265 }
7266 /*
7267 Suppress error or warning messages.
7268 */
7269 warning_handler=SetWarningHandler((WarningHandler) NULL);
7270 break;
7271 }
7272 break;
7273 }
7274 case 'r':
7275 {
7276 if (LocaleCompare("red-primary",option+1) == 0)
7277 {
7278 if (*option == '+')
7279 {
7280 (void) SetImageOption(image_info,option+1,"0.0");
7281 break;
7282 }
7283 (void) SetImageOption(image_info,option+1,argv[i+1]);
7284 break;
7285 }
7286 break;
7287 }
7288 case 's':
7289 {
7290 if (LocaleCompare("sampling-factor",option+1) == 0)
7291 {
7292 /*
7293 Set image sampling factor.
7294 */
7295 if (*option == '+')
7296 {
7297 if (image_info->sampling_factor != (char *) NULL)
7298 image_info->sampling_factor=DestroyString(
7299 image_info->sampling_factor);
7300 break;
7301 }
7302 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7303 break;
7304 }
7305 if (LocaleCompare("scene",option+1) == 0)
7306 {
7307 /*
7308 Set image scene.
7309 */
7310 if (*option == '+')
7311 {
7312 image_info->scene=0;
7313 (void) SetImageOption(image_info,option+1,"0");
7314 break;
7315 }
cristye27293e2009-12-18 02:53:20 +00007316 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007317 (void) SetImageOption(image_info,option+1,argv[i+1]);
7318 break;
7319 }
7320 if (LocaleCompare("seed",option+1) == 0)
7321 {
7322 unsigned long
7323 seed;
7324
7325 if (*option == '+')
7326 {
7327 seed=(unsigned long) time((time_t *) NULL);
7328 SeedPseudoRandomGenerator(seed);
7329 break;
7330 }
cristye27293e2009-12-18 02:53:20 +00007331 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007332 SeedPseudoRandomGenerator(seed);
7333 break;
7334 }
7335 if (LocaleCompare("size",option+1) == 0)
7336 {
7337 if (*option == '+')
7338 {
7339 if (image_info->size != (char *) NULL)
7340 image_info->size=DestroyString(image_info->size);
7341 break;
7342 }
7343 (void) CloneString(&image_info->size,argv[i+1]);
7344 break;
7345 }
7346 if (LocaleCompare("stroke",option+1) == 0)
7347 {
7348 if (*option == '+')
7349 {
7350 (void) SetImageOption(image_info,option+1,"none");
7351 break;
7352 }
7353 (void) SetImageOption(image_info,option+1,argv[i+1]);
7354 break;
7355 }
7356 if (LocaleCompare("strokewidth",option+1) == 0)
7357 {
7358 if (*option == '+')
7359 {
7360 (void) SetImageOption(image_info,option+1,"0");
7361 break;
7362 }
7363 (void) SetImageOption(image_info,option+1,argv[i+1]);
7364 break;
7365 }
7366 break;
7367 }
7368 case 't':
7369 {
7370 if (LocaleCompare("taint",option+1) == 0)
7371 {
7372 if (*option == '+')
7373 {
7374 (void) SetImageOption(image_info,option+1,"false");
7375 break;
7376 }
7377 (void) SetImageOption(image_info,option+1,"true");
7378 break;
7379 }
7380 if (LocaleCompare("texture",option+1) == 0)
7381 {
7382 if (*option == '+')
7383 {
7384 if (image_info->texture != (char *) NULL)
7385 image_info->texture=DestroyString(image_info->texture);
7386 break;
7387 }
7388 (void) CloneString(&image_info->texture,argv[i+1]);
7389 break;
7390 }
7391 if (LocaleCompare("tile-offset",option+1) == 0)
7392 {
7393 if (*option == '+')
7394 {
7395 (void) SetImageOption(image_info,option+1,"0");
7396 break;
7397 }
7398 (void) SetImageOption(image_info,option+1,argv[i+1]);
7399 break;
7400 }
7401 if (LocaleCompare("transparent-color",option+1) == 0)
7402 {
7403 if (*option == '+')
7404 {
7405 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7406 (void) SetImageOption(image_info,option+1,"none");
7407 break;
7408 }
7409 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7410 exception);
7411 (void) SetImageOption(image_info,option+1,argv[i+1]);
7412 break;
7413 }
7414 if (LocaleCompare("type",option+1) == 0)
7415 {
7416 if (*option == '+')
7417 {
7418 image_info->type=UndefinedType;
7419 (void) SetImageOption(image_info,option+1,"undefined");
7420 break;
7421 }
7422 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7423 MagickFalse,argv[i+1]);
7424 (void) SetImageOption(image_info,option+1,argv[i+1]);
7425 break;
7426 }
7427 break;
7428 }
7429 case 'u':
7430 {
7431 if (LocaleCompare("undercolor",option+1) == 0)
7432 {
7433 if (*option == '+')
7434 {
7435 (void) DeleteImageOption(image_info,option+1);
7436 break;
7437 }
7438 (void) SetImageOption(image_info,option+1,argv[i+1]);
7439 break;
7440 }
7441 if (LocaleCompare("units",option+1) == 0)
7442 {
7443 if (*option == '+')
7444 {
7445 image_info->units=UndefinedResolution;
7446 (void) SetImageOption(image_info,option+1,"undefined");
7447 break;
7448 }
7449 image_info->units=(ResolutionType) ParseMagickOption(
7450 MagickResolutionOptions,MagickFalse,argv[i+1]);
7451 (void) SetImageOption(image_info,option+1,argv[i+1]);
7452 break;
7453 }
7454 break;
7455 }
7456 case 'v':
7457 {
7458 if (LocaleCompare("verbose",option+1) == 0)
7459 {
7460 if (*option == '+')
7461 {
7462 image_info->verbose=MagickFalse;
7463 break;
7464 }
7465 image_info->verbose=MagickTrue;
7466 image_info->ping=MagickFalse;
7467 break;
7468 }
7469 if (LocaleCompare("view",option+1) == 0)
7470 {
7471 if (*option == '+')
7472 {
7473 if (image_info->view != (char *) NULL)
7474 image_info->view=DestroyString(image_info->view);
7475 break;
7476 }
7477 (void) CloneString(&image_info->view,argv[i+1]);
7478 break;
7479 }
7480 if (LocaleCompare("virtual-pixel",option+1) == 0)
7481 {
7482 if (*option == '+')
7483 {
7484 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7485 (void) SetImageOption(image_info,option+1,"undefined");
7486 break;
7487 }
7488 image_info->virtual_pixel_method=(VirtualPixelMethod)
7489 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7490 argv[i+1]);
7491 (void) SetImageOption(image_info,option+1,argv[i+1]);
7492 break;
7493 }
7494 break;
7495 }
7496 case 'w':
7497 {
7498 if (LocaleCompare("white-point",option+1) == 0)
7499 {
7500 if (*option == '+')
7501 {
7502 (void) SetImageOption(image_info,option+1,"0.0");
7503 break;
7504 }
7505 (void) SetImageOption(image_info,option+1,argv[i+1]);
7506 break;
7507 }
7508 break;
7509 }
7510 default:
7511 break;
7512 }
7513 i+=count;
7514 }
7515 return(MagickTrue);
7516}
7517
7518/*
7519%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7520% %
7521% %
7522% %
7523+ M o g r i f y I m a g e L i s t %
7524% %
7525% %
7526% %
7527%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7528%
7529% MogrifyImageList() applies any command line options that might affect the
7530% entire image list (e.g. -append, -coalesce, etc.).
7531%
7532% The format of the MogrifyImage method is:
7533%
7534% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7535% const char **argv,Image **images,ExceptionInfo *exception)
7536%
7537% A description of each parameter follows:
7538%
7539% o image_info: the image info..
7540%
7541% o argc: Specifies a pointer to an integer describing the number of
7542% elements in the argument vector.
7543%
7544% o argv: Specifies a pointer to a text array containing the command line
7545% arguments.
7546%
7547% o images: the images.
7548%
7549% o exception: return any errors or warnings in this structure.
7550%
7551*/
7552WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7553 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7554{
7555 ChannelType
7556 channel;
7557
7558 const char
7559 *option;
7560
7561 long
7562 count,
7563 index;
7564
7565 MagickStatusType
7566 status;
7567
7568 QuantizeInfo
7569 *quantize_info;
7570
7571 register long
7572 i;
7573
7574 /*
7575 Apply options to the image list.
7576 */
7577 assert(image_info != (ImageInfo *) NULL);
7578 assert(image_info->signature == MagickSignature);
7579 assert(images != (Image **) NULL);
7580 assert((*images)->signature == MagickSignature);
7581 if ((*images)->debug != MagickFalse)
7582 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7583 (*images)->filename);
7584 if ((argc <= 0) || (*argv == (char *) NULL))
7585 return(MagickTrue);
7586 quantize_info=AcquireQuantizeInfo(image_info);
7587 channel=image_info->channel;
7588 status=MagickTrue;
7589 for (i=0; i < (long) argc; i++)
7590 {
cristy74fe8f12009-10-03 19:09:01 +00007591 if (*images == (Image *) NULL)
7592 break;
cristy3ed852e2009-09-05 21:47:34 +00007593 option=argv[i];
7594 if (IsMagickOption(option) == MagickFalse)
7595 continue;
7596 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7597 0L);
7598 if ((i+count) >= argc)
7599 break;
7600 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
7601 switch (*(option+1))
7602 {
7603 case 'a':
7604 {
7605 if (LocaleCompare("affinity",option+1) == 0)
7606 {
7607 (void) SyncImagesSettings(image_info,*images);
7608 if (*option == '+')
7609 {
7610 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7611 InheritException(exception,&(*images)->exception);
7612 break;
7613 }
7614 i++;
7615 break;
7616 }
7617 if (LocaleCompare("append",option+1) == 0)
7618 {
7619 Image
7620 *append_image;
7621
7622 (void) SyncImagesSettings(image_info,*images);
7623 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7624 MagickFalse,exception);
7625 if (append_image == (Image *) NULL)
7626 {
7627 status=MagickFalse;
7628 break;
7629 }
7630 *images=DestroyImageList(*images);
7631 *images=append_image;
7632 break;
7633 }
7634 if (LocaleCompare("average",option+1) == 0)
7635 {
7636 Image
7637 *average_image;
7638
cristyd18ae7c2010-03-07 17:39:52 +00007639 /*
7640 Average an image sequence (deprecated).
7641 */
cristy3ed852e2009-09-05 21:47:34 +00007642 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007643 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7644 exception);
cristy3ed852e2009-09-05 21:47:34 +00007645 if (average_image == (Image *) NULL)
7646 {
7647 status=MagickFalse;
7648 break;
7649 }
7650 *images=DestroyImageList(*images);
7651 *images=average_image;
7652 break;
7653 }
7654 break;
7655 }
7656 case 'c':
7657 {
7658 if (LocaleCompare("channel",option+1) == 0)
7659 {
7660 if (*option == '+')
7661 {
7662 channel=DefaultChannels;
7663 break;
7664 }
7665 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7666 break;
7667 }
7668 if (LocaleCompare("clut",option+1) == 0)
7669 {
7670 Image
7671 *clut_image,
7672 *image;
7673
7674 (void) SyncImagesSettings(image_info,*images);
7675 image=RemoveFirstImageFromList(images);
7676 clut_image=RemoveFirstImageFromList(images);
7677 if (clut_image == (Image *) NULL)
7678 {
7679 status=MagickFalse;
7680 break;
7681 }
7682 (void) ClutImageChannel(image,channel,clut_image);
7683 clut_image=DestroyImage(clut_image);
7684 InheritException(exception,&image->exception);
7685 *images=DestroyImageList(*images);
7686 *images=image;
7687 break;
7688 }
7689 if (LocaleCompare("coalesce",option+1) == 0)
7690 {
7691 Image
7692 *coalesce_image;
7693
7694 (void) SyncImagesSettings(image_info,*images);
7695 coalesce_image=CoalesceImages(*images,exception);
7696 if (coalesce_image == (Image *) NULL)
7697 {
7698 status=MagickFalse;
7699 break;
7700 }
7701 *images=DestroyImageList(*images);
7702 *images=coalesce_image;
7703 break;
7704 }
7705 if (LocaleCompare("combine",option+1) == 0)
7706 {
7707 Image
7708 *combine_image;
7709
7710 (void) SyncImagesSettings(image_info,*images);
7711 combine_image=CombineImages(*images,channel,exception);
7712 if (combine_image == (Image *) NULL)
7713 {
7714 status=MagickFalse;
7715 break;
7716 }
7717 *images=DestroyImageList(*images);
7718 *images=combine_image;
7719 break;
7720 }
7721 if (LocaleCompare("composite",option+1) == 0)
7722 {
7723 Image
7724 *mask_image,
7725 *composite_image,
7726 *image;
7727
7728 RectangleInfo
7729 geometry;
7730
7731 (void) SyncImagesSettings(image_info,*images);
7732 image=RemoveFirstImageFromList(images);
7733 composite_image=RemoveFirstImageFromList(images);
7734 if (composite_image == (Image *) NULL)
7735 {
7736 status=MagickFalse;
7737 break;
7738 }
7739 (void) TransformImage(&composite_image,(char *) NULL,
7740 composite_image->geometry);
7741 SetGeometry(composite_image,&geometry);
7742 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7743 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7744 &geometry);
7745 mask_image=RemoveFirstImageFromList(images);
7746 if (mask_image != (Image *) NULL)
7747 {
7748 if ((image->compose == DisplaceCompositeOp) ||
7749 (image->compose == DistortCompositeOp))
7750 {
7751 /*
7752 Merge Y displacement into X displacement image.
7753 */
7754 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7755 mask_image,0,0);
7756 mask_image=DestroyImage(mask_image);
7757 }
7758 else
7759 {
7760 /*
7761 Set a blending mask for the composition.
7762 */
7763 image->mask=mask_image;
7764 (void) NegateImage(image->mask,MagickFalse);
7765 }
7766 }
7767 (void) CompositeImageChannel(image,channel,image->compose,
7768 composite_image,geometry.x,geometry.y);
7769 if (image->mask != (Image *) NULL)
7770 image->mask=DestroyImage(image->mask);
7771 composite_image=DestroyImage(composite_image);
7772 InheritException(exception,&image->exception);
7773 *images=DestroyImageList(*images);
7774 *images=image;
7775 break;
7776 }
7777 if (LocaleCompare("crop",option+1) == 0)
7778 {
7779 MagickStatusType
7780 flags;
7781
7782 RectangleInfo
7783 geometry;
7784
7785 (void) SyncImagesSettings(image_info,*images);
7786 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7787 if (((geometry.width == 0) && (geometry.height == 0)) ||
7788 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7789 break;
7790 (void) TransformImages(images,argv[i+1],(char *) NULL);
7791 InheritException(exception,&(*images)->exception);
7792 break;
7793 }
7794 break;
7795 }
7796 case 'd':
7797 {
7798 if (LocaleCompare("deconstruct",option+1) == 0)
7799 {
7800 Image
7801 *deconstruct_image;
7802
7803 (void) SyncImagesSettings(image_info,*images);
7804 deconstruct_image=DeconstructImages(*images,exception);
7805 if (deconstruct_image == (Image *) NULL)
7806 {
7807 status=MagickFalse;
7808 break;
7809 }
7810 *images=DestroyImageList(*images);
7811 *images=deconstruct_image;
7812 break;
7813 }
7814 if (LocaleCompare("delete",option+1) == 0)
7815 {
7816 if (*option == '+')
7817 DeleteImages(images,"-1",exception);
7818 else
7819 DeleteImages(images,argv[i+1],exception);
7820 break;
7821 }
7822 if (LocaleCompare("dither",option+1) == 0)
7823 {
7824 if (*option == '+')
7825 {
7826 quantize_info->dither=MagickFalse;
7827 break;
7828 }
7829 quantize_info->dither=MagickTrue;
7830 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7831 MagickDitherOptions,MagickFalse,argv[i+1]);
7832 break;
7833 }
7834 break;
7835 }
cristyd18ae7c2010-03-07 17:39:52 +00007836 case 'e':
7837 {
7838 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7839 {
7840 Image
7841 *evaluate_image;
7842
7843 MagickEvaluateOperator
7844 op;
7845
7846 (void) SyncImageSettings(image_info,*images);
7847 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7848 MagickFalse,argv[i+1]);
7849 evaluate_image=EvaluateImages(*images,op,exception);
7850 if (evaluate_image == (Image *) NULL)
7851 {
7852 status=MagickFalse;
7853 break;
7854 }
7855 *images=DestroyImageList(*images);
7856 *images=evaluate_image;
7857 break;
7858 }
7859 break;
7860 }
cristy3ed852e2009-09-05 21:47:34 +00007861 case 'f':
7862 {
cristyf0a247f2009-10-04 00:20:03 +00007863 if (LocaleCompare("fft",option+1) == 0)
7864 {
7865 Image
7866 *fourier_image;
7867
7868 /*
7869 Implements the discrete Fourier transform (DFT).
7870 */
7871 (void) SyncImageSettings(image_info,*images);
7872 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7873 MagickTrue : MagickFalse,exception);
7874 if (fourier_image == (Image *) NULL)
7875 break;
7876 *images=DestroyImage(*images);
7877 *images=fourier_image;
7878 break;
7879 }
cristy3ed852e2009-09-05 21:47:34 +00007880 if (LocaleCompare("flatten",option+1) == 0)
7881 {
7882 Image
7883 *flatten_image;
7884
7885 (void) SyncImagesSettings(image_info,*images);
7886 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7887 if (flatten_image == (Image *) NULL)
7888 break;
7889 *images=DestroyImageList(*images);
7890 *images=flatten_image;
7891 break;
7892 }
7893 if (LocaleCompare("fx",option+1) == 0)
7894 {
7895 Image
7896 *fx_image;
7897
7898 (void) SyncImagesSettings(image_info,*images);
7899 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7900 if (fx_image == (Image *) NULL)
7901 {
7902 status=MagickFalse;
7903 break;
7904 }
7905 *images=DestroyImageList(*images);
7906 *images=fx_image;
7907 break;
7908 }
7909 break;
7910 }
7911 case 'h':
7912 {
7913 if (LocaleCompare("hald-clut",option+1) == 0)
7914 {
7915 Image
7916 *hald_image,
7917 *image;
7918
7919 (void) SyncImagesSettings(image_info,*images);
7920 image=RemoveFirstImageFromList(images);
7921 hald_image=RemoveFirstImageFromList(images);
7922 if (hald_image == (Image *) NULL)
7923 {
7924 status=MagickFalse;
7925 break;
7926 }
7927 (void) HaldClutImageChannel(image,channel,hald_image);
7928 hald_image=DestroyImage(hald_image);
7929 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007930 if (*images != (Image *) NULL)
7931 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007932 *images=image;
7933 break;
7934 }
7935 break;
7936 }
7937 case 'i':
7938 {
7939 if (LocaleCompare("ift",option+1) == 0)
7940 {
7941 Image
cristy8587f882009-11-13 20:28:49 +00007942 *fourier_image,
7943 *magnitude_image,
7944 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007945
7946 /*
7947 Implements the inverse fourier discrete Fourier transform (DFT).
7948 */
7949 (void) SyncImagesSettings(image_info,*images);
cristy8587f882009-11-13 20:28:49 +00007950 magnitude_image=RemoveFirstImageFromList(images);
7951 phase_image=RemoveFirstImageFromList(images);
7952 if (phase_image == (Image *) NULL)
7953 {
7954 status=MagickFalse;
7955 break;
7956 }
7957 fourier_image=InverseFourierTransformImage(magnitude_image,
7958 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007959 if (fourier_image == (Image *) NULL)
7960 break;
cristy0aff6ea2009-11-14 01:40:53 +00007961 if (*images != (Image *) NULL)
7962 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007963 *images=fourier_image;
7964 break;
7965 }
7966 if (LocaleCompare("insert",option+1) == 0)
7967 {
7968 Image
7969 *p,
7970 *q;
7971
7972 index=0;
7973 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007974 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007975 p=RemoveLastImageFromList(images);
7976 if (p == (Image *) NULL)
7977 {
7978 (void) ThrowMagickException(exception,GetMagickModule(),
7979 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7980 status=MagickFalse;
7981 break;
7982 }
7983 q=p;
7984 if (index == 0)
7985 PrependImageToList(images,q);
7986 else
7987 if (index == (long) GetImageListLength(*images))
7988 AppendImageToList(images,q);
7989 else
7990 {
7991 q=GetImageFromList(*images,index-1);
7992 if (q == (Image *) NULL)
7993 {
7994 (void) ThrowMagickException(exception,GetMagickModule(),
7995 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7996 status=MagickFalse;
7997 break;
7998 }
7999 InsertImageInList(&q,p);
8000 }
8001 *images=GetFirstImageInList(q);
8002 break;
8003 }
8004 break;
8005 }
8006 case 'l':
8007 {
8008 if (LocaleCompare("layers",option+1) == 0)
8009 {
8010 Image
8011 *layers;
8012
8013 ImageLayerMethod
8014 method;
8015
8016 (void) SyncImagesSettings(image_info,*images);
8017 layers=(Image *) NULL;
8018 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
8019 MagickFalse,argv[i+1]);
8020 switch (method)
8021 {
8022 case CoalesceLayer:
8023 {
8024 layers=CoalesceImages(*images,exception);
8025 break;
8026 }
8027 case CompareAnyLayer:
8028 case CompareClearLayer:
8029 case CompareOverlayLayer:
8030 default:
8031 {
8032 layers=CompareImageLayers(*images,method,exception);
8033 break;
8034 }
8035 case MergeLayer:
8036 case FlattenLayer:
8037 case MosaicLayer:
8038 case TrimBoundsLayer:
8039 {
8040 layers=MergeImageLayers(*images,method,exception);
8041 break;
8042 }
8043 case DisposeLayer:
8044 {
8045 layers=DisposeImages(*images,exception);
8046 break;
8047 }
8048 case OptimizeImageLayer:
8049 {
8050 layers=OptimizeImageLayers(*images,exception);
8051 break;
8052 }
8053 case OptimizePlusLayer:
8054 {
8055 layers=OptimizePlusImageLayers(*images,exception);
8056 break;
8057 }
8058 case OptimizeTransLayer:
8059 {
8060 OptimizeImageTransparency(*images,exception);
8061 break;
8062 }
8063 case RemoveDupsLayer:
8064 {
8065 RemoveDuplicateLayers(images,exception);
8066 break;
8067 }
8068 case RemoveZeroLayer:
8069 {
8070 RemoveZeroDelayLayers(images,exception);
8071 break;
8072 }
8073 case OptimizeLayer:
8074 {
8075 /*
8076 General Purpose, GIF Animation Optimizer.
8077 */
8078 layers=CoalesceImages(*images,exception);
8079 if (layers == (Image *) NULL)
8080 {
8081 status=MagickFalse;
8082 break;
8083 }
8084 InheritException(exception,&layers->exception);
8085 *images=DestroyImageList(*images);
8086 *images=layers;
8087 layers=OptimizeImageLayers(*images,exception);
8088 if (layers == (Image *) NULL)
8089 {
8090 status=MagickFalse;
8091 break;
8092 }
8093 InheritException(exception,&layers->exception);
8094 *images=DestroyImageList(*images);
8095 *images=layers;
8096 layers=(Image *) NULL;
8097 OptimizeImageTransparency(*images,exception);
8098 InheritException(exception,&(*images)->exception);
8099 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8100 break;
8101 }
8102 case CompositeLayer:
8103 {
8104 CompositeOperator
8105 compose;
8106
8107 Image
8108 *source;
8109
8110 RectangleInfo
8111 geometry;
8112
8113 /*
8114 Split image sequence at the first 'NULL:' image.
8115 */
8116 source=(*images);
8117 while (source != (Image *) NULL)
8118 {
8119 source=GetNextImageInList(source);
8120 if ((source != (Image *) NULL) &&
8121 (LocaleCompare(source->magick,"NULL") == 0))
8122 break;
8123 }
8124 if (source != (Image *) NULL)
8125 {
8126 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8127 (GetNextImageInList(source) == (Image *) NULL))
8128 source=(Image *) NULL;
8129 else
8130 {
8131 /*
8132 Separate the two lists, junk the null: image.
8133 */
8134 source=SplitImageList(source->previous);
8135 DeleteImageFromList(&source);
8136 }
8137 }
8138 if (source == (Image *) NULL)
8139 {
8140 (void) ThrowMagickException(exception,GetMagickModule(),
8141 OptionError,"MissingNullSeparator","layers Composite");
8142 status=MagickFalse;
8143 break;
8144 }
8145 /*
8146 Adjust offset with gravity and virtual canvas.
8147 */
8148 SetGeometry(*images,&geometry);
8149 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8150 geometry.width=source->page.width != 0 ?
8151 source->page.width : source->columns;
8152 geometry.height=source->page.height != 0 ?
8153 source->page.height : source->rows;
8154 GravityAdjustGeometry((*images)->page.width != 0 ?
8155 (*images)->page.width : (*images)->columns,
8156 (*images)->page.height != 0 ? (*images)->page.height :
8157 (*images)->rows,(*images)->gravity,&geometry);
8158 compose=OverCompositeOp;
8159 option=GetImageOption(image_info,"compose");
8160 if (option != (const char *) NULL)
8161 compose=(CompositeOperator) ParseMagickOption(
8162 MagickComposeOptions,MagickFalse,option);
8163 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8164 exception);
8165 source=DestroyImageList(source);
8166 break;
8167 }
8168 }
8169 if (layers == (Image *) NULL)
8170 break;
8171 InheritException(exception,&layers->exception);
8172 *images=DestroyImageList(*images);
8173 *images=layers;
8174 break;
8175 }
8176 break;
8177 }
8178 case 'm':
8179 {
8180 if (LocaleCompare("map",option+1) == 0)
8181 {
8182 (void) SyncImagesSettings(image_info,*images);
8183 if (*option == '+')
8184 {
8185 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8186 InheritException(exception,&(*images)->exception);
8187 break;
8188 }
8189 i++;
8190 break;
8191 }
cristyf40785b2010-03-06 02:27:27 +00008192 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008193 {
8194 Image
cristyf40785b2010-03-06 02:27:27 +00008195 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008196
cristyd18ae7c2010-03-07 17:39:52 +00008197 /*
8198 Maximum image sequence (deprecated).
8199 */
cristy1c274c92010-03-06 02:06:45 +00008200 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008201 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008202 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008203 {
8204 status=MagickFalse;
8205 break;
8206 }
8207 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008208 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008209 break;
8210 }
cristyf40785b2010-03-06 02:27:27 +00008211 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008212 {
8213 Image
cristyf40785b2010-03-06 02:27:27 +00008214 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008215
cristyd18ae7c2010-03-07 17:39:52 +00008216 /*
8217 Minimum image sequence (deprecated).
8218 */
cristy1c274c92010-03-06 02:06:45 +00008219 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008220 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008221 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008222 {
8223 status=MagickFalse;
8224 break;
8225 }
8226 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008227 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008228 break;
8229 }
cristy3ed852e2009-09-05 21:47:34 +00008230 if (LocaleCompare("morph",option+1) == 0)
8231 {
8232 Image
8233 *morph_image;
8234
8235 (void) SyncImagesSettings(image_info,*images);
cristye27293e2009-12-18 02:53:20 +00008236 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008237 exception);
8238 if (morph_image == (Image *) NULL)
8239 {
8240 status=MagickFalse;
8241 break;
8242 }
8243 *images=DestroyImageList(*images);
8244 *images=morph_image;
8245 break;
8246 }
8247 if (LocaleCompare("mosaic",option+1) == 0)
8248 {
8249 Image
8250 *mosaic_image;
8251
8252 (void) SyncImagesSettings(image_info,*images);
8253 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8254 if (mosaic_image == (Image *) NULL)
8255 {
8256 status=MagickFalse;
8257 break;
8258 }
8259 *images=DestroyImageList(*images);
8260 *images=mosaic_image;
8261 break;
8262 }
8263 break;
8264 }
8265 case 'p':
8266 {
8267 if (LocaleCompare("print",option+1) == 0)
8268 {
8269 char
8270 *string;
8271
8272 (void) SyncImagesSettings(image_info,*images);
8273 string=InterpretImageProperties(image_info,*images,argv[i+1]);
8274 if (string == (char *) NULL)
8275 break;
8276 InheritException(exception,&(*images)->exception);
8277 (void) fprintf(stdout,"%s",string);
8278 string=DestroyString(string);
8279 }
8280 if (LocaleCompare("process",option+1) == 0)
8281 {
8282 char
8283 **arguments;
8284
8285 int
8286 j,
8287 number_arguments;
8288
8289 (void) SyncImagesSettings(image_info,*images);
8290 arguments=StringToArgv(argv[i+1],&number_arguments);
8291 if (arguments == (char **) NULL)
8292 break;
8293 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8294 {
8295 char
8296 breaker,
8297 quote,
8298 *token;
8299
8300 const char
8301 *arguments;
8302
8303 int
8304 next,
8305 status;
8306
8307 size_t
8308 length;
8309
8310 TokenInfo
8311 *token_info;
8312
8313 /*
8314 Support old style syntax, filter="-option arg".
8315 */
8316 length=strlen(argv[i+1]);
8317 token=(char *) NULL;
8318 if (~length >= MaxTextExtent)
8319 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8320 sizeof(*token));
8321 if (token == (char *) NULL)
8322 break;
8323 next=0;
8324 arguments=argv[i+1];
8325 token_info=AcquireTokenInfo();
8326 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8327 "\"",'\0',&breaker,&next,&quote);
8328 token_info=DestroyTokenInfo(token_info);
8329 if (status == 0)
8330 {
8331 const char
8332 *argv;
8333
8334 argv=(&(arguments[next]));
8335 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8336 exception);
8337 }
8338 token=DestroyString(token);
8339 break;
8340 }
8341 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8342 number_arguments-2,(const char **) arguments+2,exception);
8343 for (j=0; j < number_arguments; j++)
8344 arguments[j]=DestroyString(arguments[j]);
8345 arguments=(char **) RelinquishMagickMemory(arguments);
8346 break;
8347 }
8348 break;
8349 }
8350 case 'r':
8351 {
8352 if (LocaleCompare("reverse",option+1) == 0)
8353 {
8354 ReverseImageList(images);
8355 InheritException(exception,&(*images)->exception);
8356 break;
8357 }
8358 break;
8359 }
8360 case 's':
8361 {
8362 if (LocaleCompare("swap",option+1) == 0)
8363 {
8364 Image
8365 *p,
8366 *q,
8367 *swap;
8368
8369 long
8370 swap_index;
8371
8372 index=(-1);
8373 swap_index=(-2);
8374 if (*option != '+')
8375 {
8376 GeometryInfo
8377 geometry_info;
8378
8379 MagickStatusType
8380 flags;
8381
8382 swap_index=(-1);
8383 flags=ParseGeometry(argv[i+1],&geometry_info);
8384 index=(long) geometry_info.rho;
8385 if ((flags & SigmaValue) != 0)
8386 swap_index=(long) geometry_info.sigma;
8387 }
8388 p=GetImageFromList(*images,index);
8389 q=GetImageFromList(*images,swap_index);
8390 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8391 {
8392 (void) ThrowMagickException(exception,GetMagickModule(),
8393 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8394 status=MagickFalse;
8395 break;
8396 }
8397 if (p == q)
8398 break;
8399 swap=CloneImage(p,0,0,MagickTrue,exception);
8400 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8401 ReplaceImageInList(&q,swap);
8402 *images=GetFirstImageInList(q);
8403 break;
8404 }
8405 break;
8406 }
8407 case 'w':
8408 {
8409 if (LocaleCompare("write",option+1) == 0)
8410 {
cristy06609ee2010-03-17 20:21:27 +00008411 char
8412 key[MaxTextExtent];
8413
cristy3ed852e2009-09-05 21:47:34 +00008414 Image
8415 *write_images;
8416
8417 ImageInfo
8418 *write_info;
8419
8420 (void) SyncImagesSettings(image_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008421 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8422 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008423 write_images=(*images);
8424 if (*option == '+')
8425 write_images=CloneImageList(*images,exception);
8426 write_info=CloneImageInfo(image_info);
8427 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8428 write_info=DestroyImageInfo(write_info);
8429 if (*option == '+')
8430 write_images=DestroyImageList(write_images);
8431 break;
8432 }
8433 break;
8434 }
8435 default:
8436 break;
8437 }
8438 i+=count;
8439 }
8440 quantize_info=DestroyQuantizeInfo(quantize_info);
8441 return(status != 0 ? MagickTrue : MagickFalse);
8442}
8443
8444/*
8445%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8446% %
8447% %
8448% %
8449+ M o g r i f y I m a g e s %
8450% %
8451% %
8452% %
8453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8454%
8455% MogrifyImages() applies image processing options to a sequence of images as
8456% prescribed by command line options.
8457%
8458% The format of the MogrifyImage method is:
8459%
8460% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8461% const MagickBooleanType post,const int argc,const char **argv,
8462% Image **images,Exceptioninfo *exception)
8463%
8464% A description of each parameter follows:
8465%
8466% o image_info: the image info..
8467%
8468% o post: If true, post process image list operators otherwise pre-process.
8469%
8470% o argc: Specifies a pointer to an integer describing the number of
8471% elements in the argument vector.
8472%
8473% o argv: Specifies a pointer to a text array containing the command line
8474% arguments.
8475%
8476% o images: the images.
8477%
8478% o exception: return any errors or warnings in this structure.
8479%
8480*/
8481WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8482 const MagickBooleanType post,const int argc,const char **argv,
8483 Image **images,ExceptionInfo *exception)
8484{
8485#define MogrifyImageTag "Mogrify/Image"
8486
8487 Image
8488 *image,
8489 *mogrify_images;
8490
cristy0e9f9c12010-02-11 03:00:47 +00008491 MagickBooleanType
8492 proceed;
8493
8494 MagickSizeType
8495 number_images;
8496
cristy3ed852e2009-09-05 21:47:34 +00008497 MagickStatusType
8498 status;
8499
8500 register long
8501 i;
8502
cristy3ed852e2009-09-05 21:47:34 +00008503 /*
8504 Apply options to individual images in the list.
8505 */
8506 assert(image_info != (ImageInfo *) NULL);
8507 assert(image_info->signature == MagickSignature);
8508 if (images == (Image **) NULL)
8509 return(MogrifyImage(image_info,argc,argv,images,exception));
8510 assert((*images)->signature == MagickSignature);
8511 if ((*images)->debug != MagickFalse)
8512 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8513 (*images)->filename);
8514 if ((argc <= 0) || (*argv == (char *) NULL))
8515 return(MagickTrue);
8516 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8517 (void *) NULL);
8518 mogrify_images=NewImageList();
8519 number_images=GetImageListLength(*images);
8520 status=0;
8521 if (post == MagickFalse)
8522 status&=MogrifyImageList(image_info,argc,argv,images,exception);
8523 for (i=0; i < (long) number_images; i++)
8524 {
8525 image=RemoveFirstImageFromList(images);
8526 if (image == (Image *) NULL)
8527 continue;
8528 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8529 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008530 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8531 number_images);
8532 if (proceed == MagickFalse)
8533 break;
cristy3ed852e2009-09-05 21:47:34 +00008534 }
8535 if (post != MagickFalse)
8536 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8537 *images=mogrify_images;
8538 return(status != 0 ? MagickTrue : MagickFalse);
8539}